summaryrefslogtreecommitdiff
path: root/src/track_func.h
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2018-06-14 09:25:39 +0100
committerGitHub <noreply@github.com>2018-06-14 09:25:39 +0100
commitc2a77280842b5d752ef6c744adab20d9d1b67857 (patch)
tree1598d70926196cdaf99b64396a8624c1774411dc /src/track_func.h
parent7ae1e3e1e2a23b5cbd09bc88f9abd7ccdde23201 (diff)
downloadopenttd-c2a77280842b5d752ef6c744adab20d9d1b67857.tar.xz
Fix: Prevent ships moving into docks after finishing (un)loading. (#6791)
Diffstat (limited to 'src/track_func.h')
-rw-r--r--src/track_func.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/track_func.h b/src/track_func.h
index 68de827ef..5e1585c08 100644
--- a/src/track_func.h
+++ b/src/track_func.h
@@ -692,4 +692,25 @@ static inline bool IsUphillTrackdir(Slope slope, Trackdir dir)
return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir);
}
+/**
+ * Determine the side in which the vehicle will leave the tile
+ *
+ * @param direction vehicle direction
+ * @param track vehicle track bits
+ * @return side of tile the vehicle will leave
+ */
+static inline DiagDirection VehicleExitDir(Direction direction, TrackBits track)
+{
+ static const TrackBits state_dir_table[DIAGDIR_END] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER };
+
+ DiagDirection diagdir = DirToDiagDir(direction);
+
+ /* Determine the diagonal direction in which we will exit this tile */
+ if (!HasBit(direction, 0) && track != state_dir_table[diagdir]) {
+ diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT);
+ }
+
+ return diagdir;
+}
+
#endif /* TRACK_FUNC_H */