From 2e3a8426610c5b9352917ac6fff16ac95ca36065 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:55:11 +0100 Subject: [PATCH 1/2] Yeet huge if else --- src/faction_camp.cpp | 131 ++++++++++--------------------------------- 1 file changed, 31 insertions(+), 100 deletions(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index c684287d8e94e..3d3cde1165e8a 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -103,40 +103,15 @@ static const mongroup_id GROUP_CAMP_HUNTING( "GROUP_CAMP_HUNTING" ); static const mongroup_id GROUP_CAMP_HUNTING_LARGE( "GROUP_CAMP_HUNTING_LARGE" ); static const mongroup_id GROUP_CAMP_TRAPPING( "GROUP_CAMP_TRAPPING" ); -static const oter_str_id oter_dirt_road_3way_forest_east( "dirt_road_3way_forest_east" ); -static const oter_str_id oter_dirt_road_3way_forest_north( "dirt_road_3way_forest_north" ); -static const oter_str_id oter_dirt_road_3way_forest_south( "dirt_road_3way_forest_south" ); -static const oter_str_id oter_dirt_road_3way_forest_west( "dirt_road_3way_forest_west" ); -static const oter_str_id oter_dirt_road_forest_east( "dirt_road_forest_east" ); -static const oter_str_id oter_dirt_road_forest_north( "dirt_road_forest_north" ); -static const oter_str_id oter_dirt_road_forest_south( "dirt_road_forest_south" ); -static const oter_str_id oter_dirt_road_forest_west( "dirt_road_forest_west" ); -static const oter_str_id oter_dirt_road_turn_forest_east( "dirt_road_turn_forest_east" ); -static const oter_str_id oter_dirt_road_turn_forest_north( "dirt_road_turn_forest_north" ); -static const oter_str_id oter_dirt_road_turn_forest_south( "dirt_road_turn_forest_south" ); -static const oter_str_id oter_dirt_road_turn_forest_west( "dirt_road_turn_forest_west" ); -static const oter_str_id oter_forest( "forest" ); -static const oter_str_id oter_forest_thick( "forest_thick" ); -static const oter_str_id oter_rural_road_3way_forest_east( "rural_road_3way_forest_east" ); -static const oter_str_id oter_rural_road_3way_forest_north( "rural_road_3way_forest_north" ); -static const oter_str_id oter_rural_road_3way_forest_south( "rural_road_3way_forest_south" ); -static const oter_str_id oter_rural_road_3way_forest_west( "rural_road_3way_forest_west" ); -static const oter_str_id oter_rural_road_forest_east( "rural_road_forest_east" ); -static const oter_str_id oter_rural_road_forest_north( "rural_road_forest_north" ); -static const oter_str_id oter_rural_road_forest_south( "rural_road_forest_south" ); -static const oter_str_id oter_rural_road_forest_west( "rural_road_forest_west" ); -static const oter_str_id oter_rural_road_turn1_forest_east( "rural_road_turn1_forest_east" ); -static const oter_str_id oter_rural_road_turn1_forest_north( "rural_road_turn1_forest_north" ); -static const oter_str_id oter_rural_road_turn1_forest_south( "rural_road_turn1_forest_south" ); -static const oter_str_id oter_rural_road_turn1_forest_west( "rural_road_turn1_forest_west" ); -static const oter_str_id oter_rural_road_turn_forest_east( "rural_road_turn_forest_east" ); -static const oter_str_id oter_rural_road_turn_forest_north( "rural_road_turn_forest_north" ); -static const oter_str_id oter_rural_road_turn_forest_south( "rural_road_turn_forest_south" ); -static const oter_str_id oter_rural_road_turn_forest_west( "rural_road_turn_forest_west" ); -static const oter_str_id oter_special_forest( "special_forest" ); -static const oter_str_id oter_special_forest_thick( "special_forest_thick" ); - +static const oter_type_str_id oter_type_field( "field" ); +static const oter_type_str_id oter_type_forest( "forest" ); +static const oter_type_str_id oter_type_forest_thick( "forest_thick" ); static const oter_type_str_id oter_type_forest_trail( "forest_trail" ); +static const oter_type_str_id oter_type_forest_water( "forest_water" ); +static const oter_type_str_id oter_type_rural_road( "rural_road" ); +static const oter_type_str_id oter_type_rural_road_forest( "rural_road_forest" ); +static const oter_type_str_id oter_type_special_forest( "special_forest" ); +static const oter_type_str_id oter_type_special_forest_thick( "special_forest_thick" ); static const skill_id skill_bashing( "bashing" ); static const skill_id skill_combat( "combat" ); @@ -2425,75 +2400,31 @@ static void change_cleared_terrain( tripoint_abs_omt forest ) { if( om_cutdown_trees_est( forest ) < 5 ) { const oter_id &omt_trees = overmap_buffer.ter( forest ); - const std::string omt_trees_string = static_cast( omt_trees.id() ); - - if( omt_trees_string.find( "dirt_road" ) != std::string::npos ) {} - - if( omt_trees.id() == oter_dirt_road_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_north" ) ); - } else if( omt_trees.id() == oter_dirt_road_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_east" ) ); - } else if( omt_trees.id() == oter_dirt_road_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_south" ) ); - } else if( omt_trees.id() == oter_dirt_road_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_west" ) ); - } else if( omt_trees.id() == oter_dirt_road_3way_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_3way_north" ) ); - } else if( omt_trees.id() == oter_dirt_road_3way_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_3way_east" ) ); - } else if( omt_trees.id() == oter_dirt_road_3way_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_3way_south" ) ); - } else if( omt_trees.id() == oter_dirt_road_3way_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_3way_west" ) ); - } else if( omt_trees.id() == oter_dirt_road_turn_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_turn_north" ) ); - } else if( omt_trees.id() == oter_dirt_road_turn_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_turn_east" ) ); - } else if( omt_trees.id() == oter_dirt_road_turn_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_turn_south" ) ); - } else if( omt_trees.id() == oter_dirt_road_turn_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "dirt_road_turn_west" ) ); - } - - else if( omt_trees.id() == oter_forest || omt_trees.id() == oter_forest_thick || - omt_trees.id() == oter_special_forest || omt_trees.id() == oter_special_forest_thick || - omt_trees_string.find( "forest_trail" ) != std::string::npos ) { - overmap_buffer.ter_set( forest, oter_id( "field" ) ); - } else if( omt_trees.id() == oter_rural_road_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_north" ) ); - } else if( omt_trees.id() == oter_rural_road_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_east" ) ); - } else if( omt_trees.id() == oter_rural_road_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_south" ) ); - } else if( omt_trees.id() == oter_rural_road_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_west" ) ); - } else if( omt_trees.id() == oter_rural_road_3way_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_3way_north" ) ); - } else if( omt_trees.id() == oter_rural_road_3way_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_3way_east" ) ); - } else if( omt_trees.id() == oter_rural_road_3way_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_3way_south" ) ); - } else if( omt_trees.id() == oter_rural_road_3way_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_3way_west" ) ); - } else if( omt_trees.id() == oter_rural_road_turn_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn_north" ) ); - } else if( omt_trees.id() == oter_rural_road_turn_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn_east" ) ); - } else if( omt_trees.id() == oter_rural_road_turn_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn_south" ) ); - } else if( omt_trees.id() == oter_rural_road_turn_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn_west" ) ); - } else if( omt_trees.id() == oter_rural_road_turn1_forest_north ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn1_north" ) ); - } else if( omt_trees.id() == oter_rural_road_turn1_forest_east ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn1_east" ) ); - } else if( omt_trees.id() == oter_rural_road_turn1_forest_south ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn1_south" ) ); - } else if( omt_trees.id() == oter_rural_road_turn1_forest_west ) { - overmap_buffer.ter_set( forest, oter_id( "rural_road_turn1_west" ) ); - } else { + + // Oter types before and after clear cutting, if value (after) is linear, key (before) should also be linear, otherwise any combination of rotatable/linear/not rotatable should work + const std::unordered_map clear_cut_conversion = { + { oter_type_forest, oter_type_field }, + { oter_type_forest_thick, oter_type_field }, + { oter_type_special_forest, oter_type_field }, + { oter_type_special_forest_thick, oter_type_field }, + { oter_type_forest_trail, oter_type_field }, + { oter_type_rural_road_forest, oter_type_rural_road } + }; + auto converted_it = clear_cut_conversion.find( omt_trees->get_type_id() ); + + if( converted_it == clear_cut_conversion.end() ) { popup( _( "%s isn't a recognized terrain. Please file a bug report." ), omt_trees.id().c_str() ); return; + } else { + const oter_type_str_id &oter_type_clearcut = converted_it->second; + oter_id oter_to_place; + // Maintain rotation + if( oter_type_clearcut->is_linear() ) { + oter_to_place = oter_type_clearcut->get_linear( omt_trees->get_line() ); + } else { + oter_to_place = oter_type_clearcut->get_rotated( omt_trees->get_dir() ); + } + overmap_buffer.ter_set( forest, oter_to_place ); } popup( _( "The logged tile has been cleared and cannot be logged further after this mission." ), omt_trees.id().c_str() ); From 52d9de42ae227126103cb7ce0475b3cbea5b6fd9 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:42:38 +0100 Subject: [PATCH 2/2] Update log sources --- src/faction_camp.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 3d3cde1165e8a..3286d007db718 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -107,7 +107,7 @@ static const oter_type_str_id oter_type_field( "field" ); static const oter_type_str_id oter_type_forest( "forest" ); static const oter_type_str_id oter_type_forest_thick( "forest_thick" ); static const oter_type_str_id oter_type_forest_trail( "forest_trail" ); -static const oter_type_str_id oter_type_forest_water( "forest_water" ); +static const oter_type_str_id oter_type_forest_trail_intersection( "forest_trail_intersection" ); static const oter_type_str_id oter_type_rural_road( "rural_road" ); static const oter_type_str_id oter_type_rural_road_forest( "rural_road_forest" ); static const oter_type_str_id oter_type_special_forest( "special_forest" ); @@ -2405,13 +2405,14 @@ static void change_cleared_terrain( tripoint_abs_omt forest ) const std::unordered_map clear_cut_conversion = { { oter_type_forest, oter_type_field }, { oter_type_forest_thick, oter_type_field }, - { oter_type_special_forest, oter_type_field }, - { oter_type_special_forest_thick, oter_type_field }, { oter_type_forest_trail, oter_type_field }, - { oter_type_rural_road_forest, oter_type_rural_road } + { oter_type_forest_trail_intersection, oter_type_field }, + { oter_type_rural_road_forest, oter_type_rural_road }, + { oter_type_special_forest, oter_type_field }, + { oter_type_special_forest_thick, oter_type_field } }; - auto converted_it = clear_cut_conversion.find( omt_trees->get_type_id() ); + auto converted_it = clear_cut_conversion.find( omt_trees->get_type_id() ); if( converted_it == clear_cut_conversion.end() ) { popup( _( "%s isn't a recognized terrain. Please file a bug report." ), omt_trees.id().c_str() ); return; @@ -2433,10 +2434,8 @@ static void change_cleared_terrain( tripoint_abs_omt forest ) void basecamp::start_cut_logs( const mission_id &miss_id, float exertion_level ) { - std::vector log_sources = { "forest", "forest_thick", "forest_trail", "rural_road_forest", "rural_road_turn_forest", "rural_road_turn1_forest", "rural_road_3way_forest", - "dirt_road_forest", "dirt_road_3way_forest", "dirt_road_turn_forest", "forest_trail_intersection", "special_forest", "special_forest_thick", "forest_trail_isolated", "forest_trail_end" - }; - popup( _( "Forests are the only valid cutting locations, with forest dirt roads, forest rural roads, and trails being valid as well. Note that it's likely both forest and field roads look exactly the same after having been cleared." ) ); + std::vector log_sources = { "forest", "forest_thick", "forest_trail", "forest_trail_intersection", "rural_road_forest", "special_forest", "special_forest_thick" }; + popup( _( "Forests, forest rural roads, and trails are the only valid cutting locations. Note that it's likely both forest and field roads look exactly the same after having been cleared." ) ); tripoint_abs_omt forest = om_target_tile( omt_pos, 1, 50, log_sources, ot_match_type::type ); if( forest != tripoint_abs_omt( -999, -999, -999 ) ) { standard_npc sample_npc( "Temp" ); @@ -2472,10 +2471,8 @@ void basecamp::start_cut_logs( const mission_id &miss_id, float exertion_level ) void basecamp::start_clearcut( const mission_id &miss_id, float exertion_level ) { - std::vector log_sources = { "forest", "forest_thick", "forest_trail", "rural_road_forest", "rural_road_turn_forest", "rural_road_turn1_forest", "rural_road_3way_forest", - "dirt_road_forest", "dirt_road_3way_forest", "dirt_road_turn_forest", "forest_trail_intersection", "special_forest", "special_forest_thick", "forest_trail_isolated", "forest_trail_end" - }; - popup( _( "Forests are the only valid cutting locations, with forest dirt roads, forest rural roads, and trails being valid as well. Note that it's likely both forest and field roads look exactly the same after having been cleared." ) ); + std::vector log_sources = { "forest", "forest_thick", "forest_trail", "forest_trail_intersection", "rural_road_forest", "special_forest", "special_forest_thick" }; + popup( _( "Forests, forest rural roads, and trails are the only valid cutting locations. Note that it's likely both forest and field roads look exactly the same after having been cleared." ) ); tripoint_abs_omt forest = om_target_tile( omt_pos, 1, 50, log_sources, ot_match_type::type ); if( forest != tripoint_abs_omt( -999, -999, -999 ) ) { standard_npc sample_npc( "Temp" );