Merge branch 'master' into tracerestrict
# Conflicts: # src/rail_gui.cpp # src/saveload/saveload.cpp
This commit is contained in:
@@ -77,6 +77,9 @@ GRFLoadedFeatures _loaded_newgrf_features;
|
||||
|
||||
static const uint MAX_SPRITEGROUP = UINT8_MAX; ///< Maximum GRF-local ID for a spritegroup.
|
||||
|
||||
/** Base GRF ID for OpenTTD's base graphics GRFs. */
|
||||
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);
|
||||
|
||||
/** Temporary data during loading of GRFs */
|
||||
struct GrfProcessingState {
|
||||
private:
|
||||
@@ -1402,7 +1405,7 @@ static ChangeInfoResult RoadVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||
break;
|
||||
|
||||
case 0x12: // SFX
|
||||
rvi->sfx = buf->ReadByte();
|
||||
rvi->sfx = GetNewGRFSoundID(_cur.grffile, buf->ReadByte());
|
||||
break;
|
||||
|
||||
case PROP_ROADVEH_POWER: // Power in units of 10 HP.
|
||||
@@ -1590,7 +1593,7 @@ static ChangeInfoResult ShipVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||
break;
|
||||
|
||||
case 0x10: // SFX
|
||||
svi->sfx = buf->ReadByte();
|
||||
svi->sfx = GetNewGRFSoundID(_cur.grffile, buf->ReadByte());
|
||||
break;
|
||||
|
||||
case 0x11: { // Cargoes available for refitting
|
||||
@@ -1758,7 +1761,7 @@ static ChangeInfoResult AircraftVehicleChangeInfo(uint engine, int numinfo, int
|
||||
break;
|
||||
|
||||
case 0x12: // SFX
|
||||
avi->sfx = buf->ReadByte();
|
||||
avi->sfx = GetNewGRFSoundID(_cur.grffile, buf->ReadByte());
|
||||
break;
|
||||
|
||||
case 0x13: { // Cargoes available for refitting
|
||||
@@ -3010,7 +3013,7 @@ static ChangeInfoResult SoundEffectChangeInfo(uint sid, int numinfo, int prop, B
|
||||
}
|
||||
|
||||
if (sid + numinfo - ORIGINAL_SAMPLE_COUNT > _cur.grffile->num_sounds) {
|
||||
grfmsg(1, "SoundEffectChangeInfo: Attemting to change undefined sound effect (%u), max (%u). Ignoring.", sid + numinfo, ORIGINAL_SAMPLE_COUNT + _cur.grffile->num_sounds);
|
||||
grfmsg(1, "SoundEffectChangeInfo: Attempting to change undefined sound effect (%u), max (%u). Ignoring.", sid + numinfo, ORIGINAL_SAMPLE_COUNT + _cur.grffile->num_sounds);
|
||||
return CIR_INVALID_ID;
|
||||
}
|
||||
|
||||
@@ -5584,7 +5587,7 @@ static const Action5Type _action5_types[] = {
|
||||
/* 0x02 */ { A5BLOCK_INVALID, 0, 0, 0, "Type 0x02" },
|
||||
/* 0x03 */ { A5BLOCK_INVALID, 0, 0, 0, "Type 0x03" },
|
||||
/* 0x04 */ { A5BLOCK_ALLOW_OFFSET, SPR_SIGNALS_BASE, 1, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT, "Signal graphics" },
|
||||
/* 0x05 */ { A5BLOCK_ALLOW_OFFSET, SPR_ELRAIL_BASE, 1, ELRAIL_SPRITE_COUNT, "Catenary graphics" },
|
||||
/* 0x05 */ { A5BLOCK_ALLOW_OFFSET, SPR_ELRAIL_BASE, 1, ELRAIL_SPRITE_COUNT, "Rail catenary graphics" },
|
||||
/* 0x06 */ { A5BLOCK_ALLOW_OFFSET, SPR_SLOPES_BASE, 1, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, "Foundation graphics" },
|
||||
/* 0x07 */ { A5BLOCK_INVALID, 0, 75, 0, "TTDP GUI graphics" }, // Not used by OTTD.
|
||||
/* 0x08 */ { A5BLOCK_ALLOW_OFFSET, SPR_CANALS_BASE, 1, CANALS_SPRITE_COUNT, "Canal graphics" },
|
||||
@@ -5621,7 +5624,7 @@ static void GraphicsNew(ByteReader *buf)
|
||||
uint16 offset = HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
|
||||
ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
|
||||
|
||||
if ((type == 0x0D) && (num == 10) && _cur.grffile->is_ottdfile) {
|
||||
if ((type == 0x0D) && (num == 10) && HasBit(_cur.grfconfig->flags, GCF_SYSTEM)) {
|
||||
/* Special not-TTDP-compatible case used in openttd.grf
|
||||
* Missing shore sprites and initialisation of SPR_SHORE_BASE */
|
||||
grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from extra grf.");
|
||||
@@ -5676,7 +5679,7 @@ static void GraphicsNew(ByteReader *buf)
|
||||
LoadNextSprite(replace == 0 ? _cur.spriteid++ : replace++, _cur.file_index, _cur.nfo_line, _cur.grf_container_ver);
|
||||
}
|
||||
|
||||
if (type == 0x04 && (_cur.grffile->is_ottdfile || _cur.grfconfig->ident.grfid == BSWAP32(0xFF4F4701))) {
|
||||
if (type == 0x04 && ((_cur.grfconfig->ident.grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID || _cur.grfconfig->ident.grfid == BSWAP32(0xFF4F4701))) {
|
||||
/* Signal graphics action 5: Fill duplicate signal sprite block if this is a baseset GRF or OpenGFX */
|
||||
const SpriteID end = offset + num;
|
||||
for (SpriteID i = offset; i < end; i++) {
|
||||
@@ -5701,35 +5704,6 @@ static void SkipAct5(ByteReader *buf)
|
||||
grfmsg(3, "SkipAct5: Skipping %d sprites", _cur.skip_sprites);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we are (obviously) missing some of the extra
|
||||
* (Action 0x05) sprites that we like to use.
|
||||
* When missing sprites are found a warning will be shown.
|
||||
*/
|
||||
void CheckForMissingSprites()
|
||||
{
|
||||
/* Don't break out quickly, but allow to check the other
|
||||
* sprites as well, so we can give the best information. */
|
||||
bool missing = false;
|
||||
for (uint8 i = 0; i < lengthof(_action5_types); i++) {
|
||||
const Action5Type *type = &_action5_types[i];
|
||||
if (type->block_type == A5BLOCK_INVALID) continue;
|
||||
|
||||
for (uint j = 0; j < type->max_sprites; j++) {
|
||||
if (!SpriteExists(type->sprite_base + j)) {
|
||||
DEBUG(grf, 0, "%s sprites are missing", type->name);
|
||||
missing = true;
|
||||
/* No need to log more of the same. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (missing) {
|
||||
ShowErrorMessage(IsReleasedVersion() ? STR_NEWGRF_ERROR_MISSING_SPRITES : STR_NEWGRF_ERROR_MISSING_SPRITES_UNSTABLE, INVALID_STRING_ID, WL_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a variable common to VarAction2 and Action7/9/D.
|
||||
*
|
||||
@@ -6207,7 +6181,7 @@ static void ScanInfo(ByteReader *buf)
|
||||
}
|
||||
|
||||
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
||||
if (GB(grfid, 24, 8) == 0xFF) SetBit(_cur.grfconfig->flags, GCF_SYSTEM);
|
||||
if (GB(grfid, 0, 8) == 0xFF) SetBit(_cur.grfconfig->flags, GCF_SYSTEM);
|
||||
|
||||
AddGRFTextToList(&_cur.grfconfig->name->text, 0x7F, grfid, false, name);
|
||||
|
||||
@@ -6429,8 +6403,8 @@ static void SafeParamSet(ByteReader *buf)
|
||||
{
|
||||
uint8 target = buf->ReadByte();
|
||||
|
||||
/* Only writing GRF parameters is considered safe */
|
||||
if (target < 0x80) return;
|
||||
/* Writing GRF parameters and some bits of 'misc GRF features' are safe. */
|
||||
if (target < 0x80 || target == 0x9E) return;
|
||||
|
||||
/* GRM could be unsafe, but as here it can only happen after other GRFs
|
||||
* are loaded, it should be okay. If the GRF tried to use the slots it
|
||||
@@ -6846,7 +6820,15 @@ static void ParamSet(ByteReader *buf)
|
||||
/* Remove the local flags from the global flags */
|
||||
ClrBit(res, GMB_TRAIN_WIDTH_32_PIXELS);
|
||||
|
||||
_misc_grf_features = res;
|
||||
/* Only copy safe bits for static grfs */
|
||||
if (HasBit(_cur.grfconfig->flags, GCF_STATIC)) {
|
||||
uint32 safe_bits = 0;
|
||||
SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
|
||||
|
||||
_misc_grf_features = (_misc_grf_features & ~safe_bits) | (res & safe_bits);
|
||||
} else {
|
||||
_misc_grf_features = res;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x9F: // locale-dependent settings
|
||||
@@ -8858,11 +8840,10 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, S
|
||||
if (_cur.grffile == NULL) usererror("File '%s' lost in cache.\n", filename);
|
||||
if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return;
|
||||
if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return;
|
||||
_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);
|
||||
if (file_index >= MAX_FILE_SLOTS) {
|
||||
DEBUG(grf, 0, "'%s' is not loaded as the maximum number of file slots has been reached", filename);
|
||||
config->status = GCS_DISABLED;
|
||||
config->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
|
||||
return;
|
||||
@@ -9204,8 +9185,9 @@ static void AfterLoadGRFs()
|
||||
* Load all the NewGRFs.
|
||||
* @param load_index The offset for the first sprite to add.
|
||||
* @param file_index The Fio index of the first NewGRF to load.
|
||||
* @param num_baseset Number of NewGRFs at the front of the list to look up in the baseset dir instead of the newgrf dir.
|
||||
*/
|
||||
void LoadNewGRF(uint load_index, uint file_index)
|
||||
void LoadNewGRF(uint load_index, uint file_index, uint num_baseset)
|
||||
{
|
||||
/* In case of networking we need to "sync" the start values
|
||||
* so all NewGRFs are loaded equally. For this we use the
|
||||
@@ -9264,13 +9246,14 @@ void LoadNewGRF(uint load_index, uint file_index)
|
||||
}
|
||||
|
||||
uint slot = file_index;
|
||||
uint num_non_static = 0;
|
||||
|
||||
_cur.stage = stage;
|
||||
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;
|
||||
|
||||
Subdirectory subdir = slot == file_index ? BASESET_DIR : NEWGRF_DIR;
|
||||
Subdirectory subdir = slot < file_index + num_baseset ? BASESET_DIR : NEWGRF_DIR;
|
||||
if (!FioCheckFileExists(c->filename, subdir)) {
|
||||
DEBUG(grf, 0, "NewGRF file is missing '%s'; disabling", c->filename);
|
||||
c->status = GCS_NOT_FOUND;
|
||||
@@ -9278,6 +9261,16 @@ void LoadNewGRF(uint load_index, uint file_index)
|
||||
}
|
||||
|
||||
if (stage == GLS_LABELSCAN) InitNewGRFFile(c);
|
||||
|
||||
if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) {
|
||||
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
|
||||
DEBUG(grf, 0, "'%s' is not loaded as the maximum number of non-static GRFs has been reached", c->filename);
|
||||
c->status = GCS_DISABLED;
|
||||
c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
|
||||
continue;
|
||||
}
|
||||
num_non_static++;
|
||||
}
|
||||
LoadNewGRFFile(c, slot++, stage, subdir);
|
||||
if (stage == GLS_RESERVE) {
|
||||
SetBit(c->flags, GCF_RESERVED);
|
||||
|
Reference in New Issue
Block a user