(svn r4012) -Backport from trunk (3992, 3995): 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.
This commit is contained in:
celestar
2006-03-22 10:32:07 +00:00
parent 6e029fe97d
commit c05d3dd558
4 changed files with 50 additions and 55 deletions

42
tile.c
View File

@@ -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,24 +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)