OpenTTD Source  20241108-master-g80f628063a
track_func.h File Reference

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

#include "core/bitmath_func.hpp"
#include "track_type.h"
#include "direction_func.h"
#include "slope_func.h"

Go to the source code of this file.

Typedefs

using SetTrackBitIterator = SetBitIterator< Track, TrackBits >
 
using SetTrackdirBitIterator = SetBitIterator< Trackdir, TrackdirBits >
 

Functions

bool IsValidTrack (Track track)
 Checks if a Track is valid. More...
 
bool IsValidTrackdirForRoadVehicle (Trackdir trackdir)
 Checks if a Trackdir is valid for road vehicles. More...
 
bool IsValidTrackdir (Trackdir trackdir)
 Checks if a Trackdir is valid for non-road vehicles. More...
 
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. More...
 
TrackBits TrackToTrackBits (Track track)
 Maps a Track to the corresponding TrackBits value. More...
 
TrackBits AxisToTrackBits (Axis a)
 Maps an Axis to the corresponding TrackBits value. More...
 
TrackBits CornerToTrackBits (Corner corner)
 Returns a single horizontal/vertical trackbit that is in a specific tile corner. More...
 
TrackdirBits TrackdirToTrackdirBits (Trackdir trackdir)
 Maps a Trackdir to the corresponding TrackdirBits value. More...
 
Track RemoveFirstTrack (TrackBits *tracks)
 Removes first Track from TrackBits and returns it. More...
 
Trackdir RemoveFirstTrackdir (TrackdirBits *trackdirs)
 Removes first Trackdir from TrackdirBits and returns it. More...
 
Track FindFirstTrack (TrackBits tracks)
 Returns first Track from TrackBits or INVALID_TRACK. More...
 
Track TrackBitsToTrack (TrackBits tracks)
 Converts TrackBits to Track. More...
 
Trackdir FindFirstTrackdir (TrackdirBits trackdirs)
 Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR. More...
 
Track TrackToOppositeTrack (Track t)
 Find the opposite track to a given track. More...
 
Trackdir ReverseTrackdir (Trackdir trackdir)
 Maps a trackdir to the reverse trackdir. More...
 
Track TrackdirToTrack (Trackdir trackdir)
 Returns the Track that a given Trackdir represents. More...
 
Trackdir TrackToTrackdir (Track track)
 Returns a Trackdir for the given Track. More...
 
TrackdirBits TrackToTrackdirBits (Track track)
 Returns a TrackdirBit mask from a given Track. More...
 
TrackBits TrackdirBitsToTrackBits (TrackdirBits bits)
 Discards all directional information from a TrackdirBits value. More...
 
TrackdirBits TrackBitsToTrackdirBits (TrackBits bits)
 Converts TrackBits to TrackdirBits while allowing both directions. More...
 
bool HasTrack (TrackBits tracks, Track track)
 Checks whether a TrackBits has a given Track. More...
 
bool HasTrackdir (TrackdirBits trackdirs, Trackdir trackdir)
 Checks whether a TrackdirBits has a given Trackdir. More...
 
TrackdirBits TrackStatusToTrackdirBits (TrackStatus ts)
 Returns the present-trackdir-information of a TrackStatus. More...
 
TrackBits TrackStatusToTrackBits (TrackStatus ts)
 Returns the present-track-information of a TrackStatus. More...
 
TrackdirBits TrackStatusToRedSignals (TrackStatus ts)
 Returns the red-signal-information of a TrackStatus. More...
 
TrackStatus CombineTrackStatus (TrackdirBits trackdirbits, TrackdirBits red_signals)
 Builds a TrackStatus. More...
 
Trackdir NextTrackdir (Trackdir trackdir)
 Maps a trackdir to the trackdir that you will end up on if you go straight ahead. More...
 
TrackBits TrackCrossesTracks (Track track)
 Maps a track to all tracks that make 90 deg turns with it. More...
 
DiagDirection TrackdirToExitdir (Trackdir trackdir)
 Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir. More...
 
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. More...
 
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. More...
 
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 (4-way) direction to the diagonal track incidating with that diagdir. More...
 
TrackBits DiagDirToDiagTrackBits (DiagDirection diagdir)
 Maps a (4-way) direction to the diagonal track bits incidating with that diagdir. More...
 
Trackdir DiagDirToDiagTrackdir (DiagDirection diagdir)
 Maps a (4-way) direction to the diagonal trackdir that runs in that direction. More...
 
TrackdirBits DiagdirReachesTrackdirs (DiagDirection diagdir)
 Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction. More...
 
TrackBits DiagdirReachesTracks (DiagDirection diagdir)
 Returns all tracks that can be reached when entering a tile from a given (diagonal) direction. More...
 
TrackdirBits TrackdirReachesTrackdirs (Trackdir trackdir)
 Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile. More...
 
TrackdirBits TrackdirCrossesTrackdirs (Trackdir trackdir)
 Maps a trackdir to all trackdirs that make 90 deg turns with it. More...
 
bool IsDiagonalTrack (Track track)
 Checks if a given Track is diagonal. More...
 
bool IsDiagonalTrackdir (Trackdir trackdir)
 Checks if a given Trackdir is diagonal. More...
 
bool TracksOverlap (TrackBits bits)
 Checks if the given tracks overlap, ie form a crossing. More...
 
bool TrackOverlapsTracks (TrackBits tracks, Track track)
 Check if a given track is contained within or overlaps some other tracks. More...
 
bool IsReversingRoadTrackdir (Trackdir dir)
 Checks whether the trackdir means that we are reversing. More...
 
bool IsStraightRoadTrackdir (Trackdir dir)
 Checks whether the given trackdir is a straight road. More...
 
bool IsUphillTrackdir (Slope slope, Trackdir dir)
 Checks whether a trackdir on a specific slope is going uphill. More...
 
DiagDirection VehicleExitDir (Direction direction, TrackBits track)
 Determine the side in which the vehicle will leave the tile. More...
 

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

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.

Parameters
athe axis to convert
Returns
the track corresponding to the axis

Definition at line 66 of file track_func.h.

References IsValidAxis().

Referenced by AxisToTrackBits(), GetCrossingRailTrack(), and GetRailStationTrack().

◆ AxisToTrackBits()

TrackBits AxisToTrackBits ( Axis  a)
inline

Maps an Axis to the corresponding TrackBits value.

Parameters
athe axis to convert
Returns
the converted TrackBits value of the axis

Definition at line 88 of file track_func.h.

References AxisToTrack(), and TrackToTrackBits().

Referenced by GetCrossingRailBits(), and GetRailStationTrackBits().

◆ CombineTrackStatus()

TrackStatus CombineTrackStatus ( TrackdirBits  trackdirbits,
TrackdirBits  red_signals 
)
inline

Builds a TrackStatus.

Parameters
trackdirbitspresent trackdirs
red_signalsred signals
Returns
the TrackStatus representing the given information

Definition at line 388 of file track_func.h.

◆ 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 99 of file track_func.h.

Referenced by 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 555 of file track_func.h.

References IsValidDiagDirection().

Referenced by CYapfFollowShipT< Types >::CheckShipReverse(), DiagdirReachesTracks(), MaskWireBits(), TrainController(), TryPathReserve(), and CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::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 573 of file track_func.h.

References DiagdirReachesTrackdirs(), and TrackdirBitsToTrackBits().

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

◆ DiagDirToDiagTrack()

Track DiagDirToDiagTrack ( DiagDirection  diagdir)
inline

Maps a (4-way) direction to the diagonal track incidating with that diagdir.

Parameters
diagdirThe direction
Returns
The resulting Track

Definition at line 512 of file track_func.h.

References IsValidDiagDirection().

Referenced by CmdConvertRail(), DiagDirToDiagTrackBits(), GetRailDepotTrack(), and Train::ReserveTrackUnderConsist().

◆ DiagDirToDiagTrackBits()

TrackBits DiagDirToDiagTrackBits ( DiagDirection  diagdir)
inline

Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.

Parameters
diagdirThe direction
Returns
The resulting TrackBits

Definition at line 524 of file track_func.h.

References DiagDirToDiagTrack(), IsValidDiagDirection(), and TrackToTrackBits().

Referenced by CollectTrackbitsFromCrashedVehiclesEnum(), DeleteLastWagon(), GetRailTrackBitsUniversal(), and GetTunnelBridgeReservationTrackBits().

◆ 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 537 of file track_func.h.

References IsValidDiagDirection().

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

◆ FindFirstTrack()

Track FindFirstTrack ( TrackBits  tracks)
inline

Returns first Track from TrackBits or INVALID_TRACK.

This function returns the first Track found in the TrackBits value as Track-value. It returns INVALID_TRACK if the parameter is TRACK_BIT_NONE or INVALID_TRACK_BIT.

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

Definition at line 177 of file track_func.h.

References FindFirstBit(), INVALID_TRACK, INVALID_TRACK_BIT, and TRACK_BIT_NONE.

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

◆ FindFirstTrackdir()

Trackdir FindFirstTrackdir ( TrackdirBits  trackdirs)
inline

Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR.

This function returns the first Trackdir in the given TrackdirBits value or INVALID_TRACKDIR if the value is TRACKDIR_BIT_NONE. The TrackdirBits must not be INVALID_TRACKDIR_BIT.

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

Definition at line 211 of file track_func.h.

References FindFirstBit(), INVALID_TRACKDIR, TRACKDIR_BIT_MASK, and TRACKDIR_BIT_NONE.

Referenced by ExtendTrainReservation(), FollowReservation(), and CYapfFollowShipT< Types >::GetRandomTrackdir().

◆ HasTrack()

bool HasTrack ( TrackBits  tracks,
Track  track 
)
inline

Checks whether a TrackBits has a given Track.

Parameters
tracksThe track bits.
trackThe track to check.

Definition at line 329 of file track_func.h.

References HasBit(), and IsValidTrack().

◆ HasTrackdir()

bool HasTrackdir ( TrackdirBits  trackdirs,
Trackdir  trackdir 
)
inline

Checks whether a TrackdirBits has a given Trackdir.

Parameters
trackdirsThe trackdir bits.
trackdirThe trackdir to check.

Definition at line 340 of file track_func.h.

References HasBit(), and IsValidTrackdir().

Referenced by CYapfCostRailT< Types >::PfCalcCost(), CYapfDestinationTileT< Types >::PfDetectDestination(), CYapfFollowRoadT< Types >::SetOriginFromVehiclePos(), and YapfRoadVehicleFindNearestDepot().

◆ 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 619 of file track_func.h.

References IsValidTrack(), TRACK_X, and TRACK_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 631 of file track_func.h.

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

Referenced by CYapfCostRailT< Types >::OneTileCost(), CYapfCostRoadT< Types >::OneTileCost(), CYapfCostShipT< Types >::PfCalcCost(), 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 673 of file track_func.h.

References IsValidTrackdirForRoadVehicle().

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

◆ 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 684 of file track_func.h.

References IsValidTrackdirForRoadVehicle().

◆ 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 700 of file track_func.h.

References IsValidTrackdirForRoadVehicle().

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 28 of file track_func.h.

References TRACK_END.

Referenced by HasSignalOnTrack(), HasTrack(), IsDiagonalTrack(), TrackCrossesTracks(), TrackDirectionToTrackdir(), TrackEnterdirToTrackdir(), TrackExitdirToTrackdir(), TrackToOppositeTrack(), TrackToTrackBits(), 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 52 of file track_func.h.

References INVALID_TRACKDIR, TRACKDIR_BIT_MASK, and TRACKDIR_BIT_NONE.

Referenced by GetSignalStateByTrackdir(), HasSignalOnTrackdir(), HasTrackdir(), IsDiagonalTrackdir(), NextTrackdir(), 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 40 of file track_func.h.

References TRACKDIR_END.

Referenced by IsReversingRoadTrackdir(), IsStraightRoadTrackdir(), IsUphillTrackdir(), ReverseTrackdir(), TrackdirCrossesTrackdirs(), 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 403 of file track_func.h.

References 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 INVALID_TRACK if the parameter was TRACK_BIT_NONE or INVALID_TRACK_BIT. This is basically used in while-loops to get up to 6 possible tracks on a tile until the parameter becomes TRACK_BIT_NONE.

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

Definition at line 131 of file track_func.h.

References ClrBit(), FindFirstBit(), INVALID_TRACK, INVALID_TRACK_BIT, TRACK_BIT_MASK, and TRACK_BIT_NONE.

Referenced by CmdConvertRail(), and 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 INVALID_TRACKDIR if the trackdirs is TRACKDIR_BIT_NONE 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 156 of file track_func.h.

