OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
33 template <
class Tinst,
class Tcont>
class CargoList;
37 typedef uint32 TileOrStationID;
57 template <
class Tinst,
class Tcont>
friend class CargoList;
122 return this->feeder_share * part /
static_cast<uint
>(this->
count);
199 template <
class Tinst,
class Tcont>
219 NUM_MOVE_TO_ACTION = MTA_END
257 return this->count == 0 ? 0 : this->cargo_days_in_transit / this->
count;
263 typedef std::list<CargoPacket *> CargoPacketList;
276 template<
class Taction>
279 template<
class Taction>
287 assert(this->action_counts[
MTA_KEEP] +
300 StationID current_station,
bool accepted,
StationIDStack next_station);
313 template<
class Tsource>
324 return this->
count == 0 ? INVALID_STATION : this->
packets.front()->source;
343 return this->action_counts[action];
371 return this->action_counts[
MTA_LOAD];
417 template<MoveToAction Tfrom, MoveToAction Tto>
443 typedef std::map<StationID, uint> StationCargoAmountMap;
463 template<
class Tsource>
471 template<
class Taction>
472 bool ShiftCargo(Taction &action, StationID next);
474 template<
class Taction>
487 if (this->
packets.find(next.
Pop()) != this->packets.end())
return true;
490 return this->
packets.find(INVALID_STATION) != this->
packets.end();
499 return this->
count == 0 ? INVALID_STATION : this->
packets.begin()->second.front()->source;
537 uint
Truncate(uint
max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source =
nullptr);
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
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.
uint32 TileIndex
The index/ID of a Tile.
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.
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment)
Unloads cargo at the given station.
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.
static bool TryMerge(CargoPacket *cp, CargoPacket *icp)
Tries to merge the second packet into the first and return if that was successful.
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment)
Stages cargo for unloading.
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.
StationID source
The station where the cargo came from first.
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.
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).
byte DaysInTransit() const
Gets the number of days this cargo has been in transit.
Action of returning previously reserved cargo from the vehicle to the station.
uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
Reserves cargo for loading onto the vehicle.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
byte days_in_transit
Amount of days this packet has been in transit.
TileOrStationID loaded_at_xy
Location where this cargo has been loaded into the vehicle.
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.
void Merge(CargoPacket *cp)
Merge another packet into this one.
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.
StationID Source() const
Returns source of the first cargo packet in this list.
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.
const struct SaveLoad * GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
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 (first station in feeder chain).
StationID SourceStation() const
Gets the ID of the station where the cargo was loaded for the first time.
friend const struct SaveLoad * GetGoodsDesc()
The stations, via GoodsEntry, have a CargoList.
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.
@ ST_INDUSTRY
Source/destination is an industry.
SourceID SourceSubsidyID() const
Gets the ID of the cargo's source.
uint cargo_days_in_transit
Cache for the sum of number of days in transit of each entity; comparable to man-hours.
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.
static const uint16 MAX_COUNT
Maximum number of items in a single cargo packet.
void SetTransferLoadPlace(TileIndex xy)
Sets loaded_at_xy to the current station for all cargo to be transferred.
SourceType SourceSubsidyType() const
Gets the type of the cargo's source.
SourceID source_id
Index of source, INVALID_SOURCE if unknown/invalid.
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
uint16 Count() const
Gets the number of 'items' in this 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.
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
VehicleType
Available vehicle types.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
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.
TileIndex LoadedAtXY() const
Gets the coordinates of the cargo's last loading station.
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Tcont packets
The cargo packets in this list.
Simple collection class for a list of cargo packets.
friend const struct SaveLoad * GetCargoPacketDesc()
We want this to be saved, right?
Stores station stats for a single cargo.
TileOrStationID next_station
Station where the cargo wants to go next.
SourceType
Types of cargo source and destination.
uint32 CargoPacketID
Unique identifier for a single cargo packet.
Base class for all pools.
Action of transferring cargo from a vehicle to a station.
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.
uint16 count
The amount of cargo in this packet.
void SetNextStation(StationID next_station)
Sets the station where the packet is supposed to go next.
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
void SetLoadPlace(TileIndex load_place)
Sets the tile where the packet was loaded last.
StationID Source() const
Returns source of the first cargo packet in this list.
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?
StationID NextStation() const
Gets the ID of station the cargo wants to go next.
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.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
uint Reassign(uint max_move, TileOrStationID update=INVALID_TILE)
Moves some cargo from one designation to another.
@ 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.
friend const struct SaveLoad * GetVehicleDescription(VehicleType vt)
The vehicles have a cargo list (and we want that saved).
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
void PopCargo(Taction action)
Pops cargo from the back of the packet list and applies some action to it.
Money FeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Action of rerouting cargo in a station.
Hand-rolled multimap as map of lists.
uint Return(uint max_move, StationCargoList *dest, StationID next_station)
Returns reserved cargo to the station and removes it from the cache.
Tcont::const_reverse_iterator ConstReverseIterator
The const reverse iterator for our container.
Money FeederShare() const
Returns total sum of the feeder share for all packets.
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.
CargoPacket()
Create a new packet for savegame loading.
Money FeederShare(uint part) const
Gets part of the amount of money already paid to earlier vehicles in the feeder chain.
uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
Loads cargo onto a vehicle.
Action of loading cargo from a station onto a vehicle.
TileIndex SourceStationXY() const
Gets the coordinates of the cargo's source station.
~CargoPacket()
Destroy the packet.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.