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