Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/game Modified Files: Portfolio.java StockRound.java StockMarket.java MapHex.java TrainType.java Game.java PublicCompany.java TrainManager.java GameManager.java StockMarketI.java OperatingRound.java GameManagerI.java Round.java City.java TrainTypeI.java Added Files: SwitchableUIRound.java Log Message: 1856 CGR formation round Index: TrainTypeI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainTypeI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TrainTypeI.java 3 Jan 2009 18:24:53 -0000 1.7 --- TrainTypeI.java 4 May 2009 20:29:14 -0000 1.8 *************** *** 94,98 **** public String getRustedTrainTypeName(); ! public void setReleasedTrainType(TrainTypeI releasedTrainType); --- 94,102 ---- public String getRustedTrainTypeName(); ! ! public boolean isPermanent(); ! ! public void setPermanent(boolean permanent); ! public void setReleasedTrainType(TrainTypeI releasedTrainType); Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Portfolio.java 24 Jan 2009 15:10:26 -0000 1.32 --- Portfolio.java 4 May 2009 20:29:14 -0000 1.33 *************** *** 164,168 **** public void addCertificate(PublicCertificateI certificate) { // When undoing a company start, put the President back at the top. ! boolean atTop = certificate.isPresidentShare() && this == Bank.getIpo(); if (atTop) --- 164,168 ---- public void addCertificate(PublicCertificateI certificate) { // When undoing a company start, put the President back at the top. ! boolean atTop = certificate.isPresidentShare()/* && this == Bank.getIpo()*/; if (atTop) Index: StockMarketI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockMarketI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** StockMarketI.java 4 Jun 2008 19:00:31 -0000 1.7 --- StockMarketI.java 4 May 2009 20:29:14 -0000 1.8 *************** *** 31,34 **** --- 31,36 ---- public void moveUp(PublicCompanyI company); + + public void close (PublicCompanyI company); public int getNumberOfColumns(); Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** PublicCompany.java 24 Jan 2009 15:10:28 -0000 1.48 --- PublicCompany.java 4 May 2009 20:29:14 -0000 1.49 *************** *** 875,878 **** --- 875,880 ---- Util.moveObjects(laidBaseTokens, this); + StockMarket.getInstance().close(this); + } Index: TrainManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManager.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** TrainManager.java 24 Jan 2009 15:10:29 -0000 1.15 --- TrainManager.java 4 May 2009 20:29:14 -0000 1.16 *************** *** 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())); } } // 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; // 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 Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** GameManager.java 4 Feb 2009 20:36:39 -0000 1.44 --- GameManager.java 4 May 2009 20:29:14 -0000 1.45 *************** *** 37,40 **** --- 37,41 ---- // Variable UI Class names + protected String gameUIManagerClassName = Defs.getDefaultClassName(Defs.ClassName.GAME_UI_MANAGER); protected String orUIManagerClassName = Defs.getDefaultClassName(Defs.ClassName.OR_UI_MANAGER); protected String gameStatusClassName = Defs.getDefaultClassName(Defs.ClassName.GAME_STATUS); *************** *** 246,249 **** --- 247,259 ---- } + // GameUIManager class + Tag gameUIMgrTag = tag.getChild("GameUIManager"); + if (gameUIMgrTag != null) { + gameUIManagerClassName = + gameUIMgrTag.getAttributeAsString("class", gameUIManagerClassName); + // Check instantiatability (not sure if this belongs here) + canClassBeInstantiated (gameUIManagerClassName); + } + // ORUIManager class Tag orMgrTag = tag.getChild("ORUIManager"); *************** *** 931,934 **** --- 941,947 ---- switch (key) { + case GAME_UI_MANAGER: + return gameUIManagerClassName; + case OR_UI_MANAGER: return orUIManagerClassName; *************** *** 980,982 **** --- 993,999 ---- } + public RoundI getInterruptedRound() { + return interruptedRound; + } + } Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Round.java 4 Feb 2009 20:36:39 -0000 1.16 --- Round.java 4 May 2009 20:29:14 -0000 1.17 *************** *** 10,16 **** --- 10,19 ---- import org.apache.log4j.Logger; + import rails.game.action.ExchangeTokens; + import rails.game.action.ExchangeableToken; import rails.game.action.PossibleAction; import rails.game.action.PossibleActions; import rails.game.move.CashMove; + import rails.game.move.MoveSet; import rails.game.special.SpecialPropertyI; import rails.util.LocalText; *************** *** 28,31 **** --- 31,36 ---- protected GameManagerI gameManager = null; protected CompanyManagerI companyManager = null; + + protected Class<? extends RoundI> roundTypeForUI = null; /** Default constructor cannot be used */ *************** *** 48,51 **** --- 53,57 ---- } + roundTypeForUI = getClass(); } *************** *** 90,93 **** --- 96,103 ---- } + public void setRoundTypeForUI(Class<? extends RoundI> roundTypeForUI) { + this.roundTypeForUI = roundTypeForUI; + } + /* * (non-Javadoc) *************** *** 114,117 **** --- 124,204 ---- } + protected boolean exchangeTokens (ExchangeTokens action) { + + String errMsg = null; + + List<ExchangeableToken> tokens = action.getTokensToExchange(); + int min = action.getMinNumberToExchange(); + int max = action.getMaxNumberToExchange(); + int exchanged = 0; + + checks: { + + for (ExchangeableToken token : tokens) { + if (token.isSelected()) exchanged++; + } + if (exchanged < min || exchanged > max) { + errMsg = LocalText.getText("WrongNumberOfTokensExchanged", + action.getCompany(), + min, max, exchanged); + break checks; + } + } + + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CannotExchangeTokens", + action.getCompany(), + action.toString(), + errMsg)); + + return false; + } + + MoveSet.start(true); + + if (exchanged > 0) { + MapHex hex; + City city; + String cityName, hexName; + int cityNumber; + String[] ct; + PublicCompanyI comp = action.getCompany(); + + for (ExchangeableToken token : tokens) { + cityName = token.getCityName(); + ct = cityName.split("/"); + hexName = ct[0]; + try { + cityNumber = Integer.parseInt(ct[1]); + } catch (NumberFormatException e) { + cityNumber = 1; + } + hex = MapManager.getInstance().getHex(hexName); + city = hex.getCity(cityNumber); + + if (token.isSelected()) { + + // For now we'll assume that the old token(s) have already been removed. + // This is true in the 1856 CGR formation. + if (hex.layBaseToken(comp, city.getNumber())) { + /* TODO: the false return value must be impossible. */ + ReportBuffer.add(LocalText.getText("ExchangesBaseToken", + comp.getName(), + token.getOldCompanyName(), + city.getName())); + comp.layBaseToken(hex, 0); + } + } else { + ReportBuffer.add(LocalText.getText("NoBaseTokenExchange", + comp.getName(), + city.getName())); + } + } + } + + return true; + } + + /** * Default version, does nothing. Subclasses should override this method Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Game.java 24 Jan 2009 15:10:28 -0000 1.21 --- Game.java 4 May 2009 20:29:14 -0000 1.22 *************** *** 164,170 **** @SuppressWarnings("unchecked") ! public static boolean load(String filepath) { ! boolean result = false; log.debug("Loading game from file " + filepath); --- 164,170 ---- @SuppressWarnings("unchecked") ! public static Game load(String filepath) { ! Game game = null; log.debug("Loading game from file " + filepath); *************** *** 186,190 **** List<String> playerNames = (List<String>) ois.readObject(); ! Game game = new Game(name, playerNames, selectedGameOptions); if (!game.setup()) { --- 186,190 ---- List<String> playerNames = (List<String>) ois.readObject(); ! game = new Game(name, playerNames, selectedGameOptions); if (!game.setup()) { *************** *** 203,207 **** instance.gameManager.processOnReload(executedActions); ! result = true; } catch (Exception e) { --- 203,207 ---- instance.gameManager.processOnReload(executedActions); ! return game; } catch (Exception e) { *************** *** 210,214 **** } ! return result; } --- 210,214 ---- } ! return null; } *************** *** 255,258 **** --- 255,262 ---- return instance.playerManager; } + + public GameManagerI getGameManager() { + return gameManager; + } /** Index: City.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/City.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** City.java 3 Jan 2009 18:24:53 -0000 1.7 --- City.java 4 May 2009 20:29:14 -0000 1.8 *************** *** 57,61 **** * @return Returns the holder. */ ! public Object getHolder() { return mapHex; } --- 57,61 ---- * @return Returns the holder. */ ! public MapHex getHolder() { return mapHex; } Index: StockMarket.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockMarket.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** StockMarket.java 15 Jan 2009 20:53:28 -0000 1.14 --- StockMarket.java 4 May 2009 20:29:14 -0000 1.15 *************** *** 216,219 **** --- 216,223 ---- prepareMove(company, oldsquare, newsquare); } + + public void close (PublicCompanyI company) { + prepareMove(company, company.getCurrentSpace(), null); + } protected void moveDown(PublicCompanyI company, int numberOfSpaces) { *************** *** 294,299 **** from.getName() )); return; ! } else if (from == null && to != null) {} else if (from != null ! && to != null) { ReportBuffer.add(LocalText.getText("PRICE_MOVES_LOG", company.getName(), --- 298,304 ---- from.getName() )); return; ! } else if (from == null && to != null) { ! ; ! } else if (from != null && to != null) { ReportBuffer.add(LocalText.getText("PRICE_MOVES_LOG", company.getName(), Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** MapHex.java 15 Jan 2009 20:53:28 -0000 1.22 --- MapHex.java 4 May 2009 20:29:14 -0000 1.23 *************** *** 751,754 **** --- 751,767 ---- } } + + public List<BaseToken> getBaseTokens () { + if (cities == null || cities.isEmpty()) return null; + List<BaseToken> tokens = new ArrayList<BaseToken>(); + for (City city : cities) { + for (TokenI token : city.getTokens()) { + if (token instanceof BaseToken) { + tokens.add((BaseToken)token); + } + } + } + return tokens; + } public List<TokenI> getTokens() { Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** OperatingRound.java 4 Feb 2009 20:43:37 -0000 1.56 --- OperatingRound.java 4 May 2009 20:29:14 -0000 1.57 *************** *** 241,244 **** --- 241,248 ---- result = repayLoans((RepayLoans) selectedAction); + + } else if (selectedAction instanceof ExchangeTokens) { + + result = exchangeTokens ((ExchangeTokens)selectedAction); } else if (selectedAction instanceof NullAction) { *************** *** 1175,1178 **** --- 1179,1183 ---- if (operatingCompanyIndex >= operatingCompanyArray.length) { + operatingCompany = null; return false; } else { *************** *** 1751,1768 **** operatingCompany.addLoans(-number); ! int amount = payment = number * operatingCompany.getValuePerLoan(); ! if (amount > operatingCompany.getCash()) { ! // By now the president must have enough cash ! payment = operatingCompany.getCash(); ! remainder = amount - payment; ! if (payment > 0) { ! new CashMove (operatingCompany, null, payment); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", ! operatingCompany.getName(), ! Bank.format(payment), ! Bank.format(amount), ! number, ! Bank.format(operatingCompany.getValuePerLoan()))); ! } } if (remainder > 0) { --- 1756,1770 ---- operatingCompany.addLoans(-number); ! int amount = number * operatingCompany.getValuePerLoan(); ! payment = Math.min(amount, operatingCompany.getCash()); ! remainder = amount - payment; ! if (payment > 0) { ! new CashMove (operatingCompany, null, payment); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", ! operatingCompany.getName(), ! Bank.format(payment), ! Bank.format(amount), ! number, ! Bank.format(operatingCompany.getValuePerLoan()))); } if (remainder > 0) { *************** *** 1785,1789 **** return numberOfLoans * operatingCompany.getValuePerLoan(); } ! /*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/ --- 1787,1791 ---- return numberOfLoans * operatingCompany.getValuePerLoan(); } ! /*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/ *************** *** 2130,2134 **** for (PublicCompanyI comp : list) { possibleActions.add(new DiscardTrain(comp, ! comp.getPortfolio().getUniqueTrains())); // We handle one company at at time. // We come back here until all excess trains have been --- 2132,2136 ---- for (PublicCompanyI comp : list) { possibleActions.add(new DiscardTrain(comp, ! comp.getPortfolio().getUniqueTrains(), true)); // We handle one company at at time. // We come back here until all excess trains have been Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** StockRound.java 15 Jan 2009 20:53:28 -0000 1.35 --- StockRound.java 4 May 2009 20:29:14 -0000 1.36 *************** *** 74,84 **** sequenceRule = gameManager.getStockRoundSequenceRule(); ! ! } public void start() { ! ReportBuffer.add("\n" + LocalText.getText("StartStockRound") ! + getStockRoundNumber()); setCurrentPlayerIndex(gameManager.getPriorityPlayer().getIndex()); --- 74,84 ---- sequenceRule = gameManager.getStockRoundSequenceRule(); ! ! } public void start() { ! ReportBuffer.add("\n" + LocalText.getText("StartStockRound", ! + getStockRoundNumber())); setCurrentPlayerIndex(gameManager.getPriorityPlayer().getIndex()); Index: TrainType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainType.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** TrainType.java 3 Jan 2009 18:24:53 -0000 1.20 --- TrainType.java 4 May 2009 20:29:14 -0000 1.21 *************** *** 41,44 **** --- 41,46 ---- protected boolean obsoleting = false; + + protected boolean permanent = true; private boolean real; // Only to determine if top-level attributes must be *************** *** 248,258 **** /** - * @return Returns the amount. - */ - /* - * public int getAmount() { return amount; } - */ - - /** * @return Returns the cityScoreFactor. */ --- 250,253 ---- *************** *** 385,388 **** --- 380,391 ---- } + public boolean isPermanent() { + return permanent; + } + + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + /** * @return Returns the available. --- NEW FILE: SwitchableUIRound.java --- package rails.game; /** Abstract class for rounds that cannot be subclassed for one of the * other Round subclasses because UI is switchable: in some steps, * an SR-type UI and in other steps an OR-type UI should be displayed. * @author Erik Vos * */ public abstract class SwitchableUIRound extends Round { public SwitchableUIRound (GameManagerI gameManager) { super (gameManager); setRoundTypeForUI(null); } } Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GameManagerI.java 24 Jan 2009 15:10:28 -0000 1.2 --- GameManagerI.java 4 May 2009 20:29:14 -0000 1.3 *************** *** 157,160 **** public abstract Object getCommonParameter(Defs.Parm key); ! } \ No newline at end of file --- 157,161 ---- public abstract Object getCommonParameter(Defs.Parm key); ! ! public RoundI getInterruptedRound(); } \ No newline at end of file |