From 6cfc5ef5efb7dce269dc17e44045101b2149490e Mon Sep 17 00:00:00 2001
From: "jason@long.name" <jason@long.name@d9718cc8-9f43-0410-858b-315f434eb58c>
Date: Sun, 24 Feb 2013 21:25:59 +0000
Subject: [PATCH] budget: fix bug that caused budget numbers to occassionally
 be wrong

when bringing up the budget manually, depending on the exact moment
the road/rail/etc counts might be wrong, leading to wrong numbers being
shown

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@583 d9718cc8-9f43-0410-858b-315f434eb58c
---
 src/micropolisj/engine/Micropolis.java | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java
index 4f00f82..698ecb7 100644
--- a/src/micropolisj/engine/Micropolis.java
+++ b/src/micropolisj/engine/Micropolis.java
@@ -129,6 +129,13 @@ public class Micropolis
 	int totalPop;
 	int lastCityPop;
 
+	// used in generateBudget()
+	int lastRoadTotal;
+	int lastRailTotal;
+	int lastTotalPop;
+	int lastFireStationCount;
+	int lastPoliceCount;
+
 	int trafficMaxLocationX;
 	int trafficMaxLocationY;
 	int pollutionMaxLocationX;
@@ -1669,6 +1676,12 @@ public class Micropolis
 
 	void collectTaxPartial()
 	{
+		lastRoadTotal = roadTotal;
+		lastRailTotal = railTotal;
+		lastTotalPop = totalPop;
+		lastFireStationCount = fireStationCount;
+		lastPoliceCount = policeCount;
+
 		BudgetNumbers b = generateBudget();
 
 		taxFund += b.taxIncome;
@@ -1731,12 +1744,12 @@ public class Micropolis
 		b.policePercent = Math.max(0.0, policePercent);
 
 		b.previousBalance = totalFunds;
-		b.taxIncome = (int)Math.round(totalPop * landValueAverage / 120 * b.taxRate * FLevels[gameLevel]);
+		b.taxIncome = (int)Math.round(lastTotalPop * landValueAverage / 120 * b.taxRate * FLevels[gameLevel]);
 		assert b.taxIncome >= 0;
 
-		b.roadRequest = (int)Math.round((roadTotal + railTotal * 2) * RLevels[gameLevel]);
-		b.fireRequest = 100 * fireStationCount;
-		b.policeRequest = 100 * policeCount;
+		b.roadRequest = (int)Math.round((lastRoadTotal + lastRailTotal * 2) * RLevels[gameLevel]);
+		b.fireRequest = 100 * lastFireStationCount;
+		b.policeRequest = 100 * lastPoliceCount;
 
 		b.roadFunded = (int)Math.round(b.roadRequest * b.roadPercent);
 		b.fireFunded = (int)Math.round(b.fireRequest * b.firePercent);