|
From: <ev...@us...> - 2010-10-07 19:41:17
|
Revision: 1434
http://rails.svn.sourceforge.net/rails/?rev=1434&view=rev
Author: evos
Date: 2010-10-07 19:41:11 +0000 (Thu, 07 Oct 2010)
Log Message:
-----------
Display "No train" in stead of "Withhold" if company has had no revenue because of no trains.
Modified Paths:
--------------
trunk/18xx/LocalisedText.properties
trunk/18xx/rails/game/OperatingRound.java
trunk/18xx/rails/game/action/SetDividend.java
Modified: trunk/18xx/LocalisedText.properties
===================================================================
--- trunk/18xx/LocalisedText.properties 2010-09-24 21:55:37 UTC (rev 1433)
+++ trunk/18xx/LocalisedText.properties 2010-10-07 19:41:11 UTC (rev 1434)
@@ -410,6 +410,7 @@
NoTilesXML=No Tiles XML file specified
NoToken=No Token
NoTokenPossible=No token can be placed in hex {0}
+NO_TRAIN=No train
NoTrainSpecified=No train specified
NonNumericUpgrade=Tile {0}: non-numeric upgrade {1}
NormalToken= You can lay a connected token on {0}.
Modified: trunk/18xx/rails/game/OperatingRound.java
===================================================================
--- trunk/18xx/rails/game/OperatingRound.java 2010-09-24 21:55:37 UTC (rev 1433)
+++ trunk/18xx/rails/game/OperatingRound.java 2010-10-07 19:41:11 UTC (rev 1434)
@@ -1217,7 +1217,7 @@
if (!operatingCompany.get().canRunTrains()) {
// No trains, then the revenue is zero.
executeSetRevenueAndDividend (
- new SetDividend (0, false, new int[] {SetDividend.WITHHOLD}));
+ new SetDividend (0, false, new int[] {SetDividend.NO_TRAIN}));
// TODO: This probably does not handle share selling correctly
continue;
}
@@ -2499,160 +2499,160 @@
boolean hasTrains =
operatingCompany.get().getPortfolio().getNumberOfTrains() > 0;
- boolean canBuyTrainNow = canBuyTrainNow();
- boolean presidentMayHelp = !hasTrains && operatingCompany.get().mustOwnATrain();
- TrainI cheapestTrain = null;
- int costOfCheapestTrain = 0;
+ boolean canBuyTrainNow = canBuyTrainNow();
+ boolean presidentMayHelp = !hasTrains && operatingCompany.get().mustOwnATrain();
+ TrainI cheapestTrain = null;
+ int costOfCheapestTrain = 0;
- // First check if any more trains may be bought from the Bank
- // Postpone train limit checking, because an exchange might be possible
- if (getCurrentPhase().canBuyMoreTrainsPerTurn()
- || trainsBoughtThisTurn.isEmpty()) {
- boolean mayBuyMoreOfEachType =
- getCurrentPhase().canBuyMoreTrainsPerTypePerTurn();
+ // First check if any more trains may be bought from the Bank
+ // Postpone train limit checking, because an exchange might be possible
+ if (getCurrentPhase().canBuyMoreTrainsPerTurn()
+ || trainsBoughtThisTurn.isEmpty()) {
+ boolean mayBuyMoreOfEachType =
+ getCurrentPhase().canBuyMoreTrainsPerTypePerTurn();
- /* New trains */
- trains = trainMgr.getAvailableNewTrains();
- for (TrainI train : trains) {
- if (!operatingCompany.get().mayBuyTrainType(train)) continue;
- if (!mayBuyMoreOfEachType
- && trainsBoughtThisTurn.contains(train.getType())) {
- continue;
+ /* New trains */
+ trains = trainMgr.getAvailableNewTrains();
+ for (TrainI train : trains) {
+ if (!operatingCompany.get().mayBuyTrainType(train)) continue;
+ if (!mayBuyMoreOfEachType
+ && trainsBoughtThisTurn.contains(train.getType())) {
+ continue;
+ }
+ cost = train.getCost();
+ if (cost <= cash) {
+ if (canBuyTrainNow) {
+ BuyTrain action = new BuyTrain(train, ipo, cost);
+ action.setForcedBuyIfNoRoute(presidentMayHelp); // TEMPORARY
+ possibleActions.add(action);
}
- cost = train.getCost();
+ } else if (costOfCheapestTrain == 0
+ || cost < costOfCheapestTrain) {
+ cheapestTrain = train;
+ costOfCheapestTrain = cost;
+ }
+ // Even at train limit, exchange is allowed (per 1856)
+ if (train.canBeExchanged() && hasTrains) {
+ cost = train.getType().getExchangeCost();
if (cost <= cash) {
- if (canBuyTrainNow) {
- BuyTrain action = new BuyTrain(train, ipo, cost);
- action.setForcedBuyIfNoRoute(presidentMayHelp); // TEMPORARY
- possibleActions.add(action);
- }
- } else if (costOfCheapestTrain == 0
- || cost < costOfCheapestTrain) {
- cheapestTrain = train;
- costOfCheapestTrain = cost;
+ List<TrainI> exchangeableTrains =
+ operatingCompany.get().getPortfolio().getUniqueTrains();
+ BuyTrain action = new BuyTrain(train, ipo, cost);
+ action.setTrainsForExchange(exchangeableTrains);
+ //if (atTrainLimit) action.setForcedExchange(true);
+ possibleActions.add(action);
+ canBuyTrainNow = true;
}
- // Even at train limit, exchange is allowed (per 1856)
- if (train.canBeExchanged() && hasTrains) {
- cost = train.getType().getExchangeCost();
- if (cost <= cash) {
- List<TrainI> exchangeableTrains =
- operatingCompany.get().getPortfolio().getUniqueTrains();
- BuyTrain action = new BuyTrain(train, ipo, cost);
- action.setTrainsForExchange(exchangeableTrains);
- //if (atTrainLimit) action.setForcedExchange(true);
- possibleActions.add(action);
- canBuyTrainNow = true;
- }
- }
+ }
- if (!canBuyTrainNow) continue;
+ if (!canBuyTrainNow) continue;
- // Can a special property be used?
- // N.B. Assume that this never occurs in combination with
- // a train exchange, otherwise the below code must be duplicated
- // above.
- for (SpecialTrainBuy stb : getSpecialProperties(SpecialTrainBuy.class)) {
- int reducedPrice = stb.getPrice(cost);
- if (reducedPrice > cash) continue;
- BuyTrain bt = new BuyTrain(train, ipo, reducedPrice);
- bt.setSpecialProperty(stb);
- bt.setForcedBuyIfNoRoute(presidentMayHelp); // TEMPORARY
- possibleActions.add(bt);
- }
-
+ // Can a special property be used?
+ // N.B. Assume that this never occurs in combination with
+ // a train exchange, otherwise the below code must be duplicated
+ // above.
+ for (SpecialTrainBuy stb : getSpecialProperties(SpecialTrainBuy.class)) {
+ int reducedPrice = stb.getPrice(cost);
+ if (reducedPrice > cash) continue;
+ BuyTrain bt = new BuyTrain(train, ipo, reducedPrice);
+ bt.setSpecialProperty(stb);
+ bt.setForcedBuyIfNoRoute(presidentMayHelp); // TEMPORARY
+ possibleActions.add(bt);
}
- if (!canBuyTrainNow) return;
- /* Used trains */
- trains = pool.getUniqueTrains();
- for (TrainI train : trains) {
- if (!mayBuyMoreOfEachType
- && trainsBoughtThisTurn.contains(train.getType())) {
- continue;
- }
- cost = train.getCost();
- if (cost <= cash) {
- BuyTrain bt = new BuyTrain(train, pool, cost);
- bt.setForcedBuyIfNoRoute(presidentMayHelp); // TEMPORARY
- possibleActions.add(bt);
- } else if (costOfCheapestTrain == 0
- || cost < costOfCheapestTrain) {
- cheapestTrain = train;
- costOfCheapestTrain = cost;
- }
+ }
+ if (!canBuyTrainNow) return;
+
+ /* Used trains */
+ trains = pool.getUniqueTrains();
+ for (TrainI train : trains) {
+ if (!mayBuyMoreOfEachType
+ && trainsBoughtThisTurn.contains(train.getType())) {
+ continue;
}
- if (!hasTrains && possibleActions.getType(BuyTrain.class).isEmpty()
- && cheapestTrain != null && presidentMayHelp) {
- BuyTrain bt = new BuyTrain(cheapestTrain,
- cheapestTrain.getHolder(), costOfCheapestTrain);
- bt.setPresidentMustAddCash(costOfCheapestTrain - cash);
- bt.setForcedBuyIfNoRoute(presidentMayHelp); // TODO TEMPORARY
+ cost = train.getCost();
+ if (cost <= cash) {
+ BuyTrain bt = new BuyTrain(train, pool, cost);
+ bt.setForcedBuyIfNoRoute(presidentMayHelp); // TEMPORARY
possibleActions.add(bt);
+ } else if (costOfCheapestTrain == 0
+ || cost < costOfCheapestTrain) {
+ cheapestTrain = train;
+ costOfCheapestTrain = cost;
}
}
+ if (!hasTrains && possibleActions.getType(BuyTrain.class).isEmpty()
+ && cheapestTrain != null && presidentMayHelp) {
+ BuyTrain bt = new BuyTrain(cheapestTrain,
+ cheapestTrain.getHolder(), costOfCheapestTrain);
+ bt.setPresidentMustAddCash(costOfCheapestTrain - cash);
+ bt.setForcedBuyIfNoRoute(presidentMayHelp); // TODO TEMPORARY
+ possibleActions.add(bt);
+ }
+ }
- if (!canBuyTrainNow) return;
+ if (!canBuyTrainNow) return;
- /* Other company trains, sorted by president (current player first) */
- if (getCurrentPhase().isTrainTradingAllowed()) {
- BuyTrain bt;
- Player p;
- Portfolio pf;
- int index;
- int numberOfPlayers = getNumberOfPlayers();
+ /* Other company trains, sorted by president (current player first) */
+ if (getCurrentPhase().isTrainTradingAllowed()) {
+ BuyTrain bt;
+ Player p;
+ Portfolio pf;
+ int index;
+ int numberOfPlayers = getNumberOfPlayers();
- // Set up a list per player of presided companies
- List<List<PublicCompanyI>> companiesPerPlayer =
- new ArrayList<List<PublicCompanyI>>(numberOfPlayers);
- for (int i = 0; i < numberOfPlayers; i++)
- companiesPerPlayer.add(new ArrayList<PublicCompanyI>(4));
- List<PublicCompanyI> companies;
- // Sort out which players preside over which companies.
- for (PublicCompanyI c : getOperatingCompanies()) {
- if (c.isClosed() || c == operatingCompany.get()) continue;
- p = c.getPresident();
- index = p.getIndex();
- companiesPerPlayer.get(index).add(c);
- }
- // Scan trains per company per player, operating company president
- // first
- //int currentPlayerIndex = operatingCompany.getObject().getPresident().getIndex();
- int currentPlayerIndex = getCurrentPlayer().getIndex();
- for (int i = currentPlayerIndex; i < currentPlayerIndex
- + numberOfPlayers; i++) {
- companies = companiesPerPlayer.get(i % numberOfPlayers);
- for (PublicCompanyI company : companies) {
- pf = company.getPortfolio();
- trains = pf.getUniqueTrains();
+ // Set up a list per player of presided companies
+ List<List<PublicCompanyI>> companiesPerPlayer =
+ new ArrayList<List<PublicCompanyI>>(numberOfPlayers);
+ for (int i = 0; i < numberOfPlayers; i++)
+ companiesPerPlayer.add(new ArrayList<PublicCompanyI>(4));
+ List<PublicCompanyI> companies;
+ // Sort out which players preside over which companies.
+ for (PublicCompanyI c : getOperatingCompanies()) {
+ if (c.isClosed() || c == operatingCompany.get()) continue;
+ p = c.getPresident();
+ index = p.getIndex();
+ companiesPerPlayer.get(index).add(c);
+ }
+ // Scan trains per company per player, operating company president
+ // first
+ //int currentPlayerIndex = operatingCompany.getObject().getPresident().getIndex();
+ int currentPlayerIndex = getCurrentPlayer().getIndex();
+ for (int i = currentPlayerIndex; i < currentPlayerIndex
+ + numberOfPlayers; i++) {
+ companies = companiesPerPlayer.get(i % numberOfPlayers);
+ for (PublicCompanyI company : companies) {
+ pf = company.getPortfolio();
+ trains = pf.getUniqueTrains();
- for (TrainI train : trains) {
- if (train.isObsolete()) continue;
- if (i != currentPlayerIndex
- //&& trainMgr.buyAtFaceValueBetweenDifferentPresidents()
- && getGameParameterAsBoolean(GameDef.Parm.FIXED_PRICE_TRAINS_BETWEEN_PRESIDENTS)
- || operatingCompany.get().mustTradeTrainsAtFixedPrice()
- || company.mustTradeTrainsAtFixedPrice()) {
- if (cash >= train.getCost()) {
- bt = new BuyTrain(train, pf, train.getCost());
- } else {
- continue;
- }
+ for (TrainI train : trains) {
+ if (train.isObsolete()) continue;
+ if (i != currentPlayerIndex
+ //&& trainMgr.buyAtFaceValueBetweenDifferentPresidents()
+ && getGameParameterAsBoolean(GameDef.Parm.FIXED_PRICE_TRAINS_BETWEEN_PRESIDENTS)
+ || operatingCompany.get().mustTradeTrainsAtFixedPrice()
+ || company.mustTradeTrainsAtFixedPrice()) {
+ if (cash >= train.getCost()) {
+ bt = new BuyTrain(train, pf, train.getCost());
} else {
- bt = new BuyTrain(train, pf, 0);
+ continue;
}
- if (presidentMayHelp && cash < train.getCost()) {
- bt.setPresidentMayAddCash(train.getCost() - cash);
- }
- possibleActions.add(bt);
+ } else {
+ bt = new BuyTrain(train, pf, 0);
}
+ if (presidentMayHelp && cash < train.getCost()) {
+ bt.setPresidentMayAddCash(train.getCost() - cash);
+ }
+ possibleActions.add(bt);
}
}
}
+ }
- if (!operatingCompany.get().mustOwnATrain()
- || operatingCompany.get().getPortfolio().getNumberOfTrains() > 0) {
- doneAllowed = true;
- }
+ if (!operatingCompany.get().mustOwnATrain()
+ || operatingCompany.get().getPortfolio().getNumberOfTrains() > 0) {
+ doneAllowed = true;
+ }
}
/**
Modified: trunk/18xx/rails/game/action/SetDividend.java
===================================================================
--- trunk/18xx/rails/game/action/SetDividend.java 2010-09-24 21:55:37 UTC (rev 1433)
+++ trunk/18xx/rails/game/action/SetDividend.java 2010-10-07 19:41:11 UTC (rev 1434)
@@ -23,11 +23,12 @@
public static final int WITHHOLD = 0;
public static final int SPLIT = 1;
public static final int PAYOUT = 2;
- public static final int NUM_OPTIONS = 3;
+ public static final int NO_TRAIN = 3;
+ public static final int NUM_OPTIONS = 4;
/** Allocation name keys in the resource bundle */
public static final String[] allocationNameKeys =
- new String[] { "WITHHOLD", "SPLIT", "PAYOUT" };
+ new String[] { "WITHHOLD", "SPLIT", "PAYOUT", "NO_TRAIN" };
/*--- Server-side settings ---*/
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|