From: Erik V. <ev...@us...> - 2009-10-07 19:00:52
|
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv9081/rails/game Modified Files: StartRound.java StartRound_1835.java StockRound.java ShareSellingRound.java OperatingRound.java PhaseManager.java GameManagerI.java StartRound_1830.java Round.java PublicCompany.java TreasuryShareRound.java GameManager.java Log Message: Created basic mechanism to allow more games running in parallel at the server side (which itself will not be implemented anytime soon). NDC is used to assign a key to each GameManager. GameManager.getInstance() uses this to find the correct instance. Using this static method to find the GM from anywhere is now 'blessed'. MoveStack added. MoveSet uses the above to have a separate stack per game. Index: TreasuryShareRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TreasuryShareRound.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TreasuryShareRound.java 25 Sep 2009 19:13:01 -0000 1.13 --- TreasuryShareRound.java 7 Oct 2009 19:00:38 -0000 1.14 *************** *** 9,13 **** import rails.game.action.*; - import rails.game.move.MoveSet; import rails.game.state.BooleanState; import rails.util.LocalText; --- 9,12 ---- *************** *** 352,356 **** } ! MoveSet.start(true); PublicCertificateI cert2; for (int i = 0; i < number; i++) { --- 351,355 ---- } ! moveStack.start(true); PublicCertificateI cert2; for (int i = 0; i < number; i++) { *************** *** 473,477 **** } ! MoveSet.start(true); ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", --- 472,476 ---- } ! moveStack.start(true); ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", *************** *** 511,515 **** } ! MoveSet.start(false); // Inform GameManager --- 510,514 ---- } ! moveStack.start(false); // Inform GameManager Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** PublicCompany.java 6 Oct 2009 18:34:04 -0000 1.64 --- PublicCompany.java 7 Oct 2009 19:00:38 -0000 1.65 *************** *** 1400,1407 **** Player player; int share; for (int i = presIndex + 1; i < presIndex ! + GameManager.getInstance().getNumberOfPlayers(); i++) { ! player = GameManager.getInstance().getPlayerByIndex(i); share = player.getPortfolio().getShare(this); if (share > presShare) { --- 1400,1408 ---- Player player; int share; + GameManagerI gmgr = GameManager.getInstance(); for (int i = presIndex + 1; i < presIndex ! + gmgr.getNumberOfPlayers(); i++) { ! player = gmgr.getPlayerByIndex(i); share = player.getPortfolio().getShare(this); if (share > presShare) { Index: StartRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** StartRound.java 25 Sep 2009 19:29:56 -0000 1.26 --- StartRound.java 7 Oct 2009 19:00:38 -0000 1.27 *************** *** 6,10 **** import rails.game.action.*; import rails.game.model.ModelObject; - import rails.game.move.MoveSet; import rails.game.state.IntegerState; import rails.game.state.State; --- 6,9 ---- *************** *** 227,231 **** } ! MoveSet.start(false); assignItem(player, item, price, sharePrice); --- 226,230 ---- } ! moveStack.start(false); assignItem(player, item, price, sharePrice); Index: PhaseManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PhaseManager.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** PhaseManager.java 11 Sep 2009 19:27:23 -0000 1.15 --- PhaseManager.java 7 Oct 2009 19:00:38 -0000 1.16 *************** *** 4,7 **** --- 4,9 ---- import java.util.*; + import org.apache.log4j.Logger; + import rails.game.state.State; import rails.util.Tag; *************** *** 18,21 **** --- 20,26 ---- protected GameManagerI gameManager; + protected static Logger log = + Logger.getLogger(PhaseManager.class.getPackage().getName()); + public PhaseManager() {} Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** GameManager.java 6 Oct 2009 18:34:04 -0000 1.56 --- GameManager.java 7 Oct 2009 19:00:38 -0000 1.57 *************** *** 7,10 **** --- 7,11 ---- import org.apache.log4j.Logger; + import org.apache.log4j.NDC; import rails.common.Defs; *************** *** 99,103 **** protected int stockRoundSequenceRule = StockRound.SELL_BUY_SELL; ! protected static GameManager instance; protected String name; --- 100,140 ---- protected int stockRoundSequenceRule = StockRound.SELL_BUY_SELL; ! //protected static GameManager instance; ! /** ! * Map of GameManager instances. ! * Currently there can be only one instance, but in a possible ! * future multi-game server there may be several instances ! * running in parallel. ! * ! * <p>The reason for creating this map is the need to access ! * GameManager instances (or other common instances via the GM) ! * from many different classes, some of which ! * (like those in the move package) are many method calls away from ! * the actual GM. ! * <p>To prevent the need to pass GameManager instances or the keys to ! * this map around throughout the code, NDC is (mis-)used as the ! * mechanism to pass around a string key to each GM instance. ! * This is possible,because the server processes all player actions ! * in one thread. The key will be set in process(), which is where server ! * processing currently starts (in the furtire it will probably be moved ! * to the then needed communication interface). The key ! * can be retrieved (via NDC.peek()) anywhere. ! * <p>For now, the key is a fixed string, but that may change in the future. ! */ ! protected static Map<String, GameManagerI> gameManagerMap ! = new HashMap<String, GameManagerI>(); ! ! /** ! * The temporary fixed key to the currently single GameManager instance ! * in the GameManager map. ! * It will only be used inside the GM objects. ! * All other objects will access it via NDC. ! */ ! protected static final String GM_KEY = "GM-1"; ! ! /** ! * The MoveSet stack is maintained to enable Undo and Redo throughout the game. ! */ ! protected MoveStack moveStack = new MoveStack(); protected String name; *************** *** 132,136 **** */ public GameManager() { ! instance = this; } --- 169,174 ---- */ public GameManager() { ! //instance = this; ! gameManagerMap.put(GM_KEY, this); } *************** *** 351,354 **** --- 389,395 ---- public void startGame() { + NDC.clear(); + NDC.push (GM_KEY); + setGameParameters(); *************** *** 365,369 **** // Initialisation is complete. Undoability starts here. ! MoveSet.enable(); } --- 406,410 ---- // Initialisation is complete. Undoability starts here. ! moveStack.enable(); } *************** *** 397,402 **** * @return instance of GameManager */ ! public static GameManagerI getInstance() { ! return instance; } --- 438,443 ---- * @return instance of GameManager */ ! public static GameManagerI getInstance () { ! return gameManagerMap.get(NDC.peek()); } *************** *** 438,442 **** } else if (round instanceof StockRound) { PhaseI currentPhase = getCurrentPhase(); ! numOfORs = getCurrentPhase().getNumberOfOperatingRounds(); log.info("Phase=" + currentPhase.getName() + " ORs=" + numOfORs); --- 479,484 ---- } else if (round instanceof StockRound) { PhaseI currentPhase = getCurrentPhase(); ! if (currentPhase == null) log.error ("Current Phase is null??", new Exception ("")); ! numOfORs = currentPhase.getNumberOfOperatingRounds(); log.info("Phase=" + currentPhase.getName() + " ORs=" + numOfORs); *************** *** 572,575 **** --- 614,620 ---- public boolean process(PossibleAction action) { + NDC.clear(); + NDC.push (GM_KEY); + boolean result = true; *************** *** 607,619 **** break; case GameAction.UNDO: ! MoveSet.undo(false); result = true; break; case GameAction.FORCED_UNDO: ! MoveSet.undo(true); result = true; break; case GameAction.REDO: ! MoveSet.redo(); result = true; break; --- 652,664 ---- break; case GameAction.UNDO: ! moveStack.undoMoveSet(false); result = true; break; case GameAction.FORCED_UNDO: ! moveStack.undoMoveSet(true); result = true; break; case GameAction.REDO: ! moveStack.redoMoveSet(); result = true; break; *************** *** 638,648 **** getCurrentRound().setPossibleActions(); ! // MoveSet closing is done here to allow state changes to occur // when setting possible actions if (action != null) { if (result && !(action instanceof GameAction)) { ! if (MoveSet.isOpen()) MoveSet.finish(); } else { ! if (MoveSet.isOpen()) MoveSet.cancel(); } } --- 683,693 ---- getCurrentRound().setPossibleActions(); ! // moveStack closing is done here to allow state changes to occur // when setting possible actions if (action != null) { if (result && !(action instanceof GameAction)) { ! if (moveStack.isOpen()) moveStack.finish(); } else { ! if (moveStack.isOpen()) moveStack.cancel(); } } *************** *** 654,664 **** // Add the Undo/Redo possibleActions here. ! if (MoveSet.isUndoableByPlayer()) { possibleActions.add(new GameAction(GameAction.UNDO)); } ! if (MoveSet.isUndoableByManager()) { possibleActions.add(new GameAction(GameAction.FORCED_UNDO)); } ! if (MoveSet.isRedoable()) { possibleActions.add(new GameAction(GameAction.REDO)); } --- 699,709 ---- // Add the Undo/Redo possibleActions here. ! if (moveStack.isUndoableByPlayer()) { possibleActions.add(new GameAction(GameAction.UNDO)); } ! if (moveStack.isUndoableByManager()) { possibleActions.add(new GameAction(GameAction.FORCED_UNDO)); } ! if (moveStack.isRedoable()) { possibleActions.add(new GameAction(GameAction.REDO)); } *************** *** 674,677 **** --- 719,725 ---- public void processOnReload(List<PossibleAction> actions) throws Exception { + NDC.clear(); + NDC.push (GM_KEY); + for (PossibleAction action : actions) { *************** *** 696,700 **** new AddToList<PossibleAction>(executedActions, action, "ExecutedActions"); ! if (MoveSet.isOpen()) MoveSet.finish(); } } --- 744,748 ---- new AddToList<PossibleAction>(executedActions, action, "ExecutedActions"); ! if (moveStack.isOpen()) moveStack.finish(); } } *************** *** 986,990 **** // TODO The below should be merged into activate() if (phase.doPrivatesClose()) { ! instance.companyManager.closeAllPrivates(); } } --- 1034,1038 ---- // TODO The below should be merged into activate() if (phase.doPrivatesClose()) { ! companyManager.closeAllPrivates(); } } *************** *** 1136,1138 **** --- 1184,1190 ---- } + public MoveStack getMoveStack () { + return moveStack; + } + } Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Round.java 6 Oct 2009 18:34:04 -0000 1.26 --- Round.java 7 Oct 2009 19:00:38 -0000 1.27 *************** *** 12,16 **** import rails.game.action.*; import rails.game.move.CashMove; ! import rails.game.move.MoveSet; import rails.game.special.SpecialPropertyI; import rails.game.state.BooleanState; --- 12,16 ---- import rails.game.action.*; import rails.game.move.CashMove; ! import rails.game.move.MoveStack; import rails.game.special.SpecialPropertyI; import rails.game.state.BooleanState; *************** *** 41,44 **** --- 41,46 ---- protected BooleanState wasInterrupted = new BooleanState ("RoundInterrupted", false); + protected MoveStack moveStack = null; + /** * Constructor with the GameManager, will call setGameManager with the parameter to initialize *************** *** 63,66 **** --- 65,70 ---- stockMarket = aGameManager.getStockMarket(); mapManager = aGameManager.getMapManager(); + + moveStack = aGameManager.getMoveStack(); } *************** *** 167,171 **** } ! MoveSet.start(true); if (exchanged > 0) { --- 171,175 ---- } ! moveStack.start(true); if (exchanged > 0) { *************** *** 264,268 **** int unsoldPercentage = company.getUnsoldPercentage(); - if (unsoldPercentage <= 100 - company.getFloatPercentage()) { // Company floats --- 268,271 ---- Index: ShareSellingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/ShareSellingRound.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ShareSellingRound.java 6 Oct 2009 18:34:04 -0000 1.23 --- ShareSellingRound.java 7 Oct 2009 19:00:38 -0000 1.24 *************** *** 10,14 **** import rails.game.action.PossibleAction; import rails.game.action.SellShares; - import rails.game.move.MoveSet; import rails.game.state.IntegerState; import rails.util.LocalText; --- 10,13 ---- *************** *** 41,45 **** } ! public void start(Player sellingPlayer, int cashToRaise, PublicCompanyI unsellableCompany) { log.info("Share selling round started, player=" --- 40,44 ---- } ! public void start(Player sellingPlayer, int cashToRaise, PublicCompanyI unsellableCompany) { log.info("Share selling round started, player=" *************** *** 323,327 **** } ! MoveSet.start(true); ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", --- 322,326 ---- } ! moveStack.start(true); ReportBuffer.add(LocalText.getText("SELL_SHARES_LOG", *************** *** 353,357 **** } } ! company.adjustSharePrice (SOLD, numberToSell, gameManager.getStockMarket()); // Check if we still have the presidency --- 352,356 ---- } } ! company.adjustSharePrice (SOLD, numberToSell, gameManager.getStockMarket()); // Check if we still have the presidency Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** OperatingRound.java 6 Oct 2009 18:34:04 -0000 1.70 --- OperatingRound.java 7 Oct 2009 19:00:38 -0000 1.71 *************** *** 5,9 **** import rails.game.action.*; ! import rails.game.move.*; import rails.game.special.*; import rails.game.state.IntegerState; --- 5,10 ---- import rails.game.action.*; ! import rails.game.move.CashMove; ! import rails.game.move.MapChange; import rails.game.special.*; import rails.game.state.IntegerState; *************** *** 155,165 **** 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()); --- 156,164 ---- if (operate) { StringBuffer msg = new StringBuffer(); for (PublicCompanyI company : operatingCompanyArray) { msg.append(",").append(company.getName()); } ! if (msg.length() > 0) msg.deleteCharAt(0); log.info("Initial operating sequence is "+msg.toString()); *************** *** 404,408 **** /* End of validation, start of execution */ ! MoveSet.start(true); if (tile != null) { --- 403,407 ---- /* End of validation, start of execution */ ! moveStack.start(true); if (tile != null) { *************** *** 572,576 **** /* End of validation, start of execution */ ! MoveSet.start(true); if (hex.layBaseToken(operatingCompany, station)) { --- 571,575 ---- /* End of validation, start of execution */ ! moveStack.start(true); if (hex.layBaseToken(operatingCompany, station)) { *************** *** 669,673 **** /* End of validation, start of execution */ ! MoveSet.start(true); if (hex.layBonusToken(token, gameManager.getPhaseManager())) { --- 668,672 ---- /* End of validation, start of execution */ ! moveStack.start(true); if (hex.layBonusToken(token, gameManager.getPhaseManager())) { *************** *** 734,738 **** /* End of validation, start of execution */ ! MoveSet.start(true); new CashMove (operatingCompany, seller, cost); --- 733,737 ---- /* End of validation, start of execution */ ! moveStack.start(true); new CashMove (operatingCompany, seller, cost); *************** *** 766,770 **** } ! MoveSet.start(true); int remainingAmount = checkForDeductions (action); --- 765,769 ---- } ! moveStack.start(true); int remainingAmount = checkForDeductions (action); *************** *** 1176,1180 **** public void skip() { log.debug("Skip step " + stepObject.intValue()); ! MoveSet.start(true); nextStep(); } --- 1175,1179 ---- public void skip() { log.debug("Skip step " + stepObject.intValue()); ! moveStack.start(true); nextStep(); } *************** *** 1201,1205 **** } ! MoveSet.start(false); nextStep(); --- 1200,1204 ---- } ! moveStack.start(false); nextStep(); *************** *** 1379,1383 **** /* End of validation, start of execution */ ! MoveSet.start(true); PhaseI previousPhase = getCurrentPhase(); --- 1378,1382 ---- /* End of validation, start of execution */ ! moveStack.start(true); PhaseI previousPhase = getCurrentPhase(); *************** *** 1528,1534 **** /* End of validation, start of execution */ ! MoveSet.start(true); // ! if (action.isForced()) MoveSet.setLinkedToPrevious(); pool.buyTrain(train, 0); --- 1527,1533 ---- /* End of validation, start of execution */ ! moveStack.start(true); // ! if (action.isForced()) moveStack.setLinkedToPrevious(); pool.buyTrain(train, 0); *************** *** 1645,1649 **** } ! MoveSet.start(true); operatingCompany.buyPrivate(privateCompany, player.getPortfolio(), --- 1644,1648 ---- } ! moveStack.start(true); operatingCompany.buyPrivate(privateCompany, player.getPortfolio(), *************** *** 1662,1666 **** if (company.hasDestination() && !company.hasReachedDestination()) { ! if (!MoveSet.isOpen()) MoveSet.start(true); company.setReachedDestination(true); ReportBuffer.add(LocalText.getText("DestinationReached", --- 1661,1665 ---- if (company.hasDestination() && !company.hasReachedDestination()) { ! if (!moveStack.isOpen()) moveStack.start(true); company.setReachedDestination(true); ReportBuffer.add(LocalText.getText("DestinationReached", *************** *** 1691,1695 **** } ! MoveSet.start(true); executeTakeLoans (action); --- 1690,1694 ---- } ! moveStack.start(true); executeTakeLoans (action); *************** *** 1810,1814 **** log.info("President has $"+presCash+", so $"+cashToBeRaisedByPresident+" must be added"); savedAction = action; ! MoveSet.start(true); gameManager.startShareSellingRound(operatingCompany.getPresident(), cashToBeRaisedByPresident, operatingCompany); --- 1809,1813 ---- log.info("President has $"+presCash+", so $"+cashToBeRaisedByPresident+" must be added"); savedAction = action; ! moveStack.start(true); gameManager.startShareSellingRound(operatingCompany.getPresident(), cashToBeRaisedByPresident, operatingCompany); *************** *** 1817,1821 **** } ! MoveSet.start(true); if (repayment > 0) executeRepayLoans (action); --- 1816,1820 ---- } ! moveStack.start(true); if (repayment > 0) executeRepayLoans (action); Index: StartRound_1830.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound_1830.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** StartRound_1830.java 11 Sep 2009 19:27:23 -0000 1.20 --- StartRound_1830.java 7 Oct 2009 19:00:38 -0000 1.21 *************** *** 3,7 **** import rails.game.action.*; - import rails.game.move.MoveSet; import rails.util.LocalText; --- 3,6 ---- *************** *** 154,158 **** } ! /*----- MoveSet methods -----*/ /** * The current player bids on a given start item. --- 153,157 ---- } ! /*----- moveStack methods -----*/ /** * The current player bids on a given start item. *************** *** 234,238 **** } ! MoveSet.start(false); item.setBid(bidAmount, player); --- 233,237 ---- } ! moveStack.start(false); item.setBid(bidAmount, player); *************** *** 288,292 **** ReportBuffer.add(LocalText.getText("PASSES", playerName)); ! MoveSet.start(false); numPasses.add(1); --- 287,291 ---- ReportBuffer.add(LocalText.getText("PASSES", playerName)); ! moveStack.start(false); numPasses.add(1); Index: StartRound_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StartRound_1835.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** StartRound_1835.java 19 Jul 2009 19:24:21 -0000 1.20 --- StartRound_1835.java 7 Oct 2009 19:00:38 -0000 1.21 *************** *** 6,10 **** import rails.game.action.*; - import rails.game.move.MoveSet; import rails.game.state.IntegerState; import rails.util.LocalText; --- 6,9 ---- *************** *** 147,151 **** } ! /*----- MoveSet methods -----*/ @Override --- 146,150 ---- } ! /*----- moveStack methods -----*/ @Override *************** *** 242,246 **** ReportBuffer.add(LocalText.getText("PASSES", playerName)); ! MoveSet.start(false); numPasses.add(1); --- 241,245 ---- ReportBuffer.add(LocalText.getText("PASSES", playerName)); ! moveStack.start(false); numPasses.add(1); Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** StockRound.java 6 Oct 2009 18:34:04 -0000 1.45 --- StockRound.java 7 Oct 2009 19:00:38 -0000 1.46 *************** *** 4,8 **** import rails.game.action.*; ! import rails.game.move.*; import rails.game.special.*; import rails.game.state.*; --- 4,9 ---- import rails.game.action.*; ! import rails.game.move.CashMove; ! import rails.game.move.DoubleMapChange; import rails.game.special.*; import rails.game.state.*; *************** *** 524,528 **** } ! MoveSet.start(true); // All is OK, now start the company --- 525,529 ---- } ! moveStack.start(true); // All is OK, now start the company *************** *** 702,706 **** // All seems OK, now buy the shares. ! MoveSet.start(true); CashHolder priceRecipient = getSharePriceRecipient (cert, cash); --- 703,707 ---- // All seems OK, now buy the shares. ! moveStack.start(true); CashHolder priceRecipient = getSharePriceRecipient (cert, cash); *************** *** 953,957 **** } ! MoveSet.start(true); if (numberToSell == 1) { --- 954,958 ---- } ! moveStack.start(true); if (numberToSell == 1) { *************** *** 1030,1034 **** if (sp instanceof ExchangeForShare) { ! boolean result = ((ExchangeForShare) sp).execute(this); if (result) hasActed.set(true); return result; --- 1031,1035 ---- if (sp instanceof ExchangeForShare) { ! boolean result = executeExchangeForShare((ExchangeForShare) sp); if (result) hasActed.set(true); return result; *************** *** 1039,1042 **** --- 1040,1113 ---- } + public boolean executeExchangeForShare (ExchangeForShare sp) { + + PublicCompanyI publicCompany = + companyManager.getPublicCompany(sp.getPublicCompanyName()); + PrivateCompanyI privateCompany = sp.getCompany(); + Portfolio portfolio = privateCompany.getPortfolio(); + Player player = null; + String errMsg = null; + boolean ipoHasShare = ipo.getShare(publicCompany) >= sp.getShare(); + boolean poolHasShare = pool.getShare(publicCompany) >= sp.getShare(); + + while (true) { + + /* Check if the private is owned by a player */ + if (!(portfolio.getOwner() instanceof Player)) { + errMsg = + LocalText.getText("PrivateIsNotOwnedByAPlayer", + privateCompany.getName()); + break; + } + + player = (Player) portfolio.getOwner(); + + /* Check if a share is available */ + if (!ipoHasShare && !poolHasShare) { + errMsg = + LocalText.getText("NoSharesAvailable", + publicCompany.getName()); + break; + } + /* Check if the player has room for a share of this company */ + if (!mayPlayerBuyCompanyShare(player, publicCompany, 1)) { + // TODO: Not nice to use '1' here, should be percentage. + errMsg = + LocalText.getText("WouldExceedHoldLimit", + String.valueOf(gameManager.getPlayerShareLimit())); + break; + } + break; + } + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText( + "CannotSwapPrivateForCertificate", + player.getName(), + privateCompany.getName(), + sp.getShare(), + publicCompany.getName(), + errMsg )); + return false; + } + + moveStack.start(true); + + Certificate cert = + ipoHasShare ? ipo.findCertificate(publicCompany, + false) : pool.findCertificate(publicCompany, + false); + //player.buy(cert, 0); + cert.moveTo(player.getPortfolio()); + ReportBuffer.add(LocalText.getText("SwapsPrivateForCertificate", + player.getName(), + privateCompany.getName(), + sp.getShare(), + publicCompany.getName())); + sp.setExercised(); + privateCompany.setClosed(); + + return true; + } + /** * The current Player passes or is done. *************** *** 1054,1058 **** } ! MoveSet.start(false); if (hasActed.booleanValue()) { --- 1125,1129 ---- } ! moveStack.start(false); if (hasActed.booleanValue()) { Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GameManagerI.java 6 Oct 2009 18:34:04 -0000 1.13 --- GameManagerI.java 7 Oct 2009 19:00:38 -0000 1.14 *************** *** 6,9 **** --- 6,10 ---- import rails.game.action.PossibleAction; import rails.game.model.ModelObject; + import rails.game.move.MoveStack; import rails.game.move.MoveableHolderI; import rails.game.special.SpecialPropertyI; *************** *** 178,180 **** --- 179,184 ---- public <T extends SpecialPropertyI> List<T> getSpecialProperties( Class<T> clazz, boolean includeExercised); + + public MoveStack getMoveStack (); + } \ No newline at end of file |