summaryrefslogtreecommitdiff
path: root/src/rail_map.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-02 22:48:01 +0000
committerrubidium <rubidium@openttd.org>2008-08-02 22:48:01 +0000
commitf6555cf6f81776fa4a09fab2091bbbe43972cddc (patch)
tree7f9e26ee10037396c79f0f24eb97c51d72db17e9 /src/rail_map.h
parent2bb88255388bedae0d94c9c06751ee8f140a9194 (diff)
downloadopenttd-f6555cf6f81776fa4a09fab2091bbbe43972cddc.tar.xz
(svn r13929) -Codechange [YAPP]: Reserving and unreserving of single tracks is now possible. (michi_cc)
Diffstat (limited to 'src/rail_map.h')
-rw-r--r--src/rail_map.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/rail_map.h b/src/rail_map.h
index 56eecc473..649e3baed 100644
--- a/src/rail_map.h
+++ b/src/rail_map.h
@@ -257,6 +257,39 @@ static inline void SetTrackReservation(TileIndex t, TrackBits b)
}
/**
+ * Try to reserve a specific track on a tile
+ * @pre IsPlainRailTile(t) && HasTrack(tile, t)
+ * @param tile the tile
+ * @param t the rack to reserve
+ * @return true if successful
+ */
+static inline bool TryReserveTrack(TileIndex tile, Track t)
+{
+ assert(HasTrack(tile, t));
+ TrackBits bits = TrackToTrackBits(t);
+ TrackBits res = GetTrackReservation(tile);
+ if ((res & bits) != TRACK_BIT_NONE) return false; // already reserved
+ res |= bits;
+ if (TracksOverlap(res)) return false; // crossing reservation present
+ SetTrackReservation(tile, res);
+ return true;
+}
+
+/**
+ * Lift the reservation of a specific track on a tile
+ * @pre IsPlainRailTile(t) && HasTrack(tile, t)
+ * @param tile the tile
+ * @param t the track to free
+ */
+static inline void UnreserveTrack(TileIndex tile, Track t)
+{
+ assert(HasTrack(tile, t));
+ TrackBits res = GetTrackReservation(tile);
+ res &= ~TrackToTrackBits(t);
+ SetTrackReservation(tile, res);
+}
+
+/**
* Get the reservation state of the waypoint or depot
* @note Works for both waypoints and rail depots
* @pre IsRailWaypoint(t) || IsRailDepot(t)