From: <ev...@us...> - 2011-03-17 21:16:50
|
Revision: 1500 http://rails.svn.sourceforge.net/rails/?rev=1500&view=rev Author: evos Date: 2011-03-17 21:16:44 +0000 (Thu, 17 Mar 2011) Log Message: ----------- Fix for bug 3207870: added new class ShareSellingRound_1856 with code (copied from StockRound_1856) to prevent that a 5% CGR sale during emergency selling lowers the CGR price. Modified Paths: -------------- trunk/18xx/data/1856/Game.xml trunk/18xx/rails/game/GameManager.java Added Paths: ----------- trunk/18xx/rails/game/specific/_1856/ShareSellingRound_1856.java Modified: trunk/18xx/data/1856/Game.xml =================================================================== --- trunk/18xx/data/1856/Game.xml 2011-03-15 22:27:07 UTC (rev 1499) +++ trunk/18xx/data/1856/Game.xml 2011-03-17 21:16:44 UTC (rev 1500) @@ -17,6 +17,7 @@ <NoSaleOfJustBoughtShare/> </StockRound> <OperatingRound class="rails.game.specific._1856.OperatingRound_1856"/> + <ShareSellingRound class="rails.game.specific._1856.ShareSellingRound_1856"/> <PlayerShareLimit percentage="60"/> <BankPoolLimit percentage="50"/> </GameParameters> Modified: trunk/18xx/rails/game/GameManager.java =================================================================== --- trunk/18xx/rails/game/GameManager.java 2011-03-15 22:27:07 UTC (rev 1499) +++ trunk/18xx/rails/game/GameManager.java 2011-03-17 21:16:44 UTC (rev 1500) @@ -37,6 +37,8 @@ protected Class<? extends StockRound> stockRoundClass = StockRound.class; protected Class<? extends OperatingRound> operatingRoundClass = OperatingRound.class; + protected Class<? extends ShareSellingRound> shareSellingRoundClass + = ShareSellingRound.class; // Variable UI Class names protected String gameUIManagerClassName = GuiDef.getDefaultClassName(GuiDef.ClassName.GAME_UI_MANAGER); @@ -176,7 +178,7 @@ protected List<String> nextPlayerMessages = new ArrayList<String>(); /** - * The ReportBuffer collectes messages to be shown in the Game Report. + * The ReportBuffer collects messages to be shown in the Game Report. */ protected ReportBuffer reportBuffer; @@ -356,6 +358,20 @@ } } + // ShareSellingRound class + Tag ssrTag = gameParmTag.getChild("ShareSellingRound"); + if (ssrTag != null) { + String ssrClassName = + ssrTag.getAttributeAsString("class", "rails.game.ShareSellingRound"); + try { + shareSellingRoundClass = + Class.forName(ssrClassName).asSubclass(ShareSellingRound.class); + } catch (ClassNotFoundException e) { + throw new ConfigurationException("Cannot find class " + + ssrClassName, e); + } + } + /* Max. % of shares of one company that a player may hold */ Tag shareLimitTag = gameParmTag.getChild("PlayerShareLimit"); if (shareLimitTag != null) { @@ -756,7 +772,7 @@ interruptedRound = getCurrentRound(); // check if other companies can be dumped - createRound (ShareSellingRound.class, interruptedRound) + createRound (shareSellingRoundClass, interruptedRound) .start(player, cashToRaise, cashNeedingCompany, !problemDumpOtherCompanies || forcedSellingCompanyDump); // the last parameter indicates if the dump of other companies is allowed, either this is explicit or Added: trunk/18xx/rails/game/specific/_1856/ShareSellingRound_1856.java =================================================================== --- trunk/18xx/rails/game/specific/_1856/ShareSellingRound_1856.java (rev 0) +++ trunk/18xx/rails/game/specific/_1856/ShareSellingRound_1856.java 2011-03-17 21:16:44 UTC (rev 1500) @@ -0,0 +1,43 @@ +package rails.game.specific._1856; + +import rails.game.*; +import rails.game.action.BuyCertificate; +import rails.game.state.IntegerState; +import rails.util.LocalText; + +/** Needed to copy behaviour on share selling from StockRound_1856. */ +public class ShareSellingRound_1856 extends ShareSellingRound { + + /* Cope with multiple 5% share sales in one turn */ + private IntegerState sharesSoldSoFar; + private IntegerState squaresDownSoFar; + + public ShareSellingRound_1856 (GameManagerI aGameManager, + RoundI parentRound) { + super (aGameManager, parentRound); + + sharesSoldSoFar = new IntegerState("CGR_SharesSoldSoFar", 0); + squaresDownSoFar = new IntegerState("CGR_SquaresDownSoFar", 0); + } + + @Override + protected void adjustSharePrice (PublicCompanyI company, int numberSold, boolean soldBefore) { + + if (!company.canSharePriceVary()) return; + + int numberOfSpaces = numberSold; + if (company instanceof PublicCompany_CGR) { + if (company.getShareUnit() == 5) { + // Take care for selling 5% shares in multiple blocks per turn + numberOfSpaces + = (sharesSoldSoFar.intValue() + numberSold)/2 + - squaresDownSoFar.intValue(); + sharesSoldSoFar.add(numberSold); + squaresDownSoFar.add(numberOfSpaces); + } + } + + super.adjustSharePrice (company, numberOfSpaces, soldBefore); + } + +} Property changes on: trunk/18xx/rails/game/specific/_1856/ShareSellingRound_1856.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |