MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FindGRFConfig

Function FindGRFConfig

src/newgrf_config.cpp:596–614  ·  view source on GitHub ↗

* Find a NewGRF in the scanned list. * @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 nullptr. */

Source from the content-addressed store, hash-verified

594 * @return The matching grf, if it exists in #_all_grfs, else \c nullptr.
595 */
596const GRFConfig *FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
597{
598 assert((mode == FGCM_EXACT) != (md5sum == nullptr));
599 const GRFConfig *best = nullptr;
600 for (const auto &c : _all_grfs) {
601 /* if md5sum is set, we look for an exact match and continue if not found */
602 if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue;
603 /* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
604 if (md5sum != nullptr || mode == FGCM_ANY) return c.get();
605 /* Skip incompatible stuff, unless explicitly allowed */
606 if (mode != FGCM_NEWEST && c->flags.Test(GRFConfigFlag::Invalid)) continue;
607 /* check version compatibility */
608 if (mode == FGCM_COMPATIBLE && !c->IsCompatible(desired_version)) continue;
609 /* remember the newest one as "the best" */
610 if (best == nullptr || c->version > best->version) best = c.get();
611 }
612
613 return best;
614}
615
616/**
617 * Retrieve a NewGRF from the current config by its grfid.

Callers 11

GRFLoadConfigFunction · 0.85
OnInvalidateDataMethod · 0.85
BuildAvailablesMethod · 0.85
AddGrfInfoFunction · 0.85
FormatToMethod · 0.85
IsGoodGRFConfigListFunction · 0.85
NetworkAfterNewGRFScanFunction · 0.85
HasGRFConfigFunction · 0.85
GetTextfileMethod · 0.85

Calls 4

HasGrfIdentifierMethod · 0.80
TestMethod · 0.80
IsCompatibleMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected