From: <ev...@us...> - 2011-07-06 13:13:56
|
Revision: 1606 http://rails.svn.sourceforge.net/rails/?rev=1606&view=rev Author: evos Date: 2011-07-06 13:13:50 +0000 (Wed, 06 Jul 2011) Log Message: ----------- Phase management step 1: added <NewPhase> tag to 18TN. Added phases 3?\194?\189 and 6?\194?\189. Fixed incorrect 2- and 3-train obsolescence for 18TN. Modified Paths: -------------- trunk/18xx/data/18TN/CompanyManager.xml trunk/18xx/data/18TN/Game.xml trunk/18xx/rails/game/TrainCertificateType.java trunk/18xx/rails/game/TrainManager.java Modified: trunk/18xx/data/18TN/CompanyManager.xml =================================================================== --- trunk/18xx/data/18TN/CompanyManager.xml 2011-07-06 05:39:16 UTC (rev 1605) +++ trunk/18xx/data/18TN/CompanyManager.xml 2011-07-06 13:13:50 UTC (rev 1606) @@ -13,17 +13,15 @@ <Float percentage="60"/> <ShareUnit percentage="10"/> <BaseTokens> - <!-- HomeBase lay options: "whenStarted", "whenFloated", "firstOR" (default) --> <HomeBase lay="firstOR"/> - <!-- LayCost methods: only "sequence" (1830 style) implemented so far (default) --> <LayCost method="sequence" cost="0,40,100"/> </BaseTokens> <Certificate type="President" shares="2"/> <Certificate shares="1" number="8"/> - <Trains limit="4,4,3,2"/> + <Trains limit="4,4,4,3,2"/> <CanUseSpecialProperties/> <TileLays> - <Number colour="yellow" phase="3,4,5,6,8" number="2"/> + <Number colour="yellow" phase="3,3½,4,5,6,6½,8" number="2"/> </TileLays> </CompanyType> Modified: trunk/18xx/data/18TN/Game.xml =================================================================== --- trunk/18xx/data/18TN/Game.xml 2011-07-06 05:39:16 UTC (rev 1605) +++ trunk/18xx/data/18TN/Game.xml 2011-07-06 13:13:50 UTC (rev 1606) @@ -66,6 +66,7 @@ cities="double" if city-revenue is doubled (e.g. 1826 TGV). --> </Defaults> + <!-- <TrainType name="2" majorStops="2" cost="80" quantity="5" obsoleting="yes"/> <TrainType name="3" majorStops="3" cost="180" quantity="5" obsoleting="yes" startPhase="3"/> <TrainType name="4" majorStops="4" cost="300" quantity="3" obsoleting="yes" startPhase="4" @@ -77,6 +78,27 @@ </TrainType> <TrainType name="8" majorStops="8" cost="700" quantity="7" startPhase="8" rustedTrain="4" /> + --> + <TrainType name="2" majorStops="2" cost="80" quantity="5"/> + <TrainType name="3" majorStops="3" cost="180" quantity="5"> + <NewPhase phaseName="3"/> + <NewPhase phaseName="3½" trainIndex="4"/> + </TrainType> + <TrainType name="4" majorStops="4" cost="300" quantity="3" obsoleting="yes" + rustedTrain="2"> + <NewPhase phaseName="4"/> + </TrainType> + <TrainType name="5" majorStops="5" cost="450" quantity="2"> + <NewPhase phaseName="5"/> + </TrainType> + <TrainType name="6" majorStops="6" cost="630" quantity="2" rustedTrain="3"> + <NewPhase phaseName="6"/> + <NewPhase phaseName="6½" trainIndex="2"/> + <Sub index="2" rustedTrain="4"/> + </TrainType> + <TrainType name="8" majorStops="8" cost="700" quantity="7" rustedTrain="4"> + <NewPhase phaseName="8"/> + </TrainType> </Component> <Component name="PhaseManager" class="rails.game.PhaseManager"> <!-- Note: released and rusted trains are now specified per TrainType @@ -93,6 +115,9 @@ <Privates sellingAllowed="yes"/> <OperatingRounds number="2"/> </Phase> + <Phase name="3½"> + <Tiles colour="yellow,green"/> + </Phase> <Phase name="4"> <Tiles colour="yellow,green"/> </Phase> @@ -105,6 +130,9 @@ <Phase name="6"> <Tiles colour="yellow,green,brown"/> </Phase> + <Phase name="6½"> + <Tiles colour="yellow,green,brown"/> + </Phase> <Phase name="8"> <Tiles colour="yellow,green,brown"/> </Phase> Modified: trunk/18xx/rails/game/TrainCertificateType.java =================================================================== --- trunk/18xx/rails/game/TrainCertificateType.java 2011-07-06 05:39:16 UTC (rev 1605) +++ trunk/18xx/rails/game/TrainCertificateType.java 2011-07-06 13:13:50 UTC (rev 1606) @@ -22,6 +22,8 @@ protected List<TrainType> potentialTrainTypes = new ArrayList<TrainType>(2); + protected Map<Integer, String> newPhaseNames; + protected Map<Integer, String> rustedTrainTypeNames = null; protected Map<Integer, TrainCertificateType> rustedTrainType = null; @@ -38,9 +40,6 @@ protected String trainClassName = "rails.game.Train"; protected Class<? extends Train> trainClass; - - protected int lastIndex = 0; - // State variables protected IntegerState numberBoughtFromIPO; protected BooleanState available; @@ -99,12 +98,28 @@ 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); + if (rustedTrainTypeNames == null) { + rustedTrainTypeNames = new HashMap<Integer, String>(); } + rustedTrainTypeNames.put(index, rustedTrainTypeName1); } + } + + // New style phase changes (to replace 'startPhase' attribute and <Sub> tag) + List<Tag> newPhaseTags = tag.getChildren("NewPhase"); + if (newPhaseTags != null) { + int index; + String phaseName; + newPhaseNames = new HashMap<Integer, String>(); + for (Tag newPhaseTag : newPhaseTags) { + phaseName = newPhaseTag.getAttributeAsString("phaseName"); + if (!Util.hasValue(phaseName)) { + throw new ConfigurationException ("TrainType "+name+" has NewPhase without phase name"); + } + index = newPhaseTag.getAttributeAsInteger("trainIndex", 1); + newPhaseNames.put(index, phaseName); + } + } // Exchangeable Tag swapTag = tag.getChild("Exchange"); @@ -139,6 +154,10 @@ } } + public Map<Integer, String> getNewPhaseNames() { + return newPhaseNames; + } + public TrainI createTrain () throws ConfigurationException { TrainI train; Modified: trunk/18xx/rails/game/TrainManager.java =================================================================== --- trunk/18xx/rails/game/TrainManager.java 2011-07-06 05:39:16 UTC (rev 1605) +++ trunk/18xx/rails/game/TrainManager.java 2011-07-06 13:13:50 UTC (rev 1606) @@ -54,6 +54,10 @@ /** Required for the sell-train-to-foreigners feature of some games */ protected BooleanState anyTrainBought = new BooleanState ("AnyTrainBought", false); + + // Triggered phase changes + protected Map<TrainCertificateType, Map<Integer, Phase>> newPhases + = new HashMap<TrainCertificateType, Map<Integer, Phase>>(); // Non-game attributes protected Portfolio ipo, pool, unavailable; @@ -167,6 +171,11 @@ } } + Map<Integer, String> newPhaseNames; + Phase phase; + String phaseName; + PhaseManager phaseManager = gameManager.getPhaseManager(); + for (TrainCertificateType certType : trainCertTypes) { certType.finishConfiguration(gameManager); @@ -189,6 +198,20 @@ addTrain(train); unavailable.addTrain(train); } + + // Register any phase changes + newPhaseNames = certType.getNewPhaseNames(); + if (newPhaseNames != null && !newPhaseNames.isEmpty()) { + for (int index : newPhaseNames.keySet()) { + phaseName = newPhaseNames.get(index); + phase = (Phase)phaseManager.getPhaseByName(phaseName); + if (phase == null) { + throw new ConfigurationException ("New phase '"+phaseName+"' does not exist"); + } + if (newPhases.get(certType) == null) newPhases.put(certType, new HashMap<Integer, Phase>()); + newPhases.get(certType).put(index, phase); + } + } } @@ -301,6 +324,14 @@ trainAvailabilityChanged = true; } } + + // New style phase changes, can be triggered by any bought train. + Phase newPhase; + if (newPhases.get(boughtType) != null + && (newPhase = newPhases.get(boughtType).get(trainIndex)) != null) { + gameManager.getPhaseManager().setPhase(newPhase); + phaseHasChanged = true; + } TrainCertificateType rustedType = boughtType.getRustedTrainType(trainIndex); if (rustedType != null && !rustedType.hasRusted()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |