Changeset - r8732:71277f32d877
[Not reviewed]
master
0 6 0
peter1138 - 17 years ago 2008-03-25 12:10:13
peter1138@openttd.org
(svn r12410) -Codechange: abstract out the test for catenary on electric rails
6 files changed with 25 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/elrail.cpp
Show inline comments
 
@@ -81,38 +81,38 @@ static inline TLG GetTLG(TileIndex t)
 
 * @return trackbits of tile if it is electrified
 
 */
 
static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
 
{
 
	switch (GetTileType(t)) {
 
		case MP_RAILWAY:
 
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
 
			if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
 
			switch (GetRailTileType(t)) {
 
				case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS:
 
					return GetTrackBits(t);
 
				case RAIL_TILE_WAYPOINT:
 
					return GetRailWaypointBits(t);
 
				default:
 
					return TRACK_BIT_NONE;
 
			}
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
 
			if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
 
			if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
 
				*override = 1 << GetTunnelBridgeDirection(t);
 
			}
 
			return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
 

	
 
		case MP_ROAD:
 
			if (!IsLevelCrossing(t)) return TRACK_BIT_NONE;
 
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
 
			if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
 
			return GetCrossingRailBits(t);
 

	
 
		case MP_STATION:
 
			if (!IsRailwayStation(t)) return TRACK_BIT_NONE;
 
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
 
			if (!HasCatenary(GetRailType(t))) return TRACK_BIT_NONE;
 
			if (!IsStationTileElectrifiable(t)) return TRACK_BIT_NONE;
 
			return TrackToTrackBits(GetRailStationTrack(t));
 

	
 
		default:
 
			return TRACK_BIT_NONE;
 
	}
 
@@ -176,13 +176,13 @@ void DrawCatenaryOnTunnel(const TileInfo
 
		{ 0, 1, 16, 15 }, // NE
 
		{ 1, 0, 15, 16 }, // SE
 
		{ 0, 1, 16, 15 }, // SW
 
		{ 1, 0, 15, 16 }, // NW
 
	};
 

	
 
	if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
 
	if (!HasCatenary(GetRailType(ti->tile)) || _patches.disable_elrails) return;
 

	
 
	DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
 

	
 
	const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
 
	const int *BB_data = _tunnel_wire_BB[dir];
 
	AddSortableSpriteToDraw(
 
@@ -279,13 +279,13 @@ static void DrawCatenaryRailway(const Ti
 
		PPPallowed[i] *= HasBit(PCPstatus, i);
 

	
 
		/* A station is always "flat", so adjust the tileh accordingly */
 
		if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
 

	
 
		/* Read the foundataions if they are present, and adjust the tileh */
 
		if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
 
		if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && HasCatenary(GetRailType(neighbour))) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
 
		if (IsBridgeTile(neighbour)) {
 
			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
 
		}
 

	
 
		ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]);
 

	
 
@@ -433,13 +433,13 @@ void DrawCatenary(const TileInfo *ti)
 
