summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-20 16:19:47 +0000
committerrubidium <rubidium@openttd.org>2009-12-20 16:19:47 +0000
commitf2785ae24d369b68f246a162ff7619e61d8a380a (patch)
tree8243637bf95317635bd4e736f34999dd481e3a99
parent4d9097cafb39ecdc2b8f5e6ba42fe3c9e1d3f20b (diff)
downloadopenttd-f2785ae24d369b68f246a162ff7619e61d8a380a.tar.xz
(svn r18574) -Fix [FS#3392] (r18481): manually sending trains and RVs to depots didn't quite work
-rw-r--r--src/roadveh_cmd.cpp4
-rw-r--r--src/ship_cmd.cpp15
-rw-r--r--src/train_cmd.cpp4
3 files changed, 14 insertions, 9 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 99a0f9f6a..5df4572a6 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -361,8 +361,8 @@ static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance
if (IsRoadDepotTile(v->tile)) return FindDepotData(v->tile, 0);
switch (_settings_game.pf.pathfinder_for_roadvehs) {
- case VPF_NPF: return NPFRoadVehicleFindNearestDepot(v, _settings_game.pf.npf.maximum_go_to_depot_penalty);
- case VPF_YAPF: return YapfRoadVehicleFindNearestDepot(v, _settings_game.pf.yapf.maximum_go_to_depot_penalty);
+ case VPF_NPF: return NPFRoadVehicleFindNearestDepot(v, max_distance);
+ case VPF_YAPF: return YapfRoadVehicleFindNearestDepot(v, max_distance);
default: NOT_REACHED();
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 9bc96ab88..acd5754ec 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -97,12 +97,17 @@ SpriteID Ship::GetImage(Direction direction) const
return _ship_sprites[spritenum] + direction;
}
-static const Depot *FindClosestShipDepot(const Vehicle *v)
+static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance)
{
/* Find the closest depot */
const Depot *depot;
const Depot *best_depot = NULL;
- uint best_dist = UINT_MAX;
+ /* If we don't have a maximum distance, i.e. distance = 0,
+ * we want to find any depot so the best distance of no
+ * depot must be more than any correct distance. On the
+ * other hand if we have set a maximum distance, any depot
+ * further away than max_distance can safely be ignored. */
+ uint best_dist = max_distance == 0 ? UINT_MAX : max_distance + 1;
FOR_ALL_DEPOTS(depot) {
TileIndex tile = depot->xy;
@@ -134,9 +139,9 @@ static void CheckIfShipNeedsService(Vehicle *v)
default: NOT_REACHED();
}
- const Depot *depot = FindClosestShipDepot(v);
+ const Depot *depot = FindClosestShipDepot(v, max_distance);
- if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > max_distance) {
+ if (depot == NULL) {
if (v->current_order.IsType(OT_GOTO_DEPOT)) {
v->current_order.MakeDummy();
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
@@ -724,7 +729,7 @@ CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p
bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
{
- const Depot *depot = FindClosestShipDepot(this);
+ const Depot *depot = FindClosestShipDepot(this, 0);
if (depot == NULL) return false;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 34d767bec..dd2c7fd19 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2107,8 +2107,8 @@ static FindDepotData FindClosestTrainDepot(Train *v, int max_distance)
if (IsRailDepotTile(origin.tile)) return FindDepotData(origin.tile, 0);
switch (_settings_game.pf.pathfinder_for_trains) {
- case VPF_NPF: return NPFTrainFindNearestDepot(v, _settings_game.pf.npf.maximum_go_to_depot_penalty);
- case VPF_YAPF: return YapfTrainFindNearestDepot(v, _settings_game.pf.yapf.maximum_go_to_depot_penalty);
+ case VPF_NPF: return NPFTrainFindNearestDepot(v, max_distance);
+ case VPF_YAPF: return YapfTrainFindNearestDepot(v, max_distance);
default: NOT_REACHED();
}