From 8131ce7e21b93234d43e3c0c90319d44935a5b5a Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 25 Jul 2007 15:45:46 +0000 Subject: [PATCH] (svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary. --- src/tile.cpp | 35 ++++++++++++++++++----------------- src/tunnel_map.cpp | 6 ++---- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/tile.cpp b/src/tile.cpp index 128c16128f..449156465d 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -23,11 +23,11 @@ Slope GetTileSlope(TileIndex tile, uint *h) min = a = TileHeight(tile); b = TileHeight(tile + TileDiffXY(1, 0)); - if (min >= b) min = b; + if (min > b) min = b; c = TileHeight(tile + TileDiffXY(0, 1)); - if (min >= c) min = c; + if (min > c) min = c; d = TileHeight(tile + TileDiffXY(1, 1)); - if (min >= d) min = d; + if (min > d) min = d; r = SLOPE_FLAT; if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; @@ -42,24 +42,25 @@ Slope GetTileSlope(TileIndex tile, uint *h) uint GetTileZ(TileIndex tile) { - uint h; - GetTileSlope(tile, &h); - return h; + if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0; + + uint h = TileHeight(tile); + h = min(h, TileHeight(tile + TileDiffXY(1, 0))); + h = min(h, TileHeight(tile + TileDiffXY(0, 1))); + h = min(h, TileHeight(tile + TileDiffXY(1, 1))); + + return h * TILE_HEIGHT; } uint GetTileMaxZ(TileIndex t) { - uint max; - uint h; + if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0; - h = TileHeight(t); - max = h; - h = TileHeight(t + TileDiffXY(1, 0)); - if (h > max) max = h; - h = TileHeight(t + TileDiffXY(0, 1)); - if (h > max) max = h; - h = TileHeight(t + TileDiffXY(1, 1)); - if (h > max) max = h; - return max * 8; + uint h = TileHeight(t); + h = max(h, TileHeight(t + TileDiffXY(1, 0))); + h = max(h, TileHeight(t + TileDiffXY(0, 1))); + h = max(h, TileHeight(t + TileDiffXY(1, 1))); + + return h * TILE_HEIGHT; } diff --git a/src/tunnel_map.cpp b/src/tunnel_map.cpp index 8d75735b66..593d3fe6bc 100644 --- a/src/tunnel_map.cpp +++ b/src/tunnel_map.cpp @@ -64,8 +64,6 @@ bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir) bool IsTunnelInWay(TileIndex tile, uint z) { return - IsTunnelInWayDir(tile, z, DIAGDIR_NE) || - IsTunnelInWayDir(tile, z, DIAGDIR_SE) || - IsTunnelInWayDir(tile, z, DIAGDIR_SW) || - IsTunnelInWayDir(tile, z, DIAGDIR_NW); + IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) || + IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE); }