diff --git a/src/basecamp.h b/src/basecamp.h index aae7e83cc0d4e..1f2f9894df59d 100644 --- a/src/basecamp.h +++ b/src/basecamp.h @@ -205,6 +205,9 @@ class basecamp //change name of camp void set_name( const std::string &new_name ); void query_new_name( bool force = false ); + // remove the camp without safety checks; use abandon_camp() for in-game + void remove_camp( const tripoint_abs_omt &omt_pos ) const; + // remove the camp from an in-game context void abandon_camp(); void scan_pseudo_items(); void add_expansion( const std::string &terrain, const tripoint_abs_omt &new_pos ); diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 10a04ee913645..a05bf56db8d39 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -2165,6 +2165,21 @@ void basecamp::start_upgrade( const mission_id &miss_id ) } } +void basecamp::remove_camp( const tripoint_abs_omt &omt_pos ) const +{ + std::set &known_camps = get_player_character().camps; + known_camps.erase( omt_pos ); + + overmap_buffer.remove_camp( *this ); + + map &here = get_map(); + const tripoint_abs_sm sm_pos = coords::project_to( omt_pos ); + const tripoint_abs_ms ms_pos = coords::project_to( sm_pos ); + // We cannot use bb_pos here, because bb_pos may be {0,0,0} if you haven't examined the bulletin board on camp ever. + // here.remove_submap_camp( here.getlocal( bb_pos ) ); + here.remove_submap_camp( here.bub_from_abs( ms_pos ) ); +} + void basecamp::abandon_camp() { validate_assignees(); @@ -2181,15 +2196,7 @@ void basecamp::abandon_camp() } // We must send this message early, before the name is erased. add_msg( m_info, _( "You abandon %s." ), name ); - std::set &known_camps = get_player_character().camps; - known_camps.erase( omt_pos ); - overmap_buffer.remove_camp( *this ); - map &here = get_map(); - const tripoint_abs_sm sm_pos = coords::project_to( omt_pos ); - const tripoint_abs_ms ms_pos = coords::project_to( sm_pos ); - // We cannot use bb_pos here, because bb_pos may be {0,0,0} if you haven't examined the bulletin board on camp ever. - // here.remove_submap_camp( here.getlocal( bb_pos ) ); - here.remove_submap_camp( here.bub_from_abs( ms_pos ) ); + remove_camp( omt_pos ); } void basecamp::scan_pseudo_items() diff --git a/tests/map_helpers.cpp b/tests/map_helpers.cpp index aaf531365241c..a8c5eed643fef 100644 --- a/tests/map_helpers.cpp +++ b/tests/map_helpers.cpp @@ -22,6 +22,7 @@ #include "map_iterator.h" #include "mapdata.h" #include "npc.h" +#include "overmapbuffer.h" #include "pocket_type.h" #include "point.h" #include "ret_val.h" @@ -123,6 +124,18 @@ void clear_zones() zm.clear(); } +void clear_basecamps() +{ + std::optional camp; + do { + const tripoint_abs_omt &avatar_pos = get_avatar().global_omt_location(); + camp = overmap_buffer.find_camp( avatar_pos.xy() ); + if( camp && *camp != nullptr ) { + ( **camp ).remove_camp( avatar_pos ); + } + } while( camp ); +} + void clear_map( int zmin, int zmax ) { map &here = get_map(); @@ -140,6 +153,7 @@ void clear_map( int zmin, int zmax ) clear_items( z ); } here.process_items(); + clear_basecamps(); } void clear_map_and_put_player_underground() diff --git a/tests/map_helpers.h b/tests/map_helpers.h index 57dc3aa6326ce..2a04613e665bf 100644 --- a/tests/map_helpers.h +++ b/tests/map_helpers.h @@ -18,6 +18,7 @@ void clear_npcs(); void clear_fields( int zlevel ); void clear_items( int zlevel ); void clear_zones(); +void clear_basecamps(); void clear_map( int zmin = -2, int zmax = 0 ); void clear_radiation(); void clear_map_and_put_player_underground(); diff --git a/tests/npc_talk_test.cpp b/tests/npc_talk_test.cpp index e99a0d9aadf7f..16790e6e44028 100644 --- a/tests/npc_talk_test.cpp +++ b/tests/npc_talk_test.cpp @@ -336,6 +336,7 @@ TEST_CASE( "npc_talk_location", "[npc_talk]" ) dialogue d; prep_test( d ); + REQUIRE( !overmap_buffer.find_camp( get_avatar().global_omt_location().xy() ) ); change_om_type( "pond_field_north" ); d.add_topic( "TALK_TEST_LOCATION" ); d.gen_responses( d.topic_stack.back() );