* 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. */
| 594 | * @return The matching grf, if it exists in #_all_grfs, else \c nullptr. |
| 595 | */ |
| 596 | const 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. |
no test coverage detected