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);
73template<typename P, typename V>
74void set_life_needs(sys::state& state, P p, V v);
75float get_everyday_needs(sys::state const& state, dcon::pop_id p);
76template<typename P, typename V>
77void set_everyday_needs(sys::state& state, P p, V v);
78float get_luxury_needs(sys::state const& state, dcon::pop_id p);
79template<typename P, typename V>
80void set_luxury_needs(sys::state& state, P p, V v);
81float get_social_reform_desire(sys::state const& state, dcon::pop_id p);
82void set_social_reform_desire(sys::state& state, dcon::pop_id p, float v);
83float get_political_reform_desire(sys::state const& state, dcon::pop_id p);
84void set_political_reform_desire(sys::state& state, dcon::pop_id p, float v);
85
86template<typename T>
87auto get_employment(sys::state const& state, T p) {
88 auto ival = state.world.pop_get_uemployment(p);
89 return from_pu8(ival) * state.world.pop_get_size(p);
90}
91template<typename T>
92auto get_raw_employment(sys::state const& state, T p) {
93 auto ival = state.world.pop_get_uemployment(p);
94 return from_pu8(ival);
95}
96template<typename T>
97auto get_social_reform_desire(sys::state const& state, T p) {
98 auto ival = state.world.pop_get_usocial_reform_desire(p);
99 return from_pu8(ival);
100}
101template<typename T>
103 auto ival = state.world.pop_get_upolitical_reform_desire(p);
104 return from_pu8(ival);
105}
106template<typename T>
107auto get_militancy(sys::state const& state, T p) {
108 auto ival = state.world.pop_get_umilitancy(p);
109 return from_pmc(ival);
110}
111template<typename T>
112auto get_consciousness(sys::state const& state, T p) {
113 auto ival = state.world.pop_get_uconsciousness(p);
114 return from_pmc(ival);
115}
116template<typename T>
117auto get_literacy(sys::state const& state, T p) {
118 auto ival = state.world.pop_get_uliteracy(p);
119 return from_pu16(ival);
120}
121template<typename T>
122auto get_life_needs(sys::state const& state, T p) {
123 auto ival = state.world.pop_get_ulife_needs_satisfaction(p);
124 return from_pu8(ival);
125}
126template<typename T>
127auto get_everyday_needs(sys::state const& state, T p) {
128 auto ival = state.world.pop_get_ueveryday_needs_satisfaction(p);
129 return from_pu8(ival);
130}
131template<typename T>
132auto get_luxury_needs(sys::state const& state, T p) {
133 auto ival = state.world.pop_get_uluxury_needs_satisfaction(p);
134 return from_pu8(ival);
135}
136template<typename T>
137auto get_demo(sys::state const& state, T p, dcon::pop_demographics_key k) {
138 auto ival = state.world.pop_get_udemographics(p, k);
139 return from_pu8(ival);
140}
141
142} // namespace pop_demographics
143namespace demographics {
144
145constexpr inline dcon::demographics_key total(0);
146constexpr inline dcon::demographics_key employable(1);
147constexpr inline dcon::demographics_key employed(2);
148constexpr inline dcon::demographics_key consciousness(3);
149constexpr inline dcon::demographics_key militancy(4);
150constexpr inline dcon::demographics_key literacy(5);
151constexpr inline dcon::demographics_key political_reform_desire(6);
152constexpr inline dcon::demographics_key social_reform_desire(7);
153constexpr inline dcon::demographics_key poor_militancy(8);
154constexpr inline dcon::demographics_key middle_militancy(9);
155constexpr inline dcon::demographics_key rich_militancy(10);
156constexpr inline dcon::demographics_key poor_life_needs(11);
157constexpr inline dcon::demographics_key middle_life_needs(12);
158constexpr inline dcon::demographics_key rich_life_needs(13);
159constexpr inline dcon::demographics_key poor_everyday_needs(14);
160constexpr inline dcon::demographics_key middle_everyday_needs(15);
161constexpr inline dcon::demographics_key rich_everyday_needs(16);
162constexpr inline dcon::demographics_key poor_luxury_needs(17);
163constexpr inline dcon::demographics_key middle_luxury_needs(18);
164constexpr inline dcon::demographics_key rich_luxury_needs(19);
165constexpr inline dcon::demographics_key poor_total(20);
166constexpr inline dcon::demographics_key middle_total(21);
167constexpr inline dcon::demographics_key rich_total(22);
168
169constexpr inline uint32_t count_special_keys = 23;
170
171dcon::demographics_key to_key(sys::state const& state, dcon::ideology_id v);
172dcon::demographics_key to_key(sys::state const& state, dcon::issue_option_id v);
173dcon::demographics_key to_key(sys::state const& state, dcon::pop_type_id v);
174dcon::demographics_key to_key(sys::state const& state, dcon::culture_id v);
175dcon::demographics_key to_key(sys::state const& state, dcon::religion_id v);
176dcon::demographics_key to_employment_key(sys::state const& state, dcon::pop_type_id v);
177
178uint32_t size(sys::state const& state);
179
180void regenerate_jingoism_support(sys::state& state, dcon::nation_id n);
185
187
191
193 for(uint32_t i = 0; i < state.world.ideology_size(); ++i) {
195 }
196 }
197
198 void update(sys::state& state, uint32_t s) {
199 if(size < s) {
200 size = s;
201 state.world.for_each_ideology(
202 [&](dcon::ideology_id i) { temp_buffers[i] = ve::vectorizable_buffer<uint8_t, dcon::pop_id>(s); /*state.world.pop_make_vectorizable_float_buffer();*/ });
203 }
204 }
205};
206
210
212 for(uint32_t i = 0; i < state.world.issue_option_size(); ++i) {
214 }
215 }
216
217 void update(sys::state& state, uint32_t s) {
218 if(size < s) {
219 size = s;
220 state.world.for_each_issue_option(
221 [&](dcon::issue_option_id i) { temp_buffers[i] = ve::vectorizable_buffer<uint8_t, dcon::pop_id>(s); /*state.world.pop_make_vectorizable_float_buffer();*/ });
222 }
223 }
224};
225
227 ve::vectorizable_buffer<float, dcon::pop_id> amounts;
228 ve::vectorizable_buffer<dcon::pop_type_id, dcon::pop_id> types;
231
233 void update(uint32_t s) {
234 size = s;
235 if(reserved < s) {
236 reserved = s;
237 amounts = ve::vectorizable_buffer<float, dcon::pop_id>(s);
238 types = ve::vectorizable_buffer<dcon::pop_type_id, dcon::pop_id>(s);
239 }
240 }
241};
242
244 ve::vectorizable_buffer<float, dcon::pop_id> amounts;
247
249 void update(uint32_t s) {
250 size = s;
251 if(reserved < s) {
252 reserved = s;
253 amounts = ve::vectorizable_buffer<float, dcon::pop_id>(s);
254 }
255 }
256};
257
259 ve::vectorizable_buffer<float, dcon::pop_id> amounts;
260 ve::vectorizable_buffer<dcon::province_id, dcon::pop_id> destinations;
263
265 void update(uint32_t s) {
266 size = s;
267 if(reserved < s) {
268 reserved = s;
269 amounts = ve::vectorizable_buffer<float, dcon::pop_id>(s);
270 destinations = ve::vectorizable_buffer<dcon::province_id, dcon::pop_id>(s);
271 }
272 }
273};
274
275void update_literacy(sys::state& state, uint32_t offset, uint32_t divisions);
276void update_consciousness(sys::state& state, uint32_t offset, uint32_t divisions);
277void update_militancy(sys::state& state, uint32_t offset, uint32_t divisions);
278void update_ideologies(sys::state& state, uint32_t offset, uint32_t divisions, ideology_buffer& ibuf);
279void update_issues(sys::state& state, uint32_t offset, uint32_t divisions, issues_buffer& ibuf);
280void update_growth(sys::state& state, uint32_t offset, uint32_t divisions);
281void update_type_changes(sys::state& state, uint32_t offset, uint32_t divisions, promotion_buffer& pbuf);
282void update_assimilation(sys::state& state, uint32_t offset, uint32_t divisions, assimilation_buffer& pbuf);
283void update_internal_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
284void update_colonial_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
285void update_immigration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
286
287float get_estimated_literacy_change(sys::state& state, dcon::nation_id n);
288float get_estimated_mil_change(sys::state& state, dcon::nation_id n);
289float get_estimated_con_change(sys::state& state, dcon::nation_id n);
290float get_estimated_promotion(sys::state& state, dcon::nation_id n);
291
292void apply_ideologies(sys::state& state, uint32_t offset, uint32_t divisions, ideology_buffer& pbuf);
293void apply_issues(sys::state& state, uint32_t offset, uint32_t divisions, issues_buffer& pbuf);
294void apply_type_changes(sys::state& state, uint32_t offset, uint32_t divisions, promotion_buffer& pbuf);
295void apply_assimilation(sys::state& state, uint32_t offset, uint32_t divisions, assimilation_buffer& pbuf);
296void apply_internal_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
297void apply_colonial_migration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
298void apply_immigration(sys::state& state, uint32_t offset, uint32_t divisions, migration_buffer& pbuf);
299
301void remove_small_pops(sys::state& state);
302
303float get_monthly_pop_increase(sys::state& state, dcon::pop_id);
304int64_t get_monthly_pop_increase(sys::state& state, dcon::nation_id n);
305int64_t get_monthly_pop_increase(sys::state& state, dcon::state_instance_id n);
306int64_t get_monthly_pop_increase(sys::state& state, dcon::province_id n);
307
308float get_estimated_literacy_change(sys::state& state, dcon::pop_id n);
309float get_estimated_mil_change(sys::state& state, dcon::pop_id n);
310float get_estimated_con_change(sys::state& state, dcon::pop_id n);
311float get_estimated_type_change(sys::state& state, dcon::pop_id n);
312float get_effective_estimation_type_change(sys::state& state, dcon::nation_id nation, dcon::pop_type_id target_type);
313float get_estimated_promotion(sys::state& state, dcon::pop_id n);
314float get_estimated_demotion(sys::state& state, dcon::pop_id n);
315float get_estimated_assimilation(sys::state& state, dcon::pop_id n);
316float get_estimated_internal_migration(sys::state& state, dcon::pop_id n);
317float get_estimated_colonial_migration(sys::state& state, dcon::pop_id n);
318float get_estimated_emigration(sys::state& state, dcon::pop_id n);
319void estimate_directed_immigration(sys::state& state, dcon::nation_id n, std::vector<float>& national_amounts);
320
321float calculate_nation_sol(sys::state& state, dcon::nation_id nation_id);
322void reduce_pop_size_safe(sys::state& state, dcon::pop_id pop_id, int32_t amount);
323
324void modify_militancy(sys::state& state, dcon::nation_id n, float v);
325
326} // namespace demographics
tag_type emplace_back(T &&... ts)
void modify_militancy(sys::state &state, dcon::nation_id n, float v)
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
void set_luxury_needs(sys::state &state, P p, V v)
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_everyday_needs(sys::state &state, P p, V 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 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)
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)
void set_life_needs(sys::state &state, P p, V v)
constexpr float pop_u8_scaling
constexpr float pop_mc_scaling
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
Holds important data about the game world, state, and other data regarding windowing,...