Changeset - r6873:011bb2269607
[Not reviewed]
master
0 6 0
maedhros - 17 years ago 2007-06-12 13:22:14
maedhros@openttd.org
(svn r10114) -Fix: Only load newgrf error messages if the language matches the current
language. Since only one error can be loaded anyway, if the language didn't
match you'd get "Undefined string". Also since we're only loading one language
there's no need to use AddGRFString any more.
6 files changed with 41 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include "spritecache.h"
 
#include "station.h"
 
#include "sprite.h"
 
#include "newgrf.h"
 
#include "variables.h"
 
#include "string.h"
 
#include "strings.h"
 
#include "table/strings.h"
 
#include "bridge.h"
 
#include "town.h"
 
#include "economy.h"
 
#include "newgrf_engine.h"
 
#include "vehicle.h"
 
@@ -3409,32 +3410,26 @@ static void GRFLoadError(byte *buf, int 
 
		STR_NEWGRF_ERROR_MSG_INFO,
 
		STR_NEWGRF_ERROR_MSG_WARNING,
 
		STR_NEWGRF_ERROR_MSG_ERROR,
 
		STR_NEWGRF_ERROR_MSG_FATAL
 
	};
 

	
 
	/* AddGRFString expects the string to be referred to by an id in the newgrf
 
	 * file. Errors messages are never referred to however, so invent ids that
 
	 * are unlikely to be reached in a newgrf file so they don't overwrite
 
	 * anything else. */
 
	enum {
 
		MESSAGE_STRING_ID = MAX_UVALUE(StringID) - 1,
 
		MESSAGE_DATA_ID   = MAX_UVALUE(StringID)
 
	};
 

	
 
	if (!check_length(len, 6, "GRFLoadError")) return;
 

	
 
	/* For now we can only show one message per newgrf file. */
 
	if (_cur_grfconfig->error != NULL) return;
 

	
 
	buf++; // Skip the action byte.
 
	byte severity   = grf_load_byte(&buf);
 
	byte lang       = grf_load_byte(&buf);
 
	byte message_id = grf_load_byte(&buf);
 
	len -= 4;
 

	
 
	/* Skip the error if it isn't valid for the current language. */
 
	if (!CheckGrfLangID(lang, _cur_grffile->grf_version)) return;
 

	
 
	/* Skip the error until the activation stage unless bit 7 of the severity
 
	 * is set. */
 
	if (!HASBIT(severity, 7) && _cur_stage == GLS_INIT) {
 
		grfmsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur_stage);
 
		return;
 
	}
 
@@ -3458,32 +3453,31 @@ static void GRFLoadError(byte *buf, int 
 

	
 
	if (len <= 1) {
 
		grfmsg(7, "GRFLoadError: No message data supplied.");
 
		return;
 
	}
 

	
 
	bool new_scheme = _cur_grffile->grf_version >= 7;
 
	GRFError *error = CallocT<GRFError>(1);
 

	
 
	error->severity = sevstr[severity];
 

	
 
	if (message_id == 0xFF) {
 
		/* This is a custom error message. */
 
		const char *message = grf_load_string(&buf, len);
 
		len -= (strlen(message) + 1);
 

	
 
		error->message = AddGRFString(_cur_grffile->grfid, MESSAGE_STRING_ID, lang, new_scheme, message, STR_UNDEFINED);
 
		error->custom_message = TranslateTTDPatchCodes(message);
 
	} else {
 
		error->message = msgstr[message_id];
 
	}
 

	
 
	if (len > 0) {
 
		const char *data = grf_load_string(&buf, len);
 
		len -= (strlen(data) + 1);
 

	
 
		error->data = AddGRFString(_cur_grffile->grfid, MESSAGE_DATA_ID, lang, new_scheme, data, STR_UNDEFINED);
 
		error->data = TranslateTTDPatchCodes(data);
 
	}
 

	
 
	/* Only two parameter numbers can be used in the string. */
 
	uint i = 0;
 
	for (; i < 2 && len > 0; i++) {
 
		error->param_number[i] = grf_load_byte(&buf);
 
@@ -4113,14 +4107,18 @@ static void TranslateGRFStrings(byte *bu
 
	}
 

	
 
	if (c->status == GCS_INITIALISED) {
 
		/* If the file is not active but will be activated later, give an error
 
		 * and disable this file. */
 
		GRFError *error = CallocT<GRFError>(1);
 

	
 
		char tmp[256];
 
		GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
 
		error->data = strdup(tmp);
 

	
 
		error->message  = STR_NEWGRF_ERROR_LOAD_AFTER;
 
		error->data     = STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE;
 
		error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 

	
 
		if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error);
 
		_cur_grfconfig->error = error;
 

	
 
		_cur_grfconfig->status = GCS_DISABLED;
 
@@ -4399,12 +4397,14 @@ static void ResetNewGRF()
 
}
 

	
 
static void ResetNewGRFErrors()
 
{
 
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
 
		if (!HASBIT(c->flags, GCF_COPY) && c->error != NULL) {
 
			free(c->error->custom_message);
 
			free(c->error->data);
 
			free(c->error);
 
			c->error = NULL;
 
		}
 
	}
 
}
 

	
src/newgrf_config.cpp
Show inline comments
 
@@ -94,13 +94,18 @@ 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)->full_path);
 
		free((*config)->name);
 
		free((*config)->info);
 
		free((*config)->error);
 

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

	
 

	
 
@@ -131,12 +136,14 @@ GRFConfig **CopyGRFConfigList(GRFConfig 
 
		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);
 
		}
 

	
 
		*dst = c;
 
		dst = &c->next;
 
	}
 

	
src/newgrf_config.h
Show inline comments
 
@@ -33,14 +33,15 @@ enum GRFListCompatibility{
 
struct GRFIdentifier {
 
	uint32 grfid;
 
	uint8 md5sum[16];
 
};
 

	
 
struct GRFError {
 
	char *custom_message;
 
	char *data;
 
	StringID message;
 
	StringID data;
 
	StringID severity;
 
	uint8 num_params;
 
	uint8 param_number[2];
 
};
 

	
 
struct GRFConfig : public GRFIdentifier {
src/newgrf_gui.cpp
Show inline comments
 
@@ -45,24 +45,24 @@ static int parse_intlist(const char *p, 
 
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params)
 
{
 
	char buff[256];
 

	
 
	if (c->error != NULL) {
 
		SetDParamStr(0, c->filename);
 
		SetDParam(1, c->error->data);
 
		SetDParamStr(1, c->error->data);
 
		for (uint i = 0; i < c->error->num_params; i++) {
 
			uint32 param = 0;
 
			byte param_number = c->error->param_number[i];
 

	
 
			if (param_number < c->num_params) param = c->param[param_number];
 

	
 
			SetDParam(2 + i, param);
 
		}
 

	
 
		char message[512];
 
		GetString(message, c->error->message, lastof(message));
 
		GetString(message, c->error->custom_message != NULL ? BindCString(c->error->custom_message) : c->error->message, lastof(message));
 

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

	
 
	/* Draw filename or not if it is not known (GRF sent over internet) */
src/newgrf_text.cpp
Show inline comments
 
@@ -442,12 +442,26 @@ void SetCurrentGrfLangID(const char *iso
 
			break;
 
		}
 
	}
 
	_currentLangID = ret;
 
}
 

	
 
bool CheckGrfLangID(byte lang_id, byte grf_version)
 
{
 
	if (grf_version < 7) {
 
		switch (_currentLangID) {
 
			case GRFLX_GERMAN:  return (lang_id & GRFLB_GERMAN)  != 0;
 
			case GRFLX_FRENCH:  return (lang_id & GRFLB_FRENCH)  != 0;
 
			case GRFLX_SPANISH: return (lang_id & GRFLB_SPANISH) != 0;
 
			default:            return (lang_id & (GRFLB_ENGLISH | GRFLB_AMERICAN)) != 0;
 
		}
 
	}
 

	
 
	return (lang_id == _currentLangID || lang_id == GRFLX_UNSPECIFIED);
 
}
 

	
 
/**
 
 * House cleaning.
 
 * Remove all strings and reset the text counter.
 
 */
 
void CleanUpStrings()
 
{
src/newgrf_text.h
Show inline comments
 
@@ -10,7 +10,9 @@ StringID AddGRFString(uint32 grfid, uint
 
StringID GetGRFStringID(uint32 grfid, uint16 stringid);
 
char *GetGRFString(char *buff, uint16 stringid, const char* last);
 
void CleanUpStrings();
 
void SetCurrentGrfLangID(const char *iso_name);
 
char *TranslateTTDPatchCodes(const char *str);
 

	
 
bool CheckGrfLangID(byte lang_id, byte grf_version);
 

	
 
#endif /* NEWGRF_TEXT_H */
0 comments (0 inline, 0 general)