diff options
-rw-r--r-- | src/rail_cmd.cpp | 37 | ||||
-rw-r--r-- | src/station_cmd.cpp | 26 | ||||
-rw-r--r-- | src/station_func.h | 3 | ||||
-rw-r--r-- | src/transparency.h | 1 |
4 files changed, 26 insertions, 41 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index f2f2832b8..00b2a30bf 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1944,8 +1944,6 @@ static void DrawTile_Track(TileInfo *ti) } else { /* draw depot */ const DrawTileSprites *dts; - const DrawTileSeqStruct *dtss; - uint32 relocation; SpriteID pal = PAL_NONE; if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); @@ -1957,8 +1955,6 @@ static void DrawTile_Track(TileInfo *ti) dts = &_depot_gfx_table[GetRailDepotDirection(ti->tile)]; } - relocation = rti->total_offset; - image = dts->ground.sprite; if (image != SPR_FLAT_GRASS_TILE) image += rti->total_offset; @@ -1985,37 +1981,8 @@ static void DrawTile_Track(TileInfo *ti) if (HasCatenaryDrawn(GetRailType(ti->tile))) DrawCatenary(ti); - foreach_draw_tile_seq(dtss, dts->seq) { - SpriteID image = dtss->image.sprite; - SpriteID pal = dtss->image.pal; - - /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */ - if (IsInvisibilitySet(TO_BUILDINGS) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; - - /* Unlike stations, our default waypoint has no variation for - * different railtype, so don't use the railtype offset if - * no relocation is set */ - if (HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { - image += rti->total_offset; - } else { - image += relocation; - } - - pal = SpriteLayoutPaletteTransform(image, pal, _drawtile_track_palette); - - if ((byte)dtss->delta_z != 0x80) { - AddSortableSpriteToDraw( - image, pal, - ti->x + dtss->delta_x, ti->y + dtss->delta_y, - dtss->size_x, dtss->size_y, - dtss->size_z, ti->z + dtss->delta_z, - !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS) - ); - } else { - /* For stations and original spritelayouts delta_x and delta_y are signed */ - AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)); - } - } + /* No NewGRF depots, so no relocation */ + DrawStationTileSeq(ti, dts, TO_BUILDINGS, rti->total_offset, 0, _drawtile_track_palette); } DrawBridgeMiddle(ti); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index e3cba4b3e..a7e5d662d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2457,12 +2457,26 @@ static void DrawTile_Station(TileInfo *ti) total_offset = 0; } - const DrawTileSeqStruct *dtss; - foreach_draw_tile_seq(dtss, t->seq) { + DrawStationTileSeq(ti, t, TO_BUILDINGS, total_offset, relocation, palette); +} + +/** + * Draws a station, waypoint or depot including all subsprites on a tile. + * @param ti The tile to draw on + * @param dts Sprite and subsprites to draw + * @param to The transparancy bit that toggles drawing of these sprites + * @param total_offset Sprite-Offset between the current railtype and normal rail + * @param relocation Sprite-Offset for NewGRF defined stations + * @param default_palette The default recolour sprite to use (typically company colour) + */ +void DrawStationTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 relocation, SpriteID default_palette) +{ + const DrawTileSeqStruct *dtss; + foreach_draw_tile_seq(dtss, dts->seq) { SpriteID image = dtss->image.sprite; /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */ - if (IsInvisibilitySet(TO_BUILDINGS) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; + if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; if (relocation == 0 || HasBit(image, SPRITE_MODIFIER_USE_OFFSET)) { image += total_offset; @@ -2470,7 +2484,7 @@ static void DrawTile_Station(TileInfo *ti) image += relocation; } - SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, palette); + SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette); if ((byte)dtss->delta_z != 0x80) { AddSortableSpriteToDraw( @@ -2478,11 +2492,11 @@ static void DrawTile_Station(TileInfo *ti) ti->x + dtss->delta_x, ti->y + dtss->delta_y, dtss->size_x, dtss->size_y, dtss->size_z, ti->z + dtss->delta_z, - !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS) + !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to) ); } else { /* For stations and original spritelayouts delta_x and delta_y are signed */ - AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_BUILDINGS)); + AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)); } } } diff --git a/src/station_func.h b/src/station_func.h index ecc794a80..acc124339 100644 --- a/src/station_func.h +++ b/src/station_func.h @@ -19,6 +19,7 @@ #include "tile_type.h" #include "cargo_type.h" #include "vehicle_type.h" +#include "transparency.h" void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius); @@ -35,6 +36,8 @@ void UpdateStationAcceptance(Station *st, bool show_msg); const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx); void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image); +void DrawStationTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 relocation, SpriteID default_palette); + bool HasStationInUse(StationID station, CompanyID company); RoadStop *GetRoadStopByTile(TileIndex tile, RoadStopType type); diff --git a/src/transparency.h b/src/transparency.h index 3b5cd5ebe..a6a33eaf0 100644 --- a/src/transparency.h +++ b/src/transparency.h @@ -14,6 +14,7 @@ #include "gfx_func.h" #include "openttd.h" +#include "core/bitmath_func.hpp" /** * Transparency option bits: which position in _transparency_opt stands for which transparency. |