From: Stefan F. <ste...@us...> - 2010-03-03 00:46:17
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv3705/rails/game Modified Files: OperatingRound.java GameManager.java Log Message: Added CorrectionMode - first part Cash Correction Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** OperatingRound.java 28 Feb 2010 21:38:05 -0000 1.110 --- OperatingRound.java 3 Mar 2010 00:44:51 -0000 1.111 *************** *** 1047,1136 **** 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; - // } - /** --- 1047,1050 ---- Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** GameManager.java 23 Feb 2010 22:21:39 -0000 1.84 --- GameManager.java 3 Mar 2010 00:45:06 -0000 1.85 *************** *** 13,16 **** --- 13,17 ---- import rails.common.GuiHints; import rails.game.action.*; + import rails.game.correct.*; import rails.game.move.*; import rails.game.special.SpecialPropertyI; *************** *** 79,82 **** --- 80,86 ---- protected EnumMap<GameDef.Parm, Object> gameParameters = new EnumMap<GameDef.Parm, Object>(GameDef.Parm.class); + + protected EnumSet<CorrectionType> activeCorrections + = EnumSet.noneOf(CorrectionType.class); /** *************** *** 758,762 **** // All other actions: process per round ! result = getCurrentRound().process(action); break; } --- 762,766 ---- // All other actions: process per round ! result = processCorrectionActions(action) || getCurrentRound().process(action); break; } *************** *** 782,789 **** } ! for (PossibleAction pa : possibleActions.getList()) { ! log.debug(((Player) currentPlayer.getObject()).getName() + " may: " ! + pa.toString()); ! } // Add the Undo/Redo possibleActions here. --- 786,790 ---- } ! setCorrectionActions(); // Add the Undo/Redo possibleActions here. *************** *** 798,804 **** --- 799,875 ---- } + + // logging of game actions activated + for (PossibleAction pa : possibleActions.getList()) { + log.debug(((Player) currentPlayer.getObject()).getName() + " may: " + + pa.toString()); + } + return result; } + + /** + * Adds all Game actions + * Examples are: undo/redo/corrections + */ + private void setCorrectionActions(){ + + // If any Correction is active + if (!activeCorrections.isEmpty()) { + // remove all other actions + possibleActions.clear(); + // and set GuiHints for corrections - removed + } + + // CorrectionMode Actions + EnumSet<CorrectionType> possibleCorrections = EnumSet.allOf(CorrectionType.class); + for (CorrectionType ct:possibleCorrections) + possibleActions.add( + new CorrectionModeAction(ct, activeCorrections.contains(ct))); + + // Correction Actions + for (CorrectionType ct:activeCorrections) { + CorrectionManager cm = ct.getManager(this); + possibleActions.addAll(cm.createCorrections()); + } + } + + private boolean processCorrectionActions(PossibleAction a){ + + boolean result = false; + + if (a instanceof CorrectionModeAction) { + CorrectionModeAction cma = (CorrectionModeAction)a; + CorrectionType ct = cma.getCorrection(); + moveStack.start(false); + new SetChange<CorrectionType> + (activeCorrections, ct, !cma.isActive()); + if (!cma.isActive()) { + String text = LocalText.getText("CorrectionModeActivate", + getCurrentPlayer().getName(), + LocalText.getText(ct.name()) + ); + ReportBuffer.add(text); + DisplayBuffer.add(text); + } + else { + ReportBuffer.add(LocalText.getText("CorrectionModeDeactivate", + getCurrentPlayer().getName(), + LocalText.getText(ct.name()) + )); + } + result = true; + } + + if (a instanceof CorrectionAction) { + CorrectionAction ca= (CorrectionAction)a; + CorrectionType ct = ca.getCorrectionType(); + CorrectionManager cm = ct.getManager(this); + result = cm.executeCorrection(ca); + } + + return result; + } /* (non-Javadoc) *************** *** 817,825 **** getCurrentRound().process(new NullAction (NullAction.DONE)); getCurrentRound().setPossibleActions(); } try { log.debug("Action: " + action); ! if (!getCurrentRound().process(action)) { String msg = "Player "+action.getPlayerName()+"\'s action \"" +action.toString()+"\"\n in "+getCurrentRound().getRoundName() --- 888,897 ---- getCurrentRound().process(new NullAction (NullAction.DONE)); getCurrentRound().setPossibleActions(); + setCorrectionActions(); } try { log.debug("Action: " + action); ! if (!processCorrectionActions(action) && !getCurrentRound().process(action)) { String msg = "Player "+action.getPlayerName()+"\'s action \"" +action.toString()+"\"\n in "+getCurrentRound().getRoundName() *************** *** 831,834 **** --- 903,908 ---- } getCurrentRound().setPossibleActions(); + setCorrectionActions(); + } catch (Exception e) { log.debug("Error while reprocessing " + action.toString(), e); |