# HG changeset patch # Parent b7b78d2b5f18b82df46908d3ed0146d460e3e68f # User sbr # Date 1347526462 -7200 Add: Cargo type orders: store load/unload types for each cargo type. diff -r b7b78d2b5f18 src/order_base.h --- a/src/order_base.h Thu Sep 13 18:00:11 2012 +0200 +++ b/src/order_base.h Sun Sep 16 11:46:28 2012 +0200 @@ -44,6 +44,8 @@ CargoID refit_cargo; ///< Refit CargoID byte refit_subtype; ///< Refit subtype + uint8 cargo_type_flags[NUM_CARGO]; ///< Load/unload types for each cargo type. + public: Order *next; ///< Pointer to next order. If NULL, end of list @@ -135,8 +137,34 @@ /** How must the consist be loaded? */ inline OrderLoadFlags GetLoadType() const { return (OrderLoadFlags)GB(this->flags, 4, 4); } + + /** + * How must the consist be loaded for this type of cargo? + * @pre GetLoadType() == OLFB_CARGO_TYPE_LOAD + * @param cargo_id The cargo type index. + * @return The load type for this cargo. + */ + inline OrderLoadFlags GetLoadType(CargoID cargo_id) const + { + assert(cargo_id < NUM_CARGO); + return (OrderLoadFlags) GB(this->cargo_type_flags[cargo_id], 4, 4); + } + /** How must the consist be unloaded? */ inline OrderUnloadFlags GetUnloadType() const { return (OrderUnloadFlags)GB(this->flags, 0, 4); } + + /** + * How must the consist be unloaded for this type of cargo? + * @pre GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD + * @param cargo_id The cargo type index. + * @return The unload type for this cargo. + */ + inline OrderUnloadFlags GetUnloadType(CargoID cargo_id) const + { + assert(cargo_id < NUM_CARGO); + return (OrderUnloadFlags) GB(this->cargo_type_flags[cargo_id], 0, 4); + } + /** At which stations must we stop? */ inline OrderNonStopFlags GetNonStopType() const { return (OrderNonStopFlags)GB(this->type, 6, 2); } /** Where must we stop at the platform? */ @@ -156,8 +184,34 @@ /** Set how the consist must be loaded. */ inline void SetLoadType(OrderLoadFlags load_type) { SB(this->flags, 4, 4, load_type); } + + /** + * Set how the consist must be loaded for this type of cargo. + * @pre GetLoadType() == OLFB_CARGO_TYPE_LOAD + * @param load_type The load type. + * @param cargo_id The cargo type index. + */ + inline void SetLoadType(OrderLoadFlags load_type, CargoID cargo_id) + { + assert(cargo_id < NUM_CARGO); + SB(this->cargo_type_flags[cargo_id], 4, 4, load_type); + } + /** Set how the consist must be unloaded. */ inline void SetUnloadType(OrderUnloadFlags unload_type) { SB(this->flags, 0, 4, unload_type); } + + /** + * Set how the consist must be unloaded for this type of cargo. + * @pre GetUnloadType() == OUFB_CARGO_TYPE_UNLOAD + * @param unload_type The unload type. + * @param cargo_id The cargo type index. + */ + inline void SetUnloadType(OrderUnloadFlags unload_type, CargoID cargo_id) + { + assert(cargo_id < NUM_CARGO); + SB(this->cargo_type_flags[cargo_id], 0, 4, unload_type); + } + /** Set whether we must stop at stations or not. */ inline void SetNonStopType(OrderNonStopFlags non_stop_type) { SB(this->type, 6, 2, non_stop_type); } /** Set where we must stop at the platform. */ diff -r b7b78d2b5f18 src/order_type.h --- a/src/order_type.h Thu Sep 13 18:00:11 2012 +0200 +++ b/src/order_type.h Sun Sep 16 11:46:28 2012 +0200 @@ -54,6 +54,7 @@ OUFB_UNLOAD = 1 << 0, ///< Force unloading all cargo onto the platform, possibly not getting paid. 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. }; /** @@ -64,6 +65,7 @@ OLFB_FULL_LOAD = 1 << 1, ///< Full load the complete the consist. OLF_FULL_LOAD_ANY = 3, ///< Full load the 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. }; /** diff -r b7b78d2b5f18 src/saveload/order_sl.cpp --- a/src/saveload/order_sl.cpp Thu Sep 13 18:00:11 2012 +0200 +++ b/src/saveload/order_sl.cpp Sun Sep 16 11:46:28 2012 +0200 @@ -111,6 +111,7 @@ SLE_CONDVAR(Order, wait_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR(Order, travel_time, SLE_UINT16, 67, SL_MAX_VERSION), SLE_CONDVAR(Order, max_speed, SLE_UINT16, 172, SL_MAX_VERSION), + SLE_CONDARR(Order, cargo_type_flags, SLE_UINT8, NUM_CARGO, 177, SL_MAX_VERSION), /* Leftover from the minor savegame version stuff * We will never use those free bytes, but we have to keep this line to allow loading of old savegames */ diff -r b7b78d2b5f18 src/saveload/saveload.cpp --- a/src/saveload/saveload.cpp Thu Sep 13 18:00:11 2012 +0200 +++ b/src/saveload/saveload.cpp Sun Sep 16 11:46:28 2012 +0200 @@ -240,8 +240,9 @@ * 174 23973 1.2.x * 175 24136 * 176 24446 + * 177 >24523 */ -extern const uint16 SAVEGAME_VERSION = 176; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 177; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading