(svn r10345) -Fix [FS#290]: Make OPF handle coming out of a tunnel as well as going into a tunnel, to support road vehicles looking back when finding a depot while in a tunnel.
authormatthijs
Tue, 26 Jun 2007 20:15:33 +0000
changeset 7080 f94ff65485b5
parent 7079 9cdb1b4f9928
child 7081 283d5e8e4e36
(svn r10345) -Fix [FS#290]: Make OPF handle coming out of a tunnel as well as going into a tunnel, to support road vehicles looking back when finding a depot while in a tunnel.
-Fix [FS#290]: Make NPF look back when finding a depot for road vehicles.
src/pathfind.cpp
src/roadveh_cmd.cpp
--- a/src/pathfind.cpp	Tue Jun 26 20:03:17 2007 +0000
+++ b/src/pathfind.cpp	Tue Jun 26 20:15:33 2007 +0000
@@ -331,11 +331,19 @@
 
 	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 		if (IsTunnel(tile)) {
-			if (GetTunnelDirection(tile) != direction ||
-					GetTunnelTransportType(tile) != tpf->tracktype) {
+			if (GetTunnelTransportType(tile) != tpf->tracktype) {
 				return;
 			}
-			tile = SkipToEndOfTunnel(tpf, tile, direction);
+			/* Only skip through the tunnel if heading inwards. We can
+			 * be headed outwards if our starting position was in a
+			 * tunnel and we're pathfinding backwards */
+			if (GetTunnelDirection(tile) == direction) {
+				tile = SkipToEndOfTunnel(tpf, tile, direction);
+			} if (GetTunnelDirection(tile) != ReverseDiagDir(direction)) {
+				/* We don't support moving through the sides of a tunnel
+				 * entrance :-) */
+				return;
+			}
 		} else {
 			TileIndex tile_end;
 			if (GetBridgeRampDirection(tile) != direction ||
--- a/src/roadveh_cmd.cpp	Tue Jun 26 20:03:17 2007 +0000
+++ b/src/roadveh_cmd.cpp	Tue Jun 26 20:15:33 2007 +0000
@@ -416,7 +416,7 @@
 		/* See where we are now */
 		Trackdir trackdir = GetVehicleTrackdir(v);
 
-		ftd = NPFRouteToDepotBreadthFirst(v->tile, trackdir, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, v->owner, INVALID_RAILTYPE);
+		ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, v->tile, ReverseTrackdir(trackdir), TRANSPORT_ROAD, v->u.road.compatible_roadtypes, v->owner, INVALID_RAILTYPE, 0);
 		if (ftd.best_bird_dist == 0) {
 			return GetDepotByTile(ftd.node.tile); /* Target found */
 		} else {