OpenTTD Source: src/track_func.h Source File

OpenTTD Source 1.11.0-RC1

track_func.h
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 TRACK_FUNC_H
11 #define TRACK_FUNC_H
12
13 #include "core/bitmath_func.hpp"
14 #include "track_type.h"
15 #include "direction_func.h"
16 #include "slope_func.h"
17
27 #define FOR_EACH_SET_TRACK(var, track_bits) FOR_EACH_SET_BIT_EX(Track, var, TrackBits, track_bits)
28
36 static inline bool IsValidTrack(Track track)
37 {
38 return track < TRACK_END;
39 }
40
48 static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
49 {
50 return trackdir < TRACKDIR_END;
51 }
52
60 static inline bool IsValidTrackdir(Trackdir trackdir)
61 {
62 return trackdir != INVALID_TRACKDIR && ((1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE);
63 }
64
74 static inline Track AxisToTrack(Axis a)
75 {
76 assert(IsValidAxis(a));
77 return (Track)a;
78 }
79
85 static inline TrackBits TrackToTrackBits(Track track)
86 {
87 assert(IsValidTrack(track));
88 return (TrackBits)(1 << track);
89 }
90
96 static inline TrackBits AxisToTrackBits(Axis a)
97 {
98 return TrackToTrackBits(AxisToTrack(a));
99 }
100
107 static inline TrackBits CornerToTrackBits(Corner corner)
108 {
109 extern const TrackBits _corner_to_trackbits[];
110 assert(IsValidCorner(corner));
111 return _corner_to_trackbits[corner];
112 }
113
119 static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
120 {
121 assert(IsValidTrackdir(trackdir));
122 return (TrackdirBits)(1 << trackdir);
123 }
124
139 static inline Track RemoveFirstTrack(TrackBits *tracks)
140 {
141 if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) {
142 assert((*tracks & ~TRACK_BIT_MASK) == TRACK_BIT_NONE);
143 Track first = (Track)FIND_FIRST_BIT(*tracks);
144 ClrBit(*tracks, first);
145 return first;
146 }
147 return INVALID_TRACK;
148 }
149
164 static inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
165 {
166 if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) {
167 assert((*trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
168 Trackdir first = (Trackdir)FindFirstBit2x64(*trackdirs);
169 ClrBit(*trackdirs, first);
170 return first;
171 }
172 return INVALID_TRACKDIR;
173 }
174
185 static inline Track FindFirstTrack(TrackBits tracks)
186 {
187 return (tracks != TRACK_BIT_NONE && tracks != INVALID_TRACK_BIT) ? (Track)FIND_FIRST_BIT(tracks) : INVALID_TRACK;
188 }
189
201 static inline Track TrackBitsToTrack(TrackBits tracks)
202 {
203 assert(tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KillFirstBit(tracks & TRACK_BIT_MASK) == TRACK_BIT_NONE));
204 return tracks != INVALID_TRACK_BIT ? (Track)FIND_FIRST_BIT(tracks & TRACK_BIT_MASK) : INVALID_TRACK;
205 }
206
219 static inline Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
220 {
221 assert((trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
222 return (trackdirs != TRACKDIR_BIT_NONE) ? (Trackdir)FindFirstBit2x64(trackdirs) : INVALID_TRACKDIR;
223 }
224
225 /*
226 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
227 * TrackdirBits, Direction and DiagDirections.
228 */
229
239 static inline Track TrackToOppositeTrack(Track t)
240 {
241 assert(IsValidTrack(t));
242 return (Track)(t ^ 1);
243 }
244
255 static inline Trackdir ReverseTrackdir(Trackdir trackdir)
256 {
257 assert(IsValidTrackdirForRoadVehicle(trackdir));
258 return (Trackdir)(trackdir ^ 8);
259 }
260
270 static inline Track TrackdirToTrack(Trackdir trackdir)
271 {
272 assert(IsValidTrackdir(trackdir));
273 return (Track)(trackdir & 0x7);
274 }
275
287 static inline Trackdir TrackToTrackdir(Track track)
288 {
289 assert(IsValidTrack(track));
290 return (Trackdir)track;
291 }
292
302 static inline TrackdirBits TrackToTrackdirBits(Track track)
303 {
304 Trackdir td = TrackToTrackdir(track);
305 return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
306 }
307
316 static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
317 {
318 return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK);
319 }
320
327 static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
328 {
329 return (TrackdirBits)(bits * 0x101);
330 }
331
337 static inline bool HasTrack(TrackBits tracks, Track track)
338 {
339 assert(IsValidTrack(track));
340 return HasBit(tracks, track);
341 }
342
348 static inline bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
349 {
350 assert(IsValidTrackdir(trackdir));
351 return HasBit(trackdirs, trackdir);
352 }
353
360 static inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
361 {
362 return (TrackdirBits)(ts & TRACKDIR_BIT_MASK);
363 }
364
371 static inline TrackBits TrackStatusToTrackBits(TrackStatus ts)
372 {
373 return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts));
374 }
375
384 static inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
385 {
386 return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK);
387 }
388
396 static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
397 {
398 return (TrackStatus)(trackdirbits | (red_signals << 16));
399 }
400
411 static inline Trackdir NextTrackdir(Trackdir trackdir)
412 {
413 assert(IsValidTrackdir(trackdir));
414 extern const Trackdir _next_trackdir[TRACKDIR_END];
415 return _next_trackdir[trackdir];
416 }
417
428 static inline TrackBits TrackCrossesTracks(Track track)
429 {
430 assert(IsValidTrack(track));
431 extern const TrackBits _track_crosses_tracks[TRACK_END];
432 return _track_crosses_tracks[track];
433 }
434
447 static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
448 {
449 assert(IsValidTrackdirForRoadVehicle(trackdir));
450 extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
451 return _trackdir_to_exitdir[trackdir];
452 }
453
469 static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
470 {
471 assert(IsValidTrack(track));
472 assert(IsValidDiagDirection(diagdir));
473 extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
474 return _track_exitdir_to_trackdir[track][diagdir];
475 }
476
494 static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
495 {
496 assert(IsValidTrack(track));
497 assert(IsValidDiagDirection(diagdir));
498 extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
499 return _track_enterdir_to_trackdir[track][diagdir];
500 }
501
506 static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
507 {
508 assert(IsValidTrack(track));
509 assert(IsValidDirection(dir));
510 extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
511 return _track_direction_to_trackdir[track][dir];
512 }
513
520 static inline Track DiagDirToDiagTrack(DiagDirection diagdir)
521 {
522 assert(IsValidDiagDirection(diagdir));
523 return (Track)(diagdir & 1);
524 }
525
532 static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
533 {
534 assert(IsValidDiagDirection(diagdir));
535 return TrackToTrackBits(DiagDirToDiagTrack(diagdir));
536 }
537
545 static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
546 {
547 assert(IsValidDiagDirection(diagdir));
548 extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
549 return _dir_to_diag_trackdir[diagdir];
550 }
551
563 static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
564 {
565 assert(IsValidDiagDirection(diagdir));
566 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
567 return _exitdir_reaches_trackdirs[diagdir];
568 }
569
581 static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
582
592 static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
593 {
594 assert(IsValidTrackdir(trackdir));
595 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
596 return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)];
597 }
598 /* Note that there is no direct table for this function (there used to be),
599 * but it uses two simpler tables to achieve the result */
600
614 static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
615 {
616 assert(IsValidTrackdirForRoadVehicle(trackdir));
617 extern const TrackdirBits _track_crosses_trackdirs[TRACK_END];
618 return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
619 }
620
627 static inline bool IsDiagonalTrack(Track track)
628 {
629 assert(IsValidTrack(track));
630 return (track == TRACK_X) || (track == TRACK_Y);
631 }
632
639 static inline bool IsDiagonalTrackdir(Trackdir trackdir)
640 {
641 assert(IsValidTrackdir(trackdir));
642 return IsDiagonalTrack(TrackdirToTrack(trackdir));
643 }
644
645
653 static inline bool TracksOverlap(TrackBits bits)
654 {
655 /* With no, or only one track, there is no overlap */
656 if (bits == TRACK_BIT_NONE || KillFirstBit(bits) == TRACK_BIT_NONE) return false;
657 /* We know that there are at least two tracks present. When there are more
658 * than 2 tracks, they will surely overlap. When there are two, they will
659 * always overlap unless they are lower & upper or right & left. */
660 return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
661 }
662
670 static inline bool TrackOverlapsTracks(TrackBits tracks, Track track)
671 {
672 if (HasBit(tracks, track)) return true;
673 return TracksOverlap(tracks | TrackToTrackBits(track));
674 }
675
681 static inline bool IsReversingRoadTrackdir(Trackdir dir)
682 {
683 assert(IsValidTrackdirForRoadVehicle(dir));
684 return (dir & 0x07) >= 6;
685 }
686
692 static inline bool IsStraightRoadTrackdir(Trackdir dir)
693 {
694 assert(IsValidTrackdirForRoadVehicle(dir));
695 return (dir & 0x06) == 0;
696 }
697
708 static inline bool IsUphillTrackdir(Slope slope, Trackdir dir)
709 {
710 assert(IsValidTrackdirForRoadVehicle(dir));
711 extern const TrackdirBits _uphill_trackdirs[];
712 return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir);
713 }
714
722 static inline DiagDirection VehicleExitDir(Direction direction, TrackBits track)
723 {
724 static const TrackBits state_dir_table[DIAGDIR_END] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER };
725
726 DiagDirection diagdir = DirToDiagDir(direction);
727
728 /* Determine the diagonal direction in which we will exit this tile */
729 if (!HasBit(direction, 0) && track != state_dir_table[diagdir]) {
730 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT);
731 }
732
733 return diagdir;
734 }
735
736 #endif /* TRACK_FUNC_H */
VehicleExitDir
static DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
Definition: track_func.h:722
TRACK_BIT_MASK
@ TRACK_BIT_MASK
Bitmask for the first 6 bits.
Definition: track_type.h:54
FindFirstTrackdir
static Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR.
Definition: track_func.h:219
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:39
IsValidAxis
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
RemoveFirstTrackdir
static Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
Removes first Trackdir from TrackdirBits and returns it.
Definition: track_func.h:164
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
AxisToTrackBits
static TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:96
TRACK_X
@ TRACK_X
Track along the x-axis (north-east to south-west)
Definition: track_type.h:21
KillFirstBit
static T KillFirstBit(T value)
Clear the first bit in an integer.
Definition: bitmath_func.hpp:239
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
DiagDirToDiagTrackdir
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:545
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
DIAGDIRDIFF_90LEFT
@ DIAGDIRDIFF_90LEFT
90 degrees left
Definition: direction_type.h:108
TracksOverlap
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:653
RemoveHalftileSlope
static Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
Definition: slope_func.h:60
IsValidDiagDirection
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition: direction_func.h:21
RemoveFirstTrack
static Track RemoveFirstTrack(TrackBits *tracks)
Removes first Track from TrackBits and returns it.
Definition: track_func.h:139
INVALID_TRACKDIR_BIT
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition: track_type.h:117
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition: track_type.h:42
TrackToTrackBits
static TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:85
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:45
bitmath_func.hpp
TRACK_BIT_VERT
@ TRACK_BIT_VERT
Left and right track.
Definition: track_type.h:48
TrackdirReachesTrackdirs
static TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile.
Definition: track_func.h:592
DirToDiagDir
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
TrackBitsToTrack
static Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:201
TRACK_Y
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition: track_type.h:22
AxisToTrack
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Definition: track_func.h:74
ChangeDiagDir
static DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
Definition: direction_func.h:149
IsValidTrack
static bool IsValidTrack(Track track)
Checks if a Track is valid.
Definition: track_func.h:36
slope_func.h
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:327
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
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
IsDiagonalTrack
static bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
Definition: track_func.h:627
TrackToOppositeTrack
static Track TrackToOppositeTrack(Track t)
Find the opposite track to a given track.
Definition: track_func.h:239
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
CornerToTrackBits
static TrackBits CornerToTrackBits(Corner corner)
Returns a single horizontal/vertical trackbit that is in a specific tile corner.
Definition: track_func.h:107
FindFirstBit2x64
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
Definition: bitmath_func.hpp:216
TrackExitdirToTrackdir
static Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
Maps a track and an (4-way) dir to the trackdir that represents the track with the exit in the given ...
Definition: track_func.h:469
DiagDirToDiagTrack
static Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track incidating with that diagdir.
Definition: track_func.h:520
TrackdirCrossesTrackdirs
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition: track_func.h:614
DiagdirReachesTracks
static TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:581
CombineTrackStatus
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:396
IsValidDirection
static bool IsValidDirection(Direction d)
Checks if an integer value is a valid Direction.
Definition: direction_func.h:32
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:89
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
IsValidTrackdirForRoadVehicle
static bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
Checks if a Trackdir is valid for road vehicles.
Definition: track_func.h:48
TRACK_BIT_LOWER
@ TRACK_BIT_LOWER
Lower track.
Definition: track_type.h:43
INVALID_TRACK_BIT
@ INVALID_TRACK_BIT
Flag for an invalid trackbits value.
Definition: track_type.h:57
TrackOverlapsTracks
static bool TrackOverlapsTracks(TrackBits tracks, Track track)
Check if a given track is contained within or overlaps some other tracks.
Definition: track_func.h:670
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
TRACK_END
@ TRACK_END
Used for iterations.
Definition: track_type.h:27
TRACK_BIT_HORZ
@ TRACK_BIT_HORZ
Upper and lower track.
Definition: track_type.h:47
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:102
IsValidCorner
static bool IsValidCorner(Corner corner)
Rangecheck for Corner enumeration.
Definition: slope_func.h:24
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition: track_type.h:44
DIR_END
@ DIR_END
Used to iterate.
Definition: direction_type.h:34
TrackToTrackdirBits
static TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
Definition: track_func.h:302
TrackStatusToRedSignals
static TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
Returns the red-signal-information of a TrackStatus.
Definition: track_func.h:384
TRACKDIR_END
@ TRACKDIR_END
Used for iterations.
Definition: track_type.h:88
TrackDirectionToTrackdir
static Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
Maps a track and a full (8-way) direction to the trackdir that represents the track running in the gi...
Definition: track_func.h:506
TrackStatusToTrackdirBits
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:360
IsUphillTrackdir
static bool IsUphillTrackdir(Slope slope, Trackdir dir)
Checks whether a trackdir on a specific slope is going uphill.
Definition: track_func.h:708
TrackEnterdirToTrackdir
static Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
Maps a track and an (4-way) dir to the trackdir that represents the track with the entry in the given...
Definition: track_func.h:494
FindFirstTrack
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:185
HasTrack
static bool HasTrack(TrackBits tracks, Track track)
Checks whether a TrackBits has a given Track.
Definition: track_func.h:337
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
DiagDirToDiagTrackBits
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:532
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:123
ReverseTrackdir
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:255
IsReversingRoadTrackdir
static bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
Definition: track_func.h:681
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
TRACKDIR_BIT_MASK
@ TRACKDIR_BIT_MASK
Bitmask for bit-operations.
Definition: track_type.h:116
NextTrackdir
static Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead.
Definition: track_func.h:411
TrackCrossesTracks
static TrackBits TrackCrossesTracks(Track track)
Maps a track to all tracks that make 90 deg turns with it.
Definition: track_func.h:428
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
HasTrackdir
static bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition: track_func.h:348
TrackdirBitsToTrackBits
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:316
FIND_FIRST_BIT
#define FIND_FIRST_BIT(x)
Returns the first non-zero bit in a 6-bit value (from right).
Definition: bitmath_func.hpp:200
IsValidTrackdir
static bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
Definition: track_func.h:60
IsStraightRoadTrackdir
static bool IsStraightRoadTrackdir(Trackdir dir)
Checks whether the given trackdir is a straight road.
Definition: track_func.h:692
track_type.h
direction_func.h
IsDiagonalTrackdir
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:639
TrackdirToTrack
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:270
TrackToTrackdir
static Trackdir TrackToTrackdir(Track track)
Returns a Trackdir for the given Track.
Definition: track_func.h:287
INVALID_TRACK
@ INVALID_TRACK
Flag for an invalid track.
Definition: track_type.h:28