You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(46) |
Dec
(57) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(51) |
Feb
(10) |
Mar
|
Apr
|
May
(14) |
Jun
|
Jul
(13) |
Aug
(30) |
Sep
(83) |
Oct
(56) |
Nov
(148) |
Dec
(107) |
2010 |
Jan
(260) |
Feb
(164) |
Mar
(183) |
Apr
(99) |
May
(160) |
Jun
(40) |
Jul
(33) |
Aug
(48) |
Sep
(22) |
Oct
(24) |
Nov
(1) |
Dec
(12) |
2011 |
Jan
(6) |
Feb
(15) |
Mar
(13) |
Apr
(37) |
May
(27) |
Jun
(29) |
Jul
(33) |
Aug
(20) |
Sep
(17) |
Oct
(20) |
Nov
(33) |
Dec
(17) |
2012 |
Jan
(39) |
Feb
(38) |
Mar
(20) |
Apr
(21) |
May
(17) |
Jun
(22) |
Jul
(16) |
Aug
(3) |
Sep
(9) |
Oct
(10) |
Nov
|
Dec
|
From: Erik V. <ev...@us...> - 2009-09-25 19:13:16
|
Update of /cvsroot/rails/18xx/rails/game/state In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/game/state Modified Files: State.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: State.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/state/State.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** State.java 23 Sep 2009 21:38:57 -0000 1.10 --- State.java 25 Sep 2009 19:13:01 -0000 1.11 *************** *** 6,10 **** import rails.game.model.ModelObject; import rails.game.move.StateChange; - import rails.util.Util; public class State extends ModelObject implements StateI { --- 6,9 ---- *************** *** 30,34 **** if (object == null) { new Exception("NULL object not allowed in creating State wrapper").printStackTrace(); ! } else if (clazz != null && Util.isInstanceOf(object, clazz)) { new Exception("Object " + object + " must be instance of " + clazz).printStackTrace(); } else { --- 29,33 ---- if (object == null) { new Exception("NULL object not allowed in creating State wrapper").printStackTrace(); ! } else if (clazz != null && clazz.isAssignableFrom(object.getClass())) { new Exception("Object " + object + " must be instance of " + clazz).printStackTrace(); } else { *************** *** 41,45 **** if (object == null) { if (this.object != null) new StateChange(this, object); ! } else if (Util.isInstanceOf(object, clazz)) { if (!object.equals(this.object) || forced) new StateChange(this, object); --- 40,45 ---- if (object == null) { if (this.object != null) new StateChange(this, object); ! //} else if (Util.isInstanceOf(object, clazz)) { ! } else if (clazz.isAssignableFrom(object.getClass())) { if (!object.equals(this.object) || forced) new StateChange(this, object); |
From: Erik V. <ev...@us...> - 2009-09-25 19:13:16
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/game/specific/_18EU Modified Files: OperatingRound_18EU.java StockRound_18EU.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: StockRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/StockRound_18EU.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** StockRound_18EU.java 4 Sep 2009 18:56:16 -0000 1.23 --- StockRound_18EU.java 25 Sep 2009 19:13:01 -0000 1.24 *************** *** 104,108 **** (PublicCompanyI) companyBoughtThisTurnWrapper.getObject(); if (companyBoughtThisTurn == null) { ! from = Bank.getIpo(); Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); --- 104,108 ---- (PublicCompanyI) companyBoughtThisTurnWrapper.getObject(); if (companyBoughtThisTurn == null) { ! from = ipo; Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); *************** *** 157,161 **** /* Get the unique Pool certificates and check which ones can be bought */ ! from = Bank.getPool(); Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); --- 157,161 ---- /* Get the unique Pool certificates and check which ones can be bought */ ! from = pool; Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); *************** *** 385,389 **** homeCityNumber = homeHex.getCityOfBaseToken(minor); } else if (selectedHomeCity != null) { ! homeHex = (MapHex) selectedHomeCity.getHolder(); homeCityNumber = selectedHomeCity.getNumber(); } --- 385,389 ---- homeCityNumber = homeHex.getCityOfBaseToken(minor); } else if (selectedHomeCity != null) { ! homeHex = selectedHomeCity.getHolder(); homeCityNumber = selectedHomeCity.getNumber(); } *************** *** 443,447 **** // TODO must get this amount from XML int tokensCost = 100; ! new CashMove(company, null, tokensCost); ReportBuffer.add(LocalText.getText("PaysForTokens", company.getName(), --- 443,447 ---- // TODO must get this amount from XML int tokensCost = 100; ! new CashMove(company, bank, tokensCost); ReportBuffer.add(LocalText.getText("PaysForTokens", company.getName(), *************** *** 511,515 **** if (cashDestination == null) { // Assets go to the bank ! if (minorCash > 0) new CashMove(minor, null, minorCash); pool.transferAssetsFrom(minor.getPortfolio()); } else { --- 511,515 ---- if (cashDestination == null) { // Assets go to the bank ! if (minorCash > 0) new CashMove(minor, bank, minorCash); pool.transferAssetsFrom(minor.getPortfolio()); } else { *************** *** 585,589 **** company.getName()), pool); int cash = 5 * company.getMarketPrice(); ! new CashMove(null, company, cash); ReportBuffer.add(LocalText.getText("MonetiseTreasuryShares", company.getName(), --- 585,589 ---- company.getName()), pool); int cash = 5 * company.getMarketPrice(); ! new CashMove(bank, company, cash); ReportBuffer.add(LocalText.getText("MonetiseTreasuryShares", company.getName(), *************** *** 640,644 **** if (action.isForced()) MoveSet.setLinkedToPrevious(); ! Bank.getPool().buyTrain(train, 0); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", companyName, --- 640,644 ---- if (action.isForced()) MoveSet.setLinkedToPrevious(); ! pool.buyTrain(train, 0); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", companyName, Index: OperatingRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OperatingRound_18EU.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** OperatingRound_18EU.java 24 Jan 2009 15:10:29 -0000 1.6 --- OperatingRound_18EU.java 25 Sep 2009 19:13:01 -0000 1.7 *************** *** 58,63 **** TrainI cheapestTrain = null; int costOfCheapestTrain = 0; - Portfolio ipo = Bank.getIpo(); - Portfolio pool = Bank.getPool(); // Check if the company already has a Pullmann --- 58,61 ---- *************** *** 210,214 **** if ((numberOfTrains > comp.getTrainLimit(currentPhase.getIndex()) || numberOfTrains == 1) && pullmann != null) { ! pullmann.moveTo(Bank.getPool()); } --- 208,212 ---- if ((numberOfTrains > comp.getTrainLimit(currentPhase.getIndex()) || numberOfTrains == 1) && pullmann != null) { ! pullmann.moveTo(pool); } |
From: Erik V. <ev...@us...> - 2009-09-25 19:13:15
|
Update of /cvsroot/rails/18xx/rails/util In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/util Modified Files: Util.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: Util.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/util/Util.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Util.java 30 Jun 2008 20:35:30 -0000 1.14 --- Util.java 25 Sep 2009 19:13:01 -0000 1.15 *************** *** 30,47 **** } - /** Check if an object is an instance of a class - at runtime! */ - public static boolean isInstanceOf(Object o, Class<?> clazz) { - Class<?> c = o.getClass(); - while (c != null) { - if (c == clazz) return true; - c = c.getSuperclass(); - } - return false; - } - - public static String getClassShortName(Object object) { - return object.getClass().getName().replaceAll(".*\\.", ""); - } - public static int parseInt(String value) throws ConfigurationException { --- 30,33 ---- *************** *** 75,79 **** * Safely move objects from one holder to another, avoiding * ConcurrentModificationExceptions. ! * * @param from * @param to --- 61,65 ---- * Safely move objects from one holder to another, avoiding * ConcurrentModificationExceptions. ! * * @param from * @param to |
From: Erik V. <ev...@us...> - 2009-09-25 19:13:14
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/game/specific/_1856 Modified Files: CGRFormationRound.java PublicCompany_CGR.java StockRound_1856.java OperatingRound_1856.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: StockRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/StockRound_1856.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** StockRound_1856.java 15 Jan 2009 20:53:28 -0000 1.8 --- StockRound_1856.java 25 Sep 2009 19:13:01 -0000 1.9 *************** *** 54,58 **** if (price != 0 && cert instanceof PublicCertificateI ! && oldHolder == Bank.getIpo()) { PublicCompany_1856 comp = (PublicCompany_1856)((PublicCertificateI) cert).getCompany(); --- 54,58 ---- if (price != 0 && cert instanceof PublicCertificateI ! && oldHolder == ipo) { PublicCompany_1856 comp = (PublicCompany_1856)((PublicCertificateI) cert).getCompany(); Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CGRFormationRound.java 23 Sep 2009 21:38:57 -0000 1.16 --- CGRFormationRound.java 25 Sep 2009 19:13:01 -0000 1.17 *************** *** 142,146 **** payment = numberToRepay * valuePerLoan; ! new CashMove (currentCompany, null, payment); currentCompany.addLoans(-numberToRepay); --- 142,146 ---- payment = numberToRepay * valuePerLoan; ! new CashMove (currentCompany, bank, payment); currentCompany.addLoans(-numberToRepay); *************** *** 238,242 **** company.addLoans(-numberRepaid); if (repaymentByCompany > 0) { ! new CashMove (company, null, repaymentByCompany); ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", company.getName(), --- 238,242 ---- company.addLoans(-numberRepaid); if (repaymentByCompany > 0) { ! new CashMove (company, bank, repaymentByCompany); ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", company.getName(), *************** *** 248,252 **** if (repaymentByPresident > 0) { Player president = company.getPresident(); ! new CashMove (president, null, repaymentByPresident); ReportBuffer.add (LocalText.getText("CompanyRepaysLoansWithPresCash", company.getName(), --- 248,252 ---- if (repaymentByPresident > 0) { Player president = company.getPresident(); ! new CashMove (president, bank, repaymentByPresident); ReportBuffer.add (LocalText.getText("CompanyRepaysLoansWithPresCash", company.getName(), *************** *** 280,287 **** PublicCertificateI cgrCert, poolCert; List<PublicCertificateI> certs = new ArrayList<PublicCertificateI>(); - Portfolio scrapHeap = Bank.getScrapHeap(); - Portfolio pool = Bank.getPool(); - Portfolio unavailable = Bank.getUnavailable(); - Portfolio ipo = Bank.getIpo(); Player temporaryPresident = null; Player newPresident = null; --- 280,283 ---- *************** *** 775,779 **** if (action.isForced()) MoveSet.setLinkedToPrevious(); ! train.moveTo(Bank.getPool()); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", companyName, --- 771,775 ---- if (action.isForced()) MoveSet.setLinkedToPrevious(); ! train.moveTo(pool); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", companyName, Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** OperatingRound_1856.java 12 Sep 2009 09:40:56 -0000 1.21 --- OperatingRound_1856.java 25 Sep 2009 19:13:01 -0000 1.22 *************** *** 66,72 **** // This check does not apply to the CGR if (operatingCompany instanceof PublicCompany_CGR) return true; ! if (operatingCompany.isClosed()) continue; ! if (!operatingCompany.hasOperated()) { int soldPercentage --- 66,72 ---- // This check does not apply to the CGR if (operatingCompany instanceof PublicCompany_CGR) return true; ! if (operatingCompany.isClosed()) continue; ! if (!operatingCompany.hasOperated()) { int soldPercentage *************** *** 218,222 **** int payment = Math.min(due, (operatingCompany.getCash() / 10) * 10); if (payment > 0) { ! new CashMove (operatingCompany, null, payment); if (payment == due) { ReportBuffer.add (LocalText.getText("InterestPaidFromTreasury", --- 218,222 ---- int payment = Math.min(due, (operatingCompany.getCash() / 10) * 10); if (payment > 0) { ! new CashMove (operatingCompany, bank, payment); if (payment == due) { ReportBuffer.add (LocalText.getText("InterestPaidFromTreasury", *************** *** 260,264 **** payment = remainder; ! new CashMove (president, null, payment); ReportBuffer.add (LocalText.getText("InterestPaidFromPresidentCash", operatingCompany.getName(), --- 260,264 ---- payment = remainder; ! new CashMove (president, bank, payment); ReportBuffer.add (LocalText.getText("InterestPaidFromPresidentCash", operatingCompany.getName(), *************** *** 293,297 **** int cashInEscrow = comp.getMoneyInEscrow(); if (cashInEscrow > 0) { ! new CashMove (null, company, cashInEscrow); ReportBuffer.add(LocalText.getText("ReleasedFromEscrow", company.getName(), --- 293,297 ---- int cashInEscrow = comp.getMoneyInEscrow(); if (cashInEscrow > 0) { ! new CashMove (bank, company, cashInEscrow); ReportBuffer.add(LocalText.getText("ReleasedFromEscrow", company.getName(), Index: PublicCompany_CGR.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_CGR.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PublicCompany_CGR.java 6 Sep 2009 12:27:31 -0000 1.2 --- PublicCompany_CGR.java 25 Sep 2009 19:13:01 -0000 1.3 *************** *** 15,19 **** /** Special rules apply before CGR has got its first permanent train */ private BooleanState hadPermanentTrain; ! /* Cope with multiple 5% share sales in one turn */ private IntegerState sharesSoldSoFar; --- 15,19 ---- /** Special rules apply before CGR has got its first permanent train */ private BooleanState hadPermanentTrain; ! /* Cope with multiple 5% share sales in one turn */ private IntegerState sharesSoldSoFar; *************** *** 61,65 **** @Override public void withhold(int amount) { ! if (amount > 0) new CashMove(null, this, amount); if (hasStockPrice && !runsWithBorrowedTrain()) { Game.getStockMarket().withhold(this); --- 61,65 ---- @Override public void withhold(int amount) { ! if (amount > 0) new CashMove(bank, this, amount); if (hasStockPrice && !runsWithBorrowedTrain()) { Game.getStockMarket().withhold(this); *************** *** 81,85 **** List<PublicCertificateI>certs = new ArrayList<PublicCertificateI>(certificates); int share = 0; ! MoveableHolderI scrapHeap = Bank.getScrapHeap(); for (PublicCertificateI cert : certs) { if (share >= 100) { --- 81,85 ---- List<PublicCertificateI>certs = new ArrayList<PublicCertificateI>(certificates); int share = 0; ! MoveableHolderI scrapHeap = bank.getScrapHeap(); for (PublicCertificateI cert : certs) { if (share >= 100) { *************** *** 107,120 **** } ! public void adjustSharePrice (int actionPerformed, int numberOfSharesSold, StockMarketI stockMarket) { ! if (actionPerformed == StockRound.SOLD) { if (canSharePriceVary()) { int numberOfSpaces; if (shareUnit.intValue() == 5) { ! // Take care for selling 5% shares in multiple blocks per turn ! numberOfSpaces ! = (sharesSoldSoFar.intValue() + numberOfSharesSold)/2 - squaresDownSoFar.intValue(); sharesSoldSoFar.add(numberOfSharesSold); --- 107,121 ---- } ! @Override ! public void adjustSharePrice (int actionPerformed, int numberOfSharesSold, StockMarketI stockMarket) { ! if (actionPerformed == StockRound.SOLD) { if (canSharePriceVary()) { int numberOfSpaces; if (shareUnit.intValue() == 5) { ! // Take care for selling 5% shares in multiple blocks per turn ! numberOfSpaces ! = (sharesSoldSoFar.intValue() + numberOfSharesSold)/2 - squaresDownSoFar.intValue(); sharesSoldSoFar.add(numberOfSharesSold); *************** *** 127,134 **** } } ! ! public void setOperated() { super.setOperated(); ! // Reset the share selling counts // TODO Should this be a generic function? --- 128,136 ---- } } ! ! @Override ! public void setOperated() { super.setOperated(); ! // Reset the share selling counts // TODO Should this be a generic function? |
From: Erik V. <ev...@us...> - 2009-09-25 19:13:11
|
Update of /cvsroot/rails/18xx/rails/game/action In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/game/action Modified Files: PossibleActions.java StartCompany.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: PossibleActions.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/PossibleActions.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PossibleActions.java 4 Jun 2008 19:00:29 -0000 1.13 --- PossibleActions.java 25 Sep 2009 19:13:01 -0000 1.14 *************** *** 11,16 **** import org.apache.log4j.Logger; - import rails.util.Util; - /** * This class manages the actions that the current user can execute at any point --- 11,14 ---- *************** *** 20,24 **** * instances lingering around, as there can only be one set of possible actions * at any point in time. ! * * @author Erik Vos */ --- 18,22 ---- * instances lingering around, as there can only be one set of possible actions * at any point in time. ! * * @author Erik Vos */ *************** *** 64,68 **** public boolean contains(Class<? extends PossibleAction> clazz) { for (PossibleAction action : possibleActions) { ! if (Util.isInstanceOf(action, clazz)) return true; } return false; --- 62,66 ---- public boolean contains(Class<? extends PossibleAction> clazz) { for (PossibleAction action : possibleActions) { ! if (clazz.isAssignableFrom(action.getClass())) return true; } return false; *************** *** 73,77 **** List<T> result = new ArrayList<T>(); for (PossibleAction action : possibleActions) { ! if (Util.isInstanceOf(action, clazz)) result.add((T) action); } return result; --- 71,75 ---- List<T> result = new ArrayList<T>(); for (PossibleAction action : possibleActions) { ! if (clazz.isAssignableFrom(action.getClass())) result.add((T) action); } return result; Index: StartCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/StartCompany.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** StartCompany.java 30 Oct 2008 21:48:20 -0000 1.7 --- StartCompany.java 25 Sep 2009 19:13:01 -0000 1.8 *************** *** 13,17 **** public StartCompany(PublicCertificateI certificate, int[] prices, int maximumNumber) { ! super(certificate, Bank.getIpo(), 0, maximumNumber); this.startPrices = prices.clone(); } --- 13,17 ---- public StartCompany(PublicCertificateI certificate, int[] prices, int maximumNumber) { ! super(certificate, Bank.getInstance().getIpo(), 0, maximumNumber); this.startPrices = prices.clone(); } *************** *** 23,27 **** public StartCompany(PublicCertificateI certificate, int price, int maximumNumber) { ! super(certificate, Bank.getIpo(), 0, maximumNumber); this.price = price; } --- 23,27 ---- public StartCompany(PublicCertificateI certificate, int price, int maximumNumber) { ! super(certificate, Bank.getInstance().getIpo(), 0, maximumNumber); this.price = price; } |
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); } } |
From: Erik V. <ev...@us...> - 2009-09-25 19:13:11
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5549/rails/ui/swing Modified Files: GameStatus.java GameUIManager.java Log Message: Rationalised Bank, removing statics Removed two unnecessary Util methods Index: GameStatus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameStatus.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** GameStatus.java 12 Sep 2009 19:48:39 -0000 1.27 --- GameStatus.java 25 Sep 2009 19:13:01 -0000 1.28 *************** *** 103,106 **** --- 103,107 ---- protected GameUIManager gameUIManager; + protected Bank bank; protected PossibleActions possibleActions = PossibleActions.getInstance(); *************** *** 139,142 **** --- 140,144 ---- this.parent = parent; this.gameUIManager = gameUIManager; + bank = gameUIManager.getGameManager().getBank(); gb = new GridBagLayout(); *************** *** 160,165 **** hasCompanyLoans = gameUIManager.getGameParameterAsBoolean(Defs.Parm.HAS_ANY_COMPANY_LOANS); ! ipo = Bank.getIpo(); ! pool = Bank.getPool(); certPerPlayer = new Field[nc][np]; --- 162,167 ---- hasCompanyLoans = gameUIManager.getGameParameterAsBoolean(Defs.Parm.HAS_ANY_COMPANY_LOANS); ! ipo = bank.getIpo(); ! pool = bank.getPool(); certPerPlayer = new Field[nc][np]; *************** *** 326,330 **** 1, 1, 0); } ! f = certInIPO[i] = new Field(Bank.getIpo().getShareModel(c)); addField(f, certInIPOXOffset, certInIPOYOffset + i, 1, 1, WIDE_LEFT); f = --- 328,332 ---- 1, 1, 0); } ! f = certInIPO[i] = new Field(ipo.getShareModel(c)); addField(f, certInIPOXOffset, certInIPOYOffset + i, 1, 1, WIDE_LEFT); f = *************** *** 339,343 **** certInIPO[i].setPreferredSize(certInIPOButton[i].getPreferredSize()); ! f = certInPool[i] = new Field(Bank.getPool().getShareModel(c)); addField(f, certInPoolXOffset, certInPoolYOffset + i, 1, 1, WIDE_RIGHT); --- 341,345 ---- certInIPO[i].setPreferredSize(certInIPOButton[i].getPreferredSize()); ! f = certInPool[i] = new Field(pool.getShareModel(c)); addField(f, certInPoolXOffset, certInPoolYOffset + i, 1, 1, WIDE_RIGHT); *************** *** 475,479 **** addField(new Caption(LocalText.getText("CASH")), bankCashXOffset, bankCashYOffset - 1, 1, 1, WIDE_TOP); ! bankCash = new Field(Bank.getInstance().getCashModel()); addField(bankCash, bankCashXOffset, bankCashYOffset, 1, 1, 0); --- 477,481 ---- addField(new Caption(LocalText.getText("CASH")), bankCashXOffset, bankCashYOffset - 1, 1, 1, WIDE_TOP); ! bankCash = new Field(bank.getCashModel()); addField(bankCash, bankCashXOffset, bankCashYOffset, 1, 1, 0); *************** *** 484,488 **** addField(new Caption(LocalText.getText("USED")), poolTrainsXOffset, poolTrainsYOffset - 1, 1, 1, WIDE_TOP); ! poolTrains = new Field(Bank.getPool().getTrainsModel()); addField(poolTrains, poolTrainsXOffset, poolTrainsYOffset, 1, 1, 0); --- 486,490 ---- addField(new Caption(LocalText.getText("USED")), poolTrainsXOffset, poolTrainsYOffset - 1, 1, 1, WIDE_TOP); ! poolTrains = new Field(pool.getTrainsModel()); addField(poolTrains, poolTrainsXOffset, poolTrainsYOffset, 1, 1, 0); *************** *** 490,494 **** addField(new Caption(LocalText.getText("NEW")), newTrainsXOffset, newTrainsYOffset - 1, 1, 1, WIDE_TOP); ! newTrains = new Field(Bank.getIpo().getTrainsModel()); addField(newTrains, newTrainsXOffset, newTrainsYOffset, 1, 1, 0); --- 492,496 ---- addField(new Caption(LocalText.getText("NEW")), newTrainsXOffset, newTrainsYOffset - 1, 1, 1, WIDE_TOP); ! newTrains = new Field(ipo.getTrainsModel()); addField(newTrains, newTrainsXOffset, newTrainsYOffset, 1, 1, 0); *************** *** 498,502 **** addField(new Caption(LocalText.getText("Future")), futureTrainsXOffset, futureTrainsYOffset - 1, futureTrainsWidth, 1, WIDE_TOP); ! futureTrains = new Field(Bank.getUnavailable().getTrainsModel()); addField(futureTrains, futureTrainsXOffset, futureTrainsYOffset, futureTrainsWidth, 1, 0); --- 500,504 ---- addField(new Caption(LocalText.getText("Future")), futureTrainsXOffset, futureTrainsYOffset - 1, futureTrainsWidth, 1, WIDE_TOP); ! futureTrains = new Field(bank.getUnavailable().getTrainsModel()); addField(futureTrains, futureTrainsXOffset, futureTrainsYOffset, futureTrainsWidth, 1, 0); Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** GameUIManager.java 12 Sep 2009 19:48:39 -0000 1.18 --- GameUIManager.java 25 Sep 2009 19:13:01 -0000 1.19 *************** *** 137,141 **** return true; ! } else if (Bank.isJustBroken()) { statusWindow.reportBankBroken(); --- 137,141 ---- return true; ! } else if (gameManager.getBank().isJustBroken()) { statusWindow.reportBankBroken(); |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:16
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18AL In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/specific/_18AL Modified Files: NameTrains.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: NameTrains.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18AL/NameTrains.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NameTrains.java 4 Jun 2008 19:00:36 -0000 1.2 --- NameTrains.java 23 Sep 2009 21:38:57 -0000 1.3 *************** *** 5,12 **** import rails.game.ConfigurationException; - import rails.game.Portfolio; import rails.game.move.Moveable; - import rails.game.move.MoveableHolderI; - import rails.game.move.ObjectMove; import rails.game.special.SpecialProperty; import rails.util.Tag; --- 5,9 ---- *************** *** 20,24 **** private String description; ! public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); --- 17,22 ---- private String description; ! @Override ! public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); *************** *** 82,101 **** public void setExercised() {} - @Override - public void moveTo(MoveableHolderI newHolder) { - if (newHolder instanceof Portfolio) { - new ObjectMove(this, privateCompany, newHolder); - } - } - public String getName() { return name; } ! public String toMenu() { return description; } ! public String toString() { return description; } --- 80,94 ---- public void setExercised() {} public String getName() { return name; } ! @Override ! public String toMenu() { return description; } ! @Override ! public String toString() { return description; } |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:16
|
Update of /cvsroot/rails/18xx/rails/game/special In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/special Modified Files: SpecialProperty.java SpecialTokenLay.java Added Files: SellBonusToken.java LocatedBonus.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: SpecialTokenLay.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/special/SpecialTokenLay.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SpecialTokenLay.java 4 Jun 2008 19:00:38 -0000 1.9 --- SpecialTokenLay.java 23 Sep 2009 21:38:57 -0000 1.10 *************** *** 20,24 **** int numberUsed = 0; ! public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); --- 20,25 ---- int numberUsed = 0; ! @Override ! public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); *************** *** 89,101 **** } - /** @deprecated */ - public MapHex getLocation() { - if (locations != null) { - return locations.get(0); - } else { - return null; - } - } - public List<MapHex> getLocations() { return locations; --- 90,93 ---- *************** *** 118,122 **** } ! public String toString() { return "SpecialTokenLay comp=" + privateCompany.getName() + " type=" + tokenClass.getSimpleName() + ": " --- 110,115 ---- } ! @Override ! public String toString() { return "SpecialTokenLay comp=" + privateCompany.getName() + " type=" + tokenClass.getSimpleName() + ": " Index: SpecialProperty.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/special/SpecialProperty.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** SpecialProperty.java 26 Oct 2008 20:39:16 -0000 1.13 --- SpecialProperty.java 23 Sep 2009 21:38:57 -0000 1.14 *************** *** 5,10 **** import java.util.Map; ! import rails.game.*; import rails.game.move.MoveableHolderI; import rails.game.state.BooleanState; import rails.util.Tag; --- 5,12 ---- import java.util.Map; ! import rails.game.ConfigurationException; ! import rails.game.PrivateCompanyI; import rails.game.move.MoveableHolderI; + import rails.game.move.ObjectMove; import rails.game.state.BooleanState; import rails.util.Tag; *************** *** 14,17 **** --- 16,20 ---- protected PrivateCompanyI privateCompany; + protected MoveableHolderI holder = null; protected int closingValue = 0; protected BooleanState exercised; *************** *** 67,71 **** public void setCompany(PrivateCompanyI company) { ! this.privateCompany = company; exercised = new BooleanState(company.getName() + "_SP_" + uniqueId --- 70,75 ---- public void setCompany(PrivateCompanyI company) { ! privateCompany = company; ! holder = company; exercised = new BooleanState(company.getName() + "_SP_" + uniqueId *************** *** 78,82 **** public MoveableHolderI getHolder() { ! return null; } --- 82,86 ---- public MoveableHolderI getHolder() { ! return holder; } *************** *** 135,144 **** /** ! * Stub for moving the special property to another holder. Must be ! * overridden by subsclasses that actually can be moved. */ ! public void moveTo(MoveableHolderI newHolder) {} ! public String toString() { return getClass().getSimpleName() + " of private " + privateCompany.getName(); --- 139,154 ---- /** ! * Move the special property to another holder. ! * Only to be used for special properties that have the "transfer" attribute. */ ! public void moveTo(MoveableHolderI newHolder) { ! if (transferText.equals("")) return; ! //if (newHolder instanceof Portfolio) { ! new ObjectMove(this, holder, newHolder); ! //} ! } ! @Override ! public String toString() { return getClass().getSimpleName() + " of private " + privateCompany.getName(); --- NEW FILE: LocatedBonus.java --- /* $Header: /cvsroot/rails/18xx/rails/game/special/LocatedBonus.java,v 1.1 2009/09/23 21:38:57 evos Exp $ */ package rails.game.special; import java.util.ArrayList; import java.util.List; import rails.game.*; import rails.util.Tag; import rails.util.Util; /** * An object of class LocatedBonus represent extra income for the owning company, * usually connected to certain map locations. * <p>LocatedBonus objects are configured as Special Properties in CompanyManager.xml. * @author VosE * */ public class LocatedBonus extends SpecialProperty { String locationCodes = null; List<MapHex> locations = null; String name; int value; @Override public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); Tag bonusTag = tag.getChild("LocatedBonus"); if (bonusTag == null) { throw new ConfigurationException("<LocatedBonus> tag missing"); } locationCodes = bonusTag.getAttributeAsString("location"); if (!Util.hasValue(locationCodes)) throw new ConfigurationException("LocatedBonus: location missing"); parseLocations (); name = bonusTag.getAttributeAsString("name"); value = bonusTag.getAttributeAsInteger("value"); if (value <= 0) throw new ConfigurationException("Value invalid ["+value+"] or missing"); } public boolean isExecutionable() { return false; } public List<MapHex> getLocations() { return locations; } public String getLocationNameString() { return locationCodes; } public String getName() { return name; } public int getValue() { return value; } private void parseLocations () throws ConfigurationException { MapManager mmgr = MapManager.getInstance(); MapHex hex; locations = new ArrayList<MapHex>(); for (String hexName : locationCodes.split(",")) { hex = mmgr.getHex(hexName); if (hex == null) throw new ConfigurationException("Location " + hexName + " does not exist"); locations.add(hex); } } @Override public String toString() { return "LocatedBonus "+name+" comp=" + privateCompany.getName() + " hex=" + locationCodes + " value=" + value; } } --- NEW FILE: SellBonusToken.java --- /* $Header: /cvsroot/rails/18xx/rails/game/special/SellBonusToken.java,v 1.1 2009/09/23 21:38:57 evos Exp $ */ package rails.game.special; import java.util.ArrayList; import java.util.List; import rails.game.*; import rails.game.state.State; import rails.util.Tag; import rails.util.Util; public class SellBonusToken extends SpecialProperty { private String locationCodes = null; private List<MapHex> locations = null; //private PublicCompanyI seller = null; private State seller = null; private String name; private int price; private int value; private int maxNumberToSell; private int numberSold = 0; @Override public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); Tag sellBonusTokenTag = tag.getChild("SellBonusToken"); if (sellBonusTokenTag == null) { throw new ConfigurationException("<SellBonusToken> tag missing"); } locationCodes = sellBonusTokenTag.getAttributeAsString("location"); if (!Util.hasValue(locationCodes)) throw new ConfigurationException("SellBonusToken: location missing"); MapManager mmgr = MapManager.getInstance(); MapHex hex; locations = new ArrayList<MapHex>(); for (String hexName : locationCodes.split(",")) { hex = mmgr.getHex(hexName); if (hex == null) throw new ConfigurationException("Location " + hexName + " does not exist"); locations.add(hex); } name = sellBonusTokenTag.getAttributeAsString("name"); value = sellBonusTokenTag.getAttributeAsInteger("value", 0); if (value <= 0) throw new ConfigurationException("Value invalid ["+value+"] or missing"); price = sellBonusTokenTag.getAttributeAsInteger("price", 0); if (price <= 0) throw new ConfigurationException("Price invalid ["+price+"] or missing"); maxNumberToSell = sellBonusTokenTag.getAttributeAsInteger("number", 1); seller = new State ("SellerOf_"+name+"_Bonus", CashHolder.class); } @Override public void setExercised () { numberSold++; if (maxNumberToSell >= 0 && numberSold >= maxNumberToSell) { super.setExercised(); } } public boolean isExecutionable() { return true; } public List<MapHex> getLocations() { return locations; } public String getLocationNameString() { return locationCodes; } public String getName() { return name; } public int getPrice() { return price; } public int getValue() { return value; } public CashHolder getSeller() { return (CashHolder) seller.getObject(); } public void setSeller(CashHolder seller) { this.seller.set(seller); } @Override public String toString() { return "SellBonusToken comp=" + privateCompany.getName() + " hex=" + locationCodes + " value=" + value + " price=" + price; } } |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:14
|
Update of /cvsroot/rails/18xx/rails/game/state In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/state Modified Files: State.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: State.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/state/State.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** State.java 4 Jun 2008 19:00:36 -0000 1.9 --- State.java 23 Sep 2009 21:38:57 -0000 1.10 *************** *** 46,50 **** } else { log.error("Incompatible object type " + object.getClass().getName() ! + "passed to " + getClassName() + " wrapper for object type " + clazz.getName() + " at:", new Exception("")); --- 46,50 ---- } else { log.error("Incompatible object type " + object.getClass().getName() ! + " passed to " + getClassName() + " wrapper for object type " + clazz.getName() + " at:", new Exception("")); *************** *** 75,79 **** } ! public String getText() { if (object != null) { return object.toString(); --- 75,80 ---- } ! @Override ! public String getText() { if (object != null) { return object.toString(); *************** *** 83,87 **** } ! public String toString() { return name; } --- 84,89 ---- } ! @Override ! public String toString() { return name; } |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:14
|
Update of /cvsroot/rails/18xx/rails/game/move In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/move Modified Files: DoubleMapChange.java RemoveFromList.java MapChange.java Move.java AddToList.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: Move.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/move/Move.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Move.java 4 Jun 2008 19:00:33 -0000 1.2 --- Move.java 23 Sep 2009 21:38:57 -0000 1.3 *************** *** 1,4 **** /* $Header$ ! * * Created on 17-Jul-2006 * Change Log: --- 1,4 ---- /* $Header$ ! * * Created on 17-Jul-2006 * Change Log: *************** *** 6,11 **** --- 6,16 ---- package rails.game.move; + import java.util.ArrayList; + import java.util.List; + import org.apache.log4j.Logger; + import rails.game.model.ModelObject; + /** * @author Erik Vos *************** *** 13,16 **** --- 18,26 ---- public abstract class Move { + /** Any ModelObjects that need be updated. + * Will only be used by subclasses where it matters. + */ + protected List<ModelObject> models = null; + protected static Logger log = Logger.getLogger(Move.class.getPackage().getName()); *************** *** 20,22 **** --- 30,45 ---- public abstract boolean undo(); + public void registerModelToUpdate (ModelObject model) { + if (models == null) models = new ArrayList<ModelObject>(2); + models.add(model); + } + + // Could also be built into execute() and update() + public void updateModels () { + if (models != null) { + for (ModelObject model : models) { + model.update(); + } + } + } } Index: MapChange.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/move/MapChange.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MapChange.java 15 Jan 2009 20:53:28 -0000 1.2 --- MapChange.java 23 Sep 2009 21:38:57 -0000 1.3 *************** *** 52,55 **** --- 52,59 ---- return true; } + + public String toString() { + return "MapChange: key="+key+" from "+oldValue+" to "+newValue; + } } Index: DoubleMapChange.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/move/DoubleMapChange.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DoubleMapChange.java 4 Jun 2008 19:00:33 -0000 1.6 --- DoubleMapChange.java 23 Sep 2009 21:38:57 -0000 1.7 *************** *** 51,53 **** --- 51,56 ---- } + public String toString() { + return "DoubleMapChange: key1="+firstKey+"key2="+secondKey+" value="+value; + } } Index: RemoveFromList.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/move/RemoveFromList.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RemoveFromList.java 4 Jun 2008 19:00:33 -0000 1.2 --- RemoveFromList.java 23 Sep 2009 21:38:57 -0000 1.3 *************** *** 8,11 **** --- 8,13 ---- import java.util.List; + import rails.game.model.ModelObject; + /** * @author Erik Vos *************** *** 18,31 **** protected int index; ! public RemoveFromList(List<E> list, E object, String listName) { this.object = object; this.list = list; this.listName = listName; index = list.indexOf(object); MoveSet.add(this); } ! public boolean execute() { list.remove(object); return true; --- 20,39 ---- protected int index; ! public RemoveFromList(List<E> list, E object, String listName, ! ModelObject modelToUpdate) { this.object = object; this.list = list; this.listName = listName; index = list.indexOf(object); + if (modelToUpdate != null) registerModelToUpdate (modelToUpdate); MoveSet.add(this); } ! public RemoveFromList(List<E> list, E object, String listName) { ! this (list, object, listName, null); ! } ! ! public boolean execute() { list.remove(object); return true; *************** *** 38,42 **** public String toString() { ! return "RemoveFrom " + listName + ": " + object.toString(); } --- 46,50 ---- public String toString() { ! return "RemoveFromList " + listName + ": " + object.toString(); } Index: AddToList.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/move/AddToList.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AddToList.java 4 Jun 2008 19:00:33 -0000 1.3 --- AddToList.java 23 Sep 2009 21:38:57 -0000 1.4 *************** *** 1,4 **** /* $Header$ ! * * Created on 18-Jul-2006 * Change Log: --- 1,4 ---- /* $Header$ ! * * Created on 18-Jul-2006 * Change Log: *************** *** 8,11 **** --- 8,13 ---- import java.util.List; + import rails.game.model.ModelObject; + /** * @author Erik Vos *************** *** 17,40 **** protected String listName; ! public AddToList(List<E> list, E object, String listName) { this.object = object; this.list = list; this.listName = listName; MoveSet.add(this); } ! public boolean execute() { list.add(object); return true; } ! public boolean undo() { list.remove(object); return true; } ! public String toString() { ! return "AddTo " + listName + ": " + object.toString(); } --- 19,53 ---- protected String listName; ! public AddToList(List<E> list, E object, String listName, ! ModelObject modelToUpdate) { this.object = object; this.list = list; this.listName = listName; + if (modelToUpdate != null) registerModelToUpdate (modelToUpdate); MoveSet.add(this); } + + public AddToList(List<E> list, E object, String listName) { + this (list, object, listName, null); + } ! @Override ! public boolean execute() { list.add(object); + updateModels(); return true; } ! @Override ! public boolean undo() { list.remove(object); + updateModels(); return true; } ! @Override ! public String toString() { ! return "AddToList " + listName + ": " + object.toString(); } |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:11
|
Update of /cvsroot/rails/18xx/rails/game/action In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/action Added Files: BuyBonusToken.java Log Message: Implemented 1856 Bridge and Tunnel tokens --- NEW FILE: BuyBonusToken.java --- /* $Header: /cvsroot/rails/18xx/rails/game/action/BuyBonusToken.java,v 1.1 2009/09/23 21:38:58 evos Exp $ * * Created on 17-Sep-2006 * Change Log: */ package rails.game.action; import java.io.IOException; import java.io.ObjectInputStream; import rails.game.*; import rails.game.special.SellBonusToken; import rails.game.special.SpecialProperty; /** * @author Erik Vos */ public class BuyBonusToken extends PossibleORAction { // Initial attributes transient private PrivateCompanyI privateCompany; private String privateCompanyName; transient private CashHolder seller = null; private String sellerName = null; transient protected SellBonusToken specialProperty = null; protected int specialPropertyId; private String name; private int price; private int value; private String locationString; public static final long serialVersionUID = 1L; /** * */ public BuyBonusToken(SellBonusToken specialProperty) { this.specialProperty = specialProperty; this.specialPropertyId = specialProperty.getUniqueId(); this.privateCompany = specialProperty.getCompany(); this.privateCompanyName = privateCompany.getName(); this.seller = specialProperty.getSeller(); if (seller != null) this.sellerName = seller.getName(); this.name = specialProperty.getName(); this.price = specialProperty.getPrice(); this.value = specialProperty.getValue(); this.locationString = specialProperty.getLocationNameString(); } /** * @return Returns the privateCompany. */ public PrivateCompanyI getPrivateCompany() { return privateCompany; } public String getPrivateCompanyName() { return privateCompanyName; } public CashHolder getSeller() { return seller; } public String getSellerName() { return sellerName; } public SellBonusToken getSpecialProperty() { return specialProperty; } public String getName() { return name; } public int getValue() { return value; } public String getLocationString() { return locationString; } public int getPrice() { return price; } @Override public boolean equals(PossibleAction action) { if (!(action instanceof BuyBonusToken)) return false; BuyBonusToken a = (BuyBonusToken) action; return a.privateCompany == privateCompany && a.name.equals(name) && a.price == price && a.value == value && a.locationString.equals(locationString); } @Override public String toString() { return "BuyBonusToken " + privateCompanyName + " owner=" + sellerName + " price=" + price + " value=" + value + " locations=" + locationString; } /** Deserialize */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); privateCompany = Game.getCompanyManager().getPrivateCompany(privateCompanyName); if (sellerName.equalsIgnoreCase("Bank")) { seller = Bank.getInstance(); } else if (sellerName != null) { seller = Game.getCompanyManager().getPublicCompany(sellerName); } if (specialPropertyId > 0) { specialProperty = (SellBonusToken) SpecialProperty.getByUniqueId(specialPropertyId); } } } |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:11
|
Update of /cvsroot/rails/18xx/data In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/data Modified Files: GamesList.xml Log Message: Implemented 1856 Bridge and Tunnel tokens Index: GamesList.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/GamesList.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GamesList.xml 11 Mar 2008 20:16:01 -0000 1.11 --- GamesList.xml 23 Sep 2009 21:38:57 -0000 1.12 *************** *** 51,60 **** </Game> <Game name="1856"> ! <Note>Partly playable</Note> <Description>1856 - Railroading in Upper Canada (c) 1992, 1995 Mayfair Games, Inc. Designed by Bill Dixon ! Aspects not present in 1830 have not been implemented yet. </Description> <Players minimum="3" maximum="6"/> --- 51,61 ---- </Game> <Game name="1856"> ! <Note>Almost playable</Note> <Description>1856 - Railroading in Upper Canada (c) 1992, 1995 Mayfair Games, Inc. Designed by Bill Dixon ! Current limitation: ! - No Bridge and Tunnel bonuses. </Description> <Players minimum="3" maximum="6"/> *************** *** 103,107 **** (c) 1992 ERJO GAMES ! Should work, but has not been extensively tested </Description> <Option name="WithOptional6Train" type="toggle" default="no"/> --- 104,108 ---- (c) 1992 ERJO GAMES ! Should work, but has not been extensively tested. Linitations as with 1830. </Description> <Option name="WithOptional6Train" type="toggle" default="no"/> |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:11
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/specific/_1856 Modified Files: CGRFormationRound.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CGRFormationRound.java 6 Sep 2009 12:27:31 -0000 1.15 --- CGRFormationRound.java 23 Sep 2009 21:38:57 -0000 1.16 *************** *** 483,486 **** --- 483,488 ---- City city; for (PublicCompanyI comp : mergingCompanies) { + + // Exchange home tokens and collect non-home tokens for (TokenI token :comp.getTokens()) { if (token instanceof BaseToken) { *************** *** 497,503 **** --- 499,508 ---- } + // Move any remaining cash if (comp.getCash() > 0) { new CashMove (comp, cgr, comp.getCash()); } + + // Move any remaining trains List<TrainI> trains = new ArrayList<TrainI> (comp.getPortfolio().getTrainList()); for (TrainI train : trains) { *************** *** 505,508 **** --- 510,522 ---- if (train.getType().isPermanent()) cgr.setHadPermanentTrain(true); } + + // Move any still valid bonuses + if (comp.getBonuses() != null) { + List<Bonus> bonuses = new ArrayList<Bonus> (comp.getBonuses()); + for (Bonus bonus : bonuses) { + cgr.addBonus(new Bonus(cgr, bonus.getName(), bonus.getValue(), bonus.getLocationNameString())); + comp.removeBonus(bonus); + } + } } *************** *** 568,572 **** } ! // Close the merged companies for (PublicCompanyI comp : mergingCompanies) { comp.setClosed(); --- 582,586 ---- } ! // Close the merged companies for (PublicCompanyI comp : mergingCompanies) { comp.setClosed(); |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:09
|
Update of /cvsroot/rails/18xx In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188 Modified Files: LocalisedText.properties Log Message: Implemented 1856 Bridge and Tunnel tokens Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** LocalisedText.properties 3 Sep 2009 18:33:27 -0000 1.76 --- LocalisedText.properties 23 Sep 2009 21:38:57 -0000 1.77 *************** *** 5,8 **** --- 5,9 ---- AT_PRICE=at {0} AcceptingConfigFailure=Temporarily accepting configuration failure + AcquiresBonus={0} acquires a {1} +{2} bonus on hex(es) {3} AlreadyBought={0} already bought a share this turn AlreadySoldThisTurn={0} already sold {1} this turn *************** *** 30,36 **** --- 31,39 ---- BidTooHigh=Bid too high, player has only {0} free for bidding BidTooLow=Bid too low, minimum is {0} + BuyBonusToken=Buy {0} +{1} bonus token from {2} for {3} BuyCertificate=Buy a {0}% certificate of {1} from {2} for {3} BuyCertificates=Buy {0} {1}% certificates of {2} from {3} for {4} BuyTrain=Buy a train, or press Done to finish this company turn + BuysBonusTokenFrom={0} buys a {1} +{2} bonus token from {3} for {4} BuysItemFor={0} buys {1} for {2} BuysPrivateFromFor={0} buys private {1} from {2} for {3} *************** *** 52,55 **** --- 55,59 ---- CannotBid=Cannot bid on this item CannotBuyAnyTrain=You have no money to buy any train + CannotBuyBonusToken={0} cannot by a {1} bonus token from {2} for {3}: {4} CannotBuyPrivateFor={0} cannot buy private {1} for {2}: {3} CannotBuyPrivateFromFor={0} cannot buy private {1} from {2} for {3}: {4} |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:07
|
Update of /cvsroot/rails/18xx/rails/game/model In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game/model Added Files: BonusModel.java Log Message: Implemented 1856 Bridge and Tunnel tokens --- NEW FILE: BonusModel.java --- /* $Header: /cvsroot/rails/18xx/rails/game/model/BonusModel.java,v 1.1 2009/09/23 21:38:57 evos Exp $*/ package rails.game.model; import java.util.List; import rails.game.Bank; import rails.game.Bonus; import rails.game.state.StringState; public class BonusModel extends StringState { private List<Bonus> bonuses; public BonusModel(String name) { super(name, ""); } public void set(List<Bonus> bonuses) { this.bonuses = bonuses; } @Override public String getText() { if (bonuses == null || bonuses.isEmpty()) return ""; StringBuffer b = new StringBuffer("<html><center>"); for (Bonus bonus : bonuses) { if (b.length() > 14) { b.append("<br>"); } b.append(bonus.getLocationNameString()).append("+").append(Bank.format(bonus.getValue())); } return b.toString(); } } |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:07
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/ui/swing Modified Files: ORUIManager.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** ORUIManager.java 8 Sep 2009 21:48:59 -0000 1.28 --- ORUIManager.java 23 Sep 2009 21:38:57 -0000 1.29 *************** *** 334,337 **** --- 334,341 ---- prepareBonusToken((LayBonusToken) actions.get(0)); + } else if (actionType == BuyBonusToken.class) { + + buyBonusToken ((BuyBonusToken)actions.get(0)); + } else if (actionType == NullAction.class || actionType == GameAction.class) { *************** *** 420,423 **** --- 424,432 ---- } + private void buyBonusToken (BuyBonusToken action) { + + orWindow.process(action); + } + protected void reachDestinations (ReachDestinations action) { *************** *** 1240,1243 **** --- 1249,1268 ---- } + // Can bonus tokens be bought? + if (possibleActions.contains(BuyBonusToken.class)) { + + List<BuyBonusToken> bonusTokenActions = + possibleActions.getType(BuyBonusToken.class); + for (BuyBonusToken bbt : bonusTokenActions) { + String text = + LocalText.getText("BuyBonusToken", + bbt.getName(), + Bank.format(bbt.getValue()), + bbt.getCompanyName(), + Bank.format(bbt.getPrice()) ); + orPanel.addSpecialAction(bbt, text); + } + } + if (possibleActions.contains(ReachDestinations.class)) { orPanel.addSpecialAction(possibleActions.getType(ReachDestinations.class).get(0), |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:06
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/rails/game Modified Files: Portfolio.java PublicCompany.java GameManager.java PublicCompanyI.java BonusToken.java OperatingRound.java GameManagerI.java PrivateCompany.java Added Files: Bonus.java Log Message: Implemented 1856 Bridge and Tunnel tokens Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** Portfolio.java 30 Aug 2009 18:15:18 -0000 1.34 --- Portfolio.java 23 Sep 2009 21:38:57 -0000 1.35 *************** *** 13,16 **** --- 13,17 ---- import rails.game.model.*; import rails.game.move.*; + import rails.game.special.LocatedBonus; import rails.game.special.SpecialPropertyI; import rails.util.LocalText; *************** *** 98,143 **** } - public void buyPrivate(PrivateCompanyI privateCompany, Portfolio from, - int price) { - - if (from != Bank.getIpo()) - /* - * The initial buy is reported from StartRound. This message should also - * move to elsewhere. - */ - { - ReportBuffer.add(LocalText.getText("BuysPrivateFromFor", - name, - privateCompany.getName(), - from.getName(), - Bank.format(price) )); - } - - // Move the private certificate - privateCompany.moveTo(this); - - // Move the money - if (price > 0) new CashMove(owner, from.owner, price); - - // Move any special abilities, if configured so - List<SpecialPropertyI> sps = privateCompany.getSpecialProperties(); - if (sps != null) { - // Need intermediate List to avoid ConcurrentModificationException - List<SpecialPropertyI> spsToMove = - new ArrayList<SpecialPropertyI>(2); - for (SpecialPropertyI sp : sps) { - if (sp.getTransferText().equalsIgnoreCase("toCompany") - && owner instanceof PublicCompanyI - || sp.getTransferText().equalsIgnoreCase("toPlayer") - && owner instanceof Player) { - spsToMove.add(sp); - } - } - for (SpecialPropertyI sp : spsToMove) { - sp.moveTo(this); - } - } - } - public void transferAssetsFrom(Portfolio otherPortfolio) { --- 99,102 ---- *************** *** 501,512 **** */ public boolean addSpecialProperty(SpecialPropertyI property) { if (specialProperties == null) { specialProperties = new ArrayList<SpecialPropertyI>(2); } ! return specialProperties.add(property); } /** ! * Remove a special property. Not currently used. * * @param property The special property object to remove. --- 460,491 ---- */ public boolean addSpecialProperty(SpecialPropertyI property) { + + boolean result = false; + if (specialProperties == null) { specialProperties = new ArrayList<SpecialPropertyI>(2); } ! result = specialProperties.add(property); ! ! // Special case for bonuses with predefined locations ! // TODO Does this belong here? ! if (owner instanceof PublicCompanyI && property instanceof LocatedBonus) { ! PublicCompanyI company = (PublicCompanyI)owner; ! LocatedBonus locBonus = (LocatedBonus)property; ! Bonus bonus = new Bonus(company, locBonus.getName(), locBonus.getValue(), ! locBonus.getLocationNameString()); ! company.addBonus(bonus); ! ReportBuffer.add(LocalText.getText("AcquiresBonus", ! owner.getName(), ! locBonus.getName(), ! Bank.format(locBonus.getValue()), ! locBonus.getLocationNameString())); ! } ! ! return result; } /** ! * Remove a special property. * * @param property The special property object to remove. *************** *** 514,522 **** */ public boolean removeSpecialProperty(SpecialPropertyI property) { if (specialProperties != null) { ! return specialProperties.remove(property); ! } else { ! return false; } } --- 493,512 ---- */ public boolean removeSpecialProperty(SpecialPropertyI property) { + + boolean result = false; + if (specialProperties != null) { ! result = specialProperties.remove(property); ! ! // Special case for bonuses with predefined locations ! // TODO Does this belong here? ! if (owner instanceof PublicCompanyI && property instanceof LocatedBonus) { ! PublicCompanyI company = (PublicCompanyI)owner; ! LocatedBonus locBonus = (LocatedBonus)property; ! company.removeBonus(locBonus.getName()); ! } } + + return result; } *************** *** 545,549 **** /** ! * Remove an object. Not currently used. * * @param object The object to remove. --- 535,539 ---- /** ! * Remove an object. * * @param object The object to remove. --- NEW FILE: Bonus.java --- /* $Header: /cvsroot/rails/18xx/rails/game/Bonus.java,v 1.1 2009/09/23 21:38:57 evos Exp $ */ package rails.game; import java.util.ArrayList; import java.util.List; /** * An object of class Bonus represent extra income for the owning company, * usually connected to certain map locations. * <p>Currently, Bonus objects will be created in the following cases: * <br>1. when a SpecialTokenLay containing a BonusToken * is exercised, * <br>2. when a private having a LocatedBonus special property is bought by * a public company, * <br>3. when a sellable bonus is bought from such a public company by another company. * @author VosE * */ public class Bonus implements Closeable { private PublicCompanyI owner; private String locationCodes = null; private List<MapHex> locations = null; private String name; private int value; private String removingObjectDesc = null; private Object removingObject = null; public Bonus (PublicCompanyI owner, String name, int value, String locationCodes) { this.owner = owner; this.name = name; this.value = value; this.locationCodes = locationCodes; parseLocations(); } public boolean isExecutionable() { return false; } public PublicCompanyI getOwner() { return owner; } public List<MapHex> getLocations() { return locations; } public String getLocationNameString() { return locationCodes; } public String getName() { return name; } public int getValue() { return value; } private void parseLocations () { MapManager mmgr = MapManager.getInstance(); MapHex hex; locations = new ArrayList<MapHex>(); for (String hexName : locationCodes.split(",")) { hex = mmgr.getHex(hexName); if (hex != null) locations.add(hex); } } /** * Remove the token. * This method can be called by a certain phase when it starts. * See prepareForRemovel(). */ public void close() { owner.removeBonus(name); } /** * Prepare the bonus token for removal, if so configured. * The only case currently implemented to trigger removal * is the start of a given phase. */ public void prepareForRemoval (PhaseManager phaseManager) { if (removingObjectDesc == null) return; if (removingObject == null) { String[] spec = removingObjectDesc.split(":"); if (spec[0].equalsIgnoreCase("Phase")) { removingObject = phaseManager.getPhaseByName(spec[1]); } } if (removingObject instanceof Phase) { ((Phase) removingObject).addObjectToClose(this); } } @Override public String toString() { return "Bonus "+name+" hex=" + locationCodes + " value=" + value; } } Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** PublicCompany.java 12 Sep 2009 09:40:56 -0000 1.59 --- PublicCompany.java 23 Sep 2009 21:38:57 -0000 1.60 *************** *** 7,12 **** import rails.game.action.SetDividend; import rails.game.model.*; ! import rails.game.move.CashMove; ! import rails.game.move.Moveable; import rails.game.state.*; import rails.util.*; --- 7,12 ---- import rails.game.action.SetDividend; import rails.game.model.*; ! import rails.game.move.*; ! import rails.game.special.*; import rails.game.state.*; import rails.util.*; *************** *** 91,95 **** /** Total bonus tokens amount */ ! protected MoneyModel bonusTokensValue = null; /** Most recent revenue earned. */ --- 91,98 ---- /** Total bonus tokens amount */ ! protected BonusModel bonusValue = null; ! ! /** Acquires Bonus objects */ ! protected List<Bonus> bonuses = null; /** Most recent revenue earned. */ *************** *** 596,602 **** trainsCostThisTurn = new MoneyModel(name + "_spentOnTrains"); trainsCostThisTurn.setOption(MoneyModel.SUPPRESS_ZERO); ! bonusTokensValue = new MoneyModel(name + "_bonusValue"); ! bonusTokensValue.setOption(MoneyModel.SUPPRESS_ZERO ! + MoneyModel.ADD_PLUS); if (hasStockPrice) { parPrice = new PriceModel(this, name + "_ParPrice"); --- 599,604 ---- trainsCostThisTurn = new MoneyModel(name + "_spentOnTrains"); trainsCostThisTurn.setOption(MoneyModel.SUPPRESS_ZERO); ! bonusValue = new BonusModel(name + "_bonusValue"); ! if (hasStockPrice) { parPrice = new PriceModel(this, name + "_ParPrice"); *************** *** 956,962 **** } } ! ! /** Return the price per share at game end. ! * Normally, it is equal to the market price, * but in some games (e.g. 1856) deductions may apply. * @return --- 958,964 ---- } } ! ! /** Return the price per share at game end. ! * Normally, it is equal to the market price, * but in some games (e.g. 1856) deductions may apply. * @return *************** *** 1232,1236 **** 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; --- 1234,1238 ---- 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; *************** *** 1465,1471 **** public void buyPrivate(PrivateCompanyI privateCompany, Portfolio from, int price) { - portfolio.buyPrivate(privateCompany, from, price); privatesCostThisTurn.add(price); } --- 1467,1516 ---- public void buyPrivate(PrivateCompanyI privateCompany, Portfolio from, int price) { + //portfolio.buyPrivate(privateCompany, from, price); + if (from != Bank.getIpo()) { + // The initial buy is reported from StartRound. This message should also + // move to elsewhere. + ReportBuffer.add(LocalText.getText("BuysPrivateFromFor", + name, + privateCompany.getName(), + from.getName(), + Bank.format(price) )); + } + + // Move the private certificate + privateCompany.moveTo(portfolio); + + // Move the money + if (price > 0) new CashMove(this, from.owner, price); privatesCostThisTurn.add(price); + + // Move any special abilities to the portfolio, if configured so + List<SpecialPropertyI> sps = privateCompany.getSpecialProperties(); + if (sps != null) { + // Need intermediate List to avoid ConcurrentModificationException + List<SpecialPropertyI> spsToMoveHere = + new ArrayList<SpecialPropertyI>(2); + List<SpecialPropertyI> spsToMoveToGM = + new ArrayList<SpecialPropertyI>(2); + for (SpecialPropertyI sp : sps) { + if (sp.getTransferText().equalsIgnoreCase("toCompany")) { + spsToMoveHere.add(sp); + } else if (sp.getTransferText().equalsIgnoreCase("toGameManager")) { + // This must be SellBonusToken - remember the owner! + if (sp instanceof SellBonusToken) { + ((SellBonusToken)sp).setSeller(this); + } + spsToMoveToGM.add(sp); + } + } + for (SpecialPropertyI sp : spsToMoveHere) { + sp.moveTo(portfolio); + } + for (SpecialPropertyI sp : spsToMoveToGM) { + sp.moveTo(gameManager); + } + } + } *************** *** 1537,1553 **** } ! public void layBonusToken(MapHex hex, int cost, BonusToken token) { ! // TODO for now we only add the bonus value. ! // We must be prepared though, that tokens may be removed later. ! bonusTokensValue.add(token.getValue()); } ! public void removeBonusToken(BonusToken token) { ! bonusTokensValue.add(-token.getValue()); } ! public MoneyModel getBonusTokensModel() { ! return bonusTokensValue; } --- 1582,1614 ---- } ! public boolean addBonus(Bonus bonus) { ! if (bonuses == null) { ! bonuses = new ArrayList<Bonus>(2); ! bonusValue.set(bonuses); ! } ! new AddToList<Bonus> (bonuses, bonus, name+"_Bonuses", bonusValue); ! return true; ! } + public boolean removeBonus(Bonus bonus) { + new RemoveFromList<Bonus> (bonuses, bonus, name+"_Bonuses", bonusValue); + return true; } ! public boolean removeBonus (String name) { ! if (bonuses != null && !bonuses.isEmpty()) { ! for(Bonus bonus : bonuses) { ! if (bonus.getName().equals(name)) return removeBonus(bonus); ! } ! } ! return false; } ! public List<Bonus> getBonuses() { ! return bonuses; ! } ! ! public BonusModel getBonusTokensModel() { ! return bonusValue; } *************** *** 1636,1639 **** --- 1697,1702 ---- if (object instanceof TokenI) { return addToken((TokenI) object); + } else if (object instanceof LocatedBonus) { + return addBonus ((Bonus) object); } else { return false; *************** *** 1644,1649 **** if (object instanceof BaseToken) { return removeToken((TokenI) object); ! } else if (object instanceof BonusToken) { ! removeBonusToken((BonusToken) object); return true; } else { --- 1707,1712 ---- if (object instanceof BaseToken) { return removeToken((TokenI) object); ! } else if (object instanceof Bonus) { ! removeBonus((Bonus) object); return true; } else { Index: PrivateCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompany.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** PrivateCompany.java 15 Jan 2009 20:53:28 -0000 1.20 --- PrivateCompany.java 23 Sep 2009 21:38:57 -0000 1.21 *************** *** 6,9 **** --- 6,10 ---- import rails.game.move.*; + import rails.game.special.SellBonusToken; import rails.game.special.SpecialPropertyI; import rails.util.*; *************** *** 163,173 **** @Override public void setClosed() { ! if (!isClosed()) { ! super.setClosed(); ! unblockHexes(); ! // new CertificateMove (getPortfolio(), Bank.getScrapHeap(), ! // (Certificate)this); ! moveTo(Bank.getScrapHeap()); ! ReportBuffer.add(LocalText.getText("PrivateCloses", name)); } } --- 164,180 ---- @Override public void setClosed() { ! ! if (isClosed()) return; ! ! super.setClosed(); ! unblockHexes(); ! moveTo(Bank.getScrapHeap()); ! ReportBuffer.add(LocalText.getText("PrivateCloses", name)); ! ! // For 1856: buyable tokens move to Bank ! for (SpecialPropertyI sp : specialProperties) { ! if (sp instanceof SellBonusToken) { ! ((SellBonusToken)sp).setSeller(Bank.getInstance()); ! } } } Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** GameManager.java 12 Sep 2009 19:48:39 -0000 1.52 --- GameManager.java 23 Sep 2009 21:38:57 -0000 1.53 *************** *** 10,15 **** import rails.common.Defs; import rails.game.action.*; ! import rails.game.move.AddToList; ! import rails.game.move.MoveSet; import rails.game.special.SpecialPropertyI; import rails.game.special.SpecialTokenLay; --- 10,14 ---- import rails.common.Defs; import rails.game.action.*; ! import rails.game.move.*; import rails.game.special.SpecialPropertyI; import rails.game.special.SpecialTokenLay; *************** *** 87,91 **** protected boolean gameOver = false; protected boolean endedByBankruptcy = false; ! /** Flags to be passed to the UI, aiding the layout definition */ protected EnumMap<Defs.Parm, Boolean> gameParameters = --- 86,90 ---- protected boolean gameOver = false; protected boolean endedByBankruptcy = false; ! /** Flags to be passed to the UI, aiding the layout definition */ protected EnumMap<Defs.Parm, Boolean> gameParameters = *************** *** 105,111 **** protected StartPacket startPacket; ! PossibleActions possibleActions = PossibleActions.getInstance(); ! List<PossibleAction> executedActions = new ArrayList<PossibleAction>(); /** A List of available game options */ --- 104,115 ---- protected StartPacket startPacket; ! protected PossibleActions possibleActions = PossibleActions.getInstance(); ! protected List<PossibleAction> executedActions = new ArrayList<PossibleAction>(); ! ! /** Special properties that can be used by other players or companies ! * than just the owner (such as buyable bonus tokens as in 1856). ! */ ! protected List<SpecialPropertyI> commonSpecialProperties = null; /** A List of available game options */ *************** *** 1038,1040 **** --- 1042,1123 ---- } + /** + * Add an object. + * + * @param object The object to add. + * @return True if successful. + */ + public boolean addObject(Moveable object) { + if (object instanceof SpecialPropertyI) { + return addSpecialProperty((SpecialPropertyI) object); + } else { + return false; + } + } + + /** + * Remove an object. + * + * @param object The object to remove. + * @return True if successful. + */ + public boolean removeObject(Moveable object) { + if (object instanceof SpecialPropertyI) { + return removeSpecialProperty((SpecialPropertyI) object); + } else { + return false; + } + } + + public boolean addSpecialProperty(SpecialPropertyI property) { + + if (commonSpecialProperties == null) { + commonSpecialProperties = new ArrayList<SpecialPropertyI>(2); + } + return commonSpecialProperties.add(property); + } + + /** + * Remove a special property. + * + * @param property The special property object to remove. + * @return True if successful. + */ + public boolean removeSpecialProperty(SpecialPropertyI property) { + + if (commonSpecialProperties != null) { + return commonSpecialProperties.remove(property); + } + + return false; + } + + public List<SpecialPropertyI> getCommonSpecialProperties () { + return getSpecialProperties (null, false); + } + + @SuppressWarnings("unchecked") + public <T extends SpecialPropertyI> List<T> getSpecialProperties( + Class<T> clazz, boolean includeExercised) { + + List<T> result = new ArrayList<T>(); + + if (commonSpecialProperties != null) { + for (SpecialPropertyI sp : commonSpecialProperties) { + if ((clazz == null || clazz.isAssignableFrom(sp.getClass())) + && sp.isExecutionable() + && (!sp.isExercised() || includeExercised)) { + log.debug("Adding common SP: " + sp); + result.add((T) sp); + } + } + } + + return result; + } + + public String getName () { + return "GameManager"; + } + } Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** PublicCompanyI.java 12 Sep 2009 09:40:56 -0000 1.35 --- PublicCompanyI.java 23 Sep 2009 21:38:57 -0000 1.36 *************** *** 146,150 **** public int getMarketPrice (); public int getGameEndPrice(); ! public int getPublicNumber(); --- 146,150 ---- public int getMarketPrice (); public int getGameEndPrice(); ! public int getPublicNumber(); *************** *** 252,256 **** public void adjustSharePrice (int actionPerformed, int numberOfSharesSold, StockMarketI stockMarket); ! public boolean isSplitAllowed(); --- 252,256 ---- public void adjustSharePrice (int actionPerformed, int numberOfSharesSold, StockMarketI stockMarket); ! public boolean isSplitAllowed(); *************** *** 311,319 **** public BaseTokensModel getBaseTokensModel(); ! public MoneyModel getBonusTokensModel(); ! public void layBonusToken(MapHex hex, int cost, BonusToken token); ! public void removeBonusToken(BonusToken token); public MapHex getHomeHex(); --- 311,321 ---- public BaseTokensModel getBaseTokensModel(); ! public BonusModel getBonusTokensModel(); ! public boolean addBonus(Bonus bonus); ! public boolean removeBonus(Bonus bonus); ! public boolean removeBonus (String name); ! public List<Bonus> getBonuses(); public MapHex getHomeHex(); Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** OperatingRound.java 8 Sep 2009 21:48:59 -0000 1.67 --- OperatingRound.java 23 Sep 2009 21:38:57 -0000 1.68 *************** *** 218,221 **** --- 218,225 ---- result = layBonusToken((LayBonusToken) selectedAction); + } else if (selectedAction instanceof BuyBonusToken) { + + result = buyBonusToken((BuyBonusToken) selectedAction); + } else if (selectedAction instanceof SetDividend) { *************** *** 670,674 **** /* TODO: the false return value must be impossible. */ ! operatingCompany.layBonusToken(hex, cost, token); token.setUser(operatingCompany); --- 674,680 ---- /* TODO: the false return value must be impossible. */ ! operatingCompany.addBonus(new Bonus(operatingCompany, ! token.getName(), ! token.getValue(), hex.getName())); token.setUser(operatingCompany); *************** *** 693,696 **** --- 699,755 ---- } + public boolean buyBonusToken(BuyBonusToken action) { + + String errMsg = null; + int cost; + SellBonusToken sbt = null; + CashHolder seller = null; + + // Dummy loop to enable a quick jump out. + while (true) { + + // Checks + sbt = action.getSpecialProperty(); + cost = sbt.getPrice(); + seller = sbt.getSeller(); + + // Does the company have the money? + if (cost > operatingCompany.getCash()) { + errMsg = + LocalText.getText("NotEnoughMoney", + operatingCompany.getName()); + break; + } + break; + } + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CannotBuyBonusToken", + operatingCompany.getName(), + sbt.getName(), + seller.getName(), + Bank.format(cost), + errMsg )); + return false; + } + + /* End of validation, start of execution */ + MoveSet.start(true); + + new CashMove (operatingCompany, seller, cost); + operatingCompany.addBonus(new Bonus(operatingCompany, + sbt.getName(), + sbt.getValue(), sbt.getLocationNameString())); + + ReportBuffer.add(LocalText.getText("BuysBonusTokenFrom", + operatingCompany.getName(), + sbt.getName(), + Bank.format(sbt.getValue()), + seller.getName(), + Bank.format(sbt.getValue()))); + + sbt.setExercised(); + + return true; + } public boolean setRevenueAndDividend(SetDividend action) { *************** *** 976,980 **** if (step == STEP_LAY_TRACK) { getNormalTileLays(); ! } else if (step == STEP_LAY_TOKEN) {} else { currentSpecialProperties = null; } --- 1035,1041 ---- if (step == STEP_LAY_TRACK) { getNormalTileLays(); ! } else if (step == STEP_LAY_TOKEN) { ! ! } else { currentSpecialProperties = null; } *************** *** 1933,1936 **** --- 1994,2016 ---- } + // Are there any "common" special properties, + // i.e. properties that are available to everyone? + List<SpecialPropertyI> commonSP = gameManager.getCommonSpecialProperties(); + if (commonSP != null) { + SellBonusToken sbt; + loop: for (SpecialPropertyI sp : commonSP) { + if (sp instanceof SellBonusToken) { + sbt = (SellBonusToken) sp; + // Can't buy if already owned + if (operatingCompany.getBonuses() != null) { + for (Bonus bonus : operatingCompany.getBonuses()) { + if (bonus.getName().equals(sp.getName())) continue loop; + } + } + possibleActions.add (new BuyBonusToken (sbt)); + } + } + } + if (doneAllowed) { possibleActions.add(new NullAction(NullAction.DONE)); Index: BonusToken.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/BonusToken.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** BonusToken.java 8 Sep 2009 21:48:58 -0000 1.9 --- BonusToken.java 23 Sep 2009 21:38:57 -0000 1.10 *************** *** 64,68 **** new ObjectMove(this, holder, Bank.getScrapHeap()); ! user.removeBonusToken(this); } --- 64,68 ---- new ObjectMove(this, holder, Bank.getScrapHeap()); ! user.removeBonus(name); } Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GameManagerI.java 12 Sep 2009 19:48:39 -0000 1.10 --- GameManagerI.java 23 Sep 2009 21:38:57 -0000 1.11 *************** *** 6,12 **** import rails.game.action.PossibleAction; import rails.game.model.ModelObject; import rails.util.Tag; ! public interface GameManagerI { /** --- 6,14 ---- import rails.game.action.PossibleAction; import rails.game.model.ModelObject; + import rails.game.move.MoveableHolderI; + import rails.game.special.SpecialPropertyI; import rails.util.Tag; ! public interface GameManagerI extends MoveableHolderI { /** *************** *** 171,173 **** --- 173,179 ---- public RoundI getInterruptedRound(); + + public List<SpecialPropertyI> getCommonSpecialProperties (); + public <T extends SpecialPropertyI> List<T> getSpecialProperties( + Class<T> clazz, boolean includeExercised); } \ No newline at end of file |
From: Erik V. <ev...@us...> - 2009-09-23 21:39:05
|
Update of /cvsroot/rails/18xx/data/1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv15188/data/1856 Modified Files: CompanyManager.xml Log Message: Implemented 1856 Bridge and Tunnel tokens Index: CompanyManager.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1856/CompanyManager.xml,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** CompanyManager.xml 4 Sep 2009 18:40:30 -0000 1.29 --- CompanyManager.xml 23 Sep 2009 21:38:57 -0000 1.30 *************** *** 69,74 **** </ClosingConditions> </Company> ! <Company name="Brdg" type="Private" basePrice="100" revenue="20"/> ! <Company name="Tunn" type="Private" basePrice="100" revenue="20"/> <Company name="GT" type="Public" tokens="4" fgColour="000000" bgColour="40B0A0"> --- 69,96 ---- </ClosingConditions> </Company> ! <Company name="Brdg" type="Private" basePrice="100" revenue="20"> ! <SpecialProperties> ! <SpecialProperty condition="ifOwnedByCompany" when="revenueStep" ! class="rails.game.special.LocatedBonus" transfer="toCompany"> ! <LocatedBonus name="Bridge" location="P17,P19" value="10"/> ! </SpecialProperty> ! <SpecialProperty condition="ifOwnedByCompany" when="anyTimeDuringOR" ! class="rails.game.special.SellBonusToken" transfer="toGameManager"> ! <SellBonusToken name="Bridge" location="P17,P19" price="50" value="10" number="2"/> ! </SpecialProperty> ! </SpecialProperties> ! </Company> ! <Company name="Tunn" type="Private" basePrice="100" revenue="20"> ! <SpecialProperties> ! <SpecialProperty condition="ifOwnedByCompany" when="revenueStep" ! class="rails.game.special.LocatedBonus" transfer="toCompany"> ! <LocatedBonus name="Tunnel" location="B13" value="10"/> ! </SpecialProperty> ! <SpecialProperty condition="ifOwnedByCompany" when="anyTimeDuringOR" ! class="rails.game.special.SellBonusToken" transfer="toGameManager"> ! <SellBonusToken name="Tunnel" location="B13" price="50" value="10" number="2"/> ! </SpecialProperty> ! </SpecialProperties> ! </Company> <Company name="GT" type="Public" tokens="4" fgColour="000000" bgColour="40B0A0"> |
From: Erik V. <ev...@us...> - 2009-09-12 19:48:56
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv16351/rails/game Modified Files: GameManagerI.java GameManager.java Log Message: Simplified Defs.ClassName and Defs.Parm handling Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** GameManager.java 11 Sep 2009 19:27:23 -0000 1.51 --- GameManager.java 12 Sep 2009 19:48:39 -0000 1.52 *************** *** 87,95 **** protected boolean gameOver = false; protected boolean endedByBankruptcy = false; ! protected boolean hasAnyParPrice = false; ! protected boolean canAnyCompanyBuyPrivates = false; ! protected boolean canAnyCompanyHoldShares = false; ! protected boolean bonusTokensExist = false; ! protected boolean hasAnyCompanyLoans = false; protected int stockRoundSequenceRule = StockRound.SELL_BUY_SELL; --- 87,99 ---- protected boolean gameOver = false; protected boolean endedByBankruptcy = false; ! ! /** Flags to be passed to the UI, aiding the layout definition */ ! protected EnumMap<Defs.Parm, Boolean> gameParameters = ! new EnumMap<Defs.Parm, Boolean>(Defs.Parm.class); ! //protected boolean hasAnyParPrice = false; ! //protected boolean canAnyCompanyBuyPrivates = false; ! //protected boolean canAnyCompanyHoldShares = false; ! //protected boolean bonusTokensExist = false; ! //protected boolean hasAnyCompanyLoans = false; protected int stockRoundSequenceRule = StockRound.SELL_BUY_SELL; *************** *** 360,367 **** for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { ! hasAnyParPrice = hasAnyParPrice || company.hasParPrice(); ! canAnyCompanyBuyPrivates = canAnyCompanyBuyPrivates || company.canBuyPrivates(); ! canAnyCompanyHoldShares = canAnyCompanyHoldShares || company.canHoldOwnShares(); ! hasAnyCompanyLoans = hasAnyCompanyLoans || company.getMaxNumberOfLoans() != 0; } --- 364,375 ---- for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { ! //hasAnyParPrice = hasAnyParPrice || company.hasParPrice(); ! if (company.hasParPrice()) gameParameters.put(Defs.Parm.HAS_ANY_PAR_PRICE, true); ! //canAnyCompanyBuyPrivates = canAnyCompanyBuyPrivates || company.canBuyPrivates(); ! if (company.canBuyPrivates()) gameParameters.put(Defs.Parm.CAN_ANY_COMPANY_BUY_PRIVATES, true); ! //canAnyCompanyHoldShares = canAnyCompanyHoldShares || company.canHoldOwnShares(); ! if (company.canHoldOwnShares()) gameParameters.put(Defs.Parm.CAN_ANY_COMPANY_HOLD_OWN_SHARES, true); ! //hasAnyCompanyLoans = hasAnyCompanyLoans || company.getMaxNumberOfLoans() != 0; ! if (company.getMaxNumberOfLoans() != 0) gameParameters.put(Defs.Parm.HAS_ANY_COMPANY_LOANS, true); } *************** *** 370,374 **** if (sp instanceof SpecialTokenLay && ((SpecialTokenLay)sp).getToken() instanceof BonusToken) { ! bonusTokensExist = true; break loop; } --- 378,383 ---- if (sp instanceof SpecialTokenLay && ((SpecialTokenLay)sp).getToken() instanceof BonusToken) { ! //bonusTokensExist = true; ! gameParameters.put(Defs.Parm.DO_BONUS_TOKENS_EXIST, true); break loop; } *************** *** 973,977 **** */ public boolean canAnyCompanyHoldShares() { ! return canAnyCompanyHoldShares; } --- 982,986 ---- */ public boolean canAnyCompanyHoldShares() { ! return (Boolean) getGameParameter(Defs.Parm.CAN_ANY_COMPANY_HOLD_OWN_SHARES); } *************** *** 1017,1036 **** * @see rails.game.GameManagerI#getCommonParameter(rails.common.Defs.Parm) */ ! public Object getCommonParameter (Defs.Parm key) { ! switch (key) { ! case HAS_ANY_PAR_PRICE: ! return hasAnyParPrice; ! case CAN_ANY_COMPANY_BUY_PRIVATES: ! return canAnyCompanyBuyPrivates; ! case CAN_ANY_COMPANY_HOLD_OWN_SHARES: ! return canAnyCompanyHoldShares; ! case DO_BONUS_TOKENS_EXIST: ! return bonusTokensExist; ! case HAS_ANY_COMPANY_LOANS: ! return hasAnyCompanyLoans; ! default: ! return null; } - } --- 1026,1035 ---- * @see rails.game.GameManagerI#getCommonParameter(rails.common.Defs.Parm) */ ! public Object getGameParameter (Defs.Parm key) { ! if (gameParameters.containsKey(key)) { ! return gameParameters.get(key); ! } else { ! return false; } } Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GameManagerI.java 11 Sep 2009 19:27:23 -0000 1.9 --- GameManagerI.java 12 Sep 2009 19:48:39 -0000 1.10 *************** *** 168,172 **** public abstract int getTreasuryShareLimit(); ! public abstract Object getCommonParameter(Defs.Parm key); public RoundI getInterruptedRound(); --- 168,172 ---- public abstract int getTreasuryShareLimit(); ! public abstract Object getGameParameter(Defs.Parm key); public RoundI getInterruptedRound(); |
From: Erik V. <ev...@us...> - 2009-09-12 19:48:49
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv16351/rails/ui/swing Modified Files: ORPanel.java GameStatus.java GameUIManager.java Log Message: Simplified Defs.ClassName and Defs.Parm handling Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** GameUIManager.java 4 May 2009 20:29:15 -0000 1.17 --- GameUIManager.java 12 Sep 2009 19:48:39 -0000 1.18 *************** *** 525,535 **** } ! public Object getCommonParameter (Defs.Parm key) { ! return gameManager.getCommonParameter(key); } ! public boolean getCommonParameterAsBoolean (Defs.Parm key) { ! ! return (Boolean) getCommonParameter(key); } --- 525,534 ---- } ! public Object getGameParameter (Defs.Parm key) { ! return gameManager.getGameParameter(key); } ! public boolean getGameParameterAsBoolean (Defs.Parm key) { ! return (Boolean) getGameParameter(key); } Index: GameStatus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameStatus.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** GameStatus.java 4 Sep 2009 18:35:53 -0000 1.26 --- GameStatus.java 12 Sep 2009 19:48:39 -0000 1.27 *************** *** 155,162 **** nc = companies.length; ! hasParPrices = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.HAS_ANY_PAR_PRICE); ! compCanBuyPrivates = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.CAN_ANY_COMPANY_BUY_PRIVATES); ! compCanHoldOwnShares = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.CAN_ANY_COMPANY_HOLD_OWN_SHARES); ! hasCompanyLoans = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.HAS_ANY_COMPANY_LOANS); ipo = Bank.getIpo(); --- 155,162 ---- nc = companies.length; ! hasParPrices = gameUIManager.getGameParameterAsBoolean(Defs.Parm.HAS_ANY_PAR_PRICE); ! compCanBuyPrivates = gameUIManager.getGameParameterAsBoolean(Defs.Parm.CAN_ANY_COMPANY_BUY_PRIVATES); ! compCanHoldOwnShares = gameUIManager.getGameParameterAsBoolean(Defs.Parm.CAN_ANY_COMPANY_HOLD_OWN_SHARES); ! hasCompanyLoans = gameUIManager.getGameParameterAsBoolean(Defs.Parm.HAS_ANY_COMPANY_LOANS); ipo = Bank.getIpo(); Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** ORPanel.java 2 Sep 2009 21:47:47 -0000 1.32 --- ORPanel.java 12 Sep 2009 19:48:39 -0000 1.33 *************** *** 138,144 **** round = gameUIManager.getCurrentRound(); ! privatesCanBeBought = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.CAN_ANY_COMPANY_BUY_PRIVATES); ! bonusTokensExist = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.DO_BONUS_TOKENS_EXIST); ! hasCompanyLoans = gameUIManager.getCommonParameterAsBoolean(Defs.Parm.HAS_ANY_COMPANY_LOANS); initButtonPanel(); --- 138,144 ---- round = gameUIManager.getCurrentRound(); ! privatesCanBeBought = gameUIManager.getGameParameterAsBoolean(Defs.Parm.CAN_ANY_COMPANY_BUY_PRIVATES); ! bonusTokensExist = gameUIManager.getGameParameterAsBoolean(Defs.Parm.DO_BONUS_TOKENS_EXIST); ! hasCompanyLoans = gameUIManager.getGameParameterAsBoolean(Defs.Parm.HAS_ANY_COMPANY_LOANS); initButtonPanel(); |
From: Erik V. <ev...@us...> - 2009-09-12 19:48:49
|
Update of /cvsroot/rails/18xx/rails/common In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv16351/rails/common Modified Files: Defs.java Log Message: Simplified Defs.ClassName and Defs.Parm handling Index: Defs.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/common/Defs.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Defs.java 4 May 2009 20:29:15 -0000 1.4 --- Defs.java 12 Sep 2009 19:48:39 -0000 1.5 *************** *** 1,38 **** package rails.common; - import java.util.EnumMap; - public class Defs { ! /* Identifiers and default names for configurable UI classes */ public enum ClassName { ! GAME_UI_MANAGER, ! OR_UI_MANAGER, ! STATUS_WINDOW, ! GAME_STATUS, ! OR_WINDOW ! } ! ! private static EnumMap<Defs.ClassName, String> defaultClasses = ! new EnumMap<Defs.ClassName, String> (Defs.ClassName.class); ! ! static { ! defaultClasses.put (ClassName.GAME_UI_MANAGER, ! "rails.ui.swing.GameUIManager"); ! defaultClasses.put (ClassName.OR_UI_MANAGER, ! "rails.ui.swing.ORUIManager"); ! defaultClasses.put (ClassName.STATUS_WINDOW, ! "rails.ui.swing.StatusWindow"); ! defaultClasses.put (ClassName.GAME_STATUS, ! "rails.ui.swing.GameStatus"); ! defaultClasses.put (ClassName.OR_WINDOW, ! "rails.ui.swing.ORWindow"); ! } public static String getDefaultClassName (ClassName key) { ! return defaultClasses.get(key); } ! /* Definitions for key/value pairs in the communication * between GameManager and GameUIManager. */ --- 1,31 ---- package rails.common; public class Defs { ! /** Identifiers and default names for configurable UI classes */ public enum ClassName { ! ! GAME_UI_MANAGER ("rails.ui.swing.GameUIManager"), ! OR_UI_MANAGER ("rails.ui.swing.ORUIManager"), ! STATUS_WINDOW ("rails.ui.swing.StatusWindow"), ! GAME_STATUS ("rails.ui.swing.GameStatus"), ! OR_WINDOW ("rails.ui.swing.ORWindow"); ! ! private String defaultClassName; ! ! ClassName (String defaultClassName) { ! this.defaultClassName = defaultClassName; ! } ! ! public String getDefaultClassName () { ! return defaultClassName; ! } ! } public static String getDefaultClassName (ClassName key) { ! return key.getDefaultClassName(); } ! /** Definitions for key/value pairs in the communication * between GameManager and GameUIManager. */ |
From: Erik V. <ev...@us...> - 2009-09-12 09:41:08
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv30193/rails/game Modified Files: PublicCompanyI.java PublicCompany.java Player.java Log Message: 1856: Deduct $10 per outstanding loan from player worth. Index: Player.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Player.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Player.java 4 Sep 2009 18:56:16 -0000 1.20 --- Player.java 12 Sep 2009 09:40:56 -0000 1.21 *************** *** 85,89 **** for (PublicCertificateI cert : portfolio.getCertificates()) { ! worth += cert.getCompany().getMarketPrice(); } for (PrivateCompanyI priv : portfolio.getPrivateCompanies()) { --- 85,89 ---- for (PublicCertificateI cert : portfolio.getCertificates()) { ! worth += cert.getCompany().getGameEndPrice(); } for (PrivateCompanyI priv : portfolio.getPrivateCompanies()) { Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** PublicCompany.java 8 Sep 2009 21:48:59 -0000 1.58 --- PublicCompany.java 12 Sep 2009 09:40:56 -0000 1.59 *************** *** 956,959 **** --- 956,968 ---- } } + + /** Return the price per share at game end. + * Normally, it is equal to the market price, + * but in some games (e.g. 1856) deductions may apply. + * @return + */ + public int getGameEndPrice() { + return getMarketPrice(); + } /** Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** PublicCompanyI.java 6 Sep 2009 12:27:32 -0000 1.34 --- PublicCompanyI.java 12 Sep 2009 09:40:56 -0000 1.35 *************** *** 145,149 **** public int getMarketPrice (); ! public int getPublicNumber(); --- 145,150 ---- public int getMarketPrice (); ! public int getGameEndPrice(); ! public int getPublicNumber(); |
From: Erik V. <ev...@us...> - 2009-09-12 09:41:05
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv30193/rails/game/specific/_1856 Modified Files: PublicCompany_1856.java OperatingRound_1856.java Log Message: 1856: Deduct $10 per outstanding loan from player worth. Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** OperatingRound_1856.java 6 Sep 2009 12:27:31 -0000 1.20 --- OperatingRound_1856.java 12 Sep 2009 09:40:56 -0000 1.21 *************** *** 360,364 **** PhaseI postPhase = currentPhase; ! log.debug("+++Phase was "+prePhase.getName()+" now "+postPhase.getName()); if (postPhase != prePhase && postPhase.getName().equals("5")) { finalLoanRepaymentPending.set(true); --- 360,364 ---- PhaseI postPhase = currentPhase; ! if (postPhase != prePhase && postPhase.getName().equals("5")) { finalLoanRepaymentPending.set(true); Index: PublicCompany_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_1856.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PublicCompany_1856.java 4 Sep 2009 18:40:30 -0000 1.7 --- PublicCompany_1856.java 12 Sep 2009 09:40:55 -0000 1.8 *************** *** 63,66 **** --- 63,70 ---- if (train.getType().isPermanent()) hadPermanentTrain = true; } + + public int getGameEndPrice() { + return Math.max(0, getMarketPrice() - 10 * getCurrentNumberOfLoans()); + } } |
From: Erik V. <ev...@us...> - 2009-09-11 19:27:39
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv23159/rails/game Modified Files: StartRound_1830.java StartItem.java Game.java CompanyManagerI.java Round.java StartPacket.java CompanyManager.java PhaseManager.java GameManagerI.java GameManager.java Log Message: Rationalisation of StartPacket/StartItem initialisation code. Statics removed. Index: StartItem.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartItem.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** StartItem.java 8 Jan 2009 19:59:39 -0000 1.16 --- StartItem.java 11 Sep 2009 19:27:23 -0000 1.17 *************** *** 26,35 **** protected int row = 0; protected int column = 0; ! protected int index = nextIndex++; // Bids protected IntegerState lastBidderIndex; ! protected static List<Player> players; ! protected static int numberOfPlayers; protected MoneyModel[] bids; protected MoneyModel minimumBid; --- 26,35 ---- protected int row = 0; protected int column = 0; ! protected int index; // Bids protected IntegerState lastBidderIndex; ! protected List<Player> players; ! protected int numberOfPlayers; protected MoneyModel[] bids; protected MoneyModel minimumBid; *************** *** 67,74 **** // Static properties ! protected static Portfolio ipo; ! protected static Portfolio unavailable; ! protected static CompanyManagerI compMgr; ! protected static int nextIndex = 0; protected static Map<String, StartItem> startItemMap; --- 67,74 ---- // Static properties ! //protected static Portfolio ipo; ! //protected static Portfolio unavailable; ! //protected static CompanyManagerI compMgr; ! //protected static int nextIndex = 0; protected static Map<String, StartItem> startItemMap; *************** *** 90,98 **** * share. */ ! public StartItem(String name, String type, int basePrice, boolean president) { this.name = name; this.type = type; this.basePrice = new MoneyModel(name + "_basePrice"); this.basePrice.set(basePrice); this.president = president; status = new IntegerState(name + "_status"); --- 90,99 ---- * share. */ ! public StartItem(String name, String type, int basePrice, int index, boolean president) { this.name = name; this.type = type; this.basePrice = new MoneyModel(name + "_basePrice"); this.basePrice.set(basePrice); + this.index = index; this.president = president; status = new IntegerState(name + "_status"); *************** *** 124,132 **** * after IPO initialisation. */ ! public void init() { ! if (players == null) { ! players = Game.getPlayerManager().getPlayers(); ! numberOfPlayers = players.size(); ! } bids = new MoneyModel[numberOfPlayers]; for (int i = 0; i < numberOfPlayers; i++) { --- 125,132 ---- * after IPO initialisation. */ ! public void init(GameManagerI gameManager) { ! ! this.players = gameManager.getPlayers(); ! numberOfPlayers = players.size(); bids = new MoneyModel[numberOfPlayers]; for (int i = 0; i < numberOfPlayers; i++) { *************** *** 140,146 **** minimumBid.set(basePrice.intValue() + 5); ! if (ipo == null) ipo = Bank.getIpo(); ! if (unavailable == null) unavailable = Bank.getUnavailable(); ! if (compMgr == null) compMgr = Game.getCompanyManager(); CompanyI company = compMgr.getCompany(type, name); --- 140,147 ---- minimumBid.set(basePrice.intValue() + 5); ! Portfolio ipo = Bank.getIpo(); ! Portfolio unavailable = Bank.getUnavailable(); ! ! CompanyManagerI compMgr = gameManager.getCompanyManager(); CompanyI company = compMgr.getCompany(type, name); *************** *** 367,372 **** * @return True if this player has done any bids. */ ! public boolean hasBid(String playerName) { ! Player player = Game.getPlayerManager().getPlayerByName(playerName); int index = player.getIndex(); return bids[index].intValue() > 0; --- 368,372 ---- * @return True if this player has done any bids. */ ! public boolean hasBid(Player player) { int index = player.getIndex(); return bids[index].intValue() > 0; *************** *** 379,387 **** * @return His latest Bid object. */ ! public int getBidForPlayer(String playerName) { ! Player player = Game.getPlayerManager().getPlayerByName(playerName); ! int index = player.getIndex(); ! return bids[index].intValue(); ! } /** --- 379,387 ---- * @return His latest Bid object. */ ! //public int getBidForPlayer(String playerName) { ! // Player player = Game.getPlayerManager().getPlayerByName(playerName); ! // int index = player.getIndex(); ! // return bids[index].intValue(); ! //} /** Index: PhaseManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PhaseManager.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PhaseManager.java 8 Sep 2009 21:48:59 -0000 1.14 --- PhaseManager.java 11 Sep 2009 19:27:23 -0000 1.15 *************** *** 42,52 **** previousPhase = phase; } - PhaseI initialPhase = phaseList.get(0); - setPhase(initialPhase); - } public void init (GameManagerI gameManager) { this.gameManager = gameManager; } --- 42,51 ---- previousPhase = phase; } } public void init (GameManagerI gameManager) { this.gameManager = gameManager; + PhaseI initialPhase = phaseList.get(0); + setPhase(initialPhase); } Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** GameManager.java 8 Sep 2009 21:48:59 -0000 1.50 --- GameManager.java 11 Sep 2009 19:27:23 -0000 1.51 *************** *** 48,51 **** --- 48,52 ---- protected TrainManagerI trainManager; protected StockMarketI stockMarket; + protected Bank bank; protected List<Player> players; *************** *** 317,325 **** * @see rails.game.GameManagerI#startGame(rails.game.PlayerManager, rails.game.CompanyManagerI, rails.game.PhaseManager) */ ! public void startGame(PlayerManager playerManager, CompanyManagerI companyManager, PhaseManager phaseManager, TrainManagerI trainManager, ! StockMarketI stockMarket) { this.playerManager = playerManager; this.companyManager = companyManager; --- 318,327 ---- * @see rails.game.GameManagerI#startGame(rails.game.PlayerManager, rails.game.CompanyManagerI, rails.game.PhaseManager) */ ! public void init(PlayerManager playerManager, CompanyManagerI companyManager, PhaseManager phaseManager, TrainManagerI trainManager, ! StockMarketI stockMarket, ! Bank bank) { this.playerManager = playerManager; this.companyManager = companyManager; *************** *** 327,330 **** --- 329,333 ---- this.trainManager = trainManager; this.stockMarket = stockMarket; + this.bank = bank; players = playerManager.getPlayers(); *************** *** 333,342 **** priorityPlayer.setState(players.get(0)); setPlayerCertificateLimit (playerManager.getInitialPlayerCertificateLimit()); ! setGameParameters(); if (startPacket == null) ! startPacket = StartPacket.getStartPacket("Initial"); if (startPacket != null && !startPacket.areAllSold()) { // If we have a non-exhausted start packet startStartRound(); --- 336,350 ---- priorityPlayer.setState(players.get(0)); setPlayerCertificateLimit (playerManager.getInitialPlayerCertificateLimit()); + } ! public void startGame() { ! ! setGameParameters(); if (startPacket == null) ! startPacket = companyManager.getStartPacket(StartPacket.DEFAULT_NAME); if (startPacket != null && !startPacket.areAllSold()) { + startPacket.init(this); + // If we have a non-exhausted start packet startStartRound(); *************** *** 413,418 **** } } else if (round instanceof StockRound) { ! PhaseI currentPhase = phaseManager.getCurrentPhase(); ! numOfORs = currentPhase.getNumberOfOperatingRounds(); log.info("Phase=" + currentPhase.getName() + " ORs=" + numOfORs); --- 421,426 ---- } } else if (round instanceof StockRound) { ! PhaseI currentPhase = getCurrentPhase(); ! numOfORs = getCurrentPhase().getNumberOfOperatingRounds(); log.info("Phase=" + currentPhase.getName() + " ORs=" + numOfORs); *************** *** 938,941 **** --- 946,953 ---- } + public Bank getBank () { + return bank; + } + // TODO Should be removed public void initialiseNewPhase(PhaseI phase) { Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Round.java 4 Sep 2009 18:56:15 -0000 1.21 --- Round.java 11 Sep 2009 19:27:23 -0000 1.22 *************** *** 10,17 **** import org.apache.log4j.Logger; ! import rails.game.action.ExchangeTokens; ! import rails.game.action.ExchangeableToken; ! import rails.game.action.PossibleAction; ! import rails.game.action.PossibleActions; import rails.game.move.CashMove; import rails.game.move.MoveSet; --- 10,14 ---- import org.apache.log4j.Logger; ! import rails.game.action.*; import rails.game.move.CashMove; import rails.game.move.MoveSet; *************** *** 33,43 **** protected CompanyManagerI companyManager = null; protected PlayerManager playerManager = null; ! protected Class<? extends RoundI> roundTypeForUI = null; protected BooleanState wasInterrupted = new BooleanState ("RoundInterrupted", false); - /** Default constructor cannot be used */ - private Round () {} - /** * Constructor with the GameManager, will call setGameManager with the parameter to initialize --- 30,37 ---- protected CompanyManagerI companyManager = null; protected PlayerManager playerManager = null; ! protected Class<? extends RoundI> roundTypeForUI = null; protected BooleanState wasInterrupted = new BooleanState ("RoundInterrupted", false); /** * Constructor with the GameManager, will call setGameManager with the parameter to initialize *************** *** 129,140 **** protected boolean exchangeTokens (ExchangeTokens action) { ! String errMsg = null; ! List<ExchangeableToken> tokens = action.getTokensToExchange(); int min = action.getMinNumberToExchange(); int max = action.getMaxNumberToExchange(); int exchanged = 0; ! checks: { --- 123,134 ---- protected boolean exchangeTokens (ExchangeTokens action) { ! String errMsg = null; ! List<ExchangeableToken> tokens = action.getTokensToExchange(); int min = action.getMinNumberToExchange(); int max = action.getMaxNumberToExchange(); int exchanged = 0; ! checks: { *************** *** 160,164 **** MoveSet.start(true); ! if (exchanged > 0) { MapHex hex; --- 154,158 ---- MoveSet.start(true); ! if (exchanged > 0) { MapHex hex; *************** *** 168,172 **** String[] ct; PublicCompanyI comp = action.getCompany(); ! for (ExchangeableToken token : tokens) { cityName = token.getCityName(); --- 162,166 ---- String[] ct; PublicCompanyI comp = action.getCompany(); ! for (ExchangeableToken token : tokens) { cityName = token.getCityName(); *************** *** 182,186 **** if (token.isSelected()) { ! // For now we'll assume that the old token(s) have already been removed. // This is true in the 1856 CGR formation. --- 176,180 ---- if (token.isSelected()) { ! // For now we'll assume that the old token(s) have already been removed. // This is true in the 1856 CGR formation. *************** *** 188,192 **** /* TODO: the false return value must be impossible. */ ReportBuffer.add(LocalText.getText("ExchangesBaseToken", ! comp.getName(), token.getOldCompanyName(), city.getName())); --- 182,186 ---- /* TODO: the false return value must be impossible. */ ReportBuffer.add(LocalText.getText("ExchangesBaseToken", ! comp.getName(), token.getOldCompanyName(), city.getName())); *************** *** 200,207 **** } } ! return true; } ! /** --- 194,201 ---- } } ! return true; } ! /** *************** *** 323,332 **** } } ! protected void finishRound() { // Inform GameManager gameManager.nextRound(this); } ! public boolean wasInterrupted () { return wasInterrupted.booleanValue(); --- 317,326 ---- } } ! protected void finishRound() { // Inform GameManager gameManager.nextRound(this); } ! public boolean wasInterrupted () { return wasInterrupted.booleanValue(); *************** *** 365,368 **** } ! } --- 359,362 ---- } ! } Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Game.java 8 Sep 2009 21:48:59 -0000 1.26 --- Game.java 11 Sep 2009 19:27:23 -0000 1.27 *************** *** 67,72 **** public void start() { ! gameManager.startGame(playerManager, companyManager, ! phaseManager, trainManager, stockMarket); } --- 67,71 ---- public void start() { ! gameManager.startGame(); } *************** *** 152,160 **** */ playerManager.setPlayers(players, playerManager.getStartCash()); ! companyManager.initCompanies(gameManager); trainManager.init(gameManager); bank.initCertificates(); ! StartPacket.init(); //companyManager.initCompanies(gameManager); stockMarket.init(); --- 151,162 ---- */ playerManager.setPlayers(players, playerManager.getStartCash()); + gameManager.init(playerManager, companyManager, + phaseManager, trainManager, stockMarket, bank); ! companyManager.initCompanies(gameManager, playerManager.getPlayers()); trainManager.init(gameManager); + phaseManager.init(gameManager); bank.initCertificates(); ! //StartPacket.init(); //companyManager.initCompanies(gameManager); stockMarket.init(); Index: StartRound_1830.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound_1830.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** StartRound_1830.java 19 Jul 2009 19:24:21 -0000 1.19 --- StartRound_1830.java 11 Sep 2009 19:27:23 -0000 1.20 *************** *** 40,44 **** possibleActions.clear(); ! if (StartPacket.getStartPacket().areAllSold()) return false; while (possibleActions.isEmpty()) { --- 40,44 ---- possibleActions.clear(); ! if (startPacket.areAllSold()) return false; while (possibleActions.isEmpty()) { *************** *** 133,137 **** * loop. go to next round if that happened */ ! if (StartPacket.getStartPacket().areAllSold()) { return false; } --- 133,137 ---- * loop. go to next round if that happened */ ! if (gameManager.getStartPacket().areAllSold()) { return false; } *************** *** 352,356 **** for (int i = currentIndex + 1; i < currentIndex + gameManager.getNumberOfPlayers(); i++) { ! if (item.hasBid(gameManager.getPlayerByIndex(i).getName())) { setCurrentPlayerIndex(i); break; --- 352,356 ---- for (int i = currentIndex + 1; i < currentIndex + gameManager.getNumberOfPlayers(); i++) { ! if (item.hasBid(gameManager.getPlayerByIndex(i))) { setCurrentPlayerIndex(i); break; Index: StartPacket.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartPacket.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** StartPacket.java 11 Dec 2008 20:12:07 -0000 1.12 --- StartPacket.java 11 Sep 2009 19:27:23 -0000 1.13 *************** *** 2,6 **** package rails.game; ! import java.util.*; import org.apache.log4j.Logger; --- 2,7 ---- package rails.game; ! import java.util.ArrayList; ! import java.util.List; import org.apache.log4j.Logger; *************** *** 20,25 **** * than one, e.g. 18US). */ ! private static Map<String, StartPacket> packets = ! new HashMap<String, StartPacket>(); /** --- 21,26 ---- * than one, e.g. 18US). */ ! //private static Map<String, StartPacket> packets = ! // new HashMap<String, StartPacket>(); /** *************** *** 55,59 **** this.name = Util.hasValue(name) ? name : DEFAULT_NAME; this.roundClassName = roundClassName; ! packets.put(name, this); } --- 56,60 ---- this.name = Util.hasValue(name) ? name : DEFAULT_NAME; this.roundClassName = roundClassName; ! //packets.put(name, this); } *************** *** 69,73 **** if (biddingTag != null) { minimumInitialIncrement = ! biddingTag.getAttributeAsInteger("ïnitial", minimumInitialIncrement); minimumIncrement = --- 70,74 ---- if (biddingTag != null) { minimumInitialIncrement = ! biddingTag.getAttributeAsInteger("initial", minimumInitialIncrement); minimumIncrement = *************** *** 78,81 **** --- 79,83 ---- List<Tag> itemTags = tag.getChildren("Item"); + int index = 0; for (Tag itemTag : itemTags) { // Extract the attributes of the Start Packet Item (certificate) *************** *** 91,95 **** int basePrice = itemTag.getAttributeAsInteger("basePrice", 0); StartItem item = ! (new StartItem(itemName, itemType, basePrice, president)); items.add(item); --- 93,97 ---- int basePrice = itemTag.getAttributeAsInteger("basePrice", 0); StartItem item = ! (new StartItem(itemName, itemType, basePrice, index++, president)); items.add(item); *************** *** 127,135 **** * each one contains. */ ! protected static void init() { ! for (StartPacket sp : packets.values()) { ! for (StartItem item : sp.items) { ! item.init(); ! } } } --- 129,135 ---- * each one contains. */ ! protected void init(GameManagerI gameManager) { ! for (StartItem item : items) { ! item.init(gameManager); } } *************** *** 141,147 **** * @return The start packet (or null if it does not exist). */ ! public static StartPacket getStartPacket(String name) { ! return packets.get(name); ! } /** --- 141,147 ---- * @return The start packet (or null if it does not exist). */ ! //public static StartPacket getStartPacket(String name) { ! // return packets.get(name); ! //} /** *************** *** 150,156 **** * @return The default start packet (or null if it does not exist). */ ! public static StartPacket getStartPacket() { ! return getStartPacket(DEFAULT_NAME); ! } /** --- 150,156 ---- * @return The default start packet (or null if it does not exist). */ ! //public static StartPacket getStartPacket() { ! // return getStartPacket(DEFAULT_NAME); ! //} /** Index: CompanyManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManager.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** CompanyManager.java 24 Jan 2009 15:10:27 -0000 1.14 --- CompanyManager.java 11 Sep 2009 19:27:23 -0000 1.15 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, HashMap<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, HashMap<String, CompanyI>>(); /** A list of all start packets (usually one) */ // TODO Currently not used (but some newer games have more than one) private List<StartPacket> startPackets = new ArrayList<StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); ((Map<String, CompanyI>) mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name"); if (name == null) name = "Initial"; String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); sp.configureFromXML(packetTag); } } /* Read and configure additional rules */ /* This part may move later to a GameRules or GameManager XML */ Tag rulesTag = tag.getChild("StockRoundRules"); if (rulesTag != null) { for (String ruleTagName : rulesTag.getChildren().keySet()) { if (ruleTagName.equals("NoSaleInFirstSR")) { StockRound.setNoSaleInFirstSR(); } else if (ruleTagName.equals("NoSaleIfNotOperated")) { StockRound.setNoSaleIfNotOperated(); } } } } // Post XML parsing initialisations public void initCompanies(GameManagerI gameManager) throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.init2(gameManager); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, HashMap<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, HashMap<String, CompanyI>>(); /** A list of all start packets (usually one) */ private List<StartPacket> startPackets = new ArrayList<StartPacket>(); /** A map of all start packets, keyed by name. Default name is "Initial" */ private Map<String, StartPacket> startPacketMap = new HashMap<String, StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); ((Map<String, CompanyI>) mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name", StartPacket.DEFAULT_NAME); String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); startPacketMap.put(name, sp); sp.configureFromXML(packetTag); } } /* Read and configure additional rules */ /* This part may move later to a GameRules or GameManager XML */ Tag rulesTag = tag.getChild("StockRoundRules"); if (rulesTag != null) { for (String ruleTagName : rulesTag.getChildren().keySet()) { if (ruleTagName.equals("NoSaleInFirstSR")) { StockRound.setNoSaleInFirstSR(); } else if (ruleTagName.equals("NoSaleIfNotOperated")) { StockRound.setNoSaleIfNotOperated(); } } } } // Post XML parsing initialisations public void initCompanies(GameManagerI gameManager, List<Player> players ) throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.init2(gameManager); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } public StartPacket getStartPacket (int index) { return startPackets.get(index); } public StartPacket getStartPacket (String name) { return startPacketMap.get(name); } } \ No newline at end of file Index: CompanyManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManagerI.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** CompanyManagerI.java 24 Jan 2009 15:10:26 -0000 1.11 --- CompanyManagerI.java 11 Sep 2009 19:27:23 -0000 1.12 *************** *** 58,62 **** /** Post XML parsing initialisations */ ! public void initCompanies(GameManagerI gameManager) throws ConfigurationException; public void closeAllPrivates(); --- 58,63 ---- /** Post XML parsing initialisations */ ! public void initCompanies(GameManagerI gameManager, List<Player> players) ! throws ConfigurationException; public void closeAllPrivates(); *************** *** 64,66 **** --- 65,70 ---- public List<PrivateCompanyI> getPrivatesOwnedByPlayers(); + public StartPacket getStartPacket (int index); + public StartPacket getStartPacket (String name); + } Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GameManagerI.java 8 Sep 2009 21:48:59 -0000 1.8 --- GameManagerI.java 11 Sep 2009 19:27:23 -0000 1.9 *************** *** 16,22 **** throws ConfigurationException; ! public abstract void startGame(PlayerManager playerManager, CompanyManagerI companyManager, PhaseManager phaseManager, ! TrainManagerI trainManager, StockMarketI stockMarket); public abstract CompanyManagerI getCompanyManager(); --- 16,24 ---- throws ConfigurationException; ! public abstract void init(PlayerManager playerManager, CompanyManagerI companyManager, PhaseManager phaseManager, ! TrainManagerI trainManager, StockMarketI stockMarket, ! Bank bank); ! public abstract void startGame(); public abstract CompanyManagerI getCompanyManager(); *************** *** 148,151 **** --- 150,154 ---- public PlayerManager getPlayerManager(); public StockMarketI getStockMarket(); + public Bank getBank (); public int getPlayerCertificateLimit(); |