References ClrBit(), FindFirstBit(), INVALID_TRACKDIR, INVALID_TRACKDIR_BIT, TRACKDIR_BIT_MASK, and TRACKDIR_BIT_NONE.

Referenced by CYapfFollowShipT< Types >::GetRandomTrackdir().

◆ ReverseTrackdir()

Trackdir ReverseTrackdir ( Trackdir  trackdir)
inline

◆ 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 or be the INVALID_TRACK_BIT value.

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

Definition at line 193 of file track_func.h.

References FindFirstBit(), INVALID_TRACK, INVALID_TRACK_BIT, KillFirstBit(), TRACK_BIT_MASK, and TRACK_BIT_NONE.

Referenced by ChooseShipTrack(), DeleteLastWagon(), and Train::ReserveTrackUnderConsist().

◆ TrackBitsToTrackdirBits()

TrackdirBits TrackBitsToTrackdirBits ( TrackBits  bits)
inline

Converts TrackBits to TrackdirBits while allowing both directions.

Parameters
bitsThe TrackBits
Returns
The TrackdirBits containing of bits in both directions.

Definition at line 319 of file track_func.h.

Referenced by FollowReservation().

◆ 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 420 of file track_func.h.

References IsValidTrack().

Referenced by TrainController(), and TryPathReserve().

◆ TrackdirBitsToTrackBits()

TrackBits TrackdirBitsToTrackBits ( TrackdirBits  bits)
inline

Discards all directional information from a TrackdirBits value.

Any Track which is present in either direction will be present in the result.

Parameters
bitsThe TrackdirBits to get the TrackBits from
Returns
The TrackBits

Definition at line 308 of file track_func.h.

References TRACK_BIT_MASK.

Referenced by DiagdirReachesTracks(), ExtendTrainReservation(), MaskWireBits(), TrackStatusToTrackBits(), TrainController(), and TryPathReserve().

◆ 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 606 of file track_func.h.

References IsValidTrackdirForRoadVehicle().

Referenced by ExtendTrainReservation(), and CYapfFollowShipT< Types >::GetRandomFollowUpTileTrackdir().

◆ 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 584 of file track_func.h.

References IsValidTrackdir().

Referenced by 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 439 of file track_func.h.

References IsValidTrackdirForRoadVehicle().

Referenced by ClearPathReservation(), FollowTrainReservation(), FreeTrainReservation(), GetTrainForReservation(), CYapfCostRailT< Types >::IsAnyStationTileReserved(), CYapfCostRoadT< Types >::OneTileCost(), CYapfDestinationTileT< Types >::PfCalcEstimate(), CYapfDestinationTileOrStationRailT< Types >::PfCalcEstimate(), CYapfDestinationTileRoadT< Types >::PfCalcEstimate(), CYapfDestinationTileWaterT< Types >::PfCalcEstimate(), CYapfReserveTrack< Types >::ReserveSingleTrack(), RestoreTrainReservation(), CYapfCostBase::stSlopeCost(), TryPathReserve(), CYapfReserveTrack< Types >::UnreserveSingleTrack(), and YapfTrainCheckReverse().

◆ TrackdirToTrack()

Track TrackdirToTrack ( Trackdir  trackdir)
inline

Returns the Track that a given Trackdir represents.

This function filters the Track which is used in the Trackdir value and returns it as a Track value.

Parameters
trackdirThe trackdir value
Returns
The Track which is used in the value

Definition at line 262 of file track_func.h.

References IsValidTrackdir().

Referenced by ChooseShipTrack(), ClearPathReservation(), ExtendTrainReservation(), FindTrainOnTrackEnum(), FollowReservation(), GetSignalStateByTrackdir(), HasOnewaySignalBlockingTrackdir(), IsDiagonalTrackdir(), IsWaitingPositionFree(), CYapfReserveTrack< Types >::ReserveSingleTrack(), TryPathReserve(), CYapfReserveTrack< Types >::UnreserveSingleTrack(), UpdateSignalsAroundSegment(), YapfShipChooseTrack(), and YapfTrainChooseTrack().

◆ TrackdirToTrackdirBits()

TrackdirBits TrackdirToTrackdirBits ( Trackdir  trackdir)
inline

