102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
presentation.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
10#include "pcdogs/entity/types.h"
12#include "pcdogs/game/globals.h"
15#include "pcdogs/math/types.h"
18#include <string.h>
19
20// Original pcdogs.exe: 0x411610
21// Runs checkers initialization, human selection, move animation and iterative AI search. Its saved jump context handles nonlocal search or input cancellation.
23{
25 int32_t maximum_search_depth = 4;
26 struct Checkers_MoveList move_list;
27 struct Entity entity;
28
29 if (state_at_entry == CHECKERS_STATE_INITIALIZE)
30 {
31 entity.runtime_actor = 0;
32 entity.position_ptr = &g_cameraData.eye_pos;
33 entity.bonus_respawn_mode = 0;
34
36 {
37 int32_t second_corner_y = entity.navigation_command_position.y;
38 int32_t second_corner_z = entity.navigation_command_position.z;
39
41 g_checkersCameraPos2_Y = second_corner_y;
42 g_checkersCameraPos2_Z = second_corner_z;
43
45 {
46 int32_t first_corner_y = entity.navigation_command_position.y;
47 int32_t first_corner_z = entity.navigation_command_position.z;
48
50 g_checkersCameraPos1_Y = first_corner_y;
51 g_checkersCameraPos1_Z = first_corner_z;
53
54 int32_t next_initialization_state = g_checkersMinigameState + 1;
55
57 g_checkersMinigameState = next_initialization_state;
58 }
59 }
60
61 return;
62 }
63 else if (!state_at_entry)
64 {
66 {
67 while (true)
68 {
70 {
71 enum Checkers_MoveExecutionResult execution_result =
73
74 if (!execution_result)
75 {
77
79
80 return;
81 }
82
83 int32_t destination_columns = g_checkersSelectedCol2;
84 int32_t source_minus_destination_col = g_checkersSelectedCol1 - destination_columns;
85
86 g_checkersMoveResult = execution_result;
87
88 if ((source_minus_destination_col + 1) & ~CHECKERS_SIMPLE_STEP_DELTA)
89 {
90 bool last_jump = ((destination_columns | g_checkersSelectedRow2) & ~(uint32_t)CHECKERS_COORDINATE_MASK) == 0;
91 g_checkersMinigameState = execution_result == CHECKERS_EXEC_TURN_COMPLETE_PROMOTED && last_jump
94 }
95 else
96 {
100 }
101
103
105 {
107
108 break;
109 }
110
111 int32_t continuation_source_col = g_checkersSelectedCol2;
112 int32_t continuation_source_row = g_checkersSelectedRow2;
113
114 move_list.count = execution_result;
115 move_list.records[0].fromCol = continuation_source_col;
116 move_list.records[0].fromRow = continuation_source_row;
117
119 {
120 BOOL continuation_animation_pending;
121
122 do
123 continuation_animation_pending = Checkers_ProcessInputAndRender();
124
125 while (continuation_animation_pending);
126 }
127
133
134 struct Math_Vec3I32 position;
135
136 memset(&position, 0, 0xc);
138
139 return;
140 }
141
142 entity.runtime_actor = 0;
143 entity.position_ptr = &g_cameraData.eye_pos;
144 entity.bonus_respawn_mode = 0;
145
146 int32_t source_target_found =
147
149 enum Checkers_MoveExecutionResult pending_move_result;
150
151 if (source_target_found)
152 {
153 pending_move_result = g_checkersMoveResult;
154
155 if (pending_move_result == CHECKERS_EXEC_CAPTURE_CAN_CONTINUE && !g_worldBonusStateArray[3])
156 {
157 pending_move_result = CHECKERS_EXEC_TURN_COMPLETE;
158
159 int32_t next_player = g_worldBonusStateArray[5] ^ CHECKERS_PLAYER_MASK;
160
162 g_worldBonusStateArray[5] = next_player;
163 }
164 }
165
166 if (source_target_found && pending_move_result == CHECKERS_EXEC_TURN_COMPLETE)
167 break;
168
170 {
171 int32_t destination_board_origin_x = g_checkersCameraPos1_X;
172 int32_t destination_board_width = g_checkersCameraPos2_X - destination_board_origin_x;
173 int32_t destination_col = (int64_t)((entity.navigation_command_position.x - destination_board_origin_x) * 7 + (destination_board_width >> 1)) / destination_board_width;
174 int32_t destination_board_origin_z = g_checkersCameraPos2_Z;
175 int32_t destination_z_offset = entity.navigation_command_position.z - destination_board_origin_z;
176 int32_t destination_board_depth = g_checkersCameraPos1_Z - destination_board_origin_z;
177
178 g_checkersSelectedCol2 = destination_col;
179
180 int32_t destination_row = (int64_t)(destination_z_offset * 7 + (destination_board_depth >> 1)) / destination_board_depth;
181
182 g_checkersSelectedRow2 = destination_row;
183
184 if (!((destination_col | destination_row) & ~(uint32_t)CHECKERS_COORDINATE_MASK) && ((uint8_t)destination_col + (uint8_t)destination_row) & 1)
185 continue;
186
189 }
190
191 return;
192 }
193 }
194 else
195 {
196 entity.runtime_actor = 0;
197 entity.position_ptr = &g_cameraData.eye_pos;
198 entity.bonus_respawn_mode = 0;
199
201 {
202 int32_t source_board_origin_x = g_checkersCameraPos1_X;
203 int32_t source_board_width = g_checkersCameraPos2_X - source_board_origin_x;
204 int32_t source_col = (int64_t)((entity.navigation_command_position.x - source_board_origin_x) * 7 + (source_board_width >> 1)) / source_board_width;
205 int32_t source_board_origin_z = g_checkersCameraPos2_Z;
206 int32_t source_z_offset = entity.navigation_command_position.z - source_board_origin_z;
207 int32_t source_board_depth = g_checkersCameraPos1_Z - source_board_origin_z;
208
209 g_checkersSelectedCol1 = source_col;
210
211 int32_t source_row = (int64_t)(source_z_offset * 7 + (source_board_depth >> 1)) / source_board_depth;
212
213 g_checkersSelectedRow1 = source_row;
214
215 if ((uint32_t)source_col >= CHECKERS_BOARD_SIDE || (uint32_t)source_row >= CHECKERS_BOARD_SIDE || ((source_col ^ source_row) & 1) == 0 || (Checkers_GameBoard.playable_by_col[source_col][source_row >> 1] & CHECKERS_PLAYER_MASK) != g_worldBonusStateArray[5])
216 {
219 }
220 }
221
222 return;
223 }
224 }
225 else if (state_at_entry != CHECKERS_STATE_BEGIN_PLAY)
226 return;
227
228 if (state_at_entry == CHECKERS_STATE_BEGIN_PLAY)
229 {
233
236 }
237
238 BOOL capture_only = Checkers_BuildMoveList(&Checkers_GameBoard, g_worldBonusStateArray[5], &move_list);
239 int32_t count = move_list.count;
240
241 if (!count)
242 {
244 {
245 BOOL game_over_animation_pending;
246
247 do
248 game_over_animation_pending = Checkers_ProcessInputAndRender();
249
250 while (game_over_animation_pending);
251 }
252
253 int32_t player = g_worldBonusStateArray[5];
254
256
258
260
262
263 return;
264 }
265
267 {
269 {
270 BOOL selection_animation_pending;
271
272 do
273
274 selection_animation_pending = Checkers_ProcessInputAndRender();
275
276 while (selection_animation_pending);
277 }
278
283
285
286 g_world0CompletionBits = capture_only;
287
289
290 return;
291 }
292
293 if (count == 1)
294 {
296 {
297 BOOL single_move_animation_pending;
298
299 do
300
301 single_move_animation_pending = Checkers_ProcessInputAndRender();
302
303 while (single_move_animation_pending);
304 }
305
306 int32_t from_row = move_list.records[0].fromRow;
307 uint32_t packed_to_cols = move_list.records[0].packedToCols;
308
310
311 uint32_t packed_to_rows = move_list.records[0].packedToRows;
312
313 g_checkersSelectedRow1 = from_row;
314 g_checkersSelectedCol2 = packed_to_cols;
315 g_checkersSelectedRow2 = packed_to_rows;
317
318 return;
319 }
320
322 {
323 int32_t difficulty_setting = g_worldBonusStateArray[4];
324
326
332
333 /* Native 411be5 reads an uninitialized stack slot when unsigned AI setting >2. */
334 int32_t search_depth_stack_slot;
335
336 if ((uint32_t)difficulty_setting <= CHECKERS_DIFFICULTY_NORMAL)
337 search_depth_stack_slot = maximum_search_depth;
338 else if (difficulty_setting != CHECKERS_DIFFICULTY_HARD)
339 maximum_search_depth = search_depth_stack_slot;
340 else
341 {
342 maximum_search_depth = CHECKERS_MAX_SEARCH_DEPTH;
343 search_depth_stack_slot = maximum_search_depth;
344 }
345
346 int32_t depth = 1;
347
348 if (maximum_search_depth >= 1)
349 {
350 do
351 {
354 depth += 1;
355 } while (depth <= maximum_search_depth);
356 }
357 }
359 return;
360
362 {
363 BOOL ai_move_animation_pending;
364
365 do
366 ai_move_animation_pending = Checkers_ProcessInputAndRender();
367
368 while (ai_move_animation_pending);
369 }
370
371 int32_t ai_source_row = g_checkersAIMove_fromRow;
372 int32_t ai_destination_columns = g_checkersAIMove_toCol;
373
375
376 int32_t ai_destination_rows = g_checkersAIMove_toRow;
377
378 g_checkersSelectedRow1 = ai_source_row;
379 g_checkersSelectedCol2 = ai_destination_columns;
380 g_checkersSelectedRow2 = ai_destination_rows;
382}
383
393
394// Original pcdogs.exe: 0x411c80
402
403// Original pcdogs.exe: 0x411da0
404// Renders a checkers frame and advances pending move animation. Overlay cancellation exits through the saved checkers jump context.
406{
407 enum Checkers_MinGameState state_before_render = g_checkersMinigameState;
408
409 if (!state_before_render)
410 return 0;
411
413
415 {
417 /* no return */
418 }
419
421 {
423 }
424
425 if (state_before_render != CHECKERS_STATE_CAPTURE_SEQUENCE && state_before_render != CHECKERS_STATE_CAPTURE_SEQUENCE_PROMOTED)
426 {
428
429 return 0;
430 }
431
433 {
434 g_checkersMinigameState = state_before_render;
438
440 }
441
442 int32_t packed_destination_columns = g_checkersSelectedCol2;
443
444 g_checkersSelectedCol1 = packed_destination_columns & CHECKERS_COORDINATE_MASK;
445
446 int32_t packed_destination_rows = g_checkersSelectedRow2;
447 uint32_t remaining_destination_columns = (uint32_t)packed_destination_columns >> 3;
448
449 g_checkersSelectedCol2 = remaining_destination_columns;
450
451 uint32_t remaining_destination_rows = (uint32_t)packed_destination_rows >> 3;
452
453 g_checkersSelectedRow1 = packed_destination_rows & CHECKERS_COORDINATE_MASK;
454 g_checkersSelectedRow2 = remaining_destination_rows;
455
456 if (!remaining_destination_columns && !remaining_destination_rows)
457 {
459
460 return 0;
461 }
462
463 bool final_jump = ((remaining_destination_columns | remaining_destination_rows) & ~(uint32_t)CHECKERS_COORDINATE_MASK) == 0;
466 else
467 g_checkersMinigameState = state_before_render;
468
471}
472
473// Original pcdogs.exe: 0x411ec0
480
481// Original pcdogs.exe: 0x412d10
482// A repeated source cell needs just one target. Retail starts at (0, 0).
484{
485 int32_t previous_col = 0;
486 int32_t previous_row = 0;
487
488 for (int32_t i = 0; i < moves->count; ++i)
489 {
490 const struct Checkers_MoveSequence *move = &moves->records[i];
491 if (move->fromCol != previous_col || move->fromRow != previous_row)
492 {
493 previous_col = move->fromCol;
494 previous_row = move->fromRow;
495 Checkers_QueueCellTarget(CHECKERS_NAV_DESTINATION_CELL, previous_col, previous_row);
496 }
497 }
498}
499
500// Original pcdogs.exe: 0x412e40
502{
503 for (int32_t col = 0; col < CHECKERS_BOARD_SIDE; ++col)
504 {
505 for (int32_t row = (col - 1) & 1; row < CHECKERS_BOARD_SIDE; row += 2)
506 {
507 if ((board->playable_by_col[col][row >> 1] & CHECKERS_PLAYER_MASK) == (uint32_t)player)
509 }
510 }
511}
int32_t Actor_TracePath(struct Entity *entity, int32_t target_selector, int32_t max_path_distance, int32_t best_path_distance, int32_t trace_flags)
#define g_cameraData
Definition globals.h:63
#define CHECKERS_COORDINATE_MASK
Definition constants.h:11
#define CHECKERS_TRACE_UNBOUNDED
Definition constants.h:48
#define CHECKERS_BOARD_SIDE
Definition constants.h:12
@ CHECKERS_PATH_CURRENT
Definition constants.h:44
@ CHECKERS_PATH_SOURCE
Definition constants.h:42
@ CHECKERS_PATH_DESTINATION
Definition constants.h:43
#define CHECKERS_NAV_CURRENT_TARGET
Definition constants.h:47
@ CHECKERS_DIFFICULTY_HARD
Definition constants.h:24
@ CHECKERS_DIFFICULTY_NORMAL
Definition constants.h:23
@ CHECKERS_NAV_SELECTABLE_CELL
Definition constants.h:37
@ CHECKERS_NAV_DESTINATION_CELL
Definition constants.h:36
@ CHECKERS_NAV_SOURCE_CELL
Definition constants.h:35
#define CHECKERS_PLAYER_MASK
Definition constants.h:10
#define CHECKERS_SIMPLE_STEP_DELTA
Definition constants.h:27
#define CHECKERS_SEARCH_MIN_SCORE
Definition constants.h:49
#define CHECKERS_MAX_SEARCH_DEPTH
Definition constants.h:50
#define CHECKERS_LAST_COORDINATE
Definition constants.h:13
Checkers_Player
Definition enums.h:107
@ CHECKERS_PLAYER_2
Definition enums.h:113
@ CHECKERS_PLAYER_1
Definition enums.h:110
Checkers_MoveExecutionResult
Definition enums.h:50
@ CHECKERS_EXEC_TURN_COMPLETE_PROMOTED
Definition enums.h:62
@ CHECKERS_EXEC_TURN_COMPLETE
Definition enums.h:59
@ CHECKERS_EXEC_CAPTURE_CAN_CONTINUE
Definition enums.h:56
Checkers_MinGameState
Definition enums.h:7
@ CHECKERS_STATE_CAPTURE_SEQUENCE
Definition enums.h:19
@ CHECKERS_STATE_BEGIN_PLAY
Definition enums.h:43
@ CHECKERS_STATE_IDLE
Definition enums.h:10
@ CHECKERS_STATE_CAPTURE_SEQUENCE_PROMOTED
Definition enums.h:22
@ CHECKERS_STATE_INITIALIZE
Definition enums.h:37
@ CHECKERS_STATE_SIMPLE_MOVE_PROMOTED
Definition enums.h:16
@ CHECKERS_STATE_SIMPLE_MOVE
Definition enums.h:13
@ CHECKERS_STATE_NO_MOVES_PLAYER1
Definition enums.h:34
@ CHECKERS_STATE_ANIMATION_COMPLETE
Definition enums.h:25
@ CHECKERS_STATE_NO_MOVES_PLAYER2
Definition enums.h:31
enum Checkers_MoveExecutionResult Checkers_ExecuteMoveSequence(struct Checkers_Board *board, struct Checkers_MoveSequence const *move_sequence)
Definition board.c:150
int32_t Checkers_SearchBestMove(struct Checkers_Board *board, int32_t depth, struct Checkers_MoveSequence *out_best_move, enum Checkers_Player player, int32_t alpha, int32_t beta)
BOOL Checkers_BuildMoveList(struct Checkers_Board *board_state, enum Checkers_Player player, struct Checkers_MoveList *move_list)
Definition search.c:17
void Checkers_InitializeBoard(struct Checkers_Board *board)
Definition board.c:174
#define g_checkersSelectedRow1
Definition globals.h:42
#define g_checkersCameraPos1_Y
Definition globals.h:22
#define g_checkersAINodeCounter
Definition globals.h:54
#define g_checkersCameraPos2_Z
Definition globals.h:34
#define g_checkersCameraPos2_X
Definition globals.h:28
#define g_checkersAIThinkTimeout
Definition globals.h:77
#define g_checkersCameraPos2_Y
Definition globals.h:31
#define g_checkersJumpBuffer
Definition globals.h:74
#define g_checkersSelectedMove
Definition globals.h:36
#define g_checkersAIMove_fromRow
Definition globals.h:65
#define g_checkersAIMove_toRow
Definition globals.h:71
#define g_checkersSelectedCol2
Definition globals.h:45
#define g_checkersAIMove_fromCol
Definition globals.h:62
#define g_checkersMoveResult
Definition globals.h:57
#define g_checkersMinigameState
Definition globals.h:80
#define g_checkersCameraPos1_Z
Definition globals.h:25
#define g_checkersSelectedRow2
Definition globals.h:48
#define g_checkersAIMove
Definition globals.h:59
#define Checkers_GameBoard
Definition globals.h:51
#define g_checkersAIMove_toCol
Definition globals.h:68
#define g_checkersCameraPos1_X
Definition globals.h:19
#define g_checkersSelectedCol1
Definition globals.h:39
#define GAME_OVERLAY_CHECKERS_RENDER_BLOCKED
Definition constants.h:37
#define GAME_OVERLAY_CHECKERS_INPUT_BLOCKED
Definition constants.h:35
#define Game_FrameOverlayFlags
Definition globals.h:44
uint8_t Graphics_RenderFrame(void)
Definition frame.c:180
void Navigation_AddCommand(uint8_t command_type, int16_t target_selector_a, int16_t target_selector_b, int32_t speed, struct Math_Vec3I32 const *position)
Definition commands.c:42
void Checkers_HighlightPlayerPieces(struct Checkers_Board *board, enum Checkers_Player player)
BOOL Checkers_ProcessInputAndRender()
void Checkers_UpdateStateMachine()
void Checkers_QueueMoveListTargets(struct Checkers_MoveList *moves)
void Checkers_QueueSelectedCellTargets(void)
void Checkers_QueueMoveMidpointTarget(void)
static void Checkers_QueueCellTarget(uint8_t command, int32_t col, int32_t row)
void _longjmp(struct CRT_JumpBuffer3 *jump_buffer, int32_t value)
int32_t __setjmp3(struct CRT_JumpBuffer3 *jump_buffer, int32_t argument_count,...)
enum Checkers_Piece playable_by_col[0x8][0x4]
Definition types.h:11
int32_t count
Definition types.h:34
struct Checkers_MoveSequence records[0x3c]
Definition types.h:35
uint32_t packedToRows
Definition types.h:24
uint32_t packedToCols
Definition types.h:23
Definition types.h:22
uint8_t bonus_respawn_mode
Definition types.h:39
struct Math_Vec3I32 navigation_command_position
Definition types.h:115
struct Math_Vec3I32 * position_ptr
Definition types.h:78
struct Actor * runtime_actor
Definition types.h:107
int32_t y
Definition types.h:471
int32_t x
Definition types.h:470
int32_t z
Definition types.h:472
#define g_world0CompletionBits
Definition values.h:840
#define g_worldBonusStateArray
Definition values.h:828