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));