diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3925,7 +3925,7 @@ static void TownHouseMapSpriteGroup(Byte continue; } - hs->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid]; + hs->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid]; } } @@ -3956,7 +3956,7 @@ static void IndustryMapSpriteGroup(ByteR continue; } - indsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid]; + indsp->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid]; } } @@ -3987,7 +3987,7 @@ static void IndustrytileMapSpriteGroup(B continue; } - indtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid]; + indtsp->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid]; } } @@ -4075,7 +4075,7 @@ static void AirportMapSpriteGroup(ByteRe continue; } - as->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid]; + as->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid]; } } @@ -4106,7 +4106,7 @@ static void AirportTileMapSpriteGroup(By continue; } - airtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid]; + airtsp->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid]; } } diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -223,7 +223,7 @@ SpriteID GetCustomAirportSprite(const Ai NewAirportResolver(&object, INVALID_TILE, NULL, as->GetIndex(), layout); - group = SpriteGroup::Resolve(as->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object); if (group == NULL) return as->preview_sprite; return group->GetResult(); @@ -238,7 +238,7 @@ uint16 GetAirportCallback(CallbackID cal object.callback_param1 = param1; object.callback_param2 = param2; - const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup, &object); + const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup[0], &object); if (group == NULL) return CALLBACK_FAILED; return group->GetCallbackResult(); @@ -252,7 +252,7 @@ StringID GetAirportTextCallback(const Ai NewAirportResolver(&object, INVALID_TILE, NULL, as->GetIndex(), layout); object.callback = (CallbackID)callback; - group = SpriteGroup::Resolve(as->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object); if (group == NULL) return STR_UNDEFINED; return GetGRFStringID(as->grf_prop.grffile->grfid, 0xD000 + group->GetResult()); diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp --- a/src/newgrf_airporttiles.cpp +++ b/src/newgrf_airporttiles.cpp @@ -251,7 +251,7 @@ uint16 GetAirportTileCallback(CallbackID object.callback_param1 = param1; object.callback_param2 = param2; - group = SpriteGroup::Resolve(AirportTileSpec::Get(gfx_id)->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(AirportTileSpec::Get(gfx_id)->grf_prop.spritegroup[0], &object); if (group == NULL) return CALLBACK_FAILED; return group->GetCallbackResult(); @@ -293,7 +293,7 @@ bool DrawNewAirportTile(TileInfo *ti, St AirportTileResolver(&object, gfx, ti->tile, st); - group = SpriteGroup::Resolve(airts->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(airts->grf_prop.spritegroup[0], &object); if (group == NULL || group->type != SGT_TILELAYOUT) { return false; } diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -135,25 +135,31 @@ uint32 GetTerrainType(TileIndex tile, Ti TileIndex GetNearbyTile(byte parameter, TileIndex tile); uint32 GetNearbyTileInformation(TileIndex tile); -/** Data related to the handling of grf files. */ +/** + * Data related to the handling of grf files. + * @tparam Tcnt Number of spritegroups + */ +template struct GRFFilePropsBase { - /** Set all data constructor for the props. */ - GRFFilePropsBase(uint local_id, const struct GRFFile *grffile) : local_id(local_id), grffile(grffile) {} - /** Simple constructor for the props. */ - GRFFilePropsBase() {} - uint16 local_id; ///< id defined by the grf file for this entity - const struct GRFFile *grffile; ///< grf file that introduced this entity + /* The lack of constructor means the default zero-ing constructor is used. */ + uint16 local_id; ///< id defined by the grf file for this entity + const struct GRFFile *grffile; ///< grf file that introduced this entity + const struct SpriteGroup *spritegroup[Tcnt]; ///< pointer to the different sprites of the entity }; /** Data related to the handling of grf files. */ -struct GRFFileProps : GRFFilePropsBase { +struct GRFFileProps : GRFFilePropsBase<1> { /** Set all default data constructor for the props. */ GRFFileProps(uint16 subst_id) : - GRFFilePropsBase(0, NULL), subst_id(subst_id), spritegroup(NULL), override(subst_id) {} + GRFFilePropsBase<1>(), subst_id(subst_id), override(subst_id) + { + /* Check whether the constructor did comply with the specs. */ + assert(this->spritegroup[0] == NULL); + } + /** Simple constructor for the props. */ - GRFFileProps() : GRFFilePropsBase() {} + GRFFileProps() : GRFFilePropsBase<1>() {} uint16 subst_id; - struct SpriteGroup *spritegroup; ///< pointer to the different sprites of the entity uint16 override; ///< id of the entity been replaced by }; diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -408,7 +408,7 @@ uint16 GetHouseCallback(CallbackID callb object.u.house.not_yet_constructed = not_yet_constructed; object.u.house.initial_random_bits = initial_random_bits; - group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->grf_prop.spritegroup[0], &object); if (group == NULL) return CALLBACK_FAILED; return group->GetCallbackResult(); @@ -459,7 +459,7 @@ void DrawNewHouseTile(TileInfo *ti, Hous NewHouseResolver(&object, house_id, ti->tile, Town::GetByTile(ti->tile)); - group = SpriteGroup::Resolve(hs->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], &object); if (group == NULL || group->type != SGT_TILELAYOUT) { return; } else { @@ -639,7 +639,7 @@ static void DoTriggerHouse(TileIndex til object.callback = CBID_RANDOM_TRIGGER; object.trigger = trigger; - const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup, &object); + const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], &object); if (group == NULL) return; byte new_random_bits = Random(); diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -397,7 +397,7 @@ uint16 GetIndustryCallback(CallbackID ca object.callback_param1 = param1; object.callback_param2 = param2; - group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object); if (group == NULL) return CALLBACK_FAILED; return group->GetCallbackResult(); @@ -483,7 +483,7 @@ CommandCost CheckIfCallBackAllowsCreatio object.callback = CBID_INDUSTRY_LOCATION; _industry_creation_random_bits = seed; - group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object); /* Unlike the "normal" cases, not having a valid result means we allow * the building of the industry, as that's how it's done in TTDP. */ @@ -552,7 +552,7 @@ void IndustryProductionCallback(Industry } SB(object.callback_param2, 8, 16, loop); - const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup, &object); + const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup[0], &object); if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION) break; const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup; diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -212,7 +212,7 @@ uint16 GetIndustryTileCallback(CallbackI object.callback_param1 = param1; object.callback_param2 = param2; - group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup[0], &object); if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; return group->GetCallbackResult(); @@ -236,7 +236,7 @@ bool DrawNewIndustryTile(TileInfo *ti, I NewIndustryTileResolver(&object, gfx, ti->tile, i); - group = SpriteGroup::Resolve(inds->grf_prop.spritegroup, &object); + group = SpriteGroup::Resolve(inds->grf_prop.spritegroup[0], &object); if (group == NULL || group->type != SGT_TILELAYOUT) { return false; } else { @@ -426,7 +426,7 @@ static void DoTriggerIndustryTile(TileIn object.callback = CBID_RANDOM_TRIGGER; object.trigger = trigger; - const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup, &object); + const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup[0], &object); if (group == NULL) return; byte new_random_bits = Random(); diff --git a/src/newgrf_station.h b/src/newgrf_station.h --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -47,7 +47,7 @@ typedef byte *StationLayout; /** Station specification. */ struct StationSpec { - GRFFilePropsBase grf_prop; ///< Properties related the the grf file + GRFFilePropsBase<0> grf_prop; ///< Properties related the the grf file StationClassID cls_id; ///< The class to which this spec belongs. StringID name; ///< Name of this station.