2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file tunnel_map.cpp Map accessors for tunnels. */
11 #include "tunnelbridge_map.h"
13 #include "safeguards.h"
17 * Gets the other end of the tunnel. Where a vehicle would reappear when it
18 * enters at the given tile.
19 * @param tile the tile to search from.
20 * @return the tile of the other end of the tunnel.
22 TileIndex
GetOtherTunnelEnd(TileIndex tile
)
24 DiagDirection dir
= GetTunnelBridgeDirection(tile
);
25 TileIndexDiff delta
= TileOffsByDiagDir(dir
);
26 int z
= GetTileZ(tile
);
28 dir
= ReverseDiagDir(dir
);
32 !IsTunnelTile(tile
) ||
33 GetTunnelBridgeDirection(tile
) != dir
||
42 * Is there a tunnel in the way in the given direction?
43 * @param tile the tile to search from.
44 * @param z the 'z' to search on.
45 * @param dir the direction to start searching to.
46 * @return true if and only if there is a tunnel.
48 bool IsTunnelInWayDir(TileIndex tile
, int z
, DiagDirection dir
)
50 TileIndexDiff delta
= TileOffsByDiagDir(dir
);
55 if (!IsValidTile(tile
)) return false;
56 height
= GetTileZ(tile
);
59 return z
== height
&& IsTunnelTile(tile
) && GetTunnelBridgeDirection(tile
) == dir
;
63 * Is there a tunnel in the way in any direction?
64 * @param tile the tile to search from.
65 * @param z the 'z' to search on.
66 * @return true if and only if there is a tunnel.
68 bool IsTunnelInWay(TileIndex tile
, int z
)
70 return IsTunnelInWayDir(tile
, z
, (TileX(tile
) > (MapMaxX() / 2)) ? DIAGDIR_NE
: DIAGDIR_SW
) ||
71 IsTunnelInWayDir(tile
, z
, (TileY(tile
) > (MapMaxY() / 2)) ? DIAGDIR_NW
: DIAGDIR_SE
);