102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
collision.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
11#include "pcdogs/math/types.h"
13#include <math.h>
14#include <stdarg.h>
15#include <string.h>
16
17// Original pcdogs.exe: 0x42e6e0
18// Passes the spawn context's owner and definition to actor collision classification and returns its tri-state result unchanged.
20{
21 struct Component_SpawnParams *spawn_context = projectile->spawn_context;
22
23 return Actor_CheckCollisionType((struct Actor_State *)spawn_context->owner, spawn_context->definition, other_actor);
24}
25
26// Original pcdogs.exe: 0x42e8c0
27// Calculates collision range from launch speed and the midpoint of the configured range. The special zero-base, unit-range configuration returns the fixed unlimited-range sentinel when speed is nonzero.
29{
30 uint16_t type0_duration_base = definition->type0_duration_base;
31
32 if (!type0_duration_base && definition->type0_duration_range == 1 && definition->initial_vel_xz.z)
34
35 int32_t duration_range = (uint16_t)(definition->type0_duration_range);
36
37 return ((duration_range >> 1) + (uint32_t)type0_duration_base) * definition->initial_vel_xz.z;
38}
39
40// Original pcdogs.exe: 0x42e900
41// Decrements cooldowns and resets collision references and ranges, with separate handling for joint slots and disabled definitions. The decrementing loop requires a positive record count.
42void Component_RefreshCollisionRanges(struct Component_CollisionRecord *collision_records, int32_t slot_count)
43{
44 do
45 {
46 struct Component_Definition *definition = collision_records->definition;
47 int32_t distance = COMPONENT_COLLISION_RANGE_DISABLED;
48
49 if (collision_records->damage_cooldown)
50 --collision_records->damage_cooldown;
51
52 collision_records->reference_actor = NULL;
53 if (definition && (collision_records->attachment_joint_index || (!collision_records->damage_cooldown && Component_HasSpawnCapacity(definition))))
54 {
55 int32_t range = Component_CalculateCollisionRange(definition);
56 distance = range ? (uint32_t)range + COMPONENT_COLLISION_RANGE_PADDING
58 }
59
60 collision_records->current_distance = distance;
61 collision_records->previous_distance = distance;
62 ++collision_records;
63 } while (--slot_count);
64}
65
71
72// Updates collision records against an actor or an explicit position, with actor position taking precedence and a sentinel representing fixed-position hits. Zero count is invalid; a negative count selects one record only on the supported non-class-three actor path.
73void Component_UpdateCollisionSlots(struct Component_CollisionRecord *collision_records, int32_t slot_count,
74 struct Actor_State *actor, struct Actor_State *other_actor,
75 struct Math_Vec3I32 *test_pos,
76 const struct Component_Definition *retained_target_definition)
77{
78 if (other_actor)
79 test_pos = &other_actor->world_render_pos;
80 else if (!test_pos)
81 return;
82
83 bool force_single_slot = false;
84 struct Actor_State *collision_owner;
85
87 {
88 collision_owner = actor;
89
90 if (slot_count < 0)
91 {
92 slot_count = 1;
93 force_single_slot = true;
94 }
95 }
96 else
97 collision_owner = (struct Actor_State *)((struct Component_SpawnParams *)actor->record_ptr)->owner;
98
99 uint32_t remaining = (uint32_t)slot_count;
100 do
101 {
102 struct Component_CollisionRecord *slot = collision_records++;
103 struct Component_Definition *definition = slot->definition;
104
106 continue;
107
108 struct Actor_State *reference = slot->reference_actor;
109 bool other_is_projectile = other_actor && other_actor->collision_class == COLLISION_ACTOR_CLASS_PROJECTILE;
110 if (!force_single_slot && other_actor)
111 {
112 if (other_is_projectile && reference)
113 {
114 if (reference == COMPONENT_FIXED_POSITION_TARGET ||
116 continue;
117 if (!Component_HasProjectileAttachment(definition))
118 {
119 retained_target_definition =
120 ((const struct Component_SpawnParams *)other_actor->record_ptr)->definition;
121 if (Component_HasProjectileAttachment(retained_target_definition))
122 continue;
123 }
124 }
125 if (Actor_CheckCollisionType(collision_owner, definition, other_actor) <= 0)
126 continue;
127 }
128
129 struct Actor_State *position_source_actor =
131 int32_t x = test_pos->x;
132 int32_t target_delta_x;
133 int32_t target_delta_y;
134 int32_t target_delta_z;
135
136 if (position_source_actor)
137 {
138 target_delta_x = x - position_source_actor->position.x;
139 target_delta_y = test_pos->y - position_source_actor->position.y;
140 target_delta_z = test_pos->z - position_source_actor->position.z;
141 }
142 else
143 {
144 target_delta_x = x - actor->world_render_pos.x;
145 target_delta_y = test_pos->y - actor->world_render_pos.y;
146 target_delta_z = test_pos->z - actor->world_render_pos.z;
147 }
148
149 int32_t range = slot->previous_distance;
150 if (!reference || (reference != COMPONENT_FIXED_POSITION_TARGET && reference->collision_class == COLLISION_ACTOR_CLASS_PROJECTILE && (!other_is_projectile || (!Component_HasProjectileAttachment(definition) && Component_HasProjectileAttachment(retained_target_definition)))))
151 range = slot->current_distance;
152
153 // Squared distance check: dot(delta,delta) vs radius*radius
154 uint64_t distance_squared = (uint64_t)((int64_t)target_delta_x * target_delta_x) +
155 (uint64_t)((int64_t)target_delta_y * target_delta_y) +
156 (uint64_t)((int64_t)target_delta_z * target_delta_z);
157 int32_t target_distance_squared = (uint32_t)(distance_squared >> MATH_Q12_SHIFT);
158 uint64_t range_squared = (uint64_t)((int64_t)range * range);
159
160 if ((uint32_t)target_distance_squared < (uint32_t)(range_squared >> MATH_Q12_SHIFT))
161 {
162 int32_t homing_turn_step_angle12 = definition->homing_turn_step_angle12;
163 // Within radius: read collision shape params (cone angles, orientation)
164 int32_t horizontal_cone_width;
165 int32_t vertical_cone_width;
166
167 if (!homing_turn_step_angle12)
168 {
169 int16_t turn_step = definition->initial_target_turn_step_angle12;
170 int32_t turn_magnitude = turn_step;
171
172 vertical_cone_width = turn_magnitude;
173
174 if ((int16_t)turn_magnitude < 0)
175 {
176 turn_magnitude = -(turn_magnitude);
177 vertical_cone_width = turn_magnitude;
178 }
179
180 homing_turn_step_angle12 = (uint16_t)(definition->angular_scatter_width_angle12 + turn_magnitude);
181 horizontal_cone_width = homing_turn_step_angle12;
182
183 if ((int16_t)homing_turn_step_angle12 > MATH_ANGLE_FULL_TURN)
184 horizontal_cone_width = MATH_ANGLE_FULL_TURN;
185 }
186 else
187 {
188 horizontal_cone_width = MATH_ANGLE_FULL_TURN;
189 vertical_cone_width = MATH_ANGLE_FULL_TURN;
190 }
191
192 int32_t yaw_angle = (uint16_t)definition->yaw_offset_angle12;
193
194 int32_t pitch_angle = (uint16_t)definition->pitch_offset_angle12;
195
196 int32_t attachment_joint_index = (uint16_t)(slot->attachment_joint_index);
197 struct Math_Matrix3x3I16 out_matrix;
198
199 if (attachment_joint_index)
200 {
201 struct Bone_JointTrackState *attachment_joint =
202 &actor->component_array[attachment_joint_index - 1];
203
204 Math_MulMat3x3Q12(&out_matrix, &attachment_joint->base_rotation,
205 &attachment_joint->node->world_rot_matrix);
206
207 uint16_t joint_horizontal_width = attachment_joint->angle_param[0];
208
209 horizontal_cone_width = joint_horizontal_width ? horizontal_cone_width + joint_horizontal_width : MATH_ANGLE_FULL_TURN;
210
211 uint16_t joint_vertical_width = attachment_joint->angle_param[1];
212
213 vertical_cone_width = joint_vertical_width ? vertical_cone_width + joint_vertical_width : MATH_ANGLE_FULL_TURN;
214
215 uint16_t joint_yaw = attachment_joint->angle_param[2];
216 uint16_t joint_pitch = attachment_joint->angle_param[3];
217
218 yaw_angle += joint_yaw;
219 pitch_angle += joint_pitch;
220 }
221 else if (definition->base_pitch_angle12 && !(definition->flags & COMPONENT_FLAG_BALLISTIC_PITCH))
222 Math_BuildMatrixRotationX(&out_matrix, &actor->rot_mat, -(int16_t)definition->base_pitch_angle12);
223 else
224 out_matrix = actor->rot_mat;
225
226 /* The original transposes the orientation before projecting the world delta. */
227 int64_t local_x_product = (int64_t)out_matrix.m00 * target_delta_x +
228 (int64_t)out_matrix.m10 * target_delta_y + (int64_t)out_matrix.m20 * target_delta_z;
229 int32_t local_delta_x = (int32_t)(local_x_product >> MATH_Q12_SHIFT);
230 int64_t local_y_product = (int64_t)out_matrix.m01 * target_delta_x +
231 (int64_t)out_matrix.m11 * target_delta_y + (int64_t)out_matrix.m21 * target_delta_z;
232 int32_t local_delta_y = (int32_t)(local_y_product >> MATH_Q12_SHIFT);
233 int64_t local_z_product = (int64_t)out_matrix.m02 * target_delta_x +
234 (int64_t)out_matrix.m12 * target_delta_y + (int64_t)out_matrix.m22 * target_delta_z;
235 int32_t local_delta_z = (int32_t)(local_z_product >> MATH_Q12_SHIFT);
236 int32_t target_half_radius_q12;
237
238 if (!other_actor)
239 target_half_radius_q12 = 0;
240 else
241 target_half_radius_q12 = (int32_t)other_actor->cull_radius << 6 >> 1;
242
243 int32_t horizontal_half_angle = (uint16_t)horizontal_cone_width >> 1;
244
245 if ((int16_t)horizontal_half_angle <= MATH_ANGLE_QUARTER_TURN)
246 {
247 int64_t narrow_yaw_center_x_product = (int64_t)(Math_SinQ14(yaw_angle) >> 2) * local_delta_x;
248 int64_t narrow_yaw_center_z_product = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - yaw_angle) >> 2) * local_delta_z;
249 int32_t horizontal_radius_lower_bound = -(target_half_radius_q12);
250
251 if (!(((int32_t)(narrow_yaw_center_z_product >> MATH_Q12_SHIFT)) + ((int32_t)(narrow_yaw_center_x_product >> MATH_Q12_SHIFT)) >= horizontal_radius_lower_bound))
252 continue;
253
254 int64_t narrow_yaw_upper_x_product = (int64_t)(Math_SinQ14(horizontal_half_angle + yaw_angle - MATH_ANGLE_QUARTER_TURN) >> 2) * local_delta_x;
255 int64_t narrow_yaw_upper_z_product = (int64_t)(Math_SinQ14(MATH_ANGLE_HALF_TURN - horizontal_half_angle - yaw_angle) >> 2) * local_delta_z;
256
257 if (!(((int32_t)(narrow_yaw_upper_z_product >> MATH_Q12_SHIFT)) + ((int32_t)(narrow_yaw_upper_x_product >> MATH_Q12_SHIFT)) >= horizontal_radius_lower_bound))
258 continue;
259
260 int64_t narrow_yaw_lower_x_product = (int64_t)(Math_SinQ14((yaw_angle - horizontal_half_angle + MATH_ANGLE_QUARTER_TURN)) >> 2) * local_delta_x;
261 int64_t narrow_yaw_lower_z_product = (int64_t)(Math_SinQ14(horizontal_half_angle - yaw_angle) >> 2) * local_delta_z;
262
263 if (!(((int32_t)(narrow_yaw_lower_z_product >> MATH_Q12_SHIFT)) + ((int32_t)(narrow_yaw_lower_x_product >> MATH_Q12_SHIFT)) >= horizontal_radius_lower_bound))
264 continue;
265 }
266 else if ((int16_t)horizontal_half_angle < MATH_ANGLE_HALF_TURN)
267 {
268 int64_t wide_yaw_center_x_product = (int64_t)(Math_SinQ14(yaw_angle) >> 2) * local_delta_x;
269 int64_t wide_yaw_center_z_product = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - yaw_angle) >> 2) * local_delta_z;
270
271 if (!(((int32_t)(wide_yaw_center_z_product >> MATH_Q12_SHIFT)) + ((int32_t)(wide_yaw_center_x_product >> MATH_Q12_SHIFT)) >= -(target_half_radius_q12)))
272 {
273 int32_t horizontal_upper_boundary_angle = yaw_angle + horizontal_half_angle;
274 int64_t wide_yaw_upper_x_product = (int64_t)(Math_SinQ14((horizontal_upper_boundary_angle + MATH_ANGLE_QUARTER_TURN)) >> 2) * local_delta_x;
275 int64_t wide_yaw_upper_z_product = (int64_t)(Math_SinQ14(-((int32_t)horizontal_upper_boundary_angle)) >> 2) * local_delta_z;
276
277 if (!(((int32_t)(wide_yaw_upper_z_product >> MATH_Q12_SHIFT)) + ((int32_t)(wide_yaw_upper_x_product >> MATH_Q12_SHIFT)) <= target_half_radius_q12))
278 {
279 int64_t wide_yaw_lower_x_product = (int64_t)(Math_SinQ14((yaw_angle - horizontal_half_angle - MATH_ANGLE_QUARTER_TURN)) >> 2) * local_delta_x;
280 int64_t wide_yaw_lower_z_product = (int64_t)(Math_SinQ14(horizontal_half_angle - yaw_angle + MATH_ANGLE_HALF_TURN) >> 2) * local_delta_z;
281
282 if (!(((int32_t)(wide_yaw_lower_z_product >> MATH_Q12_SHIFT)) + ((int32_t)(wide_yaw_lower_x_product >> MATH_Q12_SHIFT)) <= target_half_radius_q12))
283 continue;
284 }
285 }
286 }
287
288 int32_t target_distance = Math_SqrtFP12(target_distance_squared);
289 int64_t pitch_distance_projection_product = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - pitch_angle) >> 2) * target_distance;
290 int32_t pitch_projected_distance = (int32_t)(pitch_distance_projection_product >> MATH_Q12_SHIFT);
291 int32_t vertical_half_angle = (uint16_t)vertical_cone_width >> 1;
292
293 if ((int16_t)vertical_half_angle <= MATH_ANGLE_QUARTER_TURN)
294 {
295 int64_t narrow_pitch_center_y_product = (int64_t)(Math_SinQ14(pitch_angle) >> 2) * local_delta_y;
296 int64_t narrow_pitch_center_distance_product = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - pitch_angle) >> 2) * pitch_projected_distance;
297 int32_t vertical_radius_lower_bound = -(target_half_radius_q12);
298
299 if (!(((int32_t)(narrow_pitch_center_distance_product >> MATH_Q12_SHIFT)) + ((int32_t)(narrow_pitch_center_y_product >> MATH_Q12_SHIFT)) >= vertical_radius_lower_bound))
300 continue;
301
302 int64_t narrow_pitch_upper_y_product = (int64_t)(Math_SinQ14(vertical_half_angle + pitch_angle - MATH_ANGLE_QUARTER_TURN) >> 2) * local_delta_y;
303 int64_t narrow_pitch_upper_distance_product = (int64_t)(Math_SinQ14(MATH_ANGLE_HALF_TURN - vertical_half_angle - pitch_angle) >> 2) * pitch_projected_distance;
304
305 if (!(((int32_t)(narrow_pitch_upper_distance_product >> MATH_Q12_SHIFT)) + ((int32_t)(narrow_pitch_upper_y_product >> MATH_Q12_SHIFT)) >= vertical_radius_lower_bound))
306 continue;
307
308 int64_t narrow_pitch_lower_y_product = (int64_t)(Math_SinQ14(pitch_angle - vertical_half_angle + MATH_ANGLE_QUARTER_TURN) >> 2) * local_delta_y;
309 int64_t narrow_pitch_lower_distance_product = (int64_t)(Math_SinQ14(vertical_half_angle - pitch_angle) >> 2) * pitch_projected_distance;
310
311 if (!(((int32_t)(narrow_pitch_lower_distance_product >> MATH_Q12_SHIFT)) + ((int32_t)(narrow_pitch_lower_y_product >> MATH_Q12_SHIFT)) >= vertical_radius_lower_bound))
312 continue;
313 }
314 else if ((int16_t)vertical_half_angle < MATH_ANGLE_HALF_TURN)
315 {
316 int64_t wide_pitch_center_y_product = (int64_t)(Math_SinQ14(pitch_angle) >> 2) * local_delta_y;
317 int64_t wide_pitch_center_distance_product = (int64_t)(Math_SinQ14(MATH_ANGLE_QUARTER_TURN - pitch_angle) >> 2) * pitch_projected_distance;
318
319 if (!(((int32_t)(wide_pitch_center_distance_product >> MATH_Q12_SHIFT)) + ((int32_t)(wide_pitch_center_y_product >> MATH_Q12_SHIFT)) >= -(target_half_radius_q12)))
320 {
321 int32_t vertical_upper_boundary_angle = vertical_half_angle + pitch_angle;
322 int64_t wide_pitch_upper_y_product = (int64_t)(Math_SinQ14(vertical_upper_boundary_angle + MATH_ANGLE_QUARTER_TURN) >> 2) * local_delta_y;
323 int64_t wide_pitch_upper_distance_product = (int64_t)(Math_SinQ14(-(vertical_upper_boundary_angle)) >> 2) * pitch_projected_distance;
324
325 if (!(((int32_t)(wide_pitch_upper_distance_product >> MATH_Q12_SHIFT)) + ((int32_t)(wide_pitch_upper_y_product >> MATH_Q12_SHIFT)) <= target_half_radius_q12))
326 {
327 int64_t wide_pitch_lower_y_product = (int64_t)(Math_SinQ14(pitch_angle - vertical_half_angle - MATH_ANGLE_QUARTER_TURN) >> 2) * local_delta_y;
328 int64_t wide_pitch_lower_distance_product = (int64_t)(Math_SinQ14(vertical_half_angle - pitch_angle + MATH_ANGLE_HALF_TURN) >> 2) * pitch_projected_distance;
329
330 if (!(((int32_t)(wide_pitch_lower_distance_product >> MATH_Q12_SHIFT)) + ((int32_t)(wide_pitch_lower_y_product >> MATH_Q12_SHIFT)) <= target_half_radius_q12))
331 continue;
332 }
333 }
334 }
335
336 // Collision confirmed: store distance and source position into contact fields
337 slot->previous_distance = target_distance;
338 slot->position.x = test_pos->x;
339 slot->position.y = test_pos->y;
340 slot->position.z = test_pos->z;
341 slot->reference_actor = other_actor;
342
343 if (!other_actor)
345 }
346
347 } while (--remaining);
348}
349
350// Original pcdogs.exe: 0x42f2c0
351// Accepts an unconstrained height or checks the airborne flag and vertical separation against the referenced actor.
353{
354 int32_t minimum_height = definition->initial_vel_xz.x;
355
356 if (!minimum_height)
357 return 1;
358
359 return (actor->behavior_flags & ACTOR_BEHAVIOR_AIRBORNE && actor->position.y - actor->child_actor->position.y >= minimum_height);
360}
361
362// Original pcdogs.exe: 0x42f330
363// Returns the definition's unsigned 16-bit damage cooldown extended to 32 bits, or zero for a null definition.
365{
366 if (!definition)
367 return 0;
368
369 int32_t cooldown_frames = (uint16_t)(definition->damage_cooldown);
370
371 return cooldown_frames;
372}
373
374// Original pcdogs.exe: 0x42f370
375// Returns whether the actor's component definition enables its airborne-target flag.
380
381// Original pcdogs.exe: 0x42f9f0
382// Turns an active projectile toward its actor target or saved target position, applying yaw limits and optional pitch tracking. Vertically oriented projectiles can snap yaw, and the invalid-angle sentinel preserves the previous angle.
383void Component_TrackTarget(struct Component_ProjectileActorView *projectile, struct Component_Definition *definition, int16_t turn_rate)
384{
385 // Get ComponentInstance from projectile actor
386 // Check if target tracking flag is set (ComponentInstance+0x28 bit 2)
387 struct Component_SpawnParams *spawn_context = projectile->spawn_context;
388
389 if (!(spawn_context->state_flags & COMPONENT_STATE_HAS_TARGET)) // Get target actor from ComponentInstance+0x1C
390 return;
391
392 // Check if target is -1 (use fixed position instead)
393 struct Actor *attached_actor = spawn_context->attached_actor;
394 int32_t target_delta_x_saved;
395 int32_t target_delta_y;
396 int32_t target_delta_x;
397 int32_t target_z;
398
399 if (attached_actor != COMPONENT_FIXED_POSITION_TARGET)
400 {
401 int32_t projectile_y_for_actor = projectile->position.y;
402
403 target_delta_x = attached_actor->world_render_pos.x - projectile->position.x;
404 target_delta_x_saved = target_delta_x;
405 target_delta_y = attached_actor->world_render_pos.y - projectile_y_for_actor;
406 target_z = attached_actor->world_render_pos.z;
407 }
408 else
409 {
410 int32_t projectile_y_for_position = projectile->position.y;
411
412 target_delta_x = spawn_context->target_pos.x - projectile->position.x;
413 target_delta_x_saved = target_delta_x; // Use fixed target position from ComponentInstance+0x10/14/18
414 target_delta_y = spawn_context->target_pos.y - projectile_y_for_position;
415 target_z = spawn_context->target_pos.z;
416 }
417
418 int32_t target_delta_z = target_z - projectile->position.z;
419 int16_t target_yaw = Math_CalculateAtan2FP12(target_delta_z, target_delta_x);
420
421 if (target_yaw != MATH_ANGLE_FULL_TURN)
422 {
423 int16_t pitch_angle = projectile->pitch_angle;
424
425 if (pitch_angle != MATH_ANGLE_QUARTER_TURN && pitch_angle != (int16_t)-MATH_ANGLE_QUARTER_TURN)
426 target_yaw = Math_ClampAngleDelta(target_yaw, projectile->yaw_angle, turn_rate);
427
428 // Calculate yaw angle to target using FastAtan2
429 projectile->yaw_angle = target_yaw;
430 }
431
432 if (definition->flags_high & (COMPONENT_FLAG_BALLISTIC_PITCH >> 8))
433 return;
434
435 definition = (struct Component_Definition *)(&target_delta_x_saved);
436
437 // Store new yaw angle at actor+0x88
438 int16_t target_pitch = Math_AsinRatioFP12(target_delta_y,
439 // Check if pitch tracking enabled (ComponentDef flag bit 15)
440 Math_SqrtFP12((int32_t)((uint64_t)(((int64_t)(target_delta_z)*target_delta_z) + ((int64_t)(target_delta_x_saved)*target_delta_x_saved) + ((int64_t)(target_delta_y)*target_delta_y)) >> MATH_Q12_SHIFT)));
441
442 if (target_pitch != MATH_ANGLE_FULL_TURN)
443 // Calculate pitch angle using Math_Atan2Alternate
444 projectile->pitch_angle = Math_ClampAngleDelta(target_pitch, projectile->pitch_angle, turn_rate);
445}
446
447// Original pcdogs.exe: 0x4304a0
448// Reflects velocity only when the scaled contact dot product is negative, then updates direction and orientation. Otherwise velocity is copied unchanged; the scale is applied directly rather than interpreted as a conventional restitution coefficient.
450{
451 // Get ComponentInstance pointer
452 // Set flag bit 6 at actor+0x30
453 struct Component_SpawnParams *spawn_params = projectile_input->spawn_context;
454
455 projectile_input->behavior_flags |= ACTOR_BEHAVIOR_AIRBORNE;
456
457 // Native ADD/ADC accumulates all three signed products before SHRD.
458 int64_t dot = (int64_t)spawn_params->impact_normal.x * spawn_params->impact_delta.x + (int64_t)spawn_params->impact_normal.y * spawn_params->impact_delta.y + (int64_t)spawn_params->impact_normal.z * spawn_params->impact_delta.z;
459 // The doubling wraps at 32 bits before the next signed multiply.
460 int32_t twice_dot = (uint32_t)(dot >> MATH_Q12_SHIFT) * 2u;
461 int32_t normal_push_scale = (int32_t)(((int64_t)spawn_params->definition->homing_strength * twice_dot) >> MATH_Q12_SHIFT);
462 struct Component_ProjectileActorView *projectile;
463 struct Math_Vec3I32 *homing_velocity;
464
465 if (normal_push_scale < 0)
466 {
467 int64_t normal_push_x_product = (int64_t)normal_push_scale * (int32_t)spawn_params->impact_normal.x;
468
469 // If moving away from target, use target velocity directly
470 homing_velocity = &projectile_input->velocity;
471 homing_velocity->x = (uint32_t)((uint64_t)normal_push_x_product >> MATH_Q12_SHIFT);
472
473 int64_t normal_push_y_product = (int64_t)normal_push_scale * (int32_t)spawn_params->impact_normal.y;
474
475 // Calculate yaw from velocity components
476 projectile_input->velocity.y = (uint32_t)((uint64_t)normal_push_y_product >> MATH_Q12_SHIFT);
477
478 // Store yaw at actor+0x88
479 int64_t normal_push_z_product = (int64_t)normal_push_scale * (int32_t)spawn_params->impact_normal.z;
480
481 // Check if should update pitch from velocity
482 int32_t normal_push_z = (uint32_t)((uint64_t)normal_push_z_product >> MATH_Q12_SHIFT);
483 int32_t normal_push_x = homing_velocity->x;
484
485 projectile_input->velocity.z = normal_push_z;
486
487 int32_t normal_push_y = projectile_input->velocity.y;
488
489 homing_velocity->x = spawn_params->impact_delta.x - normal_push_x;
490 projectile = projectile_input;
491 // Calculate pitch from velocity magnitude
492 projectile_input->velocity.y = spawn_params->impact_delta.y - normal_push_y;
493 projectile_input->velocity.z = spawn_params->impact_delta.z - normal_push_z;
494 }
495 else
496 {
497 projectile = projectile_input;
498 homing_velocity = &projectile->velocity;
499 homing_velocity->x = spawn_params->impact_delta.x;
500 homing_velocity->y = spawn_params->impact_delta.y;
501 homing_velocity->z = spawn_params->impact_delta.z;
502 }
503
504 int32_t reflected_yaw = (int32_t)Math_CalculateAtan2FP12(projectile->velocity.z, homing_velocity->x);
505
506 if (reflected_yaw != MATH_ANGLE_FULL_TURN)
507 projectile->yaw_angle = (uint16_t)reflected_yaw;
508
509 if (spawn_params->definition->gravity)
510 return;
511
512 uint64_t squared_speed = (uint64_t)((int64_t)homing_velocity->x * homing_velocity->x) + (uint64_t)((int64_t)homing_velocity->y * homing_velocity->y) + (uint64_t)((int64_t)homing_velocity->z * homing_velocity->z);
513 int32_t horizontal_speed = Math_SqrtFP12((uint32_t)(squared_speed >> MATH_Q12_SHIFT));
514 int32_t reflected_pitch = (int32_t)Math_AsinRatioFP12(-(projectile_input->velocity.y), horizontal_speed);
515
516 if (reflected_pitch != MATH_ANGLE_FULL_TURN)
517 projectile_input->pitch_angle = (int16_t)-(reflected_pitch)&MATH_ANGLE_WRAP_MASK;
518
519 int32_t angle_x;
520
521 if (!(((uint16_t)spawn_params->definition->flags >> 8) & (COMPONENT_FLAG_YAW_ONLY_ORIENTATION >> 8)))
522 angle_x = -((int32_t)projectile_input->pitch_angle);
523 else
524 angle_x = 0;
525
526 Math_BuildMatrixRotationXY(&projectile_input->rot_mat, NULL, angle_x, projectile_input->yaw_angle);
527}
int32_t Actor_CheckCollisionType(struct Actor_State *actor, struct Component_Definition *component_definition, struct Actor_State *other_actor)
Definition collision.c:286
#define ACTOR_BEHAVIOR_AIRBORNE
Definition constants.h:13
@ COLLISION_ACTOR_CLASS_PROJECTILE
Definition constants.h:69
static bool Component_HasProjectileAttachment(const struct Component_Definition *definition)
Definition collision.c:66
int32_t Component_GetCollisionCooldownFrames(struct Component_Definition const *definition)
Definition collision.c:364
void Component_RefreshCollisionRanges(struct Component_CollisionRecord *collision_records, int32_t slot_count)
Definition collision.c:42
BOOL Component_CheckHeightConstraint(struct Actor_State *actor, struct Component_Definition *definition)
Definition collision.c:352
void Component_ApplyImpactReflection(struct Component_ProjectileActorView *projectile_input)
Definition collision.c:449
int32_t Component_CalculateCollisionRange(struct Component_Definition *definition)
Definition collision.c:28
void Component_UpdateCollisionSlots(struct Component_CollisionRecord *collision_records, int32_t slot_count, struct Actor_State *actor, struct Actor_State *other_actor, struct Math_Vec3I32 *test_pos, const struct Component_Definition *retained_target_definition)
Definition collision.c:73
BOOL Component_IsAirborneTarget(struct Actor_State *actor)
Definition collision.c:376
void Component_TrackTarget(struct Component_ProjectileActorView *projectile, struct Component_Definition *definition, int16_t turn_rate)
Definition collision.c:383
#define COMPONENT_COLLISION_RANGE_DEFAULT
Definition constants.h:27
#define COMPONENT_FLAG_PROJECTILE_ATTACH_PARENT
Definition constants.h:13
#define COMPONENT_COLLISION_RANGE_DISABLED
Definition constants.h:24
#define COMPONENT_AIRBORNE_TARGET_SHIFT
Definition constants.h:40
#define COMPONENT_FIXED_POSITION_TARGET
Definition constants.h:28
#define COMPONENT_FLAG_YAW_ONLY_ORIENTATION
Definition constants.h:17
#define COMPONENT_COLLISION_RANGE_UNLIMITED
Definition constants.h:25
#define COMPONENT_STATE_HAS_TARGET
Definition constants.h:23
#define COMPONENT_FLAG_PROJECTILE_ATTACH_POSITION_SOURCE
Definition constants.h:12
#define COMPONENT_COLLISION_RANGE_PADDING
Definition constants.h:26
#define COMPONENT_FLAG_BALLISTIC_PITCH
Definition constants.h:19
#define COMPONENT_FLAG_AIRBORNE_TARGET
Definition constants.h:18
BOOL Component_HasSpawnCapacity(struct Component_Definition *definition)
Definition lifecycle.c:30
int32_t Component_CheckActorCollisionTypeAdapter(struct Component_ProjectileActorView *comp, struct Actor_State *other_actor)
Definition collision.c:19
#define MATH_Q12_SHIFT
Definition constants.h:8
#define MATH_ANGLE_QUARTER_TURN
Definition constants.h:15
#define MATH_ANGLE_WRAP_MASK
Definition constants.h:16
#define MATH_ANGLE_HALF_TURN
Definition constants.h:14
#define MATH_ANGLE_FULL_TURN
Definition constants.h:13
int32_t Math_SinQ14(int32_t angle)
int32_t Math_SqrtFP12(uint32_t value)
uint16_t Math_ClampAngleDelta(int16_t target_angle, int16_t current_angle, int16_t max_delta)
void Math_BuildMatrixRotationX(struct Math_Matrix3x3I16 *out_matrix, struct Math_Matrix3x3I16 const *left_factor, int32_t angle)
Definition matrices.c:54
void Math_MulMat3x3Q12(struct Math_Matrix3x3I16 *out_matrix, struct Math_Matrix3x3I16 const *right_factor, struct Math_Matrix3x3I16 const *left_factor)
Definition matrices.c:11
int16_t Math_CalculateAtan2FP12(int32_t y, int32_t x)
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)
uint8_t collision_class
Definition types.h:435
uint16_t x
Definition types.h:496
struct Bone_JointTrackState * component_array
Definition types.h:432
int16_t cull_radius
Definition types.h:424
struct Actor_State * child_actor
Definition types.h:478
int32_t behavior_flags
Definition types.h:407
struct Math_Vec3I32 world_render_pos
Definition types.h:420
void * record_ptr
Definition types.h:477
struct Math_Matrix3x3I16 rot_mat
Definition types.h:383
struct Math_Vec3I32 position
Definition types.h:385
Definition types.h:118
struct Math_Vec3I32 world_render_pos
Definition types.h:173
struct Math_Matrix3x3I16 base_rotation
Definition types.h:895
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
int32_t previous_distance
Definition types.h:49
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
int32_t gravity
Definition types.h:85
uint8_t flags_low
Definition types.h:78
uint16_t type0_duration_base
Definition types.h:99
int32_t initial_target_turn_step_angle12
Definition types.h:93
uint16_t type0_duration_range
Definition types.h:101
uint8_t flags_high
Definition types.h:79
int32_t angular_scatter_width_angle12
Definition types.h:92
int32_t pitch_offset_angle12
Definition types.h:95
uint16_t damage_cooldown
Definition types.h:113
int32_t yaw_offset_angle12
Definition types.h:94
int32_t base_pitch_angle12
Definition types.h:87
uint32_t flags
Definition types.h:74
struct Math_Vec2I32XZ initial_vel_xz
Definition types.h:84
struct Math_Vec3I32 position
Definition types.h:169
struct Math_Matrix3x3I16 rot_mat
Definition types.h:167
struct Component_SpawnParams * spawn_context
Definition types.h:221
struct Math_Vec3I32 velocity
Definition types.h:213
struct Math_Vec3I32 target_pos
Definition types.h:326
struct Component_Definition * definition
Definition types.h:322
struct Math_Vec3I16 impact_normal
Definition types.h:342
struct Actor * owner
Definition types.h:314
struct Math_Vec3I32 impact_delta
Definition types.h:344
uint8_t state_flags
Definition types.h:333
struct Actor * attached_actor
Definition types.h:327
int16_t m21
Definition types.h:169
int16_t m00
Definition types.h:162
int16_t m01
Definition types.h:163
int16_t m12
Definition types.h:167
int16_t m11
Definition types.h:166
int16_t m20
Definition types.h:168
int16_t m22
Definition types.h:170
int16_t m02
Definition types.h:164
int16_t m10
Definition types.h:165
int32_t x
Definition types.h:435
int32_t z
Definition types.h:436
int16_t z
Definition types.h:460
int16_t x
Definition types.h:458
int16_t y
Definition types.h:459
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