src/landscape.cpp
changeset 7764 e594296e90f6
parent 7728 68e794385dc9
child 7767 9866e9700e62
--- a/src/landscape.cpp	Sat Oct 20 14:51:09 2007 +0000
+++ b/src/landscape.cpp	Sat Oct 20 16:50:48 2007 +0000
@@ -104,9 +104,31 @@
 
 uint GetPartialZ(int x, int y, Slope corners)
 {
+	if (IsHalftileSlope(corners)) {
+		switch (GetHalftileSlopeCorner(corners)) {
+			case CORNER_W:
+				if (x - y >= 0) return GetSlopeMaxZ(corners);
+				break;
+
+			case CORNER_S:
+				if (x - (y ^ 0xF) >= 0) return GetSlopeMaxZ(corners);
+				break;
+
+			case CORNER_E:
+				if (y - x >= 0) return GetSlopeMaxZ(corners);
+				break;
+
+			case CORNER_N:
+				if ((y ^ 0xF) - x >= 0) return GetSlopeMaxZ(corners);
+				break;
+
+			default: NOT_REACHED();
+		}
+	}
+
 	int z = 0;
 
-	switch (corners) {
+	switch (corners & ~SLOPE_HALFTILE_MASK) {
 	case SLOPE_W:
 		if (x - y >= 0)
 			z = (x - y) >> 1;
@@ -209,6 +231,8 @@
 /**
  * Determine the Z height of the corners of a specific tile edge
  *
+ * @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. it's edges.
+ *
  * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
  *
  * @param tileh The slope of the tile.
@@ -227,10 +251,14 @@
 		{SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
 	};
 
+	int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
+	if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
+	if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
+
 	if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
 	if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
-	if (tileh == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
-	if (tileh == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
+	if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
+	if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
 }
 
 static Slope GetFoundationSlope(TileIndex tile, uint* z)