author | KUDr |
Sat, 21 Apr 2007 08:23:57 +0000 | |
branch | cpp_gui |
changeset 6308 | 646711c5feaa |
parent 6307 | f40e88cff863 |
child 7498 | ce6588257e8d |
permissions | -rw-r--r-- |
3154 | 1 |
/* $Id$ */ |
2 |
||
6307 | 3 |
/** @file tunnel_map.cpp */ |
4 |
||
3154 | 5 |
#include "stdafx.h" |
6 |
#include "openttd.h" |
|
7 |
#include "tile.h" |
|
8 |
#include "tunnel_map.h" |
|
9 |
||
6308 | 10 |
/** |
11 |
* Gets the other end of the tunnel. Where a vehicle would reappear when it |
|
12 |
* enters at the given tile. |
|
13 |
* @param tile the tile to search from. |
|
14 |
* @return the tile of the other end of the tunnel. |
|
15 |
*/ |
|
3154 | 16 |
TileIndex GetOtherTunnelEnd(TileIndex tile) |
17 |
{ |
|
18 |
DiagDirection dir = GetTunnelDirection(tile); |
|
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4291
diff
changeset
|
19 |
TileIndexDiff delta = TileOffsByDiagDir(dir); |
3154 | 20 |
uint z = GetTileZ(tile); |
21 |
||
22 |
dir = ReverseDiagDir(dir); |
|
23 |
do { |
|
24 |
tile += delta; |
|
25 |
} 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
|
26 |
!IsTunnelTile(tile) || |
3154 | 27 |
GetTunnelDirection(tile) != dir || |
28 |
GetTileZ(tile) != z |
|
29 |
); |
|
30 |
||
31 |
return tile; |
|
32 |
} |
|
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
|
33 |
|
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
|
34 |
|
6308 | 35 |
/** |
36 |
* Is there a tunnel in the way in the given direction? |
|
37 |
* @param tile the tile to search from. |
|
38 |
* @param z the 'z' to search on. |
|
39 |
* @param dir the direction to start searching to. |
|
40 |
* @return true if and only if there is a tunnel. |
|
41 |
*/ |
|
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
|
42 |
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
|
43 |
{ |
4559
c853d2440065
(svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents:
4291
diff
changeset
|
44 |
TileIndexDiff delta = TileOffsByDiagDir(dir); |
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
|
45 |
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
|
46 |
|
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
} 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
|
51 |
|
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
} |
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 |
|
6308 | 58 |
/** |
59 |
* Is there a tunnel in the way in any direction? |
|
60 |
* @param tile the tile to search from. |
|
61 |
* @param z the 'z' to search on. |
|
62 |
* @return true if and only if there is a tunnel. |
|
63 |
*/ |
|
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
|
64 |
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
|
65 |
{ |
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 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
} |