From 8c11d612e44c30e124881ca47e15eda9ef0c5491 Mon Sep 17 00:00:00 2001 From: smatz Date: Sat, 30 May 2009 20:13:12 +0000 Subject: (svn r16472) -Codechange: set vehicle type in SpecializedVehicle constructor instead of constructor of each vehicle type --- src/aircraft.h | 3 --- src/effectvehicle_base.h | 3 --- src/roadveh.h | 3 --- src/ship.h | 3 --- src/train.h | 3 --- src/vehicle.cpp | 4 ++-- src/vehicle_base.h | 10 ++++++---- 7 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/aircraft.h b/src/aircraft.h index 72343e6c5..1977b8249 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -100,9 +100,6 @@ struct Aircraft : public SpecializedVehicle { StationID targetairport; byte state; - /** Initializes the Vehicle to an aircraft */ - Aircraft() { this->type = VEH_AIRCRAFT; } - /** We want to 'destruct' the right class. */ virtual ~Aircraft() { this->PreDestructor(); } diff --git a/src/effectvehicle_base.h b/src/effectvehicle_base.h index 5340bdd5d..15c100b06 100644 --- a/src/effectvehicle_base.h +++ b/src/effectvehicle_base.h @@ -19,9 +19,6 @@ struct EffectVehicle : public SpecializedVehicle { uint16 animation_state; byte animation_substate; - /** Initializes the Vehicle to a special vehicle */ - EffectVehicle() { this->type = VEH_EFFECT; } - /** We want to 'destruct' the right class. */ virtual ~EffectVehicle() {} diff --git a/src/roadveh.h b/src/roadveh.h index f63cf02ee..7a248b8e7 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -133,9 +133,6 @@ struct RoadVehicle : public SpecializedVehicle { RoadType roadtype; RoadTypes compatible_roadtypes; - /** Initializes the Vehicle to a road vehicle */ - RoadVehicle() { this->type = VEH_ROAD; } - /** We want to 'destruct' the right class. */ virtual ~RoadVehicle() { this->PreDestructor(); } diff --git a/src/ship.h b/src/ship.h index 84bd7af57..7e1b2ec6d 100644 --- a/src/ship.h +++ b/src/ship.h @@ -20,9 +20,6 @@ void GetShipSpriteSize(EngineID engine, uint &width, uint &height); struct Ship: public SpecializedVehicle { TrackBitsByte state; - /** Initializes the Vehicle to a ship */ - Ship() { this->type = VEH_SHIP; } - /** We want to 'destruct' the right class. */ virtual ~Ship() { this->PreDestructor(); } diff --git a/src/train.h b/src/train.h index b38139e01..c1f9f120d 100644 --- a/src/train.h +++ b/src/train.h @@ -310,9 +310,6 @@ struct Train : public SpecializedVehicle { RailTypeByte railtype; RailTypes compatible_railtypes; - /** Initializes the Vehicle to a train */ - Train() { this->type = VEH_TRAIN; } - /** We want to 'destruct' the right class. */ virtual ~Train() { this->PreDestructor(); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2d673e86c..6e3d420bb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -188,9 +188,9 @@ bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle * } -Vehicle::Vehicle() +Vehicle::Vehicle(VehicleType type) { - this->type = VEH_INVALID; + this->type = type; this->coord.left = INVALID_COORD; this->group_id = DEFAULT_GROUP; this->fill_percent_te_id = INVALID_TE_ID; diff --git a/src/vehicle_base.h b/src/vehicle_base.h index e3659a009..581a55135 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -182,7 +182,7 @@ public: VehicleCache vcache; ///< Cache of often used calculated values /** Create a new vehicle */ - Vehicle(); + Vehicle(VehicleType type = VEH_INVALID); /** Destroy all stuff that (still) needs the virtual functions to work properly */ void PreDestructor(); @@ -502,6 +502,11 @@ template struct SpecializedVehicle : public Vehicle { static const VehicleType EXPECTED_TYPE = Type; ///< Specialized type + /** + * Set vehicle type correctly + */ + FORCEINLINE SpecializedVehicle() : Vehicle(Type) { } + /** * Get the first vehicle in the chain * @return first vehicle in the chain @@ -559,9 +564,6 @@ struct DisasterVehicle : public SpecializedVehicletype = VEH_DISASTER; } - /** We want to 'destruct' the right class. */ virtual ~DisasterVehicle() {} -- cgit v1.2.3-54-g00ecf