Index: src/newgrf_railtype.h =================================================================== --- src/newgrf_railtype.h (revision 20201) +++ src/newgrf_railtype.h (working copy) @@ -4,8 +4,9 @@ #define NEWGRF_RAILTYPE_H #include "rail.h" +#include "newgrf_commons.h" -SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, bool upper_halftile = false); +SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context = TC_NORMAL); uint8 GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile); Index: src/rail_cmd.cpp =================================================================== --- src/rail_cmd.cpp (revision 20201) +++ src/rail_cmd.cpp (working copy) @@ -1792,7 +1792,7 @@ { /* Base sprite for track fences. * Note: Halftile slopes only have fences on the upper part. */ - SpriteID base_image = GetCustomRailSprite(rti, ti->tile, RTSG_FENCES, IsHalftileSlope(ti->tileh)); + SpriteID base_image = GetCustomRailSprite(rti, ti->tile, RTSG_FENCES, IsHalftileSlope(ti->tileh) ? TC_UPPER_HALFTILE : TC_NORMAL); if (base_image == 0) base_image = SPR_TRACK_FENCE_FLAT_X; switch (GetRailGroundType(ti->tile)) { @@ -1951,8 +1951,8 @@ if (IsValidCorner(halftile_corner)) { DrawFoundation(ti, HalftileFoundation(halftile_corner)); - overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY, true); - ground = GetCustomRailSprite(rti, ti->tile, RTSG_GROUND, true); + overlay = GetCustomRailSprite(rti, ti->tile, RTSG_OVERLAY, TC_UPPER_HALFTILE); + ground = GetCustomRailSprite(rti, ti->tile, RTSG_GROUND, TC_UPPER_HALFTILE); /* Draw higher halftile-overlay: Use the sloped sprites with three corners raised. They probably best fit the lightning. */ Slope fake_slope = SlopeWithThreeCornersRaised(OppositeCorner(halftile_corner)); Index: src/tunnelbridge_cmd.cpp =================================================================== --- src/tunnelbridge_cmd.cpp (revision 20201) +++ src/tunnelbridge_cmd.cpp (working copy) @@ -1243,7 +1243,7 @@ } else if (transport_type == TRANSPORT_RAIL) { const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(rampsouth)); if (rti->UsesOverlay()) { - SpriteID surface = GetCustomRailSprite(rti, ti->tile, RTSG_BRIDGE); + SpriteID surface = GetCustomRailSprite(rti, rampsouth, RTSG_BRIDGE, TC_ON_BRIDGE); if (surface != 0) { AddSortableSpriteToDraw(surface + axis, PAL_NONE, x, y, 16, 16, 0, bridge_z, IsTransparencySet(TO_BRIDGES)); } @@ -1386,12 +1386,17 @@ { bool snow_or_desert = HasTunnelBridgeSnowOrDesert(tile); switch (_settings_game.game_creation.landscape) { - case LT_ARCTIC: - if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) { + case LT_ARCTIC: { + /* As long as we do not have a snow density, we want to use the density + * from the entry endge. For tunnels this is the lowest point for bridges the highest point. + * (Independent of foundations) */ + uint z = IsBridge(tile) ? GetTileMaxZ(tile) : GetTileZ(tile); + if (snow_or_desert != (z > GetSnowLine())) { SetTunnelBridgeSnowOrDesert(tile, !snow_or_desert); MarkTileDirtyByTile(tile); } break; + } case LT_TROPIC: if (GetTropicZone(tile) == TROPICZONE_DESERT && !snow_or_desert) { Index: src/newgrf_spritegroup.h =================================================================== --- src/newgrf_spritegroup.h (revision 20201) +++ src/newgrf_spritegroup.h (working copy) @@ -22,6 +22,7 @@ #include "newgrf_callbacks.h" #include "newgrf_generic.h" #include "newgrf_storage.h" +#include "newgrf_commons.h" /** * Gets the value of a so-called newgrf "register". @@ -343,7 +344,7 @@ } generic; struct { TileIndex tile; - bool upper_halftile; ///< Are we resolving sprites for the upper halftile? + TileContext context; ///< Are we resolving sprites for the upper halftile, or on a bridge? } routes; struct { const struct Station *st; Index: src/newgrf_railtype.cpp =================================================================== --- src/newgrf_railtype.cpp (revision 20201) +++ src/newgrf_railtype.cpp (working copy) @@ -48,7 +48,7 @@ } switch (variable) { - case 0x40: return GetTerrainType(tile, object->u.routes.upper_halftile); + case 0x40: return GetTerrainType(tile, object->u.routes.context); case 0x41: return 0; case 0x42: return IsLevelCrossingTile(tile) && IsCrossingBarred(tile); case 0x43: @@ -69,7 +69,7 @@ return NULL; } -static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, bool upper_halftile) +static inline void NewRailTypeResolver(ResolverObject *res, TileIndex tile, TileContext context) { res->GetRandomBits = &RailTypeGetRandomBits; res->GetTriggers = &RailTypeGetTriggers; @@ -78,7 +78,7 @@ res->ResolveReal = &RailTypeResolveReal; res->u.routes.tile = tile; - res->u.routes.upper_halftile = upper_halftile; + res->u.routes.context = context; res->callback = CBID_NO_CALLBACK; res->callback_param1 = 0; @@ -89,7 +89,7 @@ res->count = 0; } -SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, bool upper_halftile) +SpriteID GetCustomRailSprite(const RailtypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context) { assert(rtsg < RTSG_END); @@ -98,7 +98,7 @@ const SpriteGroup *group; ResolverObject object; - NewRailTypeResolver(&object, tile, upper_halftile); + NewRailTypeResolver(&object, tile, context); group = SpriteGroup::Resolve(rti->group[rtsg], &object); if (group == NULL || group->GetNumResults() == 0) return 0; @@ -128,5 +128,5 @@ */ void GetRailTypeResolver(ResolverObject *ro, uint index) { - NewRailTypeResolver(ro, index, false); + NewRailTypeResolver(ro, index, TC_NORMAL); } Index: src/elrail.cpp =================================================================== --- src/elrail.cpp (revision 20201) +++ src/elrail.cpp (working copy) @@ -165,20 +165,20 @@ /** * Get the base wire sprite to use. */ -static inline SpriteID GetWireBase(TileIndex tile, bool upper_halftile = false) +static inline SpriteID GetWireBase(TileIndex tile, TileContext context = TC_NORMAL) { const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile)); - SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES, upper_halftile); + SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES, context); return wires == 0 ? SPR_WIRE_BASE : wires; } /** * Get the base pylon sprite to use. */ -static inline SpriteID GetPylonBase(TileIndex tile, bool upper_halftile = false) +static inline SpriteID GetPylonBase(TileIndex tile, TileContext context = TC_NORMAL) { const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(tile)); - SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, upper_halftile); + SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, context); return pylons == 0 ? SPR_PYLON_BASE : pylons; } @@ -300,7 +300,7 @@ AdjustTileh(ti->tile, &tileh[TS_HOME]); SpriteID pylon_normal = GetPylonBase(ti->tile); - SpriteID pylon_halftile = (halftile_corner != CORNER_INVALID) ? GetPylonBase(ti->tile, true) : pylon_normal; + SpriteID pylon_halftile = (halftile_corner != CORNER_INVALID) ? GetPylonBase(ti->tile, TC_UPPER_HALFTILE) : pylon_normal; for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) { static const uint edge_corners[] = { @@ -439,7 +439,7 @@ } SpriteID wire_normal = GetWireBase(ti->tile); - SpriteID wire_halftile = (halftile_corner != CORNER_INVALID) ? GetWireBase(ti->tile, true) : wire_normal; + SpriteID wire_halftile = (halftile_corner != CORNER_INVALID) ? GetWireBase(ti->tile, TC_UPPER_HALFTILE) : wire_normal; Track halftile_track; switch (halftile_corner) { case CORNER_W: halftile_track = TRACK_LEFT; break; @@ -500,14 +500,14 @@ height = GetBridgeHeight(end); - SpriteID wire_base = GetWireBase(start); + SpriteID wire_base = GetWireBase(start, TC_ON_BRIDGE); AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset, IsTransparencySet(TO_CATENARY) ); - SpriteID pylon_base = GetPylonBase(start); + SpriteID pylon_base = GetPylonBase(start, TC_ON_BRIDGE); /* Finished with wires, draw pylons * every other tile needs a pylon on the northern end */ Index: src/newgrf_commons.h =================================================================== --- src/newgrf_commons.h (revision 20201) +++ src/newgrf_commons.h (working copy) @@ -16,6 +16,13 @@ #include "tile_cmd.h" +/** Contextx for tile accesses */ +enum TileContext { + TC_NORMAL, ///< Nothing special. + TC_UPPER_HALFTILE, ///< Querying information about the upper part of a tile with halftile foundation. + TC_ON_BRIDGE, ///< Querying information about stuff on the bridge (via some bridgehead). +}; + /** * Maps an entity id stored on the map to a GRF file. * Entities are objects used ingame (houses, industries, industry tiles) for @@ -123,7 +130,7 @@ extern AirportOverrideManager _airport_mngr; extern AirportTileOverrideManager _airporttile_mngr; -uint32 GetTerrainType(TileIndex tile, bool upper_halftile = false); +uint32 GetTerrainType(TileIndex tile, TileContext context = TC_NORMAL); TileIndex GetNearbyTile(byte parameter, TileIndex tile); uint32 GetNearbyTileInformation(TileIndex tile); Index: src/newgrf_commons.cpp =================================================================== --- src/newgrf_commons.cpp (revision 20201) +++ src/newgrf_commons.cpp (working copy) @@ -283,7 +283,7 @@ * @param upper_halftile If true, query upper halftile in case of rail tiles. * @return value corresponding to the grf expected format: * Terrain type: 0 normal, 1 desert, 2 rainforest, 4 on or above snowline */ -uint32 GetTerrainType(TileIndex tile, bool upper_halftile) +uint32 GetTerrainType(TileIndex tile, TileContext context) { switch (_settings_game.game_creation.landscape) { case LT_TROPIC: return GetTropicZone(tile); @@ -296,7 +296,7 @@ case MP_RAILWAY: { RailGroundType ground = GetRailGroundType(tile); - has_snow = (ground == RAIL_GROUND_ICE_DESERT || (upper_halftile && ground == RAIL_GROUND_HALF_SNOW)); + has_snow = (ground == RAIL_GROUND_ICE_DESERT || (context == TC_UPPER_HALFTILE && ground == RAIL_GROUND_HALF_SNOW)); break; } @@ -311,7 +311,11 @@ } case MP_TUNNELBRIDGE: - has_snow = HasTunnelBridgeSnowOrDesert(tile); + if (context == TC_ON_BRIDGE) { + has_snow = (GetBridgeHeight(tile) > GetSnowLine()); + } else { + has_snow = HasTunnelBridgeSnowOrDesert(tile); + } break; case MP_STATION: