Saveload: Add corresponding upstream version to SLXI chunk

This commit is contained in:
Jonathan G Rennison 2023-03-07 18:40:53 +00:00
parent 2acc00ab13
commit 6aa8997eee
3 changed files with 27 additions and 0 deletions

View File

@ -310,6 +310,7 @@ static void WriteSavegameInfo(const char *name)
{
extern SaveLoadVersion _sl_version;
extern std::string _sl_xv_version_label;
extern uint16 _sl_xv_upstream_version;
uint32 last_ottd_rev = 0;
byte ever_modified = 0;
bool removed_newgrfs = false;
@ -331,6 +332,9 @@ static void WriteSavegameInfo(const char *name)
if (!_sl_xv_version_label.empty()) {
p += seprintf(p, lastof(buf), " Version label: %s\n", _sl_xv_version_label.c_str());
}
if (_sl_xv_upstream_version != SL_MIN_VERSION) {
p += seprintf(p, lastof(buf), " Upstream version: %u\n", _sl_xv_upstream_version);
}
for (size_t i = 0; i < XSLFI_SIZE; i++) {
if (_sl_xv_feature_versions[i] > 0) {
p += seprintf(p, lastof(buf), " Feature: %s = %d\n", SlXvGetFeatureName((SlXvFeatureIndex) i), _sl_xv_feature_versions[i]);

View File

@ -60,16 +60,20 @@ bool _sl_maybe_chillpp; ///< is this poss
bool _sl_upstream_mode; ///< load game using upstream loader
std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks IDs which we can discard if no chunk loader exists
std::string _sl_xv_version_label; ///< optional SLXI version label
SaveLoadVersion _sl_xv_upstream_version; ///< optional SLXI upstream version
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version of SLXI chunk
static void loadVL(const SlxiSubChunkInfo *info, uint32 length);
static uint32 saveVL(const SlxiSubChunkInfo *info, bool dry_run);
static void loadUV(const SlxiSubChunkInfo *info, uint32 length);
static uint32 saveUV(const SlxiSubChunkInfo *info, bool dry_run);
static void loadLC(const SlxiSubChunkInfo *info, uint32 length);
static uint32 saveLC(const SlxiSubChunkInfo *info, bool dry_run);
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_VERSION_LABEL, XSCF_IGNORABLE_ALL, 1, 1, "version_label", saveVL, loadVL, nullptr },
{ XSLFI_UPSTREAM_VERSION, XSCF_NULL, 1, 1, "upstream_version", saveUV, loadUV, nullptr },
{ XSLFI_TRACE_RESTRICT, XSCF_NULL, 15, 15, "tracerestrict", nullptr, nullptr, "TRRM,TRRP,TRRS" },
{ XSLFI_TRACE_RESTRICT_OWNER, XSCF_NULL, 1, 1, "tracerestrict_owner", nullptr, nullptr, nullptr },
{ XSLFI_TRACE_RESTRICT_ORDRCND, XSCF_NULL, 4, 4, "tracerestrict_order_cond", nullptr, nullptr, nullptr },
@ -254,6 +258,7 @@ void SlXvResetState()
_sl_xv_discardable_chunk_ids.clear();
std::fill(_sl_xv_feature_versions.begin(), _sl_xv_feature_versions.end(), 0);
_sl_xv_version_label.clear();
_sl_xv_upstream_version = SL_MIN_VERSION;
}
/**
@ -695,6 +700,23 @@ static uint32 saveVL(const SlxiSubChunkInfo *info, bool dry_run)
return static_cast<uint32>(length);
}
static void loadUV(const SlxiSubChunkInfo *info, uint32 length)
{
if (length == 2) {
_sl_xv_upstream_version = (SaveLoadVersion)SlReadUint16();
DEBUG(sl, 2, "SLXI upstream version: %u", _sl_xv_upstream_version);
} else {
DEBUG(sl, 1, "SLXI chunk: feature: '%s', version: %d, has data of wrong length: %u", info->name, _sl_xv_feature_versions[info->index], length);
ReadBuffer::GetCurrent()->SkipBytes(length);
}
}
static uint32 saveUV(const SlxiSubChunkInfo *info, bool dry_run)
{
if (!dry_run) SlWriteUint16(SL_MAX_VERSION - 1);
return 2;
}
static void loadLC(const SlxiSubChunkInfo *info, uint32 length)
{
if (length == 1) {

View File

@ -24,6 +24,7 @@ enum SaveLoadVersion : uint16;
enum SlXvFeatureIndex {
XSLFI_NULL = 0, ///< Unused value, to indicate that no extended feature test is in use
XSLFI_VERSION_LABEL, ///< Version label
XSLFI_UPSTREAM_VERSION, ///< Corresponding upstream savegame version
XSLFI_TRACE_RESTRICT, ///< Trace restrict
XSLFI_TRACE_RESTRICT_OWNER, ///< Trace restrict: train owner test
XSLFI_TRACE_RESTRICT_ORDRCND, ///< Trace restrict: slot conditional order