OpenTTD
|
CargoList that is used for stations. More...
#include <cargopacket.h>
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. | |
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. | |
void | Append (CargoPacket *cp, StationID next) |
Appends the given cargo packet to the range of packets with the same next station. | |
bool | HasCargoFor (StationIDStack next) const |
Check for cargo headed for a specific station. | |
StationID | Source () const |
Returns source of the first cargo packet in this list. | |
uint | AvailableCount () const |
Returns sum of cargo still available for loading at the sation. | |
uint | ReservedCount () const |
Returns sum of cargo reserved for loading onto vehicles. | |
uint | TotalCount () const |
Returns total count of cargo at the station, including cargo which is already reserved for loading. | |
uint | Reserve (uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next) |
Reserves cargo for loading onto the vehicle. | |
uint | Load (uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next) |
Loads cargo onto a vehicle. | |
uint | Truncate (uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=NULL) |
Truncates where each destination loses roughly the same percentage of its cargo. | |
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. | |
![]() | |
CargoList () | |
Create the cargo list. | |
void | OnCleanPool () |
const StationCargoPacketMap * | Packets () const |
Returns a pointer to the cargo packet list (so you can iterate over it etc). | |
uint | DaysInTransit () const |
Returns average number of days in transit for a cargo entity. | |
void | InvalidateCache () |
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? |
Protected Types | |
typedef CargoList < StationCargoList, StationCargoPacketMap > | Parent |
The (direct) parent of this class. |
Protected Attributes | |
uint | reserved_count |
Amount of cargo being reserved for loading. | |
![]() | |
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. | |
class | CargoLoad |
class | CargoTransfer |
class | CargoRemoval |
class | CargoReservation |
class | CargoReturn |
class | StationCargoReroute |
struct SaveLoad * | GetGoodsDesc () |
The stations, via GoodsEntry, have a CargoList. |
Additional Inherited Members | |
![]() | |
enum | MoveToAction |
Kind of actions that could be done with packets on move. More... | |
typedef StationCargoPacketMap::iterator | Iterator |
The iterator for our container. | |
typedef StationCargoPacketMap::reverse_iterator | ReverseIterator |
The reverse iterator for our container. | |
typedef StationCargoPacketMap::const_iterator | ConstIterator |
The const iterator for our container. | |
typedef StationCargoPacketMap::const_reverse_iterator | ConstReverseIterator |
The const reverse iterator for our container. | |
![]() | |
void | AddToCache (const CargoPacket *cp) |
void | RemoveFromCache (const CargoPacket *cp, uint count) |
![]() | |
static bool | TryMerge (CargoPacket *cp, CargoPacket *icp) |
CargoList that is used for stations.
Definition at line 463 of file cargopacket.h.
|
protected |
The (direct) parent of this class.
Definition at line 466 of file cargopacket.h.
void StationCargoList::Append | ( | CargoPacket * | cp, |
StationID | next | ||
) |
Appends the given cargo packet to the range of packets with the same next station.
next | the next hop |
cp | the cargo packet to add |
Definition at line 694 of file cargopacket.cpp.
References CargoList< StationCargoList, StationCargoPacketMap >::AddToCache(), CargoList< StationCargoList, StationCargoPacketMap >::packets, and CargoList< StationCargoList, StationCargoPacketMap >::TryMerge().
Referenced by CargoTransfer::operator()(), and CargoReturn::operator()().
|
inlinestatic |
Are two the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle?
cp1 | First CargoPacket. |
cp2 | Second CargoPacket. |
Definition at line 562 of file cargopacket.h.
References CargoPacket::days_in_transit, CargoPacket::source_id, CargoPacket::source_type, and CargoPacket::source_xy.
|
inline |
Returns sum of cargo still available for loading at the sation.
(i.e. not counting cargo which is already reserved for loading)
Definition at line 522 of file cargopacket.h.
References CargoList< StationCargoList, StationCargoPacketMap >::count.
Referenced by AfterLoadGame(), HandleStationRefit(), and LoadUnloadVehicle().
|
inline |
Check for cargo headed for a specific station.
next | Station the cargo is headed for. |
Definition at line 499 of file cargopacket.h.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty(), CargoList< StationCargoList, StationCargoPacketMap >::packets, and SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop().
Referenced by HandleStationRefit().
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.
max_move | Amount of cargo to load. |
dest | Vehicle cargo list where the cargo resides. |
load_place | The new loaded_at_xy to be assigned to packets being moved. |
next_station | Next station(s) the loading vehicle will visit. |
Definition at line 844 of file cargopacket.cpp.
References VehicleCargoList::ActionCount(), min(), CargoList< VehicleCargoList, CargoPacketList >::MTA_KEEP, CargoList< StationCargoList, StationCargoPacketMap >::MTA_LOAD, CargoList< VehicleCargoList, CargoPacketList >::MTA_LOAD, VehicleCargoList::Reassign(), reserved_count, and ShiftCargo().
Referenced by LoadUnloadVehicle().
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.
max_move | Maximum amount of cargo to move. |
dest | List to append the cargo to. |
avoid | Station to exclude from routing and current next hop of packets to reroute. |
avoid2 | Additional station to exclude from routing. ge GoodsEntry to get the routing info from. |
Definition at line 864 of file cargopacket.cpp.
References ShiftCargo().
Referenced by RerouteCargo().
uint StationCargoList::Reserve | ( | uint | max_move, |
VehicleCargoList * | dest, | ||
TileIndex | load_place, | ||
StationIDStack | next_station | ||
) |
Reserves cargo for loading onto the vehicle.
max_move | Maximum amount of cargo to reserve. |
dest | VehicleCargoList to reserve for. |
load_place | Tile index of the current station. |
next_station | Next station(s) the loading vehicle will visit. |
Definition at line 827 of file cargopacket.cpp.
References ShiftCargo().
Referenced by FinalizeRefitAction::operator()().
|
inline |
Returns sum of cargo reserved for loading onto vehicles.
Definition at line 531 of file cargopacket.h.
References reserved_count.
Referenced by StationViewWindow::BuildCargoList(), and StationViewWindow::DrawEntries().
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.
Taction | Action 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. |
action | Action instance to be applied. |
next | Next hop the cargo wants to visit. |
Definition at line 722 of file cargopacket.cpp.
References MultiMap< Tkey, Tvalue, Tcompare >::equal_range(), MultiMap< Tkey, Tvalue, Tcompare >::erase(), and CargoList< StationCargoList, StationCargoPacketMap >::packets.
Referenced by Load(), Reroute(), Reserve(), and ShiftCargo().
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.
Taction | Action 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. |
action | Action instance to be applied. |
next | Next hop the cargo wants to visit. |
include_invalid | If cargo from the INVALID_STATION list should be used if necessary. |
Definition at line 752 of file cargopacket.cpp.
References SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::IsEmpty(), SmallStack< Titem, Tindex, Tinvalid, Tgrowth_step, Tmax_size >::Pop(), and ShiftCargo().
|
inline |
Returns source of the first cargo packet in this list.
Definition at line 512 of file cargopacket.h.
References CargoList< StationCargoList, StationCargoPacketMap >::count, and CargoList< StationCargoList, StationCargoPacketMap >::packets.
|
inline |
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition at line 541 of file cargopacket.h.
References CargoList< StationCargoList, StationCargoPacketMap >::count, and reserved_count.
Referenced by CompanyStationsWindow::DrawWidget(), LoadUnloadVehicle(), StationResolverObject::ResolveReal(), StationResolverObject::StationResolverObject(), and TriggerStationRandomisation().
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.
max_move | Maximum amount of cargo to remove. |
cargo_per_source | Container for counting the cargo by origin. |
Definition at line 773 of file cargopacket.cpp.
References CargoPacket::count, CargoList< StationCargoList, StationCargoPacketMap >::count, MultiMap< Tkey, Tvalue, Tcompare >::erase(), min(), CargoList< StationCargoList, StationCargoPacketMap >::packets, RandomRange(), CargoPacket::Reduce(), CargoList< StationCargoList, StationCargoPacketMap >::RemoveFromCache(), and CargoPacket::source.
Referenced by MaybeCrashAirplane(), and TruncateCargo().
|
friend |
The super class ought to know what it's doing.
Definition at line 472 of file cargopacket.h.
|
friend |
The stations, via GoodsEntry, have a CargoList.
Definition at line 266 of file station_sl.cpp.