Project Alice
Loading...
Searching...
No Matches
economy.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "container_types.hpp"
4#include "dcon_generated.hpp"
5
6namespace economy {
7
11 both
12};
13
16 int32_t naval_capacity = 1;
17 int32_t colonial_points[8] = { 30, 50, 70, 90, 110, 130, 150, 170 };
18 int32_t colonial_range = 50;
19 int32_t max_level = 6;
20 int32_t time = 1080;
21 float infrastructure = 0.16f;
22 dcon::text_key name;
23 dcon::modifier_id province_modifier;
24 uint16_t padding2 = 0;
25 bool defined = false;
26 uint8_t padding[3] = { 0 };
27};
28
29static_assert(sizeof(building_information) == 104);
30static_assert(sizeof(building_information::cost) == 40);
31static_assert(sizeof(building_information::colonial_points) == 32);
32static_assert(sizeof(building_information::province_modifier) == 2);
33static_assert(sizeof(building_information::name) == 4);
34static_assert(sizeof(building_information::cost)
41 == 92);
42static_assert(sizeof(building_information) ==
55
57 switch(v) {
59 return "railroad";
61 return "fort";
63 return "naval_base";
65 return "bank";
67 return "university";
68 default:
69 return "???";
70 }
71}
73 switch(v) {
75 return "railroad_level";
77 return "fort_level";
79 return "naval_base_level";
81 return "bank_level";
83 return "university_level";
84 default:
85 return "???";
86 }
87}
88
89float get_artisan_distribution_slow(sys::state& state, dcon::nation_id n, dcon::commodity_id c);
90
91// base subsistence
92inline constexpr float subsistence_factor = 15.0f;
93inline constexpr float subsistence_score_life = 30.0f;
94inline constexpr float subsistence_score_everyday = 50.0f;
95inline constexpr float subsistence_score_luxury = 80.0f;
97
100 float craftsmen_fraction = 0.8f;
101 dcon::modifier_id selector_modifier{};
102 dcon::modifier_id immigrator_modifier{};
103};
104static_assert(sizeof(global_economy_state) ==
109
111
112template<typename T>
113auto desired_needs_spending(sys::state const& state, T pop_indices) {
114 // TODO: gather pop types, extract cached needs sum, etc etc
115 return 0.0f;
116}
117
118constexpr inline dcon::commodity_id money(0);
119
120inline constexpr float production_scale_delta = 0.1f;
121inline constexpr float factory_closed_threshold = 0.0001f;
122inline constexpr uint32_t price_history_length = 256;
123inline constexpr uint32_t gdp_history_length = 128;
124inline constexpr float rgo_owners_cut = 0.05f;
125
126void presimulate(sys::state& state);
127
128float commodity_daily_production_amount(sys::state& state, dcon::commodity_id c);
129
130float rgo_effective_size(sys::state const& state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c);
131float rgo_total_effective_size(sys::state& state, dcon::nation_id n, dcon::province_id p);
132float rgo_total_employment(sys::state& state, dcon::nation_id n, dcon::province_id p);
133float rgo_full_production_quantity(sys::state const& state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c);
134float rgo_max_employment(sys::state & state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c);
135float rgo_total_max_employment(sys::state& state, dcon::nation_id n, dcon::province_id p);
136
137float subsistence_max_pseudoemployment(sys::state& state, dcon::nation_id n, dcon::province_id p);
138
139float factory_max_employment(sys::state const& state, dcon::factory_id f);
140
141bool has_factory(sys::state const& state, dcon::state_instance_id si);
142bool has_building(sys::state const& state, dcon::state_instance_id si, dcon::factory_type_id fac);
143bool is_bankrupt_debtor_to(sys::state& state, dcon::nation_id debt_holder, dcon::nation_id debtor);
144
145void populate_effective_prices(sys::state& state, dcon::nation_id n);
146float factory_min_input_available(sys::state& state, dcon::nation_id n, dcon::factory_type_fat_id fac_type);
147float factory_input_total_cost(sys::state& state, dcon::nation_id n, dcon::factory_type_fat_id fac_type);
148float factory_min_e_input_available(sys::state& state, dcon::nation_id n, dcon::factory_type_fat_id fac_type);
149float factory_e_input_total_cost(sys::state& state, dcon::nation_id n, dcon::factory_type_fat_id fac_type);
150float factory_input_multiplier(sys::state& state, dcon::factory_fat_id fac, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s);
151float factory_throughput_multiplier(sys::state& state, dcon::factory_type_fat_id fac_type, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s);
152float factory_output_multiplier(sys::state& state, dcon::factory_fat_id fac, dcon::nation_id n, dcon::province_id p);
153float factory_max_production_scale(sys::state& state, dcon::factory_fat_id fac, float mobilization_impact, bool occupied);
154float factory_desired_raw_profit(dcon::factory_fat_id fac, float spendings);
155float factory_total_employment(sys::state const& state, dcon::factory_id f);
156float factory_primary_employment(sys::state const& state, dcon::factory_id f);
157float factory_secondary_employment(sys::state const& state, dcon::factory_id f);
158int32_t factory_priority(sys::state const& state, dcon::factory_id f);
159void set_factory_priority(sys::state& state, dcon::factory_id f, int32_t priority);
160bool factory_is_profitable(sys::state const& state, dcon::factory_id f);
161
162bool nation_is_constructing_factories(sys::state& state, dcon::nation_id n);
163bool nation_has_closed_factories(sys::state& state, dcon::nation_id n);
164
165void initialize(sys::state& state);
167
168float pop_min_wage_factor(sys::state& state, dcon::nation_id n);
169float pop_farmer_min_wage(sys::state& state, dcon::nation_id n, float min_wage_factor);
170float pop_laborer_min_wage(sys::state& state, dcon::nation_id n, float min_wage_factor);
171float pop_factory_min_wage(sys::state& state, dcon::nation_id n, float min_wage_factor);
172
175 float slaves;
176 float total;
177};
178
179rgo_workers_breakdown rgo_relevant_population(sys::state& state, dcon::province_id p, dcon::nation_id n);
180
181float rgo_desired_worker_norm_profit(sys::state& state, dcon::province_id p, dcon::nation_id n, float min_wage, float total_relevant_population);
182float rgo_expected_worker_norm_profit(sys::state& state, dcon::province_id p, dcon::nation_id n, dcon::commodity_id c);
183
184float factory_type_output_cost(sys::state& state, dcon::nation_id n, dcon::factory_type_id factory_type);
185float factory_type_input_cost(sys::state& state, dcon::nation_id n, dcon::factory_type_id factory_type);
186float factory_type_build_cost(sys::state& state, dcon::nation_id n, dcon::factory_type_id factory_type);
187
190void daily_update(sys::state& state, bool initiate_building);
192
193float base_artisan_profit(sys::state& state, dcon::nation_id n, dcon::commodity_id c);
194float artisan_scale_limit(sys::state& state, dcon::nation_id n, dcon::commodity_id c);
195
196float stockpile_commodity_daily_increase(sys::state& state, dcon::commodity_id c, dcon::nation_id n);
197float global_market_commodity_daily_increase(sys::state& state, dcon::commodity_id c);
198float government_consumption(sys::state& state, dcon::nation_id n, dcon::commodity_id c);
199float nation_factory_consumption(sys::state& state, dcon::nation_id n, dcon::commodity_id c);
200float nation_pop_consumption(sys::state& state, dcon::nation_id n, dcon::commodity_id c);
201float nation_total_imports(sys::state& state, dcon::nation_id n);
202float pop_income(sys::state& state, dcon::pop_id p);
203
204float estimate_gold_income(sys::state& state, dcon::nation_id n);
205float estimate_tariff_income(sys::state& state, dcon::nation_id n);
206float estimate_social_spending(sys::state& state, dcon::nation_id n);
207float estimate_pop_payouts_by_income_type(sys::state& state, dcon::nation_id n, culture::income_type in);
208float estimate_tax_income_by_strata(sys::state& state, dcon::nation_id n, culture::pop_strata ps);
209float estimate_subsidy_spending(sys::state& state, dcon::nation_id n);
210float estimate_diplomatic_balance(sys::state& state, dcon::nation_id n);
211float estimate_domestic_investment(sys::state& state, dcon::nation_id n);
212
213float estimate_land_spending(sys::state& state, dcon::nation_id n);
214float estimate_naval_spending(sys::state& state, dcon::nation_id n);
215float estimate_construction_spending(sys::state& state, dcon::nation_id n);
216float estimate_war_subsidies_spending(sys::state& state, dcon::nation_id n);
217float estimate_reparations_spending(sys::state& state, dcon::nation_id n);
218float estimate_war_subsidies_income(sys::state& state, dcon::nation_id n);
219float estimate_reparations_income(sys::state& state, dcon::nation_id n);
220float estimate_overseas_penalty_spending(sys::state& state, dcon::nation_id n);
221float estimate_stockpile_filling_spending(sys::state& state, dcon::nation_id n);
222
223// NOTE: used to estimate how much you will pay if you were to subsidize a particular nation,
224// *not* how much you are paying at the moment
225float estimate_war_subsidies(sys::state& state, dcon::nation_id n);
226
227float estimate_daily_income(sys::state& state, dcon::nation_id n);
228
230 float progress = 0.0f; // in range [0,1)
232};
233
235construction_status factory_upgrade(sys::state& state, dcon::factory_id f);
236
238 float progress = 0.0f;
239 dcon::factory_type_id type;
240};
241
243 float progress = 0.0f;
244 dcon::factory_type_id type;
245};
246
247bool state_contains_constructed_factory(sys::state& state, dcon::state_instance_id si, dcon::factory_type_id ft);
248bool state_contains_factory(sys::state& state, dcon::state_instance_id s, dcon::factory_type_id ft);
249int32_t state_factory_count(sys::state& state, dcon::state_instance_id sid, dcon::nation_id n);
250float unit_construction_progress(sys::state& state, dcon::province_land_construction_id c);
251float unit_construction_progress(sys::state& state, dcon::province_naval_construction_id c);
252void try_add_factory_to_state(sys::state& state, dcon::state_instance_id s, dcon::factory_type_id t);
253void bound_budget_settings(sys::state& state, dcon::nation_id n);
254
259
260float gdp_adjusted(sys::state& state, dcon::nation_id n);
261
262void prune_factories(sys::state& state); // get rid of closed factories in full states
263void go_bankrupt(sys::state& state, dcon::nation_id n);
264dcon::modifier_id get_province_selector_modifier(sys::state& state);
265dcon::modifier_id get_province_immigrator_modifier(sys::state& state);
266
267bool can_take_loans(sys::state& state, dcon::nation_id n);
268float interest_payment(sys::state& state, dcon::nation_id n);
269float max_loan(sys::state& state, dcon::nation_id n);
270
272
273} // namespace economy
float estimate_reparations_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4655
bool state_contains_factory(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id ft)
Definition: economy.cpp:4892
void initialize(sys::state &state)
Definition: economy.cpp:593
float global_market_commodity_daily_increase(sys::state &state, dcon::commodity_id c)
Definition: economy.cpp:123
dcon::modifier_id get_province_immigrator_modifier(sys::state &state)
Definition: economy.cpp:5383
constexpr float subsistence_score_life
Definition: economy.hpp:93
float estimate_subsidy_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4641
void populate_effective_prices(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:2847
float government_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:4380
float estimate_social_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4576
construction_status province_building_construction(sys::state &state, dcon::province_id p, province_building_type t)
Definition: economy.cpp:4832
float rgo_total_effective_size(sys::state &state, dcon::nation_id n, dcon::province_id p)
Definition: economy.cpp:931
float nation_total_imports(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4527
float factory_type_input_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_id factory_type)
Definition: economy.cpp:4423
bool state_contains_constructed_factory(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id ft)
Definition: economy.cpp:4879
float estimate_tariff_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4572
float factory_desired_raw_profit(dcon::factory_fat_id fac, float spendings)
Definition: economy.cpp:1533
bool has_building(sys::state const &state, dcon::state_instance_id si, dcon::factory_type_id fac)
Definition: economy.cpp:384
float factory_max_employment(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1124
void update_factory_employment(sys::state &state)
Definition: economy.cpp:1143
bool is_bankrupt_debtor_to(sys::state &state, dcon::nation_id debt_holder, dcon::nation_id debtor)
Definition: economy.cpp:398
int32_t state_factory_count(sys::state &state, dcon::state_instance_id sid, dcon::nation_id n)
Definition: economy.cpp:4911
std::string_view province_building_type_get_name(economy::province_building_type v)
Definition: economy.hpp:56
float estimate_diplomatic_balance(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4700
void prune_factories(sys::state &state)
Definition: economy.cpp:5340
constexpr uint32_t gdp_history_length
Definition: economy.hpp:123
float estimate_pop_payouts_by_income_type(sys::state &state, dcon::nation_id n, culture::income_type in)
Definition: economy.cpp:4602
float estimate_domestic_investment(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4706
constexpr float subsistence_score_total
Definition: economy.hpp:96
int32_t previous_price_record_index(sys::state &state)
Definition: economy.cpp:85
rgo_workers_breakdown rgo_relevant_population(sys::state &state, dcon::province_id p, dcon::nation_id n)
Definition: economy.cpp:1727
float rgo_desired_worker_norm_profit(sys::state &state, dcon::province_id p, dcon::nation_id n, float min_wage, float total_relevant_population)
Definition: economy.cpp:1743
float factory_min_input_available(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
Definition: economy.cpp:1356
float estimate_overseas_penalty_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:2354
float nation_factory_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:4435
float base_artisan_profit(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:422
commodity_production_type get_commodity_production_type(sys::state &state, dcon::commodity_id c)
Definition: economy.cpp:5431
bool has_factory(sys::state const &state, dcon::state_instance_id si)
Definition: economy.cpp:128
float max_loan(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:73
float estimate_construction_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4740
float estimate_war_subsidies_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4645
construction_status factory_upgrade(sys::state &state, dcon::factory_id f)
Definition: economy.cpp:4850
float gdp_adjusted(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:103
void presimulate(sys::state &state)
Definition: economy.cpp:370
void update_rgo_employment(sys::state &state)
Definition: economy.cpp:1020
float estimate_land_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4720
float rgo_total_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
Definition: economy.cpp:943
commodity_production_type
Definition: economy.hpp:8
@ both
Definition: economy.hpp:11
@ derivative
Definition: economy.hpp:10
@ primary
Definition: economy.hpp:9
float estimate_daily_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:5228
constexpr uint32_t price_history_length
Definition: economy.hpp:122
float rgo_total_max_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
Definition: economy.cpp:955
void regenerate_unsaved_values(sys::state &state)
Definition: economy.cpp:4332
float artisan_scale_limit(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:440
constexpr dcon::commodity_id money(0)
bool can_take_loans(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:48
int32_t factory_priority(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1004
dcon::modifier_id get_province_selector_modifier(sys::state &state)
Definition: economy.cpp:5379
float unit_construction_progress(sys::state &state, dcon::province_land_construction_id c)
Definition: economy.cpp:4926
constexpr float factory_closed_threshold
Definition: economy.hpp:121
int32_t most_recent_price_record_index(sys::state &state)
Definition: economy.cpp:82
float factory_throughput_multiplier(sys::state &state, dcon::factory_type_fat_id fac_type, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s)
Definition: economy.cpp:1463
void try_add_factory_to_state(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id t)
Definition: economy.cpp:5237
bool nation_is_constructing_factories(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:404
float pop_income(sys::state &state, dcon::pop_id p)
Definition: economy.cpp:4539
float rgo_effective_size(sys::state const &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
Definition: economy.cpp:909
constexpr float subsistence_score_luxury
Definition: economy.hpp:95
float pop_factory_min_wage(sys::state &state, dcon::nation_id n, float min_wage_factor)
Definition: economy.cpp:2832
float estimate_war_subsidies_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4671
float factory_max_production_scale(sys::state &state, dcon::factory_fat_id fac, float mobilization_impact, bool occupied)
Definition: economy.cpp:1487
float commodity_daily_production_amount(sys::state &state, dcon::commodity_id c)
Definition: economy.cpp:114
float estimate_war_subsidies(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4827
std::string_view province_building_type_get_level_text(economy::province_building_type v)
Definition: economy.hpp:72
constexpr int32_t max_building_types
Definition: constants.hpp:579
float rgo_expected_worker_norm_profit(sys::state &state, dcon::province_id p, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:1793
constexpr float subsistence_factor
Definition: economy.hpp:92
constexpr float production_scale_delta
Definition: economy.hpp:120
bool factory_is_profitable(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1011
auto desired_needs_spending(sys::state const &state, T pop_indices)
Definition: economy.hpp:113
float estimate_reparations_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4683
int32_t most_recent_gdp_record_index(sys::state &state)
Definition: economy.cpp:89
float estimate_naval_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4730
float subsistence_max_pseudoemployment(sys::state &state, dcon::nation_id n, dcon::province_id p)
Definition: economy.cpp:939
void go_bankrupt(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:5387
void bound_budget_settings(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:5271
float factory_secondary_employment(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1132
float rgo_max_employment(sys::state &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
Definition: economy.cpp:951
float pop_min_wage_factor(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:2813
void resolve_constructions(sys::state &state)
Definition: economy.cpp:4990
float estimate_tax_income_by_strata(sys::state &state, dcon::nation_id n, culture::pop_strata ps)
Definition: economy.cpp:4629
float pop_farmer_min_wage(sys::state &state, dcon::nation_id n, float min_wage_factor)
Definition: economy.cpp:2818
float factory_total_employment(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1136
float estimate_stockpile_filling_spending(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:2339
constexpr float rgo_owners_cut
Definition: economy.hpp:124
float stockpile_commodity_daily_increase(sys::state &state, dcon::commodity_id c, dcon::nation_id n)
Definition: economy.cpp:118
float pop_laborer_min_wage(sys::state &state, dcon::nation_id n, float min_wage_factor)
Definition: economy.cpp:2825
float factory_input_multiplier(sys::state &state, dcon::factory_fat_id fac, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s)
Definition: economy.cpp:1436
float factory_input_total_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
Definition: economy.cpp:1377
float rgo_full_production_quantity(sys::state &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
Definition: economy.cpp:1342
province_building_type
Definition: constants.hpp:578
float interest_payment(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:62
float factory_e_input_total_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
Definition: economy.cpp:1408
void daily_update(sys::state &state, bool initiate_buildings)
Definition: economy.cpp:3070
float factory_type_output_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_id factory_type)
Definition: economy.cpp:4415
void set_factory_priority(sys::state &state, dcon::factory_id f, int32_t priority)
Definition: economy.cpp:1007
float factory_primary_employment(sys::state const &state, dcon::factory_id f)
Definition: economy.cpp:1128
worker_effect
Definition: economy.hpp:110
bool nation_has_closed_factories(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:408
float get_artisan_distribution_slow(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:546
float factory_output_multiplier(sys::state &state, dcon::factory_fat_id fac, dcon::nation_id n, dcon::province_id p)
Definition: economy.cpp:1470
float nation_pop_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:4514
float factory_min_e_input_available(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
Definition: economy.cpp:1390
float factory_type_build_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_id factory_type)
Definition: economy.cpp:4396
int32_t previous_gdp_record_index(sys::state &state)
Definition: economy.cpp:93
constexpr float subsistence_score_everyday
Definition: economy.hpp:94
float estimate_gold_income(sys::state &state, dcon::nation_id n)
Definition: economy.cpp:4558
uint uint32_t
uchar uint8_t
dcon::modifier_id province_modifier
Definition: economy.hpp:23
economy::commodity_set cost
Definition: economy.hpp:15
dcon::modifier_id selector_modifier
Definition: economy.hpp:101
building_information building_definitions[max_building_types]
Definition: economy.hpp:99
dcon::modifier_id immigrator_modifier
Definition: economy.hpp:102
dcon::factory_type_id type
Definition: economy.hpp:239
dcon::factory_type_id type
Definition: economy.hpp:244