File diff r14661:a054577a92e2 → r14662:8798e984ee81
src/newgrf.cpp
Show inline comments
 
@@ -2753,14 +2753,14 @@ static bool HandleChangeInfoResult(const
 
			/* Fall through */
 

	
 
		case CIR_INVALID_ID:
 
			/* No debug message for an invalid ID, as it has already been output */
 
			_skip_sprites = -1;
 
			_cur_grfconfig->status = GCS_DISABLED;
 
			_cur_grfconfig->error  = CallocT<GRFError>(1);
 
			_cur_grfconfig->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 
			delete _cur_grfconfig->error;
 
			_cur_grfconfig->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL);
 
			_cur_grfconfig->error->message  = (cir == CIR_INVALID_ID) ? STR_NEWGRF_ERROR_INVALID_ID : STR_NEWGRF_ERROR_UNKNOWN_PROPERTY;
 
			return true;
 
	}
 
}
 

	
 
/* Action 0x00 */
 
@@ -4328,22 +4328,16 @@ static void CfgApply(ByteReader *buf)
 
 * but that might give unwanted results. Disabling the NewGRF gives the
 
 * best result as no NewGRF author can complain about that.
 
 * @param c the NewGRF to disable.
 
 */
 
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
 
{
 
	if (c->error != NULL) {
 
		free(c->error->custom_message);
 
		free(c->error->data);
 
		free(c->error);
 
	}
 
	delete c->error;
 
	c->status = GCS_DISABLED;
 
	c->error  = CallocT<GRFError>(1);
 
	c->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC);
 
	c->error->data = strdup(_cur_grfconfig->name);
 
	c->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 
	c->error->message  = STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC;
 

	
 
	ClearTemporaryNewGRFData(GetFileByGRFID(c->grfid));
 
}
 

	
 
/* Action 0x07
 
 * Action 0x09 */
 
@@ -4546,15 +4540,14 @@ static void GRFInfo(ByteReader *buf)
 
	uint8 version    = buf->ReadByte();
 
	uint32 grfid     = buf->ReadDWord();
 
	const char *name = buf->ReadString();
 

	
 
	if (_cur_stage < GLS_RESERVE && _cur_grfconfig->status != GCS_UNKNOWN) {
 
		_cur_grfconfig->status = GCS_DISABLED;
 
		_cur_grfconfig->error  = CallocT<GRFError>(1);
 
		_cur_grfconfig->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 
		_cur_grfconfig->error->message  = STR_NEWGRF_ERROR_MULTIPLE_ACTION_8;
 
		delete _cur_grfconfig->error;
 
		_cur_grfconfig->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
 

	
 
		_skip_sprites = -1;
 
		return;
 
	}
 

	
 
	_cur_grffile->grfid = grfid;
 
@@ -4686,15 +4679,13 @@ static void GRFLoadError(ByteReader *buf
 

	
 
	if (buf->Remaining() <= 1) {
 
		grfmsg(7, "GRFLoadError: No message data supplied.");
 
		return;
 
	}
 

	
 
	GRFError *error = CallocT<GRFError>(1);
 

	
 
	error->severity = sevstr[severity];
 
	GRFError *error = new GRFError(sevstr[severity]);
 

	
 
	if (message_id == 0xFF) {
 
		/* This is a custom error message. */
 
		if (buf->HasData()) {
 
			const char *message = buf->ReadString();
 

	
 
@@ -5556,23 +5547,18 @@ static void TranslateGRFStrings(ByteRead
 
		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);
 
		delete _cur_grfconfig->error;
 
		_cur_grfconfig->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_LOAD_AFTER);
 

	
 
		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->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 

	
 
		if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error);
 
		_cur_grfconfig->error = error;
 
		_cur_grfconfig->error->data = strdup(tmp);
 

	
 
		_cur_grfconfig->status = GCS_DISABLED;
 
		ClearTemporaryNewGRFData(_cur_grffile);
 
		_skip_sprites = -1;
 
		return;
 
	}
 
@@ -5859,15 +5845,13 @@ static void ResetNewGRF()
 
}
 

	
 
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);
 
			delete c->error;
 
			c->error = NULL;
 
		}
 
	}
 
}
 

	
 
/**
 
@@ -6358,15 +6342,14 @@ static void DecodeSpecialSprite(byte *bu
 
		}
 
	} catch (...) {
 
		grfmsg(1, "DecodeSpecialSprite: Tried to read past end of pseudo-sprite data");
 

	
 
		_skip_sprites = -1;
 
		_cur_grfconfig->status = GCS_DISABLED;
 
		_cur_grfconfig->error  = CallocT<GRFError>(1);
 
		_cur_grfconfig->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 
		_cur_grfconfig->error->message  = STR_NEWGRF_ERROR_READ_BOUNDS;
 
		delete _cur_grfconfig->error;
 
		_cur_grfconfig->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_READ_BOUNDS);
 
	}
 
}
 

	
 

	
 
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
 
{
 
@@ -6390,15 +6373,13 @@ void LoadNewGRFFile(GRFConfig *config, u
 
		_cur_grffile->is_ottdfile = config->IsOpenTTDBaseGRF();
 
	}
 

	
 
	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;
 
		config->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
 
		return;
 
	}
 

	
 
	FioOpenFile(file_index, filename);
 
	_file_index = file_index; // XXX
 
	_palette_remap_grf[_file_index] = (config->windows_paletted != (_use_palette == PAL_WINDOWS));
 
@@ -6438,15 +6419,14 @@ void LoadNewGRFFile(GRFConfig *config, u
 
				FioSkipBytes(num);
 
			}
 
		} else {
 
			if (_skip_sprites == 0) {
 
				grfmsg(0, "LoadNewGRFFile: Unexpected sprite, disabling");
 
				config->status = GCS_DISABLED;
 
				config->error  = CallocT<GRFError>(1);
 
				config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
 
				config->error->message  = STR_NEWGRF_ERROR_UNEXPECTED_SPRITE;
 
				delete config->error;
 
				config->error  = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
 
				break;
 
			}
 

	
 
			FioSkipBytes(7);
 
			SkipSpriteData(type, num - 8);
 
		}