2#include "dcon_generated.hpp"
17 return dcon::pop_demographics_key(dcon::pop_demographics_key::value_base_t(v.index() +
count_special_keys));
20 return dcon::pop_demographics_key(
21 dcon::pop_demographics_key::value_base_t(state.world.ideology_size() + v.index() +
count_special_keys));
24 return state.world.ideology_size() + state.world.issue_option_size() +
count_special_keys;
28 state.world.for_each_pop([&](dcon::pop_id p) {
29 state.world.pop_set_is_primary_or_accepted_culture(p,
false);
31 if(state.world.nation_get_primary_culture(n) == state.world.pop_get_culture(p)) {
32 state.world.pop_set_is_primary_or_accepted_culture(p,
true);
35 if(state.world.nation_get_accepted_cultures(n, state.world.pop_get_culture(p)) ==
true) {
36 state.world.pop_set_is_primary_or_accepted_culture(p,
true);
43 auto ival = state.world.pop_get_udemographics(p, k);
47 state.world.pop_set_udemographics(p, k,
to_pu8(v));
51 state.world.pop_set_udemographics(p, k,
to_pu8(v));
54 auto ival = state.world.pop_get_umilitancy(p);
58 state.world.pop_set_umilitancy(p,
to_pmc(v));
62 state.world.pop_set_umilitancy(p,
to_pmc(v));
65 auto ival = state.world.pop_get_uconsciousness(p);
69 state.world.pop_set_uconsciousness(p,
to_pmc(v));
73 state.world.pop_set_uconsciousness(p,
to_pmc(v));
76 auto ival = state.world.pop_get_uliteracy(p);
81 state.world.pop_set_uliteracy(p,
to_pu16(v));
84 state.world.pop_set_uliteracy(p,
to_pu16(v));
87 auto ival = state.world.pop_get_uemployment(p);
88 return from_pu8(ival) * state.world.pop_get_size(p);
91 auto ival = state.world.pop_get_uemployment(p);
95 state.world.pop_set_uemployment(p,
to_pu8(v / state.world.pop_get_size(p)));
98 state.world.pop_set_uemployment(p,
to_pu8(v));
101 auto ival = state.world.pop_get_ulife_needs_satisfaction(p);
104template<
typename P,
typename V>
106 state.world.pop_set_ulife_needs_satisfaction(p,
to_pu8(v));
110template void set_life_needs<ve::contiguous_tags<dcon::pop_id>, ve::fp_vector>(
sys::state&, ve::contiguous_tags<dcon::pop_id>, ve::fp_vector);
111template void set_life_needs<ve::partial_contiguous_tags<dcon::pop_id>, ve::fp_vector>(
sys::state&, ve::partial_contiguous_tags<dcon::pop_id>, ve::fp_vector);
114 auto ival = state.world.pop_get_ueveryday_needs_satisfaction(p);
117template<
typename P,
typename V>
119 state.world.pop_set_ueveryday_needs_satisfaction(p,
to_pu8(v));
123template void set_everyday_needs<ve::contiguous_tags<dcon::pop_id>, ve::fp_vector>(
sys::state&, ve::contiguous_tags<dcon::pop_id>, ve::fp_vector);
124template void set_everyday_needs<ve::partial_contiguous_tags<dcon::pop_id>, ve::fp_vector>(
sys::state&, ve::partial_contiguous_tags<dcon::pop_id>, ve::fp_vector);
127 auto ival = state.world.pop_get_uluxury_needs_satisfaction(p);
130template<
typename P,
typename V>
132 state.world.pop_set_uluxury_needs_satisfaction(p,
to_pu8(v));
136template void set_luxury_needs<ve::contiguous_tags<dcon::pop_id>, ve::fp_vector>(
sys::state&, ve::contiguous_tags<dcon::pop_id>, ve::fp_vector);
137template void set_luxury_needs<ve::partial_contiguous_tags<dcon::pop_id>, ve::fp_vector>(
sys::state&, ve::partial_contiguous_tags<dcon::pop_id>, ve::fp_vector);
140 auto ival = state.world.pop_get_usocial_reform_desire(p);
144 state.world.pop_set_usocial_reform_desire(p,
to_pu8(v));
147 auto ival = state.world.pop_get_upolitical_reform_desire(p);
151 state.world.pop_set_upolitical_reform_desire(p,
to_pu8(v));
160 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
164 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
168 return dcon::demographics_key(
169 dcon::pop_demographics_key::value_base_t(
count_special_keys + state.world.pop_type_size() * 2 + v.index()));
172 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
count_special_keys + state.world.pop_type_size() * 2 + state.world.culture_size() + v.index()));
175 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
count_special_keys + state.world.pop_type_size() * 2 + state.world.culture_size() + state.world.ideology_size() + v.index()));
178 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
count_special_keys + state.world.pop_type_size() * 2 + state.world.culture_size() + state.world.ideology_size() + state.world.issue_option_size() + v.index()));
182 return count_special_keys + state.world.ideology_size() + state.world.issue_option_size() +
uint32_t(2) * state.world.pop_type_size() + state.world.culture_size() + state.world.religion_size();
193 state.world.for_each_pop([&](dcon::pop_id p) {
194 auto location = state.world.pop_get_province_from_pop_location(p);
195 state.world.province_get_demographics(location, key) += source(state, p);
198 state.world.execute_serial_over_state_instance(
199 [&](
auto si) { state.world.state_instance_set_demographics(si, key, ve::fp_vector()); });
202 auto location = state.world.province_get_state_membership(p);
203 state.world.state_instance_get_demographics(location, key) += state.world.province_get_demographics(p, key);
206 state.world.execute_serial_over_nation([&](
auto ni) { state.world.nation_set_demographics(ni, key, ve::fp_vector()); });
208 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
209 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
210 state.world.nation_get_demographics(location, key) += state.world.state_instance_get_demographics(s, key);
219 state.world.for_each_pop([&](dcon::pop_id p) {
220 auto location = state.world.pop_get_province_from_pop_location(p);
221 state.world.province_get_demographics_alt(location, key) += source(state, p);
224 state.world.execute_serial_over_state_instance(
225 [&](
auto si) { state.world.state_instance_set_demographics_alt(si, key, ve::fp_vector()); });
228 auto location = state.world.province_get_state_membership(p);
229 state.world.state_instance_get_demographics_alt(location, key) += state.world.province_get_demographics_alt(p, key);
232 state.world.execute_serial_over_nation([&](
auto ni) { state.world.nation_set_demographics_alt(ni, key, ve::fp_vector()); });
234 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
235 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
236 state.world.nation_get_demographics_alt(location, key) += state.world.state_instance_get_demographics_alt(s, key);
242 state.world.province_set_demographics_alt(pi, key, state.world.province_get_demographics(pi, key));
244 state.world.execute_serial_over_state_instance([&](
auto si) {
245 state.world.state_instance_set_demographics_alt(si, key, state.world.state_instance_get_demographics(si, key));
247 state.world.execute_serial_over_nation([&](
auto ni) {
248 state.world.nation_set_demographics_alt(ni, key, state.world.nation_get_demographics(ni, key));
257 for(
auto pc : state.world.nation_get_province_control_as_nation(n)) {
258 auto location = pc.get_province();
259 state.world.province_set_demographics(location, key, 0.f);
260 for(
auto pl : pc.get_province().get_pop_location_as_province()) {
261 state.world.province_get_demographics(location, key) += source(state, pl.get_pop());
264 for(
auto sc : state.world.nation_get_state_ownership_as_nation(n)) {
265 auto location = sc.get_state();
266 state.world.state_instance_set_demographics(location, key, 0.f);
267 for(
auto sm : sc.get_state().get_definition().get_abstract_state_membership()) {
268 state.world.state_instance_get_demographics(location, key) += state.world.province_get_demographics(sm.get_province(), key);
272 state.world.nation_set_demographics(n, key, 0.f);
273 for(
auto sc : state.world.nation_get_state_ownership_as_nation(n)) {
274 state.world.nation_get_demographics(n, key) += state.world.state_instance_get_demographics(sc.get_state(), key);
279 dcon::demographics_key key =
to_key(state, state.culture_definitions.jingoism);
281 for(
const auto pc : state.world.nation_get_province_control_as_nation(n)) {
290 auto const sz =
size(state);
292 auto const extra_size = sz - csz;
295 concurrency::parallel_for(
uint32_t(0), full ? sz : csz + extra_group_size, [&](
uint32_t base_index) {
296 auto index = base_index;
297 if constexpr(!full) {
304 dcon::demographics_key key{dcon::demographics_key::value_base_t(index)};
312 return state.world.pop_type_get_has_unemployment(state.world.pop_get_poptype(p)) ? state.world.pop_get_size(p) : 0.0f;
336 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
337 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
339 auto opt = state.world.movement_get_associated_issue_option(movement);
340 auto optpar = state.world.issue_option_get_parent_issue(opt);
341 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::political))
342 return state.world.pop_get_size(p);
351 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
352 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
354 auto opt = state.world.movement_get_associated_issue_option(movement);
355 auto optpar = state.world.issue_option_get_parent_issue(opt);
356 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::social))
357 return state.world.pop_get_size(p);
451 ? state.world.pop_get_size(p)
458 ? state.world.pop_get_size(p)
465 ? state.world.pop_get_size(p)
471 }
else if(key.index() <
to_employment_key(state, dcon::pop_type_id(0)).index()) {
472 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (
count_special_keys)) };
474 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
476 }
else if(
key.index() <
to_key(state, dcon::culture_id(0)).index()) {
477 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (
count_special_keys +
state.world.pop_type_size())) };
478 if(
state.world.pop_type_get_has_unemployment(pkey)) {
484 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
487 }
else if(
key.index() <
to_key(state, dcon::ideology_id(0)).index()) {
488 dcon::culture_id pkey{
491 return state.world.pop_get_culture(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
493 }
else if(
key.index() <
to_key(state, dcon::issue_option_id(0)).index()) {
494 dcon::ideology_id pkey{dcon::ideology_id::value_base_t(index - (
count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size()))};
499 }
else if(
key.index() <
to_key(state, dcon::religion_id(0)).index()) {
500 dcon::issue_option_id pkey{dcon::issue_option_id::value_base_t(index - (
count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size()))};
506 dcon::religion_id pkey{dcon::religion_id::value_base_t(
509 return state.world.pop_get_religion(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
520 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
522 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
523 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
524 state.world.for_each_culture([&](dcon::culture_id c) {
525 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
526 auto v =
state.world.province_get_demographics(p, k);
527 auto old_max = max_buffer.get(p);
528 auto mask = v > old_max;
529 state.world.province_set_dominant_culture(p,
530 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_culture(p)));
531 max_buffer.set(p,
ve::select(mask, v, old_max));
537 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
540 auto new_count =
state.world.state_instance_size();
541 if(new_count > old_count) {
542 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
543 old_count = new_count;
545 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
546 state.world.for_each_culture([&](dcon::culture_id c) {
547 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
548 auto v =
state.world.state_instance_get_demographics(p, k);
549 auto old_max = max_buffer.get(p);
550 auto mask = v > old_max;
551 state.world.state_instance_set_dominant_culture(p,
552 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.state_instance_get_dominant_culture(p)));
553 max_buffer.set(p,
ve::select(mask, v, old_max));
559 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
562 auto new_count =
state.world.nation_size();
563 if(new_count > old_count) {
564 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
565 old_count = new_count;
567 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
568 state.world.for_each_culture([&](dcon::culture_id c) {
569 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
570 auto v =
state.world.nation_get_demographics(p, k);
571 auto old_max = max_buffer.get(p);
572 auto mask = v > old_max;
573 state.world.nation_set_dominant_culture(p,
574 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.nation_get_dominant_culture(p)));
575 max_buffer.set(p,
ve::select(mask, v, old_max));
581 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
583 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
584 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
585 state.world.for_each_religion([&](dcon::religion_id c) {
586 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
587 auto v =
state.world.province_get_demographics(p, k);
588 auto old_max = max_buffer.get(p);
589 auto mask = v > old_max;
590 state.world.province_set_dominant_religion(p,
591 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.province_get_dominant_religion(p)));
592 max_buffer.set(p,
ve::select(mask, v, old_max));
598 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
601 auto new_count =
state.world.state_instance_size();
602 if(new_count > old_count) {
603 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
604 old_count = new_count;
606 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
607 state.world.for_each_religion([&](dcon::religion_id c) {
608 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
609 auto v =
state.world.state_instance_get_demographics(p, k);
610 auto old_max = max_buffer.get(p);
611 auto mask = v > old_max;
612 state.world.state_instance_set_dominant_religion(p,
613 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.state_instance_get_dominant_religion(p)));
614 max_buffer.set(p,
ve::select(mask, v, old_max));
620 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
623 auto new_count =
state.world.nation_size();
624 if(new_count > old_count) {
625 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
626 old_count = new_count;
628 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
629 state.world.for_each_religion([&](dcon::religion_id c) {
630 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
631 auto v =
state.world.nation_get_demographics(p, k);
632 auto old_max = max_buffer.get(p);
633 auto mask = v > old_max;
634 state.world.nation_set_dominant_religion(p,
635 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.nation_get_dominant_religion(p)));
636 max_buffer.set(p,
ve::select(mask, v, old_max));
642 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
644 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
645 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
646 state.world.for_each_ideology([&](dcon::ideology_id c) {
647 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
648 auto v =
state.world.province_get_demographics(p, k);
649 auto old_max = max_buffer.get(p);
650 auto mask = v > old_max;
651 state.world.province_set_dominant_ideology(p,
652 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.province_get_dominant_ideology(p)));
653 max_buffer.set(p,
ve::select(mask, v, old_max));
659 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
662 auto new_count =
state.world.state_instance_size();
663 if(new_count > old_count) {
664 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
665 old_count = new_count;
667 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
668 state.world.for_each_ideology([&](dcon::ideology_id c) {
669 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
670 auto v =
state.world.state_instance_get_demographics(p, k);
671 auto old_max = max_buffer.get(p);
672 auto mask = v > old_max;
673 state.world.state_instance_set_dominant_ideology(p,
674 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.state_instance_get_dominant_ideology(p)));
675 max_buffer.set(p,
ve::select(mask, v, old_max));
681 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
684 auto new_count =
state.world.nation_size();
685 if(new_count > old_count) {
686 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
687 old_count = new_count;
689 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
690 state.world.for_each_ideology([&](dcon::ideology_id c) {
691 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
692 auto v =
state.world.nation_get_demographics(p, k);
693 auto old_max = max_buffer.get(p);
694 auto mask = v > old_max;
695 state.world.nation_set_dominant_ideology(p,
696 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.nation_get_dominant_ideology(p)));
697 max_buffer.set(p,
ve::select(mask, v, old_max));
703 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
705 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
706 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
707 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
708 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
709 auto v =
state.world.province_get_demographics(p, k);
710 auto old_max = max_buffer.get(p);
711 auto mask = v > old_max;
712 state.world.province_set_dominant_issue_option(p,
713 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.province_get_dominant_issue_option(p)));
714 max_buffer.set(p,
ve::select(mask, v, old_max));
720 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
723 auto new_count =
state.world.state_instance_size();
724 if(new_count > old_count) {
725 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
726 old_count = new_count;
728 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
729 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
730 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
731 auto v =
state.world.state_instance_get_demographics(p, k);
732 auto old_max = max_buffer.get(p);
733 auto mask = v > old_max;
734 state.world.state_instance_set_dominant_issue_option(p,
ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.state_instance_get_dominant_issue_option(p)));
735 max_buffer.set(p,
ve::select(mask, v, old_max));
741 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
744 auto new_count =
state.world.nation_size();
745 if(new_count > old_count) {
746 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
747 old_count = new_count;
749 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
750 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
751 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
752 auto v =
state.world.nation_get_demographics(p, k);
753 auto old_max = max_buffer.get(p);
754 auto mask = v > old_max;
755 state.world.nation_set_dominant_issue_option(p,
756 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.nation_get_dominant_issue_option(p)));
757 max_buffer.set(p,
ve::select(mask, v, old_max));
763 static ve::vectorizable_buffer<float, dcon::pop_id> max_buffer(
uint32_t(1));
766 auto new_count =
state.world.pop_size();
767 if(new_count > old_count) {
768 max_buffer =
state.world.pop_make_vectorizable_float_buffer();
769 old_count = new_count;
771 state.world.execute_serial_over_pop([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
772 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
775 auto old_max = max_buffer.get(p);
776 auto mask = v > old_max;
777 state.world.pop_set_dominant_issue_option(p,
778 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.pop_get_dominant_issue_option(p)));
779 max_buffer.set(p,
ve::select(mask, v, old_max));
785 static ve::vectorizable_buffer<float, dcon::pop_id> max_buffer(
uint32_t(1));
788 auto new_count =
state.world.pop_size();
789 if(new_count > old_count) {
790 max_buffer =
state.world.pop_make_vectorizable_float_buffer();
791 old_count = new_count;
793 state.world.execute_serial_over_pop([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
794 state.world.for_each_ideology([&](dcon::ideology_id c) {
797 auto old_max = max_buffer.get(p);
798 auto mask = v > old_max;
799 state.world.pop_set_dominant_ideology(p,
800 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.pop_get_dominant_ideology(p)));
801 max_buffer.set(p,
ve::select(mask, v, old_max));
808 state.world.execute_serial_over_nation(
809 [&](
auto ni) {
state.world.nation_set_non_colonial_population(ni, ve::fp_vector()); });
811 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
812 if(!
state.world.province_get_is_colonial(
state.world.state_instance_get_capital(s))) {
813 auto location =
state.world.state_instance_get_nation_from_state_ownership(s);
814 state.world.nation_get_non_colonial_population(location) +=
822 state.world.execute_serial_over_nation(
823 [&](
auto ni) {
state.world.nation_set_non_colonial_bureaucrats(ni, ve::fp_vector()); });
825 state.world.for_each_state_instance(
827 if(!
state.world.province_get_is_colonial(
state.world.state_instance_get_capital(s))) {
828 auto location =
state.world.state_instance_get_nation_from_state_ownership(s);
829 state.world.nation_get_non_colonial_bureaucrats(location) +=
state.world.state_instance_get_demographics(s, k);
836 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
837 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
838 [&](
auto p) { state.world.province_set_dominant_accepted_culture(p, dcon::culture_id{}); });
839 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
840 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
842 state.world.for_each_culture([&](dcon::culture_id c) {
843 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, key =
to_key(state, c)](
auto p) {
844 auto v =
state.world.province_get_demographics(p, key);
845 auto old_max = max_buffer.get(p);
847 state.world.province_set_dominant_accepted_culture(p,
848 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_accepted_culture(p)));
849 max_buffer.set(p,
ve::select(mask, v, old_max));
861 regenerate_from_pop_data<true>(state);
864 regenerate_from_pop_data<false>(state);
869 auto const sz = size(state);
871 auto const extra_size = sz - csz;
874 concurrency::parallel_for(
uint32_t(0), full ? sz : csz + extra_group_size, [&](
uint32_t base_index) {
875 auto index = base_index;
876 if constexpr(!full) {
883 dcon::demographics_key key{ dcon::demographics_key::value_base_t(index) };
884 if(index < count_special_keys) {
891 return state.world.pop_type_get_has_unemployment(state.world.pop_get_poptype(p)) ? state.world.pop_get_size(p) : 0.0f;
915 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
916 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
918 auto opt = state.world.movement_get_associated_issue_option(movement);
919 auto optpar = state.world.issue_option_get_parent_issue(opt);
920 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::political))
921 return state.world.pop_get_size(p);
930 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
931 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
933 auto opt = state.world.movement_get_associated_issue_option(movement);
934 auto optpar = state.world.issue_option_get_parent_issue(opt);
935 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::social))
936 return state.world.pop_get_size(p);
1030 ? state.world.pop_get_size(p)
1037 ? state.world.pop_get_size(p)
1044 ? state.world.pop_get_size(p)
1050 }
else if(key.index() < to_employment_key(state, dcon::pop_type_id(0)).index()) {
1051 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys)) };
1053 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1055 }
else if(
key.index() <
to_key(state, dcon::culture_id(0)).index()) {
1056 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size())) };
1057 if(
state.world.pop_type_get_has_unemployment(pkey)) {
1063 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1066 }
else if(
key.index() <
to_key(state, dcon::ideology_id(0)).index()) {
1067 dcon::culture_id pkey{
1068 dcon::culture_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2)) };
1070 return state.world.pop_get_culture(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1072 }
else if(
key.index() <
to_key(state, dcon::issue_option_id(0)).index()) {
1073 dcon::ideology_id pkey{ dcon::ideology_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size())) };
1078 }
else if(
key.index() <
to_key(state, dcon::religion_id(0)).index()) {
1079 dcon::issue_option_id pkey{ dcon::issue_option_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size())) };
1085 dcon::religion_id pkey{ dcon::religion_id::value_base_t(
1086 index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size() +
state.world.issue_option_size())) };
1088 return state.world.pop_get_religion(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1101 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1103 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1104 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1105 state.world.for_each_culture([&](dcon::culture_id c) {
1106 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1107 auto v =
state.world.province_get_demographics_alt(p, k);
1108 auto old_max = max_buffer.get(p);
1109 auto mask = v > old_max;
1110 state.world.province_set_dominant_culture(p,
1111 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_culture(p)));
1112 max_buffer.set(p,
ve::select(mask, v, old_max));
1119 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1122 auto new_count =
state.world.state_instance_size();
1123 if(new_count > old_count) {
1124 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1125 old_count = new_count;
1127 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1128 state.world.for_each_culture([&](dcon::culture_id c) {
1129 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1130 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1131 auto old_max = max_buffer.get(p);
1132 auto mask = v > old_max;
1133 state.world.state_instance_set_dominant_culture(p,
1134 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.state_instance_get_dominant_culture(p)));
1135 max_buffer.set(p,
ve::select(mask, v, old_max));
1142 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1145 auto new_count =
state.world.nation_size();
1146 if(new_count > old_count) {
1147 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1148 old_count = new_count;
1150 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1151 state.world.for_each_culture([&](dcon::culture_id c) {
1152 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1153 auto v =
state.world.nation_get_demographics_alt(p, k);
1154 auto old_max = max_buffer.get(p);
1155 auto mask = v > old_max;
1156 state.world.nation_set_dominant_culture(p,
1157 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.nation_get_dominant_culture(p)));
1158 max_buffer.set(p,
ve::select(mask, v, old_max));
1165 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1167 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1168 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1169 state.world.for_each_religion([&](dcon::religion_id c) {
1170 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1171 auto v =
state.world.province_get_demographics_alt(p, k);
1172 auto old_max = max_buffer.get(p);
1173 auto mask = v > old_max;
1174 state.world.province_set_dominant_religion(p,
1175 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.province_get_dominant_religion(p)));
1176 max_buffer.set(p,
ve::select(mask, v, old_max));
1183 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1186 auto new_count =
state.world.state_instance_size();
1187 if(new_count > old_count) {
1188 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1189 old_count = new_count;
1191 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1192 state.world.for_each_religion([&](dcon::religion_id c) {
1193 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1194 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1195 auto old_max = max_buffer.get(p);
1196 auto mask = v > old_max;
1197 state.world.state_instance_set_dominant_religion(p,
1198 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.state_instance_get_dominant_religion(p)));
1199 max_buffer.set(p,
ve::select(mask, v, old_max));
1206 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1209 auto new_count =
state.world.nation_size();
1210 if(new_count > old_count) {
1211 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1212 old_count = new_count;
1214 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1215 state.world.for_each_religion([&](dcon::religion_id c) {
1216 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1217 auto v =
state.world.nation_get_demographics_alt(p, k);
1218 auto old_max = max_buffer.get(p);
1219 auto mask = v > old_max;
1220 state.world.nation_set_dominant_religion(p,
1221 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.nation_get_dominant_religion(p)));
1222 max_buffer.set(p,
ve::select(mask, v, old_max));
1229 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1231 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1232 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1233 state.world.for_each_ideology([&](dcon::ideology_id c) {
1234 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1235 auto v =
state.world.province_get_demographics_alt(p, k);
1236 auto old_max = max_buffer.get(p);
1237 auto mask = v > old_max;
1238 state.world.province_set_dominant_ideology(p,
1239 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.province_get_dominant_ideology(p)));
1240 max_buffer.set(p,
ve::select(mask, v, old_max));
1247 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1250 auto new_count =
state.world.state_instance_size();
1251 if(new_count > old_count) {
1252 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1253 old_count = new_count;
1255 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1256 state.world.for_each_ideology([&](dcon::ideology_id c) {
1257 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1258 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1259 auto old_max = max_buffer.get(p);
1260 auto mask = v > old_max;
1261 state.world.state_instance_set_dominant_ideology(p,
1262 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.state_instance_get_dominant_ideology(p)));
1263 max_buffer.set(p,
ve::select(mask, v, old_max));
1270 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1273 auto new_count =
state.world.nation_size();
1274 if(new_count > old_count) {
1275 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1276 old_count = new_count;
1278 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1279 state.world.for_each_ideology([&](dcon::ideology_id c) {
1280 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1281 auto v =
state.world.nation_get_demographics_alt(p, k);
1282 auto old_max = max_buffer.get(p);
1283 auto mask = v > old_max;
1284 state.world.nation_set_dominant_ideology(p,
1285 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.nation_get_dominant_ideology(p)));
1286 max_buffer.set(p,
ve::select(mask, v, old_max));
1293 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1295 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1296 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1297 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1298 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1299 auto v =
state.world.province_get_demographics_alt(p, k);
1300 auto old_max = max_buffer.get(p);
1301 auto mask = v > old_max;
1302 state.world.province_set_dominant_issue_option(p,
1303 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.province_get_dominant_issue_option(p)));
1304 max_buffer.set(p,
ve::select(mask, v, old_max));
1311 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1314 auto new_count =
state.world.state_instance_size();
1315 if(new_count > old_count) {
1316 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1317 old_count = new_count;
1319 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1320 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1321 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1322 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1323 auto old_max = max_buffer.get(p);
1324 auto mask = v > old_max;
1325 state.world.state_instance_set_dominant_issue_option(p,
ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.state_instance_get_dominant_issue_option(p)));
1326 max_buffer.set(p,
ve::select(mask, v, old_max));
1333 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1336 auto new_count =
state.world.nation_size();
1337 if(new_count > old_count) {
1338 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1339 old_count = new_count;
1341 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1342 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1343 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1344 auto v =
state.world.nation_get_demographics_alt(p, k);
1345 auto old_max = max_buffer.get(p);
1346 auto mask = v > old_max;
1347 state.world.nation_set_dominant_issue_option(p,
1348 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.nation_get_dominant_issue_option(p)));
1349 max_buffer.set(p,
ve::select(mask, v, old_max));
1362 auto const sz = size(state);
1364 auto const extra_size = sz - csz;
1367 for(
uint32_t base_index = 0; base_index < (full ? sz : csz + extra_group_size); ++ base_index) {
1368 auto index = base_index;
1369 if constexpr(!full) {
1376 dcon::demographics_key key{ dcon::demographics_key::value_base_t(index) };
1377 if(index < count_special_keys) {
1384 return state.world.pop_type_get_has_unemployment(state.world.pop_get_poptype(p)) ? state.world.pop_get_size(p) : 0.0f;
1408 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
1409 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
1411 auto opt = state.world.movement_get_associated_issue_option(movement);
1412 auto optpar = state.world.issue_option_get_parent_issue(opt);
1413 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::political))
1414 return state.world.pop_get_size(p);
1423 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
1424 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
1426 auto opt = state.world.movement_get_associated_issue_option(movement);
1427 auto optpar = state.world.issue_option_get_parent_issue(opt);
1428 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::social))
1429 return state.world.pop_get_size(p);
1523 ? state.world.pop_get_size(p)
1530 ? state.world.pop_get_size(p)
1537 ? state.world.pop_get_size(p)
1543 }
else if(key.index() < to_employment_key(state, dcon::pop_type_id(0)).index()) {
1544 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys)) };
1546 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1548 }
else if(
key.index() <
to_key(state, dcon::culture_id(0)).index()) {
1549 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size())) };
1550 if(
state.world.pop_type_get_has_unemployment(pkey)) {
1556 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1559 }
else if(
key.index() <
to_key(state, dcon::ideology_id(0)).index()) {
1560 dcon::culture_id pkey{
1561 dcon::culture_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2)) };
1563 return state.world.pop_get_culture(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1565 }
else if(
key.index() <
to_key(state, dcon::issue_option_id(0)).index()) {
1566 dcon::ideology_id pkey{ dcon::ideology_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size())) };
1571 }
else if(
key.index() <
to_key(state, dcon::religion_id(0)).index()) {
1572 dcon::issue_option_id pkey{ dcon::issue_option_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size())) };
1578 dcon::religion_id pkey{ dcon::religion_id::value_base_t(
1579 index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size() +
state.world.issue_option_size())) };
1581 return state.world.pop_get_religion(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1586 if constexpr(full ==
false) {
1587 for(
uint32_t base_index = csz; base_index < (full ? sz : csz + extra_group_size); ++base_index) {
1588 auto index = base_index;
1593 dcon::demographics_key
key{ dcon::demographics_key::value_base_t(index) };
1603 if((
state.current_date.value % 1) != 0) {
1607 for(
uint32_t index = l2_start; index < l2_end; ++index) {
1611 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1613 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1614 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1615 state.world.for_each_culture([&](dcon::culture_id c) {
1616 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1617 auto v =
state.world.province_get_demographics_alt(p, k);
1618 auto old_max = max_buffer.get(p);
1619 auto mask = v > old_max;
1620 state.world.province_set_dominant_culture(p,
1621 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_culture(p)));
1622 max_buffer.set(p,
ve::select(mask, v, old_max));
1629 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1632 auto new_count =
state.world.state_instance_size();
1633 if(new_count > old_count) {
1634 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1635 old_count = new_count;
1637 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1638 state.world.for_each_culture([&](dcon::culture_id c) {
1639 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1640 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1641 auto old_max = max_buffer.get(p);
1642 auto mask = v > old_max;
1643 state.world.state_instance_set_dominant_culture(p,
1644 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.state_instance_get_dominant_culture(p)));
1645 max_buffer.set(p,
ve::select(mask, v, old_max));
1652 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1655 auto new_count =
state.world.nation_size();
1656 if(new_count > old_count) {
1657 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1658 old_count = new_count;
1660 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1661 state.world.for_each_culture([&](dcon::culture_id c) {
1662 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1663 auto v =
state.world.nation_get_demographics_alt(p, k);
1664 auto old_max = max_buffer.get(p);
1665 auto mask = v > old_max;
1666 state.world.nation_set_dominant_culture(p,
1667 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.nation_get_dominant_culture(p)));
1668 max_buffer.set(p,
ve::select(mask, v, old_max));
1675 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1677 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1678 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1679 state.world.for_each_religion([&](dcon::religion_id c) {
1680 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1681 auto v =
state.world.province_get_demographics_alt(p, k);
1682 auto old_max = max_buffer.get(p);
1683 auto mask = v > old_max;
1684 state.world.province_set_dominant_religion(p,
1685 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.province_get_dominant_religion(p)));
1686 max_buffer.set(p,
ve::select(mask, v, old_max));
1693 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1696 auto new_count =
state.world.state_instance_size();
1697 if(new_count > old_count) {
1698 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1699 old_count = new_count;
1701 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1702 state.world.for_each_religion([&](dcon::religion_id c) {
1703 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1704 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1705 auto old_max = max_buffer.get(p);
1706 auto mask = v > old_max;
1707 state.world.state_instance_set_dominant_religion(p,
1708 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.state_instance_get_dominant_religion(p)));
1709 max_buffer.set(p,
ve::select(mask, v, old_max));
1716 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1719 auto new_count =
state.world.nation_size();
1720 if(new_count > old_count) {
1721 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1722 old_count = new_count;
1724 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1725 state.world.for_each_religion([&](dcon::religion_id c) {
1726 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1727 auto v =
state.world.nation_get_demographics_alt(p, k);
1728 auto old_max = max_buffer.get(p);
1729 auto mask = v > old_max;
1730 state.world.nation_set_dominant_religion(p,
1731 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.nation_get_dominant_religion(p)));
1732 max_buffer.set(p,
ve::select(mask, v, old_max));
1739 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1741 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1742 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1743 state.world.for_each_ideology([&](dcon::ideology_id c) {
1744 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1745 auto v =
state.world.province_get_demographics_alt(p, k);
1746 auto old_max = max_buffer.get(p);
1747 auto mask = v > old_max;
1748 state.world.province_set_dominant_ideology(p,
1749 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.province_get_dominant_ideology(p)));
1750 max_buffer.set(p,
ve::select(mask, v, old_max));
1757 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1760 auto new_count =
state.world.state_instance_size();
1761 if(new_count > old_count) {
1762 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1763 old_count = new_count;
1765 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1766 state.world.for_each_ideology([&](dcon::ideology_id c) {
1767 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1768 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1769 auto old_max = max_buffer.get(p);
1770 auto mask = v > old_max;
1771 state.world.state_instance_set_dominant_ideology(p,
1772 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.state_instance_get_dominant_ideology(p)));
1773 max_buffer.set(p,
ve::select(mask, v, old_max));
1780 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1783 auto new_count =
state.world.nation_size();
1784 if(new_count > old_count) {
1785 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1786 old_count = new_count;
1788 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1789 state.world.for_each_ideology([&](dcon::ideology_id c) {
1790 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1791 auto v =
state.world.nation_get_demographics_alt(p, k);
1792 auto old_max = max_buffer.get(p);
1793 auto mask = v > old_max;
1794 state.world.nation_set_dominant_ideology(p,
1795 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.nation_get_dominant_ideology(p)));
1796 max_buffer.set(p,
ve::select(mask, v, old_max));
1803 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1805 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1806 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1807 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1808 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1809 auto v =
state.world.province_get_demographics_alt(p, k);
1810 auto old_max = max_buffer.get(p);
1811 auto mask = v > old_max;
1812 state.world.province_set_dominant_issue_option(p,
1813 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.province_get_dominant_issue_option(p)));
1814 max_buffer.set(p,
ve::select(mask, v, old_max));
1821 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1824 auto new_count =
state.world.state_instance_size();
1825 if(new_count > old_count) {
1826 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1827 old_count = new_count;
1829 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1830 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1831 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1832 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1833 auto old_max = max_buffer.get(p);
1834 auto mask = v > old_max;
1835 state.world.state_instance_set_dominant_issue_option(p,
ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.state_instance_get_dominant_issue_option(p)));
1836 max_buffer.set(p,
ve::select(mask, v, old_max));
1843 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1846 auto new_count =
state.world.nation_size();
1847 if(new_count > old_count) {
1848 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1849 old_count = new_count;
1851 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1852 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1853 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1854 auto v =
state.world.nation_get_demographics_alt(p, k);
1855 auto old_max = max_buffer.get(p);
1856 auto mask = v > old_max;
1857 state.world.nation_set_dominant_issue_option(p,
1858 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.nation_get_dominant_issue_option(p)));
1859 max_buffer.set(p,
ve::select(mask, v, old_max));
1871 alt_st_regenerate_from_pop_data<false>(state);
1874 alt_mt_regenerate_from_pop_data<true>(state);
1884 state.world.execute_serial_over_nation(
1885 [&](
auto ni) { state.world.nation_set_non_colonial_population(ni, ve::fp_vector()); });
1887 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
1888 if(!state.world.province_get_is_colonial(state.world.state_instance_get_capital(s))) {
1889 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
1890 state.world.nation_get_non_colonial_population(location) +=
1891 state.world.state_instance_get_demographics(s, demographics::total);
1899 state.world.execute_serial_over_nation(
1900 [&](
auto ni) { state.world.nation_set_non_colonial_bureaucrats(ni, ve::fp_vector()); });
1902 state.world.for_each_state_instance(
1903 [&, k =
demographics::to_key(state, state.culture_definitions.bureaucrat)](dcon::state_instance_id s) {
1904 if(!state.world.province_get_is_colonial(state.world.state_instance_get_capital(s))) {
1905 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
1906 state.world.nation_get_non_colonial_bureaucrats(location) += state.world.state_instance_get_demographics(s, k);
1913 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer = state.world.province_make_vectorizable_float_buffer();
1914 ve::execute_serial<dcon::province_id>(
uint32_t(state.province_definitions.first_sea_province.index()),
1915 [&](
auto p) { state.world.province_set_dominant_accepted_culture(p, dcon::culture_id{}); });
1916 ve::execute_serial<dcon::province_id>(
uint32_t(state.province_definitions.first_sea_province.index()),
1917 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1919 state.world.for_each_culture([&](dcon::culture_id c) {
1920 ve::execute_serial<dcon::province_id>(
uint32_t(state.province_definitions.first_sea_province.index()), [&, key = to_key(state, c)](
auto p) {
1921 auto v = state.world.province_get_demographics_alt(p, key);
1922 auto old_max = max_buffer.get(p);
1924 state.world.province_set_dominant_accepted_culture(p,
1925 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c), state.world.province_get_dominant_accepted_culture(p)));
1926 max_buffer.set(p,
ve::select(mask, v, old_max));
1939 auto block_index = 16 * offset;
1940 auto const block_advance = 16 * divisions;
1944 while(block_index < max) {
1946 functor(ve::contiguous_tags<dcon::pop_id>(block_index + i * ve::vector_size));
1948 block_index += block_advance;
1954 concurrency::parallel_for(16 * offset, max, 16 * divisions, [&](
uint32_t index) {
1956 functor(ve::contiguous_tags<dcon::pop_id>(index + i * ve::vector_size));
1986 auto loc = state.world.pop_get_province_from_pop_location(ids);
1987 auto owner = state.world.province_get_nation_from_province_ownership(loc);
1988 auto ruling_party = state.world.nation_get_ruling_party(owner);
1989 auto ruling_ideology = state.world.political_party_get_ideology(ruling_party);
1991 auto lx_mod = ve::max(pop_demographics::get_luxury_needs(state, ids) - 0.5f, 0.0f) * state.defines.mil_has_luxury_need;
1992 auto con_sup = (pop_demographics::get_demo(state, ids, conservatism_key) * state.defines.mil_ideology);
1993 auto ruling_sup = ve::apply(
1994 [&](dcon::pop_id p, dcon::ideology_id i) {
1995 return i ? pop_demographics::get_demo(state, p, pop_demographics::to_key(state, i)) * state.defines.mil_ruling_party
1998 ids, ruling_ideology);
1999 auto ref_mod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2001 (state.defines.mil_require_reform * 0.25f));
2003 auto o_spending = state.world.nation_get_overseas_penalty(owner);
2004 auto spending_level = state.world.nation_get_spending_level(owner);
2007 (state.defines.alice_overseas_mil * 2.f)
2008 * (0.5f - (o_spending * spending_level)),
2012 auto sub_t = (lx_mod + ruling_sup) + (con_sup + ref_mod);
2014 auto pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_militancy_modifier);
2015 auto omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_militancy_modifier);
2016 auto cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2017 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_militancy_modifier));
2019 auto local_mod = (pmod + omod) + cmod;
2021 auto sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2022 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f) *
2023 state.defines.mil_non_accepted);
2030 auto war_exhaustion = state.world.nation_get_war_exhaustion(owner) * state.defines.mil_war_exhaustion;
2039 owner != dcon::nation_id{},
2044 + old_mil * (1.f - state.defines.alice_militancy_decay)
2048 + (en_mod_b - en_mod_a)
2049 + (war_exhaustion + overseas_mil)
2064 auto loc = state.world.pop_get_province_from_pop_location(ids);
2065 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2066 auto ruling_party = state.world.nation_get_ruling_party(owner);
2067 auto ruling_ideology = state.world.political_party_get_ideology(ruling_party);
2071 float ruling_sup = ruling_ideology
2074 float ref_mod = state.world.province_get_is_colonial(loc) ? 0.0f :
2076 (state.defines.mil_require_reform * 0.25f);
2078 auto o_spending = state.world.nation_get_overseas_penalty(owner);
2079 auto spending_level = state.world.nation_get_spending_level(owner);
2082 (state.defines.alice_overseas_mil * 2.f)
2083 * (0.5f - (o_spending * spending_level)),
2087 float sub_t = (lx_mod + ruling_sup) + (con_sup + ref_mod);
2089 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_militancy_modifier);
2090 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_militancy_modifier);
2091 float cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2092 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_militancy_modifier));
2094 float local_mod = (pmod + omod) + cmod;
2096 float sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2097 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f) *
2098 state.defines.mil_non_accepted);
2104 float war_exhaustion =
2105 state.world.nation_get_war_exhaustion(owner) * 0.005f;
2108 return (sub_t + local_mod) + ((sep_mod - ln_mod) + (en_mod_b - en_mod_a) + (war_exhaustion + overseas_mil)) - old_mil * state.defines.alice_militancy_decay;
2113 for(
auto prov :
dcon::fatten(state.world, n).get_province_ownership()) {
2114 for(
auto pop : prov.get_province().get_pop_location()) {
2119 return t != 0.f ? sum / t : 0.f;
2138 auto loc = state.world.pop_get_province_from_pop_location(ids);
2139 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2141 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
2142 auto types = state.world.pop_get_poptype(ids);
2144 auto lx_mod = pop_demographics::get_luxury_needs(state, ids) * state.defines.con_luxury_goods;
2145 auto cl_mod = cfrac * ve::select(state.world.pop_type_get_strata(types) == int32_t(culture::pop_strata::poor),
2146 ve::fp_vector{state.defines.con_poor_clergy}, ve::fp_vector{state.defines.con_midrich_clergy});
2147 auto lit_mod = ((state.world.nation_get_plurality(owner) / 10.0f) * (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::literacy_con_impact) + 1.0f) *
2150 auto pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_consciousness_modifier);
2151 auto omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_consciousness_modifier);
2152 auto cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2153 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_consciousness_modifier));
2155 auto local_mod = (pmod + omod) + cmod;
2157 auto sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2158 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_consciousness_modifier));
2163 ve::min(ve::max(
ve::select(owner != dcon::nation_id{}, ((old_con * 0.99f + lx_mod) + (cl_mod + lit_mod)) + (local_mod + sep_mod), 0.0f), 0.0f), 10.f));
2170 auto loc = state.world.pop_get_province_from_pop_location(ids);
2171 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2173 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc,
demographics::total);
2174 auto types = state.world.pop_get_poptype(ids);
2178 state.defines.con_poor_clergy, state.defines.con_midrich_clergy);
2179 float lit_mod = ((state.world.nation_get_plurality(owner) / 10.0f) *
2180 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::literacy_con_impact) + 1.0f) *
2182 ve::select(state.world.province_get_is_colonial(loc), state.defines.con_colonial_factor, 1.0f)) / 10.f;
2184 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_consciousness_modifier);
2185 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_consciousness_modifier);
2186 float cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2187 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_consciousness_modifier));
2189 float local_mod = (pmod + omod) + cmod;
2191 float sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2192 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_consciousness_modifier));
2195 return (lx_mod + (cl_mod + lit_mod)) + (local_mod + sep_mod) - old_con * 0.01f;
2200 for(
auto prov :
dcon::fatten(state.world, n).get_province_ownership()) {
2201 for(
auto pop : prov.get_province().get_pop_location()) {
2206 return t != 0.f ? sum / t : 0.f;
2229 auto loc = state.world.pop_get_province_from_pop_location(ids);
2230 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2232 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
2234 auto tmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency) + 1.0f;
2235 auto nmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency_modifier) + 1.0f;
2236 auto espending = 0.5f +
2237 (ve::to_float(state.world.nation_get_education_spending(owner)) / 100.0f) * state.world.nation_get_spending_level(owner) * 0.5f;
2238 auto cmod = ve::max(
2242 (cfrac - state.defines.base_clergy_for_literacy)
2243 / (state.defines.max_clergy_for_literacy - state.defines.base_clergy_for_literacy)
2247 auto old_lit = pop_demographics::get_literacy(state, ids);
2248 auto new_lit = ve::min(
2251 + (0.01f * state.defines.literacy_change_speed)
2263 pop_demographics::set_literacy(state, ids, ve::select(owner != dcon::nation_id{}, new_lit, old_lit));
2270 auto loc = state.world.pop_get_province_from_pop_location(ids);
2271 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2273 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc,
demographics::total);
2275 auto tmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency) + 1.0f;
2276 auto nmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency_modifier) + 1.0f;
2278 (float(state.world.nation_get_education_spending(owner)) / 100.0f) * state.world.nation_get_spending_level(owner);
2279 auto cmod = std::max(0.0f, std::min(1.0f, (cfrac - state.defines.base_clergy_for_literacy) /
2280 (state.defines.max_clergy_for_literacy - state.defines.base_clergy_for_literacy)));
2283 auto new_lit = std::min(std::max(old_lit + (0.01f * state.defines.literacy_change_speed) * ((espending * cmod) * (tmod * nmod)), 0.01f), 1.0f);
2285 return new_lit - old_lit;
2290 for(
auto prov :
dcon::fatten(state.world, n).get_province_ownership()) {
2291 for(
auto pop : prov.get_province().get_pop_location()) {
2296 return t != 0.f ? sum / t : 0.f;
2305 auto new_pop_count = state.world.pop_size();
2306 ibuf.
update(state, new_pop_count);
2308 assert(state.world.ideology_size() <= 64);
2313 ve::fp_vector iopt_weights[64];
2314 ve::fp_vector ttotal = 0.0f;
2316 state.world.for_each_ideology([&](dcon::ideology_id i) {
2317 if(!state.world.ideology_get_enabled(i)) {
2318 iopt_weights[i.index()] = 0.0f;
2320 auto const i_key = pop_demographics::to_key(state, i);
2321 auto owner = nations::owner_of_pop(state, ids);
2323 if(state.world.ideology_get_is_civilized_only(i)) {
2324 auto amount = ve::max(ve::fp_vector{}, ve::apply(
2325 [&](dcon::pop_id pid, dcon::pop_type_id ptid, dcon::nation_id o) {
2326 if(state.world.nation_get_is_civilized(o)) {
2327 if(auto mfn = state.world.pop_type_get_ideology_fns(ptid, i); mfn != 0) {
2328 using ftype = float(*)(int32_t);
2329 ftype fn = (ftype)mfn;
2330 float llvm_result = fn(pid.index());
2331#ifdef CHECK_LLVM_RESULTS
2332 float interp_result = 0.0f;
2333 if(auto mtrigger = state.world.pop_type_get_ideology(ptid, i); mtrigger) {
2334 interp_result = trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2336 assert(llvm_result == interp_result);
2340 auto ptrigger = state.world.pop_type_get_ideology(ptid, i);
2341 return ptrigger ? trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0) : 0.0f;
2346 }, ids, state.world.pop_get_poptype(ids), owner));
2348 iopt_weights[i.index()] = amount;
2349 ttotal = ttotal + amount;
2351 auto amount = ve::max(ve::fp_vector{}, ve::apply(
2352 [&](dcon::pop_id pid, dcon::pop_type_id ptid, dcon::nation_id o) {
2353 if(auto mfn = state.world.pop_type_get_ideology_fns(ptid, i); mfn != 0) {
2354 using ftype = float(*)(int32_t);
2355 ftype fn = (ftype)mfn;
2356 float llvm_result = fn(pid.index());
2357#ifdef CHECK_LLVM_RESULTS
2358 float interp_result = 0.0f;
2359 if(auto mtrigger = state.world.pop_type_get_ideology(ptid, i); mtrigger) {
2360 interp_result = trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2362 assert(llvm_result == interp_result);
2366 auto ptrigger = state.world.pop_type_get_ideology(ptid, i);
2367 return ptrigger ? trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0) : 0.0f;
2369 }, ids, state.world.pop_get_poptype(ids), owner));
2371 iopt_weights[i.index()] = amount;
2372 ttotal = ttotal + amount;
2378 ve::fp_vector max_weight{ 0.0f };
2379 ve::tagged_vector<dcon::ideology_id> preferred{};
2381 state.world.for_each_ideology([&](dcon::ideology_id iid) {
2382 auto avalue = iopt_weights[iid.index()] / ttotal;
2387 auto new_weight =
ve::select(ttotal > 0.0f,
state.defines.alice_ideology_base_change_rate * avalue + (1.0f -
state.defines.alice_ideology_base_change_rate) * current, current);
2388 auto new_max = new_weight > max_weight;
2389 preferred =
ve::select(new_max, ve::tagged_vector<dcon::ideology_id>{iid}, preferred);
2390 max_weight =
ve::select(new_max, new_weight, max_weight);
2395 state.world.pop_set_dominant_ideology(ids, preferred);
2397 state.world.for_each_ideology([&](dcon::ideology_id iid) {
2398 auto avalue = iopt_weights[iid.index()] / ttotal;
2407 state.defines.alice_ideology_base_change_rate * avalue + (1.0f -
state.defines.alice_ideology_base_change_rate) * current, current)));
2426 state.world.for_each_ideology([&](dcon::ideology_id i) {
2427 if(state.world.ideology_get_enabled(i)) {
2428 auto const i_key = pop_demographics::to_key(state, i);
2430 execute_staggered_blocks(offset, divisions, std::min(state.world.pop_size(), pbuf.size), [&](auto ids) {
2431 auto avalue = pbuf.temp_buffers[i].get(ids);
2432 state.world.pop_set_udemographics(ids, i_key, avalue);
2447 auto new_pop_count = state.world.pop_size();
2448 ibuf.
update(state, new_pop_count);
2451 assert(state.world.issue_option_size() <= 720);
2454 ve::fp_vector iopt_weights[720];
2455 ve::fp_vector ttotal = 0.0f;
2458 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
2459 auto opt = fatten(state.world, iid);
2460 auto allow = opt.get_allow();
2461 auto parent_issue = opt.get_parent_issue();
2466 auto has_modifier = is_social_issue || is_political_issue;
2468 is_social_issue ? sys::national_mod_offsets::social_reform_desire : sys::national_mod_offsets::political_reform_desire;
2470 auto current_issue_setting = state.world.nation_get_issues(owner, parent_issue);
2471 auto allowed_by_owner =
2472 (state.world.nation_get_is_civilized(owner) || ve::mask_vector(is_party_issue))
2473 && (ve::mask_vector(!state.world.issue_get_is_next_step_only(parent_issue)) ||
2474 (ve::tagged_vector<int32_t>(current_issue_setting) == iid.index()) ||
2475 (ve::tagged_vector<int32_t>(current_issue_setting) == iid.index() - 1) ||
2476 (ve::tagged_vector<int32_t>(current_issue_setting) == iid.index() + 1));
2477 auto owner_modifier =
2478 has_modifier ? (state.world.nation_get_modifier_values(owner, modifier_key) + 1.0f) : ve::fp_vector(1.0f);
2480 auto amount = ve::max(ve::fp_vector{}, owner_modifier *
ve::select(allowed_by_owner,
2481 ve::apply([&](dcon::pop_id pid, dcon::pop_type_id ptid, dcon::nation_id o) {
2482 if(
auto mfn = state.world.pop_type_get_issues_fns(ptid, iid); mfn != 0) {
2483 using ftype = float(*)(int32_t);
2484 ftype fn = (ftype)mfn;
2485 float llvm_result = fn(pid.index());
2486#ifdef CHECK_LLVM_RESULTS
2487 float interp_result = 0.0f;
2488 if(auto mtrigger = state.world.pop_type_get_issues(ptid, iid); mtrigger) {
2489 interp_result = trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2491 assert(llvm_result == interp_result);
2495 if(
auto mtrigger = state.world.pop_type_get_issues(ptid, iid); mtrigger) {
2496 return trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2501 }, ids, state.world.pop_get_poptype(ids), owner),
2504 iopt_weights[iid.index()] = amount;
2505 ttotal = ttotal + amount;
2509 ve::fp_vector max_weight{ 0.0f };
2510 ve::tagged_vector<dcon::issue_option_id> preferred{};
2512 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
2513 auto avalue = iopt_weights[iid.index()] / ttotal;
2517 auto owner_rate_modifier = ve::min(ve::max(state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::issue_change_speed) + 1.0f, 0.0f), 5.0f);
2520 auto new_max = new_weight > max_weight;
2521 preferred =
ve::select(new_max, ve::tagged_vector<dcon::issue_option_id>{iid}, preferred);
2522 max_weight =
ve::select(new_max, new_weight, max_weight);
2527 state.world.pop_set_dominant_issue_option(ids, preferred);
2529 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
2530 auto avalue = iopt_weights[iid.index()] / ttotal;
2534 auto owner_rate_modifier = ve::min(ve::max(state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::issue_change_speed) + 1.0f, 0.0f), 5.0f);
2556 state.world.for_each_issue_option([&](dcon::issue_option_id i) {
2560 auto avalue = pbuf.temp_buffers[i].get(ids);
2561 state.world.pop_set_udemographics(ids, i_key, avalue);
2583 auto loc = state.world.pop_get_province_from_pop_location(ids);
2584 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2586 auto base_life_rating = ve::to_float(state.world.province_get_life_rating(loc));
2587 auto mod_life_rating = ve::min(
2588 base_life_rating * (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::life_rating) + 1.0f),
2591 ve::max((mod_life_rating - state.defines.min_life_rating_for_growth) * state.defines.life_rating_growth_bonus, 0.0f);
2592 auto province_factor = lr_factor + state.defines.base_popgrowth;
2594 auto ln_factor = pop_demographics::get_life_needs(state, ids) - state.defines.life_need_starvation_limit;
2595 auto mod_sum = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::population_growth) + state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::pop_growth);
2597 auto total_factor = ln_factor * province_factor * 4.0f + mod_sum * 0.1f;
2598 auto old_size = state.world.pop_get_size(ids);
2599 auto new_size = old_size * total_factor + old_size;
2601 auto type = state.world.pop_get_poptype(ids);
2603 state.world.pop_set_size(ids,
2604 ve::select((owner != dcon::nation_id{}) && (type != state.culture_definitions.slaves), new_size, old_size));
2609 auto type = state.world.pop_get_poptype(ids);
2610 if(type == state.culture_definitions.slaves)
2613 auto loc = state.world.pop_get_province_from_pop_location(ids);
2614 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2616 auto base_life_rating = float(state.world.province_get_life_rating(loc));
2617 auto mod_life_rating = std::min(
2618 base_life_rating * (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::life_rating) + 1.0f), 40.0f);
2620 std::max((mod_life_rating - state.defines.min_life_rating_for_growth) * state.defines.life_rating_growth_bonus, 0.0f);
2621 auto province_factor = lr_factor + state.defines.base_popgrowth;
2624 auto mod_sum = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::population_growth) + state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::pop_growth);
2626 auto total_factor = ln_factor * province_factor * 4.0f + mod_sum * 0.1f;
2627 auto old_size = state.world.pop_get_size(ids);
2629 return old_size * total_factor;
2633 for(
auto prov : state.world.nation_get_province_ownership(n)) {
2634 for(
auto pop : prov.get_province().get_pop_location()) {
2644 for(
auto pop : state.world.province_get_pop_location(prov)) {
2645 t += get_monthly_pop_increase(state, pop.get_pop());
2653 for(
auto pop : state.world.province_get_pop_location(n)) {
2660 pbuf.
update(state.world.pop_size());
2668 pbuf.amounts.set(ids, 0.0f);
2669 auto owners = nations::owner_of_pop(state, ids);
2670#ifdef CHECK_LLVM_RESULTS
2671 auto promotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.promotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2672 auto demotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.demotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2674 ve::fp_vector promotion_chances;
2675 if(state.culture_definitions.promotion_chance_fn == 0)
2676 promotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.promotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2677 ve::fp_vector demotion_chances;
2678 if(state.culture_definitions.demotion_chance_fn == 0)
2679 demotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.demotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2682 [&](dcon::pop_id p, dcon::nation_id owner, float promotion_chance, float demotion_chance) {
2703 auto loc = state.world.pop_get_province_from_pop_location(p);
2704 auto si = state.world.province_get_state_membership(loc);
2705 auto nf = state.world.state_instance_get_owner_focus(si);
2706 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
2707 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
2708 auto ptype = state.world.pop_get_poptype(p);
2709 auto strata = state.world.pop_type_get_strata(ptype);
2712 using ftypeb = float(*)(int32_t);
2713 if(state.culture_definitions.promotion_chance_fn) {
2714 ftypeb fn = (ftypeb)(state.culture_definitions.promotion_chance_fn);
2715 float llvm_result = fn(p.index());
2716#ifdef CHECK_LLVM_RESULTS
2717 assert(llvm_result == promotion_chance);
2719 promotion_chance = llvm_result;
2721 if(state.culture_definitions.demotion_chance_fn) {
2722 ftypeb fn = (ftypeb)(state.culture_definitions.demotion_chance_fn);
2723 float llvm_result = fn(p.index());
2724#ifdef CHECK_LLVM_RESULTS
2725 assert(llvm_result == demotion_chance);
2727 demotion_chance = llvm_result;
2731 if(promoted_type == ptype) {
2732 promotion_chance = 0.0f;
2733 } else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
2734 promotion_chance += promotion_bonus;
2735 } else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
2736 demotion_chance += promotion_bonus;
2740 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
2743 float current_size = state.world.pop_get_size(p);
2745 bool promoting = promotion_chance >= demotion_chance;
2746 float base_amount = promoting
2747 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(owner) * state.defines.promotion_scale * current_size))
2748 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size));
2751 if(ptype == state.culture_definitions.artisans) {
2752 base_amount *= 10.f;
2758 if(base_amount >= 0.001f) {
2759 auto transfer_amount = std::min(current_size, base_amount);
2760 pbuf.amounts.set(p, transfer_amount);
2763 tagged_vector<float, dcon::pop_type_id> weights(state.world.pop_type_size());
2778 bool is_state_capital = state.world.state_instance_get_capital(state.world.province_get_state_membership(loc)) == loc;
2780 if((promoting && promoted_type && state.world.pop_type_get_strata(promoted_type) >= strata && (is_state_capital || state.world.pop_type_get_state_capital_only(promoted_type) == false))
2781 || (!promoting && promoted_type && state.world.pop_type_get_strata(promoted_type) <= strata && (is_state_capital || state.world.pop_type_get_state_capital_only(promoted_type) == false))) {
2783 float chance = 0.0f;
2784 if(auto mfn = state.world.pop_type_get_promotion_fns(ptype, promoted_type); mfn != 0) {
2785 using ftype = float(*)(int32_t);
2786 ftype fn = (ftype)mfn;
2787 float llvm_result = fn(p.index());
2788#ifdef CHECK_LLVM_RESULTS
2789 float interp_result = 0.0f;
2790 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, promoted_type); mtrigger) {
2791 interp_result = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0);
2793 assert(llvm_result == interp_result);
2795 chance = llvm_result + promotion_bonus;
2797 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, promoted_type); mtrigger) {
2798 chance = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0) + promotion_bonus;
2803 pbuf.types.set(p, promoted_type);
2808 float chances_total = 0.0f;
2809 state.world.for_each_pop_type([&](dcon::pop_type_id target_type) {
2810 if(target_type == ptype) {
2811 weights[target_type] = 0.0f;
2812 } else if(!is_state_capital && state.world.pop_type_get_state_capital_only(target_type)) {
2813 weights[target_type] = 0.0f;
2814 } else if((promoting && state.world.pop_type_get_strata(promoted_type) >= strata)
2815 || (!promoting && state.world.pop_type_get_strata(promoted_type) <= strata) ) {
2817 weights[target_type] = 0.0f;
2819 if(auto mfn = state.world.pop_type_get_promotion_fns(ptype, target_type); mfn != 0) {
2820 using ftype = float(*)(int32_t);
2821 ftype fn = (ftype)mfn;
2822 float llvm_result = fn(p.index());
2823#ifdef CHECK_LLVM_RESULTS
2824 float interp_result = 0.0f;
2825 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, target_type); mtrigger) {
2826 interp_result = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0);
2828 assert(llvm_result == interp_result);
2830 auto chance = llvm_result + (target_type == promoted_type ? promotion_bonus : 0.0f);
2831 chances_total += chance;
2832 weights[target_type] = chance;
2834 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, target_type); mtrigger) {
2835 auto chance = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0) + (target_type == promoted_type ? promotion_bonus : 0.0f);
2836 chances_total += chance;
2837 weights[target_type] = chance;
2842 weights[target_type] = 0.0f;
2846 if(chances_total > 0.0f) {
2847 auto rvalue = float(rng::get_random(state, uint32_t(p.index())) & 0xFFFF) / float(0xFFFF + 1);
2848 for(uint32_t i = state.world.pop_type_size(); i-- > 0;) {
2849 dcon::pop_type_id pr{dcon::pop_type_id::value_base_t(i)};
2850 rvalue -= weights[pr] / chances_total;
2852 pbuf.types.set(p, pr);
2856 pbuf.amounts.set(p, 0.0f);
2857 pbuf.types.set(p, dcon::pop_type_id{});
2859 pbuf.amounts.set(p, 0.0f);
2860 pbuf.types.set(p, dcon::pop_type_id{});
2863 ids, owners, promotion_chances, demotion_chances);
2868 float total_effective_change = .0f;
2870 for(
auto prov : state.world.nation_get_province_ownership(nation)) {
2871 for(
auto pop : prov.get_province().get_pop_location()) {
2877 auto owner = nation;
2879 auto p = pop.get_pop();
2881 auto loc = state.world.pop_get_province_from_pop_location(pop.get_pop());
2882 auto si = state.world.province_get_state_membership(loc);
2883 auto nf = state.world.state_instance_get_owner_focus(si);
2884 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
2885 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
2886 auto ptype = state.world.pop_get_poptype(pop.get_pop());
2887 auto strata = state.world.pop_type_get_strata(ptype);
2890 if(promoted_type == ptype) {
2891 promotion_chance = 0.0f;
2892 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
2893 promotion_chance += promotion_bonus;
2894 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
2895 demotion_chance += promotion_bonus;
2899 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
2902 float current_size = state.world.pop_get_size(p);
2904 bool promoting = promotion_chance >= demotion_chance;
2905 float base_amount = promoting
2906 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(nation) * state.defines.promotion_scale * current_size))
2907 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size));
2909 auto transfer_amount = base_amount >= 0.001f ? std::min(current_size, base_amount) : 0.0f;
2913 bool is_state_capital = state.world.state_instance_get_capital(state.world.province_get_state_membership(loc)) == loc;
2915 if(promoted_type == target_type) {
2916 if(promoting && promoted_type && state.world.pop_type_get_strata(promoted_type) >= strata &&
2917 (is_state_capital || state.world.pop_type_get_state_capital_only(promoted_type) ==
false)) {
2918 auto promote_mod = state.world.pop_type_get_promotion(ptype, promoted_type);
2924 total_effective_change += transfer_amount;
2928 }
else if(!promoting && promoted_type && state.world.pop_type_get_strata(promoted_type) <= strata &&
2929 (is_state_capital || state.world.pop_type_get_state_capital_only(promoted_type) ==
false)) {
2930 auto promote_mod = state.world.pop_type_get_promotion(ptype, promoted_type);
2936 total_effective_change += transfer_amount;
2943 float chances_total = 0.0f;
2945 state.world.for_each_pop_type([&](dcon::pop_type_id t_type) {
2946 if(t_type == ptype) {
2947 weights[t_type] = 0.0f;
2948 }
else if(!is_state_capital && state.world.pop_type_get_state_capital_only(t_type)) {
2949 weights[t_type] = 0.0f;
2950 }
else if(promoting && state.world.pop_type_get_strata(promoted_type) >= strata) {
2951 auto promote_mod = state.world.pop_type_get_promotion(ptype, t_type);
2953 auto chance = std::max(trigger::evaluate_additive_modifier(state, promote_mod, trigger::to_generic(p),
2954 trigger::to_generic(p), 0) +
2955 (t_type == promoted_type ? promotion_bonus : 0.0f),
2957 chances_total += chance;
2958 weights[t_type] = chance;
2960 weights[t_type] = 0.0f;
2962 }
else if(!promoting && state.world.pop_type_get_strata(promoted_type) <= strata) {
2963 auto promote_mod = state.world.pop_type_get_promotion(ptype, t_type);
2965 auto chance = std::max(trigger::evaluate_additive_modifier(state, promote_mod, trigger::to_generic(p),
2966 trigger::to_generic(p), 0) +
2967 (t_type == promoted_type ? promotion_bonus : 0.0f),
2969 chances_total += chance;
2970 weights[t_type] = chance;
2972 weights[t_type] = 0.0f;
2975 weights[t_type] = 0.0f;
2979 if(chances_total > 0.0f) {
2980 total_effective_change += transfer_amount * weights[target_type]/chances_total;
2986 for(
auto prov :
state.world.nation_get_province_ownership(nation)) {
2987 for(
auto pop :
prov.get_province().get_pop_location()) {
2988 if(
pop.get_pop().get_poptype() == target_type) {
2995 return total_effective_change;
3005 auto loc = state.world.pop_get_province_from_pop_location(ids);
3006 auto si = state.world.province_get_state_membership(loc);
3007 auto nf = state.world.state_instance_get_owner_focus(si);
3008 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
3009 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
3010 auto ptype = state.world.pop_get_poptype(ids);
3011 auto strata = state.world.pop_type_get_strata(ptype);
3014 if(promoted_type == ptype) {
3015 promotion_chance = 0.0f;
3016 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
3017 promotion_chance += promotion_bonus;
3018 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
3019 demotion_chance += promotion_bonus;
3023 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
3026 float current_size = state.world.pop_get_size(ids);
3028 bool promoting = promotion_chance >= demotion_chance;
3029 return std::min(current_size, promoting
3030 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(owner) *
3031 state.defines.promotion_scale * current_size))
3032 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size)));
3042 auto loc = state.world.pop_get_province_from_pop_location(ids);
3043 auto si = state.world.province_get_state_membership(loc);
3044 auto nf = state.world.state_instance_get_owner_focus(si);
3045 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
3046 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
3047 auto ptype = state.world.pop_get_poptype(ids);
3048 auto strata = state.world.pop_type_get_strata(ptype);
3051 if(promoted_type == ptype) {
3052 promotion_chance = 0.0f;
3053 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
3054 promotion_chance += promotion_bonus;
3055 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
3056 demotion_chance += promotion_bonus;
3060 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
3063 float current_size = state.world.pop_get_size(ids);
3065 bool promoting = promotion_chance >= demotion_chance;
3066 return std::min(current_size, promoting
3067 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(owner) *
3068 state.defines.promotion_scale * current_size))
3078 auto loc = state.world.pop_get_province_from_pop_location(ids);
3079 auto si = state.world.province_get_state_membership(loc);
3080 auto nf = state.world.state_instance_get_owner_focus(si);
3081 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
3082 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
3083 auto ptype = state.world.pop_get_poptype(ids);
3084 auto strata = state.world.pop_type_get_strata(ptype);
3087 if(promoted_type == ptype) {
3088 promotion_chance = 0.0f;
3089 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
3090 promotion_chance += promotion_bonus;
3091 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
3092 demotion_chance += promotion_bonus;
3096 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
3099 float current_size = state.world.pop_get_size(ids);
3101 bool promoting = promotion_chance >= demotion_chance;
3102 return std::min(current_size, promoting
3104 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size)));
3108 pbuf.
update(state.world.pop_size());
3117 pbuf.amounts.set(ids, 0.0f);
3118 auto loc = state.world.pop_get_province_from_pop_location(ids);
3119 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3120 auto assimilation_chances = ve::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.assimilation_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
3123 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float assimilation_chance) {
3129 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
3133 if(state.world.pop_get_is_primary_or_accepted_culture(p))
3137 if(state.world.province_get_is_colonial(location) && province::is_overseas(state, location))
3140 if(state.world.province_get_dominant_culture(location) == state.world.pop_get_culture(p))
3149 float current_size = state.world.pop_get_size(p);
3151 state.defines.assimilation_scale *
3152 std::max(0.0f, (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f)) *
3153 std::max(0.0f, (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f)) *
3154 assimilation_chance * current_size;
3162 auto pc = state.world.pop_get_culture(p);
3164 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
3165 base_amount /= 10.0f;
3173 for(auto core : state.world.province_get_core(location)) {
3174 if(core.get_identity().get_primary_culture() == pc) {
3175 base_amount /= 100.0f;
3185 if(base_amount >= 0.001f) {
3186 auto transfer_amount = std::min(current_size, std::ceil(base_amount));
3187 pbuf.amounts.set(p, transfer_amount);
3190 ids, loc, owners, assimilation_chances);
3195 auto location = state.world.pop_get_province_from_pop_location(ids);
3196 auto owner = state.world.province_get_nation_from_province_ownership(location);
3200 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
3204 if(state.world.pop_get_is_primary_or_accepted_culture(ids))
3211 float current_size = state.world.pop_get_size(ids);
3213 state.defines.assimilation_scale *
3214 std::max(0.0f, (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f)) *
3215 std::max(0.0f, (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f)) *
3216 assimilation_chances * current_size;
3224 auto pc = state.world.pop_get_culture(ids);
3225 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
3226 base_amount /= 10.0f;
3235 for(
auto core : state.world.province_get_core(location)) {
3236 if(core.get_identity().get_primary_culture() == pc) {
3237 base_amount /= 100.0f;
3247 if(base_amount >= 0.001f) {
3248 return std::min(current_size, std::ceil(base_amount));
3264 auto weights_buffer = state.world.province_make_vectorizable_float_buffer();
3265 float total_weight = 0.0f;
3267 auto pt = state.world.pop_get_poptype(p);
3268 auto modifier = state.world.pop_type_get_migration_target(pt);
3269 auto modifier_fn = state.world.pop_type_get_migration_target_fn(pt);
3271 return dcon::province_id{};
3273 bool limit_to_capitals = state.world.pop_type_get_state_capital_only(pt);
3274 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3275 if(loc.get_province().get_is_colonial() ==
false) {
3276 if(!limit_to_capitals || loc.get_province().get_state_membership().get_capital().id == loc.get_province().id) {
3277 float weight = 0.0f;
3279 using ftype = float(*)(int32_t, int32_t);
3280 ftype fn = (ftype)modifier_fn;
3281 float llvm_result = fn(loc.get_province().id.index(), p.index());
3282#ifdef CHECK_LLVM_RESULTS
3284 assert(llvm_result == interp_result);
3286 weight = std::max(0.0f, llvm_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3289 weight = std::max(0.0f, interp_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3293 weights_buffer.set(loc.get_province(), weight);
3294 total_weight += weight;
3300 if(total_weight <= 0.0f)
3301 return dcon::province_id{};
3304 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3305 rvalue -= weights_buffer.get(loc.get_province()) / total_weight;
3307 return loc.get_province();
3311 return dcon::province_id{};
3319 auto weights_buffer = state.world.province_make_vectorizable_float_buffer();
3320 float total_weight = 0.0f;
3322 auto modifier = state.world.pop_type_get_migration_target(state.world.pop_get_poptype(p));
3323 auto modifier_fn = state.world.pop_type_get_migration_target_fn(state.world.pop_get_poptype(p));
3325 return dcon::province_id{};
3327 auto overseas_culture = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
3328 auto home_continent = state.world.province_get_continent(state.world.pop_get_province_from_pop_location(p));
3330 bool limit_to_capitals = state.world.pop_type_get_state_capital_only(state.world.pop_get_poptype(p));
3331 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3332 if(loc.get_province().get_is_colonial() ==
true) {
3333 if((overseas_culture || loc.get_province().get_continent() == home_continent) &&
3334 (!limit_to_capitals || loc.get_province().get_state_membership().get_capital().id == loc.get_province().id)) {
3336 float weight = 0.0f;
3338 using ftype = float(*)(int32_t, int32_t);
3339 ftype fn = (ftype)modifier_fn;
3340 float llvm_result = fn(loc.get_province().id.index(), p.index());
3341#ifdef CHECK_LLVM_RESULTS
3343 assert(llvm_result == interp_result);
3345 weight = std::max(0.0f, llvm_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3348 weight = std::max(0.0f, interp_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3352 if(!limit_to_capitals || loc.get_province().get_state_membership().get_capital().id == loc.get_province().id) {
3353 weights_buffer.set(loc.get_province(), weight);
3354 total_weight += weight;
3361 if(total_weight <= 0.0f)
3362 return dcon::province_id{};
3365 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3366 rvalue -= weights_buffer.get(loc.get_province()) / total_weight;
3368 return loc.get_province();
3372 return dcon::province_id{};
3387 auto pt = state.world.pop_get_poptype(p);
3388 auto modifier = state.world.pop_type_get_country_migration_target(pt);
3389 auto modifier_fn = state.world.pop_type_get_country_migration_target_fn(pt);
3391 return dcon::nation_id{};
3393 dcon::nation_id top_nations[3] = {dcon::nation_id{}, dcon::nation_id{}, dcon::nation_id{}};
3394 float top_weights[3] = {0.0f, 0.0f, 0.0f};
3396 auto home_continent = state.world.province_get_continent(state.world.pop_get_province_from_pop_location(p));
3398 state.world.for_each_nation([&](dcon::nation_id inner) {
3399 if(state.world.nation_get_owned_province_count(inner) == 0)
3401 if(state.world.nation_get_is_civilized(inner) ==
false)
3405 if(state.world.province_get_continent(state.world.nation_get_capital(inner)) == home_continent &&
3406 !state.world.get_nation_adjacency_by_nation_adjacency_pair(owner, inner)) {
3410 float weight = 0.0f;
3412 using ftype = float(*)(int32_t, int32_t);
3413 ftype fn = (ftype)modifier_fn;
3414 float llvm_result = fn(inner.index(), p.index());
3415#ifdef CHECK_LLVM_RESULTS
3416 float interp_result = trigger::evaluate_multiplicative_modifier(state, modifier, trigger::to_generic(inner), trigger::to_generic(p), 0);
3417 assert( llvm_result == interp_result);
3419 weight = std::max(0.0f, llvm_result * std::max(0.f, (state.world.nation_get_modifier_values(inner, sys::national_mod_offsets::global_immigrant_attract) + 1.0f)));
3421 float interp_result = trigger::evaluate_multiplicative_modifier(state, modifier, trigger::to_generic(inner), trigger::to_generic(p), 0);
3422 weight = std::max(0.0f, interp_result * std::max(0.f, (state.world.nation_get_modifier_values(inner, sys::national_mod_offsets::global_immigrant_attract) + 1.0f)));
3425 if(weight > top_weights[2]) {
3426 top_weights[2] = weight;
3427 top_nations[2] = inner;
3428 if(top_weights[2] > top_weights[1]) {
3429 std::swap(top_weights[1], top_weights[2]);
3430 std::swap(top_nations[1], top_nations[2]);
3432 if(top_weights[1] > top_weights[0]) {
3433 std::swap(top_weights[1], top_weights[0]);
3434 std::swap(top_nations[1], top_nations[0]);
3439 float total_weight = top_weights[0] + top_weights[1] + top_weights[2];
3440 if(total_weight <= 0.0f)
3441 return dcon::nation_id{};
3445 rvalue -= top_weights[i] / total_weight;
3447 return top_nations[i];
3451 return dcon::nation_id{};
3457 pbuf.
update(state.world.pop_size());
3460 pbuf.amounts.set(ids, 0.0f);
3467 auto loc = state.world.pop_get_province_from_pop_location(ids);
3468 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3469 auto pop_sizes = state.world.pop_get_size(ids);
3470 auto amounts = ve::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.migration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f) * pop_sizes * ve::max((state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f), 0.0f) * state.defines.immigration_scale;
3473 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float amount, float pop_size) {
3478 if(state.world.province_get_is_colonial(location))
3480 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
3483 auto dest = impl::get_province_target_in_nation(state, owner, p);
3488 pbuf.amounts.set(p, std::min(pop_size, std::ceil(amount)));
3490 pbuf.destinations.set(p, dest);
3492 ids, loc, owners, amounts, pop_sizes);
3498 auto loc = state.world.pop_get_province_from_pop_location(ids);
3500 if(state.world.province_get_is_colonial(loc))
3502 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
3505 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3506 auto pop_sizes = state.world.pop_get_size(ids);
3508 trigger::to_generic(ids),
trigger::to_generic(ids), 0), 0.0f) * pop_sizes * std::max(0.0f, (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f)) * state.defines.immigration_scale;
3514 auto pop_size = state.world.pop_get_size(ids);
3515 return std::min(pop_size, std::ceil(amount));
3519 pbuf.
update(state.world.pop_size());
3522 pbuf.amounts.set(ids, 0.0f);
3531 auto loc = state.world.pop_get_province_from_pop_location(ids);
3532 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3533 auto pop_sizes = state.world.pop_get_size(ids);
3534 auto amounts = ve::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.colonialmigration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f) *
3536 ve::max((state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f), 0.0f) *
3537 ve::max((state.world.nation_get_modifier_values(owners, sys::national_mod_offsets::colonial_migration) + 1.0f), 0.0f) *
3538 state.defines.immigration_scale;
3541 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float amount, float pop_size) {
3546 if(state.world.nation_get_is_colonial_nation(owner) == false)
3548 auto pt = state.world.pop_get_poptype(p);
3549 if(state.world.pop_type_get_strata(pt) == uint8_t(culture::pop_strata::rich))
3551 if(state.world.province_get_is_colonial(location))
3553 if(pt == state.culture_definitions.slaves || pt == state.culture_definitions.primary_factory_worker ||
3554 pt == state.culture_definitions.secondary_factory_worker)
3560 pbuf.amounts.set(p, std::min(pop_size, std::ceil(amount)));
3563 auto dest = impl::get_colonial_province_target_in_nation(state, owner, p);
3564 pbuf.destinations.set(p, dest);
3566 ids, loc, owners, amounts, pop_sizes);
3571 auto loc = state.world.pop_get_province_from_pop_location(ids);
3572 auto owner = state.world.province_get_nation_from_province_ownership(loc);
3574 if(state.world.nation_get_is_colonial_nation(owner) ==
false)
3576 auto pt = state.world.pop_get_poptype(ids);
3579 if(state.world.province_get_is_colonial(loc))
3581 if(pt == state.culture_definitions.slaves || pt == state.culture_definitions.primary_factory_worker ||
3582 pt == state.culture_definitions.secondary_factory_worker)
3586 auto pop_sizes = state.world.pop_get_size(ids);
3590 * std::max((state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f), 0.0f)
3591 * std::max((state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::colonial_migration) + 1.0f), 0.0f)
3592 * state.defines.immigration_scale;
3597 auto pop_size = state.world.pop_get_size(ids);
3598 return std::min(pop_size, std::ceil(amounts));
3602 pbuf.
update(state.world.pop_size());
3605 pbuf.amounts.set(ids, 0.0f);
3614 auto loc = state.world.pop_get_province_from_pop_location(ids);
3615 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3616 auto pop_sizes = state.world.pop_get_size(ids);
3617 auto impush = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
3618 auto trigger_amount = ve::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.emigration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
3619 auto amounts = trigger_amount
3621 * ve::max(impush, 0.0f)
3622 * ve::max(impush, 1.0f)
3623 * state.defines.immigration_scale;
3626 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float amount, float pop_size) {
3632 if(state.world.nation_get_is_civilized(owner) == false)
3634 if(state.world.province_get_is_colonial(location))
3636 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
3638 if(state.world.culture_group_get_is_overseas(
3639 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p))) == false) {
3646 pbuf.amounts.set(p, std::min(pop_size, std::ceil(amount)));
3649 auto ndest = impl::get_immigration_target(state, owner, p, state.current_date);
3650 auto dest = impl::get_province_target_in_nation(state, ndest, p);
3652 pbuf.destinations.set(p, dest);
3654 ids, loc, owners, amounts, pop_sizes);
3659 auto sz = state.world.nation_size();
3660 national_amounts.resize(sz);
3661 for(
auto& v : national_amounts) {
3665 auto ymd_date = state.current_date.to_ymd(state.start_date);
3670 for(
auto ids : state.world.in_pop) {
3671 auto loc = state.world.pop_get_province_from_pop_location(ids);
3672 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3674 auto section =
uint64_t(ids.id.index()) / 16;
3675 auto tranche = int32_t(section / days_in_month);
3676 auto day_of_month = tranche - 10;
3677 if(day_of_month <= 0)
3678 day_of_month += days_in_month;
3679 int32_t day_adjustment = day_of_month - int32_t(ymd_date.day);
3681 if(est_amount > 0.0f) {
3682 auto target = impl::get_immigration_target(state, owners, ids, state.current_date + day_adjustment);
3684 if(target &&
uint32_t(target.index()) < sz) {
3685 national_amounts[
uint32_t(target.index())] -= est_amount;
3687 }
else if(target == n) {
3688 if(
uint32_t(owners.index()) < sz) {
3689 national_amounts[
uint32_t(owners.index())] += est_amount;
3698 auto loc = state.world.pop_get_province_from_pop_location(ids);
3699 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3701 if(state.world.nation_get_is_civilized(owners) ==
false)
3703 if(state.world.province_get_is_colonial(loc))
3705 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
3707 if(state.world.culture_group_get_is_overseas(
3708 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(ids))) ==
false) {
3712 auto pop_sizes = state.world.pop_get_size(ids);
3713 auto impush = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
3715 auto amounts = trigger_result * pop_sizes * std::max(impush, 0.0f) * std::max(impush, 1.0f) * state.defines.immigration_scale;
3720 return std::min(pop_sizes, std::ceil(amounts));
3725 dcon::pop_type_id ptid,
float l) {
3726 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(loc));
3727 if(is_mine && ptid == state.culture_definitions.farmers) {
3728 ptid = state.culture_definitions.laborers;
3729 }
else if(!is_mine && ptid == state.culture_definitions.laborers) {
3730 ptid = state.culture_definitions.farmers;
3733 for(
auto pl : state.world.province_get_pop_location(loc)) {
3734 if(pl.get_pop().get_culture() == cid && pl.get_pop().get_religion() == rid && pl.get_pop().get_poptype() == ptid) {
3735 return pl.get_pop();
3738 auto np = fatten(state.world, state.world.create_pop());
3739 state.world.force_create_pop_location(np, loc);
3740 np.set_culture(cid);
3741 np.set_religion(rid);
3742 np.set_poptype(ptid);
3745 auto n = state.world.province_get_nation_from_province_ownership(loc);
3746 if(state.world.nation_get_primary_culture(n) == cid) {
3747 np.set_is_primary_or_accepted_culture(
true);
3749 if(state.world.nation_get_accepted_cultures(n, cid) ==
true) {
3750 np.set_is_primary_or_accepted_culture(
true);
3756 float totals = 0.0f;
3757 static auto buf = state.world.ideology_make_vectorizable_float_buffer();
3759 state.world.for_each_ideology([&](dcon::ideology_id i) {
3761 if(state.world.ideology_get_enabled(i)) {
3762 auto ptrigger = state.world.pop_type_get_ideology(ptid, i);
3763 auto const i_key = pop_demographics::to_key(state, i);
3764 auto owner = nations::owner_of_pop(state, np);
3765 if(state.world.ideology_get_is_civilized_only(i)) {
3766 if(state.world.nation_get_is_civilized(owner)) {
3767 auto amount = ptrigger ? std::max(0.0f, trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(np.id),
3768 trigger::to_generic(owner), 0)) : 0.0f;
3773 auto amount = ptrigger ? std::max(0.0f, trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(np.id),
3774 trigger::to_generic(owner), 0)) : 0.0f;
3781 state.world.for_each_ideology([&](dcon::ideology_id i) {
3788 float totals = 0.0f;
3789 static auto buf = state.world.issue_option_make_vectorizable_float_buffer();
3791 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
3792 auto opt = fatten(state.world, iid);
3793 auto allow = opt.get_allow();
3794 auto parent_issue = opt.get_parent_issue();
3799 auto has_modifier = is_social_issue || is_political_issue;
3801 is_social_issue ? sys::national_mod_offsets::social_reform_desire : sys::national_mod_offsets::political_reform_desire;
3804 auto current_issue_setting = state.world.nation_get_issues(owner, parent_issue);
3805 auto allowed_by_owner =
3806 (state.world.nation_get_is_civilized(owner) || is_party_issue) &&
3807 (!state.world.issue_get_is_next_step_only(parent_issue) || (current_issue_setting.id.index() == iid.index()) || (current_issue_setting.id.index() == iid.index() - 1) || (current_issue_setting.id.index() == iid.index() + 1));
3808 auto owner_modifier = has_modifier ? (state.world.nation_get_modifier_values(owner, modifier_key) + 1.0f) : 1.0f;
3810 if(allowed_by_owner) {
3811 if(
auto mtrigger = state.world.pop_type_get_issues(ptid, iid); mtrigger) {
3813 buf.set(iid, amount);
3819 state.world.for_each_issue_option([&](dcon::issue_option_id i) {
3832 [&](dcon::pop_id p) {
3833 if(pbuf.amounts.get(p) > 0.0f && pbuf.types.get(p)) {
3834 auto target_pop = impl::find_or_make_pop(state, state.world.pop_get_province_from_pop_location(p),
3835 state.world.pop_get_culture(p), state.world.pop_get_religion(p), pbuf.types.get(p), pop_demographics::get_literacy(state, p));
3836 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3837 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3845 auto exec_fn = [&](
auto ids) {
3846 auto locs = state.world.pop_get_province_from_pop_location(ids);
3847 ve::apply([&](dcon::pop_id p, dcon::province_id l, dcon::culture_id dac) {
3848 if(pbuf.
amounts.get(p) > 0.0f) {
3850 auto cul = dac ? dac : state.world.province_get_dominant_culture(l);
3852 ? state.world.nation_get_religion(nations::owner_of_pop(state, p))
3853 : state.world.province_get_dominant_religion(l);
3854 assert(state.world.pop_get_poptype(p));
3855 auto target_pop = impl::find_or_make_pop(state, l, cul, rel, state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3856 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3857 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3860 ids, locs, state.world.province_get_dominant_accepted_culture(locs));
3868 [&](dcon::pop_id p) {
3869 if(pbuf.amounts.get(p) > 0.0f && pbuf.destinations.get(p)) {
3870 assert(state.world.pop_get_poptype(p));
3871 auto target_pop = impl::find_or_make_pop(state, pbuf.destinations.get(p), state.world.pop_get_culture(p),
3872 state.world.pop_get_religion(p), state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3873 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3874 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3875 state.world.province_get_daily_net_migration(state.world.pop_get_province_from_pop_location(p)) -=
3876 pbuf.amounts.get(p);
3877 state.world.province_get_daily_net_migration(pbuf.destinations.get(p)) += pbuf.amounts.get(p);
3887 [&](dcon::pop_id p) {
3888 if(pbuf.amounts.get(p) > 0.0f && pbuf.destinations.get(p)) {
3889 assert(state.world.pop_get_poptype(p));
3890 auto target_pop = impl::find_or_make_pop(state, pbuf.destinations.get(p), state.world.pop_get_culture(p),
3891 state.world.pop_get_religion(p), state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3892 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3893 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3894 state.world.province_get_daily_net_migration(state.world.pop_get_province_from_pop_location(p)) -=
3895 pbuf.amounts.get(p);
3896 state.world.province_get_daily_net_migration(pbuf.destinations.get(p)) += pbuf.amounts.get(p);
3906 [&](dcon::pop_id p) {
3907 auto amount = pbuf.amounts.get(p);
3908 if(amount > 0.0f && pbuf.destinations.get(p)) {
3909 assert(state.world.pop_get_poptype(p));
3910 auto target_pop = impl::find_or_make_pop(state, pbuf.destinations.get(p), state.world.pop_get_culture(p),
3911 state.world.pop_get_religion(p), state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3913 state.world.pop_get_size(p) -= amount;
3914 state.world.pop_get_size(target_pop) += amount;
3915 state.world.province_get_daily_net_immigration(state.world.pop_get_province_from_pop_location(p)) -= amount;
3916 state.world.province_get_daily_net_immigration(pbuf.destinations.get(p)) += amount;
3917 state.world.province_set_last_immigration(pbuf.destinations.get(p), state.current_date);
3926 for(
auto last = state.world.pop_size(); last-- > 0;) {
3927 dcon::pop_id m{dcon::pop_id::value_base_t(last)};
3928 if(state.world.pop_get_size(m) < 1.0f) {
3929 state.world.delete_pop(m);
3936 for(
auto last = state.world.pop_size(); last-- > 0;) {
3937 dcon::pop_id m{ dcon::pop_id::value_base_t(last) };
3938 if(state.world.pop_get_size(m) < 20.0f) {
3939 state.world.delete_pop(m);
3962 auto poor_score = (pln + pen + plun) / pp;
3963 auto middle_score = (mln + men + mlun) / mp;
3964 auto rich_score = (rln + ren + rlun) / rp;
3966 auto finalscore = (poor_score * pp + middle_score * mp + rich_score * rp) * 33 / p;
3972 if(state.world.pop_get_size(pop_id) >= amount) {
3973 state.world.pop_get_size(pop_id) -= amount;
3975 state.world.pop_get_size(pop_id) = 0;
3980 for(
auto pr : state.world.nation_get_province_ownership(n)) {
3981 for(
auto pop : pr.get_province().get_pop_location()) {
3983 auto adj_mil = base_mil + v;
#define assert(condition)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
dcon::province_id get_province_target_in_nation(sys::state &state, dcon::nation_id n, dcon::pop_id p)
dcon::nation_id get_immigration_target(sys::state &state, dcon::nation_id owner, dcon::pop_id p, sys::date day)
dcon::pop_id find_or_make_pop(sys::state &state, dcon::province_id loc, dcon::culture_id cid, dcon::religion_id rid, dcon::pop_type_id ptid, float l)
dcon::province_id get_colonial_province_target_in_nation(sys::state &state, dcon::nation_id n, dcon::pop_id p)
void alt_copy_demographics(sys::state &state, dcon::demographics_key key)
void modify_militancy(sys::state &state, dcon::nation_id n, float v)
float get_effective_estimation_type_change(sys::state &state, dcon::nation_id nation, dcon::pop_type_id target_type)
constexpr dcon::demographics_key rich_life_needs(13)
constexpr dcon::demographics_key poor_luxury_needs(17)
constexpr dcon::demographics_key middle_life_needs(12)
float get_estimated_colonial_migration(sys::state &state, dcon::pop_id ids)
void estimate_directed_immigration(sys::state &state, dcon::nation_id n, std::vector< float > &national_amounts)
void alt_st_regenerate_from_pop_data(sys::state &state)
void alt_demographics_update_extras(sys::state &state)
float get_estimated_literacy_change(sys::state &state, dcon::pop_id ids)
void sum_over_demographics(sys::state &state, dcon::demographics_key key, F const &source)
constexpr dcon::demographics_key middle_total(21)
constexpr dcon::demographics_key middle_luxury_needs(18)
float get_estimated_type_change(sys::state &state, dcon::pop_id ids)
float calculate_nation_sol(sys::state &state, dcon::nation_id nation_id)
void remove_small_pops(sys::state &state)
void regenerate_jingoism_support(sys::state &state, dcon::nation_id n)
void update_immigration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
constexpr dcon::demographics_key total(0)
void regenerate_from_pop_data(sys::state &state)
constexpr dcon::demographics_key rich_everyday_needs(16)
constexpr float issues_change_rate
constexpr dcon::demographics_key rich_luxury_needs(19)
void pexecute_staggered_blocks(uint32_t offset, uint32_t divisions, uint32_t max, F &&functor)
void apply_assimilation(sys::state &state, uint32_t offset, uint32_t divisions, assimilation_buffer &pbuf)
constexpr dcon::demographics_key poor_everyday_needs(14)
void update_internal_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void apply_type_changes(sys::state &state, uint32_t offset, uint32_t divisions, promotion_buffer &pbuf)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr float small_pop_size
float get_estimated_mil_change(sys::state &state, dcon::pop_id ids)
constexpr uint32_t count_special_keys
void update_growth(sys::state &state, uint32_t offset, uint32_t divisions)
void alt_sum_over_demographics(sys::state &state, dcon::demographics_key key, F const &source)
void alt_regenerate_from_pop_data_daily(sys::state &state)
void update_issues(sys::state &state, uint32_t offset, uint32_t divisions, issues_buffer &ibuf)
void apply_internal_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
constexpr dcon::demographics_key rich_total(22)
constexpr dcon::demographics_key poor_total(20)
void update_type_changes(sys::state &state, uint32_t offset, uint32_t divisions, promotion_buffer &pbuf)
void regenerate_from_pop_data_full(sys::state &state)
void reduce_pop_size_safe(sys::state &state, dcon::pop_id pop_id, int32_t amount)
float get_estimated_internal_migration(sys::state &state, dcon::pop_id ids)
float get_estimated_demotion(sys::state &state, dcon::pop_id ids)
constexpr dcon::demographics_key poor_life_needs(11)
void execute_staggered_blocks(uint32_t offset, uint32_t divisions, uint32_t max, F &&functor)
uint32_t size(sys::state const &state)
void sum_over_single_nation_demographics(sys::state &state, dcon::demographics_key key, dcon::nation_id n, F const &source)
float get_monthly_pop_increase(sys::state &state, dcon::pop_id ids)
float get_estimated_con_change(sys::state &state, dcon::pop_id ids)
dcon::demographics_key to_employment_key(sys::state const &state, dcon::pop_type_id v)
void update_assimilation(sys::state &state, uint32_t offset, uint32_t divisions, assimilation_buffer &pbuf)
void alt_regenerate_from_pop_data_full(sys::state &state)
void alt_mt_regenerate_from_pop_data(sys::state &state)
void remove_size_zero_pops(sys::state &state)
void update_colonial_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
constexpr uint32_t extra_demo_grouping
void apply_ideologies(sys::state &state, uint32_t offset, uint32_t divisions, ideology_buffer &pbuf)
void update_ideologies(sys::state &state, uint32_t offset, uint32_t divisions, ideology_buffer &ibuf)
constexpr uint32_t executions_per_block
void update_consciousness(sys::state &state, uint32_t offset, uint32_t divisions)
constexpr dcon::demographics_key middle_everyday_needs(15)
float get_estimated_assimilation(sys::state &state, dcon::pop_id ids)
void update_literacy(sys::state &state, uint32_t offset, uint32_t divisions)
void update_militancy(sys::state &state, uint32_t offset, uint32_t divisions)
uint32_t common_size(sys::state const &state)
void apply_colonial_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
float get_estimated_emigration(sys::state &state, dcon::pop_id ids)
void regenerate_from_pop_data_daily(sys::state &state)
void apply_immigration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
float get_estimated_promotion(sys::state &state, dcon::pop_id ids)
void apply_issues(sys::state &state, uint32_t offset, uint32_t divisions, issues_buffer &pbuf)
@ key
the parser read a key of a value in an object
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
auto nation_accepts_culture(sys::state const &state, T ids, U cul_ids)
void set_luxury_needs(sys::state &state, P p, V v)
void set_political_reform_desire(sys::state &state, dcon::pop_id p, float v)
void set_militancy(sys::state &state, dcon::pop_id p, float v)
float from_pmc(uint16_t v)
void set_everyday_needs(sys::state &state, P p, V v)
void set_social_reform_desire(sys::state &state, dcon::pop_id p, float v)
template void set_everyday_needs< dcon::pop_id, float >(sys::state &, dcon::pop_id, float)
uint32_t size(sys::state const &state)
float get_employment(sys::state const &state, dcon::pop_id p)
template void set_life_needs< dcon::pop_fat_id, float >(sys::state &, dcon::pop_fat_id, float)
void set_employment(sys::state &state, dcon::pop_id p, float v)
float get_social_reform_desire(sys::state const &state, dcon::pop_id p)
float get_luxury_needs(sys::state const &state, dcon::pop_id p)
void set_raw_employment(sys::state &state, dcon::pop_id p, float v)
void regenerate_is_primary_or_accepted(sys::state &state)
void set_demo(sys::state &state, dcon::pop_id p, dcon::pop_demographics_key k, float v)
template void set_luxury_needs< dcon::pop_fat_id, float >(sys::state &, dcon::pop_fat_id, float)
uint16_t to_pu16(float v)
float from_pu8(uint8_t 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)
template void set_luxury_needs< dcon::pop_id, float >(sys::state &, dcon::pop_id, float)
float get_life_needs(sys::state const &state, dcon::pop_id p)
float get_political_reform_desire(sys::state const &state, dcon::pop_id p)
void set_literacy(sys::state &state, T p, ve::fp_vector v)
void set_life_needs(sys::state &state, P p, V v)
template void set_everyday_needs< dcon::pop_fat_id, float >(sys::state &, dcon::pop_fat_id, float)
float get_everyday_needs(sys::state const &state, dcon::pop_id p)
float from_pu16(uint16_t v)
constexpr uint32_t count_special_keys
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
template void set_life_needs< dcon::pop_id, float >(sys::state &, dcon::pop_id, float)
bool is_overseas(sys::state const &state, dcon::province_id ids)
void ve_for_each_land_province(sys::state &state, F const &func)
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
void for_each_land_province(sys::state &state, F const &func)
uint64_t get_random(sys::state const &state, uint32_t value_in)
int32_t days_difference(year_month_day start, year_month_day end)
int32_t to_generic(dcon::province_id v)
float evaluate_additive_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
float evaluate_multiplicative_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
T select(bool v, T a, T b)
ve::vectorizable_buffer< float, dcon::pop_id > amounts
void update(sys::state &state, uint32_t s)
void update(sys::state &state, uint32_t s)
tagged_vector< ve::vectorizable_buffer< uint8_t, dcon::pop_id >, dcon::issue_option_id > temp_buffers
Holds important data about the game world, state, and other data regarding windowing,...