OpenTTD
follow_track.hpp
Go to the documentation of this file.
1 /* $Id: follow_track.hpp 27418 2015-10-30 16:18:03Z frosch $ */
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_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 = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
57  {
58  Init(v, railtype_override, pPerf);
59  }
60 
61  inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL)
62  {
63  m_veh = NULL;
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 != NULL && v->type == VEH_TRAIN));
70  m_veh = v;
71  Init(v != NULL ? 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 != NULL) && (!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() && HasBit(RoadVehicle::From(m_veh)->compatible_roadtypes, ROADTYPE_TRAM); }
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, ROADTYPE_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(((TrackStatusToTrackdirBits(GetTileTrackStatus(m_old_tile, TT(), IsRoadTT() ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0)) & TrackdirToTrackdirBits(m_old_td)) != 0) ||
127  (IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR)); // Disable the assertion for single tram bits
128  m_exitdir = TrackdirToExitdir(m_old_td);
129  if (ForcedReverse()) return true;
130  if (!CanExitOldTile()) return false;
131  FollowTileExit();
132  if (!QueryNewTileTrackStatus()) return TryReverse();
133  m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
134  if (m_new_td_bits == TRACKDIR_BIT_NONE || !CanEnterNewTile()) {
135  /* In case we can't enter the next tile, but are
136  * a normal road vehicle, then we can actually
137  * try to reverse as this is the end of the road.
138  * Trams can only turn on the appropriate bits in
139  * which case reaching this would mean a dead end
140  * near a building and in that case there would
141  * a "false" QueryNewTileTrackStatus result and
142  * as such reversing is already tried. The fact
143  * that function failed can have to do with a
144  * missing road bit, or inability to connect the
145  * different bits due to slopes. */
146  if (IsRoadTT() && !IsTram() && TryReverse()) return true;
147 
148  /* CanEnterNewTile already set a reason.
149  * Do NOT overwrite it (important for example for EC_RAIL_TYPE).
150  * Only set a reason if CanEnterNewTile was not called */
151  if (m_new_td_bits == TRACKDIR_BIT_NONE) m_err = EC_NO_WAY;
152 
153  return false;
154  }
155  if (!Allow90degTurns()) {
156  m_new_td_bits &= (TrackdirBits)~(int)TrackdirCrossesTrackdirs(m_old_td);
157  if (m_new_td_bits == TRACKDIR_BIT_NONE) {
158  m_err = EC_90DEG;
159  return false;
160  }
161  }
162  return true;
163  }
164 
165  inline bool MaskReservedTracks()
166  {
167  if (!DoTrackMasking()) return true;
168 
169  if (m_is_station) {
170  /* Check skipped station tiles as well. */
171  TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
172  for (TileIndex tile = m_new_tile - diff * m_tiles_skipped; tile != m_new_tile; tile += diff) {
173  if (HasStationReservation(tile)) {
174  m_new_td_bits = TRACKDIR_BIT_NONE;
175  m_err = EC_RESERVED;
176  return false;
177  }
178  }
179  }
180 
181  TrackBits reserved = GetReservedTrackbits(m_new_tile);
182  /* Mask already reserved trackdirs. */
183  m_new_td_bits &= ~TrackBitsToTrackdirBits(reserved);
184  /* Mask out all trackdirs that conflict with the reservation. */
185  Track t;
186  FOR_EACH_SET_TRACK(t, TrackdirBitsToTrackBits(m_new_td_bits)) {
187  if (TracksOverlap(reserved | TrackToTrackBits(t))) m_new_td_bits &= ~TrackToTrackdirBits(t);
188  }
189  if (m_new_td_bits == TRACKDIR_BIT_NONE) {
190  m_err = EC_RESERVED;
191  return false;
192  }
193  return true;
194  }
195 
196 protected:
198  inline void FollowTileExit()
199  {
200  m_is_station = m_is_bridge = m_is_tunnel = false;
201  m_tiles_skipped = 0;
202 
203  /* extra handling for tunnels and bridges in our direction */
204  if (IsTileType(m_old_tile, MP_TUNNELBRIDGE)) {
205  DiagDirection enterdir = GetTunnelBridgeDirection(m_old_tile);
206  if (enterdir == m_exitdir) {
207  /* we are entering the tunnel / bridge */
208  if (IsTunnel(m_old_tile)) {
209  m_is_tunnel = true;
210  m_new_tile = GetOtherTunnelEnd(m_old_tile);
211  } else { // IsBridge(m_old_tile)
212  m_is_bridge = true;
213  m_new_tile = GetOtherBridgeEnd(m_old_tile);
214  }
215  m_tiles_skipped = GetTunnelBridgeLength(m_new_tile, m_old_tile);
216  return;
217  }
218  assert(ReverseDiagDir(enterdir) == m_exitdir);
219  }
220 
221  /* normal or station tile, do one step */
222  TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
223  m_new_tile = TILE_ADD(m_old_tile, diff);
224 
225  /* special handling for stations */
226  if (IsRailTT() && HasStationTileRail(m_new_tile)) {
227  m_is_station = true;
228  } else if (IsRoadTT() && IsRoadStopTile(m_new_tile)) {
229  m_is_station = true;
230  } else {
231  m_is_station = false;
232  }
233  }
234 
237  {
238  CPerfStart perf(*m_pPerf);
239  if (IsRailTT() && IsPlainRailTile(m_new_tile)) {
240  m_new_td_bits = (TrackdirBits)(GetTrackBits(m_new_tile) * 0x101);
241  } else {
242  m_new_td_bits = TrackStatusToTrackdirBits(GetTileTrackStatus(m_new_tile, TT(), IsRoadTT() ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0));
243 
244  if (IsTram() && m_new_td_bits == 0) {
245  /* GetTileTrackStatus() returns 0 for single tram bits.
246  * As we cannot change it there (easily) without breaking something, change it here */
247  switch (GetSingleTramBit(m_new_tile)) {
248  case DIAGDIR_NE:
249  case DIAGDIR_SW:
250  m_new_td_bits = TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW;
251  break;
252 
253  case DIAGDIR_NW:
254  case DIAGDIR_SE:
255  m_new_td_bits = TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_Y_SE;
256  break;
257 
258  default: break;
259  }
260  }
261  }
262  return (m_new_td_bits != TRACKDIR_BIT_NONE);
263  }
264 
266  inline bool CanExitOldTile()
267  {
268  /* road stop can be left at one direction only unless it's a drive-through stop */
269  if (IsRoadTT() && IsStandardRoadStopTile(m_old_tile)) {
270  DiagDirection exitdir = GetRoadStopDir(m_old_tile);
271  if (exitdir != m_exitdir) {
272  m_err = EC_NO_WAY;
273  return false;
274  }
275  }
276 
277  /* single tram bits can only be left in one direction */
278  if (IsTram()) {
279  DiagDirection single_tram = GetSingleTramBit(m_old_tile);
280  if (single_tram != INVALID_DIAGDIR && single_tram != m_exitdir) {
281  m_err = EC_NO_WAY;
282  return false;
283  }
284  }
285 
286  /* road depots can be also left in one direction only */
287  if (IsRoadTT() && IsDepotTypeTile(m_old_tile, TT())) {
288  DiagDirection exitdir = GetRoadDepotDirection(m_old_tile);
289  if (exitdir != m_exitdir) {
290  m_err = EC_NO_WAY;
291  return false;
292  }
293  }
294  return true;
295  }
296 
298  inline bool CanEnterNewTile()
299  {
300  if (IsRoadTT() && IsStandardRoadStopTile(m_new_tile)) {
301  /* road stop can be entered from one direction only unless it's a drive-through stop */
302  DiagDirection exitdir = GetRoadStopDir(m_new_tile);
303  if (ReverseDiagDir(exitdir) != m_exitdir) {
304  m_err = EC_NO_WAY;
305  return false;
306  }
307  }
308 
309  /* single tram bits can only be entered from one direction */
310  if (IsTram()) {
311  DiagDirection single_tram = GetSingleTramBit(m_new_tile);
312  if (single_tram != INVALID_DIAGDIR && single_tram != ReverseDiagDir(m_exitdir)) {
313  m_err = EC_NO_WAY;
314  return false;
315  }
316  }
317 
318  /* road and rail depots can also be entered from one direction only */
319  if (IsRoadTT() && IsDepotTypeTile(m_new_tile, TT())) {
320  DiagDirection exitdir = GetRoadDepotDirection(m_new_tile);
321  if (ReverseDiagDir(exitdir) != m_exitdir) {
322  m_err = EC_NO_WAY;
323  return false;
324  }
325  /* don't try to enter other company's depots */
326  if (GetTileOwner(m_new_tile) != m_veh_owner) {
327  m_err = EC_OWNER;
328  return false;
329  }
330  }
331  if (IsRailTT() && IsDepotTypeTile(m_new_tile, TT())) {
332  DiagDirection exitdir = GetRailDepotDirection(m_new_tile);
333  if (ReverseDiagDir(exitdir) != m_exitdir) {
334  m_err = EC_NO_WAY;
335  return false;
336  }
337  }
338 
339  /* rail transport is possible only on tiles with the same owner as vehicle */
340  if (IsRailTT() && GetTileOwner(m_new_tile) != m_veh_owner) {
341  /* different owner */
342  m_err = EC_NO_WAY;
343  return false;
344  }
345 
346  /* rail transport is possible only on compatible rail types */
347  if (IsRailTT()) {
348  RailType rail_type = GetTileRailType(m_new_tile);
349  if (!HasBit(m_railtypes, rail_type)) {
350  /* incompatible rail type */
351  m_err = EC_RAIL_TYPE;
352  return false;
353  }
354  }
355 
356  /* tunnel holes and bridge ramps can be entered only from proper direction */
357  if (IsTileType(m_new_tile, MP_TUNNELBRIDGE)) {
358  if (IsTunnel(m_new_tile)) {
359  if (!m_is_tunnel) {
360  DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(m_new_tile);
361  if (tunnel_enterdir != m_exitdir) {
362  m_err = EC_NO_WAY;
363  return false;
364  }
365  }
366  } else { // IsBridge(m_new_tile)
367  if (!m_is_bridge) {
368  DiagDirection ramp_enderdir = GetTunnelBridgeDirection(m_new_tile);
369  if (ramp_enderdir != m_exitdir) {
370  m_err = EC_NO_WAY;
371  return false;
372  }
373  }
374  }
375  }
376 
377  /* special handling for rail stations - get to the end of platform */
378  if (IsRailTT() && m_is_station) {
379  /* entered railway station
380  * get platform length */
381  uint length = BaseStation::GetByTile(m_new_tile)->GetPlatformLength(m_new_tile, TrackdirToExitdir(m_old_td));
382  /* how big step we must do to get to the last platform tile; */
383  m_tiles_skipped = length - 1;
384  /* move to the platform end */
385  TileIndexDiff diff = TileOffsByDiagDir(m_exitdir);
386  diff *= m_tiles_skipped;
387  m_new_tile = TILE_ADD(m_new_tile, diff);
388  return true;
389  }
390 
391  return true;
392  }
393 
395  inline bool ForcedReverse()
396  {
397  /* rail and road depots cause reversing */
398  if (!IsWaterTT() && IsDepotTypeTile(m_old_tile, TT())) {
399  DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(m_old_tile) : GetRoadDepotDirection(m_old_tile);
400  if (exitdir != m_exitdir) {
401  /* reverse */
402  m_new_tile = m_old_tile;
403  m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
404  m_exitdir = exitdir;
405  m_tiles_skipped = 0;
406  m_is_tunnel = m_is_bridge = m_is_station = false;
407  return true;
408  }
409  }
410 
411  /* single tram bits cause reversing */
412  if (IsTram() && GetSingleTramBit(m_old_tile) == ReverseDiagDir(m_exitdir)) {
413  /* reverse */
414  m_new_tile = m_old_tile;
415  m_new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(m_old_td));
416  m_exitdir = ReverseDiagDir(m_exitdir);
417  m_tiles_skipped = 0;
418  m_is_tunnel = m_is_bridge = m_is_station = false;
419  return true;
420  }
421 
422  return false;
423  }
424 
426  inline bool TryReverse()
427  {
428  if (IsRoadTT() && !IsTram()) {
429  /* if we reached the end of road, we can reverse the RV and continue moving */
430  m_exitdir = ReverseDiagDir(m_exitdir);
431  /* new tile will be the same as old one */
432  m_new_tile = m_old_tile;
433  /* set new trackdir bits to all reachable trackdirs */
435  m_new_td_bits &= DiagdirReachesTrackdirs(m_exitdir);
436  if (m_new_td_bits != TRACKDIR_BIT_NONE) {
437  /* we have some trackdirs reachable after reversal */
438  return true;
439  }
440  }
441  m_err = EC_NO_WAY;
442  return false;
443  }
444 
445 public:
447  int GetSpeedLimit(int *pmin_speed = NULL) const
448  {
449  int min_speed = 0;
450  int max_speed = INT_MAX; // no limit
451 
452  /* Check for on-bridge speed limit */
453  if (!IsWaterTT() && IsBridgeTile(m_old_tile)) {
454  int spd = GetBridgeSpec(GetBridgeType(m_old_tile))->speed;
455  if (IsRoadTT()) spd *= 2;
456  if (max_speed > spd) max_speed = spd;
457  }
458  /* Check for speed limit imposed by railtype */
459  if (IsRailTT()) {
460  uint16 rail_speed = GetRailTypeInfo(GetRailType(m_old_tile))->max_speed;
461  if (rail_speed > 0) max_speed = min(max_speed, rail_speed);
462  }
463 
464  /* if min speed was requested, return it */
465  if (pmin_speed != NULL) *pmin_speed = min_speed;
466  return max_speed;
467  }
468 };
469 
473 
477 
480 
481 #endif /* FOLLOW_TRACK_HPP */
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:61
virtual uint GetPlatformLength(TileIndex tile) const =0
Obtain the length of a platform.
Invalid railtypes.
Definition: rail_type.h:58
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:296
RailTypes
The different roadtypes we support, but then a bitmask of them.
Definition: rail_type.h:52
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.
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
TrackdirBits m_new_td_bits
the new set of available trackdirs
bool m_is_tunnel
last turn passed tunnel
const VehicleType * m_veh
moving vehicle
Flag for an invalid DiagDirection.
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:156
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Track
These are used to specify a single track.
Definition: track_type.h:21
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
Definition: track_func.h:304
Transport over water.
South-west part.
Definition: road_type.h:58
static RoadBits GetRoadBits(TileIndex t, RoadType rt)
Get the present road bits for a specific road type.
Definition: road_map.h:111
Northeast, upper right on your monitor.
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:534
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:543
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:224
bool m_is_station
last turn passed station
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:427
bool m_is_bridge
last turn passed bridge ramp
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:41
Track x-axis, direction north-east.
Definition: track_type.h:108
int GetSpeedLimit(int *pmin_speed=NULL) const
Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td.
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 give tiletype.
Definition: tile_map.h:143
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:394
void FollowTileExit()
Follow the m_exitdir from m_old_tile and fill m_new_tile and m_tiles_skipped.
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
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:258
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:171
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
Definition: rail_map.h:172
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:26
Southeast.
Southwest.
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:147
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition: bridge.h:67
Trams.
Definition: road_type.h:25
#define FOR_EACH_SET_TRACK(var, track_bits)
Iterate through each set Track in a TrackBits value.
Definition: track_func.h:29
RoadBits
Enumeration for the road parts on a tile.
Definition: road_type.h:55
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:74
Performance timer for pathfinders.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:220
North-east part.
Definition: road_type.h:60
Northwest.
DiagDirection
Enumeration for diagonal directions.
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
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:61
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:509
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:56
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:137
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:57
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
Track x-axis, direction south-west.
Definition: track_type.h:115
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Track y-axis, direction north-west.
Definition: track_type.h:116
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.
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:106
static bool IsRoadStopTile(TileIndex t)
Is tile t a road stop station?
Definition: station_map.h:214
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
Track y-axis, direction south-east.
Definition: track_type.h:109
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
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
Owner m_veh_owner
owner of the vehicle
No track build.
Definition: track_type.h:107
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:318
Owner
Enum for all companies/owners.
Definition: company_type.h:20
Flag for an invalid trackdir.
Definition: track_type.h:93
#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:594
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:340
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:116
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:633
bool CanEnterNewTile()
return true if we can enter m_new_tile from m_exitdir
An invalid owner.
Definition: company_type.h:31
bool QueryNewTileTrackStatus()
stores track status (available trackdirs) for the new tile into m_new_td_bits
Train vehicle type.
Definition: vehicle_type.h:24