From: Erik V. <ev...@us...> - 2009-09-04 18:40:39
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv27615/rails/game/specific/_1856 Modified Files: CGRFormationRound.java PublicCompany_1856.java OperatingRound_1856.java Added Files: PublicCompany_CGR.java Log Message: Renamed PublicCompany_State to PublicCompany_CGR. Centralized CGR name there. Moved player limits to GameManager. Some method renaming. Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CGRFormationRound.java 3 Sep 2009 21:36:53 -0000 1.13 --- CGRFormationRound.java 4 Sep 2009 18:40:29 -0000 1.14 *************** *** 13,18 **** public class CGRFormationRound extends SwitchableUIRound { - private final String CGRNAME = "CGR"; - private Player startingPlayer; private Map<Player, List<PublicCompanyI>> companiesToRepayLoans = null; --- 13,16 ---- *************** *** 20,25 **** private int maxLoansToRepayByPresident = 0; private List<PublicCompanyI> mergingCompanies = new ArrayList<PublicCompanyI>(); ! private PublicCompany_State cgr = (PublicCompany_State)gameManager.getCompanyManager().getCompanyByName(CGRNAME); ! private String cgrName = CGRNAME; private List<TrainI> trainsToDiscardFrom = null; private boolean forcedTrainDiscard = true; --- 18,24 ---- private int maxLoansToRepayByPresident = 0; private List<PublicCompanyI> mergingCompanies = new ArrayList<PublicCompanyI>(); ! private String cgrName = PublicCompany_CGR.NAME; ! private PublicCompany_CGR cgr ! = (PublicCompany_CGR)gameManager.getCompanyManager().getCompanyByName(cgrName); private List<TrainI> trainsToDiscardFrom = null; private boolean forcedTrainDiscard = true; *************** *** 186,190 **** message = LocalText.getText("WillMergeInto", currentCompany.getName(), ! "CGR"); DisplayBuffer.add(message, false); ReportBuffer.add(message); --- 185,189 ---- message = LocalText.getText("WillMergeInto", currentCompany.getName(), ! PublicCompany_CGR.NAME); DisplayBuffer.add(message, false); ReportBuffer.add(message); *************** *** 264,268 **** String message = LocalText.getText("WillMergeInto", currentCompany.getName(), ! "CGR"); DisplayBuffer.add(message, true); ReportBuffer.add(message); --- 263,267 ---- String message = LocalText.getText("WillMergeInto", currentCompany.getName(), ! PublicCompany_CGR.NAME); DisplayBuffer.add(message, true); ReportBuffer.add(message); *************** *** 334,338 **** oldShares, newShares, ! "CGR"); DisplayBuffer.add(message, false); ReportBuffer.add(message); --- 333,337 ---- oldShares, newShares, ! PublicCompany_CGR.NAME); DisplayBuffer.add(message, false); ReportBuffer.add(message); *************** *** 389,393 **** oldShares, newShares, ! "CGR"); DisplayBuffer.add(message); ReportBuffer.add(message); --- 388,392 ---- oldShares, newShares, ! PublicCompany_CGR.NAME); DisplayBuffer.add(message); ReportBuffer.add(message); *************** *** 402,406 **** // unit becomes 10%; otherwise it stays 5%. if (cgrSharesUsed <=10) { ! (cgr).setShareUnit (10); // All superfluous shares have been removed } --- 401,405 ---- // unit becomes 10%; otherwise it stays 5%. if (cgrSharesUsed <=10) { ! cgr.setShareUnit (10); // All superfluous shares have been removed } *************** *** 412,416 **** // Move the remaining CGR shares to the ipo. // Clone the shares list first ! certs = new ArrayList<PublicCertificateI>(unavailable.getCertificatesPerCompany("CGR")); for (PublicCertificateI cert : certs) { cert.moveTo(ipo); --- 411,416 ---- // Move the remaining CGR shares to the ipo. // Clone the shares list first ! certs = new ArrayList<PublicCertificateI> ! (unavailable.getCertificatesPerCompany(PublicCompany_CGR.NAME)); for (PublicCertificateI cert : certs) { cert.moveTo(ipo); *************** *** 465,469 **** cgr.start(startSpace); message = LocalText.getText("START_MERGED_COMPANY", ! "CGR", Bank.format(startSpace.getPrice()), startSpace.getName()); --- 465,469 ---- cgr.start(startSpace); message = LocalText.getText("START_MERGED_COMPANY", ! PublicCompany_CGR.NAME, Bank.format(startSpace.getPrice()), startSpace.getName()); *************** *** 474,478 **** } cgr.setFloated(); ! ReportBuffer.add (LocalText.getText("Floats", "CGR")); // Collect the old token spots, and move cash and trains --- 474,478 ---- } cgr.setFloated(); ! ReportBuffer.add (LocalText.getText("Floats", PublicCompany_CGR.NAME)); // Collect the old token spots, and move cash and trains *************** *** 595,599 **** // Need some checks here... int newCertLimit = certLimitsTable[numPlayers-3][numCompanies-4]; ! playerManager.setPlayerCertificateLimit(newCertLimit); message = LocalText.getText("CertificateLimit", newCertLimit, --- 595,599 ---- // Need some checks here... int newCertLimit = certLimitsTable[numPlayers-3][numCompanies-4]; ! gameManager.setPlayerCertificateLimit(newCertLimit); message = LocalText.getText("CertificateLimit", newCertLimit, Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** OperatingRound_1856.java 3 Sep 2009 18:33:26 -0000 1.18 --- OperatingRound_1856.java 4 Sep 2009 18:40:30 -0000 1.19 *************** *** 17,21 **** public static final int STEP_REPAY_LOANS = 6; - private final String CGRNAME = "CGR"; static { --- 17,20 ---- *************** *** 66,70 **** // 1856 special: check if the company has sold enough shares to operate // This check does not apply to the CGR ! if (operatingCompany.getName().equals(CGRNAME)) return true; if (!operatingCompany.hasOperated()) { int soldPercentage --- 65,69 ---- // 1856 special: check if the company has sold enough shares to operate // This check does not apply to the CGR ! if (operatingCompany instanceof PublicCompany_CGR) return true; if (!operatingCompany.hasOperated()) { int soldPercentage *************** *** 108,115 **** if (operatingCompany.canRunTrains()) { ! if (operatingCompany instanceof PublicCompany_State ! && ((PublicCompany_State)operatingCompany).runsWithBorrowedTrain()) { DisplayBuffer.add(LocalText.getText("RunsWithBorrowedTrain", ! "CGR", "D")); possibleActions.add(new SetDividend( operatingCompany.getLastRevenue(), true, --- 107,114 ---- if (operatingCompany.canRunTrains()) { ! if (operatingCompany instanceof PublicCompany_CGR ! && ((PublicCompany_CGR)operatingCompany).runsWithBorrowedTrain()) { DisplayBuffer.add(LocalText.getText("RunsWithBorrowedTrain", ! PublicCompany_CGR.NAME, "D")); possibleActions.add(new SetDividend( operatingCompany.getLastRevenue(), true, *************** *** 462,466 **** List<PublicCompanyI> companies = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); ! PublicCompanyI cgr = companyManager.getCompanyByName("CGR"); boolean cgrCanOperate = cgr.hasStarted(); --- 461,465 ---- List<PublicCompanyI> companies = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); ! PublicCompanyI cgr = companyManager.getCompanyByName(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); Index: PublicCompany_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_1856.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PublicCompany_1856.java 5 Aug 2009 20:55:05 -0000 1.6 --- PublicCompany_1856.java 4 Sep 2009 18:40:30 -0000 1.7 *************** *** 1,10 **** package rails.game.specific._1856; - import java.util.ArrayList; - import java.util.List; - import rails.game.*; - import rails.game.move.MoveableHolderI; - import rails.game.move.RemoveFromList; import rails.game.state.IntegerState; --- 1,5 ---- *************** *** 69,104 **** } - public void setShareUnit (int percentage) { - // Only allowed for CGR, the value must be 10 - if (name.equalsIgnoreCase("CGR") && shareUnit.intValue() == 5 - && percentage == 10) { - shareUnit.set(percentage); - // Drop the last 10 shares - List<PublicCertificateI>certs = new ArrayList<PublicCertificateI>(certificates); - int share = 0; - MoveableHolderI scrapHeap = Bank.getScrapHeap(); - for (PublicCertificateI cert : certs) { - if (share >= 100) { - cert.moveTo(scrapHeap); - new RemoveFromList<PublicCertificateI>(certificates, cert, "CGR_Certs"); - } else { - share += cert.getShare(); - } - } - - // Update all owner ShareModels (once) - // to have the UI get the correct percentage - List<Portfolio> done = new ArrayList<Portfolio>(); - Portfolio portfolio; - for (PublicCertificateI cert : certificates) { - portfolio = (Portfolio)cert.getHolder(); - if (!done.contains(portfolio)) { - portfolio.getShareModel(this).setShare(); - done.add(portfolio); - } - } - } - - } - } --- 64,66 ---- --- NEW FILE: PublicCompany_CGR.java --- package rails.game.specific._1856; import java.util.ArrayList; import java.util.List; import rails.game.*; import rails.game.move.*; import rails.game.state.BooleanState; public class PublicCompany_CGR extends PublicCompany { public static final String NAME = "CGR"; /** Used for CGR */ private BooleanState hadPermanentTrain; /** Initialisation, to be called directly after instantiation (cloning) */ @Override public void init(String name, CompanyTypeI type) { super.init(name, type); hadPermanentTrain = new BooleanState (name+"_HadPermanentTrain", false); // Share price is initially fixed canSharePriceVary.set(false); } public boolean hadPermanentTrain() { return hadPermanentTrain.booleanValue(); } public void setHadPermanentTrain(boolean hadPermanentTrain) { this.hadPermanentTrain.set(hadPermanentTrain); canSharePriceVary.set(true); } @Override public boolean canRunTrains() { if (!hadPermanentTrain()) { return true; } return getNumberOfTrains() > 0; } public boolean runsWithBorrowedTrain () { return !hadPermanentTrain() && getNumberOfTrains() == 0; } /** * CGR share price does not move until a permanent train is bought. * * @param The revenue amount. */ @Override public void withhold(int amount) { if (amount > 0) new CashMove(null, this, amount); if (hasStockPrice && !runsWithBorrowedTrain()) { Game.getStockMarket().withhold(this); } } @Override public void buyTrain(TrainI train, int price) { super.buyTrain (train, price); if (train.getType().isPermanent()) setHadPermanentTrain(true); } public void setShareUnit (int percentage) { // Only allowed for CGR, the value must be 10 if (shareUnit.intValue() == 5 && percentage == 10) { shareUnit.set(percentage); // Drop the last 10 shares List<PublicCertificateI>certs = new ArrayList<PublicCertificateI>(certificates); int share = 0; MoveableHolderI scrapHeap = Bank.getScrapHeap(); for (PublicCertificateI cert : certs) { if (share >= 100) { cert.moveTo(scrapHeap); new RemoveFromList<PublicCertificateI>(certificates, cert, "CGR_Certs"); } else { cert.setCertificateCount(1.0f); share += cert.getShare(); } } // Update all owner ShareModels (once) // to have the UI get the correct percentage List<Portfolio> done = new ArrayList<Portfolio>(); Portfolio portfolio; for (PublicCertificateI cert : certificates) { portfolio = (Portfolio)cert.getHolder(); if (!done.contains(portfolio)) { portfolio.getShareModel(this).setShare(); done.add(portfolio); } } } } @Override public boolean mustOwnATrain() { if (!hadPermanentTrain()) { return false; } else { return super.mustOwnATrain(); } } } |