Project Alice
Loading...
Searching...
No Matches
effect_parsing.cpp
Go to the documentation of this file.
1#include "effect_parsing.hpp"
3
4namespace parsers {
5
6dcon::trigger_key ef_limit(token_generator& gen, error_handler& err, effect_building_context& context) {
7 trigger_building_context tr_context{context.outer_context, context.main_slot, context.this_slot, context.from_slot};
8 return make_trigger(gen, err, tr_context);
9}
10
12 auto old_limit_offset = context.limit_position;
13
14 context.compiled_effect.push_back(uint16_t(effect::if_scope | effect::scope_has_limit));
15 context.compiled_effect.push_back(uint16_t(0));
16 auto payload_size_offset = context.compiled_effect.size() - 1;
17 context.limit_position = context.compiled_effect.size();
18 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
19
20 parse_effect_body(gen, err, context);
21
22 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
23 context.limit_position = old_limit_offset;
24}
25
27 auto old_limit_offset = context.limit_position;
28
30 context.compiled_effect.push_back(uint16_t(0));
31 auto payload_size_offset = context.compiled_effect.size() - 1;
32 context.limit_position = context.compiled_effect.size();
33 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
34
35 parse_effect_body(gen, err, context);
36
37 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
38 context.limit_position = old_limit_offset;
39}
40
42 auto old_limit_offset = context.limit_position;
43
45 context.compiled_effect.push_back(uint16_t(0));
46 auto payload_size_offset = context.compiled_effect.size() - 1;
47 context.limit_position = context.compiled_effect.size();
48 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
49
50 parse_effect_body(gen, err, context);
51
52 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
53 context.limit_position = old_limit_offset;
54}
55
58 auto old_limit_offset = context.limit_position;
59
61 context.compiled_effect.push_back(uint16_t(0));
62 auto payload_size_offset = context.compiled_effect.size() - 1;
63 context.limit_position = context.compiled_effect.size();
64 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
65
66 parse_effect_body(gen, err, context);
67
68 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
69 context.limit_position = old_limit_offset;
70 }
71 else if (context.main_slot == trigger::slot_contents::nation) {
72 auto old_limit_offset = context.limit_position;
73 auto old_main = context.main_slot;
74
76 context.compiled_effect.push_back(uint16_t(0));
77 auto payload_size_offset = context.compiled_effect.size() - 1;
78 context.limit_position = context.compiled_effect.size();
79 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
80
81 // Change scope down to province
83 parse_effect_body(gen, err, context);
84
85 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
86 context.limit_position = old_limit_offset;
87 context.main_slot = old_main;
88 }
89 else {
90 gen.discard_group();
91 err.accumulated_errors += "any_neighbor_province effect scope used in an incorrect scope type (" + err.file_name + ")\n";
92 return;
93 }
94}
95
98 auto old_limit_offset = context.limit_position;
99
101 context.compiled_effect.push_back(uint16_t(0));
102 auto payload_size_offset = context.compiled_effect.size() - 1;
103 context.limit_position = context.compiled_effect.size();
104 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
105
106 parse_effect_body(gen, err, context);
107
108 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
109 context.limit_position = old_limit_offset;
110 } else {
111 gen.discard_group();
112 err.accumulated_errors += "any_neighbor_province effect scope used in an incorrect scope type (" + err.file_name + ")\n";
113 return;
114 }
115}
118 auto old_limit_offset = context.limit_position;
119
121 context.compiled_effect.push_back(uint16_t(0));
122 auto payload_size_offset = context.compiled_effect.size() - 1;
123 context.limit_position = context.compiled_effect.size();
124 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
125
126 parse_effect_body(gen, err, context);
127
128 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
129 context.limit_position = old_limit_offset;
130 } else {
131 gen.discard_group();
132 err.accumulated_errors += "any_neighbor_province effect scope used in an incorrect scope type (" + err.file_name + ")\n";
133 return;
134 }
135}
136
138 auto old_limit_offset = context.limit_position;
139 auto old_main = context.main_slot;
141 if(bool(context.outer_context.state.defines.alice_disable_divergent_any_country_effect)) {
143 } else {
144 if(context.effect_is_for_event) {
146 } else {
148 }
149 }
150 } else {
151 if(bool(context.outer_context.state.defines.alice_disable_divergent_any_country_effect)) {
153 } else {
154 if(context.effect_is_for_event) {
156 } else {
158 }
159 }
160 }
161
162 context.compiled_effect.push_back(uint16_t(0));
163 auto payload_size_offset = context.compiled_effect.size() - 1;
164
165 context.limit_position = context.compiled_effect.size();
166 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
167
169 parse_effect_body(gen, err, context);
170
171 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
172 context.limit_position = old_limit_offset;
173 context.main_slot = old_main;
174}
175
177 auto old_limit_offset = context.limit_position;
179 context.compiled_effect.push_back(uint16_t(0));
180 auto payload_size_offset = context.compiled_effect.size() - 1;
181 context.limit_position = context.compiled_effect.size();
182 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
183 //
184 auto old_from = context.from_slot;
185 context.from_slot = context.main_slot;
186 parse_effect_body(gen, err, context);
187 context.from_slot = old_from;
188 //
189 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
190 context.limit_position = old_limit_offset;
191}
193 auto old_limit_offset = context.limit_position;
195 context.compiled_effect.push_back(uint16_t(0));
196 auto payload_size_offset = context.compiled_effect.size() - 1;
197 context.limit_position = context.compiled_effect.size();
198 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
199 //
200 auto old_this = context.this_slot;
201 context.this_slot = context.main_slot;
202 parse_effect_body(gen, err, context);
203 context.this_slot = old_this;
204 //
205 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
206 context.limit_position = old_limit_offset;
207}
208
210 auto old_limit_offset = context.limit_position;
211 auto old_main = context.main_slot;
212
215 } else {
217 }
218 context.compiled_effect.push_back(uint16_t(0));
219 auto payload_size_offset = context.compiled_effect.size() - 1;
220
221 context.limit_position = context.compiled_effect.size();
222 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
223
225 parse_effect_body(gen, err, context);
226
227 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
228 context.limit_position = old_limit_offset;
229 context.main_slot = old_main;
230}
232 auto old_limit_offset = context.limit_position;
233 auto old_main = context.main_slot;
234
237 } else {
239 }
240 context.compiled_effect.push_back(uint16_t(0));
241 auto payload_size_offset = context.compiled_effect.size() - 1;
242
243 context.limit_position = context.compiled_effect.size();
244 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
245
247 parse_effect_body(gen, err, context);
248
249 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
250 context.limit_position = old_limit_offset;
251 context.main_slot = old_main;
252}
253
255 auto old_limit_offset = context.limit_position;
256 auto old_main = context.main_slot;
257
259 if(bool(context.outer_context.state.defines.alice_disable_divergent_any_country_effect)) {
261 } else {
262 if(context.effect_is_for_event) {
264 } else {
266 }
267 }
268 } else {
269 if(bool(context.outer_context.state.defines.alice_disable_divergent_any_country_effect)) {
271 } else {
272 if(context.effect_is_for_event) {
274 } else {
276 }
277 }
278 }
279
280 context.compiled_effect.push_back(uint16_t(0));
281 auto payload_size_offset = context.compiled_effect.size() - 1;
282
283 context.limit_position = context.compiled_effect.size();
284 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
285
287 parse_effect_body(gen, err, context);
288
289 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
290 context.limit_position = old_limit_offset;
291 context.main_slot = old_main;
292}
293
296 auto old_limit_offset = context.limit_position;
297
299 context.compiled_effect.push_back(uint16_t(0));
300 auto payload_size_offset = context.compiled_effect.size() - 1;
301 context.limit_position = context.compiled_effect.size();
302 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
303
304 parse_effect_body(gen, err, context);
305
306 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
307 context.limit_position = old_limit_offset;
308 }
309 else if(context.main_slot == trigger::slot_contents::nation) {
310 auto old_limit_offset = context.limit_position;
311 auto old_main = context.main_slot;
312
314 context.compiled_effect.push_back(uint16_t(0));
315 auto payload_size_offset = context.compiled_effect.size() - 1;
316 context.limit_position = context.compiled_effect.size();
317 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
318
319 // Change scope down to province
321 parse_effect_body(gen, err, context);
322
323 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
324 context.limit_position = old_limit_offset;
325 context.main_slot = old_main;
326 }
327 else {
328 gen.discard_group();
329 err.accumulated_errors += "random_neighbor_province effect scope used in an incorrect scope type (" + err.file_name + ")\n";
330 return;
331 }
332}
333
336 auto old_limit_offset = context.limit_position;
337
339 context.compiled_effect.push_back(uint16_t(0));
340 auto payload_size_offset = context.compiled_effect.size() - 1;
341 context.limit_position = context.compiled_effect.size();
342 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
343
344 parse_effect_body(gen, err, context);
345
346 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
347 context.limit_position = old_limit_offset;
348 }
349 else if(context.main_slot == trigger::slot_contents::nation) {
350 auto old_limit_offset = context.limit_position;
351 auto old_main = context.main_slot;
352
354 context.compiled_effect.push_back(uint16_t(0));
355 auto payload_size_offset = context.compiled_effect.size() - 1;
356 context.limit_position = context.compiled_effect.size();
357 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
358
359 // Change scope down to province
361 parse_effect_body(gen, err, context);
362
363 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
364 context.limit_position = old_limit_offset;
365 context.main_slot = old_main;
366 }
367 else {
368 gen.discard_group();
369 err.accumulated_errors += "any_empty_neighbor_province effect scope used in an incorrect scope type(" + err.file_name + ")\n";
370 return;
371 }
372}
373
376 auto old_limit_offset = context.limit_position;
377
379 context.compiled_effect.push_back(uint16_t(0));
380 auto payload_size_offset = context.compiled_effect.size() - 1;
381 context.limit_position = context.compiled_effect.size();
382 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
383
384 parse_effect_body(gen, err, context);
385
386 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
387 context.limit_position = old_limit_offset;
388 }
389 else if(context.main_slot == trigger::slot_contents::nation) {
390 auto old_limit_offset = context.limit_position;
391 auto old_main = context.main_slot;
392
394 context.compiled_effect.push_back(uint16_t(0));
395 auto payload_size_offset = context.compiled_effect.size() - 1;
396 context.limit_position = context.compiled_effect.size();
397 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
398
399 // Change scope down to province
401 parse_effect_body(gen, err, context);
402
403 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
404 context.limit_position = old_limit_offset;
405 context.main_slot = old_main;
406 }
407 else {
408 gen.discard_group();
409 err.accumulated_errors += "random_empty_neighbor_province effect scope used in an incorrect scope type (" + err.file_name + ")\n";
410 return;
411 }
412}
413
415 auto old_limit_offset = context.limit_position;
416 auto old_main = context.main_slot;
417
419 context.compiled_effect.push_back(uint16_t(0));
420 auto payload_size_offset = context.compiled_effect.size() - 1;
421
422 context.limit_position = context.compiled_effect.size();
423 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
424
426 parse_effect_body(gen, err, context);
427
428 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
429 context.limit_position = old_limit_offset;
430 context.main_slot = old_main;
431}
432
434 auto old_limit_offset = context.limit_position;
435 auto old_main = context.main_slot;
436
438 context.compiled_effect.push_back(uint16_t(0));
439 auto payload_size_offset = context.compiled_effect.size() - 1;
440
441 context.limit_position = context.compiled_effect.size();
442 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
443
445 parse_effect_body(gen, err, context);
446
447 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
448 context.limit_position = old_limit_offset;
449 context.main_slot = old_main;
450}
451
453 auto old_limit_offset = context.limit_position;
454 auto old_main = context.main_slot;
455
458 } else if(context.main_slot == trigger::slot_contents::state) {
460 } else if(context.main_slot == trigger::slot_contents::nation) {
462 } else {
463 gen.discard_group();
464 err.accumulated_errors += "poor_strata effect scope used in an incorrect scope type (" + err.file_name + ")\n";
465 return;
466 }
467
468 context.compiled_effect.push_back(uint16_t(0));
469 auto payload_size_offset = context.compiled_effect.size() - 1;
470
471 context.limit_position = context.compiled_effect.size();
472 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
473
475 parse_effect_body(gen, err, context);
476
477 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
478 context.limit_position = old_limit_offset;
479 context.main_slot = old_main;
480}
481
483 auto old_limit_offset = context.limit_position;
484 auto old_main = context.main_slot;
485
488 } else if(context.main_slot == trigger::slot_contents::state) {
490 } else if(context.main_slot == trigger::slot_contents::nation) {
492 } else {
493 gen.discard_group();
494 err.accumulated_errors += "middle_strata effect scope used in an incorrect scope type (" + err.file_name + ")\n";
495 return;
496 }
497
498 context.compiled_effect.push_back(uint16_t(0));
499 auto payload_size_offset = context.compiled_effect.size() - 1;
500
501 context.limit_position = context.compiled_effect.size();
502 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
503
505 parse_effect_body(gen, err, context);
506
507 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
508 context.limit_position = old_limit_offset;
509 context.main_slot = old_main;
510}
511
513 auto old_limit_offset = context.limit_position;
514 auto old_main = context.main_slot;
515
518 } else if(context.main_slot == trigger::slot_contents::state) {
520 } else if(context.main_slot == trigger::slot_contents::nation) {
522 } else {
523 gen.discard_group();
524 err.accumulated_errors += "rich_strata effect scope used in an incorrect scope type (" + err.file_name + ")\n";
525 return;
526 }
527
528 context.compiled_effect.push_back(uint16_t(0));
529 auto payload_size_offset = context.compiled_effect.size() - 1;
530
531 context.limit_position = context.compiled_effect.size();
532 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
533
535 parse_effect_body(gen, err, context);
536
537 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
538 context.limit_position = old_limit_offset;
539 context.main_slot = old_main;
540}
541
543 auto old_limit_offset = context.limit_position;
544 auto old_main = context.main_slot;
545
548 } else if(context.main_slot == trigger::slot_contents::state) {
550 } else if(context.main_slot == trigger::slot_contents::nation) {
552 } else {
553 gen.discard_group();
554 err.accumulated_errors += "random_pop effect scope used in an incorrect scope type (" + err.file_name + ")\n";
555 return;
556 }
557
558 context.compiled_effect.push_back(uint16_t(0));
559 auto payload_size_offset = context.compiled_effect.size() - 1;
560
561 context.limit_position = context.compiled_effect.size();
562 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
563
565 parse_effect_body(gen, err, context);
566
567 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
568 context.limit_position = old_limit_offset;
569 context.main_slot = old_main;
570}
572 auto old_limit_offset = context.limit_position;
573 auto old_main = context.main_slot;
574
575 auto const scope_offset = context.compiled_effect.size();
578 } else if(context.main_slot == trigger::slot_contents::nation) {
580 } else if(context.main_slot == trigger::slot_contents::province) { // we parse this as basically a do-nothing scope
582 context.compiled_effect.push_back(uint16_t(0));
583 auto payload_size_offset = context.compiled_effect.size() - 1;
584 context.limit_position = context.compiled_effect.size();
585 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
586
587 parse_effect_body(gen, err, context);
588
589 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
590 context.limit_position = old_limit_offset;
591
592 auto const new_scope_size = simplify_effect(context.compiled_effect.data() + scope_offset);
593 context.compiled_effect.resize(scope_offset + size_t(new_scope_size));
594 return;
595 } else {
596 gen.discard_group();
597 err.accumulated_errors += "random_owned effect scope used in an incorrect scope type (" + err.file_name + ")\n";
598 return;
599 }
600
601 context.compiled_effect.push_back(uint16_t(0));
602 auto payload_size_offset = context.compiled_effect.size() - 1;
603
604 context.limit_position = context.compiled_effect.size();
605 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
606
608 parse_effect_body(gen, err, context);
609
610 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
611 context.limit_position = old_limit_offset;
612 context.main_slot = old_main;
613
614 auto const new_scope_size = simplify_effect(context.compiled_effect.data() + scope_offset);
615 context.compiled_effect.resize(scope_offset + size_t(new_scope_size));
616}
617
619 auto old_limit_offset = context.limit_position;
620 auto old_main = context.main_slot;
621
624 } else if(context.main_slot == trigger::slot_contents::nation) {
626 } else if(context.main_slot == trigger::slot_contents::province) { // we parse this as basically a do-nothing scope
628 context.compiled_effect.push_back(uint16_t(0));
629 auto payload_size_offset = context.compiled_effect.size() - 1;
630 context.limit_position = context.compiled_effect.size();
631 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
632
633 parse_effect_body(gen, err, context);
634
635 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
636 context.limit_position = old_limit_offset;
637 return;
638 } else {
639 gen.discard_group();
640 err.accumulated_errors += "any_owned effect scope used in an incorrect scope type (" + err.file_name + ")\n";
641 return;
642 }
643
644 context.compiled_effect.push_back(uint16_t(0));
645 auto payload_size_offset = context.compiled_effect.size() - 1;
646
647 context.limit_position = context.compiled_effect.size();
648 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
649
651 parse_effect_body(gen, err, context);
652
653 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
654 context.limit_position = old_limit_offset;
655 context.main_slot = old_main;
656}
658 auto old_limit_offset = context.limit_position;
659 auto old_main = context.main_slot;
660
662 context.compiled_effect.push_back(uint16_t(effect::x_core_scope | effect::scope_has_limit));
664 } else if(context.main_slot == trigger::slot_contents::province) {
667 } else {
668 gen.discard_group();
669 err.accumulated_errors += "all_core effect scope used in an incorrect scope type (" + err.file_name + ")\n";
670 return;
671 }
672
673 context.compiled_effect.push_back(uint16_t(0));
674 auto payload_size_offset = context.compiled_effect.size() - 1;
675
676 context.limit_position = context.compiled_effect.size();
677 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
678
679
680 parse_effect_body(gen, err, context);
681
682 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
683 context.limit_position = old_limit_offset;
684 context.main_slot = old_main;
685}
687 auto old_limit_offset = context.limit_position;
688 auto old_main = context.main_slot;
689
692 } else {
693 gen.discard_group();
694 err.accumulated_errors += "any_state effect scope used in an incorrect scope type (" + err.file_name + ")\n";
695 return;
696 }
697
698 context.compiled_effect.push_back(uint16_t(0));
699 auto payload_size_offset = context.compiled_effect.size() - 1;
700
701 context.limit_position = context.compiled_effect.size();
702 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
703
705 parse_effect_body(gen, err, context);
706
707 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
708 context.limit_position = old_limit_offset;
709 context.main_slot = old_main;
710}
711
713 auto old_limit_offset = context.limit_position;
714
717 } else {
718 gen.discard_group();
719 err.accumulated_errors += "any_substate effect scope used in an incorrect scope type (" + err.file_name + ")\n";
720 return;
721 }
722
723 context.compiled_effect.push_back(uint16_t(0));
724 auto payload_size_offset = context.compiled_effect.size() - 1;
725
726 context.limit_position = context.compiled_effect.size();
727 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
728
729 parse_effect_body(gen, err, context);
730
731 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
732 context.limit_position = old_limit_offset;
733}
734
736 auto old_limit_offset = context.limit_position;
737 auto old_main = context.main_slot;
738
741 } else {
742 gen.discard_group();
743 err.accumulated_errors += "random_state effect scope used in an incorrect scope type (" + err.file_name + ")\n";
744 return;
745 }
746
747 context.compiled_effect.push_back(uint16_t(0));
748 auto payload_size_offset = context.compiled_effect.size() - 1;
749
750 context.limit_position = context.compiled_effect.size();
751 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
752
754 parse_effect_body(gen, err, context);
755
756 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
757 context.limit_position = old_limit_offset;
758 context.main_slot = old_main;
759}
760
762 auto old_limit_offset = context.limit_position;
763 auto old_main = context.main_slot;
764
767 } else if(context.main_slot == trigger::slot_contents::state) {
769 } else if(context.main_slot == trigger::slot_contents::nation) {
771 } else {
772 gen.discard_group();
773 err.accumulated_errors += "any_pop effect scope used in an incorrect scope type (" + err.file_name + ")\n";
774 return;
775 }
776
777 context.compiled_effect.push_back(uint16_t(0));
778 auto payload_size_offset = context.compiled_effect.size() - 1;
779
780 context.limit_position = context.compiled_effect.size();
781 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
782
784 parse_effect_body(gen, err, context);
785
786 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
787 context.limit_position = old_limit_offset;
788 context.main_slot = old_main;
789}
791 auto old_limit_offset = context.limit_position;
792 auto old_main = context.main_slot;
793
796 } else if(context.main_slot == trigger::slot_contents::province) {
798 } else if(context.main_slot == trigger::slot_contents::nation) {
800 context.compiled_effect.push_back(uint16_t(0));
801 auto payload_size_offset = context.compiled_effect.size() - 1;
802 context.limit_position = context.compiled_effect.size();
803 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
804
805 parse_effect_body(gen, err, context);
806
807 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
808 context.limit_position = old_limit_offset;
809 return;
810 } else {
811 gen.discard_group();
812 err.accumulated_errors += "owner effect scope used in an incorrect scope type (" + err.file_name + ")\n";
813 return;
814 }
815
816 context.compiled_effect.push_back(uint16_t(0));
817 auto payload_size_offset = context.compiled_effect.size() - 1;
818
819 context.limit_position = context.compiled_effect.size();
820 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
821
823 parse_effect_body(gen, err, context);
824
825 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
826 context.limit_position = old_limit_offset;
827 context.main_slot = old_main;
828}
830 auto old_limit_offset = context.limit_position;
831 auto old_main = context.main_slot;
832
835 } else {
836 gen.discard_group();
837 err.accumulated_errors += "controller effect scope used in an incorrect scope type (" + err.file_name + ")\n";
838 return;
839 }
840
841 context.compiled_effect.push_back(uint16_t(0));
842 auto payload_size_offset = context.compiled_effect.size() - 1;
843
844 context.limit_position = context.compiled_effect.size();
845 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
846
848 parse_effect_body(gen, err, context);
849
850 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
851 context.limit_position = old_limit_offset;
852 context.main_slot = old_main;
853}
855 auto old_limit_offset = context.limit_position;
856 auto old_main = context.main_slot;
857
860 } else {
861 gen.discard_group();
862 err.accumulated_errors += "location effect scope used in an incorrect scope type (" + err.file_name + ")\n";
863 return;
864 }
865
866 context.compiled_effect.push_back(uint16_t(0));
867 auto payload_size_offset = context.compiled_effect.size() - 1;
868
869 context.limit_position = context.compiled_effect.size();
870 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
871
873 parse_effect_body(gen, err, context);
874
875 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
876 context.limit_position = old_limit_offset;
877 context.main_slot = old_main;
878}
880 auto old_limit_offset = context.limit_position;
881 auto old_main = context.main_slot;
882
885 } else if(context.main_slot == trigger::slot_contents::pop) {
887 } else {
888 gen.discard_group();
889 err.accumulated_errors += "country effect scope used in an incorrect scope type (" + err.file_name + ")\n";
890 return;
891 }
892
893 context.compiled_effect.push_back(uint16_t(0));
894 auto payload_size_offset = context.compiled_effect.size() - 1;
895
896 context.limit_position = context.compiled_effect.size();
897 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
898
900 parse_effect_body(gen, err, context);
901
902 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
903 context.limit_position = old_limit_offset;
904 context.main_slot = old_main;
905}
907 auto old_limit_offset = context.limit_position;
908 auto old_main = context.main_slot;
909
912 } else if(context.main_slot == trigger::slot_contents::province) {
914 } else {
915 gen.discard_group();
916 err.accumulated_errors += "capital_scope effect scope used in an incorrect scope type (" + err.file_name + ")\n";
917 return;
918 }
919
920 context.compiled_effect.push_back(uint16_t(0));
921 auto payload_size_offset = context.compiled_effect.size() - 1;
922
923 context.limit_position = context.compiled_effect.size();
924 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
925
927 parse_effect_body(gen, err, context);
928
929 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
930 context.limit_position = old_limit_offset;
931 context.main_slot = old_main;
932}
934 auto old_limit_offset = context.limit_position;
935 auto old_main = context.main_slot;
936
939 } else if(context.main_slot == trigger::slot_contents::province) {
941 } else if(context.main_slot == trigger::slot_contents::pop) {
943 } else if(context.main_slot == trigger::slot_contents::nation) {
945 } else {
946 gen.discard_group();
947 err.accumulated_errors += "this effect scope used in an incorrect scope type (" + err.file_name + ")\n";
948 return;
949 }
950
951 context.compiled_effect.push_back(uint16_t(0));
952 auto payload_size_offset = context.compiled_effect.size() - 1;
953
954 context.limit_position = context.compiled_effect.size();
955 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
956
957 context.main_slot = context.this_slot;
958 parse_effect_body(gen, err, context);
959
960 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
961 context.limit_position = old_limit_offset;
962 context.main_slot = old_main;
963}
964
966 auto old_limit_offset = context.limit_position;
967 auto old_main = context.main_slot;
968
971 } else if(context.main_slot == trigger::slot_contents::province) {
973 } else if(context.main_slot == trigger::slot_contents::pop) {
975 } else if(context.main_slot == trigger::slot_contents::nation) {
977 } else {
978 gen.discard_group();
979 err.accumulated_errors += "from effect scope used in an incorrect scope type (" + err.file_name + ")\n";
980 return;
981 }
982
983 context.compiled_effect.push_back(uint16_t(0));
984 auto payload_size_offset = context.compiled_effect.size() - 1;
985
986 context.limit_position = context.compiled_effect.size();
987 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
988
989 context.main_slot = context.from_slot;
990 parse_effect_body(gen, err, context);
991
992 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
993 context.limit_position = old_limit_offset;
994 context.main_slot = old_main;
995}
996
998 auto old_limit_offset = context.limit_position;
999
1001 context.compiled_effect.push_back(uint16_t(effect::sea_zone_scope | effect::scope_has_limit));
1002 } else {
1003 gen.discard_group();
1004 err.accumulated_errors += "sea_zone effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1005 return;
1006 }
1007
1008 context.compiled_effect.push_back(uint16_t(0));
1009 auto payload_size_offset = context.compiled_effect.size() - 1;
1010
1011 context.limit_position = context.compiled_effect.size();
1012 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1013
1014 parse_effect_body(gen, err, context);
1015
1016 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1017 context.limit_position = old_limit_offset;
1018}
1019
1021 auto old_limit_offset = context.limit_position;
1022
1025 } else {
1026 gen.discard_group();
1027 err.accumulated_errors += "cultural_union effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1028 return;
1029 }
1030
1031 context.compiled_effect.push_back(uint16_t(0));
1032 auto payload_size_offset = context.compiled_effect.size() - 1;
1033
1034 context.limit_position = context.compiled_effect.size();
1035 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1036
1037 parse_effect_body(gen, err, context);
1038
1039 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1040 context.limit_position = old_limit_offset;
1041}
1042
1044 auto old_limit_offset = context.limit_position;
1045
1047 context.compiled_effect.push_back(uint16_t(effect::overlord_scope | effect::scope_has_limit));
1048 } else {
1049 gen.discard_group();
1050 err.accumulated_errors += "overlord effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1051 return;
1052 }
1053
1054 context.compiled_effect.push_back(uint16_t(0));
1055 auto payload_size_offset = context.compiled_effect.size() - 1;
1056
1057 context.limit_position = context.compiled_effect.size();
1058 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1059
1060 parse_effect_body(gen, err, context);
1061
1062 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1063 context.limit_position = old_limit_offset;
1064}
1065
1067 auto old_limit_offset = context.limit_position;
1068
1071 } else {
1072 gen.discard_group();
1073 err.accumulated_errors += "sphere_owner effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1074 return;
1075 }
1076
1077 context.compiled_effect.push_back(uint16_t(0));
1078 auto payload_size_offset = context.compiled_effect.size() - 1;
1079
1080 context.limit_position = context.compiled_effect.size();
1081 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1082
1083 parse_effect_body(gen, err, context);
1084
1085 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1086 context.limit_position = old_limit_offset;
1087}
1088
1090 auto old_limit_offset = context.limit_position;
1091 auto old_main = context.main_slot;
1092
1095 } else {
1096 gen.discard_group();
1097 err.accumulated_errors += "independence effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1098 return;
1099 }
1100
1101 context.compiled_effect.push_back(uint16_t(0));
1102 auto payload_size_offset = context.compiled_effect.size() - 1;
1103
1104 context.limit_position = context.compiled_effect.size();
1105 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1106
1108 parse_effect_body(gen, err, context);
1109
1110 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1111 context.limit_position = old_limit_offset;
1112 context.main_slot = old_main;
1113}
1115 auto old_limit_offset = context.limit_position;
1116 auto old_main = context.main_slot;
1117
1120 } else {
1121 gen.discard_group();
1122 err.accumulated_errors += "flashpoint_tag_scope effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1123 return;
1124 }
1125
1126 context.compiled_effect.push_back(uint16_t(0));
1127 auto payload_size_offset = context.compiled_effect.size() - 1;
1128
1129 context.limit_position = context.compiled_effect.size();
1130 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1131
1133 parse_effect_body(gen, err, context);
1134
1135 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1136 context.limit_position = old_limit_offset;
1137 context.main_slot = old_main;
1138}
1140 auto old_limit_offset = context.limit_position;
1141 auto old_main = context.main_slot;
1142
1144
1145 context.compiled_effect.push_back(uint16_t(0));
1146 auto payload_size_offset = context.compiled_effect.size() - 1;
1147
1148 context.limit_position = context.compiled_effect.size();
1149 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1150
1152 parse_effect_body(gen, err, context);
1153
1154 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1155 context.limit_position = old_limit_offset;
1156 context.main_slot = old_main;
1157}
1158
1160 if(context.main_slot == trigger::slot_contents::state) { // for the case where state context is added within state context
1161 auto old_limit_offset = context.limit_position;
1162
1163 context.compiled_effect.push_back(uint16_t(effect::generic_scope | effect::scope_has_limit));
1164 context.compiled_effect.push_back(uint16_t(0));
1165 auto payload_size_offset = context.compiled_effect.size() - 1;
1166 context.limit_position = context.compiled_effect.size();
1167 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1168
1169 parse_effect_body(gen, err, context);
1170
1171 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1172 context.limit_position = old_limit_offset;
1173
1174 return;
1175 }
1176
1177 auto old_limit_offset = context.limit_position;
1178 auto old_main = context.main_slot;
1179
1182 } else if(context.main_slot == trigger::slot_contents::pop) {
1184 } else {
1185 gen.discard_group();
1186 err.accumulated_errors += "state_scope effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1187 return;
1188 }
1189
1190 context.compiled_effect.push_back(uint16_t(0));
1191 auto payload_size_offset = context.compiled_effect.size() - 1;
1192
1193 context.limit_position = context.compiled_effect.size();
1194 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1195
1197 parse_effect_body(gen, err, context);
1198
1199 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1200 context.limit_position = old_limit_offset;
1201 context.main_slot = old_main;
1202}
1203
1205 auto old_limit_offset = context.limit_position;
1206
1207 context.compiled_effect.push_back(uint16_t(effect::random_scope | effect::scope_has_limit));
1208
1209 context.compiled_effect.push_back(uint16_t(0));
1210 auto payload_size_offset = context.compiled_effect.size() - 1;
1211
1212 context.limit_position = context.compiled_effect.size();
1213 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1214 context.compiled_effect.push_back(uint16_t(0));
1215
1216 auto read_body = parse_effect_body(gen, err, context);
1217
1218 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1219 context.compiled_effect[payload_size_offset + 2] = uint16_t(read_body.chance);
1220 context.limit_position = old_limit_offset;
1221}
1222
1224 auto old_limit_offset = context.limit_position;
1225
1227
1228 context.compiled_effect.push_back(uint16_t(0));
1229 auto payload_size_offset = context.compiled_effect.size() - 1;
1230
1231 context.limit_position = context.compiled_effect.size();
1232 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1233 context.compiled_effect.push_back(uint16_t(0));
1234
1235 auto read_body = parse_ef_scope_random_by_modifier(gen, err, context);
1236
1237 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1238 context.compiled_effect[payload_size_offset + 2] = uint16_t(read_body.chance_modifier.index());
1239 static_assert(sizeof(dcon::value_modifier_key::value_base_t) == sizeof(uint16_t));
1240 context.limit_position = old_limit_offset;
1241}
1242
1243dcon::value_modifier_key read_chance_modifier(token_generator& gen, error_handler& err, effect_building_context& context) {
1244 trigger_building_context t_context{ context.outer_context, context.main_slot, context.this_slot, context.from_slot };
1245 return make_value_modifier(gen, err, t_context);
1246}
1247
1248int32_t add_to_random_list(std::string_view label, token_generator& gen, error_handler& err, effect_building_context& context) {
1249 auto ivalue = parse_int(label, 0, err);
1250 context.compiled_effect.push_back(uint16_t(ivalue));
1251
1252 auto old_limit_offset = context.limit_position;
1253 context.compiled_effect.push_back(uint16_t(effect::generic_scope | effect::scope_has_limit));
1254 context.compiled_effect.push_back(uint16_t(0));
1255 auto payload_size_offset = context.compiled_effect.size() - 1;
1256 context.limit_position = context.compiled_effect.size();
1257 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1258
1259 parse_effect_body(gen, err, context);
1260
1261 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1262 context.limit_position = old_limit_offset;
1263
1264 return ivalue;
1265}
1266
1268 auto old_limit_offset = context.limit_position;
1269
1270 context.compiled_effect.push_back(uint16_t(effect::random_list_scope));
1271
1272 context.compiled_effect.push_back(uint16_t(0));
1273 auto payload_size_offset = context.compiled_effect.size() - 1;
1274
1275 context.limit_position = context.compiled_effect.size();
1276 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1277
1278 auto random_set = parse_ef_random_list(gen, err, context);
1279
1280 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1281 context.compiled_effect[payload_size_offset + 1] = uint16_t(std::max(random_set.chances_sum, 1));
1282
1283 context.limit_position = old_limit_offset;
1284}
1285
1286void ef_scope_variable(std::string_view label, token_generator& gen, error_handler& err, effect_building_context& context) {
1287 std::string str_label{label};
1288 if(auto it = context.outer_context.map_of_state_names.find(str_label); it != context.outer_context.map_of_state_names.end()) {
1289 auto old_limit_offset = context.limit_position;
1290 auto old_main = context.main_slot;
1291
1292 context.compiled_effect.push_back(uint16_t(effect::region_scope | effect::scope_has_limit));
1293
1294 context.compiled_effect.push_back(uint16_t(0));
1295 auto payload_size_offset = context.compiled_effect.size() - 1;
1296
1297 context.limit_position = context.compiled_effect.size();
1298 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1299
1300 context.compiled_effect.push_back(trigger::payload(it->second).value);
1301
1303 parse_effect_body(gen, err, context);
1304
1305 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1306 context.limit_position = old_limit_offset;
1307 context.main_slot = old_main;
1308 } else if(auto itr = context.outer_context.map_of_region_names.find(str_label); itr != context.outer_context.map_of_region_names.end()) {
1309 auto old_limit_offset = context.limit_position;
1310 auto old_main = context.main_slot;
1311
1313
1314 context.compiled_effect.push_back(uint16_t(0));
1315 auto payload_size_offset = context.compiled_effect.size() - 1;
1316
1317 context.limit_position = context.compiled_effect.size();
1318 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1319
1320 context.compiled_effect.push_back(trigger::payload(itr->second).value);
1321
1323 parse_effect_body(gen, err, context);
1324
1325 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1326 context.limit_position = old_limit_offset;
1327 context.main_slot = old_main;
1328 } else if(auto itb = context.outer_context.map_of_poptypes.find(str_label);
1329 itb != context.outer_context.map_of_poptypes.end()) {
1330
1333 else if(context.main_slot == trigger::slot_contents::state)
1337 else {
1338 gen.discard_group();
1339 err.accumulated_errors += "pop type effect scope used in an incorrect scope type (" + err.file_name + ")\n";
1340 return;
1341 }
1342
1343 auto old_limit_offset = context.limit_position;
1344 auto old_main = context.main_slot;
1345
1346 context.compiled_effect.push_back(uint16_t(0));
1347 auto payload_size_offset = context.compiled_effect.size() - 1;
1348
1349 context.limit_position = context.compiled_effect.size();
1350 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1351
1352 context.compiled_effect.push_back(trigger::payload(itb->second).value);
1353
1355 parse_effect_body(gen, err, context);
1356
1357 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1358 context.limit_position = old_limit_offset;
1359 context.main_slot = old_main;
1360 } else if(is_integer(label.data(), label.data() + label.length())) {
1361 auto value = parse_int(label, 0, err);
1362 if(0 <= value && size_t(value) < context.outer_context.original_id_to_prov_id_map.size()) {
1363
1364 auto old_limit_offset = context.limit_position;
1365 auto old_main = context.main_slot;
1366
1367 context.compiled_effect.push_back(uint16_t(effect::integer_scope | effect::scope_has_limit));
1368
1369 context.compiled_effect.push_back(uint16_t(0));
1370 auto payload_size_offset = context.compiled_effect.size() - 1;
1371
1372 context.limit_position = context.compiled_effect.size();
1373 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1375
1377 parse_effect_body(gen, err, context);
1378
1379 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1380 context.limit_position = old_limit_offset;
1381
1382 context.main_slot = old_main;
1383 } else {
1384 gen.discard_group();
1385 err.accumulated_errors += "Invalid province id used as an effect scope (" + err.file_name + ")\n";
1386 return;
1387 }
1388 } else if(label.length() == 3) {
1389 if(auto itc = context.outer_context.map_of_ident_names.find(nations::tag_to_int(label[0], label[1], label[2]));
1390 itc != context.outer_context.map_of_ident_names.end()) {
1391
1392 auto old_limit_offset = context.limit_position;
1393 auto old_main = context.main_slot;
1394
1395 context.compiled_effect.push_back(uint16_t(effect::tag_scope | effect::scope_has_limit));
1396
1397 context.compiled_effect.push_back(uint16_t(0));
1398 auto payload_size_offset = context.compiled_effect.size() - 1;
1399
1400 context.limit_position = context.compiled_effect.size();
1401 context.compiled_effect.push_back(trigger::payload(dcon::trigger_key()).value);
1402 context.compiled_effect.push_back(trigger::payload(itc->second).value);
1403
1405 parse_effect_body(gen, err, context);
1406
1407 context.compiled_effect[payload_size_offset] = uint16_t(context.compiled_effect.size() - payload_size_offset);
1408 context.limit_position = old_limit_offset;
1409
1410 context.main_slot = old_main;
1411 } else {
1412 gen.discard_group();
1413 err.accumulated_errors += "Invalid tag " + str_label + " used as an effect scope (" + err.file_name + ")\n";
1414 return;
1415 }
1416 } else {
1417 gen.discard_group();
1418 err.accumulated_errors += "unknown effect scope " + str_label + " (" + err.file_name + ")\n";
1419 return;
1420 }
1421}
1422
1423int32_t simplify_effect(uint16_t* source) {
1424 auto mask = effect::code_mask;
1425 auto firstinvalid = effect::first_invalid_code;
1427 if((source[0] & effect::code_mask) >= effect::first_scope_code) {
1428 auto source_size = 1 + effect::get_effect_scope_payload_size(source);
1429
1430 if((source[0] & effect::code_mask) == effect::random_list_scope) {
1431 auto sub_units_start = source + 4; // [code] + [payload size] + [chances total] + [first sub effect chance]
1432 while(sub_units_start < source + source_size) {
1433 auto const old_size = 1 + effect::get_generic_effect_payload_size(sub_units_start);
1434 auto const new_size = simplify_effect(sub_units_start);
1435 if(new_size > 0) {
1436 if(new_size != old_size) { // has been simplified
1437 assert(new_size < old_size);
1438 std::copy(sub_units_start + old_size, source + source_size, sub_units_start + new_size);
1439 source_size -= (old_size - new_size);
1440 }
1441 sub_units_start += new_size + 1;
1442 } else {
1443 std::copy(sub_units_start + old_size, source + source_size, sub_units_start - 1);
1444 source_size -= (1 + old_size);
1445 }
1446 }
1447 } else {
1448 auto sub_units_start = source + 2 + effect::effect_scope_data_payload(source[0]);
1449 while(sub_units_start < source + source_size) {
1450 // [0 0 ] | clr_global_flag [1 2 ] | clr_global_flag
1451 // [0 1 ] | <flag> [1 3 ] | <flag>
1452 // --------------- | n = 1 ...............
1453 // [n 2n ]
1454 // [n 2n + 1]
1455 int32_t old_size = 1 + effect::get_generic_effect_payload_size(sub_units_start);
1456 int32_t new_size = simplify_effect(sub_units_start);
1457 if((sub_units_start[0] & effect::code_mask) == effect::clr_global_flag) {
1458 auto repeats = 0;
1459 while(sub_units_start + old_size < source + source_size
1460 && (sub_units_start[old_size] & effect::code_mask) == effect::clr_global_flag
1461 && repeats < 8) {
1462 old_size += 1 + effect::data_sizes[effect::clr_global_flag];
1463 ++repeats;
1464 }
1465 static const uint16_t fop_table[] = {
1466 effect::clr_global_flag,
1467 effect::fop_clr_global_flag_2,
1468 effect::fop_clr_global_flag_3,
1469 effect::fop_clr_global_flag_4,
1470 effect::fop_clr_global_flag_5,
1471 effect::fop_clr_global_flag_6,
1472 effect::fop_clr_global_flag_7,
1473 effect::fop_clr_global_flag_8,
1474 effect::fop_clr_global_flag_9,
1475 effect::fop_clr_global_flag_10,
1476 effect::fop_clr_global_flag_11,
1477 effect::fop_clr_global_flag_12
1478 };
1479 sub_units_start[0] = fop_table[repeats];
1480 new_size = 1 + effect::data_sizes[fop_table[repeats]];
1481 for(auto i = 1; i <= repeats + 1; i++) {
1482 // todo: copy n size
1483 sub_units_start[effect::data_sizes[effect::clr_global_flag] * i]
1484 = sub_units_start[(1 + effect::data_sizes[effect::clr_global_flag]) * i - 1];
1485 }
1486 }
1487 if(new_size != old_size) { // has been simplified
1488 assert(new_size < old_size);
1489 std::copy(sub_units_start + old_size, source + source_size, sub_units_start + new_size);
1490 source_size -= (old_size - new_size);
1491 }
1492 sub_units_start += new_size;
1493 }
1494 }
1495
1496 source[1] = uint16_t(source_size - 1);
1497
1498 if((source[0] & effect::scope_has_limit) != 0 && !bool(trigger::payload(source[2]).tr_id)) {
1499 std::copy(source + 3, source + source_size, source + 2);
1500 --source_size;
1501 source[0] = uint16_t(source[0] & ~effect::scope_has_limit);
1502 source[1] = uint16_t(source_size - 1);
1503 }
1504
1505 if((source[0] & effect::code_mask) == effect::generic_scope) {
1506 if(source_size == 2) {
1507 return 0; // simplify empty scope to nothing
1508 } else if(((source[0] & effect::scope_has_limit) == 0) && effect::effect_scope_has_single_member(source)) {
1509 std::copy(source + 2, source + source_size, source);
1510 source_size -= 2;
1511 }
1512 } else if((source[0] & effect::code_mask) == effect::owner_scope_province
1513 && (source[0] & effect::scope_has_limit) == 0
1514 && (source[0] & effect::is_random_scope) == 0) {
1515 bool can_elim = true;
1516 auto sub_units_start = source + 2 + effect::effect_scope_data_payload(source[0]);
1517 while(sub_units_start < source + source_size && can_elim) {
1518 switch(sub_units_start[0] & effect::code_mask) {
1519 case effect::clr_global_flag:
1520 case effect::set_global_flag:
1521 case effect::fop_clr_global_flag_2:
1522 case effect::fop_clr_global_flag_3:
1523 case effect::fop_clr_global_flag_4:
1524 case effect::fop_clr_global_flag_5:
1525 case effect::fop_clr_global_flag_6:
1526 case effect::fop_clr_global_flag_7:
1527 case effect::fop_clr_global_flag_8:
1528 case effect::fop_clr_global_flag_9:
1529 case effect::fop_clr_global_flag_10:
1530 case effect::fop_clr_global_flag_11:
1531 case effect::fop_clr_global_flag_12:
1532 case effect::fop_change_province_name:
1534 break;
1535 default:
1536 can_elim = false;
1537 break;
1538 }
1539 sub_units_start += 1 + effect::get_generic_effect_payload_size(sub_units_start);
1540 }
1541 if(can_elim) { //eliminate
1542 std::copy(source + 2, source + source_size, source);
1543 source_size -= 2;
1544 }
1545 } else if((source[0] & effect::code_mask) == effect::integer_scope
1546 && (source[0] & effect::scope_has_limit) == 0
1547 && (source[0] & effect::is_random_scope) == 0
1548 && source[1] == 4
1550 auto sub_units_start = source + 2 + effect::effect_scope_data_payload(source[0]);
1551 auto const old_size = 1 + effect::get_generic_effect_payload_size(source);
1552 if(sub_units_start[0] == effect::change_province_name) {
1553 auto const prov = source[2]; //[code] [size] [province]
1554 auto const name_1 = sub_units_start[1];
1555 auto const name_2 = sub_units_start[2];
1556 source[0] = effect::fop_change_province_name;
1557 source[1] = name_1; //name
1558 source[2] = name_2; //name
1559 source[3] = prov; //province
1560 auto const new_size = 1 + effect::data_sizes[effect::fop_change_province_name];
1561 assert(new_size < old_size);
1562 std::copy(source + old_size, source + source_size, source + new_size);
1563 source_size -= (old_size - new_size);
1564 }
1565 }
1566 return source_size;
1567 } else {
1568 return 1 + effect::get_effect_non_scope_payload_size(source); // non scopes cannot be simplified
1569 }
1570}
1571
1572template<typename T>
1573void recurse_over_effects(uint16_t* source, T const& f) {
1574 f(source);
1575
1576 if((source[0] & effect::code_mask) >= effect::first_scope_code) {
1577 if((source[0] & effect::code_mask) == effect::random_list_scope) {
1578 auto const source_size = 1 + effect::get_generic_effect_payload_size(source);
1579
1580 auto sub_units_start = source + 4; // [code] + [payload size] + [chances total] + [first sub effect chance]
1581 while(sub_units_start < source + source_size) {
1582 recurse_over_effects(sub_units_start, f);
1583 sub_units_start += 2 + effect::get_generic_effect_payload_size(sub_units_start); // each member preceded by uint16_t
1584 }
1585 } else {
1586 auto const source_size = 1 + effect::get_generic_effect_payload_size(source);
1587
1588 auto sub_units_start = source + 2 + effect::effect_scope_data_payload(source[0]);
1589 while(sub_units_start < source + source_size) {
1590 recurse_over_effects(sub_units_start, f);
1591 sub_units_start += 1 + effect::get_generic_effect_payload_size(sub_units_start);
1592 }
1593 }
1594 }
1595}
1596
1598 ef_scope_hidden_tooltip(gen, err, context);
1599
1600 if(context.compiled_effect.size() >= std::numeric_limits<uint16_t>::max()) {
1601 err.accumulated_errors += "effect is " + std::to_string(context.compiled_effect.size()) +
1602 " cells big, which exceeds 64 KB bytecode limit (" + err.file_name + ")\n";
1603 return dcon::effect_key{0};
1604 }
1605
1606 auto const new_size = simplify_effect(context.compiled_effect.data());
1607 context.compiled_effect.resize(static_cast<size_t>(new_size));
1608
1609 return context.outer_context.state.commit_effect_data(context.compiled_effect);
1610}
1611
1612void ef_province_event::id(association_type t, int32_t value, error_handler& err, int32_t line,
1613 effect_building_context& context) {
1614 if(auto it = context.outer_context.map_of_provincial_events.find(value);
1615 it != context.outer_context.map_of_provincial_events.end()) {
1616 if(it->second.id) {
1617 id_ = it->second.id;
1618 } else {
1619 id_ = context.outer_context.state.world.create_provincial_event();
1620 it->second.id = id_;
1621 it->second.main_slot = trigger::slot_contents::province;
1622 it->second.this_slot = trigger::slot_contents::nation;
1623 it->second.from_slot = context.this_slot;
1624 it->second.just_in_case_placeholder = false;
1625 }
1626 } else {
1627 id_ = context.outer_context.state.world.create_provincial_event();
1628 context.outer_context.map_of_provincial_events.insert_or_assign(value,
1630 }
1631}
1632
1633void ef_country_event::id(association_type t, int32_t value, error_handler& err, int32_t line, effect_building_context& context) {
1634 if(auto it = context.outer_context.map_of_national_events.find(value);
1635 it != context.outer_context.map_of_national_events.end()) {
1636 if(it->second.id) {
1637 id_ = it->second.id;
1638 } else {
1639 id_ = context.outer_context.state.world.create_national_event();
1640 it->second.id = id_;
1641 it->second.main_slot = trigger::slot_contents::nation;
1642 it->second.this_slot = trigger::slot_contents::nation;
1643 it->second.from_slot = context.this_slot;
1644 it->second.just_in_case_placeholder = false;
1645 }
1646 } else {
1647 id_ = context.outer_context.state.world.create_national_event();
1648 context.outer_context.map_of_national_events.insert_or_assign(value,
1650 }
1651}
1652
1653void effect_body::country_event(association_type t, int32_t value, error_handler& err, int32_t line,
1654 effect_building_context& context) {
1657 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_this_nation));
1659 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_this_province));
1660 else if(context.this_slot == trigger::slot_contents::state)
1661 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_this_state));
1662 else if(context.this_slot == trigger::slot_contents::pop)
1663 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_this_pop));
1664 else {
1665 err.accumulated_errors +=
1666 "country_event effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1667 return;
1668 }
1669 if(auto it = context.outer_context.map_of_national_events.find(value);
1670 it != context.outer_context.map_of_national_events.end()) {
1671 if(it->second.id) {
1672 context.compiled_effect.push_back(trigger::payload(it->second.id).value);
1673 } else {
1674 auto ev_id = context.outer_context.state.world.create_national_event();
1675 it->second.id = ev_id;
1676 it->second.main_slot = trigger::slot_contents::nation;
1677 it->second.this_slot = trigger::slot_contents::nation;
1678 it->second.from_slot = context.this_slot;
1679 it->second.just_in_case_placeholder = false;
1680 context.compiled_effect.push_back(trigger::payload(ev_id).value);
1681 }
1682 } else {
1683 auto ev_id = context.outer_context.state.world.create_national_event();
1684 context.outer_context.map_of_national_events.insert_or_assign(value,
1686 context.compiled_effect.push_back(trigger::payload(ev_id).value);
1687 }
1688 } else if(context.main_slot == trigger::slot_contents::province) {
1690 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_province_this_nation));
1692 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_province_this_province));
1693 else if(context.this_slot == trigger::slot_contents::state)
1694 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_province_this_state));
1695 else if(context.this_slot == trigger::slot_contents::pop)
1696 context.compiled_effect.push_back(uint16_t(effect::country_event_immediate_province_this_pop));
1697 else {
1698 err.accumulated_errors +=
1699 "country_event effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1700 return;
1701 }
1702 if(auto it = context.outer_context.map_of_national_events.find(value);
1703 it != context.outer_context.map_of_national_events.end()) {
1704 if(it->second.id) {
1705 context.compiled_effect.push_back(trigger::payload(it->second.id).value);
1706 } else {
1707 auto ev_id = context.outer_context.state.world.create_national_event();
1708 it->second.id = ev_id;
1709 it->second.main_slot = trigger::slot_contents::nation;
1710 it->second.this_slot = trigger::slot_contents::nation;
1711 it->second.from_slot = context.this_slot;
1712 it->second.just_in_case_placeholder = false;
1713 context.compiled_effect.push_back(trigger::payload(ev_id).value);
1714 }
1715 } else {
1716 auto ev_id = context.outer_context.state.world.create_national_event();
1717 context.outer_context.map_of_national_events.insert_or_assign(value,
1719 context.compiled_effect.push_back(trigger::payload(ev_id).value);
1720 }
1721 } else {
1722 err.accumulated_errors +=
1723 "country_event effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1724 return;
1725 }
1726}
1727
1728void effect_body::province_event(association_type t, int32_t value, error_handler& err, int32_t line,
1729 effect_building_context& context) {
1732 context.compiled_effect.push_back(uint16_t(effect::province_event_immediate_this_nation));
1734 context.compiled_effect.push_back(uint16_t(effect::province_event_immediate_this_province));
1735 else if(context.this_slot == trigger::slot_contents::state)
1736 context.compiled_effect.push_back(uint16_t(effect::province_event_immediate_this_state));
1737 else if(context.this_slot == trigger::slot_contents::pop)
1738 context.compiled_effect.push_back(uint16_t(effect::province_event_immediate_this_pop));
1739 else {
1740 err.accumulated_errors +=
1741 "province_event effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1742 return;
1743 }
1744 if(auto it = context.outer_context.map_of_provincial_events.find(value);
1745 it != context.outer_context.map_of_provincial_events.end()) {
1746 if(it->second.id) {
1747 context.compiled_effect.push_back(trigger::payload(it->second.id).value);
1748 } else {
1749 auto ev_id = context.outer_context.state.world.create_provincial_event();
1750 it->second.id = ev_id;
1751 it->second.main_slot = trigger::slot_contents::province;
1752 it->second.this_slot = trigger::slot_contents::province;
1753 it->second.from_slot = context.this_slot;
1754 it->second.just_in_case_placeholder = false;
1755 context.compiled_effect.push_back(trigger::payload(ev_id).value);
1756 }
1757 } else {
1758 auto ev_id = context.outer_context.state.world.create_provincial_event();
1759 context.outer_context.map_of_provincial_events.insert_or_assign(value,
1761 context.compiled_effect.push_back(trigger::payload(ev_id).value);
1762 }
1763 } else {
1764 err.accumulated_errors +=
1765 "province_event effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1766 return;
1767 }
1768}
1769
1771 effect_building_context& context) {
1773 err.accumulated_errors +=
1774 "define_general effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1775 return;
1776 }
1777 context.compiled_effect.push_back(effect::define_general);
1778 context.add_int32_t_to_payload(context.outer_context.state.add_unit_name(value.name).index());
1779 context.compiled_effect.push_back(trigger::payload(value.personality_).value);
1780 context.compiled_effect.push_back(trigger::payload(value.background_).value);
1781}
1782void effect_body::kill_leader(association_type t, std::string_view value, error_handler& err, int32_t line, effect_building_context& context) {
1784 context.compiled_effect.push_back(effect::kill_leader);
1785 context.add_int32_t_to_payload(context.outer_context.state.add_unit_name(value).index());
1786 } else {
1787 err.accumulated_errors += "kill_leader effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1788 return;
1789 }
1790}
1792 effect_building_context& context) {
1794 err.accumulated_errors +=
1795 "define_admiral effect used in an incorrect scope type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1796 return;
1797 }
1798 context.compiled_effect.push_back(effect::define_admiral);
1799 context.add_int32_t_to_payload(context.outer_context.state.add_unit_name(value.name).index());
1800 context.compiled_effect.push_back(trigger::payload(value.personality_).value);
1801 context.compiled_effect.push_back(trigger::payload(value.background_).value);
1802}
1803void effect_body::change_province_name(association_type t, std::string_view value, error_handler & err, int32_t line,
1804 effect_building_context& context) {
1806 context.compiled_effect.push_back(uint16_t(effect::change_province_name));
1807 } else {
1808 err.accumulated_errors += "change_province_name effect used in an incorrect scope type " + slot_contents_to_string(context.main_slot) + " (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1809 return;
1810 }
1811
1812 auto name = text::find_or_add_key(context.outer_context.state, value, false);
1813 context.add_int32_t_to_payload(name.index());
1814}
1815void effect_body::change_region_name(association_type t, std::string_view value, error_handler& err, int32_t line, effect_building_context& context) {
1817 context.compiled_effect.push_back(uint16_t(effect::change_region_name_state));
1818 } else if(context.main_slot == trigger::slot_contents::province) {
1819 context.compiled_effect.push_back(uint16_t(effect::change_region_name_province));
1820 } else {
1821 err.accumulated_errors += "change_region_name effect used in an incorrect scope type " + slot_contents_to_string(context.main_slot) + " (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1822 return;
1823 }
1824
1825 auto name = text::find_or_add_key(context.outer_context.state, value, false);
1826 context.add_int32_t_to_payload(name.index());
1827}
1828void effect_body::enable_canal(association_type t, int32_t value, error_handler& err, int32_t line, effect_building_context& context) {
1829 if(1 <= value && value <= int32_t(context.outer_context.state.province_definitions.canals.size())) {
1830 context.compiled_effect.push_back(uint16_t(effect::enable_canal));
1831 context.compiled_effect.push_back(trigger::payload(uint16_t(value)).value);
1832 } else {
1833 err.accumulated_errors +=
1834 "canal index " + std::to_string(value) + " out of range (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1835 }
1836}
1837void effect_body::any_value(std::string_view label, association_type t, std::string_view value, error_handler& err, int32_t line, effect_building_context& context) {
1838 std::string str_label{ label };
1839 if(auto it = context.outer_context.map_of_commodity_names.find(str_label);
1840 it != context.outer_context.map_of_commodity_names.end()) {
1842 context.compiled_effect.push_back(effect::variable_good_name);
1843 context.compiled_effect.push_back(trigger::payload(it->second).value);
1844 context.add_float_to_payload(parse_float(value, line, err));
1845 } else if(context.main_slot == trigger::slot_contents::province) {
1846 context.compiled_effect.push_back(effect::variable_good_name_province);
1847 context.compiled_effect.push_back(trigger::payload(it->second).value);
1848 context.add_float_to_payload(parse_float(value, line, err));
1849 } else {
1850 err.accumulated_errors += "variable commodity name effect used in an incorrect scope type (" + err.file_name + ", line " +
1851 std::to_string(line) + ")\n";
1852 return;
1853 }
1854 } else if(auto itb = context.outer_context.map_of_technologies.find(str_label); itb != context.outer_context.map_of_technologies.end()) {
1856 if(parse_bool(value, line, err))
1857 context.compiled_effect.push_back(effect::variable_tech_name_yes);
1858 else
1859 context.compiled_effect.push_back(effect::variable_tech_name_no);
1860 context.compiled_effect.push_back(trigger::payload(itb->second.id).value);
1861 context.add_float_to_payload(parse_float(value, line, err));
1862 } else {
1863 err.accumulated_errors += "variable technology name effect used in an incorrect scope type (" + err.file_name +
1864 ", line " + std::to_string(line) + ")\n";
1865 return;
1866 }
1867 } else if(auto itc = context.outer_context.map_of_inventions.find(str_label); itc != context.outer_context.map_of_inventions.end()) {
1869 if(parse_bool(value, line, err))
1870 context.compiled_effect.push_back(effect::variable_invention_name_yes);
1871 else
1872 context.compiled_effect.push_back(effect::variable_invention_name_no);
1873 context.compiled_effect.push_back(trigger::payload(itc->second.id).value);
1874 context.add_float_to_payload(parse_float(value, line, err));
1875 } else {
1876 err.accumulated_errors += "variable invention name effect used in an incorrect scope type (" + err.file_name + ", line " +
1877 std::to_string(line) + ")\n";
1878 return;
1879 }
1880 } else if(auto itf = context.outer_context.map_of_iissues.find(str_label); itf != context.outer_context.map_of_iissues.end()) {
1881 if(auto itopt = context.outer_context.map_of_ioptions.find(std::string(value)); itopt != context.outer_context.map_of_ioptions.end()) {
1883 auto cat = context.outer_context.state.world.issue_get_issue_type(itf->second);
1885 context.compiled_effect.push_back(uint16_t(effect::political_reform));
1886 context.compiled_effect.push_back(trigger::payload(itopt->second.id).value);
1887 } else if(cat == uint8_t(::culture::issue_category::social)) {
1888 context.compiled_effect.push_back(uint16_t(effect::social_reform));
1889 context.compiled_effect.push_back(trigger::payload(itopt->second.id).value);
1890 } else {
1891 err.accumulated_errors += "named issue effect used with a party issue (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1892 return;
1893 }
1894 } else {
1895 err.accumulated_errors += "named issue effect used in an invalid context (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1896 return;
1897 }
1898 } else {
1899 err.accumulated_errors += "named issue effect used with an invalid option name (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1900 return;
1901 }
1902 } else if(auto ith = context.outer_context.map_of_reforms.find(str_label); ith != context.outer_context.map_of_reforms.end()) {
1903 if(auto itopt = context.outer_context.map_of_roptions.find(std::string(value));
1904 itopt != context.outer_context.map_of_roptions.end()) {
1906 auto cat = context.outer_context.state.world.reform_get_reform_type(ith->second);
1908 context.compiled_effect.push_back(uint16_t(effect::military_reform));
1909 context.compiled_effect.push_back(trigger::payload(itopt->second.id).value);
1910 } else if(cat == uint8_t(::culture::issue_category::economic)) {
1911 context.compiled_effect.push_back(uint16_t(effect::economic_reform));
1912 context.compiled_effect.push_back(trigger::payload(itopt->second.id).value);
1913 } else {
1914 err.accumulated_errors += "named reform effect used with an invalid issue type (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1915 return;
1916 }
1917 } else {
1918 err.accumulated_errors += "named reform effect used in an invalid context (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1919 return;
1920 }
1921 } else {
1922 err.accumulated_errors += "named reform effect used with an invalid option name (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1923 return;
1924 }
1925 } else {
1926 err.accumulated_errors +=
1927 "unknown effect " + str_label + " encountered (" + err.file_name + ", line " + std::to_string(line) + ")\n";
1928 return;
1929 }
1930}
1931
1932} // namespace parsers
std::string accumulated_errors
Definition: parsers.hpp:62
std::string file_name
Definition: parsers.hpp:61
#define assert(condition)
Definition: debug.h:74
constexpr uint16_t x_state_scope
constexpr uint16_t x_greater_power_scope
constexpr uint16_t rich_strata_scope_nation
constexpr uint16_t pop_type_scope_nation
constexpr uint16_t this_bounce_scope
bool effect_scope_has_single_member(uint16_t const *source)
constexpr uint16_t region_proper_scope
constexpr uint16_t crisis_state_scope
constexpr uint16_t x_neighbor_country_scope
constexpr uint16_t region_scope
constexpr uint16_t x_decision_country_scope_nation
int32_t get_effect_non_scope_payload_size(uint16_t const *data)
constexpr int8_t data_sizes[]
constexpr uint16_t x_pop_scope_province
constexpr uint16_t country_scope_pop
constexpr uint16_t this_scope_province
constexpr uint16_t owner_scope_province
constexpr uint16_t country_scope_state
constexpr uint16_t capital_scope_province
constexpr uint16_t is_random_scope
constexpr uint16_t this_scope_pop
constexpr uint16_t x_country_scope_nation
constexpr uint16_t if_scope
int32_t get_effect_scope_payload_size(uint16_t const *data)
constexpr uint16_t owner_scope_state
constexpr uint16_t state_scope_province
constexpr uint16_t poor_strata_scope_state
constexpr uint16_t state_scope_pop
constexpr uint16_t x_empty_neighbor_province_scope
int32_t effect_scope_data_payload(uint16_t code)
constexpr uint16_t from_scope_nation
constexpr uint16_t code_mask
constexpr uint16_t location_scope
constexpr uint16_t capital_scope
constexpr uint16_t generic_scope
constexpr uint16_t this_scope_nation
constexpr uint16_t tag_scope
EFFECT_BYTECODE_LIST constexpr uint16_t first_scope_code
constexpr uint16_t controller_scope
constexpr uint16_t cultural_union_scope
constexpr uint16_t sea_zone_scope
constexpr uint16_t random_scope
constexpr uint16_t independence_scope
constexpr uint16_t x_core_scope
constexpr uint16_t random_by_modifier_scope
constexpr uint16_t middle_strata_scope_state
constexpr uint16_t this_scope_state
constexpr uint16_t x_core_scope_province
constexpr uint16_t x_neighbor_province_scope
constexpr uint16_t from_scope_state
constexpr uint16_t else_if_scope
constexpr uint16_t x_event_country_scope
constexpr uint16_t rich_strata_scope_state
constexpr uint16_t x_country_scope
constexpr uint16_t from_scope_province
constexpr uint16_t poor_strata_scope_nation
int32_t get_generic_effect_payload_size(uint16_t const *data)
constexpr uint16_t x_substate_scope
constexpr uint16_t rich_strata_scope_province
constexpr uint16_t random_list_scope
constexpr uint16_t x_empty_neighbor_province_scope_nation
constexpr uint16_t pop_type_scope_province
constexpr uint16_t first_invalid_code
constexpr uint16_t poor_strata_scope_province
constexpr uint16_t scope_has_limit
constexpr uint16_t flashpoint_tag_scope
constexpr uint16_t x_owned_scope_nation
constexpr uint16_t x_decision_country_scope
constexpr uint16_t overlord_scope
constexpr uint16_t sphere_owner_scope
constexpr uint16_t x_owned_scope_state
constexpr uint16_t x_event_country_scope_nation
constexpr uint16_t integer_scope
constexpr uint16_t pop_type_scope_state
constexpr uint16_t middle_strata_scope_province
constexpr uint16_t x_pop_scope_state
constexpr uint16_t x_pop_scope_nation
constexpr uint16_t from_scope_pop
constexpr uint16_t from_bounce_scope
constexpr uint16_t middle_strata_scope_nation
constexpr uint16_t x_neighbor_province_scope_nation
uint32_t tag_to_int(char first, char second, char third)
Definition: nations.hpp:7
void ef_scope_random_owned(token_generator &gen, error_handler &err, effect_building_context &context)
bool is_integer(char const *start, char const *end)
Definition: parsers.cpp:46
void ef_scope_any_defined_country(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_location(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_all_core(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_hidden_tooltip(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_sphere_owner(token_generator &gen, error_handler &err, effect_building_context &context)
dcon::trigger_key make_trigger(token_generator &gen, error_handler &err, trigger_building_context &context)
void ef_scope_random_state(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_owner(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_cultural_union(token_generator &gen, error_handler &err, effect_building_context &context)
association_type
Definition: parsers.hpp:28
void ef_scope_any_greater_power(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random_list(token_generator &gen, error_handler &err, effect_building_context &context)
int32_t simplify_effect(uint16_t *source)
void ef_scope_from_bounce(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_else_if(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_this_bounce(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_middle_strata(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_state(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random_empty_neighbor_province(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_crisis_state_scope(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_controller(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random_country(token_generator &gen, error_handler &err, effect_building_context &context)
dcon::value_modifier_key make_value_modifier(token_generator &gen, error_handler &err, trigger_building_context &context)
void ef_scope_overlord(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_neighbor_province(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_capital_scope(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_state_scope(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_rich_strata(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_owned(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_empty_neighbor_province(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_substate(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_random_by_modifier(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_existing_country_except_scoped(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_independence(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_from(token_generator &gen, error_handler &err, effect_building_context &context)
int32_t parse_int(std::string_view content, int32_t line, error_handler &err)
Definition: parsers.cpp:226
dcon::trigger_key ef_limit(token_generator &gen, error_handler &err, effect_building_context &context)
bool parse_bool(std::string_view content, int32_t, error_handler &)
Definition: parsers.cpp:201
dcon::effect_key make_effect(token_generator &gen, error_handler &err, effect_building_context &context)
int32_t add_to_random_list(std::string_view label, token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random_neighbor_province(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_poor_strata(token_generator &gen, error_handler &err, effect_building_context &context)
dcon::value_modifier_key read_chance_modifier(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_country(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_flashpoint_tag_scope(token_generator &gen, error_handler &err, effect_building_context &context)
float parse_float(std::string_view content, int32_t line, error_handler &err)
Definition: parsers.cpp:208
void ef_scope_variable(std::string_view label, token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random(token_generator &gen, error_handler &err, effect_building_context &context)
std::string slot_contents_to_string(trigger::slot_contents v)
void ef_scope_random_greater_power(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random_neighbor_country(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_country(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_sea_zone(token_generator &gen, error_handler &err, effect_building_context &context)
void recurse_over_effects(uint16_t *source, T const &f)
void ef_scope_any_neighbor_country(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_if(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_random_pop(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_this(token_generator &gen, error_handler &err, effect_building_context &context)
void ef_scope_any_pop(token_generator &gen, error_handler &err, effect_building_context &context)
dcon::text_key find_or_add_key(sys::state &state, std::string_view key, bool as_unicode)
Definition: text.cpp:695
uchar uint8_t
dcon::national_event_id id_
void id(association_type t, int32_t value, error_handler &err, int32_t line, effect_building_context &context)
void id(association_type t, int32_t value, error_handler &err, int32_t line, effect_building_context &context)
dcon::provincial_event_id id_
void define_general(ef_define_general const &value, error_handler &err, int32_t line, effect_building_context &context)
void any_value(std::string_view label, association_type t, std::string_view value, error_handler &err, int32_t line, effect_building_context &context)
void change_province_name(association_type t, std::string_view value, error_handler &err, int32_t line, effect_building_context &context)
void country_event(association_type t, int32_t value, error_handler &err, int32_t line, effect_building_context &context)
void define_admiral(ef_define_admiral const &value, error_handler &err, int32_t line, effect_building_context &context)
void enable_canal(association_type t, int32_t value, error_handler &err, int32_t line, effect_building_context &context)
void province_event(association_type t, int32_t value, error_handler &err, int32_t line, effect_building_context &context)
void kill_leader(association_type t, std::string_view value, error_handler &err, int32_t line, effect_building_context &context)
void change_region_name(association_type t, std::string_view value, error_handler &err, int32_t line, effect_building_context &context)
trigger::slot_contents this_slot
scenario_building_context & outer_context
std::vector< uint16_t > compiled_effect
trigger::slot_contents from_slot
trigger::slot_contents main_slot
ankerl::unordered_dense::map< std::string, dcon::state_definition_id > map_of_state_names
ankerl::unordered_dense::map< std::string, pending_invention_content > map_of_inventions
ankerl::unordered_dense::map< std::string, pending_roption_content > map_of_roptions
ankerl::unordered_dense::map< std::string, pending_tech_content > map_of_technologies
ankerl::unordered_dense::map< std::string, dcon::pop_type_id > map_of_poptypes
ankerl::unordered_dense::map< int32_t, pending_nat_event > map_of_national_events
ankerl::unordered_dense::map< std::string, dcon::reform_id > map_of_reforms
std::vector< dcon::province_id > original_id_to_prov_id_map
ankerl::unordered_dense::map< std::string, dcon::issue_id > map_of_iissues
ankerl::unordered_dense::map< std::string, pending_option_content > map_of_ioptions
ankerl::unordered_dense::map< int32_t, pending_prov_event > map_of_provincial_events
ankerl::unordered_dense::map< std::string, dcon::region_id > map_of_region_names
ankerl::unordered_dense::map< uint32_t, dcon::national_identity_id > map_of_ident_names
ankerl::unordered_dense::map< std::string, dcon::commodity_id > map_of_commodity_names
std::vector< dcon::province_adjacency_id > canals
Definition: province.hpp:21
dcon::data_container world
parsing::defines defines
dcon::effect_key commit_effect_data(std::vector< uint16_t > data)
dcon::unit_name_id add_unit_name(std::string_view text)
province::global_provincial_state province_definitions