Project Alice
Loading...
Searching...
No Matches
politics.cpp
Go to the documentation of this file.
1#include "politics.hpp"
2#include "dcon_generated.hpp"
3#include "demographics.hpp"
4#include "effects.hpp"
5#include "prng.hpp"
7#include "triggers.hpp"
8
9namespace politics {
10
11float vote_total(sys::state& state, dcon::nation_id nation) {
12 float total = 0.f;
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);
18 }
19 }
20 });
21 return total;
22}
23
24float get_popular_support(sys::state& state, dcon::nation_id nation, dcon::issue_option_id issue_option) {
25 auto total = state.world.nation_get_demographics(nation, demographics::total);
26 if(total <= 0.f) {
27 return 0.f;
28 }
29 auto dkey = demographics::to_key(state, issue_option);
30 return state.world.nation_get_demographics(nation, dkey) / total;
31}
32
33float get_voter_support(sys::state& state, dcon::nation_id nation, dcon::issue_option_id issue_option) {
34 auto total = vote_total(state, nation);
35 if(total <= 0.f) {
36 return 0.f;
37 }
38 auto support = 0.f;
39 auto dkey = pop_demographics::to_key(state, issue_option);
40
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();
44 auto vote_size = pop_vote_weight(state, pop_id, nation);
45 support += vote_size * pop_demographics::get_demo(state, pop_id.id, dkey);
46 }
47 }
48 return support / total;
49}
50
51bool can_appoint_ruling_party(sys::state& state, dcon::nation_id nation) {
52 return dcon::fatten(state.world, nation).get_government_type().get_can_appoint_ruling_party();
53}
54
55bool is_election_ongoing(sys::state& state, dcon::nation_id nation) {
56 auto election_end_date = dcon::fatten(state.world, nation).get_election_ends();
57 return election_end_date && election_end_date > state.current_date;
58}
59
60bool has_elections(sys::state& state, dcon::nation_id nation) {
61 return dcon::fatten(state.world, nation).get_government_type().get_has_elections();
62}
63
64sys::date next_election_date(sys::state& state, dcon::nation_id nation) {
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());
67}
68
69dcon::reform_id get_reform_by_name(sys::state& state, std::string_view name) {
70 dcon::reform_id result{};
71 auto it = state.lookup_key(name);
72 if(it) {
73 state.world.for_each_reform([&](dcon::reform_id reform_id) {
74 auto key = state.world.reform_get_name(reform_id);
75 if(it == key) {
76 result = reform_id;
77 }
78 });
79 }
80 return result;
81}
82
83dcon::issue_id get_issue_by_name(sys::state& state, std::string_view name) {
84 dcon::issue_id result{};
85 auto it = state.lookup_key(name);
86 if(it) {
87 state.world.for_each_issue([&](dcon::issue_id issue_id) {
88 auto key = state.world.issue_get_name(issue_id);
89 if(it == key) {
90 result = issue_id;
91 }
92 });
93 }
94 return result;
95}
96
97bool reform_is_selected(sys::state& state, dcon::nation_id nation, dcon::reform_option_id reform_option) {
98 auto reform = state.world.reform_option_get_parent_reform(reform_option);
99 return reform && reform_option == state.world.nation_get_reforms(nation, reform);
100}
101
102bool issue_is_selected(sys::state& state, dcon::nation_id nation, dcon::issue_option_id issue_option) {
103 auto issue = state.world.issue_option_get_parent_issue(issue_option);
104 return issue && issue_option == state.world.nation_get_issues(nation, issue);
105}
106
107bool can_enact_political_reform(sys::state& state, dcon::nation_id nation, dcon::issue_option_id issue_option) {
108 if(!issue_option)
109 return false;
110
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();
119
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()) &&
123 (!allow || trigger::evaluate(state, allow, trigger::to_generic(nation), trigger::to_generic(nation), 0))) {
124
125 float total = 0.0f;
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);
130
131 float party_special_issues_support_total = 0.0f;
132 float count_found = 0.0f;
133
134
135
136 for(int32_t i = start; i < end; i++) {
137 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
138 if(politics::political_party_is_active(state, nation, pid)
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) {
141
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())
147 )
148 )
149 ) {
150 party_special_issues_support_total = upperhouse_weight;
151 } else {
152 party_special_issues_support_total = 0.0f;
153 }
154 count_found = 1.0f;
155 } else {
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);
159
160 if(opt_mod) {
161 party_special_issues_support_total += upperhouse_weight * trigger::evaluate_additive_modifier(state, opt_mod, trigger::to_generic(nation), trigger::to_generic(nation), 0);
162 count_found += 1.0f;
163 }
164 }
165 }
166 break; // only look at one active party per ideology
167 }
168 }
169
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)
173 total += upperhouse_weight * std::clamp(trigger::evaluate_additive_modifier(state, condition, trigger::to_generic(nation), trigger::to_generic(nation), 0), -1.0f, 1.0f);
174 if(total > 0.5f)
175 return true;
176 }
177 }
178 return false;
179}
180
181bool can_enact_social_reform(sys::state& state, dcon::nation_id n, dcon::issue_option_id o) {
182 if(!o)
183 return false;
184
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();
193
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()) &&
197 (!allow || trigger::evaluate(state, allow, trigger::to_generic(n), trigger::to_generic(n), 0))) {
198
199 float total = 0.0f;
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);
204
205 float party_special_issues_support_total = 0.0f;
206 float count_found = 0.0f;
207
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) {
213
214 if(auto special_opt = state.world.political_party_get_party_issues(pid, issue); special_opt) {
215 if(special_opt == o
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())
219 )
220 )
221 ) {
222 party_special_issues_support_total = upperhouse_weight;
223 } else {
224 party_special_issues_support_total = 0.0f;
225 }
226 count_found = 1.0f;
227 } else {
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);
231
232 if(opt_mod) {
233 party_special_issues_support_total += upperhouse_weight * trigger::evaluate_additive_modifier(state, opt_mod, trigger::to_generic(n), trigger::to_generic(n), 0);
234 count_found += 1.0f;
235 }
236 }
237 }
238 break; // only look at one active party per ideology
239 }
240 }
241
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)
245 total += upperhouse_weight * std::clamp(trigger::evaluate_additive_modifier(state, condition, trigger::to_generic(n), trigger::to_generic(n), 0), -1.0f, 1.0f);
246 if(total > 0.5f)
247 return true;
248 }
249 }
250 return false;
251}
252
253bool can_enact_military_reform(sys::state& state, dcon::nation_id n, dcon::reform_option_id o) {
254 if(!o)
255 return false;
256
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()) &&
262 (!allow || trigger::evaluate(state, allow, trigger::to_generic(n), trigger::to_generic(n), 0))) {
263
264 float base_cost = float(state.world.reform_option_get_technology_cost(o));
265 float reform_factor = politics::get_military_reform_multiplier(state, n);
266
267 if(base_cost * reform_factor <= stored_rp)
268 return true;
269 }
270 return false;
271}
272
273bool can_enact_economic_reform(sys::state& state, dcon::nation_id n, dcon::reform_option_id o) {
274 if(!o)
275 return false;
276
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()) &&
282 (!allow || trigger::evaluate(state, allow, trigger::to_generic(n), trigger::to_generic(n), 0))) {
283
284 float base_cost = float(state.world.reform_option_get_technology_cost(o));
285 float reform_factor = politics::get_economic_reform_multiplier(state, n);
286
287 if(base_cost * reform_factor <= stored_rp)
288 return true;
289 }
290 return false;
291}
292
293float get_military_reform_multiplier(sys::state& state, dcon::nation_id n) {
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);
297
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)
303 reform_factor += state.defines.military_reform_uh_factor * upperhouse_weight * trigger::evaluate_additive_modifier(state, condition, trigger::to_generic(n), trigger::to_generic(n), 0);
304 }
305 return reform_factor;
306}
307
308float get_economic_reform_multiplier(sys::state& state, dcon::nation_id n) {
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);
312
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)
318 reform_factor += state.defines.economic_reform_uh_factor * upperhouse_weight * trigger::evaluate_additive_modifier(state, condition, trigger::to_generic(n), trigger::to_generic(n), 0);
319 }
320 return reform_factor;
321}
322
323bool political_party_is_active(sys::state& state, dcon::nation_id n, dcon::political_party_id p) {
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) {
329 }
330 return b;
331}
332
333void set_ruling_party(sys::state& state, dcon::nation_id n, dcon::political_party_id p) {
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));
337 }
341 if(auto rules = state.world.nation_get_combined_issue_rules(n); (rules & issue_rule::factory_priority) == 0) {
342 for(auto po : state.world.nation_get_province_ownership_as_nation(n)) {
343 for(auto fl : po.get_province().get_factory_location()) {
344 economy::set_factory_priority(state, fl.get_factory(), 0);
345 }
346 }
347 }
348}
349
350void force_ruling_party_ideology(sys::state& state, dcon::nation_id n, dcon::ideology_id id) {
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);
354
355 for(int32_t i = start; i < end; i++) {
356 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
357 if(politics::political_party_is_active(state, n, pid) && state.world.political_party_get_ideology(pid) == id) {
358 set_ruling_party(state, n, pid);
359 return;
360 }
361 }
362}
363
364void appoint_ruling_party(sys::state& state, dcon::nation_id n, dcon::political_party_id p) {
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();
370 }
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();
375 }
376
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;
379
380 /*
381 If the new party ideology is *not* the same as the old one: all pops gain ((total number of political and social reforms over
382 baseline) x 0.01 + 1.0) x define:RULING_PARTY_ANGRY_CHANGE x pop support of the old ideology militancy all pops gain
383 define:RULING_PARTY_HAPPY_CHANGE x pop support of the new ideology militancy The same is also done for all party issues that
384 differ between the two.
385 */
386
387 auto old_party = state.world.nation_get_ruling_party(n);
388
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);
392
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()) {
396 auto base_mil = pop_demographics::get_militancy(state, pop.get_pop());
397 auto adj_mil = base_mil + pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, old_id)) * angry_value + pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, new_id)) * happy_value;
398 pop_demographics::set_militancy(state, pop.get_pop().id, std::clamp(adj_mil, 0.0f, 10.0f));
399 }
400 }
401 }
402 }
403 {
404 auto new_id = state.world.political_party_get_ideology(p);
405 auto old_id = state.world.political_party_get_ideology(old_party);
406
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()) {
410 auto base_mil = pop_demographics::get_militancy(state, pop.get_pop());
411 auto adj_mil = base_mil + pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, old_id)) * angry_value + pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, new_id)) * happy_value;
412 pop_demographics::set_militancy(state, pop.get_pop().id, std::clamp(adj_mil, 0.0f, 10.0f));
413 }
414 }
415 }
416 }
417
418 state.world.nation_set_ruling_party_last_appointed(n, state.current_date);
419 set_ruling_party(state, n, p);
420}
421
422void force_nation_ideology(sys::state& state, dcon::nation_id n, dcon::ideology_id id) {
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);
425
426 force_ruling_party_ideology(state, n, id);
427}
428
429void update_displayed_identity(sys::state& state, dcon::nation_id id) {
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));
433 if(gov_id) {
434 state.world.nation_set_color(id, state.world.national_identity_get_government_color(ident, gov_id));
435 } else {
436 state.world.nation_set_color(id, state.world.national_identity_get_color(ident));
437 }
438 state.province_ownership_changed.store(true, std::memory_order::release);
439}
440
441void change_government_type(sys::state& state, dcon::nation_id n, dcon::government_type_id new_type) {
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);
446
447 if((state.world.government_type_get_ideologies_allowed(new_type) & culture::to_bits(state.world.nation_get_ruling_party(n).get_ideology())) == 0) {
448
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);
452
453 for(int32_t i = start; i < end; i++) {
454 auto pid = dcon::political_party_id(dcon::political_party_id::value_base_t(i));
455 if(politics::political_party_is_active(state, n, pid) &&
456 (state.world.government_type_get_ideologies_allowed(new_type) &
457 culture::to_bits(state.world.political_party_get_ideology(pid))) != 0) {
458
459 set_ruling_party(state, n, pid);
460 break;
461 }
462 }
463 }
464
465 // Cancel elections
466 // If a government which allows elections -> Will immediately start a new one
467 // Else, it will just leave it cancelled
468 state.world.nation_set_election_ends(n, sys::date{});
469
470 recalculate_upper_house(state, n);
471
472 // TODO: notify player ?
474 }
475}
476
477float pop_vote_weight(sys::state& state, dcon::pop_id p, dcon::nation_id n) {
478 /*
479 When a pop's "votes" in any form, the weight of that vote is the product of the size of the pop and the national modifier for
480 voting for their strata (this could easily result in a strata having no votes). If the nation has primary culture voting set
481 then primary culture pops get a full vote, accepted culture pops get a half vote, and other culture pops get no vote. If it
482 has culture voting, primary and accepted culture pops get a full vote and no one else gets a vote. If neither is set, all pops
483 get an equal vote.
484 */
485
486 auto type = state.world.pop_get_poptype(p);
487 if(state.world.pop_type_get_voting_forbidden(type))
488 return 0.0f;
489
490 auto size = state.world.pop_get_size(p);
491 auto strata = culture::pop_strata(state.world.pop_type_get_strata(type));
492 auto vmod = [&]() {
493 switch(strata) {
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));
500 default:
501 return 0.0f;
502 }
503 }();
504
505 auto rules = state.world.nation_get_combined_issue_rules(n);
506 if((rules & issue_rule::primary_culture_voting) != 0) {
507 if(state.world.pop_get_culture(p) == state.world.nation_get_primary_culture(n))
508 return size * vmod;
509 else if(state.world.pop_get_is_primary_or_accepted_culture(p))
510 return size * vmod * 0.5f;
511 else
512 return 0.0f;
513 } else if((rules & issue_rule::culture_voting) != 0) {
514 if(state.world.pop_get_is_primary_or_accepted_culture(p))
515 return size * vmod;
516 else
517 return 0.0f;
518 } else {
519 return size * vmod;
520 }
521}
522
523void recalculate_upper_house(sys::state& state, dcon::nation_id n) {
524 /*
525 Every year, the upper house of each nation is updated. If the "same as ruling party" rule is set, the upper house becomes 100%
526 the ideology of the ruling party. If the rule is "state vote", then for each non-colonial state: for each pop in the state
527 that is not prevented from voting by its type we distribute its weighted vote proportionally to its ideology support, giving
528 us an ideology distribution for each of those states. The state ideology distributions are then normalized and summed to form
529 the distribution for the upper house. For "population_vote" and "rich_only" the voting weight of each non colonial pop (or
530 just the rich ones for "rich only") is distributed proportionally to its ideological support, with the sum for all eligible
531 pops forming the distribution for the upper house.
532 */
533 static std::vector<float> accumulated_in_state;
534 accumulated_in_state.resize(state.world.ideology_size());
535
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();
538 //(allowed_ideo & culture::to_bits(i)) != 0
539
540 if((rules & issue_rule::same_as_ruling_party) != 0) {
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);
544 }
545 if(rp_ideology)
546 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
547 } else if((rules & issue_rule::state_vote) != 0) {
548 for(auto i : state.world.in_ideology) {
549 state.world.nation_set_upper_house(n, i, 0.0f);
550 }
551 float state_total = 0.0f;
552
553 for(auto si : state.world.nation_get_state_ownership(n)) {
554 if(si.get_state().get_capital().get_is_colonial())
555 continue; // skip colonial states
556
557 for(auto i : state.world.in_ideology) {
558 accumulated_in_state[i.id.index()] = 0.0f;
559 }
560
561 province::for_each_province_in_state_instance(state, si.get_state(), [&](dcon::province_id p) {
562 for(auto pop : state.world.province_get_pop_location(p)) {
563 auto weight = pop_vote_weight(state, pop.get_pop(), n);
564 if(weight > 0) {
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));
568 }
569 }
570 }
571 });
572 float total = 0.0f;
573 for(auto i : state.world.in_ideology) {
574 total += accumulated_in_state[i.id.index()];
575 }
576 if(total > 0) {
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;
581 }
582 }
583 }
584
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;
589 }
590 } else {
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);
594 }
595 if(rp_ideology)
596 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
597 }
598 } else if((rules & issue_rule::rich_only) != 0) {
599 for(auto i : state.world.in_ideology) {
600 state.world.nation_set_upper_house(n, i, 0.0f);
601 }
602 for(auto p : state.world.nation_get_province_ownership(n)) {
603 if(p.get_province().get_is_colonial())
604 continue; // skip colonial provinces
605
606 for(auto pop : state.world.province_get_pop_location(p.get_province())) {
607 if(pop.get_pop().get_poptype().get_strata() == uint8_t(culture::pop_strata::rich)) {
608 auto weight = pop.get_pop().get_size(); // allegedly
609 if(weight > 0) {
610 for(auto i : state.world.in_ideology) {
611 if((allowed_ideo & culture::to_bits(i)) != 0)
612 state.world.nation_get_upper_house(n, i) += weight * pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, i));
613 }
614 }
615 }
616 }
617 }
618 float total = 0.0f;
619 for(auto i : state.world.in_ideology) {
620 total += state.world.nation_get_upper_house(n, i);
621 }
622 if(total > 0) {
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;
626 }
627 } else {
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);
631 }
632 if(rp_ideology)
633 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
634 }
635 } else {
636 for(auto i : state.world.in_ideology) {
637 state.world.nation_set_upper_house(n, i, 0.0f);
638 }
639 for(auto p : state.world.nation_get_province_ownership(n)) {
640 if(p.get_province().get_is_colonial())
641 continue; // skip colonial provinces
642
643 for(auto pop : state.world.province_get_pop_location(p.get_province())) {
644 auto weight = pop_vote_weight(state, pop.get_pop(), n);
645 if(weight > 0) {
646 for(auto i : state.world.in_ideology) {
647 if((allowed_ideo & culture::to_bits(i)) != 0)
648 state.world.nation_get_upper_house(n, i) += weight * pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, i));
649 }
650 }
651 }
652 }
653 float total = 0.0f;
654 for(auto i : state.world.in_ideology) {
655 total += state.world.nation_get_upper_house(n, i);
656 }
657 if(total > 0) {
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;
661 }
662 } else {
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);
666 }
667 if(rp_ideology)
668 state.world.nation_set_upper_house(n, rp_ideology, 100.0f);
669 }
670 }
671
672 if(n == state.local_player_nation) {
674 [n](sys::state& state, text::layout_base& contents) {
675 text::add_line(state, contents, "msg_upper_house_1");
676 for(auto i : state.world.in_ideology) {
677 auto frac = state.world.nation_get_upper_house(n, i);
678 if(frac > 0.f) {
679 text::add_line(state, contents, "msg_upper_house_2", text::variable_type::x, text::fp_one_place{frac}, text::variable_type::y, i.get_name());
680 }
681 }
682 },
683 "msg_upper_house_title",
684 n, dcon::nation_id{}, dcon::nation_id{},
686 });
687 }
688}
689
691 province::for_each_land_province(state, [&](dcon::province_id p) {
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);
695 if(party) {
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);
698 }
699 });
700}
701
702float 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) {
703 auto n = dcon::fatten(state.world, nat_id);
704 auto p = dcon::fatten(state.world, prov_id);
705
706 auto weight = pop_vote_weight(state, pop, n);
707 if(weight > 0.f) {
708 auto ideological_share = pop_demographics::get_consciousness(state, pop) / 20.0f;
709
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;
712
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);
718 issue_support += pop_demographics::get_demo(state, pop, pop_demographics::to_key(state, party_pos));
719 }
720 auto ideology_support = pop_demographics::get_demo(state, pop, pop_demographics::to_key(state, pid));
721 return base_support * (issue_support * (1.0f - ideological_share) + ideology_support * ideological_share);
722 } else {
723 return 0.f;
724 }
725}
726
728 dcon::political_party_id par;
729 float vote = 0.0f;
730};
731
732void start_election(sys::state& state, dcon::nation_id n) {
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);
738 [end_date](sys::state& state, text::layout_base& contents) {
739 text::add_line(state, contents, "msg_election_start_1", text::variable_type::x, end_date);
740 },
741 "msg_election_start_title",
742 n, dcon::nation_id{}, dcon::nation_id{},
744 });
745 }
746 event::fire_fixed_event(state, state.national_definitions.on_election_started, trigger::to_generic(n),
748 }
749}
750
752 static std::vector<party_vote> party_votes;
753 static std::vector<party_vote> provincial_party_votes;
754
755 for(auto n : state.world.in_nation) {
756 /*
757 A country with elections starts one every 5 years.
758 Elections last define:CAMPAIGN_DURATION months.
759 */
760 if(has_elections(state, n)) {
761 if(n.get_election_ends() == state.current_date) {
762 // make election results
763
764 party_votes.clear();
765 float total_vote = 0.0f;
766
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);
770
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) {
775 party_votes.push_back(party_vote{pid, 0.0f});
776 }
777 }
778
779 if(party_votes.size() == 0)
780 continue; // ERROR: no valid parties
781
782 // - Determine the vote in each province. Note that voting is *by active party* not by ideology.
783 for(auto p : n.get_province_ownership()) {
784 if(p.get_province().get_is_colonial())
785 continue; // skip colonial provinces
786
787 provincial_party_votes.clear();
788 float province_total = 0.0f;
789 for(auto& par : party_votes) {
790 provincial_party_votes.push_back(party_vote{par.par, 0.0f});
791 }
792
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;
797
798 for(auto pop : p.get_province().get_pop_location()) {
799 auto weight = pop_vote_weight(state, pop.get_pop(), n);
800 if(weight > 0) {
801 auto ideological_share = pop_demographics::get_consciousness(state, pop.get_pop()) / 20.0f;
802 for(auto& par : provincial_party_votes) {
803 /*
804 - For each party we do the following: figure out the pop's ideological support for the party and
805 its issues based support for the party (by summing up its support for each issue that the party
806 has set, except that pops of non-accepted cultures will never support more restrictive culture
807 voting parties). The pop then votes for the party (i.e. contributes its voting weight in support)
808 based on the sum of its issue and ideological support, except that the greater consciousness the
809 pop has, the more its vote is based on ideological support (pops with 0 consciousness vote based
810 on issues alone). The support for the party is then multiplied by
811 (provincial-modifier-ruling-party-support + national-modifier-ruling-party-support + 1), if it is
812 the ruling party, and by (1 + province-party-loyalty) for its ideology.
813 - Pop votes are also multiplied by (provincial-modifier-number-of-voters + 1)
814 */
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);
821 issue_support += pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, party_pos));
822 }
823 auto ideology_support = pop_demographics::get_demo(state, pop.get_pop(), pop_demographics::to_key(state, pid));
824 auto total_support = base_support * (issue_support * (1.0f - ideological_share) + ideology_support * ideological_share);
825
826 province_total += total_support;
827 par.vote += total_support;
828 }
829 }
830 }
831
832 if(province_total > 0) {
833 /*
834 - After the vote has occurred in each province, the winning party there has the province's ideological
835 loyalty for its ideology increased by define:LOYALTY_BOOST_ON_PARTY_WIN x
836 (provincial-boost-strongest-party-modifier + 1) x fraction-of-vote-for-winning-party
837 - If voting rule "largest_share" is in effect: all votes are added to the sum towards the party that
838 recieved the most votes in the province. If it is "dhont", then the votes in each province are normalized
839 to the number of votes from the province, and for "sainte_laque" the votes from the provinces are simply
840 summed up.
841 */
842
843 uint32_t winner = 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) {
847 winner = i;
848 winner_amount = provincial_party_votes[i].vote;
849 }
850 }
851
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,
857 -1.0f, 1.0f);
858 auto national_rule = n.get_combined_issue_rules();
859
860 if((national_rule & issue_rule::largest_share) != 0) {
861 party_votes[winner].vote += winner_amount;
862 } else if((national_rule & issue_rule::dhont) != 0) {
863 for(uint32_t i = 0; i < provincial_party_votes.size(); ++i) {
864 party_votes[i].vote += provincial_party_votes[i].vote / province_total;
865 }
866 } else /*if((national_rule & issue_rule::sainte_laque) != 0)*/ {
867 for(uint32_t i = 0; i < provincial_party_votes.size(); ++i) {
868 party_votes[i].vote += provincial_party_votes[i].vote;
869 }
870 }
871 }
872 }
873
874 /*
875 What happens with the election result depends partly on the average militancy of the nation. If it is less than 5:
876 We find the ideology group with the greatest support (each active party gives their support to their group), then
877 the party with the greatest support from the winning group is elected. If average militancy is greater than 5: the
878 party with the greatest individual support wins. (Note: so at average militancy less than 5, having parties with
879 duplicate ideologies makes an ideology group much more likely to win, because they get double counted.)
880 */
881
882 auto total_pop = n.get_demographics(demographics::total);
883 auto avg_mil = total_pop > 0.0f ? n.get_demographics(demographics::militancy) / total_pop : 0.0f;
884
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);
889 }
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;
893 }
894 dcon::ideology_group_id winner;
895 float winner_amount = -1.0f;
896 float total = 0.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);
900 winner = ig;
901 }
902 }
903
904 uint32_t winner_b = 0;
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) {
910
911 winner_b = i;
912 winner_amount_b = party_votes[i].vote;
913 }
914 }
915
916 set_ruling_party(state, n, party_votes[winner_b].par);
917
919 [rp = party_votes[winner_b].par, frac = winner_amount_b / total](sys::state& state, text::layout_base& contents) {
920 text::add_line(state, contents, "msg_election_end_2", text::variable_type::x, state.world.political_party_get_name(rp), text::variable_type::y, text::fp_percentage{frac});
921 },
922 "msg_election_end_title",
923 n, dcon::nation_id{}, dcon::nation_id{},
925 });
926 } else {
927 uint32_t winner = 0;
928 float winner_amount = party_votes[0].vote;
929 float total = 0.0f;
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) {
933 winner = i;
934 winner_amount = party_votes[i].vote;
935 }
936 }
937
938 set_ruling_party(state, n, party_votes[winner].par);
939
941 [rp = party_votes[winner].par, frac = winner_amount / total](sys::state& state, text::layout_base& contents) {
942 text::add_line(state, contents, "msg_election_end_1", text::variable_type::x, state.world.political_party_get_name(rp), text::variable_type::y, text::fp_percentage{frac});
943 },
944 "msg_election_end_title",
945 n, dcon::nation_id{}, dcon::nation_id{},
947 });
948 }
949 event::fire_fixed_event(state, state.national_definitions.on_election_finished, trigger::to_generic(n),
951 } else if(next_election_date(state, n) <= state.current_date) {
952 start_election(state, n);
953 } else if(state.current_date < n.get_election_ends()) { // do election event
954 /*
955 While an election is ongoing, random events from the `on_election_tick` category will be fired. These events are picked in
956 the usual way: based on their weights out of those that have their trigger conditions (if any) satisfied. Events occur
957 once every define:CAMPAIGN_EVENT_BASE_TIME / 2 days to define:CAMPAIGN_EVENT_BASE_TIME days (uniformly distributed).
958 */
959 auto randoms = rng::get_random_pair(state, uint32_t(n.get_election_ends().value), uint32_t(n.id.value));
960 int32_t time_value = int32_t(state.defines.campaign_event_base_time / 2.0f);
961
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;
966
967 auto election_start = n.get_election_ends() - int32_t(state.defines.campaign_duration) * 30;
968
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) {
971
972 event::fire_fixed_event(state, state.national_definitions.on_election_tick, trigger::to_generic(n.id),
974 }
975 }
976 }
977 }
978}
979
980void set_issue_option(sys::state& state, dcon::nation_id n, dcon::issue_option_id opt) {
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);
984 if(effect_k && (!effect_t || trigger::evaluate(state, effect_t, trigger::to_generic(n), trigger::to_generic(n), 0))) {
985 effect::execute(state, effect_k, trigger::to_generic(n), trigger::to_generic(n), 0, uint32_t(state.current_date.value),
986 uint32_t((opt.index() << 2) ^ n.index()));
987 }
988 state.world.nation_set_issues(n, parent, opt);
989}
990void set_reform_option(sys::state& state, dcon::nation_id n, dcon::reform_option_id 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);
994 if(effect_k && (!effect_t || trigger::evaluate(state, effect_t, trigger::to_generic(n), trigger::to_generic(n), 0))) {
995 effect::execute(state, effect_k, trigger::to_generic(n), trigger::to_generic(n), 0, uint32_t(state.current_date.value),
996 uint32_t((opt.index() << 2) ^ n.index()));
997 }
998 state.world.nation_set_reforms(n, parent, opt);
999}
1000
1001} // namespace politics
#define assert(condition)
Definition: debug.h:74
constexpr uint64_t to_bits(dcon::ideology_id id)
Definition: culture.hpp:92
void update_nation_issue_rules(sys::state &state, dcon::nation_id n_id)
Definition: culture.cpp:766
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)
Definition: economy.cpp:5271
void set_factory_priority(sys::state &state, dcon::factory_id f, int32_t priority)
Definition: economy.cpp:1007
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)
Definition: effects.cpp:5404
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)
Definition: events.cpp:709
constexpr uint32_t same_as_ruling_party
Definition: culture.hpp:34
constexpr uint32_t state_vote
Definition: culture.hpp:36
constexpr uint32_t culture_voting
Definition: culture.hpp:29
constexpr uint32_t rich_only
Definition: culture.hpp:35
constexpr uint32_t dhont
Definition: culture.hpp:32
constexpr uint32_t largest_share
Definition: culture.hpp:31
constexpr uint32_t primary_culture_voting
Definition: culture.hpp:28
constexpr uint32_t factory_priority
Definition: culture.hpp:12
void post(sys::state &state, message &&m)
void daily_party_loyalty_update(sys::state &state)
Definition: politics.cpp:690
bool can_enact_social_reform(sys::state &state, dcon::nation_id n, dcon::issue_option_id o)
Definition: politics.cpp:181
float pop_vote_weight(sys::state &state, dcon::pop_id p, dcon::nation_id n)
Definition: politics.cpp:477
float get_military_reform_multiplier(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:293
float vote_total(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:11
bool can_enact_political_reform(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
Definition: politics.cpp:107
float get_economic_reform_multiplier(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:308
float get_voter_support(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
Definition: politics.cpp:33
bool reform_is_selected(sys::state &state, dcon::nation_id nation, dcon::reform_option_id reform_option)
Definition: politics.cpp:97
void recalculate_upper_house(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:523
dcon::issue_id get_issue_by_name(sys::state &state, std::string_view name)
Definition: politics.cpp:83
sys::date next_election_date(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:64
void force_ruling_party_ideology(sys::state &state, dcon::nation_id n, dcon::ideology_id id)
Definition: politics.cpp:350
void force_nation_ideology(sys::state &state, dcon::nation_id n, dcon::ideology_id id)
Definition: politics.cpp:422
dcon::reform_id get_reform_by_name(sys::state &state, std::string_view name)
Definition: politics.cpp:69
bool can_appoint_ruling_party(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:51
void set_issue_option(sys::state &state, dcon::nation_id n, dcon::issue_option_id opt)
Definition: politics.cpp:980
bool political_party_is_active(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
Definition: politics.cpp:323
void change_government_type(sys::state &state, dcon::nation_id n, dcon::government_type_id new_type)
Definition: politics.cpp:441
void update_displayed_identity(sys::state &state, dcon::nation_id id)
Definition: politics.cpp:429
float get_popular_support(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
Definition: politics.cpp:24
bool can_enact_military_reform(sys::state &state, dcon::nation_id n, dcon::reform_option_id o)
Definition: politics.cpp:253
void set_reform_option(sys::state &state, dcon::nation_id n, dcon::reform_option_id opt)
Definition: politics.cpp:990
bool issue_is_selected(sys::state &state, dcon::nation_id nation, dcon::issue_option_id issue_option)
Definition: politics.cpp:102
bool has_elections(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:60
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)
Definition: politics.cpp:702
void appoint_ruling_party(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
Definition: politics.cpp:364
void update_elections(sys::state &state)
Definition: politics.cpp:751
void set_ruling_party(sys::state &state, dcon::nation_id n, dcon::political_party_id p)
Definition: politics.cpp:333
void start_election(sys::state &state, dcon::nation_id n)
Definition: politics.cpp:732
bool is_election_ongoing(sys::state &state, dcon::nation_id nation)
Definition: politics.cpp:55
bool can_enact_economic_reform(sys::state &state, dcon::nation_id n, dcon::reform_option_id o)
Definition: politics.cpp:273
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)
Definition: prng.cpp:26
void update_single_nation_modifiers(sys::state &state, dcon::nation_id n)
Definition: modifiers.cpp:426
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5865
float evaluate_additive_modifier(sys::state &state, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
Definition: triggers.cpp:5796
uint uint32_t
uchar uint8_t
@ ident
dcon::political_party_id par
Definition: politics.cpp:728