diff options
author | frosch <frosch@openttd.org> | 2010-10-17 12:12:13 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-10-17 12:12:13 +0000 |
commit | 3972c790c2cba8c4c01ac6536e8675808f6e1c4d (patch) | |
tree | 09e55bb7f156c3cd331ee37683595583d88a2625 /src/newgrf_config.cpp | |
parent | 918da8432ae709e002448c947550674e1f4ae278 (diff) | |
download | openttd-3972c790c2cba8c4c01ac6536e8675808f6e1c4d.tar.xz |
(svn r20957) -Codechange: Add another parameter to FindGRFConfig() to define search restrictions.
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r-- | src/newgrf_config.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index eaadd6143..6e32fe054 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -442,13 +442,13 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig) GRFListCompatibility res = GLC_ALL_GOOD; for (GRFConfig *c = grfconfig; c != NULL; c = c->next) { - const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum); + const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, c->ident.md5sum); if (f == NULL) { char buf[256]; /* 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->ident.grfid); + f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE); if (f != NULL) { 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->filename, buf); @@ -614,15 +614,20 @@ void ScanNewGRFFiles() /** * Find a NewGRF in the scanned list. * @param grfid GRFID to look for, - * @param md5sum Expected MD5 sum (set to \c NULL if not relevant). + * @param mode Restrictions for matching grfs + * @param md5sum Expected MD5 sum * @return The matching grf, if it exists in #_all_grfs, else \c NULL. */ -const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum) +const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum) { + assert((mode == FGCM_EXACT) != (md5sum == NULL)); const GRFConfig *best = NULL; for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) { + /* if md5sum is set, we look for an exact match and continue if not found */ if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue; - if (md5sum != NULL) return c; + /* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */ + if (md5sum != NULL || mode == FGCM_ANY) return c; + /* remember the newest one as "the best" */ if (best == NULL || c->version > best->version) best = c; } |