Project Alice
Loading...
Searching...
No Matches
triggers.cpp
Go to the documentation of this file.
1#include "triggers.hpp"
2#include "system_state.hpp"
3#include "demographics.hpp"
6#include "prng.hpp"
10
11namespace trigger {
12
13#ifdef WIN32
14#define CALLTYPE __vectorcall
15#else
16#define CALLTYPE
17#endif
18
19template<typename A, typename B>
20[[nodiscard]] auto compare_values(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a == value_b) {
21 switch(trigger_code & trigger::association_mask) {
23 return value_a == value_b;
25 return value_a > value_b;
27 return value_a < value_b;
29 return value_a <= value_b;
31 return value_a != value_b;
33 return value_a >= value_b;
34 default:
35 return value_a >= value_b;
36 }
37}
38
39template<typename A, typename B>
40[[nodiscard]] auto compare_values_eq(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a == value_b) {
41 switch(trigger_code & trigger::association_mask) {
43 return value_a == value_b;
45 return value_a != value_b;
47 return value_a != value_b;
49 return value_a == value_b;
51 return value_a != value_b;
53 return value_a == value_b;
54 default:
55 return value_a == value_b;
56 }
57}
58
59template<typename B>
60[[nodiscard]] auto compare_values_eq(uint16_t trigger_code, dcon::nation_fat_id value_a, B value_b)
61 -> decltype(value_a.id == value_b) {
62 switch(trigger_code & trigger::association_mask) {
64 return value_a.id == value_b;
66 return value_a.id != value_b;
68 return value_a.id != value_b;
70 return value_a.id == value_b;
72 return value_a.id != value_b;
74 return value_a.id == value_b;
75 default:
76 return value_a.id == value_b;
77 }
78}
79
80template<typename A>
81[[nodiscard]] auto compare_to_true(uint16_t trigger_code, A value_a) -> decltype(!value_a) {
82 switch(trigger_code & trigger::association_mask) {
84 return value_a;
86 return !value_a;
88 return !value_a;
90 return value_a;
92 return !value_a;
94 return value_a;
95 default:
96 return value_a;
97 }
98}
99template<typename A>
100[[nodiscard]] auto compare_to_false(uint16_t trigger_code, A value_a) -> decltype(!value_a) {
101 switch(trigger_code & trigger::association_mask) {
103 return !value_a;
105 return value_a;
107 return value_a;
109 return !value_a;
111 return value_a;
113 return !value_a;
114 default:
115 return !value_a;
116 }
117}
118float read_float_from_payload(uint16_t const* data) {
119 union {
120 struct {
121 uint16_t low;
122 uint16_t high;
123 } v;
124 float f;
125 } pack_float;
126
127 pack_float.v.low = data[0];
128 pack_float.v.high = data[1];
129
130 return pack_float.f;
131}
132int32_t read_int32_t_from_payload(uint16_t const* data) {
133 union {
134 struct {
135 uint16_t low;
136 uint16_t high;
137 } v;
138 int32_t f;
139 } pack_float;
140
141 pack_float.v.low = data[0];
142 pack_float.v.high = data[1];
143
144 return pack_float.f;
145}
146
147template<typename T>
149 using type = T;
150};
151
152template<>
153struct gathered_s<ve::contiguous_tags<int32_t>> {
154 using type = ve::tagged_vector<int32_t>;
155};
156
157template<>
158struct gathered_s<ve::unaligned_contiguous_tags<int32_t>> {
159 using type = ve::tagged_vector<int32_t>;
160};
161
162template<>
163struct gathered_s<ve::partial_contiguous_tags<int32_t>> {
164 using type = ve::tagged_vector<int32_t>;
165};
166
167template<typename T>
169
170template<typename return_type, typename primary_type, typename this_type, typename from_type>
171return_type CALLTYPE test_trigger_generic(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot,
172 from_type from_slot);
173
174#define TRIGGER_FUNCTION(function_name) \
175 template<typename return_type, typename primary_type, typename this_type, typename from_type> \
176 return_type CALLTYPE function_name(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot, \
177 from_type from_slot)
178
179template<typename T>
180struct full_mask { };
181
182template<>
183struct full_mask<bool> {
184 static constexpr bool value = true;
185};
186template<>
187struct full_mask<ve::vbitfield_type> {
188 static constexpr ve::vbitfield_type value = ve::vbitfield_type{ve::vbitfield_type::storage(-1)};
189};
190
191template<typename T>
192struct empty_mask { };
193
194template<>
195struct empty_mask<bool> {
196 static constexpr bool value = false;
197};
198template<>
199struct empty_mask<ve::vbitfield_type> {
200 static constexpr ve::vbitfield_type value = ve::vbitfield_type{ve::vbitfield_type::storage(0)};
201};
202
203bool compare(bool a, bool b) {
204 return a == b;
205}
206bool compare(ve::vbitfield_type a, ve::vbitfield_type b) {
207 return a.v == b.v;
208}
209
210TRIGGER_FUNCTION(apply_disjuctively) {
211 auto const source_size = 1 + get_trigger_scope_payload_size(tval);
212 auto sub_units_start = tval + 2 + trigger_scope_data_payload(tval[0]);
213
214 return_type result = return_type(false);
215 while(sub_units_start < tval + source_size) {
216 result = result | test_trigger_generic<return_type, primary_type, this_type, from_type>(sub_units_start, ws, primary_slot, this_slot, from_slot);
217 auto compressed_res = ve::compress_mask(result);
218 if(compare(compressed_res, full_mask<decltype(compressed_res)>::value))
219 return result;
220 sub_units_start += 1 + get_trigger_payload_size(sub_units_start);
221 }
222 return result;
223}
224
225TRIGGER_FUNCTION(apply_conjuctively) {
226 auto const source_size = 1 + get_trigger_scope_payload_size(tval);
227 auto sub_units_start = tval + 2 + trigger_scope_data_payload(tval[0]);
228
229 return_type result = return_type(true);
230 while(sub_units_start < tval + source_size) {
231 result = result & test_trigger_generic<return_type, primary_type, this_type, from_type>(sub_units_start, ws, primary_slot, this_slot, from_slot);
232 auto compressed_res = ve::compress_mask(result);
233 if(compare(compressed_res, empty_mask<decltype(compressed_res)>::value))
234 return result;
235 sub_units_start += 1 + get_trigger_payload_size(sub_units_start);
236 }
237 return result;
238}
239
240TRIGGER_FUNCTION(apply_subtriggers) {
241 if((*tval & trigger::is_disjunctive_scope) != 0)
242 return apply_disjuctively<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
243 else
244 return apply_conjuctively<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
245}
246
248 return return_type(true);
249}
250TRIGGER_FUNCTION(tf_unused_1) {
251 return return_type(true);
252}
253
254TRIGGER_FUNCTION(tf_generic_scope) {
255 return apply_subtriggers<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
256}
257
258template<typename F>
259class true_accumulator : public F {
260private:
261 ve::tagged_vector<int32_t> value;
262 uint32_t index = 0;
263 int32_t accumulated_mask = 0;
264
265public:
266 bool result = false;
267
268 true_accumulator(F&& f) : F(std::move(f)) { }
269
270 void add_value(int32_t v) {
271 if(!result) {
272 accumulated_mask |= (int32_t(v != -1) << index);
273 value.set(index++, v);
274
275 if(index == ve::vector_size) {
276 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) != 0;
277 value = ve::tagged_vector<int32_t>();
278 index = 0;
279 accumulated_mask = 0;
280 }
281 }
282 }
283 void flush() {
284 if(index != 0 && !result) {
285 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) != 0;
286 index = 0;
287 }
288 }
289};
290
291template<typename F>
292class false_accumulator : public F {
293private:
294 ve::tagged_vector<int32_t> value;
295 uint32_t index = 0;
296 int32_t accumulated_mask = 0;
297
298public:
299 bool result = true;
300
301 false_accumulator(F&& f) : F(std::move(f)) { }
302
303 void add_value(int32_t v) {
304 if(result) {
305 accumulated_mask |= (int32_t(v != -1) << index);
306 value.set(index++, v);
307
308 if(index == ve::vector_size) {
309 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) == accumulated_mask;
310 value = ve::tagged_vector<int32_t>();
311 index = 0;
312 accumulated_mask = 0;
313 }
314 }
315 }
316 void flush() {
317 if(index != 0 && result) {
318 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) == accumulated_mask;
319 index = 0;
320 }
321 }
322};
323
324template<typename TAG, typename F>
325class value_accumulator : public F {
326private:
327 ve::fp_vector value;
328 ve::tagged_vector<TAG> store;
329
330 uint32_t index = 0;
331 int32_t accumulated_mask = 0;
332
333public:
334 value_accumulator(F&& f) : F(std::move(f)) { }
335
336 void add_value(TAG v) {
337 accumulated_mask |= (int32_t(is_valid_index(v)) << index);
338 store.set(index++, v);
339
340 if(index == ve::vector_size) {
341 value = value + ve::select(accumulated_mask, F::operator()(store), 0.0f);
342 index = 0;
343 accumulated_mask = 0;
344 }
345 }
346 float flush() {
347 if(index != 0) {
348 value = value + ve::select(accumulated_mask, F::operator()(store), 0.0f);
349 index = 0;
350 }
351
352 return value.reduce();
353 }
354};
355
356template<typename F>
358 return true_accumulator<F>(std::forward<F>(f));
359}
360
361template<typename F>
363 return false_accumulator<F>(std::forward<F>(f));
364}
365
366template<typename TAG, typename F>
368 return value_accumulator<TAG, F>(std::forward<F>(f));
369}
370
371auto existence_accumulator(sys::state& ws, uint16_t const* tval, int32_t this_slot, int32_t from_slot) {
372 return make_true_accumulator([&ws, tval, this_slot, from_slot](ve::tagged_vector<int32_t> v) {
373 return apply_subtriggers<ve::mask_vector, ve::tagged_vector<int32_t>, int32_t, int32_t>(tval, ws, v, this_slot, from_slot);
374 });
375}
376
377auto universal_accumulator(sys::state& ws, uint16_t const* tval, int32_t this_slot, int32_t from_slot) {
378 return make_false_accumulator([&ws, tval, this_slot, from_slot](ve::tagged_vector<int32_t> v) {
379 return apply_subtriggers<ve::mask_vector, ve::tagged_vector<int32_t>, int32_t, int32_t>(tval, ws, v, this_slot, from_slot);
380 });
381}
382
383TRIGGER_FUNCTION(tf_x_neighbor_province_scope) {
384 return ve::apply(
385 [&ws, tval](int32_t prov_id, int32_t t_slot, int32_t f_slot) {
386 auto prov_tag = to_prov(prov_id);
387
388 if(*tval & trigger::is_existence_scope) {
389 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
390
391 for(auto adj : ws.world.province_get_province_adjacency(prov_tag)) {
392 if((adj.get_type() & province::border::impassible_bit) == 0) {
393 auto other = adj.get_connected_provinces(prov_tag == adj.get_connected_provinces(0) ? 1 : 0).id;
394 accumulator.add_value(to_generic(other));
395 }
396 }
397 accumulator.flush();
398
399 return accumulator.result;
400 } else {
401 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
402
403 for(auto adj : ws.world.province_get_province_adjacency(prov_tag)) {
404 if((adj.get_type() & province::border::impassible_bit) == 0) {
405 auto other = adj.get_connected_provinces(prov_tag == adj.get_connected_provinces(0) ? 1 : 0).id;
406 accumulator.add_value(to_generic(other));
407 }
408 }
409 accumulator.flush();
410
411 return accumulator.result;
412 }
413 },
414 primary_slot, this_slot, from_slot);
415}
416TRIGGER_FUNCTION(tf_x_neighbor_province_scope_state) {
417 return ve::apply(
418 [&ws, tval](int32_t s_id, int32_t t_slot, int32_t f_slot) {
419 auto state_tag = to_state(s_id);
420
421 std::vector<dcon::province_id> vadj;
422 vadj.reserve(32);
423
424 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(state_tag))) {
425 if(p.get_province().get_state_membership() == state_tag) {
426 for(auto adj : p.get_province().get_province_adjacency()) {
427 if((adj.get_type() & province::border::impassible_bit) == 0) {
428 auto other = (p.get_province() == adj.get_connected_provinces(0)) ? adj.get_connected_provinces(1).id : adj.get_connected_provinces(0).id;
429 if(std::find(vadj.begin(), vadj.end(), other) == vadj.end())
430 vadj.push_back(other);
431 }
432 }
433 }
434 }
435
436 if(*tval & trigger::is_existence_scope) {
437 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
438
439 for(auto p : vadj)
440 accumulator.add_value(to_generic(p));
441
442 accumulator.flush();
443 return accumulator.result;
444 } else {
445 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
446
447 for(auto p : vadj)
448 accumulator.add_value(to_generic(p));
449
450 accumulator.flush();
451 return accumulator.result;
452 }
453 },
454 primary_slot, this_slot, from_slot);
455}
456TRIGGER_FUNCTION(tf_x_neighbor_country_scope_nation) {
457 return ve::apply(
458 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
459 auto nid = to_nation(p_slot);
460
461 if(*tval & trigger::is_existence_scope) {
462 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
463
464 for(auto adj : ws.world.nation_get_nation_adjacency(nid)) {
465 auto iid = (nid == adj.get_connected_nations(0)) ? adj.get_connected_nations(1).id : adj.get_connected_nations(0).id;
466
467 accumulator.add_value(to_generic(iid));
468 if(accumulator.result)
469 return true;
470 }
471 accumulator.flush();
472
473 return accumulator.result;
474 } else {
475 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
476 for(auto adj : ws.world.nation_get_nation_adjacency(nid)) {
477 auto iid = (nid == adj.get_connected_nations(0)) ? adj.get_connected_nations(1).id : adj.get_connected_nations(0).id;
478
479 accumulator.add_value(to_generic(iid));
480 if(!accumulator.result)
481 return false;
482 }
483 accumulator.flush();
484
485 return accumulator.result;
486 }
487 },
488 primary_slot, this_slot, from_slot);
489}
490TRIGGER_FUNCTION(tf_x_neighbor_country_scope_pop) {
491 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
492 auto province_owner = ws.world.province_get_nation_from_province_ownership(location);
493
494 return tf_x_neighbor_country_scope_nation<return_type>(tval, ws, to_generic(province_owner), this_slot, from_slot);
495}
496TRIGGER_FUNCTION(tf_x_war_countries_scope_nation) {
497 return ve::apply(
498 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
499 auto nid = to_nation(p_slot);
500
501 if(*tval & trigger::is_existence_scope) {
502 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
503
504 for(auto wars_in : ws.world.nation_get_war_participant(nid)) {
505 auto is_attacker = wars_in.get_is_attacker();
506 for(auto o : wars_in.get_war().get_war_participant()) {
507 if(o.get_is_attacker() != is_attacker && o.get_nation() != nid) {
508 accumulator.add_value(to_generic(o.get_nation().id));
509 if(accumulator.result)
510 return true;
511 }
512 }
513 }
514
515 accumulator.flush();
516 return accumulator.result;
517 } else {
518 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
519
520 for(auto wars_in : ws.world.nation_get_war_participant(nid)) {
521 auto is_attacker = wars_in.get_is_attacker();
522 for(auto o : wars_in.get_war().get_war_participant()) {
523 if(o.get_is_attacker() != is_attacker && o.get_nation() != nid) {
524 accumulator.add_value(to_generic(o.get_nation().id));
525 if(!accumulator.result)
526 return false;
527 }
528 }
529 }
530
531 accumulator.flush();
532 return accumulator.result;
533 }
534 },
535 primary_slot, this_slot, from_slot);
536}
537TRIGGER_FUNCTION(tf_x_war_countries_scope_pop) {
538 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
539 auto province_owner = ws.world.province_get_nation_from_province_ownership(location);
540
541 return tf_x_war_countries_scope_nation<return_type>(tval, ws, to_generic(province_owner), this_slot, from_slot);
542}
543TRIGGER_FUNCTION(tf_x_country_scope) {
544 return ve::apply(
545 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
546 if(*tval & trigger::is_existence_scope) {
547 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
548
549 uint32_t added = 0;
550 for(auto n : ws.world.in_nation) {
551 if(n.get_owned_province_count() != 0) {
552 accumulator.add_value(to_generic(n.id));
553 if(accumulator.result)
554 return true;
555 }
556 }
557
558 accumulator.flush();
559 return accumulator.result;
560 } else {
561 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
562
563 for(auto n : ws.world.in_nation) {
564 if(n.get_owned_province_count() != 0) {
565 accumulator.add_value(to_generic(n.id));
566 if(!accumulator.result)
567 return false;
568 }
569 }
570
571 accumulator.flush();
572 return accumulator.result;
573 }
574 },
575 primary_slot, this_slot, from_slot);
576}
577TRIGGER_FUNCTION(tf_x_greater_power_scope) {
578 return ve::apply(
579 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
580 uint32_t great_nations_count = uint32_t(ws.defines.great_nations_count);
581
582 if(*tval & trigger::is_existence_scope) {
583 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
584
585 uint32_t added = 0;
586 for(uint32_t i = 0; i < ws.nations_by_rank.size() && added < great_nations_count; ++i) {
587 if(nations::is_great_power(ws, ws.nations_by_rank[i])) {
588 ++added;
589 accumulator.add_value(to_generic(ws.nations_by_rank[i]));
590 if(accumulator.result)
591 return true;
592 }
593 }
594
595 accumulator.flush();
596 return accumulator.result;
597 } else {
598 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
599
600 uint32_t added = 0;
601 for(uint32_t i = 0; i < ws.nations_by_rank.size() && added < great_nations_count; ++i) {
602 if(nations::is_great_power(ws, ws.nations_by_rank[i])) {
603 ++added;
604 accumulator.add_value(to_generic(ws.nations_by_rank[i]));
605 if(!accumulator.result)
606 return false;
607 }
608 }
609
610 accumulator.flush();
611 return accumulator.result;
612 }
613 },
614 primary_slot, this_slot, from_slot);
615}
616TRIGGER_FUNCTION(tf_x_owned_province_scope_state) {
617 return ve::apply(
618 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
619 auto sid = to_state(p_slot);
620 dcon::state_definition_fat_id state_def = fatten(ws.world, ws.world.state_instance_get_definition(sid));
621 auto owner = ws.world.state_instance_get_nation_from_state_ownership(sid);
622
623 if(*tval & trigger::is_existence_scope) {
624 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
625
626 for(auto p : state_def.get_abstract_state_membership()) {
627 if(p.get_province().get_nation_from_province_ownership() == owner) {
628 accumulator.add_value(to_generic(p.get_province().id));
629 if(accumulator.result)
630 return true;
631 }
632 }
633
634 accumulator.flush();
635 return accumulator.result;
636 } else {
637 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
638
639 for(auto p : state_def.get_abstract_state_membership()) {
640 if(p.get_province().get_nation_from_province_ownership() == owner) {
641 accumulator.add_value(to_generic(p.get_province().id));
642 if(!accumulator.result)
643 return false;
644 }
645 }
646
647 accumulator.flush();
648 return accumulator.result;
649 }
650 },
651 primary_slot, this_slot, from_slot);
652}
653TRIGGER_FUNCTION(tf_x_owned_province_scope_nation) {
654 return ve::apply(
655 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
656 auto nid = fatten(ws.world, to_nation(p_slot));
657
658 if(*tval & trigger::is_existence_scope) {
659 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
660
661 for(auto p : nid.get_province_ownership()) {
662 accumulator.add_value(to_generic(p.get_province().id));
663 if(accumulator.result)
664 return true;
665 }
666
667 accumulator.flush();
668 return accumulator.result;
669 } else {
670 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
671
672 for(auto p : nid.get_province_ownership()) {
673 accumulator.add_value(to_generic(p.get_province().id));
674 if(!accumulator.result)
675 return false;
676 }
677
678 accumulator.flush();
679 return accumulator.result;
680 }
681 },
682 primary_slot, this_slot, from_slot);
683}
684TRIGGER_FUNCTION(tf_x_core_scope_province) {
685 return ve::apply(
686 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
687 dcon::province_fat_id pid = fatten(ws.world, to_prov(p_slot));
688
689 if(*tval & trigger::is_existence_scope) {
690 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
691
692 for(auto p : pid.get_core()) {
693 auto holder = p.get_identity().get_nation_from_identity_holder();
694 if(holder) {
695 accumulator.add_value(to_generic(holder.id));
696 if(accumulator.result)
697 return true;
698 }
699 }
700
701 accumulator.flush();
702 return accumulator.result;
703 } else {
704 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
705
706 for(auto p : pid.get_core()) {
707 auto holder = p.get_identity().get_nation_from_identity_holder();
708 if(holder) {
709 accumulator.add_value(to_generic(holder.id));
710 if(!accumulator.result)
711 return false;
712 }
713 }
714
715 accumulator.flush();
716 return accumulator.result;
717 }
718 },
719 primary_slot, this_slot, from_slot);
720}
721TRIGGER_FUNCTION(tf_x_core_scope_nation) {
722 return ve::apply(
723 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
724 auto nid = fatten(ws.world, to_nation(p_slot));
725 auto ident = nid.get_identity_holder_as_nation().get_identity();
726
727 if(*tval & trigger::is_existence_scope) {
728 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
729
730 for(auto p : ident.get_core()) {
731 accumulator.add_value(to_generic(p.get_province().id));
732 if(accumulator.result)
733 return true;
734 }
735
736 accumulator.flush();
737 return accumulator.result;
738 } else {
739 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
740
741 for(auto p : ident.get_core()) {
742 accumulator.add_value(to_generic(p.get_province().id));
743 if(!accumulator.result)
744 return false;
745 }
746
747 accumulator.flush();
748 return accumulator.result;
749 }
750 },
751 primary_slot, this_slot, from_slot);
752}
753
754TRIGGER_FUNCTION(tf_x_state_scope) {
755 return ve::apply(
756 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
757 auto nid = fatten(ws.world, to_nation(p_slot));
758
759 if(*tval & trigger::is_existence_scope) {
760 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
761
762 for(auto s : nid.get_state_ownership()) {
763 accumulator.add_value(to_generic(s.get_state().id));
764 if(accumulator.result)
765 return true;
766 }
767
768 accumulator.flush();
769 return accumulator.result;
770 } else {
771 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
772
773 for(auto s : nid.get_state_ownership()) {
774 accumulator.add_value(to_generic(s.get_state().id));
775 if(!accumulator.result)
776 return false;
777 }
778
779 accumulator.flush();
780 return accumulator.result;
781 }
782 },
783 primary_slot, this_slot, from_slot);
784}
785TRIGGER_FUNCTION(tf_x_substate_scope) {
786 return ve::apply(
787 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
788 auto nid = fatten(ws.world, to_nation(p_slot));
789
790 if(*tval & trigger::is_existence_scope) {
791 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
792
793 for(auto v : nid.get_overlord_as_ruler()) {
794 if(v.get_subject().get_is_substate()) {
795 accumulator.add_value(to_generic(v.get_subject().id));
796 if(accumulator.result)
797 return true;
798 }
799 }
800
801 accumulator.flush();
802 return accumulator.result;
803 } else {
804 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
805
806 for(auto v : nid.get_overlord_as_ruler()) {
807 if(v.get_subject().get_is_substate()) {
808 accumulator.add_value(to_generic(v.get_subject().id));
809 if(!accumulator.result)
810 return false;
811 }
812 }
813
814 accumulator.flush();
815 return accumulator.result;
816 }
817 },
818 primary_slot, this_slot, from_slot);
819}
820TRIGGER_FUNCTION(tf_x_sphere_member_scope) {
821 return ve::apply(
822 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
823 auto nid = fatten(ws.world, to_nation(p_slot));
824
825 if(*tval & trigger::is_existence_scope) {
826 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
827
828 for(auto gpr : nid.get_gp_relationship_as_great_power()) {
830 accumulator.add_value(to_generic(gpr.get_influence_target().id));
831 if(accumulator.result)
832 return true;
833 }
834 }
835
836 accumulator.flush();
837 return accumulator.result;
838 } else {
839 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
840
841 for(auto gpr : nid.get_gp_relationship_as_great_power()) {
843 accumulator.add_value(to_generic(gpr.get_influence_target().id));
844 if(!accumulator.result)
845 return false;
846 }
847 }
848
849 accumulator.flush();
850 return accumulator.result;
851 }
852 },
853 primary_slot, this_slot, from_slot);
854}
855TRIGGER_FUNCTION(tf_x_pop_scope_province) {
856 return ve::apply(
857 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
858 dcon::province_fat_id pid = fatten(ws.world, to_prov(p_slot));
859
860 if(*tval & trigger::is_existence_scope) {
861 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
862
863 for(auto i : pid.get_pop_location()) {
864 accumulator.add_value(to_generic(i.get_pop().id));
865 if(accumulator.result)
866 return true;
867 }
868
869 accumulator.flush();
870 return accumulator.result;
871 } else {
872 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
873
874 for(auto i : pid.get_pop_location()) {
875 accumulator.add_value(to_generic(i.get_pop().id));
876 if(!accumulator.result)
877 return false;
878 }
879
880 accumulator.flush();
881 return accumulator.result;
882 }
883 },
884 primary_slot, this_slot, from_slot);
885}
886TRIGGER_FUNCTION(tf_x_pop_scope_state) {
887 return ve::apply(
888 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
889 auto sid = to_state(p_slot);
890 dcon::state_definition_fat_id state_def = fatten(ws.world, ws.world.state_instance_get_definition(sid));
891 auto owner = ws.world.state_instance_get_nation_from_state_ownership(sid);
892
893 if(*tval & trigger::is_existence_scope) {
894 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
895
896 for(auto p : state_def.get_abstract_state_membership()) {
897 if(p.get_province().get_nation_from_province_ownership() == owner) {
898 for(auto i : p.get_province().get_pop_location()) {
899 accumulator.add_value(to_generic(i.get_pop().id));
900 if(accumulator.result)
901 return true;
902 }
903 }
904 }
905
906 accumulator.flush();
907 return accumulator.result;
908 } else {
909 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
910
911 for(auto p : state_def.get_abstract_state_membership()) {
912 if(p.get_province().get_nation_from_province_ownership() == owner) {
913 for(auto i : p.get_province().get_pop_location()) {
914 accumulator.add_value(to_generic(i.get_pop().id));
915 if(!accumulator.result)
916 return false;
917 }
918 }
919 }
920
921 accumulator.flush();
922 return accumulator.result;
923 }
924 },
925 primary_slot, this_slot, from_slot);
926}
927TRIGGER_FUNCTION(tf_x_pop_scope_nation) {
928 return ve::apply(
929 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
930 auto nid = fatten(ws.world, to_nation(p_slot));
931
932 if(*tval & trigger::is_existence_scope) {
933 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
934
935 for(auto p : nid.get_province_ownership()) {
936 for(auto i : p.get_province().get_pop_location()) {
937 accumulator.add_value(to_generic(i.get_pop().id));
938 if(accumulator.result)
939 return true;
940 }
941 }
942
943 accumulator.flush();
944 return accumulator.result;
945 } else {
946 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
947
948 for(auto p : nid.get_province_ownership()) {
949 for(auto i : p.get_province().get_pop_location()) {
950 accumulator.add_value(to_generic(i.get_pop().id));
951 if(!accumulator.result)
952 return false;
953 }
954 }
955
956 accumulator.flush();
957 return accumulator.result;
958 }
959 },
960 primary_slot, this_slot, from_slot);
961}
962TRIGGER_FUNCTION(tf_x_provinces_in_variable_region) {
963 auto state_def = trigger::payload(*(tval + 2)).state_id;
964
965 return ve::apply(
966 [&ws, tval, state_def](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
967 if(*tval & trigger::is_existence_scope) {
968 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
969
970 for(auto i : ws.world.state_definition_get_abstract_state_membership(state_def)) {
971 accumulator.add_value(to_generic(i.get_province().id));
972 if(accumulator.result)
973 return true;
974 }
975
976 accumulator.flush();
977 return accumulator.result;
978 } else {
979 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
980
981 for(auto i : ws.world.state_definition_get_abstract_state_membership(state_def)) {
982 accumulator.add_value(to_generic(i.get_province().id));
983 if(!accumulator.result)
984 return false;
985 }
986
987 accumulator.flush();
988 return accumulator.result;
989 }
990 },
991 primary_slot, this_slot, from_slot);
992}
993TRIGGER_FUNCTION(tf_x_provinces_in_variable_region_proper) {
994 auto state_def = trigger::payload(*(tval + 2)).reg_id;
995
996 return ve::apply(
997 [&ws, tval, state_def](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
998 if(*tval & trigger::is_existence_scope) {
999 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
1000
1001 for(auto i : ws.world.region_get_region_membership(state_def)) {
1002 accumulator.add_value(to_generic(i.get_province().id));
1003 if(accumulator.result)
1004 return true;
1005 }
1006
1007 accumulator.flush();
1008 return accumulator.result;
1009 } else {
1010 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
1011
1012 for(auto i : ws.world.region_get_region_membership(state_def)) {
1013 accumulator.add_value(to_generic(i.get_province().id));
1014 if(!accumulator.result)
1015 return false;
1016 }
1017
1018 accumulator.flush();
1019 return accumulator.result;
1020 }
1021 },
1022 primary_slot, this_slot, from_slot);
1023}
1024TRIGGER_FUNCTION(tf_owner_scope_state) {
1025 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
1026 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1027 from_slot);
1028}
1029TRIGGER_FUNCTION(tf_owner_scope_province) {
1030 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1031 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1032 from_slot);
1033}
1034TRIGGER_FUNCTION(tf_controller_scope) {
1035 auto controller = ws.world.province_get_nation_from_province_control(to_prov(primary_slot));
1036 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(controller),
1037 this_slot, from_slot);
1038}
1039TRIGGER_FUNCTION(tf_location_scope) {
1040 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1041 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(location), this_slot,
1042 from_slot);
1043}
1044TRIGGER_FUNCTION(tf_country_scope_state) {
1045 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
1046 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1047 from_slot);
1048}
1049TRIGGER_FUNCTION(tf_country_scope_pop) {
1050 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1051 auto owner = ws.world.province_get_nation_from_province_ownership(location);
1052 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1053 from_slot);
1054}
1055TRIGGER_FUNCTION(tf_capital_scope) {
1056 auto cap = ws.world.nation_get_capital(to_nation(primary_slot));
1057 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(cap), this_slot, from_slot);
1058}
1059TRIGGER_FUNCTION(tf_capital_scope_province) {
1060 auto cap = ws.world.nation_get_capital(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
1061 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(cap), this_slot, from_slot);
1062}
1063TRIGGER_FUNCTION(tf_capital_scope_pop) {
1064 auto cap = ws.world.nation_get_capital(nations::owner_of_pop(ws, to_pop(primary_slot)));
1065 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(cap), this_slot, from_slot);
1066}
1067TRIGGER_FUNCTION(tf_this_scope) {
1068 return apply_subtriggers<return_type, this_type, this_type, from_type>(tval, ws, this_slot, this_slot, from_slot);
1069}
1070TRIGGER_FUNCTION(tf_from_scope) {
1071 return apply_subtriggers<return_type, from_type, this_type, from_type>(tval, ws, from_slot, this_slot, from_slot);
1072}
1073TRIGGER_FUNCTION(tf_sea_zone_scope) {
1074 /*
1075 auto sea_zones = ve::apply(
1076 [&ws](int32_t p_slot) {
1077 auto pid = fatten(ws.world, to_prov(p_slot));
1078 for(auto adj : pid.get_province_adjacency()) {
1079 if(adj.get_connected_provinces(0).id.index() >= ws.province_definitions.first_sea_province.index()) {
1080 return adj.get_connected_provinces(0).id;
1081 } else if(adj.get_connected_provinces(1).id.index() >= ws.province_definitions.first_sea_province.index()) {
1082 return adj.get_connected_provinces(1).id;
1083 }
1084 }
1085 return dcon::province_id();
1086 },
1087 primary_slot);
1088 */
1089 auto ports = ws.world.province_get_port_to(to_prov(primary_slot));
1090 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(ports),
1091 this_slot, from_slot);
1092}
1093TRIGGER_FUNCTION(tf_cultural_union_scope) {
1094 auto cultures = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1095 auto cg = ws.world.culture_get_group_from_culture_group_membership(cultures);
1096 auto union_tags = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1097 auto group_holders = ws.world.national_identity_get_nation_from_identity_holder(union_tags);
1098 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(group_holders),
1099 this_slot, from_slot);
1100}
1101TRIGGER_FUNCTION(tf_overlord_scope) {
1102 auto so = ws.world.nation_get_overlord_as_subject(to_nation(primary_slot));
1103 auto nso = ws.world.overlord_get_ruler(so);
1104 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(nso), this_slot,
1105 from_slot);
1106}
1107TRIGGER_FUNCTION(tf_sphere_owner_scope) {
1108 auto nso = ws.world.nation_get_in_sphere_of(to_nation(primary_slot));
1109 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(nso), this_slot,
1110 from_slot);
1111}
1112TRIGGER_FUNCTION(tf_independence_scope) {
1113 auto rtags = ws.world.rebel_faction_get_defection_target(to_rebel(from_slot));
1114 auto r_holders = ws.world.national_identity_get_nation_from_identity_holder(rtags);
1115
1116 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(r_holders),
1117 this_slot, from_slot);
1118}
1119TRIGGER_FUNCTION(tf_flashpoint_tag_scope) {
1120 auto ctags = ws.world.state_instance_get_flashpoint_tag(to_state(primary_slot));
1121 auto fp_nations = ws.world.national_identity_get_nation_from_identity_holder(ctags);
1122 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(fp_nations),
1123 this_slot, from_slot);
1124}
1125TRIGGER_FUNCTION(tf_crisis_state_scope) {
1126 return apply_subtriggers<return_type, int32_t, this_type, from_type>(tval, ws, to_generic(ws.crisis_state), this_slot,
1127 from_slot);
1128}
1129TRIGGER_FUNCTION(tf_state_scope_province) {
1130 auto state_instance = ws.world.province_get_state_membership(to_prov(primary_slot));
1131 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(state_instance),
1132 this_slot, from_slot);
1133}
1134TRIGGER_FUNCTION(tf_state_scope_pop) {
1135 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1136 auto state_instance = ws.world.province_get_state_membership(location);
1137 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(state_instance),
1138 this_slot, from_slot);
1139}
1140TRIGGER_FUNCTION(tf_tag_scope) {
1141 auto tag = trigger::payload(tval[2]).tag_id;
1142 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(tag);
1143 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(tag_holder),
1144 this_slot, from_slot);
1145}
1146TRIGGER_FUNCTION(tf_integer_scope) {
1147 auto wprov = trigger::payload(tval[2]).prov_id;
1148 return apply_subtriggers<return_type, int32_t, this_type, from_type>(tval, ws, to_generic(wprov), this_slot, from_slot);
1149}
1150TRIGGER_FUNCTION(tf_country_scope_nation) {
1151 return apply_subtriggers<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
1152}
1153TRIGGER_FUNCTION(tf_country_scope_province) {
1154 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1155 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1156 from_slot);
1157}
1158TRIGGER_FUNCTION(tf_cultural_union_scope_pop) {
1159 auto cultures = ws.world.pop_get_culture(to_pop(primary_slot));
1160 auto cg = ws.world.culture_get_group_from_culture_group_membership(cultures);
1161 auto union_tags = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1162 auto group_holders = ws.world.national_identity_get_nation_from_identity_holder(union_tags);
1163
1164 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(group_holders),
1165 this_slot, from_slot);
1166}
1167
1168//
1169// non scope trigger functions
1170//
1171
1173 return compare_values(tval[0], ws.current_date.to_ymd(ws.start_date).year, int32_t(tval[1]));
1174}
1176 return compare_values(tval[0], ws.current_date.to_ymd(ws.start_date).month, int32_t(tval[1]));
1177}
1179 return compare_to_true(tval[0], ws.world.province_get_is_coast(to_prov(primary_slot)));
1180}
1182 // note: comparison reversed since rank 1 is "greater" than rank 1 + N
1183 return compare_values(tval[0], int32_t(tval[1]), ws.world.nation_get_rank(to_nation(primary_slot)));
1184}
1185TRIGGER_FUNCTION(tf_technology) {
1186 auto tid = trigger::payload(tval[1]).tech_id;
1187 return compare_to_true(tval[0], ws.world.nation_get_active_technologies(to_nation(primary_slot), tid));
1188}
1189TRIGGER_FUNCTION(tf_technology_province) {
1190 auto tid = trigger::payload(tval[1]).tech_id;
1191 return compare_to_true(tval[0], ws.world.nation_get_active_technologies(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)), tid));
1192}
1193TRIGGER_FUNCTION(tf_technology_pop) {
1194 auto tid = trigger::payload(tval[1]).tech_id;
1195 return compare_to_true(tval[0], ws.world.nation_get_active_technologies(nations::owner_of_pop(ws, to_pop(primary_slot)), tid));
1196}
1197TRIGGER_FUNCTION(tf_strata_rich) {
1198 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
1199 auto strata = ws.world.pop_type_get_strata(type);
1200 return compare_to_true(tval[0], strata == decltype(strata)(int32_t(culture::pop_strata::rich)));
1201}
1202TRIGGER_FUNCTION(tf_strata_middle) {
1203 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
1204 auto strata = ws.world.pop_type_get_strata(type);
1205 return compare_to_true(tval[0], strata == decltype(strata)(int32_t(culture::pop_strata::middle)));
1206}
1207TRIGGER_FUNCTION(tf_strata_poor) {
1208 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
1209 auto strata = ws.world.pop_type_get_strata(type);
1210 return compare_to_true(tval[0], strata == decltype(strata)(int32_t(culture::pop_strata::poor)));
1211}
1212TRIGGER_FUNCTION(tf_life_rating_province) {
1213 return compare_values(tval[0], ws.world.province_get_life_rating(to_prov(primary_slot)),
1214 trigger::payload(tval[1]).signed_value);
1215}
1216TRIGGER_FUNCTION(tf_life_rating_state) {
1217 auto state_caps = ws.world.state_instance_get_capital(to_state(primary_slot));
1218 return compare_values(tval[0], ws.world.province_get_life_rating(state_caps), trigger::payload(tval[1]).signed_value);
1219}
1220
1222 return make_true_accumulator(
1223 [&ws, sea_index = ws.province_definitions.first_sea_province.index()](ve::tagged_vector<int32_t> v) {
1224 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(v));
1225 return (owners == ve::tagged_vector<dcon::nation_id>()) & (ve::int_vector(v) < sea_index);
1226 });
1227}
1228
1229TRIGGER_FUNCTION(tf_has_empty_adjacent_state_province) {
1230 auto results = ve::apply(
1231 [&ws](int32_t p_slot, int32_t, int32_t) {
1232 auto pid = to_prov(p_slot);
1233 auto acc = empty_province_accumulator(ws);
1234
1235 for(auto p : ws.world.province_get_province_adjacency(pid)) {
1236 auto other = p.get_connected_provinces(0) == pid ? p.get_connected_provinces(1) : p.get_connected_provinces(0);
1237 acc.add_value(to_generic(other));
1238 if(acc.result)
1239 return true;
1240 }
1241
1242 acc.flush();
1243 return acc.result;
1244 },
1245 primary_slot, this_slot, from_slot);
1246
1247 return compare_to_true(tval[0], results);
1248}
1249auto empty_province_from_state_accumulator(sys::state const& ws, dcon::state_instance_id sid) {
1250 return make_true_accumulator([&ws, vector_sid = ve::tagged_vector<dcon::state_instance_id>(sid),
1251 sea_index = ws.province_definitions.first_sea_province.index()](ve::tagged_vector<int32_t> v) {
1252 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(v));
1253 return (owners == ve::tagged_vector<dcon::nation_id>()) & (ve::int_vector(v) < sea_index) &
1254 (ws.world.province_get_state_membership(to_prov(v)) != vector_sid);
1255 });
1256}
1257
1258TRIGGER_FUNCTION(tf_has_empty_adjacent_state_state) {
1259 auto results = ve::apply(
1260 [&ws](int32_t p_slot, int32_t, int32_t) {
1261 auto state_id = to_state(p_slot);
1262 auto region_owner = ws.world.state_instance_get_nation_from_state_ownership(state_id);
1263
1264 auto acc = empty_province_from_state_accumulator(ws, state_id);
1265 auto region_id = ws.world.state_instance_get_definition(state_id);
1266
1267 for(auto sp : ws.world.state_definition_get_abstract_state_membership(region_id)) {
1268 if(sp.get_province().get_nation_from_province_ownership() == region_owner) {
1269 for(auto p : ws.world.province_get_province_adjacency(sp.get_province())) {
1270 auto other =
1271 p.get_connected_provinces(0) == sp.get_province() ? p.get_connected_provinces(1) : p.get_connected_provinces(0);
1272 acc.add_value(to_generic(other));
1273 if(acc.result)
1274 return true;
1275 }
1276 }
1277 }
1278
1279 acc.flush();
1280 return acc.result;
1281 },
1282 primary_slot, this_slot, from_slot);
1283
1284 return compare_to_true(tval[0], results);
1285}
1286TRIGGER_FUNCTION(tf_state_id_province) {
1287 auto pid = trigger::payload(tval[1]).prov_id;
1288 return compare_values_eq(tval[0],
1289 ws.world.abstract_state_membership_get_state(ws.world.province_get_abstract_state_membership(to_prov(primary_slot))),
1290 ws.world.abstract_state_membership_get_state(ws.world.province_get_abstract_state_membership(pid)));
1291}
1292TRIGGER_FUNCTION(tf_state_id_state) {
1293 auto pid = trigger::payload(tval[1]).prov_id;
1294 return compare_values_eq(tval[0], ws.world.state_instance_get_definition(to_state(primary_slot)),
1295 ws.world.abstract_state_membership_get_state(ws.world.province_get_abstract_state_membership(pid)));
1296}
1297TRIGGER_FUNCTION(tf_cash_reserves) {
1298 auto ratio = read_float_from_payload(tval + 1);
1299 auto target = economy::desired_needs_spending(ws, to_pop(primary_slot));
1300 auto savings_qnty = ws.world.pop_get_savings(to_pop(primary_slot));
1301 return compare_values(tval[0], ve::select(target != 0.0f, savings_qnty * 100.0f / target, 100.0f), ratio);
1302}
1303TRIGGER_FUNCTION(tf_unemployment_nation) {
1304 auto total_employable = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::employable);
1305 auto total_employed = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::employed);
1306 return compare_values(tval[0], ve::select(total_employable > 0.0f, 1.0f - (total_employed / total_employable), 0.0f),
1307 read_float_from_payload(tval + 1));
1308}
1309TRIGGER_FUNCTION(tf_unemployment_state) {
1310 auto total_employable = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::employable);
1311 auto total_employed = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::employed);
1312 return compare_values(tval[0], ve::select(total_employable > 0.0f, 1.0f - (total_employed / total_employable), 0.0f),
1313 read_float_from_payload(tval + 1));
1314}
1315TRIGGER_FUNCTION(tf_unemployment_province) {
1316 auto total_employable = ws.world.province_get_demographics(to_prov(primary_slot), demographics::employable);
1317 auto total_employed = ws.world.province_get_demographics(to_prov(primary_slot), demographics::employed);
1318 return compare_values(tval[0], ve::select(total_employable > 0.0f, 1.0f - (total_employed / total_employable), 0.0f),
1319 read_float_from_payload(tval + 1));
1320}
1321TRIGGER_FUNCTION(tf_unemployment_pop) {
1322 auto employed = ws.world.pop_get_employment(to_pop(primary_slot));
1323 auto total_pop = ws.world.pop_get_size(to_pop(primary_slot));
1324 auto ptype = ws.world.pop_get_poptype(to_pop(primary_slot));
1325 return compare_values(tval[0], ve::select(ws.world.pop_type_get_has_unemployment(ptype), 1.0f - (employed / total_pop), 0.0f),
1326 read_float_from_payload(tval + 1));
1327}
1328TRIGGER_FUNCTION(tf_is_slave_nation) {
1329 return compare_to_true(tval[0], (ws.world.nation_get_combined_issue_rules(to_nation(primary_slot)) &
1331}
1332TRIGGER_FUNCTION(tf_is_slave_state) {
1333 return compare_to_true(tval[0], ws.world.province_get_is_slave(ws.world.state_instance_get_capital(to_state(primary_slot))));
1334}
1335TRIGGER_FUNCTION(tf_is_slave_province) {
1336 return compare_to_true(tval[0], ws.world.province_get_is_slave(to_prov(primary_slot)));
1337}
1338TRIGGER_FUNCTION(tf_is_slave_pop) {
1339 return compare_values_eq(tval[0], ws.world.pop_get_poptype(to_pop(primary_slot)), ws.culture_definitions.slaves);
1340}
1341TRIGGER_FUNCTION(tf_is_independant) {
1342 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
1343 dcon::nation_id());
1344}
1345TRIGGER_FUNCTION(tf_has_national_minority_province) {
1346 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1347 auto pcultures = ws.world.nation_get_primary_culture(owners);
1348 auto prov_populations = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
1349
1350 auto majority_pop = ve::apply(
1351 [&ws](int32_t p_slot, dcon::culture_id c) {
1352 if(c)
1353 return ws.world.province_get_demographics(to_prov(p_slot), demographics::to_key(ws, c));
1354 else
1355 return 0.0f;
1356 },
1357 primary_slot, pcultures);
1358
1359 return compare_to_false(tval[0], majority_pop == prov_populations);
1360}
1361TRIGGER_FUNCTION(tf_has_national_minority_state) {
1362 auto owners = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
1363 auto pcultures = ws.world.nation_get_primary_culture(owners);
1364 auto populations = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
1365
1366 auto majority_pop = ve::apply(
1367 [&ws](int32_t p_slot, dcon::culture_id c) {
1368 if(c)
1369 return ws.world.state_instance_get_demographics(to_state(p_slot), demographics::to_key(ws, c));
1370 else
1371 return 0.0f;
1372 },
1373 primary_slot, pcultures);
1374
1375 return compare_to_false(tval[0], majority_pop == populations);
1376}
1377TRIGGER_FUNCTION(tf_has_national_minority_nation) {
1378 auto pcultures = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1379 auto populations = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
1380
1381 auto majority_pop = ve::apply(
1382 [&ws](int32_t p_slot, dcon::culture_id c) {
1383 if(c)
1384 return ws.world.nation_get_demographics(to_nation(p_slot), demographics::to_key(ws, c));
1385 else
1386 return 0.0f;
1387 },
1388 primary_slot, pcultures);
1389
1390 return compare_to_false(tval[0], majority_pop == populations);
1391}
1392TRIGGER_FUNCTION(tf_government_nation) {
1393 auto gov_type = ws.world.nation_get_government_type(to_nation(primary_slot));
1394 return compare_values_eq(tval[0], gov_type, trigger::payload(tval[1]).gov_id);
1395}
1396TRIGGER_FUNCTION(tf_government_pop) {
1397 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1398 auto owners = ws.world.province_get_nation_from_province_ownership(location);
1399
1400 return tf_government_nation<return_type>(tval, ws, to_generic(owners), int32_t(), int32_t());
1401}
1402TRIGGER_FUNCTION(tf_capital) {
1403 return compare_values_eq(tval[0], ws.world.nation_get_capital(to_nation(primary_slot)), payload(tval[1]).prov_id);
1404}
1405TRIGGER_FUNCTION(tf_tech_school) {
1406 return compare_values_eq(tval[0], ws.world.nation_get_tech_school(to_nation(primary_slot)), trigger::payload(tval[1]).mod_id);
1407}
1408TRIGGER_FUNCTION(tf_primary_culture) {
1409 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
1410 trigger::payload(tval[1]).cul_id);
1411}
1412TRIGGER_FUNCTION(tf_primary_culture_pop) {
1413 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(nations::owner_of_pop(ws, to_pop(primary_slot))),
1414 trigger::payload(tval[1]).cul_id);
1415}
1416TRIGGER_FUNCTION(tf_accepted_culture) {
1417 auto is_accepted = ws.world.nation_get_accepted_cultures(to_nation(primary_slot), trigger::payload(tval[1]).cul_id);
1418 return compare_to_true(tval[0], is_accepted);
1419}
1420TRIGGER_FUNCTION(tf_culture_pop) {
1421 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)), trigger::payload(tval[1]).cul_id);
1422}
1423TRIGGER_FUNCTION(tf_culture_state) {
1424 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
1425 trigger::payload(tval[1]).cul_id);
1426}
1427TRIGGER_FUNCTION(tf_culture_province) {
1428 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
1429 trigger::payload(tval[1]).cul_id);
1430}
1431TRIGGER_FUNCTION(tf_culture_nation) {
1432 auto c = trigger::payload(tval[1]).cul_id;
1433 return compare_to_true(tval[0], nations::nation_accepts_culture(ws, to_nation(primary_slot), c));
1434}
1435TRIGGER_FUNCTION(tf_culture_pop_reb) {
1436 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
1437 ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot)));
1438}
1439TRIGGER_FUNCTION(tf_culture_state_reb) {
1440 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
1441 ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot)));
1442}
1443TRIGGER_FUNCTION(tf_culture_province_reb) {
1444 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
1445 ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot)));
1446}
1447TRIGGER_FUNCTION(tf_culture_nation_reb) {
1448 return compare_to_true(tval[0], nations::nation_accepts_culture(ws, to_nation(primary_slot),
1449 ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot))));
1450}
1451TRIGGER_FUNCTION(tf_culture_this_nation) {
1452 auto pc = ws.world.pop_get_culture(to_pop(primary_slot));
1453 return compare_to_true(tval[0], nations::nation_accepts_culture(ws, to_nation(this_slot), pc));
1454}
1455TRIGGER_FUNCTION(tf_culture_from_nation) {
1456 auto pc = ws.world.pop_get_culture(to_pop(primary_slot));
1457 return compare_to_true(tval[0], nations::nation_accepts_culture(ws, to_nation(from_slot), pc));
1458}
1459TRIGGER_FUNCTION(tf_culture_this_state) {
1460 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1461 return tf_culture_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
1462}
1463TRIGGER_FUNCTION(tf_culture_this_pop) {
1464 auto loc = ws.world.pop_get_province_from_pop_location(to_pop(this_slot));
1465 auto owner = ws.world.province_get_nation_from_province_ownership(loc);
1466 return tf_culture_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
1467}
1468TRIGGER_FUNCTION(tf_culture_this_province) {
1469 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1470 return tf_culture_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
1471}
1472TRIGGER_FUNCTION(tf_culture_group_nation) {
1473 return compare_values_eq(tval[0], nations::primary_culture_group(ws, to_nation(primary_slot)),
1474 trigger::payload(tval[1]).culgrp_id);
1475}
1476TRIGGER_FUNCTION(tf_culture_group_pop) {
1477 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1478 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1479 return compare_values_eq(tval[0], cgroups, trigger::payload(tval[1]).culgrp_id);
1480}
1481TRIGGER_FUNCTION(tf_culture_group_province) {
1482 auto pculture = ws.world.province_get_dominant_culture(to_prov(primary_slot));
1483 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1484 return compare_values_eq(tval[0], cgroups, trigger::payload(tval[1]).culgrp_id);
1485}
1486TRIGGER_FUNCTION(tf_culture_group_state) {
1487 auto pculture = ws.world.state_instance_get_dominant_culture(to_state(primary_slot));
1488 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1489 return compare_values_eq(tval[0], cgroups, trigger::payload(tval[1]).culgrp_id);
1490}
1491TRIGGER_FUNCTION(tf_culture_group_reb_nation) {
1492 auto c = ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot));
1493 auto rcg = ws.world.culture_get_group_from_culture_group_membership(c);
1494
1495 return compare_values_eq(tval[0], rcg, nations::primary_culture_group(ws, to_nation(primary_slot)));
1496}
1497TRIGGER_FUNCTION(tf_culture_group_reb_pop) {
1498 auto c = ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot));
1499 auto rcg = ws.world.culture_get_group_from_culture_group_membership(c);
1500
1501 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1502 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1503
1504 return compare_values_eq(tval[0], rcg, cgroups);
1505}
1506TRIGGER_FUNCTION(tf_culture_group_nation_this_nation) {
1507 return compare_values_eq(tval[0], nations::primary_culture_group(ws, to_nation(primary_slot)),
1509}
1510TRIGGER_FUNCTION(tf_culture_group_pop_this_nation) {
1511 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1512 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1513 return compare_values_eq(tval[0], cgroups, nations::primary_culture_group(ws, to_nation(this_slot)));
1514}
1515TRIGGER_FUNCTION(tf_culture_group_nation_from_nation) {
1516 return compare_values_eq(tval[0], nations::primary_culture_group(ws, to_nation(primary_slot)),
1518}
1519TRIGGER_FUNCTION(tf_culture_group_pop_from_nation) {
1520 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1521 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1522 return compare_values_eq(tval[0], cgroups, nations::primary_culture_group(ws, to_nation(from_slot)));
1523}
1524TRIGGER_FUNCTION(tf_culture_group_nation_this_province) {
1525 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1526 return compare_values_eq(tval[0], nations::primary_culture_group(ws, to_nation(primary_slot)),
1527 nations::primary_culture_group(ws, owners));
1528}
1529TRIGGER_FUNCTION(tf_culture_group_pop_this_province) {
1530 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1531 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1532 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1533 return compare_values_eq(tval[0], cgroups, nations::primary_culture_group(ws, owners));
1534}
1535TRIGGER_FUNCTION(tf_culture_group_nation_this_state) {
1536 auto owners = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1537 return compare_values_eq(tval[0], nations::primary_culture_group(ws, to_nation(primary_slot)),
1538 nations::primary_culture_group(ws, owners));
1539}
1540TRIGGER_FUNCTION(tf_culture_group_pop_this_state) {
1541 auto owners = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1542 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1543 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1544 return compare_values_eq(tval[0], cgroups, nations::primary_culture_group(ws, owners));
1545}
1546TRIGGER_FUNCTION(tf_culture_group_nation_this_pop) {
1547 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
1548 return compare_values_eq(tval[0], nations::primary_culture_group(ws, to_nation(primary_slot)),
1550}
1551TRIGGER_FUNCTION(tf_culture_group_pop_this_pop) {
1552 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
1553 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1554 auto cgroups = ws.world.culture_get_group_from_culture_group_membership(pculture);
1555 return compare_values_eq(tval[0], cgroups, nations::primary_culture_group(ws, owner));
1556}
1557TRIGGER_FUNCTION(tf_religion) {
1558 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)), trigger::payload(tval[1]).rel_id);
1559}
1560TRIGGER_FUNCTION(tf_religion_reb) {
1561 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)),
1562 ws.world.rebel_faction_get_religion(to_rebel(from_slot)));
1563}
1564TRIGGER_FUNCTION(tf_religion_from_nation) {
1565 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)),
1566 ws.world.nation_get_religion(to_nation(from_slot)));
1567}
1568TRIGGER_FUNCTION(tf_religion_this_nation) {
1569 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)),
1570 ws.world.nation_get_religion(to_nation(this_slot)));
1571}
1572TRIGGER_FUNCTION(tf_religion_this_state) {
1573 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1574 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)), ws.world.nation_get_religion(owner));
1575}
1576TRIGGER_FUNCTION(tf_religion_this_province) {
1577 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1578 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)), ws.world.nation_get_religion(owner));
1579}
1580TRIGGER_FUNCTION(tf_religion_this_pop) {
1581 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
1582 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)), ws.world.nation_get_religion(owner));
1583}
1584TRIGGER_FUNCTION(tf_terrain_province) {
1585 return compare_values_eq(tval[0], ws.world.province_get_terrain(to_prov(primary_slot)), trigger::payload(tval[1]).mod_id);
1586}
1587TRIGGER_FUNCTION(tf_terrain_pop) {
1588 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1589 return compare_values_eq(tval[0], ws.world.province_get_terrain(location), trigger::payload(tval[1]).mod_id);
1590}
1591TRIGGER_FUNCTION(tf_trade_goods) {
1592 return compare_values_eq(tval[0], ws.world.province_get_rgo(to_prov(primary_slot)), trigger::payload(tval[1]).com_id);
1593}
1594
1595TRIGGER_FUNCTION(tf_is_secondary_power_nation) {
1596 return compare_to_true(tval[0], ws.world.nation_get_rank(to_nation(primary_slot)) <= uint32_t(ws.defines.colonial_rank));
1597}
1598TRIGGER_FUNCTION(tf_is_secondary_power_pop) {
1599 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
1600 return compare_to_true(tval[0], ws.world.nation_get_rank(owner) <= uint32_t(ws.defines.colonial_rank));
1601}
1602TRIGGER_FUNCTION(tf_has_faction_nation) {
1603 auto rebel_type = trigger::payload(tval[1]).reb_id;
1604 auto result = ve::apply(
1605 [&ws, rebel_type](dcon::nation_id n) {
1606 for(auto factions : ws.world.nation_get_rebellion_within(n)) {
1607 if(factions.get_rebels().get_type() == rebel_type)
1608 return true;
1609 }
1610 return false;
1611 },
1612 to_nation(primary_slot));
1613 return compare_to_true(tval[0], result);
1614}
1615TRIGGER_FUNCTION(tf_has_faction_pop) {
1616 auto rf = ws.world.pop_get_rebel_faction_from_pop_rebellion_membership(to_pop(primary_slot));
1617 return compare_values_eq(tval[0], ws.world.rebel_faction_get_type(rf), trigger::payload(tval[1]).reb_id);
1618}
1619auto unowned_core_accumulator(sys::state const& ws, dcon::nation_id n) {
1620 return make_true_accumulator([&ws, n](ve::tagged_vector<int32_t> v) {
1621 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(v));
1622 return owners != n;
1623 });
1624}
1625
1626TRIGGER_FUNCTION(tf_has_unclaimed_cores) {
1627 auto nation_tag = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1628 auto result = ve::apply(
1629 [&ws](dcon::nation_id n, dcon::national_identity_id t) {
1630 auto acc = unowned_core_accumulator(ws, n);
1631
1632 for(auto p : ws.world.national_identity_get_core(t)) {
1633 acc.add_value(to_generic(p.get_province().id));
1634 if(acc.result)
1635 return true;
1636 }
1637 acc.flush();
1638 return acc.result;
1639 },
1640 to_nation(primary_slot), nation_tag);
1641
1642 return compare_to_true(tval[0], result);
1643}
1644
1645TRIGGER_FUNCTION(tf_have_core_in_nation_tag) {
1646 auto h = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
1647 return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n) {
1648 for(auto p : ws.world.nation_get_province_ownership(h)) {
1649 if(ws.world.get_core_by_prov_tag_key(p.get_province(), n))
1650 return true;
1651 }
1652 return false;
1653 }, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot))));
1654}
1655TRIGGER_FUNCTION(tf_have_core_in_nation_this) {
1656 return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n, dcon::nation_id h) {
1657 for(auto p : ws.world.nation_get_province_ownership(h)) {
1658 if(ws.world.get_core_by_prov_tag_key(p.get_province(), n))
1659 return true;
1660 }
1661 return false;
1662 }, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot)), trigger::to_nation(this_slot)));
1663}
1664TRIGGER_FUNCTION(tf_have_core_in_nation_from) {
1665 return compare_to_true(tval[0], ve::apply([&](dcon::national_identity_id n, dcon::nation_id h) {
1666 for(auto p : ws.world.nation_get_province_ownership(h)) {
1667 if(ws.world.get_core_by_prov_tag_key(p.get_province(), n))
1668 return true;
1669 }
1670 return false;
1671 }, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot)), trigger::to_nation(from_slot)));
1672}
1673
1674TRIGGER_FUNCTION(tf_is_cultural_union_bool) {
1675 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1676 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1677 return !compare_values_eq(tval[0], union_group, dcon::culture_group_id());
1678}
1679TRIGGER_FUNCTION(tf_is_cultural_union_this_self_pop) {
1680 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1681 auto pgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1682
1683 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1684 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1685
1686 return compare_values_eq(tval[0], union_group, pgroup);
1687}
1688TRIGGER_FUNCTION(tf_is_cultural_union_pop_this_pop) {
1689 auto pculture = ws.world.pop_get_culture(to_pop(primary_slot));
1690 auto pgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1691
1692 auto ident = ws.world.nation_get_identity_from_identity_holder(nations::owner_of_pop(ws, to_pop(this_slot)));
1693 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1694
1695 return compare_values_eq(tval[0], union_group, pgroup);
1696}
1697TRIGGER_FUNCTION(tf_is_cultural_union_this_nation) {
1698 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1699 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1700 auto c = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1701 auto cg = ws.world.culture_get_group_from_culture_group_membership(c);
1702
1703 auto tident = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1704 auto tunion_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(tident);
1705 auto tculture = ws.world.nation_get_primary_culture(to_nation(this_slot));
1706 auto tcg = ws.world.culture_get_group_from_culture_group_membership(tculture);
1707
1708 return compare_to_true(tval[0], (union_group == tcg) || (tunion_group == cg));
1709}
1710TRIGGER_FUNCTION(tf_is_cultural_union_this_pop) {
1711 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1712 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1713
1714 auto pculture = ws.world.pop_get_culture(to_pop(this_slot));
1715 auto pgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1716
1717 return compare_values_eq(tval[0], union_group, pgroup);
1718}
1719TRIGGER_FUNCTION(tf_is_cultural_union_this_state) {
1720 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1721 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1722 auto c = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1723 auto cg = ws.world.culture_get_group_from_culture_group_membership(c);
1724
1725 auto tnation = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1726 auto tident = ws.world.nation_get_identity_from_identity_holder(tnation);
1727 auto tunion_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(tident);
1728 auto tculture = ws.world.nation_get_primary_culture(tnation);
1729 auto tcg = ws.world.culture_get_group_from_culture_group_membership(tculture);
1730
1731 return compare_to_true(tval[0], (union_group == tcg) || (tunion_group == cg));
1732}
1733TRIGGER_FUNCTION(tf_is_cultural_union_this_province) {
1734 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1735 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1736 auto c = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1737 auto cg = ws.world.culture_get_group_from_culture_group_membership(c);
1738
1739 auto tnation = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1740 auto tident = ws.world.nation_get_identity_from_identity_holder(tnation);
1741 auto tunion_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(tident);
1742 auto tculture = ws.world.nation_get_primary_culture(tnation);
1743 auto tcg = ws.world.culture_get_group_from_culture_group_membership(tculture);
1744
1745 return compare_to_true(tval[0], (union_group == tcg) || (tunion_group == cg));
1746}
1747TRIGGER_FUNCTION(tf_is_cultural_union_this_rebel) {
1748 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1749 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1750
1751 auto rculture = ws.world.rebel_faction_get_primary_culture(to_rebel(from_slot));
1752 auto rgroup = ws.world.culture_get_group_from_culture_group_membership(rculture);
1753
1754 return compare_values_eq(tval[0], union_group, rgroup);
1755}
1756TRIGGER_FUNCTION(tf_is_cultural_union_tag_nation) {
1757 auto pculture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1758 auto cgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1759 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cgroup);
1760
1761 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1762 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1763 auto tag_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(trigger::payload(tval[1]).tag_id);
1764
1765 return compare_to_true(tval[0], (utag == trigger::payload(tval[1]).tag_id) || (tag_group == union_group));
1766}
1767TRIGGER_FUNCTION(tf_is_cultural_union_tag_this_pop) {
1768 auto pculture = ws.world.pop_get_culture(to_pop(this_slot));
1769 auto cgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1770 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cgroup);
1771
1772 return compare_values_eq(tval[0], utag, trigger::payload(tval[1]).tag_id);
1773}
1774TRIGGER_FUNCTION(tf_is_cultural_union_tag_this_state) {
1775 auto state_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1776 auto pculture = ws.world.nation_get_primary_culture(state_owner);
1777 auto cgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1778 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cgroup);
1779
1780 auto ident = ws.world.nation_get_identity_from_identity_holder(state_owner);
1781 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1782 auto tag_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(trigger::payload(tval[1]).tag_id);
1783
1784 return compare_to_true(tval[0], (utag == trigger::payload(tval[1]).tag_id) || (tag_group == union_group));
1785}
1786TRIGGER_FUNCTION(tf_is_cultural_union_tag_this_province) {
1787 auto prov_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1788 auto pculture = ws.world.nation_get_primary_culture(prov_owner);
1789 auto cgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1790 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cgroup);
1791
1792 auto ident = ws.world.nation_get_identity_from_identity_holder(prov_owner);
1793 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1794 auto tag_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(trigger::payload(tval[1]).tag_id);
1795
1796 return compare_to_true(tval[0], (utag == trigger::payload(tval[1]).tag_id) || (tag_group == union_group));
1797}
1798TRIGGER_FUNCTION(tf_is_cultural_union_tag_this_nation) {
1799 auto pculture = ws.world.nation_get_primary_culture(to_nation(this_slot));
1800 auto cgroup = ws.world.culture_get_group_from_culture_group_membership(pculture);
1801 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cgroup);
1802
1803 auto ident = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1804 auto union_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(ident);
1805 auto tag_group = ws.world.national_identity_get_culture_group_from_cultural_union_of(trigger::payload(tval[1]).tag_id);
1806
1807 return compare_to_true(tval[0], (utag == trigger::payload(tval[1]).tag_id) || (tag_group == union_group));
1808}
1809TRIGGER_FUNCTION(tf_can_build_factory_nation) {
1810 return compare_values_eq(tval[0],
1811 ws.world.nation_get_combined_issue_rules(to_nation(primary_slot)) & issue_rule::pop_build_factory,
1813}
1814TRIGGER_FUNCTION(tf_can_build_factory_province) {
1815 auto p_owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1816 return compare_values_eq(tval[0], ws.world.nation_get_combined_issue_rules(p_owner) & issue_rule::pop_build_factory,
1818}
1819TRIGGER_FUNCTION(tf_can_build_factory_pop) {
1820 auto p_owner = nations::owner_of_pop(ws, to_pop(primary_slot));
1821 return compare_values_eq(tval[0], ws.world.nation_get_combined_issue_rules(p_owner) & issue_rule::pop_build_factory,
1823}
1824TRIGGER_FUNCTION(tf_war_nation) {
1825 return compare_to_true(tval[0], ws.world.nation_get_is_at_war(to_nation(primary_slot)));
1826}
1827TRIGGER_FUNCTION(tf_war_pop) {
1828 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
1829 return compare_to_true(tval[0], ws.world.nation_get_is_at_war(owner));
1830}
1831TRIGGER_FUNCTION(tf_war_exhaustion_nation) {
1832 return compare_values(tval[0], ws.world.nation_get_war_exhaustion(to_nation(primary_slot)), read_float_from_payload(tval + 1));
1833}
1834TRIGGER_FUNCTION(tf_war_exhaustion_province) {
1835 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1836 return compare_values(tval[0], ws.world.nation_get_war_exhaustion(owner), read_float_from_payload(tval + 1));
1837}
1838TRIGGER_FUNCTION(tf_war_exhaustion_pop) {
1839 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
1840 return compare_values(tval[0], ws.world.nation_get_war_exhaustion(owner), read_float_from_payload(tval + 1));
1841}
1842TRIGGER_FUNCTION(tf_blockade) {
1843 return compare_values(tval[0], nations::central_blockaded_fraction(ws, to_nation(primary_slot)),
1844 read_float_from_payload(tval + 1));
1845}
1847 auto pid = payload(tval[1]).prov_id;
1848 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(pid), to_nation(primary_slot));
1849}
1850TRIGGER_FUNCTION(tf_owns_province) {
1851 auto pid = payload(tval[1]).prov_id;
1852 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(pid), ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
1853}
1854TRIGGER_FUNCTION(tf_controls) {
1855 auto pid = payload(tval[1]).prov_id;
1856 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(pid), to_nation(primary_slot));
1857}
1858TRIGGER_FUNCTION(tf_is_core_integer) {
1859 auto pid = payload(tval[1]).prov_id;
1860 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1861 auto result = ve::apply(
1862 [&ws, pid](dcon::national_identity_id t) {
1863 for(auto c : ws.world.province_get_core(pid)) {
1864 if(c.get_identity() == t)
1865 return true;
1866 }
1867 return false;
1868 },
1869 tag);
1870 return compare_to_true(tval[0], result);
1871}
1872TRIGGER_FUNCTION(tf_is_core_this_nation) {
1873 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1874 auto result = ve::apply(
1875 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1876 for(auto c : ws.world.province_get_core(pid)) {
1877 if(c.get_identity() == t)
1878 return true;
1879 }
1880 return false;
1881 },
1882 to_prov(primary_slot), tag);
1883 return compare_to_true(tval[0], result);
1884}
1885TRIGGER_FUNCTION(tf_is_core_this_state) {
1886 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1887 auto tag = ws.world.nation_get_identity_from_identity_holder(owner);
1888 auto result = ve::apply(
1889 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1890 for(auto c : ws.world.province_get_core(pid)) {
1891 if(c.get_identity() == t)
1892 return true;
1893 }
1894 return false;
1895 },
1896 to_prov(primary_slot), tag);
1897 return compare_to_true(tval[0], result);
1898}
1899TRIGGER_FUNCTION(tf_is_core_this_province) {
1900 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1901 auto tag = ws.world.nation_get_identity_from_identity_holder(owner);
1902 auto result = ve::apply(
1903 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1904 for(auto c : ws.world.province_get_core(pid)) {
1905 if(c.get_identity() == t)
1906 return true;
1907 }
1908 return false;
1909 },
1910 to_prov(primary_slot), tag);
1911 return compare_to_true(tval[0], result);
1912}
1913TRIGGER_FUNCTION(tf_is_core_this_pop) {
1914 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
1915 auto tag = ws.world.nation_get_identity_from_identity_holder(owner);
1916 auto result = ve::apply(
1917 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1918 for(auto c : ws.world.province_get_core(pid)) {
1919 if(c.get_identity() == t)
1920 return true;
1921 }
1922 return false;
1923 },
1924 to_prov(primary_slot), tag);
1925 return compare_to_true(tval[0], result);
1926}
1927TRIGGER_FUNCTION(tf_is_core_from_nation) {
1928 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
1929 auto result = ve::apply(
1930 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1931 for(auto c : ws.world.province_get_core(pid)) {
1932 if(c.get_identity() == t)
1933 return true;
1934 }
1935 return false;
1936 },
1937 to_prov(primary_slot), tag);
1938 return compare_to_true(tval[0], result);
1939}
1940TRIGGER_FUNCTION(tf_is_core_reb) {
1941 auto rtags = ws.world.rebel_faction_get_defection_target(to_rebel(from_slot));
1942 auto result = ve::apply(
1943 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1944 for(auto c : ws.world.province_get_core(pid)) {
1945 if(c.get_identity() == t)
1946 return true;
1947 }
1948 return false;
1949 },
1950 to_prov(primary_slot), rtags);
1951 return compare_to_true(tval[0], result);
1952}
1953TRIGGER_FUNCTION(tf_is_core_state_from_nation) {
1954 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
1955 auto result = ve::apply(
1956 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1957 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1958 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1959 return false;
1960 }
1961 return true;
1962 },
1963 to_state(primary_slot), tag);
1964 return compare_to_true(tval[0], result);
1965}
1966TRIGGER_FUNCTION(tf_is_core_state_this_nation) {
1967 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1968 auto result = ve::apply(
1969 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1970 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1971 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1972 return false;
1973 }
1974 return true;
1975 },
1976 to_state(primary_slot), tag);
1977 return compare_to_true(tval[0], result);
1978}
1979TRIGGER_FUNCTION(tf_is_core_state_this_province) {
1980 auto tag = ws.world.nation_get_identity_from_identity_holder(ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)));
1981 auto result = ve::apply(
1982 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1983 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1984 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1985 return false;
1986 }
1987 return true;
1988 },
1989 to_state(primary_slot), tag);
1990 return compare_to_true(tval[0], result);
1991}
1992TRIGGER_FUNCTION(tf_is_core_state_this_pop) {
1993 auto tag = ws.world.nation_get_identity_from_identity_holder(nations::owner_of_pop(ws, to_pop(this_slot)));
1994 auto result = ve::apply(
1995 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1996 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1997 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1998 return false;
1999 }
2000 return true;
2001 },
2002 to_state(primary_slot), tag);
2003 return compare_to_true(tval[0], result);
2004}
2005TRIGGER_FUNCTION(tf_is_core_boolean) {
2006 return compare_to_true(tval[0], ws.world.province_get_is_owner_core(to_prov(primary_slot)));
2007}
2008TRIGGER_FUNCTION(tf_is_core_tag) {
2009 auto result = ve::apply(
2010 [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) {
2011 return bool(ws.world.get_core_by_prov_tag_key(pid, t));
2012 },
2013 to_prov(primary_slot));
2014 return compare_to_true(tval[0], result);
2015}
2016TRIGGER_FUNCTION(tf_is_core_pop_tag) {
2017 auto result = ve::apply(
2018 [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) {
2019 return bool(ws.world.get_core_by_prov_tag_key(pid, t));
2020 },
2021 ws.world.pop_get_province_from_pop_location(to_pop(primary_slot)));
2022 return compare_to_true(tval[0], result);
2023}
2024TRIGGER_FUNCTION(tf_is_core_state_tag) {
2025 auto result = ve::apply(
2026 [&ws, t = trigger::payload(tval[1]).tag_id](dcon::state_instance_id sid) {
2027 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
2028 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
2029 return false;
2030 }
2031 return true;
2032 },
2033 to_state(primary_slot));
2034 return compare_to_true(tval[0], result);
2035}
2036TRIGGER_FUNCTION(tf_num_of_revolts) {
2037 return compare_values(tval[0], ws.world.nation_get_rebel_controlled_count(to_nation(primary_slot)), tval[1]);
2038}
2039TRIGGER_FUNCTION(tf_revolt_percentage) {
2040 return compare_values(tval[0], nations::central_reb_controlled_fraction(ws, to_nation(primary_slot)),
2041 read_float_from_payload(tval + 1));
2042}
2043TRIGGER_FUNCTION(tf_num_of_cities_int) {
2044 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)), tval[1]);
2045}
2046TRIGGER_FUNCTION(tf_num_of_cities_from_nation) {
2047 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2048 ws.world.nation_get_owned_province_count(to_nation(from_slot)));
2049}
2050TRIGGER_FUNCTION(tf_num_of_cities_this_nation) {
2051 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2052 ws.world.nation_get_owned_province_count(to_nation(this_slot)));
2053}
2054TRIGGER_FUNCTION(tf_num_of_cities_this_state) {
2055 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2056 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2057 ws.world.nation_get_owned_province_count(owner));
2058}
2059TRIGGER_FUNCTION(tf_num_of_cities_this_province) {
2060 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2061 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2062 ws.world.nation_get_owned_province_count(owner));
2063}
2064TRIGGER_FUNCTION(tf_num_of_cities_this_pop) {
2065 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2066 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2067 ws.world.nation_get_owned_province_count(owner));
2068}
2069TRIGGER_FUNCTION(tf_num_of_ports) {
2070 return compare_values(tval[0], ws.world.nation_get_central_ports(to_nation(primary_slot)), tval[1]);
2071}
2072TRIGGER_FUNCTION(tf_num_of_allies) {
2073 return compare_values(tval[0], ws.world.nation_get_allies_count(to_nation(primary_slot)), tval[1]);
2074}
2075TRIGGER_FUNCTION(tf_num_of_vassals) {
2076 return compare_values(tval[0], ws.world.nation_get_vassals_count(to_nation(primary_slot)), tval[1]);
2077}
2078TRIGGER_FUNCTION(tf_owned_by_tag) {
2079 auto holders = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2080 return compare_values_eq(tval[0], holders, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2081}
2082TRIGGER_FUNCTION(tf_owned_by_this_nation) {
2083 return compare_values_eq(tval[0], to_nation(this_slot),
2084 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2085}
2086TRIGGER_FUNCTION(tf_owned_by_from_nation) {
2087 return compare_values_eq(tval[0], to_nation(from_slot),
2088 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2089}
2090TRIGGER_FUNCTION(tf_owned_by_this_province) {
2091 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)),
2092 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2093}
2094TRIGGER_FUNCTION(tf_owned_by_this_state) {
2095 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2096 return compare_values_eq(tval[0], owner, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2097}
2098TRIGGER_FUNCTION(tf_owned_by_this_pop) {
2099 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2100 return compare_values_eq(tval[0], owner, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2101}
2102TRIGGER_FUNCTION(tf_owned_by_state_tag) {
2103 auto holders = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2104 return compare_values_eq(tval[0], holders, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2105}
2106TRIGGER_FUNCTION(tf_owned_by_state_this_nation) {
2107 return compare_values_eq(tval[0], to_nation(this_slot),
2108 ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2109}
2110TRIGGER_FUNCTION(tf_owned_by_state_from_nation) {
2111 return compare_values_eq(tval[0], to_nation(from_slot),
2112 ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2113}
2114TRIGGER_FUNCTION(tf_owned_by_state_this_province) {
2115 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)),
2116 ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2117}
2118TRIGGER_FUNCTION(tf_owned_by_state_this_state) {
2119 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2120 return compare_values_eq(tval[0], owner, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2121}
2122TRIGGER_FUNCTION(tf_owned_by_state_this_pop) {
2123 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2124 return compare_values_eq(tval[0], owner, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2125}
2126TRIGGER_FUNCTION(tf_exists_bool) {
2127 return compare_to_true(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)) != 0);
2128}
2129TRIGGER_FUNCTION(tf_exists_tag) {
2130 auto holders = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2131 return compare_to_true(tval[0], ws.world.nation_get_owned_province_count(holders) != 0);
2132}
2133TRIGGER_FUNCTION(tf_has_country_flag) {
2134 return compare_to_true(tval[0], ws.world.nation_get_flag_variables(to_nation(primary_slot), payload(tval[1]).natf_id));
2135}
2136TRIGGER_FUNCTION(tf_has_country_flag_pop) {
2137 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2138 return compare_to_true(tval[0], ws.world.nation_get_flag_variables(owner, payload(tval[1]).natf_id));
2139}
2140TRIGGER_FUNCTION(tf_has_country_flag_province) {
2141 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2142 return compare_to_true(tval[0], ws.world.nation_get_flag_variables(owner, payload(tval[1]).natf_id));
2143}
2144TRIGGER_FUNCTION(tf_has_country_flag_state) {
2145 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
2146 return compare_to_true(tval[0], ws.world.nation_get_flag_variables(owner, payload(tval[1]).natf_id));
2147}
2148TRIGGER_FUNCTION(tf_continent_province) {
2149 return compare_values_eq(tval[0], ws.world.province_get_continent(to_prov(primary_slot)), trigger::payload(tval[1]).mod_id);
2150}
2151TRIGGER_FUNCTION(tf_continent_state) {
2152 auto state_caps = ws.world.state_instance_get_capital(to_state(primary_slot));
2153 return compare_values_eq(tval[0], ws.world.province_get_continent(state_caps), trigger::payload(tval[1]).mod_id);
2154}
2155TRIGGER_FUNCTION(tf_continent_nation) {
2156 auto nat_caps = ws.world.nation_get_capital(to_nation(primary_slot));
2157 return compare_values_eq(tval[0], ws.world.province_get_continent(nat_caps), trigger::payload(tval[1]).mod_id);
2158}
2159TRIGGER_FUNCTION(tf_continent_pop) {
2160 auto prov_id = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
2161 return compare_values_eq(tval[0], ws.world.province_get_continent(prov_id), trigger::payload(tval[1]).mod_id);
2162}
2163TRIGGER_FUNCTION(tf_continent_nation_this) {
2164 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(primary_slot))),
2165 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2166}
2167TRIGGER_FUNCTION(tf_continent_state_this) {
2168 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.state_instance_get_capital(to_state(primary_slot))),
2169 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2170}
2171TRIGGER_FUNCTION(tf_continent_province_this) {
2172 return compare_values_eq(tval[0], ws.world.province_get_continent(to_prov(primary_slot)),
2173 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2174}
2175TRIGGER_FUNCTION(tf_continent_pop_this) {
2176 return compare_values_eq(tval[0],
2177 ws.world.province_get_continent(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))),
2178 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2179}
2180TRIGGER_FUNCTION(tf_continent_nation_from) {
2181 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(primary_slot))),
2182 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2183}
2184TRIGGER_FUNCTION(tf_continent_state_from) {
2185 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.state_instance_get_capital(to_state(primary_slot))),
2186 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2187}
2188TRIGGER_FUNCTION(tf_continent_province_from) {
2189 return compare_values_eq(tval[0], ws.world.province_get_continent(to_prov(primary_slot)),
2190 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2191}
2192TRIGGER_FUNCTION(tf_continent_pop_from) {
2193 return compare_values_eq(tval[0],
2194 ws.world.province_get_continent(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))),
2195 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2196}
2197TRIGGER_FUNCTION(tf_casus_belli_tag) {
2198 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2199 auto result = ve::apply([&ws, tag_holder](dcon::nation_id n) { return military::can_use_cb_against(ws, n, tag_holder); },
2200 to_nation(primary_slot));
2201 return compare_to_true(tval[0], result);
2202}
2203TRIGGER_FUNCTION(tf_casus_belli_from) {
2204 auto result =
2205 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2206 to_nation(primary_slot), to_nation(from_slot));
2207 return compare_to_true(tval[0], result);
2208}
2209TRIGGER_FUNCTION(tf_casus_belli_this_nation) {
2210 auto result =
2211 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2212 to_nation(primary_slot), to_nation(this_slot));
2213 return compare_to_true(tval[0], result);
2214}
2215TRIGGER_FUNCTION(tf_casus_belli_this_state) {
2216 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2217 auto result =
2218 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2219 to_nation(primary_slot), owner);
2220 return compare_to_true(tval[0], result);
2221}
2222TRIGGER_FUNCTION(tf_casus_belli_this_province) {
2223 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2224 auto result =
2225 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2226 to_nation(primary_slot), owner);
2227 return compare_to_true(tval[0], result);
2228}
2229TRIGGER_FUNCTION(tf_casus_belli_this_pop) {
2230 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2231 auto result =
2232 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2233 to_nation(primary_slot), owner);
2234 return compare_to_true(tval[0], result);
2235}
2236TRIGGER_FUNCTION(tf_military_access_tag) {
2237 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2238 auto result = ve::apply(
2239 [&ws, holder](dcon::nation_id n) {
2240 return ws.world.unilateral_relationship_get_military_access(
2241 ws.world.get_unilateral_relationship_by_unilateral_pair(holder, n));
2242 },
2243 to_nation(primary_slot));
2244 return compare_to_true(tval[0], result);
2245}
2246TRIGGER_FUNCTION(tf_military_access_from) {
2247 auto result = ve::apply(
2248 [&ws](dcon::nation_id n, dcon::nation_id t) {
2249 return ws.world.unilateral_relationship_get_military_access(
2250 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2251 },
2252 to_nation(primary_slot), to_nation(from_slot));
2253 return compare_to_true(tval[0], result);
2254}
2255TRIGGER_FUNCTION(tf_military_access_this_nation) {
2256 auto result = ve::apply(
2257 [&ws](dcon::nation_id n, dcon::nation_id t) {
2258 return ws.world.unilateral_relationship_get_military_access(
2259 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2260 },
2261 to_nation(primary_slot), to_nation(this_slot));
2262 return compare_to_true(tval[0], result);
2263}
2264TRIGGER_FUNCTION(tf_military_access_this_state) {
2265 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2266 auto result = ve::apply(
2267 [&ws](dcon::nation_id n, dcon::nation_id t) {
2268 return ws.world.unilateral_relationship_get_military_access(
2269 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2270 },
2271 to_nation(primary_slot), owner);
2272 return compare_to_true(tval[0], result);
2273}
2274TRIGGER_FUNCTION(tf_military_access_this_province) {
2275 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2276 auto result = ve::apply(
2277 [&ws](dcon::nation_id n, dcon::nation_id t) {
2278 return ws.world.unilateral_relationship_get_military_access(
2279 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2280 },
2281 to_nation(primary_slot), owner);
2282 return compare_to_true(tval[0], result);
2283}
2284TRIGGER_FUNCTION(tf_military_access_this_pop) {
2285 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2286 auto result = ve::apply(
2287 [&ws](dcon::nation_id n, dcon::nation_id t) {
2288 return ws.world.unilateral_relationship_get_military_access(
2289 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2290 },
2291 to_nation(primary_slot), owner);
2292 return compare_to_true(tval[0], result);
2293}
2294TRIGGER_FUNCTION(tf_prestige_value) {
2295 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), read_float_from_payload(tval + 1));
2296}
2297TRIGGER_FUNCTION(tf_prestige_from) {
2298 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)),
2299 ws.world.nation_get_prestige(to_nation(from_slot)));
2300}
2301TRIGGER_FUNCTION(tf_prestige_this_nation) {
2302 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)),
2303 ws.world.nation_get_prestige(to_nation(this_slot)));
2304}
2305TRIGGER_FUNCTION(tf_prestige_this_state) {
2306 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2307 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), ws.world.nation_get_prestige(owner));
2308}
2309TRIGGER_FUNCTION(tf_prestige_this_province) {
2310 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2311 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), ws.world.nation_get_prestige(owner));
2312}
2313TRIGGER_FUNCTION(tf_prestige_this_pop) {
2314 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2315 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), ws.world.nation_get_prestige(owner));
2316}
2318 return compare_values(tval[0], ws.world.nation_get_infamy(to_nation(primary_slot)), read_float_from_payload(tval + 1));
2319}
2320TRIGGER_FUNCTION(tf_has_building_fort) {
2321 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::fort)) != 0);
2322}
2323TRIGGER_FUNCTION(tf_has_building_railroad) {
2324 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad)) != 0);
2325}
2326TRIGGER_FUNCTION(tf_has_building_naval_base) {
2327 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0);
2328}
2329
2330TRIGGER_FUNCTION(tf_has_building_factory) {
2331 auto result = ve::apply([&ws](dcon::state_instance_id s) { return economy::has_factory(ws, s); }, to_state(primary_slot));
2332 return compare_to_true(tval[0], result);
2333}
2334TRIGGER_FUNCTION(tf_has_building_state) {
2335 auto result =
2336 ve::apply([&ws, f = payload(tval[1]).fac_id](dcon::state_instance_id s) { return economy::has_building(ws, s, f); },
2337 to_state(primary_slot));
2338 return compare_to_true(tval[0], result);
2339}
2340TRIGGER_FUNCTION(tf_has_building_state_from_province) {
2341 auto state = ws.world.province_get_state_membership(to_prov(primary_slot));
2342 auto result =
2343 ve::apply([&ws, f = payload(tval[1]).fac_id](dcon::state_instance_id s) { return economy::has_building(ws, s, f); }, state);
2344 return compare_to_true(tval[0], result);
2345}
2346TRIGGER_FUNCTION(tf_has_building_factory_from_province) {
2347 auto state = ws.world.province_get_state_membership(to_prov(primary_slot));
2348 auto result = ve::apply([&ws](dcon::state_instance_id s) { return economy::has_factory(ws, s); }, state);
2349 return compare_to_true(tval[0], result);
2350}
2352 return compare_to_true(tval[0],
2353 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)) == dcon::nation_id());
2354}
2355TRIGGER_FUNCTION(tf_empty_state) {
2356 return compare_to_true(tval[0], to_state(primary_slot) == dcon::state_instance_id());
2357}
2358TRIGGER_FUNCTION(tf_is_blockaded) {
2359 return compare_to_true(tval[0], military::province_is_blockaded(ws, to_prov(primary_slot)));
2360}
2361TRIGGER_FUNCTION(tf_has_country_modifier) {
2362 auto const mod = trigger::payload(tval[1]).mod_id;
2363 auto result = ve::apply(
2364 [&ws, mod](dcon::nation_id n) {
2365 for(auto m : ws.world.nation_get_current_modifiers(n)) {
2366 if(m.mod_id == mod)
2367 return true;
2368 }
2369 return false;
2370 },
2371 to_nation(primary_slot));
2372 return compare_to_true(tval[0], result);
2373}
2374TRIGGER_FUNCTION(tf_has_country_modifier_province) {
2375 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2376 auto const mod = trigger::payload(tval[1]).mod_id;
2377 auto result = ve::apply(
2378 [&ws, mod](dcon::nation_id n) {
2379 for(auto m : ws.world.nation_get_current_modifiers(n)) {
2380 if(m.mod_id == mod)
2381 return true;
2382 }
2383 return false;
2384 },
2385 owner);
2386 return compare_to_true(tval[0], result);
2387}
2388TRIGGER_FUNCTION(tf_has_province_modifier) {
2389 auto const mod = trigger::payload(tval[1]).mod_id;
2390 auto result = ve::apply(
2391 [&ws, mod](dcon::province_id n) {
2392 for(auto m : ws.world.province_get_current_modifiers(n)) {
2393 if(m.mod_id == mod)
2394 return true;
2395 }
2396 return false;
2397 },
2398 to_prov(primary_slot));
2399 return compare_to_true(tval[0], result);
2400}
2402 return compare_values_eq(tval[0], ws.world.province_get_state_from_abstract_state_membership(to_prov(primary_slot)),
2403 trigger::payload(tval[1]).state_id);
2404}
2405TRIGGER_FUNCTION(tf_region_state) {
2406 return compare_values_eq(tval[0], ws.world.state_instance_get_definition(to_state(primary_slot)),
2407 trigger::payload(tval[1]).state_id);
2408}
2409TRIGGER_FUNCTION(tf_region_pop) {
2410 return compare_values_eq(tval[0], ws.world.province_get_state_from_abstract_state_membership(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))), trigger::payload(tval[1]).state_id);
2411}
2412
2413
2414TRIGGER_FUNCTION(tf_region_proper) {
2415 auto r = trigger::payload(tval[1]).reg_id;
2416 auto result = ve::apply([&ws, r](dcon::province_id p) {
2417 for(auto m : ws.world.province_get_region_membership(p)) {
2418 if(m.get_region() == r)
2419 return true;
2420 }
2421 return false;
2422 }, to_prov(primary_slot));
2423 return compare_to_true(tval[0], result);
2424}
2425TRIGGER_FUNCTION(tf_region_proper_state) {
2426 auto r = trigger::payload(tval[1]).reg_id;
2427 auto result = ve::apply([&ws, r](dcon::province_id p) {
2428 for(auto m : ws.world.province_get_region_membership(p)) {
2429 if(m.get_region() == r)
2430 return true;
2431 }
2432 return false;
2433 }, ws.world.state_instance_get_capital(to_state(primary_slot)));
2434 return compare_to_true(tval[0], result);
2435}
2436TRIGGER_FUNCTION(tf_region_proper_pop) {
2437 auto r = trigger::payload(tval[1]).reg_id;
2438 auto result = ve::apply([&ws, r](dcon::province_id p) {
2439 for(auto m : ws.world.province_get_region_membership(p)) {
2440 if(m.get_region() == r)
2441 return true;
2442 }
2443 return false;
2444 }, ws.world.pop_get_province_from_pop_location(to_pop(primary_slot)));
2445 return compare_to_true(tval[0], result);
2446}
2447TRIGGER_FUNCTION(tf_owns_region_proper) {
2448 auto result = ve::apply([&](dcon::region_id sd, dcon::nation_id n) {
2449 for(auto p : ws.world.region_get_region_membership(sd)) {
2450 if(p.get_province().get_nation_from_province_ownership() != n)
2451 return false;
2452 }
2453 return true;
2454 }, trigger::payload(tval[1]).reg_id, trigger::to_nation(primary_slot));
2455 return compare_to_true(tval[0], result);
2456}
2457TRIGGER_FUNCTION(tf_owns_region) {
2458 auto result = ve::apply([&](dcon::state_definition_id sd, dcon::nation_id n) {
2459 for(auto p : ws.world.state_definition_get_abstract_state_membership(sd)) {
2460 if(p.get_province().get_nation_from_province_ownership() != n)
2461 return false;
2462 }
2463 return true;
2464 }, trigger::payload(tval[1]).state_id, trigger::to_nation(primary_slot));
2465 return compare_to_true(tval[0], result);
2466}
2467TRIGGER_FUNCTION(tf_tag_tag) {
2468 return compare_values_eq(tval[0], ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot)),
2469 trigger::payload(tval[1]).tag_id);
2470}
2471TRIGGER_FUNCTION(tf_tag_this_nation) {
2472 return compare_values_eq(tval[0], to_nation(primary_slot), to_nation(this_slot));
2473}
2474TRIGGER_FUNCTION(tf_tag_this_province) {
2475 return compare_values_eq(tval[0], to_nation(primary_slot),
2476 ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)));
2477}
2478TRIGGER_FUNCTION(tf_tag_from_nation) {
2479 return compare_values_eq(tval[0], to_nation(primary_slot), to_nation(from_slot));
2480}
2481TRIGGER_FUNCTION(tf_tag_from_province) {
2482 return compare_values_eq(tval[0], to_nation(primary_slot),
2483 ws.world.province_get_nation_from_province_ownership(to_prov(from_slot)));
2484}
2485TRIGGER_FUNCTION(tf_tag_pop) {
2486 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2487 return compare_values_eq(tval[0], ws.world.nation_get_identity_from_identity_holder(owner), trigger::payload(tval[1]).tag_id);
2488}
2489TRIGGER_FUNCTION(tf_stronger_army_than_tag) {
2490 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2491
2492 auto main_brigades = ws.world.nation_get_active_regiments(to_nation(primary_slot));
2493 auto this_brigades = ws.world.nation_get_active_regiments(tag_holder);
2494 return compare_values(tval[0], main_brigades, this_brigades);
2495}
2496TRIGGER_FUNCTION(tf_stronger_army_than_this_nation) {
2497 auto main_brigades = ws.world.nation_get_active_regiments(to_nation(primary_slot));
2498 auto this_brigades = ws.world.nation_get_active_regiments(trigger::to_nation(this_slot));
2499 return compare_values(tval[0], main_brigades, this_brigades);
2500}
2501TRIGGER_FUNCTION(tf_stronger_army_than_this_state) {
2502 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2503 return tf_stronger_army_than_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
2504}
2505TRIGGER_FUNCTION(tf_stronger_army_than_this_province) {
2506 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2507 return tf_stronger_army_than_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
2508}
2509TRIGGER_FUNCTION(tf_stronger_army_than_this_pop) {
2510 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2511 return tf_stronger_army_than_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
2512}
2513TRIGGER_FUNCTION(tf_stronger_army_than_from_nation) {
2514 return tf_stronger_army_than_this_nation<return_type>(tval, ws, primary_slot, from_slot, int32_t());
2515}
2516TRIGGER_FUNCTION(tf_stronger_army_than_from_province) {
2517 return tf_stronger_army_than_this_province<return_type>(tval, ws, primary_slot, from_slot, int32_t());
2518}
2519TRIGGER_FUNCTION(tf_neighbour_tag) {
2520 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2521 auto result =
2522 ve::apply([&ws, tag_holder](
2523 dcon::nation_id n) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, tag_holder)); },
2524 to_nation(primary_slot));
2525 return compare_to_true(tval[0], result);
2526}
2527TRIGGER_FUNCTION(tf_neighbour_this) {
2528 auto result = ve::apply(
2529 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2530 to_nation(primary_slot), to_nation(this_slot));
2531 return compare_to_true(tval[0], result);
2532}
2533TRIGGER_FUNCTION(tf_neighbour_from) {
2534 auto result = ve::apply(
2535 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2536 to_nation(primary_slot), to_nation(from_slot));
2537 return compare_to_true(tval[0], result);
2538}
2539TRIGGER_FUNCTION(tf_neighbour_this_province) {
2540 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2541 auto result = ve::apply(
2542 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2543 to_nation(primary_slot), owner);
2544 return compare_to_true(tval[0], result);
2545}
2546TRIGGER_FUNCTION(tf_neighbour_from_province) {
2547 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
2548 auto result = ve::apply(
2549 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2550 to_nation(primary_slot), owner);
2551 return compare_to_true(tval[0], result);
2552}
2553TRIGGER_FUNCTION(tf_country_units_in_state_from) {
2554 auto result = ve::apply(
2555 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2556 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2557 if(p.get_province().get_state_membership() == s) {
2558 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2559 if(a.get_army().get_controller_from_army_control() == tag)
2560 return true;
2561 }
2562 }
2563 }
2564 return false;
2565 },
2566 to_state(primary_slot), to_nation(from_slot));
2567 return compare_to_true(tval[0], result);
2568}
2569TRIGGER_FUNCTION(tf_country_units_in_state_this_nation) {
2570 auto result = ve::apply(
2571 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2572 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2573 if(p.get_province().get_state_membership() == s) {
2574 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2575 if(a.get_army().get_controller_from_army_control() == tag)
2576 return true;
2577 }
2578 }
2579 }
2580 return false;
2581 },
2582 to_state(primary_slot), to_nation(this_slot));
2583 return compare_to_true(tval[0], result);
2584}
2585TRIGGER_FUNCTION(tf_country_units_in_state_this_province) {
2586 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2587 auto result = ve::apply(
2588 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2589 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2590 if(p.get_province().get_state_membership() == s) {
2591 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2592 if(a.get_army().get_controller_from_army_control() == tag)
2593 return true;
2594 }
2595 }
2596 }
2597 return false;
2598 },
2599 to_state(primary_slot), owner);
2600 return compare_to_true(tval[0], result);
2601}
2602TRIGGER_FUNCTION(tf_country_units_in_state_this_state) {
2603 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2604 auto result = ve::apply(
2605 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2606 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2607 if(p.get_province().get_state_membership() == s) {
2608 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2609 if(a.get_army().get_controller_from_army_control() == tag)
2610 return true;
2611 }
2612 }
2613 }
2614 return false;
2615 },
2616 to_state(primary_slot), owner);
2617 return compare_to_true(tval[0], result);
2618}
2619TRIGGER_FUNCTION(tf_country_units_in_state_this_pop) {
2620 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2621 auto result = ve::apply(
2622 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2623 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2624 if(p.get_province().get_state_membership() == s) {
2625 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2626 if(a.get_army().get_controller_from_army_control() == tag)
2627 return true;
2628 }
2629 }
2630 }
2631 return false;
2632 },
2633 to_state(primary_slot), owner);
2634 return compare_to_true(tval[0], result);
2635}
2636TRIGGER_FUNCTION(tf_country_units_in_state_tag) {
2637 auto tag = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2638 auto result = ve::apply(
2639 [&ws, tag](dcon::state_instance_id s) {
2640 if(!tag)
2641 return false;
2642 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2643 if(p.get_province().get_state_membership() == s) {
2644 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2645 if(a.get_army().get_controller_from_army_control() == tag)
2646 return true;
2647 }
2648 }
2649 }
2650 return false;
2651 },
2652 to_state(primary_slot));
2653 return compare_to_true(tval[0], result);
2654}
2655TRIGGER_FUNCTION(tf_units_in_province_value) {
2656 auto result = ve::apply(
2657 [&ws](dcon::province_id p) {
2658 int32_t total = 0;
2659 for(auto a : ws.world.province_get_army_location(p)) {
2660 for(auto u : a.get_army().get_army_membership()) {
2661 ++total;
2662 }
2663 }
2664 return total;
2665 },
2666 to_prov(primary_slot));
2667 return compare_values(tval[0], result, int32_t(tval[1]));
2668}
2669TRIGGER_FUNCTION(tf_units_in_province_tag) {
2670 auto tag = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2671 auto result = ve::apply(
2672 [&ws, tag](dcon::province_id p) {
2673 if(!tag)
2674 return false;
2675 for(auto a : ws.world.province_get_army_location(p)) {
2676 if(a.get_army().get_controller_from_army_control() == tag)
2677 return true;
2678 }
2679 return false;
2680 },
2681 to_prov(primary_slot));
2682 return compare_to_true(tval[0], result);
2683}
2684
2685TRIGGER_FUNCTION(tf_units_in_province_from) {
2686 auto result = ve::apply(
2687 [&ws](dcon::province_id p, dcon::nation_id n) {
2688 for(auto a : ws.world.province_get_army_location(p)) {
2689 if(a.get_army().get_controller_from_army_control() == n)
2690 return true;
2691 }
2692 return false;
2693 },
2694 to_prov(primary_slot), to_nation(from_slot));
2695 return compare_to_true(tval[0], result);
2696}
2697TRIGGER_FUNCTION(tf_units_in_province_this_nation) {
2698 auto result = ve::apply(
2699 [&ws](dcon::province_id p, dcon::nation_id n) {
2700 for(auto a : ws.world.province_get_army_location(p)) {
2701 if(a.get_army().get_controller_from_army_control() == n)
2702 return true;
2703 }
2704 return false;
2705 },
2706 to_prov(primary_slot), to_nation(this_slot));
2707 return compare_to_true(tval[0], result);
2708}
2709TRIGGER_FUNCTION(tf_units_in_province_this_province) {
2710 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2711 auto result = ve::apply(
2712 [&ws](dcon::province_id p, dcon::nation_id n) {
2713 for(auto a : ws.world.province_get_army_location(p)) {
2714 if(a.get_army().get_controller_from_army_control() == n)
2715 return true;
2716 }
2717 return false;
2718 },
2719 to_prov(primary_slot), owner);
2720 return compare_to_true(tval[0], result);
2721}
2722TRIGGER_FUNCTION(tf_units_in_province_this_state) {
2723 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2724 auto result = ve::apply(
2725 [&ws](dcon::province_id p, dcon::nation_id n) {
2726 for(auto a : ws.world.province_get_army_location(p)) {
2727 if(a.get_army().get_controller_from_army_control() == n)
2728 return true;
2729 }
2730 return false;
2731 },
2732 to_prov(primary_slot), owner);
2733 return compare_to_true(tval[0], result);
2734}
2735TRIGGER_FUNCTION(tf_units_in_province_this_pop) {
2736 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2737 auto result = ve::apply(
2738 [&ws](dcon::province_id p, dcon::nation_id n) {
2739 for(auto a : ws.world.province_get_army_location(p)) {
2740 if(a.get_army().get_controller_from_army_control() == n)
2741 return true;
2742 }
2743 return false;
2744 },
2745 to_prov(primary_slot), owner);
2746 return compare_to_true(tval[0], result);
2747}
2748TRIGGER_FUNCTION(tf_war_with_tag) {
2749 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2750 auto result =
2751 ve::apply([&ws, holder](dcon::nation_id a) { return military::are_at_war(ws, holder, a); }, to_nation(primary_slot));
2752 return compare_to_true(tval[0], result);
2753}
2754TRIGGER_FUNCTION(tf_war_with_from) {
2755 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2756 to_nation(primary_slot), to_nation(from_slot));
2757 return compare_to_true(tval[0], result);
2758}
2759TRIGGER_FUNCTION(tf_war_with_this_nation) {
2760 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2761 to_nation(primary_slot), to_nation(this_slot));
2762 return compare_to_true(tval[0], result);
2763}
2764TRIGGER_FUNCTION(tf_war_with_this_province) {
2765 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2766 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2767 to_nation(primary_slot), owner);
2768 return compare_to_true(tval[0], result);
2769}
2770TRIGGER_FUNCTION(tf_war_with_this_state) {
2771 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2772 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2773 to_nation(primary_slot), owner);
2774 return compare_to_true(tval[0], result);
2775}
2776TRIGGER_FUNCTION(tf_war_with_this_pop) {
2777 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2778 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2779 to_nation(primary_slot), owner);
2780 return compare_to_true(tval[0], result);
2781}
2782TRIGGER_FUNCTION(tf_unit_in_battle) {
2783 return compare_to_true(tval[0], military::battle_is_ongoing_in_province(ws, to_prov(primary_slot)));
2784}
2785TRIGGER_FUNCTION(tf_unit_has_leader) {
2786 auto result = ve::apply([&ws](dcon::province_id p) {
2787 for(const auto ar : ws.world.province_get_army_location(p)) {
2788 if(ws.world.army_leadership_get_general(ws.world.army_get_army_leadership(ws.world.army_location_get_army(ar)))) {
2789 return true;
2790 }
2791 }
2792 return false;
2793 }, to_prov(primary_slot));
2794 return compare_to_true(tval[0], result);
2795}
2796TRIGGER_FUNCTION(tf_has_national_focus_state) {
2797 auto result = ve::apply([&ws, tval](dcon::state_instance_id p) {
2798 return ws.world.state_instance_get_owner_focus(p) == trigger::payload(tval[1]).nf_id;
2799 }, to_state(primary_slot));
2800 return compare_to_true(tval[0], result);
2801}
2802TRIGGER_FUNCTION(tf_has_national_focus_province) {
2803 auto result = ve::apply([&ws, tval](dcon::province_id p) {
2804 return ws.world.state_instance_get_owner_focus(ws.world.province_get_state_membership(p)) == trigger::payload(tval[1]).nf_id;
2805 }, to_prov(primary_slot));
2806 return compare_to_true(tval[0], result);
2807}
2808TRIGGER_FUNCTION(tf_total_amount_of_divisions) {
2809 return compare_values(tval[0], ws.world.nation_get_active_regiments(to_nation(primary_slot)), int32_t(tval[1]));
2810}
2812 return compare_values(tval[0], ws.world.nation_get_stockpiles(to_nation(primary_slot), economy::money),
2813 read_float_from_payload(tval + 1));
2814}
2815TRIGGER_FUNCTION(tf_money_province) {
2816 return compare_values(tval[0], ws.world.nation_get_stockpiles(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)), economy::money),
2817 read_float_from_payload(tval + 1));
2818}
2819TRIGGER_FUNCTION(tf_lost_national) {
2820 return compare_values(tval[0], 1.0f - ws.world.nation_get_revanchism(to_nation(primary_slot)),
2821 read_float_from_payload(tval + 1));
2822}
2823TRIGGER_FUNCTION(tf_is_vassal) {
2824 return compare_to_true(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) != dcon::nation_id());
2825}
2826TRIGGER_FUNCTION(tf_ruling_party_ideology_nation) {
2827 auto rp = ws.world.nation_get_ruling_party(to_nation(primary_slot));
2828 return compare_values_eq(tval[0], ws.world.political_party_get_ideology(rp), trigger::payload(tval[1]).ideo_id);
2829}
2830TRIGGER_FUNCTION(tf_ruling_party_ideology_pop) {
2831 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2832 auto rp = ws.world.nation_get_ruling_party(owner);
2833 return compare_values_eq(tval[0], ws.world.political_party_get_ideology(rp), trigger::payload(tval[1]).ideo_id);
2834}
2835TRIGGER_FUNCTION(tf_ruling_party_ideology_province) {
2836 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2837 auto rp = ws.world.nation_get_ruling_party(owner);
2838 return compare_values_eq(tval[0], ws.world.political_party_get_ideology(rp), trigger::payload(tval[1]).ideo_id);
2839}
2840TRIGGER_FUNCTION(tf_ruling_party) {
2841 auto rp = ws.world.nation_get_ruling_party(to_nation(primary_slot));
2842 dcon::text_key name{dcon::text_key::value_base_t(read_int32_t_from_payload(tval + 1)) };
2843 return compare_values_eq(tval[0], ws.world.political_party_get_name(rp), name);
2844}
2845TRIGGER_FUNCTION(tf_is_ideology_enabled) {
2846 return compare_to_true(tval[0], ws.world.ideology_get_enabled(trigger::payload(tval[1]).ideo_id));
2847}
2848TRIGGER_FUNCTION(tf_political_reform_want_nation) {
2849 return compare_values(tval[0],
2850 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::political_reform_desire) *
2851 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
2852 read_float_from_payload(tval + 1));
2853}
2854TRIGGER_FUNCTION(tf_political_reform_want_pop) {
2855 return compare_values(tval[0], ws.world.pop_get_political_reform_desire(to_pop(primary_slot)),
2856 read_float_from_payload(tval + 1));
2857}
2858TRIGGER_FUNCTION(tf_social_reform_want_nation) {
2859 return compare_values(tval[0],
2860 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::social_reform_desire) *
2861 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
2862 read_float_from_payload(tval + 1));
2863}
2864TRIGGER_FUNCTION(tf_social_reform_want_pop) {
2865 return compare_values(tval[0], ws.world.pop_get_social_reform_desire(to_pop(primary_slot)), read_float_from_payload(tval + 1));
2866}
2867TRIGGER_FUNCTION(tf_total_amount_of_ships) {
2868 auto result = ve::apply(
2869 [&ws](dcon::nation_id n) {
2870 int32_t total = 0;
2871 for(auto a : ws.world.nation_get_navy_control(n)) {
2872 auto memb = a.get_navy().get_navy_membership();
2873 total += int32_t(memb.end() - memb.begin());
2874 }
2875 return total;
2876 },
2877 to_nation(primary_slot));
2878 return compare_values(tval[0], result, int32_t(tval[1]));
2879}
2880TRIGGER_FUNCTION(tf_plurality) {
2881 return compare_values(tval[0], ws.world.nation_get_plurality(to_nation(primary_slot)), read_float_from_payload(tval + 1) / 100.0f);
2882}
2883TRIGGER_FUNCTION(tf_plurality_pop) {
2884 return compare_values(tval[0], ws.world.nation_get_plurality(nations::owner_of_pop(ws, to_pop(primary_slot))), read_float_from_payload(tval + 1) / 100.0f);
2885}
2886TRIGGER_FUNCTION(tf_corruption) {
2887 return compare_values(tval[0], nations::central_has_crime_fraction(ws, to_nation(primary_slot)),
2888 read_float_from_payload(tval + 1));
2889}
2890TRIGGER_FUNCTION(tf_is_state_religion_pop) {
2891 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2892 return compare_values_eq(tval[0], ws.world.nation_get_religion(owner), ws.world.pop_get_religion(to_pop(primary_slot)));
2893}
2894TRIGGER_FUNCTION(tf_is_state_religion_province) {
2895 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2896 return compare_values_eq(tval[0], ws.world.nation_get_religion(owner),
2897 ws.world.province_get_dominant_religion(to_prov(primary_slot)));
2898}
2899TRIGGER_FUNCTION(tf_is_state_religion_state) {
2900 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
2901 return compare_values_eq(tval[0], ws.world.nation_get_religion(owner),
2902 ws.world.state_instance_get_dominant_religion(to_state(primary_slot)));
2903}
2904TRIGGER_FUNCTION(tf_is_primary_culture_pop) {
2905 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2906 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(owner), ws.world.pop_get_culture(to_pop(primary_slot)));
2907}
2908TRIGGER_FUNCTION(tf_is_primary_culture_province) {
2909 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2910 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(owner),
2911 ws.world.province_get_dominant_culture(to_prov(primary_slot)));
2912}
2913TRIGGER_FUNCTION(tf_is_primary_culture_state) {
2914 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
2915 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(owner),
2916 ws.world.state_instance_get_dominant_culture(to_state(primary_slot)));
2917}
2918TRIGGER_FUNCTION(tf_primary_culture_from_nation) {
2919 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2920 ws.world.nation_get_primary_culture(to_nation(from_slot)));
2921}
2922TRIGGER_FUNCTION(tf_primary_culture_from_province) {
2923 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
2924 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2925 ws.world.nation_get_primary_culture(this_owner));
2926}
2927TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_nation) {
2928 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2929 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2930}
2931TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_pop) {
2932 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2933 ws.world.pop_get_culture(to_pop(this_slot)));
2934}
2935TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_state) {
2936 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2937 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2938 ws.world.nation_get_primary_culture(this_owner));
2939}
2940TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_province) {
2941 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2942 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2943 ws.world.nation_get_primary_culture(this_owner));
2944}
2945TRIGGER_FUNCTION(tf_is_primary_culture_state_this_nation) {
2946 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2947 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2948}
2949TRIGGER_FUNCTION(tf_is_primary_culture_state_this_pop) {
2950 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
2951 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2952 ws.world.nation_get_primary_culture(this_owner));
2953}
2954TRIGGER_FUNCTION(tf_is_primary_culture_state_this_state) {
2955 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2956 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2957 ws.world.nation_get_primary_culture(this_owner));
2958}
2959TRIGGER_FUNCTION(tf_is_primary_culture_state_this_province) {
2960 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2961 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2962 ws.world.nation_get_primary_culture(this_owner));
2963}
2964TRIGGER_FUNCTION(tf_is_primary_culture_province_this_nation) {
2965 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2966 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2967}
2968TRIGGER_FUNCTION(tf_is_primary_culture_province_this_pop) {
2969 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
2970 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2971 ws.world.nation_get_primary_culture(this_owner));
2972}
2973TRIGGER_FUNCTION(tf_is_primary_culture_province_this_state) {
2974 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2975 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2976 ws.world.nation_get_primary_culture(this_owner));
2977}
2978TRIGGER_FUNCTION(tf_is_primary_culture_province_this_province) {
2979 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2980 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2981 ws.world.nation_get_primary_culture(this_owner));
2982}
2983TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_nation) {
2984 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
2985 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2986}
2987TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_pop) {
2988 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
2989 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
2990 ws.world.nation_get_primary_culture(this_owner));
2991}
2992TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_state) {
2993 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2994 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
2995 ws.world.nation_get_primary_culture(this_owner));
2996}
2997TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_province) {
2998 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2999 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
3000 ws.world.nation_get_primary_culture(this_owner));
3001}
3002
3003template<typename N, typename C>
3005 return ve::apply(
3006 [&ws](dcon::nation_id n, dcon::culture_id c) {
3007 return ws.world.nation_get_accepted_cultures(n, c);
3008 }, nids, cids);
3009}
3010
3011TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_nation) {
3012 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(primary_slot), ws.world.nation_get_primary_culture(to_nation(this_slot))));
3013}
3014TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_pop) {
3015 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(primary_slot), ws.world.pop_get_culture(to_pop(this_slot))));
3016}
3017TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_state) {
3018 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3019 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(primary_slot), ws.world.nation_get_primary_culture(this_owner)));
3020}
3021TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_province) {
3022 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3023 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(primary_slot), ws.world.nation_get_primary_culture(this_owner)));
3024}
3025TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_nation) {
3026 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3027 ws.world.nation_get_primary_culture(to_nation(this_slot))));
3028}
3029TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_pop) {
3030 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
3031 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3032 ws.world.nation_get_primary_culture(this_owner)));
3033}
3034TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_state) {
3035 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3036 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3037 ws.world.nation_get_primary_culture(this_owner)));
3038}
3039TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_province) {
3040 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3041 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3042 ws.world.nation_get_primary_culture(this_owner)));
3043}
3044TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_nation) {
3045 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3046 ws.world.nation_get_primary_culture(to_nation(this_slot))));
3047}
3048TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_pop) {
3049 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
3050 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3051 ws.world.nation_get_primary_culture(this_owner)));
3052}
3053TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_state) {
3054 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3055 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3056 ws.world.nation_get_primary_culture(this_owner)));
3057}
3058TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_province) {
3059 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3060 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3061 ws.world.nation_get_primary_culture(this_owner)));
3062}
3063TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_nation) {
3064 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(this_slot), ws.world.pop_get_culture(to_pop(primary_slot))));
3065}
3066TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_pop) {
3067 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
3068 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, this_owner, ws.world.pop_get_culture(to_pop(primary_slot))));
3069}
3070TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_state) {
3071 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3072 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, this_owner, ws.world.pop_get_culture(to_pop(primary_slot))));
3073}
3074TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_province) {
3075 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3076 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, this_owner, ws.world.pop_get_culture(to_pop(primary_slot))));
3077}
3078
3079TRIGGER_FUNCTION(tf_is_accepted_culture_pop) {
3080 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3081 auto is_accepted = ve::apply(
3082 [&ws](dcon::nation_id n, dcon::culture_id c) {
3083 if(n)
3084 return ws.world.nation_get_accepted_cultures(n, c);
3085 else
3086 return false;
3087 },
3088 owner, ws.world.pop_get_culture(to_pop(primary_slot)));
3089 return compare_to_true(tval[0], is_accepted);
3090}
3091TRIGGER_FUNCTION(tf_is_accepted_culture_province) {
3092 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3093 auto is_accepted = ve::apply(
3094 [&ws](dcon::nation_id n, dcon::culture_id c) {
3095 if(n)
3096 return ws.world.nation_get_accepted_cultures(n, c);
3097 else
3098 return false;
3099 },
3100 owner, ws.world.province_get_dominant_culture(to_prov(primary_slot)));
3101 return compare_to_true(tval[0], is_accepted);
3102}
3103TRIGGER_FUNCTION(tf_is_accepted_culture_state) {
3104 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3105 auto is_accepted = ve::apply(
3106 [&ws](dcon::nation_id n, dcon::culture_id c) {
3107 if(n)
3108 return ws.world.nation_get_accepted_cultures(n, c);
3109 else
3110 return false;
3111 },
3112 owner, ws.world.state_instance_get_dominant_culture(to_state(primary_slot)));
3113 return compare_to_true(tval[0], is_accepted);
3114}
3115TRIGGER_FUNCTION(tf_is_coastal_province) {
3116 return compare_to_true(tval[0], ws.world.province_get_is_coast(to_prov(primary_slot)));
3117}
3118TRIGGER_FUNCTION(tf_is_coastal_state) {
3119 auto result = ve::apply(
3120 [&ws](dcon::state_instance_id s) {
3121 return province::state_is_coastal(ws, s);
3122 },
3123 to_state(primary_slot));
3124 return compare_to_true(tval[0], result);
3125}
3126TRIGGER_FUNCTION(tf_in_sphere_tag) {
3127 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)),
3128 ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id));
3129}
3130TRIGGER_FUNCTION(tf_in_sphere_from) {
3131 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), to_nation(from_slot));
3132}
3133TRIGGER_FUNCTION(tf_in_sphere_this_nation) {
3134 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), to_nation(this_slot));
3135}
3136TRIGGER_FUNCTION(tf_in_sphere_this_province) {
3137 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3138 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), owner);
3139}
3140TRIGGER_FUNCTION(tf_in_sphere_this_state) {
3141 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3142 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), owner);
3143}
3144TRIGGER_FUNCTION(tf_in_sphere_this_pop) {
3145 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3146 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), owner);
3147}
3148TRIGGER_FUNCTION(tf_produces_nation) {
3149 auto good = payload(tval[1]).com_id;
3150 return compare_to_true(tval[0], ws.world.nation_get_domestic_market_pool(to_nation(primary_slot), good) > 0.0f);
3151}
3152TRIGGER_FUNCTION(tf_produces_province) {
3153 /* return compare_to_true(tval[0],
3154 (ws.world.province_get_rgo(to_prov(primary_slot)) == payload(tval[1]).com_id) ||
3155 (ws.world.province_get_artisan_production(to_prov(primary_slot)) == payload(tval[1]).com_id)); */
3156 return compare_to_true(tval[0], ws.world.province_get_rgo(to_prov(primary_slot)) == payload(tval[1]).com_id);
3157}
3158TRIGGER_FUNCTION(tf_produces_state) {
3159 auto good = payload(tval[1]).com_id;
3160 return compare_to_true(tval[0],
3161 ve::apply(
3162 [&](dcon::state_instance_id si, dcon::nation_id o) {
3163 auto d = ws.world.state_instance_get_definition(si);
3164 for(auto p : ws.world.state_definition_get_abstract_state_membership(d)) {
3165 if(p.get_province().get_nation_from_province_ownership() == o) {
3166 if(p.get_province().get_rgo() == good)
3167 return true;
3168 //if(p.get_province().get_artisan_production() == good)
3169 // return true;
3170
3171 for(auto f : p.get_province().get_factory_location()) {
3172 if(f.get_factory().get_building_type().get_output() == good)
3173 return true;
3174 }
3175 }
3176 }
3177 return false;
3178 },
3179 to_state(primary_slot), ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot))));
3180}
3181TRIGGER_FUNCTION(tf_produces_pop) {
3182 auto pop_location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3183 auto good = payload(tval[1]).com_id;
3184
3185 /*return compare_to_true(tval[0], (ws.world.pop_get_poptype(to_pop(primary_slot)) == ws.culture_definitions.artisans) &&
3186 (ws.world.province_get_artisan_production(pop_location) == good)); */
3187
3188 //return compare_to_true(tval[0], (ws.world.pop_get_poptype(to_pop(primary_slot)).get_is_paid_rgo_worker()) && (ws.world.province_get_rgo(pop_location) == good));
3189 return compare_to_true(tval[0], false);
3190}
3191TRIGGER_FUNCTION(tf_average_militancy_nation) {
3192 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
3193 auto mil_amount = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::militancy);
3194 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3195}
3196TRIGGER_FUNCTION(tf_average_militancy_state) {
3197 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
3198 auto mil_amount = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::militancy);
3199 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3200}
3201TRIGGER_FUNCTION(tf_average_militancy_province) {
3202 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
3203 auto mil_amount = ws.world.province_get_demographics(to_prov(primary_slot), demographics::militancy);
3204 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3205}
3206TRIGGER_FUNCTION(tf_average_consciousness_nation) {
3207 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
3208 auto mil_amount = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::consciousness);
3209 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3210}
3211TRIGGER_FUNCTION(tf_average_consciousness_state) {
3212 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
3213 auto mil_amount = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::consciousness);
3214 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3215}
3216TRIGGER_FUNCTION(tf_average_consciousness_province) {
3217 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
3218 auto mil_amount = ws.world.province_get_demographics(to_prov(primary_slot), demographics::consciousness);
3219 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3220}
3221TRIGGER_FUNCTION(tf_is_next_reform_nation) {
3222 auto ref_id = payload(tval[1]).opt_id;
3223 auto prior_opt = dcon::issue_option_id(dcon::issue_option_id::value_base_t(ref_id.index() - 1));
3224 auto reform_parent = ws.world.issue_option_get_parent_issue(ref_id);
3225 auto active_option = ws.world.nation_get_issues(to_nation(primary_slot), reform_parent);
3226
3227 return compare_values_eq(tval[0], active_option, prior_opt);
3228}
3229TRIGGER_FUNCTION(tf_is_next_reform_pop) {
3230 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3231
3232 auto ref_id = payload(tval[1]).opt_id;
3233 auto prior_opt = dcon::issue_option_id(dcon::issue_option_id::value_base_t(ref_id.index() - 1));
3234 auto reform_parent = ws.world.issue_option_get_parent_issue(ref_id);
3235 auto active_option = ws.world.nation_get_issues(owner, reform_parent);
3236
3237 return compare_values_eq(tval[0], active_option, prior_opt);
3238}
3239TRIGGER_FUNCTION(tf_is_next_rreform_nation) {
3240 auto ref_id = payload(tval[1]).ropt_id;
3241 auto prior_opt = dcon::reform_option_id(dcon::reform_option_id::value_base_t(ref_id.index() - 1));
3242 auto reform_parent = ws.world.reform_option_get_parent_reform(ref_id);
3243 auto active_option = ws.world.nation_get_reforms(to_nation(primary_slot), reform_parent);
3244
3245 return compare_values_eq(tval[0], active_option, prior_opt);
3246}
3247TRIGGER_FUNCTION(tf_is_next_rreform_pop) {
3248 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3249
3250 auto ref_id = payload(tval[1]).ropt_id;
3251 auto prior_opt = dcon::reform_option_id(dcon::reform_option_id::value_base_t(ref_id.index() - 1));
3252 auto reform_parent = ws.world.reform_option_get_parent_reform(ref_id);
3253 auto active_option = ws.world.nation_get_reforms(owner, reform_parent);
3254
3255 return compare_values_eq(tval[0], active_option, prior_opt);
3256}
3257TRIGGER_FUNCTION(tf_rebel_power_fraction) {
3258 // note: virtually unused
3259 return compare_to_true(tval[0], false);
3260}
3261TRIGGER_FUNCTION(tf_recruited_percentage_nation) {
3262 auto value = ve::apply([&ws](dcon::nation_id n) { return military::recruited_pop_fraction(ws, n); }, to_nation(primary_slot));
3263 return compare_values(tval[0], value, read_float_from_payload(tval + 1));
3264}
3265TRIGGER_FUNCTION(tf_recruited_percentage_pop) {
3266 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3267 auto value = ve::apply([&ws](dcon::nation_id n) { return military::recruited_pop_fraction(ws, n); }, owner);
3268 return compare_values(tval[0], value, read_float_from_payload(tval + 1));
3269}
3270TRIGGER_FUNCTION(tf_has_culture_core) {
3271 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3272 auto culture = ws.world.pop_get_culture(to_pop(primary_slot));
3273
3274 auto result = ve::apply(
3275 [&ws](dcon::province_id p, dcon::culture_id c) {
3276 for(auto co : ws.world.province_get_core(p)) {
3277 if(co.get_identity().get_primary_culture() == c)
3278 return true;
3279 }
3280 return false;
3281 },
3282 location, culture);
3283 return compare_to_true(tval[0], result);
3284}
3285TRIGGER_FUNCTION(tf_has_culture_core_province_this_pop) {
3286 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
3287
3288 auto result = ve::apply(
3289 [&ws](dcon::province_id p, dcon::culture_id c) {
3290 for(auto co : ws.world.province_get_core(p)) {
3291 if(co.get_identity().get_primary_culture() == c)
3292 return true;
3293 }
3294 return false;
3295 },
3296 to_prov(primary_slot), culture);
3297 return compare_to_true(tval[0], result);
3298}
3299TRIGGER_FUNCTION(tf_nationalism) {
3300 return compare_values(tval[0], ws.world.province_get_nationalism(to_prov(primary_slot)), float(tval[1]));
3301}
3302TRIGGER_FUNCTION(tf_is_overseas) {
3303 return compare_to_true(tval[0], province::is_overseas(ws, to_prov(primary_slot)));
3304}
3305TRIGGER_FUNCTION(tf_is_overseas_pop) {
3306 return compare_to_true(tval[0], province::is_overseas(ws, ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))));
3307}
3308TRIGGER_FUNCTION(tf_is_overseas_state) {
3309 return compare_to_true(tval[0], province::is_overseas(ws, ws.world.state_instance_get_capital(to_state(primary_slot))));
3310}
3311TRIGGER_FUNCTION(tf_controlled_by_rebels) {
3312 return compare_to_true(tval[0],
3313 ws.world.province_get_rebel_faction_from_province_rebel_control(to_prov(primary_slot)) != dcon::rebel_faction_id());
3314}
3315TRIGGER_FUNCTION(tf_controlled_by_tag) {
3316 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3317 ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id));
3318}
3319TRIGGER_FUNCTION(tf_controlled_by_from) {
3320 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3321 to_nation(from_slot));
3322}
3323TRIGGER_FUNCTION(tf_controlled_by_this_nation) {
3324 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3325 to_nation(this_slot));
3326}
3327TRIGGER_FUNCTION(tf_controlled_by_this_province) {
3328 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3329 ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)));
3330}
3331TRIGGER_FUNCTION(tf_controlled_by_this_state) {
3332 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3333 ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot)));
3334}
3335TRIGGER_FUNCTION(tf_controlled_by_this_pop) {
3336 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3337 nations::owner_of_pop(ws, to_pop(this_slot)));
3338}
3339TRIGGER_FUNCTION(tf_controlled_by_owner) {
3340 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3341 ws.world.province_get_nation_from_province_control(to_prov(primary_slot)));
3342}
3343TRIGGER_FUNCTION(tf_controlled_by_reb) {
3344 return compare_values_eq(tval[0], ws.world.province_get_rebel_faction_from_province_rebel_control(to_prov(primary_slot)),
3345 to_rebel(from_slot));
3346}
3347TRIGGER_FUNCTION(tf_is_canal_enabled) {
3348 return compare_to_true(tval[0], (ws.world.province_adjacency_get_type(ws.province_definitions.canals[tval[1] - 1]) &
3350}
3351TRIGGER_FUNCTION(tf_is_state_capital) {
3352 auto sid = ws.world.province_get_state_membership(to_prov(primary_slot));
3353 return compare_values_eq(tval[0], ws.world.state_instance_get_capital(sid), to_prov(primary_slot));
3354}
3355TRIGGER_FUNCTION(tf_is_state_capital_pop) {
3356 auto id = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3357 auto sid = ws.world.province_get_state_membership(id);
3358 return compare_values_eq(tval[0], ws.world.state_instance_get_capital(sid), id);
3359}
3360TRIGGER_FUNCTION(tf_truce_with_tag) {
3361 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3362 auto result = ve::apply(
3363 [&ws, holder](dcon::nation_id a) {
3364 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, holder);
3365 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3366 return bool(date) && date > ws.current_date;
3367 },
3368 to_nation(primary_slot));
3369 return compare_to_true(tval[0], result);
3370}
3371TRIGGER_FUNCTION(tf_truce_with_from) {
3372 auto result = ve::apply(
3373 [&ws](dcon::nation_id a, dcon::nation_id b) {
3374 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3375 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3376 return bool(date) && date > ws.current_date;
3377 },
3378 to_nation(primary_slot), to_nation(from_slot));
3379 return compare_to_true(tval[0], result);
3380}
3381TRIGGER_FUNCTION(tf_truce_with_this_nation) {
3382 auto result = ve::apply(
3383 [&ws](dcon::nation_id a, dcon::nation_id b) {
3384 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3385 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3386 return bool(date) && date > ws.current_date;
3387 },
3388 to_nation(primary_slot), to_nation(this_slot));
3389 return compare_to_true(tval[0], result);
3390}
3391TRIGGER_FUNCTION(tf_truce_with_this_province) {
3392 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3393 auto result = ve::apply(
3394 [&ws](dcon::nation_id a, dcon::nation_id b) {
3395 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3396 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3397 return bool(date) && date > ws.current_date;
3398 },
3399 to_nation(primary_slot), owner);
3400 return compare_to_true(tval[0], result);
3401}
3402TRIGGER_FUNCTION(tf_truce_with_this_state) {
3403 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3404 auto result = ve::apply(
3405 [&ws](dcon::nation_id a, dcon::nation_id b) {
3406 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3407 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3408 return bool(date) && date > ws.current_date;
3409 },
3410 to_nation(primary_slot), owner);
3411 return compare_to_true(tval[0], result);
3412}
3413TRIGGER_FUNCTION(tf_truce_with_this_pop) {
3414 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3415 auto result = ve::apply(
3416 [&ws](dcon::nation_id a, dcon::nation_id b) {
3417 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3418 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3419 return bool(date) && date > ws.current_date;
3420 },
3421 to_nation(primary_slot), owner);
3422 return compare_to_true(tval[0], result);
3423}
3424TRIGGER_FUNCTION(tf_total_pops_nation) {
3425 return compare_values(tval[0], ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total),
3426 read_float_from_payload(tval + 1));
3427}
3428TRIGGER_FUNCTION(tf_total_pops_state) {
3429 return compare_values(tval[0], ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total),
3430 read_float_from_payload(tval + 1));
3431}
3432TRIGGER_FUNCTION(tf_total_pops_province) {
3433 return compare_values(tval[0], ws.world.province_get_demographics(to_prov(primary_slot), demographics::total),
3434 read_float_from_payload(tval + 1));
3435}
3436TRIGGER_FUNCTION(tf_total_pops_pop) {
3437 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3438 return compare_values(tval[0], ws.world.province_get_demographics(location, demographics::total),
3439 read_float_from_payload(tval + 1));
3440}
3441TRIGGER_FUNCTION(tf_has_pop_type_nation) {
3442 auto type = payload(tval[1]).popt_id;
3443 return compare_to_true(tval[0],
3444 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type)) > 0.0f);
3445}
3446TRIGGER_FUNCTION(tf_has_pop_type_state) {
3447 auto type = payload(tval[1]).popt_id;
3448 return compare_to_true(tval[0],
3449 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type)) > 0.0f);
3450}
3451TRIGGER_FUNCTION(tf_has_pop_type_province) {
3452 auto type = payload(tval[1]).popt_id;
3453 return compare_to_true(tval[0],
3454 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type)) > 0.0f);
3455}
3456TRIGGER_FUNCTION(tf_has_pop_type_pop) {
3457 auto type = payload(tval[1]).popt_id;
3458 return compare_values_eq(tval[0], ws.world.pop_get_poptype(to_pop(primary_slot)), type);
3459}
3460TRIGGER_FUNCTION(tf_has_empty_adjacent_province) {
3461 auto result = ve::apply(
3462 [&ws](dcon::province_id p) {
3463 auto acc = empty_province_accumulator(ws);
3464 for(auto a : ws.world.province_get_province_adjacency(p)) {
3465 auto other = a.get_connected_provinces(0) != p ? a.get_connected_provinces(0) : a.get_connected_provinces(1);
3466 acc.add_value(to_generic(other));
3467 if(acc.result)
3468 return true;
3469 }
3470 acc.flush();
3471 return acc.result;
3472 },
3473 to_prov(primary_slot));
3474 return compare_to_true(tval[0], result);
3475}
3476TRIGGER_FUNCTION(tf_has_leader) {
3477 dcon::unit_name_id name{ dcon::unit_name_id::value_base_t(read_int32_t_from_payload(tval + 1)) };
3478 auto result = ve::apply(
3479 [&ws, name](dcon::nation_id n) {
3480 for(auto l : ws.world.nation_get_leader_loyalty(n)) {
3481 auto lname = l.get_leader().get_name();
3482 if(ws.to_string_view(lname) == ws.to_string_view(name))
3483 return true;
3484 }
3485 return false;
3486 },
3487 to_nation(primary_slot));
3488 return compare_to_true(tval[0], result);
3489}
3491 return compare_to_false(tval[0], ws.world.nation_get_is_player_controlled(to_nation(primary_slot)));
3492}
3493TRIGGER_FUNCTION(tf_can_create_vassals) {
3494 auto result = ve::apply(
3495 [&ws](dcon::nation_id n) {
3496 for(uint32_t i = 0; i < ws.world.national_identity_size(); ++i) {
3497 dcon::national_identity_id tag{dcon::national_identity_id::value_base_t(i)};
3498 if(nations::can_release_as_vassal(ws, n, tag))
3499 return true;
3500 }
3501 return false;
3502 },
3503 to_nation(primary_slot));
3504 return compare_to_true(tval[0], result);
3505}
3506TRIGGER_FUNCTION(tf_is_possible_vassal) {
3507 auto tag = payload(tval[1]).tag_id;
3508 auto result =
3509 ve::apply([&ws, tag](dcon::nation_id n) { return nations::can_release_as_vassal(ws, n, tag); }, to_nation(primary_slot));
3510 return compare_to_true(tval[0], result);
3511}
3512TRIGGER_FUNCTION(tf_province_id) {
3513 return compare_values_eq(tval[0], to_prov(primary_slot), payload(tval[1]).prov_id);
3514}
3515TRIGGER_FUNCTION(tf_vassal_of_tag) {
3516 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3517 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3518 tag_holder);
3519}
3520TRIGGER_FUNCTION(tf_vassal_of_from) {
3521 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3522 to_nation(from_slot));
3523}
3524TRIGGER_FUNCTION(tf_vassal_of_this_nation) {
3525 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3526 to_nation(this_slot));
3527}
3528TRIGGER_FUNCTION(tf_vassal_of_this_province) {
3529 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3530 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3531 owner);
3532}
3533TRIGGER_FUNCTION(tf_vassal_of_this_state) {
3534 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3535 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3536 owner);
3537}
3538TRIGGER_FUNCTION(tf_vassal_of_this_pop) {
3539 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3540 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3541 owner);
3542}
3543TRIGGER_FUNCTION(tf_vassal_of_province_tag) {
3544 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3545 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)))),
3546 tag_holder);
3547}
3548TRIGGER_FUNCTION(tf_vassal_of_province_from) {
3549 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)))),
3550 to_nation(from_slot));
3551}
3552TRIGGER_FUNCTION(tf_vassal_of_province_this_nation) {
3553 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)))),
3554 to_nation(this_slot));
3555}
3556TRIGGER_FUNCTION(tf_vassal_of_province_this_province) {
3557 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3558 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)))),
3559 owner);
3560}
3561TRIGGER_FUNCTION(tf_vassal_of_province_this_state) {
3562 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3563 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)))),
3564 owner);
3565}
3566TRIGGER_FUNCTION(tf_vassal_of_province_this_pop) {
3567 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3568 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)))),
3569 owner);
3570}
3571
3572
3573TRIGGER_FUNCTION(tf_substate_of_tag) {
3574 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3575 return compare_to_true(tval[0],
3576 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3577 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == tag_holder));
3578}
3579TRIGGER_FUNCTION(tf_substate_of_from) {
3580 return compare_to_true(tval[0], ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3581 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(
3582 to_nation(primary_slot))) == to_nation(from_slot)));
3583}
3584TRIGGER_FUNCTION(tf_substate_of_this_nation) {
3585 return compare_to_true(tval[0], ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3586 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(
3587 to_nation(primary_slot))) == to_nation(this_slot)));
3588}
3589TRIGGER_FUNCTION(tf_substate_of_this_province) {
3590 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3591 return compare_to_true(tval[0],
3592 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3593 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == owner));
3594}
3595TRIGGER_FUNCTION(tf_substate_of_this_state) {
3596 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3597 return compare_to_true(tval[0],
3598 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3599 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == owner));
3600}
3601TRIGGER_FUNCTION(tf_substate_of_this_pop) {
3602 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3603 return compare_to_true(tval[0],
3604 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3605 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == owner));
3606}
3607TRIGGER_FUNCTION(tf_alliance_with_tag) {
3608 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3609 auto result = ve::apply(
3610 [&ws, tag_holder](dcon::nation_id n) {
3611 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, tag_holder);
3612 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3613 },
3614 to_nation(primary_slot));
3615 return compare_to_true(tval[0], result);
3616}
3617TRIGGER_FUNCTION(tf_alliance_with_from) {
3618 auto result = ve::apply(
3619 [&ws](dcon::nation_id n, dcon::nation_id m) {
3620 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3621 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3622 },
3623 to_nation(primary_slot), to_nation(from_slot));
3624 return compare_to_true(tval[0], result);
3625}
3626TRIGGER_FUNCTION(tf_alliance_with_this_nation) {
3627 auto result = ve::apply(
3628 [&ws](dcon::nation_id n, dcon::nation_id m) {
3629 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3630 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3631 },
3632 to_nation(primary_slot), to_nation(this_slot));
3633 return compare_to_true(tval[0], result);
3634}
3635TRIGGER_FUNCTION(tf_alliance_with_this_province) {
3636 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3637 auto result = ve::apply(
3638 [&ws](dcon::nation_id n, dcon::nation_id m) {
3639 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3640 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3641 },
3642 to_nation(primary_slot), owner);
3643 return compare_to_true(tval[0], result);
3644}
3645TRIGGER_FUNCTION(tf_alliance_with_this_state) {
3646 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3647 auto result = ve::apply(
3648 [&ws](dcon::nation_id n, dcon::nation_id m) {
3649 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3650 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3651 },
3652 to_nation(primary_slot), owner);
3653 return compare_to_true(tval[0], result);
3654}
3655TRIGGER_FUNCTION(tf_alliance_with_this_pop) {
3656 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3657 auto result = ve::apply(
3658 [&ws](dcon::nation_id n, dcon::nation_id m) {
3659 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3660 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3661 },
3662 to_nation(primary_slot), owner);
3663 return compare_to_true(tval[0], result);
3664}
3665TRIGGER_FUNCTION(tf_has_recently_lost_war) {
3666 return compare_to_true(tval[0], ve::apply(
3667 [&](dcon::nation_id n) {
3668 auto d = ws.world.nation_get_last_war_loss(n);
3669 return bool(d) && ws.current_date <= (d + 365 * 5);
3670 }, to_nation(primary_slot)));
3671}
3672TRIGGER_FUNCTION(tf_has_recently_lost_war_pop) {
3673 return compare_to_true(tval[0], ve::apply(
3674 [&](dcon::nation_id n) {
3675 auto d = ws.world.nation_get_last_war_loss(n);
3676 return bool(d) && ws.current_date <= (d + 365 * 5);
3677 }, nations::owner_of_pop(ws, to_pop(primary_slot))));
3678}
3679TRIGGER_FUNCTION(tf_is_mobilised) {
3680 return compare_to_true(tval[0], ws.world.nation_get_is_mobilized(to_nation(primary_slot)));
3681}
3682TRIGGER_FUNCTION(tf_mobilisation_size) {
3683 return compare_values(tval[0],
3684 ws.world.nation_get_modifier_values(to_nation(primary_slot), sys::national_mod_offsets::mobilization_size),
3685 read_float_from_payload(tval + 1));
3686}
3687TRIGGER_FUNCTION(tf_crime_higher_than_education_nation) {
3688 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(to_nation(primary_slot)) >=
3689 ws.world.nation_get_education_spending(to_nation(primary_slot)));
3690}
3691TRIGGER_FUNCTION(tf_crime_higher_than_education_state) {
3692 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3693 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(owner) >= ws.world.nation_get_education_spending(owner));
3694}
3695TRIGGER_FUNCTION(tf_crime_higher_than_education_province) {
3696 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3697 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(owner) >= ws.world.nation_get_education_spending(owner));
3698}
3699TRIGGER_FUNCTION(tf_crime_higher_than_education_pop) {
3700 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3701 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(owner) >= ws.world.nation_get_education_spending(owner));
3702}
3703TRIGGER_FUNCTION(tf_agree_with_ruling_party) {
3704 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3705 auto ruling_ideology = ws.world.political_party_get_ideology(ws.world.nation_get_ruling_party(owner));
3706 auto population_size = ws.world.pop_get_size(to_pop(primary_slot));
3707 auto ruling_support = ve::apply(
3708 [&](dcon::pop_id p, dcon::ideology_id i) {
3709 if(i)
3710 return ws.world.pop_get_demographics(p, pop_demographics::to_key(ws, i));
3711 else
3712 return 0.0f;
3713 },
3714 to_pop(primary_slot), ruling_ideology);
3715 return compare_values(tval[0], ve::select(population_size > 0.0f, ruling_support / population_size, 0.0f),
3716 read_float_from_payload(tval + 1));
3717}
3718TRIGGER_FUNCTION(tf_is_colonial_state) {
3719 auto cap_p = ws.world.state_instance_get_capital(to_state(primary_slot));
3720 return compare_to_true(tval[0], ws.world.province_get_is_colonial(cap_p));
3721}
3722TRIGGER_FUNCTION(tf_is_colonial_province) {
3723 return compare_to_true(tval[0], ws.world.province_get_is_colonial(to_prov(primary_slot)));
3724}
3725TRIGGER_FUNCTION(tf_is_colonial_pop) {
3726 return compare_to_true(tval[0], ws.world.province_get_is_colonial(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))));
3727}
3728TRIGGER_FUNCTION(tf_has_factories_state) {
3729 auto result = ve::apply(
3730 [&ws](dcon::state_instance_id s) { return economy::has_factory(ws, s); },
3731 to_state(primary_slot));
3732 return compare_to_true(tval[0], result);
3733}
3734TRIGGER_FUNCTION(tf_has_factories_nation) {
3735 auto result = ve::apply(
3736 [&ws](dcon::nation_id n) {
3737 for(auto p : ws.world.nation_get_province_ownership(n)) {
3738 auto rng = p.get_province().get_factory_location();
3739 if(rng.begin() != rng.end())
3740 return true;
3741 }
3742 return false;
3743 },
3744 to_nation(primary_slot));
3745 return compare_to_true(tval[0], result);
3746}
3747TRIGGER_FUNCTION(tf_in_default_bool) {
3748 return compare_to_true(tval[0], ws.world.nation_get_is_bankrupt(to_nation(primary_slot)));
3749}
3750TRIGGER_FUNCTION(tf_in_default_tag) {
3751 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3752 return compare_to_true(tval[0],
3753 ve::apply([&ws, holder](dcon::nation_id n) { return economy::is_bankrupt_debtor_to(ws, n, holder); },
3754 to_nation(primary_slot)));
3755}
3756TRIGGER_FUNCTION(tf_in_default_from) {
3757 return compare_to_true(tval[0],
3758 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3759 to_nation(primary_slot), to_nation(from_slot)));
3760}
3761TRIGGER_FUNCTION(tf_in_default_this_nation) {
3762 return compare_to_true(tval[0],
3763 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3764 to_nation(primary_slot), to_nation(this_slot)));
3765}
3766TRIGGER_FUNCTION(tf_in_default_this_province) {
3767 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3768 return compare_to_true(tval[0],
3769 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3770 to_nation(primary_slot), owner));
3771}
3772TRIGGER_FUNCTION(tf_in_default_this_state) {
3773 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3774 return compare_to_true(tval[0],
3775 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3776 to_nation(primary_slot), owner));
3777}
3778TRIGGER_FUNCTION(tf_in_default_this_pop) {
3779 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3780 return compare_to_true(tval[0],
3781 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3782 to_nation(primary_slot), owner));
3783}
3784TRIGGER_FUNCTION(tf_total_num_of_ports) {
3785 return compare_values(tval[0], ws.world.nation_get_total_ports(to_nation(primary_slot)), tval[1]);
3786}
3788 return compare_to_true(tval[0], true);
3789}
3790TRIGGER_FUNCTION(tf_election) {
3791 return compare_to_true(tval[0], ve::apply(
3792 [&ws](dcon::nation_id n) {
3793 auto d = ws.world.nation_get_election_ends(n);
3794 return bool(d) && d > ws.current_date;
3795 }, to_nation(primary_slot)));
3796}
3797TRIGGER_FUNCTION(tf_has_global_flag) {
3798 return compare_to_true(tval[0], ws.national_definitions.is_global_flag_variable_set(payload(tval[1]).glob_id));
3799}
3800TRIGGER_FUNCTION(tf_is_capital) {
3801 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3802 return compare_values_eq(tval[0], ws.world.nation_get_capital(owner), to_prov(primary_slot));
3803}
3804TRIGGER_FUNCTION(tf_nationalvalue_nation) {
3805 return compare_values_eq(tval[0], ws.world.nation_get_national_value(to_nation(primary_slot)), payload(tval[1]).mod_id);
3806}
3807TRIGGER_FUNCTION(tf_nationalvalue_pop) {
3808 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3809 return compare_values_eq(tval[0], ws.world.nation_get_national_value(owner), payload(tval[1]).mod_id);
3810}
3811TRIGGER_FUNCTION(tf_nationalvalue_province) {
3812 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3813 return compare_values_eq(tval[0], ws.world.nation_get_national_value(owner), payload(tval[1]).mod_id);
3814}
3815TRIGGER_FUNCTION(tf_industrial_score_value) {
3816 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)), tval[1]);
3817}
3818TRIGGER_FUNCTION(tf_industrial_score_tag) {
3819 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3820 ws.world.nation_get_industrial_score(ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id)));
3821}
3822TRIGGER_FUNCTION(tf_industrial_score_from_nation) {
3823 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3824 ws.world.nation_get_industrial_score(to_nation(from_slot)));
3825}
3826TRIGGER_FUNCTION(tf_industrial_score_this_nation) {
3827 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3828 ws.world.nation_get_industrial_score(to_nation(this_slot)));
3829}
3830TRIGGER_FUNCTION(tf_industrial_score_this_pop) {
3831 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3832 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3833 ws.world.nation_get_industrial_score(owner));
3834}
3835TRIGGER_FUNCTION(tf_industrial_score_this_state) {
3836 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3837 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3838 ws.world.nation_get_industrial_score(owner));
3839}
3840TRIGGER_FUNCTION(tf_industrial_score_this_province) {
3841 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3842 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3843 ws.world.nation_get_industrial_score(owner));
3844}
3845TRIGGER_FUNCTION(tf_military_score_value) {
3846 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)), tval[1]);
3847}
3848TRIGGER_FUNCTION(tf_military_score_tag) {
3849 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3850 ws.world.nation_get_military_score(ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id)));
3851}
3852TRIGGER_FUNCTION(tf_military_score_from_nation) {
3853 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3854 ws.world.nation_get_military_score(to_nation(from_slot)));
3855}
3856TRIGGER_FUNCTION(tf_military_score_this_nation) {
3857 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3858 ws.world.nation_get_military_score(to_nation(this_slot)));
3859}
3860TRIGGER_FUNCTION(tf_military_score_this_pop) {
3861 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3862 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3863 ws.world.nation_get_military_score(owner));
3864}
3865TRIGGER_FUNCTION(tf_military_score_this_state) {
3866 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3867 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3868 ws.world.nation_get_military_score(owner));
3869}
3870TRIGGER_FUNCTION(tf_military_score_this_province) {
3871 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3872 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3873 ws.world.nation_get_military_score(owner));
3874}
3875TRIGGER_FUNCTION(tf_civilized_nation) {
3876 return compare_to_true(tval[0], ws.world.nation_get_is_civilized(to_nation(primary_slot)));
3877}
3878TRIGGER_FUNCTION(tf_civilized_pop) {
3879 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3880 return compare_to_true(tval[0], ws.world.nation_get_is_civilized(owner));
3881}
3882TRIGGER_FUNCTION(tf_civilized_province) {
3883 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3884 return compare_to_true(tval[0], ws.world.nation_get_is_civilized(owner));
3885}
3886TRIGGER_FUNCTION(tf_national_provinces_occupied) {
3887 return compare_values(tval[0], nations::occupied_provinces_fraction(ws, to_nation(primary_slot)),
3888 read_float_from_payload(tval + 1));
3889}
3890TRIGGER_FUNCTION(tf_is_greater_power_nation) {
3891 return compare_to_true(tval[0], ws.world.nation_get_is_great_power(to_nation(primary_slot)));
3892}
3893TRIGGER_FUNCTION(tf_is_greater_power_pop) {
3894 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3895 return compare_to_true(tval[0], ws.world.nation_get_is_great_power(owner));
3896}
3897TRIGGER_FUNCTION(tf_is_greater_power_province) {
3898 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3899 return compare_to_true(tval[0], ws.world.nation_get_is_great_power(owner));
3900}
3901TRIGGER_FUNCTION(tf_rich_tax) {
3902 return compare_values(tval[0], ws.world.nation_get_rich_tax(to_nation(primary_slot)), payload(tval[1]).signed_value);
3903}
3904TRIGGER_FUNCTION(tf_middle_tax) {
3905 return compare_values(tval[0], ws.world.nation_get_middle_tax(to_nation(primary_slot)), payload(tval[1]).signed_value);
3906}
3907TRIGGER_FUNCTION(tf_poor_tax) {
3908 return compare_values(tval[0], ws.world.nation_get_poor_tax(to_nation(primary_slot)), payload(tval[1]).signed_value);
3909}
3910TRIGGER_FUNCTION(tf_rich_tax_pop) {
3911 return compare_values(tval[0], ws.world.nation_get_rich_tax(nations::owner_of_pop(ws, to_pop(primary_slot))), payload(tval[1]).signed_value);
3912}
3913TRIGGER_FUNCTION(tf_middle_tax_pop) {
3914 return compare_values(tval[0], ws.world.nation_get_middle_tax(nations::owner_of_pop(ws, to_pop(primary_slot))), payload(tval[1]).signed_value);
3915}
3916TRIGGER_FUNCTION(tf_poor_tax_pop) {
3917 return compare_values(tval[0], ws.world.nation_get_poor_tax(nations::owner_of_pop(ws, to_pop(primary_slot))), payload(tval[1]).signed_value);
3918}
3919TRIGGER_FUNCTION(tf_social_spending_nation) {
3920 return compare_values(tval[0], ve::to_float(ws.world.nation_get_social_spending(to_nation(primary_slot))) * ws.world.nation_get_spending_level(to_nation(primary_slot)), float(payload(tval[1]).signed_value));
3921}
3922TRIGGER_FUNCTION(tf_social_spending_pop) {
3923 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3924 return compare_values(tval[0], ve::to_float(ws.world.nation_get_social_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3925}
3926TRIGGER_FUNCTION(tf_social_spending_province) {
3927 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3928 return compare_values(tval[0], ve::to_float(ws.world.nation_get_social_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3929}
3930TRIGGER_FUNCTION(tf_military_spending_nation) {
3931 return compare_values(tval[0], ve::to_float(ws.world.nation_get_military_spending(to_nation(primary_slot))) * ws.world.nation_get_spending_level(to_nation(primary_slot)), float(payload(tval[1]).signed_value));
3932}
3933TRIGGER_FUNCTION(tf_military_spending_pop) {
3934 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3935 return compare_values(tval[0], ve::to_float(ws.world.nation_get_military_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3936}
3937TRIGGER_FUNCTION(tf_military_spending_province) {
3938 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3939 return compare_values(tval[0], ve::to_float(ws.world.nation_get_military_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3940}
3941TRIGGER_FUNCTION(tf_military_spending_state) {
3942 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3943 return compare_values(tval[0], ve::to_float(ws.world.nation_get_military_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3944}
3945TRIGGER_FUNCTION(tf_administration_spending_nation) {
3946 return compare_values(tval[0], ve::to_float(ws.world.nation_get_administrative_spending(to_nation(primary_slot))) * ws.world.nation_get_spending_level(to_nation(primary_slot)), float(payload(tval[1]).signed_value));
3947}
3948TRIGGER_FUNCTION(tf_administration_spending_pop) {
3949 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3950 return compare_values(tval[0], ve::to_float(ws.world.nation_get_administrative_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3951}
3952TRIGGER_FUNCTION(tf_administration_spending_province) {
3953 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3954 return compare_values(tval[0], ve::to_float(ws.world.nation_get_administrative_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3955}
3956TRIGGER_FUNCTION(tf_administration_spending_state) {
3957 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3958 return compare_values(tval[0], ve::to_float(ws.world.nation_get_administrative_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3959}
3960TRIGGER_FUNCTION(tf_education_spending_nation) {
3961 return compare_values(tval[0], ve::to_float(ws.world.nation_get_education_spending(to_nation(primary_slot))) * ws.world.nation_get_spending_level(to_nation(primary_slot)), float(payload(tval[1]).signed_value));
3962}
3963TRIGGER_FUNCTION(tf_education_spending_pop) {
3964 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3965 return compare_values(tval[0], ve::to_float(ws.world.nation_get_education_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3966}
3967TRIGGER_FUNCTION(tf_education_spending_province) {
3968 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3969 return compare_values(tval[0], ve::to_float(ws.world.nation_get_education_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3970}
3971TRIGGER_FUNCTION(tf_education_spending_state) {
3972 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3973 return compare_values(tval[0], ve::to_float(ws.world.nation_get_education_spending(owner)) * ws.world.nation_get_spending_level(owner), float(payload(tval[1]).signed_value));
3974}
3975TRIGGER_FUNCTION(tf_colonial_nation) {
3976 return compare_to_true(tval[0], ws.world.nation_get_is_colonial_nation(to_nation(primary_slot)));
3977}
3978TRIGGER_FUNCTION(tf_pop_majority_religion_nation) {
3979 return compare_values_eq(tval[0], ws.world.nation_get_dominant_religion(to_nation(primary_slot)), payload(tval[1]).rel_id);
3980}
3981TRIGGER_FUNCTION(tf_pop_majority_religion_nation_this_nation) {
3982 return compare_values_eq(tval[0], ws.world.nation_get_dominant_religion(to_nation(primary_slot)), ws.world.nation_get_religion(to_nation(this_slot)));
3983}
3984TRIGGER_FUNCTION(tf_pop_majority_religion_state) {
3985 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_religion(to_state(primary_slot)),
3986 payload(tval[1]).rel_id);
3987}
3988TRIGGER_FUNCTION(tf_pop_majority_religion_province) {
3989 return compare_values_eq(tval[0], ws.world.province_get_dominant_religion(to_prov(primary_slot)), payload(tval[1]).rel_id);
3990}
3991TRIGGER_FUNCTION(tf_pop_majority_culture_nation) {
3992 return compare_values_eq(tval[0], ws.world.nation_get_dominant_culture(to_nation(primary_slot)), payload(tval[1]).cul_id);
3993}
3994TRIGGER_FUNCTION(tf_pop_majority_culture_state) {
3995 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
3996 payload(tval[1]).cul_id);
3997}
3998TRIGGER_FUNCTION(tf_pop_majority_culture_province) {
3999 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)), payload(tval[1]).cul_id);
4000}
4001TRIGGER_FUNCTION(tf_pop_majority_issue_nation) {
4002 return compare_values_eq(tval[0], ws.world.nation_get_dominant_issue_option(to_nation(primary_slot)), payload(tval[1]).opt_id);
4003}
4004TRIGGER_FUNCTION(tf_pop_majority_issue_state) {
4005 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_issue_option(to_state(primary_slot)),
4006 payload(tval[1]).opt_id);
4007}
4008TRIGGER_FUNCTION(tf_pop_majority_issue_province) {
4009 return compare_values_eq(tval[0], ws.world.province_get_dominant_issue_option(to_prov(primary_slot)), payload(tval[1]).opt_id);
4010}
4011TRIGGER_FUNCTION(tf_pop_majority_issue_pop) {
4012 return compare_values_eq(tval[0], ws.world.pop_get_dominant_issue_option(to_pop(primary_slot)), payload(tval[1]).opt_id);
4013}
4014TRIGGER_FUNCTION(tf_pop_majority_ideology_nation) {
4015 return compare_values_eq(tval[0], ws.world.nation_get_dominant_ideology(to_nation(primary_slot)), payload(tval[1]).ideo_id);
4016}
4017TRIGGER_FUNCTION(tf_pop_majority_ideology_state) {
4018 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_ideology(to_state(primary_slot)),
4019 payload(tval[1]).ideo_id);
4020}
4021TRIGGER_FUNCTION(tf_pop_majority_ideology_province) {
4022 return compare_values_eq(tval[0], ws.world.province_get_dominant_ideology(to_prov(primary_slot)), payload(tval[1]).ideo_id);
4023}
4024TRIGGER_FUNCTION(tf_pop_majority_ideology_pop) {
4025 return compare_values_eq(tval[0], ws.world.pop_get_dominant_ideology(to_pop(primary_slot)), payload(tval[1]).ideo_id);
4026}
4027TRIGGER_FUNCTION(tf_poor_strata_militancy_nation) {
4028 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
4029 return compare_values(tval[0],
4030 ve::select(accumulator > 0.0f,
4031 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_militancy) / accumulator, 0.0f),
4032 read_float_from_payload(tval + 1));
4033}
4034TRIGGER_FUNCTION(tf_poor_strata_militancy_state) {
4035 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
4036 return compare_values(tval[0],
4037 ve::select(accumulator > 0.0f,
4038 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_militancy) / accumulator, 0.0f),
4039 read_float_from_payload(tval + 1));
4040}
4041TRIGGER_FUNCTION(tf_poor_strata_militancy_province) {
4042 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
4043 return compare_values(tval[0],
4044 ve::select(accumulator > 0.0f,
4045 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_militancy) / accumulator, 0.0f),
4046 read_float_from_payload(tval + 1));
4047}
4048TRIGGER_FUNCTION(tf_poor_strata_militancy_pop) {
4049 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
4050 auto is_poor = ws.world.pop_type_get_strata(type) == uint8_t(culture::pop_strata::poor);
4051 return compare_values(tval[0], ve::select(is_poor, ws.world.pop_get_militancy(to_pop(primary_slot)), 0.0f),
4052 read_float_from_payload(tval + 1));
4053}
4054TRIGGER_FUNCTION(tf_middle_strata_militancy_nation) {
4055 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4056 return compare_values(tval[0],
4057 ve::select(accumulator > 0.0f,
4058 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_militancy) / accumulator, 0.0f),
4059 read_float_from_payload(tval + 1));
4060}
4061TRIGGER_FUNCTION(tf_middle_strata_militancy_state) {
4062 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4063 return compare_values(tval[0],
4064 ve::select(accumulator > 0.0f,
4065 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_militancy) / accumulator, 0.0f),
4066 read_float_from_payload(tval + 1));
4067}
4068TRIGGER_FUNCTION(tf_middle_strata_militancy_province) {
4069 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4070 return compare_values(tval[0],
4071 ve::select(accumulator > 0.0f,
4072 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_militancy) / accumulator, 0.0f),
4073 read_float_from_payload(tval + 1));
4074}
4075TRIGGER_FUNCTION(tf_middle_strata_militancy_pop) {
4076 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
4077 auto is_middle = ws.world.pop_type_get_strata(type) == uint8_t(culture::pop_strata::middle);
4078 return compare_values(tval[0], ve::select(is_middle, ws.world.pop_get_militancy(to_pop(primary_slot)), 0.0f),
4079 read_float_from_payload(tval + 1));
4080}
4081TRIGGER_FUNCTION(tf_rich_strata_militancy_nation) {
4082 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4083 return compare_values(tval[0],
4084 ve::select(accumulator > 0.0f,
4085 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_militancy) / accumulator, 0.0f),
4086 read_float_from_payload(tval + 1));
4087}
4088TRIGGER_FUNCTION(tf_rich_strata_militancy_state) {
4089 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4090 return compare_values(tval[0],
4091 ve::select(accumulator > 0.0f,
4092 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_militancy) / accumulator, 0.0f),
4093 read_float_from_payload(tval + 1));
4094}
4095TRIGGER_FUNCTION(tf_rich_strata_militancy_province) {
4096 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4097 return compare_values(tval[0],
4098 ve::select(accumulator > 0.0f,
4099 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_militancy) / accumulator, 0.0f),
4100 read_float_from_payload(tval + 1));
4101}
4102TRIGGER_FUNCTION(tf_rich_strata_militancy_pop) {
4103 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
4104 auto is_rich = ws.world.pop_type_get_strata(type) == uint8_t(culture::pop_strata::rich);
4105 return compare_values(tval[0], ve::select(is_rich, ws.world.pop_get_militancy(to_pop(primary_slot)), 0.0f),
4106 read_float_from_payload(tval + 1));
4107}
4108TRIGGER_FUNCTION(tf_rich_tax_above_poor) {
4109 return compare_to_true(tval[0],
4110 ws.world.nation_get_rich_tax(to_nation(primary_slot)) > ws.world.nation_get_poor_tax(to_nation(primary_slot)));
4111}
4112TRIGGER_FUNCTION(tf_culture_has_union_tag_pop) {
4113 auto pop_culture = ws.world.pop_get_culture(to_pop(primary_slot));
4114 auto cg = ws.world.culture_get_group_from_culture_group_membership(pop_culture);
4115 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4116 return compare_to_true(tval[0], utag != dcon::national_identity_id());
4117}
4118TRIGGER_FUNCTION(tf_culture_has_union_tag_nation) {
4119 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4120 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4121 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4122 return compare_to_true(tval[0], utag != dcon::national_identity_id());
4123}
4124TRIGGER_FUNCTION(tf_this_culture_union_tag) {
4125 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4126 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4127 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4128 return compare_values_eq(tval[0], utag, payload(tval[1]).tag_id);
4129}
4130TRIGGER_FUNCTION(tf_this_culture_union_from) {
4131 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4132 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4133 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4134 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot)));
4135}
4136TRIGGER_FUNCTION(tf_this_culture_union_this_nation) {
4137 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4138 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4139 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4140 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot)));
4141}
4142TRIGGER_FUNCTION(tf_this_culture_union_this_province) {
4143 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4144 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4145 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4146 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4147 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(owner));
4148}
4149TRIGGER_FUNCTION(tf_this_culture_union_this_state) {
4150 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4151 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4152 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4153 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4154 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(owner));
4155}
4156TRIGGER_FUNCTION(tf_this_culture_union_this_pop) {
4157 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4158 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4159 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4160 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4161 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(owner));
4162}
4163TRIGGER_FUNCTION(tf_this_culture_union_this_union_nation) {
4164 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4165 auto this_culture = ws.world.nation_get_primary_culture(to_nation(this_slot));
4166 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4167 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4168 return compare_values_eq(tval[0], pcg, tcg);
4169}
4170TRIGGER_FUNCTION(tf_this_culture_union_this_union_province) {
4171 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4172 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4173 auto this_culture = ws.world.nation_get_primary_culture(owner);
4174 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4175 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4176 return compare_values_eq(tval[0], pcg, tcg);
4177}
4178TRIGGER_FUNCTION(tf_this_culture_union_this_union_state) {
4179 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4180 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4181 auto this_culture = ws.world.nation_get_primary_culture(owner);
4182 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4183 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4184 return compare_values_eq(tval[0], pcg, tcg);
4185}
4186TRIGGER_FUNCTION(tf_this_culture_union_this_union_pop) {
4187 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4188 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4189 auto this_culture = ws.world.nation_get_primary_culture(owner);
4190 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4191 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4192 return compare_values_eq(tval[0], pcg, tcg);
4193}
4194TRIGGER_FUNCTION(tf_minorities_nation) {
4195 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4196 auto pculture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4197
4198 auto accepted_pop = ve::apply(
4199 [&ws](dcon::nation_id n, dcon::culture_id pc) {
4200 if(!pc)
4201 return 0.0f;
4202 auto accumulated = ws.world.nation_get_demographics(n, demographics::to_key(ws, pc));
4203 for(auto ac : ws.world.in_culture) {
4204 if(ws.world.nation_get_accepted_cultures(n, ac)) {
4205 accumulated += ws.world.nation_get_demographics(n, demographics::to_key(ws, ac));
4206 }
4207 }
4208 return accumulated;
4209 },
4210 to_nation(primary_slot), pculture);
4211
4212 return compare_to_true(tval[0], total_pop != accepted_pop);
4213}
4214TRIGGER_FUNCTION(tf_minorities_state) {
4215 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4216 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
4217 auto pculture = ws.world.nation_get_primary_culture(owner);
4218
4219 auto accepted_pop = ve::apply(
4220 [&ws](dcon::state_instance_id i, dcon::nation_id n, dcon::culture_id pc) {
4221 if(!pc)
4222 return 0.0f;
4223 auto accumulated = ws.world.state_instance_get_demographics(i, demographics::to_key(ws, pc));
4224 for(auto ac : ws.world.in_culture) {
4225 if(ws.world.nation_get_accepted_cultures(n, ac)) {
4226 accumulated += ws.world.state_instance_get_demographics(i, demographics::to_key(ws, ac));
4227 }
4228 }
4229 return accumulated;
4230 },
4231 to_state(primary_slot), owner, pculture);
4232
4233 return compare_to_true(tval[0], total_pop != accepted_pop);
4234}
4235TRIGGER_FUNCTION(tf_minorities_province) {
4236 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4237 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
4238 auto pculture = ws.world.nation_get_primary_culture(owner);
4239
4240 auto accepted_pop = ve::apply(
4241 [&ws](dcon::province_id i, dcon::nation_id n, dcon::culture_id pc) {
4242 if(!pc)
4243 return 0.0f;
4244 auto accumulated = ws.world.province_get_demographics(i, demographics::to_key(ws, pc));
4245 for(auto ac : ws.world.in_culture) {
4246 if(ws.world.nation_get_accepted_cultures(n, ac)) {
4247 accumulated += ws.world.province_get_demographics(i, demographics::to_key(ws, ac));
4248 }
4249 }
4250 return accumulated;
4251 },
4252 to_prov(primary_slot), owner, pculture);
4253
4254 return compare_to_true(tval[0], total_pop != accepted_pop);
4255}
4256TRIGGER_FUNCTION(tf_revanchism_nation) {
4257 return compare_values(tval[0], ws.world.nation_get_revanchism(to_nation(primary_slot)), read_float_from_payload(tval + 1));
4258}
4259TRIGGER_FUNCTION(tf_revanchism_pop) {
4260 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
4261 return compare_values(tval[0], ws.world.nation_get_revanchism(owner), read_float_from_payload(tval + 1));
4262}
4263TRIGGER_FUNCTION(tf_has_crime) {
4264 return compare_to_true(tval[0], ws.world.province_get_crime(to_prov(primary_slot)) != dcon::crime_id());
4265}
4266TRIGGER_FUNCTION(tf_num_of_substates) {
4267 return compare_values(tval[0], ws.world.nation_get_substates_count(to_nation(primary_slot)), tval[1]);
4268}
4269TRIGGER_FUNCTION(tf_num_of_vassals_no_substates) {
4270 return compare_values(tval[0],
4271 ws.world.nation_get_vassals_count(to_nation(primary_slot)) - ws.world.nation_get_substates_count(to_nation(primary_slot)),
4272 tval[1]);
4273}
4274TRIGGER_FUNCTION(tf_brigades_compare_this) {
4275 return compare_values(tval[0], ve::select(ws.world.nation_get_active_regiments(to_nation(this_slot)) != 0, ve::to_float(ws.world.nation_get_active_regiments(to_nation(primary_slot))) / ve::to_float(ws.world.nation_get_active_regiments(to_nation(this_slot))), 1'000'000.0f), read_float_from_payload(tval + 1));
4276}
4277TRIGGER_FUNCTION(tf_brigades_compare_from) {
4278 return compare_values(tval[0], ve::select(ws.world.nation_get_active_regiments(to_nation(from_slot)) != 0, ve::to_float(ws.world.nation_get_active_regiments(to_nation(primary_slot))) / ve::to_float(ws.world.nation_get_active_regiments(to_nation(from_slot))), 1'000'000.0f), read_float_from_payload(tval + 1));
4279}
4280TRIGGER_FUNCTION(tf_brigades_compare_province_this) {
4281 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
4282 return compare_values(tval[0], ve::select(ws.world.nation_get_active_regiments(to_nation(this_slot)) != 0, ve::to_float(ws.world.nation_get_active_regiments(owner)) / ve::to_float(ws.world.nation_get_active_regiments(to_nation(this_slot))), 1'000'000.0f), read_float_from_payload(tval + 1));
4283}
4284TRIGGER_FUNCTION(tf_brigades_compare_province_from) {
4285 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
4286 return compare_values(tval[0], ve::select(ws.world.nation_get_active_regiments(to_nation(from_slot)) != 0, ve::to_float(ws.world.nation_get_active_regiments(owner)) / ve::to_float(ws.world.nation_get_active_regiments(to_nation(from_slot))), 1'000'000.0f), read_float_from_payload(tval + 1));
4287}
4288TRIGGER_FUNCTION(tf_constructing_cb_tag) {
4289 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4290 return compare_to_true(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)) == tag_holder);
4291}
4292TRIGGER_FUNCTION(tf_constructing_cb_from) {
4293 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), to_nation(from_slot));
4294}
4295TRIGGER_FUNCTION(tf_constructing_cb_this_nation) {
4296 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), to_nation(this_slot));
4297}
4298TRIGGER_FUNCTION(tf_constructing_cb_this_province) {
4299 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4300 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), owner);
4301}
4302TRIGGER_FUNCTION(tf_constructing_cb_this_state) {
4303 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4304 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), owner);
4305}
4306TRIGGER_FUNCTION(tf_constructing_cb_this_pop) {
4307 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4308 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), owner);
4309}
4310TRIGGER_FUNCTION(tf_constructing_cb_discovered) {
4311 return compare_to_true(tval[0], ws.world.nation_get_constructing_cb_is_discovered(to_nation(primary_slot)));
4312}
4313TRIGGER_FUNCTION(tf_constructing_cb_progress) {
4314 return compare_values(tval[0], ws.world.nation_get_constructing_cb_progress(to_nation(primary_slot)),
4315 read_float_from_payload(tval + 1));
4316}
4317TRIGGER_FUNCTION(tf_civilization_progress) {
4318 return compare_values(tval[0],
4319 ws.world.nation_get_modifier_values(to_nation(primary_slot), sys::national_mod_offsets::civilization_progress_modifier),
4320 read_float_from_payload(tval + 1));
4321}
4322TRIGGER_FUNCTION(tf_constructing_cb_type) {
4323 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_type(to_nation(primary_slot)), payload(tval[1]).cb_id);
4324}
4325TRIGGER_FUNCTION(tf_is_our_vassal_tag) {
4326 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4327 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(tag_holder)),
4328 to_nation(primary_slot));
4329}
4330TRIGGER_FUNCTION(tf_is_our_vassal_from) {
4331 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(from_slot))),
4332 to_nation(primary_slot));
4333}
4334TRIGGER_FUNCTION(tf_is_our_vassal_this_nation) {
4335 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(this_slot))),
4336 to_nation(primary_slot));
4337}
4338TRIGGER_FUNCTION(tf_is_our_vassal_this_province) {
4339 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4340 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4341 to_nation(primary_slot));
4342}
4343TRIGGER_FUNCTION(tf_is_our_vassal_this_state) {
4344 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4345 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4346 to_nation(primary_slot));
4347}
4348TRIGGER_FUNCTION(tf_is_our_vassal_this_pop) {
4349 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4350 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4351 to_nation(primary_slot));
4352}
4353
4354TRIGGER_FUNCTION(tf_is_our_vassal_province_tag) {
4355 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4356 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(tag_holder)),
4357 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4358}
4359TRIGGER_FUNCTION(tf_is_our_vassal_province_from) {
4360 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(from_slot))),
4361 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4362}
4363TRIGGER_FUNCTION(tf_is_our_vassal_province_this_nation) {
4364 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(this_slot))),
4365 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4366}
4367TRIGGER_FUNCTION(tf_is_our_vassal_province_this_province) {
4368 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4369 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4370 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4371}
4372TRIGGER_FUNCTION(tf_is_our_vassal_province_this_state) {
4373 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4374 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4375 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4376}
4377TRIGGER_FUNCTION(tf_is_our_vassal_province_this_pop) {
4378 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4379 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4380 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4381}
4382
4383
4384TRIGGER_FUNCTION(tf_is_substate) {
4385 return compare_to_true(tval[0], ws.world.nation_get_is_substate(to_nation(primary_slot)));
4386}
4387TRIGGER_FUNCTION(tf_great_wars_enabled) {
4388 return compare_to_true(tval[0], ws.military_definitions.great_wars_enabled);
4389}
4390TRIGGER_FUNCTION(tf_can_nationalize) {
4391 auto result = ve::apply(
4392 [&ws](dcon::nation_id n) {
4393 for(auto c : ws.world.nation_get_unilateral_relationship_as_target(n)) {
4394 if(c.get_foreign_investment() > 0.0f)
4395 return true;
4396 }
4397 return false;
4398 },
4399 to_nation(primary_slot));
4400 return compare_to_true(tval[0], result);
4401}
4402TRIGGER_FUNCTION(tf_part_of_sphere) {
4403 return compare_to_true(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)) != dcon::nation_id());
4404}
4405TRIGGER_FUNCTION(tf_is_sphere_leader_of_tag) {
4406 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4407 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(holder), to_nation(primary_slot));
4408}
4409TRIGGER_FUNCTION(tf_is_sphere_leader_of_from) {
4410 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(from_slot)), to_nation(primary_slot));
4411}
4412TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_nation) {
4413 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(this_slot)), to_nation(primary_slot));
4414}
4415TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_province) {
4416 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4417 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(owner), to_nation(primary_slot));
4418}
4419TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_state) {
4420 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4421 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(owner), to_nation(primary_slot));
4422}
4423TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_pop) {
4424 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4425 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(owner), to_nation(primary_slot));
4426}
4427TRIGGER_FUNCTION(tf_number_of_states) {
4428 return compare_values(tval[0], ws.world.nation_get_owned_state_count(to_nation(primary_slot)), tval[1]);
4429}
4430TRIGGER_FUNCTION(tf_war_score) {
4431 // unimplemented: which war would this be for?
4432 return compare_to_true(tval[0], true);
4433}
4434TRIGGER_FUNCTION(tf_is_releasable_vassal_from) {
4435 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
4436 return compare_to_true(tval[0], !ws.world.national_identity_get_is_not_releasable(tag));
4437}
4438TRIGGER_FUNCTION(tf_is_releasable_vassal_other) {
4439 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
4440 return compare_to_true(tval[0], !ws.world.national_identity_get_is_not_releasable(tag));
4441}
4442TRIGGER_FUNCTION(tf_has_recent_imigration) {
4443 return compare_values(tval[0],
4444 int32_t(tval[1]) +
4445 ve::apply([&ws](dcon::province_id p) { return ws.world.province_get_last_immigration(p).to_raw_value(); },
4446 to_prov(primary_slot)),
4447 ws.current_date.to_raw_value());
4448}
4449TRIGGER_FUNCTION(tf_province_control_days) {
4450 return compare_values(tval[0],
4451 ws.current_date.to_raw_value() -
4452 ve::apply([&ws](dcon::province_id p) { return ws.world.province_get_last_control_change(p).to_raw_value(); },
4453 to_prov(primary_slot)),
4454 int32_t(tval[1]));
4455}
4456TRIGGER_FUNCTION(tf_is_disarmed) {
4457 return compare_to_true(tval[0], ve::apply([&ws](dcon::nation_id n) {
4458 auto d = ws.world.nation_get_disarmed_until(n);
4459 return bool(d) && ws.current_date < d;
4460 }, to_nation(primary_slot)));
4461}
4462TRIGGER_FUNCTION(tf_is_disarmed_pop) {
4463 return compare_to_true(tval[0], ve::apply([&ws](dcon::nation_id n) {
4464 auto d = ws.world.nation_get_disarmed_until(n);
4465 return bool(d) && ws.current_date < d;
4466 }, nations::owner_of_pop(ws, to_pop(primary_slot))));
4467}
4468TRIGGER_FUNCTION(tf_big_producer) {
4469 // stub: used only rarely in ai chances and would be expensive to test
4470 return compare_to_true(tval[0], false);
4471}
4472TRIGGER_FUNCTION(tf_someone_can_form_union_tag_from) {
4473 // stub: apparently unused
4474 return compare_to_true(tval[0], false);
4475}
4476TRIGGER_FUNCTION(tf_someone_can_form_union_tag_other) {
4477 // stub: apparently unused
4478 return compare_to_true(tval[0], false);
4479}
4480TRIGGER_FUNCTION(tf_social_movement_strength) {
4481 return compare_values(tval[0],
4482 ve::apply(
4483 [&ws](dcon::nation_id n) {
4484 float max_str = 0.0f;
4485 for(auto m : ws.world.nation_get_movement_within(n)) {
4486 auto issue = m.get_movement().get_associated_issue_option();
4487 if(issue) {
4488 if(culture::issue_type(issue.get_parent_issue().get_issue_type()) == culture::issue_type::social &&
4489 m.get_movement().get_pop_support() > max_str) {
4490 max_str = m.get_movement().get_pop_support();
4491 }
4492 }
4493 }
4494 return max_str;
4495 },
4496 to_nation(primary_slot)) *
4497 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
4498 read_float_from_payload(tval + 1));
4499}
4500TRIGGER_FUNCTION(tf_political_movement_strength) {
4501 return compare_values(tval[0],
4502 ve::apply(
4503 [&ws](dcon::nation_id n) {
4504 float max_str = 0.0f;
4505 for(auto m : ws.world.nation_get_movement_within(n)) {
4506 auto issue = m.get_movement().get_associated_issue_option();
4507 if(issue) {
4508 if(culture::issue_type(issue.get_parent_issue().get_issue_type()) == culture::issue_type::political &&
4509 m.get_movement().get_pop_support() > max_str) {
4510 max_str = m.get_movement().get_pop_support();
4511 }
4512 }
4513 }
4514 return max_str;
4515 },
4516 to_nation(primary_slot)) *
4517 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
4518 read_float_from_payload(tval + 1));
4519}
4520TRIGGER_FUNCTION(tf_can_build_factory_in_capital_state) {
4521 // stub: virtually unused
4522 return compare_to_true(tval[0], true);
4523}
4524TRIGGER_FUNCTION(tf_social_movement) {
4525 return compare_to_true(tval[0], ve::apply(
4526 [&ws](dcon::pop_id p) {
4527 auto m = fatten(ws.world, ws.world.pop_get_movement_from_pop_movement_membership(p));
4528 return m && m.get_associated_issue_option() &&
4530 m.get_associated_issue_option().get_parent_issue().get_issue_type()) ==
4532 },
4533 to_pop(primary_slot)));
4534}
4535TRIGGER_FUNCTION(tf_political_movement) {
4536 return compare_to_true(tval[0], ve::apply(
4537 [&ws](dcon::pop_id p) {
4538 auto m = fatten(ws.world, ws.world.pop_get_movement_from_pop_movement_membership(p));
4539 return m && m.get_associated_issue_option() &&
4541 m.get_associated_issue_option().get_parent_issue().get_issue_type()) ==
4543 },
4544 to_pop(primary_slot)));
4545}
4546TRIGGER_FUNCTION(tf_political_movement_from_reb) {
4547 // returns false because I'm not sure exactly what it is supposed to do (applies to the below as well)
4548 // it is called in nation scope while modifying chances for a rebel faction to spawn
4549 // perhaps reducing the chance if there is an "appropriate" movement (because there is almost always some movement)
4550 // however, the logic from working backwards from rebel factions to movements is not clear to me
4551 return compare_to_true(tval[0], false);
4552}
4553TRIGGER_FUNCTION(tf_social_movement_from_reb) {
4554 return compare_to_true(tval[0], false);
4555}
4556
4557TRIGGER_FUNCTION(tf_has_cultural_sphere) {
4558 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(this_slot));
4559 auto culture_group = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4560
4561 auto result = ve::apply(
4562 [&ws](dcon::nation_id n, dcon::culture_group_id g) {
4563 for(auto s : ws.world.nation_get_gp_relationship_as_great_power(n)) {
4564 if((s.get_status() & nations::influence::level_mask) == nations::influence::level_in_sphere &&
4565 s.get_influence_target().get_primary_culture().get_group_from_culture_group_membership() == g) {
4566 return true;
4567 }
4568 }
4569 return false;
4570 },
4571 to_nation(primary_slot), culture_group);
4572
4573 return compare_to_true(tval[0], result);
4574}
4575TRIGGER_FUNCTION(tf_world_wars_enabled) {
4576 return compare_to_true(tval[0], ws.military_definitions.world_wars_enabled);
4577}
4578TRIGGER_FUNCTION(tf_has_pop_culture_pop_this_pop) {
4579 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)), ws.world.pop_get_culture(to_pop(this_slot)));
4580}
4581TRIGGER_FUNCTION(tf_has_pop_culture_state_this_pop) {
4582 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
4583 auto result = ve::apply(
4584 [&ws](dcon::state_instance_id s, dcon::culture_id c) {
4585 return bool(c) ? ws.world.state_instance_get_demographics(s, demographics::to_key(ws, c)) > 0.0f : false;
4586 },
4587 to_state(primary_slot), culture);
4588 return compare_to_true(tval[0], result);
4589}
4590TRIGGER_FUNCTION(tf_has_pop_culture_province_this_pop) {
4591 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
4592 auto result = ve::apply(
4593 [&ws](dcon::province_id s, dcon::culture_id c) {
4594 return bool(c) ? ws.world.province_get_demographics(s, demographics::to_key(ws, c)) > 0.0f : false;
4595 },
4596 to_prov(primary_slot), culture);
4597 return compare_to_true(tval[0], result);
4598}
4599TRIGGER_FUNCTION(tf_has_pop_culture_nation_this_pop) {
4600 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
4601 auto result = ve::apply(
4602 [&ws](dcon::nation_id s, dcon::culture_id c) {
4603 return bool(c) ? ws.world.nation_get_demographics(s, demographics::to_key(ws, c)) > 0.0f : false;
4604 },
4605 to_nation(primary_slot), culture);
4606 return compare_to_true(tval[0], result);
4607}
4608TRIGGER_FUNCTION(tf_has_pop_culture_pop) {
4609 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)), payload(tval[1]).cul_id);
4610}
4611TRIGGER_FUNCTION(tf_has_pop_culture_state) {
4612 return compare_to_true(tval[0],
4613 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, payload(tval[1]).cul_id)) > 0.0f);
4614}
4615TRIGGER_FUNCTION(tf_has_pop_culture_province) {
4616 return compare_to_true(tval[0],
4617 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, payload(tval[1]).cul_id)) > 0.0f);
4618}
4619TRIGGER_FUNCTION(tf_has_pop_culture_nation) {
4620 return compare_to_true(tval[0],
4621 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, payload(tval[1]).cul_id)) > 0.0f);
4622}
4623TRIGGER_FUNCTION(tf_has_pop_religion_pop_this_pop) {
4624 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)),
4625 ws.world.pop_get_religion(to_pop(this_slot)));
4626}
4627TRIGGER_FUNCTION(tf_has_pop_religion_state_this_pop) {
4628 auto rel = ws.world.pop_get_religion(to_pop(this_slot));
4629 auto result = ve::apply(
4630 [&ws](dcon::state_instance_id s, dcon::religion_id r) {
4631 return bool(r) ? ws.world.state_instance_get_demographics(s, demographics::to_key(ws, r)) > 0.0f : false;
4632 },
4633 to_state(primary_slot), rel);
4634 return compare_to_true(tval[0], result);
4635}
4636TRIGGER_FUNCTION(tf_has_pop_religion_province_this_pop) {
4637 auto rel = ws.world.pop_get_religion(to_pop(this_slot));
4638 auto result = ve::apply(
4639 [&ws](dcon::province_id s, dcon::religion_id r) {
4640 return bool(r) ? ws.world.province_get_demographics(s, demographics::to_key(ws, r)) > 0.0f : false;
4641 },
4642 to_prov(primary_slot), rel);
4643 return compare_to_true(tval[0], result);
4644}
4645TRIGGER_FUNCTION(tf_has_pop_religion_nation_this_pop) {
4646 auto rel = ws.world.pop_get_religion(to_pop(this_slot));
4647 auto result = ve::apply(
4648 [&ws](dcon::nation_id s, dcon::religion_id r) {
4649 return bool(r) ? ws.world.nation_get_demographics(s, demographics::to_key(ws, r)) > 0.0f : false;
4650 },
4651 to_nation(primary_slot), rel);
4652 return compare_to_true(tval[0], result);
4653}
4654TRIGGER_FUNCTION(tf_has_pop_religion_pop) {
4655 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)), payload(tval[1]).rel_id);
4656}
4657TRIGGER_FUNCTION(tf_has_pop_religion_state) {
4658 return compare_to_true(tval[0],
4659 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, payload(tval[1]).rel_id)) > 0.0f);
4660}
4661TRIGGER_FUNCTION(tf_has_pop_religion_province) {
4662 return compare_to_true(tval[0],
4663 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, payload(tval[1]).rel_id)) > 0.0f);
4664}
4665TRIGGER_FUNCTION(tf_has_pop_religion_nation) {
4666 return compare_to_true(tval[0],
4667 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, payload(tval[1]).rel_id)) > 0.0f);
4668}
4669TRIGGER_FUNCTION(tf_life_needs) {
4670 return compare_values(tval[0], ws.world.pop_get_life_needs_satisfaction(to_pop(primary_slot)),
4671 read_float_from_payload(tval + 1));
4672}
4673TRIGGER_FUNCTION(tf_everyday_needs) {
4674 return compare_values(tval[0], ws.world.pop_get_everyday_needs_satisfaction(to_pop(primary_slot)),
4675 read_float_from_payload(tval + 1));
4676}
4677TRIGGER_FUNCTION(tf_luxury_needs) {
4678 return compare_values(tval[0], ws.world.pop_get_luxury_needs_satisfaction(to_pop(primary_slot)),
4679 read_float_from_payload(tval + 1));
4680}
4681TRIGGER_FUNCTION(tf_consciousness_pop) {
4682 return compare_values(tval[0], ws.world.pop_get_consciousness(to_pop(primary_slot)), read_float_from_payload(tval + 1));
4683}
4684TRIGGER_FUNCTION(tf_consciousness_province) {
4685 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4686 return compare_values(tval[0],
4687 ve::select(total_pop != 0.0f,
4688 ws.world.province_get_demographics(to_prov(primary_slot), demographics::consciousness) / total_pop, 0.0f),
4689 read_float_from_payload(tval + 1));
4690}
4691TRIGGER_FUNCTION(tf_consciousness_state) {
4692 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4693 return compare_values(tval[0],
4694 ve::select(total_pop != 0.0f,
4695 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::consciousness) / total_pop, 0.0f),
4696 read_float_from_payload(tval + 1));
4697}
4698TRIGGER_FUNCTION(tf_consciousness_nation) {
4699 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4700 return compare_values(tval[0],
4701 ve::select(total_pop != 0.0f,
4702 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::consciousness) / total_pop, 0.0f),
4703 read_float_from_payload(tval + 1));
4704}
4705TRIGGER_FUNCTION(tf_literacy_pop) {
4706 return compare_values(tval[0], ws.world.pop_get_literacy(to_pop(primary_slot)), read_float_from_payload(tval + 1));
4707}
4708TRIGGER_FUNCTION(tf_literacy_province) {
4709 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4710 return compare_values(tval[0],
4711 ve::select(total_pop != 0.0f, ws.world.province_get_demographics(to_prov(primary_slot), demographics::literacy) / total_pop,
4712 0.0f),
4713 read_float_from_payload(tval + 1));
4714}
4715TRIGGER_FUNCTION(tf_literacy_state) {
4716 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4717 return compare_values(tval[0],
4718 ve::select(total_pop != 0.0f,
4719 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::literacy) / total_pop, 0.0f),
4720 read_float_from_payload(tval + 1));
4721}
4722TRIGGER_FUNCTION(tf_literacy_nation) {
4723 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4724 return compare_values(tval[0],
4725 ve::select(total_pop != 0.0f, ws.world.nation_get_demographics(to_nation(primary_slot), demographics::literacy) / total_pop,
4726 0.0f),
4727 read_float_from_payload(tval + 1));
4728}
4729TRIGGER_FUNCTION(tf_militancy_pop) {
4730 return compare_values(tval[0], ws.world.pop_get_militancy(to_pop(primary_slot)), read_float_from_payload(tval + 1));
4731}
4732TRIGGER_FUNCTION(tf_militancy_province) {
4733 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4734 return compare_values(tval[0],
4735 ve::select(total_pop != 0.0f,
4736 ws.world.province_get_demographics(to_prov(primary_slot), demographics::militancy) / total_pop, 0.0f),
4737 read_float_from_payload(tval + 1));
4738}
4739TRIGGER_FUNCTION(tf_militancy_state) {
4740 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4741 return compare_values(tval[0],
4742 ve::select(total_pop != 0.0f,
4743 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::militancy) / total_pop, 0.0f),
4744 read_float_from_payload(tval + 1));
4745}
4746TRIGGER_FUNCTION(tf_militancy_nation) {
4747 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4748 return compare_values(tval[0],
4749 ve::select(total_pop != 0.0f,
4750 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::militancy) / total_pop, 0.0f),
4751 read_float_from_payload(tval + 1));
4752}
4753TRIGGER_FUNCTION(tf_trade_goods_in_state_state) {
4754 auto g = payload(tval[1]).com_id;
4755 auto sdef = ws.world.state_instance_get_definition(to_state(primary_slot));
4756 auto sowner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
4757 auto result = ve::apply(
4758 [&ws, g](dcon::state_definition_id sd, dcon::nation_id o) {
4759 for(auto p : ws.world.state_definition_get_abstract_state_membership(sd)) {
4760 if(p.get_province().get_nation_from_province_ownership() == o) {
4761 if(p.get_province().get_rgo() == g)
4762 return true;
4763 }
4764 }
4765 return false;
4766 },
4767 sdef, sowner);
4768 return compare_to_true(tval[0], result);
4769}
4770TRIGGER_FUNCTION(tf_trade_goods_in_state_province) {
4771 auto g = payload(tval[1]).com_id;
4772 auto si = ws.world.province_get_state_membership(to_prov(primary_slot));
4773 auto sdef = ws.world.state_instance_get_definition(si);
4774 auto sowner = ws.world.state_instance_get_nation_from_state_ownership(si);
4775 auto result = ve::apply(
4776 [&ws, g](dcon::state_definition_id sd, dcon::nation_id o) {
4777 for(auto p : ws.world.state_definition_get_abstract_state_membership(sd)) {
4778 if(p.get_province().get_nation_from_province_ownership() == o) {
4779 if(p.get_province().get_rgo() == g)
4780 return true;
4781 }
4782 }
4783 return false;
4784 },
4785 sdef, sowner);
4786 return compare_to_true(tval[0], result);
4787}
4788TRIGGER_FUNCTION(tf_has_flashpoint) {
4789 return compare_to_true(tval[0],
4790 ws.world.state_instance_get_flashpoint_tag(to_state(primary_slot)) != dcon::national_identity_id());
4791}
4792TRIGGER_FUNCTION(tf_flashpoint_tension) {
4793 return compare_values(tval[0], ws.world.state_instance_get_flashpoint_tension(to_state(primary_slot)),
4794 read_float_from_payload(tval + 1));
4795}
4796TRIGGER_FUNCTION(tf_flashpoint_tension_province) {
4797 return compare_values(tval[0], ws.world.state_instance_get_flashpoint_tension(ws.world.province_get_state_membership(to_prov(primary_slot))),
4798 read_float_from_payload(tval + 1));
4799}
4800TRIGGER_FUNCTION(tf_crisis_exist) {
4801 return compare_to_true(tval[0], ws.current_crisis != sys::crisis_type::none);
4802}
4803TRIGGER_FUNCTION(tf_is_liberation_crisis) {
4804 return compare_to_true(tval[0], ws.current_crisis == sys::crisis_type::liberation);
4805}
4806TRIGGER_FUNCTION(tf_is_claim_crisis) {
4807 return compare_to_true(tval[0], ws.current_crisis == sys::crisis_type::claim);
4808}
4809TRIGGER_FUNCTION(tf_crisis_temperature) {
4810 return compare_values(tval[0], ws.crisis_temperature, read_float_from_payload(tval + 1));
4811}
4812TRIGGER_FUNCTION(tf_involved_in_crisis_nation) {
4813 auto result = ve::apply(
4814 [&ws](dcon::nation_id n) {
4815 auto sz = ws.crisis_participants.size();
4816 for(uint32_t i = 0; i < sz; ++i) {
4817 if(!ws.crisis_participants[i].id)
4818 return false;
4819 if(ws.crisis_participants[i].id == n)
4820 return true;
4821 }
4822 return false;
4823 },
4824 to_nation(primary_slot));
4825 return compare_to_true(tval[0], result);
4826}
4827TRIGGER_FUNCTION(tf_involved_in_crisis_pop) {
4828 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
4829 auto result = ve::apply(
4830 [&ws](dcon::nation_id n) {
4831 auto sz = ws.crisis_participants.size();
4832 for(uint32_t i = 0; i < sz; ++i) {
4833 if(!ws.crisis_participants[i].id)
4834 return false;
4835 if(ws.crisis_participants[i].id == n)
4836 return true;
4837 }
4838 return false;
4839 },
4840 owner);
4841 return compare_to_true(tval[0], result);
4842}
4843TRIGGER_FUNCTION(tf_rich_strata_life_needs_nation) {
4844 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4845 return compare_values(tval[0],
4846 ve::select(accumulator > 0.0f,
4847 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_life_needs) / accumulator, 0.0f),
4848 read_float_from_payload(tval + 1));
4849}
4850TRIGGER_FUNCTION(tf_rich_strata_life_needs_state) {
4851 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4852 return compare_values(tval[0],
4853 ve::select(accumulator > 0.0f,
4854 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_life_needs) / accumulator, 0.0f),
4855 read_float_from_payload(tval + 1));
4856}
4857TRIGGER_FUNCTION(tf_rich_strata_life_needs_province) {
4858 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4859 return compare_values(tval[0],
4860 ve::select(accumulator > 0.0f,
4861 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_life_needs) / accumulator, 0.0f),
4862 read_float_from_payload(tval + 1));
4863}
4864TRIGGER_FUNCTION(tf_rich_strata_life_needs_pop) {
4865 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4866 auto si = ws.world.province_get_state_membership(location);
4867 return tf_rich_strata_life_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4868}
4869TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_nation) {
4870 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4871 return compare_values(tval[0],
4872 ve::select(accumulator > 0.0f,
4873 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_everyday_needs) / accumulator, 0.0f),
4874 read_float_from_payload(tval + 1));
4875}
4876TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_state) {
4877 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4878 return compare_values(tval[0],
4879 ve::select(accumulator > 0.0f,
4880 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_everyday_needs) / accumulator,
4881 0.0f),
4882 read_float_from_payload(tval + 1));
4883}
4884TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_province) {
4885 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4886 return compare_values(tval[0],
4887 ve::select(accumulator > 0.0f,
4888 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_everyday_needs) / accumulator, 0.0f),
4889 read_float_from_payload(tval + 1));
4890}
4891TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_pop) {
4892 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4893 auto si = ws.world.province_get_state_membership(location);
4894 return tf_rich_strata_everyday_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4895}
4896TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_nation) {
4897 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4898 return compare_values(tval[0],
4899 ve::select(accumulator > 0.0f,
4900 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_luxury_needs) / accumulator, 0.0f),
4901 read_float_from_payload(tval + 1));
4902}
4903TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_state) {
4904 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4905 return compare_values(tval[0],
4906 ve::select(accumulator > 0.0f,
4907 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_luxury_needs) / accumulator, 0.0f),
4908 read_float_from_payload(tval + 1));
4909}
4910TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_province) {
4911 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4912 return compare_values(tval[0],
4913 ve::select(accumulator > 0.0f,
4914 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_luxury_needs) / accumulator, 0.0f),
4915 read_float_from_payload(tval + 1));
4916}
4917TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_pop) {
4918 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4919 auto si = ws.world.province_get_state_membership(location);
4920 return tf_rich_strata_luxury_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4921}
4922TRIGGER_FUNCTION(tf_middle_strata_life_needs_nation) {
4923 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4924 return compare_values(tval[0],
4925 ve::select(accumulator > 0.0f,
4926 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_life_needs) / accumulator, 0.0f),
4927 read_float_from_payload(tval + 1));
4928}
4929TRIGGER_FUNCTION(tf_middle_strata_life_needs_state) {
4930 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4931 return compare_values(tval[0],
4932 ve::select(accumulator > 0.0f,
4933 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_life_needs) / accumulator, 0.0f),
4934 read_float_from_payload(tval + 1));
4935}
4936TRIGGER_FUNCTION(tf_middle_strata_life_needs_province) {
4937 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4938 return compare_values(tval[0],
4939 ve::select(accumulator > 0.0f,
4940 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_life_needs) / accumulator, 0.0f),
4941 read_float_from_payload(tval + 1));
4942}
4943TRIGGER_FUNCTION(tf_middle_strata_life_needs_pop) {
4944 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4945 auto si = ws.world.province_get_state_membership(location);
4946 return tf_middle_strata_life_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4947}
4948TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_nation) {
4949 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4950 return compare_values(tval[0],
4951 ve::select(accumulator > 0.0f,
4952 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_everyday_needs) / accumulator, 0.0f),
4953 read_float_from_payload(tval + 1));
4954}
4955TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_state) {
4956 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4957 return compare_values(tval[0],
4958 ve::select(accumulator > 0.0f,
4959 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_everyday_needs) / accumulator,
4960 0.0f),
4961 read_float_from_payload(tval + 1));
4962}
4963TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_province) {
4964 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4965 return compare_values(tval[0],
4966 ve::select(accumulator > 0.0f,
4967 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_everyday_needs) / accumulator, 0.0f),
4968 read_float_from_payload(tval + 1));
4969}
4970TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_pop) {
4971 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4972 auto si = ws.world.province_get_state_membership(location);
4973 return tf_middle_strata_everyday_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4974}
4975TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_nation) {
4976 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4977 return compare_values(tval[0],
4978 ve::select(accumulator > 0.0f,
4979 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_luxury_needs) / accumulator, 0.0f),
4980 read_float_from_payload(tval + 1));
4981}
4982TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_state) {
4983 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4984 return compare_values(tval[0],
4985 ve::select(accumulator > 0.0f,
4986 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_luxury_needs) / accumulator,
4987 0.0f),
4988 read_float_from_payload(tval + 1));
4989}
4990TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_province) {
4991 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4992 return compare_values(tval[0],
4993 ve::select(accumulator > 0.0f,
4994 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_luxury_needs) / accumulator, 0.0f),
4995 read_float_from_payload(tval + 1));
4996}
4997TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_pop) {
4998 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4999 auto si = ws.world.province_get_state_membership(location);
5000 return tf_middle_strata_luxury_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5001}
5002TRIGGER_FUNCTION(tf_poor_strata_life_needs_nation) {
5003 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
5004 return compare_values(tval[0],
5005 ve::select(accumulator > 0.0f,
5006 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_life_needs) / accumulator, 0.0f),
5007 read_float_from_payload(tval + 1));
5008}
5009TRIGGER_FUNCTION(tf_poor_strata_life_needs_state) {
5010 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
5011 return compare_values(tval[0],
5012 ve::select(accumulator > 0.0f,
5013 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_life_needs) / accumulator, 0.0f),
5014 read_float_from_payload(tval + 1));
5015}
5016TRIGGER_FUNCTION(tf_poor_strata_life_needs_province) {
5017 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
5018 return compare_values(tval[0],
5019 ve::select(accumulator > 0.0f,
5020 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_life_needs) / accumulator, 0.0f),
5021 read_float_from_payload(tval + 1));
5022}
5023TRIGGER_FUNCTION(tf_poor_strata_life_needs_pop) {
5024 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5025 auto si = ws.world.province_get_state_membership(location);
5026 return tf_poor_strata_life_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5027}
5028TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_nation) {
5029 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
5030 return compare_values(tval[0],
5031 ve::select(accumulator > 0.0f,
5032 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_everyday_needs) / accumulator, 0.0f),
5033 read_float_from_payload(tval + 1));
5034}
5035TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_state) {
5036 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
5037 return compare_values(tval[0],
5038 ve::select(accumulator > 0.0f,
5039 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_everyday_needs) / accumulator,
5040 0.0f),
5041 read_float_from_payload(tval + 1));
5042}
5043TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_province) {
5044 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
5045 return compare_values(tval[0],
5046 ve::select(accumulator > 0.0f,
5047 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_everyday_needs) / accumulator, 0.0f),
5048 read_float_from_payload(tval + 1));
5049}
5050TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_pop) {
5051 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5052 auto si = ws.world.province_get_state_membership(location);
5053 return tf_poor_strata_everyday_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5054}
5055TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_nation) {
5056 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
5057 return compare_values(tval[0],
5058 ve::select(accumulator > 0.0f,
5059 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_luxury_needs) / accumulator, 0.0f),
5060 read_float_from_payload(tval + 1));
5061}
5062TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_state) {
5063 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
5064 return compare_values(tval[0],
5065 ve::select(accumulator > 0.0f,
5066 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_luxury_needs) / accumulator, 0.0f),
5067 read_float_from_payload(tval + 1));
5068}
5069TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_province) {
5070 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
5071 return compare_values(tval[0],
5072 ve::select(accumulator > 0.0f,
5073 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_luxury_needs) / accumulator, 0.0f),
5074 read_float_from_payload(tval + 1));
5075}
5076TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_pop) {
5077 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5078 auto si = ws.world.province_get_state_membership(location);
5079 return tf_poor_strata_luxury_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5080}
5081TRIGGER_FUNCTION(tf_diplomatic_influence_tag) {
5082 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[2]).tag_id);
5083 auto result = ve::apply(
5084 [&ws, holder](dcon::nation_id a) {
5085 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(holder, a);
5086 return ws.world.gp_relationship_get_influence(gpr);
5087 },
5088 to_nation(primary_slot));
5089 return compare_values(tval[0], result, float(tval[1]));
5090}
5091TRIGGER_FUNCTION(tf_diplomatic_influence_this_nation) {
5092 auto result = ve::apply(
5093 [&ws](dcon::nation_id a, dcon::nation_id b) {
5094 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5095 return ws.world.gp_relationship_get_influence(gpr);
5096 },
5097 to_nation(primary_slot), to_nation(this_slot));
5098 return compare_values(tval[0], result, float(tval[1]));
5099}
5100TRIGGER_FUNCTION(tf_diplomatic_influence_this_province) {
5101 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5102 auto result = ve::apply(
5103 [&ws](dcon::nation_id a, dcon::nation_id b) {
5104 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5105 return ws.world.gp_relationship_get_influence(gpr);
5106 },
5107 to_nation(primary_slot), owner);
5108 return compare_values(tval[0], result, float(tval[1]));
5109}
5110TRIGGER_FUNCTION(tf_diplomatic_influence_from_nation) {
5111 auto result = ve::apply(
5112 [&ws](dcon::nation_id a, dcon::nation_id b) {
5113 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5114 return ws.world.gp_relationship_get_influence(gpr);
5115 },
5116 to_nation(primary_slot), to_nation(from_slot));
5117 return compare_values(tval[0], result, float(tval[1]));
5118}
5119TRIGGER_FUNCTION(tf_diplomatic_influence_from_province) {
5120 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
5121 auto result = ve::apply(
5122 [&ws](dcon::nation_id a, dcon::nation_id b) {
5123 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5124 return ws.world.gp_relationship_get_influence(gpr);
5125 },
5126 to_nation(primary_slot), owner);
5127 return compare_values(tval[0], result, float(tval[1]));
5128}
5129TRIGGER_FUNCTION(tf_pop_unemployment_nation) {
5130 auto type = payload(tval[3]).popt_id;
5131 auto pop_size = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type));
5132 auto employment = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_employment_key(ws, type));
5133 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5134 read_float_from_payload(tval + 1));
5135}
5136TRIGGER_FUNCTION(tf_pop_unemployment_state) {
5137 auto type = payload(tval[3]).popt_id;
5138 auto pop_size = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type));
5139 auto employment = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_employment_key(ws, type));
5140 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5141 read_float_from_payload(tval + 1));
5142}
5143TRIGGER_FUNCTION(tf_pop_unemployment_province) {
5144 auto type = payload(tval[3]).popt_id;
5145 auto pop_size = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type));
5146 auto employment = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_employment_key(ws, type));
5147 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5148 read_float_from_payload(tval + 1));
5149}
5150TRIGGER_FUNCTION(tf_pop_unemployment_pop) {
5151 auto pop_size = ws.world.pop_get_size(to_pop(primary_slot));
5152 auto employment = ws.world.pop_get_employment(to_pop(primary_slot));
5153 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5154 read_float_from_payload(tval + 1));
5155}
5156TRIGGER_FUNCTION(tf_pop_unemployment_nation_this_pop) {
5157 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5158
5159 auto pop_size = ve::apply(
5160 [&](dcon::nation_id loc, dcon::pop_type_id t) {
5161 if(t)
5162 return ws.world.nation_get_demographics(loc, demographics::to_key(ws, t));
5163 else
5164 return 0.0f;
5165 },
5166 to_nation(primary_slot), type);
5167
5168 auto employment = ve::apply(
5169 [&](dcon::nation_id loc, dcon::pop_type_id t) {
5170 if(t)
5171 return ws.world.nation_get_demographics(loc, demographics::to_employment_key(ws, t));
5172 else
5173 return 0.0f;
5174 },
5175 to_nation(primary_slot), type);
5176
5177 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5178 read_float_from_payload(tval + 1));
5179}
5180TRIGGER_FUNCTION(tf_pop_unemployment_state_this_pop) {
5181 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5182
5183 auto pop_size = ve::apply(
5184 [&](dcon::state_instance_id loc, dcon::pop_type_id t) {
5185 if(t)
5186 return ws.world.state_instance_get_demographics(loc, demographics::to_key(ws, t));
5187 else
5188 return 0.0f;
5189 },
5190 to_state(primary_slot), type);
5191
5192 auto employment = ve::apply(
5193 [&](dcon::state_instance_id loc, dcon::pop_type_id t) {
5194 if(t)
5195 return ws.world.state_instance_get_demographics(loc, demographics::to_employment_key(ws, t));
5196 else
5197 return 0.0f;
5198 },
5199 to_state(primary_slot), type);
5200
5201 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5202 read_float_from_payload(tval + 1));
5203}
5204TRIGGER_FUNCTION(tf_pop_unemployment_province_this_pop) {
5205 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5206
5207 auto pop_size = ve::apply(
5208 [&](dcon::province_id loc, dcon::pop_type_id t) {
5209 if(t)
5210 return ws.world.province_get_demographics(loc, demographics::to_key(ws, t));
5211 else
5212 return 0.0f;
5213 },
5214 to_prov(primary_slot), type);
5215
5216 auto employment = ve::apply(
5217 [&](dcon::province_id loc, dcon::pop_type_id t) {
5218 if(t)
5219 return ws.world.province_get_demographics(loc, demographics::to_employment_key(ws, t));
5220 else
5221 return 0.0f;
5222 },
5223 to_prov(primary_slot), type);
5224
5225 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5226 read_float_from_payload(tval + 1));
5227}
5228TRIGGER_FUNCTION(tf_relation_tag) {
5229 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[2]).tag_id);
5230 auto relation = ve::apply(
5231 [&ws, holder](dcon::nation_id a) {
5232 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, holder);
5233 return ws.world.diplomatic_relation_get_value(rel);
5234 },
5235 to_nation(primary_slot));
5236 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5237}
5238TRIGGER_FUNCTION(tf_relation_this_nation) {
5239 auto relation = ve::apply(
5240 [&ws](dcon::nation_id a, dcon::nation_id b) {
5241 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5242 return ws.world.diplomatic_relation_get_value(rel);
5243 },
5244 to_nation(primary_slot), to_nation(this_slot));
5245 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5246}
5247TRIGGER_FUNCTION(tf_relation_this_province) {
5248 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5249 auto relation = ve::apply(
5250 [&ws](dcon::nation_id a, dcon::nation_id b) {
5251 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5252 return ws.world.diplomatic_relation_get_value(rel);
5253 },
5254 to_nation(primary_slot), owner);
5255 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5256}
5257TRIGGER_FUNCTION(tf_relation_this_pop) {
5258 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
5259 auto relation = ve::apply(
5260 [&ws](dcon::nation_id a, dcon::nation_id b) {
5261 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5262 return ws.world.diplomatic_relation_get_value(rel);
5263 },
5264 to_nation(primary_slot), owner);
5265 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5266}
5267TRIGGER_FUNCTION(tf_relation_from_nation) {
5268 auto relation = ve::apply(
5269 [&ws](dcon::nation_id a, dcon::nation_id b) {
5270 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5271 return ws.world.diplomatic_relation_get_value(rel);
5272 },
5273 to_nation(primary_slot), to_nation(from_slot));
5274 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5275}
5276TRIGGER_FUNCTION(tf_relation_from_province) {
5277 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
5278 auto relation = ve::apply(
5279 [&ws](dcon::nation_id a, dcon::nation_id b) {
5280 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5281 return ws.world.diplomatic_relation_get_value(rel);
5282 },
5283 to_nation(primary_slot), owner);
5284 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5285}
5286TRIGGER_FUNCTION(tf_check_variable) {
5287 auto id = payload(tval[3]).natv_id;
5288 return compare_values(tval[0], ws.world.nation_get_variables(to_nation(primary_slot), id), read_float_from_payload(tval + 1));
5289}
5290TRIGGER_FUNCTION(tf_upper_house) {
5291 auto id = payload(tval[3]).ideo_id;
5292 return compare_values(tval[0], ws.world.nation_get_upper_house(to_nation(primary_slot), id), 100.0f * read_float_from_payload(tval + 1));
5293}
5294TRIGGER_FUNCTION(tf_unemployment_by_type_nation) {
5295 return tf_pop_unemployment_nation<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5296}
5297TRIGGER_FUNCTION(tf_unemployment_by_type_state) {
5298 return tf_pop_unemployment_state<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5299}
5300TRIGGER_FUNCTION(tf_unemployment_by_type_province) {
5301 return tf_pop_unemployment_province<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5302}
5303TRIGGER_FUNCTION(tf_unemployment_by_type_pop) {
5304 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5305 auto si = ws.world.province_get_state_membership(location);
5306 return tf_unemployment_by_type_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5307}
5308TRIGGER_FUNCTION(tf_party_loyalty_nation_province_id) {
5309 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5310 payload(tval[2]).signed_value);
5311}
5312TRIGGER_FUNCTION(tf_party_loyalty_from_nation_province_id) {
5313 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5314 payload(tval[2]).signed_value);
5315}
5316TRIGGER_FUNCTION(tf_party_loyalty_province_province_id) {
5317 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5318 payload(tval[2]).signed_value);
5319}
5320TRIGGER_FUNCTION(tf_party_loyalty_from_province_province_id) {
5321 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5322 payload(tval[2]).signed_value);
5323}
5324TRIGGER_FUNCTION(tf_party_loyalty_nation_from_province) {
5325 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(from_slot), payload(tval[2]).ideo_id),
5326 payload(tval[1]).signed_value);
5327}
5328TRIGGER_FUNCTION(tf_party_loyalty_generic) {
5329 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5330 payload(tval[1]).signed_value);
5331}
5332TRIGGER_FUNCTION(tf_party_loyalty_from_nation_scope_province) {
5333 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5334 payload(tval[1]).signed_value);
5335}
5336TRIGGER_FUNCTION(tf_party_loyalty_from_province_scope_province) {
5337 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5338 payload(tval[1]).signed_value);
5339}
5340TRIGGER_FUNCTION(tf_can_build_in_province_railroad_no_limit_from_nation) {
5341 return compare_to_true(tval[0],
5342 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5343 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5344 ve::to_float(ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::railroad))));
5345}
5346TRIGGER_FUNCTION(tf_can_build_in_province_railroad_yes_limit_from_nation) {
5347 return compare_to_true(tval[0],
5348 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5349 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5350 ve::to_float(ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::railroad))));
5351}
5352TRIGGER_FUNCTION(tf_can_build_in_province_railroad_no_limit_this_nation) {
5353 return compare_to_true(tval[0],
5354 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5355 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5356 ve::to_float(ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::railroad))));
5357}
5358TRIGGER_FUNCTION(tf_can_build_in_province_railroad_yes_limit_this_nation) {
5359 return compare_to_true(tval[0],
5360 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5361 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5362 ve::to_float(ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::railroad))));
5363}
5364TRIGGER_FUNCTION(tf_can_build_in_province_fort_no_limit_from_nation) {
5365 return compare_to_true(tval[0],
5366 ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::fort)) < ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::fort)));
5367}
5368TRIGGER_FUNCTION(tf_can_build_in_province_fort_yes_limit_from_nation) {
5369 return compare_to_true(tval[0],
5370 ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::fort)) < ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::fort)));
5371}
5372TRIGGER_FUNCTION(tf_can_build_in_province_fort_no_limit_this_nation) {
5373 return compare_to_true(tval[0],
5374 ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::fort)) < ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::fort)));
5375}
5376TRIGGER_FUNCTION(tf_can_build_in_province_fort_yes_limit_this_nation) {
5377 return compare_to_true(tval[0],
5378 ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::fort)) < ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::fort)));
5379}
5380TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_no_limit_from_nation) {
5381 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5382 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5383 ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::naval_base))) &&
5384 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5385 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5386 ws.world.province_get_state_membership(to_prov(primary_slot))));
5387 return compare_to_true(tval[0], result);
5388}
5389TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_yes_limit_from_nation) {
5390 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5391 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5392 ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::naval_base))) &&
5393 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5394 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5395 ws.world.province_get_state_membership(to_prov(primary_slot))));
5396 return compare_to_true(tval[0], result);
5397}
5398TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_no_limit_this_nation) {
5399 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5400 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5401 ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::naval_base))) &&
5402 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5403 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5404 ws.world.province_get_state_membership(to_prov(primary_slot))));
5405 return compare_to_true(tval[0], result);
5406}
5407TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_yes_limit_this_nation) {
5408 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5409 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5410 ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::naval_base))) &&
5411 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5412 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5413 ws.world.province_get_state_membership(to_prov(primary_slot))));
5414 return compare_to_true(tval[0], result);
5415}
5416TRIGGER_FUNCTION(tf_can_build_railway_in_capital_yes_whole_state_yes_limit) {
5417 // stub: virtually unused
5418 return compare_to_true(tval[0], true);
5419}
5420TRIGGER_FUNCTION(tf_can_build_railway_in_capital_yes_whole_state_no_limit) {
5421 // stub: virtually unused
5422 return compare_to_true(tval[0], true);
5423}
5424TRIGGER_FUNCTION(tf_can_build_railway_in_capital_no_whole_state_yes_limit) {
5425 // stub: virtually unused
5426 return compare_to_true(tval[0], true);
5427}
5428TRIGGER_FUNCTION(tf_can_build_railway_in_capital_no_whole_state_no_limit) {
5429 // stub: virtually unused
5430 return compare_to_true(tval[0], true);
5431}
5432TRIGGER_FUNCTION(tf_can_build_fort_in_capital_yes_whole_state_yes_limit) {
5433 // stub: virtually unused
5434 return compare_to_true(tval[0], true);
5435}
5436TRIGGER_FUNCTION(tf_can_build_fort_in_capital_yes_whole_state_no_limit) {
5437 // stub: virtually unused
5438 return compare_to_true(tval[0], true);
5439}
5440TRIGGER_FUNCTION(tf_can_build_fort_in_capital_no_whole_state_yes_limit) {
5441 // stub: virtually unused
5442 return compare_to_true(tval[0], true);
5443}
5444TRIGGER_FUNCTION(tf_can_build_fort_in_capital_no_whole_state_no_limit) {
5445 // stub: virtually unused
5446 return compare_to_true(tval[0], true);
5447}
5448TRIGGER_FUNCTION(tf_work_available_nation) {
5449 auto type = payload(tval[1]).popt_id;
5450 auto result = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_employment_key(ws, type)) >=
5451 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type));
5452 return compare_to_true(tval[0], result);
5453}
5454TRIGGER_FUNCTION(tf_work_available_state) {
5455 auto type = payload(tval[1]).popt_id;
5456 auto result = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_employment_key(ws, type)) >=
5457 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type));
5458 return compare_to_true(tval[0], result);
5459}
5460TRIGGER_FUNCTION(tf_work_available_province) {
5461 auto type = payload(tval[1]).popt_id;
5462 auto result = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_employment_key(ws, type)) >=
5463 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type));
5464 return compare_to_true(tval[0], result);
5465}
5466TRIGGER_FUNCTION(tf_variable_ideology_name_nation) {
5467 auto id = payload(tval[1]).ideo_id;
5468 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5469 auto support_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, id));
5470 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5471}
5472TRIGGER_FUNCTION(tf_variable_ideology_name_state) {
5473 auto id = payload(tval[1]).ideo_id;
5474 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5475 auto support_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, id));
5476 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5477}
5478TRIGGER_FUNCTION(tf_variable_ideology_name_province) {
5479 auto id = payload(tval[1]).ideo_id;
5480 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5481 auto support_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, id));
5482 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5483}
5484TRIGGER_FUNCTION(tf_variable_ideology_name_pop) {
5485 auto id = payload(tval[1]).ideo_id;
5486 auto total_pop = ws.world.pop_get_size(to_pop(primary_slot));
5487 auto support_pop = ws.world.pop_get_demographics(to_pop(primary_slot), pop_demographics::to_key(ws, id));
5488 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5489}
5490TRIGGER_FUNCTION(tf_variable_issue_name_nation) {
5491 auto id = payload(tval[1]).opt_id;
5492 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5493 auto support_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, id));
5494 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5495}
5496TRIGGER_FUNCTION(tf_variable_issue_name_state) {
5497 auto id = payload(tval[1]).opt_id;
5498 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5499 auto support_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, id));
5500 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5501}
5502TRIGGER_FUNCTION(tf_variable_issue_name_province) {
5503 auto id = payload(tval[1]).opt_id;
5504 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5505 auto support_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, id));
5506 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5507}
5508TRIGGER_FUNCTION(tf_variable_issue_name_pop) {
5509 auto id = payload(tval[1]).opt_id;
5510 auto total_pop = ws.world.pop_get_size(to_pop(primary_slot));
5511 auto support_pop = ws.world.pop_get_demographics(to_pop(primary_slot), pop_demographics::to_key(ws, id));
5512 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5513}
5514TRIGGER_FUNCTION(tf_variable_issue_group_name_nation) {
5515 auto option = payload(tval[2]).opt_id;
5516 auto issue = payload(tval[1]).iss_id;
5517 ;
5518 return compare_values_eq(tval[0], ws.world.nation_get_issues(to_nation(primary_slot), issue), option);
5519}
5520TRIGGER_FUNCTION(tf_variable_issue_group_name_state) {
5521 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
5522 auto option = payload(tval[2]).opt_id;
5523 auto issue = payload(tval[1]).iss_id;
5524 ;
5525 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5526}
5527TRIGGER_FUNCTION(tf_variable_issue_group_name_province) {
5528 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
5529 auto option = payload(tval[2]).opt_id;
5530 auto issue = payload(tval[1]).iss_id;
5531 ;
5532 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5533}
5534TRIGGER_FUNCTION(tf_variable_issue_group_name_pop) {
5535 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
5536 auto option = payload(tval[2]).opt_id;
5537 auto issue = payload(tval[1]).iss_id;
5538 ;
5539 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5540}
5541TRIGGER_FUNCTION(tf_variable_reform_group_name_nation) {
5542 auto option = payload(tval[2]).ropt_id;
5543 auto issue = payload(tval[1]).ref_id;
5544 ;
5545 return compare_values_eq(tval[0], ws.world.nation_get_reforms(to_nation(primary_slot), issue), option);
5546}
5547TRIGGER_FUNCTION(tf_variable_reform_group_name_state) {
5548 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
5549 auto option = payload(tval[2]).ropt_id;
5550 auto issue = payload(tval[1]).ref_id;
5551 ;
5552 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5553}
5554TRIGGER_FUNCTION(tf_variable_reform_group_name_province) {
5555 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
5556 auto option = payload(tval[2]).ropt_id;
5557 auto issue = payload(tval[1]).ref_id;
5558 ;
5559 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5560}
5561TRIGGER_FUNCTION(tf_variable_reform_group_name_pop) {
5562 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
5563 auto option = payload(tval[2]).ropt_id;
5564 auto issue = payload(tval[1]).ref_id;
5565 ;
5566 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5567}
5568TRIGGER_FUNCTION(tf_variable_pop_type_name_nation) {
5569 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5570 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5571 auto size = ws.world.nation_get_demographics(to_nation(primary_slot), type);
5572 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5573}
5574TRIGGER_FUNCTION(tf_variable_pop_type_name_state) {
5575 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5576 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5577 auto size = ws.world.state_instance_get_demographics(to_state(primary_slot), type);
5578 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5579}
5580TRIGGER_FUNCTION(tf_variable_pop_type_name_province) {
5581 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5582 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5583 auto size = ws.world.province_get_demographics(to_prov(primary_slot), type);
5584 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5585}
5586TRIGGER_FUNCTION(tf_variable_pop_type_name_pop) {
5587 auto pop_location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5588 auto total_pop = ws.world.province_get_demographics(pop_location, demographics::total);
5589 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5590 auto size = ws.world.province_get_demographics(pop_location, type);
5591 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5592}
5593TRIGGER_FUNCTION(tf_variable_good_name) {
5594 auto good = payload(tval[1]).com_id;
5595 auto amount = ws.world.nation_get_stockpiles(to_nation(primary_slot), good);
5596 return compare_values(tval[0], amount, read_float_from_payload(tval + 2));
5597}
5598TRIGGER_FUNCTION(tf_religion_nation) {
5599 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), payload(tval[1]).rel_id);
5600}
5601TRIGGER_FUNCTION(tf_religion_nation_reb) {
5602 auto r = ws.world.rebel_faction_get_religion(to_rebel(from_slot));
5603 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), r);
5604}
5605TRIGGER_FUNCTION(tf_religion_nation_from_nation) {
5606 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)),
5607 ws.world.nation_get_religion(to_nation(from_slot)));
5608}
5609TRIGGER_FUNCTION(tf_religion_nation_this_nation) {
5610 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)),
5611 ws.world.nation_get_religion(to_nation(this_slot)));
5612}
5613TRIGGER_FUNCTION(tf_religion_nation_this_state) {
5614 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
5615 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5616}
5617TRIGGER_FUNCTION(tf_religion_nation_this_province) {
5618 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5619 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5620}
5621TRIGGER_FUNCTION(tf_religion_nation_this_pop) {
5622 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
5623 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5624}
5625TRIGGER_FUNCTION(tf_invention) {
5626 auto tid = trigger::payload(tval[1]).invt_id;
5627 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(to_nation(primary_slot), tid));
5628}
5629TRIGGER_FUNCTION(tf_invention_province) {
5630 auto tid = trigger::payload(tval[1]).invt_id;
5631 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)), tid));
5632}
5633TRIGGER_FUNCTION(tf_invention_pop) {
5634 auto tid = trigger::payload(tval[1]).invt_id;
5635 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(nations::owner_of_pop(ws, to_pop(primary_slot)), tid));
5636}
5638 auto sid = trigger::payload(tval[1]).str_id;
5639 auto tid = ws.world.stored_trigger_get_function(sid);
5640 auto test_result = test_trigger_generic<return_type>(ws.trigger_data.data() + ws.trigger_data_indices[tid.index() + 1], ws, primary_slot, this_slot, from_slot);
5641 return compare_to_true(tval[0], test_result);
5642}
5643
5644TRIGGER_FUNCTION(tf_has_building_bank) {
5645 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::bank)) != 0);
5646}
5647TRIGGER_FUNCTION(tf_has_building_university) {
5648 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::university)) != 0);
5649}
5650
5651template<typename return_type, typename primary_type, typename this_type, typename from_type>
5653 constexpr static return_type(
5654 CALLTYPE* trigger_functions[])(uint16_t const*, sys::state&, primary_type, this_type, from_type) = {
5655 tf_none<return_type, primary_type, this_type, from_type>,
5656#define TRIGGER_BYTECODE_ELEMENT(code, name, arg) tf_##name <return_type, primary_type, this_type, from_type>,
5658#undef TRIGGER_BYTECODE_ELEMENT
5659 //
5660 // scopes
5661 //
5662 tf_generic_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t generic_scope = 0x0000; // or & and
5663 tf_x_neighbor_province_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_province_scope = 0x0001;
5664 tf_x_neighbor_country_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_country_scope_nation = 0x0002;
5665 tf_x_neighbor_country_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_country_scope_pop = 0x0003;
5666 tf_x_war_countries_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_war_countries_scope_nation = 0x0004;
5667 tf_x_war_countries_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_war_countries_scope_pop = 0x0005;
5668 tf_x_greater_power_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_greater_power_scope = 0x0006;
5669 tf_x_owned_province_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_owned_province_scope_state = 0x0007;
5670 tf_x_owned_province_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_owned_province_scope_nation = 0x0008;
5671 tf_x_core_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_core_scope_province = 0x0009;
5672 tf_x_core_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_core_scope_nation = 0x000A;
5673 tf_x_state_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_state_scope = 0x000B;
5674 tf_x_substate_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_substate_scope = 0x000C;
5675 tf_x_sphere_member_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_sphere_member_scope = 0x000D;
5676 tf_x_pop_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_province = 0x000E;
5677 tf_x_pop_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_state = 0x000F;
5678 tf_x_pop_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_nation = 0x0010;
5679 tf_x_provinces_in_variable_region<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_provinces_in_variable_region = 0x0011; // variable name
5680 tf_owner_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t owner_scope_state = 0x0012;
5681 tf_owner_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t owner_scope_province = 0x0013;
5682 tf_controller_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t controller_scope = 0x0014;
5683 tf_location_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t location_scope = 0x0015;
5684 tf_country_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_state = 0x0016;
5685 tf_country_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_pop = 0x0017;
5686 tf_capital_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t capital_scope = 0x0018;
5687 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_pop = 0x0019;
5688 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_nation = 0x001A;
5689 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_state = 0x001B;
5690 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_province = 0x001C;
5691 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_pop = 0x001D;
5692 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_nation = 0x001E;
5693 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_state = 0x001F;
5694 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_province = 0x0020;
5695 tf_sea_zone_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t sea_zone_scope = 0x0021;
5696 tf_cultural_union_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t cultural_union_scope = 0x0022;
5697 tf_overlord_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t overlord_scope = 0x0023;
5698 tf_sphere_owner_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t sphere_owner_scope = 0x0024;
5699 tf_independence_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t independence_scope = 0x0025;
5700 tf_flashpoint_tag_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t flashpoint_tag_scope = 0x0026;
5701 tf_crisis_state_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t crisis_state_scope = 0x0027;
5702 tf_state_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t state_scope_pop = 0x0028;
5703 tf_state_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t state_scope_province = 0x0029;
5704 tf_tag_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t tag_scope = 0x002A; // variable name
5705 tf_integer_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t integer_scope = 0x002B; // variable name
5706 tf_country_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_nation = 0x002C;
5707 tf_country_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_province = 0x002D;
5708 tf_cultural_union_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t cultural_union_scope_pop = 0x002E;
5709 tf_capital_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t capital_scope_province = 0x002F;
5710 tf_capital_scope_pop, //constexpr inline uint16_t capital_scope_pop = first_scope_code + 0x0030;
5711 tf_x_country_scope, //constexpr inline uint16_t x_country_scope = first_scope_code + 0x0031;
5712 tf_x_neighbor_province_scope_state, //constexpr inline uint16_t x_neighbor_province_scope_state = first_scope_code + 0x0032;
5713 tf_x_provinces_in_variable_region_proper, //constexpr inline uint16_t x_provinces_in_variable_region_proper = first_scope_code + 0x0033;
5714 };
5715};
5716
5717template<typename return_type, typename primary_type, typename this_type, typename from_type>
5718return_type CALLTYPE test_trigger_generic(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot,
5719 from_type from_slot) {
5721 ws, primary_slot, this_slot, from_slot);
5722}
5723
5724#undef CALLTYPE
5725#undef TRIGGER_FUNCTION
5726
5727float evaluate_multiplicative_modifier(sys::state& state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot) {
5728 auto base = state.value_modifiers[modifier];
5729 float product = base.factor;
5730 for(uint32_t i = 0; i < base.segments_count && product != 0; ++i) {
5731 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5732 if(seg.condition) {
5733 if(test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary,
5734 this_slot, from_slot)) {
5735 product *= seg.factor;
5736 }
5737 }
5738 }
5739 return product;
5740}
5741float evaluate_additive_modifier(sys::state& state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot) {
5742 auto base = state.value_modifiers[modifier];
5743 float sum = base.base;
5744 for(uint32_t i = 0; i < base.segments_count; ++i) {
5745 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5746 if(seg.condition) {
5747 if(test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary,
5748 this_slot, from_slot)) {
5749 sum += seg.factor;
5750 }
5751 }
5752 }
5753 return sum * base.factor;
5754}
5755
5756ve::fp_vector evaluate_multiplicative_modifier(sys::state& state, dcon::value_modifier_key modifier, ve::contiguous_tags<int32_t> primary, ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5757 auto base = state.value_modifiers[modifier];
5758 ve::fp_vector product = base.factor;
5759 for(uint32_t i = 0; i < base.segments_count; ++i) {
5760 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5761 if(seg.condition) {
5762 auto res = test_trigger_generic<ve::mask_vector>(
5763 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5764 product = ve::select(res, product * seg.factor, product);
5765 }
5766 }
5767 return product;
5768}
5769ve::fp_vector evaluate_additive_modifier(sys::state& state, dcon::value_modifier_key modifier, ve::contiguous_tags<int32_t> primary, ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5770 auto base = state.value_modifiers[modifier];
5771 ve::fp_vector sum = base.base;
5772 for(uint32_t i = 0; i < base.segments_count; ++i) {
5773 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5774 if(seg.condition) {
5775 auto res = test_trigger_generic<ve::mask_vector>(
5776 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5777 sum = ve::select(res, sum + seg.factor, sum);
5778 }
5779 }
5780 return sum * base.factor;
5781}
5782
5783ve::fp_vector evaluate_multiplicative_modifier(sys::state& state, dcon::value_modifier_key modifier, ve::contiguous_tags<int32_t> primary, ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5784 auto base = state.value_modifiers[modifier];
5785 ve::fp_vector product = base.factor;
5786 for(uint32_t i = 0; i < base.segments_count; ++i) {
5787 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5788 if(seg.condition) {
5789 auto res = test_trigger_generic<ve::mask_vector>(
5790 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5791 product = ve::select(res, product * seg.factor, product);
5792 }
5793 }
5794 return product;
5795}
5796ve::fp_vector evaluate_additive_modifier(sys::state& state, dcon::value_modifier_key modifier, ve::contiguous_tags<int32_t> primary, ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5797 auto base = state.value_modifiers[modifier];
5798 ve::fp_vector sum = base.base;
5799 for(uint32_t i = 0; i < base.segments_count; ++i) {
5800 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5801 if(seg.condition) {
5802 auto res = test_trigger_generic<ve::mask_vector>(
5803 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5804 sum = ve::select(res, sum + seg.factor, sum);
5805 }
5806 }
5807 return sum * base.factor;
5808}
5809
5810bool evaluate(sys::state& state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot) {
5811 return test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state, primary,
5812 this_slot, from_slot);
5813}
5814bool evaluate(sys::state& state, uint16_t const* data, int32_t primary, int32_t this_slot, int32_t from_slot) {
5815 return test_trigger_generic<bool>(data, state, primary, this_slot, from_slot);
5816}
5817
5818ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::contiguous_tags<int32_t> primary,
5819 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5820 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5821 primary, this_slot, from_slot);
5822}
5823ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::contiguous_tags<int32_t> primary,
5824 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5825 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5826}
5827
5828ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::tagged_vector<int32_t> primary,
5829 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5830 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5831 primary, this_slot, from_slot);
5832}
5833ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::tagged_vector<int32_t> primary,
5834 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5835 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5836}
5837
5838ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::contiguous_tags<int32_t> primary,
5839 ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5840 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5841 primary, this_slot, from_slot);
5842}
5843ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::contiguous_tags<int32_t> primary,
5844 ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5845 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5846}
5847
5848} // namespace trigger
void add_value(int32_t v)
Definition: triggers.cpp:303
void add_value(int32_t v)
Definition: triggers.cpp:270
#define B(name, bit)
Definition: cpu.h:216
#define C(name, bit)
Definition: cpu.h:242
#define CALLTYPE
#define TRIGGER_FUNCTION(function_name)
constexpr dcon::demographics_key rich_life_needs(13)
constexpr dcon::demographics_key poor_luxury_needs(17)
constexpr dcon::demographics_key middle_life_needs(12)
constexpr dcon::demographics_key rich_militancy(10)
constexpr dcon::demographics_key middle_total(21)
constexpr dcon::demographics_key middle_luxury_needs(18)
constexpr dcon::demographics_key political_reform_desire(6)
constexpr dcon::demographics_key total(0)
constexpr dcon::demographics_key rich_everyday_needs(16)
constexpr dcon::demographics_key poor_militancy(8)
constexpr dcon::demographics_key rich_luxury_needs(19)
constexpr dcon::demographics_key poor_everyday_needs(14)
constexpr dcon::demographics_key middle_militancy(9)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr dcon::demographics_key employable(1)
constexpr dcon::demographics_key consciousness(3)
constexpr dcon::demographics_key rich_total(22)
constexpr dcon::demographics_key poor_total(20)
constexpr dcon::demographics_key poor_life_needs(11)
constexpr dcon::demographics_key employed(2)
dcon::demographics_key to_employment_key(sys::state const &state, dcon::pop_type_id v)
constexpr dcon::demographics_key social_reform_desire(7)
constexpr dcon::demographics_key literacy(5)
constexpr dcon::demographics_key middle_everyday_needs(15)
constexpr dcon::demographics_key militancy(4)
bool has_building(sys::state const &state, dcon::state_instance_id si, dcon::factory_type_id fac)
Definition: economy.cpp:384
bool is_bankrupt_debtor_to(sys::state &state, dcon::nation_id debt_holder, dcon::nation_id debtor)
Definition: economy.cpp:398
bool has_factory(sys::state const &state, dcon::state_instance_id si)
Definition: economy.cpp:128
constexpr dcon::commodity_id money(0)
auto desired_needs_spending(sys::state const &state, T pop_indices)
Definition: economy.hpp:113
constexpr uint32_t slavery_allowed
Definition: culture.hpp:27
constexpr uint32_t pop_build_factory
Definition: culture.hpp:14
float recruited_pop_fraction(sys::state const &state, dcon::nation_id n)
Definition: military.cpp:457
bool can_use_cb_against(sys::state &state, dcon::nation_id from, dcon::nation_id target)
Definition: military.cpp:95
bool state_has_naval_base(sys::state const &state, dcon::state_instance_id si)
Definition: military.cpp:463
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:475
bool province_is_blockaded(sys::state const &state, dcon::province_id ids)
Definition: military.cpp:422
auto battle_is_ongoing_in_province(sys::state const &state, T ids)
constexpr uint8_t level_in_sphere
Definition: nations.hpp:169
constexpr uint8_t level_mask
Definition: nations.hpp:163
auto central_reb_controlled_fraction(sys::state const &state, T ids)
bool is_great_power(sys::state const &state, dcon::nation_id id)
Definition: nations.cpp:503
bool can_release_as_vassal(sys::state const &state, dcon::nation_id n, dcon::national_identity_id releasable)
Definition: nations.cpp:176
auto occupied_provinces_fraction(sys::state const &state, T ids)
auto primary_culture_group(sys::state const &state, T ids)
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
Definition: nations.cpp:69
auto central_blockaded_fraction(sys::state const &state, T ids)
auto central_has_crime_fraction(sys::state const &state, T ids)
auto nation_accepts_culture(sys::state const &state, T ids, U cul_ids)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
constexpr uint8_t impassible_bit
Definition: constants.hpp:595
bool is_overseas(sys::state const &state, dcon::province_id ids)
Definition: province.cpp:18
bool state_is_coastal(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1476
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
dcon::state_instance_id to_state(int32_t v)
Definition: triggers.hpp:136
auto unowned_core_accumulator(sys::state const &ws, dcon::nation_id n)
Definition: triggers.cpp:1619
constexpr uint16_t code_mask
int32_t get_trigger_scope_payload_size(uint16_t const *data)
return_type CALLTYPE test_trigger_generic(uint16_t const *tval, sys::state &ws, primary_type primary_slot, this_type this_slot, from_type from_slot)
Definition: triggers.cpp:5718
constexpr uint16_t is_disjunctive_scope
dcon::pop_id to_pop(int32_t v)
Definition: triggers.hpp:120
dcon::province_id to_prov(int32_t v)
Definition: triggers.hpp:88
auto compare_to_true(uint16_t trigger_code, A value_a) -> decltype(!value_a)
Definition: triggers.cpp:81
int32_t read_int32_t_from_payload(uint16_t const *data)
Definition: triggers.cpp:132
auto internal_tf_culture_accepted(sys::state &ws, N nids, C cids)
Definition: triggers.cpp:3004
typename gathered_s< T >::type gathered_t
Definition: triggers.cpp:168
auto make_value_accumulator(F &&f) -> value_accumulator< TAG, F >
Definition: triggers.cpp:367
auto compare_to_false(uint16_t trigger_code, A value_a) -> decltype(!value_a)
Definition: triggers.cpp:100
auto compare_values_eq(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a==value_b)
Definition: triggers.cpp:40
auto make_true_accumulator(F &&f) -> true_accumulator< F >
Definition: triggers.cpp:357
dcon::rebel_faction_id to_rebel(int32_t v)
Definition: triggers.hpp:152
bool compare(bool a, bool b)
Definition: triggers.cpp:203
auto compare_values(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a==value_b)
Definition: triggers.cpp:20
constexpr uint16_t association_gt
constexpr uint16_t association_le
auto existence_accumulator(sys::state &ws, uint16_t const *tval, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:371
float read_float_from_payload(uint16_t const *data)
Definition: triggers.cpp:118
constexpr uint16_t association_ge
constexpr uint16_t association_mask
auto universal_accumulator(sys::state &ws, uint16_t const *tval, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:377
float evaluate_additive_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5741
auto empty_province_from_state_accumulator(sys::state const &ws, dcon::state_instance_id sid)
Definition: triggers.cpp:1249
dcon::nation_id to_nation(int32_t v)
Definition: triggers.hpp:104
constexpr uint16_t association_lt
constexpr uint16_t is_existence_scope
int32_t trigger_scope_data_payload(uint16_t code)
int32_t get_trigger_payload_size(uint16_t const *data)
auto make_false_accumulator(F &&f) -> false_accumulator< F >
Definition: triggers.cpp:362
float evaluate_multiplicative_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5727
constexpr uint16_t association_ne
auto empty_province_accumulator(sys::state const &ws)
Definition: triggers.cpp:1221
constexpr uint16_t association_eq
T select(bool v, T a, T b)
bool compress_mask(bool v)
float to_float(int32_t a)
uint uint32_t
uchar uint8_t
@ ident
#define TRIGGER_BYTECODE_LIST
dcon::province_id first_sea_province
Definition: province.hpp:26
dcon::data_container world
province::global_provincial_state province_definitions
static constexpr return_type(CALLTYPE *trigger_functions[])(uint16_t const *
static constexpr sys::state from_type
Definition: triggers.cpp:5654
#define CALLTYPE
Definition: triggers.cpp:16
#define TRIGGER_FUNCTION(function_name)
Definition: triggers.cpp:174
dcon::national_identity_id tag_id
dcon::culture_id cul_id
dcon::stored_trigger_id str_id
dcon::national_variable_id natv_id
dcon::invention_id invt_id
dcon::national_focus_id nf_id
dcon::province_id prov_id
dcon::ideology_id ideo_id
dcon::issue_id iss_id
dcon::technology_id tech_id
dcon::reform_id ref_id
dcon::reform_option_id ropt_id
dcon::state_definition_id state_id
dcon::pop_type_id popt_id
dcon::issue_option_id opt_id
dcon::commodity_id com_id
dcon::rebel_type_id reb_id
dcon::region_id reg_id
dcon::modifier_id mod_id