mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21859) -Codechange: Move train subtype flags to GroundVehicle.
This commit is contained in:
parent
cfbbcf1597
commit
613743538d
|
@ -149,6 +149,19 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
|
|||
this->UpdateViewport(true, turned);
|
||||
return old_z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum to handle ground vehicle subtypes.
|
||||
* Do not access it directly unless you have to. Use the subtype access functions.
|
||||
*/
|
||||
enum GroundVehicleSubtypeFlags {
|
||||
GVSF_FRONT = 0, ///< Leading engine of a consist.
|
||||
GVSF_ARTICULATED_PART = 1, ///< Articulated part of an engine.
|
||||
GVSF_WAGON = 2, ///< Wagon (not used for road vehicles).
|
||||
GVSF_ENGINE = 3, ///< Engine that can be front engine, but might be placed behind another engine (not used for road vehicles).
|
||||
GVSF_FREE_WAGON = 4, ///< First in a wagon chain (in depot) (not used for road vehicles).
|
||||
GVSF_MULTIHEADED = 5, ///< Engine is multiheaded (not used for road vehicles).
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* GROUND_VEHICLE_HPP */
|
||||
|
|
50
src/train.h
50
src/train.h
|
@ -137,110 +137,96 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> {
|
|||
|
||||
int GetCurrentMaxSpeed() const;
|
||||
|
||||
/**
|
||||
* enum to handle train subtypes
|
||||
* Do not access it directly unless you have to. Use the access functions below
|
||||
* This is an enum to tell what bit to access as it is a bitmask
|
||||
*/
|
||||
enum TrainSubtype {
|
||||
TS_FRONT = 0, ///< Leading engine of a train
|
||||
TS_ARTICULATED_PART = 1, ///< Articulated part of an engine
|
||||
TS_WAGON = 2, ///< Wagon
|
||||
TS_ENGINE = 3, ///< Engine that can be front engine, but might be placed behind another engine.
|
||||
TS_FREE_WAGON = 4, ///< First in a wagon chain (in depot)
|
||||
TS_MULTIHEADED = 5, ///< Engine is multiheaded
|
||||
};
|
||||
|
||||
/**
|
||||
* Set front engine state
|
||||
*/
|
||||
FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, TS_FRONT); }
|
||||
FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, GVSF_FRONT); }
|
||||
|
||||
/**
|
||||
* Remove the front engine state
|
||||
*/
|
||||
FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, TS_FRONT); }
|
||||
FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, GVSF_FRONT); }
|
||||
|
||||
/**
|
||||
* Set a vehicle to be an articulated part
|
||||
*/
|
||||
FORCEINLINE void SetArticulatedPart() { SetBit(this->subtype, TS_ARTICULATED_PART); }
|
||||
FORCEINLINE void SetArticulatedPart() { SetBit(this->subtype, GVSF_ARTICULATED_PART); }
|
||||
|
||||
/**
|
||||
* Clear a vehicle from being an articulated part
|
||||
*/
|
||||
FORCEINLINE void ClearArticulatedPart() { ClrBit(this->subtype, TS_ARTICULATED_PART); }
|
||||
FORCEINLINE void ClearArticulatedPart() { ClrBit(this->subtype, GVSF_ARTICULATED_PART); }
|
||||
|
||||
/**
|
||||
* Set a vehicle to be a wagon
|
||||
*/
|
||||
FORCEINLINE void SetWagon() { SetBit(this->subtype, TS_WAGON); }
|
||||
FORCEINLINE void SetWagon() { SetBit(this->subtype, GVSF_WAGON); }
|
||||
|
||||
/**
|
||||
* Clear wagon property
|
||||
*/
|
||||
FORCEINLINE void ClearWagon() { ClrBit(this->subtype, TS_WAGON); }
|
||||
FORCEINLINE void ClearWagon() { ClrBit(this->subtype, GVSF_WAGON); }
|
||||
|
||||
/**
|
||||
* Set engine status
|
||||
*/
|
||||
FORCEINLINE void SetEngine() { SetBit(this->subtype, TS_ENGINE); }
|
||||
FORCEINLINE void SetEngine() { SetBit(this->subtype, GVSF_ENGINE); }
|
||||
|
||||
/**
|
||||
* Clear engine status
|
||||
*/
|
||||
FORCEINLINE void ClearEngine() { ClrBit(this->subtype, TS_ENGINE); }
|
||||
FORCEINLINE void ClearEngine() { ClrBit(this->subtype, GVSF_ENGINE); }
|
||||
|
||||
/**
|
||||
* Set if a vehicle is a free wagon
|
||||
*/
|
||||
FORCEINLINE void SetFreeWagon() { SetBit(this->subtype, TS_FREE_WAGON); }
|
||||
FORCEINLINE void SetFreeWagon() { SetBit(this->subtype, GVSF_FREE_WAGON); }
|
||||
|
||||
/**
|
||||
* Clear a vehicle from being a free wagon
|
||||
*/
|
||||
FORCEINLINE void ClearFreeWagon() { ClrBit(this->subtype, TS_FREE_WAGON); }
|
||||
FORCEINLINE void ClearFreeWagon() { ClrBit(this->subtype, GVSF_FREE_WAGON); }
|
||||
|
||||
/**
|
||||
* Set if a vehicle is a multiheaded engine
|
||||
*/
|
||||
FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, TS_MULTIHEADED); }
|
||||
FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, GVSF_MULTIHEADED); }
|
||||
|
||||
/**
|
||||
* Clear multiheaded engine property
|
||||
*/
|
||||
FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, TS_MULTIHEADED); }
|
||||
FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, GVSF_MULTIHEADED); }
|
||||
|
||||
|
||||
/**
|
||||
* Check if train is a front engine
|
||||
* @return Returns true if train is a front engine
|
||||
*/
|
||||
FORCEINLINE bool IsFrontEngine() const { return HasBit(this->subtype, TS_FRONT); }
|
||||
FORCEINLINE bool IsFrontEngine() const { return HasBit(this->subtype, GVSF_FRONT); }
|
||||
|
||||
/**
|
||||
* Check if train is a free wagon (got no engine in front of it)
|
||||
* @return Returns true if train is a free wagon
|
||||
*/
|
||||
FORCEINLINE bool IsFreeWagon() const { return HasBit(this->subtype, TS_FREE_WAGON); }
|
||||
FORCEINLINE bool IsFreeWagon() const { return HasBit(this->subtype, GVSF_FREE_WAGON); }
|
||||
|
||||
/**
|
||||
* Check if a vehicle is an engine (can be first in a train)
|
||||
* @return Returns true if vehicle is an engine
|
||||
*/
|
||||
FORCEINLINE bool IsEngine() const { return HasBit(this->subtype, TS_ENGINE); }
|
||||
FORCEINLINE bool IsEngine() const { return HasBit(this->subtype, GVSF_ENGINE); }
|
||||
|
||||
/**
|
||||
* Check if a train is a wagon
|
||||
* @return Returns true if vehicle is a wagon
|
||||
*/
|
||||
FORCEINLINE bool IsWagon() const { return HasBit(this->subtype, TS_WAGON); }
|
||||
FORCEINLINE bool IsWagon() const { return HasBit(this->subtype, GVSF_WAGON); }
|
||||
|
||||
/**
|
||||
* Check if train is a multiheaded engine
|
||||
* @return Returns true if vehicle is a multiheaded engine
|
||||
*/
|
||||
FORCEINLINE bool IsMultiheaded() const { return HasBit(this->subtype, TS_MULTIHEADED); }
|
||||
FORCEINLINE bool IsMultiheaded() const { return HasBit(this->subtype, GVSF_MULTIHEADED); }
|
||||
|
||||
/**
|
||||
* Tell if we are dealing with the rear end of a multiheaded engine.
|
||||
|
@ -252,7 +238,7 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> {
|
|||
* Check if train is an articulated part of an engine
|
||||
* @return Returns true if train is an articulated part
|
||||
*/
|
||||
FORCEINLINE bool IsArticulatedPart() const { return HasBit(this->subtype, TS_ARTICULATED_PART); }
|
||||
FORCEINLINE bool IsArticulatedPart() const { return HasBit(this->subtype, GVSF_ARTICULATED_PART); }
|
||||
|
||||
/**
|
||||
* Check if an engine has an articulated part.
|
||||
|
|
Loading…
Reference in New Issue