From: <ev...@us...> - 2011-06-09 22:05:34
|
Revision: 1572 http://rails.svn.sourceforge.net/rails/?rev=1572&view=rev Author: evos Date: 2011-06-09 22:05:28 +0000 (Thu, 09 Jun 2011) Log Message: ----------- Implemented train rusting on buying another than the first train of a type (for 18TN). Modified Paths: -------------- trunk/18xx/data/18TN/Game.xml trunk/18xx/rails/game/TrainManager.java trunk/18xx/rails/game/TrainType.java trunk/18xx/rails/game/TrainTypeI.java Modified: trunk/18xx/data/18TN/Game.xml =================================================================== --- trunk/18xx/data/18TN/Game.xml 2011-06-09 22:04:33 UTC (rev 1571) +++ trunk/18xx/data/18TN/Game.xml 2011-06-09 22:05:28 UTC (rev 1572) @@ -72,7 +72,9 @@ rustedTrain="2" /> <Train name="5" majorStops="5" cost="450" quantity="2" startPhase="5"/> <Train name="6" majorStops="6" cost="630" quantity="2" startPhase="6" - rustedTrain="3" /> + rustedTrain="3"> + <Sub index="2" rustedTrain="4"/> + </Train> <Train name="8" majorStops="8" cost="700" quantity="7" startPhase="8" rustedTrain="4" /> </Component> Modified: trunk/18xx/rails/game/TrainManager.java =================================================================== --- trunk/18xx/rails/game/TrainManager.java 2011-06-09 22:04:33 UTC (rev 1571) +++ trunk/18xx/rails/game/TrainManager.java 2011-06-09 22:05:28 UTC (rev 1572) @@ -91,6 +91,8 @@ } // Finish initialisation of the train types + Map<Integer, String> rustedTrainTypeNames; + TrainTypeI rustedType; for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeNames() != null) { List<TrainTypeI> rtts = new ArrayList<TrainTypeI>(2); @@ -99,9 +101,13 @@ } type.setReleasedTrainTypes(rtts); } - if (type.getRustedTrainTypeName() != null) { - type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); - mTrainTypes.get(type.getRustedTrainTypeName()).setPermanent(false); + rustedTrainTypeNames = type.getRustedTrainTypeNames(); + if (rustedTrainTypeNames != null) { + for (int index : rustedTrainTypeNames.keySet()) { + rustedType = mTrainTypes.get(rustedTrainTypeNames.get(index)); + type.setRustedTrainType(index, rustedType); + rustedType.setPermanent(false); + } } } @@ -176,7 +182,9 @@ } } } - if (boughtType.getNumberBoughtFromIPO() == 1) { + + int trainIndex = boughtType.getNumberBoughtFromIPO(); + if (trainIndex == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); @@ -187,21 +195,6 @@ phaseHasChanged = true; } - TrainTypeI rustedType = boughtType.getRustedTrainType(); - if (rustedType != null && !rustedType.hasRusted()) { - rustedType.setRusted(train.getHolder()); // Or obsolete, - // where applicable - if (rustedType.isObsoleting()) { - ReportBuffer.add(LocalText.getText("TrainsObsolete", - rustedType.getName())); - } else { - ReportBuffer.add(LocalText.getText("TrainsRusted", - rustedType.getName())); - } - trainsHaveRusted = true; - trainAvailabilityChanged = true; - } - List<TrainTypeI> releasedTypes = boughtType.getReleasedTrainTypes(); if (releasedTypes != null) { for (TrainTypeI releasedType : releasedTypes) { @@ -214,8 +207,24 @@ trainAvailabilityChanged = true; } } - } + TrainTypeI rustedType = boughtType.getRustedTrainType(trainIndex); + if (rustedType != null && !rustedType.hasRusted()) { + rustedType.setRusted(train.getHolder()); // Or obsolete, + // where applicable + if (rustedType.isObsoleting()) { + ReportBuffer.add(LocalText.getText("TrainsObsolete", + rustedType.getName())); + } else { + ReportBuffer.add(LocalText.getText("TrainsRusted", + rustedType.getName())); + } + trainsHaveRusted = true; + trainAvailabilityChanged = true; + } + +} + public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); Modified: trunk/18xx/rails/game/TrainType.java =================================================================== --- trunk/18xx/rails/game/TrainType.java 2011-06-09 22:04:33 UTC (rev 1571) +++ trunk/18xx/rails/game/TrainType.java 2011-06-09 22:05:28 UTC (rev 1572) @@ -1,8 +1,7 @@ /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/TrainType.java,v 1.32 2010/05/11 21:47:21 stefanfrey Exp $ */ package rails.game; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import org.apache.log4j.Logger; @@ -11,8 +10,7 @@ import rails.game.state.IntegerState; import rails.util.*; -public class TrainType -implements TrainTypeI { +public class TrainType implements TrainTypeI { public final static int TOWN_COUNT_MAJOR = 2; public final static int TOWN_COUNT_MINOR = 1; @@ -58,8 +56,8 @@ protected String startedPhaseName = null; // Phase startedPhase; - private String rustedTrainTypeName = null; - protected TrainTypeI rustedTrainType = null; + private Map<Integer, String> rustedTrainTypeNames = null; + protected Map<Integer, TrainTypeI> rustedTrainType = null; private String releasedTrainTypeNames = null; protected List<TrainTypeI> releasedTrainTypes = null; @@ -141,7 +139,11 @@ startedPhaseName = tag.getAttributeAsString("startPhase", ""); // Train type rusted - rustedTrainTypeName = tag.getAttributeAsString("rustedTrain"); + String rustedTrainTypeName1 = tag.getAttributeAsString("rustedTrain"); + if (Util.hasValue(rustedTrainTypeName1)) { + rustedTrainTypeNames = new HashMap<Integer, String>(); + rustedTrainTypeNames.put(1, rustedTrainTypeName1); + } // Other train type released for buying releasedTrainTypeNames = tag.getAttributeAsString("releasedTrain"); @@ -153,6 +155,19 @@ initialPortfolio = tag.getAttributeAsString("initialPortfolio", initialPortfolio); + + // Configure any actions on other than the first train of a type + List<Tag> subs = tag.getChildren("Sub"); + if (subs != null) { + for (Tag sub : tag.getChildren("Sub")) { + int index = sub.getAttributeAsInteger("index"); + rustedTrainTypeName1 = sub.getAttributeAsString("rustedTrain"); + if (rustedTrainTypeNames == null) { + rustedTrainTypeNames = new HashMap<Integer, String>(); + } + rustedTrainTypeNames.put(index, rustedTrainTypeName1); + } + } } else { name = ""; quantity = 0; @@ -343,8 +358,9 @@ /** * @return Returns the rustedTrainType. */ - public TrainTypeI getRustedTrainType() { - return rustedTrainType; + public TrainTypeI getRustedTrainType(int index) { + if (rustedTrainType == null) return null; + return rustedTrainType.get(index); } /** @@ -378,8 +394,8 @@ /** * @return Returns the rustedTrainTypeName. */ - public String getRustedTrainTypeName() { - return rustedTrainTypeName; + public Map<Integer,String> getRustedTrainTypeNames() { + return rustedTrainTypeNames; } public boolean isObsoleting() { @@ -396,8 +412,11 @@ /** * @param rustedTrainType The rustedTrainType to set. */ - public void setRustedTrainType(TrainTypeI rustedTrainType) { - this.rustedTrainType = rustedTrainType; + public void setRustedTrainType(int index, TrainTypeI rustedTrainType) { + if (this.rustedTrainType == null) { + this.rustedTrainType = new HashMap<Integer, TrainTypeI>(); + } + this.rustedTrainType.put(index, rustedTrainType); } public boolean isPermanent() { @@ -485,8 +504,9 @@ if (Util.hasValue(startedPhaseName)) { appendInfoText(b, LocalText.getText("StartsPhase", startedPhaseName)); } - if (rustedTrainTypeName != null) { - appendInfoText(b, LocalText.getText("RustsTrains", rustedTrainTypeName)); + if (rustedTrainTypeNames != null) { + appendInfoText(b, LocalText.getText("RustsTrains", rustedTrainTypeNames.get(1))); + // Ignore any 'Sub' cases for now } if (releasedTrainTypeNames != null) { appendInfoText(b, LocalText.getText("ReleasesTrains", releasedTrainTypeNames)); Modified: trunk/18xx/rails/game/TrainTypeI.java =================================================================== --- trunk/18xx/rails/game/TrainTypeI.java 2011-06-09 22:04:33 UTC (rev 1571) +++ trunk/18xx/rails/game/TrainTypeI.java 2011-06-09 22:05:28 UTC (rev 1572) @@ -2,6 +2,7 @@ package rails.game; import java.util.List; +import java.util.Map; public interface TrainTypeI extends ConfigurableComponentI, Cloneable { @@ -58,7 +59,7 @@ /** * @return Returns the rustedTrainType. */ - public TrainTypeI getRustedTrainType(); + public TrainTypeI getRustedTrainType(int index); /** * @return Returns the startedPhaseName. @@ -95,7 +96,7 @@ public String getReleasedTrainTypeNames(); - public String getRustedTrainTypeName(); + public Map<Integer,String> getRustedTrainTypeNames(); public boolean isPermanent(); @@ -103,7 +104,7 @@ public void setReleasedTrainTypes(List<TrainTypeI> releasedTrainTypes); - public void setRustedTrainType(TrainTypeI rustedTrainType); + public void setRustedTrainType(int index, TrainTypeI rustedTrainType); public TrainI cloneTrain(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |