15 for(
auto m : state.world.nation_get_movement_within(n)) {
16 if(m.get_movement().get_associated_issue_option() == o)
17 return m.get_movement().id;
19 return dcon::movement_id{};
22 for(
auto m : state.world.nation_get_movement_within(n)) {
23 if(m.get_movement().get_associated_independence() == i)
24 return m.get_movement().id;
26 return dcon::movement_id{};
30 for(
auto f : state.world.nation_get_rebellion_within(n)) {
31 if(f.get_rebels().get_type() == r)
32 return f.get_rebels().id;
34 return dcon::rebel_faction_id{};
39 state.world.execute_serial_over_movement([&](
auto ids) { state.world.movement_set_pop_support(ids, ve::fp_vector()); });
40 state.world.for_each_pop([&](dcon::pop_id p) {
41 if(
auto m = state.world.pop_get_movement_from_pop_movement_membership(p); m) {
42 auto i = state.world.movement_get_associated_issue_option(m);
43 state.world.movement_get_pop_support(m) += state.world.pop_get_size(p) * (i ? pop_demographics::get_demo(state, p, pop_demographics::to_key(state, i)) : 1.0f);
47 static ve::vectorizable_buffer<float, dcon::nation_id> nation_reform_count(
uint32_t(1));
50 auto new_count = state.world.nation_size();
51 if(new_count > old_count) {
52 nation_reform_count = state.world.nation_make_vectorizable_float_buffer();
53 old_count = new_count;
56 state.world.execute_serial_over_nation([&](
auto host_nations) {
57 nation_reform_count.set(host_nations, 0.0f);
60 for(
auto preform : state.culture_definitions.political_issues) {
61 if(state.world.issue_get_is_next_step_only(preform)) {
62 auto base_reform = state.world.issue_get_options(preform)[0].index() + 1;
64 state.world.execute_serial_over_nation([&](
auto host_nations) {
65 ve::fp_vector reform_totals = nation_reform_count.get(host_nations);
66 ve::tagged_vector<dcon::issue_option_id> creform = state.world.nation_get_issues(host_nations, preform);
67 reform_totals = reform_totals +
ve::to_float(ve::int_vector(creform.to_original_values()) - base_reform);
68 nation_reform_count.set(host_nations, reform_totals);
73 state.world.execute_serial_over_movement([&](
auto ids) {
82 auto host_nations = state.world.movement_get_nation_from_movement_within(ids);
84 auto host_max_nationalism = ve::apply(
85 [&](dcon::nation_id n, dcon::movement_id m) {
86 if(
auto iid = state.world.movement_get_associated_independence(m); iid) {
88 for(auto c : state.world.national_identity_get_core(iid)) {
89 if(c.get_province().get_nation_from_province_ownership() == n) {
90 nmax = std::max(nmax, c.get_province().get_nationalism());
99 auto host_pculture = state.world.nation_get_primary_culture(host_nations);
100 auto host_cradicalism =
ve::to_float(state.world.culture_get_radicalism(host_pculture));
102 auto ref_effect = nation_reform_count.get(host_nations) * state.defines.movement_radicalism_passed_reform_effect;
103 auto nat_effect = host_max_nationalism * state.defines.movement_radicalism_nationalism_factor;
104 auto mov_support = state.world.movement_get_pop_support(ids);
105 auto non_c_pop = state.world.nation_get_non_colonial_population(host_nations);
106 auto support_effect = state.defines.population_movement_radical_factor * mov_support / non_c_pop;
108 auto new_radicalism = state.world.movement_get_transient_radicalism(ids) + state.defines.movement_radicalism_base
109 + ref_effect + host_cradicalism + nat_effect + support_effect;
110 state.world.movement_set_radicalism(ids, ve::max(0.0f, new_radicalism));
116 auto i = state.world.movement_get_associated_issue_option(m);
118 state.world.try_create_pop_movement_membership(p, m);
121 auto prior_movement = state.world.pop_get_movement_from_pop_movement_membership(p);
123 auto i = state.world.movement_get_associated_issue_option(prior_movement);
125 state.world.delete_pop_movement_membership(state.world.pop_get_pop_movement_membership(p));
135 state.world.movement_get_transient_radicalism(m) += state.defines.suppression_radicalisation_hit;
136 for(
auto p : state.world.movement_get_pop_movement_membership(m)) {
140 state.world.movement_remove_all_pop_movement_membership(m);
150 for(
auto p : state.world.movement_get_pop_movement_membership(m)) {
155 state.world.delete_movement(m);
159 auto parent_issue = state.world.issue_option_get_parent_issue(i);
160 auto current_setting = state.world.nation_get_issues(nation_within, parent_issue);
161 if(i == current_setting)
163 if(state.world.issue_get_is_next_step_only(parent_issue)) {
164 if(i.index() != current_setting.id.index() - 1 && i.index() != current_setting.id.index() + 1)
167 auto allow = state.world.issue_option_get_allow(i);
175 auto i = state.world.movement_get_associated_issue_option(m);
177 auto nation_within = state.world.movement_get_nation_from_movement_within(m);
182 auto t = state.world.movement_get_associated_independence(m);
184 for(
auto p : state.world.nation_get_province_ownership(nation_within)) {
185 if(state.world.get_core_by_prov_tag_key(p.get_province(), t))
195 state.world.for_each_pop([&](dcon::pop_id p) {
202 if(state.world.pop_get_poptype(p) == state.culture_definitions.slaves)
205 if(state.world.pop_get_rebel_faction_from_pop_rebellion_membership(p))
208 auto pop_location = state.world.pop_get_province_from_pop_location(p);
210 if(state.world.province_get_is_colonial(pop_location))
213 auto existing_movement = state.world.pop_get_movement_from_pop_movement_membership(p);
217 if(mil >= state.defines.mil_to_join_rebel) {
221 if(existing_movement) {
223 state.world.movement_get_associated_issue_option(existing_movement);
226 if(support * 100.0f < state.defines.issue_movement_leave_limit) {
232 }
else if(mil < state.defines.nationalist_movement_mil_cap) {
246 if(con >= 1.5f || lit >= 0.25f) {
252 dcon::issue_option_id max_option;
253 float max_support = 0;
254 state.world.for_each_issue_option([&](dcon::issue_option_id io) {
255 auto parent = state.world.issue_option_get_parent_issue(io);
256 auto co = state.world.nation_get_issues(owner, parent);
257 auto allow = state.world.issue_option_get_allow(io);
260 if(sup * 100.0f >= state.defines.issue_movement_join_limit && sup > max_support) {
266 auto fp_prob = 9.0f * sup * (state.defines.movement_lit_factor * lit + state.defines.movement_con_factor * con);
268 if(rvalue < fp_prob) {
271 if(state.world.issue_get_is_next_step_only(parent) ==
false || co.id.index() + 1 == io.index() || co.id.index() - 1 == io.index()) {
284 auto new_movement = fatten(state.world, state.world.create_movement());
285 new_movement.set_associated_issue_option(max_option);
286 state.world.try_create_movement_within(new_movement, owner);
289 }
else if(!state.world.pop_get_is_primary_or_accepted_culture(p) && mil >= state.defines.nationalist_movement_mil_cap) {
298 auto pop_culture = state.world.pop_get_culture(p);
299 for(
auto c : state.world.province_get_core(pop_location)) {
300 if(c.get_identity().get_primary_culture() == pop_culture) {
303 state.world.try_create_pop_movement_membership(p, existing_mov);
305 auto new_mov = fatten(state.world, state.world.create_movement());
306 new_mov.set_associated_independence(c.get_identity());
307 state.world.try_create_movement_within(new_mov, owner);
308 state.world.try_create_pop_movement_membership(p, new_mov);
322 for(
auto last = state.world.movement_size(); last-- > 0;) {
323 dcon::movement_id m{dcon::movement_id::value_base_t(last)};
325 state.world.delete_movement(m);
331 for(
auto last = state.world.movement_size(); last-- > 0;) {
332 dcon::movement_id m{dcon::movement_id::value_base_t(last)};
333 if(state.world.movement_get_radicalism(m) >= 100.0f) {
340 if(
auto m = state.world.pop_get_pop_rebellion_membership(p); m) {
341 auto fac = state.world.pop_rebellion_membership_get_rebel_faction(m);
342 state.world.rebel_faction_get_possible_regiments(fac) -=
343 int32_t(state.world.pop_get_size(p) / state.defines.pop_size_per_regiment);
344 state.world.delete_pop_rebellion_membership(m);
349 state.world.try_create_pop_rebellion_membership(p, m);
350 state.world.rebel_faction_get_possible_regiments(m) +=
351 int32_t(state.world.pop_get_size(p) / state.defines.pop_size_per_regiment);
362 auto pops = state.world.rebel_faction_get_pop_rebellion_membership(m);
363 if(pops.begin() == pops.end())
366 auto type = fatten(state.world, state.world.rebel_faction_get_type(m));
368 auto tag = state.world.rebel_faction_get_defection_target(m);
369 auto within = fatten(state.world, m).get_rebellion_within().get_ruler();
370 if(within.get_identity_from_identity_holder() == tag)
384 auto type = fatten(state.world, state.world.rebel_faction_get_type(t));
385 auto fac = fatten(state.world, t);
386 auto pop = fatten(state.world, p);
387 if(type.get_independence() != 0 || type.get_defection() != 0) {
390 if(pop.get_is_primary_or_accepted_culture())
393 if(pop.get_is_primary_or_accepted_culture())
396 for(
auto core : pop.get_province_from_pop_location().get_core()) {
397 if(core.get_identity().get_primary_culture() == pop.get_culture())
401 if(fac.get_primary_culture() && fac.get_primary_culture() != pop.get_culture())
403 if(fac.get_religion() && fac.get_religion() != pop.get_religion())
405 if(fac.get_primary_culture_group() &&
406 fac.get_primary_culture_group() != pop.get_culture().get_group_from_culture_group_membership())
408 if(fac.get_type().get_ideology() && fac.get_type().get_ideology_restriction() && fac.get_type().get_ideology() != pop.get_dominant_ideology())
410 if(fac.get_type().get_ideology() && pop.get_province_from_pop_location().get_is_colonial())
416 auto fac = fatten(state.world, t);
417 auto pop = fatten(state.world, p);
419 if(fac.get_independence() != 0 || fac.get_defection() != 0) {
422 if(pop.get_is_primary_or_accepted_culture())
425 if(pop.get_is_primary_or_accepted_culture())
428 for(
auto core : pop.get_province_from_pop_location().get_core()) {
429 if(core.get_identity().get_primary_culture() == pop.get_culture())
436 if(!pop.get_is_primary_or_accepted_culture()) {
440 if(fac.get_ideology() && fac.get_ideology() != pop.get_dominant_ideology()) {
447 state.world.for_each_pop([&](dcon::pop_id p) {
454 auto existing_faction = state.world.pop_get_rebel_faction_from_pop_rebellion_membership(p);
457 if(mil >= state.defines.mil_to_join_rebel) {
461 auto prov = state.world.pop_get_province_from_pop_location(p);
467 auto occupying_faction = state.world.province_get_rebel_faction_from_province_rebel_control(prov);
469 assert(!
bool(state.world.province_get_nation_from_province_control(prov)));
479 float greatest_chance = 0.0f;
480 dcon::rebel_faction_id f;
481 for(
auto rf : state.world.nation_get_rebellion_within(owner)) {
483 auto chance = rf.get_rebels().get_type().get_spawn_chance();
486 if(eval > greatest_chance) {
488 greatest_chance = eval;
493 dcon::rebel_faction_id temp = state.world.create_rebel_faction();
494 dcon::national_identity_id ind_tag = [&]() {
495 auto prov = state.world.pop_get_province_from_pop_location(p);
496 for(
auto core : state.world.province_get_core(prov)) {
497 if(!core.get_identity().get_is_not_releasable() && core.get_identity().get_primary_culture() == state.world.pop_get_culture(p))
498 return core.get_identity().id;
500 return dcon::national_identity_id{};
503 dcon::rebel_type_id max_type;
505 state.world.for_each_rebel_type([&](dcon::rebel_type_id rt) {
507 state.world.rebel_faction_set_type(temp, rt);
508 state.world.rebel_faction_set_defection_target(temp, dcon::national_identity_id{});
509 state.world.rebel_faction_set_primary_culture(temp, dcon::culture_id{});
510 state.world.rebel_faction_set_primary_culture_group(temp, dcon::culture_group_id{});
511 state.world.rebel_faction_set_religion(temp, dcon::religion_id{});
515 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
516 state.world.rebel_faction_set_defection_target(temp, ind_tag);
519 if(state.world.pop_get_is_primary_or_accepted_culture(p))
523 state.world.rebel_faction_set_primary_culture_group(temp,
524 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
525 state.world.rebel_faction_set_defection_target(temp, ind_tag);
528 if(state.world.pop_get_is_primary_or_accepted_culture(p))
532 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
533 state.world.rebel_faction_set_defection_target(temp, ind_tag);
536 if(state.world.pop_get_is_primary_or_accepted_culture(p))
540 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
541 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
544 state.world.rebel_faction_set_defection_target(temp, u);
548 state.world.rebel_faction_set_defection_target(temp, ind_tag);
551 if(state.world.pop_get_is_primary_or_accepted_culture(p))
560 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
561 state.world.rebel_faction_set_defection_target(temp, ind_tag);
564 if(state.world.pop_get_is_primary_or_accepted_culture(p))
568 state.world.rebel_faction_set_primary_culture_group(temp,
569 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
570 state.world.rebel_faction_set_defection_target(temp, ind_tag);
573 if(state.world.pop_get_is_primary_or_accepted_culture(p))
577 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
578 state.world.rebel_faction_set_defection_target(temp, ind_tag);
581 if(state.world.pop_get_is_primary_or_accepted_culture(p))
585 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
586 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
589 if(state.world.pop_get_is_primary_or_accepted_culture(p))
591 state.world.rebel_faction_set_defection_target(temp, u);
595 state.world.rebel_faction_set_defection_target(temp, ind_tag);
598 if(state.world.pop_get_is_primary_or_accepted_culture(p))
602 state.world.rebel_faction_set_defection_target(temp, ind_tag);
605 if(state.world.pop_get_is_primary_or_accepted_culture(p))
612 auto chance = state.world.rebel_type_get_spawn_chance(rt);
615 if(eval > greatest_chance) {
618 greatest_chance = eval;
624 state.world.delete_rebel_faction(temp);
627 state.world.rebel_faction_set_type(temp, rt);
628 state.world.rebel_faction_set_defection_target(temp, dcon::national_identity_id{});
629 state.world.rebel_faction_set_primary_culture(temp, dcon::culture_id{});
630 state.world.rebel_faction_set_primary_culture_group(temp, dcon::culture_group_id{});
631 state.world.rebel_faction_set_religion(temp, dcon::religion_id{});
635 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
636 state.world.rebel_faction_set_defection_target(temp, ind_tag);
639 state.world.rebel_faction_set_primary_culture_group(temp,
640 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
641 state.world.rebel_faction_set_defection_target(temp, ind_tag);
644 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
645 state.world.rebel_faction_set_defection_target(temp, ind_tag);
648 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
649 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
650 state.world.rebel_faction_set_defection_target(temp, u);
654 state.world.rebel_faction_set_defection_target(temp, ind_tag);
662 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
663 state.world.rebel_faction_set_defection_target(temp, ind_tag);
666 state.world.rebel_faction_set_primary_culture_group(temp,
667 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
668 state.world.rebel_faction_set_defection_target(temp, ind_tag);
671 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
672 state.world.rebel_faction_set_defection_target(temp, ind_tag);
675 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
676 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
677 state.world.rebel_faction_set_defection_target(temp, u);
681 state.world.rebel_faction_set_defection_target(temp, ind_tag);
684 state.world.rebel_faction_set_defection_target(temp, ind_tag);
690 if(state.world.rebel_type_get_culture_restriction(rt) && !state.world.rebel_faction_get_primary_culture(temp)) {
691 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
693 if(state.world.rebel_type_get_culture_group_restriction(rt) && !state.world.rebel_faction_get_primary_culture_group(temp)) {
694 state.world.rebel_faction_set_primary_culture_group(temp, state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
697 state.world.try_create_rebellion_within(temp, owner);
700 if(greatest_chance > 0) {
706 if(existing_faction) {
714 auto control = state.world.rebel_faction_get_province_rebel_control(reb);
715 for(
auto p : control) {
716 auto prov = p.get_province();
719 state.world.delete_rebel_faction(reb);
725 for(
auto last = state.world.rebel_faction_size(); last-- > 0;) {
726 dcon::rebel_faction_id m{dcon::rebel_faction_id::value_base_t(last)};
728 for(
auto members : state.world.rebel_faction_get_pop_rebellion_membership(m)) {
740 state.world.for_each_rebel_faction([&](dcon::rebel_faction_id rf) {
742 for(
auto pop : state.world.rebel_faction_get_pop_rebellion_membership(rf)) {
743 total += int32_t(state.world.pop_get_size(pop.get_pop()) / state.defines.pop_size_per_regiment);
745 state.world.rebel_faction_set_possible_regiments(rf, total);
749 state.world.for_each_rebel_faction([&](dcon::rebel_faction_id rf) {
758 float total_change = 0;
759 for(
auto pop : state.world.rebel_faction_get_pop_rebellion_membership(rf)) {
760 auto mil_factor = [&]() {
761 auto m = pop_demographics::get_militancy(state, pop.get_pop());
762 if(m > state.defines.mil_to_autorise)
764 else if(m > state.defines.mil_to_join_rising)
770 auto reg_count = state.world.rebel_faction_get_possible_regiments(rf);
771 auto within = state.world.rebel_faction_get_ruler_from_rebellion_within(rf);
772 auto rebel_org_mod = 1.0f + state.world.nation_get_rebel_org_modifier(within, state.world.rebel_faction_get_type(rf));
775 state.world.rebel_faction_set_organization(rf,
777 state.world.rebel_faction_get_organization(rf) +
779 (1.0f + state.world.nation_get_rebel_org_modifier(within, state.world.rebel_faction_get_type(rf))) *
780 0.001f / (1.0f + state.world.nation_get_administrative_efficiency(within)) / float(reg_count)));
786 assert(rebel_provs.empty());
788 for(
auto prov : nat.get_province_ownership()) {
789 if(prov.get_province().get_rebel_faction_from_province_rebel_control()
796 auto our_str = ar.
str;
797 auto loc = state.world.army_get_location_from_army_location(ar.
a);
799 auto aa = 0.001f * -(our_str - a.str);
800 auto ab = 0.001f * -(our_str - b.str);
801 auto da = province::sorting_distance(state, a.p, loc) + aa;
802 auto db = province::sorting_distance(state, b.p, loc) + ab;
806 return a.p.index() < b.p.index();
811 for(
auto rf : state.world.in_rebel_faction) {
812 auto const faction_owner = rf.get_ruler_from_rebellion_within();
814 if(faction_owner.get_is_player_controlled()) {
815 static std::vector<impl::arm_str> rebel_hunters;
816 rebel_hunters.clear();
817 for(
auto ar : faction_owner.get_army_control()) {
818 auto loc = ar.get_army().get_location_from_army_location();
819 if(ar.get_army().get_is_rebel_hunter()
820 && !ar.get_army().get_battle_from_army_battle_participation()
821 && !ar.get_army().get_navy_from_army_transport()
822 && !ar.get_army().get_arrival_time()
823 && loc.get_nation_from_province_control() == faction_owner
829 static std::vector<impl::prov_str> rebel_provs;
833 while(rebel_provs.size() > 0 && rebel_hunters.size() > 0) {
834 auto rh = rebel_hunters[0];
837 auto closest_prov = rebel_provs[0].p;
839 auto pa = state.world.army_get_location_from_army_location(a.a);
840 auto pb = state.world.army_get_location_from_army_location(b.a);
841 auto as = 0.001f * std::max<float>(a.str, 1.f);
842 auto bs = 0.001f * std::max<float>(b.str, 1.f);
843 auto da = province::sorting_distance(state, pa, closest_prov) + as;
844 auto db = province::sorting_distance(state, pb, closest_prov) + bs;
848 return a.a.index() < b.a.index();
851 for(
uint32_t i = 0; i < rebel_hunters.size(); ++i) {
852 auto a = rebel_hunters[i].
a;
853 if(state.world.army_get_location_from_army_location(a) == closest_prov) {
854 state.world.army_get_path(a).clear();
855 state.world.army_set_arrival_time(a,
sys::date{});
857 rebel_hunters[i] = rebel_hunters.back();
858 rebel_hunters.pop_back();
860 }
else if(
auto path =
province::make_land_path(state, state.world.army_get_location_from_army_location(a), closest_prov, faction_owner, a); path.size() > 0) {
861 auto existing_path = state.world.army_get_path(a);
862 auto new_size =
uint32_t(path.size());
863 existing_path.resize(new_size);
864 for(
uint32_t j = 0; j < new_size; j++) {
865 existing_path.at(j) = path[j];
868 state.world.army_set_dig_in(a, 0);
870 rebel_hunters[i] = rebel_hunters.back();
871 rebel_hunters.pop_back();
875 rebel_provs[0] = rebel_provs.back();
876 rebel_provs.pop_back();
881 for(
const auto a : state.world.in_army) {
882 if(a.get_is_rebel_hunter()
883 && !a.get_battle_from_army_battle_participation()
884 && !a.get_navy_from_army_transport()
885 && !a.get_arrival_time()
886 && a.get_location_from_army_location() != a.get_ai_province()
887 && a.get_location_from_army_location().get_province_control().get_nation() == a.get_location_from_army_location().get_province_ownership().get_nation())
889 if(
auto path =
province::make_land_path(state, a.get_location_from_army_location(), a.get_ai_province(), a.get_army_control().get_controller(), a); path.size() > 0) {
890 auto existing_path = state.world.army_get_path(a);
891 auto new_size =
uint32_t(path.size());
892 existing_path.resize(new_size);
893 for(
uint32_t j = 0; j < new_size; j++) {
894 existing_path.at(j) = path[j];
897 state.world.army_set_dig_in(a, 0);
899 state.world.army_set_ai_province(a, state.world.army_get_location_from_army_location(a));
908 static std::vector<dcon::army_id> new_armies;
911 for(
auto rf : state.world.in_rebel_faction) {
914 float p_val = float(rval & 0xFFFF) / float(0x10000);
915 if(p_val < revolt_chance) {
916 auto const faction_owner = rf.get_ruler_from_rebellion_within();
918 auto counter = new_to_make;
926 for(
auto pop : rf.get_pop_rebellion_membership()) {
931 auto location = pop.get_pop().get_province_from_pop_location();
934 auto max_count = int32_t(state.world.pop_get_size(pop.get_pop()) *
rebel_size_reduction / (
province::is_overseas(state, pop.get_pop().get_province_from_pop_location()) ? (state.defines.pop_min_size_for_regiment_colony_multiplier * state.defines.pop_size_per_regiment) : state.defines.pop_size_per_regiment));
935 auto cregs = pop.get_pop().get_regiment_source();
936 auto used_count = int32_t(cregs.end() - cregs.begin());
938 if(used_count < max_count) {
939 auto pop_location = pop.get_pop().get_province_from_pop_location();
943 for(
auto ar : state.world.province_get_army_location(pop_location)) {
944 if(!(ar.get_army().get_battle_from_army_battle_participation()) && ar.get_army().get_controller_from_army_rebel_control() == rf)
945 return ar.get_army().id;
947 auto new_army = fatten(state.world, state.world.create_army());
948 new_army.set_controller_from_army_rebel_control(rf);
949 new_army.set_location_from_army_location(pop_location);
950 new_armies.push_back(new_army);
953 state.world.try_create_army_membership(new_reg, a);
954 state.world.try_create_regiment_source(new_reg, pop.get_pop());
965 rf.set_organization(0);
966 if(counter != new_to_make) {
971 ankerl::unordered_dense::map<int32_t, int32_t> provs;
972 for(
auto ar : state.world.rebel_faction_get_army_rebel_control(reb)) {
973 if(ar.get_controller() == reb) {
974 auto p = ar.get_army().get_location_from_army_location();
975 provs[p.id.index()] += 1;
978 for(
auto p : provs) {
988 rf.get_ruler_from_rebellion_within(), dcon::nation_id{}, dcon::nation_id{},
994 for(
auto a : new_armies) {
995 if(!state.world.army_get_battle_from_army_battle_participation(a))
1001 auto nation_count = state.world.nation_size();
1002 for(
uint32_t i = 0; i < nation_count; ++i) {
1003 dcon::nation_id m{dcon::nation_id::value_base_t(i)};
1004 if(state.world.nation_get_in_sphere_of(m) == n) {
1005 for(
auto fac : state.world.nation_get_rebellion_within(m)) {
1020 for(
auto ar : state.world.rebel_faction_get_army_rebel_control(r)) {
1021 auto regs = ar.get_army().get_army_membership();
1022 total += int32_t(regs.end() - regs.begin());
1028 return state.world.rebel_faction_get_organization(r);
1036 auto nation_brigades =
1037 std::max(1, int32_t(state.world.nation_get_active_regiments(state.world.rebel_faction_get_ruler_from_rebellion_within(r))));
1040 auto faction_org = state.world.rebel_faction_get_organization(r);
1042 if(num_brigades_ready <= 0) {
1046 float chance = std::clamp(
1047 faction_org * 0.05f + 0.02f + faction_org *
float(num_brigades_ready) / (
float(nation_brigades) * 20.0f), 0.0f, 1.0f);
1053 auto reb_controller = state.world.province_get_rebel_faction_from_province_rebel_control(p);
1054 auto owner = state.world.province_get_nation_from_province_ownership(p);
1055 if(reb_controller && owner) {
1056 assert(!
bool(state.world.province_get_nation_from_province_control(p)));
1057 auto reb_type = state.world.rebel_faction_get_type(reb_controller);
1059 if(def_type !=
culture::rebel_defection::none && state.world.province_get_last_control_change(p) + reb_type.get_defect_delay() * 31 <= state.current_date) {
1062 dcon::nation_id defection_tag = [&]() {
1066 for(
auto c : state.world.province_get_core(p)) {
1067 auto holder = c.get_identity().get_nation_from_identity_holder();
1068 if(holder.get_ruling_party().get_ideology() == reb_type.get_ideology() && holder.get_owned_province_count() != 0) {
1069 return c.get_identity().get_nation_from_identity_holder().id;
1073 for(
auto c : state.world.province_get_core(p)) {
1074 auto holder = c.get_identity().get_nation_from_identity_holder();
1075 if(!c.get_identity().get_is_not_releasable() && holder.get_owned_province_count() == 0) {
1076 auto t = c.get_identity().get_nation_from_identity_holder().id;
1086 for(
auto c : state.world.province_get_core(p)) {
1087 auto holder = c.get_identity().get_nation_from_identity_holder();
1088 if(holder.get_religion() == state.world.rebel_faction_get_religion(reb_controller) && holder.get_owned_province_count() != 0) {
1089 return c.get_identity().get_nation_from_identity_holder().id;
1093 for(
auto c : state.world.province_get_core(p)) {
1094 auto holder = c.get_identity().get_nation_from_identity_holder();
1095 if(!c.get_identity().get_is_not_releasable() && c.get_identity().get_religion() == state.world.rebel_faction_get_religion(reb_controller) && holder.get_owned_province_count() == 0) {
1096 auto t = c.get_identity().get_nation_from_identity_holder().id;
1104 for(
auto c : state.world.province_get_core(p)) {
1105 auto holder = c.get_identity().get_nation_from_identity_holder();
1106 if(c.get_identity().get_primary_culture() == state.world.rebel_faction_get_primary_culture(reb_controller) && holder.get_owned_province_count() != 0) {
1107 return c.get_identity().get_nation_from_identity_holder().id;
1111 for(
auto c : state.world.province_get_core(p)) {
1112 auto holder = c.get_identity().get_nation_from_identity_holder();
1113 if(!c.get_identity().get_is_not_releasable() && c.get_identity().get_primary_culture() == state.world.rebel_faction_get_primary_culture(reb_controller) && holder.get_owned_province_count() == 0) {
1114 auto t = c.get_identity().get_nation_from_identity_holder().id;
1122 for(
auto c : state.world.province_get_core(p)) {
1123 auto holder = c.get_identity().get_nation_from_identity_holder();
1124 if(c.get_identity().get_primary_culture().get_group_from_culture_group_membership() == state.world.rebel_faction_get_primary_culture_group(reb_controller) && holder.get_owned_province_count() != 0) {
1125 return c.get_identity().get_nation_from_identity_holder().id;
1129 for(
auto c : state.world.province_get_core(p)) {
1130 auto holder = c.get_identity().get_nation_from_identity_holder();
1131 if(!c.get_identity().get_is_not_releasable()
1132 && c.get_identity().get_primary_culture().get_group_from_culture_group_membership() == state.world.rebel_faction_get_primary_culture_group(reb_controller)
1133 && holder.get_owned_province_count() == 0) {
1135 auto t = c.get_identity().get_nation_from_identity_holder().id;
1146 for(
auto c : state.world.province_get_core(p)) {
1147 auto holder = c.get_identity().get_nation_from_identity_holder();
1148 if(c.get_identity() == state.world.rebel_faction_get_defection_target(reb_controller) && holder.get_owned_province_count() != 0) {
1154 return dcon::nation_id{};
1156 return dcon::nation_id{};
1176 if(state.defines.population_suppression_factor > 0.0f) {
1177 return std::max(state.world.movement_get_radicalism(m) + 1.0f, state.world.movement_get_radicalism(m) *
1178 state.world.movement_get_pop_support(m) / state.defines.population_suppression_factor);
1180 return state.world.movement_get_radicalism(m) + 1.0f;
1185 for(
uint32_t i = state.world.rebel_faction_size(); i-- > 0;) {
1186 auto reb = dcon::rebel_faction_id{dcon::rebel_faction_id::value_base_t(i)};
1187 auto within = state.world.rebel_faction_get_ruler_from_rebellion_within(reb);
1189 auto enforce_trigger = state.world.rebel_faction_get_type(reb).get_demands_enforced_trigger();
1190 if(is_active && enforce_trigger &&
1200 auto old_gov = state.world.nation_get_government_type(within);
1202 auto new_gov = state.world.rebel_faction_get_type(reb).get_government_change(old_gov);
1206 if(
auto iid = state.world.rebel_faction_get_type(reb).get_ideology(); iid) {
1210 for(
auto members : state.world.rebel_faction_get_pop_rebellion_membership(reb)) {
1219 if(state.world.rebel_faction_get_type(reb).get_break_alliance_on_win()) {
1235 if(
auto k = state.world.rebel_faction_get_type(reb).get_demands_enforced_effect(); k)
1237 uint32_t(state.current_date.value),
uint32_t(within.index() ^ (reb.index() << 4)));
1240 [type = state.world.rebel_faction_get_type(reb).
id, ploss, new_gov, within, when = state.current_date, i = reb.index()](
sys::state& state,
text::layout_base& contents) {
1242 text::add_line(state, contents,
"msg_rebels_win_1", text::variable_type::x, state.world.rebel_type_get_title(type));
1243 text::add_line(state, contents,
"msg_rebels_win_2", text::variable_type::x, text::fp_one_place{ploss});
1247 if(
auto iid = state.world.rebel_type_get_ideology(type); iid) {
1250 if(state.world.rebel_type_get_break_alliance_on_win(type)) {
1253 if(
auto k = state.world.rebel_type_get_demands_enforced_effect(type); k) {
1258 "msg_rebels_win_title",
1259 within, dcon::nation_id{}, dcon::nation_id{},
1272 dcon::religion_id r) {
1279 auto culture = state.world.rebel_faction_get_primary_culture(reb);
1280 auto religion = state.world.rebel_faction_get_religion(reb);
1281 auto defection_target = state.world.rebel_faction_get_defection_target(reb);
1282 auto in_nation = state.world.rebel_faction_get_ruler_from_rebellion_within(reb);
1284 auto adjective = defection_target.get_adjective();
1299 if(defection_target) {
1316 return prov.get_dominant_culture() == rf.get_primary_culture();
1318 return prov.get_dominant_culture().get_culture_group_membership().get_group() == rf.get_primary_culture_group();
1320 return prov.get_dominant_religion() == rf.get_religion();
1322 return prov.get_dominant_religion() == rf.get_defection_target().get_religion() && prov.get_province_ownership().get_nation() == rf.get_rebellion_within().get_ruler();
1324 return prov.get_dominant_culture() == rf.get_defection_target().get_primary_culture() && prov.get_province_ownership().get_nation() == rf.get_rebellion_within().get_ruler();
1326 return prov.get_province_ownership().get_nation() == rf.get_rebellion_within().get_ruler();
1334 concurrency::parallel_for(
uint32_t(0), state.world.army_rebel_control_size(), [&](
uint32_t i) {
1335 auto ar_reb_control = dcon::army_rebel_control_id{ dcon::army_rebel_control_id::value_base_t(i) };
1336 if(!state.world.army_rebel_control_is_valid(ar_reb_control))
1339 auto ar = arc.get_army();
1340 if(!ar.get_army_rebel_control().get_controller())
1342 if(ar.get_arrival_time() !=
sys::date{})
1344 if(ar.get_battle_from_army_battle_participation())
1346 if(ar.get_navy_from_army_transport())
1349 auto type = arc.get_controller().get_type();
1350 auto area = arc.get_controller().get_type().get_area();
1351 auto location = ar.get_location_from_army_location();
1353 if(location.get_nation_from_province_control() && !location.get_rebel_faction_from_province_rebel_control()) {
1356 dcon::province_fat_id best_prov = location;
1357 float best_weight = 0.f;
1358 for(
const auto adj : location.get_province_adjacency()) {
1359 auto indx = adj.get_connected_provinces(0) != location.id ? 0 : 1;
1360 auto prov = adj.get_connected_provinces(indx);
1362 if(prov.id.index() >= state.province_definitions.first_sea_province.index())
1365 if((adj.get_type() & province::border::impassible_bit) != 0)
1367 if(allow_in_area(state, prov, arc.get_controller())) {
1369 float weight = float(rng::get_random(state, uint32_t(prov.id.index() * ar.id.index())) % 100);
1373 if(prov.get_rebel_faction_from_province_rebel_control()) {
1376 if(weight >= best_weight) {
1377 best_weight = weight;
1382 if(best_prov != location) {
1383 ar.get_path().resize(1);
1384 ar.get_path()[0] = best_prov;
1387 ar.set_is_rebel_hunter(
false);
#define assert(condition)
float estimate_army_offensive_strength(sys::state &state, dcon::army_id a)
float estimate_rebel_strength(sys::state &state, dcon::province_id p)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
void execute(sys::state &state, dcon::effect_key key, int32_t primary, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
void army_arrives_in_province(sys::state &state, dcon::army_id a, dcon::province_id p, crossing_type crossing, dcon::land_battle_id from)
bool rebel_army_in_province(sys::state &state, dcon::province_id p)
sys::date arrival_time_to(sys::state &state, dcon::army_id a, dcon::province_id p)
dcon::regiment_id create_new_regiment(sys::state &state, dcon::nation_id n, dcon::unit_type_id t)
void adjust_prestige(sys::state &state, dcon::nation_id n, float delta)
void destroy_diplomatic_relationships(sys::state &state, dcon::nation_id n)
float prestige_score(sys::state const &state, dcon::nation_id n)
void create_nation_based_on_template(sys::state &state, dcon::nation_id n, dcon::nation_id base)
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
void post(sys::state &state, message &&m)
void force_nation_ideology(sys::state &state, dcon::nation_id n, dcon::ideology_id id)
void change_government_type(sys::state &state, dcon::nation_id n, dcon::government_type_id new_type)
void set_militancy(sys::state &state, dcon::pop_id p, float v)
void set_consciousness(sys::state &state, dcon::pop_id p, float v)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
float get_literacy(sys::state const &state, dcon::pop_id p)
float get_consciousness(sys::state const &state, dcon::pop_id p)
float get_militancy(sys::state const &state, dcon::pop_id p)
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
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)
bool is_overseas(sys::state const &state, dcon::province_id ids)
void for_each_land_province(sys::state &state, F const &func)
void set_province_controller(sys::state &state, dcon::province_id p, dcon::nation_id n)
void change_province_owner(sys::state &state, dcon::province_id id, dcon::nation_id new_owner)
dcon::rebel_faction_id get_faction_by_type(sys::state &state, dcon::nation_id n, dcon::rebel_type_id r)
bool pop_is_compatible_with_rebel_faction(sys::state &state, dcon::pop_id p, dcon::rebel_faction_id t)
void execute_province_defections(sys::state &state)
void add_pop_to_rebel_faction(sys::state &state, dcon::pop_id p, dcon::rebel_faction_id m)
void trigger_revolt(sys::state &state, dcon::nation_id n, dcon::rebel_type_id t, dcon::ideology_id i, dcon::culture_id c, dcon::religion_id r)
int32_t get_faction_brigades_active(sys::state &state, dcon::rebel_faction_id r)
void delete_faction(sys::state &state, dcon::rebel_faction_id reb)
bool issue_is_valid_for_movement(sys::state &state, dcon::nation_id nation_within, dcon::issue_option_id i)
bool movement_is_valid(sys::state &state, dcon::movement_id m)
constexpr float org_gain_factor
void rebel_risings_check(sys::state &state)
bool sphere_member_has_ongoing_revolt(sys::state &state, dcon::nation_id n)
float get_faction_organization(sys::state &state, dcon::rebel_faction_id r)
constexpr float rebel_size_reduction
void update_movement_values(sys::state &state)
void update_armies(sys::state &state)
void get_hunting_targets(sys::state &state, dcon::nation_id n, std::vector< impl::prov_str > &rebel_provs)
std::string rebel_name(sys::state &state, dcon::rebel_faction_id reb)
void update_factions(sys::state &state)
void suppress_movement(sys::state &state, dcon::nation_id n, dcon::movement_id m)
void remove_pop_from_movement(sys::state &state, dcon::pop_id p)
dcon::movement_id get_movement_by_independence(sys::state &state, dcon::nation_id n, dcon::national_identity_id i)
float get_faction_revolt_risk(sys::state &state, dcon::rebel_faction_id r)
bool allow_in_area(sys::state &state, dcon::province_id p, dcon::rebel_faction_id reb)
void remove_pop_from_rebel_faction(sys::state &state, dcon::pop_id p)
float get_suppression_point_cost(sys::state &state, dcon::movement_id m)
void execute_rebel_victories(sys::state &state)
void sort_hunting_targets(sys::state &state, impl::arm_str const &ar, std::vector< impl::prov_str > &rebel_provs)
void add_pop_to_movement(sys::state &state, dcon::pop_id p, dcon::movement_id m)
void daily_update_rebel_organization(sys::state &state)
int32_t get_faction_brigades_ready(sys::state &state, dcon::rebel_faction_id r)
bool pop_is_compatible_with_rebel_type(sys::state &state, dcon::pop_id p, dcon::rebel_type_id t)
void update_movements(sys::state &state)
void update_pop_movement_membership(sys::state &state)
bool rebel_faction_is_valid(sys::state &state, dcon::rebel_faction_id m)
void turn_movement_into_rebels(sys::state &state, dcon::movement_id m)
dcon::movement_id get_movement_by_position(sys::state &state, dcon::nation_id n, dcon::issue_option_id o)
void update_pop_rebel_membership(sys::state &state)
void rebel_hunting_check(sys::state &state)
uint32_t reduce(uint32_t value_in, uint32_t upper_bound)
uint64_t get_random(sys::state const &state, uint32_t value_in)
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
layout_box open_layout_box(layout_base &dest, int32_t indent)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
dcon::text_key get_adjective(sys::state &state, dcon::nation_id id)
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
void close_layout_box(columnar_layout &dest, layout_box &box)
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)
float evaluate_multiplicative_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
void effect_description(sys::state &state, text::layout_base &layout, dcon::effect_key k, int32_t primary_slot, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
float to_float(int32_t a)
Holds important data about the game world, state, and other data regarding windowing,...