From d60bbad2e11333c8772a2dd1fb29bb2358e4a0bd Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sun, 11 Aug 2013 04:07:14 +0000 Subject: [PATCH] TileConstants: continue moving tile number logic to central location (rails and wires) git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@782 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/TileConstants.java | 84 ++++++++++++++++++++ src/micropolisj/engine/ToolStroke.java | 95 +++++------------------ 2 files changed, 103 insertions(+), 76 deletions(-) diff --git a/src/micropolisj/engine/TileConstants.java b/src/micropolisj/engine/TileConstants.java index 10cf26c..be55503 100644 --- a/src/micropolisj/engine/TileConstants.java +++ b/src/micropolisj/engine/TileConstants.java @@ -495,6 +495,90 @@ public class TileConstants return (tmp >= RAILBASE && tmp < RESBASE); } + public static boolean isRailDynamic(int tile) + { + int tmp = tile & LOMASK; + return (tmp >= LHRAIL && tmp <= LVRAIL10); + } + + public static boolean railConnectsEast(int tile) + { + tile = neutralizeRoad(tile); + return (tile >= RAILHPOWERV && tile <= VRAILROAD && + tile != RAILVPOWERH && + tile != VRAILROAD && + tile != VRAIL); + } + + public static boolean railConnectsNorth(int tile) + { + tile = neutralizeRoad(tile); + return (tile >= RAILHPOWERV && tile <= VRAILROAD && + tile != RAILHPOWERV && + tile != HRAILROAD && + tile != HRAIL); + } + + public static boolean railConnectsSouth(int tile) + { + tile = neutralizeRoad(tile); + return (tile >= RAILHPOWERV && tile <= VRAILROAD && + tile != RAILHPOWERV && + tile != HRAILROAD && + tile != HRAIL); + } + + public static boolean railConnectsWest(int tile) + { + tile = neutralizeRoad(tile); + return (tile >= RAILHPOWERV && tile <= VRAILROAD && + tile != RAILVPOWERH && + tile != VRAILROAD && + tile != VRAIL); + } + + public static boolean isWireDynamic(int tile) + { + int tmp = tile & LOMASK; + return (tmp >= LHPOWER && tile <= LVPOWER10); + } + + public static boolean wireConnectsEast(int tile) + { + int ntile = neutralizeRoad(tile); + return (isConductive(tile) && + ntile != HPOWER && + ntile != HROADPOWER && + ntile != RAILHPOWERV); + } + + public static boolean wireConnectsNorth(int tile) + { + int ntile = neutralizeRoad(tile); + return (isConductive(tile) && + ntile != VPOWER && + ntile != VROADPOWER && + ntile != RAILVPOWERH); + } + + public static boolean wireConnectsSouth(int tile) + { + int ntile = neutralizeRoad(tile); + return (isConductive(tile) && + ntile != VPOWER && + ntile != VROADPOWER && + ntile != RAILVPOWERH); + } + + public static boolean wireConnectsWest(int tile) + { + int ntile = neutralizeRoad(tile); + return (isConductive(tile) && + ntile != HPOWER && + ntile != HROADPOWER && + ntile != RAILHPOWERV); + } + public static boolean isCommercialZone(int tile) { assert isZoneCenter(tile); diff --git a/src/micropolisj/engine/ToolStroke.java b/src/micropolisj/engine/ToolStroke.java index 63e9180..2b172c6 100644 --- a/src/micropolisj/engine/ToolStroke.java +++ b/src/micropolisj/engine/ToolStroke.java @@ -271,8 +271,7 @@ public class ToolStroke private void fixSingle(ToolEffectIfc eff) { - int tile = (eff.getTile(0, 0) & LOMASK); - tile = neutralizeRoad(tile); + int tile = eff.getTile(0, 0); if (isRoadDynamic(tile)) { @@ -306,121 +305,65 @@ public class ToolStroke eff.setTile(0, 0, (RoadTable[adjTile] | BULLBIT)); } //endif on a road tile - else if (tile >= LHRAIL && tile <= LVRAIL10) + else if (isRailDynamic(tile)) { // cleanup Rail int adjTile = 0; // check rail to north + if (railConnectsSouth(eff.getTile(0, -1))) { - tile = eff.getTile(0, -1); - tile = neutralizeRoad(tile); - if (tile >= RAILHPOWERV && tile <= VRAILROAD && - tile != RAILHPOWERV && - tile != HRAILROAD && - tile != HRAIL) - { - adjTile |= 1; - } + adjTile |= 1; } // check rail to east + if (railConnectsWest(eff.getTile(1, 0))) { - tile = eff.getTile(1, 0); - tile = neutralizeRoad(tile); - if (tile >= RAILHPOWERV && tile <= VRAILROAD && - tile != RAILVPOWERH && - tile != VRAILROAD && - tile != VRAIL) - { - adjTile |= 2; - } + adjTile |= 2; } // check rail to south + if (railConnectsNorth(eff.getTile(0, 1))) { - tile = eff.getTile(0, 1); - tile = neutralizeRoad(tile); - if (tile >= RAILHPOWERV && tile <= VRAILROAD && - tile != RAILHPOWERV && - tile != HRAILROAD && - tile != HRAIL) - { - adjTile |= 4; - } + adjTile |= 4; } // check rail to west + if (railConnectsEast(eff.getTile(-1, 0))) { - tile = eff.getTile(-1, 0); - tile = neutralizeRoad(tile); - if (tile >= RAILHPOWERV && tile <= VRAILROAD && - tile != RAILVPOWERH && - tile != VRAILROAD && - tile != VRAIL) - { - adjTile |= 8; - } + adjTile |= 8; } eff.setTile(0, 0, (RailTable[adjTile] | BULLBIT)); } //end if on a rail tile - else if (tile >= LHPOWER && tile <= LVPOWER10) + else if (isWireDynamic(tile)) { // Cleanup Wire int adjTile = 0; // check wire to north + if (wireConnectsSouth(eff.getTile(0, -1))) { - tile = eff.getTile(0, -1); - char ntile = neutralizeRoad(tile); - if (isConductive(tile) && - ntile != VPOWER && - ntile != VROADPOWER && - ntile != RAILVPOWERH) - { - adjTile |= 1; - } + adjTile |= 1; } // check wire to east + if (wireConnectsWest(eff.getTile(1, 0))) { - tile = eff.getTile(1, 0); - char ntile = neutralizeRoad(tile); - if (isConductive(tile) && - ntile != HPOWER && - ntile != HROADPOWER && - ntile != RAILHPOWERV) - { - adjTile |= 2; - } + adjTile |= 2; } // check wire to south + if (wireConnectsNorth(eff.getTile(0, 1))) { - tile = eff.getTile(0, 1); - char ntile = neutralizeRoad(tile); - if (isConductive(tile) && - ntile != VPOWER && - ntile != VROADPOWER && - ntile != RAILVPOWERH) - { - adjTile |= 4; - } + adjTile |= 4; } // check wire to west + if (wireConnectsEast(eff.getTile(-1, 0))) { - tile = eff.getTile(-1, 0); - char ntile = neutralizeRoad(tile); - if (isConductive(tile) && - ntile != HPOWER && - ntile != HROADPOWER && - ntile != RAILHPOWERV) - { - adjTile |= 8; - } + adjTile |= 8; } eff.setTile(0, 0, (WireTable[adjTile] | BULLBIT));