Changeset - r18943:3e25b87ea626
[Not reviewed]
master
0 4 0
frosch - 12 years ago 2012-01-15 17:33:35
frosch@openttd.org
(svn r23807) -Codechange: GRFError::num_params is not needed, remove it.
4 files changed with 4 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -6174,54 +6174,52 @@ static void GRFLoadError(ByteReader *buf
 
	if (message_id == 0xFF) {
 
		/* This is a custom error message. */
 
		if (buf->HasData()) {
 
			const char *message = buf->ReadString();
 

	
 
			error->custom_message = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, message);
 
		} else {
 
			grfmsg(7, "GRFLoadError: No custom message supplied.");
 
			error->custom_message = strdup("");
 
		}
 
	} else {
 
		error->message = msgstr[message_id];
 
	}
 

	
 
	if (buf->HasData()) {
 
		const char *data = buf->ReadString();
 

	
 
		error->data = TranslateTTDPatchCodes(_cur.grffile->grfid, lang, true, data);
 
	} else {
 
		grfmsg(7, "GRFLoadError: No message data supplied.");
 
		error->data = strdup("");
 
	}
 

	
 
	/* Only two parameter numbers can be used in the string. */
 
	uint i = 0;
 
	for (; i < 2 && buf->HasData(); i++) {
 
	for (uint i = 0; i < lengthof(error->param_value) && buf->HasData(); i++) {
 
		uint param_number = buf->ReadByte();
 
		error->param_value[i] = _cur.grffile->GetParam(param_number);
 
	}
 
	error->num_params = i;
 

	
 
	_cur.grfconfig->error = error;
 
}
 

	
 
/* Action 0x0C */
 
static void GRFComment(ByteReader *buf)
 
{
 
	/* <0C> [<ignored...>]
 
	 *
 
	 * V ignored       Anything following the 0C is ignored */
 

	
 
	if (!buf->HasData()) return;
 

	
 
	const char *text = buf->ReadString();
 
	grfmsg(2, "GRFComment: %s", text);
 
}
 

	
 
/* Action 0x0D (GLS_SAFETYSCAN) */
 
static void SafeParamSet(ByteReader *buf)
 
