forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.cpp
190 lines (173 loc) · 8.4 KB
/
event.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
#include "event.h"
namespace io
{
template<>
std::string enum_to_string<event_type>( event_type data )
{
switch( data ) {
// *INDENT-OFF*
case event_type::activates_artifact: return "activates_artifact";
case event_type::activates_mininuke: return "activates_mininuke";
case event_type::administers_mutagen: return "administers_mutagen";
case event_type::angers_amigara_horrors: return "angers_amigara_horrors";
case event_type::avatar_moves: return "avatar_moves";
case event_type::awakes_dark_wyrms: return "awakes_dark_wyrms";
case event_type::becomes_wanted: return "becomes_wanted";
case event_type::broken_bone_mends: return "broken_bone_mends";
case event_type::buries_corpse: return "buries_corpse";
case event_type::causes_resonance_cascade: return "causes_resonance_cascade";
case event_type::character_gains_effect: return "character_gains_effect";
case event_type::character_gets_headshot: return "character_gets_headshot";
case event_type::character_heals_damage: return "character_heals_damage";
case event_type::character_kills_character: return "character_kills_character";
case event_type::character_kills_monster: return "character_kills_monster";
case event_type::character_loses_effect: return "character_loses_effect";
case event_type::character_takes_damage: return "character_takes_damage";
case event_type::character_triggers_trap: return "character_triggers_trap";
case event_type::character_wakes_up: return "character_wakes_up";
case event_type::consumes_marloss_item: return "consumes_marloss_item";
case event_type::crosses_marloss_threshold: return "crosses_marloss_threshold";
case event_type::crosses_mutation_threshold: return "crosses_mutation_threshold";
case event_type::crosses_mycus_threshold: return "crosses_mycus_threshold";
case event_type::dermatik_eggs_hatch: return "dermatik_eggs_hatch";
case event_type::dermatik_eggs_injected: return "dermatik_eggs_injected";
case event_type::destroys_triffid_grove: return "destroys_triffid_grove";
case event_type::dies_from_asthma_attack: return "dies_from_asthma_attack";
case event_type::dies_from_drug_overdose: return "dies_from_drug_overdose";
case event_type::dies_of_infection: return "dies_of_infection";
case event_type::dies_of_starvation: return "dies_of_starvation";
case event_type::dies_of_thirst: return "dies_of_thirst";
case event_type::digs_into_lava: return "digs_into_lava";
case event_type::disarms_nuke: return "disarms_nuke";
case event_type::eats_sewage: return "eats_sewage";
case event_type::evolves_mutation: return "evolves_mutation";
case event_type::exhumes_grave: return "exhumes_grave";
case event_type::fails_to_install_cbm: return "fails_to_install_cbm";
case event_type::fails_to_remove_cbm: return "fails_to_remove_cbm";
case event_type::falls_asleep_from_exhaustion: return "falls_asleep_from_exhaustion";
case event_type::fuel_tank_explodes: return "fuel_tank_explodes";
case event_type::gains_addiction: return "gains_addiction";
case event_type::gains_mutation: return "gains_mutation";
case event_type::gains_skill_level: return "gains_skill_level";
case event_type::game_over: return "game_over";
case event_type::game_start: return "game_start";
case event_type::installs_cbm: return "installs_cbm";
case event_type::installs_faulty_cbm: return "installs_faulty_cbm";
case event_type::learns_martial_art: return "learns_martial_art";
case event_type::loses_addiction: return "loses_addiction";
case event_type::npc_becomes_hostile: return "npc_becomes_hostile";
case event_type::opens_portal: return "opens_portal";
case event_type::opens_temple: return "opens_temple";
case event_type::player_levels_spell: return "player_levels_spell";
case event_type::releases_subspace_specimens: return "releases_subspace_specimens";
case event_type::removes_cbm: return "removes_cbm";
case event_type::seals_hazardous_material_sarcophagus: return "seals_hazardous_material_sarcophagus";
case event_type::telefrags_creature: return "telefrags_creature";
case event_type::teleglow_teleports: return "teleglow_teleports";
case event_type::teleports_into_wall: return "teleports_into_wall";
case event_type::terminates_subspace_specimens: return "terminates_subspace_specimens";
case event_type::throws_up: return "throws_up";
case event_type::triggers_alarm: return "triggers_alarm";
// *INDENT-ON*
case event_type::num_event_types:
break;
}
debugmsg( "Invalid event_type" );
abort();
}
} // namespace io
namespace cata
{
namespace event_detail
{
constexpr std::array<std::pair<const char *, cata_variant_type>,
event_spec_empty::fields.size()> event_spec_empty::fields;
constexpr std::array<std::pair<const char *, cata_variant_type>,
event_spec_character::fields.size()> event_spec_character::fields;
static_assert( static_cast<int>( event_type::num_event_types ) == 62,
"This static_assert is a reminder to add a definition below when you add a new "
"event_type. If your event_spec specialization inherits from another struct for "
"its fields definition then you probably don't need a definition here." );
#define DEFINE_EVENT_FIELDS(type) \
constexpr std::array<std::pair<const char *, cata_variant_type>, \
event_spec<event_type::type>::fields.size()> \
event_spec<event_type::type>::fields;
DEFINE_EVENT_FIELDS( player_levels_spell )
DEFINE_EVENT_FIELDS( activates_artifact )
DEFINE_EVENT_FIELDS( administers_mutagen )
DEFINE_EVENT_FIELDS( avatar_moves )
DEFINE_EVENT_FIELDS( broken_bone_mends )
DEFINE_EVENT_FIELDS( buries_corpse )
DEFINE_EVENT_FIELDS( character_gains_effect )
DEFINE_EVENT_FIELDS( character_heals_damage )
DEFINE_EVENT_FIELDS( character_kills_character )
DEFINE_EVENT_FIELDS( character_kills_monster )
DEFINE_EVENT_FIELDS( character_loses_effect )
DEFINE_EVENT_FIELDS( character_takes_damage )
DEFINE_EVENT_FIELDS( character_triggers_trap )
DEFINE_EVENT_FIELDS( character_wakes_up )
DEFINE_EVENT_FIELDS( consumes_marloss_item )
DEFINE_EVENT_FIELDS( crosses_mutation_threshold )
DEFINE_EVENT_FIELDS( dies_from_drug_overdose )
DEFINE_EVENT_FIELDS( evolves_mutation )
DEFINE_EVENT_FIELDS( fails_to_install_cbm )
DEFINE_EVENT_FIELDS( fails_to_remove_cbm )
DEFINE_EVENT_FIELDS( fuel_tank_explodes )
DEFINE_EVENT_FIELDS( gains_addiction )
DEFINE_EVENT_FIELDS( gains_mutation )
DEFINE_EVENT_FIELDS( gains_skill_level )
DEFINE_EVENT_FIELDS( game_over )
DEFINE_EVENT_FIELDS( game_start )
DEFINE_EVENT_FIELDS( installs_cbm )
DEFINE_EVENT_FIELDS( installs_faulty_cbm )
DEFINE_EVENT_FIELDS( learns_martial_art )
DEFINE_EVENT_FIELDS( loses_addiction )
DEFINE_EVENT_FIELDS( npc_becomes_hostile )
DEFINE_EVENT_FIELDS( removes_cbm )
DEFINE_EVENT_FIELDS( telefrags_creature )
DEFINE_EVENT_FIELDS( teleports_into_wall )
} // namespace event_detail
template<event_type Type>
static void get_fields_if_match( event_type type, event::fields_type &out )
{
if( Type == type ) {
out = { event_detail::event_spec<Type>::fields.begin(),
event_detail::event_spec<Type>::fields.end()
};
}
}
template<int... I>
static event::fields_type
get_fields_helper( event_type type, std::integer_sequence<int, I...> )
{
event::fields_type result;
bool discard[] = {
( get_fields_if_match<static_cast<event_type>( I )>( type, result ), true )...
};
( void ) discard;
return result;
}
event::fields_type event::get_fields( event_type type )
{
return get_fields_helper(
type, std::make_integer_sequence<int, static_cast<int>( event_type::num_event_types )> {} );
}
cata_variant event::get_variant( const std::string &key ) const
{
auto it = data_.find( key );
if( it == data_.end() ) {
debugmsg( "No such key %s in event of type %s", key,
io::enum_to_string( type_ ) );
abort();
}
return it->second;
}
cata_variant event::get_variant_or_void( const std::string &key ) const
{
auto it = data_.find( key );
if( it == data_.end() ) {
return cata_variant();
}
return it->second;
}
} // namespace cata