diff options
author | celestar <celestar@openttd.org> | 2006-03-20 16:43:48 +0000 |
---|---|---|
committer | celestar <celestar@openttd.org> | 2006-03-20 16:43:48 +0000 |
commit | fc32e2019561f398c193f6e510e8482797303021 (patch) | |
tree | cc5045ef1db49cd6bee44904b6462f9adfd8fd86 /tile.c | |
parent | 7bedab1a401c07ae67035d396344ef456945f993 (diff) | |
download | openttd-fc32e2019561f398c193f6e510e8482797303021.tar.xz |
(svn r3992) -Fix: Rewrote the code to determine whether a rail-tile can be terraformed.
Fixes a bug where you could terraform a tunnel (fixed by r3228, but reverted that one)
Fixes a bug introduced by r3228 which allowed steep rail tiles resulting in ... unwanted effects such as display artifacts.
That means the terraform feature should not work as intended; it also uses _valid_tileh_slopes to determine valid configurations instead of hand-brewn stuff.
TODO: _terraform_err_tile and similar TileIndices should have INVALID_TILE as "unused", not 0. (0 is a valid tile).
Diffstat (limited to 'tile.c')
-rw-r--r-- | tile.c | 41 |
1 files changed, 26 insertions, 15 deletions
@@ -15,6 +15,30 @@ uint GetMapExtraBits(TileIndex tile) return GB(_m[tile].extra, 0, 2); } +/** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile + * @param n,w,e,s the four corners + * @param h uint pointer to write the height to + * @return the tileh +*/ +uint GetTileh(uint n, uint w, uint e, uint s, uint *h) +{ + uint min = n; + uint r; + + if (min >= w) min = w; + if (min >= e) min = e; + if (min >= s) min = s; + + r = 0; + if ((n -= min) != 0) r += (--n << 4) + 8; + if ((e -= min) != 0) r += (--e << 4) + 4; + if ((s -= min) != 0) r += (--s << 4) + 2; + if ((w -= min) != 0) r += (--w << 4) + 1; + + if (h != NULL) *h = min * 8; + + return r; +} uint GetTileSlope(TileIndex tile, uint *h) { @@ -22,8 +46,6 @@ uint GetTileSlope(TileIndex tile, uint *h) uint b; uint c; uint d; - uint min; - uint r; assert(tile < MapSize()); @@ -32,23 +54,12 @@ uint GetTileSlope(TileIndex tile, uint *h) return 0; } - min = a = TileHeight(tile); + a = TileHeight(tile); b = TileHeight(tile + TileDiffXY(1, 0)); - if (min >= b) min = b; c = TileHeight(tile + TileDiffXY(0, 1)); - if (min >= c) min = c; d = TileHeight(tile + TileDiffXY(1, 1)); - if (min >= d) min = d; - - r = 0; - if ((a -= min) != 0) r += (--a << 4) + 8; - if ((c -= min) != 0) r += (--c << 4) + 4; - if ((d -= min) != 0) r += (--d << 4) + 2; - if ((b -= min) != 0) r += (--b << 4) + 1; - - if (h != NULL) *h = min * 8; - return r; + return GetTileh(a, b, c, d, h); } uint GetTileZ(TileIndex tile) |