# HG changeset patch # User Loïc Guilloux # Date 2022-12-17 14:01:47 # Node ID a3a9730bcdc819fa86b1ba13598bada68d2ec1b0 # Parent a9fe1c9a1109e4701f9f7f5481363d7e9a6b6097 Fix #10208: allow to use specific underlay for road/tram tunnels (#10233) diff --git a/src/road.h b/src/road.h --- a/src/road.h +++ b/src/road.h @@ -58,7 +58,7 @@ enum RoadTypeSpriteGroup { ROTSG_CURSORS, ///< Optional: Cursor and toolbar icon images ROTSG_OVERLAY, ///< Optional: Images for overlaying track ROTSG_GROUND, ///< Required: Main group of ground images - ROTSG_reserved1, ///< Placeholder, if we need specific tunnel sprites. + ROTSG_TUNNEL, ///< Optional: Ground images for tunnels ROTSG_CATENARY_FRONT, ///< Optional: Catenary front ROTSG_CATENARY_BACK, ///< Optional: Catenary back ROTSG_BRIDGE, ///< Required: Bridge surface images diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1489,21 +1489,24 @@ static void DrawRoadDetail(SpriteID img, * @param tram_rti Tram road type information * @param road_offset Road sprite offset (based on road bits) * @param tram_offset Tram sprite offset (based on road bits) + * @param draw_underlay Whether to draw underlays */ -void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset) +void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset, bool draw_underlay) { - /* Road underlay takes precedence over tram */ - if (road_rti != nullptr) { - if (road_rti->UsesOverlay()) { - SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_GROUND); - DrawGroundSprite(ground + road_offset, pal); - } - } else { - if (tram_rti->UsesOverlay()) { - SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_GROUND); - DrawGroundSprite(ground + tram_offset, pal); + if (draw_underlay) { + /* Road underlay takes precedence over tram */ + if (road_rti != nullptr) { + if (road_rti->UsesOverlay()) { + SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_GROUND); + DrawGroundSprite(ground + road_offset, pal); + } } else { - DrawGroundSprite(SPR_TRAMWAY_TRAM + tram_offset, pal); + if (tram_rti->UsesOverlay()) { + SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_GROUND); + DrawGroundSprite(ground + tram_offset, pal); + } else { + DrawGroundSprite(SPR_TRAMWAY_TRAM + tram_offset, pal); + } } } diff --git a/src/road_func.h b/src/road_func.h --- a/src/road_func.h +++ b/src/road_func.h @@ -158,6 +158,6 @@ void MarkDirtyAdjacentLevelCrossingTiles void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count); struct TileInfo; -void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset); +void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset, bool draw_underlay = true); #endif /* ROAD_FUNC_H */ diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1307,8 +1307,28 @@ static void DrawTile_TunnelBridge(TileIn const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt); const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt); uint sprite_offset = DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? 1 : 0; + bool draw_underlay = true; - DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset); + /* Road underlay takes precedence over tram */ + if (road_rti != nullptr) { + if (road_rti->UsesOverlay()) { + SpriteID ground = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_TUNNEL); + if (ground != 0) { + DrawGroundSprite(ground + tunnelbridge_direction, PAL_NONE); + draw_underlay = false; + } + } + } else { + if (tram_rti->UsesOverlay()) { + SpriteID ground = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_TUNNEL); + if (ground != 0) { + DrawGroundSprite(ground + tunnelbridge_direction, PAL_NONE); + draw_underlay = false; + } + } + } + + DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset, draw_underlay); /* Road catenary takes precedence over tram */ SpriteID catenary_sprite_base = 0;