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/>.
8 /** @file track_func.h Different conversion functions from one kind of track to another. */
13 #include "core/bitmath_func.hpp"
14 #include "track_type.h"
15 #include "direction_func.h"
16 #include "slope_func.h"
19 * Iterate through each set Track in a TrackBits value.
20 * For more information see FOR_EACH_SET_BIT_EX.
22 * @param var Loop index variable that stores fallowing set track. Must be of type Track.
23 * @param track_bits The value to iterate through (any expression).
25 * @see FOR_EACH_SET_BIT_EX
27 #define FOR_EACH_SET_TRACK(var, track_bits) FOR_EACH_SET_BIT_EX(Track, var, TrackBits, track_bits)
30 * Checks if a Track is valid.
32 * @param track The value to check
33 * @return true if the given value is a valid track.
34 * @note Use this in an assert()
36 static inline bool IsValidTrack(Track track
)
38 return track
< TRACK_END
;
42 * Checks if a Trackdir is valid for road vehicles.
44 * @param trackdir The value to check
45 * @return true if the given value is a valid Trackdir
46 * @note Use this in an assert()
48 static inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir
)
50 return trackdir
< TRACKDIR_END
;
54 * Checks if a Trackdir is valid for non-road vehicles.
56 * @param trackdir The value to check
57 * @return true if the given value is a valid Trackdir
58 * @note Use this in an assert()
60 static inline bool IsValidTrackdir(Trackdir trackdir
)
62 return trackdir
!= INVALID_TRACKDIR
&& ((1 << trackdir
& TRACKDIR_BIT_MASK
) != TRACKDIR_BIT_NONE
);
66 * Convert an Axis to the corresponding Track
69 * Uses the fact that they share the same internal encoding
71 * @param a the axis to convert
72 * @return the track corresponding to the axis
74 static inline Track
AxisToTrack(Axis a
)
76 assert(IsValidAxis(a
));
81 * Maps a Track to the corresponding TrackBits value
82 * @param track the track to convert
83 * @return the converted TrackBits value of the track
85 static inline TrackBits
TrackToTrackBits(Track track
)
87 assert(IsValidTrack(track
));
88 return (TrackBits
)(1 << track
);
92 * Maps an Axis to the corresponding TrackBits value
93 * @param a the axis to convert
94 * @return the converted TrackBits value of the axis
96 static inline TrackBits
AxisToTrackBits(Axis a
)
98 return TrackToTrackBits(AxisToTrack(a
));
102 * Returns a single horizontal/vertical trackbit that is in a specific tile corner.
104 * @param corner The corner of a tile.
105 * @return The TrackBits of the track in the corner.
107 static inline TrackBits
CornerToTrackBits(Corner corner
)
109 extern const TrackBits _corner_to_trackbits
[];
110 assert(IsValidCorner(corner
));
111 return _corner_to_trackbits
[corner
];
115 * Maps a Trackdir to the corresponding TrackdirBits value
116 * @param trackdir the track direction to convert
117 * @return the converted TrackdirBits value
119 static inline TrackdirBits
TrackdirToTrackdirBits(Trackdir trackdir
)
121 assert(IsValidTrackdir(trackdir
));
122 return (TrackdirBits
)(1 << trackdir
);
126 * Removes first Track from TrackBits and returns it
128 * This function searches for the first bit in the TrackBits,
129 * remove this bit from the parameter and returns the found
130 * bit as Track value. It returns INVALID_TRACK if the
131 * parameter was TRACK_BIT_NONE or INVALID_TRACK_BIT. This
132 * is basically used in while-loops to get up to 6 possible
133 * tracks on a tile until the parameter becomes TRACK_BIT_NONE.
135 * @param tracks The value with the TrackBits
136 * @return The first Track from the TrackBits value
137 * @see FindFirstTrack
139 static inline Track
RemoveFirstTrack(TrackBits
*tracks
)
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
);
147 return INVALID_TRACK
;
151 * Removes first Trackdir from TrackdirBits and returns it
153 * This function searches for the first bit in the TrackdirBits parameter,
154 * remove this bit from the parameter and returns the fnound bit as
155 * Trackdir value. It returns INVALID_TRACKDIR if the trackdirs is
156 * TRACKDIR_BIT_NONE or INVALID_TRACKDIR_BIT. This is basically used in a
157 * while-loop to get all track-directions step by step until the value
158 * reaches TRACKDIR_BIT_NONE.
160 * @param trackdirs The value with the TrackdirBits
161 * @return The first Trackdir from the TrackdirBits value
162 * @see FindFirstTrackdir
164 static inline Trackdir
RemoveFirstTrackdir(TrackdirBits
*trackdirs
)
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
);
172 return INVALID_TRACKDIR
;
176 * Returns first Track from TrackBits or INVALID_TRACK
178 * This function returns the first Track found in the TrackBits value as Track-value.
179 * It returns INVALID_TRACK if the parameter is TRACK_BIT_NONE or INVALID_TRACK_BIT.
181 * @param tracks The TrackBits value
182 * @return The first Track found or INVALID_TRACK
183 * @see RemoveFirstTrack
185 static inline Track
FindFirstTrack(TrackBits tracks
)
187 return (tracks
!= TRACK_BIT_NONE
&& tracks
!= INVALID_TRACK_BIT
) ? (Track
)FIND_FIRST_BIT(tracks
) : INVALID_TRACK
;
191 * Converts TrackBits to Track.
193 * This function converts a TrackBits value to a Track value. As it
194 * is not possible to convert two or more tracks to one track the
195 * parameter must contain only one track or be the INVALID_TRACK_BIT value.
197 * @param tracks The TrackBits value to convert
198 * @return The Track from the value or INVALID_TRACK
199 * @pre tracks must contains only one Track or be INVALID_TRACK_BIT
201 static inline Track
TrackBitsToTrack(TrackBits tracks
)
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
;
208 * Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR
210 * This function returns the first Trackdir in the given TrackdirBits value or
211 * INVALID_TRACKDIR if the value is TRACKDIR_BIT_NONE. The TrackdirBits must
212 * not be INVALID_TRACKDIR_BIT.
214 * @param trackdirs The TrackdirBits value
215 * @return The first Trackdir from the TrackdirBits or INVALID_TRACKDIR on TRACKDIR_BIT_NONE.
216 * @pre trackdirs must not be INVALID_TRACKDIR_BIT
217 * @see RemoveFirstTrackdir
219 static inline Trackdir
FindFirstTrackdir(TrackdirBits trackdirs
)
221 assert((trackdirs
& ~TRACKDIR_BIT_MASK
) == TRACKDIR_BIT_NONE
);
222 return (trackdirs
!= TRACKDIR_BIT_NONE
) ? (Trackdir
)FindFirstBit2x64(trackdirs
) : INVALID_TRACKDIR
;
226 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
227 * TrackdirBits, Direction and DiagDirections.
231 * Find the opposite track to a given track.
233 * TRACK_LOWER -> TRACK_UPPER and vice versa, likewise for left/right.
234 * TRACK_X is mapped to TRACK_Y and reversed.
236 * @param t the track to convert
237 * @return the opposite track
239 static inline Track
TrackToOppositeTrack(Track t
)
241 assert(IsValidTrack(t
));
242 return (Track
)(t
^ 1);
246 * Maps a trackdir to the reverse trackdir.
248 * Returns the reverse trackdir of a Trackdir value. The reverse trackdir
249 * is the same track with the other direction on it.
251 * @param trackdir The Trackdir value
252 * @return The reverse trackdir
253 * @pre trackdir must not be INVALID_TRACKDIR
255 static inline Trackdir
ReverseTrackdir(Trackdir trackdir
)
257 assert(IsValidTrackdirForRoadVehicle(trackdir
));
258 return (Trackdir
)(trackdir
^ 8);
262 * Returns the Track that a given Trackdir represents
264 * This function filters the Track which is used in the Trackdir value and
265 * returns it as a Track value.
267 * @param trackdir The trackdir value
268 * @return The Track which is used in the value
270 static inline Track
TrackdirToTrack(Trackdir trackdir
)
272 assert(IsValidTrackdir(trackdir
));
273 return (Track
)(trackdir
& 0x7);
277 * Returns a Trackdir for the given Track
279 * Since every Track corresponds to two Trackdirs, we choose the
280 * one which points between NE and S. Note that the actual
281 * implementation is quite futile, but this might change
284 * @param track The given Track
285 * @return The Trackdir from the given Track
287 static inline Trackdir
TrackToTrackdir(Track track
)
289 assert(IsValidTrack(track
));
290 return (Trackdir
)track
;
294 * Returns a TrackdirBit mask from a given Track
296 * The TrackdirBit mask contains the two TrackdirBits that
297 * correspond with the given Track (one for each direction).
299 * @param track The track to get the TrackdirBits from
300 * @return The TrackdirBits which the selected tracks
302 static inline TrackdirBits
TrackToTrackdirBits(Track track
)
304 Trackdir td
= TrackToTrackdir(track
);
305 return (TrackdirBits
)(TrackdirToTrackdirBits(td
) | TrackdirToTrackdirBits(ReverseTrackdir(td
)));
309 * Discards all directional information from a TrackdirBits value
311 * Any Track which is present in either direction will be present in the result.
313 * @param bits The TrackdirBits to get the TrackBits from
314 * @return The TrackBits
316 static inline TrackBits
TrackdirBitsToTrackBits(TrackdirBits bits
)
318 return (TrackBits
)((bits
| (bits
>> 8)) & TRACK_BIT_MASK
);
322 * Converts TrackBits to TrackdirBits while allowing both directions.
324 * @param bits The TrackBits
325 * @return The TrackdirBits containing of bits in both directions.
327 static inline TrackdirBits
TrackBitsToTrackdirBits(TrackBits bits
)
329 return (TrackdirBits
)(bits
* 0x101);
333 * Checks whether a TrackBits has a given Track.
334 * @param tracks The track bits.
335 * @param track The track to check.
337 static inline bool HasTrack(TrackBits tracks
, Track track
)
339 assert(IsValidTrack(track
));
340 return HasBit(tracks
, track
);
344 * Checks whether a TrackdirBits has a given Trackdir.
345 * @param trackdirs The trackdir bits.
346 * @param trackdir The trackdir to check.
348 static inline bool HasTrackdir(TrackdirBits trackdirs
, Trackdir trackdir
)
350 assert(IsValidTrackdir(trackdir
));
351 return HasBit(trackdirs
, trackdir
);
355 * Returns the present-trackdir-information of a TrackStatus.
357 * @param ts The TrackStatus returned by GetTileTrackStatus()
358 * @return the present trackdirs
360 static inline TrackdirBits
TrackStatusToTrackdirBits(TrackStatus ts
)
362 return (TrackdirBits
)(ts
& TRACKDIR_BIT_MASK
);
366 * Returns the present-track-information of a TrackStatus.
368 * @param ts The TrackStatus returned by GetTileTrackStatus()
369 * @return the present tracks
371 static inline TrackBits
TrackStatusToTrackBits(TrackStatus ts
)
373 return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts
));
377 * Returns the red-signal-information of a TrackStatus.
379 * Note: The result may contain red signals for non-present tracks.
381 * @param ts The TrackStatus returned by GetTileTrackStatus()
382 * @return the The trackdirs that are blocked by red-signals
384 static inline TrackdirBits
TrackStatusToRedSignals(TrackStatus ts
)
386 return (TrackdirBits
)((ts
>> 16) & TRACKDIR_BIT_MASK
);
390 * Builds a TrackStatus
392 * @param trackdirbits present trackdirs
393 * @param red_signals red signals
394 * @return the TrackStatus representing the given information
396 static inline TrackStatus
CombineTrackStatus(TrackdirBits trackdirbits
, TrackdirBits red_signals
)
398 return (TrackStatus
)(trackdirbits
| (red_signals
<< 16));
402 * Maps a trackdir to the trackdir that you will end up on if you go straight
405 * This will be the same trackdir for diagonal trackdirs, but a
406 * different (alternating) one for straight trackdirs
408 * @param trackdir The given trackdir
409 * @return The next Trackdir value of the next tile.
411 static inline Trackdir
NextTrackdir(Trackdir trackdir
)
413 assert(IsValidTrackdir(trackdir
));
414 extern const Trackdir _next_trackdir
[TRACKDIR_END
];
415 return _next_trackdir
[trackdir
];
419 * Maps a track to all tracks that make 90 deg turns with it.
421 * For the diagonal directions these are the complement of the
422 * direction, for the straight directions these are the
423 * two vertical or horizontal tracks, depend on the given direction
425 * @param track The given track
426 * @return The TrackBits with the tracks marked which cross the given track by 90 deg.
428 static inline TrackBits
TrackCrossesTracks(Track track
)
430 assert(IsValidTrack(track
));
431 extern const TrackBits _track_crosses_tracks
[TRACK_END
];
432 return _track_crosses_tracks
[track
];
436 * Maps a trackdir to the (4-way) direction the tile is exited when following
439 * For the diagonal directions these are the same directions. For
440 * the straight directions these are the directions from the imagined
441 * base-tile to the bordering tile which will be joined if the given
442 * straight direction is leaved from the base-tile.
444 * @param trackdir The given track direction
445 * @return The direction which points to the resulting tile if following the Trackdir
447 static inline DiagDirection
TrackdirToExitdir(Trackdir trackdir
)
449 assert(IsValidTrackdirForRoadVehicle(trackdir
));
450 extern const DiagDirection _trackdir_to_exitdir
[TRACKDIR_END
];
451 return _trackdir_to_exitdir
[trackdir
];
455 * Maps a track and an (4-way) dir to the trackdir that represents the track
456 * with the exit in the given direction.
458 * For the diagonal tracks the resulting track direction are clear for a given
459 * DiagDirection. It either matches the direction or it returns INVALID_TRACKDIR,
460 * as a TRACK_X cannot be applied with DIAG_SE.
461 * For the straight tracks the resulting track direction will be the
462 * direction which the DiagDirection is pointing. But this will be INVALID_TRACKDIR
463 * if the DiagDirection is pointing 'away' the track.
465 * @param track The track to apply an direction on
466 * @param diagdir The DiagDirection to apply on
467 * @return The resulting track direction or INVALID_TRACKDIR if not possible.
469 static inline Trackdir
TrackExitdirToTrackdir(Track track
, DiagDirection diagdir
)
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
];
478 * Maps a track and an (4-way) dir to the trackdir that represents the track
479 * with the entry in the given direction.
481 * For the diagonal tracks the return value is clear, its either the matching
482 * track direction or INVALID_TRACKDIR.
483 * For the straight tracks this returns the track direction which results if
484 * you follow the DiagDirection and then turn by 45 deg left or right on the
485 * next tile. The new direction on the new track will be the returning Trackdir
486 * value. If the parameters makes no sense like the track TRACK_UPPER and the
487 * direction DIAGDIR_NE (target track cannot be reached) this function returns
490 * @param track The target track
491 * @param diagdir The direction to "come from"
492 * @return the resulting Trackdir or INVALID_TRACKDIR if not possible.
494 static inline Trackdir
TrackEnterdirToTrackdir(Track track
, DiagDirection diagdir
)
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
];
503 * Maps a track and a full (8-way) direction to the trackdir that represents
504 * the track running in the given direction.
506 static inline Trackdir
TrackDirectionToTrackdir(Track track
, Direction dir
)
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
];
515 * Maps a (4-way) direction to the diagonal track incidating with that diagdir
517 * @param diagdir The direction
518 * @return The resulting Track
520 static inline Track
DiagDirToDiagTrack(DiagDirection diagdir
)
522 assert(IsValidDiagDirection(diagdir
));
523 return (Track
)(diagdir
& 1);
527 * Maps a (4-way) direction to the diagonal track bits incidating with that diagdir
529 * @param diagdir The direction
530 * @return The resulting TrackBits
532 static inline TrackBits
DiagDirToDiagTrackBits(DiagDirection diagdir
)
534 assert(IsValidDiagDirection(diagdir
));
535 return TrackToTrackBits(DiagDirToDiagTrack(diagdir
));
539 * Maps a (4-way) direction to the diagonal trackdir that runs in that
542 * @param diagdir The direction
543 * @return The resulting Trackdir direction
545 static inline Trackdir
DiagDirToDiagTrackdir(DiagDirection diagdir
)
547 assert(IsValidDiagDirection(diagdir
));
548 extern const Trackdir _dir_to_diag_trackdir
[DIAGDIR_END
];
549 return _dir_to_diag_trackdir
[diagdir
];
553 * Returns all trackdirs that can be reached when entering a tile from a given
554 * (diagonal) direction.
556 * This will obviously include 90 degree turns, since no information is available
557 * about the exact angle of entering
559 * @param diagdir The joining direction
560 * @return The TrackdirBits which can be used from the given direction
561 * @see DiagdirReachesTracks
563 static inline TrackdirBits
DiagdirReachesTrackdirs(DiagDirection diagdir
)
565 assert(IsValidDiagDirection(diagdir
));
566 extern const TrackdirBits _exitdir_reaches_trackdirs
[DIAGDIR_END
];
567 return _exitdir_reaches_trackdirs
[diagdir
];
571 * Returns all tracks that can be reached when entering a tile from a given
572 * (diagonal) direction.
574 * This will obviously include 90 degree turns, since no
575 * information is available about the exact angle of entering
577 * @param diagdir The joining direction
578 * @return The tracks which can be used
579 * @see DiagdirReachesTrackdirs
581 static inline TrackBits
DiagdirReachesTracks(DiagDirection diagdir
) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir
)); }
584 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
585 * entering the next tile.
587 * This will include 90 degree turns!
589 * @param trackdir The track direction which will be leaved
590 * @return The track directions which can be used from this direction (in the next tile)
592 static inline TrackdirBits
TrackdirReachesTrackdirs(Trackdir trackdir
)
594 assert(IsValidTrackdir(trackdir
));
595 extern const TrackdirBits _exitdir_reaches_trackdirs
[DIAGDIR_END
];
596 return _exitdir_reaches_trackdirs
[TrackdirToExitdir(trackdir
)];
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 */
602 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
604 * For the diagonal tracks this returns the track direction bits
605 * of the other axis in both directions, which cannot be joined by
606 * the given track direction.
607 * For the straight tracks this returns all possible 90 deg turns
608 * either on the current tile (which no train can joined) or on the
611 * @param trackdir The track direction
612 * @return The TrackdirBits which are (more or less) 90 deg turns.
614 static inline TrackdirBits
TrackdirCrossesTrackdirs(Trackdir trackdir
)
616 assert(IsValidTrackdirForRoadVehicle(trackdir
));
617 extern const TrackdirBits _track_crosses_trackdirs
[TRACK_END
];
618 return _track_crosses_trackdirs
[TrackdirToTrack(trackdir
)];
622 * Checks if a given Track is diagonal
624 * @param track The given track to check
625 * @return true if diagonal, else false
627 static inline bool IsDiagonalTrack(Track track
)
629 assert(IsValidTrack(track
));
630 return (track
== TRACK_X
) || (track
== TRACK_Y
);
634 * Checks if a given Trackdir is diagonal.
636 * @param trackdir The given trackdir
637 * @return true if the trackdir use a diagonal track
639 static inline bool IsDiagonalTrackdir(Trackdir trackdir
)
641 assert(IsValidTrackdir(trackdir
));
642 return IsDiagonalTrack(TrackdirToTrack(trackdir
));
647 * Checks if the given tracks overlap, ie form a crossing. Basically this
648 * means when there is more than one track on the tile, except when there are
649 * two parallel tracks.
650 * @param bits The tracks present.
651 * @return Whether the tracks present overlap in any way.
653 static inline bool TracksOverlap(TrackBits bits
)
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
;
664 * Check if a given track is contained within or overlaps some other tracks.
666 * @param tracks Tracks to be tested against
667 * @param track The track to test
668 * @return true if the track is already in the tracks or overlaps the tracks.
670 static inline bool TrackOverlapsTracks(TrackBits tracks
, Track track
)
672 if (HasBit(tracks
, track
)) return true;
673 return TracksOverlap(tracks
| TrackToTrackBits(track
));
677 * Checks whether the trackdir means that we are reversing.
678 * @param dir the trackdir to check
679 * @return true if it is a reversing road trackdir
681 static inline bool IsReversingRoadTrackdir(Trackdir dir
)
683 assert(IsValidTrackdirForRoadVehicle(dir
));
684 return (dir
& 0x07) >= 6;
688 * Checks whether the given trackdir is a straight road
689 * @param dir the trackdir to check
690 * @return true if it is a straight road trackdir
692 static inline bool IsStraightRoadTrackdir(Trackdir dir
)
694 assert(IsValidTrackdirForRoadVehicle(dir
));
695 return (dir
& 0x06) == 0;
699 * Checks whether a trackdir on a specific slope is going uphill.
701 * Valid for rail and road tracks.
702 * Valid for tile-slopes (under foundation) and foundation-slopes (on foundation).
704 * @param slope The slope of the tile.
705 * @param dir The trackdir of interest.
706 * @return true iff the track goes upwards.
708 static inline bool IsUphillTrackdir(Slope slope
, Trackdir dir
)
710 assert(IsValidTrackdirForRoadVehicle(dir
));
711 extern const TrackdirBits _uphill_trackdirs
[];
712 return HasBit(_uphill_trackdirs
[RemoveHalftileSlope(slope
)], dir
);
716 * Determine the side in which the vehicle will leave the tile
718 * @param direction vehicle direction
719 * @param track vehicle track bits
720 * @return side of tile the vehicle will leave
722 static inline DiagDirection
VehicleExitDir(Direction direction
, TrackBits track
)
724 static const TrackBits state_dir_table
[DIAGDIR_END
] = { TRACK_BIT_RIGHT
, TRACK_BIT_LOWER
, TRACK_BIT_LEFT
, TRACK_BIT_UPPER
};
726 DiagDirection diagdir
= DirToDiagDir(direction
);
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
);
736 #endif /* TRACK_FUNC_H */