OpenTTD Source  1.11.2
pbs.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 
10 #include "stdafx.h"
11 #include "viewport_func.h"
12 #include "vehicle_func.h"
13 #include "newgrf_station.h"
15 
16 #include "safeguards.h"
17 
25 {
26  switch (GetTileType(t)) {
27  case MP_RAILWAY:
28  if (IsRailDepot(t)) return GetDepotReservationTrackBits(t);
29  if (IsPlainRail(t)) return GetRailReservationTrackBits(t);
30  break;
31 
32  case MP_ROAD:
34  break;
35 
36  case MP_STATION:
38  break;
39 
40  case MP_TUNNELBRIDGE:
42  break;
43 
44  default:
45  break;
46  }
47  return TRACK_BIT_NONE;
48 }
49 
58 {
59  TileIndex tile = start;
60  TileIndexDiff diff = TileOffsByDiagDir(dir);
61 
62  assert(IsRailStationTile(start));
63  assert(GetRailStationAxis(start) == DiagDirToAxis(dir));
64 
65  do {
67  MarkTileDirtyByTile(tile);
68  tile = TILE_ADD(tile, diff);
69  } while (IsCompatibleTrainStationTile(tile, start));
70 }
71 
80 bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations)
81 {
83 
85  /* show the reserved rail if needed */
86  if (IsBridgeTile(tile)) {
87  MarkBridgeDirty(tile);
88  } else {
89  MarkTileDirtyByTile(tile);
90  }
91  }
92 
93  switch (GetTileType(tile)) {
94  case MP_RAILWAY:
95  if (IsPlainRail(tile)) return TryReserveTrack(tile, t);
96  if (IsRailDepot(tile)) {
97  if (!HasDepotReservation(tile)) {
98  SetDepotReservation(tile, true);
99  MarkTileDirtyByTile(tile); // some GRFs change their appearance when tile is reserved
100  return true;
101  }
102  }
103  break;
104 
105  case MP_ROAD:
106  if (IsLevelCrossing(tile) && !HasCrossingReservation(tile)) {
107  SetCrossingReservation(tile, true);
108  BarCrossing(tile);
109  MarkTileDirtyByTile(tile); // crossing barred, make tile dirty
110  return true;
111  }
112  break;
113 
114  case MP_STATION:
115  if (HasStationRail(tile) && !HasStationReservation(tile)) {
116  SetRailStationReservation(tile, true);
117  if (trigger_stations && IsRailStation(tile)) TriggerStationRandomisation(nullptr, tile, SRT_PATH_RESERVATION);
118  MarkTileDirtyByTile(tile); // some GRFs need redraw after reserving track
119  return true;
120  }
121  break;
122 
123  case MP_TUNNELBRIDGE:
125  SetTunnelBridgeReservation(tile, true);
126  return true;
127  }
128  break;
129 
130  default:
131  break;
132  }
133  return false;
134 }
135 
142 {
144 
146  if (IsBridgeTile(tile)) {
147  MarkBridgeDirty(tile);
148  } else {
149  MarkTileDirtyByTile(tile);
150  }
151  }
152 
153  switch (GetTileType(tile)) {
154  case MP_RAILWAY:
155  if (IsRailDepot(tile)) {
156  SetDepotReservation(tile, false);
157  MarkTileDirtyByTile(tile);
158  break;
159  }
160  if (IsPlainRail(tile)) UnreserveTrack(tile, t);
161  break;
162 
163  case MP_ROAD:
164  if (IsLevelCrossing(tile)) {
165  SetCrossingReservation(tile, false);
166  UpdateLevelCrossing(tile);
167  }
168  break;
169 
170  case MP_STATION:
171  if (HasStationRail(tile)) {
172  SetRailStationReservation(tile, false);
173  MarkTileDirtyByTile(tile);
174  }
175  break;
176 
177  case MP_TUNNELBRIDGE:
179  break;
180 
181  default:
182  break;
183  }
184 }
185 
186 
188 static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Trackdir trackdir, bool ignore_oneway = false)
189 {
190  TileIndex start_tile = tile;
191  Trackdir start_trackdir = trackdir;
192  bool first_loop = true;
193 
194  /* Start track not reserved? This can happen if two trains
195  * are on the same tile. The reservation on the next tile
196  * is not ours in this case, so exit. */
197  if (!HasReservedTracks(tile, TrackToTrackBits(TrackdirToTrack(trackdir)))) return PBSTileInfo(tile, trackdir, false);
198 
199  /* Do not disallow 90 deg turns as the setting might have changed between reserving and now. */
200  CFollowTrackRail ft(o, rts);
201  while (ft.Follow(tile, trackdir)) {
203 
204  /* No reservation --> path end found */
205  if (reserved == TRACKDIR_BIT_NONE) {
206  if (ft.m_is_station) {
207  /* Check skipped station tiles as well, maybe our reservation ends inside the station. */
209  while (ft.m_tiles_skipped-- > 0) {
210  ft.m_new_tile -= diff;
212  tile = ft.m_new_tile;
213  trackdir = DiagDirToDiagTrackdir(ft.m_exitdir);
214  break;
215  }
216  }
217  }
218  break;
219  }
220 
221  /* Can't have more than one reserved trackdir */
222  Trackdir new_trackdir = FindFirstTrackdir(reserved);
223 
224  /* One-way signal against us. The reservation can't be ours as it is not
225  * a safe position from our direction and we can never pass the signal. */
226  if (!ignore_oneway && HasOnewaySignalBlockingTrackdir(ft.m_new_tile, new_trackdir)) break;
227 
228  tile = ft.m_new_tile;
229  trackdir = new_trackdir;
230 
231  if (first_loop) {
232  /* Update the start tile after we followed the track the first
233  * time. This is necessary because the track follower can skip
234  * tiles (in stations for example) which means that we might
235  * never visit our original starting tile again. */
236  start_tile = tile;
237  start_trackdir = trackdir;
238  first_loop = false;
239  } else {
240  /* Loop encountered? */
241  if (tile == start_tile && trackdir == start_trackdir) break;
242  }
243  /* Depot tile? Can't continue. */
244  if (IsRailDepotTile(tile)) break;
245  /* Non-pbs signal? Reservation can't continue. */
246  if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) break;
247  }
248 
249  return PBSTileInfo(tile, trackdir, false);
250 }
251 
258 
260  FindTrainOnTrackInfo() : best(nullptr) {}
261 };
262 
264 static Vehicle *FindTrainOnTrackEnum(Vehicle *v, void *data)
265 {
267 
268  if (v->type != VEH_TRAIN || (v->vehstatus & VS_CRASHED)) return nullptr;
269 
270  Train *t = Train::From(v);
271  if (t->track == TRACK_BIT_WORMHOLE || HasBit((TrackBits)t->track, TrackdirToTrack(info->res.trackdir))) {
272  t = t->First();
273 
274  /* ALWAYS return the lowest ID (anti-desync!) */
275  if (info->best == nullptr || t->index < info->best->index) info->best = t;
276  return t;
277  }
278 
279  return nullptr;
280 }
281 
290 {
291  assert(v->type == VEH_TRAIN);
292 
293  TileIndex tile = v->tile;
294  Trackdir trackdir = v->GetVehicleTrackdir();
295 
296  if (IsRailDepotTile(tile) && !GetDepotReservationTrackBits(tile)) return PBSTileInfo(tile, trackdir, false);
297 
298  FindTrainOnTrackInfo ftoti;
299  ftoti.res = FollowReservation(v->owner, GetRailTypeInfo(v->railtype)->compatible_railtypes, tile, trackdir);
301  if (train_on_res != nullptr) {
303  if (ftoti.best != nullptr) *train_on_res = ftoti.best->First();
304  if (*train_on_res == nullptr && IsRailStationTile(ftoti.res.tile)) {
305  /* The target tile is a rail station. The track follower
306  * has stopped on the last platform tile where we haven't
307  * found a train. Also check all previous platform tiles
308  * for a possible train. */
310  for (TileIndex st_tile = ftoti.res.tile + diff; *train_on_res == nullptr && IsCompatibleTrainStationTile(st_tile, ftoti.res.tile); st_tile += diff) {
311  FindVehicleOnPos(st_tile, &ftoti, FindTrainOnTrackEnum);
312  if (ftoti.best != nullptr) *train_on_res = ftoti.best->First();
313  }
314  }
315  if (*train_on_res == nullptr && IsTileType(ftoti.res.tile, MP_TUNNELBRIDGE)) {
316  /* The target tile is a bridge/tunnel, also check the other end tile. */
318  if (ftoti.best != nullptr) *train_on_res = ftoti.best->First();
319  }
320  }
321  return ftoti.res;
322 }
323 
332 {
333  assert(HasReservedTracks(tile, TrackToTrackBits(track)));
334  Trackdir trackdir = TrackToTrackdir(track);
335 
337 
338  /* Follow the path from tile to both ends, one of the end tiles should
339  * have a train on it. We need FollowReservation to ignore one-way signals
340  * here, as one of the two search directions will be the "wrong" way. */
341  for (int i = 0; i < 2; ++i, trackdir = ReverseTrackdir(trackdir)) {
342  /* If the tile has a one-way block signal in the current trackdir, skip the
343  * search in this direction as the reservation can't come from this side.*/
344  if (HasOnewaySignalBlockingTrackdir(tile, ReverseTrackdir(trackdir)) && !HasPbsSignalOnTrackdir(tile, trackdir)) continue;
345 
346  FindTrainOnTrackInfo ftoti;
347  ftoti.res = FollowReservation(GetTileOwner(tile), rts, tile, trackdir, true);
348 
350  if (ftoti.best != nullptr) return ftoti.best;
351 
352  /* Special case for stations: check the whole platform for a vehicle. */
353  if (IsRailStationTile(ftoti.res.tile)) {
355  for (TileIndex st_tile = ftoti.res.tile + diff; IsCompatibleTrainStationTile(st_tile, ftoti.res.tile); st_tile += diff) {
356  FindVehicleOnPos(st_tile, &ftoti, FindTrainOnTrackEnum);
357  if (ftoti.best != nullptr) return ftoti.best;
358  }
359  }
360 
361  /* Special case for bridges/tunnels: check the other end as well. */
362  if (IsTileType(ftoti.res.tile, MP_TUNNELBRIDGE)) {
364  if (ftoti.best != nullptr) return ftoti.best;
365  }
366  }
367 
368  return nullptr;
369 }
370 
381 bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
382 {
383  if (IsRailDepotTile(tile)) return true;
384 
385  if (IsTileType(tile, MP_RAILWAY)) {
386  /* For non-pbs signals, stop on the signal tile. */
387  if (HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, TrackdirToTrack(trackdir)))) return true;
388  }
389 
390  /* Check next tile. For performance reasons, we check for 90 degree turns ourself. */
392 
393  /* End of track? */
394  if (!ft.Follow(tile, trackdir)) {
395  /* Last tile of a terminus station is a safe position. */
396  if (include_line_end) return true;
397  }
398 
399  /* Check for reachable tracks. */
402  if (ft.m_new_td_bits == TRACKDIR_BIT_NONE) return include_line_end;
403 
406  /* PBS signal on next trackdir? Safe position. */
407  if (HasPbsSignalOnTrackdir(ft.m_new_tile, td)) return true;
408  /* One-way PBS signal against us? Safe if end-of-line is allowed. */
410  GetSignalType(ft.m_new_tile, TrackdirToTrack(td)) == SIGTYPE_PBS_ONEWAY) {
411  return include_line_end;
412  }
413  }
414 
415  return false;
416 }
417 
427 bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
428 {
429  Track track = TrackdirToTrack(trackdir);
430  TrackBits reserved = GetReservedTrackbits(tile);
431 
432  /* Tile reserved? Can never be a free waiting position. */
433  if (TrackOverlapsTracks(reserved, track)) return false;
434 
435  /* Not reserved and depot or not a pbs signal -> free. */
436  if (IsRailDepotTile(tile)) return true;
437  if (IsTileType(tile, MP_RAILWAY) && HasSignalOnTrackdir(tile, trackdir) && !IsPbsSignal(GetSignalType(tile, track))) return true;
438 
439  /* Check the next tile, if it's a PBS signal, it has to be free as well. */
441 
442  if (!ft.Follow(tile, trackdir)) return true;
443 
444  /* Check for reachable tracks. */
447 
449 }
CFollowTrackT::m_is_station
bool m_is_station
last turn passed station
Definition: follow_track.hpp:48
FindFirstTrackdir
static Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR.
Definition: track_func.h:219
PBSTileInfo::okay
bool okay
True if tile is a safe waiting position, false otherwise.
Definition: pbs.h:29
TRACK_BIT_WORMHOLE
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
Definition: track_type.h:55
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
TILE_ADD
#define TILE_ADD(x, y)
Adds to tiles together.
Definition: map_func.h:244
HasReservedTracks
static bool HasReservedTracks(TileIndex tile, TrackBits tracks)
Check whether some of tracks is reserved on a tile.
Definition: pbs.h:58
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
newgrf_station.h
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
CFollowTrackT::m_old_tile
TileIndex m_old_tile
the origin (vehicle moved from) before move
Definition: follow_track.hpp:41
PathfinderSettings::forbid_90_deg
bool forbid_90_deg
forbid trains to make 90 deg turns
Definition: settings_type.h:439
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
SetRailStationPlatformReservation
void SetRailStationPlatformReservation(TileIndex start, DiagDirection dir, bool b)
Set the reservation for a complete station platform.
Definition: pbs.cpp:57
GetReservedTrackbits
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
Definition: pbs.cpp:24
DiagDirToAxis
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition: direction_func.h:214
SetRailStationReservation
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
Definition: station_map.h:405
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
IsRailStation
static bool IsRailStation(TileIndex t)
Is this station tile a rail station?
Definition: station_map.h:92
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
FollowTrainReservation
PBSTileInfo FollowTrainReservation(const Train *v, Vehicle **train_on_res)
Follow a train reservation to the last tile.
Definition: pbs.cpp:289
KillFirstBit
static T KillFirstBit(T value)
Clear the first bit in an integer.
Definition: bitmath_func.hpp:239
GetCrossingReservationTrackBits
static TrackBits GetCrossingReservationTrackBits(TileIndex t)
Get the reserved track bits for a rail crossing.
Definition: road_map.h:405
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
DiagDirToDiagTrackdir
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:545
IsCompatibleTrainStationTile
static bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
Check if a tile is a valid continuation to a railstation tile.
Definition: station_map.h:378
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:47
SetCrossingReservation
static void SetCrossingReservation(TileIndex t, bool b)
Set the reservation state of the rail crossing.
Definition: road_map.h:393
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
Rail90DegTurnDisallowed
static bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def=_settings_game.pf.forbid_90_deg)
Test if 90 degree turns are disallowed between two railtypes.
Definition: rail.h:354
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:283
Train::GetVehicleTrackdir
Trackdir GetVehicleTrackdir() const
Get the tracks of the train vehicle.
Definition: train_cmd.cpp:4019
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:48
IsRailDepot
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Definition: rail_map.h:95
IsLevelCrossing
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:84
HasPbsSignalOnTrackdir
static bool HasPbsSignalOnTrackdir(TileIndex tile, Trackdir td)
Is a pbs signal present along the trackdir?
Definition: rail_map.h:463
TrackToTrackBits
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:85
TryReserveRailTrack
bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations)
Try to reserve a specific track on a tile.
Definition: pbs.cpp:80
GetRailReservationTrackBits
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:194
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:590
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
GameSettings::pf
PathfinderSettings pf
settings for all pathfinders
Definition: settings_type.h:570
UnreserveRailTrack
void UnreserveRailTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
Definition: pbs.cpp:141
TriggerStationRandomisation
void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type)
Trigger station randomisation.
Definition: newgrf_station.cpp:966
IsWaitingPositionFree
bool IsWaitingPositionFree(const Train *v, TileIndex tile, Trackdir trackdir, bool forbid_90deg)
Check if a safe position is free.
Definition: pbs.cpp:427
IsBridgeTile
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
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
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:327
TileIndexDiff
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:154
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:240
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
TrackdirToExitdir
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:447
PBSTileInfo
This struct contains information about the end of a reserved path.
Definition: pbs.h:26
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
FollowReservation
static PBSTileInfo FollowReservation(Owner o, RailTypes rts, TileIndex tile, Trackdir trackdir, bool ignore_oneway=false)
Follow a reservation starting from a specific tile to the end.
Definition: pbs.cpp:188
FindTrainOnTrackInfo::res
PBSTileInfo res
Information about the track.
Definition: pbs.cpp:256
PBSTileInfo::trackdir
Trackdir trackdir
The reserved trackdir on the tile.
Definition: pbs.h:28
HasSignalOnTrackdir
static bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
Definition: rail_map.h:426
HasDepotReservation
static bool HasDepotReservation(TileIndex t)
Get the reservation state of the depot.
Definition: rail_map.h:258
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
TrackdirCrossesTrackdirs
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition: track_func.h:614
safeguards.h
IsRailDepotTile
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
Definition: rail_map.h:105
follow_track.hpp
Train
'Train' is either a loco or a wagon.
Definition: train.h:85
HasOnewaySignalBlockingTrackdir
static bool HasOnewaySignalBlockingTrackdir(TileIndex tile, Trackdir td)
Is a one-way signal blocking the trackdir? A one-way signal on the trackdir against will block,...
Definition: rail_map.h:475
HasStationReservation
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:393
IsSafeWaitingPosition
bool IsSafeWaitingPosition(const Train *v, TileIndex tile, Trackdir trackdir, bool include_line_end, bool forbid_90deg)
Determine whether a certain track on a tile is a safe position to end a path.
Definition: pbs.cpp:381
GetDepotReservationTrackBits
static TrackBits GetDepotReservationTrackBits(TileIndex t)
Get the reserved track bits for a depot.
Definition: rail_map.h:282
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:55
UpdateLevelCrossing
void UpdateLevelCrossing(TileIndex tile, bool sound=true)
Sets correct crossing state.
Definition: train_cmd.cpp:1686
HasCrossingReservation
static bool HasCrossingReservation(TileIndex t)
Get the reservation state of the rail crossing.
Definition: road_map.h:380
MarkBridgeDirty
void MarkBridgeDirty(TileIndex begin, TileIndex end, DiagDirection direction, uint bridge_height)
Mark bridge tiles dirty.
Definition: tunnelbridge_cmd.cpp:64
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
GUISettings::show_track_reservation
bool show_track_reservation
highlight reserved tracks.
Definition: settings_type.h:144
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
TrackOverlapsTracks
static bool TrackOverlapsTracks(TrackBits tracks, Track track)
Check if a given track is contained within or overlaps some other tracks.
Definition: track_func.h:670
SetDepotReservation
static void SetDepotReservation(TileIndex t, bool b)
Set the reservation state of the depot.
Definition: rail_map.h:270
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
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
GetTunnelBridgeReservationTrackBits
static TrackBits GetTunnelBridgeReservationTrackBits(TileIndex t)
Get the reserved track bits for a rail tunnel/bridge.
Definition: tunnelbridge_map.h:117
PBSTileInfo::tile
TileIndex tile
Tile the path ends, INVALID_TILE if no valid path was found.
Definition: pbs.h:27
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
vehicle_func.h
SIGTYPE_PBS_ONEWAY
@ SIGTYPE_PBS_ONEWAY
no-entry signal
Definition: signal_type.h:29
IsPlainRail
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Definition: rail_map.h:49
SpecializedVehicle< Train, Type >::From
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
GetRailStationAxis
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:337
UnreserveTrack
static void UnreserveTrack(TileIndex tile, Track t)
Lift the reservation of a specific track on a tile.
Definition: rail_map.h:244
SetTunnelBridgeReservation
static void SetTunnelBridgeReservation(TileIndex t, bool b)
Set the reservation state of the rail tunnel/bridge.
Definition: tunnelbridge_map.h:104
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1985
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:51
FindVehicleOnPos
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
Definition: vehicle.cpp:498
FindTrainOnTrackInfo::FindTrainOnTrackInfo
FindTrainOnTrackInfo()
Init the best location to nullptr always!
Definition: pbs.cpp:260
BarCrossing
static void BarCrossing(TileIndex t)
Bar a level crossing.
Definition: road_map.h:447
FindTrainOnTrackInfo::best
Train * best
The currently "best" vehicle we have found.
Definition: pbs.cpp:257
CFollowTrackT::m_new_tile
TileIndex m_new_tile
the new tile (the vehicle has entered)
Definition: follow_track.hpp:43
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
SRT_PATH_RESERVATION
@ SRT_PATH_RESERVATION
Trigger platform when train reserves path.
Definition: newgrf_station.h:109
CFollowTrackT::Follow
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
Definition: follow_track.hpp:119
RailtypeInfo::compatible_railtypes
RailTypes compatible_railtypes
bitmask to the OTHER railtypes on which an engine of THIS railtype can physically travel
Definition: rail.h:188
CFollowTrackT::m_exitdir
DiagDirection m_exitdir
exit direction (leaving the old tile)
Definition: follow_track.hpp:45
CFollowTrackT::m_new_td_bits
TrackdirBits m_new_td_bits
the new set of available trackdirs
Definition: follow_track.hpp:44
GetTileRailType
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
Definition: rail.cpp:155
GetOtherTunnelBridgeEnd
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:78
ReverseTrackdir
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:255
GetStationReservationTrackBits
static TrackBits GetStationReservationTrackBits(TileIndex t)
Get the reserved track bits for a waypoint.
Definition: station_map.h:417
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
FindTrainOnTrackEnum
static Vehicle * FindTrainOnTrackEnum(Vehicle *v, void *data)
Callback for Has/FindVehicleOnPos to find a train on a specific track.
Definition: pbs.cpp:264
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
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
SpecializedVehicle::First
T * First() const
Get the first vehicle in the chain.
Definition: vehicle_base.h:1059
FindTrainOnTrackInfo
Helper struct for finding the best matching vehicle on a specific track.
Definition: pbs.cpp:255
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
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
RailTypes
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:46
HasTrack
static bool HasTrack(TileIndex tile, Track track)
Returns whether the given track is present on the given tile.
Definition: rail_map.h:160
TryReserveTrack
static bool TryReserveTrack(TileIndex tile, Track t)
Try to reserve a specific track on a tile.
Definition: rail_map.h:226
CFollowTrackT
Track follower helper template class (can serve pathfinders and vehicle controllers).
Definition: follow_track.hpp:28
CFollowTrackT::m_tiles_skipped
int m_tiles_skipped
number of skipped tunnel or station tiles
Definition: follow_track.hpp:49
TrackdirToTrack
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:270
TrackToTrackdir
static Trackdir TrackToTrackdir(Track track)
Returns a Trackdir for the given Track.
Definition: track_func.h:287
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:581
GetTrainForReservation
Train * GetTrainForReservation(TileIndex tile, Track track)
Find the train which has reserved a specific path.
Definition: pbs.cpp:331