From: Erik V. <ev...@us...> - 2011-07-22 20:16:00
|
data/1835/CompanyManager.xml | 6 +- data/1835/Game.xml | 50 +++++++++++------- data/1856/CompanyManager.xml | 2 rails/game/OperatingRound.java | 2 rails/game/Phase.java | 46 +++++++++++++++- rails/game/PhaseI.java | 3 - rails/game/PhaseManager.java | 18 ++++++ rails/game/PublicCompany.java | 15 ++++- rails/game/PublicCompanyI.java | 2 rails/game/specific/_1835/PrussianFormationRound.java | 4 - rails/game/specific/_18EU/OperatingRound_18EU.java | 4 - 11 files changed, 115 insertions(+), 37 deletions(-) New commits: commit 90f886aa199ed3b38c6ba276e17ced45be9345f5 Author: Erik Vos <eri...@xs...> Date: Fri Jul 22 22:07:40 2011 +0200 Phase management upgrade step 3: train limits. <Phase><Trains> now has a new attribute 'limitStep', which starts at 1. <Company[Type]><Trains> now lists the number of trains per step, not per phase. These changes have been applied to 1835 ONLY. Temporary code ensures that the old way still works for other games. <Phase> has another new optional attribute 'realName', intended to have the 'official' name of a phase, as in the physical game. 1835 phase example: <Phase name="4" realName="2"> <Trains limitStep="2" rusted="2"/> </Phase> In the game status window this phase is now displayed as "4 [2]". The major CompanyType now has <Trains limit="4,3,2"/> This change also fixes the 1835 bug that the train limit was reduced to 2 at buying the 4+4-train in stead of the 5-train. diff --git a/data/1835/CompanyManager.xml b/data/1835/CompanyManager.xml index 9af7965..dc0030a 100644 --- a/data/1835/CompanyManager.xml +++ b/data/1835/CompanyManager.xml @@ -10,7 +10,7 @@ <HomeBase lay="whenFloated"/> </BaseTokens> <Payout split="always"/> - <Trains limit="2,2,1" mandatory="no"/> + <Trains limit="2,1" mandatory="no"/> </CompanyType> <CompanyType name="Major" class="rails.game.PublicCompany" capitalisation="incremental"> <PoolPaysOut/> @@ -28,7 +28,7 @@ <HomeBase lay="whenFloated"/> </BaseTokens> <Capitalisation type="incremental"/> - <Trains limit="4,4,3,2"/> + <Trains limit="4,3,2"/> <CanUseSpecialProperties/> </CompanyType> @@ -211,7 +211,7 @@ <Certificate shares="2" number="3"/> <Certificate shares="2" number="4" status="reserved"/> <Certificate shares="1" number="4" status="reserved"/> - <Trains limit="0,0,4,3"/> + <Trains limit="4,4,3"/> </Company> <StartPacket roundClass="rails.game.StartRound_1835" variant="Snake"> diff --git a/data/1835/Game.xml b/data/1835/Game.xml index 75b48c6..8b11f9f 100644 --- a/data/1835/Game.xml +++ b/data/1835/Game.xml @@ -55,45 +55,57 @@ </Defaults> <TrainType name="2" majorStops="2" cost="80" quantity="9"/> <TrainType name="2+2" majorStops="2" minorStops="2" cost="120" quantity="4"/> - <TrainType name="3" majorStops="3" cost="180" quantity="4" startPhase="3"/> + <TrainType name="3" majorStops="3" cost="180" quantity="4"> + <NewPhase phaseName="3"/> + </TrainType> <TrainType name="3+3" majorStops="3" minorStops="3" cost="270" quantity="3"/> - <TrainType name="4" majorStops="4" cost="360" quantity="3" startPhase="4" - rustedTrain="2"/> - <TrainType name="4+4" majorStops="4" minorStops="4" cost="440" quantity="1" - startPhase="4+4" rustedTrain="2+2"/> - <TrainType name="5" majorStops="5" cost="500" quantity="2" startPhase="5"/> + <TrainType name="4" majorStops="4" cost="360" quantity="3"> + <NewPhase phaseName="4"/> + </TrainType> + <TrainType name="4+4" majorStops="4" minorStops="4" cost="440" quantity="1"> + <NewPhase phaseName="4+4"/> + </TrainType> + <TrainType name="5" majorStops="5" cost="500" quantity="2"> + <NewPhase phaseName="5"/> + </TrainType> <TrainType name="5+5" majorStops="5" minorStops="5" cost="600" quantity="1"/> - <TrainType name="6" majorStops="6" cost="600" quantity="2" startPhase="6" - rustedTrain="3"/> - <TrainType name="6+6" majorStops="6" minorStops="6" cost="720" quantity="4" - rustedTrain="3+3"/> + <TrainType name="6" majorStops="6" cost="600" quantity="2"> + <NewPhase phaseName="6"/> + </TrainType> + <TrainType name="6+6" majorStops="6" minorStops="6" cost="720" quantity="4"> + <NewPhase phaseName="6+6"/> + </TrainType> </Component> <Component name="PhaseManager" class="rails.game.PhaseManager"> - <Phase name="2"> + <Phase name="2" realName="1"> <Tiles colour="yellow"/> <OperatingRounds number="1"/> </Phase> - <Phase name="3"> + <Phase name="3" realName="2"> <Tiles colour="yellow,green"/> <OperatingRounds number="2"/> <OffBoardRevenue step="2"/> <Trains tradingAllowed="yes"/> </Phase> - <Phase name="4"> - <Tiles colour="yellow,green"/> + <Phase name="4" realName="2"> + <Trains limitStep="2" rusted="2"/> </Phase> - <Phase name="4+4"> - <Tiles colour="yellow,green"/> + <Phase name="4+4" realName="2"> + <Trains rusted="2+2"/> </Phase> - <Phase name="5"> + <Phase name="5" realName="3"> <Tiles colour="yellow,green,brown"/> <OperatingRounds number="3"/> <!--Privates close="yes"/--> <OffBoardRevenue step="3"/> + <Trains limitStep="3"/> <Info key="PhaseClosesAllPrivates"/> </Phase> - <Phase name="6"> - <Tiles colour="yellow,green,brown"/> + <Phase name="6" realName="3"> + <Trains rusted="3"/> </Phase> + <Phase name="6+6" realName="3"> + <Trains rusted="3+3"/> + </Phase> </Component> </ComponentManager> diff --git a/data/1856/CompanyManager.xml b/data/1856/CompanyManager.xml old mode 100755 new mode 100644 index d8e0b42..34cff8b --- a/data/1856/CompanyManager.xml +++ b/data/1856/CompanyManager.xml @@ -26,7 +26,7 @@ <BaseTokens> <LayCost method="sequence" cost="0,40,100"/> </BaseTokens> - <Trains limit="0,0,0,3"/> + <Trains limit="3"/> <Options mustTradeTrainsAtFixedPrice="yes" canClose="no"/> </CompanyType> diff --git a/rails/game/OperatingRound.java b/rails/game/OperatingRound.java index 35cc3b4..6c80717 100644 --- a/rails/game/OperatingRound.java +++ b/rails/game/OperatingRound.java @@ -1877,7 +1877,7 @@ public class OperatingRound extends Round implements Observer { excessTrainCompanies = new HashMap<Player, List<PublicCompanyI>>(); Player player; for (PublicCompanyI comp : operatingCompanies.viewList()) { - if (comp.getPortfolio().getNumberOfTrains() > comp.getTrainLimit(getCurrentPhase().getIndex())) { + if (comp.getPortfolio().getNumberOfTrains() > comp.getCurrentTrainLimit()) { player = comp.getPresident(); if (!excessTrainCompanies.containsKey(player)) { excessTrainCompanies.put(player, diff --git a/rails/game/Phase.java b/rails/game/Phase.java index 44d90be..7685387 100644 --- a/rails/game/Phase.java +++ b/rails/game/Phase.java @@ -14,6 +14,8 @@ public class Phase implements PhaseI { protected int index; protected String name; + + protected String realName; protected String colourList = ""; @@ -27,6 +29,12 @@ public class Phase implements PhaseI { protected int offBoardRevenueStep = 1; + /** New style train limit configuration. + * TODO TEMPORARILY the default is 0 to allow distinguishing the old and new styles. + * This should be set to 1 once all game configs have been converted. + */ + protected int trainLimitStep = 0; + protected int privatesRevenueStep = 1; // sfy 1889 protected boolean trainTradingAllowed = false; @@ -79,6 +87,7 @@ public class Phase implements PhaseI { privateSellingAllowed = defaults.privateSellingAllowed; numberOfOperatingRounds = defaults.numberOfOperatingRounds; offBoardRevenueStep = defaults.offBoardRevenueStep; + trainLimitStep = defaults.trainLimitStep; privatesRevenueStep = defaults.privatesRevenueStep; trainTradingAllowed = defaults.trainTradingAllowed; oneTrainPerTurn = defaults.oneTrainPerTurn; @@ -91,6 +100,9 @@ public class Phase implements PhaseI { } } } + + // Real name (as in the printed game) + realName = tag.getAttributeAsString("realName", null); // String colourList; String[] colourArray = new String[0]; @@ -124,16 +136,17 @@ public class Phase implements PhaseI { numberOfOperatingRounds); } - // Off-board revenue steps + // Off-board revenue steps (starts at 1) Tag offBoardTag = tag.getChild("OffBoardRevenue"); if (offBoardTag != null) { offBoardRevenueStep = offBoardTag.getAttributeAsInteger("step", offBoardRevenueStep); } - + Tag trainsTag = tag.getChild("Trains"); if (trainsTag != null) { + trainLimitStep = trainsTag.getAttributeAsInteger("limitStep", trainLimitStep); rustedTrainNames = trainsTag.getAttributeAsString("rusted", null); releasedTrainNames = trainsTag.getAttributeAsString("released", null); trainTradingAllowed = @@ -245,6 +258,25 @@ public class Phase implements PhaseI { return colourList; } + public int getTrainLimitStep() { + return trainLimitStep; + } + + // TEMPORARILY included. To be removed when all games have been converted to new style train limit configuration. + public void setTrainLimitStep(int trainLimitStep) { + this.trainLimitStep = trainLimitStep; + } + + public int getTrainLimitIndex() { + if(trainLimitStep > 0) { + // New style + return trainLimitStep - 1; + } else { + // TODO Old style, can be removed once all games have been converted + return index; + } + } + public int getIndex() { return index; } @@ -253,6 +285,10 @@ public class Phase implements PhaseI { return name; } + public String getRealName() { + return realName; + } + /** * @return Returns the privatesClose. */ @@ -340,6 +376,10 @@ public class Phase implements PhaseI { @Override public String toString() { - return name; + if (realName == null) { + return name; + } else { + return name + " [" + realName+ "]"; + } } } diff --git a/rails/game/PhaseI.java b/rails/game/PhaseI.java index bf41d07..a598e12 100644 --- a/rails/game/PhaseI.java +++ b/rails/game/PhaseI.java @@ -26,7 +26,8 @@ public interface PhaseI extends ConfigurableComponentI { public int getPrivatesRevenueStep(); // sfy 1889 public boolean isTrainTradingAllowed(); - + public int getTrainLimitStep(); + public int getTrainLimitIndex(); public boolean canBuyMoreTrainsPerTurn(); public boolean canBuyMoreTrainsPerTypePerTurn(); diff --git a/rails/game/PhaseManager.java b/rails/game/PhaseManager.java index 3f446bf..e0b4ef3 100644 --- a/rails/game/PhaseManager.java +++ b/rails/game/PhaseManager.java @@ -59,6 +59,24 @@ public class PhaseManager implements ConfigurableComponentI { phase.finishConfiguration(gameManager); } + /* TODO TEMPORARY CODE: + * If any phase has a train limit step > 0, all remaining 0 values must be set to 1. + * This code uses separate loops to allow easy removal. + */ + boolean anyLimitStep = false; + for (Phase phase : phaseList) { + if (phase.getTrainLimitStep() > 0) { + anyLimitStep = true; + break; + } + } + if (anyLimitStep) { + for (Phase phase : phaseList) { + if (phase.getTrainLimitStep() == 0) phase.setTrainLimitStep(1); + } + } + // End of temporary code + PhaseI initialPhase = phaseList.get(0); setPhase(initialPhase, null); } diff --git a/rails/game/PublicCompany.java b/rails/game/PublicCompany.java index 3416239..7cd390c 100644 --- a/rails/game/PublicCompany.java +++ b/rails/game/PublicCompany.java @@ -1572,12 +1572,21 @@ public class PublicCompany extends Company implements PublicCompanyI { return 100 / shareUnit.intValue(); } - public int getTrainLimit(int phaseIndex) { - return trainLimit[Math.min(phaseIndex, trainLimit.length - 1)]; + /** Get the current maximum number of trains. + * @parm index The limit for the given index (N.B. starts at 0). + * <p><i>Old style:</i> the index of the current phase.<br> + * <i>New style:</i> the index of the train limit step as defined for the current phase. + * <br>The limits per train (type) must follow the logic that is implemented for the current game, + * which is indicated by the absence or presence of 'limitStep' attributes in the <Phase> tags. + * <p>N.B. the new style limit steps per phase start at 1, + * so one must be subtracted before calling this method. + */ + protected int getTrainLimit(int index) { + return trainLimit[Math.min(index, trainLimit.length - 1)]; } public int getCurrentTrainLimit() { - return getTrainLimit(GameManager.getInstance().getCurrentPhase().getIndex()); + return getTrainLimit(gameManager.getCurrentPhase().getTrainLimitIndex()); } public int getNumberOfTrains() { diff --git a/rails/game/PublicCompanyI.java b/rails/game/PublicCompanyI.java index 31b5d4a..63ad78b 100644 --- a/rails/game/PublicCompanyI.java +++ b/rails/game/PublicCompanyI.java @@ -258,8 +258,6 @@ public interface PublicCompanyI extends CompanyI, CashHolder, TokenHolder { public void setCapitalisation(int capitalisation); - public int getTrainLimit(int phaseIndex); - public int getCurrentTrainLimit(); public int getNumberOfTrains(); diff --git a/rails/game/specific/_1835/PrussianFormationRound.java b/rails/game/specific/_1835/PrussianFormationRound.java index fe04427..1b97e32 100644 --- a/rails/game/specific/_1835/PrussianFormationRound.java +++ b/rails/game/specific/_1835/PrussianFormationRound.java @@ -118,7 +118,7 @@ public class PrussianFormationRound extends StockRound { } else if (step == Step.DISCARD_TRAINS) { - if (prussian.getNumberOfTrains() > prussian.getTrainLimit(getCurrentPhase().getIndex())) { + if (prussian.getNumberOfTrains() > prussian.getCurrentTrainLimit()) { possibleActions.add(new DiscardTrain(prussian, prussian.getPortfolio().getUniqueTrains(), true)); } @@ -189,7 +189,7 @@ public class PrussianFormationRound extends StockRound { if (skipCurrentPlayer) { setNextPlayer(); if (getCurrentPlayer() == startingPlayer) { - if (prussian.getNumberOfTrains() > prussian.getTrainLimit(getCurrentPhase().getIndex())) { + if (prussian.getNumberOfTrains() > prussian.getCurrentTrainLimit()) { step = Step.DISCARD_TRAINS; } else { finishRound(); diff --git a/rails/game/specific/_18EU/OperatingRound_18EU.java b/rails/game/specific/_18EU/OperatingRound_18EU.java index a6fb8a0..a1fc677 100644 --- a/rails/game/specific/_18EU/OperatingRound_18EU.java +++ b/rails/game/specific/_18EU/OperatingRound_18EU.java @@ -238,7 +238,7 @@ public class OperatingRound_18EU extends OperatingRound { // A Pullmann always goes first, and automatically. // If the last train is a Pullmann, discard it. - if ((numberOfTrains > comp.getTrainLimit(getCurrentPhase().getIndex()) || numberOfTrains == 1) + if ((numberOfTrains > comp.getCurrentTrainLimit() || numberOfTrains == 1) && pullmann != null) { pullmann.moveTo(pool); numberOfTrains--; @@ -246,7 +246,7 @@ public class OperatingRound_18EU extends OperatingRound { // If we are still above the limit, make the list // of trains to select the discarded one from - if (numberOfTrains > comp.getTrainLimit(getCurrentPhase().getIndex())) { + if (numberOfTrains > comp.getCurrentTrainLimit()) { player = comp.getPresident(); if (!excessTrainCompanies.containsKey(player)) { excessTrainCompanies.put(player, |