From: Erik V. <ev...@us...> - 2010-02-09 20:03:08
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv14687/rails/game Modified Files: StockRound.java Log Message: Allowing buying different size shares per company, if available (as in 1835). Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** StockRound.java 6 Feb 2010 23:48:26 -0000 1.60 --- StockRound.java 9 Feb 2010 20:03:00 -0000 1.61 *************** *** 98,104 **** setSellableShares(); ! if (isPlayerOverLimits (currentPlayer)) return true; ! passAllowed = true; --- 98,104 ---- setSellableShares(); ! if (isPlayerOverLimits (currentPlayer)) return true; ! passAllowed = true; *************** *** 209,225 **** Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); for (String compName : map.keySet()) { certs = map.get(compName); if (certs == null || certs.isEmpty()) continue; ! number = certs.size(); ! cert = certs.get(0); ! comp = cert.getCompany(); ! if (isSaleRecorded(currentPlayer, comp)) continue; ! if (maxAllowedNumberOfSharesToBuy(currentPlayer, comp, ! cert.getShare()) < 1) continue; stockSpace = comp.getCurrentSpace(); price = stockSpace.getPrice(); if (companyBoughtThisTurn != null) { // If a cert was bought before, only brown zone ones can be --- 209,233 ---- Map<String, List<PublicCertificateI>> map = from.getCertsPerCompanyMap(); + /* Allow for multiple share unit certificates (e.g. 1835) */ + PublicCertificateI[] uniqueCerts; + int[] numberOfCerts; + int shares; + int shareUnit; + int maxNumberOfSharesToBuy; for (String compName : map.keySet()) { certs = map.get(compName); if (certs == null || certs.isEmpty()) continue; ! ! 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 */ + if (maxNumberOfSharesToBuy < 1) continue; + if (isSaleRecorded(currentPlayer, comp)) continue; if (companyBoughtThisTurn != null) { // If a cert was bought before, only brown zone ones can be *************** *** 228,250 **** if (!stockSpace.isNoBuyLimit()) continue; } - /* Only certs in the brown zone may be bought all at once */ - 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) ! number--; ! if (number > 0) { ! possibleActions.add(new BuyCertificate(cert, from, price, ! number)); } } --- 236,280 ---- if (!stockSpace.isNoBuyLimit()) continue; } ! /* Check what share multiples are available ! * Normally only 1, but 1 and 2 in 1835. Allow up to 4. ! */ ! uniqueCerts = new PublicCertificateI[5]; ! 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)); ! } } } *************** *** 339,343 **** * (e.g. 1835) companies may have different ordinary shares: 5% and * 10%, or 10% and 20%. The president's share counts as a multiple ! * of the lowest ordinary share unit type. */ // Take care for max. 4 share units per share --- 369,373 ---- * (e.g. 1835) companies may have different ordinary shares: 5% and * 10%, or 10% and 20%. The president's share counts as a multiple ! * of the smallest ordinary share unit type. */ // Take care for max. 4 share units per share |