Skip to content

Commit

Permalink
clear basecamps for tests in clear_map()
Browse files Browse the repository at this point in the history
fix test npc_talk_location
  • Loading branch information
ShnitzelX2 committed Nov 24, 2024
1 parent bbc0d00 commit 7b59707
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/basecamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
25 changes: 16 additions & 9 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tripoint_abs_omt> &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<coords::sm>( omt_pos );
const tripoint_abs_ms ms_pos = coords::project_to<coords::ms>( 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();
Expand All @@ -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<tripoint_abs_omt> &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<coords::sm>( omt_pos );
const tripoint_abs_ms ms_pos = coords::project_to<coords::ms>( 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()
Expand Down
14 changes: 14 additions & 0 deletions tests/map_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -123,6 +124,18 @@ void clear_zones()
zm.clear();
}

void clear_basecamps()
{
std::optional<basecamp *> 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();
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/map_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/npc_talk_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down

0 comments on commit 7b59707

Please sign in to comment.