elrail.c
changeset 3933 231ae3c419f4
parent 3880 b493c5318c9b
child 3971 77061ae9b534
equal deleted inserted replaced
3932:dfe10fa5ce4f 3933:231ae3c419f4
    89 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
    89 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
    90 				if (override != NULL) *override = 1 << GetTunnelDirection(t);
    90 				if (override != NULL) *override = 1 << GetTunnelDirection(t);
    91 				return DiagDirToAxis(GetTunnelDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
    91 				return DiagDirToAxis(GetTunnelDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
    92 			} else {
    92 			} else {
    93 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
    93 				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
    94 				if (IsBridgeMiddle(t)) {
    94 				if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) {
    95 					if (IsTransportUnderBridge(t) &&
    95 					*override = 1 << GetBridgeRampDirection(t);
    96 						GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL) {
       
    97 						return GetRailBitsUnderBridge(t);
       
    98 					} else {
       
    99 						return 0;
       
   100 					}
       
   101 				} else {
       
   102 					if (override != NULL && DistanceMax(t, GetOtherBridgeEnd(t)) > 1) *override = 1 << GetBridgeRampDirection(t);
       
   103 
       
   104 					return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
       
   105 				}
    96 				}
       
    97 				return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
   106 			}
    98 			}
   107 		case MP_STREET:
    99 		case MP_STREET:
   108 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0;
   100 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0;
   109 			if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return 0;
   101 			if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return 0;
   110 			return GetCrossingRailBits(t);
   102 			return GetCrossingRailBits(t);
   123   * @param *tileh the tileh
   115   * @param *tileh the tileh
   124   */
   116   */
   125 static void AdjustTileh(TileIndex tile, Slope* tileh)
   117 static void AdjustTileh(TileIndex tile, Slope* tileh)
   126 {
   118 {
   127 	if (IsTunnelTile(tile)) *tileh = SLOPE_FLAT;
   119 	if (IsTunnelTile(tile)) *tileh = SLOPE_FLAT;
   128 	if (IsBridgeTile(tile) && IsBridgeRamp(tile)) {
   120 	if (IsBridgeTile(tile)) {
   129 		if (*tileh != SLOPE_FLAT) {
   121 		if (*tileh != SLOPE_FLAT) {
   130 			*tileh = SLOPE_FLAT;
   122 			*tileh = SLOPE_FLAT;
   131 		} else {
   123 		} else {
   132 			switch (GetBridgeRampDirection(tile)) {
   124 			switch (GetBridgeRampDirection(tile)) {
   133 				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
   125 				case DIAGDIR_NE: *tileh = SLOPE_NE; break;
   191 		/* We cycle through all the existing tracks at a PCP and see what
   183 		/* We cycle through all the existing tracks at a PCP and see what
   192 		   PPPs we want to have, or may not have at all */
   184 		   PPPs we want to have, or may not have at all */
   193 		for (k = 0; k < NUM_TRACKS_AT_PCP; k++) {
   185 		for (k = 0; k < NUM_TRACKS_AT_PCP; k++) {
   194 			/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
   186 			/* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
   195 			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
   187 			if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
   196 			    IsBridgeTile(neighbour) && IsBridgeRamp(neighbour) &&
   188 			    IsBridgeTile(neighbour) &&
   197 			    GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)
   189 			    GetBridgeRampDirection(neighbour) == ReverseDiagDir(i)) {
   198 			   ) continue;
   190 				continue;
       
   191 			}
   199 
   192 
   200 			/* We check whether the track in question (k) is present in the tile
   193 			/* We check whether the track in question (k) is present in the tile
   201 			   (TrackSourceTile) */
   194 			   (TrackSourceTile) */
   202 			if (HASBIT(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
   195 			if (HASBIT(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
   203 				/* track found, if track is in the neighbour tile, adjust the number
   196 				/* track found, if track is in the neighbour tile, adjust the number
   217 		/* A station is always "flat", so adjust the tileh accordingly */
   210 		/* A station is always "flat", so adjust the tileh accordingly */
   218 		if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
   211 		if (IsTileType(neighbour, MP_STATION)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
   219 
   212 
   220 		/* Read the foundataions if they are present, and adjust the tileh */
   213 		/* Read the foundataions if they are present, and adjust the tileh */
   221 		if (IsTileType(neighbour, MP_RAILWAY)) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
   214 		if (IsTileType(neighbour, MP_RAILWAY)) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
   222 		if (IsBridgeTile(neighbour) && IsBridgeRamp(neighbour)) {
   215 		if (IsBridgeTile(neighbour)) {
   223 			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
   216 			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
   224 		}
   217 		}
   225 
   218 
   226 		if (foundation != 0) {
   219 		if (foundation != 0) {
   227 			if (foundation < 15) {
   220 			if (foundation < 15) {
   245 		   In that case, we try the any of the allowed ones. if they don't exist either, don't draw
   238 		   In that case, we try the any of the allowed ones. if they don't exist either, don't draw
   246 		   anything. Note that the preferred PPPs still contain the end-of-line markers.
   239 		   anything. Note that the preferred PPPs still contain the end-of-line markers.
   247 		   Remove those (simply by ANDing with allowed, since these markers are never allowed) */
   240 		   Remove those (simply by ANDing with allowed, since these markers are never allowed) */
   248 		if ( (PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
   241 		if ( (PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
   249 
   242 
       
   243 		if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
       
   244 			Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
       
   245 			uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile), GetBridgeAxis(ti->tile));
       
   246 
       
   247 			if ((height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) &&
       
   248 			(i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) SETBIT(OverridePCP, i);
       
   249 		}
       
   250 
   250 		if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
   251 		if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
   251 			for (k = 0; k < DIR_END; k++) {
   252 			for (k = 0; k < DIR_END; k++) {
   252 				byte temp = PPPorder[i][GetTLG(ti->tile)][k];
   253 				byte temp = PPPorder[i][GetTLG(ti->tile)][k];
   253 				if (HASBIT(PPPallowed[i], temp)) {
   254 				if (HASBIT(PPPallowed[i], temp)) {
   254 					uint x  = ti->x + x_pcp_offsets[i] + x_ppp_offsets[temp];
   255 					uint x  = ti->x + x_pcp_offsets[i] + x_ppp_offsets[temp];
   277 				(HASBIT(PCPstatus, PCPpositions[t][1]) << 1);
   278 				(HASBIT(PCPstatus, PCPpositions[t][1]) << 1);
   278 
   279 
   279 			const SortableSpriteStruct *sss;
   280 			const SortableSpriteStruct *sss;
   280 			int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; /* tileh for the slopes, 0 otherwise */
   281 			int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; /* tileh for the slopes, 0 otherwise */
   281 
   282 
   282 			if ( /* We are not drawing a wire under a low bridge */
   283 			if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !(_display_opt & DO_TRANS_BUILDINGS)) {
   283 					IsBridgeTile(ti->tile) &&
   284 				uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile), GetBridgeAxis(ti->tile));
   284 					IsBridgeMiddle(ti->tile) &&
   285 
   285 					!(_display_opt & DO_TRANS_BUILDINGS) &&
   286 				if (height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) return;
   286 					GetBridgeHeight(ti->tile) <= TilePixelHeight(ti->tile)
   287 			}
   287 			   ) return;
       
   288 
   288 
   289 			assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
   289 			assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
   290 			assert(!IsSteepSlope(tileh[TS_HOME]));
   290 			assert(!IsSteepSlope(tileh[TS_HOME]));
   291 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
   291 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
   292 
   292 
   318 		/* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */
   318 		/* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */
   319 		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
   319 		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
   320 	}
   320 	}
   321 
   321 
   322 	AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
   322 	AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
   323 			sss->x_size, sss->y_size, sss->z_size, GetBridgeHeight(ti->tile) + sss->z_offset + 8);
   323 			sss->x_size, sss->y_size, sss->z_size, GetBridgeHeight(end, axis) + sss->z_offset);
   324 
   324 
   325 	/* Finished with wires, draw pylons */
   325 	/* Finished with wires, draw pylons */
   326 	/* every other tile needs a pylon on the northern end */
   326 	/* every other tile needs a pylon on the northern end */
   327 	if (num % 2) {
   327 	if (num % 2) {
   328 		if (axis == AXIS_X) {
   328 		if (axis == AXIS_X) {
   329 			AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
   329 			AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(end, axis));
   330 		} else {
   330 		} else {
   331 			AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
   331 			AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, GetBridgeHeight(end, axis));
   332 		}
   332 		}
   333 	}
   333 	}
   334 
   334 
   335 	/* need a pylon on the southern end of the bridge */
   335 	/* need a pylon on the southern end of the bridge */
   336 	if (DistanceMax(ti->tile, start) == length) {
   336 	if (DistanceMax(ti->tile, start) == length) {
   337 		if (axis == AXIS_X) {
   337 		if (axis == AXIS_X) {
   338 			AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
   338 			AddSortableSpriteToDraw( pylons_bridge[0 + HASBIT(tlg, 0)], ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, GetBridgeHeight(end, axis));
   339 		} else {
   339 		} else {
   340 			AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, GetBridgeHeight(ti->tile) + TILE_HEIGHT);
   340 			AddSortableSpriteToDraw( pylons_bridge[2 + HASBIT(tlg, 1)], ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, GetBridgeHeight(end, axis));
   341 		}
   341 		}
   342 	}
   342 	}
   343 }
   343 }
   344 
   344 
   345 void DrawCatenary(const TileInfo *ti)
   345 void DrawCatenary(const TileInfo *ti)
   346 {
   346 {
       
   347 	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
       
   348 		TileIndex head = GetNorthernBridgeEnd(ti->tile);
       
   349 
       
   350 		if (GetBridgeTransportType(head) == TRANSPORT_RAIL && GetRailType(head) == RAILTYPE_ELECTRIC) {
       
   351 			DrawCatenaryOnBridge(ti);
       
   352 		}
       
   353 	}
   347 	switch (GetTileType(ti->tile)) {
   354 	switch (GetTileType(ti->tile)) {
   348 		case MP_RAILWAY:
   355 		case MP_RAILWAY:
   349 			if (GetRailTileType(ti->tile) == RAIL_TILE_DEPOT_WAYPOINT && GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT) {
   356 			if (GetRailTileType(ti->tile) == RAIL_TILE_DEPOT_WAYPOINT && GetRailTileSubtype(ti->tile) == RAIL_SUBTYPE_DEPOT) {
   350 				const SortableSpriteStruct *sss = &CatenarySpriteData[WIRE_DEPOT_SW + ReverseDiagDir(GetRailDepotDirection(ti->tile))];
   357 				const SortableSpriteStruct *sss = &CatenarySpriteData[WIRE_DEPOT_SW + ReverseDiagDir(GetRailDepotDirection(ti->tile))];
   351 				AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
   358 				AddSortableSpriteToDraw( sss->image, ti->x + sss->x_offset, ti->y + sss->y_offset,
   352 					sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x, ti->y) + sss->z_offset);
   359 					sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x, ti->y) + sss->z_offset);
   353 				return;
   360 				return;
   354 			}
   361 			}
   355 			/* Fall through */
   362 			/* Fall through */
   356 		case MP_TUNNELBRIDGE:
   363 		case MP_TUNNELBRIDGE:
   357 			if (IsBridgeTile(ti->tile) && IsBridgeMiddle(ti->tile) && GetRailTypeOnBridge(ti->tile) == RAILTYPE_ELECTRIC) DrawCatenaryOnBridge(ti);
   364 		case MP_STREET:
   358 			/* Fall further */
   365 		case MP_STATION:
   359 		case MP_STREET: case MP_STATION:
       
   360 			DrawCatenaryRailway(ti);
   366 			DrawCatenaryRailway(ti);
   361 			break;
   367 			break;
   362 		default:
   368 		default:
   363 			break;
   369 			break;
   364 	}
   370 	}