OpenTTD Source 20260621-master-g720d10536d
track_func.h File Reference

Different conversion functions from one kind of track to another. More...

#include "track_type.h"
#include "direction_func.h"
#include "slope_func.h"

Go to the source code of this file.

Functions

bool IsValidTrack (Track track)
 Checks if a Track is valid.
bool IsValidTrackdirForRoadVehicle (Trackdir trackdir)
 Checks if a Trackdir is valid for road vehicles.
bool IsValidTrackdir (Trackdir trackdir)
 Checks if a Trackdir is valid for non-road vehicles.
Track AxisToTrack (Axis a)
 Convert an Axis to the corresponding Track Axis::X -> Track::X Axis::Y -> Track::Y Uses the fact that they share the same internal encoding.
TrackBits CornerToTrackBits (Corner corner)
 Returns a single horizontal/vertical trackbit that is in a specific tile corner.
TrackdirBits TrackdirToTrackdirBits (Trackdir trackdir)
 Maps a Trackdir to the corresponding TrackdirBits value.
Track RemoveFirstTrack (TrackBits &tracks)
 Removes first Track from TrackBits and returns it.
Trackdir RemoveFirstTrackdir (TrackdirBits &trackdirs)
 Removes first Trackdir from TrackdirBits and returns it.
Track FindFirstTrack (TrackBits tracks)
 Returns first Track from TrackBits or Track::Invalid.
Track TrackBitsToTrack (TrackBits tracks)
 Converts TrackBits to Track.
Trackdir FindFirstTrackdir (TrackdirBits trackdirs)
 Returns first Trackdir from TrackdirBits or Trackdir::Invalid.
Track TrackToOppositeTrack (Track t)
 Find the opposite track to a given track.
Trackdir ReverseTrackdir (Trackdir trackdir)
 Maps a trackdir to the reverse trackdir.
Track TrackdirToTrack (Trackdir trackdir)
 Returns the Track that a given Trackdir represents.
Trackdir TrackToTrackdir (Track track)
 Returns a Trackdir for the given Track.
TrackdirBits TrackToTrackdirBits (Track track)
 Returns a TrackdirBit mask from a given Track.
TrackBits TrackdirBitsToTrackBits (TrackdirBits bits)
 Discards all directional information from a TrackdirBits value.
TrackdirBits TrackBitsToTrackdirBits (TrackBits bits)
 Converts TrackBits to TrackdirBits while allowing both directions.
Trackdir NextTrackdir (Trackdir trackdir)
 Maps a trackdir to the trackdir that you will end up on if you go straight ahead.
TrackBits TrackCrossesTracks (Track track)
 Maps a track to all tracks that make 90 deg turns with it.
DiagDirection TrackdirToExitdir (Trackdir trackdir)
 Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Trackdir TrackExitdirToTrackdir (Track track, DiagDirection diagdir)
 Maps a track and an (4-way) dir to the trackdir that represents the track with the exit in the given direction.
Trackdir TrackEnterdirToTrackdir (Track track, DiagDirection diagdir)
 Maps a track and an (4-way) dir to the trackdir that represents the track with the entry in the given direction.
Trackdir TrackDirectionToTrackdir (Track track, Direction dir)
 Maps a track and a full (8-way) direction to the trackdir that represents the track running in the given direction.
Track DiagDirToDiagTrack (DiagDirection diagdir)
 Maps a DiagDirection to the associated diagonal Track.
Trackdir DiagDirToDiagTrackdir (DiagDirection diagdir)
 Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
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.
TrackdirBits TrackdirReachesTrackdirs (Trackdir trackdir)
 Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile.
TrackdirBits TrackdirCrossesTrackdirs (Trackdir trackdir)
 Maps a trackdir to all trackdirs that make 90 deg turns with it.
bool IsDiagonalTrack (Track track)
 Checks if a given Track is diagonal.
bool IsDiagonalTrackdir (Trackdir trackdir)
 Checks if a given Trackdir is diagonal.
bool TracksOverlap (TrackBits bits)
 Checks if the given tracks overlap, ie form a crossing.
bool TrackOverlapsTracks (TrackBits tracks, Track track)
 Check if a given track is contained within or overlaps some other tracks.
bool IsReversingRoadTrackdir (Trackdir dir)
 Checks whether the trackdir means that we are reversing.
