MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawRailCatenaryOnBridge

Function DrawRailCatenaryOnBridge

src/elrail.cpp:490–543  ·  view source on GitHub ↗

* Draws wires on a tunnel tile * * DrawTile_TunnelBridge() calls this function to draw the wires on the bridge. * * @param ti The Tileinfo to draw the tile for */

Source from the content-addressed store, hash-verified

488 * @param ti The Tileinfo to draw the tile for
489 */
490void DrawRailCatenaryOnBridge(const TileInfo *ti)
491{
492 TileIndex end = GetSouthernBridgeEnd(ti->tile);
493 TileIndex start = GetOtherBridgeEnd(end);
494
495 uint length = GetTunnelBridgeLength(start, end);
496 uint num = GetTunnelBridgeLength(ti->tile, start) + 1;
497
498 Axis axis = GetBridgeAxis(ti->tile);
499 TileLocationGroup tlg = GetTileLocationGroup(ti->tile);
500
501 RailCatenarySprite offset = (RailCatenarySprite)(axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH);
502
503 const SortableSpriteStruct *sss;
504 if ((length % 2) && num == length) {
505 /* Draw the "short" wire on the southern end of the bridge
506 * only needed if the length of the bridge is odd */
507 sss = &_rail_catenary_sprite_data[WIRE_X_FLAT_BOTH + offset];
508 } else {
509 /* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */
510 sss = &_rail_catenary_sprite_data[WIRE_X_FLAT_SW + (num % 2) + offset];
511 }
512
513 uint height = GetBridgePixelHeight(end);
514
515 SpriteID wire_base = GetWireBase(end, TCX_ON_BRIDGE);
516
517 AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x, ti->y, height, *sss, IsTransparencySet(TO_CATENARY));
518
519 SpriteID pylon_base = GetPylonBase(end, TCX_ON_BRIDGE);
520
521 static constexpr SpriteBounds pylon_bounds{{-1, -1, 0}, {1, 1, BB_HEIGHT_UNDER_BRIDGE}, {1, 1, 0}};
522
523 /* Finished with wires, draw pylons
524 * every other tile needs a pylon on the northern end */
525 if (num % 2) {
526 DiagDirection pcp_pos = (axis == AXIS_X ? DIAGDIR_NE : DIAGDIR_NW);
527 Direction ppp_pos = (axis == AXIS_X ? DIR_NW : DIR_NE);
528 if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) ppp_pos = ReverseDir(ppp_pos);
529 uint x = ti->x + _x_pcp_offsets[pcp_pos] + _x_ppp_offsets[ppp_pos];
530 uint y = ti->y + _y_pcp_offsets[pcp_pos] + _y_ppp_offsets[ppp_pos];
531 AddSortableSpriteToDraw(pylon_base + _pylon_sprites[ppp_pos], PAL_NONE, x, y, height, pylon_bounds, IsTransparencySet(TO_CATENARY));
532 }
533
534 /* need a pylon on the southern end of the bridge */
535 if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) {
536 DiagDirection pcp_pos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
537 Direction ppp_pos = (axis == AXIS_X ? DIR_NW : DIR_NE);
538 if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) ppp_pos = ReverseDir(ppp_pos);
539 uint x = ti->x + _x_pcp_offsets[pcp_pos] + _x_ppp_offsets[ppp_pos];
540 uint y = ti->y + _y_pcp_offsets[pcp_pos] + _y_ppp_offsets[ppp_pos];
541 AddSortableSpriteToDraw(pylon_base + _pylon_sprites[ppp_pos], PAL_NONE, x, y, height, pylon_bounds, IsTransparencySet(TO_CATENARY));
542 }
543}
544
545/**
546 * Draws overhead wires and pylons for electric railways.

Callers 1

DrawBridgeMiddleFunction · 0.85

Calls 12

GetSouthernBridgeEndFunction · 0.85
GetOtherBridgeEndFunction · 0.85
GetTunnelBridgeLengthFunction · 0.85
GetBridgeAxisFunction · 0.85
GetTileLocationGroupFunction · 0.85
GetBridgePixelHeightFunction · 0.85
GetWireBaseFunction · 0.85
IsTransparencySetFunction · 0.85
GetPylonBaseFunction · 0.85
HasBitFunction · 0.85
ReverseDirFunction · 0.85
AddSortableSpriteToDrawFunction · 0.70

Tested by

no test coverage detected