From: Erik V. <ev...@us...> - 2009-01-14 20:45:19
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv24082/rails/game Modified Files: ShareSellingRound.java OperatingRound.java GameManager.java Log Message: Added 1856 loan interest payment (from all possible sources). Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** OperatingRound.java 11 Jan 2009 17:24:46 -0000 1.50 --- OperatingRound.java 14 Jan 2009 20:45:07 -0000 1.51 *************** *** 5,11 **** import rails.game.action.*; ! import rails.game.move.CashMove; ! import rails.game.move.MapChange; ! import rails.game.move.MoveSet; import rails.game.special.*; import rails.game.state.IntegerState; --- 5,9 ---- import rails.game.action.*; ! import rails.game.move.*; import rails.game.special.*; import rails.game.state.IntegerState; *************** *** 57,61 **** protected List<TrainTypeI> trainsBoughtThisTurn = new ArrayList<TrainTypeI>(4); ! protected Map<PublicCompanyI, Integer> loansThisRound = null; --- 55,59 ---- protected List<TrainTypeI> trainsBoughtThisTurn = new ArrayList<TrainTypeI>(4); ! protected Map<PublicCompanyI, Integer> loansThisRound = null; *************** *** 66,70 **** protected PossibleAction selectedAction = null; ! protected BuyTrain savedAction = null; protected int cashToBeRaisedByPresident = 0; --- 64,68 ---- protected PossibleAction selectedAction = null; ! protected PossibleAction savedAction = null; protected int cashToBeRaisedByPresident = 0; *************** *** 210,216 **** result = reachDestinations ((ReachDestinations) selectedAction); ! } else if (selectedAction instanceof TakeLoans) { ! result = takeLoans((TakeLoans) selectedAction); --- 208,214 ---- result = reachDestinations ((ReachDestinations) selectedAction); ! } else if (selectedAction instanceof TakeLoans) { ! result = takeLoans((TakeLoans) selectedAction); *************** *** 648,651 **** --- 646,677 ---- public boolean setRevenueAndDividend(SetDividend action) { + String errMsg = validateSetRevenueAndDividend (action); + + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText( + "CannotProcessRevenue", + Bank.format (action.getActualRevenue()), + action.getCompanyName(), + errMsg + )); + return false; + } + + MoveSet.start(true); + + int remainingAmount = checkForDeductions (action); + if (remainingAmount < 0) { + // A share selling round will be run to raise cash to pay debts + return true; + } + + executeSetRevenueAndDividend (action); + + return true; + + } + + protected String validateSetRevenueAndDividend (SetDividend action) { + String errMsg = null; PublicCompanyI company; *************** *** 717,743 **** } else { // If there is no revenue, use withhold. ! revenueAllocation = SetDividend.WITHHOLD; } break; } - if (errMsg != null) { - DisplayBuffer.add(LocalText.getText( - "CannotProcessRevenue", - new String[] { String.valueOf(amount), companyName, errMsg })); - return false; - } ! MoveSet.start(true); operatingCompany.setLastRevenue(amount); operatingCompany.setLastRevenueAllocation(revenueAllocation); - ReportBuffer.add(LocalText.getText("CompanyRevenue", new String[] { - companyName, Bank.format(amount) })); ! if (revenueAllocation == SetDividend.PAYOUT) { ReportBuffer.add(LocalText.getText("CompanyPaysOutFull", ! new String[] { companyName, Bank.format(amount) })); operatingCompany.payout(amount); --- 743,786 ---- } else { // If there is no revenue, use withhold. ! action.setRevenueAllocation(SetDividend.WITHHOLD); ! } ! ! ReportBuffer.add(LocalText.getText("CompanyRevenue", ! action.getCompanyName(), ! Bank.format(amount))); ! if (amount == 0 && operatingCompany.getNumberOfTrains() == 0) { ! DisplayBuffer.add(LocalText.getText("RevenueWithNoTrains", ! operatingCompany.getName(), ! Bank.format(0) )); } break; } ! return errMsg; ! } ! ! protected void executeSetRevenueAndDividend (SetDividend action) { ! ! int amount = action.getActualRevenue(); ! int revenueAllocation = action.getRevenueAllocation(); operatingCompany.setLastRevenue(amount); operatingCompany.setLastRevenueAllocation(revenueAllocation); ! // Pay any debts from treasury, revenue and/or president's cash ! // The remaining dividend may be less that the original income ! amount = executeDeductions (action); ! ! if (amount == 0) { ! ! ReportBuffer.add(LocalText.getText("CompanyDoesNotPayDividend", ! operatingCompany.getName())); ! operatingCompany.withhold(amount); ! ! } else if (revenueAllocation == SetDividend.PAYOUT) { ReportBuffer.add(LocalText.getText("CompanyPaysOutFull", ! operatingCompany.getName(), Bank.format(amount) )); operatingCompany.payout(amount); *************** *** 745,750 **** } else if (revenueAllocation == SetDividend.SPLIT) { ! ReportBuffer.add(LocalText.getText("CompanySplits", new String[] { ! companyName, Bank.format(amount) })); operatingCompany.splitRevenue(amount); --- 788,793 ---- } else if (revenueAllocation == SetDividend.SPLIT) { ! ReportBuffer.add(LocalText.getText("CompanySplits", ! operatingCompany.getName(), Bank.format(amount) )); operatingCompany.splitRevenue(amount); *************** *** 753,757 **** ReportBuffer.add(LocalText.getText("CompanyWithholds", ! new String[] { companyName, Bank.format(amount) })); operatingCompany.withhold(amount); --- 796,801 ---- ReportBuffer.add(LocalText.getText("CompanyWithholds", ! operatingCompany.getName(), ! Bank.format(amount) )); operatingCompany.withhold(amount); *************** *** 764,769 **** // We have done the payout step, so continue from there nextStep(STEP_PAYOUT); ! return true; } --- 808,821 ---- // We have done the payout step, so continue from there nextStep(STEP_PAYOUT); + } ! /** Default version, to be overridden if need be */ ! protected int checkForDeductions (SetDividend action) { ! return action.getActualRevenue(); ! } ! ! /** Default version, to be overridden if need be */ ! protected int executeDeductions (SetDividend action) { ! return action.getActualRevenue(); } *************** *** 799,802 **** --- 851,855 ---- if (operatingCompany.getPortfolio().getNumberOfTrains() == 0) { // No trains, then the revenue is zero. + /* operatingCompany.setLastRevenue(0); operatingCompany.setLastRevenueAllocation(SetDividend.UNKNOWN); *************** *** 804,807 **** --- 857,864 ---- new String[] { operatingCompany.getName(), Bank.format(0) })); + */ + executeSetRevenueAndDividend ( + new SetDividend (0, false, new int[] {SetDividend.WITHHOLD})); + // TODO: This probably does not handle share selling correctly continue; } *************** *** 811,817 **** --- 868,876 ---- // If we already know what to do: do it. + /* int amount = operatingCompany.getLastRevenue(); if (amount == 0) { /* Zero dividend: process it and go to the next step */ + /* operatingCompany.withhold(0); DisplayBuffer.add(LocalText.getText("RevenueWithNoTrains", *************** *** 825,832 **** * Automatic revenue split: process it and go to the next * step ! */ operatingCompany.splitRevenue(amount); continue; } } --- 884,893 ---- * Automatic revenue split: process it and go to the next * step ! *//* operatingCompany.splitRevenue(amount); continue; } + */ + continue; } *************** *** 1296,1302 **** } ! public void resumeTrainBuying() { ! buyTrain(savedAction); } --- 1357,1367 ---- } ! public void resume() { ! if (savedAction instanceof BuyTrain) { ! buyTrain ((BuyTrain)savedAction); ! } else if (savedAction instanceof SetDividend) { ! executeSetRevenueAndDividend ((SetDividend) savedAction); ! } } *************** *** 1497,1517 **** } ! protected boolean takeLoans (TakeLoans action) { ! String errMsg = validateTakeLoans (action); ! if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotTakeLoans", ! action.getCompanyName(), action.getNumberTaken(), action.getPrice(), errMsg)); ! return false; } MoveSet.start(true); ! executeTakeLoans (action); --- 1562,1582 ---- } ! protected boolean takeLoans (TakeLoans action) { ! String errMsg = validateTakeLoans (action); ! if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotTakeLoans", ! action.getCompanyName(), action.getNumberTaken(), action.getPrice(), errMsg)); ! return false; } MoveSet.start(true); ! executeTakeLoans (action); *************** *** 1519,1523 **** } ! protected String validateTakeLoans (TakeLoans action) { --- 1584,1588 ---- } ! protected String validateTakeLoans (TakeLoans action) { *************** *** 1560,1566 **** return errMsg; } ! protected void executeTakeLoans (TakeLoans action) { ! int number = action.getNumberTaken(); int amount = calculateLoanAmount (number); --- 1625,1631 ---- return errMsg; } ! protected void executeTakeLoans (TakeLoans action) { ! int number = action.getNumberTaken(); int amount = calculateLoanAmount (number); *************** *** 1581,1585 **** )); } ! if (operatingCompany.getMaxLoansPerRound() > 0) { int oldLoansThisRound = 0; --- 1646,1650 ---- )); } ! if (operatingCompany.getMaxLoansPerRound() > 0) { int oldLoansThisRound = 0; *************** *** 1589,1602 **** oldLoansThisRound = loansThisRound.get(operatingCompany); } ! new MapChange<PublicCompanyI, Integer> (loansThisRound, operatingCompany, new Integer (oldLoansThisRound + number)); } } ! protected int calculateLoanAmount (int numberOfLoans) { return numberOfLoans * operatingCompany.getValuePerLoan(); } ! /*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/ --- 1654,1667 ---- oldLoansThisRound = loansThisRound.get(operatingCompany); } ! new MapChange<PublicCompanyI, Integer> (loansThisRound, operatingCompany, new Integer (oldLoansThisRound + number)); } } ! protected int calculateLoanAmount (int numberOfLoans) { return numberOfLoans * operatingCompany.getValuePerLoan(); } ! /*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/ *************** *** 1684,1704 **** possibleActions.add(new NullAction(NullAction.SKIP)); } else if (step == STEP_CALC_REVENUE) { ! if (operatingCompany.getPortfolio().getNumberOfTrains() == 0) { ! // No trains: the revenue is fixed at 0 ! } else { ! int[] allowedRevenueActions = ! operatingCompany.isSplitAlways() ! ? new int[] { SetDividend.SPLIT } ! : operatingCompany.isSplitAllowed() ! ? new int[] { SetDividend.PAYOUT, ! SetDividend.SPLIT, ! SetDividend.WITHHOLD } ! : new int[] { SetDividend.PAYOUT, ! SetDividend.WITHHOLD }; ! ! possibleActions.add(new SetDividend( ! operatingCompany.getLastRevenue(), true, ! allowedRevenueActions)); ! } } else if (step == STEP_BUY_TRAIN) { setBuyableTrains(); --- 1749,1753 ---- possibleActions.add(new NullAction(NullAction.SKIP)); } else if (step == STEP_CALC_REVENUE) { ! prepareRevenueAndDividendAction(); } else if (step == STEP_BUY_TRAIN) { setBuyableTrains(); *************** *** 1751,1754 **** --- 1800,1823 ---- } + protected void prepareRevenueAndDividendAction () { + + // There is only revenue if there are any trains + if (operatingCompany.getPortfolio().getNumberOfTrains() > 0) { + int[] allowedRevenueActions = + operatingCompany.isSplitAlways() + ? new int[] { SetDividend.SPLIT } + : operatingCompany.isSplitAllowed() + ? new int[] { SetDividend.PAYOUT, + SetDividend.SPLIT, + SetDividend.WITHHOLD } + : new int[] { SetDividend.PAYOUT, + SetDividend.WITHHOLD }; + + possibleActions.add(new SetDividend( + operatingCompany.getLastRevenue(), true, + allowedRevenueActions)); + } + } + /** * Get a list of buyable trains for the currently operating company. Omit *************** *** 1954,1958 **** } ! public void repayLoans (int number) { operatingCompany.addLoans(-number); --- 2023,2027 ---- } ! public void repayLoans (int number) { operatingCompany.addLoans(-number); *************** *** 1960,1965 **** new CashMove (operatingCompany, null, amount); DisplayBuffer.add(LocalText.getText("CompanyRepaysLoan", ! new String[] { ! operatingCompany.getName(), String.valueOf(number), Bank.format(operatingCompany.getValuePerLoan()), --- 2029,2034 ---- new CashMove (operatingCompany, null, amount); DisplayBuffer.add(LocalText.getText("CompanyRepaysLoan", ! new String[] { ! operatingCompany.getName(), String.valueOf(number), Bank.format(operatingCompany.getValuePerLoan()), *************** *** 1967,1971 **** })); } ! public void payLoanInterest () { int amount = operatingCompany.getCurrentLoanValue() --- 2036,2040 ---- })); } ! public void payLoanInterest () { int amount = operatingCompany.getCurrentLoanValue() *************** *** 1973,1978 **** new CashMove (operatingCompany, null, amount); DisplayBuffer.add(LocalText.getText("CompanyPaysLoanInterest", ! new String[] { ! operatingCompany.getName(), Bank.format(amount), String.valueOf(operatingCompany.getLoanInterestPct()), --- 2042,2047 ---- new CashMove (operatingCompany, null, amount); DisplayBuffer.add(LocalText.getText("CompanyPaysLoanInterest", ! new String[] { ! operatingCompany.getName(), Bank.format(amount), String.valueOf(operatingCompany.getLoanInterestPct()), Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** GameManager.java 11 Jan 2009 17:24:46 -0000 1.39 --- GameManager.java 14 Jan 2009 20:45:07 -0000 1.40 *************** *** 658,662 **** public void finishShareSellingRound() { setRound(interruptedRound); ! ((OperatingRound) getCurrentRound()).resumeTrainBuying(); } --- 658,662 ---- public void finishShareSellingRound() { setRound(interruptedRound); ! ((OperatingRound) getCurrentRound()).resume(); } Index: ShareSellingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/ShareSellingRound.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ShareSellingRound.java 23 Dec 2008 19:57:26 -0000 1.18 --- ShareSellingRound.java 14 Jan 2009 20:45:07 -0000 1.19 *************** *** 21,25 **** OperatingRound or; Player sellingPlayer; ! PublicCompanyI companyNeedingTrain; IntegerState cashToRaise; --- 21,25 ---- OperatingRound or; Player sellingPlayer; ! PublicCompanyI companyNeedingCash; IntegerState cashToRaise; *************** *** 39,47 **** super (gameManager); or = ((OperatingRound) parentRound); ! companyNeedingTrain = or.getOperatingCompany(); cashToRaise = new IntegerState("CashToRaise", or.getCashToBeRaisedByPresident()); ! sellingPlayer = companyNeedingTrain.getPresident(); currentPlayer = sellingPlayer; - log.debug("Creating ShareSellingRound, cash to raise =" + cashToRaise.intValue()); setCurrentPlayerIndex(sellingPlayer.getIndex()); --- 39,46 ---- super (gameManager); or = ((OperatingRound) parentRound); ! companyNeedingCash = or.getOperatingCompany(); cashToRaise = new IntegerState("CashToRaise", or.getCashToBeRaisedByPresident()); ! sellingPlayer = companyNeedingCash.getPresident(); currentPlayer = sellingPlayer; setCurrentPlayerIndex(sellingPlayer.getIndex()); *************** *** 51,54 **** --- 50,57 ---- public void start() { log.info("Share selling round started"); + ReportBuffer.add (LocalText.getText("PlayerMustSellShares", + sellingPlayer.getName(), + Bank.format(cashToRaise.intValue()), + companyNeedingCash.getName())); currentPlayer = sellingPlayer; setPossibleActions(); *************** *** 129,133 **** if (maxShareToSell > share - presidentShare) { dumpAllowed = false; ! if (company != companyNeedingTrain) { int playerShare; List<Player> players = gameManager.getPlayers(); --- 132,136 ---- if (maxShareToSell > share - presidentShare) { dumpAllowed = false; ! if (company != companyNeedingCash) { int playerShare; List<Player> players = gameManager.getPlayers(); *************** *** 263,267 **** && numberToSell <= presCert.getShares()) { // Not allowed to dump the company that needs the train ! if (company == companyNeedingTrain) { errMsg = LocalText.getText("CannotDumpTrainBuyingPresidency"); --- 266,270 ---- && numberToSell <= presCert.getShares()) { // Not allowed to dump the company that needs the train ! if (company == companyNeedingCash) { errMsg = LocalText.getText("CannotDumpTrainBuyingPresidency"); *************** *** 323,330 **** MoveSet.start(true); ! ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", new String[] { ! playerName, String.valueOf(numberSold), ! String.valueOf((numberSold * company.getShareUnit())), ! companyName, Bank.format(numberSold * price) })); // Check if the presidency has changed --- 326,336 ---- MoveSet.start(true); ! ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", ! playerName, ! numberSold, ! company.getShareUnit(), ! numberSold * company.getShareUnit(), ! companyName, ! Bank.format(numberSold * price) )); // Check if the presidency has changed *************** *** 380,384 **** public PublicCompanyI getCompanyNeedingTrain() { ! return companyNeedingTrain; } --- 386,390 ---- public PublicCompanyI getCompanyNeedingTrain() { ! return companyNeedingCash; } |