summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx22 <glx@openttd.org>2021-10-05 17:58:19 +0200
committerLoïc Guilloux <glx22@users.noreply.github.com>2021-10-11 21:11:13 +0200
commit207cf7bbdd2c3b919530fe66049131c18df71e4b (patch)
tree88f0d5098c682153e3a212f55f683d3045e870df
parentd0092925c9aac01b88f13bf7be29305fec3a5be1 (diff)
downloadopenttd-207cf7bbdd2c3b919530fe66049131c18df71e4b.tar.xz
Change: Reverse ship when leaving docks if a better path exists
-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) {