npf.c
changeset 2493 d834d0c1502a
parent 2416 d3f8a53cedf6
child 2605 d9d7eecdd1f1
--- a/npf.c	Wed Oct 05 04:00:39 2005 +0000
+++ b/npf.c	Wed Oct 05 07:20:26 2005 +0000
@@ -60,8 +60,10 @@
 	uint32 ts;
 
 	/* Can always go into a tunnel */
-	if (IsTileType(tile, MP_TUNNELBRIDGE) && (_m[tile].m5 & 0xF0)==0 && (_m[tile].m5 & 3) == exitdir)
+	if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0 &&
+			GB(_m[tile].m5, 0, 2) == exitdir) {
 		return false;
+	}
 
 	/* Cannot go through the back of a depot */
 	if (IsTileDepotType(tile, TRANSPORT_RAIL) && (exitdir != GetDepotDirection(tile, TRANSPORT_RAIL)))
@@ -88,8 +90,11 @@
 			return true;
 
 		/* Prevent us from falling off a slope into a tunnel exit */
-		if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && (_m[dst_tile].m5 & 0xF0)==0 && (DiagDirection)(_m[dst_tile].m5 & 3) == ReverseDiagdir(exitdir))
-				return true;
+		if (IsTileType(dst_tile, MP_TUNNELBRIDGE) &&
+				GB(_m[dst_tile].m5, 4, 4) == 0 &&
+				(DiagDirection)GB(_m[dst_tile].m5, 0, 2) == ReverseDiagdir(exitdir)) {
+			return true;
+		}
 
 		/* Check for oneway signal against us */
 		if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TYPE_SIGNALS) {
@@ -312,7 +317,7 @@
 {
 	DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
 	TileIndex tile = current->tile;
-	if ( (DiagDirection)(_m[tile].m5 & 3) == ReverseDiagdir(exitdir)) {
+	if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagdir(exitdir)) {
 		/* We just popped out if this tunnel, since were
 		 * facing the tunnel exit */
 		FindLengthOfTunnelResult flotr;
@@ -364,13 +369,13 @@
 				/* DEBUG: mark visited tiles by mowing the grass under them
 				 * ;-) */
 				if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
-					_m[tile].m2 &= ~15; /* Clear bits 0-3 */
+					SB(_m[tile].m2, 0, 4, 0);
 					MarkTileDirtyByTile(tile);
 				}
 				break;
 			case MP_STREET:
 				if (!IsTileDepotType(tile, TRANSPORT_ROAD)) {
-					_m[tile].m4 &= ~0x70; /* Clear bits 4-6 */
+					SB(_m[tile].m2, 4, 3, 0);
 					MarkTileDirtyByTile(tile);
 				}
 				break;
@@ -408,7 +413,7 @@
 	/* Determine base length */
 	switch (GetTileType(tile)) {
 		case MP_TUNNELBRIDGE:
-			if ((_m[tile].m5 & 0xF0)==0) {
+			if (GB(_m[tile].m5, 4, 4) == 0) {
 				cost = NPFTunnelCost(current);
 				break;
 			}
@@ -452,7 +457,7 @@
 	/* Determine base length */
 	switch (GetTileType(tile)) {
 		case MP_TUNNELBRIDGE:
-			if ((_m[tile].m5 & 0xF0)==0) {
+			if (GB(_m[tile].m5, 4, 4) == 0) {
 				cost = NPFTunnelCost(current);
 				break;
 			}
@@ -659,10 +664,10 @@
  * intensive owner check, instead we will just assume that if the vehicle
  * managed to get on the bridge, it is probably allowed to :-)
  */
-			if ((_m[tile].m5 & 0xC6) == 0xC0 && (unsigned)(_m[tile].m5 & 0x1) == (enterdir & 0x1)) {
+			if ((_m[tile].m5 & 0xC6) == 0xC0 && GB(_m[tile].m5, 0, 1) == (enterdir & 0x1)) {
 				/* on the middle part of a railway bridge: find bridge ending */
 				while (IsTileType(tile, MP_TUNNELBRIDGE) && !((_m[tile].m5 & 0xC6) == 0x80)) {
-					tile += TileOffsByDir(_m[tile].m5 & 0x1);
+					tile += TileOffsByDir(GB(_m[tile].m5, 0, 1));
 				}
 			}
 			/* if we were on a railway middle part, we are now at a railway bridge ending */
@@ -670,7 +675,7 @@
 			if (
 				(_m[tile].m5 & 0xFC) == 0 /* railway tunnel */
 				|| (_m[tile].m5 & 0xC6) == 0x80 /* railway bridge ending */
-				|| ((_m[tile].m5 & 0xF8) == 0xE0 && ((unsigned)_m[tile].m5 & 0x1) != (enterdir & 0x1)) /* railway under bridge */
+				|| ((_m[tile].m5 & 0xF8) == 0xE0 && GB(_m[tile].m5, 0, 1) != (enterdir & 0x1)) /* railway under bridge */
 				)
 				return IsTileOwner(tile, owner);
 			break;
@@ -704,7 +709,8 @@
 	aystar->EndNodeCheck(aystar, current);
 
 	/* Find dest tile */
-	if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_m[src_tile].m5 & 0xF0)==0 && (DiagDirection)(_m[src_tile].m5 & 3) == src_exitdir) {
+	if (IsTileType(src_tile, MP_TUNNELBRIDGE) && GB(_m[src_tile].m5, 4, 4) == 0 &&
+			(DiagDirection)GB(_m[src_tile].m5, 0, 2) == src_exitdir) {
 		/* This is a tunnel. We know this tunnel is our type,
 		 * otherwise we wouldn't have got here. It is also facing us,
 		 * so we should skip it's body */
@@ -749,8 +755,10 @@
 	/* I can't enter a tunnel entry/exit tile from a tile above the tunnel. Note
 	 * that I can enter the tunnel from a tile below the tunnel entrance. This
 	 * solves the problem of vehicles wanting to drive off a tunnel entrance */
-	if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && (_m[dst_tile].m5 & 0xF0) == 0 && GetTileZ(dst_tile) < GetTileZ(src_tile))
+	if (IsTileType(dst_tile, MP_TUNNELBRIDGE) && GB(_m[dst_tile].m5, 4, 4) == 0 &&
+			GetTileZ(dst_tile) < GetTileZ(src_tile)) {
 		return;
+	}
 
 	/* check correct rail type (mono, maglev, etc) */
 	if (type == TRANSPORT_RAIL) {