diff options
Diffstat (limited to 'src/cargopacket.h')
-rw-r--r-- | src/cargopacket.h | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/cargopacket.h b/src/cargopacket.h index 2d5c824e9..90081855e 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -197,7 +197,6 @@ public: }; 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 @@ -251,15 +250,6 @@ public: } /** - * Returns total sum of the feeder share for all packets - * @return the before mentioned number - */ - FORCEINLINE Money FeederShare() const - { - return this->feeder_share; - } - - /** * Returns source of the first cargo packet in this list * @return the before mentioned source */ @@ -326,15 +316,49 @@ public: * CargoList that is used for vehicles. */ class VehicleCargoList : public CargoList<VehicleCargoList> { +protected: + /** The (direct) parent of this class */ + typedef CargoList<VehicleCargoList> Parent; + + Money feeder_share; ///< Cache for the feeder share + + /** + * Update the cache to reflect adding of this packet. + * Increases count, feeder share and days_in_transit + * @param cp a new packet to be inserted + */ + void AddToCache(const CargoPacket *cp); + + /** + * Update the cached values to reflect the removal of this packet. + * Decreases count, feeder share and days_in_transit + * @param cp Packet to be removed from cache + */ + void RemoveFromCache(const CargoPacket *cp); + public: + /** The super class ought to know what it's doing */ + friend class CargoList<VehicleCargoList>; /** The vehicles have a cargo list (and we want that saved). */ friend const struct SaveLoad *GetVehicleDescription(VehicleType vt); /** + * Returns total sum of the feeder share for all packets + * @return the before mentioned number + */ + FORCEINLINE Money FeederShare() const + { + return this->feeder_share; + } + + /** * Ages the all cargo in this list */ void AgeCargo(); + /** Invalidates the cached data and rebuild it */ + void InvalidateCache(); + /** * Are two the two CargoPackets mergeable in the context of * a list of CargoPackets for a Vehicle? @@ -357,6 +381,8 @@ public: */ class StationCargoList : public CargoList<StationCargoList> { public: + /** The super class ought to know what it's doing */ + friend class CargoList<StationCargoList>; /** The stations, via GoodsEntry, have a CargoList. */ friend const struct SaveLoad *GetGoodsDesc(); |