# cargopacket.h

Go to the documentation of this file.

    00001 /* $Id: cargopacket.h 14137 2008-08-23 09:31:53Z celestar $ */
    00002
    00005 #ifndef CARGOPACKET_H
    00006 #define CARGOPACKET_H
    00007
    00008 #include "oldpool.h"
    00009 #include "economy_type.h"
    00010 #include "tile_type.h"
    00011 #include "station_type.h"
    00012 #include <list>
    00013
    00014 typedef uint32 CargoPacketID;
    00015 struct CargoPacket;
    00016
    00018 DECLARE_OLD_POOL(CargoPacket, CargoPacket, 10, 1000)
    00019
    00020
    00021
    00024 struct CargoPacket : PoolItem<CargoPacket, CargoPacketID, &_CargoPacket_pool> {
    00025   Money feeder_share;
    00026   TileIndex source_xy;
    00027   TileIndex loaded_at_xy;
    00028   StationID source;
    00029
    00030   uint16 count;
    00031   byte days_in_transit;
    00032   bool paid_for;
    00033
    00040   CargoPacket(StationID source = INVALID_STATION, uint16 count = 0);
    00041
    00043   virtual ~CargoPacket();
    00044
    00045
    00050   inline bool IsValid() const { return this->count != 0; }
    00051
    00058   bool SameSource(const CargoPacket *cp) const;
    00059 };
    00060
    00066 #define FOR_ALL_CARGOPACKETS_FROM(cp, start) for (cp = GetCargoPacket(start); cp != NULL; cp = (cp->index + 1U < GetCargoPacketPoolSize()) ? GetCargoPacket(cp->index + 1U) : NULL) if (cp->IsValid())
    00067
    00072 #define FOR_ALL_CARGOPACKETS(cp) FOR_ALL_CARGOPACKETS_FROM(cp, 0)
    00073
    00074 extern void SaveLoad_STNS(Station *st);
    00075
    00079 class CargoList {
    00080 public:
    00082   typedef std::list<CargoPacket *> List;
    00083
    00085   enum MoveToAction {
    00086     MTA_FINAL_DELIVERY,
    00087     MTA_CARGO_LOAD,
    00088     MTA_OTHER
    00089   };
    00090
    00091 private:
    00092   List packets;
    00093
    00094   bool empty;
    00095   uint count;
    00096   bool unpaid_cargo;
    00097   Money feeder_share;
    00098   StationID source;
    00099   uint days_in_transit;
    00100
    00101 public:
    00102   friend void SaveLoad_STNS(Station *st);
    00103
    00105   CargoList() { this->InvalidateCache(); }
    00107   ~CargoList();
    00108
    00113   const CargoList::List *Packets() const;
    00114
    00118   void AgeCargo();
    00119
    00124   bool Empty() const;
    00125
    00130   uint Count() const;
    00131
    00136   bool UnpaidCargo() const;
    00137
    00142   Money FeederShare() const;
    00143
    00148   StationID Source() const;
    00149
    00154   uint DaysInTransit() const;
    00155
    00156
    00164   void Append(CargoPacket *cp);
    00165
    00171   void Truncate(uint count);
    00172
    00189   bool MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta = MTA_OTHER, uint data = 0);
    00190
    00192   void InvalidateCache();
    00193 };
    00194
    00195 #endif /* CARGOPACKET_H */