# 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_type.h"`
`#include "slope_func.h"`

Go to the source code of this file.

## Functions

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

## Detailed Description

Different conversion functions from one kind of track to another.

Definition in file track_func.h.

## Function Documentation

static Track AxisToTrack | ( | Axis | a | ) | `[inline, static]`

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:

  | a | the axis to convert

Returns:
  the track corresponding to the axis

Definition at line 22 of file track_func.h.

Referenced by AxisToTrackBits(), CmdBuildBridge(), CmdBuildRailroadStation(), CmdBuildRoad(), CmdBuildTrainWaypoint(), and GetRailWaypointTrack().

static TrackBits AxisToTrackBits | ( | Axis | a | ) | `[inline, static]`

Maps an Axis to the corresponding TrackBits value.

Parameters:

  | a | the axis to convert

Returns:
  the converted TrackBits value of the axis

Definition at line 42 of file track_func.h.

References AxisToTrack(), and TrackToTrackBits().

Referenced by GetRailStationReservation().

static TrackStatus CombineTrackStatus | ( | TrackdirBits | trackdirbits,
|  | TrackdirBits | red_signals |
| ) |  |  | `[inline, static]`

Builds a TrackStatus.

Parameters:

  | trackdirbits | present trackdirs
  | red_signals | red signals

Returns:
  the TrackStatus representing the given information

Definition at line 342 of file track_func.h.

static TrackBits CornerToTrackBits | ( | Corner | corner | ) | `[inline, static]`

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

Parameters:

  | corner | The corner of a tile.

Returns:
  The TrackBits of the track in the corner.

Definition at line 53 of file track_func.h.

References IsValidCorner().

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

static TrackdirBits DiagdirReachesTrackdirs | ( | DiagDirection | diagdir | ) | `[inline, static]`

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:

  | diagdir | The joining direction

Returns:
  The TrackdirBits which can be used from the given direction

See also:
  DiagdirReachesTracks

Definition at line 497 of file track_func.h.

References DIAGDIR_END.

Referenced by DiagdirReachesTracks(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), IsSafeWaitingPosition(), IsWaitingPositionFree(), MaskWireBits(), TrainCheckIfLineEnds(), TryPathReserve(), and CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::TryReverse().

static TrackBits DiagdirReachesTracks | ( | DiagDirection | diagdir | ) | `[inline, static]`

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:

  | diagdir | The joining irection

Returns:
  The tracks which can be used

See also:
  DiagdirReachesTrackdirs

Definition at line 514 of file track_func.h.

References DiagdirReachesTrackdirs(), and TrackdirBitsToTrackBits().

Referenced by AIMarine::AreWaterTilesConnected(), MaskWireBits(), and TryPathReserve().

static Track DiagDirToDiagTrack | ( | DiagDirection | diagdir | ) | `[inline, static]`

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

Parameters:

  | diagdir | The direction

Returns:
  The resulting Track

Definition at line 457 of file track_func.h.

Referenced by CmdBuildTrainDepot(), CmdBuildTunnel(), CmdConvertRail(), DiagDirToDiagTrackBits(), and GetRailDepotTrack().

static TrackBits DiagDirToDiagTrackBits | ( | DiagDirection | diagdir | ) | `[inline, static]`

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

Parameters:

  | diagdir | The direction

Returns:
  The resulting TrackBits

Definition at line 468 of file track_func.h.

References DiagDirToDiagTrack(), and TrackToTrackBits().

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

static Trackdir DiagDirToDiagTrackdir | ( | DiagDirection | diagdir | ) | `[inline, static]`

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

Parameters:

  | diagdir | The direction

Returns:
  The resulting Trackdir direction

Definition at line 480 of file track_func.h.

References DIAGDIR_END.

Referenced by GetVehicleTrackdir(), and RoadFindPathToDest().

static Track FindFirstTrack | ( | TrackBits | tracks | ) | `[inline, static]`

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:

  | tracks | The TrackBits value

Returns:
  The first Track found or INVALID_TRACK

See also:
  RemoveFirstTrack

Definition at line 130 of file track_func.h.

References FIND_FIRST_BIT, INVALID_TRACK, INVALID_TRACK_BIT, and TRACK_BIT_NONE.

Referenced by AIRail::BuildRailTrack(), DoTrainPathfind(), GenericPlaceSignals(), GetVehicleTrackdir(), AIRail::RemoveRailTrack(), and TrainCheckIfLineEnds().

static Trackdir FindFirstTrackdir | ( | TrackdirBits | trackdirs | ) | `[inline, static]`

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:

  | trackdirs | The 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 164 of file track_func.h.

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

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

static bool IsDiagonalTrack | ( | Track | track | ) | `[inline, static]`

Checks if a given Track is diagonal.

Parameters:

  | track | The given track to check

Returns:
  true if diagonal, else false

Definition at line 558 of file track_func.h.

References TRACK_X, and TRACK_Y.

Referenced by IsDiagonalTrackdir().

static bool IsDiagonalTrackdir | ( | Trackdir | trackdir | ) | `[inline, static]`

Checks if a given Trackdir is diagonal.

Parameters:

  | trackdir | The given trackdir

Returns:
  true if the trackdir use a diagonal track

Definition at line 569 of file track_func.h.

References IsDiagonalTrack(), and TrackdirToTrack().

Referenced by CmdRailTrackHelper(), CmdSignalTrackHelper(), and CYapfCostShipT< Types >::PfCalcCost().

static bool IsReversingRoadTrackdir | ( | Trackdir | dir | ) | `[inline, static]`

Checks whether the trackdir means that we are reversing.

Parameters:

  | dir | the trackdir to check

Returns:
  true if it is a reversing road trackdir

Definition at line 610 of file track_func.h.

Referenced by GetVehicleTrackdir().

static bool IsStraightRoadTrackdir | ( | Trackdir | dir | ) | `[inline, static]`

Checks whether the given trackdir is a straight road.

Parameters:

  | dir | the trackdir to check

Returns:
  true if it is a straight road trackdir

Definition at line 620 of file track_func.h.

static bool IsUphillTrackdir | ( | Slope | slope,
|  | Trackdir | dir |
| ) |  |  | `[inline, static]`

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:

  | slope | The slope of the tile.
  | dir | The trackdir of interest.

Returns:
  true iff the track goes upwards.

Definition at line 635 of file track_func.h.

References HasBit(), and RemoveHalftileSlope().

static bool IsValidTrack | ( | Track | track | ) | `[inline, static]`

Checks if a Track is valid.

Parameters:

  | track | The value to check

Returns:
  true if the given value is a valid track.

Note:
  Use this in an assert()

Definition at line 177 of file track_func.h.

References TRACK_END.

Referenced by HasSignalOnTrack().

static bool IsValidTrackdir | ( | Trackdir | trackdir | ) | `[inline, static]`

Checks if a Trackdir is valid.

Parameters:

  | trackdir | The value to check

Returns:
  true if the given valie is a valid Trackdir

Note:
  Use this in an assert()

Definition at line 189 of file track_func.h.

References TRACKDIR_BIT_MASK, and TrackdirToTrackdirBits().

Referenced by DoTrainPathfind(), FreeTrainTrackReservation(), GetSignalStateByTrackdir(), HasSignalOnTrackdir(), and NPFHash().

static Trackdir NextTrackdir | ( | Trackdir | trackdir | ) | `[inline, static]`

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:

  | trackdir | The given trackdir

Returns:
  The next Trackdir value of the next tile.

Definition at line 357 of file track_func.h.

References TRACKDIR_END.

Referenced by CYapfCostShipT< Types >::PfCalcCost().

static Track RemoveFirstTrack | ( | TrackBits * | tracks | ) | `[inline, static]`

