From: Erik V. <ev...@us...> - 2010-03-04 22:15:57
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv18865/rails/game Modified Files: StockRound.java Log Message: Various changes for 1835 Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** StockRound.java 4 Mar 2010 21:16:56 -0000 1.66 --- StockRound.java 4 Mar 2010 22:15:49 -0000 1.67 *************** *** 97,101 **** // fix of the forced undo bug currentPlayer = getCurrentPlayer(); ! boolean passAllowed = false; --- 97,101 ---- // fix of the forced undo bug currentPlayer = getCurrentPlayer(); ! boolean passAllowed = false; *************** *** 151,154 **** --- 151,155 ---- int price; int number; + int unitsForPrice; int playerCash = currentPlayer.getCash(); *************** *** 170,173 **** --- 171,175 ---- cert = certs.get(0); comp = cert.getCompany(); + unitsForPrice = comp.getShareUnitsForSharePrice(); if (isSaleRecorded(currentPlayer, comp)) continue; if (maxAllowedNumberOfSharesToBuy(currentPlayer, comp, *************** *** 176,180 **** if (!cert.isPresidentShare()) { ! price = comp.getIPOPrice(); if (price <= playerCash) { possibleActions.add(new BuyCertificate(cert, from, --- 178,182 ---- if (!cert.isPresidentShare()) { ! price = comp.getIPOPrice() / unitsForPrice; if (price <= playerCash) { possibleActions.add(new BuyCertificate(cert, from, *************** *** 183,187 **** } else if (!comp.hasStarted()) { if (comp.getIPOPrice() != 0) { ! price = comp.getIPOPrice() * cert.getShares(); if (price <= playerCash) { possibleActions.add(new StartCompany(cert, price)); --- 185,189 ---- } else if (!comp.hasStarted()) { if (comp.getIPOPrice() != 0) { ! price = comp.getIPOPrice() * cert.getShares() / unitsForPrice; if (price <= playerCash) { possibleActions.add(new StartCompany(cert, price)); *************** *** 225,232 **** comp = certs.get(0).getCompany(); stockSpace = comp.getCurrentSpace(); ! price = stockSpace.getPrice(); shareUnit = comp.getShareUnit(); maxNumberOfSharesToBuy ! = maxAllowedNumberOfSharesToBuy(currentPlayer, comp, shareUnit); /* Checks if the player can buy any shares of this company */ --- 227,235 ---- comp = certs.get(0).getCompany(); stockSpace = comp.getCurrentSpace(); ! unitsForPrice = comp.getShareUnitsForSharePrice(); ! price = stockSpace.getPrice() / unitsForPrice; shareUnit = comp.getShareUnit(); maxNumberOfSharesToBuy ! = maxAllowedNumberOfSharesToBuy(currentPlayer, comp, shareUnit); /* Checks if the player can buy any shares of this company */ *************** *** 246,283 **** numberOfCerts = new int[5]; for (PublicCertificateI cert2 : certs) { ! shares = cert2.getShares(); if (maxNumberOfSharesToBuy < shares) continue; ! numberOfCerts[shares]++; ! if (uniqueCerts[shares] != null) continue; ! uniqueCerts[shares] = cert2; } /* Create a BuyCertificate action per share size */ for (shares = 1; shares < 5; shares++) { ! /* Only certs in the brown zone may be bought all at once */ ! number = numberOfCerts[shares]; ! if (number == 0) continue; ! if (!stockSpace.isNoBuyLimit()) { ! number = 1; ! /* Would the player exceed the per-company share hold limit? */ ! if (!mayPlayerBuyCompanyShare(currentPlayer, comp, number)) continue; ! /* Would the player exceed the total certificate limit? */ ! if (!stockSpace.isNoCertLimit() ! && !mayPlayerBuyCertificate(currentPlayer, comp, number)) ! continue; ! } ! // Does the player have enough cash? ! while (number > 0 && playerCash < number * price * shares) { ! number--; ! } ! if (number > 0) { ! possibleActions.add(new BuyCertificate(uniqueCerts[shares], ! from, price, ! number)); ! } } } --- 249,286 ---- numberOfCerts = new int[5]; for (PublicCertificateI cert2 : certs) { ! shares = cert2.getShares(); if (maxNumberOfSharesToBuy < shares) continue; ! numberOfCerts[shares]++; ! if (uniqueCerts[shares] != null) continue; ! uniqueCerts[shares] = cert2; } /* Create a BuyCertificate action per share size */ for (shares = 1; shares < 5; shares++) { ! /* Only certs in the brown zone may be bought all at once */ ! number = numberOfCerts[shares]; ! if (number == 0) continue; ! if (!stockSpace.isNoBuyLimit()) { ! number = 1; ! /* Would the player exceed the per-company share hold limit? */ ! if (!mayPlayerBuyCompanyShare(currentPlayer, comp, number)) continue; ! /* Would the player exceed the total certificate limit? */ ! if (!stockSpace.isNoCertLimit() ! && !mayPlayerBuyCertificate(currentPlayer, comp, number)) ! continue; ! } ! // Does the player have enough cash? ! while (number > 0 && playerCash < number * price * shares) { ! number--; ! } ! if (number > 0) { ! possibleActions.add(new BuyCertificate(uniqueCerts[shares], ! from, price, ! number)); ! } } } *************** *** 396,399 **** --- 399,403 ---- price = company.getMarketPrice(); } + price /= company.getShareUnitsForSharePrice(); for (int i = 1; i <= 4; i++) { *************** *** 737,741 **** price = currentSpace.getPrice(); ! cost = shares * price; // Check if the Player has the money. --- 741,745 ---- price = currentSpace.getPrice(); ! cost = shares * price / company.getShareUnitsForSharePrice(); // Check if the Player has the money. *************** *** 948,972 **** && numberToSell <= presCert.getShares()) { // More to sell and we are President: see if we can dump it. ! // search for the player with the most shares (fix of bug 2962977) ! int requiredShares = presCert.getShare(); ! Player potentialDirector = null; for (int i = currentIndex + 1; i < currentIndex + numberOfPlayers; i++) { ! Player otherPlayer = gameManager.getPlayerByIndex(i); ! int otherPlayerShares = otherPlayer.getPortfolio().getShare(company); ! if (otherPlayerShares >= requiredShares) { // Check if he has the right kind of share if (numberToSell > 1 || otherPlayer.getPortfolio().ownsCertificates( company, 1, false) >= 1) { ! potentialDirector = otherPlayer; ! requiredShares = otherPlayerShares + 1; } } } - // The poor sod. - dumpedPlayer = potentialDirector; - presSharesToSell = numberToSell; - numberToSell = 0; } // Check if we could sell them all --- 952,972 ---- && numberToSell <= presCert.getShares()) { // More to sell and we are President: see if we can dump it. ! Player otherPlayer; for (int i = currentIndex + 1; i < currentIndex + numberOfPlayers; i++) { ! otherPlayer = gameManager.getPlayerByIndex(i); ! if (otherPlayer.getPortfolio().getShare(company) >= presCert.getShare()) { // Check if he has the right kind of share if (numberToSell > 1 || otherPlayer.getPortfolio().ownsCertificates( company, 1, false) >= 1) { ! // The poor sod. ! dumpedPlayer = otherPlayer; ! presSharesToSell = numberToSell; ! numberToSell = 0; ! break; } } } } // Check if we could sell them all *************** *** 1003,1007 **** } else { sellPrice = company.getCurrentSpace(); ! price = sellPrice.getPrice(); sellPrices.put(companyName, sellPrice); } --- 1003,1007 ---- } else { sellPrice = company.getCurrentSpace(); ! price = sellPrice.getPrice() / company.getShareUnitsForSharePrice(); sellPrices.put(companyName, sellPrice); } *************** *** 1075,1079 **** return true; } ! protected void adjustSharePrice (PublicCompanyI company, int numberSold, boolean soldBefore) { company.adjustSharePrice (SOLD, numberSold, gameManager.getStockMarket()); --- 1075,1079 ---- return true; } ! protected void adjustSharePrice (PublicCompanyI company, int numberSold, boolean soldBefore) { company.adjustSharePrice (SOLD, numberSold, gameManager.getStockMarket()); |