# elrail.cpp File Reference

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

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "station_map.h"`
`#include "viewport_func.h"`
`#include "settings_type.h"`
`#include "landscape.h"`
`#include "rail_type.h"`
`#include "debug.h"`
`#include "tunnel_map.h"`
`#include "road_map.h"`
`#include "bridge_map.h"`
`#include "bridge.h"`
`#include "rail_map.h"`
`#include "train.h"`
`#include "rail_gui.h"`
`#include "transparency.h"`
`#include "tunnelbridge_map.h"`
`#include "vehicle_func.h"`
`#include "player_base.h"`
`#include "tunnelbridge.h"`
`#include "table/sprites.h"`
`#include "table/elrail_data.h"`

Go to the source code of this file.

## Functions
static TLG | GetTLG (TileIndex t)
static TrackBits | GetRailTrackBitsUniversal (TileIndex t, byte *override)
| Finds which Electrified Rail Bits are present on a given tile.
static void | AdjustTileh (TileIndex tile, Slope *tileh)
| Corrects the tileh for certain tile types.
static byte | GetPCPElevation (TileIndex tile, DiagDirection PCPpos)
| Returns the Z position of a Pylon Control Point.
void | DrawCatenaryOnTunnel (const TileInfo *ti)
| Draws wires on a tunnel tile.
static void | DrawCatenaryRailway (const TileInfo *ti)
| Draws wires and, if required, pylons on a given tile.
static void | DrawCatenaryOnBridge (const TileInfo *ti)
void | DrawCatenary (const TileInfo *ti)
| Draws overhead wires and pylons for electric railways.
int32 | SettingsDisableElrail (int32 p1)
| _patches.disable_elrail callback

## 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 coordnate.

### 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 postion 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

static 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:

  | tile | The tile to analyse
  | *tileh | the tileh

Definition at line 125 of file elrail.cpp.

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

Referenced by DrawCatenaryRailway().

void DrawCatenary | ( | const TileInfo * | ti | ) |

Draws overhead wires and pylons for electric railways.

Parameters:

  | ti | The TileInfo struct of the tile being drawn

See also:
  DrawCatenaryRailway

Definition at line 432 of file elrail.cpp.

References AddSortableSpriteToDraw(), DrawCatenaryRailway(), GetNorthernBridgeEnd(), GetRailDepotDirection(), GetRailType(), GetTileType(), GetTunnelBridgeTransportType(), IsBridgeAbove(), IsRailDepot(), IsTransparencySet(), MayHaveBridgeAbove(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, RAILTYPE_ELECTRIC, and TO_CATENARY.

Referenced by DrawTile_TunnelBridge().

void DrawCatenaryOnTunnel | ( | 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:

  | ti | The Tileinfo to draw the tile for

Definition at line 172 of file elrail.cpp.

References AddSortableSpriteToDraw(), BB_Z_SEPARATOR, GetRailType(), GetTunnelBridgeDirection(), IsTransparencySet(), RAILTYPE_ELECTRIC, and TO_CATENARY.

Referenced by DrawTile_TunnelBridge().

static void DrawCatenaryRailway | ( | const TileInfo * | ti | ) | `[static]`

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

Parameters:

  | ti | The Tileinfo to draw the tile for

Definition at line 200 of file elrail.cpp.

References AddSortableSpriteToDraw(), AdjustTileh(), AllowedPPPonPCP, AXIS_X, BB_HEIGHT_UNDER_BRIDGE, ClrBit(), DIAGDIR_END, DIAGDIR_NE, DiagDirToAxis(), DIR_END, DisallowedPPPofTrackAtPCP, FOUNDATION_NONE, GetBridgeAxis(), GetBridgeHeight(), GetNorthernBridgeEnd(), GetPCPElevation(), GetRailFoundation(), GetRailTrackBitsUniversal(), GetRailType(), GetTunnelBridgeDirection(), HasBit(), IgnoredPCP, IsBridgeAbove(), IsBridgeTile(), IsHalftileSlope(), IsSteepSlope(), IsTileType(), IsTransparencySet(), IsTunnelTile(), MayHaveBridgeAbove(), MP_RAILWAY, MP_STATION, OwnedPPPonPCP, PCPpositions, PreferredPPPofTrackAtPCP, RAILTYPE_ELECTRIC, ReverseDiagDir(), SetBit(), SLOPE_FLAT, TILE_HEIGHT, TileOffsByDiagDir(), TO_CATENARY, TRACK_BEGIN, TRACK_BIT_HORZ, TRACK_BIT_NONE, TRACK_BIT_VERT, TRACK_END, TRACK_X, and TRACK_Y.

Referenced by DrawCatenary().

static byte GetPCPElevation | ( | TileIndex | tile,
|  | DiagDirection | PCPpos |
| ) |  |  | `[static]`

Returns the Z position of a Pylon Control Point.

Parameters:

  | tile | The tile the pylon should stand on.
  | PCPpos | The PCP of the tile.

Returns:
  The Z position of the PCP.

Definition at line 145 of file elrail.cpp.

References min(), TILE_SIZE, TileX(), and TileY().

Referenced by DrawCatenaryRailway().

static TrackBits GetRailTrackBitsUniversal | ( | TileIndex | t,
|  | byte * | override |
| ) |  |  | `[static]`

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

Parameters:

  | t | tile to check
  | override | pointer to PCP override, can be NULL

Returns:
  trackbits of tile if it is electrified

Definition at line 83 of file elrail.cpp.

References AxisToTrackBits(), DiagDirToAxis(), GetOtherBridgeEnd(), GetRailTileType(), GetRailType(), GetRailWaypointBits(), GetTileType(), GetTrackBits(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), IsTunnel(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS, RAIL_TILE_WAYPOINT, RAILTYPE_ELECTRIC, TRACK_BIT_NONE, and TrackToTrackBits().

Referenced by DrawCatenaryRailway().