Subversion Repositories Games.Chess Giants

Rev

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