summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-01-08 20:42:12 +0000
committerfrosch <frosch@openttd.org>2010-01-08 20:42:12 +0000
commit5b422d0c64f67101ed85ebf8934dc381817e1a7b (patch)
tree27ec3978a3fce34ba614c9722af2fc77e968ece4
parenta16edfebd9b71aef938b4b32ac8276458aa33029 (diff)
downloadopenttd-5b422d0c64f67101ed85ebf8934dc381817e1a7b.tar.xz
(svn r18761) -Fix [FS#3497]: Spritelayouts do not need an Action 1 if only using default sprites.
-rw-r--r--src/newgrf.cpp32
-rw-r--r--src/newgrf_house.cpp4
-rw-r--r--src/newgrf_industrytiles.cpp4
3 files changed, 28 insertions, 12 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index f7920b5c7..37f830b1d 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2908,13 +2908,15 @@ static void NewSpriteGroup(byte *buf, size_t len)
case GSF_TOWNHOUSE:
case GSF_INDUSTRYTILES: {
- byte num_sprite_sets = _cur_grffile->spriteset_numents;
+ byte num_spriteset_ents = _cur_grffile->spriteset_numents;
+ byte num_spritesets = _cur_grffile->spriteset_numsets;
byte num_building_sprites = max((uint8)1, type);
uint i;
TileLayoutSpriteGroup *group = new TileLayoutSpriteGroup();
act_group = group;
- group->num_building_stages = num_sprite_sets;
+ /* num_building_stages should be 1, if we are only using non-custom sprites */
+ group->num_building_stages = max((uint8)1, num_spriteset_ents);
group->dts = CallocT<DrawTileSprites>(1);
/* Groundsprite */
@@ -2927,9 +2929,16 @@ static void NewSpriteGroup(byte *buf, size_t len)
if (HasBit(group->dts->ground.pal, 15)) {
/* Bit 31 set means this is a custom sprite, so rewrite it to the
* last spriteset defined. */
- SpriteID sprite = _cur_grffile->spriteset_start + GB(group->dts->ground.sprite, 0, 14) * num_sprite_sets;
- SB(group->dts->ground.sprite, 0, SPRITE_WIDTH, sprite);
- ClrBit(group->dts->ground.pal, 15);
+ uint spriteset = GB(group->dts->ground.sprite, 0, 14);
+ if (num_spriteset_ents == 0 || spriteset >= num_spritesets) {
+ grfmsg(1, "NewSpriteGroup: Spritelayout uses undefined custom spriteset %d", spriteset);
+ group->dts->ground.sprite = SPR_IMG_QUERY;
+ group->dts->ground.pal = PAL_NONE;
+ } else {
+ SpriteID sprite = _cur_grffile->spriteset_start + spriteset * num_spriteset_ents;
+ SB(group->dts->ground.sprite, 0, SPRITE_WIDTH, sprite);
+ ClrBit(group->dts->ground.pal, 15);
+ }
}
group->dts->seq = CallocT<DrawTileSeqStruct>(num_building_sprites + 1);
@@ -2947,9 +2956,16 @@ static void NewSpriteGroup(byte *buf, size_t len)
if (HasBit(seq->image.pal, 15)) {
/* Bit 31 set means this is a custom sprite, so rewrite it to the
* last spriteset defined. */
- SpriteID sprite = _cur_grffile->spriteset_start + GB(seq->image.sprite, 0, 14) * num_sprite_sets;
- SB(seq->image.sprite, 0, SPRITE_WIDTH, sprite);
- ClrBit(seq->image.pal, 15);
+ uint spriteset = GB(seq->image.sprite, 0, 14);
+ if (num_spriteset_ents == 0 || spriteset >= num_spritesets) {
+ grfmsg(1, "NewSpriteGroup: Spritelayout uses undefined custom spriteset %d", spriteset);
+ seq->image.sprite = SPR_IMG_QUERY;
+ seq->image.pal = PAL_NONE;
+ } else {
+ SpriteID sprite = _cur_grffile->spriteset_start + spriteset * num_spriteset_ents;
+ SB(seq->image.sprite, 0, SPRITE_WIDTH, sprite);
+ ClrBit(seq->image.pal, 15);
+ }
}
if (type > 0) {
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index c7f79293d..a9d7a697d 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -472,11 +472,11 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
NewHouseResolver(&object, house_id, ti->tile, Town::GetByTile(ti->tile));
group = SpriteGroup::Resolve(hs->spritegroup, &object);
- const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
- if (group == NULL || group->type != SGT_TILELAYOUT || tlgroup->num_building_stages == 0) {
+ if (group == NULL || group->type != SGT_TILELAYOUT) {
return;
} else {
/* Limit the building stage to the number of stages supplied. */
+ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
byte stage = GetHouseBuildingStage(ti->tile);
stage = Clamp(stage - 4 + tlgroup->num_building_stages, 0, tlgroup->num_building_stages - 1);
DrawTileLayout(ti, tlgroup, stage, house_id);
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index 51084e415..5abd98f4d 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -253,11 +253,11 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus
NewIndustryTileResolver(&object, gfx, ti->tile, i);
group = SpriteGroup::Resolve(inds->grf_prop.spritegroup, &object);
- const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
- if (group == NULL || group->type != SGT_TILELAYOUT || tlgroup->num_building_stages == 0) {
+ if (group == NULL || group->type != SGT_TILELAYOUT) {
return false;
} else {
/* Limit the building stage to the number of stages supplied. */
+ const TileLayoutSpriteGroup *tlgroup = (const TileLayoutSpriteGroup *)group;
byte stage = GetIndustryConstructionStage(ti->tile);
stage = Clamp(stage - 4 + tlgroup->num_building_stages, 0, tlgroup->num_building_stages - 1);
IndustryDrawTileLayout(ti, tlgroup, i->random_colour, stage, gfx);