summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-10 15:49:35 +0000
committerrubidium <rubidium@openttd.org>2010-08-10 15:49:35 +0000
commitca7a067b7a57578e05cefec1ef647a67a9b5be07 (patch)
tree2ddc3cc481a332a28f072dda0af921ad0b69799b /src
parent21e4e7ce0699408fd2d4f1e1d1c97ccfd0fa74bc (diff)
downloadopenttd-ca7a067b7a57578e05cefec1ef647a67a9b5be07.tar.xz
(svn r20435) -Codechange: move spritegroup to GRFFilePropsBase and prepare it for more spritegroups
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp10
-rw-r--r--src/newgrf_airport.cpp6
-rw-r--r--src/newgrf_airporttiles.cpp4
-rw-r--r--src/newgrf_commons.h28
-rw-r--r--src/newgrf_house.cpp6
-rw-r--r--src/newgrf_industries.cpp6
-rw-r--r--src/newgrf_industrytiles.cpp6
-rw-r--r--src/newgrf_station.h2
8 files changed, 37 insertions, 31 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index f4c98e0bc..b3e3aa3e1 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -3925,7 +3925,7 @@ static void TownHouseMapSpriteGroup(ByteReader *buf, uint8 idcount)
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(ByteReader *buf, uint8 idcount)
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(ByteReader *buf, uint8 idcount)
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(ByteReader *buf, uint8 idcount)
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(ByteReader *buf, uint8 idcount)
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
index 12c17761f..836b962bd 100644
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -223,7 +223,7 @@ SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout)
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 callback, uint32 param1, uint32 param2, Sta
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 AirportSpec *as, byte layout, uint16 callb
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
index 9fc2b960c..4b3988bb6 100644
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -251,7 +251,7 @@ uint16 GetAirportTileCallback(CallbackID callback, uint32 param1, uint32 param2,
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, Station *st, StationGfx gfx, const Airport
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
index 5d575973f..129e662b4 100644
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -135,25 +135,31 @@ uint32 GetTerrainType(TileIndex tile, TileContext context = TCX_NORMAL);
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 <size_t Tcnt>
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
index 066ee77b4..cc0c62521 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -408,7 +408,7 @@ uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, House
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, HouseID house_id)
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 tile, HouseTrigger trigger, byte base_rando
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
index fc8c8bbef..732d865eb 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -397,7 +397,7 @@ uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, In
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 CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uin
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 *ind, int reason)
}
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
index 00fb10295..3fcdac555 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -212,7 +212,7 @@ uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2
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, Industry *i, IndustryGfx gfx, const Indus
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(TileIndex tile, IndustryTileTrigger trigger, I
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
index 523f72f0c..69a8f4588 100644
--- 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.