diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -272,54 +272,64 @@ static const SaveLoad _town_desc[] = { SLEG_CONDSTRUCTLIST("acceptance_matrix", SlTownAcceptanceMatrix, SLV_166, SLV_REMOVE_TOWN_CARGO_CACHE), }; -static void Save_HIDS() -{ - Save_NewGRFMapping(_house_mngr); -} +struct HIDSChunkHandler : ChunkHandler { + HIDSChunkHandler() : ChunkHandler('HIDS', CH_TABLE) {} -static void Load_HIDS() -{ - Load_NewGRFMapping(_house_mngr); -} + void Save() const override + { + Save_NewGRFMapping(_house_mngr); + } -static void Save_TOWN() -{ - SlTableHeader(_town_desc); + void Load() const override + { + Load_NewGRFMapping(_house_mngr); + } +}; - for (Town *t : Town::Iterate()) { - SlSetArrayIndex(t->index); - SlObject(t, _town_desc); +struct CITYChunkHandler : ChunkHandler { + CITYChunkHandler() : ChunkHandler('CITY', CH_TABLE) + { + this->fix_pointers = true; } -} -static void Load_TOWN() -{ - const std::vector slt = SlCompatTableHeader(_town_desc, _town_sl_compat); - - int index; + void Save() const override + { + SlTableHeader(_town_desc); - while ((index = SlIterateArray()) != -1) { - Town *t = new (index) Town(); - 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"); + for (Town *t : Town::Iterate()) { + SlSetArrayIndex(t->index); + SlObject(t, _town_desc); } } -} + + void Load() const override + { + const std::vector slt = SlCompatTableHeader(_town_desc, _town_sl_compat); -/** Fix pointers when loading town data. */ -static void Ptrs_TOWN() -{ - if (IsSavegameVersionBefore(SLV_161)) return; + int index; + + while ((index = SlIterateArray()) != -1) { + Town *t = new (index) Town(); + SlObject(t, slt); - for (Town *t : Town::Iterate()) { - SlObject(t, _town_desc); + 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"); + } + } } -} + + void FixPointers() const override + { + if (IsSavegameVersionBefore(SLV_161)) return; -static const ChunkHandler HIDS{ 'HIDS', Save_HIDS, Load_HIDS, nullptr, nullptr, CH_TABLE }; -static const ChunkHandler CITY{ 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_TABLE }; + for (Town *t : Town::Iterate()) { + SlObject(t, _town_desc); + } + } +}; + +static const HIDSChunkHandler HIDS; +static const CITYChunkHandler CITY; static const ChunkHandlerRef town_chunk_handlers[] = { HIDS, CITY,