(svn r14) Fix: railroad crossings on slopes are now possible
authordominik
Tue, 10 Aug 2004 18:35:43 +0000
changeset 13 3e7c1f74a996
parent 12 689a3309cd1c
child 14 8289d2a744c0
(svn r14) Fix: railroad crossings on slopes are now possible
rail_cmd.c
road_cmd.c
--- a/rail_cmd.c	Tue Aug 10 17:23:21 2004 +0000
+++ b/rail_cmd.c	Tue Aug 10 18:35:43 2004 +0000
@@ -118,7 +118,7 @@
 }
 
 
-static const byte _valid_tileh_slopes[3][15] = {
+static const byte _valid_tileh_slopes[4][15] = {
 
 // set of normal ones
 {
@@ -184,6 +184,15 @@
 	RAIL_BIT_DIAG2|RAIL_BIT_RIGHT|RAIL_BIT_UPPER,
 	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
 	RAIL_BIT_DIAG1|RAIL_BIT_DIAG2|RAIL_BIT_UPPER|RAIL_BIT_LOWER|RAIL_BIT_LEFT|RAIL_BIT_RIGHT,
+	},
+
+	// valid railway crossings on slopes
+	{
+		1, 0, 0, // 0, 1, 2
+		0, 0, 1, // 3, 4, 5
+		0, 1, 0, // 6, 7, 8
+		0, 1, 1, // 9, 10, 11
+		0, 1, 1, // 12, 13, 14
 	}
 };
 
@@ -275,8 +284,12 @@
 	} else if (ti.type == MP_STREET) {
 		byte m5;
 /* BUILD ON STREET CODE */
-		if (ti.tileh != 0) goto need_clear;
-		
+		if (ti.tileh & 0x10) // very steep tile
+				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+
+		if (!_valid_tileh_slopes[3][ti.tileh]) // prevent certain slopes
+				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+
 		if (!(ti.map5 & 0xF0)) {
 			if ((ti.map5 & 0x0F) == 0xA) {
 				if (rail_bit != 2) goto need_clear;
@@ -1652,7 +1665,7 @@
 {
 	uint z = ti->z;
 	int th = ti->tileh;
-	
+
 	// check if it's a foundation
 	if (ti->tileh != 0) {
 		if ((ti->map5 & 0x80) == 0) {
--- a/road_cmd.c	Tue Aug 10 17:23:21 2004 +0000
+++ b/road_cmd.c	Tue Aug 10 18:35:43 2004 +0000
@@ -253,7 +253,7 @@
 	ROAD_ALL = (ROAD_NW | ROAD_SW | ROAD_SE | ROAD_NE)
 };
  
-static const byte _valid_tileh_slopes_road[2][15] = {
+static const byte _valid_tileh_slopes_road[3][15] = {
 	// set of normal ones
 	{
 		ROAD_ALL, 0, 0,
@@ -282,6 +282,14 @@
 		ROAD_NW | ROAD_SE | ROAD_NE, // 12
 		ROAD_ALL,
 		ROAD_ALL
+	},
+	// valid railway crossings on slopes
+	{
+		1, 0, 0, // 0, 1, 2
+		0, 0, 1, // 3, 4, 5
+		0, 1, 0, // 6, 7, 8
+		0, 1, 1, // 9, 10, 11
+		0, 1, 1, // 12, 13, 14
 	}
 };
 
@@ -347,8 +355,12 @@
 	} else if (ti.type == MP_RAILWAY) {
 		byte m5;
 
-		if (ti.tileh != 0) goto do_clear;
-		
+		if (ti.tileh & 0x10) // very steep tile
+				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+
+		if(!_valid_tileh_slopes_road[2][ti.tileh]) // prevent certain slopes
+				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+
 		if (ti.map5 == 2) {
 			if (pieces & 5) goto do_clear;
 			m5 = 0x10;
@@ -371,7 +383,7 @@
 	} else if (ti.type == MP_TUNNELBRIDGE) {
 
 		/* check for flat land */
-		if (ti.tileh & 0x10) //goto do_clear; // very steep tile
+		if (ti.tileh & 0x10) // very steep tile
 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
 
 		/* is this middle part of a bridge? */
@@ -691,6 +703,10 @@
 		((bits == (ROAD_SW | ROAD_NE)) || (i++, bits == (ROAD_NW | ROAD_SE))))
 		return i + 15;
 
+	// rail crossing
+	if ((bits & 0x10) && _valid_tileh_slopes_road[2][tileh])
+		return tileh;
+
 	return 0;
 }
 
@@ -755,7 +771,10 @@
 			AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z);
 			drts++;
 		}
-	} else if ( (ti->map5 & 0xE0) == 0) {
+	} else if ( (ti->map5 & 0xE0) == 0) { // railroad crossing
+		int f = GetRoadFoundation(ti->tileh, ti->map5 & 0xF);
+		if (f) DrawFoundation(ti, f);
+
 		image = 0x55B;
 
 		if ( (ti->map5 & 8) != 0)
@@ -836,7 +855,7 @@
 
 	// check if it's a foundation
 	if (ti->tileh != 0) {
-		if ((ti->map5 & 0xF0) == 0) {
+		if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
 			uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
 			if (f != 0) {
 				if (f < 15) {