35 template <
class Tinst,
class Tcont>
class CargoList;
39 typedef uint32 TileOrStationID;
59 template <
class Tinst,
class Tcont>
friend class CargoList;
124 return this->feeder_share * part /
static_cast<uint
>(this->
count);
202 #define FOR_ALL_CARGOPACKETS_FROM(var, start) FOR_ALL_ITEMS_FROM(CargoPacket, cargopacket_index, var, start) 208 #define FOR_ALL_CARGOPACKETS(var) FOR_ALL_CARGOPACKETS_FROM(var, 0) 214 template <
class Tinst,
class Tcont>
234 NUM_MOVE_TO_ACTION = MTA_END
245 void RemoveFromCache(
const CargoPacket *cp, uint count);
263 return &this->packets;
272 return this->count == 0 ? 0 : this->cargo_days_in_transit / this->
count;
275 void InvalidateCache();
278 typedef std::list<CargoPacket *> CargoPacketList;
289 uint action_counts[NUM_MOVE_TO_ACTION];
291 template<
class Taction>
292 void ShiftCargo(Taction action);
294 template<
class Taction>
295 void PopCargo(Taction action);
302 assert(this->action_counts[MTA_KEEP] +
303 this->action_counts[MTA_DELIVER] +
304 this->action_counts[MTA_TRANSFER] +
305 this->action_counts[MTA_LOAD] == this->
count);
311 void AddToMeta(
const CargoPacket *cp, MoveToAction action);
312 void RemoveFromMeta(
const CargoPacket *cp, MoveToAction action, uint count);
314 static MoveToAction ChooseAction(
const CargoPacket *cp, StationID cargo_next,
328 template<
class Tsource>
339 return this->count == 0 ? INVALID_STATION : this->packets.front()->source;
358 return this->action_counts[action];
368 return this->count - this->action_counts[MTA_LOAD];
386 return this->action_counts[MTA_LOAD];
395 return this->action_counts[MTA_TRANSFER] + this->action_counts[MTA_DELIVER];
404 return this->action_counts[MTA_KEEP] + this->action_counts[MTA_LOAD];
407 void Append(
CargoPacket *cp, MoveToAction action = MTA_KEEP);
411 void InvalidateCache();
424 this->action_counts[MTA_DELIVER] = this->action_counts[MTA_TRANSFER] = this->action_counts[MTA_LOAD] = 0;
425 this->action_counts[MTA_KEEP] = this->
count;
432 template<MoveToAction Tfrom, MoveToAction Tto>
437 uint Truncate(uint max_move = UINT_MAX);
458 typedef std::map<StationID, uint> StationCargoAmountMap;
478 template<
class Tsource>
486 template<
class Taction>
487 bool ShiftCargo(Taction &action, StationID next);
489 template<
class Taction>
490 uint ShiftCargo(Taction action,
StationIDStack next,
bool include_invalid);
502 if (this->packets.find(next.
Pop()) != this->packets.end())
return true;
505 return this->packets.find(INVALID_STATION) != this->packets.end();
514 return this->
count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->source;
533 return this->reserved_count;
543 return this->
count + this->reserved_count;
552 uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = NULL);
StationID Source() const
Returns source of the first cargo packet in this list.
uint RemainingCount() const
Returns the sum of cargo to be kept in the vehicle at the current station.
Action of rerouting cargo in a station.
uint cargo_days_in_transit
Cache for the sum of number of days in transit of each entity; comparable to man-hours.
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
const SaveLoad * GetVehicleDescription(VehicleType vt)
Make it possible to make the saveload tables "friends" of other classes.
Tcont::reverse_iterator ReverseIterator
The reverse iterator for our container.
Minimal stack that uses a pool to avoid pointers.
SourceTypeByte source_type
Type of source_id.
CargoList that is used for stations.
Pool< CargoPacket, CargoPacketID, 1024, 0xFFF000, PT_NORMAL, true, false > CargoPacketPool
Type of the pool for cargo packets for a little over 16 million packets.
StationID NextStation() const
Gets the ID of station the cargo wants to go next.
CargoPacket()
Create a new packet for savegame loading.
CargoList()
Create the cargo list.
Money FeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Action of shifting cargo from one vehicle to another.
void SetLoadPlace(TileIndex load_place)
Sets the tile where the packet was loaded last.
uint reserved_count
Amount of cargo being reserved for loading.
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading...
static void AfterLoad()
Savegame conversion for cargopackets.
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
CargoList< VehicleCargoList, CargoPacketList > Parent
The (direct) parent of this class.
Stores station stats for a single cargo.
Money FeederShare() const
Returns total sum of the feeder share for all packets.
TileIndex SourceStationXY() const
Gets the coordinates of the cargo's source station.
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
Action of rerouting cargo staged for transfer in a vehicle.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Types related to cargoes...
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
uint32 CargoPacketID
Unique identifier for a single cargo packet.
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
uint16 count
The amount of cargo in this packet.
SourceID SourceSubsidyID() const
Gets the ID of the cargo's source.
Tcont packets
The cargo packets in this list.
bool IsEmpty() const
Check if the stack is empty.
uint count
Cache for the number of cargo entities.
Hand-rolled multimap as map of lists.
Types related to stations.
SourceID source_id
Index of source, INVALID_SOURCE if unknown/invalid.
const SaveLoad * GetGoodsDesc()
Wrapper function to get the GoodsEntry's internal structure while some of the variables itself are pr...
byte DaysInTransit() const
Gets the number of days this cargo has been in transit.
~CargoPacket()
Destroy the packet.
Types related to the economy.
static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
Are two the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle...
VehicleType
Available vehicle types.
const struct SaveLoad * GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
Container for cargo from the same location and time.
StationID SourceStation() const
Gets the ID of the station where the cargo was loaded for the first time.
TileOrStationID next_station
Station where the cargo wants to go next.
static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
Are two the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle...
Titem Pop()
Pop an item from the stack.
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
void AssertCountConsistency() const
Assert that the designation counts add up.
CargoPacket * Split(uint new_size)
Split this packet in two and return the split off part.
static int Return(HSQUIRRELVM vm, T t)
To return a value to squirrel, we call this function.
SourceType SourceSubsidyType() const
Gets the type of the cargo's source.
Simple collection class for a list of cargo packets.
Helper class to perform the cargo payment.
Deliver the cargo to some town or industry.
Action of transferring cargo from a vehicle to a station.
MoveToAction
Kind of actions that could be done with packets on move.
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Base class for all PoolItems.
Action of reserving cargo from a station to be loaded onto a vehicle.
Base class for all pools.
SourceType
Types of cargo source and destination.
Keep the cargo in the vehicle.
TileIndex LoadedAtXY() const
Gets the coordinates of the cargo's last loading station.
StationID Source() const
Returns source of the first cargo packet in this list.
CargoList that is used for vehicles.
uint max_move
Maximum amount of cargo to be moved with this action.
Tcont::const_iterator ConstIterator
The const iterator for our container.
uint32 TileIndex
The index/ID of a Tile.
Action of returning previously reserved cargo from the vehicle to the station.
Source/destination is an industry.
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Types related to vehicles.
Abstract action of removing cargo from a vehicle or a station.
StationID source
The station where the cargo came from first.
CargoPacketPool _cargopacket_pool
The actual pool with cargo packets.
Tcont::const_reverse_iterator ConstReverseIterator
The const reverse iterator for our container.
Money feeder_share
Cache for the feeder share.
bool HasCargoFor(StationIDStack next) const
Check for cargo headed for a specific station.
void Reduce(uint count)
Reduce the packet by the given amount and remove the feeder share.
uint ReservedCount() const
Returns sum of reserved cargo.
Load the cargo from the station.
void KeepAll()
Marks all cargo in the vehicle as to be kept.
void Merge(CargoPacket *cp)
Merge another packet into this one.
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
friend const struct SaveLoad * GetCargoPacketDesc()
We want this to be saved, right?
uint16 Count() const
Gets the number of 'items' in this packet.
static const uint16 MAX_COUNT
Maximum number of items in a single cargo packet.
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
Multimap with deterministic ordering of items with equal keys.
Action of final delivery of cargo.
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
void SetNextStation(StationID next_station)
Sets the station where the packet is supposed to go next.
TileOrStationID loaded_at_xy
Location where this cargo has been loaded into the vehicle.
TileIndex source_xy
The origin of the cargo (first station in feeder chain).
Action of loading cargo from a station onto a vehicle.
Tcont::iterator Iterator
The iterator for our container.
Money FeederShare(uint part) const
Gets part of the amount of money already paid to earlier vehicles in the feeder chain.
byte days_in_transit
Amount of days this packet has been in transit.
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.