Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace alot of raw strings in faction_camp.cpp and make use of static const where appropriate #72809

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 36 additions & 108 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_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" );
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" );
Expand Down Expand Up @@ -2425,75 +2400,32 @@ 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<std::string>( 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<oter_type_str_id, oter_type_str_id> clear_cut_conversion = {
{ oter_type_forest, oter_type_field },
{ oter_type_forest_thick, oter_type_field },
{ oter_type_forest_trail, oter_type_field },
{ 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() );
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() );
Expand All @@ -2502,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<std::string> 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<std::string> 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" );
Expand Down Expand Up @@ -2541,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<std::string> 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<std::string> 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" );
Expand Down
Loading