-
Notifications
You must be signed in to change notification settings - Fork 280
/
monster_vision_test.cpp
103 lines (87 loc) · 3.38 KB
/
monster_vision_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "catch/catch.hpp"
#include <memory>
#include "calendar.h"
#include "game.h"
#include "map.h"
#include "map_helpers.h"
#include "mapdata.h"
#include "monster.h"
#include "options_helpers.h"
#include "state_helpers.h"
struct tripoint;
static monster &spawn_and_clear( const tripoint &pos, bool set_floor )
{
if( set_floor ) {
get_map().set( pos, t_floor, f_null );
}
return spawn_test_monster( "mon_zombie", pos );
}
static const time_point midday = calendar::turn_zero + 12_hours;
TEST_CASE( "monsters shouldn't see through floors", "[vision]" )
{
clear_all_state();
override_option opt( "FOV_3D", "true" );
bool old_fov_3d = fov_3d;
fov_3d = true;
calendar::turn = midday;
monster &upper = spawn_and_clear( { 5, 5, 0 }, true );
monster &adjacent = spawn_and_clear( { 5, 6, 0 }, true );
monster &distant = spawn_and_clear( { 5, 3, 0 }, true );
monster &lower = spawn_and_clear( { 5, 5, -1 }, true );
monster &deep = spawn_and_clear( { 5, 5, -2 }, true );
monster &sky = spawn_and_clear( { 5, 5, 1 }, false );
// First check monsters whose vision should be blocked by floors.
// One intervening floor between monsters.
CHECK( !upper.sees( lower ) );
CHECK( !lower.sees( upper ) );
// Two intervening floors between monsters.
CHECK( !upper.sees( deep ) );
CHECK( !deep.sees( upper ) );
// One intervening floor and an open space between monsters.
CHECK( !sky.sees( lower ) );
CHECK( !lower.sees( sky ) );
// One intervening floor between monsters, and offset one tile horizontally.
CHECK( !adjacent.sees( lower ) );
CHECK( !lower.sees( adjacent ) );
// One intervening floor between monsters, and offset two tiles horizontally.
CHECK( !distant.sees( lower ) );
CHECK( !lower.sees( distant ) );
// Two intervening floors between monsters, and offset one tile horizontally.
CHECK( !adjacent.sees( deep ) );
CHECK( !deep.sees( adjacent ) );
// Two intervening floor between monsters, and offset two tiles horizontally.
CHECK( !distant.sees( deep ) );
CHECK( !deep.sees( distant ) );
// Then cases where they should be able to see each other.
// No floor between monsters
CHECK( upper.sees( sky ) );
CHECK( sky.sees( upper ) );
// Adjacent monsters.
CHECK( upper.sees( adjacent ) );
CHECK( adjacent.sees( upper ) );
// distant monsters.
CHECK( upper.sees( distant ) );
CHECK( distant.sees( upper ) );
// One intervening vertical tile and one intervening horizontal tile.
CHECK( sky.sees( adjacent ) );
CHECK( adjacent.sees( sky ) );
// One intervening vertical tile and two intervening horizontal tiles.
CHECK( sky.sees( distant ) );
CHECK( distant.sees( sky ) );
fov_3d = old_fov_3d;
}
TEST_CASE( "monsters_dont_see_through_vehicle_holes", "[vision]" )
{
clear_all_state();
calendar::turn = midday;
put_player_underground();
tripoint origin( 60, 60, 0 );
get_map().add_vehicle( vproto_id( "apc" ), origin, -45_degrees, 0, 0 );
get_map().build_map_cache( 0 );
tripoint mon_origin = origin + tripoint( -2, 1, 0 );
monster &inside = spawn_test_monster( "mon_zombie", mon_origin );
tripoint second_origin = mon_origin + tripoint_north_west;
monster &outside = spawn_test_monster( "mon_zombie", second_origin );
CHECK( !inside.sees( outside ) );
CHECK( !outside.sees( inside ) );
}