OpenTTD
Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes | Friends
StationCargoList Class Reference

CargoList that is used for stations. More...

#include <cargopacket.h>

Inheritance diagram for StationCargoList:
CargoList< StationCargoList, StationCargoPacketMap >

Public Member Functions

template<class Taction >
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. More...
 
template<class Taction >
uint ShiftCargo (Taction action, StationIDStack next, bool include_invalid)
 Shifts cargo from the front of the packet list for a specific station and and optional also from the list for "any station", then applies some action to it. More...
 
void Append (CargoPacket *cp, StationID next)
 Appends the given cargo packet to the range of packets with the same next station. More...
 
bool HasCargoFor (StationIDStack next) const
 Check for cargo headed for a specific station. More...
 
StationID Source () const
 Returns source of the first cargo packet in this list. More...
 
uint AvailableCount () const
 Returns sum of cargo still available for loading at the sation. More...
 
uint ReservedCount () const
 Returns sum of cargo reserved for loading onto vehicles. More...
 
uint TotalCount () const
 Returns total count of cargo at the station, including cargo which is already reserved for loading. More...
 
uint Reserve (uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
 Reserves cargo for loading onto the vehicle. More...
 
uint Load (uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
 Loads cargo onto a vehicle. More...
 
uint Truncate (uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=NULL)
 Truncates where each destination loses roughly the same percentage of its cargo. More...
 
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. More...
 
- Public Member Functions inherited from CargoList< StationCargoList, StationCargoPacketMap >
 CargoList ()
 Create the cargo list. More...
 
 ~CargoList ()
 Destroy the cargolist ("frees" all cargo packets).
 
void OnCleanPool ()
 Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket's CleanPool.
 
const StationCargoPacketMapPackets () const
 Returns a pointer to the cargo packet list (so you can iterate over it etc). More...
 
uint DaysInTransit () const
 Returns average number of days in transit for a cargo entity. More...
 
void InvalidateCache ()
 Invalidates the cached data and rebuilds it. More...
 

Static Public Member Functions

static void InvalidateAllFrom (SourceType src_type, SourceID src)
 
static bool AreMergable (const CargoPacket *cp1, const CargoPacket *cp2)
 Are two the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle? More...
 

Protected Types

typedef CargoList< StationCargoList, StationCargoPacketMapParent
 The (direct) parent of this class. More...
 

Protected Attributes

uint reserved_count
 Amount of cargo being reserved for loading.
 
- Protected Attributes inherited from CargoList< StationCargoList, StationCargoPacketMap >
uint count
 Cache for the number of cargo entities.
 
uint cargo_days_in_transit
 Cache for the sum of number of days in transit of each entity; comparable to man-hours.
 
StationCargoPacketMap packets
 The cargo packets in this list.
 

Friends

class CargoList< StationCargoList, StationCargoPacketMap >
 The super class ought to know what it's doing. More...
 
class CargoLoad
 
class CargoTransfer
 
template<class Tsource >
class CargoRemoval
 
class CargoReservation
 
class CargoReturn
 
class StationCargoReroute
 
const struct SaveLoadGetGoodsDesc ()
 The stations, via GoodsEntry, have a CargoList. More...
 

Additional Inherited Members

- Public Types inherited from CargoList< StationCargoList, StationCargoPacketMap >
enum  MoveToAction
 Kind of actions that could be done with packets on move. More...
 
typedef StationCargoPacketMap ::iterator Iterator
 The iterator for our container. More...
 
typedef StationCargoPacketMap ::reverse_iterator ReverseIterator
 The reverse iterator for our container. More...
 
typedef StationCargoPacketMap ::const_iterator ConstIterator
 The const iterator for our container. More...
 
typedef StationCargoPacketMap ::const_reverse_iterator ConstReverseIterator
 The const reverse iterator for our container. More...
 
- Protected Member Functions inherited from CargoList< StationCargoList, StationCargoPacketMap >
void AddToCache (const CargoPacket *cp)
 Update the cache to reflect adding of this packet. More...
 
void RemoveFromCache (const CargoPacket *cp, uint count)
 Update the cached values to reflect the removal of this packet or part of it. More...
 
- Static Protected Member Functions inherited from CargoList< StationCargoList, StationCargoPacketMap >
static bool TryMerge (CargoPacket *cp, CargoPacket *icp)
 Tries to merge the second packet into the first and return if that was successful. More...
 

Detailed Description

CargoList that is used for stations.

Definition at line 463 of file cargopacket.h.

Member Typedef Documentation

◆ Parent

The (direct) parent of this class.

Definition at line 466 of file cargopacket.h.

Member Function Documentation

◆ Append()

void StationCargoList::Append ( CargoPacket cp,
StationID  next 
)

Appends the given cargo packet to the range of packets with the same next station.

Warning
After appending this packet may not exist anymore!
Note
Do not use the cargo packet anymore after it has been appended to this CargoList!
Parameters
nextthe next hop
cpthe cargo packet to add
Precondition
cp != NULL

Definition at line 694 of file cargopacket.cpp.

◆ AreMergable()

static bool StationCargoList::AreMergable ( const CargoPacket cp1,
const CargoPacket cp2 
)
inlinestatic

Are two the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle?

Parameters
cp1First CargoPacket.
cp2Second CargoPacket.
Returns
True if they are mergeable.

Definition at line 562 of file cargopacket.h.

References CargoPacket::days_in_transit, CargoPacket::source_id, CargoPacket::source_type, and CargoPacket::source_xy.

◆ AvailableCount()

uint StationCargoList::AvailableCount ( ) const
inline

Returns sum of cargo still available for loading at the sation.

(i.e. not counting cargo which is already reserved for loading)

Returns
Cargo on board the vehicle.

Definition at line 522 of file cargopacket.h.

References CargoPacket::count.

◆ HasCargoFor()

bool StationCargoList::HasCargoFor ( StationIDStack  next) const
inline

Check for cargo headed for a specific station.

Parameters
nextStation the cargo is headed for.
Returns
If there is any cargo for that station.

Definition at line 499 of file cargopacket.h.

References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty(), and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop().

◆ Load()

uint StationCargoList::Load ( uint  max_move,
VehicleCargoList dest,
TileIndex  load_place,
StationIDStack  next_station 
)

Loads cargo onto a vehicle.

If the vehicle has reserved cargo load that. Otherwise load cargo from the station.

Parameters
max_moveAmount of cargo to load.
destVehicle cargo list where the cargo resides.
load_placeThe new loaded_at_xy to be assigned to packets being moved.
next_stationNext station(s) the loading vehicle will visit.
Returns
Amount of cargo actually loaded.
Note
Vehicles may or may not reserve, depending on their orders. The two modes of loading are exclusive, though. If cargo is reserved we don't need to load unreserved cargo.

Definition at line 844 of file cargopacket.cpp.

References VehicleCargoList::ActionCount(), min(), CargoList< VehicleCargoList, CargoPacketList >::MTA_KEEP, CargoList< VehicleCargoList, CargoPacketList >::MTA_LOAD, and VehicleCargoList::Reassign().

◆ Reroute()

uint StationCargoList::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.

Parameters
max_moveMaximum amount of cargo to move.
destList to append the cargo to.
avoidStation to exclude from routing and current next hop of packets to reroute.
avoid2Additional station to exclude from routing. ge GoodsEntry to get the routing info from.

Definition at line 864 of file cargopacket.cpp.

Referenced by RerouteCargo().

◆ Reserve()

uint StationCargoList::Reserve ( uint  max_move,
VehicleCargoList dest,
TileIndex  load_place,
StationIDStack  next_station 
)

Reserves cargo for loading onto the vehicle.

Parameters
max_moveMaximum amount of cargo to reserve.
destVehicleCargoList to reserve for.
load_placeTile index of the current station.
next_stationNext station(s) the loading vehicle will visit.
Returns
Amount of cargo actually reserved.

Definition at line 827 of file cargopacket.cpp.

Referenced by FinalizeRefitAction::operator()().

◆ ReservedCount()

uint StationCargoList::ReservedCount ( ) const
inline

Returns sum of cargo reserved for loading onto vehicles.

Returns
Cargo reserved for loading.

Definition at line 531 of file cargopacket.h.

◆ ShiftCargo() [1/2]

template<class Taction >
bool StationCargoList::ShiftCargo ( Taction &  action,
StationID  next 
)

Shifts cargo from the front of the packet list for a specific station and applies some action to it.

Template Parameters
TactionAction class or function to be used. It should define "bool operator()(CargoPacket *)". If true is returned the cargo packet will be removed from the list. Otherwise it will be kept and the loop will be aborted.
Parameters
actionAction instance to be applied.
nextNext hop the cargo wants to visit.
Returns
True if all packets with the given next hop have been removed, False otherwise.

Definition at line 722 of file cargopacket.cpp.

◆ ShiftCargo() [2/2]

template<class Taction >
uint StationCargoList::ShiftCargo ( Taction  action,
StationIDStack  next,
bool  include_invalid 
)

Shifts cargo from the front of the packet list for a specific station and and optional also from the list for "any station", then applies some action to it.

Template Parameters
TactionAction class or function to be used. It should define "bool operator()(CargoPacket *)". If true is returned the cargo packet will be removed from the list. Otherwise it will be kept and the loop will be aborted.
Parameters
actionAction instance to be applied.
nextNext hop the cargo wants to visit.
include_invalidIf cargo from the INVALID_STATION list should be used if necessary.
Returns
Amount of cargo actually moved.

Definition at line 752 of file cargopacket.cpp.

References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty(), and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop().

◆ Source()

StationID StationCargoList::Source ( ) const
inline

Returns source of the first cargo packet in this list.

Returns
The before mentioned source.

Definition at line 512 of file cargopacket.h.

References CargoPacket::count.

◆ TotalCount()

uint StationCargoList::TotalCount ( ) const
inline

Returns total count of cargo at the station, including cargo which is already reserved for loading.

Returns
Total cargo count.

Definition at line 541 of file cargopacket.h.

References CargoPacket::count, and CargoMovement< StationCargoList, StationCargoList >::max_move.

◆ Truncate()

uint StationCargoList::Truncate ( uint  max_move = UINT_MAX,
StationCargoAmountMap *  cargo_per_source = NULL 
)

Truncates where each destination loses roughly the same percentage of its cargo.

This is done by randomizing the selection of packets to be removed. Optionally count the cargo by origin station.

Parameters
max_moveMaximum amount of cargo to remove.
cargo_per_sourceContainer for counting the cargo by origin.
Returns
Amount of cargo actually moved.

Definition at line 773 of file cargopacket.cpp.

References CargoPacket::count, min(), RandomRange(), CargoPacket::Reduce(), and CargoPacket::source.

Referenced by TruncateCargo().

Friends And Related Function Documentation

◆ CargoList< StationCargoList, StationCargoPacketMap >

The super class ought to know what it's doing.

Definition at line 472 of file cargopacket.h.

◆ GetGoodsDesc

const struct SaveLoad* GetGoodsDesc ( )
friend

The stations, via GoodsEntry, have a CargoList.

Returns
the saveload description for GoodsEntry.

Definition at line 266 of file station_sl.cpp.


The documentation for this class was generated from the following files: