4#include "dcon_generated.hpp"
17 return state.world.nation_get_modifier_values(n, sys::national_mod_offsets::minimum_wage);
21 return state.world.nation_get_modifier_values(n, sys::national_mod_offsets::minimum_wage);
25 auto life = state.world.market_get_life_needs_costs(markets, state.culture_definitions.artisans);
26 auto everyday = state.world.market_get_everyday_needs_costs(markets, state.culture_definitions.artisans);
31 auto life = state.world.market_get_life_needs_costs(markets, state.culture_definitions.farmers);
32 auto everyday = state.world.market_get_everyday_needs_costs(markets, state.culture_definitions.farmers);
33 return min_wage_factor * (life + everyday) * 1.1f;
37 auto required = state.world.market_get_life_needs_costs(markets, state.culture_definitions.primary_factory_worker);
38 auto current_price = state.world.market_get_labor_unskilled_price(markets) * state.defines.alice_needs_scaling_factor;
39 return ve::min(current_price / (0.001f + required *
primary_greed), 1.f);
43 auto required = state.world.market_get_life_needs_costs(markets, state.culture_definitions.secondary_factory_worker);
44 auto current_price = state.world.market_get_labor_skilled_price(markets) * state.defines.alice_needs_scaling_factor;
45 return ve::min(current_price / (0.001f + required *
secondary_greed), 1.f);
49 auto required = state.world.market_get_life_needs_costs(markets, state.culture_definitions.primary_factory_worker);
50 auto current_price = state.world.market_get_labor_unskilled_price(markets) * state.defines.alice_needs_scaling_factor;
51 return std::min(current_price / (0.001f + required *
primary_greed), 1.f);
54 auto required = state.world.market_get_life_needs_costs(markets, state.culture_definitions.secondary_factory_worker);
55 auto current_price = state.world.market_get_labor_skilled_price(markets) * state.defines.alice_needs_scaling_factor;
56 return std::min(current_price / (0.001f + required *
secondary_greed), 1.f);
61 auto life = state.world.market_get_life_needs_costs(markets, state.culture_definitions.laborers);
62 auto everyday = state.world.market_get_everyday_needs_costs(markets, state.culture_definitions.laborers);
63 return min_wage_factor * (life + everyday) * 1.1f;
66 auto life = state.world.market_get_life_needs_costs(m, state.culture_definitions.farmers);
67 auto everyday = state.world.market_get_everyday_needs_costs(m, state.culture_definitions.farmers);
68 return min_wage_factor * (life + everyday) * 1.1f;
71 auto life = state.world.market_get_life_needs_costs(m, state.culture_definitions.laborers);
72 auto everyday = state.world.market_get_everyday_needs_costs(m, state.culture_definitions.laborers);
73 return min_wage_factor * (life + everyday) * 1.1f;
124 float primary_commodity_basket = 0.0f;
125 state.world.for_each_commodity([&](dcon::commodity_id c) {
126 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
127 primary_commodity_basket += state.world.commodity_get_cost(c) * state.world.pop_type_get_life_needs(pt, c);
128 primary_commodity_basket += state.world.commodity_get_cost(c) * state.world.pop_type_get_everyday_needs(pt, c);
131 primary_commodity_basket /= float(state.world.pop_type_size());
133 return primary_commodity_basket / state.defines.alice_needs_scaling_factor;
150float price(
sys::state const& state, dcon::state_instance_id s, dcon::commodity_id c) {
151 auto market = state.world.state_instance_get_market_from_local_market(s);
152 return state.world.market_get_price(market, c);
156 auto total_cost = 0.f;
157 auto total_supply = 0.f;
158 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
159 auto sid = state.world.state_ownership_get_state(soid);
160 dcon::market_id market = state.world.state_instance_get_market_from_local_market(sid);
162 auto local_price =
price(state, market, c);
163 auto local_supply = state.world.market_get_supply(market, c);
165 total_cost += local_price * local_supply;
166 total_supply += local_supply;
169 if(total_supply == 0.f) {
170 auto capital = state.world.nation_get_capital(s);
171 auto sid = state.world.province_get_state_membership(capital);
172 auto market = state.world.state_instance_get_market_from_local_market(sid);
173 return state.world.market_get_price(market, c);
176 return total_cost / total_supply;
180 auto total_cost = 0.f;
181 auto total_supply = 0.f;
182 state.world.for_each_market([&](
auto m) {
183 auto local_price =
price(state, m, c);
184 auto local_supply = state.world.market_get_supply(m, c) + 0.0001f;
186 total_cost += local_price * local_supply;
187 total_supply += local_supply;
190 if(total_supply == 0.f) {
194 return total_cost / total_supply;
199 return state.world.market_get_price(s, c);
203 return state.world.market_get_price(s, c);
211 return state.world.market_get_supply(s, c);
218 auto total_supply = 0.f;
219 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
220 auto sid = state.world.state_ownership_get_state(soid);
221 auto market = state.world.state_instance_get_market_from_local_market(sid);
223 auto local_supply = state.world.market_get_supply(market, c);
224 total_supply += local_supply;
235 auto total_volume = 0.f;
237 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
238 auto sid = state.world.state_ownership_get_state(soid);
239 auto market = state.world.state_instance_get_market_from_local_market(sid);
241 state.world.market_for_each_trade_route(market, [&](
auto trade_route) {
242 auto current_volume = state.world.trade_route_get_volume(trade_route, c);
245 ? state.world.trade_route_get_connected_markets(trade_route, 0)
246 : state.world.trade_route_get_connected_markets(trade_route, 1);
248 current_volume <= 0.f
249 ? state.world.trade_route_get_connected_markets(trade_route, 0)
250 : state.world.trade_route_get_connected_markets(trade_route, 1);
252 if(target != market)
return;
254 auto s_origin = state.world.market_get_zone_from_local_market(origin);
255 auto s_target = state.world.market_get_zone_from_local_market(target);
256 auto n_origin = state.world.state_instance_get_nation_from_state_ownership(s_origin);
257 auto n_target = state.world.state_instance_get_nation_from_state_ownership(s_target);
259 if(n_origin != n_target)
return;
261 auto sat = state.world.market_get_direct_demand_satisfaction(origin, c);
262 auto absolute_volume = std::abs(current_volume);
264 total_volume += sat * absolute_volume;
275 auto total_supply = 0.f;
276 state.world.for_each_market([&](
auto m) {
277 auto local_supply = state.world.market_get_supply(m, c);
278 total_supply += local_supply;
288 return state.world.market_get_demand(s, c);
295 auto total_demand = 0.f;
296 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
297 auto sid = state.world.state_ownership_get_state(soid);
298 auto market = state.world.state_instance_get_market_from_local_market(sid);
299 auto local_demand = state.world.market_get_demand(market, c);
300 total_demand += local_demand;
309 auto total_demand = 0.f;
310 state.world.for_each_market([&](
auto m) {
311 auto local_demand = state.world.market_get_demand(m, c);
312 total_demand += local_demand;
330 return state.world.market_get_demand(s, c) * state.world.market_get_demand_satisfaction(s, c);
338 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
339 auto sid = state.world.state_ownership_get_state(soid);
340 auto market = state.world.state_instance_get_market_from_local_market(sid);
342 auto local = state.world.market_get_demand(market, c);
343 total += local * state.world.market_get_demand_satisfaction(market, c);
353 state.world.for_each_market([&](
auto m) {
354 auto local = state.world.market_get_demand(m, c);
355 total += local * state.world.market_get_demand_satisfaction(m, c);
365 return state.world.market_get_stockpile(s, c);
373 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
374 auto sid = state.world.state_ownership_get_state(soid);
375 auto market = state.world.state_instance_get_market_from_local_market(sid);
377 auto local = state.world.market_get_stockpile(market, c);
388 state.world.for_each_market([&](
auto m) {
389 auto local = state.world.market_get_stockpile(m, c);
400 auto d =
demand(state, s, c);
412 auto d =
demand(state, s, c);
423 auto d =
demand(state, c);
438 auto def = state.culture_definitions.capitalists;
441 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
442 auto sid = state.world.state_ownership_get_state(soid);
443 auto market = state.world.state_instance_get_market_from_local_market(sid);
445 auto local_count = state.world.state_instance_get_demographics(
449 auto luxury = state.world.market_get_luxury_needs_costs(
452 auto everyday = state.world.market_get_everyday_needs_costs(
455 auto life = state.world.market_get_life_needs_costs(
459 total += (luxury + everyday + life) * local_count / state.defines.alice_needs_scaling_factor;
460 count += local_count;
467 return total / count;
475 return state.world.market_get_export(s, c);
483 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
484 auto sid = state.world.state_ownership_get_state(soid);
485 auto market = state.world.state_instance_get_market_from_local_market(sid);
486 total += state.world.market_get_export(market, c);
497 static ve::vectorizable_buffer<float, dcon::nation_id> per_nation_data(
uint32_t(1));
500 auto new_count = state.world.nation_size();
501 if(new_count > old_count) {
502 per_nation_data = state.world.nation_make_vectorizable_float_buffer();
503 old_count = new_count;
506 state.world.execute_serial_over_nation([&](
auto nids) {
507 per_nation_data.set(nids, 0.f);
512 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
513 auto sid = state.world.state_ownership_get_state(soid);
514 auto market = state.world.state_instance_get_market_from_local_market(sid);
515 state.world.market_for_each_trade_route(market, [&](
auto trade_route) {
516 auto current_volume = state.world.trade_route_get_volume(trade_route, c);
519 ? state.world.trade_route_get_connected_markets(trade_route, 0)
520 : state.world.trade_route_get_connected_markets(trade_route, 1);
522 current_volume <= 0.f
523 ? state.world.trade_route_get_connected_markets(trade_route, 0)
524 : state.world.trade_route_get_connected_markets(trade_route, 1);
526 if(origin != market)
return;
528 auto sat = state.world.market_get_direct_demand_satisfaction(origin, c);
529 auto absolute_volume = std::abs(current_volume);
530 auto s_origin = state.world.market_get_zone_from_local_market(origin);
531 auto s_target = state.world.market_get_zone_from_local_market(target);
532 auto n_origin = state.world.state_instance_get_nation_from_state_ownership(s_origin);
533 auto n_target = state.world.state_instance_get_nation_from_state_ownership(s_target);
535 auto distance = state.world.trade_route_get_distance(trade_route);
537 auto trade_good_loss_mult = std::max(0.f, 1.f - 0.0001f * distance);
539 if(n_origin != n_target) {
540 per_nation_data.get(n_target) += sat * absolute_volume;
544 total += state.world.market_get_export(market, c);
549 state.world.for_each_nation([&](dcon::nation_id nid) {
550 auto value = per_nation_data.get(nid);
551 for(
size_t i = 0; i < 5; i++) {
553 if(value > top[i].value) {
554 for(
size_t j = 4; j > i; j--) {
555 top[j].value = top[j - 1].value;
556 top[j].nation = top[j - 1].nation;
559 top[i].value = value;
564 top[i].value = value;
572 total, c, { top[0], top[1], top[2], top[3], top[4] }
583 return state.world.market_get_import(s, c);
591 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
592 auto sid = state.world.state_ownership_get_state(soid);
593 auto market = state.world.state_instance_get_market_from_local_market(sid);
594 total += state.world.market_get_import(market, c);
604 static ve::vectorizable_buffer<float, dcon::nation_id> per_nation_data(
uint32_t(1));
607 auto new_count = state.world.nation_size();
608 if(new_count > old_count) {
609 per_nation_data = state.world.nation_make_vectorizable_float_buffer();
610 old_count = new_count;
613 state.world.execute_serial_over_nation([&](
auto nids) {
614 per_nation_data.set(nids, 0.f);
619 state.world.nation_for_each_state_ownership(s, [&](
auto soid) {
620 auto sid = state.world.state_ownership_get_state(soid);
621 auto market = state.world.state_instance_get_market_from_local_market(sid);
622 state.world.market_for_each_trade_route(market, [&](
auto trade_route) {
623 auto current_volume = state.world.trade_route_get_volume(trade_route, c);
626 ? state.world.trade_route_get_connected_markets(trade_route, 0)
627 : state.world.trade_route_get_connected_markets(trade_route, 1);
629 current_volume <= 0.f
630 ? state.world.trade_route_get_connected_markets(trade_route, 0)
631 : state.world.trade_route_get_connected_markets(trade_route, 1);
633 if(target != market)
return;
635 auto sat = state.world.market_get_direct_demand_satisfaction(origin, c);
636 auto absolute_volume = std::abs(current_volume);
637 auto s_origin = state.world.market_get_zone_from_local_market(origin);
638 auto s_target = state.world.market_get_zone_from_local_market(target);
639 auto n_origin = state.world.state_instance_get_nation_from_state_ownership(s_origin);
640 auto n_target = state.world.state_instance_get_nation_from_state_ownership(s_target);
642 auto distance = state.world.trade_route_get_distance(trade_route);
644 auto trade_good_loss_mult = std::max(0.f, 1.f - 0.0001f * distance);
646 if(n_origin != n_target) {
647 per_nation_data.get(n_origin) += sat * absolute_volume * trade_good_loss_mult;
651 total += state.world.market_get_import(market, c);
656 state.world.for_each_nation([&](dcon::nation_id nid) {
657 auto value = per_nation_data.get(nid);
658 for(
size_t i = 0; i < 5; i++) {
660 if(value > top[i].value) {
661 for(
size_t j = 4; j > i; j--) {
662 top[j].value = top[j - 1].value;
663 top[j].nation = top[j - 1].nation;
666 top[i].value = value;
671 top[i].value = value;
679 total, c, { top[0], top[1], top[2], top[3], top[4] }
690 dcon::commodity_id commodity_type,
695 state.world.market_get_demand(s, commodity_type) += amount;
696 assert(std::isfinite(state.world.market_get_demand(s, commodity_type)));
703 dcon::commodity_id commodity_type,
704 ve::fp_vector amount,
709 assert(std::isfinite(amount) && amount >= 0.f);
712 state.world.market_set_demand(
715 state.world.market_get_demand(s, commodity_type) + amount
720 }, state.world.market_get_demand(s, commodity_type)
728 dcon::commodity_id c,
729 ve::fp_vector amount,
733 state.world.market_set_intermediate_demand(
736 state.world.market_get_intermediate_demand(s, c) + amount
738 auto local_price =
ve_price(state, s, c);
739 auto sat = state.world.market_get_demand_satisfaction(s, c);
740 state.world.market_set_gdp(s, state.world.market_get_gdp(s) - amount * local_price * sat);
746 state.world.market_get_construction_demand(s, commodity_type) += amount;
747 assert(state.world.market_get_construction_demand(s, commodity_type) >= 0.f);
753 dcon::commodity_id commodity_type,
757 state.world.market_get_supply(s, commodity_type) += amount;
758 state.world.market_get_gdp(s) += amount *
price(state, s, commodity_type);
764 dcon::commodity_id commodity_type,
768 state.world.market_get_supply(s, commodity_type) += amount;
775 dcon::commodity_id commodity_type,
776 ve::fp_vector amount,
779 state.world.market_set_supply(
782 state.world.market_get_supply(s, commodity_type) + amount
784 state.world.market_set_gdp(
786 state.world.market_get_gdp(s)
787 + amount *
ve_price(state, s, commodity_type)
795 if(!state.world.nation_get_is_player_controlled(n) || !state.world.nation_get_is_debt_spending(n))
801 auto last_br = state.world.nation_get_bankrupt_until(n);
802 if(last_br && state.current_date < last_br)
813 auto debt = state.world.nation_get_local_loan(n);
814 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;
820 auto mod = (state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_loan_modifier) + 1.0f);
821 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);
822 return std::max(0.0f, (total_tax_base + state.world.nation_get_national_bank(n)) * mod);
833 auto date = state.current_date.to_ymd(state.start_date);
837 auto date = state.current_date.to_ymd(state.start_date);
842 return state.world.market_get_life_needs_costs(n, state.culture_definitions.primary_factory_worker)
843 + 0.1f * state.world.market_get_everyday_needs_costs(n, state.culture_definitions.primary_factory_worker);
847 float raw = state.world.market_get_gdp(n);
849 return raw / ideal_pound;
854 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
855 auto sid = state.world.state_ownership_get_state(soid);
856 auto market = state.world.state_instance_get_market_from_local_market(sid);
884 std::vector<dcon::factory_type_id> types;
886 for(
auto t : state.world.in_factory_type) {
887 if(t.get_output() == output_good) {
896 auto sdef = state.world.state_instance_get_definition(si);
897 auto owner = state.world.state_instance_get_nation_from_state_ownership(si);
898 auto crng = state.world.state_instance_get_state_building_construction(si);
899 if(crng.begin() != crng.end())
902 for(
auto p : state.world.state_definition_get_abstract_state_membership(sdef)) {
903 if(p.get_province().get_nation_from_province_ownership() == owner) {
904 auto rng = p.get_province().get_factory_location();
905 if(
rng.begin() !=
rng.end())
914 state.world.market_resize_artisan_score(state.world.commodity_size());
915 state.world.market_resize_artisan_actual_production(state.world.commodity_size());
917 auto const csize = state.world.commodity_size();
919 for(
auto m : state.world.in_market) {
920 auto zone = state.world.market_get_zone_from_local_market(m);
921 auto nation = state.world.state_instance_get_nation_from_state_ownership(zone);
923 for(
uint32_t i = 1; i < csize; ++i) {
924 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
927 state.world.commodity_get_artisan_output_amount(cid) > 0.0f
929 state.world.commodity_get_is_available_from_start(cid)
930 || state.world.nation_get_unlocked_commodities(
nation, cid)
933 m.set_artisan_score(cid, 0.f);
939 return state.world.commodity_get_is_available_from_start(c)
940 || state.world.nation_get_unlocked_commodities(n, c);
945 ve::mask_vector available_at_start = state.world.commodity_get_is_available_from_start(c);
946 ve::mask_vector active_mask = state.world.nation_get_unlocked_commodities(n, c);
947 return available_at_start || active_mask;
951 return state.world.commodity_get_is_life_need(c)
953 state.world.commodity_get_is_available_from_start(c)
954 || state.world.nation_get_unlocked_commodities(n, c)
958 return state.world.commodity_get_is_everyday_need(c)
960 state.world.commodity_get_is_available_from_start(c)
961 || state.world.nation_get_unlocked_commodities(n, c)
965 return state.world.commodity_get_is_luxury_need(c)
967 state.world.commodity_get_is_available_from_start(c)
968 || state.world.nation_get_unlocked_commodities(n, c)
973 auto zone = state.world.market_get_zone_from_local_market(n);
974 auto nation = state.world.state_instance_get_nation_from_state_ownership(zone);
976 state.world.for_each_commodity([&](dcon::commodity_id c) {
978 auto& w = state.world.market_get_life_needs_weights(n, c);
984 state.world.for_each_commodity([&](dcon::commodity_id c) {
986 auto& w = state.world.market_get_everyday_needs_weights(n, c);
992 state.world.for_each_commodity([&](dcon::commodity_id c) {
994 auto& w = state.world.market_get_luxury_needs_weights(n, c);
1002 return std::min(1.f, 100000.0f / std::max(
price(state, n, c), 0.0001f));
1006 auto zone = state.world.market_get_zone_from_local_market(n);
1007 auto nation = state.world.state_instance_get_nation_from_state_ownership(zone);
1011 state.world.for_each_commodity([&](dcon::commodity_id c) {
1014 auto& w = state.world.market_get_life_needs_weights(n, c);
1015 w = weight * state.defines.alice_need_drift_speed + w * (1.0f - state.defines.alice_need_drift_speed);
1017 assert(std::isfinite(w));
1018 assert(w <= 1.f + 0.01f);
1024 state.world.for_each_commodity([&](dcon::commodity_id c) {
1027 auto& w = state.world.market_get_everyday_needs_weights(n, c);
1028 w = weight * state.defines.alice_need_drift_speed + w * (1.0f - state.defines.alice_need_drift_speed);
1030 assert(std::isfinite(w));
1031 assert(w <= 1.f + 0.01f);
1037 state.world.for_each_commodity([&](dcon::commodity_id c) {
1040 auto& w = state.world.market_get_luxury_needs_weights(n, c);
1041 w = weight * state.defines.alice_need_drift_speed + w * (1.0f - state.defines.alice_need_drift_speed);
1043 assert(std::isfinite(w));
1044 assert(w <= 1.f + 0.01f);
1067 std::vector<float>& buffer_commodities,
1068 std::vector<float>& buffer_ingredients,
1069 std::vector<float>& buffer_weights
1071 state.world.for_each_commodity([&](dcon::commodity_id c) {
1072 float amount = buffer_commodities[c.index()];
1074 if(state.world.commodity_get_rgo_amount(c) > 0.f) {
1075 buffer_ingredients[c.index()] += amount;
1078 std::vector<float> weights;
1079 float total_weight = 0.f;
1080 float non_zero_count = 0.f;
1082 state.world.for_each_factory_type([&](dcon::factory_type_id t) {
1083 auto o = state.world.factory_type_get_output(t);
1085 auto& inputs = state.world.factory_type_get_inputs(t);
1087 float weight_current = 0;
1089 for(uint32_t i = 0; i < economy::commodity_set::set_size; ++i) {
1090 if(inputs.commodity_type[i]) {
1091 float weight_input = buffer_weights[inputs.commodity_type[i].index()];
1092 total_weight += weight_input;
1093 weight_current += weight_input;
1099 if(weight_current > 0.f)
1102 weights.push_back(weight_current);
1106 if(total_weight == 0) {
1107 for(
size_t i = 0; i < weights.size(); i++) {
1112 float average_weight = total_weight / non_zero_count;
1113 for(
size_t i = 0; i < weights.size(); i++) {
1114 if(weights[i] == 0.f) {
1115 weights[i] = average_weight;
1116 total_weight += average_weight;
1124 state.world.for_each_factory_type([&](dcon::factory_type_id t) {
1125 auto o = state.world.factory_type_get_output(t);
1127 auto& inputs = state.world.factory_type_get_inputs(t);
1128 float output_power = state.world.factory_type_get_output_amount(t);
1130 float weight_current = weights[index] / total_weight;
1134 if(inputs.commodity_type[i]) {
1136 buffer_ingredients[inputs.commodity_type[i].index()] += inputs.commodity_amounts[i] * amount / output_power * weight_current;
1138 float weight_input = buffer_weights[inputs.commodity_type[i].index()];
1139 total_weight += weight_input;
1140 weight_current += weight_input;
1158 for(
uint32_t i = 0; i < steps; i++) {
1167 auto sdef = state.world.state_instance_get_definition(si);
1168 auto owner = state.world.state_instance_get_nation_from_state_ownership(si);
1169 for(
auto p : state.world.state_definition_get_abstract_state_membership(sdef)) {
1170 if(p.get_province().get_nation_from_province_ownership() == owner) {
1171 for(
auto b : p.get_province().get_factory_location()) {
1172 if(b.get_factory().get_building_type() == fac)
1181 return state.world.nation_get_is_bankrupt(debt_holder) &&
1182 state.world.unilateral_relationship_get_owns_debt_of(
1183 state.world.get_unilateral_relationship_by_unilateral_pair(debtor, debt_holder)) > 0.1f;
1187 auto rng = state.world.nation_get_state_building_construction(n);
1188 return rng.begin() !=
rng.end();
1192 for(
auto prov_owner : nation_fat.get_province_ownership()) {
1193 auto prov = prov_owner.get_province();
1194 for(
auto factloc : prov.get_factory_location()) {
1195 auto scale = factloc.get_factory().get_production_scale();
1209 auto alice_input_base = state.defines.alice_inputs_base_factor_artisans;
1210 auto nation_input_mod = 1.f + state.world.nation_get_modifier_values(
1211 nations, sys::national_mod_offsets::artisan_input);
1213 if constexpr(std::is_same_v<T, dcon::nation_id>) {
1214 return std::max(alice_input_base * nation_input_mod, 0.01f);
1216 return ve::max(alice_input_base * nation_input_mod, 0.01f);
1225 auto alice_output_base = state.defines.alice_output_base_factor_artisans;
1226 auto nation_output_mod = 1.f + state.world.nation_get_modifier_values(
1227 nations, sys::national_mod_offsets::artisan_input);
1229 if constexpr(std::is_same_v<T, dcon::nation_id>) {
1230 return std::max(alice_output_base * nation_output_mod, 0.01f);
1232 return ve::max(alice_output_base * nation_output_mod, 0.01f);
1244 + state.world.nation_get_modifier_values(
nations, sys::national_mod_offsets::artisan_throughput)
1248template<
typename T,
typename S>
1253 dcon::commodity_id c
1255 auto const& inputs = state.world.commodity_get_artisan_inputs(c);
1256 ve::fp_vector input_total = 0.0f;
1257 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
1258 if(inputs.commodity_type[i]) {
1259 input_total = input_total + inputs.commodity_amounts[i] *
ve_price(state, markets, inputs.commodity_type[i]);
1265 auto output_total = state.world.commodity_get_artisan_output_amount(c) *
ve_price(state, markets, c) * state.world.market_get_supply_sold_ratio(markets, c);;
1270 return output_total * output_multiplier - input_multiplier * input_total;
1275 dcon::market_id market,
1276 dcon::commodity_id c
1278 auto sid = state.world.market_get_zone_from_local_market(market);
1279 auto nid = state.world.state_instance_get_nation_from_state_ownership(sid);
1281 auto const& inputs = state.world.commodity_get_artisan_inputs(c);
1282 auto input_total = 0.0f;
1283 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
1284 if(inputs.commodity_type[i]) {
1285 input_total = input_total + inputs.commodity_amounts[i] *
price(state, market, inputs.commodity_type[i]);
1291 auto output_total = state.world.commodity_get_artisan_output_amount(c) *
price(state, market, c) * state.world.market_get_supply_sold_ratio(market, c);;
1293 auto input_multiplier = artisan_input_multiplier<dcon::nation_id>(state, nid);
1294 auto output_multiplier = artisan_output_multiplier<dcon::nation_id>(state, nid);
1296 return output_total * output_multiplier - input_multiplier * input_total;
1303 dcon::commodity_id cid
1305 ve::mask_vector from_the_start = state.world.commodity_get_is_available_from_start(cid);
1306 ve::mask_vector active = state.world.nation_get_unlocked_commodities(
nations, cid);
1307 auto can_produce = state.world.commodity_get_artisan_output_amount(cid) > 0.0f;
1309 return can_produce && (from_the_start || active);
1315 dcon::commodity_id cid
1317 auto from_the_start = state.world.commodity_get_is_available_from_start(cid);
1318 auto active = state.world.nation_get_unlocked_commodities(
nations, cid);
1319 auto can_produce = state.world.commodity_get_artisan_output_amount(cid) > 0.0f;
1321 return can_produce && (from_the_start || active);
1324inline constexpr float ln_2 = 0.30103f;
1333 f = 1 + f + f * f / 2 + f * f * f / 6;
1347 ve::fp_vector temp = f;
1350 f = 1 + f + f * f / 2 + f * f * f / 6;
1360 ve::fp_vector result =
ve::select(temp < -128.f, 0.f, f);
1364 assert(std::isfinite(value));
1371template<
typename T,
typename S>
1377 auto const csize = state.world.commodity_size();
1378 float distribution_drift_speed = 0.001f;
1380 auto sids = state.world.market_get_zone_from_local_market(markets);
1381 auto num_artisans = state.world.state_instance_get_demographics(
1385 ve::fp_vector total{ };
1388 for(
uint32_t i = 1; i < csize; ++i) {
1389 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
1393 auto const& inputs = state.world.commodity_get_artisan_inputs(cid);
1394 ve::fp_vector min_available = 1.0f;
1395 ve::fp_vector input_total = 1.0f;
1397 for(
uint32_t j = 0; j < commodity_set::set_size; ++j) {
1398 if(inputs.commodity_type[j]) {
1399 min_available = ve::min(
1401 state.world.market_get_demand_satisfaction(markets, inputs.commodity_type[j]));
1404 + inputs.commodity_amounts[j]
1405 *
ve_price(state, markets, inputs.commodity_type[j]);
1416 base_profit / 10'000.0f - min_wage / state.defines.alice_needs_scaling_factor,
1417 std::numeric_limits<float>::lowest()
1420 auto w = state.world.market_get_artisan_score(markets, cid);
1421 auto current_employment = w * num_artisans;
1426 auto price_acceleration_from_additional_supply =
1434 auto hire_rate_from_income =
1436 * weight_short_term;
1438 auto hire_rate_from_predicted_acceleration_of_price =
1439 -price_acceleration_from_additional_supply *
supply * weight_mid_term;
1441 auto hire_rate_from_predicted_change_of_price =
1442 price_speed_change * weight_mid_term;
1444 auto money_to_workers_divisor =
1447 * price_acceleration_from_additional_supply;
1449 auto optimal_hire_change =
1451 hire_rate_from_income
1452 + hire_rate_from_predicted_acceleration_of_price
1453 + hire_rate_from_predicted_change_of_price
1454 ) / money_to_workers_divisor;
1456 auto change = optimal_hire_change * 1000.f;
1457 auto new_employment = ve::max(current_employment + change, 0.0f);
1461 new_employment / (num_artisans + 1.f),
1465 state.world.market_set_artisan_score(markets, cid, new_weight);
1466 total = total + new_weight;
1470 assert(std::isfinite(x));
1475 for(
uint32_t i = 1; i < csize; ++i) {
1476 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
1477 auto w = state.world.market_get_artisan_score(markets, cid);
1479 state.world.market_set_artisan_score(markets, cid, w);
1486 state.world.for_each_commodity([&](dcon::commodity_id c) {
1487 state.world.execute_serial_over_market([&](
auto markets) {
1488 state.world.market_set_price(markets, c, state.world.commodity_get_cost(c));
1489 state.world.market_set_demand(markets, c, ve::fp_vector{});
1490 state.world.market_set_supply(markets, c, ve::fp_vector{});
1491 state.world.market_set_consumption(markets, c, ve::fp_vector{});
1494 auto fc = fatten(state.world, c);
1497 fc.set_price_record(i, fc.get_cost());
1522 state.world.for_each_pop([&](dcon::pop_id p) {
1523 auto fp = fatten(state.world, p);
1527 fp.set_savings(fp.get_size() * expected_savings);
1532 state.world.execute_serial_over_market([&](
auto mid) {
1533 state.world.market_set_income_scale(mid, 1.f);
1536 state.world.for_each_factory([&](dcon::factory_id f) {
1537 auto ff = fatten(state.world, f);
1538 ff.set_production_scale(1.0f);
1542 auto csize = state.world.commodity_size();
1543 std::vector<std::vector<float>> per_climate_distribution_buffer(state.world.modifier_size() + 1, std::vector<float>(csize + 1, 0.f));
1544 std::vector<std::vector<float>> per_terrain_distribution_buffer(state.world.modifier_size() + 1, std::vector<float>(csize + 1, 0.f));
1545 std::vector<std::vector<float>> per_continent_distribution_buffer(state.world.modifier_size() + 1, std::vector<float>(csize + 1, 0.f));
1549 auto fp = fatten(state.world, p);
1550 dcon::commodity_id main_trade_good = state.world.province_get_rgo(p);
1551 if(state.world.commodity_get_money_rgo(main_trade_good)) {
1554 dcon::modifier_id climate = fp.get_climate();
1555 dcon::modifier_id terrain = fp.get_terrain();
1556 dcon::modifier_id continent = fp.get_continent();
1557 per_climate_distribution_buffer[climate.value][main_trade_good.value] += 1.f;
1558 per_terrain_distribution_buffer[terrain.value][main_trade_good.value] += 1.f;
1559 per_continent_distribution_buffer[continent.value][main_trade_good.value] += 1.f;
1564 float climate_sum = 0.f;
1565 float terrain_sum = 0.f;
1566 float continent_sum = 0.f;
1567 for(
uint32_t j = 0; j < csize; j++) {
1568 climate_sum += per_climate_distribution_buffer[i][j];
1569 terrain_sum += per_terrain_distribution_buffer[i][j];
1570 continent_sum += per_continent_distribution_buffer[i][j];
1572 for(
uint32_t j = 0; j < csize; j++) {
1573 per_climate_distribution_buffer[i][j] *= climate_sum == 0.f ? 1.f : 1.f / climate_sum;
1574 per_terrain_distribution_buffer[i][j] *= terrain_sum == 0.f ? 1.f : 1.f / terrain_sum;
1575 per_continent_distribution_buffer[i][j] *= continent_sum == 0.f ? 1.f : 1.f / continent_sum;
1580 auto fp = fatten(state.world, p);
1582 auto max_rgo_size = std::ceil(2000.f / state.defines.alice_rgo_per_size_employment
1585 float pop_amount = 0.0f;
1586 for(
auto pt : state.world.in_pop_type) {
1587 if(pt == state.culture_definitions.slaves) {
1588 pop_amount += state.world.province_get_demographics(p,
demographics::to_key(state, state.culture_definitions.slaves));
1589 }
else if(pt.get_is_paid_rgo_worker()) {
1593 auto size_at_the_start_of_the_game = std::ceil(pop_amount / state.defines.alice_rgo_per_size_employment);
1594 auto real_size = std::min(size_at_the_start_of_the_game * 1.5f, max_rgo_size);
1595 assert(std::isfinite(real_size));
1596 fp.set_rgo_size(real_size);
1598 if(state.world.province_get_rgo_was_set_during_scenario_creation(p)) {
1602 dcon::modifier_id climate = fp.get_climate();
1603 dcon::modifier_id terrain = fp.get_terrain();
1604 dcon::modifier_id continent = fp.get_continent();
1606 dcon::commodity_id main_trade_good = state.world.province_get_rgo(p);
1607 bool is_mine = state.world.commodity_get_is_mine(main_trade_good);
1609 state.world.for_each_commodity([&](dcon::commodity_id c) {
1610 fp.set_rgo_employment_per_good(c, 0.f);
1611 fp.set_rgo_target_employment_per_good(c, 0.f);
1614 static std::vector<float> true_distribution;
1615 true_distribution.resize(state.world.commodity_size());
1618 state.world.for_each_commodity([&](dcon::commodity_id c) {
1619 float climate_d = per_climate_distribution_buffer[climate.value][c.value];
1620 float terrain_d = per_terrain_distribution_buffer[terrain.value][c.value];
1621 float continent_d = per_continent_distribution_buffer[continent.value][c.value];
1622 float current = (climate_d + terrain_d) * (climate_d + terrain_d) * continent_d;
1623 true_distribution[c.index()] = current;
1629 state.world.for_each_commodity([&](dcon::commodity_id c) {
1630 float climate_d = per_climate_distribution_buffer[climate.value][c.value];
1631 float terrain_d = per_terrain_distribution_buffer[terrain.value][c.value];
1632 float current = (climate_d + terrain_d) * (climate_d + terrain_d);
1633 true_distribution[c.index()] = current;
1640 state.world.for_each_commodity([&](dcon::commodity_id c) {
1641 if(state.world.commodity_get_money_rgo(c)) {
1644 if(!state.world.commodity_get_is_available_from_start(c)) {
1647 float current = 1.f;
1648 true_distribution[c.index()] = current;
1653 state.world.for_each_commodity([&](dcon::commodity_id c) {
1654 assert(std::isfinite(total));
1657 true_distribution[c.index()] = 0.f;
1659 true_distribution[c.index()] /= total;
1664 state.world.for_each_commodity([&](dcon::commodity_id c) {
1665 auto fc = fatten(state.world, c);
1666 assert(std::isfinite(true_distribution[c.index()]));
1667 state.world.province_get_rgo_max_size_per_good(fp, c) += real_size * true_distribution[c.index()];
1671 state.world.for_each_nation([&](dcon::nation_id n) {
1672 auto fn = fatten(state.world, n);
1673 fn.set_administrative_spending(int8_t(80));
1674 fn.set_military_spending(int8_t(60));
1675 fn.set_education_spending(int8_t(100));
1676 fn.set_social_spending(int8_t(100));
1677 fn.set_land_spending(int8_t(100));
1678 fn.set_naval_spending(int8_t(100));
1679 fn.set_construction_spending(int8_t(100));
1680 fn.set_overseas_spending(int8_t(100));
1682 fn.set_poor_tax(int8_t(75));
1683 fn.set_middle_tax(int8_t(75));
1684 fn.set_rich_tax(int8_t(75));
1686 fn.set_spending_level(1.0f);
1689 state.world.for_each_market([&](dcon::market_id n) {
1691 state.world.for_each_commodity([&](dcon::commodity_id c) {
1692 state.world.market_set_demand_satisfaction(n, c, 0.0f);
1693 state.world.market_set_supply_sold_ratio(n, c, 0.0f);
1694 state.world.market_set_direct_demand_satisfaction(n, c, 0.0f);
1698 state.world.market_set_labor_skilled_price(n, 0.0001f);
1699 state.world.market_set_labor_unskilled_price(n, 0.0001f);
1709 state.world.for_each_nation([&](dcon::nation_id n) {
1710 state.world.nation_set_stockpiles(n,
money, 1000.f);
1723 if(state.world.nation_get_is_civilized(sphere_member)) {
1724 float base = state.world.nation_get_rank(sphere_member) <= state.defines.colonial_rank
1725 ? state.defines.second_rank_base_share_factor
1726 : state.defines.civ_base_share_factor;
1727 auto const ul = state.world.get_unilateral_relationship_by_unilateral_pair(sphere_member, sphere_leader);
1728 float sl_investment = state.world.unilateral_relationship_get_foreign_investment(ul);
1730 float investment_fraction = total_investment > 0.0001f ? sl_investment / total_investment : 0.0f;
1731 return base + (1.0f - base) * investment_fraction;
1733 return state.defines.unciv_base_share_factor;
1739 auto r = tariff_efficiency * float(state.world.nation_get_tariffs_import(n)) / 100.0f;
1740 return std::max(r, 0.0f);
1744 auto r = tariff_efficiency * float(state.world.nation_get_tariffs_export(n)) / 100.0f;
1745 return std::max(r, 0.0f);
1749 state.world.for_each_factory([&](dcon::factory_id f) {
1750 auto fac_type = fatten(state.world, state.world.factory_get_building_type(f));
1752 auto prov = state.world.factory_get_province_from_factory_location(f);
1753 auto pstate = state.world.province_get_state_membership(prov);
1754 auto powner = state.world.province_get_nation_from_province_ownership(prov);
1756 if(powner && pstate) {
1757 if(
auto mod_a = fac_type.get_bonus_1_trigger();
1759 sum -= fac_type.get_bonus_1_amount();
1761 if(
auto mod_b = fac_type.get_bonus_2_trigger();
1763 sum -= fac_type.get_bonus_2_amount();
1765 if(
auto mod_c = fac_type.get_bonus_3_trigger();
1767 sum -= fac_type.get_bonus_3_amount();
1771 state.world.factory_set_triggered_modifiers(f, sum);
1776 auto rgo_ownership = state.world.province_get_landowners_share(p) + state.world.province_get_capitalists_share(p);
1777 return state.world.province_get_rgo_size(p) * (1.f - rgo_ownership);
1781 bool is_mine = state.world.commodity_get_is_mine(c);
1784 auto rgo = state.world.province_get_rgo(p);
1787 base = state.defines.alice_base_rgo_employment_bonus / state.defines.alice_rgo_per_size_employment;
1792 auto rgo_ownership = state.world.province_get_landowners_share(p) + state.world.province_get_capitalists_share(p);
1793 auto sz = state.world.province_get_rgo_max_size_per_good(p, c) * rgo_ownership + base;
1794 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);
1795 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);
1796 auto specific_pmod = state.world.nation_get_rgo_size(n, c);
1797 auto bonus = pmod + nmod + specific_pmod + 1.0f;
1799 return std::max(sz * bonus, 0.00f);
1804 state.world.for_each_commodity([&](dcon::commodity_id c) {
1811 return state.defines.alice_rgo_per_size_employment *
subsistence_size(state, p) * 1.1f;
1816 state.world.for_each_commodity([&](dcon::commodity_id c) {
1817 total += state.world.province_get_rgo_employment_per_good(p, c);
1822float rgo_max_employment(
sys::state& state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c) {
1823 return state.defines.alice_rgo_per_size_employment *
rgo_effective_size(state, n, p, c);
1828 state.world.for_each_commodity([&](dcon::commodity_id c) {
1829 total += rgo_max_employment(state, n, p, c);
1835 state.world.execute_parallel_over_province([&](
auto ids) {
1836 auto max_subsistence = ve::apply([&](dcon::province_id p) {
1840 auto employment = state.world.province_get_subsistence_employment(ids);
1841 auto saturation = employment / (4.f + max_subsistence);
1842 auto saturation_score = 1.f / (saturation + 1.f);
1844 auto quality = (
ve::to_float(state.world.province_get_life_rating(ids)) - 10.f) / 10.f;
1845 quality = ve::max(quality, 0.f) + 0.01f;
1847 score = (score * saturation_score);
1848 state.world.province_set_subsistence_score(ids, score);
1853 return state.world.province_get_subsistence_score(p)
1854 * state.world.province_get_subsistence_employment(p)
1863 return state.world.province_get_subsistence_score(p)
1864 * state.world.province_get_subsistence_employment(p)
1869 state.world.execute_parallel_over_province([&](
auto ids) {
1870 auto local_states = state.world.province_get_state_membership(ids);
1871 auto weight_population =
1872 state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.farmers))
1873 + state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.laborers));
1874 auto weight_capitalists = weight_population / 50.f
1875 + state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.capitalists)) * 200.f;
1876 auto weight_aristocracy = weight_population / 50.f
1877 + state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.aristocrat)) * 200.f
1878 + state.world.state_instance_get_demographics(local_states,
demographics::to_key(state, state.culture_definitions.slaves));
1879 auto total = weight_aristocracy + weight_capitalists + weight_population + 1.0f;
1880 state.world.province_set_landowners_share(ids, weight_aristocracy / total);
1881 state.world.province_set_capitalists_share(ids, weight_capitalists / total);
1885int32_t factory_priority(
sys::state const& state, dcon::factory_id f) {
1886 return (state.world.factory_get_priority_low(f) ? 1 : 0) + (state.world.factory_get_priority_high(f) ? 2 : 0);
1889 state.world.factory_set_priority_high(f, priority >= 2);
1890 state.world.factory_set_priority_low(f, (priority & 1) != 0);
1893 return state.world.factory_get_unprofitable(f) ==
false || state.world.factory_get_subsidized(f);
1897 float profit = 0.0f;
1898 dcon::commodity_id
c;
1902 int32_t
last = state.province_definitions.first_sea_province.index();
1904 concurrency::parallel_for(0,
last, [&](int32_t for_index) {
1906 dcon::province_id p{ dcon::province_id::value_base_t(for_index) };
1908 auto owner = state.world.province_get_nation_from_province_ownership(p);
1909 auto s = state.world.province_get_state_membership(p);
1910 auto m = state.world.state_instance_get_market_from_local_market(s);
1911 auto current_employment = 0.f;
1912 state.world.for_each_commodity([&](dcon::commodity_id c) {
1913 current_employment += state.world.province_get_rgo_employment_per_good(p, c);
1915 current_employment += state.world.province_get_subsistence_employment(p);
1917 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
1918 float worker_pool = 0.0f;
1919 for(
auto wt : state.culture_definitions.rgo_workers) {
1922 float slave_pool = state.world.province_get_demographics(p,
demographics::to_key(state, state.culture_definitions.slaves));
1923 float labor_pool = worker_pool + slave_pool;
1927 labor_pool = std::min(labor_pool, total_population);
1935 assert(state.world.commodity_size() <= 126);
1940 state.world.for_each_commodity([&](dcon::commodity_id c) {
1941 if(rgo_max_employment(state, owner, p, c) > 0.f) {
1942 ordered_list[used_indices].
c = c;
1946 state.world.province_set_rgo_employment_per_good(p, c, 0.f);
1957 float total_workforce = labor_pool;
1958 float max_employment_total = 0.f;
1959 float total_employed = 0.f;
1961 for(
uint32_t i = 0; i < used_indices; ++i) {
1962 auto c = ordered_list[i].
c;
1963 float max_employment = rgo_max_employment(state, owner, p, c);
1964 max_employment_total += max_employment;
1965 float target_workforce = std::min(state.world.province_get_rgo_target_employment_per_good(p, c), total_workforce);
1967 float current_workforce = state.world.province_get_rgo_employment_per_good(p, c);
1968 float new_employment = std::min(current_workforce * (1 - speed) + target_workforce * speed, total_workforce);
1969 total_workforce -= new_employment;
1971 new_employment = std::clamp(new_employment, 0.f, max_employment);
1972 total_employed += new_employment;
1974 state.world.province_set_rgo_employment_per_good(p, c, new_employment);
1978 total_workforce -= subsistence;
1979 total_employed += subsistence;
1981 state.world.province_set_subsistence_employment(p, subsistence);
1983 assert(total_employed <= total_population + 1.f);
1985 float employment_ratio = 0.f;
1986 if(max_employment_total > 1.f) {
1987 employment_ratio = total_employed / (max_employment_total + 1.f);
1989 employment_ratio = 1.f;
1991 state.world.province_set_rgo_employment(p, employment_ratio);
1993 auto slave_fraction = (slave_pool > current_employment) ? current_employment / slave_pool : 1.0f;
1994 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);
1996 for(
auto pop : state.world.province_get_pop_location(p)) {
1997 auto pt =
pop.get_pop().get_poptype();
1998 if(pt == state.culture_definitions.slaves) {
2000 }
else if(pt.get_is_paid_rgo_worker()) {
2008 return state.defines.alice_factory_per_level_employment * state.world.factory_get_level(f);
2012 auto pid = state.world.factory_get_province_from_factory_location(f);
2013 auto sid = state.world.province_get_state_membership(pid);
2014 auto mid = state.world.state_instance_get_market_from_local_market(sid);
2016 auto primary_employment = state.world.factory_get_primary_employment(f)
2017 * state.world.market_get_labor_unskilled_demand_satisfaction(mid);
2018 return factory_max_employment(state, f) * (state.economy_definitions.craftsmen_fraction * primary_employment);
2021 auto pid = state.world.factory_get_province_from_factory_location(f);
2022 auto sid = state.world.province_get_state_membership(pid);
2023 auto mid = state.world.state_instance_get_market_from_local_market(sid);
2025 auto secondary_employment = state.world.factory_get_secondary_employment(f)
2026 * state.world.market_get_labor_skilled_demand_satisfaction(mid);
2027 return factory_max_employment(state, f) * ((1 - state.economy_definitions.craftsmen_fraction) * secondary_employment);
2031 auto pid = state.world.factory_get_province_from_factory_location(f);
2032 auto sid = state.world.province_get_state_membership(pid);
2033 auto mid = state.world.state_instance_get_market_from_local_market(sid);
2035 auto primary_employment =
2036 state.world.factory_get_primary_employment(f)
2037 * state.world.market_get_labor_unskilled_demand_satisfaction(mid);
2038 auto secondary_employment =
2039 state.world.factory_get_secondary_employment(f)
2040 * state.world.market_get_labor_skilled_demand_satisfaction(mid);
2041 return factory_max_employment(state, f) * (state.economy_definitions.craftsmen_fraction * primary_employment + (1 - state.economy_definitions.craftsmen_fraction) * secondary_employment);
2045 state.world.execute_serial_over_factory([&](
auto facids) {
2046 auto pid = state.world.factory_get_province_from_factory_location(facids);
2047 auto sid = state.world.province_get_state_membership(pid);
2048 auto mid = state.world.state_instance_get_market_from_local_market(sid);
2049 auto factory_type = state.world.factory_get_building_type(facids);
2050 auto output = state.world.factory_type_get_output(factory_type);
2052 auto price_output = ve::apply([&](dcon::market_id market, dcon::commodity_id cid) {
2053 return state.world.market_get_price(market, cid) +
price_rigging;
2056 auto supply = ve::apply([&](dcon::market_id market, dcon::commodity_id cid) {
2057 return state.world.market_get_supply(market, cid) +
price_rigging;
2060 auto demand = ve::apply([&](dcon::market_id market, dcon::commodity_id cid) {
2061 return state.world.market_get_demand(market, cid) +
price_rigging;
2064 auto primary = state.world.factory_get_primary_employment(facids);
2065 auto secondary = state.world.factory_get_secondary_employment(facids);
2067 auto profit_push = state.world.factory_get_output_cost_per_worker(facids);
2068 auto output_per_worker = profit_push / price_output;
2069 auto spendings_push = state.world.factory_get_input_cost_per_worker(facids);
2070 auto wage_unskilled = state.world.market_get_labor_unskilled_price(mid);
2071 auto wage_skilled = state.world.market_get_labor_skilled_price(mid);
2075 auto price_gradient_supply =
2077 auto price_gradient_time =
2080 auto wage_unskilled_per_employment =
2082 * ve::fp_vector{ state.defines.alice_factory_per_level_employment }
2083 * state.economy_definitions.craftsmen_fraction;
2084 auto wage_skilled_per_employment =
2086 * ve::fp_vector{ state.defines.alice_factory_per_level_employment }
2087 * (1.f - state.economy_definitions.craftsmen_fraction);
2089 auto current_profit =
2091 * state.world.market_get_labor_unskilled_demand_satisfaction(mid)
2096 * state.world.market_get_labor_skilled_demand_satisfaction(mid)
2099 -
primary * wage_unskilled_per_employment
2100 - secondary * wage_skilled_per_employment;
2102 float spendings_overestimation = 1.1f;
2104 auto gradient_primary =
2106 * (price_output + price_gradient_supply * 10.f + price_gradient_time * 10.f)
2110 * state.world.market_get_labor_skilled_demand_satisfaction(mid)
2113 - spendings_push * spendings_overestimation
2114 - wage_unskilled_per_employment * spendings_overestimation;
2115 auto gradient_secondary =
2117 * state.world.market_get_labor_unskilled_demand_satisfaction(mid)
2119 * (price_output + price_gradient_supply * 10.f + price_gradient_time * 10.f)
2121 - wage_skilled_per_employment * spendings_overestimation;
2124 + ve::min(0.01f, ve::max(-0.05f, 0.0001f * gradient_primary
2125 / (state.economy_definitions.craftsmen_fraction)));
2127 auto secondary_next = secondary
2128 + ve::min(0.01f, ve::max(-0.05f, 0.0001f * gradient_secondary
2129 / (1.f - state.economy_definitions.craftsmen_fraction)));
2134 primary_next = ve::max(0.f, ve::min(1.f, ve::min(10000.f / state.world.market_get_labor_unskilled_price(mid), primary_next)));
2135 secondary_next = ve::max(0.f, ve::min(1.f, ve::min(10000.f / state.world.market_get_labor_skilled_price(mid), secondary_next)));
2138 ve::apply([&](
auto value) {
assert(std::isfinite(value) && (value >= 0.f)); }, primary_next);
2139 ve::apply([&](
auto value) {
assert(std::isfinite(value) && (value >= 0.f)); }, secondary_next);
2142 state.world.factory_set_primary_employment(facids, primary_next);
2143 state.world.factory_set_secondary_employment(facids, secondary_next);
2147 state.world.for_each_state_instance([&](dcon::state_instance_id si) {
2148 auto market = state.world.state_instance_get_market_from_local_market(si);
2150 for(
auto pop : state.world.province_get_pop_location(p)) {
2151 if(pop.get_pop().get_poptype() == state.culture_definitions.primary_factory_worker) {
2152 pop_demographics::set_raw_employment(state, pop.get_pop(), state.world.market_get_labor_unskilled_supply_sold(market) * unskilled_labor_supply_multiplier(state, market));
2153 }
else if(
pop.get_pop().get_poptype() == state.culture_definitions.secondary_factory_worker) {
2154 pop_demographics::set_raw_employment(state, pop.get_pop(), state.world.market_get_labor_skilled_supply_sold(market) * skilled_labor_supply_multiplier(state, market));
2188 bool is_mine = state.world.commodity_get_is_mine(c);
2190 float main_rgo = 1.f;
2191 auto rgo = state.world.province_get_rgo(p);
2193 main_rgo = state.defines.alice_base_rgo_efficiency_bonus;
2196 float base_amount = state.world.commodity_get_rgo_amount(c);
2199 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_rgo_throughput)
2200 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rgo_throughput)
2201 + state.world.province_get_modifier_values(p,
2203 sys::provincial_mod_offsets::mine_rgo_eff
2205 sys::provincial_mod_offsets::farm_rgo_eff)
2206 + state.world.nation_get_modifier_values(n,
2208 sys::national_mod_offsets::mine_rgo_eff
2210 sys::national_mod_offsets::farm_rgo_eff);
2212 float saturation = std::clamp(state.world.province_get_rgo_employment_per_good(p, c)
2213 / (rgo_max_employment(state, n, p, c) + 1.f), 0.0f, 1.0f);
2215 float result = base_amount
2217 * (1.f + 1.0f * (1.f - saturation))
2219 * state.defines.alice_rgo_boost
2220 * std::max(0.5f, (1.0f + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_rgo_output) +
2221 state.world.nation_get_modifier_values(n, sys::national_mod_offsets::rgo_output) +
2222 state.world.nation_get_rgo_goods_output(n, c)));
2224 assert(result >= 0.0f && std::isfinite(result));
2238 assert(val >= 0.0f && std::isfinite(val));
2245 dcon::factory_type_id fac_type
2247 float min_input_available = 1.0f;
2248 auto& inputs = state.world.factory_type_get_inputs(fac_type);
2249 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2250 if(inputs.commodity_type[i]) {
2251 min_input_available =
2253 min_input_available,
2254 state.world.market_get_demand_satisfaction(m, inputs.commodity_type[i])
2260 return min_input_available;
2264 float input_total = 0.0f;
2265 auto& inputs = state.world.factory_type_get_inputs(fac_type);
2266 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2267 if(inputs.commodity_type[i]) {
2268 input_total += inputs.commodity_amounts[i] *
price(state, m, inputs.commodity_type[i]);
2277 float min_e_input_available = 1.0f;
2278 auto& e_inputs = state.world.factory_type_get_efficiency_inputs(fac_type);
2279 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
2280 if(e_inputs.commodity_type[i]) {
2281 min_e_input_available =
2283 min_e_input_available,
2284 state.world.market_get_demand_satisfaction(m, e_inputs.commodity_type[i])
2291 return min_e_input_available;
2295 float e_input_total = 0.0f;
2296 auto& e_inputs = state.world.factory_type_get_efficiency_inputs(fac_type);
2297 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
2298 if(e_inputs.commodity_type[i]) {
2299 e_input_total += e_inputs.commodity_amounts[i] *
price(state, m, e_inputs.commodity_type[i]);
2305 return e_input_total;
2309 auto exp = state.world.nation_get_factory_type_experience(n, fac_type);
2310 return 100000.f / (100000.f + exp);
2316 return mult * std::max(
2318 state.defines.alice_inputs_base_factor
2319 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_input)
2323 auto output = state.world.factory_type_get_output(fac_type);
2324 return state.world.nation_get_factory_goods_output(n,
output)
2325 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_output)
2331 float small_size_effect = 1.f;
2332 float small_bound = state.defines.alice_factory_per_level_employment * 5.f;
2333 if(total_workers < small_bound) {
2334 small_size_effect = 0.5f + total_workers / small_bound * 0.5f;
2337 float total_state_pop = std::max(0.01f, state.world.state_instance_get_demographics(s,
demographics::total));
2338 float capitalists = state.world.state_instance_get_demographics(s,
demographics::to_key(state, state.culture_definitions.capitalists));
2339 float owner_fraction = total_state_pop > 0
2342 capitalists / total_state_pop)
2345 auto ftid = state.world.factory_get_building_type(fac);
2348 return std::max(0.001f, small_size_effect *
2349 state.world.factory_get_triggered_modifiers(fac) *
2354 state.defines.alice_inputs_base_factor
2355 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_factory_input)
2356 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_input)
2357 + owner_fraction * -2.5f
2363 auto output = state.world.factory_type_get_output(fac_type);
2364 auto national_t = state.world.nation_get_factory_goods_throughput(n,
output);
2365 auto provincial_fac_t = state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_factory_throughput);
2366 auto nationnal_fac_t = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_throughput);
2369 * std::max(0.f, 1.f + national_t)
2370 * std::max(0.f, 1.f + provincial_fac_t)
2371 * std::max(0.f, 1.f + nationnal_fac_t);
2377 auto fac_type = state.world.factory_get_building_type(fac);
2378 return std::max(0.f,
2379 state.world.nation_get_factory_goods_output(n, fac_type.get_output())
2380 + state.world.province_get_modifier_values(p, sys::provincial_mod_offsets::local_factory_output)
2381 + state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_output)
2388 state.world.factory_get_secondary_employment(fac)
2389 * state.world.market_get_labor_skilled_demand_satisfaction(m)
2396 return fac.get_primary_employment()
2401 return state.world.factory_get_primary_employment(fac)
2402 * state.world.factory_get_level(fac)
2403 * (occupied ? 0.1f : 1.0f)
2404 * std::max(0.0f, mobilization_impact);
2409 return spendings * 1.01f;
2415 dcon::province_id p,
2416 dcon::state_instance_id s,
2419 float mobilization_impact,
2422 auto fac = fatten(state.world, f);
2423 auto fac_type = fac.get_building_type();
2426 assert(fac_type.get_output());
2441 auto const mfactor = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
2445 float bonus_profit_thanks_to_max_e_input = fac_type.get_output_amount()
2447 * throughput_multiplier
2449 * min_input_available
2450 *
price(state, m, fac_type.get_output());
2453 if(bonus_profit_thanks_to_max_e_input < e_input_total * mfactor * input_multiplier)
2454 min_e_input_available = 0.f;
2457 float total_production = fac_type.get_output_amount()
2458 * (0.75f + 0.25f * min_e_input_available)
2459 * throughput_multiplier
2461 * min_input_available;
2463 assert(min_input_available >= 0.f);
2464 assert(output_multiplier >= 0.f);
2465 assert(throughput_multiplier >= 0.f);
2466 assert(min_e_input_available >= 0.f);
2471 *
price(state, m, fac_type.get_output());
2473 float profit_if_inputs_were_satisfied =
2474 fac_type.get_output_amount()
2475 * throughput_multiplier
2477 *
price(state, m, fac_type.get_output());
2479 fac.set_output_cost_per_worker(
2480 fac_type.get_output_amount()
2481 * (0.75f + 0.25f * min_e_input_available)
2482 * min_input_available
2483 * throughput_multiplier
2485 *
price(state, m, fac_type.get_output())
2491 float base_spendings =
2494 * min_input_available
2499 * min_e_input_available;
2501 float spending_on_inputs_if_inputs_were_satisfied =
2505 float spending_on_e_inputs_if_inputs_were_satisfied =
2510 assert(base_profit >= 0.f);
2511 assert(base_spendings >= 0.f);
2513 float base_scale = std::min(1.f, (base_profit + 1.f) / (base_spendings + 1.f));
2517 float input_cost_per_employment_unit =
2519 * throughput_multiplier
2521 * min_input_available
2523 input_multiplier * mfactor
2525 * min_e_input_available
2526 * min_input_available;
2529 state.world.market_get_labor_unskilled_price(m)
2530 * state.defines.alice_factory_per_level_employment
2531 + input_cost_per_employment_unit;
2533 fac.set_input_cost_per_worker(input_cost_per_employment_unit);
2536 float max_pure_profit = profit - spendings;
2537 state.world.factory_set_unprofitable(f, max_pure_profit <= 0.0f);
2542 mobilization_impact,
2545 fac.set_production_scale(
2546 state.world.factory_get_primary_employment(fac)
2547 * state.world.market_get_labor_unskilled_demand_satisfaction(m)
2550 auto unskilled_labour_demand =
2551 fac.get_primary_employment()
2553 * state.economy_definitions.craftsmen_fraction;
2555 auto skilled_labour_demand =
2556 fac.get_secondary_employment()
2558 * (1.f - state.economy_definitions.craftsmen_fraction);
2560 state.world.market_get_labor_unskilled_demand(m) += unskilled_labour_demand;
2561 state.world.market_get_labor_skilled_demand(m) += skilled_labour_demand;
2563 auto& inputs = fac_type.get_inputs();
2564 auto& e_inputs = fac_type.get_efficiency_inputs();
2578 auto min_input_importance = std::min(1.f, profit_if_inputs_were_satisfied / (spending_on_inputs_if_inputs_were_satisfied + 0.00001f));
2579 auto min_input_coefficient = (min_input_importance + (1.f - min_input_importance) * min_input_available);
2581 auto min_e_input_importance = std::min(1.f, profit_if_inputs_were_satisfied * 0.25f / (spending_on_e_inputs_if_inputs_were_satisfied + 0.00001f));
2582 auto min_e_input_coefficient = (min_e_input_importance + (1.f - min_e_input_importance) * min_e_input_available);
2584 assert(input_multiplier >= 0.f);
2585 assert(throughput_multiplier >= 0.f);
2586 assert(production_scale >= 0.f);
2587 assert(min_input_coefficient >= 0.f);
2588 assert(base_scale >= 0.f);
2592 * throughput_multiplier
2594 * min_input_coefficient
2597 assert(input_scale >= 0.f);
2599 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
2600 if(inputs.commodity_type[i]) {
2603 inputs.commodity_type[i],
2605 * inputs.commodity_amounts[i]
2606 , economy_reason::factory
2616 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
2617 if(e_inputs.commodity_type[i]) {
2621 e_inputs.commodity_type[i],
2624 * e_inputs.commodity_amounts[i]
2625 * min_e_input_coefficient
2626 , economy_reason::factory
2633 float actual_production = total_production * production_scale;
2634 float pure_profit = max_pure_profit * production_scale;
2636 state.world.factory_set_actual_production(f, actual_production);
2637 state.world.factory_set_full_profit(f, pure_profit);
2646 auto production = state.world.factory_get_actual_production(f);
2647 if(production > 0) {
2648 auto fac = fatten(state.world, f);
2649 auto fac_type = fac.get_building_type();
2651 state.world.factory_get_full_profit(f)
2652 * state.world.market_get_supply_sold_ratio(m, fac_type.get_output());
2654 state.world.factory_set_actual_production(f, production);
2657 if(!fac.get_subsidized()) {
2658 state.world.factory_set_full_profit(f, money_made);
2662 float wages = wage_primary + wage_secondary;
2664 if(money_made < wages) {
2665 auto diff = wages - money_made;
2667 state.world.factory_set_full_profit(f, wages);
2668 state.world.nation_get_stockpiles(n,
money) -= diff;
2669 state.world.nation_get_subsidies_spending(n) += diff;
2671 state.world.factory_set_full_profit(f, std::max(money_made, 0.0f));
2672 fac.set_subsidized(
false);
2675 state.world.factory_set_full_profit(f, money_made);
2683 auto relevant_paid_population = 0.f;
2684 for(
auto wt : state.culture_definitions.rgo_workers) {
2685 relevant_paid_population += state.world.province_get_demographics(p,
demographics::to_key(state, wt));
2690 .paid_workers = relevant_paid_population,
2692 .total = relevant_paid_population + slaves
2700 dcon::province_id p,
2703 float min_wage,
float total_relevant_population
2708 float perfect_aristos_amount = total_relevant_population / 1000.f;
2709 float perfect_aristos_amount_adjusted = perfect_aristos_amount / state.defines.alice_needs_scaling_factor;
2710 float aristos_desired_cut =
aristocrats_greed * perfect_aristos_amount_adjusted * (
2711 state.world.market_get_everyday_needs_costs(m, state.culture_definitions.aristocrat)
2712 + state.world.market_get_life_needs_costs(m, state.culture_definitions.aristocrat)
2715 float aristo_burden_per_worker = aristos_desired_cut / (total_relevant_population + 1);
2718 if(subsistence == 0) subsistence = state.world.province_get_subsistence_score(p);
2720 subsistence -= subsistence_life;
2722 subsistence -= subsistence_everyday;
2727 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
2729 dcon::pop_type_id pop_type = is_mine ? state.culture_definitions.laborers : state.culture_definitions.farmers;
2731 auto ln_costs = state.world.market_get_life_needs_costs(m, pop_type);
2732 auto en_costs = state.world.market_get_everyday_needs_costs(m, pop_type);
2733 auto lx_costs = state.world.market_get_luxury_needs_costs(m, pop_type);
2735 float subsistence_based_min_wage =
2736 subsistence_life * ln_costs
2737 + subsistence_everyday * en_costs;
2747 float min_wage_burden_per_worker =
2748 (1000.f + min_wage + subsistence_based_min_wage) / state.defines.alice_needs_scaling_factor;
2750 float desired_profit_by_worker = aristo_burden_per_worker + min_wage_burden_per_worker;
2758 assert(std::isfinite(desired_profit_by_worker));
2761 return desired_profit_by_worker;
2766 dcon::province_id p,
2769 dcon::commodity_id c
2772 auto current_price =
price(state, m, c);
2777 / state.defines.alice_rgo_per_size_employment;
2781 return 1.f - (1.f - x) * (1.f - x);
2787 dcon::province_id p,
2790 float mobilization_impact,
2791 float expected_min_wage
2796 state.world.for_each_commodity([&](dcon::commodity_id c) {
2798 if(max_production < 0.001f) {
2803 auto pops_max = rgo_max_employment(state, n, p, c);
2804 auto current_employment = state.world.province_get_rgo_employment_per_good(p, c);
2807 auto efficiency_per_hire =
rgo_efficiency(state, n, p, c) / state.defines.alice_rgo_per_size_employment;
2809 auto desired_price = desired_profit / efficiency_per_hire;
2811 auto current_price =
price(state, m, c) - desired_price;
2817 if(state.world.commodity_get_money_rgo(c)) {
2822 auto price_acceleration_from_additional_supply =
2829 if(current_price >= 0.f) {
2835 auto hire_rate_from_income =
2837 * weight_short_term;
2839 auto hire_rate_from_predicted_acceleration_of_price =
2840 -price_acceleration_from_additional_supply *
supply * weight_mid_term;
2842 auto hire_rate_from_predicted_change_of_price =
2843 price_speed_change * weight_mid_term;
2845 auto money_to_workers_divisor =
2848 * efficiency_per_hire
2849 * price_acceleration_from_additional_supply;
2851 auto optimal_hire_change =
2853 hire_rate_from_income
2854 + hire_rate_from_predicted_acceleration_of_price
2855 + hire_rate_from_predicted_change_of_price
2856 ) / money_to_workers_divisor;
2858 auto change = optimal_hire_change;
2860 change = std::clamp(change, -rgo_pops.total * 0.01f, rgo_pops.total * 0.01f);
2862 assert(std::isfinite(current_employment + change));
2863 auto new_employment = std::clamp(current_employment + change, 0.0f, pops_max);
2864 state.world.province_set_rgo_target_employment_per_good(p, c, new_employment);
2867 float employment_ratio = current_employment / pops_max;
2868 assert(max_production * employment_ratio >= 0);
2869 state.world.province_set_rgo_actual_production_per_good(p, c, max_production * employment_ratio);
2875 dcon::province_id p,
2879 state.world.province_set_rgo_full_profit(p, 0.f);
2880 state.world.for_each_commodity([&](dcon::commodity_id c) {
2881 auto amount = state.world.province_get_rgo_actual_production_per_good(p, c);
2885 float profit = amount * state.world.market_get_price(m, c) * state.world.market_get_supply_sold_ratio(m, c);
2887 if(state.world.commodity_get_money_rgo(c)) {
2888 profit = amount * state.world.market_get_price(m, c);
2893 state.world.province_set_rgo_profit_per_good(p, c, profit);
2894 state.world.province_get_rgo_full_profit(p) += profit;
2896 if(state.world.commodity_get_money_rgo(c)) {
2900 * state.defines.gold_to_cash_rate
2901 * state.world.commodity_get_cost(c)
2903 && amount * state.defines.gold_to_cash_rate >= 0.0f
2905 state.world.nation_get_stockpiles(n,
money) +=
2907 * state.defines.gold_to_cash_rate
2908 * state.world.commodity_get_cost(c);
2913template<
typename T,
typename S,
typename U>
2919 ve::fp_vector expected_min_wage,
2920 ve::fp_vector mobilization_impact
2922 auto const csize = state.world.commodity_size();
2923 auto num_artisans = state.world.state_instance_get_demographics(
2925 ve::fp_vector total_profit = 0.0f;
2927 for(
uint32_t i = 1; i < csize; ++i) {
2928 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
2929 state.world.market_set_artisan_actual_production(markets, cid, 0.0f);
2933 ve::fp_vector input_total = 0.0f;
2934 auto const& inputs = state.world.commodity_get_artisan_inputs(cid);
2935 ve::fp_vector min_available = 1.0f;
2936 for(
uint32_t j = 0; j < commodity_set::set_size; ++j) {
2937 if(inputs.commodity_type[j]) {
2940 + inputs.commodity_amounts[j]
2941 *
ve_price(state, markets, inputs.commodity_type[j]);
2942 min_available = ve::min(
2944 state.world.market_get_demand_satisfaction(markets, inputs.commodity_type[j]));
2950 ve::fp_vector output_total =
2951 state.world.commodity_get_artisan_output_amount(cid)
2958 ve::fp_vector distribution = state.world.market_get_artisan_score(markets, cid);
2960 ve::fp_vector max_production_scale =
2962 * distribution / 10'000.0f
2963 * mobilization_impact;
2965 auto profit_if_inputs_were_satisfied = output_total * output_multiplier * throughput_multiplier;
2966 auto spending_on_inputs_if_inputs_were_satisfied = input_multiplier * input_total * throughput_multiplier;
2968 auto min_input_importance = ve::min(1.f, profit_if_inputs_were_satisfied / (spending_on_inputs_if_inputs_were_satisfied + 0.00001f));
2969 auto min_input_coefficient = (min_input_importance + (1.f - min_input_importance) * min_available);
2974 * throughput_multiplier
2975 * max_production_scale
2976 * min_input_coefficient,
2982 state.world.commodity_get_artisan_output_amount(cid)
2983 * throughput_multiplier
2985 * max_production_scale
2990 auto profitability_factor =
2992 output_total * output_multiplier * throughput_multiplier * min_available
2993 - input_multiplier * input_total * throughput_multiplier * min_available
2994 ) / (0.5f * expected_min_wage * (10'000.0f / state.defines.alice_needs_scaling_factor));
2996 for(
uint32_t j = 0; j < commodity_set::set_size; ++j) {
2997 if(inputs.commodity_type[j]) {
3001 inputs.commodity_type[j],
3002 demand_mod * inputs.commodity_amounts[j],
3003 economy_reason::artisan
3010 state.world.market_set_artisan_actual_production(
3017 output_total * output_multiplier * state.world.market_get_supply_sold_ratio(markets, cid)
3018 - input_multiplier * input_total;
3020 total_profit = total_profit
3023 * throughput_multiplier
3024 * max_production_scale
3029 state.world.market_set_artisan_profit(markets, total_profit);
3034 auto const csize = state.world.commodity_size();
3035 for(
uint32_t i = 1; i < csize; ++i) {
3036 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3037 auto production = state.world.market_get_artisan_actual_production(markets, cid);
3043 uint32_t total_commodities = state.world.commodity_size();
3044 for(
uint32_t i = 1; i < total_commodities; ++i) {
3045 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3046 state.world.execute_serial_over_market([&](
auto ids) {
3047 state.world.market_set_army_demand(ids, cid, 0.0f);
3051 state.world.for_each_regiment([&](dcon::regiment_id r) {
3052 auto reg = fatten(state.world, r);
3053 auto type = state.world.regiment_get_type(r);
3054 auto owner = reg.get_army_from_army_membership().get_controller_from_army_control();
3055 auto pop = reg.get_pop_from_regiment_source();
3056 auto location =
pop.get_pop_location().get_province().get_state_membership();
3057 auto market = location.get_market_from_local_market();
3058 auto scale = owner.get_spending_level();
3059 auto strength = reg.get_strength();
3062 auto o_sc_mod = std::max(
3064 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::supply_consumption)
3067 auto& supply_cost = state.military_definitions.unit_base_definitions[type].supply_cost;
3068 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3069 if(supply_cost.commodity_type[i]) {
3072 state.world.market_get_army_demand(market, supply_cost.commodity_type[i]) +=
3073 supply_cost.commodity_amounts[i]
3074 * state.world.nation_get_unit_stats(owner, type).supply_consumption
3075 * o_sc_mod * strength;
3080 auto& build_cost = state.military_definitions.unit_base_definitions[type].build_cost;
3082 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3083 if(build_cost.commodity_type[i]) {
3085 if(reinforcement > 0) {
3087 state.world.market_get_army_demand(market, build_cost.commodity_type[i]) +=
3088 build_cost.commodity_amounts[i]
3100 uint32_t total_commodities = state.world.commodity_size();
3101 for(
uint32_t i = 1; i < total_commodities; ++i) {
3102 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3103 state.world.execute_serial_over_market([&](
auto ids) {
3104 state.world.market_set_navy_demand(ids, cid, 0.0f);
3108 state.world.for_each_ship([&](dcon::ship_id r) {
3109 auto shp = fatten(state.world, r);
3110 auto type = state.world.ship_get_type(r);
3111 auto owner = shp.get_navy_from_navy_membership().get_controller_from_navy_control();
3112 auto market = owner.get_capital().get_state_membership().get_market_from_local_market();
3115 auto o_sc_mod = std::max(
3117 state.world.nation_get_modifier_values(owner, sys::national_mod_offsets::supply_consumption)
3121 auto& supply_cost = state.military_definitions.unit_base_definitions[type].supply_cost;
3122 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3123 if(supply_cost.commodity_type[i]) {
3124 state.world.market_get_navy_demand(market, supply_cost.commodity_type[i]) +=
3125 supply_cost.commodity_amounts[i]
3126 * state.world.nation_get_unit_stats(owner, type).supply_consumption
3133 auto& build_cost = state.military_definitions.unit_base_definitions[type].build_cost;
3135 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3136 if(build_cost.commodity_type[i]) {
3138 if(reinforcement > 0) {
3140 state.world.market_get_army_demand(market, build_cost.commodity_type[i]) +=
3141 build_cost.commodity_amounts[i]
3192 uint32_t total_commodities = state.world.commodity_size();
3193 for(
uint32_t i = 1; i < total_commodities; ++i) {
3194 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3195 state.world.execute_serial_over_market([&](
auto ids) {
3196 state.world.market_set_construction_demand(ids, cid, 0.0f);
3200 static auto total_budget = state.world.nation_make_vectorizable_float_buffer();
3201 static auto current_budget = state.world.nation_make_vectorizable_float_buffer();
3202 static auto going_constructions = state.world.nation_make_vectorizable_int_buffer();
3204 state.world.execute_serial_over_nation([&](
auto ids) {
3205 auto base_budget = state.world.nation_get_stockpiles(ids,
economy::money);
3206 auto construction_priority =
ve::to_float(state.world.nation_get_construction_spending(ids)) / 100.f;
3207 current_budget.set(ids, ve::max(0.f, base_budget * construction_priority));
3208 total_budget.set(ids, ve::max(0.f, base_budget * construction_priority));
3211 for(
auto lc : state.world.in_province_land_construction) {
3212 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
3213 auto owner = state.world.province_get_nation_from_province_ownership(
province);
3214 if(owner && state.world.province_get_nation_from_province_control(
province) == owner) {
3215 going_constructions.get(owner) += 1;
3219 auto owner = state.world.province_get_nation_from_province_ownership(p);
3220 if(!owner || state.world.province_get_nation_from_province_control(p) != owner)
3222 auto rng = state.world.province_get_province_naval_construction(p);
3223 if(
rng.begin() ==
rng.end())
3225 going_constructions.get(owner) += 1;
3227 for(
auto c : state.world.in_province_building_construction) {
3228 auto owner = c.get_nation().id;
3229 if(owner && c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
3230 going_constructions.get(owner) += 1;
3233 for(
auto c : state.world.in_state_building_construction) {
3234 auto owner = c.get_nation().id;
3235 if(owner && !c.get_is_pop_project()) {
3236 going_constructions.get(owner) += 1;
3241 for(
auto lc : state.world.in_province_land_construction) {
3242 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
3243 auto owner = state.world.province_get_nation_from_province_ownership(
province);
3244 float& base_budget = current_budget.get(owner);
3245 float budget_limit = total_budget.get(owner) / float(std::max(1, going_constructions.get(owner)));
3247 auto local_zone = state.world.province_get_state_membership(
province);
3248 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3250 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3251 float admin_cost_factor = 2.0f - admin_eff;
3253 if(owner && state.world.province_get_nation_from_province_control(
province) == owner) {
3255 state.military_definitions.unit_base_definitions[
3256 state.world.province_land_construction_get_type(lc)
3258 auto& current_purchased
3259 = state.world.province_land_construction_get_purchased_goods(lc);
3260 float construction_time =
3262 * float(state.military_definitions.unit_base_definitions[
3263 state.world.province_land_construction_get_type(lc)
3267 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3268 auto cid = base_cost.commodity_type[i];
3272 current_purchased.commodity_amounts[i]
3274 base_cost.commodity_amounts[i] * admin_cost_factor
3277 auto can_purchase_budget = std::min(budget_limit, base_budget) / (
price(state, market, cid) + 0.001f);
3278 auto can_purchase_construction = base_cost.commodity_amounts[i]
3280 / construction_time;
3282 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3283 base_budget = std::max(0.f, base_budget - can_purchase *
price(state, market, cid));
3295 auto owner = state.world.province_get_nation_from_province_ownership(p);
3297 auto local_zone = state.world.province_get_state_membership(p);
3298 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3300 if(!owner || state.world.province_get_nation_from_province_control(p) != owner)
3302 auto rng = state.world.province_get_province_naval_construction(p);
3303 if(
rng.begin() ==
rng.end())
3306 auto c = *(
rng.begin());
3308 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3309 float admin_cost_factor = 2.0f - admin_eff;
3311 float& base_budget = current_budget.get(owner);
3312 float budget_limit = total_budget.get(owner) /
float(std::max(1, going_constructions.get(owner)));
3313 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
3314 auto& current_purchased = c.get_purchased_goods();
3316 float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
3318 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3319 auto cid = base_cost.commodity_type[i];
3323 current_purchased.commodity_amounts[i]
3325 base_cost.commodity_amounts[i] * admin_cost_factor
3328 auto can_purchase_budget = std::min(budget_limit, base_budget) / (price(state, market, cid) + 0.001f);
3329 auto can_purchase_construction = base_cost.commodity_amounts[i]
3331 / construction_time;
3333 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3334 base_budget = std::max(0.f, base_budget - can_purchase * price(state, market, cid));
3335 register_construction_demand(
3344 for(
auto c : state.world.in_province_building_construction) {
3345 auto owner = c.get_nation().id;
3346 auto spending_scale = state.world.nation_get_spending_level(owner);
3347 auto local_zone = c.get_province().get_state_membership();
3348 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3349 if(owner && c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
3351 float& base_budget = current_budget.get(owner);
3352 float budget_limit = total_budget.get(owner) / float(std::max(1, going_constructions.get(owner)));
3353 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
3354 auto& current_purchased = c.get_purchased_goods();
3356 float(state.economy_definitions.building_definitions[int32_t(t)].time);
3358 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3359 float admin_cost_factor = 2.0f - admin_eff;
3361 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3362 auto cid = base_cost.commodity_type[i];
3364 if(current_purchased.commodity_amounts[i] >
3365 base_cost.commodity_amounts[i] * admin_cost_factor)
continue;
3367 auto can_purchase_budget = std::max(budget_limit, base_budget) / (
price(state, market, cid) + 0.001f);
3368 auto can_purchase_construction = base_cost.commodity_amounts[i]
3370 / construction_time;
3372 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3373 base_budget = std::max(0.f, base_budget - can_purchase *
price(state, market, cid));
3384 for(
auto c : state.world.in_state_building_construction) {
3385 auto owner = c.get_nation().id;
3386 auto spending_scale = state.world.nation_get_spending_level(owner);
3387 auto market = state.world.state_instance_get_market_from_local_market(c.get_state());
3388 if(owner && !c.get_is_pop_project()) {
3389 float& base_budget = current_budget.get(owner);
3390 float budget_limit = total_budget.get(owner) / float(std::max(1, going_constructions.get(owner)));
3391 auto& base_cost = c.get_type().get_construction_costs();
3392 auto& current_purchased = c.get_purchased_goods();
3394 float construction_time =
3396 * float(c.get_type().get_construction_time())
3397 * (c.get_is_upgrade() ? 0.5f : 1.0f);
3400 state.world.nation_get_modifier_values(
3402 sys::national_mod_offsets::factory_cost
3405 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3406 float admin_cost_factor = 2.0f - admin_eff;
3408 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3409 auto cid = base_cost.commodity_type[i];
3411 if(current_purchased.commodity_amounts[i] >
3412 base_cost.commodity_amounts[i] * admin_cost_factor * factory_mod)
continue;
3414 auto can_purchase_budget = std::max(budget_limit, base_budget) / (
price(state, market, cid) + 0.001f);
3415 auto can_purchase_construction = base_cost.commodity_amounts[i]
3418 / construction_time;
3420 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3421 base_budget = std::max(0.f, base_budget - can_purchase *
price(state, market, cid));
3434 uint32_t total_commodities = state.world.commodity_size();
3436 auto total_cost = 0.f;
3437 int going_constructions = 0;
3439 for(
auto lc : state.world.in_province_land_construction) {
3440 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
3441 auto owner = state.world.province_get_nation_from_province_ownership(
province);
3446 if(owner && state.world.province_get_nation_from_province_control(
province) == owner) {
3447 going_constructions++;
3451 state.world.nation_for_each_province_ownership(n, [&](
auto ownership) {
3453 auto p = state.world.province_ownership_get_province(ownership);
3455 auto local_zone = state.world.province_get_state_membership(p);
3456 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3458 if(!owner || state.world.province_get_nation_from_province_control(p) != owner)
3460 auto rng = state.world.province_get_province_naval_construction(p);
3461 if(
rng.begin() ==
rng.end())
3464 going_constructions++;
3467 for(
auto c : state.world.in_province_building_construction) {
3468 auto owner = c.get_nation().id;
3472 auto spending_scale = state.world.nation_get_spending_level(owner);
3473 auto local_zone = c.get_province().get_state_membership();
3474 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3475 if(owner && c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
3476 going_constructions++;
3480 for(
auto c : state.world.in_state_building_construction) {
3481 auto owner = c.get_nation().id;
3485 auto spending_scale = state.world.nation_get_spending_level(owner);
3486 auto market = state.world.state_instance_get_market_from_local_market(c.get_state());
3487 if(owner && !c.get_is_pop_project()) {
3488 going_constructions++;
3492 if(going_constructions == 0) {
3496 float budget_limit = current_budget / going_constructions;
3505 for(
auto lc : state.world.in_province_land_construction) {
3506 auto province = state.world.pop_get_province_from_pop_location(state.world.province_land_construction_get_pop(lc));
3507 auto owner = state.world.province_get_nation_from_province_ownership(
province);
3513 float& base_budget = current_budget;
3515 auto local_zone = state.world.province_get_state_membership(
province);
3516 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3518 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3519 float admin_cost_factor = 2.0f - admin_eff;
3521 if(owner && state.world.province_get_nation_from_province_control(
province) == owner) {
3523 state.military_definitions.unit_base_definitions[
3524 state.world.province_land_construction_get_type(lc)
3526 auto& current_purchased
3527 = state.world.province_land_construction_get_purchased_goods(lc);
3528 float construction_time =
3530 * float(state.military_definitions.unit_base_definitions[
3531 state.world.province_land_construction_get_type(lc)
3535 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3536 auto cid = base_cost.commodity_type[i];
3540 current_purchased.commodity_amounts[i]
3542 base_cost.commodity_amounts[i] * admin_cost_factor
3545 auto can_purchase_budget = std::min(budget_limit, base_budget) / (
price(state, market, cid) + 0.001f);
3546 auto can_purchase_construction = base_cost.commodity_amounts[i]
3548 / construction_time;
3550 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3551 auto cost = std::min(base_budget, can_purchase *
price(state, market, cid));
3552 base_budget -= cost;
3553 total_cost += cost * state.world.market_get_demand_satisfaction(market, cid);
3558 state.world.nation_for_each_province_ownership(n, [&](
auto ownership) {
3560 auto p = state.world.province_ownership_get_province(ownership);
3562 auto local_zone = state.world.province_get_state_membership(p);
3563 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3565 if(!owner || state.world.province_get_nation_from_province_control(p) != owner)
3567 auto rng = state.world.province_get_province_naval_construction(p);
3568 if(
rng.begin() ==
rng.end())
3571 auto c = *(
rng.begin());
3573 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3574 float admin_cost_factor = 2.0f - admin_eff;
3576 float& base_budget = current_budget;
3577 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
3578 auto& current_purchased = c.get_purchased_goods();
3580 float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
3582 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3583 auto cid = base_cost.commodity_type[i];
3587 current_purchased.commodity_amounts[i]
3589 base_cost.commodity_amounts[i] * admin_cost_factor
3592 auto can_purchase_budget = std::min(budget_limit, base_budget) / (price(state, market, cid) + 0.001f);
3593 auto can_purchase_construction = base_cost.commodity_amounts[i]
3595 / construction_time;
3597 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3598 auto cost = std::min(base_budget, can_purchase * price(state, market, cid));
3599 base_budget -= cost;
3600 total_cost += cost * state.world.market_get_demand_satisfaction(market, cid);
3604 for(
auto c : state.world.in_province_building_construction) {
3605 auto owner = c.get_nation().id;
3609 auto spending_scale = state.world.nation_get_spending_level(owner);
3610 auto local_zone = c.get_province().get_state_membership();
3611 auto market = state.world.state_instance_get_market_from_local_market(local_zone);
3612 if(owner && c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control() && !c.get_is_pop_project()) {
3614 float& base_budget = current_budget;
3615 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
3616 auto& current_purchased = c.get_purchased_goods();
3618 float(state.economy_definitions.building_definitions[int32_t(t)].time);
3620 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3621 float admin_cost_factor = 2.0f - admin_eff;
3623 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3624 auto cid = base_cost.commodity_type[i];
3626 if(current_purchased.commodity_amounts[i] >
3627 base_cost.commodity_amounts[i] * admin_cost_factor)
continue;
3629 auto can_purchase_budget = std::min(budget_limit, base_budget) / (
price(state, market, cid) + 0.001f);
3630 auto can_purchase_construction = base_cost.commodity_amounts[i]
3632 / construction_time;
3634 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3636 auto cost = std::min(base_budget, can_purchase *
price(state, market, cid));
3637 base_budget -= cost;
3638 total_cost += cost * state.world.market_get_demand_satisfaction(market, cid);
3643 for(
auto c : state.world.in_state_building_construction) {
3644 auto owner = c.get_nation().id;
3648 auto spending_scale = state.world.nation_get_spending_level(owner);
3649 auto market = state.world.state_instance_get_market_from_local_market(c.get_state());
3650 if(owner && !c.get_is_pop_project()) {
3651 float& base_budget = current_budget;
3652 auto& base_cost = c.get_type().get_construction_costs();
3653 auto& current_purchased = c.get_purchased_goods();
3655 float construction_time =
3657 * float(c.get_type().get_construction_time())
3658 * (c.get_is_upgrade() ? 0.5f : 1.0f);
3661 state.world.nation_get_modifier_values(
3663 sys::national_mod_offsets::factory_cost
3666 float admin_eff = state.world.nation_get_administrative_efficiency(owner);
3667 float admin_cost_factor = 2.0f - admin_eff;
3669 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3670 auto cid = base_cost.commodity_type[i];
3672 if(current_purchased.commodity_amounts[i] >
3673 base_cost.commodity_amounts[i] * admin_cost_factor * factory_mod)
continue;
3675 auto can_purchase_budget = std::min(budget_limit, base_budget) / (
price(state, market, cid) + 0.001f);
3676 auto can_purchase_construction = base_cost.commodity_amounts[i]
3679 / construction_time;
3681 auto can_purchase = std::min(can_purchase_budget, can_purchase_construction);
3682 auto cost = std::min(base_budget, can_purchase *
price(state, market, cid));
3683 base_budget -= cost;
3684 total_cost += cost * state.world.market_get_demand_satisfaction(market, cid);
3693 auto current_budget =
3695 * float(state.world.nation_get_construction_spending(n))
3704 for(
auto c : state.world.in_province_building_construction) {
3705 auto owner = c.get_nation().id;
3710 auto market = state.world.state_instance_get_market_from_local_market(
3711 c.get_province().get_state_membership()
3715 if(owner && owner == c.get_province().get_nation_from_province_control() && c.get_is_pop_project()) {
3717 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
3718 auto& current_purchased = c.get_purchased_goods();
3720 float(state.economy_definitions.building_definitions[int32_t(t)].time);
3721 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3722 if(base_cost.commodity_type[i]) {
3723 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i])
3725 base_cost.commodity_amounts[i]
3726 *
price(state, market, base_cost.commodity_type[i])
3727 / construction_time;
3735 for(
auto c : state.world.in_state_building_construction) {
3736 auto owner = c.get_nation().id;
3741 auto market = state.world.state_instance_get_market_from_local_market(c.get_state());
3742 if(owner && c.get_is_pop_project()) {
3743 auto& base_cost = c.get_type().get_construction_costs();
3744 auto& current_purchased = c.get_purchased_goods();
3746 float(c.get_type().get_construction_time()) * (c.get_is_upgrade() ? 0.1f : 1.0f);
3747 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));
3749 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3750 if(base_cost.commodity_type[i]) {
3751 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod)
3753 base_cost.commodity_amounts[i]
3754 *
price(state, market, base_cost.commodity_type[i])
3756 / construction_time;
3768 uint32_t total_commodities = state.world.commodity_size();
3769 for(
uint32_t i = 1; i < total_commodities; ++i) {
3770 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3771 state.world.execute_serial_over_market([&](
auto ids) {
3772 state.world.market_set_private_construction_demand(ids, cid, 0.0f);
3776 for(
auto c : state.world.in_province_building_construction) {
3777 auto owner = c.get_nation().id;
3778 auto market = state.world.state_instance_get_market_from_local_market(
3779 c.get_province().get_state_membership()
3783 if(owner && owner == c.get_province().get_nation_from_province_control() && c.get_is_pop_project()) {
3785 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
3786 auto& current_purchased = c.get_purchased_goods();
3788 float(state.economy_definitions.building_definitions[int32_t(t)].time);
3789 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3790 if(base_cost.commodity_type[i]) {
3791 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i])
3792 state.world.market_get_private_construction_demand(
3794 base_cost.commodity_type[i]
3796 base_cost.commodity_amounts[i]
3797 / construction_time;
3805 for(
auto c : state.world.in_state_building_construction) {
3806 auto owner = c.get_nation().id;
3807 auto market = state.world.state_instance_get_market_from_local_market(c.get_state());
3808 if(owner && c.get_is_pop_project()) {
3809 auto& base_cost = c.get_type().get_construction_costs();
3810 auto& current_purchased = c.get_purchased_goods();
3812 float(c.get_type().get_construction_time()) * (c.get_is_upgrade() ? 0.1f : 1.0f);
3813 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));
3815 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
3816 if(base_cost.commodity_type[i]) {
3817 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod)
3818 state.world.market_get_private_construction_demand(
3819 market, base_cost.commodity_type[i]
3821 base_cost.commodity_amounts[i]
3823 / construction_time;
3834 float military_total = 0.f;
3835 uint32_t total_commodities = state.world.commodity_size();
3837 float base_budget = state.world.nation_get_stockpiles(n,
economy::money);
3838 float construction_budget =
3841 float(state.world.nation_get_construction_spending(n))
3846 float l_spending = float(state.world.nation_get_land_spending(n)) / 100.0f;
3847 float n_spending = float(state.world.nation_get_naval_spending(n)) / 100.0f;
3848 float o_spending = float(state.world.nation_get_overseas_spending(n)) / 100.f;
3850 float total_construction_costs = 0.f;
3851 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
3852 auto local_state = state.world.state_ownership_get_state(soid);
3853 auto local_market = state.world.state_instance_get_market_from_local_market(local_state);
3855 for(
uint32_t i = 1; i < total_commodities; ++i) {
3856 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3857 auto v = state.world.market_get_army_demand(local_market, cid)
3859 *
price(state, local_market, cid);
3860 assert(std::isfinite(v) && v >= 0.0f);
3862 military_total += v;
3864 for(
uint32_t i = 1; i < total_commodities; ++i) {
3865 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3866 auto v = state.world.market_get_navy_demand(local_market, cid)
3867 * n_spending *
price(state, local_market, cid);
3868 assert(std::isfinite(v) && v >= 0.0f);
3870 military_total += v;
3872 assert(std::isfinite(total) && total >= 0.0f);
3873 state.world.nation_set_maximum_military_costs(n, military_total);
3875 for(
uint32_t i = 1; i < total_commodities; ++i) {
3876 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3877 auto demand_const = state.world.market_get_construction_demand(local_market, cid);
3878 auto c_price =
price(state, local_market, cid);
3880 total_construction_costs += demand_const * c_price;
3884 total += std::min(construction_budget, total_construction_costs);
3887 auto capital_state = state.world.province_get_state_membership(state.world.nation_get_capital(n));
3888 auto capital_market = state.world.state_instance_get_market_from_local_market(capital_state);
3890 for(
uint32_t i = 1; i < total_commodities; ++i) {
3891 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3892 auto difference = state.world.nation_get_stockpile_targets(n, cid) - state.world.nation_get_stockpiles(n, cid);
3893 if(difference > 0 && state.world.nation_get_drawing_on_stockpiles(n, cid) ==
false) {
3894 total += difference *
price(state, capital_market, cid);
3897 assert(std::isfinite(total) && total >= 0.0f);
3899 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));
3900 if(overseas_factor > 0) {
3901 for(
uint32_t i = 1; i < total_commodities; ++i) {
3902 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
3903 if(state.world.commodity_get_overseas_penalty(cid) && (state.world.commodity_get_is_available_from_start(cid) || state.world.nation_get_unlocked_commodities(n, cid))) {
3904 total += overseas_factor *
price(state, capital_market, cid) * o_spending;
3909 assert(std::isfinite(total) && total >= 0.0f);
3912 auto const a_spending = float(state.world.nation_get_administrative_spending(n)) / 100.0f * float(state.world.nation_get_administrative_spending(n)) / 100.0f;
3913 auto const s_spending = state.world.nation_get_administrative_efficiency(n) * float(state.world.nation_get_social_spending(n)) / 100.0f;
3914 auto const e_spending = float(state.world.nation_get_education_spending(n)) * float(state.world.nation_get_education_spending(n)) / 100.0f / 100.0f;
3915 auto const m_spending = float(state.world.nation_get_military_spending(n)) * float(state.world.nation_get_military_spending(n)) / 100.0f / 100.f;
3916 auto const p_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::pension_level);
3917 auto const unemp_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::unemployment_benefit);
3918 auto const di_spending =
3919 float(state.world.nation_get_domestic_investment_spending(n))
3920 * float(state.world.nation_get_domestic_investment_spending(n))
3924 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
3925 auto local_state = state.world.state_ownership_get_state(soid);
3926 auto market = state.world.state_instance_get_market_from_local_market(local_state);
3928 auto capitalists_def = state.culture_definitions.capitalists;
3930 auto capitalists = state.world.state_instance_get_demographics(local_state, capitalists_key);
3931 auto capitalists_base =
3932 state.world.market_get_life_needs_costs(market, capitalists_def)
3933 + state.world.market_get_everyday_needs_costs(market, capitalists_def)
3934 + state.world.market_get_luxury_needs_costs(market, capitalists_def);
3936 auto aristocrats_def = state.culture_definitions.aristocrat;
3938 auto aristocrats = state.world.state_instance_get_demographics(local_state, aristoctats_key);
3939 auto aristocrats_base =
3940 state.world.market_get_life_needs_costs(market, aristocrats_def)
3941 + state.world.market_get_everyday_needs_costs(market, aristocrats_def)
3942 + state.world.market_get_luxury_needs_costs(market, aristocrats_def);
3945 state.defines.alice_domestic_investment_multiplier
3948 capitalists * capitalists_base
3949 + aristocrats * aristocrats_base
3951 / state.defines.alice_needs_scaling_factor;
3953 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
3957 auto adj_pop_of_type =
3958 state.world.state_instance_get_demographics(local_state, key)
3959 / state.defines.alice_needs_scaling_factor;
3961 if(adj_pop_of_type <= 0)
3975 * state.world.market_get_life_needs_costs(market, pt);
3977 if(state.world.pop_type_get_has_unemployment(pt)) {
3979 state.world.state_instance_get_demographics(local_state, employment_key)
3980 / state.defines.alice_needs_scaling_factor;
3983 * (adj_pop_of_type - emp)
3985 * state.world.market_get_life_needs_costs(market, pt);
4007 assert(std::isfinite(total) && total >= 0.0f);
4011 assert(std::isfinite(total) && total >= 0.0f);
4018 uint32_t total_commodities = state.world.commodity_size();
4020 auto capital = state.world.nation_get_capital(n);
4021 auto capital_state = state.world.province_get_state_membership(capital);
4022 auto market = state.world.state_instance_get_market_from_local_market(capital_state);
4024 for(
uint32_t i = 1; i < total_commodities; ++i) {
4025 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4027 state.world.nation_get_stockpile_targets(n, cid)
4028 - state.world.nation_get_stockpiles(n, cid);
4030 if(difference > 0 && state.world.nation_get_drawing_on_stockpiles(n, cid) ==
false) {
4033 *
price(state, market, cid)
4034 * state.world.market_get_demand_satisfaction(market, cid);
4044 auto capital = state.world.nation_get_capital(n);
4045 auto capital_state = state.world.province_get_state_membership(capital);
4046 auto market = state.world.state_instance_get_market_from_local_market(capital_state);
4048 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));
4049 uint32_t total_commodities = state.world.commodity_size();
4051 if(overseas_factor > 0) {
4052 for(
uint32_t i = 1; i < total_commodities; ++i) {
4053 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4055 if(state.world.commodity_get_overseas_penalty(cid) && (state.world.commodity_get_is_available_from_start(cid) || state.world.nation_get_unlocked_commodities(n, cid))) {
4058 *
price(state, market, cid)
4059 * state.world.market_get_demand_satisfaction(market, cid);
4069 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
4070 auto local_state = state.world.state_ownership_get_state(soid);
4071 auto market = state.world.state_instance_get_market_from_local_market(local_state);
4072 uint32_t total_commodities = state.world.commodity_size();
4073 for(
uint32_t i = 1; i < total_commodities; ++i) {
4074 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4076 state.world.market_get_private_construction_demand(market, cid)
4077 *
price(state, market, cid);
4084 uint32_t total_commodities = state.world.commodity_size();
4085 float l_spending = float(state.world.nation_get_land_spending(n)) / 100.0f;
4086 float n_spending = float(state.world.nation_get_naval_spending(n)) / 100.0f;
4087 float o_spending = float(state.world.nation_get_overseas_spending(n)) / 100.0f;
4089 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
4090 auto local_state = state.world.state_ownership_get_state(soid);
4091 auto market = state.world.state_instance_get_market_from_local_market(local_state);
4093 for(
uint32_t i = 1; i < total_commodities; ++i) {
4094 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4095 auto sat = state.world.market_get_demand_satisfaction(market, cid);
4096 auto sat_importance = std::min(1.f, 1.f / (
price(state, market, cid) + 0.001f));
4097 auto sat_coefficient = (sat_importance + (1.f - sat_importance) * sat);
4103 state.world.market_get_army_demand(market, cid)
4107 , economy_reason::nation
4113 state.world.market_get_navy_demand(market, cid)
4117 , economy_reason::nation
4120 for(
uint32_t i = 1; i < total_commodities; ++i) {
4121 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4126 state.world.market_get_construction_demand(market, cid)
4128 economy_reason::construction
4131 for(
uint32_t i = 1; i < total_commodities; ++i) {
4132 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4137 state.world.market_get_private_construction_demand(market, cid)
4138 * private_investment_scale, economy_reason::construction);
4142 auto capital = state.world.nation_get_capital(n);
4143 auto capital_state = state.world.province_get_state_membership(capital);
4144 auto market = state.world.state_instance_get_market_from_local_market(capital_state);
4146 for(
uint32_t i = 1; i < total_commodities; ++i) {
4147 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4148 auto difference = state.world.nation_get_stockpile_targets(n, cid) - state.world.nation_get_stockpiles(n, cid);
4149 if(difference > 0 && state.world.nation_get_drawing_on_stockpiles(n, cid) ==
false) {
4150 auto sat = state.world.market_get_demand_satisfaction(market, cid);
4151 auto sat_importance = std::min(1.f, 1.f / (
price(state, market, cid) + 0.001f));
4152 auto sat_coefficient = (sat_importance + (1.f - sat_importance) * sat);
4160 economy_reason::stockpile
4164 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));
4165 if(overseas_factor > 0.f) {
4166 for(
uint32_t i = 1; i < total_commodities; ++i) {
4167 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4168 if(state.world.commodity_get_overseas_penalty(cid) && (state.world.commodity_get_is_available_from_start(cid) || state.world.nation_get_unlocked_commodities(n, cid))) {
4169 auto sat = state.world.market_get_demand_satisfaction(market, cid);
4170 auto sat_importance = std::min(1.f, 1.f / (
price(state, market, cid) + 0.001f));
4171 auto sat_coefficient = (sat_importance + (1.f - sat_importance) * sat);
4181 economy_reason::overseas_penalty
4190 ve::vectorizable_buffer<float, dcon::nation_id>& invention_count
4192 uint32_t total_commodities = state.world.commodity_size();
4194 state.ui_state.last_tick_investment_pool_change = 0;
4196 static const ve::fp_vector zero = ve::fp_vector{ 0.f };
4197 static const ve::fp_vector one = ve::fp_vector{ 1.f };
4209 ve::int_vector can_invest = expand_factory | build_factory;
4211 state.world.execute_serial_over_pop([&](
auto ids) {
4213 auto provs = state.world.pop_get_province_from_pop_location(ids);
4214 auto states = state.world.province_get_state_membership(provs);
4215 auto markets = state.world.state_instance_get_market_from_local_market(states);
4216 auto nations = state.world.state_instance_get_nation_from_state_ownership(states);
4217 auto pop_type = state.world.pop_get_poptype(ids);
4218 auto strata = state.world.pop_type_get_strata(pop_type);
4219 auto life_costs = ve::apply(
4220 [&](dcon::market_id m, dcon::pop_type_id pt) {
4221 return state.world.market_get_life_needs_costs(m, pt);
4222 }, markets, pop_type
4224 auto everyday_costs = ve::apply(
4225 [&](dcon::market_id m, dcon::pop_type_id pt) {
4226 return state.world.market_get_everyday_needs_costs(m, pt);
4227 }, markets, pop_type
4229 auto luxury_costs = ve::apply(
4230 [&](dcon::market_id m, dcon::pop_type_id pt) {
4231 return state.world.market_get_luxury_needs_costs(m, pt);
4232 }, markets, pop_type
4234 auto pop_size = state.world.pop_get_size(ids);
4235 auto savings = state.world.pop_get_savings(ids);
4239 subsistence = subsistence - available_subsistence;
4243 subsistence = subsistence - available_subsistence;
4246 auto luxury_needs_satisfaction = ve::fp_vector{ 0.f };
4250 auto life_to_satisfy = ve::max(0.f, 1.f - life_needs_satisfaction);
4251 auto everyday_to_satisfy = ve::max(0.f, 1.f - everyday_needs_satisfaction);
4252 auto luxury_to_satisfy = ve::max(0.f, 1.f - luxury_needs_satisfaction);
4254 auto required_spendings_for_life_needs =
4257 * pop_size / state.defines.alice_needs_scaling_factor;
4259 auto required_spendings_for_everyday_needs =
4262 * pop_size / state.defines.alice_needs_scaling_factor;
4264 auto required_spendings_for_luxury_needs =
4267 * pop_size / state.defines.alice_needs_scaling_factor;
4279 auto life_spending_mod = ve::max(0.f, ve::min(1.f, savings * state.defines.alice_needs_lf_spend / (1.f + required_spendings_for_life_needs)) - 0.1f);
4280 auto everyday_spending_mod = ve::max(0.f, ve::min(1.f, savings * state.defines.alice_needs_ev_spend / (1.f + required_spendings_for_everyday_needs)) - 0.1f);
4281 auto luxury_spending_mod = ve::max(0.f, ve::min(1.f, savings * state.defines.alice_needs_lx_spend / (1.f + required_spendings_for_luxury_needs)) - 0.1f);
4283 auto zero_life_costs = required_spendings_for_life_needs == 0;
4284 auto zero_everyday_costs = required_spendings_for_everyday_needs == 0;
4285 auto zero_luxury_costs = required_spendings_for_luxury_needs == 0;
4289 auto spend_on_life_needs = life_spending_mod * ve::min(savings, required_spendings_for_life_needs);
4293 spend_on_life_needs / required_spendings_for_life_needs);
4295 savings = savings - spend_on_life_needs;
4298 auto nation_rules = state.world.nation_get_combined_issue_rules(
nations);
4300 auto is_civilised = state.world.nation_get_is_civilized(
nations);
4301 auto allows_investment_mask = (nation_rules & can_invest) != 0;
4302 ve::mask_vector nation_allows_investment = is_civilised && allows_investment_mask;
4304 auto capitalists_mask = pop_type == state.culture_definitions.capitalists;
4305 auto artisans_mask = pop_type == state.culture_definitions.artisans;
4306 auto landowners_mask = pop_type == state.culture_definitions.aristocrat;
4308 auto investment_ratio =
4309 ve::select(capitalists_mask, state.defines.alice_invest_capitalist, zero)
4310 +
ve::select(landowners_mask, state.defines.alice_invest_aristocrat, zero)
4311 +
ve::select(artisans_mask, state.defines.alice_invest_aristocrat, zero);
4313 auto investment = savings * investment_ratio;
4315 savings = savings - investment;
4319 auto spend_on_everyday_needs = everyday_spending_mod * ve::min(savings, required_spendings_for_everyday_needs);
4320 auto satisfaction_everyday_money =
ve::select(
4321 zero_everyday_costs,
4322 everyday_to_satisfy,
4323 spend_on_everyday_needs / required_spendings_for_everyday_needs);
4325 savings = savings - spend_on_everyday_needs;
4328 ve::fp_vector bank_to_pop_money_transfer { 0.f };
4329 auto enough_savings = savings > required_spendings_for_luxury_needs;
4330 auto savings_for_transfer = required_spendings_for_luxury_needs - savings;
4332 auto enough_in_bank = state.world.nation_get_national_bank(
nations) > ve::max(required_spendings_for_luxury_needs + 10000.f, savings_for_transfer);
4334 enough_savings && nation_allows_investment && capitalists_mask,
4335 bank_to_pop_money_transfer - savings_for_transfer * state.defines.alice_save_aristocrat,
4336 bank_to_pop_money_transfer
4339 enough_savings && nation_allows_investment && landowners_mask,
4340 bank_to_pop_money_transfer - savings_for_transfer * state.defines.alice_save_capitalist,
4341 bank_to_pop_money_transfer
4344 !enough_savings && nation_allows_investment && enough_in_bank,
4345 bank_to_pop_money_transfer + savings_for_transfer,
4346 bank_to_pop_money_transfer
4350 [&](
float transfer, dcon::nation_id n) {
4351 state.world.nation_get_national_bank(n) -= transfer;
4353 }, bank_to_pop_money_transfer,
nations
4356 savings = savings + bank_to_pop_money_transfer;
4360 auto spend_on_luxury_needs = luxury_spending_mod * ve::min(savings, required_spendings_for_luxury_needs);
4364 spend_on_luxury_needs / required_spendings_for_luxury_needs);
4366 savings = savings - spend_on_luxury_needs;
4372 savings = savings * (
4374 - state.defines.alice_needs_lf_spend
4375 - state.defines.alice_needs_ev_spend
4376 - state.defines.alice_needs_lx_spend
4384 auto old_life_money =
4385 ve::max(0.f, old_life - life_needs_satisfaction);
4386 auto old_everyday_money =
4387 ve::max(0.f, old_everyday - everyday_needs_satisfaction);
4388 auto old_luxury_money =
4389 ve::max(0.f, old_luxury - luxury_needs_satisfaction);
4391 auto delayed_life_from_money =
4392 (old_life_money * 0.5f) + (satisfaction_life_money * 0.5f);
4393 auto delayed_everyday_from_money =
4394 (old_everyday_money * 0.5f) + (satisfaction_everyday_money * 0.5f);
4395 auto delayed_luxury_from_money =
4396 (old_luxury_money * 0.5f) + (satisfaction_luxury_money * 0.5f);
4398 auto result_life = ve::min(1.f, delayed_life_from_money + life_needs_satisfaction);
4399 auto result_everyday = ve::min(1.f, delayed_everyday_from_money + everyday_needs_satisfaction);
4400 auto result_luxury = ve::min(1.f, delayed_luxury_from_money + luxury_needs_satisfaction);
4402 ve::apply([&](
float life,
float everyday,
float luxury) {
4403 assert(life >= 0.f && life <= 1.f);
4404 assert(everyday >= 0.f && everyday <= 1.f);
4405 assert(luxury >= 0.f && luxury <= 1.f);
4406 }, result_life, result_everyday, result_luxury);
4413 auto final_demand_scale_life =
4414 pop_size / state.defines.alice_needs_scaling_factor
4415 * delayed_life_from_money;
4417 auto final_demand_scale_everyday =
4418 pop_size / state.defines.alice_needs_scaling_factor
4419 * delayed_everyday_from_money;
4421 auto final_demand_scale_luxury =
4422 pop_size / state.defines.alice_needs_scaling_factor
4423 * delayed_luxury_from_money;
4428 float scale_everyday,
4433 state.world.market_get_life_needs_scale(m, pop_type) += scale_life;
4434 state.world.market_get_everyday_needs_scale(m, pop_type) += scale_everyday;
4435 state.world.market_get_luxury_needs_scale(m, pop_type) += scale_luxury;
4436 auto zone = state.world.market_get_zone_from_local_market(m);
4437 auto nation = state.world.state_instance_get_nation_from_state_ownership(zone);
4438 state.world.nation_get_private_investment(nation) += investment;
4439 if(nation == state.local_player_nation) {
4440 state.ui_state.last_tick_investment_pool_change += investment;
4444 final_demand_scale_life,
4445 final_demand_scale_everyday,
4446 final_demand_scale_luxury,
4456 state.world.execute_serial_over_market([&](
auto ids) {
4457 auto states = state.world.market_get_zone_from_local_market(ids);
4458 auto nations = state.world.state_instance_get_nation_from_state_ownership(states);
4459 auto invention_factor = state.defines.invention_impact_on_demand * invention_count.get(
nations) + 1.f;
4461 ve::fp_vector life_mul[3] = {
4462 state.world.nation_get_modifier_values(
4463 nations, sys::national_mod_offsets::poor_life_needs) + 1.0f,
4464 state.world.nation_get_modifier_values(
4465 nations, sys::national_mod_offsets::middle_life_needs) + 1.0f,
4466 state.world.nation_get_modifier_values(
4467 nations, sys::national_mod_offsets::rich_life_needs) + 1.0f
4469 ve::fp_vector everyday_mul[3] = {
4470 state.world.nation_get_modifier_values(
4471 nations, sys::national_mod_offsets::poor_everyday_needs) + 1.0f,
4472 state.world.nation_get_modifier_values(
4473 nations, sys::national_mod_offsets::middle_everyday_needs) + 1.0f,
4474 state.world.nation_get_modifier_values(
4475 nations, sys::national_mod_offsets::rich_everyday_needs) + 1.0f
4477 ve::fp_vector luxury_mul[3] = {
4478 state.world.nation_get_modifier_values(
4479 nations, sys::national_mod_offsets::poor_luxury_needs) + 1.0f,
4480 state.world.nation_get_modifier_values(
4481 nations, sys::national_mod_offsets::middle_luxury_needs) + 1.0f,
4482 state.world.nation_get_modifier_values(
4483 nations, sys::national_mod_offsets::rich_luxury_needs) + 1.0f,
4486 for(
const auto t : state.world.in_pop_type) {
4487 auto scale_life = state.world.market_get_life_needs_scale(ids, t);
4488 auto scale_everyday = state.world.market_get_everyday_needs_scale(ids, t);
4489 auto scale_luxury = state.world.market_get_luxury_needs_scale(ids, t);
4491 auto strata = t.get_strata();
4493 for(
uint32_t i = 1; i < total_commodities; ++i) {
4494 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
4497 state.world.market_get_life_needs_weights(ids, cid);
4498 auto everyday_weight =
4499 state.world.market_get_everyday_needs_weights(ids, cid);
4500 auto luxury_weight =
4501 state.world.market_get_luxury_needs_weights(ids, cid);
4503 state.world.pop_type_get_life_needs(t, cid);
4504 auto base_everyday =
4505 state.world.pop_type_get_everyday_needs(t, cid);
4507 state.world.pop_type_get_luxury_needs(t, cid);
4516 * state.defines.alice_lf_needs_scale;
4517 auto demand_everyday =
4520 * everyday_mul[strata]
4522 * state.defines.alice_ev_needs_scale
4524 auto demand_luxury =
4527 * luxury_mul[strata]
4529 * state.defines.alice_lx_needs_scale
4532 demand_life =
ve::select(valid_good_mask, demand_life, 0.f);
4533 demand_everyday =
ve::select(valid_good_mask, demand_everyday, 0.f);
4534 demand_luxury =
ve::select(valid_good_mask, demand_luxury, 0.f);
4537 register_demand(state, ids, cid, demand_everyday, economy_reason::pop);
4545 uint32_t total_commodities = state.world.commodity_size();
4546 float p_spending = state.world.nation_get_private_investment_effective_fraction(n);
4547 float refund_amount = 0.0f;
4549 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
4550 auto local_state = state.world.state_ownership_get_state(soid);
4551 auto market = state.world.state_instance_get_market_from_local_market(local_state);
4553 for(
uint32_t i = 1; i < total_commodities; ++i) {
4554 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
4555 auto& nat_demand = state.world.market_get_construction_demand(market, c);
4556 auto com_price =
price(state, market, c);
4557 auto d_sat = state.world.market_get_demand_satisfaction(market, c);
4562 assert(refund_amount >= 0.0f);
4564 nat_demand *= d_sat;
4565 state.world.market_get_private_construction_demand(market, c) *= p_spending * d_sat;
4569 assert(refund_amount >= 0.0f);
4570 state.world.nation_get_stockpiles(n,
economy::money) += refund_amount;
4572 float admin_eff = state.world.nation_get_administrative_efficiency(n);
4573 float admin_cost_factor = 2.0f - admin_eff;
4575 for(
auto p : state.world.nation_get_province_ownership(n)) {
4576 if(p.get_province().get_nation_from_province_control() != n)
4579 auto market = state.world.state_instance_get_market_from_local_market(p.get_province().get_state_membership());
4581 for(
auto pops : p.get_province().get_pop_location()) {
4582 auto rng = pops.get_pop().get_province_land_construction();
4583 if(
rng.begin() !=
rng.end()) {
4584 auto c = *(
rng.begin());
4585 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
4586 auto& current_purchased = c.get_purchased_goods();
4587 float construction_time =
4589 * float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
4591 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4592 if(base_cost.commodity_type[i]) {
4594 current_purchased.commodity_amounts[i]
4595 < base_cost.commodity_amounts[i]
4598 auto amount = base_cost.commodity_amounts[i] / construction_time;
4600 = state.world.market_get_construction_demand(
4602 base_cost.commodity_type[i]
4607 base_cost.commodity_amounts[i] / construction_time
4609 current_purchased.commodity_amounts[i] += delta;
4620 auto rng = p.get_province().get_province_naval_construction();
4621 if(
rng.begin() !=
rng.end()) {
4622 auto c = *(
rng.begin());
4623 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
4624 auto& current_purchased = c.get_purchased_goods();
4627 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4628 if(base_cost.commodity_type[i]) {
4629 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
4630 auto amount = base_cost.commodity_amounts[i] / construction_time;
4631 auto& source = state.world.market_get_construction_demand(market, base_cost.commodity_type[i]);
4632 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
4634 current_purchased.commodity_amounts[i] += delta;
4645 for(
auto c : state.world.nation_get_province_building_construction(n)) {
4646 if(c.get_province().get_nation_from_province_ownership() == c.get_province().get_nation_from_province_control()) {
4648 auto market = c.get_province().get_state_membership().get_market_from_local_market();
4652 if(!c.get_is_pop_project()) {
4653 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
4654 auto& current_purchased = c.get_purchased_goods();
4657 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4658 if(base_cost.commodity_type[i]) {
4659 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
4660 auto amount = base_cost.commodity_amounts[i] / construction_time;
4661 auto& source = state.world.market_get_construction_demand(market, base_cost.commodity_type[i]);
4662 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
4664 current_purchased.commodity_amounts[i] += delta;
4671 }
else if(c.get_is_pop_project()) {
4672 auto& base_cost = state.economy_definitions.building_definitions[int32_t(t)].cost;
4673 auto& current_purchased = c.get_purchased_goods();
4676 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4677 if(base_cost.commodity_type[i]) {
4678 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i]) {
4679 auto amount = base_cost.commodity_amounts[i] / construction_time;
4680 auto& source = state.world.market_get_private_construction_demand(market, base_cost.commodity_type[i]);
4681 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] / construction_time));
4683 current_purchased.commodity_amounts[i] += delta;
4694 for(
auto c : state.world.nation_get_state_building_construction(n)) {
4695 auto market = c.get_state().get_market_from_local_market();
4696 if(!c.get_is_pop_project()) {
4697 auto& base_cost = c.get_type().get_construction_costs();
4698 auto& current_purchased = c.get_purchased_goods();
4700 float factory_mod = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f;
4702 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4703 if(base_cost.commodity_type[i]) {
4704 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod * admin_cost_factor) {
4705 auto amount = base_cost.commodity_amounts[i] / construction_time;
4706 auto& source = state.world.market_get_construction_demand(market, base_cost.commodity_type[i]);
4707 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] * factory_mod / construction_time));
4709 current_purchased.commodity_amounts[i] += delta;
4717 auto& base_cost = c.get_type().get_construction_costs();
4718 auto& current_purchased = c.get_purchased_goods();
4720 float factory_mod = (state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f) *
4721 std::max(0.1f, state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_owner_cost));
4723 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4724 if(base_cost.commodity_type[i]) {
4725 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * factory_mod) {
4726 auto amount = base_cost.commodity_amounts[i] / construction_time;
4727 auto& source = state.world.market_get_private_construction_demand(market, base_cost.commodity_type[i]);
4728 auto delta = std::max(0.0f, std::min(source, base_cost.commodity_amounts[i] * factory_mod / construction_time));
4730 current_purchased.commodity_amounts[i] += delta;
4749 dcon::state_instance_const_fat_id s,
4752 auto primary_def = state.culture_definitions.primary_factory_worker;
4753 auto secondary_def = state.culture_definitions.secondary_factory_worker;
4758 auto market = s.get_market_from_local_market();
4759 float total_min_to_pworkers =
4760 market.get_labor_unskilled_price()
4761 * state.world.state_instance_get_demographics(s, primary_key);
4762 float total_min_to_sworkers =
4763 market.get_labor_skilled_price()
4764 * state.world.state_instance_get_demographics(s, secondary_key);
4766 float num_pworkers = state.world.state_instance_get_demographics(s, primary_key);
4767 float num_sworkers = state.world.state_instance_get_demographics(s, secondary_key);
4768 float num_owners = state.world.state_instance_get_demographics(s,
demographics::to_key(state, state.culture_definitions.capitalists));
4770 auto per_pworker_profit = market.get_labor_unskilled_price();
4771 auto per_sworker_profit = market.get_labor_skilled_price();
4773 auto surplus = total_profit;
4774 auto per_owner_profit = 0.f;
4776 if(surplus >= 0.f && num_owners > 0.f) {
4779 per_owner_profit = surplus / num_owners;
4780 }
else if(surplus >= 0.f && num_sworkers > 0) {
4784 per_pworker_profit += surplus / (num_sworkers + num_pworkers);
4785 per_sworker_profit += surplus / (num_sworkers + num_pworkers);
4786 }
else if(surplus >= 0.f && num_pworkers > 0) {
4790 per_pworker_profit += surplus / num_pworkers;
4798 .per_primary_worker = per_pworker_profit,
4799 .per_secondary_worker = per_sworker_profit,
4800 .per_owner = per_owner_profit
4810 float income_to_build_units = 10'000.f;
4812 if(state.world.nation_get_owned_province_count(n) == 0) {
4818 auto infantry = state.military_definitions.infantry;
4819 auto artillery = state.military_definitions.artillery;
4821 auto& infantry_def = state.military_definitions.unit_base_definitions[infantry];
4822 auto& artillery_def = state.military_definitions.unit_base_definitions[artillery];
4824 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
4825 auto local_state = state.world.state_ownership_get_state(soid);
4826 auto market = state.world.state_instance_get_market_from_local_market(local_state);
4828 float daily_cost = 0.f;
4830 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4831 if(infantry_def.build_cost.commodity_type[i]) {
4832 auto p = price(state, market, infantry_def.build_cost.commodity_type[i]);
4833 daily_cost += infantry_def.build_cost.commodity_amounts[i] / infantry_def.build_time * p;
4838 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4839 if(artillery_def.build_cost.commodity_type[i]) {
4840 auto p = price(state, market, artillery_def.build_cost.commodity_type[i]);
4841 daily_cost += artillery_def.build_cost.commodity_amounts[i] / artillery_def.build_time * p;
4847 auto pairs_to_build = std::max(0.f, income_to_build_units / (daily_cost + 1.f) - 0.1f);
4849 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4850 if(infantry_def.build_cost.commodity_type[i]) {
4851 auto daily_amount = infantry_def.build_cost.commodity_amounts[i] / infantry_def.build_time;
4852 register_demand(state, market, infantry_def.build_cost.commodity_type[i], daily_amount * pairs_to_build, economy_reason::construction);
4853 state.world.market_get_stockpile(market, infantry_def.build_cost.commodity_type[i]) += daily_amount * pairs_to_build * 0.05f;
4859 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4860 if(artillery_def.build_cost.commodity_type[i]) {
4861 auto daily_amount = artillery_def.build_cost.commodity_amounts[i] / artillery_def.build_time;
4862 register_demand(state, market, artillery_def.build_cost.commodity_type[i], daily_amount * pairs_to_build, economy_reason::construction);
4863 state.world.market_get_stockpile(market, artillery_def.build_cost.commodity_type[i]) += daily_amount * pairs_to_build * 0.05f;
4875 float income_to_build_factories = 100'000.f;
4877 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
4878 auto local_state = state.world.state_ownership_get_state(soid);
4879 auto market = state.world.state_instance_get_market_from_local_market(local_state);
4882 float sum_of_build_times = 0.f;
4883 float cost_factory_set = 0.f;
4886 state.world.for_each_factory_type([&](dcon::factory_type_id factory_type) {
4887 if(!state.world.factory_type_get_is_available_from_start(factory_type)) {
4891 auto build_time = state.world.factory_type_get_construction_time(factory_type);
4892 auto& build_cost = state.world.factory_type_get_construction_costs(factory_type);
4894 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4895 if(build_cost.commodity_type[i]) {
4896 auto pr = price(state, market, build_cost.commodity_type[i]);
4897 cost_factory_set += pr * build_cost.commodity_amounts[i] / build_time;
4907 auto num_of_factory_sets = std::max(0.f, income_to_build_factories / (cost_factory_set + 1.f) - 0.1f);
4910 state.world.for_each_factory_type([&](dcon::factory_type_id factory_type) {
4911 if(!state.world.factory_type_get_is_available_from_start(factory_type)) {
4915 auto build_time = state.world.factory_type_get_construction_time(factory_type);
4916 auto& build_cost = state.world.factory_type_get_construction_costs(factory_type);
4918 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
4919 if(build_cost.commodity_type[i]) {
4920 auto amount = build_cost.commodity_amounts[i];
4924 build_cost.commodity_type[i], amount / build_time * num_of_factory_sets,
4925 economy_reason::construction
4927 state.world.market_get_stockpile(market, build_cost.commodity_type[i]) += amount / build_time * num_of_factory_sets / 100.f;
4945 auto nation_rules = n.get_combined_issue_rules();
4949 float total_cost_added = 0.f;
4950 float current_inv = n.get_private_investment();
4952 std::vector<full_construction_state> res;
4954 if(current_inv <= total_cost) {
4958 if(!n.get_is_civilized()) {
4966 static std::vector<dcon::factory_type_id> desired_types;
4967 desired_types.clear();
4969 static std::vector<dcon::state_instance_id> states_in_order;
4970 states_in_order.clear();
4971 for(
auto si : n.get_state_ownership()) {
4972 if(si.get_state().get_capital().get_is_colonial() ==
false) {
4973 states_in_order.push_back(si.get_state().id);
4978 states_in_order.begin(),
4979 states_in_order.end(),
4980 [&](dcon::state_instance_id a, dcon::state_instance_id b
4982 auto a_pop = state.world.state_instance_get_demographics(a, demographics::total);
4983 auto b_pop = state.world.state_instance_get_demographics(b, demographics::total);
4985 return a_pop > b_pop;
4986 return a.index() < b.index();
4991 bool found_investment =
false;
4993 for(
auto s : states_in_order) {
4994 auto market = state.world.state_instance_get_market_from_local_market(s);
4995 auto pw_num = state.world.state_instance_get_demographics(s,
4997 auto pw_employed = state.world.state_instance_get_demographics(s,
5000 int32_t num_factories = 0;
5001 float profit = 0.0f;
5002 dcon::factory_id selected_factory;
5005 auto d = state.world.state_instance_get_definition(s);
5006 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
5007 if(p.get_province().get_nation_from_province_ownership() == n) {
5008 for(
auto f : p.get_province().get_factory_location()) {
5013 && f.get_factory().get_primary_employment() * state.world.market_get_labor_unskilled_demand_satisfaction(market) >= 0.9f
5014 && f.get_factory().get_level() <
uint8_t(255)) {
5016 auto type = f.get_factory().get_building_type();
5017 auto ug_in_progress =
false;
5018 for(
auto c : state.world.state_instance_get_state_building_construction(s)) {
5019 if(c.get_type() == type) {
5020 ug_in_progress =
true;
5025 if(ug_in_progress) {
5030 f.get_factory().get_full_profit()
5031 / f.get_factory().get_level();
5035 selected_factory = f.get_factory();
5041 if(selected_factory && profit > 0.f) {
5042 res.push_back({ n, s,
true,
true, state.world.factory_get_building_type(selected_factory) });
5053 auto nation_rules = n.get_combined_issue_rules();
5057 float total_cost_added = 0.f;
5058 float current_inv = n.get_private_investment();
5060 std::vector<full_construction_state> res;
5062 if(current_inv <= total_cost) {
5066 if(!n.get_is_civilized()) {
5074 static std::vector<dcon::factory_type_id> desired_types;
5075 desired_types.clear();
5077 static std::vector<dcon::state_instance_id> states_in_order;
5078 states_in_order.clear();
5080 for(
auto si : n.get_state_ownership()) {
5081 if(si.get_state().get_capital().get_is_colonial() ==
false) {
5082 states_in_order.push_back(si.get_state().id);
5086 float profit = 0.0f;
5087 dcon::factory_id selected_factory;
5090 states_in_order.begin(),
5091 states_in_order.end(),
5092 [&](dcon::state_instance_id a, dcon::state_instance_id b
5094 auto a_pop = state.world.state_instance_get_demographics(a, demographics::total);
5095 auto b_pop = state.world.state_instance_get_demographics(b, demographics::total);
5097 return a_pop > b_pop;
5098 return a.index() < b.index();
5101 for(
auto s : states_in_order) {
5102 auto existing_constructions = state.world.state_instance_get_state_building_construction(s);
5103 if(existing_constructions.begin() != existing_constructions.end())
5106 if(current_inv *
courage < total_cost + total_cost_added) {
5114 int32_t num_factories = 0;
5115 auto d = state.world.state_instance_get_definition(s);
5116 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
5117 if(p.get_province().get_nation_from_province_ownership() == n) {
5118 for(
auto f : p.get_province().get_factory_location()) {
5124 if(num_factories >= int32_t(state.defines.factories_per_state)) {
5128 auto market = state.world.state_instance_get_market_from_local_market(s);
5131 desired_types.clear();
5138 if(desired_types.empty()) {
5142 auto selected = desired_types[
5144 % desired_types.size()
5148 state.world.factory_type_get_is_coastal(selected)
5153 bool already_in_progress = [&]() {
5154 for(
auto p : state.world.state_instance_get_state_building_construction(s)) {
5155 if(p.get_type() == selected)
5161 if(already_in_progress)
5165 bool present_in_location =
false;
5167 for(
auto fac : state.world.province_get_factory_location(p)) {
5168 auto type = fac.get_factory().get_building_type();
5169 if(selected == type) {
5170 present_in_location = true;
5176 if(present_in_location) {
5180 auto costs = state.world.factory_type_get_construction_costs(selected);
5181 auto time = state.world.factory_type_get_construction_time(selected);
5182 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
5183 if(costs.commodity_type[i]) {
5185 costs.commodity_amounts[i]
5186 *
price(state, market, costs.commodity_type[i])
5194 if(current_inv *
courage < total_cost + total_cost_added) {
5199 n, s,
true,
false, selected });
5207 auto nation_rules = n.get_combined_issue_rules();
5211 float total_cost_added = 0.f;
5212 float current_inv = n.get_private_investment();
5214 std::vector<full_construction_province> res;
5216 if(current_inv <= total_cost) {
5220 if(!n.get_is_civilized()) {
5228 static std::vector<std::pair<dcon::province_id, int32_t>> provinces_in_order;
5229 provinces_in_order.clear();
5230 for(
auto si : n.get_state_ownership()) {
5231 if(si.get_state().get_capital().get_is_colonial() ==
false) {
5232 auto s = si.get_state().id;
5233 auto d = state.world.state_instance_get_definition(s);
5234 int32_t num_factories = 0;
5235 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
5237 p.get_province().get_nation_from_province_ownership() == n) {
5238 for(
auto f : p.get_province().get_factory_location())
5239 num_factories += int32_t(f.get_factory().get_level());
5240 provinces_in_order.emplace_back(p.get_province().id, num_factories);
5246 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
5248 p.get_province().get_nation_from_province_ownership() == n)
5249 provinces_in_order.emplace_back(p.get_province().id, num_factories);
5253 if(!provinces_in_order.empty()) {
5254 std::pair<dcon::province_id, int32_t> best_p = provinces_in_order[0];
5255 for(
auto e : provinces_in_order)
5256 if(e.second > best_p.second)
5259 auto sid = state.world.province_get_state_membership(best_p.first);
5260 auto market = state.world.state_instance_get_market_from_local_market(sid);
5262 auto costs = state.economy_definitions.building_definitions[int32_t(province_building_type::railroad)].cost;
5263 auto time = state.economy_definitions.building_definitions[int32_t(province_building_type::railroad)].time;
5264 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
5265 if(costs.commodity_type[i]) {
5267 costs.commodity_amounts[i]
5268 *
price(state, market, costs.commodity_type[i])
5276 if(n.get_private_investment() *
courage < total_cost + total_cost_added) {
5280 res.push_back({ n, best_p.first ,
true, province_building_type::railroad });
5288 for(
auto n : state.world.in_nation) {
5291 for(
auto r : craved_constructions) {
5292 auto new_up = fatten(
5294 state.world.force_create_state_building_construction(r.state, r.nation)
5297 new_up.set_is_pop_project(r.is_pop_project);
5298 new_up.set_is_upgrade(r.is_upgrade);
5299 new_up.set_type(r.type);
5304 for(
auto r : upgrades) {
5305 auto new_up = fatten(
5307 state.world.force_create_state_building_construction(r.state, r.nation)
5310 new_up.set_is_pop_project(r.is_pop_project);
5311 new_up.set_is_upgrade(r.is_upgrade);
5312 new_up.set_type(r.type);
5317 for(
auto r : constructions) {
5318 auto new_up = fatten(
5320 state.world.force_create_state_building_construction(r.state, r.nation)
5323 new_up.set_is_pop_project(r.is_pop_project);
5324 new_up.set_is_upgrade(r.is_upgrade);
5325 new_up.set_type(r.type);
5330 for(
auto r : province_constr) {
5331 auto new_rr = fatten(
5333 state.world.force_create_province_building_construction(r.province, r.nation)
5335 new_rr.set_is_pop_project(r.is_pop_project);
5336 new_rr.set_type(
uint8_t(r.type));
5343 auto rel = state.world.nation_get_overlord_as_subject(n);
5344 auto overlord = state.world.overlord_get_ruler(rel);
5346 auto amt = state.world.nation_get_private_investment(n) * state.defines.alice_privateinvestment_subject_transfer / 100.f;
5347 state.world.nation_get_private_investment(n) -= amt;
5350 if(subjects.size() > 0) {
5351 auto part = amt / subjects.size();
5352 for(
auto s : subjects) {
5353 state.world.nation_get_private_investment(s) += part;
5357 state.world.nation_get_private_investment(overlord) += amt;
5365 static const ve::fp_vector zero = ve::fp_vector{ 0.f };
5366 static const ve::fp_vector one = ve::fp_vector{ 1.f };
5374 concurrency::parallel_for(0, 10, [&](int32_t index) {
5389 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
5390 state.world.execute_serial_over_market([&](
auto nids) {
5391 state.world.market_set_everyday_needs_costs(nids, t, ve::fp_vector{});
5396 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
5397 state.world.execute_serial_over_market([&](
auto nids) {
5398 state.world.market_set_luxury_needs_costs(nids, t, ve::fp_vector{});
5403 state.world.for_each_pop_type([&](dcon::pop_type_id t) {
5404 state.world.execute_serial_over_market([&](
auto nids) {
5405 state.world.market_set_life_needs_costs(nids, t, ve::fp_vector{});
5410 state.world.execute_serial_over_nation([&](
auto ids) {
5411 state.world.nation_set_subsidies_spending(ids, 0.0f);
5415 state.world.execute_serial_over_nation([&](
auto ids) {
5416 auto treasury = state.world.nation_get_stockpiles(ids,
economy::money);
5417 state.world.nation_set_last_treasury(ids, treasury);
5429 auto const num_nation = state.world.nation_size();
5430 uint32_t total_commodities = state.world.commodity_size();
5446 state.world.execute_parallel_over_nation([&](
auto nations) {
5447 ve::apply([&](dcon::nation_id n) {
5449 state.world.nation_for_each_province_ownership_as_nation(n, [&](dcon::province_ownership_id poid) {
5450 auto p = state.world.province_ownership_get_province(poid);
5451 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
5452 auto state_instance = state.world.province_get_state_membership(p);
5453 auto market = state_instance.get_market_from_local_market();
5454 auto n = state_instance.get_nation_from_state_ownership();
5456 auto pop_farmer_min_wage =
farmer_min_wage(state, market, min_wage_factor);
5457 auto pop_laborer_min_wage =
laborer_min_wage(state, market, min_wage_factor);
5465 is_mine ? pop_laborer_min_wage : pop_farmer_min_wage
5473 auto coastal_capital_buffer = ve::vectorizable_buffer<dcon::province_id, dcon::state_instance_id>(state.world.state_instance_size());
5475 state.world.execute_parallel_over_state_instance([&](
auto ids) {
5476 ve::apply([&](
auto sid) {
5481 static auto export_tariff_buffer = state.world.nation_make_vectorizable_float_buffer();
5482 static auto import_tariff_buffer = state.world.nation_make_vectorizable_float_buffer();
5484 state.world.execute_parallel_over_nation([&](
auto ids) {
5485 ve::apply([&](
auto nid) {
5493 state.world.execute_parallel_over_trade_route([&](
auto trade_route){
5498 auto A = ve::apply([&](
auto route) {
5499 return state.world.trade_route_get_connected_markets(route, 0);
5502 auto B = ve::apply([&](
auto route) {
5503 return state.world.trade_route_get_connected_markets(route, 1);
5506 auto s_A = state.world.market_get_zone_from_local_market(A);
5507 auto s_B = state.world.market_get_zone_from_local_market(
B);
5509 auto n_A = state.world.state_instance_get_nation_from_state_ownership(s_A);
5510 auto n_B = state.world.state_instance_get_nation_from_state_ownership(s_B);
5512 auto capital_A = state.world.state_instance_get_capital(s_A);
5513 auto capital_B = state.world.state_instance_get_capital(s_B);
5515 auto port_A = coastal_capital_buffer.get(s_A);
5516 auto port_B = coastal_capital_buffer.get(s_B);
5518 auto controller_capital_A = state.world.province_get_nation_from_province_control(capital_A);
5519 auto controller_capital_B = state.world.province_get_nation_from_province_control(capital_B);
5521 auto controller_port_A = state.world.province_get_nation_from_province_control(port_A);
5522 auto controller_port_B = state.world.province_get_nation_from_province_control(port_B);
5524 auto sphere_A = state.world.nation_get_in_sphere_of(controller_capital_A);
5525 auto sphere_B = state.world.nation_get_in_sphere_of(controller_capital_B);
5527 auto overlord_A = state.world.overlord_get_ruler(
5528 state.world.nation_get_overlord_as_subject(controller_capital_A)
5530 auto overlord_B = state.world.overlord_get_ruler(
5531 state.world.nation_get_overlord_as_subject(controller_capital_B)
5535 auto A_is_open_to_B = sphere_A == controller_capital_B || overlord_A == controller_capital_B;
5536 auto B_is_open_to_A = sphere_B == controller_capital_A || overlord_B == controller_capital_A;
5542 auto A_joins_sphere_wide_embargo = ve::apply([&](
auto n_a,
auto n_b) {
5544 }, sphere_A, controller_capital_B);
5546 auto B_joins_sphere_wide_embargo = ve::apply([&](
auto n_a,
auto n_b) {
5548 }, sphere_B, controller_capital_A);
5567 ve::mask_vector port_occupied_A = ve::apply([&](
auto n_a,
auto n_b) {
5569 }, controller_capital_A, controller_port_A);
5570 ve::mask_vector port_occupied_B = ve::apply([&](
auto n_a,
auto n_b) {
5572 }, controller_capital_B, controller_port_B);
5574 ve::mask_vector is_A_blockaded = state.world.province_get_is_blockaded(port_A) || port_occupied_A;
5575 ve::mask_vector is_B_blockaded = state.world.province_get_is_blockaded(port_B) || port_occupied_B;
5578 auto at_war = ve::apply([&](
auto n_a,
auto n_b) {
5580 }, controller_capital_A, controller_capital_B);
5588 auto is_A_civ = state.world.nation_get_is_civilized(n_A);
5589 auto is_B_civ = state.world.nation_get_is_civilized(n_B);
5591 auto is_sea_route = state.world.trade_route_get_is_sea_route(trade_route);
5592 auto is_land_route = state.world.trade_route_get_is_land_route(trade_route);
5594 is_sea_route = is_sea_route && !is_A_blockaded && !is_B_blockaded;
5596 auto same_nation = controller_capital_A == controller_capital_B;
5600 auto import_tariff_A =
ve::select(same_nation || A_is_open_to_B, ve::fp_vector{ 0.f }, import_tariff_buffer.get(n_A));
5601 auto export_tariff_A =
ve::select(same_nation || A_is_open_to_B, ve::fp_vector{ 0.f }, export_tariff_buffer.get(n_A));
5602 auto import_tariff_B =
ve::select(same_nation || B_is_open_to_A, ve::fp_vector{ 0.f }, import_tariff_buffer.get(n_B));
5603 auto export_tariff_B =
ve::select(same_nation || B_is_open_to_A, ve::fp_vector{ 0.f }, export_tariff_buffer.get(n_B));
5605 ve::fp_vector distance = 999999.f;
5606 auto land_distance = state.world.trade_route_get_land_distance(trade_route);
5607 auto sea_distance = state.world.trade_route_get_sea_distance(trade_route);
5609 distance =
ve::select(is_land_route, ve::min(distance, land_distance), distance);
5610 distance =
ve::select(is_sea_route, ve::min(distance, sea_distance), distance);
5612 state.world.trade_route_set_distance(trade_route, distance);
5614 auto trade_good_loss_mult = ve::max(0.f, 1.f - 0.0001f * distance);
5617 auto transport_cost = distance * 0.0075f;
5619 for(
auto c : state.world.in_commodity) {
5620 if(state.world.commodity_get_money_rgo(c)) {
5625 auto current_volume = state.world.trade_route_get_volume(trade_route, c);
5627 auto absolute_volume = ve::abs(current_volume);
5634 auto effect_of_scale = ve::max(0.1f, 1.f - absolute_volume * 0.0005f);
5636 auto price_A_export =
ve_price(state, A, c) * (1.f + export_tariff_A);
5637 auto price_B_export =
ve_price(state,
B, c) * (1.f + export_tariff_B);
5639 auto price_A_import =
ve_price(state, A, c) * (1.f - import_tariff_A) * trade_good_loss_mult;
5640 auto price_B_import =
ve_price(state,
B, c) * (1.f - import_tariff_B) * trade_good_loss_mult;
5642 auto current_profit_A_to_B = price_B_import - price_A_export * merchant_cut - transport_cost * effect_of_scale;
5643 auto current_profit_B_to_A = price_A_import - price_B_export * merchant_cut - transport_cost * effect_of_scale;
5645 auto none_is_profiable = (current_profit_A_to_B <= 0.f) && (current_profit_B_to_A <= 0.f);
5647 auto max_change = 0.1f + absolute_volume * 0.1f;
5648 auto change =
ve::select(current_profit_A_to_B > 0.f, current_profit_A_to_B / price_B_import, 0.f);
5649 change =
ve::select(current_profit_B_to_A > 0.f, -current_profit_B_to_A / price_A_import, change);
5650 change = ve::min(ve::max(100.f * change, -max_change), max_change);
5651 change =
ve::select(none_is_profiable, -current_volume, change);
5654 || A_joins_sphere_wide_embargo
5655 || B_joins_sphere_wide_embargo,
5662 ve::fp_vector decay = 0.99f;
5668 decay =
ve::select(current_volume > 0.f, decay * ve::min(1.f, 10000.f / price_A_export), decay * ve::min(1.f, 10000.f / price_B_export));
5669 state.world.trade_route_set_volume(trade_route, c,
ve::select(ve::apply([&](
auto r) {
return state.world.trade_route_is_valid(r); }, trade_route), (current_volume + change)* decay, 0.0f));
5671 ve::apply([&](
auto route) {
5672 assert(std::isfinite(state.world.trade_route_get_volume(route, c)));
5681 state.world.for_each_market([&](
auto market) {
5683 auto max = state.world.market_get_max_throughput(market);
5685 state.world.for_each_commodity([&](
auto commodity) {
5686 state.world.market_for_each_trade_route(market, [&](
auto trade_route) {
5687 auto current_volume = state.world.trade_route_get_volume(trade_route, commodity);
5689 current_volume > 0.f
5690 ? state.world.trade_route_get_connected_markets(trade_route, 0)
5691 : state.world.trade_route_get_connected_markets(trade_route, 1);
5693 current_volume <= 0.f
5694 ? state.world.trade_route_get_connected_markets(trade_route, 0)
5695 : state.world.trade_route_get_connected_markets(trade_route, 1);
5697 auto sat = state.world.market_get_direct_demand_satisfaction(origin, commodity);
5698 total += std::abs(current_volume * sat);
5703 state.world.for_each_commodity([&](
auto commodity) {
5704 state.world.market_for_each_trade_route(market, [&](
auto trade_route) {
5705 auto now = state.world.trade_route_get_volume(trade_route, commodity);
5706 state.world.trade_route_set_volume(trade_route, commodity, now * max / total);
5714 static ve::vectorizable_buffer<float, dcon::nation_id> invention_count = state.world.nation_make_vectorizable_float_buffer();
5715 state.world.execute_serial_over_nation([&](
auto nations) {
5716 invention_count.set(
nations, 0.f);
5721 state.world.for_each_invention([&](
auto iid) {
5722 state.world.execute_serial_over_nation([&](
auto nations) {
5725 +
ve::select(state.world.nation_get_active_inventions(
nations, iid), one, zero);
5726 invention_count.set(
nations, count);
5730 state.world.execute_parallel_over_market([&](
auto markets) {
5732 state.world.market_set_gdp(markets, 0.f);
5734 auto states = state.world.market_get_zone_from_local_market(markets);
5735 auto nations = state.world.state_instance_get_nation_from_state_ownership(states);
5737 auto invention_factor = invention_count.get(
nations) * state.defines.invention_impact_on_demand + 1.0f;
5750 uint32_t total_commodities = state.world.commodity_size();
5755 uint8_t strata_filter = 0;
5756 auto offset_life = sys::national_mod_offsets::poor_life_needs;
5757 auto offset_everyday = sys::national_mod_offsets::poor_everyday_needs;
5758 auto offset_luxury = sys::national_mod_offsets::poor_luxury_needs;
5760 auto life_needs_mult =
5761 (state.world.nation_get_modifier_values(nations, offset_life) + 1.0f)
5762 * state.defines.alice_lf_needs_scale;
5763 auto everyday_needs_mult =
5764 (state.world.nation_get_modifier_values(nations, offset_everyday) + 1.0f)
5765 * state.defines.alice_ev_needs_scale;
5766 auto luxury_needs_mult =
5767 (state.world.nation_get_modifier_values(nations, offset_luxury) + 1.0f)
5768 * state.defines.alice_lx_needs_scale;
5770 for(uint32_t i = 1; i < total_commodities; ++i) {
5771 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
5773 auto prices = state.world.market_get_price(markets, c);
5775 auto available = state.world.commodity_get_is_available_from_start(c);
5776 auto is_active = state.world.nation_get_unlocked_commodities(nations, c);
5777 auto life_weights = state.world.market_get_life_needs_weights(markets, c);
5778 auto everyday_weights = state.world.market_get_everyday_needs_weights(markets, c);
5779 auto luxury_weights = state.world.market_get_luxury_needs_weights(markets, c);
5781 state.world.for_each_pop_type([&](dcon::pop_type_id pop_type) {
5782 if(state.world.pop_type_get_strata(pop_type) != strata_filter) {
5786 auto life_base = state.world.pop_type_get_life_needs(pop_type, c);
5787 auto everyday_base = state.world.pop_type_get_everyday_needs(pop_type, c);
5788 auto luxury_base = state.world.pop_type_get_luxury_needs(pop_type, c);
5790 auto life_costs = prices * life_base * life_needs_mult * life_weights;
5791 auto everyday_costs = prices * everyday_base * everyday_needs_mult * everyday_weights * invention_factor;
5792 auto luxury_costs = prices * luxury_base * luxury_needs_mult * luxury_weights * invention_factor;
5794 state.world.market_set_life_needs_costs(
5797 state.world.market_get_life_needs_costs(markets, pop_type) + life_costs
5799 state.world.market_set_everyday_needs_costs(
5802 state.world.market_get_everyday_needs_costs(markets, pop_type) + everyday_costs
5804 state.world.market_set_luxury_needs_costs(
5807 state.world.market_get_luxury_needs_costs(markets, pop_type) + luxury_costs
5812 assert(std::isfinite(x));
5813 }, state.world.market_get_life_needs_costs(markets, pop_type)
5817 assert(std::isfinite(x));
5818 }, state.world.market_get_everyday_needs_costs(markets, pop_type)
5822 assert(std::isfinite(x));
5823 }, state.world.market_get_luxury_needs_costs(markets, pop_type)
5833 auto offset_life = sys::national_mod_offsets::middle_life_needs;
5834 auto offset_everyday = sys::national_mod_offsets::middle_everyday_needs;
5835 auto offset_luxury = sys::national_mod_offsets::middle_luxury_needs;
5837 auto life_needs_mult =
5838 (state.world.nation_get_modifier_values(
nations, offset_life) + 1.0f)
5839 * state.defines.alice_lf_needs_scale;
5840 auto everyday_needs_mult =
5841 (state.world.nation_get_modifier_values(
nations, offset_everyday) + 1.0f)
5842 * state.defines.alice_ev_needs_scale;
5843 auto luxury_needs_mult =
5844 (state.world.nation_get_modifier_values(
nations, offset_luxury) + 1.0f)
5845 * state.defines.alice_lx_needs_scale;
5847 for(
uint32_t i = 1; i < total_commodities; ++i) {
5848 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
5850 auto prices = state.world.market_get_price(markets, c);
5852 auto available = state.world.commodity_get_is_available_from_start(c);
5853 auto is_active = state.world.nation_get_unlocked_commodities(
nations, c);
5854 auto life_weights = state.world.market_get_life_needs_weights(markets, c);
5855 auto everyday_weights = state.world.market_get_everyday_needs_weights(markets, c);
5856 auto luxury_weights = state.world.market_get_luxury_needs_weights(markets, c);
5858 state.world.for_each_pop_type([&](dcon::pop_type_id pop_type) {
5859 if(state.world.pop_type_get_strata(pop_type) != strata_filter) {
5863 auto life_base = state.world.pop_type_get_life_needs(pop_type, c);
5864 auto everyday_base = state.world.pop_type_get_everyday_needs(pop_type, c);
5865 auto luxury_base = state.world.pop_type_get_luxury_needs(pop_type, c);
5867 auto life_costs = prices * life_base * life_needs_mult * life_weights;
5868 auto everyday_costs = prices * everyday_base * everyday_needs_mult * everyday_weights * invention_factor;
5869 auto luxury_costs = prices * luxury_base * luxury_needs_mult * luxury_weights * invention_factor;
5871 state.world.market_set_life_needs_costs(
5874 state.world.market_get_life_needs_costs(markets, pop_type) + life_costs
5876 state.world.market_set_everyday_needs_costs(
5879 state.world.market_get_everyday_needs_costs(markets, pop_type) + everyday_costs
5881 state.world.market_set_luxury_needs_costs(
5884 state.world.market_get_luxury_needs_costs(markets, pop_type) + luxury_costs
5889 assert(std::isfinite(x));
5890 }, state.world.market_get_life_needs_costs(markets, pop_type)
5894 assert(std::isfinite(x));
5895 }, state.world.market_get_everyday_needs_costs(markets, pop_type)
5899 assert(std::isfinite(x));
5900 }, state.world.market_get_luxury_needs_costs(markets, pop_type)
5910 auto offset_life = sys::national_mod_offsets::rich_life_needs;
5911 auto offset_everyday = sys::national_mod_offsets::rich_everyday_needs;
5912 auto offset_luxury = sys::national_mod_offsets::rich_luxury_needs;
5914 auto life_needs_mult =
5915 (state.world.nation_get_modifier_values(
nations, offset_life) + 1.0f)
5916 * state.defines.alice_lf_needs_scale;
5917 auto everyday_needs_mult =
5918 (state.world.nation_get_modifier_values(
nations, offset_everyday) + 1.0f)
5919 * state.defines.alice_ev_needs_scale;
5920 auto luxury_needs_mult =
5921 (state.world.nation_get_modifier_values(
nations, offset_luxury) + 1.0f)
5922 * state.defines.alice_lx_needs_scale;
5924 for(
uint32_t i = 1; i < total_commodities; ++i) {
5925 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
5927 auto prices = state.world.market_get_price(markets, c);
5929 auto available = state.world.commodity_get_is_available_from_start(c);
5930 auto is_active = state.world.nation_get_unlocked_commodities(
nations, c);
5931 auto life_weights = state.world.market_get_life_needs_weights(markets, c);
5932 auto everyday_weights = state.world.market_get_everyday_needs_weights(markets, c);
5933 auto luxury_weights = state.world.market_get_luxury_needs_weights(markets, c);
5935 state.world.for_each_pop_type([&](dcon::pop_type_id pop_type) {
5936 if(state.world.pop_type_get_strata(pop_type) != strata_filter) {
5940 auto life_base = state.world.pop_type_get_life_needs(pop_type, c);
5941 auto everyday_base = state.world.pop_type_get_everyday_needs(pop_type, c);
5942 auto luxury_base = state.world.pop_type_get_luxury_needs(pop_type, c);
5944 auto life_costs = prices * life_base * life_needs_mult * life_weights;
5945 auto everyday_costs = prices * everyday_base * everyday_needs_mult * everyday_weights * invention_factor;
5946 auto luxury_costs = prices * luxury_base * luxury_needs_mult * luxury_weights * invention_factor;
5948 state.world.market_set_life_needs_costs(
5951 state.world.market_get_life_needs_costs(markets, pop_type) + life_costs
5953 state.world.market_set_everyday_needs_costs(
5956 state.world.market_get_everyday_needs_costs(markets, pop_type) + everyday_costs
5958 state.world.market_set_luxury_needs_costs(
5961 state.world.market_get_luxury_needs_costs(markets, pop_type) + luxury_costs
5967 assert(std::isfinite(x));
5968 }, state.world.market_get_life_needs_costs(markets, pop_type)
5972 assert(std::isfinite(x));
5973 }, state.world.market_get_everyday_needs_costs(markets, pop_type)
5977 assert(std::isfinite(x));
5978 }, state.world.market_get_luxury_needs_costs(markets, pop_type)
5984 auto mobilization_impact =
5986 state.world.nation_get_is_mobilized(
nations),
5994 state.world.for_each_commodity([&](dcon::commodity_id c) {
5996 state.world.market_set_demand(markets, c, ve::fp_vector{});
5997 state.world.market_set_intermediate_demand(markets, c, ve::fp_vector{});
5998 state.world.market_set_labor_skilled_demand(markets, 0.f);
5999 state.world.market_set_labor_unskilled_demand(markets, 0.f);
6008 dcon::state_instance_id s,
6013 auto capital = state.world.state_instance_get_capital(s);
6015 for(
auto f : state.world.province_get_factory_location(p)) {
6016 update_single_factory_consumption(
6024 state.world.province_get_nation_from_province_control(p) != n
6028 }, states, markets,
nations, mobilization_impact
6032 sanity_check(state);
6039 state.world.for_each_pop_type([&](
auto pt) {
6040 state.world.execute_serial_over_market([&](
auto ids) {
6041 state.world.market_set_life_needs_scale(ids, pt, 0.f);
6042 state.world.market_set_everyday_needs_scale(ids, pt, 0.f);
6043 state.world.market_set_luxury_needs_scale(ids, pt, 0.f);
6054 for(
auto n :
state.nations_by_rank) {
6055 auto cap_prov =
state.world.nation_get_capital(n);
6056 auto cap_continent =
state.world.province_get_continent(cap_prov);
6057 auto cap_region =
state.world.province_get_connected_region_id(cap_prov);
6065 float budget = 0.0f;
6066 float spending_scale = 0.0f;
6067 if(
state.world.nation_get_is_player_controlled(n)) {
6075 if(sp < ip &&
state.world.nation_get_local_loan(n) >=
max_loan(state, n)) {
6080 state.world.nation_get_national_bank(n) += ip;
6086 spending_scale = 1.0f;
6089 spending_scale = (
total < 0.001f ||
total <= budget) ? 1.0f : budget / total;
6093 spending_scale = (
total < 0.001f ||
total <= budget) ? 1.0f : budget / total;
6097 if(sp < 0 && sp < -
max_loan(state, n)) {
6102 assert(spending_scale >= 0);
6103 assert(std::isfinite(spending_scale));
6104 assert(std::isfinite(budget));
6106 state.world.nation_get_stockpiles(n,
economy::money) -= std::min(budget, total * spending_scale);
6107 state.world.nation_set_spending_level(n, spending_scale);
6110 auto l =
state.world.nation_get_local_loan(n);
6111 if(s < 0 && l <
max_loan(state, n) &&
6112 std::abs(s) <=
max_loan(state, n) - l) {
6113 state.world.nation_get_local_loan(n) += std::abs(s);
6120 else if(s > 0 && l > 0) {
6121 auto change = std::min(s, l);
6127 float perceived_spending = pi_total;
6128 float pi_budget =
state.world.nation_get_private_investment(n);
6129 auto pi_scale = perceived_spending <= pi_budget ? 1.0f : pi_budget / perceived_spending;
6132 state.world.nation_set_private_investment_effective_fraction(n, pi_scale);
6133 state.world.nation_set_private_investment(n, std::max(0.0f, pi_budget - pi_total * pi_scale));
6142 concurrency::parallel_for(
uint32_t(0), total_commodities, [&](
uint32_t k) {
6143 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
6145 if(
state.world.commodity_get_money_rgo(cid)) {
6149 state.world.for_each_trade_route([&](
auto trade_route) {
6150 auto current_volume =
state.world.trade_route_get_volume(trade_route, cid);
6152 current_volume > 0.f
6153 ?
state.world.trade_route_get_connected_markets(trade_route, 0)
6154 :
state.world.trade_route_get_connected_markets(trade_route, 1);
6156 current_volume <= 0.f
6157 ?
state.world.trade_route_get_connected_markets(trade_route, 0)
6158 :
state.world.trade_route_get_connected_markets(trade_route, 1);
6160 auto sat =
state.world.market_get_direct_demand_satisfaction(origin, cid);
6163 current_volume = current_volume * std::max(0.99f, sat);
6164 state.world.trade_route_set_volume(trade_route, cid, current_volume);
6166 auto absolute_volume = std::abs(current_volume);
6168 auto s_origin =
state.world.market_get_zone_from_local_market(origin);
6169 auto s_target =
state.world.market_get_zone_from_local_market(target);
6171 auto n_origin =
state.world.state_instance_get_nation_from_state_ownership(s_origin);
6172 auto n_target =
state.world.state_instance_get_nation_from_state_ownership(s_target);
6174 register_demand(state, origin, cid, absolute_volume, economy_reason::trade);
6184 state.world.execute_parallel_over_market([&](
auto ids) {
6185 auto zones =
state.world.market_get_zone_from_local_market(ids);
6186 auto nations =
state.world.state_instance_get_nation_from_state_ownership(zones);
6188 auto capital_states =
state.world.province_get_state_membership(capital);
6189 auto capital_mask = capital_states == zones;
6190 auto income_scale =
state.world.market_get_income_scale(ids);
6192 for(
uint32_t i = 1; i < total_commodities; ++i) {
6193 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
6196 if(
state.world.commodity_get_money_rgo(c)) {
6200 auto draw_from_stockpile =
state.world.nation_get_drawing_on_stockpiles(
nations, c) ==
true;
6210 auto stockpiles =
state.world.market_get_stockpile(ids, c);
6212 auto merchants_demand = ve::max(0.f, stockpile_target_merchants - stockpiles) *
stockpile_to_supply;
6213 auto merchants_supply = ve::max(0.f, stockpiles - stockpile_target_merchants) *
stockpile_to_supply;
6215 auto production =
state.world.market_get_supply(ids, c);
6218 capital_mask && draw_from_stockpile,
6222 auto total_supply = production + national_stockpile;
6223 auto total_demand =
state.world.market_get_demand(ids, c) + merchants_demand;
6224 auto old_saturation =
state.world.market_get_demand_satisfaction(ids, c);
6225 auto new_saturation =
ve::select(total_demand == 0.f, 0.f, total_supply / total_demand);
6227 auto supply_unsold =
ve::select(total_supply > total_demand, total_supply - total_demand, 0.f);
6228 auto supply_sold = total_supply - supply_unsold;
6229 auto supply_sold_ratio =
ve::select(total_supply > 0.f, supply_sold / total_supply,
ve::select(total_demand == 0.f, ve::fp_vector{ 0.f }, ve::fp_vector{ 0.01f }));
6231 new_saturation = ve::min(new_saturation, 1.f);
6233 auto delayed_saturation =
6234 old_saturation *
state.defines.alice_sat_delay_factor
6235 + new_saturation * (1.f -
state.defines.alice_sat_delay_factor);
6237 state.world.market_set_demand_satisfaction(ids, c, delayed_saturation);
6238 state.world.market_set_consumption(ids, c, delayed_saturation * total_demand);
6239 auto old_supply_sold =
state.world.market_get_supply_sold_ratio(ids, c);
6240 state.world.market_set_supply_sold_ratio(ids, c, old_supply_sold * 0.8f + supply_sold_ratio * 0.2f);
6241 state.world.market_set_direct_demand_satisfaction(ids, c, new_saturation);
6246 auto supply_labor =
state.world.market_get_labor_unskilled_supply(ids);
6247 auto demand_labor =
state.world.market_get_labor_unskilled_demand(ids);
6249 auto satisfaction =
ve::select(demand_labor > 0.f, ve::min(1.f, supply_labor / demand_labor), 1.f);
6250 auto sold =
ve::select(supply_labor > 0.f, ve::min(1.f, demand_labor / supply_labor), 1.f);
6252 state.world.market_set_labor_unskilled_demand_satisfaction(ids, satisfaction);
6253 state.world.market_set_labor_unskilled_supply_sold(ids, sold);
6257 auto supply_labor =
state.world.market_get_labor_skilled_supply(ids);
6258 auto demand_labor =
state.world.market_get_labor_skilled_demand(ids);
6260 auto satisfaction =
ve::select(demand_labor > 0.f, ve::min(1.f, supply_labor / demand_labor), 1.f);
6261 auto sold =
ve::select(supply_labor > 0.f, ve::min(1.f, demand_labor / supply_labor), 1.f);
6263 state.world.market_set_labor_skilled_demand_satisfaction(ids, satisfaction);
6264 state.world.market_set_labor_skilled_supply_sold(ids, sold);
6275 state.world.market_set_stockpile(
6278 state.world.market_get_stockpile(ids, c)
6279 + total_supply - merchants_supply
6280 - total_demand * new_saturation
6281 ) * (1.f - stockpile_spoilage))
6284 state.world.market_set_stockpile(
6288 merchants_supply * supply_sold_ratio
6289 - merchants_demand * new_saturation
6294 total_demand = total_demand - new_saturation * total_demand;
6295 total_supply = total_supply - new_saturation * total_demand;
6298 state.world.market_set_demand(ids, c, merchants_demand +
state.world.market_get_demand(ids, c));
6300 ve::apply([&](
auto value) {
assert(std::isfinite(value)); },
state.world.market_get_stockpile(ids, c));
6308 auto buy_from_nation = ve::min(national_stockpile, total_demand * supply_sold_ratio);
6309 auto bought_from_nation_cost =
6314 state.world.nation_set_stockpiles(
nations, c, national_stockpile - buy_from_nation);
6316 state.world.nation_set_stockpiles(
6327 state.world.execute_parallel_over_pop([&](
auto ids) {
6329 auto provs =
state.world.pop_get_province_from_pop_location(ids);
6330 auto states =
state.world.province_get_state_membership(provs);
6331 auto markets =
state.world.state_instance_get_market_from_local_market(states);
6332 auto income_scale =
state.world.market_get_income_scale(markets);
6333 auto owner_spending =
state.world.nation_get_spending_level(owners);
6335 auto pop_savings =
state.world.pop_get_savings(ids);
6337 auto pop_of_type =
state.world.pop_get_size(ids);
6338 auto adj_pop_of_type = pop_of_type /
state.defines.alice_needs_scaling_factor;
6340 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;
6341 auto const s_spending = owner_spending *
state.world.nation_get_administrative_efficiency(owners) *
6343 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;
6344 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;
6345 auto const p_level =
state.world.nation_get_modifier_values(owners, sys::national_mod_offsets::pension_level);
6346 auto const unemp_level =
state.world.nation_get_modifier_values(owners, sys::national_mod_offsets::unemployment_benefit);
6347 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;
6349 auto types =
state.world.pop_get_poptype(ids);
6351 auto ln_types =
state.world.pop_type_get_life_needs_income_type(types);
6352 auto en_types =
state.world.pop_type_get_everyday_needs_income_type(types);
6353 auto lx_types =
state.world.pop_type_get_luxury_needs_income_type(types);
6355 auto ln_costs = ve::apply(
6356 [&](dcon::pop_type_id pt, dcon::market_id n) {
return pt ?
state.world.market_get_life_needs_costs(n, pt) : 0.0f; },
6358 auto en_costs = ve::apply(
6359 [&](dcon::pop_type_id pt, dcon::market_id n) {
return pt ?
state.world.market_get_everyday_needs_costs(n, pt) : 0.0f; },
6361 auto lx_costs = ve::apply(
6362 [&](dcon::pop_type_id pt, dcon::market_id n) {
return pt ?
state.world.market_get_luxury_needs_costs(n, pt) : 0.0f; },
6365 auto total_costs = ln_costs + en_costs + lx_costs;
6376 auto acc_u =
ve::select(none_of_above, s_spending * adj_pop_of_type * p_level * ln_costs, 0.0f);
6382 acc_u = acc_u +
ve::select(types ==
state.culture_definitions.capitalists, di_level * adj_pop_of_type *
state.defines.alice_domestic_investment_multiplier * total_costs, 0.0f);
6383 acc_u = acc_u +
ve::select(types ==
state.culture_definitions.aristocrat, di_level * adj_pop_of_type *
state.defines.alice_domestic_investment_multiplier * total_costs, 0.0f);
6391 acc_u = acc_u +
ve::select(none_of_above &&
state.world.pop_type_get_has_unemployment(types),
6392 s_spending * (pop_of_type - employment) /
state.defines.alice_needs_scaling_factor * unemp_level * ln_costs, 0.0f);
6394 ve::fp_vector base_income{};
6396 base_income = pop_of_type * average_expected_savings * (1.f - presimulation_stage);
6399 state.world.pop_set_savings(ids, (income_scale *
state.inflation) * (base_income + (acc_e + acc_m) + (acc_u + acc_a)));
6401 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_e);
6402 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_m);
6403 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_u);
6404 ve::apply([](
float v) {
assert(std::isfinite(v) && v >= 0); }, acc_a);
6412 auto n = dcon::nation_id{ dcon::nation_id::value_base_t(i) };
6413 if(
state.world.nation_get_owned_province_count(n) == 0)
6416 auto capital =
state.world.nation_get_capital(n);
6417 auto capital_market =
state.world.state_instance_get_market_from_local_market(
6418 state.world.province_get_state_membership(capital)
6427 auto nations_commodity_spending =
state.world.nation_get_spending_level(n);
6428 float refund = 0.0f;
6430 float max_sp = 0.0f;
6432 float spending_level = float(state.world.nation_get_naval_spending(n)) / 100.0f;
6434 state.world.nation_for_each_state_ownership_as_nation(n, [&](dcon::state_ownership_id soid) {
6435 auto local_state = state.world.state_ownership_get_state(soid);
6436 auto local_market = state.world.state_instance_get_market_from_local_market(local_state);
6437 for(uint32_t k = 1; k < total_commodities; ++k) {
6438 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
6440 auto sat = state.world.market_get_demand_satisfaction(local_market, c);
6441 auto val = state.world.market_get_navy_demand(local_market, c);
6445 * nations_commodity_spending
6447 * price(state, local_market, c);
6448 assert(delta >= 0.f);
6451 max_sp += val * sat;
6457 state.world.nation_set_effective_naval_spending(
6458 n, nations_commodity_spending * max_sp * spending_level);
6461 float max_sp = 0.0f;
6463 float spending_level = float(
state.world.nation_get_land_spending(n)) / 100.0f;
6465 state.world.nation_for_each_state_ownership_as_nation(n, [&](dcon::state_ownership_id soid) {
6466 auto local_state =
state.world.state_ownership_get_state(soid);
6467 auto local_market =
state.world.state_instance_get_market_from_local_market(local_state);
6468 for(
uint32_t k = 1; k < total_commodities; ++k) {
6469 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
6471 auto sat =
state.world.market_get_demand_satisfaction(local_market, c);
6472 auto val =
state.world.market_get_army_demand(local_market, c);
6476 * nations_commodity_spending
6478 *
price(state, local_market, c);
6482 max_sp +=
val * sat;
6487 state.world.nation_set_effective_land_spending(
6488 n, nations_commodity_spending * max_sp * spending_level);
6491 state.world.nation_set_effective_construction_spending(
6493 nations_commodity_spending
6500 for(
uint32_t k = 1; k < total_commodities; ++k) {
6501 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
6502 auto difference =
state.world.nation_get_stockpile_targets(n, c) -
state.world.nation_get_stockpiles(n, c);
6503 if(difference > 0.f &&
state.world.nation_get_drawing_on_stockpiles(n, c) ==
false) {
6504 auto sat =
state.world.market_get_direct_demand_satisfaction(capital_market, c);
6505 state.world.nation_get_stockpiles(n, c) +=
6506 difference * nations_commodity_spending * sat;
6510 * nations_commodity_spending
6511 *
price(state, capital_market, c);
6524 auto overseas_factor =
state.defines.province_overseas_penalty
6526 state.world.nation_get_owned_province_count(n)
6527 -
state.world.nation_get_central_province_count(n)
6529 auto overseas_budget = float(
state.world.nation_get_overseas_spending(n)) / 100.f;
6530 auto overseas_budget_satisfaction = 1.f;
6532 if(overseas_factor > 0) {
6533 for(
uint32_t k = 1; k < total_commodities; ++k) {
6534 dcon::commodity_id c{ dcon::commodity_id::value_base_t(k) };
6535 if(
state.world.commodity_get_overseas_penalty(c) &&
valid_need(state, n, c)) {
6536 auto sat =
state.world.market_get_demand_satisfaction(capital_market, c);
6537 overseas_budget_satisfaction = std::min(sat, overseas_budget_satisfaction);
6538 auto price_of =
price(state, capital_market, c);
6539 auto delta = overseas_factor
6540 * (1.0f - sat) * nations_commodity_spending * price_of;
6546 state.world.nation_set_overseas_penalty(n, overseas_budget
6547 * overseas_budget_satisfaction);
6549 state.world.nation_set_overseas_penalty(n, 1.0f);
6554 assert(std::isfinite(refund) && refund >= 0.0f);
6555 state.world.nation_get_stockpiles(n, money) += refund;
6563 state.world.execute_parallel_over_market([&](
auto ids) {
6564 auto states =
state.world.market_get_zone_from_local_market(ids);
6565 auto nations =
state.world.state_instance_get_nation_from_state_ownership(states);
6568 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
6569 ve::fp_vector ln_total = 0.0f;
6570 ve::fp_vector en_total = 0.0f;
6571 ve::fp_vector lx_total = 0.0f;
6573 ve::fp_vector ln_max = 0.0f;
6574 ve::fp_vector en_max = 0.0f;
6575 ve::fp_vector lx_max = 0.0f;
6577 for(
uint32_t i = 1; i < total_commodities; ++i) {
6578 dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
6579 auto sat =
state.world.market_get_demand_satisfaction(ids, c);
6582 auto ln_val =
ve::select(valid_mask, ve::fp_vector{
state.world.pop_type_get_life_needs(pt, c) }, ve::fp_vector{ 0.f });
6584 ln_total = ln_total + ln_val;
6585 ln_max = ln_max + ln_val * sat *
state.world.market_get_life_needs_weights(ids, c);
6587 auto en_val =
ve::select(valid_mask, ve::fp_vector{
state.world.pop_type_get_everyday_needs(pt, c) }, ve::fp_vector{ 0.f });
6589 en_total = en_total + en_val;
6590 en_max = en_max + en_val * sat *
state.world.market_get_everyday_needs_weights(ids, c);
6592 auto lx_val =
ve::select(valid_mask, ve::fp_vector{
state.world.pop_type_get_luxury_needs(pt, c) }, ve::fp_vector{ 0.f });
6594 lx_total = lx_total + lx_val;
6595 lx_max = lx_max + lx_val * sat *
state.world.market_get_luxury_needs_weights(ids, c);
6598 ln_max =
ve::select(ln_total > 0.f, ln_max / ln_total, 1.f);
6599 en_max =
ve::select(en_total > 0.f, en_max / en_total, 1.f);
6600 lx_max =
ve::select(lx_total > 0.f, lx_max / lx_total, 1.f);
6602 ve::apply([](
float life,
float everyday,
float luxury) {
6603 assert(life >= 0.f && life <= 1.f);
6604 assert(everyday >= 0.f && everyday <= 1.f);
6605 assert(luxury >= 0.f && luxury <= 1.f);
6606 }, ln_max, en_max, lx_max);
6608 state.world.market_set_max_life_needs_satisfaction(ids, pt, ln_max);
6609 state.world.market_set_max_everyday_needs_satisfaction(ids, pt, en_max);
6610 state.world.market_set_max_luxury_needs_satisfaction(ids, pt, lx_max);
6619 state.world.for_each_commodity([&](dcon::commodity_id c) {
6620 state.world.execute_serial_over_market([&](
auto markets) {
6621 if(
state.world.commodity_get_money_rgo(c)) {
6622 state.world.market_set_supply(markets, c, ve::fp_vector{});
6624 auto stockpiles =
state.world.market_get_stockpile(markets, c);
6626 auto merchants_supply = ve::max(0.f, stockpiles - stockpile_target_merchants) *
stockpile_to_supply;
6627 state.world.market_set_supply(markets, c, merchants_supply);
6630 state.world.market_set_import(markets, c, ve::fp_vector{});
6631 state.world.market_set_export(markets, c, ve::fp_vector{});
6634 state.world.market_set_labor_skilled_supply(markets, 0.f);
6635 state.world.market_set_labor_unskilled_supply(markets, 0.f);
6642 concurrency::parallel_for(
uint32_t(1), total_commodities, [&](
uint32_t k) {
6643 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
6645 if(
state.world.commodity_get_money_rgo(cid)) {
6649 state.world.for_each_trade_route([&](
auto trade_route) {
6652 state.world.market_get_export(route_data.origin, cid) += route_data.amount_origin;
6653 state.world.market_get_import(route_data.target, cid) += route_data.amount_target;
6654 state.world.market_get_stockpile(route_data.origin,
economy::money) += route_data.amount_origin * route_data.payment_received_per_unit;
6655 state.world.market_get_stockpile(route_data.target,
economy::money) -= route_data.amount_origin * route_data.payment_per_unit;
6656 state.world.market_get_tariff_collected(route_data.origin) += route_data.tariff_origin;
6657 state.world.market_get_tariff_collected(route_data.target) += route_data.tariff_target;
6658 state.world.market_get_stockpile(route_data.target, cid) += route_data.amount_target;
6660 assert(std::isfinite(
state.world.market_get_export(route_data.origin, cid)));
6661 assert(std::isfinite(
state.world.market_get_import(route_data.target, cid)));
6668 state.world.execute_serial_over_market([&](
auto ids) {
6674 auto const primary_def =
state.culture_definitions.primary_factory_worker;
6677 auto const secondary_def =
state.culture_definitions.secondary_factory_worker;
6680 state.world.execute_serial_over_market([&](
auto ids) {
6681 auto sid =
state.world.market_get_zone_from_local_market(ids);
6683 auto primary =
state.world.state_instance_get_demographics(sid, primary_key);
6686 auto secondary =
state.world.state_instance_get_demographics(sid, secondary_key);
6693 auto amount_of_nations =
state.world.nation_size();
6695 for (
auto n :
state.world.in_nation) {
6698 for(
auto p :
state.world.nation_get_province_ownership(n)) {
6700 auto local_state =
province.get_state_membership();
6701 auto market = local_state.get_market_from_local_market();
6704 for(
auto f :
state.world.province_get_factory_location(p.get_province())) {
6719 float subsistence_life = std::clamp(subsistence, 0.f, subsistence_score_life);
6720 subsistence -= subsistence_life;
6721 float subsistence_everyday = std::clamp(subsistence, 0.f, subsistence_score_everyday);
6722 subsistence -= subsistence_everyday;
6727 for(
auto pl : p.get_province().get_pop_location()) {
6728 auto t = pl.get_pop().get_poptype();
6736 ln -= subsistence_life;
6737 en -= subsistence_everyday;
6741 ln = std::max(0.f, ln);
6742 en = std::max(0.f, en);
6743 lx = std::max(0.f, lx);
6745 assert(std::isfinite(ln));
6746 assert(std::isfinite(en));
6747 assert(std::isfinite(lx));
6749 ln = std::min(1.f, ln) *
state.world.market_get_max_life_needs_satisfaction(market, t);
6750 en = std::min(1.f, en) *
state.world.market_get_max_everyday_needs_satisfaction(market, t);
6751 lx = std::min(1.f, lx) *
state.world.market_get_max_luxury_needs_satisfaction(market, t);
6753 ln = std::min(1.f, ln + subsistence_life);
6754 en = std::min(1.f, en + subsistence_everyday);
6766 auto const artisan_def =
state.culture_definitions.artisans;
6768 auto const clerks_def =
state.culture_definitions.secondary_factory_worker;
6770 auto const capis_def =
state.culture_definitions.capitalists;
6773 for(
auto si :
state.world.nation_get_state_ownership(n)) {
6774 float total_profit = 0.f;
6775 float rgo_owner_profit = 0.f;
6777 auto sid = si.get_state();
6779 auto market = si.get_state().get_market_from_local_market();
6780 auto income_scale =
state.world.market_get_income_scale(market);
6785 auto artisans =
state.world.state_instance_get_demographics(sid, artisan_key);
6786 auto clerks =
state.world.state_instance_get_demographics(sid, clerks_key);
6787 auto capis =
state.world.state_instance_get_demographics(sid, capis_key);
6789 auto artisans_weight =
state.world.state_instance_get_demographics(sid, artisan_key) / 1000.f;
6790 auto clerks_weight =
state.world.state_instance_get_demographics(sid, clerks_key) * 100.f;
6791 auto capis_weight =
state.world.state_instance_get_demographics(sid, capis_key) * 100'000.f;
6793 auto total_weight = artisans_weight + clerks_weight + capis_weight;
6795 if(total_weight > 0 && trade_income > 0) {
6796 auto artisans_share = artisans_weight / total_weight * trade_income;
6797 auto clerks_share = clerks_weight / total_weight * trade_income;
6798 auto capis_share = capis_weight / total_weight * trade_income;
6800 auto per_artisan = 0.f;
6801 auto per_clerk = 0.f;
6802 auto per_capi = 0.f;
6804 if(artisans > 0.f) {
6805 per_artisan = artisans_share / artisans;
6808 per_clerk = clerks_share / clerks;
6811 per_capi = capis_share / capis;
6815 for(
auto pl :
state.world.province_get_pop_location(p)) {
6816 if(artisan_def == pl.get_pop().get_poptype()) {
6817 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * per_artisan);
6818 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6819 }
else if(clerks_def == pl.get_pop().get_poptype()) {
6820 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * per_clerk);
6821 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6822 }
else if(capis_def == pl.get_pop().get_poptype()) {
6823 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * per_capi);
6824 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6826 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6839 auto const artisan_type =
state.culture_definitions.artisans;
6842 float num_artisans =
state.world.nation_get_demographics(n, key);
6843 if(num_artisans > 0) {
6844 for(
auto p :
state.world.nation_get_province_ownership(n)) {
6846 auto local_state =
province.get_state_membership();
6847 auto market = local_state.get_market_from_local_market();
6848 auto income_scale =
state.world.market_get_income_scale(market);
6849 float artisan_profit =
state.world.market_get_artisan_profit(market);
6850 auto local_artisans =
state.world.state_instance_get_demographics(local_state, key);
6851 if(local_artisans == 0.f) {
6854 auto per_profit = artisan_profit / num_artisans;
6855 for(
auto pl : p.get_province().get_pop_location()) {
6856 if(artisan_type == pl.get_pop().get_poptype()) {
6857 pl.get_pop().set_savings(
6858 pl.get_pop().get_savings()
6861 * pl.get_pop().get_size()
6865 std::isfinite(pl.get_pop().get_savings())
6866 && pl.get_pop().get_savings() >= 0
6869 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6879 for(
auto si :
state.world.nation_get_state_ownership(n)) {
6880 float total_profit = 0.f;
6881 float rgo_owner_profit = 0.f;
6883 auto market = si.get_state().get_market_from_local_market();
6884 auto income_scale =
state.world.market_get_income_scale(market);
6886 float local_farmer_min_wage =
farmer_min_wage(state, market, min_wage_factor);
6887 float local_laborer_min_wage =
laborer_min_wage(state, market, min_wage_factor);
6889 float num_capitalist =
state.world.state_instance_get_demographics(
6894 float num_aristocrat =
state.world.state_instance_get_demographics(
6899 float num_rgo_owners = num_capitalist + num_aristocrat;
6901 auto capitalists_ratio = num_capitalist / (num_rgo_owners + 1.f);
6902 auto aristocrats_ratio = num_aristocrat / (num_rgo_owners + 1.f);
6905 state, si.get_state(), [&](dcon::province_id p) {
6906 for(auto f : state.world.province_get_factory_location(p)) {
6907 total_profit += std::max(0.f, f.get_factory().get_full_profit());
6912 bool is_mine = state.world.commodity_get_is_mine(state.world.province_get_rgo(p));
6914 auto const min_wage =
6915 (is_mine ? local_laborer_min_wage : local_farmer_min_wage)
6916 / state.defines.alice_needs_scaling_factor;
6918 float total_min_to_workers = 0.0f;
6919 float num_workers = 0.0f;
6920 for(auto wt : state.culture_definitions.rgo_workers) {
6921 total_min_to_workers +=
6923 * state.world.province_get_demographics(
6925 demographics::to_employment_key(state, wt)
6928 state.world.province_get_demographics(p, demographics::to_key(state, wt));
6930 float total_rgo_profit =
state.world.province_get_rgo_full_profit(p);
6931 float total_worker_wage = 0.0f;
6933 if(num_rgo_owners > 0) {
6935 rgo_owner_profit += rgo_owners_cut * total_rgo_profit;
6936 total_rgo_profit = (1.f - rgo_owners_cut) * total_rgo_profit;
6939 total_worker_wage = total_rgo_profit;
6941 auto per_worker_profit = num_workers > 0 ? total_worker_wage / num_workers : 0.0f;
6943 for(
auto pl :
state.world.province_get_pop_location(p)) {
6944 if(pl.get_pop().get_poptype().get_is_paid_rgo_worker()) {
6945 pl.get_pop().set_savings(
6946 pl.get_pop().get_savings()
6947 + income_scale * state.inflation * pl.get_pop().get_size() * per_worker_profit);
6949 std::isfinite(pl.get_pop().get_savings())
6950 && pl.get_pop().get_savings() >= 0
6953 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6958 auto const per_rgo_owner_profit = num_rgo_owners > 0 ? rgo_owner_profit / num_rgo_owners : 0.0f;
6963 for(auto pl : state.world.province_get_pop_location(p)) {
6964 if(state.culture_definitions.primary_factory_worker == pl.get_pop().get_poptype()) {
6965 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * profit.per_primary_worker);
6966 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6967 } else if(state.culture_definitions.secondary_factory_worker == pl.get_pop().get_poptype()) {
6968 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * profit.per_secondary_worker);
6969 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6970 } else if(state.culture_definitions.capitalists == pl.get_pop().get_poptype()) {
6971 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * (profit.per_owner + per_rgo_owner_profit));
6972 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6973 } else if(state.culture_definitions.aristocrat == pl.get_pop().get_poptype()) {
6974 pl.get_pop().set_savings(pl.get_pop().get_savings() + income_scale * state.inflation * pl.get_pop().get_size() * per_rgo_owner_profit);
6975 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6977 assert(std::isfinite(pl.get_pop().get_savings()) && pl.get_pop().get_savings() >= 0);
6990 auto edu_money = 0.f;
6991 auto adm_money = 0.f;
6992 auto const edu_adm_spending = 0.05f;
6993 auto const edu_adm_effect = 1.f - edu_adm_spending;
6994 auto const education_ratio = 0.8f;
6995 auto from_investment_pool =
state.world.nation_get_private_investment(n);
6996 state.world.nation_set_private_investment(n, from_investment_pool * 0.999f);
6997 from_investment_pool *= 0.001f;
7000 for(
auto p :
state.world.nation_get_province_ownership(n)) {
7002 if(
state.world.province_get_nation_from_province_ownership(
province) ==
state.world.province_get_nation_from_province_control(
province)) {
7004 float local_teachers = 0.f;
7005 float local_managers = 0.f;
7006 for(
auto pl :
province.get_pop_location()) {
7008 auto pop = pl.get_pop();
7009 auto pt =
pop.get_poptype();
7012 local_managers +=
pop.get_size();
7014 local_teachers +=
pop.get_size();
7018 auto const pop_money =
pop.get_savings();
7019 pop.set_savings(pop_money + payment_per_pop);
7021 if(local_teachers + local_managers > 0.f) {
7022 for(
auto pl :
province.get_pop_location()) {
7023 auto const pop_money = pl.get_pop().get_savings();
7024 current += pop_money * edu_adm_spending;
7025 pl.get_pop().set_savings(pop_money * edu_adm_effect);
7026 assert(std::isfinite(pl.get_pop().get_savings()));
7029 float local_education_ratio = education_ratio;
7030 if(local_managers == 0.f) {
7031 local_education_ratio = 1.f;
7033 for(
auto pl :
province.get_pop_location()) {
7034 auto pop = pl.get_pop();
7035 auto pt =
pop.get_poptype();
7038 float ratio = (local_managers > 0.f) ?
pop.get_size() / local_managers : 0.f;
7039 pop.set_savings(
pop.get_savings() +
current * (1.f - local_education_ratio) * ratio);
7040 assert(std::isfinite(
pop.get_savings()));
7041 adm_money +=
current * (1.f - local_education_ratio) * ratio;
7043 float ratio = (local_teachers > 0.f) ?
pop.get_size() / local_teachers : 0.f;
7044 pop.set_savings(
pop.get_savings() +
current * local_education_ratio * ratio);
7045 assert(std::isfinite(
pop.get_savings()));
7046 edu_money +=
current * local_education_ratio * ratio;
7051 state.world.nation_set_private_investment_education(n, edu_money);
7052 state.world.nation_set_private_investment_administration(n, adm_money);
7060 state.world.for_each_nation([&](dcon::nation_id n) {
7061 state.world.nation_set_stockpiles(n, money, 0.f);
7067 float total_poor_tax_base = 0.0f;
7068 float total_mid_tax_base = 0.0f;
7069 float total_rich_tax_base = 0.0f;
7071 auto const poor_effect = (1.0f - tax_eff * float(
state.world.nation_get_poor_tax(n)) / 100.0f);
7072 auto const middle_effect = (1.0f - tax_eff * float(
state.world.nation_get_middle_tax(n)) / 100.0f);
7073 auto const rich_effect = (1.0f - tax_eff * float(
state.world.nation_get_rich_tax(n)) / 100.0f);
7075 assert(poor_effect >= 0 && middle_effect >= 0 && rich_effect >= 0);
7077 for(
auto p :
state.world.nation_get_province_ownership(n)) {
7079 if(
state.world.province_get_nation_from_province_ownership(
province) ==
state.world.province_get_nation_from_province_control(
province)) {
7080 for(
auto pl :
province.get_pop_location()) {
7081 auto& pop_money = pl.get_pop().get_savings();
7084 total_poor_tax_base += pop_money;
7085 pop_money *= poor_effect;
7087 total_mid_tax_base += pop_money;
7088 pop_money *= middle_effect;
7090 total_rich_tax_base += pop_money;
7091 pop_money *= rich_effect;
7093 assert(std::isfinite(pl.get_pop().get_savings()));
7098 state.world.nation_set_total_rich_income(n, total_rich_tax_base);
7099 state.world.nation_set_total_middle_income(n, total_mid_tax_base);
7100 state.world.nation_set_total_poor_income(n, total_poor_tax_base);
7101 auto collected_tax = total_poor_tax_base * tax_eff * float(
state.world.nation_get_poor_tax(n)) / 100.0f +
7102 total_mid_tax_base * tax_eff * float(
state.world.nation_get_middle_tax(n)) / 100.0f +
7103 total_rich_tax_base * tax_eff * float(
state.world.nation_get_rich_tax(n)) / 100.0f;
7104 assert(std::isfinite(collected_tax));
7105 assert(collected_tax >= 0);
7106 state.world.nation_get_stockpiles(n, money) += collected_tax;
7113 float t_total = 0.0f;
7115 for(
auto si :
state.world.nation_get_state_ownership(n)) {
7116 float total_profit = 0.f;
7117 float rgo_owner_profit = 0.f;
7119 auto market = si.get_state().get_market_from_local_market();
7120 auto capital = si.get_state().get_capital();
7121 if(
capital.get_nation_from_province_control() == n) {
7122 t_total +=
state.world.market_get_tariff_collected(market);
7124 state.world.market_set_tariff_collected(market, 0.f);
7127 assert(std::isfinite(t_total));
7129 state.world.nation_get_stockpiles(n, money) += t_total;
7133 for(
auto si :
state.world.nation_get_state_ownership(n)) {
7134 float total_profit = 0.f;
7135 float rgo_owner_profit = 0.f;
7137 auto market = si.get_state().get_market_from_local_market();
7141 state.world.execute_serial_over_market([&](
auto ids) {
7142 auto local_states =
state.world.market_get_zone_from_local_market(ids);
7143 auto nations =
state.world.state_instance_get_nation_from_state_ownership(local_states);
7153 state.world.execute_serial_over_market([&](
auto ids) {
7174 state.world.for_each_commodity([&](dcon::commodity_id c) {
7175 if(!
state.world.commodity_get_money_rgo(c))
7177 state.world.market_set_price(ids, c, 10.f *
state.world.commodity_get_cost(c));
7183 state.world.execute_serial_over_market([&](
auto ids) {
7185 state.world.market_get_labor_unskilled_supply(ids)
7188 state.world.market_get_labor_unskilled_demand(ids)
7191 auto current_price =
state.world.market_get_labor_unskilled_price(ids);
7192 auto oversupply_factor = ve::max(supply / demand - 1.f, 0.f);
7193 auto overdemand_factor = ve::max(demand / supply - 1.f, 0.f);
7194 auto speed_modifer = (overdemand_factor - oversupply_factor);
7195 auto price_speed = 0.0001f * speed_modifer;
7196 price_speed = price_speed * current_price;
7197 current_price = current_price + price_speed;
7199 auto sids =
state.world.market_get_zone_from_local_market(ids);
7200 auto nids =
state.world.state_instance_get_nation_from_state_ownership(sids);
7205 ve::fp_vector price_control = ve::fp_vector{ 0.f };
7206 price_control = price_control +
state.world.market_get_life_needs_costs(ids,
state.culture_definitions.primary_factory_worker);
7207 price_control = price_control +
state.world.market_get_everyday_needs_costs(ids,
state.culture_definitions.primary_factory_worker);
7215 *
state.world.market_get_labor_unskilled_supply_sold(ids)
7216 *
state.world.nation_get_administrative_efficiency(nids)
7217 /
state.defines.alice_needs_scaling_factor
7221 ve::apply([&](
auto value) {
assert(std::isfinite(value)); }, current_price);
7223 state.world.market_set_labor_unskilled_price(ids, ve::min(ve::max(current_price, ve::max(0.000001f, price_control)), 1'000'000'000'000.f));
7229 state.world.execute_serial_over_market([&](
auto ids) {
7231 state.world.market_get_labor_skilled_supply(ids)
7234 state.world.market_get_labor_skilled_demand(ids)
7237 auto current_price =
state.world.market_get_labor_skilled_price(ids);
7238 auto oversupply_factor = ve::max(supply / demand - 1.f, 0.f);
7239 auto overdemand_factor = ve::max(demand / supply - 1.f, 0.f);
7240 auto speed_modifer = (overdemand_factor - oversupply_factor);
7241 auto price_speed = 0.0001f * speed_modifer;
7242 price_speed = price_speed * current_price;
7243 current_price = current_price + price_speed;
7245 auto sids =
state.world.market_get_zone_from_local_market(ids);
7246 auto nids =
state.world.state_instance_get_nation_from_state_ownership(sids);
7251 ve::fp_vector price_control = ve::fp_vector{ 0.f };
7252 price_control = price_control +
state.world.market_get_life_needs_costs(ids,
state.culture_definitions.secondary_factory_worker);
7253 price_control = price_control +
state.world.market_get_everyday_needs_costs(ids,
state.culture_definitions.secondary_factory_worker);
7261 *
state.world.market_get_labor_unskilled_supply_sold(ids)
7262 *
state.world.nation_get_administrative_efficiency(nids)
7263 /
state.defines.alice_needs_scaling_factor
7267 ve::apply([&](
auto value) {
assert(std::isfinite(value)); }, current_price);
7269 state.world.market_set_labor_skilled_price(ids, ve::min(ve::max(current_price, ve::max(0.000001f, price_control)), 1'000'000'000'000.f));
7273 state.world.execute_serial_over_market([&](
auto ids) {
7274 concurrency::parallel_for(
uint32_t(1), total_commodities, [&](
uint32_t k) {
7275 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
7278 if(
state.world.commodity_get_money_rgo(cid)) {
7288 state.world.market_get_supply(ids, cid)
7291 state.world.market_get_demand(ids, cid)
7294 auto current_price =
ve_price(state, ids, cid);
7295 auto oversupply_factor = ve::max(supply / demand - 1.f, 0.f);
7296 auto overdemand_factor = ve::max(demand / supply - 1.f, 0.f);
7297 auto speed_modifer = (overdemand_factor - oversupply_factor);
7298 auto price_speed = ve::min(ve::max(price_speed_mod * speed_modifer, -0.025f), 0.025f);
7299 price_speed = price_speed * current_price;
7300 current_price = current_price + price_speed;
7303 ve::apply([&](
auto value) {
assert(std::isfinite(value)); }, current_price);
7307 state.world.market_set_price(ids, cid, ve::min(ve::max(current_price, 0.001f), 1'000'000'000'000.f));
7313 if(
state.cheat_data.ecodump) {
7314 float accumulator[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
7316 state.world.for_each_commodity([&](dcon::commodity_id c) {
7317 float states_count = 0.f;
7318 float total_price = 0.f;
7319 float total_production = 0.f;
7320 float total_demand = 0.f;
7322 state.world.for_each_market([&](
auto id) {
7324 total_price +=
state.world.market_get_price(
id, c);
7325 total_production +=
state.world.market_get_supply(
id, c);
7326 total_demand +=
state.world.market_get_demand(
id, c);
7329 state.cheat_data.prices_dump_buffer += std::to_string(total_price / states_count) +
",";
7330 state.cheat_data.supply_dump_buffer += std::to_string(total_production) +
",";
7331 state.cheat_data.demand_dump_buffer += std::to_string(total_demand) +
",";
7334 state.cheat_data.prices_dump_buffer +=
"\n";
7335 state.cheat_data.supply_dump_buffer +=
"\n";
7336 state.cheat_data.demand_dump_buffer +=
"\n";
7344 for(
auto n :
state.world.in_nation) {
7346 auto rel =
state.world.nation_get_overlord_as_subject(n);
7351 state.world.nation_get_stockpiles(n, money) -= transferamt;
7352 state.world.nation_get_stockpiles(overlord, money) += transferamt;
7355 for(
auto uni :
n.get_unilateral_relationship_as_source()) {
7356 if(uni.get_war_subsidies()) {
7359 if(sub_size <=
n.get_stockpiles(money)) {
7360 n.get_stockpiles(money) -= sub_size;
7361 uni.get_target().get_stockpiles(money) += sub_size;
7363 uni.set_war_subsidies(
false);
7369 "msg_wsub_end_title",
7370 n.id, uni.get_target().id, dcon::nation_id{},
7375 if(uni.get_reparations() &&
state.current_date <
n.get_reparations_until()) {
7377 auto total_tax_base =
n.get_total_rich_income() +
n.get_total_middle_income() +
n.get_total_poor_income();
7379 auto payout = total_tax_base * tax_eff *
state.defines.reparations_tax_hit;
7380 auto capped_payout = std::min(
n.get_stockpiles(money), payout);
7381 assert(capped_payout >= 0.0f);
7383 n.get_stockpiles(money) -= capped_payout;
7384 uni.get_target().get_stockpiles(money) += capped_payout;
7402 float total_pop_money = 0.0f;
7403 state.world.for_each_nation([&](dcon::nation_id n) {
7406 state.world.nation_get_total_rich_income(n)
7407 +
state.world.nation_get_total_middle_income(n)
7408 +
state.world.nation_get_total_poor_income(n);
7410 float target_money =
total_pop * average_expected_savings;
7415 state.world.for_each_market([&](
auto ids) {
7416 auto sid =
state.world.market_get_zone_from_local_market(ids);
7418 float target_money = local_pop * average_expected_savings;
7420 float local_money = 0.f;
7422 state.world.province_for_each_pop_location(pid, [&](
auto pop_location) {
7423 auto pop =
state.world.pop_location_get_pop(pop_location);
7424 local_money +=
state.world.pop_get_savings(pop);
7428 float target_scale = target_money / (local_money + 0.0001f);
7429 float prev_scale =
state.world.market_get_income_scale(ids);
7431 state.world.market_set_income_scale(ids, ve::fp_vector{ 1.f });
7439 if(!presimulation) {
7446 if(
state.cheat_data.ecodump) {
7447 for(
auto si :
state.world.in_state_instance) {
7448 auto market = si.get_market_from_local_market();
7449 auto nation = si.get_nation_from_state_ownership();
7452 state.world.market_get_life_needs_costs(
7453 market,
state.culture_definitions.primary_factory_worker)
7454 +
state.world.market_get_everyday_needs_costs(
7455 market,
state.culture_definitions.primary_factory_worker)
7456 +
state.world.market_get_luxury_needs_costs(
7457 market,
state.culture_definitions.primary_factory_worker);
7460 state.world.national_identity_get_identifying_int(
7461 state.world.nation_get_identity_from_identity_holder(nation)
7466 state.world.state_definition_get_name(
7471 state.cheat_data.national_economy_dump_buffer +=
7475 + std::to_string(
state.world.market_get_gdp(market)) +
","
7476 + std::to_string(life_costs) +
","
7478 + std::to_string(
state.current_date.value) +
"\n";
7486 state.culture_definitions.rgo_workers.clear();
7487 for(
auto pt : state.world.in_pop_type) {
7488 if(pt.get_is_paid_rgo_worker())
7489 state.culture_definitions.rgo_workers.push_back(pt);
7492 auto const total_commodities = state.world.commodity_size();
7493 for(
uint32_t k = 1; k < total_commodities; ++k) {
7494 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
7495 for(
auto pt : state.world.in_pop_type) {
7496 if(pt != state.culture_definitions.slaves) {
7497 if(pt.get_life_needs(cid) > 0.0f)
7498 state.world.commodity_set_is_life_need(cid,
true);
7499 if(pt.get_everyday_needs(cid) > 0.0f)
7500 state.world.commodity_set_is_everyday_need(cid,
true);
7501 if(pt.get_luxury_needs(cid) > 0.0f)
7502 state.world.commodity_set_is_luxury_need(cid,
true);
7507 state.world.market_resize_intermediate_demand(state.world.commodity_size());
7509 state.world.market_resize_life_needs_costs(state.world.pop_type_size());
7510 state.world.market_resize_everyday_needs_costs(state.world.pop_type_size());
7511 state.world.market_resize_luxury_needs_costs(state.world.pop_type_size());
7513 state.world.market_resize_life_needs_scale(state.world.pop_type_size());
7514 state.world.market_resize_everyday_needs_scale(state.world.pop_type_size());
7515 state.world.market_resize_luxury_needs_scale(state.world.pop_type_size());
7517 state.world.market_resize_max_life_needs_satisfaction(state.world.pop_type_size());
7518 state.world.market_resize_max_everyday_needs_satisfaction(state.world.pop_type_size());
7519 state.world.market_resize_max_luxury_needs_satisfaction(state.world.pop_type_size());
7521 state.world.province_resize_rgo_actual_production_per_good(state.world.commodity_size());
7525 auto overseas_factor =
7526 state.defines.province_overseas_penalty *
7528 state.world.nation_get_owned_province_count(n)
7529 - state.world.nation_get_central_province_count(n)
7531 auto o_adjust = 0.0f;
7532 if(overseas_factor > 0) {
7534 state.world.commodity_get_overseas_penalty(c)
7536 state.world.commodity_get_is_available_from_start(c)
7537 || state.world.nation_get_unlocked_commodities(n, c)
7540 o_adjust = overseas_factor;
7546 state.world.nation_for_each_state_ownership_as_nation(n, [&](
auto soid) {
7548 state.world.state_instance_get_market_from_local_market(
7549 state.world.state_ownership_get_state(soid)
7551 total = total + state.world.market_get_army_demand(market, c);
7552 total = total + state.world.market_get_navy_demand(market, c);
7553 total = total + state.world.market_get_construction_demand(market, c);
7556 return total + o_adjust;
7561 auto& costs = fat.get_construction_costs();
7563 float factory_mod = state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::factory_cost) + 1.0f;
7564 float admin_eff = state.world.nation_get_administrative_efficiency(state.local_player_nation);
7565 float admin_cost_factor = (2.0f - admin_eff) * factory_mod;
7569 auto cid = costs.commodity_type[i];
7571 total +=
price(state, m, cid) * costs.commodity_amounts[i] * admin_cost_factor;
7578float factory_type_output_cost(
7582 dcon::factory_type_id factory_type
7584 auto fac_type =
dcon::fatten(state.world, factory_type);
7586 float total_production = fac_type.get_output_amount() * output_multiplier;
7588 return total_production *
price(state, m, fac_type.get_output());
7591float factory_type_input_cost(
7595 dcon::factory_type_id factory_type
7597 auto fac_type =
dcon::fatten(state.world, factory_type);
7602 auto const maint_multiplier = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
7605 return input_total * input_multiplier + e_input_total * input_multiplier * maint_multiplier;
7610 for(
auto ownership : state.world.nation_get_province_ownership(n)) {
7611 for(
auto location : state.world.province_get_factory_location(ownership.get_province())) {
7613 auto f = state.world.factory_location_get_factory(location);
7614 auto p = ownership.get_province();
7615 auto s = p.get_state_membership();
7616 auto m = s.get_market_from_local_market();
7617 auto fac = fatten(state.world, f);
7618 auto fac_type = fac.get_building_type();
7621 float min_input_available = 1.f;
7622 float min_e_input_available = 1.f;
7631 float total_production = fac_type.get_output_amount()
7632 * (0.75f + 0.25f * min_e_input_available)
7633 * throughput_multiplier
7635 * min_input_available;
7637 float effective_production_scale = fac.get_production_scale();
7639 auto& inputs = fac_type.get_inputs();
7640 auto& e_inputs = fac_type.get_efficiency_inputs();
7649 * throughput_multiplier
7650 * effective_production_scale
7651 * (0.1f + min_input_available * 0.9f);
7653 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
7654 if(inputs.commodity_type[i]) {
7655 if(inputs.commodity_type[i] == c) {
7657 +input_scale * inputs.commodity_amounts[i];
7668 auto const mfactor = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_maintenance) + 1.0f;
7669 for(
uint32_t i = 0; i < small_commodity_set::set_size; ++i) {
7670 if(e_inputs.commodity_type[i]) {
7671 if(e_inputs.commodity_type[i] == c) {
7675 * e_inputs.commodity_amounts[i]
7676 * (0.1f + min_e_input_available * 0.9f);
7690 if(state.world.commodity_get_is_available_from_start(c) || state.world.nation_get_unlocked_commodities(n, c)) {
7691 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
7692 auto si = state.world.state_ownership_get_state(soid);
7693 auto m = state.world.state_instance_get_market_from_local_market(si);
7694 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
7696 state.world.pop_type_get_life_needs(pt, c)
7697 * state.world.market_get_life_needs_weights(m, c)
7698 + state.world.pop_type_get_everyday_needs(pt, c)
7699 * state.world.market_get_everyday_needs_weights(m, c)
7700 + state.world.pop_type_get_luxury_needs(pt, c)
7701 * state.world.market_get_luxury_needs_weights(m, c)
7705 / state.defines.alice_needs_scaling_factor;
7713 float t_total = 0.0f;
7715 auto const total_commodities = state.world.commodity_size();
7717 for(
uint32_t k = 1; k < total_commodities; ++k) {
7718 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
7719 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
7720 auto local_state = state.world.state_ownership_get_state(soid);
7721 auto market = state.world.state_instance_get_market_from_local_market(local_state);
7722 t_total +=
price(state, market, cid) * state.world.market_get_import(market, cid);
7730 float t_total = 0.0f;
7732 auto const total_commodities = state.world.commodity_size();
7734 for(
uint32_t k = 1; k < total_commodities; ++k) {
7735 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(k) };
7736 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
7737 auto local_state = state.world.state_ownership_get_state(soid);
7738 auto market = state.world.state_instance_get_market_from_local_market(local_state);
7739 t_total +=
price(state, market, cid) * state.world.market_get_export(market, cid);
7747 auto saved = state.world.pop_get_savings(p);
7753 auto strata =
culture::pop_strata(state.world.pop_type_get_strata(state.world.pop_get_poptype(p)));
7757 return saved / std::max(0.0001f, (1.0f - tax_eff *
float(state.world.nation_get_poor_tax(owner)) / 100.0f));
7759 return saved / std::max(0.0001f, (1.0f - tax_eff *
float(state.world.nation_get_middle_tax(owner)) / 100.0f));
7761 return saved / std::max(0.0001f, (1.0f - tax_eff *
float(state.world.nation_get_rich_tax(owner)) / 100.0f));
7766 auto current_volume = state.world.trade_route_get_volume(trade_route, cid);
7768 current_volume > 0.f
7769 ? state.world.trade_route_get_connected_markets(trade_route, 0)
7770 : state.world.trade_route_get_connected_markets(trade_route, 1);
7772 current_volume <= 0.f
7773 ? state.world.trade_route_get_connected_markets(trade_route, 0)
7774 : state.world.trade_route_get_connected_markets(trade_route, 1);
7776 auto s_origin = state.world.market_get_zone_from_local_market(origin);
7777 auto s_target = state.world.market_get_zone_from_local_market(target);
7778 auto n_origin = state.world.state_instance_get_nation_from_state_ownership(s_origin);
7779 auto n_target = state.world.state_instance_get_nation_from_state_ownership(s_target);
7780 bool same_nation = n_origin == n_target;
7781 auto capital_origin = state.world.state_instance_get_capital(s_origin);
7782 auto capital_target = state.world.state_instance_get_capital(s_target);
7785 auto controller_capital_origin = state.world.province_get_nation_from_province_control(capital_origin);
7786 auto controller_capital_target = state.world.province_get_nation_from_province_control(capital_target);
7787 auto controller_port_origin = state.world.province_get_nation_from_province_control(port_origin);
7788 auto controller_port_target = state.world.province_get_nation_from_province_control(port_target);
7789 auto sphere_origin = state.world.nation_get_in_sphere_of(controller_capital_origin);
7790 auto sphere_target = state.world.nation_get_in_sphere_of(controller_capital_target);
7792 auto overlord_origin = state.world.overlord_get_ruler(
7793 state.world.nation_get_overlord_as_subject(controller_capital_origin)
7795 auto overlord_target = state.world.overlord_get_ruler(
7796 state.world.nation_get_overlord_as_subject(controller_capital_target)
7802 auto origin_is_open_to_target = sphere_origin == controller_capital_target || overlord_origin == controller_capital_target;
7803 auto target_is_open_to_origin = sphere_target == controller_capital_origin || overlord_target == controller_capital_origin;
7806 state.world.market_get_direct_demand_satisfaction(origin, cid)
7807 * std::min(1.f, state.world.market_get_supply_sold_ratio(target, cid) + 100.f / (
price(state, origin, cid) +
price(state, target, cid)));
7808 auto absolute_volume = sat * std::abs(current_volume);
7809 auto distance = state.world.trade_route_get_distance(trade_route);
7811 auto trade_good_loss_mult = std::max(0.f, 1.f - 0.0001f * distance);
7812 auto import_amount = absolute_volume * trade_good_loss_mult;
7814 auto effect_of_scale = std::max(0.1f, 1.f - absolute_volume * 0.0005f);
7815 auto transport_cost = distance * 0.0075f * effect_of_scale;
7820 auto price_origin =
price(state, origin, cid);
7821 auto price_target =
price(state, target, cid);
7827 .origin_nation = n_origin,
7828 .target_nation = n_target,
7830 .amount_origin = absolute_volume,
7831 .amount_target = import_amount,
7833 .tariff_origin = 0.f,
7834 .tariff_target = 0.f,
7836 .tariff_rate_origin = 0.f,
7837 .tariff_rate_target = 0.f,
7839 .price_origin = price_origin,
7840 .price_target = price_target,
7842 .transport_cost = transport_cost,
7843 .transportaion_loss = trade_good_loss_mult,
7844 .distance = distance,
7853 .origin_nation = n_origin,
7854 .target_nation = n_target,
7856 .amount_origin = absolute_volume,
7857 .amount_target = import_amount,
7858 .tariff_origin = absolute_volume * price_origin * export_tariff,
7859 .tariff_target = import_amount * price_target * import_tariff,
7861 .tariff_rate_origin = export_tariff,
7862 .tariff_rate_target = import_tariff,
7864 .price_origin = price_origin,
7865 .price_target = price_target,
7867 .transport_cost = transport_cost,
7868 .transportaion_loss = trade_good_loss_mult,
7869 .distance = distance,
7871 .payment_per_unit = price_origin
7872 * (1.f + export_tariff)
7874 +
price(state, target, cid)
7884 std::vector<trade_breakdown_item> result;
7885 auto buffer_volume_per_nation = state.world.nation_make_vectorizable_float_buffer();
7886 auto buffer_tariff_per_nation = state.world.nation_make_vectorizable_float_buffer();
7888 state.world.for_each_commodity([&](dcon::commodity_id cid) {
7889 state.world.execute_serial_over_nation([&](
auto nids) {
7890 buffer_volume_per_nation.set(nids, 0.f);
7891 buffer_tariff_per_nation.set(nids, 0.f);
7894 state.world.nation_for_each_state_ownership(n, [&](
auto sid) {
7895 auto mid = state.world.state_instance_get_market_from_local_market(state.world.state_ownership_get_state(sid));
7896 state.world.market_for_each_trade_route(mid, [&](
auto trade_route) {
7897 trade_and_tariff route_data = explain_trade_route_commodity(state, trade_route, cid);
7900 if(route_data.origin == mid) {
7906 if(route_data.target == mid) {
7911 if(import_flag && route_data.target == mid) {
7912 buffer_volume_per_nation.get(route_data.origin_nation) += route_data.amount_target;
7913 buffer_tariff_per_nation.get(route_data.origin_nation) += route_data.tariff_target;
7916 if(export_flag && route_data.origin == mid) {
7917 buffer_volume_per_nation.get(route_data.target_nation) += route_data.amount_origin;
7918 buffer_tariff_per_nation.get(route_data.target_nation) += route_data.tariff_origin;
7923 state.world.for_each_nation([&](
auto nid) {
7924 trade_breakdown_item item = {
7925 .trade_partner = nid,
7927 .traded_amount = buffer_volume_per_nation.get(nid),
7928 .tariff = buffer_tariff_per_nation.get(nid)
7931 if(item.traded_amount == 0.f || item.tariff < 0.001f) {
7944 for(
auto poid : state.world.nation_get_province_ownership_as_nation(n)) {
7945 auto prov = poid.get_province();
7947 state.world.for_each_commodity([&](dcon::commodity_id c) {
7948 if(state.world.commodity_get_money_rgo(c)) {
7950 province::rgo_production_quantity(state, prov.id, c)
7951 * state.world.commodity_get_cost(c);
7955 return amount * state.defines.gold_to_cash_rate;
7960 state.world.for_each_commodity([&](dcon::commodity_id cid) {
7961 state.world.nation_for_each_state_ownership(n, [&](
auto sid) {
7962 auto mid = state.world.state_instance_get_market_from_local_market(state.world.state_ownership_get_state(sid));
7963 state.world.market_for_each_trade_route(mid, [&](
auto trade_route) {
7964 trade_and_tariff route_data = explain_trade_route_commodity(state, trade_route, cid);
7965 if(route_data.target == mid) {
7966 result += route_data.tariff_target;
7976 state.world.for_each_commodity([&](dcon::commodity_id cid) {
7977 state.world.nation_for_each_state_ownership(n, [&](
auto sid) {
7978 auto mid = state.world.state_instance_get_market_from_local_market(state.world.state_ownership_get_state(sid));
7979 state.world.market_for_each_trade_route(mid, [&](
auto trade_route) {
7980 trade_and_tariff route_data = explain_trade_route_commodity(state, trade_route, cid);
7981 if(route_data.origin == mid) {
7982 result += route_data.tariff_origin;
7992 auto const p_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::pension_level);
7993 auto const unemp_level = state.world.nation_get_modifier_values(n, sys::national_mod_offsets::unemployment_benefit);
7995 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
7996 auto local_state = state.world.state_ownership_get_state(soid);
7997 auto market = state.world.state_instance_get_market_from_local_market(local_state);
7998 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
7999 auto adj_pop_of_type =
8001 / state.defines.alice_needs_scaling_factor;
8002 if(adj_pop_of_type <= 0)
8009 total += adj_pop_of_type * p_level * state.world.market_get_life_needs_costs(market, pt);
8010 if(state.world.pop_type_get_has_unemployment(pt)) {
8011 auto emp = state.world.state_instance_get_demographics(local_state, demographics::to_employment_key(state, pt)) / state.defines.alice_needs_scaling_factor;
8013 (adj_pop_of_type - emp)
8015 * state.world.market_get_life_needs_costs(market, pt);
8025 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
8026 auto local_state = state.world.state_ownership_get_state(soid);
8027 auto market = state.world.state_instance_get_market_from_local_market(local_state);
8028 state.world.for_each_pop_type([&](dcon::pop_type_id pt) {
8029 auto adj_pop_of_type =
8030 state.world.state_instance_get_demographics(local_state,
demographics::to_key(state, pt)) / state.defines.alice_needs_scaling_factor;
8032 if(adj_pop_of_type <= 0)
8037 total += adj_pop_of_type * state.world.market_get_life_needs_costs(market, pt);
8042 total += adj_pop_of_type * state.world.market_get_everyday_needs_costs(market, pt);
8047 total += adj_pop_of_type * state.world.market_get_luxury_needs_costs(market, pt);
8068 return state.world.nation_get_subsidies_spending(n);
8074 for(
auto uni : state.world.nation_get_unilateral_relationship_as_target(n)) {
8075 if(uni.get_war_subsidies()) {
8083 for(
auto uni : state.world.nation_get_unilateral_relationship_as_target(n)) {
8084 if(uni.get_reparations() && state.current_date < uni.get_source().get_reparations_until()) {
8085 auto source = uni.get_source();
8087 auto total_tax_base = state.world.nation_get_total_rich_income(source) +
8088 state.world.nation_get_total_middle_income(source) +
8089 state.world.nation_get_total_poor_income(source);
8090 auto payout = total_tax_base * tax_eff * state.defines.reparations_tax_hit;
8100 for(
auto uni : state.world.nation_get_unilateral_relationship_as_source(n)) {
8101 if(uni.get_war_subsidies()) {
8111 if(state.current_date < state.world.nation_get_reparations_until(n)) {
8112 for(
auto uni : state.world.nation_get_unilateral_relationship_as_source(n)) {
8113 if(uni.get_reparations()) {
8115 auto total_tax_base = state.world.nation_get_total_rich_income(n) +
8116 state.world.nation_get_total_middle_income(n) +
8117 state.world.nation_get_total_poor_income(n);
8118 auto payout = total_tax_base * tax_eff * state.defines.reparations_tax_hit;
8130 return w_sub + w_reps + subject_payments;
8136 return w_sub + w_reps + subject_payments;
8142 return w_sub + w_reps + subject_payments;
8149 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
8150 auto local_state = state.world.state_ownership_get_state(soid);
8151 auto market = state.world.state_instance_get_market_from_local_market(local_state);
8152 auto adj_pop_of_type_capis = (state.world.state_instance_get_demographics(
8154 ) / state.defines.alice_needs_scaling_factor;
8155 auto adj_pop_of_type_arist = (state.world.state_instance_get_demographics(
8157 ) / state.defines.alice_needs_scaling_factor;
8159 state.world.market_get_life_needs_costs(market, state.culture_definitions.aristocrat)
8160 + state.world.market_get_everyday_needs_costs(market, state.culture_definitions.aristocrat)
8161 + state.world.market_get_luxury_needs_costs(market, state.culture_definitions.aristocrat);
8163 state.world.market_get_life_needs_costs(market, state.culture_definitions.capitalists)
8164 + state.world.market_get_everyday_needs_costs(market, state.culture_definitions.capitalists)
8165 + state.world.market_get_luxury_needs_costs(market, state.culture_definitions.capitalists);
8168 + state.defines.alice_domestic_investment_multiplier
8170 adj_pop_of_type_capis * capis_costs
8171 + adj_pop_of_type_arist * arist_costs
8179 uint32_t total_commodities = state.world.commodity_size();
8180 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
8181 auto local_state = state.world.state_ownership_get_state(soid);
8182 auto market = state.world.state_instance_get_market_from_local_market(local_state);
8183 for(
uint32_t i = 1; i < total_commodities; ++i) {
8184 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
8186 state.world.market_get_army_demand(market, cid)
8187 *
price(state, market, cid)
8188 * state.world.market_get_demand_satisfaction(market, cid);
8196 uint32_t total_commodities = state.world.commodity_size();
8197 state.world.nation_for_each_state_ownership(n, [&](
auto soid) {
8198 auto local_state = state.world.state_ownership_get_state(soid);
8199 auto market = state.world.state_instance_get_market_from_local_market(local_state);
8200 for(
uint32_t i = 1; i < total_commodities; ++i) {
8201 dcon::commodity_id cid{ dcon::commodity_id::value_base_t(i) };
8202 total += state.world.market_get_navy_demand(market, cid)
8203 *
price(state, market, cid)
8204 * state.world.market_get_demand_satisfaction(market, cid);
8213 auto target_m_costs = (target.get_total_rich_income() + target.get_total_middle_income() + target.get_total_poor_income()) * state.defines.warsubsidies_percent;
8214 auto source_m_costs = (source.get_total_rich_income() + source.get_total_middle_income() + source.get_total_poor_income()) * state.defines.warsubsidies_percent;
8215 return std::min(target_m_costs, source_m_costs);
8220 auto collected_tax = state.world.nation_get_total_poor_income(n) * tax_eff * float(state.world.nation_get_poor_tax(n)) / 100.0f +
8221 state.world.nation_get_total_middle_income(n) * tax_eff * float(state.world.nation_get_middle_tax(n)) / 100.0f +
8222 state.world.nation_get_total_rich_income(n) * tax_eff * float(state.world.nation_get_rich_tax(n)) / 100.0f;
8224 auto rel = state.world.nation_get_overlord_as_subject(n);
8225 auto overlord = state.world.overlord_get_ruler(rel);
8228 auto transferamt = collected_tax;
8230 if(state.world.nation_get_is_substate(n)) {
8231 transferamt *= state.defines.alice_substate_subject_money_transfer / 100.f;
8233 transferamt *= state.defines.alice_puppet_subject_money_transfer / 100.f;
8244 for(
auto n : state.world.in_nation) {
8245 auto rel = state.world.nation_get_overlord_as_subject(n);
8246 auto overlord = state.world.overlord_get_ruler(rel);
8250 auto const collected_tax = state.world.nation_get_total_poor_income(n) * tax_eff * float(state.world.nation_get_poor_tax(n)) / 100.0f +
8251 state.world.nation_get_total_middle_income(n) * tax_eff * float(state.world.nation_get_middle_tax(n)) / 100.0f +
8252 state.world.nation_get_total_rich_income(n) * tax_eff * float(state.world.nation_get_rich_tax(n)) / 100.0f;
8253 auto transferamt = collected_tax;
8255 if(state.world.nation_get_is_substate(n)) {
8256 transferamt *= state.defines.alice_substate_subject_money_transfer / 100.f;
8258 transferamt *= state.defines.alice_puppet_subject_money_transfer / 100.f;
8269 for(
auto pb_con : state.world.province_get_province_building_construction(p)) {
8270 if(pb_con.get_type() ==
uint8_t(t)) {
8271 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_get_nation_from_province_ownership(p));
8272 float admin_cost_factor = pb_con.get_is_pop_project() ? 1.0f : 2.0f - admin_eff;
8275 float purchased = 0.0f;
8276 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
8277 total += state.economy_definitions.building_definitions[int32_t(t)].cost.commodity_amounts[i] * admin_cost_factor;
8278 purchased += pb_con.get_purchased_goods().commodity_amounts[i];
8287 auto in_prov = state.world.factory_get_province_from_factory_location(f);
8288 auto in_state = state.world.province_get_state_membership(in_prov);
8289 auto fac_type = state.world.factory_get_building_type(f);
8291 for(
auto st_con : state.world.state_instance_get_state_building_construction(in_state)) {
8292 if(st_con.get_type() == fac_type) {
8293 float admin_eff = state.world.nation_get_administrative_efficiency(st_con.get_nation());
8294 float factory_mod = state.world.nation_get_modifier_values(st_con.get_nation(), sys::national_mod_offsets::factory_cost) + 1.0f;
8295 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));
8296 float admin_cost_factor = (st_con.get_is_pop_project() ? pop_factory_mod : (2.0f - admin_eff)) * factory_mod;
8300 float purchased = 0.0f;
8301 auto& goods = state.world.factory_type_get_construction_costs(fac_type);
8303 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
8304 total += goods.commodity_amounts[i] * admin_cost_factor;
8305 purchased += st_con.get_purchased_goods().commodity_amounts[i];
8316 auto d = state.world.state_instance_get_definition(s);
8317 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
8318 if(p.get_province().get_state_membership() == s) {
8319 for(
auto f : p.get_province().get_factory_location()) {
8320 if(f.get_factory().get_building_type() == ft)
8329 auto d = state.world.state_instance_get_definition(s);
8331 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
8332 if(p.get_province().get_state_membership() == s) {
8333 for(
auto f : p.get_province().get_factory_location()) {
8334 if(f.get_factory().get_building_type() == ft)
8339 for(
auto sc : state.world.state_instance_get_state_building_construction(s)) {
8340 if(sc.get_type() == ft)
8348 int32_t num_factories = 0;
8349 auto d = state.world.state_instance_get_definition(sid);
8350 for(
auto p : state.world.state_definition_get_abstract_state_membership(d))
8351 if(p.get_province().get_nation_from_province_ownership() == n)
8352 num_factories += int32_t(state.world.province_get_factory_location(p.get_province()).end() - state.world.province_get_factory_location(p.get_province()).begin());
8353 for(
auto p : state.world.state_instance_get_state_building_construction(sid))
8354 if(p.get_is_upgrade() ==
false)
8358 assert(num_factories <= int32_t(state.defines.factories_per_state));
8359 return num_factories;
8364 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_land_construction_get_nation(c));
8365 float admin_cost_factor = 2.0f - admin_eff;
8367 auto& goods = state.military_definitions.unit_base_definitions[state.world.province_land_construction_get_type(c)].build_cost;
8368 auto& cgoods = state.world.province_land_construction_get_purchased_goods(c);
8371 float purchased = 0.0f;
8373 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
8374 total += goods.commodity_amounts[i] * admin_cost_factor;
8375 purchased += cgoods.commodity_amounts[i];
8378 return total > 0.0f ? purchased / total : 0.0f;
8382 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_naval_construction_get_nation(c));
8383 float admin_cost_factor = 2.0f - admin_eff;
8385 auto& goods = state.military_definitions.unit_base_definitions[state.world.province_naval_construction_get_type(c)].build_cost;
8386 auto& cgoods = state.world.province_naval_construction_get_purchased_goods(c);
8389 float purchased = 0.0f;
8391 for(
uint32_t i = 0; i < commodity_set::set_size; ++i) {
8392 total += goods.commodity_amounts[i] * admin_cost_factor;
8393 purchased += cgoods.commodity_amounts[i];
8396 return total > 0.0f ? purchased / total : 0.0f;
8402 auto d = state.world.state_instance_get_definition(s);
8403 auto o = state.world.state_instance_get_nation_from_state_ownership(s);
8404 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
8405 if(p.get_province().get_nation_from_province_ownership() == o) {
8406 for(
auto f : p.get_province().get_factory_location()) {
8407 if(f.get_factory().get_building_type() == t) {
8408 auto factory_level = f.get_factory().get_level();
8409 auto new_factory_level = std::min(
float(std::numeric_limits<uint8_t>::max()),
float(factory_level) + 1.f);
8410 f.get_factory().get_level() =
uint8_t(new_factory_level);
8417 auto state_cap = state.world.state_instance_get_capital(s);
8418 auto new_fac = fatten(state.world, state.world.create_factory());
8419 new_fac.set_building_type(t);
8420 new_fac.set_level(
uint8_t(1));
8421 new_fac.set_production_scale(1.0f);
8423 state.world.try_create_factory_location(new_fac, state_cap);
8428 for(
auto c : state.world.in_province_land_construction) {
8429 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_land_construction_get_nation(c));
8430 float admin_cost_factor = 2.0f - admin_eff;
8432 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
8433 auto& current_purchased = c.get_purchased_goods();
8434 float construction_time = float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
8436 bool all_finished =
true;
8437 if(!(c.get_nation().get_is_player_controlled() && state.cheat_data.instant_army)) {
8438 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
8439 if(base_cost.commodity_type[j]) {
8440 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * admin_cost_factor) {
8441 all_finished =
false;
8450 auto pop_location = c.get_pop().get_province_from_pop_location();
8453 auto a = fatten(state.world, state.world.create_army());
8455 a.set_controller_from_army_control(c.get_nation());
8456 state.world.try_create_army_membership(new_reg, a);
8457 state.world.try_create_regiment_source(new_reg, c.get_pop());
8461 if(c.get_nation() == state.local_player_nation) {
8466 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
8471 state.world.delete_province_land_construction(c);
8476 auto rng = state.world.province_get_province_naval_construction(p);
8477 if(
rng.begin() !=
rng.end()) {
8478 auto c = *(rng.begin());
8480 float admin_eff = state.world.nation_get_administrative_efficiency(state.world.province_naval_construction_get_nation(c));
8481 float admin_cost_factor = 2.0f - admin_eff;
8483 auto& base_cost = state.military_definitions.unit_base_definitions[c.get_type()].build_cost;
8484 auto& current_purchased = c.get_purchased_goods();
8485 float construction_time = float(state.military_definitions.unit_base_definitions[c.get_type()].build_time);
8487 bool all_finished = true;
8488 if(!(c.get_nation().get_is_player_controlled() && state.cheat_data.instant_navy)) {
8489 for(uint32_t i = 0; i < commodity_set::set_size && all_finished; ++i) {
8490 if(base_cost.commodity_type[i]) {
8491 if(current_purchased.commodity_amounts[i] < base_cost.commodity_amounts[i] * admin_cost_factor) {
8492 all_finished = false;
8501 auto new_ship = military::create_new_ship(state, c.get_nation(), c.get_type());
8502 auto a = fatten(state.world, state.world.create_navy());
8503 a.set_controller_from_navy_control(c.get_nation());
8504 a.set_location_from_navy_location(p);
8505 state.world.try_create_navy_membership(new_ship, a);
8506 military::move_navy_to_merge(state, c.get_nation(), a, c.get_province(), c.get_template_province());
8508 if(c.get_nation() == state.local_player_nation) {
8509 notification::post(state, notification::message{ [](sys::state& state, text::layout_base& contents) {
8510 text::add_line(state, contents,
"amsg_navy_built");
8513 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
8514 sys::message_base_type::navy_built
8518 state.world.delete_province_naval_construction(c);
8523 for(
auto c :
state.world.in_province_building_construction) {
8524 auto for_province =
state.world.province_building_construction_get_province(c);
8526 float admin_eff =
state.world.nation_get_administrative_efficiency(
state.world.province_building_construction_get_nation(c));
8527 float admin_cost_factor =
state.world.province_building_construction_get_is_pop_project(c) ? 1.0f : 2.0f - admin_eff;
8530 auto& base_cost =
state.economy_definitions.building_definitions[int32_t(t)].cost;
8531 auto& current_purchased =
state.world.province_building_construction_get_purchased_goods(c);
8532 bool all_finished =
true;
8534 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
8535 if(base_cost.commodity_type[j]) {
8536 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * admin_cost_factor) {
8537 all_finished =
false;
8545 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))) {
8546 state.world.province_get_building_level(for_province,
uint8_t(t)) += 1;
8548 if(t == province_building_type::railroad) {
8550 state.railroad_built.store(
true, std::memory_order::release);
8553 if(
state.world.province_building_construction_get_nation(c) ==
state.local_player_nation) {
8555 case province_building_type::naval_base:
8559 "amsg_naval_base_complete",
8560 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
8564 case province_building_type::fort:
8568 "amsg_fort_complete",
8569 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
8573 case province_building_type::railroad:
8578 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
8587 state.world.delete_province_building_construction(c);
8591 for(
auto c :
state.world.in_state_building_construction) {
8592 auto n =
state.world.state_building_construction_get_nation(c);
8593 auto type =
state.world.state_building_construction_get_type(c);
8594 auto& base_cost =
state.world.factory_type_get_construction_costs(type);
8595 auto& current_purchased =
state.world.state_building_construction_get_purchased_goods(c);
8597 if(!
state.world.state_building_construction_get_is_pop_project(c)) {
8598 float admin_eff =
state.world.nation_get_administrative_efficiency(n);
8599 float admin_cost_factor = 2.0f - admin_eff;
8601 float factory_mod =
state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f;
8603 bool all_finished =
true;
8604 if(!(n ==
state.local_player_nation &&
state.cheat_data.instant_industry)) {
8605 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
8606 if(base_cost.commodity_type[j]) {
8607 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * factory_mod * admin_cost_factor) {
8608 all_finished =
false;
8617 state.world.state_building_construction_get_is_upgrade(c));
8618 state.world.delete_state_building_construction(c);
8621 float factory_mod = (
state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_cost) + 1.0f) *
8622 std::max(0.1f,
state.world.nation_get_modifier_values(n, sys::national_mod_offsets::factory_owner_cost));
8624 bool all_finished =
true;
8625 if(!(n ==
state.local_player_nation &&
state.cheat_data.instant_industry)) {
8626 for(
uint32_t j = 0; j < commodity_set::set_size && all_finished; ++j) {
8627 if(base_cost.commodity_type[j]) {
8628 if(current_purchased.commodity_amounts[j] < base_cost.commodity_amounts[j] * factory_mod) {
8629 all_finished =
false;
8638 state.world.state_building_construction_get_is_upgrade(c));
8640 if(
state.world.state_building_construction_get_nation(c) ==
state.local_player_nation) {
8644 "amsg_factory_complete",
8645 state.local_player_nation, dcon::nation_id{}, dcon::nation_id{},
8650 state.world.delete_state_building_construction(c);
8663 state.world.nation_get_total_poor_income(n) * state.world.nation_get_poor_tax(n) / 100.f
8664 + state.world.nation_get_total_middle_income(n) * state.world.nation_get_middle_tax(n) / 100.f
8665 + state.world.nation_get_total_rich_income(n) * state.world.nation_get_rich_tax(n) / 100.f
8670 auto n = state.world.state_instance_get_nation_from_state_ownership(s);
8672 if(state.world.factory_type_get_is_coastal(t)) {
8677 auto existing_constructions = state.world.state_instance_get_state_building_construction(s);
8678 int32_t num_factories = 0;
8679 for(
auto prj : existing_constructions) {
8680 if(!prj.get_is_upgrade())
8682 if(prj.get_type() == t)
8687 auto d = state.world.state_instance_get_definition(s);
8688 for(
auto p : state.world.state_definition_get_abstract_state_membership(d)) {
8689 if(p.get_province().get_nation_from_province_ownership() == n) {
8690 for(
auto f : p.get_province().get_factory_location()) {
8692 if(f.get_factory().get_building_type() == t)
8698 if(num_factories < int32_t(state.defines.factories_per_state)) {
8705 result.education_spending = 0;
8706 result.military_spending = 0;
8707 result.administrative_spending = 0;
8708 result.social_spending = 0;
8709 result.land_spending = 0;
8710 result.naval_spending = 0;
8711 result.construction_spending = 0;
8712 result.poor_tax = 0;
8713 result.middle_tax = 0;
8714 result.rich_tax = 0;
8715 result.tariffs_import = 0;
8716 result.tariffs_export = 0;
8717 result.domestic_investment = 0;
8718 result.overseas = 0;
8721 auto min_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tariff));
8722 result.tariffs_import = int8_t(std::clamp(min_tariff, 0, 100));
8723 result.tariffs_export = int8_t(std::clamp(min_tariff, 0, 100));
8726 auto min_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tax));
8727 result.poor_tax = int8_t(std::clamp(min_tax, 0, 100));
8728 result.middle_tax = int8_t(std::clamp(min_tax, 0, 100));
8729 result.rich_tax = int8_t(std::clamp(min_tax, 0, 100));
8732 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_military_spending));
8733 result.military_spending = int8_t(std::clamp(min_spend, 0, 100));
8736 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_social_spending));
8737 result.social_spending = int8_t(std::clamp(min_spend, 0, 100));
8740 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_domestic_investment));
8741 result.domestic_investment = int8_t(std::clamp(min_spend, 0, 100));
8747 result.education_spending = 100;
8748 result.military_spending = 100;
8749 result.administrative_spending = 100;
8750 result.social_spending = 100;
8751 result.land_spending = 100;
8752 result.naval_spending = 100;
8753 result.construction_spending = 100;
8754 result.poor_tax = 100;
8755 result.middle_tax = 100;
8756 result.rich_tax = 100;
8757 result.tariffs_import = 100;
8758 result.tariffs_export = 100;
8759 result.domestic_investment = 100;
8760 result.overseas = 100;
8763 auto min_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tariff));
8764 auto max_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_tariff));
8765 max_tariff = std::max(min_tariff, max_tariff);
8767 result.tariffs_import = int8_t(std::clamp(max_tariff, 0, 100));
8768 result.tariffs_export = int8_t(std::clamp(max_tariff, 0, 100));
8771 auto min_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tax));
8772 auto max_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_tax));
8775 max_tax = std::max(min_tax, max_tax);
8777 result.poor_tax = int8_t(std::clamp(max_tax, 0, 100));
8778 result.middle_tax = int8_t(std::clamp(max_tax, 0, 100));
8779 result.rich_tax = int8_t(std::clamp(max_tax, 0, 100));
8783 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_military_spending));
8785 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_military_spending));
8788 max_spend = std::max(min_spend, max_spend);
8790 result.military_spending = int8_t(std::clamp(max_spend, 0, 100));
8793 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_social_spending));
8794 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_social_spending));
8797 max_spend = std::max(min_spend, max_spend);
8799 result.social_spending = int8_t(std::clamp(max_spend, 0, 100));
8802 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_domestic_investment));
8803 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_domestic_investment));
8806 max_spend = std::max(min_spend, max_spend);
8808 result.domestic_investment = int8_t(std::clamp(max_spend, 0, 100));
8814 auto min_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tariff));
8815 auto max_tariff = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_tariff));
8816 max_tariff = std::max(min_tariff, max_tariff);
8819 auto& tariff = state.world.nation_get_tariffs_import(n);
8820 tariff = int8_t(std::clamp(std::clamp(int32_t(tariff), min_tariff, max_tariff), 0, 100));
8824 auto& tariff = state.world.nation_get_tariffs_export(n);
8825 tariff = int8_t(std::clamp(std::clamp(int32_t(tariff), min_tariff, max_tariff), 0, 100));
8829 auto min_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_tax));
8830 auto max_tax = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_tax));
8833 max_tax = std::max(min_tax, max_tax);
8835 auto& ptax = state.world.nation_get_poor_tax(n);
8836 ptax = int8_t(std::clamp(std::clamp(int32_t(ptax), min_tax, max_tax), 0, 100));
8837 auto& mtax = state.world.nation_get_middle_tax(n);
8838 mtax = int8_t(std::clamp(std::clamp(int32_t(mtax), min_tax, max_tax), 0, 100));
8839 auto& rtax = state.world.nation_get_rich_tax(n);
8840 rtax = int8_t(std::clamp(std::clamp(int32_t(rtax), min_tax, max_tax), 0, 100));
8844 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_military_spending));
8846 int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_military_spending));
8849 max_spend = std::max(min_spend, max_spend);
8851 auto& v = state.world.nation_get_military_spending(n);
8852 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
8855 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_social_spending));
8856 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_social_spending));
8859 max_spend = std::max(min_spend, max_spend);
8861 auto& v = state.world.nation_get_social_spending(n);
8862 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
8865 auto min_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::min_domestic_investment));
8866 auto max_spend = int32_t(100.0f * state.world.nation_get_modifier_values(n, sys::national_mod_offsets::max_domestic_investment));
8869 max_spend = std::max(min_spend, max_spend);
8871 auto& v = state.world.nation_get_domestic_investment_spending(n);
8872 v = int8_t(std::clamp(std::clamp(int32_t(v), min_spend, max_spend), 0, 100));
8877 for(
auto si : state.world.in_state_instance) {
8878 auto owner = si.get_nation_from_state_ownership();
8879 auto rules = owner.get_combined_issue_rules();
8884 dcon::factory_id deletion_choice;
8885 int32_t factory_count = 0;
8888 for(
auto f : state.world.province_get_factory_location(p)) {
8890 auto scale = f.get_factory().get_production_scale();
8891 float ten_workers = 10.f / factory_max_employment(state, f.get_factory());
8892 bool unprofitable = f.get_factory().get_unprofitable();
8893 if(((scale < ten_workers) && unprofitable) && (!deletion_choice || state.world.factory_get_level(deletion_choice) > f.get_factory().get_level())) {
8894 deletion_choice = f.get_factory();
8901 if(deletion_choice && (4 + factory_count) >= int32_t(state.defines.factories_per_state)) {
8902 auto production_type = state.world.factory_get_building_type(deletion_choice);
8903 state.world.delete_factory(deletion_choice);
8905 for(
auto proj : si.get_state_building_construction()) {
8906 if(proj.get_type() == production_type) {
8907 state.world.delete_state_building_construction(proj);
8916 return state.economy_definitions.selector_modifier;
8920 return state.economy_definitions.immigrator_modifier;
8924 auto& debt = state.world.nation_get_local_loan(n);
8929 auto existing_br = state.world.nation_get_bankrupt_until(n);
8930 if(existing_br && state.current_date < existing_br) {
8931 for(
auto gn : state.great_nations) {
8932 if(gn.nation && gn.nation != n) {
8936 }
else if(debt >= -state.defines.small_debt_limit) {
8937 for(
auto gn : state.great_nations) {
8938 if(gn.nation && gn.nation != n) {
8943 for(
auto gn : state.great_nations) {
8944 if(gn.nation && gn.nation != n) {
8953 sys::add_modifier_to_nation(state, n, state.national_definitions.in_bankrupcy, state.current_date + int32_t(state.defines.bankrupcy_duration * 365));
8954 sys::add_modifier_to_nation(state, n, state.national_definitions.bad_debter, state.current_date + int32_t(state.defines.bankruptcy_external_loan_years * 365));
8957 state.world.nation_set_is_debt_spending(n,
false);
8958 state.world.nation_set_bankrupt_until(n, state.current_date + int32_t(state.defines.bankrupcy_duration * 365));
8964 "msg_bankruptcy_title",
8965 n, dcon::nation_id{}, dcon::nation_id{},
8971 return state.world.nation_get_private_investment(n) * 0.001f;
#define assert(condition)
void get_craved_factory_types(sys::state &state, dcon::nation_id nid, dcon::market_id mid, std::vector< dcon::factory_type_id > &desired_types)
void get_desired_factory_types(sys::state &state, dcon::nation_id nid, dcon::market_id mid, std::vector< dcon::factory_type_id > &desired_types)
void update_budget(sys::state &state)
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)
@ key
the parser read a key of a value in an object
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)
void initialize(sys::state &state)
bool valid_artisan_good(sys::state &state, dcon::nation_id nations, dcon::commodity_id cid)
float global_market_commodity_daily_increase(sys::state &state, dcon::commodity_id c)
float factory_input_total_cost(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
float factory_throughput_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s)
float estimate_war_subsidies(sys::state &state, dcon::nation_fat_id target, dcon::nation_fat_id source)
float factory_max_production_scale(sys::state const &state, dcon::factory_id fac, float mobilization_impact, bool occupied)
void update_pop_consumption(sys::state &state, ve::vectorizable_buffer< float, dcon::nation_id > &invention_count)
dcon::modifier_id get_province_immigrator_modifier(sys::state &state)
constexpr float subsistence_score_life
float factory_min_e_input_available(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
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
constexpr auto utility_decay_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)
trade_and_tariff explain_trade_route_commodity(sys::state &state, dcon::trade_route_id trade_route, dcon::commodity_id cid)
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)
float estimate_subject_payments_paid(sys::state &state, dcon::nation_id n)
std::vector< full_construction_state > estimate_private_investment_upgrade(sys::state &state, dcon::nation_id nid)
construction_status province_building_construction(sys::state &state, dcon::province_id p, province_building_type t)
void update_artisan_consumption(sys::state &state, T markets, S nations, U states, ve::fp_vector expected_min_wage, ve::fp_vector mobilization_impact)
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)
float factory_e_input_total_cost(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
float consumption(sys::state &state, dcon::market_id s, dcon::commodity_id c)
float factory_desired_raw_profit(dcon::factory_id fac, float spendings)
bool state_contains_constructed_factory(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id ft)
constexpr auto mid_term_profits_weight_p
float estimate_construction_spending_from_budget(sys::state &state, dcon::nation_id n, float current_budget)
float factory_output_multiplier_no_secondary_workers(sys::state const &state, dcon::factory_id fac, dcon::nation_id n, dcon::province_id p)
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)
constexpr auto current_profits_weight_n
constexpr float merchant_cut_foreign
bool is_bankrupt_debtor_to(sys::state &state, dcon::nation_id debt_holder, dcon::nation_id debtor)
float factory_max_production_scale_non_modified(sys::state const &state, dcon::factory_fat_id fac)
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)
float estimate_diplomatic_expenses(sys::state &state, dcon::nation_id n)
constexpr float diff_non_factory
float estimate_diplomatic_balance(sys::state &state, dcon::nation_id n)
void prune_factories(sys::state &state)
ve::fp_vector ve_adjusted_subsistence_score(sys::state &state, T p)
constexpr auto current_profits_weight_trade
float supply(sys::state &state, dcon::market_id s, dcon::commodity_id c)
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)
void adjust_artisan_balance(sys::state &state, T markets, S nations)
float need_weight(sys::state &state, dcon::market_id n, dcon::commodity_id c)
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)
constexpr float artisans_greed
void run_private_investment(sys::state &state)
float factory_min_input_available(sys::state const &state, dcon::market_id m, dcon::factory_type_id fac_type)
float farmer_min_wage(sys::state &state, dcon::market_id m, float min_wage_factor)
float factory_input_multiplier(sys::state const &state, dcon::factory_id fac, dcon::nation_id n, dcon::province_id p, dcon::state_instance_id s)
void initialize_needs_weights(sys::state &state, dcon::market_id n)
float estimate_overseas_penalty_spending(sys::state &state, dcon::nation_id n)
constexpr auto short_term_profits_weight_trade
float nation_factory_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
constexpr float shift_factory
float nation_total_exports(sys::state &state, dcon::nation_id n)
trade_volume_data_detailed import_volume_detailed(sys::state &state, dcon::nation_id s, dcon::commodity_id c)
constexpr float stockpile_to_supply
profit_distribution distribute_factory_profit(sys::state const &state, dcon::state_instance_const_fat_id s, float total_profit)
bool has_factory(sys::state const &state, dcon::state_instance_id si)
auto artisan_throughput_multiplier(sys::state &state, T nations)
float max_loan(sys::state &state, dcon::nation_id n)
trade_volume_data_detailed export_volume_detailed(sys::state &state, dcon::nation_id s, dcon::commodity_id c)
float estimate_construction_spending(sys::state &state, dcon::nation_id n)
float estimate_private_construction_spendings(sys::state &state, dcon::nation_id nid)
float estimate_war_subsidies_income(sys::state &state, dcon::nation_id n)
constexpr auto mid_term_profits_weight_n
construction_status factory_upgrade(sys::state &state, dcon::factory_id f)
void presimulate(sys::state &state)
constexpr auto long_term_profits_weight_trade
constexpr float price_rigging
constexpr auto long_term_profits_weight_n
void update_rgo_employment(sys::state &state)
bool valid_life_need(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
ve::fp_vector ve_pseudo_exp_for_negative(ve::fp_vector f)
void register_intermediate_demand(sys::state &state, T s, dcon::commodity_id c, ve::fp_vector amount, economy_reason reason)
float expected_savings_per_capita(sys::state &state)
void daily_update(sys::state &state, bool presimulation, float presimulation_stage)
float full_spending_cost(sys::state &state, dcon::nation_id n)
float estimate_land_spending(sys::state &state, dcon::nation_id n)
ve::fp_vector ve_laborer_min_wage(sys::state &state, T markets, ve::fp_vector min_wage_factor)
constexpr float day_1_build_time_modifier_factory
float rgo_total_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
constexpr float merchant_cut_domestic
command::budget_settings_data budget_minimums(sys::state &state, dcon::nation_id n)
float estimate_daily_income(sys::state &state, dcon::nation_id n)
auto artisan_input_multiplier(sys::state &state, T nations)
float price(sys::state const &state, dcon::state_instance_id s, dcon::commodity_id c)
float estimate_tariff_import_income(sys::state &state, dcon::nation_id n)
constexpr uint32_t price_history_length
float rgo_total_max_employment(sys::state &state, dcon::nation_id n, dcon::province_id p)
void regenerate_unsaved_values(sys::state &state)
constexpr dcon::commodity_id money(0)
void update_land_ownership(sys::state &state)
float domestic_trade_volume(sys::state &state, dcon::nation_id s, dcon::commodity_id c)
float laborer_min_wage(sys::state &state, dcon::market_id m, float min_wage_factor)
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)
ve::mask_vector ve_valid_artisan_good(sys::state &state, T nations, dcon::commodity_id cid)
float unit_construction_progress(sys::state &state, dcon::province_land_construction_id c)
constexpr float stockpile_expected_spending_per_commodity
constexpr float factory_closed_threshold
float estimate_investment_pool_daily_loss(sys::state &state, dcon::nation_id n)
int32_t most_recent_price_record_index(sys::state &state)
float factory_type_build_cost(sys::state &state, dcon::nation_id n, dcon::market_id m, dcon::factory_type_id factory_type)
std::vector< trade_breakdown_item > explain_national_tariff(sys::state &state, dcon::nation_id n, bool import_flag, bool export_flag)
float rgo_expected_worker_norm_profit(sys::state &state, dcon::province_id p, dcon::market_id m, dcon::nation_id n, dcon::commodity_id c)
float import_volume(sys::state &state, dcon::market_id s, dcon::commodity_id c)
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)
void register_construction_demand(sys::state &state, dcon::market_id s, dcon::commodity_id commodity_type, float amount)
ve::fp_vector ve_pop_min_wage_factor(sys::state &state, T n)
void sanity_check(sys::state &state)
float rgo_effective_size(sys::state const &state, dcon::nation_id n, dcon::province_id p, dcon::commodity_id c)
float estimate_diplomatic_income(sys::state &state, dcon::nation_id n)
constexpr float payouts_spending_multiplier
float estimate_subject_payments_received(sys::state &state, dcon::nation_id o)
void update_single_factory_production(sys::state &state, dcon::factory_id f, dcon::market_id m, dcon::nation_id n)
float nation_factory_output_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n)
float ideal_pound_conversion_rate(sys::state &state, dcon::market_id n)
void register_foreign_supply(sys::state &state, dcon::market_id s, dcon::commodity_id commodity_type, float amount, economy_reason reason)
float subsistence_size(sys::state const &state, dcon::province_id p)
constexpr float primary_greed
float effective_tariff_import_rate(sys::state &state, dcon::nation_id n)
float estimate_war_subsidies_spending(sys::state &state, dcon::nation_id n)
float demand_satisfaction(sys::state &state, dcon::market_id s, dcon::commodity_id c)
float commodity_daily_production_amount(sys::state &state, dcon::commodity_id c)
float global_non_factory_construction_time_modifier(sys::state &state)
float rgo_desired_worker_norm_profit(sys::state &state, dcon::province_id p, dcon::market_id m, dcon::nation_id n, float min_wage, float total_relevant_population)
constexpr float subsistence_factor
bool factory_is_profitable(sys::state const &state, dcon::factory_id f)
float convex_function(float x)
bool valid_luxury_need(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
std::vector< full_construction_state > estimate_private_investment_construct(sys::state &state, dcon::nation_id nid, bool craved)
float estimate_reparations_spending(sys::state &state, dcon::nation_id n)
constexpr auto current_profits_weight_p
float nation_factory_input_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n)
constexpr auto short_term_profits_weight_n
int32_t most_recent_gdp_record_index(sys::state &state)
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)
void for_each_upgraded_factory(sys::state &state, dcon::state_instance_id s, F &&func)
void update_province_rgo_employment(sys::state &state, dcon::province_id p, dcon::market_id m, dcon::nation_id n, float mobilization_impact, float expected_min_wage)
void go_bankrupt(sys::state &state, dcon::nation_id n)
void bound_budget_settings(sys::state &state, dcon::nation_id n)
constexpr float slope_non_factory
float average_capitalists_luxury_cost(sys::state &state, dcon::nation_id s)
float adjusted_subsistence_score(sys::state &state, dcon::province_id p)
void update_province_rgo_production(sys::state &state, dcon::province_id p, dcon::market_id m, dcon::nation_id n)
constexpr auto utility_decay_trade
float factory_secondary_employment(sys::state const &state, dcon::factory_id f)
constexpr float production_throughput_multiplier
float market_pool(sys::state &state, dcon::market_id s, dcon::commodity_id c)
ve::fp_vector ve_artisan_min_wage(sys::state &state, T markets)
void rebalance_needs_weights(sys::state &state, dcon::market_id n)
constexpr float shift_non_factory
float pop_min_wage_factor(sys::state &state, dcon::nation_id n)
void resolve_constructions(sys::state &state)
float priority_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n)
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 factory_total_employment(sys::state const &state, dcon::factory_id f)
float export_volume(sys::state &state, dcon::market_id s, dcon::commodity_id c)
float estimate_stockpile_filling_spending(sys::state &state, dcon::nation_id n)
ve::fp_vector skilled_labor_supply_multiplier(sys::state &state, T markets)
float stockpile_commodity_daily_increase(sys::state &state, dcon::commodity_id c, dcon::nation_id n)
float estimate_tariff_export_income(sys::state &state, dcon::nation_id n)
void populate_army_consumption(sys::state &state)
void add_factory_level_to_state(sys::state &state, dcon::state_instance_id s, dcon::factory_type_id t, bool is_upgrade)
constexpr auto utility_decay_p
constexpr float secondary_greed
constexpr float secondary_employment_output_bonus
constexpr float price_speed_mod
void emulate_construction_demand(sys::state &state, dcon::nation_id n)
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 demand(sys::state &state, dcon::market_id s, 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)
ve::fp_vector ve_farmer_min_wage(sys::state &state, T markets, ve::fp_vector min_wage_factor)
std::vector< dcon::factory_type_id > commodity_get_factory_types_as_output(sys::state const &state, dcon::commodity_id output_good)
constexpr auto mid_term_profits_weight_trade
constexpr auto short_term_profits_weight_p
void initialize_artisan_distribution(sys::state &state)
bool valid_need(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
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 update_market_artisan_production(sys::state &state, T markets)
bool nation_has_closed_factories(sys::state &state, dcon::nation_id n)
void update_single_factory_consumption(sys::state &state, dcon::factory_id f, dcon::province_id p, dcon::state_instance_id s, dcon::market_id m, dcon::nation_id n, float mobilization_impact, bool occupied)
auto artisan_output_multiplier(sys::state &state, T nations)
float gdp_adjusted(sys::state &state, dcon::market_id n)
float nation_pop_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
float effective_tariff_export_rate(sys::state &state, dcon::nation_id n)
void register_demand(sys::state &state, dcon::market_id s, dcon::commodity_id commodity_type, float amount, economy_reason reason)
std::vector< full_construction_province > estimate_private_investment_province(sys::state &state, dcon::nation_id nid)
bool valid_everyday_need(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
int32_t previous_gdp_record_index(sys::state &state)
constexpr float subsistence_score_everyday
constexpr float day_1_derivative_non_factory
constexpr auto long_term_profits_weight_p
void register_domestic_supply(sys::state &state, dcon::market_id s, dcon::commodity_id commodity_type, float amount, economy_reason reason)
ve::fp_vector unskilled_labor_supply_multiplier(sys::state &state, T markets)
ve::fp_vector base_artisan_profit(sys::state &state, T markets, S nations, dcon::commodity_id c)
ve::fp_vector ve_price(sys::state const &state, T s, dcon::commodity_id c)
float estimate_gold_income(sys::state &state, dcon::nation_id n)
command::budget_settings_data budget_maximums(sys::state &state, dcon::nation_id n)
float factory_output_multiplier(sys::state const &state, dcon::factory_id fac, dcon::nation_id n, dcon::market_id m, dcon::province_id p)
constexpr float aristocrats_greed
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 unit_calculate_reinforcement(sys::state &state, dcon::regiment_id reg_id)
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)
ve::fp_vector ve_mobilization_impact(sys::state const &state, ve::tagged_vector< dcon::nation_id > nations)
dcon::regiment_id create_new_regiment(sys::state &state, dcon::nation_id n, dcon::unit_type_id t)
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
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)
std::vector< dcon::nation_id > nation_get_subjects(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)
void set_luxury_needs(sys::state &state, P p, V v)
void set_everyday_needs(sys::state &state, P p, V v)
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)
float get_life_needs(sys::state const &state, dcon::pop_id p)
void set_life_needs(sys::state &state, P p, V v)
float get_everyday_needs(sys::state const &state, dcon::pop_id p)
dcon::province_id state_get_coastal_capital(sys::state &state, dcon::state_instance_id s)
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)
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
Holds important data about the game world, state, and other data regarding windowing,...