Changeset - r3930:aff4ee55c4ef
[Not reviewed]
master
0 2 0
KUDr - 18 years ago 2006-06-01 21:00:59
kudr@openttd.org
(svn r5065) -CodeChange: [YAPF] Added PfDetectDestination(tile, trackdir) for trains (to be used by platform selection feature)
2 files changed with 21 insertions and 8 deletions:
0 comments (0 inline, 0 general)
yapf/yapf_costrail.hpp
Show inline comments
 
@@ -156,37 +156,36 @@ public:
 

	
 
		// start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment
 
		TileIndex prev_tile      = (n.m_parent != NULL) ? n.m_parent->GetLastTile() : INVALID_TILE;
 
		Trackdir  prev_trackdir  = (n.m_parent != NULL) ? n.m_parent->GetLastTrackdir() : INVALID_TRACKDIR;
 
		TileType  prev_tile_type = (n.m_parent != NULL) ? GetTileType(n.m_parent->GetLastTile()) : MP_VOID;
 

	
 
		TileIndex tile = n.m_key.m_tile;
 
		Trackdir trackdir = n.m_key.m_td;
 
		TileType tile_type = GetTileType(tile);
 

	
 
		RailType rail_type = GetTileRailType(tile, trackdir);
 

	
 
		bool target_seen = false;
 
		bool target_seen = Yapf().PfDetectDestination(tile, trackdir);
 

	
 
		while (true) {
 
			segment_cost += Yapf().OneTileCost(tile, trackdir);
 
			segment_cost += Yapf().CurveCost(prev_trackdir, trackdir);
 
			segment_cost += Yapf().SlopeCost(tile, trackdir);
 
			segment_cost += Yapf().SignalCost(n, tile, trackdir);
 
			if (n.m_segment->flags_u.flags_s.m_end_of_line) {
 
				break;
 
			}
 

	
 
			// finish if we have reached the destination
 
			target_seen = Yapf().PfDetectDestination(n);
 
			if (target_seen) {
 
				break;
 
			}
 

	
 
			// finish on first station tile - segment should end here to avoid target skipping
 
			// when cached segments are used
 
			if (tile_type == MP_STATION && prev_tile_type != MP_STATION) {
 
				break;
 
			}
 

	
 
			// finish also on waypoint - same workaround as for first station tile
 
			if (tile_type == MP_RAILWAY && IsRailWaypoint(tile)) {
 
@@ -228,24 +227,26 @@ public:
 
				rail_type = new_rail_type;
 
			}
 

	
 
			// move to the next tile
 
			prev_tile = tile;
 
			prev_trackdir = trackdir;
 
			prev_tile_type = tile_type;
 

	
 
			tile = F.m_new_tile;
 
			trackdir = new_td;
 
			tile_type = GetTileType(tile);
 

	
 
			target_seen = Yapf().PfDetectDestination(tile, trackdir);
 

	
 
			// reversing in depot penalty
 
			if (tile == prev_tile) {
 
				segment_cost += Yapf().PfGetSettings().rail_depot_reverse_penalty;
 
				break;
 
			}
 

	
 
			// if we skipped some tunnel tiles, add their cost
 
			segment_cost += YAPF_TILE_LENGTH * F.m_tunnel_tiles_skipped;
 

	
 
			// add min/max speed penalties
 
			int min_speed = 0;
 
			int max_speed = F.GetSpeedLimit(&min_speed);
yapf/yapf_destrail.hpp
Show inline comments
 
@@ -26,25 +26,31 @@ class CYapfDestinationAnyDepotRailT
 
{
 
public:
 
	typedef typename Types::Tpf Tpf;              ///< the pathfinder class (derived from THIS class)
 
	typedef typename Types::NodeList::Titem Node; ///< this will be our node type
 
	typedef typename Node::Key Key;               ///< key to hash tables
 

	
 
	/// to access inherited path finder
 
	Tpf& Yapf() {return *static_cast<Tpf*>(this);}
 

	
 
	/// Called by YAPF to detect if node ends in the desired destination
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	{
 
		bool bDest = IsTileDepotType(n.GetLastTile(), TRANSPORT_RAIL);
 
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
 
	}
 

	
 
	/// Called by YAPF to detect if node ends in the desired destination
 
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	{
 
		bool bDest = IsTileDepotType(tile, TRANSPORT_RAIL);
 
		return bDest;
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	*   adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	{
 
		n.m_estimate = n.m_cost;
 
		return true;
 
	}
 
};
 

	
 
@@ -84,32 +90,38 @@ public:
 
			m_destTrackdirs = INVALID_TRACKDIR_BIT;
 
		} else {
 
			m_destTile = v->dest_tile;
 
			m_dest_station_id = INVALID_STATION;
 
			m_destTrackdirs = (TrackdirBits)(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL) & TRACKDIR_BIT_MASK);
 
		}
 
		CYapfDestinationRailBase::SetDestination(v);
 
	}
 

	
 
	/// Called by YAPF to detect if node ends in the desired destination
 
	FORCEINLINE bool PfDetectDestination(Node& n)
 
	{
 
		return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
 
	}
 

	
 
	/// Called by YAPF to detect if node ends in the desired destination
 
	FORCEINLINE bool PfDetectDestination(TileIndex tile, Trackdir td)
 
	{
 
		bool bDest;
 
		if (m_dest_station_id != INVALID_STATION) {
 
			bDest = IsRailwayStationTile(n.GetLastTile())
 
				&& (GetStationIndex(n.GetLastTile()) == m_dest_station_id)
 
				&& (GetRailStationTrack(n.GetLastTile()) == TrackdirToTrack(n.GetLastTrackdir()));
 
			bDest = IsRailwayStationTile(tile)
 
				&& (GetStationIndex(tile) == m_dest_station_id)
 
				&& (GetRailStationTrack(tile) == TrackdirToTrack(td));
 
		} else {
 
			bDest = (n.GetLastTile() == m_destTile)
 
				&& ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetLastTrackdir())) != TRACKDIR_BIT_NONE);
 
			bDest = (tile == m_destTile)
 
				&& ((m_destTrackdirs & TrackdirToTrackdirBits(td)) != TRACKDIR_BIT_NONE);
 
		}
 
		return bDest;
 
	}
 

	
 
	/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
 
	*   adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
 
	FORCEINLINE bool PfCalcEstimate(Node& n)
 
	{
 
		static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
 
		static int dg_dir_to_y_offs[] = {0, 1, 0, -1};
 
		if (PfDetectDestination(n)) {
 
			n.m_estimate = n.m_cost;
0 comments (0 inline, 0 general)