summaryrefslogtreecommitdiff
path: root/src/pathfinder/yapf
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-05-29 14:14:52 +0000
committerfrosch <frosch@openttd.org>2016-05-29 14:14:52 +0000
commitd90686f0217c2ad8dfc814694b7b9ea578dd7a49 (patch)
tree230b82d8488790598bc5d025887e03d3fa8a9a47 /src/pathfinder/yapf
parentb0c56f3432645b505672adae8938f1a4e70febc3 (diff)
downloadopenttd-d90686f0217c2ad8dfc814694b7b9ea578dd7a49.tar.xz
(svn r27586) -Fix [FS#6410]: Automatic servicing of road vehicles compared path finder costs with tile distances, thus vehicles went to depots which were factor 100 too far away. (juanjo)
Diffstat (limited to 'src/pathfinder/yapf')
-rw-r--r--src/pathfinder/yapf/yapf_road.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp
index 4c26d7b09..380b641da 100644
--- a/src/pathfinder/yapf/yapf_road.cpp
+++ b/src/pathfinder/yapf/yapf_road.cpp
@@ -430,29 +430,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);
}
};
@@ -504,7 +509,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 */
@@ -512,8 +517,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);
}