diff options
Diffstat (limited to 'src/saveload')
-rw-r--r-- | src/saveload/company_sl.cpp | 127 | ||||
-rw-r--r-- | src/saveload/compat/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/saveload/compat/company_sl_compat.h | 129 | ||||
-rw-r--r-- | src/saveload/compat/game_sl_compat.h | 12 | ||||
-rw-r--r-- | src/saveload/compat/gamelog_sl_compat.h | 105 | ||||
-rw-r--r-- | src/saveload/compat/linkgraph_sl_compat.h | 66 | ||||
-rw-r--r-- | src/saveload/compat/station_sl_compat.h | 152 | ||||
-rw-r--r-- | src/saveload/compat/town_sl_compat.h | 87 | ||||
-rw-r--r-- | src/saveload/compat/vehicle_sl_compat.h | 207 | ||||
-rw-r--r-- | src/saveload/game_sl.cpp | 11 | ||||
-rw-r--r-- | src/saveload/gamelog_sl.cpp | 165 | ||||
-rw-r--r-- | src/saveload/linkgraph_sl.cpp | 43 | ||||
-rw-r--r-- | src/saveload/saveload.h | 3 | ||||
-rw-r--r-- | src/saveload/station_sl.cpp | 88 | ||||
-rw-r--r-- | src/saveload/town_sl.cpp | 59 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 163 |
16 files changed, 1149 insertions, 271 deletions
diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 7abec8041..27fb2cf37 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -8,6 +8,10 @@ /** @file company_sl.cpp Code handling saving and loading of company data */ #include "../stdafx.h" + +#include "saveload.h" +#include "compat/company_sl_compat.h" + #include "../company_func.h" #include "../company_manager_face.h" #include "../fios.h" @@ -16,8 +20,6 @@ #include "../station_base.h" #include "../strings_func.h" -#include "saveload.h" - #include "table/strings.h" #include "../safeguards.h" @@ -243,79 +245,44 @@ struct CompanyOldAI { class SlCompanyOldAIBuildRec : public DefaultSaveLoadHandler<SlCompanyOldAIBuildRec, CompanyOldAI> { public: - inline static const SaveLoad description[] = { - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_107), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_107), - SLE_CONDNULL(8, SL_MIN_VERSION, SLV_107), - }; + inline static const SaveLoad description[] = {{}}; // Needed to keep DefaultSaveLoadHandler happy. + inline const static SaveLoadCompatTable compat_description = _company_old_ai_buildrec_compat; + + SaveLoadTable GetDescription() const override { return {}; } - void GenericSaveLoad(CompanyOldAI *old_ai) const + void Load(CompanyOldAI *old_ai) const override { for (int i = 0; i != old_ai->num_build_rec; i++) { - SlObject(nullptr, this->GetDescription()); + SlObject(nullptr, this->GetLoadDescription()); } } - // No Save(); this is for backwards compatibility. - void Load(CompanyOldAI *old_ai) const override { this->GenericSaveLoad(old_ai); } - void LoadCheck(CompanyOldAI *old_ai) const override { this->GenericSaveLoad(old_ai); } - void FixPointers(CompanyOldAI *old_ai) const override { this->GenericSaveLoad(old_ai); } + void LoadCheck(CompanyOldAI *old_ai) const override { this->Load(old_ai); } }; class SlCompanyOldAI : public DefaultSaveLoadHandler<SlCompanyOldAI, CompanyProperties> { public: inline static const SaveLoad description[] = { - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_107), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_13), - SLE_CONDNULL(4, SLV_13, SLV_107), - SLE_CONDNULL(8, SL_MIN_VERSION, SLV_107), - SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107), - SLE_CONDNULL(3, SL_MIN_VERSION, SLV_107), - - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_107), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_107), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_107), - - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_107), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_107), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_107), - - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_69), - SLE_CONDNULL(4, SLV_69, SLV_107), - - SLE_CONDNULL(18, SL_MIN_VERSION, SLV_107), - SLE_CONDNULL(20, SL_MIN_VERSION, SLV_107), - SLE_CONDNULL(32, SL_MIN_VERSION, SLV_107), - - SLE_CONDNULL(64, SLV_2, SLV_107), - SLEG_STRUCTLIST("build_rec", SlCompanyOldAIBuildRec), + SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107), + SLEG_STRUCTLIST("buildrec", SlCompanyOldAIBuildRec), }; + inline const static SaveLoadCompatTable compat_description = _company_old_ai_compat; - void GenericSaveLoad(CompanyProperties *c) const + void Load(CompanyProperties *c) const override { if (!c->is_ai) return; CompanyOldAI old_ai; - SlObject(&old_ai, this->GetDescription()); + SlObject(&old_ai, this->GetLoadDescription()); } - // No Save(); this is for backwards compatibility. - void Load(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void LoadCheck(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void FixPointers(CompanyProperties *c) const override { this->GenericSaveLoad(c); } + void LoadCheck(CompanyProperties *c) const override { this->Load(c); } }; class SlCompanySettings : public DefaultSaveLoadHandler<SlCompanySettings, CompanyProperties> { public: inline static const SaveLoad description[] = { /* Engine renewal settings */ - SLE_CONDNULL(512, SLV_16, SLV_19), SLE_CONDREF(CompanyProperties, engine_renew_list, REF_ENGINE_RENEWS, SLV_19, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, settings.engine_renew, SLE_BOOL, SLV_16, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, settings.engine_renew_months, SLE_INT16, SLV_16, SL_MAX_VERSION), @@ -328,19 +295,25 @@ public: SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_roadveh, SLE_UINT16, SLV_120, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_aircraft, SLE_UINT16, SLV_120, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ships, SLE_UINT16, SLV_120, SL_MAX_VERSION), - - SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space }; + inline const static SaveLoadCompatTable compat_description = _company_settings_compat; - void GenericSaveLoad(CompanyProperties *c) const + void Save(CompanyProperties *c) const override { SlObject(c, this->GetDescription()); } - void Save(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void Load(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void LoadCheck(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void FixPointers(CompanyProperties *c) const override { this->GenericSaveLoad(c); } + void Load(CompanyProperties *c) const override + { + SlObject(c, this->GetLoadDescription()); + } + + void FixPointers(CompanyProperties *c) const override + { + SlObject(c, this->GetDescription()); + } + + void LoadCheck(CompanyProperties *c) const override { this->Load(c); } }; class SlCompanyEconomy : public DefaultSaveLoadHandler<SlCompanyEconomy, CompanyProperties> { @@ -358,16 +331,24 @@ public: SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32), }; + inline const static SaveLoadCompatTable compat_description = _company_economy_compat; + + void Save(CompanyProperties *c) const override + { + SlObject(&c->cur_economy, this->GetDescription()); + } + + void Load(CompanyProperties *c) const override + { + SlObject(&c->cur_economy, this->GetLoadDescription()); + } - void GenericSaveLoad(CompanyProperties *c) const + void FixPointers(CompanyProperties *c) const override { SlObject(&c->cur_economy, this->GetDescription()); } - void Save(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void Load(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void LoadCheck(CompanyProperties *c) const override { this->GenericSaveLoad(c); } - void FixPointers(CompanyProperties *c) const override { this->GenericSaveLoad(c); } + void LoadCheck(CompanyProperties *c) const override { this->Load(c); } }; class SlCompanyOldEconomy : public SlCompanyEconomy { @@ -388,7 +369,7 @@ public: if (c->num_valid_stat_ent > lengthof(c->old_economy)) SlErrorCorrupt("Too many old economy entries"); for (int i = 0; i < c->num_valid_stat_ent; i++) { - SlObject(&c->old_economy[i], this->GetDescription()); + SlObject(&c->old_economy[i], this->GetLoadDescription()); } } @@ -402,6 +383,7 @@ public: SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION), SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _company_liveries_compat; /** * Get the number of liveries used by this savegame version. @@ -430,7 +412,7 @@ public: bool update_in_use = IsSavegameVersionBefore(SLV_GROUP_LIVERIES); for (size_t i = 0; i < num_liveries; i++) { - SlObject(&c->livery[i], this->GetDescription()); + SlObject(&c->livery[i], this->GetLoadDescription()); if (update_in_use && i != LS_DEFAULT) { if (c->livery[i].in_use == 0) { c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1; @@ -479,11 +461,8 @@ static const SaveLoad _company_desc[] = { SLE_VAR(CompanyProperties, colour, SLE_UINT8), SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8), - SLE_CONDNULL(1, SL_MIN_VERSION, SLV_58), ///< avail_railtypes SLE_VAR(CompanyProperties, block_preview, SLE_UINT8), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_94), ///< cargo_types - SLE_CONDNULL(4, SLV_94, SLV_170), ///< cargo_types SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, SLV_6, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), @@ -507,8 +486,6 @@ static const SaveLoad _company_desc[] = { SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, SLV_2, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, is_ai, SLE_BOOL, SLV_2, SL_MAX_VERSION), - SLE_CONDNULL(1, SLV_107, SLV_112), ///< is_noai - SLE_CONDNULL(1, SLV_4, SLV_100), SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION), SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION), @@ -522,6 +499,8 @@ static const SaveLoad _company_desc[] = { static void Save_PLYR() { + SlTableHeader(_company_desc); + for (Company *c : Company::Iterate()) { SlSetArrayIndex(c->index); SlObject(c, _company_desc); @@ -530,20 +509,24 @@ static void Save_PLYR() static void Load_PLYR() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat); + int index; while ((index = SlIterateArray()) != -1) { Company *c = new (index) Company(); - SlObject(c, _company_desc); + SlObject(c, slt); _company_colours[index] = (Colours)c->colour; } } static void Check_PLYR() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat); + int index; while ((index = SlIterateArray()) != -1) { CompanyProperties *cprops = new CompanyProperties(); - SlObject(cprops, _company_desc); + SlObject(cprops, slt); /* We do not load old custom names */ if (IsSavegameVersionBefore(SLV_84)) { @@ -576,7 +559,7 @@ static void Ptrs_PLYR() static const ChunkHandler company_chunk_handlers[] = { - { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY }, + { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_TABLE }, }; extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers); diff --git a/src/saveload/compat/CMakeLists.txt b/src/saveload/compat/CMakeLists.txt index 1737f9493..dc7c57e5c 100644 --- a/src/saveload/compat/CMakeLists.txt +++ b/src/saveload/compat/CMakeLists.txt @@ -4,6 +4,7 @@ add_files( cargomonitor_sl_compat.h cargopacket_sl_compat.h cheat_sl_compat.h + company_sl_compat.h depot_sl_compat.h economy_sl_compat.h engine_sl_compat.h @@ -23,4 +24,6 @@ add_files( storage_sl_compat.h story_sl_compat.h subsidy_sl_compat.h + town_sl_compat.h + vehicle_sl_compat.h ) diff --git a/src/saveload/compat/company_sl_compat.h b/src/saveload/compat/company_sl_compat.h new file mode 100644 index 000000000..9da01d3a4 --- /dev/null +++ b/src/saveload/compat/company_sl_compat.h @@ -0,0 +1,129 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file company_sl_compat.h Loading of company chunks before table headers were added. */ + +#ifndef SAVELOAD_COMPAT_COMPANY_H +#define SAVELOAD_COMPAT_COMPANY_H + +#include "../saveload.h" + +/** Original field order for SlCompanyOldAIBuildRec. */ +const SaveLoadCompat _company_old_ai_buildrec_compat[] = { + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_107), + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_107), + SLC_NULL(8, SL_MIN_VERSION, SLV_107), +}; + +/** Original field order for SlCompanyOldAI. */ +const SaveLoadCompat _company_old_ai_compat[] = { + SLC_NULL(2, SL_MIN_VERSION, SLV_107), + SLC_NULL(2, SL_MIN_VERSION, SLV_13), + SLC_NULL(4, SLV_13, SLV_107), + SLC_NULL(8, SL_MIN_VERSION, SLV_107), + SLC_VAR("num_build_rec"), + SLC_NULL(3, SL_MIN_VERSION, SLV_107), + + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_107), + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_107), + SLC_NULL(2, SL_MIN_VERSION, SLV_107), + + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_107), + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_107), + SLC_NULL(2, SL_MIN_VERSION, SLV_107), + + SLC_NULL(2, SL_MIN_VERSION, SLV_69), + SLC_NULL(4, SLV_69, SLV_107), + + SLC_NULL(18, SL_MIN_VERSION, SLV_107), + SLC_NULL(20, SL_MIN_VERSION, SLV_107), + SLC_NULL(32, SL_MIN_VERSION, SLV_107), + + SLC_NULL(64, SLV_2, SLV_107), + SLC_VAR("buildrec"), +}; + +/** Original field order for SlCompanySettings. */ +const SaveLoadCompat _company_settings_compat[] = { + SLC_NULL(512, SLV_16, SLV_19), + SLC_VAR("engine_renew_list"), + SLC_VAR("settings.engine_renew"), + SLC_VAR("settings.engine_renew_months"), + SLC_VAR("settings.engine_renew_money"), + SLC_VAR("settings.renew_keep_length"), + SLC_VAR("settings.vehicle.servint_ispercent"), + SLC_VAR("settings.vehicle.servint_trains"), + SLC_VAR("settings.vehicle.servint_roadveh"), + SLC_VAR("settings.vehicle.servint_aircraft"), + SLC_VAR("settings.vehicle.servint_ships"), + SLC_NULL(63, SLV_2, SLV_144), +}; + +/** Original field order for SlCompanyEconomy. */ +const SaveLoadCompat _company_economy_compat[] = { + SLC_VAR("income"), + SLC_VAR("expenses"), + SLC_VAR("company_value"), + SLC_VAR("delivered_cargo[NUM_CARGO - 1]"), + SLC_VAR("delivered_cargo"), + SLC_VAR("performance_history"), +}; + +/** Original field order for SlCompanyLiveries. */ +const SaveLoadCompat _company_liveries_compat[] = { + SLC_VAR("in_use"), + SLC_VAR("colour1"), + SLC_VAR("colour2"), +}; + +/** Original field order for company_desc. */ +const SaveLoadCompat _company_sl_compat[] = { + SLC_VAR("name_2"), + SLC_VAR("name_1"), + SLC_VAR("name"), + SLC_VAR("president_name_1"), + SLC_VAR("president_name_2"), + SLC_VAR("president_name"), + SLC_VAR("face"), + SLC_VAR("money"), + SLC_VAR("current_loan"), + SLC_VAR("colour"), + SLC_VAR("money_fraction"), + SLC_NULL(1, SL_MIN_VERSION, SLV_58), + SLC_VAR("block_preview"), + SLC_NULL(2, SL_MIN_VERSION, SLV_94), + SLC_NULL(4, SLV_94, SLV_170), + SLC_VAR("location_of_HQ"), + SLC_VAR("last_build_coordinate"), + SLC_VAR("inaugurated_year"), + SLC_VAR("share_owners"), + SLC_VAR("num_valid_stat_ent"), + SLC_VAR("months_of_bankruptcy"), + SLC_VAR("bankrupt_asked"), + SLC_VAR("bankrupt_timeout"), + SLC_VAR("bankrupt_value"), + SLC_VAR("yearly_expenses"), + SLC_VAR("is_ai"), + SLC_NULL(1, SLV_107, SLV_112), + SLC_NULL(1, SLV_4, SLV_100), + SLC_VAR("terraform_limit"), + SLC_VAR("clear_limit"), + SLC_VAR("tree_limit"), + SLC_VAR("settings"), + SLC_VAR("old_ai"), + SLC_VAR("cur_economy"), + SLC_VAR("old_economy"), + SLC_VAR("liveries"), +}; + +#endif /* SAVELOAD_COMPAT_COMPANY_H */ diff --git a/src/saveload/compat/game_sl_compat.h b/src/saveload/compat/game_sl_compat.h index 204504e3b..cc05913d6 100644 --- a/src/saveload/compat/game_sl_compat.h +++ b/src/saveload/compat/game_sl_compat.h @@ -20,4 +20,16 @@ const SaveLoadCompat _game_script_sl_compat[] = { SLC_VAR("is_random"), }; +/** Original field order for SlGameLanguageString. */ +const SaveLoadCompat _game_language_string_sl_compat[] = { + SLC_VAR("string"), +}; + +/** Original field order for _game_language_desc. */ +const SaveLoadCompat _game_language_sl_compat[] = { + SLC_VAR("language"), + SLC_VAR("count"), + SLC_VAR("strings"), +}; + #endif /* SAVELOAD_COMPAT_GAME_H */ diff --git a/src/saveload/compat/gamelog_sl_compat.h b/src/saveload/compat/gamelog_sl_compat.h new file mode 100644 index 000000000..f1298bf92 --- /dev/null +++ b/src/saveload/compat/gamelog_sl_compat.h @@ -0,0 +1,105 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file gamelog_sl_compat.h Loading for gamelog chunks before table headers were added. */ + +#ifndef SAVELOAD_COMPAT_GAMELOG_H +#define SAVELOAD_COMPAT_GAMELOG_H + +#include "../saveload.h" + +/** Original field order for SlGamelogMode. */ +const SaveLoadCompat _gamelog_mode_sl_compat[] = { + SLC_VAR("mode.mode"), + SLC_VAR("mode.landscape"), +}; + +/** Original field order for SlGamelogRevision. */ +const SaveLoadCompat _gamelog_revision_sl_compat[] = { + SLC_VAR("revision.text"), + SLC_VAR("revision.newgrf"), + SLC_VAR("revision.slver"), + SLC_VAR("revision.modified"), +}; + +/** Original field order for SlGamelogOldver. */ +const SaveLoadCompat _gamelog_oldver_sl_compat[] = { + SLC_VAR("oldver.type"), + SLC_VAR("oldver.version"), +}; + +/** Original field order for SlGamelogSetting. */ +const SaveLoadCompat _gamelog_setting_sl_compat[] = { + SLC_VAR("setting.name"), + SLC_VAR("setting.oldval"), + SLC_VAR("setting.newval"), +}; + +/** Original field order for SlGamelogGrfadd. */ +const SaveLoadCompat _gamelog_grfadd_sl_compat[] = { + SLC_VAR("grfadd.grfid"), + SLC_VAR("grfadd.md5sum"), +}; + +/** Original field order for SlGamelogGrfrem. */ +const SaveLoadCompat _gamelog_grfrem_sl_compat[] = { + SLC_VAR("grfrem.grfid"), +}; + +/** Original field order for SlGamelogGrfcompat. */ +const SaveLoadCompat _gamelog_grfcompat_sl_compat[] = { + SLC_VAR("grfcompat.grfid"), + SLC_VAR("grfcompat.md5sum"), +}; + +/** Original field order for SlGamelogGrfparam. */ +const SaveLoadCompat _gamelog_grfparam_sl_compat[] = { + SLC_VAR("grfparam.grfid"), +}; + +/** Original field order for SlGamelogGrfmove. */ +const SaveLoadCompat _gamelog_grfmove_sl_compat[] = { + SLC_VAR("grfmove.grfid"), + SLC_VAR("grfmove.offset"), +}; + +/** Original field order for SlGamelogGrfbug. */ +const SaveLoadCompat _gamelog_grfbug_sl_compat[] = { + SLC_VAR("grfbug.data"), + SLC_VAR("grfbug.grfid"), + SLC_VAR("grfbug.bug"), +}; + +/** Original field order for SlGamelogEmergency. */ +const SaveLoadCompat _gamelog_emergency_sl_compat[] = { + SLC_VAR("is_emergency_save"), +}; + +/** Original field order for SlGamelogAction. */ +const SaveLoadCompat _gamelog_action_sl_compat[] = { + SLC_VAR("ct"), + SLC_VAR("mode"), + SLC_VAR("revision"), + SLC_VAR("oldver"), + SLC_VAR("setting"), + SLC_VAR("grfadd"), + SLC_VAR("grfrem"), + SLC_VAR("grfcompat"), + SLC_VAR("grfparam"), + SLC_VAR("grfmove"), + SLC_VAR("grfbug"), + SLC_VAR("emergency"), +}; + +/** Original field order for _gamelog_desc. */ +const SaveLoadCompat _gamelog_sl_compat[] = { + SLC_VAR("at"), + SLC_VAR("tick"), + SLC_VAR("action"), +}; + +#endif /* SAVELOAD_COMPAT_GAMELOG_H */ diff --git a/src/saveload/compat/linkgraph_sl_compat.h b/src/saveload/compat/linkgraph_sl_compat.h new file mode 100644 index 000000000..eb455da8f --- /dev/null +++ b/src/saveload/compat/linkgraph_sl_compat.h @@ -0,0 +1,66 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file linkgraph_sl_compat.h Loading of linkgraph chunks before table headers were added. */ + +#ifndef SAVELOAD_COMPAT_LINKGRAPH_H +#define SAVELOAD_COMPAT_LINKGRAPH_H + +#include "../saveload.h" + +/** Original field order for SlLinkgraphEdge. */ +const SaveLoadCompat _linkgraph_edge_sl_compat[] = { + SLC_NULL(4, SL_MIN_VERSION, SLV_191), + SLC_VAR("capacity"), + SLC_VAR("usage"), + SLC_VAR("last_unrestricted_update"), + SLC_VAR("last_restricted_update"), + SLC_VAR("next_edge"), +}; + +/** Original field order for SlLinkgraphNode. */ +const SaveLoadCompat _linkgraph_node_sl_compat[] = { + SLC_VAR("xy"), + SLC_VAR("supply"), + SLC_VAR("demand"), + SLC_VAR("station"), + SLC_VAR("last_update"), + SLC_VAR("edges"), +}; + +/** Original field order for link_graph_desc. */ +const SaveLoadCompat _linkgraph_sl_compat[] = { + SLC_VAR("last_compression"), + SLC_VAR("num_nodes"), + SLC_VAR("cargo"), + SLC_VAR("nodes"), +}; + +/** Original field order for job_desc. */ +const SaveLoadCompat _linkgraph_job_sl_compat[] = { + SLC_VAR("linkgraph.recalc_interval"), + SLC_VAR("linkgraph.recalc_time"), + SLC_VAR("linkgraph.distribution_pax"), + SLC_VAR("linkgraph.distribution_mail"), + SLC_VAR("linkgraph.distribution_armoured"), + SLC_VAR("linkgraph.distribution_default"), + SLC_VAR("linkgraph.accuracy"), + SLC_VAR("linkgraph.demand_distance"), + SLC_VAR("linkgraph.demand_size"), + SLC_VAR("linkgraph.short_path_saturation"), + SLC_VAR("join_date"), + SLC_VAR("link_graph.index"), + SLC_VAR("linkgraph"), +}; + +/** Original field order for schedule_desc. */ +const SaveLoadCompat _linkgraph_schedule_sl_compat[] = { + SLC_VAR("schedule"), + SLC_VAR("running"), +}; + +#endif /* SAVELOAD_COMPAT_LINKGRAPH_H */ diff --git a/src/saveload/compat/station_sl_compat.h b/src/saveload/compat/station_sl_compat.h index 397e1660f..1c24a8d5d 100644 --- a/src/saveload/compat/station_sl_compat.h +++ b/src/saveload/compat/station_sl_compat.h @@ -26,4 +26,156 @@ const SaveLoadCompat _roadstop_sl_compat[] = { SLC_NULL(1, SLV_25, SLV_26), }; +/** Original field order for SlStationSpecList. */ +const SaveLoadCompat _station_spec_list_sl_compat[] = { + SLC_VAR("grfid"), + SLC_VAR("localidx"), +}; + +/** Original field order for SlStationCargo. */ +const SaveLoadCompat _station_cargo_sl_compat[] = { + SLC_VAR("first"), + SLC_VAR("second"), +}; + +/** Original field order for SlStationFlow. */ +const SaveLoadCompat _station_flow_sl_compat[] = { + SLC_VAR("source"), + SLC_VAR("via"), + SLC_VAR("share"), + SLC_VAR("restricted"), +}; + +/** Original field order for SlStationGoods. */ +const SaveLoadCompat _station_goods_sl_compat[] = { + SLC_VAR("waiting_acceptance"), + SLC_VAR("status"), + SLC_NULL(2, SLV_51, SLV_68), + SLC_VAR("time_since_pickup"), + SLC_VAR("rating"), + SLC_VAR("cargo_source"), + SLC_VAR("cargo_source_xy"), + SLC_VAR("cargo_days"), + SLC_VAR("last_speed"), + SLC_VAR("last_age"), + SLC_VAR("cargo_feeder_share"), + SLC_VAR("amount_fract"), + SLC_VAR("packets"), + SLC_VAR("old_num_dests"), + SLC_VAR("cargo.reserved_count"), + SLC_VAR("link_graph"), + SLC_VAR("node"), + SLC_VAR("old_num_flows"), + SLC_VAR("max_waiting_cargo"), + SLC_VAR("flow"), + SLC_VAR("cargo"), +}; + +/** Original field order for SlStationBase. */ +const SaveLoadCompat _station_base_sl_compat[] = { + SLC_VAR("xy"), + SLC_VAR("town"), + SLC_VAR("string_id"), + SLC_VAR("name"), + SLC_VAR("delete_ctr"), + SLC_VAR("owner"), + SLC_VAR("facilities"), + SLC_VAR("build_date"), + SLC_VAR("random_bits"), + SLC_VAR("waiting_triggers"), + SLC_VAR("num_specs"), +}; + +/** Original field order for SlStationNormal. */ +const SaveLoadCompat _station_normal_sl_compat[] = { + SLC_VAR("base"), + SLC_VAR("train_station.tile"), + SLC_VAR("train_station.w"), + SLC_VAR("train_station.h"), + SLC_VAR("bus_stops"), + SLC_VAR("truck_stops"), + SLC_NULL(4, SL_MIN_VERSION, SLV_MULTITILE_DOCKS), + SLC_VAR("ship_station.tile"), + SLC_VAR("ship_station.w"), + SLC_VAR("ship_station.h"), + SLC_VAR("docking_station.tile"), + SLC_VAR("docking_station.w"), + SLC_VAR("docking_station.h"), + SLC_VAR("airport.tile"), + SLC_VAR("airport.w"), + SLC_VAR("airport.h"), + SLC_VAR("airport.type"), + SLC_VAR("airport.layout"), + SLC_VAR("airport.flags"), + SLC_VAR("airport.rotation"), + SLC_VAR("storage"), + SLC_VAR("airport.psa"), + SLC_VAR("indtype"), + SLC_VAR("time_since_load"), + SLC_VAR("time_since_unload"), + SLC_VAR("last_vehicle_type"), + SLC_VAR("had_vehicle_of_type"), + SLC_VAR("loading_vehicles"), + SLC_VAR("always_accepted"), + SLC_VAR("goods"), +}; + +/** Original field order for SlStationWaypoint. */ +const SaveLoadCompat _station_waypoint_sl_compat[] = { + SLC_VAR("base"), + SLC_VAR("town_cn"), + SLC_VAR("train_station.tile"), + SLC_VAR("train_station.w"), + SLC_VAR("train_station.h"), +}; + +/** Original field order for _station_desc. */ +const SaveLoadCompat _station_sl_compat[] = { + SLC_VAR("facilities"), + SLC_VAR("normal"), + SLC_VAR("waypoint"), + SLC_VAR("speclist"), +}; + +/** Original field order for _old_station_desc. */ +const SaveLoadCompat _old_station_sl_compat[] = { + SLC_VAR("xy"), + SLC_NULL(4, SL_MIN_VERSION, SLV_6), + SLC_VAR("train_station.tile"), + SLC_VAR("airport.tile"), + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(4, SLV_6, SLV_MULTITILE_DOCKS), + SLC_VAR("town"), + SLC_VAR("train_station.w"), + SLC_VAR("train_station.h"), + SLC_NULL(1, SL_MIN_VERSION, SLV_4), + SLC_VAR("string_id"), + SLC_VAR("name"), + SLC_VAR("indtype"), + SLC_VAR("had_vehicle_of_type"), + SLC_VAR("time_since_load"), + SLC_VAR("time_since_unload"), + SLC_VAR("delete_ctr"), + SLC_VAR("owner"), + SLC_VAR("facilities"), + SLC_VAR("airport.type"), + SLC_NULL(2, SL_MIN_VERSION, SLV_6), + SLC_NULL(1, SL_MIN_VERSION, SLV_5), + SLC_VAR("airport.flags"), + SLC_NULL(2, SL_MIN_VERSION, SLV_26), + SLC_VAR("last_vehicle_type"), + SLC_NULL(2, SLV_3, SLV_26), + SLC_VAR("build_date"), + SLC_VAR("bus_stops"), + SLC_VAR("truck_stops"), + SLC_VAR("random_bits"), + SLC_VAR("waiting_triggers"), + SLC_VAR("num_specs"), + SLC_VAR("loading_vehicles"), + SLC_NULL(32, SLV_2, SL_MAX_VERSION), + SLC_VAR("goods"), + SLC_VAR("speclist"), + +}; + #endif /* SAVELOAD_COMPAT_STATION_H */ diff --git a/src/saveload/compat/town_sl_compat.h b/src/saveload/compat/town_sl_compat.h new file mode 100644 index 000000000..34a414102 --- /dev/null +++ b/src/saveload/compat/town_sl_compat.h @@ -0,0 +1,87 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file town_sl_compat.h Loading of town chunks before table headers were added. */ + +#ifndef SAVELOAD_COMPAT_TOWN_H +#define SAVELOAD_COMPAT_TOWN_H + +#include "../saveload.h" + +/** Original field order for SlTownSupplied. */ +const SaveLoadCompat _town_supplied_sl_compat[] = { + SLC_VAR("old_max"), + SLC_VAR("new_max"), + SLC_VAR("old_act"), + SLC_VAR("new_act"), +}; + +/** Original field order for SlTownReceived. */ +const SaveLoadCompat _town_received_sl_compat[] = { + SLC_VAR("old_max"), + SLC_VAR("new_max"), + SLC_VAR("old_act"), + SLC_VAR("new_act"), +}; + +/** Original field order for SlTownAcceptanceMatrix. */ +const SaveLoadCompat _town_acceptance_matrix_sl_compat[] = { + SLC_VAR("area.tile"), + SLC_VAR("area.w"), + SLC_VAR("area.h"), +}; + +/** Original field order for town_desc. */ +const SaveLoadCompat _town_sl_compat[] = { + SLC_VAR("xy"), + SLC_NULL(2, SL_MIN_VERSION, SLV_3), + SLC_NULL(4, SLV_3, SLV_85), + SLC_NULL(2, SL_MIN_VERSION, SLV_92), + SLC_VAR("townnamegrfid"), + SLC_VAR("townnametype"), + SLC_VAR("townnameparts"), + SLC_VAR("name"), + SLC_VAR("flags"), + SLC_VAR("statues"), + SLC_NULL(1, SL_MIN_VERSION, SLV_2), + SLC_VAR("have_ratings"), + SLC_VAR("ratings"), + SLC_VAR("unwanted"), + SLC_VAR("supplied[CT_PASSENGERS].old_max"), + SLC_VAR("supplied[CT_MAIL].old_max"), + SLC_VAR("supplied[CT_PASSENGERS].new_max"), + SLC_VAR("supplied[CT_MAIL].new_max"), + SLC_VAR("supplied[CT_PASSENGERS].old_act"), + SLC_VAR("supplied[CT_MAIL].old_act"), + SLC_VAR("supplied[CT_PASSENGERS].new_act"), + SLC_VAR("supplied[CT_MAIL].new_act"), + SLC_NULL(2, SL_MIN_VERSION, SLV_164), + SLC_VAR("received[TE_FOOD].old_act"), + SLC_VAR("received[TE_WATER].old_act"), + SLC_VAR("received[TE_FOOD].new_act"), + SLC_VAR("received[TE_WATER].new_act"), + SLC_VAR("goal"), + SLC_VAR("text"), + SLC_VAR("time_until_rebuild"), + SLC_VAR("grow_counter"), + SLC_VAR("growth_rate"), + SLC_VAR("fund_buildings_months"), + SLC_VAR("road_build_months"), + SLC_VAR("exclusivity"), + SLC_VAR("exclusive_counter"), + SLC_VAR("larger_town"), + SLC_VAR("layout"), + SLC_VAR("psa_list"), + SLC_NULL(4, SLV_166, SLV_EXTEND_CARGOTYPES), + SLC_NULL(8, SLV_EXTEND_CARGOTYPES, SLV_REMOVE_TOWN_CARGO_CACHE), + SLC_NULL(30, SLV_2, SLV_REMOVE_TOWN_CARGO_CACHE), + SLC_VAR("supplied"), + SLC_VAR("received"), + SLC_VAR("acceptance_matrix"), +}; + +#endif /* SAVELOAD_COMPAT_TOWN_H */ diff --git a/src/saveload/compat/vehicle_sl_compat.h b/src/saveload/compat/vehicle_sl_compat.h new file mode 100644 index 000000000..524ff1a3b --- /dev/null +++ b/src/saveload/compat/vehicle_sl_compat.h @@ -0,0 +1,207 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file vehicle_sl_compat.h Loading of vehicle chunks before table headers were added. */ + +#ifndef SAVELOAD_COMPAT_VEHICLE_H +#define SAVELOAD_COMPAT_VEHICLE_H + +#include "../saveload.h" + +/** Original field order for SlVehicleCommon. */ +const SaveLoadCompat _vehicle_common_sl_compat[] = { + SLC_VAR("subtype"), + SLC_VAR("next"), + SLC_VAR("name"), + SLC_VAR("unitnumber"), + SLC_VAR("owner"), + SLC_VAR("tile"), + SLC_VAR("dest_tile"), + SLC_VAR("x_pos"), + SLC_VAR("y_pos"), + SLC_VAR("z_pos"), + SLC_VAR("direction"), + SLC_NULL(2, SL_MIN_VERSION, SLV_58), + SLC_VAR("spritenum"), + SLC_NULL(5, SL_MIN_VERSION, SLV_58), + SLC_VAR("engine_type"), + SLC_NULL(2, SL_MIN_VERSION, SLV_152), + SLC_VAR("cur_speed"), + SLC_VAR("subspeed"), + SLC_VAR("acceleration"), + SLC_VAR("motion_counter"), + SLC_VAR("progress"), + SLC_VAR("vehstatus"), + SLC_VAR("last_station_visited"), + SLC_VAR("last_loading_station"), + SLC_VAR("cargo_type"), + SLC_VAR("cargo_subtype"), + SLC_VAR("cargo_days"), + SLC_VAR("cargo_source"), + SLC_VAR("cargo_source_xy"), + SLC_VAR("cargo_cap"), + SLC_VAR("refit_cap"), + SLC_VAR("cargo_count"), + SLC_VAR("cargo.packets"), + SLC_VAR("cargo.action_counts"), + SLC_VAR("cargo_age_counter"), + SLC_VAR("day_counter"), + SLC_VAR("tick_counter"), + SLC_VAR("running_ticks"), + SLC_VAR("cur_implicit_order_index"), + SLC_VAR("cur_real_order_index"), + SLC_NULL(1, SL_MIN_VERSION, SLV_105), + SLC_VAR("current_order.type"), + SLC_VAR("current_order.flags"), + SLC_VAR("current_order.dest"), + SLC_VAR("current_order.refit_cargo"), + SLC_NULL(1, SLV_36, SLV_182), + SLC_VAR("current_order.wait_time"), + SLC_VAR("current_order.travel_time"), + SLC_VAR("current_order.max_speed"), + SLC_VAR("timetable_start"), + SLC_VAR("orders"), + SLC_VAR("age"), + SLC_VAR("max_age"), + SLC_VAR("date_of_last_service"), + SLC_VAR("service_interval"), + SLC_VAR("reliability"), + SLC_VAR("reliability_spd_dec"), + SLC_VAR("breakdown_ctr"), + SLC_VAR("breakdown_delay"), + SLC_VAR("breakdowns_since_last_service"), + SLC_VAR("breakdown_chance"), + SLC_VAR("build_year"), + SLC_VAR("load_unload_ticks"), + SLC_VAR("cargo_paid_for"), + SLC_VAR("vehicle_flags"), + SLC_VAR("profit_this_year"), + SLC_VAR("profit_last_year"), + SLC_VAR("cargo_feeder_share"), + SLC_VAR("cargo_loaded_at_xy"), + SLC_VAR("value"), + SLC_VAR("random_bits"), + SLC_VAR("waiting_triggers"), + SLC_VAR("next_shared"), + SLC_NULL(2, SLV_2, SLV_69), + SLC_NULL(4, SLV_69, SLV_101), + SLC_VAR("group_id"), + SLC_VAR("current_order_time"), + SLC_VAR("lateness_counter"), + SLC_NULL(10, SLV_2, SLV_144), +}; + +/** Original field order for SlVehicleTrain. */ +const SaveLoadCompat _vehicle_train_sl_compat[] = { + SLC_VAR("common"), + SLC_VAR("crash_anim_pos"), + SLC_VAR("force_proceed"), + SLC_VAR("railtype"), + SLC_VAR("track"), + SLC_VAR("flags"), + SLC_NULL(2, SLV_2, SLV_60), + SLC_VAR("wait_counter"), + SLC_NULL(2, SLV_2, SLV_20), + SLC_VAR("gv_flags"), + SLC_NULL(11, SLV_2, SLV_144), +}; + +/** Original field order for SlVehicleRoadVeh. */ +const SaveLoadCompat _vehicle_roadveh_sl_compat[] = { + SLC_VAR("common"), + SLC_VAR("state"), + SLC_VAR("frame"), + SLC_VAR("blocked_ctr"), + SLC_VAR("overtaking"), + SLC_VAR("overtaking_ctr"), + SLC_VAR("crashed_ctr"), + SLC_VAR("reverse_ctr"), + SLC_VAR("path.td"), + SLC_VAR("path.tile"), + SLC_NULL(2, SLV_6, SLV_69), + SLC_VAR("gv_flags"), + SLC_NULL(4, SLV_69, SLV_131), + SLC_NULL(2, SLV_6, SLV_131), + SLC_NULL(16, SLV_2, SLV_144), +}; + +/** Original field order for SlVehicleShip. */ +const SaveLoadCompat _vehicle_ship_sl_compat[] = { + SLC_VAR("common"), + SLC_VAR("state"), + SLC_VAR("path"), + SLC_VAR("rotation"), + SLC_NULL(16, SLV_2, SLV_144), +}; + +/** Original field order for SlVehicleAircraft. */ +const SaveLoadCompat _vehicle_aircraft_sl_compat[] = { + SLC_VAR("common"), + SLC_VAR("crashed_counter"), + SLC_VAR("pos"), + SLC_VAR("targetairport"), + SLC_VAR("state"), + SLC_VAR("previous_pos"), + SLC_VAR("last_direction"), + SLC_VAR("number_consecutive_turns"), + SLC_VAR("turn_counter"), + SLC_VAR("flags"), + SLC_NULL(13, SLV_2, SLV_144), +}; + +/** Original field order for SlVehicleEffect. */ +const SaveLoadCompat _vehicle_effect_sl_compat[] = { + SLC_VAR("subtype"), + SLC_VAR("tile"), + SLC_VAR("x_pos"), + SLC_VAR("y_pos"), + SLC_VAR("z_pos"), + SLC_VAR("sprite_cache.sprite_seq.seq[0].sprite"), + SLC_NULL(5, SL_MIN_VERSION, SLV_59), + SLC_VAR("progress"), + SLC_VAR("vehstatus"), + SLC_VAR("animation_state"), + SLC_VAR("animation_substate"), + SLC_VAR("spritenum"), + SLC_NULL(15, SLV_2, SLV_144), +}; + +/** Original field order for SlVehicleDisaster. */ +const SaveLoadCompat _vehicle_disaster_sl_compat[] = { + SLC_VAR("next"), + SLC_VAR("subtype"), + SLC_VAR("tile"), + SLC_VAR("dest_tile"), + SLC_VAR("x_pos"), + SLC_VAR("y_pos"), + SLC_VAR("z_pos"), + SLC_VAR("direction"), + SLC_NULL(5, SL_MIN_VERSION, SLV_58), + SLC_VAR("owner"), + SLC_VAR("vehstatus"), + SLC_VAR("current_order.dest"), + SLC_VAR("sprite_cache.sprite_seq.seq[0].sprite"), + SLC_VAR("age"), + SLC_VAR("tick_counter"), + SLC_VAR("image_override"), + SLC_VAR("big_ufo_destroyer_target"), + SLC_VAR("flags"), + SLC_NULL(16, SLV_2, SLV_144), +}; + +/** Original field order for vehicle_desc. */ +const SaveLoadCompat _vehicle_sl_compat[] = { + SLC_VAR("type"), + SLC_VAR("train"), + SLC_VAR("roadveh"), + SLC_VAR("ship"), + SLC_VAR("aircraft"), + SLC_VAR("effect"), + SLC_VAR("disaster"), +}; + +#endif /* SAVELOAD_COMPAT_VEHICLE_H */ diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp index 059e17333..f0083cb88 100644 --- a/src/saveload/game_sl.cpp +++ b/src/saveload/game_sl.cpp @@ -123,6 +123,7 @@ public: inline static const SaveLoad description[] = { SLEG_SSTR("string", _game_saveload_string, SLE_STR | SLF_ALLOW_CONTROL), }; + inline const static SaveLoadCompatTable compat_description = _game_language_string_sl_compat; void Save(LanguageStrings *ls) const override { @@ -139,7 +140,7 @@ public: uint32 length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? _game_saveload_strings : (uint32)SlGetStructListLength(UINT32_MAX); for (uint32 i = 0; i < length; i++) { - SlObject(nullptr, this->GetDescription()); + SlObject(nullptr, this->GetLoadDescription()); ls->lines.emplace_back(_game_saveload_string); } } @@ -153,12 +154,14 @@ static const SaveLoad _game_language_desc[] = { static void Load_GSTR() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_game_language_desc, _game_language_sl_compat); + delete _current_data; _current_data = new GameStrings(); while (SlIterateArray() != -1) { LanguageStrings ls; - SlObject(&ls, _game_language_desc); + SlObject(&ls, slt); _current_data->raw_strings.push_back(std::move(ls)); } @@ -175,6 +178,8 @@ static void Load_GSTR() static void Save_GSTR() { + SlTableHeader(_game_language_desc); + if (_current_data == nullptr) return; for (uint i = 0; i < _current_data->raw_strings.size(); i++) { @@ -184,7 +189,7 @@ static void Save_GSTR() } static const ChunkHandler game_chunk_handlers[] = { - { 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_ARRAY }, + { 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_TABLE }, { 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_TABLE }, }; diff --git a/src/saveload/gamelog_sl.cpp b/src/saveload/gamelog_sl.cpp index f76718d42..8cc81c8cf 100644 --- a/src/saveload/gamelog_sl.cpp +++ b/src/saveload/gamelog_sl.cpp @@ -8,10 +8,12 @@ /** @file gamelog_sl.cpp Code handling saving and loading of gamelog data */ #include "../stdafx.h" -#include "../gamelog_internal.h" -#include "../fios.h" #include "saveload.h" +#include "compat/gamelog_sl_compat.h" + +#include "../gamelog_internal.h" +#include "../fios.h" #include "../safeguards.h" @@ -22,16 +24,21 @@ public: SLE_VAR(LoggedChange, mode.mode, SLE_UINT8), SLE_VAR(LoggedChange, mode.landscape, SLE_UINT8), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_mode_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_MODE) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_MODE) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogRevision : public DefaultSaveLoadHandler<SlGamelogRevision, LoggedChange> { @@ -42,16 +49,21 @@ public: SLE_VAR(LoggedChange, revision.slver, SLE_UINT16), SLE_VAR(LoggedChange, revision.modified, SLE_UINT8), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_revision_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_REVISION) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_REVISION) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogOldver : public DefaultSaveLoadHandler<SlGamelogOldver, LoggedChange> { @@ -60,16 +72,21 @@ public: SLE_VAR(LoggedChange, oldver.type, SLE_UINT32), SLE_VAR(LoggedChange, oldver.version, SLE_UINT32), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_oldver_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_OLDVER) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_OLDVER) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogSetting : public DefaultSaveLoadHandler<SlGamelogSetting, LoggedChange> { @@ -79,16 +96,21 @@ public: SLE_VAR(LoggedChange, setting.oldval, SLE_INT32), SLE_VAR(LoggedChange, setting.newval, SLE_INT32), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_setting_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_SETTING) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_SETTING) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogGrfadd : public DefaultSaveLoadHandler<SlGamelogGrfadd, LoggedChange> { @@ -97,16 +119,21 @@ public: SLE_VAR(LoggedChange, grfadd.grfid, SLE_UINT32 ), SLE_ARR(LoggedChange, grfadd.md5sum, SLE_UINT8, 16), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_grfadd_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_GRFADD) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_GRFADD) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogGrfrem : public DefaultSaveLoadHandler<SlGamelogGrfrem, LoggedChange> { @@ -114,16 +141,21 @@ public: inline static const SaveLoad description[] = { SLE_VAR(LoggedChange, grfrem.grfid, SLE_UINT32), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_grfrem_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_GRFREM) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_GRFREM) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogGrfcompat : public DefaultSaveLoadHandler<SlGamelogGrfcompat, LoggedChange> { @@ -132,16 +164,21 @@ public: SLE_VAR(LoggedChange, grfcompat.grfid, SLE_UINT32 ), SLE_ARR(LoggedChange, grfcompat.md5sum, SLE_UINT8, 16), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_grfcompat_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_GRFCOMPAT) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_GRFCOMPAT) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogGrfparam : public DefaultSaveLoadHandler<SlGamelogGrfparam, LoggedChange> { @@ -149,16 +186,21 @@ public: inline static const SaveLoad description[] = { SLE_VAR(LoggedChange, grfparam.grfid, SLE_UINT32), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_grfparam_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_GRFPARAM) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_GRFPARAM) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogGrfmove : public DefaultSaveLoadHandler<SlGamelogGrfmove, LoggedChange> { @@ -167,16 +209,21 @@ public: SLE_VAR(LoggedChange, grfmove.grfid, SLE_UINT32), SLE_VAR(LoggedChange, grfmove.offset, SLE_INT32), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_grfmove_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_GRFMOVE) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_GRFMOVE) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogGrfbug : public DefaultSaveLoadHandler<SlGamelogGrfbug, LoggedChange> { @@ -186,16 +233,21 @@ public: SLE_VAR(LoggedChange, grfbug.grfid, SLE_UINT32), SLE_VAR(LoggedChange, grfbug.bug, SLE_UINT8), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_grfbug_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_GRFBUG) return; SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_GRFBUG) return; + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; static bool _is_emergency_save = true; @@ -206,8 +258,9 @@ public: inline static const SaveLoad description[] = { SLEG_CONDVAR("is_emergency_save", _is_emergency_save, SLE_BOOL, SLV_RIFF_TO_ARRAY, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_emergency_sl_compat; - void GenericSaveLoad(LoggedChange *lc) const + void Save(LoggedChange *lc) const override { if (lc->ct != GLCT_EMERGENCY) return; @@ -215,9 +268,14 @@ public: SlObject(lc, this->GetDescription()); } - void Save(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void Load(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } - void LoadCheck(LoggedChange *lc) const override { this->GenericSaveLoad(lc); } + void Load(LoggedChange *lc) const override + { + if (lc->ct != GLCT_EMERGENCY) return; + + SlObject(lc, this->GetLoadDescription()); + } + + void LoadCheck(LoggedChange *lc) const override { this->Load(lc); } }; class SlGamelogAction : public DefaultSaveLoadHandler<SlGamelogAction, LoggedAction> { @@ -236,6 +294,7 @@ public: SLEG_STRUCT("grfbug", SlGamelogGrfbug), SLEG_STRUCT("emergency", SlGamelogEmergency), }; + inline const static SaveLoadCompatTable compat_description = _gamelog_action_sl_compat; void Save(LoggedAction *la) const override { @@ -262,7 +321,7 @@ public: memset(lc, 0, sizeof(*lc)); lc->ct = ct; - SlObject(lc, this->GetDescription()); + SlObject(lc, this->GetLoadDescription()); } return; } @@ -275,7 +334,7 @@ public: memset(lc, 0, sizeof(*lc)); lc->ct = (GamelogChangeType)SlReadByte(); - SlObject(lc, this->GetDescription()); + SlObject(lc, this->GetLoadDescription()); } } @@ -293,6 +352,8 @@ static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_action assert(gamelog_action == nullptr); assert(gamelog_actions == 0); + const std::vector<SaveLoad> slt = SlCompatTableHeader(_gamelog_desc, _gamelog_sl_compat); + if (IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY)) { byte type; while ((type = SlReadByte()) != GLAT_NONE) { @@ -303,7 +364,7 @@ static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_action memset(la, 0, sizeof(*la)); la->at = (GamelogActionType)type; - SlObject(la, _gamelog_desc); + SlObject(la, slt); } return; } @@ -313,12 +374,14 @@ static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_action LoggedAction *la = &gamelog_action[gamelog_actions++]; memset(la, 0, sizeof(*la)); - SlObject(la, _gamelog_desc); + SlObject(la, slt); } } static void Save_GLOG() { + SlTableHeader(_gamelog_desc); + const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; uint i = 0; @@ -339,7 +402,7 @@ static void Check_GLOG() } static const ChunkHandler gamelog_chunk_handlers[] = { - { 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_ARRAY } + { 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_TABLE } }; extern const ChunkHandlerTable _gamelog_chunk_handlers(gamelog_chunk_handlers); diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp index 5456fb33e..952ae1de3 100644 --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -8,12 +8,15 @@ /** @file linkgraph_sl.cpp Code handling saving and loading of link graphs */ #include "../stdafx.h" + +#include "saveload.h" +#include "compat/linkgraph_sl_compat.h" + #include "../linkgraph/linkgraph.h" #include "../linkgraph/linkgraphjob.h" #include "../linkgraph/linkgraphschedule.h" #include "../network/network.h" #include "../settings_internal.h" -#include "saveload.h" #include "../safeguards.h" @@ -27,13 +30,13 @@ static NodeID _linkgraph_from; ///< Contains the current "from" node being saved class SlLinkgraphEdge : public DefaultSaveLoadHandler<SlLinkgraphEdge, Node> { public: inline static const SaveLoad description[] = { - SLE_CONDNULL(4, SL_MIN_VERSION, SLV_191), // distance SLE_VAR(Edge, capacity, SLE_UINT32), SLE_VAR(Edge, usage, SLE_UINT32), SLE_VAR(Edge, last_unrestricted_update, SLE_INT32), SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, SLV_187, SL_MAX_VERSION), SLE_VAR(Edge, next_edge, SLE_UINT16), }; + inline const static SaveLoadCompatTable compat_description = _linkgraph_edge_sl_compat; void Save(Node *bn) const override { @@ -55,7 +58,7 @@ public: if (IsSavegameVersionBefore(SLV_191)) { /* We used to save the full matrix ... */ for (NodeID to = 0; to < max_size; ++to) { - SlObject(&_linkgraph->edges[_linkgraph_from][to], this->GetDescription()); + SlObject(&_linkgraph->edges[_linkgraph_from][to], this->GetLoadDescription()); } return; } @@ -68,7 +71,7 @@ public: used_size--; if (to >= max_size) SlErrorCorrupt("Link graph structure overflow"); - SlObject(&_linkgraph->edges[_linkgraph_from][to], this->GetDescription()); + SlObject(&_linkgraph->edges[_linkgraph_from][to], this->GetLoadDescription()); } if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) && used_size > 0) SlErrorCorrupt("Corrupted link graph"); @@ -85,6 +88,7 @@ public: SLE_VAR(Node, last_update, SLE_INT32), SLEG_STRUCTLIST("edges", SlLinkgraphEdge), }; + inline const static SaveLoadCompatTable compat_description = _linkgraph_node_sl_compat; void Save(LinkGraph *lg) const override { @@ -105,7 +109,7 @@ public: lg->Init(length); for (NodeID from = 0; from < length; ++from) { _linkgraph_from = from; - SlObject(&lg->nodes[from], this->GetDescription()); + SlObject(&lg->nodes[from], this->GetLoadDescription()); } } }; @@ -136,15 +140,16 @@ class SlLinkgraphJobProxy : public DefaultSaveLoadHandler<SlLinkgraphJobProxy, L public: inline static const SaveLoad description[] = {{}}; // Needed to keep DefaultSaveLoadHandler happy. SaveLoadTable GetDescription() const override { return GetLinkGraphDesc(); } + inline const static SaveLoadCompatTable compat_description = _linkgraph_sl_compat; void Save(LinkGraphJob *lgj) const override { - SlObject(const_cast<LinkGraph *>(&lgj->Graph()), GetLinkGraphDesc()); + SlObject(const_cast<LinkGraph *>(&lgj->Graph()), this->GetDescription()); } void Load(LinkGraphJob *lgj) const override { - SlObject(const_cast<LinkGraph *>(&lgj->Graph()), GetLinkGraphDesc()); + SlObject(const_cast<LinkGraph *>(&lgj->Graph()), this->GetLoadDescription()); } }; @@ -241,6 +246,8 @@ void AfterLoadLinkGraphs() */ static void Save_LGRP() { + SlTableHeader(GetLinkGraphDesc()); + for (LinkGraph *lg : LinkGraph::Iterate()) { SlSetArrayIndex(lg->index); SlObject(lg, GetLinkGraphDesc()); @@ -252,10 +259,12 @@ static void Save_LGRP() */ static void Load_LGRP() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(GetLinkGraphDesc(), _linkgraph_sl_compat); + int index; while ((index = SlIterateArray()) != -1) { LinkGraph *lg = new (index) LinkGraph(); - SlObject(lg, GetLinkGraphDesc()); + SlObject(lg, slt); } } @@ -264,6 +273,8 @@ static void Load_LGRP() */ static void Save_LGRJ() { + SlTableHeader(GetLinkGraphJobDesc()); + for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) { SlSetArrayIndex(lgj->index); SlObject(lgj, GetLinkGraphJobDesc()); @@ -275,10 +286,12 @@ static void Save_LGRJ() */ static void Load_LGRJ() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(GetLinkGraphJobDesc(), _linkgraph_job_sl_compat); + int index; while ((index = SlIterateArray()) != -1) { LinkGraphJob *lgj = new (index) LinkGraphJob(); - SlObject(lgj, GetLinkGraphJobDesc()); + SlObject(lgj, slt); } } @@ -287,6 +300,8 @@ static void Load_LGRJ() */ static void Save_LGRS() { + SlTableHeader(GetLinkGraphScheduleDesc()); + SlSetArrayIndex(0); SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc()); } @@ -296,8 +311,10 @@ static void Save_LGRS() */ static void Load_LGRS() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(GetLinkGraphScheduleDesc(), _linkgraph_schedule_sl_compat); + if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return; - SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc()); + SlObject(&LinkGraphSchedule::instance, slt); if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many LGRS entries"); } @@ -310,9 +327,9 @@ static void Ptrs_LGRS() } static const ChunkHandler linkgraph_chunk_handlers[] = { - { 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_ARRAY }, - { 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_ARRAY }, - { 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_ARRAY }, + { 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_TABLE }, + { 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_TABLE }, + { 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_TABLE }, }; extern const ChunkHandlerTable _linkgraph_chunk_handlers(linkgraph_chunk_handlers); diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index b6e843c99..a238d8c1b 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -456,7 +456,7 @@ public: /** * Get the pre-header description of the fields in the savegame. */ - virtual SaveLoadCompatTable GetCompatDescription() const { return {}; } + virtual SaveLoadCompatTable GetCompatDescription() const = 0; /** * Get the description for how to load the chunk. Depending on the @@ -481,6 +481,7 @@ template <class TImpl, class TObject> class DefaultSaveLoadHandler : public SaveLoadHandler { public: SaveLoadTable GetDescription() const override { return static_cast<const TImpl *>(this)->description; } + SaveLoadCompatTable GetCompatDescription() const override { return static_cast<const TImpl *>(this)->compat_description; } virtual void Save(TObject *object) const {} void Save(void *object) const override { this->Save(static_cast<TObject *>(object)); } diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index ebf2c94f4..d9978cd6f 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -199,6 +199,7 @@ public: SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION), SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8, SLV_27, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _station_spec_list_sl_compat; void Save(BaseStation *bst) const override { @@ -218,7 +219,7 @@ public: /* Allocate speclist memory when loading a game */ bst->speclist = CallocT<StationSpecList>(bst->num_specs); for (uint i = 0; i < bst->num_specs; i++) { - SlObject(&bst->speclist[i], this->GetDescription()); + SlObject(&bst->speclist[i], this->GetLoadDescription()); } } } @@ -230,6 +231,7 @@ public: SLE_VAR(StationCargoPair, first, SLE_UINT16), SLE_REFLIST(StationCargoPair, second, REF_CARGO_PACKET), }; + inline const static SaveLoadCompatTable compat_description = _station_cargo_sl_compat; void Save(GoodsEntry *ge) const override { @@ -245,7 +247,7 @@ public: StationCargoPair pair; for (uint j = 0; j < num_dests; ++j) { - SlObject(&pair, this->GetDescription()); + SlObject(&pair, this->GetLoadDescription()); const_cast<StationCargoPacketMap &>(*(ge->cargo.Packets()))[pair.first].swap(pair.second); assert(pair.second.empty()); } @@ -267,6 +269,7 @@ public: SLE_VAR(FlowSaveLoad, share, SLE_UINT32), SLE_CONDVAR(FlowSaveLoad, restricted, SLE_BOOL, SLV_187, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _station_flow_sl_compat; void Save(GoodsEntry *ge) const override { @@ -300,7 +303,7 @@ public: FlowStat *fs = nullptr; StationID prev_source = INVALID_STATION; for (uint32 j = 0; j < num_flows; ++j) { - SlObject(&flow, this->GetDescription()); + SlObject(&flow, this->GetLoadDescription()); if (fs == nullptr || prev_source != flow.source) { fs = &(ge->flows.insert(std::make_pair(flow.source, FlowStat(flow.via, flow.share, flow.restricted))).first->second); } else { @@ -326,7 +329,6 @@ public: static const SaveLoad description[] = { SLEG_CONDVAR("waiting_acceptance", _waiting_acceptance, SLE_UINT16, SL_MIN_VERSION, SLV_68), SLE_CONDVAR(GoodsEntry, status, SLE_UINT8, SLV_68, SL_MAX_VERSION), - SLE_CONDNULL(2, SLV_51, SLV_68), SLE_VAR(GoodsEntry, time_since_pickup, SLE_UINT8), SLE_VAR(GoodsEntry, rating, SLE_UINT8), SLEG_CONDVAR("cargo_source", _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7), @@ -352,6 +354,7 @@ public: return description; } #endif + inline const static SaveLoadCompatTable compat_description = _station_goods_sl_compat; /** * Get the number of cargoes used by this savegame version. @@ -392,7 +395,7 @@ public: size_t num_cargo = this->GetNumCargo(); for (CargoID i = 0; i < num_cargo; i++) { GoodsEntry *ge = &st->goods[i]; - SlObject(ge, this->GetDescription()); + SlObject(ge, this->GetLoadDescription()); if (IsSavegameVersionBefore(SLV_183)) { SwapPackets(ge); } @@ -438,19 +441,14 @@ public: static const SaveLoad _old_station_desc[] = { SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), SLE_CONDVAR(Station, xy, SLE_UINT32, SLV_6, SL_MAX_VERSION), - SLE_CONDNULL(4, SL_MIN_VERSION, SLV_6), ///< bus/lorry tile SLE_CONDVAR(Station, train_station.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION), SLE_CONDVAR(Station, airport.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), SLE_CONDVAR(Station, airport.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), - SLE_CONDNULL(4, SLV_6, SLV_MULTITILE_DOCKS), SLE_REF(Station, town, REF_TOWN), SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16), SLE_CONDVAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SL_MAX_VERSION), - SLE_CONDNULL(1, SL_MIN_VERSION, SLV_4), ///< alpha_order - SLE_VAR(Station, string_id, SLE_STRINGID), SLE_CONDSSTR(Station, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION), SLE_CONDVAR(Station, indtype, SLE_UINT8, SLV_103, SL_MAX_VERSION), @@ -463,18 +461,12 @@ static const SaveLoad _old_station_desc[] = { SLE_VAR(Station, owner, SLE_UINT8), SLE_VAR(Station, facilities, SLE_UINT8), SLE_VAR(Station, airport.type, SLE_UINT8), - - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6), ///< Truck/bus stop status - SLE_CONDNULL(1, SL_MIN_VERSION, SLV_5), ///< Blocked months - SLE_CONDVAR(Station, airport.flags, SLE_VAR_U64 | SLE_FILE_U16, SL_MIN_VERSION, SLV_3), SLE_CONDVAR(Station, airport.flags, SLE_VAR_U64 | SLE_FILE_U32, SLV_3, SLV_46), SLE_CONDVAR(Station, airport.flags, SLE_UINT64, SLV_46, SL_MAX_VERSION), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_26), ///< last-vehicle SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, SLV_26, SL_MAX_VERSION), - SLE_CONDNULL(2, SLV_3, SLV_26), ///< custom station class and id SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, SLV_3, SLV_31), SLE_CONDVAR(Station, build_date, SLE_INT32, SLV_31, SL_MAX_VERSION), @@ -488,14 +480,14 @@ static const SaveLoad _old_station_desc[] = { SLE_CONDREFLIST(Station, loading_vehicles, REF_VEHICLE, SLV_57, SL_MAX_VERSION), - /* reserve extra space in savegame here. (currently 32 bytes) */ - SLE_CONDNULL(32, SLV_2, SL_MAX_VERSION), SLEG_STRUCTLIST("goods", SlStationGoods), SLEG_CONDSTRUCTLIST("speclist", SlStationSpecList, SLV_27, SL_MAX_VERSION), }; static void Load_STNS() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_old_station_desc, _old_station_sl_compat); + _cargo_source_xy = 0; _cargo_days = 0; _cargo_feeder_share = 0; @@ -505,7 +497,7 @@ static void Load_STNS() Station *st = new (index) Station(); _waiting_acceptance = 0; - SlObject(st, _old_station_desc); + SlObject(st, slt); } } @@ -542,15 +534,22 @@ public: SLE_VAR(BaseStation, waiting_triggers, SLE_UINT8), SLE_CONDVAR(BaseStation, num_specs, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH), }; + inline const static SaveLoadCompatTable compat_description = _station_base_sl_compat; - void GenericSaveLoad(BaseStation *bst) const + void Save(BaseStation *bst) const override { SlObject(bst, this->GetDescription()); } - void Save(BaseStation *bst) const override { this->GenericSaveLoad(bst); } - void Load(BaseStation *bst) const override { this->GenericSaveLoad(bst); } - void FixPointers(BaseStation *bst) const override { this->GenericSaveLoad(bst); } + void Load(BaseStation *bst) const override + { + SlObject(bst, this->GetLoadDescription()); + } + + void FixPointers(BaseStation *bst) const override + { + SlObject(bst, this->GetDescription()); + } }; /** @@ -566,7 +565,6 @@ public: SLE_REF(Station, bus_stops, REF_ROADSTOPS), SLE_REF(Station, truck_stops, REF_ROADSTOPS), - SLE_CONDNULL(4, SL_MIN_VERSION, SLV_MULTITILE_DOCKS), SLE_CONDVAR(Station, ship_station.tile, SLE_UINT32, SLV_MULTITILE_DOCKS, SL_MAX_VERSION), SLE_CONDVAR(Station, ship_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION), SLE_CONDVAR(Station, ship_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION), @@ -594,16 +592,25 @@ public: SLE_CONDVAR(Station, always_accepted, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), SLEG_STRUCTLIST("goods", SlStationGoods), }; + inline const static SaveLoadCompatTable compat_description = _station_normal_sl_compat; - void GenericSaveLoad(BaseStation *bst) const + void Save(BaseStation *bst) const { if ((bst->facilities & FACIL_WAYPOINT) != 0) return; SlObject(bst, this->GetDescription()); } - void Save(BaseStation *bst) const override { this->GenericSaveLoad(bst); } - void Load(BaseStation *bst) const override { this->GenericSaveLoad(bst); } - void FixPointers(BaseStation *bst) const override { this->GenericSaveLoad(bst); } + void Load(BaseStation *bst) const + { + if ((bst->facilities & FACIL_WAYPOINT) != 0) return; + SlObject(bst, this->GetLoadDescription()); + } + + void FixPointers(BaseStation *bst) const + { + if ((bst->facilities & FACIL_WAYPOINT) != 0) return; + SlObject(bst, this->GetDescription()); + } }; class SlStationWaypoint : public DefaultSaveLoadHandler<SlStationWaypoint, BaseStation> { @@ -616,16 +623,25 @@ public: SLE_CONDVAR(Waypoint, train_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION), SLE_CONDVAR(Waypoint, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _station_waypoint_sl_compat; - void GenericSaveLoad(BaseStation *bst) const + void Save(BaseStation *bst) const { if ((bst->facilities & FACIL_WAYPOINT) == 0) return; SlObject(bst, this->GetDescription()); } - void Save(BaseStation *bst) const override { this->GenericSaveLoad(bst); } - void Load(BaseStation *bst) const override { this->GenericSaveLoad(bst); } - void FixPointers(BaseStation *bst) const override { this->GenericSaveLoad(bst); } + void Load(BaseStation *bst) const + { + if ((bst->facilities & FACIL_WAYPOINT) == 0) return; + SlObject(bst, this->GetLoadDescription()); + } + + void FixPointers(BaseStation *bst) const + { + if ((bst->facilities & FACIL_WAYPOINT) == 0) return; + SlObject(bst, this->GetDescription()); + } }; static const SaveLoad _station_desc[] = { @@ -637,6 +653,8 @@ static const SaveLoad _station_desc[] = { static void Save_STNN() { + SlTableHeader(_station_desc); + /* Write the stations */ for (BaseStation *st : BaseStation::Iterate()) { SlSetArrayIndex(st->index); @@ -646,6 +664,8 @@ static void Save_STNN() static void Load_STNN() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_station_desc, _station_sl_compat); + _old_num_flows = 0; int index; @@ -653,7 +673,7 @@ static void Load_STNN() bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0; BaseStation *bst = waypoint ? (BaseStation *)new (index) Waypoint() : new (index) Station(); - SlObject(bst, _station_desc); + SlObject(bst, slt); } } @@ -701,7 +721,7 @@ static void Ptrs_ROADSTOP() static const ChunkHandler station_chunk_handlers[] = { { 'STNS', nullptr, Load_STNS, Ptrs_STNS, nullptr, CH_READONLY }, - { 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, nullptr, CH_ARRAY }, + { 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, nullptr, CH_TABLE }, { 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_TABLE }, }; diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index faca4180c..c5b5b0080 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -8,6 +8,11 @@ /** @file town_sl.cpp Code handling saving and loading of towns and houses */ #include "../stdafx.h" + +#include "saveload.h" +#include "compat/town_sl_compat.h" + +#include "newgrf_sl.h" #include "../newgrf_house.h" #include "../town.h" #include "../landscape.h" @@ -15,9 +20,6 @@ #include "../strings_func.h" #include "../tilematrix_type.hpp" -#include "saveload.h" -#include "newgrf_sl.h" - #include "../safeguards.h" typedef TileMatrix<CargoTypes, 4> AcceptanceMatrix; @@ -121,6 +123,7 @@ public: SLE_CONDVAR(TransportedCargoStat<uint32>, old_act, SLE_UINT32, SLV_165, SL_MAX_VERSION), SLE_CONDVAR(TransportedCargoStat<uint32>, new_act, SLE_UINT32, SLV_165, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _town_supplied_sl_compat; /** * Get the number of cargoes used by this savegame version. @@ -146,7 +149,7 @@ public: { size_t num_cargo = this->GetNumCargo(); for (CargoID i = 0; i < num_cargo; i++) { - SlObject(&t->supplied[i], this->GetDescription()); + SlObject(&t->supplied[i], this->GetLoadDescription()); } } }; @@ -159,6 +162,7 @@ public: SLE_CONDVAR(TransportedCargoStat<uint16>, old_act, SLE_UINT16, SLV_165, SL_MAX_VERSION), SLE_CONDVAR(TransportedCargoStat<uint16>, new_act, SLE_UINT16, SLV_165, SL_MAX_VERSION), }; + inline const static SaveLoadCompatTable compat_description = _town_received_sl_compat; void Save(Town *t) const override { @@ -172,7 +176,7 @@ public: { size_t length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? (size_t)TE_END : SlGetStructListLength(TE_END); for (size_t i = 0; i < length; i++) { - SlObject(&t->received[i], this->GetDescription()); + SlObject(&t->received[i], this->GetLoadDescription()); } } }; @@ -184,12 +188,13 @@ public: SLE_VAR(AcceptanceMatrix, area.w, SLE_UINT16), SLE_VAR(AcceptanceMatrix, area.h, SLE_UINT16), }; + inline const static SaveLoadCompatTable compat_description = _town_acceptance_matrix_sl_compat; void Load(Town *t) const override { /* Discard now unused acceptance matrix. */ AcceptanceMatrix dummy; - SlObject(&dummy, this->GetDescription()); + SlObject(&dummy, this->GetLoadDescription()); if (dummy.area.w != 0) { uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID; SlSkipBytes(4 * arr_len); @@ -201,10 +206,6 @@ static const SaveLoad _town_desc[] = { SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6), SLE_CONDVAR(Town, xy, SLE_UINT32, SLV_6, SL_MAX_VERSION), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_3), ///< population, no longer in use - SLE_CONDNULL(4, SLV_3, SLV_85), ///< population, no longer in use - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_92), ///< num_houses, no longer in use - SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, SLV_66, SL_MAX_VERSION), SLE_VAR(Town, townnametype, SLE_UINT16), SLE_VAR(Town, townnameparts, SLE_UINT32), @@ -214,36 +215,30 @@ static const SaveLoad _town_desc[] = { SLE_CONDVAR(Town, statues, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104), SLE_CONDVAR(Town, statues, SLE_UINT16, SLV_104, SL_MAX_VERSION), - SLE_CONDNULL(1, SL_MIN_VERSION, SLV_2), ///< sort_index, no longer in use - SLE_CONDVAR(Town, have_ratings, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104), SLE_CONDVAR(Town, have_ratings, SLE_UINT16, SLV_104, SL_MAX_VERSION), SLE_CONDARR(Town, ratings, SLE_INT16, 8, SL_MIN_VERSION, SLV_104), SLE_CONDARR(Town, ratings, SLE_INT16, MAX_COMPANIES, SLV_104, SL_MAX_VERSION), - /* failed bribe attempts are stored since savegame format 4 */ SLE_CONDARR(Town, unwanted, SLE_INT8, 8, SLV_4, SLV_104), SLE_CONDARR(Town, unwanted, SLE_INT8, MAX_COMPANIES, SLV_104, SL_MAX_VERSION), SLE_CONDVAR(Town, supplied[CT_PASSENGERS].old_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_MAIL].old_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_PASSENGERS].new_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_MAIL].new_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_PASSENGERS].old_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_MAIL].old_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_PASSENGERS].new_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_MAIL].new_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), - SLE_CONDVAR(Town, supplied[CT_PASSENGERS].old_max, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_MAIL].old_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_MAIL].old_max, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_PASSENGERS].new_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_PASSENGERS].new_max, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_MAIL].new_max, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_MAIL].new_max, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_PASSENGERS].old_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_PASSENGERS].old_act, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_MAIL].old_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_MAIL].old_act, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_PASSENGERS].new_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_PASSENGERS].new_act, SLE_UINT32, SLV_9, SLV_165), + SLE_CONDVAR(Town, supplied[CT_MAIL].new_act, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9), SLE_CONDVAR(Town, supplied[CT_MAIL].new_act, SLE_UINT32, SLV_9, SLV_165), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_164), ///< pct_pass_transported / pct_mail_transported, now computed on the fly - SLE_CONDVAR(Town, received[TE_FOOD].old_act, SLE_UINT16, SL_MIN_VERSION, SLV_165), SLE_CONDVAR(Town, received[TE_WATER].old_act, SLE_UINT16, SL_MIN_VERSION, SLV_165), SLE_CONDVAR(Town, received[TE_FOOD].new_act, SLE_UINT16, SL_MIN_VERSION, SLV_165), @@ -254,12 +249,10 @@ static const SaveLoad _town_desc[] = { SLE_CONDSSTR(Town, text, SLE_STR | SLF_ALLOW_CONTROL, SLV_168, SL_MAX_VERSION), SLE_CONDVAR(Town, time_until_rebuild, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_54), - SLE_CONDVAR(Town, grow_counter, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_54), - SLE_CONDVAR(Town, growth_rate, SLE_FILE_U8 | SLE_VAR_I16, SL_MIN_VERSION, SLV_54), - SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT16, SLV_54, SL_MAX_VERSION), + SLE_CONDVAR(Town, grow_counter, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_54), SLE_CONDVAR(Town, grow_counter, SLE_UINT16, SLV_54, SL_MAX_VERSION), - + SLE_CONDVAR(Town, growth_rate, SLE_FILE_U8 | SLE_VAR_I16, SL_MIN_VERSION, SLV_54), SLE_CONDVAR(Town, growth_rate, SLE_FILE_I16 | SLE_VAR_U16, SLV_54, SLV_165), SLE_CONDVAR(Town, growth_rate, SLE_UINT16, SLV_165, SL_MAX_VERSION), @@ -274,10 +267,6 @@ static const SaveLoad _town_desc[] = { SLE_CONDREFLIST(Town, psa_list, REF_STORAGE, SLV_161, SL_MAX_VERSION), - SLE_CONDNULL(4, SLV_166, SLV_EXTEND_CARGOTYPES), ///< cargo_produced, no longer in use - SLE_CONDNULL(8, SLV_EXTEND_CARGOTYPES, SLV_REMOVE_TOWN_CARGO_CACHE), ///< cargo_produced, no longer in use - SLE_CONDNULL(30, SLV_2, SLV_REMOVE_TOWN_CARGO_CACHE), ///< old reserved space - SLEG_CONDSTRUCTLIST("supplied", SlTownSupplied, SLV_165, SL_MAX_VERSION), SLEG_CONDSTRUCTLIST("received", SlTownReceived, SLV_165, SL_MAX_VERSION), SLEG_CONDSTRUCTLIST("acceptance_matrix", SlTownAcceptanceMatrix, SLV_166, SLV_REMOVE_TOWN_CARGO_CACHE), @@ -295,6 +284,8 @@ static void Load_HIDS() static void Save_TOWN() { + SlTableHeader(_town_desc); + for (Town *t : Town::Iterate()) { SlSetArrayIndex(t->index); SlObject(t, _town_desc); @@ -303,11 +294,13 @@ static void Save_TOWN() static void Load_TOWN() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_town_desc, _town_sl_compat); + int index; while ((index = SlIterateArray()) != -1) { Town *t = new (index) Town(); - SlObject(t, _town_desc); + SlObject(t, slt); if (t->townnamegrfid == 0 && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1) && GetStringTab(t->townnametype) != TEXT_TAB_OLD_CUSTOM) { SlErrorCorrupt("Invalid town name generator"); @@ -327,7 +320,7 @@ static void Ptrs_TOWN() static const ChunkHandler town_chunk_handlers[] = { { 'HIDS', Save_HIDS, Load_HIDS, nullptr, nullptr, CH_TABLE }, - { 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_ARRAY }, + { 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_TABLE }, }; extern const ChunkHandlerTable _town_chunk_handlers(town_chunk_handlers); diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index b2d9972fe..962f5f99a 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -8,6 +8,10 @@ /** @file vehicle_sl.cpp Code handling saving and loading of vehicles */ #include "../stdafx.h" + +#include "saveload.h" +#include "compat/vehicle_sl_compat.h" + #include "../vehicle_func.h" #include "../train.h" #include "../roadveh.h" @@ -19,8 +23,6 @@ #include "../company_func.h" #include "../disaster_vehicle.h" -#include "saveload.h" - #include <map> #include "../safeguards.h" @@ -607,12 +609,8 @@ public: SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION), SLE_VAR(Vehicle, direction, SLE_UINT8), - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_58), SLE_VAR(Vehicle, spritenum, SLE_UINT8), - SLE_CONDNULL(5, SL_MIN_VERSION, SLV_58), SLE_VAR(Vehicle, engine_type, SLE_UINT16), - - SLE_CONDNULL(2, SL_MIN_VERSION, SLV_152), SLE_VAR(Vehicle, cur_speed, SLE_UINT16), SLE_VAR(Vehicle, subspeed, SLE_UINT8), SLE_VAR(Vehicle, acceleration, SLE_UINT8), @@ -643,8 +641,6 @@ public: SLE_VAR(Vehicle, cur_implicit_order_index, SLE_UINT8), SLE_CONDVAR(Vehicle, cur_real_order_index, SLE_UINT8, SLV_158, SL_MAX_VERSION), - /* num_orders is now part of OrderList and is not saved but counted */ - SLE_CONDNULL(1, SL_MIN_VERSION, SLV_105), /* This next line is for version 4 and prior compatibility.. it temporarily reads type and flags (which were both 4 bits) into type. Later on this is @@ -659,7 +655,6 @@ public: /* Refit in current order */ SLE_CONDVAR(Vehicle, current_order.refit_cargo, SLE_UINT8, SLV_36, SL_MAX_VERSION), - SLE_CONDNULL(1, SLV_36, SLV_182), // refit_subtype /* Timetable in current order */ SLE_CONDVAR(Vehicle, current_order.wait_time, SLE_UINT16, SLV_67, SL_MAX_VERSION), @@ -707,29 +702,31 @@ public: SLE_CONDVAR(Vehicle, waiting_triggers, SLE_UINT8, SLV_2, SL_MAX_VERSION), SLE_CONDREF(Vehicle, next_shared, REF_VEHICLE, SLV_2, SL_MAX_VERSION), - SLE_CONDNULL(2, SLV_2, SLV_69), - SLE_CONDNULL(4, SLV_69, SLV_101), - SLE_CONDVAR(Vehicle, group_id, SLE_UINT16, SLV_60, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, current_order_time, SLE_UINT32, SLV_67, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, lateness_counter, SLE_INT32, SLV_67, SL_MAX_VERSION), - - SLE_CONDNULL(10, SLV_2, SLV_144), // old reserved space }; #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916) return description; } #endif + inline const static SaveLoadCompatTable compat_description = _vehicle_common_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + SlObject(v, this->GetDescription()); + } }; class SlVehicleTrain : public DefaultSaveLoadHandler<SlVehicleTrain, Vehicle> { @@ -743,24 +740,28 @@ public: SLE_CONDVAR(Train, flags, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SLV_100), SLE_CONDVAR(Train, flags, SLE_UINT16, SLV_100, SL_MAX_VERSION), - SLE_CONDNULL(2, SLV_2, SLV_60), - SLE_CONDVAR(Train, wait_counter, SLE_UINT16, SLV_136, SL_MAX_VERSION), - - SLE_CONDNULL(2, SLV_2, SLV_20), SLE_CONDVAR(Train, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION), - SLE_CONDNULL(11, SLV_2, SLV_144), // old reserved space }; + inline const static SaveLoadCompatTable compat_description = _vehicle_train_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { if (v->type != VEH_TRAIN) return; SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + if (v->type != VEH_TRAIN) return; + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + if (v->type != VEH_TRAIN) return; + SlObject(v, this->GetDescription()); + } }; class SlVehicleRoadVeh : public DefaultSaveLoadHandler<SlVehicleRoadVeh, Vehicle> { @@ -776,23 +777,27 @@ public: SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8), SLE_CONDDEQUE(RoadVehicle, path.td, SLE_UINT8, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION), SLE_CONDDEQUE(RoadVehicle, path.tile, SLE_UINT32, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION), - - SLE_CONDNULL(2, SLV_6, SLV_69), SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION), - SLE_CONDNULL(4, SLV_69, SLV_131), - SLE_CONDNULL(2, SLV_6, SLV_131), - SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space }; + inline const static SaveLoadCompatTable compat_description = _vehicle_roadveh_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { if (v->type != VEH_ROAD) return; SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + if (v->type != VEH_ROAD) return; + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + if (v->type != VEH_ROAD) return; + SlObject(v, this->GetDescription()); + } }; class SlVehicleShip : public DefaultSaveLoadHandler<SlVehicleShip, Vehicle> { @@ -802,19 +807,26 @@ public: SLE_VAR(Ship, state, SLE_UINT8), SLE_CONDDEQUE(Ship, path, SLE_UINT8, SLV_SHIP_PATH_CACHE, SL_MAX_VERSION), SLE_CONDVAR(Ship, rotation, SLE_UINT8, SLV_SHIP_ROTATION, SL_MAX_VERSION), - - SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space }; + inline const static SaveLoadCompatTable compat_description = _vehicle_ship_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { if (v->type != VEH_SHIP) return; SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + if (v->type != VEH_SHIP) return; + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + if (v->type != VEH_SHIP) return; + SlObject(v, this->GetDescription()); + } }; class SlVehicleAircraft : public DefaultSaveLoadHandler<SlVehicleAircraft, Vehicle> { @@ -835,19 +847,26 @@ public: SLE_CONDVAR(Aircraft, turn_counter, SLE_UINT8, SLV_136, SL_MAX_VERSION), SLE_CONDVAR(Aircraft, flags, SLE_UINT8, SLV_167, SL_MAX_VERSION), - - SLE_CONDNULL(13, SLV_2, SLV_144), // old reserved space }; + inline const static SaveLoadCompatTable compat_description = _vehicle_aircraft_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { if (v->type != VEH_AIRCRAFT) return; SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + if (v->type != VEH_AIRCRAFT) return; + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + if (v->type != VEH_AIRCRAFT) return; + SlObject(v, this->GetDescription()); + } }; class SlVehicleEffect : public DefaultSaveLoadHandler<SlVehicleEffect, Vehicle> { @@ -866,7 +885,6 @@ public: SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION), SLE_VAR(Vehicle, sprite_cache.sprite_seq.seq[0].sprite, SLE_FILE_U16 | SLE_VAR_U32), - SLE_CONDNULL(5, SL_MIN_VERSION, SLV_59), SLE_VAR(Vehicle, progress, SLE_UINT8), SLE_VAR(Vehicle, vehstatus, SLE_UINT8), @@ -874,19 +892,26 @@ public: SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8), SLE_CONDVAR(Vehicle, spritenum, SLE_UINT8, SLV_2, SL_MAX_VERSION), - - SLE_CONDNULL(15, SLV_2, SLV_144), // old reserved space }; + inline const static SaveLoadCompatTable compat_description = _vehicle_effect_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { if (v->type != VEH_EFFECT) return; SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + if (v->type != VEH_EFFECT) return; + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + if (v->type != VEH_EFFECT) return; + SlObject(v, this->GetDescription()); + } }; class SlVehicleDisaster : public DefaultSaveLoadHandler<SlVehicleDisaster, Vehicle> { @@ -918,7 +943,6 @@ public: SLE_CONDVAR(Vehicle, z_pos, SLE_INT32, SLV_164, SL_MAX_VERSION), SLE_VAR(Vehicle, direction, SLE_UINT8), - SLE_CONDNULL(5, SL_MIN_VERSION, SLV_58), SLE_VAR(Vehicle, owner, SLE_UINT8), SLE_VAR(Vehicle, vehstatus, SLE_UINT8), SLE_CONDVAR(Vehicle, current_order.dest, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_5), @@ -934,23 +958,30 @@ public: SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_191), SLE_CONDVAR(DisasterVehicle, big_ufo_destroyer_target, SLE_UINT32, SLV_191, SL_MAX_VERSION), SLE_CONDVAR(DisasterVehicle, flags, SLE_UINT8, SLV_194, SL_MAX_VERSION), - - SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space }; #if defined(_MSC_VER) && (_MSC_VER == 1915 || _MSC_VER == 1916) return description; } #endif + inline const static SaveLoadCompatTable compat_description = _vehicle_disaster_sl_compat; - void GenericSaveLoad(Vehicle *v) const + void Save(Vehicle *v) const override { if (v->type != VEH_DISASTER) return; SlObject(v, this->GetDescription()); } - void Save(Vehicle *v) const override { this->GenericSaveLoad(v); } - void Load(Vehicle *v) const override { this->GenericSaveLoad(v); } - void FixPointers(Vehicle *v) const override { this->GenericSaveLoad(v); } + void Load(Vehicle *v) const override + { + if (v->type != VEH_DISASTER) return; + SlObject(v, this->GetLoadDescription()); + } + + void FixPointers(Vehicle *v) const override + { + if (v->type != VEH_DISASTER) return; + SlObject(v, this->GetDescription()); + } }; const static SaveLoad _vehicle_desc[] = { @@ -966,6 +997,8 @@ const static SaveLoad _vehicle_desc[] = { /** Will be called when the vehicles need to be saved. */ static void Save_VEHS() { + SlTableHeader(_vehicle_desc); + /* Write the vehicles */ for (Vehicle *v : Vehicle::Iterate()) { SlSetArrayIndex(v->index); @@ -976,6 +1009,8 @@ static void Save_VEHS() /** Will be called when vehicles need to be loaded. */ void Load_VEHS() { + const std::vector<SaveLoad> slt = SlCompatTableHeader(_vehicle_desc, _vehicle_sl_compat); + int index; _cargo_count = 0; @@ -995,7 +1030,7 @@ void Load_VEHS() default: SlErrorCorrupt("Invalid vehicle type"); } - SlObject(v, _vehicle_desc); + SlObject(v, slt); if (_cargo_count != 0 && IsCompanyBuildableVehicleType(v) && CargoPacket::CanAllocateItem()) { /* Don't construct the packet with station here, because that'll fail with old savegames */ @@ -1030,7 +1065,7 @@ void Ptrs_VEHS() } static const ChunkHandler veh_chunk_handlers[] = { - { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY }, + { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_TABLE }, }; extern const ChunkHandlerTable _veh_chunk_handlers(veh_chunk_handlers); |