From e309183fac88e7c5365ed7b067f10547380153e8 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 10:56:46 +0300 Subject: [PATCH 1/8] Removed unused using --- src/pldata.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pldata.h b/src/pldata.h index 568578cfb3276..057b14cd411d9 100644 --- a/src/pldata.h +++ b/src/pldata.h @@ -10,8 +10,6 @@ class JsonIn; class JsonOut; template struct enum_traits; -using dis_type = std::string; - enum character_type : int { PLTYPE_CUSTOM, PLTYPE_RANDOM, From 1d484ddd39855a3ecc9c56d339bade1aee05c61b Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 10:58:01 +0300 Subject: [PATCH 2/8] Make character_type a class enum --- src/gamemode_defense.cpp | 2 +- src/main_menu.cpp | 12 ++++++------ src/newcharacter.cpp | 17 +++++++++-------- src/pldata.h | 12 ++++++------ tests/test_main.cpp | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/gamemode_defense.cpp b/src/gamemode_defense.cpp index 99dee345348e3..90c8915ca4e1f 100644 --- a/src/gamemode_defense.cpp +++ b/src/gamemode_defense.cpp @@ -94,7 +94,7 @@ bool defense_game::init() { calendar::turn = calendar::turn_zero + 12_hours; // Start at noon g->weather.temperature = 65; - if( !g->u.create( PLTYPE_CUSTOM ) ) { + if( !g->u.create( character_type::CUSTOM ) ) { return false; } g->u.str_cur = g->u.str_max; diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 7541246f7381a..2db5375ec835a 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -820,19 +820,19 @@ bool main_menu::new_character_tab() debugmsg( "Error: %s", err.what() ); continue; } - character_type play_type = PLTYPE_CUSTOM; + character_type play_type = character_type::CUSTOM; switch( sel2 ) { case 0: - play_type = PLTYPE_CUSTOM; + play_type = character_type::CUSTOM; break; case 2: - play_type = PLTYPE_RANDOM; + play_type = character_type::RANDOM; break; case 3: - play_type = PLTYPE_NOW; + play_type = character_type::NOW; break; case 4: - play_type = PLTYPE_FULL_RANDOM; + play_type = character_type::FULL_RANDOM; break; } if( !g->u.create( play_type ) ) { @@ -906,7 +906,7 @@ bool main_menu::new_character_tab() debugmsg( "Error: %s", err.what() ); continue; } - if( !g->u.create( PLTYPE_TEMPLATE, templates[sel3] ) ) { + if( !g->u.create( character_type::TEMPLATE, templates[sel3] ) ) { load_char_templates(); MAPBUFFER.reset(); overmap_buffer.clear(); diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index 939ec5454a575..a64c383d36bc1 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -130,7 +130,7 @@ void Character::pick_name( bool bUseDefault ) static matype_id choose_ma_style( const character_type type, const std::vector &styles, const avatar &u ) { - if( type == PLTYPE_NOW || type == PLTYPE_FULL_RANDOM ) { + if( type == character_type::NOW || type == character_type::FULL_RANDOM ) { return random_entry( styles ); } if( styles.size() == 1 ) { @@ -372,28 +372,29 @@ bool avatar::create( character_type type, const std::string &tempname ) prof = profession::generic(); g->scen = scenario::generic(); - const bool interactive = type != PLTYPE_NOW && type != PLTYPE_FULL_RANDOM; + const bool interactive = type != character_type::NOW && + type != character_type::FULL_RANDOM; int tab = 0; points_left points = points_left(); switch( type ) { - case PLTYPE_CUSTOM: + case character_type::CUSTOM: break; - case PLTYPE_RANDOM: + case character_type::RANDOM: //random scenario, default name if exist randomize( true, points ); tab = NEWCHAR_TAB_MAX; break; - case PLTYPE_NOW: + case character_type::NOW: //default world, fixed scenario, random name randomize( false, points, true ); break; - case PLTYPE_FULL_RANDOM: + case character_type::FULL_RANDOM: //default world, random scenario, random name randomize( true, points, true ); break; - case PLTYPE_TEMPLATE: + case character_type::TEMPLATE: if( !load_template( tempname, points ) ) { return false; } @@ -414,7 +415,7 @@ bool avatar::create( character_type type, const std::string &tempname ) "Continue anyways?" ), name ); }; - const bool allow_reroll = type == PLTYPE_RANDOM; + const bool allow_reroll = type == character_type::RANDOM; tab_direction result = tab_direction::QUIT; do { if( !interactive ) { diff --git a/src/pldata.h b/src/pldata.h index 057b14cd411d9..7f47c16cece9d 100644 --- a/src/pldata.h +++ b/src/pldata.h @@ -10,12 +10,12 @@ class JsonIn; class JsonOut; template struct enum_traits; -enum character_type : int { - PLTYPE_CUSTOM, - PLTYPE_RANDOM, - PLTYPE_TEMPLATE, - PLTYPE_NOW, - PLTYPE_FULL_RANDOM, +enum class character_type : int { + CUSTOM, + RANDOM, + TEMPLATE, + NOW, + FULL_RANDOM, }; enum add_type : int { diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 846ffd71599d4..f73a913e3db21 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -142,7 +142,7 @@ static void init_global_game_state( const std::vector &mods, g->load_world_modfiles( ui ); g->u = avatar(); - g->u.create( PLTYPE_NOW ); + g->u.create( character_type::NOW ); g->m = map( get_option( "ZLEVELS" ) ); From 95d889bcbb7b2c77fe86f2ff01190a2ec02b186c Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 10:58:36 +0300 Subject: [PATCH 3/8] Make available_status and component_type a class enums --- src/requirements.cpp | 26 +++++++++++++------------- src/requirements.h | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/requirements.cpp b/src/requirements.cpp index 11f70194d288c..12fc0dd668bbb 100644 --- a/src/requirements.cpp +++ b/src/requirements.cpp @@ -337,7 +337,7 @@ template bool requirement_data::any_marked_available( const std::vector &comps ) { for( const auto &comp : comps ) { - if( comp.available == a_true ) { + if( comp.available == available_status::a_true ) { return true; } } @@ -557,7 +557,7 @@ std::vector requirement_data::get_folded_list( int width, nc_color color = component.get_color( has_one, crafting_inv, filter, batch ); const std::string color_tag = get_tag_from_color( color ); int qty = 0; - if( component.get_component_type() == COMPONENT_ITEM ) { + if( component.get_component_type() == component_type::ITEM ) { const itype_id item_id = static_cast( component.type ); if( item::count_by_charges( item_id ) ) { qty = crafting_inv.charges_of( item_id, INT_MAX, filter ); @@ -658,11 +658,11 @@ bool requirement_data::has_comps( const inventory &crafting_inv, [ &UPS_charges_used ]( int charges ) { UPS_charges_used = std::min( UPS_charges_used, charges ); } ) ) { - tool.available = a_true; + tool.available = available_status::a_true; } else { - tool.available = a_false; + tool.available = available_status::a_false; } - has_tool_in_set = has_tool_in_set || tool.available == a_true; + has_tool_in_set = has_tool_in_set || tool.available == available_status::a_true; } if( !has_tool_in_set ) { retval = false; @@ -692,7 +692,7 @@ bool quality_requirement::has( nc_color quality_requirement::get_color( bool has_one, const inventory &, const std::function &, int ) const { - if( available == a_true ) { + if( available == available_status::a_true ) { return c_green; } return has_one ? c_dark_gray : c_red; @@ -722,7 +722,7 @@ bool tool_comp::has( nc_color tool_comp::get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int batch ) const { - if( available == a_insufficent ) { + if( available == available_status::a_insufficent ) { return c_brown; } else if( has( crafting_inv, filter, batch ) ) { return c_green; @@ -748,7 +748,7 @@ bool item_comp::has( nc_color item_comp::get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int batch ) const { - if( available == a_insufficent ) { + if( available == available_status::a_insufficent ) { return c_brown; } else if( has( crafting_inv, filter, batch ) ) { return c_green; @@ -791,12 +791,12 @@ bool requirement_data::check_enough_materials( const inventory &crafting_inv, bool requirement_data::check_enough_materials( const item_comp &comp, const inventory &crafting_inv, const std::function &filter, int batch ) const { - if( comp.available != a_true ) { + if( comp.available != available_status::a_true ) { return false; } const int cnt = std::abs( comp.count ) * batch; const tool_comp *tq = find_by_type( tools, comp.type ); - if( tq != nullptr && tq->available == a_true ) { + if( tq != nullptr && tq->available == available_status::a_true ) { // The very same item type is also needed as tool! // Use charges of it, or use it by count? const int tc = tq->by_charges() ? 1 : std::abs( tq->count ); @@ -817,7 +817,7 @@ bool requirement_data::check_enough_materials( const item_comp &comp, const inve const tool_comp t_tmp( comp.type, -( cnt + tc ) ); // not by charges! // batch factor is explicitly 1, because it's already included in the count. if( !i_tmp.has( crafting_inv, filter, 1 ) && !t_tmp.has( crafting_inv, filter, 1 ) ) { - comp.available = a_insufficent; + comp.available = available_status::a_insufficent; } } const itype *it = item::find_type( comp.type ); @@ -829,10 +829,10 @@ bool requirement_data::check_enough_materials( const item_comp &comp, const inve // This item can be used for the quality requirement, same as above for specific // tools applies. if( !crafting_inv.has_quality( qr->type, qr->level, qr->count + abs( comp.count ) ) ) { - comp.available = a_insufficent; + comp.available = available_status::a_insufficent; } } - return comp.available == a_true; + return comp.available == available_status::a_true; } template diff --git a/src/requirements.h b/src/requirements.h index 835fad3c7a113..81311bf526d2f 100644 --- a/src/requirements.h +++ b/src/requirements.h @@ -28,16 +28,16 @@ class player; // Denotes the id of an item type using itype_id = std::string; -enum available_status { +enum class available_status : int { a_true = +1, // yes, it's available a_false = -1, // no, it's not available a_insufficent = 0, // nearly, but not enough for tool+component }; -enum component_type : int { - COMPONENT_ITEM, - COMPONENT_TOOL, - COMPONENT_QUALITY, +enum class component_type : int { + ITEM, + TOOL, + QUALITY, }; struct quality { @@ -58,7 +58,7 @@ struct component { int count = 0; // -1 means the player doesn't have the item, 1 means they do, // 0 means they have item but not enough for both tool and component - mutable available_status available = a_false; + mutable available_status available = available_status::a_false; bool recoverable = true; // If true, it's not actually a component but a requirement (list of components) bool requirement = false; @@ -99,7 +99,7 @@ struct tool_comp : public component { const std::function &filter, int batch = 1 ) const; bool by_charges() const; component_type get_component_type() const { - return COMPONENT_TOOL; + return component_type::TOOL; } }; @@ -116,7 +116,7 @@ struct item_comp : public component { nc_color get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int batch = 1 ) const; component_type get_component_type() const { - return COMPONENT_ITEM; + return component_type::ITEM; } }; @@ -124,7 +124,7 @@ struct quality_requirement { quality_id type = quality_id( "UNKNOWN" ); int count = 1; int level = 1; - mutable available_status available = a_false; + mutable available_status available = available_status::a_false; bool requirement = false; // Currently unused, but here for consistency and templates // needs explicit specification due to the mutable member. update this when you add new @@ -156,7 +156,7 @@ struct quality_requirement { nc_color get_color( bool has_one, const inventory &crafting_inv, const std::function &filter, int = 0 ) const; component_type get_component_type() const { - return COMPONENT_QUALITY; + return component_type::QUALITY; } }; From 339ac5c1230a70e1a703b7096c84759a86b5c291 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 10:59:00 +0300 Subject: [PATCH 4/8] Make add_type a class enum --- src/addiction.cpp | 203 ++++++++++++++++++++-------------------- src/addiction.h | 3 +- src/avatar.h | 2 - src/cata_variant.h | 2 +- src/character.cpp | 2 +- src/consumption.cpp | 4 +- src/iexamine.cpp | 2 +- src/itype.h | 2 +- src/iuse.cpp | 14 +-- src/player.cpp | 4 +- src/pldata.h | 16 ++-- src/profession.h | 2 - src/scenario.h | 2 +- src/suffer.cpp | 6 +- tests/memorial_test.cpp | 4 +- 15 files changed, 133 insertions(+), 135 deletions(-) diff --git a/src/addiction.cpp b/src/addiction.cpp index c85514d165082..edaafb54e68ee 100644 --- a/src/addiction.cpp +++ b/src/addiction.cpp @@ -10,7 +10,6 @@ #include "debug.h" #include "enums.h" #include "morale_types.h" -#include "pldata.h" #include "rng.h" #include "translations.h" @@ -27,20 +26,20 @@ std::string enum_to_string( add_type data ) { switch( data ) { // *INDENT-OFF* - case add_type::ADD_NULL: return "NULL"; - case add_type::ADD_CAFFEINE: return "CAFFEINE"; - case add_type::ADD_ALCOHOL: return "ALCOHOL"; - case add_type::ADD_SLEEP: return "SLEEP"; - case add_type::ADD_PKILLER: return "PKILLER"; - case add_type::ADD_SPEED: return "SPEED"; - case add_type::ADD_CIG: return "CIG"; - case add_type::ADD_COKE: return "COKE"; - case add_type::ADD_CRACK: return "CRACK"; - case add_type::ADD_MUTAGEN: return "MUTAGEN"; - case add_type::ADD_DIAZEPAM: return "DIAZEPAM"; - case add_type::ADD_MARLOSS_R: return "MARLOSS_R"; - case add_type::ADD_MARLOSS_B: return "MARLOSS_B"; - case add_type::ADD_MARLOSS_Y: return "MARLOSS_Y"; + case add_type::NONE: return "NONE"; + case add_type::CAFFEINE: return "CAFFEINE"; + case add_type::ALCOHOL: return "ALCOHOL"; + case add_type::SLEEP: return "SLEEP"; + case add_type::PKILLER: return "PKILLER"; + case add_type::SPEED: return "SPEED"; + case add_type::CIG: return "CIG"; + case add_type::COKE: return "COKE"; + case add_type::CRACK: return "CRACK"; + case add_type::MUTAGEN: return "MUTAGEN"; + case add_type::DIAZEPAM: return "DIAZEPAM"; + case add_type::MARLOSS_R: return "MARLOSS_R"; + case add_type::MARLOSS_B: return "MARLOSS_B"; + case add_type::MARLOSS_Y: return "MARLOSS_Y"; // *INDENT-ON* case add_type::NUM_ADD_TYPES: break; @@ -59,7 +58,7 @@ void addict_effect( Character &u, addiction &add ) const int current_stim = u.get_stim(); switch( add.type ) { - case ADD_CIG: + case add_type::CIG: if( !one_in( 2000 - 20 * in ) ) { break; } @@ -76,7 +75,7 @@ void addict_effect( Character &u, addiction &add ) } break; - case ADD_CAFFEINE: + case add_type::CAFFEINE: if( !one_in( 2000 - 20 * in ) ) { break; } @@ -92,9 +91,10 @@ void addict_effect( Character &u, addiction &add ) } break; - case ADD_ALCOHOL: - case ADD_DIAZEPAM: { - const auto morale_type = add.type == ADD_ALCOHOL ? MORALE_CRAVING_ALCOHOL : MORALE_CRAVING_DIAZEPAM; + case add_type::ALCOHOL: + case add_type::DIAZEPAM: { + const auto morale_type = add.type == add_type::ALCOHOL ? MORALE_CRAVING_ALCOHOL : + MORALE_CRAVING_DIAZEPAM; u.mod_per_bonus( -1 ); u.mod_int_bonus( -1 ); @@ -102,13 +102,13 @@ void addict_effect( Character &u, addiction &add ) u.mod_healthy_mod( -1, -in * 10 ); } if( one_in( 20 ) && rng( 0, 20 ) < in ) { - const std::string msg_1 = add.type == ADD_ALCOHOL ? + const std::string msg_1 = add.type == add_type::ALCOHOL ? _( "You could use a drink." ) : _( "You could use some diazepam." ); u.add_msg_if_player( m_warning, msg_1 ); u.add_morale( morale_type, -35, -10 * in ); } else if( rng( 8, 300 ) < in ) { - const std::string msg_2 = add.type == ADD_ALCOHOL ? + const std::string msg_2 = add.type == add_type::ALCOHOL ? _( "Your hands start shaking… you need a drink bad!" ) : _( "You're shaking… you need some diazepam!" ); u.add_msg_if_player( m_bad, msg_2 ); @@ -120,7 +120,7 @@ void addict_effect( Character &u, addiction &add ) break; } - case ADD_SLEEP: + case add_type::SLEEP: // No effects here--just in player::can_sleep() // EXCEPT! Prolong this addiction longer than usual. if( one_in( 2 ) && add.sated < 0_turns ) { @@ -128,7 +128,7 @@ void addict_effect( Character &u, addiction &add ) } break; - case ADD_PKILLER: + case add_type::PKILLER: if( calendar::once_every( time_duration::from_turns( 100 - in * 4 ) ) && u.get_painkiller() > 20 - in ) { // Tolerance increases! @@ -161,7 +161,7 @@ void addict_effect( Character &u, addiction &add ) } break; - case ADD_SPEED: { + case add_type::SPEED: { u.mod_int_bonus( -1 ); u.mod_str_bonus( -1 ); if( current_stim > -100 && x_in_y( in, 20 ) ) { @@ -186,12 +186,13 @@ void addict_effect( Character &u, addiction &add ) } break; - case ADD_COKE: - case ADD_CRACK: { - const std::string &cur_msg = add.type == ADD_COKE ? + case add_type::COKE: + case add_type::CRACK: { + const std::string &cur_msg = add.type == add_type::COKE ? _( "You feel like you need a bump." ) : _( "You're shivering, you need some crack." ); - const auto morale_type = add.type == ADD_COKE ? MORALE_CRAVING_COCAINE : MORALE_CRAVING_CRACK; + const auto morale_type = add.type == add_type::COKE ? MORALE_CRAVING_COCAINE : + MORALE_CRAVING_CRACK; u.mod_int_bonus( -1 ); u.mod_per_bonus( -1 ); if( one_in( 900 - 30 * in ) ) { @@ -208,7 +209,7 @@ void addict_effect( Character &u, addiction &add ) break; } - case ADD_MUTAGEN: + case add_type::MUTAGEN: if( u.has_trait( trait_MUT_JUNKIE ) ) { if( one_in( 600 - 50 * in ) ) { u.add_msg_if_player( m_warning, rng( 0, @@ -227,17 +228,17 @@ void addict_effect( Character &u, addiction &add ) u.add_morale( MORALE_CRAVING_MUTAGEN, -5, -50 ); } break; - case ADD_MARLOSS_R: + case add_type::MARLOSS_R: marloss_add( u, in, _( "You daydream about luscious pink berries as big as your fist." ) ); break; - case ADD_MARLOSS_B: + case add_type::MARLOSS_B: marloss_add( u, in, _( "You daydream about nutty cyan seeds as big as your hand." ) ); break; - case ADD_MARLOSS_Y: + case add_type::MARLOSS_Y: marloss_add( u, in, _( "You daydream about succulent, pale golden gel, sweet but light." ) ); break; - case ADD_NULL: - case NUM_ADD_TYPES: + case add_type::NONE: + case add_type::NUM_ADD_TYPES: break; } } @@ -249,19 +250,19 @@ void addict_effect( Character &u, addiction &add ) std::string addiction_type_name( add_type const cur ) { static const std::map type_map = {{ - { ADD_CIG, translate_marker( "nicotine" ) }, - { ADD_CAFFEINE, translate_marker( "caffeine" ) }, - { ADD_ALCOHOL, translate_marker( "alcohol" ) }, - { ADD_SLEEP, translate_marker( "sleeping pills" ) }, - { ADD_PKILLER, translate_marker( "opiates" ) }, - { ADD_SPEED, translate_marker( "amphetamine" ) }, - { ADD_COKE, translate_marker( "cocaine" ) }, - { ADD_CRACK, translate_marker( "crack cocaine" ) }, - { ADD_MUTAGEN, translate_marker( "mutation" ) }, - { ADD_DIAZEPAM, translate_marker( "diazepam" ) }, - { ADD_MARLOSS_R, translate_marker( "Marloss berries" ) }, - { ADD_MARLOSS_B, translate_marker( "Marloss seeds" ) }, - { ADD_MARLOSS_Y, translate_marker( "Marloss gel" ) }, + { add_type::CIG, translate_marker( "nicotine" ) }, + { add_type::CAFFEINE, translate_marker( "caffeine" ) }, + { add_type::ALCOHOL, translate_marker( "alcohol" ) }, + { add_type::SLEEP, translate_marker( "sleeping pills" ) }, + { add_type::PKILLER, translate_marker( "opiates" ) }, + { add_type::SPEED, translate_marker( "amphetamine" ) }, + { add_type::COKE, translate_marker( "cocaine" ) }, + { add_type::CRACK, translate_marker( "crack cocaine" ) }, + { add_type::MUTAGEN, translate_marker( "mutation" ) }, + { add_type::DIAZEPAM, translate_marker( "diazepam" ) }, + { add_type::MARLOSS_R, translate_marker( "Marloss berries" ) }, + { add_type::MARLOSS_B, translate_marker( "Marloss seeds" ) }, + { add_type::MARLOSS_Y, translate_marker( "Marloss gel" ) }, } }; @@ -276,19 +277,19 @@ std::string addiction_type_name( add_type const cur ) std::string addiction_name( const addiction &cur ) { static const std::map type_map = {{ - { ADD_CIG, translate_marker( "Nicotine Withdrawal" ) }, - { ADD_CAFFEINE, translate_marker( "Caffeine Withdrawal" ) }, - { ADD_ALCOHOL, translate_marker( "Alcohol Withdrawal" ) }, - { ADD_SLEEP, translate_marker( "Sleeping Pill Dependence" ) }, - { ADD_PKILLER, translate_marker( "Opiate Withdrawal" ) }, - { ADD_SPEED, translate_marker( "Amphetamine Withdrawal" ) }, - { ADD_COKE, translate_marker( "Cocaine Withdrawal" ) }, - { ADD_CRACK, translate_marker( "Crack Cocaine Withdrawal" ) }, - { ADD_MUTAGEN, translate_marker( "Mutation Withdrawal" ) }, - { ADD_DIAZEPAM, translate_marker( "Diazepam Withdrawal" ) }, - { ADD_MARLOSS_R, translate_marker( "Marloss Longing" ) }, - { ADD_MARLOSS_B, translate_marker( "Marloss Desire" ) }, - { ADD_MARLOSS_Y, translate_marker( "Marloss Cravings" ) }, + { add_type::CIG, translate_marker( "Nicotine Withdrawal" ) }, + { add_type::CAFFEINE, translate_marker( "Caffeine Withdrawal" ) }, + { add_type::ALCOHOL, translate_marker( "Alcohol Withdrawal" ) }, + { add_type::SLEEP, translate_marker( "Sleeping Pill Dependence" ) }, + { add_type::PKILLER, translate_marker( "Opiate Withdrawal" ) }, + { add_type::SPEED, translate_marker( "Amphetamine Withdrawal" ) }, + { add_type::COKE, translate_marker( "Cocaine Withdrawal" ) }, + { add_type::CRACK, translate_marker( "Crack Cocaine Withdrawal" ) }, + { add_type::MUTAGEN, translate_marker( "Mutation Withdrawal" ) }, + { add_type::DIAZEPAM, translate_marker( "Diazepam Withdrawal" ) }, + { add_type::MARLOSS_R, translate_marker( "Marloss Longing" ) }, + { add_type::MARLOSS_B, translate_marker( "Marloss Desire" ) }, + { add_type::MARLOSS_Y, translate_marker( "Marloss Cravings" ) }, } }; @@ -303,18 +304,18 @@ std::string addiction_name( const addiction &cur ) morale_type addiction_craving( add_type const cur ) { static const std::map type_map = {{ - { ADD_CIG, MORALE_CRAVING_NICOTINE }, - { ADD_CAFFEINE, MORALE_CRAVING_CAFFEINE }, - { ADD_ALCOHOL, MORALE_CRAVING_ALCOHOL }, - { ADD_PKILLER, MORALE_CRAVING_OPIATE }, - { ADD_SPEED, MORALE_CRAVING_SPEED }, - { ADD_COKE, MORALE_CRAVING_COCAINE }, - { ADD_CRACK, MORALE_CRAVING_CRACK }, - { ADD_MUTAGEN, MORALE_CRAVING_MUTAGEN }, - { ADD_DIAZEPAM, MORALE_CRAVING_DIAZEPAM }, - { ADD_MARLOSS_R, MORALE_CRAVING_MARLOSS }, - { ADD_MARLOSS_B, MORALE_CRAVING_MARLOSS }, - { ADD_MARLOSS_Y, MORALE_CRAVING_MARLOSS }, + { add_type::CIG, MORALE_CRAVING_NICOTINE }, + { add_type::CAFFEINE, MORALE_CRAVING_CAFFEINE }, + { add_type::ALCOHOL, MORALE_CRAVING_ALCOHOL }, + { add_type::PKILLER, MORALE_CRAVING_OPIATE }, + { add_type::SPEED, MORALE_CRAVING_SPEED }, + { add_type::COKE, MORALE_CRAVING_COCAINE }, + { add_type::CRACK, MORALE_CRAVING_CRACK }, + { add_type::MUTAGEN, MORALE_CRAVING_MUTAGEN }, + { add_type::DIAZEPAM, MORALE_CRAVING_DIAZEPAM }, + { add_type::MARLOSS_R, MORALE_CRAVING_MARLOSS }, + { add_type::MARLOSS_B, MORALE_CRAVING_MARLOSS }, + { add_type::MARLOSS_Y, MORALE_CRAVING_MARLOSS }, } }; @@ -329,20 +330,20 @@ morale_type addiction_craving( add_type const cur ) add_type addiction_type( const std::string &name ) { static const std::map type_map = {{ - { "nicotine", ADD_CIG }, - { "caffeine", ADD_CAFFEINE }, - { "alcohol", ADD_ALCOHOL }, - { "sleeping pill", ADD_SLEEP }, - { "opiate", ADD_PKILLER }, - { "amphetamine", ADD_SPEED }, - { "cocaine", ADD_COKE }, - { "crack", ADD_CRACK }, - { "mutagen", ADD_MUTAGEN }, - { "diazepam", ADD_DIAZEPAM }, - { "marloss_r", ADD_MARLOSS_R }, - { "marloss_b", ADD_MARLOSS_B }, - { "marloss_y", ADD_MARLOSS_Y }, - { "none", ADD_NULL } + { "nicotine", add_type::CIG }, + { "caffeine", add_type::CAFFEINE }, + { "alcohol", add_type::ALCOHOL }, + { "sleeping pill", add_type::SLEEP }, + { "opiate", add_type::PKILLER }, + { "amphetamine", add_type::SPEED }, + { "cocaine", add_type::COKE }, + { "crack", add_type::CRACK }, + { "mutagen", add_type::MUTAGEN }, + { "diazepam", add_type::DIAZEPAM }, + { "marloss_r", add_type::MARLOSS_R }, + { "marloss_b", add_type::MARLOSS_B }, + { "marloss_y", add_type::MARLOSS_Y }, + { "none", add_type::NONE } } }; @@ -351,31 +352,31 @@ add_type addiction_type( const std::string &name ) return iter->second; } - return ADD_NULL; + return add_type::NONE; } std::string addiction_text( const addiction &cur ) { static const std::map addiction_msg = {{ - { ADD_CIG, translate_marker( "Intelligence - 1; Occasional cravings" ) }, - { ADD_CAFFEINE, translate_marker( "Strength - 1; Slight sluggishness; Occasional cravings" ) }, + { add_type::CIG, translate_marker( "Intelligence - 1; Occasional cravings" ) }, + { add_type::CAFFEINE, translate_marker( "Strength - 1; Slight sluggishness; Occasional cravings" ) }, { - ADD_ALCOHOL, translate_marker( "Perception - 1; Intelligence - 1; Occasional Cravings;\nRisk of delirium tremens" ) + add_type::ALCOHOL, translate_marker( "Perception - 1; Intelligence - 1; Occasional Cravings;\nRisk of delirium tremens" ) }, - { ADD_SLEEP, translate_marker( "You may find it difficult to sleep without medication." ) }, + { add_type::SLEEP, translate_marker( "You may find it difficult to sleep without medication." ) }, { - ADD_PKILLER, translate_marker( "Strength - 1; Perception - 1; Dexterity - 1;\nDepression and physical pain to some degree. Frequent cravings. Vomiting." ) + add_type::PKILLER, translate_marker( "Strength - 1; Perception - 1; Dexterity - 1;\nDepression and physical pain to some degree. Frequent cravings. Vomiting." ) }, - { ADD_SPEED, translate_marker( "Strength - 1; Intelligence - 1;\nMovement rate reduction. Depression. Weak immune system. Frequent cravings." ) }, - { ADD_COKE, translate_marker( "Perception - 1; Intelligence - 1; Frequent cravings." ) }, - { ADD_CRACK, translate_marker( "Perception - 2; Intelligence - 2; Frequent cravings." ) }, - { ADD_MUTAGEN, translate_marker( "You've gotten a taste for mutating and the chemicals that cause it. But you can stop, yeah, any time you want." ) }, + { add_type::SPEED, translate_marker( "Strength - 1; Intelligence - 1;\nMovement rate reduction. Depression. Weak immune system. Frequent cravings." ) }, + { add_type::COKE, translate_marker( "Perception - 1; Intelligence - 1; Frequent cravings." ) }, + { add_type::CRACK, translate_marker( "Perception - 2; Intelligence - 2; Frequent cravings." ) }, + { add_type::MUTAGEN, translate_marker( "You've gotten a taste for mutating and the chemicals that cause it. But you can stop, yeah, any time you want." ) }, { - ADD_DIAZEPAM, translate_marker( "Perception - 1; Intelligence - 1;\nAnxiety, nausea, hallucinations, and general malaise." ) + add_type::DIAZEPAM, translate_marker( "Perception - 1; Intelligence - 1;\nAnxiety, nausea, hallucinations, and general malaise." ) }, - { ADD_MARLOSS_R, translate_marker( "You should try some of those pink berries." ) }, - { ADD_MARLOSS_B, translate_marker( "You should try some of those cyan seeds." ) }, - { ADD_MARLOSS_Y, translate_marker( "You should try some of that golden gel." ) }, + { add_type::MARLOSS_R, translate_marker( "You should try some of those pink berries." ) }, + { add_type::MARLOSS_B, translate_marker( "You should try some of those cyan seeds." ) }, + { add_type::MARLOSS_Y, translate_marker( "You should try some of that golden gel." ) }, } }; diff --git a/src/addiction.h b/src/addiction.h index 5df8b337b7b70..4f0ba7ab6cd1f 100644 --- a/src/addiction.h +++ b/src/addiction.h @@ -4,13 +4,12 @@ #include +#include "pldata.h" #include "type_id.h" class addiction; class Character; -enum add_type : int; - // Minimum intensity before effects are seen constexpr int MIN_ADDICTION_LEVEL = 3; constexpr int MAX_ADDICTION_LEVEL = 20; diff --git a/src/avatar.h b/src/avatar.h index 98dcf917a0394..727355832eff6 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -19,8 +19,6 @@ class faction; -enum character_type : int; - class JsonIn; class JsonObject; class JsonOut; diff --git a/src/cata_variant.h b/src/cata_variant.h index 31b5dd7f26747..f8f634829b056 100644 --- a/src/cata_variant.h +++ b/src/cata_variant.h @@ -13,13 +13,13 @@ #include "debug.h" #include "enum_conversions.h" #include "hash_utils.h" +#include "pldata.h" #include "type_id.h" class JsonIn; class JsonOut; template struct enum_traits; -enum add_type : int; enum body_part : int; enum class mutagen_technique : int; enum hp_part : int; diff --git a/src/character.cpp b/src/character.cpp index 491ec06011166..d4642a46203a0 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -9490,7 +9490,7 @@ int Character::heartrate_bpm() const heartbeat += average_heartbeat * stim_modifer; if( get_effect_dur( effect_cig ) > 0_turns ) { //Nicotine-induced tachycardia - if( get_effect_dur( effect_cig ) > 10_minutes * ( addiction_level( ADD_CIG ) + 1 ) ) { + if( get_effect_dur( effect_cig ) > 10_minutes * ( addiction_level( add_type::CIG ) + 1 ) ) { heartbeat += average_heartbeat * 0.4; } else { heartbeat += average_heartbeat * 0.1; diff --git a/src/consumption.cpp b/src/consumption.cpp index e5877948c1c0e..9db22866c425e 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1042,8 +1042,8 @@ void Character::modify_stimulation( const islot_comestible &comest ) } } if( has_trait( trait_STIMBOOST ) && ( current_stim > 30 ) && - ( ( comest.add == ADD_CAFFEINE ) || ( comest.add == ADD_SPEED ) || ( comest.add == ADD_COKE ) || - ( comest.add == ADD_CRACK ) ) ) { + ( ( comest.add == add_type::CAFFEINE ) || ( comest.add == add_type::SPEED ) || + ( comest.add == add_type::COKE ) || ( comest.add == add_type::CRACK ) ) ) { int hallu_duration = ( current_stim - comest.stim < 30 ) ? current_stim - 30 : comest.stim; add_effect( effect_visuals, hallu_duration * 30_minutes ); std::vector stimboost_msg{ _( "The shadows are getting ever closer." ), diff --git a/src/iexamine.cpp b/src/iexamine.cpp index daecac6b5b322..f944eb88359f0 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -1690,7 +1690,7 @@ void iexamine::flower_poppy( player &p, const tripoint &examp ) p.add_effect( effect_pkill2, 7_minutes ); // Please drink poppy nectar responsibly. if( one_in( 20 ) ) { - p.add_addiction( ADD_PKILLER, 1 ); + p.add_addiction( add_type::PKILLER, 1 ); } } if( !query_yn( _( "Pick %s?" ), g->m.furnname( examp ) ) ) { diff --git a/src/itype.h b/src/itype.h index 0a68b560addfa..d5c2f31434107 100644 --- a/src/itype.h +++ b/src/itype.h @@ -135,7 +135,7 @@ struct islot_comestible { int addict = 0; /** effects of addiction */ - add_type add = ADD_NULL; + add_type add = add_type::NONE; /** stimulant effect */ int stim = 0; diff --git a/src/iuse.cpp b/src/iuse.cpp index 66e9529505c5f..d2f1f4f301a6e 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -534,7 +534,8 @@ int iuse::smoking( player *p, item *it, bool, const tripoint & ) weed_msg( *p ); } } - if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level( ADD_CIG ) + 1 ) ) { + if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level( + add_type::CIG ) + 1 ) ) { p->add_msg_if_player( m_bad, _( "Ugh, too much smoke… you feel nasty." ) ); } @@ -561,7 +562,8 @@ int iuse::ecig( player *p, item *it, bool, const tripoint & ) p->mod_thirst( 1 ); p->mod_hunger( -1 ); p->add_effect( effect_cig, 10_minutes ); - if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level( ADD_CIG ) + 1 ) ) { + if( p->get_effect_dur( effect_cig ) > 10_minutes * ( p->addiction_level( + add_type::CIG ) + 1 ) ) { p->add_msg_if_player( m_bad, _( "Ugh, too much nicotine… you feel nasty." ) ); } return it->type->charges_to_use(); @@ -1239,7 +1241,7 @@ static void spawn_spores( const player &p ) static void marloss_common( player &p, item &it, const trait_id ¤t_color ) { static const std::map mycus_colors = {{ - { trait_MARLOSS_BLUE, ADD_MARLOSS_B }, { trait_MARLOSS_YELLOW, ADD_MARLOSS_Y }, { trait_MARLOSS, ADD_MARLOSS_R } + { trait_MARLOSS_BLUE, add_type::MARLOSS_B }, { trait_MARLOSS_YELLOW, add_type::MARLOSS_Y }, { trait_MARLOSS, add_type::MARLOSS_R } } }; @@ -1484,9 +1486,9 @@ int iuse::mycus( player *p, item *it, bool t, const tripoint &pos ) for( const tripoint &nearby_pos : g->m.points_in_radius( p->pos(), 3 ) ) { fe.marlossify( nearby_pos ); } - p->rem_addiction( ADD_MARLOSS_R ); - p->rem_addiction( ADD_MARLOSS_B ); - p->rem_addiction( ADD_MARLOSS_Y ); + p->rem_addiction( add_type::MARLOSS_R ); + p->rem_addiction( add_type::MARLOSS_B ); + p->rem_addiction( add_type::MARLOSS_Y ); } else if( p->has_trait( trait_THRESH_MYCUS ) && !p->has_trait( trait_M_DEPENDENT ) ) { // OK, now set the hook. if( !one_in( 3 ) ) { diff --git a/src/player.cpp b/src/player.cpp index 5199d06fde538..a03c953da25f0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2037,7 +2037,7 @@ void player::process_one_effect( effect &it, bool is_new ) // Handle painkillers val = get_effect( "PKILL", reduced ); if( val != 0 ) { - mod = it.get_addict_mod( "PKILL", addiction_level( ADD_PKILLER ) ); + mod = it.get_addict_mod( "PKILL", addiction_level( add_type::PKILLER ) ); if( is_new || it.activated( calendar::turn, "PKILL", val, reduced, mod ) ) { mod_painkiller( bound_mod_to_vals( get_painkiller(), val, it.get_max_val( "PKILL", reduced ), 0 ) ); } @@ -4317,7 +4317,7 @@ int player::sleep_spot( const tripoint &p ) const int sleepy = static_cast( comfort_info.level ); bool watersleep = has_trait( trait_WATERSLEEP ); - if( has_addiction( ADD_SLEEP ) ) { + if( has_addiction( add_type::SLEEP ) ) { sleepy -= 4; } if( has_trait( trait_INSOMNIA ) ) { diff --git a/src/pldata.h b/src/pldata.h index 7f47c16cece9d..b864c03f2399e 100644 --- a/src/pldata.h +++ b/src/pldata.h @@ -18,17 +18,17 @@ enum class character_type : int { FULL_RANDOM, }; -enum add_type : int { - ADD_NULL, - ADD_CAFFEINE, ADD_ALCOHOL, ADD_SLEEP, ADD_PKILLER, ADD_SPEED, ADD_CIG, - ADD_COKE, ADD_CRACK, ADD_MUTAGEN, ADD_DIAZEPAM, ADD_MARLOSS_R, ADD_MARLOSS_B, - ADD_MARLOSS_Y, +enum class add_type : int { + NONE, + CAFFEINE, ALCOHOL, SLEEP, PKILLER, SPEED, CIG, + COKE, CRACK, MUTAGEN, DIAZEPAM, + MARLOSS_R, MARLOSS_B, MARLOSS_Y, NUM_ADD_TYPES // last }; template<> struct enum_traits { - static constexpr add_type last = NUM_ADD_TYPES; + static constexpr add_type last = add_type::NUM_ADD_TYPES; }; enum hp_part : int { @@ -49,8 +49,8 @@ struct enum_traits { class addiction { public: - add_type type = ADD_NULL; - int intensity = 0; + add_type type = add_type::NONE; + int intensity = 0; time_duration sated = 1_hours; addiction() = default; diff --git a/src/profession.h b/src/profession.h index 09d3f8dbaac48..d7dd772dfb393 100644 --- a/src/profession.h +++ b/src/profession.h @@ -26,8 +26,6 @@ class JsonObject; class avatar; class player; -enum add_type : int; - class profession { public: diff --git a/src/scenario.h b/src/scenario.h index 1ba4a8da6c4b3..fe6feea21faa5 100644 --- a/src/scenario.h +++ b/src/scenario.h @@ -7,6 +7,7 @@ #include #include +#include "pldata.h" #include "string_id.h" #include "translations.h" #include "type_id.h" @@ -14,7 +15,6 @@ class JsonObject; class profession; -enum add_type : int; template class generic_factory; diff --git a/src/suffer.cpp b/src/suffer.cpp index 341d60d839019..f014d9465a183 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -1570,13 +1570,13 @@ void Character::mend( int rate_multiplier ) if( has_effect( effect_cig ) ) { healing_factor *= 0.5; } else { - healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( ADD_CIG ) ); + healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( add_type::CIG ) ); } if( has_effect( effect_drunk ) ) { healing_factor *= 0.5; } else { - healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( ADD_ALCOHOL ) ); + healing_factor *= addiction_scaling( 0.25f, 0.75f, addiction_level( add_type::ALCOHOL ) ); } if( get_rad() > 0 && !has_trait( trait_RADIOGENIC ) ) { @@ -1836,7 +1836,7 @@ void Character::apply_wetness_morale( int temperature ) void Character::add_addiction( add_type type, int strength ) { - if( type == ADD_NULL ) { + if( type == add_type::NONE ) { return; } time_duration timer = 2_hours; diff --git a/tests/memorial_test.cpp b/tests/memorial_test.cpp index d4a131de2912f..4e90c294b6a2c 100644 --- a/tests/memorial_test.cpp +++ b/tests/memorial_test.cpp @@ -174,7 +174,7 @@ TEST_CASE( "memorials" ) m, b, "The fuel tank of the vehicle_name exploded!", "vehicle_name" ); check_memorial( - m, b, "Became addicted to alcohol.", ch, ADD_ALCOHOL ); + m, b, "Became addicted to alcohol.", ch, add_type::ALCOHOL ); check_memorial( m, b, "Gained the mutation 'Carnivore'.", ch, mut ); @@ -198,7 +198,7 @@ TEST_CASE( "memorials" ) m, b, "Learned Aikido.", ch, matype_id( "style_aikido" ) ); check_memorial( - m, b, "Overcame addiction to alcohol.", ch, ADD_ALCOHOL ); + m, b, "Overcame addiction to alcohol.", ch, add_type::ALCOHOL ); check_memorial( m, b, "npc_name became hostile.", ch2, "npc_name" ); From d72c19ba211ba58a4896a3c8c6d3b0caff79628a Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 11:00:45 +0300 Subject: [PATCH 5/8] Make radio_type a class enum --- src/iuse.cpp | 4 ++-- src/overmap.cpp | 4 ++-- src/overmap.h | 4 ++-- src/savegame.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/iuse.cpp b/src/iuse.cpp index d2f1f4f301a6e..5b8a8338ed09d 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -2171,9 +2171,9 @@ int iuse::radio_on( player *p, item *it, bool t, const tripoint &pos ) const auto tref = overmap_buffer.find_radio_station( it->frequency ); if( tref ) { const auto selected_tower = tref.tower; - if( selected_tower->type == MESSAGE_BROADCAST ) { + if( selected_tower->type == radio_type::MESSAGE_BROADCAST ) { message = selected_tower->message; - } else if( selected_tower->type == WEATHER_RADIO ) { + } else if( selected_tower->type == radio_type::WEATHER_RADIO ) { message = weather_forecast( tref.abs_sm_pos ); } diff --git a/src/overmap.cpp b/src/overmap.cpp index 83fef91cbef97..5f06e894f6d76 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -227,7 +227,7 @@ int city::get_distance_from( const tripoint &p ) const } std::map radio_type_names = -{{ {MESSAGE_BROADCAST, "broadcast"}, {WEATHER_RADIO, "weather"} }}; +{{ {radio_type::MESSAGE_BROADCAST, "broadcast"}, {radio_type::WEATHER_RADIO, "weather"} }}; /** @relates string_id */ template<> @@ -4310,7 +4310,7 @@ void overmap::place_radios() _( "Head West. All survivors, head West. Help is waiting." ) ) ); break; case 2: - radios.push_back( radio_tower( pos_sm, strength(), "", WEATHER_RADIO ) ); + radios.push_back( radio_tower( pos_sm, strength(), "", radio_type::WEATHER_RADIO ) ); break; } } else if( ter( pos_omt ) == "lmoe" ) { diff --git a/src/overmap.h b/src/overmap.h index ea073bd758f11..c5f8d24597378 100644 --- a/src/overmap.h +++ b/src/overmap.h @@ -74,7 +74,7 @@ struct om_vehicle { std::string name; }; -enum radio_type { +enum class radio_type : int { MESSAGE_BROADCAST, WEATHER_RADIO }; @@ -92,7 +92,7 @@ struct radio_tower { std::string message; int frequency; radio_tower( const point &p, int S = -1, const std::string &M = "", - radio_type T = MESSAGE_BROADCAST ) : + radio_type T = radio_type::MESSAGE_BROADCAST ) : pos( p ), strength( S ), type( T ), message( M ) { frequency = rng( 0, INT_MAX ); } diff --git a/src/savegame.cpp b/src/savegame.cpp index 9234d28d06b7a..627187868bd1c 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -1019,7 +1019,7 @@ void overmap::unserialize( std::istream &fin ) const std::string radio_name = jsin.get_string(); const auto mapping = find_if( radio_type_names.begin(), radio_type_names.end(), - [radio_name]( const std::pair &p ) { + [radio_name]( const std::pair &p ) { return p.second == radio_name; } ); if( mapping != radio_type_names.end() ) { From 609a6cfad3d1a0209578caae3119a5abe859ca9c Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 11:04:11 +0300 Subject: [PATCH 6/8] Make affected_stat a class enum --- src/bonuses.cpp | 45 +++++++++++++++++++++++---------------------- src/bonuses.h | 24 ++++++++++++------------ src/martialarts.cpp | 29 +++++++++++++++-------------- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/bonuses.cpp b/src/bonuses.cpp index 13e4b8cb77f64..990646ec62994 100644 --- a/src/bonuses.cpp +++ b/src/bonuses.cpp @@ -12,20 +12,21 @@ static bool needs_damage_type( affected_stat as ) { - return as == AFFECTED_DAMAGE || as == AFFECTED_ARMOR || - as == AFFECTED_ARMOR_PENETRATION; + return as == affected_stat::DAMAGE || + as == affected_stat::ARMOR || + as == affected_stat::ARMOR_PENETRATION; } static const std::map affected_stat_map = {{ - std::make_pair( "hit", AFFECTED_HIT ), - std::make_pair( "dodge", AFFECTED_DODGE ), - std::make_pair( "block", AFFECTED_BLOCK ), - std::make_pair( "speed", AFFECTED_SPEED ), - std::make_pair( "movecost", AFFECTED_MOVE_COST ), - std::make_pair( "damage", AFFECTED_DAMAGE ), - std::make_pair( "armor", AFFECTED_ARMOR ), - std::make_pair( "arpen", AFFECTED_ARMOR_PENETRATION ), - std::make_pair( "target_armor_multiplier", AFFECTED_TARGET_ARMOR_MULTIPLIER ) + std::make_pair( "hit", affected_stat::HIT ), + std::make_pair( "dodge", affected_stat::DODGE ), + std::make_pair( "block", affected_stat::BLOCK ), + std::make_pair( "speed", affected_stat::SPEED ), + std::make_pair( "movecost", affected_stat::MOVE_COST ), + std::make_pair( "damage", affected_stat::DAMAGE ), + std::make_pair( "armor", affected_stat::ARMOR ), + std::make_pair( "arpen", affected_stat::ARMOR_PENETRATION ), + std::make_pair( "target_armor_multiplier", affected_stat::TARGET_ARMOR_MULTIPLIER ) } }; @@ -54,19 +55,19 @@ static affected_stat affected_stat_from_string( const std::string &s ) return iter->second; } - return AFFECTED_NULL; + return affected_stat::NONE; } static const std::map affected_stat_map_translation = {{ - std::make_pair( AFFECTED_HIT, translate_marker( "Accuracy" ) ), - std::make_pair( AFFECTED_DODGE, translate_marker( "Dodge" ) ), - std::make_pair( AFFECTED_BLOCK, translate_marker( "Block" ) ), - std::make_pair( AFFECTED_SPEED, translate_marker( "Speed" ) ), - std::make_pair( AFFECTED_MOVE_COST, translate_marker( "Move cost" ) ), - std::make_pair( AFFECTED_DAMAGE, translate_marker( "damage" ) ), - std::make_pair( AFFECTED_ARMOR, translate_marker( "Armor" ) ), - std::make_pair( AFFECTED_ARMOR_PENETRATION, translate_marker( "Armor penetration" ) ), - std::make_pair( AFFECTED_TARGET_ARMOR_MULTIPLIER, translate_marker( "Target armor multiplier" ) ), + std::make_pair( affected_stat::HIT, translate_marker( "Accuracy" ) ), + std::make_pair( affected_stat::DODGE, translate_marker( "Dodge" ) ), + std::make_pair( affected_stat::BLOCK, translate_marker( "Block" ) ), + std::make_pair( affected_stat::SPEED, translate_marker( "Speed" ) ), + std::make_pair( affected_stat::MOVE_COST, translate_marker( "Move cost" ) ), + std::make_pair( affected_stat::DAMAGE, translate_marker( "damage" ) ), + std::make_pair( affected_stat::ARMOR, translate_marker( "Armor" ) ), + std::make_pair( affected_stat::ARMOR_PENETRATION, translate_marker( "Armor penetration" ) ), + std::make_pair( affected_stat::TARGET_ARMOR_MULTIPLIER, translate_marker( "Target armor multiplier" ) ), } }; @@ -113,7 +114,7 @@ void bonus_container::load( const JsonArray &jarr, const bool mult ) { for( const JsonObject &qualifiers : jarr ) { const affected_stat as = affected_stat_from_string( qualifiers.get_string( "stat" ) ); - if( as == AFFECTED_NULL ) { + if( as == affected_stat::NONE ) { qualifiers.throw_error( "Invalid affected stat", "stat" ); } diff --git a/src/bonuses.h b/src/bonuses.h index ccf1b1a54fb0e..6202677db50fc 100644 --- a/src/bonuses.h +++ b/src/bonuses.h @@ -21,17 +21,17 @@ enum scaling_stat : int { NUM_STATS }; -enum affected_stat : int { - AFFECTED_NULL = 0, - AFFECTED_HIT, - AFFECTED_DODGE, - AFFECTED_BLOCK, - AFFECTED_SPEED, - AFFECTED_MOVE_COST, - AFFECTED_DAMAGE, - AFFECTED_ARMOR, - AFFECTED_ARMOR_PENETRATION, - AFFECTED_TARGET_ARMOR_MULTIPLIER, +enum class affected_stat : int { + NONE = 0, + HIT, + DODGE, + BLOCK, + SPEED, + MOVE_COST, + DAMAGE, + ARMOR, + ARMOR_PENETRATION, + TARGET_ARMOR_MULTIPLIER, NUM_AFFECTED }; @@ -52,7 +52,7 @@ struct affected_type { } private: - affected_stat stat = affected_stat::AFFECTED_NULL; + affected_stat stat = affected_stat::NONE; damage_type type; }; diff --git a/src/martialarts.cpp b/src/martialarts.cpp index 3f0e0867127a1..23005b897ffc9 100644 --- a/src/martialarts.cpp +++ b/src/martialarts.cpp @@ -644,31 +644,31 @@ void ma_buff::apply_character( Character &u ) const int ma_buff::hit_bonus( const Character &u ) const { - return bonuses.get_flat( u, AFFECTED_HIT ); + return bonuses.get_flat( u, affected_stat::HIT ); } int ma_buff::dodge_bonus( const Character &u ) const { - return bonuses.get_flat( u, AFFECTED_DODGE ); + return bonuses.get_flat( u, affected_stat::DODGE ); } int ma_buff::block_bonus( const Character &u ) const { - return bonuses.get_flat( u, AFFECTED_BLOCK ); + return bonuses.get_flat( u, affected_stat::BLOCK ); } int ma_buff::speed_bonus( const Character &u ) const { - return bonuses.get_flat( u, AFFECTED_SPEED ); + return bonuses.get_flat( u, affected_stat::SPEED ); } int ma_buff::armor_bonus( const Character &guy, damage_type dt ) const { - return bonuses.get_flat( guy, AFFECTED_ARMOR, dt ); + return bonuses.get_flat( guy, affected_stat::ARMOR, dt ); } float ma_buff::damage_bonus( const Character &u, damage_type dt ) const { - return bonuses.get_flat( u, AFFECTED_DAMAGE, dt ); + return bonuses.get_flat( u, affected_stat::DAMAGE, dt ); } float ma_buff::damage_mult( const Character &u, damage_type dt ) const { - return bonuses.get_mult( u, AFFECTED_DAMAGE, dt ); + return bonuses.get_mult( u, affected_stat::DAMAGE, dt ); } bool ma_buff::is_throw_immune() const { @@ -1131,7 +1131,7 @@ int Character::mabuff_attack_cost_penalty() const { int ret = 0; accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) { - ret += d.get_intensity() * b.bonuses.get_flat( *this, AFFECTED_MOVE_COST ); + ret += d.get_intensity() * b.bonuses.get_flat( *this, affected_stat::MOVE_COST ); } ); return ret; } @@ -1141,7 +1141,8 @@ float Character::mabuff_attack_cost_mult() const accumulate_ma_buff_effects( *effects, [&ret, this]( const ma_buff & b, const effect & d ) { // This is correct, so that a 20% buff (1.2) plus a 20% buff (1.2) // becomes 1.4 instead of 2.4 (which would be a 240% buff) - ret *= d.get_intensity() * ( b.bonuses.get_mult( *this, AFFECTED_MOVE_COST ) - 1 ) + 1; + ret *= d.get_intensity() * ( b.bonuses.get_mult( *this, + affected_stat::MOVE_COST ) - 1 ) + 1; } ); return ret; } @@ -1227,27 +1228,27 @@ void character_martial_arts::martialart_use_message( const Character &owner ) co float ma_technique::damage_bonus( const Character &u, damage_type type ) const { - return bonuses.get_flat( u, AFFECTED_DAMAGE, type ); + return bonuses.get_flat( u, affected_stat::DAMAGE, type ); } float ma_technique::damage_multiplier( const Character &u, damage_type type ) const { - return bonuses.get_mult( u, AFFECTED_DAMAGE, type ); + return bonuses.get_mult( u, affected_stat::DAMAGE, type ); } float ma_technique::move_cost_multiplier( const Character &u ) const { - return bonuses.get_mult( u, AFFECTED_MOVE_COST ); + return bonuses.get_mult( u, affected_stat::MOVE_COST ); } float ma_technique::move_cost_penalty( const Character &u ) const { - return bonuses.get_flat( u, AFFECTED_MOVE_COST ); + return bonuses.get_flat( u, affected_stat::MOVE_COST ); } float ma_technique::armor_penetration( const Character &u, damage_type type ) const { - return bonuses.get_flat( u, AFFECTED_ARMOR_PENETRATION, type ); + return bonuses.get_flat( u, affected_stat::ARMOR_PENETRATION, type ); } std::string ma_technique::get_description() const From c56fe4453ae6d69b933b7eeafbc4db6bf9c83df5 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Mon, 13 Apr 2020 00:49:00 +0300 Subject: [PATCH 7/8] 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 5f6192a2bf374..177ffbf2650c2 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." ); From 61f0bbbb89768a673b38ac9250be8d79c3bc60cb Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Sun, 12 Apr 2020 13:05:35 +0300 Subject: [PATCH 8/8] Make direction a class enum --- src/cata_tiles.cpp | 34 ++--- src/cata_tiles.h | 2 +- src/character.cpp | 4 +- src/game.cpp | 56 ++++---- src/line.cpp | 106 ++++++++------- src/line.h | 38 +++++- src/map.cpp | 16 +-- src/map.h | 2 +- src/map_extras.cpp | 26 ++-- src/mapgen.cpp | 120 ++++++++--------- src/mission_start.cpp | 8 +- src/npc.h | 4 +- src/output.cpp | 39 +++--- src/output.h | 11 +- src/overmap_ui.cpp | 16 +-- src/pickup.cpp | 2 +- tests/line_test.cpp | 298 +++++++++++++++++++++--------------------- 17 files changed, 423 insertions(+), 359 deletions(-) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index ca6e2cc8157e1..b57c6f92902d1 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -158,18 +158,18 @@ static int msgtype_to_tilecolor( const game_message_type type, const bool bOldMs } formatted_text::formatted_text( const std::string &text, const int color, - const direction direction ) + const direction text_direction ) : text( text ), color( color ) { - switch( direction ) { - case NORTHWEST: - case WEST: - case SOUTHWEST: + switch( text_direction ) { + case direction::NORTHWEST: + case direction::WEST: + case direction::SOUTHWEST: alignment = TEXT_ALIGNMENT_RIGHT; break; - case NORTH: - case CENTER: - case SOUTH: + case direction::NORTH: + case direction::CENTER: + case direction::SOUTH: alignment = TEXT_ALIGNMENT_CENTER; break; default: @@ -1085,12 +1085,12 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int for( const point &pt_elem : collision_checkpoints ) { overlay_strings.emplace( player_to_screen( pt_elem ) + point( tile_width / 2, 0 ), formatted_text( "CHECK", catacurses::yellow, - NORTH ) ); + direction::NORTH ) ); } for( const point &pt_elem : target_points ) { overlay_strings.emplace( player_to_screen( pt_elem ) + point( tile_width / 2, 0 ), formatted_text( "TARGET", catacurses::red, - NORTH ) ); + direction::NORTH ) ); } } for( int row = min_row; row < max_row; row ++ ) { @@ -1141,7 +1141,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( scent_value > 0 ) { overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ), formatted_text( std::to_string( scent_value ), 8 + catacurses::yellow, - NORTH ) ); + direction::NORTH ) ); } } @@ -1151,7 +1151,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int if( !scent_type.is_empty() ) { overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ), formatted_text( scent_type.c_str(), 8 + catacurses::yellow, - NORTH ) ); + direction::NORTH ) ); } } @@ -1167,7 +1167,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int col = catacurses::cyan; } overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ), - formatted_text( std::to_string( rad_value ), 8 + col, NORTH ) ); + formatted_text( std::to_string( rad_value ), 8 + col, direction::NORTH ) ); } } @@ -1198,7 +1198,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 2, 0 ), formatted_text( std::to_string( temp_value ), color, - NORTH ) ); + direction::NORTH ) ); } if( g->display_overlay_state( ACTION_DISPLAY_VISIBILITY ) && @@ -1215,7 +1215,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int std::string visibility_str = visibility ? "+" : "-"; overlay_strings.emplace( player_to_screen( point( x, y ) ) + point( tile_width / 4, tile_height / 4 ), - formatted_text( visibility_str, catacurses::black, NORTH ) ); + formatted_text( visibility_str, catacurses::black, direction::NORTH ) ); } if( g->display_overlay_state( ACTION_DISPLAY_LIGHTING ) ) { @@ -1241,7 +1241,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int // string overlay overlay_strings.emplace( tile_pos + point( tile_width / 4, tile_height / 4 ), - formatted_text( string_format( "%.1f", ambient ), catacurses::black, NORTH ) ); + formatted_text( string_format( "%.1f", ambient ), catacurses::black, direction::NORTH ) ); } } @@ -1297,7 +1297,7 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int text += "+"; } overlay_strings.emplace( player_to_screen( p.pos.xy() ) + point( tile_width / 2, 0 ), - formatted_text( text, catacurses::red, NORTH ) ); + formatted_text( text, catacurses::red, direction::NORTH ) ); } } } diff --git a/src/cata_tiles.h b/src/cata_tiles.h index 87daca1def42e..8390b5482bcb4 100644 --- a/src/cata_tiles.h +++ b/src/cata_tiles.h @@ -253,7 +253,7 @@ struct formatted_text { : text( text ), color( color ), alignment( alignment ) { } - formatted_text( const std::string &text, int color, direction direction ); + formatted_text( const std::string &text, int color, direction text_direction ); }; /** type used for color blocks overlays. diff --git a/src/character.cpp b/src/character.cpp index d4642a46203a0..67ac173ba67bc 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -8121,7 +8121,7 @@ void Character::absorb_hit( body_part bp, damage_instance &dam ) if( destroy ) { if( g->u.sees( *this ) ) { - SCT.add( point( posx(), posy() ), NORTH, remove_color_tags( pre_damage_name ), + SCT.add( point( posx(), posy() ), direction::NORTH, remove_color_tags( pre_damage_name ), m_neutral, _( "destroyed" ), m_info ); } destroyed_armor_msg( *this, pre_damage_name ); @@ -8215,7 +8215,7 @@ bool Character::armor_absorb( damage_unit &du, item &armor ) add_msg_if_player( m_bad, format_string, pre_damage_name, damage_verb ); //item is damaged if( is_player() ) { - SCT.add( point( posx(), posy() ), NORTH, remove_color_tags( pre_damage_name ), m_neutral, + SCT.add( point( posx(), posy() ), direction::NORTH, remove_color_tags( pre_damage_name ), m_neutral, damage_verb, m_info ); } diff --git a/src/game.cpp b/src/game.cpp index 53001432a296a..392c27eb9e9e7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4008,49 +4008,49 @@ void game::mon_info_update( ) // for compatibility with old code, see diagram below, it explains the values for index, // also might need revisiting one z-levels are in. switch( dir_to_mon ) { - case ABOVENORTHWEST: - case NORTHWEST: - case BELOWNORTHWEST: + case direction::ABOVENORTHWEST: + case direction::NORTHWEST: + case direction::BELOWNORTHWEST: index = 7; break; - case ABOVENORTH: - case NORTH: - case BELOWNORTH: + case direction::ABOVENORTH: + case direction::NORTH: + case direction::BELOWNORTH: index = 0; break; - case ABOVENORTHEAST: - case NORTHEAST: - case BELOWNORTHEAST: + case direction::ABOVENORTHEAST: + case direction::NORTHEAST: + case direction::BELOWNORTHEAST: index = 1; break; - case ABOVEWEST: - case WEST: - case BELOWWEST: + case direction::ABOVEWEST: + case direction::WEST: + case direction::BELOWWEST: index = 6; break; - case ABOVECENTER: - case CENTER: - case BELOWCENTER: + case direction::ABOVECENTER: + case direction::CENTER: + case direction::BELOWCENTER: index = 8; break; - case ABOVEEAST: - case EAST: - case BELOWEAST: + case direction::ABOVEEAST: + case direction::EAST: + case direction::BELOWEAST: index = 2; break; - case ABOVESOUTHWEST: - case SOUTHWEST: - case BELOWSOUTHWEST: + case direction::ABOVESOUTHWEST: + case direction::SOUTHWEST: + case direction::BELOWSOUTHWEST: index = 5; break; - case ABOVESOUTH: - case SOUTH: - case BELOWSOUTH: + case direction::ABOVESOUTH: + case direction::SOUTH: + case direction::BELOWSOUTH: index = 4; break; - case ABOVESOUTHEAST: - case SOUTHEAST: - case BELOWSOUTHEAST: + case direction::ABOVESOUTHEAST: + case direction::SOUTHEAST: + case direction::BELOWSOUTHEAST: index = 3; break; } @@ -9337,7 +9337,7 @@ point game::place_player( const tripoint &dest_loc ) //Auto pulp or butcher and Auto foraging if( get_option( "AUTO_FEATURES" ) && mostseen == 0 && !u.is_mounted() ) { - static const direction adjacentDir[8] = { NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST }; + static const direction adjacentDir[8] = { direction::NORTH, direction::NORTHEAST, direction::EAST, direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST, direction::NORTHWEST }; const std::string forage_type = get_option( "AUTO_FORAGING" ); if( forage_type != "off" ) { diff --git a/src/line.cpp b/src/line.cpp index 34340a0692ba4..f94500b1b05a8 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -294,31 +294,31 @@ unsigned make_xyz( const tripoint &p ) int octant = atan2( p.x, p.y ) / sixteenth_arc; switch( octant ) { case 0: - return SOUTH + vertical_position; + return direction::SOUTH + vertical_position; case 1: case 2: - return SOUTHEAST + vertical_position; + return direction::SOUTHEAST + vertical_position; case 3: case 4: - return EAST + vertical_position; + return direction::EAST + vertical_position; case 5: case 6: - return NORTHEAST + vertical_position; + return direction::NORTHEAST + vertical_position; case -1: case -2: - return SOUTHWEST + vertical_position; + return direction::SOUTHWEST + vertical_position; case -3: case -4: - return WEST + vertical_position; + return direction::WEST + vertical_position; case -5: case -6: - return NORTHWEST + vertical_position; + return direction::NORTHWEST + vertical_position; case 7: case 8: case -7: case -8: default: - return NORTH + vertical_position; + return direction::NORTH + vertical_position; } } @@ -389,23 +389,41 @@ direction direction_from( const tripoint &p, const tripoint &q ) point direction_XY( const direction dir ) { switch( dir % 9 ) { - case NORTHWEST: + case direction::NORTHWEST: + case direction::ABOVENORTHWEST: + case direction::BELOWNORTHWEST: return point_north_west; - case NORTH: + case direction::NORTH: + case direction::ABOVENORTH: + case direction::BELOWNORTH: return point_north; - case NORTHEAST: + case direction::NORTHEAST: + case direction::ABOVENORTHEAST: + case direction::BELOWNORTHEAST: return point_north_east; - case WEST: + case direction::WEST: + case direction::ABOVEWEST: + case direction::BELOWWEST: return point_west; - case CENTER: + case direction::CENTER: + case direction::ABOVECENTER: + case direction::BELOWCENTER: return point_zero; - case EAST: + case direction::EAST: + case direction::ABOVEEAST: + case direction::BELOWEAST: return point_east; - case SOUTHWEST: + case direction::SOUTHWEST: + case direction::ABOVESOUTHWEST: + case direction::BELOWSOUTHWEST: return point_south_west; - case SOUTH: + case direction::SOUTH: + case direction::ABOVESOUTH: + case direction::BELOWSOUTH: return point_south; - case SOUTHEAST: + case direction::SOUTHEAST: + case direction::ABOVESOUTHEAST: + case direction::BELOWSOUTHEAST: return point_south_east; } @@ -422,33 +440,33 @@ std::string direction_name_impl( const direction dir, const bool short_name ) std::array < pair_t, size + 1 > result; //~ abbreviated direction names and long direction names - result[NORTH] = pair_t {translate_marker( "N " ), translate_marker( "north" )}; - result[NORTHEAST] = pair_t {translate_marker( "NE " ), translate_marker( "northeast" )}; - result[EAST] = pair_t {translate_marker( "E " ), translate_marker( "east" )}; - result[SOUTHEAST] = pair_t {translate_marker( "SE " ), translate_marker( "southeast" )}; - result[SOUTH] = pair_t {translate_marker( "S " ), translate_marker( "south" )}; - result[SOUTHWEST] = pair_t {translate_marker( "SW " ), translate_marker( "southwest" )}; - result[WEST] = pair_t {translate_marker( "W " ), translate_marker( "west" )}; - result[NORTHWEST] = pair_t {translate_marker( "NW " ), translate_marker( "northwest" )}; - result[ABOVENORTH] = pair_t {translate_marker( "UP_N " ), translate_marker( "north and above" )}; - result[ABOVENORTHEAST] = pair_t {translate_marker( "UP_NE" ), translate_marker( "northeast and above" )}; - result[ABOVEEAST] = pair_t {translate_marker( "UP_E " ), translate_marker( "east and above" )}; - result[ABOVESOUTHEAST] = pair_t {translate_marker( "UP_SE" ), translate_marker( "southeast and above" )}; - result[ABOVESOUTH] = pair_t {translate_marker( "UP_S " ), translate_marker( "south and above" )}; - result[ABOVESOUTHWEST] = pair_t {translate_marker( "UP_SW" ), translate_marker( "southwest and above" )}; - result[ABOVEWEST] = pair_t {translate_marker( "UP_W " ), translate_marker( "west and above" )}; - result[ABOVENORTHWEST] = pair_t {translate_marker( "UP_NW" ), translate_marker( "northwest and above" )}; - result[BELOWNORTH] = pair_t {translate_marker( "DN_N " ), translate_marker( "north and below" )}; - result[BELOWNORTHEAST] = pair_t {translate_marker( "DN_NE" ), translate_marker( "northeast and below" )}; - result[BELOWEAST] = pair_t {translate_marker( "DN_E " ), translate_marker( "east and below" )}; - result[BELOWSOUTHEAST] = pair_t {translate_marker( "DN_SE" ), translate_marker( "southeast and below" )}; - result[BELOWSOUTH] = pair_t {translate_marker( "DN_S " ), translate_marker( "south and below" )}; - result[BELOWSOUTHWEST] = pair_t {translate_marker( "DN_SW" ), translate_marker( "southwest and below" )}; - result[BELOWWEST] = pair_t {translate_marker( "DN_W " ), translate_marker( "west and below" )}; - result[BELOWNORTHWEST] = pair_t {translate_marker( "DN_NW" ), translate_marker( "northwest and below" )}; - result[ABOVECENTER] = pair_t {translate_marker( "UP_CE" ), translate_marker( "above" )}; - result[CENTER] = pair_t {translate_marker( "CE " ), translate_marker( "center" )}; - result[BELOWCENTER] = pair_t {translate_marker( "DN_CE" ), translate_marker( "below" )}; + result[static_cast( direction::NORTH )] = pair_t {translate_marker( "N " ), translate_marker( "north" )}; + result[static_cast( direction::NORTHEAST )] = pair_t {translate_marker( "NE " ), translate_marker( "northeast" )}; + result[static_cast( direction::EAST )] = pair_t {translate_marker( "E " ), translate_marker( "east" )}; + result[static_cast( direction::SOUTHEAST )] = pair_t {translate_marker( "SE " ), translate_marker( "southeast" )}; + result[static_cast( direction::SOUTH )] = pair_t {translate_marker( "S " ), translate_marker( "south" )}; + result[static_cast( direction::SOUTHWEST )] = pair_t {translate_marker( "SW " ), translate_marker( "southwest" )}; + result[static_cast( direction::WEST )] = pair_t {translate_marker( "W " ), translate_marker( "west" )}; + result[static_cast( direction::NORTHWEST )] = pair_t {translate_marker( "NW " ), translate_marker( "northwest" )}; + result[static_cast( direction::ABOVENORTH )] = pair_t {translate_marker( "UP_N " ), translate_marker( "north and above" )}; + result[static_cast( direction::ABOVENORTHEAST )] = pair_t {translate_marker( "UP_NE" ), translate_marker( "northeast and above" )}; + result[static_cast( direction::ABOVEEAST )] = pair_t {translate_marker( "UP_E " ), translate_marker( "east and above" )}; + result[static_cast( direction::ABOVESOUTHEAST )] = pair_t {translate_marker( "UP_SE" ), translate_marker( "southeast and above" )}; + result[static_cast( direction::ABOVESOUTH )] = pair_t {translate_marker( "UP_S " ), translate_marker( "south and above" )}; + result[static_cast( direction::ABOVESOUTHWEST )] = pair_t {translate_marker( "UP_SW" ), translate_marker( "southwest and above" )}; + result[static_cast( direction::ABOVEWEST )] = pair_t {translate_marker( "UP_W " ), translate_marker( "west and above" )}; + result[static_cast( direction::ABOVENORTHWEST )] = pair_t {translate_marker( "UP_NW" ), translate_marker( "northwest and above" )}; + result[static_cast( direction::BELOWNORTH )] = pair_t {translate_marker( "DN_N " ), translate_marker( "north and below" )}; + result[static_cast( direction::BELOWNORTHEAST )] = pair_t {translate_marker( "DN_NE" ), translate_marker( "northeast and below" )}; + result[static_cast( direction::BELOWEAST )] = pair_t {translate_marker( "DN_E " ), translate_marker( "east and below" )}; + result[static_cast( direction::BELOWSOUTHEAST )] = pair_t {translate_marker( "DN_SE" ), translate_marker( "southeast and below" )}; + result[static_cast( direction::BELOWSOUTH )] = pair_t {translate_marker( "DN_S " ), translate_marker( "south and below" )}; + result[static_cast( direction::BELOWSOUTHWEST )] = pair_t {translate_marker( "DN_SW" ), translate_marker( "southwest and below" )}; + result[static_cast( direction::BELOWWEST )] = pair_t {translate_marker( "DN_W " ), translate_marker( "west and below" )}; + result[static_cast( direction::BELOWNORTHWEST )] = pair_t {translate_marker( "DN_NW" ), translate_marker( "northwest and below" )}; + result[static_cast( direction::ABOVECENTER )] = pair_t {translate_marker( "UP_CE" ), translate_marker( "above" )}; + result[static_cast( direction::CENTER )] = pair_t {translate_marker( "CE " ), translate_marker( "center" )}; + result[static_cast( direction::BELOWCENTER )] = pair_t {translate_marker( "DN_CE" ), translate_marker( "below" )}; result[size] = pair_t {"BUG. (line.cpp:direction_name)", "BUG. (line.cpp:direction_name)"}; return result; diff --git a/src/line.h b/src/line.h index 43f4b1377a733..86b17872b6ff0 100644 --- a/src/line.h +++ b/src/line.h @@ -50,7 +50,7 @@ inline constexpr unsigned make_xyz_unit( const int x, const int y, const int z ) // This more general version of this function gives correct values for larger inputs. unsigned make_xyz( const tripoint & ); -enum direction : unsigned { +enum class direction : unsigned { ABOVENORTHWEST = make_xyz_unit( -1, -1, -1 ), NORTHWEST = make_xyz_unit( -1, -1, 0 ), BELOWNORTHWEST = make_xyz_unit( -1, -1, 1 ), @@ -82,6 +82,42 @@ enum direction : unsigned { BELOWSOUTHEAST = make_xyz_unit( 1, 1, 1 ), }; +template< class T > +constexpr inline direction operator%( const direction &lhs, const T &rhs ) +{ + return static_cast( static_cast( lhs ) % rhs ); +} + +template< class T > +constexpr inline T operator+( const direction &lhs, const T &rhs ) +{ + return static_cast( lhs ) + rhs; +} + +template< class T > +constexpr inline bool operator==( const direction &lhs, const T &rhs ) +{ + return static_cast( lhs ) == rhs; +} + +template< class T > +constexpr inline bool operator==( const T &lhs, const direction &rhs ) +{ + return operator==( rhs, lhs ); +} + +template< class T > +constexpr inline bool operator!=( const T &lhs, const direction &rhs ) +{ + return !operator==( rhs, lhs ); +} + +template< class T > +constexpr inline bool operator!=( const direction &lhs, const T &rhs ) +{ + return !operator==( lhs, rhs ); +} + direction direction_from( const point &p ) noexcept; direction direction_from( const tripoint &p ) noexcept; direction direction_from( const point &p1, const point &p2 ) noexcept; diff --git a/src/map.cpp b/src/map.cpp index c68a1d3c71de2..d324d04397d25 100755 --- a/src/map.cpp +++ b/src/map.cpp @@ -2426,16 +2426,16 @@ bool map::is_last_ter_wall( const bool no_furn, const point &p, int xmov = 0; int ymov = 0; switch( dir ) { - case NORTH: + case direction::NORTH: ymov = -1; break; - case SOUTH: + case direction::SOUTH: ymov = 1; break; - case WEST: + case direction::WEST: xmov = -1; break; - case EAST: + case direction::EAST: xmov = 1; break; default: @@ -2445,10 +2445,10 @@ bool map::is_last_ter_wall( const bool no_furn, const point &p, int y2 = p.y; bool result = true; bool loop = true; - while( ( loop ) && ( ( dir == NORTH && y2 >= 0 ) || - ( dir == SOUTH && y2 < max.y ) || - ( dir == WEST && x2 >= 0 ) || - ( dir == EAST && x2 < max.x ) ) ) { + while( ( loop ) && ( ( dir == direction::NORTH && y2 >= 0 ) || + ( dir == direction::SOUTH && y2 < max.y ) || + ( dir == direction::WEST && x2 >= 0 ) || + ( dir == direction::EAST && x2 < max.x ) ) ) { if( no_furn && has_furn( point( x2, y2 ) ) ) { loop = false; result = false; diff --git a/src/map.h b/src/map.h index 92fed42ea3429..c94f332693146 100644 --- a/src/map.h +++ b/src/map.h @@ -26,6 +26,7 @@ #include "item.h" #include "item_stack.h" #include "lightmap.h" +#include "line.h" #include "lru_cache.h" #include "mapdata.h" #include "point.h" @@ -65,7 +66,6 @@ struct partial_con; struct rl_vec2d; struct trap; -enum direction : unsigned; enum class special_item_type : int; using itype_id = std::string; class npc_template; diff --git a/src/map_extras.cpp b/src/map_extras.cpp index d12d1c160bfbf..838f0ad3f12c6 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -1574,24 +1574,24 @@ static bool mx_fumarole( map &m, const tripoint &abs_sub ) // Pick a random cardinal direction to also spawn lava in // This will make the lava a single connected line, not just on diagonals std::vector possibilities; - possibilities.push_back( EAST ); - possibilities.push_back( WEST ); - possibilities.push_back( NORTH ); - possibilities.push_back( SOUTH ); + possibilities.push_back( direction::EAST ); + possibilities.push_back( direction::WEST ); + possibilities.push_back( direction::NORTH ); + possibilities.push_back( direction::SOUTH ); const direction extra_lava_dir = random_entry( possibilities ); int x_extra = 0; int y_extra = 0; switch( extra_lava_dir ) { - case NORTH: + case direction::NORTH: y_extra = -1; break; - case EAST: + case direction::EAST: x_extra = 1; break; - case SOUTH: + case direction::SOUTH: y_extra = 1; break; - case WEST: + case direction::WEST: x_extra = -1; break; default: @@ -1677,21 +1677,21 @@ static bool mx_portal_in( map &m, const tripoint &abs_sub ) x2 = rng( SEEX, SEEX * 2 - 3 ), y2 = rng( SEEY, SEEY * 2 - 3 ); // Pick a random cardinal direction to also spawn lava in // This will make the lava a single connected line, not just on diagonals - static const std::array possibilities = { { EAST, WEST, NORTH, SOUTH } }; + static const std::array possibilities = { { direction::EAST, direction::WEST, direction::NORTH, direction::SOUTH } }; const direction extra_lava_dir = random_entry( possibilities ); int x_extra = 0; int y_extra = 0; switch( extra_lava_dir ) { - case NORTH: + case direction::NORTH: y_extra = -1; break; - case EAST: + case direction::EAST: x_extra = 1; break; - case SOUTH: + case direction::SOUTH: y_extra = 1; break; - case WEST: + case direction::WEST: x_extra = -1; break; default: diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 8d4835fbbad92..87f89638fdf06 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -4851,16 +4851,16 @@ void map::draw_mine( mapgendata &dat ) for( int i = 0; i < num_worms; i++ ) { std::vector sides; if( dat.n_fac == 6 ) { - sides.push_back( NORTH ); + sides.push_back( direction::NORTH ); } if( dat.e_fac == 6 ) { - sides.push_back( EAST ); + sides.push_back( direction::EAST ); } if( dat.s_fac == 6 ) { - sides.push_back( SOUTH ); + sides.push_back( direction::SOUTH ); } if( dat.w_fac == 6 ) { - sides.push_back( WEST ); + sides.push_back( direction::WEST ); } if( sides.empty() ) { place_spawns( GROUP_DARK_WYRM, 1, point( SEEX, SEEY ), point( SEEX, SEEY ), 1, true ); @@ -4868,16 +4868,16 @@ void map::draw_mine( mapgendata &dat ) } else { point p; switch( random_entry( sides ) ) { - case NORTH: + case direction::NORTH: p = point( rng( 1, SEEX * 2 - 2 ), rng( 1, 5 ) ); break; - case EAST: + case direction::EAST: p = point( SEEX * 2 - rng( 2, 6 ), rng( 1, SEEY * 2 - 2 ) ); break; - case SOUTH: + case direction::SOUTH: p = point( rng( 1, SEEX * 2 - 2 ), SEEY * 2 - rng( 2, 6 ) ); break; - case WEST: + case direction::WEST: p = point( rng( 1, 5 ), rng( 1, SEEY * 2 - 2 ) ); break; default: @@ -4908,16 +4908,16 @@ void map::draw_mine( mapgendata &dat ) if( terrain_type == "mine_down" ) { // Don't forget to build a slope down! std::vector open; if( dat.n_fac == 4 ) { - open.push_back( NORTH ); + open.push_back( direction::NORTH ); } if( dat.e_fac == 4 ) { - open.push_back( EAST ); + open.push_back( direction::EAST ); } if( dat.s_fac == 4 ) { - open.push_back( SOUTH ); + open.push_back( direction::SOUTH ); } if( dat.w_fac == 4 ) { - open.push_back( WEST ); + open.push_back( direction::WEST ); } if( open.empty() ) { // We'll have to build it in the center @@ -4946,19 +4946,19 @@ void map::draw_mine( mapgendata &dat ) square( this, t_slope_down, p + point( 1, 1 ), p + point( 2, 2 ) ); } else { // We can build against a wall switch( random_entry( open ) ) { - case NORTH: + case direction::NORTH: square( this, t_rock_floor, point( SEEX - 3, 6 ), point( SEEX + 2, SEEY ) ); line( this, t_slope_down, point( SEEX - 2, 6 ), point( SEEX + 1, 6 ) ); break; - case EAST: + case direction::EAST: square( this, t_rock_floor, point( SEEX + 1, SEEY - 3 ), point( SEEX * 2 - 7, SEEY + 2 ) ); line( this, t_slope_down, point( SEEX * 2 - 7, SEEY - 2 ), point( SEEX * 2 - 7, SEEY + 1 ) ); break; - case SOUTH: + case direction::SOUTH: square( this, t_rock_floor, point( SEEX - 3, SEEY + 1 ), point( SEEX + 2, SEEY * 2 - 7 ) ); line( this, t_slope_down, point( SEEX - 2, SEEY * 2 - 7 ), point( SEEX + 1, SEEY * 2 - 7 ) ); break; - case WEST: + case direction::WEST: square( this, t_rock_floor, point( 6, SEEY - 3 ), point( SEEX, SEEY + 2 ) ); line( this, t_slope_down, point( 6, SEEY - 2 ), point( 6, SEEY + 1 ) ); break; @@ -4971,16 +4971,16 @@ void map::draw_mine( mapgendata &dat ) if( dat.above() == "mine_down" ) { // Don't forget to build a slope up! std::vector open; if( dat.n_fac == 6 && ter( point( SEEX, 6 ) ) != t_slope_down ) { - open.push_back( NORTH ); + open.push_back( direction::NORTH ); } if( dat.e_fac == 6 && ter( point( SEEX * 2 - 7, SEEY ) ) != t_slope_down ) { - open.push_back( EAST ); + open.push_back( direction::EAST ); } if( dat.s_fac == 6 && ter( point( SEEX, SEEY * 2 - 7 ) ) != t_slope_down ) { - open.push_back( SOUTH ); + open.push_back( direction::SOUTH ); } if( dat.w_fac == 6 && ter( point( 6, SEEY ) ) != t_slope_down ) { - open.push_back( WEST ); + open.push_back( direction::WEST ); } if( open.empty() ) { // We'll have to build it in the center @@ -5010,16 +5010,16 @@ void map::draw_mine( mapgendata &dat ) } else { // We can build against a wall switch( random_entry( open ) ) { - case NORTH: + case direction::NORTH: line( this, t_slope_up, point( SEEX - 2, 6 ), point( SEEX + 1, 6 ) ); break; - case EAST: + case direction::EAST: line( this, t_slope_up, point( SEEX * 2 - 7, SEEY - 2 ), point( SEEX * 2 - 7, SEEY + 1 ) ); break; - case SOUTH: + case direction::SOUTH: line( this, t_slope_up, point( SEEX - 2, SEEY * 2 - 7 ), point( SEEX + 1, SEEY * 2 - 7 ) ); break; - case WEST: + case direction::WEST: line( this, t_slope_up, point( 6, SEEY - 2 ), point( 6, SEEY + 1 ) ); break; default: @@ -5044,25 +5044,25 @@ void map::draw_mine( mapgendata &dat ) if( dat.north() == "mine" ) { square( this, t_rock_floor, point( SEEX, 0 ), point( SEEX + 1, 3 ) ); } else { - face.push_back( NORTH ); + face.push_back( direction::NORTH ); } if( dat.east() == "mine" ) { square( this, t_rock_floor, point( SEEX * 2 - 4, SEEY ), point( EAST_EDGE, SEEY + 1 ) ); } else { - face.push_back( EAST ); + face.push_back( direction::EAST ); } if( dat.south() == "mine" ) { square( this, t_rock_floor, point( SEEX, SEEY * 2 - 4 ), point( SEEX + 1, SOUTH_EDGE ) ); } else { - face.push_back( SOUTH ); + face.push_back( direction::SOUTH ); } if( dat.west() == "mine" ) { square( this, t_rock_floor, point( 0, SEEY ), point( 3, SEEY + 1 ) ); } else { - face.push_back( WEST ); + face.push_back( direction::WEST ); } // Now, pick and generate a type of finale! @@ -5117,19 +5117,19 @@ void map::draw_mine( mapgendata &dat ) case 4: { // Amigara fault // Construct the fault on the appropriate face switch( random_entry( face ) ) { - case NORTH: + case direction::NORTH: square( this, t_rock, point_zero, point( EAST_EDGE, 4 ) ); line( this, t_fault, point( 4, 4 ), point( SEEX * 2 - 5, 4 ) ); break; - case EAST: + case direction::EAST: square( this, t_rock, point( SEEX * 2 - 5, 0 ), point( SOUTH_EDGE, EAST_EDGE ) ); line( this, t_fault, point( SEEX * 2 - 5, 4 ), point( SEEX * 2 - 5, SEEY * 2 - 5 ) ); break; - case SOUTH: + case direction::SOUTH: square( this, t_rock, point( 0, SEEY * 2 - 5 ), point( EAST_EDGE, SOUTH_EDGE ) ); line( this, t_fault, point( 4, SEEY * 2 - 5 ), point( SEEX * 2 - 5, SEEY * 2 - 5 ) ); break; - case WEST: + case direction::WEST: square( this, t_rock, point_zero, point( 4, SOUTH_EDGE ) ); line( this, t_fault, point( 4, 4 ), point( 4, SEEY * 2 - 5 ) ); break; @@ -5555,16 +5555,16 @@ void map::draw_triffid( mapgendata &dat ) // Next, pick a cell to move to std::vector move; if( node % 4 > 0 && !node_built[node - 1] ) { - move.push_back( WEST ); + move.push_back( direction::WEST ); } if( node % 4 < 3 && !node_built[node + 1] ) { - move.push_back( EAST ); + move.push_back( direction::EAST ); } if( static_cast( node / 4 ) > 0 && !node_built[node - 4] ) { - move.push_back( NORTH ); + move.push_back( direction::NORTH ); } if( static_cast( node / 4 ) < 3 && !node_built[node + 4] ) { - move.push_back( SOUTH ); + move.push_back( direction::SOUTH ); } if( move.empty() ) { // Nowhere to go! @@ -5572,19 +5572,19 @@ void map::draw_triffid( mapgendata &dat ) done = true; } else { switch( random_entry( move ) ) { - case NORTH: + case direction::NORTH: square( this, t_dirt, point( nodex + 1, nodey - 2 ), point( nodex + 2, nodey - 1 ) ); node -= 4; break; - case EAST: + case direction::EAST: square( this, t_dirt, point( nodex + 4, nodey + 1 ), point( nodex + 5, nodey + 2 ) ); node++; break; - case SOUTH: + case direction::SOUTH: square( this, t_dirt, point( nodex + 1, nodey + 4 ), point( nodex + 2, nodey + 5 ) ); node += 4; break; - case WEST: + case direction::WEST: square( this, t_dirt, point( nodex - 2, nodey + 1 ), point( nodex - 1, nodey + 2 ) ); node--; break; @@ -6856,47 +6856,47 @@ void build_mine_room( room_type type, int x1, int y1, int x2, int y2, mapgendata std::vector possibilities; int midx = static_cast( ( x1 + x2 ) / 2 ), midy = static_cast( ( y1 + y2 ) / 2 ); if( x2 < SEEX ) { - possibilities.push_back( EAST ); + possibilities.push_back( direction::EAST ); } if( x1 > SEEX + 1 ) { - possibilities.push_back( WEST ); + possibilities.push_back( direction::WEST ); } if( y1 > SEEY + 1 ) { - possibilities.push_back( NORTH ); + possibilities.push_back( direction::NORTH ); } if( y2 < SEEY ) { - possibilities.push_back( SOUTH ); + possibilities.push_back( direction::SOUTH ); } if( possibilities.empty() ) { // We're in the middle of the map! if( midx <= SEEX ) { - possibilities.push_back( EAST ); + possibilities.push_back( direction::EAST ); } else { - possibilities.push_back( WEST ); + possibilities.push_back( direction::WEST ); } if( midy <= SEEY ) { - possibilities.push_back( SOUTH ); + possibilities.push_back( direction::SOUTH ); } else { - possibilities.push_back( NORTH ); + possibilities.push_back( direction::NORTH ); } } const direction door_side = random_entry( possibilities ); point door_point; switch( door_side ) { - case NORTH: + case direction::NORTH: door_point.x = midx; door_point.y = y1; break; - case EAST: + case direction::EAST: door_point.x = x2; door_point.y = midy; break; - case SOUTH: + case direction::SOUTH: door_point.x = midx; door_point.y = y2; break; - case WEST: + case direction::WEST: door_point.x = x1; door_point.y = midy; break; @@ -6939,13 +6939,13 @@ void build_mine_room( room_type type, int x1, int y1, int x2, int y2, mapgendata case room_mine_fuel: { int spacing = rng( 2, 4 ); - if( door_side == NORTH || door_side == SOUTH ) { - int y = ( door_side == NORTH ? y1 + 2 : y2 - 2 ); + if( door_side == direction::NORTH || door_side == direction::SOUTH ) { + int y = ( door_side == direction::NORTH ? y1 + 2 : y2 - 2 ); for( int x = x1 + 1; x <= x2 - 1; x += spacing ) { m->place_gas_pump( point( x, y ), rng( 10000, 50000 ) ); } } else { - int x = ( door_side == EAST ? x2 - 2 : x1 + 2 ); + int x = ( door_side == direction::EAST ? x2 - 2 : x1 + 2 ); for( int y = y1 + 1; y <= y2 - 1; y += spacing ) { m->place_gas_pump( point( x, y ), rng( 10000, 50000 ) ); } @@ -6954,7 +6954,7 @@ void build_mine_room( room_type type, int x1, int y1, int x2, int y2, mapgendata break; case room_mine_housing: - if( door_side == NORTH || door_side == SOUTH ) { + if( door_side == direction::NORTH || door_side == direction::SOUTH ) { for( int y = y1 + 2; y <= y2 - 2; y += 2 ) { m->ter_set( point( x1, y ), t_window ); m->furn_set( point( x1 + 1, y ), f_bed ); @@ -7011,16 +7011,16 @@ void build_mine_room( room_type type, int x1, int y1, int x2, int y2, mapgendata if( type == room_mine_fuel ) { // Fuel stations are open on one side switch( door_side ) { - case NORTH: + case direction::NORTH: line( m, t_floor, point( x1, y1 ), point( x2, y1 ) ); break; - case EAST: + case direction::EAST: line( m, t_floor, point( x2, y1 + 1 ), point( x2, y2 - 1 ) ); break; - case SOUTH: + case direction::SOUTH: line( m, t_floor, point( x1, y2 ), point( x2, y2 ) ); break; - case WEST: + case direction::WEST: line( m, t_floor, point( x1, y1 + 1 ), point( x1, y2 - 1 ) ); break; default: diff --git a/src/mission_start.cpp b/src/mission_start.cpp index 2b312a689829b..2165d87212332 100644 --- a/src/mission_start.cpp +++ b/src/mission_start.cpp @@ -156,10 +156,10 @@ static tripoint find_potential_computer_point( const tinymap &compmap ) } } if( wall == 5 ) { - if( compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), NORTH ) && - compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), SOUTH ) && - compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), WEST ) && - compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), EAST ) ) { + if( compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), direction::NORTH ) && + compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), direction::SOUTH ) && + compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), direction::WEST ) && + compmap.is_last_ter_wall( true, p.xy(), point( SEEX * 2, SEEY * 2 ), direction::EAST ) ) { potential.emplace_back( p ); } } diff --git a/src/npc.h b/src/npc.h index 177ffbf2650c2..17be0d73cc621 100644 --- a/src/npc.h +++ b/src/npc.h @@ -527,8 +527,8 @@ struct dangerous_sound { int volume; }; -const direction npc_threat_dir[8] = { NORTHWEST, NORTH, NORTHEAST, EAST, - SOUTHEAST, SOUTH, SOUTHWEST, WEST +const direction npc_threat_dir[8] = { direction::NORTHWEST, direction::NORTH, direction::NORTHEAST, direction::EAST, + direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST }; struct healing_options { diff --git a/src/output.cpp b/src/output.cpp index cad0ebffb801b..59fdc0e6f2eef 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -1883,14 +1883,14 @@ scrollingcombattext::cSCT::cSCT( const point &p_pos, const direction p_oDir, #if defined(TILES) iso_mode = tile_iso && use_tiles; #endif - oUp = iso_mode ? NORTHEAST : NORTH; - oUpRight = iso_mode ? EAST : NORTHEAST; - oRight = iso_mode ? SOUTHEAST : EAST; - oDownRight = iso_mode ? SOUTH : SOUTHEAST; - oDown = iso_mode ? SOUTHWEST : SOUTH; - oDownLeft = iso_mode ? WEST : SOUTHWEST; - oLeft = iso_mode ? NORTHWEST : WEST; - oUpLeft = iso_mode ? NORTH : NORTHWEST; + oUp = iso_mode ? direction::NORTHEAST : direction::NORTH; + oUpRight = iso_mode ? direction::EAST : direction::NORTHEAST; + oRight = iso_mode ? direction::SOUTHEAST : direction::EAST; + oDownRight = iso_mode ? direction::SOUTH : direction::SOUTHEAST; + oDown = iso_mode ? direction::SOUTHWEST : direction::SOUTH; + oDownLeft = iso_mode ? direction::WEST : direction::SOUTHWEST; + oLeft = iso_mode ? direction::NORTHWEST : direction::WEST; + oUpLeft = iso_mode ? direction::NORTH : direction::NORTHWEST; point pairDirXY = direction_XY( oDir ); @@ -1898,7 +1898,7 @@ scrollingcombattext::cSCT::cSCT( const point &p_pos, const direction p_oDir, if( dir == point_zero ) { // This would cause infinite loop otherwise - oDir = WEST; + oDir = direction::WEST; dir.x = -1; } @@ -1933,26 +1933,29 @@ void scrollingcombattext::add( const point &pos, direction p_oDir, //Remove old HP bar removeCreatureHP(); - if( p_oDir == WEST || p_oDir == NORTHWEST || p_oDir == ( iso_mode ? NORTH : SOUTHWEST ) ) { - p_oDir = ( iso_mode ? NORTHWEST : WEST ); + if( p_oDir == direction::WEST || p_oDir == direction::NORTHWEST || + p_oDir == ( iso_mode ? direction::NORTH : direction::SOUTHWEST ) ) { + p_oDir = ( iso_mode ? direction::NORTHWEST : direction::WEST ); } else { - p_oDir = ( iso_mode ? SOUTHEAST : EAST ); + p_oDir = ( iso_mode ? direction::SOUTHEAST : direction::EAST ); } } else { //reserve Left/Right for creature hp display - if( p_oDir == ( iso_mode ? SOUTHEAST : EAST ) ) { - p_oDir = ( one_in( 2 ) ) ? ( iso_mode ? EAST : NORTHEAST ) : ( iso_mode ? SOUTH : SOUTHEAST ); + if( p_oDir == ( iso_mode ? direction::SOUTHEAST : direction::EAST ) ) { + p_oDir = ( one_in( 2 ) ) ? ( iso_mode ? direction::EAST : direction::NORTHEAST ) : + ( iso_mode ? direction::SOUTH : direction::SOUTHEAST ); - } else if( p_oDir == ( iso_mode ? NORTHWEST : WEST ) ) { - p_oDir = ( one_in( 2 ) ) ? ( iso_mode ? NORTH : NORTHWEST ) : ( iso_mode ? WEST : SOUTHWEST ); + } else if( p_oDir == ( iso_mode ? direction::NORTHWEST : direction::WEST ) ) { + p_oDir = ( one_in( 2 ) ) ? ( iso_mode ? direction::NORTH : direction::NORTHWEST ) : + ( iso_mode ? direction::WEST : direction::SOUTHWEST ); } } // in tiles, SCT that scroll downwards are inserted at the beginning of the vector to prevent // oversize ASCII tiles overdrawing messages below them. - if( tiled && ( p_oDir == SOUTHWEST || p_oDir == SOUTH || - p_oDir == ( iso_mode ? WEST : SOUTHEAST ) ) ) { + if( tiled && ( p_oDir == direction::SOUTHWEST || p_oDir == direction::SOUTH || + p_oDir == ( iso_mode ? direction::WEST : direction::SOUTHEAST ) ) ) { //Message offset: multiple impacts in the same direction in short order overriding prior messages (mostly turrets) for( auto &iter : vSCT ) { diff --git a/src/output.h b/src/output.h index 09439aa99466e..71aa229a4a832 100644 --- a/src/output.h +++ b/src/output.h @@ -19,6 +19,7 @@ #include "debug.h" #include "enums.h" #include "item.h" +#include "line.h" #include "point.h" #include "string_formatter.h" #include "translations.h" @@ -26,7 +27,6 @@ struct input_event; -enum direction : unsigned; namespace catacurses { class window; @@ -839,7 +839,14 @@ class scrollingcombattext private: point pos; direction oDir; - direction oUp, oUpRight, oRight, oDownRight, oDown, oDownLeft, oLeft, oUpLeft; + direction oUp; + direction oUpRight; + direction oRight; + direction oDownRight; + direction oDown; + direction oDownLeft; + direction oLeft; + direction oUpLeft; point dir; int iStep; int iStepOffset; diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index a96a0ba0bbffb..87df316713cfb 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -810,28 +810,28 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr std::string marker_sym = " "; switch( direction_from( center.xy(), target.xy() ) ) { - case NORTH: + case direction::NORTH: marker_sym = "^"; break; - case NORTHEAST: + case direction::NORTHEAST: marker_sym = LINE_OOXX_S; break; - case EAST: + case direction::EAST: marker_sym = ">"; break; - case SOUTHEAST: + case direction::SOUTHEAST: marker_sym = LINE_XOOX_S; break; - case SOUTH: + case direction::SOUTH: marker_sym = "v"; break; - case SOUTHWEST: + case direction::SOUTHWEST: marker_sym = LINE_XXOO_S; break; - case WEST: + case direction::WEST: marker_sym = "<"; break; - case NORTHWEST: + case direction::NORTHWEST: marker_sym = LINE_OXXO_S; break; default: diff --git a/src/pickup.cpp b/src/pickup.cpp index a6ad44f3a525f..6070bc05b2d5f 100644 --- a/src/pickup.cpp +++ b/src/pickup.cpp @@ -481,7 +481,7 @@ void Pickup::pick_up( const tripoint &p, int min, from_where get_items_from ) // Recursively pick up adjacent items if that option is on. if( get_option( "AUTO_PICKUP_ADJACENT" ) && g->u.pos() == p ) { //Autopickup adjacent - direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST}; + direction adjacentDir[8] = {direction::NORTH, direction::NORTHEAST, direction::EAST, direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST, direction::NORTHWEST}; for( auto &elem : adjacentDir ) { tripoint apos = tripoint( direction_XY( elem ), 0 ); diff --git a/tests/line_test.cpp b/tests/line_test.cpp index c3bb500e92bf6..2ca9d843e8dd9 100644 --- a/tests/line_test.cpp +++ b/tests/line_test.cpp @@ -136,159 +136,159 @@ TEST_CASE( "Test bounds for mapping x/y/z/ offsets to direction enum" ) { // Test the unit cube, which are the only values this function is valid for. - REQUIRE( make_xyz_unit( -1, -1, -1 ) == ABOVENORTHWEST ); - REQUIRE( make_xyz_unit( -1, -1, 0 ) == NORTHWEST ); - REQUIRE( make_xyz_unit( -1, -1, 1 ) == BELOWNORTHWEST ); - REQUIRE( make_xyz_unit( 0, -1, -1 ) == ABOVENORTH ); - REQUIRE( make_xyz_unit( 0, -1, 0 ) == NORTH ); - REQUIRE( make_xyz_unit( 0, -1, 2 ) == BELOWNORTH ); - REQUIRE( make_xyz_unit( 1, -1, -1 ) == ABOVENORTHEAST ); - REQUIRE( make_xyz_unit( 1, -1, 0 ) == NORTHEAST ); - REQUIRE( make_xyz_unit( 1, -1, 1 ) == BELOWNORTHEAST ); - REQUIRE( make_xyz_unit( -1, 0, -1 ) == ABOVEWEST ); - REQUIRE( make_xyz_unit( -1, 0, 0 ) == WEST ); - REQUIRE( make_xyz_unit( -1, 0, 1 ) == BELOWWEST ); - REQUIRE( make_xyz_unit( 0, 0, -1 ) == ABOVECENTER ); - REQUIRE( make_xyz_unit( 0, 0, 0 ) == CENTER ); - REQUIRE( make_xyz_unit( 0, 0, 1 ) == BELOWCENTER ); - REQUIRE( make_xyz_unit( 1, 0, -1 ) == ABOVEEAST ); - REQUIRE( make_xyz_unit( 1, 0, 0 ) == EAST ); - REQUIRE( make_xyz_unit( 1, 0, 1 ) == BELOWEAST ); - REQUIRE( make_xyz_unit( -1, 1, -1 ) == ABOVESOUTHWEST ); - REQUIRE( make_xyz_unit( -1, 1, 0 ) == SOUTHWEST ); - REQUIRE( make_xyz_unit( -1, 1, 1 ) == BELOWSOUTHWEST ); - REQUIRE( make_xyz_unit( 0, 1, -1 ) == ABOVESOUTH ); - REQUIRE( make_xyz_unit( 0, 1, 0 ) == SOUTH ); - REQUIRE( make_xyz_unit( 0, 1, 1 ) == BELOWSOUTH ); - REQUIRE( make_xyz_unit( 1, 1, -1 ) == ABOVESOUTHEAST ); - REQUIRE( make_xyz_unit( 1, 1, 0 ) == SOUTHEAST ); - REQUIRE( make_xyz_unit( 1, 1, 1 ) == BELOWSOUTHEAST ); + REQUIRE( make_xyz_unit( -1, -1, -1 ) == direction::ABOVENORTHWEST ); + REQUIRE( make_xyz_unit( -1, -1, 0 ) == direction::NORTHWEST ); + REQUIRE( make_xyz_unit( -1, -1, 1 ) == direction::BELOWNORTHWEST ); + REQUIRE( make_xyz_unit( 0, -1, -1 ) == direction::ABOVENORTH ); + REQUIRE( make_xyz_unit( 0, -1, 0 ) == direction::NORTH ); + REQUIRE( make_xyz_unit( 0, -1, 2 ) == direction::BELOWNORTH ); + REQUIRE( make_xyz_unit( 1, -1, -1 ) == direction::ABOVENORTHEAST ); + REQUIRE( make_xyz_unit( 1, -1, 0 ) == direction::NORTHEAST ); + REQUIRE( make_xyz_unit( 1, -1, 1 ) == direction::BELOWNORTHEAST ); + REQUIRE( make_xyz_unit( -1, 0, -1 ) == direction::ABOVEWEST ); + REQUIRE( make_xyz_unit( -1, 0, 0 ) == direction::WEST ); + REQUIRE( make_xyz_unit( -1, 0, 1 ) == direction::BELOWWEST ); + REQUIRE( make_xyz_unit( 0, 0, -1 ) == direction::ABOVECENTER ); + REQUIRE( make_xyz_unit( 0, 0, 0 ) == direction::CENTER ); + REQUIRE( make_xyz_unit( 0, 0, 1 ) == direction::BELOWCENTER ); + REQUIRE( make_xyz_unit( 1, 0, -1 ) == direction::ABOVEEAST ); + REQUIRE( make_xyz_unit( 1, 0, 0 ) == direction::EAST ); + REQUIRE( make_xyz_unit( 1, 0, 1 ) == direction::BELOWEAST ); + REQUIRE( make_xyz_unit( -1, 1, -1 ) == direction::ABOVESOUTHWEST ); + REQUIRE( make_xyz_unit( -1, 1, 0 ) == direction::SOUTHWEST ); + REQUIRE( make_xyz_unit( -1, 1, 1 ) == direction::BELOWSOUTHWEST ); + REQUIRE( make_xyz_unit( 0, 1, -1 ) == direction::ABOVESOUTH ); + REQUIRE( make_xyz_unit( 0, 1, 0 ) == direction::SOUTH ); + REQUIRE( make_xyz_unit( 0, 1, 1 ) == direction::BELOWSOUTH ); + REQUIRE( make_xyz_unit( 1, 1, -1 ) == direction::ABOVESOUTHEAST ); + REQUIRE( make_xyz_unit( 1, 1, 0 ) == direction::SOUTHEAST ); + REQUIRE( make_xyz_unit( 1, 1, 1 ) == direction::BELOWSOUTHEAST ); // Test the unit square values at distance 1 and 2. // Test the multiples of 30deg at 60 squares. // Test 22 deg to either side of the cardinal directions. - REQUIRE( make_xyz( tripoint( -1, -1, -1 ) ) == ABOVENORTHWEST ); - REQUIRE( make_xyz( tripoint( -2, -2, -2 ) ) == ABOVENORTHWEST ); - REQUIRE( make_xyz( tripoint( -30, -60, -1 ) ) == ABOVENORTHWEST ); - REQUIRE( make_xyz( tripoint( -60, -60, -1 ) ) == ABOVENORTHWEST ); - REQUIRE( make_xyz( tripoint( -60, -30, -1 ) ) == ABOVENORTHWEST ); - REQUIRE( make_xyz( tripoint_north_west ) == NORTHWEST ); - REQUIRE( make_xyz( tripoint( -2, -2, 0 ) ) == NORTHWEST ); - REQUIRE( make_xyz( tripoint( -60, -60, 0 ) ) == NORTHWEST ); - REQUIRE( make_xyz( tripoint( -1, -1, 1 ) ) == BELOWNORTHWEST ); - REQUIRE( make_xyz( tripoint( -2, -2, 2 ) ) == BELOWNORTHWEST ); - REQUIRE( make_xyz( tripoint( -30, -60, 1 ) ) == BELOWNORTHWEST ); - REQUIRE( make_xyz( tripoint( -60, -60, 1 ) ) == BELOWNORTHWEST ); - REQUIRE( make_xyz( tripoint( -60, -30, 1 ) ) == BELOWNORTHWEST ); - REQUIRE( make_xyz( tripoint( 0, -1, -1 ) ) == ABOVENORTH ); - REQUIRE( make_xyz( tripoint( 0, -2, -2 ) ) == ABOVENORTH ); - REQUIRE( make_xyz( tripoint( -22, -60, -1 ) ) == ABOVENORTH ); - REQUIRE( make_xyz( tripoint( 0, -60, -1 ) ) == ABOVENORTH ); - REQUIRE( make_xyz( tripoint( 22, -60, -1 ) ) == ABOVENORTH ); - REQUIRE( make_xyz( tripoint_north ) == NORTH ); - REQUIRE( make_xyz( tripoint( 0, -2, 0 ) ) == NORTH ); - REQUIRE( make_xyz( tripoint( -22, -60, 0 ) ) == NORTH ); - REQUIRE( make_xyz( tripoint( 0, -60, 0 ) ) == NORTH ); - REQUIRE( make_xyz( tripoint( 22, -60, 0 ) ) == NORTH ); - REQUIRE( make_xyz( tripoint( 0, -1, 1 ) ) == BELOWNORTH ); - REQUIRE( make_xyz( tripoint( 0, -2, 2 ) ) == BELOWNORTH ); - REQUIRE( make_xyz( tripoint( -22, -60, 1 ) ) == BELOWNORTH ); - REQUIRE( make_xyz( tripoint( 0, -60, 1 ) ) == BELOWNORTH ); - REQUIRE( make_xyz( tripoint( 22, -60, 1 ) ) == BELOWNORTH ); - REQUIRE( make_xyz( tripoint( 1, -1, -1 ) ) == ABOVENORTHEAST ); - REQUIRE( make_xyz( tripoint( 2, -2, -2 ) ) == ABOVENORTHEAST ); - REQUIRE( make_xyz( tripoint( 30, -60, -1 ) ) == ABOVENORTHEAST ); - REQUIRE( make_xyz( tripoint( 60, -60, -1 ) ) == ABOVENORTHEAST ); - REQUIRE( make_xyz( tripoint( 60, -30, -1 ) ) == ABOVENORTHEAST ); - REQUIRE( make_xyz( tripoint_north_east ) == NORTHEAST ); - REQUIRE( make_xyz( tripoint( 2, -2, 0 ) ) == NORTHEAST ); - REQUIRE( make_xyz( tripoint( 30, -60, 0 ) ) == NORTHEAST ); - REQUIRE( make_xyz( tripoint( 60, -60, 0 ) ) == NORTHEAST ); - REQUIRE( make_xyz( tripoint( 60, -30, 0 ) ) == NORTHEAST ); - REQUIRE( make_xyz( tripoint( 1, -1, 1 ) ) == BELOWNORTHEAST ); - REQUIRE( make_xyz( tripoint( 2, -2, 2 ) ) == BELOWNORTHEAST ); - REQUIRE( make_xyz( tripoint( 30, -60, 1 ) ) == BELOWNORTHEAST ); - REQUIRE( make_xyz( tripoint( 60, -60, 1 ) ) == BELOWNORTHEAST ); - REQUIRE( make_xyz( tripoint( 60, -30, 1 ) ) == BELOWNORTHEAST ); - - REQUIRE( make_xyz( tripoint( -1, 0, -1 ) ) == ABOVEWEST ); - REQUIRE( make_xyz( tripoint( -2, 0, -2 ) ) == ABOVEWEST ); - REQUIRE( make_xyz( tripoint( -60, -22, -1 ) ) == ABOVEWEST ); - REQUIRE( make_xyz( tripoint( -60, 0, -1 ) ) == ABOVEWEST ); - REQUIRE( make_xyz( tripoint( -60, 22, -1 ) ) == ABOVEWEST ); - REQUIRE( make_xyz( tripoint_west ) == WEST ); - REQUIRE( make_xyz( tripoint( -2, 0, 0 ) ) == WEST ); - REQUIRE( make_xyz( tripoint( -60, -22, 0 ) ) == WEST ); - REQUIRE( make_xyz( tripoint( -60, 0, 0 ) ) == WEST ); - REQUIRE( make_xyz( tripoint( -60, 22, 0 ) ) == WEST ); - REQUIRE( make_xyz( tripoint( -1, 0, 1 ) ) == BELOWWEST ); - REQUIRE( make_xyz( tripoint( -2, 0, 2 ) ) == BELOWWEST ); - REQUIRE( make_xyz( tripoint( -60, -22, 1 ) ) == BELOWWEST ); - REQUIRE( make_xyz( tripoint( -60, 0, 1 ) ) == BELOWWEST ); - REQUIRE( make_xyz( tripoint( -60, 22, 1 ) ) == BELOWWEST ); - REQUIRE( make_xyz( tripoint_below ) == ABOVECENTER ); - REQUIRE( make_xyz( tripoint( 0, 0, -2 ) ) == ABOVECENTER ); - REQUIRE( make_xyz( tripoint_zero ) == CENTER ); - REQUIRE( make_xyz( tripoint_above ) == BELOWCENTER ); - REQUIRE( make_xyz( tripoint( 0, 0, 2 ) ) == BELOWCENTER ); - REQUIRE( make_xyz( tripoint( 1, 0, -1 ) ) == ABOVEEAST ); - REQUIRE( make_xyz( tripoint( 2, 0, -2 ) ) == ABOVEEAST ); - REQUIRE( make_xyz( tripoint( 60, -22, -1 ) ) == ABOVEEAST ); - REQUIRE( make_xyz( tripoint( 60, 0, -1 ) ) == ABOVEEAST ); - REQUIRE( make_xyz( tripoint( 60, 22, -1 ) ) == ABOVEEAST ); - REQUIRE( make_xyz( tripoint_east ) == EAST ); - REQUIRE( make_xyz( tripoint( 2, 0, 0 ) ) == EAST ); - REQUIRE( make_xyz( tripoint( 60, -22, 0 ) ) == EAST ); - REQUIRE( make_xyz( tripoint( 60, 0, 0 ) ) == EAST ); - REQUIRE( make_xyz( tripoint( 60, 22, 0 ) ) == EAST ); - REQUIRE( make_xyz( tripoint( 1, 0, 1 ) ) == BELOWEAST ); - REQUIRE( make_xyz( tripoint( 2, 0, 2 ) ) == BELOWEAST ); - REQUIRE( make_xyz( tripoint( 60, -22, 1 ) ) == BELOWEAST ); - REQUIRE( make_xyz( tripoint( 60, 0, 1 ) ) == BELOWEAST ); - REQUIRE( make_xyz( tripoint( 60, 22, 1 ) ) == BELOWEAST ); - - REQUIRE( make_xyz( tripoint( -1, 1, -1 ) ) == ABOVESOUTHWEST ); - REQUIRE( make_xyz( tripoint( -2, 2, -2 ) ) == ABOVESOUTHWEST ); - REQUIRE( make_xyz( tripoint( -30, 60, -1 ) ) == ABOVESOUTHWEST ); - REQUIRE( make_xyz( tripoint( -60, 60, -1 ) ) == ABOVESOUTHWEST ); - REQUIRE( make_xyz( tripoint( -60, 30, -1 ) ) == ABOVESOUTHWEST ); - REQUIRE( make_xyz( tripoint_south_west ) == SOUTHWEST ); - REQUIRE( make_xyz( tripoint( -2, 2, 0 ) ) == SOUTHWEST ); - REQUIRE( make_xyz( tripoint( -30, 60, 0 ) ) == SOUTHWEST ); - REQUIRE( make_xyz( tripoint( -60, 60, 0 ) ) == SOUTHWEST ); - REQUIRE( make_xyz( tripoint( -60, 30, 0 ) ) == SOUTHWEST ); - REQUIRE( make_xyz( tripoint( -1, 1, 1 ) ) == BELOWSOUTHWEST ); - REQUIRE( make_xyz( tripoint( -2, 2, 2 ) ) == BELOWSOUTHWEST ); - REQUIRE( make_xyz( tripoint( -30, 60, 1 ) ) == BELOWSOUTHWEST ); - REQUIRE( make_xyz( tripoint( -60, 60, 1 ) ) == BELOWSOUTHWEST ); - REQUIRE( make_xyz( tripoint( -60, 30, 1 ) ) == BELOWSOUTHWEST ); - REQUIRE( make_xyz( tripoint( 0, 1, -1 ) ) == ABOVESOUTH ); - REQUIRE( make_xyz( tripoint( 0, 2, -2 ) ) == ABOVESOUTH ); - REQUIRE( make_xyz( tripoint( 0, 60, -1 ) ) == ABOVESOUTH ); - REQUIRE( make_xyz( tripoint_south ) == SOUTH ); - REQUIRE( make_xyz( tripoint( -22, 60, 0 ) ) == SOUTH ); - REQUIRE( make_xyz( tripoint( 0, 60, 0 ) ) == SOUTH ); - REQUIRE( make_xyz( tripoint( 22, 60, 0 ) ) == SOUTH ); - REQUIRE( make_xyz( tripoint( 0, 1, 1 ) ) == BELOWSOUTH ); - REQUIRE( make_xyz( tripoint( 0, 2, 2 ) ) == BELOWSOUTH ); - REQUIRE( make_xyz( tripoint( -22, 60, 1 ) ) == BELOWSOUTH ); - REQUIRE( make_xyz( tripoint( 0, 60, 1 ) ) == BELOWSOUTH ); - REQUIRE( make_xyz( tripoint( 22, 60, 1 ) ) == BELOWSOUTH ); - REQUIRE( make_xyz( tripoint( 1, 1, -1 ) ) == ABOVESOUTHEAST ); - REQUIRE( make_xyz( tripoint( 2, 2, -2 ) ) == ABOVESOUTHEAST ); - REQUIRE( make_xyz( tripoint( 30, 60, -1 ) ) == ABOVESOUTHEAST ); - REQUIRE( make_xyz( tripoint( 60, 60, -1 ) ) == ABOVESOUTHEAST ); - REQUIRE( make_xyz( tripoint( 60, 30, -1 ) ) == ABOVESOUTHEAST ); - REQUIRE( make_xyz( tripoint_south_east ) == SOUTHEAST ); - REQUIRE( make_xyz( tripoint( 2, 2, 0 ) ) == SOUTHEAST ); - REQUIRE( make_xyz( tripoint( 30, 60, 0 ) ) == SOUTHEAST ); - REQUIRE( make_xyz( tripoint( 60, 60, 0 ) ) == SOUTHEAST ); - REQUIRE( make_xyz( tripoint( 60, 30, 0 ) ) == SOUTHEAST ); - REQUIRE( make_xyz( tripoint( 1, 1, 1 ) ) == BELOWSOUTHEAST ); - REQUIRE( make_xyz( tripoint( 2, 2, 2 ) ) == BELOWSOUTHEAST ); - REQUIRE( make_xyz( tripoint( 30, 60, 1 ) ) == BELOWSOUTHEAST ); - REQUIRE( make_xyz( tripoint( 60, 60, 1 ) ) == BELOWSOUTHEAST ); - REQUIRE( make_xyz( tripoint( 60, 30, 1 ) ) == BELOWSOUTHEAST ); + REQUIRE( make_xyz( tripoint( -1, -1, -1 ) ) == direction::ABOVENORTHWEST ); + REQUIRE( make_xyz( tripoint( -2, -2, -2 ) ) == direction::ABOVENORTHWEST ); + REQUIRE( make_xyz( tripoint( -30, -60, -1 ) ) == direction::ABOVENORTHWEST ); + REQUIRE( make_xyz( tripoint( -60, -60, -1 ) ) == direction::ABOVENORTHWEST ); + REQUIRE( make_xyz( tripoint( -60, -30, -1 ) ) == direction::ABOVENORTHWEST ); + REQUIRE( make_xyz( tripoint_north_west ) == direction::NORTHWEST ); + REQUIRE( make_xyz( tripoint( -2, -2, 0 ) ) == direction::NORTHWEST ); + REQUIRE( make_xyz( tripoint( -60, -60, 0 ) ) == direction::NORTHWEST ); + REQUIRE( make_xyz( tripoint( -1, -1, 1 ) ) == direction::BELOWNORTHWEST ); + REQUIRE( make_xyz( tripoint( -2, -2, 2 ) ) == direction::BELOWNORTHWEST ); + REQUIRE( make_xyz( tripoint( -30, -60, 1 ) ) == direction::BELOWNORTHWEST ); + REQUIRE( make_xyz( tripoint( -60, -60, 1 ) ) == direction::BELOWNORTHWEST ); + REQUIRE( make_xyz( tripoint( -60, -30, 1 ) ) == direction::BELOWNORTHWEST ); + REQUIRE( make_xyz( tripoint( 0, -1, -1 ) ) == direction::ABOVENORTH ); + REQUIRE( make_xyz( tripoint( 0, -2, -2 ) ) == direction::ABOVENORTH ); + REQUIRE( make_xyz( tripoint( -22, -60, -1 ) ) == direction::ABOVENORTH ); + REQUIRE( make_xyz( tripoint( 0, -60, -1 ) ) == direction::ABOVENORTH ); + REQUIRE( make_xyz( tripoint( 22, -60, -1 ) ) == direction::ABOVENORTH ); + REQUIRE( make_xyz( tripoint_north ) == direction::NORTH ); + REQUIRE( make_xyz( tripoint( 0, -2, 0 ) ) == direction::NORTH ); + REQUIRE( make_xyz( tripoint( -22, -60, 0 ) ) == direction::NORTH ); + REQUIRE( make_xyz( tripoint( 0, -60, 0 ) ) == direction::NORTH ); + REQUIRE( make_xyz( tripoint( 22, -60, 0 ) ) == direction::NORTH ); + REQUIRE( make_xyz( tripoint( 0, -1, 1 ) ) == direction::BELOWNORTH ); + REQUIRE( make_xyz( tripoint( 0, -2, 2 ) ) == direction::BELOWNORTH ); + REQUIRE( make_xyz( tripoint( -22, -60, 1 ) ) == direction::BELOWNORTH ); + REQUIRE( make_xyz( tripoint( 0, -60, 1 ) ) == direction::BELOWNORTH ); + REQUIRE( make_xyz( tripoint( 22, -60, 1 ) ) == direction::BELOWNORTH ); + REQUIRE( make_xyz( tripoint( 1, -1, -1 ) ) == direction::ABOVENORTHEAST ); + REQUIRE( make_xyz( tripoint( 2, -2, -2 ) ) == direction::ABOVENORTHEAST ); + REQUIRE( make_xyz( tripoint( 30, -60, -1 ) ) == direction::ABOVENORTHEAST ); + REQUIRE( make_xyz( tripoint( 60, -60, -1 ) ) == direction::ABOVENORTHEAST ); + REQUIRE( make_xyz( tripoint( 60, -30, -1 ) ) == direction::ABOVENORTHEAST ); + REQUIRE( make_xyz( tripoint_north_east ) == direction::NORTHEAST ); + REQUIRE( make_xyz( tripoint( 2, -2, 0 ) ) == direction::NORTHEAST ); + REQUIRE( make_xyz( tripoint( 30, -60, 0 ) ) == direction::NORTHEAST ); + REQUIRE( make_xyz( tripoint( 60, -60, 0 ) ) == direction::NORTHEAST ); + REQUIRE( make_xyz( tripoint( 60, -30, 0 ) ) == direction::NORTHEAST ); + REQUIRE( make_xyz( tripoint( 1, -1, 1 ) ) == direction::BELOWNORTHEAST ); + REQUIRE( make_xyz( tripoint( 2, -2, 2 ) ) == direction::BELOWNORTHEAST ); + REQUIRE( make_xyz( tripoint( 30, -60, 1 ) ) == direction::BELOWNORTHEAST ); + REQUIRE( make_xyz( tripoint( 60, -60, 1 ) ) == direction::BELOWNORTHEAST ); + REQUIRE( make_xyz( tripoint( 60, -30, 1 ) ) == direction::BELOWNORTHEAST ); + + REQUIRE( make_xyz( tripoint( -1, 0, -1 ) ) == direction::ABOVEWEST ); + REQUIRE( make_xyz( tripoint( -2, 0, -2 ) ) == direction::ABOVEWEST ); + REQUIRE( make_xyz( tripoint( -60, -22, -1 ) ) == direction::ABOVEWEST ); + REQUIRE( make_xyz( tripoint( -60, 0, -1 ) ) == direction::ABOVEWEST ); + REQUIRE( make_xyz( tripoint( -60, 22, -1 ) ) == direction::ABOVEWEST ); + REQUIRE( make_xyz( tripoint_west ) == direction::WEST ); + REQUIRE( make_xyz( tripoint( -2, 0, 0 ) ) == direction::WEST ); + REQUIRE( make_xyz( tripoint( -60, -22, 0 ) ) == direction::WEST ); + REQUIRE( make_xyz( tripoint( -60, 0, 0 ) ) == direction::WEST ); + REQUIRE( make_xyz( tripoint( -60, 22, 0 ) ) == direction::WEST ); + REQUIRE( make_xyz( tripoint( -1, 0, 1 ) ) == direction::BELOWWEST ); + REQUIRE( make_xyz( tripoint( -2, 0, 2 ) ) == direction::BELOWWEST ); + REQUIRE( make_xyz( tripoint( -60, -22, 1 ) ) == direction::BELOWWEST ); + REQUIRE( make_xyz( tripoint( -60, 0, 1 ) ) == direction::BELOWWEST ); + REQUIRE( make_xyz( tripoint( -60, 22, 1 ) ) == direction::BELOWWEST ); + REQUIRE( make_xyz( tripoint_below ) == direction::ABOVECENTER ); + REQUIRE( make_xyz( tripoint( 0, 0, -2 ) ) == direction::ABOVECENTER ); + REQUIRE( make_xyz( tripoint_zero ) == direction::CENTER ); + REQUIRE( make_xyz( tripoint_above ) == direction::BELOWCENTER ); + REQUIRE( make_xyz( tripoint( 0, 0, 2 ) ) == direction::BELOWCENTER ); + REQUIRE( make_xyz( tripoint( 1, 0, -1 ) ) == direction::ABOVEEAST ); + REQUIRE( make_xyz( tripoint( 2, 0, -2 ) ) == direction::ABOVEEAST ); + REQUIRE( make_xyz( tripoint( 60, -22, -1 ) ) == direction::ABOVEEAST ); + REQUIRE( make_xyz( tripoint( 60, 0, -1 ) ) == direction::ABOVEEAST ); + REQUIRE( make_xyz( tripoint( 60, 22, -1 ) ) == direction::ABOVEEAST ); + REQUIRE( make_xyz( tripoint_east ) == direction::EAST ); + REQUIRE( make_xyz( tripoint( 2, 0, 0 ) ) == direction::EAST ); + REQUIRE( make_xyz( tripoint( 60, -22, 0 ) ) == direction::EAST ); + REQUIRE( make_xyz( tripoint( 60, 0, 0 ) ) == direction::EAST ); + REQUIRE( make_xyz( tripoint( 60, 22, 0 ) ) == direction::EAST ); + REQUIRE( make_xyz( tripoint( 1, 0, 1 ) ) == direction::BELOWEAST ); + REQUIRE( make_xyz( tripoint( 2, 0, 2 ) ) == direction::BELOWEAST ); + REQUIRE( make_xyz( tripoint( 60, -22, 1 ) ) == direction::BELOWEAST ); + REQUIRE( make_xyz( tripoint( 60, 0, 1 ) ) == direction::BELOWEAST ); + REQUIRE( make_xyz( tripoint( 60, 22, 1 ) ) == direction::BELOWEAST ); + + REQUIRE( make_xyz( tripoint( -1, 1, -1 ) ) == direction::ABOVESOUTHWEST ); + REQUIRE( make_xyz( tripoint( -2, 2, -2 ) ) == direction::ABOVESOUTHWEST ); + REQUIRE( make_xyz( tripoint( -30, 60, -1 ) ) == direction::ABOVESOUTHWEST ); + REQUIRE( make_xyz( tripoint( -60, 60, -1 ) ) == direction::ABOVESOUTHWEST ); + REQUIRE( make_xyz( tripoint( -60, 30, -1 ) ) == direction::ABOVESOUTHWEST ); + REQUIRE( make_xyz( tripoint_south_west ) == direction::SOUTHWEST ); + REQUIRE( make_xyz( tripoint( -2, 2, 0 ) ) == direction::SOUTHWEST ); + REQUIRE( make_xyz( tripoint( -30, 60, 0 ) ) == direction::SOUTHWEST ); + REQUIRE( make_xyz( tripoint( -60, 60, 0 ) ) == direction::SOUTHWEST ); + REQUIRE( make_xyz( tripoint( -60, 30, 0 ) ) == direction::SOUTHWEST ); + REQUIRE( make_xyz( tripoint( -1, 1, 1 ) ) == direction::BELOWSOUTHWEST ); + REQUIRE( make_xyz( tripoint( -2, 2, 2 ) ) == direction::BELOWSOUTHWEST ); + REQUIRE( make_xyz( tripoint( -30, 60, 1 ) ) == direction::BELOWSOUTHWEST ); + REQUIRE( make_xyz( tripoint( -60, 60, 1 ) ) == direction::BELOWSOUTHWEST ); + REQUIRE( make_xyz( tripoint( -60, 30, 1 ) ) == direction::BELOWSOUTHWEST ); + REQUIRE( make_xyz( tripoint( 0, 1, -1 ) ) == direction::ABOVESOUTH ); + REQUIRE( make_xyz( tripoint( 0, 2, -2 ) ) == direction::ABOVESOUTH ); + REQUIRE( make_xyz( tripoint( 0, 60, -1 ) ) == direction::ABOVESOUTH ); + REQUIRE( make_xyz( tripoint_south ) == direction::SOUTH ); + REQUIRE( make_xyz( tripoint( -22, 60, 0 ) ) == direction::SOUTH ); + REQUIRE( make_xyz( tripoint( 0, 60, 0 ) ) == direction::SOUTH ); + REQUIRE( make_xyz( tripoint( 22, 60, 0 ) ) == direction::SOUTH ); + REQUIRE( make_xyz( tripoint( 0, 1, 1 ) ) == direction::BELOWSOUTH ); + REQUIRE( make_xyz( tripoint( 0, 2, 2 ) ) == direction::BELOWSOUTH ); + REQUIRE( make_xyz( tripoint( -22, 60, 1 ) ) == direction::BELOWSOUTH ); + REQUIRE( make_xyz( tripoint( 0, 60, 1 ) ) == direction::BELOWSOUTH ); + REQUIRE( make_xyz( tripoint( 22, 60, 1 ) ) == direction::BELOWSOUTH ); + REQUIRE( make_xyz( tripoint( 1, 1, -1 ) ) == direction::ABOVESOUTHEAST ); + REQUIRE( make_xyz( tripoint( 2, 2, -2 ) ) == direction::ABOVESOUTHEAST ); + REQUIRE( make_xyz( tripoint( 30, 60, -1 ) ) == direction::ABOVESOUTHEAST ); + REQUIRE( make_xyz( tripoint( 60, 60, -1 ) ) == direction::ABOVESOUTHEAST ); + REQUIRE( make_xyz( tripoint( 60, 30, -1 ) ) == direction::ABOVESOUTHEAST ); + REQUIRE( make_xyz( tripoint_south_east ) == direction::SOUTHEAST ); + REQUIRE( make_xyz( tripoint( 2, 2, 0 ) ) == direction::SOUTHEAST ); + REQUIRE( make_xyz( tripoint( 30, 60, 0 ) ) == direction::SOUTHEAST ); + REQUIRE( make_xyz( tripoint( 60, 60, 0 ) ) == direction::SOUTHEAST ); + REQUIRE( make_xyz( tripoint( 60, 30, 0 ) ) == direction::SOUTHEAST ); + REQUIRE( make_xyz( tripoint( 1, 1, 1 ) ) == direction::BELOWSOUTHEAST ); + REQUIRE( make_xyz( tripoint( 2, 2, 2 ) ) == direction::BELOWSOUTHEAST ); + REQUIRE( make_xyz( tripoint( 30, 60, 1 ) ) == direction::BELOWSOUTHEAST ); + REQUIRE( make_xyz( tripoint( 60, 60, 1 ) ) == direction::BELOWSOUTHEAST ); + REQUIRE( make_xyz( tripoint( 60, 30, 1 ) ) == direction::BELOWSOUTHEAST ); } TEST_CASE( "squares_closer_to_test" )