From: Erik V. <ev...@us...> - 2009-09-08 21:49:16
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv28138/rails/game Modified Files: BonusToken.java OperatingRound.java PhaseManager.java GameManagerI.java MapHex.java Game.java PublicCompany.java TrainManagerI.java TrainManager.java Token.java GameManager.java Added Files: PhaseManagerI.java Log Message: Removed statics from some manager classes --- NEW FILE: PhaseManagerI.java --- /* $Header: /cvsroot/rails/18xx/rails/game/PhaseManagerI.java,v 1.7 2009/09/08 21:48:59 evos Exp $ */ package rails.game; public interface PhaseManagerI { public void init (GameManagerI gameManager); public int getCurrentPhaseIndex(); public PhaseI getCurrentPhase(); public void setPhase(String name); public PhaseI getPhaseNyName (String name); public boolean hasReachedPhase (String phaseName); } Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** PublicCompany.java 6 Sep 2009 12:27:32 -0000 1.57 --- PublicCompany.java 8 Sep 2009 21:48:59 -0000 1.58 *************** *** 1223,1228 **** CashHolder beneficiary = holder.getOwner(); // Special cases apply if the holder is the IPO or the Pool ! if (holder == Bank.getIpo() && ipoPaysOut || holder == Bank.getPool() ! && poolPaysOut) { beneficiary = this; } --- 1223,1228 ---- CashHolder beneficiary = holder.getOwner(); // Special cases apply if the holder is the IPO or the Pool ! if (holder == Bank.getIpo() && ipoPaysOut ! || holder == Bank.getPool() && poolPaysOut) { beneficiary = this; } Index: TrainManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManager.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** TrainManager.java 4 May 2009 20:29:14 -0000 1.16 --- TrainManager.java 8 Sep 2009 21:48:59 -0000 1.17 *************** *** 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 TrainManagerI, 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; // Non-game attributes private static TrainManagerI instance = null; protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { instance = this; ipo = Bank.getIpo(); unavailable = Bank.getUnavailable(); // Nothing to do here, everything happens when configured. 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); } } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(); } /** * 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 : instance.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 == ((TrainTypeI) lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = ((TrainTypeI) lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(); 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) { PhaseManager.getInstance().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(); 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 (TrainTypeI) 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 TrainManagerI, 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; // Non-game attributes private static TrainManagerI instance = null; protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { instance = this; ipo = Bank.getIpo(); unavailable = Bank.getUnavailable(); // Nothing to do here, everything happens when configured. 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); } } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(); } public void init (GameManagerI gameManager) { this.gameManager = gameManager; } /** * 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 : instance.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(); 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(); 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: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** GameManager.java 6 Sep 2009 12:27:36 -0000 1.49 --- GameManager.java 8 Sep 2009 21:48:59 -0000 1.50 *************** *** 939,943 **** // TODO Should be removed ! public static void initialiseNewPhase(PhaseI phase) { ReportBuffer.add(LocalText.getText("StartOfPhase", phase.getName())); --- 939,943 ---- // TODO Should be removed ! public void initialiseNewPhase(PhaseI phase) { ReportBuffer.add(LocalText.getText("StartOfPhase", phase.getName())); Index: Token.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Token.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Token.java 4 Jun 2008 19:00:31 -0000 1.5 --- Token.java 8 Sep 2009 21:48:59 -0000 1.6 *************** *** 1,4 **** /* $Header$ ! * * Created on Jan 1, 2007 * Change Log: --- 1,4 ---- /* $Header$ ! * * Created on Jan 1, 2007 * Change Log: *************** *** 17,23 **** public abstract class Token implements TokenI { ! TokenHolderI holder = null; ! String description = ""; ! String uniqueId; private static Map<String, TokenI> tokenMap = new HashMap<String, TokenI>(); --- 17,23 ---- public abstract class Token implements TokenI { ! protected TokenHolderI holder = null; ! protected String description = ""; ! protected String uniqueId; private static Map<String, TokenI> tokenMap = new HashMap<String, TokenI>(); *************** *** 59,63 **** * Transfer a token object from one TokenHolder (e.g. a Company) to another * (e.g. a Station in a MapHex). ! * * @param token * @param from --- 59,63 ---- * Transfer a token object from one TokenHolder (e.g. a Company) to another * (e.g. a Station in a MapHex). ! * * @param token * @param from Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** Game.java 6 Sep 2009 12:27:31 -0000 1.25 --- Game.java 8 Sep 2009 21:48:59 -0000 1.26 *************** *** 35,39 **** protected List<String> directories = new ArrayList<String>(); protected Map<String, String> gameOptions; ! protected List<String> players; --- 35,39 ---- protected List<String> directories = new ArrayList<String>(); protected Map<String, String> gameOptions; ! protected List<String> players; *************** *** 102,106 **** "No PlayerManager XML element found in file " + GAME_XML_FILE); } ! bank = (Bank) componentManager.findComponent("Bank"); if (bank == null) { --- 102,106 ---- "No PlayerManager XML element found in file " + GAME_XML_FILE); } ! bank = (Bank) componentManager.findComponent("Bank"); if (bank == null) { *************** *** 108,112 **** "No Bank XML element found in file " + GAME_XML_FILE); } ! companyManager = (CompanyManagerI) componentManager.findComponent(CompanyManagerI.COMPONENT_NAME); --- 108,112 ---- "No Bank XML element found in file " + GAME_XML_FILE); } ! companyManager = (CompanyManagerI) componentManager.findComponent(CompanyManagerI.COMPONENT_NAME); *************** *** 154,157 **** --- 154,158 ---- companyManager.initCompanies(gameManager); + trainManager.init(gameManager); bank.initCertificates(); StartPacket.init(); Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** OperatingRound.java 6 Sep 2009 12:27:36 -0000 1.66 --- OperatingRound.java 8 Sep 2009 21:48:59 -0000 1.67 *************** *** 667,671 **** MoveSet.start(true); ! if (hex.layBonusToken(token)) { /* TODO: the false return value must be impossible. */ --- 667,671 ---- MoveSet.start(true); ! if (hex.layBonusToken(token, gameManager.getPhaseManager())) { /* TODO: the false return value must be impossible. */ Index: PhaseManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PhaseManager.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PhaseManager.java 11 Jan 2009 17:24:46 -0000 1.13 --- PhaseManager.java 8 Sep 2009 21:48:59 -0000 1.14 *************** *** 9,14 **** public class PhaseManager implements ConfigurableComponentI { - protected static PhaseManager instance = null; - protected ArrayList<Phase> phaseList; protected HashMap<String, Phase> phaseMap; --- 9,12 ---- *************** *** 17,28 **** protected State currentPhase = new State("CurrentPhase", Phase.class); ! public PhaseManager() { ! ! instance = this; ! } ! public static PhaseManager getInstance() { ! return instance; ! } public void configureFromXML(Tag tag) throws ConfigurationException { --- 15,22 ---- protected State currentPhase = new State("CurrentPhase", Phase.class); ! // Can be removed once setPhase() has been redone. ! protected GameManagerI gameManager; ! public PhaseManager() {} public void configureFromXML(Tag tag) throws ConfigurationException { *************** *** 41,45 **** int n = 0; for (Tag phaseTag : phaseTags) { ! name = phaseTag.getAttributeAsString("name", "" + (n + 1)); phase = new Phase(n++, name, previousPhase); phaseList.add(phase); --- 35,39 ---- int n = 0; for (Tag phaseTag : phaseTags) { ! name = phaseTag.getAttributeAsString("name", String.valueOf(n + 1)); phase = new Phase(n++, name, previousPhase); phaseList.add(phase); *************** *** 53,56 **** --- 47,54 ---- } + public void init (GameManagerI gameManager) { + this.gameManager = gameManager; + } + public PhaseI getCurrentPhase() { return (PhaseI) currentPhase.getObject(); *************** *** 72,76 **** // as soon as privates closing is included there. // Please consider Undo/Redo as well ! GameManager.initialiseNewPhase(phase); } } --- 70,74 ---- // as soon as privates closing is included there. // Please consider Undo/Redo as well ! gameManager.initialiseNewPhase(phase); } } Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** MapHex.java 4 May 2009 20:29:14 -0000 1.23 --- MapHex.java 8 Sep 2009 21:48:59 -0000 1.24 *************** *** 730,734 **** } ! public boolean layBonusToken(BonusToken token) { if (token == null) { log.error("No token specified"); --- 730,741 ---- } ! /** ! * Lay a bonus token. ! * @param token The bonus token object to place ! * @param phaseManager The PhaseManager is also passed in case the ! * token must register itself for removal when a certain phase starts. ! * @return ! */ ! public boolean layBonusToken(BonusToken token, PhaseManager phaseManager) { if (token == null) { log.error("No token specified"); *************** *** 736,739 **** --- 743,747 ---- } else { token.moveTo(this); + token.prepareForRemoval (phaseManager); return true; } *************** *** 751,755 **** } } ! public List<BaseToken> getBaseTokens () { if (cities == null || cities.isEmpty()) return null; --- 759,763 ---- } } ! public List<BaseToken> getBaseTokens () { if (cities == null || cities.isEmpty()) return null; *************** *** 930,938 **** } ! public int getCurrentOffBoardValue() { ! if (hasOffBoardValues()) { return offBoardValues[Math.min( offBoardValues.length, ! PhaseManager.getInstance().getCurrentPhase().getOffBoardRevenueStep()) - 1]; } else { return 0; --- 938,946 ---- } ! public int getCurrentOffBoardValue(PhaseI phase) { ! if (hasOffBoardValues() && phase != null) { return offBoardValues[Math.min( offBoardValues.length, ! phase.getOffBoardRevenueStep()) - 1]; } else { return 0; Index: BonusToken.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/BonusToken.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** BonusToken.java 11 Jan 2009 17:24:46 -0000 1.8 --- BonusToken.java 8 Sep 2009 21:48:58 -0000 1.9 *************** *** 17,21 **** * a base from which a company can operate. Other names used in various games * and discussions are "railhead", "station", "garrison", or just "token". ! * * @author Erik Vos */ --- 17,21 ---- * a base from which a company can operate. Other names used in various games * and discussions are "railhead", "station", "garrison", or just "token". ! * * @author Erik Vos */ *************** *** 56,83 **** } public void close() { ! // new TokenMove (this, holder, Bank.getScrapHeap()); new ObjectMove(this, holder, Bank.getScrapHeap()); user.removeBonusToken(this); } ! @Override ! public void setHolder(TokenHolderI newHolder) { ! super.setHolder(newHolder); ! // Prepare for removal, is requested ! if (removingObjectDesc != null && removingObject == null) { ! String[] spec = removingObjectDesc.split(":"); ! if (spec[0].equalsIgnoreCase("Phase")) { ! removingObject = ! PhaseManager.getInstance().getPhaseByName(spec[1]); ! } } ! // If the token is placed, prepare its removal when required ! if (newHolder instanceof MapHex && removingObject != null) { ! if (removingObject instanceof Phase) { ! ((Phase) removingObject).addObjectToClose(this); ! } } } --- 56,89 ---- } + /** + * Remove the token. + * This method can be called by a certain phase when it starts. + * See prepareForRemovel(). + */ public void close() { ! new ObjectMove(this, holder, Bank.getScrapHeap()); user.removeBonusToken(this); } ! /** ! * Prepare the bonus token for removal, if so configured. ! * The only case currently implemented to trigger removal ! * is the start of a given phase. ! */ ! public void prepareForRemoval (PhaseManager phaseManager) { ! if (removingObjectDesc == null) return; ! ! if (removingObject == null) { ! String[] spec = removingObjectDesc.split(":"); ! if (spec[0].equalsIgnoreCase("Phase")) { ! removingObject = ! phaseManager.getPhaseByName(spec[1]); ! } } ! if (removingObject instanceof Phase) { ! ((Phase) removingObject).addObjectToClose(this); } } Index: TrainManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManagerI.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TrainManagerI.java 4 Jun 2008 19:00:30 -0000 1.6 --- TrainManagerI.java 8 Sep 2009 21:48:59 -0000 1.7 *************** *** 16,19 **** --- 16,21 ---- static final String COMPONENT_NAME = "TrainManager"; + public void init (GameManagerI gameManager); + public List<TrainI> getAvailableNewTrains(); Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GameManagerI.java 6 Sep 2009 12:27:36 -0000 1.7 --- GameManagerI.java 8 Sep 2009 21:48:59 -0000 1.8 *************** *** 143,151 **** public abstract PhaseManager getPhaseManager(); public abstract TrainManagerI getTrainManager (); public PlayerManager getPlayerManager(); public StockMarketI getStockMarket(); ! public int getPlayerCertificateLimit(); public void setPlayerCertificateLimit(int newLimit); --- 143,152 ---- public abstract PhaseManager getPhaseManager(); + public void initialiseNewPhase(PhaseI phase); public abstract TrainManagerI getTrainManager (); public PlayerManager getPlayerManager(); public StockMarketI getStockMarket(); ! public int getPlayerCertificateLimit(); public void setPlayerCertificateLimit(int newLimit); *************** *** 153,157 **** public int getPlayerShareLimit(); ! public abstract String getHelp(); --- 154,158 ---- public int getPlayerShareLimit(); ! public abstract String getHelp(); |