Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv21890/rails/game Modified Files: MapManager.java Portfolio.java MapHex.java OperatingRound.java GameOption.java PublicCompanyI.java PublicCompany.java Log Message: Added NoMapMode as GameOption. This mode skips LayTile and LayTrack actions and replaces those by more generic OperatingCosts actions. Currently only a non-strict mode is supported, thus "illegal" actions are possible. Option only tested and active for 1889 and 1835. Others to follow. Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** Portfolio.java 6 Feb 2010 23:48:26 -0000 1.44 --- Portfolio.java 14 Feb 2010 20:47:45 -0000 1.45 *************** *** 592,595 **** --- 592,597 ---- } else if (object instanceof SpecialPropertyI) { return addSpecialProperty((SpecialPropertyI) object); + } else if (object instanceof TokenI) { + return addToken((TokenI) object); } else { return false; *************** *** 615,618 **** --- 617,622 ---- } else if (object instanceof SpecialPropertyI) { return removeSpecialProperty((SpecialPropertyI) object); + } else if (object instanceof TokenI) { + return removeToken((TokenI) object); } else { return false; Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** PublicCompany.java 9 Feb 2010 20:02:02 -0000 1.84 --- PublicCompany.java 14 Feb 2010 20:48:02 -0000 1.85 *************** *** 1607,1611 **** } } ! public ModelObject getTilesLaidThisTurnModel() { return tilesLaidThisTurn; --- 1607,1617 ---- } } ! ! @Override ! public void layTileInNoMapMode(int cost) { ! if (cost > 0) tilesCostThisTurn.add(cost); ! tilesLaidThisTurn.appendWithDelimiter(Bank.format(cost), ","); ! } ! public ModelObject getTilesLaidThisTurnModel() { return tilesLaidThisTurn; *************** *** 1622,1625 **** --- 1628,1637 ---- if (cost > 0) tokensCostThisTurn.add(cost); } + + @Override + public void layBaseTokenInNoMapMode(int cost) { + if (cost > 0) tokensCostThisTurn.add(cost); + tokensLaidThisTurn.appendWithDelimiter(Bank.format(cost), ","); + } /** Index: MapManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapManager.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** MapManager.java 9 Feb 2010 20:00:40 -0000 1.16 --- MapManager.java 14 Feb 2010 20:47:34 -0000 1.17 *************** *** 24,27 **** --- 24,30 ---- protected Map<String, MapHex> mHexes = new HashMap<String, MapHex>(); protected int maxX, maxY; + + // upgrade costs on the map for noMapMode + protected SortedSet<Integer> possibleTileCosts; protected static final int[] xDeltaNS = new int[] { 0, -1, -1, 0, +1, +1 }; *************** *** 80,83 **** --- 83,87 ---- maxX = 0; maxY = 0; + possibleTileCosts = new TreeSet<Integer>(); for (Tag hexTag : hexTags) { hex = new MapHex(this); *************** *** 86,91 **** maxX = Math.max(maxX, hex.getX()); maxY = Math.max(maxY, hex.getY()); } ! hexes = new MapHex[1 + maxX][1 + maxY]; --- 90,100 ---- maxX = Math.max(maxX, hex.getX()); maxY = Math.max(maxY, hex.getY()); + int[] tileCosts = hex.getTileCostAsArray(); + for (int i=0; i<tileCosts.length; i++){ + possibleTileCosts.add(tileCosts[i]); + } } ! log.debug("Possible tileCosts on map are "+possibleTileCosts); ! hexes = new MapHex[1 + maxX][1 + maxY]; *************** *** 195,198 **** --- 204,211 ---- } + public SortedSet<Integer> getPossibleTileCosts() { + return possibleTileCosts; + } + public List<MapHex> parseLocations (String locationCodes) throws ConfigurationException { Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** PublicCompanyI.java 9 Feb 2010 20:02:02 -0000 1.45 --- PublicCompanyI.java 14 Feb 2010 20:48:02 -0000 1.46 *************** *** 287,291 **** public void layTile(MapHex hex, TileI tile, int orientation, int cost); ! public ModelObject getTilesLaidThisTurnModel(); --- 287,293 ---- public void layTile(MapHex hex, TileI tile, int orientation, int cost); ! ! public void layTileInNoMapMode(int cost); ! public ModelObject getTilesLaidThisTurnModel(); *************** *** 294,297 **** --- 296,301 ---- public void layBaseToken(MapHex hex, int cost); + public void layBaseTokenInNoMapMode(int cost); + public ModelObject getTokensLaidThisTurnModel(); Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -d -r1.98 -r1.99 *** OperatingRound.java 6 Feb 2010 23:48:26 -0000 1.98 --- OperatingRound.java 14 Feb 2010 20:47:45 -0000 1.99 *************** *** 6,9 **** --- 6,10 ---- import rails.common.GuiDef; import rails.game.action.*; + import rails.game.correct.*; import rails.game.move.CashMove; import rails.game.move.MapChange; *************** *** 26,29 **** --- 27,33 ---- protected boolean actionPossible = true; + /* sfy: using rails without map support */ + protected boolean noMapMode = false; + protected TreeMap<Integer, PublicCompanyI> operatingCompanies; protected List<PublicCompanyI> companiesOperatedThisRound *************** *** 68,72 **** public static final int SPLIT_ROUND_DOWN = 2; // More to the treasury ! protected static GameDef.OrStep[] steps = new GameDef.OrStep[] { GameDef.OrStep.INITIAL, --- 72,76 ---- public static final int SPLIT_ROUND_DOWN = 2; // More to the treasury ! protected static GameDef.OrStep[] steps = new GameDef.OrStep[] { GameDef.OrStep.INITIAL, *************** *** 94,98 **** operatingCompanyArray = super.getOperatingCompanies(); ! guiHints.setVisibilityHint(GuiDef.Panel.STOCK_MARKET, false); guiHints.setVisibilityHint(GuiDef.Panel.STATUS, true); --- 98,105 ---- operatingCompanyArray = super.getOperatingCompanies(); ! ! // sfy NoMapMode ! noMapMode = GameOption.convertValueToBoolean("NoMapMode", getGameOption("NoMapMode")); ! guiHints.setVisibilityHint(GuiDef.Panel.STOCK_MARKET, false); guiHints.setVisibilityHint(GuiDef.Panel.STATUS, true); *************** *** 139,143 **** if (operatingCompanyArray.length > 0) { ! if (setNextOperatingCompany(true)) { setStep(GameDef.OrStep.INITIAL); return; --- 146,150 ---- if (operatingCompanyArray.length > 0) { ! if (setNextOperatingCompany(true)){ setStep(GameDef.OrStep.INITIAL); return; *************** *** 194,197 **** --- 201,208 ---- result = buyBonusToken((BuyBonusToken) selectedAction); + } else if (selectedAction instanceof CorrectCashI) { + // includes OperatingCost + result = executeCorrectCash((CorrectCashI) selectedAction); + } else if (selectedAction instanceof SetDividend) { *************** *** 556,560 **** // If this is a home base token lay, stop here ! if (action.getType() == LayBaseToken.HOME_CITY) return true; if (cost > 0) { --- 567,573 ---- // If this is a home base token lay, stop here ! if (action.getType() == LayBaseToken.HOME_CITY) { ! return true; ! } if (cost > 0) { *************** *** 738,741 **** --- 751,757 ---- return true; } + + + public boolean setRevenueAndDividend(SetDividend action) { *************** *** 921,924 **** --- 937,1026 ---- } + public 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; + } + + /** * Internal method: change the OR state to the next step. If the currently *************** *** 1001,1007 **** operatingCompany.getPresident().getName())); setCurrentPlayer(operatingCompany.getPresident()); operatingCompany.initTurn(); trainsBoughtThisTurn.clear(); ! setStep (GameDef.OrStep.LAY_TRACK); } --- 1103,1120 ---- operatingCompany.getPresident().getName())); setCurrentPlayer(operatingCompany.getPresident()); + + if (noMapMode && !operatingCompany.hasLaidHomeBaseTokens()){ + // Lay base token in noMapMode + BaseToken token = operatingCompany.getFreeToken(); + if (token == null) { + log.error("Company " + operatingCompany.getName() + " has no free token to lay base token"); + } else { + log.debug("Company " + operatingCompany.getName() + " lays base token in nomap mode"); + token.moveTo(bank.getUnavailable()); + } + } operatingCompany.initTurn(); trainsBoughtThisTurn.clear(); ! // setStep (GameDef.OrStep.LAY_TRACK); duplication } *************** *** 1926,1930 **** if (getStep() == GameDef.OrStep.INITIAL) { initTurn(); ! setStep (GameDef.OrStep.LAY_TRACK); } --- 2039,2047 ---- if (getStep() == GameDef.OrStep.INITIAL) { initTurn(); ! if (noMapMode) { ! nextStep (GameDef.OrStep.LAY_TOKEN); ! } else { ! setStep (GameDef.OrStep.LAY_TRACK); ! } } *************** *** 1959,1962 **** --- 2076,2081 ---- } else if (step == GameDef.OrStep.CALC_REVENUE) { prepareRevenueAndDividendAction(); + if (noMapMode) + prepareOperatingCostsAction(); } else if (step == GameDef.OrStep.BUY_TRAIN) { setBuyableTrains(); *************** *** 1967,1970 **** --- 2086,2092 ---- doneAllowed = true; //} + if (noMapMode && (operatingCompany.getLastRevenue() == 0)) + prepareOperatingCostsAction(); + } else if (step == GameDef.OrStep.DISCARD_TRAINS) { *************** *** 2090,2093 **** --- 2212,2241 ---- } } + + protected void prepareOperatingCostsAction() { + + // LayTile Actions + for (Integer tc: mapManager.getPossibleTileCosts()) { + possibleActions.add(new OperatingCost( + operatingCompany, OperatingCost.OCType.LAY_TILE, tc + )); + } + // LayBaseToken Actions + if (operatingCompany.getNumberOfFreeBaseTokens() != 0) { + possibleActions.add(new OperatingCost( + operatingCompany, OperatingCost.OCType.LAY_BASE_TOKEN, + operatingCompany.getBaseTokenLayCost() + )); + } + // Default Actions + possibleActions.add(new OperatingCost( + operatingCompany, OperatingCost.OCType.LAY_TILE, 0 + )); + if (operatingCompany.getNumberOfFreeBaseTokens() != 0) { + possibleActions.add(new OperatingCost( + operatingCompany, OperatingCost.OCType.LAY_BASE_TOKEN, 0 + )); + } + } /** Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** MapHex.java 5 Feb 2010 19:55:01 -0000 1.36 --- MapHex.java 14 Feb 2010 20:47:45 -0000 1.37 *************** *** 335,338 **** --- 335,342 ---- } } + + public int[] getTileCostAsArray(){ + return tileCost; + } /** Index: GameOption.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameOption.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GameOption.java 15 Jan 2010 19:55:59 -0000 1.9 --- GameOption.java 14 Feb 2010 20:48:02 -0000 1.10 *************** *** 102,104 **** --- 102,110 ---- } + /** Get GameOption Value as Boolean Value */ + public static boolean convertValueToBoolean(String name, String value) { + return value != null + && optionsMap.get(name).isBoolean + && OPTION_VALUE_YES.equalsIgnoreCase(value); + } } |