1
0
Fork 0

Codechange: Store grfid with entity grfprops.

This allows using the grfid without having to dereference the grffile pointer.

Uses no extra storage as it fits within otherwise wasted padding space.
pull/13124/head
Peter Nelson 2024-11-23 14:05:42 +00:00 committed by Peter Nelson
parent e750d10cee
commit e73d6fcaac
24 changed files with 132 additions and 112 deletions

View File

@ -483,8 +483,8 @@ static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
td->str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
}
if (is->grf_prop.grffile != nullptr) {
td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->GetName();
if (is->grf_prop.HasGrfFile()) {
td->grf = GetGRFConfig(is->grf_prop.grfid)->GetName();
}
}
@ -1826,7 +1826,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROD_CHANGE_BUILD, 0, Random(), i, type, INVALID_TILE);
if (res != CALLBACK_FAILED) {
if (res < PRODLEVEL_MINIMUM || res > PRODLEVEL_MAXIMUM) {
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_PROD_CHANGE_BUILD, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_PROD_CHANGE_BUILD, res);
} else {
i->prod_level = res;
i->RecomputeProductionMultipliers();
@ -1851,7 +1851,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
if (HasBit(indspec->callback_mask, CBM_IND_DECIDE_COLOUR)) {
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
if (res != CALLBACK_FAILED) {
if (GB(res, 4, 11) != 0) ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_DECIDE_COLOUR, res);
if (GB(res, 4, 11) != 0) ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_DECIDE_COLOUR, res);
i->random_colour = static_cast<Colours>(GB(res, 0, 4));
}
}
@ -1865,7 +1865,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
if (res == CALLBACK_FAILED || GB(res, 0, 8) == UINT8_MAX) break;
if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
break;
}
CargoID cargo = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
@ -1881,12 +1881,12 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
/* Verify valid cargo */
if (std::ranges::find(indspec->accepts_cargo, cargo) == std::end(indspec->accepts_cargo)) {
/* Cargo not in spec, error in NewGRF */
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
break;
}
if (std::any_of(std::begin(i->accepted), std::begin(i->accepted) + j, [&cargo](const auto &a) { return a.cargo == cargo; })) {
/* Duplicate cargo */
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
break;
}
Industry::AcceptedCargo &a = i->accepted.emplace_back();
@ -1903,7 +1903,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
uint16_t res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
if (res == CALLBACK_FAILED || GB(res, 0, 8) == UINT8_MAX) break;
if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
break;
}
CargoID cargo = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
@ -1917,12 +1917,12 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
/* Verify valid cargo */
if (std::ranges::find(indspec->produced_cargo, cargo) == std::end(indspec->produced_cargo)) {
/* Cargo not in spec, error in NewGRF */
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
break;
}
if (std::any_of(std::begin(i->produced), std::begin(i->produced) + j, [&cargo](const auto &p) { return p.cargo == cargo; })) {
/* Duplicate cargo */
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
break;
}
Industry::ProducedCargo &p = i->produced.emplace_back();
@ -2812,7 +2812,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
if (res != CALLBACK_FAILED) { // failed callback means "do nothing"
suppress_message = HasBit(res, 7);
/* Get the custom message if any */
if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grffile->grfid, GB(GetRegister(0x100), 0, 16));
if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grfid, GB(GetRegister(0x100), 0, 16));
res = GB(res, 0, 4);
switch (res) {
default: NOT_REACHED();

View File

@ -104,12 +104,12 @@ static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind,
if (GB(callback, 0, 8) == 0xFF) return;
if (callback < 0x400) {
StartTextRefStackUsage(indspec->grf_prop.grffile, 6);
suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback));
suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grfid, 0xD000 + callback));
StopTextRefStackUsage();
suffix.display = CSD_CARGO_AMOUNT_TEXT;
return;
}
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback);
return;
} else { // GRF version 8 or higher.
@ -120,19 +120,19 @@ static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind,
}
if (callback < 0x400) {
StartTextRefStackUsage(indspec->grf_prop.grffile, 6);
suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback));
suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grfid, 0xD000 + callback));
StopTextRefStackUsage();
suffix.display = CSD_CARGO_AMOUNT_TEXT;
return;
}
if (callback >= 0x800 && callback < 0xC00) {
StartTextRefStackUsage(indspec->grf_prop.grffile, 6);
suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 - 0x800 + callback));
suffix.text = GetString(GetGRFStringID(indspec->grf_prop.grfid, 0xD000 - 0x800 + callback));
StopTextRefStackUsage();
suffix.display = CSD_CARGO_TEXT;
return;
}
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback);
return;
}
}
@ -477,7 +477,7 @@ public:
}
d = maxdim(d, strdim);
if (indsp->grf_prop.grffile != nullptr) {
if (indsp->grf_prop.HasGrfFile()) {
/* Reserve a few extra lines for text from an industry NewGRF. */
extra_lines_newgrf = 4;
}
@ -588,9 +588,9 @@ public:
uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_FUND_MORE_TEXT, 0, 0, nullptr, this->selected_type, INVALID_TILE);
if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
if (callback_res > 0x400) {
ErrorUnknownCallbackResult(indsp->grf_prop.grffile->grfid, CBID_INDUSTRY_FUND_MORE_TEXT, callback_res);
ErrorUnknownCallbackResult(indsp->grf_prop.grfid, CBID_INDUSTRY_FUND_MORE_TEXT, callback_res);
} else {
StringID str = GetGRFStringID(indsp->grf_prop.grffile->grfid, 0xD000 + callback_res); // No. here's the new string
StringID str = GetGRFStringID(indsp->grf_prop.grfid, 0xD000 + callback_res); // No. here's the new string
if (str != STR_UNDEFINED) {
StartTextRefStackUsage(indsp->grf_prop.grffile, 6);
DrawStringMultiLine(ir, str, TC_YELLOW);
@ -981,9 +981,9 @@ public:
uint16_t callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
if (callback_res > 0x400) {
ErrorUnknownCallbackResult(ind->grf_prop.grffile->grfid, CBID_INDUSTRY_WINDOW_MORE_TEXT, callback_res);
ErrorUnknownCallbackResult(ind->grf_prop.grfid, CBID_INDUSTRY_WINDOW_MORE_TEXT, callback_res);
} else {
StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
StringID message = GetGRFStringID(ind->grf_prop.grfid, 0xD000 + callback_res);
if (message != STR_NULL && message != STR_UNDEFINED) {
ir.top += WidgetDimensions::scaled.vsep_wide;

View File

@ -632,7 +632,10 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte
EngineID engine = _engine_mngr.GetID(type, internal_id, scope_grfid);
if (engine != INVALID_ENGINE) {
Engine *e = Engine::Get(engine);
if (e->grf_prop.grffile == nullptr) e->grf_prop.grffile = file;
if (!e->grf_prop.HasGrfFile()) {
e->grf_prop.grfid = file->grfid;
e->grf_prop.grffile = file;
}
return e;
}
}
@ -642,7 +645,8 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte
if (engine != INVALID_ENGINE) {
Engine *e = Engine::Get(engine);
if (e->grf_prop.grffile == nullptr) {
if (!e->grf_prop.HasGrfFile()) {
e->grf_prop.grfid = file->grfid;
e->grf_prop.grffile = file;
GrfMsg(5, "Replaced engine at index {} for GRFID {:x}, type {}, index {}", e->index, BSWAP32(file->grfid), type, internal_id);
}
@ -667,6 +671,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte
/* ... it's not, so create a new one based off an existing engine */
Engine *e = new Engine(type, internal_id);
e->grf_prop.grfid = file->grfid;
e->grf_prop.grffile = file;
/* Reserve the engine slot */
@ -2463,6 +2468,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt
housespec->enabled = true;
housespec->grf_prop.local_id = hid + i;
housespec->grf_prop.subst_id = subs_id;
housespec->grf_prop.grfid = _cur.grffile->grfid;
housespec->grf_prop.grffile = _cur.grffile;
/* Set default colours for randomization, used if not overridden. */
housespec->random_colour[0] = COLOUR_RED;
@ -3327,6 +3333,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr
tsp->grf_prop.local_id = indtid + i;
tsp->grf_prop.subst_id = subs_id;
tsp->grf_prop.grfid = _cur.grffile->grfid;
tsp->grf_prop.grffile = _cur.grffile;
_industile_mngr.AddEntityID(indtid + i, _cur.grffile->grfid, subs_id); // pre-reserve the tile slot
}
@ -3584,6 +3591,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
indsp->enabled = true;
indsp->grf_prop.local_id = indid + i;
indsp->grf_prop.subst_id = subs_id;
indsp->grf_prop.grfid = _cur.grffile->grfid;
indsp->grf_prop.grffile = _cur.grffile;
/* If the grf industry needs to check its surrounding upon creation, it should
* rely on callbacks, not on the original placement functions */
@ -3956,6 +3964,7 @@ static ChangeInfoResult AirportChangeInfo(uint airport, int numinfo, int prop, B
as->enabled = true;
as->grf_prop.local_id = airport + i;
as->grf_prop.subst_id = subs_id;
as->grf_prop.grfid = _cur.grffile->grfid;
as->grf_prop.grffile = _cur.grffile;
/* override the default airport */
_airport_mngr.Add(airport + i, _cur.grffile->grfid, subs_id);
@ -4717,6 +4726,7 @@ static ChangeInfoResult AirportTilesChangeInfo(uint airtid, int numinfo, int pro
tsp->grf_prop.local_id = airtid + i;
tsp->grf_prop.subst_id = subs_id;
tsp->grf_prop.grfid = _cur.grffile->grfid;
tsp->grf_prop.grffile = _cur.grffile;
_airporttile_mngr.AddEntityID(airtid + i, _cur.grffile->grfid, subs_id); // pre-reserve the tile slot
}
@ -5771,12 +5781,13 @@ static void StationMapSpriteGroup(ByteReader &buf, uint8_t idcount)
continue;
}
if (statspec->grf_prop.grffile != nullptr) {
if (statspec->grf_prop.HasGrfFile()) {
GrfMsg(1, "StationMapSpriteGroup: Station {} mapped multiple times, skipping", station);
continue;
}
statspec->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT] = _cur.spritegroups[groupid];
statspec->grf_prop.grfid = _cur.grffile->grfid;
statspec->grf_prop.grffile = _cur.grffile;
statspec->grf_prop.local_id = station;
StationClass::Assign(statspec);
@ -5955,12 +5966,13 @@ static void ObjectMapSpriteGroup(ByteReader &buf, uint8_t idcount)
continue;
}
if (spec->grf_prop.grffile != nullptr) {
if (spec->grf_prop.HasGrfFile()) {
GrfMsg(1, "ObjectMapSpriteGroup: Object {} mapped multiple times, skipping", object);
continue;
}
spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_DEFAULT] = _cur.spritegroups[groupid];
spec->grf_prop.grfid = _cur.grffile->grfid;
spec->grf_prop.grffile = _cur.grffile;
spec->grf_prop.local_id = object;
}
@ -6141,12 +6153,13 @@ static void RoadStopMapSpriteGroup(ByteReader &buf, uint8_t idcount)
continue;
}
if (roadstopspec->grf_prop.grffile != nullptr) {
if (roadstopspec->grf_prop.HasGrfFile()) {
GrfMsg(1, "RoadStopMapSpriteGroup: Road stop {} mapped multiple times, skipping", roadstop);
continue;
}
roadstopspec->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT] = _cur.spritegroups[groupid];
roadstopspec->grf_prop.grfid = _cur.grffile->grfid;
roadstopspec->grf_prop.grffile = _cur.grffile;
roadstopspec->grf_prop.local_id = roadstop;
RoadStopClass::Assign(roadstopspec);
@ -9489,25 +9502,25 @@ static void FinaliseIndustriesArray()
/* process the conversion of text at the end, so to be sure everything will be fine
* and available. Check if it does not return undefind marker, which is a very good sign of a
* substitute industry who has not changed the string been examined, thus using it as such */
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
strid = GetGRFStringID(indsp->grf_prop.grfid, indsp->name);
if (strid != STR_UNDEFINED) indsp->name = strid;
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
strid = GetGRFStringID(indsp->grf_prop.grfid, indsp->closure_text);
if (strid != STR_UNDEFINED) indsp->closure_text = strid;
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
strid = GetGRFStringID(indsp->grf_prop.grfid, indsp->production_up_text);
if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
strid = GetGRFStringID(indsp->grf_prop.grfid, indsp->production_down_text);
if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
strid = GetGRFStringID(indsp->grf_prop.grfid, indsp->new_industry_text);
if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
if (indsp->station_name != STR_NULL) {
/* STR_NULL (0) can be set by grf. It has a meaning regarding assignation of the
* station's name. Don't want to lose the value, therefore, do not process. */
strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->station_name);
strid = GetGRFStringID(indsp->grf_prop.grfid, indsp->station_name);
if (strid != STR_UNDEFINED) indsp->station_name = strid;
}
@ -9522,9 +9535,9 @@ static void FinaliseIndustriesArray()
}
for (auto &indsp : _industry_specs) {
if (indsp.enabled && indsp.grf_prop.grffile != nullptr) {
if (indsp.enabled && indsp.grf_prop.HasGrfFile()) {
for (auto &conflicting : indsp.conflicting) {
conflicting = MapNewGRFIndustryType(conflicting, indsp.grf_prop.grffile->grfid);
conflicting = MapNewGRFIndustryType(conflicting, indsp.grf_prop.grfid);
}
}
if (!indsp.enabled) {
@ -9557,7 +9570,7 @@ static void FinaliseObjectsArray()
{
for (GRFFile * const file : _grf_files) {
for (auto &objectspec : file->objectspec) {
if (objectspec != nullptr && objectspec->grf_prop.grffile != nullptr && objectspec->IsEnabled()) {
if (objectspec != nullptr && objectspec->grf_prop.HasGrfFile() && objectspec->IsEnabled()) {
_object_mngr.SetEntitySpec(objectspec.get());
}
}

View File

@ -132,7 +132,7 @@ void BindAirportSpecs()
void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
{
uint8_t airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grffile->grfid, as->grf_prop.subst_id);
uint8_t airport_id = this->AddEntityID(as->grf_prop.local_id, as->grf_prop.grfid, as->grf_prop.subst_id);
if (airport_id == this->invalid_id) {
GrfMsg(1, "Airport.SetEntitySpec: Too many airports allocated. Ignoring.");
@ -145,7 +145,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
for (int i = 0; i < this->max_offset; i++) {
AirportSpec *overridden_as = AirportSpec::GetWithoutOverride(i);
if (this->entity_overrides[i] != as->grf_prop.local_id || this->grfid_overrides[i] != as->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != as->grf_prop.local_id || this->grfid_overrides[i] != as->grf_prop.grfid) continue;
overridden_as->grf_prop.override = airport_id;
overridden_as->enabled = false;
@ -277,9 +277,9 @@ StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t
uint16_t cb_res = object.ResolveCallback();
if (cb_res == CALLBACK_FAILED || cb_res == 0x400) return STR_UNDEFINED;
if (cb_res > 0x400) {
ErrorUnknownCallbackResult(as->grf_prop.grffile->grfid, callback, cb_res);
ErrorUnknownCallbackResult(as->grf_prop.grfid, callback, cb_res);
return STR_UNDEFINED;
}
return GetGRFStringID(as->grf_prop.grffile->grfid, 0xD000 + cb_res);
return GetGRFStringID(as->grf_prop.grfid, 0xD000 + cb_res);
}

View File

@ -66,7 +66,7 @@ void AirportTileSpec::ResetAirportTiles()
void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
{
StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grffile->grfid, airpts->grf_prop.subst_id);
StationGfx airpt_id = this->AddEntityID(airpts->grf_prop.local_id, airpts->grf_prop.grfid, airpts->grf_prop.subst_id);
if (airpt_id == this->invalid_id) {
GrfMsg(1, "AirportTile.SetEntitySpec: Too many airport tiles allocated. Ignoring.");
@ -79,7 +79,7 @@ void AirportTileOverrideManager::SetEntitySpec(const AirportTileSpec *airpts)
for (int i = 0; i < this->max_offset; i++) {
AirportTileSpec *overridden_airpts = &AirportTileSpec::tiles[i];
if (this->entity_overrides[i] != airpts->grf_prop.local_id || this->grfid_overrides[i] != airpts->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != airpts->grf_prop.local_id || this->grfid_overrides[i] != airpts->grf_prop.grfid) continue;
overridden_airpts->grf_prop.override = airpt_id;
overridden_airpts->enabled = false;
@ -141,7 +141,7 @@ static uint32_t GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint
/* Overridden */
const AirportTileSpec *tile_ovr = AirportTileSpec::Get(ats->grf_prop.override);
if (tile_ovr->grf_prop.grffile->grfid == cur_grfid) {
if (tile_ovr->grf_prop.grfid == cur_grfid) {
return tile_ovr->grf_prop.local_id; // same grf file
} else {
return 0xFFFE; // not the same grf file
@ -149,7 +149,7 @@ static uint32_t GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint
}
/* Not an 'old type' tile */
if (ats->grf_prop.spritegroup[0] != nullptr) { // tile has a spritegroup ?
if (ats->grf_prop.grffile->grfid == cur_grfid) { // same airport, same grf ?
if (ats->grf_prop.grfid == cur_grfid) { // same airport, same grf ?
return ats->grf_prop.local_id;
} else {
return 0xFFFE; // Defined in another grf file

View File

@ -58,7 +58,7 @@ struct AnimationBase {
if (HasBit(spec->callback_mask, Tbase::cbm_animation_speed)) {
uint16_t callback = GetCallback(Tbase::cb_animation_speed, 0, 0, spec, obj, tile, extra_data);
if (callback != CALLBACK_FAILED) {
if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, Tbase::cb_animation_speed, callback);
if (callback >= 0x100 && spec->grf_prop.grffile->grf_version >= 8) ErrorUnknownCallbackResult(spec->grf_prop.grfid, Tbase::cb_animation_speed, callback);
animation_speed = Clamp(callback & 0xFF, 0, 16);
}
}

View File

@ -131,7 +131,7 @@ const Tspec *NewGRFClass<Tspec, Tindex, Tmax>::GetByGrf(uint32_t grfid, uint16_t
for (const auto &spec : cls.spec) {
if (spec == nullptr) continue;
if (spec->grf_prop.local_id != local_id) continue;
if ((spec->grf_prop.grffile == nullptr ? 0 : spec->grf_prop.grffile->grfid) == grfid) return spec;
if (spec->grf_prop.grfid == grfid) return spec;
}
}

View File

@ -158,7 +158,7 @@ uint16_t OverrideManagerBase::GetSubstituteID(uint16_t entity_id) const
*/
void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
{
HouseID house_id = this->AddEntityID(hs->grf_prop.local_id, hs->grf_prop.grffile->grfid, hs->grf_prop.subst_id);
HouseID house_id = this->AddEntityID(hs->grf_prop.local_id, hs->grf_prop.grfid, hs->grf_prop.subst_id);
if (house_id == this->invalid_id) {
GrfMsg(1, "House.SetEntitySpec: Too many houses allocated. Ignoring.");
@ -175,7 +175,7 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
for (int i = 0; i < this->max_offset; i++) {
HouseSpec *overridden_hs = HouseSpec::Get(i);
if (this->entity_overrides[i] != hs->grf_prop.local_id || this->grfid_overrides[i] != hs->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != hs->grf_prop.local_id || this->grfid_overrides[i] != hs->grf_prop.grfid) continue;
overridden_hs->grf_prop.override = house_id;
this->entity_overrides[i] = this->invalid_id;
@ -222,7 +222,7 @@ uint16_t IndustryOverrideManager::AddEntityID(uint16_t grf_local_id, uint32_t gr
/* This industry must be one that is not available(enabled), mostly because of climate.
* And it must not already be used by a grf (grffile == nullptr).
* So reserve this slot here, as it is the chosen one */
if (!inds->enabled && inds->grf_prop.grffile == nullptr) {
if (!inds->enabled && !inds->grf_prop.HasGrfFile()) {
EntityIDMapping *map = &this->mappings[id];
if (map->entity_id == 0 && map->grfid == 0) {
@ -247,14 +247,14 @@ uint16_t IndustryOverrideManager::AddEntityID(uint16_t grf_local_id, uint32_t gr
void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
{
/* First step : We need to find if this industry is already specified in the savegame data. */
IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid);
IndustryType ind_id = this->GetID(inds->grf_prop.local_id, inds->grf_prop.grfid);
if (ind_id == this->invalid_id) {
/* Not found.
* Or it has already been overridden, so you've lost your place.
* Or it is a simple substitute.
* We need to find a free available slot */
ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grffile->grfid, inds->grf_prop.subst_id);
ind_id = this->AddEntityID(inds->grf_prop.local_id, inds->grf_prop.grfid, inds->grf_prop.subst_id);
inds->grf_prop.override = this->invalid_id; // make sure it will not be detected as overridden
}
@ -271,7 +271,7 @@ void IndustryOverrideManager::SetEntitySpec(IndustrySpec *inds)
void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
{
IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grffile->grfid, its->grf_prop.subst_id);
IndustryGfx indt_id = this->AddEntityID(its->grf_prop.local_id, its->grf_prop.grfid, its->grf_prop.subst_id);
if (indt_id == this->invalid_id) {
GrfMsg(1, "IndustryTile.SetEntitySpec: Too many industry tiles allocated. Ignoring.");
@ -284,7 +284,7 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
for (int i = 0; i < this->max_offset; i++) {
IndustryTileSpec *overridden_its = &_industry_tile_specs[i];
if (this->entity_overrides[i] != its->grf_prop.local_id || this->grfid_overrides[i] != its->grf_prop.grffile->grfid) continue;
if (this->entity_overrides[i] != its->grf_prop.local_id || this->grfid_overrides[i] != its->grf_prop.grfid) continue;
overridden_its->grf_prop.override = indt_id;
overridden_its->enabled = false;
@ -302,14 +302,14 @@ void IndustryTileOverrideManager::SetEntitySpec(const IndustryTileSpec *its)
void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
{
/* First step : We need to find if this object is already specified in the savegame data. */
ObjectType type = this->GetID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid);
ObjectType type = this->GetID(spec->grf_prop.local_id, spec->grf_prop.grfid);
if (type == this->invalid_id) {
/* Not found.
* Or it has already been overridden, so you've lost your place.
* Or it is a simple substitute.
* We need to find a free available slot */
type = this->AddEntityID(spec->grf_prop.local_id, spec->grf_prop.grffile->grfid, OBJECT_TRANSMITTER);
type = this->AddEntityID(spec->grf_prop.local_id, spec->grf_prop.grfid, OBJECT_TRANSMITTER);
}
if (type == this->invalid_id) {

View File

@ -309,8 +309,15 @@ bool Convert8bitBooleanCallback(const struct GRFFile *grffile, uint16_t cbid, ui
template <size_t Tcnt>
struct GRFFilePropsBase {
uint16_t local_id = 0; ///< id defined by the grf file for this entity
uint32_t grfid = 0; ///< grfid that introduced this entity.
const struct GRFFile *grffile = nullptr; ///< grf file that introduced this entity
std::array<const struct SpriteGroup *, Tcnt> spritegroup{}; ///< pointers to the different sprites of the entity
/**
* Test if this entity was introduced by NewGRF.
* @returns true iff the grfid property is set.
*/
inline bool HasGrfFile() const { return this->grffile != nullptr; }
};
/** Data related to the handling of grf files. */

View File

@ -71,6 +71,7 @@ void SetCustomEngineSprites(EngineID engine, uint8_t cargo, const SpriteGroup *g
void SetEngineGRF(EngineID engine, const GRFFile *file)
{
Engine *e = Engine::Get(engine);
e->grf_prop.grfid = file->grfid;
e->grf_prop.grffile = file;
}

View File

@ -273,14 +273,14 @@ static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
if (IsTileType(tile, MP_HOUSE)) {
HouseID house = GetHouseType(tile); // tile been examined
const HouseSpec *hs = HouseSpec::Get(house);
if (hs->grf_prop.grffile != nullptr) { // must be one from a grf file
if (hs->grf_prop.HasGrfFile()) { // must be one from a grf file
SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
return hs->grf_prop.local_id == nbhd->hs->grf_prop.local_id && // same local id as the one requested
hs->grf_prop.grffile->grfid == nbhd->hs->grf_prop.grffile->grfid; // from the same grf
hs->grf_prop.grfid == nbhd->hs->grf_prop.grfid; // from the same grf
}
}
return false;
@ -297,14 +297,14 @@ static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
if (IsTileType(tile, MP_HOUSE)) {
HouseID house = GetHouseType(tile); // tile been examined
const HouseSpec *hs = HouseSpec::Get(house);
if (hs->grf_prop.grffile != nullptr) { // must be one from a grf file
if (hs->grf_prop.HasGrfFile()) { // must be one from a grf file
SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
return hs->class_id == nbhd->hs->class_id && // same classid as the one requested
hs->grf_prop.grffile->grfid == nbhd->hs->grf_prop.grffile->grfid; // from the same grf
hs->grf_prop.grfid == nbhd->hs->grf_prop.grfid; // from the same grf
}
}
return false;
@ -321,13 +321,13 @@ static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
if (IsTileType(tile, MP_HOUSE)) {
HouseID house = GetHouseType(tile); // tile been examined
const HouseSpec *hs = HouseSpec::Get(house);
if (hs->grf_prop.grffile != nullptr) { // must be one from a grf file
if (hs->grf_prop.HasGrfFile()) { // must be one from a grf file
SearchNearbyHouseData *nbhd = (SearchNearbyHouseData *)user_data;
TileIndex north_tile = tile + GetHouseNorthPart(house); // modifies 'house'!
if (north_tile == nbhd->north_tile) return false; // Always ignore origin house
return hs->grf_prop.grffile->grfid == nbhd->hs->grf_prop.grffile->grfid; // from the same grf
return hs->grf_prop.grfid == nbhd->hs->grf_prop.grfid; // from the same grf
}
}
return false;
@ -429,9 +429,9 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho
/* Building counts for new houses with id = parameter. */
case 0x61: {
const HouseSpec *hs = HouseSpec::Get(this->house_id);
if (hs->grf_prop.grffile == nullptr) return 0;
if (!hs->grf_prop.HasGrfFile()) return 0;
HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grffile->grfid);
HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grfid);
return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town);
}

View File

@ -71,7 +71,7 @@ uint32_t GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32_t cur_g
/* Overridden */
const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
if (tile_ovr->grf_prop.grffile->grfid == cur_grfid) {
if (tile_ovr->grf_prop.grfid == cur_grfid) {
return tile_ovr->grf_prop.local_id; // same grf file
} else {
return 0xFFFE; // not the same grf file
@ -79,7 +79,7 @@ uint32_t GetIndustryIDAtOffset(TileIndex tile, const Industry *i, uint32_t cur_g
}
/* Not an 'old type' tile */
if (indtsp->grf_prop.spritegroup[0] != nullptr) { // tile has a spritegroup ?
if (indtsp->grf_prop.grffile->grfid == cur_grfid) { // same industry, same grf ?
if (indtsp->grf_prop.grfid == cur_grfid) { // same industry, same grf ?
return indtsp->grf_prop.local_id;
} else {
return 0xFFFE; // Defined in another grf file
@ -126,7 +126,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_
break;
case 0xFFFFFFFF: // current grf
GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid;
GrfID = GetIndustrySpec(current->type)->grf_prop.grfid;
[[fallthrough]];
default: // use the grfid specified in register 100h
@ -284,7 +284,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_
/* Distance of nearest industry of given type */
case 0x64: {
if (this->tile == INVALID_TILE) break;
IndustryType type = MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid);
IndustryType type = MapNewGRFIndustryType(parameter, indspec->grf_prop.grfid);
if (type >= NUM_INDUSTRYTYPES) return UINT32_MAX;
return GetClosestIndustry(this->tile, type, this->industry);
}
@ -443,9 +443,8 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_
/* Create storage on first modification. */
const IndustrySpec *indsp = GetIndustrySpec(this->industry->type);
uint32_t grfid = (indsp->grf_prop.grffile != nullptr) ? indsp->grf_prop.grffile->grfid : 0;
assert(PersistentStorage::CanAllocateItem());
this->industry->psa = new PersistentStorage(grfid, GSF_INDUSTRIES, this->industry->location.tile);
this->industry->psa = new PersistentStorage(indsp->grf_prop.grfid, GSF_INDUSTRIES, this->industry->location.tile);
}
this->industry->psa->StoreValue(pos, value);
@ -584,7 +583,7 @@ uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityC
if (res < 0x100) {
default_prob = res;
} else if (res > 0x100) {
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_PROBABILITY, res);
ErrorUnknownCallbackResult(indspec->grf_prop.grfid, CBID_INDUSTRY_PROBABILITY, res);
}
}
}

View File

@ -173,11 +173,11 @@ static uint32_t GetObjectIDAtOffset(TileIndex tile, uint32_t cur_grfid)
const ObjectSpec *spec = ObjectSpec::Get(o->type);
/* Default objects have no associated NewGRF file */
if (spec->grf_prop.grffile == nullptr) {
if (!spec->grf_prop.HasGrfFile()) {
return 0xFFFE; // Defined in another grf file
}
if (spec->grf_prop.grffile->grfid == cur_grfid) { // same object, same grf ?
if (spec->grf_prop.grfid == cur_grfid) { // same object, same grf ?
return spec->grf_prop.local_id | o->view << 16;
}

View File

@ -570,7 +570,7 @@ int AllocateSpecToRoadStop(const RoadStopSpec *statspec, BaseStation *st, bool e
if (exec) {
if (i >= st->roadstop_speclist.size()) st->roadstop_speclist.resize(i + 1);
st->roadstop_speclist[i].spec = statspec;
st->roadstop_speclist[i].grfid = statspec->grf_prop.grffile->grfid;
st->roadstop_speclist[i].grfid = statspec->grf_prop.grfid;
st->roadstop_speclist[i].localidx = statspec->grf_prop.local_id;
RoadStopUpdateCachedTriggers(st);

View File

@ -708,7 +708,7 @@ int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exe
if (exec) {
if (i >= st->speclist.size()) st->speclist.resize(i + 1);
st->speclist[i].spec = statspec;
st->speclist[i].grfid = statspec->grf_prop.grffile->grfid;
st->speclist[i].grfid = statspec->grf_prop.grfid;
st->speclist[i].localidx = statspec->grf_prop.local_id;
StationUpdateCachedTriggers(st);

View File

@ -112,7 +112,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) {
uint16_t res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile);
if (res != CALLBACK_FAILED) {
if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res);
if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_COLOUR, res);
o->colour = GB(res, 0, 8);
}
}
@ -665,8 +665,8 @@ static void GetTileDesc_Object(TileIndex tile, TileDesc *td)
td->owner[0] = GetTileOwner(tile);
td->build_date = Object::GetByTile(tile)->build_date;
if (spec->grf_prop.grffile != nullptr) {
td->grf = GetGRFConfig(spec->grf_prop.grffile->grfid)->GetName();
if (spec->grf_prop.HasGrfFile()) {
td->grf = GetGRFConfig(spec->grf_prop.grfid)->GetName();
}
}

View File

@ -86,7 +86,7 @@ public:
void DrawType(int x, int y, int cls_id, int id) const override
{
const auto *spec = this->GetSpec(cls_id, id);
if (spec->grf_prop.grffile == nullptr) {
if (!spec->grf_prop.HasGrfFile()) {
extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
@ -207,7 +207,7 @@ public:
int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM);
if (spec->grf_prop.grffile == nullptr) {
if (!spec->grf_prop.HasGrfFile()) {
extern const DrawTileSprites _objects[];
const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id];
DrawOrigTileSeqInGUI(x, y, dts, PAL_NONE);
@ -228,9 +228,9 @@ public:
uint16_t callback_res = GetObjectCallback(CBID_OBJECT_FUND_MORE_TEXT, 0, 0, spec, nullptr, INVALID_TILE, _object_gui.sel_view);
if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
if (callback_res > 0x400) {
ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_FUND_MORE_TEXT, callback_res);
ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_FUND_MORE_TEXT, callback_res);
} else {
StringID message = GetGRFStringID(spec->grf_prop.grffile->grfid, 0xD000 + callback_res);
StringID message = GetGRFStringID(spec->grf_prop.grfid, 0xD000 + callback_res);
if (message != STR_NULL && message != STR_UNDEFINED) {
StartTextRefStackUsage(spec->grf_prop.grffile, 6);
/* Use all the available space left from where we stand up to the

View File

@ -113,7 +113,7 @@ public:
PickerItem GetPickerItem(const typename T::spec_type *spec, int cls_id = -1, int id = -1) const
{
if (spec == nullptr) return {0, 0, cls_id, id};
return {spec->grf_prop.grffile == nullptr ? 0 : spec->grf_prop.grffile->grfid, spec->grf_prop.local_id, spec->class_index, spec->index};
return {spec->grf_prop.grfid, spec->grf_prop.local_id, spec->class_index, spec->index};
}
PickerItem GetPickerItem(int cls_id, int id) const override

View File

@ -87,7 +87,7 @@ void MoveWaypointsToBaseStations()
* from the GRF ID / station index. */
for (OldWaypoint &wp : _old_waypoints) {
const auto specs = StationClass::Get(STAT_CLASS_WAYP)->Specs();
auto found = std::ranges::find_if(specs, [&wp](const StationSpec *spec) { return spec != nullptr && spec->grf_prop.grffile->grfid == wp.grfid && spec->grf_prop.local_id == wp.localidx; });
auto found = std::ranges::find_if(specs, [&wp](const StationSpec *spec) { return spec != nullptr && spec->grf_prop.grfid == wp.grfid && spec->grf_prop.local_id == wp.localidx; });
if (found != std::end(specs)) wp.spec = *found;
}
}

View File

@ -1479,7 +1479,7 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp
if (callback <= UINT8_MAX) {
SetStationGfx(tile, (callback & ~1) + axis);
} else {
ErrorUnknownCallbackResult(statspec->grf_prop.grffile->grfid, CBID_STATION_BUILD_TILE_LAYOUT, callback);
ErrorUnknownCallbackResult(statspec->grf_prop.grfid, CBID_STATION_BUILD_TILE_LAYOUT, callback);
}
}
@ -3503,8 +3503,8 @@ void FillTileDescRailStation(TileIndex tile, TileDesc *td)
td->station_class = StationClass::Get(spec->class_index)->name;
td->station_name = spec->name;
if (spec->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grffile->grfid);
if (spec->grf_prop.HasGrfFile()) {
const GRFConfig *gc = GetGRFConfig(spec->grf_prop.grfid);
td->grf = gc->GetName();
}
}
@ -3523,11 +3523,11 @@ void FillTileDescAirport(TileIndex tile, TileDesc *td)
const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
td->airport_tile_name = ats->name;
if (as->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(as->grf_prop.grffile->grfid);
if (as->grf_prop.HasGrfFile()) {
const GRFConfig *gc = GetGRFConfig(as->grf_prop.grfid);
td->grf = gc->GetName();
} else if (ats->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grffile->grfid);
} else if (ats->grf_prop.HasGrfFile()) {
const GRFConfig *gc = GetGRFConfig(ats->grf_prop.grfid);
td->grf = gc->GetName();
}
}
@ -3555,7 +3555,7 @@ static void GetTileDesc_Station(TileIndex tile, TileDesc *td)
const IndustrySpec *is = GetIndustrySpec(i->type);
td->owner[0] = i->owner;
str = is->name;
if (is->grf_prop.grffile != nullptr) td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->GetName();
if (is->grf_prop.HasGrfFile()) td->grf = GetGRFConfig(is->grf_prop.grfid)->GetName();
break;
}
case STATION_DOCK: str = STR_LAI_STATION_DESCRIPTION_SHIP_DOCK; break;

View File

@ -141,7 +141,7 @@ class NIHStation : public NIHelper {
const void *GetInstance(uint ) const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetStationSpec(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(index)->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetStationSpec(index)->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -201,12 +201,12 @@ static const NIVariable _niv_house[] = {
};
class NIHHouse : public NIHelper {
bool IsInspectable(uint index) const override { return HouseSpec::Get(GetHouseType(index))->grf_prop.grffile != nullptr; }
bool IsInspectable(uint index) const override { return HouseSpec::Get(GetHouseType(index))->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, GetTownIndex(index)); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return HouseSpec::Get(GetHouseType(index)); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -251,12 +251,12 @@ static const NIVariable _niv_industrytiles[] = {
};
class NIHIndustryTile : public NIHelper {
bool IsInspectable(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile != nullptr; }
bool IsInspectable(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_INDUSTRIES, GetIndustryIndex(index)); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetIndustryTileSpec(GetIndustryGfx(index)); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -364,12 +364,12 @@ static const NIVariable _niv_industries[] = {
};
class NIHIndustry : public NIHelper {
bool IsInspectable(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile != nullptr; }
bool IsInspectable(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); }
const void *GetInstance(uint index)const override { return Industry::Get(index); }
const void *GetSpec(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type); }
void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -427,12 +427,12 @@ static const NIVariable _niv_objects[] = {
};
class NIHObject : public NIHelper {
bool IsInspectable(uint index) const override { return ObjectSpec::GetByTile(index)->grf_prop.grffile != nullptr; }
bool IsInspectable(uint index) const override { return ObjectSpec::GetByTile(index)->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Object::GetByTile(index)->town->index); }
const void *GetInstance(uint index)const override { return Object::GetByTile(index); }
const void *GetSpec(uint index) const override { return ObjectSpec::GetByTile(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(index)->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(index)->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -497,12 +497,12 @@ static const NICallback _nic_airporttiles[] = {
};
class NIHAirportTile : public NIHelper {
bool IsInspectable(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile != nullptr; }
bool IsInspectable(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_AIRPORTS, GetStationIndex(index)); }
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return AirportTileSpec::Get(GetAirportGfx(index)); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -538,12 +538,12 @@ static const NIVariable _niv_airports[] = {
};
class NIHAirport : public NIHelper {
bool IsInspectable(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grffile != nullptr; }
bool IsInspectable(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.HasGrfFile(); }
uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Station::Get(index)->town->index); }
const void *GetInstance(uint index)const override { return Station::Get(index); }
const void *GetSpec(uint index) const override { return AirportSpec::Get(Station::Get(index)->airport.type); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, index, Station::Get(index)->airport.tile); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? AirportSpec::Get(Station::Get(index)->airport.type)->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint param, bool &avail) const override
{
@ -700,7 +700,7 @@ class NIHRoadStop : public NIHelper {
const void *GetInstance(uint)const override { return nullptr; }
const void *GetSpec(uint index) const override { return GetRoadStopSpec(index); }
void SetStringParameters(uint index) const override { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(index)->grf_prop.grffile->grfid : 0; }
uint32_t GetGRFID(uint index) const override { return (this->IsInspectable(index)) ? GetRoadStopSpec(index)->grf_prop.grfid : 0; }
uint Resolve(uint index, uint var, uint32_t param, bool &avail) const override
{

View File

@ -869,9 +869,9 @@ static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
uint16_t callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house, Town::GetByTile(tile), tile);
if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
if (callback_res > 0x400) {
ErrorUnknownCallbackResult(hs->grf_prop.grffile->grfid, CBID_HOUSE_CUSTOM_NAME, callback_res);
ErrorUnknownCallbackResult(hs->grf_prop.grfid, CBID_HOUSE_CUSTOM_NAME, callback_res);
} else {
StringID new_name = GetGRFStringID(hs->grf_prop.grffile->grfid, 0xD000 + callback_res);
StringID new_name = GetGRFStringID(hs->grf_prop.grfid, 0xD000 + callback_res);
if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
td->str = new_name;
}
@ -883,8 +883,8 @@ static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
td->str = STR_LAI_TOWN_INDUSTRY_DESCRIPTION_UNDER_CONSTRUCTION;
}
if (hs->grf_prop.grffile != nullptr) {
const GRFConfig *gc = GetGRFConfig(hs->grf_prop.grffile->grfid);
if (hs->grf_prop.HasGrfFile()) {
const GRFConfig *gc = GetGRFConfig(hs->grf_prop.grfid);
td->grf = gc->GetName();
}

View File

@ -1531,8 +1531,8 @@ public:
PickerItem GetPickerItem(int cls_id, int id) const override
{
const auto *spec = HouseSpec::Get(id);
if (spec->grf_prop.grffile == nullptr) return {0, spec->Index(), cls_id, id};
return {spec->grf_prop.grffile->grfid, spec->grf_prop.local_id, cls_id, id};
if (!spec->grf_prop.HasGrfFile()) return {0, spec->Index(), cls_id, id};
return {spec->grf_prop.grfid, spec->grf_prop.local_id, cls_id, id};
}
int GetSelectedType() const override { return sel_type; }
@ -1587,7 +1587,7 @@ public:
dst.insert(item);
} else {
/* Search for spec by grfid and local index. */
auto it = std::ranges::find_if(specs, [&item](const HouseSpec &spec) { return spec.grf_prop.grffile != nullptr && spec.grf_prop.grffile->grfid == item.grfid && spec.grf_prop.local_id == item.local_id; });
auto it = std::ranges::find_if(specs, [&item](const HouseSpec &spec) { return spec.grf_prop.grfid == item.grfid && spec.grf_prop.local_id == item.local_id; });
if (it == specs.end()) {
/* Not preset, hide from UI. */
dst.insert({item.grfid, item.local_id, -1, -1});

View File

@ -347,7 +347,7 @@ void VehicleLengthChanged(const Vehicle *u)
{
/* show a warning once for each engine in whole game and once for each GRF after each game load */
const Engine *engine = u->GetEngine();
uint32_t grfid = engine->grf_prop.grffile->grfid;
uint32_t grfid = engine->grf_prop.grfid;
GRFConfig *grfconfig = GetGRFConfig(grfid);
if (_gamelog.GRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) {
ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true);