OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef FOLLOW_TRACK_HPP
11#define FOLLOW_TRACK_HPP
12
13#include "../bridge.h"
14#include "../pbs.h"
15#include "../roadveh.h"
16#include "../station_base.h"
17#include "../train.h"
18#include "../tunnelbridge.h"
19#include "../tunnelbridge_map.h"
20#include "../depot_map.h"
21#include "pathfinder_func.h"
22
28template <TransportType Ttr_type_, typename VehicleType, bool T90deg_turns_allowed_ = true, bool Tmask_reserved_tracks = false>
29struct CFollowTrackT {
31 enum class ErrorCode : uint8_t {
33 Owner,
38 };
39
41 Owner veh_owner;
47 bool is_tunnel;
48 bool is_bridge;
51 ErrorCode err;
52 RailTypes railtypes;
53
54 inline CFollowTrackT(const VehicleType *v = nullptr, RailTypes railtype_override = INVALID_RAILTYPES)
55 {
56 Init(v, railtype_override);
57 }
58
59 inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES)
60 {
61 assert(IsRailTT());
62 this->veh = nullptr;
63 Init(o, railtype_override);
64 }
65
66 inline void Init(const VehicleType *v, RailTypes railtype_override)
67 {
68 assert(!IsRailTT() || (v != nullptr && v->type == ::VehicleType::Train));
69 this->veh = v;
70 Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override);
71 }
72
73 inline void Init(Owner o, RailTypes railtype_override)
74 {
75 assert(!IsRoadTT() || this->veh != nullptr);
76 assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES);
77 this->veh_owner = o;
78 /* don't worry, all is inlined so compiler should remove unnecessary initializations */
79 this->old_tile = INVALID_TILE;
81 this->new_tile = INVALID_TILE;
82 this->new_td_bits.Reset();
84 this->is_station = false;
85 this->is_bridge = false;
86 this->is_tunnel = false;
87 this->tiles_skipped = 0;
88 this->err = ErrorCode::None;
89 this->railtypes = railtype_override;
90 }
91
92 [[debug_inline]] static inline TransportType TT() { return Ttr_type_; }
93 [[debug_inline]] static inline bool IsWaterTT() { return TT() == TransportType::Water; }
94 [[debug_inline]] static inline bool IsRailTT() { return TT() == TransportType::Rail; }
95 inline bool IsTram() { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(this->veh)->roadtype); }
96 [[debug_inline]] static inline bool IsRoadTT() { return TT() == TransportType::Road; }
97 static inline bool Allow90degTurns() { return T90deg_turns_allowed_; }
98 static inline bool DoTrackMasking() { return Tmask_reserved_tracks; }
99
106 {
107 assert(this->IsTram()); // this function shouldn't be called in other cases
108
109 if (IsNormalRoadTile(tile)) {
111 switch (rb.base()) {
112 case RoadBits{RoadBit::NW}.base(): return DiagDirection::NW;
113 case RoadBits{RoadBit::SW}.base(): return DiagDirection::SW;
114 case RoadBits{RoadBit::SE}.base(): return DiagDirection::SE;
115 case RoadBits{RoadBit::NE}.base(): return DiagDirection::NE;
116 default: break;
117 }
118 }
120 }
121
130 {
131 this->old_tile = old_tile;
132 this->old_td = old_td;
133 this->err = ErrorCode::None;
134
135 assert([&]() {
136 if (this->IsTram() && this->GetSingleTramBit(this->old_tile) != DiagDirection::Invalid) return true; // Skip the check for single tram bits
137 const RoadTramType sub_mode = (IsRoadTT() && this->veh != nullptr) ? (this->IsTram() ? RoadTramType::Tram : RoadTramType::Road) : RoadTramType::Invalid;
138 const TrackdirBits old_tile_valid_dirs = GetTileTrackStatus(this->old_tile, TT(), sub_mode).trackdirs;
139 return old_tile_valid_dirs.Any(TrackdirToTrackdirBits(this->old_td));
140 }());
141
142 this->exitdir = TrackdirToExitdir(this->old_td);
143 if (this->ForcedReverse()) return true;
144 if (!this->CanExitOldTile()) return false;
145 this->FollowTileExit();
146 if (!this->QueryNewTileTrackStatus()) return TryReverse();
147 this->new_td_bits &= DiagdirReachesTrackdirs(this->exitdir);
148 if (this->new_td_bits.None() || !this->CanEnterNewTile()) {
149 /* In case we can't enter the next tile, but are
150 * a normal road vehicle, then we can actually
151 * try to reverse as this is the end of the road.
152 * Trams can only turn on the appropriate bits in
153 * which case reaching this would mean a dead end
154 * near a building and in that case there would
155 * a "false" QueryNewTileTrackStatus result and
156 * as such reversing is already tried. The fact
157 * that function failed can have to do with a
158 * missing road bit, or inability to connect the
159 * different bits due to slopes. */
160 if (IsRoadTT() && !this->IsTram() && this->TryReverse()) return true;
161
162 /* CanEnterNewTile already set a reason.
163 * Do NOT overwrite it (important for example for ErrorCode::RailRoadType).
164 * Only set a reason if CanEnterNewTile was not called */
165 if (this->new_td_bits.None()) this->err = ErrorCode::NoWay;
166
167 return false;
168 }
169 if ((!IsRailTT() && !Allow90degTurns()) || (IsRailTT() && Rail90DegTurnDisallowed(GetTileRailType(this->old_tile), GetTileRailType(this->new_tile), !Allow90degTurns()))) {
170 this->new_td_bits.Reset(TrackdirCrossesTrackdirs(this->old_td));
171 if (this->new_td_bits.None()) {
172 this->err = ErrorCode::SharpTurn;
173 return false;
174 }
175 }
176 return true;
177 }
178
179 inline bool MaskReservedTracks()
180 {
181 if (!DoTrackMasking()) return true;
182
183 if (this->is_station) {
184 /* Check skipped station tiles as well. */
185 TileIndexDiff diff = TileOffsByDiagDir(this->exitdir);
186 for (TileIndex tile = this->new_tile - diff * this->tiles_skipped; tile != this->new_tile; tile += diff) {
187 if (HasStationReservation(tile)) {
188 this->new_td_bits.Reset();
189 this->err = ErrorCode::Reserved;
190 return false;
191 }
192 }
193 }
194
195 TrackBits reserved = GetReservedTrackbits(this->new_tile);
196 /* Mask already reserved trackdirs. */
197 this->new_td_bits.Reset(TrackBitsToTrackdirBits(reserved));
198 /* Mask out all trackdirs that conflict with the reservation. */
199 for (Track t : TrackdirBitsToTrackBits(this->new_td_bits)) {
200 if (TracksOverlap(reserved | t)) this->new_td_bits.Reset(TrackToTrackdirBits(t));
201 }
202 if (this->new_td_bits.None()) {
203 this->err = ErrorCode::Reserved;
204 return false;
205 }
206 return true;
207 }
208
209protected:
211 inline void FollowTileExit()
212 {
213 this->is_station = false;
214 this->is_bridge = false;
215 this->is_tunnel = false;
216 this->tiles_skipped = 0;
217
218 /* extra handling for tunnels and bridges in our direction */
219 if (IsTileType(this->old_tile, TileType::TunnelBridge)) {
220 DiagDirection enterdir = GetTunnelBridgeDirection(this->old_tile);
221 if (enterdir == this->exitdir) {
222 /* we are entering the tunnel / bridge */
223 if (IsTunnel(this->old_tile)) {
224 this->is_tunnel = true;
225 this->new_tile = GetOtherTunnelEnd(this->old_tile);
226 } else { // IsBridge(old_tile)
227 this->is_bridge = true;
228 this->new_tile = GetOtherBridgeEnd(this->old_tile);
229 }
230 this->tiles_skipped = GetTunnelBridgeLength(this->new_tile, this->old_tile);
231 return;
232 }
233 assert(ReverseDiagDir(enterdir) == this->exitdir);
234 }
235
236 /* normal or station tile, do one step */
237 this->new_tile = TileAddByDiagDir(this->old_tile, this->exitdir);
238
239 /* special handling for stations */
240 if (IsRailTT() && HasStationTileRail(this->new_tile)) {
241 this->is_station = true;
242 } else if (IsRoadTT() && IsStationRoadStopTile(this->new_tile)) {
243 this->is_station = true;
244 }
245 }
246
252 {
253 if (IsRailTT() && IsPlainRailTile(this->new_tile)) {
254 this->new_td_bits = TrackBitsToTrackdirBits(GetTrackBits(this->new_tile));
255 } else if (IsRoadTT()) {
256 this->new_td_bits = GetTrackdirBitsForRoad(this->new_tile, this->IsTram() ? RoadTramType::Tram : RoadTramType::Road);
257 } else {
258 this->new_td_bits = GetTileTrackStatus(this->new_tile, TT(), RoadTramType::Invalid).trackdirs;
259 }
260 return this->new_td_bits.Any();
261 }
262
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() && IsBayRoadStopTile(this->old_tile)) {
271 DiagDirection exitdir = GetBayRoadStopDir(this->old_tile);
272 if (exitdir != this->exitdir) {
273 this->err = ErrorCode::NoWay;
274 return false;
275 }
276 }
277
278 /* single tram bits can only be left in one direction */
279 if (this->IsTram()) {
280 DiagDirection single_tram = GetSingleTramBit(this->old_tile);
281 if (single_tram != DiagDirection::Invalid && single_tram != this->exitdir) {
282 this->err = ErrorCode::NoWay;
283 return false;
284 }
285 }
286
287 /* road depots can be also left in one direction only */
288 if (IsRoadTT() && IsDepotTypeTile(this->old_tile, TT())) {
290 if (exitdir != this->exitdir) {
291 this->err = ErrorCode::NoWay;
292 return false;
293 }
294 }
295 return true;
296 }
297
302 inline bool CanEnterNewTile()
303 {
304 if (IsRoadTT() && IsBayRoadStopTile(this->new_tile)) {
305 /* road stop can be entered from one direction only unless it's a drive-through stop */
306 DiagDirection exitdir = GetBayRoadStopDir(this->new_tile);
307 if (ReverseDiagDir(exitdir) != this->exitdir) {
308 this->err = ErrorCode::NoWay;
309 return false;
310 }
311 }
312
313 /* single tram bits can only be entered from one direction */
314 if (this->IsTram()) {
315 DiagDirection single_tram = this->GetSingleTramBit(this->new_tile);
316 if (single_tram != DiagDirection::Invalid && single_tram != ReverseDiagDir(this->exitdir)) {
317 this->err = ErrorCode::NoWay;
318 return false;
319 }
320 }
321
322 /* road and rail depots can also be entered from one direction only */
323 if (IsRoadTT() && IsDepotTypeTile(this->new_tile, TT())) {
325 if (ReverseDiagDir(exitdir) != this->exitdir) {
326 this->err = ErrorCode::NoWay;
327 return false;
328 }
329 /* don't try to enter other company's depots */
330 if (GetTileOwner(this->new_tile) != this->veh_owner) {
331 this->err = ErrorCode::Owner;
332 return false;
333 }
334 }
335 if (IsRailTT() && IsDepotTypeTile(this->new_tile, TT())) {
337 if (ReverseDiagDir(exitdir) != this->exitdir) {
338 this->err = ErrorCode::NoWay;
339 return false;
340 }
341 }
342
343 /* rail transport is possible only on tiles with the same owner as vehicle */
344 if (IsRailTT() && GetTileOwner(this->new_tile) != this->veh_owner) {
345 /* different owner */
346 this->err = ErrorCode::NoWay;
347 return false;
348 }
349
350 /* rail transport is possible only on compatible rail types */
351 if (IsRailTT() && this->railtypes.Any()) {
352 RailType rail_type = GetTileRailType(this->new_tile);
353 if (!this->railtypes.Test(rail_type)) {
354 /* incompatible rail type */
355 this->err = ErrorCode::RailRoadType;
356 return false;
357 }
358 }
359
360 /* road transport is possible only on compatible road types */
361 if (IsRoadTT()) {
362 const RoadVehicle *v = RoadVehicle::From(this->veh);
363 RoadType roadtype = GetRoadType(this->new_tile, GetRoadTramType(v->roadtype));
364 if (!v->compatible_roadtypes.Test(roadtype)) {
365 /* incompatible road type */
366 this->err = ErrorCode::RailRoadType;
367 return false;
368 }
369 }
370
371 /* tunnel holes and bridge ramps can be entered only from proper direction */
372 if (IsTileType(this->new_tile, TileType::TunnelBridge)) {
373 if (IsTunnel(this->new_tile)) {
374 if (!this->is_tunnel) {
375 DiagDirection tunnel_enterdir = GetTunnelBridgeDirection(this->new_tile);
376 if (tunnel_enterdir != this->exitdir) {
377 this->err = ErrorCode::NoWay;
378 return false;
379 }
380 }
381 } else { // IsBridge(new_tile)
382 if (!this->is_bridge) {
383 DiagDirection ramp_enderdir = GetTunnelBridgeDirection(this->new_tile);
384 if (ramp_enderdir != this->exitdir) {
385 this->err = ErrorCode::NoWay;
386 return false;
387 }
388 }
389 }
390 }
391
392 /* special handling for rail stations - get to the end of platform */
393 if (IsRailTT() && this->is_station) {
394 /* entered railway station
395 * get platform length */
396 uint length = BaseStation::GetByTile(this->new_tile)->GetPlatformLength(this->new_tile, TrackdirToExitdir(this->old_td));
397 /* how big step we must do to get to the last platform tile? */
398 this->tiles_skipped = length - 1;
399 /* move to the platform end */
400 TileIndexDiff diff = TileOffsByDiagDir(this->exitdir);
401 diff *= this->tiles_skipped;
402 this->new_tile = TileAdd(this->new_tile, diff);
403 return true;
404 }
405
406 return true;
407 }
408
413 inline bool ForcedReverse()
414 {
415 /* rail and road depots cause reversing */
416 if (!IsWaterTT() && IsDepotTypeTile(this->old_tile, TT())) {
417 DiagDirection exitdir = IsRailTT() ? GetRailDepotDirection(this->old_tile) : GetRoadDepotDirection(this->old_tile);
418 if (exitdir != this->exitdir) {
419 /* reverse */
420 this->new_tile = this->old_tile;
421 this->new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(this->old_td));
422 this->exitdir = exitdir;
423 this->tiles_skipped = 0;
424 this->is_tunnel = false;
425 this->is_bridge = false;
426 this->is_station = false;
427 return true;
428 }
429 }
430
431 /* Single tram bits and standard road stops cause reversing. */
432 if (IsRoadTT() && ((this->IsTram() && GetSingleTramBit(this->old_tile) == ReverseDiagDir(this->exitdir)) ||
433 (IsBayRoadStopTile(this->old_tile) && GetBayRoadStopDir(this->old_tile) == ReverseDiagDir(this->exitdir)))) {
434 /* reverse */
435 this->new_tile = this->old_tile;
436 this->new_td_bits = TrackdirToTrackdirBits(ReverseTrackdir(this->old_td));
437 this->exitdir = ReverseDiagDir(this->exitdir);
438 this->tiles_skipped = 0;
439 this->is_tunnel = false;
440 this->is_bridge = false;
441 this->is_station = false;
442 return true;
443 }
444
445 return false;
446 }
447
452 inline bool TryReverse()
453 {
454 if (IsRoadTT() && !this->IsTram()) {
455 /* if we reached the end of road, we can reverse the RV and continue moving */
456 this->exitdir = ReverseDiagDir(this->exitdir);
457 /* new tile will be the same as old one */
458 this->new_tile = this->old_tile;
459 /* set new trackdir bits to all reachable trackdirs */
461 this->new_td_bits &= DiagdirReachesTrackdirs(this->exitdir);
462 if (this->new_td_bits.Any()) {
463 /* we have some trackdirs reachable after reversal */
464 return true;
465 }
466 }
467 this->err = ErrorCode::NoWay;
468 return false;
469 }
470
471public:
477 int GetSpeedLimit(int *pmin_speed = nullptr) const
478 {
479 int min_speed = 0;
480 int max_speed = INT_MAX; // no limit
481
482 /* Check for on-bridge speed limit */
483 if (!IsWaterTT() && IsBridgeTile(this->old_tile)) {
484 int spd = GetBridgeSpec(GetBridgeType(this->old_tile))->speed;
485 if (IsRoadTT()) spd *= 2;
486 max_speed = std::min(max_speed, spd);
487 }
488 /* Check for speed limit imposed by railtype */
489 if (IsRailTT()) {
490 uint16_t rail_speed = GetRailTypeInfo(GetRailType(this->old_tile))->max_speed;
491 if (rail_speed > 0) max_speed = std::min<int>(max_speed, rail_speed);
492 }
493 if (IsRoadTT()) {
494 /* max_speed is already in roadvehicle units, no need to further modify (divide by 2) */
495 uint16_t road_speed = GetRoadTypeInfo(GetRoadType(this->old_tile, GetRoadTramType(RoadVehicle::From(this->veh)->roadtype)))->max_speed;
496 if (road_speed > 0) max_speed = std::min<int>(max_speed, road_speed);
497 }
498
499 /* if min speed was requested, return it */
500 if (pmin_speed != nullptr) *pmin_speed = min_speed;
501 return max_speed;
502 }
503};
504
508
509typedef CFollowTrackT<TransportType::Rail, Train, false> CFollowTrackRailNo90;
510
512typedef CFollowTrackT<TransportType::Rail, Train, false, true> CFollowTrackFreeRailNo90;
513
514#endif /* FOLLOW_TRACK_HPP */
Header file for bridges.
const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Definition bridge.h:63
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
BridgeType GetBridgeType(Tile t)
Determines the type of bridge on a tile.
Definition bridge_map.h:56
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr bool None() const
Test if none of the values are set.
constexpr Timpl & Reset()
Reset all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
Definition rail.h:239
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:118
static constexpr Owner INVALID_OWNER
An invalid owner.
Map related accessors for depots.
bool IsDepotTypeTile(Tile tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
Definition depot_map.h:22
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DiagDirection
Enumeration for diagonal directions.
@ Invalid
Flag for an invalid DiagDirection.
@ SW
Southwest.
@ NW
Northwest.
@ NE
Northeast, upper right on your monitor.
@ SE
Southeast.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, RoadTramType sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
Definition map_func.h:615
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
Definition map_func.h:461
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
General functions related to pathfinders.
TrackdirBits GetTrackdirBitsForRoad(TileIndex tile, RoadTramType rtt)
Wrapper around GetTileTrackStatus(), as for single tram bits GetTileTrackStatus() returns 0.
TrackBits GetReservedTrackbits(TileIndex t)
Get the reserved trackbits for any tile, regardless of type.
Definition pbs.cpp:24
PBS support routines.
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
Definition rail.cpp:39
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:430
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:320
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
static bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition rail_map.h:60
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
Definition rail_map.h:171
EnumBitSet< RailType, uint64_t > RailTypes
Bitset of RailType elements.
Definition rail_type.h:37
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:26
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
DiagDirection GetRoadDepotDirection(Tile t)
Get the direction of the exit of a road depot.
Definition road_map.h:576
RoadType GetRoadType(Tile t, RoadTramType rtt)
Get the road type for the given RoadTramType.
Definition road_map.h:175
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:58
EnumBitSet< RoadBit, uint8_t > RoadBits
Bitset of RoadBit elements.
Definition road_type.h:65
@ SW
South-west part.
Definition road_type.h:59
@ NW
North-west part.
Definition road_type.h:58
@ NE
North-east part.
Definition road_type.h:61
@ SE
South-east part.
Definition road_type.h:60
RoadType
The different roadtypes we support.
Definition road_type.h:24
RoadTramType
The different types of road type.
Definition road_type.h:38
@ Invalid
Invalid marker.
Definition road_type.h:42
@ Tram
Tram type.
Definition road_type.h:40
@ Road
Road type.
Definition road_type.h:39
Road vehicle states.
Base classes/functions for stations.
bool IsStationRoadStopTile(Tile t)
Is tile t a road stop station?
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
bool HasStationTileRail(Tile t)
Has this station tile a rail?
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
DiagDirection GetBayRoadStopDir(Tile t)
Gets the direction the bay road stop entrance points towards.
#define debug_inline
When making a (pure) debug build, the compiler will by default disable inlining of functions.
Definition stdafx.h:212
virtual uint GetPlatformLength(TileIndex tile) const =0
Obtain the length of a platform.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
uint16_t speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition bridge.h:41
Track follower helper template class (can serve pathfinders and vehicle controllers).
bool CanExitOldTile()
Check whether we can leave the old tile.
bool Follow(TileIndex old_tile, Trackdir old_td)
Main follower routine.
bool CanEnterNewTile()
Checks whether we can enter the next tile.
bool QueryNewTileTrackStatus()
Stores track status (available trackdirs) for the new tile into new_td_bits.
bool TryReverse()
Try whether we can reverse our road vehicle.
int GetSpeedLimit(int *pmin_speed=nullptr) const
Helper for pathfinders - get min/max speed on the old_tile/old_td.
bool ForcedReverse()
Are we forced to reverse the vehicle?
void FollowTileExit()
Follow the exitdir from old_tile and fill new_tile and tiles_skipped.
ErrorCode
Errors encountered when attempting to follow tracks.
@ SharpTurn
90 degree turn.
@ RailRoadType
Incompatible rail or road type.
@ Reserved
Path reserved track.
@ NoWay
Tile cannot be entered.
DiagDirection GetSingleTramBit(TileIndex tile)
Tests if a tile is a road tile with a single tramtrack (tram can reverse).
Buses, trucks and trams belong to this class.
Definition roadveh.h:105
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
Definition roadveh.h:117
RoadType roadtype
NOSAVE: Roadtype of this vehicle.
Definition roadveh.h:115
static Train * From(Vehicle *v)
TrackdirBits trackdirs
Trackdirs present on the tile.
Definition track_type.h:106
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition track_func.h:292
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition track_func.h:220
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition track_func.h:540
TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition track_func.h:501
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition track_func.h:450
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition track_func.h:86
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition track_func.h:343
TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
Definition track_func.h:267
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition track_func.h:281
EnumBitSet< Trackdir, uint16_t > TrackdirBits
Bitset of Trackdir elements.
Definition track_type.h:93
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
Definition track_type.h:43
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:63
@ Invalid
Flag for an invalid trackdir.
Definition track_type.h:82
Track
These are used to specify a single track.
Definition track_type.h:19
Base for the train class.
TransportType
Available types of transport.
@ Water
Transport over water.
@ Rail
Transport by train.
@ Road
Transport by road vehicle.
TileIndex GetOtherTunnelEnd(TileIndex tile)
Gets the other end of the tunnel.
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
Definition tunnel_map.h:23
Header file for things common for tunnels and bridges.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles).
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
VehicleType
Available vehicle types.
@ Train
Train vehicle type.