Skip to content

Commit

Permalink
Create a test exercising opening and closing fake vehicle parts
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed May 3, 2022
1 parent 7e330a3 commit 89840db
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/vehicle_fake_part_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <memory>
#include <vector>

#include "action.h"
#include "avatar.h"
#include "catch/catch.hpp"
#include "damage.h"
Expand Down Expand Up @@ -336,3 +337,65 @@ TEST_CASE( "fake_parts_are_opaque", "[vehicle],[vehicle_fake]" )
here.build_lightmap( 0, you.pos() );
CHECK( !you.sees( you.pos() + point( 10, 10 ) ) );
}

TEST_CASE( "open_and_close_fake_doors", "[vehicle],[vehicle_fake]" )
{
really_clear_map();
Character &you = get_player_character();
clear_avatar();
const tripoint test_origin = you.pos() + point( 2, 0 );
map &here = get_map();

vehicle *veh = here.add_vehicle( vehicle_prototype_test_van, test_origin, 315_degrees, 100, 0 );
REQUIRE( veh != nullptr );

// First get the doors to a known good state.
for( const vpart_reference vp : veh->get_avail_parts( "OPENABLE" ) ) {
REQUIRE( !vp.part().is_fake );
veh->close( vp.part_index() );
}

// Then scan through all the openables including fakes and assert that we can open them.
int fakes_tested = 0;
for( const vpart_reference vp : veh->get_all_parts_with_fakes() ) {
if( vp.info().has_flag( "OPENABLE" ) && vp.part().is_fake ) {
fakes_tested++;
REQUIRE( !veh->is_open( vp.part_index() ) );
CHECK( can_interact_at( ACTION_OPEN, vp.pos() ) );
int part_to_open = veh->next_part_to_open( vp.part_index() );
REQUIRE( part_to_open >= 0 );
// This should be the same part for this use case since there are no curtains etc.
REQUIRE( part_to_open == vp.part_index() );
// Using open_all_at because it will usually be from outside the vehicle.
veh->open_all_at( part_to_open );
CHECK( veh->is_open( vp.part_index() ) );
CHECK( veh->is_open( vp.part().fake_part_to ) );
}
}
REQUIRE( fakes_tested == 4 );

// Then open them all back up.
for( const vpart_reference vp : veh->get_avail_parts( "OPENABLE" ) ) {
REQUIRE( !vp.part().is_fake );
veh->open( vp.part_index() );
}

// Then scan through all the openables including fakes and assert that we can close them.
fakes_tested = 0;
for( const vpart_reference vp : veh->get_all_parts_with_fakes() ) {
if( vp.info().has_flag( "OPENABLE" ) && vp.part().is_fake ) {
fakes_tested++;
CHECK( veh->is_open( vp.part_index() ) );
CHECK( can_interact_at( ACTION_CLOSE, vp.pos() ) );
int part_to_close = veh->next_part_to_close( vp.part_index() );
REQUIRE( part_to_close >= 0 );
// This should be the same part for this use case since there are no curtains etc.
REQUIRE( part_to_close == vp.part_index() );
// Using open_all_at because it will usually be from outside the vehicle.
veh->close( part_to_close );
CHECK( !veh->is_open( vp.part_index() ) );
CHECK( !veh->is_open( vp.part().fake_part_to ) );
}
}
REQUIRE( fakes_tested == 4 );
}

0 comments on commit 89840db

Please sign in to comment.