1 /* $Id$ */ |
|
2 |
|
3 /** @file tile.cpp */ |
|
4 |
|
5 #include "stdafx.h" |
|
6 #include "tile.h" |
|
7 |
|
8 Slope GetTileSlope(TileIndex tile, uint *h) |
|
9 { |
|
10 uint a; |
|
11 uint b; |
|
12 uint c; |
|
13 uint d; |
|
14 uint min; |
|
15 uint r; |
|
16 |
|
17 assert(tile < MapSize()); |
|
18 |
|
19 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
|
20 if (h != NULL) *h = 0; |
|
21 return SLOPE_FLAT; |
|
22 } |
|
23 |
|
24 min = a = TileHeight(tile); |
|
25 b = TileHeight(tile + TileDiffXY(1, 0)); |
|
26 if (min > b) min = b; |
|
27 c = TileHeight(tile + TileDiffXY(0, 1)); |
|
28 if (min > c) min = c; |
|
29 d = TileHeight(tile + TileDiffXY(1, 1)); |
|
30 if (min > d) min = d; |
|
31 |
|
32 r = SLOPE_FLAT; |
|
33 if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; |
|
34 if ((c -= min) != 0) r += (--c << 4) + SLOPE_E; |
|
35 if ((d -= min) != 0) r += (--d << 4) + SLOPE_S; |
|
36 if ((b -= min) != 0) r += (--b << 4) + SLOPE_W; |
|
37 |
|
38 if (h != NULL) *h = min * TILE_HEIGHT; |
|
39 |
|
40 return (Slope)r; |
|
41 } |
|
42 |
|
43 uint GetTileZ(TileIndex tile) |
|
44 { |
|
45 if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0; |
|
46 |
|
47 uint h = TileHeight(tile); |
|
48 h = min(h, TileHeight(tile + TileDiffXY(1, 0))); |
|
49 h = min(h, TileHeight(tile + TileDiffXY(0, 1))); |
|
50 h = min(h, TileHeight(tile + TileDiffXY(1, 1))); |
|
51 |
|
52 return h * TILE_HEIGHT; |
|
53 } |
|
54 |
|
55 |
|
56 uint GetTileMaxZ(TileIndex t) |
|
57 { |
|
58 if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0; |
|
59 |
|
60 uint h = TileHeight(t); |
|
61 h = max(h, TileHeight(t + TileDiffXY(1, 0))); |
|
62 h = max(h, TileHeight(t + TileDiffXY(0, 1))); |
|
63 h = max(h, TileHeight(t + TileDiffXY(1, 1))); |
|
64 |
|
65 return h * TILE_HEIGHT; |
|
66 } |
|