forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield.h
187 lines (156 loc) · 7.25 KB
/
field.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
#pragma once
#ifndef CATA_SRC_FIELD_H
#define CATA_SRC_FIELD_H
#include <iosfwd>
#include <map>
#include <vector>
#include "calendar.h"
#include "color.h"
#include "enums.h"
#include "field_type.h"
#include "type_id.h"
/**
* An active or passive effect existing on a tile.
* Each effect can vary in intensity and age (usually used as a time to live).
*/
class field_entry
{
public:
field_entry() : type( fd_null.id_or( INVALID_FIELD_TYPE_ID ) ), intensity( 1 ), age( 0_turns ),
is_alive( false ) { }
field_entry( const field_type_id &t, const int i, const time_duration &a ) : type( t ),
intensity( i ), age( a ), is_alive( true ) { }
nc_color color() const;
std::string symbol() const;
// return intensity level object corresponding to the current field intensity
const field_intensity_level &get_intensity_level() const;
//Returns the field_type_id of the current field entry.
field_type_id get_field_type() const;
// Allows you to modify the field_type_id of the current field entry.
// This probably shouldn't be called outside of field::replace_field, as it
// breaks the field drawing code and field lookup
field_type_id set_field_type( const field_type_id &new_type );
// Returns the maximum intensity of the current field entry.
int get_max_field_intensity() const;
// Returns the current intensity of the current field entry.
int get_field_intensity() const;
// Allows you to modify the intensity of the current field entry.
int set_field_intensity( int new_intensity );
void mod_field_intensity( int mod );
/// @returns @ref age.
time_duration get_field_age() const;
/// Sets @ref age to the given value.
/// @returns New value of @ref age.
time_duration set_field_age( const time_duration &new_age );
/// Adds given value to @ref age.
/// @returns New value of @ref age.
time_duration mod_field_age( const time_duration &mod_age ) {
return set_field_age( get_field_age() + mod_age );
}
bool is_dangerous() const;
bool is_mopsafe() const;
//Returns the display name of the current field given its current intensity.
//IE: light smoke, smoke, heavy smoke
std::string name() const {
return type.obj().get_name( intensity - 1 );
}
//Returns true if this is an active field, false if it should be removed.
bool is_field_alive() const {
return intensity > 0 && is_alive;
}
bool gas_can_spread() const {
return is_field_alive() && type.obj().phase == phase_id::GAS && type.obj().percent_spread > 0;
}
void do_decay();
std::vector<field_effect> field_effects() const;
private:
// The field identifier.
field_type_id type;
// The intensity (higher is stronger), of the field entry.
int intensity;
// The age, of the field effect. 0 is permanent.
time_duration age;
// The time when the field will decay, initialized to 0.
time_point decay_time;
// True if this is an active field, false if it should be destroyed next check.
bool is_alive;
};
/**
* A variable sized collection of field entries on a given map square.
* It contains one (at most) entry of each field type (e. g. one smoke entry and one
* fire entry, but not two fire entries).
* Use @ref find_field to get the field entry of a specific type, or iterate over
* all entries via @ref begin and @ref end (allows range based iteration).
* There is @ref displayed_field_type to specific which field should be drawn on the map.
*/
class field
{
public:
field();
/**
* Returns a field entry corresponding to the field_type_id parameter passed in.
* If no fields are found then nullptr is returned.
* @param alive_only if true, returns non-null result only if field is alive
*/
field_entry *find_field( const field_type_id &field_type_to_find, bool alive_only = true );
/**
* Returns a field entry corresponding to the field_type_id parameter passed in.
* If no fields are found then nullptr is returned.
* @param alive_only if true, returns non-null result only if field is alive
*/
const field_entry *find_field( const field_type_id &field_type_to_find,
bool alive_only = true ) const;
/**
* Inserts the given field_type_id into the field list for a given tile if it does not already exist.
* 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.
* The intensity is added to an existing field entry, but the age is only used for newly added entries.
* @return false if the field_type_id already exists, true otherwise.
*/
bool add_field( const field_type_id &field_type_to_add, int new_intensity = 1,
const time_duration &new_age = 0_turns );
/**
* Removes the field entry with a type equal to the field_type_id parameter.
* Make sure to decrement the field counter in the submap if (and only if) the
* function returns true.
* @return True if the field was removed, false if it did not exist in the first place.
*/
bool remove_field( const field_type_id &field_to_remove );
/**
* Make sure to decrement the field counter in the submap.
* Removes the field entry, the iterator must point into @ref _field_type_list and must be valid.
*/
void remove_field( std::map<field_type_id, field_entry>::iterator );
/**
* Removes all fields.
* Don't forget to update field count in submap!
*/
void clear();
// Returns the number of fields existing on the current tile.
unsigned int field_count() const;
/**
* Returns field type that should be drawn.
*/
field_type_id displayed_field_type() const;
/**
* Returns the intensity of the drawn tile
*/
int displayed_intensity() const;
description_affix displayed_description_affix() const;
//Returns the vector iterator to begin searching through the list.
std::map<field_type_id, field_entry>::iterator begin();
std::map<field_type_id, field_entry>::const_iterator begin() const;
//Returns the vector iterator to end searching through the list.
std::map<field_type_id, field_entry>::iterator end();
std::map<field_type_id, field_entry>::const_iterator end() const;
/**
* Returns the total move cost from all fields.
*/
int total_move_cost() const;
private:
// A pointer lookup table of all field effects on the current tile.
std::map<field_type_id, field_entry> _field_type_list;
//_displayed_field_type currently is equal to the last field added to the square. You can modify this behavior in the class functions if you wish.
field_type_id _displayed_field_type;
};
#endif // CATA_SRC_FIELD_H