From 7079e3b7aefeefe324524b15fa8ffb5408aa3ef8 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Mon, 13 Apr 2020 00:49:00 +0300 Subject: [PATCH] Make combat_engagement, aim_rule, cbm_recharge_rule and cbm_reserve_rule a class enums --- src/npc.cpp | 4 +-- src/npc.h | 78 ++++++++++++++++++++--------------------- src/npcmove.cpp | 30 ++++++++-------- tests/npc_talk_test.cpp | 4 +-- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/npc.cpp b/src/npc.cpp index 03a35d11a5eab..8eb8935cd5070 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -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; diff --git a/src/npc.h b/src/npc.h index c398a88579fed..17be0d73cc621 100644 --- a/src/npc.h +++ b/src/npc.h @@ -274,46 +274,46 @@ 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 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 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, @@ -321,16 +321,16 @@ enum cbm_recharge_rule { CBM_RECHARGE_NONE = 10 }; const std::unordered_map 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, @@ -338,11 +338,11 @@ enum cbm_reserve_rule { CBM_RESERVE_NONE = 0 }; const std::unordered_map 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 } } }; @@ -490,9 +490,9 @@ const std::unordered_map 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; diff --git a/src/npcmove.cpp b/src/npcmove.cpp index 69f8b4fb5a390..27ebbc3d8b8aa 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -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; } @@ -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 @@ -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(); @@ -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; } diff --git a/tests/npc_talk_test.cpp b/tests/npc_talk_test.cpp index 90802ff7339df..17c991011837f 100644 --- a/tests/npc_talk_test.cpp +++ b/tests/npc_talk_test.cpp @@ -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." );