4#include "dcon_generated.hpp"
20 state.world.nation_get_real_demand(n, commodity_type) += amount;
21 state.world.commodity_get_demand_by_category(commodity_type, (
int)reason) += amount;
22 assert(std::isfinite(state.world.nation_get_real_demand(n, commodity_type)));
27 state.world.nation_get_intermediate_demand(n, commodity_type) += amount;
29 float price = state.world.commodity_get_current_price(commodity_type);
30 float sat = state.world.nation_get_demand_satisfaction(n, commodity_type);
32 state.world.nation_get_gdp(n) -= amount * price * sat;
37 state.world.nation_get_construction_demand(n, commodity_type) += amount;
41 state.world.nation_get_domestic_market_pool(n, commodity_type) += amount;
42 state.world.nation_get_gdp(n) += amount * state.world.commodity_get_current_price(commodity_type);
49 if(!state.world.nation_get_is_player_controlled(n) || !state.world.nation_get_is_debt_spending(n))
55 auto last_br = state.world.nation_get_bankrupt_until(n);
56 if(last_br && state.current_date < last_br)
67 auto debt = state.world.nation_get_stockpiles(n,
money);
71 return -debt * std::max(0.01f, (state.world.nation_get_modifier_values(n, sys::national_mod_offsets::loan_interest) + 1.0f) * state.defines.loan_base_interest) / 30.0f;
77 auto mod = (state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_loan_modifier) + 1.0f);
78 auto total_tax_base = state.world.nation_get_total_rich_income(n) + state.world.nation_get_total_middle_income(n) + state.world.nation_get_total_poor_income(n);
79 return std::max(0.0f, total_tax_base * mod);
90 auto date = state.current_date.to_ymd(state.start_date);
94 auto date = state.current_date.to_ymd(state.start_date);
99 return state.world.nation_get_life_needs_costs(n, state.culture_definitions.primary_factory_worker)
100 + 0.1f * state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.primary_factory_worker);
104 float raw = state.world.nation_get_gdp(n);
106 return raw / ideal_pound;
115 return state.world.commodity_get_total_production(c);
129 auto sdef = state.world.state_instance_get_definition(si);
130 auto owner = state.world.state_instance_get_nation_from_state_ownership(si);
131 auto crng = state.world.state_instance_get_state_building_construction(si);
132 if(crng.begin() != crng.end())
135 for(
auto p : state.world.state_definition_get_abstract_state_membership(sdef)) {
136 if(p.get_province().get_nation_from_province_ownership() == owner) {
137 auto rng = p.get_province().get_factory_location();
138 if(
rng.begin() !=
rng.end())
148 state.world.nation_resize_artisan_distribution(state.world.commodity_size());
149 state.world.nation_resize_artisan_actual_production(state.world.commodity_size());
151 auto const csize = state.world.commodity_size();
153 for(
auto n : state.world.in_nation) {
154 for(
uint32_t i = 1; i < csize; ++i) {
155 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
156 auto kf = state.world.commodity_get_key_factory(cid);
158 if(state.world.commodity_get_artisan_output_amount(cid) > 0.0f && (state.world.commodity_get_is_available_from_start(cid) || (kf && state.world.nation_get_active_building(n, kf)))) {
160 n.set_artisan_distribution(cid, 0.f);
168 state.world.for_each_commodity([&](dcon::commodity_id c) {
169 auto kf = state.world.commodity_get_key_factory(c);
170 if(state.world.commodity_get_is_life_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
171 auto& w = state.world.nation_get_life_needs_weights(n, c);
177 state.world.for_each_commodity([&](dcon::commodity_id c) {
178 auto kf = state.world.commodity_get_key_factory(c);
179 if(state.world.commodity_get_is_everyday_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
180 auto& w = state.world.nation_get_everyday_needs_weights(n, c);
186 state.world.for_each_commodity([&](dcon::commodity_id c) {
187 auto kf = state.world.commodity_get_key_factory(c);
188 if(state.world.commodity_get_is_luxury_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
189 auto& w = state.world.nation_get_luxury_needs_weights(n, c);
197 return 1.0f /
math::sqrt(std::max(state.world.commodity_get_current_price(c), 0.001f));
202 float total_weights = 0.0f;
205 state.world.for_each_commodity([&](dcon::commodity_id c) {
206 auto kf = state.world.commodity_get_key_factory(c);
207 if(state.world.commodity_get_is_life_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
208 auto weight = need_weight(state, n, c);
209 total_weights += weight;
214 state.world.for_each_commodity([&](dcon::commodity_id c) {
215 auto kf = state.world.commodity_get_key_factory(c);
216 if(state.world.commodity_get_is_life_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
217 auto weight = need_weight(state, n, c);
218 auto ideal_weighting = weight / total_weights * count;
219 auto& w = state.world.nation_get_life_needs_weights(n, c);
220 w = ideal_weighting * state.defines.alice_need_drift_speed + w * (1.0f - state.defines.alice_need_drift_speed);
222 assert(std::isfinite(w));
223 assert(w <= count + 0.01f);
229 float total_weights = 0.0f;
232 state.world.for_each_commodity([&](dcon::commodity_id c) {
233 auto kf = state.world.commodity_get_key_factory(c);
234 if(state.world.commodity_get_is_everyday_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
235 auto weight = need_weight(state, n, c);
236 total_weights += weight;
241 state.world.for_each_commodity([&](dcon::commodity_id c) {
242 auto kf = state.world.commodity_get_key_factory(c);
243 if(state.world.commodity_get_is_everyday_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
244 auto weight = need_weight(state, n, c);
245 auto ideal_weighting = weight / total_weights * count;
246 auto& w = state.world.nation_get_everyday_needs_weights(n, c);
247 w = ideal_weighting * state.defines.alice_need_drift_speed + w * (1.0f - state.defines.alice_need_drift_speed);
249 assert(std::isfinite(w));
250 assert(w <= count + 0.01f);
256 float total_weights = 0.0f;
259 state.world.for_each_commodity([&](dcon::commodity_id c) {
260 auto kf = state.world.commodity_get_key_factory(c);
261 if(state.world.commodity_get_is_luxury_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
262 auto weight = need_weight(state, n, c);
263 total_weights += weight;
268 state.world.for_each_commodity([&](dcon::commodity_id c) {
269 auto kf = state.world.commodity_get_key_factory(c);
270 if(state.world.commodity_get_is_luxury_need(c) && (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
271 auto weight = need_weight(state, n, c);
272 auto ideal_weighting = weight / total_weights * count;
273 auto& w = state.world.nation_get_luxury_needs_weights(n, c);
274 w = ideal_weighting * state.defines.alice_need_drift_speed + w * (1.0f - state.defines.alice_need_drift_speed);
276 assert(std::isfinite(w));
277 assert(w <= count + 0.01f);
286 std::vector<float>& buffer_commodities,
287 std::vector<float>& buffer_ingredients,
288 std::vector<float>& buffer_weights
290 state.world.for_each_commodity([&](dcon::commodity_id c) {
291 float amount = buffer_commodities[c.index()];
293 if(state.world.commodity_get_rgo_amount(c) > 0.f) {
294 buffer_ingredients[c.index()] += amount;
297 std::vector<float> weights;
298 float total_weight = 0.f;
299 float non_zero_count = 0.f;
301 state.world.for_each_factory_type([&](dcon::factory_type_id t) {
302 auto o = state.world.factory_type_get_output(t);
304 auto& inputs = state.world.factory_type_get_inputs(t);
306 float weight_current = 0;
308 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
309 if(inputs.commodity_type[i]) {
310 float weight_input = buffer_weights[inputs.commodity_type[i].index()];
311 total_weight += weight_input;
312 weight_current += weight_input;
318 if(weight_current > 0.f)
321 weights.push_back(weight_current);
325 if(total_weight == 0) {
326 for(
size_t i = 0; i < weights.size(); i++) {
331 float average_weight = total_weight / non_zero_count;
332 for(
size_t i = 0; i < weights.size(); i++) {
333 if(weights[i] == 0.f) {
334 weights[i] = average_weight;
335 total_weight += average_weight;
343 state.world.for_each_factory_type([&](dcon::factory_type_id t) {
344 auto o = state.world.factory_type_get_output(t);
346 auto& inputs = state.world.factory_type_get_inputs(t);
347 float output_power = state.world.factory_type_get_output_amount(t);
349 float weight_current = weights[index] / total_weight;
353 if(inputs.commodity_type[i]) {
355 buffer_ingredients[inputs.commodity_type[i].index()] += inputs.commodity_amounts[i] * amount / output_power * weight_current;
357 float weight_input = buffer_weights[inputs.commodity_type[i].index()];
358 total_weight += weight_input;
359 weight_current += weight_input;
385 auto sdef = state.world.state_instance_get_definition(si);
386 auto owner = state.world.state_instance_get_nation_from_state_ownership(si);
387 for(
auto p : state.world.state_definition_get_abstract_state_membership(sdef)) {
388 if(p.get_province().get_nation_from_province_ownership() == owner) {
389 for(
auto b : p.get_province().get_factory_location()) {
390 if(b.get_factory().get_building_type() == fac)
399 return state.world.nation_get_is_bankrupt(debt_holder) &&
400 state.world.unilateral_relationship_get_owns_debt_of(
401 state.world.get_unilateral_relationship_by_unilateral_pair(debtor, debt_holder)) > 0.1f;
405 auto rng = state.world.nation_get_state_building_construction(n);
406 return rng.begin() !=
rng.end();
410 for(
auto prov_owner : nation_fat.get_province_ownership()) {
411 auto prov = prov_owner.get_province();
412 for(
auto factloc : prov.get_factory_location()) {
413 auto scale = factloc.get_factory().get_production_scale();
423 auto const& inputs = state.world.commodity_get_artisan_inputs(c);
424 float input_total = 0.0f;
425 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
426 if(inputs.commodity_type[i]) {
427 input_total += inputs.commodity_amounts[i] * state.world.commodity_get_current_price(inputs.commodity_type[i]);
433 float output_total = state.world.commodity_get_artisan_output_amount(c) * state.world.commodity_get_current_price(c);
435 float input_multiplier = std::max(0.1f, state.defines.alice_inputs_base_factor_artisans + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::artisan_input));
436 float output_multiplier = std::max(0.1f, state.defines.alice_output_base_factor_artisans + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::artisan_output));
438 return output_total * output_multiplier - input_multiplier * input_total;
442 auto const& inputs = state.world.commodity_get_artisan_inputs(c);
443 float input_total = 0.0f;
444 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
445 if(inputs.commodity_type[i]) {
446 least = std::min(least, state.world.nation_get_demand_satisfaction(n, inputs.commodity_type[i]));
455 auto kf = state.world.commodity_get_key_factory(cid);
457 state.world.commodity_get_artisan_output_amount(cid) > 0.0f
459 state.world.commodity_get_is_available_from_start(cid)
461 kf && state.world.nation_get_active_building(n, kf)
467inline constexpr float ln_2 = 0.30103f;
476 f = 1 + f + f * f / 2 + f * f * f / 6;
490 float multiplier = 0.000001f * state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.artisans);
491 return 1.f / (multiplier + 1.f);
497 auto const csize = state.world.commodity_size();
500 float max_score = std::numeric_limits<float>::lowest();
502 for(
uint32_t i = 1; i < csize; ++i) {
503 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
504 float score = state.world.nation_get_artisan_distribution(n, cid);
505 if(score > max_score) {
509 if(baseline > max_score) {
510 max_score = baseline;
517 auto const csize = state.world.commodity_size();
523 for(
uint32_t i = 1; i < csize; ++i) {
524 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
525 float score = state.world.nation_get_artisan_distribution(n, cid);
537 dcon::commodity_id c,
542 float score = state.world.nation_get_artisan_distribution(n, c);
547 auto const csize = state.world.commodity_size();
557 auto const csize = state.world.commodity_size();
558 float distribution_drift_speed = 0.0001f;
560 std::vector<float> current_distribution;
561 std::vector<float> profits;
562 profits.resize(csize + 1);
566 for(
uint32_t i = 1; i < csize; ++i) {
567 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
573 profits[cid.index()] = profit;
575 profits[cid.index()] = -256.f / mult / distribution_drift_speed * 10.f;
583 for(
uint32_t i = 1; i < csize; ++i) {
584 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
585 auto& w = state.world.nation_get_artisan_distribution(n, cid);
587 auto output = state.world.commodity_get_artisan_output_amount(cid);
588 auto next_score = w * 0.8f + distribution_drift_speed * profits[cid.index()] * (1 - last_distribution) /
output;
596 state.world.for_each_commodity([&](dcon::commodity_id c) {
597 auto fc = fatten(state.world, c);
598 fc.set_current_price(fc.get_cost());
599 fc.set_total_consumption(0.0f);
600 fc.set_total_production(0.0f);
601 fc.set_total_real_demand(0.0f);
603 for(
int i = 0; i < 8; i++) {
604 fc.set_demand_by_category(i, 0.f);
608 fc.set_price_record(i, fc.get_cost());
613 auto savings_buffer = state.world.pop_type_make_vectorizable_float_buffer();
614 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
615 auto ft = fatten(state.world, t);
616 state.world.for_each_commodity([&](dcon::commodity_id c) {
617 savings_buffer.get(t) += state.world.commodity_get_is_available_from_start(c)
618 ? state.world.commodity_get_cost(c) * ft.get_life_needs(c) + 0.5f * state.world.commodity_get_cost(c) * ft.get_everyday_needs(c)
621 auto strata = (ft.get_strata() * 2) + 1;
622 savings_buffer.get(t) *= strata;
625 state.world.for_each_pop([&](dcon::pop_id p) {
626 auto fp = fatten(state.world, p);
630 fp.set_savings(savings_buffer.get(fp.get_poptype()) * fp.get_size() / state.defines.alice_needs_scaling_factor);
633 state.world.for_each_factory([&](dcon::factory_id f) {
634 auto ff = fatten(state.world, f);
635 ff.set_production_scale(1.0f);
639 auto csize = state.world.commodity_size();
640 std::vector<std::vector<float>> per_climate_distribution_buffer(state.world.modifier_size() + 1, std::vector<float>(csize + 1, 0.f));
641 std::vector<std::vector<float>> per_terrain_distribution_buffer(state.world.modifier_size() + 1, std::vector<float>(csize + 1, 0.f));
642 std::vector<std::vector<float>> per_continent_distribution_buffer(state.world.modifier_size() + 1, std::vector<float>(csize + 1, 0.f));
646 auto fp = fatten(state.world, p);
647 dcon::commodity_id main_trade_good = state.world.province_get_rgo(p);
648 if(state.world.commodity_get_money_rgo(main_trade_good)) {
651 dcon::modifier_id climate = fp.get_climate();
652 dcon::modifier_id terrain = fp.get_terrain();
653 dcon::modifier_id continent = fp.get_continent();
654 per_climate_distribution_buffer[climate.value][main_trade_good.value] += 1.f;
655 per_terrain_distribution_buffer[terrain.value][main_trade_good.value] += 1.f;
656 per_continent_distribution_buffer[continent.value][main_trade_good.value] += 1.f;
661 float climate_sum = 0.f;
662 float terrain_sum = 0.f;
663 float continent_sum = 0.f;
664 for(
uint32_t j = 0; j < csize; j++) {
665 climate_sum += per_climate_distribution_buffer[i][j];
666 terrain_sum += per_terrain_distribution_buffer[i][j];
667 continent_sum += per_continent_distribution_buffer[i][j];
669 for(
uint32_t j = 0; j < csize; j++) {
670 per_climate_distribution_buffer[i][j] *= climate_sum == 0.f ? 1.f : 1.f / climate_sum;
671 per_terrain_distribution_buffer[i][j] *= terrain_sum == 0.f ? 1.f : 1.f / terrain_sum;
672 per_continent_distribution_buffer[i][j] *= continent_sum == 0.f ? 1.f : 1.f / continent_sum;
677 if(state.world.province_get_rgo_was_set_during_scenario_creation(p)) {
681 auto fp = fatten(state.world, p);
682 dcon::modifier_id climate = fp.get_climate();
683 dcon::modifier_id terrain = fp.get_terrain();
684 dcon::modifier_id continent = fp.get_continent();
686 dcon::commodity_id main_trade_good = state.world.province_get_rgo(p);
687 bool is_mine = state.world.commodity_get_is_mine(main_trade_good);
690 auto max_rgo_size = std::ceil(2000.f / state.defines.alice_rgo_per_size_employment
693 state.world.for_each_commodity([&](dcon::commodity_id c) {
694 fp.set_rgo_employment_per_good(c, 0.f);
695 fp.set_rgo_target_employment_per_good(c, 0.f);
699 float pop_amount = 0.0f;
700 for(
auto pt : state.world.in_pop_type) {
701 if(pt == state.culture_definitions.slaves) {
702 pop_amount += state.world.province_get_demographics(p, demographics::to_key(state, state.culture_definitions.slaves));
703 }
else if(pt.get_is_paid_rgo_worker()) {
704 pop_amount += state.world.province_get_demographics(p, demographics::to_key(state, pt));
708 auto size_at_the_start_of_the_game = std::ceil(pop_amount / state.defines.alice_rgo_per_size_employment);
709 auto real_size = std::min(size_at_the_start_of_the_game * 1.5f, max_rgo_size);
711 assert(std::isfinite(real_size));
712 fp.set_rgo_size(real_size);
714 static std::vector<float> true_distribution;
715 true_distribution.resize(state.world.commodity_size());
718 state.world.for_each_commodity([&](dcon::commodity_id c) {
719 float climate_d = per_climate_distribution_buffer[climate.value][c.value];
720 float terrain_d = per_terrain_distribution_buffer[terrain.value][c.value];
721 float continent_d = per_continent_distribution_buffer[continent.value][c.value];
722 float current = (climate_d + terrain_d) * (climate_d + terrain_d) * continent_d;
723 true_distribution[c.index()] = current;
729 state.world.for_each_commodity([&](dcon::commodity_id c) {
730 float climate_d = per_climate_distribution_buffer[climate.value][c.value];
731 float terrain_d = per_terrain_distribution_buffer[terrain.value][c.value];
732 float current = (climate_d + terrain_d) * (climate_d + terrain_d);
733 true_distribution[c.index()] = current;
740 state.world.for_each_commodity([&](dcon::commodity_id c) {
741 if(state.world.commodity_get_money_rgo(c)) {
744 if(!state.world.commodity_get_is_available_from_start(c)) {
748 true_distribution[c.index()] = current;
753 state.world.for_each_commodity([&](dcon::commodity_id c) {
754 assert(std::isfinite(total));
757 true_distribution[c.index()] = 0.f;
759 true_distribution[c.index()] /= total;
764 state.world.for_each_commodity([&](dcon::commodity_id c) {
765 auto fc = fatten(state.world, c);
766 assert(std::isfinite(true_distribution[c.index()]));
767 state.world.province_get_rgo_max_size_per_good(fp, c) += real_size * true_distribution[c.index()];
771 state.world.for_each_nation([&](dcon::nation_id n) {
772 initialize_needs_weights(state, n);
774 auto fn = fatten(state.world, n);
775 fn.set_administrative_spending(int8_t(80));
776 fn.set_military_spending(int8_t(60));
777 fn.set_education_spending(int8_t(100));
778 fn.set_social_spending(int8_t(100));
779 fn.set_land_spending(int8_t(100));
780 fn.set_naval_spending(int8_t(100));
781 fn.set_construction_spending(int8_t(100));
782 fn.set_overseas_spending(int8_t(100));
784 fn.set_poor_tax(int8_t(75));
785 fn.set_middle_tax(int8_t(75));
786 fn.set_rich_tax(int8_t(75));
788 fn.set_spending_level(1.0f);
790 state.world.for_each_commodity([&](dcon::commodity_id c) {
791 state.world.nation_set_demand_satisfaction(n, c, 1.0f);
792 state.world.nation_set_direct_demand_satisfaction(n, c, 0.0f);
805 state.world.for_each_nation([&](dcon::nation_id n) {
819 if(state.world.nation_get_is_civilized(sphere_member)) {
820 float base = state.world.nation_get_rank(sphere_member) <= state.defines.colonial_rank
821 ? state.defines.second_rank_base_share_factor
822 : state.defines.civ_base_share_factor;
823 auto const ul = state.world.get_unilateral_relationship_by_unilateral_pair(sphere_member, sphere_leader);
824 float sl_investment = state.world.unilateral_relationship_get_foreign_investment(ul);
826 float investment_fraction = total_investment > 0.0001f ? sl_investment / total_investment : 0.0f;
827 return base + (1.0f - base) * investment_fraction;
829 return state.defines.unciv_base_share_factor;
834 for(
auto gp : state.world.nation_get_gp_relationship_as_great_power(n)) {
839 auto t = gp.get_influence_target();
841 state.world.for_each_commodity([&](dcon::commodity_id c) {
842 state.world.nation_get_domestic_market_pool(n, c) += share * state.world.nation_get_domestic_market_pool(t, c);
849 if(
auto sl = state.world.nation_get_in_sphere_of(n); sl) {
855 state.world.for_each_commodity(
856 [&](dcon::commodity_id c) { state.world.nation_get_domestic_market_pool(n, c) *= (1.0f - share); });
862 auto r = tariff_efficiency * float(state.world.nation_get_tariffs(n)) / 100.0f;
863 return std::max(r, 0.0f);
867 auto central_ports = state.world.nation_get_central_ports(n);
868 if(central_ports > 0) {
870 + float(state.world.nation_get_central_blockaded(n)) / float(central_ports)
878 state.world.for_each_factory([&](dcon::factory_id f) {
879 auto fac_type = fatten(state.world, state.world.factory_get_building_type(f));
881 auto prov = state.world.factory_get_province_from_factory_location(f);
882 auto pstate = state.world.province_get_state_membership(prov);
883 auto powner = state.world.province_get_nation_from_province_ownership(prov);
885 if(powner && pstate) {
886 if(
auto mod_a = fac_type.get_bonus_1_trigger();
888 sum -= fac_type.get_bonus_1_amount();
890 if(
auto mod_b = fac_type.get_bonus_2_trigger();
892 sum -= fac_type.get_bonus_2_amount();
894 if(
auto mod_c = fac_type.get_bonus_3_trigger();
896 sum -= fac_type.get_bonus_3_amount();
900 state.world.factory_set_triggered_modifiers(f, sum);
905 auto rgo_ownership = state.world.province_get_landowners_share(p) + state.world.province_get_capitalists_share(p);
906 return state.world.province_get_rgo_size(p) * (1.f - rgo_ownership) * 2.0f;
910 bool is_mine = state.world.commodity_get_is_mine(c);
913 auto rgo = state.world.province_get_rgo(p);
916 base = state.defines.alice_base_rgo_employment_bonus / state.defines.alice_rgo_per_size_employment;
921 auto rgo_ownership = state.world.province_get_landowners_share(p) + state.world.province_get_capitalists_share(p);
922 auto sz = state.world.province_get_rgo_max_size_per_good(p, c) * rgo_ownership + base;
923 auto pmod = state.world.province_get_modifier_values(p, is_mine ? sys::provincial_mod_offsets::mine_rgo_size : sys::provincial_mod_offsets::farm_rgo_size);
924 auto nmod = state.world.nation_get_modifier_values(n, is_mine ? sys::national_mod_offsets::mine_rgo_size : sys::national_mod_offsets::farm_rgo_size);
925 auto specific_pmod = state.world.nation_get_rgo_size(n, c);
926 auto bonus = pmod + nmod + specific_pmod + 1.0f;
928 return std::max(sz * bonus, 0.00f);
933 state.world.for_each_commodity([&](dcon::commodity_id c) {
940 return state.defines.alice_rgo_per_size_employment *
subsistence_size(state, p) * 1.1f;
945 state.world.for_each_commodity([&](dcon::commodity_id c) {
946 total += state.world.province_get_rgo_employment_per_good(p, c);
952 return state.defines.alice_rgo_per_size_employment *
rgo_effective_size(state, n, p, c);
957 state.world.for_each_commodity([&](dcon::commodity_id c) {
964 state.world.execute_parallel_over_province([&](
auto ids) {
965 auto max_subsistence = ve::apply([&](dcon::province_id p) {
969 auto employment = state.world.province_get_subsistence_employment(ids);
970 auto saturation = employment / (4.f + max_subsistence);
971 auto saturation_score = 1.f / (saturation + 1.f);
973 auto quality = (
ve::to_float(state.world.province_get_life_rating(ids)) - 10.f) / 10.f;
974 quality = ve::max(quality, 0.f) + 0.01f;
976 score = (score * saturation_score);
977 state.world.province_set_subsistence_score(ids, score);
982 return state.world.province_get_subsistence_score(p)
983 * state.world.province_get_subsistence_employment(p)
988 state.world.execute_parallel_over_province([&](
auto ids) {
989 auto local_states = state.world.province_get_state_membership(ids);
990 auto weight_aristocracy =
991 state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.aristocrat)) * 200.f
992 + state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.slaves));
993 auto weight_capitalists =
994 state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.capitalists)) * 200.f;
995 auto weight_population =
996 state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.farmers))
997 + state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.laborers));
998 auto total = weight_aristocracy + weight_capitalists + weight_population + 1.0f;
999 state.world.province_set_landowners_share(ids, weight_aristocracy / total);
1000 state.world.province_set_capitalists_share(ids, weight_capitalists / total);
1004int32_t factory_priority(
sys::state const& state, dcon::factory_id f) {
1005 return (state.world.factory_get_priority_low(f) ? 1 : 0) + (state.world.factory_get_priority_high(f) ? 2 : 0);
1008 state.world.factory_set_priority_high(f, priority >= 2);
1009 state.world.factory_set_priority_low(f, (priority & 1) != 0);
1012 return state.world.factory_get_unprofitable(f) ==
false || state.world.factory_get_subsidized(f);
1016 float profit = 0.0f;
1017 dcon::commodity_id
c;
1021 int32_t
last = state.province_definitions.first_sea_province.index();
1023 concurrency::parallel_for(0,
last, [&](int32_t for_index) {
1025 dcon::province_id p{ dcon::province_id::value_base_t(for_index) };
1027 auto owner = state.world.province_get_nation_from_province_ownership(p);
1028 auto current_employment = 0.f;
1029 state.world.for_each_commodity([&](dcon::commodity_id c) {
1030 current_employment += state.world.province_get_rgo_employment_per_good(p, c);
1032 current_employment += state.world.province_get_subsistence_employment(p);
1034 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
1035 float worker_pool = 0.0f;
1036 for(
auto wt : state.culture_definitions.rgo_workers) {
1039 float slave_pool = state.world.province_get_demographics(p,
demographics::to_key(state, state.culture_definitions.slaves));
1040 float labor_pool = worker_pool + slave_pool;
1044 labor_pool = std::min(labor_pool, total_population);
1052 assert(state.world.commodity_size() <= 126);
1057 state.world.for_each_commodity([&](dcon::commodity_id c) {
1059 ordered_list[used_indices].
c = c;
1063 state.world.province_set_rgo_employment_per_good(p, c, 0.f);
1072 float speed = 0.20f;
1074 float total_workforce = labor_pool;
1075 float max_employment_total = 0.f;
1076 float total_employed = 0.f;
1078 for(
uint32_t i = 0; i < used_indices; ++i) {
1079 auto c = ordered_list[i].
c;
1081 max_employment_total += max_employment;
1082 float target_workforce = std::min(state.world.province_get_rgo_target_employment_per_good(p, c), total_workforce);
1084 float current_workforce = state.world.province_get_rgo_employment_per_good(p, c);
1085 float new_employment = std::min(current_workforce * (1 - speed) + target_workforce * speed, total_workforce);
1086 total_workforce -= new_employment;
1088 new_employment = std::clamp(new_employment, 0.f, max_employment);
1089 total_employed += new_employment;
1091 state.world.province_set_rgo_employment_per_good(p, c, new_employment);
1095 total_workforce -= subsistence;
1096 total_employed += subsistence;
1098 state.world.province_set_subsistence_employment(p, subsistence);
1100 assert(total_employed <= total_population + 1.f);
1102 float employment_ratio = 0.f;
1103 if(max_employment_total > 1.f) {
1104 employment_ratio = total_employed / (max_employment_total + 1.f);
1106 employment_ratio = 1.f;
1108 state.world.province_set_rgo_employment(p, employment_ratio);
1110 auto slave_fraction = (slave_pool > current_employment) ? current_employment / slave_pool : 1.0f;
1111 auto free_fraction = std::max(0.0f, (worker_pool > current_employment - slave_pool) ? (current_employment - slave_pool) / std::max(worker_pool, 0.01f) : 1.0f);
1113 for(
auto pop : state.world.province_get_pop_location(p)) {
1114 auto pt =
pop.get_pop().get_poptype();
1115 if(pt == state.culture_definitions.slaves) {
1117 }
else if(pt.get_is_paid_rgo_worker()) {
1125 return state.defines.alice_factory_per_level_employment * state.world.factory_get_level(f);
1129 auto primary_employment = state.world.factory_get_primary_employment(f);
1130 return factory_max_employment(state, f) * (state.economy_definitions.craftsmen_fraction * primary_employment);
1133 auto secondary_employment = state.world.factory_get_secondary_employment(f);
1134 return factory_max_employment(state, f) * ((1 - state.economy_definitions.craftsmen_fraction) * secondary_employment);
1138 auto primary_employment = state.world.factory_get_primary_employment(f);
1139 auto secondary_employment = state.world.factory_get_secondary_employment(f);
1140 return factory_max_employment(state, f) * (state.economy_definitions.craftsmen_fraction * primary_employment + (1 -state.economy_definitions.craftsmen_fraction) * secondary_employment);
1144 state.world.for_each_state_instance([&](dcon::state_instance_id si) {
1145 float primary_pool = state.world.state_instance_get_demographics(si,
1147 float secondary_pool = state.world.state_instance_get_demographics(si,
1150 static std::vector<dcon::factory_id> ordered_factories;
1151 ordered_factories.clear();
1154 for(auto fac : state.world.province_get_factory_location(p)) {
1155 ordered_factories.push_back(fac.get_factory());
1159 std::sort(ordered_factories.begin(), ordered_factories.end(), [&](dcon::factory_id a, dcon::factory_id b) {
1160 if(factory_is_profitable(state, a) != factory_is_profitable(state, b)) {
1161 return factory_is_profitable(state, a);
1163 if(factory_priority(state, a) != factory_priority(state, b)) {
1164 return factory_priority(state, a) > factory_priority(state, b);
1166 return a.index() < b.index();
1169 float employment_shift_speed = 0.001f;
1171 float primary_pool_copy = primary_pool;
1172 float secondary_pool_copy = secondary_pool;
1173 for(
uint32_t index = 0; index < ordered_factories.size();) {
1176 float total_workforce = 0.0f;
1177 for(; next_index < ordered_factories.size(); ++next_index) {
1179 factory_is_profitable(state, ordered_factories[index])
1181 factory_is_profitable(state, ordered_factories[next_index])
1183 factory_priority(state, ordered_factories[index])
1185 factory_priority(state, ordered_factories[next_index])
1190 state.world.factory_get_production_scale(ordered_factories[next_index]);
1194 float type_share =
state.economy_definitions.craftsmen_fraction * total_workforce;
1195 float scale = primary_pool_copy >= type_share ? 1.0f : primary_pool_copy / type_share;
1196 primary_pool_copy = std::max(0.0f, primary_pool_copy - type_share);
1199 for(
uint32_t i = index; i < next_index; ++i) {
1200 float old_employment =
state.world.factory_get_primary_employment(ordered_factories[i]);
1201 float new_employment =
1202 old_employment * (1.f - employment_shift_speed)
1203 + scale *
state.world.factory_get_production_scale(ordered_factories[i]) * employment_shift_speed;
1205 state.world.factory_set_primary_employment(
1206 ordered_factories[i],
1212 float type_share = (1.0f -
state.economy_definitions.craftsmen_fraction) * total_workforce;
1213 float scale = secondary_pool_copy >= type_share ? 1.0f : secondary_pool_copy / type_share;
1214 secondary_pool_copy = std::max(0.0f, secondary_pool_copy - type_share);
1216 for(
uint32_t i = index; i < next_index; ++i) {
1218 float old_employment =
state.world.factory_get_secondary_employment(ordered_factories[i]);
1219 float new_employment =
1220 old_employment * (1.f - employment_shift_speed)
1221 + scale *
state.world.factory_get_production_scale(ordered_factories[i]) * employment_shift_speed;
1223 state.world.factory_set_secondary_employment(
1224 ordered_factories[i],
1233 float prim_employment = 1.0f - (primary_pool > 0 ? primary_pool_copy / primary_pool : 0.0f);
1234 float sec_employment = 1.0f - (secondary_pool > 0 ? secondary_pool_copy / secondary_pool : 0.0f);
1237 for(
auto pop :
state.world.province_get_pop_location(p)) {
1238 if(pop.get_pop().get_poptype() == state.culture_definitions.primary_factory_worker) {
1239 pop_demographics::set_raw_employment(state, pop.get_pop(), prim_employment);
1240 }
else if(
pop.get_pop().get_poptype() ==
state.culture_definitions.secondary_factory_worker) {
1241 pop_demographics::set_raw_employment(state, pop.get_pop(), sec_employment);
1275 float mobilization_impact) {
1276 auto fac = fatten(state.world, f);
1277 auto fac_type = fac.get_building_type();
1286 float throughput_multiplier = (state.world.nation_get_factory_goods_throughput(n, fac_type.get_output()) + 1.0f);
1287 float output_multiplier = state.world.nation_get_factory_goods_output(n, fac_type.get_output())
1289 + fac.get_secondary_employment()
1290 * (1.0f - state.economy_definitions.craftsmen_fraction)
1294 float max_production_scale = fac.get_primary_employment()
1296 * std::max(0.0f, mobilization_impact);
1298 return throughput_multiplier * output_multiplier * max_production_scale;
1302 bool is_mine = state.world.commodity_get_is_mine(c);
1304 float main_rgo = 1.f;
1305 auto rgo = state.world.province_get_rgo(p);
1307 main_rgo = state.defines.alice_base_rgo_efficiency_bonus;
1310 float base_amount = state.world.commodity_get_rgo_amount(c);
1313 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_rgo_throughput)
1314 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rgo_throughput)
1315 + state.world.province_get_modifier_values(p,
1317 sys::provincial_mod_offsets::mine_rgo_eff
1319 sys::provincial_mod_offsets::farm_rgo_eff)
1320 + state.world.nation_get_modifier_values(n,
1322 sys::national_mod_offsets::mine_rgo_eff
1324 sys::national_mod_offsets::farm_rgo_eff);
1326 float saturation = std::clamp(state.world.province_get_rgo_employment_per_good(p, c)
1329 float result = base_amount
1331 * (1.f + 1.0f * (1.f - saturation))
1333 * state.defines.alice_rgo_boost
1334 * std::max(0.5f, (1.0f + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_rgo_output) +
1335 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rgo_output) +
1336 state.world.nation_get_rgo_goods_output(n, c)));
1338 assert(result >= 0.0f && std::isfinite(result));
1352 assert(val >= 0.0f && std::isfinite(val));
1359 dcon::factory_type_fat_id fac_type
1361 float min_input_available = 1.0f;
1362 auto& inputs = fac_type.get_inputs();
1363 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
1364 if(inputs.commodity_type[i]) {
1365 min_input_available =
1367 min_input_available,
1368 state.world.nation_get_demand_satisfaction(n, inputs.commodity_type[i])
1374 return min_input_available;
1378 float input_total = 0.0f;
1379 auto& inputs = fac_type.get_inputs();
1380 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
1381 if(inputs.commodity_type[i]) {
1382 input_total += inputs.commodity_amounts[i] * state.world.nation_get_effective_prices(n, inputs.commodity_type[i]);
1391 float min_e_input_available = 1.0f;
1392 auto& e_inputs = fac_type.get_efficiency_inputs();
1393 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
1394 if(e_inputs.commodity_type[i]) {
1395 min_e_input_available =
1397 min_e_input_available,
1398 state.world.nation_get_demand_satisfaction(n, e_inputs.commodity_type[i])
1405 return min_e_input_available;
1409 float e_input_total = 0.0f;
1410 auto& e_inputs = fac_type.get_efficiency_inputs();
1411 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
1412 if(e_inputs.commodity_type[i]) {
1413 e_input_total += e_inputs.commodity_amounts[i] * state.world.nation_get_effective_prices(n, e_inputs.commodity_type[i]);
1419 return e_input_total;
1425 state.defines.alice_inputs_base_factor
1426 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_input)
1430 auto output = state.world.factory_type_get_output(fac_type);
1431 return state.world.nation_get_factory_goods_output(n,
output)
1432 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_output)
1438 float small_size_effect = 1.f;
1439 float small_bound = state.defines.alice_factory_per_level_employment * 5.f;
1440 if(total_workers < small_bound) {
1441 small_size_effect = 0.5f + total_workers / small_bound * 0.5f;
1444 float total_state_pop = std::max(0.01f, state.world.state_instance_get_demographics(s,
demographics::total));
1445 float capitalists = state.world.state_instance_get_demographics(s,
demographics::to_key(state, state.culture_definitions.capitalists));
1446 float owner_fraction = total_state_pop > 0
1449 capitalists / total_state_pop)
1452 return small_size_effect *
1453 fac.get_triggered_modifiers() *
1456 (state.defines.alice_inputs_base_factor
1457 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_factory_input)
1458 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_input)
1459 + owner_fraction * -2.5f)
1464 return state.world.nation_get_factory_goods_throughput(n, fac_type.get_output())
1465 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_factory_throughput)
1466 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_throughput)
1471 auto fac_type = fac.get_building_type();
1473 return state.world.nation_get_factory_goods_output(n, fac_type.get_output())
1474 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_factory_output)
1475 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_output)
1476 + fac.get_secondary_employment()
1477 * (1.0f - state.economy_definitions.craftsmen_fraction)
1483 return fac.get_primary_employment()
1488 return fac.get_primary_employment()
1490 * (occupied ? 0.1f : 1.0f)
1491 * std::max(0.0f, mobilization_impact);
1496 float several_workers_scale = 10.f / total_workers;
1502 float relative_production_amount
1504 state.world.factory_type_get_output_amount(fac.get_building_type())
1506 state.world.commodity_get_total_production(fac.get_building_type().get_output())
1507 + state.world.commodity_get_total_real_demand(fac.get_building_type().get_output())
1511 float relative_modifier = (1 / (relative_production_amount + 0.01f)) / 1000.f;
1513 float effective_production_scale = 0.0f;
1514 if(state.world.factory_get_subsidized(fac)) {
1515 auto new_production_scale = std::min(1.0f, fac.get_production_scale() + several_workers_scale * fac.get_level() * 10.f);
1516 fac.set_production_scale(new_production_scale);
1517 return std::min(new_production_scale * fac.get_level(), max_production_scale);
1520 float over_profit_ratio = (raw_profit) / (desired_raw_profit + 0.0001f) - 1.f;
1521 float under_profit_ratio = (desired_raw_profit) / (raw_profit + 0.0001f) - 1.f;
1523 float speed_modifier = (over_profit_ratio - under_profit_ratio);
1524 float speed =
production_scale_delta * speed_modifier + several_workers_scale * ((raw_profit - desired_raw_profit > 0.f) ? 1.f : -1.f);
1526 speed = std::clamp(speed, -relative_modifier, relative_modifier);
1528 auto new_production_scale = std::clamp(fac.get_production_scale() + speed, 0.f, 1.f);
1529 fac.set_production_scale(new_production_scale);
1530 return std::min(new_production_scale * fac.get_level(), max_production_scale);
1534 return spendings * (1.2f + fac.get_secondary_employment() * fac.get_level() / 150.f );
1538 auto fac = fatten(state.world, f);
1539 auto fac_type = fac.get_building_type();
1542 assert(fac_type.get_output());
1548 float several_workers_scale = 10.f / total_workers;
1552 mobilization_impact,
1556 float current_workers = total_workers * max_production_scale;
1568 auto const mfactor = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
1573 float total_production = fac_type.get_output_amount()
1574 * (0.75f + 0.25f * min_e_input_available)
1575 * throughput_multiplier
1577 * min_input_available;
1582 * state.world.commodity_get_current_price(fac_type.get_output());
1587 * (state.defines.alice_factory_per_level_employment / state.defines.alice_needs_scaling_factor)
1590 * throughput_multiplier
1592 * min_input_available
1594 input_multiplier * mfactor
1596 * min_e_input_available
1597 * min_input_available;
1600 float max_pure_profit = profit - spendings;
1601 state.world.factory_set_unprofitable(f, !(max_pure_profit > 0.0f));
1606 max_production_scale,
1611 auto& inputs = fac_type.get_inputs();
1612 auto& e_inputs = fac_type.get_efficiency_inputs();
1621 * throughput_multiplier
1622 * effective_production_scale
1623 * (0.1f + min_input_available * 0.9f);
1625 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
1626 if(inputs.commodity_type[i]) {
1629 inputs.commodity_type[i],
1631 * inputs.commodity_amounts[i]
1632 , economy_reason::factory
1642 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
1643 if(e_inputs.commodity_type[i]) {
1647 e_inputs.commodity_type[i],
1650 * e_inputs.commodity_amounts[i]
1651 * (0.1f + min_e_input_available * 0.9f)
1652 , economy_reason::factory
1659 float actual_production = total_production * effective_production_scale;
1660 float pure_profit = max_pure_profit * effective_production_scale;
1662 state.world.factory_set_actual_production(f, actual_production);
1663 state.world.factory_set_full_profit(f, pure_profit);
1668 auto production = state.world.factory_get_actual_production(f);
1669 if(production > 0) {
1670 auto fac = fatten(state.world, f);
1671 auto fac_type = fac.get_building_type();
1695 auto amount = production;
1696 auto money_made = state.world.factory_get_full_profit(f);
1698 state.world.factory_set_actual_production(f, amount);
1701 if(!fac.get_subsidized()) {
1702 state.world.factory_set_full_profit(f, money_made);
1707 * fac.get_primary_employment()
1708 * (state.defines.alice_factory_per_level_employment / state.defines.alice_needs_scaling_factor);
1709 if(money_made < min_wages) {
1710 auto diff = min_wages - money_made;
1712 state.world.factory_set_full_profit(f, min_wages);
1713 state.world.nation_get_stockpiles(n,
money) -= diff;
1714 state.world.nation_get_subsidies_spending(n) += diff;
1716 state.world.factory_set_full_profit(f, std::max(money_made, 0.0f));
1717 fac.set_subsidized(
false);
1720 state.world.factory_set_full_profit(f, money_made);
1728 auto relevant_paid_population = 0.f;
1729 for(
auto wt : state.culture_definitions.rgo_workers) {
1730 relevant_paid_population += state.world.province_get_demographics(p,
demographics::to_key(state, wt));
1735 .paid_workers = relevant_paid_population,
1737 .total = relevant_paid_population + slaves
1747 float perfect_aristos_amount = total_relevant_population / 10000.f;
1748 float perfect_aristos_amount_adjusted = perfect_aristos_amount / state.defines.alice_needs_scaling_factor;
1749 float aristos_desired_cut = perfect_aristos_amount_adjusted * (
1750 state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.aristocrat)
1751 + state.world.nation_get_life_needs_costs(n, state.culture_definitions.aristocrat)
1753 float aristo_burden_per_worker = aristos_desired_cut / (total_relevant_population + 1);
1756 if (subsistence == 0) subsistence = state.world.province_get_subsistence_score(p);
1758 subsistence -= subsistence_life;
1760 subsistence -= subsistence_everyday;
1763 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
1765 dcon::pop_type_id pop_type = is_mine ? state.culture_definitions.laborers : state.culture_definitions.farmers;
1767 auto ln_costs = state.world.nation_get_life_needs_costs(n, pop_type);
1768 auto en_costs = state.world.nation_get_everyday_needs_costs(n, pop_type);
1769 auto lx_costs = state.world.nation_get_luxury_needs_costs(n, pop_type);
1771 float subsistence_based_min_wage =
1772 subsistence_life * ln_costs
1773 + subsistence_everyday * en_costs
1774 + subsistence_luxury * ln_costs;
1776 float min_wage_burden_per_worker = (min_wage + subsistence_based_min_wage) / state.defines.alice_needs_scaling_factor;
1778 float desired_profit_by_worker = aristo_burden_per_worker + min_wage_burden_per_worker / (1.f -
rgo_owners_cut);
1783 float employment_ratio = current_employment / (total_relevant_population + 1.f);
1784 desired_profit_by_worker = desired_profit_by_worker * employment_ratio;
1786 assert(std::isfinite(desired_profit_by_worker));
1788 return desired_profit_by_worker;
1795 auto current_price = state.world.commodity_get_current_price(c);
1796 auto consumed_ratio = std::min(1.f, (state.world.commodity_get_total_consumption(c) + 0.0001f) / (state.world.commodity_get_total_production(c) + 0.0001f));
1797 if(state.world.commodity_get_money_rgo(c)) {
1798 consumed_ratio = 1.f;
1805 / state.defines.alice_rgo_per_size_employment;
1809 return 1.f - (1.f - x) * (1.f - x);
1814 dcon::province_id p,
1816 float mobilization_impact,
1817 float expected_min_wage,
1823 state.world.for_each_commodity([&](dcon::commodity_id c) {
1825 if(max_production < 0.001f) {
1830 auto current_employment = state.world.province_get_rgo_employment_per_good(p, c);
1833 float market_size = state.world.commodity_get_total_production(c) + state.world.commodity_get_total_real_demand(c);
1835 float positive_speed = (expected_profit + 0.00000001f) / (desired_profit + 0.00000001f) - 1.f;
1836 float negative_speed = (desired_profit + 0.00000001f) / (expected_profit + 0.00000001f) - 1.f;
1838 float change = (positive_speed - negative_speed) /
rgo_effective_size(state, n, p, c);
1840 float discrete_step = (((expected_profit - desired_profit) > 0.f) ? 1.f : -1.f) * 20.f;
1842 change = change / max_production * pops_max / 100.f + discrete_step;
1845 assert(std::isfinite(current_employment + change));
1846 auto new_employment = std::clamp(current_employment + change, 0.0f, pops_max);
1847 state.world.province_set_rgo_target_employment_per_good(p, c, new_employment);
1850 float employment_ratio = current_employment / pops_max;
1851 assert(max_production * employment_ratio >= 0);
1852 state.world.province_set_rgo_actual_production_per_good(p, c, max_production * employment_ratio);
1857 state.world.province_set_rgo_full_profit(p, 0.f);
1858 state.world.for_each_commodity([&](dcon::commodity_id c) {
1859 auto amount = state.world.province_get_rgo_actual_production_per_good(p, c);
1863 float profit = amount * state.world.commodity_get_current_price(c);
1867 state.world.province_set_rgo_profit_per_good(p, c, profit);
1868 state.world.province_get_rgo_full_profit(p) += profit;
1870 if(state.world.commodity_get_money_rgo(c)) {
1871 assert(std::isfinite(amount * state.defines.gold_to_cash_rate) && amount * state.defines.gold_to_cash_rate >= 0.0f);
1872 state.world.nation_get_stockpiles(n,
money) += amount * state.defines.gold_to_cash_rate;
1879 auto const csize = state.world.commodity_size();
1880 auto num_artisans = state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.artisans));
1881 float total_profit = 0.0f;
1888 for(
uint32_t i = 1; i < csize; ++i) {
1889 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
1890 state.world.nation_set_artisan_actual_production(n, cid, 0.0f);
1892 float input_total = 0.0f;
1893 auto const& inputs = state.world.commodity_get_artisan_inputs(cid);
1894 float min_available = 1.0f;
1895 for(
uint32_t j = 0; j < commodity_set::set_size; ++j) {
1896 if(inputs.commodity_type[j]) {
1897 input_total += inputs.commodity_amounts[j] * state.world.nation_get_effective_prices(n, inputs.commodity_type[j]);
1898 min_available = std::min(min_available, state.world.nation_get_demand_satisfaction(n, inputs.commodity_type[j]));
1904 float output_total = state.world.commodity_get_artisan_output_amount(cid) * state.world.commodity_get_current_price(cid);
1906 float input_multiplier = std::max(0.1f, state.defines.alice_inputs_base_factor_artisans
1907 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::artisan_input));
1908 float throughput_multiplier = std::max(0.1f, 1.0f
1909 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::artisan_throughput));
1910 float output_multiplier = std::max(0.1f, state.defines.alice_output_base_factor_artisans
1911 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::artisan_output));
1914 float max_production_scale = num_artisans * distribution / 10'000.0f * std::max(0.0f, mobilization_impact);
1916 auto profitability_factor = (output_total * output_multiplier * throughput_multiplier * min_available - input_multiplier * input_total * throughput_multiplier * min_available) / (0.5f * expected_min_wage * (10'000.0f / state.defines.alice_needs_scaling_factor));
1918 bool profitable = (output_total * output_multiplier - input_multiplier * input_total) >= 0.0f;
1924 for(
uint32_t j = 0; j < commodity_set::set_size; ++j) {
1925 if(inputs.commodity_type[j]) {
1929 inputs.commodity_type[j],
1930 input_multiplier * throughput_multiplier * max_production_scale * inputs.commodity_amounts[j] * (0.1f + 0.9f * min_available),
1931 economy_reason::artisan
1937 state.world.nation_set_artisan_actual_production(n, cid, state.world.commodity_get_artisan_output_amount(cid) * throughput_multiplier * output_multiplier * max_production_scale * min_available);
1938 total_profit += std::max(0.0f, (output_total * output_multiplier - input_multiplier * input_total) * throughput_multiplier * max_production_scale * min_available);
1943 state.world.nation_set_artisan_profit(n, total_profit);
1947 auto const csize = state.world.commodity_size();
1948 auto num_artisans = state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.artisans));
1949 float total_profit = 0.0f;
1951 for(
uint32_t i = 1; i < csize; ++i) {
1952 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
1956 auto production = state.world.nation_get_artisan_actual_production(n, cid);
1957 if(production > 0.f) {
1958 auto const& inputs = state.world.commodity_get_artisan_inputs(cid);
1960 float min_input = 1.0f;
1961 for(
uint32_t j = 0; j < commodity_set::set_size; ++j) {
1962 if(inputs.commodity_type[j]) {
1963 min_input = std::min(min_input, state.world.nation_get_demand_satisfaction(n, inputs.commodity_type[j]));
1969 auto amount = min_input * production;
1970 state.world.nation_set_artisan_actual_production(n, cid, amount);
1978 uint32_t total_commodities = state.world.commodity_size();
1979 for(
uint32_t i = 1; i < total_commodities; ++i) {
1980 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
1981 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_army_demand(ids, cid, 0.0f); });
1984 state.world.for_each_regiment([&](dcon::regiment_id r) {
1985 auto reg = fatten(state.world, r);
1986 auto type = state.world.regiment_get_type(r);
1987 auto owner = reg.get_army_from_army_membership().get_controller_from_army_control();
1989 auto o_sc_mod = std::max(0.01f, state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::supply_consumption) + 1.0f);
1990 auto& supply_cost = state.military_definitions.unit_base_definitions[type].supply_cost;
1991 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
1992 if(supply_cost.commodity_type[i]) {
1993 state.world.nation_get_army_demand(owner, supply_cost.commodity_type[i]) +=
1994 supply_cost.commodity_amounts[i] * state.world.nation_get_unit_stats(owner, type).supply_consumption *
2005 uint32_t total_commodities = state.world.commodity_size();
2006 for(
uint32_t i = 1; i < total_commodities; ++i) {
2007 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2008 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_navy_demand(ids, cid, 0.0f); });
2011 state.world.for_each_ship([&](dcon::ship_id r) {
2012 auto shp = fatten(state.world, r);
2013 auto type = state.world.ship_get_type(r);
2014 auto owner = shp.get_navy_from_navy_membership().get_controller_from_navy_control();
2016 auto o_sc_mod = std::max(0.01f, state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::supply_consumption) + 1.0f);
2017 auto& supply_cost = state.military_definitions.unit_base_definitions[type].supply_cost;
2018 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2019 if(supply_cost.commodity_type[i]) {
2020 state.world.nation_get_navy_demand(owner, supply_cost.commodity_type[i]) +=
2021 supply_cost.commodity_amounts[i] * state.world.nation_get_unit_stats(owner, type).supply_consumption *
2044 float t =
math::sqrt((
static_cast<float>(state.current_date.value) * 0.01f + 2.f));
2061 float t =
math::sqrt((
static_cast<float>(state.current_date.value) * 0.01f + 2.f));
2066 uint32_t total_commodities = state.world.commodity_size();
2067 for(
uint32_t i = 1; i < total_commodities; ++i) {
2068 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2069 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_construction_demand(ids, cid, 0.0f); });
2072 for(
auto lc : state.world.in_province_land_construction) {
2073 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
2074 auto owner = state.world.province_get_nation_from_province_ownership(
province);
2076 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
2077 float admin_cost_factor = 2.0f - admin_eff;
2079 if(owner && state.world.province_get_nation_from_province_control(
province) == owner) {
2082 state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(lc)].build_cost;
2083 auto& current_purchased = state.world.province_land_construction_get_purchased_goods(lc);
2085 float(state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(lc)].build_time);
2087 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2088 if(base_cost.commodity_type[i]) {
2089 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor)
2090 register_construction_demand(state, owner, base_cost.commodity_type[i], base_cost.commodity_amounts[i] * admin_cost_factor / construction_time);
2099 auto owner = state.world.province_get_nation_from_province_ownership(p);
2100 if(!owner || state.world.province_get_nation_from_province_control(p) != owner)
2103 auto rng = state.world.province_get_province_naval_construction(p);
2104 if(rng.begin() != rng.end()) {
2105 auto c = *(rng.begin());
2107 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
2108 float admin_cost_factor = 2.0f - admin_eff;
2110 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
2111 auto& current_purchased = c.get_purchased_goods();
2112 float construction_time = global_non_factory_construction_time_modifier(state) *
2113 float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
2115 for(uint32_t i = 0; i < commodity_set::set_size; ++i) {
2116 if(base_cost.commodity_type[i]) {
2117 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor)
2118 register_construction_demand(state, owner, base_cost.commodity_type[i], base_cost.commodity_amounts[i] * admin_cost_factor / construction_time);
2127 for(
auto c : state.world.in_province_building_construction) {
2128 auto owner = c.get_nation().id;
2129 if(owner && c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
2131 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
2132 auto& current_purchased = c.get_purchased_goods();
2133 float construction_time = global_non_factory_construction_time_modifier(state) *
2134 float(state.economy_definitions.building_definitions[int32_t(t)].time);
2136 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
2137 float admin_cost_factor = 2.0f - admin_eff;
2139 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2140 if(base_cost.commodity_type[i]) {
2141 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor)
2142 register_construction_demand(state, owner, base_cost.commodity_type[i], base_cost.commodity_amounts[i] * admin_cost_factor / construction_time);
2150 for(
auto c :
state.world.in_state_building_construction) {
2151 auto owner = c.get_nation().id;
2152 if(owner && !c.get_is_pop_project()) {
2153 auto& base_cost = c.get_type().get_construction_costs();
2154 auto& current_purchased = c.get_purchased_goods();
2156 float(c.get_type().get_construction_time()) * (c.get_is_upgrade() ? 0.5f : 1.0f);
2157 float factory_mod =
state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::factory_cost) + 1.0f;
2159 float admin_eff =
state.world.nation_get_administrative_efficiency(owner);
2160 float admin_cost_factor = 2.0f - admin_eff;
2162 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2163 if(base_cost.commodity_type[i]) {
2164 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod * admin_cost_factor)
2165 register_construction_demand(state, owner, base_cost.commodity_type[i], base_cost.commodity_amounts[i] * factory_mod * admin_cost_factor / construction_time);
2175 uint32_t total_commodities = state.world.commodity_size();
2176 for(
uint32_t i = 1; i < total_commodities; ++i) {
2177 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2178 state.world.execute_serial_over_nation([&](
auto ids) { state.world.nation_set_private_construction_demand(ids, cid, 0.0f); });
2181 for(
auto c : state.world.in_province_building_construction) {
2182 auto owner = c.get_nation().id;
2184 if(owner && owner == c.get_province().get_nation_from_province_control() && c.get_is_pop_project()) {
2186 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
2187 auto& current_purchased = c.get_purchased_goods();
2189 float(state.economy_definitions.building_definitions[int32_t(t)].time);
2190 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2191 if(base_cost.commodity_type[i]) {
2192 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i])
2193 state.world.nation_get_private_construction_demand(owner, base_cost.commodity_type[i]) +=
2194 base_cost.commodity_amounts[i] / construction_time;
2202 for(
auto c : state.world.in_state_building_construction) {
2203 auto owner = c.get_nation().id;
2204 if(owner && c.get_is_pop_project()) {
2205 auto& base_cost = c.get_type().get_construction_costs();
2206 auto& current_purchased = c.get_purchased_goods();
2208 float(c.get_type().get_construction_time()) * (c.get_is_upgrade() ? 0.1f : 1.0f);
2209 float factory_mod = (state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::factory_cost) + 1.0f) * std::max(0.1f, state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::factory_owner_cost));
2211 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2212 if(base_cost.commodity_type[i]) {
2213 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod)
2214 state.world.nation_get_private_construction_demand(owner, base_cost.commodity_type[i]) +=
2215 base_cost.commodity_amounts[i] * factory_mod / construction_time;
2226 float military_total = 0.f;
2227 uint32_t total_commodities = state.world.commodity_size();
2228 float l_spending = float(state.world.nation_get_land_spending(n)) / 100.0f;
2229 float n_spending = float(state.world.nation_get_naval_spending(n)) / 100.0f;
2230 float c_spending = float(state.world.nation_get_construction_spending(n)) / 100.0f;
2231 float o_spending = float(state.world.nation_get_overseas_spending(n)) / 100.f;
2233 for(
uint32_t i = 1; i < total_commodities; ++i) {
2234 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2235 auto v = state.world.nation_get_army_demand(n, cid) * l_spending * state.world.nation_get_effective_prices(n, cid);
2236 assert(std::isfinite(v) && v >= 0.0f);
2238 military_total += v;
2240 for(
uint32_t i = 1; i < total_commodities; ++i) {
2241 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2242 auto v = state.world.nation_get_navy_demand(n, cid) * n_spending * state.world.nation_get_effective_prices(n, cid);
2243 assert(std::isfinite(v) && v >= 0.0f);
2245 military_total += v;
2247 assert(std::isfinite(total) && total >= 0.0f);
2248 state.world.nation_set_maximum_military_costs(n, military_total);
2250 for(
uint32_t i = 1; i < total_commodities; ++i) {
2251 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2252 total += state.world.nation_get_construction_demand(n, cid) * c_spending * state.world.nation_get_effective_prices(n, cid);
2254 for(
uint32_t i = 1; i < total_commodities; ++i) {
2255 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2256 auto difference = state.world.nation_get_stockpile_targets(n, cid) - state.world.nation_get_stockpiles(n, cid);
2257 if(difference > 0 && state.world.nation_get_drawing_on_stockpiles(n, cid) ==
false) {
2258 total += difference * state.world.nation_get_effective_prices(n, cid);
2261 assert(std::isfinite(total) && total >= 0.0f);
2263 auto overseas_factor = state.defines.province_overseas_penalty * float(state.world.nation_get_owned_province_count(n) - state.world.nation_get_central_province_count(n));
2264 if(overseas_factor > 0) {
2265 for(
uint32_t i = 1; i < total_commodities; ++i) {
2266 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2267 auto kf = state.world.commodity_get_key_factory(cid);
2268 if(state.world.commodity_get_overseas_penalty(cid) && (state.world.commodity_get_is_available_from_start(cid) || (kf && state.world.nation_get_active_building(n, kf)))) {
2269 total += overseas_factor * state.world.nation_get_effective_prices(n, cid) * o_spending;
2274 assert(std::isfinite(total) && total >= 0.0f);
2277 auto const a_spending = float(state.world.nation_get_administrative_spending(n)) / 100.0f * float(state.world.nation_get_administrative_spending(n)) / 100.0f;
2278 auto const s_spending = state.world.nation_get_administrative_efficiency(n) * float(state.world.nation_get_social_spending(n)) / 100.0f;
2279 auto const e_spending = float(state.world.nation_get_education_spending(n)) * float(state.world.nation_get_education_spending(n)) / 100.0f / 100.0f;
2280 auto const m_spending = float(state.world.nation_get_military_spending(n)) * float(state.world.nation_get_military_spending(n)) / 100.0f / 100.f;
2281 auto const p_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::pension_level);
2282 auto const unemp_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::unemployment_benefit);
2283 auto const di_spending = float(state.world.nation_get_domestic_investment_spending(n)) * float(state.world.nation_get_domestic_investment_spending(n)) / 100.0f / 100.0f;
2285 total += state.defines.alice_domestic_investment_multiplier * di_spending *
2286 (state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.capitalists))
2287 * state.world.nation_get_luxury_needs_costs(n, state.culture_definitions.capitalists)
2288 + state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.aristocrat))
2289 * state.world.nation_get_luxury_needs_costs(n, state.culture_definitions.aristocrat))
2290 / state.defines.alice_needs_scaling_factor;
2292 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
2293 auto adj_pop_of_type = state.world.nation_get_demographics(n,
demographics::to_key(state, pt)) / state.defines.alice_needs_scaling_factor;
2295 if(adj_pop_of_type <= 0)
2300 total += a_spending * adj_pop_of_type * state.world.nation_get_life_needs_costs(n, pt);
2302 total += e_spending * adj_pop_of_type * state.world.nation_get_life_needs_costs(n, pt);
2304 total += m_spending * adj_pop_of_type * state.world.nation_get_life_needs_costs(n, pt);
2306 total += s_spending * adj_pop_of_type * p_level * state.world.nation_get_life_needs_costs(n, pt);
2307 if(state.world.pop_type_get_has_unemployment(pt)) {
2309 total += s_spending * (adj_pop_of_type - emp) * unemp_level * state.world.nation_get_life_needs_costs(n, pt);
2315 total += a_spending * adj_pop_of_type * state.world.nation_get_everyday_needs_costs(n, pt);
2317 total += e_spending * adj_pop_of_type * state.world.nation_get_everyday_needs_costs(n, pt);
2319 total += m_spending * adj_pop_of_type * state.world.nation_get_everyday_needs_costs(n, pt);
2324 total += a_spending * adj_pop_of_type * state.world.nation_get_luxury_needs_costs(n, pt);
2326 total += e_spending * adj_pop_of_type * state.world.nation_get_luxury_needs_costs(n, pt);
2328 total += m_spending * adj_pop_of_type * state.world.nation_get_luxury_needs_costs(n, pt);
2331 assert(std::isfinite(total) && total >= 0.0f);
2334 assert(std::isfinite(total) && total >= 0.0f);
2341 uint32_t total_commodities = state.world.commodity_size();
2343 for(
uint32_t i = 1; i < total_commodities; ++i) {
2344 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
2345 auto difference = state.world.nation_get_stockpile_targets(n, cid) - state.world.nation_get_stockpiles(n, cid);
2346 if(difference > 0 && state.world.nation_get_drawing_on_stockpiles(n, cid) ==
false) {
2347 total += difference * state.world.commodity_get_current_price(cid) * state.world.nation_get_demand_satisfaction(n, cid);
2357 auto overseas_factor = state.defines.province_overseas_penalty * float(state.world.nation_get_owned_province_count(n) - state.world.nation_get_central_province_count(n));
2358 uint32_t total_commodities = state.world.commodity_size();
2360 if(overseas_factor > 0) {
2361 for(
uint32_t i = 1; i < total_commodities; ++i) {
2362 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
2364 auto kf = state.world.commodity_get_key_factory(cid);
2365 if(state.world.commodity_get_overseas_penalty(cid) && (state.world.commodity_get_is_available_from_start(cid) || (kf && state.world.nation_get_active_building(n, kf)))) {
2366 total += overseas_factor * state.world.commodity_get_current_price(cid) * state.world.nation_get_demand_satisfaction(n, cid);
2376 uint32_t total_commodities = state.world.commodity_size();
2377 for(
uint32_t i = 1; i < total_commodities; ++i) {
2378 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2379 total += state.world.nation_get_private_construction_demand(n, cid) * state.world.nation_get_effective_prices(n, cid);
2385 uint32_t total_commodities = state.world.commodity_size();
2386 float l_spending = float(state.world.nation_get_land_spending(n)) / 100.0f;
2387 float n_spending = float(state.world.nation_get_naval_spending(n)) / 100.0f;
2388 float c_spending = float(state.world.nation_get_construction_spending(n)) / 100.0f;
2389 float o_spending = float(state.world.nation_get_overseas_spending(n)) / 100.0f;
2391 for(
uint32_t i = 1; i < total_commodities; ++i) {
2392 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2393 register_demand(state, n, cid, state.world.nation_get_army_demand(n, cid) * l_spending * spending_scale, economy_reason::nation);
2395 for(
uint32_t i = 1; i < total_commodities; ++i) {
2396 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2397 register_demand(state, n, cid, state.world.nation_get_navy_demand(n, cid) * n_spending * spending_scale, economy_reason::nation);
2399 for(
uint32_t i = 1; i < total_commodities; ++i) {
2400 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2401 register_demand(state, n, cid, state.world.nation_get_construction_demand(n, cid) * c_spending * spending_scale, economy_reason::construction);
2403 for(
uint32_t i = 1; i < total_commodities; ++i) {
2404 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
2405 register_demand(state, n, cid, state.world.nation_get_private_construction_demand(n, cid) * private_investment_scale, economy_reason::construction);
2407 for(
uint32_t i = 1; i < total_commodities; ++i) {
2408 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2409 auto difference = state.world.nation_get_stockpile_targets(n, cid) - state.world.nation_get_stockpiles(n, cid);
2410 if(difference > 0 && state.world.nation_get_drawing_on_stockpiles(n, cid) ==
false) {
2411 register_demand(state, n, cid, difference * spending_scale, economy_reason::stockpile);
2414 auto overseas_factor = state.defines.province_overseas_penalty * float(state.world.nation_get_owned_province_count(n) - state.world.nation_get_central_province_count(n));
2415 if(overseas_factor > 0.f) {
2416 for(
uint32_t i = 1; i < total_commodities; ++i) {
2417 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
2418 auto kf = state.world.commodity_get_key_factory(cid);
2419 if(state.world.commodity_get_overseas_penalty(cid) && (state.world.commodity_get_is_available_from_start(cid) || (kf && state.world.nation_get_active_building(n, kf)))) {
2420 register_demand(state, n, cid, overseas_factor * spending_scale * o_spending, economy_reason::overseas_penalty);
2427 uint32_t total_commodities = state.world.commodity_size();
2429 static auto ln_demand_vector = state.world.pop_type_make_vectorizable_float_buffer();
2430 state.world.execute_serial_over_pop_type([&](
auto ids) { ln_demand_vector.set(ids, ve::fp_vector{}); });
2431 static auto en_demand_vector = state.world.pop_type_make_vectorizable_float_buffer();
2432 state.world.execute_serial_over_pop_type([&](
auto ids) { en_demand_vector.set(ids, ve::fp_vector{}); });
2433 static auto lx_demand_vector = state.world.pop_type_make_vectorizable_float_buffer();
2434 state.world.execute_serial_over_pop_type([&](
auto ids) { lx_demand_vector.set(ids, ve::fp_vector{}); });
2437 auto nation_rules = state.world.nation_get_combined_issue_rules(n);
2439 for(
auto p : state.world.nation_get_province_ownership(n)) {
2443 subsistence -= subsistence_life;
2445 subsistence -= subsistence_everyday;
2452 for(
auto pl : state.world.province_get_pop_location(p.get_province())) {
2453 auto t = pl.get_pop().get_poptype();
2455 auto total_budget = pl.get_pop().get_savings();
2456 auto total_pop = pl.get_pop().get_size();
2460 float ln_to_satisfy = std::max(1.f - subsistence_life, 0.f);
2461 float en_to_satisfy = std::max(1.f - subsistence_everyday, 0.f);
2462 float xn_to_satisfy = std::max(1.f - subsistence_luxury, 0.f);
2464 float ln_cost = ln_to_satisfy * state.world.nation_get_life_needs_costs(n, t) * total_pop / state.defines.alice_needs_scaling_factor;
2465 float en_cost = en_to_satisfy * state.world.nation_get_everyday_needs_costs(n, t) * total_pop / state.defines.alice_needs_scaling_factor;
2466 float xn_cost = xn_to_satisfy * state.world.nation_get_luxury_needs_costs(n, t) * total_pop / state.defines.alice_needs_scaling_factor;
2468 float life_needs_fraction = (total_budget >= ln_cost ? ln_to_satisfy : total_budget / ln_cost);
2469 total_budget -= ln_cost;
2472 total_budget = std::max(total_budget, 0.f);
2475 if(!nation_allows_investment || (t != state.culture_definitions.aristocrat && t != state.culture_definitions.capitalists)) {
2477 }
else if(t == state.culture_definitions.capitalists) {
2478 state.world.nation_get_private_investment(n) += total_budget * state.defines.alice_invest_capitalist;
2479 total_budget -= total_budget * state.defines.alice_invest_capitalist;
2481 state.world.nation_get_private_investment(n) += total_budget * state.defines.alice_invest_aristocrat;
2482 total_budget -= total_budget * state.defines.alice_invest_aristocrat;
2485 float everyday_needs_fraction = (total_budget >= en_cost ? en_to_satisfy : std::max(0.0f, total_budget / en_cost));
2486 total_budget -= en_cost;
2488 float luxury_needs_fraction = (total_budget >= xn_cost ? xn_to_satisfy : std::max(0.0f, total_budget / xn_cost));
2489 total_budget -= xn_cost;
2494 float total_cost = ln_cost + en_cost + xn_cost;
2496 if((total_budget > 0.f)) {
2497 float life_needs_budget = total_budget * state.defines.alice_needs_lf_spend;
2498 float everyday_needs_budget = total_budget * state.defines.alice_needs_ev_spend;
2499 float luxury_needs_budget = total_budget * state.defines.alice_needs_lx_spend;
2501 float induced_life_needs_demand = life_needs_budget / std::max(0.001f, ln_cost);
2502 float induced_everyday_needs_demand = everyday_needs_budget / std::max(0.001f, en_cost);
2503 float induced_luxury_needs_demand = luxury_needs_budget / std::max(0.001f, xn_cost);
2505 life_needs_fraction += induced_life_needs_demand;
2506 everyday_needs_fraction += induced_everyday_needs_demand;
2507 luxury_needs_fraction += induced_luxury_needs_demand;
2510 assert(std::isfinite(life_needs_fraction));
2511 assert(std::isfinite(everyday_needs_fraction));
2512 assert(std::isfinite(luxury_needs_fraction));
2518 float old_life_to_use_in_demand_calculation = old_life;
2519 float old_everyday_to_use_in_demand_calculation = old_everyday;
2520 float old_luxury_to_use_in_demand_calculation = old_luxury;
2522 float final_life_needs_fraction = life_needs_fraction + subsistence_life;
2523 float final_everyday_needs_fraction = everyday_needs_fraction + subsistence_everyday;
2524 float final_luxury_needs_fraction = luxury_needs_fraction + subsistence_luxury;
2528 old_life_to_use_in_demand_calculation = std::clamp(old_life - subsistence_life, 0.f, 1.f);
2529 old_everyday_to_use_in_demand_calculation = std::clamp(old_everyday - subsistence_everyday, 0.f, 1.f);
2530 old_luxury_to_use_in_demand_calculation = std::clamp(old_luxury - subsistence_luxury, 0.f, 1.f);
2532 auto result_life = std::clamp(old_life_to_use_in_demand_calculation * 0.9f + life_needs_fraction * 0.1f, 0.f, 1.f);
2533 auto result_everyday = std::clamp(old_everyday_to_use_in_demand_calculation * 0.9f + everyday_needs_fraction * 0.1f, 0.f, 1.f);
2534 auto result_luxury = std::clamp(old_luxury_to_use_in_demand_calculation * 0.9f + luxury_needs_fraction * 0.1f, 0.f, 1.f);
2540 ln_demand_vector.get(t) += result_life * total_pop / state.defines.alice_needs_scaling_factor;
2541 en_demand_vector.get(t) += result_everyday * total_pop / state.defines.alice_needs_scaling_factor;
2542 lx_demand_vector.get(t) += result_luxury * total_pop / state.defines.alice_needs_scaling_factor;
2544 assert(std::isfinite(ln_demand_vector.get(t)));
2545 assert(std::isfinite(en_demand_vector.get(t)));
2546 assert(std::isfinite(lx_demand_vector.get(t)));
2550 float ln_mul[] = {state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_life_needs) + 1.0f,
2551 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_life_needs) + 1.0f,
2552 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_life_needs) + 1.0f};
2553 float en_mul[] = {state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_everyday_needs) + 1.0f,
2554 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_everyday_needs) + 1.0f,
2555 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_everyday_needs) + 1.0f};
2557 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_luxury_needs) + 1.0f,
2558 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_luxury_needs) + 1.0f,
2559 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_luxury_needs) + 1.0f,
2562 for(
uint32_t i = 1; i < total_commodities; ++i) {
2563 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
2564 auto kf = state.world.commodity_get_key_factory(cid);
2565 if(state.world.commodity_get_is_available_from_start(cid) || (kf && state.world.nation_get_active_building(n, kf))) {
2566 for(
const auto t : state.world.in_pop_type) {
2567 auto strata = state.world.pop_type_get_strata(t);
2568 float life_weight = state.world.nation_get_life_needs_weights(n, cid);
2569 float everyday_weight = state.world.nation_get_everyday_needs_weights(n, cid);
2570 float luxury_weight = state.world.nation_get_luxury_needs_weights(n, cid);
2572 float base_life = state.world.pop_type_get_life_needs(t, cid);
2573 float base_everyday = state.world.pop_type_get_everyday_needs(t, cid);
2574 float base_luxury = state.world.pop_type_get_luxury_needs(t, cid);
2576 float dist_life = ln_demand_vector.get(t);
2577 float dist_everyday = en_demand_vector.get(t);
2578 float dist_luxury = lx_demand_vector.get(t);
2580 float demand_life = base_life * dist_life * base_demand * ln_mul[strata] * life_weight * state.defines.alice_lf_needs_scale;
2581 float demand_everyday = base_everyday * dist_everyday * base_demand * invention_factor * en_mul[strata] * everyday_weight * state.defines.alice_ev_needs_scale;
2582 float demand_luxury = base_luxury * dist_luxury * base_demand * invention_factor * lx_mul[strata] * luxury_weight * state.defines.alice_lx_needs_scale;
2603 uint32_t total_commodities = state.world.commodity_size();
2605 float ln_mul[] = { state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_life_needs) + 1.0f,
2606 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_life_needs) + 1.0f,
2607 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_life_needs) + 1.0f };
2608 float en_mul[] = { state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_everyday_needs) + 1.0f,
2609 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_everyday_needs) + 1.0f,
2610 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_everyday_needs) + 1.0f };
2611 float lx_mul[] = { state.world.nation_get_modifier_values(n, sys::national_mod_offsets::poor_luxury_needs) + 1.0f,
2612 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::middle_luxury_needs) + 1.0f,
2613 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rich_luxury_needs) + 1.0f };
2615 for(
uint32_t i = 1; i < total_commodities; ++i) {
2616 dcon::commodity_id c{dcon::commodity_id::value_base_t(i)};
2617 auto kf = state.world.commodity_get_key_factory(c);
2618 if(state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf))) {
2619 float effective_price = state.world.nation_get_effective_prices(n, c);
2620 auto ln_weight = state.world.nation_get_life_needs_weights(n, c);
2621 auto en_weight = state.world.nation_get_everyday_needs_weights(n, c);
2622 auto lx_weight = state.world.nation_get_luxury_needs_weights(n, c);
2624 state.world.for_each_pop_type([&](dcon::pop_type_id ids) {
2625 auto ln_base = state.world.pop_type_get_life_needs(ids, c);
2626 auto ln = ln_base * effective_price * base_demand * ln_mul[state.world.pop_type_get_strata(ids)] * ln_weight * state.defines.alice_lf_needs_scale;
2627 state.world.nation_set_life_needs_costs(n, ids, ln + state.world.nation_get_life_needs_costs(n, ids));
2628 auto en_base = state.world.pop_type_get_everyday_needs(ids, c);
2629 auto en = en_base * effective_price * base_demand * invention_factor * en_mul[state.world.pop_type_get_strata(ids)] * en_weight * state.defines.alice_ev_needs_scale;
2630 state.world.nation_set_everyday_needs_costs(n, ids, en + state.world.nation_get_everyday_needs_costs(n, ids));
2631 auto lx_base = state.world.pop_type_get_luxury_needs(ids, c);
2632 auto lx = lx_base * effective_price * base_demand * invention_factor * lx_mul[state.world.pop_type_get_strata(ids)] * lx_weight * state.defines.alice_lx_needs_scale;
2633 state.world.nation_set_luxury_needs_costs(n, ids, lx + state.world.nation_get_luxury_needs_costs(n, ids));
2634 assert(std::isfinite(state.world.nation_get_life_needs_costs(n, ids)) && state.world.nation_get_life_needs_costs(n, ids) >= 0.f);
2635 assert(std::isfinite(state.world.nation_get_everyday_needs_costs(n, ids)) && state.world.nation_get_everyday_needs_costs(n, ids) >= 0.f);
2636 assert(std::isfinite(state.world.nation_get_luxury_needs_costs(n, ids)) && state.world.nation_get_luxury_needs_costs(n, ids) >= 0.f);
2643 uint32_t total_commodities = state.world.commodity_size();
2645 float c_spending = state.world.nation_get_spending_level(n) * float(state.world.nation_get_construction_spending(n)) / 100.0f;
2646 float p_spending = state.world.nation_get_private_investment_effective_fraction(n);
2648 float refund_amount = 0.0f;
2650 for(
uint32_t i = 1; i < total_commodities; ++i) {
2651 dcon::commodity_id c{dcon::commodity_id::value_base_t(i)};
2652 auto d_sat = state.world.nation_get_demand_satisfaction(n, c);
2653 auto& nat_demand = state.world.nation_get_construction_demand(n, c);
2654 refund_amount += nat_demand * c_spending * (1.0f - d_sat) * state.world.commodity_get_current_price(c);
2655 nat_demand *= c_spending * d_sat;
2656 state.world.nation_get_private_construction_demand(n, c) *= p_spending * d_sat;
2659 assert(refund_amount >= 0.0f);
2660 state.world.nation_get_stockpiles(n,
economy::money) += refund_amount;
2662 float admin_eff = state.world.nation_get_administrative_efficiency(n);
2663 float admin_cost_factor = 2.0f - admin_eff;
2665 for(
auto p : state.world.nation_get_province_ownership(n)) {
2666 if(p.get_province().get_nation_from_province_control() != n)
2669 for(
auto pops : p.get_province().get_pop_location()) {
2670 auto rng = pops.get_pop().get_province_land_construction();
2671 if(
rng.begin() !=
rng.end()) {
2672 auto c = *(
rng.begin());
2673 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
2674 auto& current_purchased = c.get_purchased_goods();
2677 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2678 if(base_cost.commodity_type[i]) {
2679 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
2680 auto amount = base_cost.commodity_amounts[i] / construction_time;
2681 auto& source = state.world.nation_get_construction_demand(n, base_cost.commodity_type[i]);
2682 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
2683 current_purchased.commodity_amounts[i] += delta;
2694 auto rng = p.get_province().get_province_naval_construction();
2695 if(
rng.begin() !=
rng.end()) {
2696 auto c = *(
rng.begin());
2697 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
2698 auto& current_purchased = c.get_purchased_goods();
2701 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2702 if(base_cost.commodity_type[i]) {
2703 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
2704 auto amount = base_cost.commodity_amounts[i] / construction_time;
2705 auto& source = state.world.nation_get_construction_demand(n, base_cost.commodity_type[i]);
2706 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
2708 current_purchased.commodity_amounts[i] += delta;
2719 for(
auto c : state.world.nation_get_province_building_construction(n)) {
2720 if(c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control()) {
2725 if(!c.get_is_pop_project()) {
2726 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
2727 auto& current_purchased = c.get_purchased_goods();
2730 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2731 if(base_cost.commodity_type[i]) {
2732 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
2733 auto amount = base_cost.commodity_amounts[i] / construction_time;
2734 auto& source = state.world.nation_get_construction_demand(n, base_cost.commodity_type[i]);
2735 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
2737 current_purchased.commodity_amounts[i] += delta;
2744 }
else if(c.get_is_pop_project()) {
2745 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
2746 auto& current_purchased = c.get_purchased_goods();
2749 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2750 if(base_cost.commodity_type[i]) {
2751 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i]) {
2752 auto amount = base_cost.commodity_amounts[i] / construction_time;
2753 auto& source = state.world.nation_get_private_construction_demand(n, base_cost.commodity_type[i]);
2754 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
2756 current_purchased.commodity_amounts[i] += delta;
2767 for(
auto c : state.world.nation_get_state_building_construction(n)) {
2768 if(!c.get_is_pop_project()) {
2769 auto& base_cost = c.get_type().get_construction_costs();
2770 auto& current_purchased = c.get_purchased_goods();
2772 float factory_mod = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f;
2774 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2775 if(base_cost.commodity_type[i]) {
2776 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod * admin_cost_factor) {
2777 auto amount = base_cost.commodity_amounts[i] / construction_time;
2778 auto& source = state.world.nation_get_construction_demand(n, base_cost.commodity_type[i]);
2779 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] * factory_mod / construction_time));
2781 current_purchased.commodity_amounts[i] += delta;
2789 auto& base_cost = c.get_type().get_construction_costs();
2790 auto& current_purchased = c.get_purchased_goods();
2792 float factory_mod = (state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f) *
2793 std::max(0.1f, state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_owner_cost));
2795 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2796 if(base_cost.commodity_type[i]) {
2797 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod) {
2798 auto amount = base_cost.commodity_amounts[i] / construction_time;
2799 auto& source = state.world.nation_get_private_construction_demand(n, base_cost.commodity_type[i]);
2800 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] * factory_mod / construction_time));
2802 current_purchased.commodity_amounts[i] += delta;
2814 return state.world.nation_get_modifier_values(n, sys::national_mod_offsets::minimum_wage);
2819 float life = state.world.nation_get_life_needs_costs(n, state.culture_definitions.farmers);
2820 float everyday = state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.farmers);
2822 return min_wage_factor * (life + everyday) * 1.1f;
2826 float life = state.world.nation_get_life_needs_costs(n, state.culture_definitions.laborers);
2827 float everyday = state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.laborers);
2829 return min_wage_factor * (life + everyday) * 1.1f;
2834 float total = state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.primary_factory_worker));
2836 float unemployement_crisis_measures = 1.f;
2838 unemployement_crisis_measures = employed / total;
2841 float life = state.world.nation_get_life_needs_costs(n, state.culture_definitions.primary_factory_worker);
2842 float everyday = state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.primary_factory_worker);
2844 return min_wage_factor * (life + everyday) * 1.1f * unemployement_crisis_measures * unemployement_crisis_measures * unemployement_crisis_measures;
2849 auto sl = state.world.nation_get_in_sphere_of(n);
2850 if(global_price_multiplier >= 1.0f) {
2851 state.world.for_each_commodity([&](dcon::commodity_id c) {
2852 auto domestic_supply =
2853 state.world.nation_get_domestic_market_pool(n, c) + (sl ? state.world.nation_get_domestic_market_pool(sl, c) : 0.0f) +
2854 (state.world.nation_get_drawing_on_stockpiles(n, c) ? state.world.nation_get_stockpiles(n, c) : 0.0f);
2855 auto global_supply = state.world.commodity_get_global_market_pool(c);
2856 auto last_demand = state.world.nation_get_real_demand(n, c);
2857 auto base_price = state.world.commodity_get_current_price(c);
2858 if(last_demand <= domestic_supply) {
2859 state.world.nation_set_effective_prices(n, c, base_price);
2860 }
else if(last_demand <= domestic_supply + global_supply) {
2861 auto domestic_satisfiable_fraction = domestic_supply / last_demand;
2862 state.world.nation_set_effective_prices(n, c, base_price * domestic_satisfiable_fraction +
2863 base_price * (1.0f - domestic_satisfiable_fraction) * global_price_multiplier);
2864 }
else if(domestic_supply + global_supply > 0) {
2865 auto domestic_satisfiable_fraction = domestic_supply / (domestic_supply + global_supply);
2866 state.world.nation_set_effective_prices(n, c, base_price * domestic_satisfiable_fraction +
2867 base_price * (1.0f - domestic_satisfiable_fraction) * global_price_multiplier);
2869 state.world.nation_set_effective_prices(n, c, base_price * global_price_multiplier);
2871 assert(std::isfinite(state.world.nation_get_effective_prices(n, c)));
2874 state.world.for_each_commodity([&](dcon::commodity_id c) {
2875 auto domestic_supply =
2876 state.world.nation_get_domestic_market_pool(n, c) + (sl ? state.world.nation_get_domestic_market_pool(sl, c) : 0.0f) +
2877 (state.world.nation_get_drawing_on_stockpiles(n, c) ? state.world.nation_get_stockpiles(n, c) : 0.0f);
2878 auto global_supply = state.world.commodity_get_global_market_pool(c);
2879 auto last_demand = state.world.nation_get_real_demand(n, c);
2880 auto base_price = state.world.commodity_get_current_price(c);
2881 if(last_demand <= global_supply) {
2882 state.world.nation_set_effective_prices(n, c, base_price);
2883 }
else if(last_demand <= domestic_supply + global_supply) {
2884 auto global_satisfiable_fraction = global_supply / last_demand;
2885 state.world.nation_set_effective_prices(n, c, base_price * global_satisfiable_fraction * global_price_multiplier +
2886 base_price * (1.0f - global_satisfiable_fraction));
2887 }
else if(domestic_supply + global_supply > 0) {
2888 auto global_satisfiable_fraction = global_supply / (domestic_supply + global_supply);
2889 state.world.nation_set_effective_prices(n, c, base_price * global_satisfiable_fraction * global_price_multiplier +
2890 base_price * (1.0f - global_satisfiable_fraction));
2892 state.world.nation_set_effective_prices(n, c, base_price);
2894 assert(std::isfinite(state.world.nation_get_effective_prices(n, c)));
2906 float total_min_to_pworkers =
2907 min_wage * state.world.state_instance_get_demographics(s,
2909 float total_min_to_sworkers =
2910 min_wage * state.world.state_instance_get_demographics(s,
2913 float num_pworkers = state.world.state_instance_get_demographics(s,
2915 float num_sworkers = state.world.state_instance_get_demographics(s,
2917 float num_owners = state.world.state_instance_get_demographics(s,
2920 auto per_pworker_profit = 0.0f;
2921 auto per_sworker_profit = 0.0f;
2922 auto per_owner_profit = 0.0f;
2924 if(total_min_to_pworkers + total_min_to_sworkers <= total_profit && num_owners > 0) {
2925 auto surplus = total_profit - (total_min_to_pworkers + total_min_to_sworkers);
2926 per_pworker_profit = num_pworkers > 0 ? (total_min_to_pworkers + surplus * 0.1f) / num_pworkers : 0.0f;
2927 per_sworker_profit = num_sworkers > 0 ? (total_min_to_sworkers + surplus * 0.2f) / num_sworkers : 0.0f;
2928 per_owner_profit = (surplus * 0.7f) / num_owners;
2929 }
else if(total_min_to_pworkers + total_min_to_sworkers <= total_profit && num_sworkers > 0) {
2930 auto surplus = total_profit - (total_min_to_pworkers + total_min_to_sworkers);
2931 per_pworker_profit = num_pworkers > 0 ? (total_min_to_pworkers + surplus * 0.5f) / num_pworkers : 0.0f;
2932 per_sworker_profit = num_sworkers > 0 ? (total_min_to_sworkers + surplus * 0.5f) / num_sworkers : 0.0f;
2933 }
else if(total_min_to_pworkers + total_min_to_sworkers <= total_profit) {
2934 per_pworker_profit = num_pworkers > 0 ? total_profit / num_pworkers : 0.0f;
2935 }
else if(num_pworkers + num_sworkers > 0) {
2936 per_pworker_profit = total_profit / (num_pworkers + num_sworkers);
2937 per_sworker_profit = total_profit / (num_pworkers + num_sworkers);
2942 .per_primary_worker = per_pworker_profit,
2943 .per_secondary_worker = per_sworker_profit,
2944 .per_owner = per_owner_profit
2951 state.world.nation_get_total_rich_income(n)
2952 + state.world.nation_get_total_middle_income(n)
2953 + state.world.nation_get_total_poor_income(n) * 0.00001f;
2959 float income_to_build_units = base_income * 0.1f;
2962 auto infantry = state.military_definitions.infantry;
2963 auto artillery = state.military_definitions.artillery;
2965 auto& infantry_def = state.military_definitions.unit_base_definitions[infantry];
2966 auto& artillery_def = state.military_definitions.unit_base_definitions[artillery];
2968 float daily_cost = 0.f;
2970 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2971 if(infantry_def.build_cost.commodity_type[i]) {
2972 auto price = state.world.commodity_get_current_price(infantry_def.build_cost.commodity_type[i]);
2973 daily_cost += infantry_def.build_cost.commodity_amounts[i] / infantry_def.build_time * price;
2978 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2979 if(infantry_def.build_cost.commodity_type[i]) {
2980 auto price = state.world.commodity_get_current_price(artillery_def.build_cost.commodity_type[i]);
2981 daily_cost += artillery_def.build_cost.commodity_amounts[i] / artillery_def.build_time * price;
2987 auto pairs_to_build = income_to_build_units / (daily_cost + 1.f);
2989 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2990 if(infantry_def.build_cost.commodity_type[i]) {
2991 auto daily_amount = infantry_def.build_cost.commodity_amounts[i] / infantry_def.build_time;
2992 register_demand(state, n, infantry_def.build_cost.commodity_type[i], daily_amount * pairs_to_build, economy_reason::construction);
2997 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2998 if(artillery_def.build_cost.commodity_type[i]) {
2999 auto daily_amount = artillery_def.build_cost.commodity_amounts[i] / artillery_def.build_time;
3000 register_demand(state, n, artillery_def.build_cost.commodity_type[i], daily_amount * pairs_to_build, economy_reason::construction);
3010 float income_to_build_factories = base_income * 0.1f;
3014 std::vector<float> per_commodity;
3015 per_commodity.resize(state.world.commodity_size() + 2);
3017 float sum_of_build_times = 0.f;
3018 float cost_factory_set = 0.f;
3021 state.world.for_each_factory_type([&](dcon::factory_type_id factory_type) {
3022 if(!state.world.factory_type_get_is_available_from_start(factory_type)) {
3026 auto build_time = state.world.factory_type_get_construction_time(factory_type);
3027 auto& build_cost = state.world.factory_type_get_construction_costs(factory_type);
3029 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3030 if(build_cost.commodity_type[i]) {
3031 auto price = state.world.commodity_get_current_price(build_cost.commodity_type[i]);
3032 cost_factory_set += price * build_cost.commodity_amounts[i] / build_time;
3042 auto num_of_factory_sets = income_to_build_factories / (cost_factory_set + 1.f);
3045 state.world.for_each_factory_type([&](dcon::factory_type_id factory_type) {
3046 if(!state.world.factory_type_get_is_available_from_start(factory_type)) {
3050 auto build_time =
state.world.factory_type_get_construction_time(factory_type);
3051 auto& build_cost =
state.world.factory_type_get_construction_costs(factory_type);
3053 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3054 if(build_cost.commodity_type[i]) {
3055 auto amount = build_cost.commodity_amounts[i];
3059 build_cost.commodity_type[i], amount / build_time * num_of_factory_sets,
3060 economy_reason::construction
3074 concurrency::parallel_for(0, 10, [&](int32_t index) {
3092 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
3093 state.world.execute_serial_over_nation([&](
auto nids) {
3094 state.world.nation_set_everyday_needs_costs(nids, t, ve::fp_vector{});
3099 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
3100 state.world.execute_serial_over_nation([&](
auto nids) {
3101 state.world.nation_set_luxury_needs_costs(nids, t, ve::fp_vector{});
3106 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
3107 state.world.execute_serial_over_nation([&](
auto nids) {
3108 state.world.nation_set_life_needs_costs(nids, t, ve::fp_vector{});
3113 state.world.execute_serial_over_nation([&](
auto ids) {
3114 state.world.nation_set_subsidies_spending(ids, 0.0f);
3118 state.world.execute_serial_over_nation([&](
auto ids) {
3119 auto treasury = state.world.nation_get_stockpiles(ids,
economy::money);
3120 state.world.nation_set_last_treasury(ids, treasury);
3128 auto const num_nation = state.world.nation_size();
3129 uint32_t total_commodities = state.world.commodity_size();
3145 state.world.for_each_commodity([&](dcon::commodity_id c) {
3146 state.world.commodity_set_demand_by_category(c, i, 0.f);
3151 for(
auto n : state.nations_by_rank) {
3156 for(
auto n : state.nations_by_rank) {
3162 for(
auto n : state.nations_by_rank) {
3167 state.world.nation_set_gdp(n, 0.f);
3184 auto sl = state.world.nation_get_in_sphere_of(n);
3187 state.defines.base_goods_demand + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::goods_demand);
3189 int32_t num_inventions = 0;
3190 state.world.for_each_invention(
3191 [&](
auto iid) { num_inventions += int32_t(state.world.nation_get_active_inventions(n, iid)); });
3192 float invention_factor = float(num_inventions) * state.defines.invention_impact_on_demand + 1.0f;
3200 float artisan_min_wage = (
3201 1.0f * state.world.nation_get_life_needs_costs(n, state.culture_definitions.artisans)
3202 + 0.5f * state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.artisans));
3207 state.world.for_each_commodity([&](dcon::commodity_id c) {
3208 state.world.nation_set_real_demand(n, c, 0.0f);
3209 state.world.nation_set_intermediate_demand(n, c, 0.f);
3215 auto cap_prov = state.world.nation_get_capital(n);
3216 auto cap_continent = state.world.province_get_continent(cap_prov);
3217 auto cap_region = state.world.province_get_connected_region_id(cap_prov);
3221 for(
auto p : state.world.nation_get_province_ownership(n)) {
3222 for(
auto f : state.world.province_get_factory_location(p.get_province())) {
3230 p.get_province().get_state_membership(),
3231 mobilization_impact,
3233 p.get_province().get_nation_from_province_control() != n
3238 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p.get_province()));
3240 is_mine ? laborer_min_wage : farmer_min_wage, p.get_province().get_nation_from_province_control() != n);
3252 float budget = 0.0f;
3253 float spending_scale = 0.0f;
3254 if(state.world.nation_get_is_player_controlled(n)) {
3260 spending_scale = 1.0f;
3262 budget = std::max(0.0f, state.world.nation_get_stockpiles(n,
economy::money));
3263 spending_scale = (total < 0.001f || total <= budget) ? 1.0f : budget / total;
3266 budget = std::max(0.0f, state.world.nation_get_stockpiles(n,
economy::money));
3267 spending_scale = (total < 0.001f || total <= budget) ? 1.0f : budget / total;
3270 assert(spending_scale >= 0);
3271 assert(std::isfinite(spending_scale));
3272 assert(std::isfinite(budget));
3274 state.world.nation_get_stockpiles(n,
economy::money) -= std::min(budget, total * spending_scale);
3275 state.world.nation_set_spending_level(n, spending_scale);
3278 float pi_budget = state.world.nation_get_private_investment(n);
3279 auto pi_scale = pi_total <= pi_budget ? 1.0f : pi_budget / pi_total;
3280 state.world.nation_set_private_investment_effective_fraction(n, pi_scale);
3281 state.world.nation_set_private_investment(n, std::max(0.0f, pi_budget - pi_total));
3290 for(
uint32_t i = 1; i < total_commodities; ++i) {
3291 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
3293 auto dom_pool = state.world.nation_get_domestic_market_pool(n, c);
3294 auto sl_pool = (sl ? state.world.nation_get_domestic_market_pool(sl, c) : 0.0f);
3295 auto sp_pool = (state.world.nation_get_drawing_on_stockpiles(n, c) ? state.world.nation_get_stockpiles(n, c) : 0.0f);
3296 auto wm_pool = state.world.commodity_get_global_market_pool(c);
3298 auto total_supply = dom_pool + sl_pool + sp_pool + wm_pool;
3300 auto rd = state.world.nation_get_real_demand(n, c);
3301 auto old_sat = state.world.nation_get_demand_satisfaction(n, c);
3302 auto new_sat = rd > 0.0001f ? total_supply / rd : total_supply;
3303 auto adj_sat = old_sat * state.defines.alice_sat_delay_factor + new_sat * (1.0f - state.defines.alice_sat_delay_factor);
3304 state.world.nation_set_demand_satisfaction(n, c, std::min(1.0f, adj_sat));
3305 state.world.nation_set_direct_demand_satisfaction(n, c, std::min(1.0f, new_sat));
3307 if(global_price_multiplier >= 1.0f) {
3308 state.world.nation_set_domestic_market_pool(n, c, std::max(0.0f, dom_pool - rd));
3309 rd = std::max(rd - dom_pool, 0.0f);
3311 state.world.nation_set_domestic_market_pool(sl, c, std::max(0.0f, sl_pool - rd));
3312 rd = std::max(rd - sl_pool, 0.0f);
3314 if(state.world.nation_get_drawing_on_stockpiles(n, c)) {
3315 state.world.nation_set_stockpiles(n, c, std::max(0.0f, sp_pool - rd));
3316 rd = std::max(rd - sp_pool, 0.0f);
3318 state.world.commodity_set_global_market_pool(c, std::max(0.0f, wm_pool - rd));
3320 state.world.nation_set_imports(n, c, std::min(wm_pool, rd));
3322 state.world.nation_set_imports(n, c, std::min(wm_pool, rd));
3324 state.world.commodity_set_global_market_pool(c, std::max(0.0f, wm_pool - rd));
3325 rd = std::max(rd - wm_pool, 0.0f);
3327 state.world.nation_set_domestic_market_pool(n, c, std::max(0.0f, dom_pool - rd));
3328 rd = std::max(rd - dom_pool, 0.0f);
3330 state.world.nation_set_domestic_market_pool(sl, c, std::max(0.0f, sl_pool - rd));
3331 rd = std::max(rd - sl_pool, 0.0f);
3333 if(state.world.nation_get_drawing_on_stockpiles(n, c)) {
3334 state.world.nation_set_stockpiles(n, c, std::max(0.0f, sp_pool - rd));
3343 state.world.for_each_commodity([&](dcon::commodity_id c) {
3346 float world_pool = state.world.commodity_get_global_market_pool(c) * decay;
3348 state.world.execute_serial_over_nation([&](
auto nids) {
3349 sum = sum + state.world.nation_get_domestic_market_pool(nids, c);
3350 state.world.nation_set_domestic_market_pool(nids, c, 0.0f);
3352 state.world.commodity_set_global_market_pool(c, world_pool + sum.reduce());
3359 state.world.execute_parallel_over_pop([&](
auto ids) {
3361 auto owner_spending = state.world.nation_get_spending_level(owners);
3363 auto pop_of_type = state.world.pop_get_size(ids);
3364 auto adj_pop_of_type = pop_of_type / state.defines.alice_needs_scaling_factor;
3366 auto const a_spending = owner_spending *
ve::to_float(state.world.nation_get_administrative_spending(owners)) *
ve::to_float(state.world.nation_get_administrative_spending(owners)) / 100.0f / 100.f;
3367 auto const s_spending = owner_spending * state.world.nation_get_administrative_efficiency(owners) *
3368 ve::to_float(state.world.nation_get_social_spending(owners)) / 100.0f;
3369 auto const e_spending = owner_spending *
ve::to_float(state.world.nation_get_education_spending(owners)) *
ve::to_float(state.world.nation_get_education_spending(owners)) / 100.0f / 100.f;
3370 auto const m_spending = owner_spending *
ve::to_float(state.world.nation_get_military_spending(owners)) *
ve::to_float(state.world.nation_get_military_spending(owners)) / 100.0f / 100.0f;
3371 auto const p_level = state.world.nation_get_modifier_values(owners, sys::national_mod_offsets::pension_level);
3372 auto const unemp_level = state.world.nation_get_modifier_values(owners, sys::national_mod_offsets::unemployment_benefit);
3373 auto const di_level = owner_spending *
ve::to_float(state.world.nation_get_domestic_investment_spending(owners)) *
ve::to_float(state.world.nation_get_domestic_investment_spending(owners)) / 100.0f / 100.f;
3375 auto types = state.world.pop_get_poptype(ids);
3377 auto ln_types = state.world.pop_type_get_life_needs_income_type(types);
3378 auto en_types = state.world.pop_type_get_everyday_needs_income_type(types);
3379 auto lx_types = state.world.pop_type_get_luxury_needs_income_type(types);
3381 auto ln_costs = ve::apply(
3382 [&](dcon::pop_type_id pt, dcon::nation_id n) {
return pt ? state.world.nation_get_life_needs_costs(n, pt) : 0.0f; },
3384 auto en_costs = ve::apply(
3385 [&](dcon::pop_type_id pt, dcon::nation_id n) {
return pt ? state.world.nation_get_everyday_needs_costs(n, pt) : 0.0f; },
3387 auto lx_costs = ve::apply(
3388 [&](dcon::pop_type_id pt, dcon::nation_id n) {
return pt ? state.world.nation_get_luxury_needs_costs(n, pt) : 0.0f; },
3400 auto acc_u =
ve::select(none_of_above, s_spending * adj_pop_of_type * p_level * ln_costs, 0.0f);
3406 acc_u = acc_u +
ve::select(types == state.culture_definitions.capitalists, di_level * adj_pop_of_type * state.defines.alice_domestic_investment_multiplier * lx_costs, 0.0f);
3407 acc_u = acc_u +
ve::select(types == state.culture_definitions.aristocrat, di_level * adj_pop_of_type * state.defines.alice_domestic_investment_multiplier * lx_costs, 0.0f);
3415 acc_u = acc_u +
ve::select(none_of_above && state.world.pop_type_get_has_unemployment(types),
3416 s_spending * (pop_of_type - employment) / state.defines.alice_needs_scaling_factor * unemp_level * ln_costs, 0.0f);
3418 state.world.pop_set_savings(ids, state.inflation * ((acc_e + acc_m) + (acc_u + acc_a)));
3420 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_e);
3421 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_m);
3422 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_u);
3423 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_a);
3428 concurrency::parallel_for(
uint32_t(0), state.world.nation_size(), [&](
uint32_t i) {
3429 auto n = dcon::nation_id{ dcon::nation_id::value_base_t(i) };
3431 if(state.world.nation_get_owned_province_count(n) == 0)
3435 ve::vectorizable_buffer<float, dcon::pop_type_id> ln_max = state.world.pop_type_make_vectorizable_float_buffer();
3436 ve::vectorizable_buffer<float, dcon::pop_type_id> en_max = state.world.pop_type_make_vectorizable_float_buffer();
3437 ve::vectorizable_buffer<float, dcon::pop_type_id> lx_max = state.world.pop_type_make_vectorizable_float_buffer();
3438 uint32_t total_commodities = state.world.commodity_size();
3439 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
3440 float ln_total = 0.0f;
3441 float en_total = 0.0f;
3442 float lx_total = 0.0f;
3443 for(uint32_t i = 1; i < total_commodities; ++i) {
3444 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
3445 auto kf = state.world.commodity_get_key_factory(c);
3446 if(state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf))) {
3447 auto sat = state.world.nation_get_demand_satisfaction(n, c);
3449 auto ln_val = state.world.pop_type_get_life_needs(pt, c) * state.world.nation_get_life_needs_weights(n, c);
3451 ln_max.get(pt) += ln_val * sat;
3453 auto en_val = state.world.pop_type_get_everyday_needs(pt, c) * state.world.nation_get_everyday_needs_weights(n, c);
3455 en_max.get(pt) += en_val * sat;
3457 auto lx_val = state.world.pop_type_get_luxury_needs(pt, c) * state.world.nation_get_luxury_needs_weights(n, c);
3459 lx_max.get(pt) += lx_val * sat;
3464 ln_max.get(pt) /= ln_total;
3466 ln_max.get(pt) = 1.f;
3469 en_max.get(pt) /= en_total;
3471 en_max.get(pt) = 1.f;
3474 lx_max.get(pt) /= lx_total;
3476 lx_max.get(pt) = 1.f;
3482 auto nations_commodity_spending = state.world.nation_get_spending_level(n);
3483 float refund = 0.0f;
3485 float max_sp = 0.0f;
3487 float spending_level = float(state.world.nation_get_naval_spending(n)) / 100.0f;
3488 for(
uint32_t k = 1; k < total_commodities; ++k) {
3489 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
3491 auto sat =
state.world.nation_get_demand_satisfaction(n, c);
3492 auto val =
state.world.nation_get_navy_demand(n, c);
3493 auto delta =
val * (1.0f - sat) * nations_commodity_spending * spending_level *
state.world.commodity_get_current_price(c);
3497 max_sp +=
val * sat;
3501 state.world.nation_set_effective_naval_spending(n, nations_commodity_spending * max_sp * spending_level);
3504 float max_sp = 0.0f;
3506 float spending_level = float(
state.world.nation_get_land_spending(n)) / 100.0f;
3507 for(
uint32_t k = 1; k < total_commodities; ++k) {
3508 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
3510 auto sat =
state.world.nation_get_demand_satisfaction(n, c);
3511 auto val =
state.world.nation_get_army_demand(n, c);
3512 auto delta =
val * (1.0f - sat) * nations_commodity_spending * spending_level *
state.world.commodity_get_current_price(c);
3516 max_sp +=
val * sat;
3520 state.world.nation_set_effective_land_spending(n, nations_commodity_spending * max_sp * spending_level);
3523 float max_sp = 0.0f;
3525 float spending_level = float(
state.world.nation_get_construction_spending(n)) / 100.0f;
3526 for(
uint32_t k = 1; k < total_commodities; ++k) {
3527 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
3529 auto sat =
state.world.nation_get_demand_satisfaction(n, c);
3530 auto val =
state.world.nation_get_construction_demand(n, c);
3532 max_sp +=
val * sat;
3536 state.world.nation_set_effective_construction_spending(n, nations_commodity_spending * max_sp * spending_level);
3542 for(
uint32_t k = 1; k < total_commodities; ++k) {
3543 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
3544 auto difference =
state.world.nation_get_stockpile_targets(n, c) -
state.world.nation_get_stockpiles(n, c);
3545 if(difference > 0.f &&
state.world.nation_get_drawing_on_stockpiles(n, c) ==
false) {
3546 auto sat =
state.world.nation_get_direct_demand_satisfaction(n, c);
3547 state.world.nation_get_stockpiles(n, c) += difference * nations_commodity_spending * sat;
3551 * nations_commodity_spending
3552 *
state.world.commodity_get_current_price(c);
3563 auto overseas_factor =
state.defines.province_overseas_penalty * float(
state.world.nation_get_owned_province_count(n) -
state.world.nation_get_central_province_count(n));
3564 auto overseas_budget = float(
state.world.nation_get_overseas_spending(n)) / 100.f;
3565 auto overseas_budget_satisfaction = 1.f;
3567 if(overseas_factor > 0) {
3568 for(
uint32_t k = 1; k < total_commodities; ++k) {
3569 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
3570 auto kf =
state.world.commodity_get_key_factory(c);
3571 if(
state.world.commodity_get_overseas_penalty(c) &&
3572 (
state.world.commodity_get_is_available_from_start(c) || (kf &&
state.world.nation_get_active_building(n, kf)))) {
3573 auto sat =
state.world.nation_get_demand_satisfaction(n, c);
3574 overseas_budget_satisfaction = std::min(sat, overseas_budget_satisfaction);
3575 auto price =
state.world.commodity_get_current_price(c);
3576 auto delta = overseas_factor * (1.0f - sat) * nations_commodity_spending * price;
3582 state.world.nation_set_overseas_penalty(n, overseas_budget * overseas_budget_satisfaction);
3584 state.world.nation_set_overseas_penalty(n, 1.0f);
3588 assert(std::isfinite(refund) && refund >= 0.0f);
3589 state.world.nation_get_stockpiles(n, money) += refund;
3599 for(
auto p :
state.world.nation_get_province_ownership(n)) {
3604 for(
auto f :
state.world.province_get_factory_location(p.get_province())) {
3618 float subsistence_life = std::clamp(subsistence, 0.f, subsistence_score_life);
3619 subsistence -= subsistence_life;
3620 float subsistence_everyday = std::clamp(subsistence, 0.f, subsistence_score_everyday);
3621 subsistence -= subsistence_everyday;
3622 float subsistence_luxury = std::clamp(subsistence, 0.f, subsistence_score_luxury);
3628 for(
auto pl : p.get_province().get_pop_location()) {
3629 auto t = pl.get_pop().get_poptype();
3637 ln -= subsistence_life;
3638 en -= subsistence_everyday;
3639 lx -= subsistence_luxury;
3641 ln = std::min(ln, ln_max.get(t));
3642 en = std::min(en, en_max.get(t));
3643 lx = std::min(lx, lx_max.get(t));
3645 ln += subsistence_life;
3646 en += subsistence_everyday;
3647 lx += subsistence_luxury;
3661 auto const artisan_type =
state.culture_definitions.artisans;
3662 float artisan_profit =
state.world.nation_get_artisan_profit(n);
3664 if(num_artisans > 0) {
3665 auto per_profit = artisan_profit / num_artisans;
3667 for(
auto p :
state.world.nation_get_province_ownership(n)) {
3668 for(
auto pl : p.get_province().get_pop_location()) {
3669 if(artisan_type == pl.get_pop().get_poptype()) {
3670 pl.get_pop().set_savings(pl.get_pop().get_savings() +
state.inflation * pl.get_pop().get_size() * per_profit);
3671 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
3682 for(
auto si :
state.world.nation_get_state_ownership(n)) {
3683 float total_profit = 0.f;
3684 float rgo_owner_profit = 0.f;
3686 float num_capitalist =
state.world.state_instance_get_demographics(
3691 float num_aristocrat =
state.world.state_instance_get_demographics(
3696 float num_rgo_owners = num_capitalist + num_aristocrat;
3698 auto capitalists_ratio = num_capitalist / (num_rgo_owners + 1.f);
3699 auto aristocrats_ratio = num_aristocrat / (num_rgo_owners + 1.f);
3702 for(auto f : state.world.province_get_factory_location(p)) {
3703 total_profit += std::max(0.f, f.get_factory().get_full_profit());
3708 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
3711 auto const min_wage = (is_mine ? laborer_min_wage : farmer_min_wage) / state.defines.alice_needs_scaling_factor;
3713 float total_min_to_workers = 0.0f;
3714 float num_workers = 0.0f;
3715 for(auto wt : state.culture_definitions.rgo_workers) {
3716 total_min_to_workers += min_wage * state.world.province_get_demographics(p, demographics::to_employment_key(state, wt));
3717 num_workers += state.world.province_get_demographics(p, demographics::to_key(state, wt));
3719 float total_rgo_profit =
state.world.province_get_rgo_full_profit(p);
3720 float total_worker_wage = 0.0f;
3722 if(num_rgo_owners > 0) {
3724 rgo_owner_profit += rgo_owners_cut * total_rgo_profit;
3725 total_rgo_profit = (1.f - rgo_owners_cut) * total_rgo_profit;
3728 if(total_min_to_workers <= total_rgo_profit && num_rgo_owners > 0) {
3729 total_worker_wage = total_min_to_workers + (total_rgo_profit - total_min_to_workers) * 0.2f;
3730 rgo_owner_profit += (total_rgo_profit - total_min_to_workers) * 0.8f;
3732 total_worker_wage = total_rgo_profit;
3735 auto per_worker_profit = num_workers > 0 ? total_worker_wage / num_workers : 0.0f;
3737 for(
auto pl :
state.world.province_get_pop_location(p)) {
3738 if(pl.get_pop().get_poptype().get_is_paid_rgo_worker()) {
3739 pl.get_pop().set_savings(pl.get_pop().get_savings() + state.inflation * pl.get_pop().get_size() * per_worker_profit);
3740 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
3746 auto const per_rgo_owner_profit = num_rgo_owners > 0 ? rgo_owner_profit / num_rgo_owners : 0.0f;
3748 auto const min_wage = factory_min_wage /
state.defines.alice_needs_scaling_factor;
3753 for(auto pl : state.world.province_get_pop_location(p)) {
3754 if(state.culture_definitions.primary_factory_worker == pl.get_pop().get_poptype()) {
3755 pl.get_pop().set_savings(pl.get_pop().get_savings() + state.inflation * pl.get_pop().get_size() * profit.per_primary_worker);
3756 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
3757 } else if(state.culture_definitions.secondary_factory_worker == pl.get_pop().get_poptype()) {
3758 pl.get_pop().set_savings(pl.get_pop().get_savings() + state.inflation * pl.get_pop().get_size() * profit.per_secondary_worker);
3759 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
3760 } else if(state.culture_definitions.capitalists == pl.get_pop().get_poptype()) {
3761 pl.get_pop().set_savings(pl.get_pop().get_savings() + state.inflation * pl.get_pop().get_size() * (profit.per_owner + per_rgo_owner_profit));
3762 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
3763 } else if(state.culture_definitions.aristocrat == pl.get_pop().get_poptype()) {
3764 pl.get_pop().set_savings(pl.get_pop().get_savings() + state.inflation * pl.get_pop().get_size() * per_rgo_owner_profit);
3765 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
3774 if(!initiate_buildings) {
3779 auto edu_money = 0.f;
3780 auto adm_money = 0.f;
3781 auto const edu_adm_spending = 0.05f;
3782 auto const edu_adm_effect = 1.f - edu_adm_spending;
3783 auto const education_ratio = 0.8f;
3784 for(
auto p :
state.world.nation_get_province_ownership(n)) {
3786 if(
state.world.province_get_nation_from_province_ownership(
province) ==
state.world.province_get_nation_from_province_control(
province)) {
3788 float local_teachers = 0.f;
3789 float local_managers = 0.f;
3790 for(
auto pl :
province.get_pop_location()) {
3791 auto pop = pl.get_pop();
3792 auto pt =
pop.get_poptype();
3795 local_managers +=
pop.get_size();
3797 local_teachers +=
pop.get_size();
3800 if(local_teachers + local_managers > 0.f) {
3801 for(
auto pl :
province.get_pop_location()) {
3802 auto const pop_money = pl.get_pop().get_savings();
3803 current += pop_money * edu_adm_spending;
3804 pl.get_pop().set_savings(pop_money * edu_adm_effect);
3807 float local_education_ratio = education_ratio;
3808 if(local_managers == 0.f) {
3809 local_education_ratio = 1.f;
3811 for(
auto pl :
province.get_pop_location()) {
3812 auto pop = pl.get_pop();
3813 auto pt =
pop.get_poptype();
3816 float ratio =
pop.get_size() / local_managers;
3817 pop.set_savings(
pop.get_savings() + current * (1.f - local_education_ratio) * ratio);
3818 adm_money +=
current * (1.f - local_education_ratio) * ratio;
3820 float ratio =
pop.get_size() / local_teachers;
3821 pop.set_savings(
pop.get_savings() +
current * local_education_ratio * ratio);
3822 edu_money +=
current * local_education_ratio * ratio;
3827 state.world.nation_set_private_investment_education(n, edu_money);
3828 state.world.nation_set_private_investment_administration(n, adm_money);
3836 float total_poor_tax_base = 0.0f;
3837 float total_mid_tax_base = 0.0f;
3838 float total_rich_tax_base = 0.0f;
3840 auto const poor_effect = (1.0f - tax_eff * float(
state.world.nation_get_poor_tax(n)) / 100.0f);
3841 auto const middle_effect = (1.0f - tax_eff * float(
state.world.nation_get_middle_tax(n)) / 100.0f);
3842 auto const rich_effect = (1.0f - tax_eff * float(
state.world.nation_get_rich_tax(n)) / 100.0f);
3844 assert(poor_effect >= 0 && middle_effect >= 0 && rich_effect >= 0);
3846 for(
auto p :
state.world.nation_get_province_ownership(n)) {
3848 if(
state.world.province_get_nation_from_province_ownership(
province) ==
state.world.province_get_nation_from_province_control(
province)) {
3849 for(
auto pl :
province.get_pop_location()) {
3850 auto& pop_money = pl.get_pop().get_savings();
3853 total_poor_tax_base += pop_money;
3854 pop_money *= poor_effect;
3856 total_mid_tax_base += pop_money;
3857 pop_money *= middle_effect;
3859 total_rich_tax_base += pop_money;
3860 pop_money *= rich_effect;
3866 state.world.nation_set_total_rich_income(n, total_rich_tax_base);
3867 state.world.nation_set_total_middle_income(n, total_mid_tax_base);
3868 state.world.nation_set_total_poor_income(n, total_poor_tax_base);
3869 auto collected_tax = total_poor_tax_base * tax_eff * float(
state.world.nation_get_poor_tax(n)) / 100.0f +
3870 total_mid_tax_base * tax_eff * float(
state.world.nation_get_middle_tax(n)) / 100.0f +
3871 total_rich_tax_base * tax_eff * float(
state.world.nation_get_rich_tax(n)) / 100.0f;
3872 assert(std::isfinite(collected_tax));
3873 assert(collected_tax >= 0);
3874 state.world.nation_get_stockpiles(n, money) += collected_tax;
3882 float t_total = 0.0f;
3884 for(
uint32_t k = 1; k < total_commodities; ++k) {
3885 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
3886 t_total +=
state.world.commodity_get_current_price(cid) * tariff_rate *
state.world.nation_get_imports(n, cid);
3888 assert(std::isfinite(t_total));
3890 state.world.nation_get_stockpiles(n, money) += t_total;
3902 state.world.for_each_commodity([&](dcon::commodity_id c) {
3903 if(!
state.world.commodity_get_money_rgo(c))
3906 float luxury_costs_laborer = 0.f;
3907 const float base_demand =
state.defines.base_goods_demand;
3909 for(
uint32_t i = 1; i < total_commodities; ++i) {
3910 dcon::commodity_id _cid{ dcon::commodity_id::value_base_t(i) };
3912 if(
state.world.commodity_get_is_available_from_start(_cid)) {
3913 float price =
state.world.commodity_get_current_price(_cid);
3914 auto t =
state.culture_definitions.laborers;
3916 float base_life =
state.world.pop_type_get_life_needs(t, _cid);
3917 float base_everyday = 0.5f *
state.world.pop_type_get_everyday_needs(t, _cid);
3918 float base_luxury = 0.1f *
state.world.pop_type_get_luxury_needs(t, _cid);
3920 luxury_costs_laborer += base_life * base_demand *
state.defines.alice_lf_needs_scale *
price;
3921 luxury_costs_laborer += base_everyday * base_demand *
state.defines.alice_ev_needs_scale *
price;
3922 luxury_costs_laborer += base_luxury * base_demand *
state.defines.alice_lx_needs_scale *
price;
3926 state.world.commodity_set_current_price(c, std::clamp(luxury_costs_laborer * 0.3f, 0.001f, 100000.0f));
3929 concurrency::parallel_for(
uint32_t(0), total_commodities, [&](
uint32_t k) {
3930 dcon::commodity_id cid{dcon::commodity_id::value_base_t(k)};
3933 if(
state.world.commodity_get_money_rgo(cid)) {
3937 float total_r_demand = 0.0f;
3938 float total_consumption = 0.0f;
3939 float total_production = 0.0f;
3941 state.world.for_each_nation([&](dcon::nation_id n) {
3942 total_r_demand +=
state.world.nation_get_real_demand(n, cid);
3943 total_consumption +=
state.world.nation_get_real_demand(n, cid) *
state.world.nation_get_demand_satisfaction(n, cid);
3944 total_production +=
state.world.nation_get_domestic_market_pool(n, cid);
3947 state.world.commodity_set_total_consumption(cid, total_consumption);
3948 state.world.commodity_set_total_real_demand(cid, total_r_demand);
3950 auto prior_production =
state.world.commodity_get_total_production(cid);
3951 state.world.commodity_set_total_production(cid, total_production);
3953 float supply = prior_production +
state.world.commodity_get_global_market_pool(cid) / 12.f;
3954 float demand = total_r_demand;
3956 auto base_price =
state.world.commodity_get_cost(cid);
3957 auto current_price =
state.world.commodity_get_current_price(cid);
3959 float market_balance = demand -
supply;
3960 float max_slope =
math::sqrt(abs(market_balance)) + 20.f;
3962 float oversupply_factor = std::clamp(((supply + 0.001f) / (demand + 0.001f) - 1.f), 0.f, max_slope);
3963 float overdemand_factor = std::clamp(((demand + 0.001f) / (supply + 0.001f) - 1.f), 0.f, max_slope);
3965 float speed_modifer = (overdemand_factor - oversupply_factor);
3967 float price_speed = 0.05f * speed_modifer;
3969 if(current_price < 1.f) {
3970 price_speed *= current_price;
3975 current_price += price_speed;
3977 state.world.commodity_set_current_price(cid, std::clamp(current_price, 0.001f, 100000.0f));
3980 if(
state.cheat_data.ecodump) {
3981 float accumulator[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
3982 state.world.for_each_commodity([&](dcon::commodity_id c) {
3983 state.cheat_data.prices_dump_buffer += std::to_string(
state.world.commodity_get_current_price(c)) +
",";
3984 state.cheat_data.supply_dump_buffer += std::to_string(
state.world.commodity_get_total_production(c)) +
",";
3985 state.cheat_data.demand_dump_buffer += std::to_string(
state.world.commodity_get_total_real_demand(c)) +
",";
3986 for(
int i = 0; i < 8; i++) {
3987 accumulator[i] +=
state.world.commodity_get_demand_by_category(c, i);
3990 for(
int i = 0; i < 8; i++) {
3991 state.cheat_data.demand_by_category_dump_buffer += std::to_string(accumulator[i]) +
",";
3993 state.cheat_data.demand_by_category_dump_buffer +=
"\n";
3995 state.cheat_data.prices_dump_buffer +=
"\n";
3996 state.cheat_data.supply_dump_buffer +=
"\n";
3997 state.cheat_data.demand_dump_buffer +=
"\n";
4027 for(
auto n :
state.world.in_nation) {
4028 for(
auto uni :
n.get_unilateral_relationship_as_source()) {
4029 if(uni.get_war_subsidies()) {
4030 auto target_m_costs = uni.get_target().get_maximum_military_costs() *
state.defines.warsubsidies_percent;
4031 if(target_m_costs <=
n.get_stockpiles(money)) {
4032 n.get_stockpiles(money) -= target_m_costs;
4033 uni.get_target().get_stockpiles(money) += target_m_costs;
4035 uni.set_war_subsidies(
false);
4041 "msg_wsub_end_title",
4042 n.id, uni.get_target().id, dcon::nation_id{},
4047 if(uni.get_reparations() &&
state.current_date <
n.get_reparations_until()) {
4049 auto total_tax_base =
n.get_total_rich_income() +
n.get_total_middle_income() +
n.get_total_poor_income();
4051 auto payout = total_tax_base * tax_eff *
state.defines.reparations_tax_hit;
4052 auto capped_payout = std::min(
n.get_stockpiles(money), payout);
4053 assert(capped_payout >= 0.0f);
4055 n.get_stockpiles(money) -= capped_payout;
4056 uni.get_target().get_stockpiles(money) += capped_payout;
4064 for(
auto n :
state.world.in_nation) {
4065 auto m =
n.get_stockpiles(money);
4077 float primary_commodity_basket = 0.0f;
4078 state.world.for_each_commodity([&](dcon::commodity_id c) {
4079 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
4080 primary_commodity_basket += 2.0f *
state.world.commodity_get_cost(c) *
state.world.pop_type_get_life_needs(pt, c);
4081 primary_commodity_basket += 2.0f *
state.world.commodity_get_cost(c) *
state.world.pop_type_get_everyday_needs(pt, c);
4084 primary_commodity_basket /= float(
state.world.pop_type_size());
4087 float total_pop_money = 0.0f;
4089 state.world.for_each_nation([&](dcon::nation_id n) {
4091 total_pop_money +=
state.world.nation_get_total_rich_income(n) +
state.world.nation_get_total_middle_income(n) +
4092 state.world.nation_get_total_poor_income(n);
4095 float target_money =
total_pop * primary_commodity_basket /
state.defines.alice_needs_scaling_factor;
4101 if(total_pop_money > 0.001f) {
4102 state.inflation = (
state.inflation * 0.9f) + (0.1f * target_money / total_pop_money);
4108 if(initiate_buildings) {
4111 for(
auto n :
state.world.in_nation) {
4112 auto nation_rules =
n.get_combined_issue_rules();
4115 float total_cost = 0.f;
4117 for(
uint32_t i = 1; i < total_commodities; ++i) {
4118 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
4119 total_cost +=
state.world.nation_get_private_construction_demand(n, c) *
state.world.commodity_get_current_price(c);
4122 float total_cost_added = 0.f;
4124 if(
n.get_private_investment() > total_cost
4125 &&
n.get_is_civilized()
4128 static std::vector<dcon::factory_type_id> desired_types;
4129 desired_types.clear();
4131 static std::vector<dcon::state_instance_id> states_in_order;
4132 states_in_order.clear();
4133 for(
auto si :
n.get_state_ownership()) {
4134 if(si.get_state().get_capital().get_is_colonial() ==
false) {
4135 states_in_order.push_back(si.get_state().id);
4138 std::sort(states_in_order.begin(), states_in_order.end(), [&](dcon::state_instance_id a, dcon::state_instance_id b) {
4139 auto a_pop = state.world.state_instance_get_demographics(a, demographics::total);
4140 auto b_pop = state.world.state_instance_get_demographics(b, demographics::total);
4142 return a_pop > b_pop;
4143 return a.index() < b.index();
4153 for(
auto s : states_in_order) {
4154 auto pw_num =
state.world.state_instance_get_demographics(s,
4156 auto pw_employed =
state.world.state_instance_get_demographics(s,
4159 if(pw_employed >= pw_num && pw_num > 0.0f)
4162 int32_t num_factories = 0;
4164 dcon::factory_id selected_factory;
4167 auto d =
state.world.state_instance_get_definition(s);
4168 for(
auto p :
state.world.state_definition_get_abstract_state_membership(d)) {
4169 if(p.get_province().get_nation_from_province_ownership() == n) {
4170 for(
auto f : p.get_province().get_factory_location()) {
4175 && f.get_factory().get_production_scale() >= 0.9f
4176 && f.get_factory().get_primary_employment() >= 0.9f
4177 && f.get_factory().get_level() <
uint8_t(255)) {
4179 auto type = f.get_factory().get_building_type();
4180 auto ug_in_progress =
false;
4181 for(
auto c :
state.world.state_instance_get_state_building_construction(s)) {
4182 if(c.get_type() == type) {
4183 ug_in_progress =
true;
4188 if(ug_in_progress) {
4192 if(
auto new_p = f.get_factory().get_full_profit() / f.get_factory().get_level(); new_p > profit) {
4194 selected_factory = f.get_factory();
4200 if(selected_factory && profit > 0.f) {
4201 auto new_up =
fatten(
state.world,
state.world.force_create_state_building_construction(s, n));
4202 new_up.set_is_pop_project(
true);
4203 new_up.set_is_upgrade(
true);
4204 new_up.set_type(
state.world.factory_get_building_type(selected_factory));
4209 auto existing_constructions =
state.world.state_instance_get_state_building_construction(s);
4210 if(existing_constructions.begin() != existing_constructions.end())
4213 if(
n.get_private_investment() * 0.1f < total_cost + total_cost_added) {
4219 if(!desired_types.empty()) {
4220 auto selected = desired_types[
rng::get_random(state,
uint32_t((
n.id.index() << 6) ^ s.index())) % desired_types.size()];
4225 bool already_in_progress = [&]() {
4226 for(
auto p :
state.world.state_instance_get_state_building_construction(s)) {
4227 if(p.get_type() == selected)
4233 if(already_in_progress)
4237 bool present_in_location =
false;
4239 for(
auto fac :
state.world.province_get_factory_location(p)) {
4240 auto type = fac.get_factory().get_building_type();
4241 if(selected == type) {
4242 present_in_location = true;
4248 if(present_in_location)
4251 auto new_up =
fatten(
state.world,
state.world.force_create_state_building_construction(s, n));
4252 new_up.set_is_pop_project(
true);
4253 new_up.set_is_upgrade(
false);
4254 new_up.set_type(selected);
4256 auto costs = new_up.get_type().get_construction_costs();
4258 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4259 if(costs.commodity_type[i]) {
4260 total_cost_added +=
state.world.nation_get_effective_prices(n, costs.commodity_type[i]) * costs.commodity_amounts[i];
4272 static std::vector<std::pair<dcon::province_id, int32_t>> provinces_in_order;
4273 provinces_in_order.clear();
4274 for(
auto si :
n.get_state_ownership()) {
4275 if(si.get_state().get_capital().get_is_colonial() ==
false) {
4276 auto s = si.get_state().id;
4277 auto d =
state.world.state_instance_get_definition(s);
4278 int32_t num_factories = 0;
4279 for(
auto p :
state.world.state_definition_get_abstract_state_membership(d)) {
4281 p.get_province().get_nation_from_province_ownership() == n) {
4282 for(
auto f : p.get_province().get_factory_location())
4283 num_factories += int32_t(f.get_factory().get_level());
4284 provinces_in_order.emplace_back(p.get_province().id, num_factories);
4289 for(
auto p :
state.world.state_definition_get_abstract_state_membership(d)) {
4291 p.get_province().get_nation_from_province_ownership() == n)
4292 provinces_in_order.emplace_back(p.get_province().id, num_factories);
4296 if(!provinces_in_order.empty()) {
4297 std::pair<dcon::province_id, int32_t> best_p = provinces_in_order[0];
4298 for(
auto e : provinces_in_order)
4299 if(e.second > best_p.second)
4302 auto new_rr =
fatten(
state.world,
state.world.force_create_province_building_construction(best_p.first, n));
4303 new_rr.set_is_pop_project(
true);
4304 new_rr.set_type(
uint8_t(province_building_type::railroad));
4309 n.set_private_investment(0.0f);
4314 if(
state.cheat_data.ecodump) {
4315 for(
auto n :
state.world.in_nation) {
4317 state.world.nation_get_life_needs_costs(n,
state.culture_definitions.primary_factory_worker)
4318 +
state.world.nation_get_everyday_needs_costs(n,
state.culture_definitions.primary_factory_worker)
4319 +
state.world.nation_get_luxury_needs_costs(n,
state.culture_definitions.primary_factory_worker);
4322 state.cheat_data.national_economy_dump_buffer +=
4325 + std::to_string(
state.world.nation_get_gdp(n)) +
","
4326 + std::to_string(life_costs) +
","
4328 + std::to_string(
state.current_date.value) +
"\n";
4334 state.culture_definitions.rgo_workers.clear();
4335 for(
auto pt : state.world.in_pop_type) {
4336 if(pt.get_is_paid_rgo_worker())
4337 state.culture_definitions.rgo_workers.push_back(pt);
4340 auto const total_commodities = state.world.commodity_size();
4341 for(
uint32_t k = 1; k < total_commodities; ++k) {
4342 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
4343 for(
auto pt : state.world.in_pop_type) {
4344 if(pt != state.culture_definitions.slaves) {
4345 if(pt.get_life_needs(cid) > 0.0f)
4346 state.world.commodity_set_is_life_need(cid,
true);
4347 if(pt.get_everyday_needs(cid) > 0.0f)
4348 state.world.commodity_set_is_everyday_need(cid,
true);
4349 if(pt.get_luxury_needs(cid) > 0.0f)
4350 state.world.commodity_set_is_luxury_need(cid,
true);
4355 state.world.commodity_resize_demand_by_category(8);
4357 state.world.nation_resize_intermediate_demand(state.world.commodity_size());
4359 state.world.nation_resize_life_needs_costs(state.world.pop_type_size());
4360 state.world.nation_resize_everyday_needs_costs(state.world.pop_type_size());
4361 state.world.nation_resize_luxury_needs_costs(state.world.pop_type_size());
4363 state.world.province_resize_rgo_actual_production_per_good(state.world.commodity_size());
4365 state.world.for_each_commodity([&](dcon::commodity_id c) {
4366 auto fc = fatten(state.world, c);
4367 state.world.commodity_set_key_factory(c, dcon::factory_type_id{});
4368 if(fc.get_total_production() > 0.0001f) {
4369 fc.set_producer_payout_fraction(std::min(fc.get_total_consumption() / fc.get_total_production(), 1.0f));
4371 fc.set_producer_payout_fraction(1.0f);
4374 state.world.for_each_factory_type([&](dcon::factory_type_id t) {
4375 auto o = state.world.factory_type_get_output(t);
4377 state.world.commodity_set_key_factory(o, t);
4382 auto overseas_factor = state.defines.province_overseas_penalty *
4383 float(state.world.nation_get_owned_province_count(n) - state.world.nation_get_central_province_count(n));
4384 auto o_adjust = 0.0f;
4385 if(overseas_factor > 0) {
4386 auto kf = state.world.commodity_get_key_factory(c);
4387 if(state.world.commodity_get_overseas_penalty(c) &&
4388 (state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf)))) {
4389 o_adjust = overseas_factor;
4393 return (state.world.nation_get_army_demand(n, c) + state.world.nation_get_navy_demand(n, c) +
4394 state.world.nation_get_construction_demand(n, c) + o_adjust);
4399 auto& costs = fat.get_construction_costs();
4401 float factory_mod = state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::factory_cost) + 1.0f;
4402 float admin_eff = state.world.nation_get_administrative_efficiency(state.local_player_nation);
4403 float admin_cost_factor = (2.0f - admin_eff) * factory_mod;
4407 auto cid = costs.commodity_type[i];
4409 total += state.world.commodity_get_current_price(cid) * costs.commodity_amounts[i] * admin_cost_factor;
4416float factory_type_output_cost(
sys::state& state, dcon::nation_id n, dcon::factory_type_id factory_type) {
4417 auto fac_type =
dcon::fatten(state.world, factory_type);
4419 float total_production = fac_type.get_output_amount() * output_multiplier;
4421 return total_production * state.world.commodity_get_current_price(fac_type.get_output());
4424float factory_type_input_cost(
sys::state& state, dcon::nation_id n, dcon::factory_type_id factory_type) {
4425 auto fac_type =
dcon::fatten(state.world, factory_type);
4430 auto const maint_multiplier = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
4433 return input_total * input_multiplier + e_input_total * input_multiplier * maint_multiplier;
4438 for(
auto ownership : state.world.nation_get_province_ownership(n)) {
4439 for(
auto location : state.world.province_get_factory_location(ownership.get_province())) {
4441 auto f = state.world.factory_location_get_factory(location);
4442 auto p = ownership.get_province();
4443 auto s = p.get_state_membership();
4444 auto fac = fatten(state.world, f);
4445 auto fac_type = fac.get_building_type();
4448 float min_input_available = 1.f;
4449 float min_e_input_available = 1.f;
4458 float total_production = fac_type.get_output_amount()
4459 * (0.75f + 0.25f * min_e_input_available)
4460 * throughput_multiplier
4462 * min_input_available;
4464 float effective_production_scale = fac.get_production_scale();
4466 auto& inputs = fac_type.get_inputs();
4467 auto& e_inputs = fac_type.get_efficiency_inputs();
4476 * throughput_multiplier
4477 * effective_production_scale
4478 * (0.1f + min_input_available * 0.9f);
4480 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4481 if(inputs.commodity_type[i]) {
4482 if(inputs.commodity_type[i] == c) {
4484 +input_scale * inputs.commodity_amounts[i];
4495 auto const mfactor = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
4496 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
4497 if(e_inputs.commodity_type[i]) {
4498 if(e_inputs.commodity_type[i] == c) {
4502 * e_inputs.commodity_amounts[i]
4503 * (0.1f + min_e_input_available * 0.9f);
4517 auto kf = state.world.commodity_get_key_factory(c);
4518 if(state.world.commodity_get_is_available_from_start(c) || (kf && state.world.nation_get_active_building(n, kf))) {
4519 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
4520 amount += (state.world.pop_type_get_life_needs(pt, c) + state.world.pop_type_get_everyday_needs(pt, c) +
4521 state.world.pop_type_get_luxury_needs(pt, c)) *
4522 state.world.nation_get_demographics(n,
demographics::to_key(state, pt)) / state.defines.alice_needs_scaling_factor;
4529 float t_total = 0.0f;
4531 auto const total_commodities = state.world.commodity_size();
4532 for(
uint32_t k = 1; k < total_commodities; ++k) {
4533 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
4534 t_total += state.world.commodity_get_current_price(cid) * state.world.nation_get_imports(n, cid);
4541 auto saved = state.world.pop_get_savings(p);
4547 auto strata =
culture::pop_strata(state.world.pop_type_get_strata(state.world.pop_get_poptype(p)));
4551 return saved / std::max(0.0001f, (1.0f - tax_eff *
float(state.world.nation_get_poor_tax(owner)) / 100.0f));
4553 return saved / std::max(0.0001f, (1.0f - tax_eff *
float(state.world.nation_get_middle_tax(owner)) / 100.0f));
4555 return saved / std::max(0.0001f, (1.0f - tax_eff *
float(state.world.nation_get_rich_tax(owner)) / 100.0f));
4561 for(
auto poid : state.world.nation_get_province_ownership_as_nation(n)) {
4562 auto prov = poid.get_province();
4564 state.world.for_each_commodity([&](dcon::commodity_id c) {
4565 if(state.world.commodity_get_money_rgo(c)) {
4566 amount += province::rgo_production_quantity(state, prov.id, c);
4570 return amount * state.defines.gold_to_cash_rate;
4579 auto const p_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::pension_level);
4580 auto const unemp_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::unemployment_benefit);
4582 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
4583 auto adj_pop_of_type =
4584 state.world.nation_get_demographics(n,
demographics::to_key(state, pt)) / state.defines.alice_needs_scaling_factor;
4586 if(adj_pop_of_type <= 0)
4593 total += adj_pop_of_type * p_level * state.world.nation_get_life_needs_costs(n, pt);
4594 if(state.world.pop_type_get_has_unemployment(pt)) {
4595 auto emp = state.world.nation_get_demographics(n, demographics::to_employment_key(state, pt)) / state.defines.alice_needs_scaling_factor;
4596 total += (adj_pop_of_type - emp) * unemp_level * state.world.nation_get_life_needs_costs(n, pt);
4605 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
4606 auto adj_pop_of_type =
4607 state.world.nation_get_demographics(n,
demographics::to_key(state, pt)) / state.defines.alice_needs_scaling_factor;
4609 if(adj_pop_of_type <= 0)
4614 total += adj_pop_of_type * state.world.nation_get_life_needs_costs(n, pt);
4619 total += adj_pop_of_type * state.world.nation_get_everyday_needs_costs(n, pt);
4624 total += adj_pop_of_type * state.world.nation_get_luxury_needs_costs(n, pt);
4643 return state.world.nation_get_subsidies_spending(n);
4649 for(
auto uni : state.world.nation_get_unilateral_relationship_as_target(n)) {
4650 if(uni.get_war_subsidies()) {
4651 total += uni.get_target().get_maximum_military_costs() * state.defines.warsubsidies_percent;
4656float estimate_reparations_income(
sys::state& state, dcon::nation_id n) {
4658 for(
auto uni : state.world.nation_get_unilateral_relationship_as_target(n)) {
4659 if(uni.get_reparations() && state.current_date < uni.get_source().get_reparations_until()) {
4660 auto source = uni.get_source();
4662 auto total_tax_base = state.world.nation_get_total_rich_income(source) +
4663 state.world.nation_get_total_middle_income(source) +
4664 state.world.nation_get_total_poor_income(source);
4665 auto payout = total_tax_base * tax_eff * state.defines.reparations_tax_hit;
4675 for(
auto uni : state.world.nation_get_unilateral_relationship_as_source(n)) {
4676 if(uni.get_war_subsidies()) {
4677 total += uni.get_target().get_maximum_military_costs() * state.defines.warsubsidies_percent;
4686 if(state.current_date < state.world.nation_get_reparations_until(n)) {
4687 for(
auto uni : state.world.nation_get_unilateral_relationship_as_source(n)) {
4688 if(uni.get_reparations()) {
4690 auto total_tax_base = state.world.nation_get_total_rich_income(n) +
4691 state.world.nation_get_total_middle_income(n) +
4692 state.world.nation_get_total_poor_income(n);
4693 auto payout = total_tax_base * tax_eff * state.defines.reparations_tax_hit;
4704 return w_sub + w_reps;
4708 auto adj_pop_of_type_capis = (state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.capitalists))) / state.defines.alice_needs_scaling_factor;
4709 auto adj_pop_of_type_arist = (state.world.nation_get_demographics(n,
demographics::to_key(state, state.culture_definitions.aristocrat))) / state.defines.alice_needs_scaling_factor;
4711 state.world.nation_get_life_needs_costs(n, state.culture_definitions.aristocrat)
4712 + state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.aristocrat)
4713 + state.world.nation_get_luxury_needs_costs(n, state.culture_definitions.aristocrat);
4715 state.world.nation_get_life_needs_costs(n, state.culture_definitions.capitalists)
4716 + state.world.nation_get_everyday_needs_costs(n, state.culture_definitions.capitalists)
4717 + state.world.nation_get_luxury_needs_costs(n, state.culture_definitions.capitalists);
4718 return state.defines.alice_domestic_investment_multiplier * (adj_pop_of_type_capis * capis_costs + adj_pop_of_type_arist * arist_costs);
4723 uint32_t total_commodities = state.world.commodity_size();
4724 for(
uint32_t i = 1; i < total_commodities; ++i) {
4725 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
4726 total += state.world.nation_get_army_demand(n, cid) * state.world.nation_get_effective_prices(n, cid) * state.world.nation_get_demand_satisfaction(n, cid);
4733 uint32_t total_commodities = state.world.commodity_size();
4734 for(
uint32_t i = 1; i < total_commodities; ++i) {
4735 dcon::commodity_id cid{dcon::commodity_id::value_base_t(i)};
4736 total += state.world.nation_get_navy_demand(n, cid) * state.world.nation_get_effective_prices(n, cid) * state.world.nation_get_demand_satisfaction(n, cid);
4743 float admin_eff = state.world.nation_get_administrative_efficiency(n);
4744 float admin_cost_factor = 2.0f - admin_eff;
4746 for(
auto lc : state.world.nation_get_province_land_construction(n)) {
4747 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
4748 if(state.world.province_get_nation_from_province_control(
province) == n) {
4750 auto& base_cost = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(lc)].build_cost;
4751 auto& current_purchased = state.world.province_land_construction_get_purchased_goods(lc);
4754 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4755 if(base_cost.commodity_type[i]) {
4756 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor)
4757 total += state.world.nation_get_effective_prices(n, base_cost.commodity_type[i]) * state.world.nation_get_demand_satisfaction(n, base_cost.commodity_type[i]) * base_cost.commodity_amounts[i] / construction_time;
4765 for(
auto po : state.world.nation_get_province_ownership(n)) {
4766 auto p = po.get_province();
4767 if(state.world.province_get_nation_from_province_control(p) != n)
4770 auto rng = state.world.province_get_province_naval_construction(p);
4771 if(
rng.begin() !=
rng.end()) {
4772 auto c = *(
rng.begin());
4773 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
4774 auto& current_purchased = c.get_purchased_goods();
4777 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4778 if(base_cost.commodity_type[i]) {
4779 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor)
4780 total += state.world.nation_get_effective_prices(n, base_cost.commodity_type[i]) * state.world.nation_get_demand_satisfaction(n, base_cost.commodity_type[i]) * base_cost.commodity_amounts[i] / construction_time;
4788 for(
auto c : state.world.nation_get_province_building_construction(n)) {
4789 if(n == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
4791 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
4792 auto& current_purchased = c.get_purchased_goods();
4795 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4796 if(base_cost.commodity_type[i]) {
4797 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor)
4798 total += state.world.nation_get_effective_prices(n, base_cost.commodity_type[i]) * state.world.nation_get_demand_satisfaction(n, base_cost.commodity_type[i]) * base_cost.commodity_amounts[i] / construction_time;
4806 float factory_mod = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f;
4808 for(
auto c : state.world.nation_get_state_building_construction(n)) {
4809 if(!c.get_is_pop_project()) {
4810 auto& base_cost = c.get_type().get_construction_costs();
4811 auto& current_purchased = c.get_purchased_goods();
4814 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4815 if(base_cost.commodity_type[i]) {
4816 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod * admin_cost_factor)
4817 total += state.world.nation_get_effective_prices(n, base_cost.commodity_type[i]) * state.world.nation_get_demand_satisfaction(n, base_cost.commodity_type[i]) * base_cost.commodity_amounts[i] * factory_mod / construction_time;
4830 return state.world.nation_get_maximum_military_costs(n) * state.defines.warsubsidies_percent;
4834 for(
auto pb_con : state.world.province_get_province_building_construction(p)) {
4835 if(pb_con.get_type() ==
uint8_t(t)) {
4836 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_get_nation_from_province_ownership(p));
4837 float admin_cost_factor = pb_con.get_is_pop_project() ? 1.0f : 2.0f - admin_eff;
4840 float purchased = 0.0f;
4841 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4842 total += state.economy_definitions.building_definitions[int32_t(t)].cost.commodity_amounts[i] * admin_cost_factor;
4843 purchased += pb_con.get_purchased_goods().commodity_amounts[i];
4852 auto in_prov = state.world.factory_get_province_from_factory_location(f);
4853 auto in_state = state.world.province_get_state_membership(in_prov);
4854 auto fac_type = state.world.factory_get_building_type(f);
4856 for(
auto st_con : state.world.state_instance_get_state_building_construction(in_state)) {
4857 if(st_con.get_type() == fac_type) {
4858 float admin_eff = state.world.nation_get_administrative_efficiency(st_con.get_nation());
4859 float factory_mod = state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_cost) + 1.0f;
4860 float pop_factory_mod = std::max(0.1f, state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_owner_cost));
4861 float admin_cost_factor = (st_con.get_is_pop_project() ? pop_factory_mod : (2.0f - admin_eff)) * factory_mod;
4865 float purchased = 0.0f;
4866 auto& goods = state.world.factory_type_get_construction_costs(fac_type);
4868 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4869 total += goods.commodity_amounts[i] * admin_cost_factor;
4870 purchased += st_con.get_purchased_goods().commodity_amounts[i];
4881 auto d = state.world.state_instance_get_definition(s);
4882 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
4883 if(p.get_province().get_state_membership() == s) {
4884 for(
auto f : p.get_province().get_factory_location()) {
4885 if(f.get_factory().get_building_type() == ft)
4894 auto d = state.world.state_instance_get_definition(s);
4896 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
4897 if(p.get_province().get_state_membership() == s) {
4898 for(
auto f : p.get_province().get_factory_location()) {
4899 if(f.get_factory().get_building_type() == ft)
4904 for(
auto sc : state.world.state_instance_get_state_building_construction(s)) {
4905 if(sc.get_type() == ft)
4913 int32_t num_factories = 0;
4914 auto d = state.world.state_instance_get_definition(sid);
4915 for(
auto p : state.world.state_definition_get_abstract_state_membership(d))
4916 if(p.get_province().get_nation_from_province_ownership() == n)
4917 num_factories += int32_t(state.world.province_get_factory_location(p.get_province()).end() - state.world.province_get_factory_location(p.get_province()).begin());
4918 for(
auto p : state.world.state_instance_get_state_building_construction(sid))
4919 if(p.get_is_upgrade() ==
false)
4923 assert(num_factories <= int32_t(state.defines.factories_per_state));
4924 return num_factories;
4929 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_land_construction_get_nation(c));
4930 float admin_cost_factor = 2.0f - admin_eff;
4932 auto& goods = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(c)].build_cost;
4933 auto& cgoods = state.world.province_land_construction_get_purchased_goods(c);
4936 float purchased = 0.0f;
4938 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4939 total += goods.commodity_amounts[i] * admin_cost_factor;
4940 purchased += cgoods.commodity_amounts[i];
4943 return total > 0.0f ? purchased / total : 0.0f;
4947 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_naval_construction_get_nation(c));
4948 float admin_cost_factor = 2.0f - admin_eff;
4950 auto& goods = state.military_definitions.unit_base_definitions[state.world.province_naval_construction_get_type(c)].build_cost;
4951 auto& cgoods = state.world.province_naval_construction_get_purchased_goods(c);
4954 float purchased = 0.0f;
4956 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4957 total += goods.commodity_amounts[i] * admin_cost_factor;
4958 purchased += cgoods.commodity_amounts[i];
4961 return total > 0.0f ? purchased / total : 0.0f;
4967 auto d = state.world.state_instance_get_definition(s);
4968 auto o = state.world.state_instance_get_nation_from_state_ownership(s);
4969 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
4970 if(p.get_province().get_nation_from_province_ownership() == o) {
4971 for(
auto f : p.get_province().get_factory_location()) {
4972 if(f.get_factory().get_building_type() == t) {
4973 auto factory_level = f.get_factory().get_level();
4974 auto new_factory_level = std::min(
float(std::numeric_limits<uint8_t>::max()),
float(factory_level) + 1.f +
math::sqrt(f.get_factory().get_level()) / 2.f);
4975 f.get_factory().get_level() =
uint8_t(new_factory_level);
4982 auto state_cap = state.world.state_instance_get_capital(s);
4983 auto new_fac = fatten(state.world, state.world.create_factory());
4984 new_fac.set_building_type(t);
4985 new_fac.set_level(
uint8_t(1));
4986 new_fac.set_production_scale(1.0f);
4988 state.world.try_create_factory_location(new_fac, state_cap);
4993 for(
uint32_t i = state.world.province_land_construction_size(); i-- > 0;) {
4994 auto c = fatten(state.world, dcon::province_land_construction_id{dcon::province_land_construction_id::value_base_t(i)});
4996 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_land_construction_get_nation(c));
4997 float admin_cost_factor = 2.0f - admin_eff;
4999 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
5000 auto& current_purchased = c.get_purchased_goods();
5001 float construction_time = float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
5003 bool all_finished =
true;
5004 if(!(c.get_nation().get_is_player_controlled() && state.cheat_data.instant_army)) {
5005 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
5006 if(base_cost.commodity_type[j]) {
5007 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * admin_cost_factor) {
5008 all_finished =
false;
5017 auto pop_location = c.get_pop().get_province_from_pop_location();
5020 auto a = fatten(state.world, state.world.create_army());
5022 a.set_controller_from_army_control(c.get_nation());
5023 state.world.try_create_army_membership(new_reg, a);
5024 state.world.try_create_regiment_source(new_reg, c.get_pop());
5028 if(c.get_nation() == state.local_player_nation) {
5033 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
5038 state.world.delete_province_land_construction(c);
5043 auto rng = state.world.province_get_province_naval_construction(p);
5044 if(
rng.begin() !=
rng.end()) {
5045 auto c = *(rng.begin());
5047 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_naval_construction_get_nation(c));
5048 float admin_cost_factor = 2.0f - admin_eff;
5050 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
5051 auto& current_purchased = c.get_purchased_goods();
5052 float construction_time = float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
5054 bool all_finished = true;
5055 if(!(c.get_nation().get_is_player_controlled() && state.cheat_data.instant_navy)) {
5056 for(uint32_t i = 0; i < commodity_set::set_size && all_finished; ++i) {
5057 if(base_cost.commodity_type[i]) {
5058 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
5059 all_finished = false;
5068 auto new_ship = military::create_new_ship(state, c.get_nation(), c.get_type());
5069 auto a = fatten(state.world, state.world.create_navy());
5070 a.set_controller_from_navy_control(c.get_nation());
5071 a.set_location_from_navy_location(p);
5072 state.world.try_create_navy_membership(new_ship, a);
5073 military::move_navy_to_merge(state, c.get_nation(), a, c.get_province(), c.get_template_province());
5075 if(c.get_nation() == state.local_player_nation) {
5076 notification::post(state, notification::message{ [](sys::state& state, text::layout_base& contents) {
5077 text::add_line(state, contents,
"amsg_navy_built");
5080 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
5081 sys::message_base_type::navy_built
5085 state.world.delete_province_naval_construction(c);
5090 for(
uint32_t i =
state.world.province_building_construction_size(); i-- > 0;) {
5091 dcon::province_building_construction_id c{dcon::province_building_construction_id::value_base_t(i)};
5092 auto for_province =
state.world.province_building_construction_get_province(c);
5094 float admin_eff =
state.world.nation_get_administrative_efficiency(
state.world.province_building_construction_get_nation(c));
5095 float admin_cost_factor =
state.world.province_building_construction_get_is_pop_project(c) ? 1.0f : 2.0f - admin_eff;
5098 auto& base_cost =
state.economy_definitions.building_definitions[int32_t(t)].cost;
5099 auto& current_purchased =
state.world.province_building_construction_get_purchased_goods(c);
5100 bool all_finished =
true;
5102 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
5103 if(base_cost.commodity_type[j]) {
5104 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * admin_cost_factor) {
5105 all_finished =
false;
5113 if(
state.world.province_get_building_level(for_province,
uint8_t(t)) <
state.world.nation_get_max_building_level(
state.world.province_get_nation_from_province_ownership(for_province),
uint8_t(t))) {
5114 state.world.province_get_building_level(for_province,
uint8_t(t)) += 1;
5116 if(t == province_building_type::railroad) {
5118 state.railroad_built.store(
true, std::memory_order::release);
5121 if(
state.world.province_building_construction_get_nation(c) ==
state.local_player_nation) {
5123 case province_building_type::naval_base:
5127 "amsg_naval_base_complete",
5128 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
5132 case province_building_type::fort:
5136 "amsg_fort_complete",
5137 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
5141 case province_building_type::railroad:
5146 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
5155 state.world.delete_province_building_construction(c);
5159 for(
uint32_t i =
state.world.state_building_construction_size(); i-- > 0;) {
5160 dcon::state_building_construction_id c{dcon::state_building_construction_id::value_base_t(i)};
5161 auto n =
state.world.state_building_construction_get_nation(c);
5162 auto type =
state.world.state_building_construction_get_type(c);
5163 auto& base_cost =
state.world.factory_type_get_construction_costs(type);
5164 auto& current_purchased =
state.world.state_building_construction_get_purchased_goods(c);
5166 if(!
state.world.state_building_construction_get_is_pop_project(c)) {
5167 float admin_eff =
state.world.nation_get_administrative_efficiency(n);
5168 float admin_cost_factor = 2.0f - admin_eff;
5170 float factory_mod =
state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f;
5172 bool all_finished =
true;
5173 if(!(n ==
state.local_player_nation &&
state.cheat_data.instant_industry)) {
5174 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
5175 if(base_cost.commodity_type[j]) {
5176 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * factory_mod * admin_cost_factor) {
5177 all_finished =
false;
5186 state.world.state_building_construction_get_is_upgrade(c));
5187 state.world.delete_state_building_construction(c);
5190 float factory_mod = (
state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f) *
5191 std::max(0.1f,
state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_owner_cost));
5193 bool all_finished =
true;
5194 if(!(n ==
state.local_player_nation &&
state.cheat_data.instant_industry)) {
5195 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
5196 if(base_cost.commodity_type[j]) {
5197 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * factory_mod) {
5198 all_finished =
false;
5207 state.world.state_building_construction_get_is_upgrade(c));
5209 if(
state.world.state_building_construction_get_nation(c) ==
state.local_player_nation) {
5213 "amsg_factory_complete",
5214 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
5219 state.world.delete_state_building_construction(c);
5232 state.world.nation_get_total_poor_income(n) * state.world.nation_get_poor_tax(n) / 100.f
5233 + state.world.nation_get_total_middle_income(n) * state.world.nation_get_middle_tax(n) / 100.f
5234 + state.world.nation_get_total_rich_income(n) * state.world.nation_get_rich_tax(n) / 100.f
5239 auto n = state.world.state_instance_get_nation_from_state_ownership(s);
5241 if(state.world.factory_type_get_is_coastal(t)) {
5246 auto existing_constructions = state.world.state_instance_get_state_building_construction(s);
5247 int32_t num_factories = 0;
5248 for(
auto prj : existing_constructions) {
5249 if(!prj.get_is_upgrade())
5251 if(prj.get_type() == t)
5256 auto d = state.world.state_instance_get_definition(s);
5257 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
5258 if(p.get_province().get_nation_from_province_ownership() == n) {
5259 for(
auto f : p.get_province().get_factory_location()) {
5261 if(f.get_factory().get_building_type() == t)
5267 if(num_factories < int32_t(state.defines.factories_per_state)) {
5274 auto min_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tariff));
5275 auto max_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_tariff));
5276 max_tariff = std::max(min_tariff, max_tariff);
5278 auto& tariff = state.world.nation_get_tariffs(n);
5279 tariff = int8_t(std::clamp(std::clamp(int32_t(tariff), min_tariff, max_tariff), -100, 100));
5282 auto min_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tax));
5283 auto max_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_tax));
5286 max_tax = std::max(min_tax, max_tax);
5288 auto& ptax = state.world.nation_get_poor_tax(n);
5289 ptax = int8_t(std::clamp(std::clamp(int32_t(ptax), min_tax, max_tax), 0, 100));
5290 auto& mtax = state.world.nation_get_middle_tax(n);
5291 mtax = int8_t(std::clamp(std::clamp(int32_t(mtax), min_tax, max_tax), 0, 100));
5292 auto& rtax = state.world.nation_get_rich_tax(n);
5293 rtax = int8_t(std::clamp(std::clamp(int32_t(rtax), min_tax, max_tax), 0, 100));
5297 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_military_spending));
5299 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_military_spending));
5302 max_spend = std::max(min_spend, max_spend);
5304 auto& v = state.world.nation_get_military_spending(n);
5305 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
5308 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_social_spending));
5309 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_social_spending));
5312 max_spend = std::max(min_spend, max_spend);
5314 auto& v = state.world.nation_get_social_spending(n);
5315 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
5319 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_military_spending));
5321 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_military_spending));
5324 max_spend = std::max(min_spend, max_spend);
5326 auto& v = state.world.nation_get_military_spending(n);
5327 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
5330 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_domestic_investment));
5331 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_domestic_investment));
5334 max_spend = std::max(min_spend, max_spend);
5336 auto& v = state.world.nation_get_domestic_investment_spending(n);
5337 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
5342 for(
auto si : state.world.in_state_instance) {
5343 auto owner = si.get_nation_from_state_ownership();
5344 auto rules = owner.get_combined_issue_rules();
5349 dcon::factory_id deletion_choice;
5350 int32_t factory_count = 0;
5353 for(
auto f : state.world.province_get_factory_location(p)) {
5355 auto scale = f.get_factory().get_production_scale();
5356 float ten_workers = 10.f / factory_max_employment(state, f.get_factory());
5357 bool unprofitable = f.get_factory().get_unprofitable();
5358 if(((scale < ten_workers) && unprofitable) && (!deletion_choice || state.world.factory_get_level(deletion_choice) > f.get_factory().get_level())) {
5359 deletion_choice = f.get_factory();
5366 if(deletion_choice && (4 + factory_count) >= int32_t(state.defines.factories_per_state)) {
5367 auto production_type = state.world.factory_get_building_type(deletion_choice);
5368 state.world.delete_factory(deletion_choice);
5370 for(
auto proj : si.get_state_building_construction()) {
5371 if(proj.get_type() == production_type) {
5372 state.world.delete_state_building_construction(proj);
5381 return state.economy_definitions.selector_modifier;
5385 return state.economy_definitions.immigrator_modifier;
5389 auto& debt = state.world.nation_get_stockpiles(n,
economy::money);
5394 auto existing_br = state.world.nation_get_bankrupt_until(n);
5395 if(existing_br && state.current_date < existing_br) {
5396 for(
auto gn : state.great_nations) {
5397 if(gn.nation && gn.nation != n) {
5401 }
else if(debt >= -state.defines.small_debt_limit) {
5402 for(
auto gn : state.great_nations) {
5403 if(gn.nation && gn.nation != n) {
5408 for(
auto gn : state.great_nations) {
5409 if(gn.nation && gn.nation != n) {
5415 sys::add_modifier_to_nation(state, n, state.national_definitions.in_bankrupcy, state.current_date + int32_t(state.defines.bankrupcy_duration * 365));
5416 sys::add_modifier_to_nation(state, n, state.national_definitions.bad_debter, state.current_date + int32_t(state.defines.bankruptcy_external_loan_years * 365));
5419 state.world.nation_set_is_debt_spending(n,
false);
5420 state.world.nation_set_bankrupt_until(n, state.current_date + int32_t(state.defines.bankrupcy_duration * 365));
5426 "msg_bankruptcy_title",
5427 n, dcon::nation_id{}, dcon::nation_id{},
5434 if(commodity.get_rgo_amount() > 0 && (commodity.get_artisan_output_amount() > 0 || commodity.get_key_factory()))
5435 return commodity_production_type::both;
5436 else if(commodity.get_key_factory())
5437 return commodity_production_type::derivative;
5439 return commodity_production_type::primary;
#define assert(condition)
void update_budget(sys::state &state)
void get_desired_factory_types(sys::state &state, dcon::nation_id nid, std::vector< dcon::factory_type_id > &desired_types)
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
constexpr dcon::demographics_key total(0)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
dcon::demographics_key to_employment_key(sys::state const &state, dcon::pop_type_id v)
float estimate_reparations_income(sys::state &state, dcon::nation_id n)
bool state_contains_factory(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id ft)
float factory_full_production_quantity(sys::state const &state, dcon::factory_id f, dcon::nation_id n, float mobilization_impact)
void initialize(sys::state &state)
bool valid_artisan_good(sys::state &state, dcon::nation_id n, dcon::commodity_id cid)
float global_market_commodity_daily_increase(sys::state &state, dcon::commodity_id c)
dcon::modifier_id get_province_immigrator_modifier(sys::state &state)
constexpr float subsistence_score_life
float total_artisan_exp_score(sys::state &state, dcon::nation_id n, float multiplier, float max_score)
void register_demand(sys::state &state, dcon::nation_id n, dcon::commodity_id commodity_type, float amount, economy_reason reason)
float full_private_investment_cost(sys::state &state, dcon::nation_id n)
float estimate_subsidy_spending(sys::state &state, dcon::nation_id n)
constexpr float diff_factory
void populate_effective_prices(sys::state &state, dcon::nation_id n)
void update_national_consumption(sys::state &state, dcon::nation_id n, float spending_scale, float private_investment_scale)
constexpr float slope_factory
void for_each_new_factory(sys::state &state, dcon::state_instance_id s, F &&func)
float government_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
float estimate_social_spending(sys::state &state, dcon::nation_id n)
construction_status province_building_construction(sys::state &state, dcon::province_id p, province_building_type t)
float rgo_total_effective_size(sys::state &state, dcon::nation_id n, dcon::province_id p)
float nation_total_imports(sys::state &state, dcon::nation_id n)
bool state_contains_constructed_factory(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id ft)
float estimate_tariff_income(sys::state &state, dcon::nation_id n)
float factory_desired_raw_profit(dcon::factory_fat_id fac, float spendings)
bool has_building(sys::state const &state, dcon::state_instance_id si, dcon::factory_type_id fac)
float factory_max_employment(sys::state const &state, dcon::factory_id f)
void advance_construction(sys::state &state, dcon::nation_id n)
void update_factory_employment(sys::state &state)
bool is_bankrupt_debtor_to(sys::state &state, dcon::nation_id debt_holder, dcon::nation_id debtor)
int32_t state_factory_count(sys::state &state, dcon::state_instance_id sid, dcon::nation_id n)
float sphere_leader_share_factor(sys::state &state, dcon::nation_id sphere_leader, dcon::nation_id sphere_member)
constexpr float diff_non_factory
float estimate_diplomatic_balance(sys::state &state, dcon::nation_id n)
void prune_factories(sys::state &state)
constexpr float day_inf_build_time_modifier_non_factory
void update_factory_triggered_modifiers(sys::state &state)
void convert_commodities_into_ingredients(sys::state &state, std::vector< float > &buffer_commodities, std::vector< float > &buffer_ingredients, std::vector< float > &buffer_weights)
constexpr uint32_t gdp_history_length
float estimate_pop_payouts_by_income_type(sys::state &state, dcon::nation_id n, culture::income_type in)
void populate_construction_consumption(sys::state &state)
float estimate_domestic_investment(sys::state &state, dcon::nation_id n)
int32_t previous_price_record_index(sys::state &state)
void populate_private_construction_consumption(sys::state &state)
constexpr float day_inf_build_time_modifier_factory
rgo_workers_breakdown rgo_relevant_population(sys::state &state, dcon::province_id p, dcon::nation_id n)
float rgo_desired_worker_norm_profit(sys::state &state, dcon::province_id p, dcon::nation_id n, float min_wage, float total_relevant_population)
float factory_min_input_available(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
float estimate_overseas_penalty_spending(sys::state &state, dcon::nation_id n)
float nation_factory_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
float nation_factory_input_multiplier(sys::state &state, dcon::nation_id n)
constexpr float shift_factory
float base_artisan_profit(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
commodity_production_type get_commodity_production_type(sys::state &state, dcon::commodity_id c)
bool has_factory(sys::state const &state, dcon::state_instance_id si)
float max_loan(sys::state &state, dcon::nation_id n)
float estimate_construction_spending(sys::state &state, dcon::nation_id n)
float max_artisan_score(sys::state &state, dcon::nation_id n, float multiplier)
float effective_tariff_rate(sys::state &state, dcon::nation_id n)
float estimate_war_subsidies_income(sys::state &state, dcon::nation_id n)
construction_status factory_upgrade(sys::state &state, dcon::factory_id f)
float gdp_adjusted(sys::state &state, dcon::nation_id n)
void presimulate(sys::state &state)
void register_domestic_supply(sys::state &state, dcon::nation_id n, dcon::commodity_id commodity_type, float amount, economy_reason reason)
void update_rgo_employment(sys::state &state)
profit_distribution distribute_factory_profit(sys::state const &state, dcon::state_instance_const_fat_id s, float min_wage, float total_profit)
float full_spending_cost(sys::state &state, dcon::nation_id n)
float estimate_land_spending(sys::state &state, dcon::nation_id n)
constexpr float day_1_build_time_modifier_factory
void update_national_artisan_consumption(sys::state &state, dcon::nation_id n, float expected_min_wage, float mobilization_impact)
float rgo_total_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
commodity_production_type
float estimate_daily_income(sys::state &state, dcon::nation_id n)
void update_single_factory_production(sys::state &state, dcon::factory_id f, dcon::nation_id n, float expected_min_wage)
constexpr uint32_t price_history_length
float rgo_total_max_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
void adjust_artisan_balance(sys::state &state, dcon::nation_id n)
constexpr float artisan_baseline_score
void regenerate_unsaved_values(sys::state &state)
float artisan_scale_limit(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
constexpr dcon::commodity_id money(0)
void update_land_ownership(sys::state &state)
float rgo_efficiency(sys::state &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
bool can_take_loans(sys::state &state, dcon::nation_id n)
dcon::modifier_id get_province_selector_modifier(sys::state &state)
float unit_construction_progress(sys::state &state, dcon::province_land_construction_id c)
constexpr float factory_closed_threshold
int32_t most_recent_price_record_index(sys::state &state)
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)
void try_add_factory_to_state(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id t)
float pseudo_exp_for_negative(float f)
bool nation_is_constructing_factories(sys::state &state, dcon::nation_id n)
float pop_income(sys::state &state, dcon::pop_id p)
float rgo_effective_size(sys::state const &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
float factory_max_production_scale_non_modified(sys::state &state, dcon::factory_fat_id fac)
void update_province_rgo_consumption(sys::state &state, dcon::province_id p, dcon::nation_id n, float mobilization_impact, float expected_min_wage, bool occupied)
float subsistence_size(sys::state const &state, dcon::province_id p)
constexpr float subsistence_score_luxury
float pop_factory_min_wage(sys::state &state, dcon::nation_id n, float min_wage_factor)
float estimate_war_subsidies_spending(sys::state &state, dcon::nation_id n)
float factory_max_production_scale(sys::state &state, dcon::factory_fat_id fac, float mobilization_impact, bool occupied)
float commodity_daily_production_amount(sys::state &state, dcon::commodity_id c)
float global_non_factory_construction_time_modifier(sys::state &state)
float global_market_price_multiplier(sys::state &state, dcon::nation_id n)
float estimate_war_subsidies(sys::state &state, dcon::nation_id n)
float rgo_expected_worker_norm_profit(sys::state &state, dcon::province_id p, dcon::nation_id n, dcon::commodity_id c)
constexpr float subsistence_factor
constexpr float production_scale_delta
bool factory_is_profitable(sys::state const &state, dcon::factory_id f)
float convex_function(float x)
float estimate_reparations_spending(sys::state &state, dcon::nation_id n)
int32_t most_recent_gdp_record_index(sys::state &state)
float nation_factory_output_multiplier(sys::state &state, dcon::factory_type_id fac_type, dcon::nation_id n)
float estimate_naval_spending(sys::state &state, dcon::nation_id n)
float subsistence_max_pseudoemployment(sys::state &state, dcon::nation_id n, dcon::province_id p)
float get_artisan_distribution_fast(sys::state &state, dcon::nation_id n, dcon::commodity_id c, float max_score, float total_score, float multiplier)
void for_each_upgraded_factory(sys::state &state, dcon::state_instance_id s, F &&func)
void initialize_needs_weights(sys::state &state, dcon::nation_id n)
void go_bankrupt(sys::state &state, dcon::nation_id n)
void give_sphere_leader_production(sys::state &state, dcon::nation_id n)
void bound_budget_settings(sys::state &state, dcon::nation_id n)
constexpr float slope_non_factory
float adjusted_subsistence_score(sys::state &state, dcon::province_id p)
float get_artisans_multiplier(sys::state &state, dcon::nation_id n)
float factory_secondary_employment(sys::state const &state, dcon::factory_id f)
constexpr float shift_non_factory
float rgo_max_employment(sys::state &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
float pop_min_wage_factor(sys::state &state, dcon::nation_id n)
void resolve_constructions(sys::state &state)
void update_province_rgo_production(sys::state &state, dcon::province_id p, dcon::nation_id n)
float need_weight(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
void update_local_subsistence_factor(sys::state &state)
float estimate_tax_income_by_strata(sys::state &state, dcon::nation_id n, culture::pop_strata ps)
float pop_farmer_min_wage(sys::state &state, dcon::nation_id n, float min_wage_factor)
float factory_total_employment(sys::state const &state, dcon::factory_id f)
float estimate_stockpile_filling_spending(sys::state &state, dcon::nation_id n)
void update_pop_consumption(sys::state &state, dcon::nation_id n, float base_demand, float invention_factor)
constexpr float rgo_owners_cut
float stockpile_commodity_daily_increase(sys::state &state, dcon::commodity_id c, dcon::nation_id n)
float pop_laborer_min_wage(sys::state &state, dcon::nation_id n, float min_wage_factor)
void populate_needs_costs(sys::state &state, dcon::nation_id n, float base_demand, float invention_factor)
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)
void rebalance_needs_weights(sys::state &state, dcon::nation_id n)
void populate_army_consumption(sys::state &state)
void absorb_sphere_member_production(sys::state &state, dcon::nation_id n)
void add_factory_level_to_state(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id t, bool is_upgrade)
void emulate_construction_demand(sys::state &state, dcon::nation_id n)
float factory_input_total_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
constexpr float day_1_derivative_factory
float rgo_full_production_quantity(sys::state &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
float global_factory_construction_time_modifier(sys::state &state)
void populate_navy_consumption(sys::state &state)
float interest_payment(sys::state &state, dcon::nation_id n)
float factory_e_input_total_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
void initialize_artisan_distribution(sys::state &state)
void daily_update(sys::state &state, bool initiate_buildings)
void set_factory_priority(sys::state &state, dcon::factory_id f, int32_t priority)
float factory_primary_employment(sys::state const &state, dcon::factory_id f)
void register_construction_demand(sys::state &state, dcon::nation_id n, dcon::commodity_id commodity_type, float amount)
float update_factory_scale(sys::state &state, dcon::factory_fat_id fac, float max_production_scale, float raw_profit, float desired_raw_profit)
bool nation_has_closed_factories(sys::state &state, dcon::nation_id n)
float ideal_pound_conversion_rate(sys::state &state, dcon::nation_id n)
float get_artisan_distribution_slow(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
float factory_output_multiplier(sys::state &state, dcon::factory_fat_id fac, dcon::nation_id n, dcon::province_id p)
float nation_pop_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
float factory_min_e_input_available(sys::state &state, dcon::nation_id n, dcon::factory_type_fat_id fac_type)
float factory_type_build_cost(sys::state &state, dcon::nation_id n, dcon::factory_type_id factory_type)
int32_t previous_gdp_record_index(sys::state &state)
void register_intermediate_demand(sys::state &state, dcon::nation_id n, dcon::commodity_id commodity_type, float amount, economy_reason reason)
constexpr float subsistence_score_everyday
constexpr float day_1_derivative_non_factory
float estimate_gold_income(sys::state &state, dcon::nation_id n)
void update_single_factory_consumption(sys::state &state, dcon::factory_id f, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s, float mobilization_impact, float expected_min_wage, bool occupied)
void update_national_artisan_production(sys::state &state, dcon::nation_id n)
constexpr float day_1_build_time_modifier_non_factory
void fire_fixed_event(sys::state &state, std::vector< nations::fixed_event > const &v, int32_t primary_slot, slot_type pt, dcon::nation_id this_slot, int32_t from_slot, slot_type ft)
constexpr uint32_t pop_expand_factory
constexpr uint32_t destroy_factory
constexpr uint32_t pop_build_factory
float sqrt(float x) noexcept
void army_arrives_in_province(sys::state &state, dcon::army_id a, dcon::province_id p, crossing_type crossing, dcon::land_battle_id from)
float mobilization_impact(sys::state const &state, dcon::nation_id n)
void move_land_to_merge(sys::state &state, dcon::nation_id by, dcon::army_id a, dcon::province_id start, dcon::province_id dest)
dcon::regiment_id create_new_regiment(sys::state &state, dcon::nation_id n, dcon::unit_type_id t)
constexpr uint8_t level_in_sphere
constexpr uint8_t level_mask
std::string int_to_tag(uint32_t v)
float get_foreign_investment(sys::state &state, dcon::nation_id n)
float tariff_efficiency(sys::state &state, dcon::nation_id n)
dcon::nation_id owner_of_pop(sys::state const &state, dcon::pop_id pop_ids)
float tax_efficiency(sys::state &state, dcon::nation_id n)
void post(sys::state &state, message &&m)
float get_employment(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 set_everyday_needs(sys::state &state, dcon::pop_id p, float v)
float get_life_needs(sys::state const &state, dcon::pop_id p)
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)
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
bool state_is_coastal(sys::state &state, dcon::state_instance_id s)
void for_each_land_province(sys::state &state, F const &func)
constexpr uint16_t to_map_id(dcon::province_id id)
bool generic_can_build_railroads(sys::state &state, dcon::province_id id, dcon::nation_id n)
uint64_t get_random(sys::state const &state, uint32_t value_in)
MOD_PROV_LIST constexpr uint32_t count
void add_modifier_to_nation(sys::state &state, dcon::nation_id target_nation, dcon::modifier_id mod_id, sys::date expiration)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
int32_t to_generic(dcon::province_id v)
bool evaluate(sys::state &state, dcon::trigger_key key, int32_t primary, int32_t this_slot, int32_t from_slot)
T select(bool v, T a, T b)
float to_float(int32_t a)
static constexpr uint32_t set_size
float per_secondary_worker