cargopacket.h
Go to the documentation of this file.00001
00002
00005 #ifndef CARGOPACKET_H
00006 #define CARGOPACKET_H
00007
00008 #include "economy_type.h"
00009 #include "tile_type.h"
00010 #include <list>
00011
00012 typedef uint32 CargoPacketID;
00013 struct CargoPacket;
00014
00016 DECLARE_OLD_POOL(CargoPacket, CargoPacket, 10, 1000)
00017
00018
00019
00022 struct CargoPacket : PoolItem<CargoPacket, CargoPacketID, &_CargoPacket_pool> {
00023 StationID source;
00024 TileIndex source_xy;
00025 TileIndex loaded_at_xy;
00026
00027 uint16 count;
00028 byte days_in_transit;
00029 Money feeder_share;
00030 bool paid_for;
00031
00038 CargoPacket(StationID source = INVALID_STATION, uint16 count = 0);
00039
00041 virtual ~CargoPacket();
00042
00043
00048 inline bool IsValid() const { return this->count != 0; }
00049
00056 bool SameSource(const CargoPacket *cp) const;
00057 };
00058
00064 #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())
00065
00070 #define FOR_ALL_CARGOPACKETS(cp) FOR_ALL_CARGOPACKETS_FROM(cp, 0)
00071
00072 extern void SaveLoad_STNS(Station *st);
00073
00077 class CargoList {
00078 public:
00080 typedef std::list<CargoPacket *> List;
00081
00083 enum MoveToAction {
00084 MTA_FINAL_DELIVERY,
00085 MTA_CARGO_LOAD,
00086 MTA_OTHER
00087 };
00088
00089 private:
00090 List packets;
00091
00092 bool empty;
00093 uint count;
00094 bool unpaid_cargo;
00095 Money feeder_share;
00096 StationID source;
00097 uint days_in_transit;
00098
00099 public:
00100 friend void SaveLoad_STNS(Station *st);
00101
00103 CargoList() { this->InvalidateCache(); }
00105 ~CargoList();
00106
00111 const CargoList::List *Packets() const;
00112
00116 void AgeCargo();
00117
00122 bool Empty() const;
00123
00128 uint Count() const;
00129
00134 bool UnpaidCargo() const;
00135
00140 Money FeederShare() const;
00141
00146 StationID Source() const;
00147
00152 uint DaysInTransit() const;
00153
00154
00162 void Append(CargoPacket *cp);
00163
00169 void Truncate(uint count);
00170
00187 bool MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta = MTA_OTHER, uint data = 0);
00188
00190 void InvalidateCache();
00191 };
00192
00193 #endif