Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends

# StationCargoList Class Reference

CargoList that is used for stations. More...

`#include <cargopacket.h>`

Inheritance diagram for StationCargoList:

## Public Member Functions
uint | TakeFrom (VehicleCargoList *source, uint max_unload, OrderUnloadFlags flags, StationID next_station, bool has_stopped, CargoPayment *payment)
| Moves the given amount of cargo from a vehicle to a station.
uint | MoveTo (VehicleCargoList *dest, uint cap, StationID next_station, bool reserve=false)
| Move suitable packets from this list to a vehicle.
void | Append (StationID next, CargoPacket *cp)
| Appends the given cargo packet to the range of packets with the same next station.
void | RerouteStalePackets (StationID to)
| Route all packets with station "to" as next hop to a different place.
void | CountAndTruncate (uint max_remaining, StationCargoAmountMap &cargo_per_source)
| Truncate where each destination loses roughly the same percentage of its cargo.
StationID | Source () const
| Returns source of the first cargo packet in this list.
void | AssignTo (Station *station, CargoID cargo)
| Assign the cargo list to a goods entry.
## Static Public Member Functions
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?
static void | InvalidateAllFrom (SourceType src_type, SourceID src)
## Protected Member Functions
byte | GetUnloadFlags (OrderUnloadFlags order_flags)
| build unload flags from order flags and station acceptance.
UnloadType | WillUnloadOld (byte flags, StationID source)
| Determine what a cargo packet arriving at the station this list belongs to will do, using the "old", non-cargodist algorithm.
UnloadType | WillUnloadCargoDist (byte flags, StationID next_station, StationID via, StationID source)
| Determine what a cargo packet arriving at the station this list belongs to will do, using the Cargodist algorithm.
uint | MovePackets (VehicleCargoList *dest, uint cap, Iterator begin, Iterator end, bool reserve)
| Move packets from a specific range in this list to a vehicle.
## Protected Attributes
Station * | station
| Station this cargo list belongs to.
CargoID | cargo
| Cargo type this list holds.
## Friends
class | CargoList< StationCargoList, StationCargoPacketMap >
| The super class ought to know what it's doing.
struct SaveLoad * | GetGoodsDesc ()
| The stations, via GoodsEntry, have a CargoList.

## Detailed Description

CargoList that is used for stations.

Definition at line 382 of file cargopacket.h.

## Member Function Documentation

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

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:

  | next | the next hop
  | cp | the cargo packet to add

Precondition:
  cp != NULL

Definition at line 733 of file cargopacket.cpp.

References CargoList< StationCargoList, StationCargoPacketMap >::AddToCache(), AreMergable(), CargoPacket::count, CargoPacket::MAX_COUNT, CargoPacket::Merge(), and CargoList< StationCargoList, StationCargoPacketMap >::packets.

Referenced by CargoList< Tinst, Tcont >::MovePacket(), VehicleCargoList::TransferPacket(), and VehicleCargoList::Unreserve().

static bool StationCargoList::AreMergable | ( | const CargoPacket * | cp1,
|  | const CargoPacket * | cp2 |
| ) |  |  | `[inline, static]`

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

Parameters:

  | cp1 | First CargoPacket.
  | cp2 | Second CargoPacket.

Returns:
  True if they are mergeable.

Definition at line 398 of file cargopacket.h.

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

Referenced by Append().

void StationCargoList::AssignTo | ( | Station * | station,
|  | CargoID | cargo |
| ) |  |  |

Assign the cargo list to a goods entry.

Parameters:

  | station | the station the cargo list is assigned to
  | cargo | the cargo the list is assigned to

Definition at line 870 of file cargopacket.cpp.

References INVALID_CARGO.

void StationCargoList::CountAndTruncate | ( | uint | max_remaining,
|  | StationCargoAmountMap & | cargo_per_source |
| ) |  |  |

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

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

Parameters:

  | max_remaining | Maximum amount of cargo to keep in the station.
  | cargo_per_source | Container for counting the cargo by origin list.

