|     65 #include "train.h" |     65 #include "train.h" | 
|     66 #include "gui.h" |     66 #include "gui.h" | 
|     67  |     67  | 
|     68 static inline TLG GetTLG(TileIndex t) |     68 static inline TLG GetTLG(TileIndex t) | 
|     69 { |     69 { | 
|     70 	return (HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0); |     70 	return (TLG)((HASBIT(TileX(t), 0) << 1) + HASBIT(TileY(t), 0)); | 
|     71 } |     71 } | 
|     72  |     72  | 
|     73 /** Finds which Rail Bits are present on a given tile. For bridge tiles, |     73 /** Finds which Rail Bits are present on a given tile. For bridge tiles, | 
|     74  * returns track bits under the bridge |     74  * returns track bits under the bridge | 
|     75  */ |     75  */ | 
|     76 static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) |     76 static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) | 
|     77 { |     77 { | 
|     78 	switch (GetTileType(t)) { |     78 	switch (GetTileType(t)) { | 
|     79 		case MP_RAILWAY: |     79 		case MP_RAILWAY: | 
|     80 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0; |     80 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; | 
|     81 			switch (GetRailTileType(t)) { |     81 			switch (GetRailTileType(t)) { | 
|     82 				case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS: |     82 				case RAIL_TILE_NORMAL: case RAIL_TILE_SIGNALS: | 
|     83 					return GetTrackBits(t); |     83 					return GetTrackBits(t); | 
|     84 				case RAIL_TILE_DEPOT_WAYPOINT: |     84 				case RAIL_TILE_DEPOT_WAYPOINT: | 
|     85 					if (GetRailTileSubtype(t) == RAIL_SUBTYPE_WAYPOINT) return GetRailWaypointBits(t); |     85 					if (GetRailTileSubtype(t) == RAIL_SUBTYPE_WAYPOINT) return GetRailWaypointBits(t); | 
|     86 				default: |     86 				default: | 
|     87 					return 0; |     87 					return TRACK_BIT_NONE; | 
|     88 			} |     88 			} | 
|     89 			break; |     89 			break; | 
|     90  |     90  | 
|     91 		case MP_TUNNEL: |     91 		case MP_TUNNEL: | 
|     92 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0; |     92 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; | 
|     93 			if (override != NULL) *override = 1 << GetTunnelDirection(t); |     93 			if (override != NULL) *override = 1 << GetTunnelDirection(t); | 
|     94 			return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t))); |     94 			return AxisToTrackBits(DiagDirToAxis(GetTunnelDirection(t))); | 
|     95  |     95  | 
|     96 		case MP_RAILWAY_BRIDGE: |     96 		case MP_RAILWAY_BRIDGE: | 
|     97 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0; |     97 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; | 
|     98 			if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) { |     98 			if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) { | 
|     99 				*override = 1 << GetBridgeRampDirection(t); |     99 				*override = 1 << GetBridgeRampDirection(t); | 
|    100 			} |    100 			} | 
|    101 			return GetTrackBits(t); |    101 			return GetTrackBits(t); | 
|    102  |    102  | 
|    103 		case MP_STREET: |    103 		case MP_STREET: | 
|    104 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0; |    104 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE; | 
|    105 			if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return 0; |    105 			if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; | 
|    106 			return GetCrossingRailBits(t); |    106 			return GetCrossingRailBits(t); | 
|    107  |    107  | 
|    108 		case MP_STATION: |    108 		case MP_STATION: | 
|    109 			if (!IsRailwayStation(t)) return 0; |    109 			if (!IsRailwayStation(t)) return TRACK_BIT_NONE; | 
|    110 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0; |    110 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE; | 
|    111 			if (!IsStationTileElectrifiable(t)) return 0; |    111 			if (!IsStationTileElectrifiable(t)) return TRACK_BIT_NONE; | 
|    112 			return TrackToTrackBits(GetRailStationTrack(t)); |    112 			return TrackToTrackBits(GetRailStationTrack(t)); | 
|    113  |    113  | 
|    114 		default: |    114 		default: | 
|    115 			return 0; |    115 			return TRACK_BIT_NONE; | 
|    116 	} |    116 	} | 
|    117 } |    117 } | 
|    118  |    118  | 
|    119 /** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile. |    119 /** Corrects the tileh for certain tile types. Returns an effective tileh for the track on the tile. | 
|    120  * @param tile The tile to analyse |    120  * @param tile The tile to analyse | 
|    170 	 * 2) on the "far" end of a bridge head (the one that connects to bridge middle), |    170 	 * 2) on the "far" end of a bridge head (the one that connects to bridge middle), | 
|    171 	 *    because that one is drawn on the bridge. Exception is for length 0 bridges |    171 	 *    because that one is drawn on the bridge. Exception is for length 0 bridges | 
|    172 	 *    which have no middle tiles */ |    172 	 *    which have no middle tiles */ | 
|    173 	trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP); |    173 	trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP); | 
|    174 	/* If a track bit is present that is not in the main direction, the track is level */ |    174 	/* If a track bit is present that is not in the main direction, the track is level */ | 
|    175 	isflat[TS_HOME] = trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT); |    175 	isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0); | 
|    176  |    176  | 
|    177 	AdjustTileh(ti->tile, &tileh[TS_HOME]); |    177 	AdjustTileh(ti->tile, &tileh[TS_HOME]); | 
|    178  |    178  | 
|    179 	for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) { |    179 	for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) { | 
|    180 		TileIndex neighbour = ti->tile + TileOffsByDiagDir(i); |    180 		TileIndex neighbour = ti->tile + TileOffsByDiagDir(i); | 
|    183  |    183  | 
|    184 		/* Here's one of the main headaches. GetTileSlope does not correct for possibly |    184 		/* Here's one of the main headaches. GetTileSlope does not correct for possibly | 
|    185 		 * existing foundataions, so we do have to do that manually later on.*/ |    185 		 * existing foundataions, so we do have to do that manually later on.*/ | 
|    186 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL); |    186 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL); | 
|    187 		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL); |    187 		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL); | 
|    188 		if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = 0; |    188 		if (IsTunnelTile(neighbour) && i != GetTunnelDirection(neighbour)) trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE; | 
|    189 		isflat[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT); |    189 		isflat[TS_NEIGHBOUR] = ((trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0); | 
|    190  |    190  | 
|    191 		PPPpreferred[i] = 0xFF; /* We start with preferring everything (end-of-line in any direction) */ |    191 		PPPpreferred[i] = 0xFF; /* We start with preferring everything (end-of-line in any direction) */ | 
|    192 		PPPallowed[i] = AllowedPPPonPCP[i]; |    192 		PPPallowed[i] = AllowedPPPonPCP[i]; | 
|    193  |    193  | 
|    194 		/* We cycle through all the existing tracks at a PCP and see what |    194 		/* We cycle through all the existing tracks at a PCP and see what | 
|    288  |    288  | 
|    289 		if (height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) return; |    289 		if (height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) return; | 
|    290 	} |    290 	} | 
|    291  |    291  | 
|    292 	/* Drawing of pylons is finished, now draw the wires */ |    292 	/* Drawing of pylons is finished, now draw the wires */ | 
|    293 	for (t = 0; t < TRACK_END; t++) { |    293 	for (t = TRACK_BEGIN; t < TRACK_END; t++) { | 
|    294 		if (HASBIT(trackconfig[TS_HOME], t)) { |    294 		if (HASBIT(trackconfig[TS_HOME], t)) { | 
|    295  |    295  | 
|    296 			byte PCPconfig = HASBIT(PCPstatus, PCPpositions[t][0]) + |    296 			byte PCPconfig = HASBIT(PCPstatus, PCPpositions[t][0]) + | 
|    297 				(HASBIT(PCPstatus, PCPpositions[t][1]) << 1); |    297 				(HASBIT(PCPstatus, PCPpositions[t][1]) << 1); | 
|    298  |    298  | 
|    320  |    320  | 
|    321 	const SortableSpriteStruct *sss; |    321 	const SortableSpriteStruct *sss; | 
|    322 	Axis axis = GetBridgeAxis(ti->tile); |    322 	Axis axis = GetBridgeAxis(ti->tile); | 
|    323 	TLG tlg = GetTLG(ti->tile); |    323 	TLG tlg = GetTLG(ti->tile); | 
|    324  |    324  | 
|    325 	CatenarySprite offset = axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH; |    325 	CatenarySprite offset = (CatenarySprite)(axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH); | 
|    326  |    326  | 
|    327 	if ((length % 2) && num == length) { |    327 	if ((length % 2) && num == length) { | 
|    328 		/* Draw the "short" wire on the southern end of the bridge |    328 		/* Draw the "short" wire on the southern end of the bridge | 
|    329 		 * only needed if the length of the bridge is odd */ |    329 		 * only needed if the length of the bridge is odd */ | 
|    330 		sss = &CatenarySpriteData[WIRE_X_FLAT_BOTH + offset]; |    330 		sss = &CatenarySpriteData[WIRE_X_FLAT_BOTH + offset]; |