Changeset - r7678:10b1447703da
[Not reviewed]
master
0 2 0
rubidium - 17 years ago 2007-10-05 19:36:13
rubidium@openttd.org
(svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
2 files changed with 56 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/landscape.cpp
Show inline comments
 
@@ -74,29 +74,29 @@ uint ApplyFoundationToSlope(Foundation f
 
	if (IsLeveledFoundation(f)) {
 
		*s = SLOPE_FLAT;
 
		return TILE_HEIGHT;
 
	}
 

	
 
	uint dz = IsSteepSlope(*s) ? TILE_HEIGHT : 0;
 
	byte highest_corner = GetHighestSlopeCorner(*s);
 
	Corner highest_corner = GetHighestSlopeCorner(*s);
 

	
 
	switch (f) {
 
		case FOUNDATION_INCLINED_X:
 
			*s = (highest_corner <= 1 ? SLOPE_SW : SLOPE_NE);
 
			*s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
 
			break;
 

	
 
		case FOUNDATION_INCLINED_Y:
 
			*s = (((highest_corner == 1) || (highest_corner == 2)) ? SLOPE_SE : SLOPE_NW);
 
			*s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
 
			break;
 

	
 
		case FOUNDATION_STEEP_LOWER:
 
			*s = (Slope) (1 << highest_corner);
 
			*s = SlopeWithOneCornerRaised(highest_corner);
 
			break;
 

	
 
		case FOUNDATION_STEEP_HIGHER:
 
			*s = (Slope) (*s & ~SLOPE_STEEP);
 
			*s = SlopeWithThreeCornersRaised(OppositeCorner(highest_corner));
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
	return dz;
 
}
 
@@ -268,13 +268,13 @@ void DrawFoundation(TileInfo *ti, Founda
 
		lower_base = sprite_base;
 
		if (lower_base == SPR_SLOPES_VIRTUAL_BASE) lower_base = SPR_FOUNDATION_BASE;
 
		AddSortableSpriteToDraw(
 
			lower_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
 
		);
 

	
 
		byte highest_corner = GetHighestSlopeCorner(ti->tileh);
 
		Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
 
		ti->z += ApplyFoundationToSlope(f, &ti->tileh);
 

	
 
		if (IsInclinedFoundation(f)) {
 
			/* inclined foundation */
 
			byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
 

	
src/slope.h
Show inline comments
 
@@ -38,12 +38,22 @@ enum Slope {
 
	SLOPE_STEEP_S  = SLOPE_STEEP | SLOPE_WSE,               ///< a steep slope falling to north (from south)
 
	SLOPE_STEEP_E  = SLOPE_STEEP | SLOPE_SEN,               ///< a steep slope falling to west (from east)
 
	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.
 
 *
 
 * @param s The given #Slope.
 
 * @return True if the slope is steep, else false.
 
 */
 
static inline bool IsSteepSlope(Slope s)
 
@@ -70,25 +80,25 @@ static inline Slope ComplementSlope(Slop
 

	
 
/**
 
 * Returns the highest corner of a slope (one corner raised or a steep slope).
 
 *
 
 * @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();
 
	}
 
}
 

	
 
/**
 
 * Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
 
@@ -100,12 +110,46 @@ static inline uint GetSlopeMaxZ(Slope s)
 
{
 
	if (s == SLOPE_FLAT) return 0;
 
	if (IsSteepSlope(s)) return 2 * TILE_HEIGHT;
 
	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.
 
 */
 
enum Foundation {
 
	FOUNDATION_NONE,             ///< The tile has no foundation, the slope remains unchanged.
0 comments (0 inline, 0 general)