OpenTTD Source
20241121-master-g67a0fccfad
|
Container for cargo from the same location and time. More...
#include <cargopacket.h>
Data Structures | |
struct | Vector |
Public Member Functions | |
CargoPacket () | |
Create a new packet for savegame loading. | |
CargoPacket (StationID first_station, uint16_t count, SourceType source_type, SourceID source_id) | |
Creates a new cargo packet. More... | |
CargoPacket (uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share) | |
Create a new cargo packet. More... | |
CargoPacket (uint16_t count, Money feeder_share, CargoPacket &original) | |
Creates a new cargo packet. More... | |
~CargoPacket () | |
Destroy the packet. | |
CargoPacket * | Split (uint new_size) |
Split this packet in two and return the split off part. More... | |
void | Merge (CargoPacket *cp) |
Merge another packet into this one. More... | |
void | Reduce (uint count) |
Reduce the packet by the given amount and remove the feeder share. More... | |
void | SetNextHop (StationID next_hop) |
Sets the station where the packet is supposed to go next. More... | |
void | UpdateLoadingTile (TileIndex tile) |
Update for the cargo being loaded on this tile. More... | |
void | UpdateUnloadingTile (TileIndex tile) |
Update for the cargo being unloaded on this tile. More... | |
void | AddFeederShare (Money new_share) |
Adds some feeder share to the packet. More... | |
uint16_t | Count () const |
Gets the number of 'items' in this packet. More... | |
Money | GetFeederShare () const |
Gets the amount of money already paid to earlier vehicles in the feeder chain. More... | |
Money | GetFeederShare (uint part) const |
Gets part of the amount of money already paid to earlier vehicles in the feeder chain. More... | |
uint16_t | GetPeriodsInTransit () const |
Gets the number of cargo aging periods this cargo has been in transit. More... | |
SourceType | GetSourceType () const |
Gets the type of the cargo's source. More... | |
SourceID | GetSourceID () const |
Gets the ID of the cargo's source. More... | |
StationID | GetFirstStation () const |
Gets the ID of the station where the cargo was loaded for the first time. More... | |
uint | GetDistance (TileIndex current_tile) const |
Get the current distance the cargo has traveled. More... | |
StationID | GetNextHop () const |
Gets the ID of station the cargo wants to go next. More... | |
Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool > | |
void * | operator new (size_t size) |
Allocates space for new Titem. More... | |
void * | operator new (size_t size, size_t index) |
Allocates space for new Titem with given index. More... | |
void * | operator new (size_t, void *ptr) |
Allocates space for new Titem at given memory address. More... | |
void | operator delete (void *p) |
Marks Titem as free. More... | |
Static Public Member Functions | |
static void | InvalidateAllFrom (SourceType src_type, SourceID src) |
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source. More... | |
static void | InvalidateAllFrom (StationID sid) |
Invalidates (sets source to INVALID_STATION) all cargo packets from given station. More... | |
static void | AfterLoad () |
Savegame conversion for cargopackets. | |
Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool > | |
static bool | CanAllocateItem (size_t n=1) |
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() More... | |
static bool | CleaningPool () |
Returns current state of pool cleaning - yes or no. More... | |
static bool | IsValidID (size_t index) |
Tests whether given index can be used to get valid (non-nullptr) Titem. More... | |
static Titem * | Get (size_t index) |
Returns Titem with given index. More... | |
static Titem * | GetIfValid (size_t index) |
Returns Titem with given index. More... | |
static size_t | GetPoolSize () |
Returns first unused index. More... | |
static size_t | GetNumItems () |
Returns number of valid items in the pool. More... | |
static void | PostDestructor ([[maybe_unused]] size_t index) |
Dummy function called after destructor of each member. More... | |
static Pool::IterateWrapper< Titem > | Iterate (size_t from=0) |
Returns an iterable ensemble of all valid Titem. More... | |
Static Public Attributes | |
static const uint16_t | MAX_COUNT = UINT16_MAX |
Maximum number of items in a single cargo packet. | |
Private Attributes | |
uint16_t | count = 0 |
The amount of cargo in this packet. | |
uint16_t | periods_in_transit = 0 |
Amount of cargo aging periods this packet has been in transit. | |
Money | feeder_share = 0 |
Value of feeder pickup to be paid for on delivery of cargo. | |
TileIndex | source_xy = INVALID_TILE |
The origin of the cargo. | |
Vector | travelled {0, 0} |
If cargo is in station: the vector from the unload tile to the source tile. If in vehicle: an intermediate value. | |
SourceID | source_id = INVALID_SOURCE |
Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid. | |
SourceType | source_type = SourceType::Industry |
Type of source_id . | |
StationID | first_station = INVALID_STATION |
The station where the cargo came from first. | |
StationID | next_hop = INVALID_STATION |
Station where the cargo wants to go next. | |
Friends | |
template<class Tinst , class Tcont > | |
class | CargoList |
The CargoList caches, thus needs to know about it. | |
class | VehicleCargoList |
class | StationCargoList |
SaveLoadTable | GetCargoPacketDesc () |
We want this to be saved, right? More... | |
Additional Inherited Members | |
Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool > | |
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero > | Pool |
Type of the pool this item is going to be part of. | |
Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool > | |
Tindex | index |
Index of this pool item. | |
Container for cargo from the same location and time.
Definition at line 40 of file cargopacket.h.
CargoPacket::CargoPacket | ( | StationID | first_station, |
uint16_t | count, | ||
SourceType | source_type, | ||
SourceID | source_id | ||
) |
Creates a new cargo packet.
first_station | Source station of the packet. |
count | Number of cargo entities to put in this packet. |
source_type | 'Type' of source the packet comes from (for subsidies). |
source_id | Actual source of the packet (for subsidies). |
Definition at line 42 of file cargopacket.cpp.
CargoPacket::CargoPacket | ( | uint16_t | count, |
uint16_t | periods_in_transit, | ||
StationID | first_station, | ||
TileIndex | source_xy, | ||
Money | feeder_share | ||
) |
Create a new cargo packet.
Used for older savegames to load in their partial data.
count | Number of cargo entities to put in this packet. |
periods_in_transit | Number of cargo aging periods the cargo has been in transit. |
first_station | Station the cargo was initially loaded. |
source_xy | Station location the cargo was initially loaded. |
feeder_share | Feeder share the packet has already accumulated. |
Definition at line 60 of file cargopacket.cpp.
CargoPacket::CargoPacket | ( | uint16_t | count, |
Money | feeder_share, | ||
CargoPacket & | original | ||
) |
Creates a new cargo packet.
Used when loading or splitting packets.
count | Number of cargo entities to put in this packet. |
feeder_share | Feeder share the packet has already accumulated. |
original | The original packet we are splitting. |
Definition at line 77 of file cargopacket.cpp.
|
inline |
Adds some feeder share to the packet.
new_share | Feeder share to be added. |
Definition at line 149 of file cargopacket.h.
|
inline |
Gets the number of 'items' in this packet.
Definition at line 158 of file cargopacket.h.
Referenced by CargoTransfer::operator()(), CargoLoad::operator()(), CargoReservation::operator()(), CargoReturn::operator()(), CargoShift::operator()(), StationCargoReroute::operator()(), VehicleCargoReroute::operator()(), CargoRemoval< Tsource >::Postprocess(), CargoRemoval< VehicleCargoList >::Postprocess(), CargoRemoval< Tsource >::Preprocess(), and VehicleCargoList::Reassign< VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER >().
|
inline |
Get the current distance the cargo has traveled.
current_tile | Current tile of the cargo. |
Definition at line 229 of file cargopacket.h.
References abs(), DistanceManhattan(), INVALID_TILE, TileX(), TileY(), and travelled.
Referenced by CargoPayment::PayFinalDelivery().
|
inline |
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Definition at line 168 of file cargopacket.h.
References feeder_share.
Referenced by CargoList< VehicleCargoList, CargoPacketList >::InvalidateCache(), CargoPayment::PayFinalDelivery(), CargoPayment::PayTransfer(), Reduce(), and Split().
|
inline |
Gets part of the amount of money already paid to earlier vehicles in the feeder chain.
part | Amount of cargo to get the share for. |
Definition at line 179 of file cargopacket.h.
References count.
|
inline |
Gets the ID of the station where the cargo was loaded for the first time.
Definition at line 218 of file cargopacket.h.
References first_station.
Referenced by StationViewWindow::BuildCargoList(), StationCargoReroute::operator()(), and VehicleCargoReroute::operator()().
|
inline |
Gets the ID of station the cargo wants to go next.
Definition at line 268 of file cargopacket.h.
References next_hop.
Referenced by CargoTransfer::operator()(), and VehicleCargoReroute::operator()().
|
inline |
Gets the number of cargo aging periods this cargo has been in transit.
By default a period is 2.5 days (CARGO_AGING_TICKS = 185 ticks), however vehicle NewGRFs can overide the length of the cargo aging period. The value is capped at UINT16_MAX.
Definition at line 191 of file cargopacket.h.
Referenced by CargoPayment::PayFinalDelivery().
|
inline |
Gets the ID of the cargo's source.
An IndustryID, TownID or CompanyID.
Definition at line 209 of file cargopacket.h.
References source_id.
Referenced by CargoPayment::PayFinalDelivery().
|
inline |
Gets the type of the cargo's source.
industry, town or head quarter.
Definition at line 200 of file cargopacket.h.
References source_type.
Referenced by CargoPayment::PayFinalDelivery().
|
static |
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
src_type | Type of source. |
src | Index of source. |
Definition at line 137 of file cargopacket.cpp.
References INVALID_SOURCE, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool >::Iterate().
Referenced by Town::~Town().
|
static |
Invalidates (sets source to INVALID_STATION) all cargo packets from given station.
sid | Station that gets removed. |
Definition at line 148 of file cargopacket.cpp.
void CargoPacket::Merge | ( | CargoPacket * | cp | ) |
Merge another packet into this one.
cp | Packet to be merged in. |
Definition at line 114 of file cargopacket.cpp.
References count, and feeder_share.
Referenced by CargoList< Tinst, Tcont >::TryMerge().
void CargoPacket::Reduce | ( | uint | count | ) |
Reduce the packet by the given amount and remove the feeder share.
count | Amount to be removed. |
Definition at line 125 of file cargopacket.cpp.
References count, feeder_share, and GetFeederShare().
Referenced by CargoRemoval< Tsource >::Postprocess(), and StationCargoList::Truncate().
|
inline |
Sets the station where the packet is supposed to go next.
next_hop | Next station the packet should go to. |
Definition at line 92 of file cargopacket.h.
References next_hop.
Referenced by VehicleCargoReroute::operator()().
CargoPacket * CargoPacket::Split | ( | uint | new_size | ) |
Split this packet in two and return the split off part.
new_size | Size of the split part. |
Definition at line 99 of file cargopacket.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool >::CanAllocateItem(), CargoPacket(), count, feeder_share, and GetFeederShare().
Referenced by CargoRemoval< VehicleCargoList >::Postprocess(), and VehicleCargoList::Reassign< VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER >().
|
inline |
Update for the cargo being loaded on this tile.
When a CargoPacket is created, it is moved to a station. But at that moment in time it is not known yet at which tile the cargo will be picked up. As this tile is used for payment information, we delay setting the source_xy till first pickup, getting a better idea where a cargo started from.
Further more, we keep track of the amount of tiles the cargo moved inside a vehicle. This is used in GetDistance() below.
tile | Tile the cargo is being picked up from. |
Definition at line 111 of file cargopacket.h.
References INVALID_TILE, TileX(), TileY(), and travelled.
Referenced by CargoLoad::operator()(), and CargoReservation::operator()().
|
inline |
Update for the cargo being unloaded on this tile.
tile | Tile the cargo is being dropped off at. |
Definition at line 134 of file cargopacket.h.
References TileX(), TileY(), and travelled.
Referenced by CargoTransfer::operator()(), and CargoReturn::operator()().
|
friend |
We want this to be saved, right?
Definition at line 119 of file cargopacket_sl.cpp.