OpenTTD Source: src/track_func.h Source File

OpenTTD Source 13.1

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
18 using SetTrackBitIterator = SetBitIterator<Track, TrackBits>;
19
27 static inline bool IsValidTrack(Track track)
28 {
29 return track < TRACK_END;
30 }
31
39 static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
40 {
41 return trackdir < TRACKDIR_END;
42 }
43
51 static inline bool IsValidTrackdir(Trackdir trackdir)
52 {
53 return trackdir != INVALID_TRACKDIR && ((1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE);
54 }
55
65 static inline Track AxisToTrack(Axis a)
66 {
67 assert(IsValidAxis(a));
68 return (Track)a;
69 }
70
76 static inline TrackBits TrackToTrackBits(Track track)
77 {
78 assert(IsValidTrack(track));
79 return (TrackBits)(1 << track);
80 }
81
87 static inline TrackBits AxisToTrackBits(Axis a)
88 {
89 return TrackToTrackBits(AxisToTrack(a));
90 }
91
98 static inline TrackBits CornerToTrackBits(Corner corner)
99 {
100 extern const TrackBits _corner_to_trackbits[];
101 assert(IsValidCorner(corner));
102 return _corner_to_trackbits[corner];
103 }
104
110 static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
111 {
112 assert(IsValidTrackdir(trackdir));
113 return (TrackdirBits)(1 << trackdir);
114 }
115
130 static inline Track RemoveFirstTrack(TrackBits *tracks)
131 {
132 if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) {
133 assert((*tracks & ~TRACK_BIT_MASK) == TRACK_BIT_NONE);
134 Track first = (Track)FIND_FIRST_BIT(*tracks);
135 ClrBit(*tracks, first);
136 return first;
137 }
138 return INVALID_TRACK;
139 }
140
155 static inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
156 {
157 if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) {
158 assert((*trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
159 Trackdir first = (Trackdir)FindFirstBit2x64(*trackdirs);
160 ClrBit(*trackdirs, first);
161 return first;
162 }
163 return INVALID_TRACKDIR;
164 }
165
176 static inline Track FindFirstTrack(TrackBits tracks)
177 {
178 return (tracks != TRACK_BIT_NONE && tracks != INVALID_TRACK_BIT) ? (Track)FIND_FIRST_BIT(tracks) : INVALID_TRACK;
179 }
180
192 static inline Track TrackBitsToTrack(TrackBits tracks)
193 {
194 assert(tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KillFirstBit(tracks & TRACK_BIT_MASK) == TRACK_BIT_NONE));
195 return tracks != INVALID_TRACK_BIT ? (Track)FIND_FIRST_BIT(tracks & TRACK_BIT_MASK) : INVALID_TRACK;
196 }
197
210 static inline Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
211 {
212 assert((trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
213 return (trackdirs != TRACKDIR_BIT_NONE) ? (Trackdir)FindFirstBit2x64(trackdirs) : INVALID_TRACKDIR;
214 }
215
216 /*
217 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
218 * TrackdirBits, Direction and DiagDirections.
219 */
220
230 static inline Track TrackToOppositeTrack(Track t)
231 {
232 assert(IsValidTrack(t));
233 return (Track)(t ^ 1);
234 }
235
246 static inline Trackdir ReverseTrackdir(Trackdir trackdir)
247 {
248 assert(IsValidTrackdirForRoadVehicle(trackdir));
249 return (Trackdir)(trackdir ^ 8);
250 }
251
261 static inline Track TrackdirToTrack(Trackdir trackdir)
262 {
263 assert(IsValidTrackdir(trackdir));
264 return (Track)(trackdir & 0x7);
265 }
266
278 static inline Trackdir TrackToTrackdir(Track track)
279 {
280 assert(IsValidTrack(track));
281 return (Trackdir)track;
282 }
283
293 static inline TrackdirBits TrackToTrackdirBits(Track track)
294 {
295 Trackdir td = TrackToTrackdir(track);
296 return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
297 }
298
307 static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
308 {
309 return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK);
310 }
311
318 static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
319 {
320 return (TrackdirBits)(bits * 0x101);
321 }
322
328 static inline bool HasTrack(TrackBits tracks, Track track)
329 {
330 assert(IsValidTrack(track));
331 return HasBit(tracks, track);
332 }
333
339 static inline bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
340 {
341 assert(IsValidTrackdir(trackdir));
342 return HasBit(trackdirs, trackdir);
343 }
344
351 static inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
352 {
353 return (TrackdirBits)(ts & TRACKDIR_BIT_MASK);
354 }
355
362 static inline TrackBits TrackStatusToTrackBits(TrackStatus ts)
363 {
364 return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts));
365 }
366
375 static inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
376 {
377 return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK);
378 }
379
387 static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
388 {
389 return (TrackStatus)(trackdirbits | (red_signals << 16));
390 }
391
402 static inline Trackdir NextTrackdir(Trackdir trackdir)
403 {
404 assert(IsValidTrackdir(trackdir));
405 extern const Trackdir _next_trackdir[TRACKDIR_END];
406 return _next_trackdir[trackdir];
407 }
408
419 static inline TrackBits TrackCrossesTracks(Track track)
420 {
421 assert(IsValidTrack(track));
422 extern const TrackBits _track_crosses_tracks[TRACK_END];
423 return _track_crosses_tracks[track];
424 }
425
438 static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
439 {
440 assert(IsValidTrackdirForRoadVehicle(trackdir));
441 extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
442 return _trackdir_to_exitdir[trackdir];
443 }
444
460 static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
461 {
462 assert(IsValidTrack(track));
463 assert(IsValidDiagDirection(diagdir));
464 extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
465 return _track_exitdir_to_trackdir[track][diagdir];
466 }
467
485 static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
486 {
487 assert(IsValidTrack(track));
488 assert(IsValidDiagDirection(diagdir));
489 extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
490 return _track_enterdir_to_trackdir[track][diagdir];
491 }
492
497 static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
498 {
499 assert(IsValidTrack(track));
500 assert(IsValidDirection(dir));
501 extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
502 return _track_direction_to_trackdir[track][dir];
503 }
504
511 static inline Track DiagDirToDiagTrack(DiagDirection diagdir)
512 {
513 assert(IsValidDiagDirection(diagdir));
514 return (Track)(diagdir & 1);
515 }
516
523 static inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
524 {
525 assert(IsValidDiagDirection(diagdir));
526 return TrackToTrackBits(DiagDirToDiagTrack(diagdir));
527 }
528
536 static inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
537 {
538 assert(IsValidDiagDirection(diagdir));
539 extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
540 return _dir_to_diag_trackdir[diagdir];
541 }
542
554 static inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
555 {
556 assert(IsValidDiagDirection(diagdir));
557 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
558 return _exitdir_reaches_trackdirs[diagdir];
559 }
560
572 static inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
573
583 static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
584 {
585 assert(IsValidTrackdir(trackdir));
586 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
587 return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)];
588 }
589 /* Note that there is no direct table for this function (there used to be),
590 * but it uses two simpler tables to achieve the result */
591
605 static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
606 {
607 assert(IsValidTrackdirForRoadVehicle(trackdir));
608 extern const TrackdirBits _track_crosses_trackdirs[TRACK_END];
609 return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
610 }
611
618 static inline bool IsDiagonalTrack(Track track)
619 {
620 assert(IsValidTrack(track));
621 return (track == TRACK_X) || (track == TRACK_Y);
622 }
623
630 static inline bool IsDiagonalTrackdir(Trackdir trackdir)
631 {
632 assert(IsValidTrackdir(trackdir));
633 return IsDiagonalTrack(TrackdirToTrack(trackdir));
634 }
635
636
644 static inline bool TracksOverlap(TrackBits bits)
645 {
646 /* With no, or only one track, there is no overlap */
647 if (bits == TRACK_BIT_NONE || KillFirstBit(bits) == TRACK_BIT_NONE) return false;
648 /* We know that there are at least two tracks present. When there are more
649 * than 2 tracks, they will surely overlap. When there are two, they will
650 * always overlap unless they are lower & upper or right & left. */
651 return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
652 }
653
661 static inline bool TrackOverlapsTracks(TrackBits tracks, Track track)
662 {
663 if (HasBit(tracks, track)) return true;
664 return TracksOverlap(tracks | TrackToTrackBits(track));
665 }
666
672 static inline bool IsReversingRoadTrackdir(Trackdir dir)
673 {
674 assert(IsValidTrackdirForRoadVehicle(dir));
675 return (dir & 0x07) >= 6;
676 }
677
683 static inline bool IsStraightRoadTrackdir(Trackdir dir)
684 {
685 assert(IsValidTrackdirForRoadVehicle(dir));
686 return (dir & 0x06) == 0;
687 }
688
699 static inline bool IsUphillTrackdir(Slope slope, Trackdir dir)
700 {
701 assert(IsValidTrackdirForRoadVehicle(dir));
702 extern const TrackdirBits _uphill_trackdirs[];
703 return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir);
704 }
705
713 static inline DiagDirection VehicleExitDir(Direction direction, TrackBits track)
714 {
715 static const TrackBits state_dir_table[DIAGDIR_END] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER };
716
717 DiagDirection diagdir = DirToDiagDir(direction);
718
719 /* Determine the diagonal direction in which we will exit this tile */
720 if (!HasBit(direction, 0) && track != state_dir_table[diagdir]) {
721 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT);
722 }
723
724 return diagdir;
725 }
726
727 #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:713
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:210
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:155
TrackdirBits
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:125
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:87
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:536
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:109
TracksOverlap
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:644
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:130
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:76
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:45
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
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:583
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:192
TRACK_Y
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition: track_type.h:22
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:329
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:65
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:27
slope_func.h
TrackBitsToTrackdirBits
static TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:318
TrackStatusToTrackBits
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:362
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:438
IsDiagonalTrack
static bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
Definition: track_func.h:618
TrackToOppositeTrack
static Track TrackToOppositeTrack(Track t)
Find the opposite track to a given track.
Definition: track_func.h:230
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:98
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:460
DiagDirToDiagTrack
static Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track incidating with that diagdir.
Definition: track_func.h:511
TrackdirCrossesTrackdirs
static TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition: track_func.h:605
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:572
CombineTrackStatus
static TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:387
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
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:39
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:661
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:554
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:293
TrackStatusToRedSignals
static TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
Returns the red-signal-information of a TrackStatus.
Definition: track_func.h:375
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:497
TrackStatusToTrackdirBits
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:351
IsUphillTrackdir
static bool IsUphillTrackdir(Slope slope, Trackdir dir)
Checks whether a trackdir on a specific slope is going uphill.
Definition: track_func.h:699
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:485
FindFirstTrack
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:176
HasTrack
static bool HasTrack(TrackBits tracks, Track track)
Checks whether a TrackBits has a given Track.
Definition: track_func.h:328
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:110
DiagDirToDiagTrackBits
static TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:523
ReverseTrackdir
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:246
IsReversingRoadTrackdir
static bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
Definition: track_func.h:672
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:402
TrackCrossesTracks
static TrackBits TrackCrossesTracks(Track track)
Maps a track to all tracks that make 90 deg turns with it.
Definition: track_func.h:419
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:339
TrackdirBitsToTrackBits
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:307
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:51
IsStraightRoadTrackdir
static bool IsStraightRoadTrackdir(Trackdir dir)
Checks whether the given trackdir is a straight road.
Definition: track_func.h:683
track_type.h
direction_func.h
IsDiagonalTrackdir
static bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:630
TrackdirToTrack
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:261
TrackToTrackdir
static Trackdir TrackToTrackdir(Track track)
Returns a Trackdir for the given Track.
Definition: track_func.h:278
INVALID_TRACK
@ INVALID_TRACK
Flag for an invalid track.
Definition: track_type.h:28