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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#include "avatar.h"
#include "avatar_action.h"
#include "cata_catch.h"
#include "coordinates.h"
#include "gates.h"
#include "map.h"
#include "mapdata.h"
#include "map_helpers.h"
#include "player_helpers.h"
#include "sounds.h"
#include "type_id.h"
TEST_CASE( "doors_should_be_able_to_open_and_close", "[gates]" )
{
map &here = get_map();
clear_map();
tripoint pos = get_avatar().pos() + point_east;
WHEN( "the door is unlocked" ) {
// create closed door on tile next to player
REQUIRE( here.ter_set( pos, t_door_c ) );
REQUIRE( here.ter( pos ).obj().id == t_door_c->id );
THEN( "the door should be able to open and close" ) {
CHECK( here.open_door( get_avatar(), pos, true, false ) );
CHECK( here.ter( pos ).obj().id == t_door_o->id );
CHECK( here.close_door( pos, true, false ) );
CHECK( here.ter( pos ).obj().id == t_door_c->id );
}
}
WHEN( "the door is locked" ) {
// create locked door on tile next to player
REQUIRE( here.ter_set( pos, t_door_locked ) );
REQUIRE( here.ter( pos ).obj().id == t_door_locked->id );
THEN( "the door should not be able to open" ) {
CHECK_FALSE( here.close_door( pos, true, false ) );
CHECK( here.ter( pos ).obj().id == t_door_locked->id );
}
}
}
TEST_CASE( "windows_should_be_able_to_open_and_close", "[gates]" )
{
map &here = get_map();
clear_map();
tripoint pos = get_avatar().pos() + point_east;
// create closed window on tile next to player
REQUIRE( here.ter_set( pos, t_window_no_curtains ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains->id );
WHEN( "the window is opened from the inside" ) {
THEN( "the window should be able to open" ) {
CHECK( here.open_door( get_avatar(), pos, true, false ) );
CHECK( here.ter( pos ).obj().id == t_window_no_curtains_open->id );
}
}
WHEN( "the window is opened from the outside" ) {
THEN( "the window should not be able to open" ) {
CHECK_FALSE( here.close_door( pos, false, false ) );
CHECK( here.ter( pos ).obj().id == t_window_no_curtains->id );
}
}
}
// Note that it is not intended for all doors and windows to make swish sound,
// some doors and windows might make other types of sounds in the future
// TODO: update test case when door and window sounds become defined in JSON.
TEST_CASE( "doors_and_windows_should_make_whoosh_sound", "[gates]" )
{
map &here = get_map();
clear_map();
clear_avatar();
sounds::reset_sounds();
tripoint pos = get_avatar().pos() + point_east;
WHEN( "the door is opened" ) {
REQUIRE( here.ter_set( pos, t_door_c ) );
REQUIRE( here.ter( pos ).obj().id == t_door_c->id );
// make sure there is no sounds before action
REQUIRE( sounds::get_monster_sounds().first.empty() );
REQUIRE( here.open_door( get_avatar(), pos, true, false ) );
REQUIRE( here.ter( pos ).obj().id == t_door_o->id );
THEN( "the door should make a swish sound" ) {
CHECK_FALSE( sounds::get_monster_sounds().first.empty() );
}
}
WHEN( "the door is closed" ) {
REQUIRE( here.ter_set( pos, t_door_o ) );
REQUIRE( here.ter( pos ).obj().id == t_door_o->id );
// make sure there is no sounds before action
REQUIRE( sounds::get_monster_sounds().first.empty() );
REQUIRE( here.close_door( pos, true, false ) );
REQUIRE( here.ter( pos ).obj().id == t_door_c->id );
THEN( "the door should make a swish sound" ) {
CHECK_FALSE( sounds::get_monster_sounds().first.empty() );
}
}
WHEN( "the window is opened" ) {
REQUIRE( here.ter_set( pos, t_window_no_curtains ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains->id );
// make sure there is no sounds before action
REQUIRE( sounds::get_monster_sounds().first.empty() );
REQUIRE( here.open_door( get_avatar(), pos, true, false ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains_open->id );
THEN( "the window should make a swish sound" ) {
CHECK_FALSE( sounds::get_monster_sounds().first.empty() );
}
}
WHEN( "the window is closed" ) {
REQUIRE( here.ter_set( pos, t_window_no_curtains_open ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains_open->id );
// make sure there is no sounds before action
REQUIRE( sounds::get_monster_sounds().first.empty() );
REQUIRE( here.close_door( pos, true, false ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains->id );
THEN( "the window should make a swish sound" ) {
CHECK_FALSE( sounds::get_monster_sounds().first.empty() );
}
}
}
TEST_CASE( "character_should_lose_moves_when_opening_or_closing_doors_or_windows", "[gates]" )
{
avatar &they = get_avatar();
map &here = get_map();
clear_avatar();
clear_map();
tripoint pos = get_avatar().pos() + point_east;
// the movement cost for opening and closing gates
// remember to update this if changing value in code
const int open_move_cost = 100;
// set move value to 0 so we know how many
// move points were spent opening and closing gates
they.moves = 0;
WHEN( "avatar opens door" ) {
REQUIRE( here.ter_set( pos, t_door_c ) );
REQUIRE( here.ter( pos ).obj().id == t_door_c->id );
REQUIRE( avatar_action::move( they, here, tripoint_east ) );
THEN( "avatar should spend move points" ) {
CHECK( they.moves == -open_move_cost );
}
}
WHEN( "avatar fails to open locked door" ) {
REQUIRE( here.ter_set( pos, t_door_locked ) );
REQUIRE( here.ter( pos ).obj().id == t_door_locked->id );
REQUIRE_FALSE( avatar_action::move( they, here, tripoint_east ) );
THEN( "avatar should not spend move points" ) {
CHECK( they.moves == 0 );
}
}
GIVEN( "that avatar is outdoors" ) {
REQUIRE( here.is_outside( pos ) );
WHEN( "avatar fails to open window" ) {
REQUIRE( here.ter_set( pos, t_window_no_curtains ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains->id );
REQUIRE_FALSE( avatar_action::move( they, here, tripoint_east ) );
THEN( "avatar should spend move points" ) {
CHECK( they.moves == 0 );
}
}
}
GIVEN( "that avatar is indoors" ) {
ter_id ter_flat_roof = ter_id( "t_flat_roof" );
ter_id ter_concrete_floor = ter_id( "t_thconc_floor" );
ter_id ter_concrete_wall = ter_id( "t_concrete_wall" );
// enclose the player in single tile room surrounded with
// concrete floor and roof to test opening windows from indoors
const std::vector<tripoint> room_walls{
pos + point_south_east,
pos + point_south,
pos + point_south_west,
pos + point_west,
pos + point_north_west,
pos + point_north,
pos + point_north_east
};
for( tripoint point : room_walls ) {
REQUIRE( here.ter_set( point, ter_concrete_wall ) );
}
REQUIRE( here.ter_set( pos, ter_concrete_floor ) );
REQUIRE( here.ter_set( pos + tripoint_above, ter_flat_roof ) );
// mark map cache as dirty and rebuild it so that map starts
// recognizing that tile player is standing on is indoors
here.set_outside_cache_dirty( pos.z );
here.build_outside_cache( pos.z );
REQUIRE_FALSE( here.is_outside( pos ) );
WHEN( "avatar opens window" ) {
REQUIRE( here.ter_set( pos, t_window_no_curtains ) );
REQUIRE( here.ter( pos ).obj().id == t_window_no_curtains->id );
REQUIRE( avatar_action::move( they, here, tripoint_east ) );
THEN( "avatar should spend move points" ) {
CHECK( they.moves == -open_move_cost );
}
}
}
}
|