Add: INR currency (#8136)
[openttd-github.git] / src / bridge_map.cpp
blobeb286738677e10e76cbcfccea8bbd3e44eba59fb
1 /*
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/>.
6 */
8 /** @file bridge_map.cpp Map accessor functions for bridges. */
10 #include "stdafx.h"
11 #include "landscape.h"
12 #include "tunnelbridge_map.h"
14 #include "safeguards.h"
17 /**
18 * Finds the end of a bridge in the specified direction starting at a middle tile
19 * @param tile the bridge tile to find the bridge ramp for
20 * @param dir the direction to search in
22 static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
24 TileIndexDiff delta = TileOffsByDiagDir(dir);
26 dir = ReverseDiagDir(dir);
27 do {
28 tile += delta;
29 } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir);
31 return tile;
35 /**
36 * Finds the northern end of a bridge starting at a middle tile
37 * @param t the bridge tile to find the bridge ramp for
39 TileIndex GetNorthernBridgeEnd(TileIndex t)
41 return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
45 /**
46 * Finds the southern end of a bridge starting at a middle tile
47 * @param t the bridge tile to find the bridge ramp for
49 TileIndex GetSouthernBridgeEnd(TileIndex t)
51 return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
55 /**
56 * Starting at one bridge end finds the other bridge end
57 * @param tile the bridge ramp tile to find the other bridge ramp for
59 TileIndex GetOtherBridgeEnd(TileIndex tile)
61 assert(IsBridgeTile(tile));
62 return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile));
65 /**
66 * Get the height ('z') of a bridge.
67 * @param t the bridge ramp tile to get the bridge height from
68 * @return the height of the bridge.
70 int GetBridgeHeight(TileIndex t)
72 int h;
73 Slope tileh = GetTileSlope(t, &h);
74 Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
76 /* one height level extra for the ramp */
77 return h + 1 + ApplyFoundationToSlope(f, &tileh);