Project Alice
Loading...
Searching...
No Matches
demographics.hpp
Go to the documentation of this file.
1#pragma once
2#include "dcon_generated.hpp"
3#include "system_state.hpp"
4
5namespace pop_demographics {
6
7constexpr inline uint32_t count_special_keys = 0;
8
9dcon::pop_demographics_key to_key(sys::state const& state, dcon::ideology_id v);
10dcon::pop_demographics_key to_key(sys::state const& state, dcon::issue_option_id v);
11uint32_t size(sys::state const& state);
12
13constexpr inline float pop_mc_scaling = 10.0f / float(std::numeric_limits<uint16_t>::max());
14constexpr inline float pop_u16_scaling = 1.0f / float(std::numeric_limits<uint16_t>::max());
15constexpr inline float pop_u8_scaling = 1.0f / float(std::numeric_limits<uint8_t>::max());
16constexpr inline float inv_pop_mc_scaling = float(std::numeric_limits<uint16_t>::max()) / 10.0f;
17constexpr inline float inv_pop_u16_scaling = float(std::numeric_limits<uint16_t>::max());
18constexpr inline float inv_pop_u8_scaling = float(std::numeric_limits<uint8_t>::max());
19
20inline uint8_t to_pu8(float v) {
21 return uint8_t(v * inv_pop_u8_scaling + 0.49f);
22}
23inline uint16_t to_pu16(float v) {
24 return uint16_t(v * inv_pop_u16_scaling + 0.49f);
25}
26inline uint16_t to_pmc(float v) {
27 return uint16_t(v * inv_pop_mc_scaling + 0.49f);
28}
29inline ve::int_vector to_pu8(ve::fp_vector v) {
30 return ve::to_int(v * inv_pop_u8_scaling + 0.49f);
31}
32inline ve::int_vector to_pu16(ve::fp_vector v) {
33 return ve::to_int(v * inv_pop_u16_scaling + 0.49f);
34}
35inline ve::int_vector to_pmc(ve::fp_vector v) {
36 return ve::to_int(v * inv_pop_mc_scaling + 0.49f);
37}
38
39inline float from_pu8(uint8_t v) {
40 return float(v) * pop_u8_scaling;
41}
42inline float from_pu16(uint16_t v) {
43 return float(v) * pop_u16_scaling;
44}
45inline float from_pmc(uint16_t v) {
46 return float(v) * pop_mc_scaling;
47}
48
49inline ve::fp_vector from_pu8(ve::int_vector v) {
50 return ve::to_float(v) * pop_u8_scaling;
51}
52inline ve::fp_vector from_pu16(ve::int_vector v) {
53 return ve::to_float(v) * pop_u16_scaling;
54}
55inline ve::fp_vector from_pmc(ve::int_vector v) {
56 return ve::to_float(v) * pop_mc_scaling;
57}
58
60float get_demo(sys::state const& state, dcon::pop_id p, dcon::pop_demographics_key k);
61void set_demo(sys::state& state, dcon::pop_id p, dcon::pop_demographics_key k, float v);
62float get_militancy(sys::state const& state, dcon::pop_id p);
63void set_militancy(sys::state& state, dcon::pop_id p, float v);
64float get_consciousness(sys::state const& state, dcon::pop_id p);
65void set_consciousness(sys::state& state, dcon::pop_id p, float v);
66float get_literacy(sys::state const& state, dcon::pop_id p);
67void set_literacy(sys::state& state, dcon::pop_id p, float v);
68float get_employment(sys::state const& state, dcon::pop_id p);
69float get_raw_employment(sys::state const& state, dcon::pop_id p);
70void set_employment(sys::state& state, dcon::pop_id p, float v);
71void set_raw_employment(sys::state& state, dcon::pop_id p, float v);
72float get_life_needs(sys::state const& state, dcon::pop_id p);
73void set_life_needs(sys::state& state, dcon::pop_id p, float v);
74float get_everyday_needs(sys::state const& state, dcon::pop_id p);
75void set_everyday_needs(sys::state& state, dcon::pop_id p, float v);
76float get_luxury_needs(sys::state const& state, dcon::pop_id p);
77void set_luxury_needs(sys::state& state, dcon::pop_id p, float v);
78float get_social_reform_desire(sys::state const& state, dcon::pop_id p);
79void set_social_reform_desire(sys::state& state, dcon::pop_id p, float v);
80float get_political_reform_desire(sys::state const& state, dcon::pop_id p);
81void set_political_reform_desire(sys::state& state, dcon::pop_id p, float v);
82
83template<typename T>
84auto get_employment(sys::state const& state, T p) {
85 auto ival = state.world.pop_get_uemployment(p);
86 return from_pu8(ival) * state.world.pop_get_size(p);
87}
88template<typename T>
89auto get_raw_employment(sys::state const& state, T p) {
90 auto ival = state.world.pop_get_uemployment(p);
91 return from_pu8(ival);
92}
93template<typename T>
94auto get_social_reform_desire(sys::state const& state, T p) {
95 auto ival = state.world.pop_get_usocial_reform_desire(p);
96 return from_pu8(ival);
97}
98template<typename T>
99auto get_political_reform_desire(sys::state const& state, T p) {
100 auto ival = state.world.pop_get_upolitical_reform_desire(p);
101 return from_pu8(ival);
102}
103template<typename T>
104auto get_militancy(sys::state const& state, T p) {
105 auto ival = state.world.pop_get_umilitancy(p);
106 return from_pmc(ival);
107}
108template<typename T>
109auto get_consciousness(sys::state const& state, T p) {
110 auto ival = state.world.pop_get_uconsciousness(p);
111 return from_pmc(ival);
112}
113template<typename T>
114auto get_literacy(sys::state const& state, T p) {
115 auto ival = state.world.pop_get_uliteracy(p);
116 return from_pu16(ival);
117}
118template<typename T>
119auto get_life_needs(sys::state const& state, T p) {
120 auto ival = state.world.pop_get_ulife_needs_satisfaction(p);
121 return from_pu8(ival);
122}
123template<typename T>
124auto get_everyday_needs(sys::state const& state, T p) {
125 auto ival = state.world.pop_get_ueveryday_needs_satisfaction(p);
126 return from_pu8(ival);
127}
128template<typename T>
129auto get_luxury_needs(sys::state const& state, T p) {
130 auto ival = state.world.pop_get_uluxury_needs_satisfaction(p);
131 return from_pu8(ival);
132}
133template<typename T>
134auto get_demo(sys::state const& state, T p, dcon::pop_demographics_key k) {
135 auto ival = state.world.pop_get_udemographics(p, k);
136 return from_pu8(ival);
137}
138
139} // namespace pop_demographics
140namespace demographics {
141
142constexpr inline dcon::demographics_key total(0);
143constexpr inline dcon::demographics_key employable(1);
144constexpr inline dcon::demographics_key employed(2);
145constexpr inline dcon::demographics_key consciousness(3);
146constexpr inline dcon::demographics_key militancy(4);
147constexpr inline dcon::demographics_key literacy(5);
148constexpr inline dcon::demographics_key political_reform_desire(6);
149constexpr inline dcon::demographics_key social_reform_desire(7);
150constexpr inline dcon::demographics_key poor_militancy(8);
151constexpr inline dcon::demographics_key middle_militancy(9);
152constexpr inline dcon::demographics_key rich_militancy(10);
153constexpr inline dcon::demographics_key poor_life_needs(11);
154constexpr inline dcon::demographics_key middle_life_needs(12);
155constexpr inline dcon::demographics_key rich_life_needs(13);
156constexpr inline dcon::demographics_key poor_everyday_needs(14);
157constexpr inline dcon::demographics_key middle_everyday_needs(15);
158constexpr inline dcon::demographics_key rich_everyday_needs(16);
159constexpr inline dcon::demographics_key poor_luxury_needs(17);
160constexpr inline dcon::demographics_key middle_luxury_needs(18);
161constexpr inline dcon::demographics_key rich_luxury_needs(19);
162constexpr inline dcon::demographics_key poor_total(20);
163constexpr inline dcon::demographics_key middle_total(21);
164constexpr inline dcon::demographics_key rich_total(22);
165
166constexpr inline uint32_t count_special_keys = 23;
167
168dcon::demographics_key to_key(sys::state const& state, dcon::ideology_id v);
169dcon::demographics_key to_key(sys::state const& state, dcon::issue_option_id v);
170dcon::demographics_key to_key(sys::state const& state, dcon::pop_type_id v);
171dcon::demographics_key to_key(sys::state const& state, dcon::culture_id v);
172dcon::demographics_key to_key(sys::state const& state, dcon::religion_id v);
173dcon::demographics_key to_employment_key(sys::state const& state, dcon::pop_type_id v);
174
175uint32_t size(sys::state const& state);
176
177void regenerate_jingoism_support(sys::state& state, dcon::nation_id n);
182
184
188
190 for(uint32_t i = 0; i < state.world.ideology_size(); ++i) {
192 }
193 }
194
195 void update(sys::state& state, uint32_t s) {
196 if(size < s) {
197 size = s;
198 state.world.for_each_ideology(
199 [&](dcon::ideology_id i) { temp_buffers[i] = ve::vectorizable_buffer<uint8_t, dcon::pop_id>(s); /*state.world.pop_make_vectorizable_float_buffer();*/ });
200 }
201 }
202};
203
207
209 for(uint32_t i = 0; i < state.world.issue_option_size(); ++i) {
211 }
212 }
213
214 void update(sys::state& state, uint32_t s) {
215 if(size < s) {
216 size = s;
217 state.world.for_each_issue_option(
218 [&](dcon::issue_option_id i) { temp_buffers[i] = ve::vectorizable_buffer<uint8_t, dcon::pop_id>(s); /*state.world.pop_make_vectorizable_float_buffer();*/ });
219 }
220 }
221};
222
224 ve::vectorizable_buffer<float, dcon::pop_id> amounts;
225 ve::vectorizable_buffer<dcon::pop_type_id, dcon::pop_id> types;
228
230 void update(uint32_t s) {
231 size = s;
232 if(reserved < s) {
233 reserved = s;
234 amounts = ve::vectorizable_buffer<float, dcon::pop_id>(s);
235 types = ve::vectorizable_buffer<dcon::pop_type_id, dcon::pop_id>(s);
236 }
237 }
238};
239
241 ve::vectorizable_buffer<float, dcon::pop_id> amounts;
244
246 void update(uint32_t s) {
247 size = s;
248 if(reserved < s) {
249 reserved = s;
250 amounts = ve::vectorizable_buffer<float, dcon::pop_id>(s);
251 }
252 }
253};
254
256 ve::vectorizable_buffer<float, dcon::pop_id> amounts;
257 ve::vectorizable_buffer<dcon::province_id, dcon::pop_id> destinations;
260
262 void update(uint32_t s) {
263 size = s;
264 if(reserved < s) {
265 reserved = s;
266 amounts = ve::vectorizable_buffer<float, dcon::pop_id>(s);
267 destinations = ve::vectorizable_buffer<dcon::province_id, dcon::pop_id>(s);
268 }
269 }
270};
271
272void update_literacy(sys::state& state, uint32_t offset, uint32_t divisions);
273void update_consciousness(sys::state& state, uint32_t offset, uint32_t divisions);
274void update_militancy(sys::state& state, uint32_t offset, uint32_t divisions);
275void update_ideologies(sys::state& state, uint32_t offset, uint32_t divisions, ideology_buffer& ibuf);
276void update_issues(sys::state& state, uint32_t offset, uint32_t divisions, issues_buffer& ibuf);
277void update_growth(sys::state& state, uint32_t offset, uint32_t divisions);
278void update_type_changes(sys::state& state, uint32_t offset, uint32_t divisions, promotion_buffer& pbuf);
279void update_assimilation(sys::state& state, uint32_t offset, uint32_t divisions, assimilation_buffer& pbuf);
280void update_internal_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
281void update_colonial_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
282void update_immigration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
283
284float get_estimated_literacy_change(sys::state& state, dcon::nation_id n);
285float get_estimated_mil_change(sys::state& state, dcon::nation_id n);
286float get_estimated_con_change(sys::state& state, dcon::nation_id n);
287float get_estimated_promotion(sys::state& state, dcon::nation_id n);
288
289void apply_ideologies(sys::state& state, uint32_t offset, uint32_t divisions, ideology_buffer& pbuf);
290void apply_issues(sys::state& state, uint32_t offset, uint32_t divisions, issues_buffer& pbuf);
291void apply_type_changes(sys::state& state, uint32_t offset, uint32_t divisions, promotion_buffer& pbuf);
292void apply_assimilation(sys::state& state, uint32_t offset, uint32_t divisions, assimilation_buffer& pbuf);
293void apply_internal_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
294void apply_colonial_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
295void apply_immigration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
296
298void remove_small_pops(sys::state& state);
299
300float get_monthly_pop_increase(sys::state& state, dcon::pop_id);
301int64_t get_monthly_pop_increase(sys::state& state, dcon::nation_id n);
302int64_t get_monthly_pop_increase(sys::state& state, dcon::state_instance_id n);
303int64_t get_monthly_pop_increase(sys::state& state, dcon::province_id n);
304
305float get_estimated_literacy_change(sys::state& state, dcon::pop_id n);
306float get_estimated_mil_change(sys::state& state, dcon::pop_id n);
307float get_estimated_con_change(sys::state& state, dcon::pop_id n);
308float get_estimated_type_change(sys::state& state, dcon::pop_id n);
309float get_effective_estimation_type_change(sys::state& state, dcon::nation_id nation, dcon::pop_type_id target_type);
310float get_estimated_promotion(sys::state& state, dcon::pop_id n);
311float get_estimated_demotion(sys::state& state, dcon::pop_id n);
312float get_estimated_assimilation(sys::state& state, dcon::pop_id n);
313float get_estimated_internal_migration(sys::state& state, dcon::pop_id n);
314float get_estimated_colonial_migration(sys::state& state, dcon::pop_id n);
315float get_estimated_emigration(sys::state& state, dcon::pop_id n);
316void estimate_directed_immigration(sys::state& state, dcon::nation_id n, std::vector<float>& national_amounts);
317
318float calculate_nation_sol(sys::state& state, dcon::nation_id nation_id);
319void reduce_pop_size_safe(sys::state& state, dcon::pop_id pop_id, int32_t amount);
320
321} // namespace demographics
tag_type emplace_back(T &&... ts)
float get_effective_estimation_type_change(sys::state &state, dcon::nation_id nation, dcon::pop_type_id target_type)
constexpr dcon::demographics_key rich_life_needs(13)
constexpr dcon::demographics_key poor_luxury_needs(17)
constexpr dcon::demographics_key middle_life_needs(12)
float get_estimated_colonial_migration(sys::state &state, dcon::pop_id ids)
void estimate_directed_immigration(sys::state &state, dcon::nation_id n, std::vector< float > &national_amounts)
constexpr dcon::demographics_key rich_militancy(10)
void alt_demographics_update_extras(sys::state &state)
float get_estimated_literacy_change(sys::state &state, dcon::pop_id ids)
constexpr dcon::demographics_key middle_total(21)
constexpr dcon::demographics_key middle_luxury_needs(18)
float get_estimated_type_change(sys::state &state, dcon::pop_id ids)
constexpr dcon::demographics_key political_reform_desire(6)
float calculate_nation_sol(sys::state &state, dcon::nation_id nation_id)
void remove_small_pops(sys::state &state)
void regenerate_jingoism_support(sys::state &state, dcon::nation_id n)
void update_immigration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
constexpr dcon::demographics_key total(0)
constexpr dcon::demographics_key rich_everyday_needs(16)
constexpr dcon::demographics_key poor_militancy(8)
constexpr dcon::demographics_key rich_luxury_needs(19)
void apply_assimilation(sys::state &state, uint32_t offset, uint32_t divisions, assimilation_buffer &pbuf)
constexpr dcon::demographics_key poor_everyday_needs(14)
constexpr dcon::demographics_key middle_militancy(9)
void update_internal_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void apply_type_changes(sys::state &state, uint32_t offset, uint32_t divisions, promotion_buffer &pbuf)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
float get_estimated_mil_change(sys::state &state, dcon::pop_id ids)
constexpr uint32_t count_special_keys
constexpr dcon::demographics_key employable(1)
void update_growth(sys::state &state, uint32_t offset, uint32_t divisions)
void alt_regenerate_from_pop_data_daily(sys::state &state)
constexpr dcon::demographics_key consciousness(3)
void update_issues(sys::state &state, uint32_t offset, uint32_t divisions, issues_buffer &ibuf)
void apply_internal_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
constexpr dcon::demographics_key rich_total(22)
constexpr dcon::demographics_key poor_total(20)
void update_type_changes(sys::state &state, uint32_t offset, uint32_t divisions, promotion_buffer &pbuf)
void regenerate_from_pop_data_full(sys::state &state)
void reduce_pop_size_safe(sys::state &state, dcon::pop_id pop_id, int32_t amount)
float get_estimated_internal_migration(sys::state &state, dcon::pop_id ids)
float get_estimated_demotion(sys::state &state, dcon::pop_id ids)
constexpr dcon::demographics_key poor_life_needs(11)
constexpr dcon::demographics_key employed(2)
uint32_t size(sys::state const &state)
float get_monthly_pop_increase(sys::state &state, dcon::pop_id ids)
float get_estimated_con_change(sys::state &state, dcon::pop_id ids)
dcon::demographics_key to_employment_key(sys::state const &state, dcon::pop_type_id v)
constexpr dcon::demographics_key social_reform_desire(7)
void update_assimilation(sys::state &state, uint32_t offset, uint32_t divisions, assimilation_buffer &pbuf)
void alt_regenerate_from_pop_data_full(sys::state &state)
void remove_size_zero_pops(sys::state &state)
constexpr dcon::demographics_key literacy(5)
void update_colonial_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
void apply_ideologies(sys::state &state, uint32_t offset, uint32_t divisions, ideology_buffer &pbuf)
void update_ideologies(sys::state &state, uint32_t offset, uint32_t divisions, ideology_buffer &ibuf)
void update_consciousness(sys::state &state, uint32_t offset, uint32_t divisions)
constexpr dcon::demographics_key middle_everyday_needs(15)
float get_estimated_assimilation(sys::state &state, dcon::pop_id ids)
void update_literacy(sys::state &state, uint32_t offset, uint32_t divisions)
void update_militancy(sys::state &state, uint32_t offset, uint32_t divisions)
void apply_colonial_migration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
float get_estimated_emigration(sys::state &state, dcon::pop_id ids)
void regenerate_from_pop_data_daily(sys::state &state)
constexpr dcon::demographics_key militancy(4)
void apply_immigration(sys::state &state, uint32_t offset, uint32_t divisions, migration_buffer &pbuf)
float get_estimated_promotion(sys::state &state, dcon::pop_id ids)
void apply_issues(sys::state &state, uint32_t offset, uint32_t divisions, issues_buffer &pbuf)
constexpr float inv_pop_u8_scaling
constexpr float pop_u16_scaling
void set_political_reform_desire(sys::state &state, dcon::pop_id p, float v)
void set_militancy(sys::state &state, dcon::pop_id p, float v)
float from_pmc(uint16_t v)
void set_social_reform_desire(sys::state &state, dcon::pop_id p, float v)
uint16_t to_pmc(float v)
uint32_t size(sys::state const &state)
float get_employment(sys::state const &state, dcon::pop_id p)
void set_employment(sys::state &state, dcon::pop_id p, float v)
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)
void set_raw_employment(sys::state &state, dcon::pop_id p, float v)
void set_luxury_needs(sys::state &state, dcon::pop_id p, float v)
void regenerate_is_primary_or_accepted(sys::state &state)
constexpr float inv_pop_mc_scaling
void set_demo(sys::state &state, dcon::pop_id p, dcon::pop_demographics_key k, float v)
uint16_t to_pu16(float v)
float from_pu8(uint8_t v)
void set_consciousness(sys::state &state, dcon::pop_id p, float v)
void set_everyday_needs(sys::state &state, dcon::pop_id p, float v)
dcon::pop_demographics_key to_key(sys::state const &state, dcon::ideology_id v)
float get_literacy(sys::state const &state, dcon::pop_id p)
float get_consciousness(sys::state const &state, dcon::pop_id p)
float get_militancy(sys::state const &state, dcon::pop_id p)
constexpr float inv_pop_u16_scaling
float get_raw_employment(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)
void set_literacy(sys::state &state, T p, ve::fp_vector v)
constexpr float pop_u8_scaling
constexpr float pop_mc_scaling
void set_life_needs(sys::state &state, dcon::pop_id p, float v)
float get_everyday_needs(sys::state const &state, dcon::pop_id p)
float from_pu16(uint16_t v)
constexpr uint32_t count_special_keys
Definition: demographics.hpp:7
float get_demo(sys::state const &state, dcon::pop_id p, dcon::pop_demographics_key k)
uint8_t to_pu8(float v)
int32_t to_int(int32_t a)
float to_float(int32_t a)
uint uint32_t
uchar uint8_t
ve::vectorizable_buffer< float, dcon::pop_id > amounts
tagged_vector< ve::vectorizable_buffer< uint8_t, dcon::pop_id >, dcon::ideology_id > temp_buffers
ideology_buffer(sys::state &state)
void update(sys::state &state, uint32_t s)
void update(sys::state &state, uint32_t s)
tagged_vector< ve::vectorizable_buffer< uint8_t, dcon::pop_id >, dcon::issue_option_id > temp_buffers
issues_buffer(sys::state &state)
ve::vectorizable_buffer< dcon::province_id, dcon::pop_id > destinations
ve::vectorizable_buffer< float, dcon::pop_id > amounts
ve::vectorizable_buffer< float, dcon::pop_id > amounts
ve::vectorizable_buffer< dcon::pop_type_id, dcon::pop_id > types