forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.cpp
297 lines (251 loc) · 7.46 KB
/
field.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
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
#include "field.h"
#include <algorithm>
#include <utility>
#include "calendar.h"
#include "int_id.h"
int field_entry::move_cost() const
{
return type.obj().get_move_cost( intensity - 1 );
}
int field_entry::extra_radiation_min() const
{
return type.obj().get_extra_radiation_min( intensity - 1 );
}
int field_entry::extra_radiation_max() const
{
return type.obj().get_extra_radiation_max( intensity - 1 );
}
int field_entry::radiation_hurt_damage_min() const
{
return type.obj().get_radiation_hurt_damage_min( intensity - 1 );
}
int field_entry::radiation_hurt_damage_max() const
{
return type.obj().get_radiation_hurt_damage_max( intensity - 1 );
}
std::string field_entry::radiation_hurt_message() const
{
return type.obj().get_radiation_hurt_message( intensity - 1 );
}
int field_entry::intensity_upgrade_chance() const
{
return type.obj().get_intensity_upgrade_chance( intensity - 1 );
}
time_duration field_entry::intensity_upgrade_duration() const
{
return type.obj().get_intensity_upgrade_duration( intensity - 1 );
}
int field_entry::monster_spawn_chance() const
{
return type.obj().get_monster_spawn_chance( intensity - 1 );
}
int field_entry::monster_spawn_count() const
{
return type.obj().get_monster_spawn_count( intensity - 1 );
}
int field_entry::monster_spawn_radius() const
{
return type.obj().get_monster_spawn_radius( intensity - 1 );
}
mongroup_id field_entry::monster_spawn_group() const
{
return type.obj().get_monster_spawn_group( intensity - 1 );
}
float field_entry::light_emitted() const
{
return type.obj().get_light_emitted( intensity - 1 );
}
float field_entry::local_light_override() const
{
return type.obj().get_local_light_override( intensity - 1 );
}
float field_entry::translucency() const
{
return type.obj().get_translucency( intensity - 1 );
}
bool field_entry::is_transparent() const
{
return type.obj().get_transparent( intensity - 1 );
}
int field_entry::convection_temperature_mod() const
{
return type.obj().get_convection_temperature_mod( intensity - 1 );
}
nc_color field_entry::color() const
{
return type.obj().get_color( intensity - 1 );
}
std::string field_entry::symbol() const
{
return type.obj().get_symbol( intensity - 1 );
}
field_type_id field_entry::get_field_type() const
{
return type;
}
field_type_id field_entry::set_field_type( const field_type_id &new_type )
{
type = new_type;
return type;
}
int field_entry::get_max_field_intensity() const
{
return type.obj().get_max_intensity();
}
int field_entry::get_field_intensity() const
{
return intensity;
}
int field_entry::set_field_intensity( int new_intensity )
{
is_alive = new_intensity > 0;
return intensity = std::max( std::min( new_intensity, get_max_field_intensity() ), 1 );
}
time_duration field_entry::get_field_age() const
{
return age;
}
time_duration field_entry::set_field_age( const time_duration &new_age )
{
return age = new_age;
}
field::field()
: _displayed_field_type( fd_null )
{
}
/*
Function: find_field
Returns a field entry corresponding to the field_type_id parameter passed in. If no fields are found then returns NULL.
Good for checking for existence of a field: if(myfield.find_field(fd_fire)) would tell you if the field is on fire.
*/
field_entry *field::find_field( const field_type_id &field_type_to_find )
{
if( !_displayed_field_type ) {
return nullptr;
}
const auto it = _field_type_list.find( field_type_to_find );
if( it != _field_type_list.end() ) {
return &it->second;
}
return nullptr;
}
const field_entry *field::find_field_c( const field_type_id &field_type_to_find ) const
{
if( !_displayed_field_type ) {
return nullptr;
}
const auto it = _field_type_list.find( field_type_to_find );
if( it != _field_type_list.end() ) {
return &it->second;
}
return nullptr;
}
const field_entry *field::find_field( const field_type_id &field_type_to_find ) const
{
return find_field_c( field_type_to_find );
}
/*
Function: add_field
Inserts the given field_type_id into the field list for a given tile if it does not already exist.
Returns false if the field_type_id already exists, true otherwise.
If the field already exists, it will return false BUT it will add the intensity/age to the current values for upkeep.
If you wish to modify an already existing field use find_field and modify the result.
Intensity defaults to 1, and age to 0 (permanent) if not specified.
*/
bool field::add_field( const field_type_id &field_type_to_add, const int new_intensity,
const time_duration &new_age )
{
// sanity check, we don't want to store fd_null
if( !field_type_to_add ) {
debugmsg( "Tried to add null field" );
return false;
}
auto it = _field_type_list.find( field_type_to_add );
if( it != _field_type_list.end() ) {
// Most fields stack intensities, but some add duration instead
if( it->first->stacking_type == fields::stacking_type::intensity ) {
it->second.set_field_intensity( it->second.get_field_intensity() + new_intensity );
} else {
time_duration half_life = field_type_to_add->half_life;
if( new_age < half_life ) {
it->second.mod_field_age( new_age - half_life );
}
}
return false;
}
if( !_displayed_field_type ||
field_type_to_add.obj().priority >= _displayed_field_type.obj().priority ) {
_displayed_field_type = field_type_to_add;
}
_field_type_list[field_type_to_add] = field_entry( field_type_to_add, new_intensity, new_age );
return true;
}
bool field::remove_field( const field_type_id &field_to_remove )
{
const auto it = _field_type_list.find( field_to_remove );
if( it == _field_type_list.end() ) {
return false;
}
remove_field( it );
return true;
}
void field::remove_field( std::map<field_type_id, field_entry>::iterator const it )
{
_field_type_list.erase( it );
_displayed_field_type = fd_null;
if( !_field_type_list.empty() ) {
for( auto &fld : _field_type_list ) {
if( !_displayed_field_type || fld.first.obj().priority >= _displayed_field_type.obj().priority ) {
_displayed_field_type = fld.first;
}
}
}
}
/*
Function: field_count
Returns the number of fields existing on the current tile.
*/
unsigned int field::field_count() const
{
return _field_type_list.size();
}
std::map<field_type_id, field_entry>::iterator field::begin()
{
return _field_type_list.begin();
}
std::map<field_type_id, field_entry>::const_iterator field::begin() const
{
return _field_type_list.begin();
}
std::map<field_type_id, field_entry>::iterator field::end()
{
return _field_type_list.end();
}
std::map<field_type_id, field_entry>::const_iterator field::end() const
{
return _field_type_list.end();
}
/*
Function: displayed_field_type
Returns the last added field type from the tile for drawing purposes.
*/
field_type_id field::displayed_field_type() const
{
return _displayed_field_type;
}
description_affix field::displayed_description_affix() const
{
return _displayed_field_type.obj().desc_affix;
}
int field::total_move_cost() const
{
int current_cost = 0;
for( auto &fld : _field_type_list ) {
current_cost += fld.second.move_cost();
}
return current_cost;
}
std::vector<field_effect> field_entry::field_effects() const
{
return type->get_intensity_level( intensity - 1 ).field_effects;
}