From: Erik V. <ev...@us...> - 2008-11-29 20:01:43
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv26165/rails/game Modified Files: TileI.java Tile.java PublicCompany.java OperatingRound.java MapHex.java City.java Log Message: Allow selection of 1830 Erie home base station while upgrading to green. Index: City.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/City.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** City.java 4 Jun 2008 19:00:32 -0000 1.4 --- City.java 29 Nov 2008 20:01:33 -0000 1.5 *************** *** 94,98 **** token.setHolder(this); boolean result = tokens.add(token); - // mapHex.update(); return result; } --- 94,97 ---- *************** *** 146,149 **** --- 145,158 ---- return false; } + + public boolean hasTokenOf (String companyName) { + for (TokenI token : tokens) { + if (token instanceof BaseToken + && ((BaseToken)token).getCompany().getName().equals(companyName)) { + return true; + } + } + return false; + } public void setTokens(ArrayList<TokenI> tokens) { *************** *** 173,177 **** b.append(")"); return b.toString(); - // return "City ID: " + number + ", Hex: " + mapHex.getName(); } } --- 182,185 ---- Index: Tile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Tile.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Tile.java 20 Nov 2008 21:49:38 -0000 1.23 --- Tile.java 29 Nov 2008 20:01:33 -0000 1.24 *************** *** 43,46 **** --- 43,51 ---- public static final int UNLIMITED_TILES = -1; + /** + * Flag indicating that player must reposition any basetokens during the upgrade. + */ + boolean relayBaseTokensOnUpgrade = false; + /** Off-board preprinted tiles */ public static final String RED_COLOUR_NAME = "red"; *************** *** 253,257 **** } ! } } --- 258,268 ---- } ! ! // Set reposition base tokens flag ! // (valid for all upgrades although attribute of one) ! relayBaseTokensOnUpgrade = upgradeTag.getAttributeAsBoolean( ! "relayBaseTokens", ! relayBaseTokensOnUpgrade); ! } } *************** *** 380,383 **** --- 391,398 ---- } + public boolean relayBaseTokensOnUpgrade() { + return relayBaseTokensOnUpgrade; + } + public boolean lay(MapHex hex) { *************** *** 474,477 **** --- 489,493 ---- allowedPhases = Arrays.asList(phases.split(",")); } + private void convertHexString() { Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** PublicCompany.java 20 Nov 2008 21:49:38 -0000 1.43 --- PublicCompany.java 29 Nov 2008 20:01:33 -0000 1.44 *************** *** 727,731 **** public void start(StockSpaceI startSpace) { ! log.debug("+++Starting1b "+name); hasStarted.set(true); setParSpace(startSpace); --- 727,731 ---- public void start(StockSpaceI startSpace) { ! hasStarted.set(true); setParSpace(startSpace); Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** OperatingRound.java 20 Nov 2008 21:49:38 -0000 1.44 --- OperatingRound.java 29 Nov 2008 20:01:33 -0000 1.45 *************** *** 374,378 **** hex.getName(), Bank.format(cost) })); } ! hex.upgrade(tile, orientation); // Was a special property used? --- 374,378 ---- hex.getName(), Bank.format(cost) })); } ! hex.upgrade(action); // Was a special property used? Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** MapHex.java 26 Nov 2008 22:26:14 -0000 1.20 --- MapHex.java 29 Nov 2008 20:01:33 -0000 1.21 *************** *** 8,11 **** --- 8,12 ---- import org.apache.log4j.Logger; + import rails.game.action.LayTile; import rails.game.model.ModelObject; import rails.game.move.Moveable; *************** *** 362,368 **** * replaceTile(), via a TileMove object. */ ! public void upgrade(TileI newTile, int newRotation) { City newCity; String newTracks; if (currentTile.getNumStations() == newTile.getNumStations()) { --- 363,376 ---- * replaceTile(), via a TileMove object. */ ! public void upgrade(LayTile action) { ! TileI newTile = action.getLaidTile(); ! int newRotation = action.getOrientation(); ! City newCity; String newTracks; + List<City> newCities; + + Map<String, Integer> relaidTokens = action.getRelaidBaseTokens(); + if (relaidTokens == null) relaidTokens = new HashMap<String, Integer>(); if (currentTile.getNumStations() == newTile.getNumStations()) { *************** *** 372,407 **** // may become different from the new tile's // station numbers). // Scan the old cities/stations, // and assign new stations where tracks correspond for (City city : cities) { Station oldStation = city.getRelatedStation(); int[] oldTrackEnds = getTrackEndPoints(currentTile, currentTileRotation, oldStation); ! if (oldTrackEnds.length == 0) { ! // Old tile without any tracks: do not try to match ! // but just assign in sequence. ! // (assuming that we never will have an old tile ! // where some cities have tracks and others haven't). ! Station newStation = ! newTile.getStations().get(city.getNumber() - 1); ! city.setRelatedStation(newStation); ! city.setSlots(newStation.getBaseSlots()); ! log.debug("Assigned " ! + city.getUniqueId() ! + " from " ! + oldStation.getId() ! + " " ! + getConnectionString(currentTile, ! currentTileRotation, ! oldStation.getNumber()) ! + " to " ! + newStation.getId() ! + " " ! + getConnectionString(newTile, newRotation, ! newStation.getNumber())); ! continue; ! } station: for (Station newStation : newTile.getStations()) { int[] newTrackEnds = --- 380,403 ---- // may become different from the new tile's // station numbers). + Map<City, Station> citiesToStations = new HashMap<City, Station>(); + + // Check for manual handling of tokens + for (String compName : relaidTokens.keySet()) { + for (City city : cities) { + if (city.hasTokenOf(compName)) { + citiesToStations.put(city, newTile.getStations().get(relaidTokens.get(compName)-1)); + } + } + } // Scan the old cities/stations, // and assign new stations where tracks correspond for (City city : cities) { + if (citiesToStations.containsKey(city)) continue; Station oldStation = city.getRelatedStation(); int[] oldTrackEnds = getTrackEndPoints(currentTile, currentTileRotation, oldStation); ! if (oldTrackEnds.length == 0) continue; station: for (Station newStation : newTile.getStations()) { int[] newTrackEnds = *************** *** 411,443 **** if (oldTrackEnds[i] == newTrackEnds[j]) { // Match found! ! city.setRelatedStation(newStation); ! city.setSlots(newStation.getBaseSlots()); ! newTracks = ! getConnectionString(newTile, ! newRotation, ! newStation.getNumber()); ! city.setTrackEdges(newTracks); ! log.debug("Assigned " ! + city.getUniqueId() ! + " from " ! + oldStation.getId() ! + " " ! + getConnectionString(currentTile, ! currentTileRotation, ! oldStation.getNumber()) ! + " to " + newStation.getId() + " " ! + newTracks); ! break station; ! } } } - } - } ! new TileMove(this, currentTile, currentTileRotation, cities, ! newTile, newRotation, cities); ! } else { // If the number of stations does change, --- 407,453 ---- if (oldTrackEnds[i] == newTrackEnds[j]) { // Match found! ! citiesToStations.put(city, newStation); ! continue station; } } } } } ! ! // Map any unassigned cities randomly ! city: for (City city : cities) { ! if (citiesToStations.containsKey(city)) continue; ! for (Station newStation : newTile.getStations()) { ! if (citiesToStations.values().contains(newStation)) continue; ! citiesToStations.put(city, newStation); ! continue city; ! } ! } ! ! ! // Assign the new Stations to the existing cities ! for (City city : citiesToStations.keySet()) { ! Station newStation = citiesToStations.get(city); ! Station oldStation = city.getRelatedStation(); ! city.setRelatedStation(newStation); ! city.setSlots(newStation.getBaseSlots()); ! newTracks = ! getConnectionString(newTile, ! newRotation, ! newStation.getNumber()); ! city.setTrackEdges(newTracks); ! log.debug("Assigned " ! + city.getUniqueId() ! + " from " ! + oldStation.getId() ! + " " ! + getConnectionString(currentTile, ! currentTileRotation, ! oldStation.getNumber()) ! + " to " + newStation.getId() + " " ! + newTracks); ! } ! newCities = cities; ! } else { // If the number of stations does change, *************** *** 446,450 **** // Build a map from old to new cities, // so that we can move tokens at the end. ! List<City> newCities = new ArrayList<City>(4); Map<Integer, City> mNewCities = new HashMap<Integer, City>(4); Map<City, City> oldToNewCities = new HashMap<City, City>(); --- 456,460 ---- // Build a map from old to new cities, // so that we can move tokens at the end. ! newCities = new ArrayList<City>(4); Map<Integer, City> mNewCities = new HashMap<Integer, City>(4); Map<City, City> oldToNewCities = new HashMap<City, City>(); *************** *** 468,474 **** + getConnectionString(currentTile, currentTileRotation, oldStation.getNumber())); - // for (City newCity : newCities) { station: for (Station newStation : newTile.getStations()) { - // Station newStation = newCity.getRelatedStation(); int[] newTrackEnds = getTrackEndPoints(newTile, newRotation, newStation); --- 478,482 ---- *************** *** 576,581 **** } - - // Check if there any new stations not corresponding // to an old city. --- 584,587 ---- *************** *** 647,655 **** } - // Replace the tile - new TileMove(this, currentTile, currentTileRotation, cities, - newTile, newRotation, newCities); } /* TODO Further consequences to be processed here, e.g. new routes etc. */ } --- 653,662 ---- } } + // Replace the tile + new TileMove(this, currentTile, currentTileRotation, cities, + newTile, newRotation, newCities); + /* TODO Further consequences to be processed here, e.g. new routes etc. */ } *************** *** 718,722 **** return false; } else { - // new TokenMove (token, company, station); token.moveTo(city); return true; --- 725,728 ---- *************** *** 729,733 **** return false; } else { - // new TokenMove (token, token.getHolder(), this); token.moveTo(this); return true; --- 735,738 ---- *************** *** 804,823 **** } - /** Check if the tile already has a token of a company in one station */ - /* - * public boolean hasTokenOfCompany (PublicCompanyI company, Station - * station) { - * - * for (TokenI token : station.getTokens()) { if - * (((BaseToken)token).getCompany() == company) return true; } return false; } - */ - - /** Check if the tile already has a token of a company in one station */ - /* - * public boolean hasTokenOfCompany (PublicCompanyI company, int station) { - * - * return hasTokenOfCompany (company, cities.get(station).getNumber()); } - */ - public List<TokenI> getTokens(int cityNumber) { if (cities.size() > 0 && mCities.get(cityNumber) != null) { --- 809,812 ---- Index: TileI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TileI.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TileI.java 20 Nov 2008 21:49:38 -0000 1.13 --- TileI.java 29 Nov 2008 20:01:33 -0000 1.14 *************** *** 45,48 **** --- 45,50 ---- public String getUpgradesString(MapHex hex); + public boolean relayBaseTokensOnUpgrade(); + public boolean hasStations(); |