changeset 13286:58de76f90067 draft

(svn r17795) -Codechange: split cargolist into one for vehicles and one for stations.
author rubidium <rubidium@openttd.org>
date Sun, 18 Oct 2009 13:39:00 +0000
parents eb90f715c80f
children 3d2992db532c
files src/cargopacket.cpp src/cargopacket.h src/station_base.h src/vehicle_base.h
diffstat 4 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/cargopacket.cpp
+++ b/src/cargopacket.cpp
@@ -90,7 +90,7 @@
 	this->cargo_days_in_transit += cp->days_in_transit * cp->count;
 }
 
-void CargoList::AgeCargo()
+void VehicleCargoList::AgeCargo()
 {
 	for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) {
 		/* If we're at the maximum, then we can't increase no more. */
--- a/src/cargopacket.h
+++ b/src/cargopacket.h
@@ -45,6 +45,8 @@
 
 	/** The CargoList caches, thus needs to know about it. */
 	friend class CargoList;
+	friend class VehicleCargoList;
+	friend class StationCargoList;
 	/** We want this to be saved, right? */
 	friend const struct SaveLoad *GetCargoPacketDesc();
 public:
@@ -143,9 +145,6 @@
  */
 #define FOR_ALL_CARGOPACKETS(var) FOR_ALL_CARGOPACKETS_FROM(var, 0)
 
-extern const struct SaveLoad *GetGoodsDesc();
-extern const SaveLoad *GetVehicleDescription(VehicleType vt);
-
 /**
  * Simple collection class for a list of cargo packets
  */
@@ -162,7 +161,7 @@
 		MTA_UNLOAD,         ///< The cargo is moved as part of a forced unload
 	};
 
-private:
+protected:
 	Money feeder_share;         ///< Cache for the feeder share
 	uint count;                 ///< Cache for the number of cargo entities
 	uint cargo_days_in_transit; ///< Cache for the sum of number of days in transit of each entity; comparable to man-hours
@@ -184,11 +183,6 @@
 	void RemoveFromCache(const CargoPacket *cp);
 
 public:
-	/** The stations, via GoodsEntry, have a CargoList. */
-	friend const struct SaveLoad *GetGoodsDesc();
-	/** The vehicles have a cargo list too. */
-	friend const SaveLoad *GetVehicleDescription(VehicleType vt);
-
 	/** Create the cargo list */
 	FORCEINLINE CargoList() { this->InvalidateCache(); }
 	/** And destroy it ("frees" all cargo packets) */
@@ -297,4 +291,27 @@
 	void InvalidateCache();
 };
 
+/**
+ * CargoList that is used for vehicles.
+ */
+class VehicleCargoList : public CargoList {
+public:
+	/** The vehicles have a cargo list (and we want that saved). */
+	friend const struct SaveLoad *GetVehicleDescription(VehicleType vt);
+
+	/**
+	 * Ages the all cargo in this list
+	 */
+	void AgeCargo();
+};
+
+/**
+ * CargoList that is used for stations.
+ */
+class StationCargoList : public CargoList {
+public:
+	/** The stations, via GoodsEntry, have a CargoList. */
+	friend const struct SaveLoad *GetGoodsDesc();
+};
+
 #endif /* CARGOPACKET_H */
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -44,7 +44,7 @@
 	byte rating;
 	byte last_speed;
 	byte last_age;
-	CargoList cargo; ///< The cargo packets of cargo waiting in this station
+	StationCargoList cargo; ///< The cargo packets of cargo waiting in this station
 };
 
 
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -166,7 +166,7 @@
 	CargoID cargo_type;      ///< type of cargo this vehicle is carrying
 	byte cargo_subtype;      ///< Used for livery refits (NewGRF variations)
 	uint16 cargo_cap;        ///< total capacity
-	CargoList cargo;         ///< The cargo this vehicle is carrying
+	VehicleCargoList cargo;  ///< The cargo this vehicle is carrying
 
 	byte day_counter;        ///< Increased by one for each day
 	byte tick_counter;       ///< Increased by one for each tick