--- a/src/newgrf.cpp Wed Jun 13 12:05:56 2007 +0000
+++ b/src/newgrf.cpp Tue Jun 19 07:21:01 2007 +0000
@@ -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"
@@ -75,7 +76,7 @@
static byte *_preload_sprite = NULL;
/* Indicates which are the newgrf features currently loaded ingame */
-uint8 _loaded_newgrf_features;
+GRFLoadedFeatures _loaded_newgrf_features;
enum GrfDataType {
GDT_SOUND,
@@ -538,7 +539,7 @@
case 0x27: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
- if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
+ _loaded_newgrf_features.has_2CC |= HASBIT(ei[i].misc_flags, EF_USES_2CC);
}
break;
@@ -660,7 +661,7 @@
case 0x1C: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
- if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
+ _loaded_newgrf_features.has_2CC |= HASBIT(ei[i].misc_flags, EF_USES_2CC);
}
break;
@@ -771,7 +772,7 @@
case 0x17: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
- if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
+ _loaded_newgrf_features.has_2CC |= HASBIT(ei[i].misc_flags, EF_USES_2CC);
}
break;
@@ -887,7 +888,7 @@
case 0x17: // Miscellaneous flags
FOR_EACH_OBJECT {
ei[i].misc_flags = grf_load_byte(&buf);
- if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) SETBIT(_loaded_newgrf_features, GRFLOADED_2CC);
+ _loaded_newgrf_features.has_2CC |= HASBIT(ei[i].misc_flags, EF_USES_2CC);
}
break;
@@ -1296,7 +1297,7 @@
* FinaliseHouseArray() for more details. */
if (housespec[i]->min_date < 1930) housespec[i]->min_date = 1930;
}
- SETBIT(_loaded_newgrf_features, GRFLOADED_NEWHOUSES);
+ _loaded_newgrf_features.has_newhouses = true;
break;
case 0x09: // Building flags
@@ -2044,7 +2045,7 @@
);
for (uint16 i = 0; i < num_sets * num_ents; i++) {
- LoadNextSprite(_cur_spriteid++, _file_index);
+ LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line);
_nfo_line++;
}
}
@@ -2100,6 +2101,7 @@
if (feature != _cur_grffile->spriteset_feature) {
grfmsg(1, "CreateGroupFromGroupID(0x%02X:0x%02X): Sprite set feature 0x%02X does not match action feature 0x%02X, skipping",
+ setid, type,
_cur_grffile->spriteset_feature, feature);
return NULL;
}
@@ -2958,7 +2960,7 @@
}
for (; num > 0; num--) {
- LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index);
+ LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index, _nfo_line);
_nfo_line++;
}
}
@@ -3277,7 +3279,9 @@
_skip_sprites = -1;
/* If an action 8 hasn't been encountered yet, disable the grf. */
- if (_cur_grfconfig->status != GCS_ACTIVATED) _cur_grfconfig->status = GCS_DISABLED;
+ if (_cur_grfconfig->status != GCS_ACTIVATED && _cur_grfconfig->status != GCS_INITIALISED) {
+ _cur_grfconfig->status = GCS_DISABLED;
+ }
}
}
@@ -3356,7 +3360,7 @@
);
for (uint j = 0; j < num_sprites; j++) {
- LoadNextSprite(first_sprite + j, _file_index); // XXX
+ LoadNextSprite(first_sprite + j, _file_index, _nfo_line); // XXX
_nfo_line++;
}
}
@@ -3412,15 +3416,6 @@
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 +3427,9 @@
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 +3459,6 @@
return;
}
- bool new_scheme = _cur_grffile->grf_version >= 7;
GRFError *error = CallocT<GRFError>(1);
error->severity = sevstr[severity];
@@ -3471,7 +3468,7 @@
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 +3477,7 @@
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. */
@@ -4086,7 +4083,7 @@
for (uint c = 0; c < num_char; c++) {
SetUnicodeGlyph(size, base_char + c, _cur_spriteid);
- LoadNextSprite(_cur_spriteid++, _file_index);
+ LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line);
_nfo_line++;
}
}
@@ -4116,8 +4113,12 @@
/* 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);
@@ -4228,7 +4229,7 @@
| (0 << 0x0C) // newagerating
| ((_patches.build_on_slopes ? 1 : 0) << 0x0D) // buildonslopes
| ((_patches.full_load_any ? 1 : 0) << 0x0E) // fullloadany
- | (0 << 0x0F) // planespeed
+ | (1 << 0x0F) // planespeed - TODO depends on patch when implemented
| (0 << 0x10) // moreindustriesperclimate - obsolete
| (0 << 0x11) // moretoylandfeatures
| (1 << 0x12) // newstations
@@ -4398,6 +4399,18 @@
_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
@@ -4465,6 +4478,9 @@
/* Reset NewGRF files */
ResetNewGRF();
+ /* Reset NewGRF errors. */
+ ResetNewGRFErrors();
+
/* Add engine type to engine data. This is needed for the refit precalculation. */
AddTypeToEngines();
@@ -4476,7 +4492,9 @@
_traininfo_vehicle_pitch = 0;
_traininfo_vehicle_width = 29;
- _loaded_newgrf_features = 0;
+ _loaded_newgrf_features.has_2CC = false;
+ _loaded_newgrf_features.has_newhouses = false;
+ _loaded_newgrf_features.has_newindustries = false,
_signal_base = 0;
_coast_base = 0;