(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
authordarkvater
Tue, 14 Sep 2004 01:21:07 +0000
changeset 241 e6e62a5e7f52
parent 240 f1efbac04112
child 242 f4894a2cdfe8
(svn r242) -Fix: Pathfinding bug for road vehicles introduced in r160 fixed (blathijs)
-Fix: Pathfinding under bridges bug for ships introduced in r160 fixed (Darkvater)
pathfind.c
road_cmd.c
roadveh_cmd.c
ttd.h
tunnelbridge_cmd.c
--- a/pathfind.c	Mon Sep 13 23:43:54 2004 +0000
+++ b/pathfind.c	Tue Sep 14 01:21:07 2004 +0000
@@ -212,10 +212,9 @@
 		tile = TILE_FROM_XY(x,y);
 
 		if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) &&
-				(_map5[tile] & 0xF0) == 0 &&
-				//((_map5[tile]>>2)&3) == type && // This is
-				//not necesary to check, right?
-				((_map5[tile] & 3)^2) == direction &&
+				(_map5[tile] & 0xF0) == 0 &&					// tunnel entrance/exit
+				//((_map5[tile]>>2)&3) == type &&		// rail/road-tunnel <-- This is not necesary to check, right?
+				((_map5[tile] & 3)^2) == direction &&	// entrance towards: 0 = NE, 1 = SE, 2 = SW, 3 = NW
 				GetSlopeZ(x+8, y+8) == z)
 					break;
 	}
@@ -263,7 +262,7 @@
 	uint tile_org = tile;
 
 	if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0)==0) {
-		if ((_map5[tile] & 3) != direction || ((_map5[tile]>>1)&6) != tpf->tracktype)
+		if ((_map5[tile] & 3) != direction || ((_map5[tile]>>2)&3) != tpf->tracktype)
 			return;
 		tile = SkipToEndOfTunnel(tpf, tile, direction);
 	}
--- a/road_cmd.c	Mon Sep 13 23:43:54 2004 +0000
+++ b/road_cmd.c	Tue Sep 14 01:21:07 2004 +0000
@@ -1047,13 +1047,6 @@
 				r *= 0x10001;
 			}
 			return r;
-		} else if ((b&0xF0) == 0x20) {
-			/* Depot */
-			/* We reverse the dir because it points out of the
-			 * exit, and we want to get in. Maybe we should return
-			 * both dirs here? */
-			byte dir = _reverse_dir[b&3];
-			return 1 << _dir_to_straight_trackdir[dir];
 		}
 	}
 	return 0;
--- a/roadveh_cmd.c	Mon Sep 13 23:43:54 2004 +0000
+++ b/roadveh_cmd.c	Tue Sep 14 01:21:07 2004 +0000
@@ -1023,22 +1023,33 @@
 
 	{
 		uint32 r;
-			r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
+		r = GetTileTrackStatus(tile, TRANSPORT_ROAD);
 		signal = (uint16)(r >> 16);
 		bitmask = (uint16)r;
 	}
 
-
-	/* Most of the checks that used to be here, are now integrated into
-	 * GetTileTrackStatus now. The only thing still remaining is the
-	 * owner check for stations and depots, since GetTileTrackStatus
-	 * doesn't know about owner */
-	if (IS_TILETYPE(tile, MP_STREET) && (_map5[tile]&0xF0) == 0x20 && v->owner != _map_owner[tile])
-		/* Depot not owned by us */
-		bitmask = 0;
-	if (IS_TILETYPE(tile, MP_STATION) && _map_owner[tile] != OWNER_NONE && _map_owner[tile] != v->owner)
-		/* Station not owned by us */
-		bitmask = 0;
+	if (IS_TILETYPE(tile, MP_STREET)) {
+		if ((_map5[tile]&0xF0) == 0x20 && v->owner == _map_owner[tile])
+			/* Road crossing */
+			bitmask |= _road_veh_fp_ax_or[_map5[tile]&3];
+	} else if (IS_TILETYPE(tile, MP_STATION)) {
+		if (_map_owner[tile] == OWNER_NONE || _map_owner[tile] == v->owner) {
+			/* Our station */
+			Station *st = DEREF_STATION(_map2[tile]);
+			byte val = _map5[tile];
+			if (v->cargo_type != CT_PASSENGERS) {
+				if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stop_status&3))
+					bitmask |= _road_veh_fp_ax_or[(val-0x43)&3];
+			} else {
+				if (IS_BYTE_INSIDE(val, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stop_status&3))
+					bitmask |= _road_veh_fp_ax_or[(val-0x47)&3];
+			}
+		}
+	}
+	/* The above lookups should be moved to GetTileTrackStatus in the
+	 * future, but that requires more changes to the pathfinder and other
+	 * stuff, probably even more arguments to GTTS.
+	 */
 
 	/* remove unreachable tracks */
 	bitmask &= _road_veh_fp_ax_and[direction];
--- a/ttd.h	Mon Sep 13 23:43:54 2004 +0000
+++ b/ttd.h	Tue Sep 14 01:21:07 2004 +0000
@@ -104,10 +104,10 @@
 	 * bridges. For now, you should just not change the values for road
 	 * and rail.
 	 */
-        TRANSPORT_RAIL = 0,
+  TRANSPORT_RAIL = 0,
 	TRANSPORT_ROAD = 1,
-	TRANSPORT_WATER,
-	TRANSPORT_MAX
+	TRANSPORT_WATER,	// = 2
+	TRANSPORT_MAX			// = 3
 } TransportType;
 
 typedef struct TileInfo {
--- a/tunnelbridge_cmd.c	Mon Sep 13 23:43:54 2004 +0000
+++ b/tunnelbridge_cmd.c	Tue Sep 14 01:21:07 2004 +0000
@@ -1318,7 +1318,7 @@
 			/* Bridge middle part */
 			if (!(m5 & 0x20)) {
 				/* Clear ground or water underneath */
-				if ((m5 &= 0x18) != 8)
+				if ((m5 & 0x18) != 8)
 					/* Clear ground */
 					return result;
 				else