OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

tunnel_map.cpp
Go to the documentation of this file.
1 /* $Id: tunnel_map.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
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/>.
8 */
9
12 #include "stdafx.h"
13 #include "tunnelbridge_map.h"
14
15 #include "safeguards.h"
16
17
24 TileIndex GetOtherTunnelEnd(TileIndex tile)
25 {
26 DiagDirection dir = GetTunnelBridgeDirection(tile);
27 TileIndexDiff delta = TileOffsByDiagDir(dir);
28 int z = GetTileZ(tile);
29
30 dir = ReverseDiagDir(dir);
31 do {
32 tile += delta;
33 } while (
34 !IsTunnelTile(tile) ||
35 GetTunnelBridgeDirection(tile) != dir ||
36 GetTileZ(tile) != z
37 );
38
39 return tile;
40 }
41
42
50 bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
51 {
52 TileIndexDiff delta = TileOffsByDiagDir(dir);
53 int height;
54
55 do {
56 tile -= delta;
57 if (!IsValidTile(tile)) return false;
58 height = GetTileZ(tile);
59 } while (z < height);
60
61 return z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir;
62 }
63
70 bool IsTunnelInWay(TileIndex tile, int z)
71 {
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);
74 }