forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapgendata.h
222 lines (191 loc) · 6.35 KB
/
mapgendata.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
#pragma once
#ifndef CATA_SRC_MAPGENDATA_H
#define CATA_SRC_MAPGENDATA_H
#include "calendar.h"
#include "cata_variant.h"
#include "coordinates.h"
#include "cube_direction.h"
#include "enum_bitset.h"
#include "jmapgen_flags.h"
#include "mapgen.h"
#include "type_id.h"
#include "weighted_list.h"
class JsonValue;
class map;
class mission;
struct point;
struct regional_settings;
namespace om_direction
{
enum class type : int;
} // namespace om_direction
struct mapgen_arguments {
std::unordered_map<std::string, cata_variant> map;
void merge( const mapgen_arguments & );
void serialize( JsonOut & ) const;
void deserialize( const JsonValue &ji );
};
namespace mapgendata_detail
{
// helper to get a variant value with any variant being extractable as a string
template<typename Result>
inline Result extract_variant_value( const cata_variant &v )
{
return v.get<Result>();
}
template<>
inline std::string extract_variant_value<std::string>( const cata_variant &v )
{
return v.get_string();
}
} // namespace mapgendata_detail
/**
* Contains various information regarding the individual mapgen instance
* (generating a specific part of the map), used by the various mapgen
* functions to do their thing.
*
* Contains for example:
* - the @ref map to generate the map onto,
* - the overmap terrain of the area to generate and its surroundings,
* - regional settings to use.
*
* An instance of this class is passed through most of the mapgen code.
* If any of these functions need more information, add them here.
*/
// TODO: documentation
// TODO: encapsulate data member
class mapgendata
{
private:
oter_id terrain_type_;
float density_;
time_point when_;
::mission *mission_;
int zlevel_;
mapgen_arguments mapgen_args_;
enum_bitset<jmapgen_flags> mapgen_flags_;
std::vector<oter_id> predecessors_;
public:
oter_id t_nesw[8];
int n_fac = 0; // dir == 0
int e_fac = 0; // dir == 1
int s_fac = 0; // dir == 2
int w_fac = 0; // dir == 3
int ne_fac = 0; // dir == 4
int se_fac = 0; // dir == 5
int sw_fac = 0; // dir == 6
int nw_fac = 0; // dir == 7
oter_id t_above;
oter_id t_below;
std::unordered_map<cube_direction, std::string> joins;
const regional_settings ®ion;
map &m;
weighted_int_list<ter_id> default_groundcover;
struct dummy_settings_t {};
static constexpr dummy_settings_t dummy_settings = {};
mapgendata( map &, dummy_settings_t );
mapgendata( const tripoint_abs_omt &over, map &m, float density, const time_point &when,
::mission *miss );
std::vector<mapgen_phase> skip;
/**
* Creates a copy of this mapgen data, but stores a different @ref terrain_type.
* Useful when you want to create a base map (e.g. forest/field/river), that gets
* refined later:
* @code
* void generate_foo( mapgendata &dat ) {
* mapgendata base_dat( dat, oter_id( "forest" ) );
* generate( base_dat );
* ... // refine map some more.
* }
* @endcode
*/
mapgendata( const mapgendata &other, const oter_id &other_id );
/**
* Creates a copy of this mapgendata, but stores new parameter values.
*/
mapgendata( const mapgendata &other, const mapgen_arguments & );
/**
* Creates a copy of this mapgendata, but stores new parameter values
* and flags.
*/
mapgendata( const mapgendata &other, const mapgen_arguments &,
const enum_bitset<jmapgen_flags> & );
const oter_id &terrain_type() const {
return terrain_type_;
}
float monster_density() const {
return density_;
}
const time_point &when() const {
return when_;
}
::mission *mission() const {
return mission_;
}
int zlevel() const {
// TODO: should be able to determine this from the map itself
return zlevel_;
}
void set_dir( int dir_in, int val );
void fill( int val );
int &dir( int dir_in );
const oter_id &north() const {
return t_nesw[0];
}
const oter_id &east() const {
return t_nesw[1];
}
const oter_id &south() const {
return t_nesw[2];
}
const oter_id &west() const {
return t_nesw[3];
}
const oter_id &neast() const {
return t_nesw[4];
}
const oter_id &seast() const {
return t_nesw[5];
}
const oter_id &swest() const {
return t_nesw[6];
}
const oter_id &nwest() const {
return t_nesw[7];
}
const oter_id &above() const {
return t_above;
}
const oter_id &below() const {
return t_below;
}
const oter_id &neighbor_at( om_direction::type dir ) const;
const oter_id &neighbor_at( direction ) const;
void fill_groundcover() const;
void square_groundcover( const point &p1, const point &p2 ) const;
ter_id groundcover() const;
bool is_groundcover( const ter_id &iid ) const;
bool has_flag( jmapgen_flags ) const;
bool has_join( cube_direction, const std::string &join_id ) const;
bool has_predecessor() const;
const oter_id &last_predecessor() const;
void pop_last_predecessor();
template<typename Result>
Result get_arg( const std::string &name ) const {
auto it = mapgen_args_.map.find( name );
if( it == mapgen_args_.map.end() ) {
debugmsg( "No such parameter \"%s\"", name );
return Result();
}
return mapgendata_detail::extract_variant_value<Result>( it->second );
}
template<typename Result>
Result get_arg_or( const std::string &name, const Result &fallback ) const {
auto it = mapgen_args_.map.find( name );
if( it == mapgen_args_.map.end() ) {
return fallback;
}
return mapgendata_detail::extract_variant_value<Result>( it->second );
}
};
#endif // CATA_SRC_MAPGENDATA_H