diff options
author | KUDr <kudr@openttd.org> | 2007-01-10 18:12:09 +0000 |
---|---|---|
committer | KUDr <kudr@openttd.org> | 2007-01-10 18:12:09 +0000 |
commit | e373ea7096c741a8189f7a480863fd21dd6f6be1 (patch) | |
tree | d9abc3d9810159441bed9f82a52bd1ee52d770dd /src/tile.cpp | |
parent | 001d858b528d78743deaf7dcea46ea8f0736bad9 (diff) | |
download | openttd-e373ea7096c741a8189f7a480863fd21dd6f6be1.tar.xz |
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
Diffstat (limited to 'src/tile.cpp')
-rw-r--r-- | src/tile.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/tile.cpp b/src/tile.cpp new file mode 100644 index 000000000..ba6900a36 --- /dev/null +++ b/src/tile.cpp @@ -0,0 +1,63 @@ +/* $Id$ */ + +#include "stdafx.h" +#include "tile.h" + +Slope GetTileSlope(TileIndex tile, uint *h) +{ + uint a; + uint b; + uint c; + uint d; + uint min; + uint r; + + assert(tile < MapSize()); + + if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { + if (h != NULL) *h = 0; + return 0; + } + + min = 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 = SLOPE_FLAT; + if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; + if ((c -= min) != 0) r += (--c << 4) + SLOPE_E; + if ((d -= min) != 0) r += (--d << 4) + SLOPE_S; + if ((b -= min) != 0) r += (--b << 4) + SLOPE_W; + + if (h != NULL) *h = min * TILE_HEIGHT; + + return r; +} + +uint GetTileZ(TileIndex tile) +{ + uint h; + GetTileSlope(tile, &h); + return h; +} + + +uint GetTileMaxZ(TileIndex t) +{ + uint max; + uint h; + + 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; +} |