Use upstream save/load for various unchanged chunks
This commit is contained in:
@@ -16,6 +16,18 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Called after load to trash broken pages. */
|
||||
void AfterLoadStoryBook()
|
||||
{
|
||||
if (upstream_sl::IsSavegameVersionBefore(SLV_185)) {
|
||||
/* Trash all story pages and page elements because
|
||||
* they were saved with wrong data types.
|
||||
*/
|
||||
_story_page_element_pool.CleanPool();
|
||||
_story_page_pool.CleanPool();
|
||||
}
|
||||
}
|
||||
|
||||
namespace upstream_sl {
|
||||
|
||||
static const SaveLoad _story_page_elements_desc[] = {
|
||||
|
@@ -14,49 +14,8 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const SaveLoad _engine_renew_desc[] = {
|
||||
SLE_VAR(EngineRenew, from, SLE_UINT16),
|
||||
SLE_VAR(EngineRenew, to, SLE_UINT16),
|
||||
|
||||
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
|
||||
SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(EngineRenew, replace_when_old, SLE_BOOL, SLV_175, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static void Save_ERNW()
|
||||
{
|
||||
for (EngineRenew *er : EngineRenew::Iterate()) {
|
||||
SlSetArrayIndex(er->index);
|
||||
SlObject(er, _engine_renew_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_ERNW()
|
||||
{
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
EngineRenew *er = new (index) EngineRenew();
|
||||
SlObject(er, _engine_renew_desc);
|
||||
|
||||
/* Advanced vehicle lists, ungrouped vehicles got added */
|
||||
if (IsSavegameVersionBefore(SLV_60)) {
|
||||
er->group_id = ALL_GROUP;
|
||||
} else if (IsSavegameVersionBefore(SLV_71)) {
|
||||
if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Ptrs_ERNW()
|
||||
{
|
||||
for (EngineRenew *er : EngineRenew::Iterate()) {
|
||||
SlObject(er, _engine_renew_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler autoreplace_chunk_handlers[] = {
|
||||
{ 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'ERNW', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _autoreplace_chunk_handlers(autoreplace_chunk_handlers);
|
||||
|
@@ -14,112 +14,10 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Temporary storage of cargo monitoring data for loading or saving it. */
|
||||
struct TempStorage {
|
||||
CargoMonitorID number;
|
||||
uint32_t amount;
|
||||
};
|
||||
|
||||
/** Description of the #TempStorage structure for the purpose of load and save. */
|
||||
static const SaveLoad _cargomonitor_pair_desc[] = {
|
||||
SLE_VAR(TempStorage, number, SLE_UINT32),
|
||||
SLE_VAR(TempStorage, amount, SLE_UINT32),
|
||||
};
|
||||
|
||||
static CargoMonitorID FixupCargoMonitor(CargoMonitorID number)
|
||||
{
|
||||
/* Between SLV_EXTEND_CARGOTYPES and SLV_FIX_CARGO_MONITOR, the
|
||||
* CargoMonitorID structure had insufficient packing for more
|
||||
* than 32 cargo types. Here we have to shuffle bits to account
|
||||
* for the change.
|
||||
* Company moved from bits 24-31 to 25-28.
|
||||
* Cargo type increased from bits 19-23 to 19-24.
|
||||
*/
|
||||
SB(number, 25, 4, GB(number, 24, 4));
|
||||
SB(number, 29, 3, 0);
|
||||
ClrBit(number, 24);
|
||||
return number;
|
||||
}
|
||||
|
||||
/** Save the #_cargo_deliveries monitoring map. */
|
||||
static void SaveDelivery()
|
||||
{
|
||||
TempStorage storage;
|
||||
|
||||
int i = 0;
|
||||
CargoMonitorMap::const_iterator iter = _cargo_deliveries.begin();
|
||||
while (iter != _cargo_deliveries.end()) {
|
||||
storage.number = iter->first;
|
||||
storage.amount = iter->second;
|
||||
|
||||
SlSetArrayIndex(i);
|
||||
SlObject(&storage, _cargomonitor_pair_desc);
|
||||
|
||||
i++;
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
/** Load the #_cargo_deliveries monitoring map. */
|
||||
static void LoadDelivery()
|
||||
{
|
||||
TempStorage storage;
|
||||
bool fix = IsSavegameVersionBefore(SLV_FIX_CARGO_MONITOR);
|
||||
|
||||
ClearCargoDeliveryMonitoring();
|
||||
for (;;) {
|
||||
if (SlIterateArray() < 0) break;
|
||||
SlObject(&storage, _cargomonitor_pair_desc);
|
||||
|
||||
if (fix) storage.number = FixupCargoMonitor(storage.number);
|
||||
|
||||
std::pair<CargoMonitorID, uint32_t> p(storage.number, storage.amount);
|
||||
_cargo_deliveries.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Save the #_cargo_pickups monitoring map. */
|
||||
static void SavePickup()
|
||||
{
|
||||
TempStorage storage;
|
||||
|
||||
int i = 0;
|
||||
CargoMonitorMap::const_iterator iter = _cargo_pickups.begin();
|
||||
while (iter != _cargo_pickups.end()) {
|
||||
storage.number = iter->first;
|
||||
storage.amount = iter->second;
|
||||
|
||||
SlSetArrayIndex(i);
|
||||
SlObject(&storage, _cargomonitor_pair_desc);
|
||||
|
||||
i++;
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
/** Load the #_cargo_pickups monitoring map. */
|
||||
static void LoadPickup()
|
||||
{
|
||||
TempStorage storage;
|
||||
bool fix = IsSavegameVersionBefore(SLV_FIX_CARGO_MONITOR);
|
||||
|
||||
ClearCargoPickupMonitoring();
|
||||
for (;;) {
|
||||
if (SlIterateArray() < 0) break;
|
||||
SlObject(&storage, _cargomonitor_pair_desc);
|
||||
|
||||
if (fix) storage.number = FixupCargoMonitor(storage.number);
|
||||
|
||||
std::pair<CargoMonitorID, uint32_t> p(storage.number, storage.amount);
|
||||
_cargo_pickups.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
/** Chunk definition of the cargomonitoring maps. */
|
||||
static const ChunkHandler cargomonitor_chunk_handlers[] = {
|
||||
{ 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'CMPU', SavePickup, LoadPickup, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'CMDL', GeneralUpstreamChunkLoadInfo>(),
|
||||
MakeUpstreamChunkHandler<'CMPU', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _cargomonitor_chunk_handlers(cargomonitor_chunk_handlers);
|
||||
|
@@ -28,14 +28,6 @@ static const SaveLoad _depot_desc[] = {
|
||||
SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SPRINGPP, 5)),
|
||||
};
|
||||
|
||||
static void Save_DEPT()
|
||||
{
|
||||
for (Depot *depot : Depot::Iterate()) {
|
||||
SlSetArrayIndex(depot->index);
|
||||
SlObject(depot, _depot_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_DEPT()
|
||||
{
|
||||
int index;
|
||||
@@ -58,7 +50,7 @@ static void Ptrs_DEPT()
|
||||
}
|
||||
|
||||
static const ChunkHandler depot_chunk_handlers[] = {
|
||||
{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY },
|
||||
MakeSaveUpstreamFeatureConditionalLoadUpstreamChunkHandler<'DEPT', XSLFI_TABLE_MISC_SL, 2>(Load_DEPT, Ptrs_DEPT, nullptr),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _depot_chunk_handlers(depot_chunk_handlers);
|
||||
|
@@ -49,12 +49,6 @@ static const SaveLoad _economy_desc[] = {
|
||||
SLE_CONDNULL_X(8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_JOKERPP)),
|
||||
};
|
||||
|
||||
/** Economy variables */
|
||||
static void Save_ECMY()
|
||||
{
|
||||
SlObject(&_economy, _economy_desc);
|
||||
}
|
||||
|
||||
/** Economy variables */
|
||||
static void Load_ECMY()
|
||||
{
|
||||
@@ -69,14 +63,6 @@ static const SaveLoad _cargopayment_desc[] = {
|
||||
SLE_CONDVAR_X(CargoPayment, visual_transfer, SLE_INT64, SLV_181, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_OR, XSLFI_CHILLPP)),
|
||||
};
|
||||
|
||||
static void Save_CAPY()
|
||||
{
|
||||
for (CargoPayment *cp : CargoPayment::Iterate()) {
|
||||
SlSetArrayIndex(cp->index);
|
||||
SlObject(cp, _cargopayment_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_CAPY()
|
||||
{
|
||||
int index;
|
||||
@@ -96,10 +82,10 @@ static void Ptrs_CAPY()
|
||||
|
||||
|
||||
static const ChunkHandler economy_chunk_handlers[] = {
|
||||
{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_ARRAY },
|
||||
MakeSaveUpstreamFeatureConditionalLoadUpstreamChunkHandler<'CAPY', XSLFI_TABLE_MISC_SL, 2>(Load_CAPY, Ptrs_CAPY, nullptr),
|
||||
{ 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_RIFF },
|
||||
{ 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_RIFF },
|
||||
{ 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_RIFF },
|
||||
MakeSaveUpstreamFeatureConditionalLoadUpstreamChunkHandler<'ECMY', XSLFI_TABLE_MISC_SL, 2>(Load_ECMY, nullptr, nullptr),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers);
|
||||
|
@@ -83,34 +83,6 @@ Engine *GetTempDataEngine(EngineID index)
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_ENGN()
|
||||
{
|
||||
for (Engine *e : Engine::Iterate()) {
|
||||
SlSetArrayIndex(e->index);
|
||||
SlObject(e, _engine_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_ENGN()
|
||||
{
|
||||
/* As engine data is loaded before engines are initialized we need to load
|
||||
* this information into a temporary array. This is then copied into the
|
||||
* engine pool after processing NewGRFs by CopyTempEngineData(). */
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Engine *e = GetTempDataEngine(index);
|
||||
SlObject(e, _engine_desc);
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_179)) {
|
||||
/* preview_company_rank was replaced with preview_company and preview_asked.
|
||||
* Just cancel any previews. */
|
||||
e->flags &= ~4; // ENGINE_OFFER_WINDOW_OPEN
|
||||
e->preview_company = INVALID_COMPANY;
|
||||
e->preview_asked = MAX_UVALUE(CompanyMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy data from temporary engine array into the real engine pool.
|
||||
*/
|
||||
@@ -166,42 +138,14 @@ static void Load_ENGS()
|
||||
}
|
||||
}
|
||||
|
||||
/** Save and load the mapping between the engine id in the pool, and the grf file it came from. */
|
||||
static const SaveLoad _engine_id_mapping_desc[] = {
|
||||
SLE_VAR(EngineIDMapping, grfid, SLE_UINT32),
|
||||
SLE_VAR(EngineIDMapping, internal_id, SLE_UINT16),
|
||||
SLE_VAR(EngineIDMapping, type, SLE_UINT8),
|
||||
SLE_VAR(EngineIDMapping, substitute_id, SLE_UINT8),
|
||||
};
|
||||
|
||||
static void Save_EIDS()
|
||||
{
|
||||
uint index = 0;
|
||||
for (EngineIDMapping &eid : _engine_mngr) {
|
||||
SlSetArrayIndex(index);
|
||||
SlObject(&eid, _engine_id_mapping_desc);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_EIDS()
|
||||
{
|
||||
_engine_mngr.clear();
|
||||
|
||||
while (SlIterateArray() != -1) {
|
||||
EngineIDMapping *eid = &_engine_mngr.emplace_back();
|
||||
SlObject(eid, _engine_id_mapping_desc);
|
||||
}
|
||||
}
|
||||
|
||||
void AfterLoadEngines()
|
||||
{
|
||||
AnalyseEngineCallbacks();
|
||||
}
|
||||
|
||||
static const ChunkHandler engine_chunk_handlers[] = {
|
||||
{ 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'EIDS', GeneralUpstreamChunkLoadInfo>(),
|
||||
MakeUpstreamChunkHandler<'ENGN', GeneralUpstreamChunkLoadInfo>(),
|
||||
{ 'ENGS', nullptr, Load_ENGS, nullptr, nullptr, CH_RIFF },
|
||||
};
|
||||
|
||||
|
@@ -212,7 +212,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
||||
{ XSLFI_DEPOT_UNBUNCHING, XSCF_NULL, 1, 1, "slv_depot_unbunching", nullptr, nullptr, "VUBS" },
|
||||
|
||||
{ XSLFI_TABLE_PATS, XSCF_NULL, 1, 1, "table_pats", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_TABLE_MISC_SL, XSCF_NULL, 1, 1, "table_misc_sl", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_TABLE_MISC_SL, XSCF_NULL, 2, 2, "table_misc_sl", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_TABLE_SCRIPT_SL, XSCF_NULL, 1, 1, "table_script_sl", nullptr, nullptr, nullptr },
|
||||
|
||||
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr }, // This is the end marker
|
||||
|
@@ -161,7 +161,9 @@ enum SlXvFeatureIndex {
|
||||
XSLFI_DEPOT_UNBUNCHING, ///< See: SLV_DEPOT_UNBUNCHING (PR #11945)
|
||||
|
||||
XSLFI_TABLE_PATS, ///< Use upstream table format for PATS
|
||||
XSLFI_TABLE_MISC_SL, ///< Use upstream table format for miscellaneous chunks, so far: DATE, VIEW, MAPS
|
||||
XSLFI_TABLE_MISC_SL, ///< Use upstream table format for miscellaneous chunks:
|
||||
///< v1: DATE, VIEW, MAPS
|
||||
///< v2: SUBS, CMDL, CMPU, ERNW, DEPT, CAPY, ECMY, EIDS, ENGN, GOAL, GRPS, RAIL, OBJS, SIGN, PSAC, STPE, STPA
|
||||
XSLFI_TABLE_SCRIPT_SL, ///< Use upstream table format for script chunks
|
||||
|
||||
XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit
|
||||
|
@@ -14,34 +14,8 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const SaveLoad _goals_desc[] = {
|
||||
SLE_VAR(Goal, company, SLE_FILE_U16 | SLE_VAR_U8),
|
||||
SLE_VAR(Goal, type, SLE_FILE_U16 | SLE_VAR_U8),
|
||||
SLE_VAR(Goal, dst, SLE_UINT32),
|
||||
SLE_SSTR(Goal, text, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
SLE_CONDSSTR(Goal, progress, SLE_STR | SLF_ALLOW_CONTROL, SLV_182, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Goal, completed, SLE_BOOL, SLV_182, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static void Save_GOAL()
|
||||
{
|
||||
for (Goal *s : Goal::Iterate()) {
|
||||
SlSetArrayIndex(s->index);
|
||||
SlObject(s, _goals_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_GOAL()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Goal *s = new (index) Goal();
|
||||
SlObject(s, _goals_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler goal_chunk_handlers[] = {
|
||||
{ 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'GOAL', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _goal_chunk_handlers(goal_chunk_handlers);
|
||||
|
@@ -15,48 +15,8 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const SaveLoad _group_desc[] = {
|
||||
SLE_CONDVAR(Group, name, SLE_NAME, SL_MIN_VERSION, SLV_84),
|
||||
SLE_CONDSSTR(Group, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_164), // num_vehicle
|
||||
SLE_VAR(Group, owner, SLE_UINT8),
|
||||
SLE_VAR(Group, vehicle_type, SLE_UINT8),
|
||||
SLE_VAR(Group, flags, SLE_UINT8),
|
||||
SLE_CONDVAR(Group, livery.in_use, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Group, livery.colour1, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Group, livery.colour2, SLE_UINT8, SLV_GROUP_LIVERIES, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Group, parent, SLE_UINT16, SLV_189, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static void Save_GRPS()
|
||||
{
|
||||
for (Group *g : Group::Iterate()) {
|
||||
SlSetArrayIndex(g->index);
|
||||
SlObject(g, _group_desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void Load_GRPS()
|
||||
{
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Group *g = new (index) Group();
|
||||
SlObject(g, _group_desc);
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_189)) g->parent = INVALID_GROUP;
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_GROUP_LIVERIES)) {
|
||||
const Company *c = Company::Get(g->owner);
|
||||
g->livery.colour1 = c->livery[LS_DEFAULT].colour1;
|
||||
g->livery.colour2 = c->livery[LS_DEFAULT].colour2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler group_chunk_handlers[] = {
|
||||
{ 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'GRPS', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _group_chunk_handlers(group_chunk_handlers);
|
||||
|
@@ -97,41 +97,8 @@ void ResetLabelMaps()
|
||||
_railtype_list.clear();
|
||||
}
|
||||
|
||||
/** Container for a label for SaveLoad system */
|
||||
struct LabelObject {
|
||||
uint32_t label;
|
||||
};
|
||||
|
||||
static const SaveLoad _label_object_desc[] = {
|
||||
SLE_VAR(LabelObject, label, SLE_UINT32),
|
||||
};
|
||||
|
||||
static void Save_RAIL()
|
||||
{
|
||||
LabelObject lo;
|
||||
|
||||
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
|
||||
lo.label = GetRailTypeInfo(r)->label;
|
||||
|
||||
SlSetArrayIndex(r);
|
||||
SlObject(&lo, _label_object_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_RAIL()
|
||||
{
|
||||
ResetLabelMaps();
|
||||
|
||||
LabelObject lo;
|
||||
|
||||
while (SlIterateArray() != -1) {
|
||||
SlObject(&lo, _label_object_desc);
|
||||
_railtype_list.push_back((RailTypeLabel)lo.label);
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler labelmaps_chunk_handlers[] = {
|
||||
{ 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'RAIL', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _labelmaps_chunk_handlers(labelmaps_chunk_handlers);
|
||||
|
@@ -16,46 +16,6 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const SaveLoad _object_desc[] = {
|
||||
SLE_VAR(Object, location.tile, SLE_UINT32),
|
||||
SLE_VAR(Object, location.w, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_VAR(Object, location.h, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_REF(Object, town, REF_TOWN),
|
||||
SLE_VAR(Object, build_date, SLE_UINT32),
|
||||
SLE_CONDVAR(Object, colour, SLE_UINT8, SLV_148, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Object, view, SLE_UINT8, SLV_155, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Object, type, SLE_UINT16, SLV_186, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static void Save_OBJS()
|
||||
{
|
||||
/* Write the objects */
|
||||
for (Object *o : Object::Iterate()) {
|
||||
SlSetArrayIndex(o->index);
|
||||
SlObject(o, _object_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_OBJS()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Object *o = new (index) Object();
|
||||
SlObject(o, _object_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Ptrs_OBJS()
|
||||
{
|
||||
for (Object *o : Object::Iterate()) {
|
||||
SlObject(o, _object_desc);
|
||||
if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) {
|
||||
/* Due to a small bug stale objects could remain. */
|
||||
delete o;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_OBID()
|
||||
{
|
||||
Save_NewGRFMapping(_object_mngr);
|
||||
@@ -68,7 +28,7 @@ static void Load_OBID()
|
||||
|
||||
static const ChunkHandler object_chunk_handlers[] = {
|
||||
{ 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'OBJS', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _object_chunk_handlers(object_chunk_handlers);
|
||||
|
@@ -4229,6 +4229,14 @@ void SlExecWithSlVersionEnd(SaveLoadVersion old_version)
|
||||
_sl_version = old_version;
|
||||
}
|
||||
|
||||
SaveLoadVersion GeneralUpstreamChunkLoadInfo::GetLoadVersion()
|
||||
{
|
||||
extern SaveLoadVersion _sl_xv_upstream_version;
|
||||
|
||||
byte block_mode = _sl.chunk_block_modes[_sl.current_chunk_id];
|
||||
return (block_mode == CH_TABLE || block_mode == CH_SPARSE_TABLE) ? _sl_xv_upstream_version : _sl_version;
|
||||
}
|
||||
|
||||
const char *ChunkIDDumper::operator()(uint32_t id)
|
||||
{
|
||||
seprintf(this->buffer, lastof(this->buffer), "%c%c%c%c", id >> 24, id >> 16, id >> 8, id);
|
||||
|
@@ -265,6 +265,11 @@ namespace upstream_sl {
|
||||
}
|
||||
}
|
||||
|
||||
struct GeneralUpstreamChunkLoadInfo
|
||||
{
|
||||
static SaveLoadVersion GetLoadVersion();
|
||||
};
|
||||
|
||||
using upstream_sl::MakeUpstreamChunkHandler;
|
||||
using upstream_sl::MakeConditionallyUpstreamChunkHandler;
|
||||
using upstream_sl::MakeSaveUpstreamFeatureConditionalLoadUpstreamChunkHandler;
|
||||
|
@@ -28,15 +28,6 @@ static const SaveLoad _sign_desc[] = {
|
||||
SLE_CONDVAR_X(Sign, z, SLE_INT32, SLV_164, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_OR, XSLFI_ZPOS_32_BIT)),
|
||||
};
|
||||
|
||||
/** Save all signs */
|
||||
static void Save_SIGN()
|
||||
{
|
||||
for (Sign *si : Sign::Iterate()) {
|
||||
SlSetArrayIndex(si->index);
|
||||
SlObject(si, _sign_desc);
|
||||
}
|
||||
}
|
||||
|
||||
/** Load all signs */
|
||||
static void Load_SIGN()
|
||||
{
|
||||
@@ -63,7 +54,7 @@ static void Load_SIGN()
|
||||
|
||||
/** Chunk handlers related to signs. */
|
||||
static const ChunkHandler sign_chunk_handlers[] = {
|
||||
{ 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY },
|
||||
MakeSaveUpstreamFeatureConditionalLoadUpstreamChunkHandler<'SIGN', XSLFI_TABLE_MISC_SL, 2>(Load_SIGN, nullptr, nullptr),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _sign_chunk_handlers(sign_chunk_handlers);
|
||||
|
@@ -13,39 +13,9 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Description of the data to save and load in #PersistentStorage. */
|
||||
static const SaveLoad _storage_desc[] = {
|
||||
SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, SLV_6, SL_MAX_VERSION),
|
||||
SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, SLV_161, SLV_EXTEND_PERSISTENT_STORAGE),
|
||||
SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 256, SLV_EXTEND_PERSISTENT_STORAGE, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
/** Load persistent storage data. */
|
||||
static void Load_PSAC()
|
||||
{
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
assert(PersistentStorage::CanAllocateItem());
|
||||
PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
|
||||
SlObject(ps, _storage_desc);
|
||||
}
|
||||
}
|
||||
|
||||
/** Save persistent storage data. */
|
||||
static void Save_PSAC()
|
||||
{
|
||||
/* Write the industries */
|
||||
for (PersistentStorage *ps : PersistentStorage::Iterate()) {
|
||||
ps->ClearChanges();
|
||||
SlSetArrayIndex(ps->index);
|
||||
SlObject(ps, _storage_desc);
|
||||
}
|
||||
}
|
||||
|
||||
/** Chunk handler for persistent storages. */
|
||||
static const ChunkHandler persistent_storage_chunk_handlers[] = {
|
||||
{ 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'PSAC', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _persistent_storage_chunk_handlers(persistent_storage_chunk_handlers);
|
||||
|
@@ -14,90 +14,9 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Called after load to trash broken pages. */
|
||||
void AfterLoadStoryBook()
|
||||
{
|
||||
if (IsSavegameVersionBefore(SLV_185)) {
|
||||
/* Trash all story pages and page elements because
|
||||
* they were saved with wrong data types.
|
||||
*/
|
||||
_story_page_element_pool.CleanPool();
|
||||
_story_page_pool.CleanPool();
|
||||
}
|
||||
}
|
||||
|
||||
static const SaveLoad _story_page_elements_desc[] = {
|
||||
SLE_CONDVAR(StoryPageElement, sort_value, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_185),
|
||||
SLE_CONDVAR(StoryPageElement, sort_value, SLE_UINT32, SLV_185, SL_MAX_VERSION),
|
||||
SLE_VAR(StoryPageElement, page, SLE_UINT16),
|
||||
SLE_CONDVAR(StoryPageElement, type, SLE_FILE_U16 | SLE_VAR_U8, SL_MIN_VERSION, SLV_185),
|
||||
SLE_CONDVAR(StoryPageElement, type, SLE_UINT8, SLV_185, SL_MAX_VERSION),
|
||||
SLE_VAR(StoryPageElement, referenced_id, SLE_UINT32),
|
||||
SLE_SSTR(StoryPageElement, text, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
};
|
||||
|
||||
static void Save_STORY_PAGE_ELEMENT()
|
||||
{
|
||||
for (StoryPageElement *s : StoryPageElement::Iterate()) {
|
||||
SlSetArrayIndex(s->index);
|
||||
SlObject(s, _story_page_elements_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_STORY_PAGE_ELEMENT()
|
||||
{
|
||||
int index;
|
||||
uint32_t max_sort_value = 0;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
StoryPageElement *s = new (index) StoryPageElement();
|
||||
SlObject(s, _story_page_elements_desc);
|
||||
if (s->sort_value > max_sort_value) {
|
||||
max_sort_value = s->sort_value;
|
||||
}
|
||||
}
|
||||
/* Update the next sort value, so that the next
|
||||
* created page is shown after all existing pages.
|
||||
*/
|
||||
_story_page_element_next_sort_value = max_sort_value + 1;
|
||||
}
|
||||
|
||||
static const SaveLoad _story_pages_desc[] = {
|
||||
SLE_CONDVAR(StoryPage, sort_value, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_185),
|
||||
SLE_CONDVAR(StoryPage, sort_value, SLE_UINT32, SLV_185, SL_MAX_VERSION),
|
||||
SLE_VAR(StoryPage, date, SLE_UINT32),
|
||||
SLE_CONDVAR(StoryPage, company, SLE_FILE_U16 | SLE_VAR_U8, SL_MIN_VERSION, SLV_185),
|
||||
SLE_CONDVAR(StoryPage, company, SLE_UINT8, SLV_185, SL_MAX_VERSION),
|
||||
SLE_SSTR(StoryPage, title, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
};
|
||||
|
||||
static void Save_STORY_PAGE()
|
||||
{
|
||||
for (StoryPage *s : StoryPage::Iterate()) {
|
||||
SlSetArrayIndex(s->index);
|
||||
SlObject(s, _story_pages_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_STORY_PAGE()
|
||||
{
|
||||
int index;
|
||||
uint32_t max_sort_value = 0;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
StoryPage *s = new (index) StoryPage();
|
||||
SlObject(s, _story_pages_desc);
|
||||
if (s->sort_value > max_sort_value) {
|
||||
max_sort_value = s->sort_value;
|
||||
}
|
||||
}
|
||||
/* Update the next sort value, so that the next
|
||||
* created page is shown after all existing pages.
|
||||
*/
|
||||
_story_page_next_sort_value = max_sort_value + 1;
|
||||
}
|
||||
|
||||
static const ChunkHandler story_page_chunk_handlers[] = {
|
||||
{ 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'STPE', GeneralUpstreamChunkLoadInfo>(),
|
||||
MakeUpstreamChunkHandler<'STPA', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _story_page_chunk_handlers(story_page_chunk_handlers);
|
||||
|
@@ -14,38 +14,8 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const SaveLoad _subsidies_desc[] = {
|
||||
SLE_VAR(Subsidy, cargo_type, SLE_UINT8),
|
||||
SLE_CONDVAR(Subsidy, remaining, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_CUSTOM_SUBSIDY_DURATION),
|
||||
SLE_CONDVAR(Subsidy, remaining, SLE_UINT16, SLV_CUSTOM_SUBSIDY_DURATION, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, SLV_125, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
|
||||
SLE_CONDVAR(Subsidy, src, SLE_UINT16, SLV_5, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5),
|
||||
SLE_CONDVAR(Subsidy, dst, SLE_UINT16, SLV_5, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static void Save_SUBS()
|
||||
{
|
||||
for (Subsidy *s : Subsidy::Iterate()) {
|
||||
SlSetArrayIndex(s->index);
|
||||
SlObject(s, _subsidies_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_SUBS()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Subsidy *s = new (index) Subsidy();
|
||||
SlObject(s, _subsidies_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler subsidy_chunk_handlers[] = {
|
||||
{ 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY },
|
||||
MakeUpstreamChunkHandler<'SUBS', GeneralUpstreamChunkLoadInfo>(),
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _subsidy_chunk_handlers(subsidy_chunk_handlers);
|
||||
|
Reference in New Issue
Block a user