-
Notifications
You must be signed in to change notification settings - Fork 280
/
map_test.cpp
146 lines (134 loc) · 5.34 KB
/
map_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "catch/catch.hpp"
#include <memory>
#include <vector>
#include "avatar.h"
#include "enums.h"
#include "game.h"
#include "game_constants.h"
#include "map.h"
#include "map_helpers.h"
#include "point.h"
#include "state_helpers.h"
#include "type_id.h"
TEST_CASE( "destroy_grabbed_furniture" )
{
clear_all_state();
GIVEN( "Furniture grabbed by the player" ) {
const tripoint test_origin( 60, 60, 0 );
map &here = get_map();
g->u.setpos( test_origin );
const tripoint grab_point = test_origin + tripoint_east;
here.furn_set( grab_point, furn_id( "f_chair" ) );
g->u.grab( OBJECT_FURNITURE, grab_point );
WHEN( "The furniture grabbed by the player is destroyed" ) {
here.destroy( grab_point );
THEN( "The player's grab is released" ) {
CHECK( g->u.get_grab_type() == OBJECT_NONE );
CHECK( g->u.grab_point == tripoint_zero );
}
}
}
}
TEST_CASE( "map_bounds_checking" )
{
clear_all_state();
map m;
m.load( tripoint_zero, false );
for( int x = -1; x <= MAPSIZE_X; ++x ) {
for( int y = -1; y <= MAPSIZE_Y; ++y ) {
for( int z = -OVERMAP_DEPTH - 1; z <= OVERMAP_HEIGHT + 1; ++z ) {
INFO( "( " << x << ", " << y << ", " << z << " )" );
if( x < 0 || x >= MAPSIZE_X ||
y < 0 || y >= MAPSIZE_Y ||
z < -OVERMAP_DEPTH || z > OVERMAP_HEIGHT ) {
CHECK( !m.ter( { x, y, z } ) );
} else {
CHECK( m.ter( { x, y, z } ) );
}
}
}
}
}
TEST_CASE( "tinymap_bounds_checking" )
{
clear_all_state();
tinymap m;
m.load( tripoint_zero, false );
for( int x = -1; x <= SEEX * 2; ++x ) {
for( int y = -1; y <= SEEY * 2; ++y ) {
for( int z = -OVERMAP_DEPTH - 1; z <= OVERMAP_HEIGHT + 1; ++z ) {
INFO( "( " << x << ", " << y << ", " << z << " )" );
if( x < 0 || x >= SEEX * 2 ||
y < 0 || y >= SEEY * 2 ||
z < -OVERMAP_DEPTH || z > OVERMAP_HEIGHT ) {
CHECK( !m.ter( { x, y, z } ) );
} else {
CHECK( m.ter( { x, y, z } ) );
}
}
}
}
}
TEST_CASE( "place_player_can_safely_move_multiple_submaps" )
{
clear_all_state();
// Regression test for the situation where game::place_player would misuse
// map::shift if the resulting shift exceeded a single submap, leading to a
// broken active item cache.
g->place_player( tripoint_zero );
CHECK( get_map().check_submap_active_item_consistency().empty() );
}
static std::ostream &operator<<( std::ostream &os, const ter_id &tid )
{
os << tid.id().c_str();
return os;
}
TEST_CASE( "bash_through_roof_can_destroy_multiple_times" )
{
clear_all_state();
map &here = get_map();
REQUIRE( here.has_zlevels() );
static const ter_str_id t_fragile_roof( "t_fragile_roof" );
static const ter_str_id t_strong_roof( "t_strong_roof" );
static const ter_str_id t_rock_floor_no_roof( "t_rock_floor_no_roof" );
static const ter_str_id t_open_air( "t_open_air" );
static const tripoint p( 65, 65, 1 );
WHEN( "A wall has a matching roof above it, but the roof turns to a stronger roof on successful bash" ) {
static const ter_str_id t_fragile_wall( "t_fragile_wall" );
here.ter_set( p + tripoint_below, t_fragile_wall );
here.ter_set( p, t_fragile_roof );
AND_WHEN( "The roof is bashed with only enough strength to destroy the weaker roof type" ) {
here.bash( p, 10, false, false, true );
THEN( "The roof turns to the stronger type and the wall doesn't change" ) {
CHECK( here.ter( p ) == t_strong_roof );
CHECK( here.ter( p + tripoint_below ) == t_fragile_wall );
}
}
AND_WHEN( "The roof is bashed with enough strength to destroy any roof" ) {
here.bash( p, 1000, false, false, true );
THEN( "Both the roof and the wall are destroyed" ) {
CHECK( here.ter( p ) == t_open_air );
CHECK( here.ter( p + tripoint_below ) == t_rock_floor_no_roof );
}
}
}
WHEN( "A passable floor has a matching roof above it, but both the roof and the floor turn into stronger variants on destroy" ) {
static const ter_str_id t_fragile_floor( "t_fragile_floor" );
here.ter_set( p + tripoint_below, t_fragile_floor );
here.ter_set( p, t_fragile_roof );
AND_WHEN( "The roof is bashed with only enough strength to destroy the weaker roof type" ) {
here.bash( p, 10, false, false, true );
THEN( "The roof turns to the stronger type and the floor doesn't change" ) {
CHECK( here.ter( p ) == t_strong_roof );
CHECK( here.ter( p + tripoint_below ) == t_fragile_floor );
}
}
AND_WHEN( "The roof is bashed with enough strength to destroy any roof" ) {
here.bash( p, 1000, false, false, true );
THEN( "Both the roof and the floor are completely destroyed to default terrain" ) {
CHECK( here.ter( p ) == t_open_air );
CHECK( here.ter( p + tripoint_below ) == t_rock_floor_no_roof );
}
}
}
}