From f4721fed8709db7069efb76a160117c4fcdef057 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 5 Oct 2007 19:36:13 +0000 Subject: (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch. --- src/slope.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'src/slope.h') diff --git a/src/slope.h b/src/slope.h index dd04c24be..db8b17a12 100644 --- a/src/slope.h +++ b/src/slope.h @@ -40,6 +40,16 @@ enum Slope { SLOPE_STEEP_N = SLOPE_STEEP | SLOPE_ENW ///< a steep slope falling to south (from north) }; +/** + * Enumeration of tile corners + */ +enum Corner { + CORNER_W = 0, + CORNER_S = 1, + CORNER_E = 2, + CORNER_N = 3, +}; + /** * Checks if a slope is steep. * @@ -73,19 +83,19 @@ static inline Slope ComplementSlope(Slope s) * * @pre The slope must be a slope with one corner raised or a steep slope. * @param s The #Slope. - * @return Number of the highest corner. (0 west, 1 south, 2 east, 3 north) + * @return Highest corner. */ -static inline byte GetHighestSlopeCorner(Slope s) +static inline Corner GetHighestSlopeCorner(Slope s) { switch (s) { case SLOPE_W: - case SLOPE_STEEP_W: return 0; + case SLOPE_STEEP_W: return CORNER_W; case SLOPE_S: - case SLOPE_STEEP_S: return 1; + case SLOPE_STEEP_S: return CORNER_S; case SLOPE_E: - case SLOPE_STEEP_E: return 2; + case SLOPE_STEEP_E: return CORNER_E; case SLOPE_N: - case SLOPE_STEEP_N: return 3; + case SLOPE_STEEP_N: return CORNER_N; default: NOT_REACHED(); } } @@ -103,6 +113,40 @@ static inline uint GetSlopeMaxZ(Slope s) return TILE_HEIGHT; } +/** + * Returns the opposite corner. + * + * @param corner A #Corner. + * @return The opposite corner to "corner". + */ +static inline Corner OppositeCorner(Corner corner) +{ + return (Corner)(corner ^ 2); +} + +/** + * Returns the slope with a specific corner raised. + * + * @param corner The #Corner. + * @return The #Slope with corner "corner" raised. + */ +static inline Slope SlopeWithOneCornerRaised(Corner corner) +{ + assert(IS_INT_INSIDE(corner, 0, 4)); + return (Slope)(1 << corner); +} + +/** + * Returns the slope with all except one corner raised. + * + * @param corner The #Corner. + * @return The #Slope with all corners but "corner" raised. + */ +static inline Slope SlopeWithThreeCornersRaised(Corner corner) +{ + return ComplementSlope(SlopeWithOneCornerRaised(corner)); +} + /** * Enumeration for Foundations. -- cgit v1.2.3-70-g09d2