From: <ev...@us...> - 2011-04-29 13:04:02
|
Revision: 1539 http://rails.svn.sourceforge.net/rails/?rev=1539&view=rev Author: evos Date: 2011-04-29 13:03:56 +0000 (Fri, 29 Apr 2011) Log Message: ----------- 18TN: Enabled private purchase in first OR turn at fixed price. Modified Paths: -------------- trunk/18xx/LocalisedText.properties trunk/18xx/data/18TN/Game.xml trunk/18xx/rails/game/OperatingRound.java trunk/18xx/rails/ui/swing/ORUIManager.java Added Paths: ----------- trunk/18xx/rails/game/specific/_18TN/ trunk/18xx/rails/game/specific/_18TN/OperatingRound_18TN.java Modified: trunk/18xx/LocalisedText.properties =================================================================== --- trunk/18xx/LocalisedText.properties 2011-04-28 19:07:07 UTC (rev 1538) +++ trunk/18xx/LocalisedText.properties 2011-04-29 13:03:56 UTC (rev 1539) @@ -39,7 +39,7 @@ BUY_WHICH_PRIVATE=Buy which private? BUY_WHICH_TRAIN=Buy which train? # Note: in the next item, {0} MUST be in front -BuyPrivatePrompt={0} from {1} for {2}...{3} +BuyPrivatePrompt={0} from {1} for {2} BankIsBrokenDisplayText=Bank is broken. Play continues until {0} BankIsBrokenReportText=Bank is broken gameOverPlaySetOfORs=the current set of operating rounds is finished. Modified: trunk/18xx/data/18TN/Game.xml =================================================================== --- trunk/18xx/data/18TN/Game.xml 2011-04-28 19:07:07 UTC (rev 1538) +++ trunk/18xx/data/18TN/Game.xml 2011-04-29 13:03:56 UTC (rev 1539) @@ -23,6 +23,7 @@ <StockRound> <NoSaleInFirstSR/> </StockRound> + <OperatingRound class="rails.game.specific._18TN.OperatingRound_18TN"/> </GameParameters> <EndOfGame> <Bankruptcy/> Modified: trunk/18xx/rails/game/OperatingRound.java =================================================================== --- trunk/18xx/rails/game/OperatingRound.java 2011-04-28 19:07:07 UTC (rev 1538) +++ trunk/18xx/rails/game/OperatingRound.java 2011-04-29 13:03:56 UTC (rev 1539) @@ -2012,7 +2012,7 @@ lowerPrice = privateCompany.getLowerPrice(); // Is private buying allowed? - if (!getCurrentPhase().isPrivateSellingAllowed()) { + if (!isPrivateSellingAllowed()) { errMsg = LocalText.getText("PrivateBuyingIsNotAllowed"); break; } @@ -2417,7 +2417,7 @@ } // Can private companies be bought? - if (getCurrentPhase().isPrivateSellingAllowed()) { + if (isPrivateSellingAllowed()) { // Create a list of players with the current one in front int currentPlayerIndex = operatingCompany.get().getPresident().getIndex(); @@ -2430,24 +2430,14 @@ player = players.get(i % numberOfPlayers); for (PrivateCompanyI privComp : player.getPortfolio().getPrivateCompanies()) { - // start: br - // check to see if the private can be sold to a company if (!privComp.tradeableToCompany()) { continue; } - // changed so that Private companies know what prices they can be sold for - minPrice = privComp.getLowerPrice(); - if (minPrice == PrivateCompanyI.NO_PRICE_LIMIT) { - minPrice = 0; - } + minPrice = getPrivateMinimumPrice (privComp); - maxPrice = privComp.getUpperPrice(); - if (maxPrice == PrivateCompanyI.NO_PRICE_LIMIT) { - maxPrice = operatingCompany.get().getCash(); - } - // end: br + maxPrice = getPrivateMaximumPrice (privComp); possibleActions.add(new BuyPrivate(privComp, minPrice, maxPrice)); @@ -2526,6 +2516,26 @@ return true; } + protected boolean isPrivateSellingAllowed() { + return getCurrentPhase().isPrivateSellingAllowed(); + } + + protected int getPrivateMinimumPrice (PrivateCompanyI privComp) { + int minPrice = privComp.getLowerPrice(); + if (minPrice == PrivateCompanyI.NO_PRICE_LIMIT) { + minPrice = 0; + } + return minPrice; + } + + protected int getPrivateMaximumPrice (PrivateCompanyI privComp) { + int maxPrice = privComp.getUpperPrice(); + if (maxPrice == PrivateCompanyI.NO_PRICE_LIMIT) { + maxPrice = operatingCompany.get().getCash(); + } + return maxPrice; + } + protected void prepareRevenueAndDividendAction () { // There is only revenue if there are any trains Added: trunk/18xx/rails/game/specific/_18TN/OperatingRound_18TN.java =================================================================== --- trunk/18xx/rails/game/specific/_18TN/OperatingRound_18TN.java (rev 0) +++ trunk/18xx/rails/game/specific/_18TN/OperatingRound_18TN.java 2011-04-29 13:03:56 UTC (rev 1539) @@ -0,0 +1,46 @@ +package rails.game.specific._18TN; + +import java.util.List; + +import rails.game.*; + +public class OperatingRound_18TN extends OperatingRound { + + public OperatingRound_18TN (GameManagerI gameManager) { + super (gameManager); + } + + protected boolean isPrivateSellingAllowed() { + return getCurrentPhase().isPrivateSellingAllowed() + // 18TN special + || !operatingCompany.get().hasOperated() && !ownsPrivate(operatingCompany.get()); + } + + protected int getPrivateMinimumPrice (PrivateCompanyI privComp) { + int minPrice = privComp.getLowerPrice(); + if (minPrice == PrivateCompanyI.NO_PRICE_LIMIT) { + minPrice = 0; + } else if (!operatingCompany.get().hasOperated()) { + // 18TN special + minPrice = privComp.getBasePrice(); + } + return minPrice; + } + + protected int getPrivateMaximumPrice (PrivateCompanyI privComp) { + int maxPrice = privComp.getUpperPrice(); + if (maxPrice == PrivateCompanyI.NO_PRICE_LIMIT) { + maxPrice = operatingCompany.get().getCash(); + } else if (!operatingCompany.get().hasOperated()) { + // 18TN special + maxPrice = privComp.getBasePrice(); + } + return maxPrice; + } + + private boolean ownsPrivate (PublicCompanyI company) { + List<PrivateCompanyI> privates = company.getPortfolio().getPrivateCompanies(); + return privates != null && !privates.isEmpty(); + } + +} Property changes on: trunk/18xx/rails/game/specific/_18TN/OperatingRound_18TN.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/18xx/rails/ui/swing/ORUIManager.java =================================================================== --- trunk/18xx/rails/ui/swing/ORUIManager.java 2011-04-28 19:07:07 UTC (rev 1538) +++ trunk/18xx/rails/ui/swing/ORUIManager.java 2011-04-29 13:03:56 UTC (rev 1539) @@ -1255,13 +1255,21 @@ String chosenOption; BuyPrivate chosenAction = null; int minPrice = 0, maxPrice = 0; + String priceRange; for (BuyPrivate action : privates) { + minPrice = action.getMinimumPrice(); + maxPrice = action.getMaximumPrice(); + if (minPrice < maxPrice) { + priceRange = Bank.format(minPrice) + "..." + Bank.format(maxPrice); + } else { + priceRange = Bank.format(maxPrice); + } + privatesForSale.add(LocalText.getText("BuyPrivatePrompt", action.getPrivateCompany().getName(), action.getPrivateCompany().getPortfolio().getName(), - Bank.format(action.getMinimumPrice()), - Bank.format(action.getMaximumPrice()) )); + priceRange )); } if (privatesForSale.size() > 0) { @@ -1276,21 +1284,24 @@ chosenAction = privates.get(index); minPrice = chosenAction.getMinimumPrice(); maxPrice = chosenAction.getMaximumPrice(); - String price = - JOptionPane.showInputDialog(orWindow, - LocalText.getText("WHICH_PRIVATE_PRICE", - chosenOption, - Bank.format(minPrice), - Bank.format(maxPrice) ), - LocalText.getText("WHICH_PRICE"), - JOptionPane.QUESTION_MESSAGE); - try { - amount = Integer.parseInt(price); - } catch (NumberFormatException e) { - amount = 0; // This will generally be refused. + if (minPrice < maxPrice) { + String price = + JOptionPane.showInputDialog(orWindow, + LocalText.getText("WHICH_PRIVATE_PRICE", + chosenOption, + Bank.format(minPrice), + Bank.format(maxPrice) ), + LocalText.getText("WHICH_PRICE"), + JOptionPane.QUESTION_MESSAGE); + try { + amount = Integer.parseInt(price); + } catch (NumberFormatException e) { + amount = 0; // This will generally be refused. + } + chosenAction.setPrice(amount); + } else { + chosenAction.setPrice(maxPrice); } - chosenAction.setPrice(amount); - if (orWindow.process(chosenAction)) { updateMessage(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |