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_instance), 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}
1846TRIGGER_FUNCTION(tf_diplo_points) {
1847 return compare_values(tval[0], ws.world.nation_get_diplomatic_points(to_nation(primary_slot)),
1848 read_float_from_payload(tval + 1));
1849}
1851 auto pid = payload(tval[1]).prov_id;
1852 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(pid), to_nation(primary_slot));
1853}
1854TRIGGER_FUNCTION(tf_owns_province) {
1855 auto pid = payload(tval[1]).prov_id;
1856 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)));
1857}
1858TRIGGER_FUNCTION(tf_controls) {
1859 auto pid = payload(tval[1]).prov_id;
1860 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(pid), to_nation(primary_slot));
1861}
1862TRIGGER_FUNCTION(tf_is_core_integer) {
1863 auto pid = payload(tval[1]).prov_id;
1864 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot));
1865 auto result = ve::apply(
1866 [&ws, pid](dcon::national_identity_id t) {
1867 for(auto c : ws.world.province_get_core(pid)) {
1868 if(c.get_identity() == t)
1869 return true;
1870 }
1871 return false;
1872 },
1873 tag);
1874 return compare_to_true(tval[0], result);
1875}
1876TRIGGER_FUNCTION(tf_is_core_this_nation) {
1877 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1878 auto result = ve::apply(
1879 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1880 for(auto c : ws.world.province_get_core(pid)) {
1881 if(c.get_identity() == t)
1882 return true;
1883 }
1884 return false;
1885 },
1886 to_prov(primary_slot), tag);
1887 return compare_to_true(tval[0], result);
1888}
1889TRIGGER_FUNCTION(tf_is_core_this_state) {
1890 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
1891 auto tag = ws.world.nation_get_identity_from_identity_holder(owner);
1892 auto result = ve::apply(
1893 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1894 for(auto c : ws.world.province_get_core(pid)) {
1895 if(c.get_identity() == t)
1896 return true;
1897 }
1898 return false;
1899 },
1900 to_prov(primary_slot), tag);
1901 return compare_to_true(tval[0], result);
1902}
1903TRIGGER_FUNCTION(tf_is_core_this_province) {
1904 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
1905 auto tag = ws.world.nation_get_identity_from_identity_holder(owner);
1906 auto result = ve::apply(
1907 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1908 for(auto c : ws.world.province_get_core(pid)) {
1909 if(c.get_identity() == t)
1910 return true;
1911 }
1912 return false;
1913 },
1914 to_prov(primary_slot), tag);
1915 return compare_to_true(tval[0], result);
1916}
1917TRIGGER_FUNCTION(tf_is_core_this_pop) {
1918 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
1919 auto tag = ws.world.nation_get_identity_from_identity_holder(owner);
1920 auto result = ve::apply(
1921 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1922 for(auto c : ws.world.province_get_core(pid)) {
1923 if(c.get_identity() == t)
1924 return true;
1925 }
1926 return false;
1927 },
1928 to_prov(primary_slot), tag);
1929 return compare_to_true(tval[0], result);
1930}
1931TRIGGER_FUNCTION(tf_is_core_from_nation) {
1932 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
1933 auto result = ve::apply(
1934 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1935 for(auto c : ws.world.province_get_core(pid)) {
1936 if(c.get_identity() == t)
1937 return true;
1938 }
1939 return false;
1940 },
1941 to_prov(primary_slot), tag);
1942 return compare_to_true(tval[0], result);
1943}
1944TRIGGER_FUNCTION(tf_is_core_reb) {
1945 auto rtags = ws.world.rebel_faction_get_defection_target(to_rebel(from_slot));
1946 auto result = ve::apply(
1947 [&ws](dcon::province_id pid, dcon::national_identity_id t) {
1948 for(auto c : ws.world.province_get_core(pid)) {
1949 if(c.get_identity() == t)
1950 return true;
1951 }
1952 return false;
1953 },
1954 to_prov(primary_slot), rtags);
1955 return compare_to_true(tval[0], result);
1956}
1957TRIGGER_FUNCTION(tf_is_core_state_from_nation) {
1958 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
1959 auto result = ve::apply(
1960 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1961 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1962 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1963 return false;
1964 }
1965 return true;
1966 },
1967 to_state(primary_slot), tag);
1968 return compare_to_true(tval[0], result);
1969}
1970TRIGGER_FUNCTION(tf_is_core_state_this_nation) {
1971 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot));
1972 auto result = ve::apply(
1973 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1974 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1975 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1976 return false;
1977 }
1978 return true;
1979 },
1980 to_state(primary_slot), tag);
1981 return compare_to_true(tval[0], result);
1982}
1983TRIGGER_FUNCTION(tf_is_core_state_this_province) {
1984 auto tag = ws.world.nation_get_identity_from_identity_holder(ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)));
1985 auto result = ve::apply(
1986 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
1987 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
1988 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
1989 return false;
1990 }
1991 return true;
1992 },
1993 to_state(primary_slot), tag);
1994 return compare_to_true(tval[0], result);
1995}
1996TRIGGER_FUNCTION(tf_is_core_state_this_pop) {
1997 auto tag = ws.world.nation_get_identity_from_identity_holder(nations::owner_of_pop(ws, to_pop(this_slot)));
1998 auto result = ve::apply(
1999 [&ws](dcon::state_instance_id sid, dcon::national_identity_id t) {
2000 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
2001 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
2002 return false;
2003 }
2004 return true;
2005 },
2006 to_state(primary_slot), tag);
2007 return compare_to_true(tval[0], result);
2008}
2009TRIGGER_FUNCTION(tf_is_core_boolean) {
2010 return compare_to_true(tval[0], ws.world.province_get_is_owner_core(to_prov(primary_slot)));
2011}
2012TRIGGER_FUNCTION(tf_is_core_tag) {
2013 auto result = ve::apply(
2014 [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) {
2015 return bool(ws.world.get_core_by_prov_tag_key(pid, t));
2016 },
2017 to_prov(primary_slot));
2018 return compare_to_true(tval[0], result);
2019}
2020TRIGGER_FUNCTION(tf_is_core_pop_tag) {
2021 auto result = ve::apply(
2022 [&ws, t = trigger::payload(tval[1]).tag_id](dcon::province_id pid) {
2023 return bool(ws.world.get_core_by_prov_tag_key(pid, t));
2024 },
2025 ws.world.pop_get_province_from_pop_location(to_pop(primary_slot)));
2026 return compare_to_true(tval[0], result);
2027}
2028TRIGGER_FUNCTION(tf_is_core_state_tag) {
2029 auto result = ve::apply(
2030 [&ws, t = trigger::payload(tval[1]).tag_id](dcon::state_instance_id sid) {
2031 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(sid))) {
2032 if(!(ws.world.get_core_by_prov_tag_key(p.get_province(), t)))
2033 return false;
2034 }
2035 return true;
2036 },
2037 to_state(primary_slot));
2038 return compare_to_true(tval[0], result);
2039}
2040TRIGGER_FUNCTION(tf_num_of_revolts) {
2041 return compare_values(tval[0], ws.world.nation_get_rebel_controlled_count(to_nation(primary_slot)), tval[1]);
2042}
2043TRIGGER_FUNCTION(tf_revolt_percentage) {
2044 return compare_values(tval[0], nations::central_reb_controlled_fraction(ws, to_nation(primary_slot)),
2045 read_float_from_payload(tval + 1));
2046}
2047TRIGGER_FUNCTION(tf_num_of_cities_int) {
2048 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)), tval[1]);
2049}
2050TRIGGER_FUNCTION(tf_num_of_cities_from_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(from_slot)));
2053}
2054TRIGGER_FUNCTION(tf_num_of_cities_this_nation) {
2055 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2056 ws.world.nation_get_owned_province_count(to_nation(this_slot)));
2057}
2058TRIGGER_FUNCTION(tf_num_of_cities_this_state) {
2059 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2060 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2061 ws.world.nation_get_owned_province_count(owner));
2062}
2063TRIGGER_FUNCTION(tf_num_of_cities_this_province) {
2064 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2065 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2066 ws.world.nation_get_owned_province_count(owner));
2067}
2068TRIGGER_FUNCTION(tf_num_of_cities_this_pop) {
2069 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2070 return compare_values(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)),
2071 ws.world.nation_get_owned_province_count(owner));
2072}
2073TRIGGER_FUNCTION(tf_num_of_ports) {
2074 return compare_values(tval[0], ws.world.nation_get_central_ports(to_nation(primary_slot)), tval[1]);
2075}
2076TRIGGER_FUNCTION(tf_num_of_allies) {
2077 return compare_values(tval[0], ws.world.nation_get_allies_count(to_nation(primary_slot)), tval[1]);
2078}
2079TRIGGER_FUNCTION(tf_num_of_vassals) {
2080 return compare_values(tval[0], ws.world.nation_get_vassals_count(to_nation(primary_slot)), tval[1]);
2081}
2082TRIGGER_FUNCTION(tf_owned_by_tag) {
2083 auto holders = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2084 return compare_values_eq(tval[0], holders, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2085}
2086TRIGGER_FUNCTION(tf_owned_by_this_nation) {
2087 return compare_values_eq(tval[0], to_nation(this_slot),
2088 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2089}
2090TRIGGER_FUNCTION(tf_owned_by_from_nation) {
2091 return compare_values_eq(tval[0], to_nation(from_slot),
2092 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2093}
2094TRIGGER_FUNCTION(tf_owned_by_this_province) {
2095 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)),
2096 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2097}
2098TRIGGER_FUNCTION(tf_owned_by_this_state) {
2099 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(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_this_pop) {
2103 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2104 return compare_values_eq(tval[0], owner, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
2105}
2106TRIGGER_FUNCTION(tf_owned_by_state_tag) {
2107 auto holders = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2108 return compare_values_eq(tval[0], holders, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2109}
2110TRIGGER_FUNCTION(tf_owned_by_state_this_nation) {
2111 return compare_values_eq(tval[0], to_nation(this_slot),
2112 ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2113}
2114TRIGGER_FUNCTION(tf_owned_by_state_from_nation) {
2115 return compare_values_eq(tval[0], to_nation(from_slot),
2116 ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2117}
2118TRIGGER_FUNCTION(tf_owned_by_state_this_province) {
2119 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)),
2120 ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2121}
2122TRIGGER_FUNCTION(tf_owned_by_state_this_state) {
2123 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(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_owned_by_state_this_pop) {
2127 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2128 return compare_values_eq(tval[0], owner, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)));
2129}
2130TRIGGER_FUNCTION(tf_exists_bool) {
2131 return compare_to_true(tval[0], ws.world.nation_get_owned_province_count(to_nation(primary_slot)) != 0);
2132}
2133TRIGGER_FUNCTION(tf_exists_tag) {
2134 auto holders = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2135 return compare_to_true(tval[0], ws.world.nation_get_owned_province_count(holders) != 0);
2136}
2137TRIGGER_FUNCTION(tf_has_country_flag) {
2138 return compare_to_true(tval[0], ws.world.nation_get_flag_variables(to_nation(primary_slot), payload(tval[1]).natf_id));
2139}
2140TRIGGER_FUNCTION(tf_has_country_flag_pop) {
2141 auto owner = nations::owner_of_pop(ws, to_pop(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_province) {
2145 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(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_has_country_flag_state) {
2149 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
2150 return compare_to_true(tval[0], ws.world.nation_get_flag_variables(owner, payload(tval[1]).natf_id));
2151}
2152TRIGGER_FUNCTION(tf_continent_province) {
2153 return compare_values_eq(tval[0], ws.world.province_get_continent(to_prov(primary_slot)), trigger::payload(tval[1]).mod_id);
2154}
2155TRIGGER_FUNCTION(tf_continent_state) {
2156 auto state_caps = ws.world.state_instance_get_capital(to_state(primary_slot));
2157 return compare_values_eq(tval[0], ws.world.province_get_continent(state_caps), trigger::payload(tval[1]).mod_id);
2158}
2159TRIGGER_FUNCTION(tf_continent_nation) {
2160 auto nat_caps = ws.world.nation_get_capital(to_nation(primary_slot));
2161 return compare_values_eq(tval[0], ws.world.province_get_continent(nat_caps), trigger::payload(tval[1]).mod_id);
2162}
2163TRIGGER_FUNCTION(tf_continent_pop) {
2164 auto prov_id = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
2165 return compare_values_eq(tval[0], ws.world.province_get_continent(prov_id), trigger::payload(tval[1]).mod_id);
2166}
2167TRIGGER_FUNCTION(tf_continent_nation_this) {
2168 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(primary_slot))),
2169 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2170}
2171TRIGGER_FUNCTION(tf_continent_state_this) {
2172 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.state_instance_get_capital(to_state(primary_slot))),
2173 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2174}
2175TRIGGER_FUNCTION(tf_continent_province_this) {
2176 return compare_values_eq(tval[0], ws.world.province_get_continent(to_prov(primary_slot)),
2177 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2178}
2179TRIGGER_FUNCTION(tf_continent_pop_this) {
2180 return compare_values_eq(tval[0],
2181 ws.world.province_get_continent(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))),
2182 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(this_slot))));
2183}
2184TRIGGER_FUNCTION(tf_continent_nation_from) {
2185 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(primary_slot))),
2186 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2187}
2188TRIGGER_FUNCTION(tf_continent_state_from) {
2189 return compare_values_eq(tval[0], ws.world.province_get_continent(ws.world.state_instance_get_capital(to_state(primary_slot))),
2190 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2191}
2192TRIGGER_FUNCTION(tf_continent_province_from) {
2193 return compare_values_eq(tval[0], ws.world.province_get_continent(to_prov(primary_slot)),
2194 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2195}
2196TRIGGER_FUNCTION(tf_continent_pop_from) {
2197 return compare_values_eq(tval[0],
2198 ws.world.province_get_continent(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))),
2199 ws.world.province_get_continent(ws.world.nation_get_capital(to_nation(from_slot))));
2200}
2201TRIGGER_FUNCTION(tf_casus_belli_tag) {
2202 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2203 auto result = ve::apply([&ws, tag_holder](dcon::nation_id n) { return military::can_use_cb_against(ws, n, tag_holder); },
2204 to_nation(primary_slot));
2205 return compare_to_true(tval[0], result);
2206}
2207TRIGGER_FUNCTION(tf_casus_belli_from) {
2208 auto result =
2209 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2210 to_nation(primary_slot), to_nation(from_slot));
2211 return compare_to_true(tval[0], result);
2212}
2213TRIGGER_FUNCTION(tf_casus_belli_this_nation) {
2214 auto result =
2215 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2216 to_nation(primary_slot), to_nation(this_slot));
2217 return compare_to_true(tval[0], result);
2218}
2219TRIGGER_FUNCTION(tf_casus_belli_this_state) {
2220 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2221 auto result =
2222 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2223 to_nation(primary_slot), owner);
2224 return compare_to_true(tval[0], result);
2225}
2226TRIGGER_FUNCTION(tf_casus_belli_this_province) {
2227 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2228 auto result =
2229 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2230 to_nation(primary_slot), owner);
2231 return compare_to_true(tval[0], result);
2232}
2233TRIGGER_FUNCTION(tf_casus_belli_this_pop) {
2234 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2235 auto result =
2236 ve::apply([&ws](dcon::nation_id n, dcon::nation_id target) { return military::can_use_cb_against(ws, n, target); },
2237 to_nation(primary_slot), owner);
2238 return compare_to_true(tval[0], result);
2239}
2240TRIGGER_FUNCTION(tf_military_access_tag) {
2241 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2242 auto result = ve::apply(
2243 [&ws, holder](dcon::nation_id n) {
2244 return ws.world.unilateral_relationship_get_military_access(
2245 ws.world.get_unilateral_relationship_by_unilateral_pair(holder, n));
2246 },
2247 to_nation(primary_slot));
2248 return compare_to_true(tval[0], result);
2249}
2250TRIGGER_FUNCTION(tf_military_access_from) {
2251 auto result = ve::apply(
2252 [&ws](dcon::nation_id n, dcon::nation_id t) {
2253 return ws.world.unilateral_relationship_get_military_access(
2254 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2255 },
2256 to_nation(primary_slot), to_nation(from_slot));
2257 return compare_to_true(tval[0], result);
2258}
2259TRIGGER_FUNCTION(tf_military_access_this_nation) {
2260 auto result = ve::apply(
2261 [&ws](dcon::nation_id n, dcon::nation_id t) {
2262 return ws.world.unilateral_relationship_get_military_access(
2263 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2264 },
2265 to_nation(primary_slot), to_nation(this_slot));
2266 return compare_to_true(tval[0], result);
2267}
2268TRIGGER_FUNCTION(tf_military_access_this_state) {
2269 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2270 auto result = ve::apply(
2271 [&ws](dcon::nation_id n, dcon::nation_id t) {
2272 return ws.world.unilateral_relationship_get_military_access(
2273 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2274 },
2275 to_nation(primary_slot), owner);
2276 return compare_to_true(tval[0], result);
2277}
2278TRIGGER_FUNCTION(tf_military_access_this_province) {
2279 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2280 auto result = ve::apply(
2281 [&ws](dcon::nation_id n, dcon::nation_id t) {
2282 return ws.world.unilateral_relationship_get_military_access(
2283 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2284 },
2285 to_nation(primary_slot), owner);
2286 return compare_to_true(tval[0], result);
2287}
2288TRIGGER_FUNCTION(tf_military_access_this_pop) {
2289 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2290 auto result = ve::apply(
2291 [&ws](dcon::nation_id n, dcon::nation_id t) {
2292 return ws.world.unilateral_relationship_get_military_access(
2293 ws.world.get_unilateral_relationship_by_unilateral_pair(t, n));
2294 },
2295 to_nation(primary_slot), owner);
2296 return compare_to_true(tval[0], result);
2297}
2298TRIGGER_FUNCTION(tf_prestige_value) {
2299 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), read_float_from_payload(tval + 1));
2300}
2301TRIGGER_FUNCTION(tf_prestige_from) {
2302 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)),
2303 ws.world.nation_get_prestige(to_nation(from_slot)));
2304}
2305TRIGGER_FUNCTION(tf_prestige_this_nation) {
2306 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)),
2307 ws.world.nation_get_prestige(to_nation(this_slot)));
2308}
2309TRIGGER_FUNCTION(tf_prestige_this_state) {
2310 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(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_province) {
2314 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2315 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), ws.world.nation_get_prestige(owner));
2316}
2317TRIGGER_FUNCTION(tf_prestige_this_pop) {
2318 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2319 return compare_values(tval[0], ws.world.nation_get_prestige(to_nation(primary_slot)), ws.world.nation_get_prestige(owner));
2320}
2322 return compare_values(tval[0], ws.world.nation_get_infamy(to_nation(primary_slot)), read_float_from_payload(tval + 1));
2323}
2324TRIGGER_FUNCTION(tf_has_building_fort) {
2325 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::fort)) != 0);
2326}
2327TRIGGER_FUNCTION(tf_has_building_railroad) {
2328 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad)) != 0);
2329}
2330TRIGGER_FUNCTION(tf_has_building_naval_base) {
2331 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);
2332}
2333
2334TRIGGER_FUNCTION(tf_has_building_factory) {
2335 auto result = ve::apply([&ws](dcon::state_instance_id s) { return economy::has_factory(ws, s); }, to_state(primary_slot));
2336 return compare_to_true(tval[0], result);
2337}
2338TRIGGER_FUNCTION(tf_has_building_state) {
2339 auto result =
2340 ve::apply([&ws, f = payload(tval[1]).fac_id](dcon::state_instance_id s) { return economy::has_building(ws, s, f); },
2341 to_state(primary_slot));
2342 return compare_to_true(tval[0], result);
2343}
2344TRIGGER_FUNCTION(tf_has_building_state_from_province) {
2345 auto state = ws.world.province_get_state_membership(to_prov(primary_slot));
2346 auto result =
2347 ve::apply([&ws, f = payload(tval[1]).fac_id](dcon::state_instance_id s) { return economy::has_building(ws, s, f); }, state);
2348 return compare_to_true(tval[0], result);
2349}
2350TRIGGER_FUNCTION(tf_has_building_factory_from_province) {
2351 auto state = ws.world.province_get_state_membership(to_prov(primary_slot));
2352 auto result = ve::apply([&ws](dcon::state_instance_id s) { return economy::has_factory(ws, s); }, state);
2353 return compare_to_true(tval[0], result);
2354}
2356 return compare_to_true(tval[0],
2357 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)) == dcon::nation_id());
2358}
2359TRIGGER_FUNCTION(tf_empty_state) {
2360 return compare_to_true(tval[0], to_state(primary_slot) == dcon::state_instance_id());
2361}
2362TRIGGER_FUNCTION(tf_is_blockaded) {
2363 return compare_to_true(tval[0], military::province_is_blockaded(ws, to_prov(primary_slot)));
2364}
2365TRIGGER_FUNCTION(tf_has_country_modifier) {
2366 auto const mod = trigger::payload(tval[1]).mod_id;
2367 auto result = ve::apply(
2368 [&ws, mod](dcon::nation_id n) {
2369 for(auto m : ws.world.nation_get_current_modifiers(n)) {
2370 if(m.mod_id == mod)
2371 return true;
2372 }
2373 return false;
2374 },
2375 to_nation(primary_slot));
2376 return compare_to_true(tval[0], result);
2377}
2378TRIGGER_FUNCTION(tf_has_country_modifier_province) {
2379 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2380 auto const mod = trigger::payload(tval[1]).mod_id;
2381 auto result = ve::apply(
2382 [&ws, mod](dcon::nation_id n) {
2383 for(auto m : ws.world.nation_get_current_modifiers(n)) {
2384 if(m.mod_id == mod)
2385 return true;
2386 }
2387 return false;
2388 },
2389 owner);
2390 return compare_to_true(tval[0], result);
2391}
2392TRIGGER_FUNCTION(tf_has_province_modifier) {
2393 auto const mod = trigger::payload(tval[1]).mod_id;
2394 auto result = ve::apply(
2395 [&ws, mod](dcon::province_id n) {
2396 for(auto m : ws.world.province_get_current_modifiers(n)) {
2397 if(m.mod_id == mod)
2398 return true;
2399 }
2400 return false;
2401 },
2402 to_prov(primary_slot));
2403 return compare_to_true(tval[0], result);
2404}
2406 return compare_values_eq(tval[0], ws.world.province_get_state_from_abstract_state_membership(to_prov(primary_slot)),
2407 trigger::payload(tval[1]).state_id);
2408}
2409TRIGGER_FUNCTION(tf_region_state) {
2410 return compare_values_eq(tval[0], ws.world.state_instance_get_definition(to_state(primary_slot)),
2411 trigger::payload(tval[1]).state_id);
2412}
2413TRIGGER_FUNCTION(tf_region_pop) {
2414 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);
2415}
2416
2417
2418TRIGGER_FUNCTION(tf_region_proper) {
2419 auto r = trigger::payload(tval[1]).reg_id;
2420 auto result = ve::apply([&ws, r](dcon::province_id p) {
2421 for(auto m : ws.world.province_get_region_membership(p)) {
2422 if(m.get_region() == r)
2423 return true;
2424 }
2425 return false;
2426 }, to_prov(primary_slot));
2427 return compare_to_true(tval[0], result);
2428}
2429TRIGGER_FUNCTION(tf_region_proper_state) {
2430 auto r = trigger::payload(tval[1]).reg_id;
2431 auto result = ve::apply([&ws, r](dcon::province_id p) {
2432 for(auto m : ws.world.province_get_region_membership(p)) {
2433 if(m.get_region() == r)
2434 return true;
2435 }
2436 return false;
2437 }, ws.world.state_instance_get_capital(to_state(primary_slot)));
2438 return compare_to_true(tval[0], result);
2439}
2440TRIGGER_FUNCTION(tf_region_proper_pop) {
2441 auto r = trigger::payload(tval[1]).reg_id;
2442 auto result = ve::apply([&ws, r](dcon::province_id p) {
2443 for(auto m : ws.world.province_get_region_membership(p)) {
2444 if(m.get_region() == r)
2445 return true;
2446 }
2447 return false;
2448 }, ws.world.pop_get_province_from_pop_location(to_pop(primary_slot)));
2449 return compare_to_true(tval[0], result);
2450}
2451TRIGGER_FUNCTION(tf_owns_region_proper) {
2452 auto result = ve::apply([&](dcon::region_id sd, dcon::nation_id n) {
2453 for(auto p : ws.world.region_get_region_membership(sd)) {
2454 if(p.get_province().get_nation_from_province_ownership() != n)
2455 return false;
2456 }
2457 return true;
2458 }, trigger::payload(tval[1]).reg_id, trigger::to_nation(primary_slot));
2459 return compare_to_true(tval[0], result);
2460}
2461TRIGGER_FUNCTION(tf_owns_region) {
2462 auto result = ve::apply([&](dcon::state_definition_id sd, dcon::nation_id n) {
2463 for(auto p : ws.world.state_definition_get_abstract_state_membership(sd)) {
2464 if(p.get_province().get_nation_from_province_ownership() != n)
2465 return false;
2466 }
2467 return true;
2468 }, trigger::payload(tval[1]).state_id, trigger::to_nation(primary_slot));
2469 return compare_to_true(tval[0], result);
2470}
2471TRIGGER_FUNCTION(tf_tag_tag) {
2472 return compare_values_eq(tval[0], ws.world.nation_get_identity_from_identity_holder(to_nation(primary_slot)),
2473 trigger::payload(tval[1]).tag_id);
2474}
2475TRIGGER_FUNCTION(tf_tag_this_nation) {
2476 return compare_values_eq(tval[0], to_nation(primary_slot), to_nation(this_slot));
2477}
2478TRIGGER_FUNCTION(tf_tag_this_province) {
2479 return compare_values_eq(tval[0], to_nation(primary_slot),
2480 ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)));
2481}
2482TRIGGER_FUNCTION(tf_tag_from_nation) {
2483 return compare_values_eq(tval[0], to_nation(primary_slot), to_nation(from_slot));
2484}
2485TRIGGER_FUNCTION(tf_tag_from_province) {
2486 return compare_values_eq(tval[0], to_nation(primary_slot),
2487 ws.world.province_get_nation_from_province_ownership(to_prov(from_slot)));
2488}
2489TRIGGER_FUNCTION(tf_tag_pop) {
2490 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2491 return compare_values_eq(tval[0], ws.world.nation_get_identity_from_identity_holder(owner), trigger::payload(tval[1]).tag_id);
2492}
2493TRIGGER_FUNCTION(tf_stronger_army_than_tag) {
2494 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2495
2496 auto main_brigades = ws.world.nation_get_active_regiments(to_nation(primary_slot));
2497 auto this_brigades = ws.world.nation_get_active_regiments(tag_holder);
2498 return compare_values(tval[0], main_brigades, this_brigades);
2499}
2500TRIGGER_FUNCTION(tf_stronger_army_than_this_nation) {
2501 auto main_brigades = ws.world.nation_get_active_regiments(to_nation(primary_slot));
2502 auto this_brigades = ws.world.nation_get_active_regiments(trigger::to_nation(this_slot));
2503 return compare_values(tval[0], main_brigades, this_brigades);
2504}
2505TRIGGER_FUNCTION(tf_stronger_army_than_this_state) {
2506 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(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_province) {
2510 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(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_this_pop) {
2514 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2515 return tf_stronger_army_than_this_nation<return_type>(tval, ws, primary_slot, to_generic(owner), int32_t());
2516}
2517TRIGGER_FUNCTION(tf_stronger_army_than_from_nation) {
2518 return tf_stronger_army_than_this_nation<return_type>(tval, ws, primary_slot, from_slot, int32_t());
2519}
2520TRIGGER_FUNCTION(tf_stronger_army_than_from_province) {
2521 return tf_stronger_army_than_this_province<return_type>(tval, ws, primary_slot, from_slot, int32_t());
2522}
2523TRIGGER_FUNCTION(tf_neighbour_tag) {
2524 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2525 auto result =
2526 ve::apply([&ws, tag_holder](
2527 dcon::nation_id n) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, tag_holder)); },
2528 to_nation(primary_slot));
2529 return compare_to_true(tval[0], result);
2530}
2531TRIGGER_FUNCTION(tf_neighbour_this) {
2532 auto result = ve::apply(
2533 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2534 to_nation(primary_slot), to_nation(this_slot));
2535 return compare_to_true(tval[0], result);
2536}
2537TRIGGER_FUNCTION(tf_neighbour_from) {
2538 auto result = ve::apply(
2539 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2540 to_nation(primary_slot), to_nation(from_slot));
2541 return compare_to_true(tval[0], result);
2542}
2543TRIGGER_FUNCTION(tf_neighbour_this_province) {
2544 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2545 auto result = ve::apply(
2546 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2547 to_nation(primary_slot), owner);
2548 return compare_to_true(tval[0], result);
2549}
2550TRIGGER_FUNCTION(tf_neighbour_from_province) {
2551 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
2552 auto result = ve::apply(
2553 [&ws](dcon::nation_id n, dcon::nation_id o) { return bool(ws.world.get_nation_adjacency_by_nation_adjacency_pair(n, o)); },
2554 to_nation(primary_slot), owner);
2555 return compare_to_true(tval[0], result);
2556}
2557TRIGGER_FUNCTION(tf_country_units_in_state_from) {
2558 auto result = ve::apply(
2559 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2560 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2561 if(p.get_province().get_state_membership() == s) {
2562 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2563 if(a.get_army().get_controller_from_army_control() == tag)
2564 return true;
2565 }
2566 }
2567 }
2568 return false;
2569 },
2570 to_state(primary_slot), to_nation(from_slot));
2571 return compare_to_true(tval[0], result);
2572}
2573TRIGGER_FUNCTION(tf_country_units_in_state_this_nation) {
2574 auto result = ve::apply(
2575 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2576 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2577 if(p.get_province().get_state_membership() == s) {
2578 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2579 if(a.get_army().get_controller_from_army_control() == tag)
2580 return true;
2581 }
2582 }
2583 }
2584 return false;
2585 },
2586 to_state(primary_slot), to_nation(this_slot));
2587 return compare_to_true(tval[0], result);
2588}
2589TRIGGER_FUNCTION(tf_country_units_in_state_this_province) {
2590 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2591 auto result = ve::apply(
2592 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2593 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2594 if(p.get_province().get_state_membership() == s) {
2595 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2596 if(a.get_army().get_controller_from_army_control() == tag)
2597 return true;
2598 }
2599 }
2600 }
2601 return false;
2602 },
2603 to_state(primary_slot), owner);
2604 return compare_to_true(tval[0], result);
2605}
2606TRIGGER_FUNCTION(tf_country_units_in_state_this_state) {
2607 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2608 auto result = ve::apply(
2609 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2610 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2611 if(p.get_province().get_state_membership() == s) {
2612 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2613 if(a.get_army().get_controller_from_army_control() == tag)
2614 return true;
2615 }
2616 }
2617 }
2618 return false;
2619 },
2620 to_state(primary_slot), owner);
2621 return compare_to_true(tval[0], result);
2622}
2623TRIGGER_FUNCTION(tf_country_units_in_state_this_pop) {
2624 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2625 auto result = ve::apply(
2626 [&ws](dcon::state_instance_id s, dcon::nation_id tag) {
2627 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2628 if(p.get_province().get_state_membership() == s) {
2629 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2630 if(a.get_army().get_controller_from_army_control() == tag)
2631 return true;
2632 }
2633 }
2634 }
2635 return false;
2636 },
2637 to_state(primary_slot), owner);
2638 return compare_to_true(tval[0], result);
2639}
2640TRIGGER_FUNCTION(tf_country_units_in_state_tag) {
2641 auto tag = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2642 auto result = ve::apply(
2643 [&ws, tag](dcon::state_instance_id s) {
2644 if(!tag)
2645 return false;
2646 for(auto p : ws.world.state_definition_get_abstract_state_membership(ws.world.state_instance_get_definition(s))) {
2647 if(p.get_province().get_state_membership() == s) {
2648 for(auto a : ws.world.province_get_army_location(p.get_province())) {
2649 if(a.get_army().get_controller_from_army_control() == tag)
2650 return true;
2651 }
2652 }
2653 }
2654 return false;
2655 },
2656 to_state(primary_slot));
2657 return compare_to_true(tval[0], result);
2658}
2659TRIGGER_FUNCTION(tf_units_in_province_value) {
2660 auto result = ve::apply(
2661 [&ws](dcon::province_id p) {
2662 int32_t total = 0;
2663 for(auto a : ws.world.province_get_army_location(p)) {
2664 for(auto u : a.get_army().get_army_membership()) {
2665 ++total;
2666 }
2667 }
2668 return total;
2669 },
2670 to_prov(primary_slot));
2671 return compare_values(tval[0], result, int32_t(tval[1]));
2672}
2673TRIGGER_FUNCTION(tf_units_in_province_tag) {
2674 auto tag = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2675 auto result = ve::apply(
2676 [&ws, tag](dcon::province_id p) {
2677 if(!tag)
2678 return false;
2679 for(auto a : ws.world.province_get_army_location(p)) {
2680 if(a.get_army().get_controller_from_army_control() == tag)
2681 return true;
2682 }
2683 return false;
2684 },
2685 to_prov(primary_slot));
2686 return compare_to_true(tval[0], result);
2687}
2688
2689TRIGGER_FUNCTION(tf_units_in_province_from) {
2690 auto result = ve::apply(
2691 [&ws](dcon::province_id p, dcon::nation_id n) {
2692 for(auto a : ws.world.province_get_army_location(p)) {
2693 if(a.get_army().get_controller_from_army_control() == n)
2694 return true;
2695 }
2696 return false;
2697 },
2698 to_prov(primary_slot), to_nation(from_slot));
2699 return compare_to_true(tval[0], result);
2700}
2701TRIGGER_FUNCTION(tf_units_in_province_this_nation) {
2702 auto result = ve::apply(
2703 [&ws](dcon::province_id p, dcon::nation_id n) {
2704 for(auto a : ws.world.province_get_army_location(p)) {
2705 if(a.get_army().get_controller_from_army_control() == n)
2706 return true;
2707 }
2708 return false;
2709 },
2710 to_prov(primary_slot), to_nation(this_slot));
2711 return compare_to_true(tval[0], result);
2712}
2713TRIGGER_FUNCTION(tf_units_in_province_this_province) {
2714 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2715 auto result = ve::apply(
2716 [&ws](dcon::province_id p, dcon::nation_id n) {
2717 for(auto a : ws.world.province_get_army_location(p)) {
2718 if(a.get_army().get_controller_from_army_control() == n)
2719 return true;
2720 }
2721 return false;
2722 },
2723 to_prov(primary_slot), owner);
2724 return compare_to_true(tval[0], result);
2725}
2726TRIGGER_FUNCTION(tf_units_in_province_this_state) {
2727 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2728 auto result = ve::apply(
2729 [&ws](dcon::province_id p, dcon::nation_id n) {
2730 for(auto a : ws.world.province_get_army_location(p)) {
2731 if(a.get_army().get_controller_from_army_control() == n)
2732 return true;
2733 }
2734 return false;
2735 },
2736 to_prov(primary_slot), owner);
2737 return compare_to_true(tval[0], result);
2738}
2739TRIGGER_FUNCTION(tf_units_in_province_this_pop) {
2740 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2741 auto result = ve::apply(
2742 [&ws](dcon::province_id p, dcon::nation_id n) {
2743 for(auto a : ws.world.province_get_army_location(p)) {
2744 if(a.get_army().get_controller_from_army_control() == n)
2745 return true;
2746 }
2747 return false;
2748 },
2749 to_prov(primary_slot), owner);
2750 return compare_to_true(tval[0], result);
2751}
2752TRIGGER_FUNCTION(tf_war_with_tag) {
2753 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2754 auto result =
2755 ve::apply([&ws, holder](dcon::nation_id a) { return military::are_at_war(ws, holder, a); }, to_nation(primary_slot));
2756 return compare_to_true(tval[0], result);
2757}
2758TRIGGER_FUNCTION(tf_war_with_from) {
2759 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2760 to_nation(primary_slot), to_nation(from_slot));
2761 return compare_to_true(tval[0], result);
2762}
2763TRIGGER_FUNCTION(tf_war_with_this_nation) {
2764 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2765 to_nation(primary_slot), to_nation(this_slot));
2766 return compare_to_true(tval[0], result);
2767}
2768TRIGGER_FUNCTION(tf_war_with_this_province) {
2769 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2770 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2771 to_nation(primary_slot), owner);
2772 return compare_to_true(tval[0], result);
2773}
2774TRIGGER_FUNCTION(tf_war_with_this_state) {
2775 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2776 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2777 to_nation(primary_slot), owner);
2778 return compare_to_true(tval[0], result);
2779}
2780TRIGGER_FUNCTION(tf_war_with_this_pop) {
2781 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
2782 auto result = ve::apply([&ws](dcon::nation_id a, dcon::nation_id b) { return military::are_at_war(ws, a, b); },
2783 to_nation(primary_slot), owner);
2784 return compare_to_true(tval[0], result);
2785}
2786TRIGGER_FUNCTION(tf_unit_in_battle) {
2787 return compare_to_true(tval[0], military::battle_is_ongoing_in_province(ws, to_prov(primary_slot)));
2788}
2789TRIGGER_FUNCTION(tf_unit_has_leader) {
2790 auto result = ve::apply([&ws](dcon::province_id p) {
2791 for(const auto ar : ws.world.province_get_army_location(p)) {
2792 if(ws.world.army_leadership_get_general(ws.world.army_get_army_leadership(ws.world.army_location_get_army(ar)))) {
2793 return true;
2794 }
2795 }
2796 return false;
2797 }, to_prov(primary_slot));
2798 return compare_to_true(tval[0], result);
2799}
2800TRIGGER_FUNCTION(tf_has_national_focus_state) {
2801 auto result = ve::apply([&ws, tval](dcon::state_instance_id p) {
2802 return ws.world.state_instance_get_owner_focus(p) == trigger::payload(tval[1]).nf_id;
2803 }, to_state(primary_slot));
2804 return compare_to_true(tval[0], result);
2805}
2806TRIGGER_FUNCTION(tf_has_national_focus_province) {
2807 auto result = ve::apply([&ws, tval](dcon::province_id p) {
2808 return ws.world.state_instance_get_owner_focus(ws.world.province_get_state_membership(p)) == trigger::payload(tval[1]).nf_id;
2809 }, to_prov(primary_slot));
2810 return compare_to_true(tval[0], result);
2811}
2812TRIGGER_FUNCTION(tf_total_amount_of_divisions) {
2813 return compare_values(tval[0], ws.world.nation_get_active_regiments(to_nation(primary_slot)), int32_t(tval[1]));
2814}
2816 return compare_values(tval[0], ws.world.nation_get_stockpiles(to_nation(primary_slot), economy::money),
2817 read_float_from_payload(tval + 1));
2818}
2819TRIGGER_FUNCTION(tf_money_province) {
2820 return compare_values(tval[0], ws.world.nation_get_stockpiles(ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)), economy::money),
2821 read_float_from_payload(tval + 1));
2822}
2823TRIGGER_FUNCTION(tf_lost_national) {
2824 return compare_values(tval[0], 1.0f - ws.world.nation_get_revanchism(to_nation(primary_slot)),
2825 read_float_from_payload(tval + 1));
2826}
2827TRIGGER_FUNCTION(tf_is_vassal) {
2828 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());
2829}
2830TRIGGER_FUNCTION(tf_ruling_party_ideology_nation) {
2831 auto rp = ws.world.nation_get_ruling_party(to_nation(primary_slot));
2832 return compare_values_eq(tval[0], ws.world.political_party_get_ideology(rp), trigger::payload(tval[1]).ideo_id);
2833}
2834TRIGGER_FUNCTION(tf_ruling_party_ideology_pop) {
2835 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2836 auto rp = ws.world.nation_get_ruling_party(owner);
2837 return compare_values_eq(tval[0], ws.world.political_party_get_ideology(rp), trigger::payload(tval[1]).ideo_id);
2838}
2839TRIGGER_FUNCTION(tf_ruling_party_ideology_province) {
2840 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2841 auto rp = ws.world.nation_get_ruling_party(owner);
2842 return compare_values_eq(tval[0], ws.world.political_party_get_ideology(rp), trigger::payload(tval[1]).ideo_id);
2843}
2844TRIGGER_FUNCTION(tf_ruling_party) {
2845 auto rp = ws.world.nation_get_ruling_party(to_nation(primary_slot));
2846 dcon::text_key name{dcon::text_key::value_base_t(read_int32_t_from_payload(tval + 1)) };
2847 return compare_values_eq(tval[0], ws.world.political_party_get_name(rp), name);
2848}
2849TRIGGER_FUNCTION(tf_is_ideology_enabled) {
2850 return compare_to_true(tval[0], ws.world.ideology_get_enabled(trigger::payload(tval[1]).ideo_id));
2851}
2852TRIGGER_FUNCTION(tf_political_reform_want_nation) {
2853 return compare_values(tval[0],
2854 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::political_reform_desire) *
2855 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
2856 read_float_from_payload(tval + 1));
2857}
2858TRIGGER_FUNCTION(tf_political_reform_want_pop) {
2859 return compare_values(tval[0], pop_demographics::get_political_reform_desire(ws, to_pop(primary_slot)),
2860 read_float_from_payload(tval + 1));
2861}
2862TRIGGER_FUNCTION(tf_social_reform_want_nation) {
2863 return compare_values(tval[0],
2864 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::social_reform_desire) *
2865 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
2866 read_float_from_payload(tval + 1));
2867}
2868TRIGGER_FUNCTION(tf_social_reform_want_pop) {
2869 return compare_values(tval[0], pop_demographics::get_social_reform_desire(ws, to_pop(primary_slot)), read_float_from_payload(tval + 1));
2870}
2871TRIGGER_FUNCTION(tf_total_amount_of_ships) {
2872 auto result = ve::apply(
2873 [&ws](dcon::nation_id n) {
2874 int32_t total = 0;
2875 for(auto a : ws.world.nation_get_navy_control(n)) {
2876 auto memb = a.get_navy().get_navy_membership();
2877 total += int32_t(memb.end() - memb.begin());
2878 }
2879 return total;
2880 },
2881 to_nation(primary_slot));
2882 return compare_values(tval[0], result, int32_t(tval[1]));
2883}
2884TRIGGER_FUNCTION(tf_plurality) {
2885 return compare_values(tval[0], ws.world.nation_get_plurality(to_nation(primary_slot)), read_float_from_payload(tval + 1) / 100.0f);
2886}
2887TRIGGER_FUNCTION(tf_plurality_pop) {
2888 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);
2889}
2890TRIGGER_FUNCTION(tf_corruption) {
2891 return compare_values(tval[0], nations::central_has_crime_fraction(ws, to_nation(primary_slot)),
2892 read_float_from_payload(tval + 1));
2893}
2894TRIGGER_FUNCTION(tf_is_state_religion_pop) {
2895 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2896 return compare_values_eq(tval[0], ws.world.nation_get_religion(owner), ws.world.pop_get_religion(to_pop(primary_slot)));
2897}
2898TRIGGER_FUNCTION(tf_is_state_religion_province) {
2899 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2900 return compare_values_eq(tval[0], ws.world.nation_get_religion(owner),
2901 ws.world.province_get_dominant_religion(to_prov(primary_slot)));
2902}
2903TRIGGER_FUNCTION(tf_is_state_religion_state) {
2904 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
2905 return compare_values_eq(tval[0], ws.world.nation_get_religion(owner),
2906 ws.world.state_instance_get_dominant_religion(to_state(primary_slot)));
2907}
2908TRIGGER_FUNCTION(tf_is_primary_culture_pop) {
2909 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
2910 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(owner), ws.world.pop_get_culture(to_pop(primary_slot)));
2911}
2912TRIGGER_FUNCTION(tf_is_primary_culture_province) {
2913 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
2914 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(owner),
2915 ws.world.province_get_dominant_culture(to_prov(primary_slot)));
2916}
2917TRIGGER_FUNCTION(tf_is_primary_culture_state) {
2918 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
2919 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(owner),
2920 ws.world.state_instance_get_dominant_culture(to_state(primary_slot)));
2921}
2922TRIGGER_FUNCTION(tf_primary_culture_from_nation) {
2923 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2924 ws.world.nation_get_primary_culture(to_nation(from_slot)));
2925}
2926TRIGGER_FUNCTION(tf_primary_culture_from_province) {
2927 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
2928 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2929 ws.world.nation_get_primary_culture(this_owner));
2930}
2931TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_nation) {
2932 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2933 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2934}
2935TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_pop) {
2936 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2937 ws.world.pop_get_culture(to_pop(this_slot)));
2938}
2939TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_state) {
2940 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2941 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2942 ws.world.nation_get_primary_culture(this_owner));
2943}
2944TRIGGER_FUNCTION(tf_is_primary_culture_nation_this_province) {
2945 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2946 return compare_values_eq(tval[0], ws.world.nation_get_primary_culture(to_nation(primary_slot)),
2947 ws.world.nation_get_primary_culture(this_owner));
2948}
2949TRIGGER_FUNCTION(tf_is_primary_culture_state_this_nation) {
2950 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2951 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2952}
2953TRIGGER_FUNCTION(tf_is_primary_culture_state_this_pop) {
2954 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
2955 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2956 ws.world.nation_get_primary_culture(this_owner));
2957}
2958TRIGGER_FUNCTION(tf_is_primary_culture_state_this_state) {
2959 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2960 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2961 ws.world.nation_get_primary_culture(this_owner));
2962}
2963TRIGGER_FUNCTION(tf_is_primary_culture_state_this_province) {
2964 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2965 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
2966 ws.world.nation_get_primary_culture(this_owner));
2967}
2968TRIGGER_FUNCTION(tf_is_primary_culture_province_this_nation) {
2969 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2970 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2971}
2972TRIGGER_FUNCTION(tf_is_primary_culture_province_this_pop) {
2973 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
2974 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2975 ws.world.nation_get_primary_culture(this_owner));
2976}
2977TRIGGER_FUNCTION(tf_is_primary_culture_province_this_state) {
2978 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2979 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2980 ws.world.nation_get_primary_culture(this_owner));
2981}
2982TRIGGER_FUNCTION(tf_is_primary_culture_province_this_province) {
2983 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
2984 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)),
2985 ws.world.nation_get_primary_culture(this_owner));
2986}
2987TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_nation) {
2988 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
2989 ws.world.nation_get_primary_culture(to_nation(this_slot)));
2990}
2991TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_pop) {
2992 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
2993 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
2994 ws.world.nation_get_primary_culture(this_owner));
2995}
2996TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_state) {
2997 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
2998 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
2999 ws.world.nation_get_primary_culture(this_owner));
3000}
3001TRIGGER_FUNCTION(tf_is_primary_culture_pop_this_province) {
3002 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3003 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)),
3004 ws.world.nation_get_primary_culture(this_owner));
3005}
3006
3007template<typename N, typename C>
3009 return ve::apply(
3010 [&ws](dcon::nation_id n, dcon::culture_id c) {
3011 return ws.world.nation_get_accepted_cultures(n, c);
3012 }, nids, cids);
3013}
3014
3015TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_nation) {
3016 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))));
3017}
3018TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_pop) {
3019 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(primary_slot), ws.world.pop_get_culture(to_pop(this_slot))));
3020}
3021TRIGGER_FUNCTION(tf_is_accepted_culture_nation_this_state) {
3022 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(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_nation_this_province) {
3026 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3027 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(primary_slot), ws.world.nation_get_primary_culture(this_owner)));
3028}
3029TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_nation) {
3030 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3031 ws.world.nation_get_primary_culture(to_nation(this_slot))));
3032}
3033TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_pop) {
3034 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
3035 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3036 ws.world.nation_get_primary_culture(this_owner)));
3037}
3038TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_state) {
3039 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3040 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3041 ws.world.nation_get_primary_culture(this_owner)));
3042}
3043TRIGGER_FUNCTION(tf_is_accepted_culture_state_this_province) {
3044 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3045 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot)),
3046 ws.world.nation_get_primary_culture(this_owner)));
3047}
3048TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_nation) {
3049 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3050 ws.world.nation_get_primary_culture(to_nation(this_slot))));
3051}
3052TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_pop) {
3053 auto this_owner = nations::owner_of_pop(ws, to_pop(this_slot));
3054 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3055 ws.world.nation_get_primary_culture(this_owner)));
3056}
3057TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_state) {
3058 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3059 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3060 ws.world.nation_get_primary_culture(this_owner)));
3061}
3062TRIGGER_FUNCTION(tf_is_accepted_culture_province_this_province) {
3063 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3064 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3065 ws.world.nation_get_primary_culture(this_owner)));
3066}
3067TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_nation) {
3068 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, to_nation(this_slot), ws.world.pop_get_culture(to_pop(primary_slot))));
3069}
3070TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_pop) {
3071 auto this_owner = nations::owner_of_pop(ws, to_pop(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_state) {
3075 auto this_owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(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}
3078TRIGGER_FUNCTION(tf_is_accepted_culture_pop_this_province) {
3079 auto this_owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3080 return compare_to_true(tval[0], internal_tf_culture_accepted(ws, this_owner, ws.world.pop_get_culture(to_pop(primary_slot))));
3081}
3082
3083TRIGGER_FUNCTION(tf_is_accepted_culture_pop) {
3084 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3085 auto is_accepted = ve::apply(
3086 [&ws](dcon::nation_id n, dcon::culture_id c) {
3087 if(n)
3088 return ws.world.nation_get_accepted_cultures(n, c);
3089 else
3090 return false;
3091 },
3092 owner, ws.world.pop_get_culture(to_pop(primary_slot)));
3093 return compare_to_true(tval[0], is_accepted);
3094}
3095TRIGGER_FUNCTION(tf_is_accepted_culture_province) {
3096 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3097 auto is_accepted = ve::apply(
3098 [&ws](dcon::nation_id n, dcon::culture_id c) {
3099 if(n)
3100 return ws.world.nation_get_accepted_cultures(n, c);
3101 else
3102 return false;
3103 },
3104 owner, ws.world.province_get_dominant_culture(to_prov(primary_slot)));
3105 return compare_to_true(tval[0], is_accepted);
3106}
3107TRIGGER_FUNCTION(tf_is_accepted_culture_state) {
3108 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3109 auto is_accepted = ve::apply(
3110 [&ws](dcon::nation_id n, dcon::culture_id c) {
3111 if(n)
3112 return ws.world.nation_get_accepted_cultures(n, c);
3113 else
3114 return false;
3115 },
3116 owner, ws.world.state_instance_get_dominant_culture(to_state(primary_slot)));
3117 return compare_to_true(tval[0], is_accepted);
3118}
3119TRIGGER_FUNCTION(tf_is_coastal_province) {
3120 return compare_to_true(tval[0], ws.world.province_get_is_coast(to_prov(primary_slot)));
3121}
3122TRIGGER_FUNCTION(tf_is_coastal_state) {
3123 auto result = ve::apply(
3124 [&ws](dcon::state_instance_id s) {
3125 return province::state_is_coastal(ws, s);
3126 },
3127 to_state(primary_slot));
3128 return compare_to_true(tval[0], result);
3129}
3130TRIGGER_FUNCTION(tf_in_sphere_tag) {
3131 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)),
3132 ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id));
3133}
3134TRIGGER_FUNCTION(tf_in_sphere_from) {
3135 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), to_nation(from_slot));
3136}
3137TRIGGER_FUNCTION(tf_in_sphere_this_nation) {
3138 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), to_nation(this_slot));
3139}
3140TRIGGER_FUNCTION(tf_in_sphere_this_province) {
3141 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(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_state) {
3145 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(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_in_sphere_this_pop) {
3149 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3150 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)), owner);
3151}
3152TRIGGER_FUNCTION(tf_produces_nation) {
3153 auto good = payload(tval[1]).com_id;
3154
3155 return compare_to_true(
3156 tval[0],
3157 ve::apply(
3158 [&ws, good](dcon::nation_id n) {
3159 return economy::supply(ws, n, good) > 0.0f;
3160 },
3161 to_nation(primary_slot)
3162 )
3163 );
3164}
3165TRIGGER_FUNCTION(tf_produces_province) {
3166 /* return compare_to_true(tval[0],
3167 (ws.world.province_get_rgo(to_prov(primary_slot)) == payload(tval[1]).com_id) ||
3168 (ws.world.province_get_artisan_production(to_prov(primary_slot)) == payload(tval[1]).com_id)); */
3169 return compare_to_true(tval[0], ws.world.province_get_rgo(to_prov(primary_slot)) == payload(tval[1]).com_id);
3170}
3171TRIGGER_FUNCTION(tf_produces_state) {
3172 auto good = payload(tval[1]).com_id;
3173 return compare_to_true(tval[0],
3174 ve::apply(
3175 [&](dcon::state_instance_id si, dcon::nation_id o) {
3176 auto d = ws.world.state_instance_get_definition(si);
3177 for(auto p : ws.world.state_definition_get_abstract_state_membership(d)) {
3178 if(p.get_province().get_nation_from_province_ownership() == o) {
3179 if(p.get_province().get_rgo() == good)
3180 return true;
3181 //if(p.get_province().get_artisan_production() == good)
3182 // return true;
3183
3184 for(auto f : p.get_province().get_factory_location()) {
3185 if(f.get_factory().get_building_type().get_output() == good)
3186 return true;
3187 }
3188 }
3189 }
3190 return false;
3191 },
3192 to_state(primary_slot), ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot))));
3193}
3194TRIGGER_FUNCTION(tf_produces_pop) {
3195 auto pop_location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3196 auto good = payload(tval[1]).com_id;
3197
3198 /*return compare_to_true(tval[0], (ws.world.pop_get_poptype(to_pop(primary_slot)) == ws.culture_definitions.artisans) &&
3199 (ws.world.province_get_artisan_production(pop_location) == good)); */
3200
3201 //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));
3202 return compare_to_true(tval[0], false);
3203}
3204TRIGGER_FUNCTION(tf_average_militancy_nation) {
3205 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
3206 auto mil_amount = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::militancy);
3207 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3208}
3209TRIGGER_FUNCTION(tf_average_militancy_state) {
3210 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
3211 auto mil_amount = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::militancy);
3212 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3213}
3214TRIGGER_FUNCTION(tf_average_militancy_province) {
3215 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
3216 auto mil_amount = ws.world.province_get_demographics(to_prov(primary_slot), demographics::militancy);
3217 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3218}
3219TRIGGER_FUNCTION(tf_average_consciousness_nation) {
3220 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
3221 auto mil_amount = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::consciousness);
3222 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3223}
3224TRIGGER_FUNCTION(tf_average_consciousness_state) {
3225 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
3226 auto mil_amount = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::consciousness);
3227 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3228}
3229TRIGGER_FUNCTION(tf_average_consciousness_province) {
3230 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
3231 auto mil_amount = ws.world.province_get_demographics(to_prov(primary_slot), demographics::consciousness);
3232 return compare_values(tval[0], ve::select(total_pop > 0, mil_amount / total_pop, 0.0f), read_float_from_payload(tval + 1));
3233}
3234TRIGGER_FUNCTION(tf_is_next_reform_nation) {
3235 auto ref_id = payload(tval[1]).opt_id;
3236 auto prior_opt = dcon::issue_option_id(dcon::issue_option_id::value_base_t(ref_id.index() - 1));
3237 auto reform_parent = ws.world.issue_option_get_parent_issue(ref_id);
3238 auto active_option = ws.world.nation_get_issues(to_nation(primary_slot), reform_parent);
3239
3240 return compare_values_eq(tval[0], active_option, prior_opt);
3241}
3242TRIGGER_FUNCTION(tf_is_next_reform_pop) {
3243 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3244
3245 auto ref_id = payload(tval[1]).opt_id;
3246 auto prior_opt = dcon::issue_option_id(dcon::issue_option_id::value_base_t(ref_id.index() - 1));
3247 auto reform_parent = ws.world.issue_option_get_parent_issue(ref_id);
3248 auto active_option = ws.world.nation_get_issues(owner, reform_parent);
3249
3250 return compare_values_eq(tval[0], active_option, prior_opt);
3251}
3252TRIGGER_FUNCTION(tf_is_next_rreform_nation) {
3253 auto ref_id = payload(tval[1]).ropt_id;
3254 auto prior_opt = dcon::reform_option_id(dcon::reform_option_id::value_base_t(ref_id.index() - 1));
3255 auto reform_parent = ws.world.reform_option_get_parent_reform(ref_id);
3256 auto active_option = ws.world.nation_get_reforms(to_nation(primary_slot), reform_parent);
3257
3258 return compare_values_eq(tval[0], active_option, prior_opt);
3259}
3260TRIGGER_FUNCTION(tf_is_next_rreform_pop) {
3261 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3262
3263 auto ref_id = payload(tval[1]).ropt_id;
3264 auto prior_opt = dcon::reform_option_id(dcon::reform_option_id::value_base_t(ref_id.index() - 1));
3265 auto reform_parent = ws.world.reform_option_get_parent_reform(ref_id);
3266 auto active_option = ws.world.nation_get_reforms(owner, reform_parent);
3267
3268 return compare_values_eq(tval[0], active_option, prior_opt);
3269}
3270TRIGGER_FUNCTION(tf_rebel_power_fraction) {
3271 // note: virtually unused
3272 return compare_to_true(tval[0], false);
3273}
3274TRIGGER_FUNCTION(tf_recruited_percentage_nation) {
3275 auto value = ve::apply([&ws](dcon::nation_id n) { return military::recruited_pop_fraction(ws, n); }, to_nation(primary_slot));
3276 return compare_values(tval[0], value, read_float_from_payload(tval + 1));
3277}
3278TRIGGER_FUNCTION(tf_recruited_percentage_pop) {
3279 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3280 auto value = ve::apply([&ws](dcon::nation_id n) { return military::recruited_pop_fraction(ws, n); }, owner);
3281 return compare_values(tval[0], value, read_float_from_payload(tval + 1));
3282}
3283TRIGGER_FUNCTION(tf_has_culture_core) {
3284 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3285 auto culture = ws.world.pop_get_culture(to_pop(primary_slot));
3286
3287 auto result = ve::apply(
3288 [&ws](dcon::province_id p, dcon::culture_id c) {
3289 for(auto co : ws.world.province_get_core(p)) {
3290 if(co.get_identity().get_primary_culture() == c)
3291 return true;
3292 }
3293 return false;
3294 },
3295 location, culture);
3296 return compare_to_true(tval[0], result);
3297}
3298TRIGGER_FUNCTION(tf_has_culture_core_province_this_pop) {
3299 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
3300
3301 auto result = ve::apply(
3302 [&ws](dcon::province_id p, dcon::culture_id c) {
3303 for(auto co : ws.world.province_get_core(p)) {
3304 if(co.get_identity().get_primary_culture() == c)
3305 return true;
3306 }
3307 return false;
3308 },
3309 to_prov(primary_slot), culture);
3310 return compare_to_true(tval[0], result);
3311}
3312TRIGGER_FUNCTION(tf_nationalism) {
3313 return compare_values(tval[0], ws.world.province_get_nationalism(to_prov(primary_slot)), float(tval[1]));
3314}
3315TRIGGER_FUNCTION(tf_is_overseas) {
3316 return compare_to_true(tval[0], province::is_overseas(ws, to_prov(primary_slot)));
3317}
3318TRIGGER_FUNCTION(tf_is_overseas_pop) {
3319 return compare_to_true(tval[0], province::is_overseas(ws, ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))));
3320}
3321TRIGGER_FUNCTION(tf_is_overseas_state) {
3322 return compare_to_true(tval[0], province::is_overseas(ws, ws.world.state_instance_get_capital(to_state(primary_slot))));
3323}
3324TRIGGER_FUNCTION(tf_controlled_by_rebels) {
3325 return compare_to_true(tval[0],
3326 ws.world.province_get_rebel_faction_from_province_rebel_control(to_prov(primary_slot)) != dcon::rebel_faction_id());
3327}
3328TRIGGER_FUNCTION(tf_controlled_by_tag) {
3329 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3330 ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id));
3331}
3332TRIGGER_FUNCTION(tf_controlled_by_from) {
3333 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3334 to_nation(from_slot));
3335}
3336TRIGGER_FUNCTION(tf_controlled_by_this_nation) {
3337 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3338 to_nation(this_slot));
3339}
3340TRIGGER_FUNCTION(tf_controlled_by_this_province) {
3341 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3342 ws.world.province_get_nation_from_province_ownership(to_prov(this_slot)));
3343}
3344TRIGGER_FUNCTION(tf_controlled_by_this_state) {
3345 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3346 ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot)));
3347}
3348TRIGGER_FUNCTION(tf_controlled_by_this_pop) {
3349 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_control(to_prov(primary_slot)),
3350 nations::owner_of_pop(ws, to_pop(this_slot)));
3351}
3352TRIGGER_FUNCTION(tf_controlled_by_owner) {
3353 return compare_values_eq(tval[0], ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)),
3354 ws.world.province_get_nation_from_province_control(to_prov(primary_slot)));
3355}
3356TRIGGER_FUNCTION(tf_controlled_by_reb) {
3357 return compare_values_eq(tval[0], ws.world.province_get_rebel_faction_from_province_rebel_control(to_prov(primary_slot)),
3358 to_rebel(from_slot));
3359}
3360TRIGGER_FUNCTION(tf_is_canal_enabled) {
3361 return compare_to_true(tval[0], (ws.world.province_adjacency_get_type(ws.province_definitions.canals[tval[1] - 1]) &
3363}
3364TRIGGER_FUNCTION(tf_is_state_capital) {
3365 auto sid = ws.world.province_get_state_membership(to_prov(primary_slot));
3366 return compare_values_eq(tval[0], ws.world.state_instance_get_capital(sid), to_prov(primary_slot));
3367}
3368TRIGGER_FUNCTION(tf_is_state_capital_pop) {
3369 auto id = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3370 auto sid = ws.world.province_get_state_membership(id);
3371 return compare_values_eq(tval[0], ws.world.state_instance_get_capital(sid), id);
3372}
3373TRIGGER_FUNCTION(tf_truce_with_tag) {
3374 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3375 auto result = ve::apply(
3376 [&ws, holder](dcon::nation_id a) {
3377 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, holder);
3378 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3379 return bool(date) && date > ws.current_date;
3380 },
3381 to_nation(primary_slot));
3382 return compare_to_true(tval[0], result);
3383}
3384TRIGGER_FUNCTION(tf_truce_with_from) {
3385 auto result = ve::apply(
3386 [&ws](dcon::nation_id a, dcon::nation_id b) {
3387 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3388 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3389 return bool(date) && date > ws.current_date;
3390 },
3391 to_nation(primary_slot), to_nation(from_slot));
3392 return compare_to_true(tval[0], result);
3393}
3394TRIGGER_FUNCTION(tf_truce_with_this_nation) {
3395 auto result = ve::apply(
3396 [&ws](dcon::nation_id a, dcon::nation_id b) {
3397 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3398 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3399 return bool(date) && date > ws.current_date;
3400 },
3401 to_nation(primary_slot), to_nation(this_slot));
3402 return compare_to_true(tval[0], result);
3403}
3404TRIGGER_FUNCTION(tf_truce_with_this_province) {
3405 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3406 auto result = ve::apply(
3407 [&ws](dcon::nation_id a, dcon::nation_id b) {
3408 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3409 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3410 return bool(date) && date > ws.current_date;
3411 },
3412 to_nation(primary_slot), owner);
3413 return compare_to_true(tval[0], result);
3414}
3415TRIGGER_FUNCTION(tf_truce_with_this_state) {
3416 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3417 auto result = ve::apply(
3418 [&ws](dcon::nation_id a, dcon::nation_id b) {
3419 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3420 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3421 return bool(date) && date > ws.current_date;
3422 },
3423 to_nation(primary_slot), owner);
3424 return compare_to_true(tval[0], result);
3425}
3426TRIGGER_FUNCTION(tf_truce_with_this_pop) {
3427 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3428 auto result = ve::apply(
3429 [&ws](dcon::nation_id a, dcon::nation_id b) {
3430 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
3431 auto date = ws.world.diplomatic_relation_get_truce_until(rel);
3432 return bool(date) && date > ws.current_date;
3433 },
3434 to_nation(primary_slot), owner);
3435 return compare_to_true(tval[0], result);
3436}
3437TRIGGER_FUNCTION(tf_total_pops_nation) {
3438 return compare_values(tval[0], ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total),
3439 read_float_from_payload(tval + 1));
3440}
3441TRIGGER_FUNCTION(tf_total_pops_state) {
3442 return compare_values(tval[0], ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total),
3443 read_float_from_payload(tval + 1));
3444}
3445TRIGGER_FUNCTION(tf_total_pops_province) {
3446 return compare_values(tval[0], ws.world.province_get_demographics(to_prov(primary_slot), demographics::total),
3447 read_float_from_payload(tval + 1));
3448}
3449TRIGGER_FUNCTION(tf_total_pops_pop) {
3450 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
3451 return compare_values(tval[0], ws.world.province_get_demographics(location, demographics::total),
3452 read_float_from_payload(tval + 1));
3453}
3454TRIGGER_FUNCTION(tf_has_pop_type_nation) {
3455 auto type = payload(tval[1]).popt_id;
3456 return compare_to_true(tval[0],
3457 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type)) > 0.0f);
3458}
3459TRIGGER_FUNCTION(tf_has_pop_type_state) {
3460 auto type = payload(tval[1]).popt_id;
3461 return compare_to_true(tval[0],
3462 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type)) > 0.0f);
3463}
3464TRIGGER_FUNCTION(tf_has_pop_type_province) {
3465 auto type = payload(tval[1]).popt_id;
3466 return compare_to_true(tval[0],
3467 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type)) > 0.0f);
3468}
3469TRIGGER_FUNCTION(tf_has_pop_type_pop) {
3470 auto type = payload(tval[1]).popt_id;
3471 return compare_values_eq(tval[0], ws.world.pop_get_poptype(to_pop(primary_slot)), type);
3472}
3473TRIGGER_FUNCTION(tf_has_empty_adjacent_province) {
3474 auto result = ve::apply(
3475 [&ws](dcon::province_id p) {
3476 auto acc = empty_province_accumulator(ws);
3477 for(auto a : ws.world.province_get_province_adjacency(p)) {
3478 auto other = a.get_connected_provinces(0) != p ? a.get_connected_provinces(0) : a.get_connected_provinces(1);
3479 acc.add_value(to_generic(other));
3480 if(acc.result)
3481 return true;
3482 }
3483 acc.flush();
3484 return acc.result;
3485 },
3486 to_prov(primary_slot));
3487 return compare_to_true(tval[0], result);
3488}
3489TRIGGER_FUNCTION(tf_has_leader) {
3490 dcon::unit_name_id name{ dcon::unit_name_id::value_base_t(read_int32_t_from_payload(tval + 1)) };
3491 auto result = ve::apply(
3492 [&ws, name](dcon::nation_id n) {
3493 for(auto l : ws.world.nation_get_leader_loyalty(n)) {
3494 auto lname = l.get_leader().get_name();
3495 if(ws.to_string_view(lname) == ws.to_string_view(name))
3496 return true;
3497 }
3498 return false;
3499 },
3500 to_nation(primary_slot));
3501 return compare_to_true(tval[0], result);
3502}
3504 return compare_to_false(tval[0], ws.world.nation_get_is_player_controlled(to_nation(primary_slot)));
3505}
3506TRIGGER_FUNCTION(tf_can_create_vassals) {
3507 auto result = ve::apply(
3508 [&ws](dcon::nation_id n) {
3509 for(uint32_t i = 0; i < ws.world.national_identity_size(); ++i) {
3510 dcon::national_identity_id tag{dcon::national_identity_id::value_base_t(i)};
3511 if(nations::can_release_as_vassal(ws, n, tag))
3512 return true;
3513 }
3514 return false;
3515 },
3516 to_nation(primary_slot));
3517 return compare_to_true(tval[0], result);
3518}
3519TRIGGER_FUNCTION(tf_is_possible_vassal) {
3520 auto tag = payload(tval[1]).tag_id;
3521 auto result =
3522 ve::apply([&ws, tag](dcon::nation_id n) { return nations::can_release_as_vassal(ws, n, tag); }, to_nation(primary_slot));
3523 return compare_to_true(tval[0], result);
3524}
3525TRIGGER_FUNCTION(tf_province_id) {
3526 return compare_values_eq(tval[0], to_prov(primary_slot), payload(tval[1]).prov_id);
3527}
3528TRIGGER_FUNCTION(tf_vassal_of_tag) {
3529 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3530 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3531 tag_holder);
3532}
3533TRIGGER_FUNCTION(tf_vassal_of_from) {
3534 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3535 to_nation(from_slot));
3536}
3537TRIGGER_FUNCTION(tf_vassal_of_this_nation) {
3538 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3539 to_nation(this_slot));
3540}
3541TRIGGER_FUNCTION(tf_vassal_of_this_province) {
3542 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3543 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3544 owner);
3545}
3546TRIGGER_FUNCTION(tf_vassal_of_this_state) {
3547 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3548 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3549 owner);
3550}
3551TRIGGER_FUNCTION(tf_vassal_of_this_pop) {
3552 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3553 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))),
3554 owner);
3555}
3556TRIGGER_FUNCTION(tf_vassal_of_province_tag) {
3557 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
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 tag_holder);
3560}
3561TRIGGER_FUNCTION(tf_vassal_of_province_from) {
3562 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)))),
3563 to_nation(from_slot));
3564}
3565TRIGGER_FUNCTION(tf_vassal_of_province_this_nation) {
3566 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)))),
3567 to_nation(this_slot));
3568}
3569TRIGGER_FUNCTION(tf_vassal_of_province_this_province) {
3570 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3571 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)))),
3572 owner);
3573}
3574TRIGGER_FUNCTION(tf_vassal_of_province_this_state) {
3575 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3576 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)))),
3577 owner);
3578}
3579TRIGGER_FUNCTION(tf_vassal_of_province_this_pop) {
3580 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3581 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)))),
3582 owner);
3583}
3584
3585
3586TRIGGER_FUNCTION(tf_substate_of_tag) {
3587 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3588 return compare_to_true(tval[0],
3589 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3590 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == tag_holder));
3591}
3592TRIGGER_FUNCTION(tf_substate_of_from) {
3593 return compare_to_true(tval[0], ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3594 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(
3595 to_nation(primary_slot))) == to_nation(from_slot)));
3596}
3597TRIGGER_FUNCTION(tf_substate_of_this_nation) {
3598 return compare_to_true(tval[0], ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3599 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(
3600 to_nation(primary_slot))) == to_nation(this_slot)));
3601}
3602TRIGGER_FUNCTION(tf_substate_of_this_province) {
3603 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3604 return compare_to_true(tval[0],
3605 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3606 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == owner));
3607}
3608TRIGGER_FUNCTION(tf_substate_of_this_state) {
3609 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3610 return compare_to_true(tval[0],
3611 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3612 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == owner));
3613}
3614TRIGGER_FUNCTION(tf_substate_of_this_pop) {
3615 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3616 return compare_to_true(tval[0],
3617 ws.world.nation_get_is_substate(to_nation(primary_slot)) &&
3618 (ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(primary_slot))) == owner));
3619}
3620TRIGGER_FUNCTION(tf_alliance_with_tag) {
3621 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3622 auto result = ve::apply(
3623 [&ws, tag_holder](dcon::nation_id n) {
3624 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, tag_holder);
3625 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3626 },
3627 to_nation(primary_slot));
3628 return compare_to_true(tval[0], result);
3629}
3630TRIGGER_FUNCTION(tf_alliance_with_from) {
3631 auto result = ve::apply(
3632 [&ws](dcon::nation_id n, dcon::nation_id m) {
3633 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3634 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3635 },
3636 to_nation(primary_slot), to_nation(from_slot));
3637 return compare_to_true(tval[0], result);
3638}
3639TRIGGER_FUNCTION(tf_alliance_with_this_nation) {
3640 auto result = ve::apply(
3641 [&ws](dcon::nation_id n, dcon::nation_id m) {
3642 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3643 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3644 },
3645 to_nation(primary_slot), to_nation(this_slot));
3646 return compare_to_true(tval[0], result);
3647}
3648TRIGGER_FUNCTION(tf_alliance_with_this_province) {
3649 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3650 auto result = ve::apply(
3651 [&ws](dcon::nation_id n, dcon::nation_id m) {
3652 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3653 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3654 },
3655 to_nation(primary_slot), owner);
3656 return compare_to_true(tval[0], result);
3657}
3658TRIGGER_FUNCTION(tf_alliance_with_this_state) {
3659 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3660 auto result = ve::apply(
3661 [&ws](dcon::nation_id n, dcon::nation_id m) {
3662 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3663 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3664 },
3665 to_nation(primary_slot), owner);
3666 return compare_to_true(tval[0], result);
3667}
3668TRIGGER_FUNCTION(tf_alliance_with_this_pop) {
3669 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3670 auto result = ve::apply(
3671 [&ws](dcon::nation_id n, dcon::nation_id m) {
3672 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(n, m);
3673 return bool(rel) && ws.world.diplomatic_relation_get_are_allied(rel);
3674 },
3675 to_nation(primary_slot), owner);
3676 return compare_to_true(tval[0], result);
3677}
3678TRIGGER_FUNCTION(tf_has_recently_lost_war) {
3679 return compare_to_true(tval[0], ve::apply(
3680 [&](dcon::nation_id n) {
3681 auto d = ws.world.nation_get_last_war_loss(n);
3682 return bool(d) && ws.current_date <= (d + 365 * 5);
3683 }, to_nation(primary_slot)));
3684}
3685TRIGGER_FUNCTION(tf_has_recently_lost_war_pop) {
3686 return compare_to_true(tval[0], ve::apply(
3687 [&](dcon::nation_id n) {
3688 auto d = ws.world.nation_get_last_war_loss(n);
3689 return bool(d) && ws.current_date <= (d + 365 * 5);
3690 }, nations::owner_of_pop(ws, to_pop(primary_slot))));
3691}
3692TRIGGER_FUNCTION(tf_is_mobilised) {
3693 return compare_to_true(tval[0], ws.world.nation_get_is_mobilized(to_nation(primary_slot)));
3694}
3695TRIGGER_FUNCTION(tf_mobilisation_size) {
3696 return compare_values(tval[0],
3697 ws.world.nation_get_modifier_values(to_nation(primary_slot), sys::national_mod_offsets::mobilization_size),
3698 read_float_from_payload(tval + 1));
3699}
3700TRIGGER_FUNCTION(tf_crime_higher_than_education_nation) {
3701 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(to_nation(primary_slot)) >=
3702 ws.world.nation_get_education_spending(to_nation(primary_slot)));
3703}
3704TRIGGER_FUNCTION(tf_crime_higher_than_education_state) {
3705 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3706 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(owner) >= ws.world.nation_get_education_spending(owner));
3707}
3708TRIGGER_FUNCTION(tf_crime_higher_than_education_province) {
3709 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3710 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(owner) >= ws.world.nation_get_education_spending(owner));
3711}
3712TRIGGER_FUNCTION(tf_crime_higher_than_education_pop) {
3713 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3714 return compare_to_true(tval[0], ws.world.nation_get_administrative_spending(owner) >= ws.world.nation_get_education_spending(owner));
3715}
3716TRIGGER_FUNCTION(tf_agree_with_ruling_party) {
3717 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3718 auto ruling_ideology = ws.world.political_party_get_ideology(ws.world.nation_get_ruling_party(owner));
3719 auto population_size = ws.world.pop_get_size(to_pop(primary_slot));
3720 auto ruling_support = ve::apply(
3721 [&](dcon::pop_id p, dcon::ideology_id i) {
3722 if(i)
3724 else
3725 return 0.0f;
3726 },
3727 to_pop(primary_slot), ruling_ideology);
3728 return compare_values(tval[0], ve::select(population_size > 0.0f, ruling_support / population_size, 0.0f),
3729 read_float_from_payload(tval + 1));
3730}
3731TRIGGER_FUNCTION(tf_is_colonial_state) {
3732 auto cap_p = ws.world.state_instance_get_capital(to_state(primary_slot));
3733 return compare_to_true(tval[0], ws.world.province_get_is_colonial(cap_p));
3734}
3735TRIGGER_FUNCTION(tf_is_colonial_province) {
3736 return compare_to_true(tval[0], ws.world.province_get_is_colonial(to_prov(primary_slot)));
3737}
3738TRIGGER_FUNCTION(tf_is_colonial_pop) {
3739 return compare_to_true(tval[0], ws.world.province_get_is_colonial(ws.world.pop_get_province_from_pop_location(to_pop(primary_slot))));
3740}
3741TRIGGER_FUNCTION(tf_has_factories_state) {
3742 auto result = ve::apply(
3743 [&ws](dcon::state_instance_id s) { return economy::has_factory(ws, s); },
3744 to_state(primary_slot));
3745 return compare_to_true(tval[0], result);
3746}
3747TRIGGER_FUNCTION(tf_has_factories_nation) {
3748 auto result = ve::apply(
3749 [&ws](dcon::nation_id n) {
3750 for(auto p : ws.world.nation_get_province_ownership(n)) {
3751 auto rng = p.get_province().get_factory_location();
3752 if(rng.begin() != rng.end())
3753 return true;
3754 }
3755 return false;
3756 },
3757 to_nation(primary_slot));
3758 return compare_to_true(tval[0], result);
3759}
3760TRIGGER_FUNCTION(tf_in_default_bool) {
3761 return compare_to_true(tval[0], ws.world.nation_get_is_bankrupt(to_nation(primary_slot)));
3762}
3763TRIGGER_FUNCTION(tf_in_default_tag) {
3764 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
3765 return compare_to_true(tval[0],
3766 ve::apply([&ws, holder](dcon::nation_id n) { return economy::is_bankrupt_debtor_to(ws, n, holder); },
3767 to_nation(primary_slot)));
3768}
3769TRIGGER_FUNCTION(tf_in_default_from) {
3770 return compare_to_true(tval[0],
3771 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3772 to_nation(primary_slot), to_nation(from_slot)));
3773}
3774TRIGGER_FUNCTION(tf_in_default_this_nation) {
3775 return compare_to_true(tval[0],
3776 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3777 to_nation(primary_slot), to_nation(this_slot)));
3778}
3779TRIGGER_FUNCTION(tf_in_default_this_province) {
3780 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3781 return compare_to_true(tval[0],
3782 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3783 to_nation(primary_slot), owner));
3784}
3785TRIGGER_FUNCTION(tf_in_default_this_state) {
3786 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3787 return compare_to_true(tval[0],
3788 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3789 to_nation(primary_slot), owner));
3790}
3791TRIGGER_FUNCTION(tf_in_default_this_pop) {
3792 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3793 return compare_to_true(tval[0],
3794 ve::apply([&ws](dcon::nation_id n, dcon::nation_id h) { return economy::is_bankrupt_debtor_to(ws, n, h); },
3795 to_nation(primary_slot), owner));
3796}
3797TRIGGER_FUNCTION(tf_total_num_of_ports) {
3798 return compare_values(tval[0], ws.world.nation_get_total_ports(to_nation(primary_slot)), tval[1]);
3799}
3801 return compare_to_true(tval[0], true);
3802}
3803TRIGGER_FUNCTION(tf_election) {
3804 return compare_to_true(tval[0], ve::apply(
3805 [&ws](dcon::nation_id n) {
3806 auto d = ws.world.nation_get_election_ends(n);
3807 return bool(d) && d > ws.current_date;
3808 }, to_nation(primary_slot)));
3809}
3810TRIGGER_FUNCTION(tf_has_global_flag) {
3811 return compare_to_true(tval[0], ws.national_definitions.is_global_flag_variable_set(payload(tval[1]).glob_id));
3812}
3813TRIGGER_FUNCTION(tf_is_capital) {
3814 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3815 return compare_values_eq(tval[0], ws.world.nation_get_capital(owner), to_prov(primary_slot));
3816}
3817TRIGGER_FUNCTION(tf_nationalvalue_nation) {
3818 return compare_values_eq(tval[0], ws.world.nation_get_national_value(to_nation(primary_slot)), payload(tval[1]).mod_id);
3819}
3820TRIGGER_FUNCTION(tf_nationalvalue_pop) {
3821 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3822 return compare_values_eq(tval[0], ws.world.nation_get_national_value(owner), payload(tval[1]).mod_id);
3823}
3824TRIGGER_FUNCTION(tf_nationalvalue_province) {
3825 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3826 return compare_values_eq(tval[0], ws.world.nation_get_national_value(owner), payload(tval[1]).mod_id);
3827}
3828TRIGGER_FUNCTION(tf_industrial_score_value) {
3829 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)), tval[1]);
3830}
3831TRIGGER_FUNCTION(tf_industrial_score_tag) {
3832 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3833 ws.world.nation_get_industrial_score(ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id)));
3834}
3835TRIGGER_FUNCTION(tf_industrial_score_from_nation) {
3836 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3837 ws.world.nation_get_industrial_score(to_nation(from_slot)));
3838}
3839TRIGGER_FUNCTION(tf_industrial_score_this_nation) {
3840 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3841 ws.world.nation_get_industrial_score(to_nation(this_slot)));
3842}
3843TRIGGER_FUNCTION(tf_industrial_score_this_pop) {
3844 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3845 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3846 ws.world.nation_get_industrial_score(owner));
3847}
3848TRIGGER_FUNCTION(tf_industrial_score_this_state) {
3849 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3850 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3851 ws.world.nation_get_industrial_score(owner));
3852}
3853TRIGGER_FUNCTION(tf_industrial_score_this_province) {
3854 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3855 return compare_values(tval[0], ws.world.nation_get_industrial_score(to_nation(primary_slot)),
3856 ws.world.nation_get_industrial_score(owner));
3857}
3858TRIGGER_FUNCTION(tf_military_score_value) {
3859 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)), tval[1]);
3860}
3861TRIGGER_FUNCTION(tf_military_score_tag) {
3862 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3863 ws.world.nation_get_military_score(ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id)));
3864}
3865TRIGGER_FUNCTION(tf_military_score_from_nation) {
3866 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3867 ws.world.nation_get_military_score(to_nation(from_slot)));
3868}
3869TRIGGER_FUNCTION(tf_military_score_this_nation) {
3870 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3871 ws.world.nation_get_military_score(to_nation(this_slot)));
3872}
3873TRIGGER_FUNCTION(tf_military_score_this_pop) {
3874 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
3875 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3876 ws.world.nation_get_military_score(owner));
3877}
3878TRIGGER_FUNCTION(tf_military_score_this_state) {
3879 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
3880 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3881 ws.world.nation_get_military_score(owner));
3882}
3883TRIGGER_FUNCTION(tf_military_score_this_province) {
3884 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
3885 return compare_values(tval[0], ws.world.nation_get_military_score(to_nation(primary_slot)),
3886 ws.world.nation_get_military_score(owner));
3887}
3888TRIGGER_FUNCTION(tf_civilized_nation) {
3889 return compare_to_true(tval[0], ws.world.nation_get_is_civilized(to_nation(primary_slot)));
3890}
3891TRIGGER_FUNCTION(tf_civilized_pop) {
3892 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3893 return compare_to_true(tval[0], ws.world.nation_get_is_civilized(owner));
3894}
3895TRIGGER_FUNCTION(tf_civilized_province) {
3896 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3897 return compare_to_true(tval[0], ws.world.nation_get_is_civilized(owner));
3898}
3899TRIGGER_FUNCTION(tf_national_provinces_occupied) {
3900 return compare_values(tval[0], nations::occupied_provinces_fraction(ws, to_nation(primary_slot)),
3901 read_float_from_payload(tval + 1));
3902}
3903TRIGGER_FUNCTION(tf_is_greater_power_nation) {
3904 return compare_to_true(tval[0], ws.world.nation_get_is_great_power(to_nation(primary_slot)));
3905}
3906TRIGGER_FUNCTION(tf_is_greater_power_pop) {
3907 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3908 return compare_to_true(tval[0], ws.world.nation_get_is_great_power(owner));
3909}
3910TRIGGER_FUNCTION(tf_is_greater_power_province) {
3911 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3912 return compare_to_true(tval[0], ws.world.nation_get_is_great_power(owner));
3913}
3914TRIGGER_FUNCTION(tf_rich_tax) {
3915 return compare_values(tval[0], ws.world.nation_get_rich_tax(to_nation(primary_slot)), payload(tval[1]).signed_value);
3916}
3917TRIGGER_FUNCTION(tf_middle_tax) {
3918 return compare_values(tval[0], ws.world.nation_get_middle_tax(to_nation(primary_slot)), payload(tval[1]).signed_value);
3919}
3920TRIGGER_FUNCTION(tf_poor_tax) {
3921 return compare_values(tval[0], ws.world.nation_get_poor_tax(to_nation(primary_slot)), payload(tval[1]).signed_value);
3922}
3923TRIGGER_FUNCTION(tf_rich_tax_pop) {
3924 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);
3925}
3926TRIGGER_FUNCTION(tf_middle_tax_pop) {
3927 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);
3928}
3929TRIGGER_FUNCTION(tf_poor_tax_pop) {
3930 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);
3931}
3932TRIGGER_FUNCTION(tf_social_spending_nation) {
3933 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));
3934}
3935TRIGGER_FUNCTION(tf_social_spending_pop) {
3936 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3937 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));
3938}
3939TRIGGER_FUNCTION(tf_social_spending_province) {
3940 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3941 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));
3942}
3943TRIGGER_FUNCTION(tf_military_spending_nation) {
3944 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));
3945}
3946TRIGGER_FUNCTION(tf_military_spending_pop) {
3947 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3948 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));
3949}
3950TRIGGER_FUNCTION(tf_military_spending_province) {
3951 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3952 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));
3953}
3954TRIGGER_FUNCTION(tf_military_spending_state) {
3955 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3956 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));
3957}
3958TRIGGER_FUNCTION(tf_administration_spending_nation) {
3959 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));
3960}
3961TRIGGER_FUNCTION(tf_administration_spending_pop) {
3962 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3963 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));
3964}
3965TRIGGER_FUNCTION(tf_administration_spending_province) {
3966 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3967 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));
3968}
3969TRIGGER_FUNCTION(tf_administration_spending_state) {
3970 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3971 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));
3972}
3973TRIGGER_FUNCTION(tf_education_spending_nation) {
3974 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));
3975}
3976TRIGGER_FUNCTION(tf_education_spending_pop) {
3977 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
3978 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));
3979}
3980TRIGGER_FUNCTION(tf_education_spending_province) {
3981 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
3982 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));
3983}
3984TRIGGER_FUNCTION(tf_education_spending_state) {
3985 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
3986 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));
3987}
3988TRIGGER_FUNCTION(tf_colonial_nation) {
3989 return compare_to_true(tval[0], ws.world.nation_get_is_colonial_nation(to_nation(primary_slot)));
3990}
3991TRIGGER_FUNCTION(tf_pop_majority_religion_nation) {
3992 return compare_values_eq(tval[0], ws.world.nation_get_dominant_religion(to_nation(primary_slot)), payload(tval[1]).rel_id);
3993}
3994TRIGGER_FUNCTION(tf_pop_majority_religion_nation_this_nation) {
3995 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)));
3996}
3997TRIGGER_FUNCTION(tf_pop_majority_religion_state) {
3998 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_religion(to_state(primary_slot)),
3999 payload(tval[1]).rel_id);
4000}
4001TRIGGER_FUNCTION(tf_pop_majority_religion_province) {
4002 return compare_values_eq(tval[0], ws.world.province_get_dominant_religion(to_prov(primary_slot)), payload(tval[1]).rel_id);
4003}
4004TRIGGER_FUNCTION(tf_pop_majority_culture_nation) {
4005 return compare_values_eq(tval[0], ws.world.nation_get_dominant_culture(to_nation(primary_slot)), payload(tval[1]).cul_id);
4006}
4007TRIGGER_FUNCTION(tf_pop_majority_culture_state) {
4008 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_culture(to_state(primary_slot)),
4009 payload(tval[1]).cul_id);
4010}
4011TRIGGER_FUNCTION(tf_pop_majority_culture_province) {
4012 return compare_values_eq(tval[0], ws.world.province_get_dominant_culture(to_prov(primary_slot)), payload(tval[1]).cul_id);
4013}
4014TRIGGER_FUNCTION(tf_pop_majority_issue_nation) {
4015 return compare_values_eq(tval[0], ws.world.nation_get_dominant_issue_option(to_nation(primary_slot)), payload(tval[1]).opt_id);
4016}
4017TRIGGER_FUNCTION(tf_pop_majority_issue_state) {
4018 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_issue_option(to_state(primary_slot)),
4019 payload(tval[1]).opt_id);
4020}
4021TRIGGER_FUNCTION(tf_pop_majority_issue_province) {
4022 return compare_values_eq(tval[0], ws.world.province_get_dominant_issue_option(to_prov(primary_slot)), payload(tval[1]).opt_id);
4023}
4024TRIGGER_FUNCTION(tf_pop_majority_issue_pop) {
4025 return compare_values_eq(tval[0], ws.world.pop_get_dominant_issue_option(to_pop(primary_slot)), payload(tval[1]).opt_id);
4026}
4027TRIGGER_FUNCTION(tf_pop_majority_ideology_nation) {
4028 return compare_values_eq(tval[0], ws.world.nation_get_dominant_ideology(to_nation(primary_slot)), payload(tval[1]).ideo_id);
4029}
4030TRIGGER_FUNCTION(tf_pop_majority_ideology_state) {
4031 return compare_values_eq(tval[0], ws.world.state_instance_get_dominant_ideology(to_state(primary_slot)),
4032 payload(tval[1]).ideo_id);
4033}
4034TRIGGER_FUNCTION(tf_pop_majority_ideology_province) {
4035 return compare_values_eq(tval[0], ws.world.province_get_dominant_ideology(to_prov(primary_slot)), payload(tval[1]).ideo_id);
4036}
4037TRIGGER_FUNCTION(tf_pop_majority_ideology_pop) {
4038 return compare_values_eq(tval[0], ws.world.pop_get_dominant_ideology(to_pop(primary_slot)), payload(tval[1]).ideo_id);
4039}
4040TRIGGER_FUNCTION(tf_poor_strata_militancy_nation) {
4041 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
4042 return compare_values(tval[0],
4043 ve::select(accumulator > 0.0f,
4044 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_militancy) / accumulator, 0.0f),
4045 read_float_from_payload(tval + 1));
4046}
4047TRIGGER_FUNCTION(tf_poor_strata_militancy_state) {
4048 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
4049 return compare_values(tval[0],
4050 ve::select(accumulator > 0.0f,
4051 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_militancy) / accumulator, 0.0f),
4052 read_float_from_payload(tval + 1));
4053}
4054TRIGGER_FUNCTION(tf_poor_strata_militancy_province) {
4055 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
4056 return compare_values(tval[0],
4057 ve::select(accumulator > 0.0f,
4058 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_militancy) / accumulator, 0.0f),
4059 read_float_from_payload(tval + 1));
4060}
4061TRIGGER_FUNCTION(tf_poor_strata_militancy_pop) {
4062 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
4063 auto is_poor = ws.world.pop_type_get_strata(type) == uint8_t(culture::pop_strata::poor);
4064 return compare_values(tval[0], ve::select(is_poor, pop_demographics::get_militancy(ws, to_pop(primary_slot)), 0.0f),
4065 read_float_from_payload(tval + 1));
4066}
4067TRIGGER_FUNCTION(tf_middle_strata_militancy_nation) {
4068 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4069 return compare_values(tval[0],
4070 ve::select(accumulator > 0.0f,
4071 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_militancy) / accumulator, 0.0f),
4072 read_float_from_payload(tval + 1));
4073}
4074TRIGGER_FUNCTION(tf_middle_strata_militancy_state) {
4075 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4076 return compare_values(tval[0],
4077 ve::select(accumulator > 0.0f,
4078 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_militancy) / accumulator, 0.0f),
4079 read_float_from_payload(tval + 1));
4080}
4081TRIGGER_FUNCTION(tf_middle_strata_militancy_province) {
4082 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4083 return compare_values(tval[0],
4084 ve::select(accumulator > 0.0f,
4085 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_militancy) / accumulator, 0.0f),
4086 read_float_from_payload(tval + 1));
4087}
4088TRIGGER_FUNCTION(tf_middle_strata_militancy_pop) {
4089 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
4090 auto is_middle = ws.world.pop_type_get_strata(type) == uint8_t(culture::pop_strata::middle);
4091 return compare_values(tval[0], ve::select(is_middle, pop_demographics::get_militancy(ws, to_pop(primary_slot)), 0.0f),
4092 read_float_from_payload(tval + 1));
4093}
4094TRIGGER_FUNCTION(tf_rich_strata_militancy_nation) {
4095 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4096 return compare_values(tval[0],
4097 ve::select(accumulator > 0.0f,
4098 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_militancy) / accumulator, 0.0f),
4099 read_float_from_payload(tval + 1));
4100}
4101TRIGGER_FUNCTION(tf_rich_strata_militancy_state) {
4102 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4103 return compare_values(tval[0],
4104 ve::select(accumulator > 0.0f,
4105 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_militancy) / accumulator, 0.0f),
4106 read_float_from_payload(tval + 1));
4107}
4108TRIGGER_FUNCTION(tf_rich_strata_militancy_province) {
4109 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4110 return compare_values(tval[0],
4111 ve::select(accumulator > 0.0f,
4112 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_militancy) / accumulator, 0.0f),
4113 read_float_from_payload(tval + 1));
4114}
4115TRIGGER_FUNCTION(tf_rich_strata_militancy_pop) {
4116 auto type = ws.world.pop_get_poptype(to_pop(primary_slot));
4117 auto is_rich = ws.world.pop_type_get_strata(type) == uint8_t(culture::pop_strata::rich);
4118 return compare_values(tval[0], ve::select(is_rich, pop_demographics::get_militancy(ws, to_pop(primary_slot)), 0.0f),
4119 read_float_from_payload(tval + 1));
4120}
4121TRIGGER_FUNCTION(tf_rich_tax_above_poor) {
4122 return compare_to_true(tval[0],
4123 ws.world.nation_get_rich_tax(to_nation(primary_slot)) > ws.world.nation_get_poor_tax(to_nation(primary_slot)));
4124}
4125TRIGGER_FUNCTION(tf_culture_has_union_tag_pop) {
4126 auto pop_culture = ws.world.pop_get_culture(to_pop(primary_slot));
4127 auto cg = ws.world.culture_get_group_from_culture_group_membership(pop_culture);
4128 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4129 return compare_to_true(tval[0], utag != dcon::national_identity_id());
4130}
4131TRIGGER_FUNCTION(tf_culture_has_union_tag_nation) {
4132 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4133 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4134 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4135 return compare_to_true(tval[0], utag != dcon::national_identity_id());
4136}
4137TRIGGER_FUNCTION(tf_this_culture_union_tag) {
4138 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4139 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4140 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4141 return compare_values_eq(tval[0], utag, payload(tval[1]).tag_id);
4142}
4143TRIGGER_FUNCTION(tf_this_culture_union_from) {
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(to_nation(from_slot)));
4148}
4149TRIGGER_FUNCTION(tf_this_culture_union_this_nation) {
4150 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4151 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4152 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4153 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(to_nation(this_slot)));
4154}
4155TRIGGER_FUNCTION(tf_this_culture_union_this_province) {
4156 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4157 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4158 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4159 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4160 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(owner));
4161}
4162TRIGGER_FUNCTION(tf_this_culture_union_this_state) {
4163 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4164 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4165 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4166 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4167 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(owner));
4168}
4169TRIGGER_FUNCTION(tf_this_culture_union_this_pop) {
4170 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4171 auto pc = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4172 auto cg = ws.world.culture_get_group_from_culture_group_membership(pc);
4173 auto utag = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
4174 return compare_values_eq(tval[0], utag, ws.world.nation_get_identity_from_identity_holder(owner));
4175}
4176TRIGGER_FUNCTION(tf_this_culture_union_this_union_nation) {
4177 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4178 auto this_culture = ws.world.nation_get_primary_culture(to_nation(this_slot));
4179 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4180 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4181 return compare_values_eq(tval[0], pcg, tcg);
4182}
4183TRIGGER_FUNCTION(tf_this_culture_union_this_union_province) {
4184 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4185 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4186 auto this_culture = ws.world.nation_get_primary_culture(owner);
4187 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4188 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4189 return compare_values_eq(tval[0], pcg, tcg);
4190}
4191TRIGGER_FUNCTION(tf_this_culture_union_this_union_state) {
4192 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4193 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4194 auto this_culture = ws.world.nation_get_primary_culture(owner);
4195 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4196 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4197 return compare_values_eq(tval[0], pcg, tcg);
4198}
4199TRIGGER_FUNCTION(tf_this_culture_union_this_union_pop) {
4200 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4201 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4202 auto this_culture = ws.world.nation_get_primary_culture(owner);
4203 auto pcg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4204 auto tcg = ws.world.culture_get_group_from_culture_group_membership(this_culture);
4205 return compare_values_eq(tval[0], pcg, tcg);
4206}
4207TRIGGER_FUNCTION(tf_minorities_nation) {
4208 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4209 auto pculture = ws.world.nation_get_primary_culture(to_nation(primary_slot));
4210
4211 auto accepted_pop = ve::apply(
4212 [&ws](dcon::nation_id n, dcon::culture_id pc) {
4213 if(!pc)
4214 return 0.0f;
4215 auto accumulated = ws.world.nation_get_demographics(n, demographics::to_key(ws, pc));
4216 for(auto ac : ws.world.in_culture) {
4217 if(ws.world.nation_get_accepted_cultures(n, ac)) {
4218 accumulated += ws.world.nation_get_demographics(n, demographics::to_key(ws, ac));
4219 }
4220 }
4221 return accumulated;
4222 },
4223 to_nation(primary_slot), pculture);
4224
4225 return compare_to_true(tval[0], total_pop != accepted_pop);
4226}
4227TRIGGER_FUNCTION(tf_minorities_state) {
4228 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4229 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
4230 auto pculture = ws.world.nation_get_primary_culture(owner);
4231
4232 auto accepted_pop = ve::apply(
4233 [&ws](dcon::state_instance_id i, dcon::nation_id n, dcon::culture_id pc) {
4234 if(!pc)
4235 return 0.0f;
4236 auto accumulated = ws.world.state_instance_get_demographics(i, demographics::to_key(ws, pc));
4237 for(auto ac : ws.world.in_culture) {
4238 if(ws.world.nation_get_accepted_cultures(n, ac)) {
4239 accumulated += ws.world.state_instance_get_demographics(i, demographics::to_key(ws, ac));
4240 }
4241 }
4242 return accumulated;
4243 },
4244 to_state(primary_slot), owner, pculture);
4245
4246 return compare_to_true(tval[0], total_pop != accepted_pop);
4247}
4248TRIGGER_FUNCTION(tf_minorities_province) {
4249 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4250 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
4251 auto pculture = ws.world.nation_get_primary_culture(owner);
4252
4253 auto accepted_pop = ve::apply(
4254 [&ws](dcon::province_id i, dcon::nation_id n, dcon::culture_id pc) {
4255 if(!pc)
4256 return 0.0f;
4257 auto accumulated = ws.world.province_get_demographics(i, demographics::to_key(ws, pc));
4258 for(auto ac : ws.world.in_culture) {
4259 if(ws.world.nation_get_accepted_cultures(n, ac)) {
4260 accumulated += ws.world.province_get_demographics(i, demographics::to_key(ws, ac));
4261 }
4262 }
4263 return accumulated;
4264 },
4265 to_prov(primary_slot), owner, pculture);
4266
4267 return compare_to_true(tval[0], total_pop != accepted_pop);
4268}
4269TRIGGER_FUNCTION(tf_revanchism_nation) {
4270 return compare_values(tval[0], ws.world.nation_get_revanchism(to_nation(primary_slot)), read_float_from_payload(tval + 1));
4271}
4272TRIGGER_FUNCTION(tf_revanchism_pop) {
4273 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
4274 return compare_values(tval[0], ws.world.nation_get_revanchism(owner), read_float_from_payload(tval + 1));
4275}
4276TRIGGER_FUNCTION(tf_has_crime) {
4277 return compare_to_true(tval[0], ws.world.province_get_crime(to_prov(primary_slot)) != dcon::crime_id());
4278}
4279TRIGGER_FUNCTION(tf_num_of_substates) {
4280 return compare_values(tval[0], ws.world.nation_get_substates_count(to_nation(primary_slot)), tval[1]);
4281}
4282TRIGGER_FUNCTION(tf_num_of_vassals_no_substates) {
4283 return compare_values(tval[0],
4284 ws.world.nation_get_vassals_count(to_nation(primary_slot)) - ws.world.nation_get_substates_count(to_nation(primary_slot)),
4285 tval[1]);
4286}
4287TRIGGER_FUNCTION(tf_brigades_compare_this) {
4288 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));
4289}
4290TRIGGER_FUNCTION(tf_brigades_compare_from) {
4291 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));
4292}
4293TRIGGER_FUNCTION(tf_brigades_compare_province_this) {
4294 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
4295 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));
4296}
4297TRIGGER_FUNCTION(tf_brigades_compare_province_from) {
4298 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
4299 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));
4300}
4301TRIGGER_FUNCTION(tf_constructing_cb_tag) {
4302 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4303 return compare_to_true(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)) == tag_holder);
4304}
4305TRIGGER_FUNCTION(tf_constructing_cb_from) {
4306 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), to_nation(from_slot));
4307}
4308TRIGGER_FUNCTION(tf_constructing_cb_this_nation) {
4309 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), to_nation(this_slot));
4310}
4311TRIGGER_FUNCTION(tf_constructing_cb_this_province) {
4312 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4313 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), owner);
4314}
4315TRIGGER_FUNCTION(tf_constructing_cb_this_state) {
4316 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4317 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), owner);
4318}
4319TRIGGER_FUNCTION(tf_constructing_cb_this_pop) {
4320 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4321 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_target(to_nation(primary_slot)), owner);
4322}
4323TRIGGER_FUNCTION(tf_constructing_cb_discovered) {
4324 return compare_to_true(tval[0], ws.world.nation_get_constructing_cb_is_discovered(to_nation(primary_slot)));
4325}
4326TRIGGER_FUNCTION(tf_constructing_cb_progress) {
4327 return compare_values(tval[0], ws.world.nation_get_constructing_cb_progress(to_nation(primary_slot)),
4328 read_float_from_payload(tval + 1));
4329}
4330TRIGGER_FUNCTION(tf_civilization_progress) {
4331 return compare_values(tval[0],
4332 ws.world.nation_get_modifier_values(to_nation(primary_slot), sys::national_mod_offsets::civilization_progress_modifier),
4333 read_float_from_payload(tval + 1));
4334}
4335TRIGGER_FUNCTION(tf_constructing_cb_type) {
4336 return compare_values_eq(tval[0], ws.world.nation_get_constructing_cb_type(to_nation(primary_slot)), payload(tval[1]).cb_id);
4337}
4338TRIGGER_FUNCTION(tf_is_our_vassal_tag) {
4339 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4340 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(tag_holder)),
4341 to_nation(primary_slot));
4342}
4343TRIGGER_FUNCTION(tf_is_our_vassal_from) {
4344 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(from_slot))),
4345 to_nation(primary_slot));
4346}
4347TRIGGER_FUNCTION(tf_is_our_vassal_this_nation) {
4348 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(this_slot))),
4349 to_nation(primary_slot));
4350}
4351TRIGGER_FUNCTION(tf_is_our_vassal_this_province) {
4352 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4353 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4354 to_nation(primary_slot));
4355}
4356TRIGGER_FUNCTION(tf_is_our_vassal_this_state) {
4357 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4358 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4359 to_nation(primary_slot));
4360}
4361TRIGGER_FUNCTION(tf_is_our_vassal_this_pop) {
4362 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4363 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4364 to_nation(primary_slot));
4365}
4366
4367TRIGGER_FUNCTION(tf_is_our_vassal_province_tag) {
4368 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4369 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(tag_holder)),
4370 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4371}
4372TRIGGER_FUNCTION(tf_is_our_vassal_province_from) {
4373 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(from_slot))),
4374 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4375}
4376TRIGGER_FUNCTION(tf_is_our_vassal_province_this_nation) {
4377 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(to_nation(this_slot))),
4378 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4379}
4380TRIGGER_FUNCTION(tf_is_our_vassal_province_this_province) {
4381 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4382 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4383 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4384}
4385TRIGGER_FUNCTION(tf_is_our_vassal_province_this_state) {
4386 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4387 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4388 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4389}
4390TRIGGER_FUNCTION(tf_is_our_vassal_province_this_pop) {
4391 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4392 return compare_values_eq(tval[0], ws.world.overlord_get_ruler(ws.world.nation_get_overlord_as_subject(owner)),
4393 ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot)));
4394}
4395
4396
4397TRIGGER_FUNCTION(tf_is_substate) {
4398 return compare_to_true(tval[0], ws.world.nation_get_is_substate(to_nation(primary_slot)));
4399}
4400TRIGGER_FUNCTION(tf_great_wars_enabled) {
4401 return compare_to_true(tval[0], ws.military_definitions.great_wars_enabled);
4402}
4403TRIGGER_FUNCTION(tf_can_nationalize) {
4404 auto result = ve::apply(
4405 [&ws](dcon::nation_id n) {
4406 for(auto c : ws.world.nation_get_unilateral_relationship_as_target(n)) {
4407 if(c.get_foreign_investment() > 0.0f)
4408 return true;
4409 }
4410 return false;
4411 },
4412 to_nation(primary_slot));
4413 return compare_to_true(tval[0], result);
4414}
4415TRIGGER_FUNCTION(tf_part_of_sphere) {
4416 return compare_to_true(tval[0], ws.world.nation_get_in_sphere_of(to_nation(primary_slot)) != dcon::nation_id());
4417}
4418TRIGGER_FUNCTION(tf_is_sphere_leader_of_tag) {
4419 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[1]).tag_id);
4420 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(holder), to_nation(primary_slot));
4421}
4422TRIGGER_FUNCTION(tf_is_sphere_leader_of_from) {
4423 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(from_slot)), to_nation(primary_slot));
4424}
4425TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_nation) {
4426 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(to_nation(this_slot)), to_nation(primary_slot));
4427}
4428TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_province) {
4429 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
4430 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(owner), to_nation(primary_slot));
4431}
4432TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_state) {
4433 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
4434 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(owner), to_nation(primary_slot));
4435}
4436TRIGGER_FUNCTION(tf_is_sphere_leader_of_this_pop) {
4437 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
4438 return compare_values_eq(tval[0], ws.world.nation_get_in_sphere_of(owner), to_nation(primary_slot));
4439}
4440TRIGGER_FUNCTION(tf_number_of_states) {
4441 return compare_values(tval[0], ws.world.nation_get_owned_state_count(to_nation(primary_slot)), tval[1]);
4442}
4443TRIGGER_FUNCTION(tf_war_score) {
4444 auto result = ve::apply([&](dcon::nation_id n) {
4445 auto score = 0.f;
4446 auto wp = ws.world.nation_get_war_participant(n);
4447 if(wp.begin() == wp.end()) {
4448 return 0.f;
4449 }
4450 for(auto w : wp) {
4451 if(w.get_is_attacker()) {
4452 score += military::primary_warscore(ws, w.get_war());
4453 } else {
4454 score -= military::primary_warscore(ws, w.get_war());
4455 }
4456 }
4457 return score / float(wp.end() - wp.begin());
4458 }, to_nation(primary_slot));
4459 return compare_values(tval[0], result, read_float_from_payload(tval + 1));
4460}
4461TRIGGER_FUNCTION(tf_is_releasable_vassal_from) {
4462 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
4463 return compare_to_true(tval[0], !ws.world.national_identity_get_is_not_releasable(tag));
4464}
4465TRIGGER_FUNCTION(tf_is_releasable_vassal_other) {
4466 auto tag = ws.world.nation_get_identity_from_identity_holder(to_nation(from_slot));
4467 return compare_to_true(tval[0], !ws.world.national_identity_get_is_not_releasable(tag));
4468}
4469TRIGGER_FUNCTION(tf_has_recent_imigration) {
4470 return compare_values(tval[0],
4471 int32_t(tval[1]) +
4472 ve::apply([&ws](dcon::province_id p) { return ws.world.province_get_last_immigration(p).to_raw_value(); },
4473 to_prov(primary_slot)),
4474 ws.current_date.to_raw_value());
4475}
4476TRIGGER_FUNCTION(tf_province_control_days) {
4477 return compare_values(tval[0],
4478 ws.current_date.to_raw_value() -
4479 ve::apply([&ws](dcon::province_id p) { return ws.world.province_get_last_control_change(p).to_raw_value(); },
4480 to_prov(primary_slot)),
4481 int32_t(tval[1]));
4482}
4483TRIGGER_FUNCTION(tf_is_disarmed) {
4484 return compare_to_true(tval[0], ve::apply([&ws](dcon::nation_id n) {
4485 auto d = ws.world.nation_get_disarmed_until(n);
4486 return bool(d) && ws.current_date < d;
4487 }, to_nation(primary_slot)));
4488}
4489TRIGGER_FUNCTION(tf_is_disarmed_pop) {
4490 return compare_to_true(tval[0], ve::apply([&ws](dcon::nation_id n) {
4491 auto d = ws.world.nation_get_disarmed_until(n);
4492 return bool(d) && ws.current_date < d;
4493 }, nations::owner_of_pop(ws, to_pop(primary_slot))));
4494}
4495TRIGGER_FUNCTION(tf_big_producer) {
4496 // stub: used only rarely in ai chances and would be expensive to test
4497 return compare_to_true(tval[0], false);
4498}
4499TRIGGER_FUNCTION(tf_someone_can_form_union_tag_from) {
4500 // stub: apparently unused
4501 return compare_to_true(tval[0], false);
4502}
4503TRIGGER_FUNCTION(tf_someone_can_form_union_tag_other) {
4504 // stub: apparently unused
4505 return compare_to_true(tval[0], false);
4506}
4507TRIGGER_FUNCTION(tf_social_movement_strength) {
4508 return compare_values(tval[0],
4509 ve::apply(
4510 [&ws](dcon::nation_id n) {
4511 float max_str = 0.0f;
4512 for(auto m : ws.world.nation_get_movement_within(n)) {
4513 auto issue = m.get_movement().get_associated_issue_option();
4514 if(issue) {
4515 if(culture::issue_type(issue.get_parent_issue().get_issue_type()) == culture::issue_type::social &&
4516 m.get_movement().get_pop_support() > max_str) {
4517 max_str = m.get_movement().get_pop_support();
4518 }
4519 }
4520 }
4521 return max_str;
4522 },
4523 to_nation(primary_slot)) *
4524 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
4525 read_float_from_payload(tval + 1));
4526}
4527TRIGGER_FUNCTION(tf_political_movement_strength) {
4528 return compare_values(tval[0],
4529 ve::apply(
4530 [&ws](dcon::nation_id n) {
4531 float max_str = 0.0f;
4532 for(auto m : ws.world.nation_get_movement_within(n)) {
4533 auto issue = m.get_movement().get_associated_issue_option();
4534 if(issue) {
4535 if(culture::issue_type(issue.get_parent_issue().get_issue_type()) == culture::issue_type::political &&
4536 m.get_movement().get_pop_support() > max_str) {
4537 max_str = m.get_movement().get_pop_support();
4538 }
4539 }
4540 }
4541 return max_str;
4542 },
4543 to_nation(primary_slot)) *
4544 ws.defines.movement_support_uh_factor / ws.world.nation_get_non_colonial_population(to_nation(primary_slot)),
4545 read_float_from_payload(tval + 1));
4546}
4547TRIGGER_FUNCTION(tf_can_build_factory_in_capital_state) {
4548 // stub: virtually unused
4549 return compare_to_true(tval[0], true);
4550}
4551TRIGGER_FUNCTION(tf_social_movement) {
4552 return compare_to_true(tval[0], ve::apply(
4553 [&ws](dcon::pop_id p) {
4554 auto m = fatten(ws.world, ws.world.pop_get_movement_from_pop_movement_membership(p));
4555 return m && m.get_associated_issue_option() &&
4557 m.get_associated_issue_option().get_parent_issue().get_issue_type()) ==
4559 },
4560 to_pop(primary_slot)));
4561}
4562TRIGGER_FUNCTION(tf_political_movement) {
4563 return compare_to_true(tval[0], ve::apply(
4564 [&ws](dcon::pop_id p) {
4565 auto m = fatten(ws.world, ws.world.pop_get_movement_from_pop_movement_membership(p));
4566 return m && m.get_associated_issue_option() &&
4568 m.get_associated_issue_option().get_parent_issue().get_issue_type()) ==
4570 },
4571 to_pop(primary_slot)));
4572}
4573TRIGGER_FUNCTION(tf_political_movement_from_reb) {
4574 // returns false because I'm not sure exactly what it is supposed to do (applies to the below as well)
4575 // it is called in nation scope while modifying chances for a rebel faction to spawn
4576 // perhaps reducing the chance if there is an "appropriate" movement (because there is almost always some movement)
4577 // however, the logic from working backwards from rebel factions to movements is not clear to me
4578 return compare_to_true(tval[0], false);
4579}
4580TRIGGER_FUNCTION(tf_social_movement_from_reb) {
4581 return compare_to_true(tval[0], false);
4582}
4583
4584TRIGGER_FUNCTION(tf_has_cultural_sphere) {
4585 auto prim_culture = ws.world.nation_get_primary_culture(to_nation(this_slot));
4586 auto culture_group = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
4587
4588 auto result = ve::apply(
4589 [&ws](dcon::nation_id n, dcon::culture_group_id g) {
4590 for(auto s : ws.world.nation_get_gp_relationship_as_great_power(n)) {
4591 if((s.get_status() & nations::influence::level_mask) == nations::influence::level_in_sphere &&
4592 s.get_influence_target().get_primary_culture().get_group_from_culture_group_membership() == g) {
4593 return true;
4594 }
4595 }
4596 return false;
4597 },
4598 to_nation(primary_slot), culture_group);
4599
4600 return compare_to_true(tval[0], result);
4601}
4602TRIGGER_FUNCTION(tf_world_wars_enabled) {
4603 return compare_to_true(tval[0], ws.military_definitions.world_wars_enabled);
4604}
4605TRIGGER_FUNCTION(tf_has_pop_culture_pop_this_pop) {
4606 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)), ws.world.pop_get_culture(to_pop(this_slot)));
4607}
4608TRIGGER_FUNCTION(tf_has_pop_culture_state_this_pop) {
4609 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
4610 auto result = ve::apply(
4611 [&ws](dcon::state_instance_id s, dcon::culture_id c) {
4612 return bool(c) ? ws.world.state_instance_get_demographics(s, demographics::to_key(ws, c)) > 0.0f : false;
4613 },
4614 to_state(primary_slot), culture);
4615 return compare_to_true(tval[0], result);
4616}
4617TRIGGER_FUNCTION(tf_has_pop_culture_province_this_pop) {
4618 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
4619 auto result = ve::apply(
4620 [&ws](dcon::province_id s, dcon::culture_id c) {
4621 return bool(c) ? ws.world.province_get_demographics(s, demographics::to_key(ws, c)) > 0.0f : false;
4622 },
4623 to_prov(primary_slot), culture);
4624 return compare_to_true(tval[0], result);
4625}
4626TRIGGER_FUNCTION(tf_has_pop_culture_nation_this_pop) {
4627 auto culture = ws.world.pop_get_culture(to_pop(this_slot));
4628 auto result = ve::apply(
4629 [&ws](dcon::nation_id s, dcon::culture_id c) {
4630 return bool(c) ? ws.world.nation_get_demographics(s, demographics::to_key(ws, c)) > 0.0f : false;
4631 },
4632 to_nation(primary_slot), culture);
4633 return compare_to_true(tval[0], result);
4634}
4635TRIGGER_FUNCTION(tf_has_pop_culture_pop) {
4636 return compare_values_eq(tval[0], ws.world.pop_get_culture(to_pop(primary_slot)), payload(tval[1]).cul_id);
4637}
4638TRIGGER_FUNCTION(tf_has_pop_culture_state) {
4639 return compare_to_true(tval[0],
4640 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, payload(tval[1]).cul_id)) > 0.0f);
4641}
4642TRIGGER_FUNCTION(tf_has_pop_culture_province) {
4643 return compare_to_true(tval[0],
4644 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, payload(tval[1]).cul_id)) > 0.0f);
4645}
4646TRIGGER_FUNCTION(tf_has_pop_culture_nation) {
4647 return compare_to_true(tval[0],
4648 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, payload(tval[1]).cul_id)) > 0.0f);
4649}
4650TRIGGER_FUNCTION(tf_has_pop_religion_pop_this_pop) {
4651 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)),
4652 ws.world.pop_get_religion(to_pop(this_slot)));
4653}
4654TRIGGER_FUNCTION(tf_has_pop_religion_state_this_pop) {
4655 auto rel = ws.world.pop_get_religion(to_pop(this_slot));
4656 auto result = ve::apply(
4657 [&ws](dcon::state_instance_id s, dcon::religion_id r) {
4658 return bool(r) ? ws.world.state_instance_get_demographics(s, demographics::to_key(ws, r)) > 0.0f : false;
4659 },
4660 to_state(primary_slot), rel);
4661 return compare_to_true(tval[0], result);
4662}
4663TRIGGER_FUNCTION(tf_has_pop_religion_province_this_pop) {
4664 auto rel = ws.world.pop_get_religion(to_pop(this_slot));
4665 auto result = ve::apply(
4666 [&ws](dcon::province_id s, dcon::religion_id r) {
4667 return bool(r) ? ws.world.province_get_demographics(s, demographics::to_key(ws, r)) > 0.0f : false;
4668 },
4669 to_prov(primary_slot), rel);
4670 return compare_to_true(tval[0], result);
4671}
4672TRIGGER_FUNCTION(tf_has_pop_religion_nation_this_pop) {
4673 auto rel = ws.world.pop_get_religion(to_pop(this_slot));
4674 auto result = ve::apply(
4675 [&ws](dcon::nation_id s, dcon::religion_id r) {
4676 return bool(r) ? ws.world.nation_get_demographics(s, demographics::to_key(ws, r)) > 0.0f : false;
4677 },
4678 to_nation(primary_slot), rel);
4679 return compare_to_true(tval[0], result);
4680}
4681TRIGGER_FUNCTION(tf_has_pop_religion_pop) {
4682 return compare_values_eq(tval[0], ws.world.pop_get_religion(to_pop(primary_slot)), payload(tval[1]).rel_id);
4683}
4684TRIGGER_FUNCTION(tf_has_pop_religion_state) {
4685 return compare_to_true(tval[0],
4686 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, payload(tval[1]).rel_id)) > 0.0f);
4687}
4688TRIGGER_FUNCTION(tf_has_pop_religion_province) {
4689 return compare_to_true(tval[0],
4690 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, payload(tval[1]).rel_id)) > 0.0f);
4691}
4692TRIGGER_FUNCTION(tf_has_pop_religion_nation) {
4693 return compare_to_true(tval[0],
4694 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, payload(tval[1]).rel_id)) > 0.0f);
4695}
4696TRIGGER_FUNCTION(tf_life_needs) {
4697 return compare_values(tval[0], pop_demographics::get_life_needs(ws, to_pop(primary_slot)),
4698 read_float_from_payload(tval + 1));
4699}
4700TRIGGER_FUNCTION(tf_everyday_needs) {
4701 return compare_values(tval[0], pop_demographics::get_everyday_needs(ws, to_pop(primary_slot)),
4702 read_float_from_payload(tval + 1));
4703}
4704TRIGGER_FUNCTION(tf_luxury_needs) {
4705 return compare_values(tval[0], pop_demographics::get_luxury_needs(ws, to_pop(primary_slot)),
4706 read_float_from_payload(tval + 1));
4707}
4708TRIGGER_FUNCTION(tf_consciousness_pop) {
4709 return compare_values(tval[0], pop_demographics::get_consciousness(ws, to_pop(primary_slot)), read_float_from_payload(tval + 1));
4710}
4711TRIGGER_FUNCTION(tf_consciousness_province) {
4712 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4713 return compare_values(tval[0],
4714 ve::select(total_pop != 0.0f,
4715 ws.world.province_get_demographics(to_prov(primary_slot), demographics::consciousness) / total_pop, 0.0f),
4716 read_float_from_payload(tval + 1));
4717}
4718TRIGGER_FUNCTION(tf_consciousness_state) {
4719 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4720 return compare_values(tval[0],
4721 ve::select(total_pop != 0.0f,
4722 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::consciousness) / total_pop, 0.0f),
4723 read_float_from_payload(tval + 1));
4724}
4725TRIGGER_FUNCTION(tf_consciousness_nation) {
4726 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4727 return compare_values(tval[0],
4728 ve::select(total_pop != 0.0f,
4729 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::consciousness) / total_pop, 0.0f),
4730 read_float_from_payload(tval + 1));
4731}
4732TRIGGER_FUNCTION(tf_literacy_pop) {
4733 return compare_values(tval[0], pop_demographics::get_literacy(ws, to_pop(primary_slot)), read_float_from_payload(tval + 1));
4734}
4735TRIGGER_FUNCTION(tf_literacy_province) {
4736 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4737 return compare_values(tval[0],
4738 ve::select(total_pop != 0.0f, ws.world.province_get_demographics(to_prov(primary_slot), demographics::literacy) / total_pop,
4739 0.0f),
4740 read_float_from_payload(tval + 1));
4741}
4742TRIGGER_FUNCTION(tf_literacy_state) {
4743 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4744 return compare_values(tval[0],
4745 ve::select(total_pop != 0.0f,
4746 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::literacy) / total_pop, 0.0f),
4747 read_float_from_payload(tval + 1));
4748}
4749TRIGGER_FUNCTION(tf_literacy_nation) {
4750 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4751 return compare_values(tval[0],
4752 ve::select(total_pop != 0.0f, ws.world.nation_get_demographics(to_nation(primary_slot), demographics::literacy) / total_pop,
4753 0.0f),
4754 read_float_from_payload(tval + 1));
4755}
4756TRIGGER_FUNCTION(tf_militancy_pop) {
4757 return compare_values(tval[0],pop_demographics::get_militancy(ws, to_pop(primary_slot)), read_float_from_payload(tval + 1));
4758}
4759TRIGGER_FUNCTION(tf_militancy_province) {
4760 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
4761 return compare_values(tval[0],
4762 ve::select(total_pop != 0.0f,
4763 ws.world.province_get_demographics(to_prov(primary_slot), demographics::militancy) / total_pop, 0.0f),
4764 read_float_from_payload(tval + 1));
4765}
4766TRIGGER_FUNCTION(tf_militancy_state) {
4767 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
4768 return compare_values(tval[0],
4769 ve::select(total_pop != 0.0f,
4770 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::militancy) / total_pop, 0.0f),
4771 read_float_from_payload(tval + 1));
4772}
4773TRIGGER_FUNCTION(tf_militancy_nation) {
4774 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
4775 return compare_values(tval[0],
4776 ve::select(total_pop != 0.0f,
4777 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::militancy) / total_pop, 0.0f),
4778 read_float_from_payload(tval + 1));
4779}
4780TRIGGER_FUNCTION(tf_trade_goods_in_state_state) {
4781 auto g = payload(tval[1]).com_id;
4782 auto sdef = ws.world.state_instance_get_definition(to_state(primary_slot));
4783 auto sowner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
4784 auto result = ve::apply(
4785 [&ws, g](dcon::state_definition_id sd, dcon::nation_id o) {
4786 for(auto p : ws.world.state_definition_get_abstract_state_membership(sd)) {
4787 if(p.get_province().get_nation_from_province_ownership() == o) {
4788 if(p.get_province().get_rgo() == g)
4789 return true;
4790 }
4791 }
4792 return false;
4793 },
4794 sdef, sowner);
4795 return compare_to_true(tval[0], result);
4796}
4797TRIGGER_FUNCTION(tf_trade_goods_in_state_province) {
4798 auto g = payload(tval[1]).com_id;
4799 auto si = ws.world.province_get_state_membership(to_prov(primary_slot));
4800 auto sdef = ws.world.state_instance_get_definition(si);
4801 auto sowner = ws.world.state_instance_get_nation_from_state_ownership(si);
4802 auto result = ve::apply(
4803 [&ws, g](dcon::state_definition_id sd, dcon::nation_id o) {
4804 for(auto p : ws.world.state_definition_get_abstract_state_membership(sd)) {
4805 if(p.get_province().get_nation_from_province_ownership() == o) {
4806 if(p.get_province().get_rgo() == g)
4807 return true;
4808 }
4809 }
4810 return false;
4811 },
4812 sdef, sowner);
4813 return compare_to_true(tval[0], result);
4814}
4815TRIGGER_FUNCTION(tf_has_flashpoint) {
4816 return compare_to_true(tval[0],
4817 ws.world.state_instance_get_flashpoint_tag(to_state(primary_slot)) != dcon::national_identity_id());
4818}
4819TRIGGER_FUNCTION(tf_flashpoint_tension) {
4820 return compare_values(tval[0], ws.world.state_instance_get_flashpoint_tension(to_state(primary_slot)),
4821 read_float_from_payload(tval + 1));
4822}
4823TRIGGER_FUNCTION(tf_flashpoint_tension_province) {
4824 return compare_values(tval[0], ws.world.state_instance_get_flashpoint_tension(ws.world.province_get_state_membership(to_prov(primary_slot))),
4825 read_float_from_payload(tval + 1));
4826}
4827TRIGGER_FUNCTION(tf_crisis_exist) {
4828 return compare_to_true(tval[0], ws.current_crisis_state != sys::crisis_state::inactive);
4829}
4830TRIGGER_FUNCTION(tf_is_liberation_crisis) {
4831
4832 auto first_wg = ws.crisis_attacker_wargoals.at(0);
4833 return compare_to_true(tval[0], first_wg.cb == ws.military_definitions.crisis_liberate);
4834}
4835TRIGGER_FUNCTION(tf_is_claim_crisis) {
4836 assert(false && "Claim crisis is not part of PA");
4837 return compare_to_true(tval[0], false);
4838}
4839TRIGGER_FUNCTION(tf_crisis_temperature) {
4840 return compare_values(tval[0], ws.crisis_temperature, read_float_from_payload(tval + 1));
4841}
4842TRIGGER_FUNCTION(tf_involved_in_crisis_nation) {
4843 auto result = ve::apply(
4844 [&ws](dcon::nation_id n) {
4845 auto sz = ws.crisis_participants.size();
4846 for(uint32_t i = 0; i < sz; ++i) {
4847 if(!ws.crisis_participants[i].id)
4848 return false;
4849 if(ws.crisis_participants[i].id == n)
4850 return true;
4851 }
4852 return false;
4853 },
4854 to_nation(primary_slot));
4855 return compare_to_true(tval[0], result);
4856}
4857TRIGGER_FUNCTION(tf_involved_in_crisis_pop) {
4858 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
4859 auto result = ve::apply(
4860 [&ws](dcon::nation_id n) {
4861 auto sz = ws.crisis_participants.size();
4862 for(uint32_t i = 0; i < sz; ++i) {
4863 if(!ws.crisis_participants[i].id)
4864 return false;
4865 if(ws.crisis_participants[i].id == n)
4866 return true;
4867 }
4868 return false;
4869 },
4870 owner);
4871 return compare_to_true(tval[0], result);
4872}
4873TRIGGER_FUNCTION(tf_rich_strata_life_needs_nation) {
4874 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4875 return compare_values(tval[0],
4876 ve::select(accumulator > 0.0f,
4877 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_life_needs) / accumulator, 0.0f),
4878 read_float_from_payload(tval + 1));
4879}
4880TRIGGER_FUNCTION(tf_rich_strata_life_needs_state) {
4881 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4882 return compare_values(tval[0],
4883 ve::select(accumulator > 0.0f,
4884 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_life_needs) / accumulator, 0.0f),
4885 read_float_from_payload(tval + 1));
4886}
4887TRIGGER_FUNCTION(tf_rich_strata_life_needs_province) {
4888 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4889 return compare_values(tval[0],
4890 ve::select(accumulator > 0.0f,
4891 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_life_needs) / accumulator, 0.0f),
4892 read_float_from_payload(tval + 1));
4893}
4894TRIGGER_FUNCTION(tf_rich_strata_life_needs_pop) {
4895 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4896 auto si = ws.world.province_get_state_membership(location);
4897 return tf_rich_strata_life_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4898}
4899TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_nation) {
4900 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4901 return compare_values(tval[0],
4902 ve::select(accumulator > 0.0f,
4903 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_everyday_needs) / accumulator, 0.0f),
4904 read_float_from_payload(tval + 1));
4905}
4906TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_state) {
4907 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4908 return compare_values(tval[0],
4909 ve::select(accumulator > 0.0f,
4910 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_everyday_needs) / accumulator,
4911 0.0f),
4912 read_float_from_payload(tval + 1));
4913}
4914TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_province) {
4915 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4916 return compare_values(tval[0],
4917 ve::select(accumulator > 0.0f,
4918 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_everyday_needs) / accumulator, 0.0f),
4919 read_float_from_payload(tval + 1));
4920}
4921TRIGGER_FUNCTION(tf_rich_strata_everyday_needs_pop) {
4922 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4923 auto si = ws.world.province_get_state_membership(location);
4924 return tf_rich_strata_everyday_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4925}
4926TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_nation) {
4927 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_total);
4928 return compare_values(tval[0],
4929 ve::select(accumulator > 0.0f,
4930 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::rich_luxury_needs) / accumulator, 0.0f),
4931 read_float_from_payload(tval + 1));
4932}
4933TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_state) {
4934 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_total);
4935 return compare_values(tval[0],
4936 ve::select(accumulator > 0.0f,
4937 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::rich_luxury_needs) / accumulator, 0.0f),
4938 read_float_from_payload(tval + 1));
4939}
4940TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_province) {
4941 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_total);
4942 return compare_values(tval[0],
4943 ve::select(accumulator > 0.0f,
4944 ws.world.province_get_demographics(to_prov(primary_slot), demographics::rich_luxury_needs) / accumulator, 0.0f),
4945 read_float_from_payload(tval + 1));
4946}
4947TRIGGER_FUNCTION(tf_rich_strata_luxury_needs_pop) {
4948 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4949 auto si = ws.world.province_get_state_membership(location);
4950 return tf_rich_strata_luxury_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4951}
4952TRIGGER_FUNCTION(tf_middle_strata_life_needs_nation) {
4953 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4954 return compare_values(tval[0],
4955 ve::select(accumulator > 0.0f,
4956 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_life_needs) / accumulator, 0.0f),
4957 read_float_from_payload(tval + 1));
4958}
4959TRIGGER_FUNCTION(tf_middle_strata_life_needs_state) {
4960 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4961 return compare_values(tval[0],
4962 ve::select(accumulator > 0.0f,
4963 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_life_needs) / accumulator, 0.0f),
4964 read_float_from_payload(tval + 1));
4965}
4966TRIGGER_FUNCTION(tf_middle_strata_life_needs_province) {
4967 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4968 return compare_values(tval[0],
4969 ve::select(accumulator > 0.0f,
4970 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_life_needs) / accumulator, 0.0f),
4971 read_float_from_payload(tval + 1));
4972}
4973TRIGGER_FUNCTION(tf_middle_strata_life_needs_pop) {
4974 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
4975 auto si = ws.world.province_get_state_membership(location);
4976 return tf_middle_strata_life_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
4977}
4978TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_nation) {
4979 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
4980 return compare_values(tval[0],
4981 ve::select(accumulator > 0.0f,
4982 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_everyday_needs) / accumulator, 0.0f),
4983 read_float_from_payload(tval + 1));
4984}
4985TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_state) {
4986 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
4987 return compare_values(tval[0],
4988 ve::select(accumulator > 0.0f,
4989 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_everyday_needs) / accumulator,
4990 0.0f),
4991 read_float_from_payload(tval + 1));
4992}
4993TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_province) {
4994 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
4995 return compare_values(tval[0],
4996 ve::select(accumulator > 0.0f,
4997 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_everyday_needs) / accumulator, 0.0f),
4998 read_float_from_payload(tval + 1));
4999}
5000TRIGGER_FUNCTION(tf_middle_strata_everyday_needs_pop) {
5001 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5002 auto si = ws.world.province_get_state_membership(location);
5003 return tf_middle_strata_everyday_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5004}
5005TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_nation) {
5006 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_total);
5007 return compare_values(tval[0],
5008 ve::select(accumulator > 0.0f,
5009 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::middle_luxury_needs) / accumulator, 0.0f),
5010 read_float_from_payload(tval + 1));
5011}
5012TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_state) {
5013 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_total);
5014 return compare_values(tval[0],
5015 ve::select(accumulator > 0.0f,
5016 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::middle_luxury_needs) / accumulator,
5017 0.0f),
5018 read_float_from_payload(tval + 1));
5019}
5020TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_province) {
5021 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_total);
5022 return compare_values(tval[0],
5023 ve::select(accumulator > 0.0f,
5024 ws.world.province_get_demographics(to_prov(primary_slot), demographics::middle_luxury_needs) / accumulator, 0.0f),
5025 read_float_from_payload(tval + 1));
5026}
5027TRIGGER_FUNCTION(tf_middle_strata_luxury_needs_pop) {
5028 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5029 auto si = ws.world.province_get_state_membership(location);
5030 return tf_middle_strata_luxury_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5031}
5032TRIGGER_FUNCTION(tf_poor_strata_life_needs_nation) {
5033 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
5034 return compare_values(tval[0],
5035 ve::select(accumulator > 0.0f,
5036 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_life_needs) / accumulator, 0.0f),
5037 read_float_from_payload(tval + 1));
5038}
5039TRIGGER_FUNCTION(tf_poor_strata_life_needs_state) {
5040 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
5041 return compare_values(tval[0],
5042 ve::select(accumulator > 0.0f,
5043 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_life_needs) / accumulator, 0.0f),
5044 read_float_from_payload(tval + 1));
5045}
5046TRIGGER_FUNCTION(tf_poor_strata_life_needs_province) {
5047 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
5048 return compare_values(tval[0],
5049 ve::select(accumulator > 0.0f,
5050 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_life_needs) / accumulator, 0.0f),
5051 read_float_from_payload(tval + 1));
5052}
5053TRIGGER_FUNCTION(tf_poor_strata_life_needs_pop) {
5054 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5055 auto si = ws.world.province_get_state_membership(location);
5056 return tf_poor_strata_life_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5057}
5058TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_nation) {
5059 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
5060 return compare_values(tval[0],
5061 ve::select(accumulator > 0.0f,
5062 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_everyday_needs) / accumulator, 0.0f),
5063 read_float_from_payload(tval + 1));
5064}
5065TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_state) {
5066 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
5067 return compare_values(tval[0],
5068 ve::select(accumulator > 0.0f,
5069 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_everyday_needs) / accumulator,
5070 0.0f),
5071 read_float_from_payload(tval + 1));
5072}
5073TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_province) {
5074 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
5075 return compare_values(tval[0],
5076 ve::select(accumulator > 0.0f,
5077 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_everyday_needs) / accumulator, 0.0f),
5078 read_float_from_payload(tval + 1));
5079}
5080TRIGGER_FUNCTION(tf_poor_strata_everyday_needs_pop) {
5081 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5082 auto si = ws.world.province_get_state_membership(location);
5083 return tf_poor_strata_everyday_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5084}
5085TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_nation) {
5086 auto accumulator = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_total);
5087 return compare_values(tval[0],
5088 ve::select(accumulator > 0.0f,
5089 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::poor_luxury_needs) / accumulator, 0.0f),
5090 read_float_from_payload(tval + 1));
5091}
5092TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_state) {
5093 auto accumulator = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_total);
5094 return compare_values(tval[0],
5095 ve::select(accumulator > 0.0f,
5096 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::poor_luxury_needs) / accumulator, 0.0f),
5097 read_float_from_payload(tval + 1));
5098}
5099TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_province) {
5100 auto accumulator = ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_total);
5101 return compare_values(tval[0],
5102 ve::select(accumulator > 0.0f,
5103 ws.world.province_get_demographics(to_prov(primary_slot), demographics::poor_luxury_needs) / accumulator, 0.0f),
5104 read_float_from_payload(tval + 1));
5105}
5106TRIGGER_FUNCTION(tf_poor_strata_luxury_needs_pop) {
5107 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5108 auto si = ws.world.province_get_state_membership(location);
5109 return tf_poor_strata_luxury_needs_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5110}
5111TRIGGER_FUNCTION(tf_diplomatic_influence_tag) {
5112 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[2]).tag_id);
5113 auto result = ve::apply(
5114 [&ws, holder](dcon::nation_id a) {
5115 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(holder, a);
5116 return ws.world.gp_relationship_get_influence(gpr);
5117 },
5118 to_nation(primary_slot));
5119 return compare_values(tval[0], result, float(tval[1]));
5120}
5121TRIGGER_FUNCTION(tf_diplomatic_influence_this_nation) {
5122 auto result = ve::apply(
5123 [&ws](dcon::nation_id a, dcon::nation_id b) {
5124 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5125 return ws.world.gp_relationship_get_influence(gpr);
5126 },
5127 to_nation(primary_slot), to_nation(this_slot));
5128 return compare_values(tval[0], result, float(tval[1]));
5129}
5130TRIGGER_FUNCTION(tf_diplomatic_influence_this_province) {
5131 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5132 auto result = ve::apply(
5133 [&ws](dcon::nation_id a, dcon::nation_id b) {
5134 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5135 return ws.world.gp_relationship_get_influence(gpr);
5136 },
5137 to_nation(primary_slot), owner);
5138 return compare_values(tval[0], result, float(tval[1]));
5139}
5140TRIGGER_FUNCTION(tf_diplomatic_influence_from_nation) {
5141 auto result = ve::apply(
5142 [&ws](dcon::nation_id a, dcon::nation_id b) {
5143 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5144 return ws.world.gp_relationship_get_influence(gpr);
5145 },
5146 to_nation(primary_slot), to_nation(from_slot));
5147 return compare_values(tval[0], result, float(tval[1]));
5148}
5149TRIGGER_FUNCTION(tf_diplomatic_influence_from_province) {
5150 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
5151 auto result = ve::apply(
5152 [&ws](dcon::nation_id a, dcon::nation_id b) {
5153 auto gpr = ws.world.get_gp_relationship_by_gp_influence_pair(b, a);
5154 return ws.world.gp_relationship_get_influence(gpr);
5155 },
5156 to_nation(primary_slot), owner);
5157 return compare_values(tval[0], result, float(tval[1]));
5158}
5159TRIGGER_FUNCTION(tf_pop_unemployment_nation) {
5160 auto type = payload(tval[3]).popt_id;
5161 auto pop_size = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type));
5162 auto employment = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_employment_key(ws, type));
5163 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5164 read_float_from_payload(tval + 1));
5165}
5166TRIGGER_FUNCTION(tf_pop_unemployment_state) {
5167 auto type = payload(tval[3]).popt_id;
5168 auto pop_size = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type));
5169 auto employment = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_employment_key(ws, type));
5170 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5171 read_float_from_payload(tval + 1));
5172}
5173TRIGGER_FUNCTION(tf_pop_unemployment_province) {
5174 auto type = payload(tval[3]).popt_id;
5175 auto pop_size = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type));
5176 auto employment = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_employment_key(ws, type));
5177 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5178 read_float_from_payload(tval + 1));
5179}
5180TRIGGER_FUNCTION(tf_pop_unemployment_pop) {
5181 auto pop_size = ws.world.pop_get_size(to_pop(primary_slot));
5182 auto employment = pop_demographics::get_raw_employment(ws, to_pop(primary_slot));
5183 return compare_values(tval[0], 1.0f - employment, read_float_from_payload(tval + 1));
5184}
5185TRIGGER_FUNCTION(tf_pop_unemployment_nation_this_pop) {
5186 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5187
5188 auto pop_size = ve::apply(
5189 [&](dcon::nation_id loc, dcon::pop_type_id t) {
5190 if(t)
5191 return ws.world.nation_get_demographics(loc, demographics::to_key(ws, t));
5192 else
5193 return 0.0f;
5194 },
5195 to_nation(primary_slot), type);
5196
5197 auto employment = ve::apply(
5198 [&](dcon::nation_id loc, dcon::pop_type_id t) {
5199 if(t)
5200 return ws.world.nation_get_demographics(loc, demographics::to_employment_key(ws, t));
5201 else
5202 return 0.0f;
5203 },
5204 to_nation(primary_slot), type);
5205
5206 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5207 read_float_from_payload(tval + 1));
5208}
5209TRIGGER_FUNCTION(tf_pop_unemployment_state_this_pop) {
5210 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5211
5212 auto pop_size = ve::apply(
5213 [&](dcon::state_instance_id loc, dcon::pop_type_id t) {
5214 if(t)
5215 return ws.world.state_instance_get_demographics(loc, demographics::to_key(ws, t));
5216 else
5217 return 0.0f;
5218 },
5219 to_state(primary_slot), type);
5220
5221 auto employment = ve::apply(
5222 [&](dcon::state_instance_id loc, dcon::pop_type_id t) {
5223 if(t)
5224 return ws.world.state_instance_get_demographics(loc, demographics::to_employment_key(ws, t));
5225 else
5226 return 0.0f;
5227 },
5228 to_state(primary_slot), type);
5229
5230 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5231 read_float_from_payload(tval + 1));
5232}
5233TRIGGER_FUNCTION(tf_pop_unemployment_province_this_pop) {
5234 auto type = ws.world.pop_get_poptype(to_pop(this_slot));
5235
5236 auto pop_size = ve::apply(
5237 [&](dcon::province_id loc, dcon::pop_type_id t) {
5238 if(t)
5239 return ws.world.province_get_demographics(loc, demographics::to_key(ws, t));
5240 else
5241 return 0.0f;
5242 },
5243 to_prov(primary_slot), type);
5244
5245 auto employment = ve::apply(
5246 [&](dcon::province_id loc, dcon::pop_type_id t) {
5247 if(t)
5248 return ws.world.province_get_demographics(loc, demographics::to_employment_key(ws, t));
5249 else
5250 return 0.0f;
5251 },
5252 to_prov(primary_slot), type);
5253
5254 return compare_values(tval[0], ve::select(pop_size > 0.0f, 1.0f - (employment / pop_size), 0.0f),
5255 read_float_from_payload(tval + 1));
5256}
5257TRIGGER_FUNCTION(tf_relation_tag) {
5258 auto holder = ws.world.national_identity_get_nation_from_identity_holder(payload(tval[2]).tag_id);
5259 auto relation = ve::apply(
5260 [&ws, holder](dcon::nation_id a) {
5261 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, holder);
5262 return ws.world.diplomatic_relation_get_value(rel);
5263 },
5264 to_nation(primary_slot));
5265 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5266}
5267TRIGGER_FUNCTION(tf_relation_this_nation) {
5268 auto relation = ve::apply(
5269 [&ws](dcon::nation_id a, dcon::nation_id b) {
5270 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5271 return ws.world.diplomatic_relation_get_value(rel);
5272 },
5273 to_nation(primary_slot), to_nation(this_slot));
5274 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5275}
5276TRIGGER_FUNCTION(tf_relation_this_province) {
5277 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5278 auto relation = ve::apply(
5279 [&ws](dcon::nation_id a, dcon::nation_id b) {
5280 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5281 return ws.world.diplomatic_relation_get_value(rel);
5282 },
5283 to_nation(primary_slot), owner);
5284 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5285}
5286TRIGGER_FUNCTION(tf_relation_this_pop) {
5287 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
5288 auto relation = ve::apply(
5289 [&ws](dcon::nation_id a, dcon::nation_id b) {
5290 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5291 return ws.world.diplomatic_relation_get_value(rel);
5292 },
5293 to_nation(primary_slot), owner);
5294 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5295}
5296TRIGGER_FUNCTION(tf_relation_from_nation) {
5297 auto relation = ve::apply(
5298 [&ws](dcon::nation_id a, dcon::nation_id b) {
5299 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5300 return ws.world.diplomatic_relation_get_value(rel);
5301 },
5302 to_nation(primary_slot), to_nation(from_slot));
5303 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5304}
5305TRIGGER_FUNCTION(tf_relation_from_province) {
5306 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(from_slot));
5307 auto relation = ve::apply(
5308 [&ws](dcon::nation_id a, dcon::nation_id b) {
5309 auto rel = ws.world.get_diplomatic_relation_by_diplomatic_pair(a, b);
5310 return ws.world.diplomatic_relation_get_value(rel);
5311 },
5312 to_nation(primary_slot), owner);
5313 return compare_values(tval[0], relation, float(payload(tval[1]).signed_value));
5314}
5315TRIGGER_FUNCTION(tf_check_variable) {
5316 auto id = payload(tval[3]).natv_id;
5317 return compare_values(tval[0], ws.world.nation_get_variables(to_nation(primary_slot), id), read_float_from_payload(tval + 1));
5318}
5319TRIGGER_FUNCTION(tf_upper_house) {
5320 auto id = payload(tval[3]).ideo_id;
5321 return compare_values(tval[0], ws.world.nation_get_upper_house(to_nation(primary_slot), id), 100.0f * read_float_from_payload(tval + 1));
5322}
5323TRIGGER_FUNCTION(tf_unemployment_by_type_nation) {
5324 return tf_pop_unemployment_nation<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5325}
5326TRIGGER_FUNCTION(tf_unemployment_by_type_state) {
5327 return tf_pop_unemployment_state<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5328}
5329TRIGGER_FUNCTION(tf_unemployment_by_type_province) {
5330 return tf_pop_unemployment_province<return_type>(tval, ws, primary_slot, int32_t(), int32_t());
5331}
5332TRIGGER_FUNCTION(tf_unemployment_by_type_pop) {
5333 auto location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5334 auto si = ws.world.province_get_state_membership(location);
5335 return tf_unemployment_by_type_state<return_type>(tval, ws, to_generic(si), int32_t(), int32_t());
5336}
5337TRIGGER_FUNCTION(tf_party_loyalty_nation_province_id) {
5338 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5339 payload(tval[2]).signed_value);
5340}
5341TRIGGER_FUNCTION(tf_party_loyalty_from_nation_province_id) {
5342 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5343 payload(tval[2]).signed_value);
5344}
5345TRIGGER_FUNCTION(tf_party_loyalty_province_province_id) {
5346 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5347 payload(tval[2]).signed_value);
5348}
5349TRIGGER_FUNCTION(tf_party_loyalty_from_province_province_id) {
5350 return compare_values(tval[0], ws.world.province_get_party_loyalty(payload(tval[1]).prov_id, payload(tval[3]).ideo_id),
5351 payload(tval[2]).signed_value);
5352}
5353TRIGGER_FUNCTION(tf_party_loyalty_nation_from_province) {
5354 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(from_slot), payload(tval[2]).ideo_id),
5355 payload(tval[1]).signed_value);
5356}
5357TRIGGER_FUNCTION(tf_party_loyalty_generic) {
5358 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5359 payload(tval[1]).signed_value);
5360}
5361TRIGGER_FUNCTION(tf_party_loyalty_from_nation_scope_province) {
5362 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5363 payload(tval[1]).signed_value);
5364}
5365TRIGGER_FUNCTION(tf_party_loyalty_from_province_scope_province) {
5366 return compare_values(tval[0], ws.world.province_get_party_loyalty(to_prov(primary_slot), payload(tval[2]).ideo_id),
5367 payload(tval[1]).signed_value);
5368}
5369TRIGGER_FUNCTION(tf_can_build_in_province_railroad_no_limit_from_nation) {
5370 return compare_to_true(tval[0],
5371 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5372 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5373 ve::to_float(ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::railroad))));
5374}
5375TRIGGER_FUNCTION(tf_can_build_in_province_railroad_yes_limit_from_nation) {
5376 return compare_to_true(tval[0],
5377 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5378 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5379 ve::to_float(ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::railroad))));
5380}
5381TRIGGER_FUNCTION(tf_can_build_in_province_railroad_no_limit_this_nation) {
5382 return compare_to_true(tval[0],
5383 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5384 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5385 ve::to_float(ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::railroad))));
5386}
5387TRIGGER_FUNCTION(tf_can_build_in_province_railroad_yes_limit_this_nation) {
5388 return compare_to_true(tval[0],
5389 ve::to_float(ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::railroad))) +
5390 ws.world.province_get_modifier_values(to_prov(primary_slot), sys::provincial_mod_offsets::min_build_railroad) <
5391 ve::to_float(ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::railroad))));
5392}
5393TRIGGER_FUNCTION(tf_can_build_in_province_fort_no_limit_from_nation) {
5394 return compare_to_true(tval[0],
5395 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)));
5396}
5397TRIGGER_FUNCTION(tf_can_build_in_province_fort_yes_limit_from_nation) {
5398 return compare_to_true(tval[0],
5399 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)));
5400}
5401TRIGGER_FUNCTION(tf_can_build_in_province_fort_no_limit_this_nation) {
5402 return compare_to_true(tval[0],
5403 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)));
5404}
5405TRIGGER_FUNCTION(tf_can_build_in_province_fort_yes_limit_this_nation) {
5406 return compare_to_true(tval[0],
5407 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)));
5408}
5409TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_no_limit_from_nation) {
5410 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5411 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5412 ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::naval_base))) &&
5413 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5414 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5415 ws.world.province_get_state_membership(to_prov(primary_slot))));
5416 return compare_to_true(tval[0], result);
5417}
5418TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_yes_limit_from_nation) {
5419 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5420 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5421 ws.world.nation_get_max_building_level(to_nation(from_slot), uint8_t(economy::province_building_type::naval_base))) &&
5422 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5423 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5424 ws.world.province_get_state_membership(to_prov(primary_slot))));
5425 return compare_to_true(tval[0], result);
5426}
5427TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_no_limit_this_nation) {
5428 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5429 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5430 ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::naval_base))) &&
5431 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5432 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5433 ws.world.province_get_state_membership(to_prov(primary_slot))));
5434 return compare_to_true(tval[0], result);
5435}
5436TRIGGER_FUNCTION(tf_can_build_in_province_naval_base_yes_limit_this_nation) {
5437 auto result = ws.world.province_get_is_coast(to_prov(primary_slot)) &&
5438 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) <
5439 ws.world.nation_get_max_building_level(to_nation(this_slot), uint8_t(economy::province_building_type::naval_base))) &&
5440 (ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base)) != 0 ||
5441 ve::apply([&ws](dcon::state_instance_id i) { return !(military::state_has_naval_base(ws, i)); },
5442 ws.world.province_get_state_membership(to_prov(primary_slot))));
5443 return compare_to_true(tval[0], result);
5444}
5445TRIGGER_FUNCTION(tf_can_build_railway_in_capital_yes_whole_state_yes_limit) {
5446 // stub: virtually unused
5447 return compare_to_true(tval[0], true);
5448}
5449TRIGGER_FUNCTION(tf_can_build_railway_in_capital_yes_whole_state_no_limit) {
5450 // stub: virtually unused
5451 return compare_to_true(tval[0], true);
5452}
5453TRIGGER_FUNCTION(tf_can_build_railway_in_capital_no_whole_state_yes_limit) {
5454 // stub: virtually unused
5455 return compare_to_true(tval[0], true);
5456}
5457TRIGGER_FUNCTION(tf_can_build_railway_in_capital_no_whole_state_no_limit) {
5458 // stub: virtually unused
5459 return compare_to_true(tval[0], true);
5460}
5461TRIGGER_FUNCTION(tf_can_build_fort_in_capital_yes_whole_state_yes_limit) {
5462 // stub: virtually unused
5463 return compare_to_true(tval[0], true);
5464}
5465TRIGGER_FUNCTION(tf_can_build_fort_in_capital_yes_whole_state_no_limit) {
5466 // stub: virtually unused
5467 return compare_to_true(tval[0], true);
5468}
5469TRIGGER_FUNCTION(tf_can_build_fort_in_capital_no_whole_state_yes_limit) {
5470 // stub: virtually unused
5471 return compare_to_true(tval[0], true);
5472}
5473TRIGGER_FUNCTION(tf_can_build_fort_in_capital_no_whole_state_no_limit) {
5474 // stub: virtually unused
5475 return compare_to_true(tval[0], true);
5476}
5477TRIGGER_FUNCTION(tf_work_available_nation) {
5478 auto type = payload(tval[1]).popt_id;
5479 auto result = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_employment_key(ws, type)) >=
5480 ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, type));
5481 return compare_to_true(tval[0], result);
5482}
5483TRIGGER_FUNCTION(tf_work_available_state) {
5484 auto type = payload(tval[1]).popt_id;
5485 auto result = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_employment_key(ws, type)) >=
5486 ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, type));
5487 return compare_to_true(tval[0], result);
5488}
5489TRIGGER_FUNCTION(tf_work_available_province) {
5490 auto type = payload(tval[1]).popt_id;
5491 auto result = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_employment_key(ws, type)) >=
5492 ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, type));
5493 return compare_to_true(tval[0], result);
5494}
5495TRIGGER_FUNCTION(tf_variable_ideology_name_nation) {
5496 auto id = payload(tval[1]).ideo_id;
5497 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5498 auto support_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, id));
5499 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5500}
5501TRIGGER_FUNCTION(tf_variable_ideology_name_state) {
5502 auto id = payload(tval[1]).ideo_id;
5503 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5504 auto support_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, id));
5505 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5506}
5507TRIGGER_FUNCTION(tf_variable_ideology_name_province) {
5508 auto id = payload(tval[1]).ideo_id;
5509 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5510 auto support_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, id));
5511 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5512}
5513TRIGGER_FUNCTION(tf_variable_ideology_name_pop) {
5514 auto id = payload(tval[1]).ideo_id;
5515 auto support_pop = pop_demographics::get_demo(ws, to_pop(primary_slot), pop_demographics::to_key(ws, id));
5516 return compare_values(tval[0], support_pop, read_float_from_payload(tval + 2));
5517}
5518TRIGGER_FUNCTION(tf_variable_issue_name_nation) {
5519 auto id = payload(tval[1]).opt_id;
5520 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5521 auto support_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::to_key(ws, id));
5522 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5523}
5524TRIGGER_FUNCTION(tf_variable_issue_name_state) {
5525 auto id = payload(tval[1]).opt_id;
5526 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5527 auto support_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::to_key(ws, id));
5528 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5529}
5530TRIGGER_FUNCTION(tf_variable_issue_name_province) {
5531 auto id = payload(tval[1]).opt_id;
5532 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5533 auto support_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::to_key(ws, id));
5534 return compare_values(tval[0], ve::select(total_pop > 0.0f, support_pop / total_pop, 0.0f), read_float_from_payload(tval + 2));
5535}
5536TRIGGER_FUNCTION(tf_variable_issue_name_pop) {
5537 auto id = payload(tval[1]).opt_id;
5538 auto support_pop = pop_demographics::get_demo(ws, to_pop(primary_slot), pop_demographics::to_key(ws, id));
5539 return compare_values(tval[0], support_pop, read_float_from_payload(tval + 2));
5540}
5541TRIGGER_FUNCTION(tf_variable_issue_group_name_nation) {
5542 auto option = payload(tval[2]).opt_id;
5543 auto issue = payload(tval[1]).iss_id;
5544 ;
5545 return compare_values_eq(tval[0], ws.world.nation_get_issues(to_nation(primary_slot), issue), option);
5546}
5547TRIGGER_FUNCTION(tf_variable_issue_group_name_state) {
5548 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
5549 auto option = payload(tval[2]).opt_id;
5550 auto issue = payload(tval[1]).iss_id;
5551 ;
5552 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5553}
5554TRIGGER_FUNCTION(tf_variable_issue_group_name_province) {
5555 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
5556 auto option = payload(tval[2]).opt_id;
5557 auto issue = payload(tval[1]).iss_id;
5558 ;
5559 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5560}
5561TRIGGER_FUNCTION(tf_variable_issue_group_name_pop) {
5562 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
5563 auto option = payload(tval[2]).opt_id;
5564 auto issue = payload(tval[1]).iss_id;
5565 ;
5566 return compare_values_eq(tval[0], ws.world.nation_get_issues(owner, issue), option);
5567}
5568TRIGGER_FUNCTION(tf_variable_reform_group_name_nation) {
5569 auto option = payload(tval[2]).ropt_id;
5570 auto issue = payload(tval[1]).ref_id;
5571 ;
5572 return compare_values_eq(tval[0], ws.world.nation_get_reforms(to_nation(primary_slot), issue), option);
5573}
5574TRIGGER_FUNCTION(tf_variable_reform_group_name_state) {
5575 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(primary_slot));
5576 auto option = payload(tval[2]).ropt_id;
5577 auto issue = payload(tval[1]).ref_id;
5578 ;
5579 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5580}
5581TRIGGER_FUNCTION(tf_variable_reform_group_name_province) {
5582 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(primary_slot));
5583 auto option = payload(tval[2]).ropt_id;
5584 auto issue = payload(tval[1]).ref_id;
5585 ;
5586 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5587}
5588TRIGGER_FUNCTION(tf_variable_reform_group_name_pop) {
5589 auto owner = nations::owner_of_pop(ws, to_pop(primary_slot));
5590 auto option = payload(tval[2]).ropt_id;
5591 auto issue = payload(tval[1]).ref_id;
5592 ;
5593 return compare_values_eq(tval[0], ws.world.nation_get_reforms(owner, issue), option);
5594}
5595TRIGGER_FUNCTION(tf_variable_pop_type_name_nation) {
5596 auto total_pop = ws.world.nation_get_demographics(to_nation(primary_slot), demographics::total);
5597 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5598 auto size = ws.world.nation_get_demographics(to_nation(primary_slot), type);
5599 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5600}
5601TRIGGER_FUNCTION(tf_variable_pop_type_name_state) {
5602 auto total_pop = ws.world.state_instance_get_demographics(to_state(primary_slot), demographics::total);
5603 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5604 auto size = ws.world.state_instance_get_demographics(to_state(primary_slot), type);
5605 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5606}
5607TRIGGER_FUNCTION(tf_variable_pop_type_name_province) {
5608 auto total_pop = ws.world.province_get_demographics(to_prov(primary_slot), demographics::total);
5609 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5610 auto size = ws.world.province_get_demographics(to_prov(primary_slot), type);
5611 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5612}
5613TRIGGER_FUNCTION(tf_variable_pop_type_name_pop) {
5614 auto pop_location = ws.world.pop_get_province_from_pop_location(to_pop(primary_slot));
5615 auto total_pop = ws.world.province_get_demographics(pop_location, demographics::total);
5616 auto type = demographics::to_key(ws, payload(tval[1]).popt_id);
5617 auto size = ws.world.province_get_demographics(pop_location, type);
5618 return compare_values(tval[0], ve::select(total_pop > 0.0f, size / total_pop, 0.0f), read_float_from_payload(tval + 2));
5619}
5620TRIGGER_FUNCTION(tf_variable_good_name) {
5621 auto good = payload(tval[1]).com_id;
5622 auto amount = ws.world.nation_get_stockpiles(to_nation(primary_slot), good);
5623 return compare_values(tval[0], amount, read_float_from_payload(tval + 2));
5624}
5625TRIGGER_FUNCTION(tf_religion_nation) {
5626 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), payload(tval[1]).rel_id);
5627}
5628TRIGGER_FUNCTION(tf_religion_nation_reb) {
5629 auto r = ws.world.rebel_faction_get_religion(to_rebel(from_slot));
5630 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), r);
5631}
5632TRIGGER_FUNCTION(tf_religion_nation_from_nation) {
5633 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)),
5634 ws.world.nation_get_religion(to_nation(from_slot)));
5635}
5636TRIGGER_FUNCTION(tf_religion_nation_this_nation) {
5637 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)),
5638 ws.world.nation_get_religion(to_nation(this_slot)));
5639}
5640TRIGGER_FUNCTION(tf_religion_nation_this_state) {
5641 auto owner = ws.world.state_instance_get_nation_from_state_ownership(to_state(this_slot));
5642 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5643}
5644TRIGGER_FUNCTION(tf_religion_nation_this_province) {
5645 auto owner = ws.world.province_get_nation_from_province_ownership(to_prov(this_slot));
5646 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5647}
5648TRIGGER_FUNCTION(tf_religion_nation_this_pop) {
5649 auto owner = nations::owner_of_pop(ws, to_pop(this_slot));
5650 return compare_values_eq(tval[0], ws.world.nation_get_religion(to_nation(primary_slot)), ws.world.nation_get_religion(owner));
5651}
5652TRIGGER_FUNCTION(tf_invention) {
5653 auto tid = trigger::payload(tval[1]).invt_id;
5654 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(to_nation(primary_slot), tid));
5655}
5656TRIGGER_FUNCTION(tf_invention_province) {
5657 auto tid = trigger::payload(tval[1]).invt_id;
5658 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));
5659}
5660TRIGGER_FUNCTION(tf_invention_pop) {
5661 auto tid = trigger::payload(tval[1]).invt_id;
5662 return compare_to_true(tval[0], ws.world.nation_get_active_inventions(nations::owner_of_pop(ws, to_pop(primary_slot)), tid));
5663}
5665 auto sid = trigger::payload(tval[1]).str_id;
5666 auto tid = ws.world.stored_trigger_get_function(sid);
5667 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);
5668 return compare_to_true(tval[0], test_result);
5669}
5670
5671TRIGGER_FUNCTION(tf_has_building_bank) {
5672 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::bank)) != 0);
5673}
5674TRIGGER_FUNCTION(tf_has_building_university) {
5675 return compare_to_true(tval[0], ws.world.province_get_building_level(to_prov(primary_slot), uint8_t(economy::province_building_type::university)) != 0);
5676}
5677
5678TRIGGER_FUNCTION(tf_party_name) {
5679 auto ideo = trigger::payload(tval[1]).ideo_id;
5680 dcon::text_key new_name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 2)) };
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_name](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_name(pid) == new_name;
5694 }
5695 }
5696 return false;
5697
5698 }, holder, nat));
5699
5700 } else {
5701 auto n = trigger::to_nation(primary_slot);
5702 auto rp = ws.world.nation_get_ruling_party(n);
5703 return compare_to_true(tval[0], ws.world.political_party_get_name(rp) == new_name);
5704 }
5705}
5706
5707TRIGGER_FUNCTION(tf_party_position) {
5708 auto ideo = trigger::payload(tval[1]).ideo_id;
5709 dcon::issue_option_id new_opt = trigger::payload(tval[2]).opt_id;
5710 auto popt = ws.world.issue_option_get_parent_issue(new_opt);
5711
5712 if(ideo) {
5713 auto nat = trigger::to_nation(primary_slot);
5714 auto holder = ws.world.nation_get_identity_from_identity_holder(nat);
5715
5716 return compare_to_true(tval[0], ve::apply([&ws, ideo, new_opt, popt](dcon::national_identity_id h, dcon::nation_id n) {
5717 auto start = ws.world.national_identity_get_political_party_first(h).id.index();
5718 auto end = start + ws.world.national_identity_get_political_party_count(h);
5719
5720 for(int32_t i = start; i < end; i++) {
5721 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5722 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5723 return ws.world.political_party_get_party_issues(pid, popt) == new_opt;
5724 }
5725 }
5726 return false;
5727
5728 }, holder, nat));
5729 } else {
5730 auto n = trigger::to_nation(primary_slot);
5731 auto rp = ws.world.nation_get_ruling_party(n);
5732 return compare_to_true(tval[0], ws.world.political_party_get_party_issues(rp, popt) == new_opt);
5733 }
5734}
5735
5736template<typename return_type, typename primary_type, typename this_type, typename from_type>
5738 constexpr static return_type(
5739 CALLTYPE* trigger_functions[])(uint16_t const*, sys::state&, primary_type, this_type, from_type) = {
5740 tf_none<return_type, primary_type, this_type, from_type>,
5741#define TRIGGER_BYTECODE_ELEMENT(code, name, arg) tf_##name <return_type, primary_type, this_type, from_type>,
5743#undef TRIGGER_BYTECODE_ELEMENT
5744 //
5745 // scopes
5746 //
5747 tf_generic_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t generic_scope = 0x0000; // or & and
5748 tf_x_neighbor_province_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_province_scope = 0x0001;
5749 tf_x_neighbor_country_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_country_scope_nation = 0x0002;
5750 tf_x_neighbor_country_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_neighbor_country_scope_pop = 0x0003;
5751 tf_x_war_countries_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_war_countries_scope_nation = 0x0004;
5752 tf_x_war_countries_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_war_countries_scope_pop = 0x0005;
5753 tf_x_greater_power_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_greater_power_scope = 0x0006;
5754 tf_x_owned_province_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_owned_province_scope_state = 0x0007;
5755 tf_x_owned_province_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_owned_province_scope_nation = 0x0008;
5756 tf_x_core_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_core_scope_province = 0x0009;
5757 tf_x_core_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_core_scope_nation = 0x000A;
5758 tf_x_state_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_state_scope = 0x000B;
5759 tf_x_substate_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_substate_scope = 0x000C;
5760 tf_x_sphere_member_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_sphere_member_scope = 0x000D;
5761 tf_x_pop_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_province = 0x000E;
5762 tf_x_pop_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_state = 0x000F;
5763 tf_x_pop_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t x_pop_scope_nation = 0x0010;
5764 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
5765 tf_owner_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t owner_scope_state = 0x0012;
5766 tf_owner_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t owner_scope_province = 0x0013;
5767 tf_controller_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t controller_scope = 0x0014;
5768 tf_location_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t location_scope = 0x0015;
5769 tf_country_scope_state<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_state = 0x0016;
5770 tf_country_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_pop = 0x0017;
5771 tf_capital_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t capital_scope = 0x0018;
5772 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_pop = 0x0019;
5773 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_nation = 0x001A;
5774 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_state = 0x001B;
5775 tf_this_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t this_scope_province = 0x001C;
5776 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_pop = 0x001D;
5777 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_nation = 0x001E;
5778 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_state = 0x001F;
5779 tf_from_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t from_scope_province = 0x0020;
5780 tf_sea_zone_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t sea_zone_scope = 0x0021;
5781 tf_cultural_union_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t cultural_union_scope = 0x0022;
5782 tf_overlord_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t overlord_scope = 0x0023;
5783 tf_sphere_owner_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t sphere_owner_scope = 0x0024;
5784 tf_independence_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t independence_scope = 0x0025;
5785 tf_flashpoint_tag_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t flashpoint_tag_scope = 0x0026;
5786 tf_crisis_state_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t crisis_state_scope = 0x0027;
5787 tf_state_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t state_scope_pop = 0x0028;
5788 tf_state_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t state_scope_province = 0x0029;
5789 tf_tag_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t tag_scope = 0x002A; // variable name
5790 tf_integer_scope<return_type, primary_type, this_type, from_type>, // constexpr uint16_t integer_scope = 0x002B; // variable name
5791 tf_country_scope_nation<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_nation = 0x002C;
5792 tf_country_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t country_scope_province = 0x002D;
5793 tf_cultural_union_scope_pop<return_type, primary_type, this_type, from_type>, // constexpr uint16_t cultural_union_scope_pop = 0x002E;
5794 tf_capital_scope_province<return_type, primary_type, this_type, from_type>, // constexpr uint16_t capital_scope_province = 0x002F;
5795 tf_capital_scope_pop, //constexpr inline uint16_t capital_scope_pop = first_scope_code + 0x0030;
5796 tf_x_country_scope, //constexpr inline uint16_t x_country_scope = first_scope_code + 0x0031;
5797 tf_x_neighbor_province_scope_state, //constexpr inline uint16_t x_neighbor_province_scope_state = first_scope_code + 0x0032;
5798 tf_x_provinces_in_variable_region_proper, //constexpr inline uint16_t x_provinces_in_variable_region_proper = first_scope_code + 0x0033;
5799 };
5800};
5801
5802template<typename return_type, typename primary_type, typename this_type, typename from_type>
5803return_type CALLTYPE test_trigger_generic(uint16_t const* tval, sys::state& ws, primary_type primary_slot, this_type this_slot,
5804 from_type from_slot) {
5806 ws, primary_slot, this_slot, from_slot);
5807}
5808
5809#undef CALLTYPE
5810#undef TRIGGER_FUNCTION
5811
5812float evaluate_multiplicative_modifier(sys::state& state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot) {
5813 auto base = state.value_modifiers[modifier];
5814 float product = base.factor;
5815 for(uint32_t i = 0; i < base.segments_count && product != 0; ++i) {
5816 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5817 if(seg.condition) {
5818 if(test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary,
5819 this_slot, from_slot)) {
5820 product *= seg.factor;
5821 }
5822 }
5823 }
5824 return product;
5825}
5826float evaluate_additive_modifier(sys::state& state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot) {
5827 auto base = state.value_modifiers[modifier];
5828 float sum = base.base;
5829 for(uint32_t i = 0; i < base.segments_count; ++i) {
5830 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5831 if(seg.condition) {
5832 if(test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary,
5833 this_slot, from_slot)) {
5834 sum += seg.factor;
5835 }
5836 }
5837 }
5838 return sum * base.factor;
5839}
5840
5841ve::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) {
5842 auto base = state.value_modifiers[modifier];
5843 ve::fp_vector product = base.factor;
5844 for(uint32_t i = 0; i < base.segments_count; ++i) {
5845 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5846 if(seg.condition) {
5847 auto res = test_trigger_generic<ve::mask_vector>(
5848 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5849 product = ve::select(res, product * seg.factor, product);
5850 }
5851 }
5852 return product;
5853}
5854ve::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) {
5855 auto base = state.value_modifiers[modifier];
5856 ve::fp_vector sum = base.base;
5857 for(uint32_t i = 0; i < base.segments_count; ++i) {
5858 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5859 if(seg.condition) {
5860 auto res = test_trigger_generic<ve::mask_vector>(
5861 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5862 sum = ve::select(res, sum + seg.factor, sum);
5863 }
5864 }
5865 return sum * base.factor;
5866}
5867
5868ve::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) {
5869 auto base = state.value_modifiers[modifier];
5870 ve::fp_vector product = base.factor;
5871 for(uint32_t i = 0; i < base.segments_count; ++i) {
5872 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5873 if(seg.condition) {
5874 auto res = test_trigger_generic<ve::mask_vector>(
5875 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5876 product = ve::select(res, product * seg.factor, product);
5877 }
5878 }
5879 return product;
5880}
5881ve::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) {
5882 auto base = state.value_modifiers[modifier];
5883 ve::fp_vector sum = base.base;
5884 for(uint32_t i = 0; i < base.segments_count; ++i) {
5885 auto seg = state.value_modifier_segments[base.first_segment_offset + i];
5886 if(seg.condition) {
5887 auto res = test_trigger_generic<ve::mask_vector>(
5888 state.trigger_data.data() + state.trigger_data_indices[seg.condition.index() + 1], state, primary, this_slot, from_slot);
5889 sum = ve::select(res, sum + seg.factor, sum);
5890 }
5891 }
5892 return sum * base.factor;
5893}
5894
5895bool evaluate(sys::state& state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot) {
5896 return test_trigger_generic<bool>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state, primary,
5897 this_slot, from_slot);
5898}
5899bool evaluate(sys::state& state, uint16_t const* data, int32_t primary, int32_t this_slot, int32_t from_slot) {
5900 return test_trigger_generic<bool>(data, state, primary, this_slot, from_slot);
5901}
5902
5903ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::contiguous_tags<int32_t> primary,
5904 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5905 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5906 primary, this_slot, from_slot);
5907}
5908ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::contiguous_tags<int32_t> primary,
5909 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5910 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5911}
5912
5913ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::tagged_vector<int32_t> primary,
5914 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5915 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5916 primary, this_slot, from_slot);
5917}
5918ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::tagged_vector<int32_t> primary,
5919 ve::tagged_vector<int32_t> this_slot, int32_t from_slot) {
5920 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5921}
5922
5923ve::mask_vector evaluate(sys::state& state, dcon::trigger_key key, ve::contiguous_tags<int32_t> primary,
5924 ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5925 return test_trigger_generic<ve::mask_vector>(state.trigger_data.data() + state.trigger_data_indices[key.index() + 1], state,
5926 primary, this_slot, from_slot);
5927}
5928ve::mask_vector evaluate(sys::state& state, uint16_t const* data, ve::contiguous_tags<int32_t> primary,
5929 ve::contiguous_tags<int32_t> this_slot, int32_t from_slot) {
5930 return test_trigger_generic<ve::mask_vector>(data, state, primary, this_slot, from_slot);
5931}
5932
5933} // 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 assert(condition)
Definition: debug.h:74
#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:1166
bool is_bankrupt_debtor_to(sys::state &state, dcon::nation_id debt_holder, dcon::nation_id debtor)
Definition: economy.cpp:1180
float supply(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:206
bool has_factory(sys::state const &state, dcon::state_instance_id si)
Definition: economy.cpp:895
constexpr dcon::commodity_id money(0)
auto desired_needs_spending(sys::state const &state, T pop_indices)
Definition: economy.hpp:111
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:607
bool can_use_cb_against(sys::state &state, dcon::nation_id from, dcon::nation_id target)
Definition: military.cpp:245
bool state_has_naval_base(sys::state const &state, dcon::state_instance_id si)
Definition: military.cpp:613
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:649
bool province_is_blockaded(sys::state const &state, dcon::province_id ids)
Definition: military.cpp:572
auto battle_is_ongoing_in_province(sys::state const &state, T ids)
constexpr uint8_t level_in_sphere
Definition: nations.hpp:173
constexpr uint8_t level_mask
Definition: nations.hpp:167
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:1068
bool can_release_as_vassal(sys::state const &state, dcon::nation_id n, dcon::national_identity_id releasable)
Definition: nations.cpp:663
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:87
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:19
bool state_is_coastal(sys::state &state, dcon::state_instance_id s)
Definition: province.cpp:1666
Definition: json.hpp:5434
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:5803
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:3008
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:5826
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:5812
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
Holds important data about the game world, state, and other data regarding windowing,...
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:5739
#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