summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp26
-rw-r--r--src/newgrf_config.cpp9
-rw-r--r--src/newgrf_config.h3
-rw-r--r--src/newgrf_gui.cpp4
-rw-r--r--src/newgrf_text.cpp14
-rw-r--r--src/newgrf_text.h2
6 files changed, 41 insertions, 17 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;
}
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 3e3cfdc52..6d6709c6b 100644
--- 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 **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;
diff --git a/src/newgrf_config.h b/src/newgrf_config.h
index 491c7ca88..120b085b7 100644
--- 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
index 22335c3d1..4b36dc452 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -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);
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index 5c977992f..d05b0c2d3 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -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.
diff --git a/src/newgrf_text.h b/src/newgrf_text.h
index 272b78422..ec0fcdc91 100644
--- 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 */