summaryrefslogtreecommitdiff
path: root/elrail.c
diff options
context:
space:
mode:
Diffstat (limited to 'elrail.c')
-rw-r--r--elrail.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/elrail.c b/elrail.c
index f0476d210..24bd2415a 100644
--- a/elrail.c
+++ b/elrail.c
@@ -91,18 +91,10 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
return DiagDirToAxis(GetTunnelDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
} else {
if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
- if (IsBridgeMiddle(t)) {
- if (IsTransportUnderBridge(t) &&
- GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) {
- return GetRailBitsUnderBridge(t);
- } else {
- return 0;
- }
- } else {
- if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) *override = 1 << GetBridgeRampDirection(t);
-
- return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
+ if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
+ *override = 1 << GetBridgeRampDirection(t);
}
+ return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
}
case MP_STREET:
if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0;
@@ -125,7 +117,7 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
static void AdjustTileh(TileIndex tile, Slope* tileh)
{
if (IsTunnelTile(tile)) *tileh = SLOPE_FLAT;
- if (IsBridgeTile(tile) && IsBridgeRamp(tile)) {
+ if (IsBridgeTile(tile)) {
if (*tileh != SLOPE_FLAT) {
*tileh = SLOPE_FLAT;
} else {
@@ -193,9 +185,10 @@ static void DrawCatenaryRailway(const TileInfo *ti)
for (k = 0; k < NUM_TRACKS_AT_PCP; k++) {
/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
- IsBridgeTile(neighbour) && IsBridgeRamp(neighbour) &&
- GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)
- ) continue;
+ IsBridgeTile(neighbour) &&
+ GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) {
+ continue;
+ }
/* We check whether the track in question (k) is present in the tile
(TrackSourceTile) */
@@ -219,7 +212,7 @@ static void DrawCatenaryRailway(const TileInfo *ti)
/* Read the foundataions if they are present, and adjust the tileh */
if (IsTileType(neighbour, MP_RAILWAY)) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
- if (IsBridgeTile(neighbour) && IsBridgeRamp(neighbour)) {
+ if (IsBridgeTile(neighbour)) {
foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
}
@@ -247,6 +240,14 @@ static void DrawCatenaryRailway(const TileInfo *ti)
Remove those (simply by ANDing with allowed, since these markers are never allowed) */
if ( (PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
+ if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
+ Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
+ uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile), GetBridgeAxis(ti->tile));
+
+ if ((height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) &&
+ (i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) SETBIT(OverridePCP, i);
+ }
+
if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
for (k = 0; k < DIR_END; k++) {
byte temp = PPPorder[i][GetTLG(ti->tile)][k];
@@ -279,12 +280,11 @@ static void DrawCatenaryRailway(const TileInfo *ti)
const SortableSpriteStruct *sss;
int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; /* tileh for the slopes, 0 otherwise */
- if ( /* We are not drawing a wire under a low bridge */
- IsBridgeTile(ti->tile) &&
- IsBridgeMiddle(ti->tile) &&
- !(_display_opt & DO_TRANS_BUILDINGS) &&
- GetBridgeHeight(ti->tile) <= TilePixelHeight(ti->tile)
- ) return;
+ if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !(_display_opt & DO_TRANS_BUILDINGS)) {
+ uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile), GetBridgeAxis(ti->tile));
+
+ if (height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) return;
+ }
assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
assert(!IsSteepSlope(tileh[TS_HOME]));
@@ -320,30 +320,37 @@ static void DrawCatenaryOnBridge(const TileInfo *ti)
}
AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
- sss->x_size, sss->y_size, sss->z_size, GetBridgeHeight(ti->tile) + sss->z_offset + 8);
+ sss->x_size, sss->y_size, sss->z_size, GetBridgeHeight(end, axis) + sss->z_offset);
/* Finished with wires, draw pylons */
/* every other tile needs a pylon on the northern end */
if (num % 2) {
if (axis == AXIS_X) {
- AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
+ AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(end, axis));
} else {
- AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
+ AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, GetBridgeHeight(end, axis));
}
}
/* need a pylon on the southern end of the bridge */
if (DistanceMax(ti->tile, start) == length) {
if (axis == AXIS_X) {
- AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
+ AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(end, axis));
} else {
- AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
+ AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, GetBridgeHeight(end, axis));
}
}
}
void DrawCatenary(const TileInfo *ti)
{
+ if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
+ TileIndex head = GetNorthernBridgeEnd(ti->tile);
+
+ if (GetBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
+ DrawCatenaryOnBridge(ti);
+ }
+ }
switch (GetTileType(ti->tile)) {
case MP_RAILWAY:
if (GetRailTileType(ti->tile) == RAIL_TILE_DEPOT_WAYPOINT && GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT) {
@@ -354,9 +361,8 @@ void DrawCatenary(const TileInfo *ti)
}
/* Fall through */
case MP_TUNNELBRIDGE:
- if (IsBridgeTile(ti->tile) && IsBridgeMiddle(ti->tile) && GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenaryOnBridge(ti);
- /* Fall further */
- case MP_STREET: case MP_STATION:
+ case MP_STREET:
+ case MP_STATION:
DrawCatenaryRailway(ti);
break;
default: