author | skidd13 |
Sun, 15 Jun 2008 15:48:33 +0000 | |
changeset 10967 | fb9a80b89ea4 |
parent 10429 | 1b99254f9607 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8844
diff
changeset
|
3 |
/** @file tile_map.cpp Global tile accessors. */ |
6918
5589c415e28f
(svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents:
5838
diff
changeset
|
4 |
|
1213
bb9906f67932
(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" |
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7820
diff
changeset
|
6 |
#include "openttd.h" |
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7820
diff
changeset
|
7 |
#include "tile_map.h" |
8609
8c0c3e9dd6a0
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
8604
diff
changeset
|
8 |
#include "core/math_func.hpp" |
1211 | 9 |
|
3636
d87b21df2944
(svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents:
3422
diff
changeset
|
10 |
Slope GetTileSlope(TileIndex tile, uint *h) |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
11 |
{ |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
12 |
uint a; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
13 |
uint b; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
14 |
uint c; |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
15 |
uint d; |
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
16 |
uint min; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
17 |
uint r; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
18 |
|
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
19 |
assert(tile < MapSize()); |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
20 |
|
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
21 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) { |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
22 |
if (h != NULL) *h = 0; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
23 |
return SLOPE_FLAT; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
24 |
} |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
25 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
26 |
min = a = TileHeight(tile); |
1981 | 27 |
b = TileHeight(tile + TileDiffXY(1, 0)); |
7819
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
28 |
if (min > b) min = b; |
1981 | 29 |
c = TileHeight(tile + TileDiffXY(0, 1)); |
7819
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
30 |
if (min > c) min = c; |
1981 | 31 |
d = TileHeight(tile + TileDiffXY(1, 1)); |
7819
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
32 |
if (min > d) min = d; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
33 |
|
4067
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
34 |
r = SLOPE_FLAT; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
35 |
if ((a -= min) != 0) r += (--a << 4) + SLOPE_N; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
36 |
if ((c -= min) != 0) r += (--c << 4) + SLOPE_E; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
37 |
if ((d -= min) != 0) r += (--d << 4) + SLOPE_S; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
38 |
if ((b -= min) != 0) r += (--b << 4) + SLOPE_W; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
39 |
|
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
40 |
if (h != NULL) *h = min * TILE_HEIGHT; |
ab047dec0733
(svn r5363) Revert 5312, 5288, 5248, 3992, 3249, 3228
tron
parents:
3773
diff
changeset
|
41 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
42 |
return (Slope)r; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
43 |
} |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
44 |
|
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
45 |
uint GetTileZ(TileIndex tile) |
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
46 |
{ |
7819
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
47 |
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0; |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
48 |
|
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
49 |
uint h = TileHeight(tile); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
50 |
h = min(h, TileHeight(tile + TileDiffXY(1, 0))); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
51 |
h = min(h, TileHeight(tile + TileDiffXY(0, 1))); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
52 |
h = min(h, TileHeight(tile + TileDiffXY(1, 1))); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
53 |
|
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
54 |
return h * TILE_HEIGHT; |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1213
diff
changeset
|
55 |
} |
3773
996897ffc8ea
(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 |
|
996897ffc8ea
(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 |
|
996897ffc8ea
(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 |
uint GetTileMaxZ(TileIndex t) |
996897ffc8ea
(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 |
{ |
7820
f642e46e7f6b
(svn r10687) -Fix (r10686): subversion does not like it when you change code when you are typing the commit message.
rubidium
parents:
7819
diff
changeset
|
60 |
if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0; |
3773
996897ffc8ea
(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 |
|
7819
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
62 |
uint h = TileHeight(t); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
63 |
h = max(h, TileHeight(t + TileDiffXY(1, 0))); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
64 |
h = max(h, TileHeight(t + TileDiffXY(0, 1))); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
65 |
h = max(h, TileHeight(t + TileDiffXY(1, 1))); |
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
66 |
|
694a7dacd30a
(svn r10686) -Fix [FS#1058]: determining whether there is a tunnel going under the lowered area is only needed in two directions instead of all four, so take the directions (one for each axis) to the nearest border (along the given axis). Furthermore GetTileZ did much more than absolutely necessary.
rubidium
parents:
6918
diff
changeset
|
67 |
return h * TILE_HEIGHT; |
3773
996897ffc8ea
(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
|
68 |
} |