summaryrefslogtreecommitdiff
path: root/src/yapf/yapf_road.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-08-31 19:16:18 +0000
committerrubidium <rubidium@openttd.org>2009-08-31 19:16:18 +0000
commitd938896691164bd7d06c79c2943e4368ae321af5 (patch)
treeb994dab79bfbdd1f1388042e95e6579f5e764db2 /src/yapf/yapf_road.cpp
parenta1c7271eb0be00daee57100a4d9b815e6aa42067 (diff)
downloadopenttd-d938896691164bd7d06c79c2943e4368ae321af5.tar.xz
(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
Diffstat (limited to 'src/yapf/yapf_road.cpp')
-rw-r--r--src/yapf/yapf_road.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/yapf/yapf_road.cpp b/src/yapf/yapf_road.cpp
index a32eba665..2fe1e2374 100644
--- a/src/yapf/yapf_road.cpp
+++ b/src/yapf/yapf_road.cpp
@@ -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;
}