summaryrefslogtreecommitdiff
path: root/src/pathfinder
diff options
context:
space:
mode:
Diffstat (limited to 'src/pathfinder')
-rw-r--r--src/pathfinder/opf/opf_ship.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/pathfinder/opf/opf_ship.cpp b/src/pathfinder/opf/opf_ship.cpp
index 4557e3a3f..985c2ed5d 100644
--- a/src/pathfinder/opf/opf_ship.cpp
+++ b/src/pathfinder/opf/opf_ship.cpp
@@ -205,8 +205,11 @@ Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
uint dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track);
/* If the dist equals zero, or distr equals one (the extra reversing penalty),
- * then we found our destination and we are not lost. */
- path_found = (dist == 0 || distr == 1);
+ * then we found our destination and we are not lost.
+ * When we are not lost (yet) and the distance to our destination becomes
+ * less, then we aren't lost yet.
+ * So, we only become lost when the distance to our destination increases. */
+ path_found = (dist == 0 || distr == 1 || (!(v->vehicle_flags & VF_PATHFINDER_LOST) && min(dist, distr) < DistanceManhattan(tile, v->dest_tile)));
if (dist <= distr) return track;
return INVALID_TRACK; // We could better reverse
}