diff --git a/src/order_base.h b/src/order_base.h index 8f2f10c252..b223440c59 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -225,6 +225,7 @@ public: inline void SetMaxSpeed(uint16_t speed) { this->max_speed = speed; } bool ShouldStopAtStation(const Vehicle *v, StationID station) const; + bool ShouldStopAtDepot(DepotID depot) const; bool CanLoadOrUnload() const; bool CanLeaveWithCargo(bool has_cargo) const; diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 63a5869acb..c9000c18bc 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -2215,6 +2215,17 @@ bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const !(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS)); } +/** + * Check whether the given vehicle should stop at the given depot. + * @param v the vehicle that might be stopping. + * @param depot the depot to stop at. + * @return true if the vehicle should stop. + */ +bool Order::ShouldStopAtDepot(DepotID depot) const +{ + return this->IsType(OT_GOTO_DEPOT) && this->dest == depot; +} + bool Order::CanLoadOrUnload() const { return (this->IsType(OT_GOTO_STATION) || this->IsType(OT_IMPLICIT)) && diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 5680a31ff5..c82dc1c2d9 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2365,7 +2365,7 @@ static void CheckNextTrainTile(Train *v) switch (v->current_order.GetType()) { /* Exit if we reached our destination depot. */ case OT_GOTO_DEPOT: - if (v->tile == v->dest_tile) return; + if (IsRailDepotTile(v->tile) && v->current_order.ShouldStopAtDepot(GetDepotIndex(v->tile))) return; break; case OT_GOTO_WAYPOINT: