From: Erik V. <ev...@us...> - 2009-10-06 18:34:14
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv4108/rails/game/specific/_1856 Modified Files: CGRFormationRound.java PublicCompany_CGR.java StockRound_1856.java OperatingRound_1856.java Log Message: CGR pres. must buy 2nd shars at first opportunity if not yet owned Index: StockRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/StockRound_1856.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** StockRound_1856.java 25 Sep 2009 19:13:01 -0000 1.9 --- StockRound_1856.java 6 Oct 2009 18:34:03 -0000 1.10 *************** *** 2,5 **** --- 2,6 ---- import rails.game.*; + import rails.game.action.BuyCertificate; import rails.util.LocalText; *************** *** 47,51 **** @Override ! protected CashHolder getSharePriceRecipient(Certificate cert, int price) { CashHolder recipient; --- 48,52 ---- @Override ! protected CashHolder getSharePriceRecipient(PublicCertificateI cert, int price) { CashHolder recipient; *************** *** 54,60 **** if (price != 0 && cert instanceof PublicCertificateI && oldHolder == ipo) { ! PublicCompany_1856 comp = (PublicCompany_1856)((PublicCertificateI) cert).getCompany(); switch (comp.getTrainNumberAvailableAtStart()) { --- 55,62 ---- if (price != 0 && cert instanceof PublicCertificateI + && !cert.getCompany().getName().equalsIgnoreCase(PublicCompany_CGR.NAME) && oldHolder == ipo) { ! PublicCompany_1856 comp = (PublicCompany_1856)(cert).getCompany(); switch (comp.getTrainNumberAvailableAtStart()) { *************** *** 74,78 **** // fall through case 5: ! recipient = ((PublicCertificateI)cert).getCompany(); break; case 6: --- 76,80 ---- // fall through case 5: ! recipient = (cert).getCompany(); break; case 6: *************** *** 86,88 **** --- 88,161 ---- } + /** Check for the special condition that the CGR president + * has just bought his second share. + */ + @Override + protected void gameSpecificChecks (Portfolio boughtFrom, + PublicCompanyI company) { + + if (company.getName().equalsIgnoreCase(PublicCompany_CGR.NAME) + && ((PublicCompany_CGR)company).hasTemporaryPresident()) { + log.debug("Resetting temp. president"); + ipo.swapPresidentCertificate(company, + currentPlayer.getPortfolio()); + Player oldPresident = company.getPresident(); + ((PublicCompany_CGR)company).setTemporaryPresident(null); + company.getPresident().getPortfolio().getShareModel(company).update(); + if (currentPlayer != oldPresident) { + oldPresident.getPortfolio().getShareModel(company).update(); + } + } + } + + @Override + public void resume() { + } + + /** Check if the player is president of CGR and must buy a second share */ + @Override + public boolean setPossibleActions() { + + PublicCompany_CGR cgr = + (PublicCompany_CGR)companyManager.getCompanyByName(PublicCompany_CGR.NAME); + if (cgr.hasStarted() && cgr.getPresident() == currentPlayer + && cgr.hasTemporaryPresident()) { + + // Player MUST buy an extra single certificate to obtain + // the President's certificate + int cash = currentPlayer.getCash(); + PublicCertificateI cert1, cert2; + int price1 = 0; + int price2 = 0; + int lowestPrice = 999; + if ((cert1 = ipo.findCertificate(cgr, false)) != null) { + price1 = lowestPrice = cgr.getParPriceModel().getPrice().getPrice(); + } + if ((cert2 = pool.findCertificate(cgr, false)) != null) { + price2 = cgr.getCurrentPriceModel().getPrice().getPrice(); + if (price2 < lowestPrice) lowestPrice = price2; + } + DisplayBuffer.add(LocalText.getText("MustBuyExtraShareAsPresident", + currentPlayer.getName(), + cgr.getName(), + cgr.getShareUnit())); + //log.debug("MustBuyExtraShareMessageAdded", new Exception("HERE")); + if (lowestPrice > cash) { + gameManager.startShareSellingRound(currentPlayer, + lowestPrice - cash, cgr); + } else { + // Player has enough cash + if (cert1 != null && price1 <= cash) { + possibleActions.add(new BuyCertificate(cert1, ipo, price1)); + } + if (cert2 != null && price2 <= cash) { + possibleActions.add(new BuyCertificate(cert2, pool, price2)); + } + } + + return true; + } else { + return super.setPossibleActions(); + } + } } Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** CGRFormationRound.java 25 Sep 2009 19:29:56 -0000 1.18 --- CGRFormationRound.java 6 Oct 2009 18:34:03 -0000 1.19 *************** *** 414,420 **** // Assign the new president ! if (temporaryPresident != newPresident) { ! temporaryPresident.getPortfolio().swapPresidentCertificate(cgr, ! newPresident.getPortfolio()); } --- 414,427 ---- // Assign the new president ! if (newPresident.getPortfolio().getShare(cgr) == cgr.getShareUnit()) { ! // Nobody has 2 shares, then takes the first player who has got one share ! log.debug("Nobody has two shares, creating a temp.pres.: "+firstCGRowner.getName()); ! cgr.setTemporaryPresident(firstCGRowner); ! newPresident = firstCGRowner; ! } else if (temporaryPresident != null && temporaryPresident != newPresident) { ! log.debug("Moving pres.share from "+temporaryPresident.getName() ! +" to "+newPresident.getName()); ! temporaryPresident.getPortfolio().swapPresidentCertificate(cgr, ! newPresident.getPortfolio()); } Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** OperatingRound_1856.java 25 Sep 2009 19:13:01 -0000 1.22 --- OperatingRound_1856.java 6 Oct 2009 18:34:03 -0000 1.23 *************** *** 194,199 **** log.info("President has $"+presCash+", so $"+cashToBeRaisedByPresident+" must be added"); savedAction = action; ! gameManager.startShareSellingRound(this, operatingCompany, ! cashToBeRaisedByPresident); // Return arbitrary negative value to signal end of processing to caller. return -remainder; --- 194,199 ---- log.info("President has $"+presCash+", so $"+cashToBeRaisedByPresident+" must be added"); savedAction = action; ! gameManager.startShareSellingRound(operatingCompany.getPresident(), ! cashToBeRaisedByPresident, operatingCompany); // Return arbitrary negative value to signal end of processing to caller. return -remainder; Index: PublicCompany_CGR.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_CGR.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PublicCompany_CGR.java 25 Sep 2009 19:13:01 -0000 1.3 --- PublicCompany_CGR.java 6 Oct 2009 18:34:03 -0000 1.4 *************** *** 6,11 **** import rails.game.*; import rails.game.move.*; ! import rails.game.state.BooleanState; ! import rails.game.state.IntegerState; public class PublicCompany_CGR extends PublicCompany { --- 6,10 ---- import rails.game.*; import rails.game.move.*; ! import rails.game.state.*; public class PublicCompany_CGR extends PublicCompany { *************** *** 16,19 **** --- 15,21 ---- private BooleanState hadPermanentTrain; + /** If no player has 2 shares, we need a separate attribute to mark the president. */ + private State temporaryPresident = null; + /* Cope with multiple 5% share sales in one turn */ private IntegerState sharesSoldSoFar; *************** *** 42,46 **** --- 44,76 ---- } + public boolean hasTemporaryPresident () { + return getTemporaryPresident() != null; + } + + public Player getTemporaryPresident() { + if (temporaryPresident != null) { + return (Player) temporaryPresident.getObject(); + } else { + return null; + } + } + @Override + public Player getPresident() { + if (hasTemporaryPresident()) { + return getTemporaryPresident(); + } else { + return super.getPresident(); + } + } + + public void setTemporaryPresident(Player temporaryPresident) { + if (this.temporaryPresident == null) { + this.temporaryPresident = new State ("CGR_TempPres", Player.class); + } + this.temporaryPresident.set(temporaryPresident); + } + + @Override public boolean canRunTrains() { if (!hadPermanentTrain()) { *************** *** 148,151 **** } ! } --- 178,184 ---- } ! @Override ! public String getExtraShareMarks () { ! return (hasTemporaryPresident() ? "T" : ""); ! } } |