|
From: <ev...@us...> - 2011-04-14 20:33:51
|
Revision: 1519
http://rails.svn.sourceforge.net/rails/?rev=1519&view=rev
Author: evos
Date: 2011-04-14 20:33:44 +0000 (Thu, 14 Apr 2011)
Log Message:
-----------
SpecialLayTile improvements:
- added priority and colour attributes
- UI handling rationalised
Modified Paths:
--------------
trunk/18xx/rails/game/OperatingRound.java
trunk/18xx/rails/game/action/LayTile.java
trunk/18xx/rails/game/special/SpecialProperty.java
trunk/18xx/rails/game/special/SpecialPropertyI.java
trunk/18xx/rails/game/special/SpecialTileLay.java
trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java
trunk/18xx/rails/ui/swing/ORUIManager.java
Modified: trunk/18xx/rails/game/OperatingRound.java
===================================================================
--- trunk/18xx/rails/game/OperatingRound.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/game/OperatingRound.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -1415,7 +1415,16 @@
// normal tile lays are also (still) allowed
|| stl.getTile() != null
&& checkNormalTileLay(stl.getTile(), false)) {
- currentSpecialTileLays.add(new LayTile(stl));
+ LayTile lt = new LayTile(stl);
+ String[] stlc = stl.getTileColours();
+ if (stlc != null) {
+ Map<String, Integer> tc = new HashMap<String, Integer>();
+ for (String c : stlc) {
+ tc.put(c, 1);
+ }
+ lt.setTileColours(tc);
+ }
+ currentSpecialTileLays.add(lt);
}
}
}
Modified: trunk/18xx/rails/game/action/LayTile.java
===================================================================
--- trunk/18xx/rails/game/action/LayTile.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/game/action/LayTile.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -75,6 +75,7 @@
/**
* Allow laying a tile on a given location.
*/
+ // NOTE: NOT YET USED
public LayTile(List<MapHex> locations, List<TileI> tiles) {
type = LOCATION_SPECIFIC;
this.locations = locations;
Modified: trunk/18xx/rails/game/special/SpecialProperty.java
===================================================================
--- trunk/18xx/rails/game/special/SpecialProperty.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/game/special/SpecialProperty.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -1,8 +1,7 @@
/* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/special/SpecialProperty.java,v 1.27 2010/03/23 18:45:23 stefanfrey Exp $ */
package rails.game.special;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
import org.apache.log4j.Logger;
@@ -33,7 +32,15 @@
protected boolean permanent = false;
protected boolean isORProperty = false;
protected boolean isSRProperty = false;
-
+
+ /** Priority indicates whether or not the UI should assign priority to
+ * the execution of a PossibleAction. For instance, if the same tile can
+ * be laid on a hex using this special property, and by not using it,
+ * this attribute indicates which option will be used.
+ * TODO A third value means: ask the user (NOT YET IMPLEMENTED).
+ */
+ protected Priority priority = DEFAULT_PRIORITY;
+
/** Optional descriptive text, for display in menus and info text.
* Subclasses may put real text in it.
*/
@@ -88,6 +95,16 @@
// sfy 1889
permanent = tag.getAttributeAsBoolean("permanent", false);
+
+ String priorityString = tag.getAttributeAsString("priority");
+ if (Util.hasValue(priorityString)) {
+ try {
+ priority = Priority.valueOf(priorityString.toUpperCase());
+ } catch (IllegalArgumentException e) {
+ throw new ConfigurationException ("Illegal value for SpecialProperty priority: "+priorityString, e);
+ }
+ }
+
}
public void finishConfiguration (GameManagerI gameManager)
@@ -216,6 +233,14 @@
return transferText;
}
+ public Priority getPriority() {
+ return priority;
+ }
+
+ public void setPriority(Priority priority) {
+ this.priority = priority;
+ }
+
/**
* Move the special property to another holder.
* Only to be used for special properties that have the "transfer" attribute.
Modified: trunk/18xx/rails/game/special/SpecialPropertyI.java
===================================================================
--- trunk/18xx/rails/game/special/SpecialPropertyI.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/game/special/SpecialPropertyI.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -51,6 +51,18 @@
public String getTransferText();
+ public enum Priority {
+ LAST,
+ ASKUSER,
+ FIRST;
+ };
+
+ public static final Priority DEFAULT_PRIORITY = Priority.FIRST;
+
+ public Priority getPriority();
+
+ public void setPriority(Priority priority);
+
public int getUniqueId();
public String toMenu();
Modified: trunk/18xx/rails/game/special/SpecialTileLay.java
===================================================================
--- trunk/18xx/rails/game/special/SpecialTileLay.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/game/special/SpecialTileLay.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -18,6 +18,11 @@
boolean free = false;
boolean connected = false; /* sfy 1889 extension */
+ /** Tile colours that can be laid with this special property.
+ * 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 {
super.configureFromXML(tag);
@@ -33,6 +38,11 @@
tileNumber = tileLayTag.getAttributeAsInteger("tile", 0);
+ String coloursString = tag.getAttributeAsString("colour");
+ if (Util.hasValue(coloursString)) {
+ tileColours = coloursString.split(",");
+ }
+
name = tileLayTag.getAttributeAsString("name");
extra = tileLayTag.getAttributeAsBoolean("extra", extra);
@@ -118,6 +128,10 @@
return tile;
}
+ public String[] getTileColours() {
+ return tileColours;
+ }
+
public String getName() {
return name;
}
Modified: trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java
===================================================================
--- trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/game/specific/_1835/OperatingRound_1835.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -235,9 +235,11 @@
errMsg ));
return false;
} else {
+ moveStack.start(true); // Duplicate, but we have to
hasLaidExtraOBBTile.set(true);
// Done here to make getSpecialTileLays() return the correct value.
// It's provisional, on the assumption that other validations are OK.
+ // TODO To get it really right, we should separate validation and execution.
}
}
Modified: trunk/18xx/rails/ui/swing/ORUIManager.java
===================================================================
--- trunk/18xx/rails/ui/swing/ORUIManager.java 2011-04-14 20:31:35 UTC (rev 1518)
+++ trunk/18xx/rails/ui/swing/ORUIManager.java 2011-04-14 20:33:44 UTC (rev 1519)
@@ -211,9 +211,13 @@
if (sp == null || !(sp instanceof SpecialTileLay) ||
((SpecialTileLay)sp).requiresConnection())
break;
- case (LayTile.LOCATION_SPECIFIC):
- if (layTile.getLocations() != null)
+ // else fall through
+ case (LayTile.LOCATION_SPECIFIC): // NOT YET USED
+ if (layTile.getLocations() != null) {
hexUpgrades.addAll(layTile.getLocations());
+ } else {
+ mapHexes = true;
+ }
}
}
@@ -760,31 +764,29 @@
List<TileI> sp_tiles;
List<MapHex> sp_hexes;
LayTile gen_lt = null;
+ LayTile spec_lt = null;
for (LayTile lt : allowances) {
if (lt.getType() == LayTile.SPECIAL_PROPERTY) {
// Cases where a special property is used include:
// 1. SP refers to specified tiles, (one of) which is chosen:
// (examples: 18AL Lumber Terminal, 1889 Port)
- if ((((sp_tiles = lt.getTiles()) != null
- && sp_tiles.contains(tile))
- // 2. SP does not refer to specific tiles but it does refer to
- // specified hexes, (one of) which is chosen:
+ if ((sp_tiles = lt.getTiles()) != null
+ && !sp_tiles.contains(tile)) continue;
+ // 2. SP refers to specified hexes, (one of) which is chosen:
// (example: 1830 hex B20)
- || (sp_tiles == null
- && (sp_hexes = lt.getLocations()) != null)
- && sp_hexes.contains(selectedHex.getModel()))) {
- allowance = lt;
- break;
- }
+ if ((sp_hexes = lt.getLocations()) != null
+ && !sp_hexes.contains(selectedHex.getModel())) continue;
+ spec_lt = lt;
} else {
+ // Default case: the generic allowance
gen_lt = lt;
}
}
- // Default case: the generic allowance
- // TODO It is not clear that all possible cases have been covered yet.
- // But at least this works for 1830, 1889
- if (allowance == null) allowance = gen_lt;
+ allowance = spec_lt == null ? gen_lt :
+ gen_lt == null ? spec_lt :
+ spec_lt.getSpecialProperty().getPriority()
+ == SpecialPropertyI.Priority.FIRST ? spec_lt : gen_lt;
}
allowance.setChosenHex(selectedHex.getHexModel());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|