forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_type.cpp
189 lines (166 loc) · 5.47 KB
/
weather_type.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
#include "weather_type.h"
#include <cstdlib>
#include <set>
#include "assign.h"
#include "condition.h"
#include "debug.h"
#include "generic_factory.h"
#include "json.h"
namespace
{
generic_factory<weather_type> weather_type_factory( "weather_type" );
} // namespace
namespace io
{
template<>
std::string enum_to_string<precip_class>( precip_class data )
{
switch( data ) {
case precip_class::none:
return "none";
case precip_class::very_light:
return "very_light";
case precip_class::light:
return "light";
case precip_class::heavy:
return "heavy";
case precip_class::last:
break;
}
cata_fatal( "Invalid precip_class" );
}
template<>
std::string enum_to_string<sun_intensity_type>( sun_intensity_type data )
{
switch( data ) {
case sun_intensity_type::none:
return "none";
case sun_intensity_type::light:
return "light";
case sun_intensity_type::normal:
return "normal";
case sun_intensity_type::high:
return "high";
case sun_intensity_type::last:
break;
}
cata_fatal( "Invalid sun_intensity_type" );
}
template<>
std::string enum_to_string<weather_sound_category>( weather_sound_category data )
{
switch( data ) {
case weather_sound_category::drizzle:
return "drizzle";
case weather_sound_category::flurries:
return "flurries";
case weather_sound_category::rainy:
return "rainy";
case weather_sound_category::snow:
return "snow";
case weather_sound_category::snowstorm:
return "snowstorm";
case weather_sound_category::thunder:
return "thunder";
case weather_sound_category::silent:
return "silent";
case weather_sound_category::portal_storm:
return "portal_storm";
case weather_sound_category::clear:
return "clear";
case weather_sound_category::sunny:
return "sunny";
case weather_sound_category::cloudy:
return "cloudy";
case weather_sound_category::last:
break;
}
cata_fatal( "Invalid weather sound category." );
}
} // namespace io
template<>
const weather_type &weather_type_id::obj() const
{
return weather_type_factory.obj( *this );
}
/** @relates string_id */
template<>
bool string_id<weather_type>::is_valid() const
{
return weather_type_factory.is_valid( *this );
}
void weather_type::finalize()
{
}
void weather_type::check() const
{
for( const auto &type : required_weathers ) {
if( !type.is_valid() ) {
debugmsg( "Weather type %s does not exist.", type.c_str() );
}
}
}
void weather_type::load( const JsonObject &jo, const std::string & )
{
mandatory( jo, was_loaded, "name", name );
mandatory( jo, was_loaded, "id", id );
assign( jo, "color", color );
assign( jo, "map_color", map_color );
mandatory( jo, was_loaded, "sym", symbol, unicode_codepoint_from_symbol_reader );
mandatory( jo, was_loaded, "ranged_penalty", ranged_penalty );
mandatory( jo, was_loaded, "sight_penalty", sight_penalty );
mandatory( jo, was_loaded, "light_modifier", light_modifier );
mandatory( jo, was_loaded, "sound_attn", sound_attn );
mandatory( jo, was_loaded, "dangerous", dangerous );
mandatory( jo, was_loaded, "precip", precip );
mandatory( jo, was_loaded, "rains", rains );
optional( jo, was_loaded, "acidic", acidic, false );
optional( jo, was_loaded, "tiles_animation", tiles_animation, "" );
optional( jo, was_loaded, "sound_category", sound_category, weather_sound_category::silent );
mandatory( jo, was_loaded, "sun_intensity", sun_intensity );
optional( jo, was_loaded, "duration_min", duration_min, 5_minutes );
optional( jo, was_loaded, "duration_max", duration_max, 5_minutes );
if( duration_min > duration_max ) {
jo.throw_error( "duration_min must be less than or equal to duration_max" );
}
if( jo.has_member( "weather_animation" ) ) {
JsonObject weather_animation_jo = jo.get_object( "weather_animation" );
mandatory( weather_animation_jo, was_loaded, "factor", weather_animation.factor );
if( !assign( weather_animation_jo, "color", weather_animation.color ) ) {
weather_animation_jo.throw_error( "missing mandatory member \"color\"" );
}
mandatory( weather_animation_jo, was_loaded, "sym", weather_animation.symbol,
unicode_codepoint_from_symbol_reader );
}
optional( jo, was_loaded, "required_weathers", required_weathers );
read_condition<dialogue>( jo, "condition", condition, true );
}
void weather_types::reset()
{
weather_type_factory.reset();
}
void weather_types::finalize_all()
{
weather_type_factory.finalize();
for( const weather_type &wt : weather_type_factory.get_all() ) {
const_cast<weather_type &>( wt ).finalize();
}
}
const std::vector<weather_type> &weather_types::get_all()
{
return weather_type_factory.get_all();
}
void weather_types::check_consistency()
{
if( !WEATHER_CLEAR.is_valid() ) {
cata_fatal( "Weather type clear is required." );
}
if( !WEATHER_NULL.is_valid() ) {
cata_fatal( "Weather type null is required." );
}
weather_type_factory.check();
}
void weather_types::load( const JsonObject &jo, const std::string &src )
{
weather_type_factory.load( jo, src );
}