|
|
|
@ -438,29 +438,34 @@ public:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
|
|
|
|
|
static FindDepotData stFindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
|
|
|
|
|
{
|
|
|
|
|
Tpf pf;
|
|
|
|
|
return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile);
|
|
|
|
|
return pf.FindNearestDepot(v, tile, td, max_distance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
|
|
|
|
|
/**
|
|
|
|
|
* Find the best depot for a road vehicle.
|
|
|
|
|
* @param v Vehicle
|
|
|
|
|
* @param tile Tile of the vehicle.
|
|
|
|
|
* @param td Trackdir of the vehicle.
|
|
|
|
|
* @param max_distance max length (penalty) for paths.
|
|
|
|
|
* @todo max_distance not used by YAPF for road vehicles.
|
|
|
|
|
* It can be removed or copy the SetMaxCost() strategy
|
|
|
|
|
* applied in YAPF for rail. The best depot can be at
|
|
|
|
|
* a distance greater than max_distance.
|
|
|
|
|
*/
|
|
|
|
|
inline FindDepotData FindNearestDepot(const RoadVehicle *v, TileIndex tile, Trackdir td, int max_distance)
|
|
|
|
|
{
|
|
|
|
|
/* set origin and destination nodes */
|
|
|
|
|
/* Set origin. */
|
|
|
|
|
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
|
|
|
|
|
|
|
|
|
|
/* find the best path */
|
|
|
|
|
bool bFound = Yapf().FindPath(v);
|
|
|
|
|
if (!bFound) return false;
|
|
|
|
|
/* Find the best path and return if no depot is found. */
|
|
|
|
|
if (!Yapf().FindPath(v)) return FindDepotData();
|
|
|
|
|
|
|
|
|
|
/* some path found
|
|
|
|
|
* get found depot tile */
|
|
|
|
|
/* Return the cost of the best path and its depot. */
|
|
|
|
|
Node *n = Yapf().GetBestNode();
|
|
|
|
|
|
|
|
|
|
if (max_distance > 0 && n->m_cost > max_distance * YAPF_TILE_LENGTH) return false;
|
|
|
|
|
|
|
|
|
|
*depot_tile = n->m_segment_last_tile;
|
|
|
|
|
return true;
|
|
|
|
|
return FindDepotData(n->m_segment_last_tile, n->m_cost);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -512,7 +517,7 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* default is YAPF type 2 */
|
|
|
|
|
typedef bool (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int, TileIndex*);
|
|
|
|
|
typedef FindDepotData (*PfnFindNearestDepot)(const RoadVehicle*, TileIndex, Trackdir, int);
|
|
|
|
|
PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
|
|
|
|
|
|
|
|
|
|
/* check if non-default YAPF type should be used */
|
|
|
|
@ -520,8 +525,5 @@ FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_dist
|
|
|
|
|
pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FindDepotData fdd;
|
|
|
|
|
bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, &fdd.tile);
|
|
|
|
|
fdd.best_length = ret ? max_distance / 2 : UINT_MAX; // some fake distance or NOT_FOUND
|
|
|
|
|
return fdd;
|
|
|
|
|
return pfnFindNearestDepot(v, tile, trackdir, max_distance);
|
|
|
|
|
}
|
|
|
|
|