changeset 3976:b166cb90c8d0 draft

(svn r5153) - Fix: [YAPF] RVs can now plan path reversing in depot or end of road
author KUDr <KUDr@openttd.org>
date Wed, 07 Jun 2006 18:41:58 +0000
parents ebfc6791b13b
children 27f4a4390992
files yapf/follow_track.hpp yapf/yapf_road.cpp
diffstat 2 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/yapf/follow_track.hpp
+++ b/yapf/follow_track.hpp
@@ -45,10 +45,10 @@
 		m_old_td = old_td;
 		assert((GetTileTrackStatus(m_old_tile, TT()) & TrackdirToTrackdirBits(m_old_td)) != 0);
 		m_exitdir = TrackdirToExitdir(m_old_td);
-		if (EnteredRailDepot()) return true;
+		if (EnteredDepot()) return true;
 		if (!CanExitOldTile()) return false;
 		FollowTileExit();
-		if (!QueryNewTileTrackStatus()) return false;
+		if (!QueryNewTileTrackStatus()) return TryReverse();
 		if (!CanEnterNewTile()) return false;
 		m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
 		if (!Allow90degTurns())
@@ -198,23 +198,44 @@
 		return true;
 	}
 
-	FORCEINLINE bool EnteredRailDepot()
+	/** return true if we entered depot and reversed inside */
+	FORCEINLINE bool EnteredDepot()
 	{
-		// rail depots cause reversing
-		if (IsRailTT() && IsTileDepotType(m_old_tile, TT())) {
-			DiagDirection exitdir = GetRailDepotDirection(m_old_tile);
+		// rail and road depots cause reversing
+		if (!IsWaterTT() && IsTileDepotType(m_old_tile, TT())) {
+			DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
 			if (exitdir != m_exitdir) {
 				// reverse
 				m_new_tile = m_old_tile;
 				m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
 				m_exitdir = exitdir;
 				m_tiles_skipped = 0;
-				m_is_tunnel = false;
+				m_is_tunnel = m_is_bridge = m_is_station = false;
 				return true;
 			}
 		}
 		return false;
 	}
+
+	/** return true if we successfully reversed at end of road/track */
+	FORCEINLINE bool TryReverse()
+	{
+		if (IsRoadTT()) {
+			// if we reached the end of road, we can reverse the RV and continue moving
+			m_exitdir = ReverseDiagDir(m_exitdir);
+			// new tile will be the same as old one
+			m_new_tile = m_old_tile;
+			// set new trackdir bits to all reachable trackdirs
+			QueryNewTileTrackStatus();
+			m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
+			if (m_new_td_bits != TRACKDIR_BIT_NONE) {
+				// we have some trackdirs reachable after reversal
+				return true;
+			}
+		}
+		return false;
+	}
+
 public:
 	/** Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td */
 	int GetSpeedLimit(int *pmin_speed = NULL)
--- a/yapf/yapf_road.cpp
+++ b/yapf/yapf_road.cpp
@@ -76,7 +76,13 @@
 			// base tile cost depending on distance between edges
 			segment_cost += Yapf().OneTileCost(tile, trackdir);
 
-			// if there are no reachable trackdirs n new tile, we have end of road
+			// stop if we have just entered the depot
+			if (IsTileDepotType(tile, TRANSPORT_ROAD) && trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(GetRoadDepotDirection(tile)))) {
+				// next time we will reverse and leave the depot
+				break;
+			}
+
+			// if there are no reachable trackdirs on new tile, we have end of road
 			TrackFollower F;
 			if (!F.Follow(tile, trackdir)) break;