From 71c39dc8c2e7ada9c9a7d54fb5dabfd06685f3a9 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 19 Nov 2021 00:53:01 +0000 Subject: [PATCH] If train next order is for same station when leaving, do not leave Just start loading again without moving instead --- src/train_cmd.cpp | 22 ++++++++++++++++++++++ src/vehicle.cpp | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index a7d4055a61..79be35f455 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -6382,7 +6382,29 @@ static bool TrainLocoHandler(Train *v, bool mode) } if (v->current_order.IsType(OT_LEAVESTATION)) { + StationID station_id = v->current_order.GetDestination(); v->current_order.Free(); + + bool may_reverse = ProcessOrders(v); + + if (IsRailStationTile(v->tile) && GetStationIndex(v->tile) == station_id) { + if (v->current_order.ShouldStopAtStation(INVALID_STATION, station_id, false)) { + v->last_station_visited = station_id; + v->BeginLoading(); + return true; + } + } + + v->PlayLeaveStationSound(); + + if (may_reverse && CheckReverseTrain(v)) { + v->wait_counter = 0; + v->cur_speed = 0; + v->subspeed = 0; + ClrBit(v->flags, VRF_LEAVING_STATION); + ReverseTrainDirection(v); + } + SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); return true; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 8049296e98..0d83158341 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3464,7 +3464,7 @@ void Vehicle::HandleLoading(bool mode) return; } - this->PlayLeaveStationSound(); + if (this->type != VEH_TRAIN) this->PlayLeaveStationSound(); this->LeaveStation();