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 = state.world.pop_get_luxury_needs_satisfaction(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 * state.world.pop_get_literacy(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 = state.world.pop_get_consciousness(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);
280 text::add_line(state, contents, "pop_con_9", text::variable_type::x, text::fp_percentage{state.world.pop_get_literacy(ids)},
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{ state.world.pop_get_consciousness(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(state.world.pop_get_luxury_needs_satisfaction(ids) - 0.5f, 0.0f) * state.defines.mil_has_luxury_need;
348 float con_sup = (state.world.pop_get_demographics(ids, conservatism_key) * state.defines.mil_ideology);
349 float ruling_sup = ruling_ideology ? state.world.pop_get_demographics(ids, pop_demographics::to_key(state, ruling_ideology)) *
350 state.defines.mil_ruling_party
351 : 0.0f;
352 float ref_mod = state.world.province_get_is_colonial(loc)
353 ? 0.0f
354 : (state.world.pop_get_social_reform_desire(ids) + state.world.pop_get_political_reform_desire(ids)) *
355 (state.defines.mil_require_reform * 0.25f);
356
357 float sub_t = (lx_mod + ruling_sup) + (con_sup + ref_mod);
358
359 auto o_spending = state.world.nation_get_overseas_penalty(owner);
360 auto spending_level = state.world.nation_get_spending_level(owner);
361 auto overseas_mil = 0.f;
362 if(province::is_overseas(state, loc)) {
363 overseas_mil = 2.f * state.defines.alice_overseas_mil * (0.5f - (o_spending * spending_level));
364 }
365
366 float pmod = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::pop_militancy_modifier);
367 float omod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_pop_militancy_modifier);
368 float cmod = (state.world.province_get_is_colonial(loc) ? 0.0f :
369 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::core_pop_militancy_modifier));
370
371 float local_mod = (pmod + omod) + cmod;
372
373 float sep_mod = (state.world.pop_get_is_primary_or_accepted_culture(ids) ? 0.0f :
374 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::non_accepted_pop_militancy_modifier) + 1.0f) *
375 state.defines.mil_non_accepted);
376 float ln_mod = std::min((state.world.pop_get_life_needs_satisfaction(ids) - 0.5f), 0.0f) * state.defines.mil_no_life_need;
377 float en_mod_a =
378 std::min(0.0f, (state.world.pop_get_everyday_needs_satisfaction(ids) - 0.5f)) * state.defines.mil_lack_everyday_need;
379 float en_mod_b =
380 std::max(0.0f, (state.world.pop_get_everyday_needs_satisfaction(ids) - 0.5f)) * state.defines.mil_has_everyday_need;
381 //Ranges from +0.00 - +0.50 militancy monthly, 0 - 100 war exhaustion
382 float war_exhaustion =
383 state.world.nation_get_war_exhaustion(owner) * state.defines.mil_war_exhaustion;
384 auto old_mil = state.world.pop_get_militancy(ids) * 0.01f;
385 float total = (sub_t + local_mod) + ((sep_mod - ln_mod - old_mil) + (en_mod_b - en_mod_a) + (war_exhaustion + overseas_mil));
386
387 {
388 auto box = text::open_layout_box(contents);
389 text::localised_format_box(state, contents, box, "pop_mil_1");
390 if(total >= 0) {
391 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::red);
393 } else {
395 }
396 text::close_layout_box(contents, box);
397 }
399 text::add_line(state, contents, "pop_mil_2");
400 text::add_line(state, contents, "pop_mil_3", text::variable_type::x, text::fp_two_places{ln_mod < 0.0f ? -ln_mod : 0.0f});
401 {
402 auto box = text::open_layout_box(contents);
403 text::localised_format_box(state, contents, box, "pop_mil_4");
404 if(en_mod_b - en_mod_a >= 0) {
405 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::red);
406 text::add_to_layout_box(state, contents, box, text::fp_two_places{en_mod_b - en_mod_a}, text::text_color::red);
407 } else {
408 text::add_to_layout_box(state, contents, box, text::fp_two_places{en_mod_b - en_mod_a}, text::text_color::green);
409 }
410 text::close_layout_box(contents, box);
411 }
412 text::add_line(state, contents, "pop_mil_5", text::variable_type::x, text::fp_two_places{lx_mod});
413 text::add_line(state, contents, "pop_mil_6", text::variable_type::x, text::fp_two_places{con_sup});
414 text::add_line(state, contents, "pop_mil_7", text::variable_type::x, text::fp_two_places{ruling_sup});
415 text::add_line(state, contents, "pop_mil_8", text::variable_type::x, text::fp_two_places{ref_mod});
416 {
417 auto box = text::open_layout_box(contents);
418 text::localised_format_box(state, contents, box, "pop_mil_9");
419 if(pmod >= 0) {
420 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
422 } else {
424 }
425 text::close_layout_box(contents, box);
426 active_modifiers_description(state, contents, loc, 15, sys::provincial_mod_offsets::pop_militancy_modifier, false);
427 }
428 {
429 auto box = text::open_layout_box(contents);
430 text::localised_format_box(state, contents, box, "pop_mil_10");
431 if(omod >= 0) {
432 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
434 } else {
436 }
437 text::close_layout_box(contents, box);
438 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::global_pop_militancy_modifier, false);
439 }
440 if(!state.world.province_get_is_colonial(loc)) {
441 auto box = text::open_layout_box(contents);
442 text::localised_format_box(state, contents, box, "pop_mil_11");
443 if(cmod >= 0) {
444 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
446 } else {
448 }
449 text::close_layout_box(contents, box);
450 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::core_pop_militancy_modifier, false);
451 }
452 if(!state.world.pop_get_is_primary_or_accepted_culture(ids)) {
453 text::add_line(state, contents, "pop_mil_12",
455 text::variable_type::x, text::fp_two_places{state.defines.mil_non_accepted},
456 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});
457 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::non_accepted_pop_militancy_modifier, false);
458 }
459 if(war_exhaustion > 0) {
460 text::add_line(state, contents, "pop_mil_13", text::variable_type::val, text::fp_three_places{war_exhaustion});
461 }
462
463 auto box = text::open_layout_box(contents);
464 text::localised_format_box(state, contents, box, "alice_overseas_mil_description");
465 text::add_space_to_layout_box(state, contents, box);
466 if(overseas_mil <= 0) {
468 } else {
469 text::add_to_layout_box(state, contents, box, std::string_view{ "+" }, text::text_color::red);
471 }
472 text::close_layout_box(contents, box);
473
474 text::add_line(state, contents, "alice_mil_decay_description", text::variable_type::x, text::fp_three_places{ state.world.pop_get_militancy(ids) * state.defines.alice_militancy_decay });
475}
476
477void describe_lit(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
478 auto const clergy_key = demographics::to_key(state, state.culture_definitions.clergy);
479
480 auto loc = state.world.pop_get_province_from_pop_location(ids);
481 auto owner = state.world.province_get_nation_from_province_ownership(loc);
482 auto cfrac =
483 state.world.province_get_demographics(loc, clergy_key) / state.world.province_get_demographics(loc, demographics::total);
484
485 auto tmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency) + 1.0f;
486 auto nmod = state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::education_efficiency_modifier) + 1.0f;
487 auto espending =
488 (float(state.world.nation_get_education_spending(owner)) / 100.0f) * state.world.nation_get_spending_level(owner);
489 auto cmod = std::max(0.0f, std::min(1.0f, (cfrac - state.defines.base_clergy_for_literacy) /
490 (state.defines.max_clergy_for_literacy - state.defines.base_clergy_for_literacy)));
491
492 float total = (0.01f * state.defines.literacy_change_speed) * ((espending * cmod) * (tmod * nmod));
493
494 {
495 auto box = text::open_layout_box(contents);
496 text::localised_format_box(state, contents, box, "pop_lit_1");
497 if(total >= 0) {
498 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
500 } else {
502 }
503 text::close_layout_box(contents, box);
504 }
506 text::add_line(state, contents, "pop_lit_2");
508 text::fp_two_places{cmod});
509 text::add_line(state, contents, "pop_lit_4", text::variable_type::x, text::fp_two_places{espending});
510 text::add_line(state, contents, "pop_lit_5", text::variable_type::x, text::fp_percentage{tmod});
511 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::education_efficiency, false);
512 text::add_line(state, contents, "pop_lit_6", text::variable_type::x, text::fp_percentage{nmod});
513 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::education_efficiency_modifier, false);
514 text::add_line(state, contents, "pop_lit_7", text::variable_type::x, text::fp_two_places{state.defines.literacy_change_speed});
515 text::add_line(state, contents, "pop_lit_8");
516}
517
518void describe_growth(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
519 auto type = state.world.pop_get_poptype(ids);
520
521 auto loc = state.world.pop_get_province_from_pop_location(ids);
522 auto owner = state.world.province_get_nation_from_province_ownership(loc);
523
524 auto base_life_rating = float(state.world.province_get_life_rating(loc));
525 auto mod_life_rating = std::min(
526 base_life_rating * (state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::life_rating) + 1.0f), 40.0f);
527 auto lr_factor =
528 std::max((mod_life_rating - state.defines.min_life_rating_for_growth) * state.defines.life_rating_growth_bonus, 0.0f);
529 auto province_factor = lr_factor + state.defines.base_popgrowth;
530
531 auto ln_factor = state.world.pop_get_life_needs_satisfaction(ids) - state.defines.life_need_starvation_limit;
532 auto mod_sum = state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::population_growth) +
533 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::pop_growth);
534
535 auto total_factor = ln_factor * province_factor * 4.0f + mod_sum * 0.1f;
536
537 if(type == state.culture_definitions.slaves)
538 total_factor = 0.0f;
539
540 {
541 auto box = text::open_layout_box(contents);
542 text::localised_format_box(state, contents, box, "pop_growth_1");
543 if(total_factor >= 0) {
544 text::add_to_layout_box(state, contents, box, std::string_view{"+"}, text::text_color::green);
545 text::add_to_layout_box(state, contents, box, int64_t(total_factor * state.world.pop_get_size(ids)), text::text_color::green);
546 } else {
547 text::add_to_layout_box(state, contents, box, int64_t(total_factor * state.world.pop_get_size(ids)),
549 }
550 text::close_layout_box(contents, box);
551 }
553
554 if(type == state.culture_definitions.slaves) {
555 text::add_line(state, contents, "pop_growth_2");
556 return;
557 }
558 text::add_line(state, contents, "pop_growth_3");
559 text::add_line(state, contents, "pop_growth_4", text::variable_type::x, text::fp_three_places{ln_factor * province_factor * 4.0f});
560 text::add_line(state, contents, "pop_growth_5", text::variable_type::x, text::fp_four_places{province_factor}, 15);
561 text::add_line(state, contents, "pop_growth_6", text::variable_type::x, text::fp_one_place{mod_life_rating},
562 text::variable_type::y, text::fp_one_place{state.defines.min_life_rating_for_growth}, text::variable_type::val,
563 text::fp_four_places{state.defines.life_rating_growth_bonus},
564 30);
565 text::add_line(state, contents, "pop_growth_7", text::variable_type::x, text::fp_three_places{state.defines.base_popgrowth},
566 30);
567 text::add_line(state, contents, "pop_growth_8", text::variable_type::x, text::fp_two_places{ln_factor},
568 text::variable_type::y, text::fp_two_places{state.world.pop_get_life_needs_satisfaction(ids)}, text::variable_type::val,
569 text::fp_two_places{state.defines.life_need_starvation_limit},
570 15);
571 text::add_line(state, contents, "pop_growth_9", 15);
572 text::add_line(state, contents, "pop_growth_10", text::variable_type::x,
573 text::fp_three_places{state.world.province_get_modifier_values(loc, sys::provincial_mod_offsets::population_growth)});
574 active_modifiers_description(state, contents, loc, 15, sys::provincial_mod_offsets::population_growth, false);
575 text::add_line(state, contents, "pop_growth_11", text::variable_type::x,
576 text::fp_three_places{state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::pop_growth)});
577 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::pop_growth, false);
578}
579
580void describe_assimilation(sys::state& state, text::columnar_layout& contents, dcon::pop_id ids) {
581 auto location = state.world.pop_get_province_from_pop_location(ids);
582 auto owner = state.world.province_get_nation_from_province_ownership(location);
583 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);
584
585 float base_amount =
586 state.defines.assimilation_scale *
587 (state.world.province_get_modifier_values(location, sys::provincial_mod_offsets::assimilation_rate) + 1.0f) *
588 (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::global_assimilation_rate) + 1.0f) *
589 assimilation_chances;
590
591 /*
592 In a colonial province, assimilation numbers for pops with an *non* "overseas"-type culture group are reduced by a
593 factor of 100. In a non-colonial province, assimilation numbers for pops with an *non* "overseas"-type culture
594 group are reduced by a factor of 10.
595 */
596
597 auto pc = state.world.pop_get_culture(ids);
598 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
599 base_amount /= 10.0f;
600 }
601
602
603 /*
604 All pops have their assimilation numbers reduced by a factor of 100 per core in the province sharing their primary
605 culture.
606 */
607 for(auto core : state.world.province_get_core(location)) {
608 if(core.get_identity().get_primary_culture() == pc) {
609 base_amount /= 100.0f;
610 }
611 }
612
613 // slaves do not assimilate
614 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves)
615 base_amount = 0.0f;
616
617 // pops of an accepted culture do not assimilate
618 if(state.world.pop_get_is_primary_or_accepted_culture(ids))
619 base_amount = 0.0f;
620
621 // pops in an overseas and colonial province do not assimilate
622 if(state.world.province_get_is_colonial(location) && province::is_overseas(state, location))
623 base_amount = 0.0f;
624
625 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)));
627
628 if(state.world.pop_get_poptype(ids) == state.culture_definitions.slaves) {
629 text::add_line(state, contents, "pop_assim_2");
630 return;
631 }
632 if(state.world.pop_get_is_primary_or_accepted_culture(ids)) {
633 text::add_line(state, contents, "pop_assim_3");
634 return;
635 }
636 if(state.world.province_get_is_colonial(location)) {
637 text::add_line(state, contents, "pop_assim_4");
638 return;
639 }
641 text::add_line(state, contents, "pop_assim_5");
642 return;
643 }
644 text::add_line(state, contents, "pop_assim_6");
645 text::add_line(state, contents, "pop_assim_7", text::variable_type::x, text::fp_three_places{state.defines.assimilation_scale});
646 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)});
647 active_modifiers_description(state, contents, owner, 15, sys::national_mod_offsets::global_assimilation_rate, true);
648 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)});
649 active_modifiers_description(state, contents, location, 15, sys::provincial_mod_offsets::assimilation_rate, true);
650
651 if(!state.world.culture_group_get_is_overseas(state.world.culture_get_group_from_culture_group_membership(pc))) {
652 text::add_line(state, contents, "pop_assim_10");
653 }
654 float core_factor = 1.0f;
655 for(auto core : state.world.province_get_core(location)) {
656 if(core.get_identity().get_primary_culture() == pc) {
657 core_factor /= 100.0f;
658 }
659 }
660 if(core_factor < 1.0f) {
661 text::add_line(state, contents, "pop_assim_11", text::variable_type::x, text::fp_four_places{core_factor});
662 }
663 text::add_line(state, contents, "pop_assim_12", text::variable_type::x, text::fp_four_places{assimilation_chances});
664 additive_value_modifier_description(state, contents, state.culture_definitions.assimilation_chance, trigger::to_generic(ids),
665 trigger::to_generic(ids), 0);
666}
667
668std::vector<dcon::pop_id> const& get_pop_window_list(sys::state& state) {
669 static const std::vector<dcon::pop_id> empty{};
670 if(state.ui_state.population_subwindow)
671 return static_cast<population_window*>(state.ui_state.population_subwindow)->country_pop_listbox->row_contents;
672 return empty;
673}
674
676 dcon::pop_id id{};
677 if(state.ui_state.population_subwindow) {
678 auto win = static_cast<population_window*>(state.ui_state.population_subwindow)->details_win;
679 if(win) {
680 Cyto::Any payload = dcon::pop_id{};
681 win->impl_get(state, payload);
682 id = any_cast<dcon::pop_id>(payload);
683 }
684 }
685 return id;
686}
687
689 if(parent) {
690 Cyto::Any payload = dcon::state_instance_id{};
691 parent->impl_get(state, payload);
692
693 auto pop_window = static_cast<population_window*>(state.ui_state.population_subwindow);
694 pop_window->focus_state = any_cast<dcon::state_instance_id>(payload);
695 pop_window->nf_win->set_visible(state, !pop_window->nf_win->is_visible());
696 pop_window->nf_win->base_data.position = base_data.position;
697 pop_window->move_child_to_front(pop_window->nf_win);
698 pop_window->impl_on_update(state);
699 }
700}
701
702} // 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
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
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:5741
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