src/elrail.cpp
branchnoai
changeset 9694 e72987579514
parent 9629 66dde6412125
child 9701 d1ac22c62f64
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
   100 					*override = 1 << GetBridgeRampDirection(t);
   100 					*override = 1 << GetBridgeRampDirection(t);
   101 				}
   101 				}
   102 				return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t)));
   102 				return AxisToTrackBits(DiagDirToAxis(GetBridgeRampDirection(t)));
   103 			}
   103 			}
   104 
   104 
   105 		case MP_STREET:
   105 		case MP_ROAD:
   106 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
   106 			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return TRACK_BIT_NONE;
   107 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
   107 			if (GetRailType(t) != RAILTYPE_ELECTRIC) return TRACK_BIT_NONE;
   108 			return GetCrossingRailBits(t);
   108 			return GetCrossingRailBits(t);
   109 
   109 
   110 		case MP_STATION:
   110 		case MP_STATION:
   174 
   174 
   175 	AdjustTileh(ti->tile, &tileh[TS_HOME]);
   175 	AdjustTileh(ti->tile, &tileh[TS_HOME]);
   176 
   176 
   177 	for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) {
   177 	for (i = DIAGDIR_NE; i < DIAGDIR_END; i++) {
   178 		TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
   178 		TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
   179 		uint foundation = 0;
   179 		Foundation foundation = FOUNDATION_NONE;
   180 		int k;
   180 		int k;
   181 
   181 
   182 		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
   182 		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
   183 		 * existing foundataions, so we do have to do that manually later on.*/
   183 		 * existing foundataions, so we do have to do that manually later on.*/
   184 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
   184 		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour, NULL);
   223 		if (IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
   223 		if (IsTileType(neighbour, MP_RAILWAY) && GetRailType(neighbour) == RAILTYPE_ELECTRIC) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
   224 		if (IsBridgeTile(neighbour)) {
   224 		if (IsBridgeTile(neighbour)) {
   225 			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
   225 			foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetBridgeRampDirection(neighbour)));
   226 		}
   226 		}
   227 
   227 
   228 		if (foundation != 0) {
   228 		ApplyFoundationToSlope(foundation, &tileh[TS_NEIGHBOUR]);
   229 			tileh[TS_NEIGHBOUR] = foundation < 15 ? SLOPE_FLAT : _inclined_tileh[foundation - 15];
       
   230 		}
       
   231 
   229 
   232 		AdjustTileh(neighbour, &tileh[TS_NEIGHBOUR]);
   230 		AdjustTileh(neighbour, &tileh[TS_NEIGHBOUR]);
   233 
   231 
   234 		/* If we have a straight (and level) track, we want a pylon only every 2 tiles
   232 		/* If we have a straight (and level) track, we want a pylon only every 2 tiles
   235 		 * Delete the PCP if this is the case. */
   233 		 * Delete the PCP if this is the case. */
   268 						/* We have a neighour that will draw it, bail out */
   266 						/* We have a neighour that will draw it, bail out */
   269 						if (trackconfig[TS_NEIGHBOUR] != 0) break;
   267 						if (trackconfig[TS_NEIGHBOUR] != 0) break;
   270 						continue; /* No neighbour, go looking for a better position */
   268 						continue; /* No neighbour, go looking for a better position */
   271 					}
   269 					}
   272 
   270 
   273 					SpriteID img = pylons_normal[temp];
   271 					AddSortableSpriteToDraw(pylons_normal[temp], PAL_NONE, x, y, 1, 1, 10,
   274 					SpriteID pal = PAL_NONE;
   272 							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]),
   275 					if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
   273 							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,
       
   281 							GetSlopeZ(ti->x + x_pcp_offsets[i], ti->y + y_pcp_offsets[i]));
       
   282 					break; /* We already have drawn a pylon, bail out */
   274 					break; /* We already have drawn a pylon, bail out */
   283 				}
   275 				}
   284 			}
   276 			}
   285 		}
   277 		}
   286 	}
   278 	}
   313 
   305 
   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) */
   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) */
   315 			assert(!IsSteepSlope(tileh[TS_HOME]));
   307 			assert(!IsSteepSlope(tileh[TS_HOME]));
   316 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
   308 			sss = &CatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
   317 
   309 
   318 			SpriteID img = sss->image;
   310 			AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   319 			SpriteID pal = PAL_NONE;
   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,
   320 			if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
   312 				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,
       
   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);
       
   327 		}
   313 		}
   328 	}
   314 	}
   329 }
   315 }
   330 
   316 
   331 static void DrawCatenaryOnBridge(const TileInfo *ti)
   317 static void DrawCatenaryOnBridge(const TileInfo *ti)
   352 		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
   338 		sss = &CatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
   353 	}
   339 	}
   354 
   340 
   355 	height = GetBridgeHeight(end);
   341 	height = GetBridgeHeight(end);
   356 
   342 
   357 	SpriteID img = sss->image;
   343 	AddSortableSpriteToDraw(sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   358 	SpriteID pal = PAL_NONE;
   344 		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
   359 	if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
   345 		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,
       
   365 		sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset
       
   366 	);
   346 	);
   367 
   347 
   368 	/* Finished with wires, draw pylons */
   348 	/* Finished with wires, draw pylons */
   369 	/* every other tile needs a pylon on the northern end */
   349 	/* every other tile needs a pylon on the northern end */
   370 	if (num % 2) {
   350 	if (num % 2) {
   371 		if (axis == AXIS_X) {
   351 		if (axis == AXIS_X) {
   372 			img = pylons_bridge[0 + HASBIT(tlg, 0)];
   352 			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], PAL_NONE, ti->x, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
   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);
       
   375 		} else {
   353 		} else {
   376 			img = pylons_bridge[2 + HASBIT(tlg, 1)];
   354 			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], PAL_NONE, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y, 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
   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);
       
   379 		}
   355 		}
   380 	}
   356 	}
   381 
   357 
   382 	/* need a pylon on the southern end of the bridge */
   358 	/* need a pylon on the southern end of the bridge */
   383 	if (DistanceMax(ti->tile, start) == length) {
   359 	if (DistanceMax(ti->tile, start) == length) {
   384 		if (axis == AXIS_X) {
   360 		if (axis == AXIS_X) {
   385 			img = pylons_bridge[0 + HASBIT(tlg, 0)];
   361 			AddSortableSpriteToDraw(pylons_bridge[0 + HASBIT(tlg, 0)], PAL_NONE, ti->x + 16, ti->y + 4 + 8 * HASBIT(tlg, 0), 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
   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);
       
   388 		} else {
   362 		} else {
   389 			img = pylons_bridge[2 + HASBIT(tlg, 1)];
   363 			AddSortableSpriteToDraw(pylons_bridge[2 + HASBIT(tlg, 1)], PAL_NONE, ti->x + 4 + 8 * HASBIT(tlg, 1), ti->y + 16, 1, 1, 10, height, HASBIT(_transparent_opt, TO_BUILDINGS));
   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);
       
   392 		}
   364 		}
   393 	}
   365 	}
   394 }
   366 }
   395 
   367 
   396 void DrawCatenary(const TileInfo *ti)
   368 void DrawCatenary(const TileInfo *ti)
   408 	switch (GetTileType(ti->tile)) {
   380 	switch (GetTileType(ti->tile)) {
   409 		case MP_RAILWAY:
   381 		case MP_RAILWAY:
   410 			if (IsRailDepot(ti->tile)) {
   382 			if (IsRailDepot(ti->tile)) {
   411 				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
   383 				const SortableSpriteStruct *sss = &CatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
   412 
   384 
   413 				SpriteID img = sss->image;
       
   414 				SpriteID pal = PAL_NONE;
       
   415 				if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
       
   416 					SETBIT(img, PALETTE_MODIFIER_TRANSPARENT);
       
   417 					pal = PALETTE_TO_TRANSPARENT;
       
   418 				}
       
   419 
       
   420 				AddSortableSpriteToDraw(
   385 				AddSortableSpriteToDraw(
   421 					img, pal, ti->x + sss->x_offset, ti->y + sss->y_offset,
   386 					sss->image, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
   422 					sss->x_size, sss->y_size, sss->z_size,
   387 					sss->x_size, sss->y_size, sss->z_size,
   423 					GetTileMaxZ(ti->tile) + sss->z_offset
   388 					GetTileMaxZ(ti->tile) + sss->z_offset,
       
   389 					HASBIT(_transparent_opt, TO_BUILDINGS)
   424 				);
   390 				);
   425 				return;
   391 				return;
   426 			}
   392 			}
   427 			break;
   393 			break;
   428 
   394 
   429 		case MP_TUNNELBRIDGE:
   395 		case MP_TUNNELBRIDGE:
   430 		case MP_STREET:
   396 		case MP_ROAD:
   431 		case MP_STATION:
   397 		case MP_STATION:
   432 			break;
   398 			break;
   433 
   399 
   434 		default: return;
   400 		default: return;
   435 	}
   401 	}