Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/localisation/en-US/alice.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,8 @@ player_loaded_status;Ready
player_loading_status;Loading
player_oos_status;OOS
rgo_bank;RGO balance ?Y$val$?W
artisan_bank;Guilds balance ?Y$val$?W
artisan_profit;Guilds profit ?Y$val$?W
rgo_bank_in;RGOs from production ?Y$val$?W
rgo_bank_out;RGOs to pops ?Y$val$?W
factory_bank;Factories balance ?Y$val$?W
Expand Down
10 changes: 8 additions & 2 deletions src/economy/advanced_province_buildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ void update_consumption(sys::state& state) {

auto demand_scale = 0.f;

auto budget = std::max(0.f, state.world.province_get_advanced_province_building_private_savings(pid, id));
auto max_demand_scale = budget / material_cost_per_constructed_unit;

if((expected_profit_per_size - expected_maintenance > 0) && expected_days_to_payoff > 0.f && expected_days_to_payoff < 365.f * 5.f && !lots_of_empty_housing) {
/*
If new housing could pay off in a few months, we construct it as fast as possible.
Expand All @@ -221,7 +224,7 @@ void update_consumption(sys::state& state) {
We don't want to expand faster than local labor allows us
*/
auto sat = state.world.province_get_labor_demand_satisfaction(pid, economy::labor_constants::construction_labor);
demand_scale = demand_scale * sat;
demand_scale = std::min(max_demand_scale, demand_scale * sat);

/*
Register demand both on construction materials and construction labor
Expand Down Expand Up @@ -424,6 +427,9 @@ void update_profit_and_refund(sys::state& state) {

auto construction_scale = 0.f;

auto budget = std::max(0.f, state.world.province_get_advanced_province_building_private_savings(pid, id));
auto max_demand_scale = budget / material_cost_per_constructed_unit;

if((expected_profit_per_size - expected_maintenance > 0.f) && expected_days_to_payoff > 0.f && expected_days_to_payoff < 365.f * 5.f && !lots_of_empty_housing) {
/*
If new housing could pay off in a few months, we construct it as fast as possible.
Expand All @@ -437,7 +443,7 @@ void update_profit_and_refund(sys::state& state) {
*/

auto labor_sat = state.world.province_get_labor_demand_satisfaction(pid, economy::labor_constants::construction_labor);
auto demand_scale = construction_scale * labor_sat;
auto demand_scale = std::min(max_demand_scale, construction_scale * labor_sat);

/*
Find out how much we were able to buy.
Expand Down
51 changes: 15 additions & 36 deletions src/economy/economy_pops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,49 +722,16 @@ void update_income_artisans(sys::state& state) {


float estimate_trade_income(sys::state const& state, dcon::market_id mid, dcon::pop_type_id ptid, float size) {
auto const artisan_def = state.culture_definitions.artisans;
auto artisan_key = demographics::to_key(state, artisan_def);
auto const clerks_def = state.culture_definitions.secondary_factory_worker;
auto clerks_key = demographics::to_key(state, clerks_def);
auto const capis_def = state.culture_definitions.capitalists;
auto capis_key = demographics::to_key(state, capis_def);
auto sids = state.world.market_get_zone_from_local_market(mid);
auto artisans = state.world.state_instance_get_demographics(sids, artisan_key);
auto clerks = state.world.state_instance_get_demographics(sids, clerks_key);
auto capis = state.world.state_instance_get_demographics(sids, capis_key);
auto total = state.world.state_instance_get_demographics(sids, demographics::total);
auto artisans_weight = state.world.state_instance_get_demographics(sids, artisan_key);
auto clerks_weight = state.world.state_instance_get_demographics(sids, clerks_key) * 100.f;
auto capis_weight = state.world.state_instance_get_demographics(sids, capis_key) * 100'000.f;
auto base_weight = total;
auto total_weight = artisans_weight + clerks_weight + capis_weight + base_weight;

if(total_weight == 0.f) {
if(total == 0.f) {
return 0.f;
}

auto balance = state.world.market_get_stockpile(mid, economy::money);
auto trade_dividents = balance > 0.f ? balance * trade_dividents_rate : 0.f;

auto artisans_share = artisans_weight / total_weight * trade_dividents;
auto clerks_share = clerks_weight / total_weight * trade_dividents;
auto capis_share = capis_weight / total_weight * trade_dividents;
auto other_share = base_weight / total_weight * trade_dividents;

auto per_artisan = artisans > 0.f ? artisans_share / artisans : 0.f;
auto per_clerk = clerks > 0.f ? clerks_share / clerks : 0.f;
auto per_capi = capis > 0.f ? capis_share / capis : 0.f;
auto per_person = total > 0.f ? other_share / total : 0.f;

if(artisan_def == ptid) {
return state.inflation * size * (per_artisan + per_person);
} else if(clerks_def == ptid) {
return state.inflation * size * (per_clerk + per_person);
} else if(capis_def == ptid) {
return state.inflation * size * (per_capi + per_person);
}

return state.inflation * size * per_person;
return size / total * trade_dividents;
}

float estimate_trade_income(sys::state const& state, dcon::pop_id pop) {
Expand Down Expand Up @@ -1042,12 +1009,20 @@ void update_income_non_labor(sys::state& state) {

auto valid_market = market != dcon::market_id{ };

#ifndef NDEBUG
ve::fp_vector from_rgo = 0.f;
ve::fp_vector from_rent = 0.f;
ve::fp_vector from_market = 0.f;
ve::fp_vector from_factories = 0.f;
#endif // !NDEBUG

{
auto candidates = ve::select(valid_market, market_rent_tokens.get(market), 0.f);
auto total_money = ve::select(valid_market, market_rent_money.get(market), 0.f);
auto income = ve::select((pop_type == aristo_def || pop_type == capis_def) && candidates > min_registered_token_size, total_money / candidates * size, 0.f);
#ifndef NDEBUG
ve::apply([](float v) { assert(std::isfinite(v) && v >= 0); }, income);
from_rent = income * expected_share;
#endif // !NDEBUG
total_income = total_income + income;
}
Expand All @@ -1058,6 +1033,7 @@ void update_income_non_labor(sys::state& state) {
auto income = ve::select(candidates > min_registered_token_size, total_money / candidates * size, 0.f);
#ifndef NDEBUG
ve::apply([](float v) { assert(std::isfinite(v) && v >= 0); }, income);
from_market = income * expected_share;
#endif // !NDEBUG

total_income = total_income + income;
Expand All @@ -1073,6 +1049,7 @@ void update_income_non_labor(sys::state& state) {
auto income = ve::select(candidates > min_registered_token_size, total_money / candidates * size * weight, 0.f);
#ifndef NDEBUG
ve::apply([](float v) { assert(std::isfinite(v) && v >= 0); }, income);
from_rgo = income * expected_share;
#endif // !NDEBUG

total_income = total_income + income;
Expand All @@ -1084,13 +1061,15 @@ void update_income_non_labor(sys::state& state) {
auto income = ve::select((pop_type == capis_def) && candidates > min_registered_token_size && size > 0.f, total_money / candidates * size, 0.f);
#ifndef NDEBUG
ve::apply([](float v) { assert(std::isfinite(v) && v >= 0); }, income);
from_factories = income * expected_share;
#endif // !NDEBUG
total_income = total_income + income;
}

auto initial_savings = state.world.pop_get_savings(pop_vector);
#ifndef NDEBUG
ve::apply([](float v) { assert(std::isfinite(v) && v >= 0); }, total_income);
auto total = from_rgo + from_rent + from_market + from_factories;
#endif // !NDEBUG
state.world.pop_set_savings(pop_vector, initial_savings + total_income * expected_share);
});
Expand Down Expand Up @@ -1644,7 +1623,7 @@ float estimate_trade_spending(
sys::state const& state,
dcon::pop_id pop
) {
auto next_day = estimate_next_day_budget_before_taxes(state, pop);
auto next_day = state.world.pop_get_savings(pop);
return market_tax * next_day;
}

Expand Down
22 changes: 22 additions & 0 deletions src/economy/economy_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,28 @@ void make_trade_center_tooltip(sys::state& state, text::columnar_layout& content
15
);

text::add_line_break_to_layout(state, contents);
text::add_line(
state,
contents,
"artisan_bank",
text::variable_type::val,
text::fp_currency{
state.world.province_get_artisan_bank(province)
},
0
);
text::add_line(
state,
contents,
"artisan_profit",
text::variable_type::val,
text::fp_currency{
state.world.province_get_artisan_profit(province)
},
15
);

text::add_line_break_to_layout(state, contents);
text::add_line(
state,
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@
LUA_DEFINES_LIST_ELEMENT(alice_needs_ev_spend, 0.45) \
LUA_DEFINES_LIST_ELEMENT(alice_needs_lx_spend, 0.50) \
LUA_DEFINES_LIST_ELEMENT(alice_sat_delay_factor, 0.1) \
LUA_DEFINES_LIST_ELEMENT(alice_need_drift_speed, 0.01) \
LUA_DEFINES_LIST_ELEMENT(alice_need_drift_speed, 0.0001) \
LUA_DEFINES_LIST_ELEMENT(alice_disable_divergent_any_country_effect, 0.0) \
LUA_DEFINES_LIST_ELEMENT(alice_unciv_civ_forbid_war, 0.0) \
LUA_DEFINES_LIST_ELEMENT(alice_ideology_base_change_rate, 1.0) \
Expand Down
Loading