forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submap.h
314 lines (253 loc) · 8.9 KB
/
submap.h
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#pragma once
#ifndef CATA_SRC_SUBMAP_H
#define CATA_SRC_SUBMAP_H
#include <cstddef>
#include <cstdint>
#include <memory>
#include <vector>
#include <string>
#include <iterator>
#include <map>
#include "active_item_cache.h"
#include "active_tile_data.h"
#include "calendar.h"
#include "colony.h"
#include "computer.h"
#include "construction_partial.h"
#include "field.h"
#include "game_constants.h"
#include "item.h"
#include "type_id.h"
#include "point.h"
#include "poly_serialized.h"
class JsonIn;
class JsonOut;
class basecamp;
class map;
struct trap;
struct ter_t;
struct furn_t;
class vehicle;
struct spawn_point {
point pos;
int count;
mtype_id type;
int faction_id;
int mission_id;
bool friendly;
std::string name;
spawn_point( const mtype_id &T = mtype_id::NULL_ID(), int C = 0, point P = point_zero,
int FAC = -1, int MIS = -1, bool F = false,
const std::string &N = "NONE" ) :
pos( P ), count( C ), type( T ), faction_id( FAC ),
mission_id( MIS ), friendly( F ), name( N ) {}
};
template<int sx, int sy>
struct maptile_soa {
ter_id ter[sx][sy]; // Terrain on each square
furn_id frn[sx][sy]; // Furniture on each square
std::uint8_t lum[sx][sy]; // Number of items emitting light on each square
cata::colony<item> itm[sx][sy]; // Items on each square
field fld[sx][sy]; // Field on each square
trap_id trp[sx][sy]; // Trap on each square
int rad[sx][sy]; // Irradiation of each square
void swap_soa_tile( point p1, point p2 );
void swap_soa_tile( point p, maptile_soa<1, 1> &other );
};
class submap : maptile_soa<SEEX, SEEY>
{
public:
submap();
submap( submap && );
~submap();
submap &operator=( submap && );
trap_id get_trap( point p ) const {
return trp[p.x][p.y];
}
void set_trap( point p, trap_id trap ) {
is_uniform = false;
trp[p.x][p.y] = trap;
}
void set_all_traps( const trap_id &trap ) {
std::uninitialized_fill_n( &trp[0][0], elements, trap );
}
furn_id get_furn( point p ) const {
return frn[p.x][p.y];
}
void set_furn( point p, furn_id furn ) {
is_uniform = false;
frn[p.x][p.y] = furn;
}
void set_all_furn( const furn_id &furn ) {
std::uninitialized_fill_n( &frn[0][0], elements, furn );
}
ter_id get_ter( point p ) const {
return ter[p.x][p.y];
}
void set_ter( point p, ter_id terr ) {
is_uniform = false;
ter[p.x][p.y] = terr;
}
void set_all_ter( const ter_id &terr ) {
std::uninitialized_fill_n( &ter[0][0], elements, terr );
}
int get_radiation( point p ) const {
return rad[p.x][p.y];
}
void set_radiation( point p, const int radiation ) {
is_uniform = false;
rad[p.x][p.y] = radiation;
}
uint8_t get_lum( point p ) const {
return lum[p.x][p.y];
}
void set_lum( point p, uint8_t luminance ) {
is_uniform = false;
lum[p.x][p.y] = luminance;
}
void update_lum_add( point p, const item &i ) {
is_uniform = false;
if( i.is_emissive() && lum[p.x][p.y] < 255 ) {
lum[p.x][p.y]++;
}
}
void update_lum_rem( point p, const item &i );
// TODO: Replace this as it essentially makes itm public
cata::colony<item> &get_items( point p ) {
return itm[p.x][p.y];
}
const cata::colony<item> &get_items( point p ) const {
return itm[p.x][p.y];
}
// TODO: Replace this as it essentially makes fld public
field &get_field( point p ) {
return fld[p.x][p.y];
}
const field &get_field( point p ) const {
return fld[p.x][p.y];
}
struct cosmetic_t {
point pos;
std::string type;
std::string str;
};
void insert_cosmetic( point p, const std::string &type, const std::string &str );
int get_temperature() const {
return temperature;
}
void set_temperature( int new_temperature ) {
temperature = new_temperature;
}
bool has_graffiti( point p ) const;
const std::string &get_graffiti( point p ) const;
void set_graffiti( point p, const std::string &new_graffiti );
void delete_graffiti( point p );
// Signage is a pretend union between furniture on a square and stored
// writing on the square. When both are present, we have signage.
// Its effect is meant to be cosmetic and atmospheric only.
bool has_signage( point p ) const;
// Dependent on furniture + cosmetics.
std::string get_signage( point p ) const;
// Can be used anytime (prevents code from needing to place sign first.)
void set_signage( point p, const std::string &s );
// Can be used anytime (prevents code from needing to place sign first.)
void delete_signage( point p );
bool has_computer( point p ) const;
const computer *get_computer( point p ) const;
computer *get_computer( point p );
void set_computer( point p, const computer &c );
void delete_computer( point p );
bool contains_vehicle( vehicle * );
void rotate( int turns );
void store( JsonOut &jsout ) const;
void load( JsonIn &jsin, const std::string &member_name, int version );
// If is_uniform is true, this submap is a solid block of terrain
// Uniform submaps aren't saved/loaded, because regenerating them is faster
bool is_uniform;
std::vector<cosmetic_t> cosmetics; // Textual "visuals" for squares
active_item_cache active_items;
int field_count = 0;
time_point last_touched = calendar::turn_zero;
std::vector<spawn_point> spawns;
/**
* Vehicles on this submap (their (0,0) point is on this submap).
* This vehicle objects are deleted by this submap when it gets
* deleted.
*/
std::vector<std::unique_ptr<vehicle>> vehicles;
std::map<tripoint, partial_con> partial_constructions;
std::unique_ptr<basecamp> camp; // only allowing one basecamp per submap
std::map<point_sm_ms, cata::poly_serialized<active_tile_data>> active_furniture;
private:
std::map<point, computer> computers;
std::unique_ptr<computer> legacy_computer;
int temperature = 0;
void update_legacy_computer();
static constexpr size_t elements = SEEX * SEEY;
};
/**
* A wrapper for a submap point. Allows getting multiple map features
* (terrain, furniture etc.) without directly accessing submaps or
* doing multiple bounds checks and submap gets.
*/
struct maptile {
private:
friend map; // To allow "sliding" the tile in x/y without bounds checks
friend submap;
submap *const sm;
point pos_;
inline point pos() const {
return pos_;
}
maptile( submap *sub, point p ) :
sm( sub ), pos_( p ) { }
public:
trap_id get_trap() const {
return sm->get_trap( pos() );
}
furn_id get_furn() const {
return sm->get_furn( pos() );
}
ter_id get_ter() const {
return sm->get_ter( pos() );
}
const trap &get_trap_t() const {
return sm->get_trap( pos() ).obj();
}
const furn_t &get_furn_t() const {
return sm->get_furn( pos() ).obj();
}
const ter_t &get_ter_t() const {
return sm->get_ter( pos() ).obj();
}
const field &get_field() const {
return sm->get_field( pos() );
}
field_entry *find_field( const field_type_id &field_to_find ) {
return sm->get_field( pos() ).find_field( field_to_find );
}
int get_radiation() const {
return sm->get_radiation( pos() );
}
bool has_graffiti() const {
return sm->has_graffiti( pos() );
}
const std::string &get_graffiti() const {
return sm->get_graffiti( pos() );
}
bool has_signage() const {
return sm->has_signage( pos() );
}
std::string get_signage() const {
return sm->get_signage( pos() );
}
// For map::draw_maptile
size_t get_item_count() const {
return sm->get_items( pos() ).size();
}
// Assumes there is at least one item
const item &get_uppermost_item() const {
return *std::prev( sm->get_items( pos() ).cend() );
}
};
#endif // CATA_SRC_SUBMAP_H