summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ship_cmd.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 415d97ebc..0d8cd6c37 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -335,6 +335,18 @@ static Vehicle *EnsureNoMovingShipProc(Vehicle *v, void *data)
return v->type == VEH_SHIP && (v->vehstatus & (VS_HIDDEN | VS_STOPPED)) == 0 ? v : nullptr;
}
+static bool CheckReverseShip(const Ship *v)
+{
+ /* Ask pathfinder for best direction */
+ bool reverse = false;
+ switch (_settings_game.pf.pathfinder_for_ships) {
+ case VPF_NPF: reverse = NPFShipCheckReverse(v); break;
+ case VPF_YAPF: reverse = YapfShipCheckReverse(v); break;
+ default: NOT_REACHED();
+ }
+ return reverse;
+}
+
static bool CheckShipLeaveDepot(Ship *v)
{
if (!v->IsChainInDepot()) return false;
@@ -364,14 +376,7 @@ static bool CheckShipLeaveDepot(Ship *v)
TrackBits north_tracks = DiagdirReachesTracks(north_dir) & GetTileShipTrackStatus(north_neighbour);
TrackBits south_tracks = DiagdirReachesTracks(south_dir) & GetTileShipTrackStatus(south_neighbour);
if (north_tracks && south_tracks) {
- /* Ask pathfinder for best direction */
- bool reverse = false;
- switch (_settings_game.pf.pathfinder_for_ships) {
- case VPF_NPF: reverse = NPFShipCheckReverse(v); break;
- case VPF_YAPF: reverse = YapfShipCheckReverse(v); break;
- default: NOT_REACHED();
- }
- if (reverse) north_tracks = TRACK_BIT_NONE;
+ if (CheckReverseShip(v)) north_tracks = TRACK_BIT_NONE;
}
if (north_tracks) {
@@ -624,6 +629,7 @@ static void ShipController(Ship *v)
const byte *b;
Track track;
TrackBits tracks;
+ GetNewVehiclePosResult gp;
v->tick_counter++;
v->current_order_time++;
@@ -632,7 +638,8 @@ static void ShipController(Ship *v)
if (v->vehstatus & VS_STOPPED) return;
- ProcessOrders(v);
+ if (ProcessOrders(v) && CheckReverseShip(v)) goto reverse_direction;
+
v->HandleLoading();
if (v->current_order.IsType(OT_LOADING)) return;
@@ -657,7 +664,7 @@ static void ShipController(Ship *v)
if (!ShipAccelerate(v)) return;
- GetNewVehiclePosResult gp = GetNewVehiclePos(v);
+ gp = GetNewVehiclePos(v);
if (v->state != TRACK_BIT_WORMHOLE) {
/* Not on a bridge */
if (gp.old_tile == gp.new_tile) {