Skip to content

Commit

Permalink
Updated ai
Browse files Browse the repository at this point in the history
  • Loading branch information
twist84 committed Feb 4, 2025
1 parent 3cb7caa commit 833e24f
Show file tree
Hide file tree
Showing 20 changed files with 729 additions and 59 deletions.
3 changes: 3 additions & 0 deletions game/game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ copy /b $(ProjectDir)source\config\version.cpp +,, $(ProjectDir)source\config\ve
<ClCompile Include="source\ai\ai_reference_frame.cpp" />
<ClCompile Include="source\ai\ai_vehicles.cpp" />
<ClCompile Include="source\ai\clump.cpp" />
<ClCompile Include="source\ai\joint_behavior.cpp" />
<ClCompile Include="source\ai\objectives.cpp" />
<ClCompile Include="source\ai\path.cpp" />
<ClCompile Include="source\ai\path_obstacles.cpp" />
<ClCompile Include="source\ai\path_smoothing.cpp" />
<ClCompile Include="source\ai\props.cpp" />
Expand Down Expand Up @@ -785,6 +787,7 @@ copy /b $(ProjectDir)source\config\version.cpp +,, $(ProjectDir)source\config\ve
<ClInclude Include="source\ai\ai_vehicles.hpp" />
<ClInclude Include="source\ai\behavior.hpp" />
<ClInclude Include="source\ai\character_definitions.hpp" />
<ClInclude Include="source\ai\path.hpp" />
<ClInclude Include="source\ai\path_obstacles.hpp" />
<ClInclude Include="source\ai\path_obstacle_avoidance.hpp" />
<ClInclude Include="source\ai\path_smoothing.hpp" />
Expand Down
9 changes: 9 additions & 0 deletions game/game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,12 @@
<ClCompile Include="source\bink\bink_definitions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\ai\joint_behavior.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\ai\path.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="source\camera\camera.hpp">
Expand Down Expand Up @@ -4028,6 +4034,9 @@
<ClInclude Include="source\bink\bink_definitions.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="source\ai\path.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource\resource.rc">
Expand Down
114 changes: 79 additions & 35 deletions game/source/ai/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
//.text:01428E80 ; bool __cdecl actor_create_kamikaze_grenades(long)
//.text:01428EE0 ; void __cdecl actor_customize_unit(long, long, long, long, short, long)
//.text:014291D0 ; void __cdecl actor_customize_weapon(long, long)
//.text:01429350 ; bool __cdecl actor_datum_available_to_current_thread()

bool __cdecl actor_datum_available_to_current_thread()
{
//return INVOKE(0x01429350, actor_datum_available_to_current_thread);

TLS_DATA_GET_VALUE_REFERENCE(actor_data);
return actor_data != NULL;
}

void __cdecl actor_delete(long actor_index, bool a2)
{
Expand Down Expand Up @@ -72,8 +79,16 @@ void __cdecl actor_erase(long actor_index, bool delete_immediately)
//.text:0142A370 ; void __cdecl actor_freeze(long)
//.text:0142A420 ; void __cdecl actor_freeze_unit(long, long)
//.text:0142A480 ; bool __cdecl actor_general_update(long)

actor_datum* __cdecl actor_get(long actor_index)
{
TLS_DATA_GET_VALUE_REFERENCE(actor_data);

return DATUM_GET(actor_data, actor_datum, actor_index);
}

//.text:0142A630 ; bool __cdecl actor_get_active_camo_state(long)
//.text:0142A680 ;
//.text:0142A680 ; long __cdecl actor_get_backpack_weapon(long)
//.text:0142A6C0 ; bool __cdecl actor_get_crouch_velocity(long, real*)
//.text:0142A710 ; short __cdecl actor_get_desired_area_type(long)
//.text:0142A770 ; short __cdecl actor_get_enemies_in_sphere(long, real_point3d*, real, long*, short)
Expand Down Expand Up @@ -105,9 +120,38 @@ void __cdecl actor_erase(long actor_index, bool delete_immediately)
//.text:0142BD10 ; void __cdecl actor_initiate_combat(long)
//.text:0142BD90 ; void __cdecl actor_input_sample_position(long, long, actor_position_data*)
//.text:0142BE50 ; void __cdecl actor_input_update(long)
//.text:0142C690 ; bool __cdecl actor_is_active(actor_datum const*)
//.text:0142C6A0 ; bool __cdecl actor_is_blind(long)
//.text:0142C700 ; bool __cdecl actor_is_deaf(long)

bool __cdecl actor_is_active(actor_datum const* actor)
{
//return INVOKE(0x0142C690, actor_is_active, actor);

return actor->meta.active;
}

bool __cdecl actor_is_blind(long actor_index)
{
return INVOKE(0x0142C6A0, actor_is_blind, actor_index);

//actor_datum const* actor = actor_get(actor_index);
//if (actor->state.blind || !actor->meta.active || actor->state.mode == 1)
// return true;
//
//long squad_index = actor->meta.squad_index;
//return squad_index != NONE && squad_is_blind(squad_index);
}

bool __cdecl actor_is_deaf(long actor_index)
{
return INVOKE(0x0142C700, actor_is_deaf, actor_index);

//actor_datum const* actor = actor_get(actor_index);
//if (actor->state.deaf || !actor->meta.active)
// return true;
//
//long squad_index = actor->meta.squad_index;
//return squad_index != NONE && squad_is_deaf(squad_index);
}

//.text:0142C750 ; bool __cdecl actor_is_fighting(long)
//.text:0142C770 ; bool __cdecl actor_is_giant(long)
//.text:0142C7A0 ; bool __cdecl actor_is_giant(actor_datum*)
Expand Down Expand Up @@ -194,26 +238,44 @@ actor_datum* __cdecl actor_iterator_next(actor_iterator* iterator)
//.text:0142F6E0 ; bool __cdecl actor_uses_gravemind(long)
//.text:0142F6F0 ; bool __cdecl actor_vehicle_charge_allowed(long)
//.text:0142F860 ; void __cdecl actor_vehicle_update(long)
//.text:0142FD10 ; void __cdecl actors_dispose()
//.text:0142FD30 ; void __cdecl actors_dispose_from_old_map()

void __cdecl actors_dispose()
{
INVOKE(0x0142FD10, actors_dispose);
}

void __cdecl actors_dispose_from_old_map()
{
INVOKE(0x0142FD30, actors_dispose_from_old_map);
}

//.text:0142FD50 ; void __cdecl actors_freeze()
//.text:0142FDC0 ; void __cdecl actors_initialize()
//.text:0142FE80 ; void __cdecl actors_initialize_for_new_map()

void __cdecl actors_initialize()
{
INVOKE(0x0142FDC0, actors_initialize);
}

void __cdecl actors_initialize_for_new_map()
{
INVOKE(0x0142FE80, actors_initialize_for_new_map);
}

//.text:0142FEC0 ; void __cdecl actors_move_randomly()
//.text:0142FF30 ; void __cdecl actors_update()
//.text:014302E0 ; bool __cdecl ai_area_type_allowed(short, area_definition const*)
//.text:01430340 ;
//.text:01430350 ;
//.text:01430390 ;
//.text:014303D0 ;
//.text:01430350 ; t_restricted_allocation_manager<1,0,0,&void __tls_set_g_actor_data_allocator(void*)>::allocate
//.text:01430390 ; t_restricted_allocation_manager<1,0,0,&void __tls_set_g_ai_reference_frame_data_allocator(void*)>::allocate
//.text:014303D0 ; t_restricted_allocation_manager<1,0,0,&void actor_firing_position_hash_set_address(void*)>::allocate
//.text:01430410 ;
//.text:01430430 ;
//.text:01430450 ;
//.text:01430460 ;
//.text:01430470 ;
//.text:01430480 ;
//.text:014304B0 ;
//.text:014304E0 ;
//.text:01430480 ; t_restricted_allocation_manager<1,0,0,&void __tls_set_g_actor_data_allocator(void*)>::deallocate
//.text:014304B0 ; t_restricted_allocation_manager<1,0,0,&void __cdecl __tls_set_g_ai_reference_frame_data_allocator(void*)>::deallocate
//.text:014304E0 ; t_restricted_allocation_manager<1,0,0,&void __cdecl actor_firing_position_hash_set_address(void*)>::deallocate
//.text:01430510 ;
//.text:01430520 ;
//.text:01430550 ;
Expand All @@ -223,8 +285,8 @@ actor_datum* __cdecl actor_iterator_next(actor_iterator* iterator)
//.text:014305D0 ;
//.text:014305F0 ;
//.text:01430610 ;
//.text:01430620 ;
//.text:01430660 ;
//.text:01430620 ; t_restricted_allocation_manager<1,0,0,&void __tls_set_g_actor_data_allocator(void*)>::reserve_memory
//.text:01430660 ; t_restricted_allocation_manager<1,0,0,&void __tls_set_g_ai_reference_frame_data_allocator(void*)>::reserve_memory
//.text:014306A0 ;
//.text:014306E0 ; long __cdecl actor_create(long, long, long, bool)
//.text:01430840 ;
Expand All @@ -233,21 +295,3 @@ actor_datum* __cdecl actor_iterator_next(actor_iterator* iterator)
//.text:01430890 ;
//.text:014308B0 ;

actor_datum* actor_get(long actor_index)
{
TLS_DATA_GET_VALUE_REFERENCE(actor_data);

return DATUM_GET(actor_data, actor_datum, actor_index);
}

bool actor_datum_available_to_current_thread()
{
TLS_DATA_GET_VALUE_REFERENCE(actor_data);
return actor_data != NULL;
}

bool actor_is_active(actor_datum const* actor)
{
return actor->meta.active;
}

12 changes: 9 additions & 3 deletions game/source/ai/actors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,18 @@ struct actor_iterator
};
static_assert(sizeof(actor_iterator) == 0x18);

extern bool __cdecl actor_datum_available_to_current_thread();
extern void __cdecl actor_delete(long actor_index, bool a2);
extern void __cdecl actor_erase(long actor_index, bool delete_immediately);
extern actor_datum* __cdecl actor_get(long actor_index);
extern bool __cdecl actor_is_active(actor_datum const* actor);
extern bool __cdecl actor_is_blind(long actor_index);
extern bool __cdecl actor_is_deaf(long actor_index);
extern void __cdecl actor_iterator_new(actor_iterator* iterator, bool a2);
extern actor_datum* __cdecl actor_iterator_next(actor_iterator* iterator);
extern void __cdecl actors_dispose();
extern void __cdecl actors_dispose_from_old_map();
extern void __cdecl actors_initialize();
extern void __cdecl actors_initialize_for_new_map();

extern actor_datum* actor_get(long actor_index);
extern bool actor_datum_available_to_current_thread();
extern bool actor_is_active(actor_datum const* actor);

95 changes: 91 additions & 4 deletions game/source/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,121 @@
#include "memory/thread_local.hpp"

//.text:014308D0 ; void __cdecl __tls_set_g_ai_globals_allocator(void*)
//.text:014308F0 ; long __cdecl actor_endangering_player(bool, bool, dword*)

long __cdecl actor_endangering_player(bool must_be_attacking, bool build_player_mask, dword* player_mask_out)
{
return INVOKE(0x014308F0, actor_endangering_player, must_be_attacking, build_player_mask, player_mask_out);
}

//.text:01430DB0 ; bool __cdecl actor_resurrection_biped_safe(long)
//.text:014310A0 ; bool __cdecl ai_adjust_damage(long, long, s_damage_data*, real*)
//.text:014312F0 ; double __cdecl ai_chance_this_tick(real)
//.text:01431360 ; void __cdecl ai_create_mounted_weapons_for_unit(long)
//.text:014313B0 ; double __cdecl ai_danger_level(short)
//.text:014314C0 ;
//.text:014314C0 ; void __cdecl ai_debug_update(void)

void __cdecl ai_dispose()
{
INVOKE(0x014314D0, ai_dispose);

//ai_script_dispose();
//squads_dispose();
//clumps_dispose();
//joint_behavior_dispose();
//cs_dispose();
//props_dispose();
//actors_dispose();
//paths_dispose();
}

void __cdecl ai_dispose_from_old_map()
{
INVOKE(0x01431500, ai_dispose_from_old_map);

//TLS_DATA_GET_VALUE_REFERENCE(ai_globals);
//if (ai_globals->ai_initialized_for_map)
//{
// ai_script_dispose_from_old_map();
// squads_dispose_from_old_map();
// clumps_dispose_from_old_map();
// joint_behavior_dispose_from_old_map();
// cs_dispose_from_old_map();
// dynamic_firing_sets_dispose_from_old_map();
// squad_patrol_dispose_from_old_map();
// formations_dispose_from_old_map();
// props_dispose_from_old_map();
// actors_dispose_from_old_map();
// swarms_dispose_from_old_map();
// paths_dispose_from_old_map();
// ai_dialogue_dispose_from_old_map();
// flocks_dispose_from_old_map();
// ai_globals->ai_initialized_for_map = false;
//}
}

void __cdecl ai_dispose_from_old_structure_bsp(dword deactivating_structure_bsp_mask)
{
INVOKE(0x01431570, ai_dispose_from_old_structure_bsp, deactivating_structure_bsp_mask);

//TLS_DATA_GET_VALUE_REFERENCE(ai_globals);
//if (ai_globals->ai_initialized_for_map)
//{
// flocks_dispose_from_old_structure_bsp();
//
// actor_iterator actor_iter{};
// actor_iterator_new(&actor_iter, false);
// for (actor_datum* actor = actor_iterator_next(&actor_iter); actor; actor = actor_iterator_next(&actor_iter))
// {
// char bsp_index = actor->input.position.body_location.cluster_reference.bsp_index;
// if (bsp_index != NONE && TEST_BIT(deactivating_structure_bsp_mask, bsp_index))
// {
// actor_set_active(actor_iter.index, true);
// actor->input.position.body_location = (s_location)-1;
// }
// }
//
// squad_iterator squad_iter{};
// squad_iterator_new(&squad_iter);
// for (squad_datum* squad = squad_iterator_next(&squad_iter); squad; squad = squad_iterator_next(&squad_iter))
// {
// if (SLOBYTE(squad->flags) < 0)
// {
// squad_actor_iterator squad_actor_iter{};
// squad_actor_iterator_new(&squad_actor_iter, squad_iter.squad_index, true);
// if (!squad_actor_iterator_next(&squad_actor_iter))
// {
// squad_deactivate(squad_iter.squad_index);
// }
// }
// }
//}
}

//.text:01431670 ; bool __cdecl ai_enemies_attacking_players(long*, dword*)
bool __cdecl ai_enemies_attacking_players(long* attacking_object_index, dword* player_mask_out)
{
return INVOKE(0x01431670, ai_enemies_attacking_players, attacking_object_index, player_mask_out);

//long actor_index = actor_endangering_player(true, true, player_mask_out);
//if (actor_index != NONE)
//{
// actor_datum* actor = actor_get(actor_index);
// *attacking_object_index = actor->meta.unit_index;
//}
//return *player_mask_out != 0;
}

bool __cdecl ai_enemies_can_see_player(long* object_index)
{
return INVOKE(0x014316D0, ai_enemies_can_see_player, object_index);

//long actor_index = actor_endangering_player(false, false, NULL);
//if (actor_index != NONE)
//{
// actor_datum* actor = actor_get(actor_index);
// *object_index = actor->meta.unit_index;
// return true;
//}
//return false;
}

void __cdecl ai_erase(long squad_index, bool delete_immediately)
Expand Down Expand Up @@ -113,7 +200,7 @@ void __cdecl ai_handle_bump(long biped_index, long object_index, real_vector3d c
//.text:01433790 ; void __cdecl ai_handle_projectile_impact(long, long)
//.text:014337C0 ; void __cdecl ai_handle_sector_point_move(short, short, short, real_vector3d const*, s_tag_block_definition const*)
//.text:014337D0 ; void __cdecl ai_handle_spatial_effect(long, real_point3d const*, short, short, short)
//.text:01433A70 ;
//.text:01433A70 ; void __cdecl ai_handle_spawn_point_change(short, short)
//.text:01433A80 ; void __cdecl ai_handle_squad_addition(long)
//.text:01433A90 ; void __cdecl ai_handle_squad_deletion(dword const*)
//.text:01433AA0 ; void __cdecl ai_handle_squad_editing()
Expand Down
Loading

0 comments on commit 833e24f

Please sign in to comment.