Removes first Track from TrackBits and returns it.

This function searchs 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:

  | tracks | The value with the TrackBits

Returns:
  The first Track from the TrackBits value

See also:
  FindFirstTrack

Definition at line 86 of file track_func.h.

References ClrBit(), FIND_FIRST_BIT, INVALID_TRACK, INVALID_TRACK_BIT, and TRACK_BIT_NONE.

Referenced by CmdConvertRail(), and SetTrackReservation().

static Trackdir RemoveFirstTrackdir | ( | TrackdirBits * | trackdirs | ) | `[inline, static]`

Removes first Trackdir from TrackdirBits and returns it.

This function searchs 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:

  | trackdirs | The value with the TrackdirBits

Returns:
  The first Trackdir from the TrackdirBits value

See also:
  FindFirstTrackdir

Definition at line 110 of file track_func.h.

References ClrBit(), FindFirstBit2x64(), INVALID_TRACKDIR, INVALID_TRACKDIR_BIT, and TRACKDIR_BIT_NONE.

Referenced by FreeTrainTrackReservation().

static Trackdir ReverseTrackdir | ( | Trackdir | trackdir | ) | `[inline, static]`

Maps a trackdir to the reverse trackdir.

Returns the reverse trackdir of a Trackdir value. The reverse trackdir is the same track with the other direction on it.

Parameters:

  | trackdir | The Trackdir value

Returns:
  The reverse trackdir

Precondition:
  trackdir must not be INVALID_TRACKDIR

Definition at line 225 of file track_func.h.

References INVALID_TRACKDIR.

Referenced by CmdBuildRailroadStation(), CmdRemoveFromRailroadStation(), ExploreSegment(), FindClosestTrainDepot(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), FreeTrainTrackReservation(), AIRail::GetSignalType(), GetTrainForReservation(), HasOnewaySignalBlockingTrackdir(), TrackToTrackdirBits(), TryPathReserve(), UpdateSignalsAroundSegment(), YapfCheckReverseTrain(), and YapfFindNearestRailDepotTwoWay().

static Track TrackBitsToTrack | ( | TrackBits | tracks | ) | `[inline, static]`

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:

  | tracks | The 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 146 of file track_func.h.

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

Referenced by DeleteLastWagon(), and ExploreSegment().

static TrackdirBits TrackBitsToTrackdirBits | ( | TrackBits | bits | ) | `[inline, static]`

Converts TrackBits to TrackdirBits while allowing both directions.

Parameters:

  | bits | The TrackBits

Returns:
  The TrackdirBits containing of bits in both directions.

Definition at line 295 of file track_func.h.

Referenced by FollowReservation(), FreeTrainTrackReservation(), and TryPathReserve().

static TrackBits TrackCrossesTracks | ( | Track | track | ) | `[inline, static]`

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:

  | track | The given track

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

Definition at line 373 of file track_func.h.

References TRACK_END.

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

static TrackBits TrackdirBitsToTrackBits | ( | TrackdirBits | bits | ) | `[inline, static]`

Discards all directional information from a TrackdirBits value.

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

Parameters:

  | bits | The TrackdirBits to get the TrackBits from

Returns:
  The TrackBits

Definition at line 284 of file track_func.h.

References TRACK_BIT_MASK.

Referenced by CheckNextTrainTile(), CheckRoadBlockedForOvertaking(), DiagdirReachesTracks(), ExtendTrainReservation(), IsWaitingPositionFree(), MaskWireBits(), TrackStatusToTrackBits(), TrainCheckIfLineEnds(), and TryPathReserve().

static TrackdirBits TrackdirCrossesTrackdirs | ( | Trackdir | trackdir | ) | `[inline, static]`

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:

  | trackdir | The track direction

Returns:
  The TrackdirBits which are (more or less) 90 deg turns.

Definition at line 546 of file track_func.h.

References TRACKDIR_END, and TrackdirToTrack().

