author | tron |
Wed, 16 Aug 2006 06:05:44 +0000 | |
changeset 4290 | 2d6895dc84eb |
parent 3184 | 7405329343ce |
child 4291 | c0e769957f8b |
permissions | -rw-r--r-- |
3154 | 1 |
/* $Id$ */ |
2 |
||
3 |
#include "stdafx.h" |
|
4 |
#include "openttd.h" |
|
5 |
#include "tile.h" |
|
6 |
#include "tunnel_map.h" |
|
4290
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
7 |
#include "vehicle.h" |
3154 | 8 |
|
9 |
TileIndex GetOtherTunnelEnd(TileIndex tile) |
|
10 |
{ |
|
11 |
DiagDirection dir = GetTunnelDirection(tile); |
|
12 |
TileIndexDiff delta = TileOffsByDir(dir); |
|
13 |
uint z = GetTileZ(tile); |
|
14 |
||
15 |
dir = ReverseDiagDir(dir); |
|
16 |
do { |
|
17 |
tile += delta; |
|
18 |
} while ( |
|
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3156
diff
changeset
|
19 |
!IsTunnelTile(tile) || |
3154 | 20 |
GetTunnelDirection(tile) != dir || |
21 |
GetTileZ(tile) != z |
|
22 |
); |
|
23 |
||
24 |
return tile; |
|
25 |
} |
|
3156
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
26 |
|
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
27 |
|
4290
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
28 |
/** Retrieve the exit-tile of the vehicle from inside a tunnel |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
29 |
* Very similar to GetOtherTunnelEnd(), but we use the vehicle's |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
30 |
* direction for determining which end of the tunnel to find |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
31 |
* @param v the vehicle which is inside the tunnel and needs an exit |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
32 |
* @return the exit-tile of the tunnel based on the vehicle's direction */ |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
33 |
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v) |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
34 |
{ |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
35 |
TileIndex tile = TileVirtXY(v->x_pos, v->y_pos); |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
36 |
DiagDirection dir = DirToDiagDir(v->direction); |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
37 |
TileIndexDiff delta = TileOffsByDir(dir); |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
38 |
uint z = v->z_pos; |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
39 |
|
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
40 |
dir = ReverseDiagDir(dir); |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
41 |
while ( |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
42 |
!IsTunnelTile(tile) || |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
43 |
GetTunnelDirection(tile) != dir || |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
44 |
GetTileZ(tile) != z |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
45 |
) { |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
46 |
tile += delta; |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
47 |
} |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
48 |
|
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
49 |
return tile; |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
50 |
} |
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
51 |
|
2d6895dc84eb
(svn r5923) Fix 'make depend' which was broken in r3574 (it just did nothing)
tron
parents:
3184
diff
changeset
|
52 |
|
3156
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
53 |
static bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir) |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
54 |
{ |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
55 |
TileIndexDiff delta = TileOffsByDir(dir); |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
56 |
uint height; |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
57 |
|
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
58 |
do { |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
59 |
tile -= delta; |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
60 |
height = GetTileZ(tile); |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
61 |
} while (z < height); |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
62 |
|
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
63 |
return |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
64 |
z == height && |
3184
7405329343ce
(svn r3830) Move IsTunnelTile() from tile.h to tunnel_map.h and add IsTunnel(), which just checks for a tunnel, but not the tile type as IsTunnelTile() does
tron
parents:
3156
diff
changeset
|
65 |
IsTunnelTile(tile) && |
3156
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
66 |
GetTunnelDirection(tile) == dir; |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
67 |
} |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
68 |
|
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
69 |
bool IsTunnelInWay(TileIndex tile, uint z) |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
70 |
{ |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
71 |
return |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
72 |
IsTunnelInWayDir(tile, z, DIAGDIR_NE) || |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
73 |
IsTunnelInWayDir(tile, z, DIAGDIR_SE) || |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
74 |
IsTunnelInWayDir(tile, z, DIAGDIR_SW) || |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
75 |
IsTunnelInWayDir(tile, z, DIAGDIR_NW); |
028b6756b279
(svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents:
3154
diff
changeset
|
76 |
} |