# HG changeset patch # User maedhros # Date 2007-06-12 13:22:14 # Node ID 011bb22696074cbb2e1737a36cba4bd5ff58c7c1 # Parent f40beb7256a6135c9c9536fd11d6bca516c11c1c (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. diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -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 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 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 return; } - bool new_scheme = _cur_grffile->grf_version >= 7; GRFError *error = CallocT(1); error->severity = sevstr[severity]; @@ -3471,7 +3465,7 @@ static void GRFLoadError(byte *buf, int 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 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 *bu /* If the file is not active but will be activated later, give an error * and disable this file. */ GRFError *error = CallocT(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; } diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -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 if (src->error != NULL) { c->error = CallocT(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; diff --git a/src/newgrf_config.h b/src/newgrf_config.h --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -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]; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -48,7 +48,7 @@ static void ShowNewGRFInfo(const GRFConf 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 GRFConf } 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); diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -445,6 +445,20 @@ void SetCurrentGrfLangID(const char *iso _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. diff --git a/src/newgrf_text.h b/src/newgrf_text.h --- a/src/newgrf_text.h +++ b/src/newgrf_text.h @@ -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 */