src/elrail.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6595 6732a818a599
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
    50 #include "station_map.h"
    50 #include "station_map.h"
    51 #include "tile.h"
    51 #include "tile.h"
    52 #include "viewport.h"
    52 #include "viewport.h"
    53 #include "functions.h" /* We should REALLY get rid of this goddamn file, as it is butt-ugly */
    53 #include "functions.h" /* We should REALLY get rid of this goddamn file, as it is butt-ugly */
    54 #include "variables.h" /* ... same here */
    54 #include "variables.h" /* ... same here */
       
    55 #include "landscape.h"
    55 #include "rail.h"
    56 #include "rail.h"
    56 #include "debug.h"
    57 #include "debug.h"
    57 #include "tunnel_map.h"
    58 #include "tunnel_map.h"
    58 #include "road_map.h"
    59 #include "road_map.h"
    59 #include "bridge_map.h"
    60 #include "bridge_map.h"
   246 
   247 
   247 		if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
   248 		if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile)) {
   248 			Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
   249 			Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
   249 			uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
   250 			uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
   250 
   251 
   251 			if ((height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) &&
   252 			if ((height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) &&
   252 					(i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) {
   253 					(i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) {
   253 				SETBIT(OverridePCP, i);
   254 				SETBIT(OverridePCP, i);
   254 			}
   255 			}
   255 		}
   256 		}
   256 
   257 
   267 						/* We have a neighour that will draw it, bail out */
   268 						/* We have a neighour that will draw it, bail out */
   268 						if (trackconfig[TS_NEIGHBOUR] != 0) break;
   269 						if (trackconfig[TS_NEIGHBOUR] != 0) break;
   269 						continue; /* No neighbour, go looking for a better position */
   270 						continue; /* No neighbour, go looking for a better position */
   270 					}
   271 					}
   271 
   272 
   272 					AddSortableSpriteToDraw(pylons_normal[temp], PAL_NONE, x, y, 1, 1, 10,
   273 					SpriteID img = pylons_normal[temp];
       
   274 					SpriteID pal = PAL_NONE;
       
   275 					if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
       
   276 						SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   277 						pal = PALETTE_TO_TRANSPARENT;
       
   278 					}
       
   279 
       
   280 					AddSortableSpriteToDraw(img, pal, x, y, 1, 1, 10,
   273 							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]));
   281 							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]));
   274 					break; /* We already have drawn a pylon, bail out */
   282 					break; /* We already have drawn a pylon, bail out */
   275 				}
   283 				}
   276 			}
   284 			}
   277 		}
   285 		}
   278 	}
   286 	}
   279 
   287 
   280 	/* Don't draw a wire under a low bridge */
   288 	/* Don't draw a wire under a low bridge */
   281 	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !(_display_opt & DO_TRANS_BUILDINGS)) {
   289 	if (MayHaveBridgeAbove(ti->tile) && IsBridgeAbove(ti->tile) && !HASBIT(_transparent_opt, TO_BUILDINGS)) {
   282 		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
   290 		uint height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
   283 
   291 
   284 		if (height <= TilePixelHeight(ti->tile) + TILE_HEIGHT) return;
   292 		if (height <= GetTileMaxZ(ti->tile) + TILE_HEIGHT) return;
   285 	}
   293 	}
   286 
   294 
   287 	/* Drawing of pylons is finished, now draw the wires */
   295 	/* Drawing of pylons is finished, now draw the wires */
   288 	for (t = TRACK_BEGIN; t < TRACK_END; t++) {
   296 	for (t = TRACK_BEGIN; t < TRACK_END; t++) {
   289 		if (HASBIT(trackconfig[TS_HOME], t)) {
   297 		if (HASBIT(trackconfig[TS_HOME], t)) {
   305 
   313 
   306 			assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
   314 			assert(PCPconfig != 0); /* We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that) */
   307 			assert(!IsSteepSlope(tileh[TS_HOME]));
   315 			assert(!IsSteepSlope(tileh[TS_HOME]));
   308 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
   316 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
   309 
   317 
   310 			AddSortableSpriteToDraw( sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   318 			SpriteID img = sss->image;
       
   319 			SpriteID pal = PAL_NONE;
       
   320 			if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
       
   321 				SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   322 				pal = PALETTE_TO_TRANSPARENT;
       
   323 			}
       
   324 
       
   325 			AddSortableSpriteToDraw(img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
   311 				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, TILE_SIZE - 1), ti->y + min(sss->y_offset, TILE_SIZE - 1)) + sss->z_offset);
   326 				sss->x_size, sss->y_size, sss->z_size, GetSlopeZ(ti->x + min(sss->x_offset, TILE_SIZE - 1), ti->y + min(sss->y_offset, TILE_SIZE - 1)) + sss->z_offset);
   312 		}
   327 		}
   313 	}
   328 	}
   314 }
   329 }
   315 
   330 
   337 		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
   352 		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
   338 	}
   353 	}
   339 
   354 
   340 	height = GetBridgeHeight(end);
   355 	height = GetBridgeHeight(end);
   341 
   356 
   342 	AddSortableSpriteToDraw( sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   357 	SpriteID img = sss->image;
       
   358 	SpriteID pal = PAL_NONE;
       
   359 	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
       
   360 		SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   361 		pal = PALETTE_TO_TRANSPARENT;
       
   362 	}
       
   363 
       
   364 	AddSortableSpriteToDraw(img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
   343 		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset
   365 		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset
   344 	);
   366 	);
   345 
   367 
   346 	/* Finished with wires, draw pylons */
   368 	/* Finished with wires, draw pylons */
   347 	/* every other tile needs a pylon on the northern end */
   369 	/* every other tile needs a pylon on the northern end */
   348 	if (num % 2) {
   370 	if (num % 2) {
   349 		if (axis == AXIS_X) {
   371 		if (axis == AXIS_X) {
   350 			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], PAL_NONE, ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
   372 			img = pylons_bridge[0 + HASBIT(tlg, 0)];
       
   373 			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   374 			AddSortableSpriteToDraw(img, pal, ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
   351 		} else {
   375 		} else {
   352 			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], PAL_NONE, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height);
   376 			img = pylons_bridge[2 + HASBIT(tlg, 1)];
       
   377 			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   378 			AddSortableSpriteToDraw(img, pal, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height);
   353 		}
   379 		}
   354 	}
   380 	}
   355 
   381 
   356 	/* need a pylon on the southern end of the bridge */
   382 	/* need a pylon on the southern end of the bridge */
   357 	if (DistanceMax(ti->tile, start) == length) {
   383 	if (DistanceMax(ti->tile, start) == length) {
   358 		if (axis == AXIS_X) {
   384 		if (axis == AXIS_X) {
   359 			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], PAL_NONE, ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
   385 			img = pylons_bridge[0 + HASBIT(tlg, 0)];
       
   386 			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   387 			AddSortableSpriteToDraw(img, pal, ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height);
   360 		} else {
   388 		} else {
   361 			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], PAL_NONE, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height);
   389 			img = pylons_bridge[2 + HASBIT(tlg, 1)];
       
   390 			if (HASBIT(_transparent_opt, TO_BUILDINGS)) SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   391 			AddSortableSpriteToDraw(img, pal, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height);
   362 		}
   392 		}
   363 	}
   393 	}
   364 }
   394 }
   365 
   395 
   366 void DrawCatenary(const TileInfo *ti)
   396 void DrawCatenary(const TileInfo *ti)
   377 	switch (GetTileType(ti->tile)) {
   407 	switch (GetTileType(ti->tile)) {
   378 		case MP_RAILWAY:
   408 		case MP_RAILWAY:
   379 			if (IsRailDepot(ti->tile)) {
   409 			if (IsRailDepot(ti->tile)) {
   380 				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
   410 				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
   381 
   411 
       
   412 				SpriteID img = sss->image;
       
   413 				SpriteID pal = PAL_NONE;
       
   414 				if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
       
   415 					SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   416 					pal = PALETTE_TO_TRANSPARENT;
       
   417 				}
       
   418 
   382 				AddSortableSpriteToDraw(
   419 				AddSortableSpriteToDraw(
   383 					sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   420 					img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
   384 					sss->x_size, sss->y_size, sss->z_size,
   421 					sss->x_size, sss->y_size, sss->z_size,
   385 					GetTileMaxZ(ti->tile) + sss->z_offset
   422 					GetTileMaxZ(ti->tile) + sss->z_offset
   386 				);
   423 				);
   387 				return;
   424 				return;
   388 			}
   425 			}