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:

## 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, StationID 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 (StationID next) const
| Check for cargo headed for a specific station.
StationID | Source () const
| Returns source of the first cargo packet in this list.
uint | ReservedCount () const
| Returns sum of cargo reserved for loading onto vehicles.
uint | TotalCount () const
| Returns total count of cargo, including reserved cargo that's not actually in the list.
uint | Reserve (uint max_move, VehicleCargoList *dest, TileIndex load_place, StationID next)
| Reserves cargo for loading onto the vehicle.
uint | Load (uint max_move, VehicleCargoList *dest, TileIndex load_place, StationID 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.
## 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.
## 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 | CargoReroute
struct SaveLoad * | GetGoodsDesc ()
| The stations, via GoodsEntry, have a CargoList.

## Detailed Description

CargoList that is used for stations.

Definition at line 449 of file cargopacket.h.

## Member Typedef Documentation

typedef CargoList<StationCargoList, StationCargoPacketMap> StationCargoList::Parent`[protected]`

The (direct) parent of this class.

Definition at line 452 of file cargopacket.h.

## Member Function Documentation

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:

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

Precondition:
  cp != NULL

Definition at line 588 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()().

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 534 of file cargopacket.h.

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

bool StationCargoList::HasCargoFor | ( | StationID | next | ) | const`[inline]`

Check for cargo headed for a specific station.

Parameters:

  | next | Station the cargo is headed for.

Returns:
  If there is any cargo for that station.

Definition at line 485 of file cargopacket.h.

References CargoList< StationCargoList, StationCargoPacketMap >::packets.

Referenced by LoadUnloadVehicle().

uint StationCargoList::Load | ( | uint | max_move,
|  | VehicleCargoList * | dest,
|  | TileIndex | load_place,
|  | StationID | next_station |
| ) |  |  |

Loads cargo onto a vehicle.

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

Parameters:

  | dest | Vehicle cargo list where the cargo resides.
  | max_move | Amount of cargo to load.

Returns:
  Amount of cargo actually loaded.

Definition at line 730 of file cargopacket.cpp.

References VehicleCargoList::ActionCount(), CargoList< StationCargoList, StationCargoPacketMap >::count, min(), CargoList< VehicleCargoList, CargoPacketList >::MTA_KEEP, 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.

Parameters:

  | 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 751 of file cargopacket.cpp.

References ShiftCargo().

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

uint StationCargoList::Reserve | ( | uint | max_move,
|  | VehicleCargoList * | dest,
|  | TileIndex | load_place,
|  | StationID | next |
| ) |  |  |

Reserves cargo for loading onto the vehicle.

Parameters:

  | dest | VehicleCargoList to reserve for.
  | max_move | Maximum amount of cargo to reserve.
  | load_place | Tile index of the current station.

Returns:
  Amount of cargo actually reserved.

Definition at line 716 of file cargopacket.cpp.

References CargoList< StationCargoList, StationCargoPacketMap >::count, min(), and ShiftCargo().

Referenced by LoadUnloadVehicle(), and ReserveConsist().

uint StationCargoList::ReservedCount | ( |  | ) | const`[inline]`

Returns sum of cargo reserved for loading onto vehicles.

Returns:
  Cargo reserved for loading.

Definition at line 503 of file cargopacket.h.

References reserved_count.

Referenced by StationViewWindow::BuildCargoList(), and StationViewWindow::DrawEntries().

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:

  | 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.

Parameters:

  | action | Action instance to be applied.
  | next | Next hop the cargo wants to visit.

Returns:
  True if all packets with the given next hop have been removed, False otherwise.

Definition at line 616 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().

template<class Taction >

uint StationCargoList::ShiftCargo | ( | Taction | action,
|  | StationID | 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:

  | 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.

Parameters:

  | 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.

Returns:
  Amount of cargo actually moved.

Definition at line 646 of file cargopacket.cpp.

References ShiftCargo().

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

Returns source of the first cargo packet in this list.

Returns:
  The before mentioned source.

Definition at line 494 of file cargopacket.h.

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

uint StationCargoList::TotalCount | ( |  | ) | const`[inline]`

Returns total count of cargo, including reserved cargo that's not actually in the list.

Returns:
  Total cargo count.

Definition at line 513 of file cargopacket.h.

References CargoList< StationCargoList, StationCargoPacketMap >::count, and reserved_count.

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_move | Maximum amount of cargo to remove.
  | cargo_per_source | Container for counting the cargo by origin.

Returns:
  Amount of cargo actually moved.

Definition at line 663 of file cargopacket.cpp.

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

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

## Friends And Related Function Documentation

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

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

Definition at line 458 of file cargopacket.h.

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

The stations, via GoodsEntry, have a CargoList.

Returns:
  the saveload description for GoodsEntry.

Definition at line 262 of file station_sl.cpp.

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

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