{
 
	uint8 target = buf->ReadByte();
 

	
 
	/* Only writing GRF parameters is considered safe */
 
	if (target < 0x80) return;
src/newgrf_config.cpp
Show inline comments
 
@@ -167,50 +167,49 @@ GRFConfig *_all_grfs;
 
GRFConfig *_grfconfig;
 
GRFConfig *_grfconfig_newgame;
 
GRFConfig *_grfconfig_static;
 

	
 
/**
 
 * Construct a new GRFError.
 
 * @param severity The severity of this error.
 
 * @param message The actual error-string.
 
 */
 
GRFError::GRFError(StringID severity, StringID message) :
 
	message(message),
 
	severity(severity)
 
{
 
}
 

	
 
/**
 
 * Create a new GRFError that is a deep copy of an existing error message.
 
 * @param error The GRFError object to make a copy of.
 
 */
 
GRFError::GRFError(const GRFError &error) :
 
	ZeroedMemoryAllocator(),
 
	custom_message(error.custom_message),
 
	data(error.data),
 
	message(error.message),
 
	severity(error.severity),
 
	num_params(error.num_params)
 
	severity(error.severity)
 
{
 
	if (error.custom_message != NULL) this->custom_message = strdup(error.custom_message);
 
	if (error.data           != NULL) this->data           = strdup(error.data);
 
	memcpy(this->param_value, error.param_value, sizeof(this->param_value));
 
}
 

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

	
 
/**
 
 * Create a new empty GRFParameterInfo object.
 
 * @param nr The newgrf parameter that is changed.
 
 */
 
GRFParameterInfo::GRFParameterInfo(uint nr) :
 
	name(NULL),
 
	desc(NULL),
 
	type(PTYPE_UINT_ENUM),
 
	min_value(0),
 
	max_value(UINT32_MAX),
 
	def_value(0),
 
	param_nr(nr),
src/newgrf_config.h
Show inline comments
 
@@ -86,49 +86,48 @@ struct GRFIdentifier {
 
	/**
 
	 * Does the identification match the provided values?
 
	 * @param grfid  Expected grfid.
 
	 * @param md5sum Expected md5sum, may be \c NULL (in which case, do not check it).
 
	 * @return the object has the provided grfid and md5sum.
 
	 */
 
	inline bool HasGrfIdentifier(uint32 grfid, const uint8 *md5sum) const
 
	{
 
		if (this->grfid != grfid) return false;
 
		if (md5sum == NULL) return true;
 
		return memcmp(md5sum, this->md5sum, sizeof(this->md5sum)) == 0;
 
	}
 
};
 

	
 
/** Information about why GRF had problems during initialisation */
 
struct GRFError : ZeroedMemoryAllocator {
 
	GRFError(StringID severity, StringID message = 0);
 
	GRFError(const GRFError &error);
 
	~GRFError();
 

	
 
	char *custom_message;  ///< Custom message (if present)
 
	char *data;            ///< Additional data for message and custom_message
 
	StringID message;      ///< Default message
 
	StringID severity;     ///< Info / Warning / Error / Fatal
 
	uint8 num_params;      ///< Number of additinal parameters for message and custom_message (0, 1 or 2)
 
	uint32 param_value[2]; ///< Values of GRF parameters to show for message and custom_message
 
};
 

	
 
/** The possible types of a newgrf parameter. */
 
enum GRFParameterType {
 
	PTYPE_UINT_ENUM, ///< The parameter allows a range of numbers, each of which can have a special name
 
	PTYPE_BOOL,      ///< The parameter is either 0 or 1
 
	PTYPE_END,       ///< Invalid parameter type
 
};
 

	
 
/** Information about one grf parameter. */
 
struct GRFParameterInfo {
 
	GRFParameterInfo(uint nr);
 
	GRFParameterInfo(GRFParameterInfo &info);
 
	~GRFParameterInfo();
 
	struct GRFText *name;  ///< The name of this parameter
 
	struct GRFText *desc;  ///< The description of this parameter
 
	GRFParameterType type; ///< The type of this parameter
 
	uint32 min_value;      ///< The minimal value this parameter can have
 
	uint32 max_value;      ///< The maximal value of this parameter
 
	uint32 def_value;      ///< Default value of this parameter
 
	byte param_nr;         ///< GRF parameter to store content in
 
	byte first_bit;        ///< First bit to use in the GRF parameter
 
	byte num_bit;          ///< Number of bits to use for this parameter
src/newgrf_gui.cpp
Show inline comments
 
@@ -29,66 +29,66 @@
 
#include "fontcache.h"
 

	
 
#include "widgets/newgrf_widget.h"
 

	
 
#include "table/sprites.h"
 

	
 
/**
 
 * Show the first NewGRF error we can find.
 
 */
 
void ShowNewGRFError()
 
{
 
	/* Do not show errors when entering the main screen */
 
	if (_game_mode == GM_MENU) return;
 

	
 
	for (const GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
 
		/* We only want to show fatal errors */
 
		if (c->error == NULL || c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL) continue;
 

	
 
		SetDParam   (0, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING);
 
		SetDParamStr(1, c->error->custom_message);
 
		SetDParam   (2, STR_JUST_RAW_STRING);
 
		SetDParamStr(3, c->filename);
 
		SetDParam   (4, STR_JUST_RAW_STRING);
 
		SetDParamStr(5, c->error->data);
 
		for (uint i = 0; i < c->error->num_params; i++) {
 
		for (uint i = 0; i < lengthof(c->error->param_value); i++) {
 
			SetDParam(6 + i, c->error->param_value[i]);
 
		}
 
		ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
 
		break;
 
	}
 
}
 

	
 
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint bottom, bool show_params)
 
{
 
	if (c->error != NULL) {
 
		char message[512];
 
		SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
 
		SetDParam   (1, STR_JUST_RAW_STRING);
 
		SetDParamStr(2, c->filename);
 
		SetDParam   (3, STR_JUST_RAW_STRING);
 
		SetDParamStr(4, c->error->data);
 
		for (uint i = 0; i < c->error->num_params; i++) {
 
		for (uint i = 0; i < lengthof(c->error->param_value); i++) {
 
			SetDParam(5 + i, c->error->param_value[i]);
 
		}
 
		GetString(message, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
 

	
 
		SetDParamStr(0, message);
 
		y = DrawStringMultiLine(x, right, y, bottom, c->error->severity);
 
	}
 

	
 
	/* Draw filename or not if it is not known (GRF sent over internet) */
 
	if (c->filename != NULL) {
 
		SetDParamStr(0, c->filename);
 
		y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME);
 
	}
 

	
 
	/* Prepare and draw GRF ID */
 
	char buff[256];
 
	snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->ident.grfid));
 
	SetDParamStr(0, buff);
 
	y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
 

	
 
	if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
 
		SetDParam(0, c->version);
 
		y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_VERSION);
 
	}
0 comments (0 inline, 0 general)