summaryrefslogtreecommitdiff
path: root/src/newgrf.cpp
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-06-12 13:22:14 +0000
committermaedhros <maedhros@openttd.org>2007-06-12 13:22:14 +0000
commit94d390eac49841f350a357dbfc7e0904276c9dd9 (patch)
tree5ee61ed1866ad23ad460d7ef74060ce9760f90df /src/newgrf.cpp
parent8f7dea3f4f9ef108d0dc5257f10862bd8752d109 (diff)
downloadopenttd-94d390eac49841f350a357dbfc7e0904276c9dd9.tar.xz
(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.
Diffstat (limited to 'src/newgrf.cpp')
-rw-r--r--src/newgrf.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 549981db5..d16b3cbb6 100644
--- 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 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;
}