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

Function DrawSingleSignal

src/rail_cmd.cpp:1863–1901  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1861}
1862
1863static void DrawSingleSignal(TileIndex tile, const RailTypeInfo *rti, Track track, SignalState condition, SignalOffsets image, uint pos)
1864{
1865 bool side;
1866 switch (_settings_game.construction.train_signal_side) {
1867 case 0: side = false; break; // left
1868 case 2: side = true; break; // right
1869 default: side = _settings_game.vehicle.road_side != 0; break; // driving side
1870 }
1871 static const Point SignalPositions[2][12] = {
1872 { // Signals on the left side
1873 /* LEFT LEFT RIGHT RIGHT UPPER UPPER */
1874 { 8, 5}, {14, 1}, { 1, 14}, { 9, 11}, { 1, 0}, { 3, 10},
1875 /* LOWER LOWER X X Y Y */
1876 {11, 4}, {14, 14}, {11, 3}, { 4, 13}, { 3, 4}, {11, 13}
1877 }, { // Signals on the right side
1878 /* LEFT LEFT RIGHT RIGHT UPPER UPPER */
1879 {14, 1}, {12, 10}, { 4, 6}, { 1, 14}, {10, 4}, { 0, 1},
1880 /* LOWER LOWER X X Y Y */
1881 {14, 14}, { 5, 12}, {11, 13}, { 4, 3}, {13, 4}, { 3, 11}
1882 }
1883 };
1884
1885 uint x = TileX(tile) * TILE_SIZE + SignalPositions[side][pos].x;
1886 uint y = TileY(tile) * TILE_SIZE + SignalPositions[side][pos].y;
1887
1888 SignalType type = GetSignalType(tile, track);
1889 SignalVariant variant = GetSignalVariant(tile, track);
1890
1891 SpriteID sprite = GetCustomSignalSprite(rti, tile, type, variant, condition);
1892 if (sprite != 0) {
1893 sprite += image;
1894 } else {
1895 /* Normal electric signals are stored in a different sprite block than all other signals. */
1896 sprite = (type == SIGTYPE_BLOCK && variant == SIG_ELECTRIC) ? SPR_ORIGINAL_SIGNALS_BASE : SPR_SIGNALS_BASE - 16;
1897 sprite += type * 16 + variant * 64 + image * 2 + condition + (type > SIGTYPE_LAST_NOPBS ? 64 : 0);
1898 }
1899
1900 AddSortableSpriteToDraw(sprite, PAL_NONE, x, y, GetSaveSlopeZ(x, y, track), {{}, {1, 1, BB_HEIGHT_UNDER_BRIDGE}, {}});
1901}
1902
1903/** Offsets for drawing fences */
1904struct FenceOffset : SpriteBounds {

Callers 1

DrawSignalsFunction · 0.85

Calls 7

TileXFunction · 0.85
TileYFunction · 0.85
GetSignalTypeFunction · 0.85
GetSignalVariantFunction · 0.85
GetCustomSignalSpriteFunction · 0.85
GetSaveSlopeZFunction · 0.85
AddSortableSpriteToDrawFunction · 0.70

Tested by

no test coverage detected