From: Stefan F. <ste...@us...> - 2010-02-24 21:10:11
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv31633/rails/game Modified Files: OperatingRound.java Log Message: Changed base class of ClosePrivate and OperatingCost actions to PossibleAction and PossibleOR in preparation of new Correction Actions Breaks save compatibility with previous actions. Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** OperatingRound.java 23 Feb 2010 22:21:39 -0000 1.106 --- OperatingRound.java 24 Feb 2010 21:09:23 -0000 1.107 *************** *** 198,204 **** result = buyBonusToken((BuyBonusToken) selectedAction); ! } else if (selectedAction instanceof CorrectCashI) { ! // includes OperatingCost ! result = executeCorrectCash((CorrectCashI) selectedAction); } else if (selectedAction instanceof SetDividend) { --- 198,204 ---- result = buyBonusToken((BuyBonusToken) selectedAction); ! } else if (selectedAction instanceof OperatingCost) { ! ! result = executeOperatingCost((OperatingCost) selectedAction); } else if (selectedAction instanceof SetDividend) { *************** *** 942,981 **** } ! protected boolean executeCorrectCash(CorrectCashI action){ ! CashHolder ch = action.getCashHolder(); ! int amount = action.getAmount(); ! int cost = -amount; // costs are minus of CashCorrectamount ! // operating costs related stuff ! boolean flagOC = false; ! OperatingCost actionOC = null; ! OperatingCost.OCType typeOC = null; ! PublicCompanyI pc = null; ! String textError = "CCExecutionError"; ! ! if (action instanceof OperatingCost) { ! flagOC = true; ! actionOC = (OperatingCost) action; ! typeOC = actionOC.getOCType(); ! pc = (PublicCompanyI) ch; ! textError = "OCExecutionError"; ! } String errMsg = null; while (true) { ! if ((amount + ch.getCash()) < 0) { errMsg = LocalText.getText("NotEnoughMoney", ! ch.getName(), ! Bank.format(ch.getCash()), ! Bank.format(cost) ); break; } ! if (flagOC && (typeOC == OperatingCost.OCType.LAY_BASE_TOKEN) && (pc.getNumberOfFreeBaseTokens() == 0)) { errMsg = ! LocalText.getText("HasNoTokensLeft", ch.getName()); break; } --- 942,976 ---- } ! protected boolean executeOperatingCost(OperatingCost action){ ! String companyName = action.getCompanyName(); ! OperatingCost.OCType typeOC = action.getOCType(); ! int amount = action.getAmount(); String errMsg = null; while (true) { ! // Must be correct company. ! if (!companyName.equals(operatingCompany.getName())) { ! errMsg = ! LocalText.getText("WrongCompany", ! companyName, ! operatingCompany.getName() ); ! break; ! } ! // amount is available ! if ((amount + operatingCompany.getCash()) < 0) { errMsg = LocalText.getText("NotEnoughMoney", ! companyName, ! Bank.format(operatingCompany.getCash()), ! Bank.format(amount) ); break; } ! if (typeOC == OperatingCost.OCType.LAY_BASE_TOKEN && operatingCompany.getNumberOfFreeBaseTokens() == 0) { errMsg = ! LocalText.getText("HasNoTokensLeft", companyName); break; } *************** *** 984,989 **** if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText(textError, ! ch.getName(), errMsg)); return false; --- 979,984 ---- if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("OCExecutionError", ! companyName, errMsg)); return false; *************** *** 992,1025 **** moveStack.start(true); ! if (amount < 0) { ! // negative amounts: remove cash from cashholder ! new CashMove(ch, bank, cost); } else if (amount > 0) { ! // positive amounts: add cash to cashholder ! new CashMove(bank, ch, amount); } ! if (flagOC) { ! ! if (typeOC == OperatingCost.OCType.LAY_TILE) { ! pc.layTileInNoMapMode(cost); ! ReportBuffer.add(LocalText.getText("OCLayTileExecuted", ! pc.getName(), ! Bank.format(cost) )); ! } ! if (typeOC == OperatingCost.OCType.LAY_BASE_TOKEN) { ! // move token to Bank ! BaseToken token = pc.getFreeToken(); ! if (token == null) { ! log.error("Company " + pc.getName() + " has no free token"); ! return false; ! } else { ! token.moveTo(bank.getUnavailable()); ! } ! pc.layBaseTokenInNoMapMode(cost); ! ReportBuffer.add(LocalText.getText("OCLayBaseTokenExecuted", ! pc.getName(), ! Bank.format(cost) )); } } --- 987,1017 ---- moveStack.start(true); ! if (amount > 0) { ! // positive amounts: remove cash from cashholder ! new CashMove(operatingCompany, bank, amount); } else if (amount > 0) { ! // negative amounts: add cash to cashholder ! new CashMove(bank, operatingCompany, -amount); } ! if (typeOC == OperatingCost.OCType.LAY_TILE) { ! operatingCompany.layTileInNoMapMode(amount); ! ReportBuffer.add(LocalText.getText("OCLayTileExecuted", ! operatingCompany.getName(), ! Bank.format(amount) )); ! } ! if (typeOC == OperatingCost.OCType.LAY_BASE_TOKEN) { ! // move token to Bank ! BaseToken token = operatingCompany.getFreeToken(); ! if (token == null) { ! log.error("Company " + operatingCompany.getName() + " has no free token"); ! return false; ! } else { ! token.moveTo(bank.getUnavailable()); } + operatingCompany.layBaseTokenInNoMapMode(amount); + ReportBuffer.add(LocalText.getText("OCLayBaseTokenExecuted", + operatingCompany.getName(), + Bank.format(amount) )); } *************** *** 1047,1050 **** --- 1039,1128 ---- return true; } + + // protected boolean executeCorrectCash(CorrectCashI action){ + // + // CashHolder ch = action.getCashHolder(); + // int amount = action.getAmount(); + // int cost = -amount; // costs are minus of CashCorrectamount + // + // // operating costs related stuff + // boolean flagOC = false; + // OperatingCost actionOC = null; + // OperatingCost.OCType typeOC = null; + // PublicCompanyI pc = null; + // String textError = "CCExecutionError"; + // + // if (action instanceof OperatingCost) { + // flagOC = true; + // actionOC = (OperatingCost) action; + // typeOC = actionOC.getOCType(); + // pc = (PublicCompanyI) ch; + // textError = "OCExecutionError"; + // } + // + // String errMsg = null; + // + // while (true) { + // if ((amount + ch.getCash()) < 0) { + // errMsg = + // LocalText.getText("NotEnoughMoney", + // ch.getName(), + // Bank.format(ch.getCash()), + // Bank.format(cost) + // ); + // break; + // } + // if (flagOC && (typeOC == OperatingCost.OCType.LAY_BASE_TOKEN) && (pc.getNumberOfFreeBaseTokens() == 0)) { + // errMsg = + // LocalText.getText("HasNoTokensLeft", ch.getName()); + // break; + // } + // break; + // } + // + // if (errMsg != null) { + // DisplayBuffer.add(LocalText.getText(textError, + // ch.getName(), + // errMsg)); + // return false; + // } + // + // moveStack.start(true); + // + // if (amount < 0) { + // // negative amounts: remove cash from cashholder + // new CashMove(ch, bank, cost); + // } else if (amount > 0) { + // // positive amounts: add cash to cashholder + // new CashMove(bank, ch, amount); + // } + // + // if (flagOC) { + // + // if (typeOC == OperatingCost.OCType.LAY_TILE) { + // pc.layTileInNoMapMode(cost); + // ReportBuffer.add(LocalText.getText("OCLayTileExecuted", + // pc.getName(), + // Bank.format(cost) )); + // } + // if (typeOC == OperatingCost.OCType.LAY_BASE_TOKEN) { + // // move token to Bank + // BaseToken token = pc.getFreeToken(); + // if (token == null) { + // log.error("Company " + pc.getName() + " has no free token"); + // return false; + // } else { + // token.moveTo(bank.getUnavailable()); + // } + // pc.layBaseTokenInNoMapMode(cost); + // ReportBuffer.add(LocalText.getText("OCLayBaseTokenExecuted", + // pc.getName(), + // Bank.format(cost) )); + // } + // } + // + // return true; + // } + /** *************** *** 2249,2255 **** for (Integer tc: mapManager.getPossibleTileCosts()) { if (tc <= operatingCompany.getCash()) ! possibleActions.add(new OperatingCost( ! operatingCompany, OperatingCost.OCType.LAY_TILE, tc, false ! )); } --- 2327,2331 ---- for (Integer tc: mapManager.getPossibleTileCosts()) { if (tc <= operatingCompany.getCash()) ! possibleActions.add(new OperatingCost(OperatingCost.OCType.LAY_TILE, tc, false)); } *************** *** 2259,2266 **** for (int cost : costs) { if ((cost <= operatingCompany.getCash()) && (cost != 0 || costs.length == 1)) // distance method returns home base, but in sequence costs can be zero ! possibleActions.add(new OperatingCost( ! operatingCompany, OperatingCost.OCType.LAY_BASE_TOKEN, ! cost, false ! )); } } --- 2335,2339 ---- for (int cost : costs) { if ((cost <= operatingCompany.getCash()) && (cost != 0 || costs.length == 1)) // distance method returns home base, but in sequence costs can be zero ! possibleActions.add(new OperatingCost(OperatingCost.OCType.LAY_BASE_TOKEN, cost, false)); } } *************** *** 2268,2278 **** // Default OperatingCost Actions possibleActions.add(new OperatingCost( ! operatingCompany, OperatingCost.OCType.LAY_TILE, 0, true )); if (operatingCompany.getNumberOfFreeBaseTokens() != 0 && operatingCompany.getBaseTokenLayCost(null) != 0) { ! possibleActions.add(new OperatingCost( ! operatingCompany, OperatingCost.OCType.LAY_BASE_TOKEN, 0, true ! )); } --- 2341,2349 ---- // Default OperatingCost Actions possibleActions.add(new OperatingCost( ! OperatingCost.OCType.LAY_TILE, 0, true )); if (operatingCompany.getNumberOfFreeBaseTokens() != 0 && operatingCompany.getBaseTokenLayCost(null) != 0) { ! possibleActions.add(new OperatingCost(OperatingCost.OCType.LAY_BASE_TOKEN, 0, true)); } |