102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
lifecycle.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
17#include "pcdogs/game/types.h"
20#include "pcdogs/math/types.h"
22#include "pcdogs/scene/types.h"
24#include <math.h>
25#include <stdarg.h>
26#include <string.h>
27
28// Original pcdogs.exe: 0x42e870
29// Reports whether another component can spawn, treating a zero maximum as unlimited capacity.
31{
32 uint8_t max_active_instances = definition->max_active_instances;
33
34 return !(max_active_instances > 0 && definition->active_instance_count >= max_active_instances);
35}
36
37// Original pcdogs.exe: 0x42f290
38// Returns the owner stored in the actor's spawn context without null validation.
40{ // Returns owning actor via double dereference: **( componentPtr+0xF4)
41 // ComponentInstance+0xF4 points to Actor** - double deref to get owning Actor (356 bytes)
42 return (struct Actor_State *)((struct Component_SpawnParams *)actor->record_ptr)->owner;
43}
44
45// Original pcdogs.exe: 0x42f2b0
46// Returns the spawn frame stored in the actor's component context.
48{
49 return ((struct Component_SpawnParams *)actor->record_ptr)->spawn_frame;
50}
51
52// Original pcdogs.exe: 0x42f3e0
53// Spawns component actors and optional followups, updating target orientation, collision cooldowns, audio, and camera shake. Camera shake can occur even when all allocations fail; the result is the final primary spawn attempt, or null when none is attempted.
54struct Actor_State *Component_SpawnFromCollisionRecord(struct Actor_State *owner_actor, struct Actor_State *target_actor, struct Component_CollisionRecord *collision_record)
55{
56 struct Component_Definition *definition = collision_record->definition;
57 struct Actor_State *spawned_projectile = NULL;
58
59 collision_record->damage_cooldown = definition->damage_cooldown;
60
61 int32_t spawn_count = (uint8_t)(definition->spawn_count);
62 int32_t initial_duration_stagger = (uint16_t)(definition->type2_duration_stagger);
63 int32_t remaining_child_spawns = spawn_count;
64 int32_t accumulated_duration_stagger = initial_duration_stagger;
65 int32_t spawn_index_remaining = spawn_count - 1;
66 struct Actor_State *spawn_owner;
67
68 if (!spawn_count)
69 spawn_owner = owner_actor;
70 else
71 {
72 bool more_projectiles;
73
74 do
75 {
76 spawn_owner = owner_actor;
77
78 spawned_projectile = Component_CreateActor(definition, spawn_owner, target_actor, COMPONENT_ACTOR_PROJECTILE);
79
80 if (spawned_projectile)
81 {
83
84 if (target_actor)
85 target_actor->attach_refcount += 1;
86
87 definition->active_instance_count += 1;
88
89 struct Component_SpawnParams *record_ptr = spawned_projectile->record_ptr;
91
92 record_ptr->state_flags = preserved_spawn_flags;
93
94 uint8_t spawn_count_1 = definition->spawn_count;
95
96 record_ptr->damage_cooldown = 0;
97 record_ptr->state_flags =
98 ((char)spawn_index_remaining * COMPONENT_SPAWN_INDEX_MULTIPLIER + spawn_count_1) << COMPONENT_SPAWN_INDEX_SHIFT | preserved_spawn_flags;
100
101 struct Actor_State *reference_actor = collision_record->reference_actor;
102
103 record_ptr->collision.reference_actor = reference_actor;
104
105 if (reference_actor)
106 {
107 if (reference_actor != COMPONENT_FIXED_POSITION_TARGET)
108 reference_actor->attach_refcount += 1;
109 else
110 record_ptr->target_pos = collision_record->position;
111
113 }
114
115 struct Actor_State *position_source_actor = collision_record->position_source_actor;
116
117 record_ptr->position_source_actor = position_source_actor;
118
119 if (!position_source_actor)
120 record_ptr->position_source_actor = spawn_owner;
121
122 uint32_t flags = definition->flags;
123
125 {
126 struct Actor_State *parent_actor = target_actor;
127
128 if (!parent_actor)
129 parent_actor = spawn_owner;
130
131 struct Actor_State *position_source_actor_1;
132
134 position_source_actor_1 = COMPONENT_FIXED_POSITION_TARGET;
135 else
136 position_source_actor_1 = record_ptr->position_source_actor;
137
138 Actor_AttachToParent(spawned_projectile, parent_actor, (struct Scene_TransformNodePrefix *)position_source_actor_1,
140 }
141
142 uint16_t attachment_joint_index = collision_record->attachment_joint_index;
143
144 if (attachment_joint_index)
145 {
146 struct Bone_JointTrackState *component_array = spawn_owner->component_array;
147 uint16_t joint_yaw = component_array[attachment_joint_index - 1].angle_param[2];
148 struct Bone_JointTrackState *joint_angle_record =
149 &component_array[attachment_joint_index - 1];
150 uint16_t joint_pitch = joint_angle_record->angle_param[3];
151 struct Math_Matrix3x3I16 joint_rotation;
152
153 Math_BuildMatrixRotationXY(&joint_rotation,
154 &joint_angle_record->node->world_rot_matrix, joint_pitch, joint_yaw);
155
156 int16_t joint_facing_angle =
157 Math_CalculateAtan2Fast((int32_t)joint_rotation.m22, (int32_t)joint_rotation.m02);
158 int32_t m12 = (int32_t)joint_rotation.m12;
159
160 spawned_projectile->facing_current = joint_facing_angle;
162 }
163
164 int32_t owner_turn_step_angle12 = definition->owner_turn_step_angle12;
165
166 if (owner_turn_step_angle12 && spawn_owner && spawn_owner->behavior_flags & ACTOR_BEHAVIOR_GROUND_TRACKING)
167 ((struct Player_ControllerRecordView *)spawn_owner->record_ptr)->turn_step = owner_turn_step_angle12;
168
169 uint32_t range = (uint16_t)(definition->type2_duration_range);
170 uint32_t random_duration_extra = Math_GenerateRandom(range);
171 int32_t base_duration = (uint16_t)(definition->type2_duration_base);
172 int32_t staggered_duration_extra = accumulated_duration_stagger + random_duration_extra;
173
174 if (base_duration != -(staggered_duration_extra))
175 {
176 spawned_projectile->fade_timer = (uint16_t)base_duration + (uint16_t)staggered_duration_extra;
177
178 struct Math_Vec3I32 *spawn_position = &record_ptr->position_source_actor->position;
179
180 spawned_projectile->position.x = spawn_position->x;
181 spawned_projectile->position.y = spawn_position->y;
182 spawned_projectile->position.z = spawn_position->z;
183
184 if (!definition->type2_duration_stagger)
185 record_ptr->position_source_actor = spawned_projectile;
186
187 int16_t facing_current = spawned_projectile->facing_current;
188 int16_t facing_blend = spawned_projectile->facing_blend;
189
190 spawned_projectile->lifecycle_flags |= ACTOR_LIFECYCLE_DISABLED;
191 spawned_projectile->facing_target = facing_current;
192 spawned_projectile->roll_angle = facing_blend;
193 Component_CalculateOrientation((struct Component_ProjectileActorView *)spawned_projectile, definition);
194 }
195 else
196 Component_InitializeProjectile((struct Component_ProjectileActorView *)spawned_projectile, definition);
197
198 int32_t duration_stagger_step = (uint16_t)(definition->type2_duration_stagger);
199
200 accumulated_duration_stagger += duration_stagger_step;
201
202 if (remaining_child_spawns)
203 {
204 remaining_child_spawns -= 1;
205
206 int32_t angle;
207 struct Actor_State *child_actor = Component_CreateActor(definition, spawned_projectile, target_actor, COMPONENT_ACTOR_CHILD);
208
209 if (child_actor)
210 {
213
214 uint32_t child_flags = definition->flags;
215
217 {
218 struct Actor_State *position_source_actor_2 =
219 collision_record->position_source_actor;
220
221 if (!position_source_actor_2 || !((uint8_t)child_flags & COMPONENT_FLAG_CHILD_ATTACH_POSITION_SOURCE))
222 position_source_actor_2 = COMPONENT_FIXED_POSITION_TARGET;
223
224 Actor_AttachToParent(child_actor, owner_actor, (struct Scene_TransformNodePrefix *)position_source_actor_2,
225 ~child_flags >> 2 & (COMPONENT_FLAG_CHILD_ATTACHMENT_OPTION >> 2));
226 }
227 }
228
229 spawn_owner = owner_actor;
230 }
231
232 if (spawned_projectile->lifecycle_flags & ACTOR_LIFECYCLE_DISABLED)
233 {
234 int16_t roll_angle = spawned_projectile->roll_angle;
235
236 spawned_projectile->facing_current = spawned_projectile->facing_target;
237 spawned_projectile->facing_blend = roll_angle;
238 spawned_projectile->roll_angle = 0;
239 }
241 {
242 int32_t y = spawned_projectile->position.y;
243
244 spawned_projectile->velocity.x = spawned_projectile->position.x - spawn_owner->world_render_pos.x;
245
246 int32_t z = spawned_projectile->position.z;
247
248 spawned_projectile->velocity.y = y - spawn_owner->world_render_pos.y;
249 spawned_projectile->velocity.z = z - spawn_owner->world_render_pos.z;
250 spawned_projectile->world_render_pos.x = spawn_owner->world_render_pos.x;
251 spawned_projectile->world_render_pos.y = spawn_owner->world_render_pos.y;
252 spawned_projectile->world_render_pos.z = spawn_owner->world_render_pos.z;
253 spawned_projectile->position.x = spawn_owner->world_render_pos.x;
254 spawned_projectile->position.y = spawn_owner->world_render_pos.y;
255 spawned_projectile->position.z = spawn_owner->world_render_pos.z;
256 }
257 }
258
259 more_projectiles = spawn_index_remaining;
260 spawn_index_remaining -= 1;
261 } while (more_projectiles);
262 }
263
265
266 int32_t spawn_camera_shake_amplitude = definition->spawn_camera_shake_amplitude;
267
268 if (spawn_camera_shake_amplitude)
269 Camera_StartShake(&spawn_owner->position, (uint16_t)spawn_camera_shake_amplitude);
270
271 return spawned_projectile;
272}
273
274// Original pcdogs.exe: 0x42fb50
275// Initializes projectile position, timers, hit state, launch frame, velocity, orientation, and launch audio, using the supplied source position when present.
277{
278 // Get ComponentInstance from actor+0xF4
279 // Get owner actor from ComponentInstance+0x0C
280 struct Component_SpawnParams *spawn_context = projectile->spawn_context;
281 struct Actor_State *position_source_actor = spawn_context->position_source_actor;
282
283 // Copy position from owner actor if set
284 if (position_source_actor)
285 {
286 projectile->position.x = position_source_actor->position.x;
287 projectile->position.y = position_source_actor->position.y;
288 projectile->position.z = position_source_actor->position.z;
289 }
290
291 uint8_t active_spawn_flags = spawn_context->state_flags | COMPONENT_STATE_DIRECTION_DIRTY;
292
293 // Set ComponentInstance flags bit 0 at +0x28
294 spawn_context->homing_response_scale = 0;
295 // Set actor state to 2 (active) at +0xC4
296 spawn_context->state_flags = active_spawn_flags;
297
298 uint32_t range = 0;
299
300 // Set actor type to 3 (projectile) at +0xC6
302 projectile->collision_class = COLLISION_ACTOR_CLASS_PROJECTILE; // Calculate randomized lifetime: base + random(variance)
303 range = (uint16_t)(definition->type0_duration_range);
304 // Store birth timestamp from g_gameFrameCounter
305 projectile->fade_timer = Math_GenerateRandom(range) + definition->type0_duration_base;
306 projectile->spawn_context->hit_count = 0;
309 // Check special physics mode flag at ComponentDef+0x4E bit 6
310 projectile->world_render_pos.x = projectile->position.x;
311 projectile->world_render_pos.y = projectile->position.y;
312
313 int32_t behavior_flags = projectile->behavior_flags;
314
316 projectile->world_render_pos.z = projectile->position.z;
317 projectile->behavior_flags = behavior_flags;
318
319 // Clear velocity/delta at actor+0xD4-0xE8
320 int32_t behavior_flags_1 = behavior_flags;
321
323 {
324 behavior_flags_1 &= ~(ACTOR_BEHAVIOR_MOVING_LEFT);
326 projectile->behavior_flags = behavior_flags_1;
327
329 projectile->collision_class = 0;
330 }
331
332 projectile->ground_collision_node = NULL;
333 projectile->velocity = (struct Math_Vec3I32){
334 .z = 0,
335 .y = 0,
336 .x = 0};
337
338 Component_PlayPositionalSound(definition, (struct Actor_State *)(projectile), COMPONENT_SOUND_LAUNCH);
339 Component_CalculateOrientation(projectile, definition);
340}
341
342// Original pcdogs.exe: 0x42fc60
343// Clones the indexed component template into the selected actor list and initializes ownership, position, ground, and facing state. Creation failure returns null.
344struct Actor_State *Component_CreateActor(struct Component_Definition *component_def, struct Actor_State *spawn_source, struct Actor_State *owner_actor, int32_t actor_kind)
345{
346 struct Actor **list_head;
347
348 if (actor_kind != COMPONENT_ACTOR_PROJECTILE)
349 list_head = &Projectile_LiveActorListHead;
350 else
351 list_head = &g_objectNodeRoot->deferred_actor_list;
352
354 (struct Actor_State *)component_def->actor_templates[actor_kind], (struct Actor_State **)list_head);
355
356 if (!spawned_actor)
357 return spawned_actor;
358
359 struct Component_SpawnParams *spawn_params = spawned_actor->record_ptr;
360
361 *(uint16_t *)&spawned_actor->rotation = (uint16_t)actor_kind;
362 spawn_params->owner = (struct Actor *)owner_actor;
363
364 if (owner_actor)
365 spawned_actor->behavior_flags |= owner_actor->behavior_flags & ACTOR_ROOT_MOTION_LOOP;
366
367 int32_t behavior_flags = spawned_actor->behavior_flags;
368
369 spawned_actor->fade_timer = 0;
370
371 int32_t initial_behavior_flags = behavior_flags | ACTOR_BEHAVIOR_AIRBORNE;
372
374 spawned_actor->collision_class = 0;
376 spawned_actor->behavior_flags = initial_behavior_flags;
377
378 if (actor_kind == COMPONENT_ACTOR_PROJECTILE)
379 {
380 ((struct Component_SpawnParams *)spawned_actor->record_ptr)->state_flags = 0;
381
382 struct Actor_State *child_actor = spawned_actor->child_actor;
383
384 if (child_actor)
386 }
387 else
389
390 if (spawn_source)
391 {
392 spawned_actor->position.x = spawn_source->position.x;
393 spawned_actor->position.y = spawn_source->position.y;
394 spawned_actor->facing_blend = 0;
395 spawned_actor->position.z = spawn_source->position.z;
396 spawned_actor->ground_collision_node = spawn_source->ground_collision_node;
397 spawned_actor->ground_contact_polygon = spawn_source->ground_contact_polygon;
398 spawned_actor->facing_current = Math_CalculateAtan2Fast((int32_t)spawn_source->rot_mat.m22,
399 (int32_t)spawn_source->rot_mat.m02);
400 }
401
402 return spawned_actor;
403}
404
405// Original pcdogs.exe: 0x430220
406// Updates projectile reflection, homing, owner facing, gravity, and orientation according to component flags, then refreshes eligible collision ranges. Hit count and accumulated reflection response are cleared during the update.
408{
409 // Get ComponentInstance pointer from actor+0xF4+0x9C
410 projectile->spawn_context->hit_count = 0;
411
412 // Get ComponentDefinition pointer from ComponentInstance+4
413 struct Component_SpawnParams *spawn_params = projectile->spawn_context;
414 struct Component_Definition *definition = spawn_params->definition;
415
416 do
417 {
418 if (spawn_params->homing_response_scale && definition->homing_strength)
419 {
421 spawn_params->state_flags &= (uint8_t)~COMPONENT_STATE_DIRECTION_DIRTY;
422 }
423 else
424 {
425 if ((*projectile->render_node_list)->traversal_flags & SCENE_NODE_DISABLED)
426 break;
427
429 {
430 uint8_t old_state_flags = spawn_params->state_flags;
432 uint8_t apply_gravity_after_tracking = ~old_state_flags & COMPONENT_STATE_DIRECTION_DIRTY;
433
434 // Apply gravity at ComponentDef+0x0C, decreasing Y velocity
436 {
437 Component_TrackTarget(projectile, definition, (uint16_t)homing_turn_step_angle12);
439 }
440
442 {
443 Component_SetVelocityFromDirection(projectile, definition);
444 spawn_params->state_flags &= (uint8_t)~COMPONENT_STATE_DIRECTION_DIRTY;
445
446 if (!projectile->collision_class && !definition->homing_turn_step_angle12 && !definition->homing_strength && !definition->gravity && !(definition->flags_high & ((COMPONENT_FLAG_CLEAR_TARGET_IF_UNTRACKED >> 8) | (COMPONENT_FLAG_CLEAR_TARGET >> 8))))
448 }
449
450 if (!apply_gravity_after_tracking)
451 break;
452 }
453 else
454 {
455 if (definition->owner_turn_step_angle12 && spawn_params->state_flags & COMPONENT_STATE_HAS_TARGET)
456 {
457 struct Actor *owner = spawn_params->owner;
458
460 {
461 // Check homing target at ComponentDef+0x20 and target tracking flag at ComponentInstance+0x28
462 // bit 2
463 struct Actor *attached_actor = spawn_params->attached_actor;
464 int32_t target_delta_x;
465 int32_t target_z;
466
467 if (attached_actor != COMPONENT_FIXED_POSITION_TARGET)
468 {
469 // Set velocity update flag at ComponentInstance+0x28 bit 0
470 target_z = attached_actor->position.z;
471 target_delta_x = attached_actor->position.x - owner->position.x;
472 }
473 else
474 {
475 // Track target to update orientation
476 target_delta_x = spawn_params->target_pos.x - owner->position.x;
477 target_z = spawn_params->target_pos.z;
478 }
479
480 int32_t target_delta_z = target_z - owner->position.z;
481 uint16_t owner_facing = owner->facing_blend;
482
483 owner_facing += owner->facing_current;
484 owner->facing_current = owner_facing & MATH_ANGLE_WRAP_MASK;
485 spawn_params->owner->facing_blend = MATH_ANGLE_FULL_TURN;
486 spawn_params->owner->facing_target = Math_CalculateAtan2FP12(target_delta_z, target_delta_x);
487 }
488 }
489
490 break;
491 }
492 }
493
494 int32_t gravity = definition->gravity;
495
496 if (gravity)
497 {
498 projectile->velocity.y -= gravity;
499
500 int32_t velocity_magnitude =
501 Math_SqrtFP12((int32_t)((uint64_t)(((int64_t)(projectile->velocity.z) * projectile->velocity.z) + ((int64_t)(projectile->velocity.x) * projectile->velocity.x) + ((int64_t)(projectile->velocity.y) * projectile->velocity.y)) >> MATH_Q12_SHIFT));
502 int16_t velocity_pitch_angle;
503 int32_t angle_y;
504
505 velocity_pitch_angle = Math_AsinRatioFP12(-(projectile->velocity.y), velocity_magnitude);
506
507 int32_t extended_velocity_pitch = (int32_t)velocity_pitch_angle;
508
509 if (extended_velocity_pitch != MATH_ANGLE_FULL_TURN)
510 projectile->pitch_angle = (int16_t)-(extended_velocity_pitch)&MATH_ANGLE_WRAP_MASK;
511
512 int32_t angle_x;
513
514 if (!(definition->flags_high & (COMPONENT_FLAG_YAW_ONLY_ORIENTATION >> 8)))
515 angle_x = -((int32_t)projectile->pitch_angle);
516 else
517 angle_x = 0;
518
519 angle_y = projectile->yaw_angle;
520 Math_BuildMatrixRotationXY(&projectile->rot_mat, NULL, angle_x, angle_y);
521 }
522 } while (0);
523
524 uint16_t flags = (int16_t)definition->flags;
525
526 if (((uint32_t)flags >> 8 & 0xff) & (COMPONENT_FLAG_CLEAR_TARGET >> 8) || (((uint32_t)flags >> 8 & 0xff) & (COMPONENT_FLAG_CLEAR_TARGET_IF_UNTRACKED >> 8) && !(spawn_params->state_flags & COMPONENT_STATE_HAS_TARGET)))
527 {
528 spawn_params->damage_cooldown = 0;
530 spawn_params->state_flags = (spawn_params->state_flags & (uint8_t)~COMPONENT_STATE_HAS_TARGET) | COMPONENT_STATE_TARGET_CLEARED;
531 }
532
533 spawn_params->homing_response_scale = 0;
534}
535
536// Original pcdogs.exe: 0x430af0
537// Creates a followup projectile, orienting it against the incoming direction or the fallback facing and optionally attaching it to the parent. Parent requirements can reject the request, while camera shake can precede a failed allocation.
539{
541 return 0;
542
543 int32_t followup_camera_shake_amplitude = component_def->followup_camera_shake_amplitude;
544
545 if (followup_camera_shake_amplitude)
546 Camera_StartShake(&source_actor->position, (uint16_t)followup_camera_shake_amplitude);
547
548 struct Actor_State *followup_actor =
549 Component_CreateActor(component_def, source_actor, (struct Actor_State *)((struct Component_SpawnParams *)source_actor->record_ptr)->owner, COMPONENT_ACTOR_FOLLOWUP);
550
551 Component_PlayPositionalSound(component_def, followup_actor, COMPONENT_SOUND_FOLLOWUP);
552
553 if (!followup_actor)
554 return followup_actor;
555
556 if (parent_actor)
557 {
558 uint32_t flags = component_def->flags;
559
561 Actor_AttachToParent(followup_actor, parent_actor, (struct Scene_TransformNodePrefix *)(uintptr_t)(((uint8_t)flags & COMPONENT_FLAG_FOLLOWUP_ATTACH_SENTINEL) ? -1 : 0),
562 ~flags >> 5 & (COMPONENT_FLAG_FOLLOWUP_ATTACHMENT_OPTION >> 5));
563 }
564
565 int32_t source_velocity_x = source_actor->velocity.x;
566 int32_t reverse_yaw;
567
568 if (source_velocity_x || source_actor->velocity.y || source_actor->velocity.z)
569 reverse_yaw = Math_CalculateAtan2FP12(-(source_actor->velocity.z), -(source_velocity_x));
570 else
571 {
572 reverse_yaw = (source_actor->facing_current - MATH_ANGLE_HALF_TURN) & MATH_ANGLE_WRAP_MASK;
573 }
574
575 followup_actor->facing_current = (uint16_t)reverse_yaw;
576
577 int32_t pitch = -(int16_t)followup_actor->facing_blend;
578
579 Math_BuildMatrixRotationXY(&followup_actor->rot_mat, NULL, pitch, (uint16_t)reverse_yaw);
580
581 return followup_actor;
582}
583
584// Original pcdogs.exe: 0x430be0
585// Reassigns an eligible projectile to an owner, updating attachment offsets, references, timers, and facing before reinitializing movement and audio.
586void Component_AttachToOwner(struct Actor_State *owner_actor, struct Component_ProjectileActorView *projectile, struct Math_Vec3I32 *local_pos)
587{
588 struct Component_SpawnParams *spawn_params = projectile->spawn_context;
589 struct Component_Definition *definition = spawn_params->definition;
590
592 return;
593
594 projectile->position.x = local_pos->x;
595 projectile->position.y = local_pos->y;
596 projectile->position.z = local_pos->z;
597 spawn_params->damage_cooldown = 0;
599
600 struct Actor *attached_actor = spawn_params->attached_actor;
601
603
604 if (attached_actor && attached_actor != COMPONENT_FIXED_POSITION_TARGET)
605 {
606 uint8_t attach_refcount = attached_actor->attach_refcount;
607
608 if (attach_refcount)
609 attached_actor->attach_refcount = attach_refcount - 1;
610 }
611
612 struct Actor *owner = spawn_params->owner;
613
614 if (owner->actor_type != ACTOR_OBJECT_RUNTIME)
615 {
616 spawn_params->attached_actor = NULL;
617 spawn_params->state_flags &= (uint8_t)~COMPONENT_STATE_HAS_TARGET;
618 }
619 else
620 {
621 spawn_params->attached_actor = owner;
622 owner->attach_refcount += 1;
623 }
624
625 struct Actor *old_owner = spawn_params->owner;
626
627 spawn_params->position_source_actor = NULL;
628
629 if (old_owner)
630 {
631 uint8_t attach_refcount = old_owner->attach_refcount;
632
633 if (attach_refcount)
634 old_owner->attach_refcount = attach_refcount - 1;
635 }
636
637 struct Actor *new_owner = ((struct Component_SpawnParams *)owner_actor->record_ptr)->owner;
638
639 spawn_params->owner = new_owner;
640
641 if (new_owner)
642 new_owner->attach_refcount += 1;
643
644 uint16_t reversed_yaw = projectile->yaw_angle;
645 struct Component_SpawnParams *spawn_params_current = projectile->spawn_context;
646
647 reversed_yaw -= MATH_ANGLE_HALF_TURN;
648 projectile->yaw_angle = reversed_yaw & MATH_ANGLE_WRAP_MASK;
649 Component_InitializeProjectile(projectile, spawn_params_current->definition);
650 Component_PlayPositionalSound(((struct Component_SpawnParams *)owner_actor->record_ptr)->definition, owner_actor, COMPONENT_SOUND_FOLLOWUP);
651}
652
653// Original pcdogs.exe: 0x43a730
654// Clears the live-projectile list head, then detaches each projectile, stops its audio, and destroys it.
656{
657 struct Actor *projectile_actor = Projectile_LiveActorListHead;
658
659 if (!projectile_actor)
660 return;
661
663
664 struct Actor *next_projectile_actor;
665
666 do
667 {
668 Actor_DetachFromParent((struct Actor_State *)(projectile_actor));
670 0);
671 next_projectile_actor = projectile_actor->list_next;
672 Actor_Destroy((struct Actor_State *)(projectile_actor));
673 projectile_actor = next_projectile_actor;
674 } while (next_projectile_actor);
675}
#define ACTOR_BEHAVIOR_MOVEMENT_LOCKED
Definition constants.h:16
#define ACTOR_BEHAVIOR_DESTROY_AFTER_ANIMATION
Definition constants.h:28
#define ACTOR_BEHAVIOR_AIRBORNE
Definition constants.h:13
#define ACTOR_LIFECYCLE_DISABLED
Definition constants.h:39
#define ACTOR_BEHAVIOR_GROUND_TRACKING
Definition constants.h:12
#define ACTOR_BEHAVIOR_MOVING_LEFT
Definition constants.h:17
@ ACTOR_OBJECT_RUNTIME
Definition constants.h:143
#define ACTOR_BEHAVIOR_BYPASS_COLLISION
Definition constants.h:18
#define ACTOR_ROOT_MOTION_LOOP
Definition constants.h:22
struct Scene_TransformNodePrefix * Actor_AttachToParent(struct Actor_State *child_actor, struct Actor_State *parent_actor, struct Scene_TransformNodePrefix *attach_point_or_auto_sentinel, uint32_t attachment_flags_and_face_selector)
void Actor_DetachFromParent(struct Actor_State *actor)
struct Actor_State * Actor_CloneTemplateWithTemplateRelativeFixups(struct Actor_State *template_actor, struct Actor_State **list_head)
Definition lifecycle.c:311
void Actor_Destroy(struct Actor_State *actor)
Definition lifecycle.c:568
#define AUDIO_INVALID_SOUND_INDEX
Definition constants.h:49
void Audio_StopOrUpdateSoundsAtPosition(int32_t sound_index_or_mode, struct Math_Vec3I32 *position, char looping_only)
Definition spatial.c:76
void Camera_StartShake(struct Math_Vec3I32 *unused_position, int16_t amplitude)
Definition effects.c:17
@ COLLISION_ACTOR_CLASS_PROJECTILE
Definition constants.h:69
#define COMPONENT_FLAG_PROJECTILE_ATTACHMENT_OPTION
Definition constants.h:14
#define COMPONENT_STATE_DIRECTION_DIRTY
Definition constants.h:21
#define COMPONENT_FLAG_CHILD_ATTACH_POSITION_SOURCE
Definition constants.h:6
#define COMPONENT_SPAWN_INDEX_MULTIPLIER
Definition constants.h:38
@ COMPONENT_SOUND_FOLLOWUP
Definition constants.h:45
@ COMPONENT_SOUND_SPAWN
Definition constants.h:44
@ COMPONENT_SOUND_LAUNCH
Definition constants.h:46
#define COMPONENT_SPAWN_INDEX_SHIFT
Definition constants.h:39
#define COMPONENT_FLAG_FOLLOWUP_ATTACHMENT_OPTION
Definition constants.h:11
#define COMPONENT_FLAG_FOLLOWUP_ATTACH_PARENT
Definition constants.h:9
#define COMPONENT_FLAG_PROJECTILE_ATTACH_PARENT
Definition constants.h:13
#define COMPONENT_FLAG_CHILD_ATTACH_OWNER
Definition constants.h:7
#define COMPONENT_STATE_TARGET_CLEARED
Definition constants.h:22
#define COMPONENT_FIXED_POSITION_TARGET
Definition constants.h:28
@ COMPONENT_MOVEMENT_IDLE
Definition constants.h:56
@ COMPONENT_MOVEMENT_PROJECTILE
Definition constants.h:57
#define COMPONENT_FLAG_FOLLOWUP_ATTACH_SENTINEL
Definition constants.h:10
#define COMPONENT_FLAG_CHILD_ATTACHMENT_OPTION
Definition constants.h:8
#define COMPONENT_FLAG_YAW_ONLY_ORIENTATION
Definition constants.h:17
#define COMPONENT_STATE_HAS_TARGET
Definition constants.h:23
#define COMPONENT_FLAG_PROJECTILE_ATTACH_POSITION_SOURCE
Definition constants.h:12
@ COMPONENT_PHASE_INITIAL
Definition constants.h:62
@ COMPONENT_PHASE_DEFERRED_PROJECTILE
Definition constants.h:63
#define COMPONENT_FLAG_CLEAR_TARGET
Definition constants.h:16
@ COMPONENT_ACTOR_PROJECTILE
Definition constants.h:34
@ COMPONENT_ACTOR_FOLLOWUP
Definition constants.h:33
@ COMPONENT_ACTOR_CHILD
Definition constants.h:32
#define COMPONENT_FLAG_CLEAR_TARGET_IF_UNTRACKED
Definition constants.h:15
#define COMPONENT_COLLISION_ALL_FLAGS
Definition enums.h:27
#define COMPONENT_COLLISION_PROJECTILE_BEHAVIOR_MODE
Definition enums.h:24
void Component_TrackTarget(struct Component_ProjectileActorView *comp, struct Component_Definition *definition, int16_t turn_rate)
Definition collision.c:383
void Component_PlayPositionalSound(struct Component_Definition *component_def, struct Actor_State *actor, int32_t sound_slot_index)
Definition properties.c:202
void Component_ApplyImpactReflection(struct Component_ProjectileActorView *comp)
Definition collision.c:449
void Component_RefreshCollisionRanges(struct Component_CollisionRecord *collision_records, int32_t slot_count)
Definition collision.c:42
void Component_SetVelocityFromDirection(struct Component_ProjectileActorView *comp, struct Component_Definition *definition)
Definition properties.c:215
void Component_CalculateOrientation(struct Component_ProjectileActorView *comp, struct Component_Definition *definition)
Definition properties.c:83
void Projectile_DestroyAllLiveActors(void)
Definition lifecycle.c:655
#define Projectile_LiveActorListHead
Definition globals.h:15
struct Actor_State * Component_GetOwnerActor(struct Actor_State *actor)
Definition lifecycle.c:39
int32_t Component_GetSpawnFrame(struct Actor_State *actor)
Definition lifecycle.c:47
void Component_AttachToOwner(struct Actor_State *owner_actor, struct Component_ProjectileActorView *projectile, struct Math_Vec3I32 *local_pos)
Definition lifecycle.c:586
struct Actor_State * Component_SpawnFollowupProjectile(struct Component_Definition *component_def, struct Actor_State *source_actor, struct Actor_State *parent_actor)
Definition lifecycle.c:538
BOOL Component_HasSpawnCapacity(struct Component_Definition *definition)
Definition lifecycle.c:30
struct Actor_State * Component_CreateActor(struct Component_Definition *component_def, struct Actor_State *spawn_source, struct Actor_State *owner_actor, int32_t actor_kind)
Definition lifecycle.c:344
struct Actor_State * Component_SpawnFromCollisionRecord(struct Actor_State *owner_actor, struct Actor_State *target_actor, struct Component_CollisionRecord *collision_record)
Definition lifecycle.c:54
void Component_InitializeProjectile(struct Component_ProjectileActorView *projectile, struct Component_Definition *definition)
Definition lifecycle.c:276
void Component_UpdateProjectileLogic(struct Component_ProjectileActorView *projectile)
Definition lifecycle.c:407
#define MATH_Q12_SHIFT
Definition constants.h:8
#define MATH_ANGLE_WRAP_MASK
Definition constants.h:16
#define MATH_Q12_ONE
Definition constants.h:9
#define MATH_ANGLE_HALF_TURN
Definition constants.h:14
#define MATH_ANGLE_FULL_TURN
Definition constants.h:13
void Math_BuildMatrixRotationY(struct Math_Matrix3x3I16 *out_matrix, struct Math_Matrix3x3I16 const *left_factor, int32_t angle)
Definition matrices.c:76
int32_t Math_SqrtFP12(uint32_t value)
int16_t Math_CalculateAtan2FP12(int32_t y, int32_t x)
uint32_t Math_GenerateRandom(uint32_t range)
void Math_BuildMatrixRotationXY(struct Math_Matrix3x3I16 *out_matrix, struct Math_Matrix3x3I16 const *left_factor, int32_t angle_x, int32_t angle_y)
Definition matrices.c:120
int32_t Math_AsinRatioFP12(int32_t numerator, int32_t denominator)
int32_t Math_CalculateAtan2Fast(int32_t y, int32_t x)
#define SCENE_NODE_DISABLED
Definition constants.h:24
#define g_objectNodeRoot
Definition globals.h:12
uint8_t collision_class
Definition types.h:435
struct Math_Vec3I32 velocity
Definition types.h:446
int16_t facing_current
Definition types.h:447
struct Bone_JointTrackState * component_array
Definition types.h:432
uint8_t transition_phase
Definition types.h:434
uint8_t lifecycle_flags
Definition types.h:392
uint8_t movement_handler_index
Definition types.h:433
uint8_t actor_type
Definition types.h:391
struct Actor_State * child_actor
Definition types.h:478
struct Collision_Polygon * ground_contact_polygon
Definition types.h:452
struct Collision_Node * ground_collision_node
Definition types.h:451
int32_t behavior_flags
Definition types.h:407
uint16_t z
Definition types.h:497
struct Actor_State * parent_actor
Definition types.h:488
int16_t facing_target
Definition types.h:448
struct Math_Vec3I32 world_render_pos
Definition types.h:420
void * record_ptr
Definition types.h:477
int16_t fade_timer
Definition types.h:438
int16_t facing_blend
Definition types.h:449
struct Math_Matrix3x3I16 rot_mat
Definition types.h:383
int16_t roll_angle
Definition types.h:450
struct Math_Vec3I32 position
Definition types.h:385
uint8_t attach_refcount
Definition types.h:436
int32_t rotation
Definition types.h:476
Definition types.h:118
int16_t facing_current
Definition types.h:200
int16_t facing_blend
Definition types.h:202
struct Math_Vec3I32 position
Definition types.h:132
struct Actor * list_next
Definition types.h:119
int32_t behavior_flags
Definition types.h:160
uint8_t actor_type
Definition types.h:138
int16_t facing_target
Definition types.h:201
uint8_t attach_refcount
Definition types.h:189
int16_t angle_param[0x4]
Definition types.h:890
struct Scene_Node * node
Definition types.h:897
uint16_t attachment_joint_index
Definition types.h:44
struct Component_Definition * definition
Definition types.h:43
struct Math_Vec3I32 position
Definition types.h:47
struct Actor_State * reference_actor
Definition types.h:48
uint16_t damage_cooldown
Definition types.h:45
struct Actor_State * position_source_actor
Definition types.h:46
int32_t homing_turn_step_angle12
Definition types.h:91
int32_t homing_strength
Definition types.h:86
uint8_t max_active_instances
Definition types.h:106
int32_t spawn_camera_shake_amplitude
Definition types.h:97
int32_t owner_turn_step_angle12
Definition types.h:96
int32_t gravity
Definition types.h:85
uint8_t spawn_count
Definition types.h:105
struct Actor * actor_templates[0x4]
Definition types.h:117
uint16_t type0_duration_base
Definition types.h:99
uint16_t type0_duration_range
Definition types.h:101
uint8_t flags_high
Definition types.h:79
Component_CollisionTargetMask collision_neutral_mask
Definition types.h:109
uint16_t type2_duration_base
Definition types.h:100
uint16_t type2_duration_range
Definition types.h:102
int32_t followup_camera_shake_amplitude
Definition types.h:98
uint16_t damage_cooldown
Definition types.h:113
uint8_t active_instance_count
Definition types.h:104
uint16_t type2_duration_stagger
Definition types.h:107
uint32_t flags
Definition types.h:74
struct Scene_Node ** render_node_list
Definition types.h:212
struct Math_Vec3I32 position
Definition types.h:169
struct Math_Matrix3x3I16 rot_mat
Definition types.h:167
struct Math_Vec3I32 world_render_pos
Definition types.h:192
struct Collision_Node * ground_collision_node
Definition types.h:218
struct Component_SpawnParams * spawn_context
Definition types.h:221
struct Math_Vec3I32 velocity
Definition types.h:213
int16_t homing_response_scale
Definition types.h:345
struct Math_Vec3I32 target_pos
Definition types.h:326
struct Component_Definition * definition
Definition types.h:322
struct Actor * owner
Definition types.h:314
struct Actor_State * position_source_actor
Definition types.h:325
int32_t spawn_frame
Definition types.h:335
struct Component_CollisionRecord collision
Definition types.h:318
uint8_t state_flags
Definition types.h:333
struct Actor * attached_actor
Definition types.h:327
uint16_t damage_cooldown
Definition types.h:324
int16_t m12
Definition types.h:167
int16_t m22
Definition types.h:170
int16_t m02
Definition types.h:164
int32_t y
Definition types.h:471
int32_t x
Definition types.h:470
int32_t z
Definition types.h:472
struct Math_Matrix3x3I16 world_rot_matrix
Definition types.h:118
#define g_frameCounter
Definition values.h:501