From: Erik V. <ev...@us...> - 2010-02-06 23:48:34
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv9732/rails/game Modified Files: StockRound.java Portfolio.java OperatingRound.java Log Message: Allow special token lays at any time during OR. This has changed the way that OR steps are handled. These can now be used again in the UI. Goal was to enable the extra NF token lay in 1835 Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** Portfolio.java 31 Jan 2010 22:22:28 -0000 1.43 --- Portfolio.java 6 Feb 2010 23:48:26 -0000 1.44 *************** *** 623,629 **** * @return ArrayList of all special properties we have. */ ! public List<SpecialPropertyI> getSpecialProperties() { return specialProperties; } /** --- 623,640 ---- * @return ArrayList of all special properties we have. */ ! public List<SpecialPropertyI> getPersistentSpecialProperties() { return specialProperties; } + + public List<SpecialPropertyI> getAllSpecialProperties() { + List<SpecialPropertyI> sps = new ArrayList<SpecialPropertyI>(); + if (specialProperties != null) sps.addAll(specialProperties); + for (PrivateCompanyI priv : privateCompanies) { + if (priv.getSpecialProperties() != null) { + sps.addAll(priv.getSpecialProperties()); + } + } + return sps; + } /** *************** *** 655,659 **** && (owner instanceof Company && sp.isUsableIfOwnedByCompany() || owner instanceof Player && sp.isUsableIfOwnedByPlayer())) { ! log.debug("Adding private SP: " + sp); result.add((T) sp); } --- 666,670 ---- && (owner instanceof Company && sp.isUsableIfOwnedByCompany() || owner instanceof Player && sp.isUsableIfOwnedByPlayer())) { ! log.debug("Portfolio "+name+" has SP " + sp); result.add((T) sp); } *************** *** 669,673 **** && (owner instanceof Company && sp.isUsableIfOwnedByCompany() || owner instanceof Player && sp.isUsableIfOwnedByPlayer())) { ! log.debug("Adding persistent SP: " + sp); result.add((T) sp); } --- 680,684 ---- && (owner instanceof Company && sp.isUsableIfOwnedByCompany() || owner instanceof Player && sp.isUsableIfOwnedByPlayer())) { ! log.debug("Portfolio "+name+" has persistent SP " + sp); result.add((T) sp); } Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** OperatingRound.java 4 Feb 2010 22:23:01 -0000 1.97 --- OperatingRound.java 6 Feb 2010 23:48:26 -0000 1.98 *************** *** 9,13 **** --- 9,15 ---- import rails.game.move.MapChange; import rails.game.special.*; + import rails.game.state.EnumState; import rails.game.state.IntegerState; + import rails.game.state.State; import rails.util.LocalText; *************** *** 20,24 **** /* Transient memory (per round only) */ ! protected IntegerState stepObject; protected boolean actionPossible = true; --- 22,26 ---- /* Transient memory (per round only) */ ! protected EnumState<GameDef.OrStep> stepObject; protected boolean actionPossible = true; *************** *** 64,90 **** protected PossibleAction savedAction = null; - //protected int cashToBeRaisedByPresident = 0; - public static final int SPLIT_ROUND_DOWN = 2; // More to the treasury ! public static final int STEP_INITIAL = 0; ! ! public static final int STEP_LAY_TRACK = 0; ! ! public static final int STEP_LAY_TOKEN = 1; ! ! public static final int STEP_CALC_REVENUE = 2; ! ! public static final int STEP_PAYOUT = 3; ! ! public static final int STEP_BUY_TRAIN = 4; ! ! public static final int STEP_TRADE_SHARES = 5; ! ! public static int STEP_FINAL = 6; ! ! protected static int[] steps = ! new int[] { STEP_LAY_TRACK, STEP_LAY_TOKEN, STEP_CALC_REVENUE, ! STEP_PAYOUT, STEP_BUY_TRAIN, STEP_TRADE_SHARES, STEP_FINAL }; // side steps --- 66,81 ---- protected PossibleAction savedAction = null; public static final int SPLIT_ROUND_DOWN = 2; // More to the treasury ! protected static GameDef.OrStep[] steps = ! new GameDef.OrStep[] { ! GameDef.OrStep.INITIAL, ! GameDef.OrStep.LAY_TRACK, ! GameDef.OrStep.LAY_TOKEN, ! GameDef.OrStep.CALC_REVENUE, ! GameDef.OrStep.PAYOUT, ! GameDef.OrStep.BUY_TRAIN, ! GameDef.OrStep.TRADE_SHARES, ! GameDef.OrStep.FINAL }; // side steps *************** *** 95,102 **** protected TrainManager trainManager = gameManager.getTrainManager(); - public static String[] stepNames = - new String[] { "LayTrack", "LayToken", "EnterRevenue", "Payout", - "BuyTrain", "TradeShares", "Final" }; - /** * Constructor with no parameters, call the super Class (Round's) Constructor with no parameters --- 86,89 ---- *************** *** 108,112 **** operatingCompanyArray = super.getOperatingCompanies(); ! guiHints.setVisibilityHint(GuiDef.Panel.STOCK_MARKET, false); guiHints.setVisibilityHint(GuiDef.Panel.STATUS, true); guiHints.setActivePanel(GuiDef.Panel.MAP); --- 95,99 ---- operatingCompanyArray = super.getOperatingCompanies(); ! guiHints.setVisibilityHint(GuiDef.Panel.STOCK_MARKET, false); guiHints.setVisibilityHint(GuiDef.Panel.STATUS, true); guiHints.setActivePanel(GuiDef.Panel.MAP); *************** *** 138,142 **** if (operate) { ! StringBuffer msg = new StringBuffer(); for (PublicCompanyI company : operatingCompanyArray) { msg.append(",").append(company.getName()); --- 125,129 ---- if (operate) { ! StringBuilder msg = new StringBuilder(); for (PublicCompanyI company : operatingCompanyArray) { msg.append(",").append(company.getName()); *************** *** 146,150 **** if (stepObject == null) { ! stepObject = new IntegerState("ORStep", -1); stepObject.addObserver(this); } --- 133,137 ---- if (stepObject == null) { ! stepObject = new EnumState<GameDef.OrStep>("ORStep", GameDef.OrStep.INITIAL); stepObject.addObserver(this); } *************** *** 153,157 **** if (setNextOperatingCompany(true)) { ! setStep(STEP_INITIAL); return; } --- 140,144 ---- if (setNextOperatingCompany(true)) { ! setStep(GameDef.OrStep.INITIAL); return; } *************** *** 297,301 **** } // Must be correct step ! if (getStep() != STEP_LAY_TRACK) { errMsg = LocalText.getText("WrongActionNoTileLay"); break; --- 284,288 ---- } // Must be correct step ! if (getStep() != GameDef.OrStep.LAY_TRACK) { errMsg = LocalText.getText("WrongActionNoTileLay"); break; *************** *** 493,498 **** // Checks ! // Must be correct step (exception: home base lay) ! if (getStep() != STEP_LAY_TOKEN && action.getType() != LayBaseToken.HOME_CITY) { errMsg = LocalText.getText("WrongActionNoTokenLay"); break; --- 480,487 ---- // Checks ! // Must be correct step (exception: home base lay & some special token lay) ! if (getStep() != GameDef.OrStep.LAY_TOKEN ! && action.getType() != LayBaseToken.HOME_CITY ! && action.getType() != LayBaseToken.SPECIAL_PROPERTY) { errMsg = LocalText.getText("WrongActionNoTokenLay"); break; *************** *** 589,592 **** --- 578,585 ---- } + + // Jump out if we aren't in the token laying step + if (getStep() != GameDef.OrStep.LAY_TOKEN) return true; + if (!extra) { currentNormalTokenLays.clear(); *************** *** 796,800 **** } // Must be correct step ! if (getStep() != STEP_CALC_REVENUE) { errMsg = LocalText.getText("WrongActionNoRevenue"); break; --- 789,793 ---- } // Must be correct step ! if (getStep() != GameDef.OrStep.CALC_REVENUE) { errMsg = LocalText.getText("WrongActionNoRevenue"); break; *************** *** 915,919 **** // We have done the payout step, so continue from there ! nextStep(STEP_PAYOUT); } --- 908,912 ---- // We have done the payout step, so continue from there ! nextStep(GameDef.OrStep.PAYOUT); } *************** *** 939,943 **** /** Take the next step after a given one (see nextStep()) */ ! protected void nextStep(int step) { // Cycle through the steps until we reach one where a user action is // expected. --- 932,936 ---- /** Take the next step after a given one (see nextStep()) */ ! protected void nextStep(GameDef.OrStep step) { // Cycle through the steps until we reach one where a user action is // expected. *************** *** 948,959 **** while (++stepIndex < steps.length) { step = steps[stepIndex]; ! log.debug("Step " + stepNames[step]); ! if (step == STEP_LAY_TOKEN && operatingCompany.getNumberOfFreeBaseTokens() == 0) { continue; } ! if (step == STEP_CALC_REVENUE) { if (!operatingCompany.canRunTrains()) { --- 941,952 ---- while (++stepIndex < steps.length) { step = steps[stepIndex]; ! log.debug("Step " + step); ! if (step == GameDef.OrStep.LAY_TOKEN && operatingCompany.getNumberOfFreeBaseTokens() == 0) { continue; } ! if (step == GameDef.OrStep.CALC_REVENUE) { if (!operatingCompany.canRunTrains()) { *************** *** 966,975 **** } ! if (step == STEP_PAYOUT) { // This step is now obsolete continue; } ! if (step == STEP_TRADE_SHARES) { // Is company allowed to trade trasury shares? --- 959,968 ---- } ! if (step == GameDef.OrStep.PAYOUT) { // This step is now obsolete continue; } ! if (step == GameDef.OrStep.TRADE_SHARES) { // Is company allowed to trade trasury shares? *************** *** 989,993 **** } ! if (step == STEP_FINAL) { finishTurn(); } else { --- 982,986 ---- } ! if (step == GameDef.OrStep.FINAL) { finishTurn(); } else { *************** *** 998,1002 **** /** Stub, can be overridden in subclasses to check for extra steps */ ! protected boolean gameSpecificNextStep (int step) { return true; } --- 991,995 ---- /** Stub, can be overridden in subclasses to check for extra steps */ ! protected boolean gameSpecificNextStep (GameDef.OrStep step) { return true; } *************** *** 1010,1013 **** --- 1003,1007 ---- operatingCompany.initTurn(); trainsBoughtThisTurn.clear(); + setStep (GameDef.OrStep.LAY_TRACK); } *************** *** 1017,1025 **** */ protected void prepareStep() { ! int step = stepObject.intValue(); ! if (step == STEP_LAY_TRACK) { getNormalTileLays(); ! } else if (step == STEP_LAY_TOKEN) { } else { --- 1011,1019 ---- */ protected void prepareStep() { ! GameDef.OrStep step = stepObject.value(); ! if (step == GameDef.OrStep.LAY_TRACK) { getNormalTileLays(); ! } else if (step == GameDef.OrStep.LAY_TOKEN) { } else { *************** *** 1161,1165 **** public void skip() { ! log.debug("Skip step " + stepObject.intValue()); moveStack.start(true); nextStep(); --- 1155,1159 ---- public void skip() { ! log.debug("Skip step " + stepObject.value()); moveStack.start(true); nextStep(); *************** *** 1193,1197 **** nextStep(); ! if (getStep() == STEP_FINAL) { finishTurn(); } --- 1187,1191 ---- nextStep(); ! if (getStep() == GameDef.OrStep.FINAL) { finishTurn(); } *************** *** 1214,1218 **** if (setNextOperatingCompany(false)) { ! setStep(STEP_INITIAL); } else { finishOR(); --- 1208,1212 ---- if (setNextOperatingCompany(false)) { ! setStep(GameDef.OrStep.INITIAL); } else { finishOR(); *************** *** 1287,1291 **** // Checks // Must be correct step ! if (getStep() != STEP_BUY_TRAIN) { errMsg = LocalText.getText("WrongActionNoTrainBuyingCost"); break; --- 1281,1285 ---- // Checks // Must be correct step ! if (getStep() != GameDef.OrStep.BUY_TRAIN) { errMsg = LocalText.getText("WrongActionNoTrainBuyingCost"); break; *************** *** 1494,1498 **** // Checks // Must be correct step ! if (getStep() != STEP_BUY_TRAIN && getStep() != STEP_DISCARD_TRAINS) { errMsg = LocalText.getText("WrongActionNoDiscardTrain"); break; --- 1488,1493 ---- // Checks // Must be correct step ! if (getStep() != GameDef.OrStep.BUY_TRAIN ! && getStep() != GameDef.OrStep.DISCARD_TRAINS) { errMsg = LocalText.getText("WrongActionNoDiscardTrain"); break; *************** *** 1537,1541 **** // otherwise continue train buying if (!checkForExcessTrains()) { ! stepObject.set(STEP_BUY_TRAIN); } --- 1532,1536 ---- // otherwise continue train buying if (!checkForExcessTrains()) { ! stepObject.set(GameDef.OrStep.BUY_TRAIN); } *************** *** 1890,1895 **** * @return The number that defines the next action. */ ! public int getStep() { ! return stepObject.intValue(); } --- 1885,1890 ---- * @return The number that defines the next action. */ ! public GameDef.OrStep getStep() { ! return (GameDef.OrStep) stepObject.getObject(); } *************** *** 1901,1907 **** * @param step */ ! protected void setStep(int step) { ! if (step == STEP_INITIAL) initTurn(); ! stepObject.set(step); --- 1896,1901 ---- * @param step */ ! protected void setStep(GameDef.OrStep step) { ! stepObject.set(step); *************** *** 1928,1935 **** selectedAction = null; - int step = getStep(); boolean forced = false; ! if (step == STEP_LAY_TRACK) { if (!operatingCompany.hasLaidHomeBaseTokens()) { --- 1922,1934 ---- selectedAction = null; boolean forced = false; + + if (getStep() == GameDef.OrStep.INITIAL) { + initTurn(); + setStep (GameDef.OrStep.LAY_TRACK); + } ! GameDef.OrStep step = getStep(); ! if (step == GameDef.OrStep.LAY_TRACK) { if (!operatingCompany.hasLaidHomeBaseTokens()) { *************** *** 1949,1953 **** } ! } else if (step == STEP_LAY_TOKEN) { setNormalTokenLays(); setSpecialTokenLays(); --- 1948,1952 ---- } ! } else if (step == GameDef.OrStep.LAY_TOKEN) { setNormalTokenLays(); setSpecialTokenLays(); *************** *** 1958,1964 **** possibleActions.addAll(currentSpecialTokenLays); possibleActions.add(new NullAction(NullAction.SKIP)); ! } else if (step == STEP_CALC_REVENUE) { prepareRevenueAndDividendAction(); ! } else if (step == STEP_BUY_TRAIN) { setBuyableTrains(); // TODO Need route checking here. --- 1957,1963 ---- possibleActions.addAll(currentSpecialTokenLays); possibleActions.add(new NullAction(NullAction.SKIP)); ! } else if (step == GameDef.OrStep.CALC_REVENUE) { prepareRevenueAndDividendAction(); ! } else if (step == GameDef.OrStep.BUY_TRAIN) { setBuyableTrains(); // TODO Need route checking here. *************** *** 1968,1972 **** doneAllowed = true; //} ! } else if (step == STEP_DISCARD_TRAINS) { setTrainsToDiscard(); } --- 1967,1973 ---- doneAllowed = true; //} ! } else if (step == GameDef.OrStep.DISCARD_TRAINS) { ! ! forced = true; setTrainsToDiscard(); } *************** *** 1974,1978 **** // The following additional "common" actions are only available if the // primary action is not forced. ! if (step >= 0 && !forced) { setBonusTokenLays(); --- 1975,1979 ---- // The following additional "common" actions are only available if the // primary action is not forced. ! if (!forced) { setBonusTokenLays(); *************** *** 2024,2027 **** --- 2025,2057 ---- } } + + // Are there other step-independent special properties owned by the company? + List<SpecialPropertyI> orsps = operatingCompany.getPortfolio().getAllSpecialProperties(); + if (orsps != null) { + for (SpecialPropertyI sp : orsps) { + if (!sp.isExercised() && sp.isUsableIfOwnedByCompany() + && sp.isUsableDuringOR()) { + if (sp instanceof SpecialTokenLay) { + possibleActions.add(new LayBaseToken((SpecialTokenLay)sp)); + } else { + possibleActions.add(new UseSpecialProperty(sp)); + } + } + } + } + // Are there other step-independent special properties owned by teh president? + orsps = getCurrentPlayer().getPortfolio().getAllSpecialProperties(); + if (orsps != null) { + for (SpecialPropertyI sp : orsps) { + if (!sp.isExercised() && sp.isUsableIfOwnedByPlayer() + && sp.isUsableDuringOR()) { + if (sp instanceof SpecialTokenLay) { + possibleActions.add(new LayBaseToken((SpecialTokenLay)sp)); + } else { + possibleActions.add(new UseSpecialProperty(sp)); + } + } + } + } } *************** *** 2308,2312 **** @Override public String getHelp() { ! int step = getStep(); StringBuffer b = new StringBuffer(); b.append("<big>Operating round: ").append(thisOrNumber).append( --- 2338,2342 ---- @Override public String getHelp() { ! GameDef.OrStep step = getStep(); StringBuffer b = new StringBuffer(); b.append("<big>Operating round: ").append(thisOrNumber).append( *************** *** 2316,2341 **** ") has the turn."); b.append("<br><br>Currently allowed actions:"); ! if (step == STEP_LAY_TRACK) { b.append("<br> - Lay a tile"); b.append("<br> - Press 'Done' if you do not want to lay a tile"); ! } else if (step == STEP_LAY_TOKEN) { b.append("<br> - Lay a base token or press Done"); b.append("<br> - Press 'Done' if you do not want to lay a base"); ! } else if (step == STEP_CALC_REVENUE) { b.append("<br> - Enter new revenue amount"); b.append("<br> - Press 'Done' if your revenue is zero"); ! } else if (step == STEP_PAYOUT) { b.append("<br> - Choose how the revenue will be paid out"); ! } else if (step == STEP_BUY_TRAIN) { b.append("<br> - Buy one or more trains"); b.append("<br> - Press 'Done' to finish your turn"); } /* TODO: The below if needs be refined. */ if (getCurrentPhase().isPrivateSellingAllowed() ! && step != STEP_PAYOUT) { b.append("<br> - Buy one or more Privates"); } ! if (step == STEP_LAY_TRACK) { b.append("<br><br><b>Tile laying</b> proceeds as follows:"); b.append("<br><br> 1. On the map, select the hex that you want to lay a new tile upon."); --- 2346,2378 ---- ") has the turn."); b.append("<br><br>Currently allowed actions:"); ! switch (step) { ! case LAY_TRACK: b.append("<br> - Lay a tile"); b.append("<br> - Press 'Done' if you do not want to lay a tile"); ! break; ! case LAY_TOKEN: b.append("<br> - Lay a base token or press Done"); b.append("<br> - Press 'Done' if you do not want to lay a base"); ! break; ! case CALC_REVENUE: b.append("<br> - Enter new revenue amount"); b.append("<br> - Press 'Done' if your revenue is zero"); ! break; ! case PAYOUT: b.append("<br> - Choose how the revenue will be paid out"); ! break; ! case BUY_TRAIN: b.append("<br> - Buy one or more trains"); b.append("<br> - Press 'Done' to finish your turn"); + break; } + /* TODO: The below if needs be refined. */ if (getCurrentPhase().isPrivateSellingAllowed() ! && step != GameDef.OrStep.PAYOUT) { b.append("<br> - Buy one or more Privates"); } ! if (step == GameDef.OrStep.LAY_TRACK) { b.append("<br><br><b>Tile laying</b> proceeds as follows:"); b.append("<br><br> 1. On the map, select the hex that you want to lay a new tile upon."); Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** StockRound.java 5 Feb 2010 19:58:45 -0000 1.59 --- StockRound.java 6 Feb 2010 23:48:26 -0000 1.60 *************** *** 384,388 **** SpecialProperty.class, false); for (SpecialPropertyI sp : sps) { ! possibleActions.add(new UseSpecialProperty(sp)); } } --- 384,390 ---- SpecialProperty.class, false); for (SpecialPropertyI sp : sps) { ! if (sp.isUsableDuringSR()) { ! possibleActions.add(new UseSpecialProperty(sp)); ! } } } |