diff options
author | frosch <frosch@openttd.org> | 2010-10-17 12:12:52 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-10-17 12:12:52 +0000 |
commit | e805919fe9f8becadbc0e41dd018173a9c18a99f (patch) | |
tree | 9e23c445fcee51857db6b2887a6d73a012867c6d /src | |
parent | 3972c790c2cba8c4c01ac6536e8675808f6e1c4d (diff) | |
download | openttd-e805919fe9f8becadbc0e41dd018173a9c18a99f.tar.xz |
(svn r20958) -Add: the concept of min-loadable-version to NewGRFs when choosing compatbile NewGRFs. (planetmaker)
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_config.cpp | 8 | ||||
-rw-r--r-- | src/newgrf_config.h | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 6e32fe054..b951ebfe2 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -448,7 +448,7 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig) /* 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, FGCM_COMPATIBLE); + f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, NULL, c->version); 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); @@ -485,6 +485,7 @@ compatible_grf: if (c->info == NULL) c->info = DuplicateGRFText(f->info); c->error = NULL; c->version = f->version; + c->min_loadable_version = f->min_loadable_version; c->num_valid_params = f->num_valid_params; c->has_param_defaults = f->has_param_defaults; for (uint i = 0; i < f->param_info.Length(); i++) { @@ -616,9 +617,10 @@ void ScanNewGRFFiles() * @param grfid GRFID to look for, * @param mode Restrictions for matching grfs * @param md5sum Expected MD5 sum + * @param desired_version Requested version * @return The matching grf, if it exists in #_all_grfs, else \c NULL. */ -const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum) +const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version) { assert((mode == FGCM_EXACT) != (md5sum == NULL)); const GRFConfig *best = NULL; @@ -627,6 +629,8 @@ const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue; /* 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; + /* check version compatibility */ + if (mode == FGCM_COMPATIBLE && (c->version < desired_version || c->min_loadable_version > desired_version)) continue; /* remember the newest one as "the best" */ if (best == NULL || c->version > best->version) best = c; } diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 085791282..7dfa06ac6 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -143,6 +143,7 @@ struct GRFConfig : ZeroedMemoryAllocator { GRFError *error; ///< NOSAVE: Error/Warning during GRF loading (Action 0x0B) uint32 version; ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown + uint32 min_loadable_version; ///< NOSAVE: Minimum compatible version a NewGRF can define uint8 flags; ///< NOSAVE: GCF_Flags, bitset GRFStatus status; ///< NOSAVE: GRFStatus, enum uint32 grf_bugs; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs @@ -167,7 +168,7 @@ struct GRFConfig : ZeroedMemoryAllocator { /** Method to find GRFs using FindGRFConfig */ enum FindGRFConfigMode { FGCM_EXACT, ///< Only find Grfs matching md5sum - FGCM_COMPATIBLE, ///< Find best compatible + FGCM_COMPATIBLE, ///< Find best compatible Grf wrt. desired_version FGCM_NEWEST, ///< Find newest Grf FGCM_ANY, ///< Use first found }; @@ -179,7 +180,7 @@ extern GRFConfig *_grfconfig_static; ///< First item in list of static GRF set void ScanNewGRFFiles(); void CheckForMissingSprites(); -const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL); +const GRFConfig *FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum = NULL, uint32 desired_version = 0); GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF); GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only); void AppendStaticGRFConfigs(GRFConfig **dst); |