From: Erik V. <ev...@us...> - 2010-04-22 19:10:06
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv23526/rails/game Modified Files: Round.java PublicCompanyI.java PublicCompany.java Log Message: Restructured float detection such that an 1835 bug is fixed (BY must not float if one of its privates is unsold) and that game specific aspects can more easily be implemented in Round subclasses. Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** PublicCompany.java 18 Apr 2010 20:52:32 -0000 1.94 --- PublicCompany.java 22 Apr 2010 19:09:58 -0000 1.95 *************** *** 1295,1299 **** // Calculate, round up, report and add the cash ! // Define a precise sequence for the reporting Set<CashHolder> recipientSet = sharesPerRecipient.keySet(); --- 1295,1299 ---- // Calculate, round up, report and add the cash ! // Define a precise sequence for the reporting Set<CashHolder> recipientSet = sharesPerRecipient.keySet(); *************** *** 1502,1513 **** } } ! /** A generic presidency check. Perhaps it can replace the above two methods. */ public void checkPresidency () { ! Player president = getPresident(); int presIndex = president.getIndex(); int presShare = president.getPortfolio().getShare(this); ! GameManagerI gmgr = GameManager.getInstance(); Player player; --- 1502,1513 ---- } } ! /** A generic presidency check. Perhaps it can replace the above two methods. */ public void checkPresidency () { ! Player president = getPresident(); int presIndex = president.getIndex(); int presShare = president.getPortfolio().getShare(this); ! GameManagerI gmgr = GameManager.getInstance(); Player player; *************** *** 1528,1543 **** } } - - } - /** - * Return the unsold share percentage. It is calculated as the sum of the - * percentages in IPO and in the company treasury. <p>The latter percentage - * can only be nonzero in games where companies can hold their own shares, - * and will only truly represent the "unsold" percentage until the company - * has floated (in many games companies can buy and sell their own shares). - */ - public int getUnsoldPercentage() { - return bank.getIpo().getShare(this) + portfolio.getShare(this); } --- 1528,1532 ---- Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Round.java 5 Feb 2010 19:57:06 -0000 1.38 --- Round.java 22 Apr 2010 19:09:58 -0000 1.39 *************** *** 290,295 **** if (!company.hasStarted() || company.hasFloated()) return; ! int unsoldPercentage = company.getUnsoldPercentage(); ! if (unsoldPercentage <= 100 - company.getFloatPercentage()) { // Company floats floatCompany(company); --- 290,294 ---- if (!company.hasStarted() || company.hasFloated()) return; ! if (getSoldPercentage(company) >= company.getFloatPercentage()) { // Company floats floatCompany(company); *************** *** 297,300 **** --- 296,319 ---- } + /** Determine sold percentage for floating purposes */ + protected int getSoldPercentage (PublicCompanyI company) { + + int soldPercentage = 0; + for (PublicCertificateI cert : company.getCertificates()) { + if (certCountsAsSold(cert)) { + soldPercentage += cert.getShare(); + } + } + return soldPercentage; + } + + /** Can be subclassed for games with special rules */ + protected boolean certCountsAsSold (PublicCertificateI cert) { + Portfolio holder = cert.getPortfolio(); + CashHolder owner = holder.getOwner(); + return owner instanceof Player + || holder == pool; + } + /** * Float a company, including a default implementation of moving cash and *************** *** 307,311 **** // Move cash and shares where required ! int unsoldPercentage = company.getUnsoldPercentage(); int cash = 0; int capitalisationMode = company.getCapitalisation(); --- 326,330 ---- // Move cash and shares where required ! int soldPercentage = getSoldPercentage(company); int cash = 0; int capitalisationMode = company.getCapitalisation(); *************** *** 318,322 **** } else if (capitalisationMode == PublicCompanyI.CAPITALISE_INCREMENTAL) { // Incremental capitalisation as in 1851 ! capFactor = (100 - unsoldPercentage) / shareUnit; } else if (capitalisationMode == PublicCompanyI.CAPITALISE_WHEN_BOUGHT) { // Cash goes directly to treasury at each buy (as in 1856 before phase 6) --- 337,341 ---- } else if (capitalisationMode == PublicCompanyI.CAPITALISE_INCREMENTAL) { // Incremental capitalisation as in 1851 ! capFactor = soldPercentage / shareUnit; } else if (capitalisationMode == PublicCompanyI.CAPITALISE_WHEN_BOUGHT) { // Cash goes directly to treasury at each buy (as in 1856 before phase 6) Index: PublicCompanyI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompanyI.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** PublicCompanyI.java 18 Apr 2010 20:52:32 -0000 1.52 --- PublicCompanyI.java 22 Apr 2010 19:09:58 -0000 1.53 *************** *** 159,164 **** public boolean canHoldOwnShares(); - public int getUnsoldPercentage(); - /** * Get a list of this company's certificates. --- 159,162 ---- |