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