Skip to content

Commit

Permalink
Improvements for stalker actions depending on weapon types in SOC/CS (#…
Browse files Browse the repository at this point in the history
…382, #392)

Instead of using hardcoded magic numbers everywhere, moved them into one
place
  • Loading branch information
Xottab-DUTY committed Mar 31, 2022
1 parent 5bd41bb commit f77babc
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 59 deletions.
26 changes: 9 additions & 17 deletions src/xrGame/ai/stalker/ai_stalker_cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "pch_script.h"
#include "ai_stalker.h"
#include "ai_stalker_space.h"
#include "cover_point.h"
#include "cover_evaluators.h"
#include "ai_space.h"
Expand Down Expand Up @@ -77,34 +78,25 @@ void CAI_Stalker::compute_enemy_distances(float& minimum_enemy_distance, float&
if (!best_weapon())
return;

int weapon_type = best_weapon()->object().ef_weapon_type();
switch (weapon_type)
{
// pistols
case 5:
const int weapon_type = best_weapon()->object().ef_weapon_type();
switch (StalkerSpace::convert_weapon_type(weapon_type))
{
case StalkerSpace::WeaponTypes::Pistol:
maximum_enemy_distance = 10.f;
break;
}
// shotguns
case 9:
{

case StalkerSpace::WeaponTypes::Shotgun:
maximum_enemy_distance = 5.f;
break;
}
// sniper rifles
case 11:
case 12:
{

case StalkerSpace::WeaponTypes::SniperRifle:
minimum_enemy_distance = 20.f;
break;
}

default:
{
maximum_enemy_distance = 20.f;
break;
}
}

minimum_enemy_distance = std::min(minimum_enemy_distance, maximum_enemy_distance);
maximum_enemy_distance = std::max(minimum_enemy_distance, maximum_enemy_distance);
Expand Down
36 changes: 19 additions & 17 deletions src/xrGame/ai/stalker/ai_stalker_fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,14 @@ bool CAI_Stalker::fire_make_sense()
return (false);

// if we do not have automatic weapon
switch (best_weapon()->object().ef_weapon_type())
const int weapon_type = best_weapon()->object().ef_weapon_type();
switch (StalkerSpace::convert_weapon_type(weapon_type))
{
case 6:
case 7:
case 8:
case 10: break;
default: return (false);
case WeaponTypes::SubmashineGun:
case WeaponTypes::MashineGun:
break;
default:
return (false);
}

return (true);
Expand Down Expand Up @@ -1223,20 +1224,21 @@ bool CAI_Stalker::too_far_to_kill_enemy(const Fvector& position)
VERIFY(memory().enemy().selected());
VERIFY(best_weapon());
int weapon_type = best_weapon()->object().ef_weapon_type();
float distance = position.distance_to(Position());
switch (weapon_type)
const float distance = position.distance_to(Position());
const int weapon_type = best_weapon()->object().ef_weapon_type();
switch (convert_weapon_type(weapon_type))
{
// pistols
case 5:
case WeaponTypes::Pistol:
return (distance > 10.f);
// shotguns
case 9:
case WeaponTypes::Shotgun:
return (distance > 5.f);
case WeaponTypes::SniperRifle:
return (distance > 70.f);
default:
return (distance > 5.f);
// sniper rifles
case 11:
case 12: return (distance > 70.f);
default: return (distance > 5.f);
}
#endif
}
99 changes: 99 additions & 0 deletions src/xrGame/ai/stalker/ai_stalker_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,103 @@ enum EBodyAction : u32
eBodyActionHello,
eBodyActionDummy = u32(-1),
};

enum class WeaponTypes : u32
{
Unknown,

Item,
Melee,

// XXX: Better names, anyone...
Mutant1,
Mutant2,
Mutant3,

Pistol,
SubmashineGun,
Shotgun,
MashineGun,
SniperRifle,

GrenadeLauncher,
Grenade,

AnomalyMine,
AnomalyField,

PsyStrike, // Controller
ThrowingItems, // Poltergeist, burer...

Gravi,
Mincer,
BurningFuzz,
RustyHair, // NoGravity anomaly also has this type, though..
};

