Skip to content

Commit

Permalink
Make combat_engagement, aim_rule, cbm_recharge_rule and cbm_reserve_r…
Browse files Browse the repository at this point in the history
…ule a class enums
  • Loading branch information
ZhilkinSerg committed Apr 13, 2020
1 parent 2bcc395 commit 7079e3b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3158,8 +3158,8 @@ void npc::set_attitude( npc_attitude new_attitude )

npc_follower_rules::npc_follower_rules()
{
engagement = ENGAGE_CLOSE;
aim = AIM_WHEN_CONVENIENT;
engagement = combat_engagement::CLOSE;
aim = aim_rule::WHEN_CONVENIENT;
overrides = ally_rule::DEFAULT;
override_enable = ally_rule::DEFAULT;

Expand Down
78 changes: 39 additions & 39 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,75 +274,75 @@ struct npc_opinion {
void deserialize( JsonIn &jsin );
};

enum combat_engagement {
ENGAGE_NONE = 0,
ENGAGE_CLOSE,
ENGAGE_WEAK,
ENGAGE_HIT,
ENGAGE_ALL,
ENGAGE_FREE_FIRE,
ENGAGE_NO_MOVE
enum class combat_engagement : int {
NONE = 0,
CLOSE,
WEAK,
HIT,
ALL,
FREE_FIRE,
NO_MOVE
};
const std::unordered_map<std::string, combat_engagement> combat_engagement_strs = { {
{ "ENGAGE_NONE", ENGAGE_NONE },
{ "ENGAGE_CLOSE", ENGAGE_CLOSE },
{ "ENGAGE_WEAK", ENGAGE_WEAK },
{ "ENGAGE_HIT", ENGAGE_HIT },
{ "ENGAGE_ALL", ENGAGE_ALL },
{ "ENGAGE_FREE_FIRE", ENGAGE_FREE_FIRE },
{ "ENGAGE_NO_MOVE", ENGAGE_NO_MOVE }
{ "ENGAGE_NONE", combat_engagement::NONE },
{ "ENGAGE_CLOSE", combat_engagement::CLOSE },
{ "ENGAGE_WEAK", combat_engagement::WEAK },
{ "ENGAGE_HIT", combat_engagement::HIT },
{ "ENGAGE_ALL", combat_engagement::ALL },
{ "ENGAGE_FREE_FIRE", combat_engagement::FREE_FIRE },
{ "ENGAGE_NO_MOVE", combat_engagement::NO_MOVE }
}
};

enum aim_rule {
enum class aim_rule : int {
// Aim some
AIM_WHEN_CONVENIENT = 0,
WHEN_CONVENIENT = 0,
// No concern for ammo efficiency
AIM_SPRAY,
SPRAY,
// Aim when possible, then shoot
AIM_PRECISE,
PRECISE,
// If you can't aim, don't shoot
AIM_STRICTLY_PRECISE
STRICTLY_PRECISE
};
const std::unordered_map<std::string, aim_rule> aim_rule_strs = { {
{ "AIM_WHEN_CONVENIENT", AIM_WHEN_CONVENIENT },
{ "AIM_SPRAY", AIM_SPRAY },
{ "AIM_PRECISE", AIM_PRECISE },
{ "AIM_STRICTLY_PRECISE", AIM_STRICTLY_PRECISE }
{ "AIM_WHEN_CONVENIENT", aim_rule::WHEN_CONVENIENT },
{ "AIM_SPRAY", aim_rule::SPRAY },
{ "AIM_PRECISE", aim_rule::PRECISE },
{ "AIM_STRICTLY_PRECISE", aim_rule::STRICTLY_PRECISE }
}
};

// How much CBM power should remain before attempting to recharge, values are percents of power
enum cbm_recharge_rule {
enum class cbm_recharge_rule : int {
CBM_RECHARGE_ALL = 90,
CBM_RECHARGE_MOST = 75,
CBM_RECHARGE_SOME = 50,
CBM_RECHARGE_LITTLE = 25,
CBM_RECHARGE_NONE = 10
};
const std::unordered_map<std::string, cbm_recharge_rule> cbm_recharge_strs = { {
{ "CBM_RECHARGE_ALL", CBM_RECHARGE_ALL },
{ "CBM_RECHARGE_MOST", CBM_RECHARGE_MOST },
{ "CBM_RECHARGE_SOME", CBM_RECHARGE_SOME },
{ "CBM_RECHARGE_LITTLE", CBM_RECHARGE_LITTLE },
{ "CBM_RECHARGE_NONE", CBM_RECHARGE_NONE }
{ "CBM_RECHARGE_ALL", cbm_recharge_rule::CBM_RECHARGE_ALL },
{ "CBM_RECHARGE_MOST", cbm_recharge_rule::CBM_RECHARGE_MOST },
{ "CBM_RECHARGE_SOME", cbm_recharge_rule::CBM_RECHARGE_SOME },
{ "CBM_RECHARGE_LITTLE", cbm_recharge_rule::CBM_RECHARGE_LITTLE },
{ "CBM_RECHARGE_NONE", cbm_recharge_rule::CBM_RECHARGE_NONE }
}
};

// How much CBM power to reserve for defense, values are percents of total power
enum cbm_reserve_rule {
enum class cbm_reserve_rule : int {
CBM_RESERVE_ALL = 100,
CBM_RESERVE_MOST = 75,
CBM_RESERVE_SOME = 50,
CBM_RESERVE_LITTLE = 25,
CBM_RESERVE_NONE = 0
};
const std::unordered_map<std::string, cbm_reserve_rule> cbm_reserve_strs = { {
{ "CBM_RESERVE_ALL", CBM_RESERVE_ALL },
{ "CBM_RESERVE_MOST", CBM_RESERVE_MOST },
{ "CBM_RESERVE_SOME", CBM_RESERVE_SOME },
{ "CBM_RESERVE_LITTLE", CBM_RESERVE_LITTLE },
{ "CBM_RESERVE_NONE", CBM_RESERVE_NONE }
{ "CBM_RESERVE_ALL", cbm_reserve_rule::CBM_RESERVE_ALL },
{ "CBM_RESERVE_MOST", cbm_reserve_rule::CBM_RESERVE_MOST },
{ "CBM_RESERVE_SOME", cbm_reserve_rule::CBM_RESERVE_SOME },
{ "CBM_RESERVE_LITTLE", cbm_reserve_rule::CBM_RESERVE_LITTLE },
{ "CBM_RESERVE_NONE", cbm_reserve_rule::CBM_RESERVE_NONE }
}
};

Expand Down Expand Up @@ -490,9 +490,9 @@ const std::unordered_map<std::string, ally_rule_data> ally_rule_strs = { {

struct npc_follower_rules {
combat_engagement engagement;
aim_rule aim = AIM_WHEN_CONVENIENT;
cbm_recharge_rule cbm_recharge = CBM_RECHARGE_SOME;
cbm_reserve_rule cbm_reserve = CBM_RESERVE_SOME;
aim_rule aim = aim_rule::WHEN_CONVENIENT;
cbm_recharge_rule cbm_recharge = cbm_recharge_rule::CBM_RECHARGE_SOME;
cbm_reserve_rule cbm_reserve = cbm_reserve_rule::CBM_RESERVE_SOME;
ally_rule flags;
ally_rule override_enable;
ally_rule overrides;
Expand Down
30 changes: 15 additions & 15 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,21 @@ void npc::assess_danger()
return false;
}
switch( rules.engagement ) {
case ENGAGE_NONE:
case combat_engagement::NONE:
return false;
case ENGAGE_CLOSE:
case combat_engagement::CLOSE:
// Either close to player or close enough that we can reach it and close to us
return ( dist <= max_range && scaled_dist <= def_radius * 0.5 ) ||
too_close( c.pos(), g->u.pos(), def_radius );
case ENGAGE_WEAK:
case combat_engagement::WEAK:
return c.get_hp() <= average_damage_dealt();
case ENGAGE_HIT:
case combat_engagement::HIT:
return c.has_effect( effect_hit_by_player );
case ENGAGE_NO_MOVE:
case combat_engagement::NO_MOVE:
return dist <= max_range;
case ENGAGE_FREE_FIRE:
case combat_engagement::FREE_FIRE:
return dist <= max_range;
case ENGAGE_ALL:
case combat_engagement::ALL:
return true;
}

Expand All @@ -406,7 +406,7 @@ void npc::assess_danger()
}
}
}
if( is_player_ally() && rules.engagement == ENGAGE_FREE_FIRE ) {
if( is_player_ally() && rules.engagement == combat_engagement::FREE_FIRE ) {
def_radius = std::max( 6, max_range );
}
// find our Character friends and enemies
Expand Down Expand Up @@ -1288,10 +1288,10 @@ npc_action npc::method_of_attack()
const bool same_z = tar.z == pos().z;

// TODO: Change the in_vehicle check to actual "are we driving" check
const bool dont_move = in_vehicle || rules.engagement == ENGAGE_NO_MOVE ||
rules.engagement == ENGAGE_FREE_FIRE;
const bool dont_move = in_vehicle || rules.engagement == combat_engagement::NO_MOVE ||
rules.engagement == combat_engagement::FREE_FIRE;
// NPCs engage in free fire can move to avoid allies, but not if they're in a vehicle
const bool dont_move_ff = in_vehicle || rules.engagement == ENGAGE_NO_MOVE;
const bool dont_move_ff = in_vehicle || rules.engagement == combat_engagement::NO_MOVE;

// if there's enough of a threat to be here, power up the combat CBMs
activate_combat_cbms();
Expand Down Expand Up @@ -1972,13 +1972,13 @@ double npc::confidence_mult() const
}

switch( rules.aim ) {
case AIM_WHEN_CONVENIENT:
case aim_rule::WHEN_CONVENIENT:
return emergency() ? 1.5f : 1.0f;
case AIM_SPRAY:
case aim_rule::SPRAY:
return 2.0f;
case AIM_PRECISE:
case aim_rule::PRECISE:
return emergency() ? 1.0f : 0.75f;
case AIM_STRICTLY_PRECISE:
case aim_rule::STRICTLY_PRECISE:
return 0.5f;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/npc_talk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ TEST_CASE( "npc_talk_rules", "[npc_talk]" )
d.add_topic( "TALK_TEST_NPC_RULES" );
gen_response_lines( d, 1 );
CHECK( d.responses[0].text == "This is a basic test response." );
talker_npc.rules.engagement = ENGAGE_ALL;
talker_npc.rules.aim = AIM_SPRAY;
talker_npc.rules.engagement = combat_engagement::ALL;
talker_npc.rules.aim = aim_rule::SPRAY;
talker_npc.rules.set_flag( ally_rule::use_silent );
gen_response_lines( d, 4 );
CHECK( d.responses[0].text == "This is a basic test response." );
Expand Down

0 comments on commit 7079e3b

Please sign in to comment.