bool IsStraightRoadTrackdir (Trackdir dir)
 Checks whether the given trackdir is a straight road.
bool IsUphillTrackdir (Slope slope, Trackdir dir)
 Checks whether a trackdir on a specific slope is going uphill.
DiagDirection VehicleExitDir (Direction direction, TrackBits track)
 Determine the side in which the vehicle will leave the tile.

Detailed Description

Different conversion functions from one kind of track to another.

Definition in file track_func.h.

Function Documentation

◆ AxisToTrack()

Track AxisToTrack ( Axis a)
inline

◆ CornerToTrackBits()

TrackBits CornerToTrackBits ( Corner corner)
inline

Returns a single horizontal/vertical trackbit that is in a specific tile corner.

Parameters
cornerThe corner of a tile.
Returns
The TrackBits of the track in the corner.

Definition at line 74 of file track_func.h.

References _corner_to_trackbits, and IsValidCorner().

Referenced by DrawTrackBits(), FloodHalftile(), and GetRailFoundation().

◆ DiagdirReachesTrackdirs()

TrackdirBits DiagdirReachesTrackdirs ( DiagDirection diagdir)
inline

Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.

This will obviously include 90 degree turns, since no information is available about the exact angle of entering

Parameters
diagdirThe joining direction
Returns
The TrackdirBits which can be used from the given direction
See also
DiagdirReachesTracks

Definition at line 450 of file track_func.h.

References _exitdir_reaches_trackdirs, and IsValidDiagDirection().

Referenced by CYapfFollowShipT< Types >::CheckShipReverse(), DiagdirReachesTracks(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::Follow(), IsSafeWaitingPosition(), IsWaitingPositionFree(), MaskWireBits(), RoadFindPathToDest(), TrainCheckIfLineEnds(), TrainController(), TryPathReserve(), and CFollowTrackT< TRANSPORT_WATER, Ship, true >::TryReverse().

◆ DiagdirReachesTracks()

TrackBits DiagdirReachesTracks ( DiagDirection diagdir)
inline

Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.

This will obviously include 90 degree turns, since no information is available about the exact angle of entering

Parameters
diagdirThe joining direction
Returns
The tracks which can be used
See also
DiagdirReachesTrackdirs

Definition at line 468 of file track_func.h.

References DiagdirReachesTrackdirs(), and TrackdirBitsToTrackBits().

Referenced by DetermineNextTrainForceProceeding(), GetAvailShipTracks(), MaskWireBits(), PlaceExtraDepotRail(), and TryPathReserve().

◆ DiagDirToDiagTrack()

◆ DiagDirToDiagTrackdir()

Trackdir DiagDirToDiagTrackdir ( DiagDirection diagdir)
inline

Maps a (4-way) direction to the diagonal trackdir that runs in that direction.

Parameters
diagdirThe direction
Returns
The resulting Trackdir direction

Definition at line 432 of file track_func.h.

References _dir_to_diag_trackdir, and IsValidDiagDirection().

Referenced by AfterLoadGame(), FollowReservation(), RoadVehicle::GetVehicleTrackdir(), Ship::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), CYapfCostRoadT< Types >::PfCalcCost(), and VehicleEnterTile_TunnelBridge().

◆ FindFirstTrack()

Track FindFirstTrack ( TrackBits tracks)
inline

Returns first Track from TrackBits or Track::Invalid.

This function returns the first Track found in the TrackBits value as Track-value. It returns Track::Invalid if the parameter is empty.

Parameters
tracksThe TrackBits value
Returns
The first Track found or Track::Invalid
See also
RemoveFirstTrack

Definition at line 150 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::GetNthSetBit(), and Invalid.

Referenced by ChooseShipTrack(), DetermineNextTrainForceProceeding(), FloodHalftile(), GenericPlaceSignals(), Ship::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), TrackBitsToTrack(), TrainCheckIfLineEnds(), TrainController(), and YapfTrainChooseTrack().

◆ FindFirstTrackdir()

Trackdir FindFirstTrackdir ( TrackdirBits trackdirs)
inline

Returns first Trackdir from TrackdirBits or Trackdir::Invalid.

This function returns the first Trackdir in the given TrackdirBits value or Trackdir::Invalid if the value is empty. The TrackdirBits must not be INVALID_TRACKDIR_BIT.

