16#include "../order_backup.h"
17#include "../settings_type.h"
18#include "../network/network.h"
20#include "../safeguards.h"
28 uint8_t old_flags = this->
flags;
41 case OT_GOTO_DEPOT:
case OT_GOTO_STATION:
case OT_LOADING:
break;
45 if (this->
GetType() != OT_GOTO_DEPOT) {
47 if ((old_flags & 2) != 0) {
49 }
else if ((old_flags & 4) == 0) {
59 if ((old_flags & 1) != 0) {
61 }
else if ((old_flags & 2) != 0) {
84 return Order(
GB(packed, 0, 4),
GB(packed, 4, 4),
GB(packed, 8, 8));
124 if (ref_index == 0)
return nullptr;
136 assert(pool_index < UINT32_MAX);
143 static const SaveLoad _order_desc[] = {
171 len /=
sizeof(uint16_t);
172 std::vector<uint16_t> orders(len);
174 SlCopy(&orders[0], len, SLE_UINT16);
176 for (
size_t i = 0; i < len; ++i) {
181 len /=
sizeof(uint32_t);
182 std::vector<uint32_t> orders(len);
184 SlCopy(&orders[0], len, SLE_UINT32);
186 for (
size_t i = 0; i < len; ++i) {
188 item.order =
Order(
GB(orders[i], 0, 8),
GB(orders[i], 8, 8),
GB(orders[i], 16, 16));
195 if (!item.order.IsType(OT_NOTHING) && num > 1) {
197 if (prev !=
nullptr) prev->
next = num;
217 static inline const SaveLoad description[] = {
228 std::vector<Order> &
GetVector(T *container)
const override {
return container->orders; }
230 void LoadCheck(T *container)
const override { this->Load(container); }
239 static const SaveLoad _orderlist_desc[] = {
245 return _orderlist_desc;
257 SlSetArrayIndex(list->index);
280 SlObject(list, GetOrderListDescription());
282 if (migrate_orders) {
283 std::vector<Order> orders;
285 orders.push_back(std::move(old_order->order));
287 list->orders = std::move(orders);
295 static const SaveLoad _order_backup_desc[] = {
316 return _order_backup_desc;
333 SlSetArrayIndex(ob->index);
356 SlObject(ob, GetOrderBackupDescription());
358 if (migrate_orders) {
359 std::vector<Order> orders;
361 orders.push_back(std::move(old_order->order));
363 ob->orders = std::move(orders);
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
std::vector< Order > & GetVector(T *container) const override
Get instance of vector to load/save.
Default handler for saving/loading a vector to/from disk.
SavegameType _savegame_type
type of savegame we are loading
bool _networking
are we in networking mode?
bool _network_server
network-server is active
PoolID< uint8_t, struct OrderBackupIDTag, 255, 0xFF > OrderBackupID
Unique identifier for an order backup.
static std::vector< OldOrderSaveLoadItem > _old_order_saveload_pool
Temporary storage for conversion from old order pool.
Order UnpackOldOrder(uint16_t packed)
Unpacks a order from savegames made with TTD(Patch)
static Order UnpackVersion4Order(uint16_t packed)
Unpacks a order from savegames with version 4 and lower.
void ClearOldOrders()
Clear all old orders.
OldOrderSaveLoadItem & AllocateOldOrder(size_t pool_index)
Allocate an old order with the given pool index.
OldOrderSaveLoadItem * GetOldOrder(size_t ref_index)
Get a pointer to an old order with the given reference index.
Loading of order chunks before table headers were added.
const SaveLoadCompat _order_sl_compat[]
Original field order for _order_desc.
const SaveLoadCompat _orderlist_sl_compat[]
Original field order for _orderlist_desc.
const SaveLoadCompat _order_backup_sl_compat[]
Original field order for _order_backup_desc.
@ OSL_PLATFORM_FAR_END
Stop at the far end of the platform.
@ OUFB_TRANSFER
Transfer all cargo onto the platform.
@ OUF_UNLOAD_IF_POSSIBLE
Unload all cargo that the station accepts.
@ OUFB_UNLOAD
Force unloading all cargo onto the platform, possibly not getting paid.
OrderDepotTypeFlags
Reasons that could cause us to go to the depot.
@ ODTFB_PART_OF_ORDERS
This depot order is because of a regular order.
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
@ ODTF_MANUAL
Manually initiated order.
@ ODATFB_HALT
Service the vehicle and then halt it.
@ ODATF_SERVICE_ONLY
Only service the vehicle.
@ OLFB_FULL_LOAD
Full load all cargoes of the consist.
@ OLFB_NO_LOAD
Do not load anything.
@ OLF_LOAD_IF_POSSIBLE
Load as long as there is cargo that fits in the train.
@ OLF_FULL_LOAD_ANY
Full load a single cargo of the consist.
@ ONSF_NO_STOP_AT_ANY_STATION
The vehicle will not stop at any stations it passes including the destination.
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
@ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
The vehicle will not stop at any stations it passes except the destination.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlCopy(void *object, size_t length, VarType conv)
Copy a list of SL_VARs to/from a savegame.
size_t SlGetFieldLength()
Get the length of the current object.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Functions/types related to saving and loading games.
@ SGT_TTD
TTD savegame (can be detected incorrectly)
#define SLE_VARNAME(base, variable, name, type)
Storage of a variable in every version of a savegame.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
@ REF_VEHICLE
Load/save a reference to a vehicle.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
@ SLV_192
192 26700 FS#6066 Fix saving of order backups
@ SLV_TIMETABLE_START_TICKS_FIX
322 PR#11557 Fix for missing convert timetable start from a date to ticks.
@ SLV_ORDERS_OWNED_BY_ORDERLIST
354 PR#13948 Orders stored in OrderList, pool removed.
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
@ CH_READONLY
Chunk is never saved.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Declaration of functions used in more save/load files.
ClientSettings _settings_client
The current settings for this game.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void FixPointers() const override
Fix the pointers.
Handlers and description of chunk.
GUISettings gui
settings related to the GUI
bool new_nonstop
ttdpatch compatible nonstop handling
bool sg_new_nonstop
ttdpatch compatible nonstop handling read from pre v93 savegames
bool sg_full_load_any
new full load calculation, any cargo must be full read from pre v93 savegames
void FixPointers() const override
Fix the pointers.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Load() const override
Load the chunk.
Compatibility struct to allow saveload of pool-based orders.
uint32_t next
The next order index (1-based).
Data for backing up an order of a vehicle so it can be restored after a vehicle is rebuilt in the sam...
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
void SetUnloadType(OrderUnloadFlags unload_type)
Set how the consist must be unloaded.
void SetLoadType(OrderLoadFlags load_type)
Set how the consist must be loaded.
void ConvertFromOldSavegame()
Converts this order from an old savegame's version; it moves all bits to the new location.
bool IsType(OrderType type) const
Check whether this order is of the given type.
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
OrderType GetType() const
Get the type of order of this order.
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
void MakeDummy()
Makes this order a Dummy order.
uint8_t flags
Load/unload types, depot order/action types.
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Templated helper to make a PoolID a single POD value.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.