OpenTTD Source: src/bridge_map.cpp Source File

OpenTTD Source 15.3

bridge_map.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "landscape.h"
12#include "tunnelbridge_map.h"
13
14#include "safeguards.h"
15
16
22 static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
23{
24 TileIndexDiff delta = TileOffsByDiagDir(dir);
25
26 dir = ReverseDiagDir(dir);
27 do {
28 tile += delta;
29 } while (!IsBridgeTile(tile) || GetTunnelBridgeDirection(tile) != dir);
30
31 return tile;
32}
33
34
39 TileIndex GetNorthernBridgeEnd(TileIndex t)
40{
41 return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
42}
43
44
49 TileIndex GetSouthernBridgeEnd(TileIndex t)
50{
51 return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
52}
53
54
59 TileIndex GetOtherBridgeEnd(TileIndex tile)
60{
61 assert(IsBridgeTile(tile));
62 return GetBridgeEnd(tile, GetTunnelBridgeDirection(tile));
63}
64
70 int GetBridgeHeight(TileIndex t)
71{
72 auto [tileh, h] = GetTileSlopeZ(t);
73 Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
74
75 /* one height level extra for the ramp */
76 return h + 1 + ApplyFoundationToSlope(f, tileh);
77}
GetBridgeFoundation
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
Definition tunnelbridge_cmd.cpp:115
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition bridge_map.cpp:49
GetBridgeEnd
static TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
Finds the end of a bridge in the specified direction starting at a middle tile.
Definition bridge_map.cpp:22
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition bridge_map.cpp:59
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition bridge_map.cpp:39
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Definition bridge_map.cpp:70
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
GetBridgeAxis
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
Definition bridge_map.h:68
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition direction_func.h:118
AxisToDiagDir
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition direction_func.h:232
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition direction_func.h:214
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition landscape.cpp:174
landscape.h
Functions related to OTTD's landscape.
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:583
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
safeguards.h
A number of safeguards to prevent using unsafe methods.
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetTileSlopeZ
std::tuple< Slope, int > GetTileSlopeZ(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.cpp:55
tunnelbridge_map.h
Functions that have tunnels and bridges in common.
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition tunnelbridge_map.h:26