From 89840dbb13abf17db8030335e950e0a42d75a061 Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Tue, 3 May 2022 11:23:22 -0700 Subject: [PATCH] Create a test exercising opening and closing fake vehicle parts --- tests/vehicle_fake_part_test.cpp | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/vehicle_fake_part_test.cpp b/tests/vehicle_fake_part_test.cpp index e79ea23fa2c3e..bd55553585cc7 100644 --- a/tests/vehicle_fake_part_test.cpp +++ b/tests/vehicle_fake_part_test.cpp @@ -1,6 +1,7 @@ #include #include +#include "action.h" #include "avatar.h" #include "catch/catch.hpp" #include "damage.h" @@ -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 ); +}