132 if (tracks.
Count() <= 1) [[likely]]
return tracks;
166 if (!tracks.
Any(mask)) {
175 return tracks.
Any(mask) ? tracks & mask : tracks;
188 return wires == 0 ? SPR_WIRE_BASE : wires;
201 return pylons == 0 ? SPR_PYLON_BASE : pylons;
248 static const uint HALF_TILE_HEIGHT =
TILE_HEIGHT / 2;
249 return (z + HALF_TILE_HEIGHT / 2) / HALF_TILE_HEIGHT * HALF_TILE_HEIGHT;
285 Corner halftile_corner = CORNER_INVALID;
339 for (uint k = 0; k < NUM_TRACKS_AT_PCP; k++) {
364 if (!pcp_status.
Test(i)) {
365 ppp_preferred[i].Reset();
366 ppp_allowed[i].Reset();
392 for (uint k = 0; k < NUM_IGNORE_GROUPS; k++) {
401 if (ppp_allowed[i].
Any(ppp_preferred[i])) ppp_allowed[i] &= ppp_preferred[i];
413 if (ppp_allowed[i].
Any() && pcp_status.
Test(i) && !override_pcp.
Test(i) &&
420 if (ppp_allowed[i].Test(temp)) {
455 Track halftile_track;
456 switch (halftile_corner) {
457 case CORNER_W: halftile_track =
Track::Left;
break;
466 SpriteID wire_base = (t == halftile_track) ? wire_halftile : wire_normal;
471 assert(pcp_config != 0);
507 if ((length % 2) && num == length) {
510 sss = &_rail_catenary_sprite_data[WIRE_X_FLAT_BOTH + offset];
513 sss = &_rail_catenary_sprite_data[WIRE_X_FLAT_SW + (num % 2) + offset];
581 bool disable = (new_value != 0);
582 UpdateDisableElrailSettingState(disable,
true);
585void UpdateDisableElrailSettingState(
bool disable,
bool update_vehicles)
613 if (update_vehicles) {
616 if (t->IsFrontEngine()) {
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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.
uint Count() const
Count the number of set bits.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Flip()
Flip all bits.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Iterate a range of enum values.
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.
EnumIndexArray< T, DiagDirection, DiagDirection::End > DiagDirectionIndexArray
Array with DiagDirection as index.
Direction
Defines the 8 directions on the map.
Axis
Enumeration for the two axis X and Y.
DiagDirection
Enumeration for diagonal directions.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
static constexpr Directions DIRECTIONS_ALL
All possible directions.
EnumBitSet< DiagDirection, uint8_t > DiagDirections
Bitset of DiagDirection elements.
static SpriteID GetPylonBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base pylon sprite to use.
void SettingsDisableElrail(int32_t new_value)
Callback for changes to the electrified rails setting.
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.
static const DiagDirectionIndexArray< std::array< DirectionIndexArray< Direction >, TLG_END > > _ppp_order
Several PPPs maybe exist, here they are sorted in order of preference.
static const DiagDirectionIndexArray< int8_t > _x_pcp_offsets
static const DirectionIndexArray< uint8_t > _pylon_sprites
The type of pylon to draw at each PPP.
@ Neighbour
Neighbouring tile.
static const DiagDirectionIndexArray< SortableSpriteStruct > _rail_catenary_sprite_data_tunnel
Catenary sprite data of a tunnel for each direction.
RailCatenarySprite
Refers to a certain element of the catenary.
static const TrackIndexArray< DiagDirectionIndexArray< Directions > > _disallowed_ppp_of_track_at_pcp
Which pylons can definitely NOT be built.
static const TrackIndexArray< std::array< DiagDirection, 2 > > _pcp_positions
Maps a track bit onto two PCP positions.
static const DiagDirectionIndexArray< int8_t > _y_pcp_offsets
static const DirectionIndexArray< int8_t > _x_ppp_offsets
static const DiagDirectionIndexArray< Directions > _owned_ppp_on_pcp
Which of the PPPs are inside the tile.
static const TrackIndexArray< DiagDirectionIndexArray< Directions > > _preferred_ppp_of_track_at_pcp
Preferred points of each trackbit.
static const DiagDirectionIndexArray< Directions > _allowed_ppp_on_pcp
Which PPPs are possible at all on a given PCP.
static const DiagDirectionIndexArray< std::array< Track, NUM_TRACKS_AT_PCP > > _tracks_at_pcp
This array stores which track bits can meet at a tile edge.
static const DiagDirectionIndexArray< Directions > _ignored_pcp[NUM_IGNORE_GROUPS][TLG_END]
In case we have a straight line, we place pylon only every two tiles, so there are certain tiles whic...
static const RailCatenarySprite _rail_wires[5][to_underlying(Track::End)][4]
Selects a Wire (with white and grey ends) depending on whether: a) none (should never happen) b) the ...
static const DiagDirectionIndexArray< SortableSpriteStruct > _rail_catenary_sprite_data_depot
Catenary sprite data of a depot for each direction.
static const DiagDirectionIndexArray< std::array< TileSource, NUM_TRACKS_AT_PCP > > _track_source_tile
Takes each of the 6 track bits from the array above and assigns it to the home tile or neighbour tile...
TileLocationGroup
Tile Location group.
static const DirectionIndexArray< int8_t > _y_ppp_offsets
Header file for electrified rail specific functions.
bool HasRailCatenary(RailType rt)
Test if a rail type has catenary.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, RoadTramType 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 uint TileY(TileIndex tile)
Get the Y component of a tile.
static 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, RailSpriteType 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.
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.
static RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
static bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
static bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
@ Normal
Normal rail tile without signals.
@ Signals
Normal rail tile with signals.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
RailType
Enumeration for all possible railtypes.
@ INVALID_RAILTYPE
Flag for invalid railtype.
@ RAILTYPE_ELECTRIC
Electric rails.
@ RAILTYPE_RAIL
Standard non-electric rails.
Track GetCrossingRailTrack(Tile tile)
Get the rail track 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 IsValidCorner(Corner corner)
Rangecheck for Corner enumeration.
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.
@ None
The tile has no foundation, the slope remains unchanged.
Maps accessors for stations.
Track GetRailStationTrack(Tile t)
Get the rail track of a rail station tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail?
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?
bool CanStationTileHavePylons(Tile t)
Can tile t have catenary pylons?
Definition of base types and functions in a cross-platform compatible way.
static Pool::IterateWrapper< Vehicle > Iterate(size_t from=0)
Information about a rail vehicle.
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
RailTypes intended_railtypes
Intended railtypes, regardless of elrail being enabled or disabled.
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.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
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.
@ TunnelBridge
Tunnel entry/exit and bridge heads.
@ Station
A tile of a station or airport.
@ Railway
A tile with railway.
@ Road
A tile with road and/or tram tracks.
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.
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track Axis::X -> Track::X Axis::Y -> Track::Y Uses the fact that...
Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a DiagDirection to the associated diagonal Track.
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
EnumBitSet< Trackdir, uint16_t > TrackdirBits
Bitset of Trackdir elements.
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
static constexpr TrackBits TRACK_BIT_ALL
All possible tracks.
@ X_NE
X-axis and direction to north-east.
@ X_SW
X-axis and direction to south-west.
@ Y_SE
Y-axis and direction to south-east.
@ Y_NW
Y-axis and direction to north-west.
static constexpr TrackBits TRACK_BIT_CROSS
X-Y-axis cross.
Track
These are used to specify a single track.
@ X
Track along the x-axis (north-east to south-west).
@ Upper
Track in the upper corner of the tile (north).
@ Invalid
Flag for an invalid track.
@ Y
Track along the y-axis (north-west to south-east).
@ Right
Track in the right corner of the tile (east).
@ Left
Track in the left corner of the tile (west).
@ Lower
Track in the lower corner of the tile (south).
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...
@ 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).