Maps a Trackdir to the corresponding TrackdirBits value.

Parameters
trackdirthe track direction to convert
Returns
the converted TrackdirBits value

Definition at line 111 of file track_func.h.

References IsValidTrackdir().

Referenced by CYapfFollowShipT< Types >::CheckShipReverse(), CYapfFollowRoadT< Types >::FindNearestDepot(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), TrackToTrackdirBits(), and YapfShipChooseTrack().

◆ 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 INVALID_TRACKDIR. 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 DIAGDIR_NE (target track cannot be reached) this function returns INVALID_TRACKDIR.

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

Definition at line 486 of file track_func.h.

References 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 INVALID_TRACKDIR, 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 INVALID_TRACKDIR 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 INVALID_TRACKDIR if not possible.

Definition at line 461 of file track_func.h.

References 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 662 of file track_func.h.

References HasBit(), TracksOverlap(), and TrackToTrackBits().

Referenced by IsWaitingPositionFree().

◆ 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 645 of file track_func.h.

References KillFirstBit(), TRACK_BIT_HORZ, TRACK_BIT_NONE, and TRACK_BIT_VERT.

Referenced by AfterLoadCompanyStats(), CmdConvertRail(), GetRailFoundation(), MaskWireBits(), SetTrackReservation(), TrackOverlapsTracks(), and TryReserveTrack().

◆ TrackStatusToRedSignals()

TrackdirBits TrackStatusToRedSignals ( TrackStatus  ts)
inline

Returns the red-signal-information of a TrackStatus.

Note: The result may contain red signals for non-present tracks.

Parameters
tsThe TrackStatus returned by GetTileTrackStatus()
Returns
the The trackdirs that are blocked by red-signals

Definition at line 376 of file track_func.h.

References TRACKDIR_BIT_MASK.

Referenced by TrainController().

◆ TrackStatusToTrackBits()

TrackBits TrackStatusToTrackBits ( TrackStatus  ts)
inline

Returns the present-track-information of a TrackStatus.

Parameters
tsThe TrackStatus returned by GetTileTrackStatus()
Returns
the present tracks

Definition at line 363 of file track_func.h.

References TrackdirBitsToTrackBits(), and TrackStatusToTrackdirBits().

Referenced by DisasterTick_Submarine(), GenericPlaceSignals(), MaskWireBits(), TryReserveRailTrack(), UnreserveRailTrack(), and UpdateSignalsInBuffer().

◆ TrackStatusToTrackdirBits()

TrackdirBits TrackStatusToTrackdirBits ( TrackStatus  ts)
inline

Returns the present-trackdir-information of a TrackStatus.

Parameters
tsThe TrackStatus returned by GetTileTrackStatus()
Returns
the present trackdirs

Definition at line 352 of file track_func.h.

References TRACKDIR_BIT_MASK.

Referenced by CYapfFollowShipT< Types >::CheckShipReverse(), GetTrackdirBitsForRoad(), TrackStatusToTrackBits(), TrainController(), and TryPathReserve().

◆ 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 231 of file track_func.h.

References IsValidTrack().

Referenced by ChooseShipTrack(), and GetRailReservationTrackBits().

◆ TrackToTrackBits()

TrackBits TrackToTrackBits ( Track  track)
inline

Maps a Track to the corresponding TrackBits value.

Parameters
trackthe track to convert
Returns
the converted TrackBits value of the track

Definition at line 77 of file track_func.h.

References IsValidTrack().

Referenced by AdvanceWagonsAfterSwap(), AxisToTrackBits(), DiagDirToDiagTrackBits(), EnsureNoTrainOnTrack(), FollowReservation(), GetDepotReservationTrackBits(), GetRailReservationTrackBits(), GetRailTrackBitsUniversal(), GetTrainForReservation(), TrackOverlapsTracks(), TryReserveTrack(), and UnreserveTrack().

◆ 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 279 of file track_func.h.

References IsValidTrack().

Referenced by 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 294 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 714 of file track_func.h.

References ChangeDiagDir(), DIAGDIR_END, DIAGDIRDIFF_90LEFT, DirToDiagDir(), HasBit(), TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_RIGHT, and TRACK_BIT_UPPER.

Referenced by CYapfFollowShipT< Types >::CheckShipReverse(), and TrainApproachingCrossingTile().