From: Erik V. <ev...@us...> - 2010-01-24 16:21:38
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv7185/rails/game/specific/_18EU Modified Files: OperatingRound_18EU.java Log Message: Fixes to 18EU Pullmann problems Index: OperatingRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OperatingRound_18EU.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** OperatingRound_18EU.java 19 Jan 2010 19:52:30 -0000 1.12 --- OperatingRound_18EU.java 24 Jan 2010 16:21:28 -0000 1.13 *************** *** 7,10 **** --- 7,11 ---- import rails.game.action.BuyTrain; import rails.game.state.BooleanState; + import rails.util.LocalText; /** *************** *** 45,73 **** int cost; List<TrainI> trains; ! // TrainI train; boolean hasTrains = operatingCompany.getPortfolio().getNumberOfTrains() > 0; ! boolean atTrainLimit = ! operatingCompany.getNumberOfTrains() >= operatingCompany.getCurrentTrainLimit(); ! boolean canBuyTrainNow = isBelowTrainLimit(); boolean presidentMayHelp = operatingCompany.mustOwnATrain(); TrainI cheapestTrain = null; int costOfCheapestTrain = 0; ! // Check if the company already has a Pullmann ! TrainI ownedPTrain = null; ! if (hasTrains) { ! ownedPTrain = operatingCompany.getPortfolio().getTrainOfType(pullmannType); } ! ! // Postpone train limit checking, because an exchange might be possible ! ! /* New trains */ trains = trainMgr.getAvailableNewTrains(); for (TrainI train : trains) { cost = train.getCost(); if (cost <= cash) { ! if (canBuyTrainNow) ! possibleActions.add(new BuyTrain(train, ipo, cost)); } else if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) { cheapestTrain = train; --- 46,79 ---- int cost; List<TrainI> trains; ! BuyTrain bt; ! boolean hasTrains = operatingCompany.getPortfolio().getNumberOfTrains() > 0; ! boolean canBuyTrainNow = canBuyTrainNow(); ! ! if (!canBuyTrainNow) return; ! boolean presidentMayHelp = operatingCompany.mustOwnATrain(); TrainI cheapestTrain = null; int costOfCheapestTrain = 0; ! String extraMessage = null; ! boolean mustExchangePullmann = !isBelowTrainLimit() ! && hasPullmannAtStart.booleanValue() ! && !possibleActions.contains(BuyTrain.class); ! if (mustExchangePullmann) { ! extraMessage = LocalText.getText("AutodiscardTrain", ! pullmannType.getName()); } ! /* New trains */ trains = trainMgr.getAvailableNewTrains(); for (TrainI train : trains) { cost = train.getCost(); if (cost <= cash) { ! if (canBuyTrainNow) { ! bt = new BuyTrain(train, ipo, cost); ! if (mustExchangePullmann) bt.setExtraMessage(extraMessage); ! possibleActions.add(bt); ! } } else if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) { cheapestTrain = train; *************** *** 75,91 **** } - // At train limit, exchange of a Pullmann is allowed - if (atTrainLimit && ownedPTrain != null) { - BuyTrain action = new BuyTrain(train, ipo, cost); - List<TrainI> pTrains = new ArrayList<TrainI>(); - pTrains.add(ownedPTrain); - action.setTrainsForExchange(pTrains); - action.setForcedExchange(true); - possibleActions.add(action); - } - if (!canBuyTrainNow) return; - } - if (!canBuyTrainNow) return; /* Used trains */ --- 81,85 ---- *************** *** 94,104 **** // May not buy Pullmann if one is already owned, // or if no train is owned at all ! if ((ownedPTrain != null || !hasTrains) ! && train.getType().getName().equals("P")) { continue; } cost = train.getCost(); if (cost <= cash) { ! possibleActions.add(new BuyTrain(train, pool, cost)); } else if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) { cheapestTrain = train; --- 88,101 ---- // May not buy Pullmann if one is already owned, // or if no train is owned at all ! if (train.getType().getName().equals("P") ! &&(operatingCompany.getPortfolio().getTrainOfType(pullmannType) != null ! || !hasTrains)) { continue; } cost = train.getCost(); if (cost <= cash) { ! bt = new BuyTrain(train, pool, cost); ! if (mustExchangePullmann) bt.setExtraMessage(extraMessage); ! possibleActions.add(bt); } else if (costOfCheapestTrain == 0 || cost < costOfCheapestTrain) { cheapestTrain = train; *************** *** 107,123 **** } if (!hasTrains && presidentMayHelp ! && possibleActions.getType(BuyTrain.class).isEmpty() ! && cheapestTrain != null) { ! possibleActions.add(new BuyTrain(cheapestTrain, ! cheapestTrain.getHolder(), costOfCheapestTrain).setPresidentMustAddCash(costOfCheapestTrain ! - cash)); } - if (!canBuyTrainNow) return; - /* Other company trains, sorted by president (current player first) */ if (getCurrentPhase().isTrainTradingAllowed()) { PublicCompanyI c; - BuyTrain bt; Player p; Portfolio pf; --- 104,118 ---- } if (!hasTrains && presidentMayHelp ! && possibleActions.getType(BuyTrain.class).isEmpty() ! && cheapestTrain != null) { ! bt = new BuyTrain(cheapestTrain, cheapestTrain.getHolder(), costOfCheapestTrain); ! bt.setPresidentMustAddCash(costOfCheapestTrain - cash); ! if (mustExchangePullmann) bt.setExtraMessage(extraMessage); ! possibleActions.add(bt); } /* Other company trains, sorted by president (current player first) */ if (getCurrentPhase().isTrainTradingAllowed()) { PublicCompanyI c; Player p; Portfolio pf; *************** *** 152,155 **** --- 147,151 ---- if (train.getType().getName().equals("P")) continue; bt = new BuyTrain(train, pf, 0); + if (mustExchangePullmann) bt.setExtraMessage(extraMessage); possibleActions.add(bt); } *************** *** 157,167 **** } } } /** In 18EU, a company can (effectively) exchange a Pullmann */ @Override ! protected boolean isBelowTrainLimit() { ! return super.isBelowTrainLimit() ! || operatingCompany.getPortfolio().getTrainOfType(pullmannType) != null && hasPullmannAtStart.booleanValue(); } --- 153,163 ---- } } + } /** In 18EU, a company can (effectively) exchange a Pullmann */ @Override ! protected boolean canBuyTrainNow() { ! return super.canBuyTrainNow() || hasPullmann () && hasPullmannAtStart.booleanValue(); } *************** *** 169,174 **** --- 165,185 ---- @Override public boolean buyTrain(BuyTrain action) { + + boolean mustDiscardPullmann = !super.isBelowTrainLimit() && hasPullmann (); + boolean result = super.buyTrain(action); + // If we are at train limit and have a Pullmann, discard it + if (mustDiscardPullmann) { + TrainI pullmann = operatingCompany.getPortfolio().getTrainOfType(pullmannType); + if (pullmann != null) { // must be non-null + pullmann.moveTo(scrapHeap); + ReportBuffer.add(LocalText.getText("CompanyDiscardsTrain", + operatingCompany.getName(), + pullmann.getName() )); + + } + } + // Check if we have just started Phase 5 and // if we still have at least one Minor operating. *************** *** 223,226 **** --- 234,241 ---- return !excessTrainCompanies.isEmpty(); } + + private boolean hasPullmann () { + return operatingCompany.getPortfolio().getTrainOfType(pullmannType) != null; + } } |