forked from mirror/OpenTTD
(svn r21923) -Codechange: Unify articulated vehicle iteration functions.
This commit is contained in:
70
src/train.h
70
src/train.h
@@ -135,76 +135,6 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> {
|
||||
|
||||
int GetCurrentMaxSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the next part of a multi-part engine.
|
||||
* Will only work on a multi-part engine (this->EngineHasArticPart() == true),
|
||||
* Result is undefined for normal engine.
|
||||
* @return next part of articulated engine
|
||||
*/
|
||||
FORCEINLINE Train *GetNextArticulatedPart() const
|
||||
{
|
||||
assert(this->HasArticulatedPart());
|
||||
return this->Next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first part of a multi-part engine.
|
||||
* @return First part of the engine.
|
||||
*/
|
||||
FORCEINLINE Train *GetFirstEnginePart()
|
||||
{
|
||||
Train *v = this;
|
||||
while (v->IsArticulatedPart()) v = v->Previous();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first part of a multi-part engine.
|
||||
* @return First part of the engine.
|
||||
*/
|
||||
FORCEINLINE const Train *GetFirstEnginePart() const
|
||||
{
|
||||
const Train *v = this;
|
||||
while (v->IsArticulatedPart()) v = v->Previous();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last part of a multi-part engine.
|
||||
* @return Last part of the engine.
|
||||
*/
|
||||
FORCEINLINE Train *GetLastEnginePart()
|
||||
{
|
||||
Train *v = this;
|
||||
while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next real (non-articulated part) vehicle in the consist.
|
||||
* @return Next vehicle in the consist.
|
||||
*/
|
||||
FORCEINLINE Train *GetNextVehicle() const
|
||||
{
|
||||
const Train *v = this;
|
||||
while (v->HasArticulatedPart()) v = v->GetNextArticulatedPart();
|
||||
|
||||
/* v now contains the last artic part in the engine */
|
||||
return v->Next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous real (non-articulated part) vehicle in the consist.
|
||||
* @return Previous vehicle in the consist.
|
||||
*/
|
||||
FORCEINLINE Train *GetPrevVehicle() const
|
||||
{
|
||||
Train *v = this->Previous();
|
||||
while (v != NULL && v->IsArticulatedPart()) v = v->Previous();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
|
||||
* @return Next vehicle in the consist.
|
||||
|
Reference in New Issue
Block a user