Skip to content

Commit

Permalink
Fix NPC attack tests
Browse files Browse the repository at this point in the history
Move the player so game::load_npcs will actually spawn the NPCs.

Add REQUIREs to make the game not crash on failing to spawn NPCs.

Remove the weather setting because it doesn't change the tests, and
causes vision tests failures due to side effects!

Adjust the values of the m16a4 test to start passing.
  • Loading branch information
anothersimulacrum committed Jul 11, 2021
1 parent 58260a3 commit 0cdf675
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/npc_attack_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ namespace npc_attack_setup
{
static void spawn_main_npc()
{
get_player_character().setpos( { main_npc_start, -1 } );
const string_id<npc_template> blank_template( "test_talker" );
REQUIRE( g->critter_at<Creature>( main_npc_start_tripoint ) == nullptr );
const character_id model_id = get_map().place_npc( main_npc_start, blank_template );

npc &model_npc = *g->find_npc( model_id );
clear_character( model_npc );
model_npc.setpos( main_npc_start_tripoint );

g->load_npcs();

REQUIRE( g->critter_at<npc>( main_npc_start_tripoint ) != nullptr );
}

static void respawn_main_npc()
Expand Down Expand Up @@ -71,7 +75,6 @@ static void test_melee_attacks( const npc_attack_melee_test_data &data )
clear_map_and_put_player_underground();
clear_vehicles();
scoped_weather_override sunny_weather( weather_type_id( "sunny" ) );
g->weather.set_nextweather( calendar::turn );
npc_attack_setup::spawn_main_npc();
npc_attack_setup::spawn_zombie_at_range( 1 );
monster *zomble = g->critter_at<monster>( main_npc_start_tripoint + tripoint_east );
Expand Down Expand Up @@ -150,7 +153,6 @@ static void test_gun_attacks( const npc_attack_gun_test_data &data )
clear_map_and_put_player_underground();
clear_vehicles();
scoped_weather_override sunny_weather( weather_type_id( "sunny" ) );
g->weather.set_nextweather( calendar::turn );
npc_attack_setup::spawn_main_npc();
npc &main_npc = npc_attack_setup::get_main_npc();
arm_shooter( main_npc, data.weapon_id );
Expand Down Expand Up @@ -280,7 +282,7 @@ TEST_CASE( "Test NPC attack variants' potential", "[npc_attack]" )
SECTION( "m16a4" ) {
const npc_attack_gun_test_data gun{
"m16a4",
345, 375
336, 366
};
test_gun_attacks( gun );
}
Expand Down

0 comments on commit 0cdf675

Please sign in to comment.