From f580ab4ba460c307cd9d4037815e69e7a8185541 Mon Sep 17 00:00:00 2001 From: frosch Date: Wed, 10 Mar 2021 22:49:56 +0100 Subject: Fix #8647: draw tram catenary using 4 bounding boxes. The back sprite is now supposed to contain west, north and east pillars. The front sprite is supposed to contain the south pillar and the wires. --- src/road_cmd.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/road_cmd.cpp') diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 9fffa45ca..830f9dd4f 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1423,8 +1423,23 @@ void DrawRoadTypeCatenary(const TileInfo *ti, RoadType rt, RoadBits rb) * For tiles with OWNER_TOWN or OWNER_NONE, recolour CC to grey as a neutral colour. */ Owner owner = GetRoadOwner(ti->tile, GetRoadTramType(rt)); PaletteID pal = (owner == OWNER_NONE || owner == OWNER_TOWN ? GENERAL_SPRITE_COLOUR(COLOUR_GREY) : COMPANY_SPRITE_COLOUR(owner)); - if (back != 0) AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY)); - if (front != 0) AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, TILE_HEIGHT + BB_HEIGHT_UNDER_BRIDGE, ti->z, IsTransparencySet(TO_CATENARY)); + int z_wires = (ti->tileh == SLOPE_FLAT ? 0 : TILE_HEIGHT) + BB_HEIGHT_UNDER_BRIDGE; + if (back != 0) { + /* The "back" sprite contains the west, north and east pillars. + * We cut the sprite at 3/8 of the west/east edges to create 3 sprites. + * 3/8 is chosen so that sprites can somewhat graphically extend into the tile. */ + static const int INF = 1000; ///< big number compared to sprite size + static const SubSprite west = { -INF, -INF, -12, INF }; + static const SubSprite north = { -12, -INF, 12, INF }; + static const SubSprite east = { 12, -INF, INF, INF }; + AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 16, 1, z_wires, ti->z, IsTransparencySet(TO_CATENARY), 15, 0, GetSlopePixelZInCorner(ti->tileh, CORNER_W), &west); + AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 1, 1, z_wires, ti->z, IsTransparencySet(TO_CATENARY), 0, 0, GetSlopePixelZInCorner(ti->tileh, CORNER_N), &north); + AddSortableSpriteToDraw(back, pal, ti->x, ti->y, 1, 16, z_wires, ti->z, IsTransparencySet(TO_CATENARY), 0, 15, GetSlopePixelZInCorner(ti->tileh, CORNER_E), &east); + } + if (front != 0) { + /* Draw the "front" sprite (containing south pillar and wires) at a Z height that is both above the vehicles and above the "back" pillars. */ + AddSortableSpriteToDraw(front, pal, ti->x, ti->y, 16, 16, z_wires + 1, ti->z, IsTransparencySet(TO_CATENARY), 0, 0, z_wires); + } } /** -- cgit v1.2.3-54-g00ecf