(svn r17333) -Codechange: make the road pathfinder 'interface' like the one for the rail pathfinder

-Fix [FS#3057]: road vehicles forgetting their servicing order when the path takes them away (in bird distance) from their destination first
This commit is contained in:
rubidium
2009-08-31 19:16:18 +00:00
parent a1c7271eb0
commit d938896691
3 changed files with 62 additions and 40 deletions

View File

@@ -53,20 +53,25 @@ Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
*/
uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile);
/** Used when user sends RV to the nearest depot or if RV needs servicing.
* Returns the nearest depot (or NULL if depot was not found).
/** Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing.
* @param v vehicle that needs to go to some depot
* @param max_distance max distance (number of track tiles) from the current vehicle position
* (used also as optimization - the pathfinder can stop path finding if max_distance
* was reached and no depot was seen)
* @param depot_tile receives the depot tile if depot was found
* @return true if depot was found.
*/
Depot *YapfFindNearestRoadDepot(const Vehicle *v);
bool YapfFindNearestRoadDepot(const Vehicle *v, int max_distance, TileIndex *depot_tile);
/** Used when user sends train to the nearest depot or if train needs servicing.
* @param v train that needs to go to some depot
* @param max_distance max distance (number of track tiles) from the current train position
* (used also as optimization - the pathfinder can stop path finding if max_distance
* was reached and no depot was seen)
* (used also as optimization - the pathfinder can stop path finding if max_distance
* was reached and no depot was seen)
* @param reverse_penalty penalty that should be added for the path that requires reversing the train first
* @param depot_tile receives the depot tile if depot was found
* @param reversed receives true if train needs to reversed first
* @return the true if depot was found.
* @return true if depot was found.
*/
bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed);

View File

@@ -390,13 +390,13 @@ public:
return true;
}
static Depot *stFindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td)
static bool stFindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
{
Tpf pf;
return pf.FindNearestDepot(v, tile, td);
return pf.FindNearestDepot(v, tile, td, max_distance, depot_tile);
}
FORCEINLINE Depot *FindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td)
FORCEINLINE bool FindNearestDepot(const Vehicle *v, TileIndex tile, Trackdir td, int max_distance, TileIndex *depot_tile)
{
/* set origin and destination nodes */
Yapf().SetOrigin(tile, TrackdirToTrackdirBits(td));
@@ -408,10 +408,11 @@ public:
/* some path found
* get found depot tile */
Node *n = Yapf().GetBestNode();
TileIndex depot_tile = n->m_segment_last_tile;
assert(IsRoadDepotTile(depot_tile));
Depot *ret = Depot::GetByTile(depot_tile);
return ret;
if (max_distance > 0 && n->m_cost > max_distance * YAPF_TILE_LENGTH) return false;
*depot_tile = n->m_segment_last_tile;
return true;
}
};
@@ -474,8 +475,10 @@ uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile)
return dist;
}
Depot *YapfFindNearestRoadDepot(const Vehicle *v)
bool YapfFindNearestRoadDepot(const Vehicle *v, int max_distance, TileIndex *depot_tile)
{
*depot_tile = INVALID_TILE;
TileIndex tile = v->tile;
Trackdir trackdir = v->GetVehicleTrackdir();
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, RoadVehicle::From(v)->compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
@@ -489,7 +492,7 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
}
/* default is YAPF type 2 */
typedef Depot *(*PfnFindNearestDepot)(const Vehicle*, TileIndex, Trackdir);
typedef bool (*PfnFindNearestDepot)(const Vehicle*, TileIndex, Trackdir, int, TileIndex*);
PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
/* check if non-default YAPF type should be used */
@@ -497,6 +500,6 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
}
Depot *ret = pfnFindNearestDepot(v, tile, trackdir);
bool ret = pfnFindNearestDepot(v, tile, trackdir, max_distance, depot_tile);
return ret;
}