From: Stefan F. <ste...@us...> - 2010-05-29 09:39:07
|
Update of /cvsroot/rails/18xx/rails/game/correct In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv1284/rails/game/correct Modified Files: MapCorrectionManager.java MapCorrectionAction.java Log Message: Start of refining of the map correction Index: MapCorrectionAction.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/correct/MapCorrectionAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MapCorrectionAction.java 28 Mar 2010 17:05:56 -0000 1.1 --- MapCorrectionAction.java 29 May 2010 09:38:58 -0000 1.2 *************** *** 4,14 **** --- 4,19 ---- import java.io.ObjectInputStream; import java.util.ArrayList; + import java.util.HashMap; import java.util.List; + import java.util.Map; import rails.game.correct.MapCorrectionManager.*; + import rails.game.BaseToken; + import rails.game.Station; import rails.game.MapHex; import rails.game.MapManager; import rails.game.TileI; import rails.game.TileManager; + import rails.game.TokenI; import rails.game.action.PossibleAction; import rails.util.Util; *************** *** 38,42 **** /** Orientation: how to lay the tile */ private int orientation; ! /** * Instantiates a new map tile correction action. --- 43,55 ---- /** Orientation: how to lay the tile */ private int orientation; ! ! /** RelayBaseTokens: how to relay the base tokens */ ! transient private List<BaseToken> tokensToRelay; ! private String[]tokensToRelayOwner; ! transient private List<Station> stationsForRelay; ! private int[] stationForRelayId; ! transient private List<Station> possibleStations; ! private int[] possibleStationsId; ! /** * Instantiates a new map tile correction action. *************** *** 63,67 **** public TileI getChosenTile() { ! if (step.ordinal() > ActionStep.SELECT_TILE.ordinal()) return tiles.get(0); else --- 76,80 ---- public TileI getChosenTile() { ! if (nextStep.ordinal() > ActionStep.SELECT_TILE.ordinal()) return tiles.get(0); else *************** *** 69,73 **** } ! public void setTiles(List<TileI> tiles) { this.tiles = tiles; this.tileIds = new int[tiles.size()]; --- 82,86 ---- } ! void setTiles(List<TileI> tiles) { this.tiles = tiles; this.tileIds = new int[tiles.size()]; *************** *** 76,79 **** --- 89,116 ---- } + public List<Station> getStationsForRelay() { + return stationsForRelay; + } + + private void setStationsForRelay(List<Station> stations) { + this.stationsForRelay = stations; + } + + public List<BaseToken> getTokensToRelay() { + return tokensToRelay; + } + + void setTokensToRelay(List<BaseToken> tokens) { + this.tokensToRelay = tokens; + } + + public List<Station> getPossibleStations() { + return possibleStations; + } + + void setPossibleStations(List<Station> possibleStations) { + this.possibleStations = possibleStations; + } + public int getOrientation(){ return orientation; *************** *** 88,92 **** } ! private void setNextStep(ActionStep step) { this.nextStep = step; if (step == null) --- 125,129 ---- } ! void setNextStep(ActionStep step) { this.nextStep = step; if (step == null) *************** *** 119,122 **** --- 156,164 ---- public void selectOrientation(int orientation) { setOrientation(orientation); + setNextStep(ActionStep.RELAY_BASETOKENS); + } + + public void selectRelayBaseTokens(List<Station> chosenStations) { + setStationsForRelay(chosenStations); setNextStep(ActionStep.FINISHED); } *************** *** 160,163 **** --- 202,211 ---- if (step.ordinal() > ActionStep.SELECT_ORIENTATION.ordinal()) b.append(" Orientation=" + orientation); + if (step.ordinal() >= ActionStep.RELAY_BASETOKENS.ordinal()) + b.append(" Tokens to relay=" + tokensToRelay); + if (step.ordinal() == ActionStep.RELAY_BASETOKENS.ordinal()) + b.append(" Possible Stations=" + possibleStations); + if (step.ordinal() > ActionStep.RELAY_BASETOKENS.ordinal()) + b.append(" Selected stations for relay=" + stationsForRelay); return b.toString(); } Index: MapCorrectionManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/correct/MapCorrectionManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MapCorrectionManager.java 28 Mar 2010 17:05:56 -0000 1.1 --- MapCorrectionManager.java 29 May 2010 09:38:58 -0000 1.2 *************** *** 1,14 **** package rails.game.correct; import java.util.HashMap; import java.util.List; ! import rails.game.correct.MapCorrectionAction.*; ! import rails.game.GameManager; import rails.game.MapHex; import rails.game.ReportBuffer; import rails.game.TileI; import rails.game.TileManager; import rails.util.LocalText; --- 1,19 ---- package rails.game.correct; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; + import java.util.Map; ! import rails.game.BaseToken; ! import rails.game.City; ! import rails.game.DisplayBuffer; import rails.game.GameManager; import rails.game.MapHex; import rails.game.ReportBuffer; + import rails.game.Station; import rails.game.TileI; import rails.game.TileManager; + import rails.game.TokenI; import rails.util.LocalText; *************** *** 16,20 **** public static enum ActionStep { ! SELECT_HEX,SELECT_TILE,SELECT_ORIENTATION,FINISHED,CANCELLED; } --- 21,25 ---- public static enum ActionStep { ! SELECT_HEX,SELECT_TILE,SELECT_ORIENTATION,RELAY_BASETOKENS,FINISHED,CANCELLED; } *************** *** 42,76 **** if (action instanceof MapCorrectionAction) return execute((MapCorrectionAction) action); ! else return super.executeCorrection(action); } private boolean execute(MapCorrectionAction action){ MapHex hex = action.getLocation(); TileI chosenTile = action.getChosenTile(); - TileManager tmgr = gameManager.getTileManager(); TileI preprintedTile = tmgr.getTile(hex.getPreprintedTileId()); ! // already finished, thus on reload ! ActionStep executeStep = action.getStep(); ! if (executeStep != ActionStep.FINISHED) ! executeStep = action.moveToNextStep(); ! ! switch (executeStep) { case SELECT_TILE: // create list of possible up and downgrades ! List<TileI> possibleTiles = tmgr.getAllUpgrades(preprintedTile); if (preprintedTile == hex.getCurrentTile()) possibleTiles.remove(hex.getCurrentTile()); // remove preprinted tile if still laid action.setTiles(possibleTiles); break; - case SELECT_ORIENTATION: // default orientation for preprinted files ! if (preprintedTile == chosenTile) action.selectOrientation(hex.getPreprintedTileRotation()); ! break; case FINISHED: // lays tiles --- 47,163 ---- if (action instanceof MapCorrectionAction) return execute((MapCorrectionAction) action); ! else // any other action, could be a correctionMode action return super.executeCorrection(action); } private boolean execute(MapCorrectionAction action){ + + if (action.getStep() == ActionStep.FINISHED) { + // already finished, thus on reload + action.setNextStep(ActionStep.FINISHED); + } MapHex hex = action.getLocation(); + TileI chosenTile = action.getChosenTile(); TileManager tmgr = gameManager.getTileManager(); TileI preprintedTile = tmgr.getTile(hex.getPreprintedTileId()); ! // check conditions ! String errMsg = null; ! while (true) { ! // check if chosenTile is still available (not for preprinted) ! if (chosenTile != null && chosenTile.getExternalId() > 0 && chosenTile != hex.getCurrentTile() ! && chosenTile.countFreeTiles() == 0) { ! errMsg = ! LocalText.getText("TileNotAvailable", ! chosenTile.getExternalId()); ! // return to step of hex selection ! action.selectHex(hex); ! break; ! } ! // check if chosenTile contains enough slots ! List<BaseToken> baseTokens = hex.getBaseTokens(); ! if (chosenTile != null && baseTokens != null && !baseTokens.isEmpty()) { ! List<Station> stations = chosenTile.getStations(); ! int nbSlots = 0; ! if (stations != null) { ! for (Station station:stations) { ! nbSlots += station.getBaseSlots(); ! } ! } ! if (baseTokens.size() > nbSlots) { ! errMsg = ! LocalText.getText("CorrectMapNotEnoughSlots", chosenTile.getExternalId()); ! // return to step of hex selection ! action.selectHex(hex); ! break; ! } ! } ! break; ! } ! ! if (errMsg != null) { ! DisplayBuffer.add(LocalText.getText("CorrectMapCannotLayTile", ! chosenTile.getExternalId(), ! hex.getName(), ! errMsg )); ! ; ! // stay at the same step ! action.setNextStep(action.getStep()); ! } ! ! ActionStep nextStep; ! // not yet finished, move to next step ! if (action.getStep() != ActionStep.FINISHED) ! nextStep = action.getNextStep(); ! else ! nextStep = ActionStep.FINISHED; ! ! // preparation for the next step ! switch (nextStep) { case SELECT_TILE: // create list of possible up and downgrades ! List<TileI> possibleTiles = tmgr.getAllUpgrades(preprintedTile, hex); if (preprintedTile == hex.getCurrentTile()) possibleTiles.remove(hex.getCurrentTile()); // remove preprinted tile if still laid action.setTiles(possibleTiles); break; case SELECT_ORIENTATION: // default orientation for preprinted files ! if (preprintedTile == chosenTile) { action.selectOrientation(hex.getPreprintedTileRotation()); ! return execute(action); ! } else if (chosenTile.getFixedOrientation() != -1) { ! action.selectOrientation(chosenTile.getFixedOrientation()); ! return execute(action); ! } else { ! break; ! } ! case RELAY_BASETOKENS: ! // check if relays are necessary: ! // A. downgrades or equalgrades to a tile with two stations or more ! if (chosenTile.getNumStations() >= 2 ! && hex.getCurrentTile().getColourNumber() >= chosenTile.getColourNumber() ! // B. or the current tile requires relays ! || hex.getCurrentTile().relayBaseTokensOnUpgrade()) { ! // define tokens for relays ! List<BaseToken> tokens = new ArrayList<BaseToken>(); ! for (City oldCity:hex.getCities()) { ! for (TokenI token:oldCity.getTokens()) { ! if (token instanceof BaseToken) { ! tokens.add((BaseToken)token); ! } ! } ! } ! action.setTokensToRelay(tokens); ! // define possible stations ! action.setPossibleStations(chosenTile.getStations()); ! break; ! } else { ! action.selectRelayBaseTokens(null); ! // move to FINISHED ! return execute(action); ! } case FINISHED: // lays tiles *************** *** 91,94 **** --- 178,185 ---- activeTileAction = null; } + + if (action.getStep() != ActionStep.FINISHED) { + action.moveToNextStep(); + } return true; |