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