# 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_OTHER }
| 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.
bool | UnpaidCargo () const
| Is there some cargo that has not been paid for?
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=MTA_OTHER, 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.
bool | unpaid_cargo
| Cache for the unpaid cargo.
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 77 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_OTHER | "Just" move the packet to another cargo list

Definition at line 83 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 95 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 112 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 117 of file cargopacket.cpp.

References count.

bool CargoList::UnpaidCargo | ( |  | ) | const

Is there some cargo that has not been paid for?

Returns:
  true if and only if there is such a cargo

Definition at line 122 of file cargopacket.cpp.

References unpaid_cargo.

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

Returns total sum of the feeder share for all packets.

Returns:
  the before mentioned number

Definition at line 127 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 132 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 137 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 142 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 164 of file cargopacket.cpp.

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

bool CargoList::MoveTo | ( | CargoList * | dest,
|  | uint | count,
|  | CargoList::MoveToAction | mta = `MTA_OTHER`,
|  | 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_OTHER: 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_OTHER - unused
    | mta | == MTA_FINAL_DELIVERY || dest != NULL

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

Definition at line 187 of file cargopacket.cpp.

References Append(), CargoPacket::count, CargoPacket::days_in_transit, Empty(), CargoPacket::feeder_share, InvalidateCache(), CargoPacket::loaded_at_xy, MAX_UVALUE, MoveTo(), MTA_CARGO_LOAD, MTA_FINAL_DELIVERY, MTA_OTHER, packets, CargoPacket::paid_for, 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