Skip to content

Commit

Permalink
Adjustments to '*group_states'
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Sep 27, 2024
1 parent 78d1f4e commit c4965f7
Show file tree
Hide file tree
Showing 25 changed files with 704 additions and 678 deletions.
217 changes: 109 additions & 108 deletions src/xrGame/ai/monsters/group_states/group_state_attack.cpp

Large diffs are not rendered by default.

88 changes: 46 additions & 42 deletions src/xrGame/ai/monsters/group_states/group_state_attack_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ CStateGroupAttackRun::CStateGroupAttackRun(CBaseMonster* object) : inherited(obj
{
m_pDog = smart_cast<CustomDog*>(object);

m_next_encircle_tick = 0;
m_time_path_rebuild = {};

m_next_encircle_tick = {};
m_encircle_time = {};
m_encircle_dir = {};

m_intercept_tick = {};
m_intercept_length = {};
m_intercept = {};

m_memorized_tick = {};
m_memorized_pos = {};
m_predicted_vel = {};

m_next_encircle_tick = {};
}

CStateGroupAttackRun::~CStateGroupAttackRun()
Expand All @@ -32,9 +46,8 @@ CStateGroupAttackRun::~CStateGroupAttackRun()
void CStateGroupAttackRun::initialize()
{
inherited::initialize();
this->object->path().prepare_builder();
object->path().prepare_builder();

// interception
m_intercept_tick = Device.dwTimeGlobal;
m_intercept.setHP(::Random.randF(M_PI * 2.f), 0);
m_intercept.normalize_safe();
Expand All @@ -45,12 +58,10 @@ void CStateGroupAttackRun::initialize()

m_intercept_length = 3000 + rand() % 4000;

// prediction
m_memorized_tick = Device.dwTimeGlobal;
m_memorized_pos = this->object->EnemyMan.get_enemy()->Position();
m_memorized_pos = object->EnemyMan.get_enemy()->Position();
m_predicted_vel = cr_fvector3(0.f);

// encirclement
if (Device.dwTimeGlobal > m_next_encircle_tick)
{
m_encircle_time = 2000 + rand() % 4000;
Expand All @@ -62,11 +73,11 @@ void CStateGroupAttackRun::initialize()
}

m_encircle_dir = m_intercept;
CMonsterSquad* squad = monster_squad().get_squad(this->object);
CMonsterSquad* squad = monster_squad().get_squad(object);
if (squad && squad->SquadActive())
{
SSquadCommand command;
squad->GetCommand(this->object, command);
squad->GetCommand(object, command);
if (command.type == SC_ATTACK)
{
m_encircle_dir = command.direction;
Expand All @@ -93,7 +104,7 @@ void CStateGroupAttackRun::execute()
}
}

const Fvector enemy_pos = this->object->EnemyMan.get_enemy()->Position();
const Fvector enemy_pos = object->EnemyMan.get_enemy()->Position();
const int memory_update_ms = 250;

if (Device.dwTimeGlobal > m_memorized_tick + memory_update_ms)
Expand All @@ -105,11 +116,11 @@ void CStateGroupAttackRun::execute()
m_memorized_pos = enemy_pos;
}

const SVelocityParam velocity_run = this->object->move().get_velocity
const SVelocityParam velocity_run = object->move().get_velocity
(MonsterMovement::eVelocityParameterRunNormal);

const float self_vel = velocity_run.velocity.linear;
const Fvector self_pos = this->object->Position();
const Fvector self_pos = object->Position();

const Fvector self2enemy = enemy_pos - self_pos;
const float self2enemy_dist = magnitude(self2enemy);
Expand All @@ -127,7 +138,6 @@ void CStateGroupAttackRun::execute()
}
}

// classify if predicted enemy going to the left or right (viewed from our eyes)
const Fvector linear_prediction = enemy_pos + m_predicted_vel * prediction_time;
const Fvector self2linear = linear_prediction - self_pos;
const bool predicted_left = crossproduct(self2linear, self2enemy).z > 0;
Expand All @@ -145,65 +155,60 @@ void CStateGroupAttackRun::execute()

Fvector target = radial_prediction + m_intercept * self2enemy_dist * 0.5f;

const u32 old_vertex = this->object->ai_location().level_vertex_id();
const u32 old_vertex = object->ai_location().level_vertex_id();

u32 vertex = ai().level_graph().check_position_in_direction(old_vertex, self_pos, target);

if (!ai().level_graph().valid_vertex_id(vertex))
{
target = enemy_pos;
vertex = this->object->EnemyMan.get_enemy()->ai_location().level_vertex_id();
vertex = object->EnemyMan.get_enemy()->ai_location().level_vertex_id();
}

// установка параметров функциональных блоков
this->object->set_action(ACT_RUN);
object->set_action(ACT_RUN);

