63 int32_t best_path_distance, int32_t trace_flags,
struct Entity *steering_entity)
75 int32_t resolved_target_selector = target_selector;
77 uint32_t target_distance;
78 int32_t target_delta_x;
80 int32_t target_delta_z;
81 bool target_visible =
false;
82 bool apply_target_steering =
false;
89 int32_t target_radius;
91 bool resolve_target_position =
false;
95 if (resolved_target_selector)
96 resolve_target_position =
true;
99 int32_t attached_target_selector = (int32_t)source_entity->
attach_offset_x;
101 target_selector = attached_target_selector;
103 if (attached_target_selector)
108 resolved_target_selector = target_selector;
109 resolve_target_position =
true;
118 int32_t all_entities_trace_flags = trace_flags;
121 trace_flags = all_entities_trace_flags;
126 if (!all_entities_target_update_mask)
143 int32_t candidate_entity_selector = 1;
145 steering_entity = entity_array;
149 int32_t candidate_entity_count;
153 if (entity_array != source_entity)
159 struct Actor *candidate_actor;
165 int32_t candidate_trace_flags = trace_flags;
171 candidate_entity_selector, INT32_MAX, best_path_distance,
172 candidate_trace_flags);
174 if (candidate_trace_result)
176 target_selector = candidate_trace_result;
183 candidate_entity_selector += 1;
184 entity_array = &entity_array[1];
186 }
while (candidate_entity_selector <= candidate_entity_count);
188 steering_entity = entity_array;
195 target_delta_x = source_entity->
path_target.
x - position_ptr->
x;
197 target_delta_z = source_entity->
path_target.
z - position_ptr->
z;
199 if (!all_entities_target_update_mask)
202 target_distance = (uint32_t)best_path_distance;
204 target_visible =
true;
205 apply_target_steering =
true;
210 if ((uint32_t)resolved_target_selector + 0x8000u > 9u)
211 resolve_target_position =
true;
214 switch (resolved_target_selector)
218 void *sole_active_actor;
219 int32_t sole_active_entity_address;
221 if (*(uint32_t *)active_entity_words == 1)
223 sole_active_entity_address = active_entity_words[1];
224 steering_entity = (
struct Entity *)(uintptr_t)sole_active_entity_address;
225 sole_active_actor = (
void *)((uint32_t)(uintptr_t)((
const struct Entity *)(uintptr_t)sole_active_entity_address)->
runtime_actor);
232 if (!active_list_target_update_mask)
248 if (*(uint32_t *)navigation_work_list > 0)
250 int32_t best_active_list_distance = best_path_distance;
251 uintptr_t active_list_byte_offset = 4;
255 int32_t active_candidate_address =
258 steering_entity = (
struct Entity *)(uintptr_t)active_candidate_address;
260 if ((uintptr_t)active_candidate_address != (uintptr_t)source_entity)
262 void *active_candidate_actor = (
void *)((uint32_t)(uintptr_t)((
const struct Entity *)(uintptr_t)active_candidate_address)->
runtime_actor);
264 if (active_candidate_actor
268 int32_t active_candidate_trace_flags = trace_flags;
272 int32_t active_index_product_high;
276 int32_t active_index_quotient = active_index_product_high >> 6;
278 active_index_quotient + ((uint32_t)active_index_quotient >> 0x1f) + 1, INT32_MAX,
279 best_active_list_distance, active_candidate_trace_flags);
281 if (active_candidate_trace_result)
283 best_active_list_distance = source_entity->path_best_distance;
284 target_selector = active_candidate_trace_result;
291 active_list_byte_offset += 4;
292 }
while ((uint32_t)i < *(uint32_t *)navigation_work_list);
294 best_path_distance = best_active_list_distance;
305 if (!active_list_target_update_mask)
308 target_distance = (uint32_t)best_path_distance;
310 target_visible =
true;
311 apply_target_steering =
true;
314 else if ((uintptr_t)sole_active_entity_address != (uintptr_t)source_entity
318 int32_t sole_index_product_high;
320 sole_index_product_high = (int32_t)((uint64_t)((int64_t)(int32_t)(
ENTITY_INDEX_RECIPROCAL) * (int32_t)((sole_active_entity_address - (intptr_t)target_level->
entity_array))) >> 32);
322 int32_t sole_index_quotient = sole_index_product_high >> 6;
324 resolved_target_selector = sole_index_quotient + ((uint32_t)sole_index_quotient >> 0x1f) + 1;
325 target_selector = resolved_target_selector;
327 resolve_target_position =
true;
338 int32_t active_respawn_index = (uint8_t)(source_entity->
active_flag);
340 target_selector = ((int32_t)UINT32_MAX) - active_respawn_index;
342 resolved_target_selector = target_selector;
343 resolve_target_position =
true;
353 if (!respawn_target_update_mask)
365 int32_t respawn_candidate_ordinal = 1;
369 int32_t best_respawn_distance = best_path_distance;
370 int32_t respawn_trace_flags = trace_flags;
374 int32_t respawn_target_selector = ((int32_t)UINT32_MAX);
376 bool more_respawn_targets;
381 respawn_target_selector, INT32_MAX, best_respawn_distance, respawn_trace_flags);
383 if (respawn_trace_result)
386 target_selector = respawn_trace_result;
391 respawn_target_selector -= 1;
392 more_respawn_targets = respawn_candidate_ordinal + 1 <= respawn_target_count;
393 respawn_candidate_ordinal += 1;
394 }
while (more_respawn_targets);
396 best_path_distance = best_respawn_distance;
407 if (!respawn_target_update_mask)
410 target_distance = (uint32_t)best_path_distance;
412 target_visible =
true;
413 apply_target_steering =
true;
422 resolve_target_position =
true;
431 target_selector = ((int32_t)UINT32_MAX);
432 resolved_target_selector = ((int32_t)UINT32_MAX);
433 resolve_target_position =
true;
443 target_selector = -(last_respawn_ordinal);
444 resolved_target_selector = target_selector;
445 resolve_target_position =
true;
453 if (resolve_target_position)
465 resolved_target_position = &command->
pos;
466 target_radius = command->
speed;
473 else if (resolved_target_selector < 0)
477 if (resolved_target_selector >= ((int32_t)0xffffff9b))
483 resolved_target_position = NULL;
486 target_scene_node; target_scene_node = target_scene_node->next_in_resource_list)
488 if ((uint8_t)target_scene_node->type_specific_secondary_render_or_sound_index == (uint8_t)(resolved_target_selector - 0x68))
490 resolved_target_position = &target_scene_node->world_pos;
497 else if (resolved_target_selector > 0)
499 steering_entity = &target_level->
entity_array[resolved_target_selector - 1];
500 uint32_t selected_entity_flags = steering_entity->
flags;
505 resolved_target_position = NULL;
509 resolved_target_position = steering_entity->
position_ptr;
518 position = resolved_target_position;
522 target_delta_x = position->
x - position_ptr->
x;
523 target_delta_z = position->
z - position_ptr->
z;
525 int32_t direction_mode_height_offset;
528 direction_mode_height_offset = 0;
530 direction_mode_height_offset =
538 if (target_distance <= (uint32_t)target_radius + (uint32_t)best_path_distance)
540 int32_t candidate_trace_flags = trace_flags;
546 target_visible =
true;
552 int32_t passes_frustum =
556 return passes_frustum;
558 target_visible =
true;
562 int32_t source_facing_angle;
576 int32_t view_half_angle = source_entity->
param_108 >> 0xd;
577 if (
target_in_view_cone(angle, view_half_angle, target_delta_x, target_delta_z, target_radius))
581 target_visible =
true;
582 apply_target_steering =
true;
596 end_pos.
z = collision_end_z;
603 start_pos.
z = collision_start_z;
608 target_visible =
true;
609 apply_target_steering =
true;
622 int32_t navigation_target_filter = trace_flags;
623 int32_t attach_offset_x;
628 navigation_target_filter = attach_offset_x;
631 if (trace_flags || attach_offset_x > 0)
635 int32_t source_index_product_high;
639 int32_t source_index_quotient = source_index_product_high >> 6;
642 int32_t source_selector = source_index_quotient + ((uint32_t)source_index_quotient >> 0x1f) + 1;
644 if (!best_path_distance)
649 int32_t navigation_command_index = 0;
669 if (command_target_selector_a != source_selector)
673 if (command_target_selector_b == source_selector ||
678 if (command_target_selector_a == navigation_target_filter ||
685 if (
Actor_TracePath(source_entity, navigation_command_index + 1, INT32_MAX,
698 int32_t next_navigation_command_index = navigation_command_index + 1;
700 navigation_command_index = next_navigation_command_index;
702 if (next_navigation_command_index >= navigation_work_list_local->
nav_command_count)
711 target_delta_x = source_entity->
path_target.
x - position_ptr->
x;
712 target_delta_z = source_entity->
path_target.
z - position_ptr->
z;
715 int32_t saved_path_target_y = end_pos.
y;
719 int32_t saved_path_target_z = end_pos.
z;
723 target_distance = (uint32_t)best_path_distance;
728 target_visible =
true;
729 apply_target_steering =
true;
737 if (apply_target_steering)
743 int32_t steering_facing_angle;
771 int32_t direction_mode_height_offset_for_result;
774 direction_mode_height_offset_for_result = 0;
789 if (target_selector < 0)
793 if (target_selector >= -(result_respawn_target_count))
795 source_entity->
active_flag = UINT8_MAX - (uint8_t)target_selector;
797 if (target_distance <= (uint32_t)max_path_distance)
799 uint32_t reached_target_flags = source_entity->
flags;
802 source_entity->
flags = reached_target_flags;
808 if (target_distance <= (uint32_t)max_path_distance)
809 return target_selector;