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#include "politics.hpp"
11
12namespace trigger {
13
14#ifdef WIN32
15#define CALLTYPE __vectorcall
16#else
17#define CALLTYPE
18#endif
19
20template<typename A, typename B>
21[[nodiscard]] auto compare_values(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a == value_b) {
22 switch(trigger_code & trigger::association_mask) {
24 return value_a == value_b;
26 return value_a > value_b;
28 return value_a < value_b;
30 return value_a <= value_b;
32 return value_a != value_b;
34 return value_a >= value_b;
35 default:
36 return value_a >= value_b;
37 }
38}
39
40template<typename A, typename B>
41[[nodiscard]] auto compare_values_eq(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a == value_b) {
42 switch(trigger_code & trigger::association_mask) {
44 return value_a == value_b;
46 return value_a != value_b;
48 return value_a != value_b;
50 return value_a == value_b;
52 return value_a != value_b;
54 return value_a == value_b;
55 default:
56 return value_a == value_b;
57 }
58}
59
60template<typename B>
61[[nodiscard]] auto compare_values_eq(uint16_t trigger_code, dcon::nation_fat_id value_a, B value_b)
62 -> decltype(value_a.id == value_b) {
63 switch(trigger_code & trigger::association_mask) {
65 return value_a.id == value_b;
67 return value_a.id != value_b;
69 return value_a.id != value_b;
71 return value_a.id == value_b;
73 return value_a.id != value_b;
75 return value_a.id == value_b;
76 default:
77 return value_a.id == value_b;
78 }
79}
80
81template<typename A>
82[[nodiscard]] auto compare_to_true(uint16_t trigger_code, A value_a) -> decltype(!value_a) {
83 switch(trigger_code & trigger::association_mask) {
85 return value_a;
87 return !value_a;
89 return !value_a;
91 return value_a;
93 return !value_a;
95 return value_a;
96 default:
97 return value_a;
98 }
99}
100template<typename A>
101[[nodiscard]] auto compare_to_false(uint16_t trigger_code, A value_a) -> decltype(!value_a) {
102 switch(trigger_code & trigger::association_mask) {
104 return !value_a;
106 return value_a;
108 return value_a;
110 return !value_a;
112 return value_a;
114 return !value_a;
115 default:
116 return !value_a;
117 }
118}
119float read_float_from_payload(uint16_t const* data) {
120 union {
121 struct {
122 uint16_t low;
123 uint16_t high;
124 } v;
125 float f;
126 } pack_float;
127
128 pack_float.v.low = data[0];
129 pack_float.v.high = data[1];
130
131 return pack_float.f;
132}
133int32_t read_int32_t_from_payload(uint16_t const* data) {
134 union {
135 struct {
136 uint16_t low;
137 uint16_t high;
138 } v;
139 int32_t f;
140 } pack_float;
141
142 pack_float.v.low = data[0];
143 pack_float.v.high = data[1];
144
145 return pack_float.f;
146}
147
148template<typename T>
150 using type = T;
151};
152
153template<>
154struct gathered_s<ve::contiguous_tags<int32_t>> {
155 using type = ve::tagged_vector<int32_t>;
156};
157
158template<>
159struct gathered_s<ve::unaligned_contiguous_tags<int32_t>> {
160 using type = ve::tagged_vector<int32_t>;
161};
162
163template<>
164struct gathered_s<ve::partial_contiguous_tags<int32_t>> {
165 using type = ve::tagged_vector<int32_t>;
166};
167
168template<typename T>
170
171template<typename return_type, typename primary_type, typename this_type, typename from_type>
172return_type CALLTYPE test_trigger_generic(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot,
173 from_type from_slot);
174
175#define TRIGGER_FUNCTION(function_name) \
176 template<typename return_type, typename primary_type, typename this_type, typename from_type> \
177 return_type CALLTYPE function_name(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot, \
178 from_type from_slot)
179
180template<typename T>
181struct full_mask { };
182
183template<>
184struct full_mask<bool> {
185 static constexpr bool value = true;
186};
187template<>
188struct full_mask<ve::vbitfield_type> {
189 static constexpr ve::vbitfield_type value = ve::vbitfield_type{ve::vbitfield_type::storage(-1)};
190};
191
192template<typename T>
193struct empty_mask { };
194
195template<>
196struct empty_mask<bool> {
197 static constexpr bool value = false;
198};
199template<>
200struct empty_mask<ve::vbitfield_type> {
201 static constexpr ve::vbitfield_type value = ve::vbitfield_type{ve::vbitfield_type::storage(0)};
202};
203
204bool compare(bool a, bool b) {
205 return a == b;
206}
207bool compare(ve::vbitfield_type a, ve::vbitfield_type b) {
208 return a.v == b.v;
209}
210
211TRIGGER_FUNCTION(apply_disjuctively) {
212 auto const source_size = 1 + get_trigger_scope_payload_size(tval);
213 auto sub_units_start = tval + 2 + trigger_scope_data_payload(tval[0]);
214
215 return_type result = return_type(false);
216 while(sub_units_start < tval + source_size) {
217 result = result | test_trigger_generic<return_type, primary_type, this_type, from_type>(sub_units_start, ws, primary_slot, this_slot, from_slot);
218 auto compressed_res = ve::compress_mask(result);
219 if(compare(compressed_res, full_mask<decltype(compressed_res)>::value))
220 return result;
221 sub_units_start += 1 + get_trigger_payload_size(sub_units_start);
222 }
223 return result;
224}
225
226TRIGGER_FUNCTION(apply_conjuctively) {
227 auto const source_size = 1 + get_trigger_scope_payload_size(tval);
228 auto sub_units_start = tval + 2 + trigger_scope_data_payload(tval[0]);
229
230 return_type result = return_type(true);
231 while(sub_units_start < tval + source_size) {
232 result = result & test_trigger_generic<return_type, primary_type, this_type, from_type>(sub_units_start, ws, primary_slot, this_slot, from_slot);
233 auto compressed_res = ve::compress_mask(result);
234 if(compare(compressed_res, empty_mask<decltype(compressed_res)>::value))
235 return result;
236 sub_units_start += 1 + get_trigger_payload_size(sub_units_start);
237 }
238 return result;
239}
240
241TRIGGER_FUNCTION(apply_subtriggers) {
242 if((*tval & trigger::is_disjunctive_scope) != 0)
243 return apply_disjuctively<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
244 else
245 return apply_conjuctively<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
246}
247
249 return return_type(true);
250}
251TRIGGER_FUNCTION(tf_unused_1) {
252 return return_type(true);
253}
254
255TRIGGER_FUNCTION(tf_generic_scope) {
256 return apply_subtriggers<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
257}
258
259template<typename F>
260class true_accumulator : public F {
261private:
262 ve::tagged_vector<int32_t> value;
263 uint32_t index = 0;
264 int32_t accumulated_mask = 0;
265
266public:
267 bool result = false;
268
269 true_accumulator(F&& f) : F(std::move(f)) { }
270
271 void add_value(int32_t v) {
272 if(!result) {
273 accumulated_mask |= (int32_t(v != -1) << index);
274 value.set(index++, v);
275
276 if(index == ve::vector_size) {
277 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) != 0;
278 value = ve::tagged_vector<int32_t>();
279 index = 0;
280 accumulated_mask = 0;
281 }
282 }
283 }
284 void flush() {
285 if(index != 0 && !result) {
286 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) != 0;
287 index = 0;
288 }
289 }
290};
291
292template<typename F>
293class false_accumulator : public F {
294private:
295 ve::tagged_vector<int32_t> value;
296 uint32_t index = 0;
297 int32_t accumulated_mask = 0;
298
299public:
300 bool result = true;
301
302 false_accumulator(F&& f) : F(std::move(f)) { }
303
304 void add_value(int32_t v) {
305 if(result) {
306 accumulated_mask |= (int32_t(v != -1) << index);
307 value.set(index++, v);
308
309 if(index == ve::vector_size) {
310 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) == accumulated_mask;
311 value = ve::tagged_vector<int32_t>();
312 index = 0;
313 accumulated_mask = 0;
314 }
315 }
316 }
317 void flush() {
318 if(index != 0 && result) {
319 result = (ve::compress_mask(F::operator()(value)).v & accumulated_mask) == accumulated_mask;
320 index = 0;
321 }
322 }
323};
324
325template<typename TAG, typename F>
326class value_accumulator : public F {
327private:
328 ve::fp_vector value;
329 ve::tagged_vector<TAG> store;
330
331 uint32_t index = 0;
332 int32_t accumulated_mask = 0;
333
334public:
335 value_accumulator(F&& f) : F(std::move(f)) { }
336
337 void add_value(TAG v) {
338 accumulated_mask |= (int32_t(is_valid_index(v)) << index);
339 store.set(index++, v);
340
341 if(index == ve::vector_size) {
342 value = value + ve::select(accumulated_mask, F::operator()(store), 0.0f);
343 index = 0;
344 accumulated_mask = 0;
345 }
346 }
347 float flush() {
348 if(index != 0) {
349 value = value + ve::select(accumulated_mask, F::operator()(store), 0.0f);
350 index = 0;
351 }
352
353 return value.reduce();
354 }
355};
356
357template<typename F>
359 return true_accumulator<F>(std::forward<F>(f));
360}
361
362template<typename F>
364 return false_accumulator<F>(std::forward<F>(f));
365}
366
367template<typename TAG, typename F>
369 return value_accumulator<TAG, F>(std::forward<F>(f));
370}
371
372auto existence_accumulator(sys::state& ws, uint16_t const* tval, int32_t this_slot, int32_t from_slot) {
373 return make_true_accumulator([&ws, tval, this_slot, from_slot](ve::tagged_vector<int32_t> v) {
374 return apply_subtriggers<ve::mask_vector, ve::tagged_vector<int32_t>, int32_t, int32_t>(tval, ws, v, this_slot, from_slot);
375 });
376}
377
378auto universal_accumulator(sys::state& ws, uint16_t const* tval, int32_t this_slot, int32_t from_slot) {
379 return make_false_accumulator([&ws, tval, this_slot, from_slot](ve::tagged_vector<int32_t> v) {
380 return apply_subtriggers<ve::mask_vector, ve::tagged_vector<int32_t>, int32_t, int32_t>(tval, ws, v, this_slot, from_slot);
381 });
382}
383
384TRIGGER_FUNCTION(tf_x_neighbor_province_scope) {
385 return ve::apply(
386 [&ws, tval](int32_t prov_id, int32_t t_slot, int32_t f_slot) {
387 auto prov_tag = to_prov(prov_id);
388
389 if(*tval & trigger::is_existence_scope) {
390 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
391
392 for(auto adj : ws.world.province_get_province_adjacency(prov_tag)) {
393 if((adj.get_type() & province::border::impassible_bit) == 0) {
394 auto other = adj.get_connected_provinces(prov_tag == adj.get_connected_provinces(0) ? 1 : 0).id;
395 accumulator.add_value(to_generic(other));
396 }
397 }
398 accumulator.flush();
399
400 return accumulator.result;
401 } else {
402 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
403
404 for(auto adj : ws.world.province_get_province_adjacency(prov_tag)) {
405 if((adj.get_type() & province::border::impassible_bit) == 0) {
406 auto other = adj.get_connected_provinces(prov_tag == adj.get_connected_provinces(0) ? 1 : 0).id;
407 accumulator.add_value(to_generic(other));
408 }
409 }
410 accumulator.flush();
411
412 return accumulator.result;
413 }
414 },
415 primary_slot, this_slot, from_slot);
416}
417TRIGGER_FUNCTION(tf_x_neighbor_province_scope_state) {
418 return ve::apply(
419 [&ws, tval](int32_t s_id, int32_t t_slot, int32_t f_slot) {
420 auto state_tag = to_state(s_id);
421
422 std::vector<dcon::province_id> vadj;
423 vadj.reserve(32);
424
425 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(state_tag))) {
426 if(p.get_province().get_state_membership() == state_tag) {
427 for(auto adj : p.get_province().get_province_adjacency()) {
428 if((adj.get_type() & province::border::impassible_bit) == 0) {
429 auto other = (p.get_province() == adj.get_connected_provinces(0)) ? adj.get_connected_provinces(1).id : adj.get_connected_provinces(0).id;
430 if(std::find(vadj.begin(), vadj.end(), other) == vadj.end())
431 vadj.push_back(other);
432 }
433 }
434 }
435 }
436
437 if(*tval & trigger::is_existence_scope) {
438 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
439
440 for(auto p : vadj)
441 accumulator.add_value(to_generic(p));
442
443 accumulator.flush();
444 return accumulator.result;
445 } else {
446 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
447
448 for(auto p : vadj)
449 accumulator.add_value(to_generic(p));
450
451 accumulator.flush();
452 return accumulator.result;
453 }
454 },
455 primary_slot, this_slot, from_slot);
456}
457TRIGGER_FUNCTION(tf_x_neighbor_country_scope_nation) {
458 return ve::apply(
459 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
460 auto nid = to_nation(p_slot);
461
462 if(*tval & trigger::is_existence_scope) {
463 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
464
465 for(auto adj : ws.world.nation_get_nation_adjacency(nid)) {
466 auto iid = (nid == adj.get_connected_nations(0)) ? adj.get_connected_nations(1).id : adj.get_connected_nations(0).id;
467
468 accumulator.add_value(to_generic(iid));
469 if(accumulator.result)
470 return true;
471 }
472 accumulator.flush();
473
474 return accumulator.result;
475 } else {
476 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
477 for(auto adj : ws.world.nation_get_nation_adjacency(nid)) {
478 auto iid = (nid == adj.get_connected_nations(0)) ? adj.get_connected_nations(1).id : adj.get_connected_nations(0).id;
479
480 accumulator.add_value(to_generic(iid));
481 if(!accumulator.result)
482 return false;
483 }
484 accumulator.flush();
485
486 return accumulator.result;
487 }
488 },
489 primary_slot, this_slot, from_slot);
490}
491TRIGGER_FUNCTION(tf_x_neighbor_country_scope_pop) {
492 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
493 auto province_owner = ws.world.province_get_nation_from_province_ownership(location);
494
495 return tf_x_neighbor_country_scope_nation<return_type>(tval, ws, to_generic(province_owner), this_slot, from_slot);
496}
497TRIGGER_FUNCTION(tf_x_war_countries_scope_nation) {
498 return ve::apply(
499 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
500 auto nid = to_nation(p_slot);
501
502 if(*tval & trigger::is_existence_scope) {
503 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
504
505 for(auto wars_in : ws.world.nation_get_war_participant(nid)) {
506 auto is_attacker = wars_in.get_is_attacker();
507 for(auto o : wars_in.get_war().get_war_participant()) {
508 if(o.get_is_attacker() != is_attacker && o.get_nation() != nid) {
509 accumulator.add_value(to_generic(o.get_nation().id));
510 if(accumulator.result)
511 return true;
512 }
513 }
514 }
515
516 accumulator.flush();
517 return accumulator.result;
518 } else {
519 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
520
521 for(auto wars_in : ws.world.nation_get_war_participant(nid)) {
522 auto is_attacker = wars_in.get_is_attacker();
523 for(auto o : wars_in.get_war().get_war_participant()) {
524 if(o.get_is_attacker() != is_attacker && o.get_nation() != nid) {
525 accumulator.add_value(to_generic(o.get_nation().id));
526 if(!accumulator.result)
527 return false;
528 }
529 }
530 }
531
532 accumulator.flush();
533 return accumulator.result;
534 }
535 },
536 primary_slot, this_slot, from_slot);
537}
538TRIGGER_FUNCTION(tf_x_war_countries_scope_pop) {
539 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
540 auto province_owner = ws.world.province_get_nation_from_province_ownership(location);
541
542 return tf_x_war_countries_scope_nation<return_type>(tval, ws, to_generic(province_owner), this_slot, from_slot);
543}
544TRIGGER_FUNCTION(tf_x_country_scope) {
545 return ve::apply(
546 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
547 if(*tval & trigger::is_existence_scope) {
548 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
549
550 uint32_t added = 0;
551 for(auto n : ws.world.in_nation) {
552 if(n.get_owned_province_count() != 0) {
553 accumulator.add_value(to_generic(n.id));
554 if(accumulator.result)
555 return true;
556 }
557 }
558
559 accumulator.flush();
560 return accumulator.result;
561 } else {
562 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
563
564 for(auto n : ws.world.in_nation) {
565 if(n.get_owned_province_count() != 0) {
566 accumulator.add_value(to_generic(n.id));
567 if(!accumulator.result)
568 return false;
569 }
570 }
571
572 accumulator.flush();
573 return accumulator.result;
574 }
575 },
576 primary_slot, this_slot, from_slot);
577}
578TRIGGER_FUNCTION(tf_x_greater_power_scope) {
579 return ve::apply(
580 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
581 uint32_t great_nations_count = uint32_t(ws.defines.great_nations_count);
582
583 if(*tval & trigger::is_existence_scope) {
584 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
585
586 uint32_t added = 0;
587 for(uint32_t i = 0; i < ws.nations_by_rank.size() && added < great_nations_count; ++i) {
588 if(nations::is_great_power(ws, ws.nations_by_rank[i])) {
589 ++added;
590 accumulator.add_value(to_generic(ws.nations_by_rank[i]));
591 if(accumulator.result)
592 return true;
593 }
594 }
595
596 accumulator.flush();
597 return accumulator.result;
598 } else {
599 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
600
601 uint32_t added = 0;
602 for(uint32_t i = 0; i < ws.nations_by_rank.size() && added < great_nations_count; ++i) {
603 if(nations::is_great_power(ws, ws.nations_by_rank[i])) {
604 ++added;
605 accumulator.add_value(to_generic(ws.nations_by_rank[i]));
606 if(!accumulator.result)
607 return false;
608 }
609 }
610
611 accumulator.flush();
612 return accumulator.result;
613 }
614 },
615 primary_slot, this_slot, from_slot);
616}
617TRIGGER_FUNCTION(tf_x_owned_province_scope_state) {
618 return ve::apply(
619 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
620 auto sid = to_state(p_slot);
621 dcon::state_definition_fat_id state_def = fatten(ws.world, ws.world.state_instance_get_definition(sid));
622 auto owner = ws.world.state_instance_get_nation_from_state_ownership(sid);
623
624 if(*tval & trigger::is_existence_scope) {
625 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
626
627 for(auto p : state_def.get_abstract_state_membership()) {
628 if(p.get_province().get_nation_from_province_ownership() == owner) {
629 accumulator.add_value(to_generic(p.get_province().id));
630 if(accumulator.result)
631 return true;
632 }
633 }
634
635 accumulator.flush();
636 return accumulator.result;
637 } else {
638 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
639
640 for(auto p : state_def.get_abstract_state_membership()) {
641 if(p.get_province().get_nation_from_province_ownership() == owner) {
642 accumulator.add_value(to_generic(p.get_province().id));
643 if(!accumulator.result)
644 return false;
645 }
646 }
647
648 accumulator.flush();
649 return accumulator.result;
650 }
651 },
652 primary_slot, this_slot, from_slot);
653}
654TRIGGER_FUNCTION(tf_x_owned_province_scope_nation) {
655 return ve::apply(
656 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
657 auto nid = fatten(ws.world, to_nation(p_slot));
658
659 if(*tval & trigger::is_existence_scope) {
660 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
661
662 for(auto p : nid.get_province_ownership()) {
663 accumulator.add_value(to_generic(p.get_province().id));
664 if(accumulator.result)
665 return true;
666 }
667
668 accumulator.flush();
669 return accumulator.result;
670 } else {
671 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
672
673 for(auto p : nid.get_province_ownership()) {
674 accumulator.add_value(to_generic(p.get_province().id));
675 if(!accumulator.result)
676 return false;
677 }
678
679 accumulator.flush();
680 return accumulator.result;
681 }
682 },
683 primary_slot, this_slot, from_slot);
684}
685TRIGGER_FUNCTION(tf_x_core_scope_province) {
686 return ve::apply(
687 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
688 dcon::province_fat_id pid = fatten(ws.world, to_prov(p_slot));
689
690 if(*tval & trigger::is_existence_scope) {
691 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
692
693 for(auto p : pid.get_core()) {
694 auto holder = p.get_identity().get_nation_from_identity_holder();
695 if(holder) {
696 accumulator.add_value(to_generic(holder.id));
697 if(accumulator.result)
698 return true;
699 }
700 }
701
702 accumulator.flush();
703 return accumulator.result;
704 } else {
705 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
706
707 for(auto p : pid.get_core()) {
708 auto holder = p.get_identity().get_nation_from_identity_holder();
709 if(holder) {
710 accumulator.add_value(to_generic(holder.id));
711 if(!accumulator.result)
712 return false;
713 }
714 }
715
716 accumulator.flush();
717 return accumulator.result;
718 }
719 },
720 primary_slot, this_slot, from_slot);
721}
722TRIGGER_FUNCTION(tf_x_core_scope_nation) {
723 return ve::apply(
724 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
725 auto nid = fatten(ws.world, to_nation(p_slot));
726 auto ident = nid.get_identity_holder_as_nation().get_identity();
727
728 if(*tval & trigger::is_existence_scope) {
729 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
730
731 for(auto p : ident.get_core()) {
732 accumulator.add_value(to_generic(p.get_province().id));
733 if(accumulator.result)
734 return true;
735 }
736
737 accumulator.flush();
738 return accumulator.result;
739 } else {
740 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
741
742 for(auto p : ident.get_core()) {
743 accumulator.add_value(to_generic(p.get_province().id));
744 if(!accumulator.result)
745 return false;
746 }
747
748 accumulator.flush();
749 return accumulator.result;
750 }
751 },
752 primary_slot, this_slot, from_slot);
753}
754
755TRIGGER_FUNCTION(tf_x_state_scope) {
756 return ve::apply(
757 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
758 auto nid = fatten(ws.world, to_nation(p_slot));
759
760 if(*tval & trigger::is_existence_scope) {
761 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
762
763 for(auto s : nid.get_state_ownership()) {
764 accumulator.add_value(to_generic(s.get_state().id));
765 if(accumulator.result)
766 return true;
767 }
768
769 accumulator.flush();
770 return accumulator.result;
771 } else {
772 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
773
774 for(auto s : nid.get_state_ownership()) {
775 accumulator.add_value(to_generic(s.get_state().id));
776 if(!accumulator.result)
777 return false;
778 }
779
780 accumulator.flush();
781 return accumulator.result;
782 }
783 },
784 primary_slot, this_slot, from_slot);
785}
786TRIGGER_FUNCTION(tf_x_substate_scope) {
787 return ve::apply(
788 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
789 auto nid = fatten(ws.world, to_nation(p_slot));
790
791 if(*tval & trigger::is_existence_scope) {
792 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
793
794 for(auto v : nid.get_overlord_as_ruler()) {
795 if(v.get_subject().get_is_substate()) {
796 accumulator.add_value(to_generic(v.get_subject().id));
797 if(accumulator.result)
798 return true;
799 }
800 }
801
802 accumulator.flush();
803 return accumulator.result;
804 } else {
805 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
806
807 for(auto v : nid.get_overlord_as_ruler()) {
808 if(v.get_subject().get_is_substate()) {
809 accumulator.add_value(to_generic(v.get_subject().id));
810 if(!accumulator.result)
811 return false;
812 }
813 }
814
815 accumulator.flush();
816 return accumulator.result;
817 }
818 },
819 primary_slot, this_slot, from_slot);
820}
821TRIGGER_FUNCTION(tf_x_sphere_member_scope) {
822 return ve::apply(
823 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
824 auto nid = fatten(ws.world, to_nation(p_slot));
825
826 if(*tval & trigger::is_existence_scope) {
827 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
828
829 for(auto gpr : nid.get_gp_relationship_as_great_power()) {
831 accumulator.add_value(to_generic(gpr.get_influence_target().id));
832 if(accumulator.result)
833 return true;
834 }
835 }
836
837 accumulator.flush();
838 return accumulator.result;
839 } else {
840 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
841
842 for(auto gpr : nid.get_gp_relationship_as_great_power()) {
844 accumulator.add_value(to_generic(gpr.get_influence_target().id));
845 if(!accumulator.result)
846 return false;
847 }
848 }
849
850 accumulator.flush();
851 return accumulator.result;
852 }
853 },
854 primary_slot, this_slot, from_slot);
855}
856TRIGGER_FUNCTION(tf_x_pop_scope_province) {
857 return ve::apply(
858 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
859 dcon::province_fat_id pid = fatten(ws.world, to_prov(p_slot));
860
861 if(*tval & trigger::is_existence_scope) {
862 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
863
864 for(auto i : pid.get_pop_location()) {
865 accumulator.add_value(to_generic(i.get_pop().id));
866 if(accumulator.result)
867 return true;
868 }
869
870 accumulator.flush();
871 return accumulator.result;
872 } else {
873 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
874
875 for(auto i : pid.get_pop_location()) {
876 accumulator.add_value(to_generic(i.get_pop().id));
877 if(!accumulator.result)
878 return false;
879 }
880
881 accumulator.flush();
882 return accumulator.result;
883 }
884 },
885 primary_slot, this_slot, from_slot);
886}
887TRIGGER_FUNCTION(tf_x_pop_scope_state) {
888 return ve::apply(
889 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
890 auto sid = to_state(p_slot);
891 dcon::state_definition_fat_id state_def = fatten(ws.world, ws.world.state_instance_get_definition(sid));
892 auto owner = ws.world.state_instance_get_nation_from_state_ownership(sid);
893
894 if(*tval & trigger::is_existence_scope) {
895 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
896
897 for(auto p : state_def.get_abstract_state_membership()) {
898 if(p.get_province().get_nation_from_province_ownership() == owner) {
899 for(auto i : p.get_province().get_pop_location()) {
900 accumulator.add_value(to_generic(i.get_pop().id));
901 if(accumulator.result)
902 return true;
903 }
904 }
905 }
906
907 accumulator.flush();
908 return accumulator.result;
909 } else {
910 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
911
912 for(auto p : state_def.get_abstract_state_membership()) {
913 if(p.get_province().get_nation_from_province_ownership() == owner) {
914 for(auto i : p.get_province().get_pop_location()) {
915 accumulator.add_value(to_generic(i.get_pop().id));
916 if(!accumulator.result)
917 return false;
918 }
919 }
920 }
921
922 accumulator.flush();
923 return accumulator.result;
924 }
925 },
926 primary_slot, this_slot, from_slot);
927}
928TRIGGER_FUNCTION(tf_x_pop_scope_nation) {
929 return ve::apply(
930 [&ws, tval](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
931 auto nid = fatten(ws.world, to_nation(p_slot));
932
933 if(*tval & trigger::is_existence_scope) {
934 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
935
936 for(auto p : nid.get_province_ownership()) {
937 for(auto i : p.get_province().get_pop_location()) {
938 accumulator.add_value(to_generic(i.get_pop().id));
939 if(accumulator.result)
940 return true;
941 }
942 }
943
944 accumulator.flush();
945 return accumulator.result;
946 } else {
947 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
948
949 for(auto p : nid.get_province_ownership()) {
950 for(auto i : p.get_province().get_pop_location()) {
951 accumulator.add_value(to_generic(i.get_pop().id));
952 if(!accumulator.result)
953 return false;
954 }
955 }
956
957 accumulator.flush();
958 return accumulator.result;
959 }
960 },
961 primary_slot, this_slot, from_slot);
962}
963TRIGGER_FUNCTION(tf_x_provinces_in_variable_region) {
964 auto state_def = trigger::payload(*(tval + 2)).state_id;
965
966 return ve::apply(
967 [&ws, tval, state_def](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
968 if(*tval & trigger::is_existence_scope) {
969 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
970
971 for(auto i : ws.world.state_definition_get_abstract_state_membership(state_def)) {
972 accumulator.add_value(to_generic(i.get_province().id));
973 if(accumulator.result)
974 return true;
975 }
976
977 accumulator.flush();
978 return accumulator.result;
979 } else {
980 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
981
982 for(auto i : ws.world.state_definition_get_abstract_state_membership(state_def)) {
983 accumulator.add_value(to_generic(i.get_province().id));
984 if(!accumulator.result)
985 return false;
986 }
987
988 accumulator.flush();
989 return accumulator.result;
990 }
991 },
992 primary_slot, this_slot, from_slot);
993}
994TRIGGER_FUNCTION(tf_x_provinces_in_variable_region_proper) {
995 auto state_def = trigger::payload(*(tval + 2)).reg_id;
996
997 return ve::apply(
998 [&ws, tval, state_def](int32_t p_slot, int32_t t_slot, int32_t f_slot) {
999 if(*tval & trigger::is_existence_scope) {
1000 auto accumulator = existence_accumulator(ws, tval, t_slot, f_slot);
1001
1002 for(auto i : ws.world.region_get_region_membership(state_def)) {
1003 accumulator.add_value(to_generic(i.get_province().id));
1004 if(accumulator.result)
1005 return true;
1006 }
1007
1008 accumulator.flush();
1009 return accumulator.result;
1010 } else {
1011 auto accumulator = universal_accumulator(ws, tval, t_slot, f_slot);
1012
1013 for(auto i : ws.world.region_get_region_membership(state_def)) {
1014 accumulator.add_value(to_generic(i.get_province().id));
1015 if(!accumulator.result)
1016 return false;
1017 }
1018
1019 accumulator.flush();
1020 return accumulator.result;
1021 }
1022 },
1023 primary_slot, this_slot, from_slot);
1024}
1025TRIGGER_FUNCTION(tf_owner_scope_state) {
1026 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
1027 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1028 from_slot);
1029}
1030TRIGGER_FUNCTION(tf_owner_scope_province) {
1031 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1032 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1033 from_slot);
1034}
1035TRIGGER_FUNCTION(tf_controller_scope) {
1036 auto controller = ws.world.province_get_nation_from_province_control(to_prov(primary_slot));
1037 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(controller),
1038 this_slot, from_slot);
1039}
1040TRIGGER_FUNCTION(tf_location_scope) {
1041 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1042 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(location), this_slot,
1043 from_slot);
1044}
1045TRIGGER_FUNCTION(tf_country_scope_state) {
1046 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
1047 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1048 from_slot);
1049}
1050TRIGGER_FUNCTION(tf_country_scope_pop) {
1051 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1052 auto owner = ws.world.province_get_nation_from_province_ownership(location);
1053 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1054 from_slot);
1055}
1056TRIGGER_FUNCTION(tf_capital_scope) {
1057 auto cap = ws.world.nation_get_capital(to_nation(primary_slot));
1058 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(cap), this_slot, from_slot);
1059}
1060TRIGGER_FUNCTION(tf_capital_scope_province) {
1061 auto cap = ws.world.nation_get_capital(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
1062 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(cap), this_slot, from_slot);
1063}
1064TRIGGER_FUNCTION(tf_capital_scope_pop) {
1065 auto cap = ws.world.nation_get_capital(nations::owner_of_pop(ws, to_pop(primary_slot)));
1066 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(cap), this_slot, from_slot);
1067}
1068TRIGGER_FUNCTION(tf_this_scope) {
1069 return apply_subtriggers<return_type, this_type, this_type, from_type>(tval, ws, this_slot, this_slot, from_slot);
1070}
1071TRIGGER_FUNCTION(tf_from_scope) {
1072 return apply_subtriggers<return_type, from_type, this_type, from_type>(tval, ws, from_slot, this_slot, from_slot);
1073}
1074TRIGGER_FUNCTION(tf_sea_zone_scope) {
1075 /*
1076 auto sea_zones = ve::apply(
1077 [&ws](int32_t p_slot) {
1078 auto pid = fatten(ws.world, to_prov(p_slot));
1079 for(auto adj : pid.get_province_adjacency()) {
1080 if(adj.get_connected_provinces(0).id.index() >= ws.province_definitions.first_sea_province.index()) {
1081 return adj.get_connected_provinces(0).id;
1082 } else if(adj.get_connected_provinces(1).id.index() >= ws.province_definitions.first_sea_province.index()) {
1083 return adj.get_connected_provinces(1).id;
1084 }
1085 }
1086 return dcon::province_id();
1087 },
1088 primary_slot);
1089 */
1090 auto ports = ws.world.province_get_port_to(to_prov(primary_slot));
1091 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(ports),
1092 this_slot, from_slot);
1093}
1094TRIGGER_FUNCTION(tf_cultural_union_scope) {
1095 auto cultures = ws.world.nation_get_primary_culture(to_nation(primary_slot));
1096 auto cg = ws.world.culture_get_group_from_culture_group_membership(cultures);
1097 auto union_tags = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1098 auto group_holders = ws.world.national_identity_get_nation_from_identity_holder(union_tags);
1099 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(group_holders),
1100 this_slot, from_slot);
1101}
1102TRIGGER_FUNCTION(tf_overlord_scope) {
1103 auto so = ws.world.nation_get_overlord_as_subject(to_nation(primary_slot));
1104 auto nso = ws.world.overlord_get_ruler(so);
1105 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(nso), this_slot,
1106 from_slot);
1107}
1108TRIGGER_FUNCTION(tf_sphere_owner_scope) {
1109 auto nso = ws.world.nation_get_in_sphere_of(to_nation(primary_slot));
1110 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(nso), this_slot,
1111 from_slot);
1112}
1113TRIGGER_FUNCTION(tf_independence_scope) {
1114 auto rtags = ws.world.rebel_faction_get_defection_target(to_rebel(from_slot));
1115 auto r_holders = ws.world.national_identity_get_nation_from_identity_holder(rtags);
1116
1117 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(r_holders),
1118 this_slot, from_slot);
1119}
1120TRIGGER_FUNCTION(tf_flashpoint_tag_scope) {
1121 auto ctags = ws.world.state_instance_get_flashpoint_tag(to_state(primary_slot));
1122 auto fp_nations = ws.world.national_identity_get_nation_from_identity_holder(ctags);
1123 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(fp_nations),
1124 this_slot, from_slot);
1125}
1126TRIGGER_FUNCTION(tf_crisis_state_scope) {
1127 return apply_subtriggers<return_type, int32_t, this_type, from_type>(tval, ws, to_generic(ws.crisis_state), this_slot,
1128 from_slot);
1129}
1130TRIGGER_FUNCTION(tf_state_scope_province) {
1131 auto state_instance = ws.world.province_get_state_membership(to_prov(primary_slot));
1132 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(state_instance),
1133 this_slot, from_slot);
1134}
1135TRIGGER_FUNCTION(tf_state_scope_pop) {
1136 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
1137 auto state_instance = ws.world.province_get_state_membership(location);
1138 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(state_instance),
1139 this_slot, from_slot);
1140}
1141TRIGGER_FUNCTION(tf_tag_scope) {
1142 auto tag = trigger::payload(tval[2]).tag_id;
1143 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(tag);
1144 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(tag_holder),
1145 this_slot, from_slot);
1146}
1147TRIGGER_FUNCTION(tf_integer_scope) {
1148 auto wprov = trigger::payload(tval[2]).prov_id;
1149 return apply_subtriggers<return_type, int32_t, this_type, from_type>(tval, ws, to_generic(wprov), this_slot, from_slot);
1150}
1151TRIGGER_FUNCTION(tf_country_scope_nation) {
1152 return apply_subtriggers<return_type, primary_type, this_type, from_type>(tval, ws, primary_slot, this_slot, from_slot);
1153}
1154TRIGGER_FUNCTION(tf_country_scope_province) {
1155 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
1156 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(owner), this_slot,
1157 from_slot);
1158}
1159TRIGGER_FUNCTION(tf_cultural_union_scope_pop) {
1160 auto cultures = ws.world.pop_get_culture(to_pop(primary_slot));
1161 auto cg = ws.world.culture_get_group_from_culture_group_membership(cultures);
1162 auto union_tags = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1163 auto group_holders = ws.world.national_identity_get_nation_from_identity_holder(union_tags);
1164
1165 return apply_subtriggers<return_type, gathered_t<primary_type>, this_type, from_type>(tval, ws, to_generic(group_holders),
1166 this_slot, from_slot);
1167}
1168
1169//
1170// non scope trigger functions
1171//
1172
1174 return compare_values(tval[0], ws.current_date.to_ymd(ws.start_date).year, int32_t(tval[1]));
1175}
1177 return compare_values(tval[0], ws.current_date.to_ymd(ws.start_date).month, int32_t(tval[1]));
1178}
1180 return compare_to_true(tval[0], ws.world.province_get_is_coast(to_prov(primary_slot)));
1181}
1183 // note: comparison reversed since rank 1 is "greater" than rank 1 + N
1184 return compare_values(tval[0], int32_t(tval[1]), ws.world.nation_get_rank(to_nation(primary_slot)));
1185}
1186TRIGGER_FUNCTION(tf_technology) {
1187 auto tid = trigger::payload(tval[1]).tech_id;
1188 return compare_to_true(tval[0], ws.world.nation_get_active_technologies(to_nation(primary_slot), tid));
1189}
1190TRIGGER_FUNCTION(tf_technology_province) {
1191 auto tid = trigger::payload(tval[1]).tech_id;
1192 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));
1193}
1194TRIGGER_FUNCTION(tf_technology_pop) {
1195 auto tid = trigger::payload(tval[1]).tech_id;
1196 return compare_to_true(tval[0], ws.world.nation_get_active_technologies(nations::owner_of_pop(ws, to_pop(primary_slot)), tid));
1197}
1198TRIGGER_FUNCTION(tf_strata_rich) {
1199 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
1200 auto strata = ws.world.pop_type_get_strata(type);
1201 return compare_to_true(tval[0], strata == decltype(strata)(int32_t(culture::pop_strata::rich)));
1202}
1203TRIGGER_FUNCTION(tf_strata_middle) {
1204 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
1205 auto strata = ws.world.pop_type_get_strata(type);
1206 return compare_to_true(tval[0], strata == decltype(strata)(int32_t(culture::pop_strata::middle)));
1207}
1208TRIGGER_FUNCTION(tf_strata_poor) {
1209 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
1210 auto strata = ws.world.pop_type_get_strata(type);
1211 return compare_to_true(tval[0], strata == decltype(strata)(int32_t(culture::pop_strata::poor)));
1212}
1213TRIGGER_FUNCTION(tf_life_rating_province) {
1214 return compare_values(tval[0], ws.world.province_get_life_rating(to_prov(primary_slot)),
1215 trigger::payload(tval[1]).signed_value);
1216}
1217TRIGGER_FUNCTION(tf_life_rating_state) {
1218 auto state_caps = ws.world.state_instance_get_capital(to_state(primary_slot));
1219 return compare_values(tval[0], ws.world.province_get_life_rating(state_caps), trigger::payload(tval[1]).signed_value);
1220}
1221
1223 return make_true_accumulator(
1224 [&ws, sea_index = ws.province_definitions.first_sea_province.index()](ve::tagged_vector<int32_t> v) {
1225 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(v));
1226 return (owners == ve::tagged_vector<dcon::nation_id>()) & (ve::int_vector(v) < sea_index);
1227 });
1228}
1229
1230TRIGGER_FUNCTION(tf_has_empty_adjacent_state_province) {
1231 auto results = ve::apply(
1232 [&ws](int32_t p_slot, int32_t, int32_t) {
1233 auto pid = to_prov(p_slot);
1234 auto acc = empty_province_accumulator(ws);
1235
1236 for(auto p : ws.world.province_get_province_adjacency(pid)) {
1237 auto other = p.get_connected_provinces(0) == pid ? p.get_connected_provinces(1) : p.get_connected_provinces(0);
1238 acc.add_value(to_generic(other));
1239 if(acc.result)
1240 return true;
1241 }
1242
1243 acc.flush();
1244 return acc.result;
1245 },
1246 primary_slot, this_slot, from_slot);
1247
1248 return compare_to_true(tval[0], results);
1249}
1250auto empty_province_from_state_accumulator(sys::state const& ws, dcon::state_instance_id sid) {
1251 return make_true_accumulator([&ws, vector_sid = ve::tagged_vector<dcon::state_instance_id>(sid),
1252 sea_index = ws.province_definitions.first_sea_province.index()](ve::tagged_vector<int32_t> v) {
1253 auto owners = ws.world.province_get_nation_from_province_ownership(to_prov(v));
1254 return (owners == ve::tagged_vector<dcon::nation_id>()) & (ve::int_vector(v) < sea_index) &
1255 (ws.world.province_get_state_membership(to_prov(v)) != vector_sid);
1256 });
1257}
1258
1259TRIGGER_FUNCTION(tf_has_empty_adjacent_state_state) {
1260 auto results = ve::apply(
1261 [&ws](int32_t p_slot, int32_t, int32_t) {
1262 auto state_id = to_state(p_slot);
1263 auto region_owner = ws.world.state_instance_get_nation_from_state_ownership(state_id);
1264
1265 auto acc = empty_province_from_state_accumulator(ws, state_id);
1266 auto region_id = ws.world.state_instance_get_definition(state_id);
1267
1268 for(auto sp : ws.world.state_definition_get_abstract_state_membership(region_id)) {
1269 if(sp.get_province().get_nation_from_province_ownership() == region_owner) {
1270 for(auto p : ws.world.province_get_province_adjacency(sp.get_province())) {
1271 auto other =
1272 p.get_connected_provinces(0) == sp.get_province() ? p.get_connected_provinces(1) : p.get_connected_provinces(0);
1273 acc.add_value(to_generic(other));
1274 if(acc.result)
1275 return true;
1276 }
1277 }
1278 }
1279
1280 acc.flush();
1281 return acc.result;
1282 },
1283 primary_slot, this_slot, from_slot);
1284
1285 return compare_to_true(tval[0], results);
1286}
1287TRIGGER_FUNCTION(tf_state_id_province) {
1288 auto pid = trigger::payload(tval[1]).prov_id;
1289 return compare_values_eq(tval[0],
1290 ws.world.abstract_state_membership_get_state(ws.world.province_get_abstract_state_membership(to_prov(primary_slot))),
1291 ws.world.abstract_state_membership_get_state(ws.world.province_get_abstract_state_membership(pid)));
1292}
1293TRIGGER_FUNCTION(tf_state_id_state) {
1294 auto pid = trigger::payload(tval[1]).prov_id;
1295 return compare_values_eq(tval[0], ws.world.state_instance_get_definition(to_state(primary_slot)),
1296 ws.world.abstract_state_membership_get_state(ws.world.province_get_abstract_state_membership(pid)));
1297}
1298TRIGGER_FUNCTION(tf_cash_reserves) {
1299 auto ratio = read_float_from_payload(tval + 1);
1300 auto target = economy::desired_needs_spending(ws, to_pop(primary_slot));
1301 auto savings_qnty = ws.world.pop_get_savings(to_pop(primary_slot));
1302 return compare_values(tval[0], ve::select(target != 0.0f, savings_qnty * 100.0f / target, 100.0f), ratio);
1303}
1304TRIGGER_FUNCTION(tf_unemployment_nation) {
1305 auto total_employable = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::employable);
1306 auto total_employed = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::employed);
1307 return compare_values(tval[0], ve::select(total_employable > 0.0f, 1.0f - (total_employed / total_employable), 0.0f),
1308 read_float_from_payload(tval + 1));
1309}
1310TRIGGER_FUNCTION(tf_unemployment_state) {
1311 auto total_employable = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::employable);
1312 auto total_employed = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::employed);
1313 return compare_values(tval[0], ve::select(total_employable > 0.0f, 1.0f - (total_employed / total_employable), 0.0f),
1314 read_float_from_payload(tval + 1));
1315}
1316TRIGGER_FUNCTION(tf_unemployment_province) {
1317 auto total_employable = ws.world.province_get_demographics(to_prov(primary_slot), demographics::employable);
1318 auto total_employed = ws.world.province_get_demographics(to_prov(primary_slot), demographics::employed);
1319 return compare_values(tval[0], ve::select(total_employable > 0.0f, 1.0f - (total_employed / total_employable), 0.0f),
1320 read_float_from_payload(tval + 1));
1321}
1322TRIGGER_FUNCTION(tf_unemployment_pop) {
1323 auto employed = pop_demographics::get_raw_employment(ws, 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, 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], pop_demographics::get_political_reform_desire(ws, 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], pop_demographics::get_social_reform_desire(ws, 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)
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, pop_demographics::get_militancy(ws, 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, pop_demographics::get_militancy(ws, 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, pop_demographics::get_militancy(ws, 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], pop_demographics::get_life_needs(ws, to_pop(primary_slot)),
4671 read_float_from_payload(tval + 1));
4672}
4673TRIGGER_FUNCTION(tf_everyday_needs) {
4674 return compare_values(tval[0], pop_demographics::get_everyday_needs(ws, to_pop(primary_slot)),
4675 read_float_from_payload(tval + 1));
4676}
4677TRIGGER_FUNCTION(tf_luxury_needs) {
4678 return compare_values(tval[0], pop_demographics::get_luxury_needs(ws, to_pop(primary_slot)),
4679 read_float_from_payload(tval + 1));
4680}
4681TRIGGER_FUNCTION(tf_consciousness_pop) {
4682 return compare_values(tval[0], pop_demographics::get_consciousness(ws, 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], pop_demographics::get_literacy(ws, 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],pop_demographics::get_militancy(ws, 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 = pop_demographics::get_raw_employment(ws, to_pop(primary_slot));
5153 return compare_values(tval[0], 1.0f - employment, read_float_from_payload(tval + 1));
5154}
5155TRIGGER_FUNCTION(tf_pop_unemployment_nation_this_pop) {
5156 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5157
5158 auto pop_size = ve::apply(
5159 [&](dcon::nation_id loc, dcon::pop_type_id t) {
5160 if(t)
5161 return ws.world.nation_get_demographics(loc, demographics::to_key(ws, t));
5162 else
5163 return 0.0f;
5164 },
5165 to_nation(primary_slot), type);
5166
5167 auto employment = ve::apply(
5168 [&](dcon::nation_id loc, dcon::pop_type_id t) {
5169 if(t)
5170 return ws.world.nation_get_demographics(loc, demographics::to_employment_key(ws, t));
5171 else
5172 return 0.0f;
5173 },
5174 to_nation(primary_slot), type);
5175
5176 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5177 read_float_from_payload(tval + 1));
5178}
5179TRIGGER_FUNCTION(tf_pop_unemployment_state_this_pop) {
5180 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5181
5182 auto pop_size = ve::apply(
5183 [&](dcon::state_instance_id loc, dcon::pop_type_id t) {
5184 if(t)
5185 return ws.world.state_instance_get_demographics(loc, demographics::to_key(ws, t));
5186 else
5187 return 0.0f;
5188 },
5189 to_state(primary_slot), type);
5190
5191 auto employment = ve::apply(
5192 [&](dcon::state_instance_id loc, dcon::pop_type_id t) {
5193 if(t)
5194 return ws.world.state_instance_get_demographics(loc, demographics::to_employment_key(ws, t));
5195 else
5196 return 0.0f;
5197 },
5198 to_state(primary_slot), type);
5199
5200 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5201 read_float_from_payload(tval + 1));
5202}
5203TRIGGER_FUNCTION(tf_pop_unemployment_province_this_pop) {
5204 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5205
5206 auto pop_size = ve::apply(
5207 [&](dcon::province_id loc, dcon::pop_type_id t) {
5208 if(t)
5209 return ws.world.province_get_demographics(loc, demographics::to_key(ws, t));
5210 else
5211 return 0.0f;
5212 },
5213 to_prov(primary_slot), type);
5214
5215 auto employment = ve::apply(
5216 [&](dcon::province_id loc, dcon::pop_type_id t) {
5217 if(t)
5218 return ws.world.province_get_demographics(loc, demographics::to_employment_key(ws, t));
5219 else
5220 return 0.0f;
5221 },
5222 to_prov(primary_slot), type);
5223
5224 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5225 read_float_from_payload(tval + 1));
5226}
5227TRIGGER_FUNCTION(tf_relation_tag) {
5228 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[2]).tag_id);
5229 auto relation = ve::apply(
5230 [&ws, holder](dcon::nation_id a) {
5231 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, holder);
5232 return ws.world.diplomatic_relation_get_value(rel);
5233 },
5234 to_nation(primary_slot));
5235 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5236}
5237TRIGGER_FUNCTION(tf_relation_this_nation) {
5238 auto relation = ve::apply(
5239 [&ws](dcon::nation_id a, dcon::nation_id b) {
5240 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5241 return ws.world.diplomatic_relation_get_value(rel);
5242 },
5243 to_nation(primary_slot), to_nation(this_slot));
5244 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5245}
5246TRIGGER_FUNCTION(tf_relation_this_province) {
5247 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5248 auto relation = ve::apply(
5249 [&ws](dcon::nation_id a, dcon::nation_id b) {
5250 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5251 return ws.world.diplomatic_relation_get_value(rel);
5252 },
5253 to_nation(primary_slot), owner);
5254 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5255}
5256TRIGGER_FUNCTION(tf_relation_this_pop) {
5257 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
5258 auto relation = ve::apply(
5259 [&ws](dcon::nation_id a, dcon::nation_id b) {
5260 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5261 return ws.world.diplomatic_relation_get_value(rel);
5262 },
5263 to_nation(primary_slot), owner);
5264 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5265}
5266TRIGGER_FUNCTION(tf_relation_from_nation) {
5267 auto relation = ve::apply(
5268 [&ws](dcon::nation_id a, dcon::nation_id b) {
5269 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5270 return ws.world.diplomatic_relation_get_value(rel);
5271 },
5272 to_nation(primary_slot), to_nation(from_slot));
5273 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5274}
5275TRIGGER_FUNCTION(tf_relation_from_province) {
5276 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
5277 auto relation = ve::apply(
5278 [&ws](dcon::nation_id a, dcon::nation_id b) {
5279 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5280 return ws.world.diplomatic_relation_get_value(rel);
5281 },
5282 to_nation(primary_slot), owner);
5283 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5284}
5285TRIGGER_FUNCTION(tf_check_variable) {
5286 auto id = payload(tval[3]).natv_id;
5287 return compare_values(tval[0], ws.world.nation_get_variables(to_nation(primary_slot), id), read_float_from_payload(tval + 1));
5288}
5289TRIGGER_FUNCTION(tf_upper_house) {
5290 auto id = payload(tval[3]).ideo_id;
5291 return compare_values(tval[0], ws.world.nation_get_upper_house(to_nation(primary_slot), id), 100.0f * read_float_from_payload(tval + 1));
5292}
5293TRIGGER_FUNCTION(tf_unemployment_by_type_nation) {
5294 return tf_pop_unemployment_nation<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5295}
5296TRIGGER_FUNCTION(tf_unemployment_by_type_state) {
5297 return tf_pop_unemployment_state<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5298}
5299TRIGGER_FUNCTION(tf_unemployment_by_type_province) {
5300 return tf_pop_unemployment_province<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5301}
5302TRIGGER_FUNCTION(tf_unemployment_by_type_pop) {
5303 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5304 auto si = ws.world.province_get_state_membership(location);
5305 return tf_unemployment_by_type_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5306}
5307TRIGGER_FUNCTION(tf_party_loyalty_nation_province_id) {
5308 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5309 payload(tval[2]).signed_value);
5310}
5311TRIGGER_FUNCTION(tf_party_loyalty_from_nation_province_id) {
5312 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5313 payload(tval[2]).signed_value);
5314}
5315TRIGGER_FUNCTION(tf_party_loyalty_province_province_id) {
5316 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5317 payload(tval[2]).signed_value);
5318}
5319TRIGGER_FUNCTION(tf_party_loyalty_from_province_province_id) {
5320 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5321 payload(tval[2]).signed_value);
5322}
5323TRIGGER_FUNCTION(tf_party_loyalty_nation_from_province) {
5324 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(from_slot), payload(tval[2]).ideo_id),
5325 payload(tval[1]).signed_value);
5326}
5327TRIGGER_FUNCTION(tf_party_loyalty_generic) {
5328 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5329 payload(tval[1]).signed_value);
5330}
5331TRIGGER_FUNCTION(tf_party_loyalty_from_nation_scope_province) {
5332 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5333 payload(tval[1]).signed_value);
5334}
5335TRIGGER_FUNCTION(tf_party_loyalty_from_province_scope_province) {
5336 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5337 payload(tval[1]).signed_value);
5338}
5339TRIGGER_FUNCTION(tf_can_build_in_province_railroad_no_limit_from_nation) {
5340 return compare_to_true(tval[0],
5341 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5342 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5343 ve::to_float(ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::railroad))));
5344}
5345TRIGGER_FUNCTION(tf_can_build_in_province_railroad_yes_limit_from_nation) {
5346 return compare_to_true(tval[0],
5347 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5348 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5349 ve::to_float(ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::railroad))));
5350}
5351TRIGGER_FUNCTION(tf_can_build_in_province_railroad_no_limit_this_nation) {
5352 return compare_to_true(tval[0],
5353 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5354 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5355 ve::to_float(ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::railroad))));
5356}
5357TRIGGER_FUNCTION(tf_can_build_in_province_railroad_yes_limit_this_nation) {
5358 return compare_to_true(tval[0],
5359 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5360 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5361 ve::to_float(ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::railroad))));
5362}
5363TRIGGER_FUNCTION(tf_can_build_in_province_fort_no_limit_from_nation) {
5364 return compare_to_true(tval[0],
5365 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)));
5366}
5367TRIGGER_FUNCTION(tf_can_build_in_province_fort_yes_limit_from_nation) {
5368 return compare_to_true(tval[0],
5369 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)));
5370}
5371TRIGGER_FUNCTION(tf_can_build_in_province_fort_no_limit_this_nation) {
5372 return compare_to_true(tval[0],
5373 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)));
5374}
5375TRIGGER_FUNCTION(tf_can_build_in_province_fort_yes_limit_this_nation) {
5376 return compare_to_true(tval[0],
5377 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)));
5378}
5379TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_no_limit_from_nation) {
5380 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5381 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5382 ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::naval_base))) &&
5383 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5384 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5385 ws.world.province_get_state_membership(to_prov(primary_slot))));
5386 return compare_to_true(tval[0], result);
5387}
5388TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_yes_limit_from_nation) {
5389 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5390 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5391 ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::naval_base))) &&
5392 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5393 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5394 ws.world.province_get_state_membership(to_prov(primary_slot))));
5395 return compare_to_true(tval[0], result);
5396}
5397TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_no_limit_this_nation) {
5398 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5399 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5400 ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::naval_base))) &&
5401 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5402 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5403 ws.world.province_get_state_membership(to_prov(primary_slot))));
5404 return compare_to_true(tval[0], result);
5405}
5406TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_yes_limit_this_nation) {
5407 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5408 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5409 ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::naval_base))) &&
5410 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5411 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5412 ws.world.province_get_state_membership(to_prov(primary_slot))));
5413 return compare_to_true(tval[0], result);
5414}
5415TRIGGER_FUNCTION(tf_can_build_railway_in_capital_yes_whole_state_yes_limit) {
5416 // stub: virtually unused
5417 return compare_to_true(tval[0], true);
5418}
5419TRIGGER_FUNCTION(tf_can_build_railway_in_capital_yes_whole_state_no_limit) {
5420 // stub: virtually unused
5421 return compare_to_true(tval[0], true);
5422}
5423TRIGGER_FUNCTION(tf_can_build_railway_in_capital_no_whole_state_yes_limit) {
5424 // stub: virtually unused
5425 return compare_to_true(tval[0], true);
5426}
5427TRIGGER_FUNCTION(tf_can_build_railway_in_capital_no_whole_state_no_limit) {
5428 // stub: virtually unused
5429 return compare_to_true(tval[0], true);
5430}
5431TRIGGER_FUNCTION(tf_can_build_fort_in_capital_yes_whole_state_yes_limit) {
5432 // stub: virtually unused
5433 return compare_to_true(tval[0], true);
5434}
5435TRIGGER_FUNCTION(tf_can_build_fort_in_capital_yes_whole_state_no_limit) {
5436 // stub: virtually unused
5437 return compare_to_true(tval[0], true);
5438}
5439TRIGGER_FUNCTION(tf_can_build_fort_in_capital_no_whole_state_yes_limit) {
5440 // stub: virtually unused
5441 return compare_to_true(tval[0], true);
5442}
5443TRIGGER_FUNCTION(tf_can_build_fort_in_capital_no_whole_state_no_limit) {
5444 // stub: virtually unused
5445 return compare_to_true(tval[0], true);
5446}
5447TRIGGER_FUNCTION(tf_work_available_nation) {
5448 auto type = payload(tval[1]).popt_id;
5449 auto result = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_employment_key(ws, type)) >=
5450 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type));
5451 return compare_to_true(tval[0], result);
5452}
5453TRIGGER_FUNCTION(tf_work_available_state) {
5454 auto type = payload(tval[1]).popt_id;
5455 auto result = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_employment_key(ws, type)) >=
5456 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type));
5457 return compare_to_true(tval[0], result);
5458}
5459TRIGGER_FUNCTION(tf_work_available_province) {
5460 auto type = payload(tval[1]).popt_id;
5461 auto result = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_employment_key(ws, type)) >=
5462 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type));
5463 return compare_to_true(tval[0], result);
5464}
5465TRIGGER_FUNCTION(tf_variable_ideology_name_nation) {
5466 auto id = payload(tval[1]).ideo_id;
5467 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5468 auto support_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, id));
5469 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5470}
5471TRIGGER_FUNCTION(tf_variable_ideology_name_state) {
5472 auto id = payload(tval[1]).ideo_id;
5473 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5474 auto support_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, id));
5475 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5476}
5477TRIGGER_FUNCTION(tf_variable_ideology_name_province) {
5478 auto id = payload(tval[1]).ideo_id;
5479 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5480 auto support_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, id));
5481 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5482}
5483TRIGGER_FUNCTION(tf_variable_ideology_name_pop) {
5484 auto id = payload(tval[1]).ideo_id;
5485 auto support_pop = pop_demographics::get_demo(ws, to_pop(primary_slot), pop_demographics::to_key(ws, id));
5486 return compare_values(tval[0], support_pop, read_float_from_payload(tval + 2));
5487}
5488TRIGGER_FUNCTION(tf_variable_issue_name_nation) {
5489 auto id = payload(tval[1]).opt_id;
5490 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5491 auto support_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, id));
5492 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5493}
5494TRIGGER_FUNCTION(tf_variable_issue_name_state) {
5495 auto id = payload(tval[1]).opt_id;
5496 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5497 auto support_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, id));
5498 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5499}
5500TRIGGER_FUNCTION(tf_variable_issue_name_province) {
5501 auto id = payload(tval[1]).opt_id;
5502 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5503 auto support_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, id));
5504 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5505}
5506TRIGGER_FUNCTION(tf_variable_issue_name_pop) {
5507 auto id = payload(tval[1]).opt_id;
5508 auto support_pop = pop_demographics::get_demo(ws, to_pop(primary_slot), pop_demographics::to_key(ws, id));
5509 return compare_values(tval[0], support_pop, read_float_from_payload(tval + 2));
5510}
5511TRIGGER_FUNCTION(tf_variable_issue_group_name_nation) {
5512 auto option = payload(tval[2]).opt_id;
5513 auto issue = payload(tval[1]).iss_id;
5514 ;
5515 return compare_values_eq(tval[0], ws.world.nation_get_issues(to_nation(primary_slot), issue), option);
5516}
5517TRIGGER_FUNCTION(tf_variable_issue_group_name_state) {
5518 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
5519 auto option = payload(tval[2]).opt_id;
5520 auto issue = payload(tval[1]).iss_id;
5521 ;
5522 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5523}
5524TRIGGER_FUNCTION(tf_variable_issue_group_name_province) {
5525 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
5526 auto option = payload(tval[2]).opt_id;
5527 auto issue = payload(tval[1]).iss_id;
5528 ;
5529 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5530}
5531TRIGGER_FUNCTION(tf_variable_issue_group_name_pop) {
5532 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
5533 auto option = payload(tval[2]).opt_id;
5534 auto issue = payload(tval[1]).iss_id;
5535 ;
5536 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5537}
5538TRIGGER_FUNCTION(tf_variable_reform_group_name_nation) {
5539 auto option = payload(tval[2]).ropt_id;
5540 auto issue = payload(tval[1]).ref_id;
5541 ;
5542 return compare_values_eq(tval[0], ws.world.nation_get_reforms(to_nation(primary_slot), issue), option);
5543}
5544TRIGGER_FUNCTION(tf_variable_reform_group_name_state) {
5545 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
5546 auto option = payload(tval[2]).ropt_id;
5547 auto issue = payload(tval[1]).ref_id;
5548 ;
5549 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5550}
5551TRIGGER_FUNCTION(tf_variable_reform_group_name_province) {
5552 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
5553 auto option = payload(tval[2]).ropt_id;
5554 auto issue = payload(tval[1]).ref_id;
5555 ;
5556 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5557}
5558TRIGGER_FUNCTION(tf_variable_reform_group_name_pop) {
5559 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
5560 auto option = payload(tval[2]).ropt_id;
5561 auto issue = payload(tval[1]).ref_id;
5562 ;
5563 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5564}
5565TRIGGER_FUNCTION(tf_variable_pop_type_name_nation) {
5566 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5567 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5568 auto size = ws.world.nation_get_demographics(to_nation(primary_slot), type);
5569 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5570}
5571TRIGGER_FUNCTION(tf_variable_pop_type_name_state) {
5572 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5573 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5574 auto size = ws.world.state_instance_get_demographics(to_state(primary_slot), type);
5575 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5576}
5577TRIGGER_FUNCTION(tf_variable_pop_type_name_province) {
5578 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5579 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5580 auto size = ws.world.province_get_demographics(to_prov(primary_slot), type);
5581 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5582}
5583TRIGGER_FUNCTION(tf_variable_pop_type_name_pop) {
5584 auto pop_location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5585 auto total_pop = ws.world.province_get_demographics(pop_location, demographics::total);
5586 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5587 auto size = ws.world.province_get_demographics(pop_location, type);
5588 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5589}
5590TRIGGER_FUNCTION(tf_variable_good_name) {
5591 auto good = payload(tval[1]).com_id;
5592 auto amount = ws.world.nation_get_stockpiles(to_nation(primary_slot), good);
5593 return compare_values(tval[0], amount, read_float_from_payload(tval + 2));
5594}
5595TRIGGER_FUNCTION(tf_religion_nation) {
5596 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), payload(tval[1]).rel_id);
5597}
5598TRIGGER_FUNCTION(tf_religion_nation_reb) {
5599 auto r = ws.world.rebel_faction_get_religion(to_rebel(from_slot));
5600 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), r);
5601}
5602TRIGGER_FUNCTION(tf_religion_nation_from_nation) {
5603 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)),
5604 ws.world.nation_get_religion(to_nation(from_slot)));
5605}
5606TRIGGER_FUNCTION(tf_religion_nation_this_nation) {
5607 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)),
5608 ws.world.nation_get_religion(to_nation(this_slot)));
5609}
5610TRIGGER_FUNCTION(tf_religion_nation_this_state) {
5611 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
5612 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5613}
5614TRIGGER_FUNCTION(tf_religion_nation_this_province) {
5615 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5616 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5617}
5618TRIGGER_FUNCTION(tf_religion_nation_this_pop) {
5619 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
5620 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5621}
5622TRIGGER_FUNCTION(tf_invention) {
5623 auto tid = trigger::payload(tval[1]).invt_id;
5624 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(to_nation(primary_slot), tid));
5625}
5626TRIGGER_FUNCTION(tf_invention_province) {
5627 auto tid = trigger::payload(tval[1]).invt_id;
5628 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));
5629}
5630TRIGGER_FUNCTION(tf_invention_pop) {
5631 auto tid = trigger::payload(tval[1]).invt_id;
5632 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(nations::owner_of_pop(ws, to_pop(primary_slot)), tid));
5633}
5635 auto sid = trigger::payload(tval[1]).str_id;
5636 auto tid = ws.world.stored_trigger_get_function(sid);
5637 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);
5638 return compare_to_true(tval[0], test_result);
5639}
5640
5641TRIGGER_FUNCTION(tf_has_building_bank) {
5642 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::bank)) != 0);
5643}
5644TRIGGER_FUNCTION(tf_has_building_university) {
5645 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::university)) != 0);
5646}
5647
5648TRIGGER_FUNCTION(tf_party_name) {
5649 auto ideo = trigger::payload(tval[1]).ideo_id;
5650 dcon::text_key new_name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 2)) };
5651
5652 if(ideo) {
5653 auto nat = trigger::to_nation(primary_slot);
5654 auto holder = ws.world.nation_get_identity_from_identity_holder(nat);
5655
5656 return compare_to_true(tval[0], ve::apply([&ws, ideo, new_name](dcon::national_identity_id h, dcon::nation_id n) {
5657 auto start = ws.world.national_identity_get_political_party_first(h).id.index();
5658 auto end = start + ws.world.national_identity_get_political_party_count(h);
5659
5660 for(int32_t i = start; i < end; i++) {
5661 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5662 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5663 return ws.world.political_party_get_name(pid) == new_name;
5664 }
5665 }
5666 return false;
5667
5668 }, holder, nat));
5669
5670 } else {
5671 auto n = trigger::to_nation(primary_slot);
5672 auto rp = ws.world.nation_get_ruling_party(n);
5673 return compare_to_true(tval[0], ws.world.political_party_get_name(rp) == new_name);
5674 }
5675}
5676
5677TRIGGER_FUNCTION(tf_party_position) {
5678 auto ideo = trigger::payload(tval[1]).ideo_id;
5679 dcon::issue_option_id new_opt = trigger::payload(tval[2]).opt_id;
5680 auto popt = ws.world.issue_option_get_parent_issue(new_opt);
5681
5682 if(ideo) {
5683 auto nat = trigger::to_nation(primary_slot);
5684 auto holder = ws.world.nation_get_identity_from_identity_holder(nat);
5685
5686 return compare_to_true(tval[0], ve::apply([&ws, ideo, new_opt, popt](dcon::national_identity_id h, dcon::nation_id n) {
5687 auto start = ws.world.national_identity_get_political_party_first(h).id.index();
5688 auto end = start + ws.world.national_identity_get_political_party_count(h);
5689
5690 for(int32_t i = start; i < end; i++) {
5691 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5692 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5693 return ws.world.political_party_get_party_issues(pid, popt) == new_opt;
5694 }
5695 }
5696 return false;
5697
5698 }, holder, nat));
5699 } else {
5700 auto n = trigger::to_nation(primary_slot);
5701 auto rp = ws.world.nation_get_ruling_party(n);
5702 return compare_to_true(tval[0], ws.world.political_party_get_party_issues(rp, popt) == new_opt);
5703 }
5704}
5705
5706template<typename return_type, typename primary_type, typename this_type, typename from_type>
5708 constexpr static return_type(
5709 CALLTYPE* trigger_functions[])(uint16_t const*, sys::state&, primary_type, this_type, from_type) = {
5710 tf_none<return_type, primary_type, this_type, from_type>,
5711#define TRIGGER_BYTECODE_ELEMENT(code, name, arg) tf_##name <return_type, primary_type, this_type, from_type>,
5713#undef TRIGGER_BYTECODE_ELEMENT
5714 //
5715 // scopes
5716 //
5717 tf_generic_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t generic_scope = 0x0000; // or & and
5718 tf_x_neighbor_province_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_province_scope = 0x0001;
5719 tf_x_neighbor_country_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_country_scope_nation = 0x0002;
5720 tf_x_neighbor_country_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_country_scope_pop = 0x0003;
5721 tf_x_war_countries_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_war_countries_scope_nation = 0x0004;
5722 tf_x_war_countries_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_war_countries_scope_pop = 0x0005;
5723 tf_x_greater_power_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_greater_power_scope = 0x0006;
5724 tf_x_owned_province_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_owned_province_scope_state = 0x0007;
5725 tf_x_owned_province_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_owned_province_scope_nation = 0x0008;
5726 tf_x_core_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_core_scope_province = 0x0009;
5727 tf_x_core_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_core_scope_nation = 0x000A;
5728 tf_x_state_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_state_scope = 0x000B;
5729 tf_x_substate_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_substate_scope = 0x000C;
5730 tf_x_sphere_member_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_sphere_member_scope = 0x000D;
5731 tf_x_pop_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_province = 0x000E;
5732 tf_x_pop_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_state = 0x000F;
5733 tf_x_pop_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_nation = 0x0010;
5734 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
5735 tf_owner_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t owner_scope_state = 0x0012;
5736 tf_owner_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t owner_scope_province = 0x0013;
5737 tf_controller_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t controller_scope = 0x0014;
5738 tf_location_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t location_scope = 0x0015;
5739 tf_country_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_state = 0x0016;
5740 tf_country_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_pop = 0x0017;
5741 tf_capital_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t capital_scope = 0x0018;
5742 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_pop = 0x0019;
5743 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_nation = 0x001A;
5744 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_state = 0x001B;
5745 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_province = 0x001C;
5746 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_pop = 0x001D;
5747 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_nation = 0x001E;
5748 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_state = 0x001F;
5749 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_province = 0x0020;
5750 tf_sea_zone_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t sea_zone_scope = 0x0021;
5751 tf_cultural_union_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t cultural_union_scope = 0x0022;
5752 tf_overlord_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t overlord_scope = 0x0023;
5753 tf_sphere_owner_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t sphere_owner_scope = 0x0024;
5754 tf_independence_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t independence_scope = 0x0025;
5755 tf_flashpoint_tag_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t flashpoint_tag_scope = 0x0026;
5756 tf_crisis_state_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t crisis_state_scope = 0x0027;
5757 tf_state_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t state_scope_pop = 0x0028;
5758 tf_state_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t state_scope_province = 0x0029;
5759 tf_tag_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t tag_scope = 0x002A; // variable name
5760 tf_integer_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t integer_scope = 0x002B; // variable name
5761 tf_country_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_nation = 0x002C;
5762 tf_country_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_province = 0x002D;
5763 tf_cultural_union_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t cultural_union_scope_pop = 0x002E;
5764 tf_capital_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t capital_scope_province = 0x002F;
5765 tf_capital_scope_pop, //constexpr inline uint16_t capital_scope_pop = first_scope_code + 0x0030;
5766 tf_x_country_scope, //constexpr inline uint16_t x_country_scope = first_scope_code + 0x0031;
5767 tf_x_neighbor_province_scope_state, //constexpr inline uint16_t x_neighbor_province_scope_state = first_scope_code + 0x0032;
5768 tf_x_provinces_in_variable_region_proper, //constexpr inline uint16_t x_provinces_in_variable_region_proper = first_scope_code + 0x0033;
5769 };
5770};
5771
5772template<typename return_type, typename primary_type, typename this_type, typename from_type>
5773return_type CALLTYPE test_trigger_generic(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot,
5774 from_type from_slot) {
5776 ws, primary_slot, this_slot, from_slot);
5777}
5778
5779#undef CALLTYPE
5780#undef TRIGGER_FUNCTION
5781
5782float evaluate_multiplicative_modifier(sys::state& state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot) {
5783 auto base = state.value_modifiers[modifier];
5784 float product = base.factor;
5785 for(uint32_t i = 0; i < base.segments_count && product != 0; ++i) {
5786 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5787 if(seg.condition) {
5788 if(test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary,
5789 this_slot, from_slot)) {
5790 product *= seg.factor;
5791 }
5792 }
5793 }
5794 return product;
5795}
5796float evaluate_additive_modifier(sys::state& state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot) {
5797 auto base = state.value_modifiers[modifier];
5798 float 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 if(test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary,
5803 this_slot, from_slot)) {
5804 sum += seg.factor;
5805 }
5806 }
5807 }
5808 return sum * base.factor;
5809}
5810
5811ve::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) {
5812 auto base = state.value_modifiers[modifier];
5813 ve::fp_vector product = base.factor;
5814 for(uint32_t i = 0; i < base.segments_count; ++i) {
5815 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5816 if(seg.condition) {
5817 auto res = test_trigger_generic<ve::mask_vector>(
5818 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5819 product = ve::select(res, product * seg.factor, product);
5820 }
5821 }
5822 return product;
5823}
5824ve::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) {
5825 auto base = state.value_modifiers[modifier];
5826 ve::fp_vector sum = base.base;
5827 for(uint32_t i = 0; i < base.segments_count; ++i) {
5828 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5829 if(seg.condition) {
5830 auto res = test_trigger_generic<ve::mask_vector>(
5831 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5832 sum = ve::select(res, sum + seg.factor, sum);
5833 }
5834 }
5835 return sum * base.factor;
5836}
5837
5838ve::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) {
5839 auto base = state.value_modifiers[modifier];
5840 ve::fp_vector product = base.factor;
5841 for(uint32_t i = 0; i < base.segments_count; ++i) {
5842 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5843 if(seg.condition) {
5844 auto res = test_trigger_generic<ve::mask_vector>(
5845 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5846 product = ve::select(res, product * seg.factor, product);
5847 }
5848 }
5849 return product;
5850}
5851ve::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) {
5852 auto base = state.value_modifiers[modifier];
5853 ve::fp_vector sum = base.base;
5854 for(uint32_t i = 0; i < base.segments_count; ++i) {
5855 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5856 if(seg.condition) {
5857 auto res = test_trigger_generic<ve::mask_vector>(
5858 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5859 sum = ve::select(res, sum + seg.factor, sum);
5860 }
5861 }
5862 return sum * base.factor;
5863}
5864
5865bool evaluate(sys::state& state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot) {
5866 return test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state, primary,
5867 this_slot, from_slot);
5868}
5869bool evaluate(sys::state& state, uint16_t const* data, int32_t primary, int32_t this_slot, int32_t from_slot) {
5870 return test_trigger_generic<bool>(data, state, primary, this_slot, from_slot);
5871}
5872
5873ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::contiguous_tags<int32_t> primary,
5874 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5875 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5876 primary, this_slot, from_slot);
5877}
5878ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::contiguous_tags<int32_t> primary,
5879 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5880 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5881}
5882
5883ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::tagged_vector<int32_t> primary,
5884 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5885 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5886 primary, this_slot, from_slot);
5887}
5888ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::tagged_vector<int32_t> primary,
5889 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5890 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5891}
5892
5893ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::contiguous_tags<int32_t> primary,
5894 ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5895 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5896 primary, this_slot, from_slot);
5897}
5898ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::contiguous_tags<int32_t> primary,
5899 ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5900 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5901}
5902
5903} // namespace trigger
void add_value(int32_t v)
Definition: triggers.cpp:304
void add_value(int32_t v)
Definition: triggers.cpp:271
#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)
bool political_party_is_active(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
Definition: politics.cpp:323
float get_social_reform_desire(sys::state const &state, dcon::pop_id p)
float get_luxury_needs(sys::state const &state, dcon::pop_id p)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
float get_literacy(sys::state const &state, dcon::pop_id p)
float get_consciousness(sys::state const &state, dcon::pop_id p)
float get_militancy(sys::state const &state, dcon::pop_id p)
float get_raw_employment(sys::state const &state, dcon::pop_id p)
float get_life_needs(sys::state const &state, dcon::pop_id p)
float get_political_reform_desire(sys::state const &state, dcon::pop_id p)
float get_everyday_needs(sys::state const &state, dcon::pop_id p)
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
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:5773
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:82
int32_t read_int32_t_from_payload(uint16_t const *data)
Definition: triggers.cpp:133
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:169
auto make_value_accumulator(F &&f) -> value_accumulator< TAG, F >
Definition: triggers.cpp:368
auto compare_to_false(uint16_t trigger_code, A value_a) -> decltype(!value_a)
Definition: triggers.cpp:101
auto compare_values_eq(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a==value_b)
Definition: triggers.cpp:41
auto make_true_accumulator(F &&f) -> true_accumulator< F >
Definition: triggers.cpp:358
dcon::rebel_faction_id to_rebel(int32_t v)
Definition: triggers.hpp:152
bool compare(bool a, bool b)
Definition: triggers.cpp:204
auto compare_values(uint16_t trigger_code, A value_a, B value_b) -> decltype(value_a==value_b)
Definition: triggers.cpp:21
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:372
float read_float_from_payload(uint16_t const *data)
Definition: triggers.cpp:119
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:378
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:5796
auto empty_province_from_state_accumulator(sys::state const &ws, dcon::state_instance_id sid)
Definition: triggers.cpp:1250
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:363
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:5782
constexpr uint16_t association_ne
auto empty_province_accumulator(sys::state const &ws)
Definition: triggers.cpp:1222
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:5709
#define CALLTYPE
Definition: triggers.cpp:17
#define TRIGGER_FUNCTION(function_name)
Definition: triggers.cpp:175
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