You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(46) |
Dec
(57) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(51) |
Feb
(10) |
Mar
|
Apr
|
May
(14) |
Jun
|
Jul
(13) |
Aug
(30) |
Sep
(83) |
Oct
(56) |
Nov
(148) |
Dec
(107) |
2010 |
Jan
(260) |
Feb
(164) |
Mar
(183) |
Apr
(99) |
May
(160) |
Jun
(40) |
Jul
(33) |
Aug
(48) |
Sep
(22) |
Oct
(24) |
Nov
(1) |
Dec
(12) |
2011 |
Jan
(6) |
Feb
(15) |
Mar
(13) |
Apr
(37) |
May
(27) |
Jun
(29) |
Jul
(33) |
Aug
(20) |
Sep
(17) |
Oct
(20) |
Nov
(33) |
Dec
(17) |
2012 |
Jan
(39) |
Feb
(38) |
Mar
(20) |
Apr
(21) |
May
(17) |
Jun
(22) |
Jul
(16) |
Aug
(3) |
Sep
(9) |
Oct
(10) |
Nov
|
Dec
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:31
|
Update of /cvsroot/rails/18xx In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969 Modified Files: LocalisedText.properties Log Message: 1856 CGR formation round Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** LocalisedText.properties 4 Feb 2009 20:36:40 -0000 1.68 --- LocalisedText.properties 4 May 2009 20:29:15 -0000 1.69 *************** *** 38,41 **** --- 38,43 ---- BuysTrainUsingSP={0} buys a {1}-train from {2} for {3} using {4}. CASH=Cash + CanOperate={0} can operate this round + CannotOperate={0} cannot operate this round CannotBuyAnything={0} cannot buy anything CERT_NAME={0} {1}% share *************** *** 57,60 **** --- 59,63 ---- CannotDumpPresidency=Cannot dump presidency CannotDumpTrainBuyingPresidency=Cannot dump presidency of train buying company + CannotExchangeTokens={0} cannot {1}: {2} CannotLayBaseTokenOn={0} cannot lay a base token on {1} for {2}: {3} CannotLayTileOn={0} cannot lay tile {1} on {2} for {3}: {4} *************** *** 108,112 **** DestinationReached={0} has reached its destination hex {1} DestinationsReached=Destinations reached ! DestinationsReachedPrompt=Select companies that have reached their destinations DiscardTrain=Discard {0}-train DoesNotExist=Item does not exist --- 111,116 ---- DestinationReached={0} has reached its destination hex {1} DestinationsReached=Destinations reached ! DestinationsReachedPrompt=Select companies that have reached their destinations ! DiscardsBaseToken={0} discards a {1} base token on {2} DiscardTrain=Discard {0}-train DoesNotExist=Item does not exist *************** *** 126,129 **** --- 130,138 ---- EndOfOperatingRound=End of Operating Round {0} EnterRevenue=Enter the earnings of the operating company + ExchangesBaseToken={0} exchanges a {1} base token on {2} + ExchangeableToken=Hex {1} {2}, city {3} (with tracks to {4}) [was {0} token] + ExchangeTokens=Exchange tokens + ExchangeTokensPrompt1=Select {0} cities where {1} will exchange a base token + ExchangeTokensPrompt2=Select {0} through {1} cities where {2} will exchange a base token ExchangesTrain={0} exchanges a {1}-train for a {2}-train from {3} for {4} ExtraTile= You can lay an unconnected tile on {0}. *************** *** 153,156 **** --- 162,167 ---- GetNoShareForMinor={0} does not get a share for Minor {1}, which closes HasFirstTurn={0} has the first turn + HasMergedShares={0} has exchanged {1} old shares for {2} {3} shares + HasPutShareInPool={0} has put one remaining share in the pool HAS_TOO_MANY_TRAINS={0}: company {1} has too many trains. Which train do you discard? HasTooManyTrains={0} has too many trains ({1}, limit is {2}). Select one train to discard. *************** *** 200,203 **** --- 211,215 ---- MapWindowORTitle=Rails: Map, Operating Round {0} or {1} MARKET=Stock Market + MayDiscardTrain={0} may voluntarily discard a train MayNotBuyAndSell={0} may not both buy and sell shares MayNotYetOperate={0} may not yet operate: {1}% sold whereas {2}% required *************** *** 216,219 **** --- 228,232 ---- NEW=New NewGame=New Game + NoBaseTokenExchange={0} does not exchange a token on {1} NoDumping=Cannot dump presidency NoGameOptions=This game has no options *************** *** 342,346 **** StartOfPhase=Start of phase {0}. StartPacketHasNoClass=Start packet {0} has no class defined. ! StartStockRound=Start of Stock Round Status_Unavailable=Currently unavailable Status_Biddable=Click to bid on this item --- 355,359 ---- StartOfPhase=Start of phase {0}. StartPacketHasNoClass=Start packet {0} has no class defined. ! StartStockRound=Start of Stock Round {0} Status_Unavailable=Currently unavailable Status_Biddable=Click to bid on this item *************** *** 422,425 **** --- 435,439 ---- WrongActionNoTrainBuyingCost=Wrong action, expected train buying cost WrongCompany=Wrong company: {0} (expected {1}) + WrongNumberOfTokensExchanged: {0} must exchange {1} through {2} tokens but did {3} WrongPhase=Wrong phase {0} WrongPlayer=Wrong player {0} - {1} has the turn |
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 |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:27
|
Update of /cvsroot/rails/18xx/rails/test In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/test Modified Files: GameTest.java Log Message: 1856 CGR formation round Index: GameTest.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/test/GameTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GameTest.java 4 Jun 2008 19:00:41 -0000 1.3 --- GameTest.java 4 May 2009 20:29:14 -0000 1.4 *************** *** 32,36 **** /* Start the rails.game selector, which will do all the rest. */ ! new GameUIManager(); } } --- 32,37 ---- /* Start the rails.game selector, which will do all the rest. */ ! //new GameUIManager(); ! new GameSetupWindow(); } } |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:26
|
Update of /cvsroot/rails/18xx/rails/ui/swing/elements In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing/elements Modified Files: CheckBoxDialog.java Log Message: 1856 CGR formation round Index: CheckBoxDialog.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/elements/CheckBoxDialog.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CheckBoxDialog.java 20 Nov 2008 21:46:00 -0000 1.1 --- CheckBoxDialog.java 4 May 2009 20:29:14 -0000 1.2 *************** *** 51,55 **** initialize(); pack(); ! // Center on owner int x = --- 51,55 ---- initialize(); pack(); ! this.setVisible(true); // Center on owner int x = *************** *** 61,65 **** setLocation(x, y); ! this.setVisible(true); } --- 61,65 ---- setLocation(x, y); ! } |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:26
|
Update of /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing/gamespecific/_1856 Modified Files: StatusWindow_1856.java Log Message: 1856 CGR formation round Index: StatusWindow_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StatusWindow_1856.java 4 Feb 2009 20:36:40 -0000 1.1 --- StatusWindow_1856.java 4 May 2009 20:29:15 -0000 1.2 *************** *** 7,10 **** --- 7,12 ---- import rails.game.*; + import rails.game.action.DiscardTrain; + import rails.game.action.ExchangeTokens; import rails.game.action.RepayLoans; import rails.game.specific._1856.CGRFormationRound; *************** *** 21,35 **** public void updateStatus() { RoundI currentRound = gameUIManager.getCurrentRound(); ! if (!(currentRound instanceof OperatingRound)) { ! return; ! } else if (!(currentRound instanceof CGRFormationRound)) { super.updateStatus(); } else if (possibleActions.contains(RepayLoans.class)) { ! RepayLoans action = possibleActions.getType(RepayLoans.class).get(0); ! repayLoans (action); } } ! // Code copied from ORUIManager protected void repayLoans (RepayLoans action) { --- 23,72 ---- public void updateStatus() { RoundI currentRound = gameUIManager.getCurrentRound(); ! //if (!(currentRound instanceof OperatingRound)) { ! if (!(currentRound instanceof CGRFormationRound)) { super.updateStatus(); } else if (possibleActions.contains(RepayLoans.class)) { ! //RepayLoans action = possibleActions.getType(RepayLoans.class).get(0); ! //repayLoans (action); ! immediateAction = possibleActions.getType(RepayLoans.class).get(0); ! } else if (possibleActions.contains(DiscardTrain.class)) { ! immediateAction = possibleActions.getType(DiscardTrain.class).get(0); ! } else if (possibleActions.contains(ExchangeTokens.class)) { ! immediateAction = possibleActions.getType(ExchangeTokens.class).get(0); } } ! @Override ! public boolean processImmediateAction() { ! ! if (immediateAction == null) { ! return false; ! } else if (immediateAction instanceof RepayLoans) { ! // Make a local copy and discard the original, ! // so that it's not going to loop. ! RepayLoans nextAction = (RepayLoans) immediateAction; ! immediateAction = null; ! repayLoans (nextAction); ! return true; ! } else if (immediateAction instanceof DiscardTrain) { ! // Make a local copy and discard the original, ! // so that it's not going to loop. ! DiscardTrain nextAction = (DiscardTrain) immediateAction; ! immediateAction = null; ! gameUIManager.discardTrains (nextAction); ! return true; ! } else if (immediateAction instanceof ExchangeTokens) { ! // Make a local copy and discard the original, ! // so that it's not going to loop. ! ExchangeTokens nextAction = (ExchangeTokens) immediateAction; ! immediateAction = null; ! gameUIManager.exchangeTokens (nextAction); ! return true; ! } else { ! return super.processImmediateAction(); ! } ! } ! ! // Code partly copied from ORUIManager protected void repayLoans (RepayLoans action) { *************** *** 55,59 **** message[displayBufSize] = LocalText.getText("SelectLoansToRepay", action.getCompanyName()); ! Object choice = JOptionPane.showInputDialog(this, message, --- 92,96 ---- message[displayBufSize] = LocalText.getText("SelectLoansToRepay", action.getCompanyName()); ! Object choice = JOptionPane.showInputDialog(this, message, |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:23
|
Update of /cvsroot/rails/18xx/rails/common In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/common Modified Files: Defs.java Log Message: 1856 CGR formation round Index: Defs.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/common/Defs.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Defs.java 4 Feb 2009 20:36:40 -0000 1.3 --- Defs.java 4 May 2009 20:29:15 -0000 1.4 *************** *** 7,10 **** --- 7,11 ---- /* Identifiers and default names for configurable UI classes */ public enum ClassName { + GAME_UI_MANAGER, OR_UI_MANAGER, STATUS_WINDOW, *************** *** 17,20 **** --- 18,23 ---- static { + defaultClasses.put (ClassName.GAME_UI_MANAGER, + "rails.ui.swing.GameUIManager"); defaultClasses.put (ClassName.OR_UI_MANAGER, "rails.ui.swing.ORUIManager"); |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:22
|
Update of /cvsroot/rails/18xx/data/1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/data/1856 Modified Files: CompanyManager.xml Game.xml Log Message: 1856 CGR formation round Index: CompanyManager.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1856/CompanyManager.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** CompanyManager.xml 11 Jan 2009 17:24:46 -0000 1.24 --- CompanyManager.xml 4 May 2009 20:29:15 -0000 1.25 *************** *** 100,103 **** --- 100,104 ---- <!-- Initially 20 shares are configured--> <ShareUnit percentage="5"/> + <Trains number="0,0,0,3"/> <Certificate type="President" shares="2"/> <Certificate shares="1" number="18"/> Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1856/Game.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Game.xml 4 Feb 2009 20:36:39 -0000 1.21 --- Game.xml 4 May 2009 20:29:15 -0000 1.22 *************** *** 6,9 **** --- 6,10 ---- sequence="SellBuyOrBuySell"/> <OperatingRound class="rails.game.specific._1856.OperatingRound_1856"/> + <GameUIManager class="rails.game.specific._1856.GameUIManager_1856"/> <StatusWindow class="rails.ui.swing.gamespecific._1856.StatusWindow_1856"/> <PlayerShareLimit percentage="60"/> |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:22
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing/hexmap Modified Files: EWHexMap.java HexMap.java NSHexMap.java Log Message: 1856 CGR formation round Index: NSHexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/NSHexMap.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NSHexMap.java 4 Jun 2008 19:00:38 -0000 1.6 --- NSHexMap.java 4 May 2009 20:29:15 -0000 1.7 *************** *** 43,46 **** --- 43,47 ---- hex.setHexModel(mh); hex.originalTileId = hex.currentTileId; + hexesByName.put(mh.getName(), hex); h[i][j] = hex; Index: EWHexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/EWHexMap.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EWHexMap.java 4 Jun 2008 19:00:38 -0000 1.7 --- EWHexMap.java 4 May 2009 20:29:15 -0000 1.8 *************** *** 40,43 **** --- 40,44 ---- hex.setHexModel(mh); hex.originalTileId = hex.currentTileId; + hexesByName.put(mh.getName(), hex); h[i][j] = hex; Index: HexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/HexMap.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** HexMap.java 4 Jun 2008 19:00:38 -0000 1.14 --- HexMap.java 4 May 2009 20:29:15 -0000 1.15 *************** *** 37,41 **** protected GUIHex[][] h; ! MapHex[][] hexArray; protected static ArrayList<GUIHex> hexes; protected int scale = 2 * Scale.get(); --- 37,42 ---- protected GUIHex[][] h; ! protected MapHex[][] hexArray; ! protected Map<String, GUIHex> hexesByName = new HashMap<String, GUIHex>(); protected static ArrayList<GUIHex> hexes; protected int scale = 2 * Scale.get(); *************** *** 94,97 **** --- 95,102 ---- return null; } + + public GUIHex getHexByName (String hexName) { + return hexesByName.get (hexName); + } public void paintComponent(Graphics g) { |
From: Erik V. <ev...@us...> - 2009-05-04 20:29:22
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing Modified Files: ORUIManager.java GameSetupWindow.java GameUIManager.java Log Message: 1856 CGR formation round Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ORUIManager.java 21 Jan 2009 20:18:23 -0000 1.26 --- ORUIManager.java 4 May 2009 20:29:15 -0000 1.27 *************** *** 897,929 **** if (dt == null) break; ! PublicCompanyI c = dt.getCompany(); ! String playerName = dt.getPlayerName(); ! List<TrainI> trains = dt.getOwnedTrains(); ! List<String> trainOptions = ! new ArrayList<String>(trains.size()); ! String[] options = new String[trains.size()]; ! ! for (int i = 0; i < options.length; i++) { ! options[i] = ! LocalText.getText("N_Train", ! trains.get(i).getName()); ! trainOptions.add(options[i]); ! } ! String discardedTrainName = ! (String) JOptionPane.showInputDialog(orWindow, ! LocalText.getText("HAS_TOO_MANY_TRAINS", ! playerName, ! c.getName() ), ! LocalText.getText("WhichTrainToDiscard"), ! JOptionPane.QUESTION_MESSAGE, null, ! options, options[0]); ! if (discardedTrainName != null) { ! TrainI discardedTrain = ! trains.get(trainOptions.indexOf(discardedTrainName)); ! ! dt.setDiscardedTrain(discardedTrain); ! ! orWindow.process(dt); ! } } } --- 897,901 ---- if (dt == null) break; ! gameUIManager.discardTrains(dt); } } Index: GameSetupWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameSetupWindow.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GameSetupWindow.java 4 Jun 2008 19:00:32 -0000 1.12 --- GameSetupWindow.java 4 May 2009 20:29:15 -0000 1.13 *************** *** 8,15 **** --- 8,17 ---- import org.apache.log4j.Logger; + import rails.common.Defs; import rails.game.*; import rails.ui.swing.GameUIManager; import rails.util.*; + import java.io.File; import java.util.*; import java.util.List; *************** *** 37,40 **** --- 39,43 ---- List<GameOption> availableOptions = new ArrayList<GameOption>(); String gameName; + Game game; // Used by the player selection combo box. *************** *** 46,53 **** Logger.getLogger(GameSetupWindow.class.getPackage().getName()); ! public GameSetupWindow(GameUIManager gameUIManager) { super(); ! this.gameUIManager = gameUIManager; initialize(); --- 49,56 ---- Logger.getLogger(GameSetupWindow.class.getPackage().getName()); ! public GameSetupWindow(/*GameUIManager gameUIManager*/) { super(); ! //this.gameUIManager = gameUIManager; initialize(); *************** *** 193,198 **** toggleOptions(); this.pack(); ! } else if (arg0.getSource().equals(loadButton) ! && gameUIManager.loadGame()) { setVisible(false); } else if (arg0.getSource().equals(infoButton)) { --- 196,223 ---- toggleOptions(); this.pack(); ! } else if (arg0.getSource().equals(loadButton)) { ! String saveDirectory = Config.get("save.directory"); ! JFileChooser jfc = new JFileChooser(); ! //if (providedName != null) { ! // jfc.setSelectedFile(new File(providedName)); ! //} else { ! jfc.setCurrentDirectory(new File(saveDirectory)); ! //} ! ! if (jfc.showOpenDialog(getContentPane()) == JFileChooser.APPROVE_OPTION) { ! File selectedFile = jfc.getSelectedFile(); ! String filepath = selectedFile.getPath(); ! saveDirectory = selectedFile.getParent(); ! if ((game = Game.load(filepath)) == null) { ! JOptionPane.showMessageDialog(this, ! DisplayBuffer.get(), "", JOptionPane.ERROR_MESSAGE); ! return; ! } ! DisplayBuffer.clear(); ! ! } ! ! startGameUIManager(game); ! gameUIManager.startLoadedGame(); setVisible(false); } else if (arg0.getSource().equals(infoButton)) { *************** *** 344,348 **** } ! Game game = new Game(gameName, playerNames, selectedOptions); if (!game.setup()) { JOptionPane.showMessageDialog(this, DisplayBuffer.get(), "", --- 369,373 ---- } ! game = new Game(gameName, playerNames, selectedOptions); if (!game.setup()) { JOptionPane.showMessageDialog(this, DisplayBuffer.get(), "", *************** *** 355,358 **** --- 380,384 ---- } else { game.start(); + startGameUIManager (game); gameUIManager.gameUIInit(); } *************** *** 361,364 **** --- 387,403 ---- // XXX: object rather than just making it invisible } + + private void startGameUIManager(Game game) { + String gameUIManagerClassName = game.getGameManager().getClassName(Defs.ClassName.GAME_UI_MANAGER); + try { + Class<? extends GameUIManager> gameUIManagerClass = + Class.forName(gameUIManagerClassName).asSubclass(GameUIManager.class); + gameUIManager = gameUIManagerClass.newInstance(); + gameUIManager.init(this); + } catch (Exception e) { + log.fatal("Cannot instantiate class " + gameUIManagerClassName, e); + System.exit(1); + } + } private void fillPlayersPane() { Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GameUIManager.java 4 Feb 2009 20:36:40 -0000 1.16 --- GameUIManager.java 4 May 2009 20:29:15 -0000 1.17 *************** *** 3,8 **** import java.io.File; import java.text.SimpleDateFormat; ! import java.util.Date; ! import java.util.List; import javax.swing.JFileChooser; --- 3,7 ---- import java.io.File; import java.text.SimpleDateFormat; ! import java.util.*; import javax.swing.JFileChooser; *************** *** 13,20 **** import rails.common.Defs; import rails.game.*; ! import rails.game.action.GameAction; ! import rails.game.action.PossibleAction; ! import rails.util.Config; ! import rails.util.Util; /** --- 12,18 ---- import rails.common.Defs; import rails.game.*; ! import rails.game.action.*; ! import rails.ui.swing.elements.CheckBoxDialog; ! import rails.util.*; /** *************** *** 55,59 **** --- 53,63 ---- public GameUIManager() { + + } + + public void init (GameSetupWindow gameSetupWindow) { + instance = this; + this.gameSetupWindow = gameSetupWindow; saveDirectory = Config.get("save.directory"); *************** *** 71,75 **** } ! gameSetupWindow = new GameSetupWindow(this); } --- 75,79 ---- } ! //gameSetupWindow = new GameSetupWindow(this); } *************** *** 97,100 **** --- 101,110 ---- } + + public void startLoadedGame() { + gameUIInit(); + processOnServer(null); + statusWindow.setGameActions(); + } public boolean processOnServer(PossibleAction action) { *************** *** 102,106 **** // In some cases an Undo requires a different follow-up lastAction = action; ! log.debug("==Passing to server: " + action); --- 112,117 ---- // In some cases an Undo requires a different follow-up lastAction = action; ! if (action != null) action.setActed(); ! log.debug("==Passing to server: " + action); *************** *** 109,113 **** --- 120,128 ---- action.setPlayerName(player.getName()); } + + // Process the action on the server boolean result = gameManager.process(action); + + // Follow-up the result log.debug("==Result from server: " + result); if (DisplayBuffer.getAutoDisplay()) activeWindow.displayServerMessage(); *************** *** 149,152 **** --- 164,171 ---- // Process consequences of a round type change to the UI + Class<? extends RoundI> previousRoundType + = previousRound == null ? null : previousRound.getClass(); + Class<? extends RoundI> currentRoundType + = currentRound.getClass(); Class<? extends RoundI> previousRoundUItype = previousRound == null ? null : previousRound.getRoundTypeForUI(); *************** *** 154,184 **** = currentRound.getRoundTypeForUI(); if (previousRound == null || !previousRound.equals(currentRound)) { if (previousRound != null) { ! // Finish the previous round UI aspects ! //if (previousRound instanceof StockRound) { ! if (StockRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Stock Round UI"); statusWindow.finishRound(); ! //} else if (previousRound instanceof StartRound) { ! } else if (StartRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Start Round UI"); if (startRoundWindow != null) { startRoundWindow.close(); startRoundWindow = null; } ! //} else if (previousRound instanceof OperatingRound) { ! } else if (OperatingRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Operating Round UI"); orUIManager.finish(); } } ! // Start the new round UI aspects ! //if (currentRound instanceof StartRound) { ! if (StartRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Start Round UI"); startRound = (StartRound) currentRound; if (startRoundWindow == null) { --- 173,210 ---- = currentRound.getRoundTypeForUI(); + /* Distinguish actual round type from visible round type. + * Actual round type is the class of the active Round subclass. + * Visible round type is the class of one of the three 'basic' + * round types: Start, Stock or Operating. + * The latter type determines what UI windows will become visible. + */ + + /* Process actual round type changes */ if (previousRound == null || !previousRound.equals(currentRound)) { + /* Finish previous round UI processing */ if (previousRound != null) { ! ! if (StockRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Stock Round"); statusWindow.finishRound(); ! } else if (StartRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Start Round"); if (startRoundWindow != null) { startRoundWindow.close(); startRoundWindow = null; } ! } else if (OperatingRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Operating Round"); orUIManager.finish(); + } else if (SwitchableUIRound.class.isAssignableFrom(previousRoundType) ) { + log.debug("UI leaving switchable round type"); } } ! // Start the new round UI processing ! if (StartRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Start Round"); startRound = (StartRound) currentRound; if (startRoundWindow == null) { *************** *** 186,204 **** } stockChart.setVisible(false); - //} else if (currentRound instanceof StockRound) { } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Stock Round UI"); stockChart.setVisible(true); statusWindow.setVisible(true); - //} else if (currentRound instanceof OperatingRound) { } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Operating Round UI"); stockChart.setVisible(false); ! orUIManager.initOR((OperatingRound) currentRound); } } --- 212,263 ---- } + } else if (StockRound.class.isAssignableFrom(currentRoundType)) { + + log.debug("UI entering Stock Round"); + + } else if (OperatingRound.class.isAssignableFrom(currentRoundType)) { + + log.debug("UI entering Operating Round"); + orUIManager.initOR((OperatingRound) currentRound); + } else if (SwitchableUIRound.class.isAssignableFrom(currentRoundType) ) { + log.debug("UI entering switchable round type"); + } + } + + /* Process visible round type changes */ + if (previousRoundUItype == null || !previousRoundUItype.equals(currentRoundUItype)) { + + if (previousRoundUItype != null) { + // Finish the previous round UI aspects + if (StockRound.class.isAssignableFrom(previousRoundUItype)) { + log.debug("Leaving Stock Round UI type"); + } else if (StartRound.class.isAssignableFrom(previousRoundUItype)) { + log.debug("Leaving Start Round UI type"); + } else if (OperatingRound.class.isAssignableFrom(previousRoundUItype)) { + log.debug("Leaving Operating Round UI type"); + orWindow.setVisible(false); + } + } + + // Start the new round UI aspects + if (StartRound.class.isAssignableFrom(currentRoundUItype)) { + + log.debug("Entering Start Round UI type"); + activeWindow = startRoundWindow; stockChart.setVisible(false); } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Stock Round UI type"); ! activeWindow = statusWindow; stockChart.setVisible(true); statusWindow.setVisible(true); } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Operating Round UI type "); ! activeWindow = orWindow; stockChart.setVisible(false); ! orWindow.setVisible(true); } } *************** *** 207,230 **** previousRound = currentRound; ! // Update the current round window ! //if (currentRound instanceof StartRound) { if (StartRound.class.isAssignableFrom(currentRoundUItype)) { - activeWindow = startRoundWindow; startRoundWindow.updateStatus(); startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); - //} else if (currentRound instanceof StockRound) { } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { - activeWindow = statusWindow; statusWindow.updateStatus(); - //} else if (currentRound instanceof OperatingRound) { } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { - activeWindow = orUIManager.getORWindow(); orUIManager.updateStatus(); } } --- 266,411 ---- previousRound = currentRound; ! // Update the currently visible round window ! // "Switchable" rounds will be handled from subclasses of this class. if (StartRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating Start round window"); startRoundWindow.updateStatus(); startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating Stock (status) round window"); statusWindow.updateStatus(); } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating Operating round window"); orUIManager.updateStatus(); + } else { + // Handle special rounds that do not fall in a standard category + // The round must indicate which main window to raise + if (StockRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating switched Stock (status) round window"); + activeWindow = statusWindow; + } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating switched Operating round window"); + activeWindow = orWindow; + } + updateStatus(activeWindow); + } + } + + /** Stub, to be overridden in subclasses for special round types */ + protected void updateStatus(ActionPerformer activeWindow) { + + } + + public void discardTrains (DiscardTrain dt) { + + PublicCompanyI c = dt.getCompany(); + String playerName = dt.getPlayerName(); + List<TrainI> trains = dt.getOwnedTrains(); + int size = trains.size() + (dt.isForced() ? 0 : 1); + List<String> trainOptions = + new ArrayList<String>(size); + String[] options = new String[size]; + String prompt = null; + + int j = 0; + if (!dt.isForced()) { + trainOptions.add( + options[j++] = LocalText.getText("None") + ); + prompt = LocalText.getText("MayDiscardTrain", + c.getName()); + } + int offset = j; + for (int i = 0; i < trains.size(); i++) { + trainOptions.add( + options[j++] = LocalText.getText("N_Train", + trains.get(i).getName()) + ); + } + if (prompt == null) prompt = LocalText.getText( + "HAS_TOO_MANY_TRAINS", + playerName, + c.getName() ); + String discardedTrainName = + (String) JOptionPane.showInputDialog(orWindow, + prompt, + LocalText.getText("WhichTrainToDiscard"), + JOptionPane.QUESTION_MESSAGE, null, + options, options[0]); + if (discardedTrainName != null) { + int index = trainOptions.indexOf(discardedTrainName); + if (index >= offset) { + TrainI discardedTrain = + trains.get(trainOptions.indexOf(discardedTrainName)-offset); + dt.setDiscardedTrain(discardedTrain); + } + + orWindow.process(dt); + } + } + + public void exchangeTokens (ExchangeTokens action) { + + int index, cityNumber; + String prompt, cityName, hexName, oldCompName; + String[] ct; + MapHex hex; + List<String> options = new ArrayList<String>(); + City city; + List<ExchangeableToken> oldTokens = action.getTokensToExchange(); + + for (ExchangeableToken t : oldTokens) { + cityName = t.getCityName(); + ct = cityName.split("/"); + hexName = ct[0]; + try { + cityNumber = Integer.parseInt(ct[1]); + } catch (NumberFormatException e) { + cityNumber = 1; + } + hex = orWindow.getMapPanel().getMap().getHexByName (hexName).getHexModel(); + city = hex.getCity(cityNumber); + oldCompName = t.getOldCompanyName(); + options.add(LocalText.getText("ExchangeableToken", + oldCompName, + hexName, + hex.getCityName(), + cityNumber, + city.getTrackEdges())); + } + + + int minNumber = action.getMinNumberToExchange(); + int maxNumber = action.getMaxNumberToExchange(); + if (minNumber == maxNumber) { + prompt = LocalText.getText("ExchangeTokensPrompt1", + minNumber, + action.getCompanyName()); + } else { + prompt = LocalText.getText("ExchangeTokensPrompt2", + minNumber, maxNumber, + action.getCompanyName()); + } + + if (options.size() > 0) { + orWindow.setVisible(true); + boolean[] exchanged = + new CheckBoxDialog(orWindow.getORPanel(), + LocalText.getText("ExchangeTokens"), + prompt, + options.toArray(new String[0])) + .getSelectedOptions(); + for (index=0; index < options.size(); index++) { + if (exchanged[index]) { + oldTokens.get(index).setSelected(true); + } + } + orWindow.process(action); } } *************** *** 257,260 **** --- 438,442 ---- } + /* public boolean loadGame() { *************** *** 285,288 **** --- 467,471 ---- return true; } + */ public PossibleAction getLastAction() { |
From: Erik V. <ev...@us...> - 2009-02-04 20:43:48
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5321/rails/game Modified Files: OperatingRound.java Log Message: CGR Formation round phase 1: repaying loans. Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** OperatingRound.java 4 Feb 2009 20:36:39 -0000 1.55 --- OperatingRound.java 4 Feb 2009 20:43:37 -0000 1.56 *************** *** 1758,1763 **** if (payment > 0) { new CashMove (operatingCompany, null, payment); ! } ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", operatingCompany.getName(), Bank.format(payment), --- 1758,1762 ---- if (payment > 0) { new CashMove (operatingCompany, null, payment); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", operatingCompany.getName(), Bank.format(payment), *************** *** 1765,1768 **** --- 1764,1768 ---- number, Bank.format(operatingCompany.getValuePerLoan()))); + } } if (remainder > 0) { |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:52
|
Update of /cvsroot/rails/18xx/rails/common In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/rails/common Modified Files: Defs.java Log Message: CGR Formation round phase 1: repaying loans. Index: Defs.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/common/Defs.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Defs.java 11 Jan 2009 17:24:46 -0000 1.2 --- Defs.java 4 Feb 2009 20:36:40 -0000 1.3 *************** *** 9,13 **** OR_UI_MANAGER, STATUS_WINDOW, ! GAME_STATUS } --- 9,14 ---- OR_UI_MANAGER, STATUS_WINDOW, ! GAME_STATUS, ! OR_WINDOW } *************** *** 22,25 **** --- 23,28 ---- defaultClasses.put (ClassName.GAME_STATUS, "rails.ui.swing.GameStatus"); + defaultClasses.put (ClassName.OR_WINDOW, + "rails.ui.swing.ORWindow"); } |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:52
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/rails/game Modified Files: RoundI.java OperatingRound.java DisplayBuffer.java Round.java GameManager.java Log Message: CGR Formation round phase 1: repaying loans. Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** OperatingRound.java 24 Jan 2009 15:10:27 -0000 1.54 --- OperatingRound.java 4 Feb 2009 20:36:39 -0000 1.55 *************** *** 107,111 **** protected boolean doneAllowed = false; ! protected TrainManagerI trainManager = gameManager.getTrainManager(); --- 107,111 ---- protected boolean doneAllowed = false; ! protected TrainManagerI trainManager = gameManager.getTrainManager(); *************** *** 127,130 **** --- 127,132 ---- numberOfPlayers = players.size(); } + + operatingCompanyArray = super.getOperatingCompanies(); } *************** *** 151,155 **** if (operate) { ! operatingCompanyArray = super.getOperatingCompanies(); if (operatingCompanyArray.length > 0) { --- 153,164 ---- if (operate) { ! ! ! StringBuffer msg = new StringBuffer(); ! for (PublicCompanyI company : operatingCompanyArray) { ! msg.append(",").append(company.getName()); ! } ! msg.deleteCharAt(0); ! log.info("Initial operating sequence is "+msg.toString()); if (operatingCompanyArray.length > 0) { *************** *** 908,912 **** continue; } ! if (step == STEP_TRADE_SHARES) { --- 917,921 ---- continue; } ! if (step == STEP_TRADE_SHARES) { *************** *** 1387,1390 **** --- 1396,1400 ---- executeRepayLoans ((RepayLoans) savedAction); } + savedAction = null; } *************** *** 1702,1706 **** int repayment = action.getNumberRepaid() * operatingCompany.getValuePerLoan(); ! if (repayment > operatingCompany.getCash()) { // President must contribute int remainder = repayment - operatingCompany.getCash(); --- 1712,1716 ---- int repayment = action.getNumberRepaid() * operatingCompany.getValuePerLoan(); ! if (repayment > 0 && repayment > operatingCompany.getCash()) { // President must contribute int remainder = repayment - operatingCompany.getCash(); *************** *** 1722,1726 **** MoveSet.start(true); ! executeRepayLoans (action); return true; --- 1732,1736 ---- MoveSet.start(true); ! if (repayment > 0) executeRepayLoans (action); return true; *************** *** 1865,1868 **** --- 1875,1882 ---- } else if (step == STEP_BUY_TRAIN) { setBuyableTrains(); + if (!operatingCompany.mustOwnATrain() + || operatingCompany.getPortfolio().getNumberOfTrains() > 0) { + doneAllowed = true; + } } else if (step == STEP_DISCARD_TRAINS) { setTrainsToDiscard(); Index: DisplayBuffer.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/DisplayBuffer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DisplayBuffer.java 4 Jun 2008 19:00:31 -0000 1.5 --- DisplayBuffer.java 4 Feb 2009 20:36:39 -0000 1.6 *************** *** 27,30 **** --- 27,32 ---- */ private static List<String> displayBuffer = new ArrayList<String>(); + + private static boolean autoDisplay = true; /** *************** *** 33,40 **** */ public static void add(String message) { if (Util.hasValue(message)) { displayBuffer.add(message); /* Also log the message */ ! log.info("Displayed: " + message); } } --- 35,47 ---- */ public static void add(String message) { + add (message, true); + } + + public static void add (String message, boolean autoDisplay) { + DisplayBuffer.autoDisplay = autoDisplay; if (Util.hasValue(message)) { displayBuffer.add(message); /* Also log the message */ ! log.info("To display: " + message); } } *************** *** 50,53 **** --- 57,68 ---- } } + + public static int getSize() { + return displayBuffer.size(); + } + + public static boolean getAutoDisplay () { + return autoDisplay; + } public static void clear() { Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Round.java 15 Jan 2009 20:53:28 -0000 1.15 --- Round.java 4 Feb 2009 20:36:39 -0000 1.16 *************** *** 80,83 **** --- 80,93 ---- } + /** Allows round instances to tell the UI what type of window to raise. + * Normally the type corresponds to the round type (e.g. OperatingRound + * needs ORWindow), but sometimes deviations occur (such as the + * CGRFormationRound, which isn't a StockRound type but needs StatusWindow). + * @return + */ + public Class<? extends RoundI> getRoundTypeForUI () { + return this.getClass(); + } + /* * (non-Javadoc) *************** *** 140,143 **** --- 150,154 ---- operatingCompanies.put(new Integer(key), company); } + return operatingCompanies.values().toArray(new PublicCompanyI[0]); } Index: RoundI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/RoundI.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RoundI.java 23 Dec 2008 19:55:29 -0000 1.9 --- RoundI.java 4 Feb 2009 20:36:39 -0000 1.10 *************** *** 12,20 **** /** * Get the player that has the next turn. ! * * @return Player object. */ public Player getCurrentPlayer(); public String getHelp(); --- 12,22 ---- /** * Get the player that has the next turn. ! * * @return Player object. */ public Player getCurrentPlayer(); + public Class<? extends RoundI> getRoundTypeForUI (); + public String getHelp(); Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** GameManager.java 24 Jan 2009 15:10:29 -0000 1.43 --- GameManager.java 4 Feb 2009 20:36:39 -0000 1.44 *************** *** 40,43 **** --- 40,44 ---- protected String gameStatusClassName = Defs.getDefaultClassName(Defs.ClassName.GAME_STATUS); protected String statusWindowClassName = Defs.getDefaultClassName(Defs.ClassName.STATUS_WINDOW); + protected String orWindowClassName = Defs.getDefaultClassName(Defs.ClassName.OR_WINDOW); protected PlayerManager playerManager; *************** *** 249,253 **** if (orMgrTag != null) { orUIManagerClassName = ! orMgrTag.getAttributeAsString("class", "ORUIManager"); // Check instantiatability (not sure if this belongs here) canClassBeInstantiated (orUIManagerClassName); --- 250,254 ---- if (orMgrTag != null) { orUIManagerClassName = ! orMgrTag.getAttributeAsString("class", orUIManagerClassName); // Check instantiatability (not sure if this belongs here) canClassBeInstantiated (orUIManagerClassName); *************** *** 258,262 **** if (gameStatusTag != null) { gameStatusClassName = ! gameStatusTag.getAttributeAsString("class", "GameStatus"); // Check instantiatability (not sure if this belongs here) canClassBeInstantiated (gameStatusClassName); --- 259,263 ---- if (gameStatusTag != null) { gameStatusClassName = ! gameStatusTag.getAttributeAsString("class", gameStatusClassName); // Check instantiatability (not sure if this belongs here) canClassBeInstantiated (gameStatusClassName); *************** *** 268,275 **** statusWindowClassName = statusWindowTag.getAttributeAsString("class", ! "StatusWindow"); // Check instantiatability (not sure if this belongs here) canClassBeInstantiated (statusWindowClassName); } } --- 269,286 ---- statusWindowClassName = statusWindowTag.getAttributeAsString("class", ! statusWindowClassName); // Check instantiatability (not sure if this belongs here) canClassBeInstantiated (statusWindowClassName); } + + // ORWindow class + Tag orWindowTag = tag.getChild("ORWindow"); + if (orWindowTag != null) { + orWindowClassName = + orWindowTag.getAttributeAsString("class", + orWindowClassName); + // Check instantiatability (not sure if this belongs here) + canClassBeInstantiated (orWindowClassName); + } } *************** *** 360,364 **** * @see rails.game.GameManagerI#setRound(rails.game.RoundI) */ ! private void setRound(RoundI round) { currentRound.set(round); } --- 371,375 ---- * @see rails.game.GameManagerI#setRound(rails.game.RoundI) */ ! protected void setRound(RoundI round) { currentRound.set(round); } *************** *** 616,620 **** for (PossibleAction action : actions) { ! // TEMPORARY FIX TO ALLOW OLD 1856 SAVED FILES TO BE PROCESSED if (!possibleActions.contains(action.getClass()) --- 627,631 ---- for (PossibleAction action : actions) { ! // TEMPORARY FIX TO ALLOW OLD 1856 SAVED FILES TO BE PROCESSED if (!possibleActions.contains(action.getClass()) *************** *** 625,629 **** getCurrentRound().setPossibleActions(); } ! try { log.debug("Action: " + action); --- 636,640 ---- getCurrentRound().setPossibleActions(); } ! try { log.debug("Action: " + action); *************** *** 882,886 **** return phaseManager; } ! public TrainManagerI getTrainManager () { return trainManager; --- 893,897 ---- return phaseManager; } ! public TrainManagerI getTrainManager () { return trainManager; *************** *** 919,922 **** --- 930,934 ---- switch (key) { + case OR_UI_MANAGER: return orUIManagerClassName; |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:52
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/rails/game/specific/_1856 Modified Files: OperatingRound_1856.java Added Files: CGRFormationRound.java GameManager_1856.java Log Message: CGR Formation round phase 1: repaying loans. --- NEW FILE: CGRFormationRound.java --- package rails.game.specific._1856; import java.util.*; import rails.game.*; import rails.game.action.RepayLoans; import rails.game.move.CashMove; import rails.util.LocalText; public class CGRFormationRound extends OperatingRound { /* This isn't really a stock round, but it must subclass one of the * three base types, otherwise the not-subclassable GameUIManager * cannot handle it. StockRound has been chosen because the UI * should show the StatusWindow. */ private Player startingPlayer; private Map<Player, List<PublicCompanyI>> companiesToRepayLoans = null; private PublicCompanyI currentCompany = null; private int maxLoansToRepayByPresident = 0; private List<PublicCompanyI> mergingCompanies = new ArrayList<PublicCompanyI>(); public CGRFormationRound (GameManagerI gameManager) { super (gameManager); } @Override /** This class needs the game status window to show up * rather than the operating round window. */ public Class<? extends RoundI> getRoundTypeForUI () { return StockRound.class; } public void start (Player startingPlayer) { this.startingPlayer = startingPlayer; Player president; companiesToRepayLoans = null; ReportBuffer.add(LocalText.getText("StartCGRFormationRound", startingPlayer.getName())); // Collect companies having loans for (PublicCompanyI company : getOperatingCompanies()) { if (company.getCurrentNumberOfLoans() > 0) { if (companiesToRepayLoans == null) { companiesToRepayLoans = new HashMap<Player, List<PublicCompanyI>>(); } president = company.getPresident(); if (!companiesToRepayLoans.containsKey(president)) { companiesToRepayLoans.put (president, new ArrayList<PublicCompanyI>()); } companiesToRepayLoans.get(president).add(company); } } setCurrentPlayer (startingPlayer); setNextCompanyNeedingPresidentIntervention(); } private boolean setNextCompanyNeedingPresidentIntervention () { while (true) { while (!companiesToRepayLoans.containsKey(getCurrentPlayer())) { gameManager.setNextPlayer(); if (getCurrentPlayer().equals(startingPlayer)) { return false; } } // Player to act already has been selected Player player = getCurrentPlayer(); if (companiesToRepayLoans.get(player).isEmpty()) { companiesToRepayLoans.remove(player); continue; } currentCompany = companiesToRepayLoans.get(player).get(0); companiesToRepayLoans.get(player).remove(currentCompany); int numberOfLoans = currentCompany.getCurrentNumberOfLoans(); if (numberOfLoans == 0) continue; int compCash = currentCompany.getCash(); int presCash = player.getCash(); int valuePerLoan = currentCompany.getValuePerLoan(); String message; int payment; message = LocalText.getText("CompanyHasLoans", currentCompany.getName(), player.getName(), numberOfLoans, Bank.format(valuePerLoan), Bank.format(numberOfLoans * valuePerLoan)); ReportBuffer.add(message); DisplayBuffer.add(message, false); // Let company repay all loans for which it has the cash int numberToRepay = Math.min(numberOfLoans, compCash / valuePerLoan); if (numberToRepay > 0) { payment = numberToRepay * valuePerLoan; new CashMove (currentCompany, null, payment); currentCompany.addLoans(-numberToRepay); message = LocalText.getText("CompanyRepaysLoans", currentCompany.getName(), Bank.format(payment), Bank.format(numberOfLoans * valuePerLoan), numberToRepay, Bank.format(valuePerLoan)); ReportBuffer.add (message); DisplayBuffer.add(message, false); } // If that was all, we're done with this company numberOfLoans = currentCompany.getCurrentNumberOfLoans(); if (numberOfLoans == 0) continue; // Check the president's cash // He should be involved if at least one extra loan could be repaid compCash = currentCompany.getCash(); if ((compCash + presCash) / valuePerLoan > 0) { int maxNumber = Math.min((compCash + presCash)/valuePerLoan, numberOfLoans); if (maxNumber == numberOfLoans) { DisplayBuffer.add(LocalText.getText("YouCanRepayAllLoans", player.getName(), maxNumber, currentCompany.getName()), false); } else { DisplayBuffer.add(LocalText.getText("YouCannotRepayAllLoans", player.getName(), maxNumber, numberOfLoans, currentCompany.getName()), false); } maxLoansToRepayByPresident = maxNumber; break; } else { // President cannot help, this company will merge into CGR anyway mergingCompanies.add(currentCompany); message = LocalText.getText("WillMergeInto", currentCompany.getName(), "CGR"); DisplayBuffer.add(message, false); ReportBuffer.add(message); continue; } } return true; } @Override public boolean setPossibleActions() { RepayLoans action = new RepayLoans (currentCompany, 0, maxLoansToRepayByPresident, currentCompany.getValuePerLoan()); possibleActions.add(action); operatingCompany = currentCompany; return true; } @Override protected boolean repayLoans (RepayLoans action) { boolean result = super.repayLoans(action); if (action.getCompany().getCurrentNumberOfLoans() > 0) { mergingCompanies.add(currentCompany); String message = LocalText.getText("WillMergeInto", currentCompany.getName(), "CGR"); DisplayBuffer.add(message, true); ReportBuffer.add(message); } if (!setNextCompanyNeedingPresidentIntervention()) { gameManager.nextRound(this); } return result; } @Override public String toString() { return "1856 CGRFormationRound"; } } Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** OperatingRound_1856.java 24 Jan 2009 15:09:14 -0000 1.7 --- OperatingRound_1856.java 4 Feb 2009 20:36:39 -0000 1.8 *************** *** 12,19 **** public class OperatingRound_1856 extends OperatingRound { ! ! BooleanState finalLoanRepaymentPending = new BooleanState ("LoanRepaymentPending", false); ! Player playerToStartLoanRepayment = null; public static final int STEP_REPAY_LOANS = 6; --- 12,19 ---- public class OperatingRound_1856 extends OperatingRound { ! ! private BooleanState finalLoanRepaymentPending = new BooleanState ("LoanRepaymentPending", false); ! private Player playerToStartLoanRepayment = null; public static final int STEP_REPAY_LOANS = 6; *************** *** 296,299 **** --- 296,300 ---- if (getStep() == STEP_REPAY_LOANS) { + // Has company any outstanding loans to repay? if (operatingCompany.getMaxNumberOfLoans() != 0 *************** *** 329,347 **** } } ! public boolean buyTrain(BuyTrain action) { ! PhaseI prePhase = currentPhase; ! boolean result = super.buyTrain(action); ! PhaseI postPhase = currentPhase; ! if (postPhase != prePhase && postPhase.getName().equals("5")) { finalLoanRepaymentPending.set(true); ! playerToStartLoanRepayment = gameManager.getPlayerByIndex(action.getPlayerIndex()); } ! return result; } --- 330,349 ---- } } ! ! @Override public boolean buyTrain(BuyTrain action) { ! PhaseI prePhase = currentPhase; ! boolean result = super.buyTrain(action); ! PhaseI postPhase = currentPhase; ! if (postPhase != prePhase && postPhase.getName().equals("5")) { finalLoanRepaymentPending.set(true); ! playerToStartLoanRepayment = gameManager.getPlayerByIndex(action.getPlayerIndex()); } ! return result; } *************** *** 419,429 **** return true; } - } else { - // We are not in this step - return true; } } ! protected void finishTurn() { --- 421,447 ---- return true; } } + return true; } ! ! @Override ! public void resume() { ! ! if (savedAction == null) { ! // End of CGRFormationRound ! finalLoanRepaymentPending.set(false); ! if (setNextOperatingCompany(false)) { ! setStep(STEP_INITIAL); ! } else { ! finishOR(); ! } ! } else { ! super.resume(); ! } ! } ! ! ! @Override protected void finishTurn() { *************** *** 435,442 **** priv.checkClosingIfExercised(true); } ! if (finalLoanRepaymentPending.booleanValue()) { ! // Must start final loan repayment and CGR formation ! // TODO } --- 453,461 ---- priv.checkClosingIfExercised(true); } ! if (finalLoanRepaymentPending.booleanValue()) { ! ! ((GameManager_1856)gameManager).startCGRFormationRound(this, playerToStartLoanRepayment); ! return; } *************** *** 447,451 **** } } - - } --- 466,468 ---- --- NEW FILE: GameManager_1856.java --- /* $Header: /cvsroot/rails/18xx/rails/game/specific/_1856/GameManager_1856.java,v 1.1 2009/02/04 20:36:39 evos Exp $ */ package rails.game.specific._1856; import rails.game.*; public class GameManager_1856 extends GameManager { private Player playerToStartCGRFRound = null; public void startCGRFormationRound(OperatingRound_1856 or, Player playerToStartCGRFRound) { this.playerToStartCGRFRound = playerToStartCGRFRound; interruptedRound = or; if (this.playerToStartCGRFRound != null) { createRound (CGRFormationRound.class).start (this.playerToStartCGRFRound); this.playerToStartCGRFRound = null; } } @Override public void nextRound(RoundI round) { if (round instanceof CGRFormationRound) { setRound(interruptedRound); ((OperatingRound_1856)interruptedRound).resume(); } else { super.nextRound(round); } } } |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:51
|
Update of /cvsroot/rails/18xx In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948 Modified Files: LocalisedText.properties Log Message: CGR Formation round phase 1: repaying loans. Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** LocalisedText.properties 21 Jan 2009 20:18:23 -0000 1.67 --- LocalisedText.properties 4 Feb 2009 20:36:40 -0000 1.68 *************** *** 82,85 **** --- 82,86 ---- CompanyDoesNotOwnTrain=Company {0} does not own a {1}-train CompanyDoesNotPayDividend={0} does not pay a dividend + CompanyHasLoans={0} (president {1}) has {2} loans of {3}, total is {4} CompanyHasNoType=Company {0} has no type defined CompanyHasUnknownType=Company {0} has an undefined type {1} *************** *** 295,299 **** Select=Select SelectCompanyToMergeMinorInto=Select major company to merge minor {0} into ! SelectLoansToRepay=Select number of loans to repay SelectMinorToMerge=Select the minor to merge to start company {0} SelectNoBid=Select, No Bid --- 296,300 ---- Select=Select SelectCompanyToMergeMinorInto=Select major company to merge minor {0} into ! SelectLoansToRepay=Select number of loans of {0} to repay SelectMinorToMerge=Select the minor to merge to start company {0} SelectNoBid=Select, No Bid *************** *** 336,339 **** --- 337,341 ---- StartCompany={0} (buy {1}% share for {2}) StartCompanyFixed=Start {0} by buying {1}% share for {2} + StartCGRFormationRound=Starting CGR formation round. Starting player is {0} StartFinalMinorExchangeRound=Start of the Final Minor Company Exchange Round StartOfInitialRound=Start of initial round *************** *** 405,408 **** --- 407,411 ---- WhichTrainToDiscard=Which train will you discard? WHICH_VARIANT=Select the {0} variant that you want to play + WillMergeInto={0} will merge into {1} WITHHOLD=Withhold WithOptional6Train=Add optional (3rd) 6-train *************** *** 425,428 **** --- 428,433 ---- YOU_MUST_ADD_CASH=(you must add {0}) YouAreBankrupt=You must still raise {0}, but you can\\'t sell any more shares, so you are Bankrupt! + YouCanRepayAllLoans={0} can repay all {1} loans of {2} and save it from merging into CGR + YouCannotRepayAllLoans={0} can repay max. {1} out of {2} loans of {3}, but cannot save it from merging into CGR YouMustRaiseCash=You must raise {0} cash by selling shares |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:51
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/rails/ui/swing Modified Files: ORWindow.java StatusWindow.java GameUIManager.java Log Message: CGR Formation round phase 1: repaying loans. Index: StatusWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/StatusWindow.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** StatusWindow.java 3 Dec 2008 20:17:36 -0000 1.26 --- StatusWindow.java 4 Feb 2009 20:36:40 -0000 1.27 *************** *** 514,517 **** --- 514,520 ---- process(executedAction); } + } else { + // Unknown action, let UIManager catch it + process (executedAction); } } Index: ORWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORWindow.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ORWindow.java 15 Jan 2009 20:53:28 -0000 1.22 --- ORWindow.java 4 Feb 2009 20:36:40 -0000 1.23 *************** *** 25,36 **** public class ORWindow extends JFrame implements ActionPerformer { private static final long serialVersionUID = 1L; ! public GameUIManager gameUIManager; ! private ORUIManager orUIManager; ! private MapPanel mapPanel; ! private ORPanel orPanel; ! private UpgradesPanel upgradePanel; ! private MessagePanel messagePanel; ! private Rectangle lastBounds; protected PossibleActions possibleActions = PossibleActions.getInstance(); --- 25,36 ---- public class ORWindow extends JFrame implements ActionPerformer { private static final long serialVersionUID = 1L; ! protected GameUIManager gameUIManager; ! protected ORUIManager orUIManager; ! protected MapPanel mapPanel; ! protected ORPanel orPanel; ! protected UpgradesPanel upgradePanel; ! protected MessagePanel messagePanel; ! protected Rectangle lastBounds; protected PossibleActions possibleActions = PossibleActions.getInstance(); Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** GameUIManager.java 23 Dec 2008 20:02:45 -0000 1.15 --- GameUIManager.java 4 Feb 2009 20:36:40 -0000 1.16 *************** *** 95,101 **** updateUI(); ! } ! public boolean processOnServer(PossibleAction action) { --- 95,101 ---- updateUI(); ! } ! public boolean processOnServer(PossibleAction action) { *************** *** 111,115 **** boolean result = gameManager.process(action); log.debug("==Result from server: " + result); ! activeWindow.displayServerMessage(); reportWindow.addLog(); --- 111,115 ---- boolean result = gameManager.process(action); log.debug("==Result from server: " + result); ! if (DisplayBuffer.getAutoDisplay()) activeWindow.displayServerMessage(); reportWindow.addLog(); *************** *** 149,171 **** // Process consequences of a round type change to the UI if (previousRound == null || !previousRound.equals(currentRound)) { ! // Finish the previous round UI aspects ! if (previousRound instanceof StockRound) { ! log.debug("Finishing Stock Round UI"); ! statusWindow.finishRound(); ! } else if (previousRound instanceof StartRound) { ! log.debug("Finishing Start Round UI"); ! if (startRoundWindow != null) { ! startRoundWindow.close(); ! startRoundWindow = null; } - } else if (previousRound instanceof OperatingRound) { - log.debug("Finishing Operating Round UI"); - orUIManager.finish(); } // Start the new round UI aspects ! if (currentRound instanceof StartRound) { log.debug("Entering Start Round UI"); --- 149,182 ---- // Process consequences of a round type change to the UI + Class<? extends RoundI> previousRoundUItype + = previousRound == null ? null : previousRound.getRoundTypeForUI(); + Class<? extends RoundI> currentRoundUItype + = currentRound.getRoundTypeForUI(); + if (previousRound == null || !previousRound.equals(currentRound)) { ! if (previousRound != null) { ! // Finish the previous round UI aspects ! //if (previousRound instanceof StockRound) { ! if (StockRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Stock Round UI"); ! statusWindow.finishRound(); ! //} else if (previousRound instanceof StartRound) { ! } else if (StartRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Start Round UI"); ! if (startRoundWindow != null) { ! startRoundWindow.close(); ! startRoundWindow = null; ! } ! //} else if (previousRound instanceof OperatingRound) { ! } else if (OperatingRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Operating Round UI"); ! orUIManager.finish(); } } // Start the new round UI aspects ! //if (currentRound instanceof StartRound) { ! if (StartRound.class.isAssignableFrom(currentRoundUItype)) { log.debug("Entering Start Round UI"); *************** *** 177,181 **** stockChart.setVisible(false); ! } else if (currentRound instanceof StockRound) { log.debug("Entering Stock Round UI"); --- 188,193 ---- stockChart.setVisible(false); ! //} else if (currentRound instanceof StockRound) { ! } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { log.debug("Entering Stock Round UI"); *************** *** 183,187 **** statusWindow.setVisible(true); ! } else if (currentRound instanceof OperatingRound) { log.debug("Entering Operating Round UI"); --- 195,200 ---- statusWindow.setVisible(true); ! //} else if (currentRound instanceof OperatingRound) { ! } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { log.debug("Entering Operating Round UI"); *************** *** 192,198 **** statusWindow.setupFor(currentRound); // Update the current round window ! if (currentRound instanceof StartRound) { activeWindow = startRoundWindow; --- 205,213 ---- statusWindow.setupFor(currentRound); + previousRound = currentRound; // Update the current round window ! //if (currentRound instanceof StartRound) { ! if (StartRound.class.isAssignableFrom(currentRoundUItype)) { activeWindow = startRoundWindow; *************** *** 200,216 **** startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); ! } else if (currentRound instanceof StockRound) { activeWindow = statusWindow; statusWindow.updateStatus(); ! } else if (currentRound instanceof OperatingRound) { activeWindow = orUIManager.getORWindow(); orUIManager.updateStatus(); - } - - previousRound = currentRound; } --- 215,231 ---- startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); ! //} else if (currentRound instanceof StockRound) { ! } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { activeWindow = statusWindow; statusWindow.updateStatus(); ! //} else if (currentRound instanceof OperatingRound) { ! } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { activeWindow = orUIManager.getORWindow(); orUIManager.updateStatus(); + } } *************** *** 282,336 **** return gameManager; } ! public RoundI getCurrentRound() { return gameManager.getCurrentRound(); } ! public boolean isGameOver() { return gameManager.isGameOver(); } ! public String getHelp () { return gameManager.getHelp(); } ! public int getNumberOfPlayers() { return gameManager.getNumberOfPlayers(); } ! public List<Player> getPlayers() { return gameManager.getPlayers(); } ! public List<String> getPlayerNames() { return gameManager.getPlayerNames(); } ! public Player getCurrentPlayer() { return gameManager.getCurrentPlayer(); } ! public Player getPriorityPlayer () { return gameManager.getPriorityPlayer(); } ! public PhaseI getCurrentPhase() { return gameManager.getCurrentPhase(); } ! public List<PublicCompanyI> getAllPublicCompanies(){ return gameManager.getAllPublicCompanies(); } ! public String getClassName (Defs.ClassName key) { return gameManager.getClassName(key); } ! public Object getCommonParameter (Defs.Parm key) { return gameManager.getCommonParameter(key); } ! public boolean getCommonParameterAsBoolean (Defs.Parm key) { ! return (Boolean) getCommonParameter(key); } --- 297,351 ---- return gameManager; } ! public RoundI getCurrentRound() { return gameManager.getCurrentRound(); } ! public boolean isGameOver() { return gameManager.isGameOver(); } ! public String getHelp () { return gameManager.getHelp(); } ! public int getNumberOfPlayers() { return gameManager.getNumberOfPlayers(); } ! public List<Player> getPlayers() { return gameManager.getPlayers(); } ! public List<String> getPlayerNames() { return gameManager.getPlayerNames(); } ! public Player getCurrentPlayer() { return gameManager.getCurrentPlayer(); } ! public Player getPriorityPlayer () { return gameManager.getPriorityPlayer(); } ! public PhaseI getCurrentPhase() { return gameManager.getCurrentPhase(); } ! public List<PublicCompanyI> getAllPublicCompanies(){ return gameManager.getAllPublicCompanies(); } ! public String getClassName (Defs.ClassName key) { return gameManager.getClassName(key); } ! public Object getCommonParameter (Defs.Parm key) { return gameManager.getCommonParameter(key); } ! public boolean getCommonParameterAsBoolean (Defs.Parm key) { ! return (Boolean) getCommonParameter(key); } |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:48
|
Update of /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/rails/ui/swing/gamespecific/_1856 Added Files: StatusWindow_1856.java Log Message: CGR Formation round phase 1: repaying loans. --- NEW FILE: StatusWindow_1856.java --- package rails.ui.swing.gamespecific._1856; import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; import rails.game.*; import rails.game.action.RepayLoans; import rails.game.specific._1856.CGRFormationRound; import rails.ui.swing.StatusWindow; import rails.util.LocalText; public class StatusWindow_1856 extends StatusWindow { public StatusWindow_1856() { super(); } @Override public void updateStatus() { RoundI currentRound = gameUIManager.getCurrentRound(); if (!(currentRound instanceof OperatingRound)) { return; } else if (!(currentRound instanceof CGRFormationRound)) { super.updateStatus(); } else if (possibleActions.contains(RepayLoans.class)) { RepayLoans action = possibleActions.getType(RepayLoans.class).get(0); repayLoans (action); } } // Code copied from ORUIManager protected void repayLoans (RepayLoans action) { int minNumber = action.getMinNumber(); int maxNumber = action.getMaxNumber(); int loanAmount = action.getPrice(); int numberRepaid = 0; List<String> options = new ArrayList<String>(); for (int i=minNumber; i<=maxNumber; i++) { if (i == 0) { options.add(LocalText.getText("None")); } else { options.add(LocalText.getText("RepayLoan", i, Bank.format(loanAmount), Bank.format(i * loanAmount))); } } int displayBufSize = DisplayBuffer.getSize(); String[] message = new String[displayBufSize+1]; System.arraycopy (DisplayBuffer.get(),0,message,0,displayBufSize); message[displayBufSize] = LocalText.getText("SelectLoansToRepay", action.getCompanyName()); Object choice = JOptionPane.showInputDialog(this, message, LocalText.getText("Select"), JOptionPane.QUESTION_MESSAGE, null, options.toArray(), options.get(0)); numberRepaid = minNumber + options.indexOf(choice); action.setNumberTaken(numberRepaid); process (action); } } |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:48
|
Update of /cvsroot/rails/18xx/data/1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/data/1856 Modified Files: Game.xml Log Message: CGR Formation round phase 1: repaying loans. Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1856/Game.xml,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Game.xml 15 Nov 2008 13:41:48 -0000 1.20 --- Game.xml 4 Feb 2009 20:36:39 -0000 1.21 *************** *** 1,9 **** <?xml version="1.0"?> <ComponentManager> ! <Component name="GameManager" class="rails.game.GameManager"> <Game name="1856"/> <StockRound class="rails.game.specific._1856.StockRound_1856" sequence="SellBuyOrBuySell"/> <OperatingRound class="rails.game.specific._1856.OperatingRound_1856"/> <PlayerShareLimit percentage="60"/> <BankPoolLimit percentage="50"/> --- 1,10 ---- <?xml version="1.0"?> <ComponentManager> ! <Component name="GameManager" class="rails.game.specific._1856.GameManager_1856"> <Game name="1856"/> <StockRound class="rails.game.specific._1856.StockRound_1856" sequence="SellBuyOrBuySell"/> <OperatingRound class="rails.game.specific._1856.OperatingRound_1856"/> + <StatusWindow class="rails.ui.swing.gamespecific._1856.StatusWindow_1856"/> <PlayerShareLimit percentage="60"/> <BankPoolLimit percentage="50"/> |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:46
|
Update of /cvsroot/rails/18xx/rails/game/action In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4948/rails/game/action Modified Files: RepayLoans.java Log Message: CGR Formation round phase 1: repaying loans. Index: RepayLoans.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/RepayLoans.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RepayLoans.java 21 Jan 2009 20:18:24 -0000 1.2 --- RepayLoans.java 4 Feb 2009 20:36:40 -0000 1.3 *************** *** 15,19 **** * @author Erik Vos */ ! public class RepayLoans extends PossibleORAction { // Initial attributes --- 15,19 ---- * @author Erik Vos */ ! public class RepayLoans extends PossibleAction { // Initial attributes *************** *** 56,64 **** * @return Returns the company. */ - @Override public PublicCompanyI getCompany() { return company; } public int getPrice() { return price; --- 56,70 ---- * @return Returns the company. */ public PublicCompanyI getCompany() { return company; } + /** + * @return Returns the company. + */ + public String getCompanyName() { + return companyName; + } + public int getPrice() { return price; |
From: Erik V. <ev...@us...> - 2009-02-04 20:36:40
|
Update of /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4935/rails/ui/swing/gamespecific/_1856 Log Message: Directory /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856 added to the repository |
From: Erik V. <ev...@us...> - 2009-01-24 15:10:40
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8171/rails/game Modified Files: CompanyManagerI.java Portfolio.java PublicCompanyI.java CompanyManager.java OperatingRound.java CompanyType.java GameManagerI.java Game.java PublicCompany.java TrainManager.java GameManager.java Log Message: Minor changes, mainly about better integrating TrainManager and removing static access to it. Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Portfolio.java 15 Jan 2009 20:53:28 -0000 1.31 --- Portfolio.java 24 Jan 2009 15:10:26 -0000 1.32 *************** *** 493,501 **** } - public TrainI getTrainOfType(String name) { - - return getTrainOfType(TrainManager.get().getTypeByName(name)); - } - /** * Add a special property. Used to make special properties independent of --- 493,496 ---- Index: CompanyManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManager.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** CompanyManager.java 15 Jan 2009 20:53:28 -0000 1.13 --- CompanyManager.java 24 Jan 2009 15:10:27 -0000 1.14 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, HashMap<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, HashMap<String, CompanyI>>(); /** A list of all start packets (usually one) */ // TODO Currently not used (but some newer games have more than one) private List<StartPacket> startPackets = new ArrayList<StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); ((Map<String, CompanyI>) mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name"); if (name == null) name = "Initial"; String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); sp.configureFromXML(packetTag); } } /* Read and configure additional rules */ /* This part may move later to a GameRules or GameManager XML */ Tag rulesTag = tag.getChild("StockRoundRules"); if (rulesTag != null) { for (String ruleTagName : rulesTag.getChildren().keySet()) { if (ruleTagName.equals("NoSaleInFirstSR")) { StockRound.setNoSaleInFirstSR(); } else if (ruleTagName.equals("NoSaleIfNotOperated")) { StockRound.setNoSaleIfNotOperated(); } } } } // Post XML parsing initialisations public void initCompanies() throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.init2(); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.util.LocalText; import rails.util.Tag; public class CompanyManager implements CompanyManagerI, ConfigurableComponentI { /** A List with all private companies */ private List<PrivateCompanyI> lPrivateCompanies = new ArrayList<PrivateCompanyI>(); /** A List with all public companies */ private List<PublicCompanyI> lPublicCompanies = new ArrayList<PublicCompanyI>(); /** A map with all private companies by name */ private Map<String, PrivateCompanyI> mPrivateCompanies = new HashMap<String, PrivateCompanyI>(); /** A map with all public (i.e. non-private) companies by name */ private Map<String, PublicCompanyI> mPublicCompanies = new HashMap<String, PublicCompanyI>(); /** A map of all type names to maps of companies of that type by name */ // TODO Redundant, current usage can be replaced. private Map<String, HashMap<String, CompanyI>> mCompaniesByTypeAndName = new HashMap<String, HashMap<String, CompanyI>>(); /** A list of all start packets (usually one) */ // TODO Currently not used (but some newer games have more than one) private List<StartPacket> startPackets = new ArrayList<StartPacket>(); private int numberOfPublicCompanies = 0; protected static Logger log = Logger.getLogger(CompanyManager.class.getPackage().getName()); /* * NOTES: 1. we don't have a map over all companies, because some games have * duplicate names, e.g. B&O in 1830. 2. we have both a map and a list of * private/public companies to preserve configuration sequence while * allowing direct access. */ /** * No-args constructor. */ public CompanyManager() { // Nothing to do here, everything happens when configured. } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { /** A map with all company types, by type name */ // Localised here as it has no permanent use Map<String, CompanyTypeI> mCompanyTypes = new HashMap<String, CompanyTypeI>(); for (Tag compTypeTag : tag.getChildren(CompanyTypeI.ELEMENT_ID)) { // Extract the attributes of the Component String name = compTypeTag.getAttributeAsString(CompanyTypeI.NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompanyType")); } String className = compTypeTag.getAttributeAsString(CompanyTypeI.CLASS_TAG); if (className == null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeHasNoClass", name)); } if (mCompanyTypes.get(name) != null) { throw new ConfigurationException(LocalText.getText( "CompanyTypeConfiguredTwice", name)); } CompanyTypeI companyType = new CompanyType(name, className); mCompanyTypes.put(name, companyType); // Further parsing is done within CompanyType companyType.configureFromXML(compTypeTag); } /* Read and configure the companies */ for (Tag companyTag : tag.getChildren(CompanyI.COMPANY_ELEMENT_ID)) { // Extract the attributes of the Component String name = companyTag.getAttributeAsString(CompanyI.COMPANY_NAME_TAG); if (name == null) { throw new ConfigurationException( LocalText.getText("UnnamedCompany")); } String type = companyTag.getAttributeAsString(CompanyI.COMPANY_TYPE_TAG); if (type == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasNoType", name)); } CompanyTypeI cType = mCompanyTypes.get(type); if (cType == null) { throw new ConfigurationException(LocalText.getText( "CompanyHasUnknownType", name, type )); } try { CompanyI company = cType.createCompany(name, companyTag); /* Private or public */ if (company instanceof PrivateCompanyI) { mPrivateCompanies.put(name, (PrivateCompanyI) company); lPrivateCompanies.add((PrivateCompanyI) company); } else if (company instanceof PublicCompanyI) { ((PublicCompanyI)company).setIndex (numberOfPublicCompanies++); mPublicCompanies.put(name, (PublicCompanyI) company); lPublicCompanies.add((PublicCompanyI) company); } /* By type and name */ if (!mCompaniesByTypeAndName.containsKey(type)) mCompaniesByTypeAndName.put(type, new HashMap<String, CompanyI>()); ((Map<String, CompanyI>) mCompaniesByTypeAndName.get(type)).put( name, company); } catch (Exception e) { throw new ConfigurationException(LocalText.getText( "ClassCannotBeInstantiated", cType.getClassName()), e); } } /* Read and configure the start packets */ List<Tag> packetTags = tag.getChildren("StartPacket"); if (packetTags != null) { for (Tag packetTag : tag.getChildren("StartPacket")) { // Extract the attributes of the Component String name = packetTag.getAttributeAsString("name"); if (name == null) name = "Initial"; String roundClass = packetTag.getAttributeAsString("roundClass"); if (roundClass == null) { throw new ConfigurationException(LocalText.getText( "StartPacketHasNoClass", name)); } StartPacket sp = new StartPacket(name, roundClass); startPackets.add(sp); sp.configureFromXML(packetTag); } } /* Read and configure additional rules */ /* This part may move later to a GameRules or GameManager XML */ Tag rulesTag = tag.getChild("StockRoundRules"); if (rulesTag != null) { for (String ruleTagName : rulesTag.getChildren().keySet()) { if (ruleTagName.equals("NoSaleInFirstSR")) { StockRound.setNoSaleInFirstSR(); } else if (ruleTagName.equals("NoSaleIfNotOperated")) { StockRound.setNoSaleIfNotOperated(); } } } } // Post XML parsing initialisations public void initCompanies(GameManagerI gameManager) throws ConfigurationException { for (PublicCompanyI comp : lPublicCompanies) { comp.init2(gameManager); } } /** * @see rails.game.CompanyManagerI#getCompany(java.lang.String) * */ public PrivateCompanyI getPrivateCompany(String name) { return mPrivateCompanies.get(name); } public PublicCompanyI getPublicCompany(String name) { return mPublicCompanies.get(name); } public List<PrivateCompanyI> getAllPrivateCompanies() { return lPrivateCompanies; } public List<PublicCompanyI> getAllPublicCompanies() { return lPublicCompanies; } public PublicCompanyI getCompanyByName(String name) { for (int i = 0; i < lPublicCompanies.size(); i++) { PublicCompany co = (PublicCompany) lPublicCompanies.get(i); if (name.equalsIgnoreCase(co.getName())) { return lPublicCompanies.get(i); } } return null; } public CompanyI getCompany(String type, String name) { if (mCompaniesByTypeAndName.containsKey(type)) { return (mCompaniesByTypeAndName.get(type)).get(name); } else { return null; } } public void closeAllPrivates() { if (lPrivateCompanies == null) return; for (PrivateCompanyI priv : lPrivateCompanies) { priv.setClosed(); } } public List<PrivateCompanyI> getPrivatesOwnedByPlayers() { List<PrivateCompanyI> privatesOwnedByPlayers = new ArrayList<PrivateCompanyI>(); for (PrivateCompanyI priv : getAllPrivateCompanies()) { if (priv.getPortfolio().getOwner() instanceof Player) { privatesOwnedByPlayers.add(priv); } } return privatesOwnedByPlayers; } } \ No newline at end of file Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** PublicCompany.java 15 Jan 2009 20:53:28 -0000 1.47 --- PublicCompany.java 24 Jan 2009 15:10:28 -0000 1.48 *************** *** 226,229 **** --- 226,231 ---- protected int maxLoansPerRound = 0; protected MoneyModel currentLoanValue = null; + + protected GameManagerI gameManager; /** *************** *** 612,616 **** * Final initialisation, after all XML has been processed. */ ! public void init2() throws ConfigurationException { if (hasStockPrice && Util.hasValue(startSpace)) { parPrice.setPrice(StockMarket.getInstance().getStockSpace( --- 614,622 ---- * Final initialisation, after all XML has been processed. */ ! public void init2(GameManagerI gameManager) ! throws ConfigurationException { ! ! this.gameManager = gameManager; ! if (hasStockPrice && Util.hasValue(startSpace)) { parPrice.setPrice(StockMarket.getInstance().getStockSpace( *************** *** 827,833 **** if (initialTrain != null) { ! TrainI train = Bank.getIpo().getTrainOfType(initialTrain); buyTrain(train, 0); ! TrainManager.get().checkTrainAvailability(train, Bank.getIpo()); } } --- 833,841 ---- if (initialTrain != null) { ! TrainManagerI trainManager = gameManager.getTrainManager(); ! TrainTypeI type = trainManager.getTypeByName(initialTrain); ! TrainI train = Bank.getIpo().getTrainOfType(type); buyTrain(train, 0); ! trainManager.checkTrainAvailability(train, Bank.getIpo()); } } *************** *** 1595,1599 **** if (phaseMap == null || phaseMap.isEmpty()) return 1; ! PhaseI phase = PhaseManager.getInstance().getCurrentPhase(); Integer ii = phaseMap.get(phase.getName()); if (ii == null) return 1; --- 1603,1607 ---- if (phaseMap == null || phaseMap.isEmpty()) return 1; ! PhaseI phase = gameManager.getPhaseManager().getCurrentPhase(); Integer ii = phaseMap.get(phase.getName()); if (ii == null) return 1; Index: TrainManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManager.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TrainManager.java 4 Jun 2008 19:00:31 -0000 1.14 --- TrainManager.java 24 Jan 2009 15:10:29 -0000 1.15 *************** *** 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); } public static TrainManagerI get() { return instance; } /** * @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())); } } // 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.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** GameManager.java 21 Jan 2009 20:18:24 -0000 1.42 --- GameManager.java 24 Jan 2009 15:10:29 -0000 1.43 *************** *** 44,47 **** --- 44,48 ---- protected CompanyManagerI companyManager; protected PhaseManager phaseManager; + protected TrainManagerI trainManager; protected List<Player> players; *************** *** 294,301 **** public void startGame(PlayerManager playerManager, CompanyManagerI companyManager, ! PhaseManager phaseManager) { this.playerManager = playerManager; this.companyManager = companyManager; this.phaseManager = phaseManager; players = playerManager.getPlayers(); --- 295,304 ---- public void startGame(PlayerManager playerManager, CompanyManagerI companyManager, ! PhaseManager phaseManager, ! TrainManagerI trainManager) { this.playerManager = playerManager; this.companyManager = companyManager; this.phaseManager = phaseManager; + this.trainManager = trainManager; players = playerManager.getPlayers(); *************** *** 879,882 **** --- 882,889 ---- return phaseManager; } + + public TrainManagerI getTrainManager () { + return trainManager; + } // TODO Should be removed Index: CompanyType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyType.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CompanyType.java 15 Jan 2009 20:53:28 -0000 1.7 --- CompanyType.java 24 Jan 2009 15:10:28 -0000 1.8 *************** *** 23,27 **** private CompanyI dummyCompany; ! /** * The constructor. --- 23,27 ---- private CompanyI dummyCompany; ! /** * The constructor. *************** *** 60,65 **** } ! ! public CompanyI createCompany(String name, Tag tag) throws ConfigurationException { CompanyI newCompany = null; --- 60,65 ---- } ! ! public CompanyI createCompany(String name, Tag tag) throws ConfigurationException { CompanyI newCompany = null; Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Game.java 23 Dec 2008 19:50:41 -0000 1.20 --- Game.java 24 Jan 2009 15:10:28 -0000 1.21 *************** *** 27,30 **** --- 27,31 ---- protected PlayerManager playerManager; protected PhaseManager phaseManager; + protected TrainManagerI trainManager; protected StockMarketI stockMarket; protected Bank bank; *************** *** 65,69 **** public void start() { ! gameManager.startGame(playerManager, companyManager, phaseManager); } --- 66,71 ---- public void start() { ! gameManager.startGame(playerManager, companyManager, ! phaseManager, trainManager); } *************** *** 129,132 **** --- 131,142 ---- } + trainManager = + (TrainManager) componentManager.findComponent("TrainManager"); + if (trainManager == null) { + throw new ConfigurationException( + "No TrainManager XML element found in file " + + GAME_XML_FILE); + } + /* * Initialisations that involve relations between components can *************** *** 135,139 **** bank.initCertificates(); StartPacket.init(); ! companyManager.initCompanies(); stockMarket.init(); } catch (Exception e) { --- 145,149 ---- bank.initCertificates(); StartPacket.init(); ! companyManager.initCompanies(gameManager); stockMarket.init(); } catch (Exception e) { Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** PublicCompanyI.java 11 Jan 2009 17:24:46 -0000 1.27 --- PublicCompanyI.java 24 Jan 2009 15:10:26 -0000 1.28 *************** *** 18,22 **** public static final int CAPITALISE_WHEN_BOUGHT = 2; ! public void init2() throws ConfigurationException; public void setIndex (int index); --- 18,22 ---- public static final int CAPITALISE_WHEN_BOUGHT = 2; ! public void init2(GameManagerI gameManager) throws ConfigurationException; public void setIndex (int index); Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** OperatingRound.java 21 Jan 2009 20:18:23 -0000 1.53 --- OperatingRound.java 24 Jan 2009 15:10:27 -0000 1.54 *************** *** 107,110 **** --- 107,112 ---- protected boolean doneAllowed = false; + + protected TrainManagerI trainManager = gameManager.getTrainManager(); public static String[] stepNames = *************** *** 1347,1351 **** // Check if the phase has changed. ! TrainManager.get().checkTrainAvailability(train, oldHolder); currentPhase = getCurrentPhase(); --- 1349,1353 ---- // Check if the phase has changed. ! gameManager.getTrainManager().checkTrainAvailability(train, oldHolder); currentPhase = getCurrentPhase(); *************** *** 1941,1945 **** if (operatingCompany == null) return; ! TrainManagerI trainMgr = TrainManager.get(); int cash = operatingCompany.getCash(); --- 1943,1947 ---- if (operatingCompany == null) return; ! TrainManagerI trainMgr = gameManager.getTrainManager(); int cash = operatingCompany.getCash(); Index: CompanyManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/CompanyManagerI.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CompanyManagerI.java 3 Dec 2008 20:15:15 -0000 1.10 --- CompanyManagerI.java 24 Jan 2009 15:10:26 -0000 1.11 *************** *** 58,62 **** /** Post XML parsing initialisations */ ! public void initCompanies() throws ConfigurationException; public void closeAllPrivates(); --- 58,62 ---- /** Post XML parsing initialisations */ ! public void initCompanies(GameManagerI gameManager) throws ConfigurationException; public void closeAllPrivates(); Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GameManagerI.java 23 Dec 2008 19:50:41 -0000 1.1 --- GameManagerI.java 24 Jan 2009 15:10:28 -0000 1.2 *************** *** 16,20 **** public abstract void startGame(PlayerManager playerManager, ! CompanyManagerI companyManager, PhaseManager phaseManager); public abstract CompanyManagerI getCompanyManager(); --- 16,21 ---- public abstract void startGame(PlayerManager playerManager, ! CompanyManagerI companyManager, PhaseManager phaseManager, ! TrainManagerI trainManager); public abstract CompanyManagerI getCompanyManager(); *************** *** 141,144 **** --- 142,148 ---- public abstract PhaseManager getPhaseManager(); + + public abstract TrainManagerI getTrainManager (); + public abstract String getHelp(); |
From: Erik V. <ev...@us...> - 2009-01-24 15:10:40
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8171/rails/game/specific/_18EU Modified Files: OperatingRound_18EU.java Log Message: Minor changes, mainly about better integrating TrainManager and removing static access to it. Index: OperatingRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OperatingRound_18EU.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OperatingRound_18EU.java 23 Dec 2008 20:02:18 -0000 1.5 --- OperatingRound_18EU.java 24 Jan 2009 15:10:29 -0000 1.6 *************** *** 15,18 **** --- 15,20 ---- */ public class OperatingRound_18EU extends OperatingRound { + + protected TrainTypeI pullmannType; protected BooleanState hasPullmannAtStart = *************** *** 24,27 **** --- 26,30 ---- public OperatingRound_18EU (GameManagerI gameManager) { super (gameManager); + pullmannType = trainManager.getTypeByName("P"); } *************** *** 29,34 **** protected void initTurn() { super.initTurn(); ! hasPullmannAtStart.set(operatingCompany.getPortfolio().getTrainOfType( ! "P") != null); } --- 32,37 ---- protected void initTurn() { super.initTurn(); ! hasPullmannAtStart.set(operatingCompany.getPortfolio() ! .getTrainOfType(pullmannType) != null); } *************** *** 41,45 **** if (operatingCompany == null) return; ! TrainManagerI trainMgr = TrainManager.get(); int cash = operatingCompany.getCash(); --- 44,48 ---- if (operatingCompany == null) return; ! TrainManagerI trainMgr = gameManager.getTrainManager(); int cash = operatingCompany.getCash(); *************** *** 61,65 **** TrainI ownedPTrain = null; if (hasTrains) { ! ownedPTrain = operatingCompany.getPortfolio().getTrainOfType("P"); } --- 64,68 ---- TrainI ownedPTrain = null; if (hasTrains) { ! ownedPTrain = operatingCompany.getPortfolio().getTrainOfType(pullmannType); } *************** *** 164,168 **** protected boolean canBuyTrain() { return super.canBuyTrain() ! || operatingCompany.getPortfolio().getTrainOfType("P") != null && hasPullmannAtStart.booleanValue(); } --- 167,171 ---- protected boolean canBuyTrain() { return super.canBuyTrain() ! || operatingCompany.getPortfolio().getTrainOfType(pullmannType) != null && hasPullmannAtStart.booleanValue(); } *************** *** 201,205 **** // Check if the company has a Pullmann ! pullmann = portfolio.getTrainOfType("P"); // A Pullmann always goes first, and automatically. --- 204,208 ---- // Check if the company has a Pullmann ! pullmann = portfolio.getTrainOfType(pullmannType); // A Pullmann always goes first, and automatically. |
From: Erik V. <ev...@us...> - 2009-01-24 15:10:34
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8171/rails/game/specific/_1856 Modified Files: PublicCompany_1856.java Log Message: Minor changes, mainly about better integrating TrainManager and removing static access to it. Index: PublicCompany_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_1856.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PublicCompany_1856.java 20 Nov 2008 21:49:38 -0000 1.1 --- PublicCompany_1856.java 24 Jan 2009 15:10:29 -0000 1.2 *************** *** 4,8 **** import rails.game.StockSpaceI; import rails.game.TrainI; - import rails.game.TrainManager; import rails.game.state.IntegerState; --- 4,7 ---- *************** *** 17,21 **** super.start(startSpace); ! TrainI nextAvailableTrain = TrainManager.get().getAvailableNewTrains().get(0); int trainNumber; try { --- 16,21 ---- super.start(startSpace); ! TrainI nextAvailableTrain ! = gameManager.getTrainManager().getAvailableNewTrains().get(0); int trainNumber; try { |
From: Erik V. <ev...@us...> - 2009-01-24 15:09:27
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8115/rails/game/specific/_1856 Modified Files: OperatingRound_1856.java Log Message: Preparations for final loan repayment Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** OperatingRound_1856.java 21 Jan 2009 20:18:24 -0000 1.6 --- OperatingRound_1856.java 24 Jan 2009 15:09:14 -0000 1.7 *************** *** 7,14 **** --- 7,19 ---- import rails.game.action.*; import rails.game.move.CashMove; + import rails.game.state.BooleanState; import rails.game.state.IntegerState; import rails.util.LocalText; public class OperatingRound_1856 extends OperatingRound { + + BooleanState finalLoanRepaymentPending + = new BooleanState ("LoanRepaymentPending", false); + Player playerToStartLoanRepayment = null; public static final int STEP_REPAY_LOANS = 6; *************** *** 64,68 **** = 100 - operatingCompany.getUnsoldPercentage(); ! TrainI nextAvailableTrain = TrainManager.get().getAvailableNewTrains().get(0); int trainNumber; try { --- 69,73 ---- = 100 - operatingCompany.getUnsoldPercentage(); ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); int trainNumber; try { *************** *** 324,327 **** --- 329,350 ---- } } + + public boolean buyTrain(BuyTrain action) { + + PhaseI prePhase = currentPhase; + + boolean result = super.buyTrain(action); + + PhaseI postPhase = currentPhase; + + if (postPhase != prePhase && postPhase.getName().equals("5")) { + finalLoanRepaymentPending.set(true); + playerToStartLoanRepayment + = gameManager.getPlayerByIndex(action.getPlayerIndex()); + } + + return result; + } + @Override *************** *** 402,405 **** --- 425,451 ---- } + + protected void finishTurn() { + + operatingCompany.setOperated(true); + + // Check if any privates must be closed + // (now only applies to 1856 W&SR) + for (PrivateCompanyI priv : operatingCompany.getPortfolio().getPrivateCompanies()) { + priv.checkClosingIfExercised(true); + } + + if (finalLoanRepaymentPending.booleanValue()) { + // Must start final loan repayment and CGR formation + // TODO + } + + if (setNextOperatingCompany(false)) { + setStep(STEP_INITIAL); + } else { + finishOR(); + } + } + } |
From: Erik V. <ev...@us...> - 2009-01-21 20:18:36
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv26428/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: Added 1856 loan repayment step at end of OR. Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** ORUIManager.java 15 Jan 2009 20:53:28 -0000 1.25 --- ORUIManager.java 21 Jan 2009 20:18:23 -0000 1.26 *************** *** 345,348 **** --- 345,352 ---- takeLoans ((TakeLoans)actions.get(0)); + + } else if (actionType == RepayLoans.class) { + + repayLoans ((RepayLoans)actions.get(0)); } *************** *** 1051,1056 **** } ! protected void repayLoans () { } --- 1055,1098 ---- } ! protected void repayLoans (RepayLoans action) { ! ! int minNumber = action.getMinNumber(); ! int maxNumber = action.getMaxNumber(); ! int loanAmount = action.getPrice(); ! int numberRepaid = 0; + if (minNumber == maxNumber) { + // No choice, just tell him + JOptionPane.showMessageDialog (orWindow, + LocalText.getText("RepayLoan", + minNumber, + Bank.format(loanAmount), + Bank.format(minNumber * loanAmount))); + numberRepaid = minNumber; + } else { + List<String> options = new ArrayList<String>(); + for (int i=minNumber; i<=maxNumber; i++) { + if (i == 0) { + options.add(LocalText.getText("None")); + } else { + options.add(LocalText.getText("RepayLoan", + i, + Bank.format(loanAmount), + Bank.format(i * loanAmount))); + } + } + Object choice = JOptionPane.showInputDialog(orWindow, + LocalText.getText("SelectLoansToRepay"), + LocalText.getText("Select"), + JOptionPane.QUESTION_MESSAGE, + null, + options.toArray(), + options.get(minNumber == 0 ? 1 : minNumber)); + + numberRepaid = minNumber + options.indexOf(choice); + + } + action.setNumberTaken(numberRepaid); + orWindow.process(action); } *************** *** 1147,1156 **** setMessage(message); ! } else if (possibleActions.contains(BuyTrain.class)/* ! * || ! * possibleActions.contains(DiscardTrain.class) ! */) { - // orPanel.initTrainBuying(oRound.getOperatingCompany().mayBuyTrains()); orPanel.initTrainBuying(true); --- 1189,1194 ---- setMessage(message); ! } else if (possibleActions.contains(BuyTrain.class)) { orPanel.initTrainBuying(true); *************** *** 1159,1167 **** } else if (possibleActions.contains(DiscardTrain.class)) { - // discardTrain(); ! } else if (possibleActions.contains(TakeLoans.class)) { ! orPanel.enableLoanTaking (possibleActions.getType(TakeLoans.class).get(0)); } else if (orStep == OperatingRound.STEP_FINAL) { --- 1197,1204 ---- } else if (possibleActions.contains(DiscardTrain.class)) { ! } else if (possibleActions.contains(RepayLoans.class)) { ! orPanel.enableLoanRepayment (possibleActions.getType(RepayLoans.class).get(0)); } else if (orStep == OperatingRound.STEP_FINAL) { Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** ORPanel.java 11 Jan 2009 17:24:46 -0000 1.28 --- ORPanel.java 21 Jan 2009 20:18:23 -0000 1.29 *************** *** 724,727 **** --- 724,742 ---- takeLoans.setEnabled(action != null); } + + public void enableLoanRepayment (RepayLoans action) { + + repayLoans.setPossibleAction(action); + repayLoans.setEnabled(true); + + loansCaption.setHighlight(true); + + button1.setText(LocalText.getText("RepayLoans")); + button1.setActionCommand(REPAY_LOANS_CMD); + button1.setPossibleAction(action); + button1.setMnemonic(KeyEvent.VK_R); + button1.setEnabled(true); + button1.setVisible(true); + } public void finishORCompanyTurn(int orCompIndex) { |
From: Erik V. <ev...@us...> - 2009-01-21 20:18:36
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv26428/rails/game/specific/_1856 Modified Files: OperatingRound_1856.java Log Message: Added 1856 loan repayment step at end of OR. Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** OperatingRound_1856.java 14 Jan 2009 20:45:07 -0000 1.5 --- OperatingRound_1856.java 21 Jan 2009 20:18:24 -0000 1.6 *************** *** 12,15 **** --- 12,30 ---- public class OperatingRound_1856 extends OperatingRound { + public static final int STEP_REPAY_LOANS = 6; + + static { + STEP_FINAL = 7; + + steps = + new int[] { STEP_LAY_TRACK, STEP_LAY_TOKEN, STEP_CALC_REVENUE, + STEP_PAYOUT, STEP_BUY_TRAIN, STEP_TRADE_SHARES, + STEP_REPAY_LOANS, STEP_FINAL }; + + stepNames = + new String[] { "LayTrack", "LayToken", "EnterRevenue", "Payout", + "BuyTrain", "TradeShares", "RepayLoans", "Final" }; + } + public OperatingRound_1856 (GameManagerI gameManager) { super (gameManager); *************** *** 274,277 **** --- 289,326 ---- 1, operatingCompany.getValuePerLoan())); } + + if (getStep() == STEP_REPAY_LOANS) { + // Has company any outstanding loans to repay? + if (operatingCompany.getMaxNumberOfLoans() != 0 + && operatingCompany.getCurrentNumberOfLoans() > 0) { + + // Minimum number to repay + int minNumber = Math.max(0, + operatingCompany.getCurrentNumberOfLoans() + - operatingCompany.sharesOwnedByPlayers()); + // Maximum number to repay (dependent on cash) + int maxNumber = Math.min(operatingCompany.getCurrentNumberOfLoans(), + operatingCompany.getCash() / operatingCompany.getValuePerLoan()); + + if (maxNumber < minNumber) { + // Company doesn't have the cash, president must contribute. + maxNumber = minNumber; + } + + if (minNumber > 0) { + // Mandatory repayment + DisplayBuffer.add(LocalText.getText("MustRepayLoans", + operatingCompany.getName(), + minNumber, + Bank.format(operatingCompany.getValuePerLoan()), + Bank.format(minNumber * operatingCompany.getValuePerLoan()))); + } + possibleActions.add(new RepayLoans(operatingCompany, + minNumber, maxNumber, operatingCompany.getValuePerLoan())); + + // Step may only be skipped if repayment is optional + if (minNumber == 0) doneAllowed = true; + } + } } *************** *** 325,327 **** --- 374,405 ---- * operatingCompany.getLoanInterestPct() / 100; } + + @Override + protected boolean gameSpecificNextStep (int step) { + + if (step == STEP_REPAY_LOANS) { + + // Has company any outstanding loans to repay? + if (operatingCompany.getMaxNumberOfLoans() == 0 + || operatingCompany.getCurrentNumberOfLoans() == 0) { + return false; + // Is company required to repay loans? + } else if (operatingCompany.sharesOwnedByPlayers() + < operatingCompany.getCurrentNumberOfLoans()) { + return true; + // Has company enough money to repay at least one loan? + } else if (operatingCompany.getCash() + < operatingCompany.getValuePerLoan()) { + return false; + } else { + // Loan repayment is possible but optional + return true; + } + } else { + // We are not in this step + return true; + } + + } + } |