Skip to content
Open
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
18 changes: 18 additions & 0 deletions C7Engine/AI/ChooseProducible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ private static float ScoreInflow(ProducibleStats stats, City city, Player player
// I am not sure how civ III does this, although I guess we should consider stuff like
// no more buildings to build, reached unit cap, very bad economy with no other options,
// the WealthNever and WealthOften flags from RACE, etc

if (HasWeakEconomy(player)) {
return 100 - player.gold;
}

return -1000f;
}

Expand Down Expand Up @@ -134,6 +139,10 @@ private static float ScoreUnit(ProducibleStats stats, City city, Player player,
// still in the expansion phase.
if (unitSupportCost > 0 && !atWar && !stats.inExpansionPhase) {
score -= unitSupportCost / 2;

if (HasWeakEconomy(player)) {
score -= unitSupportCost * 2;
}
}

////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -288,6 +297,11 @@ private static float ScoreBuilding(ProducibleStats stats, City city, Player play
score += 20;
}

// Penalize buildings if economy is weak
if (HasWeakEconomy(player)) {
score -= 10 * building.maintenanceCost;
}

return score;
}

Expand Down Expand Up @@ -374,5 +388,9 @@ private static int NumUnworkedTiles(City city) {
}
return result;
}

public static bool HasWeakEconomy(Player player) {
return player.luxuryRate == 0 && player.scienceRate == 0 && player.gold < 100;
}
}
}
8 changes: 7 additions & 1 deletion C7Engine/AI/PlayerAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private static void AdjustSliders(Player player) {
// Now max out the science slider and then decrease it (increasing
// the tax rate) until we're not losing money.
player.scienceRate = MAX_SLIDER_VALUE - player.luxuryRate;
while (player.CalculateGoldPerTurn() < 0 && player.scienceRate > 0) {
while (player.scienceRate > 0 && !BudgetIsTolerable(player)) {
player.scienceRate--;
player.taxRate++;
}
Expand Down Expand Up @@ -441,5 +441,11 @@ private static void FixRemainingUnhappyCities(Player player) {
}
}
}

public static bool BudgetIsTolerable(Player player) {
var gpt = player.CalculateGoldPerTurn();
var tolerableDeficit = gpt > player.gold * -0.1;
return gpt > 0 || tolerableDeficit;
}
}
}
7 changes: 5 additions & 2 deletions C7Engine/C7GameData/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public int gold {
}
}

private int lastGoldPerTurn = 0;

/// <summary>
/// Sets the current gold amount of the player. If the add parameter is true, the gold gets appended.<br/>
/// </summary>
Expand Down Expand Up @@ -751,7 +753,7 @@ public void DoPerTurnFinanceUpdates(GameData gameData) {
}

// If that wasn't sufficient, go after luxuries.
if (scienceRate > 0) {
if (luxuryRate > 0) {
--luxuryRate;
++taxRate;
continue;
Expand All @@ -761,7 +763,8 @@ public void DoPerTurnFinanceUpdates(GameData gameData) {
throw new Exception($"{this} was unable to get the budget under control despite being under the unit support cap and zeroing out the sliders (gold={gold}, gpt={CalculateGoldPerTurn()})");
}

gold += CalculateGoldPerTurn();
lastGoldPerTurn = CalculateGoldPerTurn();
gold += lastGoldPerTurn;
}

public void HandleCityUpdates(GameData gameData) {
Expand Down
Loading