269 * @return The TrackBits |
269 * @return The TrackBits |
270 */ |
270 */ |
271 static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) |
271 static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) |
272 { |
272 { |
273 return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK); |
273 return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK); |
|
274 } |
|
275 |
|
276 /** |
|
277 * Converts TrackBits to TrackdirBits while allowing both directions. |
|
278 * |
|
279 * @param bits The TrackBits |
|
280 * @return The TrackDirBits containing of bits in both directions. |
|
281 */ |
|
282 static inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits) |
|
283 { |
|
284 return (TrackdirBits)(bits * 0x101); |
|
285 } |
|
286 |
|
287 /** |
|
288 * Returns the present-trackdir-information of a TrackStatus. |
|
289 * |
|
290 * @param ts The TrackStatus returned by GetTileTrackStatus() |
|
291 * @return the present trackdirs |
|
292 */ |
|
293 static inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts) |
|
294 { |
|
295 return (TrackdirBits)(ts & TRACKDIR_BIT_MASK); |
|
296 } |
|
297 |
|
298 /** |
|
299 * Returns the present-track-information of a TrackStatus. |
|
300 * |
|
301 * @param ts The TrackStatus returned by GetTileTrackStatus() |
|
302 * @return the present tracks |
|
303 */ |
|
304 static inline TrackBits TrackStatusToTrackBits(TrackStatus ts) |
|
305 { |
|
306 return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts)); |
|
307 } |
|
308 |
|
309 /** |
|
310 * Returns the red-signal-information of a TrackStatus. |
|
311 * |
|
312 * Note: The result may contain red signals for non-present tracks. |
|
313 * |
|
314 * @param ts The TrackStatus returned by GetTileTrackStatus() |
|
315 * @return the The trackdirs that are blocked by red-signals |
|
316 */ |
|
317 static inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts) |
|
318 { |
|
319 return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK); |
|
320 } |
|
321 |
|
322 /** |
|
323 * Builds a TrackStatus |
|
324 * |
|
325 * @param trackdirbits present trackdirs |
|
326 * @param red_signals red signals |
|
327 * @return the TrackStatus representing the given information |
|
328 */ |
|
329 static inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals) |
|
330 { |
|
331 return (TrackStatus)(trackdirbits | (red_signals << 16)); |
274 } |
332 } |
275 |
333 |
276 /** |
334 /** |
277 * Maps a trackdir to the trackdir that you will end up on if you go straight |
335 * Maps a trackdir to the trackdir that you will end up on if you go straight |
278 * ahead. |
336 * ahead. |
514 static inline bool IsStraightRoadTrackdir(Trackdir dir) |
572 static inline bool IsStraightRoadTrackdir(Trackdir dir) |
515 { |
573 { |
516 return (dir & 0x06) == 0; |
574 return (dir & 0x06) == 0; |
517 } |
575 } |
518 |
576 |
|
577 /** |
|
578 * Checks whether a trackdir on a specific slope is going uphill. |
|
579 * |
|
580 * Valid for rail and road tracks. |
|
581 * Valid for tile-slopes (under foundation) and foundation-slopes (on foundation). |
|
582 * |
|
583 * @param slope The slope of the tile. |
|
584 * @param dir The trackdir of interest. |
|
585 * @return true iff the track goes upwards. |
|
586 */ |
|
587 static inline bool IsUphillTrackdir(Slope slope, Trackdir dir) |
|
588 { |
|
589 extern const TrackdirBits _uphill_trackdirs[]; |
|
590 return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir); |
|
591 } |
|
592 |
519 #endif /* TRACK_FUNC_H */ |
593 #endif /* TRACK_FUNC_H */ |