From a9a21e784da0e13eb7d6240c0346d17d487307b4 Mon Sep 17 00:00:00 2001 From: Nicolas Chappe <74881848+nchappe@users.noreply.github.com> Date: Tue, 26 Jul 2022 18:27:54 +0200 Subject: [PATCH] Codechange: Always set the ODATFB_NEAREST_DEPOT flag for 'any depot' orders --- src/depot_type.h | 6 +++++- src/order_cmd.cpp | 6 +++--- src/order_gui.cpp | 2 +- src/script/api/script_order.cpp | 2 +- src/train_cmd.cpp | 2 +- src/vehicle_gui.cpp | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/depot_type.h b/src/depot_type.h index a2326794a0..d511b1b9e5 100644 --- a/src/depot_type.h +++ b/src/depot_type.h @@ -10,9 +10,13 @@ #ifndef DEPOT_TYPE_H #define DEPOT_TYPE_H -typedef uint16 DepotID; ///< Type for the unique identifier of depots. +#include "station_type.h" + +typedef StationID DepotID; ///< Type for the unique identifier of depots. struct Depot; +static const DepotID INVALID_DEPOT = INVALID_STATION; + static const uint MAX_LENGTH_DEPOT_NAME_CHARS = 32; ///< The maximum length of a depot name in characters including '\0' #endif /* DEPOT_TYPE_H */ diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 42cad82ad3..37f1c5ed34 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -656,7 +656,7 @@ void OrderList::DebugCheckSanity() const static inline bool OrderGoesToStation(const Vehicle *v, const Order *o) { return o->IsType(OT_GOTO_STATION) || - (v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT)); + (v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && o->GetDestination() != INVALID_STATION); } /** @@ -690,7 +690,7 @@ TileIndex Order::GetLocation(const Vehicle *v, bool airport) const return BaseStation::Get(this->GetDestination())->xy; case OT_GOTO_DEPOT: - if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE; + if (this->GetDestination() == INVALID_DEPOT) return INVALID_TILE; return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy; default: @@ -1991,7 +1991,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool if (pbs_look_ahead && reverse) return false; v->SetDestTile(location); - v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo()); + v->current_order.SetDestination(destination); /* If there is no depot in front, reverse automatically (trains only) */ if (v->type == VEH_TRAIN && reverse) Command::Do(DC_EXEC, v->index, false); diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 982c8f7b29..16f5d49447 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -619,7 +619,7 @@ private: Order order; order.next = nullptr; order.index = 0; - order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS, + order.MakeGoToDepot(INVALID_DEPOT, ODTFB_PART_OF_ORDERS, _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); order.SetDepotActionType(ODATFB_NEAREST_DEPOT); diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index c127d11e3c..1886080aa7 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -470,7 +470,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (order_flags & OF_GOTO_NEAREST_DEPOT) odaf |= ODATFB_NEAREST_DEPOT; OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & OF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); if (order_flags & OF_GOTO_NEAREST_DEPOT) { - order.MakeGoToDepot(0, odtf, onsf, odaf); + order.MakeGoToDepot(INVALID_DEPOT, odtf, onsf, odaf); } else { /* Check explicitly if the order is to a station (for aircraft) or * to a depot (other vehicle types). */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index e84ac6b8ea..b08c57587b 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3974,7 +3974,7 @@ static void CheckIfTrainNeedsService(Train *v) } SetBit(v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); - v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE); + v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, ODATFB_NEAREST_DEPOT); v->dest_tile = tfdd.tile; SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 41ac89846c..49e57c605e 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2864,7 +2864,7 @@ public: SetDParam(0, v->type); SetDParam(1, v->current_order.GetDestination()); SetDParam(2, v->GetDisplaySpeed()); - if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) { + if (v->current_order.GetDestination() == INVALID_DEPOT) { /* This case *only* happens when multiple nearest depot orders * follow each other (including an order list only one order: a * nearest depot order) and there are no reachable depots.