Skip to content

Commit

Permalink
Merge pull request #1864 from ineveraskedforthis/labour-rework
Browse files Browse the repository at this point in the history
Labour rework
  • Loading branch information
schombert authored Jan 19, 2025
2 parents 1d53028 + d970a79 commit d91559b
Show file tree
Hide file tree
Showing 25 changed files with 1,870 additions and 1,151 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ list(APPEND ALICE_INCREMENTAL_SOURCES_LIST
"src/culture/rebels.cpp"
"src/economy/demographics.cpp"
"src/economy/economy.cpp"
"src/economy/economy_government.cpp"
"src/gamestate/commands.cpp"
"src/gamestate/diplomatic_messages.cpp"
"src/gamestate/modifiers.cpp"
Expand Down
36 changes: 6 additions & 30 deletions src/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ void update_ai_econ_construction(sys::state& state) {
for(auto fac : state.world.province_get_factory_location(p)) {
auto type = fac.get_factory().get_building_type();
if(type_selection == type) {
under_cap = fac.get_factory().get_primary_employment() * state.world.market_get_labor_unskilled_demand_satisfaction(market) < 0.9f;
under_cap = economy::factory_total_employment_score(state, fac.get_factory()) < 0.9f;
present_in_location = true;
return;
}
Expand Down Expand Up @@ -1520,9 +1520,8 @@ void update_ai_econ_construction(sys::state& state) {

auto unprofitable = fac.get_factory().get_unprofitable();
auto factory_level = fac.get_factory().get_level();
auto primary_employment = fac.get_factory().get_primary_employment() * state.world.market_get_labor_unskilled_demand_satisfaction(market);

if(!unprofitable && factory_level < uint8_t(255) && primary_employment >= 0.9f) {
if(!unprofitable && factory_level < uint8_t(255) && economy::factory_total_employment_score(state, fac.get_factory()) >= 0.9f) {
// test if factory is already upgrading
auto ug_in_progress = false;
for(auto c : state.world.state_instance_get_state_building_construction(si)) {
Expand Down Expand Up @@ -1621,7 +1620,7 @@ void update_ai_econ_construction(sys::state& state) {
for(auto fac : state.world.province_get_factory_location(p)) {
auto type = fac.get_factory().get_building_type();
if(type_selection == type) {
under_cap = fac.get_factory().get_primary_employment() * state.world.market_get_labor_unskilled_demand_satisfaction(market) < 0.9f;
under_cap = economy::factory_total_employment_score(state, fac.get_factory()) < 0.9f;
present_in_location = true;
return;
}
Expand Down Expand Up @@ -3818,23 +3817,18 @@ void update_budget(sys::state& state) {
float investments_budget_ratio = 0.05f;
float soldiers_budget_ratio = 0.40f;
float construction_budget_ratio = 0.50f;
float administration_budget_ratio = 0.15f;
float overseas_maintenance_budget_ratio = 0.10f;

if(n.get_is_at_war()) {
land_budget_ratio = 2.f;
sea_budget_ratio = 2.f;

administration_budget_ratio *= 0.15f;
education_budget_ratio *= 0.15f;
overseas_maintenance_budget_ratio *= 0.15f;
//n.set_land_spending(int8_t(100));
//n.set_naval_spending(int8_t(100));
} else if(n.get_ai_is_threatened()) {
land_budget_ratio = 0.5f;
sea_budget_ratio = 0.25f;

administration_budget_ratio *= 0.75f;
education_budget_ratio *= 0.75f;
overseas_maintenance_budget_ratio *= 0.75f;
//n.set_land_spending(int8_t(50));
Expand All @@ -3847,7 +3841,6 @@ void update_budget(sys::state& state) {
float naval_budget = sea_budget_ratio * base_income;
float education_budget = education_budget_ratio * base_income;
float construction_budget = construction_budget_ratio * base_income;
float administration_budget = administration_budget_ratio * base_income;
float soldiers_budget = soldiers_budget_ratio * base_income;
float overseas_budget = overseas_maintenance_budget_ratio * base_income;

Expand All @@ -3865,10 +3858,10 @@ void update_budget(sys::state& state) {
n.set_naval_spending(int8_t(ratio_naval));

n.set_construction_spending(75);
n.set_administrative_spending(10);

float max_education_budget = 1.f + economy::estimate_pop_payouts_by_income_type(state, n, culture::income_type::education);
float max_soldiers_budget = 1.f + economy::estimate_pop_payouts_by_income_type(state, n, culture::income_type::military);
float max_admin_budget = 1.f + economy::estimate_pop_payouts_by_income_type(state, n, culture::income_type::administration);
float max_overseas_budget = 1.f + economy::estimate_overseas_penalty_spending(state, n);

// solving x^2 * max = desired
Expand All @@ -3890,14 +3883,11 @@ void update_budget(sys::state& state) {

float soldiers_max_ratio = 100.f * math::sqrt(soldiers_budget / max_soldiers_budget);
soldiers_max_ratio = std::clamp(soldiers_max_ratio, 0.f, 100.f);

float administration_max_ratio = 100.f * math::sqrt(administration_budget / max_admin_budget);
administration_max_ratio = std::clamp(administration_max_ratio, 0.f, 100.f);

float overseas_max_ratio = std::clamp(100.f * overseas_budget / max_overseas_budget, 0.f, 100.f);

n.set_tariffs_import(int8_t(5));
n.set_tariffs_export(int8_t(5));
n.set_tariffs_import(int8_t(10));
n.set_tariffs_export(int8_t(10));

float poor_militancy = (state.world.nation_get_demographics(n, demographics::poor_militancy) / std::max(1.0f, state.world.nation_get_demographics(n, demographics::poor_total))) / 10.f;
float mid_militancy = (state.world.nation_get_demographics(n, demographics::middle_militancy) / std::max(1.0f, state.world.nation_get_demographics(n, demographics::middle_total))) / 10.f;
Expand All @@ -3920,9 +3910,6 @@ void update_budget(sys::state& state) {
}

if(n.get_spending_level() < 1.0f || n.get_last_treasury() >= n.get_stockpiles(economy::money) || ratio_education < 50.f) { // losing money
//if(n.get_administrative_efficiency() > 0.98f) {
// n.set_administrative_spending(int8_t(std::max(0, n.get_administrative_spending() - 2)));
//}
if(!n.get_ai_is_threatened()) {
n.set_military_spending(int8_t(std::max(50, n.get_military_spending() - 5)));
}
Expand All @@ -3932,9 +3919,6 @@ void update_budget(sys::state& state) {
n.set_middle_tax(int8_t(std::clamp(n.get_middle_tax() + 3, 10, std::max(10, max_mid_tax))));
n.set_rich_tax(int8_t(std::clamp(n.get_rich_tax() + 5, 10, std::max(10, max_rich_tax))));
} else if(n.get_last_treasury() < n.get_stockpiles(economy::money)) { // gaining money
//if(n.get_administrative_efficiency() < 0.98f) {
// n.set_administrative_spending(int8_t(std::min(100, n.get_administrative_spending() + 2)));
//}
if(n.get_ai_is_threatened()) {
n.set_military_spending(int8_t(std::min(100, n.get_military_spending() + 10)));
} else {
Expand Down Expand Up @@ -3965,9 +3949,6 @@ void update_budget(sys::state& state) {

// Laissez faire prioritize tax free capitalists
if(n.get_spending_level() < 1.0f || n.get_last_treasury() >= n.get_stockpiles(economy::money) || ratio_education < 50.f) { // losing money
//if(n.get_administrative_efficiency() > 0.98f) {
// n.set_administrative_spending(int8_t(std::max(0, n.get_administrative_spending() - 2)));
//}
if(!n.get_ai_is_threatened()) {
n.set_military_spending(int8_t(std::max(50, n.get_military_spending() - 5)));
}
Expand All @@ -3977,9 +3958,6 @@ void update_budget(sys::state& state) {
n.set_middle_tax(int8_t(std::clamp(n.get_middle_tax() + 3, 10, std::max(10, max_mid_tax))));
n.set_rich_tax(int8_t(std::clamp(n.get_rich_tax() + 2, 10, std::max(10, max_rich_tax))));
} else if(n.get_last_treasury() < n.get_stockpiles(economy::money)) { // gaining money
//if(n.get_administrative_efficiency() < 0.98f) {
// n.set_administrative_spending(int8_t(std::min(100, n.get_administrative_spending() + 2)));
//}
if(n.get_ai_is_threatened()) {
n.set_military_spending(int8_t(std::min(100, n.get_military_spending() + 10)));
} else {
Expand All @@ -3995,8 +3973,6 @@ void update_budget(sys::state& state) {
}
}

n.set_administrative_spending(int8_t(std::min(int8_t(administration_max_ratio), n.get_administrative_spending())));
n.set_administrative_spending(int8_t(administration_max_ratio));
n.set_military_spending(int8_t(std::min(int8_t(soldiers_max_ratio), n.get_military_spending())));
n.set_overseas_spending(int8_t(overseas_max_ratio));

Expand Down
Loading

0 comments on commit d91559b

Please sign in to comment.