Subversion Repositories Games.Chess Giants

Rev

Rev 81 | Rev 130 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // scene.cpp
  2.  
  3. #include "common.h"
  4.  
  5.  
  6. // prototypes of local functions
  7. static void Scene_AddPart (scene_t *scene, int part_type, int part_color, float pos_x, float pos_y, float pos_z, float turn_yaw, float pitch);
  8. static void Scene_AddTile (scene_t *scene, int tile_type, float scale, float pos_x, float pos_y, float pos_z, float turn_yaw);
  9.  
  10.  
  11. // global variables used in this module only
  12. static wchar_t connected_comment[4096];
  13. static wchar_t filename[MAX_PATH];
  14. static float simpleshadow_sizes[] =
  15. {
  16.    0, // #define PART_NONE 0
  17.    2.5f, // #define PART_KING 1
  18.    2.45f, // #define PART_QUEEN 2
  19.    2.35f, // #define PART_BISHOP 3
  20.    2.25f, // #define PART_KNIGHT 4
  21.    2.15f, // #define PART_ROOK 5
  22.    2.0f, // #define PART_PAWN 6
  23. };
  24.  
  25.  
  26. void Scene_Init (scene_t *scene, board_t *board)
  27. {
  28.    // this function initializes the scene objects array and inserts the chess table in it
  29.  
  30.    wchar_t format_string[4096];
  31.  
  32.    // allocate array for the board (3 objects) and zero it out
  33.    scene->objects = (sceneobject_t *) SAFE_malloc (3, sizeof (sceneobject_t), true);
  34.  
  35.    // insert the table edges, the table and the board
  36.    scene->objects[0].mesh_index = theme->trim_meshindex;
  37.    scene->objects[0].texture_index = theme->trim_texture;
  38.    scene->objects[0].scale = 1.0f;
  39.    scene->objects[1].mesh_index = theme->table_meshindex;
  40.    scene->objects[1].texture_index = theme->table_texture;
  41.    scene->objects[1].scale = 1.0f;
  42.    scene->objects[2].mesh_index = theme->board_meshindex;
  43.    scene->objects[2].texture_index = theme->board_texture;
  44.    scene->objects[2].scale = 1.0f;
  45.    scene->object_count = 3;
  46.  
  47.    // reset the camera position for a cool slide-in effect, but only if autorotate is enabled
  48.    if (options.want_autorotateon1vs1)
  49.    {
  50.       current_pitch = 6.0f; // autorotate is enabled, prepare for slide-in effect
  51.       current_yaw = (Board_ColorToMove (board) == COLOR_WHITE ? 90.0f : -90.0f);
  52.       current_distance = 40.0f;
  53.    }
  54.    else
  55.    {
  56.       current_pitch = 55.0f; // no autorotate, reset to standard view position directly
  57.       current_yaw = (Board_ColorToMove (board) == COLOR_BLACK ? 90.0f : -90.0f);
  58.       current_distance = 70.0f;
  59.    }
  60.  
  61.    // HACK to prevent the player to click and block the view angles while the slide-in is not finished
  62.    command_ignoretime = current_time + 2.0f; // allow 2 seconds
  63.  
  64.    // build the connected comment string (we use it as a global variable)
  65.    wcscpy_s (format_string, WCHAR_SIZEOF (format_string), LOCALIZE (L"YouAreConnectedToX"));
  66.    wcscat_s (format_string, WCHAR_SIZEOF (format_string), L"\n");
  67.    wcscat_s (format_string, WCHAR_SIZEOF (format_string), LOCALIZE (L"YouMayEitherDisplayThePlayersListOrTheSoughtGamesList"));
  68.    wcscat_s (format_string, WCHAR_SIZEOF (format_string), L"\n");
  69.    wcscat_s (format_string, WCHAR_SIZEOF (format_string), LOCALIZE (L"PleaseReferToTheInternetMenu"));
  70.    swprintf_s (connected_comment, WCHAR_SIZEOF (connected_comment), format_string, options.network.server_address);
  71.  
  72.    // completely reset the whole GUI structure so as to NULL out all pointers
  73.    memset (&scene->gui, 0, sizeof (scene->gui));
  74.  
  75.    // set the buttons locations
  76.    Scene_SetButton (&scene->gui.larrow, 0.3f, 0.5f, 3.0f, 4.0f, larrow_spriteindex);
  77.    Scene_SetButton (&scene->gui.rarrow, 3.3f, 0.5f, 3.0f, 4.0f, rarrow_spriteindex);
  78.    Scene_SetButton (&scene->gui.chatbutton, 1.0f, 10.0f, 10.0f, 13.0f, chatbutton_spriteindex);
  79.    Scene_SetButton (&scene->gui.gamesbutton, 1.0f, 35.0f, 10.0f, 13.0f, gamesbutton_spriteindex);
  80.    Scene_SetButton (&scene->gui.peoplebutton, 1.0f, 60.0f, 10.0f, 13.0f, peoplebutton_spriteindex);
  81.  
  82.    // remember to update the scene
  83.    scene->update = true;
  84.  
  85.    return; // finished
  86. }
  87.  
  88.  
  89. void Scene_Shutdown (scene_t *scene)
  90. {
  91.    // this function frees the memory space allocated for the 3D scene and clears its pointers
  92.  
  93.    int cchistory_index;
  94.  
  95.    // free GUI mallocated buffers
  96.    SAFE_free ((void **) &scene->gui.arrow_text.buffer);
  97.    scene->gui.arrow_text.is_displayed = false;
  98.    SAFE_free ((void **) &scene->gui.comment_text.buffer);
  99.    scene->gui.comment_text.is_displayed = false;
  100.    SAFE_free ((void **) &scene->gui.history_text.buffer);
  101.    scene->gui.history_text.is_displayed = false;
  102.    SAFE_free ((void **) &scene->gui.clock_text.buffer);
  103.    scene->gui.clock_text.is_displayed = false;
  104.    SAFE_free ((void **) &scene->gui.turn_text.buffer);
  105.    scene->gui.turn_text.is_displayed = false;
  106.    SAFE_free ((void **) &scene->gui.central_text.buffer);
  107.    scene->gui.central_text.is_displayed = false;
  108.  
  109.    // for each entry in the CC history...
  110.    for (cchistory_index = 0; cchistory_index < scene->gui.cchistory_count; cchistory_index++)
  111.       SAFE_free ((void **) &scene->gui.cchistory[cchistory_index].text); // free its text buffer
  112.    SAFE_free ((void **) &scene->gui.cchistory); // free the GUI's CC history
  113.    scene->gui.cchistory_count = 0;
  114.  
  115.    SAFE_free ((void **) &scene->objects); // free the scene objects array
  116.    scene->object_count = 0;
  117.  
  118.    return; // finished
  119. }
  120.  
  121.  
  122. void Scene_Update (scene_t *scene, board_t *board)
  123. {
  124.    // this function updates the scene objects to display with what's currently on the board
  125.  
  126.    static bool rooksound_played = false; // hack to have two sounds when a king castles
  127.  
  128.    boardslot_t *boardslot;
  129.    boardmove_t *currentmove;
  130.    player_t *local_player;
  131.    player_t *network_player;
  132.    player_t *current_player;
  133.    player_t *opposite_player;
  134.    wchar_t *history_text; // mallocated
  135.    int historytext_size;
  136.    unsigned char takenpart_type;
  137.    int movement_direction;
  138.    int line;
  139.    int column;
  140.    int pos_index;
  141.    int part_index;
  142.    int move_index;
  143.    int start_index;
  144.    int length;
  145.    int threat_line;
  146.    int threat_column;
  147.    int minutes;
  148.    int seconds;
  149.    float flaticons_yaw;
  150.    float source_x;
  151.    float source_y;
  152.    float target_x;
  153.    float target_y;
  154.    float current_x;
  155.    float current_y;
  156.    float current_z;
  157.    int movement_diffco;
  158.    int movement_diffli;
  159.    float movement_maxheight;
  160.    float movement_ratio;
  161.  
  162.    // get the current player (we'll need it), its opponent and see if we're online
  163.    current_player = Player_GetCurrent ();
  164.    opposite_player = Player_GetOpposite ();
  165.    network_player = Player_FindByType (PLAYER_INTERNET);
  166.  
  167.    // determine display yaw (for flat icons) according to camera angle
  168.    if ((current_yaw > 45.0f) && (current_yaw <= 135.0f))
  169.       flaticons_yaw = 180.0f;
  170.    else if ((current_yaw > -45.0f) && (current_yaw <= 45.0f))
  171.       flaticons_yaw = 90.0f;
  172.    else if ((current_yaw > -135.0f) && (current_yaw <= -45.0f))
  173.       flaticons_yaw = 0.0f;
  174.    else
  175.       flaticons_yaw = -90.0f;
  176.  
  177.    // get the current move
  178.    currentmove = &board->moves[board->viewed_move]; // quick access to current move
  179.  
  180.    // fetch the background sprite from the theme
  181.    if (want_custombackground)
  182.       scene->background_spriteindex = custombg.sprite_index; // use the custom background if specified
  183.    else
  184.       scene->background_spriteindex = theme->bg.sprite_index; // else use the theme's supplied background
  185.  
  186.    // shrink the scene objects array to leave just the board (3 objects)
  187.    scene->objects = (sceneobject_t *) SAFE_realloc (scene->objects, scene->object_count, 3, sizeof (sceneobject_t), false);
  188.    scene->object_count = 3;
  189.  
  190.    // update the board theme
  191.    scene->objects[0].mesh_index = theme->trim_meshindex;
  192.    scene->objects[0].texture_index = theme->trim_texture;
  193.    scene->objects[0].material_index = theme->trim_material;
  194.    scene->objects[0].scale = 1.0f;
  195.    scene->objects[1].mesh_index = theme->table_meshindex;
  196.    scene->objects[1].texture_index = theme->table_texture;
  197.    scene->objects[1].material_index = theme->table_material;
  198.    scene->objects[1].scale = 1.0f;
  199.    scene->objects[2].mesh_index = theme->board_meshindex;
  200.    scene->objects[2].texture_index = theme->board_texture;
  201.    scene->objects[2].material_index = theme->board_material;
  202.    scene->objects[2].scale = 1.0f;
  203.  
  204.    // draw the grid numbers if we want them
  205.    if (want_grid)
  206.       Scene_AddTile (scene, theme->grid_texture, 30.0f, 0.0f, 0.0f, 0.01f, 0.0f);
  207.  
  208.    ////////////////////////////////////////////////////////////////////////////////////////////////
  209.    // recompute the slot textures (only in play mode when we render the real board)
  210.  
  211.    // erase all the slot flags
  212.    for (line = 0; line < 8; line++)
  213.       for (column = 0; column < 8; column++)
  214.          currentmove->slots[line][column].flags = FLAG_NONE; // because we will recompute them
  215.  
  216.    // cycle through all the grid again and see if either king is in check
  217.    for (line = 0; line < 8; line++)
  218.       for (column = 0; column < 8; column++)
  219.       {
  220.          boardslot = &currentmove->slots[line][column]; // quick access to grid slot
  221.  
  222.          if (boardslot->part != PART_KING)
  223.             continue; // if this slot is not a king, skip it
  224.  
  225.          // is this king currently threatened ?
  226.          if (Move_IsKingThreatenedAtLocation (currentmove, boardslot->color, line, column, &threat_line, &threat_column))
  227.          {
  228.             currentmove->slots[line][column].flags |= FLAG_CHECK; // mark it as threatened
  229.             currentmove->slots[threat_line][threat_column].flags |= FLAG_THREAT; // and who threatens it
  230.          }
  231.       }
  232.  
  233.    // are we in play mode ? i.e, are we rendering the last move ?
  234.    if (board->viewed_move == board->move_count - 1)
  235.    {
  236.       // mark the selected position as selected
  237.       if (IS_VALID_POSITION (board->selected_position))
  238.          currentmove->slots[board->selected_position[0]][board->selected_position[1]].flags |= FLAG_SELECTED;
  239.  
  240.       // now cycle through all the grid again and see if some slots need to be coloured
  241.       for (line = 0; line < 8; line++)
  242.          for (column = 0; column < 8; column++)
  243.          {
  244.             boardslot = &currentmove->slots[line][column]; // quick access to grid slot
  245.  
  246.             if (!(boardslot->flags & FLAG_SELECTED))
  247.                continue; // if this slot is not selected, skip it
  248.  
  249.             //////////////////////////////////////////////////////////////////////////////////////////
  250.             ////////////////////////////////////////// PAWN //////////////////////////////////////////
  251.             //////////////////////////////////////////////////////////////////////////////////////////
  252.             // is it a pawn ?
  253.             if (boardslot->part == PART_PAWN)
  254.             {
  255.                // figure out movement direction
  256.                if (boardslot->color == COLOR_WHITE)
  257.                   movement_direction = 1;
  258.                else
  259.                   movement_direction = -1;
  260.  
  261.                // if pawn has still room to move forward, it can
  262.                if ((((line < 7) && (movement_direction == 1)) || ((line > 0) && (movement_direction == -1)))
  263.                    && (currentmove->slots[line + movement_direction][column].part == PART_NONE))
  264.                {
  265.                   currentmove->slots[line + movement_direction][column].flags |= FLAG_POSSIBLEMOVE;
  266.  
  267.                   // if pawn is still in its initial slot, it can move twice forward
  268.                   if ((((line == 1) && (movement_direction == 1)) || ((line == 6) && (movement_direction == -1)))
  269.                       && (currentmove->slots[line + movement_direction * 2][column].part == PART_NONE))
  270.                      currentmove->slots[line + movement_direction * 2][column].flags |= FLAG_POSSIBLEMOVE;
  271.                }
  272.  
  273.                // see if pawn can take a piece on its left
  274.                if ((column > 0) && (currentmove->slots[line + movement_direction][column - 1].part != PART_NONE)
  275.                    && (currentmove->slots[line + movement_direction][column - 1].color != currentmove->slots[line][column].color))
  276.                   currentmove->slots[line + movement_direction][column - 1].flags |= FLAG_TAKEABLE;
  277.  
  278.                // see if pawn can take a piece on its right
  279.                if ((column < 7) && (currentmove->slots[line + movement_direction][column + 1].part != PART_NONE)
  280.                    && (currentmove->slots[line + movement_direction][column + 1].color != currentmove->slots[line][column].color))
  281.                   currentmove->slots[line + movement_direction][column + 1].flags |= FLAG_TAKEABLE;
  282.  
  283.                // if previous move was a pawn rush, see if pawn can take "en passant"
  284.                if ((currentmove->part == PART_PAWN)
  285.                      && (currentmove->target[1] == currentmove->source[1]) // pawn moved in column
  286.                      && (abs (currentmove->target[0] - currentmove->source[0]) == 2) // pawn rushed
  287.                      && (currentmove->target[0] == line) // pawn is in line with us
  288.                      && (abs (currentmove->target[1] - column) == 1)) // pawn is next to us
  289.                   currentmove->slots[line + movement_direction][currentmove->target[1]].flags |= FLAG_TAKEABLE;
  290.             }
  291.  
  292.             //////////////////////////////////////////////////////////////////////////////////////////
  293.             ////////////////////////////////////////// ROOK //////////////////////////////////////////
  294.             //////////////////////////////////////////////////////////////////////////////////////////
  295.             // else is it a rook ?
  296.             else if (boardslot->part == PART_ROOK)
  297.             {
  298.                // see how far rook can move upwards
  299.                for (pos_index = line + 1; pos_index < 8; pos_index++)
  300.                {
  301.                   if (currentmove->slots[pos_index][column].part != PART_NONE)
  302.                   {
  303.                      if (currentmove->slots[pos_index][column].color != currentmove->slots[line][column].color)
  304.                         currentmove->slots[pos_index][column].flags |= FLAG_TAKEABLE;
  305.                      break;
  306.                   }
  307.                   currentmove->slots[pos_index][column].flags |= FLAG_POSSIBLEMOVE;
  308.                }
  309.  
  310.                // see how far rook can move downwards
  311.                for (pos_index = line - 1; pos_index >= 0; pos_index--)
  312.                {
  313.                   if (currentmove->slots[pos_index][column].part != PART_NONE)
  314.                   {
  315.                      if (currentmove->slots[pos_index][column].color != currentmove->slots[line][column].color)
  316.                         currentmove->slots[pos_index][column].flags |= FLAG_TAKEABLE;
  317.                      break;
  318.                   }
  319.                   currentmove->slots[pos_index][column].flags |= FLAG_POSSIBLEMOVE;
  320.                }
  321.  
  322.                // see how far rook can move left
  323.                for (pos_index = column - 1; pos_index >= 0; pos_index--)
  324.                {
  325.                   if (currentmove->slots[line][pos_index].part != PART_NONE)
  326.                   {
  327.                      if (currentmove->slots[line][pos_index].color != currentmove->slots[line][column].color)
  328.                         currentmove->slots[line][pos_index].flags |= FLAG_TAKEABLE;
  329.                      break;
  330.                   }
  331.                   currentmove->slots[line][pos_index].flags |= FLAG_POSSIBLEMOVE;
  332.                }
  333.  
  334.                // see how far rook can move right
  335.                for (pos_index = column + 1; pos_index < 8; pos_index++)
  336.                {
  337.                   if (currentmove->slots[line][pos_index].part != PART_NONE)
  338.                   {
  339.                      if (currentmove->slots[line][pos_index].color != currentmove->slots[line][column].color)
  340.                         currentmove->slots[line][pos_index].flags |= FLAG_TAKEABLE;
  341.                      break;
  342.                   }
  343.                   currentmove->slots[line][pos_index].flags |= FLAG_POSSIBLEMOVE;
  344.                }
  345.             }
  346.  
  347.             //////////////////////////////////////////////////////////////////////////////////////////
  348.             ///////////////////////////////////////// KNIGHT /////////////////////////////////////////
  349.             //////////////////////////////////////////////////////////////////////////////////////////
  350.             // else is it a knight ?
  351.             else if (boardslot->part == PART_KNIGHT)
  352.             {
  353.                // peek knight's NNW move
  354.                if ((column > 0) && (line < 6))
  355.                   if (currentmove->slots[line + 2][column - 1].part == PART_NONE)
  356.                      currentmove->slots[line + 2][column - 1].flags |= FLAG_POSSIBLEMOVE;
  357.                   else if (currentmove->slots[line + 2][column - 1].color != currentmove->slots[line][column].color)
  358.                      currentmove->slots[line + 2][column - 1].flags |= FLAG_TAKEABLE;
  359.  
  360.                // peek knight's NNE move
  361.                if ((column < 7) && (line < 6))
  362.                   if (currentmove->slots[line + 2][column + 1].part == PART_NONE)
  363.                      currentmove->slots[line + 2][column + 1].flags |= FLAG_POSSIBLEMOVE;
  364.                   else if (currentmove->slots[line + 2][column + 1].color != currentmove->slots[line][column].color)
  365.                      currentmove->slots[line + 2][column + 1].flags |= FLAG_TAKEABLE;
  366.  
  367.                // peek knight's ENE move
  368.                if ((column < 6) && (line < 7))
  369.                   if (currentmove->slots[line + 1][column + 2].part == PART_NONE)
  370.                      currentmove->slots[line + 1][column + 2].flags |= FLAG_POSSIBLEMOVE;
  371.                   else if (currentmove->slots[line + 1][column + 2].color != currentmove->slots[line][column].color)
  372.                      currentmove->slots[line + 1][column + 2].flags |= FLAG_TAKEABLE;
  373.  
  374.                // peek knight's ESE move
  375.                if ((column < 6) && (line > 0))
  376.                   if (currentmove->slots[line - 1][column + 2].part == PART_NONE)
  377.                      currentmove->slots[line - 1][column + 2].flags |= FLAG_POSSIBLEMOVE;
  378.                   else if (currentmove->slots[line - 1][column + 2].color != currentmove->slots[line][column].color)
  379.                      currentmove->slots[line - 1][column + 2].flags |= FLAG_TAKEABLE;
  380.  
  381.                // peek knight's SSW move
  382.                if ((column > 0) && (line > 1))
  383.                   if (currentmove->slots[line - 2][column - 1].part == PART_NONE)
  384.                      currentmove->slots[line - 2][column - 1].flags |= FLAG_POSSIBLEMOVE;
  385.                   else if (currentmove->slots[line - 2][column - 1].color != currentmove->slots[line][column].color)
  386.                      currentmove->slots[line - 2][column - 1].flags |= FLAG_TAKEABLE;
  387.  
  388.                // peek knight's SSE move
  389.                if ((column < 7) && (line > 1))
  390.                   if (currentmove->slots[line - 2][column + 1].part == PART_NONE)
  391.                      currentmove->slots[line - 2][column + 1].flags |= FLAG_POSSIBLEMOVE;
  392.                   else if (currentmove->slots[line - 2][column + 1].color != currentmove->slots[line][column].color)
  393.                      currentmove->slots[line - 2][column + 1].flags |= FLAG_TAKEABLE;
  394.  
  395.                // peek knight's WNW move
  396.                if ((column > 1) && (line < 7))
  397.                   if (currentmove->slots[line + 1][column - 2].part == PART_NONE)
  398.                      currentmove->slots[line + 1][column - 2].flags |= FLAG_POSSIBLEMOVE;
  399.                   else if (currentmove->slots[line + 1][column - 2].color != currentmove->slots[line][column].color)
  400.                      currentmove->slots[line + 1][column - 2].flags |= FLAG_TAKEABLE;
  401.  
  402.                // peek knight's WSW move
  403.                if ((column > 1) && (line > 0))
  404.                   if (currentmove->slots[line - 1][column - 2].part == PART_NONE)
  405.                      currentmove->slots[line - 1][column - 2].flags |= FLAG_POSSIBLEMOVE;
  406.                   else if (currentmove->slots[line - 1][column - 2].color != currentmove->slots[line][column].color)
  407.                      currentmove->slots[line - 1][column - 2].flags |= FLAG_TAKEABLE;
  408.             }
  409.  
  410.             //////////////////////////////////////////////////////////////////////////////////////////
  411.             ///////////////////////////////////////// BISHOP /////////////////////////////////////////
  412.             //////////////////////////////////////////////////////////////////////////////////////////
  413.             // else is it a bishop ?
  414.             else if (boardslot->part == PART_BISHOP)
  415.             {
  416.                // see how far bishop can move NE
  417.                for (pos_index = 1; pos_index < 8; pos_index++)
  418.                {
  419.                   if ((line + pos_index > 7) || (column + pos_index > 7))
  420.                      break;
  421.                   if (currentmove->slots[line + pos_index][column + pos_index].part != PART_NONE)
  422.                   {
  423.                      if (currentmove->slots[line + pos_index][column + pos_index].color != currentmove->slots[line][column].color)
  424.                         currentmove->slots[line + pos_index][column + pos_index].flags |= FLAG_TAKEABLE;
  425.                      break;
  426.                   }
  427.                   currentmove->slots[line + pos_index][column + pos_index].flags |= FLAG_POSSIBLEMOVE;
  428.                }
  429.  
  430.                // see how far bishop can move SE
  431.                for (pos_index = 1; pos_index < 8; pos_index++)
  432.                {
  433.                   if ((line - pos_index < 0) || (column + pos_index > 7))
  434.                      break;
  435.                   if (currentmove->slots[line - pos_index][column + pos_index].part != PART_NONE)
  436.                   {
  437.                      if (currentmove->slots[line - pos_index][column + pos_index].color != currentmove->slots[line][column].color)
  438.                         currentmove->slots[line - pos_index][column + pos_index].flags |= FLAG_TAKEABLE;
  439.                      break;
  440.                   }
  441.                   currentmove->slots[line - pos_index][column + pos_index].flags |= FLAG_POSSIBLEMOVE;
  442.                }
  443.  
  444.                // see how far bishop can move NW
  445.                for (pos_index = 1; pos_index < 8; pos_index++)
  446.                {
  447.                   if ((line + pos_index > 7) || (column - pos_index < 0))
  448.                      break;
  449.                   if (currentmove->slots[line + pos_index][column - pos_index].part != PART_NONE)
  450.                   {
  451.                      if (currentmove->slots[line + pos_index][column - pos_index].color != currentmove->slots[line][column].color)
  452.                         currentmove->slots[line + pos_index][column - pos_index].flags |= FLAG_TAKEABLE;
  453.                      break;
  454.                   }
  455.                   currentmove->slots[line + pos_index][column - pos_index].flags |= FLAG_POSSIBLEMOVE;
  456.                }
  457.  
  458.                // see how far bishop can move SW
  459.                for (pos_index = 1; pos_index < 8; pos_index++)
  460.                {
  461.                   if ((line - pos_index < 0) || (column - pos_index < 0))
  462.                      break;
  463.                   if (currentmove->slots[line - pos_index][column - pos_index].part != PART_NONE)
  464.                   {
  465.                      if (currentmove->slots[line - pos_index][column - pos_index].color != currentmove->slots[line][column].color)
  466.                         currentmove->slots[line - pos_index][column - pos_index].flags |= FLAG_TAKEABLE;
  467.                      break;
  468.                   }
  469.                   currentmove->slots[line - pos_index][column - pos_index].flags |= FLAG_POSSIBLEMOVE;
  470.                }
  471.             }
  472.  
  473.             //////////////////////////////////////////////////////////////////////////////////////////
  474.             ///////////////////////////////////////// QUEEN //////////////////////////////////////////
  475.             //////////////////////////////////////////////////////////////////////////////////////////
  476.             // else is it a queen ?
  477.             else if (boardslot->part == PART_QUEEN)
  478.             {
  479.                // see how far queen can move NE
  480.                for (pos_index = 1; pos_index < 8; pos_index++)
  481.                {
  482.                   if ((line + pos_index > 7) || (column + pos_index > 7))
  483.                      break;
  484.                   if (currentmove->slots[line + pos_index][column + pos_index].part != PART_NONE)
  485.                   {
  486.                      if (currentmove->slots[line + pos_index][column + pos_index].color != currentmove->slots[line][column].color)
  487.                         currentmove->slots[line + pos_index][column + pos_index].flags |= FLAG_TAKEABLE;
  488.                      break;
  489.                   }
  490.                   currentmove->slots[line + pos_index][column + pos_index].flags |= FLAG_POSSIBLEMOVE;
  491.                }
  492.  
  493.                // see how far queen can move SE
  494.                for (pos_index = 1; pos_index < 8; pos_index++)
  495.                {
  496.                   if ((line - pos_index < 0) || (column + pos_index > 7))
  497.                      break;
  498.                   if (currentmove->slots[line - pos_index][column + pos_index].part != PART_NONE)
  499.                   {
  500.                      if (currentmove->slots[line - pos_index][column + pos_index].color != currentmove->slots[line][column].color)
  501.                         currentmove->slots[line - pos_index][column + pos_index].flags |= FLAG_TAKEABLE;
  502.                      break;
  503.                   }
  504.                   currentmove->slots[line - pos_index][column + pos_index].flags |= FLAG_POSSIBLEMOVE;
  505.                }
  506.  
  507.                // see how far queen can move NW
  508.                for (pos_index = 1; pos_index < 8; pos_index++)
  509.                {
  510.                   if ((line + pos_index > 7) || (column - pos_index < 0))
  511.                      break;
  512.                   if (currentmove->slots[line + pos_index][column - pos_index].part != PART_NONE)
  513.                   {
  514.                      if (currentmove->slots[line + pos_index][column - pos_index].color != currentmove->slots[line][column].color)
  515.                         currentmove->slots[line + pos_index][column - pos_index].flags |= FLAG_TAKEABLE;
  516.                      break;
  517.                   }
  518.                   currentmove->slots[line + pos_index][column - pos_index].flags |= FLAG_POSSIBLEMOVE;
  519.                }
  520.  
  521.                // see how far queen can move SW
  522.                for (pos_index = 1; pos_index < 8; pos_index++)
  523.                {
  524.                   if ((line - pos_index < 0) || (column - pos_index < 0))
  525.                      break;
  526.                   if (currentmove->slots[line - pos_index][column - pos_index].part != PART_NONE)
  527.                   {
  528.                      if (currentmove->slots[line - pos_index][column - pos_index].color != currentmove->slots[line][column].color)
  529.                         currentmove->slots[line - pos_index][column - pos_index].flags |= FLAG_TAKEABLE;
  530.                      break;
  531.                   }
  532.                   currentmove->slots[line - pos_index][column - pos_index].flags |= FLAG_POSSIBLEMOVE;
  533.                }
  534.  
  535.                // see how far queen can move upwards
  536.                for (pos_index = line + 1; pos_index < 8; pos_index++)
  537.                {
  538.                   if (currentmove->slots[pos_index][column].part != PART_NONE)
  539.                   {
  540.                      if (currentmove->slots[pos_index][column].color != currentmove->slots[line][column].color)
  541.                         currentmove->slots[pos_index][column].flags |= FLAG_TAKEABLE;
  542.                      break;
  543.                   }
  544.                   currentmove->slots[pos_index][column].flags |= FLAG_POSSIBLEMOVE;
  545.                }
  546.  
  547.                // see how far queen can move downwards
  548.                for (pos_index = line - 1; pos_index >= 0; pos_index--)
  549.                {
  550.                   if (currentmove->slots[pos_index][column].part != PART_NONE)
  551.                   {
  552.                      if (currentmove->slots[pos_index][column].color != currentmove->slots[line][column].color)
  553.                         currentmove->slots[pos_index][column].flags |= FLAG_TAKEABLE;
  554.                      break;
  555.                   }
  556.                   currentmove->slots[pos_index][column].flags |= FLAG_POSSIBLEMOVE;
  557.                }
  558.  
  559.                // see how far queen can move left
  560.                for (pos_index = column - 1; pos_index >= 0; pos_index--)
  561.                {
  562.                   if (currentmove->slots[line][pos_index].part != PART_NONE)
  563.                   {
  564.                      if (currentmove->slots[line][pos_index].color != currentmove->slots[line][column].color)
  565.                         currentmove->slots[line][pos_index].flags |= FLAG_TAKEABLE;
  566.                      break;
  567.                   }
  568.                   currentmove->slots[line][pos_index].flags |= FLAG_POSSIBLEMOVE;
  569.                }
  570.  
  571.                // see how far queen can move right
  572.                for (pos_index = column + 1; pos_index < 8; pos_index++)
  573.                {
  574.                   if (currentmove->slots[line][pos_index].part != PART_NONE)
  575.                   {
  576.                      if (currentmove->slots[line][pos_index].color != currentmove->slots[line][column].color)
  577.                         currentmove->slots[line][pos_index].flags |= FLAG_TAKEABLE;
  578.                      break;
  579.                   }
  580.                   currentmove->slots[line][pos_index].flags |= FLAG_POSSIBLEMOVE;
  581.                }
  582.             }
  583.  
  584.             //////////////////////////////////////////////////////////////////////////////////////////
  585.             ////////////////////////////////////////// KING //////////////////////////////////////////
  586.             //////////////////////////////////////////////////////////////////////////////////////////
  587.             // else is it a king ?
  588.             else if (boardslot->part == PART_KING)
  589.             {
  590.                // see if king can move NE
  591.                if ((line < 7) && (column < 7))
  592.                {
  593.                   if (currentmove->slots[line + 1][column + 1].part == PART_NONE)
  594.                      currentmove->slots[line + 1][column + 1].flags |= FLAG_POSSIBLEMOVE;
  595.                   else if (currentmove->slots[line + 1][column + 1].color != currentmove->slots[line][column].color)
  596.                      currentmove->slots[line + 1][column + 1].flags |= FLAG_TAKEABLE;
  597.                }
  598.  
  599.                // see if king can move SE
  600.                if ((line > 0) && (column < 7))
  601.                {
  602.                   if (currentmove->slots[line - 1][column + 1].part == PART_NONE)
  603.                      currentmove->slots[line - 1][column + 1].flags |= FLAG_POSSIBLEMOVE;
  604.                   else if (currentmove->slots[line - 1][column + 1].color != currentmove->slots[line][column].color)
  605.                      currentmove->slots[line - 1][column + 1].flags |= FLAG_TAKEABLE;
  606.                }
  607.  
  608.                // see if king can move NW
  609.                if ((line < 7) && (column > 0))
  610.                {
  611.                   if (currentmove->slots[line + 1][column - 1].part == PART_NONE)
  612.                      currentmove->slots[line + 1][column - 1].flags |= FLAG_POSSIBLEMOVE;
  613.                   else if (currentmove->slots[line + 1][column - 1].color != currentmove->slots[line][column].color)
  614.                      currentmove->slots[line + 1][column - 1].flags |= FLAG_TAKEABLE;
  615.                }
  616.  
  617.                // see if king can move SW
  618.                if ((line > 0) && (column > 0))
  619.                {
  620.                   if (currentmove->slots[line - 1][column - 1].part == PART_NONE)
  621.                      currentmove->slots[line - 1][column - 1].flags |= FLAG_POSSIBLEMOVE;
  622.                   else if (currentmove->slots[line - 1][column - 1].color != currentmove->slots[line][column].color)
  623.                      currentmove->slots[line - 1][column - 1].flags |= FLAG_TAKEABLE;
  624.                }
  625.  
  626.                // see if king can move upwards
  627.                if (line < 7)
  628.                {
  629.                   if (currentmove->slots[line + 1][column].part == PART_NONE)
  630.                      currentmove->slots[line + 1][column].flags |= FLAG_POSSIBLEMOVE;
  631.                   else if (currentmove->slots[line + 1][column].color != currentmove->slots[line][column].color)
  632.                      currentmove->slots[line + 1][column].flags |= FLAG_TAKEABLE;
  633.                }
  634.  
  635.                // see if king can move downwards
  636.                if (line > 0)
  637.                {
  638.                   if (currentmove->slots[line - 1][column].part == PART_NONE)
  639.                      currentmove->slots[line - 1][column].flags |= FLAG_POSSIBLEMOVE;
  640.                   else if (currentmove->slots[line - 1][column].color != currentmove->slots[line][column].color)
  641.                      currentmove->slots[line - 1][column].flags |= FLAG_TAKEABLE;
  642.                }
  643.  
  644.                // see if king can move right
  645.                if (column < 7)
  646.                {
  647.                   if (currentmove->slots[line][column + 1].part == PART_NONE)
  648.                      currentmove->slots[line][column + 1].flags |= FLAG_POSSIBLEMOVE;
  649.                   else if (currentmove->slots[line][column + 1].color != currentmove->slots[line][column].color)
  650.                      currentmove->slots[line][column + 1].flags |= FLAG_TAKEABLE;
  651.                }
  652.  
  653.                // see if king can move left
  654.                if (column > 0)
  655.                {
  656.                   if (currentmove->slots[line][column - 1].part == PART_NONE)
  657.                      currentmove->slots[line][column - 1].flags |= FLAG_POSSIBLEMOVE;
  658.                   else if (currentmove->slots[line][column - 1].color != currentmove->slots[line][column].color)
  659.                      currentmove->slots[line][column - 1].flags |= FLAG_TAKEABLE;
  660.                }
  661.  
  662.                // can king castle bishopside ?
  663.                if (currentmove->sides[boardslot->color].shortcastle_allowed // no parts have moved yet
  664.                    && (currentmove->slots[line][5].part == PART_NONE) // no other part...
  665.                    && (currentmove->slots[line][6].part == PART_NONE) // ...in the way
  666.                    && !Move_IsCheck (currentmove, boardslot->color) // king not currently in check
  667.                    && !Move_IsKingThreatenedAtLocation (currentmove, boardslot->color, line, 5, &threat_line, &threat_column)) // king's way safe
  668.                   currentmove->slots[line][column + 2].flags |= FLAG_POSSIBLEMOVE; // allow castling bishopside
  669.  
  670.                // can king castle queenside ?
  671.                if (currentmove->sides[boardslot->color].longcastle_allowed // no parts have moved yet
  672.                    && (currentmove->slots[line][3].part == PART_NONE) // no other part...
  673.                    && (currentmove->slots[line][2].part == PART_NONE) // ...is...
  674.                    && (currentmove->slots[line][1].part == PART_NONE) // ...in the way
  675.                    && !Move_IsCheck (currentmove, boardslot->color) // king not currently in check
  676.                    && !Move_IsKingThreatenedAtLocation (currentmove, boardslot->color, line, 3, &threat_line, &threat_column)) // king's way safe
  677.                   currentmove->slots[line][column - 2].flags |= FLAG_POSSIBLEMOVE; // allow castling queenside
  678.             }
  679.          }
  680.    } // end if (play mode)
  681.  
  682.    ////////////////////////////////////////////////////////////////////////////////////////////////
  683.    // now place the parts that are off-board (taken parts)
  684.  
  685.    // but only if we want them displayed
  686.    if (options.want_takenparts)
  687.    {
  688.       // draw the white player's taken parts, place the part off the board (watch out for the hack...)
  689.       for (part_index = 0; part_index < currentmove->sides[COLOR_WHITE].takenpart_count; part_index++)
  690.       {
  691.          takenpart_type = currentmove->sides[COLOR_WHITE].takenparts[part_index];
  692.  
  693.          // do we want the 3D models or the flat icons ?
  694.          // we do when EITHER we don't want flat icons OR the current player is looking downstraight
  695.          if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  696.             Scene_AddPart (scene, takenpart_type, COLOR_BLACK, (part_index < MAX_STACKABLE_PARTS ? 23.2f : 26.8f),
  697.                            (part_index % MAX_STACKABLE_PARTS == 0 ? 23.2f : scene->objects[scene->object_count - 1].y - (scene->objects[scene->object_count - 1].simpleshadow_size + simpleshadow_sizes[takenpart_type]) * 0.75f),
  698.                            0.04f, (takenpart_type == PART_PAWN ? -90.0f : 100.0f), 0.0f); // rotate pawns 90°
  699.          else
  700.             Scene_AddTile (scene, theme->flattextures[COLOR_BLACK][takenpart_type], 1.25f, (part_index < MAX_STACKABLE_PARTS ? 23.2f : 26.8f),
  701.                            20.0f - (part_index < MAX_STACKABLE_PARTS ? part_index : (part_index - MAX_STACKABLE_PARTS)) * 2.5f, 0.07f, flaticons_yaw);
  702.       }
  703.  
  704.       // now draw the black player's taken parts, place the part off the board (watch out for the hack...)
  705.       for (part_index = 0; part_index < currentmove->sides[COLOR_BLACK].takenpart_count; part_index++)
  706.       {
  707.          takenpart_type = currentmove->sides[COLOR_BLACK].takenparts[part_index];
  708.  
  709.          // do we want the 3D models or the flat icons ?
  710.          // we do when EITHER we don't want flat icons OR the current player is looking downstraight
  711.          if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  712.             Scene_AddPart (scene, takenpart_type, COLOR_WHITE, (part_index < MAX_STACKABLE_PARTS ? -23.2f : -26.8f),
  713.                            (part_index % MAX_STACKABLE_PARTS == 0 ? -23.2f : scene->objects[scene->object_count - 1].y + (scene->objects[scene->object_count - 1].simpleshadow_size + simpleshadow_sizes[takenpart_type]) * 0.75f),
  714.                            0.04f, (takenpart_type == PART_PAWN ? -90.0f : 100.0f), 0.0f); // rotate pawns 90°
  715.          else
  716.             Scene_AddTile (scene, theme->flattextures[COLOR_WHITE][takenpart_type], 1.25f, (part_index < MAX_STACKABLE_PARTS ? -23.2f : -26.8f),
  717.                            -20.0f + (part_index < MAX_STACKABLE_PARTS ? part_index : (part_index - MAX_STACKABLE_PARTS)) * 2.5f, 0.07f, flaticons_yaw);
  718.       }
  719.    }
  720.  
  721.    ////////////////////////////////////////////////////////////////////////////////////////////////
  722.    // now draw the textured slots
  723.  
  724.    // cycle through all the board slots...
  725.    for (line = 0; line < 8; line++)
  726.       for (column = 0; column < 8; column++)
  727.       {
  728.          if (currentmove->slots[line][column].flags == FLAG_NONE)
  729.             continue; // skip everything that doesn't need to be drawn
  730.  
  731.          // draw the texture we want. Only one texture is allowed, so PRIORITY MATTERS.
  732.          if (currentmove->slots[line][column].flags & FLAG_SELECTED)
  733.             Scene_AddTile (scene, theme->selected_textureindex, 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.02f, 0.0f);
  734.          else if (options.want_threats && currentmove->slots[line][column].flags & FLAG_CHECK)
  735.             Scene_AddTile (scene, theme->check_textureindex, 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.02f, 0.0f);
  736.          else if (options.want_possiblemoves && currentmove->slots[line][column].flags & FLAG_POSSIBLEMOVE)
  737.             Scene_AddTile (scene, theme->possiblemove_textureindex, 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.02f, 0.0f);
  738.          else if (options.want_possiblemoves && currentmove->slots[line][column].flags & FLAG_TAKEABLE)
  739.             Scene_AddTile (scene, theme->takeable_textureindex, 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.02f, 0.0f);
  740.          else if (options.want_threats && currentmove->slots[line][column].flags & FLAG_THREAT)
  741.             Scene_AddTile (scene, theme->threat_textureindex, 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.02f, 0.0f);
  742.       }
  743.  
  744.    // is it time to draw the hovered slot and last move textures on the board slots ?
  745.    if (animation_endtime < current_time)
  746.    {
  747.       // add the hovered slot tile (only when it should not be hidden because of highlighting)
  748.       if (!is_paused && IS_VALID_POSITION (board->hovered_position)
  749.           && ((highlight_endtime < current_time) || ((int) ((highlight_endtime - current_time) * 20.0f) % 2 == 1)))
  750.          Scene_AddTile (scene, theme->hovered_textureindex, 3.1f,
  751.                         17.5f - (7 - board->hovered_position[1]) * 5.0f,
  752.                         17.5f - board->hovered_position[0] * 5.0f,
  753.                         0.03f, 0.0f); // hovered tile
  754.  
  755.       // and the previous move source and target
  756.       if (options.want_lastmove && (board->move_count > 1) && (board->viewed_move > 0)
  757.           && IS_VALID_POSITION (board->moves[board->viewed_move].source)
  758.           && IS_VALID_POSITION (board->moves[board->viewed_move].target))
  759.       {
  760.          Scene_AddTile (scene, theme->lastmovesource_textureindex, 2.5f,
  761.                         17.5f - (7 - board->moves[board->viewed_move].source[1]) * 5.0f,
  762.                         17.5f - board->moves[board->viewed_move].source[0] * 5.0f,
  763.                         0.04f, 0.0f); // previous move source
  764.          Scene_AddTile (scene, theme->lastmovetarget_textureindex, 2.5f,
  765.                         17.5f - (7 - board->moves[board->viewed_move].target[1]) * 5.0f,
  766.                         17.5f - board->moves[board->viewed_move].target[0] * 5.0f,
  767.                         0.04f, 0.0f); // previous move target
  768.       }
  769.    }
  770.  
  771.    ////////////////////////////////////////////////////////////////////////////////////////////////
  772.    // now draw the 3D parts that are still in play
  773.  
  774.    // cycle through all the grid and place all static parts
  775.    for (line = 0; line < 8; line++)
  776.    {
  777.       for (column = 0; column < 8; column++)
  778.       {
  779.          boardslot = &currentmove->slots[line][column]; // quick access to grid slot
  780.  
  781.          // is there nothing on this grid slot ?
  782.          if (boardslot->part == PART_NONE)
  783.             continue; // then don't draw anything on it
  784.  
  785.          // is this part not animated ? i.e.:
  786.          // has no movement happened yet
  787.          // OR does the movement NOT land on this slot
  788.          //    AND is it NOT the tower concerned by a castle ?
  789.          if ((board->viewed_move == 0)
  790.              || (((line != currentmove->target[0]) || (column != currentmove->target[1]))
  791.                  && ((towupper (currentmove->pgntext[0]) != L'O')
  792.                      || (line != (currentmove->color == COLOR_WHITE ? 0 : 7)) || (column != (currentmove->target[1] == 2 ? 3 : 5)))))
  793.          {
  794.             // do we want the 3D models or the flat icons ?
  795.             // we do when EITHER we don't want flat icons OR the player playing the current move is looking downstraight
  796.             if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  797.                Scene_AddPart (scene, boardslot->part, boardslot->color, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f, 0.0f, 0.0f);
  798.             else
  799.                Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.05f, flaticons_yaw);
  800.          }
  801.       } // end for (column = 0; column < 8; column++)
  802.    } // end for (line = 0; line < 8; line++)
  803.  
  804.    // now do another pass and draw the part(s) that are currently moving
  805.    for (line = 0; line < 8; line++)
  806.    {
  807.       for (column = 0; column < 8; column++)
  808.       {
  809.          boardslot = &currentmove->slots[line][column]; // quick access to grid slot
  810.  
  811.          // is there nothing on this grid slot ?
  812.          if (boardslot->part == PART_NONE)
  813.             continue; // then don't draw anything on it
  814.  
  815.          // has a movement happened yet AND does it land on this slot ?
  816.          if ((board->viewed_move > 0)
  817.              && (line == currentmove->target[0]) && (column == currentmove->target[1]))
  818.          {
  819.             // do we want animations AND is it still time to play the animation ?
  820.             if (options.want_animations && (animation_endtime > current_time))
  821.             {
  822.                // get the source and target X and Y positions
  823.                source_x = 17.5f - (7 - currentmove->source[1]) * 5.0f;
  824.                source_y = 17.5f - currentmove->source[0] * 5.0f;
  825.                target_x = 17.5f - (7 - currentmove->target[1]) * 5.0f;
  826.                target_y = 17.5f - currentmove->target[0] * 5.0f;
  827.  
  828.                // compute the movement completion ratio between 0 and 1
  829.                movement_ratio = 1.0f - (animation_endtime - current_time) / ANIMATION_DURATION;
  830.  
  831.                // compute the current X an Y based on movement timing
  832.                current_x = source_x + (target_x - source_x) * movement_ratio;
  833.                current_y = source_y + (target_y - source_y) * movement_ratio;
  834.  
  835.                // do we want the 3D models or the flat icons ?
  836.                // we do when EITHER we don't want flat icons OR the player playing the current move is looking downstraight
  837.                if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  838.                {
  839.                   // height is a sine positive, max height is proportional to travelled distance
  840.                   movement_diffco = abs (currentmove->target[1] - currentmove->source[1]);
  841.                   movement_diffli = abs (currentmove->target[0] - currentmove->source[0]);
  842.                   movement_maxheight = 0.5f + (float) movement_diffco + (float) movement_diffli;
  843.                   if (currentmove->part == PART_KNIGHT)
  844.                      movement_maxheight *= 2.0f; // knights jump high
  845.                   else if ((currentmove->part == PART_KING) && (movement_diffco == 2))
  846.                      movement_maxheight *= 5.0f; // kings jump VERY high when castling too
  847.                   else if (movement_maxheight > 5.0f)
  848.                      movement_maxheight = 5.0f; // all other parts just hover above the ground
  849.                   current_z = 0.04f + (float) sin (MATH_PI * movement_ratio) * movement_maxheight;
  850.  
  851.                   // make this part move realistically
  852.                   Scene_AddPart (scene, boardslot->part, boardslot->color, current_x, current_y, current_z, 0.0f, (boardslot->color == COLOR_BLACK ? -1 : 1) * min (current_z * 3.0f, 10.0f));
  853.                }
  854.                else
  855.                   Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, current_x, current_y, 0.07f, flaticons_yaw);
  856.             }
  857.             else
  858.             {
  859.                // do we want the 3D models or the flat icons ?
  860.                // we do when EITHER we don't want flat icons OR the current player is looking downstraight
  861.                if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  862.                   Scene_AddPart (scene, boardslot->part, boardslot->color, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f, 0.0f, 0.0f);
  863.                else
  864.                   Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.05f, flaticons_yaw);
  865.             }
  866.  
  867.             // is it time to play a move sound ?
  868.             if ((sound_playtime != 0) && (sound_playtime < current_time))
  869.             {
  870.                // is the current player in checkmate, in check, in stalemate or is it a capture ? (to play the right sound)
  871.                // read as: was the last move an opponent's move AND did it put us to check ?
  872.                if (currentmove->is_check)
  873.                {
  874.                   Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound
  875.  
  876.                   // is it a checkmate or a normal check ? (checkmate == check + stalemate)
  877.                   if (currentmove->is_stalemate)
  878.                      Audio_PlaySound (board->players[currentmove->color].type == PLAYER_HUMAN ? SOUNDTYPE_VICTORY : SOUNDTYPE_DEFEAT, 0.0f, 0.0f, 0.04f); // if so, play endgame sound at the center of the board
  879.                   else
  880.                      Audio_PlaySound (SOUNDTYPE_CHECK, 0.0f, 0.0f, 0.04f); // else play the check sound at the center of the board
  881.                }
  882.                else if (currentmove->is_stalemate)
  883.                {
  884.                   Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound
  885.                   Audio_PlaySound (SOUNDTYPE_DEFEAT, 0.0f, 0.0f, 0.04f); // on stalemate, play defeat sound at the center of the board
  886.                }
  887.                else if (currentmove->has_captured)
  888.                   Audio_PlaySound (SOUNDTYPE_PIECETAKEN, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // on capture, play the capture sound
  889.                else
  890.                   Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // play the normal move sound
  891.  
  892.                sound_playtime = 0; // mark this animation as completed and sound played
  893.             }
  894.          }
  895.  
  896.          // else has a movement happened yet AND is this movement a castle AND is this the concerned tower ?
  897.          else if ((board->viewed_move > 0)
  898.                   && (towupper (currentmove->pgntext[0]) == L'O') // either O-O-O or O-O
  899.                   && (line == (currentmove->color == COLOR_WHITE ? 0 : 7)) && (column == (currentmove->target[1] == 2 ? 3 : 5)))
  900.          {
  901.             // do we want animations AND is it still time to play the animation ? (castling rooks move faster)
  902.             if (options.want_animations && (animation_endtime - (0.5f * ANIMATION_DURATION) > current_time))
  903.             {
  904.                // get the source and target X and Y positions
  905.                source_x = 17.5f - (7 - (currentmove->target[1] == 2 ? 0 : 7)) * 5.0f; // if king moves left, then rook starts on column a, else it starts on column h
  906.                source_y = 17.5f - line * 5.0f;
  907.                target_x = 17.5f - (7 - column) * 5.0f;
  908.                target_y = 17.5f - line * 5.0f;
  909.  
  910.                // compute the movement completion ratio between 0 and 1 (castling rooks move faster)
  911.                movement_ratio = min (1.0f, 1.0f - (animation_endtime - (0.5f * ANIMATION_DURATION) - current_time) / (0.5f * ANIMATION_DURATION));
  912.  
  913.                // compute the current X an Y based on movement timing
  914.                current_x = source_x + (target_x - source_x) * movement_ratio;
  915.                current_y = source_y + (target_y - source_y) * movement_ratio;
  916.  
  917.                // height is a sine positive, max height is proportional to travelled distance
  918.                movement_maxheight = 1.0f; // castling rook will barely hover above the ground
  919.                current_z = 0.04f + (float) sin (MATH_PI * movement_ratio) * movement_maxheight;
  920.  
  921.                // make this part move realistically - do we want the 3D models or the flat icons ?
  922.                // we do when EITHER we don't want flat icons OR the player playing the current move is looking downstraight
  923.                if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  924.                   Scene_AddPart (scene, boardslot->part, boardslot->color, current_x, current_y, current_z, 0.0f, (boardslot->color == COLOR_BLACK ? -1 : 1) * min (current_z * 3.0f, 10.0f));
  925.                else
  926.                   Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, current_x, current_y, 0.09f, flaticons_yaw);
  927.  
  928.                if (movement_ratio < 0.9f)
  929.                   rooksound_played = false; // if the rook is still moving, reset the "sound played" flag
  930.                else if (!rooksound_played)
  931.                {
  932.                   Audio_PlaySound (SOUNDTYPE_MOVE, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f); // when the rook has landed, play a move sound
  933.                   rooksound_played = true; // remember this is no longer to be done
  934.                }
  935.             }
  936.             else
  937.             {
  938.                // do we want the 3D models or the flat icons ?
  939.                // we do when EITHER we don't want flat icons OR the current player is looking downstraight
  940.                if (!want_flaticons || (current_pitch < MAX_PITCH_FOR_FLAT_ICONS))
  941.                   Scene_AddPart (scene, boardslot->part, boardslot->color, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.04f, 0.0f, 0.0f);
  942.                else
  943.                   Scene_AddTile (scene, theme->flattextures[boardslot->color][boardslot->part], 2.5f, 17.5f - (7 - column) * 5.0f, 17.5f - line * 5.0f, 0.05f, flaticons_yaw);
  944.             }
  945.          }
  946.       } // end for (column = 0; column < 8; column++)
  947.    } // end for (line = 0; line < 8; line++)
  948.  
  949.    ////////////////////////////////////////////////////////////////////////////////////
  950.    // now draw the sepia overlay if we're in history view mode or if the game is paused
  951.  
  952.    if (options.want_sepiafilter && (is_paused || ((board->move_count > 1) && (board->viewed_move != board->move_count - 1))))
  953.       scene->overlay_spriteindex = sepia_spriteindex; // use the sepia filter
  954.    else
  955.       scene->overlay_spriteindex = -1; // else use natural colors
  956.  
  957.    ////////////////////////////////////////////////////////////////////////////////////////////////
  958.    // now draw the move comment text
  959.  
  960.    // does the move we are viewing have a comment ? if so, copy it, else leave it clear. Also if we're online, display a help text
  961.    if ((currentmove->comment != NULL) && (currentmove->comment[0] != 0))
  962.       Scene_SetText (&scene->gui.comment_text, 53.3f, 0.5f, 93.0f, ALIGN_CENTER, ALIGN_TOP, ALIGN_LEFT, chat_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191), 999999.0f, false, currentmove->comment);
  963.    else if ((network_player != NULL) && network_player->is_logged_in && !network_player->is_in_game)
  964.       Scene_SetText (&scene->gui.comment_text, 53.3f, 0.5f, 93.0f, ALIGN_CENTER, ALIGN_TOP, ALIGN_LEFT, chat_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191), 999999.0f, false, connected_comment);
  965.    else if (RGBACOLOR_ALPHA (scene->gui.comment_text.color) >= 128) // HACK: don't clear if a dimmed hint text is already here
  966.       scene->gui.comment_text.is_displayed = false; // else clear comment text
  967.  
  968.    ////////////////////////////////////////////////////////////////////////////////////////////////
  969.    // now draw the game clock
  970.  
  971.    // do we want to print the game clock ?
  972.    if (options.want_clock && (board->move_count > 1) && (board->game_state == STATE_PLAYING))
  973.    {
  974.       network_player = Player_FindByType (PLAYER_INTERNET); // quick access to network player
  975.  
  976.       // are we in Internet play ? if so, count time down, else count it up
  977.       if ((network_player != NULL) && network_player->is_in_game)
  978.          seconds = Player_GetCurrent ()->remaining_seconds - (int) (current_time - board->lastmove_time); // total seconds first
  979.       else
  980.          seconds = (int) (current_time - stoppage_time - board->lastmove_time); // total seconds first, take pauses in account
  981.  
  982.       minutes = seconds / 60; // minutes
  983.       seconds -= 60 * minutes; // remaining seconds
  984.  
  985.       Scene_SetText (&the_scene.gui.clock_text, 99.0f, 66.6f, -1, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_RIGHT, players_fontindex, RGBACOLOR_SETALPHA (options.clock_color, 0x7f), 999999.0f, false, L"%02d:%02d  ", minutes, seconds); // note: last space is alt+255
  986.    }
  987.    else
  988.       scene->gui.clock_text.is_displayed = false;
  989.  
  990.    ////////////////////////////////////////////////////////////////////////////////////////////////
  991.    // now draw the turn text
  992.  
  993.    // do we want to print the player's turn AND has the game not ended yet ? if so, copy it, else leave it clear
  994.    if (options.want_turn && (board->game_state == STATE_PLAYING))
  995.    {
  996.       if (Board_ColorToMove (board) == COLOR_BLACK)
  997.       {
  998.          if (the_scene.gui.turn_text.color != 0x000000C0)
  999.             Scene_SetText (&the_scene.gui.turn_text, 99.0f, 100.0f, -1, ALIGN_RIGHT, ALIGN_BOTTOM, ALIGN_RIGHT, players_fontindex, 0x000000C0, 999999.0f, true, LOCALIZE (L"BlackMoves"));
  1000.       }
  1001.       else
  1002.       {
  1003.          if (the_scene.gui.turn_text.color != 0xFFFFFF80)
  1004.             Scene_SetText (&the_scene.gui.turn_text, 99.0f, 100.0f, -1, ALIGN_RIGHT, ALIGN_BOTTOM, ALIGN_RIGHT, players_fontindex, 0xFFFFFF80, 999999.0f, true, LOCALIZE (L"WhiteMoves"));
  1005.       }
  1006.    }
  1007.    else
  1008.       scene->gui.turn_text.is_displayed = false;
  1009.  
  1010.    ////////////////////////////////////////////////////////////////////////////////////////////////
  1011.    // now draw the game history text
  1012.  
  1013.    // do we want to display the game history ? if so, display the game history text in PGN
  1014.    if (options.want_history && (board->move_count > 1))
  1015.    {
  1016.       // first off, see where we start (for long games, we don't want to display EVERYTHING...
  1017.       if (board->viewed_move > 30)
  1018.          start_index = board->viewed_move - 30; // display 30 moves maximum
  1019.       else
  1020.          start_index = 1;
  1021.  
  1022.       // allocate an arbitrary length history text string buffer (assume each move can't be longer than 15 characters)
  1023.       historytext_size = 15 * (1 + (board->viewed_move + 1) - start_index);
  1024.       history_text = (wchar_t *) SAFE_malloc (historytext_size, sizeof (wchar_t), false);
  1025.       history_text[0] = 0; // and reset it
  1026.  
  1027.       // now for each move we want to display...
  1028.       for (move_index = start_index; move_index <= board->viewed_move; move_index++)
  1029.       {
  1030.          length = wcslen (history_text); // get current text length
  1031.  
  1032.          // every move pair, append move pair number
  1033.          if (move_index % 2 == 1)
  1034.             swprintf_s (&history_text[length], historytext_size - length, L"%d.   ", 1 + move_index / 2);
  1035.  
  1036.          // append move text
  1037.          wcscat_s (history_text, historytext_size, board->moves[move_index].pgntext);
  1038.          wcscat_s (history_text, historytext_size, L"   ");
  1039.  
  1040.          // every odd move, drop a newline
  1041.          if (move_index % 2 == 0)
  1042.             wcscat_s (history_text, historytext_size, L"\n");
  1043.       }
  1044.  
  1045.       // add 50% alpha to game history color and transmit it to 3D engine
  1046.       Scene_SetText (&the_scene.gui.history_text, 100.0f, 50.0f, -1, ALIGN_RIGHT, ALIGN_BOTTOM, ALIGN_LEFT, chat_fontindex, RGBACOLOR_SETALPHA (options.history_color, 0x7f), 999999.0f, false, history_text);
  1047.       SAFE_free ((void **) &history_text);
  1048.    }
  1049.    else
  1050.       scene->gui.history_text.is_displayed = false; // if we don't need to display the game history, free the buffer
  1051.  
  1052.    ////////////////////////////////////////////////////////////////////////////////////////////////
  1053.    // now draw the chat area
  1054.  
  1055.    // is a valid chatter channel selected ?
  1056.    if ((selected_chatterchannel != NULL) && (chatterchannel_count > 0) && ((local_player = Player_FindByType (PLAYER_HUMAN)) != NULL))
  1057.    {
  1058.       // set the chatter's name
  1059.       wcscpy_s (scene->gui.entered_ccreply.nickname, WCHAR_SIZEOF (scene->gui.entered_ccreply.nickname), local_player->name);
  1060.  
  1061.       // correct or update the channel name and color
  1062.       if (selected_chatterchannel->theme[0] != 0)
  1063.          wcscpy_s (scene->gui.entered_ccreply.channelname, WCHAR_SIZEOF (scene->gui.entered_ccreply.channelname), selected_chatterchannel->theme);
  1064.       else
  1065.          swprintf_s (scene->gui.entered_ccreply.channelname, WCHAR_SIZEOF (scene->gui.entered_ccreply.channelname), L"%s %d", LOCALIZE (L"ChatterChannels_ColumnChannelNumber"), selected_chatterchannel->id);
  1066.       scene->gui.entered_ccreply.color = RGBACOLOR_FULLALPHA (selected_chatterchannel->color); // full bright for entering text
  1067.    }
  1068.  
  1069.    // display parts pick line in position setup mode only
  1070.    scene->gui.is_partspick_displayed = (board->game_state == STATE_SETUPPOSITION ? true : false);
  1071.  
  1072.    //////////////////////////
  1073.    // error and notifications
  1074.  
  1075.    // is the current player a computer AND are we playing a game right now
  1076.    // AND has the computer been thinking for more than 5 seconds AND is there no "thinking" text yet ?
  1077.    if ((board->players[Board_ColorToMove (board)].type == PLAYER_COMPUTER) && (board->game_state == STATE_PLAYING)
  1078.        && (board->lastmove_time + 5.0f < current_time) && !scene->gui.central_text.is_displayed)
  1079.    {
  1080.       Scene_SetText (&the_scene.gui.central_text, 50.0f, 40.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191),
  1081.                      999999.0f, true, LOCALIZE (L"Thinking")); // if so, display the "thinking" phrase in the middle of the screen
  1082.       the_scene.gui.want_spinwheel = true; // start spinning wheel
  1083.    }
  1084.  
  1085.    // is there a network player AND is our socket gone AWOL ?
  1086.    else if ((network_player != NULL) && (network_player->our_socket == INVALID_SOCKET))
  1087.    {
  1088.       // is there nothing in the center of the screen yet ?
  1089.       if (!the_scene.gui.central_text.is_displayed)
  1090.          Scene_SetText (&the_scene.gui.central_text, 50.0f, 50.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191),
  1091.                         999999.0f, true, LOCALIZE (L"Error_ConnectionToChessServerLost")); // display "error" in the middle of the screen
  1092.       the_scene.overlay_spriteindex = sepia_spriteindex; // display sepia filter if no connection
  1093.    }
  1094.  
  1095.    // is the game paused ?
  1096.    if (is_paused)
  1097.       Scene_SetText (&the_scene.gui.central_text, 50.0f, 50.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 255),
  1098.                      1.0f, false, LOCALIZE (L"Paused")); // if so, display the "paused" phrase in the middle of the screen
  1099.  
  1100.    return; // finished, scene is updated
  1101. }
  1102.  
  1103.  
  1104. void Scene_AddCCReply (scene_t *scene, wchar_t *nickname, wchar_t *channelname, unsigned long color_rgbx, wchar_t *fmt, ...)
  1105. {
  1106.    // helper function to add a CC reply on display
  1107.  
  1108.    static wchar_t message[4096];
  1109.    ccreply_t re;
  1110.    va_list argptr;
  1111.  
  1112.    // concatenate all the arguments in one string
  1113.    va_start (argptr, fmt);
  1114.    _vsnwprintf_s (message, WCHAR_SIZEOF (message), _TRUNCATE, fmt, argptr);
  1115.    va_end (argptr);
  1116.  
  1117.    // now put the text in place
  1118.    memset (&re, 0, sizeof (re)); // reset the structure we're about to fill
  1119.  
  1120.    wcscpy_s (re.nickname, WCHAR_SIZEOF (re.nickname), nickname); // copy nickname
  1121.    wcscpy_s (re.channelname, WCHAR_SIZEOF (re.channelname), channelname); // copy channel name
  1122.  
  1123.    re.text_length = wcslen (message); // get text length
  1124.    re.text = (wchar_t *) SAFE_malloc (re.text_length + 1, sizeof (wchar_t), false); // allocate text space (include null terminator)
  1125.    wcscpy_s (re.text, re.text_length + 1, message); // get the text
  1126.  
  1127.    re.color = RGBACOLOR_SETALPHA (color_rgbx, 0xC0); // copy reply color and force a slightly transparent alpha
  1128.    re.arrival_time = current_time; // save CC reply arrival time
  1129.  
  1130.    // reallocate CC history array to hold now one reply more
  1131.    the_scene.gui.cchistory = (ccreply_t *) SAFE_realloc (the_scene.gui.cchistory, the_scene.gui.cchistory_count, the_scene.gui.cchistory_count + 1, sizeof (ccreply_t), false);
  1132.    memcpy (&the_scene.gui.cchistory[the_scene.gui.cchistory_count], &re, sizeof (ccreply_t));
  1133.    the_scene.gui.cchistory_count++; // CC history holds now one reply more
  1134.  
  1135.    return; // finished, announcement text is set
  1136. }
  1137.  
  1138.  
  1139. void Scene_AddAnnouncement (scene_t *scene, wchar_t *fmt, ...)
  1140. {
  1141.    // helper function to set the announcement (red) text on display
  1142.  
  1143.    static wchar_t message[4096];
  1144.    ccreply_t re;
  1145.    va_list argptr;
  1146.  
  1147.    // concatenate all the arguments in one string
  1148.    va_start (argptr, fmt);
  1149.    _vsnwprintf_s (message, WCHAR_SIZEOF (message), _TRUNCATE, fmt, argptr);
  1150.    va_end (argptr);
  1151.  
  1152.    // now put the text in place
  1153.    memset (&re, 0, sizeof (re)); // reset the structure we're about to fill
  1154.  
  1155.    re.text_length = wcslen (message); // get text length
  1156.    re.text = (wchar_t *) SAFE_malloc (re.text_length + 1, sizeof (wchar_t), false); // allocate text space (include null terminator)
  1157.    wcscpy_s (re.text, re.text_length + 1, message); // get the text
  1158.  
  1159.    wcscpy_s (re.channelname, WCHAR_SIZEOF (re.channelname), LOCALIZE (L"ImportantMessage"));
  1160.    re.color = RGBA_TO_RGBACOLOR (192, 0, 0, 0xE0); // fair red, a bit more opaque than normal messages
  1161.    re.arrival_time = current_time; // save announcement arrival time
  1162.  
  1163.    // reallocate CC history array to hold now one reply more
  1164.    the_scene.gui.cchistory = (ccreply_t *) SAFE_realloc (the_scene.gui.cchistory, the_scene.gui.cchistory_count, the_scene.gui.cchistory_count + 1, sizeof (ccreply_t), false);
  1165.    memcpy (&the_scene.gui.cchistory[the_scene.gui.cchistory_count], &re, sizeof (ccreply_t));
  1166.    the_scene.gui.cchistory_count++; // CC history holds now one reply more
  1167.  
  1168.    return; // finished, announcement text is set
  1169. }
  1170.  
  1171.  
  1172. void Scene_SetButton (guibutton_t *button, float left, float top, float width, float height, int sprite_index)
  1173. {
  1174.    // helper function to set up a GUI button
  1175.  
  1176.    button->left = left;
  1177.    button->top = top;
  1178.    button->width = width;
  1179.    button->height = height;
  1180.    button->sprite_index = sprite_index;
  1181.  
  1182.    return; // finished, button is set
  1183. }
  1184.  
  1185.  
  1186. void Scene_SetText (guitext_t *text, float xpos_percent, float ypos_percent, float maxwidth_percent, int horizontal_align, int vertical_align, int text_align, int font_index, unsigned long color_rgba, float duration, bool want_fade, wchar_t *fmt, ...)
  1187. {
  1188.    // helper function to set some text on display
  1189.  
  1190.    static wchar_t message[4096];
  1191.    va_list argptr;
  1192.    int length;
  1193.  
  1194.    // concatenate all the arguments in one string
  1195.    va_start (argptr, fmt);
  1196.    _vsnwprintf_s (message, WCHAR_SIZEOF (message), _TRUNCATE, fmt, argptr);
  1197.    va_end (argptr);
  1198.  
  1199.    text->xpos_percent = xpos_percent; // save text's X position, in percents from left to right
  1200.    text->ypos_percent = ypos_percent; // save text's Y position, in percents from top to bottom
  1201.    text->maxwidth_percent = maxwidth_percent; // save text's max width before word wrapping
  1202.    text->horizontal_align = horizontal_align; // save text's horizontal alignment regarding the X position
  1203.    text->vertical_align = vertical_align; // save text's vertical alignment regarding the Y position
  1204.    text->text_align = text_align; // save text's horizontal alignment inside the bounding rectangle
  1205.    text->font_index = font_index; // save the index of the font with which to display this text
  1206.    text->color = color_rgba; // text's color, in RGBA
  1207.  
  1208.    // now put the text in place
  1209.    length = wcslen (message) + 1; // include null terminator
  1210.    text->buffer = (wchar_t *) SAFE_realloc (text->buffer, text->buffer_size, length, sizeof (wchar_t), false);
  1211.    wcscpy_s (text->buffer, length, message); // copy message text
  1212.    text->buffer_size = length; // and save buffer length
  1213.  
  1214.    text->appear_time = current_time; // save text arrival time
  1215.    text->disappear_time = current_time + duration; // make it last duration seconds
  1216.    text->want_fade = want_fade; // remember if text needs to be faded in and out
  1217.  
  1218.    // mark this text for display
  1219.    text->is_displayed = true;
  1220.  
  1221.    return; // finished, text is set
  1222. }
  1223.  
  1224.  
  1225. static void Scene_AddPart (scene_t *scene, int part_type, int part_color, float pos_x, float pos_y, float pos_z, float turn_yaw, float pitch)
  1226. {
  1227.    // helper function to add a specified part of the specified color to the rendered scene
  1228.  
  1229.    sceneobject_t *object;
  1230.    partcolor_t *partcolor;
  1231.  
  1232.    // reallocate space to hold one object more and blank it out
  1233.    scene->objects = (sceneobject_t *) SAFE_realloc (scene->objects, scene->object_count, scene->object_count + 1, sizeof (sceneobject_t), true);
  1234.  
  1235.    object = &scene->objects[scene->object_count]; // quick access to object
  1236.  
  1237.    object->mesh_index = theme->part_meshes[part_type]; // retrieve object mesh
  1238.    object->simpleshadow_size = simpleshadow_sizes[part_type]; // retrieve simple shadow size according to part type
  1239.    object->scale = 1.0f; // scale at 1 so far
  1240.  
  1241.    // set object texture and material
  1242.    partcolor = &theme->part_colors[part_color]; // quick access to part color struct
  1243.    object->texture_index = partcolor->texture;
  1244.    object->material_index = partcolor->material;
  1245.  
  1246.    // figure out object position on board
  1247.    object->x = pos_x;
  1248.    object->y = pos_y;
  1249.    object->z = pos_z;
  1250.  
  1251.    // turn a color's all parts' yaw 180 degrees so as both sides face each other
  1252.    if (part_color == COLOR_WHITE)
  1253.       object->yaw = 180.0f;
  1254.    else
  1255.       object->yaw = 0.0f;
  1256.  
  1257.    // and add the final turn pitch and yaw
  1258.    object->pitch = pitch;
  1259.    object->yaw = WrapAngle (object->yaw + turn_yaw);
  1260.  
  1261.    scene->object_count++; // array holds now one object more
  1262.    return; // finished
  1263. }
  1264.  
  1265.  
  1266. static void Scene_AddTile (scene_t *scene, int texture_index, float scale, float pos_x, float pos_y, float pos_z, float turn_yaw)
  1267. {
  1268.    // helper function to add a specified part of the specified color to the rendered scene
  1269.  
  1270.    sceneobject_t *object;
  1271.  
  1272.    // reallocate space to hold one object more and blank it out
  1273.    scene->objects = (sceneobject_t *) SAFE_realloc (scene->objects, scene->object_count, scene->object_count + 1, sizeof (sceneobject_t), true);
  1274.  
  1275.    object = &scene->objects[scene->object_count]; // quick access to object
  1276.  
  1277.    // save object data
  1278.    object->mesh_index = -1; // objects that have -1 as mesh index are tiles
  1279.    object->texture_index = texture_index;
  1280.    object->material_index = -1; // objects will use the default material
  1281.  
  1282.    // figure out object position on board
  1283.    object->x = pos_x;
  1284.    object->y = pos_y;
  1285.    object->z = pos_z;
  1286.    object->scale = scale;
  1287.  
  1288.    // turn tile as requested
  1289.    object->yaw = turn_yaw;
  1290.  
  1291.    scene->object_count++; // array holds now one object more
  1292.  
  1293.    return; // finished
  1294. }
  1295.