From: Stefan F. <ste...@us...> - 2010-05-29 09:39:07
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv1284/rails/game Modified Files: TileManager.java TileI.java Tile.java Log Message: Start of refining of the map correction Index: TileI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TileI.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** TileI.java 15 May 2010 19:05:39 -0000 1.20 --- TileI.java 29 May 2010 09:38:58 -0000 1.21 *************** *** 49,53 **** public List<TileI> getUpgrades(MapHex hex, PhaseI phase); ! public List<TileI> getAllUpgrades(); public List<TileI> getValidUpgrades(MapHex hex, PhaseI phase); --- 49,53 ---- public List<TileI> getUpgrades(MapHex hex, PhaseI phase); ! public List<TileI> getAllUpgrades(MapHex hex); public List<TileI> getValidUpgrades(MapHex hex, PhaseI phase); Index: TileManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TileManager.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** TileManager.java 28 Mar 2010 17:05:55 -0000 1.16 --- TileManager.java 29 May 2010 09:38:58 -0000 1.17 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import rails.util.LocalText; import rails.util.Tag; public class TileManager implements ConfigurableComponentI { protected Map<Integer, TileI> tileMap = new HashMap<Integer, TileI>(); protected List<Integer> tileIds = new ArrayList<Integer>(); // private static List<String> directories = new ArrayList<String>(); private List<String> directories = new ArrayList<String>(); /** * No-args constructor. */ public TileManager() { } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tileSetTop) throws ConfigurationException { /* * Note: prefix se is used for elements from TileSet.xml, prefix te for * elements from Tiles.xml. */ String tileDefFileName = tileSetTop.getAttributeAsString("tiles"); if (tileDefFileName == null) throw new ConfigurationException(LocalText.getText("NoTilesXML")); //directories.add("data/" + ComponentManager.getGameName()); directories.add("data/" + GameManager.getInstance().getGameName()); Tag tileDefTop = Tag.findTopTagInFile(tileDefFileName, directories, "Tiles"); if (tileDefTop == null) throw new ConfigurationException(LocalText.getText("NoTilesTag")); List<Tag> tileSetList = tileSetTop.getChildren("Tile"); List<Tag> tileDefList = tileDefTop.getChildren("Tile"); /* * The XML files TileSet.xml and Tiles.xml are read side by side, as * each one configures different tile aspects. The reason for having two * XML files is, that Tiles.xml defines per-tile aspects that are the * same for all games (such as the colour, tracks and stations; this * file is an automatically generated subset of the generic file * tiles/Tiles.xml), whereas TileSet.xml specifies the aspects that are * (or can be) specific to each rails.game (such as the possible * upgrades). <p>TileSet.xml is leading. */ int tileId; TileI tile; // Creates maps to the tile definitions in both files. Map<Integer, Tag> tileSetMap = new HashMap<Integer, Tag>(); Map<Integer, Tag> tileDefMap = new HashMap<Integer, Tag>(); for (Tag tileSetTag : tileSetList) { tileId = tileSetTag.getAttributeAsInteger("id"); /* * Check for duplicates (this also covers missing tile ids, as this * returns 0, and we always have a tile numbered 0! */ if (tileSetMap.containsKey(tileId)) { throw new ConfigurationException(LocalText.getText( "DuplicateTilesetID", String.valueOf(tileId))); } tileSetMap.put(tileId, tileSetTag); tileIds.add(tileId); } for (Tag tileDefTag : tileDefList) { tileId = tileDefTag.getAttributeAsInteger("id"); /* * Check for duplicates (this also covers missing tile ids, as this * returns 0, and we always have a tile numbered 0! */ if (tileDefMap.containsKey(tileId)) { throw new ConfigurationException(LocalText.getText( "DuplicateTileID", String.valueOf(tileId))); } else if (!tileSetMap.containsKey(tileId)) { throw new ConfigurationException(LocalText.getText( "TileMissingInTileSet", String.valueOf(tileId))); } tileDefMap.put(tileId, tileDefTag); } // Create the Tile objects (must be done before further parsing) for (Integer id : tileSetMap.keySet()) { tile = new Tile(id); tileMap.put(id, tile); } // Finally, parse the <Tile> subtags for (Integer id : tileMap.keySet()) { tile = tileMap.get(id); tile.configureFromXML(tileSetMap.get(id), tileDefMap.get(id)); } } public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { for (TileI tile : tileMap.values()) { tile.finishConfiguration(this); } } public TileI getTile(int id) { return tileMap.get(id); } /** Get the tile IDs in the XML definition sequence */ public List<Integer> getTileIds() { return tileIds; } /** returns the set of all possible upgrade tiles */ public List<TileI> getAllUpgrades(TileI tile) { TreeSet<TileI> tileSet = new TreeSet<TileI>(); return new ArrayList<TileI>(recursiveUpgrades(tile, tileSet)); } private TreeSet<TileI> recursiveUpgrades(TileI tile, TreeSet<TileI> tileSet) { tileSet.add(tile); List<TileI> directUpgrades = tile.getAllUpgrades(); for (TileI upgrade:directUpgrades) if (!tileSet.contains(upgrade)) tileSet = recursiveUpgrades(upgrade, tileSet); return tileSet; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import rails.util.LocalText; import rails.util.Tag; public class TileManager implements ConfigurableComponentI { protected Map<Integer, TileI> tileMap = new HashMap<Integer, TileI>(); protected List<Integer> tileIds = new ArrayList<Integer>(); // private static List<String> directories = new ArrayList<String>(); private List<String> directories = new ArrayList<String>(); /** * No-args constructor. */ public TileManager() { } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tileSetTop) throws ConfigurationException { /* * Note: prefix se is used for elements from TileSet.xml, prefix te for * elements from Tiles.xml. */ String tileDefFileName = tileSetTop.getAttributeAsString("tiles"); if (tileDefFileName == null) throw new ConfigurationException(LocalText.getText("NoTilesXML")); //directories.add("data/" + ComponentManager.getGameName()); directories.add("data/" + GameManager.getInstance().getGameName()); Tag tileDefTop = Tag.findTopTagInFile(tileDefFileName, directories, "Tiles"); if (tileDefTop == null) throw new ConfigurationException(LocalText.getText("NoTilesTag")); List<Tag> tileSetList = tileSetTop.getChildren("Tile"); List<Tag> tileDefList = tileDefTop.getChildren("Tile"); /* * The XML files TileSet.xml and Tiles.xml are read side by side, as * each one configures different tile aspects. The reason for having two * XML files is, that Tiles.xml defines per-tile aspects that are the * same for all games (such as the colour, tracks and stations; this * file is an automatically generated subset of the generic file * tiles/Tiles.xml), whereas TileSet.xml specifies the aspects that are * (or can be) specific to each rails.game (such as the possible * upgrades). <p>TileSet.xml is leading. */ int tileId; TileI tile; // Creates maps to the tile definitions in both files. Map<Integer, Tag> tileSetMap = new HashMap<Integer, Tag>(); Map<Integer, Tag> tileDefMap = new HashMap<Integer, Tag>(); for (Tag tileSetTag : tileSetList) { tileId = tileSetTag.getAttributeAsInteger("id"); /* * Check for duplicates (this also covers missing tile ids, as this * returns 0, and we always have a tile numbered 0! */ if (tileSetMap.containsKey(tileId)) { throw new ConfigurationException(LocalText.getText( "DuplicateTilesetID", String.valueOf(tileId))); } tileSetMap.put(tileId, tileSetTag); tileIds.add(tileId); } for (Tag tileDefTag : tileDefList) { tileId = tileDefTag.getAttributeAsInteger("id"); /* * Check for duplicates (this also covers missing tile ids, as this * returns 0, and we always have a tile numbered 0! */ if (tileDefMap.containsKey(tileId)) { throw new ConfigurationException(LocalText.getText( "DuplicateTileID", String.valueOf(tileId))); } else if (!tileSetMap.containsKey(tileId)) { throw new ConfigurationException(LocalText.getText( "TileMissingInTileSet", String.valueOf(tileId))); } tileDefMap.put(tileId, tileDefTag); } // Create the Tile objects (must be done before further parsing) for (Integer id : tileSetMap.keySet()) { tile = new Tile(id); tileMap.put(id, tile); } // Finally, parse the <Tile> subtags for (Integer id : tileMap.keySet()) { tile = tileMap.get(id); tile.configureFromXML(tileSetMap.get(id), tileDefMap.get(id)); } } public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { for (TileI tile : tileMap.values()) { tile.finishConfiguration(this); } } public TileI getTile(int id) { return tileMap.get(id); } /** Get the tile IDs in the XML definition sequence */ public List<Integer> getTileIds() { return tileIds; } /** returns the set of all possible upgrade tiles */ public List<TileI> getAllUpgrades(TileI tile, MapHex hex) { TreeSet<TileI> tileSet = new TreeSet<TileI>(); return new ArrayList<TileI>(recursiveUpgrades(tile, hex, tileSet)); } private TreeSet<TileI> recursiveUpgrades(TileI tile, MapHex hex, TreeSet<TileI> tileSet) { tileSet.add(tile); List<TileI> directUpgrades = tile.getAllUpgrades(hex); for (TileI upgrade:directUpgrades) if (!tileSet.contains(upgrade)) tileSet = recursiveUpgrades(upgrade, hex, tileSet); return tileSet; } } \ No newline at end of file Index: Tile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Tile.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** Tile.java 18 May 2010 04:12:23 -0000 1.42 --- Tile.java 29 May 2010 09:38:58 -0000 1.43 *************** *** 394,406 **** /** ! * Get all possible upgrades for a specific tile * * @return A List of valid upgrade TileI objects. */ ! public List<TileI> getAllUpgrades() { List<TileI> upgr = new ArrayList<TileI>(); for (Upgrade upgrade : upgrades) { ! upgr.add(upgrade.getTile()); } return upgr; --- 394,409 ---- /** ! * Get all possible upgrades for a specific tile on a certain hex * * @return A List of valid upgrade TileI objects. */ ! public List<TileI> getAllUpgrades(MapHex hex) { List<TileI> upgr = new ArrayList<TileI>(); for (Upgrade upgrade : upgrades) { ! TileI tile = upgrade.getTile(); ! if (upgrade.isAllowedForHex(hex)) { ! upgr.add(tile); ! } } return upgr; |