From: Erik V. <ev...@us...> - 2010-03-04 22:08:34
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1835 In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv17059/rails/game/specific/_1835 Modified Files: GameManager_1835.java PrussianFormationRound.java Log Message: Various changes for 1835 Index: PrussianFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/PrussianFormationRound.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PrussianFormationRound.java 2 Mar 2010 22:15:33 -0000 1.3 --- PrussianFormationRound.java 4 Mar 2010 22:08:24 -0000 1.4 *************** *** 1,4 **** --- 1,5 ---- package rails.game.specific._1835; + import java.util.ArrayList; import java.util.List; *************** *** 11,15 **** public class PrussianFormationRound extends StockRound { ! private PublicCompanyI prussian; private PhaseI phase; --- 12,16 ---- public class PrussianFormationRound extends StockRound { ! private PublicCompanyI prussian; private PhaseI phase; *************** *** 19,28 **** private boolean mergePr; private boolean forcedMerge; ! private enum Step { START, MERGE }; ! Step step; --- 20,29 ---- private boolean mergePr; private boolean forcedMerge; ! private enum Step { START, MERGE }; ! Step step; *************** *** 38,42 **** } ! public void start() { prussian = companyManager.getCompanyByName(PR_ID); --- 39,44 ---- } ! @Override ! public void start() { prussian = companyManager.getCompanyByName(PR_ID); *************** *** 50,100 **** log.debug("StartPr="+startPr+" forcedStart="+forcedStart +" mergePr="+mergePr+" forcedMerge="+forcedMerge); - - step = startPr ? Step.START : Step.MERGE; } ! public boolean setPossibleActions() { ! if (step == Step.START) { PublicCompanyI m2 = companyManager.getCompanyByName(M2_ID); Player m2Owner = m2.getPresident(); setCurrentPlayer(m2Owner); ! ReportBuffer.add(LocalText.getText("StartingPlayer", getCurrentPlayer().getName())); possibleActions.add(new FoldIntoPrussian(m2)); ! } else if (step == Step.MERGE) { ! SpecialPropertyI sp; ! for (PrivateCompanyI company : currentPlayer.getPortfolio().getPrivateCompanies()) { ! sp = company.getSpecialProperties().get(0); ! if (sp instanceof ExchangeForShare) { ! possibleActions.add(new FoldIntoPrussian(company)); ! } ! } ! PublicCompanyI company; ! List<SpecialPropertyI> sps; ! for (PublicCertificateI cert : currentPlayer.getPortfolio().getCertificates()) { ! if (!cert.isPresidentShare()) continue; ! company = cert.getCompany(); ! sps = company.getSpecialProperties(); ! if (sps != null && !sps.isEmpty() && sps.get(0) instanceof ExchangeForShare) { ! possibleActions.add(new FoldIntoPrussian(company)); ! } ! } } - return true; ! } ! ! protected boolean processGameSpecificAction(PossibleAction action) { if (action instanceof FoldIntoPrussian) { ! FoldIntoPrussian a = (FoldIntoPrussian) action; List<CompanyI> folded = a.getFoldedCompanies(); ! if (step == Step.START) { if (folded.isEmpty() || !startPrussian(a)) { --- 52,125 ---- log.debug("StartPr="+startPr+" forcedStart="+forcedStart +" mergePr="+mergePr+" forcedMerge="+forcedMerge); + step = startPr ? Step.START : Step.MERGE; + if (step == Step.MERGE) { + startingPlayer + = ((GameManager_1835)gameManager).getPrussianFormationStartingPlayer(); + setCurrentPlayer(startingPlayer); + } } ! @Override ! public boolean setPossibleActions() { ! if (step == Step.START) { PublicCompanyI m2 = companyManager.getCompanyByName(M2_ID); Player m2Owner = m2.getPresident(); + startingPlayer = m2Owner; setCurrentPlayer(m2Owner); ! ReportBuffer.add(LocalText.getText("StartingPlayer", getCurrentPlayer().getName())); possibleActions.add(new FoldIntoPrussian(m2)); ! } else if (step == Step.MERGE) { ! ! while (true) { ! List<CompanyI> foldables = new ArrayList<CompanyI> (); ! SpecialPropertyI sp; ! for (PrivateCompanyI company : currentPlayer.getPortfolio().getPrivateCompanies()) { ! sp = company.getSpecialProperties().get(0); ! if (sp instanceof ExchangeForShare) { ! foldables.add(company); ! } ! } ! PublicCompanyI company; ! List<SpecialPropertyI> sps; ! for (PublicCertificateI cert : currentPlayer.getPortfolio().getCertificates()) { ! if (!cert.isPresidentShare()) continue; ! company = cert.getCompany(); ! sps = company.getSpecialProperties(); ! if (sps != null && !sps.isEmpty() && sps.get(0) instanceof ExchangeForShare) { ! foldables.add(company); ! } ! } ! if (foldables.isEmpty()) { ! // No merge options for the current player, try the next one ! setNextPlayer(); ! if (getCurrentPlayer() == startingPlayer) { ! finishRound(); ! break; ! } else { ! continue; ! } ! } else { ! possibleActions.add(new FoldIntoPrussian(foldables)); ! break; ! } ! } } return true; ! } ! ! @Override ! protected boolean processGameSpecificAction(PossibleAction action) { if (action instanceof FoldIntoPrussian) { ! FoldIntoPrussian a = (FoldIntoPrussian) action; List<CompanyI> folded = a.getFoldedCompanies(); ! if (step == Step.START) { if (folded.isEmpty() || !startPrussian(a)) { *************** *** 106,110 **** if (!folded.isEmpty()) mergeIntoPrussian (a); } ! return true; } else { --- 131,141 ---- if (!folded.isEmpty()) mergeIntoPrussian (a); } ! ! // No merge options for the current player, try the next one ! setNextPlayer(); ! if (getCurrentPlayer() == startingPlayer) { ! finishRound(); ! } ! return true; } else { *************** *** 114,124 **** private boolean startPrussian (FoldIntoPrussian action) { ! // Validate String errMsg = null; ! while (true) { if (!(M2_ID.equals(action.getFoldedCompanyNames()))) { ! errMsg = LocalText.getText("WrongCompany", action.getFoldedCompanyNames(), M2_ID); --- 145,155 ---- private boolean startPrussian (FoldIntoPrussian action) { ! // Validate String errMsg = null; ! while (true) { if (!(M2_ID.equals(action.getFoldedCompanyNames()))) { ! errMsg = LocalText.getText("WrongCompany", action.getFoldedCompanyNames(), M2_ID); *************** *** 127,131 **** break; } ! if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotMerge", --- 158,162 ---- break; } ! if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotMerge", *************** *** 135,143 **** return false; } ! moveStack.start(false); ! // Execute prussian.start(); String message = LocalText.getText("START_MERGED_COMPANY", PR_ID, --- 166,176 ---- return false; } ! moveStack.start(false); ! // Execute prussian.start(); + prussian.setFloated(); + ((GameManager_1835)gameManager).setPrussianFormationStartingPlayer(currentPlayer); String message = LocalText.getText("START_MERGED_COMPANY", PR_ID, *************** *** 145,163 **** prussian.getStartSpace()); ReportBuffer.add(message); ! executeExchange (action.getFoldedCompanies(), true); ! return true; } ! private boolean mergeIntoPrussian (FoldIntoPrussian action) { ! // Validate String errMsg = null; ! while (true) { break; } ! if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotMerge", --- 178,196 ---- prussian.getStartSpace()); ReportBuffer.add(message); ! executeExchange (action.getFoldedCompanies(), true); ! return true; } ! private boolean mergeIntoPrussian (FoldIntoPrussian action) { ! // Validate String errMsg = null; ! while (true) { break; } ! if (errMsg != null) { DisplayBuffer.add(LocalText.getText("CannotMerge", *************** *** 167,181 **** return false; } ! moveStack.start(false); ! // Execute ! executeExchange (action.getFoldedCompanies(), true); ! return true; } private void executeExchange (List<CompanyI> companies, boolean president) { ! ExchangeForShare efs; PublicCertificateI cert; --- 200,214 ---- return false; } ! moveStack.start(false); ! // Execute ! executeExchange (action.getFoldedCompanies(), false); ! return true; } private void executeExchange (List<CompanyI> companies, boolean president) { ! ExchangeForShare efs; PublicCertificateI cert; *************** *** 183,187 **** // Shortcut, sp should be checked efs = (ExchangeForShare) company.getSpecialProperties().get(0); ! cert = unavailable.findCertificate(prussian, efs.getShare(), president); cert.moveTo(currentPlayer.getPortfolio()); company.setClosed(); --- 216,221 ---- // Shortcut, sp should be checked efs = (ExchangeForShare) company.getSpecialProperties().get(0); ! cert = unavailable.findCertificate(prussian, efs.getShare()/prussian.getShareUnit(), ! president); cert.moveTo(currentPlayer.getPortfolio()); company.setClosed(); *************** *** 190,196 **** company.getName(), PR_ID, ! company instanceof PrivateCompanyI ? "no" : Bank.format(((PublicCompanyI)company).getCash()), ! company instanceof PrivateCompanyI ? "no" : ((PublicCompanyI)company).getPortfolio().getTrainList().size())); ReportBuffer.add(LocalText.getText("GetShareForMinor", --- 224,230 ---- company.getName(), PR_ID, ! company instanceof PrivateCompanyI ? "no" : Bank.format(((PublicCompanyI)company).getCash()), ! company instanceof PrivateCompanyI ? "no" : ((PublicCompanyI)company).getPortfolio().getTrainList().size())); ReportBuffer.add(LocalText.getText("GetShareForMinor", *************** *** 202,208 **** } } ! public static boolean prussianIsComplete(GameManagerI gameManager) { ! List<PublicCertificateI> unissued = gameManager.getBank().getUnavailable().getCertificatesPerCompany(PR_ID); return unissued == null || unissued.isEmpty(); --- 236,242 ---- } } ! public static boolean prussianIsComplete(GameManagerI gameManager) { ! List<PublicCertificateI> unissued = gameManager.getBank().getUnavailable().getCertificatesPerCompany(PR_ID); return unissued == null || unissued.isEmpty(); Index: GameManager_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/GameManager_1835.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GameManager_1835.java 16 Feb 2010 20:25:38 -0000 1.1 --- GameManager_1835.java 4 Mar 2010 22:08:23 -0000 1.2 *************** *** 8,11 **** --- 8,12 ---- public static String PR_NAME = PrussianFormationRound.PR_ID; private RoundI previousRound; + private Player prFormStartingPlayer = null; public GameManager_1835() { *************** *** 15,20 **** @Override public void nextRound(RoundI round) { ! ! if (!(round instanceof PrussianFormationRound)) { PhaseI phase = getCurrentPhase(); if (phase.getName().equals("4") || phase.getName().equals("4+4") --- 16,23 ---- @Override public void nextRound(RoundI round) { ! ! if (round instanceof PrussianFormationRound) { ! super.nextRound(previousRound); ! } else { PhaseI phase = getCurrentPhase(); if (phase.getName().equals("4") || phase.getName().equals("4+4") *************** *** 23,31 **** previousRound = round; startPrussianFormationRound (); - return; } } } - super.nextRound(round); } --- 26,34 ---- previousRound = round; startPrussianFormationRound (); } + } else { + super.nextRound(round); } } } *************** *** 35,37 **** --- 38,48 ---- createRound (PrussianFormationRound.class).start (); } + + public void setPrussianFormationStartingPlayer(Player prFormStartingPlayer) { + this.prFormStartingPlayer = prFormStartingPlayer; + } + + public Player getPrussianFormationStartingPlayer() { + return prFormStartingPlayer; + } } |