summaryrefslogtreecommitdiff
path: root/src/newgrf_config.cpp
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2007-01-13 17:42:50 +0000
committerDarkvater <darkvater@openttd.org>2007-01-13 17:42:50 +0000
commit66c5cde9816ae913051c9bb516798cac5aee28e9 (patch)
tree19f7c89441139abe8f37d5f10fbf1953686d9da5 /src/newgrf_config.cpp
parent3f168daee13cd537bf2e07e18e0f03ff654ee0d0 (diff)
downloadopenttd-66c5cde9816ae913051c9bb516798cac5aee28e9.tar.xz
(svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
-GRF Window colour-codes changed a bit: Static is now grey, and compatible GRF (found locally only based on GRFID) are shown in orange. Compatible GRF's also have an orange status/warning text saying they're not the original the game was saved with. -Loaded games with something amiss regarding GRF's will show an appropiate warning message.
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r--src/newgrf_config.cpp44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 22cccaee6..534509e89 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -195,24 +195,45 @@ void ResetGRFConfig(bool defaults)
}
-/* Check if all GRFs in the GRF Config can be loaded */
-bool IsGoodGRFConfigList(void)
+/** Check if all GRFs in the GRF config from a savegame can be loaded.
+ * @return will return any of the following 3 values:<br>
+ * <ul>
+ * <li> GCF_ACTIVATED: No problems occured, all GRF files were found and loaded
+ * <li> GCF_COMPATIBLE: For one or more GRF's no exact match was found, but a
+ * compatible GRF with the same grfid was found and used instead
+ * <li> GCF_NOT_FOUND: For one or more GRF's no match was found at all
+ * </ul> */
+GCF_Flags IsGoodGRFConfigList(void)
{
- bool res = true;
- GRFConfig *c;
+ GCF_Flags res = GCF_ACTIVATED;
- for (c = _grfconfig; c != NULL; c = c->next) {
+ for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
if (f == NULL) {
- char buf[512], *p = buf;
+ char buf[256], *p = buf;
+
+ /* If we have not found the exactly matching GRF try to find one with the
+ * same grfid, as it most likely is compatible */
+ f = FindGRFConfig(c->grfid);
+ if (f != NULL) {
+ md5sumToString(buf, lastof(buf), c->md5sum);
+ DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf);
+ SETBIT(c->flags, GCF_COMPATIBLE);
+
+ /* Non-found has precedence over compatibility load */
+ if (res != GCF_NOT_FOUND) res = GCF_COMPATIBLE;
+ goto compatible_grf;
+ }
- p += snprintf(p, lastof(buf) - p, "Couldn't find NewGRF %08X (%s) checksum ", BSWAP32(c->grfid), c->filename);
- md5sumToString(p, lastof(buf), c->md5sum);
- ShowInfo(buf);
+ /* No compatible grf was found, mark it as disabled */
+ md5sumToString(buf, lastof(buf), c->md5sum);
+ DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf);
- res = false;
+ SETBIT(c->flags, GCF_NOT_FOUND);
+ res = GCF_NOT_FOUND;
} else {
- DEBUG(grf, 1, "Loading GRF %08X from '%s'", BSWAP32(c->grfid), f->filename);
+compatible_grf:
+ DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename);
/* The filename could be the filename as in the savegame. As we need
* to load the GRF here, we need the correct filename, so overwrite that
* in any case and set the name and info when it is not set already.
@@ -221,6 +242,7 @@ bool IsGoodGRFConfigList(void)
if (!HASBIT(c->flags, GCF_COPY)) {
free(c->filename);
c->filename = strdup(f->filename);
+ memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum));
if (c->name == NULL) c->name = strdup(f->name);
if (c->info == NULL) c->info = strdup(f->info);
}