author | KUDr |
Fri, 20 Apr 2007 19:43:06 +0000 | |
changeset 6513 | 454347ca3dfb |
parent 6422 | 6679df1c05ba |
child 7323 | 20a18eb8efaf |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6422
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
5587
diff
changeset
|
3 |
/** @file tile.cpp */ |
6679df1c05ba
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
5587
diff
changeset
|
4 |
|
1213
fc87a2ee4161
(svn r1717) -Fix: some compilation problems for braindead VS6 and added missing files to project (thx bociusz)
darkvater
parents:
1211
diff
changeset
|
5 |
#include "stdafx.h" |
1211 | 6 |
#include "tile.h" |
7 |
||
3636
a36cc46e754d
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3422
diff
changeset
|
8 |
Slope GetTileSlope(TileIndex tile, uint *h) |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
9 |
{ |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
10 |
uint a; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
11 |
uint b; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
12 |
uint c; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
13 |
uint d; |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
14 |
uint min; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
15 |
uint r; |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
16 |
|
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
17 |
assert(tile < MapSize()); |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
18 |
|
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
19 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
20 |
if (h != NULL) *h = 0; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
21 |
return SLOPE_FLAT; |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
22 |
} |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
23 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
24 |
min = a = TileHeight(tile); |
1981 | 25 |
b = TileHeight(tile + TileDiffXY(1, 0)); |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
26 |
if (min >= b) min = b; |
1981 | 27 |
c = TileHeight(tile + TileDiffXY(0, 1)); |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
28 |
if (min >= c) min = c; |
1981 | 29 |
d = TileHeight(tile + TileDiffXY(1, 1)); |
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
30 |
if (min >= d) min = d; |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
31 |
|
4067
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
32 |
r = SLOPE_FLAT; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
33 |
if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
34 |
if ((c -= min) != 0) r += (--c << 4) + SLOPE_E; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
35 |
if ((d -= min) != 0) r += (--d << 4) + SLOPE_S; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
36 |
if ((b -= min) != 0) r += (--b << 4) + SLOPE_W; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
37 |
|
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
38 |
if (h != NULL) *h = min * TILE_HEIGHT; |
5ef297943eff
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
39 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
40 |
return (Slope)r; |
1335
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
41 |
} |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
42 |
|
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
43 |
uint GetTileZ(TileIndex tile) |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
44 |
{ |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
45 |
uint h; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
46 |
GetTileSlope(tile, &h); |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
47 |
return h; |
a5f223b9f549
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
48 |
} |
3773
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
49 |
|
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
50 |
|
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
51 |
uint GetTileMaxZ(TileIndex t) |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
52 |
{ |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
53 |
uint max; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
54 |
uint h; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
55 |
|
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
56 |
h = TileHeight(t); |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
57 |
max = h; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
58 |
h = TileHeight(t + TileDiffXY(1, 0)); |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
59 |
if (h > max) max = h; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
60 |
h = TileHeight(t + TileDiffXY(0, 1)); |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
61 |
if (h > max) max = h; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
62 |
h = TileHeight(t + TileDiffXY(1, 1)); |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
63 |
if (h > max) max = h; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
64 |
return max * 8; |
0019b5f70ea9
(svn r4765) Add GetTileMaxZ(), which returns the height of the highest corner of a tile, and use it to simplify the code in a few places
tron
parents:
3636
diff
changeset
|
65 |
} |