author | matthijs |
Wed, 22 Jun 2005 22:38:18 +0000 | |
changeset 1967 | c57192f4c121 |
parent 1950 | 6e4d384034d9 |
child 2001 | 480b824e27f0 |
permissions | -rw-r--r-- |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
1 |
#ifndef RAIL_H |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
2 |
#define RAIL_H |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
3 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
4 |
#include "tile.h" |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
5 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
6 |
/* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
7 |
* Some enums for accesing the map bytes for rail tiles |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
8 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
9 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
10 |
/* These types are used in the map5 byte for rail tiles. Use GetRailTileType() to |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
11 |
* get these values */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
12 |
typedef enum RailTileTypes { |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
13 |
RAIL_TYPE_NORMAL = 0x0, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
14 |
RAIL_TYPE_SIGNALS = 0x40, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
15 |
RAIL_TYPE_UNUSED = 0x80, /* XXX: Maybe this could become waypoints? */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
16 |
RAIL_TYPE_DEPOT_WAYPOINT = 0xC0, /* Is really depots and waypoints... */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
17 |
RAIL_TILE_TYPE_MASK = 0xC0, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
18 |
} RailTileType; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
19 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
20 |
enum { /* DEPRECATED TODO: Rewrite all uses of this */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
21 |
RAIL_TYPE_SPECIAL = 0x80, /* This used to say "If this bit is set, then it's |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
22 |
* not a regular track.", but currently, you |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
23 |
* should rather view map5[6..7] as one type, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
24 |
* containing a value from RailTileTypes above. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
25 |
* This value is only maintained for backwards |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
26 |
* compatibility */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
27 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
28 |
/* There used to be RAIL_BIT_* enums here, they moved to (for now) npf.c as |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
29 |
* TRACK_BIT_* */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
30 |
}; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
31 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
32 |
/* These subtypes are used in the map5 byte when the main rail type is |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
33 |
* RAIL_TYPE_DEPOT_WAYPOINT */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
34 |
typedef enum RailTileSubtypes { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
35 |
RAIL_SUBTYPE_DEPOT = 0x00, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
36 |
RAIL_SUBTYPE_WAYPOINT = 0x04, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
37 |
RAIL_SUBTYPE_MASK = 0x3C, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
38 |
} RailTileSubtype; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
39 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
40 |
typedef enum SignalTypes { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
41 |
/* Stored in _map3_hi[0..1] for MP_RAILWAY */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
42 |
SIGTYPE_NORMAL = 0, // normal signal |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
43 |
SIGTYPE_ENTRY = 1, // presignal block entry |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
44 |
SIGTYPE_EXIT = 2, // presignal block exit |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
45 |
SIGTYPE_COMBO = 3, // presignal inter-block |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
46 |
SIGTYPE_END, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
47 |
SIGTYPE_MASK = 3, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
48 |
} SignalType; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
49 |
|
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
50 |
typedef enum RailTypes { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
51 |
RAILTYPE_RAIL = 0, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
52 |
RAILTYPE_MONO = 1, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
53 |
RAILTYPE_MAGLEV = 2, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
54 |
RAILTYPE_END, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
55 |
RAILTYPE_MASK = 0x3, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
56 |
INVALID_RAILTYPE = 0xFF, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
57 |
} RailType; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
58 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
59 |
enum { |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
60 |
SIG_SEMAPHORE_MASK = 4, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
61 |
}; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
62 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
63 |
/* These are used to specify a single track. Can be translated to a trackbit |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
64 |
* with TrackToTrackbit */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
65 |
typedef enum Tracks { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
66 |
TRACK_DIAG1 = 0, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
67 |
TRACK_DIAG2 = 1, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
68 |
TRACK_UPPER = 2, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
69 |
TRACK_LOWER = 3, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
70 |
TRACK_LEFT = 4, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
71 |
TRACK_RIGHT = 5, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
72 |
TRACK_END, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
73 |
INVALID_TRACK = 0xFF, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
74 |
} Track; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
75 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
76 |
/* These are the bitfield variants of the above */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
77 |
typedef enum TrackBits { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
78 |
TRACK_BIT_DIAG1 = 1, // 0 |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
79 |
TRACK_BIT_DIAG2 = 2, // 1 |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
80 |
TRACK_BIT_UPPER = 4, // 2 |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
81 |
TRACK_BIT_LOWER = 8, // 3 |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
82 |
TRACK_BIT_LEFT = 16, // 4 |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
83 |
TRACK_BIT_RIGHT = 32, // 5 |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
84 |
TRACK_BIT_MASK = 0x3F, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
85 |
} TrackBits; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
86 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
87 |
/* These are a combination of tracks and directions. Values are 0-5 in one |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
88 |
direction (corresponding to the Track enum) and 8-13 in the other direction. */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
89 |
typedef enum Trackdirs { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
90 |
TRACKDIR_DIAG1_NE = 0, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
91 |
TRACKDIR_DIAG2_SE = 1, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
92 |
TRACKDIR_UPPER_E = 2, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
93 |
TRACKDIR_LOWER_E = 3, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
94 |
TRACKDIR_LEFT_S = 4, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
95 |
TRACKDIR_RIGHT_S = 5, |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
96 |
/* Note the two missing values here. This enables trackdir -> track |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
97 |
* conversion by doing (trackdir & 7) */ |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
98 |
TRACKDIR_DIAG1_SW = 8, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
99 |
TRACKDIR_DIAG2_NW = 9, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
100 |
TRACKDIR_UPPER_W = 10, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
101 |
TRACKDIR_LOWER_W = 11, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
102 |
TRACKDIR_LEFT_N = 12, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
103 |
TRACKDIR_RIGHT_N = 13, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
104 |
TRACKDIR_END, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
105 |
INVALID_TRACKDIR = 0xFF, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
106 |
} Trackdir; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
107 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
108 |
/* These are a combination of tracks and directions. Values are 0-5 in one |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
109 |
direction (corresponding to the Track enum) and 8-13 in the other direction. */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
110 |
typedef enum TrackdirBits { |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
111 |
TRACKDIR_BIT_DIAG1_NE = 0x1, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
112 |
TRACKDIR_BIT_DIAG2_SE = 0x2, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
113 |
TRACKDIR_BIT_UPPER_E = 0x4, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
114 |
TRACKDIR_BIT_LOWER_E = 0x8, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
115 |
TRACKDIR_BIT_LEFT_S = 0x10, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
116 |
TRACKDIR_BIT_RIGHT_S = 0x20, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
117 |
/* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
118 |
TRACKDIR_BIT_DIAG1_SW = 0x0100, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
119 |
TRACKDIR_BIT_DIAG2_NW = 0x0200, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
120 |
TRACKDIR_BIT_UPPER_W = 0x0400, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
121 |
TRACKDIR_BIT_LOWER_W = 0x0800, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
122 |
TRACKDIR_BIT_LEFT_N = 0x1000, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
123 |
TRACKDIR_BIT_RIGHT_N = 0x2000, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
124 |
TRACKDIR_BIT_MASK = 0x3F3F, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
125 |
INVALID_TRACKDIR_BIT = 0xFFFF, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
126 |
} TrackdirBits; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
127 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
128 |
/* These are states in which a signal can be. Currently these are only two, so |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
129 |
* simple boolean logic will do. But do try to compare to this enum instead of |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
130 |
* normal boolean evaluation, since that will make future additions easier. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
131 |
*/ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
132 |
typedef enum SignalStates { |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
133 |
SIGNAL_STATE_RED = 0, |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
134 |
SIGNAL_STATE_GREEN = 1, |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
135 |
} SignalState; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
136 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
137 |
|
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
138 |
/** |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
139 |
* Maps a Trackdir to the corresponding TrackdirBits value |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
140 |
*/ |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
141 |
static inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir) { return (TrackdirBits)(1 << trackdir); } |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
142 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
143 |
/* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
144 |
* These functions check the validity of Tracks and Trackdirs. assert against |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
145 |
* them when convenient. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
146 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
147 |
static inline bool IsValidTrack(Track track) { return track < TRACK_END; } |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
148 |
static inline bool IsValidTrackdir(Trackdir trackdir) { return (TrackdirToTrackdirBits(trackdir) & TRACKDIR_BIT_MASK) != 0; } |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
149 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
150 |
/* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
151 |
* Functions to map tracks to the corresponding bits in the signal |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
152 |
* presence/status bytes in the map. You should not use these directly, but |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
153 |
* wrapper functions below instead. XXX: Which are these? |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
154 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
155 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
156 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
157 |
* Maps a trackdir to the bit that stores its status in the map arrays, in the |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
158 |
* direction along with the trackdir. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
159 |
*/ |
1947
9ee32f167208
(svn r2453) * CodeChange: Declared the lookup arrays in rail.h as extern, so the linker will complain if they are not defined (ie when rail.c is not included).
matthijs
parents:
1944
diff
changeset
|
160 |
extern const byte _signal_along_trackdir[TRACKDIR_END]; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
161 |
static inline byte SignalAlongTrackdir(Trackdir trackdir) {return _signal_along_trackdir[trackdir];} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
162 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
163 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
164 |
* Maps a trackdir to the bit that stores its status in the map arrays, in the |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
165 |
* direction against the trackdir. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
166 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
167 |
static inline byte SignalAgainstTrackdir(Trackdir trackdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
168 |
extern const byte _signal_against_trackdir[TRACKDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
169 |
return _signal_against_trackdir[trackdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
170 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
171 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
172 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
173 |
* Maps a Track to the bits that store the status of the two signals that can |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
174 |
* be present on the given track. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
175 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
176 |
static inline byte SignalOnTrack(Track track) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
177 |
extern const byte _signal_on_track[TRACK_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
178 |
return _signal_on_track[track]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
179 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
180 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
181 |
/* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
182 |
* Some functions to query rail tiles |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
183 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
184 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
185 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
186 |
* Returns the RailTileType of a given rail tile. (ie normal, with signals, |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
187 |
* depot, etc.) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
188 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
189 |
static inline RailTileType GetRailTileType(TileIndex tile) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
190 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
191 |
assert(IsTileType(tile, MP_RAILWAY)); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
192 |
return (_map5[tile] & RAIL_TILE_TYPE_MASK); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
193 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
194 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
195 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
196 |
* Returns the rail type of the given rail tile (ie rail, mono, maglev). |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
197 |
*/ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
198 |
static inline RailType GetRailType(TileIndex tile) { return (RailType)(_map3_lo[tile] & RAILTYPE_MASK); } |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
199 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
200 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
201 |
* Checks if a rail tile has signals. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
202 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
203 |
static inline bool HasSignals(TileIndex tile) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
204 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
205 |
return GetRailTileType(tile) == RAIL_TYPE_SIGNALS; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
206 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
207 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
208 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
209 |
* Returns the RailTileSubtype of a given rail tile with type |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
210 |
* RAIL_TYPE_DEPOT_WAYPOINT |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
211 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
212 |
static inline RailTileSubtype GetRailTileSubtype(TileIndex tile) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
213 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
214 |
assert(GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT); |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
215 |
return (RailTileSubtype)(_map5[tile] & RAIL_SUBTYPE_MASK); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
216 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
217 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
218 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
219 |
* Returns whether this is plain rails, with or without signals. Iow, if this |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
220 |
* tiles RailTileType is RAIL_TYPE_NORMAL or RAIL_TYPE_SIGNALS. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
221 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
222 |
static inline bool IsPlainRailTile(TileIndex tile) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
223 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
224 |
RailTileType rtt = GetRailTileType(tile); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
225 |
return rtt == RAIL_TYPE_NORMAL || rtt == RAIL_TYPE_SIGNALS; |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
226 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
227 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
228 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
229 |
* Returns the tracks present on the given plain rail tile (IsPlainRailTile()) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
230 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
231 |
static inline TrackBits GetTrackBits(TileIndex tile) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
232 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
233 |
assert(GetRailTileType(tile) == RAIL_TYPE_NORMAL || GetRailTileType(tile) == RAIL_TYPE_SIGNALS); |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
234 |
return (TrackBits)(_map5[tile] & TRACK_BIT_MASK); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
235 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
236 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
237 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
238 |
* Returns whether the given track is present on the given tile. Tile must be |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
239 |
* a plain rail tile (IsPlainRailTile()). |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
240 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
241 |
static inline bool HasTrack(TileIndex tile, Track track) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
242 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
243 |
assert(IsValidTrack(track)); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
244 |
return HASBIT(GetTrackBits(tile), track); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
245 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
246 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
247 |
/* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
248 |
* Functions describing logical relations between Tracks, TrackBits, Trackdirs |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
249 |
* TrackdirBits, Direction and DiagDirections. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
250 |
* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
251 |
* TODO: Add #unndefs or something similar to remove the arrays used below |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
252 |
* from the global scope and expose direct uses of them. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
253 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
254 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
255 |
/** |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
256 |
* Maps a trackdir to the reverse trackdir. |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
257 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
258 |
static inline Trackdir ReverseTrackdir(Trackdir trackdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
259 |
extern const Trackdir _reverse_trackdir[TRACKDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
260 |
return _reverse_trackdir[trackdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
261 |
} |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
262 |
|
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
263 |
/* |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
264 |
* Maps a Track to the corresponding TrackBits value |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
265 |
*/ |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
266 |
static inline TrackBits TrackToTrackBits(Track track) { return (TrackBits)(1 << track); } |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
267 |
|
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
268 |
/* Returns the Track that a given Trackdir represents */ |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
269 |
static inline Track TrackdirToTrack(Trackdir trackdir) { return (Track)(trackdir & 0x7); } |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
270 |
|
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
271 |
/* Returns a Trackdir for the given Track. Since every Track corresponds to |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
272 |
* two Trackdirs, we choose the one which points between NE and S. |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
273 |
* Note that the actual implementation is quite futile, but this might change |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
274 |
* in the future. |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
275 |
*/ |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
276 |
static inline Trackdir TrackToTrackdir(Track track) { return (Trackdir)track; } |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
277 |
|
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
278 |
/* Returns a TrackdirBit mask that contains the two TrackdirBits that |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
279 |
* correspond with the given Track (one for each direction). |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
280 |
*/ |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
281 |
static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = TrackToTrackdir(track); return TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td));} |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
282 |
|
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
283 |
/** |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
284 |
* Maps a trackdir to the trackdir that you will end up on if you go straight |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
285 |
* ahead. This will be the same trackdir for diagonal trackdirs, but a |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
286 |
* different (alternating) one for straight trackdirs |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
287 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
288 |
static inline Trackdir NextTrackdir(Trackdir trackdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
289 |
extern const Trackdir _next_trackdir[TRACKDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
290 |
return _next_trackdir[trackdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
291 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
292 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
293 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
294 |
* Maps a track to all tracks that make 90 deg turns with it. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
295 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
296 |
static inline TrackBits TrackCrossesTracks(Track track) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
297 |
extern const TrackBits _track_crosses_tracks[TRACK_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
298 |
return _track_crosses_tracks[track]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
299 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
300 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
301 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
302 |
* Maps a trackdir to the (4-way) direction the tile is exited when following |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
303 |
* that trackdir. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
304 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
305 |
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
306 |
extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
307 |
return _trackdir_to_exitdir[trackdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
308 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
309 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
310 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
311 |
* Maps a track and an (4-way) dir to the trackdir that represents the track |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
312 |
* with the exit in the given direction. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
313 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
314 |
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
315 |
extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
316 |
return _track_exitdir_to_trackdir[track][diagdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
317 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
318 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
319 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
320 |
* Maps a track and a full (8-way) direction to the trackdir that represents |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
321 |
* the track running in the given direction. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
322 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
323 |
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
324 |
extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
325 |
return _track_direction_to_trackdir[track][dir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
326 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
327 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
328 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
329 |
* Maps a (4-way) direction to the diagonal trackdir that runs in that |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
330 |
* direction. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
331 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
332 |
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
333 |
extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
334 |
return _dir_to_diag_trackdir[diagdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
335 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
336 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
337 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
338 |
* Maps a trackdir to the trackdirs that can be reached from it (ie, when |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
339 |
* entering the next tile. This |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
340 |
*/ |
1947
9ee32f167208
(svn r2453) * CodeChange: Declared the lookup arrays in rail.h as extern, so the linker will complain if they are not defined (ie when rail.c is not included).
matthijs
parents:
1944
diff
changeset
|
341 |
extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END]; |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
342 |
/* Note that there is no direct table for this function (there used to be), |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
343 |
* but it uses two simpeler tables to achieve the result */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
344 |
static inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir) { return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)]; } |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
345 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
346 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
347 |
* Maps a trackdir to all trackdirs that make 90 deg turns with it. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
348 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
349 |
static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
350 |
extern const TrackdirBits _track_crosses_trackdirs[TRACKDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
351 |
return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
352 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
353 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
354 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
355 |
* Maps a (4-way) direction to the reverse. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
356 |
*/ |
1948
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
357 |
static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) { |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
358 |
extern const DiagDirection _reverse_diagdir[DIAGDIR_END]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
359 |
return _reverse_diagdir[diagdir]; |
e5f34b543a3c
(svn r2454) * Codechange: Move #include "stdafx.h" and "openttd.h" from rail.h to rail.c
matthijs
parents:
1947
diff
changeset
|
360 |
} |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
361 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
362 |
/* Checks if a given Track is diagonal */ |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
363 |
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_DIAG1) || (track == TRACK_DIAG2); } |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
364 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
365 |
/* Checks if a given Trackdir is diagonal. */ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
366 |
static inline bool IsDiagonalTrackdir(Trackdir trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); } |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
367 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
368 |
/* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
369 |
* Functions quering signals on tiles. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
370 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
371 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
372 |
/** |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
373 |
* Checks for the presence of signals (either way) on the given track on the |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
374 |
* given rail tile. |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
375 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
376 |
static inline bool HasSignalOnTrack(TileIndex tile, Track track) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
377 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
378 |
assert(IsValidTrack(track)); |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
379 |
return ((GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && ((_map3_lo[tile] & SignalOnTrack(track)) != 0)); |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
380 |
} |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
381 |
|
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
382 |
/** |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
383 |
* Checks for the presence of signals along the given trackdir on the given |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
384 |
* rail tile. |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
385 |
* |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
386 |
* Along meaning if you are currently driving on the given trackdir, this is |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
387 |
* the signal that is facing us (for which we stop when it's red). |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
388 |
*/ |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
389 |
static inline bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir) |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
390 |
{ |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
391 |
assert (IsValidTrackdir(trackdir)); |
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
392 |
return (GetRailTileType(tile) == RAIL_TYPE_SIGNALS) && (_map3_lo[tile] & SignalAlongTrackdir(trackdir)); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
393 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
394 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
395 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
396 |
* Gets the state of the signal along the given trackdir. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
397 |
* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
398 |
* Along meaning if you are currently driving on the given trackdir, this is |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
399 |
* the signal that is facing us (for which we stop when it's red). |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
400 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
401 |
static inline SignalState GetSignalState(TileIndex tile, Trackdir trackdir) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
402 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
403 |
assert(IsValidTrackdir(trackdir)); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
404 |
assert(HasSignalOnTrack(tile, TrackdirToTrack(trackdir))); |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
405 |
return ((_map2[tile] & SignalAlongTrackdir(trackdir))?SIGNAL_STATE_GREEN:SIGNAL_STATE_RED); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
406 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
407 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
408 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
409 |
* Gets the type of signal on a given track on a given rail tile with signals. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
410 |
* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
411 |
* Note that currently, the track argument is not used, since |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
412 |
* signal types cannot be mixed. This function is trying to be |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
413 |
* future-compatible, though. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
414 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
415 |
static inline SignalType GetSignalType(TileIndex tile, Track track) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
416 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
417 |
assert(IsValidTrack(track)); |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
418 |
assert(GetRailTileType(tile) == RAIL_TYPE_SIGNALS); |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
419 |
return (SignalType)(_map3_hi[tile] & SIGTYPE_MASK); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
420 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
421 |
|
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
422 |
/** |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
423 |
* Checks if this tile contains semaphores (returns true) or normal signals |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
424 |
* (returns false) on the given track. Does not check if there are actually |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
425 |
* signals on the track, you should use HasSignalsOnTrack() for that. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
426 |
* |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
427 |
* Note that currently, the track argument is not used, since |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
428 |
* semaphores/electric signals cannot be mixed. This function is trying to be |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
429 |
* future-compatible, though. |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
430 |
*/ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
431 |
static inline bool HasSemaphores(TileIndex tile, Track track) |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
432 |
{ |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
433 |
assert(IsValidTrack(track)); |
1944
012fa5e69118
(svn r2450) * Codechange: Replaced all uses of the arrays in tile.h with calls to the associated wrapper functions.
matthijs
parents:
1942
diff
changeset
|
434 |
return (_map3_hi[tile] & SIG_SEMAPHORE_MASK); |
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
435 |
} |
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
436 |
|
1950
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
437 |
/** |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
438 |
* Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile. |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
439 |
* Note that there is no check if the given trackdir is actually present on |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
440 |
* the tile! |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
441 |
* The given trackdir is used when there are (could be) multiple rail types on |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
442 |
* one tile. |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
443 |
*/ |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
444 |
RailType GetTileRailType(TileIndex tile, byte trackdir); |
6e4d384034d9
(svn r2456) * Prettyfied npf.c using enums and wrappers from rail.h.
matthijs
parents:
1948
diff
changeset
|
445 |
|
1967
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
446 |
/** |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
447 |
* Returns whether the given tile is a level crossing. |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
448 |
*/ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
449 |
static inline bool IsLevelCrossing(TileIndex tile) |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
450 |
{ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
451 |
return (_map5[tile] & 0xF0) == 0x10; |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
452 |
} |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
453 |
|
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
454 |
/** |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
455 |
* Gets the transport type of the given track on the given crossing tile. |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
456 |
* @return The transport type of the given track, either TRANSPORT_ROAD, |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
457 |
* TRANSPORT_RAIL. |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
458 |
*/ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
459 |
static inline TransportType GetCrossingTransportType(TileIndex tile, Track track) |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
460 |
{ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
461 |
/* XXX: Nicer way to write this? */ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
462 |
switch(track) |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
463 |
{ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
464 |
/* When map5 bit 3 is set, the road runs in the y direction (DIAG2) */ |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
465 |
case TRACK_DIAG1: |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
466 |
return (HASBIT(_map5[tile], 3) ? TRANSPORT_RAIL : TRANSPORT_ROAD); |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
467 |
case TRACK_DIAG2: |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
468 |
return (HASBIT(_map5[tile], 3) ? TRANSPORT_ROAD : TRANSPORT_RAIL); |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
469 |
default: |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
470 |
assert(0); |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
471 |
} |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
472 |
return INVALID_TRANSPORT; |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
473 |
} |
c57192f4c121
(svn r2473) - Add: VehicleMayEnterTile(), which checks if the tile owner of a tile is correct for a vehicle to enter it. Based upon glx's code.
matthijs
parents:
1950
diff
changeset
|
474 |
|
1942
634961366cdc
(svn r2448) General cleanup of rail related code, more to follow.
matthijs
parents:
diff
changeset
|
475 |
#endif // RAIL_H |