From: Dr. M. B. <neu...@us...> - 2012-03-29 09:40:00
|
rails/game/specific/_1880/StockRound_1880.java | 195 ++++++++++++++++++++++--- 1 file changed, 178 insertions(+), 17 deletions(-) New commits: commit d7be1f2a041f83d75eb725395423c3701449f022 Author: Martin <dr....@t-...> Date: Thu Mar 29 11:39:29 2012 +0200 Implemented the handling of the Flotation Check at the end of a StockRound and the fact that only owned stocks by the director of a public Company count against the floatpercentage. Conflicts: rails/game/specific/_1880/StockRound_1880.java diff --git a/rails/game/specific/_1880/StockRound_1880.java b/rails/game/specific/_1880/StockRound_1880.java index ba422f6..8ed6669 100644 --- a/rails/game/specific/_1880/StockRound_1880.java +++ b/rails/game/specific/_1880/StockRound_1880.java @@ -393,8 +393,7 @@ public class StockRound_1880 extends StockRound { } } } - } - + } /* (non-Javadoc) * @see rails.game.StockRound#finishRound() @@ -479,7 +478,6 @@ public class StockRound_1880 extends StockRound { } /* (non-Javadoc) - * @see rails.game.StockRound#useSpecialProperty(rails.game.action.UseSpecialProperty) */ @Override @@ -726,5 +724,4 @@ public class StockRound_1880 extends StockRound { action.setStartPrice(action.getPrice()); return true; } - -} +} \ No newline at end of file commit 8dcb095b0fa0f9693ec22716916581b64919ef71 Merge: b8c0ada 2f4783b Author: Martin <dr....@t-...> Date: Thu Mar 29 11:34:20 2012 +0200 Merge branch 'specific_1880' of ssh://neu...@ra.../gitroot/rails/rails into specific_1880 Conflicts: rails/game/specific/_1880/StockRound_1880.java diff --cc LICENSE index 5b6e7c6,5b6e7c6..5b6e7c6 mode 100755,100755..100644 --- a/LICENSE +++ b/LICENSE diff --cc README index 97c5c5d,97c5c5d..97c5c5d mode 100755,100755..100644 --- a/README +++ b/README diff --cc data/1830/StockMarket.xml index 770d885,770d885..770d885 mode 100755,100755..100644 --- a/data/1830/StockMarket.xml +++ b/data/1830/StockMarket.xml diff --cc data/1856/StockMarket.xml index f9c9372,f9c9372..f9c9372 mode 100755,100755..100644 --- a/data/1856/StockMarket.xml +++ b/data/1856/StockMarket.xml diff --cc data/1870/StockMarket.xml index c69c8ee,c69c8ee..c69c8ee mode 100755,100755..100644 --- a/data/1870/StockMarket.xml +++ b/data/1870/StockMarket.xml diff --cc data/18AL/StockMarket.xml index 7747579,7747579..7747579 mode 100755,100755..100644 --- a/data/18AL/StockMarket.xml +++ b/data/18AL/StockMarket.xml diff --cc data/18EU/StockMarket.xml index 6c6d780,6c6d780..6c6d780 mode 100755,100755..100644 --- a/data/18EU/StockMarket.xml +++ b/data/18EU/StockMarket.xml diff --cc doc/18oo.vsd index bbb8b9b,bbb8b9b..bbb8b9b mode 100755,100755..100644 --- a/doc/18oo.vsd +++ b/doc/18oo.vsd diff --cc make_rails_pkg.sh index ee40072,ee40072..ee40072 mode 100755,100755..100644 --- a/make_rails_pkg.sh +++ b/make_rails_pkg.sh diff --cc rails/game/specific/_1880/StockRound_1880.java index 256a82c,2f54eac..ba422f6 --- a/rails/game/specific/_1880/StockRound_1880.java +++ b/rails/game/specific/_1880/StockRound_1880.java @@@ -393,256 -394,173 +395,336 @@@ public class StockRound_1880 extends St } } - /* (non-Javadoc) - * @see rails.game.StockRound#startCompany(java.lang.String, rails.game.action.StartCompany) - */ - public boolean startCompany(String playerName, StartCompany_1880 action) { - // TODO Auto-generated method stub - if (super.startCompany(playerName, action)){ - action.setBuildingRight((PublicCompany_1880) action.getCompany(), action.buildingRightToString(action.buildingRight)); - action.setStartPrice(action.getPrice()); - return true; - } else { - return false; - } - } + + /* (non-Javadoc) + * @see rails.game.StockRound#finishRound() + */ + @Override + protected void finishRound() { + ReportBuffer.add(" "); + ReportBuffer.add(LocalText.getText("END_SR", + String.valueOf(getStockRoundNumber()))); + + if (raiseIfSoldOut) { + /* Check if any companies are sold out. */ + for (PublicCompanyI company : gameManager.getCompaniesInRunningOrder()) { + if (company.hasStockPrice() && company.isSoldOut() && (!((PublicCompany_1880) company).isCommunistPhase())) { + StockSpaceI oldSpace = company.getCurrentSpace(); + stockMarket.soldOut(company); + StockSpaceI newSpace = company.getCurrentSpace(); + if (newSpace != oldSpace) { + ReportBuffer.add(LocalText.getText("SoldOut", + company.getName(), + Bank.format(oldSpace.getPrice()), + oldSpace.getName(), + Bank.format(newSpace.getPrice()), + newSpace.getName())); + } else { + ReportBuffer.add(LocalText.getText("SoldOutNoRaise", + company.getName(), + Bank.format(newSpace.getPrice()), + newSpace.getName())); + } + } + } + } ++ ++ for (PublicCompanyI c : companyManager.getAllPublicCompanies()) { ++ if (c.hasStarted() && !c.hasFloated()) { ++ checkFlotation(c); ++ } ++ } ++ + /** At the end of each Stockround the current amount of negative cash is subject to a fine of 50 percent + * + */ + for (Player p : playerManager.getPlayers()) { + if (p.getCash() <0 ) { + int fine = p.getCash()/2; + p.addCash(-fine); + } + } + + // Report financials + ReportBuffer.add(""); + for (PublicCompanyI c : companyManager.getAllPublicCompanies()) { + if (c.hasFloated() && !c.isClosed()) { + ReportBuffer.add(LocalText.getText("Has", c.getName(), + Bank.format(c.getCash()))); + } + } + for (Player p : playerManager.getPlayers()) { + ReportBuffer.add(LocalText.getText("Has", p.getName(), + Bank.format(p.getCash()))); + } + // Inform GameManager + gameManager.nextRound(this); + } + /* (non-Javadoc) - * @see rails.game.StockRound#startCompany(java.lang.String, rails.game.action.StartCompany) + * @see rails.game.StockRound#sellShares(rails.game.action.SellShares) */ @Override - public boolean startCompany(String playerName, StartCompany action) { + public boolean sellShares(SellShares action) { + // TODO Auto-generated method stub + if(super.sellShares(action)) { + int numberSold=action.getNumber(); + gameManager.getCurrentPlayer().addCash(-5*numberSold); //Deduct the Money for selling those Shares ! + return true; + } + else + { + return false; + } + } + + /* (non-Javadoc) ++ + * @see rails.game.StockRound#useSpecialProperty(rails.game.action.UseSpecialProperty) + */ + @Override + public boolean useSpecialProperty(UseSpecialProperty action) { + SpecialPropertyI sp = action.getSpecialProperty(); + + // TODO This should work for all subclasses, but not all have execute() + // yet. + if (sp instanceof ExchangeForCash_1880) { + + boolean result = executeExchangeForCash((ExchangeForCash_1880) sp); + if (result) hasActed.set(true); + return result; + + } else { + return super.useSpecialProperty(action); + } + + } + + private boolean executeExchangeForCash(ExchangeForCash_1880 sp) { + CompanyI privateCompany = sp.getOriginalCompany(); + Portfolio portfolio = privateCompany.getPortfolio(); + + Player player = null; + String errMsg = null; + + 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(); + break; + } + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText( + "CannotSwapPrivateForCash", + player.getName(), + privateCompany.getName(), + errMsg )); + return false; + } + + moveStack.start(true); + int amount = sp.getPhaseAmount(); + if (amount >0 ) { + player.addCash(amount); + sp.setExercised(); + privateCompany.setClosed(); + return true; + } + return false; + } + + /* (non-Javadoc) + * @see rails.game.StockRound#process(rails.game.action.PossibleAction) + */ + @Override + public boolean process(PossibleAction action) { + boolean result; + String playerName = action.getPlayerName(); + + if (action instanceof StartCompany) { + + StartCompany_1880 startCompanyAction = (StartCompany_1880) action; + + result = startCompany(playerName, startCompanyAction); + + return result; + } else { + return super.process(action); + } + } ++ ++ /* ++ * @see rails.game.Round#checkFlotation(rails.game.PublicCompanyI) ++ */ ++ @Override ++ protected void checkFlotation(PublicCompanyI company) { ++ if (!company.hasStarted() || company.hasFloated()) return; ++ if (getOwnedPercentageByDirector(company) >= company.getFloatPercentage()) { ++ // Company floats ++ floatCompany(company); ++ } ++ ++ } ++ ++ /** Determine sold percentage for floating purposes */ ++ protected int getOwnedPercentageByDirector (PublicCompanyI company) { ++ ++ int soldPercentage = 0; ++ Player director = company.getPresident(); ++ for (PublicCertificateI cert : company.getCertificates()) { ++ if (certCountsAsSold(cert, director)) { ++ soldPercentage += cert.getShare(); ++ } ++ } ++ return soldPercentage; ++ } ++ ++ private boolean certCountsAsSold(PublicCertificateI cert, Player director) { ++ Portfolio holder = cert.getPortfolio(); ++ CashHolder owner = holder.getOwner(); ++ return owner.equals(director); ++ } ++ ++ public boolean startCompany(String playerName, StartCompany_1880 action) { ++ + PublicCompanyI company = action.getCompany(); + int price = action.getPrice(); + int shares = action.getNumberBought(); + + String errMsg = null; + StockSpaceI startSpace = null; + int numberOfCertsToBuy = 0; + PublicCertificateI cert = null; + String companyName = company.getName(); + int cost = 0; + + currentPlayer = getCurrentPlayer(); + + // Dummy loop to allow a quick jump out + while (true) { + + // Check everything + // Only the player that has the turn may buy + if (!playerName.equals(currentPlayer.getName())) { + errMsg = LocalText.getText("WrongPlayer", playerName, currentPlayer.getName()); + break; + } + + // The player may not have bought this turn. + if (companyBoughtThisTurnWrapper.get() != null) { + errMsg = LocalText.getText("AlreadyBought", playerName); + break; + } + + // Check company + if (company == null) { + errMsg = LocalText.getText("CompanyDoesNotExist", companyName); + break; + } + // The company may not have started yet. + if (company.hasStarted()) { + errMsg = + LocalText.getText("CompanyAlreadyStarted", companyName); + break; + } + + // Find the President's certificate + cert = ipo.findCertificate(company, true); + // Make sure that we buy at least one! + if (shares < cert.getShares()) shares = cert.getShares(); + + // Determine the number of Certificates to buy + // (shortcut: assume that any additional certs are one share each) + numberOfCertsToBuy = shares - (cert.getShares() - 1); + // Check if the player may buy that many certificates. + if (!mayPlayerBuyCertificate(currentPlayer, company, numberOfCertsToBuy)) { + errMsg = LocalText.getText("CantBuyMoreCerts"); + break; + } + + // Check if the company has a fixed par price (1835). + startSpace = company.getStartSpace(); + if (startSpace != null) { + // If so, it overrides whatever is given. + price = startSpace.getPrice(); + } else { + // Else the given price must be a valid start price + if ((startSpace = stockMarket.getStartSpace(price)) == null) { + errMsg = LocalText.getText("InvalidStartPrice", + Bank.format(price), + company.getName() ); + break; + } + } + + // Check if the Player has the money. + cost = shares * price; + if (currentPlayer.getCash() < cost) { + errMsg = LocalText.getText("NoMoney"); + break; + } + + break; + } + + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CantStart", + playerName, + companyName, + Bank.format(price), + errMsg )); + return false; + } + + moveStack.start(true); + + // All is OK, now start the company + company.start(startSpace); + + CashHolder priceRecipient = getSharePriceRecipient (company, ipo, price); + + // Transfer the President's certificate + cert.moveTo(currentPlayer.getPortfolio()); + + + // If more than one certificate is bought at the same time, transfer + // these too. + for (int i = 1; i < numberOfCertsToBuy; i++) { + cert = ipo.findCertificate(company, false); + cert.moveTo(currentPlayer.getPortfolio()); + } + + // Pay for these shares + new CashMove (currentPlayer, priceRecipient, cost); + + ReportBuffer.add(LocalText.getText("START_COMPANY_LOG", + playerName, + companyName, + Bank.format(price), + Bank.format(cost), + shares, + cert.getShare(), + priceRecipient.getName() )); + ReportBuffer.getAllWaiting(); + + //checkFlotation(company); We need to check in finishRound + + companyBoughtThisTurnWrapper.set(company); + hasActed.set(true); + setPriority(); + + // Check for any game-specific consequences + // (such as making another company available in the IPO) + gameSpecificChecks(ipo, company); - ++ action.setBuildingRight((PublicCompany_1880) action.getCompany(), action.buildingRightToString(action.buildingRight)); ++ action.setStartPrice(action.getPrice()); + return true; + } - /* (non-Javadoc) - * @see rails.game.StockRound#finishRound() - */ - @Override - protected void finishRound() { - ReportBuffer.add(" "); - ReportBuffer.add(LocalText.getText("END_SR", - String.valueOf(getStockRoundNumber()))); - - if (raiseIfSoldOut) { - /* Check if any companies are sold out. */ - for (PublicCompanyI company : gameManager.getCompaniesInRunningOrder()) { - if (company.hasStockPrice() && company.isSoldOut() && (!((PublicCompany_1880) company).isCommunistPhase())) { - StockSpaceI oldSpace = company.getCurrentSpace(); - stockMarket.soldOut(company); - StockSpaceI newSpace = company.getCurrentSpace(); - if (newSpace != oldSpace) { - ReportBuffer.add(LocalText.getText("SoldOut", - company.getName(), - Bank.format(oldSpace.getPrice()), - oldSpace.getName(), - Bank.format(newSpace.getPrice()), - newSpace.getName())); - } else { - ReportBuffer.add(LocalText.getText("SoldOutNoRaise", - company.getName(), - Bank.format(newSpace.getPrice()), - newSpace.getName())); - } - } - } - } - - for (PublicCompanyI c : companyManager.getAllPublicCompanies()) { - if (c.hasStarted() && !c.hasFloated()) { - checkFlotation(c); - } - } - - /** At the end of each Stockround the current amount of negative cash is subject to a fine of 50 percent - * - */ - for (Player p : playerManager.getPlayers()) { - if (p.getCash() <0 ) { - int fine = p.getCash()/2; - p.addCash(-fine); - } - } - - // Report financials - ReportBuffer.add(""); - for (PublicCompanyI c : companyManager.getAllPublicCompanies()) { - if (c.hasFloated() && !c.isClosed()) { - ReportBuffer.add(LocalText.getText("Has", c.getName(), - Bank.format(c.getCash()))); - } - } - for (Player p : playerManager.getPlayers()) { - ReportBuffer.add(LocalText.getText("Has", p.getName(), - Bank.format(p.getCash()))); - } - // Inform GameManager - gameManager.nextRound(this); - } - - /* (non-Javadoc) - * @see rails.game.StockRound#sellShares(rails.game.action.SellShares) - */ - @Override - public boolean sellShares(SellShares action) { - // TODO Auto-generated method stub - if(super.sellShares(action)) { - int numberSold=action.getNumber(); - gameManager.getCurrentPlayer().addCash(-5*numberSold); //Deduct the Money for selling those Shares ! - return true; - } - else - { - return false; - } - } - - /* (non-Javadoc) - * @see rails.game.Round#checkFlotation(rails.game.PublicCompanyI) - */ - @Override - protected void checkFlotation(PublicCompanyI company) { - if (!company.hasStarted() || company.hasFloated()) return; - - if (getOwnedPercentageByDirector(company) >= company.getFloatPercentage()) { - // Company floats - floatCompany(company); - } - - } - - /** Determine sold percentage for floating purposes */ - protected int getOwnedPercentageByDirector (PublicCompanyI company) { - - int soldPercentage = 0; - Player director = company.getPresident(); - for (PublicCertificateI cert : company.getCertificates()) { - if (certCountsAsSold(cert, director)) { - soldPercentage += cert.getShare(); - } - } - return soldPercentage; - } - - private boolean certCountsAsSold(PublicCertificateI cert, Player director) { - Portfolio holder = cert.getPortfolio(); - CashHolder owner = holder.getOwner(); - return owner.equals(director); - } } diff --cc tiles/Create_TileDictionary_pdf.sh index 0c521fa,0c521fa..0c521fa mode 100755,100755..100644 --- a/tiles/Create_TileDictionary_pdf.sh +++ b/tiles/Create_TileDictionary_pdf.sh commit b8c0ada06fd0a4d5defbf3cfbc62df00a660aa83 Author: Martin <dr....@t-...> Date: Thu Mar 29 11:27:13 2012 +0200 Implemented the handling of the Flotation Check at the end of a StockRound and the fact that only owned stocks by the director of a public Company count against the floatpercentage. diff --git a/rails/game/specific/_1880/StockRound_1880.java b/rails/game/specific/_1880/StockRound_1880.java index 537f704..256a82c 100644 --- a/rails/game/specific/_1880/StockRound_1880.java +++ b/rails/game/specific/_1880/StockRound_1880.java @@ -9,6 +9,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import rails.common.DisplayBuffer; import rails.common.LocalText; import rails.game.*; import rails.game.action.BuyCertificate; @@ -138,7 +139,8 @@ public class StockRound_1880 extends StockRound { ((PublicCompany_1880) privComp).setDestinationHex(company.getHomeHexes().get(0)); privComp.setInfoText(privComp.getInfoText() + "<br>Destination: "+privComp.getDestinationHex().getInfo()); // Check if the company has floated - if (!company.hasFloated()) checkFlotation(company); + // if (!company.hasFloated()) checkFlotation(company); + // moved to finishRound return; } else { return; @@ -396,8 +398,137 @@ public class StockRound_1880 extends StockRound { */ @Override public boolean startCompany(String playerName, StartCompany action) { - // TODO Auto-generated method stub - return super.startCompany(playerName, action); + PublicCompanyI company = action.getCompany(); + int price = action.getPrice(); + int shares = action.getNumberBought(); + + String errMsg = null; + StockSpaceI startSpace = null; + int numberOfCertsToBuy = 0; + PublicCertificateI cert = null; + String companyName = company.getName(); + int cost = 0; + + currentPlayer = getCurrentPlayer(); + + // Dummy loop to allow a quick jump out + while (true) { + + // Check everything + // Only the player that has the turn may buy + if (!playerName.equals(currentPlayer.getName())) { + errMsg = LocalText.getText("WrongPlayer", playerName, currentPlayer.getName()); + break; + } + + // The player may not have bought this turn. + if (companyBoughtThisTurnWrapper.get() != null) { + errMsg = LocalText.getText("AlreadyBought", playerName); + break; + } + + // Check company + if (company == null) { + errMsg = LocalText.getText("CompanyDoesNotExist", companyName); + break; + } + // The company may not have started yet. + if (company.hasStarted()) { + errMsg = + LocalText.getText("CompanyAlreadyStarted", companyName); + break; + } + + // Find the President's certificate + cert = ipo.findCertificate(company, true); + // Make sure that we buy at least one! + if (shares < cert.getShares()) shares = cert.getShares(); + + // Determine the number of Certificates to buy + // (shortcut: assume that any additional certs are one share each) + numberOfCertsToBuy = shares - (cert.getShares() - 1); + // Check if the player may buy that many certificates. + if (!mayPlayerBuyCertificate(currentPlayer, company, numberOfCertsToBuy)) { + errMsg = LocalText.getText("CantBuyMoreCerts"); + break; + } + + // Check if the company has a fixed par price (1835). + startSpace = company.getStartSpace(); + if (startSpace != null) { + // If so, it overrides whatever is given. + price = startSpace.getPrice(); + } else { + // Else the given price must be a valid start price + if ((startSpace = stockMarket.getStartSpace(price)) == null) { + errMsg = LocalText.getText("InvalidStartPrice", + Bank.format(price), + company.getName() ); + break; + } + } + + // Check if the Player has the money. + cost = shares * price; + if (currentPlayer.getCash() < cost) { + errMsg = LocalText.getText("NoMoney"); + break; + } + + break; + } + + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CantStart", + playerName, + companyName, + Bank.format(price), + errMsg )); + return false; + } + + moveStack.start(true); + + // All is OK, now start the company + company.start(startSpace); + + CashHolder priceRecipient = getSharePriceRecipient (company, ipo, price); + + // Transfer the President's certificate + cert.moveTo(currentPlayer.getPortfolio()); + + + // If more than one certificate is bought at the same time, transfer + // these too. + for (int i = 1; i < numberOfCertsToBuy; i++) { + cert = ipo.findCertificate(company, false); + cert.moveTo(currentPlayer.getPortfolio()); + } + + // Pay for these shares + new CashMove (currentPlayer, priceRecipient, cost); + + ReportBuffer.add(LocalText.getText("START_COMPANY_LOG", + playerName, + companyName, + Bank.format(price), + Bank.format(cost), + shares, + cert.getShare(), + priceRecipient.getName() )); + ReportBuffer.getAllWaiting(); + + //checkFlotation(company); We need to check in finishRound + + companyBoughtThisTurnWrapper.set(company); + hasActed.set(true); + setPriority(); + + // Check for any game-specific consequences + // (such as making another company available in the IPO) + gameSpecificChecks(ipo, company); + + return true; } /* (non-Javadoc) @@ -432,6 +563,13 @@ public class StockRound_1880 extends StockRound { } } } + + for (PublicCompanyI c : companyManager.getAllPublicCompanies()) { + if (c.hasStarted() && !c.hasFloated()) { + checkFlotation(c); + } + } + /** At the end of each Stockround the current amount of negative cash is subject to a fine of 50 percent * */ @@ -475,5 +613,36 @@ public class StockRound_1880 extends StockRound { } } + /* (non-Javadoc) + * @see rails.game.Round#checkFlotation(rails.game.PublicCompanyI) + */ + @Override + protected void checkFlotation(PublicCompanyI company) { + if (!company.hasStarted() || company.hasFloated()) return; + + if (getOwnedPercentageByDirector(company) >= company.getFloatPercentage()) { + // Company floats + floatCompany(company); + } + + } + /** Determine sold percentage for floating purposes */ + protected int getOwnedPercentageByDirector (PublicCompanyI company) { + + int soldPercentage = 0; + Player director = company.getPresident(); + for (PublicCertificateI cert : company.getCertificates()) { + if (certCountsAsSold(cert, director)) { + soldPercentage += cert.getShare(); + } + } + return soldPercentage; + } + + private boolean certCountsAsSold(PublicCertificateI cert, Player director) { + Portfolio holder = cert.getPortfolio(); + CashHolder owner = holder.getOwner(); + return owner.equals(director); + } } |