object->anim().accel_activate(eAT_Aggressive);
object->anim().accel_set_braking(false);
object->path().set_target_point(target, vertex);
object->path().set_rebuild_time(object->get_attack_rebuild_time());
object->path().set_use_covers(false);

this->object->anim().accel_activate(eAT_Aggressive);
this->object->anim().accel_set_braking(false);
this->object->path().set_target_point(target, vertex);
this->object->path().set_rebuild_time(this->object->get_attack_rebuild_time());
this->object->path().set_use_covers(false);
//this->object->path().set_cover_params (0.1f, 30.f, 1.f, 30.f);
this->object->set_state_sound(MonsterSound::eMonsterSoundAggressive);
object->set_state_sound(MonsterSound::eMonsterSoundAggressive);

this->object->path().extrapolate_path(true);
object->path().extrapolate_path(true);

this->object->path().set_try_min_time(self2enemy_dist >= 5.f);
object->path().set_try_min_time(self2enemy_dist >= 5.f);

const bool enemy_at_home = this->object->Home->at_home(enemy_pos);
const bool enemy_at_home = object->Home->at_home(enemy_pos);

if (!enemy_at_home || Device.dwTimeGlobal < this->time_state_started + m_encircle_time)
if (!enemy_at_home || Device.dwTimeGlobal < time_state_started + m_encircle_time)
{
this->object->path().set_use_dest_orient(true);
this->object->path().set_dest_direction(m_encircle_dir);
this->object->path().set_try_min_time(false);
object->path().set_use_dest_orient(true);
object->path().set_dest_direction(m_encircle_dir);
object->path().set_try_min_time(false);
}
else
{
this->object->path().set_use_dest_orient(false);
object->path().set_use_dest_orient(false);
}
}


void CStateGroupAttackRun::finalize()
{
inherited::finalize();
this->object->path().extrapolate_path(false);
object->path().extrapolate_path(false);
}


void CStateGroupAttackRun::critical_finalize()
{
inherited::critical_finalize();
this->object->path().extrapolate_path(false);
object->path().extrapolate_path(false);
}



bool CStateGroupAttackRun::check_completion()
{
float m_fDistMin = this->object->MeleeChecker.get_min_distance();
float dist = this->object->MeleeChecker.distance_to_enemy(this->object->EnemyMan.get_enemy());
float m_fDistMin = object->MeleeChecker.get_min_distance();
float dist = object->MeleeChecker.distance_to_enemy(object->EnemyMan.get_enemy());

if (dist < m_fDistMin)
{
Expand All @@ -213,11 +218,10 @@ bool CStateGroupAttackRun::check_completion()
return false;
}


bool CStateGroupAttackRun::check_start_conditions()
{
float m_fDistMax = this->object->MeleeChecker.get_max_distance();
float dist = this->object->MeleeChecker.distance_to_enemy(this->object->EnemyMan.get_enemy());
float m_fDistMax = object->MeleeChecker.get_max_distance();
float dist = object->MeleeChecker.distance_to_enemy(object->EnemyMan.get_enemy());

if (dist > m_fDistMax)
{
Expand Down
18 changes: 9 additions & 9 deletions src/xrGame/ai/monsters/group_states/group_state_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CStateCustomGroup::CStateCustomGroup(CBaseMonster* object) : inherited(object)
{
m_pDog = smart_cast<CustomDog*>(object);

this->add_state(eStateCustom, new CStateMonsterCustomAction(object));
add_state(eStateCustom, new CStateMonsterCustomAction(object));
}

CStateCustomGroup::~CStateCustomGroup()
Expand All @@ -20,22 +20,22 @@ CStateCustomGroup::~CStateCustomGroup()
void CStateCustomGroup::execute()
{
// check alife control
this->select_state(eStateCustom);
this->m_pDog->start_animation();
select_state(eStateCustom);
m_pDog->start_animation();

this->get_state_current()->execute();
this->prev_substate = this->current_substate;
get_state_current()->execute();
prev_substate = current_substate;
}

void CStateCustomGroup::setup_substates()
{
state_ptr state = this->get_state_current();
if (this->current_substate == eStateCustom) {
state_ptr state = get_state_current();
if (current_substate == eStateCustom) {
SStateDataAction data;

data.action = ACT_STAND_IDLE;
data.time_out = 0; // do not use time out
switch (this->m_pDog->get_number_animation())
switch (m_pDog->get_number_animation())
{
case u32(5):
data.sound_type = MonsterSound::eMonsterSoundSteal;
Expand All @@ -47,7 +47,7 @@ void CStateCustomGroup::setup_substates()
data.sound_type = MonsterSound::eMonsterSoundIdle;
break;
}
data.sound_delay = this->object->db().m_dwEatSndDelay;
data.sound_delay = object->db().m_dwEatSndDelay;
state->fill_data_with(&data, sizeof(SStateDataAction));

return;
Expand Down
Loading

0 comments on commit c4965f7

Please sign in to comment.