celestar@3355: /* $Id$ */ bjarni@6268: /** @file elrail.cpp rubidium@4549: * This file deals with displaying wires and pylons for electric railways. rubidium@4549: *

Basics

rubidium@4549: * rubidium@4549: *

Tile Types

rubidium@4549: * rubidium@4549: * We have two different types of tiles in the drawing code: rubidium@4549: * Normal Railway Tiles (NRTs) which can have more than one track on it, and rubidium@4549: * Special Railways tiles (SRTs) which have only one track (like crossings, depots rubidium@4549: * stations, etc). rubidium@4549: * rubidium@4549: *

Location Categories

rubidium@4549: * rubidium@4549: * All tiles are categorized into three location groups (TLG): rubidium@4549: * Group 0: Tiles with both an even X coordinate and an even Y coordinate rubidium@4549: * Group 1: Tiles with an even X and an odd Y coordinate rubidium@4549: * Group 2: Tiles with an odd X and an even Y coordinate rubidium@4549: * Group 3: Tiles with both an odd X and Y coordnate. rubidium@4549: * rubidium@4549: *

Pylon Points

rubidium@4549: *

Control Points

rubidium@4549: * A Pylon Control Point (PCP) is a position where a wire (or rather two) rubidium@4549: * is mounted onto a pylon. rubidium@4549: * Each NRT does contain 4 PCPs which are bitmapped to a byte rubidium@4549: * variable and are represented by the DiagDirection enum rubidium@4549: * rubidium@4549: * Each track ends on two PCPs and thus requires one pylon on each end. However, rubidium@4549: * there is one exception: Straight-and-level tracks only have one pylon every rubidium@4549: * other tile. rubidium@4549: * rubidium@4549: * Now on each edge there are two PCPs: One from each adjacent tile. Both PCPs rubidium@4549: * are merged using an OR operation (i. e. if one tile needs a PCP at the postion rubidium@4549: * in question, both tiles get it). rubidium@4549: * rubidium@4549: *

Position Points

rubidium@4549: * A Pylon Position Point (PPP) is a position where a pylon is located on the rubidium@4549: * ground. Each PCP owns 8 in (45 degree steps) PPPs that are located around rubidium@4549: * it. PPPs are represented using the Direction enum. Each track bit has PPPs rubidium@4549: * that are impossible (because the pylon would be situated on the track) and rubidium@4549: * some that are preferred (because the pylon would be rectangular to the track). rubidium@4549: * rubidium@4549: * rubidium@4549: * rubidium@4549: * rubidium@4549: */ celestar@3355: celestar@3355: #include "stdafx.h" celestar@3355: #include "openttd.h" tron@3367: #include "station_map.h" celestar@3355: #include "tile.h" celestar@3355: #include "viewport.h" celestar@3355: #include "functions.h" /* We should REALLY get rid of this goddamn file, as it is butt-ugly */ celestar@3355: #include "variables.h" /* ... same here */ KUDr@6307: #include "landscape.h" celestar@3355: #include "rail.h" celestar@3355: #include "debug.h" celestar@3355: #include "tunnel_map.h" celestar@3355: #include "road_map.h" celestar@3355: #include "bridge_map.h" celestar@3355: #include "bridge.h" celestar@3355: #include "rail_map.h" celestar@3355: #include "table/sprites.h" celestar@3355: #include "table/elrail_data.h" KUDr@5116: #include "vehicle.h" KUDr@5116: #include "train.h" KUDr@5116: #include "gui.h" celestar@3355: celestar@3355: static inline TLG GetTLG(TileIndex t) celestar@3355: { rubidium@5838: return (TLG)((HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0)); celestar@3355: } celestar@3355: celestar@3355: /** Finds which Rail Bits are present on a given tile. For bridge tiles, rubidium@4549: * returns track bits under the bridge rubidium@4549: */ celestar@3355: static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) celestar@3355: { celestar@3355: switch (GetTileType(t)) { celestar@3355: case MP_RAILWAY: rubidium@5838: if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; celestar@3355: switch (GetRailTileType(t)) { rubidium@3792: case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS: celestar@3355: return GetTrackBits(t); KUDr@6285: case RAIL_TILE_WAYPOINT: KUDr@6285: return GetRailWaypointBits(t); celestar@3355: default: rubidium@5838: return TRACK_BIT_NONE; celestar@3355: } celestar@3355: break; tron@4077: celestar@3355: case MP_TUNNELBRIDGE: celestar@3355: if (IsTunnel(t)) { rubidium@5838: if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; celestar@3355: if (override != NULL) *override = 1 << GetTunnelDirection(t); tron@4158: return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t))); celestar@3355: } else { rubidium@5838: if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; celestar@5573: if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) { celestar@5573: *override = 1 << GetBridgeRampDirection(t); celestar@3355: } celestar@5573: return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t))); celestar@3355: } tron@4077: celestar@3355: case MP_STREET: rubidium@5838: if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE; KUDr@6285: if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; celestar@3355: return GetCrossingRailBits(t); tron@4077: celestar@3355: case MP_STATION: rubidium@5838: if (!IsRailwayStation(t)) return TRACK_BIT_NONE; rubidium@5838: if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; rubidium@5838: if (!IsStationTileElectrifiable(t)) return TRACK_BIT_NONE; celestar@3375: return TrackToTrackBits(GetRailStationTrack(t)); tron@4077: celestar@3355: default: rubidium@5838: return TRACK_BIT_NONE; celestar@3355: } celestar@3355: } celestar@3355: celestar@3451: /** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile. rubidium@4549: * @param tile The tile to analyse rubidium@4549: * @param *tileh the tileh rubidium@4549: */ belugas@4171: static void AdjustTileh(TileIndex tile, Slope *tileh) celestar@3451: { tron@4077: if (IsTileType(tile, MP_TUNNELBRIDGE)) { tron@4077: if (IsTunnel(tile)) { bjarni@6298: *tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon bjarni@6298: } else if (*tileh != SLOPE_FLAT) { tron@3636: *tileh = SLOPE_FLAT; celestar@3451: } else { bjarni@6298: switch (GetBridgeRampDirection(tile)) { bjarni@6298: case DIAGDIR_NE: *tileh = SLOPE_NE; break; bjarni@6298: case DIAGDIR_SE: *tileh = SLOPE_SE; break; bjarni@6298: case DIAGDIR_SW: *tileh = SLOPE_SW; break; bjarni@6298: case DIAGDIR_NW: *tileh = SLOPE_NW; break; bjarni@6298: default: NOT_REACHED(); celestar@3451: } celestar@3451: } celestar@3451: } celestar@3451: } celestar@3451: celestar@3355: /** Draws wires and, if required, pylons on a given tile rubidium@4549: * @param ti The Tileinfo to draw the tile for rubidium@4549: */ celestar@3355: static void DrawCatenaryRailway(const TileInfo *ti) celestar@3355: { celestar@3355: /* Pylons are placed on a tile edge, so we need to take into account rubidium@4549: * the track configuration of 2 adjacent tiles. trackconfig[0] stores the rubidium@4549: * current tile (home tile) while [1] holds the neighbour */ celestar@3355: TrackBits trackconfig[TS_END]; celestar@3355: bool isflat[TS_END]; celestar@3355: /* Note that ti->tileh has already been adjusted for Foundations */ tron@3636: Slope tileh[TS_END] = { ti->tileh, SLOPE_FLAT }; celestar@3355: celestar@3355: TLG tlg = GetTLG(ti->tile); celestar@3355: byte PCPstatus = 0; celestar@3355: byte OverridePCP = 0; orudge@3395: byte PPPpreferred[DIAGDIR_END]; orudge@3395: byte PPPallowed[DIAGDIR_END]; celestar@3355: DiagDirection i; celestar@3355: Track t; celestar@3355: celestar@3355: /* Find which rail bits are present, and select the override points. rubidium@4549: * We don't draw a pylon: rubidium@4549: * 1) INSIDE a tunnel (we wouldn't see it anyway) rubidium@4549: * 2) on the "far" end of a bridge head (the one that connects to bridge middle), rubidium@4549: * because that one is drawn on the bridge. Exception is for length 0 bridges rubidium@4549: * which have no middle tiles */ celestar@3355: trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP); celestar@3355: /* If a track bit is present that is not in the main direction, the track is level */ rubidium@5838: isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0); celestar@3355: celestar@3451: AdjustTileh(ti->tile, &tileh[TS_HOME]); celestar@3355: celestar@3355: for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) { Darkvater@4559: TileIndex neighbour = ti->tile + TileOffsByDiagDir(i); celestar@3355: uint foundation = 0; celestar@3355: int k; celestar@3355: celestar@3355: /* Here's one of the main headaches. GetTileSlope does not correct for possibly rubidium@4549: * existing foundataions, so we do have to do that manually later on.*/ celestar@3355: tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL); celestar@3355: trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL); rubidium@5838: if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE; rubidium@5838: isflat[TS_NEIGHBOUR] = ((trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0); celestar@3355: bjarni@6298: PPPpreferred[i] = 0xFF; // We start with preferring everything (end-of-line in any direction) celestar@3451: PPPallowed[i] = AllowedPPPonPCP[i]; celestar@3451: celestar@3355: /* We cycle through all the existing tracks at a PCP and see what rubidium@4549: * PPPs we want to have, or may not have at all */ celestar@3451: for (k = 0; k < NUM_TRACKS_AT_PCP; k++) { celestar@3355: /* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */ celestar@3451: if (TrackSourceTile[i][k] == TS_NEIGHBOUR && celestar@5573: IsBridgeTile(neighbour) && tron@4000: GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) { tron@4000: continue; tron@4000: } celestar@3355: celestar@3451: /* We check whether the track in question (k) is present in the tile rubidium@4549: * (TrackSourceTile) */ celestar@3451: if (HASBIT(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) { celestar@3451: /* track found, if track is in the neighbour tile, adjust the number rubidium@4549: * of the PCP for preferred/allowed determination*/ celestar@3451: DiagDirection PCPpos = (TrackSourceTile[i][k] == TS_HOME) ? i : ReverseDiagDir(i); bjarni@6298: SETBIT(PCPstatus, i); // This PCP is in use celestar@3451: celestar@3451: PPPpreferred[i] &= PreferredPPPofTrackAtPCP[TracksAtPCP[i][k]][PCPpos]; celestar@3451: PPPallowed[i] &= ~DisallowedPPPofTrackAtPCP[TracksAtPCP[i][k]][PCPpos]; celestar@3355: } celestar@3355: } celestar@3355: celestar@3355: /* Deactivate all PPPs if PCP is not used */ celestar@3355: PPPpreferred[i] *= HASBIT(PCPstatus, i); celestar@3355: PPPallowed[i] *= HASBIT(PCPstatus, i); celestar@3355: celestar@3880: /* A station is always "flat", so adjust the tileh accordingly */ celestar@3880: if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT; celestar@3355: celestar@3355: /* Read the foundataions if they are present, and adjust the tileh */ glx@4448: if (IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]); celestar@5573: if (IsBridgeTile(neighbour)) { celestar@3368: foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour))); celestar@3368: } celestar@3368: celestar@3355: if (foundation != 0) { bjarni@6298: tileh[TS_NEIGHBOUR] = foundation < 15 ? SLOPE_FLAT : _inclined_tileh[foundation - 15]; celestar@3355: } celestar@3355: celestar@3451: AdjustTileh(neighbour, &tileh[TS_NEIGHBOUR]); celestar@3355: celestar@3355: /* If we have a straight (and level) track, we want a pylon only every 2 tiles rubidium@4549: * Delete the PCP if this is the case. */ celestar@3355: /* Level means that the slope is the same, or the track is flat */ celestar@3355: if (tileh[TS_HOME] == tileh[TS_NEIGHBOUR] || (isflat[TS_HOME] && isflat[TS_NEIGHBOUR])) { celestar@3355: for (k = 0; k < NUM_IGNORE_GROUPS; k++) celestar@3451: if (PPPpreferred[i] == IgnoredPCP[k][tlg][i]) CLRBIT(PCPstatus, i); celestar@3355: } celestar@3355: celestar@3451: /* Now decide where we draw our pylons. First try the preferred PPPs, but they may not exist. rubidium@4549: * In that case, we try the any of the allowed ones. if they don't exist either, don't draw rubidium@4549: * anything. Note that the preferred PPPs still contain the end-of-line markers. rubidium@4549: * Remove those (simply by ANDing with allowed, since these markers are never allowed) */ tron@4077: if ((PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i]; celestar@3355: celestar@5573: if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) { celestar@5573: Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y; celestar@5573: uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile)); celestar@5573: celestar@5573: if ((height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) && bjarni@6298: (i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) { bjarni@6298: SETBIT(OverridePCP, i); bjarni@6298: } celestar@5573: } celestar@5573: celestar@3451: if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) { celestar@3355: for (k = 0; k < DIR_END; k++) { celestar@3355: byte temp = PPPorder[i][GetTLG(ti->tile)][k]; tron@4077: celestar@3451: if (HASBIT(PPPallowed[i], temp)) { celestar@3355: uint x = ti->x + x_pcp_offsets[i] + x_ppp_offsets[temp]; celestar@3355: uint y = ti->y + y_pcp_offsets[i] + y_ppp_offsets[temp]; celestar@3355: celestar@3355: /* Don't build the pylon if it would be outside the tile */ celestar@3355: if (!HASBIT(OwnedPPPonPCP[i], temp)) { celestar@3355: /* We have a neighour that will draw it, bail out */ celestar@3355: if (trackconfig[TS_NEIGHBOUR] != 0) break; celestar@3355: continue; /* No neighbour, go looking for a better position */ celestar@3355: } celestar@3355: KUDr@6307: SpriteID img = pylons_normal[temp]; KUDr@6307: SpriteID pal = PAL_NONE; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) { KUDr@6307: SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: pal = PALETTE_TO_TRANSPARENT; KUDr@6307: } KUDr@6307: KUDr@6307: AddSortableSpriteToDraw(img, pal, x, y, 1, 1, 10, celestar@3355: GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i])); celestar@3355: break; /* We already have drawn a pylon, bail out */ celestar@3355: } celestar@3355: } celestar@3355: } celestar@3355: } celestar@3355: tron@4480: /* Don't draw a wire under a low bridge */ KUDr@6307: if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !HASBIT(_transparent_opt, TO_BUILDINGS)) { celestar@5573: uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile)); celestar@5573: celestar@5573: if (height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) return; tron@4480: } tron@4480: celestar@3355: /* Drawing of pylons is finished, now draw the wires */ rubidium@5838: for (t = TRACK_BEGIN; t < TRACK_END; t++) { celestar@3355: if (HASBIT(trackconfig[TS_HOME], t)) { bjarni@6298: if (IsTunnelTile(ti->tile)) { bjarni@6298: const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[GetTunnelDirection(ti->tile)]; celestar@3355: bjarni@6298: AddSortableSpriteToDraw( bjarni@6298: sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, bjarni@6298: sss->x_size, sss->y_size, sss->z_size, bjarni@6298: GetTileZ(ti->tile) + sss->z_offset bjarni@6298: ); bjarni@6298: break; bjarni@6298: } celestar@3355: byte PCPconfig = HASBIT(PCPstatus, PCPpositions[t][0]) + celestar@3355: (HASBIT(PCPstatus, PCPpositions[t][1]) << 1); celestar@3355: celestar@3355: const SortableSpriteStruct *sss; celestar@3355: int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; /* tileh for the slopes, 0 otherwise */ celestar@3355: celestar@3355: assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */ tron@3636: assert(!IsSteepSlope(tileh[TS_HOME])); celestar@3355: sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]]; celestar@3355: KUDr@6307: SpriteID img = sss->image; KUDr@6307: SpriteID pal = PAL_NONE; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) { KUDr@6307: SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: pal = PALETTE_TO_TRANSPARENT; KUDr@6307: } KUDr@6307: KUDr@6307: AddSortableSpriteToDraw(img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset, tron@3645: sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, TILE_SIZE - 1), ti->y + min(sss->y_offset, TILE_SIZE - 1)) + sss->z_offset); celestar@3355: } celestar@3355: } celestar@3355: } celestar@3355: celestar@3355: static void DrawCatenaryOnBridge(const TileInfo *ti) celestar@3355: { celestar@3445: TileIndex end = GetSouthernBridgeEnd(ti->tile); celestar@3445: TileIndex start = GetOtherBridgeEnd(end); celestar@3445: celestar@3445: uint length = GetBridgeLength(start, end); celestar@3355: uint num = DistanceMax(ti->tile, start); tron@4159: uint height; celestar@3445: celestar@3355: const SortableSpriteStruct *sss; celestar@3355: Axis axis = GetBridgeAxis(ti->tile); celestar@3355: TLG tlg = GetTLG(ti->tile); celestar@3355: rubidium@5838: CatenarySprite offset = (CatenarySprite)(axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH); celestar@3355: celestar@3355: if ((length % 2) && num == length) { celestar@3445: /* Draw the "short" wire on the southern end of the bridge celestar@3445: * only needed if the length of the bridge is odd */ celestar@3355: sss = &CatenarySpriteData[WIRE_X_FLAT_BOTH + offset]; celestar@3355: } else { celestar@3445: /* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */ celestar@3355: sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset]; celestar@3355: } celestar@3355: celestar@5573: height = GetBridgeHeight(end); tron@4159: KUDr@6307: SpriteID img = sss->image; KUDr@6307: SpriteID pal = PAL_NONE; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) { KUDr@6307: SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: pal = PALETTE_TO_TRANSPARENT; KUDr@6307: } KUDr@6307: KUDr@6307: AddSortableSpriteToDraw(img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset, tron@4159: sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset tron@4159: ); celestar@3445: celestar@3445: /* Finished with wires, draw pylons */ celestar@3445: /* every other tile needs a pylon on the northern end */ celestar@3355: if (num % 2) { celestar@3355: if (axis == AXIS_X) { KUDr@6307: img = pylons_bridge[0 + HASBIT(tlg, 0)]; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: AddSortableSpriteToDraw(img, pal, ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height); celestar@3355: } else { KUDr@6307: img = pylons_bridge[2 + HASBIT(tlg, 1)]; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: AddSortableSpriteToDraw(img, pal, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height); celestar@3355: } celestar@3355: } celestar@3355: celestar@3445: /* need a pylon on the southern end of the bridge */ celestar@3445: if (DistanceMax(ti->tile, start) == length) { celestar@3355: if (axis == AXIS_X) { KUDr@6307: img = pylons_bridge[0 + HASBIT(tlg, 0)]; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: AddSortableSpriteToDraw(img, pal, ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height); celestar@3355: } else { KUDr@6307: img = pylons_bridge[2 + HASBIT(tlg, 1)]; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: AddSortableSpriteToDraw(img, pal, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height); celestar@3355: } celestar@3355: } celestar@3355: } celestar@3355: celestar@3355: void DrawCatenary(const TileInfo *ti) celestar@3355: { celestar@5573: if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) { celestar@5573: TileIndex head = GetNorthernBridgeEnd(ti->tile); celestar@5573: celestar@5573: if (GetBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) { celestar@5573: DrawCatenaryOnBridge(ti); celestar@5573: } celestar@5573: } KUDr@5116: if (_patches.disable_elrails) return; KUDr@5116: celestar@3355: switch (GetTileType(ti->tile)) { celestar@3355: case MP_RAILWAY: tron@4182: if (IsRailDepot(ti->tile)) { bjarni@6298: const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)]; tron@4470: KUDr@6307: SpriteID img = sss->image; KUDr@6307: SpriteID pal = PAL_NONE; KUDr@6307: if (HASBIT(_transparent_opt, TO_BUILDINGS)) { KUDr@6307: SETBIT(img, PALETTE_MODIFIER_TRANSPARENT); KUDr@6307: pal = PALETTE_TO_TRANSPARENT; KUDr@6307: } KUDr@6307: tron@4470: AddSortableSpriteToDraw( KUDr@6307: img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset, tron@4470: sss->x_size, sss->y_size, sss->z_size, tron@4470: GetTileMaxZ(ti->tile) + sss->z_offset tron@4470: ); celestar@3355: return; celestar@3355: } tron@3995: break; tron@3995: celestar@3355: case MP_TUNNELBRIDGE: celestar@5573: case MP_STREET: celestar@5573: case MP_STATION: celestar@3355: break; tron@3995: tron@3995: default: return; celestar@3355: } tron@3995: DrawCatenaryRailway(ti); celestar@3355: } KUDr@5116: KUDr@5116: int32 SettingsDisableElrail(int32 p1) KUDr@5116: { KUDr@5116: EngineID e_id; bjarni@6298: Vehicle *v; KUDr@5116: Player *p; KUDr@5116: bool disable = (p1 != 0); KUDr@5116: KUDr@5116: /* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/ KUDr@5116: const RailType old_railtype = disable ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; KUDr@5116: const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC; KUDr@5116: KUDr@5116: /* walk through all train engines */ Darkvater@5314: for (e_id = 0; e_id < NUM_TRAIN_ENGINES; e_id++) { tron@6074: RailVehicleInfo *rv_info = &_rail_vehicle_info[e_id]; KUDr@5116: /* if it is an electric rail engine and its railtype is the wrong one */ tron@6074: if (rv_info->engclass == 2 && rv_info->railtype == old_railtype) { KUDr@5116: /* change it to the proper one */ tron@6074: rv_info->railtype = new_railtype; KUDr@5116: } KUDr@5116: } KUDr@5116: KUDr@5116: /* when disabling elrails, make sure that all existing trains can run on KUDr@5116: * normal rail too */ KUDr@5116: if (disable) { KUDr@5116: FOR_ALL_VEHICLES(v) { bjarni@6298: if (v->type == VEH_TRAIN && v->u.rail.railtype == RAILTYPE_ELECTRIC) { KUDr@5116: /* this railroad vehicle is now compatible only with elrail, KUDr@5116: * so add there also normal rail compatibility */ KUDr@5116: v->u.rail.compatible_railtypes |= (1 << RAILTYPE_RAIL); KUDr@5116: v->u.rail.railtype = RAILTYPE_RAIL; KUDr@5116: SETBIT(v->u.rail.flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL); KUDr@5116: } KUDr@5116: } KUDr@5116: } KUDr@5116: KUDr@5116: /* setup total power for trains */ KUDr@5116: FOR_ALL_VEHICLES(v) { KUDr@5116: /* power is cached only for front engines */ bjarni@6298: if (v->type == VEH_TRAIN && IsFrontEngine(v)) TrainPowerChanged(v); KUDr@5116: } KUDr@5116: KUDr@5116: FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index); KUDr@5116: KUDr@5116: /* This resets the _last_built_railtype, which will be invalid for electric KUDr@5116: * rails. It may have unintended consequences if that function is ever KUDr@5116: * extended, though. */ KUDr@5116: ReinitGuiAfterToggleElrail(disable); KUDr@5116: return 0; KUDr@5116: }