3#include "dcon_generated.hpp"
15template auto is_overseas<ve::tagged_vector<dcon::province_id>>(
sys::state const&, ve::tagged_vector<dcon::province_id>);
19 auto owners = state.world.province_get_nation_from_province_ownership(ids);
20 auto owner_cap = state.world.nation_get_capital(owners);
21 return (state.world.province_get_continent(ids) != state.world.province_get_continent(owner_cap)) &&
22 (state.world.province_get_connected_region_id(ids) != state.world.province_get_connected_region_id(owner_cap));
26 auto it = state.world.get_nation_adjacency_by_nation_adjacency_pair(a, b);
30 if(!state.adjacency_data_out_of_date)
33 state.adjacency_data_out_of_date =
false;
35 state.world.nation_adjacency_resize(0);
37 state.world.for_each_province([&](dcon::province_id
id) { state.world.province_set_connected_region_id(
id, 0); });
39 static std::vector<dcon::province_id> to_fill_list;
40 uint16_t current_fill_id = 0;
41 state.province_definitions.connected_region_is_coastal.clear();
43 to_fill_list.reserve(state.world.province_size());
45 for(int32_t i = state.province_definitions.first_sea_province.index(); i-- > 0;) {
46 dcon::province_id
id{dcon::province_id::value_base_t(i)};
47 if(state.world.province_get_connected_region_id(
id) == 0) {
50 bool found_coast =
false;
52 to_fill_list.push_back(
id);
54 while(!to_fill_list.empty()) {
55 auto current_id = to_fill_list.back();
56 to_fill_list.pop_back();
58 found_coast = found_coast || state.world.province_get_is_coast(current_id);
60 state.world.province_set_connected_region_id(current_id, current_fill_id);
61 for(
auto rel : state.world.province_get_province_adjacency(current_id)) {
64 auto owner_a = rel.get_connected_provinces(0).get_nation_from_province_ownership();
65 auto owner_b = rel.get_connected_provinces(1).get_nation_from_province_ownership();
66 if(owner_a == owner_b) {
67 if(rel.get_connected_provinces(0).get_connected_region_id() == 0)
68 to_fill_list.push_back(rel.get_connected_provinces(0));
69 if(rel.get_connected_provinces(1).get_connected_region_id() == 0)
70 to_fill_list.push_back(rel.get_connected_provinces(1));
72 state.world.try_create_nation_adjacency(owner_a, owner_b);
78 state.province_definitions.connected_region_is_coastal.push_back(found_coast);
86 state.province_ownership_changed.store(
true, std::memory_order::release);
90 auto trad_cap = state.world.national_identity_get_capital(state.world.nation_get_identity_from_identity_holder(n));
91 if(state.world.province_get_nation_from_province_ownership(trad_cap) == n) {
94 dcon::province_id best_choice;
95 for(
auto prov : state.world.nation_get_province_ownership(n)) {
98 prov.get_province().get_is_owner_core() == state.world.province_get_is_owner_core(best_choice)) {
99 best_choice = prov.get_province().id;
100 }
else if(prov.get_province().get_is_owner_core() && !state.world.province_get_is_owner_core(best_choice)) {
101 best_choice = prov.get_province().id;
108 auto old_con = state.world.province_get_nation_from_province_control(p);
110 state.world.province_set_last_control_change(p, state.current_date);
111 auto rc = state.world.province_get_rebel_faction_from_province_rebel_control(p);
112 auto owner = state.world.province_get_nation_from_province_ownership(p);
114 state.world.nation_get_rebel_controlled_count(owner) -= uint16_t(1);
116 state.world.nation_get_central_rebel_controlled(owner) -= uint16_t(1);
120 if(old_con == owner) {
121 state.world.nation_get_occupied_count(owner) += uint16_t(1);
122 if(state.world.province_get_is_blockaded(p) && !
is_overseas(state, p)) {
123 state.world.nation_get_central_blockaded(owner) -= uint16_t(1);
125 }
else if(n == owner) {
126 state.world.nation_get_occupied_count(owner) -= uint16_t(1);
129 state.world.province_set_rebel_faction_from_province_rebel_control(p, dcon::rebel_faction_id{});
130 state.world.province_set_nation_from_province_control(p, n);
131 state.military_definitions.pending_blackflag_update =
true;
136 auto old_con = state.world.province_get_rebel_faction_from_province_rebel_control(p);
138 state.world.province_set_last_control_change(p, state.current_date);
139 auto owner = state.world.province_get_nation_from_province_ownership(p);
140 if(!old_con && owner) {
141 state.world.nation_get_rebel_controlled_count(owner) += uint16_t(1);
143 state.world.nation_get_central_rebel_controlled(owner) += uint16_t(1);
146 if(owner && state.world.province_get_nation_from_province_control(p) == owner) {
147 state.world.nation_get_occupied_count(owner) += uint16_t(1);
148 if(state.world.province_get_is_blockaded(p) && !
is_overseas(state, p)) {
149 state.world.nation_get_central_blockaded(owner) -= uint16_t(1);
152 state.world.province_set_rebel_faction_from_province_rebel_control(p, rf);
153 state.world.province_set_nation_from_province_control(p, dcon::nation_id{});
154 state.military_definitions.pending_blackflag_update =
true;
160 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_central_province_count(ids, ve::int_vector()); });
161 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_central_blockaded(ids, ve::int_vector()); });
162 state.world.execute_serial_over_nation(
163 [&](
auto ids) { state.world.nation_set_central_rebel_controlled(ids, ve::int_vector()); });
164 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_rebel_controlled_count(ids, ve::int_vector()); });
165 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_central_ports(ids, ve::int_vector()); });
166 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_central_crime_count(ids, ve::int_vector()); });
167 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_total_ports(ids, ve::int_vector()); });
168 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_occupied_count(ids, ve::int_vector()); });
169 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_owned_state_count(ids, ve::int_vector()); });
170 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_is_colonial_nation(ids, ve::mask_vector()); });
174 for(
auto n : state.world.in_nation) {
175 auto orange = n.get_province_ownership();
176 n.set_owned_province_count(uint16_t(orange.end() - orange.begin()));
179 for(int32_t i = 0; i < state.province_definitions.first_sea_province.index(); ++i) {
180 dcon::province_id pid{dcon::province_id::value_base_t(i)};
182 auto owner = state.world.province_get_nation_from_province_ownership(pid);
184 bool owner_core =
false;
185 for(
auto c : state.world.province_get_core(pid)) {
186 if(c.get_identity().get_nation_from_identity_holder() == owner) {
191 state.world.province_set_is_owner_core(pid, owner_core);
193 state.world.province_set_is_owner_core(pid,
false);
197 for(
auto n : state.world.in_nation) {
198 if(n.get_capital().get_nation_from_province_ownership() != n) {
203 for(int32_t i = 0; i < state.province_definitions.first_sea_province.index(); ++i) {
204 dcon::province_id pid{dcon::province_id::value_base_t(i)};
206 auto owner = state.world.province_get_nation_from_province_ownership(pid);
209 bool reb_controlled = bool(state.world.province_get_rebel_faction_from_province_rebel_control(pid));
212 state.world.nation_get_rebel_controlled_count(owner) += uint16_t(1);
214 if(state.world.province_get_is_coast(pid)) {
215 state.world.nation_get_total_ports(owner) += uint16_t(1);
217 if(
auto c = state.world.province_get_nation_from_province_control(pid);
bool(c) && c != owner) {
218 state.world.nation_get_occupied_count(owner) += uint16_t(1);
220 if(state.world.province_get_is_colonial(pid)) {
221 state.world.nation_set_is_colonial_nation(owner,
true);
224 state.world.nation_get_central_province_count(owner) += uint16_t(1);
227 state.world.nation_get_central_blockaded(owner) += uint16_t(1);
229 if(state.world.province_get_is_coast(pid)) {
230 state.world.nation_get_central_ports(owner) += uint16_t(1);
233 state.world.nation_get_central_rebel_controlled(owner) += uint16_t(1);
235 if(state.world.province_get_crime(pid)) {
236 state.world.nation_get_central_crime_count(owner) += uint16_t(1);
241 state.world.for_each_state_instance([&](dcon::state_instance_id s) {
242 auto owner = state.world.state_instance_get_nation_from_state_ownership(s);
243 state.world.nation_get_owned_state_count(owner) += uint16_t(1);
245 for(
auto prv : state.world.state_definition_get_abstract_state_membership(state.world.state_instance_get_definition(s))) {
246 if(state.world.province_get_nation_from_province_ownership(prv.get_province()) == owner) {
247 p = prv.get_province().id;
251 state.world.state_instance_set_capital(s, p);
256 if(!state.national_cached_values_out_of_date)
259 state.national_cached_values_out_of_date =
false;
261 restore_cached_values(state);
265 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_central_blockaded(ids, ve::int_vector()); });
266 for(int32_t i = 0; i < state.province_definitions.first_sea_province.index(); ++i) {
267 dcon::province_id pid{ dcon::province_id::value_base_t(i) };
269 auto owner = state.world.province_get_nation_from_province_ownership(pid);
273 state.world.nation_get_central_blockaded(owner) += uint16_t(1);
281 for(int32_t i = 0; i < state.province_definitions.first_sea_province.index(); ++i) {
282 dcon::province_id pid{dcon::province_id::value_base_t(i)};
284 for(
auto adj : state.world.province_get_province_adjacency(pid)) {
287 state.world.province_set_is_coast(pid,
true);
293 for(
auto si : state.world.in_state_instance) {
296 state.world.state_instance_set_naval_base_is_taken(si,
true);
298 for(
auto pc : state.world.province_get_province_building_construction(p)) {
299 if(pc.get_type() == uint8_t(economy::province_building_type::naval_base))
300 state.world.state_instance_set_naval_base_is_taken(si, true);
306 restore_cached_values(state);
310 for(
auto pb : state.world.province_get_province_building_construction(
id)) {
318 if(n != state.world.province_get_nation_from_province_control(
id))
325 int32_t min_build_railroad =
326 int32_t(state.world.province_get_modifier_values(
id, sys::provincial_mod_offsets::min_build_railroad));
331 auto owner = state.world.province_get_nation_from_province_ownership(
id);
333 if(owner != state.world.province_get_nation_from_province_control(
id))
339 if(state.world.nation_get_is_great_power(n) ==
false || state.world.nation_get_is_great_power(owner) ==
true)
341 if(state.world.nation_get_is_civilized(owner) ==
false)
344 auto rules = state.world.nation_get_combined_issue_rules(owner);
351 auto rules = state.world.nation_get_combined_issue_rules(n);
358 int32_t min_build_railroad =
359 int32_t(state.world.province_get_modifier_values(
id, sys::provincial_mod_offsets::min_build_railroad));
364 for(
auto pb : state.world.province_get_province_building_construction(
id)) {
371 if(state.world.province_get_nation_from_province_ownership(
id) != n)
373 if(state.world.province_get_nation_from_province_ownership(
id) != state.world.province_get_nation_from_province_control(
id))
380 int32_t min_build = int32_t(state.world.province_get_modifier_values(
id, sys::provincial_mod_offsets::min_build_fort));
385 for(
auto pb : state.world.province_get_province_building_construction(
id)) {
392 if(state.world.province_get_nation_from_province_ownership(
id) != n)
394 if(state.world.province_get_is_coast(
id) ==
false)
396 if(state.world.province_get_nation_from_province_ownership(
id) != state.world.province_get_nation_from_province_control(
id))
401 auto si = state.world.province_get_state_membership(
id);
405 int32_t min_build = int32_t(state.world.province_get_modifier_values(
id, sys::provincial_mod_offsets::min_build_naval_base));
407 return (max_local_lvl - current_lvl - min_build > 0) && (current_lvl > 0 || !si.get_naval_base_is_taken()) && !
has_naval_base_being_built(state,
id);
411 for(
auto pb : state.world.province_get_province_building_construction(
id)) {
419 auto owner = state.world.province_get_nation_from_province_ownership(
id);
421 if(owner != state.world.province_get_nation_from_province_control(
id))
427 if(state.world.nation_get_is_great_power(n) ==
false || state.world.nation_get_is_great_power(owner) ==
true)
429 if(state.world.nation_get_is_civilized(owner) ==
false)
432 auto rules = state.world.nation_get_combined_issue_rules(owner);
439 auto rules = state.world.nation_get_combined_issue_rules(n);
446 int32_t current_lvl = state.world.province_get_building_level(
id,
uint8_t(t));
447 int32_t max_local_lvl = state.world.nation_get_max_building_level(n,
uint8_t(t));
448 int32_t min_build = int32_t(state.world.province_get_modifier_values(
id, sys::provincial_mod_offsets::min_build_railroad));
453 return bool(
dcon::fatten(state.world,
id).get_nation_from_province_ownership());
456 auto owner = state.world.province_get_nation_from_province_ownership(
id);
460 auto owner = state.world.province_get_nation_from_province_ownership(
id);
464 auto owner = state.world.province_get_nation_from_province_ownership(
id);
471 return state.world.province_get_rgo_full_profit(
id);
474 auto n = state.world.province_get_nation_from_province_ownership(
id);
475 return state.world.province_get_rgo_actual_production_per_good(
id, c);
478 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(prov_id));
479 auto sz = state.world.province_get_rgo_size(prov_id);
481 auto n =
dcon::fatten(state.world, prov_id).get_nation_from_province_ownership();
482 auto bonus = state.world.province_get_modifier_values(prov_id,
483 is_mine ? sys::provincial_mod_offsets::mine_rgo_size : sys::provincial_mod_offsets::farm_rgo_size) +
484 state.world.nation_get_modifier_values(n,
485 is_mine ? sys::national_mod_offsets::mine_rgo_size : sys::national_mod_offsets::farm_rgo_size) +
486 state.world.nation_get_rgo_size(n, state.world.province_get_rgo(prov_id)) + 1.0f;
493 for(
auto po : state.world.province_get_pop_location(p)) {
494 if(po.get_pop().get_is_primary_or_accepted_culture() &&
495 po.get_pop().get_poptype() == state.culture_definitions.bureaucrat) {
496 bsum += po.get_pop().get_size();
504 auto owner = state.world.state_instance_get_nation_from_state_ownership(
id);
506 auto admin_mod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::administrative_efficiency_modifier);
508 float issue_sum = 0.0f;
509 for(
auto i : state.culture_definitions.social_issues) {
510 issue_sum += state.world.issue_option_get_administrative_multiplier(state.world.nation_get_issues(owner, i));
512 auto from_issues = issue_sum * state.defines.bureaucracy_percentage_increment + state.defines.max_bureaucracy_percentage;
513 float non_core_effect = 0.0f;
516 if(!state.world.province_get_is_owner_core(p)) {
517 non_core_effect += state.defines.noncore_tax_penalty;
519 for(
auto po : state.world.province_get_pop_location(p)) {
520 if(po.get_pop().get_is_primary_or_accepted_culture() &&
521 po.get_pop().get_poptype() == state.culture_definitions.bureaucrat) {
522 bsum += po.get_pop().get_size();
529 ? std::clamp(admin_mod + non_core_effect + state.defines.base_country_admin_efficiency +
530 std::min(state.culture_definitions.bureaucrat_tax_efficiency * bsum / total_pop, 1.0f) / from_issues,
550 auto si = state.world.province_get_state_membership(
id);
551 auto owner = state.world.province_get_nation_from_province_ownership(
id);
554 (1 - state.defines.admin_efficiency_crimefight_percent) *
555 state.world.nation_get_administrative_efficiency(owner)) *
556 (state.defines.max_crimefight_percent - state.defines.min_crimefight_percent) +
557 state.defines.min_crimefight_percent;
568 return militancy / total_pop;
572 auto first = state.world.province_adjacency_get_connected_provinces(adj, 0);
574 return state.world.province_adjacency_get_connected_provinces(adj, 1);
586 return direct_distance(state, state.world.state_instance_get_capital(state_id), prov_id);
590 return sorting_distance(state, state.world.state_instance_get_capital(state_id), prov_id);
594 if(state.world.state_instance_get_capital(
id).get_is_colonial() ==
false)
600 if(bureaucrat_size / total_size >= state.defines.state_creation_admin_limit) {
601 auto owner = state.world.state_instance_get_nation_from_state_ownership(
id);
614 bool entirely_overseas =
true;
615 float prov_count = 0.0f;
620 if(entirely_overseas) {
621 auto owner = state.world.state_instance_get_nation_from_state_ownership(
id);
623 return state.defines.colonization_create_state_cost * prov_count * std::max(
distance / state.defines.colonization_colony_state_distance, 1.0f);
632 state.world.province_set_is_colonial(p,
false);
635 auto timed_modifiers = state.world.province_get_current_modifiers(p);
636 for(
uint32_t i = timed_modifiers.size(); i-- > 0;) {
637 if(bool(timed_modifiers[i].expiration)) {
638 timed_modifiers.remove_at(i);
645 state.defines.colony_to_state_prestige_gain *
646 (1.0f + state.world.nation_get_modifier_values(source, sys::national_mod_offsets::colonial_prestige)));
657 state.world.nation_set_is_colonial_nation(source,
false);
658 for(
auto p : state.world.nation_get_province_ownership(source)) {
659 if(p.get_province().get_is_colonial()) {
660 state.world.nation_set_is_colonial_nation(source,
true);
667 auto state_def = state.world.province_get_state_from_abstract_state_membership(
id);
668 auto old_si = state.world.province_get_state_membership(
id);
669 auto old_owner = state.world.province_get_nation_from_province_ownership(
id);
671 if(new_owner == old_owner)
674 state.adjacency_data_out_of_date =
true;
675 state.national_cached_values_out_of_date =
true;
677 bool state_is_new =
false;
678 dcon::state_instance_id new_si;
680 auto pmods = state.world.province_get_current_modifiers(
id);
683 bool will_be_colonial = state.world.province_get_is_colonial(
id)
684 || (old_owner && state.world.nation_get_is_civilized(old_owner) ==
false
685 && state.world.nation_get_is_civilized(new_owner) ==
true)
689 state.world.state_instance_set_naval_base_is_taken(old_si,
false);
691 for(
auto pc : state.world.province_get_province_building_construction(
id)) {
693 state.world.state_instance_set_naval_base_is_taken(old_si,
false);
700 for(
auto si : state.world.nation_get_state_ownership(new_owner)) {
701 if(si.get_state().get_definition().id == state_def) {
702 new_si = si.get_state().id;
706 bool was_slave_state = !old_owner || state.world.province_get_is_slave(
id);
708 new_si = state.world.create_state_instance();
709 state.world.state_instance_set_definition(new_si, state_def);
710 state.world.try_create_state_ownership(new_si, new_owner);
711 state.world.state_instance_set_capital(new_si,
id);
712 state.world.province_set_is_colonial(
id, will_be_colonial);
713 state.world.province_set_is_slave(
id,
false);
715 state.world.nation_set_is_colonial_nation(new_owner,
true);
717 state.world.state_instance_set_naval_base_is_taken(new_si,
true);
721 auto sc = state.world.state_instance_get_capital(new_si);
722 state.world.province_set_is_colonial(
id, state.world.province_get_is_colonial(sc));
723 state.world.province_set_is_slave(
id, state.world.province_get_is_slave(sc));
725 if(state.world.state_instance_get_naval_base_is_taken(new_si)) {
728 state.world.state_instance_set_naval_base_is_taken(new_si,
true);
732 if(was_slave_state) {
736 auto province_fac_range = state.world.province_get_factory_location(
id);
737 int32_t factories_in_province = int32_t(province_fac_range.end() - province_fac_range.begin());
739 int32_t factories_in_new_state = 0;
741 auto fac_range = state.world.province_get_factory_location(pr);
743 for(
const auto pfac : province_fac_range) {
744 for(int32_t i = 0; i < int32_t(fac_range.end() - fac_range.begin()); i++) {
745 const auto fac = *(fac_range.begin() + i);
746 if(fac.get_factory().get_building_type() == pfac.get_factory().get_building_type()) {
747 pfac.get_factory().get_level() += fac.get_factory().get_level();
748 state.world.delete_factory(fac.get_factory().id);
753 factories_in_new_state += int32_t(fac_range.end() - fac_range.begin());
756 auto excess_factories = std::min((factories_in_new_state + factories_in_province) - int32_t(state.defines.factories_per_state), factories_in_province);
757 while(excess_factories > 0) {
758 state.world.delete_factory((*(province_fac_range.begin() + excess_factories - 1)).get_factory().id);
762 state.world.province_set_state_membership(
id, new_si);
764 for(
auto p : state.world.province_get_pop_location(
id)) {
766 if(state.world.nation_get_primary_culture(new_owner) == p.get_pop().get_culture()) {
767 p.get_pop().set_is_primary_or_accepted_culture(
true);
770 if(state.world.nation_get_accepted_cultures(new_owner, p.get_pop().get_culture())) {
771 p.get_pop().set_is_primary_or_accepted_culture(
true);
774 p.get_pop().set_is_primary_or_accepted_culture(
false);
777 state.world.nation_get_owned_province_count(new_owner) += uint16_t(1);
779 state.world.province_set_state_membership(
id, dcon::state_instance_id{});
781 state.world.province_set_building_level(
id,
uint8_t(t),
uint8_t(0));
784 auto province_fac_range = state.world.province_get_factory_location(
id);
785 while(province_fac_range.begin() != province_fac_range.end()) {
786 state.world.delete_factory((*province_fac_range.begin()).get_factory().id);
789 for(
auto p : state.world.province_get_pop_location(
id)) {
790 p.get_pop().set_is_primary_or_accepted_culture(
false);
796 for(
auto p : state.world.province_get_pop_location(
id)) {
800 for(
const auto src : p.get_pop().get_regiment_source()) {
801 if(!src.get_regiment().get_army_from_army_membership().get_is_retreating()
802 && !src.get_regiment().get_army_from_army_membership().get_navy_from_army_transport()
803 && !src.get_regiment().get_army_from_army_membership().get_battle_from_army_battle_participation()
804 && !src.get_regiment().get_army_from_army_membership().get_controller_from_army_rebel_control()) {
805 auto new_u = fatten(state.world, state.world.create_army());
806 new_u.set_controller_from_army_control(new_owner);
807 src.get_regiment().set_army_from_army_membership(new_u);
810 src.get_regiment().set_strength(0.f);
814 auto regs = p.get_pop().get_regiment_source();
815 while(regs.begin() != regs.end()) {
816 state.world.delete_regiment_source(*(regs.begin()));
819 auto lc = p.get_pop().get_province_land_construction();
820 while(lc.begin() != lc.end()) {
821 state.world.delete_province_land_construction(*(lc.begin()));
826 state.world.province_set_nation_from_province_ownership(
id, new_owner);
827 state.world.province_set_rebel_faction_from_province_rebel_control(
id, dcon::rebel_faction_id{});
828 state.world.province_set_last_control_change(
id, state.current_date);
829 state.world.province_set_nation_from_province_control(
id, new_owner);
830 state.world.province_set_siege_progress(
id, 0.0f);
835 state.world.province_set_is_owner_core(
id,
836 bool(state.world.get_core_by_prov_tag_key(
id, state.world.nation_get_identity_from_identity_holder(new_owner))));
839 dcon::province_id a_province;
842 if(old_si == state.crisis_state)
844 state.world.delete_state_instance(old_si);
845 }
else if(state.world.state_instance_get_capital(old_si) ==
id) {
846 state.world.state_instance_set_capital(old_si, a_province);
851 state.world.nation_get_owned_province_count(old_owner) -= uint16_t(1);
852 auto lprovs = state.world.nation_get_province_ownership(old_owner);
853 if(lprovs.begin() == lprovs.end()) {
854 state.world.nation_set_marked_for_gc(old_owner,
true);
859 state.world.province_set_naval_rally_point(
id,
false);
860 state.world.province_set_land_rally_point(
id,
false);
866 auto rng = state.world.province_get_province_building_construction(
id);
867 while(
rng.begin() !=
rng.end()) {
868 state.world.delete_province_building_construction(*(
rng.begin()));
873 auto rng = state.world.province_get_province_naval_construction(
id);
874 while(
rng.begin() !=
rng.end()) {
875 state.world.delete_province_naval_construction(*(
rng.begin()));
879 for(
auto adj : state.world.province_get_province_adjacency(
id)) {
880 auto other = adj.get_connected_provinces(0) !=
id ? adj.get_connected_provinces(0) : adj.get_connected_provinces(1);
881 if(other.get_nation_from_province_ownership() == new_owner) {
889 for(
auto ar : state.world.province_get_army_location_as_location(
id)) {
890 if(ar.get_army() && ar.get_army().get_army_rebel_control().get_controller()) {
891 assert(!ar.get_army().get_army_control().get_controller());
892 state.world.army_set_controller_from_army_control(ar.get_army(), dcon::nation_id{});
893 state.world.army_set_controller_from_army_rebel_control(ar.get_army(), dcon::rebel_faction_id{});
894 state.world.army_set_is_retreating(ar.get_army(),
true);
898 if(state_is_new && old_owner) {
908 bool was_colonial = state.world.province_get_is_colonial(
id);
922 if(state.world.nation_get_modifier_values(new_owner, sys::national_mod_offsets::research_points_on_conquer) > 0.0f) {
923 auto rp_mod_mod = state.world.nation_get_modifier_values(new_owner, sys::national_mod_offsets::research_points_modifier);
925 float sum_from_pops = 0;
927 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
928 auto rp = state.world.pop_type_get_research_points(t);
930 sum_from_pops += rp * std::min(1.0f, state.world.province_get_demographics(
id,
demographics::to_key(state, t)) /
931 (total_pop * state.world.pop_type_get_research_optimum(t)));
935 auto amount = total_pop > 0.0f ? (state.defines.research_points_on_conquer_mult * sum_from_pops) * (rp_mod_mod + 1.0f) : 0.0f;
936 state.world.nation_get_research_points(new_owner) += amount;
943 if(state.world.province_get_is_owner_core(
id) ==
false && !was_colonial) {
944 for(
auto pop : state.world.province_get_pop_location(
id)) {
945 if(!pop.get_pop().get_is_primary_or_accepted_culture()) {
954 state.world.province_set_nationalism(
id, state.defines.years_of_nationalism);
959 auto old_n = state.world.province_get_nationalism(ids);
960 auto new_nat = ve::max(old_n - 0.083f, 0.0f);
961 state.world.province_set_nationalism(ids, new_nat);
967 auto owner = state.world.province_get_nation_from_province_ownership(p);
980 if((rvalues.high & 0xFF) >= chance) {
981 if(state.world.province_get_crime(p)) {
983 state.world.nation_get_central_crime_count(owner) -= uint16_t(1);
985 state.world.province_set_crime(p, dcon::crime_id{});
987 if(!state.world.province_get_crime(p)) {
988 static std::vector<dcon::crime_id> possible_crimes;
989 possible_crimes.clear();
991 for(
uint32_t i = 0; i < state.culture_definitions.crimes.size(); ++i) {
992 dcon::crime_id c{dcon::crime_id::value_base_t(i)};
993 if(state.culture_definitions.crimes[c].available_by_default || state.world.nation_get_active_crime(owner, c)) {
994 if(
auto t = state.culture_definitions.crimes[c].trigger; t) {
996 possible_crimes.push_back(c);
998 possible_crimes.push_back(c);
1003 if(
auto count = possible_crimes.size(); count != 0) {
1004 auto selected = possible_crimes[rvalues.low % count];
1005 state.world.province_set_crime(p, selected);
1007 state.world.nation_get_central_crime_count(owner) += uint16_t(1);
1015 for(
auto rel : state.world.state_definition_get_colonization(d)) {
1016 if(rel.get_colonizer() == n) {
1023bool can_invest_in_colony(
sys::state& state, dcon::nation_id n, dcon::state_definition_id d) {
1025 if(state.world.nation_get_rank(n) > uint16_t(state.defines.colonial_rank))
1028 if(state.world.state_definition_get_colonization_stage(d) >
uint8_t(2))
1032 if(state.crisis_colony == d)
1034 for(
auto par : state.world.war_get_war_participant(state.crisis_war)) {
1035 if(par.get_nation() == n)
1039 dcon::colonization_id colony_status;
1040 auto crange = state.world.state_definition_get_colonization(d);
1041 for(
auto rel : crange) {
1042 if(rel.get_colonizer() == n) {
1043 colony_status = rel.id;
1050 if(crange.end() - crange.begin() <= 1)
1058 if(state.world.colonization_get_last_investment(colony_status) + int32_t(state.defines.colonization_days_between_investment) > state.current_date)
1068 if(state.world.state_definition_get_colonization_stage(d) == 1) {
1069 return free_points >= int32_t(state.defines.colonization_interest_cost);
1070 }
else if(state.world.colonization_get_level(colony_status) <= 4) {
1071 return free_points >= int32_t(state.defines.colonization_influence_cost);
1073 return free_points >=
1074 int32_t(state.defines.colonization_extra_guard_cost * (state.world.colonization_get_level(colony_status) - 4) +
1075 state.defines.colonization_influence_cost);
1080 auto d = state.world.state_instance_get_definition(si);
1081 auto owner = state.world.state_instance_get_nation_from_state_ownership(si);
1082 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1083 if(p.get_province().get_nation_from_province_ownership() == owner) {
1084 for(
auto adj : p.get_province().get_province_adjacency()) {
1085 auto indx = adj.get_connected_provinces(0) != p.get_province() ? 0 : 1;
1086 auto o = adj.get_connected_provinces(indx).get_nation_from_province_ownership();
1089 if(o.get_overlord_as_subject().get_ruler() == n)
1098 if(state.world.state_definition_get_colonization_stage(d) >
uint8_t(1))
1101 auto mem = state.world.state_definition_get_abstract_state_membership(d);
1102 if(mem.begin() == mem.end() || (*mem.begin()).get_province().id.index() >= state.province_definitions.first_sea_province.index())
1106 if(state.world.nation_get_rank(n) > uint16_t(state.defines.colonial_rank))
1110 if(state.crisis_colony == d)
1112 for(
auto par : state.world.war_get_war_participant(state.crisis_war)) {
1113 if(par.get_nation() == n)
1117 float max_life_rating = -1.0f;
1118 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1119 if(!p.get_province().get_nation_from_province_ownership()) {
1120 max_life_rating = std::max(max_life_rating,
float(p.get_province().get_life_rating()));
1124 if(max_life_rating < 0.0f) {
1133 if(state.defines.colonial_liferating + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::colonial_life_rating) > max_life_rating) {
1137 auto colonizers = state.world.state_definition_get_colonization(d);
1138 auto num_colonizers = colonizers.end() - colonizers.begin();
1142 if(num_colonizers >= 4)
1145 for(
auto c : colonizers) {
1146 if(c.get_colonizer() == n)
1156 bool adjacent = [&]() {
1157 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1158 if(!p.get_province().get_nation_from_province_ownership()) {
1159 for(
auto adj : p.get_province().get_province_adjacency()) {
1160 auto indx = adj.get_connected_provinces(0) != p.get_province() ? 0 : 1;
1161 auto o = adj.get_connected_provinces(indx).get_nation_from_province_ownership();
1164 if(o.get_overlord_as_subject().get_ruler() == n)
1185 bool reachable_by_sea =
false;
1187 dcon::province_id coastal_target = [&]() {
1188 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1189 if(!p.get_province().get_nation_from_province_ownership()) {
1190 if(p.get_province().get_is_coast())
1191 return p.get_province().id;
1194 return dcon::province_id{};
1197 if(!adjacent && coastal_target && state.world.nation_get_central_ports(n) != 0) {
1198 for(
auto p : state.world.nation_get_province_ownership(n)) {
1202 reachable_by_sea =
true;
1209 if(!adjacent && !reachable_by_sea)
1219 return free_points >= int32_t(state.defines.colonization_interest_cost_initial +
1220 (adjacent ? state.defines.colonization_interest_cost_neighbor_modifier : 0.0f));
1224 if(state.world.state_definition_get_colonization_stage(d) >
uint8_t(1))
1227 if(free_points < int32_t(state.defines.colonization_interest_cost_initial + state.defines.colonization_interest_cost_neighbor_modifier))
1230 auto mem = state.world.state_definition_get_abstract_state_membership(d);
1231 if(mem.begin() == mem.end() || (*mem.begin()).get_province().id.index() >= state.province_definitions.first_sea_province.index())
1235 if(state.world.nation_get_rank(n) > uint16_t(state.defines.colonial_rank))
1239 if(state.crisis_colony == d)
1242 float max_life_rating = -1.0f;
1243 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1244 if(!p.get_province().get_nation_from_province_ownership()) {
1245 max_life_rating = std::max(max_life_rating,
float(p.get_province().get_life_rating()));
1249 if(max_life_rating < 0.0f) {
1258 if(state.defines.colonial_liferating + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::colonial_life_rating) > max_life_rating) {
1262 auto colonizers = state.world.state_definition_get_colonization(d);
1263 auto num_colonizers = colonizers.end() - colonizers.begin();
1267 if(num_colonizers >= 4)
1270 for(
auto c : colonizers) {
1271 if(c.get_colonizer() == n)
1282 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1283 if(!p.get_province().get_nation_from_province_ownership()) {
1284 for(
auto adj : p.get_province().get_province_adjacency()) {
1285 auto indx = adj.get_connected_provinces(0) != p.get_province() ? 0 : 1;
1286 auto o = adj.get_connected_provinces(indx).get_nation_from_province_ownership();
1289 if(o.get_overlord_as_subject().get_ruler() == n)
1297 bool reachable_by_sea =
false;
1299 if(!adjacent && coastal_target && state.world.nation_get_central_ports(n) != 0) {
1300 for(
auto p : state.world.nation_get_province_ownership(n)) {
1304 reachable_by_sea =
true;
1311 if(!adjacent && !reachable_by_sea)
1319 return free_points >= int32_t(state.defines.colonization_interest_cost_initial +
1320 (adjacent ? state.defines.colonization_interest_cost_neighbor_modifier : 0.0f));
1324 uint8_t greatest_other_level = 0;
1325 dcon::nation_id second_colonizer;
1326 for(
auto rel : state.world.state_definition_get_colonization(state_def)) {
1327 if(rel.get_colonizer() != source) {
1328 if(rel.get_level() >= greatest_other_level) {
1329 greatest_other_level = rel.get_level();
1330 second_colonizer = rel.get_colonizer();
1335 for(
auto rel : state.world.state_definition_get_colonization(state_def)) {
1336 if(rel.get_colonizer() == source) {
1338 if(state.world.state_definition_get_colonization_stage(state_def) == 1) {
1339 rel.get_points_invested() += uint16_t(state.defines.colonization_interest_cost);
1340 }
else if(rel.get_level() <= 4) {
1341 rel.get_points_invested() += uint16_t(state.defines.colonization_influence_cost);
1343 rel.get_points_invested() += uint16_t(
1344 state.defines.colonization_extra_guard_cost * (rel.get_level() - 4) + state.defines.colonization_influence_cost);
1347 rel.get_level() +=
uint8_t(1);
1348 rel.set_last_investment(state.current_date);
1355 if(state.world.state_definition_get_colonization_stage(state_def) == 1) {
1356 if(rel.get_level() >= int32_t(state.defines.colonization_interest_lead)) {
1358 state.world.state_definition_set_colonization_stage(state_def,
uint8_t(2));
1359 auto col_range = state.world.state_definition_get_colonization(state_def);
1360 while(int32_t(col_range.end() - col_range.begin()) > 2) {
1361 for(
auto r : col_range) {
1362 if(r.get_colonizer() != source && r.get_colonizer() != second_colonizer) {
1363 state.world.delete_colonization(r);
1369 }
else if(rel.get_level() >= int32_t(state.defines.colonization_interest_lead) + greatest_other_level) {
1370 state.world.state_definition_set_colonization_stage(state_def,
uint8_t(3));
1371 auto col_range = state.world.state_definition_get_colonization(state_def);
1372 while(int32_t(col_range.end() - col_range.begin()) > 1) {
1373 for(
auto r : col_range) {
1374 if(r.get_colonizer() != source) {
1375 state.world.delete_colonization(r);
1387 for(
auto d : state.world.in_state_definition) {
1388 auto colonizers = state.world.state_definition_get_colonization(d);
1389 auto num_colonizers = colonizers.end() - colonizers.begin();
1391 if(num_colonizers > 0) {
1392 int32_t unowned_provs = 0;
1393 for(
auto p : d.get_abstract_state_membership()) {
1394 if(!(p.get_province().get_nation_from_province_ownership())) {
1399 if(unowned_provs == 0) {
1400 while(colonizers.begin() != colonizers.end()) {
1401 state.world.delete_colonization(*(colonizers.begin()));
1403 d.set_colonization_stage(
uint8_t(0));
1408 if(num_colonizers == 0 && d.get_colonization_stage() != 0) {
1409 d.set_colonization_stage(
uint8_t(0));
1410 }
else if(num_colonizers > 1 && d.get_colonization_stage() ==
uint8_t(2)) {
1418 int32_t max_points = 0;
1419 float at_war_adjust = 0.0f;
1420 for(
auto c : colonizers) {
1421 max_points = std::max(max_points, int32_t(c.get_level()));
1422 if(state.world.nation_get_is_at_war(c.get_colonizer()) ||
1423 (state.world.nation_get_disarmed_until(c.get_colonizer()) &&
1424 state.current_date <= state.world.nation_get_disarmed_until(c.get_colonizer()))) {
1425 at_war_adjust = state.defines.at_war_tension_decay;
1429 float adjust = state.defines.colonization_influence_temperature_per_day +
1430 float(max_points) * state.defines.colonization_influence_temperature_per_level +
1431 (state.current_crisis !=
sys::crisis_type::none ? state.defines.tension_while_crisis : 0.0f) + at_war_adjust;
1433 d.set_colonization_temperature(std::clamp(d.get_colonization_temperature() + adjust, 0.0f, 100.0f));
1434 }
else if(num_colonizers == 1 &&
1435 (*colonizers.begin()).get_last_investment() + int32_t(state.defines.colonization_days_for_initial_investment) <=
1436 state.current_date) {
1442 d.set_colonization_stage(
uint8_t(3));
1443 (*colonizers.begin()).set_last_investment(state.current_date);
1444 }
else if(d.get_colonization_stage() ==
uint8_t(3) && num_colonizers != 0) {
1449 if((*colonizers.begin()).get_last_investment() + 31 * int32_t(state.defines.colonization_months_to_colonize) <=
1450 state.current_date) {
1452 d.set_colonization_stage(
uint8_t(0));
1454 state.world.delete_colonization(*(colonizers.begin()));
1455 }
while(colonizers.end() != colonizers.begin());
1456 }
else if(state.world.nation_get_is_player_controlled((*colonizers.begin()).get_colonizer()) ==
false) {
1457 auto source = (*colonizers.begin()).get_colonizer();
1459 for(
auto pr : state.world.state_definition_get_abstract_state_membership(d)) {
1460 if(!pr.get_province().get_nation_from_province_ownership()) {
1465 state.world.state_definition_set_colonization_temperature(d, 0.0f);
1466 state.world.state_definition_set_colonization_stage(d,
uint8_t(0));
1468 while(colonizers.begin() != colonizers.end()) {
1469 state.world.delete_colonization(*colonizers.begin());
1477 auto d = state.world.state_instance_get_definition(s);
1478 auto o = state.world.state_instance_get_nation_from_state_ownership(s);
1479 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1480 if(p.get_province().get_nation_from_province_ownership() == o) {
1481 if(p.get_province().get_port_to())
1489 auto d = state.world.state_instance_get_definition(s);
1490 auto o = state.world.state_instance_get_nation_from_state_ownership(s);
1492 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
1493 if(p.get_province().get_nation_from_province_ownership() == o) {
1494 if(p.get_province().get_port_to()) {
1495 if(p.get_province().get_is_owner_core())
1506 state.world.try_create_core(prov, tag);
1507 if(state.world.province_get_nation_from_province_ownership(prov) ==
1508 state.world.national_identity_get_nation_from_identity_holder(tag)) {
1509 state.world.province_set_is_owner_core(prov,
true);
1515 auto core_rel = state.world.get_core_by_prov_tag_key(prov, tag);
1517 state.world.delete_core(core_rel);
1518 if(state.world.province_get_nation_from_province_ownership(prov) ==
1519 state.world.national_identity_get_nation_from_identity_holder(tag)) {
1520 state.world.province_set_is_owner_core(prov,
false);
1526 auto old_rgo = state.world.province_get_rgo(prov);
1527 state.world.province_set_rgo(prov, c);
1528 if(state.world.commodity_get_is_mine(old_rgo) != state.world.commodity_get_is_mine(c)) {
1529 if(state.world.commodity_get_is_mine(c)) {
1530 for(
auto pop : state.world.province_get_pop_location(prov)) {
1531 if(pop.get_pop().get_poptype() == state.culture_definitions.farmers) {
1532 pop.get_pop().set_poptype(state.culture_definitions.laborers);
1536 for(
auto pop : state.world.province_get_pop_location(prov)) {
1537 if(pop.get_pop().get_poptype() == state.culture_definitions.laborers) {
1538 pop.get_pop().set_poptype(state.culture_definitions.farmers);
1546 state.world.province_adjacency_get_type(state.province_definitions.canals[
id]) &=
~province::border::impassible_bit;
1551 return state.world.province_adjacency_get_distance(pair);
1556 auto apos = state.world.province_get_mid_point_b(a);
1557 auto bpos = state.world.province_get_mid_point_b(b);
1558 auto dot = (apos.x * bpos.x + apos.y * bpos.y) + apos.z * bpos.z;
1563 auto apos = state.world.province_get_mid_point_b(a);
1564 auto bpos = state.world.province_get_mid_point_b(b);
1565 auto dot = (apos.x * bpos.x + apos.y * bpos.y) + apos.z * bpos.z;
1571 auto controller = state.world.province_get_nation_from_province_control(prov);
1576 if(controller == nation_as)
1579 if(state.world.nation_get_in_sphere_of(controller) == nation_as)
1582 auto coverl = state.world.nation_get_overlord_as_subject(controller);
1583 if(state.world.overlord_get_ruler(coverl) == nation_as)
1586 auto url = state.world.get_unilateral_relationship_by_unilateral_pair(controller, nation_as);
1587 if(state.world.unilateral_relationship_get_military_access(url))
1598 auto controller = state.world.province_get_nation_from_province_control(prov);
1606 if(controller == nation_as)
1609 if(state.world.nation_get_in_sphere_of(controller) == nation_as)
1612 auto coverl = state.world.nation_get_overlord_as_subject(controller);
1613 if(state.world.overlord_get_ruler(coverl) == nation_as)
1616 auto url = state.world.get_unilateral_relationship_by_unilateral_pair(controller, nation_as);
1617 if(state.world.unilateral_relationship_get_military_access(url))
1627 auto controller = state.world.province_get_nation_from_province_control(prov);
1630 return !bool(state.world.province_get_rebel_faction_from_province_rebel_control(prov));
1635 if(controller == nation_as)
1638 if(state.world.nation_get_in_sphere_of(controller) == nation_as)
1641 auto coverl = state.world.nation_get_overlord_as_subject(controller);
1642 if(state.world.overlord_get_ruler(coverl) == nation_as)
1645 auto url = state.world.get_unilateral_relationship_by_unilateral_pair(controller, nation_as);
1646 if(state.world.unilateral_relationship_get_military_access(url))
1656 float distance_covered = 0.0f;
1657 float distance_to_target = 0.0f;
1661 if(other.distance_covered + other.distance_to_target != distance_covered + distance_to_target)
1662 return distance_covered + distance_to_target > other.distance_covered + other.distance_to_target;
1663 return other.province.index() >
province.index();
1667static void assert_path_result(std::vector<dcon::province_id>& v) {
1668 for(
auto const e : v)
1673std::vector<dcon::province_id>
make_land_path(
sys::state& state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as, dcon::army_id a) {
1675 std::vector<province_and_distance> path_heap;
1676 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
1678 std::vector<dcon::province_id> path_result;
1683 auto fill_path_result = [&](dcon::province_id i) {
1684 path_result.push_back(end);
1685 while(i && i != start) {
1686 path_result.push_back(i);
1687 i = origins_vector.get(i);
1692 while(path_heap.size() > 0) {
1693 std::pop_heap(path_heap.begin(), path_heap.end());
1694 auto nearest = path_heap.back();
1695 path_heap.pop_back();
1697 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
1699 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
1700 auto bits = adj.get_type();
1701 auto distance = adj.get_distance();
1704 if(other_prov == end) {
1705 fill_path_result(nearest.province);
1706 assert_path_result(path_result);
1710 if(other_prov.id.index() < state.province_definitions.first_sea_province.index()) {
1713 auto armies = state.world.province_get_army_location(other_prov);
1714 float danger_factor = (armies.begin() == armies.end() || (*armies.begin()).get_army().get_controller_from_army_control() == nation_as) ? 1.f : 4.f;
1715 path_heap.push_back(
1717 std::push_heap(path_heap.begin(), path_heap.end());
1718 origins_vector.set(other_prov, nearest.province);
1720 origins_vector.set(other_prov, dcon::province_id{0});
1724 path_heap.push_back(
1726 std::push_heap(path_heap.begin(), path_heap.end());
1727 origins_vector.set(other_prov, nearest.province);
1729 origins_vector.set(other_prov, dcon::province_id{0});
1736 assert_path_result(path_result);
1742 std::vector<province_and_distance> path_heap;
1743 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
1745 std::vector<dcon::province_id> path_result;
1750 auto fill_path_result = [&](dcon::province_id i) {
1751 path_result.push_back(end);
1752 while(i && i != start) {
1753 path_result.push_back(i);
1754 i = origins_vector.get(i);
1759 while(path_heap.size() > 0) {
1760 std::pop_heap(path_heap.begin(), path_heap.end());
1761 auto nearest = path_heap.back();
1762 path_heap.pop_back();
1764 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
1766 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
1767 auto bits = adj.get_type();
1768 auto distance = adj.get_distance();
1771 if(other_prov == end) {
1772 fill_path_result(nearest.province);
1773 assert_path_result(path_result);
1777 if(other_prov.id.index() < state.province_definitions.first_sea_province.index()) {
1779 path_heap.push_back(
1781 std::push_heap(path_heap.begin(), path_heap.end());
1782 origins_vector.set(other_prov, nearest.province);
1784 origins_vector.set(other_prov, dcon::province_id{0});
1787 origins_vector.set(other_prov, dcon::province_id{0});
1793 assert_path_result(path_result);
1799 std::vector<province_and_distance> path_heap;
1800 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
1802 std::vector<dcon::province_id> path_result;
1807 auto fill_path_result = [&](dcon::province_id i) {
1808 path_result.push_back(end);
1809 while(i && i != start) {
1810 path_result.push_back(i);
1811 i = origins_vector.get(i);
1816 while(path_heap.size() > 0) {
1817 std::pop_heap(path_heap.begin(), path_heap.end());
1818 auto nearest = path_heap.back();
1819 path_heap.pop_back();
1821 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
1823 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
1824 auto bits = adj.get_type();
1825 auto distance = adj.get_distance();
1828 if(other_prov == end) {
1829 fill_path_result(nearest.province);
1830 assert_path_result(path_result);
1834 path_heap.push_back(
1836 std::push_heap(path_heap.begin(), path_heap.end());
1837 origins_vector.set(other_prov, nearest.province);
1843 assert_path_result(path_result);
1850 std::vector<province_and_distance> path_heap;
1851 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
1853 std::vector<dcon::province_id> path_result;
1858 auto fill_path_result = [&](dcon::province_id i) {
1859 path_result.push_back(end);
1860 while(i && i != start) {
1861 path_result.push_back(i);
1862 i = origins_vector.get(i);
1867 while(path_heap.size() > 0) {
1868 std::pop_heap(path_heap.begin(), path_heap.end());
1869 auto nearest = path_heap.back();
1870 path_heap.pop_back();
1872 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
1874 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
1875 auto bits = adj.get_type();
1876 auto distance = adj.get_distance();
1880 (other_prov.id.index() >= state.province_definitions.first_sea_province.index() ||
1881 nearest.province.index() >= state.province_definitions.first_sea_province.index())) {
1886 if(other_prov == end) {
1887 fill_path_result(nearest.province);
1888 assert_path_result(path_result);
1893 std::push_heap(path_heap.begin(), path_heap.end());
1894 origins_vector.set(other_prov, nearest.province);
1896 }
else if(other_prov.id.index() < state.province_definitions.first_sea_province.index() && other_prov == end && other_prov.get_port_to() == nearest.province) {
1898 fill_path_result(nearest.province);
1899 assert_path_result(path_result);
1901 }
else if(nearest.province.index() < state.province_definitions.first_sea_province.index() && state.world.province_get_port_to(nearest.province) == other_prov.id) {
1903 if(other_prov == end) {
1904 fill_path_result(nearest.province);
1905 assert_path_result(path_result);
1909 std::push_heap(path_heap.begin(), path_heap.end());
1910 origins_vector.set(other_prov, nearest.province);
1917 assert_path_result(path_result);
1922 float distance_covered = 0.0f;
1926 if(other.distance_covered != distance_covered)
1927 return distance_covered > other.distance_covered;
1928 return other.province.index() >
province.index();
1934 std::vector<retreat_province_and_distance> path_heap;
1935 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
1937 std::vector<dcon::province_id> path_result;
1939 auto fill_path_result = [&](dcon::province_id i) {
1940 while(i && i != start) {
1941 path_result.push_back(i);
1942 i = origins_vector.get(i);
1947 while(path_heap.size() > 0) {
1948 std::pop_heap(path_heap.begin(), path_heap.end());
1949 auto nearest = path_heap.back();
1950 path_heap.pop_back();
1952 if(nearest.province.index() < state.province_definitions.first_sea_province.index()) {
1953 fill_path_result(nearest.province);
1954 assert_path_result(path_result);
1958 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
1960 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
1961 auto bits = adj.get_type();
1962 auto distance = adj.get_distance();
1967 std::push_heap(path_heap.begin(), path_heap.end());
1968 origins_vector.set(other_prov, nearest.province);
1969 }
else if(other_prov.get_port_to() != nearest.province) {
1973 std::push_heap(path_heap.begin(), path_heap.end());
1974 origins_vector.set(other_prov, nearest.province);
1976 origins_vector.set(other_prov, dcon::province_id{0});
1982 assert_path_result(path_result);
1988 std::vector<retreat_province_and_distance> path_heap;
1989 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
1991 origins_vector.set(start, dcon::province_id{0});
1993 std::vector<dcon::province_id> path_result;
1995 auto fill_path_result = [&](dcon::province_id i) {
1996 while(i && i != start) {
1997 path_result.push_back(i);
1998 i = origins_vector.get(i);
2003 while(path_heap.size() > 0) {
2004 std::pop_heap(path_heap.begin(), path_heap.end());
2005 auto nearest = path_heap.back();
2006 path_heap.pop_back();
2009 fill_path_result(nearest.province);
2010 assert_path_result(path_result);
2014 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
2016 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
2017 auto bits = adj.get_type();
2018 auto distance = adj.get_distance();
2023 std::push_heap(path_heap.begin(), path_heap.end());
2024 origins_vector.set(other_prov, nearest.province);
2032 assert_path_result(path_result);
2037 std::vector<retreat_province_and_distance> path_heap;
2038 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
2040 origins_vector.set(start, dcon::province_id{0});
2042 std::vector<dcon::province_id> path_result;
2044 auto fill_path_result = [&](dcon::province_id i) {
2045 while(i && i != start) {
2046 path_result.push_back(i);
2047 i = origins_vector.get(i);
2052 while(path_heap.size() > 0) {
2053 std::pop_heap(path_heap.begin(), path_heap.end());
2054 auto nearest = path_heap.back();
2055 path_heap.pop_back();
2057 if(state.world.province_get_is_coast(nearest.province)) {
2058 fill_path_result(nearest.province);
2059 assert_path_result(path_result);
2063 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
2065 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
2066 auto bits = adj.get_type();
2067 auto distance = adj.get_distance();
2073 std::push_heap(path_heap.begin(), path_heap.end());
2074 origins_vector.set(other_prov, nearest.province);
2076 origins_vector.set(other_prov, dcon::province_id{0});
2085 assert_path_result(path_result);
2089 std::vector<retreat_province_and_distance> path_heap;
2090 auto origins_vector = ve::vectorizable_buffer<dcon::province_id, dcon::province_id>(state.world.province_size());
2092 origins_vector.set(start, dcon::province_id{0});
2094 std::vector<dcon::province_id> path_result;
2096 auto fill_path_result = [&](dcon::province_id i) {
2097 while(i && i != start) {
2098 path_result.push_back(i);
2099 i = origins_vector.get(i);
2104 while(path_heap.size() > 0) {
2105 std::pop_heap(path_heap.begin(), path_heap.end());
2106 auto nearest = path_heap.back();
2107 path_heap.pop_back();
2109 if(state.world.province_get_is_coast(nearest.province)) {
2110 fill_path_result(nearest.province);
2111 assert_path_result(path_result);
2115 for(
auto adj : state.world.province_get_province_adjacency(nearest.province)) {
2117 adj.get_connected_provinces(0) == nearest.province ? adj.get_connected_provinces(1) : adj.get_connected_provinces(0);
2118 auto bits = adj.get_type();
2119 auto distance = adj.get_distance();
2124 std::push_heap(path_heap.begin(), path_heap.end());
2125 origins_vector.set(other_prov, nearest.province);
2133 assert_path_result(path_result);
2138 for(
auto p : state.world.in_province) {
2139 auto tile_pos = p.get_mid_point();
2140 auto scaled_pos = tile_pos / glm::vec2{float(state.map_state.map_data.size_x), float(state.map_state.map_data.size_y)};
2142 glm::vec3 new_world_pos;
2143 float angle_x = 2 * scaled_pos.x *
math::pi;
2147 float angle_y = scaled_pos.y *
math::pi;
2152 p.set_mid_point_b(new_world_pos);
2154 for(
auto adj : state.world.in_province_adjacency) {
2155 auto dist =
direct_distance(state, adj.get_connected_provinces(0), adj.get_connected_provinces(1));
2156 adj.set_distance(dist);
#define assert(condition)
void fix_slaves_in_province(sys::state &state, dcon::nation_id owner, dcon::province_id p)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr dcon::demographics_key militancy(4)
float rgo_total_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
float rgo_total_max_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
float subsistence_max_pseudoemployment(sys::state &state, dcon::nation_id n, dcon::province_id p)
void fire_fixed_event(sys::state &state, std::vector< nations::fixed_event > const &v, int32_t primary_slot, slot_type pt, dcon::nation_id this_slot, int32_t from_slot, slot_type ft)
constexpr uint32_t build_railway
constexpr uint32_t build_bank
constexpr uint32_t build_university
constexpr uint32_t allow_foreign_investment
float cos(float x) noexcept
float sin(float x) noexcept
float acos(float x) noexcept
bool province_is_under_siege(sys::state const &state, dcon::province_id ids)
bool are_allied_in_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
void army_arrives_in_province(sys::state &state, dcon::army_id a, dcon::province_id p, crossing_type crossing, dcon::land_battle_id from)
void eject_ships(sys::state &state, dcon::province_id p)
void update_blockade_status(sys::state &state)
bool are_in_common_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
bool can_embark_onto_sea_tile(sys::state &state, dcon::nation_id from, dcon::province_id p, dcon::army_id a)
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
void invalidate_unowned_wargoals(sys::state &state)
void update_blackflag_status(sys::state &state, dcon::province_id p)
bool province_is_blockaded(sys::state const &state, dcon::province_id ids)
int32_t free_colonial_points(sys::state &state, dcon::nation_id n)
void adjust_prestige(sys::state &state, dcon::nation_id n, float delta)
void cleanup_crisis(sys::state &state)
void set_militancy(sys::state &state, dcon::pop_id p, float v)
float get_militancy(sys::state const &state, dcon::pop_id p)
constexpr uint8_t impassible_bit
constexpr uint8_t national_bit
constexpr uint8_t coastal_bit
std::vector< dcon::province_id > make_land_path(sys::state &state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as, dcon::army_id a)
float direct_distance(sys::state &state, dcon::province_id a, dcon::province_id b)
float sorting_distance(sys::state &state, dcon::province_id a, dcon::province_id b)
void upgrade_colonial_state(sys::state &state, dcon::nation_id source, dcon::state_instance_id si)
float state_sorting_distance(sys::state &state, dcon::state_instance_id state_id, dcon::province_id prov_id)
bool has_an_owner(sys::state &state, dcon::province_id id)
bool can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
void update_connected_regions(sys::state &state)
void update_blockaded_cache(sys::state &state)
void update_nationalism(sys::state &state)
void update_crimes(sys::state &state)
std::vector< dcon::province_id > make_safe_land_path(sys::state &state, dcon::province_id start, dcon::province_id end, dcon::nation_id nation_as)
std::vector< dcon::province_id > make_naval_retreat_path(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
bool has_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
void restore_cached_values(sys::state &state)
bool has_naval_base_being_built(sys::state &state, dcon::province_id id)
void enable_canal(sys::state &state, int32_t id)
void add_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
float state_distance(sys::state &state, dcon::state_instance_id state_id, dcon::province_id prov_id)
bool is_overseas(sys::state const &state, dcon::province_id ids)
void ve_for_each_land_province(sys::state &state, F const &func)
bool has_safe_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
void remove_core(sys::state &state, dcon::province_id prov, dcon::national_identity_id tag)
bool is_colonizing(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
bool can_build_province_building(sys::state &state, dcon::province_id id, dcon::nation_id n, economy::province_building_type t)
float state_accepted_bureaucrat_size(sys::state &state, dcon::state_instance_id id)
void set_rgo(sys::state &state, dcon::province_id prov, dcon::commodity_id c)
std::vector< dcon::province_id > make_path_to_nearest_coast(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
float distance(sys::state &state, dcon::province_adjacency_id pair)
bool has_province_building_being_built(sys::state &state, dcon::province_id id, economy::province_building_type t)
float rgo_employment(sys::state &state, dcon::province_id id)
bool can_integrate_colony(sys::state &state, dcon::state_instance_id id)
std::vector< dcon::province_id > make_land_retreat_path(sys::state &state, dcon::nation_id nation_as, dcon::province_id start)
bool fast_can_start_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d, int32_t free_points, dcon::province_id coastal_target, bool &adjacent)
float rgo_production_quantity(sys::state &state, dcon::province_id id, dcon::commodity_id c)
float crime_fighting_efficiency(sys::state &state, dcon::province_id id)
bool state_is_coastal(sys::state &state, dcon::state_instance_id s)
float rgo_maximum_employment(sys::state &state, dcon::province_id id)
bool has_railroads_being_built(sys::state &state, dcon::province_id id)
float land_maximum_employment(sys::state &state, dcon::province_id id)
void for_each_land_province(sys::state &state, F const &func)
bool can_build_fort(sys::state &state, dcon::province_id id, dcon::nation_id n)
bool can_start_colony(sys::state &state, dcon::nation_id n, dcon::state_definition_id d)
float rgo_size(sys::state &state, dcon::province_id prov_id)
std::vector< dcon::province_id > make_naval_path(sys::state &state, dcon::province_id start, dcon::province_id end)
std::vector< dcon::province_id > make_unowned_land_path(sys::state &state, dcon::province_id start, dcon::province_id end)
void set_province_controller(sys::state &state, dcon::province_id p, dcon::nation_id n)
void update_colonization(sys::state &state)
float land_employment(sys::state &state, dcon::province_id id)
bool has_naval_access_to_province(sys::state &state, dcon::nation_id nation_as, dcon::province_id prov)
float rgo_income(sys::state &state, dcon::province_id id)
void conquer_province(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
constexpr float world_circumference
bool state_is_coastal_non_core_nb(sys::state &state, dcon::state_instance_id s)
bool has_fort_being_built(sys::state &state, dcon::province_id id)
bool nations_are_adjacent(sys::state &state, dcon::nation_id a, dcon::nation_id b)
bool can_build_naval_base(sys::state &state, dcon::province_id id, dcon::nation_id n)
dcon::province_id get_connected_province(sys::state &state, dcon::province_adjacency_id adj, dcon::province_id curr)
float revolt_risk(sys::state &state, dcon::province_id id)
float colony_integration_cost(sys::state &state, dcon::state_instance_id id)
float state_admin_efficiency(sys::state &state, dcon::state_instance_id id)
void change_province_owner(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
std::vector< dcon::province_id > make_unowned_path_to_nearest_coast(sys::state &state, dcon::province_id start)
dcon::province_id pick_capital(sys::state &state, dcon::nation_id n)
void restore_distances(sys::state &state)
bool state_borders_nation(sys::state &state, dcon::nation_id n, dcon::state_instance_id si)
void increase_colonial_investment(sys::state &state, dcon::nation_id source, dcon::state_definition_id state_def)
bool generic_can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
void remove_pop_from_movement(sys::state &state, dcon::pop_id p)
void remove_pop_from_rebel_faction(sys::state &state, dcon::pop_id p)
random_pair get_random_pair(sys::state const &state, uint32_t value_in)
int32_t to_generic(dcon::province_id v)
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
bool operator<(province_and_distance const &other) const noexcept
dcon::province_id province
dcon::province_id prov_id
dcon::province_id province
bool operator<(retreat_province_and_distance const &other) const noexcept