Skip to content

Commit

Permalink
Add a test for crouching vision
Browse files Browse the repository at this point in the history
This tests that the player cannot see past an adjacent obstacle when
crouching, but light can still pass it.
  • Loading branch information
jbytheway committed Feb 23, 2020
1 parent 9d3c363 commit c3cf52c
Showing 1 changed file with 59 additions and 11 deletions.
70 changes: 59 additions & 11 deletions tests/vision_test.cpp
Original file line number Diff line number Diff line change
@@ -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<vision_test_flags>(
static_cast<unsigned>( l ) & static_cast<unsigned>( r ) );
}

static bool operator!( vision_test_flags f )
{
return !static_cast<unsigned>( f );
}

static void full_map_test( const std::vector<std::string> &setup,
const std::vector<std::string> &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<std::string> &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<std::string> setup;
std::vector<std::string> expected_results;
time_point time;
bool test_3d;
vision_test_flags flags;

static void transpose( std::vector<std::string> &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();

0 comments on commit c3cf52c

Please sign in to comment.