(svn r27950) -Merge: Documentation updates from 1.7 branch
[openttd.git] / src / bridge_map.cpp
blobd1e0d6024aea269c8fcfcd3c5eb197ac985f241e
1 /* $Id$ */
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 */
10 /** @file bridge_map.cpp Map accessor functions for bridges. */
12 #include "stdafx.h"
13 #include "landscape.h"
14 #include "tunnelbridge_map.h"
16 #include "safeguards.h"
19 /**
20 * Finds the end of a bridge in the specified direction starting at a middle tile
21 * @param tile the bridge tile to find the bridge ramp for
22 * @param dir the direction to search in
24 static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
26 TileIndexDiff delta = TileOffsByDiagDir(dir);
28 dir = ReverseDiagDir(dir);
29 do {
30 tile += delta;
31 } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir);
33 return tile;
37 /**
38 * Finds the northern end of a bridge starting at a middle tile
39 * @param t the bridge tile to find the bridge ramp for
41 TileIndex GetNorthernBridgeEnd(TileIndex t)
43 return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
47 /**
48 * Finds the southern end of a bridge starting at a middle tile
49 * @param t the bridge tile to find the bridge ramp for
51 TileIndex GetSouthernBridgeEnd(TileIndex t)
53 return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
57 /**
58 * Starting at one bridge end finds the other bridge end
59 * @param t the bridge ramp tile to find the other bridge ramp for
61 TileIndex GetOtherBridgeEnd(TileIndex tile)
63 assert(IsBridgeTile(tile));
64 return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile));
67 /**
68 * Get the height ('z') of a bridge.
69 * @param tile the bridge ramp tile to get the bridge height from
70 * @return the height of the bridge.
72 int GetBridgeHeight(TileIndex t)
74 int h;
75 Slope tileh = GetTileSlope(t, &h);
76 Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
78 /* one height level extra for the ramp */
79 return h + 1 + ApplyFoundationToSlope(f, &tileh);