OpenTTD Source 20260218-master-g2123fca5ea
elrail.cpp File Reference

This file deals with displaying wires and pylons for electric railways. More...

#include "stdafx.h"
#include "station_map.h"
#include "viewport_func.h"
#include "train.h"
#include "rail_gui.h"
#include "tunnelbridge_map.h"
#include "tunnelbridge.h"
#include "elrail_func.h"
#include "company_base.h"
#include "newgrf_railtype.h"
#include "table/elrail_data.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

static TileLocationGroup GetTileLocationGroup (TileIndex t)
 Get the tile location group of a tile.
static TrackBits GetRailTrackBitsUniversal (TileIndex t, DiagDirections *override)
 Finds which Electrified Rail Bits are present on a given tile.
static TrackBits MaskWireBits (TileIndex t, TrackBits tracks)
 Masks out track bits when neighbouring tiles are unelectrified.
static SpriteID GetWireBase (TileIndex tile, TileContext context=TCX_NORMAL)
 Get the base wire sprite to use.
static SpriteID GetPylonBase (TileIndex tile, TileContext context=TCX_NORMAL)
 Get the base pylon sprite to use.
static void AdjustTileh (TileIndex tile, Slope *tileh)
 Corrects the tileh for certain tile types.
static int GetPCPElevation (TileIndex tile, DiagDirection pcp_pos)
 Returns the Z position of a Pylon Control Point.
void DrawRailCatenaryOnTunnel (const TileInfo *ti)
 Draws wires on a tunnel tile.
static void DrawRailCatenaryRailway (const TileInfo *ti)
 Draws wires and, if required, pylons on a given tile.
void DrawRailCatenaryOnBridge (const TileInfo *ti)
 Draws wires on a tunnel tile.
void DrawRailCatenary (const TileInfo *ti)
 Draws overhead wires and pylons for electric railways.
void SettingsDisableElrail (int32_t new_value)
 Callback for changes to the electrified rails setting.
void UpdateDisableElrailSettingState (bool disable, bool update_vehicles)

Detailed Description

This file deals with displaying wires and pylons for electric railways.

Basics

Tile Types

We have two different types of tiles in the drawing code: Normal Railway Tiles (NRTs) which can have more than one track on it, and Special Railways tiles (SRTs) which have only one track (like crossings, depots stations, etc).

Location Categories

All tiles are categorized into three location groups (TLG): Group 0: Tiles with both an even X coordinate and an even Y coordinate Group 1: Tiles with an even X and an odd Y coordinate Group 2: Tiles with an odd X and an even Y coordinate Group 3: Tiles with both an odd X and Y coordinate.

Pylon Points

Control Points

A Pylon Control Point (PCP) is a position where a wire (or rather two) is mounted onto a pylon. Each NRT does contain 4 PCPs which are bitmapped to a byte variable and are represented by the DiagDirection enum.

Each track ends on two PCPs and thus requires one pylon on each end. However, there is one exception: Straight-and-level tracks only have one pylon every other tile.

Now on each edge there are two PCPs: One from each adjacent tile. Both PCPs are merged using an OR operation (i. e. if one tile needs a PCP at the position in question, both tiles get it).

Position Points

A Pylon Position Point (PPP) is a position where a pylon is located on the ground. Each PCP owns 8 in (45 degree steps) PPPs that are located around it. PPPs are represented using the Direction enum. Each track bit has PPPs that are impossible (because the pylon would be situated on the track) and some that are preferred (because the pylon would be rectangular to the track).

Definition in file elrail.cpp.

Function Documentation

◆ AdjustTileh()

void AdjustTileh ( TileIndex tile,
Slope * tileh )
static

Corrects the tileh for certain tile types.

Returns an effective tileh for the track on the tile.

Parameters
tileThe tile to analyse
*tilehthe tileh

Definition at line 208 of file elrail.cpp.

References GetTunnelBridgeDirection(), InclinedSlope(), IsTileType(), IsTunnel(), SLOPE_FLAT, SLOPE_STEEP, and TunnelBridge.

Referenced by DrawRailCatenaryRailway().

◆ DrawRailCatenary()

void DrawRailCatenary ( const TileInfo * ti)

Draws overhead wires and pylons for electric railways.

Parameters
tiThe TileInfo struct of the tile being drawn
See also
DrawRailCatenaryRailway

Definition at line 559 of file elrail.cpp.

References AddSortableSpriteToDraw(), DrawRailCatenaryRailway(), GetRailDepotDirection(), GetTileMaxPixelZ(), GetTileType(), GetWireBase(), IsRailDepot(), IsTransparencySet(), Railway, Road, Station, TileInfo::tile, TO_CATENARY, TunnelBridge, Coord3D< T >::x, and Coord3D< T >::y.

Referenced by DrawTile_Road(), and DrawTile_TunnelBridge().

◆ DrawRailCatenaryOnBridge()

void DrawRailCatenaryOnBridge ( const TileInfo * ti)

◆ DrawRailCatenaryOnTunnel()

void DrawRailCatenaryOnTunnel ( const TileInfo * ti)

Draws wires on a tunnel tile.

DrawTile_TunnelBridge() calls this function to draw the wires as SpriteCombine with the tunnel roof.

Parameters
tiThe Tileinfo to draw the tile for

Definition at line 258 of file elrail.cpp.

References AddSortableSpriteToDraw(), GetTilePixelZ(), GetTunnelBridgeDirection(), GetWireBase(), IsTransparencySet(), TileInfo::tile, TO_CATENARY, Coord3D< T >::x, and Coord3D< T >::y.

Referenced by DrawTile_TunnelBridge().

◆ DrawRailCatenaryRailway()

void DrawRailCatenaryRailway ( const TileInfo * ti)
static

