@@ -5405,49 +5405,49 @@ static void DecodeSpecialSprite(uint num
handlers[action][stage](buf, num);
}
free(buf);
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
{
const char *filename = config->filename;
uint16 num;
/* A .grf file is activated only if it was active when the game was
* started. If a game is loaded, only its active .grfs will be
* reactivated, unless "loadallgraphics on" is used. A .grf file is
* considered active if its action 8 has been processed, i.e. its
* action 8 hasn't been skipped using an action 7.
*
* During activation, only actions 0, 1, 2, 3, 4, 5, 7, 8, 9, 0A and 0B are
* carried out. All others are ignored, because they only need to be
* processed once at initialization. */
if (stage != GLS_FILESCAN && stage != GLS_SAFETYSCAN && stage != GLS_LABELSCAN) {
_cur_grffile = GetFileByFilename(filename);
if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename);
if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
if (stage == GLS_ACTIVATION && config->status != GCS_INITIALISED) return;
if (stage == GLS_ACTIVATION && !HASBIT(config->flags, GCF_RESERVED)) return;
if (file_index > LAST_GRF_SLOT) {
DEBUG(grf, 0, "'%s' is not loaded as the maximum number of GRFs has been reached", filename);
config->status = GCS_DISABLED;
config->error = CallocT<GRFError>(1);
config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
config->error->message = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED;
return;
FioOpenFile(file_index, filename);
_file_index = file_index; // XXX
_cur_grfconfig = config;
DEBUG(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
/* Skip the first sprite; we don't care about how many sprites this
* does contain; newest TTDPatches and George's longvehicles don't
* neither, apparently. */
if (FioReadWord() == 4 && FioReadByte() == 0xFF) {
FioReadDword();
} else {
@@ -5539,41 +5539,42 @@ static void AfterLoadGRFs()
void LoadNewGRF(uint load_index, uint file_index)
InitializeGRFSpecial();
ResetNewGRFData();
/* Load newgrf sprites
* in each loading stage, (try to) open each file specified in the config
* and load information from it. */
for (GrfLoadingStage stage = GLS_LABELSCAN; stage <= GLS_ACTIVATION; stage++) {
uint slot = file_index;
_cur_stage = stage;
_cur_spriteid = load_index;
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
if (stage > GLS_INIT && HASBIT(c->flags, GCF_INIT_ONLY)) continue;
/* @todo usererror() */
if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename);
if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid);
LoadNewGRFFile(c, slot++, stage);
if (stage == GLS_RESERVE) {
if (c->status == GCS_ACTIVATED) c->status = GCS_INITIALISED;
SETBIT(c->flags, GCF_RESERVED);
} else if (stage == GLS_ACTIVATION) {
CLRBIT(c->flags, GCF_RESERVED);
ClearTemporaryNewGRFData();
BuildCargoTranslationMap();
DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur_spriteid);
/* Call any functions that should be run after GRFs have been loaded. */
AfterLoadGRFs();
bool HasGrfMiscBit(GrfMiscBit bit)
return HASBIT(_misc_grf_features, bit);
/* $Id$ */
/** @file newgrf_config.h */
#ifndef NEWGRF_CONFIG_H
#define NEWGRF_CONFIG_H
#include "openttd.h"
/* GRF config bit flags */
enum GCF_Flags {
GCF_SYSTEM, ///< GRF file is an openttd-internal system grf
GCF_UNSAFE, ///< GRF file is unsafe for static usage
GCF_STATIC, ///< GRF file is used statically (can be used in any MP game)
GCF_COMPATIBLE,///< GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
GCF_COPY, ///< The data is copied from a grf in _all_grfs
GCF_INIT_ONLY, ///< GRF file is processed up to GLS_INIT
GCF_RESERVED, ///< GRF file passed GLS_RESERVE stage
};
enum GRFStatus {
GCS_UNKNOWN, ///< The status of this grf file is unknown
GCS_DISABLED, ///< GRF file is disabled
GCS_NOT_FOUND, ///< GRF file was not found in the local cache
GCS_INITIALISED, ///< GRF file has been initialised
GCS_ACTIVATED ///< GRF file has been activated
enum GRFListCompatibility{
GLC_ALL_GOOD,
GLC_COMPATIBLE,
GLC_NOT_FOUND
struct GRFIdentifier {
uint32 grfid;
uint8 md5sum[16];
struct GRFError {
char *custom_message;
char *data;
Status change: