You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(46) |
Dec
(57) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(51) |
Feb
(10) |
Mar
|
Apr
|
May
(14) |
Jun
|
Jul
(13) |
Aug
(30) |
Sep
(83) |
Oct
(56) |
Nov
(148) |
Dec
(107) |
| 2010 |
Jan
(260) |
Feb
(164) |
Mar
(183) |
Apr
(99) |
May
(160) |
Jun
(40) |
Jul
(33) |
Aug
(48) |
Sep
(22) |
Oct
(24) |
Nov
(1) |
Dec
(12) |
| 2011 |
Jan
(6) |
Feb
(15) |
Mar
(13) |
Apr
(37) |
May
(27) |
Jun
(29) |
Jul
(33) |
Aug
(20) |
Sep
(17) |
Oct
(20) |
Nov
(33) |
Dec
(17) |
| 2012 |
Jan
(39) |
Feb
(38) |
Mar
(20) |
Apr
(21) |
May
(17) |
Jun
(22) |
Jul
(16) |
Aug
(3) |
Sep
(9) |
Oct
(10) |
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
|
|
|
|
|
1
|
2
|
|
3
|
4
(11) |
5
|
6
|
7
|
8
|
9
|
|
10
|
11
|
12
|
13
|
14
|
15
|
16
|
|
17
|
18
|
19
|
20
|
21
|
22
|
23
|
|
24
(3) |
25
|
26
|
27
|
28
|
29
|
30
|
|
31
|
|
|
|
|
|
|
|
From: Erik V. <ev...@us...> - 2009-05-24 18:45:27
|
Update of /cvsroot/rails/18xx In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv20723 Modified Files: LocalisedText.properties Log Message: Added message to start merged company Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** LocalisedText.properties 4 May 2009 20:29:15 -0000 1.69 --- LocalisedText.properties 24 May 2009 18:45:15 -0000 1.70 *************** *** 331,334 **** --- 331,335 ---- SRHelpText=Stock round help text goes here. START_COMPANY={0} starts {1} at {2}. + START_MERGED_COMPANY={0} starts at {1} ({2}) START_COMPANY_LOG={0} starts {1} at {2} and pays {3} for {4} shares ({5}%) to {6} StartACompany=Start {0} by buying a {1}% share for {2} |
|
From: Erik V. <ev...@us...> - 2009-05-24 18:44:51
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv20632/rails/game/specific/_1856 Modified Files: CGRFormationRound.java Log Message: Implemented correct CGR start price Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CGRFormationRound.java 4 May 2009 20:29:14 -0000 1.2 --- CGRFormationRound.java 24 May 2009 18:44:40 -0000 1.3 *************** *** 494,504 **** executeExchangeTokens (nonHomeTokens); } ! ! // Close the absorbed companies and float the CGR for (PublicCompanyI comp : mergingCompanies) { comp.setClosed(); } ! cgr.start(100); // TODO: assign correct starting price cgr.setFloated(); // Check the trains, autodiscard any excess non-permanent trains --- 494,544 ---- executeExchangeTokens (nonHomeTokens); } ! ! // Determine the CGR starting price, ! // and close the absorbed companies. ! int lowestPrice = 999; ! int totalPrice = 0; ! int price; ! int numberMerged = mergingCompanies.size(); for (PublicCompanyI comp : mergingCompanies) { + price = comp.getMarketPrice(); + totalPrice += price; + if (price < lowestPrice) lowestPrice = price; comp.setClosed(); } ! if (numberMerged >= 3) { ! totalPrice -= lowestPrice; ! numberMerged--; ! } ! int cgrPrice = Math.max(100, ((int)((totalPrice/numberMerged)/5))*5); ! ! // Find the correct start space and start the CGR ! if (cgrPrice == 100) { ! cgr.start(100); ! } else { ! StockMarketI sm = StockMarket.getInstance(); ! int prevColPrice = 100; ! int colPrice; ! StockSpaceI startSpace; ! for (int col=6; col <= sm.getNumberOfColumns(); col++) { ! colPrice = sm.getStockSpace(1, col).getPrice(); ! if (cgrPrice > colPrice) continue; ! if (cgrPrice - prevColPrice < colPrice - cgrPrice) { ! startSpace = sm.getStockSpace(1, col-1); ! } else { ! startSpace = sm.getStockSpace(1, col); ! } ! cgr.start(startSpace); ! message = LocalText.getText("START_MERGED_COMPANY", ! "CGR", ! Bank.format(startSpace.getPrice()), ! startSpace.getName()); ! DisplayBuffer.add(message); ! ReportBuffer.add(message); ! break; ! } ! } cgr.setFloated(); + ReportBuffer.add (LocalText.getText("Floats", "CGR")); // Check the trains, autodiscard any excess non-permanent trains |
|
From: Erik V. <ev...@us...> - 2009-05-24 18:44:31
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv20593/rails/game/specific/_1856 Modified Files: GameUIManager_1856.java Log Message: Removed outcommented code Index: GameUIManager_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/GameUIManager_1856.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GameUIManager_1856.java 4 May 2009 20:29:14 -0000 1.1 --- GameUIManager_1856.java 24 May 2009 18:44:20 -0000 1.2 *************** *** 1,17 **** package rails.game.specific._1856; - import rails.game.action.PossibleActions; - import rails.ui.swing.ActionPerformer; import rails.ui.swing.GameUIManager; public class GameUIManager_1856 extends GameUIManager { - /* - protected void updateStatus(ActionPerformer activeWindow) { - - PossibleActions possibleActions = PossibleActions.getInstance(); - - } - */ } --- 1,8 ---- |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:32
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/game/specific/_1856 Modified Files: CGRFormationRound.java PublicCompany_1856.java OperatingRound_1856.java Added Files: GameUIManager_1856.java Log Message: 1856 CGR formation round --- NEW FILE: GameUIManager_1856.java --- package rails.game.specific._1856; import rails.game.action.PossibleActions; import rails.ui.swing.ActionPerformer; import rails.ui.swing.GameUIManager; public class GameUIManager_1856 extends GameUIManager { /* protected void updateStatus(ActionPerformer activeWindow) { PossibleActions possibleActions = PossibleActions.getInstance(); } */ } Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** OperatingRound_1856.java 4 Feb 2009 20:36:39 -0000 1.8 --- OperatingRound_1856.java 4 May 2009 20:29:14 -0000 1.9 *************** *** 2,5 **** --- 2,7 ---- import java.util.ArrayList; + import java.util.Arrays; + import java.util.Iterator; import java.util.List; *************** *** 432,436 **** // End of CGRFormationRound finalLoanRepaymentPending.set(false); ! if (setNextOperatingCompany(false)) { setStep(STEP_INITIAL); } else { --- 434,439 ---- // End of CGRFormationRound finalLoanRepaymentPending.set(false); ! resetOperatingCompanies(); ! if (operatingCompany != null) { setStep(STEP_INITIAL); } else { *************** *** 442,445 **** --- 445,496 ---- } + private void resetOperatingCompanies() { + + int lastOperatingCompanyIndex = operatingCompanyIndex; + // Find the first company that has not yet operated + // and is not closed. + while (setNextOperatingCompany(false) + && getOperatingCompany().isClosed()); + + List<PublicCompanyI> companies + = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); + PublicCompanyI company; + PublicCompanyI cgr = companyManager.getCompanyByName("CGR"); + int index = 0; + boolean cgrCanOperate = true; + for (Iterator<PublicCompanyI> it = companies.iterator(); + it.hasNext(); ) { + company = it.next(); + if (company.isClosed()) { + if (index <= lastOperatingCompanyIndex) cgrCanOperate = false; + it.remove(); + } + } + + if (operatingCompany != null) { + operatingCompanyIndex = companies.indexOf(operatingCompany); + } + + for (PublicCompanyI c : companies) { + log.debug("Now operating: "+c.getName()); + } + + String message; + if (cgrCanOperate) { + operatingCompanyIndex = Math.max (0, operatingCompanyIndex); + companies.add(operatingCompanyIndex, cgr); + operatingCompany = cgr; + message = LocalText.getText("CanOperate", cgr.getName()); + } else { + message = LocalText.getText("CannotOperate", cgr.getName()); + } + ReportBuffer.add (message); + DisplayBuffer.add(message); + + operatingCompanyArray = companies.toArray(new PublicCompanyI[0]); + operatingCompanyIndexObject.set(operatingCompanyIndex); + + log.debug ("Next operating company: "+operatingCompany.getName()); + } @Override Index: PublicCompany_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_1856.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PublicCompany_1856.java 24 Jan 2009 15:10:29 -0000 1.2 --- PublicCompany_1856.java 4 May 2009 20:29:14 -0000 1.3 *************** *** 1,7 **** package rails.game.specific._1856; ! import rails.game.PublicCompany; ! import rails.game.StockSpaceI; ! import rails.game.TrainI; import rails.game.state.IntegerState; --- 1,5 ---- package rails.game.specific._1856; ! import rails.game.*; import rails.game.state.IntegerState; *************** *** 9,23 **** private IntegerState trainNumberAvailableAtStart; ! private IntegerState moneyInEscrow; ! public void start(StockSpaceI startSpace) { ! super.start(startSpace); ! ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); int trainNumber; ! try { trainNumber = Integer.parseInt(nextAvailableTrain.getName()); } catch (NumberFormatException e) { --- 7,25 ---- private IntegerState trainNumberAvailableAtStart; ! private IntegerState moneyInEscrow; ! ! /** Used for CGR */ ! private boolean hadPermanentTrain = false; ! ! @Override public void start(StockSpaceI startSpace) { ! super.start(startSpace); ! ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); int trainNumber; ! try { trainNumber = Integer.parseInt(nextAvailableTrain.getName()); } catch (NumberFormatException e) { *************** *** 27,43 **** = new IntegerState (name+"_trainAtStart"); trainNumberAvailableAtStart.set(trainNumber); ! if (trainNumber == 6) { this.capitalisation = CAPITALISE_FULL; } ! moneyInEscrow = new IntegerState (name+"_moneyInEscrow", 0); } ! public int getTrainNumberAvailableAtStart () { return trainNumberAvailableAtStart.intValue(); } ! public void setMoneyInEscrow (int amount) { moneyInEscrow.set(amount); --- 29,45 ---- = new IntegerState (name+"_trainAtStart"); trainNumberAvailableAtStart.set(trainNumber); ! if (trainNumber == 6) { this.capitalisation = CAPITALISE_FULL; } ! moneyInEscrow = new IntegerState (name+"_moneyInEscrow", 0); } ! public int getTrainNumberAvailableAtStart () { return trainNumberAvailableAtStart.intValue(); } ! public void setMoneyInEscrow (int amount) { moneyInEscrow.set(amount); *************** *** 47,53 **** moneyInEscrow.add(amount); } ! public int getMoneyInEscrow () { return moneyInEscrow.intValue(); } } --- 49,67 ---- moneyInEscrow.add(amount); } ! public int getMoneyInEscrow () { return moneyInEscrow.intValue(); } + + public boolean hadPermanentTrain() { + return hadPermanentTrain; + } + + @Override + public void buyTrain(TrainI train, int price) { + super.buyTrain (train, price); + if (train.getType().isPermanent()) hadPermanentTrain = true; + } + + } Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CGRFormationRound.java 4 Feb 2009 20:36:39 -0000 1.1 --- CGRFormationRound.java 4 May 2009 20:29:14 -0000 1.2 *************** *** 4,18 **** import rails.game.*; ! import rails.game.action.RepayLoans; import rails.game.move.CashMove; import rails.util.LocalText; ! public class CGRFormationRound extends OperatingRound { ! /* This isn't really a stock round, but it must subclass one of the ! * three base types, otherwise the not-subclassable GameUIManager ! * cannot handle it. StockRound has been chosen because the UI ! * should show the StatusWindow. ! */ private Player startingPlayer; --- 4,17 ---- import rails.game.*; ! import rails.game.action.*; import rails.game.move.CashMove; + import rails.game.move.MoveSet; + import rails.game.state.IntegerState; import rails.util.LocalText; ! public class CGRFormationRound extends SwitchableUIRound { ! ! private final String CGRNAME = "CGR"; private Player startingPlayer; *************** *** 21,24 **** --- 20,35 ---- private int maxLoansToRepayByPresident = 0; private List<PublicCompanyI> mergingCompanies = new ArrayList<PublicCompanyI>(); + private PublicCompanyI cgr = gameManager.getCompanyManager().getCompanyByName(CGRNAME); + private String cgrName = CGRNAME; + private List<TrainI> trainsToDiscardFrom = null; + private boolean forcedTrainDiscard = true; + private List<ExchangeableToken> tokensToExchangeFrom = null; + private List<BaseToken> nonHomeTokens = null; + + private IntegerState stepObject = new IntegerState ("CGRFormStep", 0); + + public static final int STEP_REPAY_LOANS = 1; + public static final int STEP_DISCARD_TRAINS = 2; + public static final int STEP_EXCHANGE_TOKENS = 3; public CGRFormationRound (GameManagerI gameManager) { *************** *** 32,35 **** --- 43,47 ---- public Class<? extends RoundI> getRoundTypeForUI () { return StockRound.class; + //return OperatingRound.class; } *************** *** 60,67 **** --- 72,89 ---- } + setStep(STEP_REPAY_LOANS); + setCurrentPlayer (startingPlayer); setNextCompanyNeedingPresidentIntervention(); } + + private void setStep(int step) { + stepObject.set(step); + } + + private int getStep() { + return stepObject.intValue(); + } private boolean setNextCompanyNeedingPresidentIntervention () { *************** *** 164,181 **** public boolean setPossibleActions() { ! RepayLoans action = new RepayLoans (currentCompany, 0, ! maxLoansToRepayByPresident, ! currentCompany.getValuePerLoan()); ! possibleActions.add(action); ! operatingCompany = currentCompany; return true; } - @Override protected boolean repayLoans (RepayLoans action) { ! boolean result = super.repayLoans(action); ! if (action.getCompany().getCurrentNumberOfLoans() > 0) { mergingCompanies.add(currentCompany); String message = LocalText.getText("WillMergeInto", --- 186,252 ---- public boolean setPossibleActions() { ! int step = getStep(); ! if (step == STEP_REPAY_LOANS) { ! RepayLoans action = new RepayLoans (currentCompany, 0, ! maxLoansToRepayByPresident, ! currentCompany.getValuePerLoan()); ! possibleActions.add(action); ! roundTypeForUI = StockRound_1856.class; ! } else if (step == STEP_EXCHANGE_TOKENS) { ! int numberToExchange = cgr.getNumberOfFreeBaseTokens(); ! ExchangeTokens action = new ExchangeTokens (tokensToExchangeFrom, ! numberToExchange, numberToExchange); ! action.setCompany(cgr); ! possibleActions.add(action); ! roundTypeForUI = OperatingRound_1856.class; ! } else if (step == STEP_DISCARD_TRAINS) { ! DiscardTrain action = new DiscardTrain (cgr, ! trainsToDiscardFrom, forcedTrainDiscard); ! possibleActions.add(action); ! roundTypeForUI = OperatingRound_1856.class; ! } return true; } protected boolean repayLoans (RepayLoans action) { + + // TODO Validation skipped for now... ! MoveSet.start(true); ! ! PublicCompanyI company = action.getCompany(); ! int numberRepaid = action.getNumberRepaid(); ! int repayment = numberRepaid * company.getValuePerLoan(); ! ! if (repayment > 0) { ! ! int repaymentByCompany = Math.min (repayment, company.getCash()); ! int repaymentByPresident = repayment - repaymentByCompany; ! ! company.addLoans(-numberRepaid); ! if (repaymentByCompany > 0) { ! new CashMove (company, null, repaymentByCompany); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", ! company.getName(), ! Bank.format(repaymentByCompany), ! Bank.format(repayment), ! numberRepaid, ! Bank.format(company.getValuePerLoan()))); ! } ! if (repaymentByPresident > 0) { ! Player president = company.getPresident(); ! new CashMove (president, null, repaymentByPresident); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoansWithPresCash", ! company.getName(), ! Bank.format(repaymentByPresident), ! Bank.format(repayment), ! numberRepaid, ! Bank.format(company.getValuePerLoan()), ! president.getName())); ! } ! } ! ! if (action.getCompany().getCurrentNumberOfLoans() > 0) { mergingCompanies.add(currentCompany); String message = LocalText.getText("WillMergeInto", *************** *** 184,197 **** DisplayBuffer.add(message, true); ReportBuffer.add(message); } ! if (!setNextCompanyNeedingPresidentIntervention()) { gameManager.nextRound(this); } ! return result; } --- 255,680 ---- DisplayBuffer.add(message, true); ReportBuffer.add(message); + + } + + return true; + + } + + private void formCGR () { + + Player player; + Portfolio portfolio; + int count, cgrSharesUsed, oldShares, newShares; + PublicCertificateI cgrCert, poolCert; + List<PublicCertificateI> certs = new ArrayList<PublicCertificateI>(); + Portfolio scrapHeap = Bank.getScrapHeap(); + Portfolio pool = Bank.getPool(); + Portfolio unavailable = Bank.getUnavailable(); + Portfolio ipo = Bank.getIpo(); + Player temporaryPresident = null; + Player newPresident = null; + Player firstCGRowner = null; + int maxShares = 0; + + // Exchange the player shares + setCurrentPlayer(startingPlayer); + cgrSharesUsed = 0; + + do { + player = getCurrentPlayer(); + portfolio = player.getPortfolio(); + oldShares = newShares = 0; + certs.clear(); + poolCert = null; + + for (PublicCertificateI cert : player.getPortfolio().getCertificates()) { + if (mergingCompanies.contains(cert.getCompany())) { + certs.add((cert)); + oldShares++; + if (cert.isPresidentShare()) { + oldShares++; + } + } + } + if (oldShares > 0) { + + count = oldShares; + if (count >= 4 && temporaryPresident == null && cgrSharesUsed <= 18) { + cgrCert = cgr.getPresidentsShare(); + cgrCert.moveTo(portfolio); + count -= 4; + cgrSharesUsed += 2; + newShares += 2; + temporaryPresident = player; + } + while (count >= 2 && cgrSharesUsed <= 19) { + cgrCert = unavailable.findCertificate(cgr, false); + cgrCert.moveTo(portfolio); + count -= 2; + cgrSharesUsed++; + newShares++; + } + + String message = LocalText.getText("HasMergedShares", + player.getName(), + oldShares, + newShares, + "CGR"); + DisplayBuffer.add(message, false); + ReportBuffer.add(message); + + if (count == 1) { + // Should work OK even if this is a president's share. + // In the pool we will treat all certs equally. + poolCert = certs.get(certs.size()-1); + poolCert.moveTo(pool); + certs.remove(poolCert); + + message = LocalText.getText("HasPutShareInPool", + player.getName()); + DisplayBuffer.add(message, false); + ReportBuffer.add(message); + + } + // Note: old shares are removed when company is closed + + if (firstCGRowner == null) firstCGRowner = player; + + // Check for presidency + if (newShares > maxShares) { + maxShares = newShares; + newPresident = player; + } + } + + gameManager.setNextPlayer(); + + } while (getCurrentPlayer() != startingPlayer); + + // Exchange the pool shares + certs.clear(); + oldShares = newShares = 0; + + for (PublicCertificateI cert : pool.getCertificates()) { + if (mergingCompanies.contains(cert.getCompany())) { + certs.add((cert)); + oldShares++; + } + } + count = oldShares; + while (count >= 2 && cgrSharesUsed <= 19) { + cgrCert = unavailable.findCertificate(cgr, false); + cgrCert.moveTo(pool); + count -= 2; + cgrSharesUsed++; + newShares++; } ! String message = LocalText.getText("HasMergedShares", ! LocalText.getText("POOL"), ! oldShares, ! newShares, ! "CGR"); ! DisplayBuffer.add(message); ! ReportBuffer.add(message); ! ! for (PublicCertificateI discardCert : certs) { ! discardCert.moveTo(scrapHeap); ! } ! ! log.info(cgrSharesUsed+" CGR shares are now in play"); ! // Move the remaining CGR shares to the ipo. ! // Must clone the list first ! certs = new ArrayList<PublicCertificateI>(unavailable.getCertificatesPerCompany("CGR")); ! for (PublicCertificateI cert : certs) { ! cert.moveTo(ipo); ! } ! ! // Assign the new president ! if (temporaryPresident != newPresident) { ! temporaryPresident.getPortfolio().swapPresidentCertificate(cgr, ! newPresident.getPortfolio()); ! } ! ! newPresident.getPortfolio().getShareModel(cgr).setShare(); ! message = LocalText.getText("IS_NOW_PRES_OF", ! newPresident.getName(), cgrName); ! ReportBuffer.add(message); ! DisplayBuffer.add(message); ! ! // Collect the old token spots, and move cash and trains ! List<BaseToken> homeTokens = new ArrayList<BaseToken>(); ! nonHomeTokens = new ArrayList<BaseToken>(); ! BaseToken bt; ! MapHex hex; ! City city; ! for (PublicCompanyI comp : mergingCompanies) { ! for (TokenI token :comp.getTokens()) { ! if (token instanceof BaseToken) { ! bt = (BaseToken) token; ! if (!bt.isPlaced()) continue; ! city = (City) bt.getHolder(); ! hex = city.getHolder(); ! if (hex == comp.getHomeHex()) { ! homeTokens.add(bt); ! } else { ! nonHomeTokens.add(bt); ! } ! } ! } ! ! if (comp.getCash() > 0) { ! new CashMove (comp, cgr, comp.getCash()); ! } ! List<TrainI> trains = new ArrayList<TrainI> (comp.getPortfolio().getTrainList()); ! for (TrainI train : trains) { ! train.moveTo(cgr.getPortfolio()); ! } ! } ! ! // Replace the home tokens ! for (BaseToken token : homeTokens) { ! city = (City) token.getHolder(); ! hex = city.getHolder(); ! token.moveTo(token.getCompany()); ! if (hex.layBaseToken(cgr, city.getNumber())) { ! /* TODO: the false return value must be impossible. */ ! ReportBuffer.add(LocalText.getText("ExchangesBaseToken", ! cgrName, token.getCompany().getName(), ! city.getName())); ! cgr.layBaseToken(hex, 0); ! } ! } ! ! // Clean up any non-home tokens on cities now having a CGR token ! for (BaseToken token : new ArrayList<BaseToken>(nonHomeTokens)) { ! city = (City) token.getHolder(); ! hex = city.getHolder(); ! List<BaseToken> otherTokens = hex.getBaseTokens(); ! if (otherTokens != null) { ! for (BaseToken token2 : otherTokens) { ! if (token2.getCompany() == cgr) { ! ReportBuffer.add(LocalText.getText("DiscardsBaseToken", ! cgrName, token.getCompany().getName(), ! city.getName())); ! token.moveTo(token.getCompany()); ! nonHomeTokens.remove(token); ! break; ! } ! } ! } ! } ! ! // Prepare replacing the other tokens, if possible ! if (homeTokens.size() + nonHomeTokens.size() > cgr.getNumberOfBaseTokens()) { ! // CGR cannot replace all tokens, must choose ! // First collect old names per city ! Map<String, String> oldTokens = new HashMap<String, String>(); ! String cityName; ! for (BaseToken token : nonHomeTokens) { ! if (token.getHolder() instanceof City) { ! cityName = token.getHolder().getName(); ! if (oldTokens.containsKey(cityName)) { ! oldTokens.put(cityName, ! oldTokens.get(cityName)+","+token.getCompany().getName()); ! } else { ! oldTokens.put(cityName, token.getCompany().getName()); ! } ! } ! } ! // Then create list of exchange spots. Sort it on hexname/city number ! tokensToExchangeFrom = new ArrayList<ExchangeableToken>(); ! for (String key : new TreeSet<String> (oldTokens.keySet())) { ! tokensToExchangeFrom.add(new ExchangeableToken( ! key, oldTokens.get(key))); ! } ! } else { ! executeExchangeTokens (nonHomeTokens); ! } + // Close the absorbed companies and float the CGR + for (PublicCompanyI comp : mergingCompanies) { + comp.setClosed(); + } + cgr.start(100); // TODO: assign correct starting price + cgr.setFloated(); + + // Check the trains, autodiscard any excess non-permanent trains + int trainLimit = cgr.getTrainLimit(gameManager.getCurrentPlayerIndex()); + List<TrainI> trains = cgr.getPortfolio().getTrainList(); + outer: while (cgr.getNumberOfTrains() > trainLimit) { + for (TrainI train : trains) { + if (!train.getType().isPermanent()) { + train.moveTo(pool); + ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", + cgrName, train.getName())); + continue outer; + } + } + break; + } + } + + private void executeExchangeTokens (List<BaseToken> exchangedTokens) { + City city; + MapHex hex; + for (BaseToken token : exchangedTokens) { + // Remove old token + city = (City) token.getHolder(); + hex = city.getHolder(); + token.moveTo(token.getCompany()); + // Replace it with a CGR token + if (hex.layBaseToken(cgr, city.getNumber())) { + cgr.layBaseToken(hex, 0); + //log.debug("CGR exchanges a token at "+hex.getName()+" "+hex.getCityName()); + } else { + log.error("Error in laying CGR token on "+hex.getName()+" "+hex.getCityName()); + } + } + } + + public boolean process (PossibleAction action) { + + boolean result = false; + + if (action instanceof RepayLoans) { + result = repayLoans((RepayLoans)action); + } else if (action instanceof DiscardTrain) { + result = discardTrain((DiscardTrain)action); + } else if (action instanceof ExchangeTokens) { + result = exchangeTokens ((ExchangeTokens)action); + } + if (!result) return false; + + if (getStep() == STEP_REPAY_LOANS) { + + if (setNextCompanyNeedingPresidentIntervention()) { + return true; + } + + if (!mergingCompanies.isEmpty()) { + formCGR(); + setStep (STEP_EXCHANGE_TOKENS); + } + } + + if (getStep() == STEP_EXCHANGE_TOKENS) { + + if (action instanceof ExchangeTokens) { + tokensToExchangeFrom = null; + } else if (tokensToExchangeFrom != null + && !tokensToExchangeFrom.isEmpty()) { + return true; + } + setStep (STEP_DISCARD_TRAINS); + } + + if (getStep() == STEP_DISCARD_TRAINS) { + + if (checkForTrainsToDiscard()) return true; gameManager.nextRound(this); } ! return true; ! } ! ! ! private boolean checkForTrainsToDiscard () { + // Check if CGR must discard trains + if (cgr.getNumberOfTrains() > cgr.getCurrentTrainLimit()) { + log.debug("CGR must discard trains"); + if (getStep() != STEP_DISCARD_TRAINS) { + setStep(STEP_DISCARD_TRAINS); + } + trainsToDiscardFrom = cgr.getPortfolio().getTrainList(); + forcedTrainDiscard = true; + return true; + } else { + // Check if CGR still has non-permanent trains + // these may be discarded voluntarily + trainsToDiscardFrom = new ArrayList<TrainI>(); + for (TrainI train : cgr.getPortfolio().getTrainList()) { + if (!train.getType().isPermanent()) { + trainsToDiscardFrom.add(train); + } + } + if (!trainsToDiscardFrom.isEmpty()) { + if (getStep() != STEP_DISCARD_TRAINS) { + setStep(STEP_DISCARD_TRAINS); + } + forcedTrainDiscard = false; + return true; + } + } + return false; + } + + public boolean discardTrain(DiscardTrain action) { + + TrainI train = action.getDiscardedTrain(); + PublicCompanyI company = action.getCompany(); + String companyName = company.getName(); + + String errMsg = null; + + // Dummy loop to enable a quick jump out. + while (true) { + // Checks + // Must be CGR + if (company != cgr) { + errMsg = LocalText.getText("WrongCompany", + company.getName(), + cgrName); + break; + } + // Must be correct step + if (getStep() != STEP_DISCARD_TRAINS) { + errMsg = LocalText.getText("WrongActionNoDiscardTrain"); + break; + } + + if (train == null && action.isForced()) { + errMsg = LocalText.getText("NoTrainSpecified"); + break; + } + + // Does the company own such a train? + + if (train != null && !company.getPortfolio().getTrainList().contains(train)) { + errMsg = + LocalText.getText("CompanyDoesNotOwnTrain", + company.getName(), + train.getName() ); + break; + } + + break; + } + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CannotDiscardTrain", + companyName, + train.getName(), + errMsg )); + return false; + } + + /* End of validation, start of execution */ + MoveSet.start(true); + + if (train != null) { + + if (action.isForced()) MoveSet.setLinkedToPrevious(); + + train.moveTo(Bank.getPool()); + ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", + companyName, + train.getName() )); + + } + + return true; } *************** *** 201,203 **** --- 684,687 ---- } + } |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:32
|
Update of /cvsroot/rails/18xx/rails/game/action In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/game/action Modified Files: DiscardTrain.java RepayLoans.java Added Files: ExchangeableToken.java ExchangeTokens.java Log Message: 1856 CGR formation round Index: RepayLoans.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/RepayLoans.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RepayLoans.java 4 Feb 2009 20:36:40 -0000 1.3 --- RepayLoans.java 4 May 2009 20:29:15 -0000 1.4 *************** *** 96,100 **** .append(" maxNumber=").append(maxNumber) .append(" value=").append(price); ! if (numberRepaid != 0) { b.append(" numberRepaid="+numberRepaid); } --- 96,100 ---- .append(" maxNumber=").append(maxNumber) .append(" value=").append(price); ! if (acted) { b.append(" numberRepaid="+numberRepaid); } --- NEW FILE: ExchangeableToken.java --- /* $Header: /cvsroot/rails/18xx/rails/game/action/ExchangeableToken.java,v 1.1 2009/05/04 20:29:15 evos Exp $ * * Created on 20-May-2006 * Change Log: */ package rails.game.action; import java.io.Serializable; /** * A simple, serializable class that holds the <i>original</i> location * of a Base token, to facilitate its replacement even after its company * has been closed and all its tokens removed. This class is used in * the ExchangeTokens action class. * @author Erik Vos */ public class ExchangeableToken implements Serializable { private String cityName; private String oldCompanyName; private boolean selected = false; public static final long serialVersionUID = 1L; public ExchangeableToken (String cityName, String oldCompanyName) { this.cityName = cityName; this.oldCompanyName = oldCompanyName; } public String getCityName() { return cityName; } public String getOldCompanyName() { return oldCompanyName; } public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } public String toString() { return cityName+"["+oldCompanyName+"]" + (selected ? "*" : ""); } } --- NEW FILE: ExchangeTokens.java --- /* $Header: /cvsroot/rails/18xx/rails/game/action/ExchangeTokens.java,v 1.1 2009/05/04 20:29:15 evos Exp $ * * Created on 20-May-2006 * Change Log: */ package rails.game.action; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import rails.game.*; /** * @author Erik Vos */ public class ExchangeTokens extends PossibleORAction { // Server settings private List<ExchangeableToken> tokensToExchange = new ArrayList<ExchangeableToken>(); private int minNumberToExchange = 0; private int maxNumberToExchange = 0; // Client settings public static final long serialVersionUID = 1L; public ExchangeTokens(List<ExchangeableToken> tokensToSelectFrom, int minNumberToExchange, int maxNumberToExchange) { super(); this.tokensToExchange = tokensToSelectFrom; this.minNumberToExchange = minNumberToExchange; this.maxNumberToExchange = maxNumberToExchange; } public void setExchangedTokens(List<ExchangeableToken> exchangedTokens) { for (ExchangeableToken t : exchangedTokens) { t.setSelected(true); } } public int getMaxNumberToExchange() { return maxNumberToExchange; } public int getMinNumberToExchange() { return minNumberToExchange; } public List<ExchangeableToken> getTokensToExchange() { return tokensToExchange; } @Override public String toString() { StringBuffer b = new StringBuffer(); b.append("ExchangeTokens for "+companyName+":"); for (ExchangeableToken token : tokensToExchange) { b.append(" ").append(token.toString()); } b.append(" min=").append (minNumberToExchange); b.append(" max=").append (maxNumberToExchange); return b.toString(); } @Override public boolean equals(PossibleAction action) { if (!(action instanceof ExchangeTokens)) return false; ExchangeTokens a = (ExchangeTokens) action; return a.tokensToExchange == tokensToExchange && a.company == company; } /** Deserialize */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); } } Index: DiscardTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/DiscardTrain.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DiscardTrain.java 4 Jun 2008 19:00:29 -0000 1.8 --- DiscardTrain.java 4 May 2009 20:29:15 -0000 1.9 *************** *** 71,80 **** StringBuffer b = new StringBuffer(); b.append("Discard train: ").append(company.getName()); ! b.append(" has"); for (TrainI train : ownedTrains) { b.append(" ").append(train.getName()); } if (discardedTrain != null) { ! b.append(" discards ").append(discardedTrain.getName()); } return b.toString(); --- 71,81 ---- StringBuffer b = new StringBuffer(); b.append("Discard train: ").append(company.getName()); ! b.append(" one of"); for (TrainI train : ownedTrains) { b.append(" ").append(train.getName()); } + b.append(forced ? "," : ", not").append (" forced,"); if (discardedTrain != null) { ! b.append(" and discards ").append(discardedTrain.getName()); } return b.toString(); |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:31
|
Update of /cvsroot/rails/18xx In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969 Modified Files: LocalisedText.properties Log Message: 1856 CGR formation round Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.68 retrieving revision 1.69 diff -C2 -d -r1.68 -r1.69 *** LocalisedText.properties 4 Feb 2009 20:36:40 -0000 1.68 --- LocalisedText.properties 4 May 2009 20:29:15 -0000 1.69 *************** *** 38,41 **** --- 38,43 ---- BuysTrainUsingSP={0} buys a {1}-train from {2} for {3} using {4}. CASH=Cash + CanOperate={0} can operate this round + CannotOperate={0} cannot operate this round CannotBuyAnything={0} cannot buy anything CERT_NAME={0} {1}% share *************** *** 57,60 **** --- 59,63 ---- CannotDumpPresidency=Cannot dump presidency CannotDumpTrainBuyingPresidency=Cannot dump presidency of train buying company + CannotExchangeTokens={0} cannot {1}: {2} CannotLayBaseTokenOn={0} cannot lay a base token on {1} for {2}: {3} CannotLayTileOn={0} cannot lay tile {1} on {2} for {3}: {4} *************** *** 108,112 **** DestinationReached={0} has reached its destination hex {1} DestinationsReached=Destinations reached ! DestinationsReachedPrompt=Select companies that have reached their destinations DiscardTrain=Discard {0}-train DoesNotExist=Item does not exist --- 111,116 ---- DestinationReached={0} has reached its destination hex {1} DestinationsReached=Destinations reached ! DestinationsReachedPrompt=Select companies that have reached their destinations ! DiscardsBaseToken={0} discards a {1} base token on {2} DiscardTrain=Discard {0}-train DoesNotExist=Item does not exist *************** *** 126,129 **** --- 130,138 ---- EndOfOperatingRound=End of Operating Round {0} EnterRevenue=Enter the earnings of the operating company + ExchangesBaseToken={0} exchanges a {1} base token on {2} + ExchangeableToken=Hex {1} {2}, city {3} (with tracks to {4}) [was {0} token] + ExchangeTokens=Exchange tokens + ExchangeTokensPrompt1=Select {0} cities where {1} will exchange a base token + ExchangeTokensPrompt2=Select {0} through {1} cities where {2} will exchange a base token ExchangesTrain={0} exchanges a {1}-train for a {2}-train from {3} for {4} ExtraTile= You can lay an unconnected tile on {0}. *************** *** 153,156 **** --- 162,167 ---- GetNoShareForMinor={0} does not get a share for Minor {1}, which closes HasFirstTurn={0} has the first turn + HasMergedShares={0} has exchanged {1} old shares for {2} {3} shares + HasPutShareInPool={0} has put one remaining share in the pool HAS_TOO_MANY_TRAINS={0}: company {1} has too many trains. Which train do you discard? HasTooManyTrains={0} has too many trains ({1}, limit is {2}). Select one train to discard. *************** *** 200,203 **** --- 211,215 ---- MapWindowORTitle=Rails: Map, Operating Round {0} or {1} MARKET=Stock Market + MayDiscardTrain={0} may voluntarily discard a train MayNotBuyAndSell={0} may not both buy and sell shares MayNotYetOperate={0} may not yet operate: {1}% sold whereas {2}% required *************** *** 216,219 **** --- 228,232 ---- NEW=New NewGame=New Game + NoBaseTokenExchange={0} does not exchange a token on {1} NoDumping=Cannot dump presidency NoGameOptions=This game has no options *************** *** 342,346 **** StartOfPhase=Start of phase {0}. StartPacketHasNoClass=Start packet {0} has no class defined. ! StartStockRound=Start of Stock Round Status_Unavailable=Currently unavailable Status_Biddable=Click to bid on this item --- 355,359 ---- StartOfPhase=Start of phase {0}. StartPacketHasNoClass=Start packet {0} has no class defined. ! StartStockRound=Start of Stock Round {0} Status_Unavailable=Currently unavailable Status_Biddable=Click to bid on this item *************** *** 422,425 **** --- 435,439 ---- WrongActionNoTrainBuyingCost=Wrong action, expected train buying cost WrongCompany=Wrong company: {0} (expected {1}) + WrongNumberOfTokensExchanged: {0} must exchange {1} through {2} tokens but did {3} WrongPhase=Wrong phase {0} WrongPlayer=Wrong player {0} - {1} has the turn |
Update of /cvsroot/rails/18xx/rails/game In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/game Modified Files: Portfolio.java StockRound.java StockMarket.java MapHex.java TrainType.java Game.java PublicCompany.java TrainManager.java GameManager.java StockMarketI.java OperatingRound.java GameManagerI.java Round.java City.java TrainTypeI.java Added Files: SwitchableUIRound.java Log Message: 1856 CGR formation round Index: TrainTypeI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainTypeI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TrainTypeI.java 3 Jan 2009 18:24:53 -0000 1.7 --- TrainTypeI.java 4 May 2009 20:29:14 -0000 1.8 *************** *** 94,98 **** public String getRustedTrainTypeName(); ! public void setReleasedTrainType(TrainTypeI releasedTrainType); --- 94,102 ---- public String getRustedTrainTypeName(); ! ! public boolean isPermanent(); ! ! public void setPermanent(boolean permanent); ! public void setReleasedTrainType(TrainTypeI releasedTrainType); Index: Portfolio.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Portfolio.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** Portfolio.java 24 Jan 2009 15:10:26 -0000 1.32 --- Portfolio.java 4 May 2009 20:29:14 -0000 1.33 *************** *** 164,168 **** public void addCertificate(PublicCertificateI certificate) { // When undoing a company start, put the President back at the top. ! boolean atTop = certificate.isPresidentShare() && this == Bank.getIpo(); if (atTop) --- 164,168 ---- public void addCertificate(PublicCertificateI certificate) { // When undoing a company start, put the President back at the top. ! boolean atTop = certificate.isPresidentShare()/* && this == Bank.getIpo()*/; if (atTop) Index: StockMarketI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockMarketI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** StockMarketI.java 4 Jun 2008 19:00:31 -0000 1.7 --- StockMarketI.java 4 May 2009 20:29:14 -0000 1.8 *************** *** 31,34 **** --- 31,36 ---- public void moveUp(PublicCompanyI company); + + public void close (PublicCompanyI company); public int getNumberOfColumns(); Index: PublicCompany.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/PublicCompany.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** PublicCompany.java 24 Jan 2009 15:10:28 -0000 1.48 --- PublicCompany.java 4 May 2009 20:29:14 -0000 1.49 *************** *** 875,878 **** --- 875,880 ---- Util.moveObjects(laidBaseTokens, this); + StockMarket.getInstance().close(this); + } Index: TrainManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainManager.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** TrainManager.java 24 Jan 2009 15:10:29 -0000 1.15 --- TrainManager.java 4 May 2009 20:29:14 -0000 1.16 *************** *** 1 **** ! /* $Header$ */ package rails.game; import java.util.*; import rails.game.state.IntegerState; import rails.util.LocalText; import rails.util.Tag; public class TrainManager implements TrainManagerI, ConfigurableComponentI { // Static attributes protected List<TrainTypeI> lTrainTypes = new ArrayList<TrainTypeI>(); protected Map<String, TrainTypeI> mTrainTypes = new HashMap<String, TrainTypeI>(); protected boolean buyAtFaceValueBetweenDifferentPresidents = false; // Dynamic attributes protected Portfolio unavailable = null; protected IntegerState newTypeIndex; protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; // Non-game attributes private static TrainManagerI instance = null; protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { instance = this; ipo = Bank.getIpo(); unavailable = Bank.getUnavailable(); // Nothing to do here, everything happens when configured. newTypeIndex = new IntegerState("NewTrainTypeIndex", 0); } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { TrainType defaultType = null; TrainType newType; Tag defaultsTag = tag.getChild("Defaults"); if (defaultsTag != null) { defaultType = new TrainType(false); defaultType.configureFromXML(defaultsTag); } List<Tag> typeTags = tag.getChildren("Train"); for (Tag typeTag : typeTags) { if (defaultType != null) { newType = (TrainType) defaultType.clone(); if (newType == null) { throw new ConfigurationException("Cannot clone traintype " + defaultType.getName()); } } else { newType = new TrainType(true); } lTrainTypes.add(newType); newType.configureFromXML(typeTag); mTrainTypes.put(newType.getName(), newType); } // Special train buying rules Tag rulesTag = tag.getChild("TrainBuyingRules"); if (rulesTag != null) { // A 1851 special buyAtFaceValueBetweenDifferentPresidents = rulesTag.getChild("FaceValueIfDifferentPresidents") != null; } // Finish initialisation of the train types for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeName() != null) { type.setReleasedTrainType(mTrainTypes.get(type.getReleasedTrainTypeName())); } if (type.getRustedTrainTypeName() != null) { type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); } } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(); } /** * Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the * IPO. * * @param holder The Portfolio for which this list will be made (always * IPO). */ public static String makeAbbreviatedList(Portfolio holder) { StringBuffer b = new StringBuffer(); TrainI[] trains; for (TrainTypeI type : instance.getTrainTypes()) { trains = holder.getTrainsPerType(type); if (trains.length > 0) { if (b.length() > 0) b.append(" "); b.append(type.getName()).append("("); if (type.hasInfiniteAmount()) { b.append("+"); } else { b.append(trains.length); } b.append(")"); } } return b.toString(); } /** * Make a full list of trains, like "2 2 3 3", to show in any field * describing train possessions, except the IPO. * * @param holder The Portfolio for which this list will be made. */ public static String makeFullList(Portfolio holder) { List<TrainI> trains = holder.getTrainList(); if (trains == null || trains.size() == 0) return ""; return makeFullList(trains); } public static String makeFullList(List<TrainI> trains) { StringBuffer b = new StringBuffer(); for (TrainI train : trains) { if (b.length() > 0) b.append(" "); if (train.isObsolete()) b.append("("); b.append(train.toDisplay()); if (train.isObsolete()) b.append(")"); } return b.toString(); } /** * This method handles any consequences of new train buying (from the IPO), * such as rusting and phase changes. It must be called <b>after</b> the * train has been transferred. * */ public void checkTrainAvailability(TrainI train, Portfolio from) { trainsHaveRusted = false; phaseHasChanged = false; if (from != ipo) return; TrainTypeI boughtType, nextType; boughtType = train.getType(); if (boughtType == ((TrainTypeI) lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = ((TrainTypeI) lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(); trainAvailabilityChanged = true; ReportBuffer.add("All " + boughtType.getName() + "-trains are sold out, " + nextType.getName() + "-trains now available"); } } if (boughtType.getNumberBoughtFromIPO() == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); String newPhase = boughtType.getStartedPhaseName(); if (newPhase != null) { PhaseManager.getInstance().setPhase(newPhase); phaseHasChanged = true; } TrainTypeI rustedType = boughtType.getRustedTrainType(); if (rustedType != null && !rustedType.hasRusted()) { rustedType.setRusted(train.getHolder()); // Or obsolete, // where applicable ReportBuffer.add(LocalText.getText("TrainsRusted", rustedType.getName())); trainsHaveRusted = true; trainAvailabilityChanged = true; } TrainTypeI releasedType = boughtType.getReleasedTrainType(); if (releasedType != null) { if (!releasedType.isAvailable()) releasedType.setAvailable(); ReportBuffer.add(LocalText.getText("TrainsAvailable", releasedType.getName())); trainAvailabilityChanged = true; } } } public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); TrainI train; for (TrainTypeI type : lTrainTypes) { if (type.isAvailable()) { train = ipo.getTrainOfType(type); if (train != null) { availableTrains.add(train); } } } return availableTrains; } public TrainTypeI getTypeByName(String name) { return (TrainTypeI) mTrainTypes.get(name); } public List<TrainTypeI> getTrainTypes() { return lTrainTypes; } public boolean hasAvailabilityChanged() { return trainAvailabilityChanged; } public void resetAvailabilityChanged() { trainAvailabilityChanged = false; } public boolean hasPhaseChanged() { return phaseHasChanged; } public boolean buyAtFaceValueBetweenDifferentPresidents() { return buyAtFaceValueBetweenDifferentPresidents; } } \ No newline at end of file --- 1 ---- ! /* $Header$ */ package rails.game; import java.util.*; import rails.game.state.IntegerState; import rails.util.LocalText; import rails.util.Tag; public class TrainManager implements TrainManagerI, ConfigurableComponentI { // Static attributes protected List<TrainTypeI> lTrainTypes = new ArrayList<TrainTypeI>(); protected Map<String, TrainTypeI> mTrainTypes = new HashMap<String, TrainTypeI>(); protected boolean buyAtFaceValueBetweenDifferentPresidents = false; // Dynamic attributes protected Portfolio unavailable = null; protected IntegerState newTypeIndex; protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; // Non-game attributes private static TrainManagerI instance = null; protected Portfolio ipo = null; /** * No-args constructor. */ public TrainManager() { instance = this; ipo = Bank.getIpo(); unavailable = Bank.getUnavailable(); // Nothing to do here, everything happens when configured. newTypeIndex = new IntegerState("NewTrainTypeIndex", 0); } /** * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { TrainType defaultType = null; TrainType newType; Tag defaultsTag = tag.getChild("Defaults"); if (defaultsTag != null) { defaultType = new TrainType(false); defaultType.configureFromXML(defaultsTag); } List<Tag> typeTags = tag.getChildren("Train"); for (Tag typeTag : typeTags) { if (defaultType != null) { newType = (TrainType) defaultType.clone(); if (newType == null) { throw new ConfigurationException("Cannot clone traintype " + defaultType.getName()); } } else { newType = new TrainType(true); } lTrainTypes.add(newType); newType.configureFromXML(typeTag); mTrainTypes.put(newType.getName(), newType); } // Special train buying rules Tag rulesTag = tag.getChild("TrainBuyingRules"); if (rulesTag != null) { // A 1851 special buyAtFaceValueBetweenDifferentPresidents = rulesTag.getChild("FaceValueIfDifferentPresidents") != null; } // Finish initialisation of the train types for (TrainTypeI type : lTrainTypes) { if (type.getReleasedTrainTypeName() != null) { type.setReleasedTrainType(mTrainTypes.get(type.getReleasedTrainTypeName())); } if (type.getRustedTrainTypeName() != null) { type.setRustedTrainType(mTrainTypes.get(type.getRustedTrainTypeName())); mTrainTypes.get(type.getRustedTrainTypeName()).setPermanent(false); } } // By default, set the first train type to "available". newTypeIndex.set(0); lTrainTypes.get(newTypeIndex.intValue()).setAvailable(); } /** * Make an abbreviated list of trains, like "2(6) 3(5)" etc, to show in the * IPO. * * @param holder The Portfolio for which this list will be made (always * IPO). */ public static String makeAbbreviatedList(Portfolio holder) { StringBuffer b = new StringBuffer(); TrainI[] trains; for (TrainTypeI type : instance.getTrainTypes()) { trains = holder.getTrainsPerType(type); if (trains.length > 0) { if (b.length() > 0) b.append(" "); b.append(type.getName()).append("("); if (type.hasInfiniteAmount()) { b.append("+"); } else { b.append(trains.length); } b.append(")"); } } return b.toString(); } /** * Make a full list of trains, like "2 2 3 3", to show in any field * describing train possessions, except the IPO. * * @param holder The Portfolio for which this list will be made. */ public static String makeFullList(Portfolio holder) { List<TrainI> trains = holder.getTrainList(); if (trains == null || trains.size() == 0) return ""; return makeFullList(trains); } public static String makeFullList(List<TrainI> trains) { StringBuffer b = new StringBuffer(); for (TrainI train : trains) { if (b.length() > 0) b.append(" "); if (train.isObsolete()) b.append("("); b.append(train.toDisplay()); if (train.isObsolete()) b.append(")"); } return b.toString(); } /** * This method handles any consequences of new train buying (from the IPO), * such as rusting and phase changes. It must be called <b>after</b> the * train has been transferred. * */ public void checkTrainAvailability(TrainI train, Portfolio from) { trainsHaveRusted = false; phaseHasChanged = false; if (from != ipo) return; TrainTypeI boughtType, nextType; boughtType = train.getType(); if (boughtType == ((TrainTypeI) lTrainTypes.get(newTypeIndex.intValue())) && ipo.getTrainOfType(boughtType) == null) { // Last train bought, make a new type available. newTypeIndex.add(1); nextType = ((TrainTypeI) lTrainTypes.get(newTypeIndex.intValue())); if (nextType != null) { if (!nextType.isAvailable()) nextType.setAvailable(); trainAvailabilityChanged = true; ReportBuffer.add("All " + boughtType.getName() + "-trains are sold out, " + nextType.getName() + "-trains now available"); } } if (boughtType.getNumberBoughtFromIPO() == 1) { // First train of a new type bought ReportBuffer.add(LocalText.getText("FirstTrainBought", boughtType.getName())); String newPhase = boughtType.getStartedPhaseName(); if (newPhase != null) { PhaseManager.getInstance().setPhase(newPhase); phaseHasChanged = true; } TrainTypeI rustedType = boughtType.getRustedTrainType(); if (rustedType != null && !rustedType.hasRusted()) { rustedType.setRusted(train.getHolder()); // Or obsolete, // where applicable ReportBuffer.add(LocalText.getText("TrainsRusted", rustedType.getName())); trainsHaveRusted = true; trainAvailabilityChanged = true; } TrainTypeI releasedType = boughtType.getReleasedTrainType(); if (releasedType != null) { if (!releasedType.isAvailable()) releasedType.setAvailable(); ReportBuffer.add(LocalText.getText("TrainsAvailable", releasedType.getName())); trainAvailabilityChanged = true; } } } public List<TrainI> getAvailableNewTrains() { List<TrainI> availableTrains = new ArrayList<TrainI>(); TrainI train; for (TrainTypeI type : lTrainTypes) { if (type.isAvailable()) { train = ipo.getTrainOfType(type); if (train != null) { availableTrains.add(train); } } } return availableTrains; } public TrainTypeI getTypeByName(String name) { return (TrainTypeI) mTrainTypes.get(name); } public List<TrainTypeI> getTrainTypes() { return lTrainTypes; } public boolean hasAvailabilityChanged() { return trainAvailabilityChanged; } public void resetAvailabilityChanged() { trainAvailabilityChanged = false; } public boolean hasPhaseChanged() { return phaseHasChanged; } public boolean buyAtFaceValueBetweenDifferentPresidents() { return buyAtFaceValueBetweenDifferentPresidents; } } \ No newline at end of file Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** GameManager.java 4 Feb 2009 20:36:39 -0000 1.44 --- GameManager.java 4 May 2009 20:29:14 -0000 1.45 *************** *** 37,40 **** --- 37,41 ---- // Variable UI Class names + protected String gameUIManagerClassName = Defs.getDefaultClassName(Defs.ClassName.GAME_UI_MANAGER); protected String orUIManagerClassName = Defs.getDefaultClassName(Defs.ClassName.OR_UI_MANAGER); protected String gameStatusClassName = Defs.getDefaultClassName(Defs.ClassName.GAME_STATUS); *************** *** 246,249 **** --- 247,259 ---- } + // GameUIManager class + Tag gameUIMgrTag = tag.getChild("GameUIManager"); + if (gameUIMgrTag != null) { + gameUIManagerClassName = + gameUIMgrTag.getAttributeAsString("class", gameUIManagerClassName); + // Check instantiatability (not sure if this belongs here) + canClassBeInstantiated (gameUIManagerClassName); + } + // ORUIManager class Tag orMgrTag = tag.getChild("ORUIManager"); *************** *** 931,934 **** --- 941,947 ---- switch (key) { + case GAME_UI_MANAGER: + return gameUIManagerClassName; + case OR_UI_MANAGER: return orUIManagerClassName; *************** *** 980,982 **** --- 993,999 ---- } + public RoundI getInterruptedRound() { + return interruptedRound; + } + } Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Round.java 4 Feb 2009 20:36:39 -0000 1.16 --- Round.java 4 May 2009 20:29:14 -0000 1.17 *************** *** 10,16 **** --- 10,19 ---- import org.apache.log4j.Logger; + import rails.game.action.ExchangeTokens; + import rails.game.action.ExchangeableToken; import rails.game.action.PossibleAction; import rails.game.action.PossibleActions; import rails.game.move.CashMove; + import rails.game.move.MoveSet; import rails.game.special.SpecialPropertyI; import rails.util.LocalText; *************** *** 28,31 **** --- 31,36 ---- protected GameManagerI gameManager = null; protected CompanyManagerI companyManager = null; + + protected Class<? extends RoundI> roundTypeForUI = null; /** Default constructor cannot be used */ *************** *** 48,51 **** --- 53,57 ---- } + roundTypeForUI = getClass(); } *************** *** 90,93 **** --- 96,103 ---- } + public void setRoundTypeForUI(Class<? extends RoundI> roundTypeForUI) { + this.roundTypeForUI = roundTypeForUI; + } + /* * (non-Javadoc) *************** *** 114,117 **** --- 124,204 ---- } + protected boolean exchangeTokens (ExchangeTokens action) { + + String errMsg = null; + + List<ExchangeableToken> tokens = action.getTokensToExchange(); + int min = action.getMinNumberToExchange(); + int max = action.getMaxNumberToExchange(); + int exchanged = 0; + + checks: { + + for (ExchangeableToken token : tokens) { + if (token.isSelected()) exchanged++; + } + if (exchanged < min || exchanged > max) { + errMsg = LocalText.getText("WrongNumberOfTokensExchanged", + action.getCompany(), + min, max, exchanged); + break checks; + } + } + + if (errMsg != null) { + DisplayBuffer.add(LocalText.getText("CannotExchangeTokens", + action.getCompany(), + action.toString(), + errMsg)); + + return false; + } + + MoveSet.start(true); + + if (exchanged > 0) { + MapHex hex; + City city; + String cityName, hexName; + int cityNumber; + String[] ct; + PublicCompanyI comp = action.getCompany(); + + for (ExchangeableToken token : tokens) { + cityName = token.getCityName(); + ct = cityName.split("/"); + hexName = ct[0]; + try { + cityNumber = Integer.parseInt(ct[1]); + } catch (NumberFormatException e) { + cityNumber = 1; + } + hex = MapManager.getInstance().getHex(hexName); + city = hex.getCity(cityNumber); + + if (token.isSelected()) { + + // For now we'll assume that the old token(s) have already been removed. + // This is true in the 1856 CGR formation. + if (hex.layBaseToken(comp, city.getNumber())) { + /* TODO: the false return value must be impossible. */ + ReportBuffer.add(LocalText.getText("ExchangesBaseToken", + comp.getName(), + token.getOldCompanyName(), + city.getName())); + comp.layBaseToken(hex, 0); + } + } else { + ReportBuffer.add(LocalText.getText("NoBaseTokenExchange", + comp.getName(), + city.getName())); + } + } + } + + return true; + } + + /** * Default version, does nothing. Subclasses should override this method Index: Game.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Game.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Game.java 24 Jan 2009 15:10:28 -0000 1.21 --- Game.java 4 May 2009 20:29:14 -0000 1.22 *************** *** 164,170 **** @SuppressWarnings("unchecked") ! public static boolean load(String filepath) { ! boolean result = false; log.debug("Loading game from file " + filepath); --- 164,170 ---- @SuppressWarnings("unchecked") ! public static Game load(String filepath) { ! Game game = null; log.debug("Loading game from file " + filepath); *************** *** 186,190 **** List<String> playerNames = (List<String>) ois.readObject(); ! Game game = new Game(name, playerNames, selectedGameOptions); if (!game.setup()) { --- 186,190 ---- List<String> playerNames = (List<String>) ois.readObject(); ! game = new Game(name, playerNames, selectedGameOptions); if (!game.setup()) { *************** *** 203,207 **** instance.gameManager.processOnReload(executedActions); ! result = true; } catch (Exception e) { --- 203,207 ---- instance.gameManager.processOnReload(executedActions); ! return game; } catch (Exception e) { *************** *** 210,214 **** } ! return result; } --- 210,214 ---- } ! return null; } *************** *** 255,258 **** --- 255,262 ---- return instance.playerManager; } + + public GameManagerI getGameManager() { + return gameManager; + } /** Index: City.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/City.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** City.java 3 Jan 2009 18:24:53 -0000 1.7 --- City.java 4 May 2009 20:29:14 -0000 1.8 *************** *** 57,61 **** * @return Returns the holder. */ ! public Object getHolder() { return mapHex; } --- 57,61 ---- * @return Returns the holder. */ ! public MapHex getHolder() { return mapHex; } Index: StockMarket.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockMarket.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** StockMarket.java 15 Jan 2009 20:53:28 -0000 1.14 --- StockMarket.java 4 May 2009 20:29:14 -0000 1.15 *************** *** 216,219 **** --- 216,223 ---- prepareMove(company, oldsquare, newsquare); } + + public void close (PublicCompanyI company) { + prepareMove(company, company.getCurrentSpace(), null); + } protected void moveDown(PublicCompanyI company, int numberOfSpaces) { *************** *** 294,299 **** from.getName() )); return; ! } else if (from == null && to != null) {} else if (from != null ! && to != null) { ReportBuffer.add(LocalText.getText("PRICE_MOVES_LOG", company.getName(), --- 298,304 ---- from.getName() )); return; ! } else if (from == null && to != null) { ! ; ! } else if (from != null && to != null) { ReportBuffer.add(LocalText.getText("PRICE_MOVES_LOG", company.getName(), Index: MapHex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/MapHex.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** MapHex.java 15 Jan 2009 20:53:28 -0000 1.22 --- MapHex.java 4 May 2009 20:29:14 -0000 1.23 *************** *** 751,754 **** --- 751,767 ---- } } + + public List<BaseToken> getBaseTokens () { + if (cities == null || cities.isEmpty()) return null; + List<BaseToken> tokens = new ArrayList<BaseToken>(); + for (City city : cities) { + for (TokenI token : city.getTokens()) { + if (token instanceof BaseToken) { + tokens.add((BaseToken)token); + } + } + } + return tokens; + } public List<TokenI> getTokens() { Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** OperatingRound.java 4 Feb 2009 20:43:37 -0000 1.56 --- OperatingRound.java 4 May 2009 20:29:14 -0000 1.57 *************** *** 241,244 **** --- 241,248 ---- result = repayLoans((RepayLoans) selectedAction); + + } else if (selectedAction instanceof ExchangeTokens) { + + result = exchangeTokens ((ExchangeTokens)selectedAction); } else if (selectedAction instanceof NullAction) { *************** *** 1175,1178 **** --- 1179,1183 ---- if (operatingCompanyIndex >= operatingCompanyArray.length) { + operatingCompany = null; return false; } else { *************** *** 1751,1768 **** operatingCompany.addLoans(-number); ! int amount = payment = number * operatingCompany.getValuePerLoan(); ! if (amount > operatingCompany.getCash()) { ! // By now the president must have enough cash ! payment = operatingCompany.getCash(); ! remainder = amount - payment; ! if (payment > 0) { ! new CashMove (operatingCompany, null, payment); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", ! operatingCompany.getName(), ! Bank.format(payment), ! Bank.format(amount), ! number, ! Bank.format(operatingCompany.getValuePerLoan()))); ! } } if (remainder > 0) { --- 1756,1770 ---- operatingCompany.addLoans(-number); ! int amount = number * operatingCompany.getValuePerLoan(); ! payment = Math.min(amount, operatingCompany.getCash()); ! remainder = amount - payment; ! if (payment > 0) { ! new CashMove (operatingCompany, null, payment); ! ReportBuffer.add (LocalText.getText("CompanyRepaysLoans", ! operatingCompany.getName(), ! Bank.format(payment), ! Bank.format(amount), ! number, ! Bank.format(operatingCompany.getValuePerLoan()))); } if (remainder > 0) { *************** *** 1785,1789 **** return numberOfLoans * operatingCompany.getValuePerLoan(); } ! /*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/ --- 1787,1791 ---- return numberOfLoans * operatingCompany.getValuePerLoan(); } ! /*----- METHODS TO BE CALLED TO SET UP THE NEXT TURN -----*/ *************** *** 2130,2134 **** for (PublicCompanyI comp : list) { possibleActions.add(new DiscardTrain(comp, ! comp.getPortfolio().getUniqueTrains())); // We handle one company at at time. // We come back here until all excess trains have been --- 2132,2136 ---- for (PublicCompanyI comp : list) { possibleActions.add(new DiscardTrain(comp, ! comp.getPortfolio().getUniqueTrains(), true)); // We handle one company at at time. // We come back here until all excess trains have been Index: StockRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/StockRound.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** StockRound.java 15 Jan 2009 20:53:28 -0000 1.35 --- StockRound.java 4 May 2009 20:29:14 -0000 1.36 *************** *** 74,84 **** sequenceRule = gameManager.getStockRoundSequenceRule(); ! ! } public void start() { ! ReportBuffer.add("\n" + LocalText.getText("StartStockRound") ! + getStockRoundNumber()); setCurrentPlayerIndex(gameManager.getPriorityPlayer().getIndex()); --- 74,84 ---- sequenceRule = gameManager.getStockRoundSequenceRule(); ! ! } public void start() { ! ReportBuffer.add("\n" + LocalText.getText("StartStockRound", ! + getStockRoundNumber())); setCurrentPlayerIndex(gameManager.getPriorityPlayer().getIndex()); Index: TrainType.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TrainType.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** TrainType.java 3 Jan 2009 18:24:53 -0000 1.20 --- TrainType.java 4 May 2009 20:29:14 -0000 1.21 *************** *** 41,44 **** --- 41,46 ---- protected boolean obsoleting = false; + + protected boolean permanent = true; private boolean real; // Only to determine if top-level attributes must be *************** *** 248,258 **** /** - * @return Returns the amount. - */ - /* - * public int getAmount() { return amount; } - */ - - /** * @return Returns the cityScoreFactor. */ --- 250,253 ---- *************** *** 385,388 **** --- 380,391 ---- } + public boolean isPermanent() { + return permanent; + } + + public void setPermanent(boolean permanent) { + this.permanent = permanent; + } + /** * @return Returns the available. --- NEW FILE: SwitchableUIRound.java --- package rails.game; /** Abstract class for rounds that cannot be subclassed for one of the * other Round subclasses because UI is switchable: in some steps, * an SR-type UI and in other steps an OR-type UI should be displayed. * @author Erik Vos * */ public abstract class SwitchableUIRound extends Round { public SwitchableUIRound (GameManagerI gameManager) { super (gameManager); setRoundTypeForUI(null); } } Index: GameManagerI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManagerI.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GameManagerI.java 24 Jan 2009 15:10:28 -0000 1.2 --- GameManagerI.java 4 May 2009 20:29:14 -0000 1.3 *************** *** 157,160 **** public abstract Object getCommonParameter(Defs.Parm key); ! } \ No newline at end of file --- 157,161 ---- public abstract Object getCommonParameter(Defs.Parm key); ! ! public RoundI getInterruptedRound(); } \ No newline at end of file |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:27
|
Update of /cvsroot/rails/18xx/rails/test In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/test Modified Files: GameTest.java Log Message: 1856 CGR formation round Index: GameTest.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/test/GameTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GameTest.java 4 Jun 2008 19:00:41 -0000 1.3 --- GameTest.java 4 May 2009 20:29:14 -0000 1.4 *************** *** 32,36 **** /* Start the rails.game selector, which will do all the rest. */ ! new GameUIManager(); } } --- 32,37 ---- /* Start the rails.game selector, which will do all the rest. */ ! //new GameUIManager(); ! new GameSetupWindow(); } } |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:26
|
Update of /cvsroot/rails/18xx/rails/ui/swing/elements In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing/elements Modified Files: CheckBoxDialog.java Log Message: 1856 CGR formation round Index: CheckBoxDialog.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/elements/CheckBoxDialog.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CheckBoxDialog.java 20 Nov 2008 21:46:00 -0000 1.1 --- CheckBoxDialog.java 4 May 2009 20:29:14 -0000 1.2 *************** *** 51,55 **** initialize(); pack(); ! // Center on owner int x = --- 51,55 ---- initialize(); pack(); ! this.setVisible(true); // Center on owner int x = *************** *** 61,65 **** setLocation(x, y); ! this.setVisible(true); } --- 61,65 ---- setLocation(x, y); ! } |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:26
|
Update of /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing/gamespecific/_1856 Modified Files: StatusWindow_1856.java Log Message: 1856 CGR formation round Index: StatusWindow_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/gamespecific/_1856/StatusWindow_1856.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StatusWindow_1856.java 4 Feb 2009 20:36:40 -0000 1.1 --- StatusWindow_1856.java 4 May 2009 20:29:15 -0000 1.2 *************** *** 7,10 **** --- 7,12 ---- import rails.game.*; + import rails.game.action.DiscardTrain; + import rails.game.action.ExchangeTokens; import rails.game.action.RepayLoans; import rails.game.specific._1856.CGRFormationRound; *************** *** 21,35 **** public void updateStatus() { RoundI currentRound = gameUIManager.getCurrentRound(); ! if (!(currentRound instanceof OperatingRound)) { ! return; ! } else if (!(currentRound instanceof CGRFormationRound)) { super.updateStatus(); } else if (possibleActions.contains(RepayLoans.class)) { ! RepayLoans action = possibleActions.getType(RepayLoans.class).get(0); ! repayLoans (action); } } ! // Code copied from ORUIManager protected void repayLoans (RepayLoans action) { --- 23,72 ---- public void updateStatus() { RoundI currentRound = gameUIManager.getCurrentRound(); ! //if (!(currentRound instanceof OperatingRound)) { ! if (!(currentRound instanceof CGRFormationRound)) { super.updateStatus(); } else if (possibleActions.contains(RepayLoans.class)) { ! //RepayLoans action = possibleActions.getType(RepayLoans.class).get(0); ! //repayLoans (action); ! immediateAction = possibleActions.getType(RepayLoans.class).get(0); ! } else if (possibleActions.contains(DiscardTrain.class)) { ! immediateAction = possibleActions.getType(DiscardTrain.class).get(0); ! } else if (possibleActions.contains(ExchangeTokens.class)) { ! immediateAction = possibleActions.getType(ExchangeTokens.class).get(0); } } ! @Override ! public boolean processImmediateAction() { ! ! if (immediateAction == null) { ! return false; ! } else if (immediateAction instanceof RepayLoans) { ! // Make a local copy and discard the original, ! // so that it's not going to loop. ! RepayLoans nextAction = (RepayLoans) immediateAction; ! immediateAction = null; ! repayLoans (nextAction); ! return true; ! } else if (immediateAction instanceof DiscardTrain) { ! // Make a local copy and discard the original, ! // so that it's not going to loop. ! DiscardTrain nextAction = (DiscardTrain) immediateAction; ! immediateAction = null; ! gameUIManager.discardTrains (nextAction); ! return true; ! } else if (immediateAction instanceof ExchangeTokens) { ! // Make a local copy and discard the original, ! // so that it's not going to loop. ! ExchangeTokens nextAction = (ExchangeTokens) immediateAction; ! immediateAction = null; ! gameUIManager.exchangeTokens (nextAction); ! return true; ! } else { ! return super.processImmediateAction(); ! } ! } ! ! // Code partly copied from ORUIManager protected void repayLoans (RepayLoans action) { *************** *** 55,59 **** message[displayBufSize] = LocalText.getText("SelectLoansToRepay", action.getCompanyName()); ! Object choice = JOptionPane.showInputDialog(this, message, --- 92,96 ---- message[displayBufSize] = LocalText.getText("SelectLoansToRepay", action.getCompanyName()); ! Object choice = JOptionPane.showInputDialog(this, message, |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:23
|
Update of /cvsroot/rails/18xx/rails/common In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/common Modified Files: Defs.java Log Message: 1856 CGR formation round Index: Defs.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/common/Defs.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Defs.java 4 Feb 2009 20:36:40 -0000 1.3 --- Defs.java 4 May 2009 20:29:15 -0000 1.4 *************** *** 7,10 **** --- 7,11 ---- /* Identifiers and default names for configurable UI classes */ public enum ClassName { + GAME_UI_MANAGER, OR_UI_MANAGER, STATUS_WINDOW, *************** *** 17,20 **** --- 18,23 ---- static { + defaultClasses.put (ClassName.GAME_UI_MANAGER, + "rails.ui.swing.GameUIManager"); defaultClasses.put (ClassName.OR_UI_MANAGER, "rails.ui.swing.ORUIManager"); |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:22
|
Update of /cvsroot/rails/18xx/data/1856 In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/data/1856 Modified Files: CompanyManager.xml Game.xml Log Message: 1856 CGR formation round Index: CompanyManager.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1856/CompanyManager.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** CompanyManager.xml 11 Jan 2009 17:24:46 -0000 1.24 --- CompanyManager.xml 4 May 2009 20:29:15 -0000 1.25 *************** *** 100,103 **** --- 100,104 ---- <!-- Initially 20 shares are configured--> <ShareUnit percentage="5"/> + <Trains number="0,0,0,3"/> <Certificate type="President" shares="2"/> <Certificate shares="1" number="18"/> Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1856/Game.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Game.xml 4 Feb 2009 20:36:39 -0000 1.21 --- Game.xml 4 May 2009 20:29:15 -0000 1.22 *************** *** 6,9 **** --- 6,10 ---- sequence="SellBuyOrBuySell"/> <OperatingRound class="rails.game.specific._1856.OperatingRound_1856"/> + <GameUIManager class="rails.game.specific._1856.GameUIManager_1856"/> <StatusWindow class="rails.ui.swing.gamespecific._1856.StatusWindow_1856"/> <PlayerShareLimit percentage="60"/> |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:22
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing/hexmap Modified Files: EWHexMap.java HexMap.java NSHexMap.java Log Message: 1856 CGR formation round Index: NSHexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/NSHexMap.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NSHexMap.java 4 Jun 2008 19:00:38 -0000 1.6 --- NSHexMap.java 4 May 2009 20:29:15 -0000 1.7 *************** *** 43,46 **** --- 43,47 ---- hex.setHexModel(mh); hex.originalTileId = hex.currentTileId; + hexesByName.put(mh.getName(), hex); h[i][j] = hex; Index: EWHexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/EWHexMap.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** EWHexMap.java 4 Jun 2008 19:00:38 -0000 1.7 --- EWHexMap.java 4 May 2009 20:29:15 -0000 1.8 *************** *** 40,43 **** --- 40,44 ---- hex.setHexModel(mh); hex.originalTileId = hex.currentTileId; + hexesByName.put(mh.getName(), hex); h[i][j] = hex; Index: HexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/HexMap.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** HexMap.java 4 Jun 2008 19:00:38 -0000 1.14 --- HexMap.java 4 May 2009 20:29:15 -0000 1.15 *************** *** 37,41 **** protected GUIHex[][] h; ! MapHex[][] hexArray; protected static ArrayList<GUIHex> hexes; protected int scale = 2 * Scale.get(); --- 37,42 ---- protected GUIHex[][] h; ! protected MapHex[][] hexArray; ! protected Map<String, GUIHex> hexesByName = new HashMap<String, GUIHex>(); protected static ArrayList<GUIHex> hexes; protected int scale = 2 * Scale.get(); *************** *** 94,97 **** --- 95,102 ---- return null; } + + public GUIHex getHexByName (String hexName) { + return hexesByName.get (hexName); + } public void paintComponent(Graphics g) { |
|
From: Erik V. <ev...@us...> - 2009-05-04 20:29:22
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29969/rails/ui/swing Modified Files: ORUIManager.java GameSetupWindow.java GameUIManager.java Log Message: 1856 CGR formation round Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ORUIManager.java 21 Jan 2009 20:18:23 -0000 1.26 --- ORUIManager.java 4 May 2009 20:29:15 -0000 1.27 *************** *** 897,929 **** if (dt == null) break; ! PublicCompanyI c = dt.getCompany(); ! String playerName = dt.getPlayerName(); ! List<TrainI> trains = dt.getOwnedTrains(); ! List<String> trainOptions = ! new ArrayList<String>(trains.size()); ! String[] options = new String[trains.size()]; ! ! for (int i = 0; i < options.length; i++) { ! options[i] = ! LocalText.getText("N_Train", ! trains.get(i).getName()); ! trainOptions.add(options[i]); ! } ! String discardedTrainName = ! (String) JOptionPane.showInputDialog(orWindow, ! LocalText.getText("HAS_TOO_MANY_TRAINS", ! playerName, ! c.getName() ), ! LocalText.getText("WhichTrainToDiscard"), ! JOptionPane.QUESTION_MESSAGE, null, ! options, options[0]); ! if (discardedTrainName != null) { ! TrainI discardedTrain = ! trains.get(trainOptions.indexOf(discardedTrainName)); ! ! dt.setDiscardedTrain(discardedTrain); ! ! orWindow.process(dt); ! } } } --- 897,901 ---- if (dt == null) break; ! gameUIManager.discardTrains(dt); } } Index: GameSetupWindow.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameSetupWindow.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GameSetupWindow.java 4 Jun 2008 19:00:32 -0000 1.12 --- GameSetupWindow.java 4 May 2009 20:29:15 -0000 1.13 *************** *** 8,15 **** --- 8,17 ---- import org.apache.log4j.Logger; + import rails.common.Defs; import rails.game.*; import rails.ui.swing.GameUIManager; import rails.util.*; + import java.io.File; import java.util.*; import java.util.List; *************** *** 37,40 **** --- 39,43 ---- List<GameOption> availableOptions = new ArrayList<GameOption>(); String gameName; + Game game; // Used by the player selection combo box. *************** *** 46,53 **** Logger.getLogger(GameSetupWindow.class.getPackage().getName()); ! public GameSetupWindow(GameUIManager gameUIManager) { super(); ! this.gameUIManager = gameUIManager; initialize(); --- 49,56 ---- Logger.getLogger(GameSetupWindow.class.getPackage().getName()); ! public GameSetupWindow(/*GameUIManager gameUIManager*/) { super(); ! //this.gameUIManager = gameUIManager; initialize(); *************** *** 193,198 **** toggleOptions(); this.pack(); ! } else if (arg0.getSource().equals(loadButton) ! && gameUIManager.loadGame()) { setVisible(false); } else if (arg0.getSource().equals(infoButton)) { --- 196,223 ---- toggleOptions(); this.pack(); ! } else if (arg0.getSource().equals(loadButton)) { ! String saveDirectory = Config.get("save.directory"); ! JFileChooser jfc = new JFileChooser(); ! //if (providedName != null) { ! // jfc.setSelectedFile(new File(providedName)); ! //} else { ! jfc.setCurrentDirectory(new File(saveDirectory)); ! //} ! ! if (jfc.showOpenDialog(getContentPane()) == JFileChooser.APPROVE_OPTION) { ! File selectedFile = jfc.getSelectedFile(); ! String filepath = selectedFile.getPath(); ! saveDirectory = selectedFile.getParent(); ! if ((game = Game.load(filepath)) == null) { ! JOptionPane.showMessageDialog(this, ! DisplayBuffer.get(), "", JOptionPane.ERROR_MESSAGE); ! return; ! } ! DisplayBuffer.clear(); ! ! } ! ! startGameUIManager(game); ! gameUIManager.startLoadedGame(); setVisible(false); } else if (arg0.getSource().equals(infoButton)) { *************** *** 344,348 **** } ! Game game = new Game(gameName, playerNames, selectedOptions); if (!game.setup()) { JOptionPane.showMessageDialog(this, DisplayBuffer.get(), "", --- 369,373 ---- } ! game = new Game(gameName, playerNames, selectedOptions); if (!game.setup()) { JOptionPane.showMessageDialog(this, DisplayBuffer.get(), "", *************** *** 355,358 **** --- 380,384 ---- } else { game.start(); + startGameUIManager (game); gameUIManager.gameUIInit(); } *************** *** 361,364 **** --- 387,403 ---- // XXX: object rather than just making it invisible } + + private void startGameUIManager(Game game) { + String gameUIManagerClassName = game.getGameManager().getClassName(Defs.ClassName.GAME_UI_MANAGER); + try { + Class<? extends GameUIManager> gameUIManagerClass = + Class.forName(gameUIManagerClassName).asSubclass(GameUIManager.class); + gameUIManager = gameUIManagerClass.newInstance(); + gameUIManager.init(this); + } catch (Exception e) { + log.fatal("Cannot instantiate class " + gameUIManagerClassName, e); + System.exit(1); + } + } private void fillPlayersPane() { Index: GameUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/GameUIManager.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** GameUIManager.java 4 Feb 2009 20:36:40 -0000 1.16 --- GameUIManager.java 4 May 2009 20:29:15 -0000 1.17 *************** *** 3,8 **** import java.io.File; import java.text.SimpleDateFormat; ! import java.util.Date; ! import java.util.List; import javax.swing.JFileChooser; --- 3,7 ---- import java.io.File; import java.text.SimpleDateFormat; ! import java.util.*; import javax.swing.JFileChooser; *************** *** 13,20 **** import rails.common.Defs; import rails.game.*; ! import rails.game.action.GameAction; ! import rails.game.action.PossibleAction; ! import rails.util.Config; ! import rails.util.Util; /** --- 12,18 ---- import rails.common.Defs; import rails.game.*; ! import rails.game.action.*; ! import rails.ui.swing.elements.CheckBoxDialog; ! import rails.util.*; /** *************** *** 55,59 **** --- 53,63 ---- public GameUIManager() { + + } + + public void init (GameSetupWindow gameSetupWindow) { + instance = this; + this.gameSetupWindow = gameSetupWindow; saveDirectory = Config.get("save.directory"); *************** *** 71,75 **** } ! gameSetupWindow = new GameSetupWindow(this); } --- 75,79 ---- } ! //gameSetupWindow = new GameSetupWindow(this); } *************** *** 97,100 **** --- 101,110 ---- } + + public void startLoadedGame() { + gameUIInit(); + processOnServer(null); + statusWindow.setGameActions(); + } public boolean processOnServer(PossibleAction action) { *************** *** 102,106 **** // In some cases an Undo requires a different follow-up lastAction = action; ! log.debug("==Passing to server: " + action); --- 112,117 ---- // In some cases an Undo requires a different follow-up lastAction = action; ! if (action != null) action.setActed(); ! log.debug("==Passing to server: " + action); *************** *** 109,113 **** --- 120,128 ---- action.setPlayerName(player.getName()); } + + // Process the action on the server boolean result = gameManager.process(action); + + // Follow-up the result log.debug("==Result from server: " + result); if (DisplayBuffer.getAutoDisplay()) activeWindow.displayServerMessage(); *************** *** 149,152 **** --- 164,171 ---- // Process consequences of a round type change to the UI + Class<? extends RoundI> previousRoundType + = previousRound == null ? null : previousRound.getClass(); + Class<? extends RoundI> currentRoundType + = currentRound.getClass(); Class<? extends RoundI> previousRoundUItype = previousRound == null ? null : previousRound.getRoundTypeForUI(); *************** *** 154,184 **** = currentRound.getRoundTypeForUI(); if (previousRound == null || !previousRound.equals(currentRound)) { if (previousRound != null) { ! // Finish the previous round UI aspects ! //if (previousRound instanceof StockRound) { ! if (StockRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Stock Round UI"); statusWindow.finishRound(); ! //} else if (previousRound instanceof StartRound) { ! } else if (StartRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Start Round UI"); if (startRoundWindow != null) { startRoundWindow.close(); startRoundWindow = null; } ! //} else if (previousRound instanceof OperatingRound) { ! } else if (OperatingRound.class.isAssignableFrom(previousRoundUItype)) { ! log.debug("Finishing Operating Round UI"); orUIManager.finish(); } } ! // Start the new round UI aspects ! //if (currentRound instanceof StartRound) { ! if (StartRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Start Round UI"); startRound = (StartRound) currentRound; if (startRoundWindow == null) { --- 173,210 ---- = currentRound.getRoundTypeForUI(); + /* Distinguish actual round type from visible round type. + * Actual round type is the class of the active Round subclass. + * Visible round type is the class of one of the three 'basic' + * round types: Start, Stock or Operating. + * The latter type determines what UI windows will become visible. + */ + + /* Process actual round type changes */ if (previousRound == null || !previousRound.equals(currentRound)) { + /* Finish previous round UI processing */ if (previousRound != null) { ! ! if (StockRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Stock Round"); statusWindow.finishRound(); ! } else if (StartRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Start Round"); if (startRoundWindow != null) { startRoundWindow.close(); startRoundWindow = null; } ! } else if (OperatingRound.class.isAssignableFrom(previousRoundType)) { ! log.debug("UI leaving Operating Round"); orUIManager.finish(); + } else if (SwitchableUIRound.class.isAssignableFrom(previousRoundType) ) { + log.debug("UI leaving switchable round type"); } } ! // Start the new round UI processing ! if (StartRound.class.isAssignableFrom(currentRoundType)) { ! log.debug("UI entering Start Round"); startRound = (StartRound) currentRound; if (startRoundWindow == null) { *************** *** 186,204 **** } stockChart.setVisible(false); - //} else if (currentRound instanceof StockRound) { } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Stock Round UI"); stockChart.setVisible(true); statusWindow.setVisible(true); - //} else if (currentRound instanceof OperatingRound) { } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Operating Round UI"); stockChart.setVisible(false); ! orUIManager.initOR((OperatingRound) currentRound); } } --- 212,263 ---- } + } else if (StockRound.class.isAssignableFrom(currentRoundType)) { + + log.debug("UI entering Stock Round"); + + } else if (OperatingRound.class.isAssignableFrom(currentRoundType)) { + + log.debug("UI entering Operating Round"); + orUIManager.initOR((OperatingRound) currentRound); + } else if (SwitchableUIRound.class.isAssignableFrom(currentRoundType) ) { + log.debug("UI entering switchable round type"); + } + } + + /* Process visible round type changes */ + if (previousRoundUItype == null || !previousRoundUItype.equals(currentRoundUItype)) { + + if (previousRoundUItype != null) { + // Finish the previous round UI aspects + if (StockRound.class.isAssignableFrom(previousRoundUItype)) { + log.debug("Leaving Stock Round UI type"); + } else if (StartRound.class.isAssignableFrom(previousRoundUItype)) { + log.debug("Leaving Start Round UI type"); + } else if (OperatingRound.class.isAssignableFrom(previousRoundUItype)) { + log.debug("Leaving Operating Round UI type"); + orWindow.setVisible(false); + } + } + + // Start the new round UI aspects + if (StartRound.class.isAssignableFrom(currentRoundUItype)) { + + log.debug("Entering Start Round UI type"); + activeWindow = startRoundWindow; stockChart.setVisible(false); } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Stock Round UI type"); ! activeWindow = statusWindow; stockChart.setVisible(true); statusWindow.setVisible(true); } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { ! log.debug("Entering Operating Round UI type "); ! activeWindow = orWindow; stockChart.setVisible(false); ! orWindow.setVisible(true); } } *************** *** 207,230 **** previousRound = currentRound; ! // Update the current round window ! //if (currentRound instanceof StartRound) { if (StartRound.class.isAssignableFrom(currentRoundUItype)) { - activeWindow = startRoundWindow; startRoundWindow.updateStatus(); startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); - //} else if (currentRound instanceof StockRound) { } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { - activeWindow = statusWindow; statusWindow.updateStatus(); - //} else if (currentRound instanceof OperatingRound) { } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { - activeWindow = orUIManager.getORWindow(); orUIManager.updateStatus(); } } --- 266,411 ---- previousRound = currentRound; ! // Update the currently visible round window ! // "Switchable" rounds will be handled from subclasses of this class. if (StartRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating Start round window"); startRoundWindow.updateStatus(); startRoundWindow.setSRPlayerTurn(startRound.getCurrentPlayerIndex()); } else if (StockRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating Stock (status) round window"); statusWindow.updateStatus(); } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating Operating round window"); orUIManager.updateStatus(); + } else { + // Handle special rounds that do not fall in a standard category + // The round must indicate which main window to raise + if (StockRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating switched Stock (status) round window"); + activeWindow = statusWindow; + } else if (OperatingRound.class.isAssignableFrom(currentRoundUItype)) { + log.debug("Updating switched Operating round window"); + activeWindow = orWindow; + } + updateStatus(activeWindow); + } + } + + /** Stub, to be overridden in subclasses for special round types */ + protected void updateStatus(ActionPerformer activeWindow) { + + } + + public void discardTrains (DiscardTrain dt) { + + PublicCompanyI c = dt.getCompany(); + String playerName = dt.getPlayerName(); + List<TrainI> trains = dt.getOwnedTrains(); + int size = trains.size() + (dt.isForced() ? 0 : 1); + List<String> trainOptions = + new ArrayList<String>(size); + String[] options = new String[size]; + String prompt = null; + + int j = 0; + if (!dt.isForced()) { + trainOptions.add( + options[j++] = LocalText.getText("None") + ); + prompt = LocalText.getText("MayDiscardTrain", + c.getName()); + } + int offset = j; + for (int i = 0; i < trains.size(); i++) { + trainOptions.add( + options[j++] = LocalText.getText("N_Train", + trains.get(i).getName()) + ); + } + if (prompt == null) prompt = LocalText.getText( + "HAS_TOO_MANY_TRAINS", + playerName, + c.getName() ); + String discardedTrainName = + (String) JOptionPane.showInputDialog(orWindow, + prompt, + LocalText.getText("WhichTrainToDiscard"), + JOptionPane.QUESTION_MESSAGE, null, + options, options[0]); + if (discardedTrainName != null) { + int index = trainOptions.indexOf(discardedTrainName); + if (index >= offset) { + TrainI discardedTrain = + trains.get(trainOptions.indexOf(discardedTrainName)-offset); + dt.setDiscardedTrain(discardedTrain); + } + + orWindow.process(dt); + } + } + + public void exchangeTokens (ExchangeTokens action) { + + int index, cityNumber; + String prompt, cityName, hexName, oldCompName; + String[] ct; + MapHex hex; + List<String> options = new ArrayList<String>(); + City city; + List<ExchangeableToken> oldTokens = action.getTokensToExchange(); + + for (ExchangeableToken t : oldTokens) { + cityName = t.getCityName(); + ct = cityName.split("/"); + hexName = ct[0]; + try { + cityNumber = Integer.parseInt(ct[1]); + } catch (NumberFormatException e) { + cityNumber = 1; + } + hex = orWindow.getMapPanel().getMap().getHexByName (hexName).getHexModel(); + city = hex.getCity(cityNumber); + oldCompName = t.getOldCompanyName(); + options.add(LocalText.getText("ExchangeableToken", + oldCompName, + hexName, + hex.getCityName(), + cityNumber, + city.getTrackEdges())); + } + + + int minNumber = action.getMinNumberToExchange(); + int maxNumber = action.getMaxNumberToExchange(); + if (minNumber == maxNumber) { + prompt = LocalText.getText("ExchangeTokensPrompt1", + minNumber, + action.getCompanyName()); + } else { + prompt = LocalText.getText("ExchangeTokensPrompt2", + minNumber, maxNumber, + action.getCompanyName()); + } + + if (options.size() > 0) { + orWindow.setVisible(true); + boolean[] exchanged = + new CheckBoxDialog(orWindow.getORPanel(), + LocalText.getText("ExchangeTokens"), + prompt, + options.toArray(new String[0])) + .getSelectedOptions(); + for (index=0; index < options.size(); index++) { + if (exchanged[index]) { + oldTokens.get(index).setSelected(true); + } + } + orWindow.process(action); } } *************** *** 257,260 **** --- 438,442 ---- } + /* public boolean loadGame() { *************** *** 285,288 **** --- 467,471 ---- return true; } + */ public PossibleAction getLastAction() { |