mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use a common sub-class for NewGRFMapping chunks
parent
6e627f35ac
commit
7bcc7e11ff
|
@ -14,32 +14,12 @@
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
|
||||||
struct APIDChunkHandler : ChunkHandler {
|
struct APIDChunkHandler : NewGRFMappingChunkHandler {
|
||||||
APIDChunkHandler() : ChunkHandler('APID', CH_TABLE) {}
|
APIDChunkHandler() : NewGRFMappingChunkHandler('APID', _airport_mngr) {}
|
||||||
|
|
||||||
void Save() const override
|
|
||||||
{
|
|
||||||
Save_NewGRFMapping(_airport_mngr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load() const override
|
|
||||||
{
|
|
||||||
Load_NewGRFMapping(_airport_mngr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ATIDChunkHandler : ChunkHandler {
|
struct ATIDChunkHandler : NewGRFMappingChunkHandler {
|
||||||
ATIDChunkHandler() : ChunkHandler('ATID', CH_TABLE) {}
|
ATIDChunkHandler() : NewGRFMappingChunkHandler('ATID', _airporttile_mngr) {}
|
||||||
|
|
||||||
void Save() const override
|
|
||||||
{
|
|
||||||
Save_NewGRFMapping(_airporttile_mngr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load() const override
|
|
||||||
{
|
|
||||||
Load_NewGRFMapping(_airporttile_mngr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const ATIDChunkHandler ATID;
|
static const ATIDChunkHandler ATID;
|
||||||
|
|
|
@ -119,32 +119,12 @@ struct INDYChunkHandler : ChunkHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IIDSChunkHandler : ChunkHandler {
|
struct IIDSChunkHandler : NewGRFMappingChunkHandler {
|
||||||
IIDSChunkHandler() : ChunkHandler('IIDS', CH_TABLE) {}
|
IIDSChunkHandler() : NewGRFMappingChunkHandler('IIDS', _industry_mngr) {}
|
||||||
|
|
||||||
void Save() const override
|
|
||||||
{
|
|
||||||
Save_NewGRFMapping(_industry_mngr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load() const override
|
|
||||||
{
|
|
||||||
Load_NewGRFMapping(_industry_mngr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TIDSChunkHandler : ChunkHandler {
|
struct TIDSChunkHandler : NewGRFMappingChunkHandler {
|
||||||
TIDSChunkHandler() : ChunkHandler('TIDS', CH_TABLE) {}
|
TIDSChunkHandler() : NewGRFMappingChunkHandler('TIDS', _industile_mngr) {}
|
||||||
|
|
||||||
void Save() const override
|
|
||||||
{
|
|
||||||
Save_NewGRFMapping(_industile_mngr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load() const override
|
|
||||||
{
|
|
||||||
Load_NewGRFMapping(_industile_mngr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Description of the data to save and load in #IndustryBuildData. */
|
/** Description of the data to save and load in #IndustryBuildData. */
|
||||||
|
|
|
@ -26,38 +26,36 @@ static const SaveLoad _newgrf_mapping_desc[] = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a GRF ID + local id -> OpenTTD's id mapping.
|
* Save a GRF ID + local id -> OpenTTD's id mapping.
|
||||||
* @param mapping The mapping to save.
|
|
||||||
*/
|
*/
|
||||||
void Save_NewGRFMapping(const OverrideManagerBase &mapping)
|
void NewGRFMappingChunkHandler::Save() const
|
||||||
{
|
{
|
||||||
SlTableHeader(_newgrf_mapping_desc);
|
SlTableHeader(_newgrf_mapping_desc);
|
||||||
|
|
||||||
for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
|
for (uint i = 0; i < this->mapping.GetMaxMapping(); i++) {
|
||||||
if (mapping.mapping_ID[i].grfid == 0 &&
|
if (this->mapping.mapping_ID[i].grfid == 0 &&
|
||||||
mapping.mapping_ID[i].entity_id == 0) continue;
|
this->mapping.mapping_ID[i].entity_id == 0) continue;
|
||||||
SlSetArrayIndex(i);
|
SlSetArrayIndex(i);
|
||||||
SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
|
SlObject(&this->mapping.mapping_ID[i], _newgrf_mapping_desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a GRF ID + local id -> OpenTTD's id mapping.
|
* Load a GRF ID + local id -> OpenTTD's id mapping.
|
||||||
* @param mapping The mapping to load.
|
|
||||||
*/
|
*/
|
||||||
void Load_NewGRFMapping(OverrideManagerBase &mapping)
|
void NewGRFMappingChunkHandler::Load() const
|
||||||
{
|
{
|
||||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_newgrf_mapping_desc, _newgrf_mapping_sl_compat);
|
const std::vector<SaveLoad> slt = SlCompatTableHeader(_newgrf_mapping_desc, _newgrf_mapping_sl_compat);
|
||||||
|
|
||||||
/* Clear the current mapping stored.
|
/* Clear the current mapping stored.
|
||||||
* This will create the manager if ever it is not yet done */
|
* This will create the manager if ever it is not yet done */
|
||||||
mapping.ResetMapping();
|
this->mapping.ResetMapping();
|
||||||
|
|
||||||
uint max_id = mapping.GetMaxMapping();
|
uint max_id = this->mapping.GetMaxMapping();
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
|
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
|
||||||
SlObject(&mapping.mapping_ID[index], slt);
|
SlObject(&this->mapping.mapping_ID[index], slt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,12 @@
|
||||||
|
|
||||||
#include "../newgrf_commons.h"
|
#include "../newgrf_commons.h"
|
||||||
|
|
||||||
void Save_NewGRFMapping(const OverrideManagerBase &mapping);
|
struct NewGRFMappingChunkHandler : ChunkHandler {
|
||||||
void Load_NewGRFMapping(OverrideManagerBase &mapping);
|
OverrideManagerBase &mapping;
|
||||||
|
|
||||||
|
NewGRFMappingChunkHandler(uint32 id, OverrideManagerBase &mapping) : ChunkHandler(id, CH_TABLE), mapping(mapping) {}
|
||||||
|
void Save() const override;
|
||||||
|
void Load() const override;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* SAVELOAD_NEWGRF_SL_H */
|
#endif /* SAVELOAD_NEWGRF_SL_H */
|
||||||
|
|
|
@ -66,18 +66,8 @@ struct OBJSChunkHandler : ChunkHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OBIDChunkHandler : ChunkHandler {
|
struct OBIDChunkHandler : NewGRFMappingChunkHandler {
|
||||||
OBIDChunkHandler() : ChunkHandler('OBID', CH_TABLE) {}
|
OBIDChunkHandler() : NewGRFMappingChunkHandler('OBID', _object_mngr) {}
|
||||||
|
|
||||||
void Save() const override
|
|
||||||
{
|
|
||||||
Save_NewGRFMapping(_object_mngr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load() const override
|
|
||||||
{
|
|
||||||
Load_NewGRFMapping(_object_mngr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const OBIDChunkHandler OBID;
|
static const OBIDChunkHandler OBID;
|
||||||
|
|
|
@ -272,18 +272,8 @@ static const SaveLoad _town_desc[] = {
|
||||||
SLEG_CONDSTRUCTLIST("acceptance_matrix", SlTownAcceptanceMatrix, SLV_166, SLV_REMOVE_TOWN_CARGO_CACHE),
|
SLEG_CONDSTRUCTLIST("acceptance_matrix", SlTownAcceptanceMatrix, SLV_166, SLV_REMOVE_TOWN_CARGO_CACHE),
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HIDSChunkHandler : ChunkHandler {
|
struct HIDSChunkHandler : NewGRFMappingChunkHandler {
|
||||||
HIDSChunkHandler() : ChunkHandler('HIDS', CH_TABLE) {}
|
HIDSChunkHandler() : NewGRFMappingChunkHandler('HIDS', _house_mngr) {}
|
||||||
|
|
||||||
void Save() const override
|
|
||||||
{
|
|
||||||
Save_NewGRFMapping(_house_mngr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load() const override
|
|
||||||
{
|
|
||||||
Load_NewGRFMapping(_house_mngr);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CITYChunkHandler : ChunkHandler {
|
struct CITYChunkHandler : ChunkHandler {
|
||||||
|
|
Loading…
Reference in New Issue