(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
authortron
Thu, 10 Aug 2006 14:44:32 +0000
changeset 4246 6dcc0e44a367
parent 4245 e8d08dbda199
child 4247 091fb0c37c8c
(svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
landscape.c
rail_cmd.c
road_cmd.c
table/autorail.h
tunnelbridge_cmd.c
--- a/landscape.c	Thu Aug 10 09:10:41 2006 +0000
+++ b/landscape.c	Thu Aug 10 14:44:32 2006 +0000
@@ -214,6 +214,17 @@
 		OffsetGroundSprite(31, 1);
 	} else {
 		// inclined foundation
+		if (IsSteepSlope(ti->tileh)) {
+			uint32 lower_base;
+
+			// Lower part of foundation
+			lower_base = sprite_base;
+			if (lower_base == SPR_SLOPES_BASE - 15) lower_base = SPR_FOUNDATION_BASE;
+			AddSortableSpriteToDraw(
+				lower_base + (ti->tileh & ~SLOPE_STEEP), ti->x, ti->y, 16, 16, 7, ti->z
+			);
+			ti->z += TILE_HEIGHT;
+		}
 		AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 1, ti->z);
 		ti->tileh = _inclined_tileh[f - 15];
 		OffsetGroundSprite(31, 9);
--- a/rail_cmd.c	Thu Aug 10 09:10:41 2006 +0000
+++ b/rail_cmd.c	Thu Aug 10 14:44:32 2006 +0000
@@ -154,8 +154,10 @@
 {
 	uint i;
 
-	if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) return 0;
-	if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) return tileh;
+	if (!IsSteepSlope(tileh)) {
+		if ((~_valid_tileh_slopes[0][tileh] & bits) == 0) return 0;
+		if ((~_valid_tileh_slopes[1][tileh] & bits) == 0) return tileh;
+	}
 
 	switch (bits) {
 		case TRACK_BIT_X: i = 0; break;
@@ -163,11 +165,15 @@
 		default:          return 0;
 	}
 	switch (tileh) {
-		case SLOPE_W: i += 0; break;
-		case SLOPE_S: i += 2; break;
-		case SLOPE_E: i += 4; break;
-		case SLOPE_N: i += 6; break;
-		default:      return 0;
+		case SLOPE_W:
+		case SLOPE_STEEP_W: i += 0; break;
+		case SLOPE_S:
+		case SLOPE_STEEP_S: i += 2; break;
+		case SLOPE_E:
+		case SLOPE_STEEP_E: i += 4; break;
+		case SLOPE_N:
+		case SLOPE_STEEP_N: i += 6; break;
+		default: return 0;
 	}
 	return i + 15;
 }
