(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.
replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
maedhros 17 years ago
parent d1e71eb34e
commit 109dd33c4a

@ -18,6 +18,7 @@
#include "newgrf.h"
#include "variables.h"
#include "string.h"
#include "strings.h"
#include "table/strings.h"
#include "bridge.h"
#include "town.h"
@ -3412,15 +3413,6 @@ static void GRFLoadError(byte *buf, int len)
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. */
@ -3432,6 +3424,9 @@ static void GRFLoadError(byte *buf, int len)
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) {
@ -3461,7 +3456,6 @@ static void GRFLoadError(byte *buf, int len)
return;
}
bool new_scheme = _cur_grffile->grf_version >= 7;
GRFError *error = CallocT<GRFError>(1);
error->severity = sevstr[severity];
@ -3471,7 +3465,7 @@ static void GRFLoadError(byte *buf, int len)
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];
}
@ -3480,7 +3474,7 @@ static void GRFLoadError(byte *buf, int len)
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. */
@ -4116,8 +4110,12 @@ static void TranslateGRFStrings(byte *buf, int len)
/* 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);
@ -4402,6 +4400,8 @@ 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;
}

@ -97,7 +97,12 @@ void ClearGRFConfig(GRFConfig **config)
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;
@ -134,6 +139,8 @@ GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src)
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;

@ -36,8 +36,9 @@ struct GRFIdentifier {
};
struct GRFError {
char *custom_message;
char *data;
StringID message;
StringID data;
StringID severity;
uint8 num_params;
uint8 param_number[2];

@ -48,7 +48,7 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bott
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];
@ -59,7 +59,7 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bott
}
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);

@ -445,6 +445,20 @@ void SetCurrentGrfLangID(const char *iso_name)
_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.

@ -13,4 +13,6 @@ 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 */

Loading…
Cancel
Save