OpenTTD Source: src/pathfinder/follow_track.hpp Source File

OpenTTD Source 14.0-RC3

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