OpenTTD Source 20241224-master-gf74b0cf984
|
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. | |
CargoPacket (uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share) | |
Create a new cargo packet. | |
CargoPacket (uint16_t count, Money feeder_share, CargoPacket &original) | |
Creates a new cargo packet. | |
~CargoPacket () | |
Destroy the packet. | |
CargoPacket * | Split (uint new_size) |
Split this packet in two and return the split off part. | |
void | Merge (CargoPacket *cp) |
Merge another packet into this one. | |
void | Reduce (uint count) |
Reduce the packet by the given amount and remove the feeder share. | |
void | SetNextHop (StationID next_hop) |
Sets the station where the packet is supposed to go next. | |
void | UpdateLoadingTile (TileIndex tile) |
Update for the cargo being loaded on this tile. | |
void | UpdateUnloadingTile (TileIndex tile) |
Update for the cargo being unloaded on this tile. | |
void | AddFeederShare (Money new_share) |
Adds some feeder share to the packet. | |
uint16_t | Count () const |
Gets the number of 'items' in this packet. | |
Money | GetFeederShare () const |
Gets the amount of money already paid to earlier vehicles in the feeder chain. | |
Money | GetFeederShare (uint part) const |
Gets part of the amount of money already paid to earlier vehicles in the feeder chain. | |
uint16_t | GetPeriodsInTransit () const |
Gets the number of cargo aging periods this cargo has been in transit. | |
SourceType | GetSourceType () const |
Gets the type of the cargo's source. | |
SourceID | GetSourceID () const |
Gets the ID of the cargo's source. | |
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 | GetNextHop () const |
Gets the ID of station the cargo wants to go next. | |
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. | |
void * | operator new (size_t size, size_t index) |
Allocates space for new Titem with given index. | |
void * | operator new (size_t, void *ptr) |
Allocates space for new Titem at given memory address. | |
void | operator delete (void *p) |
Marks Titem as free. | |
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. | |
static void | InvalidateAllFrom (StationID sid) |
Invalidates (sets source to INVALID_STATION) all cargo packets from given station. | |
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() | |
static bool | CleaningPool () |
Returns current state of pool cleaning - yes or no. | |
static bool | IsValidID (size_t index) |
Tests whether given index can be used to get valid (non-nullptr) Titem. | |
static Titem * | Get (size_t index) |
Returns Titem with given index. | |
static Titem * | GetIfValid (size_t index) |
Returns Titem with given index. | |
static size_t | GetPoolSize () |
Returns first unused index. | |
static size_t | GetNumItems () |
Returns number of valid items in the pool. | |
static void | PostDestructor (size_t index) |
Dummy function called after destructor of each member. | |
static Pool::IterateWrapper< Titem > | Iterate (size_t from=0) |
Returns an iterable ensemble of all valid Titem. | |
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? | |
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 | ( | ) |
Create a new packet for savegame loading.
Definition at line 27 of file cargopacket.cpp.
References Industry, and INVALID_SOURCE.
Referenced by Split().
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.
References count.
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.
References count.
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.
References count.
|
inline |
Destroy the packet.
Definition at line 82 of file cargopacket.h.
|
inline |
Adds some feeder share to the packet.
new_share | Feeder share to be added. |
Definition at line 149 of file cargopacket.h.
Referenced by VehicleCargoList::Stage().
|
static |
Savegame conversion for cargopackets.
Definition at line 23 of file cargopacket_sl.cpp.
References first_station, SpecializedStation< Station, false >::Get(), INVALID_TILE, IsSavegameVersionBefore(), SpecializedStation< Station, false >::IsValidID(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool >::Iterate(), SLV_120, SLV_181, SLV_44, SLV_68, SLV_CARGO_TRAVELLED, source_xy, TileX(), TileY(), and BaseStation::xy.
Referenced by AfterLoadGame().
|
inline |
Gets the number of 'items' in this packet.
Definition at line 158 of file cargopacket.h.
References count.
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(), and CargoPayment::PayTransfer().
|
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< StationCargoList, StationCargoPacketMap >::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 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.
References periods_in_transit.
Referenced by CargoPayment::PayFinalDelivery(), and CargoPayment::PayTransfer().
|
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 Station::~Station(), and 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 |
The CargoList caches, thus needs to know about it.
Definition at line 67 of file cargopacket.h.
|
friend |
We want this to be saved, right?
Definition at line 119 of file cargopacket_sl.cpp.
|
friend |
Definition at line 69 of file cargopacket.h.
|
friend |
Definition at line 68 of file cargopacket.h.
|
private |
The amount of cargo in this packet.
Definition at line 48 of file cargopacket.h.
Referenced by CargoList< Tinst, Tcont >::AddToCache(), VehicleCargoList::AddToMeta(), VehicleCargoList::AgeCargo(), VehicleCargoList::Append(), CargoPacket(), CargoPacket(), CargoPacket(), Count(), GetFeederShare(), Merge(), Reduce(), Split(), VehicleCargoList::Stage(), StationCargoList::Truncate(), and CargoList< Tinst, Tcont >::TryMerge().
|
private |
Value of feeder pickup to be paid for on delivery of cargo.
Definition at line 51 of file cargopacket.h.
Referenced by VehicleCargoList::AddToCache(), GetFeederShare(), Merge(), Reduce(), and Split().
|
private |
The station where the cargo came from first.
Definition at line 63 of file cargopacket.h.
Referenced by AfterLoad(), VehicleCargoList::AreMergable(), StationCargoList::AreMergable(), VehicleCargoList::ChooseAction(), GetFirstStation(), VehicleCargoList::Stage(), and StationCargoList::Truncate().
|
static |
Maximum number of items in a single cargo packet.
Definition at line 74 of file cargopacket.h.
Referenced by CargoList< Tinst, Tcont >::TryMerge().
|
private |
Station where the cargo wants to go next.
Definition at line 64 of file cargopacket.h.
Referenced by GetNextHop(), SetNextHop(), VehicleCargoList::Stage(), and VehicleCargoList::Reassign< VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER >().
|
private |
Amount of cargo aging periods this packet has been in transit.
Definition at line 49 of file cargopacket.h.
Referenced by CargoList< Tinst, Tcont >::AddToCache(), VehicleCargoList::AgeCargo(), VehicleCargoList::AreMergable(), StationCargoList::AreMergable(), GetPeriodsInTransit(), and CargoList< Tinst, Tcont >::RemoveFromCache().
|
private |
Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
Definition at line 56 of file cargopacket.h.
Referenced by VehicleCargoList::AreMergable(), StationCargoList::AreMergable(), and GetSourceID().
|
private |
Type of source_id
.
Definition at line 57 of file cargopacket.h.
Referenced by VehicleCargoList::AreMergable(), StationCargoList::AreMergable(), and GetSourceType().
|
private |
The origin of the cargo.
Definition at line 53 of file cargopacket.h.
Referenced by AfterLoad(), VehicleCargoList::AreMergable(), and StationCargoList::AreMergable().
|
private |
If cargo is in station: the vector from the unload tile to the source tile. If in vehicle: an intermediate value.
Definition at line 54 of file cargopacket.h.
Referenced by GetDistance(), UpdateLoadingTile(), and UpdateUnloadingTile().