summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoïc Guilloux <glx22@users.noreply.github.com>2021-11-06 17:32:37 +0100
committerGitHub <noreply@github.com>2021-11-06 17:32:37 +0100
commit6ff0858b38cac1fa734081adef1ae6d6b6297a13 (patch)
tree0313e51f60b3412127718e146f05aaf9dd55743c /src
parent33ef34189e25779c222efa068313c6df5ea532ed (diff)
downloadopenttd-6ff0858b38cac1fa734081adef1ae6d6b6297a13.tar.xz
Fix #9669, cbe00ec: Only try valid reverse directions (#9672)
Diffstat (limited to 'src')
-rw-r--r--src/pathfinder/npf/npf.cpp7
-rw-r--r--src/pathfinder/yapf/yapf_ship.cpp8
2 files changed, 12 insertions, 3 deletions
diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp
index f7cb1a5cd..25681507c 100644
--- a/src/pathfinder/npf/npf.cpp
+++ b/src/pathfinder/npf/npf.cpp
@@ -1225,9 +1225,12 @@ bool NPFShipCheckReverse(const Ship *v, Trackdir *best_td)
AyStarUserData user = { v->owner, TRANSPORT_WATER, RAILTYPES_NONE, ROADTYPES_NONE, 0 };
if (best_td != nullptr) {
- TrackdirBits rtds = DiagdirReachesTrackdirs(ReverseDiagDir(VehicleExitDir(v->direction, v->state)));
+ DiagDirection entry = ReverseDiagDir(VehicleExitDir(v->direction, v->state));
+ TrackdirBits rtds = DiagdirReachesTrackdirs(entry) & TrackStatusToTrackdirBits(GetTileTrackStatus(v->tile, TRANSPORT_WATER, 0, entry));
Trackdir best = (Trackdir)FindFirstBit2x64(rtds);
- for (rtds = KillFirstBit(rtds); rtds != TRACKDIR_BIT_NONE; rtds = KillFirstBit(rtds)) {
+ rtds = KillFirstBit(rtds);
+ if (rtds == TRACKDIR_BIT_NONE) return false; /* At most one choice. */
+ for (; rtds != TRACKDIR_BIT_NONE; rtds = KillFirstBit(rtds)) {
Trackdir td = (Trackdir)FindFirstBit2x64(rtds);
ftd = NPFRouteToStationOrTileTwoWay(v->tile, best, false, v->tile, td, false, &fstd, &user);
if (ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE)) best = td;
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp
index 25a63ec66..947de5a76 100644
--- a/src/pathfinder/yapf/yapf_ship.cpp
+++ b/src/pathfinder/yapf/yapf_ship.cpp
@@ -212,7 +212,13 @@ public:
/* create pathfinder instance */
Tpf pf;
/* set origin and destination nodes */
- pf.SetOrigin(tile, trackdir == nullptr ? TrackdirToTrackdirBits(td1) | TrackdirToTrackdirBits(td2) : DiagdirReachesTrackdirs(ReverseDiagDir(VehicleExitDir(v->direction, v->state))));
+ if (trackdir == nullptr) {
+ pf.SetOrigin(tile, TrackdirToTrackdirBits(td1) | TrackdirToTrackdirBits(td2));
+ } else {
+ DiagDirection entry = ReverseDiagDir(VehicleExitDir(v->direction, v->state));
+ TrackdirBits rtds = DiagdirReachesTrackdirs(entry) & TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0, entry));
+ pf.SetOrigin(tile, rtds);
+ }
pf.SetDestination(v);
/* find best path */
if (!pf.FindPath(v)) return false;