Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/game Modified Files: Portfolio.java StockRound.java TrainType.java StartItem.java Game.java PlayerManager.java PublicCompany.java TreasuryShareRound.java TrainManager.java GameManager.java Station.java ShareSellingRound.java BonusToken.java OperatingRound.java Bank.java Round.java PrivateCompany.java Train.java TrainTypeI.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: TrainTypeI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainTypeI.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TrainTypeI.java 4 May 2009 20:29:14 -0000 1.8 --- TrainTypeI.java 25 Sep 2009 19:13:01 -0000 1.9 *************** *** 85,89 **** * @param available The available to set. */ ! public void setAvailable(); public void setRusted(Portfolio lastBuyingCompany); --- 85,89 ---- * @param available The available to set. */ ! public void setAvailable(Bank bank); public void setRusted(Portfolio lastBuyingCompany); Index: TreasuryShareRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TreasuryShareRound.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TreasuryShareRound.java 15 Jan 2009 20:53:28 -0000 1.12 --- TreasuryShareRound.java 25 Sep 2009 19:13:01 -0000 1.13 *************** *** 106,110 **** /* Get the unique Pool certificates and check which ones can be bought */ ! from = Bank.getPool(); Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); --- 106,110 ---- /* Get the unique Pool certificates and check which ones can be bought */ ! from = pool; Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); *************** *** 177,181 **** /* May not sell more than the Pool can accept */ maxShareToSell = ! Math.min(maxShareToSell, Bank.getPoolShareLimit() - pool.getShare(company)); if (maxShareToSell == 0) continue; --- 177,181 ---- /* May not sell more than the Pool can accept */ maxShareToSell = ! Math.min(maxShareToSell, bank.getPoolShareLimit() - pool.getShare(company)); if (maxShareToSell == 0) continue; *************** *** 422,426 **** // The pool may not get over its limit. ! if (pool.getShare(company) + numberToSell * company.getShareUnit() > Bank.getPoolShareLimit()) { errMsg = LocalText.getText("PoolOverHoldLimit"); break; --- 422,426 ---- // The pool may not get over its limit. ! if (pool.getShare(company) + numberToSell * company.getShareUnit() > bank.getPoolShareLimit()) { errMsg = LocalText.getText("PoolOverHoldLimit"); break; Index: StartItem.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartItem.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** StartItem.java 11 Sep 2009 19:27:23 -0000 1.17 --- StartItem.java 25 Sep 2009 19:13:01 -0000 1.18 *************** *** 140,145 **** minimumBid.set(basePrice.intValue() + 5); ! Portfolio ipo = Bank.getIpo(); ! Portfolio unavailable = Bank.getUnavailable(); CompanyManagerI compMgr = gameManager.getCompanyManager(); --- 140,145 ---- minimumBid.set(basePrice.intValue() + 5); ! Portfolio ipo = gameManager.getBank().getIpo(); ! Portfolio unavailable = gameManager.getBank().getUnavailable(); CompanyManagerI compMgr = gameManager.getCompanyManager(); Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** PublicCompany.java 23 Sep 2009 21:38:57 -0000 1.60 --- PublicCompany.java 25 Sep 2009 19:13:01 -0000 1.61 *************** *** 242,245 **** --- 242,246 ---- protected GameManagerI gameManager; + protected Bank bank; /** *************** *** 641,644 **** --- 642,646 ---- this.gameManager = gameManager; + bank = gameManager.getBank(); if (hasStockPrice && Util.hasValue(startSpace)) { *************** *** 866,872 **** TrainManagerI trainManager = gameManager.getTrainManager(); TrainTypeI type = trainManager.getTypeByName(initialTrain); ! TrainI train = Bank.getIpo().getTrainOfType(type); buyTrain(train, 0); ! trainManager.checkTrainAvailability(train, Bank.getIpo()); } } --- 868,874 ---- TrainManagerI trainManager = gameManager.getTrainManager(); TrainTypeI type = trainManager.getTypeByName(initialTrain); ! TrainI train = bank.getIpo().getTrainOfType(type); buyTrain(train, 0); ! trainManager.checkTrainAvailability(train, bank.getIpo()); } } *************** *** 898,902 **** super.setClosed(); for (PublicCertificateI cert : certificates) { ! cert.moveTo(Bank.getScrapHeap()); } lastRevenue.setOption(MoneyModel.SUPPRESS_ZERO); --- 900,904 ---- super.setClosed(); for (PublicCertificateI cert : certificates) { ! cert.moveTo(bank.getScrapHeap()); } lastRevenue.setOption(MoneyModel.SUPPRESS_ZERO); *************** *** 1126,1131 **** public boolean isAvailable() { Portfolio presLoc = certificates.get(0).getPortfolio(); ! return presLoc != Bank.getUnavailable() ! && presLoc != Bank.getScrapHeap(); } --- 1128,1133 ---- public boolean isAvailable() { Portfolio presLoc = certificates.get(0).getPortfolio(); ! return presLoc != bank.getUnavailable() ! && presLoc != bank.getScrapHeap(); } *************** *** 1180,1184 **** int withheld = (amount / (2 * getNumberOfShares())) * getNumberOfShares(); ! new CashMove(null, this, withheld); ReportBuffer.add(name + " receives " + Bank.format(withheld)); --- 1182,1186 ---- int withheld = (amount / (2 * getNumberOfShares())) * getNumberOfShares(); ! new CashMove(bank, this, withheld); ReportBuffer.add(name + " receives " + Bank.format(withheld)); *************** *** 1217,1221 **** ReportBuffer.add(recipient.getName() + " receives " + Bank.format(part)); ! new CashMove(null, recipient, part); } --- 1219,1223 ---- ReportBuffer.add(recipient.getName() + " receives " + Bank.format(part)); ! new CashMove(bank, recipient, part); } *************** *** 1234,1239 **** CashHolder beneficiary = holder.getOwner(); // Special cases apply if the holder is the IPO or the Pool ! if (holder == Bank.getIpo() && ipoPaysOut ! || holder == Bank.getPool() && poolPaysOut) { beneficiary = this; } --- 1236,1241 ---- CashHolder beneficiary = holder.getOwner(); // Special cases apply if the holder is the IPO or the Pool ! if (holder == bank.getIpo() && ipoPaysOut ! || holder == bank.getPool() && poolPaysOut) { beneficiary = this; } *************** *** 1247,1251 **** */ public void withhold(int amount) { ! if (amount > 0) new CashMove(null, this, amount); // Move the token if (hasStockPrice) Game.getStockMarket().withhold(this); --- 1249,1253 ---- */ public void withhold(int amount) { ! if (amount > 0) new CashMove(bank, this, amount); // Move the token if (hasStockPrice) Game.getStockMarket().withhold(this); *************** *** 1411,1415 **** */ public int getUnsoldPercentage() { ! return Bank.getIpo().getShare(this) + portfolio.getShare(this); } --- 1413,1417 ---- */ public int getUnsoldPercentage() { ! return bank.getIpo().getShare(this) + portfolio.getShare(this); } *************** *** 1469,1473 **** //portfolio.buyPrivate(privateCompany, from, price); ! if (from != Bank.getIpo()) { // The initial buy is reported from StartRound. This message should also // move to elsewhere. --- 1471,1475 ---- //portfolio.buyPrivate(privateCompany, from, price); ! if (from != bank.getIpo()) { // The initial buy is reported from StartRound. This message should also // move to elsewhere. *************** *** 1483,1487 **** // Move the money ! if (price > 0) new CashMove(this, from.owner, price); privatesCostThisTurn.add(price); --- 1485,1489 ---- // Move the money ! if (price > 0) new CashMove(bank, from.owner, price); privatesCostThisTurn.add(price); Index: TrainManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManager.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** TrainManager.java 8 Sep 2009 21:48:59 -0000 1.17 --- TrainManager.java 25 Sep 2009 19:13:01 -0000 1.18 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import rails.game.state.IntegerState; import rails.util.LocalText; import rails.util.Tag; public class TrainManager implements TrainManagerI, ConfigurableComponentI { // Static attributes protected List<TrainTypeI> lTrainTypes = new ArrayList<TrainTypeI>(); protected Map<String, TrainTypeI> mTrainTypes = new HashMap<String, TrainTypeI>(); protected boolean buyAtFaceValueBetweenDifferentPresidents = false; // Dynamic attributes protected Portfolio unavailable = null; protected IntegerState newTypeIndex; protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; protected GameManagerI gameManager = null; // Non-game attributes private static TrainManagerI instance = null; protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { instance = this; ipo = Bank.getIpo(); unavailable = Bank.getUnavailable(); // Nothing to do here, everything happens when configured. newTypeIndex = new IntegerState("NewTrainTypeIndex", 0); } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { TrainType defaultType = null; TrainType newType; Tag defaultsTag = tag.getChild("Defaults"); if (defaultsTag != null) { defaultType = new TrainType(false); defaultType.configureFromXML(defaultsTag); } List<Tag> typeTags = tag.getChildren("Train"); for (Tag typeTag : typeTags) { if (defaultType != null) { newType = (TrainType) defaultType.clone(); if (newType == null) { throw new ConfigurationException("Cannot clone traintype " + defaultType.getName()); } } else { newType = new TrainType(true); } lTrainTypes.add(newType); newType.configureFromXML(typeTag); mTrainTypes.put(newType.getName(), newType); } // Special train buying rules Tag rulesTag = tag.getChild("TrainBuyingRules"); if (rulesTag != null) { // A 1851 special buyAtFaceValueBetweenDifferentPresidents = rulesTag.getChild("FaceValueIfDifferentPresidents") != null; } // Finish initialisation of the train types for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeName() != null) { type.setReleasedTrainType(mTrainTypes.get(type.getReleasedTrainTypeName())); } if (type.getRustedTrainTypeName() != null) { type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); mTrainTypes.get(type.getRustedTrainTypeName()).setPermanent(false); } } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(); } public void init (GameManagerI gameManager) { this.gameManager = gameManager; } /** * Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the * IPO. * * @param holder The Portfolio for which this list will be made (always * IPO). */ public static String makeAbbreviatedList(Portfolio holder) { StringBuffer b = new StringBuffer(); TrainI[] trains; for (TrainTypeI type : instance.getTrainTypes()) { trains = holder.getTrainsPerType(type); if (trains.length > 0) { if (b.length() > 0) b.append(" "); b.append(type.getName()).append("("); if (type.hasInfiniteAmount()) { b.append("+"); } else { b.append(trains.length); } b.append(")"); } } return b.toString(); } /** * Make a full list of trains, like "2 2 3 3", to show in any field * describing train possessions, except the IPO. * * @param holder The Portfolio for which this list will be made. */ public static String makeFullList(Portfolio holder) { List<TrainI> trains = holder.getTrainList(); if (trains == null || trains.size() == 0) return ""; return makeFullList(trains); } public static String makeFullList(List<TrainI> trains) { StringBuffer b = new StringBuffer(); for (TrainI train : trains) { if (b.length() > 0) b.append(" "); if (train.isObsolete()) b.append("("); b.append(train.toDisplay()); if (train.isObsolete()) b.append(")"); } return b.toString(); } /** * This method handles any consequences of new train buying (from the IPO), * such as rusting and phase changes. It must be called <b>after</b> the * train has been transferred. * */ public void checkTrainAvailability(TrainI train, Portfolio from) { trainsHaveRusted = false; phaseHasChanged = false; if (from != ipo) return; TrainTypeI boughtType, nextType; boughtType = train.getType(); if (boughtType == (lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = (lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(); trainAvailabilityChanged = true; ReportBuffer.add("All " + boughtType.getName() + "-trains are sold out, " + nextType.getName() + "-trains now available"); } } if (boughtType.getNumberBoughtFromIPO() == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); String newPhase = boughtType.getStartedPhaseName(); if (newPhase != null) { gameManager.getPhaseManager().setPhase(newPhase); phaseHasChanged = true; } TrainTypeI rustedType = boughtType.getRustedTrainType(); if (rustedType != null && !rustedType.hasRusted()) { rustedType.setRusted(train.getHolder()); // Or obsolete, // where applicable ReportBuffer.add(LocalText.getText("TrainsRusted", rustedType.getName())); trainsHaveRusted = true; trainAvailabilityChanged = true; } TrainTypeI releasedType = boughtType.getReleasedTrainType(); if (releasedType != null) { if (!releasedType.isAvailable()) releasedType.setAvailable(); ReportBuffer.add(LocalText.getText("TrainsAvailable", releasedType.getName())); trainAvailabilityChanged = true; } } } public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); TrainI train; for (TrainTypeI type : lTrainTypes) { if (type.isAvailable()) { train = ipo.getTrainOfType(type); if (train != null) { availableTrains.add(train); } } } return availableTrains; } public TrainTypeI getTypeByName(String name) { return mTrainTypes.get(name); } public List<TrainTypeI> getTrainTypes() { return lTrainTypes; } public boolean hasAvailabilityChanged() { return trainAvailabilityChanged; } public void resetAvailabilityChanged() { trainAvailabilityChanged = false; } public boolean hasPhaseChanged() { return phaseHasChanged; } public boolean buyAtFaceValueBetweenDifferentPresidents() { return buyAtFaceValueBetweenDifferentPresidents; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import rails.game.state.IntegerState; import rails.util.LocalText; import rails.util.Tag; public class TrainManager implements TrainManagerI, ConfigurableComponentI { // Static attributes protected List<TrainTypeI> lTrainTypes = new ArrayList<TrainTypeI>(); protected Map<String, TrainTypeI> mTrainTypes = new HashMap<String, TrainTypeI>(); protected boolean buyAtFaceValueBetweenDifferentPresidents = false; // Dynamic attributes protected Portfolio unavailable = null; protected IntegerState newTypeIndex; protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; protected GameManagerI gameManager = null; protected Bank bank = null; // Non-game attributes private static TrainManagerI instance = null; protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { instance = this; // Nothing to do here, everything happens when configured. newTypeIndex = new IntegerState("NewTrainTypeIndex", 0); } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { TrainType defaultType = null; TrainType newType; Tag defaultsTag = tag.getChild("Defaults"); if (defaultsTag != null) { defaultType = new TrainType(false); defaultType.configureFromXML(defaultsTag); } List<Tag> typeTags = tag.getChildren("Train"); for (Tag typeTag : typeTags) { if (defaultType != null) { newType = (TrainType) defaultType.clone(); if (newType == null) { throw new ConfigurationException("Cannot clone traintype " + defaultType.getName()); } } else { newType = new TrainType(true); } lTrainTypes.add(newType); newType.configureFromXML(typeTag); mTrainTypes.put(newType.getName(), newType); } // Special train buying rules Tag rulesTag = tag.getChild("TrainBuyingRules"); if (rulesTag != null) { // A 1851 special buyAtFaceValueBetweenDifferentPresidents = rulesTag.getChild("FaceValueIfDifferentPresidents") != null; } // Finish initialisation of the train types for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeName() != null) { type.setReleasedTrainType(mTrainTypes.get(type.getReleasedTrainTypeName())); } if (type.getRustedTrainTypeName() != null) { type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); mTrainTypes.get(type.getRustedTrainTypeName()).setPermanent(false); } } } public void init (GameManagerI gameManager) { this.gameManager = gameManager; bank = gameManager.getBank(); ipo = bank.getIpo(); unavailable = bank.getUnavailable(); // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(bank); } /** * Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the * IPO. * * @param holder The Portfolio for which this list will be made (always * IPO). */ public static String makeAbbreviatedList(Portfolio holder) { StringBuffer b = new StringBuffer(); TrainI[] trains; for (TrainTypeI type : instance.getTrainTypes()) { trains = holder.getTrainsPerType(type); if (trains.length > 0) { if (b.length() > 0) b.append(" "); b.append(type.getName()).append("("); if (type.hasInfiniteAmount()) { b.append("+"); } else { b.append(trains.length); } b.append(")"); } } return b.toString(); } /** * Make a full list of trains, like "2 2 3 3", to show in any field * describing train possessions, except the IPO. * * @param holder The Portfolio for which this list will be made. */ public static String makeFullList(Portfolio holder) { List<TrainI> trains = holder.getTrainList(); if (trains == null || trains.size() == 0) return ""; return makeFullList(trains); } public static String makeFullList(List<TrainI> trains) { StringBuffer b = new StringBuffer(); for (TrainI train : trains) { if (b.length() > 0) b.append(" "); if (train.isObsolete()) b.append("("); b.append(train.toDisplay()); if (train.isObsolete()) b.append(")"); } return b.toString(); } /** * This method handles any consequences of new train buying (from the IPO), * such as rusting and phase changes. It must be called <b>after</b> the * train has been transferred. * */ public void checkTrainAvailability(TrainI train, Portfolio from) { trainsHaveRusted = false; phaseHasChanged = false; if (from != ipo) return; TrainTypeI boughtType, nextType; boughtType = train.getType(); if (boughtType == (lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = (lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(bank); trainAvailabilityChanged = true; ReportBuffer.add("All " + boughtType.getName() + "-trains are sold out, " + nextType.getName() + "-trains now available"); } } if (boughtType.getNumberBoughtFromIPO() == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); String newPhase = boughtType.getStartedPhaseName(); if (newPhase != null) { gameManager.getPhaseManager().setPhase(newPhase); phaseHasChanged = true; } TrainTypeI rustedType = boughtType.getRustedTrainType(); if (rustedType != null && !rustedType.hasRusted()) { rustedType.setRusted(train.getHolder()); // Or obsolete, // where applicable ReportBuffer.add(LocalText.getText("TrainsRusted", rustedType.getName())); trainsHaveRusted = true; trainAvailabilityChanged = true; } TrainTypeI releasedType = boughtType.getReleasedTrainType(); if (releasedType != null) { if (!releasedType.isAvailable()) releasedType.setAvailable(bank); ReportBuffer.add(LocalText.getText("TrainsAvailable", releasedType.getName())); trainAvailabilityChanged = true; } } } public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); TrainI train; for (TrainTypeI type : lTrainTypes) { if (type.isAvailable()) { train = ipo.getTrainOfType(type); if (train != null) { availableTrains.add(train); } } } return availableTrains; } public TrainTypeI getTypeByName(String name) { return mTrainTypes.get(name); } public List<TrainTypeI> getTrainTypes() { return lTrainTypes; } public boolean hasAvailabilityChanged() { return trainAvailabilityChanged; } public void resetAvailabilityChanged() { trainAvailabilityChanged = false; } public boolean hasPhaseChanged() { return phaseHasChanged; } public boolean buyAtFaceValueBetweenDifferentPresidents() { return buyAtFaceValueBetweenDifferentPresidents; } } \ No newline at end of file Index: PrivateCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompany.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** PrivateCompany.java 23 Sep 2009 21:38:57 -0000 1.21 --- PrivateCompany.java 25 Sep 2009 19:13:01 -0000 1.22 *************** *** 169,173 **** super.setClosed(); unblockHexes(); ! moveTo(Bank.getScrapHeap()); ReportBuffer.add(LocalText.getText("PrivateCloses", name)); --- 169,173 ---- super.setClosed(); unblockHexes(); ! moveTo(Bank.getInstance().getScrapHeap()); ReportBuffer.add(LocalText.getText("PrivateCloses", name)); *************** *** 175,179 **** for (SpecialPropertyI sp : specialProperties) { if (sp instanceof SellBonusToken) { ! ((SellBonusToken)sp).setSeller(Bank.getInstance()); } } --- 175,179 ---- for (SpecialPropertyI sp : specialProperties) { if (sp instanceof SellBonusToken) { ! ((SellBonusToken)sp).setSeller((CashHolder)Bank.getInstance()); } } Index: PlayerManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PlayerManager.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PlayerManager.java 4 Sep 2009 18:40:30 -0000 1.9 --- PlayerManager.java 25 Sep 2009 19:13:01 -0000 1.10 *************** *** 45,49 **** } ! public void setPlayers (List<String> playerNames, int startCash) { Player player; --- 45,49 ---- } ! public void setPlayers (List<String> playerNames, Bank bank) { Player player; *************** *** 56,64 **** int playerIndex = 0; for (String playerName : playerNames) { player = new Player(playerName, playerIndex++); players.add(player); playerMap.put(playerName, player); ! Bank.transferCash(null, player, getStartCash()); ReportBuffer.add(LocalText.getText("PlayerIs", playerIndex, --- 56,66 ---- int playerIndex = 0; + int startCash = getStartCash(); for (String playerName : playerNames) { player = new Player(playerName, playerIndex++); players.add(player); playerMap.put(playerName, player); ! player.addCash(startCash); ! bank.addCash(-startCash); ReportBuffer.add(LocalText.getText("PlayerIs", playerIndex, *************** *** 67,71 **** ReportBuffer.add(LocalText.getText("PlayerCash", Bank.format(startCash))); ReportBuffer.add(LocalText.getText("BankHas", ! Bank.format(Bank.getInstance().getCash()))); } --- 69,73 ---- ReportBuffer.add(LocalText.getText("PlayerCash", Bank.format(startCash))); ReportBuffer.add(LocalText.getText("BankHas", ! Bank.format(bank.getCash()))); } *************** *** 85,93 **** } ! public Player getPlayerByIndex(int index) { ! return players.get(index); ! } ! ! public int getStartCash () { return playerStartCash[numberOfPlayers]; } --- 87,91 ---- } ! protected int getStartCash () { return playerStartCash[numberOfPlayers]; } Index: Bank.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Bank.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Bank.java 3 Sep 2009 21:36:53 -0000 1.11 --- Bank.java 25 Sep 2009 19:13:01 -0000 1.12 *************** *** 17,39 **** /** The Bank's amont of cash */ ! private static CashModel money; ! ! private static int gameType; /** The IPO */ ! private static Portfolio ipo = null; /** The Bank Pool */ ! private static Portfolio pool = null; /** Collection of items that will (may) become available in the future */ ! private static Portfolio unavailable = null; /** Collection of items that have bene discarded (but are kept to allow Undo) */ ! private static Portfolio scrapHeap = null; private static Bank instance = null; /** Is the bank broken (remains true once set) */ ! private static boolean broken = false; /** Is the bank just broken (returns true exactly once) */ ! private static boolean brokenReported = false; /** --- 17,37 ---- /** The Bank's amont of cash */ ! private CashModel money; /** The IPO */ ! private Portfolio ipo = null; /** The Bank Pool */ ! private Portfolio pool = null; /** Collection of items that will (may) become available in the future */ ! private Portfolio unavailable = null; /** Collection of items that have bene discarded (but are kept to allow Undo) */ ! private Portfolio scrapHeap = null; private static Bank instance = null; /** Is the bank broken (remains true once set) */ ! private boolean broken = false; /** Is the bank just broken (returns true exactly once) */ ! private boolean brokenReported = false; /** *************** *** 41,54 **** * rest is copied. */ ! private static String moneyFormat = null; ! ! static { ! String configFormat = Config.get("money_format"); ! if (Util.hasValue(configFormat) && configFormat.matches(".*@.*")) { ! moneyFormat = configFormat; ! } ! } ! private static int poolShareLimit = DEFAULT_POOL_SHARE_LIMIT; protected static Logger log = --- 39,45 ---- * rest is copied. */ ! private String moneyFormat = null; ! private int poolShareLimit = DEFAULT_POOL_SHARE_LIMIT; protected static Logger log = *************** *** 62,84 **** } - /** - * Central method for transferring all cash. - * - * @param from Who pays the money (null = Bank). - * @param to Who received the money (null = Bank). - * @param amount The amount of money. - */ - public static boolean transferCash(CashHolder from, CashHolder to, - int amount) { - if (from == null) - from = instance; - else if (to == null) to = instance; - to.addCash(amount); - return from.addCash(-amount); - } - public Bank() { instance = this; money = new CashModel(this); // Create the IPO and the Bank Pool. --- 53,60 ---- } public Bank() { instance = this; + money = new CashModel(this); // Create the IPO and the Bank Pool. *************** *** 88,91 **** --- 64,71 ---- scrapHeap = new Portfolio("ScrapHeap", this); + String configFormat = Config.get("money_format"); + if (Util.hasValue(configFormat) && configFormat.matches(".*@.*")) { + moneyFormat = configFormat; + } } *************** *** 124,128 **** * @param percentage of a company allowed to be in the Bank pool. */ ! public static void setPoolShareLimit(int percentage) { poolShareLimit = percentage; } --- 104,108 ---- * @param percentage of a company allowed to be in the Bank pool. */ ! public void setPoolShareLimit(int percentage) { poolShareLimit = percentage; } *************** *** 154,171 **** /** - * @return Which type of rails.game we're playing (1830, 1856, 1870, etc.) - */ - public static int getGameType() { - return gameType; - } - - /** * @return IPO Portfolio */ ! public static Portfolio getIpo() { return ipo; } ! public static Portfolio getScrapHeap() { return scrapHeap; } --- 134,144 ---- /** * @return IPO Portfolio */ ! public Portfolio getIpo() { return ipo; } ! public Portfolio getScrapHeap() { return scrapHeap; } *************** *** 195,203 **** } ! public static boolean isBroken() { return broken; } ! public static boolean isJustBroken() { boolean result = broken && !brokenReported; brokenReported = true; --- 168,176 ---- } ! public boolean isBroken() { return broken; } ! public boolean isJustBroken() { boolean result = broken && !brokenReported; brokenReported = true; *************** *** 208,212 **** * @return Portfolio of stock in Bank Pool */ ! public static Portfolio getPool() { return pool; } --- 181,185 ---- * @return Portfolio of stock in Bank Pool */ ! public Portfolio getPool() { return pool; } *************** *** 215,219 **** * @return Portfolio of unavailable shares */ ! public static Portfolio getUnavailable() { return unavailable; } --- 188,192 ---- * @return Portfolio of unavailable shares */ ! public Portfolio getUnavailable() { return unavailable; } *************** *** 243,252 **** * @return The maximum percentage. */ ! public static int getPoolShareLimit() { return poolShareLimit; } public static String format(int amount) { ! return moneyFormat.replaceFirst("@", String.valueOf(amount)); } --- 216,225 ---- * @return The maximum percentage. */ ! public int getPoolShareLimit() { return poolShareLimit; } public static String format(int amount) { ! return instance.moneyFormat.replaceFirst("@", String.valueOf(amount)); } Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** GameManager.java 23 Sep 2009 21:38:57 -0000 1.53 --- GameManager.java 25 Sep 2009 19:13:01 -0000 1.54 *************** *** 228,232 **** Tag poolLimitTag = tag.getChild("BankPoolShareLimit"); if (poolLimitTag != null) { ! Bank.setPoolShareLimit(poolLimitTag.getAttributeAsInteger("percentage")); } --- 228,232 ---- Tag poolLimitTag = tag.getChild("BankPoolShareLimit"); if (poolLimitTag != null) { ! bank.setPoolShareLimit(poolLimitTag.getAttributeAsInteger("percentage")); } *************** *** 444,448 **** } else if (round instanceof OperatingRound) { ! if (Bank.isBroken() && !gameEndsAfterSetOfORs) { finishGame(); --- 444,448 ---- } else if (round instanceof OperatingRound) { ! if (bank.isBroken() && !gameEndsAfterSetOfORs) { finishGame(); *************** *** 454,458 **** startStartRound(); } else { ! if (Bank.isBroken() && gameEndsAfterSetOfORs) { finishGame(); } else { --- 454,458 ---- startStartRound(); } else { ! if (bank.isBroken() && gameEndsAfterSetOfORs) { finishGame(); } else { Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Round.java 11 Sep 2009 19:27:23 -0000 1.22 --- Round.java 25 Sep 2009 19:13:01 -0000 1.23 *************** *** 30,33 **** --- 30,38 ---- protected CompanyManagerI companyManager = null; protected PlayerManager playerManager = null; + protected Bank bank = null; + protected Portfolio ipo = null; + protected Portfolio pool = null; + protected Portfolio unavailable = null; + protected Portfolio scrapHeap = null; protected Class<? extends RoundI> roundTypeForUI = null; *************** *** 49,52 **** --- 54,62 ---- companyManager = aGameManager.getCompanyManager(); playerManager = aGameManager.getPlayerManager(); + bank = aGameManager.getBank(); + ipo = bank.getIpo(); + pool = bank.getPool(); + unavailable = bank.getUnavailable(); + scrapHeap = bank.getScrapHeap(); } *************** *** 296,300 **** if (cash > 0) { ! new CashMove(Bank.getInstance(), company, cash); ReportBuffer.add(LocalText.getText("FloatsWithCash", company.getName(), --- 306,310 ---- if (cash > 0) { ! new CashMove(bank, company, cash); ReportBuffer.add(LocalText.getText("FloatsWithCash", company.getName(), *************** *** 308,312 **** && company.canHoldOwnShares()) { List<Certificate> moving = new ArrayList<Certificate>(); ! for (Certificate ipoCert : Bank.getIpo().getCertificatesPerCompany( company.getName())) { moving.add(ipoCert); --- 318,322 ---- && company.canHoldOwnShares()) { List<Certificate> moving = new ArrayList<Certificate>(); ! for (Certificate ipoCert : ipo.getCertificatesPerCompany( company.getName())) { moving.add(ipoCert); Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Game.java 11 Sep 2009 19:27:23 -0000 1.27 --- Game.java 25 Sep 2009 19:13:01 -0000 1.28 *************** *** 150,154 **** * only be done after all XML has been processed. */ ! playerManager.setPlayers(players, playerManager.getStartCash()); gameManager.init(playerManager, companyManager, phaseManager, trainManager, stockMarket, bank); --- 150,154 ---- * only be done after all XML has been processed. */ ! playerManager.setPlayers(players, bank); gameManager.init(playerManager, companyManager, phaseManager, trainManager, stockMarket, bank); Index: Train.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Train.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Train.java 3 Jan 2009 18:24:53 -0000 1.12 --- Train.java 25 Sep 2009 19:13:01 -0000 1.13 *************** *** 29,34 **** protected BooleanState obsolete; ! protected static final Portfolio unavailable = Bank.getUnavailable(); ! protected static final Portfolio ipo = Bank.getIpo(); protected static Logger log = --- 29,34 ---- protected BooleanState obsolete; ! protected static final Portfolio unavailable = Bank.getInstance().getUnavailable(); ! protected static final Portfolio ipo = Bank.getInstance().getIpo(); protected static Logger log = *************** *** 141,145 **** public void setRusted() { ! new ObjectMove(this, holder, Bank.getScrapHeap()); } --- 141,145 ---- public void setRusted() { ! new ObjectMove(this, holder, Bank.getInstance().getScrapHeap()); } Index: ShareSellingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/ShareSellingRound.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ShareSellingRound.java 6 Sep 2009 12:27:33 -0000 1.21 --- ShareSellingRound.java 25 Sep 2009 19:13:01 -0000 1.22 *************** *** 119,123 **** /* May not sell more than the Pool can accept */ maxShareToSell = ! Math.min(maxShareToSell, Bank.getPoolShareLimit() - pool.getShare(company)); if (maxShareToSell == 0) continue; --- 119,123 ---- /* May not sell more than the Pool can accept */ maxShareToSell = ! Math.min(maxShareToSell, bank.getPoolShareLimit() - pool.getShare(company)); if (maxShareToSell == 0) continue; *************** *** 239,243 **** // The pool may not get over its limit. ! if (pool.getShare(company) + numberToSell * company.getShareUnit() > Bank.getPoolShareLimit()) { errMsg = LocalText.getText("PoolOverHoldLimit"); break; --- 239,243 ---- // The pool may not get over its limit. ! if (pool.getShare(company) + numberToSell * company.getShareUnit() > bank.getPoolShareLimit()) { errMsg = LocalText.getText("PoolOverHoldLimit"); break; Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** OperatingRound.java 23 Sep 2009 21:38:57 -0000 1.68 --- OperatingRound.java 25 Sep 2009 19:13:01 -0000 1.69 *************** *** 145,149 **** Bank.format(revenue), priv.getName())); ! new CashMove(null, recipient, revenue); } --- 145,149 ---- Bank.format(revenue), priv.getName())); ! new CashMove(bank, recipient, revenue); } *************** *** 408,412 **** if (tile != null) { if (cost > 0) ! new CashMove(operatingCompany, null, cost); operatingCompany.layTile(hex, tile, orientation, cost); --- 408,412 ---- if (tile != null) { if (cost > 0) ! new CashMove(operatingCompany, bank, cost); operatingCompany.layTile(hex, tile, orientation, cost); *************** *** 580,584 **** if (cost > 0) { ! new CashMove(operatingCompany, null, cost); ReportBuffer.add(LocalText.getText("LAYS_TOKEN_ON", companyName, --- 580,584 ---- if (cost > 0) { ! new CashMove(operatingCompany, bank, cost); ReportBuffer.add(LocalText.getText("LAYS_TOKEN_ON", companyName, *************** *** 1401,1405 **** operatingCompany.getPortfolio().getTrainOfType( exchangedTrain.getType()); ! Bank.getPool().buyTrain(oldTrain, 0); ReportBuffer.add(LocalText.getText("ExchangesTrain", companyName, --- 1401,1405 ---- operatingCompany.getPortfolio().getTrainOfType( exchangedTrain.getType()); ! pool.buyTrain(oldTrain, 0); ReportBuffer.add(LocalText.getText("ExchangesTrain", companyName, *************** *** 1424,1432 **** operatingCompany.buyTrain(train, price); ! if (oldHolder == Bank.getIpo()) { train.getType().addToBoughtFromIPO(); // Clone the train if infinitely available if (train.getType().hasInfiniteAmount()) { ! Bank.getIpo().addTrain(train.getType().cloneTrain()); } --- 1424,1432 ---- operatingCompany.buyTrain(train, price); ! if (oldHolder == ipo) { train.getType().addToBoughtFromIPO(); // Clone the train if infinitely available if (train.getType().hasInfiniteAmount()) { ! ipo.addTrain(train.getType().cloneTrain()); } *************** *** 1531,1535 **** if (action.isForced()) MoveSet.setLinkedToPrevious(); ! Bank.getPool().buyTrain(train, 0); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", companyName, --- 1531,1535 ---- if (action.isForced()) MoveSet.setLinkedToPrevious(); ! pool.buyTrain(train, 0); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", companyName, *************** *** 1744,1748 **** int amount = calculateLoanAmount (number); operatingCompany.addLoans(number); ! new CashMove (null, operatingCompany, amount); if (number == 1) { ReportBuffer.add(LocalText.getText("CompanyTakesLoan", --- 1744,1748 ---- int amount = calculateLoanAmount (number); operatingCompany.addLoans(number); ! new CashMove (bank, operatingCompany, amount); if (number == 1) { ReportBuffer.add(LocalText.getText("CompanyTakesLoan", *************** *** 1854,1858 **** if (president.getCash() >= remainder) { payment = remainder; ! new CashMove (president, null, payment); ReportBuffer.add (LocalText.getText("CompanyRepaysLoansWithPresCash", operatingCompany.getName(), --- 1854,1858 ---- if (president.getCash() >= remainder) { payment = remainder; ! new CashMove (president, bank, payment); ReportBuffer.add (LocalText.getText("CompanyRepaysLoansWithPresCash", operatingCompany.getName(), *************** *** 2071,2076 **** TrainI cheapestTrain = null; int costOfCheapestTrain = 0; - Portfolio ipo = Bank.getIpo(); - Portfolio pool = Bank.getPool(); // First check if any more trains may be bought from the Bank --- 2071,2074 ---- *************** *** 2265,2269 **** int amount = operatingCompany.getCurrentLoanValue() * operatingCompany.getLoanInterestPct() / 100; ! new CashMove (operatingCompany, null, amount); DisplayBuffer.add(LocalText.getText("CompanyPaysLoanInterest", operatingCompany.getName(), --- 2263,2267 ---- int amount = operatingCompany.getCurrentLoanValue() * operatingCompany.getLoanInterestPct() / 100; ! new CashMove (operatingCompany, bank, amount); DisplayBuffer.add(LocalText.getText("CompanyPaysLoanInterest", operatingCompany.getName(), Index: BonusToken.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/BonusToken.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** BonusToken.java 23 Sep 2009 21:38:57 -0000 1.10 --- BonusToken.java 25 Sep 2009 19:13:01 -0000 1.11 *************** *** 63,67 **** public void close() { ! new ObjectMove(this, holder, Bank.getScrapHeap()); user.removeBonus(name); } --- 63,67 ---- public void close() { ! new ObjectMove(this, holder, Bank.getInstance().getScrapHeap()); user.removeBonus(name); } Index: Station.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Station.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Station.java 4 Jun 2008 19:00:31 -0000 1.10 --- Station.java 25 Sep 2009 19:13:01 -0000 1.11 *************** *** 7,12 **** import org.apache.log4j.Logger; - import rails.util.Util; - /** * A Station object represents any junction on a tile, where one, two or more --- 7,10 ---- *************** *** 21,25 **** * a normal upgrade in this program. <p> See also the City class, which * represents stations on tiles that have actually been laid on a MapHex. ! * * @author Erik Vos */ --- 19,23 ---- * a normal upgrade in this program. <p> See also the City class, which * represents stations on tiles that have actually been laid on a MapHex. ! * * @author Erik Vos */ *************** *** 70,74 **** public String getName() { ! return "Station " + id + " on " + Util.getClassShortName(tile) + " " + tile.getName(); } --- 68,72 ---- public String getName() { ! return "Station " + id + " on " + tile.getClass().getSimpleName() + " " + tile.getName(); } Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** StockRound.java 6 Sep 2009 12:27:32 -0000 1.42 --- StockRound.java 25 Sep 2009 19:13:01 -0000 1.43 *************** *** 51,57 **** /* Permanent memory */ static protected StockMarketI stockMarket; - static protected Portfolio ipo; - static protected Portfolio pool; - static protected Portfolio unavailable; /* Rules */ --- 51,54 ---- *************** *** 73,79 **** numberOfPlayers = gameManager.getPlayers().size(); if (stockMarket == null) stockMarket = StockMarket.getInstance(); - if (ipo == null) ipo = Bank.getIpo(); - if (pool == null) pool = Bank.getPool(); - if (unavailable == null) unavailable = Bank.getUnavailable(); sequenceRule = gameManager.getStockRoundSequenceRule(); --- 70,73 ---- *************** *** 304,308 **** /* May not sell more than the Pool can accept */ maxShareToSell = ! Math.min(maxShareToSell, Bank.getPoolShareLimit() - pool.getShare(company)); if (maxShareToSell == 0) continue; --- 298,302 ---- /* May not sell more than the Pool can accept */ maxShareToSell = ! Math.min(maxShareToSell, bank.getPoolShareLimit() - pool.getShare(company)); if (maxShareToSell == 0) continue; *************** *** 795,799 **** if (cert instanceof PublicCertificateI && (comp = ((PublicCertificateI) cert).getCompany()).hasFloated() ! && oldHolder == Bank.getIpo() && comp.getCapitalisation() == PublicCompanyI.CAPITALISE_INCREMENTAL) { recipient = comp; --- 789,793 ---- if (cert instanceof PublicCertificateI && (comp = ((PublicCertificateI) cert).getCompany()).hasFloated() ! && oldHolder == ipo && comp.getCapitalisation() == PublicCompanyI.CAPITALISE_INCREMENTAL) { recipient = comp; *************** *** 880,884 **** // The pool may not get over its limit. ! if (pool.getShare(company) + numberToSell * company.getShareUnit() > Bank.getPoolShareLimit()) { errMsg = LocalText.getText("PoolOverHoldLimit"); break; --- 874,878 ---- // The pool may not get over its limit. ! if (pool.getShare(company) + numberToSell * company.getShareUnit() > bank.getPoolShareLimit()) { errMsg = LocalText.getText("PoolOverHoldLimit"); break; Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Portfolio.java 23 Sep 2009 21:38:57 -0000 1.35 --- Portfolio.java 25 Sep 2009 19:13:01 -0000 1.36 *************** *** 398,402 **** public void discardTrain(TrainI train) { ! train.moveTo(Bank.getPool()); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", name, train.getName() )); --- 398,402 ---- public void discardTrain(TrainI train) { ! train.moveTo(Bank.getInstance().getPool()); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", name, train.getName() )); *************** *** 586,590 **** for (SpecialPropertyI sp : sps) { ! if ((clazz == null || Util.isInstanceOf(sp, clazz)) && sp.isExecutionable() && (!sp.isExercised() || includeExercised) --- 586,590 ---- for (SpecialPropertyI sp : sps) { ! if ((clazz == null || clazz.isAssignableFrom(sp.getClass())) && sp.isExecutionable() && (!sp.isExercised() || includeExercised) *************** *** 600,604 **** if (specialProperties != null) { for (SpecialPropertyI sp : specialProperties) { ! if ((clazz == null || Util.isInstanceOf(sp, clazz)) && sp.isExecutionable() && (!sp.isExercised() || includeExercised) --- 600,604 ---- if (specialProperties != null) { for (SpecialPropertyI sp : specialProperties) { ! if ((clazz == null || clazz.isAssignableFrom(sp.getClass())) && sp.isExecutionable() && (!sp.isExercised() || includeExercised) Index: TrainType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainType.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** TrainType.java 4 May 2009 20:29:14 -0000 1.21 --- TrainType.java 25 Sep 2009 19:13:01 -0000 1.22 *************** *** 398,410 **** * Make a train type available for buying by public companies. */ ! public void setAvailable() { available.set(true); Portfolio to = ! (initialPortfolio.equalsIgnoreCase("Pool") ? Bank.getPool() ! : Bank.getIpo()); for (TrainI train : trains) { ! new ObjectMove(train, Bank.getUnavailable(), to); } } --- 398,410 ---- * Make a train type available for buying by public companies. */ ! public void setAvailable(Bank bank) { available.set(true); Portfolio to = ! (initialPortfolio.equalsIgnoreCase("Pool") ? bank.getPool() ! : bank.getIpo()); for (TrainI train : trains) { ! new ObjectMove(train, bank.getUnavailable(), to); } } |