-
Notifications
You must be signed in to change notification settings - Fork 280
/
active_item_cache_test.cpp
52 lines (48 loc) · 1.95 KB
/
active_item_cache_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
#include "catch/catch.hpp"
#include <memory>
#include <set>
#include "calendar.h"
#include "game.h"
#include "game_constants.h"
#include "item.h"
#include "map.h"
#include "point.h"
#include "state_helpers.h"
TEST_CASE( "place_active_item_at_various_coordinates", "[item]" )
{
clear_all_state();
for( int z = -OVERMAP_DEPTH; z < OVERMAP_HEIGHT; ++z ) {
for( int x = 0; x < MAPSIZE_X; ++x ) {
for( int y = 0; y < MAPSIZE_Y; ++y ) {
g->m.i_clear( { x, y, z } );
}
}
}
REQUIRE( g->m.get_submaps_with_active_items().empty() );
// An arbitrary active item.
item &active = *item::spawn_temporary( "firecracker_act", calendar::start_of_cataclysm,
item::default_charges_tag() );
active.activate();
// For each space in a wide area place the item and check if the cache has been updated.
int z = 0;
for( int x = 0; x < MAPSIZE_X; ++x ) {
for( int y = 0; y < MAPSIZE_Y; ++y ) {
REQUIRE( g->m.i_at( { x, y, z } ).empty() );
CAPTURE( x, y, z );
tripoint abs_loc = g->m.get_abs_sub() + tripoint( x / SEEX, y / SEEY, z );
CAPTURE( abs_loc.x, abs_loc.y, abs_loc.z );
REQUIRE( g->m.get_submaps_with_active_items().empty() );
REQUIRE( g->m.get_submaps_with_active_items().find( abs_loc ) ==
g->m.get_submaps_with_active_items().end() );
detached_ptr<item> n = item::spawn( active );
item &item_ref = *n;
g->m.add_item( { x, y, z }, std::move( n ) );
REQUIRE( item_ref.is_active() );
REQUIRE_FALSE( g->m.get_submaps_with_active_items().empty() );
REQUIRE( g->m.get_submaps_with_active_items().find( abs_loc ) !=
g->m.get_submaps_with_active_items().end() );
REQUIRE_FALSE( g->m.i_at( { x, y, z } ).empty() );
g->m.i_clear( { x, y, z } );
}
}
}