4 |
4 |
5 #ifndef RAIL_H |
5 #ifndef RAIL_H |
6 #define RAIL_H |
6 #define RAIL_H |
7 |
7 |
8 #include "direction.h" |
8 #include "direction.h" |
9 #include "rail_map.h" |
|
10 #include "tile.h" |
9 #include "tile.h" |
|
10 |
|
11 typedef enum RailTypes { |
|
12 RAILTYPE_RAIL = 0, |
|
13 RAILTYPE_ELECTRIC = 1, |
|
14 RAILTYPE_MONO = 2, |
|
15 RAILTYPE_MAGLEV = 3, |
|
16 RAILTYPE_END, |
|
17 INVALID_RAILTYPE = 0xFF |
|
18 } RailType; |
|
19 |
|
20 typedef byte RailTypeMask; |
|
21 |
|
22 |
|
23 /** These are used to specify a single track. |
|
24 * Can be translated to a trackbit with TrackToTrackbit */ |
|
25 typedef enum Track { |
|
26 TRACK_X = 0, |
|
27 TRACK_Y = 1, |
|
28 TRACK_UPPER = 2, |
|
29 TRACK_LOWER = 3, |
|
30 TRACK_LEFT = 4, |
|
31 TRACK_RIGHT = 5, |
|
32 TRACK_END, |
|
33 INVALID_TRACK = 0xFF |
|
34 } Track; |
|
35 |
|
36 |
|
37 /** Bitfield corresponding to Track */ |
|
38 typedef enum TrackBits { |
|
39 TRACK_BIT_NONE = 0U, |
|
40 TRACK_BIT_X = 1U << TRACK_X, |
|
41 TRACK_BIT_Y = 1U << TRACK_Y, |
|
42 TRACK_BIT_UPPER = 1U << TRACK_UPPER, |
|
43 TRACK_BIT_LOWER = 1U << TRACK_LOWER, |
|
44 TRACK_BIT_LEFT = 1U << TRACK_LEFT, |
|
45 TRACK_BIT_RIGHT = 1U << TRACK_RIGHT, |
|
46 TRACK_BIT_CROSS = TRACK_BIT_X | TRACK_BIT_Y, |
|
47 TRACK_BIT_HORZ = TRACK_BIT_UPPER | TRACK_BIT_LOWER, |
|
48 TRACK_BIT_VERT = TRACK_BIT_LEFT | TRACK_BIT_RIGHT, |
|
49 TRACK_BIT_3WAY_NE = TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT, |
|
50 TRACK_BIT_3WAY_SE = TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_RIGHT, |
|
51 TRACK_BIT_3WAY_SW = TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_LEFT, |
|
52 TRACK_BIT_3WAY_NW = TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_LEFT, |
|
53 TRACK_BIT_ALL = TRACK_BIT_CROSS | TRACK_BIT_HORZ | TRACK_BIT_VERT, |
|
54 TRACK_BIT_MASK = 0x3FU |
|
55 } TrackBits; |
|
56 |
11 |
57 |
12 /** These are a combination of tracks and directions. Values are 0-5 in one |
58 /** These are a combination of tracks and directions. Values are 0-5 in one |
13 direction (corresponding to the Track enum) and 8-13 in the other direction. */ |
59 direction (corresponding to the Track enum) and 8-13 in the other direction. */ |
14 typedef enum Trackdirs { |
60 typedef enum Trackdirs { |
15 TRACKDIR_X_NE = 0, |
61 TRACKDIR_X_NE = 0, |
324 static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); } |
370 static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); } |
325 |
371 |
326 /* Checks if a given Trackdir is diagonal. */ |
372 /* Checks if a given Trackdir is diagonal. */ |
327 static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); } |
373 static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); } |
328 |
374 |
329 /* |
|
330 * Functions quering signals on tiles. |
|
331 */ |
|
332 |
|
333 /** |
|
334 * Checks for the presence of signals (either way) on the given track on the |
|
335 * given rail tile. |
|
336 */ |
|
337 static inline bool HasSignalOnTrack(TileIndex tile, Track track) |
|
338 { |
|
339 assert(IsValidTrack(track)); |
|
340 return |
|
341 GetRailTileType(tile) == RAIL_TILE_SIGNALS && |
|
342 (_m[tile].m3 & SignalOnTrack(track)) != 0; |
|
343 } |
|
344 |
|
345 /** |
|
346 * Checks for the presence of signals along the given trackdir on the given |
|
347 * rail tile. |
|
348 * |
|
349 * Along meaning if you are currently driving on the given trackdir, this is |
|
350 * the signal that is facing us (for which we stop when it's red). |
|
351 */ |
|
352 static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir) |
|
353 { |
|
354 assert (IsValidTrackdir(trackdir)); |
|
355 return |
|
356 GetRailTileType(tile) == RAIL_TILE_SIGNALS && |
|
357 _m[tile].m3 & SignalAlongTrackdir(trackdir); |
|
358 } |
|
359 |
|
360 /** |
|
361 * Gets the state of the signal along the given trackdir. |
|
362 * |
|
363 * Along meaning if you are currently driving on the given trackdir, this is |
|
364 * the signal that is facing us (for which we stop when it's red). |
|
365 */ |
|
366 static inline SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir) |
|
367 { |
|
368 assert(IsValidTrackdir(trackdir)); |
|
369 assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir))); |
|
370 return _m[tile].m2 & SignalAlongTrackdir(trackdir) ? |
|
371 SIGNAL_STATE_GREEN : SIGNAL_STATE_RED; |
|
372 } |
|
373 |
|
374 |
|
375 /** |
|
376 * Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile. |
|
377 * Note that there is no check if the given trackdir is actually present on |
|
378 * the tile! |
|
379 * The given trackdir is used when there are (could be) multiple rail types on |
|
380 * one tile. |
|
381 */ |
|
382 RailType GetTileRailType(TileIndex tile, Trackdir trackdir); |
|
383 |
|
384 |
375 |
385 /** |
376 /** |
386 * Returns a pointer to the Railtype information for a given railtype |
377 * Returns a pointer to the Railtype information for a given railtype |
387 * @param railtype the rail type which the information is requested for |
378 * @param railtype the rail type which the information is requested for |
388 * @return The pointer to the RailtypeInfo |
379 * @return The pointer to the RailtypeInfo |