12 * Do not access it directly unless you have to. Use the access functions below |
14 * Do not access it directly unless you have to. Use the access functions below |
13 * This is an enum to tell what bit to access as it is a bitmask |
15 * This is an enum to tell what bit to access as it is a bitmask |
14 */ |
16 */ |
15 |
17 |
16 enum TrainSubtype { |
18 enum TrainSubtype { |
17 Train_Front = 0, // Leading engine of a train |
19 Train_Front = 0, ///< Leading engine of a train |
18 Train_Articulated_Part = 1, // Articulated part of an engine |
20 Train_Articulated_Part = 1, ///< Articulated part of an engine |
19 Train_Wagon = 2, // Wagon |
21 Train_Wagon = 2, ///< Wagon |
20 Train_Engine = 3, // Engine, that can be front engines, but might be placed behind another engine |
22 Train_Engine = 3, ///< Engine, that can be front engines, but might be placed behind another engine |
21 Train_Free_Wagon = 4, // First in a wagon chain (in depot) |
23 Train_Free_Wagon = 4, ///< First in a wagon chain (in depot) |
22 Train_Multiheaded = 5, // Engine is a multiheaded |
24 Train_Multiheaded = 5, ///< Engine is a multiheaded |
23 }; |
25 }; |
24 |
26 |
25 |
27 |
26 /** Check if a vehicle is front engine |
28 /** Check if a vehicle is front engine |
27 * @param v vehicle to check |
29 * @param v vehicle to check |
28 * @return Returns true if vehicle is a front engine |
30 * @return Returns true if vehicle is a front engine |
29 */ |
31 */ |
30 static inline bool IsFrontEngine(const Vehicle *v) |
32 static inline bool IsFrontEngine(const Vehicle *v) |
31 { |
33 { |
|
34 assert(v->type == VEH_TRAIN); |
32 return HASBIT(v->subtype, Train_Front); |
35 return HASBIT(v->subtype, Train_Front); |
33 } |
36 } |
34 |
37 |
35 /** Set front engine state |
38 /** Set front engine state |
36 * @param v vehicle to change |
39 * @param v vehicle to change |
37 */ |
40 */ |
38 static inline void SetFrontEngine(Vehicle *v) |
41 static inline void SetFrontEngine(Vehicle *v) |
39 { |
42 { |
|
43 assert(v->type == VEH_TRAIN); |
40 SETBIT(v->subtype, Train_Front); |
44 SETBIT(v->subtype, Train_Front); |
41 } |
45 } |
42 |
46 |
43 /** Remove the front engine state |
47 /** Remove the front engine state |
44 * @param v vehicle to change |
48 * @param v vehicle to change |
45 */ |
49 */ |
46 static inline void ClearFrontEngine(Vehicle *v) |
50 static inline void ClearFrontEngine(Vehicle *v) |
47 { |
51 { |
|
52 assert(v->type == VEH_TRAIN); |
48 CLRBIT(v->subtype, Train_Front); |
53 CLRBIT(v->subtype, Train_Front); |
49 } |
54 } |
50 |
55 |
51 /** Check if a vehicle is an articulated part of an engine |
56 /** Check if a vehicle is an articulated part of an engine |
52 * @param v vehicle to check |
57 * @param v vehicle to check |
53 * @return Returns true if vehicle is an articulated part |
58 * @return Returns true if vehicle is an articulated part |
54 */ |
59 */ |
55 static inline bool IsArticulatedPart(const Vehicle *v) |
60 static inline bool IsArticulatedPart(const Vehicle *v) |
56 { |
61 { |
|
62 assert(v->type == VEH_TRAIN); |
57 return HASBIT(v->subtype, Train_Articulated_Part); |
63 return HASBIT(v->subtype, Train_Articulated_Part); |
58 } |
64 } |
59 |
65 |
60 /** Set a vehicle to be an articulated part |
66 /** Set a vehicle to be an articulated part |
61 * @param v vehicle to change |
67 * @param v vehicle to change |
62 */ |
68 */ |
63 static inline void SetArticulatedPart(Vehicle *v) |
69 static inline void SetArticulatedPart(Vehicle *v) |
64 { |
70 { |
|
71 assert(v->type == VEH_TRAIN); |
65 SETBIT(v->subtype, Train_Articulated_Part); |
72 SETBIT(v->subtype, Train_Articulated_Part); |
66 } |
73 } |
67 |
74 |
68 /** Clear a vehicle from being an articulated part |
75 /** Clear a vehicle from being an articulated part |
69 * @param v vehicle to change |
76 * @param v vehicle to change |
70 */ |
77 */ |
71 static inline void ClearArticulatedPart(Vehicle *v) |
78 static inline void ClearArticulatedPart(Vehicle *v) |
72 { |
79 { |
|
80 assert(v->type == VEH_TRAIN); |
73 CLRBIT(v->subtype, Train_Articulated_Part); |
81 CLRBIT(v->subtype, Train_Articulated_Part); |
74 } |
82 } |
75 |
83 |
76 /** Check if a vehicle is a wagon |
84 /** Check if a vehicle is a wagon |
77 * @param v vehicle to check |
85 * @param v vehicle to check |
78 * @return Returns true if vehicle is a wagon |
86 * @return Returns true if vehicle is a wagon |
79 */ |
87 */ |
80 static inline bool IsTrainWagon(const Vehicle *v) |
88 static inline bool IsTrainWagon(const Vehicle *v) |
81 { |
89 { |
|
90 assert(v->type == VEH_TRAIN); |
82 return HASBIT(v->subtype, Train_Wagon); |
91 return HASBIT(v->subtype, Train_Wagon); |
83 } |
92 } |
84 |
93 |
85 /** Set a vehicle to be a wagon |
94 /** Set a vehicle to be a wagon |
86 * @param v vehicle to change |
95 * @param v vehicle to change |
87 */ |
96 */ |
88 static inline void SetTrainWagon(Vehicle *v) |
97 static inline void SetTrainWagon(Vehicle *v) |
89 { |
98 { |
|
99 assert(v->type == VEH_TRAIN); |
90 SETBIT(v->subtype, Train_Wagon); |
100 SETBIT(v->subtype, Train_Wagon); |
91 } |
101 } |
92 |
102 |
93 /** Clear wagon property |
103 /** Clear wagon property |
94 * @param v vehicle to change |
104 * @param v vehicle to change |
95 */ |
105 */ |
96 static inline void ClearTrainWagon(Vehicle *v) |
106 static inline void ClearTrainWagon(Vehicle *v) |
97 { |
107 { |
|
108 assert(v->type == VEH_TRAIN); |
98 CLRBIT(v->subtype, Train_Wagon); |
109 CLRBIT(v->subtype, Train_Wagon); |
99 } |
110 } |
100 |
111 |
101 /** Check if a vehicle is an engine (can be first in a train) |
112 /** Check if a vehicle is an engine (can be first in a train) |
102 * @param v vehicle to check |
113 * @param v vehicle to check |
103 * @return Returns true if vehicle is an engine |
114 * @return Returns true if vehicle is an engine |
104 */ |
115 */ |
105 static inline bool IsTrainEngine(const Vehicle *v) |
116 static inline bool IsTrainEngine(const Vehicle *v) |
106 { |
117 { |
|
118 assert(v->type == VEH_TRAIN); |
107 return HASBIT(v->subtype, Train_Engine); |
119 return HASBIT(v->subtype, Train_Engine); |
108 } |
120 } |
109 |
121 |
110 /** Set engine status |
122 /** Set engine status |
111 * @param v vehicle to change |
123 * @param v vehicle to change |
112 */ |
124 */ |
113 static inline void SetTrainEngine(Vehicle *v) |
125 static inline void SetTrainEngine(Vehicle *v) |
114 { |
126 { |
|
127 assert(v->type == VEH_TRAIN); |
115 SETBIT(v->subtype, Train_Engine); |
128 SETBIT(v->subtype, Train_Engine); |
116 } |
129 } |
117 |
130 |
118 /** Clear engine status |
131 /** Clear engine status |
119 * @param v vehicle to change |
132 * @param v vehicle to change |
120 */ |
133 */ |
121 static inline void ClearTrainEngine(Vehicle *v) |
134 static inline void ClearTrainEngine(Vehicle *v) |
122 { |
135 { |
|
136 assert(v->type == VEH_TRAIN); |
123 CLRBIT(v->subtype, Train_Engine); |
137 CLRBIT(v->subtype, Train_Engine); |
124 } |
138 } |
125 |
139 |
126 /** Check if a vehicle is a free wagon (got no engine in front of it) |
140 /** Check if a vehicle is a free wagon (got no engine in front of it) |
127 * @param v vehicle to check |
141 * @param v vehicle to check |
128 * @return Returns true if vehicle is a free wagon |
142 * @return Returns true if vehicle is a free wagon |
129 */ |
143 */ |
130 static inline bool IsFreeWagon(const Vehicle *v) |
144 static inline bool IsFreeWagon(const Vehicle *v) |
131 { |
145 { |
|
146 assert(v->type == VEH_TRAIN); |
132 return HASBIT(v->subtype, Train_Free_Wagon); |
147 return HASBIT(v->subtype, Train_Free_Wagon); |
133 } |
148 } |
134 |
149 |
135 /** Set if a vehicle is a free wagon |
150 /** Set if a vehicle is a free wagon |
136 * @param v vehicle to change |
151 * @param v vehicle to change |
137 */ |
152 */ |
138 static inline void SetFreeWagon(Vehicle *v) |
153 static inline void SetFreeWagon(Vehicle *v) |
139 { |
154 { |
|
155 assert(v->type == VEH_TRAIN); |
140 SETBIT(v->subtype, Train_Free_Wagon); |
156 SETBIT(v->subtype, Train_Free_Wagon); |
141 } |
157 } |
142 |
158 |
143 /** Clear a vehicle from being a free wagon |
159 /** Clear a vehicle from being a free wagon |
144 * @param v vehicle to change |
160 * @param v vehicle to change |
145 */ |
161 */ |
146 static inline void ClearFreeWagon(Vehicle *v) |
162 static inline void ClearFreeWagon(Vehicle *v) |
147 { |
163 { |
|
164 assert(v->type == VEH_TRAIN); |
148 CLRBIT(v->subtype, Train_Free_Wagon); |
165 CLRBIT(v->subtype, Train_Free_Wagon); |
149 } |
166 } |
150 |
167 |
151 /** Check if a vehicle is a multiheaded engine |
168 /** Check if a vehicle is a multiheaded engine |
152 * @param v vehicle to check |
169 * @param v vehicle to check |
153 * @return Returns true if vehicle is a multiheaded engine |
170 * @return Returns true if vehicle is a multiheaded engine |
154 */ |
171 */ |
155 static inline bool IsMultiheaded(const Vehicle *v) |
172 static inline bool IsMultiheaded(const Vehicle *v) |
156 { |
173 { |
|
174 assert(v->type == VEH_TRAIN); |
157 return HASBIT(v->subtype, Train_Multiheaded); |
175 return HASBIT(v->subtype, Train_Multiheaded); |
158 } |
176 } |
159 |
177 |
160 /** Set if a vehicle is a multiheaded engine |
178 /** Set if a vehicle is a multiheaded engine |
161 * @param v vehicle to change |
179 * @param v vehicle to change |
162 */ |
180 */ |
163 static inline void SetMultiheaded(Vehicle *v) |
181 static inline void SetMultiheaded(Vehicle *v) |
164 { |
182 { |
|
183 assert(v->type == VEH_TRAIN); |
165 SETBIT(v->subtype, Train_Multiheaded); |
184 SETBIT(v->subtype, Train_Multiheaded); |
166 } |
185 } |
167 |
186 |
168 /** Clear multiheaded engine property |
187 /** Clear multiheaded engine property |
169 * @param v vehicle to change |
188 * @param v vehicle to change |
170 */ |
189 */ |
171 static inline void ClearMultiheaded(Vehicle *v) |
190 static inline void ClearMultiheaded(Vehicle *v) |
172 { |
191 { |
|
192 assert(v->type == VEH_TRAIN); |
173 CLRBIT(v->subtype, Train_Multiheaded); |
193 CLRBIT(v->subtype, Train_Multiheaded); |
174 } |
194 } |
175 |
195 |
176 /** Check if an engine has an articulated part. |
196 /** Check if an engine has an articulated part. |
177 * @param v Vehicle. |
197 * @param v Vehicle. |
178 * @return True if the engine has an articulated part. |
198 * @return True if the engine has an articulated part. |
179 */ |
199 */ |
180 static inline bool EngineHasArticPart(const Vehicle *v) |
200 static inline bool EngineHasArticPart(const Vehicle *v) |
181 { |
201 { |
|
202 assert(v->type == VEH_TRAIN); |
182 return (v->next != NULL && IsArticulatedPart(v->next)); |
203 return (v->next != NULL && IsArticulatedPart(v->next)); |
183 } |
204 } |
184 |
205 |
185 /** |
206 /** |
186 * Get the next part of a multi-part engine. |
207 * Get the next part of a multi-part engine. |