1 /* $Id$ */ |
1 /* $Id$ */ |
2 |
2 |
3 #include "stdafx.h" |
3 #include "stdafx.h" |
4 #include "tile.h" |
4 #include "tile.h" |
5 |
|
6 /** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile |
|
7 * @param n,w,e,s the four corners |
|
8 * @param h uint pointer to write the height to |
|
9 * @return the tileh |
|
10 */ |
|
11 Slope GetTileh(uint n, uint w, uint e, uint s, uint *h) |
|
12 { |
|
13 uint min = n; |
|
14 Slope r; |
|
15 |
|
16 if (min >= w) min = w; |
|
17 if (min >= e) min = e; |
|
18 if (min >= s) min = s; |
|
19 |
|
20 r = SLOPE_FLAT; |
|
21 if ((n -= min) != 0) r += (--n << 4) + SLOPE_N; |
|
22 if ((e -= min) != 0) r += (--e << 4) + SLOPE_E; |
|
23 if ((s -= min) != 0) r += (--s << 4) + SLOPE_S; |
|
24 if ((w -= min) != 0) r += (--w << 4) + SLOPE_W; |
|
25 |
|
26 if (h != NULL) *h = min * TILE_HEIGHT; |
|
27 |
|
28 return r; |
|
29 } |
|
30 |
5 |
31 Slope GetTileSlope(TileIndex tile, uint *h) |
6 Slope GetTileSlope(TileIndex tile, uint *h) |
32 { |
7 { |
33 uint a; |
8 uint a; |
34 uint b; |
9 uint b; |
35 uint c; |
10 uint c; |
36 uint d; |
11 uint d; |
|
12 uint min; |
|
13 uint r; |
37 |
14 |
38 assert(tile < MapSize()); |
15 assert(tile < MapSize()); |
39 |
16 |
40 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
17 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
41 if (h != NULL) *h = 0; |
18 if (h != NULL) *h = 0; |
42 return 0; |
19 return 0; |
43 } |
20 } |
44 |
21 |
45 a = TileHeight(tile); |
22 min = a = TileHeight(tile); |
46 b = TileHeight(tile + TileDiffXY(1, 0)); |
23 b = TileHeight(tile + TileDiffXY(1, 0)); |
|
24 if (min >= b) min = b; |
47 c = TileHeight(tile + TileDiffXY(0, 1)); |
25 c = TileHeight(tile + TileDiffXY(0, 1)); |
|
26 if (min >= c) min = c; |
48 d = TileHeight(tile + TileDiffXY(1, 1)); |
27 d = TileHeight(tile + TileDiffXY(1, 1)); |
|
28 if (min >= d) min = d; |
49 |
29 |
50 return GetTileh(a, b, c, d, h); |
30 r = SLOPE_FLAT; |
|
31 if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; |
|
32 if ((c -= min) != 0) r += (--c << 4) + SLOPE_E; |
|
33 if ((d -= min) != 0) r += (--d << 4) + SLOPE_S; |
|
34 if ((b -= min) != 0) r += (--b << 4) + SLOPE_W; |
|
35 |
|
36 if (h != NULL) *h = min * TILE_HEIGHT; |
|
37 |
|
38 return r; |
51 } |
39 } |
52 |
40 |
53 uint GetTileZ(TileIndex tile) |
41 uint GetTileZ(TileIndex tile) |
54 { |
42 { |
55 uint h; |
43 uint h; |