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);
105 state.world.pop_set_ulife_needs_satisfaction(p,
to_pu8(v));
108 auto ival = state.world.pop_get_ueveryday_needs_satisfaction(p);
112 state.world.pop_set_ueveryday_needs_satisfaction(p,
to_pu8(v));
115 auto ival = state.world.pop_get_uluxury_needs_satisfaction(p);
119 state.world.pop_set_uluxury_needs_satisfaction(p,
to_pu8(v));
122 auto ival = state.world.pop_get_usocial_reform_desire(p);
126 state.world.pop_set_usocial_reform_desire(p,
to_pu8(v));
129 auto ival = state.world.pop_get_upolitical_reform_desire(p);
133 state.world.pop_set_upolitical_reform_desire(p,
to_pu8(v));
142 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
146 return dcon::demographics_key(dcon::pop_demographics_key::value_base_t(
150 return dcon::demographics_key(
151 dcon::pop_demographics_key::value_base_t(
count_special_keys + state.world.pop_type_size() * 2 + v.index()));
154 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()));
157 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()));
160 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()));
164 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();
175 state.world.for_each_pop([&](dcon::pop_id p) {
176 auto location = state.world.pop_get_province_from_pop_location(p);
177 state.world.province_get_demographics(location, key) += source(state, p);
180 state.world.execute_serial_over_state_instance(
181 [&](
auto si) { state.world.state_instance_set_demographics(si, key, ve::fp_vector()); });
184 auto location = state.world.province_get_state_membership(p);
185 state.world.state_instance_get_demographics(location, key) += state.world.province_get_demographics(p, key);
188 state.world.execute_serial_over_nation([&](
auto ni) { state.world.nation_set_demographics(ni, key, ve::fp_vector()); });
190 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
191 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
192 state.world.nation_get_demographics(location, key) += state.world.state_instance_get_demographics(s, key);
201 state.world.for_each_pop([&](dcon::pop_id p) {
202 auto location = state.world.pop_get_province_from_pop_location(p);
203 state.world.province_get_demographics_alt(location, key) += source(state, p);
206 state.world.execute_serial_over_state_instance(
207 [&](
auto si) { state.world.state_instance_set_demographics_alt(si, key, ve::fp_vector()); });
210 auto location = state.world.province_get_state_membership(p);
211 state.world.state_instance_get_demographics_alt(location, key) += state.world.province_get_demographics_alt(p, key);
214 state.world.execute_serial_over_nation([&](
auto ni) { state.world.nation_set_demographics_alt(ni, key, ve::fp_vector()); });
216 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
217 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
218 state.world.nation_get_demographics_alt(location, key) += state.world.state_instance_get_demographics_alt(s, key);
224 state.world.province_set_demographics_alt(pi, key, state.world.province_get_demographics(pi, key));
226 state.world.execute_serial_over_state_instance([&](
auto si) {
227 state.world.state_instance_set_demographics_alt(si, key, state.world.state_instance_get_demographics(si, key));
229 state.world.execute_serial_over_nation([&](
auto ni) {
230 state.world.nation_set_demographics_alt(ni, key, state.world.nation_get_demographics(ni, key));
239 for(
auto pc : state.world.nation_get_province_control_as_nation(n)) {
240 auto location = pc.get_province();
241 state.world.province_set_demographics(location, key, 0.f);
242 for(
auto pl : pc.get_province().get_pop_location_as_province()) {
243 state.world.province_get_demographics(location, key) += source(state, pl.get_pop());
246 for(
auto sc : state.world.nation_get_state_ownership_as_nation(n)) {
247 auto location = sc.get_state();
248 state.world.state_instance_set_demographics(location, key, 0.f);
249 for(
auto sm : sc.get_state().get_definition().get_abstract_state_membership()) {
250 state.world.state_instance_get_demographics(location, key) += state.world.province_get_demographics(sm.get_province(), key);
254 state.world.nation_set_demographics(n, key, 0.f);
255 for(
auto sc : state.world.nation_get_state_ownership_as_nation(n)) {
256 state.world.nation_get_demographics(n, key) += state.world.state_instance_get_demographics(sc.get_state(), key);
261 dcon::demographics_key key =
to_key(state, state.culture_definitions.jingoism);
263 for(
const auto pc : state.world.nation_get_province_control_as_nation(n)) {
272 auto const sz =
size(state);
274 auto const extra_size = sz - csz;
277 concurrency::parallel_for(
uint32_t(0), full ? sz : csz + extra_group_size, [&](
uint32_t base_index) {
278 auto index = base_index;
279 if constexpr(!full) {
286 dcon::demographics_key key{dcon::demographics_key::value_base_t(index)};
294 return state.world.pop_type_get_has_unemployment(state.world.pop_get_poptype(p)) ? state.world.pop_get_size(p) : 0.0f;
318 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
319 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
321 auto opt = state.world.movement_get_associated_issue_option(movement);
322 auto optpar = state.world.issue_option_get_parent_issue(opt);
323 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::political))
324 return state.world.pop_get_size(p);
333 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
334 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
336 auto opt = state.world.movement_get_associated_issue_option(movement);
337 auto optpar = state.world.issue_option_get_parent_issue(opt);
338 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::social))
339 return state.world.pop_get_size(p);
433 ? state.world.pop_get_size(p)
440 ? state.world.pop_get_size(p)
447 ? state.world.pop_get_size(p)
453 }
else if(key.index() <
to_employment_key(state, dcon::pop_type_id(0)).index()) {
454 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (
count_special_keys)) };
456 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
458 }
else if(key.index() <
to_key(state, dcon::culture_id(0)).index()) {
459 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (
count_special_keys +
state.world.pop_type_size())) };
460 if(
state.world.pop_type_get_has_unemployment(pkey)) {
466 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
469 }
else if(key.index() <
to_key(state, dcon::ideology_id(0)).index()) {
470 dcon::culture_id pkey{
473 return state.world.pop_get_culture(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
475 }
else if(key.index() <
to_key(state, dcon::issue_option_id(0)).index()) {
476 dcon::ideology_id pkey{dcon::ideology_id::value_base_t(index - (
count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size()))};
481 }
else if(key.index() <
to_key(state, dcon::religion_id(0)).index()) {
482 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()))};
488 dcon::religion_id pkey{dcon::religion_id::value_base_t(
491 return state.world.pop_get_religion(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
502 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
504 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
505 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
506 state.world.for_each_culture([&](dcon::culture_id c) {
507 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
508 auto v =
state.world.province_get_demographics(p, k);
509 auto old_max = max_buffer.get(p);
510 auto mask = v > old_max;
511 state.world.province_set_dominant_culture(p,
512 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_culture(p)));
513 max_buffer.set(p,
ve::select(mask, v, old_max));
519 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
522 auto new_count =
state.world.state_instance_size();
523 if(new_count > old_count) {
524 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
525 old_count = new_count;
527 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
528 state.world.for_each_culture([&](dcon::culture_id c) {
529 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
530 auto v =
state.world.state_instance_get_demographics(p, k);
531 auto old_max = max_buffer.get(p);
532 auto mask = v > old_max;
533 state.world.state_instance_set_dominant_culture(p,
534 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.state_instance_get_dominant_culture(p)));
535 max_buffer.set(p,
ve::select(mask, v, old_max));
541 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
544 auto new_count =
state.world.nation_size();
545 if(new_count > old_count) {
546 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
547 old_count = new_count;
549 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
550 state.world.for_each_culture([&](dcon::culture_id c) {
551 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
552 auto v =
state.world.nation_get_demographics(p, k);
553 auto old_max = max_buffer.get(p);
554 auto mask = v > old_max;
555 state.world.nation_set_dominant_culture(p,
556 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.nation_get_dominant_culture(p)));
557 max_buffer.set(p,
ve::select(mask, v, old_max));
563 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
565 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
566 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
567 state.world.for_each_religion([&](dcon::religion_id c) {
568 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
569 auto v =
state.world.province_get_demographics(p, k);
570 auto old_max = max_buffer.get(p);
571 auto mask = v > old_max;
572 state.world.province_set_dominant_religion(p,
573 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.province_get_dominant_religion(p)));
574 max_buffer.set(p,
ve::select(mask, v, old_max));
580 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
583 auto new_count =
state.world.state_instance_size();
584 if(new_count > old_count) {
585 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
586 old_count = new_count;
588 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
589 state.world.for_each_religion([&](dcon::religion_id c) {
590 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
591 auto v =
state.world.state_instance_get_demographics(p, k);
592 auto old_max = max_buffer.get(p);
593 auto mask = v > old_max;
594 state.world.state_instance_set_dominant_religion(p,
595 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.state_instance_get_dominant_religion(p)));
596 max_buffer.set(p,
ve::select(mask, v, old_max));
602 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
605 auto new_count =
state.world.nation_size();
606 if(new_count > old_count) {
607 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
608 old_count = new_count;
610 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
611 state.world.for_each_religion([&](dcon::religion_id c) {
612 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
613 auto v =
state.world.nation_get_demographics(p, k);
614 auto old_max = max_buffer.get(p);
615 auto mask = v > old_max;
616 state.world.nation_set_dominant_religion(p,
617 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.nation_get_dominant_religion(p)));
618 max_buffer.set(p,
ve::select(mask, v, old_max));
624 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
626 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
627 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
628 state.world.for_each_ideology([&](dcon::ideology_id c) {
629 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
630 auto v =
state.world.province_get_demographics(p, k);
631 auto old_max = max_buffer.get(p);
632 auto mask = v > old_max;
633 state.world.province_set_dominant_ideology(p,
634 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.province_get_dominant_ideology(p)));
635 max_buffer.set(p,
ve::select(mask, v, old_max));
641 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
644 auto new_count =
state.world.state_instance_size();
645 if(new_count > old_count) {
646 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
647 old_count = new_count;
649 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
650 state.world.for_each_ideology([&](dcon::ideology_id c) {
651 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
652 auto v =
state.world.state_instance_get_demographics(p, k);
653 auto old_max = max_buffer.get(p);
654 auto mask = v > old_max;
655 state.world.state_instance_set_dominant_ideology(p,
656 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.state_instance_get_dominant_ideology(p)));
657 max_buffer.set(p,
ve::select(mask, v, old_max));
663 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
666 auto new_count =
state.world.nation_size();
667 if(new_count > old_count) {
668 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
669 old_count = new_count;
671 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
672 state.world.for_each_ideology([&](dcon::ideology_id c) {
673 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
674 auto v =
state.world.nation_get_demographics(p, k);
675 auto old_max = max_buffer.get(p);
676 auto mask = v > old_max;
677 state.world.nation_set_dominant_ideology(p,
678 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.nation_get_dominant_ideology(p)));
679 max_buffer.set(p,
ve::select(mask, v, old_max));
685 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
687 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
688 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
689 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
690 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
691 auto v =
state.world.province_get_demographics(p, k);
692 auto old_max = max_buffer.get(p);
693 auto mask = v > old_max;
694 state.world.province_set_dominant_issue_option(p,
695 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.province_get_dominant_issue_option(p)));
696 max_buffer.set(p,
ve::select(mask, v, old_max));
702 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
705 auto new_count =
state.world.state_instance_size();
706 if(new_count > old_count) {
707 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
708 old_count = new_count;
710 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
711 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
712 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
713 auto v =
state.world.state_instance_get_demographics(p, k);
714 auto old_max = max_buffer.get(p);
715 auto mask = v > old_max;
716 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)));
717 max_buffer.set(p,
ve::select(mask, v, old_max));
723 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
726 auto new_count =
state.world.nation_size();
727 if(new_count > old_count) {
728 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
729 old_count = new_count;
731 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
732 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
733 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
734 auto v =
state.world.nation_get_demographics(p, k);
735 auto old_max = max_buffer.get(p);
736 auto mask = v > old_max;
737 state.world.nation_set_dominant_issue_option(p,
738 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.nation_get_dominant_issue_option(p)));
739 max_buffer.set(p,
ve::select(mask, v, old_max));
745 static ve::vectorizable_buffer<float, dcon::pop_id> max_buffer(
uint32_t(1));
748 auto new_count =
state.world.pop_size();
749 if(new_count > old_count) {
750 max_buffer =
state.world.pop_make_vectorizable_float_buffer();
751 old_count = new_count;
753 state.world.execute_serial_over_pop([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
754 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
757 auto old_max = max_buffer.get(p);
758 auto mask = v > old_max;
759 state.world.pop_set_dominant_issue_option(p,
760 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.pop_get_dominant_issue_option(p)));
761 max_buffer.set(p,
ve::select(mask, v, old_max));
767 static ve::vectorizable_buffer<float, dcon::pop_id> max_buffer(
uint32_t(1));
770 auto new_count =
state.world.pop_size();
771 if(new_count > old_count) {
772 max_buffer =
state.world.pop_make_vectorizable_float_buffer();
773 old_count = new_count;
775 state.world.execute_serial_over_pop([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
776 state.world.for_each_ideology([&](dcon::ideology_id c) {
779 auto old_max = max_buffer.get(p);
780 auto mask = v > old_max;
781 state.world.pop_set_dominant_ideology(p,
782 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.pop_get_dominant_ideology(p)));
783 max_buffer.set(p,
ve::select(mask, v, old_max));
790 state.world.execute_serial_over_nation(
791 [&](
auto ni) {
state.world.nation_set_non_colonial_population(ni, ve::fp_vector()); });
793 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
794 if(!
state.world.province_get_is_colonial(
state.world.state_instance_get_capital(s))) {
795 auto location =
state.world.state_instance_get_nation_from_state_ownership(s);
796 state.world.nation_get_non_colonial_population(location) +=
804 state.world.execute_serial_over_nation(
805 [&](
auto ni) {
state.world.nation_set_non_colonial_bureaucrats(ni, ve::fp_vector()); });
807 state.world.for_each_state_instance(
809 if(!
state.world.province_get_is_colonial(
state.world.state_instance_get_capital(s))) {
810 auto location =
state.world.state_instance_get_nation_from_state_ownership(s);
811 state.world.nation_get_non_colonial_bureaucrats(location) +=
state.world.state_instance_get_demographics(s, k);
818 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
819 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
820 [&](
auto p) { state.world.province_set_dominant_accepted_culture(p, dcon::culture_id{}); });
821 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
822 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
824 state.world.for_each_culture([&](dcon::culture_id c) {
825 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, key =
to_key(state, c)](
auto p) {
826 auto v =
state.world.province_get_demographics(p, key);
827 auto old_max = max_buffer.get(p);
829 state.world.province_set_dominant_accepted_culture(p,
830 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_accepted_culture(p)));
831 max_buffer.set(p,
ve::select(mask, v, old_max));
843 regenerate_from_pop_data<true>(state);
846 regenerate_from_pop_data<false>(state);
851 auto const sz = size(state);
853 auto const extra_size = sz - csz;
856 concurrency::parallel_for(
uint32_t(0), full ? sz : csz + extra_group_size, [&](
uint32_t base_index) {
857 auto index = base_index;
858 if constexpr(!full) {
865 dcon::demographics_key key{ dcon::demographics_key::value_base_t(index) };
866 if(index < count_special_keys) {
873 return state.world.pop_type_get_has_unemployment(state.world.pop_get_poptype(p)) ? state.world.pop_get_size(p) : 0.0f;
897 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
898 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
900 auto opt = state.world.movement_get_associated_issue_option(movement);
901 auto optpar = state.world.issue_option_get_parent_issue(opt);
902 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::political))
903 return state.world.pop_get_size(p);
912 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
913 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
915 auto opt = state.world.movement_get_associated_issue_option(movement);
916 auto optpar = state.world.issue_option_get_parent_issue(opt);
917 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::social))
918 return state.world.pop_get_size(p);
1012 ? state.world.pop_get_size(p)
1019 ? state.world.pop_get_size(p)
1026 ? state.world.pop_get_size(p)
1032 }
else if(key.index() < to_employment_key(state, dcon::pop_type_id(0)).index()) {
1033 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys)) };
1035 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1037 }
else if(key.index() <
to_key(state, dcon::culture_id(0)).index()) {
1038 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size())) };
1039 if(
state.world.pop_type_get_has_unemployment(pkey)) {
1045 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1048 }
else if(key.index() <
to_key(state, dcon::ideology_id(0)).index()) {
1049 dcon::culture_id pkey{
1050 dcon::culture_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2)) };
1052 return state.world.pop_get_culture(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1054 }
else if(key.index() <
to_key(state, dcon::issue_option_id(0)).index()) {
1055 dcon::ideology_id pkey{ dcon::ideology_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size())) };
1060 }
else if(key.index() <
to_key(state, dcon::religion_id(0)).index()) {
1061 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())) };
1067 dcon::religion_id pkey{ dcon::religion_id::value_base_t(
1068 index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size() +
state.world.issue_option_size())) };
1070 return state.world.pop_get_religion(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1083 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1085 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1086 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1087 state.world.for_each_culture([&](dcon::culture_id c) {
1088 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1089 auto v =
state.world.province_get_demographics_alt(p, k);
1090 auto old_max = max_buffer.get(p);
1091 auto mask = v > old_max;
1092 state.world.province_set_dominant_culture(p,
1093 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_culture(p)));
1094 max_buffer.set(p,
ve::select(mask, v, old_max));
1101 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1104 auto new_count =
state.world.state_instance_size();
1105 if(new_count > old_count) {
1106 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1107 old_count = new_count;
1109 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1110 state.world.for_each_culture([&](dcon::culture_id c) {
1111 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1112 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1113 auto old_max = max_buffer.get(p);
1114 auto mask = v > old_max;
1115 state.world.state_instance_set_dominant_culture(p,
1116 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.state_instance_get_dominant_culture(p)));
1117 max_buffer.set(p,
ve::select(mask, v, old_max));
1124 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1127 auto new_count =
state.world.nation_size();
1128 if(new_count > old_count) {
1129 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1130 old_count = new_count;
1132 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1133 state.world.for_each_culture([&](dcon::culture_id c) {
1134 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1135 auto v =
state.world.nation_get_demographics_alt(p, k);
1136 auto old_max = max_buffer.get(p);
1137 auto mask = v > old_max;
1138 state.world.nation_set_dominant_culture(p,
1139 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.nation_get_dominant_culture(p)));
1140 max_buffer.set(p,
ve::select(mask, v, old_max));
1147 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1149 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1150 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1151 state.world.for_each_religion([&](dcon::religion_id c) {
1152 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1153 auto v =
state.world.province_get_demographics_alt(p, k);
1154 auto old_max = max_buffer.get(p);
1155 auto mask = v > old_max;
1156 state.world.province_set_dominant_religion(p,
1157 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.province_get_dominant_religion(p)));
1158 max_buffer.set(p,
ve::select(mask, v, old_max));
1165 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1168 auto new_count =
state.world.state_instance_size();
1169 if(new_count > old_count) {
1170 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1171 old_count = new_count;
1173 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1174 state.world.for_each_religion([&](dcon::religion_id c) {
1175 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1176 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1177 auto old_max = max_buffer.get(p);
1178 auto mask = v > old_max;
1179 state.world.state_instance_set_dominant_religion(p,
1180 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.state_instance_get_dominant_religion(p)));
1181 max_buffer.set(p,
ve::select(mask, v, old_max));
1188 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1191 auto new_count =
state.world.nation_size();
1192 if(new_count > old_count) {
1193 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1194 old_count = new_count;
1196 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1197 state.world.for_each_religion([&](dcon::religion_id c) {
1198 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1199 auto v =
state.world.nation_get_demographics_alt(p, k);
1200 auto old_max = max_buffer.get(p);
1201 auto mask = v > old_max;
1202 state.world.nation_set_dominant_religion(p,
1203 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.nation_get_dominant_religion(p)));
1204 max_buffer.set(p,
ve::select(mask, v, old_max));
1211 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1213 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1214 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1215 state.world.for_each_ideology([&](dcon::ideology_id c) {
1216 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1217 auto v =
state.world.province_get_demographics_alt(p, k);
1218 auto old_max = max_buffer.get(p);
1219 auto mask = v > old_max;
1220 state.world.province_set_dominant_ideology(p,
1221 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.province_get_dominant_ideology(p)));
1222 max_buffer.set(p,
ve::select(mask, v, old_max));
1229 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1232 auto new_count =
state.world.state_instance_size();
1233 if(new_count > old_count) {
1234 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1235 old_count = new_count;
1237 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1238 state.world.for_each_ideology([&](dcon::ideology_id c) {
1239 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1240 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1241 auto old_max = max_buffer.get(p);
1242 auto mask = v > old_max;
1243 state.world.state_instance_set_dominant_ideology(p,
1244 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.state_instance_get_dominant_ideology(p)));
1245 max_buffer.set(p,
ve::select(mask, v, old_max));
1252 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1255 auto new_count =
state.world.nation_size();
1256 if(new_count > old_count) {
1257 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1258 old_count = new_count;
1260 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1261 state.world.for_each_ideology([&](dcon::ideology_id c) {
1262 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1263 auto v =
state.world.nation_get_demographics_alt(p, k);
1264 auto old_max = max_buffer.get(p);
1265 auto mask = v > old_max;
1266 state.world.nation_set_dominant_ideology(p,
1267 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.nation_get_dominant_ideology(p)));
1268 max_buffer.set(p,
ve::select(mask, v, old_max));
1275 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1277 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1278 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1279 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1280 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1281 auto v =
state.world.province_get_demographics_alt(p, k);
1282 auto old_max = max_buffer.get(p);
1283 auto mask = v > old_max;
1284 state.world.province_set_dominant_issue_option(p,
1285 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.province_get_dominant_issue_option(p)));
1286 max_buffer.set(p,
ve::select(mask, v, old_max));
1293 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1296 auto new_count =
state.world.state_instance_size();
1297 if(new_count > old_count) {
1298 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1299 old_count = new_count;
1301 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1302 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1303 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1304 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1305 auto old_max = max_buffer.get(p);
1306 auto mask = v > old_max;
1307 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)));
1308 max_buffer.set(p,
ve::select(mask, v, old_max));
1315 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1318 auto new_count =
state.world.nation_size();
1319 if(new_count > old_count) {
1320 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1321 old_count = new_count;
1323 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1324 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1325 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1326 auto v =
state.world.nation_get_demographics_alt(p, k);
1327 auto old_max = max_buffer.get(p);
1328 auto mask = v > old_max;
1329 state.world.nation_set_dominant_issue_option(p,
1330 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.nation_get_dominant_issue_option(p)));
1331 max_buffer.set(p,
ve::select(mask, v, old_max));
1344 auto const sz = size(state);
1346 auto const extra_size = sz - csz;
1349 for(
uint32_t base_index = 0; base_index < (full ? sz : csz + extra_group_size); ++ base_index) {
1350 auto index = base_index;
1351 if constexpr(!full) {
1358 dcon::demographics_key key{ dcon::demographics_key::value_base_t(index) };
1359 if(index < count_special_keys) {
1366 return state.world.pop_type_get_has_unemployment(state.world.pop_get_poptype(p)) ? state.world.pop_get_size(p) : 0.0f;
1390 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
1391 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
1393 auto opt = state.world.movement_get_associated_issue_option(movement);
1394 auto optpar = state.world.issue_option_get_parent_issue(opt);
1395 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::political))
1396 return state.world.pop_get_size(p);
1405 if(state.world.province_get_is_colonial(state.world.pop_get_province_from_pop_location(p)) ==
false) {
1406 auto movement = state.world.pop_get_movement_from_pop_movement_membership(p);
1408 auto opt = state.world.movement_get_associated_issue_option(movement);
1409 auto optpar = state.world.issue_option_get_parent_issue(opt);
1410 if(opt && state.world.issue_get_issue_type(optpar) == uint8_t(culture::issue_type::social))
1411 return state.world.pop_get_size(p);
1505 ? state.world.pop_get_size(p)
1512 ? state.world.pop_get_size(p)
1519 ? state.world.pop_get_size(p)
1525 }
else if(key.index() < to_employment_key(state, dcon::pop_type_id(0)).index()) {
1526 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys)) };
1528 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1530 }
else if(key.index() <
to_key(state, dcon::culture_id(0)).index()) {
1531 dcon::pop_type_id pkey{ dcon::pop_type_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size())) };
1532 if(
state.world.pop_type_get_has_unemployment(pkey)) {
1538 return state.world.pop_get_poptype(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1541 }
else if(key.index() <
to_key(state, dcon::ideology_id(0)).index()) {
1542 dcon::culture_id pkey{
1543 dcon::culture_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2)) };
1545 return state.world.pop_get_culture(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1547 }
else if(key.index() <
to_key(state, dcon::issue_option_id(0)).index()) {
1548 dcon::ideology_id pkey{ dcon::ideology_id::value_base_t(index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size())) };
1553 }
else if(key.index() <
to_key(state, dcon::religion_id(0)).index()) {
1554 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())) };
1560 dcon::religion_id pkey{ dcon::religion_id::value_base_t(
1561 index - (count_special_keys +
state.world.pop_type_size() * 2 +
state.world.culture_size() +
state.world.ideology_size() +
state.world.issue_option_size())) };
1563 return state.world.pop_get_religion(p) == pkey ?
state.world.pop_get_size(p) : 0.0f;
1568 if constexpr(full ==
false) {
1569 for(
uint32_t base_index = csz; base_index < (full ? sz : csz + extra_group_size); ++base_index) {
1570 auto index = base_index;
1575 dcon::demographics_key key{ dcon::demographics_key::value_base_t(index) };
1585 if((
state.current_date.value % 1) != 0) {
1589 for(
uint32_t index = l2_start; index < l2_end; ++index) {
1593 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1595 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1596 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1597 state.world.for_each_culture([&](dcon::culture_id c) {
1598 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1599 auto v =
state.world.province_get_demographics_alt(p, k);
1600 auto old_max = max_buffer.get(p);
1601 auto mask = v > old_max;
1602 state.world.province_set_dominant_culture(p,
1603 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.province_get_dominant_culture(p)));
1604 max_buffer.set(p,
ve::select(mask, v, old_max));
1611 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1614 auto new_count =
state.world.state_instance_size();
1615 if(new_count > old_count) {
1616 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1617 old_count = new_count;
1619 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1620 state.world.for_each_culture([&](dcon::culture_id c) {
1621 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1622 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1623 auto old_max = max_buffer.get(p);
1624 auto mask = v > old_max;
1625 state.world.state_instance_set_dominant_culture(p,
1626 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.state_instance_get_dominant_culture(p)));
1627 max_buffer.set(p,
ve::select(mask, v, old_max));
1634 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1637 auto new_count =
state.world.nation_size();
1638 if(new_count > old_count) {
1639 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1640 old_count = new_count;
1642 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1643 state.world.for_each_culture([&](dcon::culture_id c) {
1644 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1645 auto v =
state.world.nation_get_demographics_alt(p, k);
1646 auto old_max = max_buffer.get(p);
1647 auto mask = v > old_max;
1648 state.world.nation_set_dominant_culture(p,
1649 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c),
state.world.nation_get_dominant_culture(p)));
1650 max_buffer.set(p,
ve::select(mask, v, old_max));
1657 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1659 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1660 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1661 state.world.for_each_religion([&](dcon::religion_id c) {
1662 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1663 auto v =
state.world.province_get_demographics_alt(p, k);
1664 auto old_max = max_buffer.get(p);
1665 auto mask = v > old_max;
1666 state.world.province_set_dominant_religion(p,
1667 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.province_get_dominant_religion(p)));
1668 max_buffer.set(p,
ve::select(mask, v, old_max));
1675 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1678 auto new_count =
state.world.state_instance_size();
1679 if(new_count > old_count) {
1680 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1681 old_count = new_count;
1683 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1684 state.world.for_each_religion([&](dcon::religion_id c) {
1685 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1686 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1687 auto old_max = max_buffer.get(p);
1688 auto mask = v > old_max;
1689 state.world.state_instance_set_dominant_religion(p,
1690 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.state_instance_get_dominant_religion(p)));
1691 max_buffer.set(p,
ve::select(mask, v, old_max));
1698 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1701 auto new_count =
state.world.nation_size();
1702 if(new_count > old_count) {
1703 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1704 old_count = new_count;
1706 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1707 state.world.for_each_religion([&](dcon::religion_id c) {
1708 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1709 auto v =
state.world.nation_get_demographics_alt(p, k);
1710 auto old_max = max_buffer.get(p);
1711 auto mask = v > old_max;
1712 state.world.nation_set_dominant_religion(p,
1713 ve::select(mask, ve::tagged_vector<dcon::religion_id>(c),
state.world.nation_get_dominant_religion(p)));
1714 max_buffer.set(p,
ve::select(mask, v, old_max));
1721 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1723 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1724 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1725 state.world.for_each_ideology([&](dcon::ideology_id c) {
1726 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1727 auto v =
state.world.province_get_demographics_alt(p, k);
1728 auto old_max = max_buffer.get(p);
1729 auto mask = v > old_max;
1730 state.world.province_set_dominant_ideology(p,
1731 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.province_get_dominant_ideology(p)));
1732 max_buffer.set(p,
ve::select(mask, v, old_max));
1739 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1742 auto new_count =
state.world.state_instance_size();
1743 if(new_count > old_count) {
1744 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1745 old_count = new_count;
1747 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1748 state.world.for_each_ideology([&](dcon::ideology_id c) {
1749 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1750 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1751 auto old_max = max_buffer.get(p);
1752 auto mask = v > old_max;
1753 state.world.state_instance_set_dominant_ideology(p,
1754 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.state_instance_get_dominant_ideology(p)));
1755 max_buffer.set(p,
ve::select(mask, v, old_max));
1762 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1765 auto new_count =
state.world.nation_size();
1766 if(new_count > old_count) {
1767 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1768 old_count = new_count;
1770 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1771 state.world.for_each_ideology([&](dcon::ideology_id c) {
1772 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1773 auto v =
state.world.nation_get_demographics_alt(p, k);
1774 auto old_max = max_buffer.get(p);
1775 auto mask = v > old_max;
1776 state.world.nation_set_dominant_ideology(p,
1777 ve::select(mask, ve::tagged_vector<dcon::ideology_id>(c),
state.world.nation_get_dominant_ideology(p)));
1778 max_buffer.set(p,
ve::select(mask, v, old_max));
1785 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer =
state.world.province_make_vectorizable_float_buffer();
1787 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()),
1788 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1789 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1790 ve::execute_serial<dcon::province_id>(
uint32_t(
state.province_definitions.first_sea_province.index()), [&, k =
to_key(state, c)](
auto p) {
1791 auto v =
state.world.province_get_demographics_alt(p, k);
1792 auto old_max = max_buffer.get(p);
1793 auto mask = v > old_max;
1794 state.world.province_set_dominant_issue_option(p,
1795 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.province_get_dominant_issue_option(p)));
1796 max_buffer.set(p,
ve::select(mask, v, old_max));
1803 static ve::vectorizable_buffer<float, dcon::state_instance_id> max_buffer(
uint32_t(1));
1806 auto new_count =
state.world.state_instance_size();
1807 if(new_count > old_count) {
1808 max_buffer =
state.world.state_instance_make_vectorizable_float_buffer();
1809 old_count = new_count;
1811 state.world.execute_serial_over_state_instance([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1812 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1813 state.world.execute_serial_over_state_instance([&, k =
to_key(state, c)](
auto p) {
1814 auto v =
state.world.state_instance_get_demographics_alt(p, k);
1815 auto old_max = max_buffer.get(p);
1816 auto mask = v > old_max;
1817 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)));
1818 max_buffer.set(p,
ve::select(mask, v, old_max));
1825 static ve::vectorizable_buffer<float, dcon::nation_id> max_buffer(
uint32_t(1));
1828 auto new_count =
state.world.nation_size();
1829 if(new_count > old_count) {
1830 max_buffer =
state.world.nation_make_vectorizable_float_buffer();
1831 old_count = new_count;
1833 state.world.execute_serial_over_nation([&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1834 state.world.for_each_issue_option([&](dcon::issue_option_id c) {
1835 state.world.execute_serial_over_nation([&, k =
to_key(state, c)](
auto p) {
1836 auto v =
state.world.nation_get_demographics_alt(p, k);
1837 auto old_max = max_buffer.get(p);
1838 auto mask = v > old_max;
1839 state.world.nation_set_dominant_issue_option(p,
1840 ve::select(mask, ve::tagged_vector<dcon::issue_option_id>(c),
state.world.nation_get_dominant_issue_option(p)));
1841 max_buffer.set(p,
ve::select(mask, v, old_max));
1853 alt_st_regenerate_from_pop_data<false>(state);
1856 alt_mt_regenerate_from_pop_data<true>(state);
1866 state.world.execute_serial_over_nation(
1867 [&](
auto ni) { state.world.nation_set_non_colonial_population(ni, ve::fp_vector()); });
1869 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
1870 if(!state.world.province_get_is_colonial(state.world.state_instance_get_capital(s))) {
1871 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
1872 state.world.nation_get_non_colonial_population(location) +=
1873 state.world.state_instance_get_demographics(s, demographics::total);
1881 state.world.execute_serial_over_nation(
1882 [&](
auto ni) { state.world.nation_set_non_colonial_bureaucrats(ni, ve::fp_vector()); });
1884 state.world.for_each_state_instance(
1885 [&, k =
demographics::to_key(state, state.culture_definitions.bureaucrat)](dcon::state_instance_id s) {
1886 if(!state.world.province_get_is_colonial(state.world.state_instance_get_capital(s))) {
1887 auto location = state.world.state_instance_get_nation_from_state_ownership(s);
1888 state.world.nation_get_non_colonial_bureaucrats(location) += state.world.state_instance_get_demographics(s, k);
1895 static ve::vectorizable_buffer<float, dcon::province_id> max_buffer = state.world.province_make_vectorizable_float_buffer();
1896 ve::execute_serial<dcon::province_id>(
uint32_t(state.province_definitions.first_sea_province.index()),
1897 [&](
auto p) { state.world.province_set_dominant_accepted_culture(p, dcon::culture_id{}); });
1898 ve::execute_serial<dcon::province_id>(
uint32_t(state.province_definitions.first_sea_province.index()),
1899 [&](
auto p) { max_buffer.set(p, ve::fp_vector()); });
1901 state.world.for_each_culture([&](dcon::culture_id c) {
1902 ve::execute_serial<dcon::province_id>(
uint32_t(state.province_definitions.first_sea_province.index()), [&, key = to_key(state, c)](
auto p) {
1903 auto v = state.world.province_get_demographics_alt(p, key);
1904 auto old_max = max_buffer.get(p);
1906 state.world.province_set_dominant_accepted_culture(p,
1907 ve::select(mask, ve::tagged_vector<dcon::culture_id>(c), state.world.province_get_dominant_accepted_culture(p)));
1908 max_buffer.set(p,
ve::select(mask, v, old_max));
1921 auto block_index = 16 * offset;
1922 auto const block_advance = 16 * divisions;
1926 while(block_index < max) {
1928 functor(ve::contiguous_tags<dcon::pop_id>(block_index + i * ve::vector_size));
1930 block_index += block_advance;
1936 concurrency::parallel_for(16 * offset, max, 16 * divisions, [&](
uint32_t index) {
1938 functor(ve::contiguous_tags<dcon::pop_id>(index + i * ve::vector_size));
1968 auto loc = state.world.pop_get_province_from_pop_location(ids);
1969 auto owner = state.world.province_get_nation_from_province_ownership(loc);
1970 auto ruling_party = state.world.nation_get_ruling_party(owner);
1971 auto ruling_ideology = state.world.political_party_get_ideology(ruling_party);
1973 auto lx_mod = ve::max(pop_demographics::get_luxury_needs(state, ids) - 0.5f, 0.0f) * state.defines.mil_has_luxury_need;
1974 auto con_sup = (pop_demographics::get_demo(state, ids, conservatism_key) * state.defines.mil_ideology);
1975 auto ruling_sup = ve::apply(
1976 [&](dcon::pop_id p, dcon::ideology_id i) {
1977 return i ? pop_demographics::get_demo(state, p, pop_demographics::to_key(state, i)) * state.defines.mil_ruling_party
1980 ids, ruling_ideology);
1981 auto ref_mod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
1983 (state.defines.mil_require_reform * 0.25f));
1985 auto o_spending = state.world.nation_get_overseas_penalty(owner);
1986 auto spending_level = state.world.nation_get_spending_level(owner);
1989 (state.defines.alice_overseas_mil * 2.f)
1990 * (0.5f - (o_spending * spending_level)),
1994 auto sub_t = (lx_mod + ruling_sup) + (con_sup + ref_mod);
1996 auto pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_militancy_modifier);
1997 auto omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_militancy_modifier);
1998 auto cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
1999 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_militancy_modifier));
2001 auto local_mod = (pmod + omod) + cmod;
2003 auto sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2004 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f) *
2005 state.defines.mil_non_accepted);
2012 auto war_exhaustion = state.world.nation_get_war_exhaustion(owner) * state.defines.mil_war_exhaustion;
2021 owner != dcon::nation_id{},
2026 + old_mil * (1.f - state.defines.alice_militancy_decay)
2030 + (en_mod_b - en_mod_a)
2031 + (war_exhaustion + overseas_mil)
2046 auto loc = state.world.pop_get_province_from_pop_location(ids);
2047 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2048 auto ruling_party = state.world.nation_get_ruling_party(owner);
2049 auto ruling_ideology = state.world.political_party_get_ideology(ruling_party);
2053 float ruling_sup = ruling_ideology
2056 float ref_mod = state.world.province_get_is_colonial(loc) ? 0.0f :
2058 (state.defines.mil_require_reform * 0.25f);
2060 auto o_spending = state.world.nation_get_overseas_penalty(owner);
2061 auto spending_level = state.world.nation_get_spending_level(owner);
2064 (state.defines.alice_overseas_mil * 2.f)
2065 * (0.5f - (o_spending * spending_level)),
2069 float sub_t = (lx_mod + ruling_sup) + (con_sup + ref_mod);
2071 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_militancy_modifier);
2072 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_militancy_modifier);
2073 float cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2074 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_militancy_modifier));
2076 float local_mod = (pmod + omod) + cmod;
2078 float sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2079 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f) *
2080 state.defines.mil_non_accepted);
2086 float war_exhaustion =
2087 state.world.nation_get_war_exhaustion(owner) * 0.005f;
2090 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;
2095 for(
auto prov :
dcon::fatten(state.world, n).get_province_ownership()) {
2096 for(
auto pop : prov.get_province().get_pop_location()) {
2101 return t != 0.f ? sum / t : 0.f;
2120 auto loc = state.world.pop_get_province_from_pop_location(ids);
2121 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2123 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
2124 auto types = state.world.pop_get_poptype(ids);
2126 auto lx_mod = pop_demographics::get_luxury_needs(state, ids) * state.defines.con_luxury_goods;
2127 auto cl_mod = cfrac * ve::select(state.world.pop_type_get_strata(types) == int32_t(culture::pop_strata::poor),
2128 ve::fp_vector{state.defines.con_poor_clergy}, ve::fp_vector{state.defines.con_midrich_clergy});
2129 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) *
2132 auto pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_consciousness_modifier);
2133 auto omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_consciousness_modifier);
2134 auto cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2135 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_consciousness_modifier));
2137 auto local_mod = (pmod + omod) + cmod;
2139 auto sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2140 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_consciousness_modifier));
2145 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));
2152 auto loc = state.world.pop_get_province_from_pop_location(ids);
2153 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2155 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc,
demographics::total);
2156 auto types = state.world.pop_get_poptype(ids);
2160 state.defines.con_poor_clergy, state.defines.con_midrich_clergy);
2161 float lit_mod = ((state.world.nation_get_plurality(owner) / 10.0f) *
2162 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::literacy_con_impact) + 1.0f) *
2164 ve::select(state.world.province_get_is_colonial(loc), state.defines.con_colonial_factor, 1.0f)) / 10.f;
2166 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_consciousness_modifier);
2167 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_consciousness_modifier);
2168 float cmod =
ve::select(state.world.province_get_is_colonial(loc), 0.0f,
2169 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_consciousness_modifier));
2171 float local_mod = (pmod + omod) + cmod;
2173 float sep_mod =
ve::select(state.world.pop_get_is_primary_or_accepted_culture(ids), 0.0f,
2174 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_consciousness_modifier));
2177 return (lx_mod + (cl_mod + lit_mod)) + (local_mod + sep_mod) - old_con * 0.01f;
2182 for(
auto prov :
dcon::fatten(state.world, n).get_province_ownership()) {
2183 for(
auto pop : prov.get_province().get_pop_location()) {
2188 return t != 0.f ? sum / t : 0.f;
2211 auto loc = state.world.pop_get_province_from_pop_location(ids);
2212 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2214 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
2216 auto tmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency) + 1.0f;
2217 auto nmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency_modifier) + 1.0f;
2218 auto espending = 0.5f +
2219 (ve::to_float(state.world.nation_get_education_spending(owner)) / 100.0f) * state.world.nation_get_spending_level(owner) * 0.5f;
2220 auto cmod = ve::max(
2224 (cfrac - state.defines.base_clergy_for_literacy)
2225 / (state.defines.max_clergy_for_literacy - state.defines.base_clergy_for_literacy)
2229 auto old_lit = pop_demographics::get_literacy(state, ids);
2230 auto new_lit = ve::min(
2233 + (0.01f * state.defines.literacy_change_speed)
2245 pop_demographics::set_literacy(state, ids, ve::select(owner != dcon::nation_id{}, new_lit, old_lit));
2252 auto loc = state.world.pop_get_province_from_pop_location(ids);
2253 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2255 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc,
demographics::total);
2257 auto tmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency) + 1.0f;
2258 auto nmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency_modifier) + 1.0f;
2260 (float(state.world.nation_get_education_spending(owner)) / 100.0f) * state.world.nation_get_spending_level(owner);
2261 auto cmod = std::max(0.0f, std::min(1.0f, (cfrac - state.defines.base_clergy_for_literacy) /
2262 (state.defines.max_clergy_for_literacy - state.defines.base_clergy_for_literacy)));
2265 auto new_lit = std::min(std::max(old_lit + (0.01f * state.defines.literacy_change_speed) * ((espending * cmod) * (tmod * nmod)), 0.01f), 1.0f);
2267 return new_lit - old_lit;
2272 for(
auto prov :
dcon::fatten(state.world, n).get_province_ownership()) {
2273 for(
auto pop : prov.get_province().get_pop_location()) {
2278 return t != 0.f ? sum / t : 0.f;
2287 auto new_pop_count = state.world.pop_size();
2288 ibuf.
update(state, new_pop_count);
2290 assert(state.world.ideology_size() <= 64);
2295 ve::fp_vector iopt_weights[64];
2296 ve::fp_vector ttotal = 0.0f;
2298 state.world.for_each_ideology([&](dcon::ideology_id i) {
2299 if(!state.world.ideology_get_enabled(i)) {
2300 iopt_weights[i.index()] = 0.0f;
2302 auto const i_key = pop_demographics::to_key(state, i);
2303 auto owner = nations::owner_of_pop(state, ids);
2305 if(state.world.ideology_get_is_civilized_only(i)) {
2306 auto amount = ve::max(ve::fp_vector{}, ve::apply(
2307 [&](dcon::pop_id pid, dcon::pop_type_id ptid, dcon::nation_id o) {
2308 if(state.world.nation_get_is_civilized(o)) {
2309 if(auto mfn = state.world.pop_type_get_ideology_fns(ptid, i); mfn != 0) {
2310 using ftype = float(*)(int32_t);
2311 ftype fn = (ftype)mfn;
2312 float llvm_result = fn(pid.index());
2313#ifdef CHECK_LLVM_RESULTS
2314 float interp_result = 0.0f;
2315 if(auto mtrigger = state.world.pop_type_get_ideology(ptid, i); mtrigger) {
2316 interp_result = trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2318 assert(llvm_result == interp_result);
2322 auto ptrigger = state.world.pop_type_get_ideology(ptid, i);
2323 return ptrigger ? trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0) : 0.0f;
2328 }, ids, state.world.pop_get_poptype(ids), owner));
2330 iopt_weights[i.index()] = amount;
2331 ttotal = ttotal + amount;
2333 auto amount = ve::max(ve::fp_vector{}, ve::apply(
2334 [&](dcon::pop_id pid, dcon::pop_type_id ptid, dcon::nation_id o) {
2335 if(auto mfn = state.world.pop_type_get_ideology_fns(ptid, i); mfn != 0) {
2336 using ftype = float(*)(int32_t);
2337 ftype fn = (ftype)mfn;
2338 float llvm_result = fn(pid.index());
2339#ifdef CHECK_LLVM_RESULTS
2340 float interp_result = 0.0f;
2341 if(auto mtrigger = state.world.pop_type_get_ideology(ptid, i); mtrigger) {
2342 interp_result = trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2344 assert(llvm_result == interp_result);
2348 auto ptrigger = state.world.pop_type_get_ideology(ptid, i);
2349 return ptrigger ? trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0) : 0.0f;
2351 }, ids, state.world.pop_get_poptype(ids), owner));
2353 iopt_weights[i.index()] = amount;
2354 ttotal = ttotal + amount;
2360 ve::fp_vector max_weight{ 0.0f };
2361 ve::tagged_vector<dcon::ideology_id> preferred{};
2363 state.world.for_each_ideology([&](dcon::ideology_id iid) {
2364 auto avalue = iopt_weights[iid.index()] / ttotal;
2369 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);
2370 auto new_max = new_weight > max_weight;
2371 preferred =
ve::select(new_max, ve::tagged_vector<dcon::ideology_id>{iid}, preferred);
2372 max_weight =
ve::select(new_max, new_weight, max_weight);
2377 state.world.pop_set_dominant_ideology(ids, preferred);
2379 state.world.for_each_ideology([&](dcon::ideology_id iid) {
2380 auto avalue = iopt_weights[iid.index()] / ttotal;
2389 state.defines.alice_ideology_base_change_rate * avalue + (1.0f -
state.defines.alice_ideology_base_change_rate) * current, current)));
2408 state.world.for_each_ideology([&](dcon::ideology_id i) {
2409 if(state.world.ideology_get_enabled(i)) {
2410 auto const i_key = pop_demographics::to_key(state, i);
2412 execute_staggered_blocks(offset, divisions, std::min(state.world.pop_size(), pbuf.size), [&](auto ids) {
2413 auto avalue = pbuf.temp_buffers[i].get(ids);
2414 state.world.pop_set_udemographics(ids, i_key, avalue);
2429 auto new_pop_count = state.world.pop_size();
2430 ibuf.
update(state, new_pop_count);
2433 assert(state.world.issue_option_size() <= 720);
2436 ve::fp_vector iopt_weights[720];
2437 ve::fp_vector ttotal = 0.0f;
2440 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
2441 auto opt = fatten(state.world, iid);
2442 auto allow = opt.get_allow();
2443 auto parent_issue = opt.get_parent_issue();
2448 auto has_modifier = is_social_issue || is_political_issue;
2450 is_social_issue ? sys::national_mod_offsets::social_reform_desire : sys::national_mod_offsets::political_reform_desire;
2452 auto current_issue_setting = state.world.nation_get_issues(owner, parent_issue);
2453 auto allowed_by_owner =
2454 (state.world.nation_get_is_civilized(owner) || ve::mask_vector(is_party_issue))
2455 && (ve::mask_vector(!state.world.issue_get_is_next_step_only(parent_issue)) ||
2456 (ve::tagged_vector<int32_t>(current_issue_setting) == iid.index()) ||
2457 (ve::tagged_vector<int32_t>(current_issue_setting) == iid.index() - 1) ||
2458 (ve::tagged_vector<int32_t>(current_issue_setting) == iid.index() + 1));
2459 auto owner_modifier =
2460 has_modifier ? (state.world.nation_get_modifier_values(owner, modifier_key) + 1.0f) : ve::fp_vector(1.0f);
2462 auto amount = ve::max(ve::fp_vector{}, owner_modifier *
ve::select(allowed_by_owner,
2463 ve::apply([&](dcon::pop_id pid, dcon::pop_type_id ptid, dcon::nation_id o) {
2464 if(
auto mfn = state.world.pop_type_get_issues_fns(ptid, iid); mfn != 0) {
2465 using ftype = float(*)(int32_t);
2466 ftype fn = (ftype)mfn;
2467 float llvm_result = fn(pid.index());
2468#ifdef CHECK_LLVM_RESULTS
2469 float interp_result = 0.0f;
2470 if(auto mtrigger = state.world.pop_type_get_issues(ptid, iid); mtrigger) {
2471 interp_result = trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2473 assert(llvm_result == interp_result);
2477 if(
auto mtrigger = state.world.pop_type_get_issues(ptid, iid); mtrigger) {
2478 return trigger::evaluate_multiplicative_modifier(state, mtrigger, trigger::to_generic(pid), trigger::to_generic(pid), 0);
2483 }, ids, state.world.pop_get_poptype(ids), owner),
2486 iopt_weights[iid.index()] = amount;
2487 ttotal = ttotal + amount;
2491 ve::fp_vector max_weight{ 0.0f };
2492 ve::tagged_vector<dcon::issue_option_id> preferred{};
2494 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
2495 auto avalue = iopt_weights[iid.index()] / ttotal;
2499 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);
2502 auto new_max = new_weight > max_weight;
2503 preferred =
ve::select(new_max, ve::tagged_vector<dcon::issue_option_id>{iid}, preferred);
2504 max_weight =
ve::select(new_max, new_weight, max_weight);
2509 state.world.pop_set_dominant_issue_option(ids, preferred);
2511 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
2512 auto avalue = iopt_weights[iid.index()] / ttotal;
2516 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);
2538 state.world.for_each_issue_option([&](dcon::issue_option_id i) {
2542 auto avalue = pbuf.temp_buffers[i].get(ids);
2543 state.world.pop_set_udemographics(ids, i_key, avalue);
2565 auto loc = state.world.pop_get_province_from_pop_location(ids);
2566 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2568 auto base_life_rating = ve::to_float(state.world.province_get_life_rating(loc));
2569 auto mod_life_rating = ve::min(
2570 base_life_rating * (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::life_rating) + 1.0f),
2573 ve::max((mod_life_rating - state.defines.min_life_rating_for_growth) * state.defines.life_rating_growth_bonus, 0.0f);
2574 auto province_factor = lr_factor + state.defines.base_popgrowth;
2576 auto ln_factor = pop_demographics::get_life_needs(state, ids) - state.defines.life_need_starvation_limit;
2577 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);
2579 auto total_factor = ln_factor * province_factor * 4.0f + mod_sum * 0.1f;
2580 auto old_size = state.world.pop_get_size(ids);
2581 auto new_size = old_size * total_factor + old_size;
2583 auto type = state.world.pop_get_poptype(ids);
2585 state.world.pop_set_size(ids,
2586 ve::select((owner != dcon::nation_id{}) && (type != state.culture_definitions.slaves), new_size, old_size));
2591 auto type = state.world.pop_get_poptype(ids);
2592 if(type == state.culture_definitions.slaves)
2595 auto loc = state.world.pop_get_province_from_pop_location(ids);
2596 auto owner = state.world.province_get_nation_from_province_ownership(loc);
2598 auto base_life_rating = float(state.world.province_get_life_rating(loc));
2599 auto mod_life_rating = std::min(
2600 base_life_rating * (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::life_rating) + 1.0f), 40.0f);
2602 std::max((mod_life_rating - state.defines.min_life_rating_for_growth) * state.defines.life_rating_growth_bonus, 0.0f);
2603 auto province_factor = lr_factor + state.defines.base_popgrowth;
2606 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);
2608 auto total_factor = ln_factor * province_factor * 4.0f + mod_sum * 0.1f;
2609 auto old_size = state.world.pop_get_size(ids);
2611 return old_size * total_factor;
2615 for(
auto prov : state.world.nation_get_province_ownership(n)) {
2616 for(
auto pop : prov.get_province().get_pop_location()) {
2626 for(
auto pop : state.world.province_get_pop_location(prov)) {
2627 t += get_monthly_pop_increase(state, pop.get_pop());
2635 for(
auto pop : state.world.province_get_pop_location(n)) {
2642 pbuf.
update(state.world.pop_size());
2650 pbuf.amounts.set(ids, 0.0f);
2651 auto owners = nations::owner_of_pop(state, ids);
2652#ifdef CHECK_LLVM_RESULTS
2653 auto promotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.promotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2654 auto demotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.demotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2656 ve::fp_vector promotion_chances;
2657 if(state.culture_definitions.promotion_chance_fn == 0)
2658 promotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.promotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2659 ve::fp_vector demotion_chances;
2660 if(state.culture_definitions.demotion_chance_fn == 0)
2661 demotion_chances = trigger::evaluate_additive_modifier(state, state.culture_definitions.demotion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
2664 [&](dcon::pop_id p, dcon::nation_id owner, float promotion_chance, float demotion_chance) {
2685 auto loc = state.world.pop_get_province_from_pop_location(p);
2686 auto si = state.world.province_get_state_membership(loc);
2687 auto nf = state.world.state_instance_get_owner_focus(si);
2688 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
2689 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
2690 auto ptype = state.world.pop_get_poptype(p);
2691 auto strata = state.world.pop_type_get_strata(ptype);
2694 using ftypeb = float(*)(int32_t);
2695 if(state.culture_definitions.promotion_chance_fn) {
2696 ftypeb fn = (ftypeb)(state.culture_definitions.promotion_chance_fn);
2697 float llvm_result = fn(p.index());
2698#ifdef CHECK_LLVM_RESULTS
2699 assert(llvm_result == promotion_chance);
2701 promotion_chance = llvm_result;
2703 if(state.culture_definitions.demotion_chance_fn) {
2704 ftypeb fn = (ftypeb)(state.culture_definitions.demotion_chance_fn);
2705 float llvm_result = fn(p.index());
2706#ifdef CHECK_LLVM_RESULTS
2707 assert(llvm_result == demotion_chance);
2709 demotion_chance = llvm_result;
2713 if(promoted_type == ptype) {
2714 promotion_chance = 0.0f;
2715 } else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
2716 promotion_chance += promotion_bonus;
2717 } else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
2718 demotion_chance += promotion_bonus;
2722 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
2725 float current_size = state.world.pop_get_size(p);
2727 bool promoting = promotion_chance >= demotion_chance;
2728 float base_amount = promoting
2729 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(owner) * state.defines.promotion_scale * current_size))
2730 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size));
2733 if(ptype == state.culture_definitions.artisans) {
2734 base_amount *= 10.f;
2740 if(base_amount >= 0.001f) {
2741 auto transfer_amount = std::min(current_size, base_amount);
2742 pbuf.amounts.set(p, transfer_amount);
2745 tagged_vector<float, dcon::pop_type_id> weights(state.world.pop_type_size());
2760 bool is_state_capital = state.world.state_instance_get_capital(state.world.province_get_state_membership(loc)) == loc;
2762 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))
2763 || (!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))) {
2765 float chance = 0.0f;
2766 if(auto mfn = state.world.pop_type_get_promotion_fns(ptype, promoted_type); mfn != 0) {
2767 using ftype = float(*)(int32_t);
2768 ftype fn = (ftype)mfn;
2769 float llvm_result = fn(p.index());
2770#ifdef CHECK_LLVM_RESULTS
2771 float interp_result = 0.0f;
2772 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, promoted_type); mtrigger) {
2773 interp_result = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0);
2775 assert(llvm_result == interp_result);
2777 chance = llvm_result + promotion_bonus;
2779 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, promoted_type); mtrigger) {
2780 chance = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0) + promotion_bonus;
2785 pbuf.types.set(p, promoted_type);
2790 float chances_total = 0.0f;
2791 state.world.for_each_pop_type([&](dcon::pop_type_id target_type) {
2792 if(target_type == ptype) {
2793 weights[target_type] = 0.0f;
2794 } else if(!is_state_capital && state.world.pop_type_get_state_capital_only(target_type)) {
2795 weights[target_type] = 0.0f;
2796 } else if((promoting && state.world.pop_type_get_strata(promoted_type) >= strata)
2797 || (!promoting && state.world.pop_type_get_strata(promoted_type) <= strata) ) {
2799 weights[target_type] = 0.0f;
2801 if(auto mfn = state.world.pop_type_get_promotion_fns(ptype, target_type); mfn != 0) {
2802 using ftype = float(*)(int32_t);
2803 ftype fn = (ftype)mfn;
2804 float llvm_result = fn(p.index());
2805#ifdef CHECK_LLVM_RESULTS
2806 float interp_result = 0.0f;
2807 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, target_type); mtrigger) {
2808 interp_result = trigger::evaluate_additive_modifier(state, mtrigger, trigger::to_generic(p), trigger::to_generic(p), 0);
2810 assert(llvm_result == interp_result);
2812 auto chance = llvm_result + (target_type == promoted_type ? promotion_bonus : 0.0f);
2813 chances_total += chance;
2814 weights[target_type] = chance;
2816 if(auto mtrigger = state.world.pop_type_get_promotion(ptype, target_type); mtrigger) {
2817 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);
2818 chances_total += chance;
2819 weights[target_type] = chance;
2824 weights[target_type] = 0.0f;
2828 if(chances_total > 0.0f) {
2829 auto rvalue = float(rng::get_random(state, uint32_t(p.index())) & 0xFFFF) / float(0xFFFF + 1);
2830 for(uint32_t i = state.world.pop_type_size(); i-- > 0;) {
2831 dcon::pop_type_id pr{dcon::pop_type_id::value_base_t(i)};
2832 rvalue -= weights[pr] / chances_total;
2834 pbuf.types.set(p, pr);
2838 pbuf.amounts.set(p, 0.0f);
2839 pbuf.types.set(p, dcon::pop_type_id{});
2841 pbuf.amounts.set(p, 0.0f);
2842 pbuf.types.set(p, dcon::pop_type_id{});
2845 ids, owners, promotion_chances, demotion_chances);
2850 float total_effective_change = .0f;
2852 for(
auto prov : state.world.nation_get_province_ownership(nation)) {
2853 for(
auto pop : prov.get_province().get_pop_location()) {
2859 auto owner = nation;
2861 auto p = pop.get_pop();
2863 auto loc = state.world.pop_get_province_from_pop_location(pop.get_pop());
2864 auto si = state.world.province_get_state_membership(loc);
2865 auto nf = state.world.state_instance_get_owner_focus(si);
2866 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
2867 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
2868 auto ptype = state.world.pop_get_poptype(pop.get_pop());
2869 auto strata = state.world.pop_type_get_strata(ptype);
2872 if(promoted_type == ptype) {
2873 promotion_chance = 0.0f;
2874 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
2875 promotion_chance += promotion_bonus;
2876 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
2877 demotion_chance += promotion_bonus;
2881 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
2884 float current_size = state.world.pop_get_size(p);
2886 bool promoting = promotion_chance >= demotion_chance;
2887 float base_amount = promoting
2888 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(nation) * state.defines.promotion_scale * current_size))
2889 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size));
2891 auto transfer_amount = base_amount >= 0.001f ? std::min(current_size, base_amount) : 0.0f;
2895 bool is_state_capital = state.world.state_instance_get_capital(state.world.province_get_state_membership(loc)) == loc;
2897 if(promoted_type == target_type) {
2898 if(promoting && promoted_type && state.world.pop_type_get_strata(promoted_type) >= strata &&
2899 (is_state_capital || state.world.pop_type_get_state_capital_only(promoted_type) ==
false)) {
2900 auto promote_mod = state.world.pop_type_get_promotion(ptype, promoted_type);
2906 total_effective_change += transfer_amount;
2910 }
else if(!promoting && promoted_type && state.world.pop_type_get_strata(promoted_type) <= strata &&
2911 (is_state_capital || state.world.pop_type_get_state_capital_only(promoted_type) ==
false)) {
2912 auto promote_mod = state.world.pop_type_get_promotion(ptype, promoted_type);
2918 total_effective_change += transfer_amount;
2925 float chances_total = 0.0f;
2927 state.world.for_each_pop_type([&](dcon::pop_type_id t_type) {
2928 if(t_type == ptype) {
2929 weights[t_type] = 0.0f;
2930 }
else if(!is_state_capital && state.world.pop_type_get_state_capital_only(t_type)) {
2931 weights[t_type] = 0.0f;
2932 }
else if(promoting && state.world.pop_type_get_strata(promoted_type) >= strata) {
2933 auto promote_mod = state.world.pop_type_get_promotion(ptype, t_type);
2935 auto chance = std::max(trigger::evaluate_additive_modifier(state, promote_mod, trigger::to_generic(p),
2936 trigger::to_generic(p), 0) +
2937 (t_type == promoted_type ? promotion_bonus : 0.0f),
2939 chances_total += chance;
2940 weights[t_type] = chance;
2942 weights[t_type] = 0.0f;
2944 }
else if(!promoting && state.world.pop_type_get_strata(promoted_type) <= strata) {
2945 auto promote_mod = state.world.pop_type_get_promotion(ptype, t_type);
2947 auto chance = std::max(trigger::evaluate_additive_modifier(state, promote_mod, trigger::to_generic(p),
2948 trigger::to_generic(p), 0) +
2949 (t_type == promoted_type ? promotion_bonus : 0.0f),
2951 chances_total += chance;
2952 weights[t_type] = chance;
2954 weights[t_type] = 0.0f;
2957 weights[t_type] = 0.0f;
2961 if(chances_total > 0.0f) {
2962 total_effective_change += transfer_amount * weights[target_type]/chances_total;
2968 for(
auto prov :
state.world.nation_get_province_ownership(nation)) {
2969 for(
auto pop :
prov.get_province().get_pop_location()) {
2970 if(
pop.get_pop().get_poptype() == target_type) {
2977 return total_effective_change;
2987 auto loc = state.world.pop_get_province_from_pop_location(ids);
2988 auto si = state.world.province_get_state_membership(loc);
2989 auto nf = state.world.state_instance_get_owner_focus(si);
2990 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
2991 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
2992 auto ptype = state.world.pop_get_poptype(ids);
2993 auto strata = state.world.pop_type_get_strata(ptype);
2996 if(promoted_type == ptype) {
2997 promotion_chance = 0.0f;
2998 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
2999 promotion_chance += promotion_bonus;
3000 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
3001 demotion_chance += promotion_bonus;
3005 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
3008 float current_size = state.world.pop_get_size(ids);
3010 bool promoting = promotion_chance >= demotion_chance;
3011 return std::min(current_size, promoting
3012 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(owner) *
3013 state.defines.promotion_scale * current_size))
3014 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size)));
3024 auto loc = state.world.pop_get_province_from_pop_location(ids);
3025 auto si = state.world.province_get_state_membership(loc);
3026 auto nf = state.world.state_instance_get_owner_focus(si);
3027 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
3028 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
3029 auto ptype = state.world.pop_get_poptype(ids);
3030 auto strata = state.world.pop_type_get_strata(ptype);
3033 if(promoted_type == ptype) {
3034 promotion_chance = 0.0f;
3035 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
3036 promotion_chance += promotion_bonus;
3037 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
3038 demotion_chance += promotion_bonus;
3042 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
3045 float current_size = state.world.pop_get_size(ids);
3047 bool promoting = promotion_chance >= demotion_chance;
3048 return std::min(current_size, promoting
3049 ? (std::ceil(promotion_chance * state.world.nation_get_administrative_efficiency(owner) *
3050 state.defines.promotion_scale * current_size))
3060 auto loc = state.world.pop_get_province_from_pop_location(ids);
3061 auto si = state.world.province_get_state_membership(loc);
3062 auto nf = state.world.state_instance_get_owner_focus(si);
3063 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
3064 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
3065 auto ptype = state.world.pop_get_poptype(ids);
3066 auto strata = state.world.pop_type_get_strata(ptype);
3069 if(promoted_type == ptype) {
3070 promotion_chance = 0.0f;
3071 }
else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
3072 promotion_chance += promotion_bonus;
3073 }
else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
3074 demotion_chance += promotion_bonus;
3078 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f)
3081 float current_size = state.world.pop_get_size(ids);
3083 bool promoting = promotion_chance >= demotion_chance;
3084 return std::min(current_size, promoting
3086 : (std::ceil(demotion_chance * state.defines.promotion_scale * current_size)));
3090 pbuf.
update(state.world.pop_size());
3099 pbuf.amounts.set(ids, 0.0f);
3100 auto loc = state.world.pop_get_province_from_pop_location(ids);
3101 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3102 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);
3105 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float assimilation_chance) {
3111 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
3115 if(state.world.pop_get_is_primary_or_accepted_culture(p))
3119 if(state.world.province_get_is_colonial(location) && province::is_overseas(state, location))
3122 if(state.world.province_get_dominant_culture(location) == state.world.pop_get_culture(p))
3131 float current_size = state.world.pop_get_size(p);
3133 state.defines.assimilation_scale *
3134 std::max(0.0f, (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f)) *
3135 std::max(0.0f, (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f)) *
3136 assimilation_chance * current_size;
3144 auto pc = state.world.pop_get_culture(p);
3146 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
3147 base_amount /= 10.0f;
3155 for(auto core : state.world.province_get_core(location)) {
3156 if(core.get_identity().get_primary_culture() == pc) {
3157 base_amount /= 100.0f;
3167 if(base_amount >= 0.001f) {
3168 auto transfer_amount = std::min(current_size, std::ceil(base_amount));
3169 pbuf.amounts.set(p, transfer_amount);
3172 ids, loc, owners, assimilation_chances);
3177 auto location = state.world.pop_get_province_from_pop_location(ids);
3178 auto owner = state.world.province_get_nation_from_province_ownership(location);
3182 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
3186 if(state.world.pop_get_is_primary_or_accepted_culture(ids))
3193 float current_size = state.world.pop_get_size(ids);
3195 state.defines.assimilation_scale *
3196 std::max(0.0f, (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f)) *
3197 std::max(0.0f, (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f)) *
3198 assimilation_chances * current_size;
3206 auto pc = state.world.pop_get_culture(ids);
3207 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
3208 base_amount /= 10.0f;
3217 for(
auto core : state.world.province_get_core(location)) {
3218 if(core.get_identity().get_primary_culture() == pc) {
3219 base_amount /= 100.0f;
3229 if(base_amount >= 0.001f) {
3230 return std::min(current_size, std::ceil(base_amount));
3246 auto weights_buffer = state.world.province_make_vectorizable_float_buffer();
3247 float total_weight = 0.0f;
3249 auto pt = state.world.pop_get_poptype(p);
3250 auto modifier = state.world.pop_type_get_migration_target(pt);
3251 auto modifier_fn = state.world.pop_type_get_migration_target_fn(pt);
3253 return dcon::province_id{};
3255 bool limit_to_capitals = state.world.pop_type_get_state_capital_only(pt);
3256 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3257 if(loc.get_province().get_is_colonial() ==
false) {
3258 if(!limit_to_capitals || loc.get_province().get_state_membership().get_capital().id == loc.get_province().id) {
3259 float weight = 0.0f;
3261 using ftype = float(*)(int32_t, int32_t);
3262 ftype fn = (ftype)modifier_fn;
3263 float llvm_result = fn(loc.get_province().id.index(), p.index());
3264#ifdef CHECK_LLVM_RESULTS
3266 assert(llvm_result == interp_result);
3268 weight = std::max(0.0f, llvm_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3271 weight = std::max(0.0f, interp_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3275 weights_buffer.set(loc.get_province(), weight);
3276 total_weight += weight;
3282 if(total_weight <= 0.0f)
3283 return dcon::province_id{};
3286 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3287 rvalue -= weights_buffer.get(loc.get_province()) / total_weight;
3289 return loc.get_province();
3293 return dcon::province_id{};
3301 auto weights_buffer = state.world.province_make_vectorizable_float_buffer();
3302 float total_weight = 0.0f;
3304 auto modifier = state.world.pop_type_get_migration_target(state.world.pop_get_poptype(p));
3305 auto modifier_fn = state.world.pop_type_get_migration_target_fn(state.world.pop_get_poptype(p));
3307 return dcon::province_id{};
3309 auto overseas_culture = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
3310 auto home_continent = state.world.province_get_continent(state.world.pop_get_province_from_pop_location(p));
3312 bool limit_to_capitals = state.world.pop_type_get_state_capital_only(state.world.pop_get_poptype(p));
3313 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3314 if(loc.get_province().get_is_colonial() ==
true) {
3315 if((overseas_culture || loc.get_province().get_continent() == home_continent) &&
3316 (!limit_to_capitals || loc.get_province().get_state_membership().get_capital().id == loc.get_province().id)) {
3318 float weight = 0.0f;
3320 using ftype = float(*)(int32_t, int32_t);
3321 ftype fn = (ftype)modifier_fn;
3322 float llvm_result = fn(loc.get_province().id.index(), p.index());
3323#ifdef CHECK_LLVM_RESULTS
3325 assert(llvm_result == interp_result);
3327 weight = std::max(0.0f, llvm_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3330 weight = std::max(0.0f, interp_result * (loc.get_province().get_modifier_values(sys::provincial_mod_offsets::immigrant_attract) + 1.0f));
3334 if(!limit_to_capitals || loc.get_province().get_state_membership().get_capital().id == loc.get_province().id) {
3335 weights_buffer.set(loc.get_province(), weight);
3336 total_weight += weight;
3343 if(total_weight <= 0.0f)
3344 return dcon::province_id{};
3347 for(
auto loc : state.world.nation_get_province_ownership(n)) {
3348 rvalue -= weights_buffer.get(loc.get_province()) / total_weight;
3350 return loc.get_province();
3354 return dcon::province_id{};
3369 auto pt = state.world.pop_get_poptype(p);
3370 auto modifier = state.world.pop_type_get_country_migration_target(pt);
3371 auto modifier_fn = state.world.pop_type_get_country_migration_target_fn(pt);
3373 return dcon::nation_id{};
3375 dcon::nation_id top_nations[3] = {dcon::nation_id{}, dcon::nation_id{}, dcon::nation_id{}};
3376 float top_weights[3] = {0.0f, 0.0f, 0.0f};
3378 auto home_continent = state.world.province_get_continent(state.world.pop_get_province_from_pop_location(p));
3380 state.world.for_each_nation([&](dcon::nation_id inner) {
3381 if(state.world.nation_get_owned_province_count(inner) == 0)
3383 if(state.world.nation_get_is_civilized(inner) ==
false)
3387 if(state.world.province_get_continent(state.world.nation_get_capital(inner)) == home_continent &&
3388 !state.world.get_nation_adjacency_by_nation_adjacency_pair(owner, inner)) {
3392 float weight = 0.0f;
3394 using ftype = float(*)(int32_t, int32_t);
3395 ftype fn = (ftype)modifier_fn;
3396 float llvm_result = fn(inner.index(), p.index());
3397#ifdef CHECK_LLVM_RESULTS
3398 float interp_result = trigger::evaluate_multiplicative_modifier(state, modifier, trigger::to_generic(inner), trigger::to_generic(p), 0);
3399 assert( llvm_result == interp_result);
3401 weight = std::max(0.0f, llvm_result * (state.world.nation_get_modifier_values(inner, sys::national_mod_offsets::global_immigrant_attract) + 1.0f));
3403 float interp_result = trigger::evaluate_multiplicative_modifier(state, modifier, trigger::to_generic(inner), trigger::to_generic(p), 0);
3404 weight = std::max(0.0f, interp_result * (state.world.nation_get_modifier_values(inner, sys::national_mod_offsets::global_immigrant_attract) + 1.0f));
3407 if(weight > top_weights[2]) {
3408 top_weights[2] = weight;
3409 top_nations[2] = inner;
3410 if(top_weights[2] > top_weights[1]) {
3411 std::swap(top_weights[1], top_weights[2]);
3412 std::swap(top_nations[1], top_nations[2]);
3414 if(top_weights[1] > top_weights[0]) {
3415 std::swap(top_weights[1], top_weights[0]);
3416 std::swap(top_nations[1], top_nations[0]);
3421 float total_weight = top_weights[0] + top_weights[1] + top_weights[2];
3422 if(total_weight <= 0.0f)
3423 return dcon::nation_id{};
3427 rvalue -= top_weights[i] / total_weight;
3429 return top_nations[i];
3433 return dcon::nation_id{};
3439 pbuf.
update(state.world.pop_size());
3442 pbuf.amounts.set(ids, 0.0f);
3449 auto loc = state.world.pop_get_province_from_pop_location(ids);
3450 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3451 auto pop_sizes = state.world.pop_get_size(ids);
3452 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;
3455 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float amount, float pop_size) {
3460 if(state.world.province_get_is_colonial(location))
3462 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
3465 auto dest = impl::get_province_target_in_nation(state, owner, p);
3470 pbuf.amounts.set(p, std::min(pop_size, std::ceil(amount)));
3472 pbuf.destinations.set(p, dest);
3474 ids, loc, owners, amounts, pop_sizes);
3480 auto loc = state.world.pop_get_province_from_pop_location(ids);
3482 if(state.world.province_get_is_colonial(loc))
3484 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
3487 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3488 auto pop_sizes = state.world.pop_get_size(ids);
3490 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;
3496 auto pop_size = state.world.pop_get_size(ids);
3497 return std::min(pop_size, std::ceil(amount));
3501 pbuf.
update(state.world.pop_size());
3504 pbuf.amounts.set(ids, 0.0f);
3513 auto loc = state.world.pop_get_province_from_pop_location(ids);
3514 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3515 auto pop_sizes = state.world.pop_get_size(ids);
3516 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) *
3518 ve::max((state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f), 0.0f) *
3519 ve::max((state.world.nation_get_modifier_values(owners, sys::national_mod_offsets::colonial_migration) + 1.0f), 0.0f) *
3520 state.defines.immigration_scale;
3523 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float amount, float pop_size) {
3528 if(state.world.nation_get_is_colonial_nation(owner) == false)
3530 auto pt = state.world.pop_get_poptype(p);
3531 if(state.world.pop_type_get_strata(pt) == uint8_t(culture::pop_strata::rich))
3533 if(state.world.province_get_is_colonial(location))
3535 if(pt == state.culture_definitions.slaves || pt == state.culture_definitions.primary_factory_worker ||
3536 pt == state.culture_definitions.secondary_factory_worker)
3542 pbuf.amounts.set(p, std::min(pop_size, std::ceil(amount)));
3545 auto dest = impl::get_colonial_province_target_in_nation(state, owner, p);
3546 pbuf.destinations.set(p, dest);
3548 ids, loc, owners, amounts, pop_sizes);
3553 auto loc = state.world.pop_get_province_from_pop_location(ids);
3554 auto owner = state.world.province_get_nation_from_province_ownership(loc);
3556 if(state.world.nation_get_is_colonial_nation(owner) ==
false)
3558 auto pt = state.world.pop_get_poptype(ids);
3561 if(state.world.province_get_is_colonial(loc))
3563 if(pt == state.culture_definitions.slaves || pt == state.culture_definitions.primary_factory_worker ||
3564 pt == state.culture_definitions.secondary_factory_worker)
3568 auto pop_sizes = state.world.pop_get_size(ids);
3572 * std::max((state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f), 0.0f)
3573 * std::max((state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::colonial_migration) + 1.0f), 0.0f)
3574 * state.defines.immigration_scale;
3579 auto pop_size = state.world.pop_get_size(ids);
3580 return std::min(pop_size, std::ceil(amounts));
3584 pbuf.
update(state.world.pop_size());
3587 pbuf.amounts.set(ids, 0.0f);
3596 auto loc = state.world.pop_get_province_from_pop_location(ids);
3597 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3598 auto pop_sizes = state.world.pop_get_size(ids);
3599 auto impush = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
3600 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);
3601 auto amounts = trigger_amount
3603 * ve::max(impush, 0.0f)
3604 * ve::max(impush, 1.0f)
3605 * state.defines.immigration_scale;
3608 [&](dcon::pop_id p, dcon::province_id location, dcon::nation_id owner, float amount, float pop_size) {
3614 if(state.world.nation_get_is_civilized(owner) == false)
3616 if(state.world.province_get_is_colonial(location))
3618 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
3620 if(state.world.culture_group_get_is_overseas(
3621 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p))) == false) {
3628 pbuf.amounts.set(p, std::min(pop_size, std::ceil(amount)));
3631 auto ndest = impl::get_immigration_target(state, owner, p, state.current_date);
3632 auto dest = impl::get_province_target_in_nation(state, ndest, p);
3634 pbuf.destinations.set(p, dest);
3636 ids, loc, owners, amounts, pop_sizes);
3641 auto sz = state.world.nation_size();
3642 national_amounts.resize(sz);
3643 for(
auto& v : national_amounts) {
3647 auto ymd_date = state.current_date.to_ymd(state.start_date);
3652 for(
auto ids : state.world.in_pop) {
3653 auto loc = state.world.pop_get_province_from_pop_location(ids);
3654 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3656 auto section =
uint64_t(ids.id.index()) / 16;
3657 auto tranche = int32_t(section / days_in_month);
3658 auto day_of_month = tranche - 10;
3659 if(day_of_month <= 0)
3660 day_of_month += days_in_month;
3661 int32_t day_adjustment = day_of_month - int32_t(ymd_date.day);
3663 if(est_amount > 0.0f) {
3664 auto target = impl::get_immigration_target(state, owners, ids, state.current_date + day_adjustment);
3666 if(target &&
uint32_t(target.index()) < sz) {
3667 national_amounts[
uint32_t(target.index())] -= est_amount;
3669 }
else if(target == n) {
3670 if(
uint32_t(owners.index()) < sz) {
3671 national_amounts[
uint32_t(owners.index())] += est_amount;
3680 auto loc = state.world.pop_get_province_from_pop_location(ids);
3681 auto owners = state.world.province_get_nation_from_province_ownership(loc);
3683 if(state.world.nation_get_is_civilized(owners) ==
false)
3685 if(state.world.province_get_is_colonial(loc))
3687 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
3689 if(state.world.culture_group_get_is_overseas(
3690 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(ids))) ==
false) {
3694 auto pop_sizes = state.world.pop_get_size(ids);
3695 auto impush = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
3697 auto amounts = trigger_result * pop_sizes * std::max(impush, 0.0f) * std::max(impush, 1.0f) * state.defines.immigration_scale;
3702 return std::min(pop_sizes, std::ceil(amounts));
3707 dcon::pop_type_id ptid,
float l) {
3708 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(loc));
3709 if(is_mine && ptid == state.culture_definitions.farmers) {
3710 ptid = state.culture_definitions.laborers;
3711 }
else if(!is_mine && ptid == state.culture_definitions.laborers) {
3712 ptid = state.culture_definitions.farmers;
3715 for(
auto pl : state.world.province_get_pop_location(loc)) {
3716 if(pl.get_pop().get_culture() == cid && pl.get_pop().get_religion() == rid && pl.get_pop().get_poptype() == ptid) {
3717 return pl.get_pop();
3720 auto np = fatten(state.world, state.world.create_pop());
3721 state.world.force_create_pop_location(np, loc);
3722 np.set_culture(cid);
3723 np.set_religion(rid);
3724 np.set_poptype(ptid);
3727 auto n = state.world.province_get_nation_from_province_ownership(loc);
3728 if(state.world.nation_get_primary_culture(n) == cid) {
3729 np.set_is_primary_or_accepted_culture(
true);
3731 if(state.world.nation_get_accepted_cultures(n, cid) ==
true) {
3732 np.set_is_primary_or_accepted_culture(
true);
3738 float totals = 0.0f;
3739 static auto buf = state.world.ideology_make_vectorizable_float_buffer();
3741 state.world.for_each_ideology([&](dcon::ideology_id i) {
3743 if(state.world.ideology_get_enabled(i)) {
3744 auto ptrigger = state.world.pop_type_get_ideology(ptid, i);
3745 auto const i_key = pop_demographics::to_key(state, i);
3746 auto owner = nations::owner_of_pop(state, np);
3747 if(state.world.ideology_get_is_civilized_only(i)) {
3748 if(state.world.nation_get_is_civilized(owner)) {
3749 auto amount = ptrigger ? std::max(0.0f, trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(np.id),
3750 trigger::to_generic(owner), 0)) : 0.0f;
3755 auto amount = ptrigger ? std::max(0.0f, trigger::evaluate_multiplicative_modifier(state, ptrigger, trigger::to_generic(np.id),
3756 trigger::to_generic(owner), 0)) : 0.0f;
3763 state.world.for_each_ideology([&](dcon::ideology_id i) {
3770 float totals = 0.0f;
3771 static auto buf = state.world.issue_option_make_vectorizable_float_buffer();
3773 state.world.for_each_issue_option([&](dcon::issue_option_id iid) {
3774 auto opt = fatten(state.world, iid);
3775 auto allow = opt.get_allow();
3776 auto parent_issue = opt.get_parent_issue();
3781 auto has_modifier = is_social_issue || is_political_issue;
3783 is_social_issue ? sys::national_mod_offsets::social_reform_desire : sys::national_mod_offsets::political_reform_desire;
3786 auto current_issue_setting = state.world.nation_get_issues(owner, parent_issue);
3787 auto allowed_by_owner =
3788 (state.world.nation_get_is_civilized(owner) || is_party_issue) &&
3789 (!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));
3790 auto owner_modifier = has_modifier ? (state.world.nation_get_modifier_values(owner, modifier_key) + 1.0f) : 1.0f;
3792 if(allowed_by_owner) {
3793 if(
auto mtrigger = state.world.pop_type_get_issues(ptid, iid); mtrigger) {
3795 buf.set(iid, amount);
3801 state.world.for_each_issue_option([&](dcon::issue_option_id i) {
3814 [&](dcon::pop_id p) {
3815 if(pbuf.amounts.get(p) > 0.0f && pbuf.types.get(p)) {
3816 auto target_pop = impl::find_or_make_pop(state, state.world.pop_get_province_from_pop_location(p),
3817 state.world.pop_get_culture(p), state.world.pop_get_religion(p), pbuf.types.get(p), pop_demographics::get_literacy(state, p));
3818 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3819 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3827 auto exec_fn = [&](
auto ids) {
3828 auto locs = state.world.pop_get_province_from_pop_location(ids);
3829 ve::apply([&](dcon::pop_id p, dcon::province_id l, dcon::culture_id dac) {
3830 if(pbuf.
amounts.get(p) > 0.0f) {
3832 auto cul = dac ? dac : state.world.province_get_dominant_culture(l);
3834 ? state.world.nation_get_religion(nations::owner_of_pop(state, p))
3835 : state.world.province_get_dominant_religion(l);
3836 assert(state.world.pop_get_poptype(p));
3837 auto target_pop = impl::find_or_make_pop(state, l, cul, rel, state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3838 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3839 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3842 ids, locs, state.world.province_get_dominant_accepted_culture(locs));
3850 [&](dcon::pop_id p) {
3851 if(pbuf.amounts.get(p) > 0.0f && pbuf.destinations.get(p)) {
3852 assert(state.world.pop_get_poptype(p));
3853 auto target_pop = impl::find_or_make_pop(state, pbuf.destinations.get(p), state.world.pop_get_culture(p),
3854 state.world.pop_get_religion(p), state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3855 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3856 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3857 state.world.province_get_daily_net_migration(state.world.pop_get_province_from_pop_location(p)) -=
3858 pbuf.amounts.get(p);
3859 state.world.province_get_daily_net_migration(pbuf.destinations.get(p)) += pbuf.amounts.get(p);
3869 [&](dcon::pop_id p) {
3870 if(pbuf.amounts.get(p) > 0.0f && pbuf.destinations.get(p)) {
3871 assert(state.world.pop_get_poptype(p));
3872 auto target_pop = impl::find_or_make_pop(state, pbuf.destinations.get(p), state.world.pop_get_culture(p),
3873 state.world.pop_get_religion(p), state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3874 state.world.pop_get_size(p) -= pbuf.amounts.get(p);
3875 state.world.pop_get_size(target_pop) += pbuf.amounts.get(p);
3876 state.world.province_get_daily_net_migration(state.world.pop_get_province_from_pop_location(p)) -=
3877 pbuf.amounts.get(p);
3878 state.world.province_get_daily_net_migration(pbuf.destinations.get(p)) += pbuf.amounts.get(p);
3888 [&](dcon::pop_id p) {
3889 auto amount = pbuf.amounts.get(p);
3890 if(amount > 0.0f && pbuf.destinations.get(p)) {
3891 assert(state.world.pop_get_poptype(p));
3892 auto target_pop = impl::find_or_make_pop(state, pbuf.destinations.get(p), state.world.pop_get_culture(p),
3893 state.world.pop_get_religion(p), state.world.pop_get_poptype(p), pop_demographics::get_literacy(state, p));
3895 state.world.pop_get_size(p) -= amount;
3896 state.world.pop_get_size(target_pop) += amount;
3897 state.world.province_get_daily_net_immigration(state.world.pop_get_province_from_pop_location(p)) -= amount;
3898 state.world.province_get_daily_net_immigration(pbuf.destinations.get(p)) += amount;
3899 state.world.province_set_last_immigration(pbuf.destinations.get(p), state.current_date);
3908 for(
auto last = state.world.pop_size(); last-- > 0;) {
3909 dcon::pop_id m{dcon::pop_id::value_base_t(last)};
3910 if(state.world.pop_get_size(m) < 1.0f) {
3911 state.world.delete_pop(m);
3918 for(
auto last = state.world.pop_size(); last-- > 0;) {
3919 dcon::pop_id m{ dcon::pop_id::value_base_t(last) };
3920 if(state.world.pop_get_size(m) < 20.0f) {
3921 state.world.delete_pop(m);
3944 auto poor_score = (pln + pen + plun) / pp;
3945 auto middle_score = (mln + men + mlun) / mp;
3946 auto rich_score = (rln + ren + rlun) / rp;
3948 auto finalscore = (poor_score * pp + middle_score * mp + rich_score * rp) * 33 / p;
3954 if(state.world.pop_get_size(pop_id) >= amount) {
3955 state.world.pop_get_size(pop_id) -= amount;
3957 state.world.pop_get_size(pop_id) = 0;
#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)
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)
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_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_social_reform_desire(sys::state &state, dcon::pop_id p, float v)
uint32_t size(sys::state const &state)
float get_employment(sys::state const &state, dcon::pop_id p)
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 set_luxury_needs(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)
uint16_t to_pu16(float v)
float from_pu8(uint8_t v)
void set_consciousness(sys::state &state, dcon::pop_id p, float v)
void set_everyday_needs(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)
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, dcon::pop_id p, float v)
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)
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