From b4f7e09d74512a5acd66b134d8a82892b900e91b Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sun, 11 Aug 2013 04:07:11 +0000 Subject: [PATCH] TileConstants: move tile number comparisons to central location (road numbers) git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@781 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/TileConstants.java | 54 ++++++++++++++++++++++ src/micropolisj/engine/ToolStroke.java | 55 ++++------------------- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/src/micropolisj/engine/TileConstants.java b/src/micropolisj/engine/TileConstants.java index c2479d1..10cf26c 100644 --- a/src/micropolisj/engine/TileConstants.java +++ b/src/micropolisj/engine/TileConstants.java @@ -435,6 +435,60 @@ public class TileConstants return (tmp >= ROADBASE && tmp < POWERBASE); } + /** + * Checks whether the tile is a road that will automatically change to connect to + * neighboring roads. + */ + public static boolean isRoadDynamic(int tile) + { + int tmp = neutralizeRoad(tile); + return (tmp >= ROADS && tile <= INTERSECTION); + } + + public static boolean roadConnectsEast(int tile) + { + tile = neutralizeRoad(tile); + return (((tile == VRAILROAD) || + (tile >= ROADBASE && tile <= VROADPOWER) + ) && + (tile != VROADPOWER) && + (tile != HRAILROAD) && + (tile != VBRIDGE)); + } + + public static boolean roadConnectsNorth(int tile) + { + tile = neutralizeRoad(tile); + return (((tile == HRAILROAD) || + (tile >= ROADBASE && tile <= VROADPOWER) + ) && + (tile != HROADPOWER) && + (tile != VRAILROAD) && + (tile != ROADBASE)); + } + + public static boolean roadConnectsSouth(int tile) + { + tile = neutralizeRoad(tile); + return (((tile == HRAILROAD) || + (tile >= ROADBASE && tile <= VROADPOWER) + ) && + (tile != HROADPOWER) && + (tile != VRAILROAD) && + (tile != ROADBASE)); + } + + public static boolean roadConnectsWest(int tile) + { + tile = neutralizeRoad(tile); + return (((tile == VRAILROAD) || + (tile >= ROADBASE && tile <= VROADPOWER) + ) && + (tile != VROADPOWER) && + (tile != HRAILROAD) && + (tile != VBRIDGE)); + } + public static boolean isRail(int tile) { int tmp = tile & LOMASK; diff --git a/src/micropolisj/engine/ToolStroke.java b/src/micropolisj/engine/ToolStroke.java index 8b66de5..63e9180 100644 --- a/src/micropolisj/engine/ToolStroke.java +++ b/src/micropolisj/engine/ToolStroke.java @@ -274,70 +274,33 @@ public class ToolStroke int tile = (eff.getTile(0, 0) & LOMASK); tile = neutralizeRoad(tile); - if (tile >= TileConstants.ROADS && tile <= INTERSECTION) + if (isRoadDynamic(tile)) { // cleanup road int adjTile = 0; // check road to north + if (roadConnectsSouth(eff.getTile(0, -1))) { - tile = eff.getTile(0, -1); - tile = neutralizeRoad(tile); - if (((tile == HRAILROAD) || - (tile >= ROADBASE && tile <= VROADPOWER) - ) && - (tile != HROADPOWER) && - (tile != VRAILROAD) && - (tile != ROADBASE)) - { - adjTile |= 1; - } + adjTile |= 1; } // check road to east + if (roadConnectsWest(eff.getTile(1, 0))) { - tile = eff.getTile(1, 0); - tile = neutralizeRoad(tile); - if (((tile == VRAILROAD) || - (tile >= ROADBASE && tile <= VROADPOWER) - ) && - (tile != VROADPOWER) && - (tile != HRAILROAD) && - (tile != VBRIDGE)) - { - adjTile |= 2; - } + adjTile |= 2; } // check road to south + if (roadConnectsNorth(eff.getTile(0, 1))) { - tile = eff.getTile(0, 1); - tile = neutralizeRoad(tile); - if (((tile == HRAILROAD) || - (tile >= ROADBASE && tile <= VROADPOWER) - ) && - (tile != HROADPOWER) && - (tile != VRAILROAD) && - (tile != ROADBASE)) - { - adjTile |= 4; - } - + adjTile |= 4; } // check road to west + if (roadConnectsEast(eff.getTile(-1, 0))) { - tile = eff.getTile(-1, 0); - tile = neutralizeRoad(tile); - if (((tile == VRAILROAD) || - (tile >= ROADBASE && tile <= VROADPOWER) - ) && - (tile != VROADPOWER) && - (tile != HRAILROAD) && - (tile != VBRIDGE)) - { - adjTile |= 8; - } + adjTile |= 8; } eff.setTile(0, 0, (RoadTable[adjTile] | BULLBIT));