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 bridge_map.cpp Map accessor functions for bridges. */
11 #include "landscape.h"
12 #include "tunnelbridge_map.h"
14 #include "safeguards.h"
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
);
29 } while (!IsBridgeTile(tile
) || GetTunnelBridgeDirection(tile
) != dir
);
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
))));
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
)));
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
));
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
)
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
);