Parameters
trackdirsThe TrackdirBits value
Returns
The first Trackdir from the TrackdirBits or Trackdir::Invalid on empty.
Precondition
trackdirs must not be INVALID_TRACKDIR_BIT
See also
RemoveFirstTrackdir

Definition at line 184 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::GetNthSetBit(), and Invalid.

Referenced by CheckNextTrainTile(), ExtendTrainReservation(), FollowReservation(), IsSafeWaitingPosition(), and TrainController().

◆ IsDiagonalTrack()

bool IsDiagonalTrack ( Track track)
inline

Checks if a given Track is diagonal.

Parameters
trackThe given track to check
Returns
true if diagonal, else false

Definition at line 514 of file track_func.h.

References IsValidTrack(), X, and Y.

Referenced by ChooseShipTrack(), and IsDiagonalTrackdir().

◆ IsDiagonalTrackdir()

bool IsDiagonalTrackdir ( Trackdir trackdir)
inline

Checks if a given Trackdir is diagonal.

Parameters
trackdirThe given trackdir
Returns
true if the trackdir use a diagonal track

Definition at line 526 of file track_func.h.

References IsDiagonalTrack(), IsValidTrackdir(), and TrackdirToTrack().

Referenced by CmdRailTrackHelper(), CmdSignalTrackHelper(), CYapfCostRailT< Types >::OneTileCost(), CYapfCostRoadT< Types >::OneTileCost(), CYapfCostShipT< Types >::PfCalcCost(), CYapfCostRailT< Types >::ReservationCost(), and CYapfCostBase::stSlopeCost().

◆ IsReversingRoadTrackdir()

bool IsReversingRoadTrackdir ( Trackdir dir)
inline

Checks whether the trackdir means that we are reversing.

Parameters
dirthe trackdir to check
Returns
true if it is a reversing road trackdir

Definition at line 568 of file track_func.h.

References IsValidTrackdirForRoadVehicle(), and to_underlying().

Referenced by RoadVehicle::GetCurrentMaxSpeed(), RoadVehicle::GetVehicleTrackdir(), RoadVehicle::HasToUseGetSlopePixelZ(), and VehicleEnterTile_Station().

◆ IsStraightRoadTrackdir()

bool IsStraightRoadTrackdir ( Trackdir dir)
inline

Checks whether the given trackdir is a straight road.

Parameters
dirthe trackdir to check
Returns
true if it is a straight road trackdir

Definition at line 579 of file track_func.h.

References IsValidTrackdirForRoadVehicle(), and to_underlying().

◆ IsUphillTrackdir()

bool IsUphillTrackdir ( Slope slope,
Trackdir dir )
inline

Checks whether a trackdir on a specific slope is going uphill.

Valid for rail and road tracks. Valid for tile-slopes (under foundation) and foundation-slopes (on foundation).

Parameters
slopeThe slope of the tile.
dirThe trackdir of interest.
Returns
true iff the track goes upwards.

Definition at line 595 of file track_func.h.

References IsValidTrackdirForRoadVehicle(), and RemoveHalftileSlope().

Referenced by CYapfCostBase::stSlopeCost().

◆ IsValidTrack()

bool IsValidTrack ( Track track)
inline

Checks if a Track is valid.

Parameters
trackThe value to check
Returns
true if the given value is a valid track.
Note
Use this in an assert()

Definition at line 24 of file track_func.h.

References End.

Referenced by GenericPlaceSignals(), HasSignalOnTrack(), IsDiagonalTrack(), SetSignalType(), SetSignalVariant(), SetTrackReservation(), TrackCrossesTracks(), TrackDirectionToTrackdir(), TrackEnterdirToTrackdir(), TrackExitdirToTrackdir(), TrackToOppositeTrack(), and TrackToTrackdir().

◆ IsValidTrackdir()

bool IsValidTrackdir ( Trackdir trackdir)
inline

Checks if a Trackdir is valid for non-road vehicles.

Parameters
trackdirThe value to check
Returns
true if the given value is a valid Trackdir
Note
Use this in an assert()

Definition at line 48 of file track_func.h.

References End, and TRACKDIR_BIT_MASK.

Referenced by FreeTrainTrackReservation(), GetSignalStateByTrackdir(), HasSignalOnTrackdir(), IsDiagonalTrackdir(), NextTrackdir(), TrackdirCrossesTrackdirs(), TrackdirReachesTrackdirs(), TrackdirToTrack(), and TrackdirToTrackdirBits().

