From 71dfd2900a136ee880d3bd34b9820896ca74f132 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 23 Jul 2021 18:33:24 +0100 Subject: [PATCH] Add depot order flag for specific depot Use upper half of order flags for extra depot flags See: #302 --- src/order_base.h | 4 ++++ src/order_type.h | 9 +++++++++ src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/vehicle.cpp | 10 ++++++++++ 5 files changed, 25 insertions(+) diff --git a/src/order_base.h b/src/order_base.h index ebcdae82a7..07d738efb9 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -324,6 +324,8 @@ public: inline OrderDepotTypeFlags GetDepotOrderType() const { return (OrderDepotTypeFlags)GB(this->flags, 0, 3); } /** What are we going to do when in the depot. */ inline OrderDepotActionFlags GetDepotActionType() const { return (OrderDepotActionFlags)GB(this->flags, 4, 3); } + /** Extra depot flags. */ + inline OrderDepotExtraFlags GetDepotExtraFlags() const { return (OrderDepotExtraFlags)GB(this->flags, 8, 8); } /** What waypoint flags? */ inline OrderWaypointFlags GetWaypointFlags() const { return (OrderWaypointFlags)GB(this->flags, 0, 3); } /** What variable do we have to compare? */ @@ -385,6 +387,8 @@ public: inline void SetDepotOrderType(OrderDepotTypeFlags depot_order_type) { SB(this->flags, 0, 3, depot_order_type); } /** Set what we are going to do in the depot. */ inline void SetDepotActionType(OrderDepotActionFlags depot_service_type) { SB(this->flags, 4, 3, depot_service_type); } + /** Set what we are going to do in the depot. */ + inline void SetDepotExtraFlags(OrderDepotExtraFlags depot_extra_flags) { SB(this->flags, 8, 8, depot_extra_flags); } /** Set waypoint flags. */ inline void SetWaypointFlags(OrderWaypointFlags waypoint_flags) { SB(this->flags, 0, 3, waypoint_flags); } /** Set variable we have to compare. */ diff --git a/src/order_type.h b/src/order_type.h index e2cac04e12..7e44c85e58 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -117,6 +117,15 @@ enum OrderDepotActionFlags { }; DECLARE_ENUM_AS_BIT_SET(OrderDepotActionFlags) +/** + * Extra depot flags. + */ +enum OrderDepotExtraFlags { + ODEF_NONE = 0, ///< No flags. + ODEFB_SPECIFIC = 1 << 0, ///< This order is for a specific depot. +}; +DECLARE_ENUM_AS_BIT_SET(OrderDepotExtraFlags) + /** * Flags for go to waypoint orders */ diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 684f25f39c..8e374b250a 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -154,6 +154,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_STATION_CARGO_HISTORY, XSCF_NULL, 1, 1, "station_cargo_history", nullptr, nullptr, nullptr }, { XSLFI_TRAIN_SPEED_ADAPTATION, XSCF_NULL, 1, 1, "train_speed_adaptation", nullptr, nullptr, "TSAS" }, { XSLFI_EXTRA_STATION_NAMES, XSCF_NULL, 1, 1, "extra_station_names", nullptr, nullptr, nullptr }, + { XSLFI_DEPOT_ORDER_EXTRA_FLAGS,XSCF_IGNORABLE_UNKNOWN, 1, 1, "depot_order_extra_flags", nullptr, nullptr, nullptr }, { XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index b22e064202..55455248d1 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -108,6 +108,7 @@ enum SlXvFeatureIndex { XSLFI_STATION_CARGO_HISTORY, ///< Station waiting cargo history XSLFI_TRAIN_SPEED_ADAPTATION, ///< Train speed adaptation XSLFI_EXTRA_STATION_NAMES, ///< Extra station names + XSLFI_DEPOT_ORDER_EXTRA_FLAGS, ///< Depot order extra flags XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 7290874db1..2c00d38839 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2478,6 +2478,13 @@ void VehicleEnterDepot(Vehicle *v) return; } + /* Test whether we are heading for this depot. If not, do nothing. */ + if ((v->current_order.GetDepotExtraFlags() & ODEFB_SPECIFIC) && + (v->type == VEH_AIRCRAFT ? v->current_order.GetDestination() != GetStationIndex(v->tile) : v->dest_tile != v->tile)) { + /* We are heading for another depot, keep driving. */ + return; + } + if (v->current_order.GetDepotActionType() & ODATFB_SELL) { _vehicles_to_sell.insert(v->index); return; @@ -3600,6 +3607,9 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command, Tile } else if (!(command & DEPOT_SERVICE)) { this->current_order.SetDepotActionType(ODATFB_HALT); } + if (command & DEPOT_SPECIFIC) { + this->current_order.SetDepotExtraFlags(ODEFB_SPECIFIC); + } SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); /* If there is no depot in front and the train is not already reversing, reverse automatically (trains only) */