author | truebrain |
Fri, 18 Jul 2008 10:15:16 +0000 | |
branch | noai |
changeset 11168 | 3842648184cd |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
9723 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9724
diff
changeset
|
3 |
/** @file tile_map.cpp Global tile accessors. */ |
9723 | 4 |
|
5 |
#include "stdafx.h" |
|
6 |
#include "openttd.h" |
|
7 |
#include "tile_map.h" |
|
8 |
#include "core/math_func.hpp" |
|
9 |
||
10 |
Slope GetTileSlope(TileIndex tile, uint *h) |
|
11 |
{ |
|
12 |
uint a; |
|
13 |
uint b; |
|
14 |
uint c; |
|
15 |
uint d; |
|
16 |
uint min; |
|
17 |
uint r; |
|
18 |
||
19 |
assert(tile < MapSize()); |
|
20 |
||
21 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
|
22 |
if (h != NULL) *h = 0; |
|
23 |
return SLOPE_FLAT; |
|
24 |
} |
|
25 |
||
26 |
min = a = TileHeight(tile); |
|
27 |
b = TileHeight(tile + TileDiffXY(1, 0)); |
|
28 |
if (min > b) min = b; |
|
29 |
c = TileHeight(tile + TileDiffXY(0, 1)); |
|
30 |
if (min > c) min = c; |
|
31 |
d = TileHeight(tile + TileDiffXY(1, 1)); |
|
32 |
if (min > d) min = d; |
|
33 |
||
34 |
r = SLOPE_FLAT; |
|
35 |
if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; |
|
36 |
if ((c -= min) != 0) r += (--c << 4) + SLOPE_E; |
|
37 |
if ((d -= min) != 0) r += (--d << 4) + SLOPE_S; |
|
38 |
if ((b -= min) != 0) r += (--b << 4) + SLOPE_W; |
|
39 |
||
40 |
if (h != NULL) *h = min * TILE_HEIGHT; |
|
41 |
||
42 |
return (Slope)r; |
|
43 |
} |
|
44 |
||
45 |
uint GetTileZ(TileIndex tile) |
|
46 |
{ |
|
47 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0; |
|
48 |
||
49 |
uint h = TileHeight(tile); |
|
50 |
h = min(h, TileHeight(tile + TileDiffXY(1, 0))); |
|
51 |
h = min(h, TileHeight(tile + TileDiffXY(0, 1))); |
|
52 |
h = min(h, TileHeight(tile + TileDiffXY(1, 1))); |
|
53 |
||
54 |
return h * TILE_HEIGHT; |
|
55 |
} |
|
56 |
||
57 |
||
58 |
uint GetTileMaxZ(TileIndex t) |
|
59 |
{ |
|
60 |
if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0; |
|
61 |
||
62 |
uint h = TileHeight(t); |
|
63 |
h = max(h, TileHeight(t + TileDiffXY(1, 0))); |
|
64 |
h = max(h, TileHeight(t + TileDiffXY(0, 1))); |
|
65 |
h = max(h, TileHeight(t + TileDiffXY(1, 1))); |
|
66 |
||
67 |
return h * TILE_HEIGHT; |
|
68 |
} |