summaryrefslogtreecommitdiff
path: root/src/yapf
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
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')
-rw-r--r--src/yapf/yapf.h17
-rw-r--r--src/yapf/yapf_road.cpp23
2 files changed, 24 insertions, 16 deletions
diff --git a/src/yapf/yapf.h b/src/yapf/yapf.h
index 9adf22532..aaff42028 100644
--- a/src/yapf/yapf.h
+++ b/src/yapf/yapf.h
@@ -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);
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;
}