|
@@ -115,43 +115,46 @@ void ClearGRFConfigList(GRFConfig **conf
|
|
|
GRFConfig *c, *next;
|
|
|
for (c = *config; c != NULL; c = next) {
|
|
|
next = c->next;
|
|
|
ClearGRFConfig(&c);
|
|
|
}
|
|
|
*config = NULL;
|
|
|
}
|
|
|
|
|
|
|
|
|
/** Copy a GRF Config list
|
|
|
* @param dst pointer to destination list
|
|
|
* @param src pointer to source list values
|
|
|
* @param init_only the copied GRF will be processed up to GLS_INIT
|
|
|
* @return pointer to the last value added to the destination list */
|
|
|
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
|
|
|
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
|
|
|
{
|
|
|
/* Clear destination as it will be overwritten */
|
|
|
ClearGRFConfigList(dst);
|
|
|
for (; src != NULL; src = src->next) {
|
|
|
GRFConfig *c = CallocT<GRFConfig>(1);
|
|
|
*c = *src;
|
|
|
if (src->filename != NULL) c->filename = strdup(src->filename);
|
|
|
if (src->full_path != NULL) c->full_path = strdup(src->full_path);
|
|
|
if (src->name != NULL) c->name = strdup(src->name);
|
|
|
if (src->info != NULL) c->info = strdup(src->info);
|
|
|
if (src->error != NULL) {
|
|
|
c->error = CallocT<GRFError>(1);
|
|
|
memcpy(c->error, src->error, sizeof(GRFError));
|
|
|
if (src->error->data != NULL) c->error->data = strdup(src->error->data);
|
|
|
if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
|
|
|
}
|
|
|
|
|
|
if (init_only) SETBIT(c->flags, GCF_INIT_ONLY);
|
|
|
|
|
|
*dst = c;
|
|
|
dst = &c->next;
|
|
|
}
|
|
|
|
|
|
return dst;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Removes duplicates from lists of GRFConfigs. These duplicates
|
|
|
* are introduced when the _grfconfig_static GRFs are appended
|
|
|
* to the _grfconfig on a newgame or savegame. As the parameters
|
|
|
* of the static GRFs could be different that the parameters of
|
|
@@ -181,52 +184,45 @@ static void RemoveDuplicatesFromGRFConfi
|
|
|
RemoveDuplicatesFromGRFConfigList(list->next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Appends the static GRFs to a list of GRFs
|
|
|
* @param dst the head of the list to add to
|
|
|
*/
|
|
|
void AppendStaticGRFConfigs(GRFConfig **dst)
|
|
|
{
|
|
|
GRFConfig **tail = dst;
|
|
|
while (*tail != NULL) tail = &(*tail)->next;
|
|
|
|
|
|
CopyGRFConfigList(tail, _grfconfig_static);
|
|
|
CopyGRFConfigList(tail, _grfconfig_static, false);
|
|
|
RemoveDuplicatesFromGRFConfigList(*dst);
|
|
|
}
|
|
|
|
|
|
/** Appends an element to a list of GRFs
|
|
|
* @param dst the head of the list to add to
|
|
|
* @param el the new tail to be */
|
|
|
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
|
|
|
{
|
|
|
GRFConfig **tail = dst;
|
|
|
while (*tail != NULL) tail = &(*tail)->next;
|
|
|
*tail = el;
|
|
|
|
|
|
RemoveDuplicatesFromGRFConfigList(*dst);
|
|
|
}
|
|
|
|
|
|
|
|
|
/* Reset the current GRF Config to either blank or newgame settings */
|
|
|
void ResetGRFConfig(bool defaults)
|
|
|
{
|
|
|
GRFConfig **c = &_grfconfig;
|
|
|
|
|
|
if (defaults) {
|
|
|
c = CopyGRFConfigList(c, _grfconfig_newgame);
|
|
|
} else {
|
|
|
ClearGRFConfigList(c);
|
|
|
}
|
|
|
|
|
|
CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults);
|
|
|
AppendStaticGRFConfigs(&_grfconfig);
|
|
|
}
|
|
|
|
|
|
|
|
|
/** Check if all GRFs in the GRF config from a savegame can be loaded.
|
|
|
* @return will return any of the following 3 values:<br>
|
|
|
* <ul>
|
|
|
* <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded
|
|
|
* <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a
|
|
|
* compatible GRF with the same grfid was found and used instead
|
|
|
* <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all
|
|
|
* </ul> */
|