Skip to content

Commit

Permalink
Fix various clear_map issues
Browse files Browse the repository at this point in the history
After CleverRaven#30051 clear_creatures no longer clears NPCs.  Add a call to do
that in these tests where it is needed.

Also, in clear_map, remove NPCs before vehicles to avoid unboarding
errors (as already hinted at in npc_test.cpp).

Simplify npc_test to use the new improved clear_map.

Ultimately, this is all a workaround for the fact that vehicle detaching
does not properly mark NPCs as not in the vehicle.  That should also be
fixed.
  • Loading branch information
jbytheway committed May 1, 2019
1 parent 79877f3 commit 581edb5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 5 additions & 2 deletions tests/map_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ void clear_map()
for( int z = -2; z <= 0; ++z ) {
clear_fields( z );
}
wipe_map_terrain();
g->m.clear_traps();
// Remove NPCs before vehicles otherwise you get unboarding errors
// TODO: Fixc vehicle detaching so that it removes boarded NPCs first, so
// that this is not a problem.
clear_npcs();
clear_creatures();
wipe_map_terrain();
g->m.clear_traps();
}

void clear_map_and_put_player_underground()
Expand Down
4 changes: 2 additions & 2 deletions tests/monster_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef statistics<int> move_statistics;
static int moves_to_destination( const std::string &monster_type,
const tripoint &start, const tripoint &end )
{
clear_creatures();
clear_map();
REQUIRE( g->num_creatures() == 1 ); // the player
monster &test_monster = spawn_test_monster( monster_type, start );
// Get it riled up and give it a goal.
Expand Down Expand Up @@ -83,7 +83,7 @@ std::ostream &operator << ( std::ostream &os, const std::vector<track> &vec )
**/
static int can_catch_player( const std::string &monster_type, const tripoint &direction_of_flight )
{
clear_creatures();
clear_map();
REQUIRE( g->num_creatures() == 1 ); // the player
player &test_player = g->u;
// Strip off any potentially encumbering clothing.
Expand Down
10 changes: 2 additions & 8 deletions tests/npc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,8 @@ TEST_CASE( "npc-movement" )

g->place_player( tripoint( 60, 60, 0 ) );

// kill npcs before removing vehicles so they are correctly unboarded
clear_npcs();
clear_creatures();
// remove existing vehicles
VehicleList vehs = g->m.get_vehicles( g->u.pos(), g->u.pos() + point( width - 1, height - 1 ) );
for( auto &veh : vehs ) {
g->m.detach_vehicle( veh.v );
}
clear_map();

for( int y = 0; y < height; ++y ) {
for( int x = 0; x < width; ++x ) {
const char type = setup[y][x];
Expand Down

0 comments on commit 581edb5

Please sign in to comment.