◆ IsValidTrackdirForRoadVehicle()

bool IsValidTrackdirForRoadVehicle ( Trackdir trackdir)
inline

Checks if a Trackdir is valid for road vehicles.

Parameters
trackdirThe value to check
Returns
true if the given value is a valid Trackdir
Note
Use this in an assert()

Definition at line 36 of file track_func.h.

References End.

Referenced by IsReversingRoadTrackdir(), IsStraightRoadTrackdir(), IsUphillTrackdir(), ReverseTrackdir(), and TrackdirToExitdir().

◆ NextTrackdir()

Trackdir NextTrackdir ( Trackdir trackdir)
inline

Maps a trackdir to the trackdir that you will end up on if you go straight ahead.

This will be the same trackdir for diagonal trackdirs, but a different (alternating) one for straight trackdirs

Parameters
trackdirThe given trackdir
Returns
The next Trackdir value of the next tile.

Definition at line 307 of file track_func.h.

References _next_trackdir, and IsValidTrackdir().

◆ RemoveFirstTrack()

Track RemoveFirstTrack ( TrackBits & tracks)
inline

Removes first Track from TrackBits and returns it.

This function searches for the first bit in the TrackBits, remove this bit from the parameter and returns the found bit as Track value. It returns Track::Invalid if the parameter was empty. This is basically used in while-loops to get up to 6 possible tracks on a tile until the parameter becomes empty.

Parameters
tracksThe value with the TrackBits
Returns
The first Track from the TrackBits value
See also
FindFirstTrack