Definition at line 817 of file cargopacket.cpp.

References CargoList< StationCargoList, StationCargoPacketMap >::cargo_days_in_transit, CargoPacket::count, CargoList< StationCargoList, StationCargoPacketMap >::count, CargoPacket::days_in_transit, MultiMap< Tkey, Tvalue, Tcompare >::erase(), CargoList< StationCargoList, StationCargoPacketMap >::packets, CargoList< StationCargoList, StationCargoPacketMap >::RemoveFromCache(), and CargoPacket::source.

byte StationCargoList::GetUnloadFlags | ( | OrderUnloadFlags | order_flags | ) | `[inline, protected]`

build unload flags from order flags and station acceptance.

Parameters:

  | order_flags | order flags to check for forced transfer/deliver

Returns:
  some combination of UL_ACCEPTED, UL_DELIVER and UL_TRANSFER

Definition at line 710 of file cargopacket.cpp.

References GoodsEntry::acceptance_pickup, GoodsEntry::GES_ACCEPTANCE, Station::goods, HasBit(), OUFB_TRANSFER, OUFB_UNLOAD, and station.

Referenced by TakeFrom().

uint StationCargoList::MovePackets | ( | VehicleCargoList * | dest,
|  | uint | cap,
|  | Iterator | begin,
|  | Iterator | end,
|  | bool | reserve |
| ) |  |  | `[protected]`

Move packets from a specific range in this list to a vehicle.

Parameters:

  | dest | Cargo list the packets will be moved to.
  | cap | Maximum amount of cargo to move.
  | begin | Begin of the range to take packets from.
  | end | End of the range to take packets from.
  | reserve | If the packets should be loaded on or reserved for the vehicle.

Returns:
  Amount of cargo that has been moved.

Definition at line 760 of file cargopacket.cpp.

References CargoList< StationCargoList, StationCargoPacketMap >::MovePacket(), station, and BaseStation::xy.

Referenced by MoveTo().

uint StationCargoList::MoveTo | ( | VehicleCargoList * | dest,
|  | uint | cap,
|  | StationID | next,
|  | bool | reserve = `false` |
| ) |  |  |

Move suitable packets from this list to a vehicle.

Parameters:

  | dest | Vehicle cargo list to move packets to.
  | cap | Maximum amount of cargo to be moved.
  | next | Next station the vehicle will stop at.
  | reserve | If the packets should be loaded on or reserved for the vehicle.

Returns:
  Amount of cargo that has been moved.

Definition at line 777 of file cargopacket.cpp.

References MultiMap< Tkey, Tvalue, Tcompare >::equal_range(), MovePackets(), and CargoList< StationCargoList, StationCargoPacketMap >::packets.

Referenced by LoadUnloadVehicle(), and ReserveConsist().

void StationCargoList::RerouteStalePackets | ( | StationID | to | ) |

Route all packets with station "to" as next hop to a different place.

Parameters:

  | to | station to exclude from routing.

Definition at line 793 of file cargopacket.cpp.

References cargo, MultiMap< Tkey, Tvalue, Tcompare >::equal_range(), MultiMap< Tkey, Tvalue, Tcompare >::erase(), Station::goods, MultiMap< Tkey, Tvalue, Tcompare >::Insert(), CargoList< StationCargoList, StationCargoPacketMap >::packets, CargoPacket::source, and station.

Referenced by Station::RunAverages(), and Station::~Station().

StationID StationCargoList::Source | ( |  | ) | const`[inline]`

Returns source of the first cargo packet in this list.

Returns:
  The before mentioned source.

Definition at line 420 of file cargopacket.h.

References CargoList< StationCargoList, StationCargoPacketMap >::Empty(), and CargoList< StationCargoList, StationCargoPacketMap >::packets.

uint StationCargoList::TakeFrom | ( | VehicleCargoList * | source,
|  | uint | max_unload,
|  | OrderUnloadFlags | order_flags,
|  | StationID | next,
|  | bool | has_stopped,
|  | CargoPayment * | payment |
| ) |  |  |

Moves the given amount of cargo from a vehicle to a station.

Depending on the value of flags the side effects of this function differ:

- OUFB_UNLOAD_IF_POSSIBLE and dest->acceptance_pickup & GoodsEntry::GES_ACCEPTANCE: packets are accepted here and may be unloaded and/or delivered (=destroyed); if not using cargodist: all packets are unloaded and delivered if using cargodist: only packets which have this station as final destination are unloaded and delivered. if using cargodist: other packets may or may not be unloaded, depending on next_station. if GoodsEntry::GES_ACCEPTANCE is not set and using cargodist: packets may still be unloaded, but not delivered.
- OUFB_UNLOAD: unload all packets unconditionally; if OUF_UNLOAD_IF_POSSIBLE set and OUFB_TRANSFER not set: also deliver packets (no matter if using cargodist).
- OUFB_TRANSFER: don't deliver any packets; overrides delivering aspect of OUFB_UNLOAD_IF_POSSIBLE.
  Parameters:

    | source | Vehicle cargo list to take the cargo from.
    | max_unload | Maximum amount of cargo entities to move.
    | flags | How to handle the moving (side effects).
    | next | Next unloading station in the vehicle's order list.
    | has_stopped | Vehicle has stopped at this station before, so don't update the flow stats for kept cargo.
    | payment | Payment object to be updated when delivering/transferring.

  Returns:
    Number of cargo entities actually moved.

Definition at line 594 of file cargopacket.cpp.

References cargo, VehicleCargoList::DeliverPacket(), GoodsEntry::flows, GetUnloadFlags(), Station::goods, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, VehicleCargoList::KeepPacket(), CargoList< Tinst, Tcont >::packets, station, VehicleCargoList::TransferPacket(), UL_DELIVER, UL_KEEP, UL_TRANSFER, WillUnloadCargoDist(), and WillUnloadOld().

Referenced by LoadUnloadVehicle().

UnloadType StationCargoList::WillUnloadCargoDist | ( | byte | flags,
|  | StationID | next,
|  | StationID | via,
|  | StationID | source |
| ) |  |  | `[protected]`

Determine what a cargo packet arriving at the station this list belongs to will do, using the Cargodist algorithm.

Parameters:

  | flags | Unload flags telling if the cargo is accepted and what order flags there are.
  | next | Station the vehicle the cargo is coming from will visit next (or INVALID_STATION if unknown).
  | via | Station the cargo wants to go to next. If that is this station the cargo wants to be delivered.
  | source | ID of the packets source station.

Returns:
  Unload type (deliver, transfer, keep) telling what to do with the packet.

Definition at line 519 of file cargopacket.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, station, UL_ACCEPTED, UL_DELIVER, and UL_TRANSFER.

Referenced by TakeFrom().

UnloadType StationCargoList::WillUnloadOld | ( | byte | flags,
|  | StationID | source |
| ) |  |  | `[protected]`

Determine what a cargo packet arriving at the station this list belongs to will do, using the "old", non-cargodist algorithm.

Parameters:

  | flags | Unload flags telling if the cargo is accepted and what order flags there are.
  | source | ID of the packets source station.

Returns:
  Unload type (deliver, transfer, keep) telling what to do with the packet.

Definition at line 482 of file cargopacket.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, station, UL_ACCEPTED, UL_DELIVER, and UL_TRANSFER.

Referenced by TakeFrom().

## Friends And Related Function Documentation

friend class CargoList< StationCargoList, StationCargoPacketMap >`[friend]`

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

Definition at line 385 of file cargopacket.h.

struct SaveLoad* GetGoodsDesc | ( |  | ) | `[friend]`

The stations, via GoodsEntry, have a CargoList.

Returns:
  the saveload description for GoodsEntry.

Definition at line 284 of file station_sl.cpp.

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

- src/cargopacket.h
- src/cargopacket.cpp