170 return (tracks & mask) !=
TRACK_BIT_NONE ? tracks & mask : tracks;
180 return wires == 0 ? SPR_WIRE_BASE : wires;
190 return pylons == 0 ? SPR_PYLON_BASE : pylons;
248 static const int _tunnel_wire_BB[4][4] = {
260 const int *BB_data = _tunnel_wire_BB[dir];
262 wire_base + sss->image_offset, PAL_NONE, ti->
x + sss->x_offset, ti->
y + sss->y_offset,
263 BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset,
BB_Z_SEPARATOR - sss->z_offset + 1,
266 BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset,
BB_Z_SEPARATOR - sss->z_offset
287 Corner halftile_corner = CORNER_INVALID;
295 byte OverridePCP = 0;
316 static const uint edge_corners[] = {
317 1 << CORNER_N | 1 << CORNER_E,
318 1 << CORNER_S | 1 << CORNER_E,
319 1 << CORNER_S | 1 << CORNER_W,
320 1 << CORNER_N | 1 << CORNER_W,
322 SpriteID pylon_base = (halftile_corner != CORNER_INVALID &&
HasBit(edge_corners[i], halftile_corner)) ? pylon_halftile : pylon_normal;
330 wireconfig[TS_NEIGHBOUR] =
MaskWireBits(neighbour, trackconfig[TS_NEIGHBOUR]);
342 PPPpreferred[i] = 0xFF;
347 for (uint k = 0; k < NUM_TRACKS_AT_PCP; k++) {
349 if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
358 if (
HasBit(wireconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
361 PCPpos = (TrackSourceTile[i][k] == TS_HOME) ? i :
ReverseDiagDir(i);
366 if (
HasBit(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
372 if (!
HasBit(PCPstatus, i)) {
399 if (tileh[TS_HOME] == tileh[TS_NEIGHBOUR] || (isflat[TS_HOME] && isflat[TS_NEIGHBOUR])) {
400 for (uint k = 0; k < NUM_IGNORE_GROUPS; k++) {
409 if ((PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
421 if (PPPallowed[i] != 0 &&
HasBit(PCPstatus, i) && !
HasBit(OverridePCP, i) &&
426 if (
HasBit(PPPallowed[i], temp)) {
427 uint x = ti->
x + x_pcp_offsets[i] + x_ppp_offsets[temp];
428 uint y = ti->
y + y_pcp_offsets[i] + y_ppp_offsets[temp];
461 Track halftile_track;
462 switch (halftile_corner) {
463 case CORNER_W: halftile_track =
TRACK_LEFT;
break;
464 case CORNER_S: halftile_track =
TRACK_LOWER;
break;
465 case CORNER_E: halftile_track =
TRACK_RIGHT;
break;
466 case CORNER_N: halftile_track =
TRACK_UPPER;
break;
473 SpriteID wire_base = (t == halftile_track) ? wire_halftile : wire_normal;
478 int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3;
480 assert(PCPconfig != 0);
482 sss = &RailCatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
490 sss->x_size, sss->y_size, sss->z_size, GetSlopePixelZ(ti->
x + sss->x_offset, ti->
y + sss->y_offset) + sss->z_offset,
517 if ((length % 2) && num == length) {
520 sss = &RailCatenarySpriteData[WIRE_X_FLAT_BOTH + offset];
523 sss = &RailCatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
531 sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
543 uint x = ti->
x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
544 uint y = ti->
y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
545 AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1,
BB_HEIGHT_UNDER_BRIDGE, height,
IsTransparencySet(
TO_CATENARY), -1, -1);
553 uint x = ti->
x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
554 uint y = ti->
y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
555 AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1,
BB_HEIGHT_UNDER_BRIDGE, height,
IsTransparencySet(
TO_CATENARY), -1, -1);
575 wire_base + sss->image_offset, PAL_NONE, ti->
x + sss->x_offset, ti->
y + sss->y_offset,
576 sss->x_size, sss->y_size, sss->z_size,
598 bool disable = (p1 != 0);
609 if (rv_info->
engclass == 2 && rv_info->railtype == old_railtype) {
611 rv_info->railtype = new_railtype;
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
static bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
uint ApplyFoundationToSlope(Foundation f, Slope *s)
Applies a foundation to a slope.
Corner
Enumeration of tile corners.
Definition of stuff that is very close to a company, like the company struct itself.
NewGRF handling of rail types.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Tile information, used while rendering the tile.
void DrawRailCatenaryOnBridge(const TileInfo *ti)
Draws wires on a tunnel tile.
Maps accessors for stations.
RailType
Enumeration for all possible railtypes.
Bitmask for the first 6 bits.
static const byte AllowedPPPonPCP[DIAGDIR_END]
Which PPPs are possible at all on a given PCP.
static int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Base for the train class.
static const byte DisallowedPPPofTrackAtPCP[TRACK_END][DIAGDIR_END]
Which pylons can definitely NOT be built.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
bool CanStationTileHaveWires(TileIndex tile)
Check if a rail station tile shall have wires when electrified.
Track
These are used to specify a single track.
static TrackBits GetCrossingRailBits(TileIndex tile)
Get the rail track bits of a level crossing.
A tile with road (or tram tracks)
Slope tileh
Slope of the tile.
static const uint BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. ...
static uint TileX(TileIndex tile)
Get the X component of a tile.
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Tindex index
Index of this pool item.
static SpriteID GetPylonBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base pylon sprite to use.
static void DrawRailCatenaryRailway(const TileInfo *ti)
Draws wires and, if required, pylons on a given tile.
Northeast, upper right on your monitor.
static const byte PreferredPPPofTrackAtPCP[TRACK_END][DIAGDIR_END]
Preferred points of each trackbit.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Track in the left corner of the tile (west)
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
static Track GetRailStationTrack(TileIndex t)
Get the rail track of a rail station tile.
Standard non-electric rails.
static const byte OwnedPPPonPCP[DIAGDIR_END]
Which of the PPPs are inside the tile.
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction...
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
static const uint TILE_SIZE
Tile size in world coordinates.
Direction
Defines the 8 directions on the map.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
This struct contains all the info that is needed to draw and construct tracks.
Functions related to (drawing on) viewports.
Normal rail tile with signals.
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
TrackBits
Bitfield corresponding to Track.
Querying information about stuff on the bridge (via some bridgehead).
Track x-axis, direction north-east.
indicates the slope is steep
SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
uint x
X position of the tile in unit coordinates.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Querying information about the upper part of a tile with halftile foundation.
Foundation
Enumeration for Foundations.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
TileIndex tile
Tile index.
Track along the y-axis (north-west to south-east)
static int GetPCPElevation(TileIndex tile, DiagDirection PCPpos)
Returns the Z position of a Pylon Control Point.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
Header file for things common for tunnels and bridges.
void ConsistChanged(ConsistChangeFlags allowed_changes)
Recalculates the cached stuff of a train.
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
EngineClass engclass
Class of engine for this vehicle.
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Track in the right corner of the tile (east)
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
Finds which Electrified Rail Bits are present on a given tile.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Definition of base types and functions in a cross-platform compatible way.
static const DiagDirection PCPpositions[TRACK_END][2]
Maps a track bit onto two PCP positions.
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
A number of safeguards to prevent using unsafe methods.
#define FOR_EACH_SET_TRACK(var, track_bits)
Iterate through each set Track in a TrackBits value.
Track in the lower corner of the tile (south)
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
uint y
Y position of the tile in unit coordinates.
void DrawRailCatenaryOnTunnel(const TileInfo *ti)
Draws wires on a tunnel tile.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
Checks if a track combination is valid on a specific slope and returns the needed foundation...
static bool HasRailCatenary(RailType rt)
Test if a rail type has catenary.
DiagDirection
Enumeration for diagonal directions.
static T min(const T a, const T b)
Returns the minimum of two values.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
RailTypes GetCompanyRailtypes(CompanyID company)
Get the rail types the given company can build.
static SpriteID GetWireBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base wire sprite to use.
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Information about a rail vehicle.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction...
'Train' is either a loco or a wagon.
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
static Slope InclinedSlope(DiagDirection dir)
Returns the slope that is inclined in a specific direction.
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
Electric train engine is allowed to run on normal rail. */.
Flag for an invalid track.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Tunnel entry/exit and bridge heads.
static void AdjustTileh(TileIndex tile, Slope *tileh)
Corrects the tileh for certain tile types.
static TLG GetTLG(TileIndex t)
Get the tile location group of a tile.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Track x-axis, direction south-west.
uint32 TileIndex
The index/ID of a Tile.
static const byte IgnoredPCP[NUM_IGNORE_GROUPS][TLG_END][DIAGDIR_END]
In case we have a straight line, we place pylon only every two tiles, so there are certain tiles whic...
RailTypes avail_railtypes
Rail types available to the company.
static int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Track y-axis, direction north-west.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
RailCatenarySprite
Refers to a certain element of the catenary.
The tile has no foundation, the slope remains unchanged.
Slope
Enumeration for the slope-type.
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Normal rail tile without signals.
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
bool CanStationTileHavePylons(TileIndex tile)
Check if a rail station tile shall have pylons when electrified.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
header file for electrified rail specific functions
Functions that have tunnels and bridges in common.
static bool IsTunnelTile(TileIndex t)
Is this a tunnel (entrance)?
Track y-axis, direction south-east.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Flag for invalid railtype.
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Stores all the data for overhead wire and pylon drawing.
Track along the x-axis (north-east to south-west)
static Direction ReverseDir(Direction d)
Return the reverse of a direction.
static TrackBits MaskWireBits(TileIndex t, TrackBits tracks)
Masks out track bits when neighbouring tiles are unelectrified.
Track in the upper corner of the tile (north)
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Valid changes while vehicle is driving, and possibly changing tracks.
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Axis
Allow incrementing of DiagDirDiff variables.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
bool SettingsDisableElrail(int32 p1)
_settings_game.disable_elrail callback
TileContext
Context for tile accesses.