summaryrefslogtreecommitdiff
path: root/src/pathfinder/yapf/yapf_ship.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pathfinder/yapf/yapf_ship.cpp')
-rw-r--r--src/pathfinder/yapf/yapf_ship.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp
index 3a54ddb3e..25a63ec66 100644
--- a/src/pathfinder/yapf/yapf_ship.cpp
+++ b/src/pathfinder/yapf/yapf_ship.cpp
@@ -204,14 +204,15 @@ public:
* @param tile Current position
* @param td1 Forward direction
* @param td2 Reverse direction
+ * @param trackdir [out] the best of all possible reversed trackdirs
* @return true if the reverse direction is better
*/
- static bool CheckShipReverse(const Ship *v, TileIndex tile, Trackdir td1, Trackdir td2)
+ static bool CheckShipReverse(const Ship *v, TileIndex tile, Trackdir td1, Trackdir td2, Trackdir *trackdir)
{
/* create pathfinder instance */
Tpf pf;
/* set origin and destination nodes */
- pf.SetOrigin(tile, TrackdirToTrackdirBits(td1) | TrackdirToTrackdirBits(td2));
+ pf.SetOrigin(tile, trackdir == nullptr ? TrackdirToTrackdirBits(td1) | TrackdirToTrackdirBits(td2) : DiagdirReachesTrackdirs(ReverseDiagDir(VehicleExitDir(v->direction, v->state))));
pf.SetDestination(v);
/* find best path */
if (!pf.FindPath(v)) return false;
@@ -226,8 +227,12 @@ public:
}
Trackdir best_trackdir = pNode->GetTrackdir();
- assert(best_trackdir == td1 || best_trackdir == td2);
- return best_trackdir == td2;
+ if (trackdir != nullptr) {
+ *trackdir = best_trackdir;
+ } else {
+ assert(best_trackdir == td1 || best_trackdir == td2);
+ }
+ return best_trackdir != td1;
}
};
@@ -353,13 +358,13 @@ Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir,
return (td_ret != INVALID_TRACKDIR) ? TrackdirToTrack(td_ret) : INVALID_TRACK;
}
-bool YapfShipCheckReverse(const Ship *v)
+bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir)
{
Trackdir td = v->GetVehicleTrackdir();
Trackdir td_rev = ReverseTrackdir(td);
TileIndex tile = v->tile;
- typedef bool (*PfnCheckReverseShip)(const Ship*, TileIndex, Trackdir, Trackdir);
+ typedef bool (*PfnCheckReverseShip)(const Ship*, TileIndex, Trackdir, Trackdir, Trackdir*);
PfnCheckReverseShip pfnCheckReverseShip = CYapfShip2::CheckShipReverse; // default: ExitDir
/* check if non-default YAPF type needed */
@@ -367,7 +372,7 @@ bool YapfShipCheckReverse(const Ship *v)
pfnCheckReverseShip = &CYapfShip1::CheckShipReverse; // Trackdir
}
- bool reverse = pfnCheckReverseShip(v, tile, td, td_rev);
+ bool reverse = pfnCheckReverseShip(v, tile, td, td_rev, trackdir);
return reverse;
}