celestar@3355: /* $Id$ */ belugas@6443: /** @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" rubidium@8720: #include "viewport_func.h" rubidium@8766: #include "settings_type.h" maedhros@6949: #include "landscape.h" rubidium@8599: #include "rail_type.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" KUDr@5116: #include "train.h" rubidium@8607: #include "rail_gui.h" belugas@8345: #include "transparency.h" smatz@8579: #include "tunnelbridge_map.h" rubidium@8640: #include "vehicle_func.h" rubidium@8750: #include "player_base.h" smatz@8894: #include "tunnelbridge.h" rubidium@9282: #include "engine_func.h" smatz@8579: rubidium@8760: #include "table/sprites.h" rubidium@8760: #include "table/elrail_data.h" celestar@3355: celestar@3355: static inline TLG GetTLG(TileIndex t) celestar@3355: { skidd13@8424: return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0)); celestar@3355: } celestar@3355: smatz@8895: /** smatz@8895: * Finds which Electrified Rail Bits are present on a given tile. smatz@8895: * @param t tile to check smatz@8895: * @param override pointer to PCP override, can be NULL smatz@8895: * @return trackbits of tile if it is electrified rubidium@4549: */ celestar@3355: static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) celestar@3355: { celestar@3355: switch (GetTileType(t)) { celestar@3355: case MP_RAILWAY: peter1138@9228: if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE; celestar@3355: switch (GetRailTileType(t)) { rubidium@3792: case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS: celestar@3355: return GetTrackBits(t); rubidium@6498: case RAIL_TILE_WAYPOINT: rubidium@6498: return GetRailWaypointBits(t); celestar@3355: default: rubidium@5838: return TRACK_BIT_NONE; celestar@3355: } celestar@3355: break; tron@4077: celestar@3355: case MP_TUNNELBRIDGE: peter1138@9228: if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE; smatz@8895: if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) { smatz@8584: *override = 1 << GetTunnelBridgeDirection(t); celestar@3355: } smatz@8584: return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t))); tron@4077: rubidium@7866: case MP_ROAD: frosch@9059: if (!IsLevelCrossing(t)) return TRACK_BIT_NONE; peter1138@9228: if (!HasCatenary(GetRailType(t))) 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; peter1138@9228: if (!HasCatenary(GetRailType(t))) 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)) { rubidium@6595: *tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon rubidium@6595: } else if (*tileh != SLOPE_FLAT) { rubidium@6595: *tileh = SLOPE_FLAT; celestar@3451: } else { frosch@8909: *tileh = InclinedSlope(GetTunnelBridgeDirection(tile)); celestar@3451: } celestar@3451: } celestar@3451: } celestar@3451: rubidium@8030: /** rubidium@8030: * Returns the Z position of a Pylon Control Point. rubidium@8030: * rubidium@8030: * @param tile The tile the pylon should stand on. rubidium@8030: * @param PCPpos The PCP of the tile. rubidium@8030: * @return The Z position of the PCP. rubidium@8030: */ rubidium@8030: static byte GetPCPElevation(TileIndex tile, DiagDirection PCPpos) rubidium@8030: { rubidium@8030: /* The elevation of the "pylon"-sprite should be the elevation at the PCP. rubidium@8030: * PCPs are always on a tile edge. rubidium@8030: * rubidium@8030: * This position can be outside of the tile, i.e. ?_pcp_offset == TILE_SIZE > TILE_SIZE - 1. rubidium@8030: * So we have to move it inside the tile, because if the neighboured tile has a foundation, rubidium@8030: * that does not smoothly connect to the current tile, we will get a wrong elevation from GetSlopeZ(). rubidium@8030: * rubidium@8030: * When we move the position inside the tile, we will get a wrong elevation if we have a slope. rubidium@8030: * To catch all cases we round the Z position to the next (TILE_HEIGHT / 2). rubidium@8030: * This will return the correct elevation for slopes and will also detect non-continuous elevation on edges. rubidium@8030: * rubidium@8030: * Also note that the result of GetSlopeZ() is very special on bridge-ramps. rubidium@8030: */ rubidium@8030: rubidium@8030: byte z = GetSlopeZ(TileX(tile) * TILE_SIZE + min(x_pcp_offsets[PCPpos], TILE_SIZE - 1), TileY(tile) * TILE_SIZE + min(y_pcp_offsets[PCPpos], TILE_SIZE - 1)); rubidium@8030: return (z + 2) & ~3; // this means z = (z + TILE_HEIGHT / 4) / (TILE_HEIGHT / 2) * (TILE_HEIGHT / 2); rubidium@8030: } rubidium@8030: rubidium@8097: /** rubidium@8097: * Draws wires on a tunnel tile rubidium@8097: * rubidium@8097: * DrawTile_TunnelBridge() calls this function to draw the wires as SpriteCombine with the tunnel roof. rubidium@8097: * rubidium@8097: * @param ti The Tileinfo to draw the tile for rubidium@8097: */ rubidium@8097: void DrawCatenaryOnTunnel(const TileInfo *ti) rubidium@8097: { rubidium@8097: /* xmin, ymin, xmax + 1, ymax + 1 of BB */ rubidium@8097: static const int _tunnel_wire_BB[4][4] = { rubidium@8097: { 0, 1, 16, 15 }, // NE rubidium@8097: { 1, 0, 15, 16 }, // SE rubidium@8097: { 0, 1, 16, 15 }, // SW rubidium@8097: { 1, 0, 15, 16 }, // NW rubidium@8097: }; rubidium@8097: peter1138@9228: if (!HasCatenary(GetRailType(ti->tile)) || _patches.disable_elrails) return; rubidium@8097: smatz@8579: DiagDirection dir = GetTunnelBridgeDirection(ti->tile); rubidium@8097: rubidium@8097: const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir]; rubidium@8097: const int *BB_data = _tunnel_wire_BB[dir]; rubidium@8097: AddSortableSpriteToDraw( rubidium@8097: sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, rubidium@8097: BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset + 1, rubidium@8097: GetTileZ(ti->tile) + sss->z_offset, smatz@9024: IsTransparencySet(TO_CATENARY), rubidium@8097: BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset rubidium@8097: ); rubidium@8097: } rubidium@8097: 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: rubidium@8260: /* Half tile slopes coincide only with horizontal/vertical track. rubidium@8260: * Faking a flat slope results in the correct sprites on positions. */ rubidium@8260: if (IsHalftileSlope(tileh[TS_HOME])) tileh[TS_HOME] = SLOPE_FLAT; rubidium@8260: 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); rubidium@7831: Foundation foundation = FOUNDATION_NONE; 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); smatz@8579: if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE; rubidium@8030: rubidium@8030: /* If the neighboured tile does not smoothly connect to the current tile (because of a foundation), rubidium@8030: * we have to draw all pillars on the current tile. */ rubidium@8030: if (GetPCPElevation(ti->tile, i) != GetPCPElevation(neighbour, ReverseDiagDir(i))) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE; rubidium@8030: rubidium@5838: isflat[TS_NEIGHBOUR] = ((trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0); celestar@3355: rubidium@6595: 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) && smatz@8579: GetTunnelBridgeDirection(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) */ skidd13@8424: 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); skidd13@8427: 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 */ skidd13@8424: PPPpreferred[i] *= HasBit(PCPstatus, i); skidd13@8424: 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 */ peter1138@9228: if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && HasCatenary(GetRailType(neighbour))) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]); celestar@5573: if (IsBridgeTile(neighbour)) { smatz@8579: foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour))); celestar@3368: } celestar@3368: rubidium@7831: ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]); celestar@3355: rubidium@8260: /* Half tile slopes coincide only with horizontal/vertical track. rubidium@8260: * Faking a flat slope results in the correct sprites on positions. */ rubidium@8260: if (IsHalftileSlope(tileh[TS_NEIGHBOUR])) tileh[TS_NEIGHBOUR] = SLOPE_FLAT; rubidium@8260: 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++) skidd13@8425: 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: rubidium@7195: if ((height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) && rubidium@6595: (i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) { skidd13@8427: SetBit(OverridePCP, i); rubidium@6595: } celestar@5573: } celestar@5573: skidd13@8424: 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: skidd13@8424: 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 */ skidd13@8424: 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: rubidium@8097: AddSortableSpriteToDraw(pylon_sprites[temp], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, rubidium@8030: GetPCPElevation(ti->tile, i), smatz@9024: IsTransparencySet(TO_CATENARY), -1, -1); 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 */ smatz@9024: if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) { celestar@5573: uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile)); celestar@5573: rubidium@7195: if (height <= GetTileMaxZ(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++) { skidd13@8424: if (HasBit(trackconfig[TS_HOME], t)) { rubidium@8097: if (IsTunnelTile(ti->tile)) break; // drawn together with tunnel-roof (see DrawCatenaryOnTunnel()) skidd13@8424: byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) + skidd13@8424: (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: rubidium@8030: /* rubidium@8030: * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE. rubidium@8030: * Therefore it is save to use GetSlopeZ() for the elevation. rubidium@8030: * Also note, that the result of GetSlopeZ() is very special for bridge-ramps. rubidium@8030: */ rubidium@7829: AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, rubidium@8030: sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset, smatz@9024: IsTransparencySet(TO_CATENARY)); 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: smatz@8894: uint length = GetTunnelBridgeLength(start, end); smatz@8894: uint num = GetTunnelBridgeLength(ti->tile, start) + 1; 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: rubidium@7829: AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, rubidium@7829: sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset, smatz@9024: IsTransparencySet(TO_CATENARY) 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) { rubidium@8030: DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_NE : DIAGDIR_NW); rubidium@8030: Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE); skidd13@8424: if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos); rubidium@8030: uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos]; rubidium@8030: uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos]; smatz@9024: AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1); celestar@3355: } celestar@3355: celestar@3445: /* need a pylon on the southern end of the bridge */ smatz@8894: if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) { rubidium@8030: DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE); rubidium@8030: Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE); skidd13@8424: if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos); rubidium@8030: uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos]; rubidium@8030: uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos]; smatz@9024: AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1); celestar@3355: } celestar@3355: } celestar@3355: celestar@3355: void DrawCatenary(const TileInfo *ti) celestar@3355: { rubidium@7516: if (_patches.disable_elrails) return; rubidium@7516: smatz@9302: /* Do not draw catenary if it is invisible */ smatz@9302: if (IsInvisibilitySet(TO_CATENARY)) return; smatz@9302: celestar@5573: if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) { celestar@5573: TileIndex head = GetNorthernBridgeEnd(ti->tile); celestar@5573: peter1138@9228: if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && HasCatenary(GetRailType(head))) { celestar@5573: DrawCatenaryOnBridge(ti); celestar@5573: } celestar@5573: } KUDr@5116: celestar@3355: switch (GetTileType(ti->tile)) { celestar@3355: case MP_RAILWAY: rubidium@6595: if (IsRailDepot(ti->tile)) { rubidium@6595: const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)]; tron@4470: rubidium@8030: /* This wire is not visible with the default depot sprites */ tron@4470: AddSortableSpriteToDraw( rubidium@7829: sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, tron@4470: sss->x_size, sss->y_size, sss->z_size, rubidium@7829: GetTileMaxZ(ti->tile) + sss->z_offset, smatz@9024: IsTransparencySet(TO_CATENARY) tron@4470: ); celestar@3355: return; celestar@3355: } tron@3995: break; tron@3995: celestar@3355: case MP_TUNNELBRIDGE: rubidium@7866: case MP_ROAD: 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: { rubidium@6595: 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 */ peter1138@8897: EngineID eid; peter1138@8897: FOR_ALL_ENGINEIDS_OF_TYPE(eid, VEH_TRAIN) { peter1138@8897: RailVehicleInfo *rv_info = &_rail_vehicle_info[eid]; 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) { rubidium@6585: 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 */ rubidium@8732: v->u.rail.compatible_railtypes |= RAILTYPES_RAIL; KUDr@5116: v->u.rail.railtype = RAILTYPE_RAIL; skidd13@8427: 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 */ rubidium@6585: 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: }