OpenTTD
follow_track.hpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef FOLLOW_TRACK_HPP
13 #define FOLLOW_TRACK_HPP
14 
15 #include "../pbs.h"
16 #include "../roadveh.h"
17 #include "../station_base.h"
18 #include "../train.h"
19 #include "../tunnelbridge.h"
20 #include "../tunnelbridge_map.h"
21 #include "../depot_map.h"
22 #include "pf_performance_timer.hpp"
23 
29 template <TransportType Ttr_type_, typename VehicleType, bool T90deg_turns_allowed_ = true, bool Tmask_reserved_tracks = false>
31 {
32  enum ErrorCode {
33  EC_NONE,
34  EC_OWNER,
35  EC_RAIL_ROAD_TYPE,
36  EC_90DEG,
37  EC_NO_WAY,
38  EC_RESERVED,
39  };
40 
41  const VehicleType *m_veh;
48  bool m_is_tunnel;
49  bool m_is_bridge;
50  bool m_is_station;
52  ErrorCode m_err;
53  CPerformanceTimer *m_pPerf;
54  RailTypes m_railtypes;
55 
56  inline CFollowTrackT(const VehicleType *v = nullptr, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = nullptr)
57  {
58  Init(v, railtype_override, pPerf);
59  }
60 
61  inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = nullptr)
62  {
63  assert(IsRailTT());
64  m_veh = nullptr;
65  Init(o, railtype_override, pPerf);
66  }
67 
68  inline void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf)
69  {
70  assert(!IsRailTT() || (v != nullptr && v->type == VEH_TRAIN));
71  m_veh = v;
72  Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf);
73  }
74 
75  inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf)
76  {
77  assert(!IsRoadTT() || m_veh != nullptr);
78  assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES);
79  m_veh_owner = o;
80  m_pPerf = pPerf;
81  /* don't worry, all is inlined so compiler should remove unnecessary initializations */
82  m_old_tile = INVALID_TILE;
83  m_old_td = INVALID_TRACKDIR;
84  m_new_tile = INVALID_TILE;
85  m_new_td_bits = TRACKDIR_BIT_NONE;
86  m_exitdir = INVALID_DIAGDIR;
87  m_is_station = m_is_bridge = m_is_tunnel = false;
88  m_tiles_skipped = 0;
89  m_err = EC_NONE;
90  m_railtypes = railtype_override;
91  }
92 
93  inline static TransportType TT() { return Ttr_type_; }
94  inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; }
95  inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; }
96  inline bool IsTram() { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(m_veh)->roadtype); }
97  inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; }
98  inline static bool Allow90degTurns() { return T90deg_turns_allowed_; }
99  inline static bool DoTrackMasking() { return Tmask_reserved_tracks; }
100 
103  {
104  assert(IsTram()); // this function shouldn't be called in other cases
105 
106  if (IsNormalRoadTile(tile)) {
107  RoadBits rb = GetRoadBits(tile, RTT_TRAM);
108  switch (rb) {
109  case ROAD_NW: return DIAGDIR_NW;
110  case ROAD_SW: return DIAGDIR_SW;
111  case ROAD_SE: return DIAGDIR_SE;
112  case ROAD_NE: return DIAGDIR_NE;
113  default: break;
114  }
115  }
116  return INVALID_DIAGDIR;
117  }
118 
123  inline bool Follow(TileIndex old_tile, Trackdir old_td)
124  {
125  m_old_tile = old_tile;
126  m_old_td = old_td;
127  m_err = EC_NONE;
128  assert(
130  GetTileTrackStatus(m_old_tile, TT(), (IsRoadTT() && m_veh != nullptr) ? (this->IsTram() ? RTT_TRAM : RTT_ROAD) : 0)
131  ) & TrackdirToTrackdirBits(m_old_td)) != 0) ||
132  (IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR) // Disable the assertion for single tram bits
133  );
134  m_exitdir = TrackdirToExitdir(m_old_td);
135  if (ForcedReverse()) return true;
136  if (!CanExitOldTile()) return false;
137  FollowTileExit();
138  if (!QueryNewTileTrackStatus()) return TryReverse();
139  m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
140  if (m_new_td_bits == TRACKDIR_BIT_NONE || !CanEnterNewTile()) {
141  /* In case we can't enter the next tile, but are
142  * a normal road vehicle, then we can actually
143  * try to reverse as this is the end of the road.
144  * Trams can only turn on the appropriate bits in
145  * which case reaching this would mean a dead end
146  * near a building and in that case there would
147  * a "false" QueryNewTileTrackStatus result and
148  * as such reversing is already tried. The fact
149  * that function failed can have to do with a
150  * missing road bit, or inability to connect the
151  * different bits due to slopes. */
152  if (IsRoadTT() && !IsTram() && TryReverse()) return true;
153 
154  /* CanEnterNewTile already set a reason.
155  * Do NOT overwrite it (important for example for EC_RAIL_ROAD_TYPE).
156  * Only set a reason if CanEnterNewTile was not called */
157  if (m_new_td_bits == TRACKDIR_BIT_NONE) m_err = EC_NO_WAY;
158 
159  return false;
160  }
161  if ((!IsRailTT() && !Allow90degTurns()) || (IsRailTT() && Rail90DegTurnDisallowed(GetTileRailType(m_old_tile), GetTileRailType(m_new_tile), !Allow90degTurns()))) {
162  m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td);
163  if (m_new_td_bits == TRACKDIR_BIT_NONE) {
164  m_err = EC_90DEG;
165  return false;
166  }
167  }
168  return true;
169  }
170 
171  inline bool MaskReservedTracks()
172  {
173  if (!DoTrackMasking()) return true;
174 
175  if (m_is_station) {
176  /* Check skipped station tiles as well. */
177  TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
178  for (TileIndex tile = m_new_tile - diff * m_tiles_skipped; tile != m_new_tile; tile += diff) {
179  if (HasStationReservation(tile)) {
180  m_new_td_bits = TRACKDIR_BIT_NONE;
181  m_err = EC_RESERVED;
182  return false;
183  }
184  }
185  }
186 
187  TrackBits reserved = GetReservedTrackbits(m_new_tile);
188  /* Mask already reserved trackdirs. */
189  m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved);
190  /* Mask out all trackdirs that conflict with the reservation. */
191  Track t;
192  FOR_EACH_SET_TRACK(t, TrackdirBitsToTrackBits(m_new_td_bits)) {
193  if (TracksOverlap(reserved | TrackToTrackBits(t))) m_new_td_bits &= ~TrackToTrackdirBits(t);
194  }
195  if (m_new_td_bits == TRACKDIR_BIT_NONE) {
196  m_err = EC_RESERVED;
197  return false;
198  }
199  return true;
200  }
201 
202 protected:
204  inline void FollowTileExit()
205  {
206  m_is_station = m_is_bridge = m_is_tunnel = false;
207  m_tiles_skipped = 0;
208 
209  /* extra handling for tunnels and bridges in our direction */
210  if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
211  DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
212  if (enterdir == m_exitdir) {
213  /* we are entering the tunnel / bridge */
214  if (IsTunnel(m_old_tile)) {
215  m_is_tunnel = true;
216  m_new_tile = GetOtherTunnelEnd(m_old_tile);
217  } else { // IsBridge(m_old_tile)
218  m_is_bridge = true;
219  m_new_tile = GetOtherBridgeEnd(m_old_tile);
220  }
221  m_tiles_skipped = GetTunnelBridgeLength(m_new_tile, m_old_tile);
222  return;
223  }
224  assert(ReverseDiagDir(enterdir) == m_exitdir);
225  }
226 
227  /* normal or station tile, do one step */
228  m_new_tile = TileAddByDiagDir(m_old_tile, m_exitdir);
229 
230  /* special handling for stations */
231  if (IsRailTT() && HasStationTileRail(m_new_tile)) {
232  m_is_station = true;
233  } else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
234  m_is_station = true;
235  }
236  }
237 
240  {
241  CPerfStart perf(*m_pPerf);
242  if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
243  m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
244  } else {
245  m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() ? (this->IsTram() ? RTT_TRAM : RTT_ROAD) : 0));
246 
247  if (IsTram() && m_new_td_bits == TRACKDIR_BIT_NONE) {
248  /* GetTileTrackStatus() returns 0 for single tram bits.
249  * As we cannot change it there (easily) without breaking something, change it here */
250  switch (GetSingleTramBit(m_new_tile)) {
251  case DIAGDIR_NE:
252  case DIAGDIR_SW:
253  m_new_td_bits = TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW;
254  break;
255 
256  case DIAGDIR_NW:
257  case DIAGDIR_SE:
258  m_new_td_bits = TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_Y_SE;
259  break;
260 
261  default: break;
262  }
263  }
264  }
265  return (m_new_td_bits != TRACKDIR_BIT_NONE);
266  }
267 
269  inline bool CanExitOldTile()
270  {
271  /* road stop can be left at one direction only unless it's a drive-through stop */
272  if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
273  DiagDirection exitdir = GetRoadStopDir(m_old_tile);
274  if (exitdir != m_exitdir) {
275  m_err = EC_NO_WAY;
276  return false;
277  }
278  }
279 
280  /* single tram bits can only be left in one direction */
281  if (IsTram()) {
282  DiagDirection single_tram = GetSingleTramBit(m_old_tile);
283  if (single_tram != INVALID_DIAGDIR && single_tram != m_exitdir) {
284  m_err = EC_NO_WAY;
285  return false;
286  }
287  }
288 
289  /* road depots can be also left in one direction only */
290  if (IsRoadTT() && IsDepotTypeTile(m_old_tile, TT())) {
291  DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
292  if (exitdir != m_exitdir) {
293  m_err = EC_NO_WAY;
294  return false;
295  }
296  }
297  return true;
298  }
299 
301  inline bool CanEnterNewTile()
302  {
303  if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
304  /* road stop can be entered from one direction only unless it's a drive-through stop */
305  DiagDirection exitdir = GetRoadStopDir(m_new_tile);
306  if (ReverseDiagDir(exitdir) != m_exitdir) {
307  m_err = EC_NO_WAY;
308  return false;
309  }
310  }
311 
312  /* single tram bits can only be entered from one direction */
313  if (IsTram()) {
314  DiagDirection single_tram = GetSingleTramBit(m_new_tile);
315  if (single_tram != INVALID_DIAGDIR && single_tram != ReverseDiagDir(m_exitdir)) {
316  m_err = EC_NO_WAY;
317  return false;
318  }
319  }
320 
321  /* road and rail depots can also be entered from one direction only */
322  if (IsRoadTT() && IsDepotTypeTile(m_new_tile, TT())) {
323  DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
324  if (ReverseDiagDir(exitdir) != m_exitdir) {
325  m_err = EC_NO_WAY;
326  return false;
327  }
328  /* don't try to enter other company's depots */
329  if (GetTileOwner(m_new_tile) != m_veh_owner) {
330  m_err = EC_OWNER;
331  return false;
332  }
333  }
334  if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) {
335  DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
336  if (ReverseDiagDir(exitdir) != m_exitdir) {
337  m_err = EC_NO_WAY;
338  return false;
339  }
340  }
341 
342  /* rail transport is possible only on tiles with the same owner as vehicle */
343  if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh_owner) {
344  /* different owner */
345  m_err = EC_NO_WAY;
346  return false;
347  }
348 
349  /* rail transport is possible only on compatible rail types */
350  if (IsRailTT()) {
351  RailType rail_type = GetTileRailType(m_new_tile);
352  if (!HasBit(m_railtypes, rail_type)) {
353  /* incompatible rail type */
354  m_err = EC_RAIL_ROAD_TYPE;
355  return false;
356  }
357  }
358 
359  /* road transport is possible only on compatible road types */
360  if (IsRoadTT()) {
361  const RoadVehicle *v = RoadVehicle::From(m_veh);
362  RoadType roadtype = GetRoadType(m_new_tile, GetRoadTramType(v->roadtype));
363  if (!HasBit(v->compatible_roadtypes, roadtype)) {
364  /* incompatible road type */
365  m_err = EC_RAIL_ROAD_TYPE;
366  return false;
367  }
368  }
369 
370  /* tunnel holes and bridge ramps can be entered only from proper direction */
371  if (IsTileType(m_new_tile, MP_TUNNELBRIDGE)) {
372  if (IsTunnel(m_new_tile)) {
373  if (!m_is_tunnel) {
374  DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_new_tile);
375  if (tunnel_enterdir != m_exitdir) {
376  m_err = EC_NO_WAY;
377  return false;
378  }
379  }
380  } else { // IsBridge(m_new_tile)
381  if (!m_is_bridge) {
382  DiagDirection ramp_enderdir = GetTunnelBridgeDirection(m_new_tile);
383  if (ramp_enderdir != m_exitdir) {
384  m_err = EC_NO_WAY;
385  return false;
386  }
387  }
388  }
389  }
390 
391  /* special handling for rail stations - get to the end of platform */
392  if (IsRailTT() && m_is_station) {
393  /* entered railway station
394  * get platform length */
395  uint length = BaseStation::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
396  /* how big step we must do to get to the last platform tile; */
397  m_tiles_skipped = length - 1;
398  /* move to the platform end */
399  TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
400  diff *= m_tiles_skipped;
401  m_new_tile = TILE_ADD(m_new_tile, diff);
402  return true;
403  }
404 
405  return true;
406  }
407 
409  inline bool ForcedReverse()
410  {
411  /* rail and road depots cause reversing */
412  if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
413  DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
414  if (exitdir != m_exitdir) {
415  /* reverse */
416  m_new_tile = m_old_tile;
417  m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
418  m_exitdir = exitdir;
419  m_tiles_skipped = 0;
420  m_is_tunnel = m_is_bridge = m_is_station = false;
421  return true;
422  }
423  }
424 
425  /* Single tram bits and standard road stops cause reversing. */
426  if (IsRoadTT() && ((IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) ||
427  (IsStandardRoadStopTile(m_old_tile) && GetRoadStopDir(m_old_tile) == ReverseDiagDir(m_exitdir)))) {
428  /* reverse */
429  m_new_tile = m_old_tile;
430  m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
431  m_exitdir = ReverseDiagDir(m_exitdir);
432  m_tiles_skipped = 0;
433  m_is_tunnel = m_is_bridge = m_is_station = false;
434  return true;
435  }
436 
437  return false;
438  }
439 
441  inline bool TryReverse()
442  {
443  if (IsRoadTT() && !IsTram()) {
444  /* if we reached the end of road, we can reverse the RV and continue moving */
445  m_exitdir = ReverseDiagDir(m_exitdir);
446  /* new tile will be the same as old one */
447  m_new_tile = m_old_tile;
448  /* set new trackdir bits to all reachable trackdirs */
450  m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
451  if (m_new_td_bits != TRACKDIR_BIT_NONE) {
452  /* we have some trackdirs reachable after reversal */
453  return true;
454  }
455  }
456  m_err = EC_NO_WAY;
457  return false;
458  }
459 
460 public:
462  int GetSpeedLimit(int *pmin_speed = nullptr) const
463  {
464  int min_speed = 0;
465  int max_speed = INT_MAX; // no limit
466 
467  /* Check for on-bridge speed limit */
468  if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
469  int spd = GetBridgeSpec(GetBridgeType(m_old_tile))->speed;
470  if (IsRoadTT()) spd *= 2;
471  if (max_speed > spd) max_speed = spd;
472  }
473  /* Check for speed limit imposed by railtype */
474  if (IsRailTT()) {
475  uint16 rail_speed = GetRailTypeInfo(GetRailType(m_old_tile))->max_speed;
476  if (rail_speed > 0) max_speed = min(max_speed, rail_speed);
477  }
478 
479  /* if min speed was requested, return it */
480  if (pmin_speed != nullptr) *pmin_speed = min_speed;
481  return max_speed;
482  }
483 };
484 
488 
490 
493 
494 #endif /* FOLLOW_TRACK_HPP */
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:61
Owner
Enum for all companies/owners.
Definition: company_type.h:20
virtual uint GetPlatformLength(TileIndex tile) const =0
Obtain the length of a platform.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:306
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:103
No track build.
Definition: track_type.h:104
DiagDirection GetSingleTramBit(TileIndex tile)
Tests if a tile is a road tile with a single tramtrack (tram can reverse)
bool Follow(TileIndex old_tile, Trackdir old_td)
main follower routine.
TrackdirBits m_new_td_bits
the new set of available trackdirs
bool m_is_tunnel
last turn passed tunnel
An invalid owner.
Definition: company_type.h:31
const VehicleType * m_veh
moving vehicle
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:156
Train vehicle type.
Definition: vehicle_type.h:26
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:37
Northwest.
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:72
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
Definition: track_func.h:304
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
Transport over water.
South-west part.
Definition: road_type.h:58
static TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition: map_func.h:384
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition: bridge.h:48
TileIndex m_old_tile
the origin (vehicle moved from) before move
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Definition: road_map.h:567
Flag for an invalid DiagDirection.
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:565
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:225
bool m_is_station
last turn passed station
RoadType
The different roadtypes we support.
Definition: road_type.h:27
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:449
bool m_is_bridge
last turn passed bridge ramp
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Buses, trucks and trams belong to this class.
Definition: roadveh.h:109
RoadType roadtype
Roadtype of this vehicle.
Definition: roadveh.h:119
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
Southeast.
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:129
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:395
void FollowTileExit()
Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped.
bool CanExitOldTile()
return true if we can leave m_old_tile in m_exitdir
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
Definition: depot_map.h:20
static TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition: track_func.h:121
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
Definition: station_map.h:259
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:180
Invalid railtypes.
Definition: rail_type.h:58
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
Definition: rail_map.h:173
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:27
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:148
Track y-axis, direction south-east.
Definition: track_type.h:106
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:67
#define FOR_EACH_SET_TRACK(var, track_bits)
Iterate through each set Track in a TrackBits value.
Definition: track_func.h:29
Flag for an invalid trackdir.
Definition: track_type.h:91
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:55
Performance timer for pathfinders.
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:40
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:230
North-east part.
Definition: road_type.h:60
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:52
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
static bool IsPlainRailTile(TileIndex t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition: rail_map.h:62
Track follower helper template class (can serve pathfinders and vehicle controllers).
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:257
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:591
North-west part.
Definition: road_type.h:57
South-east part.
Definition: road_type.h:59
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:58
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:138
Transport by train.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:87
RailType GetTileRailType(TileIndex tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
Definition: rail.cpp:157
bool ForcedReverse()
return true if we must reverse (in depots and single tram bits)
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Definition: road_map.h:75
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Track
These are used to specify a single track.
Definition: track_type.h:21
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
Definition: pbs.cpp:26
TileIndex m_new_tile
the new tile (the vehicle has entered)
TransportType
Available types of transport.
Transport by road vehicle.
Track x-axis, direction south-west.
Definition: track_type.h:112
Track y-axis, direction north-west.
Definition: track_type.h:113
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:120
int GetSpeedLimit(int *pmin_speed=nullptr) const
Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td.
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
Definition: station_map.h:215
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
Definition: tunnel_map.cpp:24
DiagDirection m_exitdir
exit direction (leaving the old tile)
bool TryReverse()
return true if we successfully reversed at end of road/track
Trackdir m_old_td
the trackdir (the vehicle was on) before move
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:329
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Northeast, upper right on your monitor.
Owner m_veh_owner
owner of the vehicle
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:318
Track x-axis, direction north-east.
Definition: track_type.h:105
#define TILE_ADD(x, y)
Adds to tiles together.
Definition: map_func.h:246
int m_tiles_skipped
number of skipped tunnel or station tiles
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition: track_func.h:616
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:356
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:24
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:362
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:117
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:655
bool CanEnterNewTile()
return true if we can enter m_new_tile from m_exitdir
bool QueryNewTileTrackStatus()
stores track status (available trackdirs) for the new tile into m_new_td_bits
Southwest.