constexpr WeaponTypes convert_weapon_type_cop(int type)
{
switch (type)
{
case 0: return WeaponTypes::Item;
case 1: return WeaponTypes::Melee;
case 2: return WeaponTypes::Mutant1;
case 3: return WeaponTypes::Mutant2;
case 4: return WeaponTypes::Grenade;
case 5: return WeaponTypes::Pistol;
case 6:
case 7:
case 8: return WeaponTypes::SubmashineGun;
case 9: return WeaponTypes::Shotgun;
case 10: return WeaponTypes::MashineGun;
case 11: return WeaponTypes::SniperRifle;
case 12: return WeaponTypes::GrenadeLauncher;
case 13: return WeaponTypes::AnomalyMine;
case 14: return WeaponTypes::Mincer;
case 15: return WeaponTypes::AnomalyField;
//case 16: is not used in release gamedata
case 17: return WeaponTypes::Gravi;
case 18: return WeaponTypes::BurningFuzz;
case 19: return WeaponTypes::RustyHair;
}

return WeaponTypes::Unknown;
}

constexpr WeaponTypes convert_weapon_type_soc_cs(int type)
{
switch (type)
{
case 0: return WeaponTypes::Item;
case 1: return WeaponTypes::Melee;
case 2: return WeaponTypes::Mutant1;
case 3: return WeaponTypes::Mutant2;
case 4: return WeaponTypes::Mutant3;
case 5: return WeaponTypes::Pistol;
case 6: return WeaponTypes::SubmashineGun;
case 7: return WeaponTypes::Shotgun;
case 8: return WeaponTypes::SniperRifle;
case 9: return WeaponTypes::GrenadeLauncher;
case 10: return WeaponTypes::Grenade;
case 11: return WeaponTypes::PsyStrike;
case 12: return WeaponTypes::ThrowingItems;
case 13: return WeaponTypes::AnomalyMine;
case 14: return WeaponTypes::Mincer;
case 15: return WeaponTypes::AnomalyField;
//case 16: is not used in release gamedata
case 17: return WeaponTypes::Gravi;
case 18: return WeaponTypes::BurningFuzz;
case 19: return WeaponTypes::RustyHair;
}

return WeaponTypes::Unknown;
}

inline WeaponTypes convert_weapon_type(int type)
{
if (ShadowOfChernobylMode || ClearSkyMode)
return convert_weapon_type_soc_cs(type);

return convert_weapon_type_cop(type);
}
};
32 changes: 7 additions & 25 deletions src/xrGame/stalker_combat_action_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,13 @@ void CStalkerActionCombatBase::aim_ready_force_full()
void CStalkerActionCombatBase::select_queue_params(const float& distance, u32& min_queue_size, u32& max_queue_size,
u32& min_queue_interval, u32& max_queue_interval) const
{
int weapon_type = 6;
WeaponTypes weapon_type = WeaponTypes::Unknown;
if (object().best_weapon())
weapon_type = object().best_weapon()->object().ef_weapon_type();

if (ClearSkyMode || ShadowOfChernobylMode)
{
// remap
switch (weapon_type)
{
case 6: weapon_type = 666; break; // random number so that we can get to the default case
case 7: weapon_type = 9; break; // shotguns
case 8: weapon_type = 11; break; // sniper rifles
}
}
weapon_type = convert_weapon_type(object().best_weapon()->object().ef_weapon_type());

switch (weapon_type)
{
// pistols
case 5:
case WeaponTypes::Pistol:
{
if (distance > object().pstl_queue_fire_dist_far())
{
Expand All @@ -136,8 +124,7 @@ void CStalkerActionCombatBase::select_queue_params(const float& distance, u32& m

break;
}
// shotguns
case 9:
case WeaponTypes::Shotgun:
{
if (distance > object().shtg_queue_fire_dist_far())
{
Expand All @@ -163,9 +150,7 @@ void CStalkerActionCombatBase::select_queue_params(const float& distance, u32& m

break;
}
// sniper rifles
case 11:
case 12:
case WeaponTypes::SniperRifle:
{
if (distance > object().snp_queue_fire_dist_far())
{
Expand All @@ -191,11 +176,8 @@ void CStalkerActionCombatBase::select_queue_params(const float& distance, u32& m

break;
}
// machine guns
case 6:
case 7:
case 8:
case 10:
case WeaponTypes::SubmashineGun:
case WeaponTypes::MashineGun:
{
if (distance > object().mchg_queue_fire_dist_far())
{
Expand Down

0 comments on commit f77babc

Please sign in to comment.