@@ -64,12 +64,20 @@ GRFConfig::GRFConfig(const GRFConfig &co
param_info(config.param_info),
has_param_defaults(config.has_param_defaults)
{
}
/**
* Return whether this NewGRF can replace an older version of the same NewGRF.
*/
bool GRFConfig::IsCompatible(uint32_t old_version) const
return this->min_loadable_version <= old_version && old_version <= this->version;
* Copy the parameter information from the \a src config.
* @param src Source config.
void GRFConfig::CopyParams(const GRFConfig &src)
this->num_params = src.num_params;
@@ -682,13 +690,13 @@ const GRFConfig *FindGRFConfig(uint32_t
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 != nullptr || mode == FGCM_ANY) return c;
/* Skip incompatible stuff, unless explicitly allowed */
if (mode != FGCM_NEWEST && HasBit(c->flags, GCF_INVALID)) continue;
/* check version compatibility */
if (mode == FGCM_COMPATIBLE && (c->version < desired_version || c->min_loadable_version > desired_version)) continue;
if (mode == FGCM_COMPATIBLE && !c->IsCompatible(desired_version)) continue;
/* remember the newest one as "the best" */
if (best == nullptr || c->version > best->version) best = c;
return best;
@@ -170,12 +170,13 @@ struct GRFConfig : ZeroedMemoryAllocator
uint8_t palette; ///< GRFPalette, bitset
std::vector<std::optional<GRFParameterInfo>> param_info; ///< NOSAVE: extra information about the parameters
bool has_param_defaults; ///< NOSAVE: did this newgrf specify any defaults for it's parameters
struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
bool IsCompatible(uint32_t old_version) const;
void CopyParams(const GRFConfig &src);
std::optional<std::string> GetTextfile(TextfileType type) const;
const char *GetName() const;
const char *GetDescription() const;
const char *GetURL() const;
@@ -720,13 +720,17 @@ struct NewGRFWindow : public Window, New
if (iter == grfid_map.end() || iter->second->version >= a->version) continue;
GRFConfig **c = &this->actives;
while (*c != iter->second) c = &(*c)->next;
GRFConfig *d = new GRFConfig(*a);
d->next = (*c)->next;
if (d->IsCompatible((*c)->version)) {
d->CopyParams(**c);
} else {
d->SetParameterDefaults();
if (this->active_sel == *c) {
CloseWindowByClass(WC_GRF_PARAMETERS);
CloseWindowByClass(WC_TEXTFILE);
this->active_sel = nullptr;
delete *c;
Status change: