# CargoPacket Struct Reference

Container for cargo from the same location and time. More...

`#include <cargopacket.h>`

Inheritance diagram for CargoPacket:

## Public Member Functions

| CargoPacket ()
| Create a new packet for savegame loading.
| CargoPacket (StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id)
| Creates a new cargo packet.
| CargoPacket (uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share=0, SourceType source_type=ST_INDUSTRY, SourceID source_id=INVALID_SOURCE)
| Creates a new cargo packet.
| ~CargoPacket ()
| Destroy the packet.
FORCEINLINE uint16 | Count () const
| Gets the number of 'items' in this packet.
FORCEINLINE Money | FeederShare () const
| Gets the amount of money already paid to earlier vehicles in the feeder chain.
FORCEINLINE byte | DaysInTransit () const
| Gets the number of days this cargo has been in transit.
FORCEINLINE SourceType | SourceSubsidyType () const
| Gets the type of the cargo's source.
FORCEINLINE SourceID | SourceSubsidyID () const
| Gets the ID of the cargo's source.
FORCEINLINE SourceID | SourceStation () const
| Gets the ID of the station where the cargo was loaded for the first time.
FORCEINLINE TileIndex | SourceStationXY () const
| Gets the coordinates of the cargo's source station.
FORCEINLINE TileIndex | LoadedAtXY () const
| Gets the coordinates of the cargo's last loading station.

## Static Public Member Functions

static void | InvalidateAllFrom (SourceType src_type, SourceID src)
| Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
static void | InvalidateAllFrom (StationID sid)
| Invalidates (sets source to INVALID_STATION) all cargo packets from given station.
static void | AfterLoad ()

## Static Public Attributes

static const uint16 | MAX_COUNT = UINT16_MAX
| Maximum number of items in a single cargo packet.

## Private Attributes

Money | feeder_share
| Value of feeder pickup to be paid for on delivery of cargo.
uint16 | count
| The amount of cargo in this packet.
byte | days_in_transit
| Amount of days this packet has been in transit.
SourceTypeByte | source_type
| Type of `source_id`.
SourceID | source_id
| Index of source, INVALID_SOURCE if unknown/invalid.
StationID | source
| The station where the cargo came from first.
TileIndex | source_xy
| The origin of the cargo (first station in feeder chain).
TileIndex | loaded_at_xy
| Location where this cargo has been loaded into the vehicle.

## Friends

class | CargoList
| The CargoList caches, thus needs to know about it.
class | VehicleCargoList
class | StationCargoList
struct SaveLoad * | GetCargoPacketDesc ()
| We want this to be saved, right?

## Detailed Description

Container for cargo from the same location and time.

Definition at line 37 of file cargopacket.h.

## Constructor & Destructor Documentation

CargoPacket::CargoPacket | ( | StationID | source,
|  | TileIndex | source_xy,
|  | uint16 | count,
|  | SourceType | source_type,
|  | SourceID | source_id |
| ) |  |  |

Creates a new cargo packet.

Parameters:

  | source | the source station of the packet
  | source_xy | the source location of the packet
  | count | the number of cargo entities to put in this packet
  | source_type | the 'type' of source the packet comes from (for subsidies)
  | source_id | the actual source of the packet (for subsidies)

Precondition:
  count != 0

Definition at line 36 of file cargopacket.cpp.

CargoPacket::CargoPacket | ( | uint16 | count,
|  | byte | days_in_transit,
|  | StationID | source,
|  | TileIndex | source_xy,
|  | TileIndex | loaded_at_xy,
|  | Money | feeder_share = `0`,
|  | SourceType | source_type = `ST_INDUSTRY`,
|  | SourceID | source_id = `INVALID_SOURCE` |
| ) |  |  |

Creates a new cargo packet.

Initializes the fields that cannot be changed later. Used when loading or splitting packets.

Parameters:

  | count | the number of cargo entities to put in this packet
  | days_in_transit | number of days the cargo has been in transit
  | source | the station the cargo was initially loaded
  | source_xy | the station location the cargo was initially loaded
  | loaded_at_xy | the location the cargo was loaded last
  | feeder_share | feeder share the packet has already accumulated
  | source_type | the 'type' of source the packet comes from (for subsidies)
  | source_id | the actual source of the packet (for subsidies)

