Saveload: Use table format for industry build data chunks

pull/661/head
Jonathan G Rennison 3 months ago
parent 0e262620d2
commit f52d56249d

@ -215,6 +215,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_TABLE_MISC_SL, XSCF_NULL, 2, 2, "table_misc_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_SCRIPT_SL, XSCF_NULL, 1, 1, "table_script_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_NEWGRF_SL, XSCF_NULL, 1, 1, "table_newgrf_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_INDUSTRY_SL, XSCF_NULL, 1, 1, "table_industry_sl", nullptr, nullptr, nullptr },
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr }, // This is the end marker
};

@ -166,6 +166,7 @@ enum SlXvFeatureIndex {
///< v2: SUBS, CMDL, CMPU, ERNW, DEPT, CAPY, ECMY, EIDS, ENGN, GOAL, GRPS, RAIL, OBJS, SIGN, PSAC, STPE, STPA
XSLFI_TABLE_SCRIPT_SL, ///< Use upstream table format for script chunks
XSLFI_TABLE_NEWGRF_SL, ///< Use upstream table format for NewGRF/ID mapping chunks
XSLFI_TABLE_INDUSTRY_SL, ///< Use upstream table format for industry chunks: IBLD, ITBL
XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit
XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk

@ -135,44 +135,54 @@ static void Ptrs_INDY()
}
/** Description of the data to save and load in #IndustryBuildData. */
static const SaveLoad _industry_builder_desc[] = {
SLEG_VAR(_industry_builder.wanted_inds, SLE_UINT32),
static const NamedSaveLoad _industry_builder_desc[] = {
NSL("wanted_inds", SLEG_VAR(_industry_builder.wanted_inds, SLE_UINT32)),
};
/** Load/save industry builder. */
static void LoadSave_IBLD()
/** Save industry builder. */
static void Save_IBLD()
{
SlGlobList(_industry_builder_desc);
SlSaveTableObjectChunk(_industry_builder_desc);
}
/** Load industry builder. */
static void Load_IBLD()
{
SlLoadTableOrRiffFiltered(_industry_builder_desc);
}
/** Description of the data to save and load in #IndustryTypeBuildData. */
static const SaveLoad _industrytype_builder_desc[] = {
SLE_VAR(IndustryTypeBuildData, probability, SLE_UINT32),
SLE_VAR(IndustryTypeBuildData, min_number, SLE_UINT8),
SLE_VAR(IndustryTypeBuildData, target_count, SLE_UINT16),
SLE_VAR(IndustryTypeBuildData, max_wait, SLE_UINT16),
SLE_VAR(IndustryTypeBuildData, wait_count, SLE_UINT16),
static const NamedSaveLoad _industrytype_builder_desc[] = {
NSL("probability", SLE_VAR(IndustryTypeBuildData, probability, SLE_UINT32)),
NSL("min_number", SLE_VAR(IndustryTypeBuildData, min_number, SLE_UINT8)),
NSL("target_count", SLE_VAR(IndustryTypeBuildData, target_count, SLE_UINT16)),
NSL("max_wait", SLE_VAR(IndustryTypeBuildData, max_wait, SLE_UINT16)),
NSL("wait_count", SLE_VAR(IndustryTypeBuildData, wait_count, SLE_UINT16)),
};
/** Save industry-type build data. */
static void Save_ITBL()
{
std::vector<SaveLoad> sld = SlTableHeader(_industrytype_builder_desc);
for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
SlSetArrayIndex(i);
SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
SlObjectSaveFiltered(_industry_builder.builddata + i, sld);
}
}
/** Load industry-type build data. */
static void Load_ITBL()
{
std::vector<SaveLoad> sld = SlTableHeaderOrRiff(_industrytype_builder_desc);
for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
_industry_builder.builddata[it].Reset();
}
int index;
while ((index = SlIterateArray()) != -1) {
if ((uint)index >= NUM_INDUSTRYTYPES) SlErrorCorrupt("Too many industry builder datas");
SlObject(_industry_builder.builddata + index, _industrytype_builder_desc);
SlObjectLoadFiltered(_industry_builder.builddata + index, sld);
}
}
@ -180,8 +190,8 @@ static const ChunkHandler industry_chunk_handlers[] = {
{ 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, nullptr, CH_ARRAY },
{ 'IIDS', Save_IIDS, Load_IIDS, nullptr, nullptr, CH_TABLE },
{ 'TIDS', Save_TIDS, Load_TIDS, nullptr, nullptr, CH_TABLE },
{ 'IBLD', LoadSave_IBLD, LoadSave_IBLD, nullptr, nullptr, CH_RIFF },
{ 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_ARRAY },
{ 'IBLD', Save_IBLD, Load_IBLD, nullptr, nullptr, CH_TABLE },
{ 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_TABLE },
};
extern const ChunkHandlerTable _industry_chunk_handlers(industry_chunk_handlers);

Loading…
Cancel
Save