Codechange: Use ChunkHandlers sub-classes
This commit is contained in:
@@ -18,22 +18,30 @@
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Prices in pre 126 savegames */
|
||||
static void Load_PRIC()
|
||||
{
|
||||
/* Old games store 49 base prices, very old games store them as int32 */
|
||||
int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
|
||||
SlCopy(nullptr, 49, vt | SLE_VAR_NULL);
|
||||
SlCopy(nullptr, 49, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
}
|
||||
struct PRICChunkHandler : ChunkHandler {
|
||||
PRICChunkHandler() : ChunkHandler('PRIC', CH_READONLY) {}
|
||||
|
||||
void Load() const override
|
||||
{
|
||||
/* Old games store 49 base prices, very old games store them as int32 */
|
||||
int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
|
||||
SlCopy(nullptr, 49, vt | SLE_VAR_NULL);
|
||||
SlCopy(nullptr, 49, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
}
|
||||
};
|
||||
|
||||
/** Cargo payment rates in pre 126 savegames */
|
||||
static void Load_CAPR()
|
||||
{
|
||||
uint num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
|
||||
int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
|
||||
SlCopy(nullptr, num_cargo, vt | SLE_VAR_NULL);
|
||||
SlCopy(nullptr, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
}
|
||||
struct CAPRChunkHandler : ChunkHandler {
|
||||
CAPRChunkHandler() : ChunkHandler('CAPR', CH_READONLY) {}
|
||||
|
||||
void Load() const override
|
||||
{
|
||||
uint num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
|
||||
int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
|
||||
SlCopy(nullptr, num_cargo, vt | SLE_VAR_NULL);
|
||||
SlCopy(nullptr, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
}
|
||||
};
|
||||
|
||||
static const SaveLoad _economy_desc[] = {
|
||||
SLE_CONDVAR(Economy, old_max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_65),
|
||||
@@ -49,25 +57,29 @@ static const SaveLoad _economy_desc[] = {
|
||||
};
|
||||
|
||||
/** Economy variables */
|
||||
static void Save_ECMY()
|
||||
{
|
||||
SlTableHeader(_economy_desc);
|
||||
struct ECMYChunkHandler : ChunkHandler {
|
||||
ECMYChunkHandler() : ChunkHandler('ECMY', CH_TABLE) {}
|
||||
|
||||
SlSetArrayIndex(0);
|
||||
SlObject(&_economy, _economy_desc);
|
||||
}
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(_economy_desc);
|
||||
|
||||
/** Economy variables */
|
||||
static void Load_ECMY()
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_economy_desc, _economy_sl_compat);
|
||||
SlSetArrayIndex(0);
|
||||
SlObject(&_economy, _economy_desc);
|
||||
}
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
|
||||
SlObject(&_economy, slt);
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many ECMY entries");
|
||||
|
||||
StartupIndustryDailyChanges(IsSavegameVersionBefore(SLV_102)); // old savegames will need to be initialized
|
||||
}
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_economy_desc, _economy_sl_compat);
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
|
||||
SlObject(&_economy, slt);
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many ECMY entries");
|
||||
|
||||
StartupIndustryDailyChanges(IsSavegameVersionBefore(SLV_102)); // old savegames will need to be initialized
|
||||
}
|
||||
};
|
||||
|
||||
static const SaveLoad _cargopayment_desc[] = {
|
||||
SLE_REF(CargoPayment, front, REF_VEHICLE),
|
||||
@@ -76,39 +88,46 @@ static const SaveLoad _cargopayment_desc[] = {
|
||||
SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, SLV_181, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static void Save_CAPY()
|
||||
{
|
||||
SlTableHeader(_cargopayment_desc);
|
||||
|
||||
for (CargoPayment *cp : CargoPayment::Iterate()) {
|
||||
SlSetArrayIndex(cp->index);
|
||||
SlObject(cp, _cargopayment_desc);
|
||||
struct CAPYChunkHandler : ChunkHandler {
|
||||
CAPYChunkHandler() : ChunkHandler('CAPY', CH_TABLE)
|
||||
{
|
||||
this->fix_pointers = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_CAPY()
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_cargopayment_desc, _cargopayment_sl_compat);
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(_cargopayment_desc);
|
||||
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
CargoPayment *cp = new (index) CargoPayment();
|
||||
SlObject(cp, slt);
|
||||
for (CargoPayment *cp : CargoPayment::Iterate()) {
|
||||
SlSetArrayIndex(cp->index);
|
||||
SlObject(cp, _cargopayment_desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Ptrs_CAPY()
|
||||
{
|
||||
for (CargoPayment *cp : CargoPayment::Iterate()) {
|
||||
SlObject(cp, _cargopayment_desc);
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_cargopayment_desc, _cargopayment_sl_compat);
|
||||
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
CargoPayment *cp = new (index) CargoPayment();
|
||||
SlObject(cp, slt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler CAPY{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_TABLE };
|
||||
static const ChunkHandler PRIC{ 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_READONLY };
|
||||
static const ChunkHandler CAPR{ 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_READONLY };
|
||||
static const ChunkHandler ECMY{ 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_TABLE };
|
||||
void FixPointers() const override
|
||||
{
|
||||
for (CargoPayment *cp : CargoPayment::Iterate()) {
|
||||
SlObject(cp, _cargopayment_desc);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static const CAPYChunkHandler CAPY;
|
||||
static const PRICChunkHandler PRIC;
|
||||
static const CAPRChunkHandler CAPR;
|
||||
static const ECMYChunkHandler ECMY;
|
||||
static const ChunkHandlerRef economy_chunk_handlers[] = {
|
||||
CAPY,
|
||||
PRIC,
|
||||
|
Reference in New Issue
Block a user