diff --git a/tests/vision_test.cpp b/tests/vision_test.cpp index df21a9eee6684..96efebcca0a97 100644 --- a/tests/vision_test.cpp +++ b/tests/vision_test.cpp @@ -22,9 +22,27 @@ #include "game_constants.h" #include "point.h" +enum class vision_test_flags { + none = 0, + no_3d = 1 << 0, + crouching = 1 << 1, +}; + +static vision_test_flags operator&( vision_test_flags l, vision_test_flags r ) +{ + return static_cast( + static_cast( l ) & static_cast( r ) ); +} + +static bool operator!( vision_test_flags f ) +{ + return !static_cast( f ); +} + static void full_map_test( const std::vector &setup, const std::vector &expected_results, - const time_point &time ) + const time_point &time, + const vision_test_flags flags ) { const ter_id t_brick_wall( "t_brick_wall" ); const ter_id t_window_frame( "t_window_frame" ); @@ -40,6 +58,12 @@ static void full_map_test( const std::vector &setup, clear_map(); g->reset_light_level(); + if( !!( flags & vision_test_flags::crouching ) ) { + g->u.set_movement_mode( character_movemode::CMM_CROUCH ); + } else { + g->u.set_movement_mode( character_movemode::CMM_WALK ); + } + REQUIRE( !g->u.is_blind() ); REQUIRE( !g->u.in_sleep_state() ); REQUIRE( !g->u.has_effect( effect_narcosis ) ); @@ -224,7 +248,7 @@ struct vision_test_case { std::vector setup; std::vector expected_results; time_point time; - bool test_3d; + vision_test_flags flags; static void transpose( std::vector &v ) { if( v.empty() ) { @@ -261,7 +285,7 @@ struct vision_test_case { } void test() const { - full_map_test( setup, expected_results, time ); + full_map_test( setup, expected_results, time, flags ); } void test_all_transformations() const { @@ -286,6 +310,7 @@ struct vision_test_case { void test_all() const { // Disabling 3d tests for now since 3d sight casting is actually // different (it sees round corners more). + const bool test_3d = !( flags & vision_test_flags::no_3d ); if( test_3d ) { INFO( "using 3d casting" ); fov_3d = true; @@ -326,7 +351,7 @@ TEST_CASE( "vision_daylight", "[shadowcasting][vision]" ) "444", }, midday, - true + vision_test_flags::none }; t.test_all(); @@ -346,7 +371,7 @@ TEST_CASE( "vision_day_indoors", "[shadowcasting][vision]" ) "111", }, midday, - true + vision_test_flags::none }; t.test_all(); @@ -370,7 +395,8 @@ TEST_CASE( "vision_light_shining_in", "[shadowcasting][vision]" ) "1144444444", }, midday, - false // 3D FOV gives different results here due to it seeing round corners more + // 3D FOV gives different results here due to it seeing round corners more + vision_test_flags::no_3d }; t.test_all(); @@ -388,7 +414,7 @@ TEST_CASE( "vision_no_lights", "[shadowcasting][vision]" ) "111", }, midnight, - true + vision_test_flags::none }; t.test_all(); @@ -408,7 +434,7 @@ TEST_CASE( "vision_utility_light", "[shadowcasting][vision]" ) "444", }, midnight, - true + vision_test_flags::none }; t.test_all(); @@ -428,7 +454,7 @@ TEST_CASE( "vision_wall_obstructs_light", "[shadowcasting][vision]" ) "111", }, midnight, - true + vision_test_flags::none }; t.test_all(); @@ -452,7 +478,29 @@ TEST_CASE( "vision_wall_can_be_lit_by_player", "[shadowcasting][vision]" ) "66", }, midnight, - true + vision_test_flags::none + }; + + t.test_all(); +} + +TEST_CASE( "vision_crouching_blocks_vision_but_not_light", "[shadowcasting][vision]" ) +{ + vision_test_case t { + { + "###", + "#u#", + "#=#", + " ", + }, + { + "444", + "444", + "444", + "666", + }, + midday, + vision_test_flags::crouching }; t.test_all(); @@ -481,7 +529,7 @@ TEST_CASE( "vision_see_wall_in_moonlight", "[shadowcasting][vision]" ) }, // Want a night time full_moon - time_past_midnight( full_moon ), - true + vision_test_flags::none }; t.test_all();