Draws wires and, if required, pylons on a given tile.

Parameters
tiThe Tileinfo to draw the tile for

Definition at line 272 of file elrail.cpp.

References _allowed_ppp_on_pcp, _disallowed_ppp_of_track_at_pcp, _ignored_pcp, _owned_ppp_on_pcp, _pcp_positions, _preferred_ppp_of_track_at_pcp, AddSortableSpriteToDraw(), AdjustTileh(), ApplyFoundationToSlope(), AXIS_X, BB_HEIGHT_UNDER_BRIDGE, CanStationTileHavePylons(), CanStationTileHaveWires(), DIAGDIR_BEGIN, DIAGDIR_END, DiagDirToAxis(), DIR_BEGIN, DIR_END, DIRECTIONS_ALL, FOUNDATION_NONE, GetBridgeAxis(), GetBridgeFoundation(), GetBridgeHeight(), GetHalftileSlopeCorner(), GetNorthernBridgeEnd(), GetPCPElevation(), GetPylonBase(), GetRailFoundation(), GetRailTrackBitsUniversal(), GetRailType(), GetSlopePixelZ(), GetTileLocationGroup(), GetTileMaxZ(), GetTileSlope(), GetTunnelBridgeDirection(), GetWireBase(), HasBit(), HasRailCatenary(), INVALID_TRACK, IsBridgeAbove(), IsBridgeTile(), IsHalftileSlope(), IsRailStationTile(), IsSteepSlope(), IsTileType(), IsTransparencySet(), IsTunnelTile(), MaskWireBits(), SpriteBounds::origin, Railway, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), ReverseDiagDir(), Road, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SLOPE_FLAT, Station, TCX_UPPER_HALFTILE, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TileInfo::tile, TileInfo::tileh, TileOffsByDiagDir(), TO_BRIDGES, TO_CATENARY, TRACK_BIT_HORZ, TRACK_BIT_NONE, TRACK_BIT_VERT, TRACK_LEFT, TRACK_LOWER, TRACK_RIGHT, TRACK_UPPER, TRACK_X, TRACK_Y, Coord3D< T >::x, and Coord3D< T >::y.

Referenced by DrawRailCatenary().

◆ GetPCPElevation()

int GetPCPElevation ( TileIndex tile,
DiagDirection pcp_pos )
static

Returns the Z position of a Pylon Control Point.

Parameters
tileThe tile the pylon should stand on.
pcp_posThe PCP of the tile.
Returns
The Z position of the PCP.

Definition at line 228 of file elrail.cpp.

References GetSlopePixelZ(), TILE_HEIGHT, TILE_SIZE, TileX(), and TileY().

Referenced by DrawRailCatenaryRailway().

◆ GetPylonBase()

SpriteID GetPylonBase ( TileIndex tile,
TileContext context = TCX_NORMAL )
inlinestatic

Get the base pylon sprite to use.

Parameters
tileThe tile to get the pylon sprite for.
contextThe context to get the sprite for.
Returns
The pylon sprite.

Definition at line 196 of file elrail.cpp.

References GetCustomRailSprite(), GetRailType(), GetRailTypeInfo(), RTSG_PYLONS, and TCX_NORMAL.

Referenced by DrawRailCatenaryOnBridge(), and DrawRailCatenaryRailway().

◆ GetRailTrackBitsUniversal()

TrackBits GetRailTrackBitsUniversal ( TileIndex t,
DiagDirections * override )
static

Finds which Electrified Rail Bits are present on a given tile.

Parameters
ttile to check
overridepointer to PCP override, can be nullptr
Returns
trackbits of tile if it is electrified

Definition at line 86 of file elrail.cpp.

References DiagDirToDiagTrackBits(), GetCrossingRailBits(), GetOtherBridgeEnd(), GetRailStationTrack(), GetRailTileType(), GetRailType(), GetTileType(), GetTrackBits(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasRailCatenary(), HasStationRail(), IsLevelCrossing(), IsTunnel(), Normal, Railway, Road, Signals, Station, TRACK_BIT_NONE, TrackToTrackBits(), TRANSPORT_RAIL, and TunnelBridge.

Referenced by DrawRailCatenaryRailway().

◆ GetTileLocationGroup()

TileLocationGroup GetTileLocationGroup ( TileIndex t)
inlinestatic

Get the tile location group of a tile.

Parameters
tThe tile to get the tile location group of.
Returns
The tile location group.

Definition at line 75 of file elrail.cpp.

References GB(), TileX(), and TileY().

Referenced by DrawRailCatenaryOnBridge(), and DrawRailCatenaryRailway().

◆ GetWireBase()

SpriteID GetWireBase ( TileIndex tile,
TileContext context = TCX_NORMAL )
inlinestatic

Get the base wire sprite to use.

Parameters
tileThe tile to get the wire sprite for.
contextThe context to get the sprite for.
Returns
The wire sprite.

Definition at line 183 of file elrail.cpp.

References GetCustomRailSprite(), GetRailType(), GetRailTypeInfo(), RTSG_WIRES, and TCX_NORMAL.

Referenced by DrawRailCatenary(), DrawRailCatenaryOnBridge(), DrawRailCatenaryOnTunnel(), and DrawRailCatenaryRailway().

◆ MaskWireBits()

◆ SettingsDisableElrail()

void SettingsDisableElrail ( int32_t new_value)

Callback for changes to the electrified rails setting.

A callback to denote that a setting has been changed.

Parameters
new_valueThe new value for the setting.

Definition at line 585 of file elrail.cpp.

◆ UpdateDisableElrailSettingState()

void UpdateDisableElrailSettingState ( bool disable,
bool update_vehicles )

Definition at line 591 of file elrail.cpp.