From c50fabb5740345f92a826b0edfab786cfabf5651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Sat, 17 Dec 2022 15:01:47 +0100 Subject: [PATCH] Fix #10208: allow to use specific underlay for road/tram tunnels (#10233) --- src/road.h | 2 +- src/road_cmd.cpp | 27 +++++++++++++++------------ src/road_func.h | 2 +- src/tunnelbridge_cmd.cpp | 22 +++++++++++++++++++++- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/road.h b/src/road.h index 6a2af6698f..c34579b5bb 100644 --- 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 index 8fa060e173..dda2f2fa2a 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1489,21 +1489,24 @@ static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int * @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 index af756a2570..2db2f24fe3 100644 --- a/src/road_func.h +++ b/src/road_func.h @@ -158,6 +158,6 @@ void MarkDirtyAdjacentLevelCrossingTiles(TileIndex tile, Axis road_axis); 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 index 9d3868c86d..c22168476b 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1307,8 +1307,28 @@ static void DrawTile_TunnelBridge(TileInfo *ti) 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;