1
0
Fork 0

(svn r16472) -Codechange: set vehicle type in SpecializedVehicle constructor instead of constructor of each vehicle type

release/1.0
smatz 2009-05-30 20:13:12 +00:00
parent 7633362912
commit 8c11d612e4
7 changed files with 8 additions and 21 deletions

View File

@ -100,9 +100,6 @@ struct Aircraft : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
StationID targetairport; StationID targetairport;
byte state; byte state;
/** Initializes the Vehicle to an aircraft */
Aircraft() { this->type = VEH_AIRCRAFT; }
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~Aircraft() { this->PreDestructor(); } virtual ~Aircraft() { this->PreDestructor(); }

View File

@ -19,9 +19,6 @@ struct EffectVehicle : public SpecializedVehicle<EffectVehicle, VEH_EFFECT> {
uint16 animation_state; uint16 animation_state;
byte animation_substate; byte animation_substate;
/** Initializes the Vehicle to a special vehicle */
EffectVehicle() { this->type = VEH_EFFECT; }
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~EffectVehicle() {} virtual ~EffectVehicle() {}

View File

@ -133,9 +133,6 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
RoadType roadtype; RoadType roadtype;
RoadTypes compatible_roadtypes; RoadTypes compatible_roadtypes;
/** Initializes the Vehicle to a road vehicle */
RoadVehicle() { this->type = VEH_ROAD; }
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~RoadVehicle() { this->PreDestructor(); } virtual ~RoadVehicle() { this->PreDestructor(); }

View File

@ -20,9 +20,6 @@ void GetShipSpriteSize(EngineID engine, uint &width, uint &height);
struct Ship: public SpecializedVehicle<Ship, VEH_SHIP> { struct Ship: public SpecializedVehicle<Ship, VEH_SHIP> {
TrackBitsByte state; TrackBitsByte state;
/** Initializes the Vehicle to a ship */
Ship() { this->type = VEH_SHIP; }
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~Ship() { this->PreDestructor(); } virtual ~Ship() { this->PreDestructor(); }

View File

@ -310,9 +310,6 @@ struct Train : public SpecializedVehicle<Train, VEH_TRAIN> {
RailTypeByte railtype; RailTypeByte railtype;
RailTypes compatible_railtypes; RailTypes compatible_railtypes;
/** Initializes the Vehicle to a train */
Train() { this->type = VEH_TRAIN; }
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~Train() { this->PreDestructor(); } virtual ~Train() { this->PreDestructor(); }

View File

@ -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->coord.left = INVALID_COORD;
this->group_id = DEFAULT_GROUP; this->group_id = DEFAULT_GROUP;
this->fill_percent_te_id = INVALID_TE_ID; this->fill_percent_te_id = INVALID_TE_ID;

View File

@ -182,7 +182,7 @@ public:
VehicleCache vcache; ///< Cache of often used calculated values VehicleCache vcache; ///< Cache of often used calculated values
/** Create a new vehicle */ /** Create a new vehicle */
Vehicle(); Vehicle(VehicleType type = VEH_INVALID);
/** Destroy all stuff that (still) needs the virtual functions to work properly */ /** Destroy all stuff that (still) needs the virtual functions to work properly */
void PreDestructor(); void PreDestructor();
@ -502,6 +502,11 @@ template <class T, VehicleType Type>
struct SpecializedVehicle : public Vehicle { struct SpecializedVehicle : public Vehicle {
static const VehicleType EXPECTED_TYPE = Type; ///< Specialized type static const VehicleType EXPECTED_TYPE = Type; ///< Specialized type
/**
* Set vehicle type correctly
*/
FORCEINLINE SpecializedVehicle<T, Type>() : Vehicle(Type) { }
/** /**
* Get the first vehicle in the chain * Get the first vehicle in the chain
* @return first vehicle in the chain * @return first vehicle in the chain
@ -559,9 +564,6 @@ struct DisasterVehicle : public SpecializedVehicle<DisasterVehicle, VEH_DISASTER
uint16 image_override; uint16 image_override;
VehicleID big_ufo_destroyer_target; VehicleID big_ufo_destroyer_target;
/** Initializes the Vehicle to a disaster vehicle */
DisasterVehicle() { this->type = VEH_DISASTER; }
/** We want to 'destruct' the right class. */ /** We want to 'destruct' the right class. */
virtual ~DisasterVehicle() {} virtual ~DisasterVehicle() {}