forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omdata.h
326 lines (258 loc) · 8.68 KB
/
omdata.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
315
316
317
318
319
320
321
322
323
324
325
326
#pragma once
#ifndef CATA_SRC_OMDATA_H
#define CATA_SRC_OMDATA_H
#include <climits>
#include <cstddef>
#include <cstdint>
#include <bitset>
#include <list>
#include <optional>
#include <set>
#include <vector>
#include <array>
#include <string>
#include "cuboid_rectangle.h"
#include "catacharset.h"
#include "color.h"
#include "numeric_interval.h"
#include "coordinates.h"
#include "int_id.h"
#include "om_direction.h"
#include "point.h"
#include "string_id.h"
#include "translations.h"
#include "type_id.h"
struct city;
class overmap_land_use_code;
struct MonsterGroup;
using overmap_land_use_code_id = string_id<overmap_land_use_code>;
class JsonObject;
static const overmap_land_use_code_id land_use_code_forest( "forest" );
static const overmap_land_use_code_id land_use_code_wetland( "wetland" );
static const overmap_land_use_code_id land_use_code_wetland_forest( "wetland_forest" );
static const overmap_land_use_code_id land_use_code_wetland_saltwater( "wetland_saltwater" );
class overmap_land_use_code
{
public:
overmap_land_use_code_id id = overmap_land_use_code_id::NULL_ID();
int land_use_code = 0;
std::string name;
std::string detailed_definition;
uint32_t symbol = 0;
nc_color color = c_black;
std::string get_symbol() const;
// Used by generic_factory
bool was_loaded = false;
void load( const JsonObject &jo, const std::string &src );
void finalize();
void check() const;
};
struct overmap_spawns {
overmap_spawns() : group( mongroup_id::NULL_ID() ) {}
string_id<MonsterGroup> group;
numeric_interval<int> population;
bool operator==( const overmap_spawns &rhs ) const {
return group == rhs.group && population == rhs.population;
}
protected:
void deserialize( const JsonObject &jo );
};
struct overmap_static_spawns : public overmap_spawns {
int chance = 0;
bool operator==( const overmap_static_spawns &rhs ) const {
return overmap_spawns::operator==( rhs ) && chance == rhs.chance;
}
void deserialize( const JsonObject &jo );
};
//terrain flags enum! this is for tracking the indices of each flag.
enum oter_flags {
known_down = 0,
known_up,
no_rotate, // this tile doesn't have four rotated versions (north, east, south, west)
river_tile,
has_sidewalk,
line_drawing, // does this tile have 8 versions, including straights, bends, tees, and a fourway?
subway_connection,
lake,
lake_shore,
generic_loot,
risk_high,
risk_low,
source_ammo,
source_animals,
source_books,
source_chemistry,
source_clothing,
source_construction,
source_cooking,
source_drink,
source_electronics,
source_fabrication,
source_farming,
source_food,
source_forage,
source_fuel,
source_gun,
source_luxury,
source_medicine,
source_people,
source_safety,
source_tailoring,
source_vehicles,
source_weapon,
num_oter_flags
};
struct oter_type_t {
public:
static const oter_type_t null_type;
public:
oter_type_str_id id;
std::string name; // Untranslated name
uint32_t symbol = 0;
nc_color color = c_black;
overmap_land_use_code_id land_use_code = overmap_land_use_code_id::NULL_ID();
std::vector<std::string> looks_like;
unsigned char see_cost = 0; // Affects how far the player can see in the overmap
unsigned char travel_cost = 5; // Affects the pathfinding and travel times
std::string extras = "none";
int mondensity = 0;
// Spawns are added to the submaps *once* upon mapgen of the submaps
overmap_static_spawns static_spawns;
bool was_loaded = false;
std::string get_symbol() const;
oter_type_t() = default;
oter_id get_first() const;
oter_id get_rotated( om_direction::type dir ) const;
oter_id get_linear( size_t n ) const;
bool has_flag( oter_flags flag ) const {
return flags[flag];
}
void set_flag( oter_flags flag, bool value = true ) {
flags[flag] = value;
}
void load( const JsonObject &jo, const std::string &src );
void check() const;
void finalize();
bool is_rotatable() const {
return !has_flag( no_rotate ) && !has_flag( line_drawing );
}
bool is_linear() const {
return has_flag( line_drawing );
}
bool has_connections() const {
return !connect_group.empty();
}
bool connects_to( const oter_type_id &other ) const {
return has_connections() && connect_group == other->connect_group;
}
private:
std::bitset<num_oter_flags> flags;
std::vector<oter_id> directional_peers;
std::string connect_group; // Group for connection when rendering overmap tiles
void register_terrain( const oter_t &peer, size_t n, size_t max_n );
};
struct oter_t {
private:
const oter_type_t *type;
public:
oter_str_id id; // definitive identifier.
oter_t();
oter_t( const oter_type_t &type );
oter_t( const oter_type_t &type, om_direction::type dir );
oter_t( const oter_type_t &type, size_t line );
const oter_type_str_id &get_type_id() const {
return type->id;
}
std::string get_mapgen_id() const;
oter_id get_rotated( om_direction::type dir ) const;
std::string get_name() const {
return _( type->name );
}
std::string get_symbol( const bool from_land_use_code = false ) const {
return utf32_to_utf8( from_land_use_code ? symbol_alt : symbol );
}
uint32_t get_uint32_symbol() const {
return symbol;
}
nc_color get_color( const bool from_land_use_code = false ) const {
return from_land_use_code ? type->land_use_code->color : type->color;
}
om_direction::type get_dir() const {
return dir;
}
size_t get_line() const {
return line;
}
void get_rotation_and_subtile( int &rotation, int &subtile ) const;
unsigned char get_see_cost() const {
return type->see_cost;
}
unsigned char get_travel_cost() const {
return type->travel_cost;
}
const std::string &get_extras() const {
return type->extras;
}
int get_mondensity() const {
return type->mondensity;
}
const overmap_static_spawns &get_static_spawns() const {
return type->static_spawns;
}
overmap_land_use_code_id get_land_use_code() const {
return type->land_use_code;
}
bool type_is( const oter_type_id &type_id ) const;
bool type_is( const oter_type_t &type ) const;
bool has_connection( om_direction::type dir ) const;
bool has_flag( oter_flags flag ) const {
return type->has_flag( flag );
}
bool is_hardcoded() const;
bool is_rotatable() const {
return type->is_rotatable();
}
bool is_linear() const {
return type->is_linear();
}
bool is_river() const {
return type->has_flag( river_tile );
}
bool is_wooded() const {
return type->land_use_code == land_use_code_forest ||
type->land_use_code == land_use_code_wetland ||
type->land_use_code == land_use_code_wetland_forest ||
type->land_use_code == land_use_code_wetland_saltwater;
}
bool is_lake() const {
return type->has_flag( lake );
}
bool is_lake_shore() const {
return type->has_flag( lake_shore );
}
private:
om_direction::type dir = om_direction::type::none;
uint32_t symbol;
uint32_t symbol_alt;
size_t line = 0; // Index of line. Only valid in case of line drawing.
};
// TODO: Deprecate these operators
bool operator==( const oter_id &lhs, const char *rhs );
bool operator!=( const oter_id &lhs, const char *rhs );
namespace overmap_terrains
{
void load( const JsonObject &jo, const std::string &src );
void check_consistency();
void finalize();
void reset();
const std::vector<oter_t> &get_all();
} // namespace overmap_terrains
namespace overmap_land_use_codes
{
void load( const JsonObject &jo, const std::string &src );
void finalize();
void check_consistency();
void reset();
const std::vector<overmap_land_use_code> &get_all();
} // namespace overmap_land_use_codes
#endif // CATA_SRC_OMDATA_H