src/elrail.cpp
changeset 8083 ad22eade501f
parent 7931 b0a46cd92225
child 8088 92fca5b09665
equal deleted inserted replaced
8082:63240e1bd6cc 8083:ad22eade501f
    64 #include "table/elrail_data.h"
    64 #include "table/elrail_data.h"
    65 #include "vehicle.h"
    65 #include "vehicle.h"
    66 #include "train.h"
    66 #include "train.h"
    67 #include "gui.h"
    67 #include "gui.h"
    68 #include "transparency.h"
    68 #include "transparency.h"
       
    69 #include "tunnelbridge_map.h"
       
    70 
    69 
    71 
    70 static inline TLG GetTLG(TileIndex t)
    72 static inline TLG GetTLG(TileIndex t)
    71 {
    73 {
    72 	return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0));
    74 	return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0));
    73 }
    75 }
    91 			break;
    93 			break;
    92 
    94 
    93 		case MP_TUNNELBRIDGE:
    95 		case MP_TUNNELBRIDGE:
    94 			if (IsTunnel(t)) {
    96 			if (IsTunnel(t)) {
    95 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
    97 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
    96 				if (override != NULL) *override = 1 << GetTunnelDirection(t);
    98 				if (override != NULL) *override = 1 << GetTunnelBridgeDirection(t);
    97 				return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t)));
    99 				return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
    98 			} else {
   100 			} else {
    99 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
   101 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
   100 				if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
   102 				if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
   101 					*override = 1 << GetBridgeRampDirection(t);
   103 					*override = 1 << GetTunnelBridgeDirection(t);
   102 				}
   104 				}
   103 				return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t)));
   105 				return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(t)));
   104 			}
   106 			}
   105 
   107 
   106 		case MP_ROAD:
   108 		case MP_ROAD:
   107 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
   109 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
   108 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
   110 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
   129 		if (IsTunnel(tile)) {
   131 		if (IsTunnel(tile)) {
   130 			*tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon
   132 			*tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon
   131 		} else if (*tileh != SLOPE_FLAT) {
   133 		} else if (*tileh != SLOPE_FLAT) {
   132 			*tileh = SLOPE_FLAT;
   134 			*tileh = SLOPE_FLAT;
   133 		} else {
   135 		} else {
   134 			switch (GetBridgeRampDirection(tile)) {
   136 			switch (GetTunnelBridgeDirection(tile)) {
   135 				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
   137 				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
   136 				case DIAGDIR_SE: *tileh = SLOPE_SE; break;
   138 				case DIAGDIR_SE: *tileh = SLOPE_SE; break;
   137 				case DIAGDIR_SW: *tileh = SLOPE_SW; break;
   139 				case DIAGDIR_SW: *tileh = SLOPE_SW; break;
   138 				case DIAGDIR_NW: *tileh = SLOPE_NW; break;
   140 				case DIAGDIR_NW: *tileh = SLOPE_NW; break;
   139 				default: NOT_REACHED();
   141 				default: NOT_REACHED();
   186 		{ 1, 0, 15, 16 }, // NW
   188 		{ 1, 0, 15, 16 }, // NW
   187 	};
   189 	};
   188 
   190 
   189 	if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
   191 	if ((GetRailType(ti->tile) != RAILTYPE_ELECTRIC) || _patches.disable_elrails) return;
   190 
   192 
   191 	DiagDirection dir = GetTunnelDirection(ti->tile);
   193 	DiagDirection dir = GetTunnelBridgeDirection(ti->tile);
   192 
   194 
   193 	const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
   195 	const SortableSpriteStruct *sss = &CatenarySpriteData_Tunnel[dir];
   194 	const int *BB_data = _tunnel_wire_BB[dir];
   196 	const int *BB_data = _tunnel_wire_BB[dir];
   195 	AddSortableSpriteToDraw(
   197 	AddSortableSpriteToDraw(
   196 		sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   198 		sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   245 
   247 
   246 		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
   248 		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
   247 		 * existing foundataions, so we do have to do that manually later on.*/
   249 		 * existing foundataions, so we do have to do that manually later on.*/
   248 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
   250 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
   249 		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
   251 		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
   250 		if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
   252 		if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
   251 
   253 
   252 		/* If the neighboured tile does not smoothly connect to the current tile (because of a foundation),
   254 		/* If the neighboured tile does not smoothly connect to the current tile (because of a foundation),
   253 		 * we have to draw all pillars on the current tile. */
   255 		 * we have to draw all pillars on the current tile. */
   254 		if (GetPCPElevation(ti->tile, i) != GetPCPElevation(neighbour, ReverseDiagDir(i))) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
   256 		if (GetPCPElevation(ti->tile, i) != GetPCPElevation(neighbour, ReverseDiagDir(i))) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
   255 
   257 
   262 		 * PPPs we want to have, or may not have at all */
   264 		 * PPPs we want to have, or may not have at all */
   263 		for (k = 0; k < NUM_TRACKS_AT_PCP; k++) {
   265 		for (k = 0; k < NUM_TRACKS_AT_PCP; k++) {
   264 			/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
   266 			/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
   265 			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
   267 			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
   266 			    IsBridgeTile(neighbour) &&
   268 			    IsBridgeTile(neighbour) &&
   267 			    GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) {
   269 			    GetTunnelBridgeDirection(neighbour) == ReverseDiagDir(i)) {
   268 				continue;
   270 				continue;
   269 			}
   271 			}
   270 
   272 
   271 			/* We check whether the track in question (k) is present in the tile
   273 			/* We check whether the track in question (k) is present in the tile
   272 			 * (TrackSourceTile) */
   274 			 * (TrackSourceTile) */
   289 		if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
   291 		if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
   290 
   292 
   291 		/* Read the foundataions if they are present, and adjust the tileh */
   293 		/* Read the foundataions if they are present, and adjust the tileh */
   292 		if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
   294 		if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
   293 		if (IsBridgeTile(neighbour)) {
   295 		if (IsBridgeTile(neighbour)) {
   294 			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
   296 			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
   295 		}
   297 		}
   296 
   298 
   297 		ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]);
   299 		ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]);
   298 
   300 
   299 	/* Half tile slopes coincide only with horizontal/vertical track.
   301 	/* Half tile slopes coincide only with horizontal/vertical track.
   441 	if (_patches.disable_elrails) return;
   443 	if (_patches.disable_elrails) return;
   442 
   444 
   443 	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
   445 	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
   444 		TileIndex head = GetNorthernBridgeEnd(ti->tile);
   446 		TileIndex head = GetNorthernBridgeEnd(ti->tile);
   445 
   447 
   446 		if (GetBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
   448 		if (GetTunnelBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
   447 			DrawCatenaryOnBridge(ti);
   449 			DrawCatenaryOnBridge(ti);
   448 		}
   450 		}
   449 	}
   451 	}
   450 
   452 
   451 	switch (GetTileType(ti->tile)) {
   453 	switch (GetTileType(ti->tile)) {