From bc04b07f2be187258f32fa0d64d757a680665a83 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 8 Sep 2016 00:12:27 +0100 Subject: [PATCH] Fix double-use of bits 3 and 7 in Order::flags. Use a different encoding for the cargo type load/unload bit in flags. --- src/order_base.h | 26 ++++++++++++++++++++++---- src/order_type.h | 4 +++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/order_base.h b/src/order_base.h index 2e1a864783..9b4292db15 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -160,7 +160,12 @@ public: void SetRefit(CargoID cargo); /** How must the consist be loaded? */ - inline OrderLoadFlags GetLoadType() const { return (OrderLoadFlags)GB(this->flags, 4, 4); } + inline OrderLoadFlags GetLoadType() const + { + OrderLoadFlags type = (OrderLoadFlags)GB(this->flags, 4, 3); + if (type == OLFB_CARGO_TYPE_LOAD_ENCODING) type = OLFB_CARGO_TYPE_LOAD; + return type; + } /** * How must the consist be loaded for this type of cargo? @@ -189,7 +194,12 @@ public: } /** How must the consist be unloaded? */ - inline OrderUnloadFlags GetUnloadType() const { return (OrderUnloadFlags)GB(this->flags, 0, 4); } + inline OrderUnloadFlags GetUnloadType() const + { + OrderUnloadFlags type = (OrderUnloadFlags)GB(this->flags, 0, 3); + if (type == OUFB_CARGO_TYPE_UNLOAD_ENCODING) type = OUFB_CARGO_TYPE_UNLOAD; + return type; + } /** * How must the consist be unloaded for this type of cargo? @@ -249,7 +259,11 @@ public: inline uint16 GetConditionValue() const { return GB(this->dest, 0, 11); } /** Set how the consist must be loaded. */ - inline void SetLoadType(OrderLoadFlags load_type) { SB(this->flags, 4, 4, load_type); } + inline void SetLoadType(OrderLoadFlags load_type) + { + if (load_type == OLFB_CARGO_TYPE_LOAD) load_type = OLFB_CARGO_TYPE_LOAD_ENCODING; + SB(this->flags, 4, 3, load_type); + } /** * Set how the consist must be loaded for this type of cargo. @@ -265,7 +279,11 @@ public: } /** Set how the consist must be unloaded. */ - inline void SetUnloadType(OrderUnloadFlags unload_type) { SB(this->flags, 0, 4, unload_type); } + inline void SetUnloadType(OrderUnloadFlags unload_type) + { + if (unload_type == OUFB_CARGO_TYPE_UNLOAD) unload_type = OUFB_CARGO_TYPE_UNLOAD_ENCODING; + SB(this->flags, 0, 3, unload_type); + } /** * Set how the consist must be unloaded for this type of cargo. diff --git a/src/order_type.h b/src/order_type.h index 05625c422e..78f7ca23c7 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -61,6 +61,7 @@ enum OrderUnloadFlags { OUFB_TRANSFER = 1 << 1, ///< Transfer all cargo onto the platform. OUFB_NO_UNLOAD = 1 << 2, ///< Totally no unloading will be done. OUFB_CARGO_TYPE_UNLOAD = 1 << 3, ///< Unload actions are defined per cargo type. + OUFB_CARGO_TYPE_UNLOAD_ENCODING = (1 << 0) | (1 << 2), ///< Raw encoding of OUFB_CARGO_TYPE_UNLOAD }; /** @@ -71,7 +72,8 @@ enum OrderLoadFlags { OLFB_FULL_LOAD = 1 << 1, ///< Full load all cargoes of the consist. OLF_FULL_LOAD_ANY = 3, ///< Full load a single cargo of the consist. OLFB_NO_LOAD = 4, ///< Do not load anything. - OLFB_CARGO_TYPE_LOAD = 1 << 3 ///< Load actions are defined per cargo type. + OLFB_CARGO_TYPE_LOAD = 1 << 3, ///< Load actions are defined per cargo type. + OLFB_CARGO_TYPE_LOAD_ENCODING = (1 << 1) | 4, ///< Raw encoding of OLFB_CARGO_TYPE_LOAD }; /**