Saveload: Store NewGRF name in savegame, include in missing GRF message

pull/211/head
Jonathan G Rennison 3 years ago
parent d328f359c9
commit f0c3a4b42e

@ -616,7 +616,7 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
if (f != nullptr) {
md5sumToString(buf, lastof(buf), c->ident.md5sum);
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->GetDisplayPath(), buf);
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s, name: '%s'. Compatibility mode on", BSWAP32(c->ident.grfid), c->GetDisplayPath(), buf, GetDefaultLangGRFStringFromGRFText(c->name));
if (!HasBit(c->flags, GCF_COMPATIBLE)) {
/* Preserve original_md5sum after it has been assigned */
SetBit(c->flags, GCF_COMPATIBLE);
@ -630,7 +630,7 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
/* No compatible grf was found, mark it as disabled */
md5sumToString(buf, lastof(buf), c->ident.md5sum);
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->GetDisplayPath(), buf);
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s, name: '%s'", BSWAP32(c->ident.grfid), c->GetDisplayPath(), buf, GetDefaultLangGRFStringFromGRFText(c->name));
c->status = GCS_NOT_FOUND;
res = GLC_NOT_FOUND;

@ -644,6 +644,21 @@ const char *GetGRFStringFromGRFText(const GRFTextList &text_list)
return default_text;
}
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list)
{
const char *default_text = nullptr;
for (const auto &text : text_list) {
/* If the current string is English or American, set it as the
* fallback language if the specific language isn't available. */
if (text.langid == GRFLX_UNSPECIFIED || (default_text == nullptr && (text.langid == GRFLX_ENGLISH || text.langid == GRFLX_AMERICAN))) {
default_text = text.text.c_str();
}
}
return default_text;
}
static std::array<std::pair<uint16, const char *>, 16> _grf_string_ptr_log;
static unsigned int _grf_string_ptr_log_next = 0;
@ -659,6 +674,11 @@ const char *GetGRFStringFromGRFText(const GRFTextWrapper &text)
return text ? GetGRFStringFromGRFText(*text) : nullptr;
}
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text)
{
return text ? GetDefaultLangGRFStringFromGRFText(*text) : nullptr;
}
/**
* Get a C-string from a stringid set by a newgrf.
*/

@ -36,6 +36,8 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_schem
StringID GetGRFStringID(uint32 grfid, StringID stringid);
const char *GetGRFStringFromGRFText(const GRFTextList &text_list);
const char *GetGRFStringFromGRFText(const GRFTextWrapper &text);
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextList &text_list);
const char *GetDefaultLangGRFStringFromGRFText(const GRFTextWrapper &text);
const char *GetGRFStringPtr(uint16 stringid);
void CleanUpStrings();
void SetCurrentGrfLangID(byte language_id);

@ -141,6 +141,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_ONE_WAY_ROAD_STATE, XSCF_NULL, 1, 1, "one_way_road_state", nullptr, nullptr, nullptr },
{ XSLFI_VENC_CHUNK, XSCF_IGNORABLE_ALL, 1, 1, "venc_chunk", nullptr, nullptr, "VENC" },
{ XSLFI_ANIMATED_TILE_EXTRA, XSCF_NULL, 1, 1, "animated_tile_extra", nullptr, nullptr, nullptr },
{ XSLFI_NEWGRF_INFO_EXTRA, XSCF_NULL, 1, 1, "newgrf_info_extra", nullptr, nullptr, nullptr },
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker
};

@ -95,6 +95,7 @@ enum SlXvFeatureIndex {
XSLFI_ONE_WAY_ROAD_STATE, ///< One-way road state cache
XSLFI_VENC_CHUNK, ///< VENC chunk
XSLFI_ANIMATED_TILE_EXTRA, ///< Animated tile extra info
XSLFI_NEWGRF_INFO_EXTRA, ///< Extra NewGRF info in savegame
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

@ -55,6 +55,7 @@ void Load_NewGRFMapping(OverrideManagerBase &mapping)
}
}
static std::string _grf_name;
static const SaveLoad _grfconfig_desc[] = {
SLE_STR(GRFConfig, filename, SLE_STR, 0x40),
@ -64,6 +65,7 @@ static const SaveLoad _grfconfig_desc[] = {
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80),
SLE_VAR(GRFConfig, num_params, SLE_UINT8),
SLE_CONDVAR(GRFConfig, palette, SLE_UINT8, SLV_101, SL_MAX_VERSION),
SLEG_CONDSSTR_X(_grf_name, 0, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_NEWGRF_INFO_EXTRA)),
SLE_END()
};
@ -75,6 +77,7 @@ static void Save_NGRF()
for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
if (HasBit(c->flags, GCF_STATIC)) continue;
SlSetArrayIndex(index++);
_grf_name = str_strip_all_scc(GetDefaultLangGRFStringFromGRFText(c->name));
SlObject(c, _grfconfig_desc);
}
}
@ -86,6 +89,9 @@ static void Load_NGRF_common(GRFConfig *&grfconfig)
while (SlIterateArray() != -1) {
GRFConfig *c = new GRFConfig();
SlObject(c, _grfconfig_desc);
if (SlXvIsFeaturePresent(XSLFI_NEWGRF_INFO_EXTRA)) {
AddGRFTextToList(c->name, 0x7F, c->ident.grfid, false, _grf_name.c_str());
}
if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette();
AppendToGRFConfigList(&grfconfig, c);
}

Loading…
Cancel
Save