@@ -175,8 +181,12 @@
 
 static uint32 CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
 {
-	// never allow building on top of steep tiles
-	if (!IsSteepSlope(tileh)) {
+	if (IsSteepSlope(tileh)) {
+		if (existing == 0 &&
+				(rail_bits == TRACK_BIT_X || rail_bits == TRACK_BIT_Y)) {
+			return _price.terraform;
+		}
+	} else {
 		rail_bits |= existing;
 
 		// don't allow building on the lower side of a coast
@@ -1702,7 +1712,11 @@
 		uint f = GetRailFoundation(tileh, GetTrackBits(tile));
 
 		if (f != 0) {
-			if (f < 15) return z + TILE_HEIGHT; // leveled foundation
+			if (IsSteepSlope(tileh)) {
+				z += TILE_HEIGHT;
+			} else if (f < 15) {
+				return z + TILE_HEIGHT; // leveled foundation
+			}
 			tileh = _inclined_tileh[f - 15]; // inclined foundation
 		}
 		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
--- a/road_cmd.c	Thu Aug 10 09:10:41 2006 +0000
+++ b/road_cmd.c	Thu Aug 10 14:44:32 2006 +0000
@@ -243,7 +243,15 @@
 {
 	RoadBits road_bits;
 
-	if (IsSteepSlope(tileh)) return CMD_ERROR;
+	if (IsSteepSlope(tileh)) {
+		if (existing == 0) {
+			// force full pieces.
+			*pieces |= (*pieces & 0xC) >> 2;
+			*pieces |= (*pieces & 0x3) << 2;
+			if (*pieces == ROAD_X || *pieces == ROAD_Y) return _price.terraform;
+		}
+		return CMD_ERROR;
+	}
 	road_bits = *pieces | existing;
 
 	// no special foundation
@@ -354,11 +362,6 @@
 		}
 
 		case MP_TUNNELBRIDGE:
-			/* check for flat land */
-			if (IsSteepSlope(tileh)) {
-				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
-			}
-
 			if (!IsBridge(tile) || !IsBridgeMiddle(tile)) goto do_clear;
 
 			/* only allow roads pertendicular to bridge */
@@ -659,7 +662,10 @@
 	uint i;
 
 	// normal level sloped building
-	if ((~_valid_tileh_slopes_road[1][tileh] & bits) == 0) return tileh;
+	if (!IsSteepSlope(tileh) &&
+			(~_valid_tileh_slopes_road[1][tileh] & bits) == 0) {
+		return tileh;
+	}
 
 	// inclined sloped building
 	switch (bits) {
@@ -668,11 +674,15 @@
 		default:     return 0;
 	}
 	switch (tileh) {
-		case SLOPE_W: i += 0; break;
-		case SLOPE_S: i += 2; break;
-		case SLOPE_E: i += 4; break;
-		case SLOPE_N: i += 6; break;
-		default:      return 0;
+		case SLOPE_W:
+		case SLOPE_STEEP_W: i += 0; break;
+		case SLOPE_S:
+		case SLOPE_STEEP_S: i += 2; break;
+		case SLOPE_E:
+		case SLOPE_STEEP_E: i += 4; break;
+		case SLOPE_N:
+		case SLOPE_STEEP_N: i += 6; break;
+		default: return 0;
 	}
 	return i + 15;
 }
@@ -839,7 +849,11 @@
 		uint f = GetRoadFoundation(tileh, GetRoadBits(tile));
 
 		if (f != 0) {
-			if (f < 15) return z + TILE_HEIGHT; // leveled foundation
+			if (IsSteepSlope(tileh)) {
+				z += TILE_HEIGHT;
+			} else if (f < 15) {
+				return z + TILE_HEIGHT; // leveled foundation
+			}
 			tileh = _inclined_tileh[f - 15]; // inclined foundation
 		}
 		return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
--- a/table/autorail.h	Thu Aug 10 09:10:41 2006 +0000
+++ b/table/autorail.h	Thu Aug 10 14:44:32 2006 +0000
@@ -38,14 +38,14 @@
 	{       0,       1,       2,       3,       4,       5 }, // invalid (20)
 	{       0,       1,       2,       3,       4,       5 }, // invalid (21)
 	{       0,       1,       2,       3,       4,       5 }, // invalid (22)
-	{  RED(6), RED(11), RED(17), RED(27), RED(39), RED(47) }, // tileh = 23
+	{       6,      11, RED(17), RED(27), RED(39), RED(47) }, // tileh = 23
 	{       0,       1,       2,       3,       4,       5 }, // invalid (24)
 	{       0,       1,       2,       3,       4,       5 }, // invalid (25)
 	{       0,       1,       2,       3,       4,       5 }, // invalid (26)
-	{  RED(7), RED(15), RED(24), RED(33), RED(36), RED(44) }, // tileh = 27
+	{       7,      15, RED(24), RED(33), RED(36), RED(44) }, // tileh = 27
 	{       0,       1,       2,       3,       4,       5 }, // invalid (28)
-	{  RED(3), RED(14), RED(18), RED(26), RED(41), RED(49) }, // tileh = 29
-	{  RED(4), RED(12), RED(21), RED(30), RED(37), RED(45) }, // tileh = 30
+	{       3,      14, RED(18), RED(26), RED(41), RED(49) }, // tileh = 29
+	{       4,      12, RED(21), RED(30), RED(37), RED(45) }  // tileh = 30
 };
 #undef RED
 
--- a/tunnelbridge_cmd.c	Thu Aug 10 09:10:41 2006 +0000
+++ b/tunnelbridge_cmd.c	Thu Aug 10 14:44:32 2006 +0000
@@ -118,8 +118,8 @@
 	if (HASBIT(valid, tileh)) return 0;
 
 	valid =
-		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) |
-		(axis == AXIS_X ? M(SLOPE_E) : M(SLOPE_W));
+		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_N) | M(SLOPE_STEEP_N) |
+		(axis == AXIS_X ? M(SLOPE_E) | M(SLOPE_STEEP_E) : M(SLOPE_W) | M(SLOPE_STEEP_W));
 	if (HASBIT(valid, tileh)) return _price.terraform;
 
 	return CMD_ERROR;
@@ -133,8 +133,8 @@
 	if (HASBIT(valid, tileh)) return 0;
 
 	valid =
-		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) |
-		(axis == AXIS_X ? M(SLOPE_W) : M(SLOPE_E));
+		BRIDGE_FULL_LEVELED_FOUNDATION | M(SLOPE_S) | M(SLOPE_STEEP_S) |
+		(axis == AXIS_X ? M(SLOPE_W) | M(SLOPE_STEEP_W) : M(SLOPE_E) | M(SLOPE_STEEP_E));
 	if (HASBIT(valid, tileh)) return _price.terraform;
 
 	return CMD_ERROR;
@@ -245,11 +245,13 @@
 	tileh_start = GetTileSlope(tile_start, &z_start);
 	tileh_end = GetTileSlope(tile_end, &z_end);
 
+	if (IsSteepSlope(tileh_start)) z_start += TILE_HEIGHT;
 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_start)) {
 		z_start += TILE_HEIGHT;
 		tileh_start = SLOPE_FLAT;
 	}
 
+	if (IsSteepSlope(tileh_end)) z_end += TILE_HEIGHT;
 	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh_end)) {
 		z_end += TILE_HEIGHT;
 		tileh_end = SLOPE_FLAT;
@@ -596,7 +598,10 @@
 	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
 
 	// one height level extra if the ramp is on a flat foundation
-	return h + TILE_HEIGHT + (IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0);
+	return
+		h + TILE_HEIGHT +
+		(IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0) +
+		(IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
 }
 
 
@@ -832,10 +837,10 @@
 	return GetBridgeHeightRamp(GetSouthernBridgeEnd(t));
 }
 
-static const byte _bridge_foundations[2][16] = {
-// 0 1  2  3  4 5 6 7  8 9 10 11 12 13 14 15
-	{0,16,18,3,20,5,0,7,22,0,10,11,12,13,14},
-	{0,15,17,0,19,5,6,7,21,9,10,11, 0,13,14},
+static const byte _bridge_foundations[][31] = {
+//  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15                      _S          _W    _N _E
+	{ 0,16,18, 3,20, 5, 0, 7,22, 0,10,11,12,13,14, 0, 0, 0, 0, 0, 0, 0, 0,18, 0, 0, 0,16, 0,22,20 },
+	{ 0,15,17, 0,19, 5, 6, 7,21, 9,10,11, 0,13,14, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0,15, 0,21,19 }
 };
 
 extern const byte _road_sloped_sprites[14];
@@ -890,11 +895,15 @@
 
 	// inclined sloped building
 	switch (tileh) {
-		case SLOPE_W: i = 0; break;
-		case SLOPE_S: i = 2; break;
-		case SLOPE_E: i = 4; break;
-		case SLOPE_N: i = 6; break;
-		default:      return 0;
+		case SLOPE_W:
+		case SLOPE_STEEP_W: i = 0; break;
+		case SLOPE_S:
+		case SLOPE_STEEP_S: i = 2; break;
+		case SLOPE_E:
+		case SLOPE_STEEP_E: i = 4; break;
+		case SLOPE_N:
+		case SLOPE_STEEP_N: i = 6; break;
+		default: return 0;
 	}
 	if (axis != AXIS_X) ++i;
 	return i + 15;
@@ -1103,6 +1112,7 @@
 			if (5 <= pos && pos <= 10) {
 				uint delta;
 
+				if (IsSteepSlope(tileh)) return z + TILE_HEIGHT * 2;
 				if (HASBIT(BRIDGE_HORZ_RAMP, tileh)) return z + TILE_HEIGHT;
 
 				if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION, tileh)) z += TILE_HEIGHT;
@@ -1118,19 +1128,32 @@
 				uint f = GetBridgeFoundation(tileh, DiagDirToAxis(dir));
 
 				if (f != 0) {
-					if (f < 15) return z + TILE_HEIGHT;
+					if (IsSteepSlope(tileh)) {
+						z += TILE_HEIGHT;
+					} else if (f < 15) {
+						return z + TILE_HEIGHT;
+					}
 					tileh = _inclined_tileh[f - 15];
 				}
 			}
 		} else {
+			uint ground_z;
+
 			// HACK on the bridge?
-			if (_get_z_hint >= z + TILE_HEIGHT + (tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT)) return _get_z_hint;
+			ground_z = z + TILE_HEIGHT;
+			if (tileh != SLOPE_FLAT) ground_z += TILE_HEIGHT;
+			if (IsSteepSlope(tileh)) ground_z += TILE_HEIGHT;
+			if (_get_z_hint >= ground_z) return _get_z_hint;
 
 			if (IsTransportUnderBridge(tile)) {
 				uint f = _bridge_foundations[GetBridgeAxis(tile)][tileh];
 
 				if (f != 0) {
-					if (f < 15) return z + TILE_HEIGHT;
+					if (IsSteepSlope(tileh)) {
+						z += TILE_HEIGHT;
+					} else if (f < 15) {
+						return z + TILE_HEIGHT;
+					}
 					tileh = _inclined_tileh[f - 15];
 				}
 			}