From: Erik V. <ev...@us...> - 2009-10-07 19:00:49
|
Update of /cvsroot/rails/18xx/rails/game/special In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv9081/rails/game/special Modified Files: ExchangeForShare.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: ExchangeForShare.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/special/ExchangeForShare.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ExchangeForShare.java 3 Oct 2009 13:59:33 -0000 1.14 --- ExchangeForShare.java 7 Oct 2009 19:00:38 -0000 1.15 *************** *** 3,7 **** import rails.game.*; - import rails.game.move.MoveSet; import rails.util.*; --- 3,6 ---- *************** *** 36,110 **** } - public boolean execute(StockRound round) { - - publicCompany = - Game.getCompanyManager().getPublicCompany(publicCompanyName); - - Portfolio portfolio = privateCompany.getPortfolio(); - Player player = null; - String errMsg = null; - Bank bank = Bank.getInstance(); - boolean ipoHasShare = bank.getIpo().getShare(publicCompany) >= share; - boolean poolHasShare = bank.getPool().getShare(publicCompany) >= share; - - 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", - publicCompanyName); - break; - } - /* Check if the player has room for a share of this company */ - if (!round.mayPlayerBuyCompanyShare(player, publicCompany, 1)) { - // TODO: Not nice to use '1' here, should be percentage. - errMsg = - LocalText.getText("WouldExceedHoldLimit", - String.valueOf(round.getGameManager().getPlayerShareLimit())); - break; - } - break; - } - if (errMsg != null) { - DisplayBuffer.add(LocalText.getText( - "CannotSwapPrivateForCertificate", - player.getName(), - privateCompany.getName(), - share, - publicCompanyName, - errMsg )); - return false; - } - - MoveSet.start(true); - - Certificate cert = - ipoHasShare ? bank.getIpo().findCertificate(publicCompany, - false) : bank.getPool().findCertificate(publicCompany, - false); - //player.buy(cert, 0); - cert.moveTo(player.getPortfolio()); - ReportBuffer.add(LocalText.getText("SwapsPrivateForCertificate", - player.getName(), - privateCompany.getName(), - share, - publicCompanyName )); - setExercised(); - privateCompany.setClosed(); - - return true; - } - /** * @return Returns the privateCompany. --- 35,38 ---- |