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())
414 auto fac = fatten(state.world, t);
415 auto pop = fatten(state.world, p);
417 if(fac.get_independence() != 0 || fac.get_defection() != 0) {
420 if(pop.get_is_primary_or_accepted_culture())
423 if(pop.get_is_primary_or_accepted_culture())
426 for(
auto core : pop.get_province_from_pop_location().get_core()) {
427 if(core.get_identity().get_primary_culture() == pop.get_culture())
434 if(!pop.get_is_primary_or_accepted_culture()) {
438 if(fac.get_ideology() && fac.get_ideology() != pop.get_dominant_ideology()) {
445 state.world.for_each_pop([&](dcon::pop_id p) {
452 auto existing_faction = state.world.pop_get_rebel_faction_from_pop_rebellion_membership(p);
455 if(mil >= state.defines.mil_to_join_rebel) {
459 auto prov = state.world.pop_get_province_from_pop_location(p);
465 auto occupying_faction = state.world.province_get_rebel_faction_from_province_rebel_control(prov);
467 assert(!
bool(state.world.province_get_nation_from_province_control(prov)));
477 float greatest_chance = 0.0f;
478 dcon::rebel_faction_id f;
479 for(
auto rf : state.world.nation_get_rebellion_within(owner)) {
481 auto chance = rf.get_rebels().get_type().get_spawn_chance();
484 if(eval > greatest_chance) {
486 greatest_chance = eval;
491 dcon::rebel_faction_id temp = state.world.create_rebel_faction();
492 dcon::national_identity_id ind_tag = [&]() {
493 auto prov = state.world.pop_get_province_from_pop_location(p);
494 for(
auto core : state.world.province_get_core(prov)) {
495 if(!core.get_identity().get_is_not_releasable() && core.get_identity().get_primary_culture() == state.world.pop_get_culture(p))
496 return core.get_identity().id;
498 return dcon::national_identity_id{};
501 dcon::rebel_type_id max_type;
503 state.world.for_each_rebel_type([&](dcon::rebel_type_id rt) {
505 state.world.rebel_faction_set_type(temp, rt);
506 state.world.rebel_faction_set_defection_target(temp, dcon::national_identity_id{});
507 state.world.rebel_faction_set_primary_culture(temp, dcon::culture_id{});
508 state.world.rebel_faction_set_primary_culture_group(temp, dcon::culture_group_id{});
509 state.world.rebel_faction_set_religion(temp, dcon::religion_id{});
513 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
514 state.world.rebel_faction_set_defection_target(temp, ind_tag);
517 if(state.world.pop_get_is_primary_or_accepted_culture(p))
521 state.world.rebel_faction_set_primary_culture_group(temp,
522 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
523 state.world.rebel_faction_set_defection_target(temp, ind_tag);
526 if(state.world.pop_get_is_primary_or_accepted_culture(p))
530 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
531 state.world.rebel_faction_set_defection_target(temp, ind_tag);
534 if(state.world.pop_get_is_primary_or_accepted_culture(p))
538 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
539 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
542 state.world.rebel_faction_set_defection_target(temp, u);
546 state.world.rebel_faction_set_defection_target(temp, ind_tag);
549 if(state.world.pop_get_is_primary_or_accepted_culture(p))
558 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
559 state.world.rebel_faction_set_defection_target(temp, ind_tag);
562 if(state.world.pop_get_is_primary_or_accepted_culture(p))
566 state.world.rebel_faction_set_primary_culture_group(temp,
567 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
568 state.world.rebel_faction_set_defection_target(temp, ind_tag);
571 if(state.world.pop_get_is_primary_or_accepted_culture(p))
575 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
576 state.world.rebel_faction_set_defection_target(temp, ind_tag);
579 if(state.world.pop_get_is_primary_or_accepted_culture(p))
583 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
584 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
587 if(state.world.pop_get_is_primary_or_accepted_culture(p))
589 state.world.rebel_faction_set_defection_target(temp, u);
593 state.world.rebel_faction_set_defection_target(temp, ind_tag);
596 if(state.world.pop_get_is_primary_or_accepted_culture(p))
600 state.world.rebel_faction_set_defection_target(temp, ind_tag);
603 if(state.world.pop_get_is_primary_or_accepted_culture(p))
610 auto chance = state.world.rebel_type_get_spawn_chance(rt);
613 if(eval > greatest_chance) {
616 greatest_chance = eval;
622 state.world.delete_rebel_faction(temp);
625 state.world.rebel_faction_set_type(temp, rt);
626 state.world.rebel_faction_set_defection_target(temp, dcon::national_identity_id{});
627 state.world.rebel_faction_set_primary_culture(temp, dcon::culture_id{});
628 state.world.rebel_faction_set_primary_culture_group(temp, dcon::culture_group_id{});
629 state.world.rebel_faction_set_religion(temp, dcon::religion_id{});
633 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
634 state.world.rebel_faction_set_defection_target(temp, ind_tag);
637 state.world.rebel_faction_set_primary_culture_group(temp,
638 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
639 state.world.rebel_faction_set_defection_target(temp, ind_tag);
642 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
643 state.world.rebel_faction_set_defection_target(temp, ind_tag);
646 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
647 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
648 state.world.rebel_faction_set_defection_target(temp, u);
652 state.world.rebel_faction_set_defection_target(temp, ind_tag);
660 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
661 state.world.rebel_faction_set_defection_target(temp, ind_tag);
664 state.world.rebel_faction_set_primary_culture_group(temp,
665 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
666 state.world.rebel_faction_set_defection_target(temp, ind_tag);
669 state.world.rebel_faction_set_religion(temp, state.world.pop_get_religion(p));
670 state.world.rebel_faction_set_defection_target(temp, ind_tag);
673 auto cg = state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p));
674 auto u = state.world.culture_group_get_identity_from_cultural_union_of(cg);
675 state.world.rebel_faction_set_defection_target(temp, u);
679 state.world.rebel_faction_set_defection_target(temp, ind_tag);
682 state.world.rebel_faction_set_defection_target(temp, ind_tag);
688 if(state.world.rebel_type_get_culture_restriction(rt) && !state.world.rebel_faction_get_primary_culture(temp)) {
689 state.world.rebel_faction_set_primary_culture(temp, state.world.pop_get_culture(p));
691 if(state.world.rebel_type_get_culture_group_restriction(rt) && !state.world.rebel_faction_get_primary_culture_group(temp)) {
692 state.world.rebel_faction_set_primary_culture_group(temp, state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(p)));
695 state.world.try_create_rebellion_within(temp, owner);
698 if(greatest_chance > 0) {
704 if(existing_faction) {
712 auto control = state.world.rebel_faction_get_province_rebel_control(reb);
713 for(
auto p : control) {
714 auto prov = p.get_province();
717 state.world.delete_rebel_faction(reb);
723 for(
auto last = state.world.rebel_faction_size(); last-- > 0;) {
724 dcon::rebel_faction_id m{dcon::rebel_faction_id::value_base_t(last)};
726 for(
auto members : state.world.rebel_faction_get_pop_rebellion_membership(m)) {
738 state.world.for_each_rebel_faction([&](dcon::rebel_faction_id rf) {
740 for(
auto pop : state.world.rebel_faction_get_pop_rebellion_membership(rf)) {
741 total += int32_t(state.world.pop_get_size(pop.get_pop()) / state.defines.pop_size_per_regiment);
743 state.world.rebel_faction_set_possible_regiments(rf, total);
747 state.world.for_each_rebel_faction([&](dcon::rebel_faction_id rf) {
756 float total_change = 0;
757 for(
auto pop : state.world.rebel_faction_get_pop_rebellion_membership(rf)) {
758 auto mil_factor = [&]() {
759 auto m = pop_demographics::get_militancy(state, pop.get_pop());
760 if(m > state.defines.mil_to_autorise)
762 else if(m > state.defines.mil_to_join_rising)
768 auto reg_count = state.world.rebel_faction_get_possible_regiments(rf);
769 auto within = state.world.rebel_faction_get_ruler_from_rebellion_within(rf);
770 auto rebel_org_mod = 1.0f + state.world.nation_get_rebel_org_modifier(within, state.world.rebel_faction_get_type(rf));
773 state.world.rebel_faction_set_organization(rf,
775 state.world.rebel_faction_get_organization(rf) +
777 (1.0f + state.world.nation_get_rebel_org_modifier(within, state.world.rebel_faction_get_type(rf))) *
778 0.001f / (1.0f + state.world.nation_get_administrative_efficiency(within)) / float(reg_count)));
784 assert(rebel_provs.empty());
786 for(
auto prov : nat.get_province_ownership()) {
787 if(prov.get_province().get_rebel_faction_from_province_rebel_control()
794 auto our_str = ar.
str;
795 auto loc = state.world.army_get_location_from_army_location(ar.
a);
797 auto aa = 0.001f * -(our_str - a.str);
798 auto ab = 0.001f * -(our_str - b.str);
799 auto da = province::sorting_distance(state, a.p, loc) + aa;
800 auto db = province::sorting_distance(state, b.p, loc) + ab;
804 return a.p.index() < b.p.index();
809 for(
auto rf : state.world.in_rebel_faction) {
810 auto const faction_owner = rf.get_ruler_from_rebellion_within();
812 if(faction_owner.get_is_player_controlled()) {
813 static std::vector<impl::arm_str> rebel_hunters;
814 rebel_hunters.clear();
815 for(
auto ar : faction_owner.get_army_control()) {
816 auto loc = ar.get_army().get_location_from_army_location();
817 if(ar.get_army().get_is_rebel_hunter()
818 && !ar.get_army().get_battle_from_army_battle_participation()
819 && !ar.get_army().get_navy_from_army_transport()
820 && !ar.get_army().get_arrival_time()
821 && loc.get_nation_from_province_control() == faction_owner
827 static std::vector<impl::prov_str> rebel_provs;
831 while(rebel_provs.size() > 0 && rebel_hunters.size() > 0) {
832 auto rh = rebel_hunters[0];
835 auto closest_prov = rebel_provs[0].p;
837 auto pa = state.world.army_get_location_from_army_location(a.a);
838 auto pb = state.world.army_get_location_from_army_location(b.a);
839 auto as = 0.001f * std::max<float>(a.str, 1.f);
840 auto bs = 0.001f * std::max<float>(b.str, 1.f);
841 auto da = province::sorting_distance(state, pa, closest_prov) + as;
842 auto db = province::sorting_distance(state, pb, closest_prov) + bs;
846 return a.a.index() < b.a.index();
849 for(
uint32_t i = 0; i < rebel_hunters.size(); ++i) {
850 auto a = rebel_hunters[i].
a;
851 if(state.world.army_get_location_from_army_location(a) == closest_prov) {
852 state.world.army_get_path(a).clear();
853 state.world.army_set_arrival_time(a,
sys::date{});
855 rebel_hunters[i] = rebel_hunters.back();
856 rebel_hunters.pop_back();
858 }
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) {
859 auto existing_path = state.world.army_get_path(a);
860 auto new_size =
uint32_t(path.size());
861 existing_path.resize(new_size);
862 for(
uint32_t j = 0; j < new_size; j++) {
863 existing_path.at(j) = path[j];
866 state.world.army_set_dig_in(a, 0);
868 rebel_hunters[i] = rebel_hunters.back();
869 rebel_hunters.pop_back();
873 rebel_provs[0] = rebel_provs.back();
874 rebel_provs.pop_back();
879 for(
const auto a : state.world.in_army) {
880 if(a.get_is_rebel_hunter()
881 && !a.get_battle_from_army_battle_participation()
882 && !a.get_navy_from_army_transport()
883 && !a.get_arrival_time()
884 && a.get_location_from_army_location() != a.get_ai_province()
885 && a.get_location_from_army_location().get_province_control().get_nation() == a.get_location_from_army_location().get_province_ownership().get_nation())
887 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) {
888 auto existing_path = state.world.army_get_path(a);
889 auto new_size =
uint32_t(path.size());
890 existing_path.resize(new_size);
891 for(
uint32_t j = 0; j < new_size; j++) {
892 existing_path.at(j) = path[j];
895 state.world.army_set_dig_in(a, 0);
897 state.world.army_set_ai_province(a, state.world.army_get_location_from_army_location(a));
906 static std::vector<dcon::army_id> new_armies;
909 for(
auto rf : state.world.in_rebel_faction) {
912 float p_val = float(rval & 0xFFFF) / float(0x10000);
913 if(p_val < revolt_chance) {
914 auto const faction_owner = rf.get_ruler_from_rebellion_within();
916 auto counter = new_to_make;
924 for(
auto pop : rf.get_pop_rebellion_membership()) {
929 auto location = pop.get_pop().get_province_from_pop_location();
932 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));
933 auto cregs = pop.get_pop().get_regiment_source();
934 auto used_count = int32_t(cregs.end() - cregs.begin());
936 if(used_count < max_count) {
937 auto pop_location = pop.get_pop().get_province_from_pop_location();
941 for(
auto ar : state.world.province_get_army_location(pop_location)) {
942 if(!(ar.get_army().get_battle_from_army_battle_participation()) && ar.get_army().get_controller_from_army_rebel_control() == rf)
943 return ar.get_army().id;
945 auto new_army = fatten(state.world, state.world.create_army());
946 new_army.set_controller_from_army_rebel_control(rf);
947 new_army.set_location_from_army_location(pop_location);
948 new_armies.push_back(new_army);
951 state.world.try_create_army_membership(new_reg, a);
952 state.world.try_create_regiment_source(new_reg, pop.get_pop());
963 rf.set_organization(0);
964 if(counter != new_to_make) {
969 ankerl::unordered_dense::map<int32_t, int32_t> provs;
970 for(
auto ar : state.world.rebel_faction_get_army_rebel_control(reb)) {
971 if(ar.get_controller() == reb) {
972 auto p = ar.get_army().get_location_from_army_location();
973 provs[p.id.index()] += 1;
976 for(
auto p : provs) {
986 rf.get_ruler_from_rebellion_within(), dcon::nation_id{}, dcon::nation_id{},
992 for(
auto a : new_armies) {
993 if(!state.world.army_get_battle_from_army_battle_participation(a))
999 auto nation_count = state.world.nation_size();
1000 for(
uint32_t i = 0; i < nation_count; ++i) {
1001 dcon::nation_id m{dcon::nation_id::value_base_t(i)};
1002 if(state.world.nation_get_in_sphere_of(m) == n) {
1003 for(
auto fac : state.world.nation_get_rebellion_within(m)) {
1018 for(
auto ar : state.world.rebel_faction_get_army_rebel_control(r)) {
1019 auto regs = ar.get_army().get_army_membership();
1020 total += int32_t(regs.end() - regs.begin());
1026 return state.world.rebel_faction_get_organization(r);
1034 auto nation_brigades =
1035 std::max(1, int32_t(state.world.nation_get_active_regiments(state.world.rebel_faction_get_ruler_from_rebellion_within(r))));
1038 auto faction_org = state.world.rebel_faction_get_organization(r);
1040 if(num_brigades_ready <= 0) {
1044 float chance = std::clamp(
1045 faction_org * 0.05f + 0.02f + faction_org *
float(num_brigades_ready) / (
float(nation_brigades) * 20.0f), 0.0f, 1.0f);
1051 auto reb_controller = state.world.province_get_rebel_faction_from_province_rebel_control(p);
1052 auto owner = state.world.province_get_nation_from_province_ownership(p);
1053 if(reb_controller && owner) {
1054 assert(!
bool(state.world.province_get_nation_from_province_control(p)));
1055 auto reb_type = state.world.rebel_faction_get_type(reb_controller);
1057 if(def_type !=
culture::rebel_defection::none && state.world.province_get_last_control_change(p) + reb_type.get_defect_delay() * 31 <= state.current_date) {
1060 dcon::nation_id defection_tag = [&]() {
1064 for(
auto c : state.world.province_get_core(p)) {
1065 auto holder = c.get_identity().get_nation_from_identity_holder();
1066 if(holder.get_ruling_party().get_ideology() == reb_type.get_ideology() && holder.get_owned_province_count() != 0) {
1067 return c.get_identity().get_nation_from_identity_holder().id;
1071 for(
auto c : state.world.province_get_core(p)) {
1072 auto holder = c.get_identity().get_nation_from_identity_holder();
1073 if(!c.get_identity().get_is_not_releasable() && holder.get_owned_province_count() == 0) {
1074 auto t = c.get_identity().get_nation_from_identity_holder().id;
1084 for(
auto c : state.world.province_get_core(p)) {
1085 auto holder = c.get_identity().get_nation_from_identity_holder();
1086 if(holder.get_religion() == state.world.rebel_faction_get_religion(reb_controller) && holder.get_owned_province_count() != 0) {
1087 return c.get_identity().get_nation_from_identity_holder().id;
1091 for(
auto c : state.world.province_get_core(p)) {
1092 auto holder = c.get_identity().get_nation_from_identity_holder();
1093 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) {
1094 auto t = c.get_identity().get_nation_from_identity_holder().id;
1102 for(
auto c : state.world.province_get_core(p)) {
1103 auto holder = c.get_identity().get_nation_from_identity_holder();
1104 if(c.get_identity().get_primary_culture() == state.world.rebel_faction_get_primary_culture(reb_controller) && holder.get_owned_province_count() != 0) {
1105 return c.get_identity().get_nation_from_identity_holder().id;
1109 for(
auto c : state.world.province_get_core(p)) {
1110 auto holder = c.get_identity().get_nation_from_identity_holder();
1111 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) {
1112 auto t = c.get_identity().get_nation_from_identity_holder().id;
1120 for(
auto c : state.world.province_get_core(p)) {
1121 auto holder = c.get_identity().get_nation_from_identity_holder();
1122 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) {
1123 return c.get_identity().get_nation_from_identity_holder().id;
1127 for(
auto c : state.world.province_get_core(p)) {
1128 auto holder = c.get_identity().get_nation_from_identity_holder();
1129 if(!c.get_identity().get_is_not_releasable()
1130 && c.get_identity().get_primary_culture().get_group_from_culture_group_membership() == state.world.rebel_faction_get_primary_culture_group(reb_controller)
1131 && holder.get_owned_province_count() == 0) {
1133 auto t = c.get_identity().get_nation_from_identity_holder().id;
1144 for(
auto c : state.world.province_get_core(p)) {
1145 auto holder = c.get_identity().get_nation_from_identity_holder();
1146 if(c.get_identity() == state.world.rebel_faction_get_defection_target(reb_controller) && holder.get_owned_province_count() != 0) {
1152 return dcon::nation_id{};
1154 return dcon::nation_id{};
1174 if(state.defines.population_suppression_factor > 0.0f) {
1175 return std::max(state.world.movement_get_radicalism(m) + 1.0f, state.world.movement_get_radicalism(m) *
1176 state.world.movement_get_pop_support(m) / state.defines.population_suppression_factor);
1178 return state.world.movement_get_radicalism(m) + 1.0f;
1183 for(
uint32_t i = state.world.rebel_faction_size(); i-- > 0;) {
1184 auto reb = dcon::rebel_faction_id{dcon::rebel_faction_id::value_base_t(i)};
1185 auto within = state.world.rebel_faction_get_ruler_from_rebellion_within(reb);
1187 auto enforce_trigger = state.world.rebel_faction_get_type(reb).get_demands_enforced_trigger();
1188 if(is_active && enforce_trigger &&
1198 auto old_gov = state.world.nation_get_government_type(within);
1200 auto new_gov = state.world.rebel_faction_get_type(reb).get_government_change(old_gov);
1204 if(
auto iid = state.world.rebel_faction_get_type(reb).get_ideology(); iid) {
1208 for(
auto members : state.world.rebel_faction_get_pop_rebellion_membership(reb)) {
1217 if(state.world.rebel_faction_get_type(reb).get_break_alliance_on_win()) {
1233 if(
auto k = state.world.rebel_faction_get_type(reb).get_demands_enforced_effect(); k)
1235 uint32_t(state.current_date.value),
uint32_t(within.index() ^ (reb.index() << 4)));
1238 [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) {
1240 text::add_line(state, contents,
"msg_rebels_win_1", text::variable_type::x, state.world.rebel_type_get_title(type));
1241 text::add_line(state, contents,
"msg_rebels_win_2", text::variable_type::x, text::fp_one_place{ploss});
1245 if(
auto iid = state.world.rebel_type_get_ideology(type); iid) {
1248 if(state.world.rebel_type_get_break_alliance_on_win(type)) {
1251 if(
auto k = state.world.rebel_type_get_demands_enforced_effect(type); k) {
1256 "msg_rebels_win_title",
1257 within, dcon::nation_id{}, dcon::nation_id{},
1270 dcon::religion_id r) {
1277 auto culture = state.world.rebel_faction_get_primary_culture(reb);
1278 auto religion = state.world.rebel_faction_get_religion(reb);
1279 auto defection_target = state.world.rebel_faction_get_defection_target(reb);
1280 auto in_nation = state.world.rebel_faction_get_ruler_from_rebellion_within(reb);
1282 auto adjective = defection_target.get_adjective();
1297 if(defection_target) {
1314 return prov.get_dominant_culture() == rf.get_primary_culture();
1316 return prov.get_dominant_culture().get_culture_group_membership().get_group() == rf.get_primary_culture_group();
1318 return prov.get_dominant_religion() == rf.get_religion();
1320 return prov.get_dominant_religion() == rf.get_defection_target().get_religion() && prov.get_province_ownership().get_nation() == rf.get_rebellion_within().get_ruler();
1322 return prov.get_dominant_culture() == rf.get_defection_target().get_primary_culture() && prov.get_province_ownership().get_nation() == rf.get_rebellion_within().get_ruler();
1324 return prov.get_province_ownership().get_nation() == rf.get_rebellion_within().get_ruler();
1332 concurrency::parallel_for(
uint32_t(0), state.world.army_rebel_control_size(), [&](
uint32_t i) {
1333 auto ar_reb_control = dcon::army_rebel_control_id{ dcon::army_rebel_control_id::value_base_t(i) };
1334 if(!state.world.army_rebel_control_is_valid(ar_reb_control))
1337 auto ar = arc.get_army();
1338 if(!ar.get_army_rebel_control().get_controller())
1340 if(ar.get_arrival_time() !=
sys::date{})
1342 if(ar.get_battle_from_army_battle_participation())
1344 if(ar.get_navy_from_army_transport())
1347 auto type = arc.get_controller().get_type();
1348 auto area = arc.get_controller().get_type().get_area();
1349 auto location = ar.get_location_from_army_location();
1351 if(location.get_nation_from_province_control() && !location.get_rebel_faction_from_province_rebel_control()) {
1354 dcon::province_fat_id best_prov = location;
1355 float best_weight = 0.f;
1356 for(
const auto adj : location.get_province_adjacency()) {
1357 auto indx = adj.get_connected_provinces(0) != location.id ? 0 : 1;
1358 auto prov = adj.get_connected_provinces(indx);
1360 if(prov.id.index() >= state.province_definitions.first_sea_province.index())
1363 if((adj.get_type() & province::border::impassible_bit) != 0)
1365 if(allow_in_area(state, prov, arc.get_controller())) {
1367 float weight = float(rng::get_random(state, uint32_t(prov.id.index() * ar.id.index())) % 100);
1371 if(prov.get_rebel_faction_from_province_rebel_control()) {
1374 if(weight >= best_weight) {
1375 best_weight = weight;
1380 if(best_prov != location) {
1381 ar.get_path().resize(1);
1382 ar.get_path()[0] = best_prov;
1385 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)