|
From: <ev...@us...> - 2011-05-21 10:40:50
|
Revision: 1563
http://rails.svn.sourceforge.net/rails/?rev=1563&view=rev
Author: evos
Date: 2011-05-21 10:40:43 +0000 (Sat, 21 May 2011)
Log Message:
-----------
Added some Javadoc to Tile.java.
Added 'quantityIncrement' attribute to <Tile>. Not used yet, but may be useful for 1825 kits.
Integer values may now be prefixed with a '+' sign (which is stripped before parsing by Java). May be helpful with increment values.
Modified Paths:
--------------
trunk/18xx/rails/game/MapHex.java
trunk/18xx/rails/game/Tile.java
trunk/18xx/rails/game/TileI.java
trunk/18xx/rails/util/Tag.java
Modified: trunk/18xx/rails/game/MapHex.java
===================================================================
--- trunk/18xx/rails/game/MapHex.java 2011-05-19 12:13:55 UTC (rev 1562)
+++ trunk/18xx/rails/game/MapHex.java 2011-05-21 10:40:43 UTC (rev 1563)
@@ -804,7 +804,7 @@
+ "/" + currentTileRotation + " by " + newTile.getId() + "/"
+ newTileOrientation);
- newTile.lay(this);
+ newTile.add(this);
currentTile = newTile;
currentTileRotation = newTileOrientation;
Modified: trunk/18xx/rails/game/Tile.java
===================================================================
--- trunk/18xx/rails/game/Tile.java 2011-05-19 12:13:55 UTC (rev 1562)
+++ trunk/18xx/rails/game/Tile.java 2011-05-21 10:40:43 UTC (rev 1563)
@@ -10,6 +10,12 @@
import rails.util.LocalText;
import rails.util.Tag;
+/** Represents a certain tile <i>type</i>, identified by its id (tile number).
+ * <p> For each tile number, only one tile object is created.
+ * The list <b>tilesLaid</b> records in which hexes a certain tile number has been laid.
+ * @author Erik
+ *
+ */
public class Tile extends ModelObject implements TileI, StationHolder, Comparable<TileI> {
/** The 'internal id', identifying the tile in the XML files */
@@ -82,6 +88,10 @@
protected static final int TILE_NUMBER_OFFSET = 2;
+ /** Records in which hexes a certain tile number has been laid.
+ * The length of this list indicates the number of tiles laid on the map board.
+ * <p>As this list is not a State object, it must only be updated via the TileMove execute() and undo() methods.
+ */
private final ArrayList<MapHex> tilesLaid = new ArrayList<MapHex>();
/** Storage of revenueBonus that are bound to the tile */
@@ -204,12 +214,18 @@
externalId = setTag.getAttributeAsString("extId", externalId);
/* Picture id */
pictureId = setTag.getAttributeAsInteger("pic", pictureId);
+
/* Quantity */
quantity = setTag.getAttributeAsInteger("quantity", 0);
/* Value '99' and '-1' mean 'unlimited' */
unlimited = (quantity == 99 || quantity == UNLIMITED_TILES
|| "yes".equalsIgnoreCase(setTag.getGameOptions().get("UnlimitedTiles")));
- if (unlimited) quantity = UNLIMITED_TILES;
+ if (unlimited) {
+ quantity = UNLIMITED_TILES;
+ } else {
+ quantity += setTag.getAttributeAsInteger("quantityIncrement", 0);
+ }
+
/* Multiple base tokens of one company allowed */
allowsMultipleBasesOfOneCompany = setTag.hasChild(
"AllowsMultipleBasesOfOneCompany");
@@ -467,16 +483,17 @@
return relayBaseTokensOnUpgrade;
}
- public boolean lay(MapHex hex) {
-
+ /** Register a tile of this type being laid on the map.
+ * This method may only be called via the TileMove execute() and undo() methods. */
+ public boolean add(MapHex hex) {
tilesLaid.add(hex);
update();
-
return true;
}
+ /** Register a tile of this type being removed from the map.
+ * This method may only be called via the TileMove execute() and undo() methods. */
public boolean remove(MapHex hex) {
-
tilesLaid.remove(hex);
update();
return true;
@@ -498,6 +515,7 @@
return "#" + externalId + ": " + count;
}
+ // NOT USED
public int getQuantity() {
return quantity;
}
Modified: trunk/18xx/rails/game/TileI.java
===================================================================
--- trunk/18xx/rails/game/TileI.java 2011-05-19 12:13:55 UTC (rev 1562)
+++ trunk/18xx/rails/game/TileI.java 2011-05-21 10:40:43 UTC (rev 1563)
@@ -62,7 +62,7 @@
public int getNumStations();
- public boolean lay(MapHex hex);
+ public boolean add(MapHex hex);
public boolean remove(MapHex hex);
Modified: trunk/18xx/rails/util/Tag.java
===================================================================
--- trunk/18xx/rails/util/Tag.java 2011-05-19 12:13:55 UTC (rev 1562)
+++ trunk/18xx/rails/util/Tag.java 2011-05-21 10:40:43 UTC (rev 1563)
@@ -141,6 +141,8 @@
String value = attributes.get(name);
if (value == null) return defaultValue;
try {
+ // Unlike Java, we want to allow '+' signs
+ if (value.startsWith("+")) value = value.substring(1);
return Integer.parseInt(value);
} catch (Exception e) {
throw new ConfigurationException("Invalid integer value: " + value,
@@ -168,11 +170,11 @@
}
}
-public int getAttributeAsInteger(String name) throws ConfigurationException {
+ public int getAttributeAsInteger(String name) throws ConfigurationException {
+
+ return getAttributeAsInteger(name, 0);
+ }
-return getAttributeAsInteger(name, 0);
-}
-
public int[] getAttributeAsIntegerArray(String name, int[] defaultArray)
throws ConfigurationException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|