Changeset - r3918:2735a9be7286
[Not reviewed]
master
0 1 0
KUDr - 18 years ago 2006-05-30 15:04:59
kudr@openttd.org
(svn r5037) -Fix: assert when GetVehicleTrackdir() returns wrong trackdir - introduced by r5033 (thanks yanek)
1 file changed with 16 insertions and 4 deletions:
0 comments (0 inline, 0 general)
yapf/yapf_road.cpp
Show inline comments
 
@@ -292,50 +292,62 @@ public:
 
		Tpf pf;
 
		return pf.DistanceToTile(v, tile);
 
	}
 

	
 
	FORCEINLINE uint DistanceToTile(const Vehicle *v, TileIndex dst_tile)
 
	{
 
		// handle special case - when current tile is the destination tile
 
		if (dst_tile == v->tile) {
 
			// distance is zero in this case
 
			return 0;
 
		}
 

	
 
		// set origin (tile, trackdir)
 
		TileIndex src_tile = v->tile;
 
		Trackdir src_td = GetVehicleTrackdir(v);
 
		Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
 
		if (!SetOriginFromVehiclePos(v)) return UINT_MAX;
 

	
 
		// set destination tile, trackdir
 
		//   get available trackdirs on the destination tile
 
		uint dest_ts = GetTileTrackStatus(dst_tile, TRANSPORT_ROAD);
 
		TrackdirBits dst_td_bits = (TrackdirBits)(dest_ts & TRACKDIR_BIT_MASK);
 
		Yapf().SetDestination(dst_tile, dst_td_bits);
 

	
 
		// find the best path
 
		Yapf().FindPath(v);
 

	
 
		// if path not found - return distance = UINT_MAX
 
		uint dist = UINT_MAX;
 
		Node* pNode = &Yapf().GetBestNode();
 
		if (pNode != NULL) {
 
			// path was found or at least suggested
 
			// get the path cost estimate
 
			dist = pNode->GetCostEstimate();
 
		}
 

	
 
		return dist;
 
	}
 

	
 
	/** Return true if the valid origin (tile/trackdir) was set from the current vehicle position. */
 
	FORCEINLINE bool SetOriginFromVehiclePos(const Vehicle *v)
 
	{
 
		// set origin (tile, trackdir)
 
		TileIndex src_tile = v->tile;
 
		Trackdir src_td = GetVehicleTrackdir(v);
 
		if ((GetTileTrackStatus(src_tile, TRANSPORT_ROAD) & TrackdirToTrackdirBits(src_td)) == 0) {
 
			// sometimes the roadveh is not on the road (it resides on non-existing track)
 
			// how should we handle that situation?
 
			return false;
 
		}
 
		Yapf().SetOrigin(src_tile, TrackdirToTrackdirBits(src_td));
 
		return true;
 
	}
 

	
 
	static Depot* stFindNearestDepot(Vehicle* v, TileIndex tile, Trackdir td)
 
	{
 
		Tpf pf;
 
		return pf.FindNearestDepot(v, tile, td);
 
	}
 

	
 
	FORCEINLINE Depot* FindNearestDepot(Vehicle* v, TileIndex tile, Trackdir td)
 
	{
 
		// set origin and destination nodes
 
		Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
 

	
 
		// find the best path
0 comments (0 inline, 0 general)