|
@@ -9,24 +9,25 @@
|
|
|
#include "openttd.h"
|
|
|
#include "debug.h"
|
|
|
#include "gfx.h"
|
|
|
#include "fileio.h"
|
|
|
#include "functions.h"
|
|
|
#include "engine.h"
|
|
|
#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"
|
|
|
#include "newgrf_text.h"
|
|
|
#include "table/sprites.h"
|
|
|
#include "fontcache.h"
|
|
|
#include "date.h"
|
|
|
#include "currency.h"
|
|
|
#include "landscape.h"
|
|
@@ -3403,44 +3404,38 @@ static void GRFLoadError(byte *buf, int
|
|
|
STR_NEWGRF_ERROR_INVALID_PARAMETER,
|
|
|
STR_NEWGRF_ERROR_LOAD_BEFORE,
|
|
|
STR_NEWGRF_ERROR_LOAD_AFTER
|
|
|
};
|
|
|
|
|
|
static const StringID sevstr[] = {
|
|
|
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;
|
|
|
}
|
|
|
CLRBIT(severity, 7);
|
|
|
|
|
|
if (severity >= lengthof(sevstr)) {
|
|
|
grfmsg(7, "GRFLoadError: Invalid severity id %d. Setting to 2 (non-fatal error).", severity);
|
|
|
severity = 2;
|
|
|
} else if (severity == 3) {
|
|
@@ -3452,44 +3447,43 @@ static void GRFLoadError(byte *buf, int
|
|
|
}
|
|
|
|
|
|
if (message_id >= lengthof(msgstr) && message_id != 0xFF) {
|
|
|
grfmsg(7, "GRFLoadError: Invalid message id.");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
len--;
|
|
|
}
|
|
|
error->num_params = i;
|
|
|
|
|
|
_cur_grfconfig->error = error;
|
|
|
}
|
|
@@ -4107,26 +4101,30 @@ static void TranslateGRFStrings(byte *bu
|
|
|
|
|
|
uint32 grfid = grf_load_dword(&buf);
|
|
|
const GRFConfig *c = GetGRFConfig(grfid);
|
|
|
if (c == NULL || (c->status != GCS_INITIALISED && c->status != GCS_ACTIVATED)) {
|
|
|
grfmsg(7, "TranslateGRFStrings: GRFID 0x%08x unknown, skipping action 13", BSWAP32(grfid));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
_skip_sprites = -1;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
byte num_strings = grf_load_byte(&buf);
|
|
|
uint16 first_id = grf_load_word(&buf);
|
|
@@ -4393,24 +4391,26 @@ static void ResetNewGRF()
|
|
|
free(f->cargo_list);
|
|
|
free(f);
|
|
|
}
|
|
|
|
|
|
_first_grffile = NULL;
|
|
|
_cur_grffile = NULL;
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Reset all NewGRF loaded data
|
|
|
* TODO
|
|
|
*/
|
|
|
static void ResetNewGRFData()
|
|
|
{
|