Codechange: Use ChunkHandlers sub-classes

This commit is contained in:
glx22
2021-06-07 23:24:37 +02:00
committed by Loïc Guilloux
parent c1a9fe6fbd
commit 2c941cd8b3
35 changed files with 1953 additions and 1665 deletions

View File

@@ -29,40 +29,47 @@ static const SaveLoad _depot_desc[] = {
SLE_CONDVAR(Depot, build_date, SLE_INT32, SLV_142, SL_MAX_VERSION),
};
static void Save_DEPT()
{
SlTableHeader(_depot_desc);
for (Depot *depot : Depot::Iterate()) {
SlSetArrayIndex(depot->index);
SlObject(depot, _depot_desc);
struct DEPTChunkHandler : ChunkHandler {
DEPTChunkHandler() : ChunkHandler('DEPT', CH_TABLE)
{
this->fix_pointers = true;
}
}
static void Load_DEPT()
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_depot_desc, _depot_sl_compat);
void Save() const override
{
SlTableHeader(_depot_desc);
int index;
while ((index = SlIterateArray()) != -1) {
Depot *depot = new (index) Depot();
SlObject(depot, slt);
/* Set the town 'pointer' so we can restore it later. */
if (IsSavegameVersionBefore(SLV_141)) depot->town = (Town *)(size_t)_town_index;
for (Depot *depot : Depot::Iterate()) {
SlSetArrayIndex(depot->index);
SlObject(depot, _depot_desc);
}
}
}
static void Ptrs_DEPT()
{
for (Depot *depot : Depot::Iterate()) {
SlObject(depot, _depot_desc);
if (IsSavegameVersionBefore(SLV_141)) depot->town = Town::Get((size_t)depot->town);
void Load() const override
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_depot_desc, _depot_sl_compat);
int index;
while ((index = SlIterateArray()) != -1) {
Depot *depot = new (index) Depot();
SlObject(depot, slt);
/* Set the town 'pointer' so we can restore it later. */
if (IsSavegameVersionBefore(SLV_141)) depot->town = (Town *)(size_t)_town_index;
}
}
}
static const ChunkHandler DEPT{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_TABLE };
void FixPointers() const override
{
for (Depot *depot : Depot::Iterate()) {
SlObject(depot, _depot_desc);
if (IsSavegameVersionBefore(SLV_141)) depot->town = Town::Get((size_t)depot->town);
}
}
};
static const DEPTChunkHandler DEPT;
static const ChunkHandlerRef depot_chunk_handlers[] = {
DEPT,
};