Skip to content

Commit

Permalink
Merge pull request #77162 from sparr/repeat_survey_mission_fewer_steps
Browse files Browse the repository at this point in the history
Repeat survey missions without leaving interface
  • Loading branch information
Maleclypse authored Oct 31, 2024
2 parents f5a220a + 0983f53 commit 1e1ce2c
Showing 1 changed file with 135 additions and 125 deletions.
260 changes: 135 additions & 125 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4485,72 +4485,77 @@ bool basecamp::survey_field_return( const mission_id &miss_id )
}

popup( _( "Select a tile up to %d tiles away." ), 1 );
const tripoint_abs_omt where( ui::omap::choose_point() );
if( where == overmap::invalid_tripoint ) {
return false;
}

int dist = rl_dist( where.xy(), omt_pos.xy() );
if( dist != 1 ) {
popup( _( "You must select a tile within %d range of the camp" ), 1 );
return false;
}
if( omt_pos.z() != where.z() ) {
popup( _( "Expansions must be on the same level as the camp" ) );
return false;
}
const point dir = talk_function::om_simple_dir( omt_pos, where );
if( expansions.find( dir ) != expansions.end() ) {
if( query_yn(
_( "You already have an expansion at that location. Do you want to finish this mission? If not, the mission remains active and another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
tripoint_abs_omt where( get_player_character().global_omt_location() );

while( true ) {
where = ui::omap::choose_point( where );
if( where == overmap::invalid_tripoint ) {
return false;
}
}

if( overmap_buffer.ter_existing( where ) == oter_id( "field" ) ) {
if( query_yn(
_( "This location is already a field. Do you want to finish this mission? If not, the mission remains active and another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
return false;
int dist = rl_dist( where.xy(), omt_pos.xy() );
if( dist != 1 ) {
popup( _( "You must select a tile within %d range of the camp" ), 1 );
continue;
}
if( omt_pos.z() != where.z() ) {
popup( _( "Expansions must be on the same level as the camp" ) );
continue;
}
const point dir = talk_function::om_simple_dir( omt_pos, where );
if( expansions.find( dir ) != expansions.end() ) {
if( query_yn(
_( "You already have an expansion at that location. Do you want to finish this mission? If not, another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}
}

tinymap target;
target.load( where, false );
int mismatch_tiles = 0;
const tripoint_omt_ms mapmin{ 0, 0, where.z() };
const tripoint_omt_ms mapmax = { 2 * SEEX - 1, 2 * SEEY - 1, where.z() };
const std::unordered_set<ter_str_id> match_terrains = { ter_t_clay, ter_t_dirt, ter_t_dirtmound, ter_t_grass, ter_t_grass_dead, ter_t_grass_golf, ter_t_grass_long, ter_t_grass_tall, ter_t_moss, ter_t_sand };
for( const tripoint_omt_ms &p : target.points_in_rectangle( mapmin, mapmax ) ) {
if( match_terrains.find( target.ter( p ).id() ) == match_terrains.end() ) {
mismatch_tiles++;
if( overmap_buffer.ter_existing( where ) == oter_id( "field" ) ) {
if( query_yn(
_( "This location is already a field. Do you want to finish this mission? If not, another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}

tinymap target;
target.load( where, false );
int mismatch_tiles = 0;
const tripoint_omt_ms mapmin{ 0, 0, where.z() };
const tripoint_omt_ms mapmax = { 2 * SEEX - 1, 2 * SEEY - 1, where.z() };
const std::unordered_set<ter_str_id> match_terrains = { ter_t_clay, ter_t_dirt, ter_t_dirtmound, ter_t_grass, ter_t_grass_dead, ter_t_grass_golf, ter_t_grass_long, ter_t_grass_tall, ter_t_moss, ter_t_sand };
for( const tripoint_omt_ms &p : target.points_in_rectangle( mapmin, mapmax ) ) {
if( match_terrains.find( target.ter( p ).id() ) == match_terrains.end() ) {
mismatch_tiles++;
}
}

if( mismatch_tiles > 0 ) {
if( query_yn(
_( "This location has %d tiles blocking it from being converted. Do you want to finish this mission? If not, another tile can be checked." ),
mismatch_tiles ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}
}

if( mismatch_tiles > 0 ) {
overmap_buffer.ter_set( where, oter_id( "field" ) );
if( query_yn(
_( "This location has %d tiles blocking it from being converted. Do you want to finish this mission? If not, the mission remains active and another tile can be checked." ),
mismatch_tiles ) ) {
_( "This location has now been converted into a field! Do you want to finish the mission? If not, another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
return false;
continue;
}
}

overmap_buffer.ter_set( where, oter_id( "field" ) );
if( query_yn(
_( "This location has now been converted into a field! Do you want to finish the mission? If not, the mission remains active and another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
return false;
}
}

bool basecamp::survey_return( const mission_id &miss_id )
Expand All @@ -4562,91 +4567,96 @@ bool basecamp::survey_return( const mission_id &miss_id )
}

popup( _( "Select a tile up to %d tiles away." ), 1 );
const tripoint_abs_omt where( ui::omap::choose_point() );
if( where == overmap::invalid_tripoint ) {
return false;
}

int dist = rl_dist( where.xy(), omt_pos.xy() );
if( dist != 1 ) {
popup( _( "You must select a tile within %d range of the camp" ), 1 );
return false;
}
if( omt_pos.z() != where.z() ) {
popup( _( "Expansions must be on the same level as the camp" ) );
return false;
}
const point dir = talk_function::om_simple_dir( omt_pos, where );
if( expansions.find( dir ) != expansions.end() ) {
if( query_yn(
_( "You already have an expansion at that location. Do you want to finish this mission? If not, the mission remains active and another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
tripoint_abs_omt where( get_player_character().global_omt_location() );

while( true ) {
where = ui::omap::choose_point( where );
if( where == overmap::invalid_tripoint ) {
return false;
}
}

const oter_id &omt_ref = overmap_buffer.ter( where );
const std::optional<mapgen_arguments> *maybe_args = overmap_buffer.mapgen_args( where );
const auto &pos_expansions = recipe_group::get_recipes_by_id( "all_faction_base_expansions",
omt_ref, maybe_args );
if( pos_expansions.empty() ) {
popup( _( "You can't build any expansions in a %s." ), omt_ref.id().c_str() );
if( query_yn(
_( "You can't build any expansion in a %s. Do you want to finish this mission? If not, the mission remains active and another tile can be checked." ),
omt_ref.id().c_str() ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
return false;
int dist = rl_dist( where.xy(), omt_pos.xy() );
if( dist != 1 ) {
popup( _( "You must select a tile within %d range of the camp" ), 1 );
continue;
}
if( omt_pos.z() != where.z() ) {
popup( _( "Expansions must be on the same level as the camp" ) );
continue;
}
const point dir = talk_function::om_simple_dir( omt_pos, where );
if( expansions.find( dir ) != expansions.end() ) {
if( query_yn(
_( "You already have an expansion at that location. Do you want to finish this mission? If not, another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}
}

const recipe_id expansion_type = base_camps::select_camp_option( pos_expansions,
_( "Select an expansion:" ) );
const oter_id &omt_ref = overmap_buffer.ter( where );
const std::optional<mapgen_arguments> *maybe_args = overmap_buffer.mapgen_args( where );
const auto &pos_expansions = recipe_group::get_recipes_by_id( "all_faction_base_expansions",
omt_ref, maybe_args );
if( pos_expansions.empty() ) {
if( query_yn(
_( "You can't build any expansion in a %s. Do you want to finish this mission? If not, another tile can be checked." ),
omt_ref.id().c_str() ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}

bool mirror_horizontal;
bool mirror_vertical;
int rotation;
const recipe_id expansion_type = base_camps::select_camp_option( pos_expansions,
_( "Select an expansion:" ) );

if( !extract_and_check_orientation_flags( expansion_type,
dir,
mirror_horizontal,
mirror_vertical,
rotation,
"%s failed to build the %s expansion",
comp->disp_name() ) ) {
if( query_yn(
_( "Do you want to finish this mission? If not, the mission remains active and another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
return false;
bool mirror_horizontal;
bool mirror_vertical;
int rotation;

if( expansion_type == recipe_id::NULL_ID() ||
!extract_and_check_orientation_flags( expansion_type,
dir,
mirror_horizontal,
mirror_vertical,
rotation,
"%s failed to build the %s expansion",
comp->disp_name() ) ) {
if( query_yn(
_( "Do you want to finish this mission? If not, another tile can be checked." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}
}

const ret_val<void> has_vehicle_collision = run_mapgen_update_func( update_mapgen_id(
expansion_type.str() ), where, {}, nullptr, true,
mirror_horizontal, mirror_vertical, rotation );
if( !has_vehicle_collision.success() ) {
popup( _( "%1$s failed to add the %2$s expansion, %3$s vehicle/appliance seems to be in the way." ),
comp->disp_name(),
expansion_type->blueprint_name(),
has_vehicle_collision.str() );
if( query_yn(
_( "Do you want to finish this mission? If not, the mission remains active and another tile can be checked (e.g. after clearing away the obstacle)." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
return false;
const ret_val<void> has_vehicle_collision = run_mapgen_update_func( update_mapgen_id(
expansion_type.str() ), where, {}, nullptr, true,
mirror_horizontal, mirror_vertical, rotation );
if( !has_vehicle_collision.success() ) {
popup( _( "%1$s failed to add the %2$s expansion, %3$s vehicle/appliance seems to be in the way." ),
comp->disp_name(),
expansion_type->blueprint_name(),
has_vehicle_collision.str() );
if( query_yn(
_( "Do you want to finish this mission? If not, another tile can be checked, or you can try again after clearing away the obstacle." ) ) ) {
finish_return( *comp, true, abort_msg, skill_construction.str(), 0 );
return true;
} else {
continue;
}
}
overmap_buffer.ter_set( where, oter_id( expansion_type.str() ) );
add_expansion( expansion_type.str(), where, dir );
const std::string msg = _( "returns from surveying for the expansion." );
finish_return( *comp, true, msg, skill_construction.str(), 2 );
return true;
}
overmap_buffer.ter_set( where, oter_id( expansion_type.str() ) );
add_expansion( expansion_type.str(), where, dir );
const std::string msg = _( "returns from surveying for the expansion." );
finish_return( *comp, true, msg, skill_construction.str(), 2 );
return true;
}

bool basecamp::farm_return( const mission_id &miss_id, const point &dir )
Expand Down

0 comments on commit 1e1ce2c

Please sign in to comment.