# cargopacket.h

Go to the documentation of this file.

    00001 /* $Id: cargopacket.h 16742 2009-07-04 17:39:00Z rubidium $ */
    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
    00039   CargoPacket(StationID source = INVALID_STATION, uint16 count = 0);
    00040
    00042   virtual ~CargoPacket();
    00043
    00044
    00049   inline bool IsValid() const { return this->count != 0; }
    00050
    00057   bool SameSource(const CargoPacket *cp) const;
    00058 };
    00059
    00065 #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())
    00066
    00071 #define FOR_ALL_CARGOPACKETS(cp) FOR_ALL_CARGOPACKETS_FROM(cp, 0)
    00072
    00073 extern void SaveLoad_STNS(Station *st);
    00074
    00078 class CargoList {
    00079 public:
    00081   typedef std::list<CargoPacket *> List;
    00082
    00084   enum MoveToAction {
    00085     MTA_FINAL_DELIVERY,
    00086     MTA_CARGO_LOAD,
    00087     MTA_TRANSFER,
    00088     MTA_UNLOAD,
    00089   };
    00090
    00091 private:
    00092   List packets;
    00093
    00094   bool empty;
    00095   uint count;
    00096   Money feeder_share;
    00097   StationID source;
    00098   uint days_in_transit;
    00099
    00100 public:
    00101   friend void SaveLoad_STNS(Station *st);
    00102
    00104   CargoList() { this->InvalidateCache(); }
    00106   ~CargoList();
    00107
    00112   const CargoList::List *Packets() const;
    00113
    00117   void AgeCargo();
    00118
    00123   bool Empty() const;
    00124
    00129   uint Count() const;
    00130
    00135   Money FeederShare() const;
    00136
    00141   StationID Source() const;
    00142
    00147   uint DaysInTransit() const;
    00148
    00149
    00157   void Append(CargoPacket *cp);
    00158
    00164   void Truncate(uint count);
    00165
    00187   bool MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, CargoPayment *payment, uint data = 0);
    00188
    00190   void InvalidateCache();
    00191 };
    00192
    00193 #endif /* CARGOPACKET_H */