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. |