15 auto& nat_values =
state.
world.modifier_get_national_values(mod_id);
17 if(!(nat_values.offsets[i]))
20 auto fixed_offset = nat_values.offsets[i];
21 auto modifier_amount = nat_values.values[i];
22 state.
world.nation_get_modifier_values(target_nation, fixed_offset) += modifier_amount;
28 auto& nat_values =
state.
world.modifier_get_national_values(mod_id);
30 if(!(nat_values.offsets[i]))
33 auto fixed_offset = nat_values.offsets[i];
34 auto modifier_amount = nat_values.values[i];
35 state.
world.nation_get_modifier_values(target_nation, fixed_offset) += modifier_amount * scale;
40 auto& prov_values =
state.
world.modifier_get_province_values(mod_id);
41 auto owner =
state.
world.province_get_nation_from_province_ownership(target_prov);
43 if(!(prov_values.offsets[i]))
46 auto fixed_offset = prov_values.offsets[i];
47 auto modifier_amount = prov_values.values[i];
48 state.
world.province_get_modifier_values(target_prov, fixed_offset) += modifier_amount;
51 auto& nat_values =
state.
world.modifier_get_national_values(mod_id);
53 if(!(nat_values.offsets[i]))
56 auto fixed_offset = nat_values.offsets[i];
57 auto modifier_amount = nat_values.values[i];
58 state.
world.nation_get_modifier_values(owner, fixed_offset) += modifier_amount;
64 auto lst =
state.
world.nation_get_current_modifiers(target_nation);
66 if(m.mod_id == mod_id) {
67 if(!expiration || (m.expiration && m.expiration < expiration)) {
68 m.expiration = expiration;
76 auto lst =
state.
world.province_get_current_modifiers(target_prov);
78 if(m.mod_id == mod_id) {
79 if(!expiration || (m.expiration && m.expiration < expiration)) {
80 m.expiration = expiration;
88 auto modifiers_range =
state.
world.nation_get_current_modifiers(target_nation);
89 auto count = modifiers_range.size();
91 if(modifiers_range.at(i).mod_id == mod_id) {
92 modifiers_range.remove_at(i);
99 auto modifiers_range =
state.
world.province_get_current_modifiers(target_prov);
100 auto count = modifiers_range.size();
102 if(modifiers_range.at(i).mod_id == mod_id) {
103 modifiers_range.remove_at(i);
110 auto lst =
state.
world.province_get_current_modifiers(target_prov);
111 auto modifiers_range =
state.
world.province_get_current_modifiers(target_prov);
112 auto count = modifiers_range.size();
114 if(modifiers_range.at(i).mod_id == mod_id) {
115 modifiers_range.remove_at(i);
124 auto& nat_values =
state.
world.modifier_get_national_values(m);
126 if(!(nat_values.offsets[i]))
130 [&, fixed_offset = nat_values.offsets[i], modifier_amount = nat_values.values[i]](
auto nation_indices) {
131 auto has_mod_mask = mask_functor(nation_indices);
132 auto old_mod_value = state.world.nation_get_modifier_values(nation_indices, fixed_offset);
133 state.world.nation_set_modifier_values(nation_indices, fixed_offset,
134 ve::select(has_mod_mask, old_mod_value + modifier_amount, old_mod_value));
141 auto& nat_values =
state.
world.modifier_get_national_values(m);
143 if(!(nat_values.offsets[i]))
147 [&, fixed_offset = nat_values.offsets[i], modifier_amount = nat_values.values[i]](
auto nation_indices) {
148 auto scaling_factor = scale_functor(nation_indices);
149 auto old_mod_value = state.world.nation_get_modifier_values(nation_indices, fixed_offset);
150 state.world.nation_set_modifier_values(nation_indices, fixed_offset, old_mod_value + scaling_factor * modifier_amount);
157 auto& prov_values =
state.
world.modifier_get_province_values(mod_id);
160 if(!(prov_values.offsets[i]))
163 auto fixed_offset = prov_values.offsets[i];
164 auto modifier_amount = prov_values.values[i];
167 auto has_mod_mask = mask_functor(ids);
168 auto old_value =
state.
world.province_get_modifier_values(ids, fixed_offset);
169 state.
world.province_set_modifier_values(ids, fixed_offset,
170 ve::select(has_mod_mask, old_value + modifier_amount, old_value));
174 auto& nat_values =
state.
world.modifier_get_national_values(mod_id);
177 if(!(nat_values.offsets[i]))
180 auto fixed_offset = nat_values.offsets[i];
181 auto modifier_amount = nat_values.values[i];
184 auto owners =
state.
world.province_get_nation_from_province_ownership(ids);
185 auto has_mod_mask = mask_functor(ids) && (owners != dcon::nation_id{});
187 auto old_value =
state.
world.nation_get_modifier_values(owners, fixed_offset);
188 state.
world.nation_set_modifier_values(owners, fixed_offset,
189 ve::select(has_mod_mask, old_value + modifier_amount, old_value));
195 auto& prov_values =
state.
world.modifier_get_province_values(mod_id);
198 if(!(prov_values.offsets[i]))
201 auto fixed_offset = prov_values.offsets[i];
202 auto modifier_amount = prov_values.values[i];
205 auto old_value =
state.
world.province_get_modifier_values(ids, fixed_offset);
206 state.
world.province_set_modifier_values(ids, fixed_offset, old_value + modifier_amount);
213 auto& prov_values =
state.
world.modifier_get_province_values(mod_id);
216 if(!(prov_values.offsets[i]))
219 auto fixed_offset = prov_values.offsets[i];
220 auto modifier_amount = prov_values.values[i];
223 auto scale = scale_functor(ids);
224 auto old_value =
state.
world.province_get_modifier_values(ids, fixed_offset);
225 state.
world.province_set_modifier_values(ids, fixed_offset, old_value + modifier_amount * scale);
229 auto& nat_values =
state.
world.modifier_get_national_values(mod_id);
232 if(!(nat_values.offsets[i]))
235 auto fixed_offset = nat_values.offsets[i];
236 auto modifier_amount = nat_values.values[i];
239 auto owners =
state.
world.province_get_nation_from_province_ownership(ids);
240 auto scale =
ve::select(owners != dcon::nation_id{}, scale_functor(ids), 0.0f);
242 auto old_value =
state.
world.nation_get_modifier_values(owners, fixed_offset);
243 state.
world.nation_set_modifier_values(owners, fixed_offset, old_value + modifier_amount * scale);
252 auto timed_modifiers = n.get_current_modifiers();
253 for(
uint32_t i = timed_modifiers.size(); i-- > 0;) {
254 if(
bool(timed_modifiers[i].expiration) && timed_modifiers[i].expiration <
state.
current_date) {
255 timed_modifiers.remove_at(i);
261 dcon::national_modifier_value mid{dcon::national_modifier_value::value_base_t(i)};
262 state.
world.execute_serial_over_nation([&](
auto ids) {
state.
world.nation_set_modifier_values(ids, mid, ve::fp_vector{}); });
266 if(
auto ts = n.get_tech_school(); ts)
270 if(
auto nv = n.get_national_value(); nv)
274 for(
auto mpr :
state.
world.nation_get_current_modifiers(n)) {
278 state.
world.for_each_technology([&](dcon::technology_id t) {
279 auto tmod =
state.
world.technology_get_modifier(t);
282 [&](
auto ids) {
return state.
world.nation_get_active_technologies(ids, t); });
285 state.
world.for_each_invention([&](dcon::invention_id i) {
286 auto tmod =
state.
world.invention_get_modifier(i);
289 [&](
auto ids) {
return state.
world.nation_get_active_inventions(ids, i); });
292 state.
world.for_each_issue([&](dcon::issue_id i) {
294 auto iopt =
state.
world.nation_get_issues(n, i);
295 auto imod =
state.
world.issue_option_get_modifier(iopt);
301 state.
world.for_each_reform([&](dcon::reform_id i) {
303 auto iopt =
state.
world.nation_get_reforms(n, i);
304 auto imod =
state.
world.reform_option_get_modifier(iopt);
305 if(imod && !n.get_is_civilized()) {
311 auto in_wars = n.get_war_participant();
312 if(in_wars.begin() != in_wars.end()) {
323 [&](
auto ids) { return state.world.nation_get_infamy(ids); });
327 [&](
auto ids) { return state.world.nation_get_plurality(ids); });
331 [&](
auto ids) { return state.world.nation_get_war_exhaustion(ids); });
335 auto total = state.world.nation_get_demographics(ids, demographics::total);
336 return ve::select(total > 0, state.world.nation_get_demographics(ids, demographics::literacy) / total, 0.0f);
341 auto bc = ve::to_float(state.world.nation_get_central_blockaded(ids));
342 auto c = ve::to_float(state.world.nation_get_central_ports(ids));
343 return ve::select(c > 0.0f, bc / c, 0.0f);
349 [&](dcon::nation_id nid) {
350 auto n = fatten(state.world, nid);
351 auto cap_continent = n.get_capital().get_continent();
353 float occupied = 0.0f;
354 for(auto owned : n.get_province_ownership()) {
355 if(owned.get_province().get_continent() == cap_continent) {
357 if(auto c = owned.get_province().get_nation_from_province_control().id; c && c != n.id) {
363 return 100.0f * occupied / total;
370 for(
auto n : state.world.in_nation) {
371 if(n.get_is_civilized() ==
false) {
372 if(state.national_definitions.unciv_nation)
375 if(
state.national_definitions.great_power)
377 }
else if(
n.get_rank() <= uint16_t(
state.defines.colonial_rank)) {
378 if(
state.national_definitions.second_power)
381 if(
state.national_definitions.civ_nation)
385 if(
state.national_definitions.disarming) {
386 for(
auto n :
state.world.in_nation) {
387 if(
bool(
n.get_disarmed_until()) &&
n.get_disarmed_until() >
state.current_date) {
392 if(
state.national_definitions.in_bankrupcy) {
394 [&](
auto ids) { return state.world.nation_get_is_bankrupt(ids); });
398 for(
auto tm :
state.national_definitions.triggered_modifiers) {
399 if(tm.trigger_condition && tm.linked_modifier) {
400 auto& nat_values =
state.world.modifier_get_national_values(tm.linked_modifier);
401 auto size_used =
state.world.nation_size();
402 ve::execute_serial_fast<dcon::nation_id>(size_used, [&](
auto nids) {
403 auto trigger_condition_satisfied =
405 ve::apply([size_used](
auto n) {
return n.index() < int32_t(size_used); }, nids);
407 if(compressed_res.v == ve::vbitfield_type::storage(0)) {
411 if(!(nat_values.offsets[i]))
414 auto fixed_offset = nat_values.offsets[i];
415 auto modifier_amount = nat_values.values[i];
416 auto old_mod_value =
state.world.nation_get_modifier_values(nids, fixed_offset);
417 state.world.nation_set_modifier_values(nids, fixed_offset,
418 ve::select(trigger_condition_satisfied, old_mod_value + modifier_amount, old_mod_value));
429 dcon::national_modifier_value mid{dcon::national_modifier_value::value_base_t(i)};
430 state.
world.nation_set_modifier_values(n, mid, 0.0f);
433 if(
auto ts =
state.
world.nation_get_tech_school(n); ts)
436 if(
auto nv =
state.
world.nation_get_national_value(n); nv)
439 for(
auto mpr :
state.
world.nation_get_current_modifiers(n)) {
443 state.
world.for_each_technology([&](dcon::technology_id t) {
444 auto tmod =
state.
world.technology_get_modifier(t);
445 if(tmod &&
state.
world.nation_get_active_technologies(n, t)) {
446 apply_modifier_values_to_nation(state, n, tmod);
449 state.
world.for_each_invention([&](dcon::invention_id i) {
450 auto tmod =
state.
world.invention_get_modifier(i);
451 if(tmod &&
state.
world.nation_get_active_inventions(n, i)) {
452 apply_modifier_values_to_nation(state, n, tmod);
455 state.
world.for_each_issue([&](dcon::issue_id i) {
456 auto iopt =
state.
world.nation_get_issues(n, i);
457 auto imod =
state.
world.issue_option_get_modifier(iopt);
464 state.
world.for_each_reform([&](dcon::reform_id i) {
465 auto iopt =
state.
world.nation_get_reforms(n, i);
466 auto imod =
state.
world.reform_option_get_modifier(iopt);
473 auto in_wars =
state.
world.nation_get_war_participant(n);
474 if(in_wars.begin() != in_wars.end()) {
505 auto cap_continent = nid.get_capital().get_continent();
507 float occupied = 0.0f;
508 for(
auto owned : nid.get_province_ownership()) {
509 if(owned.get_province().get_continent() == cap_continent) {
511 if(
auto c = owned.get_province().get_nation_from_province_control().id; c && c != n) {
518 total > 0.0f ? occupied / total : 0.0f);
521 if(
state.
world.nation_get_is_civilized(n) ==
false) {
541 if(
bool(
state.
world.nation_get_is_bankrupt(n))) {
548 if(tm.trigger_condition && tm.linked_modifier) {
550 auto trigger_condition_satisfied =
553 if(trigger_condition_satisfied) {
563 auto timed_modifiers =
state.
world.province_get_current_modifiers(p);
564 for(
uint32_t i = timed_modifiers.size(); i-- > 0;) {
565 if(bool(timed_modifiers[i].expiration) && timed_modifiers[i].expiration < state.current_date) {
566 timed_modifiers.remove_at(i);
572 dcon::provincial_modifier_value mid{dcon::provincial_modifier_value::value_base_t(i)};
574 [&](
auto ids) {
state.world.province_set_modifier_values(ids, mid, ve::fp_vector{}); });
577 if(
state.national_definitions.land_province)
581 for(
auto mpr :
state.world.province_get_current_modifiers(p)) {
582 apply_modifier_values_to_province(state, p, mpr.mod_id);
587 if(
auto m =
state.world.province_get_terrain(p); m)
591 if(
auto m =
state.world.province_get_climate(p); m)
595 if(
auto m =
state.world.province_get_continent(p); m)
599 if(
auto m =
state.world.province_get_state_membership(p).get_owner_focus(); m)
603 if(
auto c =
state.world.province_get_crime(p); c) {
604 if(auto m = state.culture_definitions.crimes[c].modifier; m)
605 apply_modifier_values_to_province(state, p, m);
610 if(
state.economy_definitions.building_definitions[int32_t(t)].province_modifier) {
615 if(
state.national_definitions.infrastructure) {
617 return ve::to_float(state.world.province_get_building_level(ids, uint8_t(economy::province_building_type::railroad))) *
618 state.economy_definitions.building_definitions[int32_t(economy::province_building_type::railroad)].infrastructure;
621 if(
state.national_definitions.nationalism) {
623 return ve::select(state.world.province_get_is_owner_core(ids), 0.0f, state.world.province_get_nationalism(ids));
626 if(
state.national_definitions.non_coastal) {
628 [&](
auto ids) { return !state.world.province_get_is_coast(ids); });
630 if(
state.national_definitions.coastal) {
632 [&](
auto ids) { return state.world.province_get_is_coast(ids); });
634 if(
state.national_definitions.overseas) {
636 [&](
auto ids) { return province::is_overseas(state, ids); });
638 if(
state.national_definitions.core) {
640 [&](
auto ids) { return state.world.province_get_is_owner_core(ids); });
642 if(
state.national_definitions.has_siege) {
644 [&](
auto ids) { return military::province_is_under_siege(state, ids); });
646 if(
state.national_definitions.blockaded) {
648 [&](
auto ids) { return military::province_is_blockaded(state, ids); });
constexpr dcon::demographics_key total(0)
constexpr dcon::demographics_key literacy(5)
void bound_budget_settings(sys::state &state, dcon::nation_id n)
bool is_great_power(sys::state const &state, dcon::nation_id id)
void ve_for_each_land_province(sys::state &state, F const &func)
void for_each_land_province(sys::state &state, F const &func)
MOD_NAT_LIST constexpr uint32_t count
MOD_PROV_LIST constexpr uint32_t count
void recreate_province_modifiers(sys::state &state)
void bulk_apply_masked_modifier_to_nations(sys::state &state, dcon::modifier_id m, F const &mask_functor)
void toggle_modifier_from_province(sys::state &state, dcon::province_id target_prov, dcon::modifier_id mod_id, sys::date expiration)
void apply_modifier_values_to_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id)
void remove_modifier_from_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id)
void update_single_nation_modifiers(sys::state &state, dcon::nation_id n)
void repopulate_modifier_effects(sys::state &state)
void recreate_national_modifiers(sys::state &state)
void bulk_apply_scaled_modifier_to_nations(sys::state &state, dcon::modifier_id m, F const &scale_functor)
void update_modifier_effects(sys::state &state)
void apply_modifier_values_to_province(sys::state &state, dcon::province_id target_prov, dcon::modifier_id mod_id)
void add_modifier_to_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id, sys::date expiration)
void bulk_apply_modifier_to_provinces(sys::state &state, dcon::modifier_id mod_id)
void bulk_apply_masked_modifier_to_provinces(sys::state &state, dcon::modifier_id mod_id, F const &mask_functor)
void add_modifier_to_province(sys::state &state, dcon::province_id target_prov, dcon::modifier_id mod_id, sys::date expiration)
void bulk_apply_scaled_modifier_to_provinces(sys::state &state, dcon::modifier_id mod_id, F const &scale_functor)
void apply_scaled_modifier_values_to_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id, float scale)
void remove_modifier_from_province(sys::state &state, dcon::province_id target_prov, dcon::modifier_id mod_id)
int32_t to_generic(dcon::province_id v)
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
T select(bool v, T a, T b)
bool compress_mask(bool v)
float to_float(int32_t a)
dcon::modifier_id total_occupation
dcon::modifier_id total_blockaded
dcon::modifier_id unciv_nation
dcon::modifier_id in_bankrupcy
dcon::modifier_id disarming
dcon::modifier_id civ_nation
dcon::modifier_id plurality
std::vector< triggered_modifier > triggered_modifiers
dcon::modifier_id great_power
dcon::modifier_id war_exhaustion
dcon::modifier_id average_literacy
dcon::modifier_id second_power
static constexpr uint32_t modifier_definition_size
static constexpr uint32_t modifier_definition_size
dcon::data_container world
nations::global_national_state national_definitions