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