221 */ |
221 */ |
222 static inline WaypointID GetWaypointIndex(TileIndex t) |
222 static inline WaypointID GetWaypointIndex(TileIndex t) |
223 { |
223 { |
224 return (WaypointID)_m[t].m2; |
224 return (WaypointID)_m[t].m2; |
225 } |
225 } |
|
226 |
|
227 |
|
228 /** |
|
229 * Returns the reserved track bits of the tile |
|
230 * @pre IsPlainRailTile(t) |
|
231 * @param t the tile to query |
|
232 * @return the track bits |
|
233 */ |
|
234 static inline TrackBits GetTrackReservation(TileIndex t) |
|
235 { |
|
236 assert(IsPlainRailTile(t)); |
|
237 byte track_b = GB(_m[t].m2, 8, 3); |
|
238 Track track = (Track)(track_b - 1); // map array saves Track+1 |
|
239 if (track_b == 0) return TRACK_BIT_NONE; |
|
240 return (TrackBits)(TrackToTrackBits(track) | (HasBit(_m[t].m2, 11) ? TrackToTrackBits(TrackToOppositeTrack(track)) : 0)); |
|
241 } |
|
242 |
|
243 /** |
|
244 * Sets the reserved track bits of the tile |
|
245 * @pre IsPlainRailTile(t) && !TracksOverlap(b) |
|
246 * @param t the tile to change |
|
247 * @param b the track bits |
|
248 */ |
|
249 static inline void SetTrackReservation(TileIndex t, TrackBits b) |
|
250 { |
|
251 assert(IsPlainRailTile(t)); |
|
252 assert(b != INVALID_TRACK_BIT); |
|
253 assert(!TracksOverlap(b)); |
|
254 Track track = RemoveFirstTrack(&b); |
|
255 SB(_m[t].m2, 8, 3, track == INVALID_TRACK ? 0 : track+1); |
|
256 SB(_m[t].m2, 11, 1, (byte)(b != TRACK_BIT_NONE)); |
|
257 } |
|
258 |
|
259 /** |
|
260 * Get the reservation state of the waypoint or depot |
|
261 * @note Works for both waypoints and rail depots |
|
262 * @pre IsRailWaypoint(t) || IsRailDepot(t) |
|
263 * @param t the waypoint/depot tile |
|
264 * @return reservation state |
|
265 */ |
|
266 static inline bool GetDepotWaypointReservation(TileIndex t) |
|
267 { |
|
268 assert(IsRailWaypoint(t) || IsRailDepot(t)); |
|
269 return HasBit(_m[t].m5, 4); |
|
270 } |
|
271 |
|
272 /** |
|
273 * Set the reservation state of the waypoint or depot |
|
274 * @note Works for both waypoints and rail depots |
|
275 * @pre IsRailWaypoint(t) || IsRailDepot(t) |
|
276 * @param t the waypoint/depot tile |
|
277 * @param b the reservation state |
|
278 */ |
|
279 static inline void SetDepotWaypointReservation(TileIndex t, bool b) |
|
280 { |
|
281 assert(IsRailWaypoint(t) || IsRailDepot(t)); |
|
282 SB(_m[t].m5, 4, 1, (byte)b); |
|
283 } |
|
284 |
|
285 /** |
|
286 * Get the reserved track bits for a waypoint |
|
287 * @pre IsRailWaypoint(t) |
|
288 * @param t the tile |
|
289 * @return reserved track bits |
|
290 */ |
|
291 static inline TrackBits GetRailWaypointReservation(TileIndex t) |
|
292 { |
|
293 return GetDepotWaypointReservation(t) ? GetRailWaypointBits(t) : TRACK_BIT_NONE; |
|
294 } |
|
295 |
|
296 /** |
|
297 * Get the reserved track bits for a depot |
|
298 * @pre IsRailDepot(t) |
|
299 * @param t the tile |
|
300 * @return reserved track bits |
|
301 */ |
|
302 static inline TrackBits GetRailDepotReservation(TileIndex t) |
|
303 { |
|
304 return GetDepotWaypointReservation(t) ? TrackToTrackBits(GetRailDepotTrack(t)) : TRACK_BIT_NONE; |
|
305 } |
|
306 |
226 |
307 |
227 static inline SignalType GetSignalType(TileIndex t, Track track) |
308 static inline SignalType GetSignalType(TileIndex t, Track track) |
228 { |
309 { |
229 assert(GetRailTileType(t) == RAIL_TILE_SIGNALS); |
310 assert(GetRailTileType(t) == RAIL_TILE_SIGNALS); |
230 byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0; |
311 byte pos = (track == TRACK_LOWER || track == TRACK_RIGHT) ? 4 : 0; |