diff options
Diffstat (limited to 'src/pathfinder/npf/npf.cpp')
-rw-r--r-- | src/pathfinder/npf/npf.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 3bc596e63..f7cb1a5cd 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -1211,7 +1211,7 @@ Track NPFShipChooseTrack(const Ship *v, bool &path_found) return TrackdirToTrack(ftd.best_trackdir); } -bool NPFShipCheckReverse(const Ship *v) +bool NPFShipCheckReverse(const Ship *v, Trackdir *best_td) { NPFFindStationOrTileData fstd; NPFFoundTargetData ftd; @@ -1224,7 +1224,21 @@ bool NPFShipCheckReverse(const Ship *v) assert(trackdir_rev != INVALID_TRACKDIR); AyStarUserData user = { v->owner, TRANSPORT_WATER, RAILTYPES_NONE, ROADTYPES_NONE, 0 }; - ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, v->tile, trackdir_rev, false, &fstd, &user); + if (best_td != nullptr) { + TrackdirBits rtds = DiagdirReachesTrackdirs(ReverseDiagDir(VehicleExitDir(v->direction, v->state))); + Trackdir best = (Trackdir)FindFirstBit2x64(rtds); + for (rtds = KillFirstBit(rtds); 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; + } + if (ftd.best_bird_dist == 0) { + *best_td = best; + return true; + } + } else { + ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, v->tile, trackdir_rev, false, &fstd, &user); + } /* If we didn't find anything, just keep on going straight ahead, otherwise take the reverse flag */ return ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE); } |