From 88edfd4ef16bedd98a07a2142e693ab50fbdcef2 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 6 Jun 2021 09:59:33 +0200 Subject: Change: rework several CH_RIFF chunks to use CH_ARRAY instead This adds two byte extra to those chunks, and might feel a bit silly at first. But in later changes we will prefix CH_ARRAY with a table header, and then this change shines. Without this, we could still add headers to these chunks, but any external reader wouldn't know if the CH_RIFF has them or not. This way is much more practical, as they are now more like any other chunk. --- src/saveload/economy_sl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/saveload/economy_sl.cpp') diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp index 82e3014ad..7a0f536b2 100644 --- a/src/saveload/economy_sl.cpp +++ b/src/saveload/economy_sl.cpp @@ -51,13 +51,17 @@ static const SaveLoad _economy_desc[] = { /** Economy variables */ static void Save_ECMY() { + SlSetArrayIndex(0); SlObject(&_economy, _economy_desc); } /** Economy variables */ static void Load_ECMY() { + if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return; SlObject(&_economy, _economy_desc); + if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many ECMY entries"); + StartupIndustryDailyChanges(IsSavegameVersionBefore(SLV_102)); // old savegames will need to be initialized } @@ -98,7 +102,7 @@ static const ChunkHandler economy_chunk_handlers[] = { { 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_ARRAY }, { 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_RIFF }, { 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_RIFF }, - { 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_RIFF }, + { 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_ARRAY }, }; extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers); -- cgit v1.2.3-70-g09d2