From: Erik V. <ev...@us...> - 2011-12-01 10:51:18
|
data/1830/CompanyManager.xml | 2 - rails/game/OperatingRound.java | 64 +++++++++++++++++++++++++++++---- rails/game/Tile.java | 15 +++++++ rails/game/action/LayTile.java | 37 ++++++++++--------- rails/game/special/SpecialTileLay.java | 60 +++++++++++++++--------------- 5 files changed, 125 insertions(+), 53 deletions(-) New commits: commit d7237eb244b6daecea9fa7df87e3e0116fbf9a38 Author: Erik Vos <eri...@xs...> Date: Wed Nov 30 23:21:02 2011 +0100 Further changes to fix special tile lays. diff --git a/data/1830/CompanyManager.xml b/data/1830/CompanyManager.xml index 3623f7f..5c2fe0e 100644 --- a/data/1830/CompanyManager.xml +++ b/data/1830/CompanyManager.xml @@ -40,7 +40,7 @@ <Blocking hex="B20"/> <SpecialProperties> <SpecialProperty condition="ifOwnedByCompany" when="tileLayingStep" class="rails.game.special.SpecialTileLay"> - <SpecialTileLay location="B20" extra="yes" free="yes"/> + <SpecialTileLay colour="yellow" location="B20" extra="yes" free="yes"/> </SpecialProperty> </SpecialProperties> </Company> diff --git a/rails/game/OperatingRound.java b/rails/game/OperatingRound.java index f754fa8..5ade2c4 100644 --- a/rails/game/OperatingRound.java +++ b/rails/game/OperatingRound.java @@ -1715,11 +1715,18 @@ public class OperatingRound extends Round implements Observer { for (String colour : stlc) { if (phaseColours.contains(colour)) layableColours.add(colour); } + if (layableColours.isEmpty()) continue; } // If any locations are specified, check if tile or colour(s) can be laid there. Map<String, Integer> tc = new HashMap<String, Integer>(); List<MapHex> hexes = stl.getLocations(); + List<MapHex> remainingHexes = null; + List<String> remainingColours = null; + if (hexes != null) { + remainingHexes = new ArrayList<MapHex> (); + remainingColours = new ArrayList<String>(); + } for (String colour : layableColours) { if (hexes != null) { for (MapHex hex : hexes) { @@ -1727,6 +1734,8 @@ public class OperatingRound extends Round implements Observer { if (hex.getCurrentTile().getColourNumber() + 1 == Tile.getColourNumberForName(colour)) { tc.put(colour, 1); + remainingColours.add(colour); + remainingHexes.add(hex); continue; } } @@ -1736,6 +1745,13 @@ public class OperatingRound extends Round implements Observer { } if (!tc.isEmpty()) lt.setTileColours(tc); + if (hexes != null) { + if (!remainingHexes.isEmpty()) { + lt.setLocations(remainingHexes); + } else { + continue; + } + } if (!tc.isEmpty() || hexes == null) currentSpecialTileLays.add(lt); } } diff --git a/rails/game/action/LayTile.java b/rails/game/action/LayTile.java index a5d0ad2..074e0ea 100644 --- a/rails/game/action/LayTile.java +++ b/rails/game/action/LayTile.java @@ -181,6 +181,11 @@ public class LayTile extends PossibleORAction { return locations; } + public void setLocations(List<MapHex> locations) { + this.locations = locations; + if (locations != null) buildLocationNameString(); + } + public int getType() { return type; } diff --git a/rails/game/special/SpecialTileLay.java b/rails/game/special/SpecialTileLay.java index b7fd63a..3e1dea6 100644 --- a/rails/game/special/SpecialTileLay.java +++ b/rails/game/special/SpecialTileLay.java @@ -8,7 +8,7 @@ import rails.common.LocalText; import rails.common.parser.ConfigurationException; import rails.common.parser.Tag; import rails.game.*; -import rails.util.*; +import rails.util.Util; public class SpecialTileLay extends SpecialProperty { @@ -25,9 +25,9 @@ public class SpecialTileLay extends SpecialProperty { * Default is same colours as is allowed in a a normal tile lay. * Don't use if specific tiles are specified! */ protected String[] tileColours = null; - + @Override - public void configureFromXML(Tag tag) throws ConfigurationException { + public void configureFromXML(Tag tag) throws ConfigurationException { super.configureFromXML(tag); Tag tileLayTag = tag.getChild("SpecialTileLay"); @@ -41,43 +41,43 @@ public class SpecialTileLay extends SpecialProperty { tileNumber = tileLayTag.getAttributeAsInteger("tile", 0); - String coloursString = tag.getAttributeAsString("colour"); + String coloursString = tileLayTag.getAttributeAsString("colour"); if (Util.hasValue(coloursString)) { tileColours = coloursString.split(","); } - + name = tileLayTag.getAttributeAsString("name"); extra = tileLayTag.getAttributeAsBoolean("extra", extra); free = tileLayTag.getAttributeAsBoolean("free", free); connected = tileLayTag.getAttributeAsBoolean("connected", connected); /* sfy 1889 extension */ closingValue = - tileLayTag.getAttributeAsInteger("closingValue", closingValue); + tileLayTag.getAttributeAsInteger("closingValue", closingValue); if (tileNumber > 0) { - description = LocalText.getText("LayNamedTileInfo", - tileNumber, - name != null ? name : "", - locationCodes, - (extra ? LocalText.getText("extra"):LocalText.getText("notExtra")), - (free ? LocalText.getText("noCost") : LocalText.getText("normalCost")), - (connected ? LocalText.getText("connected") : LocalText.getText("unconnected")) - /* sfy 1889 extension */ - ); + description = LocalText.getText("LayNamedTileInfo", + tileNumber, + name != null ? name : "", + locationCodes, + (extra ? LocalText.getText("extra"):LocalText.getText("notExtra")), + (free ? LocalText.getText("noCost") : LocalText.getText("normalCost")), + (connected ? LocalText.getText("connected") : LocalText.getText("unconnected")) + /* sfy 1889 extension */ + ); } else { - description = LocalText.getText("LayTileInfo", - locationCodes, - (extra ? LocalText.getText("extra"):LocalText.getText("notExtra")), - (free ? LocalText.getText("noCost") : LocalText.getText("normalCost")), + description = LocalText.getText("LayTileInfo", + locationCodes, + (extra ? LocalText.getText("extra"):LocalText.getText("notExtra")), + (free ? LocalText.getText("noCost") : LocalText.getText("normalCost")), (connected ? LocalText.getText("connected") : LocalText.getText("unconnected")) /* sfy 1889 extension */ - ); + ); } } @Override - public void finishConfiguration (GameManagerI gameManager) + public void finishConfiguration (GameManagerI gameManager) throws ConfigurationException { TileManager tmgr = gameManager.getTileManager(); @@ -93,7 +93,7 @@ public class SpecialTileLay extends SpecialProperty { hex = mmgr.getHex(hexName); if (hex == null) throw new ConfigurationException("Location " + hexName - + " does not exist"); + + " does not exist"); locations.add(hex); } @@ -140,18 +140,20 @@ public class SpecialTileLay extends SpecialProperty { } @Override - public String toString() { - return "SpecialTileLay comp=" + originalCompany.getName() + " hex=" - + locationCodes + " extra=" + extra + " cost=" + free + " connected=" + connected; + public String toString() { + return "SpecialTileLay comp=" + originalCompany.getName() + + " hex=" + locationCodes + + " colour="+tileColours + + " extra=" + extra + " cost=" + free + " connected=" + connected; } @Override - public String toMenu() { - return description; + public String toMenu() { + return description; } @Override - public String getInfo() { - return description; + public String getInfo() { + return description; } } commit 990c04c1307f86d382b46fc640cedf2fcee7fc0f Merge: 0713ba0 f3a0308 Author: Erik Vos <eri...@xs...> Date: Wed Nov 30 23:03:59 2011 +0100 Merge branch 'master' of ssh://rails.git.sourceforge.net/gitroot/rails/rails into fixes commit 0713ba0215c23c385ba9414b6f6768650e43f99f Author: Erik Vos <eri...@xs...> Date: Wed Nov 30 00:44:33 2011 +0100 Special tile lay fixes diff --git a/rails/game/OperatingRound.java b/rails/game/OperatingRound.java index 8d6dac3..f754fa8 100644 --- a/rails/game/OperatingRound.java +++ b/rails/game/OperatingRound.java @@ -485,7 +485,7 @@ public class OperatingRound extends Round implements Observer { if (getStep() != GameDef.OrStep.LAY_TOKEN) { possibleActions.add(new LayBaseToken((SpecialTokenLay)sp)); } - } else { + } else if (!(sp instanceof SpecialTileLay)){ possibleActions.add(new UseSpecialProperty(sp)); } } @@ -1688,21 +1688,55 @@ public class OperatingRound extends Round implements Observer { if (operatingCompany.get().canUseSpecialProperties()) { + // What colours can be laid in the current phase? + List<String> phaseColours = getCurrentPhase().getTileColours(); + for (SpecialTileLay stl : getSpecialProperties(SpecialTileLay.class)) { if (stl.isExtra() // If the special tile lay is not extra, it is only allowed if // normal tile lays are also (still) allowed || checkNormalTileLay(stl.getTile(), false)) { LayTile lt = new LayTile(stl); + TileI tile = stl.getTile(); + + // Which tile colour(s) are specified explicitly... String[] stlc = stl.getTileColours(); - if (stlc != null) { - Map<String, Integer> tc = new HashMap<String, Integer>(); - for (String c : stlc) { - tc.put(c, 1); + if ((stlc == null || stlc.length == 0) && tile != null) { + // ... or implicitly + stlc = new String[] {tile.getColourName()}; + } + + // Which of the specified tile colours can really be laid now? + List<String> layableColours; + if (stlc == null) { + layableColours = phaseColours; + } else { + layableColours = new ArrayList<String>(); + for (String colour : stlc) { + if (phaseColours.contains(colour)) layableColours.add(colour); } - lt.setTileColours(tc); } - currentSpecialTileLays.add(lt); + + // If any locations are specified, check if tile or colour(s) can be laid there. + Map<String, Integer> tc = new HashMap<String, Integer>(); + List<MapHex> hexes = stl.getLocations(); + for (String colour : layableColours) { + if (hexes != null) { + for (MapHex hex : hexes) { + // At least one hex does not have that colour yet + if (hex.getCurrentTile().getColourNumber() + 1 + == Tile.getColourNumberForName(colour)) { + tc.put(colour, 1); + continue; + } + } + } else { + tc.put(colour, 1); + } + } + + if (!tc.isEmpty()) lt.setTileColours(tc); + if (!tc.isEmpty() || hexes == null) currentSpecialTileLays.add(lt); } } } diff --git a/rails/game/Tile.java b/rails/game/Tile.java index 2ef98f0..d36365e 100644 --- a/rails/game/Tile.java +++ b/rails/game/Tile.java @@ -406,6 +406,21 @@ public class Tile extends ModelObject implements TileI, StationHolder, Comparabl return colourNumber; } + public static int getColourNumberForName(String name) { + if (name.equalsIgnoreCase(WHITE_COLOUR_NAME)) { + return WHITE_COLOUR_NUMBER; + } else if (name.equalsIgnoreCase(YELLOW_COLOUR_NAME)) { + return YELLOW_COLOUR_NUMBER; + } else if (name.equalsIgnoreCase(GREEN_COLOUR_NAME)) { + return GREEN_COLOUR_NUMBER; + } else if (name.equalsIgnoreCase(BROWN_COLOUR_NAME)) { + return BROWN_COLOUR_NUMBER; + } else if (name.equalsIgnoreCase(GREY_COLOUR_NAME)) { + return GREY_COLOUR_NUMBER; + } else { + return -1; + } + } /** * @return Returns the id. */ diff --git a/rails/game/action/LayTile.java b/rails/game/action/LayTile.java index 1d30f72..a5d0ad2 100644 --- a/rails/game/action/LayTile.java +++ b/rails/game/action/LayTile.java @@ -103,7 +103,7 @@ public class LayTile extends PossibleORAction { } } - + } /** @@ -194,8 +194,8 @@ public class LayTile extends PossibleORAction { public boolean isTileColourAllowed(String tileColour) { return tileColours != null - && tileColours.containsKey(tileColour) - && tileColours.get(tileColour) > 0; + && tileColours.containsKey(tileColour) + && tileColours.get(tileColour) > 0; } public void setTileColours(Map<String, Integer> map) { @@ -226,7 +226,7 @@ public class LayTile extends PossibleORAction { relaidBaseTokens.put(companyName, cityNumber); relaidBaseTokensString = Util.appendWithDelimiter(relaidBaseTokensString, Util.appendWithDelimiter(companyName, String.valueOf(cityNumber), ":"), - ","); + ","); } public Map<String, Integer> getRelaidBaseTokens() { @@ -238,10 +238,10 @@ public class LayTile extends PossibleORAction { if (!(action instanceof LayTile)) return false; LayTile a = (LayTile) action; return (a.locationNames == null && locationNames == null || a.locationNames.equals(locationNames)) - && a.type == type - && a.tileColours == tileColours - && a.tiles == tiles - && a.specialProperty == specialProperty; + && a.type == type + && a.tileColours == tileColours + && a.tiles == tiles + && a.specialProperty == specialProperty; } @Override @@ -249,15 +249,15 @@ public class LayTile extends PossibleORAction { if (!(action instanceof LayTile)) return false; LayTile a = (LayTile) action; return (a.laidTileId == laidTileId - && a.chosenHexName.equals(chosenHexName) - && a.orientation == orientation - && (a.relaidBaseTokensString == null && relaidBaseTokensString == null - || a.relaidBaseTokensString.equals(relaidBaseTokensString))); + && a.chosenHexName.equals(chosenHexName) + && a.orientation == orientation + && (a.relaidBaseTokensString == null && relaidBaseTokensString == null + || a.relaidBaseTokensString.equals(relaidBaseTokensString))); } @Override public String toString() { - StringBuffer b = new StringBuffer("LayTile"); + StringBuilder b = new StringBuilder("LayTile"); if (laidTile == null) { b.append(" type=").append(type); if (locations != null) @@ -274,7 +274,7 @@ public class LayTile extends PossibleORAction { } else { b.append(" tile=").append(laidTile.getId()).append(" hex=").append( chosenHex.getName()).append(" orientation=").append( - orientation).append(" tokens=").append(relaidBaseTokensString); + orientation).append(" tokens=").append(relaidBaseTokensString); } return b.toString(); } @@ -282,7 +282,7 @@ public class LayTile extends PossibleORAction { /** Deserialize */ @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, - ClassNotFoundException { + ClassNotFoundException { //in.defaultReadObject(); // Custom reading for backwards compatibility @@ -315,7 +315,7 @@ public class LayTile extends PossibleORAction { } if (specialPropertyId > 0) { specialProperty = - (SpecialTileLay) SpecialProperty.getByUniqueId(specialPropertyId); + (SpecialTileLay) SpecialProperty.getByUniqueId(specialPropertyId); } if (laidTileId != 0) { laidTile = tmgr.getTile(laidTileId); |