mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for GRFConfigFlags.
This is renamed from `GCF_Flag` didn't match convention.pull/13442/head
parent
877fa54f66
commit
6f52a977a8
|
@ -507,7 +507,7 @@ bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id)
|
||||||
*/
|
*/
|
||||||
static inline bool IsLoggableGrfConfig(const GRFConfig &g)
|
static inline bool IsLoggableGrfConfig(const GRFConfig &g)
|
||||||
{
|
{
|
||||||
return !HasBit(g.flags, GCF_STATIC) && g.status != GCS_NOT_FOUND;
|
return !g.flags.Test(GRFConfigFlag::Static) && g.status != GCS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -153,7 +153,7 @@ static std::unique_ptr<GRFConfig> GetDefaultExtraGRFConfig()
|
||||||
auto gc = std::make_unique<GRFConfig>("OPENTTD.GRF");
|
auto gc = std::make_unique<GRFConfig>("OPENTTD.GRF");
|
||||||
gc->palette |= GRFP_GRF_DOS;
|
gc->palette |= GRFP_GRF_DOS;
|
||||||
FillGRFDetails(*gc, false, BASESET_DIR);
|
FillGRFDetails(*gc, false, BASESET_DIR);
|
||||||
ClrBit(gc->flags, GCF_INIT_ONLY);
|
gc->flags.Reset(GRFConfigFlag::InitOnly);
|
||||||
return gc;
|
return gc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ static std::unique_ptr<GRFConfig> GetBasesetExtraGRFConfig()
|
||||||
{
|
{
|
||||||
auto gc = std::make_unique<GRFConfig>(BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig());
|
auto gc = std::make_unique<GRFConfig>(BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig());
|
||||||
if (gc->param.empty()) gc->SetParameterDefaults();
|
if (gc->param.empty()) gc->SetParameterDefaults();
|
||||||
ClrBit(gc->flags, GCF_INIT_ONLY);
|
gc->flags.Reset(GRFConfigFlag::InitOnly);
|
||||||
return gc;
|
return gc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ static bool SwitchNewGRFBlitter()
|
||||||
uint depth_wanted_by_base = BaseGraphics::GetUsedSet()->blitter == BLT_32BPP ? 32 : 8;
|
uint depth_wanted_by_base = BaseGraphics::GetUsedSet()->blitter == BLT_32BPP ? 32 : 8;
|
||||||
uint depth_wanted_by_grf = _support8bpp != S8BPP_NONE ? 8 : 32;
|
uint depth_wanted_by_grf = _support8bpp != S8BPP_NONE ? 8 : 32;
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue;
|
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || c->flags.Test(GRFConfigFlag::InitOnly)) continue;
|
||||||
if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
|
if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
|
||||||
}
|
}
|
||||||
/* We need a 32bpp blitter for font anti-alias. */
|
/* We need a 32bpp blitter for font anti-alias. */
|
||||||
|
|
|
@ -193,7 +193,7 @@ static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig &config, std::strin
|
||||||
config.info = f->info;
|
config.info = f->info;
|
||||||
config.url = f->url;
|
config.url = f->url;
|
||||||
}
|
}
|
||||||
SetBit(config.flags, GCF_COPY);
|
config.flags.Set(GRFConfigFlag::Copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,12 +230,12 @@ void SerializeNetworkGameInfo(Packet &p, const NetworkServerGameInfo &info, bool
|
||||||
* the GRFs that are needed, i.e. the ones that the server has
|
* the GRFs that are needed, i.e. the ones that the server has
|
||||||
* selected in the NewGRF GUI and not the ones that are used due
|
* selected in the NewGRF GUI and not the ones that are used due
|
||||||
* to the fact that they are in [newgrf-static] in openttd.cfg */
|
* to the fact that they are in [newgrf-static] in openttd.cfg */
|
||||||
uint count = std::ranges::count_if(info.grfconfig, [](const auto &c) { return !HasBit(c->flags, GCF_STATIC); });
|
uint count = std::ranges::count_if(info.grfconfig, [](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static); });
|
||||||
p.Send_uint8 (count); // Send number of GRFs
|
p.Send_uint8 (count); // Send number of GRFs
|
||||||
|
|
||||||
/* Send actual GRF Identifications */
|
/* Send actual GRF Identifications */
|
||||||
for (const auto &c : info.grfconfig) {
|
for (const auto &c : info.grfconfig) {
|
||||||
if (HasBit(c->flags, GCF_STATIC)) continue;
|
if (c->flags.Test(GRFConfigFlag::Static)) continue;
|
||||||
|
|
||||||
SerializeGRFIdentifier(p, c->ident);
|
SerializeGRFIdentifier(p, c->ident);
|
||||||
if (send_newgrf_names) p.Send_string(c->GetName());
|
if (send_newgrf_names) p.Send_string(c->GetName());
|
||||||
|
|
|
@ -118,7 +118,7 @@ void NetworkAfterNewGRFScan()
|
||||||
item->info.compatible = item->info.version_compatible;
|
item->info.compatible = item->info.version_compatible;
|
||||||
|
|
||||||
for (auto &c : item->info.grfconfig) {
|
for (auto &c : item->info.grfconfig) {
|
||||||
assert(HasBit(c->flags, GCF_COPY));
|
assert(c->flags.Test(GRFConfigFlag::Copy));
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
|
||||||
if (f == nullptr) {
|
if (f == nullptr) {
|
||||||
|
|
|
@ -418,11 +418,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
|
||||||
|
|
||||||
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
|
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
|
||||||
|
|
||||||
uint grf_count = std::ranges::count_if(_grfconfig, [](const auto &c){ return !HasBit(c->flags, GCF_STATIC); });
|
uint grf_count = std::ranges::count_if(_grfconfig, [](const auto &c){ return !c->flags.Test(GRFConfigFlag::Static); });
|
||||||
p->Send_uint8 (grf_count);
|
p->Send_uint8 (grf_count);
|
||||||
|
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (!HasBit(c->flags, GCF_STATIC)) SerializeGRFIdentifier(*p, c->ident);
|
if (!c->flags.Test(GRFConfigFlag::Static)) SerializeGRFIdentifier(*p, c->ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->SendPacket(std::move(p));
|
this->SendPacket(std::move(p));
|
||||||
|
|
|
@ -5063,7 +5063,7 @@ static void SafeChangeInfo(ByteReader &buf)
|
||||||
uint32_t s = buf.ReadDWord();
|
uint32_t s = buf.ReadDWord();
|
||||||
buf.ReadDWord(); // dest
|
buf.ReadDWord(); // dest
|
||||||
const GRFConfig *grfconfig = GetGRFConfig(s);
|
const GRFConfig *grfconfig = GetGRFConfig(s);
|
||||||
if (grfconfig != nullptr && !HasBit(grfconfig->flags, GCF_STATIC)) {
|
if (grfconfig != nullptr && !grfconfig->flags.Test(GRFConfigFlag::Static)) {
|
||||||
is_safe = false;
|
is_safe = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -5072,7 +5072,7 @@ static void SafeChangeInfo(ByteReader &buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
|
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
|
||||||
|
|
||||||
/* Skip remainder of GRF */
|
/* Skip remainder of GRF */
|
||||||
_cur.skip_sprites = -1;
|
_cur.skip_sprites = -1;
|
||||||
|
@ -6376,7 +6376,7 @@ static void FeatureNewName(ByteReader &buf)
|
||||||
case GSF_SHIPS:
|
case GSF_SHIPS:
|
||||||
case GSF_AIRCRAFT:
|
case GSF_AIRCRAFT:
|
||||||
if (!generic) {
|
if (!generic) {
|
||||||
Engine *e = GetNewEngine(_cur.grffile, (VehicleType)feature, id, HasBit(_cur.grfconfig->flags, GCF_STATIC));
|
Engine *e = GetNewEngine(_cur.grffile, (VehicleType)feature, id, _cur.grfconfig->flags.Test(GRFConfigFlag::Static));
|
||||||
if (e == nullptr) break;
|
if (e == nullptr) break;
|
||||||
StringID string = AddGRFString(_cur.grffile->grfid, GRFStringID{e->index}, lang, new_scheme, false, name, e->info.string_id);
|
StringID string = AddGRFString(_cur.grffile->grfid, GRFStringID{e->index}, lang, new_scheme, false, name, e->info.string_id);
|
||||||
e->info.string_id = string;
|
e->info.string_id = string;
|
||||||
|
@ -6517,7 +6517,7 @@ static void GraphicsNew(ByteReader &buf)
|
||||||
uint16_t offset = HasBit(type, 7) ? buf.ReadExtendedByte() : 0;
|
uint16_t offset = HasBit(type, 7) ? buf.ReadExtendedByte() : 0;
|
||||||
ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
|
ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
|
||||||
|
|
||||||
if ((type == 0x0D) && (num == 10) && HasBit(_cur.grfconfig->flags, GCF_SYSTEM)) {
|
if ((type == 0x0D) && (num == 10) && _cur.grfconfig->flags.Test(GRFConfigFlag::System)) {
|
||||||
/* Special not-TTDP-compatible case used in openttd.grf
|
/* Special not-TTDP-compatible case used in openttd.grf
|
||||||
* Missing shore sprites and initialisation of SPR_SHORE_BASE */
|
* Missing shore sprites and initialisation of SPR_SHORE_BASE */
|
||||||
GrfMsg(2, "GraphicsNew: Loading 10 missing shore sprites from extra grf.");
|
GrfMsg(2, "GraphicsNew: Loading 10 missing shore sprites from extra grf.");
|
||||||
|
@ -6979,7 +6979,7 @@ static void SkipIf(ByteReader &buf)
|
||||||
|
|
||||||
GRFConfig *c = GetGRFConfig(cond_val, mask);
|
GRFConfig *c = GetGRFConfig(cond_val, mask);
|
||||||
|
|
||||||
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
|
if (c != nullptr && c->flags.Test(GRFConfigFlag::Static) && !_cur.grfconfig->flags.Test(GRFConfigFlag::Static) && _networking) {
|
||||||
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
|
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
|
||||||
c = nullptr;
|
c = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -7091,12 +7091,12 @@ static void ScanInfo(ByteReader &buf)
|
||||||
_cur.grfconfig->ident.grfid = grfid;
|
_cur.grfconfig->ident.grfid = grfid;
|
||||||
|
|
||||||
if (grf_version < 2 || grf_version > 8) {
|
if (grf_version < 2 || grf_version > 8) {
|
||||||
SetBit(_cur.grfconfig->flags, GCF_INVALID);
|
_cur.grfconfig->flags.Set(GRFConfigFlag::Invalid);
|
||||||
Debug(grf, 0, "{}: NewGRF \"{}\" (GRFID {:08X}) uses GRF version {}, which is incompatible with this version of OpenTTD.", _cur.grfconfig->filename, StrMakeValid(name), std::byteswap(grfid), grf_version);
|
Debug(grf, 0, "{}: NewGRF \"{}\" (GRFID {:08X}) uses GRF version {}, which is incompatible with this version of OpenTTD.", _cur.grfconfig->filename, StrMakeValid(name), std::byteswap(grfid), grf_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
||||||
if (GB(grfid, 0, 8) == 0xFF) SetBit(_cur.grfconfig->flags, GCF_SYSTEM);
|
if (GB(grfid, 0, 8) == 0xFF) _cur.grfconfig->flags.Set(GRFConfigFlag::System);
|
||||||
|
|
||||||
AddGRFTextToList(_cur.grfconfig->name, 0x7F, grfid, false, name);
|
AddGRFTextToList(_cur.grfconfig->name, 0x7F, grfid, false, name);
|
||||||
|
|
||||||
|
@ -7351,7 +7351,7 @@ static void SafeParamSet(ByteReader &buf)
|
||||||
* reserved, it would be marked unsafe anyway. GRM for (e.g. bridge)
|
* reserved, it would be marked unsafe anyway. GRM for (e.g. bridge)
|
||||||
* sprites is considered safe. */
|
* sprites is considered safe. */
|
||||||
|
|
||||||
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
|
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
|
||||||
|
|
||||||
/* Skip remainder of GRF */
|
/* Skip remainder of GRF */
|
||||||
_cur.skip_sprites = -1;
|
_cur.skip_sprites = -1;
|
||||||
|
@ -7620,7 +7620,7 @@ static void ParamSet(ByteReader &buf)
|
||||||
/* Read another GRF File's parameter */
|
/* Read another GRF File's parameter */
|
||||||
const GRFFile *file = GetFileByGRFID(data);
|
const GRFFile *file = GetFileByGRFID(data);
|
||||||
GRFConfig *c = GetGRFConfig(data);
|
GRFConfig *c = GetGRFConfig(data);
|
||||||
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
|
if (c != nullptr && c->flags.Test(GRFConfigFlag::Static) && !_cur.grfconfig->flags.Test(GRFConfigFlag::Static) && _networking) {
|
||||||
/* Disable the read GRF if it is a static NewGRF. */
|
/* Disable the read GRF if it is a static NewGRF. */
|
||||||
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
|
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
|
||||||
src1 = 0;
|
src1 = 0;
|
||||||
|
@ -7759,7 +7759,7 @@ static void ParamSet(ByteReader &buf)
|
||||||
ClrBit(res, GMB_TRAIN_WIDTH_32_PIXELS);
|
ClrBit(res, GMB_TRAIN_WIDTH_32_PIXELS);
|
||||||
|
|
||||||
/* Only copy safe bits for static grfs */
|
/* Only copy safe bits for static grfs */
|
||||||
if (HasBit(_cur.grfconfig->flags, GCF_STATIC)) {
|
if (_cur.grfconfig->flags.Test(GRFConfigFlag::Static)) {
|
||||||
uint32_t safe_bits = 0;
|
uint32_t safe_bits = 0;
|
||||||
SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
|
SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
|
||||||
|
|
||||||
|
@ -7800,7 +7800,7 @@ static void SafeGRFInhibit(ByteReader &buf)
|
||||||
|
|
||||||
/* GRF is unsafe it if tries to deactivate other GRFs */
|
/* GRF is unsafe it if tries to deactivate other GRFs */
|
||||||
if (grfid != _cur.grfconfig->ident.grfid) {
|
if (grfid != _cur.grfconfig->ident.grfid) {
|
||||||
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
|
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
|
||||||
|
|
||||||
/* Skip remainder of GRF */
|
/* Skip remainder of GRF */
|
||||||
_cur.skip_sprites = -1;
|
_cur.skip_sprites = -1;
|
||||||
|
@ -8636,7 +8636,7 @@ static void StaticGRFInfo(ByteReader &buf)
|
||||||
*/
|
*/
|
||||||
static void GRFUnsafe(ByteReader &)
|
static void GRFUnsafe(ByteReader &)
|
||||||
{
|
{
|
||||||
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
|
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
|
||||||
|
|
||||||
/* Skip remainder of GRF */
|
/* Skip remainder of GRF */
|
||||||
_cur.skip_sprites = -1;
|
_cur.skip_sprites = -1;
|
||||||
|
@ -9757,7 +9757,7 @@ void LoadNewGRFFile(GRFConfig &config, GrfLoadingStage stage, Subdirectory subdi
|
||||||
_cur.grffile = GetFileByFilename(filename);
|
_cur.grffile = GetFileByFilename(filename);
|
||||||
if (_cur.grffile == nullptr) UserError("File '{}' lost in cache.\n", filename);
|
if (_cur.grffile == nullptr) UserError("File '{}' lost in cache.\n", filename);
|
||||||
if (stage == GLS_RESERVE && config.status != GCS_INITIALISED) return;
|
if (stage == GLS_RESERVE && config.status != GCS_INITIALISED) return;
|
||||||
if (stage == GLS_ACTIVATION && !HasBit(config.flags, GCF_RESERVED)) return;
|
if (stage == GLS_ACTIVATION && !config.flags.Test(GRFConfigFlag::Reserved)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needs_palette_remap = config.palette & GRFP_USE_MASK;
|
bool needs_palette_remap = config.palette & GRFP_USE_MASK;
|
||||||
|
@ -10141,7 +10141,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
|
||||||
_cur.stage = stage;
|
_cur.stage = stage;
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
|
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
|
||||||
if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue;
|
if (stage > GLS_INIT && c->flags.Test(GRFConfigFlag::InitOnly)) continue;
|
||||||
|
|
||||||
Subdirectory subdir = num_grfs < num_baseset ? BASESET_DIR : NEWGRF_DIR;
|
Subdirectory subdir = num_grfs < num_baseset ? BASESET_DIR : NEWGRF_DIR;
|
||||||
if (!FioCheckFileExists(c->filename, subdir)) {
|
if (!FioCheckFileExists(c->filename, subdir)) {
|
||||||
|
@ -10152,7 +10152,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
|
||||||
|
|
||||||
if (stage == GLS_LABELSCAN) InitNewGRFFile(*c);
|
if (stage == GLS_LABELSCAN) InitNewGRFFile(*c);
|
||||||
|
|
||||||
if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) {
|
if (!c->flags.Test(GRFConfigFlag::Static) && !c->flags.Test(GRFConfigFlag::System)) {
|
||||||
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
|
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
|
||||||
Debug(grf, 0, "'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->filename);
|
Debug(grf, 0, "'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->filename);
|
||||||
c->status = GCS_DISABLED;
|
c->status = GCS_DISABLED;
|
||||||
|
@ -10166,14 +10166,14 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
|
||||||
|
|
||||||
LoadNewGRFFile(*c, stage, subdir, false);
|
LoadNewGRFFile(*c, stage, subdir, false);
|
||||||
if (stage == GLS_RESERVE) {
|
if (stage == GLS_RESERVE) {
|
||||||
SetBit(c->flags, GCF_RESERVED);
|
c->flags.Set(GRFConfigFlag::Reserved);
|
||||||
} else if (stage == GLS_ACTIVATION) {
|
} else if (stage == GLS_ACTIVATION) {
|
||||||
ClrBit(c->flags, GCF_RESERVED);
|
c->flags.Reset(GRFConfigFlag::Reserved);
|
||||||
assert(GetFileByGRFID(c->ident.grfid) == _cur.grffile);
|
assert(GetFileByGRFID(c->ident.grfid) == _cur.grffile);
|
||||||
ClearTemporaryNewGRFData(_cur.grffile);
|
ClearTemporaryNewGRFData(_cur.grffile);
|
||||||
BuildCargoTranslationMap();
|
BuildCargoTranslationMap();
|
||||||
Debug(sprite, 2, "LoadNewGRF: Currently {} sprites are loaded", _cur.spriteid);
|
Debug(sprite, 2, "LoadNewGRF: Currently {} sprites are loaded", _cur.spriteid);
|
||||||
} else if (stage == GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) {
|
} else if (stage == GLS_INIT && c->flags.Test(GRFConfigFlag::InitOnly)) {
|
||||||
/* We're not going to activate this, so free whatever data we allocated */
|
/* We're not going to activate this, so free whatever data we allocated */
|
||||||
ClearTemporaryNewGRFData(_cur.grffile);
|
ClearTemporaryNewGRFData(_cur.grffile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
|
||||||
error(config.error),
|
error(config.error),
|
||||||
version(config.version),
|
version(config.version),
|
||||||
min_loadable_version(config.min_loadable_version),
|
min_loadable_version(config.min_loadable_version),
|
||||||
flags(config.flags & ~(1 << GCF_COPY)),
|
flags(config.flags),
|
||||||
status(config.status),
|
status(config.status),
|
||||||
grf_bugs(config.grf_bugs),
|
grf_bugs(config.grf_bugs),
|
||||||
num_valid_params(config.num_valid_params),
|
num_valid_params(config.num_valid_params),
|
||||||
|
@ -52,6 +52,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
|
||||||
param_info(config.param_info),
|
param_info(config.param_info),
|
||||||
param(config.param)
|
param(config.param)
|
||||||
{
|
{
|
||||||
|
this->flags.Reset(GRFConfigFlag::Copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRFConfig::SetParams(std::span<const uint32_t> pars)
|
void GRFConfig::SetParams(std::span<const uint32_t> pars)
|
||||||
|
@ -306,14 +307,14 @@ bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
|
||||||
config.FinalizeParameterInfo();
|
config.FinalizeParameterInfo();
|
||||||
|
|
||||||
/* Skip if the grfid is 0 (not read) or if it is an internal GRF */
|
/* Skip if the grfid is 0 (not read) or if it is an internal GRF */
|
||||||
if (config.ident.grfid == 0 || HasBit(config.flags, GCF_SYSTEM)) return false;
|
if (config.ident.grfid == 0 || config.flags.Test(GRFConfigFlag::System)) return false;
|
||||||
|
|
||||||
if (is_static) {
|
if (is_static) {
|
||||||
/* Perform a 'safety scan' for static GRFs */
|
/* Perform a 'safety scan' for static GRFs */
|
||||||
LoadNewGRFFile(config, GLS_SAFETYSCAN, subdir, true);
|
LoadNewGRFFile(config, GLS_SAFETYSCAN, subdir, true);
|
||||||
|
|
||||||
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
|
/* GRFConfigFlag::Unsafe is set if GLS_SAFETYSCAN finds unsafe actions */
|
||||||
if (HasBit(config.flags, GCF_UNSAFE)) return false;
|
if (config.flags.Test(GRFConfigFlag::Unsafe)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CalcGRFMD5Sum(config, subdir);
|
return CalcGRFMD5Sum(config, subdir);
|
||||||
|
@ -340,7 +341,11 @@ static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bo
|
||||||
{
|
{
|
||||||
for (const auto &s : src) {
|
for (const auto &s : src) {
|
||||||
auto &c = dst.emplace_back(std::make_unique<GRFConfig>(*s));
|
auto &c = dst.emplace_back(std::make_unique<GRFConfig>(*s));
|
||||||
AssignBit(c->flags, GCF_INIT_ONLY, init_only);
|
if (init_only) {
|
||||||
|
c->flags.Set(GRFConfigFlag::InitOnly);
|
||||||
|
} else {
|
||||||
|
c->flags.Reset(GRFConfigFlag::InitOnly);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,15 +433,15 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig)
|
||||||
|
|
||||||
for (auto &c : grfconfig) {
|
for (auto &c : grfconfig) {
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
|
||||||
if (f == nullptr || HasBit(f->flags, GCF_INVALID)) {
|
if (f == nullptr || f->flags.Test(GRFConfigFlag::Invalid)) {
|
||||||
/* If we have not found the exactly matching GRF try to find one with the
|
/* If we have not found the exactly matching GRF try to find one with the
|
||||||
* same grfid, as it most likely is compatible */
|
* same grfid, as it most likely is compatible */
|
||||||
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
|
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
|
||||||
if (f != nullptr) {
|
if (f != nullptr) {
|
||||||
Debug(grf, 1, "NewGRF {:08X} ({}) not found; checksum {}. Compatibility mode on", std::byteswap(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
|
Debug(grf, 1, "NewGRF {:08X} ({}) not found; checksum {}. Compatibility mode on", std::byteswap(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
|
||||||
if (!HasBit(c->flags, GCF_COMPATIBLE)) {
|
if (!c->flags.Test(GRFConfigFlag::Compatible)) {
|
||||||
/* Preserve original_md5sum after it has been assigned */
|
/* Preserve original_md5sum after it has been assigned */
|
||||||
SetBit(c->flags, GCF_COMPATIBLE);
|
c->flags.Set(GRFConfigFlag::Compatible);
|
||||||
c->original_md5sum = c->ident.md5sum;
|
c->original_md5sum = c->ident.md5sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,9 +461,9 @@ compatible_grf:
|
||||||
/* The filename could be the filename as in the savegame. As we need
|
/* The filename could be the filename as in the savegame. As we need
|
||||||
* to load the GRF here, we need the correct filename, so overwrite that
|
* to load the GRF here, we need the correct filename, so overwrite that
|
||||||
* in any case and set the name and info when it is not set already.
|
* in any case and set the name and info when it is not set already.
|
||||||
* When the GCF_COPY flag is set, it is certain that the filename is
|
* When the GRFConfigFlag::Copy flag is set, it is certain that the filename is
|
||||||
* already a local one, so there is no need to replace it. */
|
* already a local one, so there is no need to replace it. */
|
||||||
if (!HasBit(c->flags, GCF_COPY)) {
|
if (!c->flags.Test(GRFConfigFlag::Copy)) {
|
||||||
c->filename = f->filename;
|
c->filename = f->filename;
|
||||||
c->ident.md5sum = f->ident.md5sum;
|
c->ident.md5sum = f->ident.md5sum;
|
||||||
c->name = f->name;
|
c->name = f->name;
|
||||||
|
@ -605,7 +610,7 @@ const GRFConfig *FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5
|
||||||
/* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
|
/* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
|
||||||
if (md5sum != nullptr || mode == FGCM_ANY) return c.get();
|
if (md5sum != nullptr || mode == FGCM_ANY) return c.get();
|
||||||
/* Skip incompatible stuff, unless explicitly allowed */
|
/* Skip incompatible stuff, unless explicitly allowed */
|
||||||
if (mode != FGCM_NEWEST && HasBit(c->flags, GCF_INVALID)) continue;
|
if (mode != FGCM_NEWEST && c->flags.Test(GRFConfigFlag::Invalid)) continue;
|
||||||
/* check version compatibility */
|
/* check version compatibility */
|
||||||
if (mode == FGCM_COMPATIBLE && !c->IsCompatible(desired_version)) continue;
|
if (mode == FGCM_COMPATIBLE && !c->IsCompatible(desired_version)) continue;
|
||||||
/* remember the newest one as "the best" */
|
/* remember the newest one as "the best" */
|
||||||
|
|
|
@ -17,16 +17,17 @@
|
||||||
#include "3rdparty/md5/md5.h"
|
#include "3rdparty/md5/md5.h"
|
||||||
|
|
||||||
/** GRF config bit flags */
|
/** GRF config bit flags */
|
||||||
enum GCF_Flags : uint8_t {
|
enum GRFConfigFlag : uint8_t {
|
||||||
GCF_SYSTEM, ///< GRF file is an openttd-internal system grf
|
System, ///< GRF file is an openttd-internal system grf
|
||||||
GCF_UNSAFE, ///< GRF file is unsafe for static usage
|
Unsafe, ///< GRF file is unsafe for static usage
|
||||||
GCF_STATIC, ///< GRF file is used statically (can be used in any MP game)
|
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)
|
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
|
Copy, ///< The data is copied from a grf in _all_grfs
|
||||||
GCF_INIT_ONLY, ///< GRF file is processed up to GLS_INIT
|
InitOnly, ///< GRF file is processed up to GLS_INIT
|
||||||
GCF_RESERVED, ///< GRF file passed GLS_RESERVE stage
|
Reserved, ///< GRF file passed GLS_RESERVE stage
|
||||||
GCF_INVALID, ///< GRF is unusable with this version of OpenTTD
|
Invalid, ///< GRF is unusable with this version of OpenTTD
|
||||||
};
|
};
|
||||||
|
using GRFConfigFlags = EnumBitSet<GRFConfigFlag, uint8_t>;
|
||||||
|
|
||||||
/** Status of GRF */
|
/** Status of GRF */
|
||||||
enum GRFStatus : uint8_t {
|
enum GRFStatus : uint8_t {
|
||||||
|
@ -172,7 +173,7 @@ struct GRFConfig {
|
||||||
|
|
||||||
uint32_t version = 0; ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown
|
uint32_t version = 0; ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown
|
||||||
uint32_t min_loadable_version = 0; ///< NOSAVE: Minimum compatible version a NewGRF can define
|
uint32_t min_loadable_version = 0; ///< NOSAVE: Minimum compatible version a NewGRF can define
|
||||||
uint8_t flags = 0; ///< NOSAVE: GCF_Flags, bitset
|
GRFConfigFlags flags = {}; ///< NOSAVE: GCF_Flags, bitset
|
||||||
GRFStatus status = GCS_UNKNOWN; ///< NOSAVE: GRFStatus, enum
|
GRFStatus status = GCS_UNKNOWN; ///< NOSAVE: GRFStatus, enum
|
||||||
GRFBugs grf_bugs = {}; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
|
GRFBugs grf_bugs = {}; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
|
||||||
uint8_t num_valid_params = MAX_NUM_PARAMS; ///< NOSAVE: Number of valid parameters (action 0x14)
|
uint8_t num_valid_params = MAX_NUM_PARAMS; ///< NOSAVE: Number of valid parameters (action 0x14)
|
||||||
|
@ -205,7 +206,7 @@ enum FindGRFConfigMode : uint8_t {
|
||||||
FGCM_EXACT, ///< Only find Grfs matching md5sum
|
FGCM_EXACT, ///< Only find Grfs matching md5sum
|
||||||
FGCM_COMPATIBLE, ///< Find best compatible Grf wrt. desired_version
|
FGCM_COMPATIBLE, ///< Find best compatible Grf wrt. desired_version
|
||||||
FGCM_NEWEST, ///< Find newest Grf
|
FGCM_NEWEST, ///< Find newest Grf
|
||||||
FGCM_NEWEST_VALID,///< Find newest Grf, ignoring Grfs with GCF_INVALID set
|
FGCM_NEWEST_VALID,///< Find newest Grf, ignoring Grfs with GRFConfigFlag::Invalid set
|
||||||
FGCM_ANY, ///< Use first found
|
FGCM_ANY, ///< Use first found
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -128,8 +128,8 @@ static void ShowNewGRFInfo(const GRFConfig &c, const Rect &r, bool show_params)
|
||||||
/* Show flags */
|
/* Show flags */
|
||||||
if (c.status == GCS_NOT_FOUND) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NOT_FOUND);
|
if (c.status == GCS_NOT_FOUND) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NOT_FOUND);
|
||||||
if (c.status == GCS_DISABLED) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_DISABLED);
|
if (c.status == GCS_DISABLED) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_DISABLED);
|
||||||
if (HasBit(c.flags, GCF_INVALID)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
|
if (c.flags.Test(GRFConfigFlag::Invalid)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
|
||||||
if (HasBit(c.flags, GCF_COMPATIBLE)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
|
if (c.flags.Test(GRFConfigFlag::Compatible)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
|
||||||
|
|
||||||
/* Draw GRF info if it exists */
|
/* Draw GRF info if it exists */
|
||||||
if (!StrEmpty(c.GetDescription())) {
|
if (!StrEmpty(c.GetDescription())) {
|
||||||
|
@ -834,9 +834,9 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
|
|
||||||
/* Do not show a "not-failure" colour when it actually failed to load */
|
/* Do not show a "not-failure" colour when it actually failed to load */
|
||||||
if (pal != PALETTE_TO_RED) {
|
if (pal != PALETTE_TO_RED) {
|
||||||
if (HasBit(c.flags, GCF_STATIC)) {
|
if (c.flags.Test(GRFConfigFlag::Static)) {
|
||||||
pal = PALETTE_TO_GREY;
|
pal = PALETTE_TO_GREY;
|
||||||
} else if (HasBit(c.flags, GCF_COMPATIBLE)) {
|
} else if (c.flags.Test(GRFConfigFlag::Compatible)) {
|
||||||
pal = PALETTE_TO_ORANGE;
|
pal = PALETTE_TO_ORANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1081,7 +1081,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
}
|
}
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
if (click_count == 1) {
|
if (click_count == 1) {
|
||||||
if (this->editable && this->avail_sel != nullptr && !HasBit(this->avail_sel->flags, GCF_INVALID)) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
|
if (this->editable && this->avail_sel != nullptr && !this->avail_sel->flags.Test(GRFConfigFlag::Invalid)) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* With double click, continue */
|
/* With double click, continue */
|
||||||
|
@ -1089,7 +1089,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_NS_ADD:
|
case WID_NS_ADD:
|
||||||
if (this->avail_sel == nullptr || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) break;
|
if (this->avail_sel == nullptr || !this->editable || this->avail_sel->flags.Test(GRFConfigFlag::Invalid)) break;
|
||||||
|
|
||||||
this->AddGRFToActive();
|
this->AddGRFToActive();
|
||||||
break;
|
break;
|
||||||
|
@ -1221,11 +1221,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
case GOID_NEWGRF_RESCANNED:
|
case GOID_NEWGRF_RESCANNED:
|
||||||
/* Search the list for items that are now found and mark them as such. */
|
/* Search the list for items that are now found and mark them as such. */
|
||||||
for (auto &c : this->actives) {
|
for (auto &c : this->actives) {
|
||||||
bool compatible = HasBit(c->flags, GCF_COMPATIBLE);
|
bool compatible = c->flags.Test(GRFConfigFlag::Compatible);
|
||||||
if (c->status != GCS_NOT_FOUND && !compatible) continue;
|
if (c->status != GCS_NOT_FOUND && !compatible) continue;
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, compatible ? &c->original_md5sum : &c->ident.md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, compatible ? &c->original_md5sum : &c->ident.md5sum);
|
||||||
if (f == nullptr || HasBit(f->flags, GCF_INVALID)) continue;
|
if (f == nullptr || f->flags.Test(GRFConfigFlag::Invalid)) continue;
|
||||||
|
|
||||||
c = std::make_unique<GRFConfig>(*f);
|
c = std::make_unique<GRFConfig>(*f);
|
||||||
}
|
}
|
||||||
|
@ -1263,7 +1263,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
WID_NS_PRESET_LIST,
|
WID_NS_PRESET_LIST,
|
||||||
WID_NS_TOGGLE_PALETTE
|
WID_NS_TOGGLE_PALETTE
|
||||||
);
|
);
|
||||||
this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == nullptr || HasBit(this->avail_sel->flags, GCF_INVALID));
|
this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == nullptr || this->avail_sel->flags.Test(GRFConfigFlag::Invalid));
|
||||||
this->SetWidgetDisabledState(WID_NS_UPGRADE, !this->editable || this->actives.empty() || !this->CanUpgradeCurrent());
|
this->SetWidgetDisabledState(WID_NS_UPGRADE, !this->editable || this->actives.empty() || !this->CanUpgradeCurrent());
|
||||||
|
|
||||||
bool disable_all = this->active_sel == nullptr || !this->editable;
|
bool disable_all = this->active_sel == nullptr || !this->editable;
|
||||||
|
@ -1296,7 +1296,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||||
bool has_compatible = false;
|
bool has_compatible = false;
|
||||||
for (const auto &c : this->actives) {
|
for (const auto &c : this->actives) {
|
||||||
has_missing |= c->status == GCS_NOT_FOUND;
|
has_missing |= c->status == GCS_NOT_FOUND;
|
||||||
has_compatible |= HasBit(c->flags, GCF_COMPATIBLE);
|
has_compatible |= c->flags.Test(GRFConfigFlag::Compatible);
|
||||||
}
|
}
|
||||||
StringID text;
|
StringID text;
|
||||||
StringID tool_tip;
|
StringID tool_tip;
|
||||||
|
@ -1443,7 +1443,7 @@ private:
|
||||||
if (_settings_client.gui.newgrf_show_old_versions) {
|
if (_settings_client.gui.newgrf_show_old_versions) {
|
||||||
this->avails.push_back(c.get());
|
this->avails.push_back(c.get());
|
||||||
} else {
|
} else {
|
||||||
const GRFConfig *best = FindGRFConfig(c->ident.grfid, HasBit(c->flags, GCF_INVALID) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
|
const GRFConfig *best = FindGRFConfig(c->ident.grfid, c->flags.Test(GRFConfigFlag::Invalid) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
|
||||||
/* Never triggers; FindGRFConfig returns either c, or a newer version of c. */
|
/* Never triggers; FindGRFConfig returns either c, or a newer version of c. */
|
||||||
assert(best != nullptr);
|
assert(best != nullptr);
|
||||||
|
|
||||||
|
@ -1481,12 +1481,12 @@ private:
|
||||||
*/
|
*/
|
||||||
bool AddGRFToActive(int ins_pos = -1)
|
bool AddGRFToActive(int ins_pos = -1)
|
||||||
{
|
{
|
||||||
if (this->avail_sel == nullptr || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;
|
if (this->avail_sel == nullptr || !this->editable || this->avail_sel->flags.Test(GRFConfigFlag::Invalid)) return false;
|
||||||
|
|
||||||
CloseWindowByClass(WC_TEXTFILE);
|
CloseWindowByClass(WC_TEXTFILE);
|
||||||
|
|
||||||
/* Get number of non-static NewGRFs. */
|
/* Get number of non-static NewGRFs. */
|
||||||
size_t count = std::ranges::count_if(this->actives, [](const auto &gc) { return !HasBit(gc->flags, GCF_STATIC); });
|
size_t count = std::ranges::count_if(this->actives, [](const auto &gc) { return !gc->flags.Test(GRFConfigFlag::Static); });
|
||||||
if (count >= NETWORK_MAX_GRF_COUNT) {
|
if (count >= NETWORK_MAX_GRF_COUNT) {
|
||||||
ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO);
|
ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1527,14 +1527,14 @@ void ShowMissingContentWindow(const GRFConfigList &list)
|
||||||
/* Only show the things in the current list, or everything when nothing's selected */
|
/* Only show the things in the current list, or everything when nothing's selected */
|
||||||
ContentVector cv;
|
ContentVector cv;
|
||||||
for (const auto &c : list) {
|
for (const auto &c : list) {
|
||||||
if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
|
if (c->status != GCS_NOT_FOUND && !c->flags.Test(GRFConfigFlag::Compatible)) continue;
|
||||||
|
|
||||||
ContentInfo *ci = new ContentInfo();
|
ContentInfo *ci = new ContentInfo();
|
||||||
ci->type = CONTENT_TYPE_NEWGRF;
|
ci->type = CONTENT_TYPE_NEWGRF;
|
||||||
ci->state = ContentInfo::DOES_NOT_EXIST;
|
ci->state = ContentInfo::DOES_NOT_EXIST;
|
||||||
ci->name = c->GetName();
|
ci->name = c->GetName();
|
||||||
ci->unique_id = std::byteswap(c->ident.grfid);
|
ci->unique_id = std::byteswap(c->ident.grfid);
|
||||||
ci->md5sum = HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum;
|
ci->md5sum = c->flags.Test(GRFConfigFlag::Compatible) ? c->original_md5sum : c->ident.md5sum;
|
||||||
cv.push_back(ci);
|
cv.push_back(ci);
|
||||||
}
|
}
|
||||||
ShowNetworkContentListWindow(cv.empty() ? nullptr : &cv, CONTENT_TYPE_NEWGRF);
|
ShowNetworkContentListWindow(cv.empty() ? nullptr : &cv, CONTENT_TYPE_NEWGRF);
|
||||||
|
|
|
@ -244,7 +244,7 @@ static void WriteSavegameInfo(const std::string &name)
|
||||||
if (_load_check_data.HasNewGrfs()) {
|
if (_load_check_data.HasNewGrfs()) {
|
||||||
for (const auto &c : _load_check_data.grfconfig) {
|
for (const auto &c : _load_check_data.grfconfig) {
|
||||||
fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", std::byteswap(c->ident.grfid),
|
fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", std::byteswap(c->ident.grfid),
|
||||||
FormatArrayAsHex(HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum), c->filename);
|
FormatArrayAsHex(c->flags.Test(GRFConfigFlag::Compatible) ? c->original_md5sum : c->ident.md5sum), c->filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||||
message.reserve(1024);
|
message.reserve(1024);
|
||||||
message += "Loading your savegame caused OpenTTD to crash.\n";
|
message += "Loading your savegame caused OpenTTD to crash.\n";
|
||||||
|
|
||||||
_saveload_crash_with_missing_newgrfs = std::ranges::any_of(_grfconfig, [](const auto &c) { return HasBit(c->flags, GCF_COMPATIBLE) || c->status == GCS_NOT_FOUND; });
|
_saveload_crash_with_missing_newgrfs = std::ranges::any_of(_grfconfig, [](const auto &c) { return c->flags.Test(GRFConfigFlag::Compatible) || c->status == GCS_NOT_FOUND; });
|
||||||
|
|
||||||
if (_saveload_crash_with_missing_newgrfs) {
|
if (_saveload_crash_with_missing_newgrfs) {
|
||||||
message +=
|
message +=
|
||||||
|
@ -386,7 +386,7 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||||
"The missing/compatible NewGRFs are:\n";
|
"The missing/compatible NewGRFs are:\n";
|
||||||
|
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
if (c->flags.Test(GRFConfigFlag::Compatible)) {
|
||||||
const GRFIdentifier &replaced = _gamelog.GetOverriddenIdentifier(*c);
|
const GRFIdentifier &replaced = _gamelog.GetOverriddenIdentifier(*c);
|
||||||
fmt::format_to(std::back_inserter(message), "NewGRF {:08X} (checksum {}) not found.\n Loaded NewGRF \"{}\" (checksum {}) with same GRF ID instead.\n",
|
fmt::format_to(std::back_inserter(message), "NewGRF {:08X} (checksum {}) not found.\n Loaded NewGRF \"{}\" (checksum {}) with same GRF ID instead.\n",
|
||||||
std::byteswap(c->ident.grfid), FormatArrayAsHex(c->original_md5sum), c->filename, FormatArrayAsHex(replaced.md5sum));
|
std::byteswap(c->ident.grfid), FormatArrayAsHex(c->original_md5sum), c->filename, FormatArrayAsHex(replaced.md5sum));
|
||||||
|
@ -708,7 +708,7 @@ bool AfterLoadGame()
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (c->status == GCS_NOT_FOUND) {
|
if (c->status == GCS_NOT_FOUND) {
|
||||||
_gamelog.GRFRemove(c->ident.grfid);
|
_gamelog.GRFRemove(c->ident.grfid);
|
||||||
} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
} else if (c->flags.Test(GRFConfigFlag::Compatible)) {
|
||||||
_gamelog.GRFCompatible(c->ident);
|
_gamelog.GRFCompatible(c->ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ struct NGRFChunkHandler : ChunkHandler {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (HasBit(c->flags, GCF_STATIC) || HasBit(c->flags, GCF_INIT_ONLY)) continue;
|
if (c->flags.Any({GRFConfigFlag::Static, GRFConfigFlag::InitOnly})) continue;
|
||||||
this->SaveParameters(*c);
|
this->SaveParameters(*c);
|
||||||
SlSetArrayIndex(index++);
|
SlSetArrayIndex(index++);
|
||||||
SlObject(c.get(), description);
|
SlObject(c.get(), description);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
ScriptNewGRFList::ScriptNewGRFList()
|
ScriptNewGRFList::ScriptNewGRFList()
|
||||||
{
|
{
|
||||||
for (const auto &c : _grfconfig) {
|
for (const auto &c : _grfconfig) {
|
||||||
if (!HasBit(c->flags, GCF_STATIC)) {
|
if (!c->flags.Test(GRFConfigFlag::Static)) {
|
||||||
this->AddItem(std::byteswap(c->ident.grfid));
|
this->AddItem(std::byteswap(c->ident.grfid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,14 +28,14 @@ ScriptNewGRFList::ScriptNewGRFList()
|
||||||
{
|
{
|
||||||
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
|
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
|
||||||
|
|
||||||
return std::ranges::any_of(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
|
return std::ranges::any_of(_grfconfig, [grfid](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static) && c->ident.grfid == grfid; });
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ SQInteger ScriptNewGRF::GetVersion(SQInteger grfid)
|
/* static */ SQInteger ScriptNewGRF::GetVersion(SQInteger grfid)
|
||||||
{
|
{
|
||||||
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
|
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
|
||||||
|
|
||||||
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
|
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static) && c->ident.grfid == grfid; });
|
||||||
if (it != std::end(_grfconfig)) return (*it)->version;
|
if (it != std::end(_grfconfig)) return (*it)->version;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -45,7 +45,7 @@ ScriptNewGRFList::ScriptNewGRFList()
|
||||||
{
|
{
|
||||||
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
|
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
|
||||||
|
|
||||||
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
|
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static) && c->ident.grfid == grfid; });
|
||||||
if (it != std::end(_grfconfig)) return (*it)->GetName();
|
if (it != std::end(_grfconfig)) return (*it)->GetName();
|
||||||
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
|
@ -1107,14 +1107,14 @@ static GRFConfigList GRFLoadConfig(const IniFile &ini, const char *grpname, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if item is valid */
|
/* Check if item is valid */
|
||||||
if (!FillGRFDetails(*c, is_static) || HasBit(c->flags, GCF_INVALID)) {
|
if (!FillGRFDetails(*c, is_static) || c->flags.Test(GRFConfigFlag::Invalid)) {
|
||||||
if (c->status == GCS_NOT_FOUND) {
|
if (c->status == GCS_NOT_FOUND) {
|
||||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
|
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
|
||||||
} else if (HasBit(c->flags, GCF_UNSAFE)) {
|
} else if (c->flags.Test(GRFConfigFlag::Unsafe)) {
|
||||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
|
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
|
||||||
} else if (HasBit(c->flags, GCF_SYSTEM)) {
|
} else if (c->flags.Test(GRFConfigFlag::System)) {
|
||||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
|
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
|
||||||
} else if (HasBit(c->flags, GCF_INVALID)) {
|
} else if (c->flags.Test(GRFConfigFlag::Invalid)) {
|
||||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
|
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
|
||||||
} else {
|
} else {
|
||||||
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
|
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
|
||||||
|
@ -1136,7 +1136,7 @@ static GRFConfigList GRFLoadConfig(const IniFile &ini, const char *grpname, bool
|
||||||
|
|
||||||
if (is_static) {
|
if (is_static) {
|
||||||
/* Mark file as static to avoid saving in savegame. */
|
/* Mark file as static to avoid saving in savegame. */
|
||||||
SetBit(c->flags, GCF_STATIC);
|
c->flags.Set(GRFConfigFlag::Static);
|
||||||
} else if (++num_grfs > NETWORK_MAX_GRF_COUNT) {
|
} else if (++num_grfs > NETWORK_MAX_GRF_COUNT) {
|
||||||
/* Check we will not load more non-static NewGRFs than allowed. This could trigger issues for game servers. */
|
/* Check we will not load more non-static NewGRFs than allowed. This could trigger issues for game servers. */
|
||||||
ShowErrorMessage(STR_CONFIG_ERROR, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, WL_CRITICAL);
|
ShowErrorMessage(STR_CONFIG_ERROR, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, WL_CRITICAL);
|
||||||
|
|
|
@ -369,7 +369,7 @@ void SurveyGrfs(nlohmann::json &survey)
|
||||||
if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_UNSET) grf["blitter"] = "unset";
|
if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_UNSET) grf["blitter"] = "unset";
|
||||||
if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_32BPP) grf["blitter"] = "32bpp";
|
if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_32BPP) grf["blitter"] = "32bpp";
|
||||||
|
|
||||||
grf["is_static"] = HasBit(c->flags, GCF_STATIC);
|
grf["is_static"] = c->flags.Test(GRFConfigFlag::Static);
|
||||||
grf["parameters"] = std::span<const uint32_t>(c->param);
|
grf["parameters"] = std::span<const uint32_t>(c->param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue