diff options
Diffstat (limited to 'src/track_func.h')
-rw-r--r-- | src/track_func.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/track_func.h b/src/track_func.h index 47364b8c0..38a1bba66 100644 --- a/src/track_func.h +++ b/src/track_func.h @@ -274,6 +274,64 @@ static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) } /** + * Converts TrackBits to TrackdirBits while allowing both directions. + * + * @param bits The TrackBits + * @return The TrackDirBits containing of bits in both directions. + */ +static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits) +{ + return (TrackdirBits)(bits * 0x101); +} + +/** + * Returns the present-trackdir-information of a TrackStatus. + * + * @param ts The TrackStatus returned by GetTileTrackStatus() + * @return the present trackdirs + */ +static inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts) +{ + return (TrackdirBits)(ts & TRACKDIR_BIT_MASK); +} + +/** + * Returns the present-track-information of a TrackStatus. + * + * @param ts The TrackStatus returned by GetTileTrackStatus() + * @return the present tracks + */ +static inline TrackBits TrackStatusToTrackBits(TrackStatus ts) +{ + return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts)); +} + +/** + * Returns the red-signal-information of a TrackStatus. + * + * Note: The result may contain red signals for non-present tracks. + * + * @param ts The TrackStatus returned by GetTileTrackStatus() + * @return the The trackdirs that are blocked by red-signals + */ +static inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts) +{ + return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK); +} + +/** + * Builds a TrackStatus + * + * @param trackdirbits present trackdirs + * @param red_signals red signals + * @return the TrackStatus representing the given information + */ +static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals) +{ + return (TrackStatus)(trackdirbits | (red_signals << 16)); +} + +/** * Maps a trackdir to the trackdir that you will end up on if you go straight * ahead. * |