forked from freeorion/freeorion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffectParser1.cpp
259 lines (235 loc) · 10.3 KB
/
EffectParser1.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
#include "EffectParser1.h"
#include "../universe/Effects.h"
#include "../universe/ValueRef.h"
#include "../universe/Enums.h"
#include <boost/phoenix.hpp>
#include <boost/phoenix/function/adapt_function.hpp>
namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;
namespace parse { namespace detail {
using PassedMessageParams =
std::vector<std::pair<std::string, MovableEnvelope<ValueRef::ValueRef<std::string>>>>;
effect_payload construct_GenerateSitRepMessage1(
std::string& message_string, std::string& icon,
const PassedMessageParams& message_parameters,
const MovableEnvelope<ValueRef::ValueRef<int>>& recipient_empire_id,
EmpireAffiliationType affiliation,
std::string label,
bool stringtable_lookup,
bool& pass)
{
return effect_payload(
std::make_unique<Effect::GenerateSitRepMessage>(
message_string,
icon,
OpenEnvelopes(message_parameters, pass),
recipient_empire_id.OpenEnvelope(pass),
affiliation,
label,
stringtable_lookup
)
);
}
effect_payload construct_GenerateSitRepMessage2(
std::string& message_string, std::string& icon,
const PassedMessageParams& message_parameters,
EmpireAffiliationType affiliation,
const parse::detail::condition_payload& condition,
std::string label,
bool stringtable_lookup,
bool& pass)
{
return effect_payload(
std::make_unique<Effect::GenerateSitRepMessage>(
message_string,
icon,
OpenEnvelopes(message_parameters, pass),
affiliation,
condition.OpenEnvelope(pass),
label,
stringtable_lookup
)
);
}
effect_payload construct_GenerateSitRepMessage3(
std::string& message_string, std::string& icon,
const PassedMessageParams& message_parameters,
EmpireAffiliationType affiliation,
std::string label,
bool stringtable_lookup,
bool& pass)
{
return effect_payload(
std::make_unique<Effect::GenerateSitRepMessage>(
message_string,
icon,
OpenEnvelopes(message_parameters, pass),
affiliation,
label,
stringtable_lookup
)
);
}
BOOST_PHOENIX_ADAPT_FUNCTION(effect_payload, construct_GenerateSitRepMessage1_, construct_GenerateSitRepMessage1, 8)
BOOST_PHOENIX_ADAPT_FUNCTION(effect_payload, construct_GenerateSitRepMessage2_, construct_GenerateSitRepMessage2, 8)
BOOST_PHOENIX_ADAPT_FUNCTION(effect_payload, construct_GenerateSitRepMessage3_, construct_GenerateSitRepMessage3, 7)
effect_parser_rules_1::effect_parser_rules_1(
const parse::lexer& tok,
Labeller& label,
const condition_parser_grammar& condition_parser,
const value_ref_grammar<std::string>& string_grammar
) :
effect_parser_rules_1::base_type(start, "effect_parser_rules_1"),
int_rules(tok, label, condition_parser, string_grammar),
double_rules(tok, label, condition_parser, string_grammar),
empire_affiliation_type_enum(tok),
unlock_item_type_enum(tok),
one_or_more_string_and_string_ref_pair(string_and_string_ref)
{
qi::_1_type _1;
qi::_2_type _2;
qi::_3_type _3;
qi::_a_type _a;
qi::_b_type _b;
qi::_c_type _c;
qi::_d_type _d;
qi::_e_type _e;
qi::_f_type _f;
qi::_val_type _val;
qi::eps_type eps;
qi::_pass_type _pass;
qi::omit_type omit_;
using phoenix::new_;
using phoenix::construct;
using phoenix::push_back;
const boost::phoenix::function<construct_movable> construct_movable_;
const boost::phoenix::function<deconstruct_movable> deconstruct_movable_;
set_empire_meter_1 =
(( omit_[tok.SetEmpireMeter_] >> label(tok.empire_))
> int_rules.expr
> label(tok.meter_) > tok.string
> label(tok.value_) > double_rules.expr
) [ _val = construct_movable_(
new_<Effect::SetEmpireMeter>(
deconstruct_movable_(_1, _pass),
_2,
deconstruct_movable_(_3, _pass))) ]
;
set_empire_meter_2
= (( omit_[tok.SetEmpireMeter_]
>> label(tok.meter_)) > tok.string
> label(tok.value_) > double_rules.expr
) [ _val = construct_movable_(new_<Effect::SetEmpireMeter>(
_1,
deconstruct_movable_(_2, _pass))) ]
;
give_empire_content
= ( unlock_item_type_enum
> label(tok.name_) > string_grammar
> -(label(tok.empire_) > int_rules.expr)
) [ _val = construct_movable_(new_<Effect::GiveEmpireContent>(
deconstruct_movable_(_2, _pass),
_1,
deconstruct_movable_(_3, _pass))) ]
;
set_empire_tech_progress
= ( omit_[tok.SetEmpireTechProgress_]
> label(tok.name_) > string_grammar
> label(tok.progress_) > double_rules.expr
> -(label(tok.empire_) > int_rules.expr)
) [ _val = construct_movable_(new_<Effect::SetEmpireTechProgress>(
deconstruct_movable_(_1, _pass),
deconstruct_movable_(_2, _pass),
deconstruct_movable_(_3, _pass))) ]
;
// Note: the NoStringtableLookup flag controls the lookup both of template in Vartext and of the label in SitrepPanel.
generate_sitrep_message
= tok.GenerateSitRepMessage_
> label(tok.message_) > tok.string [ _a = _1 ]
> label(tok.label_) > tok.string [ _e = _1 ]
> (
tok.NoStringtableLookup_ [ _f = false ]
| eps [ _f = true ]
)
> -(label(tok.icon_) > tok.string [ _b = _1 ] )
> -(label(tok.parameters_) > one_or_more_string_and_string_ref_pair [_c = _1] )
> (
( // empire id specified, optionally with an affiliation type:
// useful to specify a single recipient empire, or the allies
// or enemies of a single empire
(( (label(tok.affiliation_) > empire_affiliation_type_enum [ _d = _1 ])
| eps [ _d = EmpireAffiliationType::AFFIL_SELF ]
)
>> label(tok.empire_)
) > int_rules.expr
[ _val = construct_GenerateSitRepMessage1_(_a, _b, _c, _1, _d, _e, _f, _pass) ]
)
| ( // condition specified, with an affiliation type of CanSee:
// used to specify CanSee affiliation
( label(tok.affiliation_) >> tok.CanSee_)
> label(tok.condition_) > condition_parser
[ _val = construct_GenerateSitRepMessage2_(_a, _b, _c, EmpireAffiliationType::AFFIL_CAN_SEE, _1, _e, _f, _pass) ]
)
| ( // condition specified, with an affiliation type of Human:
// used to specify Human affiliation
( label(tok.affiliation_) >> tok.Human_)
> label(tok.condition_) > condition_parser
[ _val = construct_GenerateSitRepMessage2_(_a, _b, _c, EmpireAffiliationType::AFFIL_HUMAN, _1, _e, _f, _pass) ]
)
| ( // no empire id or condition specified, with or without an
// affiliation type: useful to specify no or all empires
( (label(tok.affiliation_) > empire_affiliation_type_enum [ _d = _1 ])
| eps [ _d = EmpireAffiliationType::AFFIL_ANY ]
)
[ _val = construct_GenerateSitRepMessage3_(
_a, _b, _c,
_d, _e, _f, _pass) ]
)
)
;
set_overlay_texture
= ( omit_[tok.SetOverlayTexture_]
> label(tok.name_) > tok.string
> label(tok.size_) > double_rules.expr
) [ _val = construct_movable_(new_<Effect::SetOverlayTexture>(
_1,
deconstruct_movable_(_2, _pass))) ]
;
string_and_string_ref
=
(
label(tok.tag_) > tok.string [ _a = _1 ] >
label(tok.data_)
> ( int_rules.expr [ _b = construct_movable_(new_<ValueRef::StringCast<int>>(deconstruct_movable_(_1, _pass))) ]
| double_rules.expr [ _b = construct_movable_(new_<ValueRef::StringCast<double>>(deconstruct_movable_(_1, _pass))) ]
| tok.string [ _b = construct_movable_(new_<ValueRef::Constant<std::string>>(_1)) ]
| string_grammar [ _b = _1 ]
)
)
[_val = construct<string_and_string_ref_pair>(_a, _b)]
;
start
%= set_empire_meter_1
| set_empire_meter_2
| give_empire_content
| set_empire_tech_progress
| generate_sitrep_message
| set_overlay_texture
;
set_empire_meter_1.name("SetEmpireMeter (w/empire ID)");
set_empire_meter_2.name("SetEmpireMeter");
give_empire_content.name("GiveEmpireContent");
set_empire_tech_progress.name("SetEmpireTechProgress");
generate_sitrep_message.name("GenerateSitrepMessage");
set_overlay_texture.name("SetOverlayTexture");
string_and_string_ref.name("Tag and Data (string reference)");
#if DEBUG_EFFECT_PARSERS
debug(set_empire_meter_1);
debug(set_empire_meter_2);
debug(give_empire_content);
debug(set_empire_tech_progress);
debug(generate_sitrep_message);
debug(set_overlay_texture);
#endif
}
} }