From: Erik V. <ev...@us...> - 2009-11-04 20:33:32
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv21355/rails/game Modified Files: Portfolio.java BonusToken.java Bank.java GameManagerI.java TileManager.java TrainType.java PrivateCompany.java Train.java Company.java TrainManager.java TrainTypeI.java GameManager.java Log Message: More rationalising of static method usage Index: TrainTypeI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainTypeI.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** TrainTypeI.java 10 Oct 2009 15:25:49 -0000 1.10 --- TrainTypeI.java 4 Nov 2009 20:33:22 -0000 1.11 *************** *** 2,6 **** package rails.game; ! public interface TrainTypeI extends ConfigurableComponentI, Cloneable { --- 2,6 ---- package rails.game; ! public interface TrainTypeI extends ConfigurableComponentI, Cloneable { *************** *** 95,110 **** public String getRustedTrainTypeName(); ! public boolean isPermanent(); ! public void setPermanent(boolean permanent); ! public void setReleasedTrainType(TrainTypeI releasedTrainType); public void setRustedTrainType(TrainTypeI rustedTrainType); ! public TrainI cloneTrain(); ! public int getIndex(); } --- 95,111 ---- public String getRustedTrainTypeName(); ! public boolean isPermanent(); ! public void setPermanent(boolean permanent); ! public void setReleasedTrainType(TrainTypeI releasedTrainType); public void setRustedTrainType(TrainTypeI rustedTrainType); ! public TrainI cloneTrain(); ! public int getIndex(); + public TrainManager getTrainManager(); } Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Portfolio.java 31 Oct 2009 17:08:26 -0000 1.38 --- Portfolio.java 4 Nov 2009 20:33:22 -0000 1.39 *************** *** 73,79 **** protected String name; ! /** A map allowing finding portfolios by name, for use in deserialization */ ! protected static Map<String, Portfolio> portfolioMap = ! new HashMap<String, Portfolio>(); protected static Logger log = --- 73,81 ---- protected String name; ! /** Specific portfolio names */ ! public static final String IPO_NAME = "IPO"; ! public static final String POOL_NAME = "Pool"; ! public static final String SCRAPHEAP_NAME = "ScrapHeap"; ! public static final String UNAVAILABLE_NAME = "Unavailable"; protected static Logger log = *************** *** 83,87 **** this.name = name; this.owner = holder; ! portfolioMap.put(name, this); if (owner instanceof PublicCompanyI) { --- 85,90 ---- this.name = name; this.owner = holder; ! //portfolioMap.put(name, this); ! GameManager.getInstance().addPortfolio(this); if (owner instanceof PublicCompanyI) { *************** *** 95,102 **** } - public static Portfolio getByName(String name) { - return portfolioMap.get(name); - } - public void transferAssetsFrom(Portfolio otherPortfolio) { --- 98,101 ---- *************** *** 377,382 **** trains.add(train); TrainTypeI type = train.getType(); ! if (trainsPerType.get(type) == null) trainsPerType.put(type, new ArrayList<TrainI>()); trainsPerType.get(train.getType()).add(train); train.setHolder(this); --- 376,382 ---- trains.add(train); TrainTypeI type = train.getType(); ! if (!trainsPerType.containsKey(type)) { trainsPerType.put(type, new ArrayList<TrainI>()); + } trainsPerType.get(train.getType()).add(train); train.setHolder(this); *************** *** 398,402 **** public void discardTrain(TrainI train) { ! train.moveTo(Bank.getInstance().getPool()); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", name, train.getName() )); --- 398,402 ---- public void discardTrain(TrainI train) { ! train.moveTo(GameManager.getInstance().getBank().getPool()); ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", name, train.getName() )); *************** *** 453,456 **** --- 453,514 ---- /** + * Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the + * IPO. + * + * @param holder The Portfolio for which this list will be made (always + * IPO). + */ + + public String makeAbbreviatedListOfTrains() { + + if (trains == null || trains.isEmpty()) return ""; + + StringBuffer b = new StringBuffer(); + List<TrainI> trainsOfType; + + for (TrainTypeI type : GameManager.getInstance().getTrainManager().getTrainTypes()) { + trainsOfType = trainsPerType.get(type); + if (trainsOfType != null && !trainsOfType.isEmpty()) { + if (b.length() > 0) b.append(" "); + b.append(type.getName()).append("("); + if (type.hasInfiniteAmount()) { + b.append("+"); + } else { + b.append(trainsOfType.size()); + } + b.append(")"); + } + } + + return b.toString(); + } + + /** + * Make a full list of trains, like "2 2 3 3", to show in any field + * describing train possessions, except the IPO. + * + * @param holder The Portfolio for which this list will be made. + */ + public String makeFullListOfTrains() { + + if (trains == null || trains.isEmpty()) return ""; + + List<TrainI> trainsOfType; + StringBuffer b = new StringBuffer(); + + for (TrainTypeI type : GameManager.getInstance().getTrainManager().getTrainTypes()) { + trainsOfType = trainsPerType.get(type); + if (trainsOfType != null && !trainsOfType.isEmpty()) { + for (TrainI train : trainsOfType) { + if (b.length() > 0) b.append(" "); + b.append(train.getName()); + } + } + } + + return b.toString(); + } + + /** * Add a special property. Used to make special properties independent of * the private company that originally held it. Index: TileManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TileManager.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TileManager.java 31 Oct 2009 17:08:26 -0000 1.12 --- TileManager.java 4 Nov 2009 20:33:22 -0000 1.13 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import rails.util.LocalText; import rails.util.Tag; public class TileManager implements ConfigurableComponentI { protected static TileManager instance = null; protected Map<Integer, TileI> tileMap = new HashMap<Integer, TileI>(); protected List<Integer> tileIds = new ArrayList<Integer>(); private static List<String> directories = new ArrayList<String>(); /** * No-args constructor. */ public TileManager() { instance = this; } public static TileManager get() { return instance; } /** * @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()); 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; } } \ 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>(); /** * 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()); 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; } } \ No newline at end of file Index: TrainManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManager.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** TrainManager.java 31 Oct 2009 17:08:26 -0000 1.22 --- TrainManager.java 4 Nov 2009 20:33:22 -0000 1.23 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import rails.game.state.IntegerState; import rails.util.LocalText; import rails.util.Tag; public class TrainManager implements ConfigurableComponentI { // Static attributes protected List<TrainTypeI> lTrainTypes = new ArrayList<TrainTypeI>(); protected Map<String, TrainTypeI> mTrainTypes = new HashMap<String, TrainTypeI>(); protected boolean buyAtFaceValueBetweenDifferentPresidents = false; // Dynamic attributes protected Portfolio unavailable = null; protected IntegerState newTypeIndex; protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; protected GameManagerI gameManager = null; protected Bank bank = null; // Non-game attributes protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { newTypeIndex = new IntegerState("NewTrainTypeIndex", 0); } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { TrainType defaultType = null; TrainType newType; Tag defaultsTag = tag.getChild("Defaults"); if (defaultsTag != null) { defaultType = new TrainType(false); defaultType.configureFromXML(defaultsTag); } List<Tag> typeTags = tag.getChildren("Train"); for (Tag typeTag : typeTags) { if (defaultType != null) { newType = (TrainType) defaultType.clone(); if (newType == null) { throw new ConfigurationException("Cannot clone traintype " + defaultType.getName()); } } else { newType = new TrainType(true); } lTrainTypes.add(newType); newType.configureFromXML(typeTag); mTrainTypes.put(newType.getName(), newType); } // Special train buying rules Tag rulesTag = tag.getChild("TrainBuyingRules"); if (rulesTag != null) { // A 1851 special buyAtFaceValueBetweenDifferentPresidents = rulesTag.getChild("FaceValueIfDifferentPresidents") != null; } // Finish initialisation of the train types for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeName() != null) { type.setReleasedTrainType(mTrainTypes.get(type.getReleasedTrainTypeName())); } if (type.getRustedTrainTypeName() != null) { type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); mTrainTypes.get(type.getRustedTrainTypeName()).setPermanent(false); } } } public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { this.gameManager = gameManager; bank = gameManager.getBank(); ipo = bank.getIpo(); unavailable = bank.getUnavailable(); for (TrainTypeI type : lTrainTypes) { type.finishConfiguration(gameManager); } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(bank); } /** * Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the * IPO. * * @param holder The Portfolio for which this list will be made (always * IPO). */ public static String makeAbbreviatedList(Portfolio holder) { StringBuffer b = new StringBuffer(); TrainI[] trains; for (TrainTypeI type : GameManager.getInstance().getTrainManager().getTrainTypes()) { trains = holder.getTrainsPerType(type); if (trains.length > 0) { if (b.length() > 0) b.append(" "); b.append(type.getName()).append("("); if (type.hasInfiniteAmount()) { b.append("+"); } else { b.append(trains.length); } b.append(")"); } } return b.toString(); } /** * Make a full list of trains, like "2 2 3 3", to show in any field * describing train possessions, except the IPO. * * @param holder The Portfolio for which this list will be made. */ public static String makeFullList(Portfolio holder) { List<TrainI> trains = holder.getTrainList(); if (trains == null || trains.size() == 0) return ""; return makeFullList(trains); } public static String makeFullList(List<TrainI> trains) { StringBuffer b = new StringBuffer(); for (TrainI train : trains) { if (b.length() > 0) b.append(" "); if (train.isObsolete()) b.append("("); b.append(train.toDisplay()); if (train.isObsolete()) b.append(")"); } return b.toString(); } /** * This method handles any consequences of new train buying (from the IPO), * such as rusting and phase changes. It must be called <b>after</b> the * train has been transferred. * */ public void checkTrainAvailability(TrainI train, Portfolio from) { trainsHaveRusted = false; phaseHasChanged = false; if (from != ipo) return; TrainTypeI boughtType, nextType; boughtType = train.getType(); if (boughtType == (lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = (lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(bank); trainAvailabilityChanged = true; ReportBuffer.add("All " + boughtType.getName() + "-trains are sold out, " + nextType.getName() + "-trains now available"); } } if (boughtType.getNumberBoughtFromIPO() == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); String newPhase = boughtType.getStartedPhaseName(); if (newPhase != null) { gameManager.getPhaseManager().setPhase(newPhase); phaseHasChanged = true; } TrainTypeI rustedType = boughtType.getRustedTrainType(); if (rustedType != null && !rustedType.hasRusted()) { rustedType.setRusted(train.getHolder()); // Or obsolete, // where applicable ReportBuffer.add(LocalText.getText("TrainsRusted", rustedType.getName())); trainsHaveRusted = true; trainAvailabilityChanged = true; } TrainTypeI releasedType = boughtType.getReleasedTrainType(); if (releasedType != null) { if (!releasedType.isAvailable()) releasedType.setAvailable(bank); ReportBuffer.add(LocalText.getText("TrainsAvailable", releasedType.getName())); trainAvailabilityChanged = true; } } } public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); TrainI train; for (TrainTypeI type : lTrainTypes) { if (type.isAvailable()) { train = ipo.getTrainOfType(type); if (train != null) { availableTrains.add(train); } } } return availableTrains; } public TrainTypeI getTypeByName(String name) { return mTrainTypes.get(name); } public List<TrainTypeI> getTrainTypes() { return lTrainTypes; } public boolean hasAvailabilityChanged() { return trainAvailabilityChanged; } public void resetAvailabilityChanged() { trainAvailabilityChanged = false; } public boolean hasPhaseChanged() { return phaseHasChanged; } public boolean buyAtFaceValueBetweenDifferentPresidents() { return buyAtFaceValueBetweenDifferentPresidents; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import rails.game.state.IntegerState; import rails.util.LocalText; import rails.util.Tag; public class TrainManager implements ConfigurableComponentI { // Static attributes protected List<TrainTypeI> lTrainTypes = new ArrayList<TrainTypeI>(); protected Map<String, TrainTypeI> mTrainTypes = new HashMap<String, TrainTypeI>(); protected Map<String, TrainI> trainMap = new HashMap<String, TrainI>(); protected boolean buyAtFaceValueBetweenDifferentPresidents = false; // Dynamic attributes protected Portfolio unavailable = null; protected IntegerState newTypeIndex; protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; protected GameManagerI gameManager = null; protected Bank bank = null; // Non-game attributes protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { newTypeIndex = new IntegerState("NewTrainTypeIndex", 0); } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { TrainType defaultType = null; TrainType newType; Tag defaultsTag = tag.getChild("Defaults"); if (defaultsTag != null) { defaultType = new TrainType(false); defaultType.configureFromXML(defaultsTag); } List<Tag> typeTags = tag.getChildren("Train"); for (Tag typeTag : typeTags) { if (defaultType != null) { newType = (TrainType) defaultType.clone(); if (newType == null) { throw new ConfigurationException("Cannot clone traintype " + defaultType.getName()); } } else { newType = new TrainType(true); } lTrainTypes.add(newType); newType.configureFromXML(typeTag); mTrainTypes.put(newType.getName(), newType); } // Special train buying rules Tag rulesTag = tag.getChild("TrainBuyingRules"); if (rulesTag != null) { // A 1851 special buyAtFaceValueBetweenDifferentPresidents = rulesTag.getChild("FaceValueIfDifferentPresidents") != null; } // Finish initialisation of the train types for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeName() != null) { type.setReleasedTrainType(mTrainTypes.get(type.getReleasedTrainTypeName())); } if (type.getRustedTrainTypeName() != null) { type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); mTrainTypes.get(type.getRustedTrainTypeName()).setPermanent(false); } } } public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { this.gameManager = gameManager; bank = gameManager.getBank(); ipo = bank.getIpo(); unavailable = bank.getUnavailable(); for (TrainTypeI type : lTrainTypes) { type.finishConfiguration(gameManager); } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(bank); } public void addTrain (String uniqueID, TrainI train) { trainMap.put(uniqueID, train); } public TrainI getTrainByUniqueId(String id) { return trainMap.get(id); } /** * This method handles any consequences of new train buying (from the IPO), * such as rusting and phase changes. It must be called <b>after</b> the * train has been transferred. * */ public void checkTrainAvailability(TrainI train, Portfolio from) { trainsHaveRusted = false; phaseHasChanged = false; if (from != ipo) return; TrainTypeI boughtType, nextType; boughtType = train.getType(); if (boughtType == (lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = (lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(bank); trainAvailabilityChanged = true; ReportBuffer.add("All " + boughtType.getName() + "-trains are sold out, " + nextType.getName() + "-trains now available"); } } if (boughtType.getNumberBoughtFromIPO() == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); String newPhase = boughtType.getStartedPhaseName(); if (newPhase != null) { gameManager.getPhaseManager().setPhase(newPhase); phaseHasChanged = true; } TrainTypeI rustedType = boughtType.getRustedTrainType(); if (rustedType != null && !rustedType.hasRusted()) { rustedType.setRusted(train.getHolder()); // Or obsolete, // where applicable ReportBuffer.add(LocalText.getText("TrainsRusted", rustedType.getName())); trainsHaveRusted = true; trainAvailabilityChanged = true; } TrainTypeI releasedType = boughtType.getReleasedTrainType(); if (releasedType != null) { if (!releasedType.isAvailable()) releasedType.setAvailable(bank); ReportBuffer.add(LocalText.getText("TrainsAvailable", releasedType.getName())); trainAvailabilityChanged = true; } } } public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); TrainI train; for (TrainTypeI type : lTrainTypes) { if (type.isAvailable()) { train = ipo.getTrainOfType(type); if (train != null) { availableTrains.add(train); } } } return availableTrains; } public TrainTypeI getTypeByName(String name) { return mTrainTypes.get(name); } public List<TrainTypeI> getTrainTypes() { return lTrainTypes; } public boolean hasAvailabilityChanged() { return trainAvailabilityChanged; } public void resetAvailabilityChanged() { trainAvailabilityChanged = false; } public boolean hasPhaseChanged() { return phaseHasChanged; } public boolean buyAtFaceValueBetweenDifferentPresidents() { return buyAtFaceValueBetweenDifferentPresidents; } } \ No newline at end of file Index: PrivateCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PrivateCompany.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** PrivateCompany.java 31 Oct 2009 17:08:27 -0000 1.25 --- PrivateCompany.java 4 Nov 2009 20:33:22 -0000 1.26 *************** *** 104,110 **** } ! public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { ! for (SpecialPropertyI sp : specialProperties) { sp.finishConfiguration(gameManager); --- 104,110 ---- } ! public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { ! for (SpecialPropertyI sp : specialProperties) { sp.finishConfiguration(gameManager); *************** *** 180,184 **** super.setClosed(); unblockHexes(); ! moveTo(Bank.getInstance().getScrapHeap()); ReportBuffer.add(LocalText.getText("PrivateCloses", name)); --- 180,184 ---- super.setClosed(); unblockHexes(); ! moveTo(GameManager.getInstance().getBank().getScrapHeap()); ReportBuffer.add(LocalText.getText("PrivateCloses", name)); *************** *** 186,190 **** for (SpecialPropertyI sp : specialProperties) { if (sp instanceof SellBonusToken) { ! ((SellBonusToken)sp).setSeller(Bank.getInstance()); } } --- 186,190 ---- for (SpecialPropertyI sp : specialProperties) { if (sp instanceof SellBonusToken) { ! ((SellBonusToken)sp).setSeller(GameManager.getInstance().getBank()); } } Index: Bank.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Bank.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Bank.java 31 Oct 2009 17:08:27 -0000 1.15 --- Bank.java 4 Nov 2009 20:33:22 -0000 1.16 *************** *** 46,56 **** Logger.getLogger(Bank.class.getPackage().getName()); - /** - * @return an instance of the Bank object - */ - public static Bank getInstance() { - return instance; - } - public Bank() { --- 46,49 ---- *************** *** 59,66 **** money = new CashModel(this); // Create the IPO and the Bank Pool. ! ipo = new Portfolio("IPO", this); ! pool = new Portfolio("Pool", this); ! unavailable = new Portfolio("Unavailable", this); ! scrapHeap = new Portfolio("ScrapHeap", this); String configFormat = Config.get("money_format"); --- 52,59 ---- money = new CashModel(this); // Create the IPO and the Bank Pool. ! ipo = new Portfolio(Portfolio.IPO_NAME, this); ! pool = new Portfolio(Portfolio.POOL_NAME, this); ! unavailable = new Portfolio(Portfolio.UNAVAILABLE_NAME, this); ! scrapHeap = new Portfolio(Portfolio.SCRAPHEAP_NAME, this); String configFormat = Config.get("money_format"); *************** *** 100,104 **** public void finishConfiguration (GameManagerI gameManager) { ! ReportBuffer.add(LocalText.getText("BankSizeIs", format(money.getCash()))); --- 93,97 ---- public void finishConfiguration (GameManagerI gameManager) { ! ReportBuffer.add(LocalText.getText("BankSizeIs", format(money.getCash()))); *************** *** 124,128 **** } } ! /** * @param percentage of a company allowed to be in the Bank pool. --- 117,121 ---- } } ! /** * @param percentage of a company allowed to be in the Bank pool. Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** GameManager.java 31 Oct 2009 17:08:26 -0000 1.65 --- GameManager.java 4 Nov 2009 20:33:22 -0000 1.66 *************** *** 61,64 **** --- 61,68 ---- protected State priorityPlayer = new State("PriorityPlayer", Player.class); + /** Map relating portfolio names and objects, to enable deserialization */ + protected Map<String, Portfolio> portfolioMap = + new HashMap<String, Portfolio> (); + protected int playerShareLimit = 60; protected int treasuryShareLimit = 50; // For some games *************** *** 993,996 **** --- 997,1008 ---- } + public void addPortfolio (Portfolio portfolio) { + portfolioMap.put(portfolio.getName(), portfolio); + } + + public Portfolio getPortfolioByName (String name) { + return portfolioMap.get(name); + } + /* (non-Javadoc) * @see rails.game.GameManagerI#getStartPacket() Index: Company.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Company.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Company.java 3 Dec 2008 20:15:15 -0000 1.9 --- Company.java 4 Nov 2009 20:33:22 -0000 1.10 *************** *** 10,14 **** Cloneable { - protected static int numberOfCompanies = 0; protected String name; protected String longName; --- 10,13 ---- *************** *** 34,38 **** public Company() { - this.companyNumber = numberOfCompanies++; } --- 33,36 ---- *************** *** 45,55 **** /** - * @return Number of Companies - */ - public static int getNumberOfCompanies() { - return numberOfCompanies; - } - - /** * @return This company's number */ --- 43,46 ---- Index: Train.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Train.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Train.java 10 Oct 2009 15:25:49 -0000 1.14 --- Train.java 4 Nov 2009 20:33:22 -0000 1.15 *************** *** 2,8 **** package rails.game; - import java.util.HashMap; - import java.util.Map; - import org.apache.log4j.Logger; --- 2,5 ---- *************** *** 23,35 **** protected String uniqueId; - protected static Map<String, TrainI> trainMap = - new HashMap<String, TrainI>(); protected Portfolio holder; protected BooleanState obsolete; - protected static final Portfolio unavailable = Bank.getInstance().getUnavailable(); - protected static final Portfolio ipo = Bank.getInstance().getIpo(); - protected static Logger log = Logger.getLogger(Train.class.getPackage().getName()); --- 20,27 ---- *************** *** 48,60 **** uniqueId = type.getName() + "_" + index; ! trainMap.put(uniqueId, this); obsolete = new BooleanState(uniqueId, false); } - public static TrainI getByUniqueId(String id) { - return trainMap.get(id); - } - public String getUniqueId() { return uniqueId; --- 40,48 ---- uniqueId = type.getName() + "_" + index; ! type.getTrainManager().addTrain(uniqueId, this); obsolete = new BooleanState(uniqueId, false); } public String getUniqueId() { return uniqueId; *************** *** 136,144 **** new ObjectMove(this, holder, to); ! } public void setRusted() { ! new ObjectMove(this, holder, Bank.getInstance().getScrapHeap()); } --- 124,132 ---- new ObjectMove(this, holder, to); ! } public void setRusted() { ! new ObjectMove(this, holder, GameManager.getInstance().getBank().getScrapHeap()); } *************** *** 154,157 **** return getName(); } ! } --- 142,145 ---- return getName(); } ! } Index: BonusToken.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/BonusToken.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** BonusToken.java 25 Sep 2009 19:13:01 -0000 1.11 --- BonusToken.java 4 Nov 2009 20:33:22 -0000 1.12 *************** *** 63,67 **** public void close() { ! new ObjectMove(this, holder, Bank.getInstance().getScrapHeap()); user.removeBonus(name); } --- 63,67 ---- public void close() { ! new ObjectMove(this, holder, GameManager.getInstance().getBank().getScrapHeap()); user.removeBonus(name); } Index: TrainType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainType.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** TrainType.java 31 Oct 2009 17:08:26 -0000 1.25 --- TrainType.java 4 Nov 2009 20:33:22 -0000 1.26 *************** *** 12,16 **** import rails.util.Tag; ! public class TrainType implements TrainTypeI { --- 12,16 ---- import rails.util.Tag; ! public class TrainType implements TrainTypeI { *************** *** 25,29 **** protected int amount; protected boolean infiniteAmount = false; ! /** Index: used for sorting trains lists in configured order. */ protected int index; --- 25,29 ---- protected int amount; protected boolean infiniteAmount = false; ! /** Index: used for sorting trains lists in configured order. */ protected int index; *************** *** 45,49 **** protected boolean obsoleting = false; ! protected boolean permanent = true; --- 45,49 ---- protected boolean obsoleting = false; ! protected boolean permanent = true; *************** *** 66,70 **** protected ArrayList<TrainI> trains = null; ! protected int lastIndex = 0; --- 66,70 ---- protected ArrayList<TrainI> trains = null; ! protected int lastIndex = 0; *************** *** 72,75 **** --- 72,77 ---- protected BooleanState rusted; + protected TrainManager trainManager; + /** In some cases, trains start their life in the Pool */ protected String initialPortfolio = "IPO"; *************** *** 222,236 **** public void finishConfiguration (GameManagerI gameManager) { ! index = gameManager.getTrainManager().getTrainTypes().indexOf(this); ! Portfolio unavailable = gameManager.getBank().getUnavailable(); ! for (TrainI train : trains) { unavailable.addTrain(train); } } ! protected TrainI createTrain () throws ConfigurationException { ! TrainI train; try { --- 224,241 ---- public void finishConfiguration (GameManagerI gameManager) { ! ! trainManager = gameManager.getTrainManager(); ! index = trainManager.getTrainTypes().indexOf(this); ! Portfolio unavailable = gameManager.getBank().getUnavailable(); ! for (TrainI train : trains) { + train.init(this, lastIndex++); unavailable.addTrain(train); } } ! protected TrainI createTrain () throws ConfigurationException { ! TrainI train; try { *************** *** 244,256 **** + "constructor", e); } - train.init(this, lastIndex++); return train; } ! ! /** Create train without throwing exceptions. ! * To be used <b>after</b> completing initialization, ! * i.e. in cloning infinitely available trains. */ ! public TrainI cloneTrain () { TrainI train = null; --- 249,260 ---- + "constructor", e); } return train; } ! ! /** Create train without throwing exceptions. ! * To be used <b>after</b> completing initialization, ! * i.e. in cloning infinitely available trains. */ ! public TrainI cloneTrain () { TrainI train = null; *************** *** 462,469 **** return clone; } ! public int getIndex() { return index; } ! } --- 466,477 ---- return clone; } ! public int getIndex() { return index; } ! ! public TrainManager getTrainManager() { ! return trainManager; ! } ! } Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** GameManagerI.java 30 Oct 2009 21:53:03 -0000 1.20 --- GameManagerI.java 4 Nov 2009 20:33:22 -0000 1.21 *************** *** 134,138 **** public abstract void setNextPlayer(); ! /** * @return the StartPacket */ --- 134,141 ---- public abstract void setNextPlayer(); ! public void addPortfolio (Portfolio portfolio); ! public Portfolio getPortfolioByName (String name); ! ! /** * @return the StartPacket */ |