diff --git a/src/micropolisj/engine/CityBudget.java b/src/micropolisj/engine/CityBudget.java new file mode 100644 index 0000000..a2bb919 --- /dev/null +++ b/src/micropolisj/engine/CityBudget.java @@ -0,0 +1,20 @@ +// This file is part of MicropolisJ. +// Copyright (C) 2013 Jason Long +// Portions Copyright (C) 1989-2007 Electronic Arts Inc. +// +// MicropolisJ is free software; you can redistribute it and/or modify +// it under the terms of the GNU GPLv3, with additional terms. +// See the README file, included in this distribution, for details. + +package micropolisj.engine; + +public class CityBudget +{ + private final Micropolis city; + public int totalFunds; + + CityBudget(Micropolis city) + { + this.city = city; + } +} diff --git a/src/micropolisj/engine/MapGenerator.java b/src/micropolisj/engine/MapGenerator.java index 2173af1..063f9c2 100644 --- a/src/micropolisj/engine/MapGenerator.java +++ b/src/micropolisj/engine/MapGenerator.java @@ -60,7 +60,8 @@ public class MapGenerator public void generateSomeCity(long r) { - engine.totalFunds = GameLevel.getStartingFunds(engine.gameLevel); + //FIXME- initial funds should be set by caller + engine.budget.totalFunds = GameLevel.getStartingFunds(engine.gameLevel); generateMap(r); engine.fireWholeMapChanged(); } diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java index 0c824f6..6d2a0e7 100644 --- a/src/micropolisj/engine/Micropolis.java +++ b/src/micropolisj/engine/Micropolis.java @@ -94,7 +94,7 @@ public class Micropolis static final int DEFAULT_WIDTH = 120; static final int DEFAULT_HEIGHT = 100; - public int totalFunds; + public final CityBudget budget = new CityBudget(this); public boolean autoBulldoze = true; public boolean autoBudget = false; public Speed simSpeed = Speed.NORMAL; @@ -205,7 +205,7 @@ public class Micropolis public void spend(int amount) { - totalFunds -= amount; + budget.totalFunds -= amount; fireFundsChanged(); } @@ -1725,7 +1725,7 @@ public class Micropolis cashFlow = revenue - expenses; spend(-cashFlow); - hist.totalFunds = totalFunds; + hist.totalFunds = budget.totalFunds; financialHistory.add(0,hist); taxFund = 0; @@ -1751,7 +1751,7 @@ public class Micropolis b.firePercent = Math.max(0.0, firePercent); b.policePercent = Math.max(0.0, policePercent); - b.previousBalance = totalFunds; + b.previousBalance = budget.totalFunds; b.taxIncome = (int)Math.round(lastTotalPop * landValueAverage / 120 * b.taxRate * FLevels[gameLevel]); assert b.taxIncome >= 0; @@ -1763,7 +1763,7 @@ public class Micropolis b.fireFunded = (int)Math.round(b.fireRequest * b.firePercent); b.policeFunded = (int)Math.round(b.policeRequest * b.policePercent); - int yumDuckets = totalFunds + b.taxIncome; + int yumDuckets = budget.totalFunds + b.taxIncome; assert yumDuckets >= 0; if (yumDuckets >= b.roadFunded) @@ -1919,7 +1919,7 @@ public class Micropolis dis.readShort(); } - totalFunds = dis.readInt(); //[50-51] total funds + budget.totalFunds = dis.readInt(); //[50-51] total funds autoBulldoze = dis.readShort() != 0; //52 autoBudget = dis.readShort() != 0; autoGo = dis.readShort() != 0; //54 @@ -1986,7 +1986,7 @@ public class Micropolis out.writeShort(0); } //50 - out.writeInt(totalFunds); + out.writeInt(budget.totalFunds); out.writeShort(autoBulldoze ? 1 : 0); out.writeShort(autoBudget ? 1 : 0); //54 @@ -2613,7 +2613,7 @@ public class Micropolis gameLevel = newLevel; fireOptionsChanged(); - if (totalFunds > delta) { + if (budget.totalFunds > delta) { spend(delta); } } diff --git a/src/micropolisj/engine/MicropolisTool.java b/src/micropolisj/engine/MicropolisTool.java index 3013e3c..fae9be8 100644 --- a/src/micropolisj/engine/MicropolisTool.java +++ b/src/micropolisj/engine/MicropolisTool.java @@ -158,7 +158,7 @@ public enum MicropolisTool cost += getToolCost(); - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; // take care of the money situation here @@ -220,7 +220,7 @@ public enum MicropolisTool cost += getToolCost(); - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; // take care of the money situation here @@ -283,7 +283,7 @@ public enum MicropolisTool cost += getToolCost(); - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; // take care of the money situation here @@ -394,7 +394,7 @@ public enum MicropolisTool if ((currTile & ZONEBIT) != 0) { // zone center bit is set - if (engine.totalFunds >= 1) + if (engine.budget.totalFunds >= 1) { engine.spend(1); switch (checkSize(tmp)) @@ -435,7 +435,7 @@ public enum MicropolisTool tmp == REDGE || tmp == CHANNEL) { - if (engine.totalFunds >= 6) + if (engine.budget.totalFunds >= 6) { ToolResult result = layDoze(engine, xpos, ypos); if (tmp != (engine.getTile(xpos, ypos) & LOMASK)) @@ -501,7 +501,7 @@ public enum MicropolisTool } } - if (engine.totalFunds < cost) { + if (engine.budget.totalFunds < cost) { return ToolResult.INSUFFICIENT_FUNDS; } @@ -538,7 +538,7 @@ public enum MicropolisTool private ToolResult layDoze(Micropolis engine, int xpos, int ypos) { - if (engine.totalFunds <= 0) + if (engine.budget.totalFunds <= 0) return ToolResult.INSUFFICIENT_FUNDS; char tile = engine.getTile(xpos, ypos); @@ -569,7 +569,7 @@ public enum MicropolisTool final int TUNNEL_COST = 100; int cost = RAIL_COST; - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); @@ -580,7 +580,7 @@ public enum MicropolisTool case CHANNEL: cost = TUNNEL_COST; - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; if (xpos + 1 < engine.getWidth()) @@ -676,7 +676,7 @@ public enum MicropolisTool final int BRIDGE_COST = 50; int cost = ROAD_COST; - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); @@ -687,7 +687,7 @@ public enum MicropolisTool case CHANNEL: // check how to build bridges, if possible. cost = BRIDGE_COST; - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; if (xpos + 1 < engine.getWidth()) @@ -783,7 +783,7 @@ public enum MicropolisTool final int UNDERWATER_WIRE_COST = 25; int cost = WIRE_COST; - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; char tile = (char) (engine.getTile(xpos, ypos) & LOMASK); @@ -796,7 +796,7 @@ public enum MicropolisTool case CHANNEL: cost = UNDERWATER_WIRE_COST; - if (engine.totalFunds < cost) + if (engine.budget.totalFunds < cost) return ToolResult.INSUFFICIENT_FUNDS; if (xpos + 1 < engine.getWidth()) diff --git a/src/micropolisj/gui/MainWindow.java b/src/micropolisj/gui/MainWindow.java index 7b7708a..db91cef 100644 --- a/src/micropolisj/gui/MainWindow.java +++ b/src/micropolisj/gui/MainWindow.java @@ -1211,7 +1211,7 @@ public class MainWindow extends JFrame private void reloadFunds() { - fundsLbl.setText(formatFunds(getEngine().totalFunds)); + fundsLbl.setText(formatFunds(getEngine().budget.totalFunds)); } //implements Micropolis.Listener