Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7958: Custom catenary missing on road bridges #7991

Merged
merged 2 commits into from
Feb 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/tunnelbridge_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,32 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis
}
}

/**
* Retrieve the sprites required for catenary on a road/tram bridge.
* @param rti RoadTypeInfo for the road or tram type to get catenary for
* @param head_tile Bridge head tile with roadtype information
* @param offset Sprite offset identifying flat to sloped bridge tiles
* @param head Are we drawing bridge head?
* @param[out] spr_back Back catenary sprite to use
* @param[out] spr_front Front catenary sprite to use
*/
static void GetBridgeRoadCatenary(const RoadTypeInfo *rti, TileIndex head_tile, int offset, bool head, SpriteID &spr_back, SpriteID &spr_front)
{
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };

/* Simplified from DrawRoadTypeCatenary() to remove all the special cases required for regular ground road */
spr_back = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
spr_front = GetCustomRoadSprite(rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
if (spr_back == 0 && spr_front == 0) {
spr_back = SPR_TRAMWAY_BASE + back_offsets[offset];
spr_front = SPR_TRAMWAY_BASE + front_offsets[offset];
} else {
if (spr_back != 0) spr_back += 23 + offset;
if (spr_front != 0) spr_front += 23 + offset;
}
}

/**
* Draws the road and trambits over an already drawn (lower end) of a bridge.
* @param head_tile bridge head tile with roadtype information
Expand All @@ -1126,9 +1152,6 @@ static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int off
bool trans_front[4] = { false };

static const SpriteID overlay_offsets[6] = { 0, 1, 11, 12, 13, 14 };
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };

if (head || !IsInvisibilitySet(TO_BRIDGES)) {
/* Road underlay takes precedence over tram */
trans_back[0] = !head && IsTransparencySet(TO_BRIDGES);
Expand Down Expand Up @@ -1168,25 +1191,9 @@ static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int off
trans_back[3] = IsTransparencySet(TO_CATENARY);
trans_front[0] = IsTransparencySet(TO_CATENARY);
if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
seq_back[3] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
seq_front[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
if (seq_back[3] == 0 || seq_front[0] == 0) {
seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
} else {
seq_back[3] += 23 + offset;
seq_front[0] += 23 + offset;
}
GetBridgeRoadCatenary(road_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
seq_back[3] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
seq_front[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
if (seq_back[3] == 0 || seq_front[0] == 0) {
seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
} else {
seq_back[3] += 23 + offset;
seq_front[0] += 23 + offset;
}
GetBridgeRoadCatenary(tram_rti, head_tile, offset, head, seq_back[3], seq_front[0]);
}
}

Expand Down