From 8db501e11510580f4fd531496108f7e883a3a0ad Mon Sep 17 00:00:00 2001 From: terkhen Date: Wed, 19 Jan 2011 20:04:09 +0000 Subject: [PATCH] (svn r21862) -Codechange: Unify subtype handling between road vehicles and trains. --- src/ground_vehicle.hpp | 108 +++++++++++++++++++++++++++++++++++ src/roadveh.h | 34 ----------- src/saveload/saveload.cpp | 3 +- src/saveload/vehicle_sl.cpp | 17 ++++++ src/train.h | 110 ------------------------------------ 5 files changed, 127 insertions(+), 145 deletions(-) diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index 57984a030a..f616c39e0a 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -162,6 +162,114 @@ struct GroundVehicle : public SpecializedVehicle { 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). }; + + /** + * Set front engine state. + */ + FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, GVSF_FRONT); } + + /** + * Remove the front engine state. + */ + FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, GVSF_FRONT); } + + /** + * Set a vehicle to be an 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, GVSF_ARTICULATED_PART); } + + /** + * Set a vehicle to be a wagon. + */ + FORCEINLINE void SetWagon() { SetBit(this->subtype, GVSF_WAGON); } + + /** + * Clear wagon property. + */ + FORCEINLINE void ClearWagon() { ClrBit(this->subtype, GVSF_WAGON); } + + /** + * Set engine status. + */ + FORCEINLINE void SetEngine() { SetBit(this->subtype, GVSF_ENGINE); } + + /** + * Clear engine status. + */ + FORCEINLINE void ClearEngine() { ClrBit(this->subtype, GVSF_ENGINE); } + + /** + * Set a vehicle as a 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, GVSF_FREE_WAGON); } + + /** + * Set a vehicle as a multiheaded engine. + */ + FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, GVSF_MULTIHEADED); } + + /** + * Clear multiheaded engine property. + */ + FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, GVSF_MULTIHEADED); } + + /** + * Check if the vehicle is a front engine. + * @return Returns true if the vehicle is a front engine. + */ + FORCEINLINE bool IsFrontEngine() const { return HasBit(this->subtype, GVSF_FRONT); } + + /** + * Check if the vehicle is a free wagon (got no engine in front of it). + * @return Returns true if the vehicle is a 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 consist). + * @return Returns true if vehicle is an engine. + */ + FORCEINLINE bool IsEngine() const { return HasBit(this->subtype, GVSF_ENGINE); } + + /** + * Check if a vehicle is a wagon. + * @return Returns true if vehicle is a wagon. + */ + FORCEINLINE bool IsWagon() const { return HasBit(this->subtype, GVSF_WAGON); } + + /** + * Check if the vehicle is a multiheaded engine. + * @return Returns true if the vehicle is a multiheaded engine. + */ + FORCEINLINE bool IsMultiheaded() const { return HasBit(this->subtype, GVSF_MULTIHEADED); } + + /** + * Tell if we are dealing with the rear end of a multiheaded engine. + * @return True if the engine is the rear part of a dualheaded engine. + */ + FORCEINLINE bool IsRearDualheaded() const { return this->IsMultiheaded() && !this->IsEngine(); } + + /** + * Check if the vehicle is an articulated part of an engine. + * @return Returns true if the vehicle is an articulated part. + */ + FORCEINLINE bool IsArticulatedPart() const { return HasBit(this->subtype, GVSF_ARTICULATED_PART); } + + /** + * Check if an engine has an articulated part. + * @return True if the engine has an articulated part. + */ + FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); } }; #endif /* GROUND_VEHICLE_HPP */ diff --git a/src/roadveh.h b/src/roadveh.h index 2cb920c61a..92a5eab9ec 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -75,12 +75,6 @@ static const uint RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16; static const uint RVC_DRIVE_THROUGH_STOP_FRAME = 11; static const uint RVC_DEPOT_STOP_FRAME = 11; -enum RoadVehicleSubType { - RVST_FRONT, - RVST_ARTIC_PART, -}; - - void RoadVehUpdateCache(RoadVehicle *v); /** @@ -128,34 +122,6 @@ struct RoadVehicle : public GroundVehicle { int GetCurrentMaxSpeed() const; - /** - * Check if vehicle is a front engine - * @return Returns true if vehicle is a front engine - */ - FORCEINLINE bool IsFrontEngine() const { return this->subtype == RVST_FRONT; } - - /** - * Set front engine state - */ - FORCEINLINE void SetFrontEngine() { this->subtype = RVST_FRONT; } - - /** - * Check if vehicl is an articulated part of an engine - * @return Returns true if vehicle is an articulated part - */ - FORCEINLINE bool IsArticulatedPart() const { return this->subtype == RVST_ARTIC_PART; } - - /** - * Set a vehicle to be an articulated part - */ - FORCEINLINE void SetArticulatedPart() { this->subtype = RVST_ARTIC_PART; } - - /** - * Check if an engine has an articulated part. - * @return True if the engine has an articulated part. - */ - FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); } - protected: // These functions should not be called outside acceleration code. /** diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index f4d59ca856..4d68133bcd 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -221,8 +221,9 @@ * 154 21426 * 155 21453 * 156 21728 + * 157 21862 */ -extern const uint16 SAVEGAME_VERSION = 156; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 157; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 398f74e2fb..f85719e381 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -308,6 +308,23 @@ void AfterLoadVehicles(bool part_of_load) } } + if (IsSavegameVersionBefore(157)) { + /* The road vehicle subtype was converted to a flag. */ + RoadVehicle *rv; + FOR_ALL_ROADVEHICLES(rv) { + if (rv->subtype == 0) { + /* The road vehicle is at the front. */ + rv->SetFrontEngine(); + } else if (rv->subtype == 1) { + /* The road vehicle is an articulated part. */ + rv->subtype = 0; + rv->SetArticulatedPart(); + } else { + NOT_REACHED(); + } + } + } + CheckValidVehicles(); FOR_ALL_VEHICLES(v) { diff --git a/src/train.h b/src/train.h index 55c273faab..f20bdd582e 100644 --- a/src/train.h +++ b/src/train.h @@ -137,116 +137,6 @@ struct Train : public GroundVehicle { int GetCurrentMaxSpeed() const; - /** - * Set front engine state - */ - FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, GVSF_FRONT); } - - /** - * Remove the front engine state - */ - FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, GVSF_FRONT); } - - /** - * Set a vehicle to be an 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, GVSF_ARTICULATED_PART); } - - /** - * Set a vehicle to be a wagon - */ - FORCEINLINE void SetWagon() { SetBit(this->subtype, GVSF_WAGON); } - - /** - * Clear wagon property - */ - FORCEINLINE void ClearWagon() { ClrBit(this->subtype, GVSF_WAGON); } - - /** - * Set engine status - */ - FORCEINLINE void SetEngine() { SetBit(this->subtype, GVSF_ENGINE); } - - /** - * Clear engine status - */ - FORCEINLINE void ClearEngine() { ClrBit(this->subtype, GVSF_ENGINE); } - - /** - * Set if a vehicle is a 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, GVSF_FREE_WAGON); } - - /** - * Set if a vehicle is a multiheaded engine - */ - FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, GVSF_MULTIHEADED); } - - /** - * Clear multiheaded engine property - */ - 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, 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, 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, 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, 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, GVSF_MULTIHEADED); } - - /** - * Tell if we are dealing with the rear end of a multiheaded engine. - * @return True if the engine is the rear part of a dualheaded engine. - */ - FORCEINLINE bool IsRearDualheaded() const { return this->IsMultiheaded() && !this->IsEngine(); } - - /** - * 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, GVSF_ARTICULATED_PART); } - - /** - * Check if an engine has an articulated part. - * @return True if the engine has an articulated part. - */ - FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); } - - /** * Get the next part of a multi-part engine. * Will only work on a multi-part engine (this->EngineHasArticPart() == true),