# CargoList Class Reference

Simple collection class for a list of cargo packets. More...

`#include <cargopacket.h>`

## Public Types
enum | MoveToAction { MTA_FINAL_DELIVERY, MTA_CARGO_LOAD, MTA_TRANSFER, MTA_UNLOAD }
| Kind of actions that could be done with packets on move. More...
typedef std::list< CargoPacket * > | List
| List of cargo packets.
## Public Member Functions
| CargoList ()
| Create the cargo list.
| ~CargoList ()
| And destroy it ("frees" all cargo packets).
const CargoList::List * | Packets () const
| Returns a pointer to the cargo packet list (so you can iterate over it etc).
void | AgeCargo ()
| Ages the all cargo in this list.
bool | Empty () const
| Checks whether this list is empty.
uint | Count () const
| Returns the number of cargo entities in this list.
Money | FeederShare () const
| Returns total sum of the feeder share for all packets.
StationID | Source () const
| Returns source of the first cargo packet in this list.
uint | DaysInTransit () const
| Returns average number of days in transit for a cargo entity.
void | Append (CargoPacket *cp)
| Appends the given cargo packet.
void | Truncate (uint count)
| Truncates the cargo in this list to the given amount.
bool | MoveTo (CargoList *dest, uint count, CargoList::MoveToAction mta, CargoPayment *payment, uint data=0)
| Moves the given amount of cargo to another list.
void | InvalidateCache ()
| Invalidates the cached data and rebuild it.
## Private Attributes
List | packets
| The cargo packets in this list.
bool | empty
| Cache for whether this list is empty or not.
uint | count
| Cache for the number of cargo entities.
Money | feeder_share
| Cache for the feeder share.
StationID | source
| Cache for the source of the packet.
uint | days_in_transit
| Cache for the number of days in transit.
## Friends
void | SaveLoad_STNS (Station *st)

## Detailed Description

Simple collection class for a list of cargo packets.

Definition at line 78 of file cargopacket.h.

## Member Enumeration Documentation

enum CargoList::MoveToAction

Kind of actions that could be done with packets on move.

Enumerator:

  MTA_FINAL_DELIVERY | "Deliver" the packet to the final destination, i.e. destroy the packet
  MTA_CARGO_LOAD | Load the packet onto a vehicle, i.e. set the last loaded station ID.
  MTA_TRANSFER | The cargo is moved as part of a transfer.
  MTA_UNLOAD | The cargo is moved as part of a forced unload.

Definition at line 84 of file cargopacket.h.

## Member Function Documentation

const CargoList::List * CargoList::Packets | ( |  | ) | const

Returns a pointer to the cargo packet list (so you can iterate over it etc).

Returns:
  pointer to the packet list

Definition at line 57 of file cargopacket.cpp.

References packets.

bool CargoList::Empty | ( |  | ) | const

Checks whether this list is empty.

Returns:
  true if and only if the list is empty

Definition at line 74 of file cargopacket.cpp.

References empty.

Referenced by MoveTo().

uint CargoList::Count | ( |  | ) | const

Returns the number of cargo entities in this list.

Returns:
  the before mentioned number

Definition at line 79 of file cargopacket.cpp.

References count.

Money CargoList::FeederShare | ( |  | ) | const

Returns total sum of the feeder share for all packets.

Returns:
  the before mentioned number

Definition at line 84 of file cargopacket.cpp.

References feeder_share.

StationID CargoList::Source | ( |  | ) | const

Returns source of the first cargo packet in this list.

Returns:
  the before mentioned source

Definition at line 89 of file cargopacket.cpp.

References source.

uint CargoList::DaysInTransit | ( |  | ) | const

Returns average number of days in transit for a cargo entity.

Returns:
  the before mentioned number

Definition at line 94 of file cargopacket.cpp.

References days_in_transit.

void CargoList::Append | ( | CargoPacket * | cp | ) |

Appends the given cargo packet.

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:

  | cp | the cargo packet to add

Precondition:
  cp != NULL

Definition at line 99 of file cargopacket.cpp.

References CargoPacket::count, CargoPacket::feeder_share, InvalidateCache(), CargoPacket::IsValid(), and packets.

Referenced by MoveTo().

void CargoList::Truncate | ( | uint | count | ) |

Truncates the cargo in this list to the given amount.

It leaves the first count cargo entities and removes the rest.

Parameters:

  | count | the maximum amount of entities to be in the list after the command

Definition at line 121 of file cargopacket.cpp.

References CargoPacket::count, InvalidateCache(), and packets.

bool CargoList::MoveTo | ( | CargoList * | dest,
|  | uint | count,
|  | CargoList::MoveToAction | mta,
|  | CargoPayment * | payment,
|  | uint | data = `0` |
| ) |  |  |

Moves the given amount of cargo to another list.

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

- MTA_FINAL_DELIVERY: destroys the packets that do not originate from a specific station
- MTA_CARGO_LOAD: sets the loaded_at_xy value of the moved packets
- MTA_TRANSFER: just move without side effects
- MTA_UNLOAD: just move without side effects
  Parameters:

    | dest | the destination to move the cargo to
    | count | the amount of cargo entities to move
    | mta | how to handle the moving (side effects)
    | data | Depending on mta the data of this variable differs: MTA_FINAL_DELIVERY - station ID of packet's origin not to remove MTA_CARGO_LOAD - station's tile index of load MTA_TRANSFER - unused MTA_UNLOAD - unused
    | payment | The payment helper

  Precondition:
    mta == MTA_FINAL_DELIVERY || dest != NULL

    mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL

  Returns:
    true if there are still packets that might be moved from this cargo list

Definition at line 144 of file cargopacket.cpp.

References Append(), CargoPacket::count, CargoPacket::days_in_transit, Empty(), CargoPacket::feeder_share, InvalidateCache(), CargoPacket::loaded_at_xy, MoveTo(), MTA_CARGO_LOAD, MTA_FINAL_DELIVERY, MTA_TRANSFER, MTA_UNLOAD, packets, CargoPayment::PayFinalDelivery(), CargoPayment::PayTransfer(), CargoPacket::source, and CargoPacket::source_xy.

Referenced by MoveTo().

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

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