changeset 3142:8096637a944a draft

(svn r3760) Replace some magic numbers for checking for a suitable slope for a level crossing by some less magic numbers. Quite similar to r3699, though this time for placing the rails
author tron <tron@openttd.org>
date Sat, 04 Mar 2006 13:52:52 +0000
parents 70b2d4ab500c
children bfe09300a12a
files rail_cmd.c
diffstat 1 files changed, 7 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -130,7 +130,7 @@
 }
 
 
-static const byte _valid_tileh_slopes[4][15] = {
+static const byte _valid_tileh_slopes[][15] = {
 
 // set of normal ones
 {
@@ -197,15 +197,6 @@
 	TRACK_BIT_X|TRACK_BIT_Y|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_BIT_RIGHT,
 	TRACK_BIT_X|TRACK_BIT_Y|TRACK_BIT_UPPER|TRACK_BIT_LOWER|TRACK_BIT_LEFT|TRACK_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
-	}
 };
 
 uint GetRailFoundation(uint tileh, uint bits)
@@ -346,8 +337,13 @@
 			break;
 
 		case MP_STREET:
-			if (!_valid_tileh_slopes[3][tileh]) // prevent certain slopes
+#define M(x) (1 << (x))
+			/* Level crossings may only be built on these slopes */
+			if (!HASBIT(M(14) | M(13) | M(11) | M(10) | M(7) | M(5) | M(0), tileh)) {
 				return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
+			}
+#undef M
+
 			if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 
 			if (GetRoadType(tile) == ROAD_NORMAL && (