From b438380a1e681e49f471402d614dcdef3c8a3a45 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 29 Jun 2021 18:48:39 +0100 Subject: [PATCH] Add station cargo history save/load support --- src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/saveload/station_sl.cpp | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index ec53a3fde9..fa4d0b3d51 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -151,6 +151,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_WATER_FLOODING, XSCF_NULL, 2, 2, "water_flooding", nullptr, nullptr, nullptr }, { XSLFI_MORE_HOUSES, XSCF_NULL, 2, 2, "more_houses", nullptr, nullptr, nullptr }, { XSLFI_CUSTOM_TOWN_ZONE, XSCF_IGNORABLE_UNKNOWN, 1, 1, "custom_town_zone", nullptr, nullptr, nullptr }, + { XSLFI_STATION_CARGO_HISTORY, XSCF_NULL, 1, 1, "station_cargo_history", nullptr, nullptr, nullptr }, { XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index 1cc9c89de1..bd347e754f 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -105,6 +105,7 @@ enum SlXvFeatureIndex { XSLFI_WATER_FLOODING, ///< Water flooding map bit XSLFI_MORE_HOUSES, ///< More house types XSLFI_CUSTOM_TOWN_ZONE, ///< Custom town zones + XSLFI_STATION_CARGO_HISTORY, ///< Station waiting cargo history 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 diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 4a6a63787b..0572d55ba0 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -459,6 +459,7 @@ static const SaveLoad _station_desc[] = { SLE_CONDVAR(Station, always_accepted, SLE_FILE_U32 | SLE_VAR_U64, SLV_127, SLV_EXTEND_CARGOTYPES), SLE_CONDVAR(Station, always_accepted, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), SLE_CONDNULL_X(32 * 24, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_JOKERPP, SL_JOKER_1_22)), + SLE_CONDVAR_X(Station, station_cargo_history_cargoes, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_STATION_CARGO_HISTORY)), SLE_END() }; @@ -547,6 +548,17 @@ static void RealSave_STNN(BaseStation *bst) SlObjectSaveFiltered(const_cast(&(*it)), _cargo_list_desc); // _cargo_list_desc has no conditionals } } + + assert(st->station_cargo_history.size() == CountBits(st->station_cargo_history_cargoes)); + dumper->CheckBytes(st->station_cargo_history.size() * MAX_STATION_CARGO_HISTORY_DAYS * 2); + for (const auto &history : st->station_cargo_history) { + uint i = st->station_cargo_history_offset; + do { + dumper->RawWriteUint16(history[i]); + i++; + if (i == MAX_STATION_CARGO_HISTORY_DAYS) i = 0; + } while (i != st->station_cargo_history_offset); + } } for (uint i = 0; i < bst->num_specs; i++) { @@ -656,6 +668,15 @@ static void Load_STNN() } if (SlXvIsFeatureMissing(XSLFI_ST_LAST_VEH_TYPE)) st->goods[i].last_vehicle_type = _old_last_vehicle_type; } + + st->station_cargo_history.resize(CountBits(st->station_cargo_history_cargoes)); + buffer->CheckBytes(st->station_cargo_history.size() * MAX_STATION_CARGO_HISTORY_DAYS * 2); + for (auto &history : st->station_cargo_history) { + for (uint16 &amount : history) { + amount = buffer->RawReadUint16(); + } + } + st->station_cargo_history_offset = 0; } if (bst->num_specs != 0) {