summaryrefslogtreecommitdiff
path: root/tile.c
diff options
context:
space:
mode:
Diffstat (limited to 'tile.c')
-rw-r--r--tile.c42
1 files changed, 15 insertions, 27 deletions
diff --git a/tile.c b/tile.c
index 98fb5f0bd..ba6900a36 100644
--- a/tile.c
+++ b/tile.c
@@ -3,37 +3,14 @@
#include "stdafx.h"
#include "tile.h"
-/** 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
-*/
-Slope GetTileh(uint n, uint w, uint e, uint s, uint *h)
-{
- uint min = n;
- Slope r;
-
- if (min >= w) min = w;
- if (min >= e) min = e;
- if (min >= s) min = s;
-
- r = SLOPE_FLAT;
- if ((n -= min) != 0) r += (--n << 4) + SLOPE_N;
- if ((e -= min) != 0) r += (--e << 4) + SLOPE_E;
- if ((s -= min) != 0) r += (--s << 4) + SLOPE_S;
- if ((w -= min) != 0) r += (--w << 4) + SLOPE_W;
-
- if (h != NULL) *h = min * TILE_HEIGHT;
-
- return r;
-}
-
Slope GetTileSlope(TileIndex tile, uint *h)
{
uint a;
uint b;
uint c;
uint d;
+ uint min;
+ uint r;
assert(tile < MapSize());
@@ -42,12 +19,23 @@ Slope GetTileSlope(TileIndex tile, uint *h)
return 0;
}
- a = TileHeight(tile);
+ 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;
- return GetTileh(a, b, c, d, h);
+ if (h != NULL) *h = min * TILE_HEIGHT;
+
+ return r;
}
uint GetTileZ(TileIndex tile)