From: Erik V. <ev...@us...> - 2012-06-13 22:32:31
|
data/1835/CompanyManager.xml | 3 +- rails/ui/swing/ORUIManager.java | 51 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) New commits: commit f34c80df8dacc9f6381c2a0c615cec89aade704c Author: Erik Vos <eri...@xs...> Date: Wed Jun 13 17:36:00 2012 +0200 Fixes for 1835 Pfalzbahnen. Manual closure made possible for PfB. If two tokens are laid on L6 (BA home) before the first tile, only the BA president will get asked where to put the BA home token. diff --git a/data/1835/CompanyManager.xml b/data/1835/CompanyManager.xml index 4e05202..b7e893f 100644 --- a/data/1835/CompanyManager.xml +++ b/data/1835/CompanyManager.xml @@ -55,7 +55,7 @@ <ClosingConditions> <Phase>5</Phase> <SpecialProperties condition="ifAllExercised"/> - <CloseManually/> <!-- If second tile is laid not via special property --> + <CloseManually/> <!-- Workaround, may be needed if one of the tiles is not laid via this special property --> </ClosingConditions> </Company> <Company name="PfB" longname="Pfalzbahnen" type="Private" basePrice="150" revenue="15"> @@ -70,6 +70,7 @@ <ClosingConditions> <Phase>5</Phase> <SpecialProperties condition="ifAllExercised"/> + <CloseManually/> <!-- Workaround, may be needed if a tile or token is not laid via this special property --> </ClosingConditions> </Company> <Company name="LD" longname="Leipzig-Dresdner Bahn" type="Private" basePrice="190"> diff --git a/rails/ui/swing/ORUIManager.java b/rails/ui/swing/ORUIManager.java index 0224995..2252757 100644 --- a/rails/ui/swing/ORUIManager.java +++ b/rails/ui/swing/ORUIManager.java @@ -937,12 +937,53 @@ public class ORUIManager implements DialogOwner { */ protected void relayBaseTokens (LayTile action) { - MapHex hex = action.getChosenHex(); + final MapHex hex = action.getChosenHex(); TileI newTile = action.getLaidTile(); TileI oldTile = hex.getCurrentTile(); if (!action.isRelayBaseTokens() && !oldTile.relayBaseTokensOnUpgrade()) return; - for (Stop oldStop : hex.getStops()) { + + List<Stop> stopsToQuery = hex.getStops(); + + /* Check which tokens must be relaid, and in which sequence. + * Ideally, the game engine should instruct the UI what to do + * if there is more than one stop and more than one token. + * TODO LayTile does not yet allow that. + * + * For now, the only case that needs special handling is the 1835 BA home hex L6, + * where it it possible to have two tokens laid before even one tile. + * Let's generalise this case to: two stops, both tokened. + * We consider single-slot stops only. + * In fact, all we need to do is + * 1. Sort the stops so that the home company gets queried first, + * 2. Count down the number of free slots per new station, so that full stations are skipped, + * It's already taken care for, that a choice-between-one is handled automatically. + * [EV, jun2012] + */ + if (stopsToQuery.size() == 2) { + Collections.sort(stopsToQuery, new Comparator<Stop>() { + public int compare (Stop s1, Stop s2) { + // Home stops on this hex go first. + boolean home1 = ((BaseToken)s1.getTokens().get(0)).getCompany().getHomeHexes().contains(hex); + boolean home2 = ((BaseToken)s2.getTokens().get(0)).getCompany().getHomeHexes().contains(hex); + if (home1 && !home2) { + return -1; + } else if (home2 && !home1) { + return 1; + } else { + return 0; // Doesn't matter + } + } + }); + } + + // Array to enable counting down the free token slots per new station + int[] freeSlots = new int[1 + newTile.getStations().size()]; + for (Station newStation : newTile.getStations()) { + freeSlots[newStation.getNumber()] = newStation.getBaseSlots(); + } + + for (Stop oldStop : stopsToQuery) { if (oldStop.hasTokens()) { // Assume only 1 token (no exceptions known) PublicCompanyI company = ((BaseToken)oldStop.getTokens().get(0)).getCompany(); @@ -951,7 +992,7 @@ public class ORUIManager implements DialogOwner { Map<String, Integer> promptToCityMap = new HashMap<String, Integer>(); String prompt; for (Station newStation : newTile.getStations()) { - if (newStation.getBaseSlots() > 0) { + if (newStation.getBaseSlots() > 0 && freeSlots[newStation.getNumber()] > 0) { prompt = LocalText.getText("SelectStationForTokenOption", newStation.getNumber(), hex.getConnectionString( @@ -987,8 +1028,10 @@ public class ORUIManager implements DialogOwner { prompts.toArray(), prompts.get(0)); if (selected == null) return; action.addRelayBaseToken(company.getName(), promptToCityMap.get(selected)); + --freeSlots[promptToCityMap.get(selected)]; } else { - action.addRelayBaseToken(company.getName(), promptToCityMap.get(prompts.toArray() [0])); + action.addRelayBaseToken(company.getName(), promptToCityMap.get(prompts.toArray()[0])); + --freeSlots[promptToCityMap.get(prompts.toArray()[0])]; } } } |