From: <wak...@us...> - 2011-06-13 19:10:52
|
Revision: 1576 http://rails.svn.sourceforge.net/rails/?rev=1576&view=rev Author: wakko666 Date: 2011-06-13 19:10:45 +0000 (Mon, 13 Jun 2011) Log Message: ----------- Apply TileOrientation Enumeration patch from "Adam Badura" <ab...@o2...> Modified Paths: -------------- trunk/18xx/data/1825/Map.xml trunk/18xx/data/1830/Map.xml trunk/18xx/data/1835/Map.xml trunk/18xx/data/1851/Map.xml trunk/18xx/data/1856/Map.xml trunk/18xx/data/1870/Map.xml trunk/18xx/data/1880/Map.xml trunk/18xx/data/1889/Map.xml trunk/18xx/data/18AL/Map.xml trunk/18xx/data/18EU/Map.xml trunk/18xx/data/18GA/Map.xml trunk/18xx/data/18JR/Map.xml trunk/18xx/data/18Kaas/Map.xml trunk/18xx/data/18Scan/Map.xml trunk/18xx/data/18TN/Map.xml trunk/18xx/data/18VA/Map.xml trunk/18xx/rails/game/MapHex.java trunk/18xx/rails/game/MapManager.java trunk/18xx/rails/ui/swing/hexmap/EWHexMap.java trunk/18xx/rails/ui/swing/hexmap/GUIHex.java trunk/18xx/rails/ui/swing/hexmap/GUITile.java trunk/18xx/rails/ui/swing/hexmap/NSHexMap.java Added Paths: ----------- trunk/18xx/rails/game/TileOrientation.java Modified: trunk/18xx/data/1825/Map.xml =================================================================== --- trunk/18xx/data/1825/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1825/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="R"> +<Map tileOrientation="EW" letterOrientation="vertical" even="R"> <IfOption name="Include" parm="Unit3" value="yes"> <Hex name="B8" tile="-5" orientation="1" city="Inverness"/> <Hex name="B12" tile="-25011" city="Aberdeen"/> Modified: trunk/18xx/data/1830/Map.xml =================================================================== --- trunk/18xx/data/1830/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1830/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" +<Map tileOrientation="EW" letterOrientation="vertical" even="B"> <Hex name="A9" tile="-901" orientation="0" value="30,50" city="Canadian West"/> <Hex name="A11" tile="-902" orientation="1" value="30,50" city="Canadian West"/> Modified: trunk/18xx/data/1835/Map.xml =================================================================== --- trunk/18xx/data/1835/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1835/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="B"> +<Map tileOrientation="EW" letterOrientation="vertical" even="B"> <Hex name="A9" tile="-7"/> <Hex name="A11" tile="-10" city="Kiel"/> <Hex name="A17" tile="-800" orientation="5"/> Modified: trunk/18xx/data/1851/Map.xml =================================================================== --- trunk/18xx/data/1851/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1851/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="B"> +<Map tileOrientation="EW" letterOrientation="vertical" even="B"> <Hex name="@18" tile="-902" orientation="1" value="40,50,60" city="Cincinnati"/> <Hex name="A3" tile="-901" orientation="5" value="40,50,70" city="St. Louis"/> <Hex name="A5" tile="-10" orientation="1" city="East St. Louis"/> Modified: trunk/18xx/data/1856/Map.xml =================================================================== --- trunk/18xx/data/1856/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1856/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.NSHexMap" tileOrientation="NS" letterOrientation="horizontal" even="A"> +<Map tileOrientation="NS" letterOrientation="horizontal" even="A"> <Hex name="A20" tile="-902" value="30,50,60" city="Detroit/Windsor"/> <Hex name="B13" tile="-902" orientation="1" value="30,50,50" city="Sarnia"/> <Hex name="B15" tile="0"/> Modified: trunk/18xx/data/1870/Map.xml =================================================================== --- trunk/18xx/data/1870/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1870/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="A"> +<Map tileOrientation="EW" letterOrientation="vertical" even="A"> <Hex name="A2" tile="-902" value="30,40,50" city="Denver"/> <Hex name="A4" tile="0"/> <Hex name="A6" tile="0"/> Modified: trunk/18xx/data/1880/Map.xml =================================================================== --- trunk/18xx/data/1880/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1880/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="B"> +<Map tileOrientation="EW" letterOrientation="vertical" even="B"> <Hex name="A3" tile="-902" value="20,30,40,50" city="Russia" /> <Hex name="A5" tile="-10" city="Qiqihar"/> <Hex name="A7" tile="-1" /> Modified: trunk/18xx/data/1889/Map.xml =================================================================== --- trunk/18xx/data/1889/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/1889/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.NSHexMap" tileOrientation="NS" letterOrientation="horizontal" even="A"> +<Map tileOrientation="NS" letterOrientation="horizontal" even="A"> <Hex name="A8" tile="0" cost="80"/> <Hex name="A10" tile="-10" city="Sukomo"/> Modified: trunk/18xx/data/18AL/Map.xml =================================================================== --- trunk/18xx/data/18AL/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18AL/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.NSHexMap" tileOrientation="NS" letterOrientation="vertical" even="A"> +<Map tileOrientation="NS" letterOrientation="vertical" even="A"> <Hex name="A2" tile="0"/> <Hex name="A4" tile="-912" orientation="2" value="40,50" city="Nashville"/> <Hex name="B1" tile="-901" value="40,30" city="Corinth"/> Modified: trunk/18xx/data/18EU/Map.xml =================================================================== --- trunk/18xx/data/18EU/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18EU/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.NSHexMap" tileOrientation="NS" letterOrientation="vertical" even="A"> +<Map tileOrientation="NS" letterOrientation="vertical" even="A"> <Image file="18EU/MapImage.svg" x="18" y="15" scale="0.952"/> <!-- Hex name="" tile="" orientation="" value="" impassable="" label="" cost="" value="" port="yes/no" --> <Hex name="A4" port="yes" value="10" tile="-800" orientation="0"/> Modified: trunk/18xx/data/18GA/Map.xml =================================================================== --- trunk/18xx/data/18GA/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18GA/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,5 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" - letterOrientation="vertical" even="B"> +<Map tileOrientation="EW" letterOrientation="vertical" even="B"> <Hex name="A3" tile="-902" orientation="1" value="30,60" city="Chattanooga"/> <Hex name="B2" tile="0" cost="60"> Modified: trunk/18xx/data/18JR/Map.xml =================================================================== --- trunk/18xx/data/18JR/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18JR/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.NSHexMap" tileOrientation="NS" letterOrientation="vertical" even="B"> +<Map tileOrientation="NS" letterOrientation="vertical" even="B"> <Hex name="A5" tile="-7" orientation="1"/> <Hex name="A7" tile="-7" orientation="2"/> Modified: trunk/18xx/data/18Kaas/Map.xml =================================================================== --- trunk/18xx/data/18Kaas/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18Kaas/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="A"> +<Map tileOrientation="EW" letterOrientation="vertical" even="A"> <!-- To be added: orientation, impassable hex sides, etc.--> <Hex name="A16" tile="0"/> <Hex name="A18" tile="-3" value="10" orientation="0"/> Modified: trunk/18xx/data/18Scan/Map.xml =================================================================== --- trunk/18xx/data/18Scan/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18Scan/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" letterOrientation="vertical" even="A"> +<Map tileOrientation="EW" letterOrientation="vertical" even="A"> <!-- Hex name="" tile="" orientation="" value="" impassable="" label="" cost="" value="" port="yes/no" --> <Hex name="A4" tile="-911" city="Newcastle" value="20,50,80"/> <Hex name="A6" tile="0" cost="60"/> Modified: trunk/18xx/data/18TN/Map.xml =================================================================== --- trunk/18xx/data/18TN/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18TN/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,5 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.EWHexMap" tileOrientation="EW" - letterOrientation="vertical" even="A"> +<Map tileOrientation="EW" letterOrientation="vertical" even="A"> <Hex name="A16" tile="-902" city="Cincinnati" orientation="1" value="50,80"/> <Hex name="B13" tile="-10001" city="Louisville"/> Modified: trunk/18xx/data/18VA/Map.xml =================================================================== --- trunk/18xx/data/18VA/Map.xml 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/data/18VA/Map.xml 2011-06-13 19:10:45 UTC (rev 1576) @@ -1,4 +1,4 @@ -<Map mapClass="rails.ui.swing.hexmap.NSHexMap" tileOrientation="NS" letterOrientation="vertical" even="A"> +<Map tileOrientation="NS" letterOrientation="vertical" even="A"> <Hex name="A6" tile="0"/> <Hex name="A8" tile="-1921" orientation="1" value="40,70" city="Philadelphia"/> <Hex name="B5" tile="-10" city="Hagerstown"/> Modified: trunk/18xx/rails/game/MapHex.java =================================================================== --- trunk/18xx/rails/game/MapHex.java 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/rails/game/MapHex.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -19,14 +19,14 @@ /** * Represents a Hex on the Map from the Model side. * - * <p> <b>Tile orientations</b>. Tiles can be oriented NS or EW; the directions - * refer to the "flat" hex sides. <p> The term "rotation" is used to indicate - * the amount of rotation (in 60 degree units) from the standard orientation of - * the tile (sometimes the term orientation is also used to refer to rotation). + * <p> The term "rotation" is used to indicate the amount of rotation (in 60 + * degree units) from the standard orientation of the tile (sometimes the term + * orientation is also used to refer to rotation). * <p>Rotation is always relative to the standard orientation, which has the - * printed tile number on the S edge for NS oriented tiles, or on the SW edge - * for EW oriented tiles. The rotation numbers are indicated in the below - * picture for an NS-oriented tile: <p> <code> + * printed tile number on the S edge for {@link TileOrientation#NS}-oriented + * tiles, or on the SW edge for {@link TileOrientation#EW}-oriented tiles. The + * rotation numbers are indicated in the below picture for an + * {@code NS}-oriented tile: <p> <code> * * ____3____ * / \ @@ -35,15 +35,12 @@ * \ / * 1 5 * \____0____/ - * </code> <p> For EW-oriented + * </code> <p> For {@code EW}-oriented * tiles the above picture should be rotated 30 degrees clockwise. */ public class MapHex extends ModelObject implements ConfigurableComponentI, StationHolder, TokenHolder { - public static final int EW = 0; - public static final int NS = 1; - private static final String[] ewOrNames = { "SW", "W", "NW", "NE", "E", "SE" }; private static final String[] nsOrNames = @@ -186,7 +183,7 @@ if (lettersGoHorizontal()) { row = number; column = letter - '@'; - if (getTileOrientation() == MapHex.EW) { + if (getTileOrientation() == TileOrientation.EW) { // Tiles with flat EW sides, letters go horizontally. // Example: 1841 (NOT TESTED, PROBABLY WRONG). x = column; @@ -202,7 +199,7 @@ { row = letter - '@'; column = number; - if (getTileOrientation() == MapHex.EW) { + if (getTileOrientation() == TileOrientation.EW) { // Tiles with flat EW sides, letters go vertically. // Most common case. // Tested for 1830 and 1870. OK with 1830 Wabash and 1825R2 (negative column numbers) @@ -276,6 +273,9 @@ } public void finishConfiguration (GameManagerI gameManager) { + if(gameManager == null) { + throw new IllegalArgumentException("gameManager must not be null"); + } currentTile = gameManager.getTileManager().getTile(preprintedTileId); // We need completely new objects, not just references to the Tile's @@ -335,7 +335,7 @@ return openHexSides != null && openHexSides[side%6]; } - public int getTileOrientation() { + public TileOrientation getTileOrientation() { return mapManager.getTileOrientation(); } @@ -355,7 +355,7 @@ public String getOrientationName(int orientation) { - if (getTileOrientation() == EW) { + if (getTileOrientation() == TileOrientation.EW) { return ewOrNames[orientation % 6]; } else { return nsOrNames[orientation % 6]; Modified: trunk/18xx/rails/game/MapManager.java =================================================================== --- trunk/18xx/rails/game/MapManager.java 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/rails/game/MapManager.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -18,7 +18,7 @@ // The next attributes are duplicates in MapHex. We'll see what we really // need. - protected int tileOrientation; + protected TileOrientation tileOrientation; protected boolean lettersGoHorizontal; protected boolean letterAHasEvenNumbers; @@ -60,23 +60,28 @@ * @see rails.game.ConfigurableComponentI#configureFromXML(org.w3c.dom.Element) */ public void configureFromXML(Tag tag) throws ConfigurationException { - mapUIClassName = tag.getAttributeAsString("mapClass"); - if (mapUIClassName == null) { - throw new ConfigurationException("Map class name missing"); - } - String attr = tag.getAttributeAsString("tileOrientation"); if (attr == null) throw new ConfigurationException("Map orientation undefined"); - if (attr.equals("EW")) { - tileOrientation = MapHex.EW; - } else if (attr.equals("NS")) { - tileOrientation = MapHex.NS; - } else { - throw new ConfigurationException("Invalid tile orientation: " - + attr); + try { + tileOrientation = TileOrientation.valueOf(attr); } + catch(IllegalArgumentException exception) { + throw new ConfigurationException("Invalid tile orientation: " + attr, exception); + } + switch(tileOrientation) { + case NS: + mapUIClassName = "rails.ui.swing.hexmap.NSHexMap"; + break; + case EW: + mapUIClassName = "rails.ui.swing.hexmap.EWHexMap"; + break; + default: + // Unexpected default. + throw new AssertionError(tileOrientation); + } + attr = tag.getAttributeAsString("letterOrientation"); if (attr.equals("horizontal")) { lettersGoHorizontal = true; @@ -101,8 +106,8 @@ List<Tag> hexTags = tag.getChildren("Hex"); MapHex hex; - minX = minY = minCol = minRow = 9999; - maxX = maxY = maxCol = maxRow = -9999; + minX = minY = minCol = minRow = Integer.MAX_VALUE; + maxX = maxY = maxCol = maxRow = Integer.MIN_VALUE; possibleTileCosts = new TreeSet<Integer>(); for (Tag hexTag : hexTags) { hex = new MapHex(this); @@ -223,7 +228,7 @@ public int getAdjacentX (int x, int y, int orientation) { - if (tileOrientation == MapHex.EW) { + if (tileOrientation == TileOrientation.EW) { return x + (y % 2 == 0 ? xYEvenDeltaEW[orientation] : xYOddDeltaEW[orientation]); } else { return x + xDeltaNS[orientation]; @@ -232,7 +237,7 @@ public int getAdjacentY (int x, int y, int orientation) { - if (tileOrientation == MapHex.EW) { + if (tileOrientation == TileOrientation.EW) { return y + yDeltaEW[orientation]; } else { return y + ((x % 2 == 0) == letterAHasEvenNumbers ? @@ -243,7 +248,7 @@ /** * @return Returns the currentTileOrientation. */ - public int getTileOrientation() { + public TileOrientation getTileOrientation() { return tileOrientation; } Added: trunk/18xx/rails/game/TileOrientation.java =================================================================== --- trunk/18xx/rails/game/TileOrientation.java (rev 0) +++ trunk/18xx/rails/game/TileOrientation.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -0,0 +1,57 @@ +package rails.game; + +/** + * Tile orientation enumeration. + * + * Tile orientation refers to "flat edges" parallel with coordinates system + * axis. Thus there are two orientations: North-South + * ({@link TileOrientation#NS NS}) and East-West + * ({@link TileOrientation#EW EW}). + * + * Although it seems neither is dominating in 18xx games North-South is used by + * default for management and classification. So North-South orientation is + * treated here as the natural one. + * + * @author Adam Badura + * @since 1.4.3 + */ +public enum TileOrientation { + /** + * North-South tile orientation. + * + * <p>This is default orientation for internal uses (which includes SVG + * images).</p> + */ + NS, + + /** + * East-West tile orientation. + */ + EW; + + + /** + * Returns rotation to be applied to {@link TileOrientation#NS}-oriented + * tile to achieve this orientation. + * + * <p>The rotation has to be done around center point of the tile.</p> + * + * <p>This function returns {@literal 0} for {@link TileOrientation#NS} + * since {@code NS}-oriented tile does not need any rotation to be + * transformed into {@code NS}-oriented tile.</p> + * + * @return Rotation to be applied to {@link TileOrientation#NS}-oriented + * tile to achieve this orientation. + */ + public int getBaseRotation() { + switch(this) { + case NS: + return 0; + case EW: + return 30; + default: + // Unexpected default. + throw new AssertionError(this); + } + } +} Property changes on: trunk/18xx/rails/game/TileOrientation.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/18xx/rails/ui/swing/hexmap/EWHexMap.java =================================================================== --- trunk/18xx/rails/ui/swing/hexmap/EWHexMap.java 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/rails/ui/swing/hexmap/EWHexMap.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -4,7 +4,8 @@ import java.awt.*; /** - * Class EWHexMap displays a basic hex map with EW exit orientation. + * Class EWHexMap displays a basic hex map with + * {@link rails.game.TileOrientation#EW EW} exit orientation. */ public class EWHexMap extends HexMap { Modified: trunk/18xx/rails/ui/swing/hexmap/GUIHex.java =================================================================== --- trunk/18xx/rails/ui/swing/hexmap/GUIHex.java 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/rails/ui/swing/hexmap/GUIHex.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -108,7 +108,7 @@ this.zoomFactor = zoomFactor; tokenDiameter = (int)Math.round(NORMAL_TOKEN_SIZE * zoomFactor); - if (hexMap.getMapManager().getTileOrientation() == MapHex.EW) { + if (hexMap.getMapManager().getTileOrientation() == TileOrientation.EW) { /* The numbering is unusual: * 0 * / \ @@ -242,7 +242,7 @@ // NOTE: orientation here is its normal value in Rails + 3 (mod 6). orientation %= 6; if (barStartPoints == null) barStartPoints = new ArrayList<Integer>(2); - if (hexMap.getMapManager().getTileOrientation() == MapHex.EW) { + if (hexMap.getMapManager().getTileOrientation() == TileOrientation.EW) { barStartPoints.add((5-orientation)%6); } else { barStartPoints.add((3+orientation)%6); Modified: trunk/18xx/rails/ui/swing/hexmap/GUITile.java =================================================================== --- trunk/18xx/rails/ui/swing/hexmap/GUITile.java 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/rails/ui/swing/hexmap/GUITile.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -56,7 +56,7 @@ tile = tileManager.getTile(tileId); picId = tile.getPictureId(); - if (hex.getTileOrientation() == MapHex.EW) { + if (hex.getTileOrientation() == TileOrientation.EW) { baseRotation = 0.5 * DEG60; } else { baseRotation = 0.0; Modified: trunk/18xx/rails/ui/swing/hexmap/NSHexMap.java =================================================================== --- trunk/18xx/rails/ui/swing/hexmap/NSHexMap.java 2011-06-11 06:05:21 UTC (rev 1575) +++ trunk/18xx/rails/ui/swing/hexmap/NSHexMap.java 2011-06-13 19:10:45 UTC (rev 1576) @@ -4,7 +4,8 @@ import java.awt.*; /** - * Class NSHexMap displays a basic hex map with NS exit orientation. + * Class NSHexMap displays a basic hex map with + * {@link rails.game.TileOrientation#NS NS} exit orientation. */ public class NSHexMap extends HexMap { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |