OpenTTD Source 20260311-master-g511d3794ce
tunnelbridge_cmd.cpp File Reference

This file deals with tunnels and bridges (non-gui stuff). More...

#include "stdafx.h"
#include "viewport_func.h"
#include "command_func.h"
#include "town.h"
#include "train.h"
#include "ship.h"
#include "roadveh.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "newgrf_sound.h"
#include "autoslope.h"
#include "tunnelbridge_map.h"
#include "strings_func.h"
#include "timer/timer_game_calendar.h"
#include "clear_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "tunnelbridge.h"
#include "cheat_type.h"
#include "elrail_func.h"
#include "pbs.h"
#include "company_base.h"
#include "newgrf_railtype.h"
#include "newgrf_roadtype.h"
#include "object_base.h"
#include "water.h"
#include "company_gui.h"
#include "tunnelbridge_cmd.h"
#include "landscape_cmd.h"
#include "terraform_cmd.h"
#include "table/strings.h"
#include "table/bridge_land.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

void MarkBridgeDirty (TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
 Mark bridge tiles dirty.
void MarkBridgeDirty (TileIndex tile)
 Mark bridge tiles dirty.
void ResetBridges ()
 Reset the data been eventually changed by the grf loaded.
int CalcBridgeLenCostFactor (int length)
 Calculate the price factor for building a long bridge.
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.
static bool BridgeHasCustomSpriteTable (BridgeType bridge_type, BridgePieces piece)
 Test if bridge piece uses a custom sprite table.
static std::span< const PalSpriteIDGetBridgeSpriteTable (BridgeType bridge_type, BridgePieces piece)
 Get the sprite table for a rail/road bridge piece.
static uint8_t GetBridgeSpriteTableBaseOffset (TransportType transport_type, TileIndex ramp)
 Get the sprite table transport type base offset for a rail/road bridge.
static uint8_t GetBridgeRampDirectionBaseOffset (DiagDirection diagdir)
 Get bridge sprite table base offset for the ramp part of bridge.
static uint8_t GetBridgeMiddleAxisBaseOffset (Axis axis)
 Get bridge sprite table base offset for the middle part of bridge.
static CommandCost CheckBridgeSlope (BridgePieces bridge_piece, Axis axis, Slope &tileh, int &z)
 Determines the foundation for the bridge head, and tests if the resulting slope is valid.
CommandCost CheckBridgeAvailability (BridgeType bridge_type, uint bridge_len, DoCommandFlags flags)
 Is a bridge of the specified type and length available?
static Money TunnelBridgeClearCost (TileIndex tile, Price base_price)
 Calculate the base cost of clearing a tunnel/bridge per tile.
static CommandCost CheckBuildAbove (TileIndex tile, DoCommandFlags flags, Axis axis, int height)
CommandCost CmdBuildBridge (DoCommandFlags flags, TileIndex tile_end, TileIndex tile_start, TransportType transport_type, BridgeType bridge_type, uint8_t road_rail_type)
 Build a Bridge.
CommandCost CmdBuildTunnel (DoCommandFlags flags, TileIndex start_tile, TransportType transport_type, uint8_t road_rail_type)
 Build Tunnel.
static CommandCost CheckAllowRemoveTunnelBridge (TileIndex tile)
 Are we allowed to remove the tunnel or bridge at tile?
static CommandCost DoClearTunnel (TileIndex tile, DoCommandFlags flags)
 Remove a tunnel from the game, update town rating, etc.
static CommandCost DoClearBridge (TileIndex tile, DoCommandFlags flags)
 Remove a bridge from the game, update town rating, etc.
static CommandCost ClearTile_TunnelBridge (TileIndex tile, DoCommandFlags flags)
 Tile callback function signature for clearing a tile.
static void DrawPillar (const PalSpriteID &psid, int x, int y, int z, uint8_t w, uint8_t h, const SubSprite *subsprite)
 Draw a single pillar sprite.
static int DrawPillarColumn (int z_bottom, int z_top, const PalSpriteID &psid, int x, int y, int w, int h)
 Draw two bridge pillars (north and south).
static void DrawBridgePillars (const PalSpriteID &psid, const TileInfo *ti, Axis axis, bool drawfarpillar, int x, int y, int z_bridge)
 Draws the pillars under high bridges.
static void GetBridgeRoadCatenary (const RoadTypeInfo *rti, TileIndex head_tile, int offset, bool head, SpriteID &spr_back, SpriteID &spr_front)
 Retrieve the sprites required for catenary on a road/tram bridge.
static void DrawBridgeRoadBits (TileIndex head_tile, int x, int y, int z, int offset, bool head, bool is_custom_layout)
 Draws the road and trambits over an already drawn (lower end) of a bridge.
static void DrawTile_TunnelBridge (TileInfo *ti)
 Tile callback function signature for drawing a tile and its contents to the screen.
static BridgePieces CalcBridgePiece (uint north, uint south)
 Compute bridge piece.
static BridgePillarFlags GetBridgeTilePillarFlags (TileIndex tile, TileIndex rampnorth, TileIndex rampsouth, BridgeType type, TransportType transport_type)
 Get pillar information for a bridge middle tile.
void DrawBridgeMiddle (const TileInfo *ti, BridgePillarFlags blocked_pillars)
 Draw the middle bits of a bridge.
static int GetSlopePixelZ_TunnelBridge (TileIndex tile, uint x, uint y, bool ground_vehicle)
 Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
static Foundation GetFoundation_TunnelBridge (TileIndex tile, Slope tileh)
 Tile callback function signature for getting the foundation of a tile.
static void GetTileDesc_TunnelBridge (TileIndex tile, TileDesc &td)
 Tile callback function signature for obtaining a tile description.
static void TileLoop_TunnelBridge (TileIndex tile)
 Tile callback function signature for running periodic tile updates.
static TrackStatus GetTileTrackStatus_TunnelBridge (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 Tile callback function signature for getting the possible tracks that can be taken on a given tile by a given transport.
static void ChangeTileOwner_TunnelBridge (TileIndex tile, Owner old_owner, Owner new_owner)
 Tile callback function signature for changing the owner of a tile.
template<typename T>
static void PrepareToEnterBridge (T *gv)
 Helper to prepare the ground vehicle when entering a bridge.
static VehicleEnterTileStates VehicleEnterTile_TunnelBridge (Vehicle *v, TileIndex tile, int x, int y)
 Tile callback function for a vehicle entering a tile.
static CommandCost TerraformTile_TunnelBridge (TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
 Tile callback function signature of the terraforming callback.
static CommandCost CheckBuildAbove_TunnelBridge (TileIndex tile, DoCommandFlags flags, Axis axis, int height)
 Tile callback function signature to test if a bridge can be built above a tile.

Variables

BridgeSpec _bridge [MAX_BRIDGES]
 The specification of all bridges.
TileIndex _build_tunnel_endtile
 The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
static const int BRIDGE_Z_START = 3
 Z position of the bridge sprites relative to bridge height (downwards).
static const uint8_t TUNNEL_SOUND_FRAME = 1
 Frame when the 'enter tunnel' sound should be played.
const uint8_t _tunnel_visibility_frame [DIAGDIR_END] = {12, 8, 8, 12}
 Frame when a vehicle should be hidden in a tunnel with a certain direction.
const TileTypeProcs _tile_type_tunnelbridge_procs
 TileTypeProcs definitions for TileType::TunnelBridge tiles.

Detailed Description

This file deals with tunnels and bridges (non-gui stuff).

Todo
separate this file into two.

Definition in file tunnelbridge_cmd.cpp.

Function Documentation

◆ BridgeHasCustomSpriteTable()

bool BridgeHasCustomSpriteTable ( BridgeType bridge_type,
BridgePieces piece )
static

Test if bridge piece uses a custom sprite table.

Parameters
bridge_typeBridge type.
pieceBridge piece.
Returns
True iff a custom sprite table is used for the bridge piece.

Definition at line 143 of file tunnelbridge_cmd.cpp.

References GetBridgeSpec(), and BridgeSpec::sprite_table.

Referenced by DrawBridgeMiddle(), and DrawTile_TunnelBridge().

◆ 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 93 of file tunnelbridge_cmd.cpp.

Referenced by CmdBuildBridge(), and ShowBuildBridgeWindow().

◆ CalcBridgePiece()

BridgePieces CalcBridgePiece ( uint north,
uint south )
static

Compute bridge piece.

Computes the bridge piece to display depending on the position inside the bridge. bridges pieces sequence (middle parts). Note that it is not covering the bridge heads, which are always referenced by the same sprite table. bridge len 1: BRIDGE_PIECE_NORTH bridge len 2: BRIDGE_PIECE_NORTH BRIDGE_PIECE_SOUTH bridge len 3: BRIDGE_PIECE_NORTH BRIDGE_PIECE_MIDDLE_ODD BRIDGE_PIECE_SOUTH bridge len 4: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH bridge len 5: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_MIDDLE_EVEN BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH bridge len 6: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH bridge len 7: BRIDGE_PIECE_NORTH BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_MIDDLE_ODD BRIDGE_PIECE_INNER_NORTH BRIDGE_PIECE_INNER_SOUTH BRIDGE_PIECE_SOUTH #0 - always as first, #1 - always as last (if len>1) #2,#3 are to pair in order for odd bridges: #5 is going in the bridge middle if on even position, #4 on odd (counting from 0)

Parameters
northNorthernmost tile of bridge
southSouthernmost tile of bridge
Returns
Index of bridge piece

Definition at line 1566 of file tunnelbridge_cmd.cpp.

Referenced by DrawBridgeMiddle(), and GetBridgeTilePillarFlags().

◆ ChangeTileOwner_TunnelBridge()

void ChangeTileOwner_TunnelBridge ( TileIndex tile,
Owner old_owner,
Owner new_owner )
static

◆ CheckAllowRemoveTunnelBridge()

CommandCost CheckAllowRemoveTunnelBridge ( TileIndex tile)
inlinestatic

Are we allowed to remove the tunnel or bridge at tile?

Parameters
tileEnd point of the tunnel or bridge.
Returns
A succeeded command if the tunnel or bridge may be removed, a failed command otherwise.

Definition at line 821 of file tunnelbridge_cmd.cpp.

References _cheats, _current_company, _settings_game, CheckOwnership(), CheckTileOwnership(), GetRoadOwner(), GetRoadTypeRoad(), GetRoadTypeTram(), GetTileOwner(), GetTunnelBridgeTransportType(), INVALID_ROADTYPE, OWNER_NONE, OWNER_TOWN, OWNER_WATER, RTT_ROAD, RTT_TRAM, CommandCost::Succeeded(), TRANSPORT_RAIL, TRANSPORT_ROAD, and TRANSPORT_WATER.

Referenced by DoClearBridge(), and DoClearTunnel().

◆ CheckBridgeAvailability()

CommandCost CheckBridgeAvailability ( BridgeType bridge_type,
uint bridge_len,
DoCommandFlags 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 239 of file tunnelbridge_cmd.cpp.

References _settings_game, BridgeSpec::avail_year, CMD_ERROR, GetBridgeSpec(), MAX_BRIDGES, BridgeSpec::max_length, BridgeSpec::min_length, QueryCost, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TimerGameCalendar::year.

Referenced by CmdBuildBridge(), and ShowBuildBridgeWindow().

◆ CheckBridgeSlope()

CommandCost CheckBridgeSlope ( BridgePieces bridge_piece,
Axis axis,
Slope & tileh,
int & z )
static

Determines the foundation for the bridge head, and tests if the resulting slope is valid.

Parameters
bridge_pieceDirection of the bridge head.
axisAxis of the bridge
tilehSlope of the tile under the north bridge head; returns slope on top of foundation
zTileZ corresponding to tileh, gets modified as well
Returns
Error or cost for bridge foundation

Definition at line 212 of file tunnelbridge_cmd.cpp.

References _price, ApplyFoundationToSlope(), AXIS_X, BuildFoundation, CMD_ERROR, EXPENSES_CONSTRUCTION, FOUNDATION_NONE, GetBridgeFoundation(), SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by CmdBuildBridge(), and TerraformTile_TunnelBridge().

◆ CheckBuildAbove()

CommandCost CheckBuildAbove ( TileIndex tile,
DoCommandFlags flags,
Axis axis,
int height )
static

Definition at line 291 of file tunnelbridge_cmd.cpp.

◆ CheckBuildAbove_TunnelBridge()

CommandCost CheckBuildAbove_TunnelBridge ( TileIndex tile,
DoCommandFlags flags,
Axis axis,
int height )
static

Tile callback function signature to test if a bridge can be built above a tile.

Parameters
tileThe involved tile.
flagsCommand flags passed to the build command.
axisAxis of bridge being built.
heightAbsolute height of bridge platform.
Returns
Error code or extra cost for building bridge above the tile.
See also
CheckBuildAbove

Definition at line 2132 of file tunnelbridge_cmd.cpp.

References DiagDirToAxis(), GetBridgeHeight(), GetTunnelBridgeDirection(), and IsTunnel().

◆ ClearTile_TunnelBridge()

CommandCost ClearTile_TunnelBridge ( TileIndex tile,
DoCommandFlags flags )
static

Tile callback function signature for clearing a tile.

Parameters
tileThe tile to clear.
flagsThe command flags.
Returns
The cost or error.
See also
ClearTile

Definition at line 1035 of file tunnelbridge_cmd.cpp.

References Auto, DoClearBridge(), DoClearTunnel(), IsTunnel(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

◆ CmdBuildBridge()

CommandCost CmdBuildBridge ( DoCommandFlags flags,
TileIndex tile_end,
TileIndex tile_start,
TransportType transport_type,
BridgeType bridge_type,
uint8_t road_rail_type )

Build a Bridge.

Parameters
flagstype of operation
tile_endend tile
tile_startstart tile
transport_typetransport type.
bridge_typebridge type (hi bh)
road_rail_typerail type or road types.
Returns
the cost of this operation or an error

Definition at line 310 of file tunnelbridge_cmd.cpp.

References _current_company, _local_company, _price, _settings_game, CommandCost::AddCost(), AddSideToSignalBuffer(), AXIS_X, AXIS_Y, AxisToDiagDir(), AxisToTrack(), BuildAqueduct, BuildBridge, Town::cache, CalcBridgeLenCostFactor(), CalcClosestTownFromTile(), ChangeTownRating(), CheckBridgeAvailability(), CheckBridgeSlope(), CheckForDockingTile(), ClearBridge, ClosestTownFromTile(), CMD_ERROR, CommandCostWithParam(), DirtyCompanyInfrastructureWindows(), DistanceSquare(), Execute, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetBridgeAxis(), GetBridgeHeight(), GetBridgeSpec(), GetBridgeType(), CommandCost::GetCost(), GetNorthernBridgeEnd(), GetOtherBridgeEnd(), GetRailType(), GetRoadOwner(), GetRoadTypeRoad(), GetRoadTypeTram(), GetTileMaxZ(), GetTileOwner(), GetTileSlopeZ(), GetTileZ(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasTunnelBridgeReservation(), Company::infrastructure, INVALID_DIAGDIR, INVALID_RAILTYPE, INVALID_ROADTYPE, CompanyProperties::is_ai, IsBridgeAbove(), IsBridgeTile(), IsTileOwner(), IsValidTile(), MakeAqueductBridgeRamp(), MakeRailBridgeRamp(), MakeRoadBridgeRamp(), MarkBridgeDirty(), OWNER_DEITY, OWNER_NONE, OWNER_TOWN, QueryCost, CompanyInfrastructure::rail, RailBuildCost(), RATING_TUNNEL_BRIDGE_UP_STEP, ReverseDiagDir(), CompanyInfrastructure::road, RoadBuildCost(), RTT_ROAD, RTT_TRAM, SetBridgeMiddle(), SetTunnelBridgeReservation(), SLOPE_FLAT, TownCache::squared_town_zone_radius, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileDiffXY(), TileOffsByAxis(), TileX(), TileY(), to_underlying(), TownEdge, TRANSPORT_RAIL, TRANSPORT_ROAD, TRANSPORT_WATER, TUNNELBRIDGE_TRACKBIT_FACTOR, TunnelBridgeClearCost(), ValParamRailType(), ValParamRoadType(), CompanyInfrastructure::water, Town::xy, and YapfNotifyTrackLayoutChange().

◆ CmdBuildTunnel()

CommandCost CmdBuildTunnel ( DoCommandFlags flags,
TileIndex start_tile,
TransportType transport_type,
uint8_t road_rail_type )

◆ DoClearBridge()

◆ DoClearTunnel()

◆ DrawBridgeMiddle()

◆ DrawBridgePillars()

void DrawBridgePillars ( const PalSpriteID & psid,
const TileInfo * ti,
Axis axis,
bool drawfarpillar,
int x,
int y,
int z_bridge )
static

Draws the pillars under high bridges.

Parameters
psidImage and palette of a bridge pillar.
tiTileInfo of current bridge-middle-tile.
axisOrientation of bridge.
drawfarpillarWhether to draw the pillar at the back
xSprite X position of front pillar.
ySprite Y position of front pillar.
z_bridgeAbsolute height of bridge bottom.

< bounding box size of pillars along bridge direction

< sprite position offset of back facing pillar

< big number compared to sprite size

Definition at line 1093 of file tunnelbridge_cmd.cpp.

References AxisToDiagDir(), DrawPillar(), DrawPillarColumn(), GetSlopePixelZOnEdge(), INF, OtherAxis(), ReverseDiagDir(), PalSpriteID::sprite, TILE_HEIGHT, TileInfo::tileh, and Coord3D< T >::z.

◆ DrawBridgeRoadBits()

void DrawBridgeRoadBits ( TileIndex head_tile,
int x,
int y,
int z,
int offset,
bool head,
bool is_custom_layout )
static

Draws the road and trambits over an already drawn (lower end) of a bridge.

Parameters
head_tilebridge head tile with roadtype information
xthe x of the bridge
ythe y of the bridge
zthe z of the bridge
offsetsprite offset identifying flat to sloped bridge tiles
headare we drawing bridge head?
is_custom_layoutSet if the bridge uses a custom sprite layout.

Definition at line 1176 of file tunnelbridge_cmd.cpp.

References AddSortableSpriteToDraw(), EndSpriteCombine(), GetBridgeRoadCatenary(), GetCustomRoadSprite(), GetRoadTypeInfo(), GetRoadTypeRoad(), GetRoadTypeTram(), HasRoadCatenaryDrawn(), INVALID_ROADTYPE, IsInvisibilitySet(), IsTransparencySet(), lengthof, ROTSG_BRIDGE, ROTSG_OVERLAY, StartSpriteCombine(), TCX_NORMAL, TCX_ON_BRIDGE, TILE_SIZE, TO_BRIDGES, and TO_CATENARY.

Referenced by DrawBridgeMiddle(), and DrawTile_TunnelBridge().

◆ DrawPillar()

void DrawPillar ( const PalSpriteID & psid,
int x,
int y,
int z,
uint8_t w,
uint8_t h,
const SubSprite * subsprite )
inlinestatic

Draw a single pillar sprite.

Parameters
psidPillarsprite
xPillar X
yPillar Y
zPillar Z
wBounding box size in X direction
hBounding box size in Y direction
subspriteOptional subsprite for drawing halfpillars

< Start offset of pillar wrt. bridge (downwards)

Definition at line 1056 of file tunnelbridge_cmd.cpp.

References AddSortableSpriteToDraw(), BRIDGE_Z_START, PalSpriteID::pal, PalSpriteID::sprite, and TILE_HEIGHT.

Referenced by DrawBridgePillars(), and DrawPillarColumn().

◆ DrawPillarColumn()

int DrawPillarColumn ( int z_bottom,
int z_top,
const PalSpriteID & psid,
int x,
int y,
int w,
int h )
static

Draw two bridge pillars (north and south).

Parameters
z_bottomBottom Z
z_topTop Z
psidPillarsprite
xPillar X
yPillar Y
wBounding box size in X direction
hBounding box size in Y direction
Returns
Reached Z at the bottom

Definition at line 1073 of file tunnelbridge_cmd.cpp.

References DrawPillar(), and TILE_HEIGHT.

Referenced by DrawBridgePillars().

◆ DrawTile_TunnelBridge()

void DrawTile_TunnelBridge ( TileInfo * ti)
static

Tile callback function signature for drawing a tile and its contents to the screen.

Parameters
tiInformation about the tile to draw

Draws a tunnel of bridge tile. For tunnels, this is rather simple, as you only need to draw the entrance. Bridges are a bit more complex. base_offset is where the sprite selection comes into play and it works a bit like a bitmask.

For bridge heads:

  • Bit 0: direction
  • Bit 1: northern or southern heads
  • Bit 2: Set if the bridge head is sloped
  • Bit 3 and more: Railtype Specific subset

Please note that in this code, "roads" are treated as railtype 1, whilst the real railtypes are 0, 2 and 3

Definition at line 1288 of file tunnelbridge_cmd.cpp.

References _aqueduct_sprite_table_heads, _settings_client, AddSortableSpriteToDraw(), AXIS_X, RailTypeInfo::base_sprites, BB_Z_SEPARATOR, RailTypeInfo::bridge_deck, BridgeHasCustomSpriteTable(), DIAGDIR_END, DiagDirToAxis(), DrawBridgeMiddle(), DrawBridgeRoadBits(), DrawFoundation(), DrawGroundSprite(), DrawRailCatenary(), DrawRailCatenaryOnTunnel(), DrawRoadOverlays(), EdgeNE, EndSpriteCombine(), GetBridgeFoundation(), GetBridgeRampDirectionBaseOffset(), GetBridgeSpriteTable(), GetBridgeSpriteTableBaseOffset(), GetBridgeType(), GetCustomRailSprite(), GetCustomRoadSprite(), GetRailType(), GetRailTypeInfo(), GetRoadTypeInfo(), GetRoadTypeRoad(), GetRoadTypeTram(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), GetWaterClass(), HasBridgeFlatRamp(), HasRailCatenaryDrawn(), HasRoadCatenaryDrawn(), HasTileWaterClass(), HasTunnelBridgeReservation(), HasTunnelBridgeSnowOrDesert(), INVALID_ROADTYPE, IsTransparencySet(), IsTunnel(), PALETTE_CRASH, ROTSG_CATENARY_FRONT, ROTSG_TUNNEL, RTBO_SLOPE, RTBO_X, RTBO_Y, RTO_SLOPE_NE, RTO_X, RTSG_BRIDGE, RTSG_OVERLAY, RTSG_TUNNEL, RTSG_TUNNEL_PORTAL, Sea, RailTypeInfo::single_sloped, RailTypeInfo::single_x, RailTypeInfo::single_y, SLOPE_FLAT, SlopeToSpriteOffset(), SPR_RAILTYPE_TUNNEL_BASE, StartSpriteCombine(), TileInfo::tile, TILE_HEIGHT, TILE_SIZE, TileInfo::tileh, TileOffsByDiagDir(), TO_CATENARY, TRANSPORT_RAIL, TRANSPORT_ROAD, TRANSPORT_WATER, RailTypeInfo::tunnel, Coord3D< T >::x, Coord3D< T >::y, and Coord3D< T >::z.

◆ 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 114 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(), GetFoundation_TunnelBridge(), GetSlopePixelZ_TunnelBridge(), and HasBridgeFlatRamp().

◆ GetBridgeMiddleAxisBaseOffset()

uint8_t GetBridgeMiddleAxisBaseOffset ( Axis axis)
static

Get bridge sprite table base offset for the middle part of bridge.

Parameters
axisAxis of bridge.
Returns
Offset for axis.

Definition at line 198 of file tunnelbridge_cmd.cpp.

References AXIS_X.

Referenced by DrawBridgeMiddle().

◆ GetBridgeRampDirectionBaseOffset()

uint8_t GetBridgeRampDirectionBaseOffset ( DiagDirection diagdir)
static

Get bridge sprite table base offset for the ramp part of bridge.

Parameters
diagdirDirection of ramp.
Returns
Offset for direction.

Definition at line 186 of file tunnelbridge_cmd.cpp.

References DIAGDIR_END.

Referenced by DrawTile_TunnelBridge().

◆ GetBridgeRoadCatenary()

void GetBridgeRoadCatenary ( const RoadTypeInfo * rti,
TileIndex head_tile,
int offset,
bool head,
SpriteID & spr_back,
SpriteID & spr_front )
static

Retrieve the sprites required for catenary on a road/tram bridge.

Parameters
rtiRoadTypeInfo for the road or tram type to get catenary for
head_tileBridge head tile with roadtype information
offsetSprite offset identifying flat to sloped bridge tiles
headAre we drawing bridge head?
[out]spr_backBack catenary sprite to use
[out]spr_frontFront catenary sprite to use

Definition at line 1149 of file tunnelbridge_cmd.cpp.

References GetCustomRoadSprite(), ROTSG_CATENARY_BACK, ROTSG_CATENARY_FRONT, SPR_TRAMWAY_BASE, TCX_NORMAL, and TCX_ON_BRIDGE.

Referenced by DrawBridgeRoadBits().

◆ GetBridgeSpriteTable()

std::span< const PalSpriteID > GetBridgeSpriteTable ( BridgeType bridge_type,
BridgePieces piece )
static

Get the sprite table for a rail/road bridge piece.

Parameters
bridge_typeBridge type.
pieceBridge piece.
Returns
Sprite table for the bridge piece.

Definition at line 156 of file tunnelbridge_cmd.cpp.

References GetBridgeSpec(), and BridgeSpec::sprite_table.

Referenced by DrawBridgeMiddle(), and DrawTile_TunnelBridge().

◆ GetBridgeSpriteTableBaseOffset()

uint8_t GetBridgeSpriteTableBaseOffset ( TransportType transport_type,
TileIndex ramp )
static

Get the sprite table transport type base offset for a rail/road bridge.

Parameters
transport_typeTransport type of bridge.
rampTile of bridge ramp.
Returns
Offset for transport type.

Definition at line 172 of file tunnelbridge_cmd.cpp.

References RailTypeInfo::bridge_offset, GetRailType(), GetRailTypeInfo(), TRANSPORT_RAIL, and TRANSPORT_ROAD.

Referenced by DrawBridgeMiddle(), and DrawTile_TunnelBridge().

◆ GetBridgeTilePillarFlags()

BridgePillarFlags GetBridgeTilePillarFlags ( TileIndex tile,
TileIndex rampnorth,
TileIndex rampsouth,
BridgeType type,
TransportType transport_type )
static

Get pillar information for a bridge middle tile.

Parameters
tileTile of bridge middle.
rampnorthNorthern ramp tile of bridge.
rampsouthSouthern ramp tile of bridge.
typeBridge type.
transport_typeTransport type of bridge.
Returns
Pillar flags for bridge middle.

Definition at line 1590 of file tunnelbridge_cmd.cpp.

References AXIS_X, AXIS_Y, CalcBridgePiece(), BridgeSpec::ctrl_flags, GetBridgeSpec(), GetTunnelBridgeLength(), BridgeSpec::InvalidPillarFlags, BridgeSpec::pillar_flags, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileX(), and TRANSPORT_WATER.

Referenced by DrawBridgeMiddle().

◆ GetFoundation_TunnelBridge()

Foundation GetFoundation_TunnelBridge ( TileIndex tile,
Slope tileh )
static

Tile callback function signature for getting the foundation of a tile.

Parameters
tileThe tile to check.
tilehThe current slope.
Returns
The foundation that will be used.

Definition at line 1758 of file tunnelbridge_cmd.cpp.

References DiagDirToAxis(), FOUNDATION_NONE, GetBridgeFoundation(), GetTunnelBridgeDirection(), and IsTunnel().

◆ GetSlopePixelZ_TunnelBridge()

int GetSlopePixelZ_TunnelBridge ( TileIndex tile,
uint x,
uint y,
bool ground_vehicle )
static

Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.

Parameters
tileThe queries tile for the Z coordinate.
xWorld X coordinate in tile "units".
yWorld Y coordinate in tile "units".
ground_vehicleWhether to get the Z coordinate of the ground vehicle, or the ground.
Returns
World Z coordinate at tile ground (vehicle) level, including slopes and foundations.
See also
GetSlopePixelZ

Definition at line 1726 of file tunnelbridge_cmd.cpp.

References ApplyPixelFoundationToSlope(), DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), GetBridgeFoundation(), GetPartialPixelZ(), GetTilePixelSlope(), GetTunnelBridgeDirection(), IsTunnel(), SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, SLOPE_SW, and TILE_HEIGHT.

◆ GetTileDesc_TunnelBridge()

◆ GetTileTrackStatus_TunnelBridge()

TrackStatus GetTileTrackStatus_TunnelBridge ( TileIndex tile,
TransportType mode,
uint sub_mode,
DiagDirection side )
static

Tile callback function signature for getting the possible tracks that can be taken on a given tile by a given transport.

The return value contains the existing trackdirs and signal states.

see track_func.h for usage of TrackStatus.

Parameters
tilethe tile to get the track status from
modethe mode of transportation
sub_modeused to differentiate between different kinds within the mode
sideThe side where the tile is entered.
Returns
the track status information
See also
GetTileTrackStatus

Definition at line 1860 of file tunnelbridge_cmd.cpp.

References CombineTrackStatus(), DiagDirToDiagTrackBits(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), HasTileRoadType(), INVALID_DIAGDIR, ReverseDiagDir(), TrackBitsToTrackdirBits(), TRACKDIR_BIT_NONE, and TRANSPORT_ROAD.

◆ 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 130 of file tunnelbridge_cmd.cpp.

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

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

◆ MarkBridgeDirty() [1/2]

void MarkBridgeDirty ( TileIndex begin,
TileIndex end,
DiagDirection direction,
uint bridge_height )

Mark bridge tiles dirty.

Note: The bridge does not need to exist, everything is passed via parameters.

Parameters
beginStart tile.
endEnd tile.
directionDirection from begin to end.
bridge_heightBridge height level.

Definition at line 63 of file tunnelbridge_cmd.cpp.

References MarkTileDirtyByTile(), TileHeight(), and TileOffsByDiagDir().

Referenced by ClearPathReservation(), CmdBuildBridge(), CmdBuildRoad(), CmdConvertRail(), CmdConvertRoad(), MarkBridgeDirty(), RemoveRoad(), TryReserveRailTrack(), and UnreserveRailTrack().

◆ MarkBridgeDirty() [2/2]

void MarkBridgeDirty ( TileIndex tile)

Mark bridge tiles dirty.

Parameters
tileBridge head.

Definition at line 76 of file tunnelbridge_cmd.cpp.

References GetBridgeHeight(), GetOtherTunnelBridgeEnd(), GetTunnelBridgeDirection(), and MarkBridgeDirty().

◆ PrepareToEnterBridge()

template<typename T>
void PrepareToEnterBridge ( T * gv)
static

Helper to prepare the ground vehicle when entering a bridge.

This get called when entering the bridge, at the last frame of travel on the bridge head. Our calling function gets called before UpdateInclination/UpdateZPosition, which normally controls the Z-coordinate. However, in the wormhole of the bridge the vehicle is in a strange state so UpdateInclination does not get called for the wormhole of the bridge and as such the going up/down bits would remain set. As such, this function clears those. In doing so, the call to UpdateInclination will not update the Z-coordinate, so that has to be done here as well.

Parameters
gvThe ground vehicle entering the bridge.

Definition at line 1938 of file tunnelbridge_cmd.cpp.

References ClrBit(), GVF_GOINGDOWN_BIT, GVF_GOINGUP_BIT, HasBit(), and T.

Referenced by VehicleEnterTile_TunnelBridge().

◆ ResetBridges()

void ResetBridges ( )

Reset the data been eventually changed by the grf loaded.

Definition at line 82 of file tunnelbridge_cmd.cpp.

References _bridge.

Referenced by ResetNewGRFData().

◆ TerraformTile_TunnelBridge()

CommandCost TerraformTile_TunnelBridge ( TileIndex tile,
DoCommandFlags flags,
int z_new,
Slope tileh_new )
static

Tile callback function signature of the terraforming callback.

The function is called when a tile is affected by a terraforming operation. It has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype. With DoCommandFlag::Execute in flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself).

Note
The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation.
Parameters
tileThe involved tile.
flagsCommand flags passed to the terraform command (DoCommandFlag::Execute, DoCommandFlag::QueryCost, etc.).
z_newTileZ after terraforming.
tileh_newSlope after terraforming.
Returns
Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.)
See also
TerraformTile

Definition at line 2107 of file tunnelbridge_cmd.cpp.

References _price, _settings_game, AutoslopeEnabled(), BuildFoundation, CheckBridgeSlope(), DIAGDIR_NE, DIAGDIR_NW, DiagDirToAxis(), EXPENSES_CONSTRUCTION, GetTileSlopeZ(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), IsBridge(), CommandCost::Succeeded(), and TRANSPORT_WATER.

◆ TileLoop_TunnelBridge()

void TileLoop_TunnelBridge ( TileIndex tile)
static

Tile callback function signature for running periodic tile updates.

Parameters
tileThe tile to update.
See also
RunTileLoop

Definition at line 1831 of file tunnelbridge_cmd.cpp.

References _settings_game, Arctic, GetSnowLine(), GetTileMaxZ(), GetTileZ(), GetTropicZone(), HasTunnelBridgeSnowOrDesert(), IsBridge(), MarkTileDirtyByTile(), SetTunnelBridgeSnowOrDesert(), Tropic, and TROPICZONE_DESERT.

◆ TunnelBridgeClearCost()

Money TunnelBridgeClearCost ( TileIndex tile,
Price base_price )
static

Calculate the base cost of clearing a tunnel/bridge per tile.

Parameters
tileStart tile of the tunnel/bridge.
base_priceThe base cost for clearing the tile.
Returns
How much clearing this tunnel/bridge costs per tile.

Definition at line 264 of file tunnelbridge_cmd.cpp.

References _price, ClearAqueduct, GetRailType(), GetRoadTypeRoad(), GetRoadTypeTram(), GetTunnelBridgeTransportType(), INVALID_ROADTYPE, RailClearCost(), RoadClearCost(), TRANSPORT_RAIL, TRANSPORT_ROAD, and TRANSPORT_WATER.

Referenced by CmdBuildBridge(), DoClearBridge(), and DoClearTunnel().

◆ VehicleEnterTile_TunnelBridge()

Variable Documentation

◆ _bridge

The specification of all bridges.

Definition at line 48 of file tunnelbridge_cmd.cpp.

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

◆ _build_tunnel_endtile

TileIndex _build_tunnel_endtile

The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.

Definition at line 49 of file tunnelbridge_cmd.cpp.

Referenced by CcBuildRailTunnel(), CcBuildRoadTunnel(), CmdBuildTunnel(), DoClearTunnel(), BuildRailToolbarWindow::OnPlacePresize(), and BuildRoadToolbarWindow::OnPlacePresize().

◆ _tile_type_tunnelbridge_procs

const TileTypeProcs _tile_type_tunnelbridge_procs
extern
Initial value:
= {
.draw_tile_proc = DrawTile_TunnelBridge,
.get_slope_pixel_z_proc = GetSlopePixelZ_TunnelBridge,
.clear_tile_proc = ClearTile_TunnelBridge,
.get_tile_desc_proc = GetTileDesc_TunnelBridge,
.get_tile_track_status_proc = GetTileTrackStatus_TunnelBridge,
.tile_loop_proc = TileLoop_TunnelBridge,
.change_tile_owner_proc = ChangeTileOwner_TunnelBridge,
.vehicle_enter_tile_proc = VehicleEnterTile_TunnelBridge,
.get_foundation_proc = GetFoundation_TunnelBridge,
.terraform_tile_proc = TerraformTile_TunnelBridge,
.check_build_above_proc = CheckBuildAbove_TunnelBridge,
}
static Foundation GetFoundation_TunnelBridge(TileIndex tile, Slope tileh)
Tile callback function signature for getting the foundation of a tile.
static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc &td)
Tile callback function signature for obtaining a tile description.
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlags flags)
Tile callback function signature for clearing a tile.
static int GetSlopePixelZ_TunnelBridge(TileIndex tile, uint x, uint y, bool ground_vehicle)
Tile callback function signature for obtaining the world Z coordinate of a given point of a tile.
static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner new_owner)
Tile callback function signature for changing the owner of a tile.
static CommandCost CheckBuildAbove_TunnelBridge(TileIndex tile, DoCommandFlags flags, Axis axis, int height)
Tile callback function signature to test if a bridge can be built above a tile.
static VehicleEnterTileStates VehicleEnterTile_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
Tile callback function for a vehicle entering a tile.
static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Tile callback function signature for getting the possible tracks that can be taken on a given tile by...
static void DrawTile_TunnelBridge(TileInfo *ti)
Tile callback function signature for drawing a tile and its contents to the screen.
static CommandCost TerraformTile_TunnelBridge(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
Tile callback function signature of the terraforming callback.
static void TileLoop_TunnelBridge(TileIndex tile)
Tile callback function signature for running periodic tile updates.

TileTypeProcs definitions for TileType::TunnelBridge tiles.

Definition at line 61 of file landscape.cpp.

◆ _tunnel_visibility_frame

const uint8_t _tunnel_visibility_frame[DIAGDIR_END] = {12, 8, 8, 12}
extern

Frame when a vehicle should be hidden in a tunnel with a certain direction.

This differs per direction, because of visibility / bounding box issues. Note that direction, in this case, is the direction leading into the tunnel. When entering a tunnel, hide the vehicle when it reaches the given frame. When leaving a tunnel, show the vehicle when it is one frame further to the 'outside', i.e. at (TILE_SIZE-1) - (frame) + 1

Referenced by AfterLoadGame(), and VehicleEnterTile_TunnelBridge().

◆ BRIDGE_Z_START

const int BRIDGE_Z_START = 3
static

Z position of the bridge sprites relative to bridge height (downwards).

Definition at line 52 of file tunnelbridge_cmd.cpp.

Referenced by DrawBridgeMiddle(), and DrawPillar().

◆ TUNNEL_SOUND_FRAME

const uint8_t TUNNEL_SOUND_FRAME = 1
static

Frame when the 'enter tunnel' sound should be played.

This is the second frame on a tile, so the sound is played shortly after entering the tunnel tile, while the vehicle is still visible.

Definition at line 1953 of file tunnelbridge_cmd.cpp.

Referenced by VehicleEnterTile_TunnelBridge().