Definition at line 106 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::GetNthSetBit(), Invalid, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::None(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset().

Referenced by SetTrackReservation().

◆ RemoveFirstTrackdir()

Trackdir RemoveFirstTrackdir ( TrackdirBits & trackdirs)
inline

Removes first Trackdir from TrackdirBits and returns it.

This function searches for the first bit in the TrackdirBits parameter, remove this bit from the parameter and returns the fnound bit as Trackdir value. It returns Trackdir::Invalid if the trackdirs is empty or INVALID_TRACKDIR_BIT. This is basically used in a while-loop to get all track-directions step by step until the value reaches TRACKDIR_BIT_NONE.

Parameters
trackdirsThe value with the TrackdirBits
Returns
The first Trackdir from the TrackdirBits value
See also
FindFirstTrackdir

Definition at line 130 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::GetNthSetBit(), Invalid, INVALID_TRACKDIR_BIT, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::None(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset().

Referenced by FreeTrainTrackReservation(), and CYapfCostRailT< Types >::PfCalcCost().

◆ ReverseTrackdir()

◆ TrackBitsToTrack()

Track TrackBitsToTrack ( TrackBits tracks)
inline

Converts TrackBits to Track.

This function converts a TrackBits value to a Track value. As it is not possible to convert two or more tracks to one track the parameter must contain only one track.

Parameters
tracksThe TrackBits value to convert
Returns
The Track from the value
Precondition
tracks must contains only one Track

Definition at line 166 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Count(), and FindFirstTrack().

Referenced by ChooseShipTrack(), CmdRemoveSingleSignal(), DeleteLastWagon(), DoDryUp(), ExploreSegment(), Train::ReserveTrackUnderConsist(), and TrainController().

◆ TrackBitsToTrackdirBits()

◆ TrackCrossesTracks()

TrackBits TrackCrossesTracks ( Track track)
inline

Maps a track to all tracks that make 90 deg turns with it.

For the diagonal directions these are the complement of the direction, for the straight directions these are the two vertical or horizontal tracks, depend on the given direction

Parameters
trackThe given track
Returns
The TrackBits with the tracks marked which cross the given track by 90 deg.

Definition at line 324 of file track_func.h.

References _track_crosses_tracks, and IsValidTrack().

Referenced by CheckNextTrainTile(), TrainCheckIfLineEnds(), TrainController(), and TryPathReserve().

◆ TrackdirBitsToTrackBits()

◆ TrackdirCrossesTrackdirs()

TrackdirBits TrackdirCrossesTrackdirs ( Trackdir trackdir)
inline

Maps a trackdir to all trackdirs that make 90 deg turns with it.

For the diagonal tracks this returns the track direction bits of the other axis in both directions, which cannot be joined by the given track direction. For the straight tracks this returns all possible 90 deg turns either on the current tile (which no train can joined) or on the bordering tiles.

Parameters
trackdirThe track direction
Returns
The TrackdirBits which are (more or less) 90 deg turns.

Definition at line 501 of file track_func.h.

References _track_crosses_trackdirs, IsValidTrackdir(), and TrackdirToTrack().

Referenced by ExtendTrainReservation(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::Follow(), CYapfFollowShipT< Types >::GetRandomFollowUpTileTrackdir(), IsSafeWaitingPosition(), and IsWaitingPositionFree().

◆ TrackDirectionToTrackdir()

Trackdir TrackDirectionToTrackdir ( Track track,
Direction dir )
inline

Maps a track and a full (8-way) direction to the trackdir that represents the track running in the given direction.

Parameters
trackThe track to get the trackdir for.
dirThe direction along the track.
Returns
The resulting trackdir.

Definition at line 405 of file track_func.h.

References _track_direction_to_trackdir, IsValidDirection(), and IsValidTrack().

Referenced by Ship::GetVehicleTrackdir(), Train::GetVehicleTrackdir(), and TrainController().

◆ TrackdirReachesTrackdirs()

TrackdirBits TrackdirReachesTrackdirs ( Trackdir trackdir)
inline

Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile.

This will include 90 degree turns!

Parameters
trackdirThe track direction which will be leaved
Returns
The track directions which can be used from this direction (in the next tile)

Definition at line 479 of file track_func.h.

References _exitdir_reaches_trackdirs, IsValidTrackdir(), and TrackdirToExitdir().

Referenced by CmdRemoveSingleSignal(), and ExtendTrainReservation().

◆ TrackdirToExitdir()

DiagDirection TrackdirToExitdir ( Trackdir trackdir)
inline

Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.

For the diagonal directions these are the same directions. For the straight directions these are the directions from the imagined base-tile to the bordering tile which will be joined if the given straight direction is leaved from the base-tile.

Parameters
trackdirThe given track direction
Returns
The direction which points to the resulting tile if following the Trackdir

Definition at line 343 of file track_func.h.

References _trackdir_to_exitdir, and IsValidTrackdirForRoadVehicle().

Referenced by CFollowTrackT< TRANSPORT_WATER, Ship, true >::CanEnterNewTile(), CheckShipStayInDepot(), ClearPathReservation(), CmdRemoveSingleSignal(), DetermineNextTrainForceProceeding(), CFollowTrackT< TRANSPORT_WATER, Ship, true >::Follow(), FollowTrainReservation(), FreeTrainReservation(), FreeTrainTrackReservation(), GetTrainForReservation(), CYapfCostRailT< Types >::IsAnyStationTileReserved(), OctileDistanceCost(), CYapfCostRoadT< Types >::OneTileCost(), CYapfCostRailT< Types >::PfCalcCost(), CYapfReserveTrack< Types >::ReserveSingleTrack(), RestoreTrainReservation(), ReverseTrainDirection(), CYapfCostBase::stSlopeCost(), TrackdirReachesTrackdirs(), TrainController(), TryPathReserve(), CYapfReserveTrack< Types >::UnreserveSingleTrack(), UpdateSignalsAroundSegment(), and YapfTrainCheckReverse().

◆ TrackdirToTrack()

◆ TrackdirToTrackdirBits()

◆ TrackEnterdirToTrackdir()

Trackdir TrackEnterdirToTrackdir ( Track track,
DiagDirection diagdir )
inline

Maps a track and an (4-way) dir to the trackdir that represents the track with the entry in the given direction.

For the diagonal tracks the return value is clear, its either the matching track direction or Trackdir::Invalid. For the straight tracks this returns the track direction which results if you follow the DiagDirection and then turn by 45 deg left or right on the next tile. The new direction on the new track will be the returning Trackdir value. If the parameters makes no sense like the track Track::Upper and the direction DiagDirection::NE (target track cannot be reached) this function returns Trackdir::Invalid.

Parameters
trackThe target track
diagdirThe direction to "come from"
Returns
the resulting Trackdir or Trackdir::Invalid if not possible.

Definition at line 390 of file track_func.h.

References _track_enterdir_to_trackdir, IsValidDiagDirection(), and IsValidTrack().

◆ TrackExitdirToTrackdir()

Trackdir TrackExitdirToTrackdir ( Track track,
DiagDirection diagdir )
inline

Maps a track and an (4-way) dir to the trackdir that represents the track with the exit in the given direction.

For the diagonal tracks the resulting track direction are clear for a given DiagDirection. It either matches the direction or it returns Trackdir::Invalid, as a Track::X cannot be applied with DIAG_SE. For the straight tracks the resulting track direction will be the direction which the DiagDirection is pointing. But this will be Trackdir::Invalid if the DiagDirection is pointing 'away' the track.

Parameters
trackThe track to apply an direction on
diagdirThe DiagDirection to apply on
Returns
The resulting track direction or Trackdir::Invalid if not possible.

Definition at line 365 of file track_func.h.

References _track_exitdir_to_trackdir, IsValidDiagDirection(), and IsValidTrack().

◆ TrackOverlapsTracks()

bool TrackOverlapsTracks ( TrackBits tracks,
Track track )
inline

Check if a given track is contained within or overlaps some other tracks.

Parameters
tracksTracks to be tested against
trackThe track to test
Returns
true if the track is already in the tracks or overlaps the tracks.

Definition at line 557 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and TracksOverlap().

Referenced by IsWaitingPositionFree(), and CYapfCostRailT< Types >::ReservationCost().

◆ TracksOverlap()

bool TracksOverlap ( TrackBits bits)
inline

Checks if the given tracks overlap, ie form a crossing.

Basically this means when there is more than one track on the tile, except when there are two parallel tracks.

Parameters
bitsThe tracks present.
Returns
Whether the tracks present overlap in any way.

Definition at line 540 of file track_func.h.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Count(), TRACK_BIT_HORZ, and TRACK_BIT_VERT.

Referenced by AfterLoadCompanyStats(), ChangeTileOwner_Rail(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdConvertRail(), CmdRemoveSingleRail(), EnsureNoTrainOnTrackBits(), FreeTrainTrackReservation(), GetRailFoundation(), MaskWireBits(), SetTrackReservation(), TrackOverlapsTracks(), and TryReserveTrack().

◆ TrackToOppositeTrack()

Track TrackToOppositeTrack ( Track t)
inline

Find the opposite track to a given track.

Track::Lower -> Track::Upper and vice versa, likewise for left/right. Track::X is mapped to Track::Y and reversed.

Parameters
tthe track to convert
Returns
the opposite track

Definition at line 204 of file track_func.h.

References IsValidTrack(), and to_underlying().

Referenced by ChooseShipTrack(), and GetRailReservationTrackBits().

◆ TrackToTrackdir()

Trackdir TrackToTrackdir ( Track track)
inline

Returns a Trackdir for the given Track.

Since every Track corresponds to two Trackdirs, we choose the one which points between NE and S. Note that the actual implementation is quite futile, but this might change in the future.

Parameters
trackThe given Track
Returns
The Trackdir from the given Track

Definition at line 252 of file track_func.h.

References IsValidTrack().

Referenced by CmdRailTrackHelper(), CmdRemoveSingleSignal(), CmdSignalTrackHelper(), GetTrainForReservation(), and TrackToTrackdirBits().

◆ TrackToTrackdirBits()

TrackdirBits TrackToTrackdirBits ( Track track)
inline

Returns a TrackdirBit mask from a given Track.

The TrackdirBit mask contains the two TrackdirBits that correspond with the given Track (one for each direction).

Parameters
trackThe track to get the TrackdirBits from
Returns
The TrackdirBits which the selected tracks

Definition at line 267 of file track_func.h.

References ReverseTrackdir(), TrackdirToTrackdirBits(), and TrackToTrackdir().

◆ VehicleExitDir()

DiagDirection VehicleExitDir ( Direction direction,
TrackBits track )
inline

Determine the side in which the vehicle will leave the tile.

Parameters
directionvehicle direction
trackvehicle track bits
Returns
side of tile the vehicle will leave

Definition at line 609 of file track_func.h.

References ChangeDiagDir(), DirToDiagDir(), IsDiagonalDirection(), Left, Left90, Lower, Right, and Upper.

Referenced by CYapfFollowShipT< Types >::CheckShipReverse(), ReverseTrainDirection(), TrainApproachingCrossingTile(), TrainCheckIfLineEnds(), TrainController(), and TrainLocoHandler().