From: <ev...@us...> - 2010-09-07 19:14:54
|
Revision: 1414 http://rails.svn.sourceforge.net/rails/?rev=1414&view=rev Author: evos Date: 2010-09-07 19:14:48 +0000 (Tue, 07 Sep 2010) Log Message: ----------- Removed redundant actions (such as presidency swapping) when a company price token reaches a "close" area. Modified Paths: -------------- trunk/18xx/rails/game/ShareSellingRound.java trunk/18xx/rails/game/StockRound.java Modified: trunk/18xx/rails/game/ShareSellingRound.java =================================================================== --- trunk/18xx/rails/game/ShareSellingRound.java 2010-09-06 21:20:12 UTC (rev 1413) +++ trunk/18xx/rails/game/ShareSellingRound.java 2010-09-07 19:14:48 UTC (rev 1414) @@ -126,27 +126,27 @@ /* * If the current Player is president, check if he can dump the * presidency onto someone else - * + * * Two reasons for the check: * A) President not allowed to sell that company * Thus keep enough shares to stay president - * + * * Example here * share = 60%, other player holds 40%, maxShareToSell > 30% - * => requires selling of president + * => requires selling of president * B) President allowed to sell that company * In that case the president share can be sold - * + * * Example here * share = 60%, , president share = 20%, maxShareToSell > 40% - * => requires selling of president + * => requires selling of president */ if (company.getPresident() == currentPlayer) { int presidentShare = company.getCertificates().get(0).getShare(); boolean dumpPossible; - log.debug("Forced selling check: company = " + company + + log.debug("Forced selling check: company = " + company + ", share = " + share + ", maxShareToSell = " + maxShareToSell); if (company == cashNeedingCompany || !dumpOtherCompaniesAllowed) { // case A: selling of president not allowed (either company triggered share selling or no dump of others) @@ -377,43 +377,46 @@ companyName, Bank.format(numberSold * price) )); - // Check if the presidency has changed - if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) { - ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", - dumpedPlayer.getName(), - companyName)); - // First swap the certificates - Portfolio dumpedPortfolio = dumpedPlayer.getPortfolio(); - List<PublicCertificateI> swapped = - portfolio.swapPresidentCertificate(company, dumpedPortfolio); - for (int i = 0; i < presSharesToSell; i++) { - certsToSell.add(swapped.get(i)); - } - } - - // Transfer the sold certificates - for (PublicCertificateI cert2 : certsToSell) { - if (cert2 != null) { - executeTradeCertificate (cert2, pool, cert2.getShares() * price); - } - } boolean soldBefore = sellPrices.containsKey(companyName); adjustSharePrice (company, numberSold, soldBefore); - // Check if we still have the presidency - if (currentPlayer == company.getPresident()) { - Player otherPlayer; - for (int i = currentIndex + 1; i < currentIndex + numberOfPlayers; i++) { - otherPlayer = gameManager.getPlayerByIndex(i); - if (otherPlayer.getPortfolio().getShare(company) > portfolio.getShare(company)) { - portfolio.swapPresidentCertificate(company, - otherPlayer.getPortfolio()); - ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", - otherPlayer.getName(), - company.getName())); - break; - } - } + if (!company.isClosed()) { + // Check if the presidency has changed + if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) { + ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", + dumpedPlayer.getName(), + companyName)); + // First swap the certificates + Portfolio dumpedPortfolio = dumpedPlayer.getPortfolio(); + List<PublicCertificateI> swapped = + portfolio.swapPresidentCertificate(company, dumpedPortfolio); + for (int i = 0; i < presSharesToSell; i++) { + certsToSell.add(swapped.get(i)); + } + } + + // Transfer the sold certificates + for (PublicCertificateI cert2 : certsToSell) { + if (cert2 != null) { + executeTradeCertificate (cert2, pool, cert2.getShares() * price); + } + } + + // Check if we still have the presidency + if (currentPlayer == company.getPresident()) { + Player otherPlayer; + for (int i = currentIndex + 1; i < currentIndex + numberOfPlayers; i++) { + otherPlayer = gameManager.getPlayerByIndex(i); + if (otherPlayer.getPortfolio().getShare(company) > portfolio.getShare(company)) { + portfolio.swapPresidentCertificate(company, + otherPlayer.getPortfolio()); + ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", + otherPlayer.getName(), + company.getName())); + break; + } + } + } } cashToRaise.add(-numberSold * price); Modified: trunk/18xx/rails/game/StockRound.java =================================================================== --- trunk/18xx/rails/game/StockRound.java 2010-09-06 21:20:12 UTC (rev 1413) +++ trunk/18xx/rails/game/StockRound.java 2010-09-07 19:14:48 UTC (rev 1414) @@ -417,8 +417,8 @@ * original price is still valid */ price = getCurrentSellPrice(company); - - // removed as this is done in getCurrentSellPrice + + // removed as this is done in getCurrentSellPrice // price /= company.getShareUnitsForSharePrice(); /* Allow for different share units (as in 1835) */ @@ -1070,44 +1070,51 @@ Bank.format(numberSold * price * shareUnits) )); } - // Check if the presidency has changed - if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) { - ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", - dumpedPlayer.getName(), - companyName )); - // First swap the certificates - Portfolio dumpedPortfolio = dumpedPlayer.getPortfolio(); - List<PublicCertificateI> swapped = - portfolio.swapPresidentCertificate(company, dumpedPortfolio); - for (int i = 0; i < presSharesToSell; i++) { - certsToSell.add(swapped.get(i)); - } - } + // PROVISIONALLY MOVED UPWARDS + adjustSharePrice (company, numberSold, soldBefore); - // Transfer the sold certificates - Iterator<PublicCertificateI> it = certsToSell.iterator(); - while (it.hasNext()) { - cert = it.next(); - if (cert != null) { - executeTradeCertificate(cert, pool, cert.getShares() * price); + if (!company.isClosed()) { + + // Check if the presidency has changed + if (presCert != null && dumpedPlayer != null && presSharesToSell > 0) { + ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", + dumpedPlayer.getName(), + companyName )); + // First swap the certificates + Portfolio dumpedPortfolio = dumpedPlayer.getPortfolio(); + List<PublicCertificateI> swapped = + portfolio.swapPresidentCertificate(company, dumpedPortfolio); + for (int i = 0; i < presSharesToSell; i++) { + certsToSell.add(swapped.get(i)); + } } - } - adjustSharePrice (company, numberSold, soldBefore); - // Check if we still have the presidency - if (currentPlayer == company.getPresident()) { - Player otherPlayer; - for (int i = currentIndex + 1; i < currentIndex + numberOfPlayers; i++) { - otherPlayer = gameManager.getPlayerByIndex(i); - if (otherPlayer.getPortfolio().getShare(company) > portfolio.getShare(company)) { - portfolio.swapPresidentCertificate(company, - otherPlayer.getPortfolio()); - ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", - otherPlayer.getName(), - company.getName() )); - break; - } - } + // Transfer the sold certificates + Iterator<PublicCertificateI> it = certsToSell.iterator(); + while (it.hasNext()) { + cert = it.next(); + if (cert != null) { + executeTradeCertificate(cert, pool, cert.getShares() * price); + } + } + // PROVISIONALLY MOVED UPWARDS + //adjustSharePrice (company, numberSold, soldBefore); + + // Check if we still have the presidency + if (currentPlayer == company.getPresident()) { + Player otherPlayer; + for (int i = currentIndex + 1; i < currentIndex + numberOfPlayers; i++) { + otherPlayer = gameManager.getPlayerByIndex(i); + if (otherPlayer.getPortfolio().getShare(company) > portfolio.getShare(company)) { + portfolio.swapPresidentCertificate(company, + otherPlayer.getPortfolio()); + ReportBuffer.add(LocalText.getText("IS_NOW_PRES_OF", + otherPlayer.getName(), + company.getName() )); + break; + } + } + } } // Remember that the player has sold this company this round. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |