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
6 changes: 6 additions & 0 deletions assets/localisation/en-US/alice.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,12 @@ private_education_owners;Private educators ?Y$val$?!
port_owners;Local port ?Y$val$?!
housing_owners;Landlords ?Y$val$?!
private_education_price;Education price ?Y$val$?!
private_education_supply_1;Education private supply ?Y$val$?!
private_education_supply_2;Education public supply ?Y$val$?!
private_education_demand_1;Education public demand ?Y$val$?!
private_education_demand_2;Education private demand ?Y$val$?!
private_education_size_public;Education public size ?Y$val$?!
private_education_size_private;Education private size ?Y$val$?!
port_price;Local port price ?Y$val$?!
housing_price;Housing price ?Y$val$?!
housing_supply;Housing supply ?Y$val$?!
Expand Down
34 changes: 21 additions & 13 deletions src/economy/advanced_province_buildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "constants_dcon.hpp"
#include "province_templates.hpp"
#include "money.hpp"
#include "economy_production.hpp"

namespace services {

Expand Down Expand Up @@ -96,7 +97,7 @@ namespace advanced_province_buildings {

// could be expanded by 1000 per 1 years
constexpr float max_port_expansion_speed = 1000.f / 365.f;
constexpr float max_city_expansion_rate= 0.1f / 365.f;
constexpr float max_city_expansion_rate= 1.f / 365.f;
constexpr float max_city_expansion_speed = 1000.f / 365.f;
constexpr float ports_decay_speed = 0.99999f;

Expand Down Expand Up @@ -508,14 +509,13 @@ void update_private_size(sys::state& state) {
/ (state.world.province_get_demographics(pids, demographics::total) + 1.f)
);

auto cost_of_input = state.world.province_get_labor_price(pids, def.throughput_labour_type);
auto wage = state.world.province_get_labor_price(pids, def.throughput_labour_type);
auto cost_of_output = state.world.province_get_service_price(pids, def.output) * local_education_efficiency * tmod * nmod * def.output_amount;

auto current_private_size = state.world.province_get_advanced_province_building_private_size(pids, bid);
auto margin = (cost_of_output - cost_of_input) / cost_of_input;
auto new_private_size = current_private_size + ve::min(margin, 100.f) + ve::min(ve::max(margin, -0.01f), 0.01f) * current_private_size;
auto max_size = state.world.province_get_demographics(pids, demographics::total) * state.world.province_get_labor_price(pids, economy::labor::no_education) / cost_of_input;
new_private_size = ve::min(max_size, new_private_size);
auto sat = state.world.province_get_labor_demand_satisfaction(pids, def.throughput_labour_type);
auto gradient = economy::gradient_employment_i<ve::fp_vector>(cost_of_output, ve::fp_vector{0.f}, ve::fp_vector{1.f}, wage);
auto employment_change = economy::gradient_to_employment_change<ve::fp_vector>(gradient, wage, current_private_size, sat);
auto new_private_size = current_private_size + employment_change;
state.world.province_set_advanced_province_building_private_size(pids, bid, ve::max(0.f, new_private_size));
});
}
Expand All @@ -527,15 +527,15 @@ void update_private_size(sys::state& state) {

province::for_each_market_province_parallel_over_market(state, [&](dcon::market_id mid, dcon::state_instance_id sid, dcon::province_id pid) {
auto owner = state.world.province_get_nation_from_province_ownership(pid);
auto cost_of_input = state.world.province_get_labor_price(pid, def.throughput_labour_type);
auto wage = state.world.province_get_labor_price(pid, def.throughput_labour_type);
auto max_size = state.world.province_get_advanced_province_building_max_private_size(pid, bid);
auto efficiency = ports_efficiency(state, owner, max_size);
auto cost_of_output = state.world.province_get_service_price(pid, def.output) * efficiency * def.output_amount;
auto current_private_size = state.world.province_get_advanced_province_building_private_size(pid, bid);
auto margin = (cost_of_output - cost_of_input) / cost_of_input;
auto probability_to_hire = state.world.province_get_labor_demand_satisfaction(pid, def.throughput_labour_type);
margin = margin > 0.f ? std::max(0.f, (probability_to_hire - 0.4f)) * margin : margin;
auto new_private_size = current_private_size + ve::min(margin, 100.f) + ve::min(ve::max(margin, -0.01f), 0.01f) * current_private_size;
auto sat = state.world.province_get_labor_demand_satisfaction(pid, def.throughput_labour_type);
auto gradient = economy::gradient_employment_i<ve::fp_vector>(cost_of_output, ve::fp_vector{ 0.f }, ve::fp_vector{ 1.f }, wage);
auto employment_change = economy::gradient_to_employment_change<ve::fp_vector>(gradient, wage, current_private_size, sat);
auto new_private_size = current_private_size + employment_change;
new_private_size = ve::min(max_size, new_private_size);
state.world.province_set_advanced_province_building_private_size(pid, bid, ve::max(0.f, new_private_size));
});
Expand Down Expand Up @@ -613,7 +613,15 @@ void update_national_size(sys::state& state) {
auto weight = ve::select(total_population == 0.f, 0.f, local_population / total_population);
auto local_education_budget = weight * education_budget;

state.world.province_set_advanced_province_building_national_size(pids, bid, ve::select(invalid, 0.f, ve::max(0.f, local_education_budget / cost_of_input)));
auto limitation = ve::max(0.f, local_education_budget / cost_of_input);

auto current_size = state.world.province_get_advanced_province_building_national_size(pids, bid);
auto sat = state.world.province_get_labor_demand_satisfaction(pids, def.throughput_labour_type);
auto demand_education_satisfaction = state.world.province_get_service_satisfaction_for_free(pids, def.output);
auto expansion_rate = (sat - 0.5f) * (current_size * 0.01f + 1.f) * (1.f - demand_education_satisfaction);
auto next_size = ve::min(ve::max(current_size + expansion_rate, 0.f), limitation);

state.world.province_set_advanced_province_building_national_size(pids, bid, ve::select(invalid, 0.f, next_size));
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/economy/demographics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ void set_consciousness(sys::state& state, T p, ve::fp_vector v) {
state.world.pop_set_uconsciousness(p, to_pmc(v));
}
float get_life_needs(sys::state const& state, dcon::pop_id p) {
auto ival = state.world.pop_get_ulife_needs_satisfaction(p);
return from_pu8(ival);
auto value = state.world.pop_get_satisfaction(p);
return std::min(value * 3.f, 1.f);
}
float get_everyday_needs(sys::state const& state, dcon::pop_id p) {
auto ival = state.world.pop_get_ueveryday_needs_satisfaction(p);
return from_pu8(ival);
auto value = state.world.pop_get_satisfaction(p);
return std::clamp(value* 3.f - 1.f, 0.f, 1.f);
}
float get_luxury_needs(sys::state const& state, dcon::pop_id p) {
auto ival = state.world.pop_get_uluxury_needs_satisfaction(p);
return from_pu8(ival);
auto value = state.world.pop_get_satisfaction(p);
return std::clamp(value* 3.f - 2.f, 0.f, 1.f);
}
float get_literacy(sys::state const& state, dcon::pop_id p) {
auto ival = state.world.pop_get_uliteracy(p);
Expand Down
26 changes: 7 additions & 19 deletions src/economy/demographics_templates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

#include "system_state.hpp"
#include "demographics.hpp"
#include "adaptive_ve.hpp"

namespace pop_demographics {
template<typename P, typename V>
void set_life_needs(sys::state& state, P p, V v) {
state.world.pop_set_ulife_needs_satisfaction(p, to_pu8(v));
}
template<typename P, typename V>
void set_everyday_needs(sys::state& state, P p, V v) {
state.world.pop_set_ueveryday_needs_satisfaction(p, to_pu8(v));
}
template<typename P, typename V>
void set_luxury_needs(sys::state& state, P p, V v) {
state.world.pop_set_uluxury_needs_satisfaction(p, to_pu8(v));
}

template<typename T>
auto get_employment(sys::state const& state, T p) {
auto ival = state.world.pop_get_uemployment(p);
Expand Down Expand Up @@ -58,18 +46,18 @@ void set_literacy(sys::state& state, P p, V v) {
}
template<typename T>
auto get_life_needs(sys::state const& state, T p) {
auto ival = state.world.pop_get_ulife_needs_satisfaction(p);
return from_pu8(ival);
auto val = state.world.pop_get_satisfaction(p);
return adaptive_ve::min<decltype(val)>(val * 3.f, 1.f);
}
template<typename T>
auto get_everyday_needs(sys::state const& state, T p) {
auto ival = state.world.pop_get_ueveryday_needs_satisfaction(p);
return from_pu8(ival);
auto val = state.world.pop_get_satisfaction(p);
return adaptive_ve::max<decltype(val)>(adaptive_ve::min<decltype(val)>(val * 3.f - 1.f, 1.f), 0.f);
}
template<typename T>
auto get_luxury_needs(sys::state const& state, T p) {
auto ival = state.world.pop_get_uluxury_needs_satisfaction(p);
return from_pu8(ival);
auto val = state.world.pop_get_satisfaction(p);
return adaptive_ve::max<decltype(val)>(adaptive_ve::min<decltype(val)>(val * 3.f - 2.f, 1.f), 0.f);
}
template<typename T>
auto get_demo(sys::state const& state, T p, dcon::pop_demographics_key k) {
Expand Down
26 changes: 11 additions & 15 deletions src/economy/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void rebalance_needs_weights(sys::state& state, dcon::market_id n) {
auto wage =
state.world.province_get_labor_price(capital, labor::no_education)
+ state.world.province_get_labor_price(capital, labor::basic_education)
+ state.world.province_get_labor_price(capital, labor::high_education);
+ state.world.province_get_labor_price(capital, labor::high_education) * 0.5f;

{
auto expected_cost = 0.f;
Expand Down Expand Up @@ -557,9 +557,7 @@ void initialize(sys::state& state) {

state.world.for_each_pop([&](dcon::pop_id p) {
auto fp = fatten(state.world, p);
pop_demographics::set_life_needs(state, p, 1.0f);
pop_demographics::set_everyday_needs(state, p, 0.1f);
pop_demographics::set_luxury_needs(state, p, 0.0f);
state.world.pop_set_satisfaction(p, 0.4f);
fp.set_savings(fp.get_size() * expected_savings);
});

Expand Down Expand Up @@ -3763,17 +3761,15 @@ void daily_update(sys::state& state, bool presimulation, float presimulation_sta
}

{
auto ln = pop_demographics::get_life_needs(state, ids);
auto en = pop_demographics::get_everyday_needs(state, ids);
auto lx = pop_demographics::get_luxury_needs(state, ids);
auto satisfaction = state.world.pop_get_satisfaction(ids);

ln = ve::min(1.f, ve::max(0.f, ln + (potential_ratio_life.get(ids) * (ln_satisfaction + satisfaction_from_subsistence.get(ids)) - 2.f) * pop_demographics::pop_u8_scaling));
en = ve::min(1.f, ve::max(0.f, en + (potential_ratio_everyday.get(ids) * en_satisfaction - 2.f) * pop_demographics::pop_u8_scaling));
lx = ve::min(1.f, ve::max(0.f, lx + (potential_ratio_luxury.get(ids) * lx_satisfaction - 2.f) * pop_demographics::pop_u8_scaling));
auto satisfaction_gain =
ve::min(1.f, potential_ratio_life.get(ids) * ln_satisfaction)
+ ve::min(1.f, potential_ratio_everyday.get(ids) * en_satisfaction)
+ ve::min(1.f, potential_ratio_luxury.get(ids) * lx_satisfaction);
satisfaction = satisfaction * 0.999f + satisfaction_gain * 0.001f / 3.f;

pop_demographics::set_life_needs(state, ids, ln);
pop_demographics::set_everyday_needs(state, ids, en);
pop_demographics::set_luxury_needs(state, ids, lx);
state.world.pop_set_satisfaction(ids, satisfaction);
}

{
Expand Down Expand Up @@ -4021,7 +4017,7 @@ void daily_update(sys::state& state, bool presimulation, float presimulation_sta
+ economy::price_properties::labor::min;

auto no_education = state.world.province_get_labor_price(ids, labor::no_education);
target_wage = ve::min(target_wage, no_education * 0.5f);
target_wage = ve::min(target_wage, no_education * 0.05f);
auto basic_education = state.world.province_get_labor_price(ids, labor::basic_education);
auto high_education = state.world.province_get_labor_price(ids, labor::high_education);
auto high_education_and_accepted = state.world.province_get_labor_price(ids, labor::high_education_and_accepted);
Expand Down Expand Up @@ -4414,7 +4410,7 @@ void daily_update(sys::state& state, bool presimulation, float presimulation_sta

price_control =
price_control
* state.world.province_get_labor_supply_sold(ids, i)
* ve::max(0.f, state.world.province_get_labor_supply_sold(ids, i) - 0.8f) * 5.f
* state.world.province_get_control_ratio(ids)
/ state.defines.alice_needs_scaling_factor
* min_wage_factor;
Expand Down
10 changes: 5 additions & 5 deletions src/economy/economy_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace economy {

constexpr inline float factories_per_state_required_city_size = 100'000.f;
constexpr inline float factories_per_state_required_city_size = 60'000.f;

namespace numerical {
namespace commodity_unit {
Expand All @@ -27,7 +27,7 @@ inline constexpr float effect_of_transportation_scale = 0.0005f;
inline constexpr float trade_distance_covered_by_pair_of_workers_per_unit_of_good = 10.f;
// Huge values could cause massive spikes of demand for transportation labor
inline constexpr float invalid_trade_route_distance = 0.01f;
inline constexpr float trade_loss_per_distance_unit = 0.0001f;
inline constexpr float trade_loss_per_distance_unit = 0.001f;
inline constexpr float trade_effect_of_scale_lower_bound = 0.1f;
inline constexpr float trade_base_multiplicative_decay = 0.0002f;
inline constexpr float trade_base_additive_decay = 0.1f;
Expand Down Expand Up @@ -59,8 +59,8 @@ inline constexpr float investment_pool_investment_per_day = 0.25f;
// greed drives incomes of corresponding pops up
// while making life worse on average
// profit cuts change distribution of incomes
inline constexpr float aristocrats_greed = 0.2f;
inline constexpr float artisans_greed = 0.3f;
inline constexpr float aristocrats_greed = 0.1f;
inline constexpr float artisans_greed = 0.1f;
inline constexpr float labor_greed_life = 0.1f;
inline constexpr float capitalists_greed = 0.4f;
inline constexpr float capitalists_greed = 0.1f;
}
Loading
Loading