forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_helpers.cpp
137 lines (123 loc) · 3.38 KB
/
map_helpers.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
#include "map_helpers.h"
#include <cassert>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "field.h"
#include "game.h"
#include "game_constants.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "npc.h"
#include "point.h"
#include "type_id.h"
class vehicle;
// Remove all vehicles from the map
void clear_vehicles()
{
map &here = get_map();
for( wrapped_vehicle &veh : here.get_vehicles() ) {
here.destroy_vehicle( veh.v );
}
}
void wipe_map_terrain()
{
map &here = get_map();
const int mapsize = here.getmapsize() * SEEX;
for( int z = 0; z <= OVERMAP_HEIGHT; ++z ) {
ter_id terrain = z == 0 ? t_grass : t_open_air;
for( int x = 0; x < mapsize; ++x ) {
for( int y = 0; y < mapsize; ++y ) {
here.set( { x, y, z}, terrain, f_null );
}
}
}
clear_vehicles();
here.invalidate_map_cache( 0 );
here.build_map_cache( 0, true );
}
void clear_creatures()
{
// Remove any interfering monsters.
g->clear_zombies();
}
void clear_npcs()
{
// Reload to ensure that all active NPCs are in the overmap_buffer.
g->reload_npcs();
for( npc &n : g->all_npcs() ) {
n.die( nullptr );
}
g->cleanup_dead();
}
void clear_fields( const int zlevel )
{
map &here = get_map();
const int mapsize = here.getmapsize() * SEEX;
for( int x = 0; x < mapsize; ++x ) {
for( int y = 0; y < mapsize; ++y ) {
const tripoint p( x, y, zlevel );
std::vector<field_type_id> fields;
for( auto &pr : here.field_at( p ) ) {
fields.push_back( pr.second.get_field_type() );
}
for( field_type_id f : fields ) {
here.remove_field( p, f );
}
}
}
}
void clear_items( const int zlevel )
{
map &here = get_map();
const int mapsize = here.getmapsize() * SEEX;
for( int x = 0; x < mapsize; ++x ) {
for( int y = 0; y < mapsize; ++y ) {
here.i_clear( { x, y, zlevel } );
}
}
}
void clear_map()
{
// Clearing all z-levels is rather slow, so just clear the ones I know the
// tests use for now.
for( int z = -2; z <= 0; ++z ) {
clear_fields( z );
}
wipe_map_terrain();
clear_npcs();
clear_creatures();
get_map().clear_traps();
for( int z = -2; z <= 0; ++z ) {
clear_items( z );
}
}
void clear_map_and_put_player_underground()
{
clear_map();
// Make sure the player doesn't block the path of the monster being tested.
get_player_location().setpos( { 0, 0, -2 } );
}
monster &spawn_test_monster( const std::string &monster_type, const tripoint &start )
{
monster *const added = g->place_critter_at( mtype_id( monster_type ), start );
assert( added );
return *added;
}
// Build a map of size MAPSIZE_X x MAPSIZE_Y around tripoint_zero with a given
// terrain, and no furniture, traps, or items.
void build_test_map( const ter_id &terrain )
{
map &here = get_map();
for( const tripoint &p : here.points_in_rectangle( tripoint_zero,
tripoint( MAPSIZE * SEEX, MAPSIZE * SEEY, 0 ) ) ) {
here.furn_set( p, furn_id( "f_null" ) );
here.ter_set( p, terrain );
here.trap_set( p, trap_id( "tr_null" ) );
here.i_clear( p );
}
here.invalidate_map_cache( 0 );
here.build_map_cache( 0, true );
}