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