Referenced by ExtendTrainReservation(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetDriveableTrackdirBits(), IsSafeWaitingPosition(), and IsWaitingPositionFree().

static TrackdirBits TrackdirReachesTrackdirs | ( | Trackdir | trackdir | ) | `[inline, static]`

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:

  | trackdir | The track direction which will be leaved

Returns:
  The track directions which can be used from this direction (in the next tile)

Definition at line 525 of file track_func.h.

References DIAGDIR_END, and TrackdirToExitdir().

Referenced by ExtendTrainReservation(), and GetDriveableTrackdirBits().

static DiagDirection TrackdirToExitdir | ( | Trackdir | trackdir | ) | `[inline, static]`

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:

  | trackdir | The given track direction

Returns:
  The direction which points to the resulting tile if following the Trackdir

Definition at line 391 of file track_func.h.

References TRACKDIR_END.

Referenced by CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), ClearPathReservation(), CmdBuildRailroadStation(), CmdRemoveFromRailroadStation(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetTrainForReservation(), NPFSaveTargetData(), CYapfDestinationTileT< Types >::PfCalcEstimate(), TrackdirReachesTrackdirs(), TryPathReserve(), UpdateSignalsAroundSegment(), and YapfCheckReverseTrain().

static Track TrackdirToTrack | ( | Trackdir | trackdir | ) | `[inline, static]`

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:

  | trackdir | The trackdir value

Returns:
  The Track which is used in the value

Definition at line 240 of file track_func.h.

Referenced by CheckNextTrainTile(), ChooseShipTrack(), ClearPathReservation(), CmdRailTrackHelper(), CmdSignalTrackHelper(), DoTrainPathfind(), ExtendTrainReservation(), FindTrainOnTrackEnum(), FollowReservation(), FreeTrainTrackReservation(), GetSignalStateByTrackdir(), HasOnewaySignalBlockingTrackdir(), HasPbsSignalOnTrackdir(), IsDiagonalTrackdir(), IsSafeWaitingPosition(), IsWaitingPositionFree(), NPFSaveTargetData(), TrackdirCrossesTrackdirs(), TryPathReserve(), and UpdateSignalsAroundSegment().

static TrackdirBits TrackdirToTrackdirBits | ( | Trackdir | trackdir | ) | `[inline, static]`

Maps a Trackdir to the corresponding TrackdirBits value.

Parameters:

  | trackdir | the track direction to convert

Returns:
  the converted TrackdirBits value

Definition at line 67 of file track_func.h.

Referenced by CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::ForcedReverse(), IsValidTrackdir(), CYapfDestinationTileT< Types >::PfDetectDestination(), TrackToTrackdirBits(), and YapfFindNearestRoadDepot().

static Trackdir TrackEnterdirToTrackdir | ( | Track | track,
|  | DiagDirection | diagdir |
| ) |  |  | `[inline, static]`

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

Parameters:

  | track | The target track
  | diagdir | The direction to "come from"

Returns:
  the resulting Trackdir or INVALID_TRACKDIR if not possible.

Definition at line 435 of file track_func.h.

References DIAGDIR_END, and TRACK_END.

static Trackdir TrackExitdirToTrackdir | ( | Track | track,
|  | DiagDirection | diagdir |
| ) |  |  | `[inline, static]`

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:

  | track | The track to applie an direction on
  | diagdir | The DiagDirection to applie on

Returns:
  The resulting track direction or INVALID_TRACKDIR if not possible.

Definition at line 412 of file track_func.h.

References DIAGDIR_END, and TRACK_END.

static bool TrackOverlapsTracks | ( | TrackBits | tracks,
|  | Track | track |
| ) |  |  | `[inline, static]`

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

Parameters:

  | tracks | Tracks to be testet against
  | track | The track to test

Returns:
  true if the track is already in the tracks or overlaps the tracks.

Definition at line 599 of file track_func.h.

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

Referenced by IsWaitingPositionFree().

static bool TracksOverlap | ( | TrackBits | bits | ) | `[inline, static]`

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

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

Parameters:

  | bits | The tracks present.

Returns:
  Whether the tracks present overlap in any way.

Definition at line 582 of file track_func.h.

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

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

static TrackdirBits TrackStatusToRedSignals | ( | TrackStatus | ts | ) | `[inline, static]`

Returns the red-signal-information of a TrackStatus.

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

Parameters:

  | ts | The TrackStatus returned by GetTileTrackStatus()

Returns:
  the The trackdirs that are blocked by red-signals

Definition at line 330 of file track_func.h.

References TRACKDIR_BIT_MASK.

Referenced by CheckRoadBlockedForOvertaking(), RoadFindPathToDest(), and TrainCheckIfLineEnds().

static TrackBits TrackStatusToTrackBits | ( | TrackStatus | ts | ) | `[inline, static]`

Returns the present-track-information of a TrackStatus.

Parameters:

  | ts | The TrackStatus returned by GetTileTrackStatus()

Returns:
  the present tracks

Definition at line 317 of file track_func.h.

References TrackdirBitsToTrackBits(), and TrackStatusToTrackdirBits().

Referenced by AIMarine::AreWaterTilesConnected(), DisasterTick_Submarine(), GenericPlaceSignals(), GetAnyRoadTrackBits(), MaskWireBits(), and UpdateSignalsInBuffer().

static TrackdirBits TrackStatusToTrackdirBits | ( | TrackStatus | ts | ) | `[inline, static]`

Returns the present-trackdir-information of a TrackStatus.

Parameters:

  | ts | The TrackStatus returned by GetTileTrackStatus()

Returns:
  the present trackdirs

Definition at line 306 of file track_func.h.

References TRACKDIR_BIT_MASK.

Referenced by CheckRoadBlockedForOvertaking(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::Follow(), GetDriveableTrackdirBits(), AITile::HasTransportType(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_, Tmask_reserved_tracks >::QueryNewTileTrackStatus(), RoadFindPathToDest(), TrackStatusToTrackBits(), TrainCheckIfLineEnds(), TryPathReserve(), and YapfFindNearestRoadDepot().

static Track TrackToOppositeTrack | ( | Track | t | ) | `[inline, static]`

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:

  | t | the track to convert

Returns:
  the opposite track

Definition at line 209 of file track_func.h.

References INVALID_TRACK.

Referenced by GetTrackReservation().

static TrackBits TrackToTrackBits | ( | Track | track | ) | `[inline, static]`

Maps a Track to the corresponding TrackBits value.

Parameters:

  | track | the track to convert

Returns:
  the converted TrackBits value of the track

Definition at line 32 of file track_func.h.

Referenced by AdvanceWagonsAfterSwap(), AxisToTrackBits(), AIRail::BuildSignal(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), DiagDirToDiagTrackBits(), EnsureNoTrainOnTrack(), FollowReservation(), FreeTrainTrackReservation(), GetRailDepotReservation(), GetRailTrackBitsUniversal(), AIRail::GetRailTracks(), GetRailWaypointBits(), AIRail::GetSignalType(), GetTrackReservation(), GetTrainForReservation(), AIRail::RemoveSignal(), TrackOverlapsTracks(), TryReserveRailTrack(), TryReserveTrack(), UnreserveRailTrack(), and UnreserveTrack().

static Trackdir TrackToTrackdir | ( | Track | track | ) | `[inline, static]`

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:

  | track | The given Track

Returns:
  The Trackdir from the given Track

Definition at line 256 of file track_func.h.

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

static TrackdirBits TrackToTrackdirBits | ( | Track | track | ) | `[inline, static]`

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:

  | track | The track to get the TrackdirBits from

Returns:
  The TrackdirBits which the selected tracks

Definition at line 270 of file track_func.h.

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