33 template <
class Tinst,
class Tcont>
class CargoList;
60 bool in_vehicle =
false;
67 template <
class Tinst,
class Tcont>
friend class CargoList;
114 this->source_xy = tile;
118 assert(!this->in_vehicle);
119 this->in_vehicle =
true;
137 assert(this->in_vehicle);
138 this->in_vehicle =
false;
151 this->feeder_share += new_share;
181 return this->feeder_share * part /
static_cast<uint
>(this->
count);
233 assert(this->in_vehicle);
240 local_travelled.x -=
TileX(current_tile);
241 local_travelled.y -=
TileY(current_tile);
259 uint distance_travelled =
abs(local_travelled.x) +
abs(local_travelled.y);
261 return std::min(distance_travelled, distance_source_dest);
282 template <
class Tinst,
class Tcont>
302 NUM_MOVE_TO_ACTION = MTA_END
340 return this->count == 0 ? 0 : this->cargo_periods_in_transit / this->
count;
346 typedef std::list<CargoPacket *> CargoPacketList;
359 template<
class Taction>
362 template<
class Taction>
370 assert(this->action_counts[
MTA_KEEP] +
383 StationID current_station,
bool accepted,
StationIDStack next_station);
396 template<
class Tsource>
407 return this->
count == 0 ? INVALID_STATION : this->
packets.front()->first_station;
426 return this->action_counts[action];
454 return this->action_counts[
MTA_LOAD];
498 template<MoveToAction Tfrom, MoveToAction Tto>
524 typedef std::map<StationID, uint> StationCargoAmountMap;
544 template<
class Tsource>
552 template<
class Taction>
553 bool ShiftCargo(Taction &action, StationID next);
555 template<
class Taction>
568 if (this->
packets.find(next.
Pop()) != this->packets.end())
return true;
571 return this->
packets.find(INVALID_STATION) != this->
packets.end();
580 return this->
count == 0 ? INVALID_STATION : this->
packets.begin()->second.front()->first_station;
618 uint
Truncate(uint
max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source =
nullptr);
Types related to cargoes...
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
uint16_t SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
SourceType
Types of cargo source and destination.
@ Industry
Source/destination is an industry.
CargoPacketPool _cargopacket_pool
The actual pool with cargo packets.
uint32_t CargoPacketID
Unique identifier for a single cargo packet.
SaveLoadTable GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
Pool< CargoPacket, CargoPacketID, 1024, 0xFFF000, PT_NORMAL, true, false > CargoPacketPool
Type of the pool for cargo packets for a little over 16 million packets.
Action of final delivery of cargo.
Simple collection class for a list of cargo packets.
Tcont::reverse_iterator ReverseIterator
The reverse iterator for our container.
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
MoveToAction
Kind of actions that could be done with packets on move.
@ MTA_KEEP
Keep the cargo in the vehicle.
@ MTA_DELIVER
Deliver the cargo to some town or industry.
@ MTA_LOAD
Load the cargo from the station.
@ MTA_TRANSFER
Transfer the cargo to the station.
Tcont packets
The cargo packets in this list.
~CargoList()
Destroy the cargolist ("frees" all cargo packets).
Tcont::const_iterator ConstIterator
The const iterator for our container.
uint count
Cache for the number of cargo entities.
CargoList()
Create the cargo list.
uint64_t cargo_periods_in_transit
Cache for the sum of number of cargo aging periods in transit of each entity; comparable to man-hours...
static bool TryMerge(CargoPacket *cp, CargoPacket *icp)
Tries to merge the second packet into the first and return if that was successful.
Tcont::iterator Iterator
The iterator for our container.
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Tcont::const_reverse_iterator ConstReverseIterator
The const reverse iterator for our container.
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
void InvalidateCache()
Invalidates the cached data and rebuilds it.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
Action of loading cargo from a station onto a vehicle.
uint max_move
Maximum amount of cargo to be moved with this action.
Abstract action of removing cargo from a vehicle or a station.
Action of reserving cargo from a station to be loaded onto a vehicle.
Action of returning previously reserved cargo from the vehicle to the station.
Action of shifting cargo from one vehicle to another.
Action of transferring cargo from a vehicle to a station.
Hand-rolled multimap as map of lists.
Minimal stack that uses a pool to avoid pointers.
Titem Pop()
Pop an item from the stack.
bool IsEmpty() const
Check if the stack is empty.
CargoList that is used for stations.
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile)
Reserves cargo for loading onto the vehicle.
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
bool ShiftCargo(Taction &action, StationID next)
Shifts cargo from the front of the packet list for a specific station and applies some action to it.
uint reserved_count
Amount of cargo being reserved for loading.
static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
Are the two CargoPackets mergeable in the context of a list of CargoPackets for a Station?
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile)
Loads cargo onto a vehicle.
bool HasCargoFor(StationIDStack next) const
Check for cargo headed for a specific station.
StationID GetFirstStation() const
Returns first station of the first cargo packet in this list.
Action of rerouting cargo in a station.
CargoList that is used for vehicles.
uint Shift(uint max_move, VehicleCargoList *dest)
Shifts cargo between two vehicles.
void AddToMeta(const CargoPacket *cp, MoveToAction action)
Adds a packet to the metadata.
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoID cargo, CargoPayment *payment, TileIndex current_tile)
Stages cargo for unloading.
void PopCargo(Taction action)
Pops cargo from the back of the packet list and applies some action to it.
Money GetFeederShare() const
Returns total sum of the feeder share for all packets.
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
uint Unload(uint max_move, StationCargoList *dest, CargoID cargo, CargoPayment *payment, TileIndex current_tile)
Unloads cargo at the given station.
void AssertCountConsistency() const
Assert that the designation counts add up.
void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count)
Removes a packet or part of it from the metadata.
uint Return(uint max_move, StationCargoList *dest, StationID next_station, TileIndex current_tile)
Returns reserved cargo to the station and removes it from the cache.
static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
Are the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle?
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
uint action_counts[NUM_MOVE_TO_ACTION]
Counts of cargo to be transferred, delivered, kept and loaded.
uint ReservedCount() const
Returns sum of reserved cargo.
static MoveToAction ChooseAction(const CargoPacket *cp, StationID cargo_next, StationID current_station, bool accepted, StationIDStack next_station)
Choose action to be performed with the given cargo packet.
uint RemainingCount() const
Returns the sum of cargo to be kept in the vehicle at the current station.
CargoList< VehicleCargoList, CargoPacketList > Parent
The (direct) parent of this class.
Money feeder_share
Cache for the feeder share.
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
uint Reassign(uint max_move)
Moves some cargo from one designation to another.
void InvalidateCache()
Invalidates the cached data and rebuild it.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
void KeepAll()
Marks all cargo in the vehicle as to be kept.
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
void AgeCargo()
Ages the all cargo in this list.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
void ShiftCargo(Taction action)
Shifts cargo from the front of the packet list and applies some action to it.
Action of rerouting cargo staged for transfer in a vehicle.
Types related to the economy.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Multimap with deterministic ordering of items with equal keys.
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
Functions/types related to saving and loading games.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Types related to stations.
Container for cargo from the same location and time.
void Reduce(uint count)
Reduce the packet by the given amount and remove the feeder share.
uint16_t Count() const
Gets the number of 'items' in this packet.
Money GetFeederShare(uint part) const
Gets part of the amount of money already paid to earlier vehicles in the feeder chain.
~CargoPacket()
Destroy the packet.
void Merge(CargoPacket *cp)
Merge another packet into this one.
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
static const uint16_t MAX_COUNT
Maximum number of items in a single cargo packet.
TileIndex source_xy
The origin of the cargo.
void SetNextHop(StationID next_hop)
Sets the station where the packet is supposed to go next.
SourceID source_id
Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
CargoPacket * Split(uint new_size)
Split this packet in two and return the split off part.
StationID next_hop
Station where the cargo wants to go next.
void UpdateLoadingTile(TileIndex tile)
Update for the cargo being loaded on this tile.
friend SaveLoadTable GetCargoPacketDesc()
We want this to be saved, right?
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
SourceID GetSourceID() const
Gets the ID of the cargo's source.
SourceType source_type
Type of source_id.
static void AfterLoad()
Savegame conversion for cargopackets.
StationID GetNextHop() const
Gets the ID of station the cargo wants to go next.
uint16_t count
The amount of cargo in this packet.
CargoPacket()
Create a new packet for savegame loading.
Money GetFeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
StationID GetFirstStation() const
Gets the ID of the station where the cargo was loaded for the first time.
uint GetDistance(TileIndex current_tile) const
Get the current distance the cargo has traveled.
StationID first_station
The station where the cargo came from first.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Vector travelled
If cargo is in station: the vector from the unload tile to the source tile. If in vehicle: an interme...
uint16_t GetPeriodsInTransit() const
Gets the number of cargo aging periods this cargo has been in transit.
void UpdateUnloadingTile(TileIndex tile)
Update for the cargo being unloaded on this tile.
SourceType GetSourceType() const
Gets the type of the cargo's source.
uint16_t periods_in_transit
Amount of cargo aging periods this packet has been in transit.
Helper class to perform the cargo payment.
Stores station stats for a single cargo.
Base class for all PoolItems.
Base class for all pools.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Types related to vehicles.