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_instance;
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}
1946uint32_t ef_diplo_points(EFFECT_PARAMTERS) {
1947 auto& dippts = ws.world.nation_get_diplomatic_points(trigger::to_nation(primary_slot));
1948 auto amount = trigger::read_float_from_payload(tval + 1);
1949 assert(std::isfinite(amount));
1950 dippts = std::max(0.0f, dippts + amount);
1951 return 0;
1952}
1954 auto amount = trigger::read_float_from_payload(tval + 1);
1955 assert(std::isfinite(amount));
1956 nations::adjust_prestige(ws, trigger::to_nation(primary_slot), amount);
1957 return 0;
1958}
1960 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
1961 culture::replace_cores(ws, tag, trigger::payload(tval[1]).tag_id);
1962 auto old_holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
1963 ws.world.nation_set_identity_from_identity_holder(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tag_id);
1965 if(old_holder) {
1966 ws.world.nation_set_identity_from_identity_holder(old_holder, tag);
1968 }
1969 return 0;
1970}
1971uint32_t ef_change_tag_culture(EFFECT_PARAMTERS) {
1972 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot));
1973 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
1974 auto u = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
1975 if(!u)
1976 return 0;
1977
1978 auto old_holder = ws.world.national_identity_get_nation_from_identity_holder(u);
1979 auto tag = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(primary_slot));
1980 culture::replace_cores(ws, tag, u);
1981 ws.world.nation_set_identity_from_identity_holder(trigger::to_nation(primary_slot), u);
1983 if(old_holder) {
1984 ws.world.nation_set_identity_from_identity_holder(old_holder, tag);
1986 }
1987 return 0;
1988}
1989uint32_t ef_change_tag_no_core_switch(EFFECT_PARAMTERS) {
1990 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
1991 if(!holder)
1992 return 0;
1993
1994 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot))) {
1995 network::switch_player(ws, holder, trigger::to_nation(primary_slot));
1996 } else if(ws.world.nation_get_is_player_controlled(holder)) {
1997 network::switch_player(ws, trigger::to_nation(primary_slot), holder);
1998 }
1999
2000 auto old_controller = ws.world.nation_get_is_player_controlled(holder);
2001 ws.world.nation_set_is_player_controlled(holder, ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)));
2002 ws.world.nation_set_is_player_controlled(trigger::to_nation(primary_slot), old_controller);
2003
2004 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
2005 ai::remove_ai_data(ws, trigger::to_nation(primary_slot));
2006 if(ws.world.nation_get_is_player_controlled(holder))
2007 ai::remove_ai_data(ws, holder);
2008
2009 if(ws.local_player_nation == trigger::to_nation(primary_slot)) {
2010 ws.local_player_nation = holder;
2011 } else if(ws.local_player_nation == holder) {
2012 ws.local_player_nation = trigger::to_nation(primary_slot);
2013 }
2014 return 0;
2015}
2016uint32_t ef_change_tag_no_core_switch_culture(EFFECT_PARAMTERS) {
2017 auto prim_culture = ws.world.nation_get_primary_culture(trigger::to_nation(primary_slot));
2018 auto cg = ws.world.culture_get_group_from_culture_group_membership(prim_culture);
2019 auto u = ws.world.culture_group_get_identity_from_cultural_union_of(cg);
2020 auto holder = ws.world.national_identity_get_nation_from_identity_holder(u);
2021 if(!holder)
2022 return 0;
2023
2024 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot))) {
2025 network::switch_player(ws, holder, trigger::to_nation(primary_slot));
2026 } else if(ws.world.nation_get_is_player_controlled(holder)) {
2027 network::switch_player(ws, trigger::to_nation(primary_slot), holder);
2028 }
2029
2030 auto old_controller = ws.world.nation_get_is_player_controlled(holder);
2031 ws.world.nation_set_is_player_controlled(holder, ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)));
2032 ws.world.nation_set_is_player_controlled(trigger::to_nation(primary_slot), old_controller);
2033
2034 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
2035 ai::remove_ai_data(ws, trigger::to_nation(primary_slot));
2036 if(ws.world.nation_get_is_player_controlled(holder))
2037 ai::remove_ai_data(ws, holder);
2038
2039 if(ws.local_player_nation == trigger::to_nation(primary_slot)) {
2040 ws.local_player_nation = holder;
2041 } else if(ws.local_player_nation == holder) {
2042 ws.local_player_nation = trigger::to_nation(primary_slot);
2043 }
2044 return 0;
2045}
2046uint32_t ef_set_country_flag(EFFECT_PARAMTERS) {
2047 ws.world.nation_set_flag_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natf_id, true);
2048 return 0;
2049}
2050uint32_t ef_clr_country_flag(EFFECT_PARAMTERS) {
2051 ws.world.nation_set_flag_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natf_id, false);
2052 return 0;
2053}
2054uint32_t ef_military_access(EFFECT_PARAMTERS) {
2055 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2056 if(target)
2057 military::give_military_access(ws, trigger::to_nation(primary_slot), target);
2058 return 0;
2059}
2060uint32_t ef_military_access_this_nation(EFFECT_PARAMTERS) {
2062 return 0;
2063}
2064uint32_t ef_military_access_this_province(EFFECT_PARAMTERS) {
2065 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2066 if(target)
2067 military::give_military_access(ws, trigger::to_nation(primary_slot), target);
2068 return 0;
2069}
2070uint32_t ef_military_access_from_nation(EFFECT_PARAMTERS) {
2072 return 0;
2073}
2074uint32_t ef_military_access_from_province(EFFECT_PARAMTERS) {
2075 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2076 if(target)
2077 military::give_military_access(ws, trigger::to_nation(primary_slot), target);
2078 return 0;
2079}
2081 auto& inf = ws.world.nation_get_infamy(trigger::to_nation(primary_slot));
2082 auto amount = trigger::read_float_from_payload(tval + 1);
2083 assert(std::isfinite(amount));
2084 inf = std::max(0.0f, inf + amount);
2085 return 0;
2086}
2087uint32_t ef_secede_province(EFFECT_PARAMTERS) {
2088 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2089 if(!holder)
2090 return 0;
2091 auto hprovs = ws.world.nation_get_province_ownership(holder);
2092 if(hprovs.begin() == hprovs.end()) {
2093 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2094 if(powner)
2095 nations::create_nation_based_on_template(ws, holder, powner);
2096 }
2097 province::change_province_owner(ws, trigger::to_prov(primary_slot), holder);
2098 return 0;
2099}
2100uint32_t ef_secede_province_state(EFFECT_PARAMTERS) {
2101 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2102 if(!holder)
2103 return 0;
2104 auto hprovs = ws.world.nation_get_province_ownership(holder);
2105 if(hprovs.begin() == hprovs.end()) {
2106 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2107 if(powner)
2108 nations::create_nation_based_on_template(ws, holder, powner);
2109 }
2111 [&](dcon::province_id p) { province::change_province_owner(ws, p, holder); });
2112 return 0;
2113}
2114uint32_t ef_secede_province_state_this_nation(EFFECT_PARAMTERS) {
2115 auto target = trigger::to_nation(this_slot);
2116 auto hprovs = ws.world.nation_get_province_ownership(target);
2117 if(hprovs.begin() == hprovs.end()) {
2118 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2119 if(powner)
2120 nations::create_nation_based_on_template(ws, target, powner);
2121 }
2123 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2124 return 0;
2125}
2126uint32_t ef_secede_province_state_this_state(EFFECT_PARAMTERS) {
2127 auto target = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2128 if(!target)
2129 return 0;
2130 auto hprovs = ws.world.nation_get_province_ownership(target);
2131 if(hprovs.begin() == hprovs.end()) {
2132 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2133 if(powner)
2134 nations::create_nation_based_on_template(ws, target, powner);
2135 }
2137 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2138 return 0;
2139}
2140uint32_t ef_secede_province_state_this_province(EFFECT_PARAMTERS) {
2141 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2142 if(!target)
2143 return 0;
2144 auto hprovs = ws.world.nation_get_province_ownership(target);
2145 if(hprovs.begin() == hprovs.end()) {
2146 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2147 if(powner)
2148 nations::create_nation_based_on_template(ws, target, powner);
2149 }
2151 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2152 return 0;
2153}
2154uint32_t ef_secede_province_state_this_pop(EFFECT_PARAMTERS) {
2155 auto target = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2156 if(!target)
2157 return 0;
2158 auto hprovs = ws.world.nation_get_province_ownership(target);
2159 if(hprovs.begin() == hprovs.end()) {
2160 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2161 if(powner)
2162 nations::create_nation_based_on_template(ws, target, powner);
2163 }
2165 [&](dcon::province_id p) { province::change_province_owner(ws, p, target); });
2166 return 0;
2167}
2168uint32_t ef_secede_province_state_from_nation(EFFECT_PARAMTERS) {
2169 return ef_secede_province_state_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2170}
2171uint32_t ef_secede_province_state_from_province(EFFECT_PARAMTERS) {
2172 return ef_secede_province_state_this_province(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2173}
2174uint32_t ef_secede_province_state_reb(EFFECT_PARAMTERS) {
2175 auto target = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
2176 auto holder = ws.world.national_identity_get_nation_from_identity_holder(target);
2177 if(!holder)
2178 return 0;
2179 auto hprovs = ws.world.nation_get_province_ownership(holder);
2180 if(hprovs.begin() == hprovs.end()) {
2181 auto powner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot));
2182 if(powner)
2183 nations::create_nation_based_on_template(ws, holder, powner);
2184 }
2186 [&](dcon::province_id p) { province::change_province_owner(ws, p, holder); });
2187 return 0;
2188}
2189
2190uint32_t ef_secede_province_this_nation(EFFECT_PARAMTERS) {
2191 auto target = trigger::to_nation(this_slot);
2192 auto hprovs = ws.world.nation_get_province_ownership(target);
2193 if(hprovs.begin() == hprovs.end()) {
2194 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2195 if(powner)
2196 nations::create_nation_based_on_template(ws, target, powner);
2197 }
2198 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2199 return 0;
2200}
2201uint32_t ef_secede_province_this_state(EFFECT_PARAMTERS) {
2202 auto target = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2203 if(!target)
2204 return 0;
2205 auto hprovs = ws.world.nation_get_province_ownership(target);
2206 if(hprovs.begin() == hprovs.end()) {
2207 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2208 if(powner)
2209 nations::create_nation_based_on_template(ws, target, powner);
2210 }
2211 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2212 return 0;
2213}
2214uint32_t ef_secede_province_this_province(EFFECT_PARAMTERS) {
2215 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2216 if(!target)
2217 return 0;
2218 auto hprovs = ws.world.nation_get_province_ownership(target);
2219 if(hprovs.begin() == hprovs.end()) {
2220 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2221 if(powner)
2222 nations::create_nation_based_on_template(ws, target, powner);
2223 }
2224 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2225 return 0;
2226}
2227uint32_t ef_secede_province_this_pop(EFFECT_PARAMTERS) {
2228 auto target = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2229 if(!target)
2230 return 0;
2231 auto hprovs = ws.world.nation_get_province_ownership(target);
2232 if(hprovs.begin() == hprovs.end()) {
2233 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2234 if(powner)
2235 nations::create_nation_based_on_template(ws, target, powner);
2236 }
2237 province::change_province_owner(ws, trigger::to_prov(primary_slot), target);
2238 return 0;
2239}
2240uint32_t ef_secede_province_from_nation(EFFECT_PARAMTERS) {
2241 return ef_secede_province_this_nation(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2242}
2243uint32_t ef_secede_province_from_province(EFFECT_PARAMTERS) {
2244 return ef_secede_province_this_province(tval, ws, primary_slot, from_slot, 0, r_hi, r_lo, els);
2245}
2246uint32_t ef_secede_province_reb(EFFECT_PARAMTERS) {
2247 auto target = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
2248 auto holder = ws.world.national_identity_get_nation_from_identity_holder(target);
2249 if(!holder)
2250 return 0;
2251 auto hprovs = ws.world.nation_get_province_ownership(holder);
2252 if(hprovs.begin() == hprovs.end()) {
2253 auto powner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2254 if(powner)
2255 nations::create_nation_based_on_template(ws, holder, powner);
2256 }
2257 province::change_province_owner(ws, trigger::to_prov(primary_slot), holder);
2258 return 0;
2259}
2261 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2262 if(!holder || holder == trigger::to_nation(primary_slot))
2263 return 0;
2264 auto hprovs = ws.world.nation_get_province_ownership(holder);
2265 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2266 if(sprovs.begin() == sprovs.end()) {
2268 }
2269 while(hprovs.begin() != hprovs.end()) {
2270 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2271 }
2272 return 0;
2273}
2274uint32_t ef_inherit_this_nation(EFFECT_PARAMTERS) {
2275 auto holder = trigger::to_nation(this_slot);
2276 if(holder == trigger::to_nation(primary_slot))
2277 return 0;
2278 auto hprovs = ws.world.nation_get_province_ownership(holder);
2279 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2280 if(sprovs.begin() == sprovs.end()) {
2282 }
2283 while(hprovs.begin() != hprovs.end()) {
2284 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2285 }
2286 return 0;
2287}
2288uint32_t ef_inherit_this_state(EFFECT_PARAMTERS) {
2289 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2290 if(!holder || holder == trigger::to_nation(primary_slot))
2291 return 0;
2292 auto hprovs = ws.world.nation_get_province_ownership(holder);
2293 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2294 if(sprovs.begin() == sprovs.end()) {
2296 }
2297 while(hprovs.begin() != hprovs.end()) {
2298 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2299 }
2300 return 0;
2301}
2302uint32_t ef_inherit_this_province(EFFECT_PARAMTERS) {
2303 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2304 if(!holder || holder == trigger::to_nation(primary_slot))
2305 return 0;
2306 auto hprovs = ws.world.nation_get_province_ownership(holder);
2307 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2308 if(sprovs.begin() == sprovs.end()) {
2310 }
2311 while(hprovs.begin() != hprovs.end()) {
2312 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2313 }
2314 return 0;
2315}
2316uint32_t ef_inherit_this_pop(EFFECT_PARAMTERS) {
2317 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2318 if(!holder || holder == trigger::to_nation(primary_slot))
2319 return 0;
2320 auto hprovs = ws.world.nation_get_province_ownership(holder);
2321 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2322 if(sprovs.begin() == sprovs.end()) {
2324 }
2325 while(hprovs.begin() != hprovs.end()) {
2326 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2327 }
2328 return 0;
2329}
2330uint32_t ef_inherit_from_nation(EFFECT_PARAMTERS) {
2331 auto holder = trigger::to_nation(from_slot);
2332 if(holder == trigger::to_nation(primary_slot))
2333 return 0;
2334 auto hprovs = ws.world.nation_get_province_ownership(holder);
2335 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2336 if(sprovs.begin() == sprovs.end()) {
2338 }
2339 while(hprovs.begin() != hprovs.end()) {
2340 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2341 }
2342 return 0;
2343}
2344uint32_t ef_inherit_from_province(EFFECT_PARAMTERS) {
2345 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2346 if(!holder || holder == trigger::to_nation(primary_slot))
2347 return 0;
2348 auto hprovs = ws.world.nation_get_province_ownership(holder);
2349 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2350 if(sprovs.begin() == sprovs.end()) {
2352 }
2353 while(hprovs.begin() != hprovs.end()) {
2354 province::change_province_owner(ws, (*hprovs.begin()).get_province().id, trigger::to_nation(primary_slot));
2355 }
2356 return 0;
2357}
2359 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2360 if(!holder || holder == trigger::to_nation(primary_slot))
2361 return 0;
2362 auto hprovs = ws.world.nation_get_province_ownership(holder);
2363 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2364 if(hprovs.begin() == hprovs.end()) {
2366 }
2367 while(sprovs.begin() != sprovs.end()) {
2368 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2369 }
2370 return 0;
2371}
2372uint32_t ef_annex_to_this_nation(EFFECT_PARAMTERS) {
2373 auto holder = trigger::to_nation(this_slot);
2374 if(holder == trigger::to_nation(primary_slot))
2375 return 0;
2376 auto hprovs = ws.world.nation_get_province_ownership(holder);
2377 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2378 if(hprovs.begin() == hprovs.end()) {
2380 }
2381 while(sprovs.begin() != sprovs.end()) {
2382 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2383 }
2384 return 0;
2385}
2386uint32_t ef_annex_to_this_state(EFFECT_PARAMTERS) {
2387 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2388 if(!holder || holder == trigger::to_nation(primary_slot))
2389 return 0;
2390 auto hprovs = ws.world.nation_get_province_ownership(holder);
2391 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2392 if(hprovs.begin() == hprovs.end()) {
2394 }
2395 while(sprovs.begin() != sprovs.end()) {
2396 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2397 }
2398 return 0;
2399}
2400uint32_t ef_annex_to_this_province(EFFECT_PARAMTERS) {
2401 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2402 if(!holder || holder == trigger::to_nation(primary_slot))
2403 return 0;
2404 auto hprovs = ws.world.nation_get_province_ownership(holder);
2405 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2406 if(hprovs.begin() == hprovs.end()) {
2408 }
2409 while(sprovs.begin() != sprovs.end()) {
2410 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2411 }
2412 return 0;
2413}
2414uint32_t ef_annex_to_this_pop(EFFECT_PARAMTERS) {
2415 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2416 if(!holder || holder == trigger::to_nation(primary_slot))
2417 return 0;
2418 auto hprovs = ws.world.nation_get_province_ownership(holder);
2419 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2420 if(hprovs.begin() == hprovs.end()) {
2422 }
2423 while(sprovs.begin() != sprovs.end()) {
2424 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2425 }
2426 return 0;
2427}
2428uint32_t ef_annex_to_from_nation(EFFECT_PARAMTERS) {
2429 auto holder = trigger::to_nation(from_slot);
2430 if(holder == trigger::to_nation(primary_slot))
2431 return 0;
2432 auto hprovs = ws.world.nation_get_province_ownership(holder);
2433 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2434 if(hprovs.begin() == hprovs.end()) {
2436 }
2437 while(sprovs.begin() != sprovs.end()) {
2438 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2439 }
2440 return 0;
2441}
2442uint32_t ef_annex_to_from_province(EFFECT_PARAMTERS) {
2443 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2444 if(!holder || holder == trigger::to_nation(primary_slot))
2445 return 0;
2446 auto hprovs = ws.world.nation_get_province_ownership(holder);
2447 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
2448 if(hprovs.begin() == hprovs.end()) {
2450 }
2451 while(sprovs.begin() != sprovs.end()) {
2452 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, holder);
2453 }
2454 return 0;
2455}
2457 nations::liberate_nation_from(ws, trigger::payload(tval[1]).tag_id, trigger::to_nation(primary_slot));
2458 return 0;
2459}
2460uint32_t ef_release_this_nation(EFFECT_PARAMTERS) {
2461 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot)),
2462 trigger::to_nation(primary_slot));
2463 return 0;
2464}
2465uint32_t ef_release_this_state(EFFECT_PARAMTERS) {
2466 auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
2467 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2468}
2469uint32_t ef_release_this_province(EFFECT_PARAMTERS) {
2470 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2471 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2472}
2473uint32_t ef_release_this_pop(EFFECT_PARAMTERS) {
2474 auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
2475 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2476}
2477uint32_t ef_release_from_nation(EFFECT_PARAMTERS) {
2478 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(from_slot)),
2479 trigger::to_nation(primary_slot));
2480 return 0;
2481}
2482uint32_t ef_release_from_province(EFFECT_PARAMTERS) {
2483 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2484 return ef_release_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_hi, r_lo, els);
2485}
2486uint32_t ef_change_controller(EFFECT_PARAMTERS) {
2487 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2488 if(holder) {
2489 province::set_province_controller(ws, trigger::to_prov(primary_slot), holder);
2490 military::eject_ships(ws, trigger::to_prov(primary_slot));
2491 }
2492 return 0;
2493}
2494uint32_t ef_change_controller_this_nation(EFFECT_PARAMTERS) {
2496 military::eject_ships(ws, trigger::to_prov(primary_slot));
2497 return 0;
2498}
2499uint32_t ef_change_controller_this_province(EFFECT_PARAMTERS) {
2500 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2501 if(owner) {
2502 province::set_province_controller(ws, trigger::to_prov(primary_slot), owner);
2503 military::eject_ships(ws, trigger::to_prov(primary_slot));
2504 }
2505 return 0;
2506}
2507uint32_t ef_change_controller_from_nation(EFFECT_PARAMTERS) {
2509 military::eject_ships(ws, trigger::to_prov(primary_slot));
2510 return 0;
2511}
2512uint32_t ef_change_controller_from_province(EFFECT_PARAMTERS) {
2513 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2514 if(owner) {
2515 province::set_province_controller(ws, trigger::to_prov(primary_slot), owner);
2516 military::eject_ships(ws, trigger::to_prov(primary_slot));
2517 }
2518 return 0;
2519}
2520uint32_t ef_change_controller_state(EFFECT_PARAMTERS) {
2521 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2522 if(holder) {
2523 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2524 province::set_province_controller(ws, p, holder);
2525 military::eject_ships(ws, p);
2526 });
2527 }
2528 return 0;
2529}
2530uint32_t ef_change_controller_state_this_nation(EFFECT_PARAMTERS) {
2531 auto holder = trigger::to_nation(this_slot);
2532 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2533 province::set_province_controller(ws, p, holder);
2534 military::eject_ships(ws, p);
2535 });
2536 return 0;
2537}
2538uint32_t ef_change_controller_state_this_province(EFFECT_PARAMTERS) {
2539 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2540 if(holder) {
2541 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2542 province::set_province_controller(ws, p, holder);
2543 military::eject_ships(ws, p);
2544 });
2545 }
2546 return 0;
2547}
2548uint32_t ef_change_controller_state_from_nation(EFFECT_PARAMTERS) {
2549 auto holder = trigger::to_nation(from_slot);
2550 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2551 province::set_province_controller(ws, p, holder);
2552 military::eject_ships(ws, p);
2553 });
2554 return 0;
2555}
2556uint32_t ef_change_controller_state_from_province(EFFECT_PARAMTERS) {
2557 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2558 if(holder) {
2559 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, holder](dcon::province_id p) {
2560 province::set_province_controller(ws, p, holder);
2561 military::eject_ships(ws, p);
2562 });
2563 }
2564 return 0;
2565}
2566uint32_t ef_infrastructure(EFFECT_PARAMTERS) {
2567 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::railroad));
2568 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value),
2569 0,
2570 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)))));
2571 ws.railroad_built.store(true, std::memory_order::release);
2572 return 0;
2573}
2575 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
2576 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad));
2577 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value),
2578 0,
2579 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)))));
2580 });
2581 ws.railroad_built.store(true, std::memory_order::release);
2582 return 0;
2583}
2584
2586 auto& m = ws.world.pop_get_savings(trigger::to_pop(primary_slot));
2587 auto amount = trigger::read_float_from_payload(tval + 1);
2588 assert(std::isfinite(amount));
2589 m = std::max(0.0f, m + amount);
2590 return 0;
2591}
2593 ws.world.nation_get_leadership_points(trigger::to_nation(primary_slot)) += float(trigger::payload(tval[1]).signed_value);
2594 return 0;
2595}
2596uint32_t ef_create_vassal(EFFECT_PARAMTERS) {
2597 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2598 if(!holder)
2599 return 0;
2600 nations::make_vassal(ws, holder, trigger::to_nation(primary_slot));
2601 return 0;
2602}
2603uint32_t ef_create_vassal_this_nation(EFFECT_PARAMTERS) {
2604 nations::make_vassal(ws, trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2605 return 0;
2606}
2607uint32_t ef_create_vassal_this_province(EFFECT_PARAMTERS) {
2608 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2609 if(!holder)
2610 return 0;
2611 nations::make_vassal(ws, holder, trigger::to_nation(primary_slot));
2612 return 0;
2613}
2614uint32_t ef_create_vassal_from_nation(EFFECT_PARAMTERS) {
2615 nations::make_vassal(ws, trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2616 return 0;
2617}
2618uint32_t ef_create_vassal_from_province(EFFECT_PARAMTERS) {
2619 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2620 if(!holder)
2621 return 0;
2622 nations::make_vassal(ws, holder, trigger::to_nation(primary_slot));
2623 return 0;
2624}
2625uint32_t ef_end_military_access(EFFECT_PARAMTERS) {
2626 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2627 if(target)
2628 military::remove_military_access(ws, trigger::to_nation(primary_slot), target);
2629 return 0;
2630}
2631uint32_t ef_end_military_access_this_nation(EFFECT_PARAMTERS) {
2633 return 0;
2634}
2635uint32_t ef_end_military_access_this_province(EFFECT_PARAMTERS) {
2636 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2637 if(target)
2638 military::remove_military_access(ws, trigger::to_nation(primary_slot), target);
2639 return 0;
2640}
2641uint32_t ef_end_military_access_from_nation(EFFECT_PARAMTERS) {
2643 return 0;
2644}
2645uint32_t ef_end_military_access_from_province(EFFECT_PARAMTERS) {
2646 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2647 if(target)
2648 military::remove_military_access(ws, trigger::to_nation(primary_slot), target);
2649 return 0;
2650}
2651uint32_t ef_leave_alliance(EFFECT_PARAMTERS) {
2652 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2653 nations::break_alliance(ws, holder, trigger::to_nation(primary_slot));
2654 return 0;
2655}
2656uint32_t ef_leave_alliance_this_nation(EFFECT_PARAMTERS) {
2657 nations::break_alliance(ws, trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2658 return 0;
2659}
2660uint32_t ef_leave_alliance_this_province(EFFECT_PARAMTERS) {
2661 nations::break_alliance(ws, ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)),
2662 trigger::to_nation(primary_slot));
2663 return 0;
2664}
2665uint32_t ef_leave_alliance_from_nation(EFFECT_PARAMTERS) {
2666 nations::break_alliance(ws, trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2667 return 0;
2668}
2669uint32_t ef_leave_alliance_from_province(EFFECT_PARAMTERS) {
2670 nations::break_alliance(ws, ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)),
2671 trigger::to_nation(primary_slot));
2672 return 0;
2673}
2675 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2676 military::end_wars_between(ws, trigger::to_nation(primary_slot), target);
2677 return 0;
2678}
2679uint32_t ef_end_war_this_nation(EFFECT_PARAMTERS) {
2681 return 0;
2682}
2683uint32_t ef_end_war_this_province(EFFECT_PARAMTERS) {
2684 military::end_wars_between(ws, trigger::to_nation(primary_slot), ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)));
2685 return 0;
2686}
2687uint32_t ef_end_war_from_nation(EFFECT_PARAMTERS) {
2689 return 0;
2690}
2691uint32_t ef_end_war_from_province(EFFECT_PARAMTERS) {
2692 military::end_wars_between(ws, trigger::to_nation(primary_slot), ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)));
2693 return 0;
2694}
2695uint32_t ef_enable_ideology(EFFECT_PARAMTERS) {
2696 ws.world.ideology_set_enabled(trigger::payload(tval[1]).ideo_id, true);
2697 return 0;
2698}
2699uint32_t ef_ruling_party_ideology(EFFECT_PARAMTERS) {
2701 return 0;
2702}
2704 auto& plur = ws.world.nation_get_plurality(trigger::to_nation(primary_slot));
2705 auto amount = trigger::read_float_from_payload(tval + 1);
2706 assert(std::isfinite(amount));
2707 plur = std::clamp(plur + amount, 0.0f, 100.0f);
2708 return 0;
2709}
2710uint32_t ef_remove_province_modifier(EFFECT_PARAMTERS) {
2711 sys::remove_modifier_from_province(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).mod_id);
2712 return 0;
2713}
2715 auto mod = trigger::payload(tval[1]).mod_id;
2716 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
2718 });
2719 return 0;
2720}
2721uint32_t ef_remove_country_modifier(EFFECT_PARAMTERS) {
2722 sys::remove_modifier_from_nation(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id);
2723 return 0;
2724}
2725uint32_t ef_create_alliance(EFFECT_PARAMTERS) {
2726 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2727 if(holder && ws.world.nation_get_owned_province_count(holder) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2728 nations::make_alliance(ws, holder, trigger::to_nation(primary_slot));
2729 return 0;
2730}
2731uint32_t ef_create_alliance_this_nation(EFFECT_PARAMTERS) {
2732 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)
2733 nations::make_alliance(ws, trigger::to_nation(primary_slot), trigger::to_nation(this_slot));
2734 return 0;
2735}
2736uint32_t ef_create_alliance_this_province(EFFECT_PARAMTERS) {
2737 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2738 if(owner && ws.world.nation_get_owned_province_count(owner) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2739 nations::make_alliance(ws, trigger::to_nation(primary_slot), owner);
2740 return 0;
2741}
2742uint32_t ef_create_alliance_from_nation(EFFECT_PARAMTERS) {
2743 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)
2744 nations::make_alliance(ws, trigger::to_nation(primary_slot), trigger::to_nation(from_slot));
2745 return 0;
2746}
2747uint32_t ef_create_alliance_from_province(EFFECT_PARAMTERS) {
2748 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2749 if(owner && ws.world.nation_get_owned_province_count(owner) != 0 && ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) != 0)
2750 nations::make_alliance(ws, trigger::to_nation(primary_slot), owner);
2751 return 0;
2752}
2753uint32_t ef_release_vassal(EFFECT_PARAMTERS) {
2754 auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
2755 if(!holder)
2756 return 0;
2757 auto hprovs = ws.world.nation_get_province_ownership(holder);
2758 if(hprovs.begin() == hprovs.end()) {
2759 nations::liberate_nation_from(ws, trigger::payload(tval[1]).tag_id, trigger::to_nation(primary_slot));
2760 if(ws.world.nation_get_owned_province_count(holder) == 0)
2761 return 0;
2762 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2763 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2764 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2765 auto& flags = ws.world.gp_relationship_get_status(sr);
2767 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2768 }
2769 } else {
2770 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2771 if(rel) {
2772 nations::release_vassal(ws, rel);
2773 }
2774 }
2775 return 0;
2776}
2777uint32_t ef_release_vassal_this_nation(EFFECT_PARAMTERS) {
2778 auto hprovs = ws.world.nation_get_province_ownership(trigger::to_nation(this_slot));
2779 if(hprovs.begin() == hprovs.end()) {
2780 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot)),
2781 trigger::to_nation(primary_slot));
2782 if(ws.world.nation_get_owned_province_count(trigger::to_nation(this_slot)) == 0)
2783 return 0;
2784 ws.world.force_create_overlord(trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2785 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2786 auto sr = ws.world.force_create_gp_relationship(trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2787 auto& flags = ws.world.gp_relationship_get_status(sr);
2789 ws.world.nation_set_in_sphere_of(trigger::to_nation(this_slot), trigger::to_nation(primary_slot));
2790 }
2791 } else {
2792 auto rel = ws.world.nation_get_overlord_as_subject(trigger::to_nation(this_slot));
2793 if(rel) {
2794 nations::release_vassal(ws, rel);
2795 }
2796 }
2797 return 0;
2798}
2799uint32_t ef_release_vassal_this_province(EFFECT_PARAMTERS) {
2800 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
2801 if(!holder)
2802 return 0;
2803 auto hprovs = ws.world.nation_get_province_ownership(holder);
2804 if(hprovs.begin() == hprovs.end()) {
2805 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(holder),
2806 trigger::to_nation(primary_slot));
2807 if(ws.world.nation_get_owned_province_count(holder) == 0)
2808 return 0;
2809 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2810 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2811 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2812 auto& flags = ws.world.gp_relationship_get_status(sr);
2814 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2815 }
2816 } else {
2817 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2818 if(rel) {
2819 nations::release_vassal(ws, rel);
2820 }
2821 }
2822 return 0;
2823}
2824uint32_t ef_release_vassal_from_nation(EFFECT_PARAMTERS) {
2825 auto hprovs = ws.world.nation_get_province_ownership(trigger::to_nation(from_slot));
2826 if(hprovs.begin() == hprovs.end()) {
2827 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot)),
2828 trigger::to_nation(primary_slot));
2829 if(ws.world.nation_get_owned_province_count(trigger::to_nation(from_slot)) == 0)
2830 return 0;
2831 ws.world.force_create_overlord(trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2832 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2833 auto sr = ws.world.force_create_gp_relationship(trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2834 auto& flags = ws.world.gp_relationship_get_status(sr);
2836 ws.world.nation_set_in_sphere_of(trigger::to_nation(from_slot), trigger::to_nation(primary_slot));
2837 }
2838 } else {
2839 auto rel = ws.world.nation_get_overlord_as_subject(trigger::to_nation(from_slot));
2840 if(rel) {
2841 nations::release_vassal(ws, rel);
2842 }
2843 }
2844 return 0;
2845}
2846uint32_t ef_release_vassal_from_province(EFFECT_PARAMTERS) {
2847 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
2848 if(!holder)
2849 return 0;
2850 auto hprovs = ws.world.nation_get_province_ownership(holder);
2851 if(hprovs.begin() == hprovs.end()) {
2852 nations::liberate_nation_from(ws, ws.world.nation_get_identity_from_identity_holder(holder),
2853 trigger::to_nation(primary_slot));
2854 if(ws.world.nation_get_owned_province_count(holder) == 0)
2855 return 0;
2856 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2857 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2858 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2859 auto& flags = ws.world.gp_relationship_get_status(sr);
2861 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2862 }
2863 } else {
2864 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2865 if(rel) {
2866 nations::release_vassal(ws, rel);
2867 }
2868 }
2869 return 0;
2870}
2871uint32_t ef_release_vassal_reb(EFFECT_PARAMTERS) {
2872 auto itag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
2873 auto holder = ws.world.national_identity_get_nation_from_identity_holder(itag);
2874 if(!holder)
2875 return 0;
2876 auto hprovs = ws.world.nation_get_province_ownership(holder);
2877 if(hprovs.begin() == hprovs.end()) {
2878 nations::liberate_nation_from(ws, itag, trigger::to_nation(primary_slot));
2879 if(ws.world.nation_get_owned_province_count(holder) == 0)
2880 return 0;
2881 ws.world.force_create_overlord(holder, trigger::to_nation(primary_slot));
2882 if(ws.world.nation_get_is_great_power(trigger::to_nation(primary_slot))) {
2883 auto sr = ws.world.force_create_gp_relationship(holder, trigger::to_nation(primary_slot));
2884 auto& flags = ws.world.gp_relationship_get_status(sr);
2886 ws.world.nation_set_in_sphere_of(holder, trigger::to_nation(primary_slot));
2887 }
2888 } else {
2889 auto rel = ws.world.nation_get_overlord_as_subject(holder);
2890 if(rel) {
2891 nations::release_vassal(ws, rel);
2892 }
2893 }
2894 return 0;
2895}
2896uint32_t ef_release_vassal_random(EFFECT_PARAMTERS) {
2897 // unused
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(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_nation(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_this_province(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_nation(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_from_province(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_reb(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2939 else
2940 return 0;
2941}
2943 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2944 if(owner)
2945 return ef_release_vassal_random(tval, ws, trigger::to_generic(owner), this_slot, from_slot, r_hi, r_lo, els);
2946 else
2947 return 0;
2948}
2949uint32_t ef_change_province_name(EFFECT_PARAMTERS) {
2950 dcon::text_key name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
2951 ws.world.province_set_name(trigger::to_prov(primary_slot), name);
2952 return 0;
2953}
2954uint32_t ef_enable_canal(EFFECT_PARAMTERS) {
2955 province::enable_canal(ws, tval[1] - 1);
2956 return 0;
2957}
2958uint32_t ef_set_global_flag(EFFECT_PARAMTERS) {
2959 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, true);
2960 return 0;
2961}
2962uint32_t ef_clr_global_flag(EFFECT_PARAMTERS) {
2963 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
2964 return 0;
2965}
2966uint32_t ef_nationalvalue_province(EFFECT_PARAMTERS) {
2967 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
2968 if(owner)
2969 ws.world.nation_set_national_value(owner, trigger::payload(tval[1]).mod_id);
2970 return 0;
2971}
2972uint32_t ef_nationalvalue_nation(EFFECT_PARAMTERS) {
2973 ws.world.nation_set_national_value(trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id);
2974 return 0;
2975}
2976uint32_t ef_civilized_yes(EFFECT_PARAMTERS) {
2978 return 0;
2979}
2980uint32_t ef_civilized_no(EFFECT_PARAMTERS) {
2982 return 0;
2983}
2984uint32_t ef_is_slave_state_no(EFFECT_PARAMTERS) {
2985 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
2986 ws.world.province_set_is_slave(p, false);
2987 bool mine = ws.world.commodity_get_is_mine(ws.world.province_get_rgo(p));
2988 for(auto pop : ws.world.province_get_pop_location(p)) {
2989 if(pop.get_pop().get_poptype() == ws.culture_definitions.slaves) {
2990 pop.get_pop().set_poptype(mine ? ws.culture_definitions.laborers : ws.culture_definitions.farmers);
2991 }
2992 }
2993 });
2994 return 0;
2995}
2996uint32_t ef_is_slave_pop_no(EFFECT_PARAMTERS) {
2997 if(ws.world.pop_get_poptype(trigger::to_pop(primary_slot)) == ws.culture_definitions.slaves) {
2998 bool mine = ws.world.commodity_get_is_mine(
2999 ws.world.province_get_rgo(ws.world.pop_get_province_from_pop_location(trigger::to_pop(primary_slot))));
3000 ws.world.pop_set_poptype(trigger::to_pop(primary_slot),
3001 mine ? ws.culture_definitions.laborers : ws.culture_definitions.farmers);
3002 }
3003 return 0;
3004}
3006 auto p = trigger::to_prov(primary_slot);
3007 ws.world.province_set_is_slave(p, false);
3008 bool mine = ws.world.commodity_get_is_mine(ws.world.province_get_rgo(p));
3009 for(auto pop : ws.world.province_get_pop_location(p)) {
3010 if(pop.get_pop().get_poptype() == ws.culture_definitions.slaves) {
3011 pop.get_pop().set_poptype(mine ? ws.culture_definitions.laborers : ws.culture_definitions.farmers);
3012 }
3013 }
3014 return 0;
3015}
3018 return 0;
3019}
3020uint32_t ef_social_reform(EFFECT_PARAMTERS) {
3021 auto opt = trigger::payload(tval[1]).opt_id;
3022 politics::set_issue_option(ws, trigger::to_nation(primary_slot), opt);
3025 return 0;
3026}
3028 auto opt = trigger::payload(tval[1]).opt_id;
3029 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
3030 if(owner) {
3031 politics::set_issue_option(ws, owner, opt);
3034 }
3035 return 0;
3036}
3037uint32_t ef_political_reform(EFFECT_PARAMTERS) {
3038 auto opt = trigger::payload(tval[1]).opt_id;
3039 politics::set_issue_option(ws, trigger::to_nation(primary_slot), opt);
3042 return 0;
3043}
3045 auto opt = trigger::payload(tval[1]).opt_id;
3046 auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot));
3047 if(owner) {
3048 politics::set_issue_option(ws, owner, opt);
3051 }
3052 return 0;
3053}
3054uint32_t ef_add_tax_relative_income(EFFECT_PARAMTERS) {
3055 auto income = ws.world.nation_get_total_poor_income(trigger::to_nation(primary_slot)) +
3056 ws.world.nation_get_total_middle_income(trigger::to_nation(primary_slot)) +
3057 ws.world.nation_get_total_rich_income(trigger::to_nation(primary_slot));
3058 auto amount = trigger::read_float_from_payload(tval + 1);
3059 assert(std::isfinite(amount));
3060 auto combined_amount = income * amount;
3061 assert(std::isfinite(combined_amount));
3062 auto& v = ws.world.nation_get_stockpiles(trigger::to_nation(primary_slot), economy::money);
3063
3064 if(ws.world.nation_get_is_player_controlled(trigger::to_nation(primary_slot)))
3065 v = v + combined_amount;
3066 else
3067 v = std::max(v + combined_amount, 0.0f); // temporary measure since there is no debt
3068 return 0;
3069}
3072 return 0;
3073}
3075 auto amount = trigger::read_float_from_payload(tval + 1);
3076 assert(std::isfinite(amount));
3077 ws.world.pop_get_size(trigger::to_pop(primary_slot)) *= amount;
3078 return 0;
3079}
3080uint32_t ef_reduce_pop_abs(EFFECT_PARAMTERS) {
3081 auto amount = trigger::read_int32_t_from_payload(tval + 1);
3082
3083 demographics::reduce_pop_size_safe(ws, trigger::to_pop(primary_slot), amount);
3084 return 0;
3085}
3087 auto amount = trigger::read_float_from_payload(tval + 1);
3088 assert(std::isfinite(amount));
3089 for(auto p : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3090 p.get_pop().get_size() *= amount;
3091 }
3092 return 0;
3093}
3095 auto amount = trigger::read_float_from_payload(tval + 1);
3096 assert(std::isfinite(amount));
3097 for(auto pr : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
3098 for(auto p : pr.get_province().get_pop_location()) {
3099 p.get_pop().get_size() *= amount;
3100 }
3101 }
3102 return 0;
3103}
3105 auto amount = trigger::read_float_from_payload(tval + 1);
3106 assert(std::isfinite(amount));
3107 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, amount](dcon::province_id pr) {
3108 for(auto p : ws.world.province_get_pop_location(pr)) {
3109 p.get_pop().get_size() *= amount;
3110 }
3111 });
3112 return 0;
3113}
3115 ws.world.pop_set_province_from_pop_location(trigger::to_pop(primary_slot), trigger::payload(tval[1]).prov_id);
3116 return 0;
3117}
3119 ws.world.pop_set_poptype(trigger::to_pop(primary_slot), trigger::payload(tval[1]).popt_id);
3120 return 0;
3121}
3122uint32_t ef_years_of_research(EFFECT_PARAMTERS) {
3123 auto& rp = ws.world.nation_get_research_points(trigger::to_nation(primary_slot));
3124 auto amount = trigger::read_float_from_payload(tval + 1);
3125 assert(std::isfinite(amount));
3126 rp += nations::daily_research_points(ws, trigger::to_nation(primary_slot)) * 365.0f * amount;
3127 return 0;
3128}
3129uint32_t ef_prestige_factor_positive(EFFECT_PARAMTERS) {
3130 auto& bp = ws.world.nation_get_prestige(trigger::to_nation(primary_slot));
3131 auto score = nations::prestige_score(ws, trigger::to_nation(primary_slot));
3132 auto amount = trigger::read_float_from_payload(tval + 1);
3133 assert(std::isfinite(amount));
3134
3135 bp += (score) *
3136 (ws.world.nation_get_modifier_values(trigger::to_nation(primary_slot), sys::national_mod_offsets::prestige) + 1.0f) *
3137 amount;
3138 return 0;
3139}
3140uint32_t ef_prestige_factor_negative(EFFECT_PARAMTERS) {
3141 auto& bp = ws.world.nation_get_prestige(trigger::to_nation(primary_slot));
3142 auto score = nations::prestige_score(ws, trigger::to_nation(primary_slot));
3143 auto amount = trigger::read_float_from_payload(tval + 1);
3144 assert(std::isfinite(amount));
3145
3146 bp = std::max(0.0f, bp + (score)*amount);
3147 return 0;
3148}
3149uint32_t ef_military_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_economic_reform(EFFECT_PARAMTERS) {
3157 auto opt = trigger::payload(tval[1]).ropt_id;
3158 politics::set_reform_option(ws, trigger::to_nation(primary_slot), opt);
3161 return 0;
3162}
3163uint32_t ef_remove_random_military_reforms(EFFECT_PARAMTERS) {
3164 std::vector<dcon::reform_option_id> active_reforms;
3165 auto nation_id = trigger::to_nation(primary_slot);
3166 for(auto issue : ws.world.in_reform) {
3167 if(issue.get_reform_type() == uint8_t(culture::issue_type::military) &&
3168 ws.world.nation_get_reforms(nation_id, issue) != ws.world.reform_get_options(issue)[0])
3169 active_reforms.push_back(ws.world.reform_get_options(issue)[0]);
3170 }
3171 for(int32_t i = tval[1] - 1; active_reforms.size() != 0 && i >= 0; --i) {
3172 auto r = rng::get_random(ws, r_hi, uint32_t(r_lo + i)) % active_reforms.size();
3173 politics::set_reform_option(ws, nation_id, active_reforms[r]);
3174 active_reforms[r] = active_reforms.back();
3175 active_reforms.pop_back();
3176 }
3179 return tval[1];
3180}
3181uint32_t ef_remove_random_economic_reforms(EFFECT_PARAMTERS) {
3182 std::vector<dcon::reform_option_id> active_reforms;
3183 auto nation_id = trigger::to_nation(primary_slot);
3184 for(auto issue : ws.world.in_reform) {
3185 if(issue.get_reform_type() == uint8_t(culture::issue_type::economic) &&
3186 ws.world.nation_get_reforms(nation_id, issue) != ws.world.reform_get_options(issue)[0])
3187 active_reforms.push_back(ws.world.reform_get_options(issue)[0]);
3188 }
3189 for(int32_t i = tval[1] - 1; active_reforms.size() != 0 && i >= 0; --i) {
3190 auto r = rng::get_random(ws, r_hi, uint32_t(r_lo + i)) % active_reforms.size();
3191 politics::set_reform_option(ws, nation_id, active_reforms[r]);
3192 active_reforms[r] = active_reforms.back();
3193 active_reforms.pop_back();
3194 }
3197 return tval[1];
3198}
3200 ws.world.province_set_crime(trigger::to_prov(primary_slot), trigger::payload(tval[1]).crm_id);
3201 return 0;
3202}
3203uint32_t ef_add_crime_none(EFFECT_PARAMTERS) {
3204 ws.world.province_set_crime(trigger::to_prov(primary_slot), dcon::crime_id{});
3205 return 0;
3206}
3209 return 0;
3210}
3211uint32_t ef_build_factory_in_capital_state(EFFECT_PARAMTERS) {
3212 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
3213 auto cs = ws.world.province_get_state_membership(c);
3214 if(!cs)
3215 return 0;
3216 economy::try_add_factory_to_state(ws, cs, trigger::payload(tval[1]).fac_id);
3217 return 0;
3218}
3219uint32_t ef_activate_technology(EFFECT_PARAMTERS) {
3220 if(ws.world.nation_get_active_technologies(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id) == false)
3221 culture::apply_technology(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id);
3222 return 0;
3223}
3224uint32_t ef_activate_invention(EFFECT_PARAMTERS) {
3225 if(ws.world.nation_get_active_inventions(trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id) == true)
3226 culture::apply_invention(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id);
3227 return 0;
3228}
3229uint32_t ef_great_wars_enabled_yes(EFFECT_PARAMTERS) {
3230 ws.military_definitions.great_wars_enabled = true;
3231 return 0;
3232}
3233uint32_t ef_great_wars_enabled_no(EFFECT_PARAMTERS) {
3234 ws.military_definitions.great_wars_enabled = false;
3235 return 0;
3236}
3237uint32_t ef_world_wars_enabled_yes(EFFECT_PARAMTERS) {
3238 ws.military_definitions.world_wars_enabled = true;
3239 return 0;
3240}
3241uint32_t ef_world_wars_enabled_no(EFFECT_PARAMTERS) {
3242 ws.military_definitions.world_wars_enabled = false;
3243 return 0;
3244}
3245uint32_t ef_assimilate_province(EFFECT_PARAMTERS) {
3246 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner) {
3247 auto owner_c = ws.world.nation_get_primary_culture(owner);
3248 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3249 pop.get_pop().set_culture(owner_c);
3250 pop.get_pop().set_is_primary_or_accepted_culture(true);
3251 }
3252 }
3253 return 0;
3254}
3255uint32_t ef_assimilate_state(EFFECT_PARAMTERS) {
3256 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot)); owner) {
3257 auto owner_c = ws.world.nation_get_primary_culture(owner);
3258 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3259 for(auto pop : ws.world.province_get_pop_location(p)) {
3260 pop.get_pop().set_culture(owner_c);
3261 pop.get_pop().set_is_primary_or_accepted_culture(true);
3262 }
3263 });
3264 }
3265 return 0;
3266}
3267uint32_t ef_assimilate_pop(EFFECT_PARAMTERS) {
3268 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot)); owner) {
3269 auto owner_c = ws.world.nation_get_primary_culture(owner);
3270 ws.world.pop_set_culture(trigger::to_pop(primary_slot), owner_c);
3271 ws.world.pop_set_is_primary_or_accepted_culture(trigger::to_pop(primary_slot), true);
3272 }
3273 return 0;
3274}
3275uint32_t ef_set_culture_pop(EFFECT_PARAMTERS) {
3276 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot)); owner) {
3277 auto c = trigger::payload(tval[1]).cul_id;
3278 ws.world.pop_set_culture(trigger::to_pop(primary_slot), c);
3279 ws.world.pop_set_is_primary_or_accepted_culture(trigger::to_pop(primary_slot), nations::nation_accepts_culture(ws, owner, c));
3280 }
3281 return 0;
3282}
3284 auto l = pop_demographics::get_literacy(ws, trigger::to_pop(primary_slot));
3285 auto amount = trigger::read_float_from_payload(tval + 1);
3286 assert(std::isfinite(amount));
3287 pop_demographics::set_literacy(ws, trigger::to_pop(primary_slot), std::clamp(l + amount, 0.0f, 1.0f));
3288 return 0;
3289}
3290uint32_t ef_add_crisis_interest(EFFECT_PARAMTERS) {
3291 if(ws.current_crisis_state != sys::crisis_state::inactive && ws.current_crisis_state == sys::crisis_state::heating_up) {
3292 for(auto& im : ws.crisis_participants) {
3293 if(im.id == trigger::to_nation(primary_slot)) {
3294 return 0;
3295 }
3296 if(!im.id) {
3297 im.id = trigger::to_nation(primary_slot);
3298 im.merely_interested = true;
3299 im.supports_attacker = false;
3300 return 0;
3301 }
3302 }
3303 }
3304 return 0;
3305}
3306uint32_t ef_flashpoint_tension(EFFECT_PARAMTERS) {
3307 auto& current_tension = ws.world.state_instance_get_flashpoint_tension(trigger::to_state(primary_slot));
3308 auto amount = trigger::read_float_from_payload(tval + 1);
3309 assert(std::isfinite(amount));
3310
3311 current_tension = std::clamp(current_tension + amount, 0.0f, 100.0f);
3312 return 0;
3313}
3315 auto state = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
3316 if(!state)
3317 return 0;
3318
3319 auto& current_tension = ws.world.state_instance_get_flashpoint_tension(state);
3320 auto amount = trigger::read_float_from_payload(tval + 1);
3321 assert(std::isfinite(amount));
3322
3323 current_tension = std::clamp(current_tension + amount, 0.0f, 100.0f);
3324 return 0;
3325}
3326uint32_t ef_add_crisis_temperature(EFFECT_PARAMTERS) {
3327 auto amount = trigger::read_float_from_payload(tval + 1);
3328 assert(std::isfinite(amount));
3329
3330 ws.crisis_temperature = std::clamp(ws.crisis_temperature + amount, 0.0f, 100.0f);
3331 return 0;
3332}
3333uint32_t ef_consciousness(EFFECT_PARAMTERS) {
3334 auto amount = trigger::read_float_from_payload(tval + 1);
3335 assert(std::isfinite(amount));
3336
3337 auto c = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
3338 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(c + amount, 0.0f, 10.0f));
3339 return 0;
3340}
3342 auto amount = trigger::read_float_from_payload(tval + 1);
3343 assert(std::isfinite(amount));
3344 for(auto p : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3345 auto c = pop_demographics::get_consciousness(ws, p.get_pop());
3346 pop_demographics::set_consciousness(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3347 }
3348 return 0;
3349}
3351 auto amount = trigger::read_float_from_payload(tval + 1);
3352 assert(std::isfinite(amount));
3353 for(auto pr : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
3354 for(auto p : pr.get_province().get_pop_location()) {
3355 auto c = pop_demographics::get_consciousness(ws, p.get_pop());
3356 pop_demographics::set_consciousness(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3357 }
3358 }
3359 return 0;
3360}
3362 auto amount = trigger::read_float_from_payload(tval + 1);
3363 assert(std::isfinite(amount));
3364 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, amount](dcon::province_id pr) {
3365 for(auto p : ws.world.province_get_pop_location(pr)) {
3366 auto c = pop_demographics::get_consciousness(ws, p.get_pop());
3367 pop_demographics::set_consciousness(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3368 }
3369 });
3370 return 0;
3371}
3373 auto amount = trigger::read_float_from_payload(tval + 1);
3374 assert(std::isfinite(amount));
3375
3376 auto c = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
3377 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(c + amount, 0.0f, 10.0f));
3378 return 0;
3379}
3381 auto amount = trigger::read_float_from_payload(tval + 1);
3382 assert(std::isfinite(amount));
3383 for(auto p : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
3384 auto c = pop_demographics::get_militancy(ws, p.get_pop());
3385 pop_demographics::set_militancy(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3386 }
3387 return 0;
3388}
3390 auto amount = trigger::read_float_from_payload(tval + 1);
3391 assert(std::isfinite(amount));
3392 for(auto pr : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
3393 for(auto p : pr.get_province().get_pop_location()) {
3394 auto c = pop_demographics::get_militancy(ws, p.get_pop());
3395 pop_demographics::set_militancy(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3396 }
3397 }
3398 return 0;
3399}
3401 auto amount = trigger::read_float_from_payload(tval + 1);
3402 assert(std::isfinite(amount));
3403 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&ws, amount](dcon::province_id pr) {
3404 for(auto p : ws.world.province_get_pop_location(pr)) {
3405 auto c = pop_demographics::get_militancy(ws, p.get_pop());
3406 pop_demographics::set_militancy(ws, p.get_pop(), std::clamp(c + amount, 0.0f, 10.0f));
3407 }
3408 });
3409 return 0;
3410}
3412 auto& s = ws.world.province_get_rgo_size(trigger::to_prov(primary_slot));
3413 s = std::max(s + float(trigger::payload(tval[1]).signed_value), 0.0f);
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::fort));
3418 building_level = uint8_t(std::clamp(int32_t(building_level) + int32_t(trigger::payload(tval[1]).signed_value),
3419 0,
3420 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)))));
3421 return 0;
3422}
3424 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::naval_base));
3425 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)))));
3426 if(building_level > 0) {
3427 auto si = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
3428 ws.world.state_instance_set_naval_base_is_taken(si, true);
3429 }
3430 return 0;
3431}
3433 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::bank));
3434 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)))));
3435 return 0;
3436}
3438 auto& building_level = ws.world.province_get_building_level(trigger::to_prov(primary_slot), uint8_t(economy::province_building_type::university));
3439 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)))));
3440 return 0;
3441}
3443 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3444 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort));
3445 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)))));
3446 });
3447 return 0;
3448}
3450 uint32_t lvl = 0;
3451 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3452 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::naval_base));
3453 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)))));
3454 lvl = std::max<uint32_t>(lvl, building_level);
3455 });
3456 if(lvl > 0) {
3457 auto si = ws.world.province_get_state_membership(trigger::to_prov(primary_slot));
3458 ws.world.state_instance_set_naval_base_is_taken(si, true);
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::bank));
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::bank)))));
3466 });
3467 return 0;
3468}
3470 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3471 auto& building_level = ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::university));
3472 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)))));
3473 });
3474 return 0;
3475}
3476
3477uint32_t ef_trigger_revolt_nation(EFFECT_PARAMTERS) {
3478 rebel::trigger_revolt(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).reb_id, trigger::payload(tval[4]).ideo_id,
3479 trigger::payload(tval[2]).cul_id, trigger::payload(tval[3]).rel_id);
3480 return 0;
3481}
3482uint32_t ef_trigger_revolt_state(EFFECT_PARAMTERS) {
3483 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(primary_slot)); owner)
3484 rebel::trigger_revolt(ws, owner, trigger::payload(tval[1]).reb_id, trigger::payload(tval[4]).ideo_id,
3485 trigger::payload(tval[2]).cul_id, trigger::payload(tval[3]).rel_id);
3486 return 0;
3487}
3488uint32_t ef_trigger_revolt_province(EFFECT_PARAMTERS) {
3489 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
3490 rebel::trigger_revolt(ws, owner, trigger::payload(tval[1]).reb_id, trigger::payload(tval[4]).ideo_id,
3491 trigger::payload(tval[2]).cul_id, trigger::payload(tval[3]).rel_id);
3492 return 0;
3493}
3494uint32_t ef_diplomatic_influence(EFFECT_PARAMTERS) {
3495 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id); holder)
3497 float(trigger::payload(tval[2]).signed_value));
3498 return 0;
3499}
3500uint32_t ef_diplomatic_influence_this_nation(EFFECT_PARAMTERS) {
3502 float(trigger::payload(tval[1]).signed_value));
3503 return 0;
3504}
3505uint32_t ef_diplomatic_influence_this_province(EFFECT_PARAMTERS) {
3506 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
3508 float(trigger::payload(tval[1]).signed_value));
3509 return 0;
3510}
3511uint32_t ef_diplomatic_influence_from_nation(EFFECT_PARAMTERS) {
3513 float(trigger::payload(tval[1]).signed_value));
3514 return 0;
3515}
3516uint32_t ef_diplomatic_influence_from_province(EFFECT_PARAMTERS) {
3517 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
3519 float(trigger::payload(tval[1]).signed_value));
3520 return 0;
3521}
3523 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id); holder)
3524 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), holder, float(trigger::payload(tval[2]).signed_value));
3525 return 0;
3526}
3527uint32_t ef_relation_this_nation(EFFECT_PARAMTERS) {
3529 float(trigger::payload(tval[1]).signed_value));
3530 return 0;
3531}
3532uint32_t ef_relation_this_province(EFFECT_PARAMTERS) {
3533 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
3534 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), owner, float(trigger::payload(tval[1]).signed_value));
3535 return 0;
3536}
3537uint32_t ef_relation_from_nation(EFFECT_PARAMTERS) {
3539 float(trigger::payload(tval[1]).signed_value));
3540 return 0;
3541}
3542uint32_t ef_relation_from_province(EFFECT_PARAMTERS) {
3543 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
3544 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), owner, float(trigger::payload(tval[1]).signed_value));
3545 return 0;
3546}
3547uint32_t ef_add_province_modifier(EFFECT_PARAMTERS) {
3548 sys::add_modifier_to_province(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).mod_id,
3549 ws.current_date + trigger::payload(tval[2]).signed_value);
3550 return 0;
3551}
3552uint32_t ef_add_province_modifier_no_duration(EFFECT_PARAMTERS) {
3553 sys::add_modifier_to_province(ws, trigger::to_prov(primary_slot), trigger::payload(tval[1]).mod_id, sys::date{});
3554 return 0;
3555}
3557 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3558 sys::add_modifier_to_province(ws, p, trigger::payload(tval[1]).mod_id, ws.current_date + trigger::payload(tval[2]).signed_value);
3559 });
3560 return 0;
3561}
3563 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
3564 sys::add_modifier_to_province(ws, p, trigger::payload(tval[1]).mod_id, sys::date{});
3565 });
3566 return 0;
3567}
3568uint32_t ef_add_country_modifier(EFFECT_PARAMTERS) {
3569 sys::add_modifier_to_nation(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id,
3570 ws.current_date + trigger::payload(tval[2]).signed_value);
3571 return 0;
3572}
3573uint32_t ef_add_country_modifier_no_duration(EFFECT_PARAMTERS) {
3574 sys::add_modifier_to_nation(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).mod_id, sys::date{});
3575 return 0;
3576}
3577// Effects give "blank check" CBs that can be used on any state, thus target state is empty.
3578// Scenario of a CB without target state is to be correctly handled in the UI and game logic.
3579uint32_t ef_casus_belli_tag(EFFECT_PARAMTERS) {
3580 auto type = trigger::payload(tval[1]).cb_id;
3581 auto months = trigger::payload(tval[2]).signed_value;
3582 auto tag_target = trigger::payload(tval[3]).tag_id;
3583
3584 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target); holder) {
3585 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3586 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type , dcon::state_definition_id{} });
3587 }
3588 return 0;
3589}
3590uint32_t ef_casus_belli_int(EFFECT_PARAMTERS) {
3591 auto type = trigger::payload(tval[1]).cb_id;
3592 auto months = trigger::payload(tval[2]).signed_value;
3593
3594 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[3]).prov_id); holder) {
3595 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3596 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type, dcon::state_definition_id{} });
3597 }
3598 return 0;
3599}
3600uint32_t ef_casus_belli_this_nation(EFFECT_PARAMTERS) {
3601 auto type = trigger::payload(tval[1]).cb_id;
3602 auto months = trigger::payload(tval[2]).signed_value;
3603
3604 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3605 .push_back(
3606 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(this_slot), type, dcon::state_definition_id{} });
3607
3608 return 0;
3609}
3610uint32_t ef_casus_belli_this_state(EFFECT_PARAMTERS) {
3611 auto type = trigger::payload(tval[1]).cb_id;
3612 auto months = trigger::payload(tval[2]).signed_value;
3613
3614 if(auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); holder) {
3615 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3616 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type, dcon::state_definition_id{} });
3617 }
3618 return 0;
3619}
3620uint32_t ef_casus_belli_this_province(EFFECT_PARAMTERS) {
3621 auto type = trigger::payload(tval[1]).cb_id;
3622 auto months = trigger::payload(tval[2]).signed_value;
3623
3624 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); holder) {
3625 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3626 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type, dcon::state_definition_id{} });
3627 }
3628 return 0;
3629}
3630uint32_t ef_casus_belli_this_pop(EFFECT_PARAMTERS) {
3631 auto type = trigger::payload(tval[1]).cb_id;
3632 auto months = trigger::payload(tval[2]).signed_value;
3633
3634 if(auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); holder) {
3635 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3636 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type, dcon::state_definition_id{} });
3637 }
3638 return 0;
3639}
3640uint32_t ef_casus_belli_from_nation(EFFECT_PARAMTERS) {
3641 auto type = trigger::payload(tval[1]).cb_id;
3642 auto months = trigger::payload(tval[2]).signed_value;
3643
3644 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3645 .push_back(
3646 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(from_slot), type, dcon::state_definition_id{} });
3647
3648 return 0;
3649}
3650uint32_t ef_casus_belli_from_province(EFFECT_PARAMTERS) {
3651 auto type = trigger::payload(tval[1]).cb_id;
3652 auto months = trigger::payload(tval[2]).signed_value;
3653
3654 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); holder) {
3655 ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot))
3656 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, holder, type, dcon::state_definition_id{} });
3657 }
3658 return 0;
3659}
3660uint32_t ef_add_casus_belli_tag(EFFECT_PARAMTERS) {
3661 auto type = trigger::payload(tval[1]).cb_id;
3662 auto months = trigger::payload(tval[2]).signed_value;
3663 auto tag_target = trigger::payload(tval[3]).tag_id;
3664
3665 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target); holder) {
3666 ws.world.nation_get_available_cbs(holder).push_back(
3667 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3668 }
3669 return 0;
3670}
3671uint32_t ef_add_casus_belli_int(EFFECT_PARAMTERS) {
3672 auto type = trigger::payload(tval[1]).cb_id;
3673 auto months = trigger::payload(tval[2]).signed_value;
3674
3675 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[3]).prov_id); holder) {
3676 ws.world.nation_get_available_cbs(holder).push_back(
3677 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3678 }
3679 return 0;
3680}
3681uint32_t ef_add_casus_belli_this_nation(EFFECT_PARAMTERS) {
3682 auto type = trigger::payload(tval[1]).cb_id;
3683 auto months = trigger::payload(tval[2]).signed_value;
3684
3685 ws.world.nation_get_available_cbs(trigger::to_nation(this_slot))
3686 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3687 return 0;
3688}
3689uint32_t ef_add_casus_belli_this_state(EFFECT_PARAMTERS) {
3690 auto type = trigger::payload(tval[1]).cb_id;
3691 auto months = trigger::payload(tval[2]).signed_value;
3692
3693 if(auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); holder) {
3694 ws.world.nation_get_available_cbs(holder).push_back(
3695 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3696 }
3697 return 0;
3698}
3699uint32_t ef_add_casus_belli_this_province(EFFECT_PARAMTERS) {
3700 auto type = trigger::payload(tval[1]).cb_id;
3701 auto months = trigger::payload(tval[2]).signed_value;
3702
3703 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); holder) {
3704 ws.world.nation_get_available_cbs(holder).push_back(
3705 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3706 }
3707 return 0;
3708}
3709uint32_t ef_add_casus_belli_this_pop(EFFECT_PARAMTERS) {
3710 auto type = trigger::payload(tval[1]).cb_id;
3711 auto months = trigger::payload(tval[2]).signed_value;
3712
3713 if(auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); holder) {
3714 ws.world.nation_get_available_cbs(holder).push_back(
3715 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3716 }
3717 return 0;
3718}
3719uint32_t ef_add_casus_belli_from_nation(EFFECT_PARAMTERS) {
3720 auto type = trigger::payload(tval[1]).cb_id;
3721 auto months = trigger::payload(tval[2]).signed_value;
3722
3723 ws.world.nation_get_available_cbs(trigger::to_nation(from_slot))
3724 .push_back(military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3725 return 0;
3726}
3727uint32_t ef_add_casus_belli_from_province(EFFECT_PARAMTERS) {
3728 auto type = trigger::payload(tval[1]).cb_id;
3729 auto months = trigger::payload(tval[2]).signed_value;
3730
3731 if(auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); holder) {
3732 ws.world.nation_get_available_cbs(holder).push_back(
3733 military::available_cb{ months > 0 ? ws.current_date + 31 * months : sys::date{}, trigger::to_nation(primary_slot), type, dcon::state_definition_id{} });
3734 }
3735 return 0;
3736}
3737uint32_t ef_remove_casus_belli_tag(EFFECT_PARAMTERS) {
3738 auto type = trigger::payload(tval[1]).cb_id;
3739 auto tag_target = trigger::payload(tval[2]).tag_id;
3740
3741 auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target);
3742 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3743 for(uint32_t i = cbs.size(); i-- > 0;) {
3744 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3745 cbs.remove_at(i);
3746 }
3747 return 0;
3748}
3749uint32_t ef_remove_casus_belli_int(EFFECT_PARAMTERS) {
3750 auto type = trigger::payload(tval[1]).cb_id;
3751
3752 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[2]).prov_id);
3753 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3754 for(uint32_t i = cbs.size(); i-- > 0;) {
3755 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3756 cbs.remove_at(i);
3757 }
3758 return 0;
3759}
3760uint32_t ef_remove_casus_belli_this_nation(EFFECT_PARAMTERS) {
3761 auto type = trigger::payload(tval[1]).cb_id;
3762
3763 auto holder = trigger::to_nation(this_slot);
3764 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3765 for(uint32_t i = cbs.size(); i-- > 0;) {
3766 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3767 cbs.remove_at(i);
3768 }
3769 return 0;
3770}
3771uint32_t ef_remove_casus_belli_this_state(EFFECT_PARAMTERS) {
3772 auto type = trigger::payload(tval[1]).cb_id;
3773
3774 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
3775 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3776 for(uint32_t i = cbs.size(); i-- > 0;) {
3777 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3778 cbs.remove_at(i);
3779 }
3780 return 0;
3781}
3782uint32_t ef_remove_casus_belli_this_province(EFFECT_PARAMTERS) {
3783 auto type = trigger::payload(tval[1]).cb_id;
3784
3785 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3786 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3787 for(uint32_t i = cbs.size(); i-- > 0;) {
3788 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3789 cbs.remove_at(i);
3790 }
3791 return 0;
3792}
3793uint32_t ef_remove_casus_belli_this_pop(EFFECT_PARAMTERS) {
3794 auto type = trigger::payload(tval[1]).cb_id;
3795
3796 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
3797 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3798 for(uint32_t i = cbs.size(); i-- > 0;) {
3799 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3800 cbs.remove_at(i);
3801 }
3802 return 0;
3803}
3804uint32_t ef_remove_casus_belli_from_nation(EFFECT_PARAMTERS) {
3805 auto type = trigger::payload(tval[1]).cb_id;
3806
3807 auto holder = trigger::to_nation(from_slot);
3808 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3809 for(uint32_t i = cbs.size(); i-- > 0;) {
3810 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3811 cbs.remove_at(i);
3812 }
3813 return 0;
3814}
3815uint32_t ef_remove_casus_belli_from_province(EFFECT_PARAMTERS) {
3816 auto type = trigger::payload(tval[1]).cb_id;
3817
3818 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
3819 auto cbs = ws.world.nation_get_available_cbs(trigger::to_nation(primary_slot));
3820 for(uint32_t i = cbs.size(); i-- > 0;) {
3821 if(cbs.at(i).cb_type == type && cbs.at(i).target == holder)
3822 cbs.remove_at(i);
3823 }
3824 return 0;
3825}
3826uint32_t ef_this_remove_casus_belli_tag(EFFECT_PARAMTERS) {
3827 auto type = trigger::payload(tval[1]).cb_id;
3828 auto tag_target = trigger::payload(tval[2]).tag_id;
3829
3830 auto holder = ws.world.national_identity_get_nation_from_identity_holder(tag_target);
3831 if(holder) {
3832 auto cbs = ws.world.nation_get_available_cbs(holder);
3833 for(uint32_t i = cbs.size(); i-- > 0;) {
3834 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3835 cbs.remove_at(i);
3836 }
3837 }
3838 return 0;
3839}
3840uint32_t ef_this_remove_casus_belli_int(EFFECT_PARAMTERS) {
3841 auto type = trigger::payload(tval[1]).cb_id;
3842
3843 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::payload(tval[2]).prov_id);
3844 if(holder) {
3845 auto cbs = ws.world.nation_get_available_cbs(holder);
3846 for(uint32_t i = cbs.size(); i-- > 0;) {
3847 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3848 cbs.remove_at(i);
3849 }
3850 }
3851 return 0;
3852}
3853uint32_t ef_this_remove_casus_belli_this_nation(EFFECT_PARAMTERS) {
3854 auto type = trigger::payload(tval[1]).cb_id;
3855
3856 auto holder = trigger::to_nation(this_slot);
3857 auto cbs = ws.world.nation_get_available_cbs(holder);
3858 for(uint32_t i = cbs.size(); i-- > 0;) {
3859 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3860 cbs.remove_at(i);
3861 }
3862 return 0;
3863}
3864uint32_t ef_this_remove_casus_belli_this_state(EFFECT_PARAMTERS) {
3865 auto type = trigger::payload(tval[1]).cb_id;
3866
3867 auto holder = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
3868 if(holder) {
3869 auto cbs = ws.world.nation_get_available_cbs(holder);
3870 for(uint32_t i = cbs.size(); i-- > 0;) {
3871 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3872 cbs.remove_at(i);
3873 }
3874 }
3875 return 0;
3876}
3877uint32_t ef_this_remove_casus_belli_this_province(EFFECT_PARAMTERS) {
3878 auto type = trigger::payload(tval[1]).cb_id;
3879
3880 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3881 if(holder) {
3882 auto cbs = ws.world.nation_get_available_cbs(holder);
3883 for(uint32_t i = cbs.size(); i-- > 0;) {
3884 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3885 cbs.remove_at(i);
3886 }
3887 }
3888 return 0;
3889}
3890uint32_t ef_this_remove_casus_belli_this_pop(EFFECT_PARAMTERS) {
3891 auto type = trigger::payload(tval[1]).cb_id;
3892
3893 auto holder = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
3894 if(holder) {
3895 auto cbs = ws.world.nation_get_available_cbs(holder);
3896 for(uint32_t i = cbs.size(); i-- > 0;) {
3897 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3898 cbs.remove_at(i);
3899 }
3900 }
3901 return 0;
3902}
3903uint32_t ef_this_remove_casus_belli_from_nation(EFFECT_PARAMTERS) {
3904 auto type = trigger::payload(tval[1]).cb_id;
3905
3906 auto holder = trigger::to_nation(from_slot);
3907 auto cbs = ws.world.nation_get_available_cbs(holder);
3908 for(uint32_t i = cbs.size(); i-- > 0;) {
3909 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3910 cbs.remove_at(i);
3911 }
3912 return 0;
3913}
3914uint32_t ef_this_remove_casus_belli_from_province(EFFECT_PARAMTERS) {
3915 auto type = trigger::payload(tval[1]).cb_id;
3916
3917 auto holder = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot));
3918 if(holder) {
3919 auto cbs = ws.world.nation_get_available_cbs(holder);
3920 for(uint32_t i = cbs.size(); i-- > 0;) {
3921 if(cbs.at(i).cb_type == type && cbs.at(i).target == trigger::to_nation(primary_slot))
3922 cbs.remove_at(i);
3923 }
3924 }
3925 return 0;
3926}
3927
3928uint32_t ef_add_truce_tag(EFFECT_PARAMTERS) {
3929 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
3930 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3931 return 0;
3932 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[2] * 30.5f));
3933 return 0;
3934}
3935uint32_t ef_add_truce_this_nation(EFFECT_PARAMTERS) {
3936 auto target = trigger::to_nation(this_slot);
3937 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3938 return 0;
3939 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3940 return 0;
3941}
3942uint32_t ef_add_truce_this_state(EFFECT_PARAMTERS) {
3943 auto target = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot));
3944 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3945 return 0;
3946 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3947 return 0;
3948}
3949uint32_t ef_add_truce_this_province(EFFECT_PARAMTERS) {
3950 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3951 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3952 return 0;
3953 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3954 return 0;
3955}
3956uint32_t ef_add_truce_this_pop(EFFECT_PARAMTERS) {
3957 auto target = nations::owner_of_pop(ws, trigger::to_pop(this_slot));
3958 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3959 return 0;
3960 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3961 return 0;
3962}
3963uint32_t ef_add_truce_from_nation(EFFECT_PARAMTERS) {
3964 auto target = trigger::to_nation(from_slot);
3965 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3966 return 0;
3967 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3968 return 0;
3969}
3970uint32_t ef_add_truce_from_province(EFFECT_PARAMTERS) {
3971 auto target = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot));
3972 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
3973 return 0;
3974 military::add_truce(ws, target, trigger::to_nation(primary_slot), int32_t(tval[1] * 30.5f));
3975 return 0;
3976}
3978 for(auto drel : ws.world.nation_get_diplomatic_relation(trigger::to_nation(primary_slot))) {
3979 auto other_nation = drel.get_related_nations(0) != trigger::to_nation(primary_slot) ? drel.get_related_nations(0) : drel.get_related_nations(1);
3980 if(drel.get_are_allied()) {
3981 for(auto wfor : ws.world.nation_get_war_participant(trigger::to_nation(primary_slot))) {
3982 if(wfor.get_war().get_primary_attacker() == trigger::to_nation(primary_slot)) {
3983 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)) {
3984
3986 std::memset(&m, 0, sizeof(m));
3987 m.from = trigger::to_nation(primary_slot);
3988 m.to = other_nation;
3990 m.data.war = wfor.get_war();
3992 }
3993 }
3994 if(wfor.get_war().get_primary_defender() == trigger::to_nation(primary_slot)) {
3995 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)) {
3996
3998 std::memset(&m, 0, sizeof(m));
3999 m.from = trigger::to_nation(primary_slot);
4000 m.to = other_nation;
4002 m.data.war = wfor.get_war();
4004 }
4005 }
4006 }
4007 }
4008
4009 }
4010
4011 return 0;
4012}
4013
4014uint32_t ef_ruling_party_this(EFFECT_PARAMTERS) {
4015 politics::force_ruling_party_ideology(ws, trigger::to_nation(primary_slot), ws.world.nation_get_ruling_party(trigger::to_nation(this_slot)).get_ideology());
4016 return 0;
4017}
4018uint32_t ef_ruling_party_from(EFFECT_PARAMTERS) {
4019 politics::force_ruling_party_ideology(ws, trigger::to_nation(primary_slot), ws.world.nation_get_ruling_party(trigger::to_nation(from_slot)).get_ideology());
4020 return 0;
4021}
4022
4024 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
4025 if(!target)
4026 return 0;
4027 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4028 return 0;
4029 if(target == trigger::to_nation(primary_slot))
4030 return 0;
4031 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4032 if(!war) {
4034 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4035 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4036 trigger::payload(tval[7]).tag_id,
4037 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4038 } else {
4039 if(trigger::payload(tval[5]).cb_id) { //attacker
4040 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4041 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4042 trigger::payload(tval[7]).tag_id,
4043 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4044 }
4045 }
4046 if(trigger::payload(tval[2]).cb_id) { //defender
4047 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[2]).cb_id,
4048 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[3]).prov_id),
4049 trigger::payload(tval[4]).tag_id,
4050 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[4]).tag_id));
4051 }
4054 return 0;
4055}
4056uint32_t ef_war_this_nation(EFFECT_PARAMTERS) {
4057 auto target = trigger::to_nation(this_slot);
4058 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4059 return 0;
4060 if(target == trigger::to_nation(primary_slot))
4061 return 0;
4062 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4063 if(!war) {
4065 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4066 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4067 trigger::payload(tval[6]).tag_id,
4068 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4069 } else {
4070 if(trigger::payload(tval[4]).cb_id) { //attacker
4071 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4072 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4073 trigger::payload(tval[6]).tag_id,
4074 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4075 }
4076 }
4077 if(trigger::payload(tval[1]).cb_id) { //defender
4078 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[1]).cb_id,
4079 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[2]).prov_id),
4080 trigger::payload(tval[3]).tag_id,
4081 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[3]).tag_id));
4082 }
4085 return 0;
4086}
4087uint32_t ef_war_this_state(EFFECT_PARAMTERS) {
4088 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); owner)
4089 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4090 return 0;
4091}
4092uint32_t ef_war_this_province(EFFECT_PARAMTERS) {
4093 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
4094 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4095 return 0;
4096}
4097uint32_t ef_war_this_pop(EFFECT_PARAMTERS) {
4098 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_slot)); owner)
4099 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4100 return 0;
4101}
4102uint32_t ef_war_from_nation(EFFECT_PARAMTERS) {
4103 return ef_war_this_nation(tval, ws, primary_slot, from_slot, 0, r_lo, r_hi, els);
4104}
4105uint32_t ef_war_from_province(EFFECT_PARAMTERS) {
4106 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
4107 return ef_war_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4108 return 0;
4109}
4110uint32_t ef_war_no_ally_tag(EFFECT_PARAMTERS) {
4111 auto target = ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[1]).tag_id);
4112 if(!target)
4113 return 0;
4114 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4115 return 0;
4116 if(target == trigger::to_nation(primary_slot))
4117 return 0;
4118 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4119 if(!war) {
4121 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4122 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4123 trigger::payload(tval[7]).tag_id,
4124 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4125 } else {
4126 if(trigger::payload(tval[5]).cb_id) { //attacker
4127 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[5]).cb_id,
4128 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[6]).prov_id),
4129 trigger::payload(tval[7]).tag_id,
4130 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[7]).tag_id));
4131 }
4132 }
4133 if(trigger::payload(tval[2]).cb_id) { //defender
4134 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[2]).cb_id,
4135 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[3]).prov_id),
4136 trigger::payload(tval[4]).tag_id,
4137 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[4]).tag_id));
4138 }
4140 return 0;
4141}
4142uint32_t ef_war_no_ally_this_nation(EFFECT_PARAMTERS) {
4143 auto target = trigger::to_nation(this_slot);
4144 if(ws.world.nation_get_owned_province_count(target) == 0 || ws.world.nation_get_owned_province_count(trigger::to_nation(primary_slot)) == 0)
4145 return 0;
4146 if(target == trigger::to_nation(primary_slot))
4147 return 0;
4148 auto war = military::find_war_between(ws, trigger::to_nation(primary_slot), target);
4149 if(!war) {
4151 war = military::create_war(ws, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4152 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4153 trigger::payload(tval[6]).tag_id,
4154 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4155 } else {
4156 if(trigger::payload(tval[4]).cb_id) { //attacker
4157 military::add_wargoal(ws, war, trigger::to_nation(primary_slot), target, trigger::payload(tval[4]).cb_id,
4158 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[5]).prov_id),
4159 trigger::payload(tval[6]).tag_id,
4160 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[6]).tag_id));
4161 }
4162 }
4163 if(trigger::payload(tval[1]).cb_id) { //defender
4164 military::add_wargoal(ws, war, target, trigger::to_nation(primary_slot), trigger::payload(tval[1]).cb_id,
4165 ws.world.province_get_state_from_abstract_state_membership(trigger::payload(tval[2]).prov_id),
4166 trigger::payload(tval[3]).tag_id,
4167 ws.world.national_identity_get_nation_from_identity_holder(trigger::payload(tval[3]).tag_id));
4168 }
4170 return 0;
4171}
4172uint32_t ef_war_no_ally_this_state(EFFECT_PARAMTERS) {
4173 if(auto owner = ws.world.state_instance_get_nation_from_state_ownership(trigger::to_state(this_slot)); owner)
4174 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4175 return 0;
4176}
4177uint32_t ef_war_no_ally_this_province(EFFECT_PARAMTERS) {
4178 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(this_slot)); owner)
4179 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4180 return 0;
4181}
4182uint32_t ef_war_no_ally_this_pop(EFFECT_PARAMTERS) {
4183 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(this_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_war_no_ally_from_nation(EFFECT_PARAMTERS) {
4188 ef_war_no_ally_this_nation(tval, ws, primary_slot, from_slot, 0, r_lo, r_hi, els);
4189 return 0;
4190}
4191uint32_t ef_war_no_ally_from_province(EFFECT_PARAMTERS) {
4192 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(from_slot)); owner)
4193 ef_war_no_ally_this_nation(tval, ws, primary_slot, trigger::to_generic(owner), 0, r_lo, r_hi, els);
4194 return 0;
4195}
4196uint32_t ef_country_event_this_nation(EFFECT_PARAMTERS) {
4197 auto postpone = int32_t(tval[2]);
4198 assert(postpone > 0);
4199 auto future_date = ws.current_date + postpone;
4200 auto name = text::produce_simple_string(ws, dcon::fatten(ws.world, trigger::payload(tval[1]).nev_id).get_name());
4201 auto nationtag = text::produce_simple_string(ws, dcon::fatten(ws.world, trigger::to_nation(primary_slot)).get_identity_from_identity_holder().get_name());
4202 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4203 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});
4204 return 0;
4205}
4206uint32_t ef_country_event_immediate_this_nation(EFFECT_PARAMTERS) {
4207 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4208 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});
4209 return 0;
4210}
4211uint32_t ef_province_event_this_nation(EFFECT_PARAMTERS) {
4212 auto postpone = int32_t(tval[2]);
4213 assert(postpone > 0);
4214 auto future_date = ws.current_date + postpone;
4215 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});
4216 return 0;
4217}
4218uint32_t ef_province_event_immediate_this_nation(EFFECT_PARAMTERS) {
4219 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});
4220 return 0;
4221}
4222uint32_t ef_country_event_this_state(EFFECT_PARAMTERS) {
4223 auto postpone = int32_t(tval[2]);
4224 assert(postpone > 0);
4225 auto future_date = ws.current_date + postpone;
4226 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4227 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});
4228 return 0;
4229}
4230uint32_t ef_country_event_immediate_this_state(EFFECT_PARAMTERS) {
4231 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4232 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});
4233 return 0;
4234}
4235uint32_t ef_province_event_this_state(EFFECT_PARAMTERS) {
4236 auto postpone = int32_t(tval[2]);
4237 assert(postpone > 0);
4238 auto future_date = ws.current_date + postpone;
4239 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});
4240 return 0;
4241}
4242uint32_t ef_province_event_immediate_this_state(EFFECT_PARAMTERS) {
4243 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});
4244 return 0;
4245}
4246uint32_t ef_country_event_this_province(EFFECT_PARAMTERS) {
4247 auto postpone = int32_t(tval[2]);
4248 assert(postpone > 0);
4249 auto future_date = ws.current_date + postpone;
4250 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4251 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});
4252 return 0;
4253}
4254uint32_t ef_country_event_immediate_this_province(EFFECT_PARAMTERS) {
4255 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4256 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});
4257 return 0;
4258}
4259uint32_t ef_province_event_this_province(EFFECT_PARAMTERS) {
4260 auto postpone = int32_t(tval[2]);
4261 assert(postpone > 0);
4262 auto future_date = ws.current_date + postpone;
4263 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});
4264 return 0;
4265}
4266uint32_t ef_province_event_immediate_this_province(EFFECT_PARAMTERS) {
4267 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});
4268 return 0;
4269}
4270uint32_t ef_country_event_this_pop(EFFECT_PARAMTERS) {
4271 auto postpone = int32_t(tval[2]);
4272 assert(postpone > 0);
4273 auto future_date = ws.current_date + postpone;
4274 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), future_date))
4275 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});
4276 return 0;
4277}
4278uint32_t ef_country_event_immediate_this_pop(EFFECT_PARAMTERS) {
4279 if(!event::would_be_duplicate_instance(ws, trigger::payload(tval[1]).nev_id, trigger::to_nation(primary_slot), ws.current_date))
4280 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});
4281 return 0;
4282}
4283uint32_t ef_province_event_this_pop(EFFECT_PARAMTERS) {
4284 auto postpone = int32_t(tval[2]);
4285 assert(postpone > 0);
4286 auto future_date = ws.current_date + postpone;
4287 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});
4288 return 0;
4289}
4290uint32_t ef_province_event_immediate_this_pop(EFFECT_PARAMTERS) {
4291 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});
4292 return 0;
4293}
4294uint32_t ef_country_event_province_this_nation(EFFECT_PARAMTERS) {
4295 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4296 return ef_country_event_this_nation(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4297 return 0;
4298}
4299uint32_t ef_country_event_immediate_province_this_nation(EFFECT_PARAMTERS) {
4300 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4301 return ef_country_event_immediate_this_nation(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4302 return 0;
4303}
4304uint32_t ef_country_event_province_this_state(EFFECT_PARAMTERS) {
4305 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4306 return ef_country_event_this_state(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4307 return 0;
4308}
4309uint32_t ef_country_event_immediate_province_this_state(EFFECT_PARAMTERS) {
4310 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4311 return ef_country_event_immediate_this_state(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4312 return 0;
4313}
4314uint32_t ef_country_event_province_this_province(EFFECT_PARAMTERS) {
4315 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4316 return ef_country_event_this_province(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4317 return 0;
4318}
4319uint32_t ef_country_event_immediate_province_this_province(EFFECT_PARAMTERS) {
4320 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4321 return ef_country_event_immediate_this_province(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4322 return 0;
4323}
4324uint32_t ef_country_event_province_this_pop(EFFECT_PARAMTERS) {
4325 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4326 return ef_country_event_this_pop(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4327 return 0;
4328}
4329uint32_t ef_country_event_immediate_province_this_pop(EFFECT_PARAMTERS) {
4330 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4331 return ef_country_event_immediate_this_pop(tval, ws, trigger::to_generic(owner), this_slot, 0, r_lo, r_hi, els);
4332 return 0;
4333}
4334
4335uint32_t ef_sub_unit_int(EFFECT_PARAMTERS) {
4336 // do nothing
4337 return 0;
4338}
4339uint32_t ef_sub_unit_this(EFFECT_PARAMTERS) {
4340 // do nothing
4341 return 0;
4342}
4343uint32_t ef_sub_unit_from(EFFECT_PARAMTERS) {
4344 // do nothing
4345 return 0;
4346}
4347uint32_t ef_sub_unit_current(EFFECT_PARAMTERS) {
4348 // do nothing
4349 return 0;
4350}
4351uint32_t ef_set_variable(EFFECT_PARAMTERS) {
4352 auto amount = trigger::read_float_from_payload(tval + 2);
4353 assert(std::isfinite(amount));
4354
4355 ws.world.nation_get_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natv_id) = amount;
4356 return 0;
4357}
4358uint32_t ef_change_variable(EFFECT_PARAMTERS) {
4359 auto amount = trigger::read_float_from_payload(tval + 2);
4360 assert(std::isfinite(amount));
4361
4362 ws.world.nation_get_variables(trigger::to_nation(primary_slot), trigger::payload(tval[1]).natv_id) += amount;
4363 return 0;
4364}
4366 auto i = trigger::payload(tval[1]).ideo_id;
4367 auto factor = trigger::read_float_from_payload(tval + 2);
4368 assert(std::isfinite(factor));
4369
4370 auto s = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, i));
4371 float new_total = 1.0f - s + std::max(0.0f, s + factor);
4372 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, i), std::max(0.0f, s + factor));
4373
4374 for(auto j : ws.world.in_ideology) {
4376 pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, j)) / new_total);
4377 }
4378
4379 return 0;
4380}
4382 auto i = trigger::payload(tval[1]).ideo_id;
4383 auto amount = trigger::read_float_from_payload(tval + 2);
4384 assert(std::isfinite(amount));
4385
4386 auto& u = ws.world.nation_get_upper_house(trigger::to_nation(primary_slot), i);
4387 float new_total = 100.0f - u + std::max(0.0f, u + 100.0f * amount);
4388 u = std::max(0.0f, u + 100.0f * amount);
4389
4390
4391 for(auto j : ws.world.in_ideology) {
4392 //auto prior_value = ws.world.nation_get_upper_house(trigger::to_nation(primary_slot), j);
4393 //auto new_value = prior_value * 100.0f / (new_total);
4394 //ws.world.nation_set_upper_house(trigger::to_nation(primary_slot), j, prior_value);
4395 ws.world.nation_get_upper_house(trigger::to_nation(primary_slot), j) *= 100.0f / (new_total);
4396 }
4397
4398 return 0;
4399}
4400uint32_t ef_scaled_militancy_issue(EFFECT_PARAMTERS) {
4401 auto issue_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4402
4403 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), issue_demo_tag);
4404 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4405 assert(std::isfinite(adjustment));
4406 auto v = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
4407 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4408
4409 return 0;
4410}
4411uint32_t ef_scaled_militancy_ideology(EFFECT_PARAMTERS) {
4412 auto ideology_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4413
4414 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), ideology_demo_tag);
4415 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
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_militancy_unemployment(EFFECT_PARAMTERS) {
4423 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, trigger::to_pop(primary_slot));
4424 float adjustment = trigger::read_float_from_payload(tval + 1) * float(unemployed);
4425 assert(std::isfinite(adjustment));
4426 auto v = pop_demographics::get_militancy(ws, trigger::to_pop(primary_slot));
4427 pop_demographics::set_militancy(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4428
4429 return 0;
4430}
4431uint32_t ef_scaled_consciousness_issue(EFFECT_PARAMTERS) {
4432 auto issue_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4433
4434 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), issue_demo_tag);
4435 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4436 assert(std::isfinite(adjustment));
4437 auto v = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
4438 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4439
4440 return 0;
4441}
4442uint32_t ef_scaled_consciousness_ideology(EFFECT_PARAMTERS) {
4443 auto ideology_demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4444
4445 auto support = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), ideology_demo_tag);
4446 float adjustment = trigger::read_float_from_payload(tval + 2) * float(support);
4447 assert(std::isfinite(adjustment));
4448 auto v = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
4449 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4450
4451 return 0;
4452}
4453uint32_t ef_scaled_consciousness_unemployment(EFFECT_PARAMTERS) {
4454 auto unemployed = 1.0 - pop_demographics::get_employment(ws, trigger::to_pop(primary_slot));
4455 float adjustment = trigger::read_float_from_payload(tval + 1) * float(unemployed);
4456 auto v = pop_demographics::get_consciousness(ws, trigger::to_pop(primary_slot));
4457 pop_demographics::set_consciousness(ws, trigger::to_pop(primary_slot), std::clamp(v + adjustment, 0.0f, 10.0f));
4458
4459 return 0;
4460}
4461uint32_t ef_scaled_militancy_nation_issue(EFFECT_PARAMTERS) {
4462 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4463 auto factor = trigger::read_float_from_payload(tval + 2);
4464 assert(std::isfinite(factor));
4465
4466 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4467 for(auto pop : p.get_province().get_pop_location()) {
4468 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4469 float adjustment = factor * support;
4470 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4471 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4472 }
4473 }
4474
4475 return 0;
4476}
4477uint32_t ef_scaled_militancy_nation_ideology(EFFECT_PARAMTERS) {
4478 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4479 auto factor = trigger::read_float_from_payload(tval + 2);
4480 assert(std::isfinite(factor));
4481
4482 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4483 for(auto pop : p.get_province().get_pop_location()) {
4484 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4485 float adjustment = factor * support;
4486 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4487 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4488 }
4489 }
4490
4491 return 0;
4492}
4493uint32_t ef_scaled_militancy_nation_unemployment(EFFECT_PARAMTERS) {
4494 auto factor = trigger::read_float_from_payload(tval + 1);
4495 assert(std::isfinite(factor));
4496
4497 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4498 for(auto pop : p.get_province().get_pop_location()) {
4499 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4500 float adjustment = factor * unemployed;
4501 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4502 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4503 }
4504 }
4505
4506 return 0;
4507}
4508uint32_t ef_scaled_consciousness_nation_issue(EFFECT_PARAMTERS) {
4509 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4510 auto factor = trigger::read_float_from_payload(tval + 2);
4511 assert(std::isfinite(factor));
4512
4513 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4514 for(auto pop : p.get_province().get_pop_location()) {
4515 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4516 float adjustment = factor * support;
4517 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4518 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4519 }
4520 }
4521
4522 return 0;
4523}
4524uint32_t ef_scaled_consciousness_nation_ideology(EFFECT_PARAMTERS) {
4525 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4526 auto factor = trigger::read_float_from_payload(tval + 2);
4527 assert(std::isfinite(factor));
4528
4529 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4530 for(auto pop : p.get_province().get_pop_location()) {
4531 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4532 float adjustment = factor * support;
4533 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4534 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4535 }
4536 }
4537
4538 return 0;
4539}
4540uint32_t ef_scaled_consciousness_nation_unemployment(EFFECT_PARAMTERS) {
4541 auto factor = trigger::read_float_from_payload(tval + 1);
4542 assert(std::isfinite(factor));
4543
4544 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4545 for(auto pop : p.get_province().get_pop_location()) {
4546 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4547 float adjustment = factor * unemployed;
4548 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4549 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4550 }
4551 }
4552
4553 return 0;
4554}
4555uint32_t ef_scaled_militancy_state_issue(EFFECT_PARAMTERS) {
4556 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4557 auto factor = trigger::read_float_from_payload(tval + 2);
4558 assert(std::isfinite(factor));
4559
4560 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4561 for(auto pop : ws.world.province_get_pop_location(p)) {
4562 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4563 float adjustment = factor * support;
4564 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4565 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4566 }
4567 });
4568
4569 return 0;
4570}
4571uint32_t ef_scaled_militancy_state_ideology(EFFECT_PARAMTERS) {
4572 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4573 auto factor = trigger::read_float_from_payload(tval + 2);
4574 assert(std::isfinite(factor));
4575
4576 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4577 for(auto pop : ws.world.province_get_pop_location(p)) {
4578 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4579 float adjustment = factor * support;
4580 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4581 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4582 }
4583 });
4584
4585 return 0;
4586}
4587uint32_t ef_scaled_militancy_state_unemployment(EFFECT_PARAMTERS) {
4588 auto factor = trigger::read_float_from_payload(tval + 1);
4589 assert(std::isfinite(factor));
4590
4591 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4592 for(auto pop : ws.world.province_get_pop_location(p)) {
4593 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4594 float adjustment = factor * unemployed;
4595 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4596 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4597 }
4598 });
4599
4600 return 0;
4601}
4602uint32_t ef_scaled_consciousness_state_issue(EFFECT_PARAMTERS) {
4603 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4604 auto factor = trigger::read_float_from_payload(tval + 2);
4605 assert(std::isfinite(factor));
4606
4607 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4608 for(auto pop : ws.world.province_get_pop_location(p)) {
4609 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4610 float adjustment = factor * support;
4611 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4612 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4613 }
4614 });
4615
4616 return 0;
4617}
4618uint32_t ef_scaled_consciousness_state_ideology(EFFECT_PARAMTERS) {
4619 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4620 auto factor = trigger::read_float_from_payload(tval + 2);
4621 assert(std::isfinite(factor));
4622
4623 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4624 for(auto pop : ws.world.province_get_pop_location(p)) {
4625 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4626 float adjustment = factor * support;
4627 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4628 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4629 }
4630 });
4631
4632 return 0;
4633}
4634uint32_t ef_scaled_consciousness_state_unemployment(EFFECT_PARAMTERS) {
4635 auto factor = trigger::read_float_from_payload(tval + 1);
4636 assert(std::isfinite(factor));
4637
4638 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4639 for(auto pop : ws.world.province_get_pop_location(p)) {
4640 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4641 float adjustment = factor * unemployed;
4642 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4643 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4644 }
4645 });
4646
4647 return 0;
4648}
4649uint32_t ef_scaled_militancy_province_issue(EFFECT_PARAMTERS) {
4650 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4651 auto factor = trigger::read_float_from_payload(tval + 2);
4652 assert(std::isfinite(factor));
4653
4654 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4655 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4656 float adjustment = factor * support;
4657 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4658 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4659 }
4660
4661 return 0;
4662}
4663uint32_t ef_scaled_militancy_province_ideology(EFFECT_PARAMTERS) {
4664 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4665 auto factor = trigger::read_float_from_payload(tval + 2);
4666 assert(std::isfinite(factor));
4667
4668 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4669 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4670 float adjustment = factor * support;
4671 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4672 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4673 }
4674
4675 return 0;
4676}
4677uint32_t ef_scaled_militancy_province_unemployment(EFFECT_PARAMTERS) {
4678 auto factor = trigger::read_float_from_payload(tval + 1);
4679 assert(std::isfinite(factor));
4680
4681 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4682 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4683 float adjustment = factor * unemployed;
4684 auto v = pop_demographics::get_militancy(ws, pop.get_pop());
4685 pop_demographics::set_militancy(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4686 }
4687
4688 return 0;
4689}
4690uint32_t ef_scaled_consciousness_province_issue(EFFECT_PARAMTERS) {
4691 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4692 auto factor = trigger::read_float_from_payload(tval + 2);
4693 assert(std::isfinite(factor));
4694
4695 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4696 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4697 float adjustment = factor * support;
4698 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4699 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4700 }
4701
4702 return 0;
4703}
4704uint32_t ef_scaled_consciousness_province_ideology(EFFECT_PARAMTERS) {
4705 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).ideo_id);
4706 auto factor = trigger::read_float_from_payload(tval + 2);
4707 assert(std::isfinite(factor));
4708
4709 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4710 auto support = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4711 float adjustment = factor * support;
4712 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4713 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4714 }
4715
4716 return 0;
4717}
4718uint32_t ef_scaled_consciousness_province_unemployment(EFFECT_PARAMTERS) {
4719 auto factor = trigger::read_float_from_payload(tval + 1);
4720 assert(std::isfinite(factor));
4721
4722 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4723 auto unemployed = 1.0f - pop_demographics::get_raw_employment(ws, pop.get_pop());
4724 float adjustment = factor * unemployed;
4725 auto v = pop_demographics::get_consciousness(ws, pop.get_pop());
4726 pop_demographics::set_consciousness(ws, pop.get_pop(), std::clamp(v + adjustment, 0.0f, 10.0f));
4727 }
4728
4729 return 0;
4730}
4731uint32_t ef_variable_good_name(EFFECT_PARAMTERS) {
4732 auto amount = trigger::read_float_from_payload(tval + 2);
4733 assert(std::isfinite(amount));
4734 auto& v = ws.world.nation_get_stockpiles(trigger::to_nation(primary_slot), trigger::payload(tval[1]).com_id);
4735 v = std::max(v + amount, 0.0f);
4736 return 0;
4737}
4738uint32_t ef_variable_good_name_province(EFFECT_PARAMTERS) {
4739 auto amount = trigger::read_float_from_payload(tval + 2);
4740 assert(std::isfinite(amount));
4741 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner) {
4742 auto& v = ws.world.nation_get_stockpiles(owner, trigger::payload(tval[1]).com_id);
4743 v = std::max(v + amount, 0.0f);
4744 }
4745 return 0;
4746}
4748 dcon::unit_name_id ename{ dcon::unit_name_id::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
4749 auto esv = ws.to_string_view(ename);
4750 for(auto l : ws.world.nation_get_leader_loyalty(trigger::to_nation(primary_slot))) {
4751 auto n = l.get_leader().get_name();
4752 auto nsv = ws.to_string_view(n);
4753 if(nsv == esv) {
4754 military::kill_leader(ws, l.get_leader());
4755 return 0;
4756 }
4757 }
4758 return 0;
4759}
4760uint32_t ef_define_general(EFFECT_PARAMTERS) {
4761 auto l = fatten(ws.world, ws.world.create_leader());
4762 l.set_since(ws.current_date);
4763 l.set_is_admiral(false);
4764 l.set_background(trigger::payload(tval[4]).lead_id);
4765 l.set_personality(trigger::payload(tval[3]).lead_id);
4766 l.set_name(dcon::unit_name_id(dcon::unit_name_id::value_base_t(trigger::read_int32_t_from_payload(tval + 1))));
4767 l.set_nation_from_leader_loyalty(trigger::to_nation(primary_slot));
4768 return 0;
4769}
4770uint32_t ef_define_admiral(EFFECT_PARAMTERS) {
4771 auto l = fatten(ws.world, ws.world.create_leader());
4772 l.set_since(ws.current_date);
4773 l.set_is_admiral(true);
4774 l.set_background(trigger::payload(tval[4]).lead_id);
4775 l.set_personality(trigger::payload(tval[3]).lead_id);
4776 l.set_name(dcon::unit_name_id(dcon::unit_name_id::value_base_t(trigger::read_int32_t_from_payload(tval + 1))));
4777 l.set_nation_from_leader_loyalty(trigger::to_nation(primary_slot));
4778 return 0;
4779}
4780uint32_t ef_dominant_issue(EFFECT_PARAMTERS) {
4781 auto t = trigger::payload(tval[1]).opt_id;
4782 auto factor = trigger::read_float_from_payload(tval + 2);
4783
4784 auto s = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, t));
4785 auto new_total = 1.0f - s + std::max(0.0f, s + factor);
4786 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, t), std::max(0.0f, s + factor));
4787
4788 for(auto i : ws.world.in_issue_option) {
4790 pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), pop_demographics::to_key(ws, i)) / new_total);
4791 }
4792
4793 return 0;
4794}
4795uint32_t ef_dominant_issue_nation(EFFECT_PARAMTERS) {
4796 auto demo_tag = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4797 auto factor = trigger::read_float_from_payload(tval + 2);
4798
4799 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4800 for(auto pop : p.get_province().get_pop_location()) {
4801 auto s = pop_demographics::get_demo(ws, pop.get_pop(), demo_tag);
4802 auto new_total = 1.0f - s + std::max(0.0f, s + factor);
4803 pop_demographics::set_demo(ws, pop.get_pop(), demo_tag, std::max(0.0f, s + factor));
4804
4805 for(auto i : ws.world.in_issue_option) {
4806 pop_demographics::set_demo(ws, pop.get_pop(), pop_demographics::to_key(ws, i),
4807 pop_demographics::get_demo(ws, pop.get_pop(), pop_demographics::to_key(ws, i)) / new_total);
4808 }
4809 }
4810 }
4811
4812 return 0;
4813}
4814uint32_t ef_add_war_goal(EFFECT_PARAMTERS) {
4815 if(auto w = military::find_war_between(ws, trigger::to_nation(primary_slot), trigger::to_nation(from_slot)); w) {
4816 military::add_wargoal(ws, w, trigger::to_nation(from_slot), trigger::to_nation(primary_slot), trigger::payload(tval[1]).cb_id,
4817 dcon::state_definition_id{}, dcon::national_identity_id{}, trigger::to_nation(primary_slot));
4818 }
4819 return 0;
4820}
4821uint32_t ef_move_issue_percentage_nation(EFFECT_PARAMTERS) {
4822 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4823 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4824 auto amount = trigger::read_float_from_payload(tval + 3);
4825
4826 for(auto p : ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot))) {
4827 for(auto pop : p.get_province().get_pop_location()) {
4828 auto s = pop_demographics::get_demo(ws, pop.get_pop(), from_issue);
4829 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s - s * amount);
4830 auto s2 = pop_demographics::get_demo(ws, pop.get_pop(), to_issue);
4831 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s2 + s * amount);
4832 }
4833 }
4834
4835 return 0;
4836}
4837uint32_t ef_move_issue_percentage_state(EFFECT_PARAMTERS) {
4838 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4839 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4840 auto amount = trigger::read_float_from_payload(tval + 3);
4841
4842 province::for_each_province_in_state_instance(ws, trigger::to_state(primary_slot), [&](dcon::province_id p) {
4843 for(auto pop : ws.world.province_get_pop_location(p)) {
4844 auto s = pop_demographics::get_demo(ws, pop.get_pop(), from_issue);
4845 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s - s * amount);
4846 auto s2 = pop_demographics::get_demo(ws, pop.get_pop(), to_issue);
4847 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s2 + s * amount);
4848 }
4849 });
4850
4851 return 0;
4852}
4853uint32_t ef_move_issue_percentage_province(EFFECT_PARAMTERS) {
4854 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4855 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4856 auto amount = trigger::read_float_from_payload(tval + 3);
4857
4858 for(auto pop : ws.world.province_get_pop_location(trigger::to_prov(primary_slot))) {
4859 auto s = pop_demographics::get_demo(ws, pop.get_pop(), from_issue);
4860 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s - s * amount);
4861 auto s2 = pop_demographics::get_demo(ws, pop.get_pop(), to_issue);
4862 pop_demographics::set_demo(ws, pop.get_pop(), from_issue, s2 + s * amount);
4863 }
4864
4865 return 0;
4866}
4867uint32_t ef_move_issue_percentage_pop(EFFECT_PARAMTERS) {
4868 auto from_issue = pop_demographics::to_key(ws, trigger::payload(tval[1]).opt_id);
4869 auto to_issue = pop_demographics::to_key(ws, trigger::payload(tval[2]).opt_id);
4870 auto amount = trigger::read_float_from_payload(tval + 3);
4871
4872 auto s = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), from_issue);
4873 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), from_issue, s - s * amount);
4874 auto s2 = pop_demographics::get_demo(ws, trigger::to_pop(primary_slot), to_issue);
4875 pop_demographics::set_demo(ws, trigger::to_pop(primary_slot), from_issue, s2 + s * amount);
4876
4877 return 0;
4878}
4879uint32_t ef_party_loyalty(EFFECT_PARAMTERS) {
4880 auto i = trigger::payload(tval[2]).ideo_id;
4881 auto amount = float(trigger::payload(tval[3]).signed_value) / 100.0f;
4882 auto& v = ws.world.province_get_party_loyalty(trigger::payload(tval[1]).prov_id, i);
4883 v = std::clamp(v + amount, -1.0f, 1.0f);
4884 return 0;
4885}
4886uint32_t ef_party_loyalty_province(EFFECT_PARAMTERS) {
4887 auto i = trigger::payload(tval[1]).ideo_id;
4888 auto amount = float(trigger::payload(tval[2]).signed_value) / 100.0f;
4889 auto& v = ws.world.province_get_party_loyalty(trigger::to_prov(primary_slot), i);
4890 v = std::clamp(v + amount, -1.0f, 1.0f);
4891 return 0;
4892}
4893
4894uint32_t ef_build_railway_in_capital_yes_whole_state_yes_limit(EFFECT_PARAMTERS) {
4895 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4896 auto cs = ws.world.province_get_state_membership(c);
4897 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
4898 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f)
4899 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4900 });
4901 ws.railroad_built.store(true, std::memory_order::release);
4902 return 0;
4903}
4904uint32_t ef_build_railway_in_capital_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
4905 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4906 auto cs = ws.world.province_get_state_membership(c);
4907 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
4908 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f)
4909 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4910 });
4911 ws.railroad_built.store(true, std::memory_order::release);
4912 return 0;
4913}
4914uint32_t ef_build_railway_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
4915 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4916 if(c) {
4917 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f) {
4918 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4919 ws.railroad_built.store(true, std::memory_order::release);
4920 }
4921 }
4922 return 0;
4923}
4924uint32_t ef_build_railway_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
4925 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4926 if(c) {
4927 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_railroad) <= 1.0f) {
4928 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::railroad)) += uint8_t(1);
4929 ws.railroad_built.store(true, std::memory_order::release);
4930 }
4931 }
4932 return 0;
4933}
4934uint32_t ef_build_fort_in_capital_yes_whole_state_yes_limit(EFFECT_PARAMTERS) {
4935 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4936 auto cs = ws.world.province_get_state_membership(c);
4938 [&](dcon::province_id p) { ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort)) += uint8_t(1); });
4939 return 0;
4940}
4941uint32_t ef_build_fort_in_capital_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
4942 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4943 auto cs = ws.world.province_get_state_membership(c);
4945 [&](dcon::province_id p) { ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::fort)) += uint8_t(1); });
4946 return 0;
4947}
4948uint32_t ef_build_fort_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
4949 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4950 if(c) {
4951 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::fort)) += uint8_t(1);
4952 }
4953 return 0;
4954}
4955uint32_t ef_build_fort_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
4956 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
4957 if(c) {
4958 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::fort)) += uint8_t(1);
4959 }
4960 return 0;
4961}
4962uint32_t ef_relation_reb(EFFECT_PARAMTERS) {
4963 auto itag = ws.world.rebel_faction_get_defection_target(trigger::to_rebel(from_slot));
4964 if(auto holder = ws.world.national_identity_get_nation_from_identity_holder(itag); holder)
4965 nations::adjust_relationship(ws, trigger::to_nation(primary_slot), holder, float(trigger::payload(tval[1]).signed_value));
4966 return 0;
4967}
4968uint32_t ef_variable_tech_name_yes(EFFECT_PARAMTERS) {
4969 if(ws.world.nation_get_active_technologies(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id) == false)
4970 culture::apply_technology(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id);
4971 return 0;
4972}
4973uint32_t ef_variable_tech_name_no(EFFECT_PARAMTERS) {
4974 if(ws.world.nation_get_active_technologies(trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id) == true)
4975 culture::remove_technology(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).tech_id);
4976 return 0;
4977}
4978uint32_t ef_variable_invention_name_yes(EFFECT_PARAMTERS) {
4979 if(ws.world.nation_get_active_inventions(trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id) == false)
4980 culture::apply_invention(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id);
4981 return 0;
4982}
4983uint32_t ef_variable_invention_name_no(EFFECT_PARAMTERS) {
4984 if(ws.world.nation_get_active_inventions(trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id) == true)
4985 culture::remove_invention(ws, trigger::to_nation(primary_slot), trigger::payload(tval[1]).invt_id);
4986 return 0;
4987}
4988uint32_t ef_set_country_flag_province(EFFECT_PARAMTERS) {
4989 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
4990 return ef_set_country_flag(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
4991 return 0;
4992}
4994 if(auto owner = nations::owner_of_pop(ws, trigger::to_pop(primary_slot)); owner)
4995 return ef_set_country_flag(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
4996 return 0;
4997}
4998uint32_t ef_add_country_modifier_province(EFFECT_PARAMTERS) {
4999 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5000 return ef_add_country_modifier(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
5001 return 0;
5002}
5003uint32_t ef_add_country_modifier_province_no_duration(EFFECT_PARAMTERS) {
5004 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5005 return ef_add_country_modifier_no_duration(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
5006 return 0;
5007}
5008uint32_t ef_relation_province(EFFECT_PARAMTERS) {
5009 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5010 return ef_relation(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
5011 return 0;
5012}
5013uint32_t ef_relation_province_this_nation(EFFECT_PARAMTERS) {
5014 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5015 return ef_relation_this_nation(tval, ws, trigger::to_generic(owner), this_slot, 0, 0, 0, els);
5016 return 0;
5017}
5018uint32_t ef_relation_province_this_province(EFFECT_PARAMTERS) {
5019 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5020 return ef_relation_this_province(tval, ws, trigger::to_generic(owner), this_slot, 0, 0, 0, els);
5021 return 0;
5022}
5023uint32_t ef_relation_province_from_nation(EFFECT_PARAMTERS) {
5024 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5025 return ef_relation_this_nation(tval, ws, trigger::to_generic(owner), from_slot, 0, 0, 0, els);
5026 return 0;
5027}
5028uint32_t ef_relation_province_from_province(EFFECT_PARAMTERS) {
5029 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5030 return ef_relation_this_province(tval, ws, trigger::to_generic(owner), from_slot, 0, 0, 0, els);
5031 return 0;
5032}
5033uint32_t ef_relation_province_reb(EFFECT_PARAMTERS) {
5034 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5035 return ef_relation_reb(tval, ws, trigger::to_generic(owner), 0, from_slot, 0, 0, els);
5036 return 0;
5037}
5038uint32_t ef_treasury_province(EFFECT_PARAMTERS) {
5039 if(auto owner = ws.world.province_get_nation_from_province_ownership(trigger::to_prov(primary_slot)); owner)
5040 return ef_treasury(tval, ws, trigger::to_generic(owner), 0, 0, 0, 0, els);
5041 return 0;
5042}
5043
5044//
5045// Banks
5046//
5047uint32_t ef_build_bank_in_capital_yes_whole_state_yes_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_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
5057 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5058 auto cs = ws.world.province_get_state_membership(c);
5059 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
5060 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5061 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5062 });
5063 return 0;
5064}
5065uint32_t ef_build_bank_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
5066 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5067 if(c) {
5068 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5069 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5070 }
5071 return 0;
5072}
5073uint32_t ef_build_bank_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
5074 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5075 if(c) {
5076 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_bank) <= 1.0f)
5077 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::bank)) += uint8_t(1);
5078 }
5079 return 0;
5080}
5081//
5082// Banks
5083//
5084uint32_t ef_build_university_in_capital_yes_whole_state_yes_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_yes_whole_state_no_limit(EFFECT_PARAMTERS) {
5094 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5095 auto cs = ws.world.province_get_state_membership(c);
5096 province::for_each_province_in_state_instance(ws, cs, [&](dcon::province_id p) {
5097 if(ws.world.province_get_modifier_values(p, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5098 ws.world.province_get_building_level(p, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5099 });
5100 return 0;
5101}
5102uint32_t ef_build_university_in_capital_no_whole_state_yes_limit(EFFECT_PARAMTERS) {
5103 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5104 if(c) {
5105 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5106 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5107 }
5108 return 0;
5109}
5110uint32_t ef_build_university_in_capital_no_whole_state_no_limit(EFFECT_PARAMTERS) {
5111 auto c = ws.world.nation_get_capital(trigger::to_nation(primary_slot));
5112 if(c) {
5113 if(ws.world.province_get_modifier_values(c, sys::provincial_mod_offsets::min_build_university) <= 1.0f)
5114 ws.world.province_get_building_level(c, uint8_t(economy::province_building_type::university)) += uint8_t(1);
5115 }
5116 return 0;
5117}
5118
5120 auto sprovs = ws.world.nation_get_province_ownership(trigger::to_nation(primary_slot));
5121 while(sprovs.begin() != sprovs.end()) {
5122 province::change_province_owner(ws, (*sprovs.begin()).get_province().id, dcon::nation_id{});
5123 }
5124 return 0;
5125}
5127 province::change_province_owner(ws, trigger::to_prov(primary_slot), dcon::nation_id{ });
5128 return 0;
5129}
5130
5131uint32_t ef_fop_clr_global_flag_2(EFFECT_PARAMTERS) {
5132 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5133 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5134 return 0;
5135}
5136uint32_t ef_fop_clr_global_flag_3(EFFECT_PARAMTERS) {
5137 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5138 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5139 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5140 return 0;
5141}
5142uint32_t ef_fop_clr_global_flag_4(EFFECT_PARAMTERS) {
5143 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5144 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5145 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5146 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5147 return 0;
5148}
5149uint32_t ef_fop_clr_global_flag_5(EFFECT_PARAMTERS) {
5150 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5151 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5152 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5153 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5154 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5155 return 0;
5156}
5157uint32_t ef_fop_clr_global_flag_6(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 return 0;
5165}
5166uint32_t ef_fop_clr_global_flag_7(EFFECT_PARAMTERS) {
5167 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5168 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5169 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5170 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5171 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5172 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5173 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5174 return 0;
5175}
5176uint32_t ef_fop_clr_global_flag_8(EFFECT_PARAMTERS) {
5177 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5178 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5179 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5180 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5181 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5182 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5183 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5184 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5185 return 0;
5186}
5187uint32_t ef_fop_clr_global_flag_9(EFFECT_PARAMTERS) {
5188 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5189 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5190 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5191 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5192 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5193 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5194 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5195 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5196 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5197 return 0;
5198}
5199uint32_t ef_fop_clr_global_flag_10(EFFECT_PARAMTERS) {
5200 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5201 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5202 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5203 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5204 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5205 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5206 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5207 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5208 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5209 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[10]).glob_id, false);
5210 return 0;
5211}
5212uint32_t ef_fop_clr_global_flag_11(EFFECT_PARAMTERS) {
5213 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5214 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5215 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5216 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5217 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5218 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5219 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5220 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5221 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5222 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[10]).glob_id, false);
5223 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[11]).glob_id, false);
5224 return 0;
5225}
5226uint32_t ef_fop_clr_global_flag_12(EFFECT_PARAMTERS) {
5227 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[1]).glob_id, false);
5228 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[2]).glob_id, false);
5229 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[3]).glob_id, false);
5230 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[4]).glob_id, false);
5231 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[5]).glob_id, false);
5232 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[6]).glob_id, false);
5233 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[7]).glob_id, false);
5234 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[8]).glob_id, false);
5235 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[9]).glob_id, false);
5236 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[10]).glob_id, false);
5237 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[11]).glob_id, false);
5238 ws.national_definitions.set_global_flag_variable(trigger::payload(tval[12]).glob_id, false);
5239 return 0;
5240}
5241uint32_t ef_fop_change_province_name(EFFECT_PARAMTERS) {
5242 dcon::text_key name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 1)) };
5243 ws.world.province_set_name(trigger::payload(tval[3]).prov_id, name);
5244 return 0;
5245}
5246uint32_t ef_change_terrain_province(EFFECT_PARAMTERS) {
5247 auto const p = trigger::to_prov(primary_slot);
5248 ws.world.province_set_terrain(p, trigger::payload(tval[1]).mod_id);
5249 return 0;
5250}
5251uint32_t ef_change_terrain_pop(EFFECT_PARAMTERS) {
5252 auto const p = ws.world.pop_get_province_from_pop_location(trigger::to_pop(primary_slot));
5253 ws.world.province_set_terrain(p, trigger::payload(tval[1]).mod_id);
5254 return 0;
5255}
5256uint32_t ef_masquerade_as_nation_this(EFFECT_PARAMTERS) {
5257 auto dnid = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(this_slot));
5258 ws.world.nation_set_masquerade_identity(trigger::to_nation(primary_slot), dnid);
5259 return 0;
5260}
5261uint32_t ef_masquerade_as_nation_from(EFFECT_PARAMTERS) {
5262 auto dnid = ws.world.nation_get_identity_from_identity_holder(trigger::to_nation(from_slot));
5263 ws.world.nation_set_masquerade_identity(trigger::to_nation(primary_slot), dnid);
5264 return 0;
5265}
5266
5267uint32_t ef_change_party_name(EFFECT_PARAMTERS) {
5268 auto ideo = trigger::payload(tval[1]).ideo_id;
5269 dcon::text_key new_name{ dcon::text_key::value_base_t(trigger::read_int32_t_from_payload(tval + 2)) };
5270
5271 if(ideo) {
5272 auto n = trigger::to_nation(primary_slot);
5273 auto holder = ws.world.nation_get_identity_from_identity_holder(n);
5274
5275 auto start = ws.world.national_identity_get_political_party_first(holder).id.index();
5276 auto end = start + ws.world.national_identity_get_political_party_count(holder);
5277
5278 for(int32_t i = start; i < end; i++) {
5279 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5280 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5281 ws.world.political_party_set_name(pid, new_name);
5282 return 0;
5283 }
5284 }
5285 } else {
5286 auto n = trigger::to_nation(primary_slot);
5287 auto rp = ws.world.nation_get_ruling_party(n);
5288 if(rp) {
5289 ws.world.political_party_set_name(rp, new_name);
5290 }
5291 }
5292 return 0;
5293}
5294
5295uint32_t ef_change_party_position(EFFECT_PARAMTERS) {
5296 auto ideo = trigger::payload(tval[1]).ideo_id;
5297 dcon::issue_option_id new_opt = trigger::payload(tval[2]).opt_id;
5298 auto popt = ws.world.issue_option_get_parent_issue(new_opt);
5299
5300 if(ideo) {
5301 auto n = trigger::to_nation(primary_slot);
5302 auto holder = ws.world.nation_get_identity_from_identity_holder(n);
5303
5304 auto start = ws.world.national_identity_get_political_party_first(holder).id.index();
5305 auto end = start + ws.world.national_identity_get_political_party_count(holder);
5306
5307 for(int32_t i = start; i < end; i++) {
5308 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
5309 if(politics::political_party_is_active(ws, n, pid) && ws.world.political_party_get_ideology(pid) == ideo) {
5310 ws.world.political_party_set_party_issues(pid, popt, new_opt);
5311 if(ws.world.nation_get_ruling_party(n) == pid)
5312 politics::set_ruling_party(ws, n, pid); // force update of issues and rules
5313 return 0;
5314 }
5315 }
5316 } else {
5317 auto n = trigger::to_nation(primary_slot);
5318 auto rp = ws.world.nation_get_ruling_party(n);
5319 if(rp) {
5320 ws.world.political_party_set_party_issues(rp, popt, new_opt);
5321 politics::set_ruling_party(ws, n, rp); // force update of issues and rules
5322 }
5323 }
5324 return 0;
5325}
5326
5327inline constexpr uint32_t(*effect_functions[])(EFFECT_PARAMTERS) = {
5328 ef_none,
5329#define EFFECT_BYTECODE_ELEMENT(code, name, arg) ef_##name,
5331#undef EFFECT_BYTECODE_ELEMENT
5332 //
5333 // SCOPES
5334 //
5335 es_generic_scope, // constexpr inline uint16_t generic_scope = first_scope_code + 0x0000; // default grouping of effects (or hidden_tooltip)
5336 es_x_neighbor_province_scope, // constexpr inline uint16_t x_neighbor_province_scope = first_scope_code + 0x0001;
5337 es_x_neighbor_country_scope, // constexpr inline uint16_t x_neighbor_country_scope = first_scope_code + 0x0002;
5338 es_x_country_scope, // constexpr inline uint16_t x_country_scope = first_scope_code + 0x0003;
5339 es_x_country_scope_nation, // constexpr inline uint16_t x_country_scope_nation = first_scope_code + 0x0004;
5340 es_x_empty_neighbor_province_scope, // constexpr inline uint16_t x_empty_neighbor_province_scope = first_scope_code + 0x0005;
5341 es_x_greater_power_scope, // constexpr inline uint16_t x_greater_power_scope = first_scope_code + 0x0006;
5342 es_poor_strata_scope_nation, // constexpr inline uint16_t poor_strata_scope_nation = first_scope_code + 0x0007;
5343 es_poor_strata_scope_state, // constexpr inline uint16_t poor_strata_scope_state = first_scope_code + 0x0008;
5344 es_poor_strata_scope_province, // constexpr inline uint16_t poor_strata_scope_province = first_scope_code + 0x0009;
5345 es_middle_strata_scope_nation, // constexpr inline uint16_t middle_strata_scope_nation = first_scope_code + 0x000A;
5346 es_middle_strata_scope_state, // constexpr inline uint16_t middle_strata_scope_state = first_scope_code + 0x000B;
5347 es_middle_strata_scope_province, // constexpr inline uint16_t middle_strata_scope_province = first_scope_code + 0x000C;
5348 es_rich_strata_scope_nation, // constexpr inline uint16_t rich_strata_scope_nation = first_scope_code + 0x000D;
5349 es_rich_strata_scope_state, // constexpr inline uint16_t rich_strata_scope_state = first_scope_code + 0x000E;
5350 es_rich_strata_scope_province, // constexpr inline uint16_t rich_strata_scope_province = first_scope_code + 0x000F;
5351 es_x_pop_scope_nation, // constexpr inline uint16_t x_pop_scope_nation = first_scope_code + 0x0010;
5352 es_x_pop_scope_state, // constexpr inline uint16_t x_pop_scope_state = first_scope_code + 0x0011;
5353 es_x_pop_scope_province, // constexpr inline uint16_t x_pop_scope_province = first_scope_code + 0x0012;
5354 es_x_owned_scope_nation, // constexpr inline uint16_t x_owned_scope_nation = first_scope_code + 0x0013;
5355 es_x_owned_scope_state, // constexpr inline uint16_t x_owned_scope_state = first_scope_code + 0x0014;
5356 es_x_core_scope, // constexpr inline uint16_t x_core_scope = first_scope_code + 0x0015;
5357 es_x_state_scope, // constexpr inline uint16_t x_state_scope = first_scope_code + 0x0016;
5358 es_random_list_scope, // constexpr inline uint16_t random_list_scope = first_scope_code + 0x0017;
5359 es_random_scope, // constexpr inline uint16_t random_scope = first_scope_code + 0x0018;
5360 es_owner_scope_state, // constexpr inline uint16_t owner_scope_state = first_scope_code + 0x0019;
5361 es_owner_scope_province, // constexpr inline uint16_t owner_scope_province = first_scope_code + 0x001A;
5362 es_controller_scope, // constexpr inline uint16_t controller_scope = first_scope_code + 0x001B;
5363 es_location_scope, // constexpr inline uint16_t location_scope = first_scope_code + 0x001C;
5364 es_country_scope_pop, // constexpr inline uint16_t country_scope_pop = first_scope_code + 0x001D;
5365 es_country_scope_state, // constexpr inline uint16_t country_scope_state = first_scope_code + 0x001E;
5366 es_capital_scope, // constexpr inline uint16_t capital_scope = first_scope_code + 0x001F;
5367 es_this_scope_nation, // constexpr inline uint16_t this_scope_nation = first_scope_code + 0x0020;
5368 es_this_scope_state, // constexpr inline uint16_t this_scope_state = first_scope_code + 0x0021;
5369 es_this_scope_province, // constexpr inline uint16_t this_scope_province = first_scope_code + 0x0022;
5370 es_this_scope_pop, // constexpr inline uint16_t this_scope_pop = first_scope_code + 0x0023;
5371 es_from_scope_nation, // constexpr inline uint16_t from_scope_nation = first_scope_code + 0x0024;
5372 es_from_scope_state, // constexpr inline uint16_t from_scope_state = first_scope_code + 0x0025;
5373 es_from_scope_province, // constexpr inline uint16_t from_scope_province = first_scope_code + 0x0026;
5374 es_from_scope_pop, // constexpr inline uint16_t from_scope_pop = first_scope_code + 0x0027;
5375 es_sea_zone_scope, // constexpr inline uint16_t sea_zone_scope = first_scope_code + 0x0028;
5376 es_cultural_union_scope, // constexpr inline uint16_t cultural_union_scope = first_scope_code + 0x0029;
5377 es_overlord_scope, // constexpr inline uint16_t overlord_scope = first_scope_code + 0x002A;
5378 es_sphere_owner_scope, // constexpr inline uint16_t sphere_owner_scope = first_scope_code + 0x002B;
5379 es_independence_scope, // constexpr inline uint16_t independence_scope = first_scope_code + 0x002C;
5380 es_flashpoint_tag_scope, // constexpr inline uint16_t flashpoint_tag_scope = first_scope_code + 0x002D;
5381 es_crisis_state_scope, // constexpr inline uint16_t crisis_state_scope = first_scope_code + 0x002E;
5382 es_state_scope_pop, // constexpr inline uint16_t state_scope_pop = first_scope_code + 0x002F;
5383 es_state_scope_province, // constexpr inline uint16_t state_scope_province = first_scope_code + 0x0030;
5384 es_x_substate_scope, // constexpr inline uint16_t x_state_scope = first_scope_code + 0x0031;
5385 es_capital_scope_province, // constexpr inline uint16_t capital_scope = first_scope_code + 0x0032;
5386 es_x_core_scope_province, //constexpr inline uint16_t x_core_scope_province = first_scope_code + 0x0033;
5387 es_tag_scope, // constexpr inline uint16_t tag_scope = first_scope_code + 0x0034;
5388 es_integer_scope, // constexpr inline uint16_t integer_scope = first_scope_code + 0x0035;
5389 es_pop_type_scope_nation, // constexpr inline uint16_t pop_type_scope_nation = first_scope_code + 0x0036;
5390 es_pop_type_scope_state, // constexpr inline uint16_t pop_type_scope_state = first_scope_code + 0x0037;
5391 es_pop_type_scope_province, // constexpr inline uint16_t pop_type_scope_province = first_scope_code + 0x0038;
5392 es_region_proper_scope, //constexpr inline uint16_t region_proper_scope = first_scope_code + 0x0039;
5393 es_region_scope, // constexpr inline uint16_t region_scope = first_scope_code + 0x003A;
5394 es_if_scope, // constexpr inline uint16_t if_scope = first_scope_code + 0x003B;
5395 es_else_if_scope, // constexpr inline uint16_t else_if_scope = first_scope_code + 0x003C;
5396 es_x_event_country_scope, // constexpr inline uint16_t x_event_country_scope = first_scope_code + 0x003D;
5397 es_x_decision_country_scope, // constexpr inline uint16_t x_decision_country_scope = first_scope_code + 0x003E;
5398 es_x_event_country_scope_nation,//constexpr inline uint16_t x_event_country_scope_nation = first_scope_code + 0x003F;
5399 es_x_decision_country_scope_nation,//constexpr inline uint16_t x_decision_country_scope_nation = first_scope_code + 0x0040;
5400 es_from_bounce_scope,//constexpr inline uint16_t from_bounce_scope = first_scope_code + 0x0041;
5401 es_this_bounce_scope,//constexpr inline uint16_t this_bounce_scope = first_scope_code + 0x0042;
5402 es_random_by_modifier_scope,//constexpr inline uint16_t random_by_modifier_scope = first_scope_code + 0x0043;
5403 es_x_neighbor_province_scope_nation, // constexpr inline uint16_t x_neighbor_province_scope_nation = first_scope_code + 0x0044;
5404 es_x_empty_neighbor_province_scope_nation // constexpr inline uint16_t x_empty_neighbor_province_scope_nation = first_scope_code + 0x0045;
5405 // constexpr inline uint16_t first_invalid_code = first_scope_code + 0x0045;
5406};
5407
5410 return effect_functions[*tval & effect::code_mask](tval, ws, primary_slot, this_slot, from_slot, r_lo, r_hi, els);
5411}
5412
5413void execute(sys::state& state, dcon::effect_key key, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo,
5414 uint32_t r_hi) {
5415 bool els = false;
5416 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);
5417}
5418
5419void execute(sys::state& state, uint16_t const* data, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo,
5420 uint32_t r_hi) {
5421 bool els = false;
5422 internal_execute_effect(data, state, primary, this_slot, from_slot, r_lo, r_hi, els);
5423}
5424
5425} // 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:4008
void apply_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
Definition: culture.cpp:560
void replace_cores(sys::state &state, dcon::national_identity_id old_tag, dcon::national_identity_id new_tag)
Definition: culture.cpp:1112
void remove_invention(sys::state &state, dcon::nation_id target_nation, dcon::invention_id i_id)
Definition: culture.cpp:668
void remove_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
Definition: culture.cpp:486
void apply_technology(sys::state &state, dcon::nation_id target_nation, dcon::technology_id t_id)
Definition: culture.cpp:412
void update_nation_issue_rules(sys::state &state, dcon::nation_id n_id)
Definition: culture.cpp:831
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)
Pushes a diplomatic message to the list of pending diplomatic requests for the specified recipient (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:8669
uint32_t ef_consciousness_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3361
uint32_t ef_add_province_modifier_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3556
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:2921
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:3005
uint32_t ef_release_vassal_province_this_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:2907
uint32_t ef_release_vassal_province_from_province(EFFECT_PARAMTERS)
Definition: effects.cpp:2928
uint32_t ef_reduce_pop_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3104
uint32_t ef_annex_to_null_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:5119
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:3086
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:4993
uint32_t ef_militancy_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3400
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:5126
uint32_t ef_reduce_pop_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:3094
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:2942
int32_t get_effect_scope_payload_size(uint16_t const *data)
uint32_t ef_bank_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3462
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:5413
uint32_t ef_release_vassal_province_this_province(EFFECT_PARAMTERS)
Definition: effects.cpp:2914
constexpr uint16_t code_mask
uint32_t ef_fort_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3442
uint32_t ef_flashpoint_tension_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3314
uint32_t ef_consciousness_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3341
uint32_t ef_infrastructure_state(EFFECT_PARAMTERS)
Definition: effects.cpp:2574
uint32_t internal_execute_effect(EFFECT_PARAMTERS)
Definition: effects.cpp:5408
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:3044
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:2935
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:3469
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:2900
uint32_t ef_naval_base_state(EFFECT_PARAMTERS)
Definition: effects.cpp:3449
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:2714
uint32_t ef_militancy_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:3389
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:3380
uint32_t ef_social_reform_province(EFFECT_PARAMTERS)
Definition: effects.cpp:3027
uint32_t ef_remove_core_nation_this_province(EFFECT_PARAMTERS)
Definition: effects.cpp:1605
uint32_t ef_consciousness_nation(EFFECT_PARAMTERS)
Definition: effects.cpp:3350
uint32_t ef_add_province_modifier_state_no_duration(EFFECT_PARAMTERS)
Definition: effects.cpp:3562
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:7175
void remove_from_common_allied_wars(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:683
void end_wars_between(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:2343
bool has_truce_with(sys::state &state, dcon::nation_id attacker, dcon::nation_id target)
Definition: military.cpp:2296
bool standard_war_joining_is_possible(sys::state &state, dcon::war_id wfor, dcon::nation_id n, bool as_attacker)
Definition: military.cpp:2603
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:2668
dcon::war_id find_war_between(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:718
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:2509
void add_truce(sys::state &state, dcon::nation_id a, dcon::nation_id b, int32_t days)
Definition: military.cpp:3493
void give_military_access(sys::state &state, dcon::nation_id accessing_nation, dcon::nation_id target)
Definition: military.cpp:2329
void call_attacker_allies(sys::state &state, dcon::war_id wfor)
Definition: military.cpp:2648
void remove_military_access(sys::state &state, dcon::nation_id accessing_nation, dcon::nation_id target)
Definition: military.cpp:2336
void kill_leader(sys::state &state, dcon::leader_id l)
Definition: military.cpp:2150
void call_defender_allies(sys::state &state, dcon::war_id wfor)
Definition: military.cpp:2617
constexpr uint8_t level_in_sphere
Definition: nations.hpp:173
constexpr uint8_t level_mask
Definition: nations.hpp:167
void make_uncivilized(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:3325
void break_alliance(sys::state &state, dcon::diplomatic_relation_id rel)
Definition: nations.cpp:2012
void adjust_prestige(sys::state &state, dcon::nation_id n, float delta)
Definition: nations.cpp:1900
void destroy_diplomatic_relationships(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:1918
void make_vassal(sys::state &state, dcon::nation_id subject, dcon::nation_id overlord)
Definition: nations.cpp:1963
void release_vassal(sys::state &state, dcon::overlord_id rel)
Definition: nations.cpp:1948
void update_pop_acceptance(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:3043
void make_alliance(sys::state &state, dcon::nation_id a, dcon::nation_id b)
Definition: nations.cpp:2037
void adjust_influence_with_overflow(sys::state &state, dcon::nation_id great_power, dcon::nation_id target, float delta)
Definition: nations.cpp:3141
void liberate_nation_from(sys::state &state, dcon::national_identity_id liberated, dcon::nation_id from)
Definition: nations.cpp:3062
float prestige_score(sys::state const &state, dcon::nation_id n)
Definition: nations.cpp:961
float daily_research_points(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:741
void make_civilized(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:3218
void adjust_relationship(sys::state &state, dcon::nation_id a, dcon::nation_id b, float delta)
Definition: nations.cpp:1660
void create_nation_based_on_template(sys::state &state, dcon::nation_id n, dcon::nation_id base)
Definition: nations.cpp:1672
void perform_nationalization(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:3118
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
Definition: nations.cpp:87
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:1650
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:1735
void add_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1694
void remove_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
Definition: province.cpp:1704
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:1715
void set_province_controller(sys::state &state, dcon::province_id p, dcon::nation_id n)
Definition: province.cpp:157
void change_province_owner(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
Definition: province.cpp:716
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:1271
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:427
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:5895
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:5812
uint uint32_t
uchar uint8_t
#define EFFECT_BYTECODE_LIST
Holds data regarding a diplomatic message between two specified nations at a certain date,...
Holds important data about the game world, state, and other data regarding windowing,...
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