train.h
changeset 4384 7e0d3ed719d9
parent 2855 56c39efde08a
child 4640 4e380e2ecfa7
equal deleted inserted replaced
4383:f1e2d6c7527e 4384:7e0d3ed719d9
   171 static inline void ClearMultiheaded(Vehicle *v)
   171 static inline void ClearMultiheaded(Vehicle *v)
   172 {
   172 {
   173 	CLRBIT(v->subtype, Train_Multiheaded);
   173 	CLRBIT(v->subtype, Train_Multiheaded);
   174 }
   174 }
   175 
   175 
       
   176 /** Check if an engine has an articulated part.
       
   177  * @param v Vehicle.
       
   178  * @return True if the engine has an articulated part.
       
   179  */
       
   180 static inline bool EngineHasArticPart(const Vehicle *v)
       
   181 {
       
   182 	return (v->next != NULL && IsArticulatedPart(v->next));
       
   183 }
       
   184 
       
   185 /**
       
   186  * Get the next part of a multi-part engine.
       
   187  * Will only work on a multi-part engine (EngineHasArticPart(v) == true),
       
   188  * Result is undefined for normal engine.
       
   189  */
       
   190 static inline Vehicle *GetNextArticPart(const Vehicle *v)
       
   191 {
       
   192 	assert(EngineHasArticPart(v));
       
   193 	return v->next;
       
   194 }
       
   195 
       
   196 /** Get the last part of a multi-part engine.
       
   197  * @param v Vehicle.
       
   198  * @return Last part of the engine.
       
   199  */
       
   200 static inline Vehicle *GetLastEnginePart(Vehicle *v)
       
   201 {
       
   202 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
       
   203 	return v;
       
   204 }
       
   205 
   176 /** Get the next real (non-articulated part) vehicle in the consist.
   206 /** Get the next real (non-articulated part) vehicle in the consist.
   177  * @param v Vehicle.
   207  * @param v Vehicle.
   178  * @return Next vehicle in the consist.
   208  * @return Next vehicle in the consist.
   179  */
   209  */
   180 static inline Vehicle *GetNextVehicle(const Vehicle *v)
   210 static inline Vehicle *GetNextVehicle(const Vehicle *v)
   181 {
   211 {
   182 	Vehicle *u = v->next;
   212 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
   183 	while (u != NULL && IsArticulatedPart(u)) {
   213 
   184 		u = u->next;
   214 	/* v now contains the last artic part in the engine */
   185 	}
   215 	return v->next;
   186 	return u;
       
   187 }
       
   188 
       
   189 /** Check if an engine has an articulated part.
       
   190  * @param v Vehicle.
       
   191  * @return True if the engine has an articulated part.
       
   192  */
       
   193 static inline bool EngineHasArticPart(const Vehicle *v)
       
   194 {
       
   195 	return (v->next != NULL && IsArticulatedPart(v->next));
       
   196 }
       
   197 
       
   198 /** Get the last part of a multi-part engine.
       
   199  * @param v Vehicle.
       
   200  * @return Last part of the engine.
       
   201  */
       
   202 static inline Vehicle *GetLastEnginePart(Vehicle *v)
       
   203 {
       
   204 	while (EngineHasArticPart(v)) v = v->next;
       
   205 	return v;
       
   206 }
   216 }
   207 
   217 
   208 void ConvertOldMultiheadToNew(void);
   218 void ConvertOldMultiheadToNew(void);
   209 void ConnectMultiheadedTrains(void);
   219 void ConnectMultiheadedTrains(void);
   210 
   220