2#include "dcon_generated.hpp"
13 state.world.for_each_province([&](dcon::province_id
province) {
14 if(nation == state.world.province_get_nation_from_province_ownership(
province)) {
15 for(auto pop_loc : state.world.province_get_pop_location(province)) {
16 auto pop_id = pop_loc.get_pop();
17 total += pop_vote_weight(state, pop_id, nation);
30 return state.world.nation_get_demographics(nation, dkey) / total;
41 for(
auto province : state.world.nation_get_province_ownership(nation)) {
42 for(
auto pop_loc :
province.get_province().get_pop_location()) {
43 auto pop_id = pop_loc.get_pop();
48 return support / total;
52 return dcon::fatten(state.world, nation).get_government_type().get_can_appoint_ruling_party();
56 auto election_end_date =
dcon::fatten(state.world, nation).get_election_ends();
57 return election_end_date && election_end_date > state.current_date;
61 return dcon::fatten(state.world, nation).get_government_type().get_has_elections();
65 auto end_date = state.world.nation_get_election_ends(nation);
66 return end_date + int32_t(30.5f * state.world.nation_get_government_type(nation).get_duration());
70 dcon::reform_id result{};
71 auto it = state.lookup_key(name);
73 state.world.for_each_reform([&](dcon::reform_id reform_id) {
74 auto key = state.world.reform_get_name(reform_id);
84 dcon::issue_id result{};
85 auto it = state.lookup_key(name);
87 state.world.for_each_issue([&](dcon::issue_id issue_id) {
88 auto key = state.world.issue_get_name(issue_id);
98 auto reform = state.world.reform_option_get_parent_reform(reform_option);
99 return reform && reform_option == state.world.nation_get_reforms(nation, reform);
103 auto issue = state.world.issue_option_get_parent_issue(issue_option);
104 return issue && issue_option == state.world.nation_get_issues(nation, issue);
111 auto issue = state.world.issue_option_get_parent_issue(issue_option);
112 auto current = state.world.nation_get_issues(nation, issue.id).id;
113 auto allow = state.world.issue_option_get_allow(issue_option);
114 auto time_limit = state.world.nation_get_last_issue_or_reform_change(nation);
115 auto tag = state.world.nation_get_identity_from_identity_holder(nation);
116 auto start = state.world.national_identity_get_political_party_first(tag).id.index();
117 auto end = start + state.world.national_identity_get_political_party_count(tag);
118 auto count_party_issues = state.world.political_party_get_party_issues_size();
120 if(current != issue_option && (!time_limit || (time_limit + int32_t(state.defines.min_delay_between_reforms * 30) <= state.current_date)) &&
121 (!state.world.issue_get_is_next_step_only(issue.id) || current.index() + 1 == issue_option.index() ||
122 current.index() - 1 == issue_option.index()) &&
126 for(
uint32_t icounter = state.world.ideology_size(); icounter-- > 0;) {
127 dcon::ideology_id iid{dcon::ideology_id::value_base_t(icounter)};
128 auto condition = issue_option.index() > current.index() ? state.world.ideology_get_add_political_reform(iid) : state.world.ideology_get_remove_political_reform(iid);
129 auto upperhouse_weight = 0.01f * state.world.nation_get_upper_house(nation, iid);
131 float party_special_issues_support_total = 0.0f;
132 float count_found = 0.0f;
136 for(int32_t i = start; i < end; i++) {
137 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
139 && (state.world.nation_get_government_type(nation).get_ideologies_allowed() &
culture::to_bits(state.world.political_party_get_ideology(pid))) != 0
140 && state.world.political_party_get_ideology(pid) == iid) {
142 if(
auto special_opt = state.world.political_party_get_party_issues(pid, issue); special_opt) {
143 if(special_opt == issue_option
144 || (state.world.issue_get_is_next_step_only(issue.id)
145 && ((special_opt.id.index() > current.index() && issue_option.index() > current.index())
146 || (special_opt.id.index() < current.index() && issue_option.index() < current.index())
150 party_special_issues_support_total = upperhouse_weight;
152 party_special_issues_support_total = 0.0f;
156 for(
uint32_t j = 0; j < count_party_issues; ++j) {
157 auto popt = state.world.political_party_get_party_issues(pid, dcon::issue_id{ dcon::issue_id::value_base_t(j) });
158 auto opt_mod = state.world.issue_option_get_support_modifiers(popt, issue_option);
170 if(count_found > 0.0f)
171 total += std::clamp(party_special_issues_support_total / count_found, -1.0f, 1.0f);
172 else if(condition && upperhouse_weight > 0.0f)
185 auto issue = state.world.issue_option_get_parent_issue(o);
186 auto current = state.world.nation_get_issues(n, issue.id).id;
187 auto allow = state.world.issue_option_get_allow(o);
188 auto time_limit = state.world.nation_get_last_issue_or_reform_change(n);
189 auto tag = state.world.nation_get_identity_from_identity_holder(n);
190 auto start = state.world.national_identity_get_political_party_first(tag).id.index();
191 auto end = start + state.world.national_identity_get_political_party_count(tag);
192 auto count_party_issues = state.world.political_party_get_party_issues_size();
194 if(current != o && (!time_limit || (time_limit + int32_t(state.defines.min_delay_between_reforms * 30) <= state.current_date)) &&
195 (!state.world.issue_get_is_next_step_only(issue.id) || current.index() + 1 == o.index() ||
196 current.index() - 1 == o.index()) &&
200 for(
uint32_t icounter = state.world.ideology_size(); icounter-- > 0;) {
201 dcon::ideology_id iid{dcon::ideology_id::value_base_t(icounter)};
202 auto condition = o.index() > current.index() ? state.world.ideology_get_add_social_reform(iid) : state.world.ideology_get_remove_social_reform(iid);
203 auto upperhouse_weight = 0.01f * state.world.nation_get_upper_house(n, iid);
205 float party_special_issues_support_total = 0.0f;
206 float count_found = 0.0f;
208 for(int32_t i = start; i < end; i++) {
209 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
211 && (state.world.nation_get_government_type(n).get_ideologies_allowed() &
culture::to_bits(state.world.political_party_get_ideology(pid))) != 0
212 && state.world.political_party_get_ideology(pid) == iid) {
214 if(
auto special_opt = state.world.political_party_get_party_issues(pid, issue); special_opt) {
216 || (state.world.issue_get_is_next_step_only(issue.id)
217 && ((special_opt.id.index() > current.index() && o.index() > current.index())
218 || (special_opt.id.index() < current.index() && o.index() < current.index())
222 party_special_issues_support_total = upperhouse_weight;
224 party_special_issues_support_total = 0.0f;
228 for(
uint32_t j = 0; j < count_party_issues; ++j) {
229 auto popt = state.world.political_party_get_party_issues(pid, dcon::issue_id{ dcon::issue_id::value_base_t(j) });
230 auto opt_mod = state.world.issue_option_get_support_modifiers(popt, o);
242 if(count_found > 0.0f)
243 total += std::clamp(party_special_issues_support_total / count_found, -1.0f, 1.0f);
244 else if(condition && upperhouse_weight > 0.0f)
257 auto reform = state.world.reform_option_get_parent_reform(o);
258 auto current = state.world.nation_get_reforms(n, reform.id).id;
259 auto allow = state.world.reform_option_get_allow(o);
260 auto stored_rp = state.world.nation_get_research_points(n);
261 if(o.index() > current.index() && (!state.world.reform_get_is_next_step_only(reform.id) || current.index() + 1 == o.index()) &&
264 float base_cost = float(state.world.reform_option_get_technology_cost(o));
267 if(base_cost * reform_factor <= stored_rp)
277 auto reform = state.world.reform_option_get_parent_reform(o);
278 auto current = state.world.nation_get_reforms(n, reform.id).id;
279 auto allow = state.world.reform_option_get_allow(o);
280 auto stored_rp = state.world.nation_get_research_points(n);
281 if(o.index() > current.index() && (!state.world.reform_get_is_next_step_only(reform.id) || current.index() + 1 == o.index()) &&
284 float base_cost = float(state.world.reform_option_get_technology_cost(o));
287 if(base_cost * reform_factor <= stored_rp)
294 float reform_factor = 1.0f +
295 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::self_unciv_military_modifier) +
296 state.world.nation_get_modifier_values(state.world.nation_get_in_sphere_of(n), sys::national_mod_offsets::unciv_military_modifier);
298 for(
uint32_t icounter = state.world.ideology_size(); icounter-- > 0;) {
299 dcon::ideology_id iid{dcon::ideology_id::value_base_t(icounter)};
300 auto condition = state.world.ideology_get_add_military_reform(iid);
301 auto upperhouse_weight = 0.01f * state.world.nation_get_upper_house(n, iid);
302 if(condition && upperhouse_weight > 0.0f)
305 return reform_factor;
309 float reform_factor = 1.0f +
310 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::self_unciv_economic_modifier) +
311 state.world.nation_get_modifier_values(state.world.nation_get_in_sphere_of(n), sys::national_mod_offsets::unciv_economic_modifier);
313 for(
uint32_t icounter = state.world.ideology_size(); icounter-- > 0;) {
314 dcon::ideology_id iid{dcon::ideology_id::value_base_t(icounter)};
315 auto condition = state.world.ideology_get_add_economic_reform(iid);
316 auto upperhouse_weight = 0.01f * state.world.nation_get_upper_house(n, iid);
317 if(condition && upperhouse_weight > 0.0f)
320 return reform_factor;
324 auto start_date = state.world.political_party_get_start_date(p);
325 auto end_date = state.world.political_party_get_end_date(p);
326 bool b = (!start_date || start_date <= state.current_date) && (!end_date || end_date > state.current_date);
327 if(
auto k = state.world.political_party_get_trigger(p); b && k) {
334 state.world.nation_set_ruling_party(n, p);
335 for(
auto pi : state.culture_definitions.party_issues) {
336 state.world.nation_set_issues(n, pi, state.world.political_party_get_party_issues(p, pi));
342 for(
auto po : state.world.nation_get_province_ownership_as_nation(n)) {
343 for(
auto fl : po.get_province().get_factory_location()) {
351 auto tag = state.world.nation_get_identity_from_identity_holder(n);
352 auto start = state.world.national_identity_get_political_party_first(tag).id.index();
353 auto end = start + state.world.national_identity_get_political_party_count(tag);
355 for(int32_t i = start; i < end; i++) {
356 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
365 int32_t reform_totals = 0;
366 for(
auto preform : state.culture_definitions.political_issues) {
367 auto creform = state.world.nation_get_issues(n, preform);
368 auto base_reform = state.world.issue_get_options(preform)[0];
369 reform_totals += creform.id.index() - base_reform.index();
371 for(
auto preform : state.culture_definitions.social_issues) {
372 auto creform = state.world.nation_get_issues(n, preform);
373 auto base_reform = state.world.issue_get_options(preform)[0];
374 reform_totals += creform.id.index() - base_reform.index();
377 auto angry_value = (0.1f * float(reform_totals) + 1.0f) * state.defines.ruling_party_angry_change;
378 auto happy_value = state.defines.ruling_party_happy_change;
387 auto old_party = state.world.nation_get_ruling_party(n);
389 for(
auto pa_id : state.culture_definitions.party_issues) {
390 auto new_id = state.world.political_party_get_party_issues(p, pa_id);
391 auto old_id = state.world.political_party_get_party_issues(old_party, pa_id);
393 if(new_id != old_id) {
394 for(
auto pr : state.world.nation_get_province_ownership(n)) {
395 for(
auto pop : pr.get_province().get_pop_location()) {
404 auto new_id = state.world.political_party_get_ideology(p);
405 auto old_id = state.world.political_party_get_ideology(old_party);
407 if(new_id != old_id) {
408 for(
auto pr : state.world.nation_get_province_ownership(n)) {
409 for(
auto pop : pr.get_province().get_pop_location()) {
418 state.world.nation_set_ruling_party_last_appointed(n, state.current_date);
423 state.world.for_each_ideology([&](
auto iid) { state.world.nation_set_upper_house(n, iid, 0.0f); });
424 state.world.nation_set_upper_house(n,
id, 100.0f);
430 auto ident = state.world.nation_get_identity_from_identity_holder(
id);
431 auto gov_id = state.world.nation_get_government_type(
id);
432 assert(!gov_id || state.world.government_type_is_valid(gov_id));
434 state.world.nation_set_color(
id, state.world.national_identity_get_government_color(
ident, gov_id));
436 state.world.nation_set_color(
id, state.world.national_identity_get_color(
ident));
438 state.province_ownership_changed.store(
true, std::memory_order::release);
442 auto old_gov = state.world.nation_get_government_type(n);
443 if(old_gov != new_type) {
444 assert(state.world.government_type_is_valid(new_type));
445 state.world.nation_set_government_type(n, new_type);
447 if((state.world.government_type_get_ideologies_allowed(new_type) &
culture::to_bits(state.world.nation_get_ruling_party(n).get_ideology())) == 0) {
449 auto tag = state.world.nation_get_identity_from_identity_holder(n);
450 auto start = state.world.national_identity_get_political_party_first(tag).id.index();
451 auto end = start + state.world.national_identity_get_political_party_count(tag);
453 for(int32_t i = start; i < end; i++) {
454 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
456 (state.world.government_type_get_ideologies_allowed(new_type) &
468 state.world.nation_set_election_ends(n,
sys::date{});
486 auto type = state.world.pop_get_poptype(p);
487 if(state.world.pop_type_get_voting_forbidden(type))
490 auto size = state.world.pop_get_size(p);
495 return std::max(0.0f, state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_vote));
497 return std::max(0.0f, state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_vote));
499 return std::max(0.0f, state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_vote));
505 auto rules = state.world.nation_get_combined_issue_rules(n);
507 if(state.world.pop_get_culture(p) == state.world.nation_get_primary_culture(n))
509 else if(state.world.pop_get_is_primary_or_accepted_culture(p))
510 return size * vmod * 0.5f;
514 if(state.world.pop_get_is_primary_or_accepted_culture(p))
533 static std::vector<float> accumulated_in_state;
534 accumulated_in_state.resize(state.world.ideology_size());
536 auto rules = state.world.nation_get_combined_issue_rules(n);
537 auto allowed_ideo = state.world.nation_get_government_type(n).get_ideologies_allowed();
541 auto rp_ideology = state.world.political_party_get_ideology(state.world.nation_get_ruling_party(n));
542 for(
auto i : state.world.in_ideology) {
543 state.world.nation_set_upper_house(n, i, 0.0f);
546 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
548 for(
auto i : state.world.in_ideology) {
549 state.world.nation_set_upper_house(n, i, 0.0f);
551 float state_total = 0.0f;
553 for(
auto si : state.world.nation_get_state_ownership(n)) {
554 if(si.get_state().get_capital().get_is_colonial())
557 for(
auto i : state.world.in_ideology) {
558 accumulated_in_state[i.id.index()] = 0.0f;
562 for(auto pop : state.world.province_get_pop_location(p)) {
563 auto weight = pop_vote_weight(state, pop.get_pop(), n);
565 for(auto i : state.world.in_ideology) {
566 if((allowed_ideo & culture::to_bits(i)) != 0)
567 accumulated_in_state[i.id.index()] += weight * pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, i));
573 for(
auto i : state.world.in_ideology) {
574 total += accumulated_in_state[i.id.index()];
577 for(
auto i : state.world.in_ideology) {
578 auto scaled = accumulated_in_state[i.id.index()] / total;
579 state_total += scaled;
580 state.world.nation_get_upper_house(n, i) += scaled;
585 if(state_total > 0) {
586 auto scale_factor = 100.0f / state_total;
587 for(
auto i : state.world.in_ideology) {
588 state.world.nation_get_upper_house(n, i) *= scale_factor;
591 auto rp_ideology = state.world.political_party_get_ideology(state.world.nation_get_ruling_party(n));
592 for(
auto i : state.world.in_ideology) {
593 state.world.nation_set_upper_house(n, i, 0.0f);
596 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
599 for(
auto i : state.world.in_ideology) {
600 state.world.nation_set_upper_house(n, i, 0.0f);
602 for(
auto p :
state.world.nation_get_province_ownership(n)) {
603 if(p.get_province().get_is_colonial())
606 for(
auto pop :
state.world.province_get_pop_location(p.get_province())) {
610 for(
auto i :
state.world.in_ideology) {
619 for(
auto i :
state.world.in_ideology) {
620 total +=
state.world.nation_get_upper_house(n, i);
623 auto scale_factor = 100.0f /
total;
624 for(
auto i :
state.world.in_ideology) {
625 state.world.nation_get_upper_house(n, i) *= scale_factor;
628 auto rp_ideology =
state.world.political_party_get_ideology(
state.world.nation_get_ruling_party(n));
629 for(
auto i :
state.world.in_ideology) {
630 state.world.nation_set_upper_house(n, i, 0.0f);
633 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
636 for(
auto i :
state.world.in_ideology) {
637 state.world.nation_set_upper_house(n, i, 0.0f);
639 for(
auto p :
state.world.nation_get_province_ownership(n)) {
640 if(p.get_province().get_is_colonial())
643 for(
auto pop :
state.world.province_get_pop_location(p.get_province())) {
646 for(
auto i :
state.world.in_ideology) {
654 for(
auto i :
state.world.in_ideology) {
655 total +=
state.world.nation_get_upper_house(n, i);
658 auto scale_factor = 100.0f /
total;
659 for(
auto i :
state.world.in_ideology) {
660 state.world.nation_get_upper_house(n, i) *= scale_factor;
663 auto rp_ideology =
state.world.political_party_get_ideology(
state.world.nation_get_ruling_party(n));
664 for(
auto i :
state.world.in_ideology) {
665 state.world.nation_set_upper_house(n, i, 0.0f);
668 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
672 if(n ==
state.local_player_nation) {
676 for(
auto i :
state.world.in_ideology) {
677 auto frac =
state.world.nation_get_upper_house(n, i);
683 "msg_upper_house_title",
684 n, dcon::nation_id{}, dcon::nation_id{},
692 auto si = state.world.province_get_state_membership(p);
693 auto nf = state.world.state_instance_get_owner_focus(si);
694 auto party = state.world.national_focus_get_ideology(nf);
696 auto& l = state.world.province_get_party_loyalty(p, party);
697 l = std::clamp(l + state.world.national_focus_get_loyalty_value(nf), -1.0f, 1.0f);
710 float ruling_party_support = p.get_modifier_values(sys::provincial_mod_offsets::local_ruling_party_support) + n.get_modifier_values(sys::national_mod_offsets::ruling_party_support) + 1.0f;
711 float prov_vote_mod = p.get_modifier_values(sys::provincial_mod_offsets::number_of_voters) + 1.0f;
713 auto pid = state.world.political_party_get_ideology(par_id);
714 auto base_support = (p.get_party_loyalty(pid) + 1.0f) * prov_vote_mod * (par_id == n.get_ruling_party() ? ruling_party_support : 1.0f) * weight;
715 auto issue_support = 0.0f;
716 for(
auto pi : state.culture_definitions.party_issues) {
717 auto party_pos = state.world.political_party_get_party_issues(par_id, pi);
721 return base_support * (issue_support * (1.0f - ideological_share) + ideology_support * ideological_share);
728 dcon::political_party_id
par;
733 if(state.world.nation_get_election_ends(n) < state.current_date) {
734 state.world.nation_set_election_ends(n, state.current_date + int32_t(state.defines.campaign_duration) * 30);
735 if(n == state.local_player_nation) {
736 auto end_date = state.world.nation_get_election_ends(n);
741 "msg_election_start_title",
742 n, dcon::nation_id{}, dcon::nation_id{},
752 static std::vector<party_vote> party_votes;
753 static std::vector<party_vote> provincial_party_votes;
755 for(
auto n : state.world.in_nation) {
761 if(n.get_election_ends() == state.current_date) {
765 float total_vote = 0.0f;
767 auto tag = state.world.nation_get_identity_from_identity_holder(n);
768 auto start = state.world.national_identity_get_political_party_first(tag).id.index();
769 auto end = start + state.world.national_identity_get_political_party_count(tag);
771 for(int32_t i = start; i < end; i++) {
772 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
774 && (n.get_government_type().get_ideologies_allowed() &
culture::to_bits(state.world.political_party_get_ideology(pid))) != 0) {
779 if(party_votes.size() == 0)
783 for(
auto p : n.get_province_ownership()) {
784 if(p.get_province().get_is_colonial())
787 provincial_party_votes.clear();
788 float province_total = 0.0f;
789 for(
auto& par : party_votes) {
793 float ruling_party_support =
794 p.get_province().get_modifier_values(sys::provincial_mod_offsets::local_ruling_party_support) +
795 n.get_modifier_values(sys::national_mod_offsets::ruling_party_support) + 1.0f;
796 float prov_vote_mod = p.get_province().get_modifier_values(sys::provincial_mod_offsets::number_of_voters) + 1.0f;
798 for(
auto pop : p.get_province().get_pop_location()) {
802 for(
auto& par : provincial_party_votes) {
815 auto pid = state.world.political_party_get_ideology(par.par);
816 auto base_support = (p.get_province().get_party_loyalty(pid) + 1.0f)
817 * prov_vote_mod * (par.par == n.get_ruling_party() ? ruling_party_support : 1.0f) * weight;
818 auto issue_support = 0.0f;
819 for(
auto pi : state.culture_definitions.party_issues) {
820 auto party_pos = state.world.political_party_get_party_issues(par.par, pi);
824 auto total_support = base_support * (issue_support * (1.0f - ideological_share) + ideology_support * ideological_share);
826 province_total += total_support;
827 par.vote += total_support;
832 if(province_total > 0) {
844 float winner_amount = provincial_party_votes[0].vote;
845 for(
uint32_t i = 1; i < provincial_party_votes.size(); ++i) {
846 if(provincial_party_votes[i].vote > winner_amount) {
848 winner_amount = provincial_party_votes[i].vote;
852 auto pid = state.world.political_party_get_ideology(provincial_party_votes[winner].par);
853 auto& l = p.get_province().get_party_loyalty(pid);
854 l = std::clamp(l + state.defines.loyalty_boost_on_party_win *
855 (p.get_province().get_modifier_values(sys::provincial_mod_offsets::boost_strongest_party) + 1.0f)
856 * winner_amount / province_total,
858 auto national_rule = n.get_combined_issue_rules();
861 party_votes[winner].vote += winner_amount;
863 for(
uint32_t i = 0; i < provincial_party_votes.size(); ++i) {
864 party_votes[i].vote += provincial_party_votes[i].vote / province_total;
867 for(
uint32_t i = 0; i < provincial_party_votes.size(); ++i) {
868 party_votes[i].vote += provincial_party_votes[i].vote;
885 if(avg_mil <= 5.0f) {
886 static auto per_group = state.world.ideology_group_make_vectorizable_float_buffer();
887 for(
auto ig : state.world.in_ideology_group) {
888 per_group.set(ig, 0.0f);
890 for(
uint32_t i = 0; i < party_votes.size(); ++i) {
891 per_group.get(state.world.ideology_get_ideology_group_from_ideology_group_membership(
892 state.world.political_party_get_ideology(party_votes[i].par))) += party_votes[i].vote;
894 dcon::ideology_group_id winner;
895 float winner_amount = -1.0f;
897 for(
auto ig : state.world.in_ideology_group) {
898 if(per_group.get(ig) > winner_amount) {
899 winner_amount = per_group.get(ig);
905 float winner_amount_b = -1.0f;
906 for(
uint32_t i = 0; i < party_votes.size(); ++i) {
907 total += party_votes[i].vote;
908 if(state.world.ideology_get_ideology_group_from_ideology_group_membership(state.world.political_party_get_ideology(party_votes[i].par)) == winner
909 && party_votes[i].vote > winner_amount_b) {
912 winner_amount_b = party_votes[i].vote;
922 "msg_election_end_title",
923 n, dcon::nation_id{}, dcon::nation_id{},
928 float winner_amount = party_votes[0].vote;
930 for(
uint32_t i = 1; i < party_votes.size(); ++i) {
931 total += party_votes[i].vote;
932 if(party_votes[i].vote > winner_amount) {
934 winner_amount = party_votes[i].vote;
944 "msg_election_end_title",
945 n, dcon::nation_id{}, dcon::nation_id{},
953 }
else if(state.current_date < n.get_election_ends()) {
960 int32_t time_value = int32_t(state.defines.campaign_event_base_time / 2.0f);
962 int32_t first_roll = int32_t(
uint32_t(randoms.low) % time_value) + time_value;
963 int32_t second_roll = first_roll + int32_t(
uint32_t(randoms.low >> 32) % time_value) + time_value;
964 int32_t third_roll = second_roll + int32_t(
uint32_t(randoms.high) % time_value) + time_value;
965 int32_t fourth_roll = third_roll + int32_t(
uint32_t(randoms.high >> 32) % time_value) + time_value;
967 auto election_start = n.get_election_ends() - int32_t(state.defines.campaign_duration) * 30;
969 if(election_start + first_roll == state.current_date || election_start + second_roll == state.current_date
970 || election_start + third_roll == state.current_date || election_start + fourth_roll == state.current_date) {
981 auto parent = state.world.issue_option_get_parent_issue(opt);
982 auto effect_t = state.world.issue_option_get_on_execute_trigger(opt);
983 auto effect_k = state.world.issue_option_get_on_execute_effect(opt);
986 uint32_t((opt.index() << 2) ^ n.index()));
988 state.world.nation_set_issues(n, parent, opt);
991 auto parent = state.world.reform_option_get_parent_reform(opt);
992 auto effect_t = state.world.reform_option_get_on_execute_trigger(opt);
993 auto effect_k = state.world.reform_option_get_on_execute_effect(opt);
996 uint32_t((opt.index() << 2) ^ n.index()));
998 state.world.nation_set_reforms(n, parent, opt);
#define assert(condition)
constexpr uint64_t to_bits(dcon::ideology_id id)
void update_nation_issue_rules(sys::state &state, dcon::nation_id n_id)
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)
void bound_budget_settings(sys::state &state, dcon::nation_id n)
void set_factory_priority(sys::state &state, dcon::factory_id f, int32_t priority)
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 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 same_as_ruling_party
constexpr uint32_t state_vote
constexpr uint32_t culture_voting
constexpr uint32_t rich_only
constexpr uint32_t largest_share
constexpr uint32_t primary_culture_voting
constexpr uint32_t factory_priority
void post(sys::state &state, message &&m)
void daily_party_loyalty_update(sys::state &state)
bool can_enact_social_reform(sys::state &state, dcon::nation_id n, dcon::issue_option_id o)
float pop_vote_weight(sys::state &state, dcon::pop_id p, dcon::nation_id n)
float get_military_reform_multiplier(sys::state &state, dcon::nation_id n)
float vote_total(sys::state &state, dcon::nation_id nation)
bool can_enact_political_reform(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
float get_economic_reform_multiplier(sys::state &state, dcon::nation_id n)
float get_voter_support(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
bool reform_is_selected(sys::state &state, dcon::nation_id nation, dcon::reform_option_id reform_option)
void recalculate_upper_house(sys::state &state, dcon::nation_id n)
dcon::issue_id get_issue_by_name(sys::state &state, std::string_view name)
sys::date next_election_date(sys::state &state, dcon::nation_id nation)
void force_ruling_party_ideology(sys::state &state, dcon::nation_id n, dcon::ideology_id id)
void force_nation_ideology(sys::state &state, dcon::nation_id n, dcon::ideology_id id)
dcon::reform_id get_reform_by_name(sys::state &state, std::string_view name)
bool can_appoint_ruling_party(sys::state &state, dcon::nation_id nation)
void set_issue_option(sys::state &state, dcon::nation_id n, dcon::issue_option_id opt)
bool political_party_is_active(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
void change_government_type(sys::state &state, dcon::nation_id n, dcon::government_type_id new_type)
void update_displayed_identity(sys::state &state, dcon::nation_id id)
float get_popular_support(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
bool can_enact_military_reform(sys::state &state, dcon::nation_id n, dcon::reform_option_id o)
void set_reform_option(sys::state &state, dcon::nation_id n, dcon::reform_option_id opt)
bool issue_is_selected(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
bool has_elections(sys::state &state, dcon::nation_id nation)
float party_total_support(sys::state &state, dcon::pop_id pop, dcon::political_party_id par_id, dcon::nation_id nat_id, dcon::province_id prov_id)
void appoint_ruling_party(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
void update_elections(sys::state &state)
void set_ruling_party(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
void start_election(sys::state &state, dcon::nation_id n)
bool is_election_ongoing(sys::state &state, dcon::nation_id nation)
bool can_enact_economic_reform(sys::state &state, dcon::nation_id n, dcon::reform_option_id o)
void set_militancy(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_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)
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
void for_each_land_province(sys::state &state, F const &func)
random_pair get_random_pair(sys::state const &state, uint32_t value_in)
void update_single_nation_modifiers(sys::state &state, dcon::nation_id n)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
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_additive_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
dcon::political_party_id par