160 mask = ~TrackdirBitsToTrackBits(neighbour_tdb);
171 return (tracks & mask) !=
TRACK_BIT_NONE ? tracks & mask : tracks;
181 return wires == 0 ? SPR_WIRE_BASE : wires;
191 return pylons == 0 ? SPR_PYLON_BASE : pylons;
238 static const uint HALF_TILE_HEIGHT =
TILE_HEIGHT / 2;
239 return (z + HALF_TILE_HEIGHT / 2) / HALF_TILE_HEIGHT * HALF_TILE_HEIGHT;
270 bool is_flat[TS_END];
276 Corner halftile_corner = CORNER_INVALID;
285 std::array<Directions, DIAGDIR_END> ppp_preferred{};
286 std::array<Directions, DIAGDIR_END> ppp_allowed{};
305 static const uint edge_corners[] = {
306 1 << CORNER_N | 1 << CORNER_E,
307 1 << CORNER_S | 1 << CORNER_E,
308 1 << CORNER_S | 1 << CORNER_W,
309 1 << CORNER_N | 1 << CORNER_W,
311 SpriteID pylon_base = (halftile_corner != CORNER_INVALID &&
HasBit(edge_corners[i], halftile_corner)) ? pylon_halftile : pylon_normal;
319 wire_config[TS_NEIGHBOUR] =
MaskWireBits(neighbour, track_config[TS_NEIGHBOUR]);
336 for (uint k = 0; k < NUM_TRACKS_AT_PCP; k++) {
338 if (_track_source_tile[i][k] == TS_NEIGHBOUR &&
347 if (
HasBit(wire_config[_track_source_tile[i][k]], _tracks_at_pcp[i][k])) {
350 pcp_pos = (_track_source_tile[i][k] == TS_HOME) ? i :
ReverseDiagDir(i);
355 if (
HasBit(track_config[_track_source_tile[i][k]], _tracks_at_pcp[i][k])) {
361 if (!pcp_status.Test(i)) {
362 ppp_preferred[i].Reset();
363 ppp_allowed[i].Reset();
388 if (tileh[TS_HOME] == tileh[TS_NEIGHBOUR] || (is_flat[TS_HOME] && is_flat[TS_NEIGHBOUR])) {
389 for (uint k = 0; k < NUM_IGNORE_GROUPS; k++) {
390 if (ppp_preferred[i] ==
_ignored_pcp[k][tlg][i]) pcp_status.Reset(i);
398 if (ppp_allowed[i].Any(ppp_preferred[i])) ppp_allowed[i] &= ppp_preferred[i];
410 if (ppp_allowed[i].Any() && pcp_status.Test(i) && !override_pcp.Test(i) &&
417 if (ppp_allowed[i].Test(temp)) {
418 uint x = ti->
x + _x_pcp_offsets[i] + _x_ppp_offsets[temp];
419 uint y = ti->
y + _y_pcp_offsets[i] + _y_ppp_offsets[temp];
452 Track halftile_track;
453 switch (halftile_corner) {
454 case CORNER_W: halftile_track =
TRACK_LEFT;
break;
455 case CORNER_S: halftile_track =
TRACK_LOWER;
break;
456 case CORNER_E: halftile_track =
TRACK_RIGHT;
break;
457 case CORNER_N: halftile_track =
TRACK_UPPER;
break;
463 SpriteID wire_base = (t == halftile_track) ? wire_halftile : wire_normal;
466 int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3;
468 assert(pcp_config != 0);
470 const SortableSpriteStruct &sss = _rail_catenary_sprite_data[_rail_wires[tileh_selector][t][pcp_config]];
504 if ((length % 2) && num == length) {
507 sss = &_rail_catenary_sprite_data[WIRE_X_FLAT_BOTH + offset];
510 sss = &_rail_catenary_sprite_data[WIRE_X_FLAT_SW + (num % 2) + offset];
529 uint x = ti->
x + _x_pcp_offsets[pcp_pos] + _x_ppp_offsets[ppp_pos];
530 uint y = ti->
y + _y_pcp_offsets[pcp_pos] + _y_ppp_offsets[ppp_pos];
539 uint x = ti->
x + _x_pcp_offsets[pcp_pos] + _x_ppp_offsets[ppp_pos];
540 uint y = ti->
y + _y_pcp_offsets[pcp_pos] + _y_ppp_offsets[ppp_pos];
577 bool disable = (new_value != 0);
578 UpdateDisableElrailSettingState(disable,
true);
581void UpdateDisableElrailSettingState(
bool disable,
bool update_vehicles)
610 if (update_vehicles) {
613 if (t->IsFrontEngine()) {
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
constexpr Timpl & Reset()
Reset all bits.
This struct contains all the info that is needed to draw and construct tracks.
Definition of stuff that is very close to a company, like the company struct itself.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Direction ReverseDir(Direction d)
Return the reverse of a direction.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Direction
Defines the 8 directions on the map.
@ DIR_BEGIN
Used to iterate.
@ DIR_END
Used to iterate.
Axis
Allow incrementing of DiagDirDiff variables.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_END
Used for iterations.
@ DIAGDIR_BEGIN
Used for iterations.
static constexpr Directions DIRECTIONS_ALL
All possible directions.
static SpriteID GetPylonBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base pylon sprite to use.
void SettingsDisableElrail(int32_t new_value)
_settings_game.disable_elrail callback
void DrawRailCatenaryOnBridge(const TileInfo *ti)
Draws wires on a tunnel tile.
static SpriteID GetWireBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base wire sprite to use.
static TileLocationGroup GetTileLocationGroup(TileIndex t)
Get the tile location group of a tile.
void DrawRailCatenaryOnTunnel(const TileInfo *ti)
Draws wires on a tunnel tile.
static TrackBits MaskWireBits(TileIndex t, TrackBits tracks)
Masks out track bits when neighbouring tiles are unelectrified.
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
static void AdjustTileh(TileIndex tile, Slope *tileh)
Corrects the tileh for certain tile types.
static void DrawRailCatenaryRailway(const TileInfo *ti)
Draws wires and, if required, pylons on a given tile.
static int GetPCPElevation(TileIndex tile, DiagDirection pcp_pos)
Returns the Z position of a Pylon Control Point.
static TrackBits GetRailTrackBitsUniversal(TileIndex t, DiagDirections *override)
Finds which Electrified Rail Bits are present on a given tile.
Stores all the data for overhead wire and pylon drawing.
RailCatenarySprite
Refers to a certain element of the catenary.
static const Directions _owned_ppp_on_pcp[DIAGDIR_END]
Which of the PPPs are inside the tile.
static const Directions _disallowed_ppp_of_track_at_pcp[TRACK_END][DIAGDIR_END]
Which pylons can definitely NOT be built.
static const DiagDirection _pcp_positions[TRACK_END][2]
Maps a track bit onto two PCP positions.
static const Directions _ignored_pcp[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...
static const Directions _preferred_ppp_of_track_at_pcp[TRACK_END][DIAGDIR_END]
Preferred points of each trackbit.
static const Directions _allowed_ppp_on_pcp[DIAGDIR_END]
Which PPPs are possible at all on a given PCP.
TileLocationGroup
Tile Location group.
header file for electrified rail specific functions
bool HasRailCatenary(RailType rt)
Test if a rail type has catenary.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
TileContext
Context for tile accesses.
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
@ TCX_NORMAL
Nothing special.
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
NewGRF handling of rail types.
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
@ RTSG_PYLONS
Catenary pylons.
@ RTSG_WIRES
Catenary wires.
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
Checks if a track combination is valid on a specific slope and returns the needed foundation.
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
@ RAIL_TILE_SIGNALS
Normal rail tile with signals.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
static debug_inline bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
static debug_inline bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
RailType
Enumeration for all possible railtypes.
@ INVALID_RAILTYPE
Flag for invalid railtype.
@ RAILTYPE_ELECTRIC
Electric rails.
@ RAILTYPE_RAIL
Standard non-electric rails.
TrackBits GetCrossingRailBits(Tile tile)
Get the rail track bits of a level crossing.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
A number of safeguards to prevent using unsafe methods.
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Slope InclinedSlope(DiagDirection dir)
Returns the slope that is inclined in a specific direction.
Corner
Enumeration of tile corners.
Slope
Enumeration for the slope-type.
@ SLOPE_STEEP
indicates the slope is steep
Foundation
Enumeration for Foundations.
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Maps accessors for stations.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
Track GetRailStationTrack(Tile t)
Get the rail track of a rail station tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
bool CanStationTileHaveWires(Tile t)
Can tile t have catenary wires?
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
bool CanStationTileHavePylons(Tile t)
Can tile t have catenary pylons?
Definition of base types and functions in a cross-platform compatible way.
Information about a rail vehicle.
RailType intended_railtype
Intended railtype, regardless of elrail being enabled or disabled.
RailType railtype
Railtype, mangled if elrail is disabled.
Iterable ensemble of each set bit in a value.
Coord3D< int8_t > origin
Position of northern corner within tile.
Tile information, used while rendering the tile.
Slope tileh
Slope of the tile.
TileIndex tile
Tile index.
'Train' is either a loco or a wagon.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
static constexpr uint TILE_SIZE
Tile size in world coordinates.
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
@ MP_ROAD
A tile with road (or tram tracks)
@ MP_STATION
A tile of a station.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
TrackBits
Allow incrementing of Track variables.
@ TRACK_BIT_Y
Y-axis track.
@ TRACK_BIT_CROSS
X-Y-axis cross.
@ TRACK_BIT_HORZ
Upper and lower track.
@ TRACK_BIT_NONE
No track.
@ TRACK_BIT_X
X-axis track.
@ TRACK_BIT_MASK
Bitmask for the first 6 bits.
@ TRACK_BIT_VERT
Left and right track.
TrackdirBits
Allow incrementing of Trackdir variables.
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
@ TRACKDIR_BIT_NONE
No track build.
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Track
These are used to specify a single track.
@ INVALID_TRACK
Flag for an invalid track.
@ TRACK_Y
Track along the y-axis (north-west to south-east)
@ TRACK_LOWER
Track in the lower corner of the tile (south)
@ TRACK_LEFT
Track in the left corner of the tile (west)
@ TRACK_RIGHT
Track in the right corner of the tile (east)
@ TRACK_X
Track along the x-axis (north-east to south-west)
@ TRACK_UPPER
Track in the upper corner of the tile (north)
Base for the train class.
static constexpr ConsistChangeFlags CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
@ AllowedOnNormalRail
Electric train engine is allowed to run on normal rail. */.
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...
@ TRANSPORT_RAIL
Transport by train.
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
Header file for things common for tunnels and bridges.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
@ VEH_TRAIN
Train vehicle type.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Functions related to (drawing on) viewports.
static constexpr int BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).