From d11b5e0dddc83b95120ffaacea1176ad01ae4208 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Fri, 29 May 2020 11:46:33 +0300 Subject: [PATCH 1/5] Rename usage_from and make it a class enum --- src/basecamp.cpp | 4 +-- src/craft_command.cpp | 68 ++++++++++++++++++++-------------------- src/craft_command.h | 24 +++++++++------ src/crafting.cpp | 72 +++++++++++++++++++++---------------------- 4 files changed, 87 insertions(+), 81 deletions(-) diff --git a/src/basecamp.cpp b/src/basecamp.cpp index 250c62c9aa42c..f3600e8d82b77 100644 --- a/src/basecamp.cpp +++ b/src/basecamp.cpp @@ -724,7 +724,7 @@ bool basecamp_action_components::choose_components() comp_selection is = g->u.select_item_component( it, batch_size_, base_._inv, true, filter, !base_.by_radio ); - if( is.use_from == cancel ) { + if( is.use_from == usage_from::cancel ) { return false; } item_selections_.push_back( is ); @@ -734,7 +734,7 @@ bool basecamp_action_components::choose_components() comp_selection ts = g->u.select_tool_component( it, batch_size_, base_._inv, DEFAULT_HOTKEYS, true, !base_.by_radio ); - if( ts.use_from == cancel ) { + if( ts.use_from == usage_from::cancel ) { return false; } tool_selections_.push_back( ts ); diff --git a/src/craft_command.cpp b/src/craft_command.cpp index 6d83371116554..dccb358556af3 100644 --- a/src/craft_command.cpp +++ b/src/craft_command.cpp @@ -27,15 +27,15 @@ template std::string comp_selection::nname() const { switch( use_from ) { - case use_from_map: + case usage_from::map: return item::nname( comp.type, comp.count ) + _( " (nearby)" ); - case use_from_both: + case usage_from::both: return item::nname( comp.type, comp.count ) + _( " (person & nearby)" ); - case use_from_player: + case usage_from::player: // Is the same as the default return; - case use_from_none: - case cancel: - case num_usages: + case usage_from::none: + case usage_from::cancel: + case usage_from::num_usages_from: break; } @@ -46,17 +46,17 @@ namespace io { template<> -std::string enum_to_string( usage data ) +std::string enum_to_string( usage_from data ) { switch( data ) { // *INDENT-OFF* - case usage::use_from_map: return "map"; - case usage::use_from_player: return "player"; - case usage::use_from_both: return "both"; - case usage::use_from_none: return "none"; - case usage::cancel: return "cancel"; + case usage_from::map: return "map"; + case usage_from::player: return "player"; + case usage_from::both: return "both"; + case usage_from::none: return "none"; + case usage_from::cancel: return "cancel"; // *INDENT-ON* - case usage::num_usages: + case usage_from::num_usages_from: break; } debugmsg( "Invalid usage" ); @@ -84,7 +84,7 @@ void comp_selection::deserialize( JsonIn &jsin ) std::string use_from_str; data.read( "use_from", use_from_str ); - use_from = io::string_to_enum( use_from_str ); + use_from = io::string_to_enum( use_from_str ); data.read( "type", comp.type ); data.read( "count", comp.count ); } @@ -154,7 +154,7 @@ void craft_command::execute( const tripoint &new_loc ) for( const auto &it : needs->get_components() ) { comp_selection is = crafter->select_item_component( it, batch_size, map_inv, true, filter ); - if( is.use_from == cancel ) { + if( is.use_from == usage_from::cancel ) { return; } item_selections.push_back( is ); @@ -166,7 +166,7 @@ void craft_command::execute( const tripoint &new_loc ) it, batch_size, map_inv, DEFAULT_HOTKEYS, true, true, []( int charges ) { return charges / 20 + charges % 20; } ); - if( ts.use_from == cancel ) { + if( ts.use_from == usage_from::cancel ) { return; } tool_selections.push_back( ts ); @@ -296,49 +296,49 @@ std::vector> craft_command::check_item_components_miss if( item::count_by_charges( type ) && count > 0 ) { switch( item_sel.use_from ) { - case use_from_player: + case usage_from::player: if( !crafter->has_charges( type, count, filter ) ) { missing.push_back( item_sel ); } break; - case use_from_map: + case usage_from::map: if( !map_inv.has_charges( type, count, filter ) ) { missing.push_back( item_sel ); } break; - case use_from_both: + case usage_from::both: if( !( crafter->charges_of( type, INT_MAX, filter ) + map_inv.charges_of( type, INT_MAX, filter ) >= count ) ) { missing.push_back( item_sel ); } break; - case use_from_none: - case cancel: - case num_usages: + case usage_from::none: + case usage_from::cancel: + case usage_from::num_usages_from: break; } } else { // Counting by units, not charges. switch( item_sel.use_from ) { - case use_from_player: + case usage_from::player: if( !crafter->has_amount( type, count, false, filter ) ) { missing.push_back( item_sel ); } break; - case use_from_map: + case usage_from::map: if( !map_inv.has_components( type, count, filter ) ) { missing.push_back( item_sel ); } break; - case use_from_both: + case usage_from::both: if( !( crafter->amount_of( type, false, std::numeric_limits::max(), filter ) + map_inv.amount_of( type, false, std::numeric_limits::max(), filter ) >= count ) ) { missing.push_back( item_sel ); } break; - case use_from_none: - case cancel: - case num_usages: + case usage_from::none: + case usage_from::cancel: + case usage_from::num_usages_from: break; } } @@ -357,20 +357,20 @@ std::vector> craft_command::check_tool_components_miss if( tool_sel.comp.count > 0 ) { const int count = tool_sel.comp.count * batch_size; switch( tool_sel.use_from ) { - case use_from_player: + case usage_from::player: if( !crafter->has_charges( type, count ) ) { missing.push_back( tool_sel ); } break; - case use_from_map: + case usage_from::map: if( !map_inv.has_charges( type, count ) ) { missing.push_back( tool_sel ); } break; - case use_from_both: - case use_from_none: - case cancel: - case num_usages: + case usage_from::both: + case usage_from::none: + case usage_from::cancel: + case usage_from::num_usages_from: break; } } else if( !crafter->has_amount( type, 1 ) && !map_inv.has_tools( type, 1 ) ) { diff --git a/src/craft_command.h b/src/craft_command.h index 1c70f8b14d8f0..a99e223670faa 100644 --- a/src/craft_command.h +++ b/src/craft_command.h @@ -20,27 +20,33 @@ template struct enum_traits; /** * enum used by comp_selection to indicate where a component should be consumed from. */ -enum usage { - use_from_none = 0, - use_from_map = 1, - use_from_player = 2, - use_from_both = 1 | 2, +enum class usage_from : int { + none = 0, + map = 1, + player = 2, + both = 1 | 2, cancel = 4, // FIXME: hacky. - num_usages + num_usages_from }; template<> -struct enum_traits { - static constexpr usage last = usage::num_usages; +struct enum_traits { + static constexpr usage_from last = usage_from::num_usages_from; }; +inline bool operator&( usage_from l, usage_from r ) +{ + using I = std::underlying_type_t; + return static_cast( l ) & static_cast( r ); +} + /** * Struct that represents a selection of a component for crafting. */ template struct comp_selection { /** Tells us where the selected component should be used from. */ - usage use_from = use_from_none; + usage_from use_from = usage_from::none; CompType comp; /** provides a translated name for 'comp', suffixed with it's location e.g '(nearby)'. */ diff --git a/src/crafting.cpp b/src/crafting.cpp index d17c94a95316e..c10b15bea407b 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -1299,7 +1299,7 @@ bool player::can_continue_craft( item &craft ) std::vector> item_selections; for( const auto &it : continue_reqs.get_components() ) { comp_selection is = select_item_component( it, batch_size, map_inv, true, filter ); - if( is.use_from == cancel ) { + if( is.use_from == usage_from::cancel ) { cancel_activity(); add_msg( _( "You stop crafting." ) ); return false; @@ -1352,7 +1352,7 @@ bool player::can_continue_craft( item &craft ) map_inv, DEFAULT_HOTKEYS, true, true, []( int charges ) { return charges / 20; } ); - if( selection.use_from == cancel ) { + if( selection.use_from == usage_from::cancel ) { return false; } new_tool_selections.push_back( selection ); @@ -1416,7 +1416,7 @@ comp_selection player::select_item_component( const std::vector player::select_item_component( const std::vector player::select_item_component( const std::vector player::select_item_component( const std::vector( cmenu.ret ) >= map_has.size() + player_has.size() + mixed.size() ) { - selected.use_from = cancel; + selected.use_from = usage_from::cancel; return selected; } size_t uselection = static_cast( cmenu.ret ); if( uselection < map_has.size() ) { - selected.use_from = usage::use_from_map; + selected.use_from = usage_from::map; selected.comp = map_has[uselection]; } else if( uselection < map_has.size() + player_has.size() ) { uselection -= map_has.size(); - selected.use_from = usage::use_from_player; + selected.use_from = usage_from::player; selected.comp = player_has[uselection]; } else { uselection -= map_has.size() + player_has.size(); - selected.use_from = usage::use_from_both; + selected.use_from = usage_from::both; selected.comp = mixed[uselection]; } } @@ -1609,7 +1609,7 @@ std::list player::consume_items( map &m, const comp_selection & int real_count = ( selected_comp.count > 0 ) ? selected_comp.count * batch : std::abs( selected_comp.count ); // First try to get everything from the map, than (remaining amount) from player - if( is.use_from & use_from_map ) { + if( is.use_from & usage_from::map ) { if( by_charges ) { std::list tmp = m.use_charges( loc, radius, selected_comp.type, real_count, filter ); ret.splice( ret.end(), tmp ); @@ -1619,7 +1619,7 @@ std::list player::consume_items( map &m, const comp_selection & ret.splice( ret.end(), tmp ); } } - if( is.use_from & use_from_player ) { + if( is.use_from & usage_from::player ) { if( by_charges ) { std::list tmp = use_charges( selected_comp.type, real_count, filter ); ret.splice( ret.end(), tmp ); @@ -1691,27 +1691,27 @@ player::select_tool_component( const std::vector &tools, int batch, i } } if( found_nocharge ) { - selected.use_from = use_from_none; + selected.use_from = usage_from::none; return selected; // Default to using a tool that doesn't require charges } if( player_has.size() + map_has.size() == 1 ) { if( map_has.empty() ) { - selected.use_from = use_from_player; + selected.use_from = usage_from::player; selected.comp = player_has[0]; } else { - selected.use_from = use_from_map; + selected.use_from = usage_from::map; selected.comp = map_has[0]; } } else if( is_npc() ) { if( !player_has.empty() ) { - selected.use_from = use_from_player; + selected.use_from = usage_from::player; selected.comp = player_has[0]; } else if( !map_has.empty() ) { - selected.use_from = use_from_map; + selected.use_from = usage_from::map; selected.comp = map_has[0]; } else { - selected.use_from = use_from_none; + selected.use_from = usage_from::none; return selected; } } else { // Variety of options, list them and pick one @@ -1742,7 +1742,7 @@ player::select_tool_component( const std::vector &tools, int batch, i } if( tmenu.entries.empty() ) { // This SHOULD only happen if cooking with a fire, - selected.use_from = use_from_none; + selected.use_from = usage_from::none; return selected; // and the fire goes out. } @@ -1753,17 +1753,17 @@ player::select_tool_component( const std::vector &tools, int batch, i tmenu.query(); if( tmenu.ret < 0 || static_cast( tmenu.ret ) >= map_has.size() + player_has.size() ) { - selected.use_from = cancel; + selected.use_from = usage_from::cancel; return selected; } size_t uselection = static_cast( tmenu.ret ); if( uselection < map_has.size() ) { - selected.use_from = use_from_map; + selected.use_from = usage_from::map; selected.comp = map_has[uselection]; } else { uselection -= map_has.size(); - selected.use_from = use_from_player; + selected.use_from = usage_from::player; selected.comp = player_has[uselection]; } } @@ -1813,7 +1813,7 @@ bool player::craft_consume_tools( item &craft, int mulitplier, bool start_craft if( tool_sel.comp.count > 0 ) { const int count = calc_charges( tool_sel.comp.count ); switch( tool_sel.use_from ) { - case use_from_player: + case usage_from::player: if( !has_charges( type, count ) ) { add_msg_player_or_npc( _( "You have insufficient %s charges and can't continue crafting" ), @@ -1823,7 +1823,7 @@ bool player::craft_consume_tools( item &craft, int mulitplier, bool start_craft return false; } break; - case use_from_map: + case usage_from::map: if( !map_inv.has_charges( type, count ) ) { add_msg_player_or_npc( _( "You have insufficient %s charges and can't continue crafting" ), @@ -1833,10 +1833,10 @@ bool player::craft_consume_tools( item &craft, int mulitplier, bool start_craft return false; } break; - case use_from_both: - case use_from_none: - case cancel: - case num_usages: + case usage_from::both: + case usage_from::none: + case usage_from::cancel: + case usage_from::num_usages_from: break; } } else if( !has_amount( type, 1 ) && !map_inv.has_tools( type, 1 ) ) { @@ -1873,14 +1873,14 @@ void player::consume_tools( map &m, const comp_selection &tool, int b const itype *tmp = item::find_type( tool.comp.type ); int quantity = tool.comp.count * batch * tmp->charge_factor(); - if( tool.use_from & use_from_player ) { + if( tool.use_from & usage_from::player ) { use_charges( tool.comp.type, quantity ); } - if( tool.use_from & use_from_map ) { + if( tool.use_from & usage_from::map ) { m.use_charges( origin, radius, tool.comp.type, quantity, return_true, bcp ); } - // else, use_from_none (or cancel), so we don't use up any tools; + // else, usage_from::none (or usage_from::cancel), so we don't use up any tools; } /* This call is in-efficient when doing it for multiple items with the same map inventory. From afa1ed9986278fc5f8495bb0e2bbfce1b1401d58 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Fri, 29 May 2020 13:21:35 +0300 Subject: [PATCH 2/5] Rename creature_size and make it a class enum --- src/activity_handlers.cpp | 24 +++--- src/activity_item_handling.cpp | 4 +- src/ballistics.cpp | 6 +- src/character.cpp | 14 ++-- src/character.h | 6 +- src/creature.cpp | 49 ++++++----- src/creature.h | 148 +++++++++++++++++++++++++++++++-- src/explosion.cpp | 4 +- src/game.cpp | 28 +++---- src/item.h | 1 - src/iuse.cpp | 11 +-- src/melee.cpp | 2 +- src/monattack.cpp | 10 +-- src/mondeath.cpp | 12 +-- src/monmove.cpp | 49 +++++------ src/monster.cpp | 38 ++++----- src/monster.h | 2 +- src/monstergenerator.cpp | 12 +-- src/mtype.cpp | 2 +- src/mtype.h | 6 +- src/mutation.cpp | 10 +-- src/player.cpp | 6 +- src/ranged.cpp | 32 +++---- src/trapfunc.cpp | 52 ++++++------ tests/char_biometrics_test.cpp | 30 +++---- tests/creature_test.cpp | 29 ++++--- 26 files changed, 369 insertions(+), 218 deletions(-) diff --git a/src/activity_handlers.cpp b/src/activity_handlers.cpp index aaae1100ff98c..6b81ee9acddfe 100644 --- a/src/activity_handlers.cpp +++ b/src/activity_handlers.cpp @@ -103,6 +103,8 @@ #include "vpart_position.h" #include "weather.h" +enum class creature_size : int; + static const efftype_id effect_sheared( "sheared" ); #define dbg(x) DebugLog((x),D_GAME) << __FILE__ << ":" << __LINE__ << ": " @@ -615,7 +617,7 @@ static void set_up_butchery( player_activity &act, player &u, butcher_type actio u.has_amount( itype_vine_30, 1 ) || u.has_amount( itype_grapnel, 1 ) || u.has_amount( itype_chain, 1 ); - const bool big_corpse = corpse.size >= MS_MEDIUM; + const bool big_corpse = corpse.size >= creature_size::medium; if( big_corpse ) { if( has_rope && !has_tree_nearby && !b_rack_present ) { @@ -667,7 +669,7 @@ static void set_up_butchery( player_activity &act, player &u, butcher_type actio } if( action == butcher_type::QUARTER ) { - if( corpse.size == MS_TINY ) { + if( corpse.size == creature_size::tiny ) { u.add_msg_if_player( m_bad, _( "This corpse is too small to quarter without damaging." ), corpse.nname() ); act.targets.pop_back(); @@ -734,19 +736,19 @@ int butcher_time_to_cut( const player &u, const item &corpse_item, const butcher int time_to_cut = 0; switch( corpse.size ) { // Time (roughly) in turns to cut up the corpse - case MS_TINY: + case creature_size::tiny: time_to_cut = 150; break; - case MS_SMALL: + case creature_size::small: time_to_cut = 300; break; - case MS_MEDIUM: + case creature_size::medium: time_to_cut = 450; break; - case MS_LARGE: + case creature_size::large: time_to_cut = 600; break; - case MS_HUGE: + case creature_size::huge: time_to_cut = 1800; break; } @@ -972,7 +974,7 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player & roll = roll / 4; } else if( entry.type == "bone" ) { roll /= 2; - } else if( corpse_item->get_mtype()->size >= MS_MEDIUM && ( entry.type == "skin" ) ) { + } else if( corpse_item->get_mtype()->size >= creature_size::medium && ( entry.type == "skin" ) ) { roll /= 2; } else if( entry.type == "offal" ) { roll /= 5; @@ -1161,9 +1163,11 @@ static void butchery_drops_harvest( item *corpse_item, const mtype &mt, player & } if( action == butcher_type::DISSECT ) { - p.practice( skill_firstaid, std::max( 0, practice ), std::max( mt.size - MS_MEDIUM, 0 ) + 4 ); + p.practice( skill_firstaid, std::max( 0, practice ), std::max( mt.size - creature_size::medium, + 0 ) + 4 ); } else { - p.practice( skill_survival, std::max( 0, practice ), std::max( mt.size - MS_MEDIUM, 0 ) + 4 ); + p.practice( skill_survival, std::max( 0, practice ), std::max( mt.size - creature_size::medium, + 0 ) + 4 ); } } diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index 42f3d2faa439e..31306d0826e80 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -1262,7 +1262,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe // make sure nobody else is working on that corpse right now if( i.is_corpse() && !i.has_var( "activity_var" ) ) { const mtype corpse = *i.get_mtype(); - if( corpse.size >= MS_MEDIUM ) { + if( corpse.size >= creature_size::medium ) { big_count += 1; } else { small_count += 1; @@ -1888,7 +1888,7 @@ static bool butcher_corpse_activity( player &p, const tripoint &src_loc, for( auto &elem : items ) { if( elem.is_corpse() && !elem.has_var( "activity_var" ) ) { const mtype corpse = *elem.get_mtype(); - if( corpse.size >= MS_MEDIUM && reason != do_activity_reason::NEEDS_BIG_BUTCHERING ) { + if( corpse.size >= creature_size::medium && reason != do_activity_reason::NEEDS_BIG_BUTCHERING ) { continue; } elem.set_var( "activity_var", p.name ); diff --git a/src/ballistics.cpp b/src/ballistics.cpp index d3dd62c2096a9..343720428dc45 100644 --- a/src/ballistics.cpp +++ b/src/ballistics.cpp @@ -92,10 +92,10 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack ) bool embed = mon_there && effects.count( "NO_EMBED" ) == 0 && effects.count( "TANGLE" ) == 0; // Don't embed in small creatures if( embed ) { - const m_size critter_size = mon->get_size(); + const creature_size critter_size = mon->get_size(); const units::volume vol = dropped_item.volume(); - embed = embed && ( critter_size > MS_TINY || vol < 250_ml ); - embed = embed && ( critter_size > MS_SMALL || vol < 500_ml ); + embed = embed && ( critter_size > creature_size::tiny || vol < 250_ml ); + embed = embed && ( critter_size > creature_size::small || vol < 500_ml ); // And if we deal enough damage // Item volume bumps up the required damage too embed = embed && diff --git a/src/character.cpp b/src/character.cpp index c51c4171817fb..f096a6dcc27d8 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -549,7 +549,7 @@ int Character::get_fat_to_hp() const return mut_fat_hp * ( get_bmi() - character_weight_category::normal ); } -m_size Character::get_size() const +creature_size Character::get_size() const { return size_class; } @@ -1123,7 +1123,7 @@ bool Character::check_mount_is_spooked() // / 2 if horse has full tack and saddle. // Monster in spear reach monster and average stat (8) player on saddled horse, 14% -2% -0.8% / 2 = ~5% if( mounted_creature && mounted_creature->type->has_fear_trigger( mon_trigger::HOSTILE_CLOSE ) ) { - const m_size mount_size = mounted_creature->get_size(); + const creature_size mount_size = mounted_creature->get_size(); const bool saddled = mounted_creature->has_effect( effect_monster_saddled ); for( const monster &critter : g->all_monsters() ) { double chance = 1.0; @@ -7155,15 +7155,15 @@ std::string Character::height_string() const int Character::height() const { switch( get_size() ) { - case MS_TINY: + case creature_size::tiny: return init_height - 100; - case MS_SMALL: + case creature_size::small: return init_height - 50; - case MS_MEDIUM: + case creature_size::medium: return init_height; - case MS_LARGE: + case creature_size::large: return init_height + 50; - case MS_HUGE: + case creature_size::huge: return init_height + 100; } diff --git a/src/character.h b/src/character.h index 4fa16f785ad18..1a978c4de94a0 100644 --- a/src/character.h +++ b/src/character.h @@ -459,7 +459,7 @@ class Character : public Creature, public visitable int get_fat_to_hp() const; /** Get size class of character **/ - m_size get_size() const override; + creature_size get_size() const override; /** Returns either "you" or the player's name. capitalize_first assumes that the character's name is already upper case and uses it only for @@ -2246,7 +2246,7 @@ class Character : public Creature, public visitable /**height at character creation*/ int init_height = 175; /** Size class of character. */ - m_size size_class = MS_MEDIUM; + creature_size size_class = creature_size::medium; // the player's activity level for metabolism calculations float activity_level = NO_EXERCISE; @@ -2391,7 +2391,7 @@ class Character : public Creature, public visitable }; // Little size helper, exposed for use in deserialization code. -m_size calculate_size( const Character &c ); +creature_size calculate_size( const Character &c ); template<> struct enum_traits { diff --git a/src/creature.cpp b/src/creature.cpp index 9e633bf0d0b7a..92f9651b463a8 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -64,9 +64,12 @@ static const efftype_id effect_stunned( "stunned" ); static const efftype_id effect_tied( "tied" ); static const efftype_id effect_zapped( "zapped" ); -const std::map Creature::size_map = { - {"TINY", MS_TINY}, {"SMALL", MS_SMALL}, {"MEDIUM", MS_MEDIUM}, - {"LARGE", MS_LARGE}, {"HUGE", MS_HUGE} +const std::map Creature::size_map = { + {"TINY", creature_size::tiny}, + {"SMALL", creature_size::small}, + {"MEDIUM", creature_size::medium}, + {"LARGE", creature_size::large}, + {"HUGE", creature_size::huge} }; const std::set Creature::cmat_flesh{ @@ -239,18 +242,18 @@ bool Creature::sees( const Creature &critter ) const } float size_modifier = 1.0; switch( ch->get_size() ) { - case MS_TINY: + case creature_size::tiny: size_modifier = 2.0; break; - case MS_SMALL: + case creature_size::small: size_modifier = 1.4; break; - case MS_MEDIUM: + case creature_size::medium: break; - case MS_LARGE: + case creature_size::large: size_modifier = 0.6; break; - case MS_HUGE: + case creature_size::huge: size_modifier = 0.15; break; } @@ -465,15 +468,15 @@ Creature *Creature::auto_find_hostile_target( int range, int &boo_hoo, int area int Creature::size_melee_penalty() const { switch( get_size() ) { - case MS_TINY: + case creature_size::tiny: return 30; - case MS_SMALL: + case creature_size::small: return 15; - case MS_MEDIUM: + case creature_size::medium: return 0; - case MS_LARGE: + case creature_size::large: return -10; - case MS_HUGE: + case creature_size::huge: return -20; } @@ -758,19 +761,19 @@ void Creature::deal_projectile_attack( Creature *source, dealt_projectile_attack } if( stun_strength > 0 ) { switch( get_size() ) { - case MS_TINY: + case creature_size::tiny: stun_strength *= 4; break; - case MS_SMALL: + case creature_size::small: stun_strength *= 2; break; - case MS_MEDIUM: + case creature_size::medium: default: break; - case MS_LARGE: + case creature_size::large: stun_strength /= 2; break; - case MS_HUGE: + case creature_size::huge: stun_strength /= 4; break; } @@ -1631,19 +1634,19 @@ units::mass Creature::weight_capacity() const { units::mass base_carry = 13_kilogram; switch( get_size() ) { - case MS_TINY: + case creature_size::tiny: base_carry /= 4; break; - case MS_SMALL: + case creature_size::small: base_carry /= 2; break; - case MS_MEDIUM: + case creature_size::medium: default: break; - case MS_LARGE: + case creature_size::large: base_carry *= 2; break; - case MS_HUGE: + case creature_size::huge: base_carry *= 4; break; } diff --git a/src/creature.h b/src/creature.h index 3750446236ac9..cf03d0ee2a10a 100644 --- a/src/creature.h +++ b/src/creature.h @@ -51,14 +51,146 @@ struct dealt_projectile_attack; struct pathfinding_settings; struct trap; -enum m_size : int { - MS_TINY = 1, // Squirrel - MS_SMALL, // Dog - MS_MEDIUM, // Human - MS_LARGE, // Cow - MS_HUGE // TAAAANK +enum class creature_size : int { + // Keep it starting at 1 - damage done to monsters depends on it + // Squirrel + tiny = 1, + // Dog + small, + // Human + medium, + // Cow + large, + // TAAAANK + huge }; +using I = std::underlying_type_t; +constexpr I operator+( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) + static_cast( rhs ); +} + +constexpr I operator+( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) + rhs; +} + +constexpr I operator+( const I lhs, const creature_size rhs ) +{ + return lhs + static_cast( rhs ); +} + +constexpr I operator-( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) - static_cast( rhs ); +} + +constexpr I operator-( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) - rhs; +} + +constexpr I operator-( const I lhs, const creature_size rhs ) +{ + return lhs - static_cast( rhs ); +} + +constexpr I operator*( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) * static_cast( rhs ); +} + +constexpr I operator*( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) * rhs; +} + +constexpr I operator*( const I lhs, const creature_size rhs ) +{ + return lhs * static_cast( rhs ); +} + +constexpr I operator/( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) / static_cast( rhs ); +} + +constexpr I operator/( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) / rhs; +} + +constexpr bool operator<=( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) <= static_cast( rhs ); +} + +constexpr bool operator<=( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) <= rhs; +} + +constexpr bool operator<=( const I lhs, const creature_size rhs ) +{ + return lhs <= static_cast( rhs ); +} + +constexpr bool operator<( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) < static_cast( rhs ); +} + +constexpr bool operator<( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) < rhs; +} + +constexpr bool operator<( const I lhs, const creature_size rhs ) +{ + return lhs < static_cast( rhs ); +} + +constexpr bool operator>=( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) >= static_cast( rhs ); +} + +constexpr bool operator>=( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) >= rhs; +} + +constexpr bool operator>=( const I lhs, const creature_size rhs ) +{ + return lhs >= static_cast( rhs ); +} + +constexpr bool operator>( const creature_size lhs, const creature_size rhs ) +{ + return static_cast( lhs ) > static_cast( rhs ); +} + +constexpr bool operator>( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) > rhs; +} + +constexpr bool operator>( const I lhs, const creature_size rhs ) +{ + return lhs > static_cast( rhs ); +} + +constexpr bool operator==( const creature_size lhs, const I rhs ) +{ + return static_cast( lhs ) == rhs; +} + +constexpr bool operator==( const I lhs, const creature_size rhs ) +{ + return lhs == static_cast( rhs ); +} + enum FacingDirection { FD_NONE = 0, FD_LEFT = 1, @@ -70,7 +202,7 @@ class Creature public: virtual ~Creature(); - static const std::map size_map; + static const std::map size_map; // Like disp_name, but without any "the" virtual std::string get_name() const = 0; @@ -428,7 +560,7 @@ class Creature virtual float get_hit() const; virtual int get_speed() const; - virtual m_size get_size() const = 0; + virtual creature_size get_size() const = 0; virtual int get_hp( hp_part bp ) const = 0; virtual int get_hp() const = 0; virtual int get_hp_max( hp_part bp ) const = 0; diff --git a/src/explosion.cpp b/src/explosion.cpp index 175da46f92147..5fb550f21d0a4 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -690,10 +690,10 @@ void emp_blast( const tripoint &p ) int deact_chance = 0; const auto mon_item_id = critter.type->revert_to_itype; switch( critter.get_size() ) { - case MS_TINY: + case creature_size::tiny: deact_chance = 6; break; - case MS_SMALL: + case creature_size::small: deact_chance = 3; break; default: diff --git a/src/game.cpp b/src/game.cpp index dfb12b5fbd90d..32980dd784511 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5282,13 +5282,13 @@ bool game::forced_door_closing( const tripoint &p, const ter_id &door_type, int if( can_see ) { add_msg( _( "The %1$s hits the %2$s." ), door_name, critter.name() ); } - if( critter.type->size <= MS_SMALL ) { + if( critter.type->size <= creature_size::small ) { critter.die_in_explosion( nullptr ); } else { critter.apply_damage( nullptr, bodypart_id( "torso" ), bash_dmg ); critter.check_dead_state(); } - if( !critter.is_dead() && critter.type->size >= MS_HUGE ) { + if( !critter.is_dead() && critter.type->size >= creature_size::huge ) { // big critters simply prevent the gate from closing // TODO: perhaps damage/destroy the gate // if the critter was really big? @@ -5944,19 +5944,19 @@ void game::print_all_tile_info( const tripoint &lp, const catacurses::window &w_ if( u.sees_with_infrared( *creature ) ) { std::string size_str; switch( creature->get_size() ) { - case MS_TINY: + case creature_size::tiny: size_str = pgettext( "infrared size", "tiny" ); break; - case MS_SMALL: + case creature_size::small: size_str = pgettext( "infrared size", "small" ); break; - case MS_MEDIUM: + case creature_size::medium: size_str = pgettext( "infrared size", "medium" ); break; - case MS_LARGE: + case creature_size::large: size_str = pgettext( "infrared size", "large" ); break; - case MS_HUGE: + case creature_size::huge: size_str = pgettext( "infrared size", "huge" ); break; } @@ -9155,13 +9155,13 @@ std::vector game::get_dangerous_tile( const tripoint &dest_loc ) co bool game::walk_move( const tripoint &dest_loc ) { if( m.has_flag_ter( TFLAG_SMALL_PASSAGE, dest_loc ) ) { - if( u.get_size() > MS_MEDIUM ) { + if( u.get_size() > creature_size::medium ) { add_msg( m_warning, _( "You can't fit there." ) ); return false; // character too large to fit through a tight passage } if( u.is_mounted() ) { monster *mount = u.mounted_creature.get(); - if( mount->get_size() > MS_MEDIUM ) { + if( mount->get_size() > creature_size::medium ) { add_msg( m_warning, _( "Your mount can't fit there." ) ); return false; // char's mount is too large for tight passages } @@ -9406,18 +9406,18 @@ bool game::walk_move( const tripoint &dest_loc ) if( u.is_mounted() ) { auto mons = u.mounted_creature.get(); switch( mons->get_size() ) { - case MS_TINY: + case creature_size::tiny: volume = 0; // No sound for the tinies break; - case MS_SMALL: + case creature_size::small: volume /= 3; break; - case MS_MEDIUM: + case creature_size::medium: break; - case MS_LARGE: + case creature_size::large: volume *= 1.5; break; - case MS_HUGE: + case creature_size::huge: volume *= 2; break; default: diff --git a/src/item.h b/src/item.h index 56aa9111aa2f8..f5ae3896b8739 100644 --- a/src/item.h +++ b/src/item.h @@ -62,7 +62,6 @@ struct use_function; enum art_effect_passive : int; enum body_part : int; -enum m_size : int; enum class side : int; class body_part_set; class map; diff --git a/src/iuse.cpp b/src/iuse.cpp index 8054e37e46b55..0f0bb48da75e7 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -7777,7 +7777,8 @@ int iuse::camera( player *p, item *it, bool, const tripoint & ) monster &z = *mon; // shoot past small monsters and hallucinations - if( trajectory_point != aim_point && ( z.type->size <= MS_SMALL || z.is_hallucination() || + if( trajectory_point != aim_point && ( z.type->size <= creature_size::small || + z.is_hallucination() || z.type->in_species( species_HALLUCINATION ) ) ) { continue; } @@ -9553,13 +9554,13 @@ int iuse::capture_monster_act( player *p, item *it, bool, const tripoint &pos ) return 0; } } else { - if( !it->has_property( "monster_size_capacity" ) ) { - debugmsg( "%s has no monster_size_capacity.", it->tname() ); + if( !it->has_property( "creature_size_capacity" ) ) { + debugmsg( "%s has no creature_size_capacity.", it->tname() ); return 0; } - const std::string capacity = it->get_property_string( "monster_size_capacity" ); + const std::string capacity = it->get_property_string( "creature_size_capacity" ); if( Creature::size_map.count( capacity ) == 0 ) { - debugmsg( "%s has invalid monster_size_capacity %s.", + debugmsg( "%s has invalid creature_size_capacity %s.", it->tname(), capacity.c_str() ); return 0; } diff --git a/src/melee.cpp b/src/melee.cpp index 360ef45f45bed..b91c3bee6620d 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -629,7 +629,7 @@ void player::reach_attack( const tripoint &p ) Creature *critter = g->critter_at( p ); // Original target size, used when there are monsters in front of our target - int target_size = critter != nullptr ? critter->get_size() : 2; + const int target_size = critter != nullptr ? static_cast( critter->get_size() ) : 2; // Reset last target pos last_target_pos = cata::nullopt; // Max out recoil diff --git a/src/monattack.cpp b/src/monattack.cpp index c2cdb24185033..dc4304980d5b8 100644 --- a/src/monattack.cpp +++ b/src/monattack.cpp @@ -2295,21 +2295,21 @@ static bool blobify( monster &blob, monster &target ) } switch( target.get_size() ) { - case MS_TINY: + case creature_size::tiny: // Just consume it target.set_hp( 0 ); blob.set_speed_base( blob.get_speed_base() + 5 ); return false; - case MS_SMALL: + case creature_size::small: target.poly( mon_blob_small ); break; - case MS_MEDIUM: + case creature_size::medium: target.poly( mon_blob ); break; - case MS_LARGE: + case creature_size::large: target.poly( mon_blob_large ); break; - case MS_HUGE: + case creature_size::huge: // No polymorphing huge stuff target.add_effect( effect_slimed, rng( 2_turns, 10_turns ) ); break; diff --git a/src/mondeath.cpp b/src/mondeath.cpp index 96485800c797f..4c2d4b59474c6 100644 --- a/src/mondeath.cpp +++ b/src/mondeath.cpp @@ -185,7 +185,7 @@ void mdeath::splatter( monster &z ) const auto area = g->m.points_in_radius( z.pos(), 1 ); int number_of_gibs = std::min( std::floor( corpse_damage ) - 1, 1 + max_hp / 5.0f ); - if( pulverized && z.type->size >= MS_MEDIUM ) { + if( pulverized && z.type->size >= creature_size::medium ) { number_of_gibs += rng( 1, 6 ); sfx::play_variant_sound( "mon_death", "zombie_gibbed", sfx::get_heard_volume( z.pos() ) ); } @@ -560,19 +560,19 @@ void mdeath::explode( monster &z ) { int size = 0; switch( z.type->size ) { - case MS_TINY: + case creature_size::tiny: size = 4; break; - case MS_SMALL: + case creature_size::small: size = 8; break; - case MS_MEDIUM: + case creature_size::medium: size = 14; break; - case MS_LARGE: + case creature_size::large: size = 20; break; - case MS_HUGE: + case creature_size::huge: size = 26; break; } diff --git a/src/monmove.cpp b/src/monmove.cpp index d7eac71363fce..27b024ae5d5fd 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -142,7 +142,7 @@ bool monster::will_move_to( const tripoint &p ) const return false; } - if( get_size() > MS_MEDIUM && g->m.has_flag_ter( TFLAG_SMALL_PASSAGE, p ) ) { + if( get_size() > creature_size::medium && g->m.has_flag_ter( TFLAG_SMALL_PASSAGE, p ) ) { return false; // if a large critter, can't move through tight passages } @@ -183,7 +183,7 @@ bool monster::will_move_to( const tripoint &p ) const } // Don't enter open pits ever unless tiny, can fly or climb well - if( !( type->size == MS_TINY || can_climb() ) && + if( !( type->size == creature_size::tiny || can_climb() ) && ( target == t_pit || target == t_pit_spiked || target == t_pit_glass ) ) { return false; } @@ -193,7 +193,7 @@ bool monster::will_move_to( const tripoint &p ) const if( attitude( &g->u ) != MATT_ATTACK ) { // Sharp terrain is ignored while attacking if( avoid_simple && g->m.has_flag( "SHARP", p ) && - !( type->size == MS_TINY || flies() ) ) { + !( type->size == creature_size::tiny || flies() ) ) { return false; } } @@ -1084,18 +1084,18 @@ void monster::footsteps( const tripoint &p ) volume = 10; } switch( type->size ) { - case MS_TINY: + case creature_size::tiny: volume = 0; // No sound for the tinies break; - case MS_SMALL: + case creature_size::small: volume /= 3; break; - case MS_MEDIUM: + case creature_size::medium: break; - case MS_LARGE: + case creature_size::large: volume *= 1.5; break; - case MS_HUGE: + case creature_size::huge: volume *= 2; break; default: @@ -1554,7 +1554,7 @@ bool monster::move_to( const tripoint &p, bool force, bool step_on_critter, return true; } - if( type->size != MS_TINY && on_ground ) { + if( type->size != creature_size::tiny && on_ground ) { const int sharp_damage = rng( 1, 10 ); const int rough_damage = rng( 1, 2 ); if( g->m.has_flag( "SHARP", pos() ) && !one_in( 4 ) && @@ -1590,19 +1590,19 @@ bool monster::move_to( const tripoint &p, bool force, bool step_on_critter, if( digging() && g->m.has_flag( "DIGGABLE", pos() ) ) { int factor = 0; switch( type->size ) { - case MS_TINY: + case creature_size::tiny: factor = 100; break; - case MS_SMALL: + case creature_size::small: factor = 30; break; - case MS_MEDIUM: + case creature_size::medium: factor = 6; break; - case MS_LARGE: + case creature_size::large: factor = 3; break; - case MS_HUGE: + case creature_size::huge: factor = 1; break; } @@ -1844,14 +1844,14 @@ void monster::knock_back_to( const tripoint &to ) // First, see if we hit another monster if( monster *const z = g->critter_at( to ) ) { - apply_damage( z, bodypart_id( "torso" ), z->type->size ); + apply_damage( z, bodypart_id( "torso" ), static_cast( z->type->size ) ); add_effect( effect_stunned, 1_turns ); if( type->size > 1 + z->type->size ) { z->knock_back_from( pos() ); // Chain reaction! - z->apply_damage( this, bodypart_id( "torso" ), type->size ); + z->apply_damage( this, bodypart_id( "torso" ), static_cast( type->size ) ); z->add_effect( effect_stunned, 1_turns ); } else if( type->size > z->type->size ) { - z->apply_damage( this, bodypart_id( "torso" ), type->size ); + z->apply_damage( this, bodypart_id( "torso" ), static_cast( type->size ) ); z->add_effect( effect_stunned, 1_turns ); } z->check_dead_state(); @@ -1866,7 +1866,8 @@ void monster::knock_back_to( const tripoint &to ) if( npc *const p = g->critter_at( to ) ) { apply_damage( p, bodypart_id( "torso" ), 3 ); add_effect( effect_stunned, 1_turns ); - p->deal_damage( this, bodypart_id( "torso" ), damage_instance( DT_BASH, type->size ) ); + p->deal_damage( this, bodypart_id( "torso" ), + damage_instance( DT_BASH, static_cast( type->size ) ) ); if( u_see ) { add_msg( _( "The %1$s bounces off %2$s!" ), name(), p->name ); } @@ -1888,7 +1889,7 @@ void monster::knock_back_to( const tripoint &to ) if( g->m.impassable( to ) ) { // It's some kind of wall. - apply_damage( nullptr, bodypart_id( "torso" ), type->size ); + apply_damage( nullptr, bodypart_id( "torso" ), static_cast( type->size ) ); add_effect( effect_stunned, 2_turns ); if( u_see ) { add_msg( _( "The %1$s bounces off a %2$s." ), name(), @@ -1983,10 +1984,10 @@ void monster::shove_vehicle( const tripoint &remote_destination, float shove_damage_min = 0.00F; float shove_damage_max = 0.00F; switch( this->get_size() ) { - case MS_TINY: - case MS_SMALL: + case creature_size::tiny: + case creature_size::small: break; - case MS_MEDIUM: + case creature_size::medium: if( veh_mass < 500_kilogram ) { shove_moves_minimal = 150; shove_veh_mass_moves_factor = 20; @@ -1995,7 +1996,7 @@ void monster::shove_vehicle( const tripoint &remote_destination, shove_damage_max = 0.01F; } break; - case MS_LARGE: + case creature_size::large: if( veh_mass < 1000_kilogram ) { shove_moves_minimal = 100; shove_veh_mass_moves_factor = 8; @@ -2004,7 +2005,7 @@ void monster::shove_vehicle( const tripoint &remote_destination, shove_damage_max = 0.03F; } break; - case MS_HUGE: + case creature_size::huge: if( veh_mass < 2000_kilogram ) { shove_moves_minimal = 50; shove_veh_mass_moves_factor = 4; diff --git a/src/monster.cpp b/src/monster.cpp index d98f75407fba5..c8972151e2d5f 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -172,12 +172,12 @@ struct pathfinding_settings; // The rough formula is 2^(-x), e.g. for x = 5 it's 0.03125 (~ 3%). static constexpr int UPGRADE_MAX_ITERS = 5; -static const std::map size_names { - { m_size::MS_TINY, to_translation( "size adj", "tiny" ) }, - { m_size::MS_SMALL, to_translation( "size adj", "small" ) }, - { m_size::MS_MEDIUM, to_translation( "size adj", "medium" ) }, - { m_size::MS_LARGE, to_translation( "size adj", "large" ) }, - { m_size::MS_HUGE, to_translation( "size adj", "huge" ) }, +static const std::map size_names { + { creature_size::tiny, to_translation( "size adj", "tiny" ) }, + { creature_size::small, to_translation( "size adj", "small" ) }, + { creature_size::medium, to_translation( "size adj", "medium" ) }, + { creature_size::large, to_translation( "size adj", "large" ) }, + { creature_size::huge, to_translation( "size adj", "huge" ) }, }; static const std::map> attitude_names { @@ -1897,19 +1897,19 @@ float monster::stability_roll() const { int size_bonus = 0; switch( type->size ) { - case MS_TINY: + case creature_size::tiny: size_bonus -= 7; break; - case MS_SMALL: + case creature_size::small: size_bonus -= 3; break; - case MS_LARGE: + case creature_size::large: size_bonus += 5; break; - case MS_HUGE: + case creature_size::huge: size_bonus += 10; break; - case MS_MEDIUM: + case creature_size::medium: break; // keep default } @@ -1961,15 +1961,15 @@ float monster::fall_damage_mod() const } switch( type->size ) { - case MS_TINY: + case creature_size::tiny: return 0.2f; - case MS_SMALL: + case creature_size::small: return 0.6f; - case MS_MEDIUM: + case creature_size::medium: return 1.0f; - case MS_LARGE: + case creature_size::large: return 1.4f; - case MS_HUGE: + case creature_size::huge: return 2.0f; } @@ -2546,7 +2546,7 @@ bool monster::make_fungus() polypick = 7; } else if( tid == mon_zombie_gasbag ) { polypick = 8; - } else if( type->in_species( species_SPIDER ) && get_size() > MS_TINY ) { + } else if( type->in_species( species_SPIDER ) && get_size() > creature_size::tiny ) { polypick = 9; } @@ -2629,9 +2629,9 @@ field_type_id monster::gibType() const return type->gibType(); } -m_size monster::get_size() const +creature_size monster::get_size() const { - return m_size( type->size + size_bonus ); + return creature_size( type->size + size_bonus ); } units::mass monster::get_weight() const diff --git a/src/monster.h b/src/monster.h index 4daa805f2e3a5..cbf28dd57c7bb 100644 --- a/src/monster.h +++ b/src/monster.h @@ -106,7 +106,7 @@ class monster : public Creature void try_biosignature(); void refill_udders(); void spawn( const tripoint &p ); - m_size get_size() const override; + creature_size get_size() const override; units::mass get_weight() const override; units::mass weight_capacity() const override; units::volume get_volume() const; diff --git a/src/monstergenerator.cpp b/src/monstergenerator.cpp index 8ca3300d55da5..6513e56235a77 100644 --- a/src/monstergenerator.cpp +++ b/src/monstergenerator.cpp @@ -260,18 +260,18 @@ static int calc_bash_skill( const mtype &t ) return ret; } -static m_size volume_to_size( const units::volume &vol ) +static creature_size volume_to_size( const units::volume &vol ) { if( vol <= 7500_ml ) { - return MS_TINY; + return creature_size::tiny; } else if( vol <= 46250_ml ) { - return MS_SMALL; + return creature_size::small; } else if( vol <= 77500_ml ) { - return MS_MEDIUM; + return creature_size::medium; } else if( vol <= 483750_ml ) { - return MS_LARGE; + return creature_size::large; } - return MS_HUGE; + return creature_size::huge; } struct monster_adjustment { diff --git a/src/mtype.cpp b/src/mtype.cpp index 257bac19118b9..d3264398d43b3 100644 --- a/src/mtype.cpp +++ b/src/mtype.cpp @@ -29,7 +29,7 @@ mtype::mtype() name = pl_translation( "human", "humans" ); sym = " "; color = c_white; - size = MS_MEDIUM; + size = creature_size::medium; volume = 62499_ml; weight = 81499_gram; mat = { material_id( "flesh" ) }; diff --git a/src/mtype.h b/src/mtype.h index cc7a4de0aeb79..aa3c6dfab5666 100644 --- a/src/mtype.h +++ b/src/mtype.h @@ -27,7 +27,7 @@ struct species_type; template struct enum_traits; enum body_part : int; -enum m_size : int; +enum class creature_size : int; using mon_action_death = void ( * )( monster & ); using mon_action_attack = bool ( * )( monster * ); @@ -72,7 +72,7 @@ enum m_flag : int { MF_STUMBLES, // Stumbles in its movement MF_WARM, // Warm blooded MF_NOHEAD, // Headshots not allowed! - MF_HARDTOSHOOT, // It's one size smaller for ranged attacks, no less then MS_TINY + MF_HARDTOSHOOT, // It's one size smaller for ranged attacks, no less then creature_size::tiny MF_GRABS, // Its attacks may grab us! MF_BASHES, // Bashes down doors MF_DESTROYS, // Bashes down walls and more @@ -242,7 +242,7 @@ struct mtype { mfaction_id default_faction; bodytype_id bodytype; nc_color color = c_white; - m_size size; + creature_size size; units::volume volume; units::mass weight; phase_id phase; diff --git a/src/mutation.cpp b/src/mutation.cpp index 70b01b7c8119c..d95f0e07c83b7 100644 --- a/src/mutation.cpp +++ b/src/mutation.cpp @@ -235,17 +235,17 @@ const resistances &mutation_branch::damage_resistance( body_part bp ) const return iter->second; } -m_size calculate_size( const Character &c ) +creature_size calculate_size( const Character &c ) { if( c.has_trait( trait_id( "SMALL2" ) ) || c.has_trait( trait_id( "SMALL_OK" ) ) || c.has_trait( trait_id( "SMALL" ) ) ) { - return MS_SMALL; + return creature_size::small; } else if( c.has_trait( trait_LARGE ) || c.has_trait( trait_LARGE_OK ) ) { - return MS_LARGE; + return creature_size::large; } else if( c.has_trait( trait_HUGE ) || c.has_trait( trait_HUGE_OK ) ) { - return MS_HUGE; + return creature_size::huge; } - return MS_MEDIUM; + return creature_size::medium; } void Character::mutation_effect( const trait_id &mut ) diff --git a/src/player.cpp b/src/player.cpp index 22541cdbd9560..6a2084fda3d97 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1282,7 +1282,8 @@ void player::knock_back_to( const tripoint &to ) // First, see if we hit a monster if( monster *const critter = g->critter_at( to ) ) { - deal_damage( critter, bodypart_id( "torso" ), damage_instance( DT_BASH, critter->type->size ) ); + deal_damage( critter, bodypart_id( "torso" ), damage_instance( DT_BASH, + static_cast( critter->type->size ) ) ); add_effect( effect_stunned, 1_turns ); /** @EFFECT_STR_MAX allows knocked back player to knock back, damage, stun some monsters */ if( ( str_max - 6 ) / 4 > critter->type->size ) { @@ -1301,7 +1302,8 @@ void player::knock_back_to( const tripoint &to ) } if( npc *const np = g->critter_at( to ) ) { - deal_damage( np, bodypart_id( "torso" ), damage_instance( DT_BASH, np->get_size() ) ); + deal_damage( np, bodypart_id( "torso" ), + damage_instance( DT_BASH, static_cast( np->get_size() ) ) ); add_effect( effect_stunned, 1_turns ); np->deal_damage( this, bodypart_id( "torso" ), damage_instance( DT_BASH, 3 ) ); add_msg_player_or_npc( _( "You bounce off %s!" ), _( " bounces off %s!" ), diff --git a/src/ranged.cpp b/src/ranged.cpp index c013efc086f84..a9e5a51cb21d7 100644 --- a/src/ranged.cpp +++ b/src/ranged.cpp @@ -448,18 +448,18 @@ target_handler::trajectory target_handler::mode_spell( avatar &you, const spell_ return mode_spell( you, you.magic.get_spell( sp ), no_fail, no_mana ); } -static double occupied_tile_fraction( m_size target_size ) +static double occupied_tile_fraction( creature_size target_size ) { switch( target_size ) { - case MS_TINY: + case creature_size::tiny: return 0.1; - case MS_SMALL: + case creature_size::small: return 0.25; - case MS_MEDIUM: + case creature_size::medium: return 0.5; - case MS_LARGE: + case creature_size::large: return 0.75; - case MS_HUGE: + case creature_size::huge: return 1.0; } @@ -470,15 +470,15 @@ double Creature::ranged_target_size() const { if( has_flag( MF_HARDTOSHOOT ) ) { switch( get_size() ) { - case MS_TINY: - case MS_SMALL: - return occupied_tile_fraction( MS_TINY ); - case MS_MEDIUM: - return occupied_tile_fraction( MS_SMALL ); - case MS_LARGE: - return occupied_tile_fraction( MS_MEDIUM ); - case MS_HUGE: - return occupied_tile_fraction( MS_LARGE ); + case creature_size::tiny: + case creature_size::small: + return occupied_tile_fraction( creature_size::tiny ); + case creature_size::medium: + return occupied_tile_fraction( creature_size::small ); + case creature_size::large: + return occupied_tile_fraction( creature_size::medium ); + case creature_size::huge: + return occupied_tile_fraction( creature_size::large ); } } return occupied_tile_fraction( get_size() ); @@ -3118,7 +3118,7 @@ void target_ui::panel_fire_mode_aim( int &text_y ) } const double target_size = dst_critter ? dst_critter->ranged_target_size() : - occupied_tile_fraction( MS_MEDIUM ); + occupied_tile_fraction( creature_size::medium ); text_y = print_aim( *you, w_target, text_y, ctxt, &*relevant->gun_current_mode(), target_size, dst, predicted_recoil ); diff --git a/src/trapfunc.cpp b/src/trapfunc.cpp index 42717a7ef0c6b..793b308cef5f4 100644 --- a/src/trapfunc.cpp +++ b/src/trapfunc.cpp @@ -87,7 +87,7 @@ bool trapfunc::none( const tripoint &, Creature *, item * ) bool trapfunc::bubble( const tripoint &p, Creature *c, item * ) { // tiny animals don't trigger bubble wrap - if( c != nullptr && c->get_size() == MS_TINY ) { + if( c != nullptr && c->get_size() == creature_size::tiny ) { return false; } if( c != nullptr ) { @@ -106,7 +106,7 @@ bool trapfunc::glass( const tripoint &p, Creature *c, item * ) { if( c != nullptr ) { // tiny animals and hallucinations don't trigger glass trap - if( c->get_size() == MS_TINY || c->is_hallucination() ) { + if( c->get_size() == creature_size::tiny || c->is_hallucination() ) { return false; } c->add_msg_player_or_npc( m_warning, _( "You step on some glass!" ), @@ -143,7 +143,7 @@ bool trapfunc::cot( const tripoint &, Creature *c, item * ) bool trapfunc::beartrap( const tripoint &p, Creature *c, item * ) { // tiny animals don't trigger bear traps - if( c != nullptr && c->get_size() == MS_TINY ) { + if( c != nullptr && c->get_size() == creature_size::tiny ) { return false; } sounds::sound( p, 8, sounds::sound_t::combat, _( "SNAP!" ), false, "trap", "bear_trap" ); @@ -187,7 +187,7 @@ bool trapfunc::board( const tripoint &, Creature *c, item * ) return false; } // tiny animals don't trigger spiked boards, they can squeeze between the nails - if( c->get_size() == MS_TINY ) { + if( c->get_size() == creature_size::tiny ) { return false; } c->add_msg_player_or_npc( m_bad, _( "You step on a spiked board!" ), @@ -223,7 +223,7 @@ bool trapfunc::caltrops( const tripoint &, Creature *c, item * ) return false; } // tiny animals don't trigger caltrops, they can squeeze between them - if( c->get_size() == MS_TINY ) { + if( c->get_size() == creature_size::tiny ) { return false; } c->add_msg_player_or_npc( m_bad, _( "You step on a sharp metal caltrop!" ), @@ -252,7 +252,7 @@ bool trapfunc::caltrops_glass( const tripoint &p, Creature *c, item * ) return false; } // tiny animals don't trigger caltrops, they can squeeze between them - if( c->get_size() == MS_TINY || c->is_hallucination() ) { + if( c->get_size() == creature_size::tiny || c->is_hallucination() ) { return false; } c->add_msg_player_or_npc( m_bad, _( "You step on a sharp glass caltrop!" ), @@ -282,7 +282,7 @@ bool trapfunc::tripwire( const tripoint &p, Creature *c, item * ) return false; } // tiny animals don't trigger tripwires, they just squeeze under it - if( c->get_size() == MS_TINY ) { + if( c->get_size() == creature_size::tiny ) { return false; } c->add_msg_player_or_npc( m_bad, _( "You trip over a tripwire!" ), @@ -391,19 +391,19 @@ bool trapfunc::crossbow( const tripoint &p, Creature *c, item * ) int chance = 0; // adapted from shotgun code - chance of getting hit depends on size switch( z->type->size ) { - case MS_TINY: + case creature_size::tiny: chance = 50; break; - case MS_SMALL: + case creature_size::small: chance = 8; break; - case MS_MEDIUM: + case creature_size::medium: chance = 6; break; - case MS_LARGE: + case creature_size::large: chance = 4; break; - case MS_HUGE: + case creature_size::huge: chance = 1; break; } @@ -489,19 +489,19 @@ bool trapfunc::shotgun( const tripoint &p, Creature *c, item * ) bool seen = g->u.sees( *z ); int chance = 0; switch( z->type->size ) { - case MS_TINY: + case creature_size::tiny: chance = 100; break; - case MS_SMALL: + case creature_size::small: chance = 16; break; - case MS_MEDIUM: + case creature_size::medium: chance = 12; break; - case MS_LARGE: + case creature_size::large: chance = 8; break; - case MS_HUGE: + case creature_size::huge: chance = 2; break; } @@ -561,7 +561,7 @@ bool trapfunc::snare_light( const tripoint &p, Creature *c, item * ) // Actual effects c->add_effect( effect_lightsnare, 1_turns, hit->token, true ); monster *z = dynamic_cast( c ); - if( z != nullptr && z->type->size == MS_TINY ) { + if( z != nullptr && z->type->size == creature_size::tiny ) { z->deal_damage( nullptr, hit, damage_instance( DT_BASH, 10 ) ); } c->check_dead_state(); @@ -595,11 +595,11 @@ bool trapfunc::snare_heavy( const tripoint &p, Creature *c, item * ) } else if( z != nullptr ) { int damage; switch( z->type->size ) { - case MS_TINY: - case MS_SMALL: + case creature_size::tiny: + case creature_size::small: damage = 20; break; - case MS_MEDIUM: + case creature_size::medium: damage = 10; break; default: @@ -614,7 +614,7 @@ bool trapfunc::snare_heavy( const tripoint &p, Creature *c, item * ) bool trapfunc::landmine( const tripoint &p, Creature *c, item * ) { // tiny animals are too light to trigger land mines - if( c != nullptr && c->get_size() == MS_TINY ) { + if( c != nullptr && c->get_size() == creature_size::tiny ) { return false; } if( c != nullptr ) { @@ -760,7 +760,7 @@ bool trapfunc::pit( const tripoint &p, Creature *c, item * ) return false; } // tiny animals aren't hurt by falling into pits - if( c->get_size() == MS_TINY ) { + if( c->get_size() == creature_size::tiny ) { return false; } const float eff = pit_effectiveness( p ); @@ -807,7 +807,7 @@ bool trapfunc::pit_spikes( const tripoint &p, Creature *c, item * ) return false; } // tiny animals aren't hurt by falling into spiked pits - if( c->get_size() == MS_TINY ) { + if( c->get_size() == creature_size::tiny ) { return false; } c->add_msg_player_or_npc( m_bad, _( "You fall in a spiked pit!" ), @@ -890,7 +890,7 @@ bool trapfunc::pit_glass( const tripoint &p, Creature *c, item * ) return false; } // tiny animals aren't hurt by falling into glass pits - if( c->get_size() == MS_TINY ) { + if( c->get_size() == creature_size::tiny ) { return false; } c->add_msg_player_or_npc( m_bad, _( "You fall in a pit filled with glass shards!" ), @@ -1074,7 +1074,7 @@ static bool sinkhole_safety_roll( player *p, const itype_id &itemname, const int bool trapfunc::sinkhole( const tripoint &p, Creature *c, item *i ) { // tiny creatures don't trigger the sinkhole to collapse - if( c == nullptr || c->get_size() == MS_TINY ) { + if( c == nullptr || c->get_size() == creature_size::tiny ) { return false; } monster *z = dynamic_cast( c ); diff --git a/tests/char_biometrics_test.cpp b/tests/char_biometrics_test.cpp index d5209e0c956d6..536f9271d166a 100644 --- a/tests/char_biometrics_test.cpp +++ b/tests/char_biometrics_test.cpp @@ -240,7 +240,7 @@ TEST_CASE( "character height and body size mutations", "[biometrics][height][mut REQUIRE( dummy.base_height() == init_height ); WHEN( "they are normal-sized (MEDIUM)" ) { - REQUIRE( dummy.get_size() == MS_MEDIUM ); + REQUIRE( dummy.get_size() == creature_size::medium ); THEN( "height is initial height" ) { CHECK( dummy.height() == init_height ); @@ -249,7 +249,7 @@ TEST_CASE( "character height and body size mutations", "[biometrics][height][mut WHEN( "they become SMALL" ) { set_single_trait( dummy, "SMALL" ); - REQUIRE( dummy.get_size() == MS_SMALL ); + REQUIRE( dummy.get_size() == creature_size::small ); THEN( "they are 50cm shorter" ) { CHECK( dummy.height() == init_height - 50 ); @@ -258,7 +258,7 @@ TEST_CASE( "character height and body size mutations", "[biometrics][height][mut WHEN( "they become LARGE" ) { set_single_trait( dummy, "LARGE" ); - REQUIRE( dummy.get_size() == MS_LARGE ); + REQUIRE( dummy.get_size() == creature_size::large ); THEN( "they are 50cm taller" ) { CHECK( dummy.height() == init_height + 50 ); @@ -267,7 +267,7 @@ TEST_CASE( "character height and body size mutations", "[biometrics][height][mut WHEN( "they become HUGE" ) { set_single_trait( dummy, "HUGE" ); - REQUIRE( dummy.get_size() == MS_HUGE ); + REQUIRE( dummy.get_size() == creature_size::huge ); THEN( "they are 100cm taler" ) { CHECK( dummy.height() == init_height + 100 ); @@ -313,7 +313,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) REQUIRE_FALSE( dummy.has_trait( trait_id( "SMALL" ) ) ); REQUIRE_FALSE( dummy.has_trait( trait_id( "LARGE" ) ) ); REQUIRE_FALSE( dummy.has_trait( trait_id( "HUGE" ) ) ); - REQUIRE( dummy.get_size() == MS_MEDIUM ); + REQUIRE( dummy.get_size() == creature_size::medium ); THEN( "bodyweight varies from ~49-107kg" ) { // BMI [16-35] is "Emaciated/Underweight" to "Obese/Very Obese" @@ -325,7 +325,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) WHEN( "character is small" ) { set_single_trait( dummy, "SMALL" ); - REQUIRE( dummy.get_size() == MS_SMALL ); + REQUIRE( dummy.get_size() == creature_size::small ); THEN( "bodyweight varies from ~25-55kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0f ) == Approx( 25.0f ).margin( 0.1f ) ); @@ -336,7 +336,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) WHEN( "character is large" ) { set_single_trait( dummy, "LARGE" ); - REQUIRE( dummy.get_size() == MS_LARGE ); + REQUIRE( dummy.get_size() == creature_size::large ); THEN( "bodyweight varies from ~81-177kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0f ) == Approx( 81.0f ).margin( 0.1f ) ); @@ -347,7 +347,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) WHEN( "character is huge" ) { set_single_trait( dummy, "HUGE" ); - REQUIRE( dummy.get_size() == MS_HUGE ); + REQUIRE( dummy.get_size() == creature_size::huge ); THEN( "bodyweight varies from ~121-265kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0f ) == Approx( 121.0f ).margin( 0.1f ) ); @@ -365,7 +365,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) REQUIRE_FALSE( dummy.has_trait( trait_id( "SMALL" ) ) ); REQUIRE_FALSE( dummy.has_trait( trait_id( "LARGE" ) ) ); REQUIRE_FALSE( dummy.has_trait( trait_id( "HUGE" ) ) ); - REQUIRE( dummy.get_size() == MS_MEDIUM ); + REQUIRE( dummy.get_size() == creature_size::medium ); THEN( "bodyweight varies from ~57-126kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0 ) == Approx( 57.8 ).margin( 0.1f ) ); @@ -376,7 +376,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) WHEN( "character is small" ) { set_single_trait( dummy, "SMALL" ); - REQUIRE( dummy.get_size() == MS_SMALL ); + REQUIRE( dummy.get_size() == creature_size::small ); THEN( "bodyweight varies from ~31-68kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0f ) == Approx( 31.4f ).margin( 0.1f ) ); @@ -387,7 +387,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) WHEN( "character is large" ) { set_single_trait( dummy, "LARGE" ); - REQUIRE( dummy.get_size() == MS_LARGE ); + REQUIRE( dummy.get_size() == creature_size::large ); THEN( "bodyweight varies from ~92-201kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0f ) == Approx( 92.16f ).margin( 0.1f ) ); @@ -398,7 +398,7 @@ TEST_CASE( "size and height determine body weight", "[biometrics][bodyweight]" ) WHEN( "character is huge" ) { set_single_trait( dummy, "HUGE" ); - REQUIRE( dummy.get_size() == MS_HUGE ); + REQUIRE( dummy.get_size() == creature_size::huge ); THEN( "bodyweight varies from ~134-294kg" ) { CHECK( bodyweight_kg_at_bmi( dummy, 16.0f ) == Approx( 134.6f ).margin( 0.1f ) ); @@ -548,7 +548,7 @@ TEST_CASE( "basal metabolic rate with various size and metabolism", "[biometrics // CHECK expressions have expected value on the left hand side for better readability. SECTION( "normal body size" ) { - REQUIRE( dummy.get_size() == MS_MEDIUM ); + REQUIRE( dummy.get_size() == creature_size::medium ); SECTION( "normal metabolism" ) { CHECK( 2087 == bmr_at_act_level( dummy, NO_EXERCISE ) ); @@ -577,7 +577,7 @@ TEST_CASE( "basal metabolic rate with various size and metabolism", "[biometrics SECTION( "small body size" ) { set_single_trait( dummy, "SMALL" ); - REQUIRE( dummy.get_size() == MS_SMALL ); + REQUIRE( dummy.get_size() == creature_size::small ); CHECK( 1262 == bmr_at_act_level( dummy, NO_EXERCISE ) ); CHECK( 1630 == bmr_at_act_level( dummy, MODERATE_EXERCISE ) ); @@ -586,7 +586,7 @@ TEST_CASE( "basal metabolic rate with various size and metabolism", "[biometrics SECTION( "large body size" ) { set_single_trait( dummy, "LARGE" ); - REQUIRE( dummy.get_size() == MS_LARGE ); + REQUIRE( dummy.get_size() == creature_size::large ); CHECK( 3062 == bmr_at_act_level( dummy, NO_EXERCISE ) ); CHECK( 3955 == bmr_at_act_level( dummy, MODERATE_EXERCISE ) ); diff --git a/tests/creature_test.cpp b/tests/creature_test.cpp index 42240c6660d93..0cd2b6f074d53 100644 --- a/tests/creature_test.cpp +++ b/tests/creature_test.cpp @@ -19,7 +19,7 @@ float expected_weights_max[][12] = { { 2000, 0, 0, 0, 1191.49, 1191.49, 0, 0 { 3657, 2861.78, 113.73, 0, 1815.83, 1815.83, 0, 0, 508.904, 508.904, 0, 0 } }; -static void calculate_bodypart_distribution( const enum m_size asize, const enum m_size dsize, +static void calculate_bodypart_distribution( const creature_size asize, const creature_size dsize, const int hit_roll, float ( &expected )[12] ) { INFO( "hit roll = " << hit_roll ); @@ -59,25 +59,34 @@ TEST_CASE( "Check distribution of attacks to body parts for same sized opponents { srand( 4242424242 ); - calculate_bodypart_distribution( MS_SMALL, MS_SMALL, 0, expected_weights_base[1] ); - calculate_bodypart_distribution( MS_SMALL, MS_SMALL, 1, expected_weights_base[1] ); - calculate_bodypart_distribution( MS_SMALL, MS_SMALL, 100, expected_weights_max[1] ); + calculate_bodypart_distribution( creature_size::small, creature_size::small, 0, + expected_weights_base[1] ); + calculate_bodypart_distribution( creature_size::small, creature_size::small, 1, + expected_weights_base[1] ); + calculate_bodypart_distribution( creature_size::small, creature_size::small, 100, + expected_weights_max[1] ); } TEST_CASE( "Check distribution of attacks to body parts for smaller attacker." ) { srand( 4242424242 ); - calculate_bodypart_distribution( MS_SMALL, MS_MEDIUM, 0, expected_weights_base[0] ); - calculate_bodypart_distribution( MS_SMALL, MS_MEDIUM, 1, expected_weights_base[0] ); - calculate_bodypart_distribution( MS_SMALL, MS_MEDIUM, 100, expected_weights_max[0] ); + calculate_bodypart_distribution( creature_size::small, creature_size::medium, 0, + expected_weights_base[0] ); + calculate_bodypart_distribution( creature_size::small, creature_size::medium, 1, + expected_weights_base[0] ); + calculate_bodypart_distribution( creature_size::small, creature_size::medium, 100, + expected_weights_max[0] ); } TEST_CASE( "Check distribution of attacks to body parts for larger attacker." ) { srand( 4242424242 ); - calculate_bodypart_distribution( MS_MEDIUM, MS_SMALL, 0, expected_weights_base[2] ); - calculate_bodypart_distribution( MS_MEDIUM, MS_SMALL, 1, expected_weights_base[2] ); - calculate_bodypart_distribution( MS_MEDIUM, MS_SMALL, 100, expected_weights_max[2] ); + calculate_bodypart_distribution( creature_size::medium, creature_size::small, 0, + expected_weights_base[2] ); + calculate_bodypart_distribution( creature_size::medium, creature_size::small, 1, + expected_weights_base[2] ); + calculate_bodypart_distribution( creature_size::medium, creature_size::small, 100, + expected_weights_max[2] ); } From f85489aa78223c6e42c72911c214256c2b72eed1 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Fri, 29 May 2020 13:39:35 +0300 Subject: [PATCH 3/5] Make oter_flags a class enum --- src/game.cpp | 8 ++--- src/mapgen.cpp | 2 +- src/mapgen_functions.cpp | 8 ++--- src/omdata.h | 23 ++++++++------ src/overmap.cpp | 14 ++++----- src/overmap.h | 68 ++++++++++++++++++++-------------------- 6 files changed, 64 insertions(+), 59 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 32980dd784511..bb05678f50cf7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -10964,12 +10964,12 @@ void game::vertical_notes( int z_before, int z_after ) } const oter_id &ter = overmap_buffer.ter( cursp_before ); const oter_id &ter2 = overmap_buffer.ter( cursp_after ); - if( z_after > z_before && ter->has_flag( known_up ) && - !ter2->has_flag( known_down ) ) { + if( z_after > z_before && ter->has_flag( oter_flags::known_up ) && + !ter2->has_flag( oter_flags::known_down ) ) { overmap_buffer.set_seen( cursp_after, true ); overmap_buffer.add_note( cursp_after, string_format( ">:W;%s", _( "AUTO: goes down" ) ) ); - } else if( z_after < z_before && ter->has_flag( known_down ) && - !ter2->has_flag( known_up ) ) { + } else if( z_after < z_before && ter->has_flag( oter_flags::known_down ) && + !ter2->has_flag( oter_flags::known_up ) ) { overmap_buffer.set_seen( cursp_after, true ); overmap_buffer.add_note( cursp_after, string_format( "<:W;%s", _( "AUTO: goes up" ) ) ); } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 77d2820fce95b..82ce19cd717d3 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -5568,7 +5568,7 @@ void map::draw_connections( mapgendata &dat ) } // finally, any terrain with SIDEWALKS should contribute sidewalks to neighboring diagonal roads - if( terrain_type->has_flag( has_sidewalk ) ) { + if( terrain_type->has_flag( oter_flags::has_sidewalk ) ) { for( int dir = 4; dir < 8; dir++ ) { // NE SE SW NW bool n_roads_nesw[4] = {}; int n_num_dirs = terrain_type_to_nesw_array( oter_id( dat.t_nesw[dir] ), n_roads_nesw ); diff --git a/src/mapgen_functions.cpp b/src/mapgen_functions.cpp index f5588f0b9562b..4ad9194fe4945 100644 --- a/src/mapgen_functions.cpp +++ b/src/mapgen_functions.cpp @@ -565,7 +565,7 @@ void mapgen_road( mapgendata &dat ) int neighbor_sidewalks = 0; // N E S W NE SE SW NW for( int dir = 0; dir < 8; dir++ ) { - sidewalks_neswx[dir] = dat.t_nesw[dir]->has_flag( has_sidewalk ); + sidewalks_neswx[dir] = dat.t_nesw[dir]->has_flag( oter_flags::has_sidewalk ); neighbor_sidewalks += sidewalks_neswx[dir]; } @@ -913,7 +913,7 @@ void mapgen_subway( mapgendata &dat ) // N E S W for( int dir = 0; dir < 4; dir++ ) { - if( dat.t_nesw[dir]->has_flag( subway_connection ) && !subway_nesw[dir] ) { + if( dat.t_nesw[dir]->has_flag( oter_flags::subway_connection ) && !subway_nesw[dir] ) { num_dirs++; subway_nesw[dir] = true; } @@ -928,7 +928,7 @@ void mapgen_subway( mapgendata &dat ) } if( dat.t_nesw[dir]->get_type_id().str() != "subway" && - !dat.t_nesw[dir]->has_flag( subway_connection ) ) { + !dat.t_nesw[dir]->has_flag( oter_flags::subway_connection ) ) { continue; } // n_* contain details about the neighbor being considered @@ -936,7 +936,7 @@ void mapgen_subway( mapgendata &dat ) // TODO: figure out how to call this function without creating a new oter_id object int n_num_dirs = terrain_type_to_nesw_array( dat.t_nesw[dir], n_subway_nesw ); for( int dir = 0; dir < 4; dir++ ) { - if( dat.t_nesw[dir]->has_flag( subway_connection ) && !n_subway_nesw[dir] ) { + if( dat.t_nesw[dir]->has_flag( oter_flags::subway_connection ) && !n_subway_nesw[dir] ) { n_num_dirs++; n_subway_nesw[dir] = true; } diff --git a/src/omdata.h b/src/omdata.h index c80728c6d24f5..75505a478245b 100644 --- a/src/omdata.h +++ b/src/omdata.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -15,6 +14,7 @@ #include "catacharset.h" #include "color.h" #include "common_types.h" +#include "enum_bitset.h" #include "int_id.h" #include "point.h" #include "string_id.h" @@ -153,7 +153,7 @@ struct overmap_static_spawns : public overmap_spawns { }; //terrain flags enum! this is for tracking the indices of each flag. -enum oter_flags { +enum class oter_flags : int { known_down = 0, known_up, no_rotate, // this tile doesn't have four rotated versions (north, east, south, west) @@ -191,6 +191,11 @@ enum oter_flags { num_oter_flags }; +template<> +struct enum_traits { + static constexpr auto last = oter_flags::num_oter_flags; +}; + struct oter_type_t { public: static const oter_type_t null_type; @@ -222,7 +227,7 @@ struct oter_type_t { } void set_flag( oter_flags flag, bool value = true ) { - flags[flag] = value; + flags.set( flag, value ); } void load( const JsonObject &jo, const std::string &src ); @@ -230,15 +235,15 @@ struct oter_type_t { void finalize(); bool is_rotatable() const { - return !has_flag( no_rotate ) && !has_flag( line_drawing ); + return !has_flag( oter_flags::no_rotate ) && !has_flag( oter_flags::line_drawing ); } bool is_linear() const { - return has_flag( line_drawing ); + return has_flag( oter_flags::line_drawing ); } private: - std::bitset flags; + enum_bitset flags; std::vector directional_peers; void register_terrain( const oter_t &peer, size_t n, size_t max_n ); @@ -326,7 +331,7 @@ struct oter_t { } bool is_river() const { - return type->has_flag( river_tile ); + return type->has_flag( oter_flags::river_tile ); } bool is_wooded() const { @@ -337,11 +342,11 @@ struct oter_t { } bool is_lake() const { - return type->has_flag( lake ); + return type->has_flag( oter_flags::lake ); } bool is_lake_shore() const { - return type->has_flag( lake_shore ); + return type->has_flag( oter_flags::lake_shore ); } private: diff --git a/src/overmap.cpp b/src/overmap.cpp index aa7b9fd5351e1..c95b183b1be48 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -567,8 +567,8 @@ void oter_type_t::load( const JsonObject &jo, const std::string &src ) const auto flag_reader = make_flag_reader( oter_flags_map, "overmap terrain flag" ); optional( jo, was_loaded, "flags", flags, flag_reader ); - if( has_flag( line_drawing ) ) { - if( has_flag( no_rotate ) ) { + if( has_flag( oter_flags::line_drawing ) ) { + if( has_flag( oter_flags::no_rotate ) ) { jo.throw_error( R"(Mutually exclusive flags: "NO_ROTATE" and "LINEAR".)" ); } @@ -601,7 +601,7 @@ void oter_type_t::finalize() for( om_direction::type dir : om_direction::all ) { register_terrain( oter_t( *this, dir ), static_cast( dir ), om_direction::size ); } - } else if( has_flag( line_drawing ) ) { + } else if( has_flag( oter_flags::line_drawing ) ) { for( size_t i = 0; i < om_lines::size; ++i ) { register_terrain( oter_t( *this, i ), i, om_lines::size ); } @@ -645,7 +645,7 @@ oter_id oter_type_t::get_rotated( om_direction::type dir ) const oter_id oter_type_t::get_linear( size_t n ) const { - if( !has_flag( line_drawing ) ) { + if( !has_flag( oter_flags::line_drawing ) ) { debugmsg( "Overmap terrain \"%s \" isn't drawn with lines.", id.c_str() ); return ot_null; } @@ -683,14 +683,14 @@ oter_t::oter_t( const oter_type_t &type, size_t line ) : std::string oter_t::get_mapgen_id() const { - return type->has_flag( line_drawing ) + return type->has_flag( oter_flags::line_drawing ) ? type->id.str() + om_lines::mapgen_suffixes[om_lines::all[line].mapgen] : type->id.str(); } oter_id oter_t::get_rotated( om_direction::type dir ) const { - return type->has_flag( line_drawing ) + return type->has_flag( oter_flags::line_drawing ) ? type->get_linear( om_lines::rotate( this->line, dir ) ) : type->get_rotated( om_direction::add( this->dir, dir ) ); } @@ -1005,7 +1005,7 @@ void overmap_special::check() const if( !elem.terrain ) { debugmsg( "In overmap special \"%s\", connection [%d,%d,%d] doesn't have a terrain.", id.c_str(), elem.p.x, elem.p.y, elem.p.z ); - } else if( !elem.existing && !elem.terrain->has_flag( line_drawing ) ) { + } else if( !elem.existing && !elem.terrain->has_flag( oter_flags::line_drawing ) ) { debugmsg( "In overmap special \"%s\", connection [%d,%d,%d] \"%s\" isn't drawn with lines.", id.c_str(), elem.p.x, elem.p.y, elem.p.z, elem.terrain.c_str() ); } else if( oter.terrain && !oter.terrain->type_is( elem.terrain ) ) { diff --git a/src/overmap.h b/src/overmap.h index 5079d6e550774..e8680c5f62a24 100644 --- a/src/overmap.h +++ b/src/overmap.h @@ -156,40 +156,40 @@ class overmap_special_batch }; static const std::map oter_flags_map = { - { "KNOWN_DOWN", known_down }, - { "KNOWN_UP", known_up }, - { "RIVER", river_tile }, - { "SIDEWALK", has_sidewalk }, - { "NO_ROTATE", no_rotate }, - { "LINEAR", line_drawing }, - { "SUBWAY", subway_connection }, - { "LAKE", lake }, - { "LAKE_SHORE", lake_shore }, - { "GENERIC_LOOT", generic_loot }, - { "RISK_HIGH", risk_high }, - { "RISK_LOW", risk_low }, - { "SOURCE_AMMO", source_ammo }, - { "SOURCE_ANIMALS", source_animals }, - { "SOURCE_BOOKS", source_books }, - { "SOURCE_CHEMISTRY", source_chemistry }, - { "SOURCE_CLOTHING", source_clothing }, - { "SOURCE_CONSTRUCTION", source_construction }, - { "SOURCE_COOKING", source_cooking }, - { "SOURCE_DRINK", source_drink }, - { "SOURCE_ELECTRONICS", source_electronics }, - { "SOURCE_FABRICATION", source_fabrication }, - { "SOURCE_FARMING", source_farming }, - { "SOURCE_FOOD", source_food }, - { "SOURCE_FORAGE", source_forage }, - { "SOURCE_FUEL", source_fuel }, - { "SOURCE_GUN", source_gun }, - { "SOURCE_LUXURY", source_luxury }, - { "SOURCE_MEDICINE", source_medicine }, - { "SOURCE_PEOPLE", source_people }, - { "SOURCE_SAFETY", source_safety }, - { "SOURCE_TAILORING", source_tailoring }, - { "SOURCE_VEHICLES", source_vehicles }, - { "SOURCE_WEAPON", source_weapon } + { "KNOWN_DOWN", oter_flags::known_down }, + { "KNOWN_UP", oter_flags::known_up }, + { "RIVER", oter_flags::river_tile }, + { "SIDEWALK", oter_flags::has_sidewalk }, + { "NO_ROTATE", oter_flags::no_rotate }, + { "LINEAR", oter_flags::line_drawing }, + { "SUBWAY", oter_flags::subway_connection }, + { "LAKE", oter_flags::lake }, + { "LAKE_SHORE", oter_flags::lake_shore }, + { "GENERIC_LOOT", oter_flags::generic_loot }, + { "RISK_HIGH", oter_flags::risk_high }, + { "RISK_LOW", oter_flags::risk_low }, + { "SOURCE_AMMO", oter_flags::source_ammo }, + { "SOURCE_ANIMALS", oter_flags::source_animals }, + { "SOURCE_BOOKS", oter_flags::source_books }, + { "SOURCE_CHEMISTRY", oter_flags::source_chemistry }, + { "SOURCE_CLOTHING", oter_flags::source_clothing }, + { "SOURCE_CONSTRUCTION", oter_flags::source_construction }, + { "SOURCE_COOKING", oter_flags::source_cooking }, + { "SOURCE_DRINK", oter_flags::source_drink }, + { "SOURCE_ELECTRONICS", oter_flags::source_electronics }, + { "SOURCE_FABRICATION", oter_flags::source_fabrication }, + { "SOURCE_FARMING", oter_flags::source_farming }, + { "SOURCE_FOOD", oter_flags::source_food }, + { "SOURCE_FORAGE", oter_flags::source_forage }, + { "SOURCE_FUEL", oter_flags::source_fuel }, + { "SOURCE_GUN", oter_flags::source_gun }, + { "SOURCE_LUXURY", oter_flags::source_luxury }, + { "SOURCE_MEDICINE", oter_flags::source_medicine }, + { "SOURCE_PEOPLE", oter_flags::source_people }, + { "SOURCE_SAFETY", oter_flags::source_safety }, + { "SOURCE_TAILORING", oter_flags::source_tailoring }, + { "SOURCE_VEHICLES", oter_flags::source_vehicles }, + { "SOURCE_WEAPON", oter_flags::source_weapon } }; class overmap From d6899ff15cfcbefd0974a18c7be82106a44192b8 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Fri, 29 May 2020 14:02:31 +0300 Subject: [PATCH 4/5] Make input_event_t a class enum --- src/action.cpp | 2 +- src/game.cpp | 4 +- src/input.cpp | 42 ++++++++-------- src/input.h | 16 +++---- src/mutation_ui.cpp | 6 +-- src/ncurses_def.cpp | 20 ++++---- src/npctrade.cpp | 4 +- src/output.cpp | 2 +- src/popup.cpp | 4 +- src/savegame.cpp | 2 +- src/sdltiles.cpp | 98 +++++++++++++++++++------------------- src/string_input_popup.cpp | 2 +- src/wincurse.cpp | 8 ++-- 13 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/action.cpp b/src/action.cpp index 087c85bd45915..e8377756d89e7 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -120,7 +120,7 @@ std::vector keys_bound_to( action_id act, const bool restrict_to_printable action_id action_from_key( char ch ) { input_context ctxt = get_default_mode_input_context(); - const input_event event( ch, CATA_INPUT_KEYBOARD ); + const input_event event( ch, input_event_t::keyboard ); const std::string &action = ctxt.input_to_action( event ); return look_up_action( action ); } diff --git a/src/game.cpp b/src/game.cpp index bb05678f50cf7..b13ced7ba1fa8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2383,7 +2383,7 @@ std::pair game::mouse_edge_scrolling( input_context &ctxt, c last_mouse_edge_scroll = now; } const input_event event = ctxt.get_raw_input(); - if( event.type == CATA_INPUT_MOUSE ) { + if( event.type == input_event_t::mouse ) { const int threshold_x = projected_window_width() / 100; const int threshold_y = projected_window_height() / 100; if( event.mouse_pos.x <= threshold_x ) { @@ -2409,7 +2409,7 @@ std::pair game::mouse_edge_scrolling( input_context &ctxt, c } } ret.second = ret.first; - } else if( event.type == CATA_INPUT_TIMEOUT ) { + } else if( event.type == input_event_t::timeout ) { ret.first = ret.second; } #endif diff --git a/src/input.cpp b/src/input.cpp index 9ff9c5321c23d..7e17cb6682190 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -157,7 +157,7 @@ void input_manager::init() action_contexts[action_id].clear(); touched.insert( a.second ); } - add_input_for_action( action_id, context, input_event( a.first, CATA_INPUT_KEYBOARD ) ); + add_input_for_action( action_id, context, input_event( a.first, input_event_t::keyboard ) ); } // Unmap actions that are explicitly not mapped for( const auto &elem : unbound_keymap ) { @@ -223,11 +223,11 @@ void input_manager::load( const std::string &file_name, bool is_user_preferences std::string input_method = keybinding.get_string( "input_method" ); input_event new_event; if( input_method == "keyboard" ) { - new_event.type = CATA_INPUT_KEYBOARD; + new_event.type = input_event_t::keyboard; } else if( input_method == "gamepad" ) { - new_event.type = CATA_INPUT_GAMEPAD; + new_event.type = input_event_t::gamepad; } else if( input_method == "mouse" ) { - new_event.type = CATA_INPUT_MOUSE; + new_event.type = input_event_t::mouse; } if( keybinding.has_array( "key" ) ) { @@ -292,13 +292,13 @@ void input_manager::save() for( const auto &event : events ) { jsout.start_object(); switch( event.type ) { - case CATA_INPUT_KEYBOARD: + case input_event_t::keyboard: jsout.member( "input_method", "keyboard" ); break; - case CATA_INPUT_GAMEPAD: + case input_event_t::gamepad: jsout.member( "input_method", "gamepad" ); break; - case CATA_INPUT_MOUSE: + case input_event_t::mouse: jsout.member( "input_method", "mouse" ); break; default: @@ -409,7 +409,7 @@ int input_manager::get_keycode( const std::string &name ) const std::string input_manager::get_keyname( int ch, input_event_t inp_type, bool portable ) const { cata::optional raw; - if( inp_type == CATA_INPUT_KEYBOARD ) { + if( inp_type == input_event_t::keyboard ) { const t_key_to_name_map::const_iterator a = keycode_to_keyname.find( ch ); if( a != keycode_to_keyname.end() ) { if( IS_F_KEY( ch ) ) { @@ -426,7 +426,7 @@ std::string input_manager::get_keyname( int ch, input_event_t inp_type, bool por } raw = a->second; } - } else if( inp_type == CATA_INPUT_MOUSE ) { + } else if( inp_type == input_event_t::mouse ) { if( ch == MOUSE_BUTTON_LEFT ) { raw = translate_marker_context( "key name", "MOUSE_LEFT" ); } else if( ch == MOUSE_BUTTON_RIGHT ) { @@ -438,7 +438,7 @@ std::string input_manager::get_keyname( int ch, input_event_t inp_type, bool por } else if( ch == MOUSE_MOVE ) { raw = translate_marker_context( "key name", "MOUSE_MOVE" ); } - } else if( inp_type == CATA_INPUT_GAMEPAD ) { + } else if( inp_type == input_event_t::gamepad ) { const t_key_to_name_map::const_iterator a = gamepad_keycode_to_keyname.find( ch ); if( a != gamepad_keycode_to_keyname.end() ) { raw = a->second; @@ -693,7 +693,7 @@ std::vector input_context::keys_bound_to( const std::string &action_descri for( const auto &events_event : events ) { // Ignore multi-key input and non-keyboard input // TODO: fix for Unicode. - if( events_event.type == CATA_INPUT_KEYBOARD && events_event.sequence.size() == 1 ) { + if( events_event.type == input_event_t::keyboard && events_event.sequence.size() == 1 ) { if( !restrict_to_printable || ( events_event.sequence.front() < 0xFF && isprint( events_event.sequence.front() ) ) ) { result.push_back( static_cast( events_event.sequence.front() ) ); @@ -718,7 +718,7 @@ std::string input_context::get_available_single_char_hotkeys( std::string reques category ); for( const auto &events_event : events ) { // Only consider keyboard events without modifiers - if( events_event.type == CATA_INPUT_KEYBOARD && events_event.modifiers.empty() ) { + if( events_event.type == input_event_t::keyboard && events_event.modifiers.empty() ) { requested_keys.erase( std::remove_if( requested_keys.begin(), requested_keys.end(), ContainsPredicate, char>( events_event.sequence ) ), @@ -732,7 +732,7 @@ std::string input_context::get_available_single_char_hotkeys( std::string reques const input_context::input_event_filter input_context::disallow_lower_case = []( const input_event &evt ) -> bool { - return evt.type != CATA_INPUT_KEYBOARD || + return evt.type != input_event_t::keyboard || // std::lower from is undefined outside unsigned char range // and std::lower from may throw bad_cast for some locales evt.get_first_input() < 'a' || evt.get_first_input() > 'z'; @@ -765,7 +765,7 @@ std::string input_context::get_desc( const std::string &action_descriptor, if( evt_filter( event ) && // Only display gamepad buttons if a gamepad is available. - ( gamepad_available() || event.type != CATA_INPUT_GAMEPAD ) ) { + ( gamepad_available() || event.type != input_event_t::gamepad ) ) { inputs_to_show.push_back( event ); } @@ -811,10 +811,10 @@ std::string input_context::get_desc( const std::string &action_descriptor, for( const auto &evt : events ) { if( evt_filter( evt ) && // Only display gamepad buttons if a gamepad is available. - ( gamepad_available() || evt.type != CATA_INPUT_GAMEPAD ) ) { + ( gamepad_available() || evt.type != input_event_t::gamepad ) ) { na = false; - if( evt.type == CATA_INPUT_KEYBOARD && evt.sequence.size() == 1 ) { + if( evt.type == input_event_t::keyboard && evt.sequence.size() == 1 ) { const int ch = evt.get_first_input(); const std::string key = utf32_to_utf8( ch ); const auto pos = ci_find_substr( text, key ); @@ -852,11 +852,11 @@ const std::string &input_context::handle_input( const int timeout ) if( timeout >= 0 ) { inp_mngr.set_timeout( timeout ); } - next_action.type = CATA_INPUT_ERROR; + next_action.type = input_event_t::error; const std::string *result = &CATA_ERROR; while( true ) { next_action = inp_mngr.get_input_event(); - if( next_action.type == CATA_INPUT_TIMEOUT ) { + if( next_action.type == input_event_t::timeout ) { result = &TIMEOUT; break; } @@ -872,7 +872,7 @@ const std::string &input_context::handle_input( const int timeout ) break; } - if( next_action.type == CATA_INPUT_MOUSE ) { + if( next_action.type == input_event_t::mouse ) { if( !handling_coordinate_input && action == CATA_ERROR ) { continue; // Ignore this mouse input. } @@ -1306,13 +1306,13 @@ void input_manager::wait_for_any_key() while( true ) { const input_event evt = inp_mngr.get_input_event(); switch( evt.type ) { - case CATA_INPUT_KEYBOARD: + case input_event_t::keyboard: if( !evt.sequence.empty() ) { return; } break; // errors are accepted as well to avoid an infinite loop - case CATA_INPUT_ERROR: + case input_event_t::error: return; default: break; diff --git a/src/input.h b/src/input.h index c8e434343c2c6..8e8c930347dfb 100644 --- a/src/input.h +++ b/src/input.h @@ -76,12 +76,12 @@ std::string get_input_string_from_file( const std::string &fname = "input.txt" ) enum mouse_buttons { MOUSE_BUTTON_LEFT = 1, MOUSE_BUTTON_RIGHT, SCROLLWHEEL_UP, SCROLLWHEEL_DOWN, MOUSE_MOVE }; -enum input_event_t { - CATA_INPUT_ERROR, - CATA_INPUT_TIMEOUT, - CATA_INPUT_KEYBOARD, - CATA_INPUT_GAMEPAD, - CATA_INPUT_MOUSE +enum class input_event_t : int { + error, + timeout, + keyboard, + gamepad, + mouse }; /** @@ -116,7 +116,7 @@ struct input_event { #endif input_event() : edit_refresh( false ) { - type = CATA_INPUT_ERROR; + type = input_event_t::error; #if defined(__ANDROID__) shortcut_last_used_action_counter = 0; #endif @@ -675,7 +675,7 @@ class input_context * Sets input polling timeout as appropriate for the current interface system. * Use this method to set timeouts when using input_context, rather than calling * the old timeout() method or using input_manager::(re)set_timeout, as using - * this method will cause CATA_INPUT_TIMEOUT events to be generated correctly, + * this method will cause input_event_t::timeout events to be generated correctly, * and will reset timeout correctly when a new input context is entered. */ void set_timeout( int val ); diff --git a/src/mutation_ui.cpp b/src/mutation_ui.cpp index afefb5f329339..3a6c13659e94e 100644 --- a/src/mutation_ui.cpp +++ b/src/mutation_ui.cpp @@ -277,7 +277,7 @@ void player::power_mutations() bool handled = false; const std::string action = ctxt.handle_input(); const input_event evt = ctxt.get_raw_input(); - if( evt.type == CATA_INPUT_KEYBOARD && !evt.sequence.empty() ) { + if( evt.type == input_event_t::keyboard && !evt.sequence.empty() ) { const int ch = evt.get_first_input(); const trait_id mut_id = trait_by_invlet( ch ); if( !mut_id.is_null() ) { @@ -295,7 +295,7 @@ void player::power_mutations() while( !pop_exit ) { const query_popup::result ret = pop.query(); bool pop_handled = false; - if( ret.evt.type == CATA_INPUT_KEYBOARD && !ret.evt.sequence.empty() ) { + if( ret.evt.type == input_event_t::keyboard && !ret.evt.sequence.empty() ) { const int newch = ret.evt.get_first_input(); if( mutation_chars.valid( newch ) ) { const trait_id other_mut_id = trait_by_invlet( newch ); @@ -312,7 +312,7 @@ void player::power_mutations() if( ret.action == "QUIT" ) { pop_exit = true; } else if( ret.action != "HELP_KEYBINDINGS" && - ret.evt.type == CATA_INPUT_KEYBOARD ) { + ret.evt.type == input_event_t::keyboard ) { popup( _( "Invalid mutation letter. Only those characters are valid:\n\n%s" ), mutation_chars.get_allowed_chars() ); } diff --git a/src/ncurses_def.cpp b/src/ncurses_def.cpp index 0338176f17b93..08cf0e2bdfb20 100644 --- a/src/ncurses_def.cpp +++ b/src/ncurses_def.cpp @@ -256,9 +256,9 @@ input_event input_manager::get_input_event() rval = input_event(); if( key == ERR ) { if( input_timeout > 0 ) { - rval.type = CATA_INPUT_TIMEOUT; + rval.type = input_event_t::timeout; } else { - rval.type = CATA_INPUT_ERROR; + rval.type = input_event_t::error; } // ncurses mouse handling } else if( key == KEY_RESIZE ) { @@ -266,7 +266,7 @@ input_event input_manager::get_input_event() } else if( key == KEY_MOUSE ) { MEVENT event; if( getmouse( &event ) == OK ) { - rval.type = CATA_INPUT_MOUSE; + rval.type = input_event_t::mouse; rval.mouse_pos = point( event.x, event.y ); if( event.bstate & BUTTON1_CLICKED ) { rval.add_input( MOUSE_BUTTON_LEFT ); @@ -279,17 +279,17 @@ input_event input_manager::get_input_event() set_timeout( input_timeout ); } } else { - rval.type = CATA_INPUT_ERROR; + rval.type = input_event_t::error; } } else { - rval.type = CATA_INPUT_ERROR; + rval.type = input_event_t::error; } } else { if( key == 127 ) { // == Unicode DELETE previously_pressed_key = KEY_BACKSPACE; - return input_event( KEY_BACKSPACE, CATA_INPUT_KEYBOARD ); + return input_event( KEY_BACKSPACE, input_event_t::keyboard ); } - rval.type = CATA_INPUT_KEYBOARD; + rval.type = input_event_t::keyboard; rval.text.append( 1, static_cast( key ) ); // Read the UTF-8 sequence (if any) if( key < 127 ) { @@ -307,7 +307,7 @@ input_event input_manager::get_input_event() // Other control character, etc. - no text at all, return an event // without the text property previously_pressed_key = key; - return input_event( key, CATA_INPUT_KEYBOARD ); + return input_event( key, input_event_t::keyboard ); } // Now we have loaded an UTF-8 sequence (possibly several bytes) // but we should only return *one* key, so return the code point of it. @@ -316,7 +316,7 @@ input_event input_manager::get_input_event() // Invalid UTF-8 sequence, this should never happen, what now? // Maybe return any error instead? previously_pressed_key = key; - return input_event( key, CATA_INPUT_KEYBOARD ); + return input_event( key, input_event_t::keyboard ); } previously_pressed_key = cp; // for compatibility only add the first byte, not the code point @@ -331,7 +331,7 @@ input_event input_manager::get_input_event() void input_manager::set_timeout( const int delay ) { timeout( delay ); - // Use this to determine when curses should return a CATA_INPUT_TIMEOUT event. + // Use this to determine when curses should return a input_event_t::timeout event. input_timeout = delay; } diff --git a/src/npctrade.cpp b/src/npctrade.cpp index d54abc50b96d0..f196c0dff6dc3 100644 --- a/src/npctrade.cpp +++ b/src/npctrade.cpp @@ -425,7 +425,7 @@ void trading_window::show_item_data( size_t offset, exit = true; } else if( action == "ANY_INPUT" ) { const input_event evt = ctxt.get_raw_input(); - if( evt.type != CATA_INPUT_KEYBOARD || evt.sequence.empty() ) { + if( evt.type != input_event_t::keyboard || evt.sequence.empty() ) { continue; } size_t help = evt.get_first_input(); @@ -560,7 +560,7 @@ bool trading_window::perform_trade( npc &np, const std::string &deal ) confirm = false; } else if( action == "ANY_INPUT" ) { const input_event evt = ctxt.get_raw_input(); - if( evt.type != CATA_INPUT_KEYBOARD || evt.sequence.empty() ) { + if( evt.type != input_event_t::keyboard || evt.sequence.empty() ) { continue; } size_t ch = evt.get_first_input(); diff --git a/src/output.cpp b/src/output.cpp index 19cd4cad19678..a05d242e9f638 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -759,7 +759,7 @@ int popup( const std::string &text, PopupFlags flags ) pop.context( "POPUP_WAIT" ); const auto &res = pop.query(); - if( res.evt.type == CATA_INPUT_KEYBOARD ) { + if( res.evt.type == input_event_t::keyboard ) { return res.evt.get_first_input(); } else { return UNKNOWN_UNICODE; diff --git a/src/popup.cpp b/src/popup.cpp index e2457776075eb..7c96ec58851b0 100644 --- a/src/popup.cpp +++ b/src/popup.cpp @@ -298,9 +298,9 @@ query_popup::result query_popup::query_once() res.evt = ctxt.get_raw_input(); } while( // Always ignore mouse movement - ( res.evt.type == CATA_INPUT_MOUSE && res.evt.get_first_input() == MOUSE_MOVE ) || + ( res.evt.type == input_event_t::mouse && res.evt.get_first_input() == MOUSE_MOVE ) || // Ignore window losing focus in SDL - ( res.evt.type == CATA_INPUT_KEYBOARD && res.evt.sequence.empty() ) + ( res.evt.type == input_event_t::keyboard && res.evt.sequence.empty() ) ); if( cancel && res.action == "QUIT" ) { diff --git a/src/savegame.cpp b/src/savegame.cpp index dbf46a816da4e..4f97c04ba4333 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -286,7 +286,7 @@ void game::load_shortcuts( std::istream &fin ) for( const JsonMember &member : data.get_object( "quick_shortcuts" ) ) { std::list &qslist = quick_shortcuts_map[member.name()]; for( const int i : member.get_array() ) { - qslist.push_back( input_event( i, CATA_INPUT_KEYBOARD ) ); + qslist.push_back( input_event( i, input_event_t::keyboard ) ); } } } diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index cba00c3fb1603..4a9ef679b2a38 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -1515,7 +1515,7 @@ static int HandleDPad() return 0; } - last_input = input_event( lc, CATA_INPUT_GAMEPAD ); + last_input = input_event( lc, input_event_t::gamepad ); lastdpad = lc; queued_dpad = ERR; @@ -1535,7 +1535,7 @@ static int HandleDPad() // If we didn't hold it down for a while, just // fire the last registered press. if( queued_dpad != ERR ) { - last_input = input_event( queued_dpad, CATA_INPUT_GAMEPAD ); + last_input = input_event( queued_dpad, input_event_t::gamepad ); queued_dpad = ERR; return 1; } @@ -2010,7 +2010,7 @@ int choose_best_key_for_action( const std::string &action, const std::string &ca const std::vector &events = inp_mngr.get_input_for_action( action, category ); int best_key = -1; for( const auto &events_event : events ) { - if( events_event.type == CATA_INPUT_KEYBOARD && events_event.sequence.size() == 1 ) { + if( events_event.type == input_event_t::keyboard && events_event.sequence.size() == 1 ) { bool is_ascii_char = isprint( events_event.sequence.front() ) && events_event.sequence.front() < 0xFF; bool is_best_ascii_char = best_key >= 0 && isprint( best_key ) && best_key < 0xFF; @@ -2026,7 +2026,7 @@ bool add_key_to_quick_shortcuts( int key, const std::string &category, bool back { if( key > 0 ) { quick_shortcuts_t &qsl = quick_shortcuts_map[get_quick_shortcut_name( category )]; - input_event event = input_event( key, CATA_INPUT_KEYBOARD ); + input_event event = input_event( key, input_event_t::keyboard ); quick_shortcuts_t::iterator it = std::find( qsl.begin(), qsl.end(), event ); if( it != qsl.end() ) { // already exists ( *it ).shortcut_last_used_action_counter = @@ -2199,7 +2199,7 @@ void draw_quick_shortcuts() std::vector ®istered_manual_keys = touch_input_context.get_registered_manual_keys(); for( const auto &manual_key : registered_manual_keys ) { - input_event event( manual_key.key, CATA_INPUT_KEYBOARD ); + input_event event( manual_key.key, input_event_t::keyboard ); add_quick_shortcut( qsl, event, !shortcut_right, true ); } } @@ -2440,56 +2440,56 @@ void handle_finger_input( uint32_t ticks ) WindowHeight ) ) ) { if( !handle_diagonals ) { if( delta_x >= 0 && delta_y >= 0 ) { - last_input = input_event( delta_x > delta_y ? KEY_RIGHT : KEY_DOWN, CATA_INPUT_KEYBOARD ); + last_input = input_event( delta_x > delta_y ? KEY_RIGHT : KEY_DOWN, input_event_t::keyboard ); } else if( delta_x < 0 && delta_y >= 0 ) { - last_input = input_event( -delta_x > delta_y ? KEY_LEFT : KEY_DOWN, CATA_INPUT_KEYBOARD ); + last_input = input_event( -delta_x > delta_y ? KEY_LEFT : KEY_DOWN, input_event_t::keyboard ); } else if( delta_x >= 0 && delta_y < 0 ) { - last_input = input_event( delta_x > -delta_y ? KEY_RIGHT : KEY_UP, CATA_INPUT_KEYBOARD ); + last_input = input_event( delta_x > -delta_y ? KEY_RIGHT : KEY_UP, input_event_t::keyboard ); } else if( delta_x < 0 && delta_y < 0 ) { - last_input = input_event( -delta_x > -delta_y ? KEY_LEFT : KEY_UP, CATA_INPUT_KEYBOARD ); + last_input = input_event( -delta_x > -delta_y ? KEY_LEFT : KEY_UP, input_event_t::keyboard ); } } else { if( delta_x > 0 ) { if( std::abs( delta_y ) < delta_x * 0.5f ) { // swipe right - last_input = input_event( KEY_RIGHT, CATA_INPUT_KEYBOARD ); + last_input = input_event( KEY_RIGHT, input_event_t::keyboard ); } else if( std::abs( delta_y ) < delta_x * 2.0f ) { if( delta_y < 0 ) { // swipe up-right - last_input = input_event( JOY_RIGHTUP, CATA_INPUT_GAMEPAD ); + last_input = input_event( JOY_RIGHTUP, input_event_t::gamepad ); } else { // swipe down-right - last_input = input_event( JOY_RIGHTDOWN, CATA_INPUT_GAMEPAD ); + last_input = input_event( JOY_RIGHTDOWN, input_event_t::gamepad ); } } else { if( delta_y < 0 ) { // swipe up - last_input = input_event( KEY_UP, CATA_INPUT_KEYBOARD ); + last_input = input_event( KEY_UP, input_event_t::keyboard ); } else { // swipe down - last_input = input_event( KEY_DOWN, CATA_INPUT_KEYBOARD ); + last_input = input_event( KEY_DOWN, input_event_t::keyboard ); } } } else { if( std::abs( delta_y ) < -delta_x * 0.5f ) { // swipe left - last_input = input_event( KEY_LEFT, CATA_INPUT_KEYBOARD ); + last_input = input_event( KEY_LEFT, input_event_t::keyboard ); } else if( std::abs( delta_y ) < -delta_x * 2.0f ) { if( delta_y < 0 ) { // swipe up-left - last_input = input_event( JOY_LEFTUP, CATA_INPUT_GAMEPAD ); + last_input = input_event( JOY_LEFTUP, input_event_t::gamepad ); } else { // swipe down-left - last_input = input_event( JOY_LEFTDOWN, CATA_INPUT_GAMEPAD ); + last_input = input_event( JOY_LEFTDOWN, input_event_t::gamepad ); } } else { if( delta_y < 0 ) { // swipe up - last_input = input_event( KEY_UP, CATA_INPUT_KEYBOARD ); + last_input = input_event( KEY_UP, input_event_t::keyboard ); } else { // swipe down - last_input = input_event( KEY_DOWN, CATA_INPUT_KEYBOARD ); + last_input = input_event( KEY_DOWN, input_event_t::keyboard ); } } } @@ -2501,13 +2501,13 @@ void handle_finger_input( uint32_t ticks ) // We only allow repeats for waiting, not confirming in menus as that's a bit silly if( is_default_mode ) { last_input = input_event( get_key_event_from_string( get_option( "ANDROID_TAP_KEY" ) ), - CATA_INPUT_KEYBOARD ); + input_event_t::keyboard ); } } else { if( last_tap_time > 0 && ticks - last_tap_time < static_cast( get_option( "ANDROID_INITIAL_DELAY" ) ) ) { // Double tap - last_input = input_event( is_default_mode ? KEY_ESCAPE : KEY_ESCAPE, CATA_INPUT_KEYBOARD ); + last_input = input_event( is_default_mode ? KEY_ESCAPE : KEY_ESCAPE, input_event_t::keyboard ); last_tap_time = 0; } else { // First tap detected, waiting to decide whether it's a single or a double tap input @@ -2822,7 +2822,7 @@ static void CheckMessages() // Single tap last_tap_time = ticks; last_input = input_event( is_default_mode ? get_key_event_from_string( - get_option( "ANDROID_TAP_KEY" ) ) : '\n', CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_TAP_KEY" ) ) : '\n', input_event_t::keyboard ); last_tap_time = 0; return; } @@ -2917,7 +2917,7 @@ static void CheckMessages() } else if( add_alt_code( lc ) ) { // key was handled } else { - last_input = input_event( lc, CATA_INPUT_KEYBOARD ); + last_input = input_event( lc, input_event_t::keyboard ); #if defined(__ANDROID__) if( !android_is_hardware_keyboard_available() ) { if( !is_string_input( touch_input_context ) && !touch_input_context.allow_text_entry ) { @@ -2926,7 +2926,7 @@ static void CheckMessages() } // add a quick shortcut - if( !last_input.text.empty() || !inp_mngr.get_keyname( lc, CATA_INPUT_KEYBOARD ).empty() ) { + if( !last_input.text.empty() || !inp_mngr.get_keyname( lc, input_event_t::keyboard ).empty() ) { qsl.remove( last_input ); add_quick_shortcut( qsl, last_input, false, true ); refresh_display(); @@ -2960,7 +2960,7 @@ static void CheckMessages() if( ev.key.keysym.sym == SDLK_LALT || ev.key.keysym.sym == SDLK_RALT ) { int code = end_alt_code(); if( code ) { - last_input = input_event( code, CATA_INPUT_KEYBOARD ); + last_input = input_event( code, input_event_t::keyboard ); last_input.text = utf32_to_utf8( code ); } } @@ -2970,7 +2970,7 @@ static void CheckMessages() if( !add_alt_code( *ev.text.text ) ) { if( strlen( ev.text.text ) > 0 ) { const unsigned lc = UTF8_getch( ev.text.text ); - last_input = input_event( lc, CATA_INPUT_KEYBOARD ); + last_input = input_event( lc, input_event_t::keyboard ); #if defined(__ANDROID__) if( !android_is_hardware_keyboard_available() ) { if( !is_string_input( touch_input_context ) && !touch_input_context.allow_text_entry ) { @@ -2993,7 +2993,7 @@ static void CheckMessages() } else { // no key pressed in this event last_input = input_event(); - last_input.type = CATA_INPUT_KEYBOARD; + last_input.type = input_event_t::keyboard; } last_input.text = ev.text.text; text_refresh = true; @@ -3002,11 +3002,11 @@ static void CheckMessages() case SDL_TEXTEDITING: { if( strlen( ev.edit.text ) > 0 ) { const unsigned lc = UTF8_getch( ev.edit.text ); - last_input = input_event( lc, CATA_INPUT_KEYBOARD ); + last_input = input_event( lc, input_event_t::keyboard ); } else { // no key pressed in this event last_input = input_event(); - last_input.type = CATA_INPUT_KEYBOARD; + last_input.type = input_event_t::keyboard; } last_input.edit = ev.edit.text; last_input.edit_refresh = true; @@ -3014,7 +3014,7 @@ static void CheckMessages() } break; case SDL_JOYBUTTONDOWN: - last_input = input_event( ev.jbutton.button, CATA_INPUT_KEYBOARD ); + last_input = input_event( ev.jbutton.button, input_event_t::keyboard ); break; case SDL_JOYAXISMOTION: // on gamepads, the axes are the analog sticks @@ -3028,26 +3028,26 @@ static void CheckMessages() } // Only monitor motion when cursor is visible - last_input = input_event( MOUSE_MOVE, CATA_INPUT_MOUSE ); + last_input = input_event( MOUSE_MOVE, input_event_t::mouse ); } break; case SDL_MOUSEBUTTONUP: switch( ev.button.button ) { case SDL_BUTTON_LEFT: - last_input = input_event( MOUSE_BUTTON_LEFT, CATA_INPUT_MOUSE ); + last_input = input_event( MOUSE_BUTTON_LEFT, input_event_t::mouse ); break; case SDL_BUTTON_RIGHT: - last_input = input_event( MOUSE_BUTTON_RIGHT, CATA_INPUT_MOUSE ); + last_input = input_event( MOUSE_BUTTON_RIGHT, input_event_t::mouse ); break; } break; case SDL_MOUSEWHEEL: if( ev.wheel.y > 0 ) { - last_input = input_event( SCROLLWHEEL_UP, CATA_INPUT_MOUSE ); + last_input = input_event( SCROLLWHEEL_UP, input_event_t::mouse ); } else if( ev.wheel.y < 0 ) { - last_input = input_event( SCROLLWHEEL_DOWN, CATA_INPUT_MOUSE ); + last_input = input_event( SCROLLWHEEL_DOWN, input_event_t::mouse ); } break; @@ -3143,7 +3143,7 @@ static void CheckMessages() if( std::max( d1, d2 ) < get_option( "ANDROID_DEADZONE_RANGE" ) * longest_window_edge ) { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_2_TAP_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_2_TAP_KEY" ) ), input_event_t::keyboard ); } else { float dot = ( x1 * x2 + y1 * y2 ) / ( d1 * d2 ); // dot product of two finger vectors, -1 to +1 if( dot > 0.0f ) { // both fingers mostly heading in same direction, check for double-finger swipe gesture @@ -3156,16 +3156,16 @@ static void CheckMessages() float yavg = 0.5f * ( y1 + y2 ); if( xavg > 0 && xavg > std::abs( yavg ) ) { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_2_SWIPE_LEFT_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_2_SWIPE_LEFT_KEY" ) ), input_event_t::keyboard ); } else if( xavg < 0 && -xavg > std::abs( yavg ) ) { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_2_SWIPE_RIGHT_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_2_SWIPE_RIGHT_KEY" ) ), input_event_t::keyboard ); } else if( yavg > 0 && yavg > std::abs( xavg ) ) { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_2_SWIPE_DOWN_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_2_SWIPE_DOWN_KEY" ) ), input_event_t::keyboard ); } else { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_2_SWIPE_UP_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_2_SWIPE_UP_KEY" ) ), input_event_t::keyboard ); } } } else { @@ -3181,10 +3181,10 @@ static void CheckMessages() const float zoom_ratio = 0.9f; if( curr_dist < down_dist * zoom_ratio ) { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_PINCH_IN_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_PINCH_IN_KEY" ) ), input_event_t::keyboard ); } else if( curr_dist > down_dist / zoom_ratio ) { last_input = input_event( get_key_event_from_string( - get_option( "ANDROID_PINCH_OUT_KEY" ) ), CATA_INPUT_KEYBOARD ); + get_option( "ANDROID_PINCH_OUT_KEY" ) ), input_event_t::keyboard ); } } } @@ -3667,11 +3667,11 @@ input_event input_manager::get_input_event() if( inputdelay < 0 ) { do { CheckMessages(); - if( last_input.type != CATA_INPUT_ERROR ) { + if( last_input.type != input_event_t::error ) { break; } SDL_Delay( 1 ); - } while( last_input.type == CATA_INPUT_ERROR ); + } while( last_input.type == input_event_t::error ); } else if( inputdelay > 0 ) { uint32_t starttime = SDL_GetTicks(); uint32_t endtime = 0; @@ -3679,29 +3679,29 @@ input_event input_manager::get_input_event() do { CheckMessages(); endtime = SDL_GetTicks(); - if( last_input.type != CATA_INPUT_ERROR ) { + if( last_input.type != input_event_t::error ) { break; } SDL_Delay( 1 ); timedout = endtime >= starttime + inputdelay; if( timedout ) { - last_input.type = CATA_INPUT_TIMEOUT; + last_input.type = input_event_t::timeout; } } while( !timedout ); } else { CheckMessages(); } - if( last_input.type == CATA_INPUT_MOUSE ) { + if( last_input.type == input_event_t::mouse ) { SDL_GetMouseState( &last_input.mouse_pos.x, &last_input.mouse_pos.y ); - } else if( last_input.type == CATA_INPUT_KEYBOARD ) { + } else if( last_input.type == input_event_t::keyboard ) { previously_pressed_key = last_input.get_first_input(); #if defined(__ANDROID__) android_vibrate(); #endif } #if defined(__ANDROID__) - else if( last_input.type == CATA_INPUT_GAMEPAD ) { + else if( last_input.type == input_event_t::gamepad ) { android_vibrate(); } #endif diff --git a/src/string_input_popup.cpp b/src/string_input_popup.cpp index dc9e0384193c6..3c87c98dfa301 100644 --- a/src/string_input_popup.cpp +++ b/src/string_input_popup.cpp @@ -373,7 +373,7 @@ const std::string &string_input_popup::query_string( const bool loop, const bool const std::string action = ctxt->handle_input(); const input_event ev = ctxt->get_raw_input(); - ch = ev.type == CATA_INPUT_KEYBOARD ? ev.get_first_input() : 0; + ch = ev.type == input_event_t::keyboard ? ev.get_first_input() : 0; if( callbacks[ch] ) { if( callbacks[ch]() ) { diff --git a/src/wincurse.cpp b/src/wincurse.cpp index 7dfb19ae025e2..bb651d6e4a17c 100644 --- a/src/wincurse.cpp +++ b/src/wincurse.cpp @@ -689,17 +689,17 @@ input_event input_manager::get_input_event() input_event rval; if( lastchar == ERR ) { if( input_timeout > 0 ) { - rval.type = CATA_INPUT_TIMEOUT; + rval.type = input_event_t::timeout; } else { - rval.type = CATA_INPUT_ERROR; + rval.type = input_event_t::error; } } else { // == Unicode DELETE if( lastchar == 127 ) { previously_pressed_key = KEY_BACKSPACE; - return input_event( KEY_BACKSPACE, CATA_INPUT_KEYBOARD ); + return input_event( KEY_BACKSPACE, input_event_t::keyboard ); } - rval.type = CATA_INPUT_KEYBOARD; + rval.type = input_event_t::keyboard; rval.text = utf32_to_utf8( lastchar ); previously_pressed_key = lastchar; // for compatibility only add the first byte, not the code point From 15c4e94bb5e2109ec7012772aacd3b9904694da4 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Fri, 29 May 2020 14:02:42 +0300 Subject: [PATCH 5/5] Make ot_match_type a class enum --- src/enums.h | 2 +- src/overmap.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/enums.h b/src/enums.h index 9b535ca85a1cf..9fe68e903990b 100644 --- a/src/enums.h +++ b/src/enums.h @@ -51,7 +51,7 @@ enum visibility_type { }; // Matching rules for comparing a string to an overmap terrain id. -enum ot_match_type { +enum class ot_match_type : int { // The provided string must completely match the overmap terrain id, including // linear direction suffixes for linear terrain types or rotation suffixes // for rotated terrain types. diff --git a/src/overmap.cpp b/src/overmap.cpp index c95b183b1be48..ca75fbd5856b3 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -4463,12 +4463,12 @@ std::string enum_to_string( ot_match_type data ) { switch( data ) { // *INDENT-OFF* - case exact: return "EXACT"; - case type: return "TYPE"; - case prefix: return "PREFIX"; - case contains: return "CONTAINS"; + case ot_match_type::exact: return "EXACT"; + case ot_match_type::type: return "TYPE"; + case ot_match_type::prefix: return "PREFIX"; + case ot_match_type::contains: return "CONTAINS"; // *INDENT-ON* - case num_ot_match_type: + case ot_match_type::num_ot_match_type: break; } debugmsg( "Invalid ot_match_type" );