Project Alice
Loading...
Searching...
No Matches
gui_population_window.cpp
Go to the documentation of this file.
2#include "demographics.hpp"
5#include "triggers.hpp"
6
7namespace ui {
8
9void describe_conversion(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
10 auto location = state.world.pop_get_province_from_pop_location(ids);
11 auto owner = state.world.province_get_nation_from_province_ownership(location);
12 auto conversion_chances = std::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.conversion_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
13
14 float base_amount =
15 state.defines.conversion_scale *
16 (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::conversion_rate) + 1.0f) *
17 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_conversion_rate) + 1.0f) *
18 conversion_chances;
19
20 auto pr = state.world.pop_get_religion(ids);
21 auto state_religion = state.world.nation_get_religion(owner);
22
23 // pops of the state religion do not convert
24 if(state_religion == pr)
25 base_amount = 0.0f;
26
27 // need at least 1 pop following the religion in the province
28 if(state.world.province_get_demographics(location, demographics::to_key(state, state_religion.id)) < 1.f)
29 base_amount = 0.0f;
30
31 text::add_line(state, contents, "pop_conver_1", text::variable_type::x, int64_t(std::max(0.0f, state.world.pop_get_size(ids) * base_amount)));
33
34 if(state_religion == pr) {
35 text::add_line(state, contents, "pop_conver_2");
36 return;
37 }
38 // need at least 1 pop following the religion in the province
39 if(state.world.province_get_demographics(location, demographics::to_key(state, state_religion.id)) < 1.f) {
40 text::add_line(state, contents, "pop_conver_3");
41 return; // early exit
42 }
43 text::add_line(state, contents, "pop_conver_4");
44 text::add_line(state, contents, "pop_conver_5", text::variable_type::x, text::fp_three_places{state.defines.conversion_scale});
45 text::add_line(state, contents, "pop_conver_6", text::variable_type::x, text::fp_two_places{ std::max(0.0f,state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_conversion_rate) + 1.0f)});
46 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::global_conversion_rate, true);
47 text::add_line(state, contents, "pop_conver_7", text::variable_type::x, text::fp_two_places{ std::max(0.0f, state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::conversion_rate) + 1.0f)});
48 active_modifiers_description(state, contents, location, 15, sys::provincial_mod_offsets::conversion_rate, true);
49
50 text::add_line(state, contents, "pop_conver_8", text::variable_type::x, text::fp_four_places{conversion_chances});
51 additive_value_modifier_description(state, contents, state.culture_definitions.conversion_chance, trigger::to_generic(ids),
52 trigger::to_generic(ids), 0);
53}
54
55void describe_migration(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
56 auto loc = state.world.pop_get_province_from_pop_location(ids);
57
58
59 if(state.world.province_get_is_colonial(loc)) {
60 text::add_line(state, contents, "pop_mig_1");
61 return;
62 }
63 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves) {
64 text::add_line(state, contents, "pop_mig_2");
65 return;
66 }
67
68 auto owners = state.world.province_get_nation_from_province_ownership(loc);
69 auto migration_chance = std::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.migration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
70 auto prov_mod = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
71 auto scale = state.defines.immigration_scale;
72
75
76 active_modifiers_description(state, contents, loc, 0, sys::provincial_mod_offsets::immigrant_push, true);
77
78 text::add_line(state, contents, "pop_mig_4");
79 additive_value_modifier_description(state, contents, state.culture_definitions.migration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
80}
81
83 auto loc = state.world.pop_get_province_from_pop_location(ids);
84 auto owner = state.world.province_get_nation_from_province_ownership(loc);
85
86
87 if(state.world.nation_get_is_colonial_nation(owner) == false) {
88 text::add_line(state, contents, "pop_cmig_1");
89 return;
90 }
91 if(state.world.province_get_is_colonial(loc)) {
92 text::add_line(state, contents, "pop_cmig_2");
93 return;
94 }
95 auto pt = state.world.pop_get_poptype(ids);
96 if(pt == state.culture_definitions.slaves) {
97 text::add_line(state, contents, "pop_cmig_3");
98 return;
99 }
100 if(state.world.pop_type_get_strata(pt) == uint8_t(culture::pop_strata::rich)) {
101 text::add_line(state, contents, "pop_cmig_4");
102 return;
103 }
104 if(pt == state.culture_definitions.primary_factory_worker || pt == state.culture_definitions.secondary_factory_worker) {
105 text::add_line(state, contents, "pop_cmig_5");
106 return;
107 }
108
109 auto mig_chance = std::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.colonialmigration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
110 auto im_push = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
111 auto cmig = (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::colonial_migration) + 1.0f);
112 auto scale = state.defines.immigration_scale;
113
116 text::fp_two_places{mig_chance});
117
118 active_modifiers_description(state, contents, loc, 0, sys::provincial_mod_offsets::immigrant_push, true);
119 active_modifiers_description(state, contents, owner, 0, sys::national_mod_offsets::colonial_migration, true);
120
121 text::add_line(state, contents, "pop_cmig_7");
122 additive_value_modifier_description(state, contents, state.culture_definitions.colonialmigration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0);
123}
124
125void describe_emigration(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
126 auto loc = state.world.pop_get_province_from_pop_location(ids);
127 auto owners = state.world.province_get_nation_from_province_ownership(loc);
128
129 if(state.world.nation_get_is_civilized(owners) == false) {
130 text::add_line(state, contents, "pop_emg_1");
131 return;
132 }
133 if(state.world.province_get_is_colonial(loc)) {
134 text::add_line(state, contents, "pop_emg_2");
135 return;
136 }
137 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves) {
138 text::add_line(state, contents, "pop_emg_3");
139 return;
140 }
141 if(state.world.culture_group_get_is_overseas(
142 state.world.culture_get_group_from_culture_group_membership(state.world.pop_get_culture(ids))) == false) {
143 text::add_line(state, contents, "pop_emg_4");
144 return;
145 }
146
147 auto impush = (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::immigrant_push) + 1.0f);
148 auto emig = std::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.emigration_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
149 auto scale = state.defines.immigration_scale;
150
153
154 active_modifiers_description(state, contents, loc, 0, sys::provincial_mod_offsets::immigrant_push, true);
155
156 text::add_line(state, contents, "pop_emg_6");
157 additive_value_modifier_description(state, contents, state.culture_definitions.emigration_chance, trigger::to_generic(ids),
158 trigger::to_generic(ids), 0);
159}
160
162
163 auto owner = nations::owner_of_pop(state, ids);
164 auto promotion_chance = trigger::evaluate_additive_modifier(state, state.culture_definitions.promotion_chance,
166 auto demotion_chance = trigger::evaluate_additive_modifier(state, state.culture_definitions.demotion_chance,
168
169 auto loc = state.world.pop_get_province_from_pop_location(ids);
170 auto si = state.world.province_get_state_membership(loc);
171 auto nf = state.world.state_instance_get_owner_focus(si);
172 auto promoted_type = state.world.national_focus_get_promotion_type(nf);
173 auto promotion_bonus = state.world.national_focus_get_promotion_amount(nf);
174 auto ptype = state.world.pop_get_poptype(ids);
175 auto strata = state.world.pop_type_get_strata(ptype);
176
177 text::add_line(state, contents, "pop_prom_1");
178 if(promoted_type) {
179 if(promoted_type == ptype) {
180 text::add_line(state, contents, "pop_prom_3");
181 } else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
182 text::add_line(state, contents, "pop_prom_2", text::variable_type::val, text::fp_two_places{promotion_bonus});
183 promotion_chance += promotion_bonus;
184 } else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
185 demotion_chance += promotion_bonus;
186 }
187 }
188 additive_value_modifier_description(state, contents, state.culture_definitions.promotion_chance, trigger::to_generic(ids),
189 trigger::to_generic(ids), 0);
190
192
193 text::add_line(state, contents, "pop_prom_4");
194 if(promoted_type) {
195 if(promoted_type == ptype) {
196
197 } else if(state.world.pop_type_get_strata(promoted_type) >= strata) {
198
199 } else if(state.world.pop_type_get_strata(promoted_type) <= strata) {
200 text::add_line(state, contents, "pop_prom_2", text::variable_type::val, text::fp_two_places{promotion_bonus});
201 }
202 }
203 additive_value_modifier_description(state, contents, state.culture_definitions.demotion_chance, trigger::to_generic(ids),
204 trigger::to_generic(ids), 0);
205
207
208 if(promotion_chance <= 0.0f && demotion_chance <= 0.0f) {
209 text::add_line(state, contents, "pop_prom_7");
210 return;
211 }
212
213 bool promoting = promotion_chance >= demotion_chance;
214 if(promoting) {
215 text::add_line(state, contents, "pop_prom_5");
216 text::add_line(state, contents, "pop_prom_8", text::variable_type::x, text::fp_three_places{state.defines.promotion_scale},
218 text::fp_percentage{state.world.nation_get_administrative_efficiency(owner)});
219 } else {
220 text::add_line(state, contents, "pop_prom_6");
221 text::add_line(state, contents, "pop_prom_9", text::variable_type::x, text::fp_three_places{state.defines.promotion_scale},
223 }
224}
225
226void describe_con(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
227 auto const clergy_key = demographics::to_key(state, state.culture_definitions.clergy);
228
229 auto loc = state.world.pop_get_province_from_pop_location(ids);
230 auto owner = state.world.province_get_nation_from_province_ownership(loc);
231 float cfrac =
232 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
233 auto types = state.world.pop_get_poptype(ids);
234
235 float lx_mod = pop_demographics::get_luxury_needs(state, ids) * state.defines.con_luxury_goods;
236 float cl_mod = cfrac * (state.world.pop_type_get_strata(types) == int32_t(culture::pop_strata::poor) ?
237 state.defines.con_poor_clergy : state.defines.con_midrich_clergy);
238 float lit_mod = ((state.world.nation_get_plurality(owner) / 10.0f) *
239 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::literacy_con_impact) + 1.0f) *
240 state.defines.con_literacy * pop_demographics::get_literacy(state, ids) *
241 (state.world.province_get_is_colonial(loc) ? state.defines.con_colonial_factor : 1.0f)) / 10.f;
242
243 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_consciousness_modifier);
244 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_consciousness_modifier);
245 float cmod = (state.world.province_get_is_colonial(loc) ? 0.0f :
246 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_consciousness_modifier));
247
248 float local_mod = (pmod + omod) + cmod;
249
250 float sep_mod = (state.world.pop_get_is_primary_or_accepted_culture(ids) ? 0.0f :
251 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_consciousness_modifier));
252 auto old_con = pop_demographics::get_consciousness(state, ids) * 0.01f;
253 auto total = (lx_mod + (cl_mod + lit_mod - old_con)) + (local_mod + sep_mod);
254
255 {
256 auto box = text::open_layout_box(contents);
257 text::localised_format_box(state, contents, box, "pop_con_1");
258 if(total >= 0) {
259 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
261 } else {
263 }
264 text::close_layout_box(contents, box);
265 }
267 text::add_line(state, contents, "pop_con_2");
268 text::add_line(state, contents, "pop_con_3", text::variable_type::x, text::fp_two_places{lx_mod});
270 text::fp_two_places{cl_mod});
271 text::add_line(state, contents, "pop_con_5", text::variable_type::x, text::fp_two_places{lit_mod});
272
273 text::add_line(state, contents, "pop_con_6", text::variable_type::x,
274 text::fp_two_places{state.world.nation_get_plurality(owner)}, 15);
275 text::add_line(state, contents, "pop_con_7", text::variable_type::x,
276 text::fp_percentage{state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::literacy_con_impact) + 1.0f},
277 15);
278 active_modifiers_description(state, contents, owner, 30, sys::national_mod_offsets::literacy_con_impact, false);
279 text::add_line(state, contents, "pop_con_8", text::variable_type::x, text::fp_two_places{state.defines.con_literacy}, 15);
281 15);
282 if(state.world.province_get_is_colonial(loc)) {
283 text::add_line(state, contents, "pop_con_10", text::variable_type::x, text::fp_two_places{state.defines.con_colonial_factor},
284 15);
285 }
286 text::add_line(state, contents, "pop_con_11", 15);
287 {
288 auto box = text::open_layout_box(contents);
289 text::localised_format_box(state, contents, box, "pop_con_12");
290 if(pmod >= 0) {
291 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
293 } else {
295 }
296 text::close_layout_box(contents, box);
297 active_modifiers_description(state, contents, loc, 15, sys::provincial_mod_offsets::pop_consciousness_modifier, false);
298 }
299 {
300 auto box = text::open_layout_box(contents);
301 text::localised_format_box(state, contents, box, "pop_con_13");
302 if(omod >= 0) {
303 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
305 } else {
307 }
308 text::close_layout_box(contents, box);
309 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::global_pop_consciousness_modifier, false);
310 }
311 if(!state.world.province_get_is_colonial(loc)) {
312 auto box = text::open_layout_box(contents);
313 text::localised_format_box(state, contents, box, "pop_con_14");
314 if(cmod >= 0) {
315 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
317 } else {
319 }
320 text::close_layout_box(contents, box);
321 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::core_pop_consciousness_modifier, false);
322 }
323 if(!state.world.pop_get_is_primary_or_accepted_culture(ids)) {
324 auto box = text::open_layout_box(contents);
325 text::localised_format_box(state, contents, box, "pop_con_15");
326 if(sep_mod >= 0) {
327 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
329 } else {
331 }
332 text::close_layout_box(contents, box);
333 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::non_accepted_pop_consciousness_modifier,
334 false);
335 }
336 text::add_line(state, contents, "alice_con_decay_description", text::variable_type::x, text::fp_three_places{ pop_demographics::get_consciousness(state, ids) * 0.01f });
337}
338
339void describe_mil(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
340 auto const conservatism_key = pop_demographics::to_key(state, state.culture_definitions.conservative);
341
342 auto loc = state.world.pop_get_province_from_pop_location(ids);
343 auto owner = state.world.province_get_nation_from_province_ownership(loc);
344 auto ruling_party = state.world.nation_get_ruling_party(owner);
345 auto ruling_ideology = state.world.political_party_get_ideology(ruling_party);
346
347 float lx_mod = std::max(pop_demographics::get_luxury_needs(state, ids) - 0.5f, 0.0f) * state.defines.mil_has_luxury_need;
348 float con_sup = (pop_demographics::get_demo(state, ids, conservatism_key) * state.defines.mil_ideology);
349 float ruling_sup = ruling_ideology ? pop_demographics::get_demo(state, ids, pop_demographics::to_key(state, ruling_ideology)) * state.defines.mil_ruling_party : 0.0f;
350 float ref_mod = state.world.province_get_is_colonial(loc)
351 ? 0.0f
353 (state.defines.mil_require_reform * 0.25f);
354
355 float sub_t = (lx_mod + ruling_sup) + (con_sup + ref_mod);
356
357 auto o_spending = state.world.nation_get_overseas_penalty(owner);
358 auto spending_level = state.world.nation_get_spending_level(owner);
359 auto overseas_mil = 0.f;
360 if(province::is_overseas(state, loc)) {
361 overseas_mil = 2.f * state.defines.alice_overseas_mil * (0.5f - (o_spending * spending_level));
362 }
363
364 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_militancy_modifier);
365 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_militancy_modifier);
366 float cmod = (state.world.province_get_is_colonial(loc) ? 0.0f :
367 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_militancy_modifier));
368
369 float local_mod = (pmod + omod) + cmod;
370
371 float sep_mod = (state.world.pop_get_is_primary_or_accepted_culture(ids) ? 0.0f :
372 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f) *
373 state.defines.mil_non_accepted);
374 float ln_mod = std::min((pop_demographics::get_life_needs(state, ids) - 0.5f), 0.0f) * state.defines.mil_no_life_need;
375 float en_mod_a =
376 std::min(0.0f, (pop_demographics::get_everyday_needs(state, ids) - 0.5f)) * state.defines.mil_lack_everyday_need;
377 float en_mod_b =
378 std::max(0.0f, (pop_demographics::get_everyday_needs(state, ids) - 0.5f)) * state.defines.mil_has_everyday_need;
379 //Ranges from +0.00 - +0.50 militancy monthly, 0 - 100 war exhaustion
380 float war_exhaustion =
381 state.world.nation_get_war_exhaustion(owner) * state.defines.mil_war_exhaustion;
382 auto old_mil = pop_demographics::get_militancy(state, ids) * 0.01f;
383 float total = (sub_t + local_mod) + ((sep_mod - ln_mod - old_mil) + (en_mod_b - en_mod_a) + (war_exhaustion + overseas_mil));
384
385 {
386 auto box = text::open_layout_box(contents);
387 text::localised_format_box(state, contents, box, "pop_mil_1");
388 if(total >= 0) {
389 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::red);
391 } else {
393 }
394 text::close_layout_box(contents, box);
395 }
397 text::add_line(state, contents, "pop_mil_2");
398 text::add_line(state, contents, "pop_mil_3", text::variable_type::x, text::fp_two_places{ln_mod < 0.0f ? -ln_mod : 0.0f});
399 {
400 auto box = text::open_layout_box(contents);
401 text::localised_format_box(state, contents, box, "pop_mil_4");
402 if(en_mod_b - en_mod_a >= 0) {
403 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::red);
404 text::add_to_layout_box(state, contents, box, text::fp_two_places{en_mod_b - en_mod_a}, text::text_color::red);
405 } else {
406 text::add_to_layout_box(state, contents, box, text::fp_two_places{en_mod_b - en_mod_a}, text::text_color::green);
407 }
408 text::close_layout_box(contents, box);
409 }
410 text::add_line(state, contents, "pop_mil_5", text::variable_type::x, text::fp_two_places{lx_mod});
411 text::add_line(state, contents, "pop_mil_6", text::variable_type::x, text::fp_two_places{con_sup});
412 text::add_line(state, contents, "pop_mil_7", text::variable_type::x, text::fp_two_places{ruling_sup});
413 text::add_line(state, contents, "pop_mil_8", text::variable_type::x, text::fp_two_places{ref_mod});
414 {
415 auto box = text::open_layout_box(contents);
416 text::localised_format_box(state, contents, box, "pop_mil_9");
417 if(pmod >= 0) {
418 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
420 } else {
422 }
423 text::close_layout_box(contents, box);
424 active_modifiers_description(state, contents, loc, 15, sys::provincial_mod_offsets::pop_militancy_modifier, false);
425 }
426 {
427 auto box = text::open_layout_box(contents);
428 text::localised_format_box(state, contents, box, "pop_mil_10");
429 if(omod >= 0) {
430 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
432 } else {
434 }
435 text::close_layout_box(contents, box);
436 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::global_pop_militancy_modifier, false);
437 }
438 if(!state.world.province_get_is_colonial(loc)) {
439 auto box = text::open_layout_box(contents);
440 text::localised_format_box(state, contents, box, "pop_mil_11");
441 if(cmod >= 0) {
442 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
444 } else {
446 }
447 text::close_layout_box(contents, box);
448 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::core_pop_militancy_modifier, false);
449 }
450 if(!state.world.pop_get_is_primary_or_accepted_culture(ids)) {
451 text::add_line(state, contents, "pop_mil_12",
453 text::variable_type::x, text::fp_two_places{state.defines.mil_non_accepted},
454 text::variable_type::y, text::fp_percentage{state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f});
455 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::non_accepted_pop_militancy_modifier, false);
456 }
457 if(war_exhaustion > 0) {
458 text::add_line(state, contents, "pop_mil_13", text::variable_type::val, text::fp_three_places{war_exhaustion});
459 }
460
461 auto box = text::open_layout_box(contents);
462 text::localised_format_box(state, contents, box, "alice_overseas_mil_description");
463 text::add_space_to_layout_box(state, contents, box);
464 if(overseas_mil <= 0) {
466 } else {
467 text::add_to_layout_box(state, contents, box, std::string_view{ "+" }, text::text_color::red);
469 }
470 text::close_layout_box(contents, box);
471
472 text::add_line(state, contents, "alice_mil_decay_description", text::variable_type::x, text::fp_three_places{ pop_demographics::get_militancy(state, ids) * state.defines.alice_militancy_decay });
473}
474
475void describe_lit(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
476 auto const clergy_key = demographics::to_key(state, state.culture_definitions.clergy);
477
478 auto loc = state.world.pop_get_province_from_pop_location(ids);
479 auto owner = state.world.province_get_nation_from_province_ownership(loc);
480 auto cfrac =
481 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
482
483 auto tmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency) + 1.0f;
484 auto nmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency_modifier) + 1.0f;
485 auto espending =
486 (float(state.world.nation_get_education_spending(owner)) / 100.0f) * state.world.nation_get_spending_level(owner);
487 auto cmod = std::max(0.0f, std::min(1.0f, (cfrac - state.defines.base_clergy_for_literacy) /
488 (state.defines.max_clergy_for_literacy - state.defines.base_clergy_for_literacy)));
489
490 float total = (0.01f * state.defines.literacy_change_speed) * ((espending * cmod) * (tmod * nmod));
491
492 {
493 auto box = text::open_layout_box(contents);
494 text::localised_format_box(state, contents, box, "pop_lit_1");
495 if(total >= 0) {
496 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
498 } else {
500 }
501 text::close_layout_box(contents, box);
502 }
504 text::add_line(state, contents, "pop_lit_2");
506 text::fp_two_places{cmod});
507 text::add_line(state, contents, "pop_lit_4", text::variable_type::x, text::fp_two_places{espending});
508 text::add_line(state, contents, "pop_lit_5", text::variable_type::x, text::fp_percentage{tmod});
509 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::education_efficiency, false);
510 text::add_line(state, contents, "pop_lit_6", text::variable_type::x, text::fp_percentage{nmod});
511 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::education_efficiency_modifier, false);
512 text::add_line(state, contents, "pop_lit_7", text::variable_type::x, text::fp_two_places{state.defines.literacy_change_speed});
513 text::add_line(state, contents, "pop_lit_8");
514}
515
516void describe_growth(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
517 auto type = state.world.pop_get_poptype(ids);
518
519 auto loc = state.world.pop_get_province_from_pop_location(ids);
520 auto owner = state.world.province_get_nation_from_province_ownership(loc);
521
522 auto base_life_rating = float(state.world.province_get_life_rating(loc));
523 auto mod_life_rating = std::min(
524 base_life_rating * (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::life_rating) + 1.0f), 40.0f);
525 auto lr_factor =
526 std::max((mod_life_rating - state.defines.min_life_rating_for_growth) * state.defines.life_rating_growth_bonus, 0.0f);
527 auto province_factor = lr_factor + state.defines.base_popgrowth;
528
529 auto ln_factor = pop_demographics::get_life_needs(state, ids) - state.defines.life_need_starvation_limit;
530 auto mod_sum = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::population_growth) + state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::pop_growth);
531
532 auto total_factor = ln_factor * province_factor * 4.0f + mod_sum * 0.1f;
533
534 if(type == state.culture_definitions.slaves)
535 total_factor = 0.0f;
536
537 {
538 auto box = text::open_layout_box(contents);
539 text::localised_format_box(state, contents, box, "pop_growth_1");
540 if(total_factor >= 0) {
541 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
542 text::add_to_layout_box(state, contents, box, int64_t(total_factor * state.world.pop_get_size(ids)), text::text_color::green);
543 } else {
544 text::add_to_layout_box(state, contents, box, int64_t(total_factor * state.world.pop_get_size(ids)),
546 }
547 text::close_layout_box(contents, box);
548 }
550
551 if(type == state.culture_definitions.slaves) {
552 text::add_line(state, contents, "pop_growth_2");
553 return;
554 }
555 text::add_line(state, contents, "pop_growth_3");
556 text::add_line(state, contents, "pop_growth_4", text::variable_type::x, text::fp_three_places{ln_factor * province_factor * 4.0f});
557 text::add_line(state, contents, "pop_growth_5", text::variable_type::x, text::fp_four_places{province_factor}, 15);
558 text::add_line(state, contents, "pop_growth_6", text::variable_type::x, text::fp_one_place{mod_life_rating},
559 text::variable_type::y, text::fp_one_place{state.defines.min_life_rating_for_growth}, text::variable_type::val,
560 text::fp_four_places{state.defines.life_rating_growth_bonus},
561 30);
562 text::add_line(state, contents, "pop_growth_7", text::variable_type::x, text::fp_three_places{state.defines.base_popgrowth},
563 30);
564 text::add_line(state, contents, "pop_growth_8", text::variable_type::x, text::fp_two_places{ln_factor},
566 text::fp_two_places{state.defines.life_need_starvation_limit},
567 15);
568 text::add_line(state, contents, "pop_growth_9", 15);
569 text::add_line(state, contents, "pop_growth_10", text::variable_type::x,
570 text::fp_three_places{state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::population_growth)});
571 active_modifiers_description(state, contents, loc, 15, sys::provincial_mod_offsets::population_growth, false);
572 text::add_line(state, contents, "pop_growth_11", text::variable_type::x,
573 text::fp_three_places{state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::pop_growth)});
574 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::pop_growth, false);
575}
576
577void describe_assimilation(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
578 auto location = state.world.pop_get_province_from_pop_location(ids);
579 auto owner = state.world.province_get_nation_from_province_ownership(location);
580 auto assimilation_chances = std::max(trigger::evaluate_additive_modifier(state, state.culture_definitions.assimilation_chance, trigger::to_generic(ids), trigger::to_generic(ids), 0), 0.0f);
581
582 float base_amount =
583 state.defines.assimilation_scale *
584 (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f) *
585 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f) *
586 assimilation_chances;
587
588 /*
589 In a colonial province, assimilation numbers for pops with an *non* "overseas"-type culture group are reduced by a
590 factor of 100. In a non-colonial province, assimilation numbers for pops with an *non* "overseas"-type culture
591 group are reduced by a factor of 10.
592 */
593
594 auto pc = state.world.pop_get_culture(ids);
595 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
596 base_amount /= 10.0f;
597 }
598
599
600 /*
601 All pops have their assimilation numbers reduced by a factor of 100 per core in the province sharing their primary
602 culture.
603 */
604 for(auto core : state.world.province_get_core(location)) {
605 if(core.get_identity().get_primary_culture() == pc) {
606 base_amount /= 100.0f;
607 }
608 }
609
610 // slaves do not assimilate
611 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
612 base_amount = 0.0f;
613
614 // pops of an accepted culture do not assimilate
615 if(state.world.pop_get_is_primary_or_accepted_culture(ids))
616 base_amount = 0.0f;
617
618 // pops in an overseas and colonial province do not assimilate
619 if(state.world.province_get_is_colonial(location) && province::is_overseas(state, location))
620 base_amount = 0.0f;
621
622 text::add_line(state, contents, "pop_assim_1", text::variable_type::x, int64_t(std::max(0.0f, state.world.pop_get_size(ids) * base_amount)));
624
625 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves) {
626 text::add_line(state, contents, "pop_assim_2");
627 return;
628 }
629 if(state.world.pop_get_is_primary_or_accepted_culture(ids)) {
630 text::add_line(state, contents, "pop_assim_3");
631 return;
632 }
633 if(state.world.province_get_is_colonial(location)) {
634 text::add_line(state, contents, "pop_assim_4");
635 return;
636 }
638 text::add_line(state, contents, "pop_assim_5");
639 return;
640 }
641 text::add_line(state, contents, "pop_assim_6");
642 text::add_line(state, contents, "pop_assim_7", text::variable_type::x, text::fp_three_places{state.defines.assimilation_scale});
643 text::add_line(state, contents, "pop_assim_8", text::variable_type::x, text::fp_two_places{ std::max(0.0f,state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f)});
644 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::global_assimilation_rate, true);
645 text::add_line(state, contents, "pop_assim_9", text::variable_type::x, text::fp_two_places{ std::max(0.0f, state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f)});
646 active_modifiers_description(state, contents, location, 15, sys::provincial_mod_offsets::assimilation_rate, true);
647
648 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
649 text::add_line(state, contents, "pop_assim_10");
650 }
651 float core_factor = 1.0f;
652 for(auto core : state.world.province_get_core(location)) {
653 if(core.get_identity().get_primary_culture() == pc) {
654 core_factor /= 100.0f;
655 }
656 }
657 if(core_factor < 1.0f) {
658 text::add_line(state, contents, "pop_assim_11", text::variable_type::x, text::fp_four_places{core_factor});
659 }
660 text::add_line(state, contents, "pop_assim_12", text::variable_type::x, text::fp_four_places{assimilation_chances});
661 additive_value_modifier_description(state, contents, state.culture_definitions.assimilation_chance, trigger::to_generic(ids),
662 trigger::to_generic(ids), 0);
663}
664
665std::vector<dcon::pop_id> const& get_pop_window_list(sys::state& state) {
666 static const std::vector<dcon::pop_id> empty{};
667 if(state.ui_state.population_subwindow)
668 return static_cast<population_window*>(state.ui_state.population_subwindow)->country_pop_listbox->row_contents;
669 return empty;
670}
671
673 dcon::pop_id id{};
674 if(state.ui_state.population_subwindow) {
675 auto win = static_cast<population_window*>(state.ui_state.population_subwindow)->details_win;
676 if(win) {
677 Cyto::Any payload = dcon::pop_id{};
678 win->impl_get(state, payload);
679 id = any_cast<dcon::pop_id>(payload);
680 }
681 }
682 return id;
683}
684
686 if(parent) {
687 Cyto::Any payload = dcon::state_instance_id{};
688 parent->impl_get(state, payload);
689
690 auto pop_window = static_cast<population_window*>(state.ui_state.population_subwindow);
691 pop_window->focus_state = any_cast<dcon::state_instance_id>(payload);
692 pop_window->nf_win->set_visible(state, !pop_window->nf_win->is_visible());
693 pop_window->nf_win->base_data.position = base_data.position;
694 pop_window->move_child_to_front(pop_window->nf_win);
695 pop_window->impl_on_update(state);
696 }
697}
698
699} // namespace ui
void button_action(sys::state &state) noexcept override
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
Definition: nations.cpp:69
float get_social_reform_desire(sys::state const &state, dcon::pop_id p)
float get_luxury_needs(sys::state const &state, dcon::pop_id p)
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_life_needs(sys::state const &state, dcon::pop_id p)
float get_political_reform_desire(sys::state const &state, dcon::pop_id p)
float get_everyday_needs(sys::state const &state, dcon::pop_id p)
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
bool is_overseas(sys::state const &state, dcon::province_id ids)
Definition: province.cpp:18
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
Definition: text.cpp:1165
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1880
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
Definition: text.cpp:1152
void add_space_to_layout_box(sys::state &state, layout_base &dest, layout_box &box)
Definition: text.cpp:1788
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
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
void describe_conversion(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
std::vector< dcon::pop_id > const & get_pop_window_list(sys::state &state)
void describe_mil(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_growth(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void additive_value_modifier_description(sys::state &state, text::layout_base &layout, dcon::value_modifier_key modifier, int32_t primary, int32_t this_slot, int32_t from_slot)
void describe_emigration(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_lit(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_migration(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_con(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_promotion_demotion(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_colonial_migration(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
void describe_assimilation(sys::state &state, text::columnar_layout &contents, dcon::pop_id ids)
dcon::pop_id get_pop_details_pop(sys::state &state)
void active_modifiers_description(sys::state &state, text::layout_base &layout, dcon::nation_id n, int32_t identation, dcon::national_modifier_value nmid, bool header)
uchar uint8_t
element_base * population_subwindow