From: Erik V. <ev...@us...> - 2009-08-28 20:27:50
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29002/rails/game/specific/_1856 Modified Files: CGRFormationRound.java OperatingRound_1856.java Added Files: PublicCompany_State.java Log Message: Split off new class PublicCompany_State for 1856 CGR --- NEW FILE: PublicCompany_State.java --- 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; public class PublicCompany_State extends PublicCompany { /** Used for CGR */ private boolean hadPermanentTrain = false; public boolean hadPermanentTrain() { return hadPermanentTrain; } @Override public void buyTrain(TrainI train, int price) { super.buyTrain (train, price); if (train.getType().isPermanent()) hadPermanentTrain = 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 { 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); } } } } } Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** CGRFormationRound.java 3 Aug 2009 21:27:19 -0000 1.9 --- CGRFormationRound.java 28 Aug 2009 20:27:38 -0000 1.10 *************** *** 26,30 **** private List<ExchangeableToken> tokensToExchangeFrom = null; private List<BaseToken> nonHomeTokens = null; ! private IntegerState stepObject = new IntegerState ("CGRFormStep", 0); --- 26,30 ---- private List<ExchangeableToken> tokensToExchangeFrom = null; private List<BaseToken> nonHomeTokens = null; ! private IntegerState stepObject = new IntegerState ("CGRFormStep", 0); *************** *** 71,75 **** } } ! if (companiesToRepayLoans == null) { finishRound(); --- 71,75 ---- } } ! if (companiesToRepayLoans == null) { finishRound(); *************** *** 83,91 **** process (null); } ! private void setStep(int step) { stepObject.set(step); } ! private int getStep() { return stepObject.intValue(); --- 83,91 ---- process (null); } ! private void setStep(int step) { stepObject.set(step); } ! private int getStep() { return stepObject.intValue(); *************** *** 216,233 **** protected boolean repayLoans (RepayLoans action) { ! // TODO Validation skipped for now... MoveSet.start(true); ! PublicCompanyI company = action.getCompany(); int numberRepaid = action.getNumberRepaid(); int repayment = numberRepaid * company.getValuePerLoan(); ! if (repayment > 0) { ! int repaymentByCompany = Math.min (repayment, company.getCash()); int repaymentByPresident = repayment - repaymentByCompany; ! company.addLoans(-numberRepaid); if (repaymentByCompany > 0) { --- 216,233 ---- protected boolean repayLoans (RepayLoans action) { ! // TODO Validation skipped for now... MoveSet.start(true); ! PublicCompanyI company = action.getCompany(); int numberRepaid = action.getNumberRepaid(); int repayment = numberRepaid * company.getValuePerLoan(); ! if (repayment > 0) { ! int repaymentByCompany = Math.min (repayment, company.getCash()); int repaymentByPresident = repayment - repaymentByCompany; ! company.addLoans(-numberRepaid); if (repaymentByCompany > 0) { *************** *** 303,309 **** } } ! if (oldShares > 0) { ! count = oldShares; if (count >= 4 && temporaryPresident == null && cgrSharesUsed <= 18) { --- 303,309 ---- } } ! if (oldShares > 0) { ! count = oldShares; if (count >= 4 && temporaryPresident == null && cgrSharesUsed <= 18) { *************** *** 322,326 **** newShares++; } ! String message = LocalText.getText("HasMergedShares", player.getName(), --- 322,326 ---- newShares++; } ! String message = LocalText.getText("HasMergedShares", player.getName(), *************** *** 330,334 **** DisplayBuffer.add(message, false); ReportBuffer.add(message); ! if (count == 1) { // Should work OK even if this is a president's share. --- 330,334 ---- DisplayBuffer.add(message, false); ReportBuffer.add(message); ! if (count == 1) { // Should work OK even if this is a president's share. *************** *** 337,351 **** poolCert.moveTo(pool); certs.remove(poolCert); ! message = LocalText.getText("HasPutShareInPool", player.getName()); DisplayBuffer.add(message, false); ReportBuffer.add(message); ! } // Note: old shares are removed when company is closed ! if (firstCGRowner == null) firstCGRowner = player; ! // Check for presidency if (newShares > maxShares) { --- 337,351 ---- poolCert.moveTo(pool); certs.remove(poolCert); ! message = LocalText.getText("HasPutShareInPool", player.getName()); DisplayBuffer.add(message, false); ReportBuffer.add(message); ! } // Note: old shares are removed when company is closed ! if (firstCGRowner == null) firstCGRowner = player; ! // Check for presidency if (newShares > maxShares) { *************** *** 391,400 **** log.info(cgrSharesUsed+" CGR shares are now in play"); ! // If no more than 10 shares are in play, the CGR share // unit becomes 10%; otherwise it stays 5%. if (cgrSharesUsed <=10) { ! ((PublicCompany_1856)cgr).setShareUnit (10); ! // All superfluous shares have been removed } message = LocalText.getText("CompanyHasShares", --- 391,400 ---- log.info(cgrSharesUsed+" CGR shares are now in play"); ! // If no more than 10 shares are in play, the CGR share // unit becomes 10%; otherwise it stays 5%. if (cgrSharesUsed <=10) { ! ((PublicCompany_State)cgr).setShareUnit (10); ! // All superfluous shares have been removed } message = LocalText.getText("CompanyHasShares", *************** *** 402,406 **** DisplayBuffer.add(message); ReportBuffer.add(message); ! // Move the remaining CGR shares to the ipo. // Clone the shares list first --- 402,406 ---- DisplayBuffer.add(message); ReportBuffer.add(message); ! // Move the remaining CGR shares to the ipo. // Clone the shares list first *************** *** 512,517 **** executeExchangeTokens (nonHomeTokens); } ! ! // Determine the CGR starting price, // and close the absorbed companies. int lowestPrice = 999; --- 512,517 ---- executeExchangeTokens (nonHomeTokens); } ! ! // Determine the CGR starting price, // and close the absorbed companies. int lowestPrice = 999; *************** *** 529,534 **** numberMerged--; } ! int cgrPrice = Math.max(100, ((int)((totalPrice/numberMerged)/5))*5); ! // Find the correct start space and start the CGR if (cgrPrice == 100) { --- 529,534 ---- numberMerged--; } ! int cgrPrice = Math.max(100, (((totalPrice/numberMerged)/5))*5); ! // Find the correct start space and start the CGR if (cgrPrice == 100) { *************** *** 549,554 **** cgr.start(startSpace); message = LocalText.getText("START_MERGED_COMPANY", ! "CGR", ! Bank.format(startSpace.getPrice()), startSpace.getName()); DisplayBuffer.add(message); --- 549,554 ---- cgr.start(startSpace); message = LocalText.getText("START_MERGED_COMPANY", ! "CGR", ! Bank.format(startSpace.getPrice()), startSpace.getName()); DisplayBuffer.add(message); *************** *** 593,601 **** } } ! ! public boolean process (PossibleAction action) { ! boolean result = true; ! if (action instanceof RepayLoans) { result = repayLoans((RepayLoans)action); --- 593,602 ---- } } ! ! @Override ! public boolean process (PossibleAction action) { ! boolean result = true; ! if (action instanceof RepayLoans) { result = repayLoans((RepayLoans)action); *************** *** 606,616 **** } if (!result) return false; ! if (getStep() == STEP_REPAY_LOANS) { ! if (setNextCompanyNeedingPresidentIntervention()) { return true; } ! if (!mergingCompanies.isEmpty()) { formCGR(); --- 607,617 ---- } if (!result) return false; ! if (getStep() == STEP_REPAY_LOANS) { ! if (setNextCompanyNeedingPresidentIntervention()) { return true; } ! if (!mergingCompanies.isEmpty()) { formCGR(); *************** *** 622,626 **** } ! if (getStep() == STEP_EXCHANGE_TOKENS) { if (action instanceof ExchangeTokens) { --- 623,627 ---- } ! if (getStep() == STEP_EXCHANGE_TOKENS) { if (action instanceof ExchangeTokens) { *************** *** 632,640 **** setStep (STEP_DISCARD_TRAINS); } ! if (getStep() == STEP_DISCARD_TRAINS) { ! if (checkForTrainsToDiscard()) return true; ! //gameManager.nextRound(this); finishRound(); } --- 633,641 ---- setStep (STEP_DISCARD_TRAINS); } ! if (getStep() == STEP_DISCARD_TRAINS) { ! if (checkForTrainsToDiscard()) return true; ! //gameManager.nextRound(this); finishRound(); } *************** *** 642,647 **** return true; } ! ! private boolean checkForTrainsToDiscard () { --- 643,648 ---- return true; } ! ! private boolean checkForTrainsToDiscard () { Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** OperatingRound_1856.java 19 Jul 2009 19:24:21 -0000 1.12 --- OperatingRound_1856.java 28 Aug 2009 20:27:38 -0000 1.13 *************** *** 106,115 **** // Check if any loan interest can be paid ! int loanValue = operatingCompany.getLoanValueModel().intValue(); ! if (loanValue > 0) { ! int interest = loanValue * operatingCompany.getLoanInterestPct() / 100; ! int compCash = (operatingCompany.getCash() / 10) * 10; ! requiredCash = Math.max(interest - compCash, 0); ! } // There is only revenue if there are any trains --- 106,117 ---- // Check if any loan interest can be paid ! if (operatingCompany.canLoan()) { ! int loanValue = operatingCompany.getLoanValueModel().intValue(); ! if (loanValue > 0) { ! int interest = loanValue * operatingCompany.getLoanInterestPct() / 100; ! int compCash = (operatingCompany.getCash() / 10) * 10; ! requiredCash = Math.max(interest - compCash, 0); ! } ! } // There is only revenue if there are any trains *************** *** 141,144 **** --- 143,147 ---- int amount = action.getActualRevenue(); + if (!operatingCompany.canLoan()) return amount; int due = calculateLoanInterest(operatingCompany.getCurrentNumberOfLoans()); if (due == 0) return amount; *************** *** 192,195 **** --- 195,199 ---- int amount = action.getActualRevenue(); + if (!operatingCompany.canLoan()) return amount; int due = calculateLoanInterest(operatingCompany.getCurrentNumberOfLoans()); if (due == 0) return amount; *************** *** 407,410 **** --- 411,415 ---- if (step == STEP_REPAY_LOANS) { + // Are we // Has company any outstanding loans to repay? if (operatingCompany.getMaxNumberOfLoans() == 0 |