Project Alice
Loading...
Searching...
No Matches
effects.cpp
Go to the documentation of this file.
1#include "effects.hpp"
2#include "system_state.hpp"
3#include "ai.hpp"
4#include "demographics.hpp"
5#include "politics.hpp"
6#include "prng.hpp"
8#include "rebels.hpp"
9#include "triggers.hpp"
10#include "script_constants.hpp"
11#include "nations.hpp"
12#include "nations_templates.hpp"
13
14namespace effect {
15
16#define EFFECT_PARAMTERS \
17 uint16_t const *tval, sys::state &ws, int32_t primary_slot, int32_t this_slot, int32_t from_slot, uint32_t r_hi, uint32_t r_lo, bool& els
18
20
22 auto const source_size = 1 + get_effect_scope_payload_size(tval);
23 auto sub_units_start = tval + 2 + effect_scope_data_payload(tval[0]);
24
25 uint32_t i = 0;
26 while(sub_units_start < tval + source_size) {
27 i += internal_execute_effect(sub_units_start, ws, primary_slot, this_slot, from_slot, r_hi, r_lo + i, els);
28 sub_units_start += 1 + get_generic_effect_payload_size(sub_units_start);
29 }
30 return i;
31}
32
34 return apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo, els);
35}
36
38 uint32_t ret = 0;
39 els = false;
40 if((tval[0] & effect::scope_has_limit) != 0) {
41 auto limit = trigger::payload(tval[2]).tr_id;
42 if(trigger::evaluate(ws, limit, primary_slot, this_slot, from_slot)) {
43 ret = apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo, els);
44 els = true;
45 }
46 } else {
47 ret = apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo, els);
48 els = true;
49 }
50 return ret;
51}
53 uint32_t ret = 0;
54 if((tval[0] & effect::scope_has_limit) != 0) {
55 auto limit = trigger::payload(tval[2]).tr_id;
56 if(!els && trigger::evaluate(ws, limit, primary_slot, this_slot, from_slot)) {
57 ret = apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo, els);
58 els = true;
59 }
60 } else if(!els) {
61 ret = apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo, els);
62 els = true;
63 }
64 return ret;
65}
66
68 auto neighbor_range = ws.world.province_get_province_adjacency(trigger::to_prov(primary_slot));
69
70 if((tval[0] & effect::is_random_scope) != 0) {
71 std::vector<dcon::province_id> rlist;
72
73 if((tval[0] & effect::scope_has_limit) != 0) {
74 auto limit = trigger::payload(tval[2]).tr_id;
75 for(auto p : neighbor_range) {
76 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
77 if(other.get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other.id), this_slot, from_slot)) {
78 rlist.push_back(other.id);
79 }
80 }
81 } else {
82 for(auto p : neighbor_range) {
83 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
84 if(other.get_nation_from_province_ownership()) {
85 rlist.push_back(other.id);
86 }
87 }
88 }
89
90 if(rlist.size() != 0) {
91 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
92 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
93 }
94 return 0;
95 } else {
96 if((tval[0] & effect::scope_has_limit) != 0) {
97 auto limit = trigger::payload(tval[2]).tr_id;
98 uint32_t i = 0;
99 for(auto p : neighbor_range) {
100 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
101 if(other.get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other.id), this_slot, from_slot)) {
102 i += apply_subeffects(tval, ws, trigger::to_generic(other.id), this_slot, from_slot, r_hi, r_lo + i, els);
103 }
104 }
105 return i;
106 } else {
107 uint32_t i = 0;
108 for(auto p : neighbor_range) {
109 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
110 if(other.get_nation_from_province_ownership()) {
111 i += apply_subeffects(tval, ws, trigger::to_generic(other.id), this_slot, from_slot, r_hi, r_lo + i, els);
112 }
113 }
114 return i;
115 }
116 }
117}
118
119std::vector<dcon::province_id> country_get_province_adjacency(sys::state &state, dcon::nation_id nat_id) {
120 std::vector<dcon::province_id> v;
121
122 for(auto own : state.world.nation_get_province_ownership(nat_id)) {
123 auto prov = own.get_province().id;
124 auto neighbor_range = state.world.province_get_province_adjacency(prov);
125
126 for(auto adj : state.world.province_get_province_adjacency(prov)) {
128 auto other = adj.get_connected_provinces(0) != prov ? adj.get_connected_provinces(0) : adj.get_connected_provinces(1);
129
130 if(std::find(v.begin(), v.end(), other.id) == v.end()) {
131 v.push_back(other.id);
132 }
133 }
134 }
135 }
136
137 return v;
138}
140 auto neighbor_range = country_get_province_adjacency(ws, trigger::to_nation(primary_slot));
141
142
143 // random_
144 if((tval[0] & effect::is_random_scope) != 0) {
145 std::vector<dcon::province_id> rlist;
146
147 if((tval[0] & effect::scope_has_limit) != 0) {
148 auto limit = trigger::payload(tval[2]).tr_id;
149 for(auto other : neighbor_range) {
150 if(dcon::fatten(ws.world, other).get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other), this_slot, from_slot)) {
151 rlist.push_back(other);
152 }
153 }
154 } else {
155 for(auto other : neighbor_range) {
156 if(dcon::fatten(ws.world, other).get_nation_from_province_ownership()) {
157 rlist.push_back(other);
158 }
159 }
160 }
161
162 if(rlist.size() != 0) {
163 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
164 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
165 }
166 return 0;
167 } else {
168 // any_
169 if((tval[0] & effect::scope_has_limit) != 0) {
170 auto limit = trigger::payload(tval[2]).tr_id;
171 uint32_t i = 0;
172 for(auto other : neighbor_range) {
173 if(dcon::fatten(ws.world, other).get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other), this_slot, from_slot)) {
174 i += apply_subeffects(tval, ws, trigger::to_generic(other), this_slot, from_slot, r_hi, r_lo + i, els);
175 }
176 }
177 return i;
178 } else {
179 uint32_t i = 0;
180 for(auto other : neighbor_range) {
181 if(dcon::fatten(ws.world, other).get_nation_from_province_ownership()) {
182 i += apply_subeffects(tval, ws, trigger::to_generic(other), this_slot, from_slot, r_hi, r_lo + i, els);
183 }
184 }
185 return i;
186 }
187 }
188}
190 auto neighbor_range = country_get_province_adjacency(ws, trigger::to_nation(primary_slot));
191
192 // random_
193 if((tval[0] & effect::is_random_scope) != 0) {
194 std::vector<dcon::province_id> rlist;
195
196 if((tval[0] & effect::scope_has_limit) != 0) {
197 auto limit = trigger::payload(tval[2]).tr_id;
198 for(auto other : neighbor_range) {
199 if(!dcon::fatten(ws.world, other).get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other), this_slot, from_slot)) {
200 rlist.push_back(other);
201 }
202 }
203 } else {
204 for(auto other : neighbor_range) {
205 if(!dcon::fatten(ws.world, other).get_nation_from_province_ownership()) {
206 rlist.push_back(other);
207 }
208 }
209 }
210
211 if(rlist.size() != 0) {
212 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
213 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
214 }
215 return 0;
216 } else {
217 // any_
218 if((tval[0] & effect::scope_has_limit) != 0) {
219 auto limit = trigger::payload(tval[2]).tr_id;
220 uint32_t i = 0;
221 for(auto other : neighbor_range) {
222 if(!dcon::fatten(ws.world, other).get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other), this_slot, from_slot)) {
223 i += apply_subeffects(tval, ws, trigger::to_generic(other), this_slot, from_slot, r_hi, r_lo + i, els);
224 }
225 }
226 return i;
227 } else {
228 uint32_t i = 0;
229 for(auto other : neighbor_range) {
230 if(!dcon::fatten(ws.world, other).get_nation_from_province_ownership()) {
231 i += apply_subeffects(tval, ws, trigger::to_generic(other), this_slot, from_slot, r_hi, r_lo + i, els);
232 }
233 }
234 return i;
235 }
236 }
237}
239 auto neighbor_range = ws.world.nation_get_nation_adjacency(trigger::to_nation(primary_slot));
240
241 if((tval[0] & effect::is_random_scope) != 0) {
242 std::vector<dcon::nation_id> rlist;
243
244 if((tval[0] & effect::scope_has_limit) != 0) {
245 auto limit = trigger::payload(tval[2]).tr_id;
246 for(auto p : neighbor_range) {
247 auto other = p.get_connected_nations(0) == trigger::to_nation(primary_slot) ? p.get_connected_nations(1) : p.get_connected_nations(0);
248 if(trigger::evaluate(ws, limit, trigger::to_generic(other.id), this_slot, from_slot)) {
249 rlist.push_back(other.id);
250 }
251 }
252 } else {
253 for(auto p : neighbor_range) {
254 auto other = p.get_connected_nations(0) == trigger::to_nation(primary_slot) ? p.get_connected_nations(1) : p.get_connected_nations(0);
255 rlist.push_back(other.id);
256 }
257 }
258
259 if(rlist.size() != 0) {
260 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
261 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
262 }
263 return 0;
264 } else {
265 if((tval[0] & effect::scope_has_limit) != 0) {
266 auto limit = trigger::payload(tval[2]).tr_id;
267 uint32_t i = 0;
268 for(auto p : neighbor_range) {
269 auto other = p.get_connected_nations(0) == trigger::to_nation(primary_slot) ? p.get_connected_nations(1) : p.get_connected_nations(0);
270 if(trigger::evaluate(ws, limit, trigger::to_generic(other.id), this_slot, from_slot)) {
271 i += apply_subeffects(tval, ws, trigger::to_generic(other.id), this_slot, from_slot, r_hi, r_lo + i, els);
272 }
273 }
274 return i;
275 } else {
276 uint32_t i = 0;
277 for(auto p : neighbor_range) {
278 auto other = p.get_connected_nations(0) == trigger::to_nation(primary_slot) ? p.get_connected_nations(1) : p.get_connected_nations(0);
279 i += apply_subeffects(tval, ws, trigger::to_generic(other.id), this_slot, from_slot, r_hi, r_lo + i, els);
280 }
281 return i;
282 }
283 }
284}
286 if((tval[0] & effect::is_random_scope) != 0) {
287 std::vector<dcon::nation_id> rlist;
288 if((tval[0] & effect::scope_has_limit) != 0) {
289 auto limit = trigger::payload(tval[2]).tr_id;
290 for(auto n : ws.world.in_nation) {
291 if(n.get_owned_province_count() != 0 && trigger::evaluate(ws, limit, trigger::to_generic(n.id), this_slot, from_slot))
292 rlist.push_back(n.id);
293 }
294 } else {
295 for(auto n : ws.world.in_nation) {
296 if(n.get_owned_province_count() != 0)
297 rlist.push_back(n.id);
298 }
299 }
300
301 if(rlist.size() != 0) {
302 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
303 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
304 }
305 return 0;
306 } else {
307 uint32_t i = 0;
308 if((tval[0] & effect::scope_has_limit) != 0) {
309 auto limit = trigger::payload(tval[2]).tr_id;
310 for(auto n : ws.world.in_nation) {
311 if(n.get_owned_province_count() != 0 && trigger::evaluate(ws, limit, trigger::to_generic(n.id), this_slot, from_slot))
312 i += apply_subeffects(tval, ws, trigger::to_generic(n.id), this_slot, from_slot, r_hi, r_lo + i, els);
313 }
314 } else {
315 for(auto n : ws.world.in_nation) {
316 if(n.get_owned_province_count() != 0)
317 i += apply_subeffects(tval, ws, trigger::to_generic(n.id), this_slot, from_slot, r_hi, r_lo + i, els);
318 }
319 }
320 return i;
321 }
322}
324 if((tval[0] & effect::is_random_scope) != 0) {
325 std::vector<dcon::nation_id> rlist;
326 if((tval[0] & effect::scope_has_limit) != 0) {
327 auto limit = trigger::payload(tval[2]).tr_id;
328 for(auto n : ws.world.in_nation) {
329 if(n != trigger::to_nation(primary_slot) && trigger::evaluate(ws, limit, trigger::to_generic(n.id), this_slot, from_slot))
330 rlist.push_back(n.id);
331 }
332 } else {
333 for(auto n : ws.world.in_nation) {
334 if(n != trigger::to_nation(primary_slot))
335 rlist.push_back(n.id);
336 }
337 }
338 if(rlist.size() != 0) {
339 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
340 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
341 }
342 return 0;
343 } else {
344 uint32_t i = 0;
345 if((tval[0] & effect::scope_has_limit) != 0) {
346 auto limit = trigger::payload(tval[2]).tr_id;
347 for(auto n : ws.world.in_nation) {
348 if(n != trigger::to_nation(primary_slot) && trigger::evaluate(ws, limit, trigger::to_generic(n.id), this_slot, from_slot))
349 i += apply_subeffects(tval, ws, trigger::to_generic(n.id), this_slot, from_slot, r_hi, r_lo + i, els);
350 }
351 } else {
352 for(auto n : ws.world.in_nation) {
353 if(n != trigger::to_nation(primary_slot))
354 i += apply_subeffects(tval, ws, trigger::to_generic(n.id), this_slot, from_slot, r_hi, r_lo + i, els);
355 }
356 }
357 return i;
358 }
359}
361 if((tval[0] & effect::is_random_scope) != 0) {
362 std::vector<dcon::nation_id> rlist;
363 if((tval[0] & effect::scope_has_limit) != 0) {
364 auto limit = trigger::payload(tval[2]).tr_id;
365 for(auto n : ws.world.in_nation) {
366 if(n != trigger::to_nation(primary_slot) && n.get_owned_province_count() != 0 && trigger::evaluate(ws, limit, trigger::to_generic(n.id), this_slot, from_slot))
367 rlist.push_back(n.id);
368 }
369 } else {
370 for(auto n : ws.world.in_nation) {
371 if(n != trigger::to_nation(primary_slot) && n.get_owned_province_count() != 0)
372 rlist.push_back(n.id);
373 }
374 }
375 if(rlist.size() != 0) {
376 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
377 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
378 }
379 return 0;
380 } else {
381 uint32_t i = 0;
382 if((tval[0] & effect::scope_has_limit) != 0) {
383 auto limit = trigger::payload(tval[2]).tr_id;
384 for(auto n : ws.world.in_nation) {
385 if(n != trigger::to_nation(primary_slot) && n.get_owned_province_count() != 0 && trigger::evaluate(ws, limit, trigger::to_generic(n.id), this_slot, from_slot))
386 i += apply_subeffects(tval, ws, trigger::to_generic(n.id), this_slot, from_slot, r_hi, r_lo + i, els);
387 }
388 } else {
389 for(auto n : ws.world.in_nation) {
390 if(n != trigger::to_nation(primary_slot) && n.get_owned_province_count() != 0)
391 i += apply_subeffects(tval, ws, trigger::to_generic(n.id), this_slot, from_slot, r_hi, r_lo + i, els);
392 }
393 }
394 return i;
395 }
396}
398 if((tval[0] & effect::scope_has_limit) != 0) {
399 auto limit = trigger::payload(tval[2]).tr_id;
400 if(trigger::evaluate(ws, limit, primary_slot, this_slot, primary_slot)) {
401 return apply_subeffects(tval, ws, primary_slot, this_slot, primary_slot, r_hi, r_lo + 1, els);
402 }
403 return 0;
404 }
405 return apply_subeffects(tval, ws, primary_slot, this_slot, primary_slot, r_hi, r_lo + 1, els);
406}
408 if((tval[0] & effect::scope_has_limit) != 0) {
409 auto limit = trigger::payload(tval[2]).tr_id;
410 if(trigger::evaluate(ws, limit, primary_slot, primary_slot, from_slot)) {
411 return apply_subeffects(tval, ws, primary_slot, primary_slot, from_slot, r_hi, r_lo + 1, els);
412 }
413 return 0;
414 }
415 return apply_subeffects(tval, ws, primary_slot, primary_slot, from_slot, r_hi, r_lo + 1, els);
416}
417
419 return es_x_country_scope_nation(tval, ws, trigger::to_generic(dcon::nation_id{}), this_slot, from_slot, r_hi, r_lo, els);
420}
422 return es_x_event_country_scope_nation(tval, ws, trigger::to_generic(dcon::nation_id{}), this_slot, from_slot, r_hi, r_lo, els);
423}
425 return es_x_decision_country_scope_nation(tval, ws, trigger::to_generic(dcon::nation_id{}), this_slot, from_slot, r_hi, r_lo, els);
426}
428 auto neighbor_range = ws.world.province_get_province_adjacency(trigger::to_prov(primary_slot));
429 if((tval[0] & effect::is_random_scope) != 0) {
430 std::vector<dcon::province_id> rlist;
431 if((tval[0] & effect::scope_has_limit) != 0) {
432 auto limit = trigger::payload(tval[2]).tr_id;
433 for(auto p : neighbor_range) {
434 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
435 if(!other.get_nation_from_province_ownership() && trigger::evaluate(ws, limit, trigger::to_generic(other.id), this_slot, from_slot)) {
436 rlist.push_back(other.id);
437 }
438 }
439 } else {
440 for(auto p : neighbor_range) {
441 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
442 if(!other.get_nation_from_province_ownership()) {
443 rlist.push_back(other.id);
444 }
445 }
446 }
447
448 if(rlist.size() != 0) {
449 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
450 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
451 }
452 return 0;
453 } else {
454 uint32_t i = 0;
455 if((tval[0] & effect::scope_has_limit) != 0) {
456 auto limit = trigger::payload(tval[2]).tr_id;
457 for(auto p : neighbor_range) {
458 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
459 if(!other.get_nation_from_province_ownership() &&
460 trigger::evaluate(ws, limit, trigger::to_generic(other.id), this_slot, from_slot)) {
461 i += apply_subeffects(tval, ws, trigger::to_generic(other.id), this_slot, from_slot, r_hi, r_lo + i, els);
462 }
463 }
464 } else {
465 for(auto p : neighbor_range) {
466 auto other = p.get_connected_provinces(p.get_connected_provinces(0) == trigger::to_prov(primary_slot) ? 1 : 0);
467 if(!other.get_nation_from_province_ownership()) {
468 i += apply_subeffects(tval, ws, trigger::to_generic(other.id), this_slot, from_slot, r_hi, r_lo + i, els);
469 }
470 }
471 }
472 return i;
473 }
474}
476 if((tval[0] & effect::is_random_scope) != 0) {
477 std::vector<dcon::nation_id> rlist;
478 if((tval[0] & effect::scope_has_limit) != 0) {
479 auto limit = trigger::payload(tval[2]).tr_id;
480 for(auto& n : ws.great_nations) {
481 if(trigger::evaluate(ws, limit, trigger::to_generic(n.nation), this_slot, from_slot)) {
482 rlist.push_back(n.nation);
483 }
484 }
485 } else {
486 for(auto& n : ws.great_nations) {
487 rlist.push_back(n.nation);
488 }
489 }
490 if(rlist.size() != 0) {
491 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
492 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
493 }
494 return 0;
495 } else {
496 uint32_t i = 0;
497 if((tval[0] & effect::scope_has_limit) != 0) {
498 auto limit = trigger::payload(tval[2]).tr_id;
499 for(auto& n : ws.great_nations) {
500 if(trigger::evaluate(ws, limit, trigger::to_generic(n.nation), this_slot, from_slot)) {
501 i += apply_subeffects(tval, ws, trigger::to_generic(n.nation), this_slot, from_slot, r_hi, r_lo + i, els);
502 }
503 }
504 return i;
505 } else {
506 for(auto& n : ws.great_nations) {
507 i += apply_subeffects(tval, ws, trigger::to_generic(n.nation), this_slot, from_slot, r_hi, r_lo + i, els);
508 }
509 return i;
510 }
511 }
512}
514 uint32_t i = 0;
515 std::vector<dcon::pop_id> plist;
516 if((tval[0] & effect::scope_has_limit) != 0) {
517 auto limit = trigger::payload(tval[2]).tr_id;
518 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
519 for(auto pop : p.get_province().get_pop_location()) {
520 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::poor) && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
521 plist.push_back(pop.get_pop().id);
522 }
523 }
524 }
525 } else {
526 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
527 for(auto pop : p.get_province().get_pop_location()) {
528 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::poor)) {
529 plist.push_back(pop.get_pop().id);
530 }
531 }
532 }
533 }
534
535 for(auto p : plist)
536 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
537
538 return i;
539}
541 uint32_t i = 0;
542 std::vector<dcon::pop_id> plist;
543
544 if((tval[0] & effect::scope_has_limit) != 0) {
545 auto limit = trigger::payload(tval[2]).tr_id;
546 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
547 for(auto pop : ws.world.province_get_pop_location(p)) {
548 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::poor) && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
549 plist.push_back(pop.get_pop().id);
550 }
551 }
552 });
553 } else {
554 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
555 for(auto pop : ws.world.province_get_pop_location(p)) {
556 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::poor)) {
557 plist.push_back(pop.get_pop().id);
558 }
559 }
560 });
561 }
562
563 for(auto p : plist)
564 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
565 return i;
566}
567uint32_t es_poor_strata_scope_province(EFFECT_PARAMTERS) {
568 uint32_t i = 0;
569 std::vector<dcon::pop_id> plist;
570
571 if((tval[0] & effect::scope_has_limit) != 0) {
572 auto limit = trigger::payload(tval[2]).tr_id;
573 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
574 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::poor) && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
575 plist.push_back(pop.get_pop().id);
576 }
577 }
578 } else {
579 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
580 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::poor)) {
581 plist.push_back(pop.get_pop().id);
582 }
583 }
584 }
585
586 for(auto p : plist)
587 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
588 return i;
589}
590uint32_t es_middle_strata_scope_nation(EFFECT_PARAMTERS) {
591 uint32_t i = 0;
592 std::vector<dcon::pop_id> plist;
593
594 if((tval[0] & effect::scope_has_limit) != 0) {
595 auto limit = trigger::payload(tval[2]).tr_id;
596 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
597 for(auto pop : p.get_province().get_pop_location()) {
598 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::middle) &&
599 trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
600 plist.push_back(pop.get_pop().id);
601 }
602 }
603 }
604 } else {
605 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
606 for(auto pop : p.get_province().get_pop_location()) {
607 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::middle)) {
608 plist.push_back(pop.get_pop().id);
609 }
610 }
611 }
612 }
613
614 for(auto p : plist)
615 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
616 return i;
617}
618uint32_t es_middle_strata_scope_state(EFFECT_PARAMTERS) {
619 uint32_t i = 0;
620 std::vector<dcon::pop_id> plist;
621
622 if((tval[0] & effect::scope_has_limit) != 0) {
623 auto limit = trigger::payload(tval[2]).tr_id;
624 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
625 for(auto pop : ws.world.province_get_pop_location(p)) {
626 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::middle) && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
627 plist.push_back(pop.get_pop().id);
628 }
629 }
630 });
631 } else {
632 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
633 for(auto pop : ws.world.province_get_pop_location(p)) {
634 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::middle)) {
635 plist.push_back(pop.get_pop().id);
636 }
637 }
638 });
639 }
640 for(auto p : plist)
641 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
642 return i;
643}
644uint32_t es_middle_strata_scope_province(EFFECT_PARAMTERS) {
645 uint32_t i = 0;
646 std::vector<dcon::pop_id> plist;
647
648 if((tval[0] & effect::scope_has_limit) != 0) {
649 auto limit = trigger::payload(tval[2]).tr_id;
650 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
651 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::middle) &&
652 trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
653 plist.push_back(pop.get_pop().id);
654 }
655 }
656 } else {
657 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
658 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::middle)) {
659 plist.push_back(pop.get_pop().id);
660 }
661 }
662 }
663 return i;
664}
665uint32_t es_rich_strata_scope_nation(EFFECT_PARAMTERS) {
666 uint32_t i = 0;
667 std::vector<dcon::pop_id> plist;
668
669 if((tval[0] & effect::scope_has_limit) != 0) {
670 auto limit = trigger::payload(tval[2]).tr_id;
671 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
672 for(auto pop : p.get_province().get_pop_location()) {
673 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich) &&
674 trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
675 plist.push_back(pop.get_pop().id);
676 }
677 }
678 }
679 } else {
680 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
681 for(auto pop : p.get_province().get_pop_location()) {
682 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich)) {
683 plist.push_back(pop.get_pop().id);
684 }
685 }
686 }
687 }
688
689 for(auto p : plist)
690 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
691 return i;
692}
693uint32_t es_rich_strata_scope_state(EFFECT_PARAMTERS) {
694 uint32_t i = 0;
695 std::vector<dcon::pop_id> plist;
696
697 if((tval[0] & effect::scope_has_limit) != 0) {
698 auto limit = trigger::payload(tval[2]).tr_id;
699 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
700 for(auto pop : ws.world.province_get_pop_location(p)) {
701 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich) && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
702 plist.push_back(pop.get_pop().id);
703 }
704 }
705 });
706 } else {
707 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
708 for(auto pop : ws.world.province_get_pop_location(p)) {
709 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich)) {
710 plist.push_back(pop.get_pop().id);
711 }
712 }
713 });
714 }
715
716 for(auto p : plist)
717 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
718 return i;
719}
720uint32_t es_rich_strata_scope_province(EFFECT_PARAMTERS) {
721 uint32_t i = 0;
722 std::vector<dcon::pop_id> plist;
723
724 if((tval[0] & effect::scope_has_limit) != 0) {
725 auto limit = trigger::payload(tval[2]).tr_id;
726 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
727 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich) && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
728 plist.push_back(pop.get_pop().id);
729 }
730 }
731 } else {
732 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
733 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich)) {
734 plist.push_back(pop.get_pop().id);
735 }
736 }
737 }
738 for(auto p : plist)
739 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
740 return i;
741}
742uint32_t es_x_pop_scope_nation(EFFECT_PARAMTERS) {
743 if((tval[0] & effect::is_random_scope) != 0) {
744 std::vector<dcon::pop_id> rlist;
745 if((tval[0] & effect::scope_has_limit) != 0) {
746 auto limit = trigger::payload(tval[2]).tr_id;
747 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
748 for(auto pop : p.get_province().get_pop_location()) {
749 if(trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
750 rlist.push_back(pop.get_pop().id);
751 }
752 }
753 }
754 } else {
755 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
756 for(auto pop : p.get_province().get_pop_location()) {
757 rlist.push_back(pop.get_pop().id);
758 }
759 }
760 }
761 if(rlist.size() != 0) {
762 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
763 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
764 }
765 return 0;
766 } else {
767 uint32_t i = 0;
768 std::vector<dcon::pop_id> plist;
769
770 if((tval[0] & effect::scope_has_limit) != 0) {
771 auto limit = trigger::payload(tval[2]).tr_id;
772 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
773 for(auto pop : p.get_province().get_pop_location()) {
774 if(trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
775 plist.push_back(pop.get_pop().id);
776 }
777 }
778 }
779 } else {
780 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
781 for(auto pop : p.get_province().get_pop_location()) {
782 plist.push_back(pop.get_pop().id);
783 }
784 }
785 }
786
787 for(auto p : plist)
788 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
789 return i;
790 }
791}
792uint32_t es_x_pop_scope_state(EFFECT_PARAMTERS) {
793 if((tval[0] & effect::is_random_scope) != 0) {
794 std::vector<dcon::pop_id> rlist;
795 if((tval[0] & effect::scope_has_limit) != 0) {
796 auto limit = trigger::payload(tval[2]).tr_id;
797 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
798 for(auto pop : ws.world.province_get_pop_location(p)) {
799 if(trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
800 rlist.push_back(pop.get_pop().id);
801 }
802 }
803 });
804 } else {
805 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
806 for(auto pop : ws.world.province_get_pop_location(p)) {
807 rlist.push_back(pop.get_pop().id);
808 }
809 });
810 }
811 if(rlist.size() != 0) {
812 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
813 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
814 }
815 return 0;
816 } else {
817 uint32_t i = 0;
818 std::vector<dcon::pop_id> plist;
819
820 if((tval[0] & effect::scope_has_limit) != 0) {
821 auto limit = trigger::payload(tval[2]).tr_id;
822 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
823 for(auto pop : ws.world.province_get_pop_location(p)) {
824 if(trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
825 plist.push_back(pop.get_pop().id);
826 }
827 }
828 });
829 } else {
830 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
831 for(auto pop : ws.world.province_get_pop_location(p)) {
832 plist.push_back(pop.get_pop().id);
833 }
834 });
835 }
836
837 for(auto p : plist)
838 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
839 return i;
840 }
841}
842uint32_t es_x_pop_scope_province(EFFECT_PARAMTERS) {
843 if((tval[0] & effect::is_random_scope) != 0) {
844 std::vector<dcon::pop_id> rlist;
845
846 if((tval[0] & effect::scope_has_limit) != 0) {
847 auto limit = trigger::payload(tval[2]).tr_id;
848 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
849 if(trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
850 rlist.push_back(pop.get_pop().id);
851 }
852 }
853 } else {
854 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
855 rlist.push_back(pop.get_pop().id);
856 }
857 }
858
859 if(rlist.size() != 0) {
860 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
861 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
862 }
863 return 0;
864 } else {
865 uint32_t i = 0;
866 std::vector<dcon::pop_id> plist;
867
868 if((tval[0] & effect::scope_has_limit) != 0) {
869 auto limit = trigger::payload(tval[2]).tr_id;
870 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
871 if(trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
872 plist.push_back(pop.get_pop().id);
873 }
874 }
875 } else {
876 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
877 plist.push_back(pop.get_pop().id);
878 }
879 }
880
881 for(auto p : plist)
882 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
883 return i;
884 }
885}
886uint32_t es_x_owned_scope_nation(EFFECT_PARAMTERS) {
887 if((tval[0] & effect::is_random_scope) != 0) {
888 std::vector<dcon::province_id> rlist;
889
890 if((tval[0] & effect::scope_has_limit) != 0) {
891 auto limit = trigger::payload(tval[2]).tr_id;
892 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
893 if(trigger::evaluate(ws, limit, trigger::to_generic(p.get_province().id), this_slot, from_slot)) {
894 rlist.push_back(p.get_province().id);
895 }
896 }
897 } else {
898 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
899 rlist.push_back(p.get_province().id);
900 }
901 }
902
903 if(rlist.size() != 0) {
904 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
905 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
906 }
907 return 0;
908 } else {
909 std::vector<dcon::province_id> plist;
910
911 if((tval[0] & effect::scope_has_limit) != 0) {
912 auto limit = trigger::payload(tval[2]).tr_id;
913 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
914 if(trigger::evaluate(ws, limit, trigger::to_generic(p.get_province().id), this_slot, from_slot)) {
915 plist.push_back(p.get_province());
916 }
917 }
918 } else {
919 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
920 plist.push_back(p.get_province());
921 }
922 }
923
924 uint32_t i = 0;
925 for(auto p : plist) {
926 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
927 }
928 return i;
929 }
930}
931uint32_t es_x_owned_scope_state(EFFECT_PARAMTERS) {
932 if((tval[0] & effect::is_random_scope) != 0) {
933 std::vector<dcon::province_id> rlist;
934
935 if((tval[0] & effect::scope_has_limit) != 0) {
936 auto limit = trigger::payload(tval[2]).tr_id;
937 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
938 if(trigger::evaluate(ws, limit, trigger::to_generic(p), this_slot, from_slot)) {
939 rlist.push_back(p);
940 }
941 });
942 } else {
943 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
944 rlist.push_back(p);
945 });
946 }
947
948 if(rlist.size() != 0) {
949 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
950 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
951 }
952 return 0;
953 } else {
954 uint32_t i = 0;
955 if((tval[0] & effect::scope_has_limit) != 0) {
956 auto limit = trigger::payload(tval[2]).tr_id;
957 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
958 if(trigger::evaluate(ws, limit, trigger::to_generic(p), this_slot, from_slot)) {
959 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
960 }
961 });
962 } else {
963 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
964 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
965 });
966 }
967 return i;
968 }
969}
970uint32_t es_x_core_scope(EFFECT_PARAMTERS) {
971 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
972 auto cores_range = ws.world.national_identity_get_core(tag);
973
974 if((tval[0] & effect::is_random_scope) != 0) {
975 std::vector<dcon::province_id> rlist;
976
977 if((tval[0] & effect::scope_has_limit) != 0) {
978 auto limit = trigger::payload(tval[2]).tr_id;
979 for(auto p : cores_range) {
980 if(trigger::evaluate(ws, limit, trigger::to_generic(p.get_province().id), this_slot, from_slot))
981 rlist.push_back(p.get_province().id);
982 }
983 } else {
984 for(auto p : cores_range) {
985 rlist.push_back(p.get_province().id);
986 }
987 }
988
989 if(rlist.size() != 0) {
990 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
991 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
992 }
993 return 0;
994 } else {
995 std::vector<dcon::province_id> plist;
996
997 if((tval[0] & effect::scope_has_limit) != 0) {
998 auto limit = trigger::payload(tval[2]).tr_id;
999 for(auto p : cores_range) {
1000 if(trigger::evaluate(ws, limit, trigger::to_generic(p.get_province().id), this_slot, from_slot))
1001 plist.push_back(p.get_province());
1002 }
1003 } else {
1004 for(auto p : cores_range) {
1005 plist.push_back(p.get_province());
1006 }
1007 }
1008
1009 uint32_t i = 0;
1010 for(auto p : plist) {
1011 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
1012 }
1013 return i;
1014 }
1015}
1016uint32_t es_x_core_scope_province(EFFECT_PARAMTERS) {
1017 auto prov = trigger::to_prov(primary_slot);
1018 auto cores_range = ws.world.province_get_core(prov);
1019
1020 if((tval[0] & effect::is_random_scope) != 0) {
1021 std::vector<dcon::nation_id> rlist;
1022
1023 if((tval[0] & effect::scope_has_limit) != 0) {
1024 auto limit = trigger::payload(tval[2]).tr_id;
1025 for(auto p : cores_range) {
1026 auto h = p.get_identity().get_nation_from_identity_holder();
1027 if(h && trigger::evaluate(ws, limit, trigger::to_generic(h.id), this_slot, from_slot))
1028 rlist.push_back(h.id);
1029 }
1030 } else {
1031 for(auto p : cores_range) {
1032 auto h = p.get_identity().get_nation_from_identity_holder();
1033 if(h)
1034 rlist.push_back(h.id);
1035 }
1036 }
1037
1038 if(rlist.size() != 0) {
1039 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
1040 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
1041 }
1042 return 0;
1043 } else {
1044 std::vector<dcon::nation_id> plist;
1045
1046 if((tval[0] & effect::scope_has_limit) != 0) {
1047 auto limit = trigger::payload(tval[2]).tr_id;
1048 for(auto p : cores_range) {
1049 auto h = p.get_identity().get_nation_from_identity_holder();
1050 if(h && trigger::evaluate(ws, limit, trigger::to_generic(h.id), this_slot, from_slot))
1051 plist.push_back(h);
1052 }
1053 } else {
1054 for(auto p : cores_range) {
1055 auto h = p.get_identity().get_nation_from_identity_holder();
1056 if(h)
1057 plist.push_back(h);
1058 }
1059 }
1060
1061 uint32_t i = 0;
1062 for(auto p : plist) {
1063 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
1064 }
1065 return i;
1066 }
1067}
1068uint32_t es_x_state_scope(EFFECT_PARAMTERS) {
1069 if((tval[0] & effect::is_random_scope) != 0) {
1070 std::vector<dcon::state_instance_id> rlist;
1071
1072 if((tval[0] & effect::scope_has_limit) != 0) {
1073 auto limit = trigger::payload(tval[2]).tr_id;
1074 for(auto si : ws.world.nation_get_state_ownership(trigger::to_nation(primary_slot))) {
1075 if(trigger::evaluate(ws, limit, trigger::to_generic(si.get_state().id), this_slot, from_slot))
1076 rlist.push_back(si.get_state().id);
1077 }
1078 } else {
1079 for(auto si : ws.world.nation_get_state_ownership(trigger::to_nation(primary_slot))) {
1080 rlist.push_back(si.get_state().id);
1081 }
1082 }
1083 if(rlist.size() != 0) {
1084 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
1085 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
1086 }
1087 return 0;
1088 } else {
1089 std::vector<dcon::state_instance_id> slist;
1090
1091 if((tval[0] & effect::scope_has_limit) != 0) {
1092 auto limit = trigger::payload(tval[2]).tr_id;
1093 for(auto si : ws.world.nation_get_state_ownership(trigger::to_nation(primary_slot))) {
1094 if(trigger::evaluate(ws, limit, trigger::to_generic(si.get_state().id), this_slot, from_slot))
1095 slist.push_back(si.get_state());
1096 }
1097 } else {
1098 for(auto si : ws.world.nation_get_state_ownership(trigger::to_nation(primary_slot))) {
1099 slist.push_back(si.get_state());
1100 }
1101 }
1102
1103 uint32_t i = 0;
1104 for(auto p : slist) {
1105 i += apply_subeffects(tval, ws, trigger::to_generic(p), this_slot, from_slot, r_hi, r_lo + i, els);
1106 }
1107 return i;
1108 }
1109}
1110uint32_t es_x_substate_scope(EFFECT_PARAMTERS) {
1111 if((tval[0] & effect::is_random_scope) != 0) {
1112 std::vector<dcon::nation_id> rlist;
1113
1114 if((tval[0] & effect::scope_has_limit) != 0) {
1115 auto limit = trigger::payload(tval[2]).tr_id;
1116 for(auto si : ws.world.nation_get_overlord_as_ruler(trigger::to_nation(primary_slot))) {
1117 if(si.get_subject().get_is_substate() && trigger::evaluate(ws, limit, trigger::to_generic(si.get_subject().id), this_slot, from_slot))
1118 rlist.push_back(si.get_subject().id);
1119 }
1120 } else {
1121 for(auto si : ws.world.nation_get_overlord_as_ruler(trigger::to_nation(primary_slot))) {
1122 if(si.get_subject().get_is_substate())
1123 rlist.push_back(si.get_subject().id);
1124 }
1125 }
1126 if(rlist.size() != 0) {
1127 auto r = rng::get_random(ws, r_hi, r_lo) % rlist.size();
1128 return 1 + apply_subeffects(tval, ws, trigger::to_generic(rlist[r]), this_slot, from_slot, r_hi, r_lo + 1, els);
1129 }
1130 return 0;
1131 } else {
1132 uint32_t i = 0;
1133 if((tval[0] & effect::scope_has_limit) != 0) {
1134 auto limit = trigger::payload(tval[2]).tr_id;
1135 for(auto si : ws.world.nation_get_overlord_as_ruler(trigger::to_nation(primary_slot))) {
1136 if(si.get_subject().get_is_substate() && trigger::evaluate(ws, limit, trigger::to_generic(si.get_subject().id), this_slot, from_slot)) {
1137 i += apply_subeffects(tval, ws, trigger::to_generic(si.get_subject()), this_slot, from_slot, r_hi, r_lo + i, els);
1138 }
1139 }
1140 } else {
1141 for(auto si : ws.world.nation_get_overlord_as_ruler(trigger::to_nation(primary_slot))) {
1142 if(si.get_subject().get_is_substate()) {
1143 i += apply_subeffects(tval, ws, trigger::to_generic(si.get_subject()), this_slot, from_slot, r_hi, r_lo + i, els);
1144 }
1145 }
1146 }
1147 return i;
1148 }
1149}
1150uint32_t es_random_list_scope(EFFECT_PARAMTERS) {
1151 auto const source_size = 1 + effect::get_effect_scope_payload_size(tval);
1152 auto chances_total = tval[2];
1153
1154 auto r = int32_t(rng::get_random(ws, r_hi, r_lo) % chances_total);
1155
1156 auto sub_units_start = tval + 3; // [code] + [payload size] + [chances total] + [first sub effect chance]
1157 while(sub_units_start < tval + source_size) {
1158 r -= *sub_units_start;
1159 if(r < 0) {
1160 return 1 + internal_execute_effect(sub_units_start + 1, ws, primary_slot, this_slot, from_slot, r_hi, r_lo + 1, els);
1161 }
1162 sub_units_start += 2 + effect::get_generic_effect_payload_size(sub_units_start + 1); // each member preceeded by uint16_t
1163 }
1164 return 0;
1165}
1166uint32_t es_random_scope(EFFECT_PARAMTERS) {
1167 auto chance = tval[2];
1168 auto r = int32_t(rng::get_random(ws, r_hi, r_lo) % 100);
1169 if(r < chance)
1170 return 1 + apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo + 1, els);
1171 return 1;
1172}
1173uint32_t es_random_by_modifier_scope(EFFECT_PARAMTERS) {
1174 auto mod_k = dcon::value_modifier_key{ dcon::value_modifier_key::value_base_t(tval[2]) };
1175 auto chance = trigger::evaluate_multiplicative_modifier(ws, mod_k, primary_slot, this_slot, from_slot);
1176 assert(chance >= 0.f);
1177 auto r = int32_t(rng::get_random(ws, r_hi, r_lo) % 100);
1178 if(r < chance)
1179 return 1 + apply_subeffects(tval, ws, primary_slot, this_slot, from_slot, r_hi, r_lo + 1, els);
1180 return 1;
1181}
1182uint32_t es_owner_scope_state(EFFECT_PARAMTERS) {
1183 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot)); owner)
1184 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1185 return 0;
1186}
1187uint32_t es_owner_scope_province(EFFECT_PARAMTERS) {
1188 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
1189 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1190 return 0;
1191}
1192uint32_t es_controller_scope(EFFECT_PARAMTERS) {
1193 if(auto controller = ws.world.province_get_nation_from_province_control(trigger::to_prov(primary_slot)); controller)
1194 return apply_subeffects(tval, ws, trigger::to_generic(controller), this_slot, from_slot, r_hi, r_lo, els);
1195 return 0;
1196}
1197uint32_t es_location_scope(EFFECT_PARAMTERS) {
1198 if(auto owner = ws.world.pop_get_province_from_pop_location(trigger::to_pop(primary_slot)); owner)
1199 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1200 return 0;
1201}
1202uint32_t es_country_scope_pop(EFFECT_PARAMTERS) {
1203 auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot));
1204 if(owner)
1205 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1206 return 0;
1207}
1208uint32_t es_country_scope_state(EFFECT_PARAMTERS) {
1209 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
1210 if(owner)
1211 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1212 return 0;
1213}
1214uint32_t es_capital_scope(EFFECT_PARAMTERS) {
1215 auto owner = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
1216 if(owner)
1217 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1218 return 0;
1219}
1220uint32_t es_capital_scope_province(EFFECT_PARAMTERS) {
1221 auto owner = ws.world.nation_get_capital(ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)));
1222 if(owner)
1223 return apply_subeffects(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
1224 return 0;
1225}
1226uint32_t es_this_scope_nation(EFFECT_PARAMTERS) {
1227 return apply_subeffects(tval, ws, this_slot, this_slot, from_slot, r_hi, r_lo, els);
1228}
1229uint32_t es_this_scope_state(EFFECT_PARAMTERS) {
1230 return apply_subeffects(tval, ws, this_slot, this_slot, from_slot, r_hi, r_lo, els);
1231}
1232uint32_t es_this_scope_province(EFFECT_PARAMTERS) {
1233 return apply_subeffects(tval, ws, this_slot, this_slot, from_slot, r_hi, r_lo, els);
1234}
1235uint32_t es_this_scope_pop(EFFECT_PARAMTERS) {
1236 return apply_subeffects(tval, ws, this_slot, this_slot, from_slot, r_hi, r_lo, els);
1237}
1238uint32_t es_from_scope_nation(EFFECT_PARAMTERS) {
1239 return apply_subeffects(tval, ws, from_slot, this_slot, from_slot, r_hi, r_lo, els);
1240}
1241uint32_t es_from_scope_state(EFFECT_PARAMTERS) {
1242 return apply_subeffects(tval, ws, from_slot, this_slot, from_slot, r_hi, r_lo, els);
1243}
1244uint32_t es_from_scope_province(EFFECT_PARAMTERS) {
1245 return apply_subeffects(tval, ws, from_slot, this_slot, from_slot, r_hi, r_lo, els);
1246}
1247uint32_t es_from_scope_pop(EFFECT_PARAMTERS) {
1248 return apply_subeffects(tval, ws, from_slot, this_slot, from_slot, r_hi, r_lo, els);
1249}
1250uint32_t es_sea_zone_scope(EFFECT_PARAMTERS) {
1251 auto pid = fatten(ws.world, trigger::to_prov(primary_slot));
1252 for(auto adj : pid.get_province_adjacency()) {
1253 if(adj.get_connected_provinces(0).id.index() >= ws.province_definitions.first_sea_province.index()) {
1254 return apply_subeffects(tval, ws, trigger::to_generic(adj.get_connected_provinces(0).id), this_slot, from_slot, r_hi, r_lo, els);
1255 } else if(adj.get_connected_provinces(1).id.index() >= ws.province_definitions.first_sea_province.index()) {
1256 return apply_subeffects(tval, ws, trigger::to_generic(adj.get_connected_provinces(1).id), this_slot, from_slot, r_hi, r_lo, els);
1257 }
1258 }
1259 return 0;
1260}
1261uint32_t es_cultural_union_scope(EFFECT_PARAMTERS) {
1262 auto cultures = ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot));
1263 auto cg = ws.world.culture_get_group_from_culture_group_membership(cultures);
1264 auto union_tags = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1265 auto group_holders = ws.world.national_identity_get_nation_from_identity_holder(union_tags);
1266 if(group_holders)
1267 return apply_subeffects(tval, ws, trigger::to_generic(group_holders), this_slot, from_slot, r_hi, r_lo, els);
1268 return 0;
1269}
1270uint32_t es_overlord_scope(EFFECT_PARAMTERS) {
1271 auto overlord = ws.world.nation_get_overlord_as_subject(trigger::to_nation(primary_slot));
1272 auto on = ws.world.overlord_get_ruler(overlord);
1273 if(on)
1274 return apply_subeffects(tval, ws, trigger::to_generic(on), this_slot, from_slot, r_hi, r_lo, els);
1275 return 0;
1276}
1277uint32_t es_sphere_owner_scope(EFFECT_PARAMTERS) {
1278 auto sphere_leader = ws.world.nation_get_in_sphere_of(trigger::to_nation(primary_slot));
1279 if(sphere_leader)
1280 return apply_subeffects(tval, ws, trigger::to_generic(sphere_leader), this_slot, from_slot, r_hi, r_lo, els);
1281 return 0;
1282}
1283uint32_t es_independence_scope(EFFECT_PARAMTERS) {
1284 auto rtag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(primary_slot));
1285 auto rnation = ws.world.national_identity_get_nation_from_identity_holder(rtag);
1286 if(rnation)
1287 return apply_subeffects(tval, ws, trigger::to_generic(rnation), this_slot, from_slot, r_hi, r_lo, els);
1288 return 0;
1289}
1290uint32_t es_flashpoint_tag_scope(EFFECT_PARAMTERS) {
1291 auto ctag = ws.world.state_instance_get_flashpoint_tag(trigger::to_state(primary_slot));
1292 auto rnation = ws.world.national_identity_get_nation_from_identity_holder(ctag);
1293 if(rnation)
1294 return apply_subeffects(tval, ws, trigger::to_generic(rnation), this_slot, from_slot, r_hi, r_lo, els);
1295 return 0;
1296}
1297uint32_t es_crisis_state_scope(EFFECT_PARAMTERS) {
1298 auto cstate = ws.crisis_state;
1299 if(cstate)
1300 return apply_subeffects(tval, ws, trigger::to_generic(cstate), this_slot, from_slot, r_hi, r_lo, els);
1301 return 0;
1302}
1303uint32_t es_state_scope_province(EFFECT_PARAMTERS) {
1304 auto state = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
1305 if(state)
1306 return apply_subeffects(tval, ws, trigger::to_generic(state), this_slot, from_slot, r_hi, r_lo, els);
1307 return 0;
1308}
1309uint32_t es_state_scope_pop(EFFECT_PARAMTERS) {
1310 auto pop_province = ws.world.pop_get_province_from_pop_location(trigger::to_pop(primary_slot));
1311 auto state = ws.world.province_get_state_membership(pop_province);
1312 if(state)
1313 return apply_subeffects(tval, ws, trigger::to_generic(state), this_slot, from_slot, r_hi, r_lo, els);
1314 return 0;
1315}
1317 if((tval[0] & effect::scope_has_limit) != 0) {
1318 auto limit = trigger::payload(tval[2]).tr_id;
1319 auto tag = trigger::payload(tval[3]).tag_id;
1320 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(tag);
1321 if(tag_holder && trigger::evaluate(ws, limit, trigger::to_generic(tag_holder), this_slot, from_slot))
1322 return apply_subeffects(tval, ws, trigger::to_generic(tag_holder), this_slot, from_slot, r_hi, r_lo, els);
1323 return 0;
1324 } else {
1325 auto tag = trigger::payload(tval[2]).tag_id;
1326 auto tag_holder = ws.world.national_identity_get_nation_from_identity_holder(tag);
1327 if(tag_holder)
1328 return apply_subeffects(tval, ws, trigger::to_generic(tag_holder), this_slot, from_slot, r_hi, r_lo, els);
1329 return 0;
1330 }
1331}
1332uint32_t es_integer_scope(EFFECT_PARAMTERS) {
1333 if((tval[0] & effect::scope_has_limit) != 0) {
1334 auto limit = trigger::payload(tval[2]).tr_id;
1335 auto prov = trigger::payload(tval[3]).prov_id;
1336 if(prov && trigger::evaluate(ws, limit, trigger::to_generic(prov), this_slot, from_slot))
1337 return apply_subeffects(tval, ws, trigger::to_generic(prov), this_slot, from_slot, r_hi, r_lo, els);
1338 return 0;
1339 } else {
1340 auto prov = trigger::payload(tval[2]).prov_id;
1341 if(prov)
1342 return apply_subeffects(tval, ws, trigger::to_generic(prov), this_slot, from_slot, r_hi, r_lo, els);
1343 return 0;
1344 }
1345}
1346uint32_t es_pop_type_scope_nation(EFFECT_PARAMTERS) {
1347 uint32_t i = 0;
1348 if((tval[0] & effect::scope_has_limit) != 0) {
1349 auto limit = trigger::payload(tval[2]).tr_id;
1350 auto type = trigger::payload(tval[3]).popt_id;
1351 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
1352 for(auto pop : p.get_province().get_pop_location()) {
1353 if(pop.get_pop().get_poptype() == type && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
1354 i += apply_subeffects(tval, ws, trigger::to_generic(pop.get_pop().id), this_slot, from_slot, r_hi, r_lo + i, els);
1355 }
1356 }
1357 }
1358 } else {
1359 auto type = trigger::payload(tval[2]).popt_id;
1360 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
1361 for(auto pop : p.get_province().get_pop_location()) {
1362 if(pop.get_pop().get_poptype() == type) {
1363 i += apply_subeffects(tval, ws, trigger::to_generic(pop.get_pop().id), this_slot, from_slot, r_hi, r_lo + i, els);
1364 }
1365 }
1366 }
1367 }
1368 return i;
1369}
1370uint32_t es_pop_type_scope_state(EFFECT_PARAMTERS) {
1371 if((tval[0] & effect::scope_has_limit) != 0) {
1372 auto limit = trigger::payload(tval[2]).tr_id;
1373 auto type = trigger::payload(tval[3]).popt_id;
1374 uint32_t i = 0;
1375 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
1376 for(auto pop : ws.world.province_get_pop_location(p)) {
1377 if(pop.get_pop().get_poptype() == type && trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
1378 i += apply_subeffects(tval, ws, trigger::to_generic(pop.get_pop().id), this_slot, from_slot, r_hi, r_lo + i, els);
1379 }
1380 }
1381 });
1382 return i;
1383 } else {
1384 auto type = trigger::payload(tval[2]).popt_id;
1385 uint32_t i = 0;
1386 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
1387 for(auto pop : ws.world.province_get_pop_location(p)) {
1388 if(pop.get_pop().get_poptype() == type) {
1389 i += apply_subeffects(tval, ws, trigger::to_generic(pop.get_pop().id), this_slot, from_slot, r_hi, r_lo + i, els);
1390 }
1391 }
1392 });
1393 return i;
1394 }
1395}
1396uint32_t es_pop_type_scope_province(EFFECT_PARAMTERS) {
1397 if((tval[0] & effect::scope_has_limit) != 0) {
1398 auto limit = trigger::payload(tval[2]).tr_id;
1399 auto type = trigger::payload(tval[3]).popt_id;
1400
1401 uint32_t i = 0;
1402 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
1403 if(pop.get_pop().get_poptype() == type &&
1404 trigger::evaluate(ws, limit, trigger::to_generic(pop.get_pop().id), this_slot, from_slot)) {
1405 i += apply_subeffects(tval, ws, trigger::to_generic(pop.get_pop().id), this_slot, from_slot, r_hi, r_lo + i, els);
1406 }
1407 }
1408 return i;
1409 } else {
1410 auto type = trigger::payload(tval[2]).popt_id;
1411
1412 uint32_t i = 0;
1413 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
1414 if(pop.get_pop().get_poptype() == type) {
1415 i += apply_subeffects(tval, ws, trigger::to_generic(pop.get_pop().id), this_slot, from_slot, r_hi, r_lo + i, els);
1416 }
1417 }
1418 return i;
1419 }
1420}
1421uint32_t es_region_scope(EFFECT_PARAMTERS) {
1422 uint32_t i = 0;
1423 if((tval[0] & effect::scope_has_limit) != 0) {
1424 auto region = trigger::payload(tval[3]).state_id;
1425 auto limit = trigger::payload(tval[2]).tr_id;
1426 for(auto p : ws.world.state_definition_get_abstract_state_membership(region)) {
1427 if(trigger::evaluate(ws, limit, trigger::to_generic(p.get_province().id), this_slot, from_slot)) {
1428 i += apply_subeffects(tval, ws, trigger::to_generic(p.get_province().id), this_slot, from_slot, r_hi, r_lo + i, els);
1429 }
1430 }
1431 } else {
1432 auto region = trigger::payload(tval[2]).state_id;
1433 for(auto p : ws.world.state_definition_get_abstract_state_membership(region)) {
1434 i += apply_subeffects(tval, ws, trigger::to_generic(p.get_province().id), this_slot, from_slot, r_hi, r_lo + i, els);
1435 }
1436 }
1437 return i;
1438}
1439uint32_t es_region_proper_scope(EFFECT_PARAMTERS) {
1440 uint32_t i = 0;
1441 if((tval[0] & effect::scope_has_limit) != 0) {
1442 auto region = trigger::payload(tval[3]).reg_id;
1443 auto limit = trigger::payload(tval[2]).tr_id;
1444 for(auto p : ws.world.region_get_region_membership(region)) {
1445 if(trigger::evaluate(ws, limit, trigger::to_generic(p.get_province().id), this_slot, from_slot)) {
1446 i += apply_subeffects(tval, ws, trigger::to_generic(p.get_province().id), this_slot, from_slot, r_hi, r_lo + i, els);
1447 }
1448 }
1449 } else {
1450 auto region = trigger::payload(tval[2]).reg_id;
1451 for(auto p : ws.world.region_get_region_membership(region)) {
1452 i += apply_subeffects(tval, ws, trigger::to_generic(p.get_province().id), this_slot, from_slot, r_hi, r_lo + i, els);
1453 }
1454 }
1455 return i;
1456}
1457
1459 return 0;
1460}
1462 auto new_capital = trigger::payload(tval[1]).prov_id;
1463 if(ws.world.province_get_nation_from_province_ownership(new_capital) == trigger::to_nation(primary_slot))
1464 ws.world.nation_set_capital(trigger::to_nation(primary_slot), new_capital);
1465 return 0;
1466}
1467uint32_t ef_add_core_tag(EFFECT_PARAMTERS) {
1468 auto tag = trigger::payload(tval[1]).tag_id;
1469 province::add_core(ws, trigger::to_prov(primary_slot), tag);
1470 return 0;
1471}
1472uint32_t ef_add_core_tag_state(EFFECT_PARAMTERS) {
1473 auto tag = trigger::payload(tval[1]).tag_id;
1474 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) { province::add_core(ws, p, tag); });
1475 return 0;
1476}
1477uint32_t ef_add_core_int(EFFECT_PARAMTERS) {
1478 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
1479 auto prov = trigger::payload(tval[1]).prov_id;
1480 province::add_core(ws, prov, tag);
1481 return 0;
1482}
1483uint32_t ef_add_core_this_nation(EFFECT_PARAMTERS) {
1484 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
1485 auto prov = trigger::to_prov(primary_slot);
1486 province::add_core(ws, prov, tag);
1487 return 0;
1488}
1489uint32_t ef_add_core_this_province(EFFECT_PARAMTERS) {
1490 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
1491 if(owner)
1492 return ef_add_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1493 else
1494 return 0;
1495}
1496uint32_t ef_add_core_this_state(EFFECT_PARAMTERS) {
1497 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
1498 if(owner)
1499 return ef_add_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1500 else
1501 return 0;
1502}
1503uint32_t ef_add_core_this_pop(EFFECT_PARAMTERS) {
1504 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
1505 if(owner)
1506 return ef_add_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1507 else
1508 return 0;
1509}
1510uint32_t ef_add_core_from_province(EFFECT_PARAMTERS) {
1511 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
1512 if(owner)
1513 return ef_add_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1514 else
1515 return 0;
1516}
1517uint32_t ef_add_core_from_nation(EFFECT_PARAMTERS) {
1518 return ef_add_core_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
1519}
1520uint32_t ef_add_core_reb(EFFECT_PARAMTERS) {
1521 auto tag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
1522 province::add_core(ws, trigger::to_prov(primary_slot), tag);
1523 return 0;
1524}
1525
1526uint32_t ef_add_core_state_this_nation(EFFECT_PARAMTERS) {
1527 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
1529 [&](dcon::province_id p) { province::add_core(ws, p, tag); });
1530 return 0;
1531}
1532uint32_t ef_add_core_state_this_province(EFFECT_PARAMTERS) {
1533 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
1534 if(owner)
1535 return ef_add_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1536 else
1537 return 0;
1538}
1539uint32_t ef_add_core_state_this_state(EFFECT_PARAMTERS) {
1540 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
1541 if(owner)
1542 return ef_add_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1543 else
1544 return 0;
1545}
1546uint32_t ef_add_core_state_this_pop(EFFECT_PARAMTERS) {
1547 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
1548 if(owner)
1549 return ef_add_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1550 else
1551 return 0;
1552}
1553uint32_t ef_add_core_state_from_province(EFFECT_PARAMTERS) {
1554 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
1555 if(owner)
1556 return ef_add_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1557 else
1558 return 0;
1559}
1560uint32_t ef_add_core_state_from_nation(EFFECT_PARAMTERS) {
1561 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(from_slot));
1563 [&](dcon::province_id p) { province::add_core(ws, p, tag); });
1564 return 0;
1565}
1566uint32_t ef_add_core_state_reb(EFFECT_PARAMTERS) {
1567 auto tag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
1569 [&](dcon::province_id p) { province::add_core(ws, p, tag); });
1570 return 0;
1571}
1572
1573uint32_t ef_remove_core_tag(EFFECT_PARAMTERS) {
1574 auto tag = trigger::payload(tval[1]).tag_id;
1575 auto prov = trigger::to_prov(primary_slot);
1576 province::remove_core(ws, prov, tag);
1577 return 0;
1578}
1579uint32_t ef_remove_core_tag_state(EFFECT_PARAMTERS) {
1580 auto tag = trigger::payload(tval[1]).tag_id;
1582 [&](dcon::province_id p) { province::remove_core(ws, p, tag); });
1583 return 0;
1584}
1586 auto tag = trigger::payload(tval[1]).tag_id;
1587 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
1588 province::remove_core(ws, p.get_province(), tag);
1589 }
1590 return 0;
1591}
1592uint32_t ef_remove_core_int(EFFECT_PARAMTERS) {
1593 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
1594 auto prov = trigger::payload(tval[1]).prov_id;
1595 province::remove_core(ws, prov, tag);
1596 return 0;
1597}
1599 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
1600 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
1601 province::remove_core(ws, p.get_province(), tag);
1602 }
1603 return 0;
1604}
1606 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
1607 if(owner)
1608 return ef_remove_core_nation_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1609 else
1610 return 0;
1611}
1613 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
1614 if(owner)
1615 return ef_remove_core_nation_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1616 else
1617 return 0;
1618}
1620 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
1621 if(owner)
1622 return ef_remove_core_nation_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1623 else
1624 return 0;
1625}
1627 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
1628 if(owner)
1629 return ef_remove_core_nation_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1630 return 0;
1631}
1633 return ef_remove_core_nation_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
1634}
1636 auto tag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
1637 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
1638 province::remove_core(ws, p.get_province(), tag);
1639 }
1640 return 0;
1641}
1643 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
1645 [&](dcon::province_id p) { province::remove_core(ws, p, tag);
1646 });
1647 return 0;
1648}
1650 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
1651 if(owner)
1652 return ef_remove_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1653 else
1654 return 0;
1655}
1657 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
1658 if(owner)
1659 return ef_remove_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1660 else
1661 return 0;
1662}
1664 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
1665 if(owner)
1666 return ef_remove_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1667 else
1668 return 0;
1669}
1671 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
1672 if(owner)
1673 return ef_remove_core_state_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1674 return 0;
1675}
1677 return ef_remove_core_state_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
1678}
1680 auto tag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
1682 [&](dcon::province_id p) { province::remove_core(ws, p, tag); });
1683 return 0;
1684}
1685
1686uint32_t ef_remove_core_this_nation(EFFECT_PARAMTERS) {
1687 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
1688 auto prov = trigger::to_prov(primary_slot);
1689 province::remove_core(ws, prov, tag);
1690 return 0;
1691}
1692uint32_t ef_remove_core_this_province(EFFECT_PARAMTERS) {
1693 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
1694 if(owner)
1695 return ef_remove_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1696 else
1697 return 0;
1698}
1699uint32_t ef_remove_core_this_state(EFFECT_PARAMTERS) {
1700 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
1701 if(owner)
1702 return ef_remove_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1703 else
1704 return 0;
1705}
1706uint32_t ef_remove_core_this_pop(EFFECT_PARAMTERS) {
1707 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
1708 if(owner)
1709 return ef_remove_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1710 else
1711 return 0;
1712}
1713uint32_t ef_remove_core_from_province(EFFECT_PARAMTERS) {
1714 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
1715 if(owner)
1716 return ef_remove_core_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
1717 return 0;
1718}
1719uint32_t ef_remove_core_from_nation(EFFECT_PARAMTERS) {
1720 return ef_remove_core_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
1721}
1722uint32_t ef_remove_core_reb(EFFECT_PARAMTERS) {
1723 auto tag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
1724 province::remove_core(ws, trigger::to_prov(primary_slot), tag);
1725 return 0;
1726}
1727uint32_t ef_change_region_name_state(EFFECT_PARAMTERS) {
1728 auto def = ws.world.state_instance_get_definition(trigger::to_state(primary_slot));
1729 dcon::text_key name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
1730 ws.world.state_definition_set_name(def, name);
1731 return 0;
1732}
1733uint32_t ef_change_region_name_province(EFFECT_PARAMTERS) {
1734 auto def = ws.world.province_get_state_from_abstract_state_membership(trigger::to_prov(primary_slot));
1735 if(def) {
1736 dcon::text_key name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
1737 ws.world.state_definition_set_name(def, name);
1738 }
1739 return 0;
1740}
1742 province::set_rgo(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).com_id);
1743 return 0;
1744}
1745uint32_t ef_add_accepted_culture(EFFECT_PARAMTERS) {
1746 if(ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot)) == trigger::payload(tval[1]).cul_id) {
1747 return 0;
1748 }
1749 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), trigger::payload(tval[1]).cul_id, true);
1751 return 0;
1752}
1753uint32_t ef_add_accepted_culture_union(EFFECT_PARAMTERS) {
1754 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot));
1755 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
1756 for(auto c : ws.world.culture_group_get_culture_group_membership(cg)) {
1757 if(ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot)) != c.get_member().id) {
1758 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.get_member().id, true);
1759 }
1760 }
1762 return 0;
1763}
1764
1765uint32_t ef_add_accepted_culture_this(EFFECT_PARAMTERS) {
1766 auto c = ws.world.nation_get_primary_culture(trigger::to_nation(this_slot));
1767 if(ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot)) == c) {
1768 return 0;
1769 }
1770 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c, true);
1772 return 0;
1773}
1775 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(this_slot));
1776 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
1777 for(auto c : ws.world.culture_group_get_culture_group_membership(cg)) {
1778 if(ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot)) != c.get_member().id) {
1779 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.get_member().id, true);
1780 }
1781 }
1783 return 0;
1784}
1785uint32_t ef_add_accepted_culture_from(EFFECT_PARAMTERS) {
1786 auto c = ws.world.nation_get_primary_culture(trigger::to_nation(from_slot));
1787 if(ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot)) == c) {
1788 return 0;
1789 }
1790 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c, true);
1792 return 0;
1793}
1795 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(from_slot));
1796 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
1797 for(auto c : ws.world.culture_group_get_culture_group_membership(cg)) {
1798 if(ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot)) != c.get_member().id) {
1799 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.get_member().id, true);
1800 }
1801 }
1803 return 0;
1804}
1805
1806uint32_t ef_primary_culture(EFFECT_PARAMTERS) {
1807 ws.world.nation_set_primary_culture(trigger::to_nation(primary_slot), trigger::payload(tval[1]).cul_id);
1808 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), trigger::payload(tval[1]).cul_id, false);
1810 return 0;
1811}
1812uint32_t ef_primary_culture_this_nation(EFFECT_PARAMTERS) {
1813 auto c = ws.world.nation_get_primary_culture(trigger::to_nation(this_slot));
1814 ws.world.nation_set_primary_culture(trigger::to_nation(primary_slot), c);
1815 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.id, false);
1817 return 0;
1818}
1819uint32_t ef_primary_culture_this_state(EFFECT_PARAMTERS) {
1820 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
1821 if(owner) {
1822 auto c = ws.world.nation_get_primary_culture(owner);
1823 ws.world.nation_set_primary_culture(trigger::to_nation(primary_slot), c);
1824 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.id, false);
1826 }
1827 return 0;
1828}
1829uint32_t ef_primary_culture_this_province(EFFECT_PARAMTERS) {
1830 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
1831 if(owner) {
1832 auto c = ws.world.nation_get_primary_culture(owner);
1833 ws.world.nation_set_primary_culture(trigger::to_nation(primary_slot), c);
1834 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.id, false);
1836 }
1837 return 0;
1838}
1839uint32_t ef_primary_culture_this_pop(EFFECT_PARAMTERS) {
1840 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
1841 if(owner) {
1842 auto c = ws.world.nation_get_primary_culture(owner);
1843 ws.world.nation_set_primary_culture(trigger::to_nation(primary_slot), c);
1844 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.id, false);
1846 }
1847 return 0;
1848}
1849uint32_t ef_primary_culture_from_nation(EFFECT_PARAMTERS) {
1850 auto c = ws.world.nation_get_primary_culture(trigger::to_nation(from_slot));
1851 ws.world.nation_set_primary_culture(trigger::to_nation(primary_slot), c);
1852 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), c.id, false);
1854 return 0;
1855}
1856uint32_t ef_remove_accepted_culture(EFFECT_PARAMTERS) {
1857 ws.world.nation_set_accepted_cultures(trigger::to_nation(primary_slot), trigger::payload(tval[1]).cul_id, false);
1859 return 0;
1860}
1862 ws.world.province_set_life_rating(trigger::to_prov(primary_slot),
1863 uint8_t(std::clamp(int32_t(ws.world.province_get_life_rating(trigger::to_prov(primary_slot))) +
1865 0, 255)));
1866 return 0;
1867}
1869 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
1870 ws.world.province_set_life_rating(
1871 p,
1872 uint8_t(std::clamp(int32_t(ws.world.province_get_life_rating(p)) + trigger::payload(tval[1]).signed_value, 0, 255)));
1873 });
1874
1875 return 0;
1876}
1878 ws.world.nation_set_religion(trigger::to_nation(primary_slot), trigger::payload(tval[1]).rel_id);
1879 return 0;
1880}
1881uint32_t ef_religion_province(EFFECT_PARAMTERS) {
1882 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner) {
1883 auto owner_c = ws.world.nation_get_primary_culture(owner);
1884 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
1885 pop.get_pop().set_religion(trigger::payload(tval[1]).rel_id);
1886 }
1887 }
1888 return 0;
1889}
1890uint32_t ef_religion_pop(EFFECT_PARAMTERS) {
1891 auto pop = trigger::to_pop(primary_slot);
1892 dcon::fatten(ws.world, pop).set_religion(trigger::payload(tval[1]).rel_id);
1893 return 0;
1894}
1895uint32_t ef_is_slave_state_yes(EFFECT_PARAMTERS) {
1897 [&](dcon::province_id p) { ws.world.province_set_is_slave(p, true); });
1898 return 0;
1899}
1901 ws.world.province_set_is_slave(trigger::to_prov(primary_slot), true);
1902 return 0;
1903}
1904uint32_t ef_is_slave_pop_yes(EFFECT_PARAMTERS) {
1905 ws.world.pop_set_poptype(trigger::to_pop(primary_slot), ws.culture_definitions.slaves);
1906 return 0;
1907}
1908uint32_t ef_research_points(EFFECT_PARAMTERS) {
1909 ws.world.nation_get_research_points(trigger::to_nation(primary_slot)) += float(trigger::payload(tval[1]).signed_value);
1910 return 0;
1911}
1913 ws.world.nation_set_tech_school(trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id);
1914 return 0;
1915}
1917 politics::change_government_type(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).gov_id);
1918 return 0;
1919}
1920uint32_t ef_government_reb(EFFECT_PARAMTERS) {
1921
1922 auto new_gov = ws.world.rebel_faction_get_type(trigger::to_rebel(from_slot))
1923 .get_government_change(ws.world.nation_get_government_type(trigger::to_nation(primary_slot)));
1924 if(new_gov) {
1925 politics::change_government_type(ws, trigger::to_nation(primary_slot), new_gov);
1926 }
1927 return 0;
1928}
1930 auto amount = trigger::read_float_from_payload(tval + 1);
1931 assert(std::isfinite(amount));
1932 auto& t = ws.world.nation_get_stockpiles(trigger::to_nation(primary_slot), economy::money);
1933 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
1934 t += amount;
1935 else
1936 t = std::max(0.0f, t + amount);
1937 return 0;
1938}
1939uint32_t ef_war_exhaustion(EFFECT_PARAMTERS) {
1940 auto& war_x = ws.world.nation_get_war_exhaustion(trigger::to_nation(primary_slot));
1941 auto amount = trigger::read_float_from_payload(tval + 1);
1942 assert(std::isfinite(amount));
1943 war_x = std::clamp(war_x + amount, 0.0f, 100.0f);
1944 return 0;
1945}
1947 auto amount = trigger::read_float_from_payload(tval + 1);
1948 assert(std::isfinite(amount));
1949 nations::adjust_prestige(ws, trigger::to_nation(primary_slot), amount);
1950 return 0;
1951}
1953 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
1954 culture::replace_cores(ws, tag, trigger::payload(tval[1]).tag_id);
1955 auto old_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
1956 ws.world.nation_set_identity_from_identity_holder(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tag_id);
1958 if(old_holder) {
1959 ws.world.nation_set_identity_from_identity_holder(old_holder, tag);
1961 }
1962 return 0;
1963}
1964uint32_t ef_change_tag_culture(EFFECT_PARAMTERS) {
1965 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot));
1966 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
1967 auto u = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1968 if(!u)
1969 return 0;
1970
1971 auto old_holder = ws.world.national_identity_get_nation_from_identity_holder(u);
1972 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
1973 culture::replace_cores(ws, tag, u);
1974 ws.world.nation_set_identity_from_identity_holder(trigger::to_nation(primary_slot), u);
1976 if(old_holder) {
1977 ws.world.nation_set_identity_from_identity_holder(old_holder, tag);
1979 }
1980 return 0;
1981}
1982uint32_t ef_change_tag_no_core_switch(EFFECT_PARAMTERS) {
1983 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
1984 if(!holder)
1985 return 0;
1986
1987 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot))) {
1988 network::switch_player(ws, holder, trigger::to_nation(primary_slot));
1989 } else if(ws.world.nation_get_is_player_controlled(holder)) {
1990 network::switch_player(ws, trigger::to_nation(primary_slot), holder);
1991 }
1992
1993 auto old_controller = ws.world.nation_get_is_player_controlled(holder);
1994 ws.world.nation_set_is_player_controlled(holder, ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)));
1995 ws.world.nation_set_is_player_controlled(trigger::to_nation(primary_slot), old_controller);
1996
1997 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
1998 ai::remove_ai_data(ws, trigger::to_nation(primary_slot));
1999 if(ws.world.nation_get_is_player_controlled(holder))
2000 ai::remove_ai_data(ws, holder);
2001
2002 if(ws.local_player_nation == trigger::to_nation(primary_slot)) {
2003 ws.local_player_nation = holder;
2004 } else if(ws.local_player_nation == holder) {
2005 ws.local_player_nation = trigger::to_nation(primary_slot);
2006 }
2007 return 0;
2008}
2009uint32_t ef_change_tag_no_core_switch_culture(EFFECT_PARAMTERS) {
2010 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot));
2011 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
2012 auto u = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
2013 auto holder = ws.world.national_identity_get_nation_from_identity_holder(u);
2014 if(!holder)
2015 return 0;
2016
2017 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot))) {
2018 network::switch_player(ws, holder, trigger::to_nation(primary_slot));
2019 } else if(ws.world.nation_get_is_player_controlled(holder)) {
2020 network::switch_player(ws, trigger::to_nation(primary_slot), holder);
2021 }
2022
2023 auto old_controller = ws.world.nation_get_is_player_controlled(holder);
2024 ws.world.nation_set_is_player_controlled(holder, ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)));
2025 ws.world.nation_set_is_player_controlled(trigger::to_nation(primary_slot), old_controller);
2026
2027 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
2028 ai::remove_ai_data(ws, trigger::to_nation(primary_slot));
2029 if(ws.world.nation_get_is_player_controlled(holder))
2030 ai::remove_ai_data(ws, holder);
2031
2032 if(ws.local_player_nation == trigger::to_nation(primary_slot)) {
2033 ws.local_player_nation = holder;
2034 } else if(ws.local_player_nation == holder) {
2035 ws.local_player_nation = trigger::to_nation(primary_slot);
2036 }
2037 return 0;
2038}
2039uint32_t ef_set_country_flag(EFFECT_PARAMTERS) {
2040 ws.world.nation_set_flag_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natf_id, true);
2041 return 0;
2042}
2043uint32_t ef_clr_country_flag(EFFECT_PARAMTERS) {
2044 ws.world.nation_set_flag_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natf_id, false);
2045 return 0;
2046}
2047uint32_t ef_military_access(EFFECT_PARAMTERS) {
2048 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2049 if(target)
2050 military::give_military_access(ws, trigger::to_nation(primary_slot), target);
2051 return 0;
2052}
2053uint32_t ef_military_access_this_nation(EFFECT_PARAMTERS) {
2055 return 0;
2056}
2057uint32_t ef_military_access_this_province(EFFECT_PARAMTERS) {
2058 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2059 if(target)
2060 military::give_military_access(ws, trigger::to_nation(primary_slot), target);
2061 return 0;
2062}
2063uint32_t ef_military_access_from_nation(EFFECT_PARAMTERS) {
2065 return 0;
2066}
2067uint32_t ef_military_access_from_province(EFFECT_PARAMTERS) {
2068 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2069 if(target)
2070 military::give_military_access(ws, trigger::to_nation(primary_slot), target);
2071 return 0;
2072}
2074 auto& inf = ws.world.nation_get_infamy(trigger::to_nation(primary_slot));
2075 auto amount = trigger::read_float_from_payload(tval + 1);
2076 assert(std::isfinite(amount));
2077 inf = std::max(0.0f, inf + amount);
2078 return 0;
2079}
2080uint32_t ef_secede_province(EFFECT_PARAMTERS) {
2081 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2082 if(!holder)
2083 return 0;
2084 auto hprovs = ws.world.nation_get_province_ownership(holder);
2085 if(hprovs.begin() == hprovs.end()) {
2086 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2087 if(powner)
2088 nations::create_nation_based_on_template(ws, holder, powner);
2089 }
2090 province::change_province_owner(ws, trigger::to_prov(primary_slot), holder);
2091 return 0;
2092}
2093uint32_t ef_secede_province_state(EFFECT_PARAMTERS) {
2094 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2095 if(!holder)
2096 return 0;
2097 auto hprovs = ws.world.nation_get_province_ownership(holder);
2098 if(hprovs.begin() == hprovs.end()) {
2099 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2100 if(powner)
2101 nations::create_nation_based_on_template(ws, holder, powner);
2102 }
2104 [&](dcon::province_id p) { province::change_province_owner(ws, p, holder); });
2105 return 0;
2106}
2107uint32_t ef_secede_province_state_this_nation(EFFECT_PARAMTERS) {
2108 auto target = trigger::to_nation(this_slot);
2109 auto hprovs = ws.world.nation_get_province_ownership(target);
2110 if(hprovs.begin() == hprovs.end()) {
2111 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2112 if(powner)
2113 nations::create_nation_based_on_template(ws, target, powner);
2114 }
2116 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2117 return 0;
2118}
2119uint32_t ef_secede_province_state_this_state(EFFECT_PARAMTERS) {
2120 auto target = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2121 if(!target)
2122 return 0;
2123 auto hprovs = ws.world.nation_get_province_ownership(target);
2124 if(hprovs.begin() == hprovs.end()) {
2125 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2126 if(powner)
2127 nations::create_nation_based_on_template(ws, target, powner);
2128 }
2130 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2131 return 0;
2132}
2133uint32_t ef_secede_province_state_this_province(EFFECT_PARAMTERS) {
2134 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2135 if(!target)
2136 return 0;
2137 auto hprovs = ws.world.nation_get_province_ownership(target);
2138 if(hprovs.begin() == hprovs.end()) {
2139 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2140 if(powner)
2141 nations::create_nation_based_on_template(ws, target, powner);
2142 }
2144 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2145 return 0;
2146}
2147uint32_t ef_secede_province_state_this_pop(EFFECT_PARAMTERS) {
2148 auto target = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2149 if(!target)
2150 return 0;
2151 auto hprovs = ws.world.nation_get_province_ownership(target);
2152 if(hprovs.begin() == hprovs.end()) {
2153 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2154 if(powner)
2155 nations::create_nation_based_on_template(ws, target, powner);
2156 }
2158 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2159 return 0;
2160}
2161uint32_t ef_secede_province_state_from_nation(EFFECT_PARAMTERS) {
2162 return ef_secede_province_state_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2163}
2164uint32_t ef_secede_province_state_from_province(EFFECT_PARAMTERS) {
2165 return ef_secede_province_state_this_province(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2166}
2167uint32_t ef_secede_province_state_reb(EFFECT_PARAMTERS) {
2168 auto target = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
2169 auto holder = ws.world.national_identity_get_nation_from_identity_holder(target);
2170 if(!holder)
2171 return 0;
2172 auto hprovs = ws.world.nation_get_province_ownership(holder);
2173 if(hprovs.begin() == hprovs.end()) {
2174 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2175 if(powner)
2176 nations::create_nation_based_on_template(ws, holder, powner);
2177 }
2179 [&](dcon::province_id p) { province::change_province_owner(ws, p, holder); });
2180 return 0;
2181}
2182
2183uint32_t ef_secede_province_this_nation(EFFECT_PARAMTERS) {
2184 auto target = trigger::to_nation(this_slot);
2185 auto hprovs = ws.world.nation_get_province_ownership(target);
2186 if(hprovs.begin() == hprovs.end()) {
2187 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2188 if(powner)
2189 nations::create_nation_based_on_template(ws, target, powner);
2190 }
2191 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2192 return 0;
2193}
2194uint32_t ef_secede_province_this_state(EFFECT_PARAMTERS) {
2195 auto target = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2196 if(!target)
2197 return 0;
2198 auto hprovs = ws.world.nation_get_province_ownership(target);
2199 if(hprovs.begin() == hprovs.end()) {
2200 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2201 if(powner)
2202 nations::create_nation_based_on_template(ws, target, powner);
2203 }
2204 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2205 return 0;
2206}
2207uint32_t ef_secede_province_this_province(EFFECT_PARAMTERS) {
2208 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2209 if(!target)
2210 return 0;
2211 auto hprovs = ws.world.nation_get_province_ownership(target);
2212 if(hprovs.begin() == hprovs.end()) {
2213 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2214 if(powner)
2215 nations::create_nation_based_on_template(ws, target, powner);
2216 }
2217 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2218 return 0;
2219}
2220uint32_t ef_secede_province_this_pop(EFFECT_PARAMTERS) {
2221 auto target = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2222 if(!target)
2223 return 0;
2224 auto hprovs = ws.world.nation_get_province_ownership(target);
2225 if(hprovs.begin() == hprovs.end()) {
2226 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2227 if(powner)
2228 nations::create_nation_based_on_template(ws, target, powner);
2229 }
2230 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2231 return 0;
2232}
2233uint32_t ef_secede_province_from_nation(EFFECT_PARAMTERS) {
2234 return ef_secede_province_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2235}
2236uint32_t ef_secede_province_from_province(EFFECT_PARAMTERS) {
2237 return ef_secede_province_this_province(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2238}
2239uint32_t ef_secede_province_reb(EFFECT_PARAMTERS) {
2240 auto target = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
2241 auto holder = ws.world.national_identity_get_nation_from_identity_holder(target);
2242 if(!holder)
2243 return 0;
2244 auto hprovs = ws.world.nation_get_province_ownership(holder);
2245 if(hprovs.begin() == hprovs.end()) {
2246 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2247 if(powner)
2248 nations::create_nation_based_on_template(ws, holder, powner);
2249 }
2250 province::change_province_owner(ws, trigger::to_prov(primary_slot), holder);
2251 return 0;
2252}
2254 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2255 if(!holder || holder == trigger::to_nation(primary_slot))
2256 return 0;
2257 auto hprovs = ws.world.nation_get_province_ownership(holder);
2258 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2259 if(sprovs.begin() == sprovs.end()) {
2261 }
2262 while(hprovs.begin() != hprovs.end()) {
2263 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2264 }
2265 return 0;
2266}
2267uint32_t ef_inherit_this_nation(EFFECT_PARAMTERS) {
2268 auto holder = trigger::to_nation(this_slot);
2269 if(holder == trigger::to_nation(primary_slot))
2270 return 0;
2271 auto hprovs = ws.world.nation_get_province_ownership(holder);
2272 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2273 if(sprovs.begin() == sprovs.end()) {
2275 }
2276 while(hprovs.begin() != hprovs.end()) {
2277 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2278 }
2279 return 0;
2280}
2281uint32_t ef_inherit_this_state(EFFECT_PARAMTERS) {
2282 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2283 if(!holder || holder == trigger::to_nation(primary_slot))
2284 return 0;
2285 auto hprovs = ws.world.nation_get_province_ownership(holder);
2286 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2287 if(sprovs.begin() == sprovs.end()) {
2289 }
2290 while(hprovs.begin() != hprovs.end()) {
2291 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2292 }
2293 return 0;
2294}
2295uint32_t ef_inherit_this_province(EFFECT_PARAMTERS) {
2296 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2297 if(!holder || holder == trigger::to_nation(primary_slot))
2298 return 0;
2299 auto hprovs = ws.world.nation_get_province_ownership(holder);
2300 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2301 if(sprovs.begin() == sprovs.end()) {
2303 }
2304 while(hprovs.begin() != hprovs.end()) {
2305 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2306 }
2307 return 0;
2308}
2309uint32_t ef_inherit_this_pop(EFFECT_PARAMTERS) {
2310 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2311 if(!holder || holder == trigger::to_nation(primary_slot))
2312 return 0;
2313 auto hprovs = ws.world.nation_get_province_ownership(holder);
2314 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2315 if(sprovs.begin() == sprovs.end()) {
2317 }
2318 while(hprovs.begin() != hprovs.end()) {
2319 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2320 }
2321 return 0;
2322}
2323uint32_t ef_inherit_from_nation(EFFECT_PARAMTERS) {
2324 auto holder = trigger::to_nation(from_slot);
2325 if(holder == trigger::to_nation(primary_slot))
2326 return 0;
2327 auto hprovs = ws.world.nation_get_province_ownership(holder);
2328 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2329 if(sprovs.begin() == sprovs.end()) {
2331 }
2332 while(hprovs.begin() != hprovs.end()) {
2333 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2334 }
2335 return 0;
2336}
2337uint32_t ef_inherit_from_province(EFFECT_PARAMTERS) {
2338 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2339 if(!holder || holder == trigger::to_nation(primary_slot))
2340 return 0;
2341 auto hprovs = ws.world.nation_get_province_ownership(holder);
2342 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2343 if(sprovs.begin() == sprovs.end()) {
2345 }
2346 while(hprovs.begin() != hprovs.end()) {
2347 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2348 }
2349 return 0;
2350}
2352 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2353 if(!holder || holder == trigger::to_nation(primary_slot))
2354 return 0;
2355 auto hprovs = ws.world.nation_get_province_ownership(holder);
2356 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2357 if(hprovs.begin() == hprovs.end()) {
2359 }
2360 while(sprovs.begin() != sprovs.end()) {
2361 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2362 }
2363 return 0;
2364}
2365uint32_t ef_annex_to_this_nation(EFFECT_PARAMTERS) {
2366 auto holder = trigger::to_nation(this_slot);
2367 if(holder == trigger::to_nation(primary_slot))
2368 return 0;
2369 auto hprovs = ws.world.nation_get_province_ownership(holder);
2370 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2371 if(hprovs.begin() == hprovs.end()) {
2373 }
2374 while(sprovs.begin() != sprovs.end()) {
2375 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2376 }
2377 return 0;
2378}
2379uint32_t ef_annex_to_this_state(EFFECT_PARAMTERS) {
2380 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2381 if(!holder || holder == trigger::to_nation(primary_slot))
2382 return 0;
2383 auto hprovs = ws.world.nation_get_province_ownership(holder);
2384 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2385 if(hprovs.begin() == hprovs.end()) {
2387 }
2388 while(sprovs.begin() != sprovs.end()) {
2389 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2390 }
2391 return 0;
2392}
2393uint32_t ef_annex_to_this_province(EFFECT_PARAMTERS) {
2394 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2395 if(!holder || holder == trigger::to_nation(primary_slot))
2396 return 0;
2397 auto hprovs = ws.world.nation_get_province_ownership(holder);
2398 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2399 if(hprovs.begin() == hprovs.end()) {
2401 }
2402 while(sprovs.begin() != sprovs.end()) {
2403 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2404 }
2405 return 0;
2406}
2407uint32_t ef_annex_to_this_pop(EFFECT_PARAMTERS) {
2408 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2409 if(!holder || holder == trigger::to_nation(primary_slot))
2410 return 0;
2411 auto hprovs = ws.world.nation_get_province_ownership(holder);
2412 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2413 if(hprovs.begin() == hprovs.end()) {
2415 }
2416 while(sprovs.begin() != sprovs.end()) {
2417 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2418 }
2419 return 0;
2420}
2421uint32_t ef_annex_to_from_nation(EFFECT_PARAMTERS) {
2422 auto holder = trigger::to_nation(from_slot);
2423 if(holder == trigger::to_nation(primary_slot))
2424 return 0;
2425 auto hprovs = ws.world.nation_get_province_ownership(holder);
2426 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2427 if(hprovs.begin() == hprovs.end()) {
2429 }
2430 while(sprovs.begin() != sprovs.end()) {
2431 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2432 }
2433 return 0;
2434}
2435uint32_t ef_annex_to_from_province(EFFECT_PARAMTERS) {
2436 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2437 if(!holder || holder == trigger::to_nation(primary_slot))
2438 return 0;
2439 auto hprovs = ws.world.nation_get_province_ownership(holder);
2440 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2441 if(hprovs.begin() == hprovs.end()) {
2443 }
2444 while(sprovs.begin() != sprovs.end()) {
2445 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2446 }
2447 return 0;
2448}
2450 nations::liberate_nation_from(ws, trigger::payload(tval[1]).tag_id, trigger::to_nation(primary_slot));
2451 return 0;
2452}
2453uint32_t ef_release_this_nation(EFFECT_PARAMTERS) {
2454 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot)),
2455 trigger::to_nation(primary_slot));
2456 return 0;
2457}
2458uint32_t ef_release_this_state(EFFECT_PARAMTERS) {
2459 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2460 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2461}
2462uint32_t ef_release_this_province(EFFECT_PARAMTERS) {
2463 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2464 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2465}
2466uint32_t ef_release_this_pop(EFFECT_PARAMTERS) {
2467 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2468 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2469}
2470uint32_t ef_release_from_nation(EFFECT_PARAMTERS) {
2471 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(from_slot)),
2472 trigger::to_nation(primary_slot));
2473 return 0;
2474}
2475uint32_t ef_release_from_province(EFFECT_PARAMTERS) {
2476 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2477 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2478}
2479uint32_t ef_change_controller(EFFECT_PARAMTERS) {
2480 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2481 if(holder) {
2482 province::set_province_controller(ws, trigger::to_prov(primary_slot), holder);
2483 military::eject_ships(ws, trigger::to_prov(primary_slot));
2484 }
2485 return 0;
2486}
2487uint32_t ef_change_controller_this_nation(EFFECT_PARAMTERS) {
2489 military::eject_ships(ws, trigger::to_prov(primary_slot));
2490 return 0;
2491}
2492uint32_t ef_change_controller_this_province(EFFECT_PARAMTERS) {
2493 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2494 if(owner) {
2495 province::set_province_controller(ws, trigger::to_prov(primary_slot), owner);
2496 military::eject_ships(ws, trigger::to_prov(primary_slot));
2497 }
2498 return 0;
2499}
2500uint32_t ef_change_controller_from_nation(EFFECT_PARAMTERS) {
2502 military::eject_ships(ws, trigger::to_prov(primary_slot));
2503 return 0;
2504}
2505uint32_t ef_change_controller_from_province(EFFECT_PARAMTERS) {
2506 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2507 if(owner) {
2508 province::set_province_controller(ws, trigger::to_prov(primary_slot), owner);
2509 military::eject_ships(ws, trigger::to_prov(primary_slot));
2510 }
2511 return 0;
2512}
2513uint32_t ef_change_controller_state(EFFECT_PARAMTERS) {
2514 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2515 if(holder) {
2516 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2517 province::set_province_controller(ws, p, holder);
2518 military::eject_ships(ws, p);
2519 });
2520 }
2521 return 0;
2522}
2523uint32_t ef_change_controller_state_this_nation(EFFECT_PARAMTERS) {
2524 auto holder = trigger::to_nation(this_slot);
2525 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2526 province::set_province_controller(ws, p, holder);
2527 military::eject_ships(ws, p);
2528 });
2529 return 0;
2530}
2531uint32_t ef_change_controller_state_this_province(EFFECT_PARAMTERS) {
2532 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2533 if(holder) {
2534 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2535 province::set_province_controller(ws, p, holder);
2536 military::eject_ships(ws, p);
2537 });
2538 }
2539 return 0;
2540}
2541uint32_t ef_change_controller_state_from_nation(EFFECT_PARAMTERS) {
2542 auto holder = trigger::to_nation(from_slot);
2543 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2544 province::set_province_controller(ws, p, holder);
2545 military::eject_ships(ws, p);
2546 });
2547 return 0;
2548}
2549uint32_t ef_change_controller_state_from_province(EFFECT_PARAMTERS) {
2550 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2551 if(holder) {
2552 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2553 province::set_province_controller(ws, p, holder);
2554 military::eject_ships(ws, p);
2555 });
2556 }
2557 return 0;
2558}
2559uint32_t ef_infrastructure(EFFECT_PARAMTERS) {
2560 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::railroad));
2561 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value),
2562 0,
2563 int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)), uint8_t(economy::province_building_type::railroad)))));
2564 ws.railroad_built.store(true, std::memory_order::release);
2565 return 0;
2566}
2568 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
2569 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad));
2570 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value),
2571 0,
2572 int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(p), uint8_t(economy::province_building_type::railroad)))));
2573 });
2574 ws.railroad_built.store(true, std::memory_order::release);
2575 return 0;
2576}
2577
2579 auto& m = ws.world.pop_get_savings(trigger::to_pop(primary_slot));
2580 auto amount = trigger::read_float_from_payload(tval + 1);
2581 assert(std::isfinite(amount));
2582 m = std::max(0.0f, m + amount);
2583 return 0;
2584}
2586 ws.world.nation_get_leadership_points(trigger::to_nation(primary_slot)) += float(trigger::payload(tval[1]).signed_value);
2587 return 0;
2588}
2589uint32_t ef_create_vassal(EFFECT_PARAMTERS) {
2590 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2591 if(!holder)
2592 return 0;
2593 nations::make_vassal(ws, holder, trigger::to_nation(primary_slot));
2594 return 0;
2595}
2596uint32_t ef_create_vassal_this_nation(EFFECT_PARAMTERS) {
2597 nations::make_vassal(ws, trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2598 return 0;
2599}
2600uint32_t ef_create_vassal_this_province(EFFECT_PARAMTERS) {
2601 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2602 if(!holder)
2603 return 0;
2604 nations::make_vassal(ws, holder, trigger::to_nation(primary_slot));
2605 return 0;
2606}
2607uint32_t ef_create_vassal_from_nation(EFFECT_PARAMTERS) {
2608 nations::make_vassal(ws, trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2609 return 0;
2610}
2611uint32_t ef_create_vassal_from_province(EFFECT_PARAMTERS) {
2612 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2613 if(!holder)
2614 return 0;
2615 nations::make_vassal(ws, holder, trigger::to_nation(primary_slot));
2616 return 0;
2617}
2618uint32_t ef_end_military_access(EFFECT_PARAMTERS) {
2619 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2620 if(target)
2621 military::remove_military_access(ws, trigger::to_nation(primary_slot), target);
2622 return 0;
2623}
2624uint32_t ef_end_military_access_this_nation(EFFECT_PARAMTERS) {
2626 return 0;
2627}
2628uint32_t ef_end_military_access_this_province(EFFECT_PARAMTERS) {
2629 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2630 if(target)
2631 military::remove_military_access(ws, trigger::to_nation(primary_slot), target);
2632 return 0;
2633}
2634uint32_t ef_end_military_access_from_nation(EFFECT_PARAMTERS) {
2636 return 0;
2637}
2638uint32_t ef_end_military_access_from_province(EFFECT_PARAMTERS) {
2639 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2640 if(target)
2641 military::remove_military_access(ws, trigger::to_nation(primary_slot), target);
2642 return 0;
2643}
2644uint32_t ef_leave_alliance(EFFECT_PARAMTERS) {
2645 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2646 nations::break_alliance(ws, holder, trigger::to_nation(primary_slot));
2647 return 0;
2648}
2649uint32_t ef_leave_alliance_this_nation(EFFECT_PARAMTERS) {
2650 nations::break_alliance(ws, trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2651 return 0;
2652}
2653uint32_t ef_leave_alliance_this_province(EFFECT_PARAMTERS) {
2654 nations::break_alliance(ws, ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)),
2655 trigger::to_nation(primary_slot));
2656 return 0;
2657}
2658uint32_t ef_leave_alliance_from_nation(EFFECT_PARAMTERS) {
2659 nations::break_alliance(ws, trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2660 return 0;
2661}
2662uint32_t ef_leave_alliance_from_province(EFFECT_PARAMTERS) {
2663 nations::break_alliance(ws, ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)),
2664 trigger::to_nation(primary_slot));
2665 return 0;
2666}
2668 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2669 military::end_wars_between(ws, trigger::to_nation(primary_slot), target);
2670 return 0;
2671}
2672uint32_t ef_end_war_this_nation(EFFECT_PARAMTERS) {
2674 return 0;
2675}
2676uint32_t ef_end_war_this_province(EFFECT_PARAMTERS) {
2677 military::end_wars_between(ws, trigger::to_nation(primary_slot), ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)));
2678 return 0;
2679}
2680uint32_t ef_end_war_from_nation(EFFECT_PARAMTERS) {
2682 return 0;
2683}
2684uint32_t ef_end_war_from_province(EFFECT_PARAMTERS) {
2685 military::end_wars_between(ws, trigger::to_nation(primary_slot), ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)));
2686 return 0;
2687}
2688uint32_t ef_enable_ideology(EFFECT_PARAMTERS) {
2689 ws.world.ideology_set_enabled(trigger::payload(tval[1]).ideo_id, true);
2690 return 0;
2691}
2692uint32_t ef_ruling_party_ideology(EFFECT_PARAMTERS) {
2694 return 0;
2695}
2697 auto& plur = ws.world.nation_get_plurality(trigger::to_nation(primary_slot));
2698 auto amount = trigger::read_float_from_payload(tval + 1);
2699 assert(std::isfinite(amount));
2700 plur = std::clamp(plur + amount, 0.0f, 100.0f);
2701 return 0;
2702}
2703uint32_t ef_remove_province_modifier(EFFECT_PARAMTERS) {
2704 sys::remove_modifier_from_province(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).mod_id);
2705 return 0;
2706}
2708 auto mod = trigger::payload(tval[1]).mod_id;
2709 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
2711 });
2712 return 0;
2713}
2714uint32_t ef_remove_country_modifier(EFFECT_PARAMTERS) {
2715 sys::remove_modifier_from_nation(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id);
2716 return 0;
2717}
2718uint32_t ef_create_alliance(EFFECT_PARAMTERS) {
2719 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2720 if(holder && ws.world.nation_get_owned_province_count(holder) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2721 nations::make_alliance(ws, holder, trigger::to_nation(primary_slot));
2722 return 0;
2723}
2724uint32_t ef_create_alliance_this_nation(EFFECT_PARAMTERS) {
2725 if(ws.world.nation_get_owned_province_count(trigger::to_nation(this_slot)) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2726 nations::make_alliance(ws, trigger::to_nation(primary_slot), trigger::to_nation(this_slot));
2727 return 0;
2728}
2729uint32_t ef_create_alliance_this_province(EFFECT_PARAMTERS) {
2730 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2731 if(owner && ws.world.nation_get_owned_province_count(owner) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2732 nations::make_alliance(ws, trigger::to_nation(primary_slot), owner);
2733 return 0;
2734}
2735uint32_t ef_create_alliance_from_nation(EFFECT_PARAMTERS) {
2736 if(ws.world.nation_get_owned_province_count(trigger::to_nation(from_slot)) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2737 nations::make_alliance(ws, trigger::to_nation(primary_slot), trigger::to_nation(from_slot));
2738 return 0;
2739}
2740uint32_t ef_create_alliance_from_province(EFFECT_PARAMTERS) {
2741 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2742 if(owner && ws.world.nation_get_owned_province_count(owner) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2743 nations::make_alliance(ws, trigger::to_nation(primary_slot), owner);
2744 return 0;
2745}
2746uint32_t ef_release_vassal(EFFECT_PARAMTERS) {
2747 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2748 if(!holder)
2749 return 0;
2750 auto hprovs = ws.world.nation_get_province_ownership(holder);
2751 if(hprovs.begin() == hprovs.end()) {
2752 nations::liberate_nation_from(ws, trigger::payload(tval[1]).tag_id, trigger::to_nation(primary_slot));
2753 if(ws.world.nation_get_owned_province_count(holder) == 0)
2754 return 0;
2755 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2756 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2757 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2758 auto& flags = ws.world.gp_relationship_get_status(sr);
2760 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2761 }
2762 } else {
2763 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2764 if(rel) {
2765 nations::release_vassal(ws, rel);
2766 }
2767 }
2768 return 0;
2769}
2770uint32_t ef_release_vassal_this_nation(EFFECT_PARAMTERS) {
2771 auto hprovs = ws.world.nation_get_province_ownership(trigger::to_nation(this_slot));
2772 if(hprovs.begin() == hprovs.end()) {
2773 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot)),
2774 trigger::to_nation(primary_slot));
2775 if(ws.world.nation_get_owned_province_count(trigger::to_nation(this_slot)) == 0)
2776 return 0;
2777 ws.world.force_create_overlord(trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2778 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2779 auto sr = ws.world.force_create_gp_relationship(trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2780 auto& flags = ws.world.gp_relationship_get_status(sr);
2782 ws.world.nation_set_in_sphere_of(trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2783 }
2784 } else {
2785 auto rel = ws.world.nation_get_overlord_as_subject(trigger::to_nation(this_slot));
2786 if(rel) {
2787 nations::release_vassal(ws, rel);
2788 }
2789 }
2790 return 0;
2791}
2792uint32_t ef_release_vassal_this_province(EFFECT_PARAMTERS) {
2793 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2794 if(!holder)
2795 return 0;
2796 auto hprovs = ws.world.nation_get_province_ownership(holder);
2797 if(hprovs.begin() == hprovs.end()) {
2798 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(holder),
2799 trigger::to_nation(primary_slot));
2800 if(ws.world.nation_get_owned_province_count(holder) == 0)
2801 return 0;
2802 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2803 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2804 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2805 auto& flags = ws.world.gp_relationship_get_status(sr);
2807 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2808 }
2809 } else {
2810 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2811 if(rel) {
2812 nations::release_vassal(ws, rel);
2813 }
2814 }
2815 return 0;
2816}
2817uint32_t ef_release_vassal_from_nation(EFFECT_PARAMTERS) {
2818 auto hprovs = ws.world.nation_get_province_ownership(trigger::to_nation(from_slot));
2819 if(hprovs.begin() == hprovs.end()) {
2820 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot)),
2821 trigger::to_nation(primary_slot));
2822 if(ws.world.nation_get_owned_province_count(trigger::to_nation(from_slot)) == 0)
2823 return 0;
2824 ws.world.force_create_overlord(trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2825 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2826 auto sr = ws.world.force_create_gp_relationship(trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2827 auto& flags = ws.world.gp_relationship_get_status(sr);
2829 ws.world.nation_set_in_sphere_of(trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2830 }
2831 } else {
2832 auto rel = ws.world.nation_get_overlord_as_subject(trigger::to_nation(from_slot));
2833 if(rel) {
2834 nations::release_vassal(ws, rel);
2835 }
2836 }
2837 return 0;
2838}
2839uint32_t ef_release_vassal_from_province(EFFECT_PARAMTERS) {
2840 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2841 if(!holder)
2842 return 0;
2843 auto hprovs = ws.world.nation_get_province_ownership(holder);
2844 if(hprovs.begin() == hprovs.end()) {
2845 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(holder),
2846 trigger::to_nation(primary_slot));
2847 if(ws.world.nation_get_owned_province_count(holder) == 0)
2848 return 0;
2849 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2850 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2851 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2852 auto& flags = ws.world.gp_relationship_get_status(sr);
2854 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2855 }
2856 } else {
2857 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2858 if(rel) {
2859 nations::release_vassal(ws, rel);
2860 }
2861 }
2862 return 0;
2863}
2864uint32_t ef_release_vassal_reb(EFFECT_PARAMTERS) {
2865 auto itag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
2866 auto holder = ws.world.national_identity_get_nation_from_identity_holder(itag);
2867 if(!holder)
2868 return 0;
2869 auto hprovs = ws.world.nation_get_province_ownership(holder);
2870 if(hprovs.begin() == hprovs.end()) {
2871 nations::liberate_nation_from(ws, itag, trigger::to_nation(primary_slot));
2872 if(ws.world.nation_get_owned_province_count(holder) == 0)
2873 return 0;
2874 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2875 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2876 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2877 auto& flags = ws.world.gp_relationship_get_status(sr);
2879 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2880 }
2881 } else {
2882 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2883 if(rel) {
2884 nations::release_vassal(ws, rel);
2885 }
2886 }
2887 return 0;
2888}
2889uint32_t ef_release_vassal_random(EFFECT_PARAMTERS) {
2890 // unused
2891 return 0;
2892}
2894 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2895 if(owner)
2896 return ef_release_vassal(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2897 else
2898 return 0;
2899}
2901 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2902 if(owner)
2903 return ef_release_vassal_this_nation(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2904 else
2905 return 0;
2906}
2908 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2909 if(owner)
2910 return ef_release_vassal_this_province(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2911 else
2912 return 0;
2913}
2915 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2916 if(owner)
2917 return ef_release_vassal_from_nation(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2918 else
2919 return 0;
2920}
2922 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2923 if(owner)
2924 return ef_release_vassal_from_province(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2925 else
2926 return 0;
2927}
2929 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2930 if(owner)
2931 return ef_release_vassal_reb(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2932 else
2933 return 0;
2934}
2936 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2937 if(owner)
2938 return ef_release_vassal_random(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2939 else
2940 return 0;
2941}
2942uint32_t ef_change_province_name(EFFECT_PARAMTERS) {
2943 dcon::text_key name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
2944 ws.world.province_set_name(trigger::to_prov(primary_slot), name);
2945 return 0;
2946}
2947uint32_t ef_enable_canal(EFFECT_PARAMTERS) {
2948 province::enable_canal(ws, tval[1] - 1);
2949 return 0;
2950}
2951uint32_t ef_set_global_flag(EFFECT_PARAMTERS) {
2952 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, true);
2953 return 0;
2954}
2955uint32_t ef_clr_global_flag(EFFECT_PARAMTERS) {
2956 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
2957 return 0;
2958}
2959uint32_t ef_nationalvalue_province(EFFECT_PARAMTERS) {
2960 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2961 if(owner)
2962 ws.world.nation_set_national_value(owner, trigger::payload(tval[1]).mod_id);
2963 return 0;
2964}
2965uint32_t ef_nationalvalue_nation(EFFECT_PARAMTERS) {
2966 ws.world.nation_set_national_value(trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id);
2967 return 0;
2968}
2969uint32_t ef_civilized_yes(EFFECT_PARAMTERS) {
2971 return 0;
2972}
2973uint32_t ef_civilized_no(EFFECT_PARAMTERS) {
2975 return 0;
2976}
2977uint32_t ef_is_slave_state_no(EFFECT_PARAMTERS) {
2978 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
2979 ws.world.province_set_is_slave(p, false);
2980 bool mine = ws.world.commodity_get_is_mine(ws.world.province_get_rgo(p));
2981 for(auto pop : ws.world.province_get_pop_location(p)) {
2982 if(pop.get_pop().get_poptype() == ws.culture_definitions.slaves) {
2983 pop.get_pop().set_poptype(mine ? ws.culture_definitions.laborers : ws.culture_definitions.farmers);
2984 }
2985 }
2986 });
2987 return 0;
2988}
2989uint32_t ef_is_slave_pop_no(EFFECT_PARAMTERS) {
2990 if(ws.world.pop_get_poptype(trigger::to_pop(primary_slot)) == ws.culture_definitions.slaves) {
2991 bool mine = ws.world.commodity_get_is_mine(
2992 ws.world.province_get_rgo(ws.world.pop_get_province_from_pop_location(trigger::to_pop(primary_slot))));
2993 ws.world.pop_set_poptype(trigger::to_pop(primary_slot),
2994 mine ? ws.culture_definitions.laborers : ws.culture_definitions.farmers);
2995 }
2996 return 0;
2997}
2999 auto p = trigger::to_prov(primary_slot);
3000 ws.world.province_set_is_slave(p, false);
3001 bool mine = ws.world.commodity_get_is_mine(ws.world.province_get_rgo(p));
3002 for(auto pop : ws.world.province_get_pop_location(p)) {
3003 if(pop.get_pop().get_poptype() == ws.culture_definitions.slaves) {
3004 pop.get_pop().set_poptype(mine ? ws.culture_definitions.laborers : ws.culture_definitions.farmers);
3005 }
3006 }
3007 return 0;
3008}
3011 return 0;
3012}
3013uint32_t ef_social_reform(EFFECT_PARAMTERS) {
3014 auto opt = trigger::payload(tval[1]).opt_id;
3015 politics::set_issue_option(ws, trigger::to_nation(primary_slot), opt);
3018 return 0;
3019}
3021 auto opt = trigger::payload(tval[1]).opt_id;
3022 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
3023 if(owner) {
3024 politics::set_issue_option(ws, owner, opt);
3027 }
3028 return 0;
3029}
3030uint32_t ef_political_reform(EFFECT_PARAMTERS) {
3031 auto opt = trigger::payload(tval[1]).opt_id;
3032 politics::set_issue_option(ws, trigger::to_nation(primary_slot), opt);
3035 return 0;
3036}
3038 auto opt = trigger::payload(tval[1]).opt_id;
3039 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
3040 if(owner) {
3041 politics::set_issue_option(ws, owner, opt);
3044 }
3045 return 0;
3046}
3047uint32_t ef_add_tax_relative_income(EFFECT_PARAMTERS) {
3048 auto income = ws.world.nation_get_total_poor_income(trigger::to_nation(primary_slot)) +
3049 ws.world.nation_get_total_middle_income(trigger::to_nation(primary_slot)) +
3050 ws.world.nation_get_total_rich_income(trigger::to_nation(primary_slot));
3051 auto amount = trigger::read_float_from_payload(tval + 1);
3052 assert(std::isfinite(amount));
3053 auto combined_amount = income * amount;
3054 assert(std::isfinite(combined_amount));
3055 auto& v = ws.world.nation_get_stockpiles(trigger::to_nation(primary_slot), economy::money);
3056
3057 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
3058 v = v + combined_amount;
3059 else
3060 v = std::max(v + combined_amount, 0.0f); // temporary measure since there is no debt
3061 return 0;
3062}
3065 return 0;
3066}
3068 auto amount = trigger::read_float_from_payload(tval + 1);
3069 assert(std::isfinite(amount));
3070 ws.world.pop_get_size(trigger::to_pop(primary_slot)) *= amount;
3071 return 0;
3072}
3073uint32_t ef_reduce_pop_abs(EFFECT_PARAMTERS) {
3074 auto amount = trigger::read_int32_t_from_payload(tval + 1);
3075
3076 demographics::reduce_pop_size_safe(ws, trigger::to_pop(primary_slot), amount);
3077 return 0;
3078}
3080 auto amount = trigger::read_float_from_payload(tval + 1);
3081 assert(std::isfinite(amount));
3082 for(auto p : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3083 p.get_pop().get_size() *= amount;
3084 }
3085 return 0;
3086}
3088 auto amount = trigger::read_float_from_payload(tval + 1);
3089 assert(std::isfinite(amount));
3090 for(auto pr : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
3091 for(auto p : pr.get_province().get_pop_location()) {
3092 p.get_pop().get_size() *= amount;
3093 }
3094 }
3095 return 0;
3096}
3098 auto amount = trigger::read_float_from_payload(tval + 1);
3099 assert(std::isfinite(amount));
3100 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, amount](dcon::province_id pr) {
3101 for(auto p : ws.world.province_get_pop_location(pr)) {
3102 p.get_pop().get_size() *= amount;
3103 }
3104 });
3105 return 0;
3106}
3108 ws.world.pop_set_province_from_pop_location(trigger::to_pop(primary_slot), trigger::payload(tval[1]).prov_id);
3109 return 0;
3110}
3112 ws.world.pop_set_poptype(trigger::to_pop(primary_slot), trigger::payload(tval[1]).popt_id);
3113 return 0;
3114}
3115uint32_t ef_years_of_research(EFFECT_PARAMTERS) {
3116 auto& rp = ws.world.nation_get_research_points(trigger::to_nation(primary_slot));
3117 auto amount = trigger::read_float_from_payload(tval + 1);
3118 assert(std::isfinite(amount));
3119 rp += nations::daily_research_points(ws, trigger::to_nation(primary_slot)) * 365.0f * amount;
3120 return 0;
3121}
3122uint32_t ef_prestige_factor_positive(EFFECT_PARAMTERS) {
3123 auto& bp = ws.world.nation_get_prestige(trigger::to_nation(primary_slot));
3124 auto score = nations::prestige_score(ws, trigger::to_nation(primary_slot));
3125 auto amount = trigger::read_float_from_payload(tval + 1);
3126 assert(std::isfinite(amount));
3127
3128 bp += (score) *
3129 (ws.world.nation_get_modifier_values(trigger::to_nation(primary_slot), sys::national_mod_offsets::prestige) + 1.0f) *
3130 amount;
3131 return 0;
3132}
3133uint32_t ef_prestige_factor_negative(EFFECT_PARAMTERS) {
3134 auto& bp = ws.world.nation_get_prestige(trigger::to_nation(primary_slot));
3135 auto score = nations::prestige_score(ws, trigger::to_nation(primary_slot));
3136 auto amount = trigger::read_float_from_payload(tval + 1);
3137 assert(std::isfinite(amount));
3138
3139 bp = std::max(0.0f, bp + (score)*amount);
3140 return 0;
3141}
3142uint32_t ef_military_reform(EFFECT_PARAMTERS) {
3143 auto opt = trigger::payload(tval[1]).ropt_id;
3144 politics::set_reform_option(ws, trigger::to_nation(primary_slot), opt);
3147 return 0;
3148}
3149uint32_t ef_economic_reform(EFFECT_PARAMTERS) {
3150 auto opt = trigger::payload(tval[1]).ropt_id;
3151 politics::set_reform_option(ws, trigger::to_nation(primary_slot), opt);
3154 return 0;
3155}
3156uint32_t ef_remove_random_military_reforms(EFFECT_PARAMTERS) {
3157 std::vector<dcon::reform_option_id> active_reforms;
3158 auto nation_id = trigger::to_nation(primary_slot);
3159 for(auto issue : ws.world.in_reform) {
3160 if(issue.get_reform_type() == uint8_t(culture::issue_type::military) &&
3161 ws.world.nation_get_reforms(nation_id, issue) != ws.world.reform_get_options(issue)[0])
3162 active_reforms.push_back(ws.world.reform_get_options(issue)[0]);
3163 }
3164 for(int32_t i = tval[1] - 1; active_reforms.size() != 0 && i >= 0; --i) {
3165 auto r = rng::get_random(ws, r_hi, uint32_t(r_lo + i)) % active_reforms.size();
3166 politics::set_reform_option(ws, nation_id, active_reforms[r]);
3167 active_reforms[r] = active_reforms.back();
3168 active_reforms.pop_back();
3169 }
3172 return tval[1];
3173}
3174uint32_t ef_remove_random_economic_reforms(EFFECT_PARAMTERS) {
3175 std::vector<dcon::reform_option_id> active_reforms;
3176 auto nation_id = trigger::to_nation(primary_slot);
3177 for(auto issue : ws.world.in_reform) {
3178 if(issue.get_reform_type() == uint8_t(culture::issue_type::economic) &&
3179 ws.world.nation_get_reforms(nation_id, issue) != ws.world.reform_get_options(issue)[0])
3180 active_reforms.push_back(ws.world.reform_get_options(issue)[0]);
3181 }
3182 for(int32_t i = tval[1] - 1; active_reforms.size() != 0 && i >= 0; --i) {
3183 auto r = rng::get_random(ws, r_hi, uint32_t(r_lo + i)) % active_reforms.size();
3184 politics::set_reform_option(ws, nation_id, active_reforms[r]);
3185 active_reforms[r] = active_reforms.back();
3186 active_reforms.pop_back();
3187 }
3190 return tval[1];
3191}
3193 ws.world.province_set_crime(trigger::to_prov(primary_slot), trigger::payload(tval[1]).crm_id);
3194 return 0;
3195}
3196uint32_t ef_add_crime_none(EFFECT_PARAMTERS) {
3197 ws.world.province_set_crime(trigger::to_prov(primary_slot), dcon::crime_id{});
3198 return 0;
3199}
3202 return 0;
3203}
3204uint32_t ef_build_factory_in_capital_state(EFFECT_PARAMTERS) {
3205 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
3206 auto cs = ws.world.province_get_state_membership(c);
3207 if(!cs)
3208 return 0;
3209 economy::try_add_factory_to_state(ws, cs, trigger::payload(tval[1]).fac_id);
3210 return 0;
3211}
3212uint32_t ef_activate_technology(EFFECT_PARAMTERS) {
3213 if(ws.world.nation_get_active_technologies(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id) == false)
3214 culture::apply_technology(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id);
3215 return 0;
3216}
3217uint32_t ef_activate_invention(EFFECT_PARAMTERS) {
3218 if(ws.world.nation_get_active_inventions(trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id) == true)
3219 culture::apply_invention(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id);
3220 return 0;
3221}
3222uint32_t ef_great_wars_enabled_yes(EFFECT_PARAMTERS) {
3223 ws.military_definitions.great_wars_enabled = true;
3224 return 0;
3225}
3226uint32_t ef_great_wars_enabled_no(EFFECT_PARAMTERS) {
3227 ws.military_definitions.great_wars_enabled = false;
3228 return 0;
3229}
3230uint32_t ef_world_wars_enabled_yes(EFFECT_PARAMTERS) {
3231 ws.military_definitions.world_wars_enabled = true;
3232 return 0;
3233}
3234uint32_t ef_world_wars_enabled_no(EFFECT_PARAMTERS) {
3235 ws.military_definitions.world_wars_enabled = false;
3236 return 0;
3237}
3238uint32_t ef_assimilate_province(EFFECT_PARAMTERS) {
3239 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner) {
3240 auto owner_c = ws.world.nation_get_primary_culture(owner);
3241 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3242 pop.get_pop().set_culture(owner_c);
3243 pop.get_pop().set_is_primary_or_accepted_culture(true);
3244 }
3245 }
3246 return 0;
3247}
3248uint32_t ef_assimilate_state(EFFECT_PARAMTERS) {
3249 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot)); owner) {
3250 auto owner_c = ws.world.nation_get_primary_culture(owner);
3251 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3252 for(auto pop : ws.world.province_get_pop_location(p)) {
3253 pop.get_pop().set_culture(owner_c);
3254 pop.get_pop().set_is_primary_or_accepted_culture(true);
3255 }
3256 });
3257 }
3258 return 0;
3259}
3260uint32_t ef_assimilate_pop(EFFECT_PARAMTERS) {
3261 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot)); owner) {
3262 auto owner_c = ws.world.nation_get_primary_culture(owner);
3263 ws.world.pop_set_culture(trigger::to_pop(primary_slot), owner_c);
3264 ws.world.pop_set_is_primary_or_accepted_culture(trigger::to_pop(primary_slot), true);
3265 }
3266 return 0;
3267}
3268uint32_t ef_set_culture_pop(EFFECT_PARAMTERS) {
3269 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot)); owner) {
3270 auto c = trigger::payload(tval[1]).cul_id;
3271 ws.world.pop_set_culture(trigger::to_pop(primary_slot), c);
3272 ws.world.pop_set_is_primary_or_accepted_culture(trigger::to_pop(primary_slot), nations::nation_accepts_culture(ws, owner, c));
3273 }
3274 return 0;
3275}
3277 auto l = pop_demographics::get_literacy(ws, trigger::to_pop(primary_slot));
3278 auto amount = trigger::read_float_from_payload(tval + 1);
3279 assert(std::isfinite(amount));
3280 pop_demographics::set_literacy(ws, trigger::to_pop(primary_slot), std::clamp(l + amount, 0.0f, 1.0f));
3281 return 0;
3282}
3283uint32_t ef_add_crisis_interest(EFFECT_PARAMTERS) {
3284 if(ws.current_crisis != sys::crisis_type::none && ws.current_crisis_mode == sys::crisis_mode::heating_up) {
3285 for(auto& im : ws.crisis_participants) {
3286 if(im.id == trigger::to_nation(primary_slot)) {
3287 return 0;
3288 }
3289 if(!im.id) {
3290 im.id = trigger::to_nation(primary_slot);
3291 im.merely_interested = true;
3292 im.supports_attacker = false;
3293 return 0;
3294 }
3295 }
3296 }
3297 return 0;
3298}
3299uint32_t ef_flashpoint_tension(EFFECT_PARAMTERS) {
3300 auto& current_tension = ws.world.state_instance_get_flashpoint_tension(trigger::to_state(primary_slot));
3301 auto amount = trigger::read_float_from_payload(tval + 1);
3302 assert(std::isfinite(amount));
3303
3304 current_tension = std::clamp(current_tension + amount, 0.0f, 100.0f);
3305 return 0;
3306}
3308 auto state = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
3309 if(!state)
3310 return 0;
3311
3312 auto& current_tension = ws.world.state_instance_get_flashpoint_tension(state);
3313 auto amount = trigger::read_float_from_payload(tval + 1);
3314 assert(std::isfinite(amount));
3315
3316 current_tension = std::clamp(current_tension + amount, 0.0f, 100.0f);
3317 return 0;
3318}
3319uint32_t ef_add_crisis_temperature(EFFECT_PARAMTERS) {
3320 auto amount = trigger::read_float_from_payload(tval + 1);
3321 assert(std::isfinite(amount));
3322
3323 ws.crisis_temperature = std::clamp(ws.crisis_temperature + amount, 0.0f, 100.0f);
3324 return 0;
3325}
3326uint32_t ef_consciousness(EFFECT_PARAMTERS) {
3327 auto amount = trigger::read_float_from_payload(tval + 1);
3328 assert(std::isfinite(amount));
3329
3330 auto c = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
3331 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(c + amount, 0.0f, 10.0f));
3332 return 0;
3333}
3335 auto amount = trigger::read_float_from_payload(tval + 1);
3336 assert(std::isfinite(amount));
3337 for(auto p : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3338 auto c = pop_demographics::get_consciousness(ws, p.get_pop());
3339 pop_demographics::set_consciousness(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3340 }
3341 return 0;
3342}
3344 auto amount = trigger::read_float_from_payload(tval + 1);
3345 assert(std::isfinite(amount));
3346 for(auto pr : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
3347 for(auto p : pr.get_province().get_pop_location()) {
3348 auto c = pop_demographics::get_consciousness(ws, p.get_pop());
3349 pop_demographics::set_consciousness(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3350 }
3351 }
3352 return 0;
3353}
3355 auto amount = trigger::read_float_from_payload(tval + 1);
3356 assert(std::isfinite(amount));
3357 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, amount](dcon::province_id pr) {
3358 for(auto p : ws.world.province_get_pop_location(pr)) {
3359 auto c = pop_demographics::get_consciousness(ws, p.get_pop());
3360 pop_demographics::set_consciousness(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3361 }
3362 });
3363 return 0;
3364}
3366 auto amount = trigger::read_float_from_payload(tval + 1);
3367 assert(std::isfinite(amount));
3368
3369 auto c = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
3370 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(c + amount, 0.0f, 10.0f));
3371 return 0;
3372}
3374 auto amount = trigger::read_float_from_payload(tval + 1);
3375 assert(std::isfinite(amount));
3376 for(auto p : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3377 auto c = pop_demographics::get_militancy(ws, p.get_pop());
3378 pop_demographics::set_militancy(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3379 }
3380 return 0;
3381}
3383 auto amount = trigger::read_float_from_payload(tval + 1);
3384 assert(std::isfinite(amount));
3385 for(auto pr : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
3386 for(auto p : pr.get_province().get_pop_location()) {
3387 auto c = pop_demographics::get_militancy(ws, p.get_pop());
3388 pop_demographics::set_militancy(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3389 }
3390 }
3391 return 0;
3392}
3394 auto amount = trigger::read_float_from_payload(tval + 1);
3395 assert(std::isfinite(amount));
3396 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, amount](dcon::province_id pr) {
3397 for(auto p : ws.world.province_get_pop_location(pr)) {
3398 auto c = pop_demographics::get_militancy(ws, p.get_pop());
3399 pop_demographics::set_militancy(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3400 }
3401 });
3402 return 0;
3403}
3405 auto& s = ws.world.province_get_rgo_size(trigger::to_prov(primary_slot));
3406 s = std::max(s + float(trigger::payload(tval[1]).signed_value), 0.0f);
3407 return 0;
3408}
3410 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::fort));
3411 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value),
3412 0,
3413 int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)), uint8_t(economy::province_building_type::fort)))));
3414 return 0;
3415}
3417 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base));
3418 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)), uint8_t(economy::province_building_type::naval_base)))));
3419 if(building_level > 0) {
3420 auto si = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
3421 ws.world.state_instance_set_naval_base_is_taken(si, true);
3422 }
3423 return 0;
3424}
3426 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::bank));
3427 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)), uint8_t(economy::province_building_type::bank)))));
3428 return 0;
3429}
3431 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::university));
3432 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)), uint8_t(economy::province_building_type::university)))));
3433 return 0;
3434}
3436 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3437 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort));
3438 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(p), uint8_t(economy::province_building_type::fort)))));
3439 });
3440 return 0;
3441}
3443 uint32_t lvl = 0;
3444 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3445 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::naval_base));
3446 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(p), uint8_t(economy::province_building_type::naval_base)))));
3447 lvl = std::max<uint32_t>(lvl, building_level);
3448 });
3449 if(lvl > 0) {
3450 auto si = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
3451 ws.world.state_instance_set_naval_base_is_taken(si, true);
3452 }
3453 return 0;
3454}
3456 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3457 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::bank));
3458 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(p), uint8_t(economy::province_building_type::bank)))));
3459 });
3460 return 0;
3461}
3463 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3464 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::university));
3465 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value), 0, int32_t(ws.world.nation_get_max_building_level(ws.world.province_get_nation_from_province_ownership(p), uint8_t(economy::province_building_type::university)))));
3466 });
3467 return 0;
3468}
3469
3470uint32_t ef_trigger_revolt_nation(EFFECT_PARAMTERS) {
3471 rebel::trigger_revolt(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).reb_id, trigger::payload(tval[4]).ideo_id,
3472 trigger::payload(tval[2]).cul_id, trigger::payload(tval[3]).rel_id);
3473 return 0;
3474}
3475uint32_t ef_trigger_revolt_state(EFFECT_PARAMTERS) {
3476 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot)); owner)
3477 rebel::trigger_revolt(ws, owner, trigger::payload(tval[1]).reb_id, trigger::payload(tval[4]).ideo_id,
3478 trigger::payload(tval[2]).cul_id, trigger::payload(tval[3]).rel_id);
3479 return 0;
3480}
3481uint32_t ef_trigger_revolt_province(EFFECT_PARAMTERS) {
3482 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
3483 rebel::trigger_revolt(ws, owner, trigger::payload(tval[1]).reb_id, trigger::payload(tval[4]).ideo_id,
3484 trigger::payload(tval[2]).cul_id, trigger::payload(tval[3]).rel_id);
3485 return 0;
3486}
3487uint32_t ef_diplomatic_influence(EFFECT_PARAMTERS) {
3488 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id); holder)
3490 float(trigger::payload(tval[2]).signed_value));
3491 return 0;
3492}
3493uint32_t ef_diplomatic_influence_this_nation(EFFECT_PARAMTERS) {
3495 float(trigger::payload(tval[1]).signed_value));
3496 return 0;
3497}
3498uint32_t ef_diplomatic_influence_this_province(EFFECT_PARAMTERS) {
3499 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
3501 float(trigger::payload(tval[1]).signed_value));
3502 return 0;
3503}
3504uint32_t ef_diplomatic_influence_from_nation(EFFECT_PARAMTERS) {
3506 float(trigger::payload(tval[1]).signed_value));
3507 return 0;
3508}
3509uint32_t ef_diplomatic_influence_from_province(EFFECT_PARAMTERS) {
3510 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
3512 float(trigger::payload(tval[1]).signed_value));
3513 return 0;
3514}
3516 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id); holder)
3517 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), holder, float(trigger::payload(tval[2]).signed_value));
3518 return 0;
3519}
3520uint32_t ef_relation_this_nation(EFFECT_PARAMTERS) {
3522 float(trigger::payload(tval[1]).signed_value));
3523 return 0;
3524}
3525uint32_t ef_relation_this_province(EFFECT_PARAMTERS) {
3526 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
3527 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), owner, float(trigger::payload(tval[1]).signed_value));
3528 return 0;
3529}
3530uint32_t ef_relation_from_nation(EFFECT_PARAMTERS) {
3532 float(trigger::payload(tval[1]).signed_value));
3533 return 0;
3534}
3535uint32_t ef_relation_from_province(EFFECT_PARAMTERS) {
3536 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
3537 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), owner, float(trigger::payload(tval[1]).signed_value));
3538 return 0;
3539}
3540uint32_t ef_add_province_modifier(EFFECT_PARAMTERS) {
3541 sys::add_modifier_to_province(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).mod_id,
3542 ws.current_date + trigger::payload(tval[2]).signed_value);
3543 return 0;
3544}
3545uint32_t ef_add_province_modifier_no_duration(EFFECT_PARAMTERS) {
3546 sys::add_modifier_to_province(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).mod_id, sys::date{});
3547 return 0;
3548}
3550 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3551 sys::add_modifier_to_province(ws, p, trigger::payload(tval[1]).mod_id, ws.current_date + trigger::payload(tval[2]).signed_value);
3552 });
3553 return 0;
3554}
3556 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3557 sys::add_modifier_to_province(ws, p, trigger::payload(tval[1]).mod_id, sys::date{});
3558 });
3559 return 0;
3560}
3561uint32_t ef_add_country_modifier(EFFECT_PARAMTERS) {
3562 sys::add_modifier_to_nation(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id,
3563 ws.current_date + trigger::payload(tval[2]).signed_value);
3564 return 0;
3565}
3566uint32_t ef_add_country_modifier_no_duration(EFFECT_PARAMTERS) {
3567 sys::add_modifier_to_nation(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id, sys::date{});
3568 return 0;
3569}
3570uint32_t ef_casus_belli_tag(EFFECT_PARAMTERS) {
3571 auto type = trigger::payload(tval[1]).cb_id;
3572 auto months = trigger::payload(tval[2]).signed_value;
3573 auto tag_target = trigger::payload(tval[3]).tag_id;
3574
3575 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target); holder) {
3576 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3577 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type });
3578 }
3579 return 0;
3580}
3581uint32_t ef_casus_belli_int(EFFECT_PARAMTERS) {
3582 auto type = trigger::payload(tval[1]).cb_id;
3583 auto months = trigger::payload(tval[2]).signed_value;
3584
3585 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[3]).prov_id); holder) {
3586 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3587 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type });
3588 }
3589 return 0;
3590}
3591uint32_t ef_casus_belli_this_nation(EFFECT_PARAMTERS) {
3592 auto type = trigger::payload(tval[1]).cb_id;
3593 auto months = trigger::payload(tval[2]).signed_value;
3594
3595 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3596 .push_back(
3597 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(this_slot), type });
3598
3599 return 0;
3600}
3601uint32_t ef_casus_belli_this_state(EFFECT_PARAMTERS) {
3602 auto type = trigger::payload(tval[1]).cb_id;
3603 auto months = trigger::payload(tval[2]).signed_value;
3604
3605 if(auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); holder) {
3606 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3607 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type });
3608 }
3609 return 0;
3610}
3611uint32_t ef_casus_belli_this_province(EFFECT_PARAMTERS) {
3612 auto type = trigger::payload(tval[1]).cb_id;
3613 auto months = trigger::payload(tval[2]).signed_value;
3614
3615 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); holder) {
3616 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3617 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type });
3618 }
3619 return 0;
3620}
3621uint32_t ef_casus_belli_this_pop(EFFECT_PARAMTERS) {
3622 auto type = trigger::payload(tval[1]).cb_id;
3623 auto months = trigger::payload(tval[2]).signed_value;
3624
3625 if(auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); holder) {
3626 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3627 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type });
3628 }
3629 return 0;
3630}
3631uint32_t ef_casus_belli_from_nation(EFFECT_PARAMTERS) {
3632 auto type = trigger::payload(tval[1]).cb_id;
3633 auto months = trigger::payload(tval[2]).signed_value;
3634
3635 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3636 .push_back(
3637 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(from_slot), type });
3638
3639 return 0;
3640}
3641uint32_t ef_casus_belli_from_province(EFFECT_PARAMTERS) {
3642 auto type = trigger::payload(tval[1]).cb_id;
3643 auto months = trigger::payload(tval[2]).signed_value;
3644
3645 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); holder) {
3646 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3647 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type });
3648 }
3649 return 0;
3650}
3651uint32_t ef_add_casus_belli_tag(EFFECT_PARAMTERS) {
3652 auto type = trigger::payload(tval[1]).cb_id;
3653 auto months = trigger::payload(tval[2]).signed_value;
3654 auto tag_target = trigger::payload(tval[3]).tag_id;
3655
3656 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target); holder) {
3657 ws.world.nation_get_available_cbs(holder).push_back(
3658 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3659 }
3660 return 0;
3661}
3662uint32_t ef_add_casus_belli_int(EFFECT_PARAMTERS) {
3663 auto type = trigger::payload(tval[1]).cb_id;
3664 auto months = trigger::payload(tval[2]).signed_value;
3665
3666 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[3]).prov_id); holder) {
3667 ws.world.nation_get_available_cbs(holder).push_back(
3668 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3669 }
3670 return 0;
3671}
3672uint32_t ef_add_casus_belli_this_nation(EFFECT_PARAMTERS) {
3673 auto type = trigger::payload(tval[1]).cb_id;
3674 auto months = trigger::payload(tval[2]).signed_value;
3675
3676 ws.world.nation_get_available_cbs(trigger::to_nation(this_slot))
3677 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3678 return 0;
3679}
3680uint32_t ef_add_casus_belli_this_state(EFFECT_PARAMTERS) {
3681 auto type = trigger::payload(tval[1]).cb_id;
3682 auto months = trigger::payload(tval[2]).signed_value;
3683
3684 if(auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); holder) {
3685 ws.world.nation_get_available_cbs(holder).push_back(
3686 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3687 }
3688 return 0;
3689}
3690uint32_t ef_add_casus_belli_this_province(EFFECT_PARAMTERS) {
3691 auto type = trigger::payload(tval[1]).cb_id;
3692 auto months = trigger::payload(tval[2]).signed_value;
3693
3694 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); holder) {
3695 ws.world.nation_get_available_cbs(holder).push_back(
3696 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3697 }
3698 return 0;
3699}
3700uint32_t ef_add_casus_belli_this_pop(EFFECT_PARAMTERS) {
3701 auto type = trigger::payload(tval[1]).cb_id;
3702 auto months = trigger::payload(tval[2]).signed_value;
3703
3704 if(auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); holder) {
3705 ws.world.nation_get_available_cbs(holder).push_back(
3706 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3707 }
3708 return 0;
3709}
3710uint32_t ef_add_casus_belli_from_nation(EFFECT_PARAMTERS) {
3711 auto type = trigger::payload(tval[1]).cb_id;
3712 auto months = trigger::payload(tval[2]).signed_value;
3713
3714 ws.world.nation_get_available_cbs(trigger::to_nation(from_slot))
3715 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3716 return 0;
3717}
3718uint32_t ef_add_casus_belli_from_province(EFFECT_PARAMTERS) {
3719 auto type = trigger::payload(tval[1]).cb_id;
3720 auto months = trigger::payload(tval[2]).signed_value;
3721
3722 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); holder) {
3723 ws.world.nation_get_available_cbs(holder).push_back(
3724 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type });
3725 }
3726 return 0;
3727}
3728uint32_t ef_remove_casus_belli_tag(EFFECT_PARAMTERS) {
3729 auto type = trigger::payload(tval[1]).cb_id;
3730 auto tag_target = trigger::payload(tval[2]).tag_id;
3731
3732 auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target);
3733 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3734 for(uint32_t i = cbs.size(); i-- > 0;) {
3735 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3736 cbs.remove_at(i);
3737 }
3738 return 0;
3739}
3740uint32_t ef_remove_casus_belli_int(EFFECT_PARAMTERS) {
3741 auto type = trigger::payload(tval[1]).cb_id;
3742
3743 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[2]).prov_id);
3744 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3745 for(uint32_t i = cbs.size(); i-- > 0;) {
3746 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3747 cbs.remove_at(i);
3748 }
3749 return 0;
3750}
3751uint32_t ef_remove_casus_belli_this_nation(EFFECT_PARAMTERS) {
3752 auto type = trigger::payload(tval[1]).cb_id;
3753
3754 auto holder = trigger::to_nation(this_slot);
3755 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3756 for(uint32_t i = cbs.size(); i-- > 0;) {
3757 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3758 cbs.remove_at(i);
3759 }
3760 return 0;
3761}
3762uint32_t ef_remove_casus_belli_this_state(EFFECT_PARAMTERS) {
3763 auto type = trigger::payload(tval[1]).cb_id;
3764
3765 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
3766 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3767 for(uint32_t i = cbs.size(); i-- > 0;) {
3768 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3769 cbs.remove_at(i);
3770 }
3771 return 0;
3772}
3773uint32_t ef_remove_casus_belli_this_province(EFFECT_PARAMTERS) {
3774 auto type = trigger::payload(tval[1]).cb_id;
3775
3776 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3777 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3778 for(uint32_t i = cbs.size(); i-- > 0;) {
3779 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3780 cbs.remove_at(i);
3781 }
3782 return 0;
3783}
3784uint32_t ef_remove_casus_belli_this_pop(EFFECT_PARAMTERS) {
3785 auto type = trigger::payload(tval[1]).cb_id;
3786
3787 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
3788 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3789 for(uint32_t i = cbs.size(); i-- > 0;) {
3790 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3791 cbs.remove_at(i);
3792 }
3793 return 0;
3794}
3795uint32_t ef_remove_casus_belli_from_nation(EFFECT_PARAMTERS) {
3796 auto type = trigger::payload(tval[1]).cb_id;
3797
3798 auto holder = trigger::to_nation(from_slot);
3799 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3800 for(uint32_t i = cbs.size(); i-- > 0;) {
3801 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3802 cbs.remove_at(i);
3803 }
3804 return 0;
3805}
3806uint32_t ef_remove_casus_belli_from_province(EFFECT_PARAMTERS) {
3807 auto type = trigger::payload(tval[1]).cb_id;
3808
3809 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
3810 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3811 for(uint32_t i = cbs.size(); i-- > 0;) {
3812 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3813 cbs.remove_at(i);
3814 }
3815 return 0;
3816}
3817uint32_t ef_this_remove_casus_belli_tag(EFFECT_PARAMTERS) {
3818 auto type = trigger::payload(tval[1]).cb_id;
3819 auto tag_target = trigger::payload(tval[2]).tag_id;
3820
3821 auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target);
3822 if(holder) {
3823 auto cbs = ws.world.nation_get_available_cbs(holder);
3824 for(uint32_t i = cbs.size(); i-- > 0;) {
3825 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3826 cbs.remove_at(i);
3827 }
3828 }
3829 return 0;
3830}
3831uint32_t ef_this_remove_casus_belli_int(EFFECT_PARAMTERS) {
3832 auto type = trigger::payload(tval[1]).cb_id;
3833
3834 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[2]).prov_id);
3835 if(holder) {
3836 auto cbs = ws.world.nation_get_available_cbs(holder);
3837 for(uint32_t i = cbs.size(); i-- > 0;) {
3838 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3839 cbs.remove_at(i);
3840 }
3841 }
3842 return 0;
3843}
3844uint32_t ef_this_remove_casus_belli_this_nation(EFFECT_PARAMTERS) {
3845 auto type = trigger::payload(tval[1]).cb_id;
3846
3847 auto holder = trigger::to_nation(this_slot);
3848 auto cbs = ws.world.nation_get_available_cbs(holder);
3849 for(uint32_t i = cbs.size(); i-- > 0;) {
3850 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3851 cbs.remove_at(i);
3852 }
3853 return 0;
3854}
3855uint32_t ef_this_remove_casus_belli_this_state(EFFECT_PARAMTERS) {
3856 auto type = trigger::payload(tval[1]).cb_id;
3857
3858 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
3859 if(holder) {
3860 auto cbs = ws.world.nation_get_available_cbs(holder);
3861 for(uint32_t i = cbs.size(); i-- > 0;) {
3862 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3863 cbs.remove_at(i);
3864 }
3865 }
3866 return 0;
3867}
3868uint32_t ef_this_remove_casus_belli_this_province(EFFECT_PARAMTERS) {
3869 auto type = trigger::payload(tval[1]).cb_id;
3870
3871 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3872 if(holder) {
3873 auto cbs = ws.world.nation_get_available_cbs(holder);
3874 for(uint32_t i = cbs.size(); i-- > 0;) {
3875 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3876 cbs.remove_at(i);
3877 }
3878 }
3879 return 0;
3880}
3881uint32_t ef_this_remove_casus_belli_this_pop(EFFECT_PARAMTERS) {
3882 auto type = trigger::payload(tval[1]).cb_id;
3883
3884 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
3885 if(holder) {
3886 auto cbs = ws.world.nation_get_available_cbs(holder);
3887 for(uint32_t i = cbs.size(); i-- > 0;) {
3888 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3889 cbs.remove_at(i);
3890 }
3891 }
3892 return 0;
3893}
3894uint32_t ef_this_remove_casus_belli_from_nation(EFFECT_PARAMTERS) {
3895 auto type = trigger::payload(tval[1]).cb_id;
3896
3897 auto holder = trigger::to_nation(from_slot);
3898 auto cbs = ws.world.nation_get_available_cbs(holder);
3899 for(uint32_t i = cbs.size(); i-- > 0;) {
3900 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3901 cbs.remove_at(i);
3902 }
3903 return 0;
3904}
3905uint32_t ef_this_remove_casus_belli_from_province(EFFECT_PARAMTERS) {
3906 auto type = trigger::payload(tval[1]).cb_id;
3907
3908 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
3909 if(holder) {
3910 auto cbs = ws.world.nation_get_available_cbs(holder);
3911 for(uint32_t i = cbs.size(); i-- > 0;) {
3912 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3913 cbs.remove_at(i);
3914 }
3915 }
3916 return 0;
3917}
3918
3919uint32_t ef_add_truce_tag(EFFECT_PARAMTERS) {
3920 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
3921 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3922 return 0;
3923 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[2] * 30.5f));
3924 return 0;
3925}
3926uint32_t ef_add_truce_this_nation(EFFECT_PARAMTERS) {
3927 auto target = trigger::to_nation(this_slot);
3928 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3929 return 0;
3930 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3931 return 0;
3932}
3933uint32_t ef_add_truce_this_state(EFFECT_PARAMTERS) {
3934 auto target = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
3935 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3936 return 0;
3937 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3938 return 0;
3939}
3940uint32_t ef_add_truce_this_province(EFFECT_PARAMTERS) {
3941 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3942 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3943 return 0;
3944 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3945 return 0;
3946}
3947uint32_t ef_add_truce_this_pop(EFFECT_PARAMTERS) {
3948 auto target = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
3949 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3950 return 0;
3951 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3952 return 0;
3953}
3954uint32_t ef_add_truce_from_nation(EFFECT_PARAMTERS) {
3955 auto target = trigger::to_nation(from_slot);
3956 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3957 return 0;
3958 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3959 return 0;
3960}
3961uint32_t ef_add_truce_from_province(EFFECT_PARAMTERS) {
3962 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3963 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3964 return 0;
3965 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3966 return 0;
3967}
3969 for(auto drel : ws.world.nation_get_diplomatic_relation(trigger::to_nation(primary_slot))) {
3970 auto other_nation = drel.get_related_nations(0) != trigger::to_nation(primary_slot) ? drel.get_related_nations(0) : drel.get_related_nations(1);
3971 if(drel.get_are_allied()) {
3972 for(auto wfor : ws.world.nation_get_war_participant(trigger::to_nation(primary_slot))) {
3973 if(wfor.get_war().get_primary_attacker() == trigger::to_nation(primary_slot)) {
3974 if(!military::has_truce_with(ws, other_nation, wfor.get_war().get_primary_defender()) && military::standard_war_joining_is_possible(ws, wfor.get_war(), other_nation, true)) {
3975
3977 std::memset(&m, 0, sizeof(m));
3978 m.from = trigger::to_nation(primary_slot);
3979 m.to = other_nation;
3981 m.data.war = wfor.get_war();
3983 }
3984 }
3985 if(wfor.get_war().get_primary_defender() == trigger::to_nation(primary_slot)) {
3986 if(!military::has_truce_with(ws, other_nation, wfor.get_war().get_primary_attacker()) && military::standard_war_joining_is_possible(ws, wfor.get_war(), other_nation, false)) {
3987
3989 std::memset(&m, 0, sizeof(m));
3990 m.from = trigger::to_nation(primary_slot);
3991 m.to = other_nation;
3993 m.data.war = wfor.get_war();
3995 }
3996 }
3997 }
3998 }
3999
4000 }
4001
4002 return 0;
4003}
4004
4005uint32_t ef_ruling_party_this(EFFECT_PARAMTERS) {
4006 politics::force_ruling_party_ideology(ws, trigger::to_nation(primary_slot), ws.world.nation_get_ruling_party(trigger::to_nation(this_slot)).get_ideology());
4007 return 0;
4008}
4009uint32_t ef_ruling_party_from(EFFECT_PARAMTERS) {
4010 politics::force_ruling_party_ideology(ws, trigger::to_nation(primary_slot), ws.world.nation_get_ruling_party(trigger::to_nation(from_slot)).get_ideology());
4011 return 0;
4012}
4013
4015 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
4016 if(!target)
4017 return 0;
4018 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4019 return 0;
4020 if(target == trigger::to_nation(primary_slot))
4021 return 0;
4022 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4023 if(!war) {
4025 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4026 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4027 trigger::payload(tval[7]).tag_id,
4028 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4029 } else {
4030 if(trigger::payload(tval[5]).cb_id) { //attacker
4031 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4032 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4033 trigger::payload(tval[7]).tag_id,
4034 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4035 }
4036 }
4037 if(trigger::payload(tval[2]).cb_id) { //defender
4038 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[2]).cb_id,
4039 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[3]).prov_id),
4040 trigger::payload(tval[4]).tag_id,
4041 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[4]).tag_id));
4042 }
4045 return 0;
4046}
4047uint32_t ef_war_this_nation(EFFECT_PARAMTERS) {
4048 auto target = trigger::to_nation(this_slot);
4049 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4050 return 0;
4051 if(target == trigger::to_nation(primary_slot))
4052 return 0;
4053 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4054 if(!war) {
4056 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4057 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4058 trigger::payload(tval[6]).tag_id,
4059 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4060 } else {
4061 if(trigger::payload(tval[4]).cb_id) { //attacker
4062 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4063 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4064 trigger::payload(tval[6]).tag_id,
4065 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4066 }
4067 }
4068 if(trigger::payload(tval[1]).cb_id) { //defender
4069 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[1]).cb_id,
4070 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[2]).prov_id),
4071 trigger::payload(tval[3]).tag_id,
4072 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[3]).tag_id));
4073 }
4076 return 0;
4077}
4078uint32_t ef_war_this_state(EFFECT_PARAMTERS) {
4079 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); owner)
4080 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4081 return 0;
4082}
4083uint32_t ef_war_this_province(EFFECT_PARAMTERS) {
4084 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
4085 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4086 return 0;
4087}
4088uint32_t ef_war_this_pop(EFFECT_PARAMTERS) {
4089 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); owner)
4090 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4091 return 0;
4092}
4093uint32_t ef_war_from_nation(EFFECT_PARAMTERS) {
4094 return ef_war_this_nation(tval, ws, primary_slot, from_slot, 0, r_lo, r_hi, els);
4095}
4096uint32_t ef_war_from_province(EFFECT_PARAMTERS) {
4097 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
4098 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4099 return 0;
4100}
4101uint32_t ef_war_no_ally_tag(EFFECT_PARAMTERS) {
4102 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
4103 if(!target)
4104 return 0;
4105 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4106 return 0;
4107 if(target == trigger::to_nation(primary_slot))
4108 return 0;
4109 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4110 if(!war) {
4112 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4113 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4114 trigger::payload(tval[7]).tag_id,
4115 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4116 } else {
4117 if(trigger::payload(tval[5]).cb_id) { //attacker
4118 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4119 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4120 trigger::payload(tval[7]).tag_id,
4121 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4122 }
4123 }
4124 if(trigger::payload(tval[2]).cb_id) { //defender
4125 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[2]).cb_id,
4126 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[3]).prov_id),
4127 trigger::payload(tval[4]).tag_id,
4128 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[4]).tag_id));
4129 }
4131 return 0;
4132}
4133uint32_t ef_war_no_ally_this_nation(EFFECT_PARAMTERS) {
4134 auto target = trigger::to_nation(this_slot);
4135 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4136 return 0;
4137 if(target == trigger::to_nation(primary_slot))
4138 return 0;
4139 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4140 if(!war) {
4142 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4143 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4144 trigger::payload(tval[6]).tag_id,
4145 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4146 } else {
4147 if(trigger::payload(tval[4]).cb_id) { //attacker
4148 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4149 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4150 trigger::payload(tval[6]).tag_id,
4151 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4152 }
4153 }
4154 if(trigger::payload(tval[1]).cb_id) { //defender
4155 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[1]).cb_id,
4156 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[2]).prov_id),
4157 trigger::payload(tval[3]).tag_id,
4158 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[3]).tag_id));
4159 }
4161 return 0;
4162}
4163uint32_t ef_war_no_ally_this_state(EFFECT_PARAMTERS) {
4164 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); owner)
4165 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4166 return 0;
4167}
4168uint32_t ef_war_no_ally_this_province(EFFECT_PARAMTERS) {
4169 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
4170 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4171 return 0;
4172}
4173uint32_t ef_war_no_ally_this_pop(EFFECT_PARAMTERS) {
4174 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); owner)
4175 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4176 return 0;
4177}
4178uint32_t ef_war_no_ally_from_nation(EFFECT_PARAMTERS) {
4179 ef_war_no_ally_this_nation(tval, ws, primary_slot, from_slot, 0, r_lo, r_hi, els);
4180 return 0;
4181}
4182uint32_t ef_war_no_ally_from_province(EFFECT_PARAMTERS) {
4183 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
4184 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4185 return 0;
4186}
4187uint32_t ef_country_event_this_nation(EFFECT_PARAMTERS) {
4188 auto postpone = int32_t(tval[2]);
4189 assert(postpone > 0);
4190 auto future_date = ws.current_date + postpone;
4191 auto name = text::produce_simple_string(ws, dcon::fatten(ws.world, trigger::payload(tval[1]).nev_id).get_name());
4192 auto nationtag = text::produce_simple_string(ws, dcon::fatten(ws.world, trigger::to_nation(primary_slot)).get_identity_from_identity_holder().get_name());
4193 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4194 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, future_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::nation});
4195 return 0;
4196}
4197uint32_t ef_country_event_immediate_this_nation(EFFECT_PARAMTERS) {
4198 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4199 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, ws.current_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::nation});
4200 return 0;
4201}
4202uint32_t ef_province_event_this_nation(EFFECT_PARAMTERS) {
4203 auto postpone = int32_t(tval[2]);
4204 assert(postpone > 0);
4205 auto future_date = ws.current_date + postpone;
4206 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, future_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::nation});
4207 return 0;
4208}
4209uint32_t ef_province_event_immediate_this_nation(EFFECT_PARAMTERS) {
4210 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, ws.current_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::nation});
4211 return 0;
4212}
4213uint32_t ef_country_event_this_state(EFFECT_PARAMTERS) {
4214 auto postpone = int32_t(tval[2]);
4215 assert(postpone > 0);
4216 auto future_date = ws.current_date + postpone;
4217 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4218 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, future_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::state});
4219 return 0;
4220}
4221uint32_t ef_country_event_immediate_this_state(EFFECT_PARAMTERS) {
4222 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4223 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, ws.current_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::state});
4224 return 0;
4225}
4226uint32_t ef_province_event_this_state(EFFECT_PARAMTERS) {
4227 auto postpone = int32_t(tval[2]);
4228 assert(postpone > 0);
4229 auto future_date = ws.current_date + postpone;
4230 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, future_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::state});
4231 return 0;
4232}
4233uint32_t ef_province_event_immediate_this_state(EFFECT_PARAMTERS) {
4234 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, ws.current_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::state});
4235 return 0;
4236}
4237uint32_t ef_country_event_this_province(EFFECT_PARAMTERS) {
4238 auto postpone = int32_t(tval[2]);
4239 assert(postpone > 0);
4240 auto future_date = ws.current_date + postpone;
4241 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4242 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, future_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::province});
4243 return 0;
4244}
4245uint32_t ef_country_event_immediate_this_province(EFFECT_PARAMTERS) {
4246 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4247 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, ws.current_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::province});
4248 return 0;
4249}
4250uint32_t ef_province_event_this_province(EFFECT_PARAMTERS) {
4251 auto postpone = int32_t(tval[2]);
4252 assert(postpone > 0);
4253 auto future_date = ws.current_date + postpone;
4254 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, future_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::province});
4255 return 0;
4256}
4257uint32_t ef_province_event_immediate_this_province(EFFECT_PARAMTERS) {
4258 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, ws.current_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::province});
4259 return 0;
4260}
4261uint32_t ef_country_event_this_pop(EFFECT_PARAMTERS) {
4262 auto postpone = int32_t(tval[2]);
4263 assert(postpone > 0);
4264 auto future_date = ws.current_date + postpone;
4265 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4266 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, future_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::pop});
4267 return 0;
4268}
4269uint32_t ef_country_event_immediate_this_pop(EFFECT_PARAMTERS) {
4270 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4271 ws.future_n_event.push_back(event::pending_human_n_event {r_lo + 1, r_hi, primary_slot, this_slot, ws.current_date, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), event::slot_type::nation, event::slot_type::pop});
4272 return 0;
4273}
4274uint32_t ef_province_event_this_pop(EFFECT_PARAMTERS) {
4275 auto postpone = int32_t(tval[2]);
4276 assert(postpone > 0);
4277 auto future_date = ws.current_date + postpone;
4278 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, future_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::pop});
4279 return 0;
4280}
4281uint32_t ef_province_event_immediate_this_pop(EFFECT_PARAMTERS) {
4282 ws.future_p_event.push_back(event::pending_human_p_event {r_lo + 1, r_hi, this_slot, ws.current_date, trigger::payload(tval[1]).pev_id, trigger::to_prov(primary_slot), event::slot_type::pop});
4283 return 0;
4284}
4285uint32_t ef_country_event_province_this_nation(EFFECT_PARAMTERS) {
4286 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4287 return ef_country_event_this_nation(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4288 return 0;
4289}
4290uint32_t ef_country_event_immediate_province_this_nation(EFFECT_PARAMTERS) {
4291 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4292 return ef_country_event_immediate_this_nation(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4293 return 0;
4294}
4295uint32_t ef_country_event_province_this_state(EFFECT_PARAMTERS) {
4296 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4297 return ef_country_event_this_state(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4298 return 0;
4299}
4300uint32_t ef_country_event_immediate_province_this_state(EFFECT_PARAMTERS) {
4301 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4302 return ef_country_event_immediate_this_state(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4303 return 0;
4304}
4305uint32_t ef_country_event_province_this_province(EFFECT_PARAMTERS) {
4306 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4307 return ef_country_event_this_province(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4308 return 0;
4309}
4310uint32_t ef_country_event_immediate_province_this_province(EFFECT_PARAMTERS) {
4311 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4312 return ef_country_event_immediate_this_province(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4313 return 0;
4314}
4315uint32_t ef_country_event_province_this_pop(EFFECT_PARAMTERS) {
4316 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4317 return ef_country_event_this_pop(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4318 return 0;
4319}
4320uint32_t ef_country_event_immediate_province_this_pop(EFFECT_PARAMTERS) {
4321 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4322 return ef_country_event_immediate_this_pop(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4323 return 0;
4324}
4325
4326uint32_t ef_sub_unit_int(EFFECT_PARAMTERS) {
4327 // do nothing
4328 return 0;
4329}
4330uint32_t ef_sub_unit_this(EFFECT_PARAMTERS) {
4331 // do nothing
4332 return 0;
4333}
4334uint32_t ef_sub_unit_from(EFFECT_PARAMTERS) {
4335 // do nothing
4336 return 0;
4337}
4338uint32_t ef_sub_unit_current(EFFECT_PARAMTERS) {
4339 // do nothing
4340 return 0;
4341}
4342uint32_t ef_set_variable(EFFECT_PARAMTERS) {
4343 auto amount = trigger::read_float_from_payload(tval + 2);
4344 assert(std::isfinite(amount));
4345
4346 ws.world.nation_get_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natv_id) = amount;
4347 return 0;
4348}
4349uint32_t ef_change_variable(EFFECT_PARAMTERS) {
4350 auto amount = trigger::read_float_from_payload(tval + 2);
4351 assert(std::isfinite(amount));
4352
4353 ws.world.nation_get_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natv_id) += amount;
4354 return 0;
4355}
4357 auto i = trigger::payload(tval[1]).ideo_id;
4358 auto factor = trigger::read_float_from_payload(tval + 2);
4359 assert(std::isfinite(factor));
4360
4361 auto s = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, i));
4362 float new_total = 1.0f - s + std::max(0.0f, s + factor);
4363 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, i), std::max(0.0f, s + factor));
4364
4365 for(auto j : ws.world.in_ideology) {
4367 pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, j)) / new_total);
4368 }
4369
4370 return 0;
4371}
4373 auto i = trigger::payload(tval[1]).ideo_id;
4374 auto amount = trigger::read_float_from_payload(tval + 2);
4375 assert(std::isfinite(amount));
4376
4377 auto& u = ws.world.nation_get_upper_house(trigger::to_nation(primary_slot), i);
4378 float new_total = 100.0f - u + std::max(0.0f, u + 100.0f * amount);
4379 u = std::max(0.0f, u + 100.0f * amount);
4380
4381
4382 for(auto j : ws.world.in_ideology) {
4383 //auto prior_value = ws.world.nation_get_upper_house(trigger::to_nation(primary_slot), j);
4384 //auto new_value = prior_value * 100.0f / (new_total);
4385 //ws.world.nation_set_upper_house(trigger::to_nation(primary_slot), j, prior_value);
4386 ws.world.nation_get_upper_house(trigger::to_nation(primary_slot), j) *= 100.0f / (new_total);
4387 }
4388
4389 return 0;
4390}
4391uint32_t ef_scaled_militancy_issue(EFFECT_PARAMTERS) {
4392 auto issue_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4393
4394 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), issue_demo_tag);
4395 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4396 assert(std::isfinite(adjustment));
4397 auto v = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
4398 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4399
4400 return 0;
4401}
4402uint32_t ef_scaled_militancy_ideology(EFFECT_PARAMTERS) {
4403 auto ideology_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4404
4405 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), ideology_demo_tag);
4406 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4407 assert(std::isfinite(adjustment));
4408 auto v = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
4409 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4410
4411 return 0;
4412}
4413uint32_t ef_scaled_militancy_unemployment(EFFECT_PARAMTERS) {
4414 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, trigger::to_pop(primary_slot));
4415 float adjustment = trigger::read_float_from_payload(tval + 1) * float(unemployed);
4416 assert(std::isfinite(adjustment));
4417 auto v = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
4418 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4419
4420 return 0;
4421}
4422uint32_t ef_scaled_consciousness_issue(EFFECT_PARAMTERS) {
4423 auto issue_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4424
4425 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), issue_demo_tag);
4426 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4427 assert(std::isfinite(adjustment));
4428 auto v = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
4429 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4430
4431 return 0;
4432}
4433uint32_t ef_scaled_consciousness_ideology(EFFECT_PARAMTERS) {
4434 auto ideology_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4435
4436 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), ideology_demo_tag);
4437 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4438 assert(std::isfinite(adjustment));
4439 auto v = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
4440 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4441
4442 return 0;
4443}
4444uint32_t ef_scaled_consciousness_unemployment(EFFECT_PARAMTERS) {
4445 auto unemployed = 1.0 - pop_demographics::get_employment(ws, trigger::to_pop(primary_slot));
4446 float adjustment = trigger::read_float_from_payload(tval + 1) * float(unemployed);
4447 auto v = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
4448 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4449
4450 return 0;
4451}
4452uint32_t ef_scaled_militancy_nation_issue(EFFECT_PARAMTERS) {
4453 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4454 auto factor = trigger::read_float_from_payload(tval + 2);
4455 assert(std::isfinite(factor));
4456
4457 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4458 for(auto pop : p.get_province().get_pop_location()) {
4459 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4460 float adjustment = factor * support;
4461 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4462 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4463 }
4464 }
4465
4466 return 0;
4467}
4468uint32_t ef_scaled_militancy_nation_ideology(EFFECT_PARAMTERS) {
4469 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4470 auto factor = trigger::read_float_from_payload(tval + 2);
4471 assert(std::isfinite(factor));
4472
4473 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4474 for(auto pop : p.get_province().get_pop_location()) {
4475 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4476 float adjustment = factor * support;
4477 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4478 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4479 }
4480 }
4481
4482 return 0;
4483}
4484uint32_t ef_scaled_militancy_nation_unemployment(EFFECT_PARAMTERS) {
4485 auto factor = trigger::read_float_from_payload(tval + 1);
4486 assert(std::isfinite(factor));
4487
4488 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4489 for(auto pop : p.get_province().get_pop_location()) {
4490 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4491 float adjustment = factor * unemployed;
4492 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4493 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4494 }
4495 }
4496
4497 return 0;
4498}
4499uint32_t ef_scaled_consciousness_nation_issue(EFFECT_PARAMTERS) {
4500 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4501 auto factor = trigger::read_float_from_payload(tval + 2);
4502 assert(std::isfinite(factor));
4503
4504 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4505 for(auto pop : p.get_province().get_pop_location()) {
4506 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4507 float adjustment = factor * support;
4508 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4509 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4510 }
4511 }
4512
4513 return 0;
4514}
4515uint32_t ef_scaled_consciousness_nation_ideology(EFFECT_PARAMTERS) {
4516 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4517 auto factor = trigger::read_float_from_payload(tval + 2);
4518 assert(std::isfinite(factor));
4519
4520 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4521 for(auto pop : p.get_province().get_pop_location()) {
4522 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4523 float adjustment = factor * support;
4524 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4525 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4526 }
4527 }
4528
4529 return 0;
4530}
4531uint32_t ef_scaled_consciousness_nation_unemployment(EFFECT_PARAMTERS) {
4532 auto factor = trigger::read_float_from_payload(tval + 1);
4533 assert(std::isfinite(factor));
4534
4535 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4536 for(auto pop : p.get_province().get_pop_location()) {
4537 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4538 float adjustment = factor * unemployed;
4539 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4540 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4541 }
4542 }
4543
4544 return 0;
4545}
4546uint32_t ef_scaled_militancy_state_issue(EFFECT_PARAMTERS) {
4547 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4548 auto factor = trigger::read_float_from_payload(tval + 2);
4549 assert(std::isfinite(factor));
4550
4551 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4552 for(auto pop : ws.world.province_get_pop_location(p)) {
4553 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4554 float adjustment = factor * support;
4555 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4556 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4557 }
4558 });
4559
4560 return 0;
4561}
4562uint32_t ef_scaled_militancy_state_ideology(EFFECT_PARAMTERS) {
4563 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4564 auto factor = trigger::read_float_from_payload(tval + 2);
4565 assert(std::isfinite(factor));
4566
4567 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4568 for(auto pop : ws.world.province_get_pop_location(p)) {
4569 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4570 float adjustment = factor * support;
4571 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4572 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4573 }
4574 });
4575
4576 return 0;
4577}
4578uint32_t ef_scaled_militancy_state_unemployment(EFFECT_PARAMTERS) {
4579 auto factor = trigger::read_float_from_payload(tval + 1);
4580 assert(std::isfinite(factor));
4581
4582 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4583 for(auto pop : ws.world.province_get_pop_location(p)) {
4584 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4585 float adjustment = factor * unemployed;
4586 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4587 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4588 }
4589 });
4590
4591 return 0;
4592}
4593uint32_t ef_scaled_consciousness_state_issue(EFFECT_PARAMTERS) {
4594 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4595 auto factor = trigger::read_float_from_payload(tval + 2);
4596 assert(std::isfinite(factor));
4597
4598 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4599 for(auto pop : ws.world.province_get_pop_location(p)) {
4600 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4601 float adjustment = factor * support;
4602 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4603 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4604 }
4605 });
4606
4607 return 0;
4608}
4609uint32_t ef_scaled_consciousness_state_ideology(EFFECT_PARAMTERS) {
4610 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4611 auto factor = trigger::read_float_from_payload(tval + 2);
4612 assert(std::isfinite(factor));
4613
4614 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4615 for(auto pop : ws.world.province_get_pop_location(p)) {
4616 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4617 float adjustment = factor * support;
4618 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4619 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4620 }
4621 });
4622
4623 return 0;
4624}
4625uint32_t ef_scaled_consciousness_state_unemployment(EFFECT_PARAMTERS) {
4626 auto factor = trigger::read_float_from_payload(tval + 1);
4627 assert(std::isfinite(factor));
4628
4629 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4630 for(auto pop : ws.world.province_get_pop_location(p)) {
4631 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4632 float adjustment = factor * unemployed;
4633 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4634 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4635 }
4636 });
4637
4638 return 0;
4639}
4640uint32_t ef_scaled_militancy_province_issue(EFFECT_PARAMTERS) {
4641 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4642 auto factor = trigger::read_float_from_payload(tval + 2);
4643 assert(std::isfinite(factor));
4644
4645 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4646 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4647 float adjustment = factor * support;
4648 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4649 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4650 }
4651
4652 return 0;
4653}
4654uint32_t ef_scaled_militancy_province_ideology(EFFECT_PARAMTERS) {
4655 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4656 auto factor = trigger::read_float_from_payload(tval + 2);
4657 assert(std::isfinite(factor));
4658
4659 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4660 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4661 float adjustment = factor * support;
4662 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4663 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4664 }
4665
4666 return 0;
4667}
4668uint32_t ef_scaled_militancy_province_unemployment(EFFECT_PARAMTERS) {
4669 auto factor = trigger::read_float_from_payload(tval + 1);
4670 assert(std::isfinite(factor));
4671
4672 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4673 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4674 float adjustment = factor * unemployed;
4675 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4676 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4677 }
4678
4679 return 0;
4680}
4681uint32_t ef_scaled_consciousness_province_issue(EFFECT_PARAMTERS) {
4682 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4683 auto factor = trigger::read_float_from_payload(tval + 2);
4684 assert(std::isfinite(factor));
4685
4686 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4687 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4688 float adjustment = factor * support;
4689 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4690 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4691 }
4692
4693 return 0;
4694}
4695uint32_t ef_scaled_consciousness_province_ideology(EFFECT_PARAMTERS) {
4696 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4697 auto factor = trigger::read_float_from_payload(tval + 2);
4698 assert(std::isfinite(factor));
4699
4700 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4701 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4702 float adjustment = factor * support;
4703 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4704 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4705 }
4706
4707 return 0;
4708}
4709uint32_t ef_scaled_consciousness_province_unemployment(EFFECT_PARAMTERS) {
4710 auto factor = trigger::read_float_from_payload(tval + 1);
4711 assert(std::isfinite(factor));
4712
4713 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4714 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4715 float adjustment = factor * unemployed;
4716 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4717 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4718 }
4719
4720 return 0;
4721}
4722uint32_t ef_variable_good_name(EFFECT_PARAMTERS) {
4723 auto amount = trigger::read_float_from_payload(tval + 2);
4724 assert(std::isfinite(amount));
4725 auto& v = ws.world.nation_get_stockpiles(trigger::to_nation(primary_slot), trigger::payload(tval[1]).com_id);
4726 v = std::max(v + amount, 0.0f);
4727 return 0;
4728}
4729uint32_t ef_variable_good_name_province(EFFECT_PARAMTERS) {
4730 auto amount = trigger::read_float_from_payload(tval + 2);
4731 assert(std::isfinite(amount));
4732 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner) {
4733 auto& v = ws.world.nation_get_stockpiles(owner, trigger::payload(tval[1]).com_id);
4734 v = std::max(v + amount, 0.0f);
4735 }
4736 return 0;
4737}
4739 dcon::unit_name_id ename{ dcon::unit_name_id::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
4740 auto esv = ws.to_string_view(ename);
4741 for(auto l : ws.world.nation_get_leader_loyalty(trigger::to_nation(primary_slot))) {
4742 auto n = l.get_leader().get_name();
4743 auto nsv = ws.to_string_view(n);
4744 if(nsv == esv) {
4745 military::kill_leader(ws, l.get_leader());
4746 return 0;
4747 }
4748 }
4749 return 0;
4750}
4751uint32_t ef_define_general(EFFECT_PARAMTERS) {
4752 auto l = fatten(ws.world, ws.world.create_leader());
4753 l.set_since(ws.current_date);
4754 l.set_is_admiral(false);
4755 l.set_background(trigger::payload(tval[4]).lead_id);
4756 l.set_personality(trigger::payload(tval[3]).lead_id);
4757 l.set_name(dcon::unit_name_id(dcon::unit_name_id::value_base_t(trigger::read_int32_t_from_payload(tval + 1))));
4758 l.set_nation_from_leader_loyalty(trigger::to_nation(primary_slot));
4759 return 0;
4760}
4761uint32_t ef_define_admiral(EFFECT_PARAMTERS) {
4762 auto l = fatten(ws.world, ws.world.create_leader());
4763 l.set_since(ws.current_date);
4764 l.set_is_admiral(true);
4765 l.set_background(trigger::payload(tval[4]).lead_id);
4766 l.set_personality(trigger::payload(tval[3]).lead_id);
4767 l.set_name(dcon::unit_name_id(dcon::unit_name_id::value_base_t(trigger::read_int32_t_from_payload(tval + 1))));
4768 l.set_nation_from_leader_loyalty(trigger::to_nation(primary_slot));
4769 return 0;
4770}
4771uint32_t ef_dominant_issue(EFFECT_PARAMTERS) {
4772 auto t = trigger::payload(tval[1]).opt_id;
4773 auto factor = trigger::read_float_from_payload(tval + 2);
4774
4775 auto s = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, t));
4776 auto new_total = 1.0f - s + std::max(0.0f, s + factor);
4777 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, t), std::max(0.0f, s + factor));
4778
4779 for(auto i : ws.world.in_issue_option) {
4781 pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, i)) / new_total);
4782 }
4783
4784 return 0;
4785}
4786uint32_t ef_dominant_issue_nation(EFFECT_PARAMTERS) {
4787 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4788 auto factor = trigger::read_float_from_payload(tval + 2);
4789
4790 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4791 for(auto pop : p.get_province().get_pop_location()) {
4792 auto s = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4793 auto new_total = 1.0f - s + std::max(0.0f, s + factor);
4794 pop_demographics::set_demo(ws, pop.get_pop(), demo_tag, std::max(0.0f, s + factor));
4795
4796 for(auto i : ws.world.in_issue_option) {
4797 pop_demographics::set_demo(ws, pop.get_pop(), pop_demographics::to_key(ws, i),
4798 pop_demographics::get_demo(ws, pop.get_pop(), pop_demographics::to_key(ws, i)) / new_total);
4799 }
4800 }
4801 }
4802
4803 return 0;
4804}
4805uint32_t ef_add_war_goal(EFFECT_PARAMTERS) {
4806 if(auto w = military::find_war_between(ws, trigger::to_nation(primary_slot), trigger::to_nation(from_slot)); w) {
4807 military::add_wargoal(ws, w, trigger::to_nation(from_slot), trigger::to_nation(primary_slot), trigger::payload(tval[1]).cb_id,
4808 dcon::state_definition_id{}, dcon::national_identity_id{}, trigger::to_nation(primary_slot));
4809 }
4810 return 0;
4811}
4812uint32_t ef_move_issue_percentage_nation(EFFECT_PARAMTERS) {
4813 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4814 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4815 auto amount = trigger::read_float_from_payload(tval + 3);
4816
4817 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4818 for(auto pop : p.get_province().get_pop_location()) {
4819 auto s = pop_demographics::get_demo(ws, pop.get_pop(), from_issue);
4820 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s - s * amount);
4821 auto s2 = pop_demographics::get_demo(ws, pop.get_pop(), to_issue);
4822 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s2 + s * amount);
4823 }
4824 }
4825
4826 return 0;
4827}
4828uint32_t ef_move_issue_percentage_state(EFFECT_PARAMTERS) {
4829 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4830 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4831 auto amount = trigger::read_float_from_payload(tval + 3);
4832
4833 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4834 for(auto pop : ws.world.province_get_pop_location(p)) {
4835 auto s = pop_demographics::get_demo(ws, pop.get_pop(), from_issue);
4836 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s - s * amount);
4837 auto s2 = pop_demographics::get_demo(ws, pop.get_pop(), to_issue);
4838 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s2 + s * amount);
4839 }
4840 });
4841
4842 return 0;
4843}
4844uint32_t ef_move_issue_percentage_province(EFFECT_PARAMTERS) {
4845 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4846 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4847 auto amount = trigger::read_float_from_payload(tval + 3);
4848
4849 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4850 auto s = pop_demographics::get_demo(ws, pop.get_pop(), from_issue);
4851 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s - s * amount);
4852 auto s2 = pop_demographics::get_demo(ws, pop.get_pop(), to_issue);
4853 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s2 + s * amount);
4854 }
4855
4856 return 0;
4857}
4858uint32_t ef_move_issue_percentage_pop(EFFECT_PARAMTERS) {
4859 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4860 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4861 auto amount = trigger::read_float_from_payload(tval + 3);
4862
4863 auto s = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), from_issue);
4864 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), from_issue, s - s * amount);
4865 auto s2 = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), to_issue);
4866 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), from_issue, s2 + s * amount);
4867
4868 return 0;
4869}
4870uint32_t ef_party_loyalty(EFFECT_PARAMTERS) {
4871 auto i = trigger::payload(tval[2]).ideo_id;
4872 auto amount = float(trigger::payload(tval[3]).signed_value) / 100.0f;
4873 auto& v = ws.world.province_get_party_loyalty(trigger::payload(tval[1]).prov_id, i);
4874 v = std::clamp(v + amount, -1.0f, 1.0f);
4875 return 0;
4876}
4877uint32_t ef_party_loyalty_province(EFFECT_PARAMTERS) {
4878 auto i = trigger::payload(tval[1]).ideo_id;
4879 auto amount = float(trigger::payload(tval[2]).signed_value) / 100.0f;
4880 auto& v = ws.world.province_get_party_loyalty(trigger::to_prov(primary_slot), i);
4881 v = std::clamp(v + amount, -1.0f, 1.0f);
4882 return 0;
4883}
4884
4885uint32_t ef_build_railway_in_capital_yes_whole_state_yes_limit(EFFECT_PARAMTERS) {
4886 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4887 auto cs = ws.world.province_get_state_membership(c);
4888 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
4889 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f)
4890 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4891 });
4892 ws.railroad_built.store(true, std::memory_order::release);
4893 return 0;
4894}
4895uint32_t ef_build_railway_in_capital_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
4896 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4897 auto cs = ws.world.province_get_state_membership(c);
4898 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
4899 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f)
4900 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4901 });
4902 ws.railroad_built.store(true, std::memory_order::release);
4903 return 0;
4904}
4905uint32_t ef_build_railway_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
4906 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4907 if(c) {
4908 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f) {
4909 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4910 ws.railroad_built.store(true, std::memory_order::release);
4911 }
4912 }
4913 return 0;
4914}
4915uint32_t ef_build_railway_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
4916 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4917 if(c) {
4918 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f) {
4919 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4920 ws.railroad_built.store(true, std::memory_order::release);
4921 }
4922 }
4923 return 0;
4924}
4925uint32_t ef_build_fort_in_capital_yes_whole_state_yes_limit(EFFECT_PARAMTERS) {
4926 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4927 auto cs = ws.world.province_get_state_membership(c);
4929 [&](dcon::province_id p) { ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort)) += uint8_t(1); });
4930 return 0;
4931}
4932uint32_t ef_build_fort_in_capital_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
4933 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4934 auto cs = ws.world.province_get_state_membership(c);
4936 [&](dcon::province_id p) { ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort)) += uint8_t(1); });
4937 return 0;
4938}
4939uint32_t ef_build_fort_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
4940 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4941 if(c) {
4942 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::fort)) += uint8_t(1);
4943 }
4944 return 0;
4945}
4946uint32_t ef_build_fort_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
4947 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4948 if(c) {
4949 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::fort)) += uint8_t(1);
4950 }
4951 return 0;
4952}
4953uint32_t ef_relation_reb(EFFECT_PARAMTERS) {
4954 auto itag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
4955 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(itag); holder)
4956 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), holder, float(trigger::payload(tval[1]).signed_value));
4957 return 0;
4958}
4959uint32_t ef_variable_tech_name_yes(EFFECT_PARAMTERS) {
4960 if(ws.world.nation_get_active_technologies(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id) == false)
4961 culture::apply_technology(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id);
4962 return 0;
4963}
4964uint32_t ef_variable_tech_name_no(EFFECT_PARAMTERS) {
4965 if(ws.world.nation_get_active_technologies(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id) == true)
4966 culture::remove_technology(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id);
4967 return 0;
4968}
4969uint32_t ef_variable_invention_name_yes(EFFECT_PARAMTERS) {
4970 if(ws.world.nation_get_active_inventions(trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id) == false)
4971 culture::apply_invention(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id);
4972 return 0;
4973}
4974uint32_t ef_variable_invention_name_no(EFFECT_PARAMTERS) {
4975 if(ws.world.nation_get_active_inventions(trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id) == true)
4976 culture::remove_invention(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id);
4977 return 0;
4978}
4979uint32_t ef_set_country_flag_province(EFFECT_PARAMTERS) {
4980 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4981 return ef_set_country_flag(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
4982 return 0;
4983}
4985 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot)); owner)
4986 return ef_set_country_flag(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
4987 return 0;
4988}
4989uint32_t ef_add_country_modifier_province(EFFECT_PARAMTERS) {
4990 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4991 return ef_add_country_modifier(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
4992 return 0;
4993}
4994uint32_t ef_add_country_modifier_province_no_duration(EFFECT_PARAMTERS) {
4995 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4996 return ef_add_country_modifier_no_duration(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
4997 return 0;
4998}
4999uint32_t ef_relation_province(EFFECT_PARAMTERS) {
5000 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5001 return ef_relation(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
5002 return 0;
5003}
5004uint32_t ef_relation_province_this_nation(EFFECT_PARAMTERS) {
5005 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5006 return ef_relation_this_nation(tval, ws, trigger::to_generic(owner), this_slot, 0, 0, 0, els);
5007 return 0;
5008}
5009uint32_t ef_relation_province_this_province(EFFECT_PARAMTERS) {
5010 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5011 return ef_relation_this_province(tval, ws, trigger::to_generic(owner), this_slot, 0, 0, 0, els);
5012 return 0;
5013}
5014uint32_t ef_relation_province_from_nation(EFFECT_PARAMTERS) {
5015 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5016 return ef_relation_this_nation(tval, ws, trigger::to_generic(owner), from_slot, 0, 0, 0, els);
5017 return 0;
5018}
5019uint32_t ef_relation_province_from_province(EFFECT_PARAMTERS) {
5020 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5021 return ef_relation_this_province(tval, ws, trigger::to_generic(owner), from_slot, 0, 0, 0, els);
5022 return 0;
5023}
5024uint32_t ef_relation_province_reb(EFFECT_PARAMTERS) {
5025 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5026 return ef_relation_reb(tval, ws, trigger::to_generic(owner), 0, from_slot, 0, 0, els);
5027 return 0;
5028}
5029uint32_t ef_treasury_province(EFFECT_PARAMTERS) {
5030 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5031 return ef_treasury(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
5032 return 0;
5033}
5034
5035//
5036// Banks
5037//
5038uint32_t ef_build_bank_in_capital_yes_whole_state_yes_limit(EFFECT_PARAMTERS) {
5039 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5040 auto cs = ws.world.province_get_state_membership(c);
5041 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
5042 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5043 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5044 });
5045 return 0;
5046}
5047uint32_t ef_build_bank_in_capital_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
5048 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5049 auto cs = ws.world.province_get_state_membership(c);
5050 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
5051 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5052 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5053 });
5054 return 0;
5055}
5056uint32_t ef_build_bank_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
5057 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5058 if(c) {
5059 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5060 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5061 }
5062 return 0;
5063}
5064uint32_t ef_build_bank_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
5065 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5066 if(c) {
5067 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5068 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5069 }
5070 return 0;
5071}
5072//
5073// Banks
5074//
5075uint32_t ef_build_university_in_capital_yes_whole_state_yes_limit(EFFECT_PARAMTERS) {
5076 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5077 auto cs = ws.world.province_get_state_membership(c);
5078 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
5079 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5080 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5081 });
5082 return 0;
5083}
5084uint32_t ef_build_university_in_capital_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
5085 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5086 auto cs = ws.world.province_get_state_membership(c);
5087 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
5088 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5089 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5090 });
5091 return 0;
5092}
5093uint32_t ef_build_university_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
5094 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5095 if(c) {
5096 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5097 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5098 }
5099 return 0;
5100}
5101uint32_t ef_build_university_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
5102 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5103 if(c) {
5104 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5105 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5106 }
5107 return 0;
5108}
5109
5111 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
5112 while(sprovs.begin() != sprovs.end()) {
5113 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, dcon::nation_id{});
5114 }
5115 return 0;
5116}
5118 province::change_province_owner(ws, trigger::to_prov(primary_slot), dcon::nation_id{ });
5119 return 0;
5120}
5121
5122uint32_t ef_fop_clr_global_flag_2(EFFECT_PARAMTERS) {
5123 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5124 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5125 return 0;
5126}
5127uint32_t ef_fop_clr_global_flag_3(EFFECT_PARAMTERS) {
5128 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5129 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5130 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5131 return 0;
5132}
5133uint32_t ef_fop_clr_global_flag_4(EFFECT_PARAMTERS) {
5134 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5135 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5136 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5137 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5138 return 0;
5139}
5140uint32_t ef_fop_clr_global_flag_5(EFFECT_PARAMTERS) {
5141 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5142 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5143 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5144 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5145 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5146 return 0;
5147}
5148uint32_t ef_fop_clr_global_flag_6(EFFECT_PARAMTERS) {
5149 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5150 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5151 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5152 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5153 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5154 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5155 return 0;
5156}
5157uint32_t ef_fop_clr_global_flag_7(EFFECT_PARAMTERS) {
5158 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5159 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5160 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5161 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5162 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5163 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5164 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5165 return 0;
5166}
5167uint32_t ef_fop_clr_global_flag_8(EFFECT_PARAMTERS) {
5168 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5169 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5170 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5171 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5172 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5173 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5174 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5175 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5176 return 0;
5177}
5178uint32_t ef_fop_clr_global_flag_9(EFFECT_PARAMTERS) {
5179 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5180 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5181 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5182 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5183 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5184 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5185 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5186 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5187 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5188 return 0;
5189}
5190uint32_t ef_fop_clr_global_flag_10(EFFECT_PARAMTERS) {
5191 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5192 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5193 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5194 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5195 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5196 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5197 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5198 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5199 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5200 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[10]).glob_id, false);
5201 return 0;
5202}
5203uint32_t ef_fop_clr_global_flag_11(EFFECT_PARAMTERS) {
5204 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5205 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5206 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5207 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5208 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5209 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5210 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5211 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5212 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5213 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[10]).glob_id, false);
5214 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[11]).glob_id, false);
5215 return 0;
5216}
5217uint32_t ef_fop_clr_global_flag_12(EFFECT_PARAMTERS) {
5218 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5219 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5220 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5221 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5222 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5223 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5224 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5225 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5226 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5227 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[10]).glob_id, false);
5228 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[11]).glob_id, false);
5229 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[12]).glob_id, false);
5230 return 0;
5231}
5232uint32_t ef_fop_change_province_name(EFFECT_PARAMTERS) {
5233 dcon::text_key name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
5234 ws.world.province_set_name(trigger::payload(tval[3]).prov_id, name);
5235 return 0;
5236}
5237uint32_t ef_change_terrain_province(EFFECT_PARAMTERS) {
5238 auto const p = trigger::to_prov(primary_slot);
5239 ws.world.province_set_terrain(p, trigger::payload(tval[1]).mod_id);
5240 return 0;
5241}
5242uint32_t ef_change_terrain_pop(EFFECT_PARAMTERS) {
5243 auto const p = ws.world.pop_get_province_from_pop_location(trigger::to_pop(primary_slot));
5244 ws.world.province_set_terrain(p, trigger::payload(tval[1]).mod_id);
5245 return 0;
5246}
5247uint32_t ef_masquerade_as_nation_this(EFFECT_PARAMTERS) {
5248 auto dnid = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
5249 ws.world.nation_set_masquerade_identity(trigger::to_nation(primary_slot), dnid);
5250 return 0;
5251}
5252uint32_t ef_masquerade_as_nation_from(EFFECT_PARAMTERS) {
5253 auto dnid = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(from_slot));
5254 ws.world.nation_set_masquerade_identity(trigger::to_nation(primary_slot), dnid);
5255 return 0;
5256}
5257
5258uint32_t ef_change_party_name(EFFECT_PARAMTERS) {
5259 auto ideo = trigger::payload(tval[1]).ideo_id;
5260 dcon::text_key new_name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 2)) };
5261
5262 if(ideo) {
5263 auto n = trigger::to_nation(primary_slot);
5264 auto holder = ws.world.nation_get_identity_from_identity_holder(n);
5265
5266 auto start = ws.world.national_identity_get_political_party_first(holder).id.index();
5267 auto end = start + ws.world.national_identity_get_political_party_count(holder);
5268
5269 for(int32_t i = start; i < end; i++) {
5270 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5271 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5272 ws.world.political_party_set_name(pid, new_name);
5273 return 0;
5274 }
5275 }
5276 } else {
5277 auto n = trigger::to_nation(primary_slot);
5278 auto rp = ws.world.nation_get_ruling_party(n);
5279 if(rp) {
5280 ws.world.political_party_set_name(rp, new_name);
5281 }
5282 }
5283 return 0;
5284}
5285
5286uint32_t ef_change_party_position(EFFECT_PARAMTERS) {
5287 auto ideo = trigger::payload(tval[1]).ideo_id;
5288 dcon::issue_option_id new_opt = trigger::payload(tval[2]).opt_id;
5289 auto popt = ws.world.issue_option_get_parent_issue(new_opt);
5290
5291 if(ideo) {
5292 auto n = trigger::to_nation(primary_slot);
5293 auto holder = ws.world.nation_get_identity_from_identity_holder(n);
5294
5295 auto start = ws.world.national_identity_get_political_party_first(holder).id.index();
5296 auto end = start + ws.world.national_identity_get_political_party_count(holder);
5297
5298 for(int32_t i = start; i < end; i++) {
5299 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5300 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5301 ws.world.political_party_set_party_issues(pid, popt, new_opt);
5302 if(ws.world.nation_get_ruling_party(n) == pid)
5303 politics::set_ruling_party(ws, n, pid); // force update of issues and rules
5304 return 0;
5305 }
5306 }
5307 } else {
5308 auto n = trigger::to_nation(primary_slot);
5309 auto rp = ws.world.nation_get_ruling_party(n);
5310 if(rp) {
5311 ws.world.political_party_set_party_issues(rp, popt, new_opt);
5312 politics::set_ruling_party(ws, n, rp); // force update of issues and rules
5313 }
5314 }
5315 return 0;
5316}
5317
5318inline constexpr uint32_t(*effect_functions[])(EFFECT_PARAMTERS) = {
5319 ef_none,
5320#define EFFECT_BYTECODE_ELEMENT(code, name, arg) ef_##name,
5322#undef EFFECT_BYTECODE_ELEMENT
5323 //
5324 // SCOPES
5325 //
5326 es_generic_scope, // constexpr inline uint16_t generic_scope = first_scope_code + 0x0000; // default grouping of effects (or hidden_tooltip)
5327 es_x_neighbor_province_scope, // constexpr inline uint16_t x_neighbor_province_scope = first_scope_code + 0x0001;
5328 es_x_neighbor_country_scope, // constexpr inline uint16_t x_neighbor_country_scope = first_scope_code + 0x0002;
5329 es_x_country_scope, // constexpr inline uint16_t x_country_scope = first_scope_code + 0x0003;
5330 es_x_country_scope_nation, // constexpr inline uint16_t x_country_scope_nation = first_scope_code + 0x0004;
5331 es_x_empty_neighbor_province_scope, // constexpr inline uint16_t x_empty_neighbor_province_scope = first_scope_code + 0x0005;
5332 es_x_greater_power_scope, // constexpr inline uint16_t x_greater_power_scope = first_scope_code + 0x0006;
5333 es_poor_strata_scope_nation, // constexpr inline uint16_t poor_strata_scope_nation = first_scope_code + 0x0007;
5334 es_poor_strata_scope_state, // constexpr inline uint16_t poor_strata_scope_state = first_scope_code + 0x0008;
5335 es_poor_strata_scope_province, // constexpr inline uint16_t poor_strata_scope_province = first_scope_code + 0x0009;
5336 es_middle_strata_scope_nation, // constexpr inline uint16_t middle_strata_scope_nation = first_scope_code + 0x000A;
5337 es_middle_strata_scope_state, // constexpr inline uint16_t middle_strata_scope_state = first_scope_code + 0x000B;
5338 es_middle_strata_scope_province, // constexpr inline uint16_t middle_strata_scope_province = first_scope_code + 0x000C;
5339 es_rich_strata_scope_nation, // constexpr inline uint16_t rich_strata_scope_nation = first_scope_code + 0x000D;
5340 es_rich_strata_scope_state, // constexpr inline uint16_t rich_strata_scope_state = first_scope_code + 0x000E;
5341 es_rich_strata_scope_province, // constexpr inline uint16_t rich_strata_scope_province = first_scope_code + 0x000F;
5342 es_x_pop_scope_nation, // constexpr inline uint16_t x_pop_scope_nation = first_scope_code + 0x0010;
5343 es_x_pop_scope_state, // constexpr inline uint16_t x_pop_scope_state = first_scope_code + 0x0011;
5344 es_x_pop_scope_province, // constexpr inline uint16_t x_pop_scope_province = first_scope_code + 0x0012;
5345 es_x_owned_scope_nation, // constexpr inline uint16_t x_owned_scope_nation = first_scope_code + 0x0013;
5346 es_x_owned_scope_state, // constexpr inline uint16_t x_owned_scope_state = first_scope_code + 0x0014;
5347 es_x_core_scope, // constexpr inline uint16_t x_core_scope = first_scope_code + 0x0015;
5348 es_x_state_scope, // constexpr inline uint16_t x_state_scope = first_scope_code + 0x0016;
5349 es_random_list_scope, // constexpr inline uint16_t random_list_scope = first_scope_code + 0x0017;
5350 es_random_scope, // constexpr inline uint16_t random_scope = first_scope_code + 0x0018;
5351 es_owner_scope_state, // constexpr inline uint16_t owner_scope_state = first_scope_code + 0x0019;
5352 es_owner_scope_province, // constexpr inline uint16_t owner_scope_province = first_scope_code + 0x001A;
5353 es_controller_scope, // constexpr inline uint16_t controller_scope = first_scope_code + 0x001B;
5354 es_location_scope, // constexpr inline uint16_t location_scope = first_scope_code + 0x001C;
5355 es_country_scope_pop, // constexpr inline uint16_t country_scope_pop = first_scope_code + 0x001D;
5356 es_country_scope_state, // constexpr inline uint16_t country_scope_state = first_scope_code + 0x001E;
5357 es_capital_scope, // constexpr inline uint16_t capital_scope = first_scope_code + 0x001F;
5358 es_this_scope_nation, // constexpr inline uint16_t this_scope_nation = first_scope_code + 0x0020;
5359 es_this_scope_state, // constexpr inline uint16_t this_scope_state = first_scope_code + 0x0021;
5360 es_this_scope_province, // constexpr inline uint16_t this_scope_province = first_scope_code + 0x0022;
5361 es_this_scope_pop, // constexpr inline uint16_t this_scope_pop = first_scope_code + 0x0023;
5362 es_from_scope_nation, // constexpr inline uint16_t from_scope_nation = first_scope_code + 0x0024;
5363 es_from_scope_state, // constexpr inline uint16_t from_scope_state = first_scope_code + 0x0025;
5364 es_from_scope_province, // constexpr inline uint16_t from_scope_province = first_scope_code + 0x0026;
5365 es_from_scope_pop, // constexpr inline uint16_t from_scope_pop = first_scope_code + 0x0027;
5366 es_sea_zone_scope, // constexpr inline uint16_t sea_zone_scope = first_scope_code + 0x0028;
5367 es_cultural_union_scope, // constexpr inline uint16_t cultural_union_scope = first_scope_code + 0x0029;
5368 es_overlord_scope, // constexpr inline uint16_t overlord_scope = first_scope_code + 0x002A;
5369 es_sphere_owner_scope, // constexpr inline uint16_t sphere_owner_scope = first_scope_code + 0x002B;
5370 es_independence_scope, // constexpr inline uint16_t independence_scope = first_scope_code + 0x002C;
5371 es_flashpoint_tag_scope, // constexpr inline uint16_t flashpoint_tag_scope = first_scope_code + 0x002D;
5372 es_crisis_state_scope, // constexpr inline uint16_t crisis_state_scope = first_scope_code + 0x002E;
5373 es_state_scope_pop, // constexpr inline uint16_t state_scope_pop = first_scope_code + 0x002F;
5374 es_state_scope_province, // constexpr inline uint16_t state_scope_province = first_scope_code + 0x0030;
5375 es_x_substate_scope, // constexpr inline uint16_t x_state_scope = first_scope_code + 0x0031;
5376 es_capital_scope_province, // constexpr inline uint16_t capital_scope = first_scope_code + 0x0032;
5377 es_x_core_scope_province, //constexpr inline uint16_t x_core_scope_province = first_scope_code + 0x0033;
5378 es_tag_scope, // constexpr inline uint16_t tag_scope = first_scope_code + 0x0034;
5379 es_integer_scope, // constexpr inline uint16_t integer_scope = first_scope_code + 0x0035;
5380 es_pop_type_scope_nation, // constexpr inline uint16_t pop_type_scope_nation = first_scope_code + 0x0036;
5381 es_pop_type_scope_state, // constexpr inline uint16_t pop_type_scope_state = first_scope_code + 0x0037;
5382 es_pop_type_scope_province, // constexpr inline uint16_t pop_type_scope_province = first_scope_code + 0x0038;
5383 es_region_proper_scope, //constexpr inline uint16_t region_proper_scope = first_scope_code + 0x0039;
5384 es_region_scope, // constexpr inline uint16_t region_scope = first_scope_code + 0x003A;
5385 es_if_scope, // constexpr inline uint16_t if_scope = first_scope_code + 0x003B;
5386 es_else_if_scope, // constexpr inline uint16_t else_if_scope = first_scope_code + 0x003C;
5387 es_x_event_country_scope, // constexpr inline uint16_t x_event_country_scope = first_scope_code + 0x003D;
5388 es_x_decision_country_scope, // constexpr inline uint16_t x_decision_country_scope = first_scope_code + 0x003E;
5389 es_x_event_country_scope_nation,//constexpr inline uint16_t x_event_country_scope_nation = first_scope_code + 0x003F;
5390 es_x_decision_country_scope_nation,//constexpr inline uint16_t x_decision_country_scope_nation = first_scope_code + 0x0040;
5391 es_from_bounce_scope,//constexpr inline uint16_t from_bounce_scope = first_scope_code + 0x0041;
5392 es_this_bounce_scope,//constexpr inline uint16_t this_bounce_scope = first_scope_code + 0x0042;
5393 es_random_by_modifier_scope,//constexpr inline uint16_t random_by_modifier_scope = first_scope_code + 0x0043;
5394 es_x_neighbor_province_scope_nation, // constexpr inline uint16_t x_neighbor_province_scope_nation = first_scope_code + 0x0044;
5395 es_x_empty_neighbor_province_scope_nation // constexpr inline uint16_t x_empty_neighbor_province_scope_nation = first_scope_code + 0x0045;
5396 // constexpr inline uint16_t first_invalid_code = first_scope_code + 0x0045;
5397};
5398
5401 return effect_functions[*tval & effect::code_mask](tval, ws, primary_slot, this_slot, from_slot, r_lo, r_hi, els);
5402}
5403
5404void execute(sys::state& state, dcon::effect_key key, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo,
5405 uint32_t r_hi) {
5406 bool els = false;
5407 internal_execute_effect(state.effect_data.data() + state.effect_data_indices[key.index() + 1], state, primary, this_slot, from_slot, r_lo, r_hi, els);
5408}
5409
5410void execute(sys::state& state, uint16_t const* data, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo,
5411 uint32_t r_hi) {
5412 bool els = false;
5413 internal_execute_effect(data, state, primary, this_slot, from_slot, r_lo, r_hi, els);
5414}
5415
5416} // namespace effect
dcon::text_key get_name() noexcept
#define assert(condition)
Definition: debug.h:74
#define EFFECT_PARAMTERS
Definition: effects.cpp:16
void remove_ai_data(sys::state &state, dcon::nation_id n)
Definition: ai.cpp:3303
void apply_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
Definition: culture.cpp:500
void replace_cores(sys::state &state, dcon::national_identity_id old_tag, dcon::national_identity_id new_tag)
Definition: culture.cpp:1047
void remove_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
Definition: culture.cpp:606
void remove_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
Definition: culture.cpp:430
void apply_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
Definition: culture.cpp:360
void update_nation_issue_rules(sys::state &state, dcon::nation_id n_id)
Definition: culture.cpp:766
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
void reduce_pop_size_safe(sys::state &state, dcon::pop_id pop_id, int32_t amount)
void post(sys::state &state, message const &m)
constexpr dcon::commodity_id money(0)
void try_add_factory_to_state(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id t)
Definition: economy.cpp:5237
uint32_t ef_consciousness_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3354
uint32_t ef_add_province_modifier_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3549
uint32_t ef_is_slave_province_yes(EFFECT_PARAMTERS)
Definition: effects.cpp:1900
uint32_t ef_remove_core_state_this_pop(EFFECT_PARAMTERS)
Definition: effects.cpp:1663
uint32_t es_x_decision_country_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:424
uint32_t es_x_greater_power_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:475
uint32_t ef_remove_core_state_from_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:1676
uint32_t ef_release_vassal_province_from_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:2914
uint32_t ef_add_accepted_culture_union_this(EFFECT_PARAMTERS)
Definition: effects.cpp:1774
uint32_t es_poor_strata_scope_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:513
uint32_t es_this_bounce_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:407
uint32_t ef_is_slave_province_no(EFFECT_PARAMTERS)
Definition: effects.cpp:2998
uint32_t ef_release_vassal_province_this_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:2900
uint32_t ef_release_vassal_province_from_province(EFFECT_PARAMTERS)
Definition: effects.cpp:2921
uint32_t ef_reduce_pop_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3097
uint32_t ef_annex_to_null_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:5110
uint32_t es_if_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:37
uint32_t apply_subeffects(EFFECT_PARAMTERS)
Definition: effects.cpp:21
uint32_t ef_reduce_pop_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3079
uint32_t ef_remove_core_nation_this_pop(EFFECT_PARAMTERS)
Definition: effects.cpp:1619
constexpr uint16_t is_random_scope
uint32_t ef_set_country_flag_pop(EFFECT_PARAMTERS)
Definition: effects.cpp:4984
uint32_t ef_militancy_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3393
uint32_t es_x_country_scope_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:285
uint32_t ef_annex_to_null_province(EFFECT_PARAMTERS)
Definition: effects.cpp:5117
uint32_t ef_reduce_pop_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:3087
uint32_t es_x_decision_country_scope_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:360
uint32_t ef_release_vassal_province_random(EFFECT_PARAMTERS)
Definition: effects.cpp:2935
int32_t get_effect_scope_payload_size(uint16_t const *data)
uint32_t ef_bank_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3455
uint32_t ef_remove_core_state_from_province(EFFECT_PARAMTERS)
Definition: effects.cpp:1670
uint32_t ef_remove_core_state_reb(EFFECT_PARAMTERS)
Definition: effects.cpp:1679
int32_t effect_scope_data_payload(uint16_t code)
void execute(sys::state &state, dcon::effect_key key, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
Definition: effects.cpp:5404
uint32_t ef_release_vassal_province_this_province(EFFECT_PARAMTERS)
Definition: effects.cpp:2907
constexpr uint16_t code_mask
uint32_t ef_fort_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3435
uint32_t ef_flashpoint_tension_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3307
uint32_t ef_consciousness_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3334
uint32_t ef_infrastructure_state(EFFECT_PARAMTERS)
Definition: effects.cpp:2567
uint32_t internal_execute_effect(EFFECT_PARAMTERS)
Definition: effects.cpp:5399
uint32_t ef_remove_core_nation_this_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:1598
uint32_t es_x_event_country_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:421
uint32_t ef_political_reform_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3037
uint32_t es_x_neighbor_province_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:67
uint32_t ef_release_vassal_province_reb(EFFECT_PARAMTERS)
Definition: effects.cpp:2928
uint32_t es_generic_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:33
uint32_t ef_remove_core_tag_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:1585
uint32_t ef_remove_core_state_this_province(EFFECT_PARAMTERS)
Definition: effects.cpp:1649
uint32_t ef_remove_core_nation_reb(EFFECT_PARAMTERS)
Definition: effects.cpp:1635
uint32_t ef_life_rating_state(EFFECT_PARAMTERS)
Definition: effects.cpp:1868
uint32_t ef_university_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3462
uint32_t es_x_event_country_scope_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:323
uint32_t ef_remove_core_nation_this_state(EFFECT_PARAMTERS)
Definition: effects.cpp:1612
uint32_t es_x_country_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:418
int32_t get_generic_effect_payload_size(uint16_t const *data)
uint32_t es_x_empty_neighbor_province_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:427
uint32_t ef_add_accepted_culture_union_from(EFFECT_PARAMTERS)
Definition: effects.cpp:1794
constexpr uint16_t first_invalid_code
uint32_t ef_release_vassal_province(EFFECT_PARAMTERS)
Definition: effects.cpp:2893
uint32_t ef_naval_base_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3442
constexpr uint16_t scope_has_limit
uint32_t ef_remove_core_state_this_state(EFFECT_PARAMTERS)
Definition: effects.cpp:1656
uint32_t ef_remove_core_state_this_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:1642
uint32_t es_x_neighbor_country_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:238
uint32_t es_x_empty_neighbor_province_scope_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:189
uint32_t es_poor_strata_scope_state(EFFECT_PARAMTERS)
Definition: effects.cpp:540
uint32_t es_x_neighbor_province_scope_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:139
uint32_t ef_remove_core_nation_from_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:1632
uint32_t ef_remove_province_modifier_state(EFFECT_PARAMTERS)
Definition: effects.cpp:2707
uint32_t ef_militancy_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:3382
uint32_t ef_remove_core_nation_from_province(EFFECT_PARAMTERS)
Definition: effects.cpp:1626
std::vector< dcon::province_id > country_get_province_adjacency(sys::state &state, dcon::nation_id nat_id)
Definition: effects.cpp:119
uint32_t es_from_bounce_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:397
uint32_t ef_militancy_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3373
uint32_t ef_social_reform_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3020
uint32_t ef_remove_core_nation_this_province(EFFECT_PARAMTERS)
Definition: effects.cpp:1605
uint32_t ef_consciousness_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:3343
uint32_t ef_add_province_modifier_state_no_duration(EFFECT_PARAMTERS)
Definition: effects.cpp:3555
uint32_t es_else_if_scope(EFFECT_PARAMTERS)
Definition: effects.cpp:52
bool would_be_duplicate_instance(sys::state &state, dcon::national_event_id e, dcon::nation_id n, sys::date date)
Definition: events.cpp:459
void eject_ships(sys::state &state, dcon::province_id p)
Definition: military.cpp:6771
void remove_from_common_allied_wars(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:507
void end_wars_between(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:2084
bool has_truce_with(sys::state &state, dcon::nation_id attacker, dcon::nation_id target)
Definition: military.cpp:2037
bool standard_war_joining_is_possible(sys::state &state, dcon::war_id wfor, dcon::nation_id n, bool as_attacker)
Definition: military.cpp:2344
void add_wargoal(sys::state &state, dcon::war_id wfor, dcon::nation_id added_by, dcon::nation_id target, dcon::cb_type_id type, dcon::state_definition_id sd, dcon::national_identity_id tag, dcon::nation_id secondary_nation)
Definition: military.cpp:2409
dcon::war_id find_war_between(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:542
dcon::war_id create_war(sys::state &state, dcon::nation_id primary_attacker, dcon::nation_id primary_defender, dcon::cb_type_id primary_wargoal, dcon::state_definition_id primary_wargoal_state, dcon::national_identity_id primary_wargoal_tag, dcon::nation_id primary_wargoal_secondary)
Definition: military.cpp:2250
void add_truce(sys::state &state, dcon::nation_id a, dcon::nation_id b, int32_t days)
Definition: military.cpp:3193
void give_military_access(sys::state &state, dcon::nation_id accessing_nation, dcon::nation_id target)
Definition: military.cpp:2070
void call_attacker_allies(sys::state &state, dcon::war_id wfor)
Definition: military.cpp:2389
void remove_military_access(sys::state &state, dcon::nation_id accessing_nation, dcon::nation_id target)
Definition: military.cpp:2077
void kill_leader(sys::state &state, dcon::leader_id l)
Definition: military.cpp:1891
void call_defender_allies(sys::state &state, dcon::war_id wfor)
Definition: military.cpp:2358
constexpr uint8_t level_in_sphere
Definition: nations.hpp:169
constexpr uint8_t level_mask
Definition: nations.hpp:163
void make_uncivilized(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:2865
void break_alliance(sys::state &state, dcon::diplomatic_relation_id rel)
Definition: nations.cpp:1442
void adjust_prestige(sys::state &state, dcon::nation_id n, float delta)
Definition: nations.cpp:1330
void destroy_diplomatic_relationships(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:1348
void make_vassal(sys::state &state, dcon::nation_id subject, dcon::nation_id overlord)
Definition: nations.cpp:1393
void release_vassal(sys::state &state, dcon::overlord_id rel)
Definition: nations.cpp:1378
void update_pop_acceptance(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:2583
void make_alliance(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: nations.cpp:1467
void adjust_influence_with_overflow(sys::state &state, dcon::nation_id great_power, dcon::nation_id target, float delta)
Definition: nations.cpp:2681
void liberate_nation_from(sys::state &state, dcon::national_identity_id liberated, dcon::nation_id from)
Definition: nations.cpp:2602
float prestige_score(sys::state const &state, dcon::nation_id n)
Definition: nations.cpp:396
float daily_research_points(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:254
void make_civilized(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:2758
void adjust_relationship(sys::state &state, dcon::nation_id a, dcon::nation_id b, float delta)
Definition: nations.cpp:1094
void create_nation_based_on_template(sys::state &state, dcon::nation_id n, dcon::nation_id base)
Definition: nations.cpp:1106
void perform_nationalization(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:2658
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
Definition: nations.cpp:69
auto nation_accepts_culture(sys::state const &state, T ids, U cul_ids)
void switch_player(sys::state &state, dcon::nation_id new_n, dcon::nation_id old_n)
Definition: network.cpp:1152
void force_ruling_party_ideology(sys::state &state, dcon::nation_id n, dcon::ideology_id id)
Definition: politics.cpp:350
void set_issue_option(sys::state &state, dcon::nation_id n, dcon::issue_option_id opt)
Definition: politics.cpp:980
bool political_party_is_active(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
Definition: politics.cpp:323
void change_government_type(sys::state &state, dcon::nation_id n, dcon::government_type_id new_type)
Definition: politics.cpp:441
void update_displayed_identity(sys::state &state, dcon::nation_id id)
Definition: politics.cpp:429
void set_reform_option(sys::state &state, dcon::nation_id n, dcon::reform_option_id opt)
Definition: politics.cpp:990
void set_ruling_party(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
Definition: politics.cpp:333
void start_election(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:732
void set_militancy(sys::state &state, dcon::pop_id p, float v)
float get_employment(sys::state const &state, dcon::pop_id p)
void set_demo(sys::state &state, dcon::pop_id p, dcon::pop_demographics_key k, float v)
void set_consciousness(sys::state &state, dcon::pop_id p, float v)
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)
void set_literacy(sys::state &state, T p, ve::fp_vector v)
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
constexpr uint8_t coastal_bit
Definition: constants.hpp:594
void enable_canal(sys::state &state, int32_t id)
Definition: province.cpp:1545
void add_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1504
void remove_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1514
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
void set_rgo(sys::state &state, dcon::province_id prov, dcon::commodity_id c)
Definition: province.cpp:1525
void set_province_controller(sys::state &state, dcon::province_id p, dcon::nation_id n)
Definition: province.cpp:107
void change_province_owner(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
Definition: province.cpp:666
void trigger_revolt(sys::state &state, dcon::nation_id n, dcon::rebel_type_id t, dcon::ideology_id i, dcon::culture_id c, dcon::religion_id r)
Definition: rebels.cpp:1269
uint64_t get_random(sys::state const &state, uint32_t value_in)
Definition: prng.cpp:8
void remove_modifier_from_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id)
Definition: modifiers.cpp:87
void update_single_nation_modifiers(sys::state &state, dcon::nation_id n)
Definition: modifiers.cpp:426
void add_modifier_to_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id, sys::date expiration)
Definition: modifiers.cpp:63
void add_modifier_to_province(sys::state &state, dcon::province_id target_prov, dcon::modifier_id mod_id, sys::date expiration)
Definition: modifiers.cpp:75
void remove_modifier_from_province(sys::state &state, dcon::province_id target_prov, dcon::modifier_id mod_id)
Definition: modifiers.cpp:98
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
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
dcon::pop_id to_pop(int32_t v)
Definition: triggers.hpp:120
dcon::province_id to_prov(int32_t v)
Definition: triggers.hpp:88
int32_t read_int32_t_from_payload(uint16_t const *data)
Definition: triggers.cpp:133
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5865
dcon::rebel_faction_id to_rebel(int32_t v)
Definition: triggers.hpp:152
float read_float_from_payload(uint16_t const *data)
Definition: triggers.cpp:119
dcon::nation_id to_nation(int32_t v)
Definition: triggers.hpp:104
float evaluate_multiplicative_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5782
uint uint32_t
uchar uint8_t
#define EFFECT_BYTECODE_LIST
dcon::national_identity_id tag_id
dcon::culture_id cul_id
dcon::invention_id invt_id
dcon::cb_type_id cb_id
dcon::national_event_id nev_id
dcon::provincial_event_id pev_id
dcon::province_id prov_id
dcon::ideology_id ideo_id
dcon::technology_id tech_id
dcon::trigger_key tr_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::region_id reg_id
dcon::modifier_id mod_id