From: Erik V. <ev...@us...> - 2009-01-21 20:18:34
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv26428/rails/game Modified Files: OperatingRound.java GameManager.java Log Message: Added 1856 loan repayment step at end of OR. Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** OperatingRound.java 15 Jan 2009 20:53:28 -0000 1.52 --- OperatingRound.java 21 Jan 2009 20:18:23 -0000 1.53 *************** *** 97,101 **** public static final int STEP_TRADE_SHARES = 5; ! public static final int STEP_FINAL = 6; protected static int[] steps = --- 97,101 ---- public static final int STEP_TRADE_SHARES = 5; ! public static int STEP_FINAL = 6; protected static int[] steps = *************** *** 106,110 **** public static final int STEP_DISCARD_TRAINS = -2; ! public static final String[] stepNames = new String[] { "LayTrack", "LayToken", "EnterRevenue", "Payout", "BuyTrain", "TradeShares", "Final" }; --- 106,112 ---- public static final int STEP_DISCARD_TRAINS = -2; ! protected boolean doneAllowed = false; ! ! public static String[] stepNames = new String[] { "LayTrack", "LayToken", "EnterRevenue", "Payout", "BuyTrain", "TradeShares", "Final" }; *************** *** 225,228 **** --- 227,234 ---- result = takeLoans((TakeLoans) selectedAction); + } else if (selectedAction instanceof RepayLoans) { + + result = repayLoans((RepayLoans) selectedAction); + } else if (selectedAction instanceof NullAction) { *************** *** 794,797 **** --- 800,809 ---- operatingCompany.setLastRevenueAllocation(revenueAllocation); + if (amount == 0 && operatingCompany.getNumberOfTrains() == 0) { + DisplayBuffer.add(LocalText.getText("RevenueWithNoTrains", + operatingCompany.getName(), + Bank.format(0) )); + } + // Pay any debts from treasury, revenue and/or president's cash // The remaining dividend may be less that the original income *************** *** 894,898 **** continue; } ! if (step == STEP_TRADE_SHARES) { --- 906,910 ---- continue; } ! if (step == STEP_TRADE_SHARES) { *************** *** 907,910 **** --- 919,924 ---- } + if (!gameSpecificNextStep (step)) continue; + // No reason found to skip this step break; *************** *** 919,922 **** --- 933,941 ---- } + /** Stub, can be overridden in subclasses to check for extra steps */ + protected boolean gameSpecificNextStep (int step) { + return true; + } + protected void initTurn() { setCurrentPlayer(operatingCompany.getPresident()); *************** *** 1088,1113 **** String errMsg = null; ! int step = getStep(); ! ! if (step == STEP_BUY_TRAIN) { ! ! if (operatingCompany.getPortfolio().getNumberOfTrains() == 0 ! && operatingCompany.mustOwnATrain()) { ! // FIXME: Need to check for valid route before throwing an ! // error. ! errMsg = ! LocalText.getText("CompanyMustOwnATrain", ! operatingCompany.getName()); ! setStep(STEP_BUY_TRAIN); ! DisplayBuffer.add(errMsg); ! return false; ! } ! ! } else { ! ! errMsg = LocalText.getText("InvalidDoneAction"); DisplayBuffer.add(errMsg); return false; - } --- 1107,1120 ---- String errMsg = null; ! if (operatingCompany.getPortfolio().getNumberOfTrains() == 0 ! && operatingCompany.mustOwnATrain()) { ! // FIXME: Need to check for valid route before throwing an ! // error. ! errMsg = ! LocalText.getText("CompanyMustOwnATrain", ! operatingCompany.getName()); ! setStep(STEP_BUY_TRAIN); DisplayBuffer.add(errMsg); return false; } *************** *** 1375,1378 **** --- 1382,1387 ---- } else if (savedAction instanceof SetDividend) { executeSetRevenueAndDividend ((SetDividend) savedAction); + } else if (savedAction instanceof RepayLoans) { + executeRepayLoans ((RepayLoans) savedAction); } } *************** *** 1570,1582 **** } - /** Stub for applying any follow-up actions when - * a company reaches it destinations. - * Default version: no actions. - * @param company - */ - protected void reachDestination (PublicCompanyI company) { - - } - protected boolean takeLoans (TakeLoans action) { --- 1579,1582 ---- *************** *** 1587,1591 **** action.getCompanyName(), action.getNumberTaken(), ! action.getPrice(), errMsg)); --- 1587,1591 ---- action.getCompanyName(), action.getNumberTaken(), ! Bank.format(action.getPrice()), errMsg)); *************** *** 1676,1679 **** --- 1676,1773 ---- } + /** Stub for applying any follow-up actions when + * a company reaches it destinations. + * Default version: no actions. + * @param company + */ + protected void reachDestination (PublicCompanyI company) { + + } + + protected boolean repayLoans (RepayLoans action) { + + String errMsg = validateRepayLoans (action); + + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CannotRepayLoans", + action.getCompanyName(), + action.getNumberRepaid(), + Bank.format(action.getPrice()), + errMsg)); + + return false; + } + + int repayment = action.getNumberRepaid() * operatingCompany.getValuePerLoan(); + if (repayment > operatingCompany.getCash()) { + // President must contribute + int remainder = repayment - operatingCompany.getCash(); + Player president = operatingCompany.getPresident(); + int presCash = president.getCash(); + if (remainder > presCash) { + // Start a share selling round + cashToBeRaisedByPresident = remainder - presCash; + log.info("A share selling round must be started as the president cannot pay $" + + remainder + " loan repayment"); + log.info("President has $"+presCash+", so $"+cashToBeRaisedByPresident+" must be added"); + savedAction = action; + gameManager.startShareSellingRound(this, operatingCompany, + cashToBeRaisedByPresident); + return true; + } + } + + MoveSet.start(true); + + executeRepayLoans (action); + + return true; + } + + protected String validateRepayLoans (RepayLoans action) { + + String errMsg = null; + + return errMsg; + } + + protected void executeRepayLoans (RepayLoans action) { + + int number = action.getNumberRepaid(); + int payment; + int remainder = 0; + + operatingCompany.addLoans(-number); + int amount = payment = number * operatingCompany.getValuePerLoan(); + if (amount > operatingCompany.getCash()) { + // By now the president must have enough cash + payment = operatingCompany.getCash(); + remainder = amount - payment; + if (payment > 0) { + new CashMove (operatingCompany, null, payment); + } + ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", + operatingCompany.getName(), + Bank.format(payment), + Bank.format(amount), + number, + Bank.format(operatingCompany.getValuePerLoan()))); + } + if (remainder > 0) { + Player president = operatingCompany.getPresident(); + if (president.getCash() >= remainder) { + payment = remainder; + new CashMove (president, null, payment); + ReportBuffer.add (LocalText.getText("CompanyRepaysLoansWithPresCash", + operatingCompany.getName(), + Bank.format(payment), + Bank.format(amount), + number, + Bank.format(operatingCompany.getValuePerLoan()), + president.getName())); + } + } + } + protected int calculateLoanAmount (int numberOfLoans) { return numberOfLoans * operatingCompany.getValuePerLoan(); *************** *** 1742,1745 **** --- 1836,1840 ---- possibleActions.clear(); selectedAction = null; + doneAllowed = false; int step = getStep(); *************** *** 1800,1805 **** } ! if (getStep() >= STEP_BUY_TRAIN ! && (!operatingCompany.mustOwnATrain() || operatingCompany.getPortfolio().getNumberOfTrains() > 0)) { possibleActions.add(new NullAction(NullAction.DONE)); } --- 1895,1899 ---- } ! if (doneAllowed) { possibleActions.add(new NullAction(NullAction.DONE)); } *************** *** 1990,1993 **** --- 2084,2092 ---- } } + + if (!operatingCompany.mustOwnATrain() + || operatingCompany.getPortfolio().getNumberOfTrains() > 0) { + doneAllowed = true; + } } *************** *** 2040,2054 **** } - public void repayLoans (int number) { - operatingCompany.addLoans(-number); - int amount = number * operatingCompany.getValuePerLoan(); - new CashMove (operatingCompany, null, amount); - DisplayBuffer.add(LocalText.getText("CompanyRepaysLoan", - operatingCompany.getName(), - number, - Bank.format(operatingCompany.getValuePerLoan()), - Bank.format(amount))); - } - public void payLoanInterest () { int amount = operatingCompany.getCurrentLoanValue() --- 2139,2142 ---- Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** GameManager.java 15 Jan 2009 20:53:28 -0000 1.41 --- GameManager.java 21 Jan 2009 20:18:24 -0000 1.42 *************** *** 613,616 **** --- 613,626 ---- for (PossibleAction action : actions) { + + // TEMPORARY FIX TO ALLOW OLD 1856 SAVED FILES TO BE PROCESSED + if (!possibleActions.contains(action.getClass()) + && possibleActions.contains(RepayLoans.class)) { + // Insert "Done" + log.debug("Action DONE inserted"); + getCurrentRound().process(new NullAction (NullAction.DONE)); + getCurrentRound().setPossibleActions(); + } + try { log.debug("Action: " + action); |