diff options
author | frosch <frosch@openttd.org> | 2011-05-29 16:56:22 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-05-29 16:56:22 +0000 |
commit | a241a4ce97ffe3f519ecf656ad10c518d646d423 (patch) | |
tree | b6319bc947c6ae62a4822ed0368228f3e5f4e2ca /src/newgrf_station.cpp | |
parent | 5b449145f7983d44d73195b8a18e4a2da721ee71 (diff) | |
download | openttd-a241a4ce97ffe3f519ecf656ad10c518d646d423.tar.xz |
(svn r22518) -Feature: [NewGRF] Advanced sprite layouts with register modifiers.
Diffstat (limited to 'src/newgrf_station.cpp')
-rw-r--r-- | src/newgrf_station.cpp | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 5d2707b70..af0945c05 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -746,7 +746,7 @@ void DeallocateSpecFromStation(BaseStation *st, byte specindex) bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station) { const StationSpec *statspec; - const DrawTileSprites *sprites; + const DrawTileSprites *sprites = NULL; const RailtypeInfo *rti = GetRailTypeInfo(railtype); PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company); uint tile = 2; @@ -754,36 +754,57 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID statspec = StationClass::Get(sclass, station); if (statspec == NULL) return false; - uint relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE); - if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) { uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE); if (callback != CALLBACK_FAILED) tile = callback; } + uint32 total_offset = rti->GetRailtypeSpriteOffset(); + uint32 relocation = 0; + uint32 ground_relocation = 0; + const NewGRFSpriteLayout *layout = NULL; + DrawTileSprites tmp_rail_layout; + if (statspec->renderdata == NULL) { sprites = GetStationTileLayout(STATION_RAIL, tile + axis); } else { - sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis]; + layout = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : (uint)axis]; + if (!layout->NeedsPreprocessing()) { + sprites = layout; + layout = NULL; + } } - SpriteID image = sprites->ground.sprite; - PaletteID pal = sprites->ground.pal; - if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) { - if (HasBit(statspec->flags, SSF_SEPARATE_GROUND)) { - /* Use separate action 1-2-3 chain for ground sprite */ - image += GetCustomStationRelocation(statspec, NULL, INVALID_TILE, 1); - } else { - image += relocation; + if (layout != NULL) { + /* Sprite layout which needs preprocessing */ + bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND); + uint32 var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, separate_ground); + uint8 var10; + FOR_EACH_SET_BIT(var10, var10_values) { + uint32 var10_relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, var10); + layout->ProcessRegisters(var10, var10_relocation, separate_ground); } - image += rti->fallback_railtype; + + tmp_rail_layout.seq = layout->GetLayout(&tmp_rail_layout.ground); + sprites = &tmp_rail_layout; + total_offset = 0; } else { - image += rti->GetRailtypeSpriteOffset(); + /* Simple sprite layout */ + ground_relocation = relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, 0); + if (HasBit(sprites->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) { + ground_relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE, 1); + } + ground_relocation += rti->fallback_railtype; } + SpriteID image = sprites->ground.sprite; + PaletteID pal = sprites->ground.pal; + image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset; + if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation; + DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y); - DrawRailTileSeqInGUI(x, y, sprites, rti->GetRailtypeSpriteOffset(), relocation, palette); + DrawRailTileSeqInGUI(x, y, sprites, total_offset, relocation, palette); return true; } |