File diff r14661:a054577a92e2 → r14662:8798e984ee81
src/newgrf_config.cpp
Show inline comments
 
@@ -17,24 +17,35 @@
 
#include "network/network_func.h"
 
#include "gfx_func.h"
 

	
 
#include "fileio_func.h"
 
#include "fios.h"
 

	
 

	
 
GRFConfig *_all_grfs;
 
GRFConfig *_grfconfig;
 
GRFConfig *_grfconfig_newgame;
 
GRFConfig *_grfconfig_static;
 

	
 
GRFError::GRFError(StringID severity, StringID message) :
 
	message(message),
 
	severity(severity)
 
{
 
}
 

	
 
GRFError::~GRFError()
 
{
 
	free(this->custom_message);
 
	free(this->data);
 
 }
 

	
 
/**
 
 * Update the palettes of the graphics from the config file.
 
 * This is needed because the config file gets read and parsed
 
 * before the palette is chosen (one can configure the base
 
 * graphics set governing the palette in the config after all).
 
 * As a result of this we update the settings from the config
 
 * once we have determined the palette.
 
 */
 
void UpdateNewGRFConfigPalette()
 
{
 
	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->windows_paletted = (_use_palette == PAL_WINDOWS);
 
@@ -92,30 +103,25 @@ bool FillGRFDetails(GRFConfig *config, b
 

	
 
	return CalcGRFMD5Sum(config);
 
}
 

	
 

	
 
void ClearGRFConfig(GRFConfig **config)
 
{
 
	/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
 
	if (!HasBit((*config)->flags, GCF_COPY)) {
 
		free((*config)->filename);
 
		free((*config)->name);
 
		free((*config)->info);
 

	
 
		if ((*config)->error != NULL) {
 
			free((*config)->error->custom_message);
 
			free((*config)->error->data);
 
			free((*config)->error);
 
		}
 
		delete (*config)->error;
 
	}
 
	free(*config);
 
	*config = NULL;
 
}
 

	
 

	
 
/* Clear a GRF Config list */
 
void ClearGRFConfigList(GRFConfig **config)
 
{
 
	GRFConfig *c, *next;
 
	for (c = *config; c != NULL; c = next) {
 
		next = c->next;
 
@@ -130,26 +136,27 @@ void ClearGRFConfigList(GRFConfig **conf
 
 * @param c the grfconfig to copy
 
 * @return A pointer to a new grfconfig that's a copy of the original
 
 */
 
GRFConfig *DuplicateGRFConfig(const GRFConfig *c)
 
{
 
	GRFConfig *config = MallocT<GRFConfig>(1);
 
	*config = *c;
 

	
 
	if (c->filename != NULL) config->filename = strdup(c->filename);
 
	if (c->name     != NULL) config->name = strdup(c->name);
 
	if (c->info     != NULL) config->info = strdup(c->info);
 
	if (c->error    != NULL) {
 
		config->error = MallocT<GRFError>(1);
 
		memcpy(config->error, c->error, sizeof(GRFError));
 
		config->error = new GRFError(c->error->severity, c->error->message);
 
		config->error->num_params = c->error->num_params;
 
		memcpy(config->error->param_value, c->error->param_value, sizeof(config->error->param_value));
 
		if (c->error->data           != NULL) config->error->data = strdup(c->error->data);
 
		if (c->error->custom_message != NULL) config->error->custom_message = strdup(c->error->custom_message);
 
	}
 

	
 
	ClrBit(config->flags, GCF_COPY);
 

	
 
	return config;
 
}
 

	
 
/** Copy a GRF Config list
 
 * @param dst pointer to destination list
 
 * @param src pointer to source list values