File diff r10931:719d8f259204 → r10932:d500145bd277
src/elrail.cpp
Show inline comments
 
@@ -119,12 +119,28 @@ static TrackBits GetRailTrackBitsUnivers
 

	
 
		default:
 
			return TRACK_BIT_NONE;
 
	}
 
}
 

	
 
/**
 
 * Get the base wire sprite to use.
 
 */
 
static inline SpriteID GetWireBase(TileIndex tile)
 
{
 
	return SPR_WIRE_BASE;
 
}
 

	
 
/**
 
 * Get the base pylon sprite to use.
 
 */
 
static inline SpriteID GetPylonBase(TileIndex tile)
 
{
 
	return SPR_PYLON_BASE;
 
}
 

	
 
/** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile.
 
 * @param tile The tile to analyse
 
 * @param *tileh the tileh
 
 */
 
static void AdjustTileh(TileIndex tile, Slope *tileh)
 
{
 
@@ -182,16 +198,18 @@ void DrawCatenaryOnTunnel(const TileInfo
 
		{ 0, 1, 16, 15 }, // SW
 
		{ 1, 0, 15, 16 }, // NW
 
	};
 

	
 
	DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
 

	
 
	SpriteID wire_base = GetWireBase(ti->tile);
 

	
 
	const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
 
	const int *BB_data = _tunnel_wire_BB[dir];
 
	AddSortableSpriteToDraw(
 
		sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
		wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
		BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset + 1,
 
		GetTileZ(ti->tile) + sss->z_offset,
 
		IsTransparencySet(TO_CATENARY),
 
		BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset
 
	);
 
}
 
@@ -228,12 +246,14 @@ static void DrawCatenaryRailway(const Ti
 
	trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP);
 
	/* If a track bit is present that is not in the main direction, the track is level */
 
	isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0);
 

	
 
	AdjustTileh(ti->tile, &tileh[TS_HOME]);
 

	
 
	SpriteID pylon_base = GetPylonBase(ti->tile);
 

	
 
	for (DiagDirection i = DIAGDIR_NE; i < DIAGDIR_END; i++) {
 
		TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
 
		Foundation foundation = FOUNDATION_NONE;
 
		byte elevation = GetPCPElevation(ti->tile, i);
 

	
 
		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
 
@@ -334,13 +354,13 @@ static void DrawCatenaryRailway(const Ti
 
					if (!HasBit(OwnedPPPonPCP[i], temp)) {
 
						/* We have a neighour that will draw it, bail out */
 
						if (trackconfig[TS_NEIGHBOUR] != 0) break;
 
						continue; /* No neighbour, go looking for a better position */
 
					}
 

	
 
					AddSortableSpriteToDraw(pylon_sprites[temp], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE,
 
					AddSortableSpriteToDraw(pylon_base + pylon_sprites[temp], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE,
 
						elevation, IsTransparencySet(TO_CATENARY), -1, -1);
 

	
 
					break; /* We already have drawn a pylon, bail out */
 
				}
 
			}
 
		}
 
@@ -353,12 +373,14 @@ static void DrawCatenaryRailway(const Ti
 
	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !IsTransparencySet(TO_CATENARY)) {
 
		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
 

	
 
		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
 
	}
 

	
 
	SpriteID wire_base = GetWireBase(ti->tile);
 

	
 
	/* Drawing of pylons is finished, now draw the wires */
 
	for (Track t = TRACK_BEGIN; t < TRACK_END; t++) {
 
		if (HasBit(trackconfig[TS_HOME], t)) {
 
			byte PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) +
 
				(HasBit(PCPstatus, PCPpositions[t][1]) << 1);
 

	
 
@@ -371,13 +393,13 @@ static void DrawCatenaryRailway(const Ti
 

	
 
			/*
 
			 * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE.
 
			 * Therefore it is safe to use GetSlopeZ() for the elevation.
 
			 * Also note, that the result of GetSlopeZ() is very special for bridge-ramps.
 
			 */
 
			AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
			AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset,
 
				IsTransparencySet(TO_CATENARY));
 
		}
 
	}
 
}
 

	
 
@@ -404,49 +426,55 @@ void DrawCatenaryOnBridge(const TileInfo
 
		/* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */
 
		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
 
	}
 

	
 
	height = GetBridgeHeight(end);
 

	
 
	AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
	SpriteID wire_base = GetWireBase(start);
 

	
 
	AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
 
		IsTransparencySet(TO_CATENARY)
 
	);
 

	
 
	SpriteID pylon_base = GetPylonBase(start);
 

	
 
	/* Finished with wires, draw pylons */
 
	/* every other tile needs a pylon on the northern end */
 
	if (num % 2) {
 
		DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_NE : DIAGDIR_NW);
 
		Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
 
		if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
 
		uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
 
		uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
 
		AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1);
 
		AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1);
 
	}
 

	
 
	/* need a pylon on the southern end of the bridge */
 
	if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) {
 
		DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
 
		Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
 
		if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
 
		uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
 
		uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
 
		AddSortableSpriteToDraw(pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1);
 
		AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1);
 
	}
 
}
 

	
 
void DrawCatenary(const TileInfo *ti)
 
{
 
	switch (GetTileType(ti->tile)) {
 
		case MP_RAILWAY:
 
			if (IsRailDepot(ti->tile)) {
 
				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
 

	
 
				SpriteID wire_base = GetWireBase(ti->tile);
 

	
 
				/* This wire is not visible with the default depot sprites */
 
				AddSortableSpriteToDraw(
 
					sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
					wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
 
					sss->x_size, sss->y_size, sss->z_size,
 
					GetTileMaxZ(ti->tile) + sss->z_offset,
 
					IsTransparencySet(TO_CATENARY)
 
				);
 
				return;
 
			}