OpenTTD Source  20240917-master-g9ab0a47812
elrail.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
55 #include "stdafx.h"
56 #include "station_map.h"
57 #include "viewport_func.h"
58 #include "train.h"
59 #include "rail_gui.h"
60 #include "tunnelbridge_map.h"
61 #include "tunnelbridge.h"
62 #include "elrail_func.h"
63 #include "company_base.h"
64 #include "newgrf_railtype.h"
65 
66 #include "table/elrail_data.h"
67 
68 #include "safeguards.h"
69 
75 static inline TLG GetTLG(TileIndex t)
76 {
77  return (TLG)((HasBit(TileX(t), 0) << 1) + HasBit(TileY(t), 0));
78 }
79 
86 static TrackBits GetRailTrackBitsUniversal(TileIndex t, uint8_t *override)
87 {
88  switch (GetTileType(t)) {
89  case MP_RAILWAY:
91  switch (GetRailTileType(t)) {
93  return GetTrackBits(t);
94  default:
95  return TRACK_BIT_NONE;
96  }
97  break;
98 
99  case MP_TUNNELBRIDGE:
101  if (!HasRailCatenary(GetRailType(t))) return TRACK_BIT_NONE;
102  if (override != nullptr && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
103  *override = 1 << GetTunnelBridgeDirection(t);
104  }
106 
107  case MP_ROAD:
108  if (!IsLevelCrossing(t)) return TRACK_BIT_NONE;
109  if (!HasRailCatenary(GetRailType(t))) return TRACK_BIT_NONE;
110  return GetCrossingRailBits(t);
111 
112  case MP_STATION:
113  if (!HasStationRail(t)) return TRACK_BIT_NONE;
114  if (!HasRailCatenary(GetRailType(t))) return TRACK_BIT_NONE;
116 
117  default:
118  return TRACK_BIT_NONE;
119  }
120 }
121 
126 {
127  /* Single track bits are never masked out. */
128  if (HasAtMostOneBit(tracks)) [[likely]] return tracks;
129 
130  if (!IsPlainRailTile(t)) return tracks;
131 
132  TrackdirBits neighbour_tdb = TRACKDIR_BIT_NONE;
133  for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
134  /* If the neighbour tile is either not electrified or has no tracks that can be reached
135  * from this tile, mark all trackdirs that can be reached from the neighbour tile
136  * as needing no catenary. We make an exception for blocked station tiles with a matching
137  * axis that still display wires to preserve visual continuity. */
138  TileIndex next_tile = TileAddByDiagDir(t, d);
139  RailType rt = GetTileRailType(next_tile);
140  if (rt == INVALID_RAILTYPE || !HasRailCatenary(rt) ||
142  (!HasStationTileRail(next_tile) || GetRailStationAxis(next_tile) != DiagDirToAxis(d) || !CanStationTileHaveWires(next_tile)))) {
143  neighbour_tdb |= DiagdirReachesTrackdirs(ReverseDiagDir(d));
144  }
145  }
146 
147  /* If the tracks from either a diagonal crossing or don't overlap, both
148  * trackdirs have to be marked to mask the corresponding track bit. Else
149  * one marked trackdir is enough the mask the track bit. */
150  TrackBits mask;
151  if (tracks == TRACK_BIT_CROSS || !TracksOverlap(tracks)) {
152  /* If the tracks form either a diagonal crossing or don't overlap, both
153  * trackdirs have to be marked to mask the corresponding track bit. */
154  mask = ~(TrackBits)((neighbour_tdb & (neighbour_tdb >> 8)) & TRACK_BIT_MASK);
155  /* If that results in no masked tracks and it is not a diagonal crossing,
156  * require only one marked trackdir to mask. */
157  if (tracks != TRACK_BIT_CROSS && (mask & TRACK_BIT_MASK) == TRACK_BIT_MASK) mask = ~TrackdirBitsToTrackBits(neighbour_tdb);
158  } else {
159  /* Require only one marked trackdir to mask the track. */
160  mask = ~TrackdirBitsToTrackBits(neighbour_tdb);
161  /* If that results in an empty set, require both trackdirs for diagonal track. */
162  if ((tracks & mask) == TRACK_BIT_NONE) {
163  if ((neighbour_tdb & TRACKDIR_BIT_X_NE) == 0 || (neighbour_tdb & TRACKDIR_BIT_X_SW) == 0) mask |= TRACK_BIT_X;
164  if ((neighbour_tdb & TRACKDIR_BIT_Y_NW) == 0 || (neighbour_tdb & TRACKDIR_BIT_Y_SE) == 0) mask |= TRACK_BIT_Y;
165  /* If that still is not enough, require both trackdirs for any track. */
166  if ((tracks & mask) == TRACK_BIT_NONE) mask = ~(TrackBits)((neighbour_tdb & (neighbour_tdb >> 8)) & TRACK_BIT_MASK);
167  }
168  }
169 
170  /* Mask the tracks only if at least one track bit would remain. */
171  return (tracks & mask) != TRACK_BIT_NONE ? tracks & mask : tracks;
172 }
173 
177 static inline SpriteID GetWireBase(TileIndex tile, TileContext context = TCX_NORMAL)
178 {
179  const RailTypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
180  SpriteID wires = GetCustomRailSprite(rti, tile, RTSG_WIRES, context);
181  return wires == 0 ? SPR_WIRE_BASE : wires;
182 }
183 
187 static inline SpriteID GetPylonBase(TileIndex tile, TileContext context = TCX_NORMAL)
188 {
189  const RailTypeInfo *rti = GetRailTypeInfo(GetRailType(tile));
190  SpriteID pylons = GetCustomRailSprite(rti, tile, RTSG_PYLONS, context);
191  return pylons == 0 ? SPR_PYLON_BASE : pylons;
192 }
193 
199 static void AdjustTileh(TileIndex tile, Slope *tileh)
200 {
201  if (IsTileType(tile, MP_TUNNELBRIDGE)) {
202  if (IsTunnel(tile)) {
203  *tileh = SLOPE_STEEP; // XXX - Hack to make tunnel entrances to always have a pylon
204  } else if (*tileh != SLOPE_FLAT) {
205  *tileh = SLOPE_FLAT;
206  } else {
207  *tileh = InclinedSlope(GetTunnelBridgeDirection(tile));
208  }
209  }
210 }
211 
219 static int GetPCPElevation(TileIndex tile, DiagDirection PCPpos)
220 {
221  /* The elevation of the "pylon"-sprite should be the elevation at the PCP.
222  * PCPs are always on a tile edge.
223  *
224  * This position can be outside of the tile, i.e. ?_pcp_offset == TILE_SIZE > TILE_SIZE - 1.
225  * So we have to move it inside the tile, because if the neighboured tile has a foundation,
226  * that does not smoothly connect to the current tile, we will get a wrong elevation from GetSlopePixelZ().
227  *
228  * When we move the position inside the tile, we will get a wrong elevation if we have a slope.
229  * To catch all cases we round the Z position to the next (TILE_HEIGHT / 2).
230  * This will return the correct elevation for slopes and will also detect non-continuous elevation on edges.
231  *
232  * Also note that the result of GetSlopePixelZ() is very special on bridge-ramps.
233  */
234 
235  int z = GetSlopePixelZ(TileX(tile) * TILE_SIZE + std::min<int8_t>(x_pcp_offsets[PCPpos], TILE_SIZE - 1),
236  TileY(tile) * TILE_SIZE + std::min<int8_t>(y_pcp_offsets[PCPpos], TILE_SIZE - 1), true);
237  /* Round the Z to the nearest half tile height. */
238  static const uint HALF_TILE_HEIGHT = TILE_HEIGHT / 2;
239  return (z + HALF_TILE_HEIGHT / 2) / HALF_TILE_HEIGHT * HALF_TILE_HEIGHT;
240 }
241 
250 {
251  /* xmin, ymin, xmax + 1, ymax + 1 of BB */
252  static const int _tunnel_wire_BB[4][4] = {
253  { 0, 1, 16, 15 }, // NE
254  { 1, 0, 15, 16 }, // SE
255  { 0, 1, 16, 15 }, // SW
256  { 1, 0, 15, 16 }, // NW
257  };
258 
260 
261  SpriteID wire_base = GetWireBase(ti->tile);
262 
263  const SortableSpriteStruct *sss = &RailCatenarySpriteData_Tunnel[dir];
264  const int *BB_data = _tunnel_wire_BB[dir];
266  wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
267  BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset + 1,
268  GetTilePixelZ(ti->tile) + sss->z_offset,
270  BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset, BB_Z_SEPARATOR - sss->z_offset
271  );
272 }
273 
278 static void DrawRailCatenaryRailway(const TileInfo *ti)
279 {
280  /* Pylons are placed on a tile edge, so we need to take into account
281  * the track configuration of 2 adjacent tiles. trackconfig[0] stores the
282  * current tile (home tile) while [1] holds the neighbour */
283  TrackBits trackconfig[TS_END];
284  TrackBits wireconfig[TS_END];
285  bool isflat[TS_END];
286  /* Note that ti->tileh has already been adjusted for Foundations */
287  Slope tileh[TS_END] = { ti->tileh, SLOPE_FLAT };
288 
289  /* Half tile slopes coincide only with horizontal/vertical track.
290  * Faking a flat slope results in the correct sprites on positions. */
291  Corner halftile_corner = CORNER_INVALID;
292  if (IsHalftileSlope(tileh[TS_HOME])) {
293  halftile_corner = GetHalftileSlopeCorner(tileh[TS_HOME]);
294  tileh[TS_HOME] = SLOPE_FLAT;
295  }
296 
297  TLG tlg = GetTLG(ti->tile);
298  uint8_t PCPstatus = 0;
299  uint8_t OverridePCP = 0;
300  uint8_t PPPpreferred[DIAGDIR_END];
301  uint8_t PPPallowed[DIAGDIR_END];
302 
303  /* Find which rail bits are present, and select the override points.
304  * We don't draw a pylon:
305  * 1) INSIDE a tunnel (we wouldn't see it anyway)
306  * 2) on the "far" end of a bridge head (the one that connects to bridge middle),
307  * because that one is drawn on the bridge. Exception is for length 0 bridges
308  * which have no middle tiles */
309  trackconfig[TS_HOME] = GetRailTrackBitsUniversal(ti->tile, &OverridePCP);
310  wireconfig[TS_HOME] = MaskWireBits(ti->tile, trackconfig[TS_HOME]);
311  /* If a track bit is present that is not in the main direction, the track is level */
312  isflat[TS_HOME] = ((trackconfig[TS_HOME] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0);
313 
314  AdjustTileh(ti->tile, &tileh[TS_HOME]);
315 
316  SpriteID pylon_normal = GetPylonBase(ti->tile);
317  SpriteID pylon_halftile = (halftile_corner != CORNER_INVALID) ? GetPylonBase(ti->tile, TCX_UPPER_HALFTILE) : pylon_normal;
318 
319  for (DiagDirection i = DIAGDIR_BEGIN; i < DIAGDIR_END; i++) {
320  static const uint edge_corners[] = {
321  1 << CORNER_N | 1 << CORNER_E, // DIAGDIR_NE
322  1 << CORNER_S | 1 << CORNER_E, // DIAGDIR_SE
323  1 << CORNER_S | 1 << CORNER_W, // DIAGDIR_SW
324  1 << CORNER_N | 1 << CORNER_W, // DIAGDIR_NW
325  };
326  SpriteID pylon_base = (halftile_corner != CORNER_INVALID && HasBit(edge_corners[i], halftile_corner)) ? pylon_halftile : pylon_normal;
327  TileIndex neighbour = ti->tile + TileOffsByDiagDir(i);
328  int elevation = GetPCPElevation(ti->tile, i);
329 
330  /* Here's one of the main headaches. GetTileSlope does not correct for possibly
331  * existing foundataions, so we do have to do that manually later on.*/
332  tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour);
333  trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, nullptr);
334  wireconfig[TS_NEIGHBOUR] = MaskWireBits(neighbour, trackconfig[TS_NEIGHBOUR]);
335  if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) wireconfig[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
336 
337  /* Ignore station tiles that allow neither wires nor pylons. */
338  if (IsRailStationTile(neighbour) && !CanStationTileHavePylons(neighbour) && !CanStationTileHaveWires(neighbour)) wireconfig[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
339 
340  /* If the neighboured tile does not smoothly connect to the current tile (because of a foundation),
341  * we have to draw all pillars on the current tile. */
342  if (elevation != GetPCPElevation(neighbour, ReverseDiagDir(i))) wireconfig[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
343 
344  isflat[TS_NEIGHBOUR] = ((trackconfig[TS_NEIGHBOUR] & (TRACK_BIT_HORZ | TRACK_BIT_VERT)) != 0);
345 
346  PPPpreferred[i] = 0xFF; // We start with preferring everything (end-of-line in any direction)
347  PPPallowed[i] = AllowedPPPonPCP[i];
348 
349  /* We cycle through all the existing tracks at a PCP and see what
350  * PPPs we want to have, or may not have at all */
351  for (uint k = 0; k < NUM_TRACKS_AT_PCP; k++) {
352  /* Next to us, we have a bridge head, don't worry about that one, if it shows away from us */
353  if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
354  IsBridgeTile(neighbour) &&
355  GetTunnelBridgeDirection(neighbour) == ReverseDiagDir(i)) {
356  continue;
357  }
358 
359  /* We check whether the track in question (k) is present in the tile
360  * (TrackSourceTile) */
361  DiagDirection PCPpos = i;
362  if (HasBit(wireconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
363  /* track found, if track is in the neighbour tile, adjust the number
364  * of the PCP for preferred/allowed determination*/
365  PCPpos = (TrackSourceTile[i][k] == TS_HOME) ? i : ReverseDiagDir(i);
366  SetBit(PCPstatus, i); // This PCP is in use
367  PPPpreferred[i] &= PreferredPPPofTrackAtPCP[TracksAtPCP[i][k]][PCPpos];
368  }
369 
370  if (HasBit(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
371  PPPallowed[i] &= ~DisallowedPPPofTrackAtPCP[TracksAtPCP[i][k]][PCPpos];
372  }
373  }
374 
375  /* Deactivate all PPPs if PCP is not used */
376  if (!HasBit(PCPstatus, i)) {
377  PPPpreferred[i] = 0;
378  PPPallowed[i] = 0;
379  }
380 
381  Foundation foundation = FOUNDATION_NONE;
382 
383  /* Station and road crossings are always "flat", so adjust the tileh accordingly */
384  if (IsTileType(neighbour, MP_STATION) || IsTileType(neighbour, MP_ROAD)) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
385 
386  /* Read the foundations if they are present, and adjust the tileh */
387  if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE && IsTileType(neighbour, MP_RAILWAY) && HasRailCatenary(GetRailType(neighbour))) foundation = GetRailFoundation(tileh[TS_NEIGHBOUR], trackconfig[TS_NEIGHBOUR]);
388  if (IsBridgeTile(neighbour)) {
389  foundation = GetBridgeFoundation(tileh[TS_NEIGHBOUR], DiagDirToAxis(GetTunnelBridgeDirection(neighbour)));
390  }
391 
392  ApplyFoundationToSlope(foundation, tileh[TS_NEIGHBOUR]);
393 
394  /* Half tile slopes coincide only with horizontal/vertical track.
395  * Faking a flat slope results in the correct sprites on positions. */
396  if (IsHalftileSlope(tileh[TS_NEIGHBOUR])) tileh[TS_NEIGHBOUR] = SLOPE_FLAT;
397 
398  AdjustTileh(neighbour, &tileh[TS_NEIGHBOUR]);
399 
400  /* If we have a straight (and level) track, we want a pylon only every 2 tiles
401  * Delete the PCP if this is the case.
402  * Level means that the slope is the same, or the track is flat */
403  if (tileh[TS_HOME] == tileh[TS_NEIGHBOUR] || (isflat[TS_HOME] && isflat[TS_NEIGHBOUR])) {
404  for (uint k = 0; k < NUM_IGNORE_GROUPS; k++) {
405  if (PPPpreferred[i] == IgnoredPCP[k][tlg][i]) ClrBit(PCPstatus, i);
406  }
407  }
408 
409  /* Now decide where we draw our pylons. First try the preferred PPPs, but they may not exist.
410  * In that case, we try the any of the allowed ones. if they don't exist either, don't draw
411  * anything. Note that the preferred PPPs still contain the end-of-line markers.
412  * Remove those (simply by ANDing with allowed, since these markers are never allowed) */
413  if ((PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
414 
415  if (IsBridgeAbove(ti->tile)) {
416  Track bridgetrack = GetBridgeAxis(ti->tile) == AXIS_X ? TRACK_X : TRACK_Y;
417  int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
418 
419  if ((height <= GetTileMaxZ(ti->tile) + 1) &&
420  (i == PCPpositions[bridgetrack][0] || i == PCPpositions[bridgetrack][1])) {
421  SetBit(OverridePCP, i);
422  }
423  }
424 
425  if (PPPallowed[i] != 0 && HasBit(PCPstatus, i) && !HasBit(OverridePCP, i) &&
427  for (Direction k = DIR_BEGIN; k < DIR_END; k++) {
428  uint8_t temp = PPPorder[i][GetTLG(ti->tile)][k];
429 
430  if (HasBit(PPPallowed[i], temp)) {
431  uint x = ti->x + x_pcp_offsets[i] + x_ppp_offsets[temp];
432  uint y = ti->y + y_pcp_offsets[i] + y_ppp_offsets[temp];
433 
434  /* Don't build the pylon if it would be outside the tile */
435  if (!HasBit(OwnedPPPonPCP[i], temp)) {
436  /* We have a neighbour that will draw it, bail out */
437  if (trackconfig[TS_NEIGHBOUR] != TRACK_BIT_NONE) break;
438  continue; // No neighbour, go looking for a better position
439  }
440 
441  AddSortableSpriteToDraw(pylon_base + pylon_sprites[temp], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE,
442  elevation, IsTransparencySet(TO_CATENARY), -1, -1);
443 
444  break; // We already have drawn a pylon, bail out
445  }
446  }
447  }
448  }
449 
450  /* The wire above the tunnel is drawn together with the tunnel-roof (see DrawRailCatenaryOnTunnel()) */
451  if (IsTunnelTile(ti->tile)) return;
452 
453  /* Don't draw a wire under a low bridge */
455  int height = GetBridgeHeight(GetNorthernBridgeEnd(ti->tile));
456 
457  if (height <= GetTileMaxZ(ti->tile) + 1) return;
458  }
459 
460  /* Don't draw a wire if the station tile does not want any */
461  if (IsRailStationTile(ti->tile) && !CanStationTileHaveWires(ti->tile)) return;
462 
463  SpriteID wire_normal = GetWireBase(ti->tile);
464  SpriteID wire_halftile = (halftile_corner != CORNER_INVALID) ? GetWireBase(ti->tile, TCX_UPPER_HALFTILE) : wire_normal;
465  Track halftile_track;
466  switch (halftile_corner) {
467  case CORNER_W: halftile_track = TRACK_LEFT; break;
468  case CORNER_S: halftile_track = TRACK_LOWER; break;
469  case CORNER_E: halftile_track = TRACK_RIGHT; break;
470  case CORNER_N: halftile_track = TRACK_UPPER; break;
471  default: halftile_track = INVALID_TRACK; break;
472  }
473 
474  /* Drawing of pylons is finished, now draw the wires */
475  for (Track t : SetTrackBitIterator(wireconfig[TS_HOME])) {
476  SpriteID wire_base = (t == halftile_track) ? wire_halftile : wire_normal;
477  uint8_t PCPconfig = HasBit(PCPstatus, PCPpositions[t][0]) +
478  (HasBit(PCPstatus, PCPpositions[t][1]) << 1);
479 
480  const SortableSpriteStruct *sss;
481  int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3; // tileh for the slopes, 0 otherwise
482 
483  assert(PCPconfig != 0); // We have a pylon on neither end of the wire, that doesn't work (since we have no sprites for that)
484  assert(!IsSteepSlope(tileh[TS_HOME]));
485  sss = &RailCatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
486 
487  /*
488  * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE.
489  * Therefore it is safe to use GetSlopePixelZ() for the elevation.
490  * Also note that the result of GetSlopePixelZ() is very special for bridge-ramps, so we round the result up or
491  * down to the nearest full height change.
492  */
493  AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
494  sss->x_size, sss->y_size, sss->z_size, (GetSlopePixelZ(ti->x + sss->x_offset, ti->y + sss->y_offset, true) + 4) / 8 * 8 + sss->z_offset,
496  }
497 }
498 
507 {
509  TileIndex start = GetOtherBridgeEnd(end);
510 
511  uint length = GetTunnelBridgeLength(start, end);
512  uint num = GetTunnelBridgeLength(ti->tile, start) + 1;
513  uint height;
514 
515  const SortableSpriteStruct *sss;
516  Axis axis = GetBridgeAxis(ti->tile);
517  TLG tlg = GetTLG(ti->tile);
518 
519  RailCatenarySprite offset = (RailCatenarySprite)(axis == AXIS_X ? 0 : WIRE_Y_FLAT_BOTH - WIRE_X_FLAT_BOTH);
520 
521  if ((length % 2) && num == length) {
522  /* Draw the "short" wire on the southern end of the bridge
523  * only needed if the length of the bridge is odd */
524  sss = &RailCatenarySpriteData[WIRE_X_FLAT_BOTH + offset];
525  } else {
526  /* Draw "long" wires on all other tiles of the bridge (one pylon every two tiles) */
527  sss = &RailCatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
528  }
529 
530  height = GetBridgePixelHeight(end);
531 
532  SpriteID wire_base = GetWireBase(end, TCX_ON_BRIDGE);
533 
534  AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
535  sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
537  );
538 
539  SpriteID pylon_base = GetPylonBase(end, TCX_ON_BRIDGE);
540 
541  /* Finished with wires, draw pylons
542  * every other tile needs a pylon on the northern end */
543  if (num % 2) {
544  DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_NE : DIAGDIR_NW);
545  Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
546  if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
547  uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
548  uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
549  AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1);
550  }
551 
552  /* need a pylon on the southern end of the bridge */
553  if (GetTunnelBridgeLength(ti->tile, start) + 1 == length) {
554  DiagDirection PCPpos = (axis == AXIS_X ? DIAGDIR_SW : DIAGDIR_SE);
555  Direction PPPpos = (axis == AXIS_X ? DIR_NW : DIR_NE);
556  if (HasBit(tlg, (axis == AXIS_X ? 0 : 1))) PPPpos = ReverseDir(PPPpos);
557  uint x = ti->x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
558  uint y = ti->y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
559  AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1, BB_HEIGHT_UNDER_BRIDGE, height, IsTransparencySet(TO_CATENARY), -1, -1);
560  }
561 }
562 
568 void DrawRailCatenary(const TileInfo *ti)
569 {
570  switch (GetTileType(ti->tile)) {
571  case MP_RAILWAY:
572  if (IsRailDepot(ti->tile)) {
573  const SortableSpriteStruct *sss = &RailCatenarySpriteData_Depot[GetRailDepotDirection(ti->tile)];
574 
575  SpriteID wire_base = GetWireBase(ti->tile);
576 
577  /* This wire is not visible with the default depot sprites */
579  wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
580  sss->x_size, sss->y_size, sss->z_size,
581  GetTileMaxPixelZ(ti->tile) + sss->z_offset,
583  );
584  return;
585  }
586  break;
587 
588  case MP_TUNNELBRIDGE:
589  case MP_ROAD:
590  case MP_STATION:
591  break;
592 
593  default: return;
594  }
596 }
597 
598 void SettingsDisableElrail(int32_t new_value)
599 {
600  bool disable = (new_value != 0);
601 
602  /* pick appropriate railtype for elrail engines depending on setting */
603  const RailType new_railtype = disable ? RAILTYPE_RAIL : RAILTYPE_ELECTRIC;
604 
605  /* walk through all train engines */
606  for (Engine *e : Engine::IterateType(VEH_TRAIN)) {
607  RailVehicleInfo *rv_info = &e->u.rail;
608  /* update railtype of engines intended to use elrail */
609  if (rv_info->intended_railtype == RAILTYPE_ELECTRIC) {
610  rv_info->railtype = new_railtype;
611  }
612  }
613 
614  /* when disabling elrails, make sure that all existing trains can run on
615  * normal rail too */
616  if (disable) {
617  for (Train *t : Train::Iterate()) {
618  if (t->railtype == RAILTYPE_ELECTRIC) {
619  /* this railroad vehicle is now compatible only with elrail,
620  * so add there also normal rail compatibility */
621  t->compatible_railtypes |= RAILTYPES_RAIL;
622  t->railtype = RAILTYPE_RAIL;
624  }
625  }
626  }
627 
628  /* Fix the total power and acceleration for trains */
629  for (Train *t : Train::Iterate()) {
630  /* power and acceleration is cached only for front engines */
631  if (t->IsFrontEngine()) {
632  t->ConsistChanged(CCF_TRACK);
633  }
634  }
635 
636  for (Company *c : Company::Iterate()) c->avail_railtypes = GetCompanyRailTypes(c->index);
637 
638  /* This resets the _last_built_railtype, which will be invalid for electric
639  * rails. It may have unintended consequences if that function is ever
640  * extended, though. */
642 }
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34
DiagdirReachesTracks
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:573
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
tunnelbridge.h
TCX_UPPER_HALFTILE
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
Definition: newgrf_commons.h:25
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
ReverseDir
Direction ReverseDir(Direction d)
Return the reverse of a direction.
Definition: direction_func.h:54
GetTLG
static TLG GetTLG(TileIndex t)
Get the tile location group of a tile.
Definition: elrail.cpp:75
TO_CATENARY
@ TO_CATENARY
catenary
Definition: transparency.h:30
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition: engine_base.h:186
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
SettingsDisableElrail
void SettingsDisableElrail(int32_t new_value)
_settings_game.disable_elrail callback
Definition: elrail.cpp:598
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:59
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:136
GetBridgeFoundation
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
Definition: tunnelbridge_cmd.cpp:129
IsHalftileSlope
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
Definition: slope_func.h:47
train.h
BB_Z_SEPARATOR
static const uint BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.
Definition: viewport_type.h:89
GetTunnelBridgeLength
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:25
IsTunnelTile
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:34
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:37
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
DIR_BEGIN
@ DIR_BEGIN
Used to iterate.
Definition: direction_type.h:25
RAILTYPE_RAIL
@ RAILTYPE_RAIL
Standard non-electric rails.
Definition: rail_type.h:29
company_base.h
RAILTYPE_ELECTRIC
@ RAILTYPE_ELECTRIC
Electric rails.
Definition: rail_type.h:30
tunnelbridge_map.h
GetTileSlope
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition: tile_map.h:279
elrail_func.h
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
RTSG_PYLONS
@ RTSG_PYLONS
Catenary pylons.
Definition: rail.h:55
RAIL_TILE_SIGNALS
@ RAIL_TILE_SIGNALS
Normal rail tile with signals.
Definition: rail_map.h:25
GetCrossingRailBits
TrackBits GetCrossingRailBits(Tile tile)
Get the rail track bits of a level crossing.
Definition: road_map.h:368
IsTransparencySet
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition: transparency.h:48
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
TRACK_BIT_HORZ
@ TRACK_BIT_HORZ
Upper and lower track.
Definition: track_type.h:44
DIR_END
@ DIR_END
Used to iterate.
Definition: direction_type.h:34
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Definition: bridge_map.cpp:70
DrawRailCatenaryRailway
static void DrawRailCatenaryRailway(const TileInfo *ti)
Draws wires and, if required, pylons on a given tile.
Definition: elrail.cpp:278
RailTypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:127
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
RailCatenarySprite
RailCatenarySprite
Refers to a certain element of the catenary.
Definition: elrail_data.h:422
BB_HEIGHT_UNDER_BRIDGE
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
Definition: viewport_type.h:88
IsSteepSlope
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
IsRailStationTile
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
Definition: station_map.h:102
TRACK_BIT_VERT
@ TRACK_BIT_VERT
Left and right track.
Definition: track_type.h:45
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL
@ VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL
Electric train engine is allowed to run on normal rail. *‍/.
Definition: train.h:30
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
IsLevelCrossing
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition: road_map.h:85
DrawRailCatenaryOnBridge
void DrawRailCatenaryOnBridge(const TileInfo *ti)
Draws wires on a tunnel tile.
Definition: elrail.cpp:506
HasRailCatenary
bool HasRailCatenary(RailType rt)
Test if a rail type has catenary.
Definition: elrail_func.h:21
TileInfo::y
int y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:45
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetHalftileSlopeCorner
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
Definition: slope_func.h:148
TRACKDIR_BIT_Y_NW
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition: track_type.h:108
Engine
Definition: engine_base.h:37
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
GetSlopePixelZ
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
Definition: landscape.cpp:303
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:50
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition: station_map.h:496
Foundation
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
GetRailTrackBitsUniversal
static TrackBits GetRailTrackBitsUniversal(TileIndex t, uint8_t *override)
Finds which Electrified Rail Bits are present on a given tile.
Definition: elrail.cpp:86
TRACK_BIT_MASK
@ TRACK_BIT_MASK
Bitmask for the first 6 bits.
Definition: track_type.h:51
TrackToTrackBits
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:77
AllowedPPPonPCP
static const uint8_t AllowedPPPonPCP[DIAGDIR_END]
Which PPPs are possible at all on a given PCP.
Definition: elrail_data.h:43
TracksOverlap
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:645
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:553
DiagDirToDiagTrackBits
TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:524
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:46
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:36
GetRailDepotDirection
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
Definition: rail_map.h:171
DisallowedPPPofTrackAtPCP
static const uint8_t DisallowedPPPofTrackAtPCP[TRACK_END][DIAGDIR_END]
Which pylons can definitely NOT be built.
Definition: elrail_data.h:197
TO_BRIDGES
@ TO_BRIDGES
bridges
Definition: transparency.h:28
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
IsRailDepot
static debug_inline bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
Definition: rail_map.h:95
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
GetRailStationTrack
Track GetRailStationTrack(Tile t)
Get the rail track of a rail station tile.
Definition: station_map.h:508
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:301
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition: direction_type.h:74
IsTunnel
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:23
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:99
ReverseDiagDir
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Definition: direction_func.h:118
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:39
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
HasStationTileRail
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition: station_map.h:146
DiagdirReachesTrackdirs
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:555
ApplyFoundationToSlope
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
Definition: landscape.cpp:170
AdjustTileh
static void AdjustTileh(TileIndex tile, Slope *tileh)
Corrects the tileh for certain tile types.
Definition: elrail.cpp:199
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
TrackdirBitsToTrackBits
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:308
TileContext
TileContext
Context for tile accesses.
Definition: newgrf_commons.h:23
CanStationTileHavePylons
bool CanStationTileHavePylons(Tile t)
Can tile t have catenary pylons?
Definition: station_map.h:472
safeguards.h
Train
'Train' is either a loco or a wagon.
Definition: train.h:89
TCX_NORMAL
@ TCX_NORMAL
Nothing special.
Definition: newgrf_commons.h:24
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:49
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
TRACK_BIT_CROSS
@ TRACK_BIT_CROSS
X-Y-axis cross.
Definition: track_type.h:43
GetRailTileType
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:36
IgnoredPCP
static const uint8_t IgnoredPCP[NUM_IGNORE_GROUPS][TLG_END][DIAGDIR_END]
In case we have a straight line, we place pylon only every two tiles, so there are certain tiles whic...
Definition: elrail_data.h:122
TrackStatusToTrackBits
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:363
stdafx.h
OwnedPPPonPCP
static const uint8_t OwnedPPPonPCP[DIAGDIR_END]
Which of the PPPs are inside the tile.
Definition: elrail_data.h:55
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
viewport_func.h
IsPlainRailTile
static debug_inline bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition: rail_map.h:60
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:673
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:117
GetTrackBits
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:565
MaskWireBits
static TrackBits MaskWireBits(TileIndex t, TrackBits tracks)
Masks out track bits when neighbouring tiles are unelectrified.
Definition: elrail.cpp:125
TRACKDIR_BIT_X_NE
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition: track_type.h:100
rail_gui.h
GetPylonBase
static SpriteID GetPylonBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base pylon sprite to use.
Definition: elrail.cpp:187
RTSG_WIRES
@ RTSG_WIRES
Catenary wires.
Definition: rail.h:54
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
GetCompanyRailTypes
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:251
SLOPE_STEEP
@ SLOPE_STEEP
indicates the slope is steep
Definition: slope_type.h:54
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
GetRailFoundation
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
Checks if a track combination is valid on a specific slope and returns the needed foundation.
Definition: rail_cmd.cpp:312
TCX_ON_BRIDGE
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
Definition: newgrf_commons.h:26
HasAtMostOneBit
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
Definition: bitmath_func.hpp:290
HasStationRail
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition: station_map.h:135
GetPCPElevation
static int GetPCPElevation(TileIndex tile, DiagDirection PCPpos)
Returns the Z position of a Pylon Control Point.
Definition: elrail.cpp:219
TRACK_LEFT
@ TRACK_LEFT
Track in the left corner of the tile (west)
Definition: track_type.h:25
GetTileRailType
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
Definition: rail.cpp:155
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
RAIL_TILE_NORMAL
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
Definition: rail_map.h:24
GetWireBase
static SpriteID GetWireBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base wire sprite to use.
Definition: elrail.cpp:177
GetTunnelBridgeTransportType
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition: tunnelbridge_map.h:39
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
TRACK_UPPER
@ TRACK_UPPER
Track in the upper corner of the tile (north)
Definition: track_type.h:23
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
RailVehicleInfo::railtype
RailType railtype
Railtype, mangled if elrail is disabled.
Definition: engine_type.h:46
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:38
TRACK_LOWER
@ TRACK_LOWER
Track in the lower corner of the tile (south)
Definition: track_type.h:24
SpecializedVehicle< Train, Type >::Iterate
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1284
RailVehicleInfo::intended_railtype
RailType intended_railtype
Intended railtype, regardless of elrail being enabled or disabled.
Definition: engine_type.h:47
DrawRailCatenaryOnTunnel
void DrawRailCatenaryOnTunnel(const TileInfo *ti)
Draws wires on a tunnel tile.
Definition: elrail.cpp:249
InclinedSlope
Slope InclinedSlope(DiagDirection dir)
Returns the slope that is inclined in a specific direction.
Definition: slope_func.h:256
TRACKDIR_BIT_Y_SE
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition: track_type.h:101
station_map.h
elrail_data.h
GetTileMaxPixelZ
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition: tile_map.h:312
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
Definition: tile_type.h:18
DrawRailCatenary
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
Definition: elrail.cpp:568
TLG
TLG
Tile Location group.
Definition: elrail_data.h:20
PCPpositions
static const DiagDirection PCPpositions[TRACK_END][2]
Maps a track bit onto two PCP positions.
Definition: elrail_data.h:63
TileInfo::x
int x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:44
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:47
CCF_TRACK
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
Definition: train.h:48
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition: track_type.h:98
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
TRACK_Y
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition: track_type.h:22
GetBridgePixelHeight
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition: bridge_map.h:84
GetBridgeAxis
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
Definition: bridge_map.h:68
Company
Definition: company_base.h:133
PreferredPPPofTrackAtPCP
static const uint8_t PreferredPPPofTrackAtPCP[TRACK_END][DIAGDIR_END]
Preferred points of each trackbit.
Definition: elrail_data.h:79
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
INVALID_TRACK
@ INVALID_TRACK
Flag for an invalid track.
Definition: track_type.h:28
GetTilePixelZ
int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.h:302
TileAddByDiagDir
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:606
TRACK_X
@ TRACK_X
Track along the x-axis (north-east to south-west)
Definition: track_type.h:21
CanStationTileHaveWires
bool CanStationTileHaveWires(Tile t)
Can tile t have catenary wires?
Definition: station_map.h:448
newgrf_railtype.h
GetCustomRailSprite
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition: newgrf_railtype.cpp:96
TRACKDIR_BIT_X_SW
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition: track_type.h:107
SortableSpriteStruct
Definition: elrail_data.h:317
RAILTYPES_RAIL
@ RAILTYPES_RAIL
Non-electrified rails.
Definition: rail_type.h:46
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
ReinitGuiAfterToggleElrail
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
Definition: rail_gui.cpp:1908
TRACK_RIGHT
@ TRACK_RIGHT
Track in the right corner of the tile (east)
Definition: track_type.h:26
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103