OpenTTD Source 20241224-master-gf74b0cf984
bridge.h File Reference

Header file for bridges. More...

#include "gfx_type.h"
#include "tile_cmd.h"
#include "timer/timer_game_calendar.h"

Go to the source code of this file.

Data Structures

struct  BridgeSpec
 Struct containing information about a single bridge type. More...
 

Typedefs

typedef uint BridgeType
 Bridge spec number.
 

Enumerations

enum  BridgePieces {
  BRIDGE_PIECE_NORTH = 0 , BRIDGE_PIECE_SOUTH , BRIDGE_PIECE_INNER_NORTH , BRIDGE_PIECE_INNER_SOUTH ,
  BRIDGE_PIECE_MIDDLE_ODD , BRIDGE_PIECE_MIDDLE_EVEN , BRIDGE_PIECE_HEAD , NUM_BRIDGE_PIECES
}
 This enum is related to the definition of bridge pieces, which is used to determine the proper sprite table to use while drawing a given bridge part. More...
 

Functions

Foundation GetBridgeFoundation (Slope tileh, Axis axis)
 Get the foundation for a bridge.
 
bool HasBridgeFlatRamp (Slope tileh, Axis axis)
 Determines if the track on a bridge ramp is flat or goes up/down.
 
const BridgeSpecGetBridgeSpec (BridgeType i)
 Get the specification of a bridge type.
 
void DrawBridgeMiddle (const TileInfo *ti)
 Draw the middle bits of a bridge.
 
CommandCost CheckBridgeAvailability (BridgeType bridge_type, uint bridge_len, DoCommandFlag flags=DC_NONE)
 Is a bridge of the specified type and length available?
 
int CalcBridgeLenCostFactor (int x)
 Calculate the price factor for building a long bridge.
 
void ResetBridges ()
 Reset the data been eventually changed by the grf loaded.
 

Variables

static const uint MAX_BRIDGES = 13
 Maximal number of available bridge specs.
 
constexpr uint SPRITES_PER_BRIDGE_PIECE = 32
 Number of sprites there are per bridge piece.
 
BridgeSpec _bridge [MAX_BRIDGES]
 The specification of all bridges.
 

Detailed Description

Header file for bridges.

Definition in file bridge.h.

Typedef Documentation

◆ BridgeType

typedef uint BridgeType

Bridge spec number.

Definition at line 38 of file bridge.h.

Enumeration Type Documentation

◆ BridgePieces

This enum is related to the definition of bridge pieces, which is used to determine the proper sprite table to use while drawing a given bridge part.

Definition at line 22 of file bridge.h.

Function Documentation

◆ CalcBridgeLenCostFactor()

int CalcBridgeLenCostFactor ( int  length)

Calculate the price factor for building a long bridge.

Basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8,

Parameters
lengthLength of the bridge.
Returns
Price factor for the bridge.

Definition at line 108 of file tunnelbridge_cmd.cpp.

Referenced by CmdBuildBridge(), and ShowBuildBridgeWindow().

◆ CheckBridgeAvailability()

CommandCost CheckBridgeAvailability ( BridgeType  bridge_type,
uint  bridge_len,
DoCommandFlag  flags 
)

Is a bridge of the specified type and length available?

Parameters
bridge_typeWanted type of bridge.
bridge_lenWanted length of the bridge.
flagsType of operation.
Returns
A succeeded (the requested bridge is available) or failed (it cannot be built) command.

Definition at line 200 of file tunnelbridge_cmd.cpp.

References _settings_game, BridgeSpec::avail_year, CMD_ERROR, GameSettings::construction, DC_QUERY_COST, GetBridgeSpec(), ConstructionSettings::max_bridge_length, MAX_BRIDGES, BridgeSpec::max_length, BridgeSpec::min_length, and TimerGameCalendar::year.

Referenced by CmdBuildBridge(), and ShowBuildBridgeWindow().

◆ DrawBridgeMiddle()

◆ GetBridgeFoundation()

Foundation GetBridgeFoundation ( Slope  tileh,
Axis  axis 
)

Get the foundation for a bridge.

Parameters
tilehThe slope to build the bridge on.
axisThe axis of the bridge entrance.
Returns
The foundation required.

Definition at line 129 of file tunnelbridge_cmd.cpp.

References AXIS_X, AXIS_Y, FlatteningFoundation(), FOUNDATION_NONE, HasSlopeHighestCorner(), InclinedFoundation(), SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by CheckBridgeSlope(), DrawRailCatenaryRailway(), DrawTile_TunnelBridge(), GetBridgeHeight(), and HasBridgeFlatRamp().

◆ GetBridgeSpec()

const BridgeSpec * GetBridgeSpec ( BridgeType  i)
inline

Get the specification of a bridge type.

Parameters
iThe type of bridge to get the specification for.
Returns
The specification.

Definition at line 67 of file bridge.h.

References _bridge, and lengthof.

Referenced by CheckBridgeAvailability(), CmdBuildBridge(), DrawBridgeMiddle(), RoadVehicle::GetCurrentMaxSpeed(), Train::GetCurrentMaxSpeed(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::GetSpeedLimit(), and ShowBuildBridgeWindow().

◆ HasBridgeFlatRamp()

bool HasBridgeFlatRamp ( Slope  tileh,
Axis  axis 
)

Determines if the track on a bridge ramp is flat or goes up/down.

Parameters
tilehSlope of the tile under the bridge head
axisOrientation of bridge
Returns
true iff the track is flat.

Definition at line 145 of file tunnelbridge_cmd.cpp.

References ApplyFoundationToSlope(), GetBridgeFoundation(), and SLOPE_FLAT.

Referenced by DrawTile_TunnelBridge(), and CYapfCostBase::stSlopeCost().

◆ ResetBridges()

void ResetBridges ( )

Reset the data been eventually changed by the grf loaded.

Definition at line 86 of file tunnelbridge_cmd.cpp.

References _bridge, free(), and MAX_BRIDGES.

Referenced by ResetNewGRFData().

Variable Documentation

◆ _bridge

BridgeSpec _bridge[MAX_BRIDGES]
extern

The specification of all bridges.

Definition at line 52 of file tunnelbridge_cmd.cpp.

Referenced by BridgeChangeInfo(), GetBridgeSpec(), and ResetBridges().

◆ MAX_BRIDGES

const uint MAX_BRIDGES = 13
static

Maximal number of available bridge specs.

Definition at line 35 of file bridge.h.

Referenced by BridgeChangeInfo(), CheckBridgeAvailability(), GrowTownWithBridge(), ResetBridges(), and ShowBuildBridgeWindow().

◆ SPRITES_PER_BRIDGE_PIECE

constexpr uint SPRITES_PER_BRIDGE_PIECE = 32
constexpr

Number of sprites there are per bridge piece.

Definition at line 36 of file bridge.h.

Referenced by BridgeChangeInfo().