Definition at line 49 of file cargopacket.cpp.

## Member Function Documentation

FORCEINLINE uint16 CargoPacket::Count | ( |  | ) | const`[inline]`

Gets the number of 'items' in this packet.

Returns:
  the item count

Definition at line 96 of file cargopacket.h.

References count.

Referenced by StationViewWindow::OrderWaitingCargo().

FORCEINLINE byte CargoPacket::DaysInTransit | ( |  | ) | const`[inline]`

Gets the number of days this cargo has been in transit.

This number isn't really in days, but in 2.5 days (185 ticks) and it is capped at 255.

Returns:
  the length this cargo has been in transit

Definition at line 117 of file cargopacket.h.

References days_in_transit.

Referenced by CargoPayment::PayFinalDelivery(), and CargoPayment::PayTransfer().

FORCEINLINE Money CargoPacket::FeederShare | ( |  | ) | const`[inline]`

Gets the amount of money already paid to earlier vehicles in the feeder chain.

Returns:
  the feeder share

Definition at line 106 of file cargopacket.h.

References feeder_share.

Referenced by CargoPayment::PayFinalDelivery().

void CargoPacket::InvalidateAllFrom | ( | StationID | sid | ) | `[static]`

Invalidates (sets source to INVALID_STATION) all cargo packets from given station.

Parameters:

  | sid | the station that gets removed

Definition at line 79 of file cargopacket.cpp.

References FOR_ALL_CARGOPACKETS, and source.

void CargoPacket::InvalidateAllFrom | ( | SourceType | src_type,
|  | SourceID | src |
| ) |  |  | `[static]`

Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.

Parameters:

  | src_type | type of source
  | src | index of source

Definition at line 67 of file cargopacket.cpp.

References FOR_ALL_CARGOPACKETS, INVALID_SOURCE, source_id, and source_type.

Referenced by DestroyCompanyHQ(), Station::~Station(), and Town::~Town().

FORCEINLINE TileIndex CargoPacket::LoadedAtXY | ( |  | ) | const`[inline]`

Gets the coordinates of the cargo's last loading station.

Returns:
  the last loading station's coordinates

Definition at line 162 of file cargopacket.h.

References loaded_at_xy.

Referenced by CargoPayment::PayTransfer().

FORCEINLINE SourceID CargoPacket::SourceStation | ( |  | ) | const`[inline]`

Gets the ID of the station where the cargo was loaded for the first time.

Returns:
  the StationID

Definition at line 144 of file cargopacket.h.

References source.

Referenced by StationViewWindow::OrderWaitingCargo().

FORCEINLINE TileIndex CargoPacket::SourceStationXY | ( |  | ) | const`[inline]`

Gets the coordinates of the cargo's source station.

Returns:
  the source station's coordinates

Definition at line 153 of file cargopacket.h.

References source_xy.

Referenced by CargoPayment::PayFinalDelivery().

FORCEINLINE SourceID CargoPacket::SourceSubsidyID | ( |  | ) | const`[inline]`

Gets the ID of the cargo's source.

An IndustryID, TownID or CompanyID

Returns:
  the source ID

Definition at line 135 of file cargopacket.h.

References source_id.

Referenced by CargoPayment::PayFinalDelivery().

FORCEINLINE SourceType CargoPacket::SourceSubsidyType | ( |  | ) | const`[inline]`

Gets the type of the cargo's source.

industry, town or head quarter

Returns:
  the source type

Definition at line 126 of file cargopacket.h.

References source_type.

Referenced by CargoPayment::PayFinalDelivery().

## Friends And Related Function Documentation

friend class CargoList `[friend]`

The CargoList caches, thus needs to know about it.

Definition at line 49 of file cargopacket.h.

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

We want this to be saved, right?

Returns:
  the saveload description for CargoPackets.

Definition at line 84 of file cargopacket_sl.cpp.

## Field Documentation

const uint16 CargoPacket::MAX_COUNT = UINT16_MAX`[static]`

Maximum number of items in a single cargo packet.

Definition at line 56 of file cargopacket.h.

Referenced by CargoList< Tinst >::Append().

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

- src/cargopacket.h
- src/cargopacket.cpp
- src/saveload/cargopacket_sl.cpp