From: Erik V. <ev...@us...> - 2008-11-26 22:26:25
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv19600/rails/game Modified Files: MapHex.java Log Message: Fixed 1851 Louisville green upgrade bug: L&N token not displayed Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** MapHex.java 4 Jun 2008 19:00:31 -0000 1.19 --- MapHex.java 26 Nov 2008 22:26:14 -0000 1.20 *************** *** 451,463 **** Map<Station, City> newStationsToCities = new HashMap<Station, City>(); ! // Tentatively number the new cities after the new stations ! // City city; ! // for (Station newStation : newTile.getStations()) { ! // city = new City (this, newStation.getNumber(), newStation); ! // newCities.add(city); ! // } ! // Scan the old cities/stations, // and assign new stations where tracks correspond for (City oldCity : cities) { int cityNumber = oldCity.getNumber(); --- 451,458 ---- Map<Station, City> newStationsToCities = new HashMap<Station, City>(); ! // Scan the old cities/stations, // and assign new stations where tracks correspond + int newCityNumber = 0; for (City oldCity : cities) { int cityNumber = oldCity.getNumber(); *************** *** 491,495 **** if (!newStationsToCities.containsKey(newStation)) { newCity = ! new City(this, cityNumber, newStation); newCities.add(newCity); --- 486,490 ---- if (!newStationsToCities.containsKey(newStation)) { newCity = ! new City(this, ++newCityNumber, newStation); newCities.add(newCity); *************** *** 529,543 **** } } } // Check if there any new stations not corresponding ! // to an old city - create a new city for these stations. for (Station newStation : newTile.getStations()) { if (newStationsToCities.containsKey(newStation)) continue; int cityNumber; for (cityNumber = 1; mNewCities.containsKey(cityNumber); cityNumber++) ; ! newCity = new City(this, cityNumber, newStation); newCities.add(newCity); mNewCities.put(cityNumber, newCity); --- 524,591 ---- } + + } + } + + // If an old city is not yet connected, check if was + // connected to another city it has merged into (1851 Louisville) + for (City oldCity : cities) { + if (oldToNewCities.containsKey(oldCity)) continue; + Station oldStation = oldCity.getRelatedStation(); + int[] oldTrackEnds = + getTrackEndPoints(currentTile, currentTileRotation, + oldStation); + station: for (int i = 0; i < oldTrackEnds.length; i++) { + log.debug("Old track ending at "+oldTrackEnds[i]); + if (oldTrackEnds[i] < 0) { + int oldStationNumber = -oldTrackEnds[i]; + // Find the old city that has this number + for (City oldCity2 : cities) { + log.debug("Old city "+oldCity2.getNumber()+" has station "+oldCity2.getRelatedStation().getNumber()); + log.debug(" and links to new city "+oldToNewCities.get(oldCity2)); + if (oldCity2.getRelatedStation().getNumber() + == oldStationNumber + && oldToNewCities.containsKey(oldCity2)) { + newCity = oldToNewCities.get(oldCity2); + oldToNewCities.put(oldCity, newCity); + log.debug("Assigned from " + + oldCity.getUniqueId() + + " #" + + currentTile.getId() + + "/" + + currentTileRotation + + " " + + oldStation.getId() + + " " + + getConnectionString(currentTile, + currentTileRotation, + oldStation.getNumber()) + + " to " + newCity.getUniqueId() + + " #" + newTile.getId() + "/" + + newRotation + " " + + newCity.getRelatedStation().getId() + " " + + newCity.getTrackEdges()); + break station; + + + } + } + + } } } + + // Check if there any new stations not corresponding ! // to an old city. for (Station newStation : newTile.getStations()) { if (newStationsToCities.containsKey(newStation)) continue; + + // Create a new city for such a station. int cityNumber; for (cityNumber = 1; mNewCities.containsKey(cityNumber); cityNumber++) ; ! newCity = new City(this, ++newCityNumber, newStation); newCities.add(newCity); mNewCities.put(cityNumber, newCity); *************** *** 558,563 **** for (City oldCity : cities) { - // log.debug("Old city "+oldCity.getNumber()+" has - // "+oldCity.getTokens().size()+" tokens"); newCity = oldToNewCities.get(oldCity); if (newCity != null) { --- 606,609 ---- |