src/vehicle.h
branchnoai
changeset 9701 d1ac22c62f64
parent 9694 e72987579514
child 9703 d2a6acdbd665
--- a/src/vehicle.h	Sun Aug 19 14:04:13 2007 +0000
+++ b/src/vehicle.h	Sun Sep 02 11:17:33 2007 +0000
@@ -218,13 +218,23 @@
 struct Vehicle;
 DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
 
+struct SaveLoad;
+const SaveLoad *GetVehicleDescription(VehicleType vt);
+void AfterLoadVehicles();
+
 struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
 	VehicleTypeByte type;    ///< Type of vehicle
 	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
 
-	Vehicle *next;           // next
+private:
+	Vehicle *next;           // pointer to the next vehicle in the chain
+	Vehicle *previous;       // NOSAVE: pointer to the previous vehicle in the chain
 	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
-	Vehicle *depot_list;     //NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
+public:
+	friend const SaveLoad *GetVehicleDescription(VehicleType vt); // So we can use private/protected variables in the saveload code
+	friend void AfterLoadVehicles();
+
+	Vehicle *depot_list;     // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
 
 	StringID string_id;      // Displayed string
 
@@ -347,11 +357,11 @@
 	/** Create a new vehicle */
 	Vehicle();
 
+	/** Destroy all stuff that (still) needs the virtual functions to work properly */
+	void PreDestructor();
 	/** We want to 'destruct' the right class. */
 	virtual ~Vehicle();
 
-	void QuickFree();
-
 	void BeginLoading();
 	void LeaveStation();
 
@@ -415,11 +425,77 @@
 	virtual int GetImage(Direction direction) const { return 0; }
 
 	/**
+	 * Gets the speed in mph that can be sent into SetDParam for string processing.
+	 * @return the vehicle's speed
+	 */
+	virtual int GetDisplaySpeed() const { return 0; }
+
+	/**
+	 * Gets the maximum speed in mph that can be sent into SetDParam for string processing.
+	 * @return the vehicle's maximum speed
+	 */
+	virtual int GetDisplayMaxSpeed() const { return 0; }
+
+	/**
+	 * Gets the running cost of a vehicle
+	 * @return the vehicle's running cost
+	 */
+	virtual Money GetRunningCost() const { return 0; }
+
+	/**
+	 * Check whether the vehicle is in the depot.
+	 * @return true if and only if the vehicle is in the depot.
+	 */
+	virtual bool IsInDepot() const { return false; }
+
+	/**
+	 * Check whether the vehicle is in the depot *and* stopped.
+	 * @return true if and only if the vehicle is in the depot and stopped.
+	 */
+	virtual bool IsStoppedInDepot() const { return this->IsInDepot() && (this->vehstatus & VS_STOPPED) != 0; }
+
+	/**
 	 * Calls the tick handler of the vehicle
 	 */
 	virtual void Tick() {};
 
-	bool IsValid() const { return this->type != VEH_INVALID; }
+	/**
+	 * Gets the running cost of a vehicle  that can be sent into SetDParam for string processing.
+	 * @return the vehicle's running cost
+	 */
+	Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
+
+	/**
+	 * Is this vehicle a valid vehicle?
+	 * @return true if and only if the vehicle is valid.
+	 */
+	inline bool IsValid() const { return this->type != VEH_INVALID; }
+
+	/**
+	 * Set the next vehicle of this vehicle.
+	 * @param next the next vehicle. NULL removes the next vehicle.
+	 */
+	void SetNext(Vehicle *next);
+
+	/**
+	 * Get the next vehicle of this vehicle.
+	 * @note articulated parts are also counted as vehicles.
+	 * @return the next vehicle or NULL when there isn't a next vehicle.
+	 */
+	inline Vehicle *Next() const { return this->next; }
+
+	/**
+	 * Get the previous vehicle of this vehicle.
+	 * @note articulated parts are also counted as vehicles.
+	 * @return the previous vehicle or NULL when there isn't a previous vehicle.
+	 */
+	inline Vehicle *Previous() const { return this->previous; }
+
+	/**
+	 * Get the first vehicle of this vehicle chain.
+	 * @return the first vehicle of the chain.
+	 */
+	inline Vehicle *First() const { return this->first; }
 };
 
 /**
@@ -496,10 +572,7 @@
 
 void VehicleServiceInDepot(Vehicle *v);
 void VehiclePositionChanged(Vehicle *v);
-void AfterLoadVehicles();
 Vehicle *GetLastVehicleInChain(Vehicle *v);
-Vehicle *GetPrevVehicleInChain(const Vehicle *v);
-Vehicle *GetFirstVehicleInChain(const Vehicle *v);
 uint CountVehiclesInChain(const Vehicle *v);
 bool IsEngineCountable(const Vehicle *v);
 void DeleteVehicleChain(Vehicle *v);
@@ -543,22 +616,17 @@
 void BeginVehicleMove(Vehicle *v);
 void EndVehicleMove(Vehicle *v);
 
-void ShowAircraftViewWindow(const Vehicle* v);
-
 UnitID GetFreeUnitNumber(VehicleType type);
 
 void TrainConsistChanged(Vehicle *v);
 void TrainPowerChanged(Vehicle *v);
 Money GetTrainRunningCost(const Vehicle *v);
 
-int CheckTrainStoppedInDepot(const Vehicle *v);
-
 bool VehicleNeedsService(const Vehicle *v);
 
 uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
 void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
-bool IsVehicleInDepot(const Vehicle *v);
 void VehicleEnterDepot(Vehicle *v);
 
 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g);
@@ -566,6 +634,8 @@
 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
 bool CanBuildVehicleInfrastructure(VehicleType type);
 
+void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
+
 /* Flags to add to p2 for goto depot commands */
 /* Note: bits 8-10 are used for VLW flags */
 enum {
@@ -599,7 +669,7 @@
 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
 
 #define BEGIN_ENUM_WAGONS(v) do {
-#define END_ENUM_WAGONS(v) } while ((v = v->next) != NULL);
+#define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL);
 
 static inline VehicleID GetMaxVehicleIndex()
 {