{
 
	if (_patches.disable_elrails) return;
 

	
 
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
 
		TileIndex head = GetNorthernBridgeEnd(ti->tile);
 

	
 
		if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
 
		if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && HasCatenary(GetRailType(head))) {
 
			DrawCatenaryOnBridge(ti);
 
		}
 
	}
 

	
 
	switch (GetTileType(ti->tile)) {
 
		case MP_RAILWAY:
src/rail.h
Show inline comments
 
@@ -180,12 +180,23 @@ static inline Money RailConvertCost(Rail
 
void *UpdateTrainPowerProc(Vehicle *v, void *data);
 
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
 
void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
 
void *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
 
int TicksToLeaveDepot(const Vehicle *v);
 

	
 

	
 
/**
 
 * Test if a rail type has catenary
 
 * @param rt Rail type to test
 
 */
 
static inline bool HasCatenary(RailType rt)
 
{
 
	return rt == RAILTYPE_ELECTRIC;
 
}
 

	
 

	
 
/**
 
 * Draws overhead wires and pylons for electric railways.
 
 * @param ti The TileInfo struct of the tile being drawn
 
 * @see DrawCatenaryRailway
 
 */
 
void DrawCatenary(const TileInfo *ti);
src/rail_cmd.cpp
Show inline comments
 
@@ -1758,13 +1758,13 @@ static void DrawTile_Track(TileInfo *ti)
 
		TrackBits rails = GetTrackBits(ti->tile);
 

	
 
		DrawTrackBits(ti, rails);
 

	
 
		if (HasBit(_display_opt, DO_FULL_DETAIL)) DrawTrackDetails(ti);
 

	
 
		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
 
		if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
 

	
 
		if (HasSignals(ti->tile)) DrawSignals(ti->tile, rails);
 
	} else {
 
		/* draw depot/waypoint */
 
		const DrawTileSprites* dts;
 
		const DrawTileSeqStruct* dtss;
 
@@ -1832,13 +1832,13 @@ default_waypoint:
 
				if (IsSnowRailGround(ti->tile)) image += rti->snow_offset;
 
			}
 
		}
 

	
 
		DrawGroundSprite(image, PAL_NONE);
 

	
 
		if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
 
		if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
 

	
 
		foreach_draw_tile_seq(dtss, dts->seq) {
 
			SpriteID image = dtss->image.sprite;
 
			SpriteID pal;
 

	
 
			/* Unlike stations, our default waypoint has no variation for
src/road_cmd.cpp
Show inline comments
 
@@ -1108,13 +1108,13 @@ static void DrawTile_Road(TileInfo *ti)
 

	
 
			DrawGroundSprite(image, pal);
 
			if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
 
				DrawGroundSprite(SPR_TRAMWAY_OVERLAY + (GetCrossingRoadAxis(ti->tile) ^ 1), pal);
 
				DrawTramCatenary(ti, GetCrossingRoadBits(ti->tile));
 
			}
 
			if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenary(ti);
 
			if (HasCatenary(GetRailType(ti->tile))) DrawCatenary(ti);
 
			break;
 
		}
 

	
 
		default:
 
		case ROAD_TILE_DEPOT: {
 
			const DrawTileSprites* dts;
src/station_cmd.cpp
Show inline comments
 
@@ -2174,13 +2174,13 @@ static void DrawTile_Station(TileInfo *t
 
		} else {
 
			image += total_offset;
 
		}
 
		DrawGroundSprite(image, HasBit(image, PALETTE_MODIFIER_COLOR) ? palette : PAL_NONE);
 
	}
 

	
 
	if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
 
	if (HasCatenary(GetRailType(ti->tile)) && IsStationTileElectrifiable(ti->tile)) DrawCatenary(ti);
 

	
 
	if (HasBit(roadtypes, ROADTYPE_TRAM)) {
 
		Axis axis = GetRoadStopDir(ti->tile) == DIAGDIR_NE ? AXIS_X : AXIS_Y;
 
		DrawGroundSprite((HasBit(roadtypes, ROADTYPE_ROAD) ? SPR_TRAMWAY_OVERLAY : SPR_TRAMWAY_TRAM) + (axis ^ 1), PAL_NONE);
 
		DrawTramCatenary(ti, axis == AXIS_X ? ROAD_X : ROAD_Y);
 
	}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -856,13 +856,13 @@ static void DrawTile_TunnelBridge(TileIn
 
				DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][tunnelbridge_direction], PAL_NONE);
 

	
 
				catenary = true;
 
				StartSpriteCombine();
 
				AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
 
			}
 
		} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
 
		} else if (HasCatenary(GetRailType(ti->tile))) {
 
			DrawCatenary(ti);
 

	
 
			catenary = true;
 
			StartSpriteCombine();
 
			DrawCatenaryOnTunnel(ti);
 
		}
 
@@ -932,13 +932,13 @@ static void DrawTile_TunnelBridge(TileIn
 
					offset += 2;
 
				}
 
				/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
 
				DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD));
 
			}
 
			EndSpriteCombine();
 
		} else if (GetRailType(ti->tile) == RAILTYPE_ELECTRIC) {
 
		} else if (HasCatenary(GetRailType(ti->tile))) {
 
			DrawCatenary(ti);
 
		}
 

	
 
		DrawBridgeMiddle(ti);
 
	}
 
}
 
@@ -1058,13 +1058,13 @@ void DrawBridgeMiddle(const TileInfo* ti
 
			/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
 
			DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD));
 
		} else {
 
			EndSpriteCombine();
 
			StartSpriteCombine();
 
		}
 
	} else if (GetRailType(rampsouth) == RAILTYPE_ELECTRIC) {
 
	} else if (HasCatenary(GetRailType(rampsouth))) {
 
		DrawCatenary(ti);
 
	}
 

	
 
	/* draw roof, the component of the bridge which is logically between the vehicle and the camera */
 
	if (axis == AXIS_X) {
 
		y += 12;
0 comments (0 inline, 0 general)