4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file tunnel_map.cpp Map accessors for tunnels. */
13 #include "tunnelbridge_map.h"
15 #include "safeguards.h"
19 * Gets the other end of the tunnel. Where a vehicle would reappear when it
20 * enters at the given tile.
21 * @param tile the tile to search from.
22 * @return the tile of the other end of the tunnel.
24 TileIndex
GetOtherTunnelEnd(TileIndex tile
)
26 DiagDirection dir
= GetTunnelBridgeDirection(tile
);
27 TileIndexDiff delta
= TileOffsByDiagDir(dir
);
28 int z
= GetTileZ(tile
);
30 dir
= ReverseDiagDir(dir
);
34 !IsTunnelTile(tile
) ||
35 GetTunnelBridgeDirection(tile
) != dir
||
44 * Is there a tunnel in the way in the given direction?
45 * @param tile the tile to search from.
46 * @param z the 'z' to search on.
47 * @param dir the direction to start searching to.
48 * @return true if and only if there is a tunnel.
50 bool IsTunnelInWayDir(TileIndex tile
, int z
, DiagDirection dir
)
52 TileIndexDiff delta
= TileOffsByDiagDir(dir
);
57 if (!IsValidTile(tile
)) return false;
58 height
= GetTileZ(tile
);
61 return z
== height
&& IsTunnelTile(tile
) && GetTunnelBridgeDirection(tile
) == dir
;
65 * Is there a tunnel in the way in any direction?
66 * @param tile the tile to search from.
67 * @param z the 'z' to search on.
68 * @return true if and only if there is a tunnel.
70 bool IsTunnelInWay(TileIndex tile
, int z
)
72 return IsTunnelInWayDir(tile
, z
, (TileX(tile
) > (MapMaxX() / 2)) ? DIAGDIR_NE
: DIAGDIR_SW
) ||
73 IsTunnelInWayDir(tile
, z
, (TileY(tile
) > (MapMaxY() / 2)) ? DIAGDIR_NW
: DIAGDIR_SE
);