102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
player.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
11#include "pcdogs/entity/types.h"
14#include "pcdogs/game/globals.h"
15#include "pcdogs/game/types.h"
25#include "pcdogs/math/types.h"
26#include "pcdogs/menu/globals.h"
33#include <math.h>
34#include <stdarg.h>
35#include <string.h>
36
37// Original pcdogs.exe: 0x409420
38// Caches ground-derived jump velocity and sets a short grace timer when movement permits it. The disabled path clears the timer without refreshing the cached velocity.
40{
41 struct Player_ControllerRecordView *controller = actor->record_ptr;
42
43 if (controller->configured_jump_startup_ticks)
44 {
45 controller->jump_grace_ticks = 0;
46
47 return;
48 }
49
51
53
55 {
56 controller->jump_grace_ticks = 3;
57
58 return;
59 }
60
61 controller->jump_grace_ticks = 0;
62}
63
64// Original pcdogs.exe: 0x409a00
65// Processes player movement input, jumping, trails, targets, and velocity. Animation and bone-state input suppression is conditional on the input-control flag.
67{
68 struct Actor_State *moving_actor = actor;
69 struct Player_ControllerRecordView *controller = moving_actor->record_ptr;
70 struct Entity *owner_entity =
71 // Wave5 Agent07 SSOT 2026-05-06: controller+0x16C is read as signed room index; Player_ProcessMovement
72 // multiplies by 0x180 and indexes currentLevelData->room_array, so this is not the movement helper's player
73 // slot.
74 &pkg_resource_current_level_data->entity_array[(int32_t)controller->owner_entity_index];
75 uint32_t flags = owner_entity->flags;
76 struct Math_Vec3I32 inout_velocity;
77 struct Math_Vec3I32 movement_velocity;
78 int32_t path_axis_or_input_lock_bits;
79 int32_t path_axis_or_jump_motion_bits;
80
82 {
84 {
85 int32_t y = moving_actor->position.y;
86
87 path_axis_or_input_lock_bits = owner_entity->path_target.x - moving_actor->position.x;
88 movement_velocity.x = path_axis_or_input_lock_bits;
89
90 int32_t z = moving_actor->position.z;
91
92 movement_velocity.y = owner_entity->path_target.y - y;
93 path_axis_or_jump_motion_bits = owner_entity->path_target.z - z;
94 movement_velocity.z = path_axis_or_jump_motion_bits;
95
96 if (owner_entity->flags & ENTITY_FLAG_RUN_REQUEST && (uint32_t)path_axis_or_input_lock_bits + 0x200u <= 0x400u && (uint32_t)path_axis_or_jump_motion_bits + 0x200u <= 0x400u)
97 {
98 int32_t current_facing = moving_actor->facing_current;
99 int32_t facing_target = moving_actor->facing_target;
100 int32_t angle;
101
102 if (current_facing == facing_target)
103 {
104 int32_t blended_facing = (current_facing + moving_actor->facing_blend) & MATH_ANGLE_WRAP_MASK;
105
106 movement_velocity.x = -(Math_SinQ14(blended_facing) >> 2);
107 angle = MATH_ANGLE_QUARTER_TURN - ((moving_actor->facing_current + moving_actor->facing_blend) & MATH_ANGLE_WRAP_MASK);
108 }
109 else
110 {
111 movement_velocity.x = -(Math_SinQ14(facing_target) >> 2);
112 angle = MATH_ANGLE_QUARTER_TURN - moving_actor->facing_target;
113 }
114
115 movement_velocity.z = -((Math_SinQ14(angle) >> 2));
116 owner_entity->path_best_distance = MATH_Q12_ONE;
117 path_axis_or_input_lock_bits = movement_velocity.x;
118 path_axis_or_jump_motion_bits = movement_velocity.z;
119 }
120
121 movement_velocity.y = 0;
122 }
123 else
124 {
125 path_axis_or_jump_motion_bits = 0;
126 path_axis_or_input_lock_bits = 0;
127 __builtin_memset(&movement_velocity, 0, 0xc);
128 }
129
130 if (owner_entity->path_best_distance)
131 {
132 if (owner_entity->flags & ENTITY_FLAG_RUN_REQUEST)
133 movement_velocity = (struct Math_Vec3I32){
134 .x = -(path_axis_or_input_lock_bits),
135 .y = 0,
136 .z = -(path_axis_or_jump_motion_bits)};
137
138 int64_t direction_x_squared_wide = (int64_t)movement_velocity.x * movement_velocity.x;
139 int64_t direction_y_squared_wide = (int64_t)movement_velocity.y * movement_velocity.y;
140
141 // Check jump button press and transition to jump state if grounded
142 int64_t direction_z_squared_wide = (int64_t)movement_velocity.z * movement_velocity.z;
143
144 path_axis_or_input_lock_bits = Math_SqrtFP12((int32_t)(((uint64_t)direction_z_squared_wide + (uint64_t)direction_x_squared_wide + (uint64_t)direction_y_squared_wide) >> 12));
145 path_axis_or_jump_motion_bits = 0;
146
147 if (path_axis_or_input_lock_bits)
148 {
149 path_axis_or_jump_motion_bits = path_axis_or_input_lock_bits;
150
151 int32_t reciprocal_direction_length = INT64_C(4294967296) / path_axis_or_jump_motion_bits;
152 int64_t normalized_x_product_wide = (int64_t)reciprocal_direction_length * movement_velocity.x;
153
154 inout_velocity.x = ((int32_t)((uint64_t)normalized_x_product_wide >> 12)) >> 8;
155
156 int64_t normalized_y_product_wide = (int64_t)reciprocal_direction_length * movement_velocity.y;
157
158 inout_velocity.y = ((int32_t)((uint64_t)normalized_y_product_wide >> 12)) >> 8;
159
160 int64_t normalized_z_product_wide = (int64_t)reciprocal_direction_length * movement_velocity.z;
161
162 path_axis_or_input_lock_bits = ((int32_t)((uint64_t)normalized_z_product_wide >> 12)) >> 8;
163 inout_velocity.z = path_axis_or_input_lock_bits;
164 }
165 else
166 __builtin_memset(&inout_velocity, 0, 0xc);
167
168 moving_actor = actor;
169 }
170 else
171 __builtin_memset(&inout_velocity, 0, 0xc);
172 }
173 else
174 {
175 // Read analog stick input via Input_CalculateMovementVector and decompose into X/Z movement
176 int32_t landing_input_index = (uint8_t)(controller->input_source_index);
177
178 if (!(g_inputLandingFlagsPtr[3] & g_inputStateCurrentP1[landing_input_index].button_bits))
179 {
180 // Wave5 Agent07 SSOT 2026-05-06: controller+0x168 is a dword/flag cluster; this path clears bit0
181 // (AND 0xFE) when landing/action mask is absent, and later tests/sets the same low bit. Treat
182 // prior route-prev-state naming as unproven.
183 uint32_t state_flags = controller->state_flags;
184
185 state_flags &= ~(uint32_t)PLAYER_STATE_JUMP_STARTED;
186 controller->state_flags = state_flags;
187 }
188
189 // Wave5 Agent07 SSOT 2026-05-06: controller+0x170 is a word countdown/lockout checked before live input
190 // vector calculation; nonzero skips the normal Input_CalculateMovementVector setup and is decremented later
191 // at 0x409D7A..0x409D87.
192 if (controller->input_lock_ticks || controller->death_stage)
193 __builtin_memset(&movement_velocity, 0, 0xc);
194 else
195 {
196 struct Animation_DataBlock *current_animation =
197 moving_actor->anim_asset_table->anim_ptrs[Actor_GetAnimSeqIndex(moving_actor)];
198
199 if (!current_animation || !(current_animation->fixup_flags & ANIMATION_DATA_SUPPRESS_PLAYER_INPUT))
200 {
201 int32_t movement_input_index = (uint8_t)(controller->input_source_index);
202 int32_t button_bits = g_inputStateCurrentP1[movement_input_index].button_bits;
203
204 if (button_bits == INPUT_STATE_DISABLED)
205 __builtin_memset(&movement_velocity, 0, 0xc);
206 else if (!((uint8_t)button_bits & INPUT_BUTTON_ACTION_3) || Actor_GetAnimSeqIndex(moving_actor) != ACTOR_ANIMATION_NO_BONE || Trail_CheckBoneAvailable() > 0)
207 // Animation and trail gating applies only when input-control bit 0x40 is set.
208 {
209 // Compute direction from camera-relative input using sin/cos lookup table
210 int32_t copied_input_index = (uint8_t)(controller->input_source_index);
211
212 controller->input.button_bits = g_inputStateCurrentP1[copied_input_index].button_bits;
213 controller->input.axis = (struct Math_Vec2I16){
214 .x = g_inputStateCurrentP1[copied_input_index].axis.x,
215 .y = g_inputStateCurrentP1[copied_input_index].axis.y};
216
217 // Normal gameplay mode: Read input from g_currentInputState[player_slot*3], convert to
218 // camera-relative vector via Input_CalculateMovementVector
219 struct Math_Vec2I16 heading_angle = (struct Math_Vec2I16){
220 .x = g_inputStateCurrentP1[copied_input_index].axis_aux.x,
221 .y = g_inputStateCurrentP1[copied_input_index].axis_aux.y};
222
223 controller->input.axis_aux = heading_angle;
224
225 if (controller->attachment_ticks > 0 || (controller->state_flags & PLAYER_STATE_JUMP_STARTED && !(moving_actor->behavior_flags & ACTOR_BEHAVIOR_AIRBORNE)))
226 {
227 int32_t attachment_jump_button_mask = (uint8_t)(g_inputLandingFlagsPtr[3]);
228
229 controller->input.button_bits &= ~attachment_jump_button_mask;
230 }
231
232 if (controller->input.button_bits & INPUT_BUTTON_ACTION_1 && owner_entity->shared_ref_50)
233 {
234 int16_t current_level_id = g_currentLevelID;
235
236 if (current_level_id < LEVEL_BONUS_FIRST || current_level_id >= LEVEL_AFTER_BONUS)
237 {
238 uint32_t flags_1 = owner_entity->flags;
239
240 flags_1 |= ENTITY_FLAG_BIT_0;
241 owner_entity->flags = flags_1;
242 }
243 }
244
245 // dttr-scatter parity 2026-05-04: Player movement orientation derives from player facing
246 // angle minus camera yaw before Input_CalculateMovementVector. Do not replace this with a
247 // generic camera world-rotation matrix multiply without rechecking this path.
248 heading_angle.x = g_cameraData.look_yaw;
249
250 int32_t player_index;
251
252 // dttr-scatter parity note (2026-05-04): movement-yaw load/callsite; uses word_624346 -
253 // word_624348 as input yaw for Input_CalculateMovementVector. Repo constants:
254 // SCATTER_ADDR_MOVEMENT_YAW_CURRENT=0x00624346,
255 // SCATTER_ADDR_MOVEMENT_YAW_BASE=0x00624348.
256 heading_angle.x -= g_cameraData.view_roll;
257 // Wave5 Agent07 SSOT 2026-05-06: helper playerIndex argument comes from controller+0x0C;
258 // it selects the 12-byte input slot at g_inputStateCurrentP1/currentInputX, not the room
259 // index at controller+0x16C.
260 player_index = (uint8_t)controller->input_source_index;
261 // Wave5 Agent07 SSOT 2026-05-06: Player_ProcessMovement owns the callsite:
262 // out=&[ebp-0x20], playerIndex=controller+0x0C, heading=(int16)(word_624346 -
263 // word_624348); Input_CalculateMovementVector only consumes that state.
264 Input_CalculateMovementVector(&movement_velocity, player_index, heading_angle.x);
265 }
266 else
267 __builtin_memset(&movement_velocity, 0, 0xc);
268 }
269 else
270 __builtin_memset(&movement_velocity, 0, 0xc);
271 }
272
273 inout_velocity = movement_velocity;
274 Trail_UpdateAndRenderBone(moving_actor, &movement_velocity);
275 }
276
277 uint16_t input_lock_ticks = controller->input_lock_ticks;
278
279 if (input_lock_ticks)
280 controller->input_lock_ticks = input_lock_ticks - 1;
281
283 {
284 path_axis_or_jump_motion_bits = moving_actor->behavior_flags & ACTOR_BEHAVIOR_AIRBORNE;
285
286 if ((path_axis_or_jump_motion_bits || !controller->jump_phase_ticks) && !controller->reaction_animation_ticks)
287 {
288 int32_t param_max_speed_1;
289
290 if (!controller->death_stage)
291 param_max_speed_1 = 0;
292 else
293 param_max_speed_1 = owner_entity->param_max_speed_1;
294
295 int32_t speed_z;
296
297 speed_z = param_max_speed_1;
298
299 if ((!(owner_entity->flags & ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST) || !(controller->input.button_bits & g_inputLandingFlagsPtr[3])) && owner_entity->path_best_distance)
300 {
301 param_max_speed_1 = owner_entity->path_target.y - moving_actor->position.y;
302 speed_z = param_max_speed_1;
303 }
304
305 if ((!(owner_entity->flags & ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST) || !(controller->input.button_bits & g_inputLandingFlagsPtr[3])) && (!owner_entity->path_best_distance || param_max_speed_1 <= 0))
306 {
307 // Apply friction and velocity damping via Physics_CalculateFrictionForce
308 if (path_axis_or_jump_motion_bits)
309 {
310 controller->jump_phase_ticks = 0;
311
312 if (moving_actor->velocity.y > 0)
313 moving_actor->velocity.y = 0;
314 }
315 else
316 {
317 param_max_speed_1 = 0;
318 speed_z = 0;
319 }
320
321 int32_t released_jump_button_mask = (uint8_t)(g_inputLandingFlagsPtr[3]);
322
323 controller->input.button_bits &= ~released_jump_button_mask;
324 controller->movement_param_4c = owner_entity->param_max_speed_2;
325 path_axis_or_jump_motion_bits = owner_entity->param_max_speed_0;
326 controller->movement_param_40 = path_axis_or_jump_motion_bits;
327 controller->movement_param_44 = owner_entity->param_max_speed_1;
328
329 if (param_max_speed_1)
330 {
331 if (owner_entity->path_best_distance)
332 {
333 int32_t descent_horizontal_distance = Math_ApproxDistance3DWeighted(
334 owner_entity->path_target.x - moving_actor->position.x, 0,
335 owner_entity->path_target.z - moving_actor->position.z);
336 int32_t param_max_speed_2_1 = owner_entity->param_max_speed_2;
337
338 if (param_max_speed_2_1)
339 param_max_speed_2_1 =
340 ((int64_t)descent_horizontal_distance * 4096) / param_max_speed_2_1;
341
342 path_axis_or_jump_motion_bits = param_max_speed_2_1;
343
344 int32_t param_max_speed_1_1 = owner_entity->param_max_speed_1;
345 int32_t saved_descent_travel_time = path_axis_or_jump_motion_bits;
346
347 if (param_max_speed_1_1)
348 {
349 param_max_speed_1_1 =
350 ((int64_t)speed_z * 4096) / param_max_speed_1_1;
351 path_axis_or_jump_motion_bits = saved_descent_travel_time;
352 }
353
354 if (path_axis_or_jump_motion_bits < param_max_speed_1_1)
355 {
356 if (!param_max_speed_1_1)
357 controller->movement_param_4c = owner_entity->param_max_speed_2;
358 else
359 {
360 path_axis_or_jump_motion_bits = param_max_speed_1_1;
361 controller->movement_param_4c =
362 ((int64_t)descent_horizontal_distance * 4096) / path_axis_or_jump_motion_bits;
363 }
364 }
365 else if (!path_axis_or_jump_motion_bits)
366 // Final velocity integration and camera follow update via Camera_MoveToTarget
367 controller->movement_param_44 = owner_entity->param_max_speed_1;
368 else
369 {
370 path_axis_or_jump_motion_bits = saved_descent_travel_time;
371 controller->movement_param_44 =
372 ((int64_t)speed_z * 4096) / path_axis_or_jump_motion_bits;
373 }
374 }
375 }
376 else if (controller->movement_mode == PLAYER_MOVEMENT_PATH_JUMP_STEERED)
377 controller->movement_param_44 = 0;
378 }
379 else
380 {
381 if (path_axis_or_jump_motion_bits)
382 controller->jump_phase_ticks = 0xff;
383 else
384 {
385 param_max_speed_1 = 0;
386 speed_z = 0;
387 }
388
389 int32_t held_jump_button_mask = (uint8_t)(g_inputLandingFlagsPtr[3]);
390
391 controller->input.button_bits |= held_jump_button_mask;
392 controller->movement_param_4c = owner_entity->param_max_speed_2;
393 controller->movement_param_40 = owner_entity->param_max_speed_0;
394 path_axis_or_jump_motion_bits = owner_entity->param_max_speed_1;
395 controller->movement_param_44 = path_axis_or_jump_motion_bits;
396
397 if (param_max_speed_1)
398 {
399 int32_t ascent_horizontal_distance = Math_ApproxDistance3DWeighted(
400 owner_entity->path_target.x - moving_actor->position.x, 0,
401 owner_entity->path_target.z - moving_actor->position.z);
402 int32_t param_max_speed_2 = owner_entity->param_max_speed_2;
403
404 if (param_max_speed_2)
405 param_max_speed_2 =
406 ((int64_t)ascent_horizontal_distance * 4096) / param_max_speed_2;
407
408 path_axis_or_jump_motion_bits = param_max_speed_2;
409
410 int32_t param_max_speed_0 = owner_entity->param_max_speed_0;
411 int32_t saved_ascent_travel_time = path_axis_or_jump_motion_bits;
412
413 if (param_max_speed_0)
414 {
415 param_max_speed_0 =
416 ((int64_t)speed_z * 4096) / param_max_speed_0;
417 path_axis_or_jump_motion_bits = saved_ascent_travel_time;
418 }
419
420 if (path_axis_or_jump_motion_bits < param_max_speed_0)
421 {
422 if (!param_max_speed_0)
423 controller->movement_param_4c = owner_entity->param_max_speed_2;
424 else
425 {
426 path_axis_or_jump_motion_bits = param_max_speed_0;
427 controller->movement_param_4c =
428 ((int64_t)ascent_horizontal_distance * 4096) / path_axis_or_jump_motion_bits;
429 }
430 }
431 else if (!path_axis_or_jump_motion_bits)
432 controller->movement_param_40 = owner_entity->param_max_speed_0;
433 else
434 {
435 path_axis_or_jump_motion_bits = saved_ascent_travel_time;
436 controller->movement_param_40 =
437 ((int64_t)speed_z * 4096) / path_axis_or_jump_motion_bits;
438 }
439 }
440 }
441 }
442 }
443
444 char jump_phase_ticks = controller->jump_phase_ticks;
445
446 if (!(moving_actor->behavior_flags & ACTOR_BEHAVIOR_AIRBORNE))
447 {
448 int32_t ground_jump_velocity;
449
450 if (jump_phase_ticks >= 0)
451 {
452 if ((uint8_t)controller->input.button_bits & g_inputLandingFlagsPtr[3])
453 {
454 jump_phase_ticks = -(controller->configured_jump_startup_ticks);
455 controller->jump_phase_ticks = jump_phase_ticks;
456
457 if (!jump_phase_ticks)
458 {
459 ground_jump_velocity = Physics_CalculateGroundJumpVelocity(moving_actor);
460
461 if (ground_jump_velocity)
462 {
463 uint8_t jump_hold_ticks = controller->configured_jump_hold_ticks + 1;
464
466 controller->jump_phase_ticks = jump_hold_ticks;
467 controller->jump_grace_ticks = 0;
468 moving_actor->velocity.y = ground_jump_velocity;
469
470 int32_t behavior_flags = moving_actor->behavior_flags;
471
472 behavior_flags |= ACTOR_BEHAVIOR_AIRBORNE;
473 moving_actor->behavior_flags = behavior_flags;
474 }
475 else
476 {
477 int32_t rejected_jump_button_mask = (uint8_t)(g_inputLandingFlagsPtr[3]);
478
479 controller->input.button_bits &= ~rejected_jump_button_mask;
480 }
481 }
482 else
483 {
484 controller->input_lock_ticks = -(int16_t)jump_phase_ticks;
485 }
486 }
487 }
488 else
489 {
490 controller->jump_phase_ticks = jump_phase_ticks + 1;
491
492 if ((uint8_t)jump_phase_ticks == 0xff)
493 {
494 ground_jump_velocity = Physics_CalculateGroundJumpVelocity(moving_actor);
495
496 if (ground_jump_velocity)
497 {
498 uint8_t jump_hold_ticks = controller->configured_jump_hold_ticks + 1;
499
501 controller->jump_phase_ticks = jump_hold_ticks;
502 controller->jump_grace_ticks = 0;
503 moving_actor->velocity.y = ground_jump_velocity;
504
505 int32_t behavior_flags = moving_actor->behavior_flags;
506
507 behavior_flags |= ACTOR_BEHAVIOR_AIRBORNE;
508 moving_actor->behavior_flags = behavior_flags;
509 }
510 }
511 }
512 }
513 else if (jump_phase_ticks <= 0)
514 {
515 uint8_t jump_grace_ticks = controller->jump_grace_ticks;
516
517 if (jump_grace_ticks)
518 {
519 controller->jump_grace_ticks = jump_grace_ticks - 1;
520
521 if (controller->input.button_bits & g_inputLandingFlagsPtr[3])
522 {
523 int32_t cached_jump_velocity = controller->cached_jump_velocity;
524
525 jump_grace_ticks = controller->configured_jump_hold_ticks + 1;
527 controller->jump_phase_ticks = jump_grace_ticks;
528 controller->jump_grace_ticks = 0;
529 moving_actor->velocity.y = cached_jump_velocity;
530
531 int32_t behavior_flags = moving_actor->behavior_flags;
532
533 behavior_flags |= ACTOR_BEHAVIOR_AIRBORNE;
534 moving_actor->behavior_flags = behavior_flags;
535 }
536 }
537 else if (!moving_actor->ground_collision_node)
538 {
539 if (moving_actor->velocity.y <= controller->movement_param_44)
540 {
541 controller->jump_phase_ticks = jump_phase_ticks - 1;
542
543 if ((int8_t)(jump_phase_ticks - 1) < -60)
544 {
545 moving_actor->velocity = (struct Math_Vec3I32){
546 .z = 0,
547 .y = 0,
548 .x = 0};
549
550 Actor_MoveToTarget(moving_actor, owner_entity->runtime_target_pos, ACTOR_FACING_RELATIVE, 0, 0);
551 }
552 }
553 }
554 else if (controller->movement_mode < PLAYER_MOVEMENT_PATH_JUMP_FIXED)
555 controller->jump_phase_ticks = 0;
556 }
557 else
558 {
559 controller->jump_phase_ticks = jump_phase_ticks - 1;
560
561 if (jump_phase_ticks == 1)
562 {
563 controller->jump_grace_ticks = 0;
564 controller->jump_phase_ticks = 0;
565 }
566 else if (!controller->jump_grace_ticks && !(controller->input.button_bits & g_inputLandingFlagsPtr[3]))
567 {
568 controller->jump_grace_ticks = 0;
569 controller->jump_phase_ticks = 0;
570 }
571 }
572
573 Physics_CalculateActorVelocity(moving_actor, &inout_velocity, &movement_velocity);
574
575 if (moving_actor->component_count)
576 __builtin_memset(&controller->contact_slots, 0, 0x20);
577
578 controller->state_flags &= (uint8_t)~PLAYER_STATE_CONTACT_REFRESH;
579}
580
581// Original pcdogs.exe: 0x40af20
582// Decrements the 16-bit life count and backs up its low byte before respawning. The zero-life pause path exits before clearing state; other paths reset the transient record prefix while preserving its persistent tail.
583void Player_RespawnAfterDeath(struct Entity *current_entity, struct Actor_State *actor, struct Player_ControllerRecordView *record)
584{
586 record->lives_remaining -= 1;
588
589 if (!record->lives_remaining)
590 {
593
594 return;
595 }
596
597 uint32_t respawn_transition_flags = Game_FrameTransitionFlags & ~(uint32_t)GAME_TRANSITION_RESPAWN_PENDING;
598
600 Game_FrameTransitionFlags = respawn_transition_flags;
602
603 int32_t respawn_entity_flags = current_entity->flags & ~(uint32_t)(ENTITY_FLAG_PAUSE_EXEMPT | ENTITY_FLAG_RESTORE_DEFAULTS);
604
605 respawn_entity_flags |= ENTITY_FLAG_ACTIVATION_REQUEST;
606 current_entity->flags = respawn_entity_flags;
608 record->attachment_ticks = 0;
609 record->forced_animation_ticks = 0;
610 record->input_lock_ticks = 0;
611 memset(record, 0, 0x168);
613 Player_ResetBoneCount(current_entity, (struct Pkg_ActorRecord *)record);
614 *(uint8_t *)&actor->fade_alpha = 0;
616 actor->move_anim_speed = 0x40;
617 actor->velocity = (struct Math_Vec3I32){
618 .z = 0,
619 .y = 0,
620 .x = 0};
621
622 actor->roll_angle = 0;
623
624 int32_t bonus_respawn_entity_index = Level_ResetBonusState();
625
626 if (bonus_respawn_entity_index <= 0)
627 {
629 current_entity->respawn_transition_speed, 0);
630
631 return;
632 }
633
634 struct Entity *respawn_entity = &pkg_resource_current_level_data->entity_array[bonus_respawn_entity_index - 1];
635
636 if (!respawn_entity->bonus_respawn_mode)
637 {
638 Actor_MoveToTarget(actor, &respawn_entity->bonus_respawn_pos, (uint16_t)bonus_respawn_entity_index, 0, 0);
639
640 return;
641 }
642
643 Actor_MoveToTarget(actor, respawn_entity->bonus_respawn_target_pos, (uint16_t)bonus_respawn_entity_index, 0, 0);
644}
645
646// Original pcdogs.exe: 0x428a60
647// Initializes player state from saved lives and collectible counts, establishes default health, and updates completion flags. The saved life byte is sign-extended into the runtime word.
648void Player_InitializeState(struct Entity *entity, struct Pkg_ActorRecord *record)
649{
650 ((struct Player_ControllerRecordView *)record)->lives_remaining = (int16_t)(int8_t)g_backupLives;
651
652 int32_t level_start_puppy_count = (int32_t)g_levelStartPuppyCount;
653
654 record->reserved_5C[0x18] = (uint8_t)level_start_puppy_count;
655 record->reserved_5C[0x19] = (uint32_t)level_start_puppy_count >> 8;
656 record->reserved_5C[0x1a] = (uint32_t)level_start_puppy_count >> 16;
657 record->reserved_5C[0x1b] = (uint32_t)level_start_puppy_count >> 24;
660}
661
662// Original pcdogs.exe: 0x428aa0
663// Clears both completion-state bits, then sets either completed or in-progress state according to saved progress.
665{
667
668 bool game_complete = Save_IsGameComplete();
669 int32_t behavior_flags = actor->behavior_flags;
670
671 if (game_complete)
672 {
673 actor->behavior_flags = behavior_flags | ACTOR_BEHAVIOR_FORCE_ALTERNATE_LOD;
674
675 return;
676 }
677
678 actor->behavior_flags = behavior_flags | ACTOR_BEHAVIOR_FORCE_PRIMARY_LOD;
679}
680
681// Original pcdogs.exe: 0x428ae0
682// Resets the player's health-or-energy field to four. The current-entity argument is unused.
683void Player_ResetBoneCount(struct Entity *current_entity, struct Pkg_ActorRecord *record)
684{
685 (void)current_entity;
686 record->reserved_5C[0x18] = PLAYER_MAX_HEALTH;
687 record->reserved_5C[0x19] = 0;
688 record->reserved_5C[0x1a] = 0;
689 record->reserved_5C[0x1b] = 0;
690}
691
692// Original pcdogs.exe: 0x428af0
693// Updates collectible counters, restores health, or adds a life according to powerup type. The first counter branch accepts all signed type values at most three, including negative values.
694void Player_CollectPowerup(int32_t powerup_type)
695{
696 if (powerup_type <= POWERUP_SCORE_LAST)
697 {
698 int32_t collected_score = Menu_Selection + 1;
699 bool score_does_not_exceed_record = (uint32_t)collected_score <= (uint32_t)(int32_t)(int8_t)g_currentLevelScore;
700
701 Menu_Selection = collected_score;
702
703 if (score_does_not_exceed_record)
704 return;
705
706 g_currentLevelScore = (uint8_t)collected_score;
707
708 if ((uint8_t)collected_score == PLAYER_BONUS_UNLOCK_SCORE)
710
711 return;
712 }
713
714 if (powerup_type >= POWERUP_INVENTORY_FIRST && powerup_type < POWERUP_EXTRA_LIFE)
715 {
716 g_menuItems[powerup_type] += 1;
717
718 return;
719 }
720
721 struct Actor_State *active_player_actor = Entity_GetCurrentOrFirstActiveActor();
722
723 if (!active_player_actor)
724 return;
725
726 struct Player_ControllerRecordView *record_ptr = active_player_actor->record_ptr;
727
728 if (powerup_type >= POWERUP_HEALTH_FIRST && powerup_type < POWERUP_INVENTORY_FIRST)
729 {
730 int32_t bone_count = record_ptr->health_or_energy;
731
732 if (bone_count < PLAYER_MAX_HEALTH)
733 record_ptr->health_or_energy = bone_count + 1;
734 }
735 else if (powerup_type == POWERUP_EXTRA_LIFE)
736 {
737 int16_t lives_remaining = record_ptr->lives_remaining;
738
740 {
741 record_ptr->lives_remaining = lives_remaining + 1;
743 }
744 }
745}
@ ACTOR_ANIMATION_IDLE
Definition constants.h:98
@ ACTOR_ANIMATION_NO_BONE
Definition constants.h:109
#define ACTOR_BEHAVIOR_AIRBORNE
Definition constants.h:13
#define ACTOR_BEHAVIOR_FORCE_ALTERNATE_LOD
Definition constants.h:36
@ ACTOR_DEATH_ALIVE
Definition constants.h:131
@ ACTOR_FACING_ABSOLUTE
Definition constants.h:190
@ ACTOR_FACING_RELATIVE
Definition constants.h:189
#define ACTOR_BEHAVIOR_FORCE_PRIMARY_LOD
Definition constants.h:35
void Actor_MoveToTarget(struct Actor_State *actor, struct Math_Vec3I32 const *target_pos, int16_t facing_selector, int32_t facing_angle_degrees_q12, int32_t duration_frames)
Definition movement.c:142
void Actor_CopyEntityDefaultsToRecord(struct Actor_State *actor)
Definition lifecycle.c:250
int32_t Actor_GetAnimSeqIndex(struct Actor_State *actor)
Definition animation.c:519
#define ANIMATION_DATA_SUPPRESS_PLAYER_INPUT
Definition constants.h:34
void Animation_QueueStateChange(int32_t anim_state)
Definition controller.c:71
#define g_cameraData
Definition globals.h:63
#define ENTITY_FLAG_PAUSE_EXEMPT
Definition constants.h:26
#define ENTITY_FLAG_BIT_0
Definition constants.h:7
#define ENTITY_FLAG_WALK_REQUEST
Definition constants.h:12
#define ENTITY_FLAG_ACTIVE_WORKLIST_REQUEST
Definition constants.h:9
#define ENTITY_FLAG_SCRIPT_PAUSED
Definition constants.h:20
#define ENTITY_FLAG_ACTIVE_WORKLIST_DEFERRED
Definition constants.h:11
#define ENTITY_FLAG_ACTIVATION_REQUEST
Definition constants.h:17
#define ENTITY_FLAG_RESTORE_DEFAULTS
Definition constants.h:18
#define ENTITY_FLAG_RUN_REQUEST
Definition constants.h:13
struct Actor_State * Entity_GetCurrentOrFirstActiveActor(void)
Definition lifecycle.c:753
#define GAME_RESPAWN_FADE_DELAY_FRAMES
Definition constants.h:48
#define PLAYER_MAX_HEALTH
Definition constants.h:42
#define GAME_TRANSITION_GAME_OVER
Definition constants.h:28
#define PLAYER_STATE_JUMP_STARTED
Definition constants.h:39
#define PLAYER_MAX_LIVES
Definition constants.h:43
#define GAME_PAUSE_FRAMES
Definition constants.h:45
@ PLAYER_MOVEMENT_PATH_JUMP_FIXED
Definition constants.h:55
@ PLAYER_MOVEMENT_PATH_JUMP_STEERED
Definition constants.h:56
#define PLAYER_BONUS_UNLOCK_SCORE
Definition constants.h:44
#define GAME_TRANSITION_RESPAWN_PENDING
Definition constants.h:31
#define PLAYER_STATE_CONTACT_REFRESH
Definition constants.h:40
void Game_TriggerPause(int32_t pause_type)
Definition loop.c:61
#define Game_FrameTransitionFlags
Definition globals.h:47
#define Game_PauseStateCounter
Definition globals.h:71
#define INPUT_STATE_DISABLED
Definition constants.h:20
#define INPUT_BUTTON_ACTION_1
Definition constants.h:8
#define INPUT_BUTTON_ACTION_3
Definition constants.h:10
void Input_CalculateMovementVector(struct Math_Vec3I32 *out_move_vector, int32_t player_index, int32_t heading_angle)
Definition state.c:436
#define g_inputLandingFlagsPtr
Definition globals.h:32
#define g_inputStateCurrentP1
Definition globals.h:72
@ LEVEL_AFTER_BONUS
Definition constants.h:95
int32_t Level_ResetBonusState(void)
Definition progress.c:273
#define g_bonusLevelUnlocked
Definition globals.h:109
#define g_currentLevelScore
Definition globals.h:64
#define g_levelStartPuppyCount
Definition globals.h:58
#define g_currentLevelID
Definition globals.h:43
#define MATH_ANGLE_QUARTER_TURN
Definition constants.h:15
#define MATH_ANGLE_WRAP_MASK
Definition constants.h:16
#define MATH_Q12_ONE
Definition constants.h:9
int32_t Math_SinQ14(int32_t angle)
int32_t Math_SqrtFP12(uint32_t value)
int32_t Math_ApproxDistance3DWeighted(int32_t dx, int32_t dy, int32_t dz)
Definition fixed_point.c:59
#define g_menuItems
Definition globals.h:162
#define Menu_Selection
Definition globals.h:171
#define pkg_resource_current_level_data
Definition globals.h:117
void Physics_CalculateActorVelocity(struct Actor_State *actor, struct Math_Vec3I32 *inout_velocity, struct Math_Vec3I32 *steering_vec)
Definition movement.c:135
int32_t Physics_CalculateGroundJumpVelocity(struct Actor_State *actor)
Definition ground.c:230
void Player_ProcessMovement(struct Actor_State *actor)
Definition player.c:66
void Player_ResetBoneCount(struct Entity *current_entity, struct Pkg_ActorRecord *record)
Definition player.c:683
void Player_SetCompletionFlags(struct Actor_State *actor)
Definition player.c:664
void Player_InitializeState(struct Entity *entity, struct Pkg_ActorRecord *record)
Definition player.c:648
void Player_RespawnAfterDeath(struct Entity *current_entity, struct Actor_State *actor, struct Player_ControllerRecordView *record)
Definition player.c:583
void Player_CollectPowerup(int32_t powerup_type)
Definition player.c:694
void Player_CacheGroundJumpVelocity(struct Actor_State *actor)
Definition player.c:39
@ POWERUP_EXTRA_LIFE
Definition constants.h:18
@ POWERUP_INVENTORY_FIRST
Definition constants.h:17
@ POWERUP_HEALTH_FIRST
Definition constants.h:16
@ POWERUP_SCORE_LAST
Definition constants.h:15
void Save_SetBackupLives(uint8_t lives)
Definition progress.c:85
int32_t Save_IsGameComplete(void)
Definition progress.c:27
uint8_t component_count
Definition types.h:430
struct Math_Vec3I32 velocity
Definition types.h:446
int16_t move_anim_speed
Definition types.h:428
int16_t facing_current
Definition types.h:447
struct Collision_Node * ground_collision_node
Definition types.h:451
struct Animation_StateTable * anim_asset_table
Definition types.h:425
int32_t behavior_flags
Definition types.h:407
int16_t facing_target
Definition types.h:448
void * record_ptr
Definition types.h:477
int16_t facing_blend
Definition types.h:449
int16_t roll_angle
Definition types.h:450
struct Math_Vec3I32 position
Definition types.h:385
int32_t fade_alpha
Definition types.h:482
Animation_DataBlockFixupFlags fixup_flags
Definition types.h:761
struct Animation_DataBlock * anim_ptrs[0x2b]
Definition types.h:422
Definition types.h:22
uint32_t flags
Definition types.h:25
struct Math_Vec3I32 * runtime_target_pos
Definition types.h:49
uint8_t bonus_respawn_mode
Definition types.h:39
int32_t param_max_speed_1
Definition types.h:83
int32_t respawn_transition_speed
Definition types.h:61
int32_t param_max_health
Definition types.h:98
int32_t param_max_speed_2
Definition types.h:85
struct Math_Vec3I32 path_target
Definition types.h:113
struct Math_Vec3I32 bonus_respawn_pos
Definition types.h:35
struct Actor * runtime_actor
Definition types.h:107
void * shared_ref_50
Definition types.h:47
struct Math_Vec3I32 * bonus_respawn_target_pos
Definition types.h:41
int32_t path_best_distance
Definition types.h:112
int32_t param_max_speed_0
Definition types.h:82
struct Math_Vec2I16 axis
Definition types.h:84
uint32_t button_bits
Definition types.h:83
struct Math_Vec2I16 axis_aux
Definition types.h:85
int16_t x
Definition types.h:402
int32_t y
Definition types.h:471
int32_t x
Definition types.h:470
int32_t z
Definition types.h:472
uint8_t reserved_5C[0x2c]
Definition types.h:1073
struct Input_State input
Definition types.h:125
struct Actor_ContactSlot contact_slots[4]
Definition types.h:216
uint8_t configured_jump_hold_ticks
Definition types.h:153
uint16_t reaction_animation_ticks
Definition types.h:136
uint8_t configured_jump_startup_ticks
Definition types.h:154
int32_t Trail_CheckBoneAvailable(void)
Definition effects.c:388
void Trail_UpdateAndRenderBone(struct Actor_State *actor, struct Math_Vec3I32 *movement_vec)
Definition effects.c:413
#define g_renderingStateFlag
Definition values.h:627
#define g_backupLives
Definition values.h:426
#define g_screenFadeDuration
Definition values.h:621