From b7993793c813359ba4963df93d49a80335ddca36 Mon Sep 17 00:00:00 2001 From: frosch Date: Wed, 20 Feb 2008 17:49:50 +0000 Subject: (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus(). --- src/track_func.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/track_func.h') 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 @@ -273,6 +273,64 @@ static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK); } +/** + * 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. -- cgit v1.2.3-54-g00ecf