diff --git a/src/direction_func.h b/src/direction_func.h index 657645e283..8889485842 100644 --- a/src/direction_func.h +++ b/src/direction_func.h @@ -14,198 +14,6 @@ #include "direction_type.h" -/** - * Return the reverse of a direction - * - * @param d The direction to get the reverse from - * @return The reverse Direction - */ -static inline Direction ReverseDir(Direction d) -{ - return (Direction)(4 ^ d); -} - - -/** - * Calculate the difference between to directions - * - * @param d0 The first direction as the base - * @param d1 The second direction as the offset from the base - * @return The difference how the second directions drifts of the first one. - */ -static inline DirDiff DirDifference(Direction d0, Direction d1) -{ - /* Cast to uint so compiler can use bitmask. If the difference is negative - * and we used int instead of uint, further "+ 8" would have to be added. */ - return (DirDiff)((uint)(d0 - d1) % 8); -} - -/** - * Applies two differences together - * - * This function adds two differences together and return the resulting - * difference. So adding two DIRDIFF_REVERSE together results in the - * DIRDIFF_SAME difference. - * - * @param d The first difference - * @param delta The second difference to add on - * @return The resulting difference - */ -static inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta) -{ - /* Cast to uint so compiler can use bitmask. Result can never be negative. */ - return (DirDiff)((uint)(d + delta) % 8); -} - -/** - * Change a direction by a given difference - * - * This functions returns a new direction of the given direction - * which is rotated by the given difference. - * - * @param d The direction to get a new direction from - * @param delta The offset/drift applied to the direction - * @return The new direction - */ -static inline Direction ChangeDir(Direction d, DirDiff delta) -{ - /* Cast to uint so compiler can use bitmask. Result can never be negative. */ - return (Direction)((uint)(d + delta) % 8); -} - - -/** - * Returns the reverse direction of the given DiagDirection - * - * @param d The DiagDirection to get the reverse from - * @return The reverse direction - */ -static inline DiagDirection ReverseDiagDir(DiagDirection d) -{ - return (DiagDirection)(2 ^ d); -} - - -/** - * Applies a difference on a DiagDirection - * - * This function applies a difference on a DiagDirection and returns - * the new DiagDirection. - * - * @param d The DiagDirection - * @param delta The difference to apply on - * @return The new direction which was calculated - */ -static inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta) -{ - /* Cast to uint so compiler can use bitmask. Result can never be negative. */ - return (DiagDirection)((uint)(d + delta) % 4); -} - -/** - * Convert a Direction to a DiagDirection. - * - * This function can be used to convert the 8-way Direction to - * the 4-way DiagDirection. If the direction cannot be mapped its - * "rounded clockwise". So DIR_N becomes DIAGDIR_NE. - * - * @param dir The direction to convert - * @return The resulting DiagDirection, maybe "rounded clockwise". - */ -static inline DiagDirection DirToDiagDir(Direction dir) -{ - return (DiagDirection)(dir >> 1); -} - -/** - * Convert a DiagDirection to a Direction. - * - * This function can be used to convert the 4-way DiagDirection - * to the 8-way Direction. As 4-way are less than 8-way not all - * possible directions can be calculated. - * - * @param dir The direction to convert - * @return The resulting Direction - */ -static inline Direction DiagDirToDir(DiagDirection dir) -{ - return (Direction)(dir * 2 + 1); -} - - -/** - * Select the other axis as provided. - * - * This is basically the not-operator for the axis. - * - * @param a The given axis - * @return The other axis - */ -static inline Axis OtherAxis(Axis a) -{ - return (Axis)(a ^ 1); -} - - -/** - * Convert a DiagDirection to the axis. - * - * This function returns the axis which belongs to the given - * DiagDirection. The axis X belongs to the DiagDirection - * north-east and south-west. - * - * @param d The DiagDirection - * @return The axis which belongs to the direction - */ -static inline Axis DiagDirToAxis(DiagDirection d) -{ - return (Axis)(d & 1); -} - - -/** - * Converts an Axis to a DiagDirection - * - * This function returns the DiagDirection which - * belongs to the axis. As 2 directions are mapped to an axis - * this function returns the one which points to south, - * either south-west (on X axis) or south-east (on Y axis) - * - * @param a The axis - * @return The direction pointed to south - */ -static inline DiagDirection AxisToDiagDir(Axis a) -{ - return (DiagDirection)(2 - a); -} - -/** - * Converts an Axis to a Direction - * - * This function returns the Direction which - * belongs to the axis. As 2 directions are mapped to an axis - * this function returns the one which points to south, - * either south-west (on X axis) or south-east (on Y axis) - * - * @param a The axis - * @return The direction pointed to south - */ -static inline Direction AxisToDirection(Axis a) -{ - return (Direction)(5 - 2 * a); -} - -/** - * Convert an axis and a flag for north/south into a DiagDirection - * @param xy axis to convert - * @param ns north -> 0, south -> 1 - * @return the desired DiagDirection - */ -static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns) -{ - return (DiagDirection)(xy * 3 ^ ns * 2); -} - /** * Checks if an integer value is a valid DiagDirection * @@ -239,6 +47,211 @@ static inline bool IsValidAxis(Axis d) return d < AXIS_END; } +/** + * Return the reverse of a direction + * + * @param d The direction to get the reverse from + * @return The reverse Direction + */ +static inline Direction ReverseDir(Direction d) +{ + assert(IsValidDirection(d)); + return (Direction)(4 ^ d); +} + + +/** + * Calculate the difference between to directions + * + * @param d0 The first direction as the base + * @param d1 The second direction as the offset from the base + * @return The difference how the second directions drifts of the first one. + */ +static inline DirDiff DirDifference(Direction d0, Direction d1) +{ + assert(IsValidDirection(d0)); + assert(IsValidDirection(d1)); + /* Cast to uint so compiler can use bitmask. If the difference is negative + * and we used int instead of uint, further "+ 8" would have to be added. */ + return (DirDiff)((uint)(d0 - d1) % 8); +} + +/** + * Applies two differences together + * + * This function adds two differences together and return the resulting + * difference. So adding two DIRDIFF_REVERSE together results in the + * DIRDIFF_SAME difference. + * + * @param d The first difference + * @param delta The second difference to add on + * @return The resulting difference + */ +static inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta) +{ + /* Cast to uint so compiler can use bitmask. Result can never be negative. */ + return (DirDiff)((uint)(d + delta) % 8); +} + +/** + * Change a direction by a given difference + * + * This functions returns a new direction of the given direction + * which is rotated by the given difference. + * + * @param d The direction to get a new direction from + * @param delta The offset/drift applied to the direction + * @return The new direction + */ +static inline Direction ChangeDir(Direction d, DirDiff delta) +{ + assert(IsValidDirection(d)); + /* Cast to uint so compiler can use bitmask. Result can never be negative. */ + return (Direction)((uint)(d + delta) % 8); +} + + +/** + * Returns the reverse direction of the given DiagDirection + * + * @param d The DiagDirection to get the reverse from + * @return The reverse direction + */ +static inline DiagDirection ReverseDiagDir(DiagDirection d) +{ + assert(IsValidDiagDirection(d)); + return (DiagDirection)(2 ^ d); +} + + +/** + * Applies a difference on a DiagDirection + * + * This function applies a difference on a DiagDirection and returns + * the new DiagDirection. + * + * @param d The DiagDirection + * @param delta The difference to apply on + * @return The new direction which was calculated + */ +static inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta) +{ + assert(IsValidDiagDirection(d)); + /* Cast to uint so compiler can use bitmask. Result can never be negative. */ + return (DiagDirection)((uint)(d + delta) % 4); +} + +/** + * Convert a Direction to a DiagDirection. + * + * This function can be used to convert the 8-way Direction to + * the 4-way DiagDirection. If the direction cannot be mapped its + * "rounded clockwise". So DIR_N becomes DIAGDIR_NE. + * + * @param dir The direction to convert + * @return The resulting DiagDirection, maybe "rounded clockwise". + */ +static inline DiagDirection DirToDiagDir(Direction dir) +{ + assert(IsValidDirection(dir)); + return (DiagDirection)(dir >> 1); +} + +/** + * Convert a DiagDirection to a Direction. + * + * This function can be used to convert the 4-way DiagDirection + * to the 8-way Direction. As 4-way are less than 8-way not all + * possible directions can be calculated. + * + * @param dir The direction to convert + * @return The resulting Direction + */ +static inline Direction DiagDirToDir(DiagDirection dir) +{ + assert(IsValidDiagDirection(dir)); + return (Direction)(dir * 2 + 1); +} + + +/** + * Select the other axis as provided. + * + * This is basically the not-operator for the axis. + * + * @param a The given axis + * @return The other axis + */ +static inline Axis OtherAxis(Axis a) +{ + assert(IsValidAxis(a)); + return (Axis)(a ^ 1); +} + + +/** + * Convert a DiagDirection to the axis. + * + * This function returns the axis which belongs to the given + * DiagDirection. The axis X belongs to the DiagDirection + * north-east and south-west. + * + * @param d The DiagDirection + * @return The axis which belongs to the direction + */ +static inline Axis DiagDirToAxis(DiagDirection d) +{ + assert(IsValidDiagDirection(d)); + return (Axis)(d & 1); +} + + +/** + * Converts an Axis to a DiagDirection + * + * This function returns the DiagDirection which + * belongs to the axis. As 2 directions are mapped to an axis + * this function returns the one which points to south, + * either south-west (on X axis) or south-east (on Y axis) + * + * @param a The axis + * @return The direction pointed to south + */ +static inline DiagDirection AxisToDiagDir(Axis a) +{ + assert(IsValidAxis(a)); + return (DiagDirection)(2 - a); +} + +/** + * Converts an Axis to a Direction + * + * This function returns the Direction which + * belongs to the axis. As 2 directions are mapped to an axis + * this function returns the one which points to south, + * either south-west (on X axis) or south-east (on Y axis) + * + * @param a The axis + * @return The direction pointed to south + */ +static inline Direction AxisToDirection(Axis a) +{ + assert(IsValidAxis(a)); + return (Direction)(5 - 2 * a); +} + +/** + * Convert an axis and a flag for north/south into a DiagDirection + * @param xy axis to convert + * @param ns north -> 0, south -> 1 + * @return the desired DiagDirection + */ +static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns) +{ + assert(IsValidAxis(xy)); + return (DiagDirection)(xy * 3 ^ ns * 2); +} + /** * Checks if a given Direction is diagonal. * @@ -247,6 +260,7 @@ static inline bool IsValidAxis(Axis d) */ static inline bool IsDiagonalDirection(Direction dir) { + assert(IsValidDirection(dir)); return (dir & 1) != 0; } diff --git a/src/road_func.h b/src/road_func.h index bfe261980c..c4af229d53 100644 --- a/src/road_func.h +++ b/src/road_func.h @@ -37,6 +37,16 @@ static inline bool IsValidRoadType(RoadType rt) return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM; } +/** + * Whether the given roadtype is valid. + * @param rt the roadtype to check for validness + * @return true if and only if valid + */ +static inline bool IsValidRoadBits(RoadBits r) +{ + return r < ROAD_END; +} + /** * Maps a RoadType to the corresponding RoadTypes value * @@ -45,6 +55,7 @@ static inline bool IsValidRoadType(RoadType rt) */ static inline RoadTypes RoadTypeToRoadTypes(RoadType rt) { + assert(IsValidRoadType(rt)); return (RoadTypes)(1 << rt); } @@ -73,6 +84,7 @@ static inline RoadTypes ComplementRoadTypes(RoadTypes r) */ static inline RoadBits ComplementRoadBits(RoadBits r) { + assert(IsValidRoadBits(r)); return (RoadBits)(ROAD_ALL ^ r); } @@ -86,6 +98,7 @@ static inline RoadBits ComplementRoadBits(RoadBits r) */ static inline RoadBits MirrorRoadBits(RoadBits r) { + assert(IsValidRoadBits(r)); return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2)); } @@ -100,6 +113,7 @@ static inline RoadBits MirrorRoadBits(RoadBits r) */ static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot) { + assert(IsValidRoadBits(r)); for (; rot > (DiagDirDiff)0; rot--) { r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3)); } @@ -114,6 +128,7 @@ static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot) */ static inline bool IsStraightRoad(RoadBits r) { + assert(IsValidRoadBits(r)); return (r == ROAD_X || r == ROAD_Y); } @@ -128,6 +143,7 @@ static inline bool IsStraightRoad(RoadBits r) */ static inline RoadBits DiagDirToRoadBits(DiagDirection d) { + assert(IsValidDiagDirection(d)); return (RoadBits)(ROAD_NW << (3 ^ d)); } @@ -142,6 +158,7 @@ static inline RoadBits DiagDirToRoadBits(DiagDirection d) */ static inline RoadBits AxisToRoadBits(Axis a) { + assert(IsValidAxis(a)); return a == AXIS_X ? ROAD_X : ROAD_Y; } @@ -154,7 +171,7 @@ static inline RoadBits AxisToRoadBits(Axis a) */ static inline Money RoadMaintenanceCost(RoadType roadtype, uint32 num) { - assert(roadtype < ROADTYPE_END); + assert(IsValidRoadType(roadtype)); return (_price[PR_INFRASTRUCTURE_ROAD] * (roadtype == ROADTYPE_TRAM ? 3 : 2) * num * (1 + IntSqrt(num))) >> 9; // 2 bits fraction for the multiplier and 7 bits scaling. } diff --git a/src/track_func.h b/src/track_func.h index 0cd3dcf316..6896792374 100644 --- a/src/track_func.h +++ b/src/track_func.h @@ -14,6 +14,7 @@ #include "core/bitmath_func.hpp" #include "track_type.h" +#include "direction_func.h" #include "slope_func.h" /** @@ -27,6 +28,42 @@ */ #define FOR_EACH_SET_TRACK(var, track_bits) FOR_EACH_SET_BIT_EX(Track, var, TrackBits, track_bits) +/** + * Checks if a Track is valid. + * + * @param track The value to check + * @return true if the given value is a valid track. + * @note Use this in an assert() + */ +static inline bool IsValidTrack(Track track) +{ + return track < TRACK_END; +} + +/** + * Checks if a Trackdir is valid for road vehicles. + * + * @param trackdir The value to check + * @return true if the given value is a valid Trackdir + * @note Use this in an assert() + */ +static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir) +{ + return trackdir < TRACKDIR_END; +} + +/** + * Checks if a Trackdir is valid for non-road vehicles. + * + * @param trackdir The value to check + * @return true if the given value is a valid Trackdir + * @note Use this in an assert() + */ +static inline bool IsValidTrackdir(Trackdir trackdir) +{ + return (1 << trackdir & TRACKDIR_BIT_MASK) != 0; +} + /** * Convert an Axis to the corresponding Track * AXIS_X -> TRACK_X @@ -38,6 +75,7 @@ */ static inline Track AxisToTrack(Axis a) { + assert(IsValidAxis(a)); return (Track)a; } @@ -48,6 +86,7 @@ static inline Track AxisToTrack(Axis a) */ static inline TrackBits TrackToTrackBits(Track track) { + assert(IsValidTrack(track)); return (TrackBits)(1 << track); } @@ -74,8 +113,6 @@ static inline TrackBits CornerToTrackBits(Corner corner) return _corner_to_trackbits[corner]; } - - /** * Maps a Trackdir to the corresponding TrackdirBits value * @param trackdir the track direction to convert @@ -83,6 +120,7 @@ static inline TrackBits CornerToTrackBits(Corner corner) */ static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { + assert(IsValidTrackdir(trackdir)); return (TrackdirBits)(1 << trackdir); } @@ -103,6 +141,7 @@ static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) static inline Track RemoveFirstTrack(TrackBits *tracks) { if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) { + assert((*tracks & ~TRACK_BIT_MASK) == TRACK_BIT_NONE); Track first = (Track)FIND_FIRST_BIT(*tracks); ClrBit(*tracks, first); return first; @@ -127,6 +166,7 @@ static inline Track RemoveFirstTrack(TrackBits *tracks) static inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs) { if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) { + assert((*trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE); Trackdir first = (Trackdir)FindFirstBit2x64(*trackdirs); ClrBit(*trackdirs, first); return first; @@ -184,31 +224,6 @@ static inline Trackdir FindFirstTrackdir(TrackdirBits trackdirs) return (trackdirs != TRACKDIR_BIT_NONE) ? (Trackdir)FindFirstBit2x64(trackdirs) : INVALID_TRACKDIR; } -/** - * Checks if a Track is valid. - * - * @param track The value to check - * @return true if the given value is a valid track. - * @note Use this in an assert() - */ -static inline bool IsValidTrack(Track track) -{ - return track < TRACK_END; -} - -/** - * Checks if a Trackdir is valid. - * - * @param trackdir The value to check - * @return true if the given value is a valid Trackdir - * @note Use this in an assert() - */ -static inline bool IsValidTrackdir(Trackdir trackdir) -{ - return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; -} - - /* * Functions describing logical relations between Tracks, TrackBits, Trackdirs * TrackdirBits, Direction and DiagDirections. @@ -225,7 +240,7 @@ static inline bool IsValidTrackdir(Trackdir trackdir) */ static inline Track TrackToOppositeTrack(Track t) { - assert(t != INVALID_TRACK); + assert(IsValidTrack(t)); return (Track)(t ^ 1); } @@ -241,7 +256,7 @@ static inline Track TrackToOppositeTrack(Track t) */ static inline Trackdir ReverseTrackdir(Trackdir trackdir) { - assert(trackdir != INVALID_TRACKDIR); + assert(IsValidTrackdirForRoadVehicle(trackdir)); return (Trackdir)(trackdir ^ 8); } @@ -256,6 +271,7 @@ static inline Trackdir ReverseTrackdir(Trackdir trackdir) */ static inline Track TrackdirToTrack(Trackdir trackdir) { + assert(IsValidTrackdir(trackdir)); return (Track)(trackdir & 0x7); } @@ -272,6 +288,7 @@ static inline Track TrackdirToTrack(Trackdir trackdir) */ static inline Trackdir TrackToTrackdir(Track track) { + assert(IsValidTrack(track)); return (Trackdir)track; } @@ -373,6 +390,7 @@ static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, Trackdir */ static inline Trackdir NextTrackdir(Trackdir trackdir) { + assert(IsValidTrackdir(trackdir)); extern const Trackdir _next_trackdir[TRACKDIR_END]; return _next_trackdir[trackdir]; } @@ -389,6 +407,7 @@ static inline Trackdir NextTrackdir(Trackdir trackdir) */ static inline TrackBits TrackCrossesTracks(Track track) { + assert(IsValidTrack(track)); extern const TrackBits _track_crosses_tracks[TRACK_END]; return _track_crosses_tracks[track]; } @@ -407,6 +426,7 @@ static inline TrackBits TrackCrossesTracks(Track track) */ static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) { + assert(IsValidTrackdirForRoadVehicle(trackdir)); extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END]; return _trackdir_to_exitdir[trackdir]; } @@ -428,6 +448,8 @@ static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) */ static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) { + assert(IsValidTrack(track)); + assert(IsValidDiagDirection(diagdir)); extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END]; return _track_exitdir_to_trackdir[track][diagdir]; } @@ -451,6 +473,8 @@ static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir */ static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) { + assert(IsValidTrack(track)); + assert(IsValidDiagDirection(diagdir)); extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END]; return _track_enterdir_to_trackdir[track][diagdir]; } @@ -461,6 +485,8 @@ static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdi */ static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) { + assert(IsValidTrack(track)); + assert(IsValidDirection(dir)); extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END]; return _track_direction_to_trackdir[track][dir]; } @@ -473,6 +499,7 @@ static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) */ static inline Track DiagDirToDiagTrack(DiagDirection diagdir) { + assert(IsValidDiagDirection(diagdir)); return (Track)(diagdir & 1); } @@ -484,6 +511,7 @@ static inline Track DiagDirToDiagTrack(DiagDirection diagdir) */ static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir) { + assert(IsValidDiagDirection(diagdir)); return TrackToTrackBits(DiagDirToDiagTrack(diagdir)); } @@ -496,6 +524,7 @@ static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir) */ static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir) { + assert(IsValidDiagDirection(diagdir)); extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END]; return _dir_to_diag_trackdir[diagdir]; } @@ -513,6 +542,7 @@ static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir) */ static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir) { + assert(IsValidDiagDirection(diagdir)); extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; return _exitdir_reaches_trackdirs[diagdir]; } @@ -541,6 +571,7 @@ static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return Tra */ static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { + assert(IsValidTrackdir(trackdir)); extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; } @@ -562,6 +593,7 @@ static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) */ static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) { + assert(IsValidTrackdirForRoadVehicle(trackdir)); extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END]; return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; } @@ -574,6 +606,7 @@ static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) */ static inline bool IsDiagonalTrack(Track track) { + assert(IsValidTrack(track)); return (track == TRACK_X) || (track == TRACK_Y); } @@ -585,6 +618,7 @@ static inline bool IsDiagonalTrack(Track track) */ static inline bool IsDiagonalTrackdir(Trackdir trackdir) { + assert(IsValidTrackdir(trackdir)); return IsDiagonalTrack(TrackdirToTrack(trackdir)); } @@ -626,6 +660,7 @@ static inline bool TrackOverlapsTracks(TrackBits tracks, Track track) */ static inline bool IsReversingRoadTrackdir(Trackdir dir) { + assert(IsValidTrackdirForRoadVehicle(dir)); return (dir & 0x07) >= 6; } @@ -636,6 +671,7 @@ static inline bool IsReversingRoadTrackdir(Trackdir dir) */ static inline bool IsStraightRoadTrackdir(Trackdir dir) { + assert(IsValidTrackdirForRoadVehicle(dir)); return (dir & 0x06) == 0; } @@ -651,6 +687,7 @@ static inline bool IsStraightRoadTrackdir(Trackdir dir) */ static inline bool IsUphillTrackdir(Slope slope, Trackdir dir) { + assert(IsValidTrackdirForRoadVehicle(dir)); extern const TrackdirBits _uphill_trackdirs[]; return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir); }