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

# VehicleCargoList Class Reference

CargoList that is used for vehicles. More...

`#include <cargopacket.h>`

Inheritance diagram for VehicleCargoList:

## Public Member Functions
| ~VehicleCargoList ()
| Delete a vehicle cargo list and clear its reservation list.
void | OnCleanPool ()
| Additionally empty the reservation list for vehicle cargo lists.
Money | FeederShare () const
| Returns total sum of the feeder share for all packets.
void | Append (CargoPacket *cp, bool update_cache=true)
| Appends the given cargo packet.
uint | OnboardCount () const
| Returns sum of cargo on board the vehicle (ie not only reserved).
uint | ReservedCount () const
| Returns sum of cargo reserved for the vehicle.
const CargoPacketList * | Reserved () const
| Returns a pointer to the reserved cargo list.
StationID | Source () const
| Returns source of the first cargo packet in this list.
void | Reserve (CargoPacket *cp)
| Reserves a packet for later loading and adds it to the cache.
void | Unreserve (StationID next, StationCargoList *dest)
| Returns all reserved cargo to the station and removes it from the cache.
uint | LoadReserved (uint count)
| Load packets from the reservation list.
void | SwapReserved ()
| Swap the reserved and packets lists when starting to load cargo.
void | AgeCargo ()
| Ages the all cargo in this list.
void | InvalidateCache ()
| Invalidates the cached data and rebuilds it.
uint | MoveTo (VehicleCargoList *dest, uint cap)
| Moves the given amount of cargo to another vehicle (during autoreplace).
## 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?
## Protected Types
typedef CargoList < VehicleCargoList, CargoPacketList > | Parent
| The (direct) parent of this class.
## Protected Member Functions
uint | TransferPacket (Iterator &c, uint remaining_unload, StationCargoList *dest, CargoPayment *payment, StationID next)
| Transfer a packet to a station, but don't deliver it.
uint | DeliverPacket (Iterator &c, uint remaining_unload, CargoPayment *payment)
| Deliver a specific packet or part of it to a station and handle payment.
uint | KeepPacket (Iterator &c)
| Keep a packet in the vehicle while unloading by temporarily moving it to the reservation list.
void | AddToCache (const CargoPacket *cp)
| Update the cache to reflect adding of this packet.
void | RemoveFromCache (const CargoPacket *cp)
| Update the cached values to reflect the removal of this packet.
## Protected Attributes
CargoPacketList | reserved
| Packets reserved for unloading in this list.
Money | feeder_share
| Cache for the feeder share.
uint | reserved_count
| Cache for the number of reserved cargo entities.
## Friends
class | StationCargoList
| The station cargo list needs to control the unloading.
class | CargoList< VehicleCargoList, CargoPacketList >
| The super class ought to know what it's doing.
struct SaveLoad * | GetVehicleDescription (VehicleType vt)
| The vehicles have a cargo list (and we want that saved).

## Detailed Description

CargoList that is used for vehicles.

Definition at line 260 of file cargopacket.h.

## Member Typedef Documentation

typedef CargoList<VehicleCargoList, CargoPacketList> VehicleCargoList::Parent`[protected]`

The (direct) parent of this class.

Definition at line 267 of file cargopacket.h.

## Member Function Documentation

void VehicleCargoList::AddToCache | ( | const CargoPacket * | cp | ) | `[protected]`

Update the cache to reflect adding of this packet.

Increases count, feeder share and days_in_transit.

Parameters:

  | cp | New packet to be inserted.

Reimplemented from CargoList< VehicleCargoList, CargoPacketList >.

Definition at line 662 of file cargopacket.cpp.

References CargoList< VehicleCargoList, CargoPacketList >::AddToCache(), CargoPacket::feeder_share, and feeder_share.

Referenced by Append(), InvalidateCache(), and Reserve().

void VehicleCargoList::Append | ( | CargoPacket * | cp,
|  | bool | update_cache = `true` |
| ) |  |  |

Appends the given cargo packet.

Tries to merge it with another one in the packets list. If no fitting packet is found, appends it.

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 | Cargo packet to add.
  | update_cache | If false, the cache is not updated; used when loading from the reservation list.

Precondition:
  cp != NULL

Definition at line 195 of file cargopacket.cpp.

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

Referenced by Load_VEHS(), LoadOldVehicle(), LoadReserved(), and CargoList< Tinst, Tcont >::MovePacket().

static bool VehicleCargoList::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 366 of file cargopacket.h.

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

Referenced by Append().

uint VehicleCargoList::DeliverPacket | ( | Iterator & | it,
|  | uint | cap,
|  | CargoPayment * | payment |
| ) |  |  | `[protected]`

Deliver a specific packet or part of it to a station and handle payment.

The given iterator is incremented in the process.

Parameters:

  | it | Iterator pointing to the packet to be delivered.
  | cap | Maximum amount of cargo to be unloaded.
  | payment | Payment object to use for payment.

Returns:
  Amount of cargo actually unloaded.

Definition at line 415 of file cargopacket.cpp.

References CargoList< VehicleCargoList, CargoPacketList >::cargo_days_in_transit, CargoList< VehicleCargoList, CargoPacketList >::count, CargoPacket::count, CargoPacket::days_in_transit, CargoPacket::feeder_share, feeder_share, CargoList< VehicleCargoList, CargoPacketList >::packets, CargoPayment::PayFinalDelivery(), and RemoveFromCache().

Referenced by StationCargoList::TakeFrom().

Money VehicleCargoList::FeederShare | ( |  | ) | const`[inline]`

Returns total sum of the feeder share for all packets.

Returns:
  The before mentioned number.

Definition at line 292 of file cargopacket.h.

References feeder_share.

Referenced by DrawRoadVehDetails(), and DrawShipDetails().

uint VehicleCargoList::KeepPacket | ( | Iterator & | it | ) | `[protected]`

Keep a packet in the vehicle while unloading by temporarily moving it to the reservation list.

The given iterator is incremented in the process.

Parameters:

  | it | Iterator pointing to the packet.

Returns:
  Size of the packet.

Definition at line 444 of file cargopacket.cpp.

References CargoPacket::count, CargoList< VehicleCargoList, CargoPacketList >::packets, reserved, and reserved_count.

Referenced by StationCargoList::TakeFrom().

uint VehicleCargoList::LoadReserved | ( | uint | max_move | ) |

Load packets from the reservation list.

max_move Number of cargo to load.

Returns:
  Amount of cargo actually loaded.

Definition at line 277 of file cargopacket.cpp.

References Append(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool >::CanAllocateItem(), CargoPacket::count, CargoPacket::days_in_transit, CargoPacket::loaded_at_xy, reserved, reserved_count, CargoPacket::source, CargoPacket::source_id, CargoPacket::source_type, and CargoPacket::source_xy.

uint VehicleCargoList::MoveTo | ( | VehicleCargoList * | dest,
|  | uint | cap |
| ) |  |  |

Moves the given amount of cargo to another vehicle (during autoreplace).

Parameters:

  | dest | Destination to move the cargo to.
  | cap | Maximum amount of cargo entities to move.

Returns:
  Amount of cargo actually moved.

Definition at line 674 of file cargopacket.cpp.

References CargoList< VehicleCargoList, CargoPacketList >::MovePacket(), and CargoList< VehicleCargoList, CargoPacketList >::packets.

uint VehicleCargoList::OnboardCount | ( |  | ) | const`[inline]`

Returns sum of cargo on board the vehicle (ie not only reserved).

Returns:
  Cargo on board the vehicle.

Definition at line 304 of file cargopacket.h.

References CargoList< VehicleCargoList, CargoPacketList >::count, and reserved_count.

Referenced by CalcPercentVehicleFilled(), and LoadUnloadVehicle().

void VehicleCargoList::RemoveFromCache | ( | const CargoPacket * | cp | ) | `[protected]`

Update the cached values to reflect the removal of this packet.

Decreases count, feeder share and days_in_transit.

Parameters:

  | cp | Packet to be removed from cache.

Reimplemented from CargoList< VehicleCargoList, CargoPacketList >.

Definition at line 651 of file cargopacket.cpp.

References CargoPacket::feeder_share, feeder_share, and CargoList< VehicleCargoList, CargoPacketList >::RemoveFromCache().

Referenced by DeliverPacket(), and Unreserve().

void VehicleCargoList::Reserve | ( | CargoPacket * | cp | ) |

Reserves a packet for later loading and adds it to the cache.

Parameters:

  | cp | Packet to be reserved.

Definition at line 247 of file cargopacket.cpp.

References AddToCache(), CargoPacket::count, reserved, and reserved_count.

Referenced by CargoList< Tinst, Tcont >::MovePacket().

const CargoPacketList* VehicleCargoList::Reserved | ( |  | ) | const`[inline]`

Returns a pointer to the reserved cargo list.

Returns:
  Pointer to the reserved list.

Definition at line 322 of file cargopacket.h.

References reserved.

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

Returns sum of cargo reserved for the vehicle.

Returns:
  Cargo reserved for the vehicle.

Definition at line 313 of file cargopacket.h.

References reserved_count.

Referenced by Vehicle::CancelReservation().

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

Returns source of the first cargo packet in this list.

If the regular packets list is empty but there are packets in the reservation list it returns the source of the first reserved packet.

Returns:
  The before mentioned source.

Definition at line 334 of file cargopacket.h.

References CargoList< VehicleCargoList, CargoPacketList >::Empty(), CargoList< VehicleCargoList, CargoPacketList >::packets, and reserved.

Referenced by DrawRoadVehDetails(), DrawShipDetails(), and GetCargoSummaryOfArticulatedVehicle().

void VehicleCargoList::SwapReserved | ( |  | ) |

Swap the reserved and packets lists when starting to load cargo.

Pull in the "kept" packets which were stored in the reservation list so that we don't have to iterate over them all the time.

Precondition:
  this->packets.empty()

Definition at line 566 of file cargopacket.cpp.

References CargoList< VehicleCargoList, CargoPacketList >::packets, reserved, and reserved_count.

uint VehicleCargoList::TransferPacket | ( | Iterator & | it,
|  | uint | cap,
|  | StationCargoList * | dest,
|  | CargoPayment * | payment,
|  | StationID | next |
| ) |  |  | `[protected]`

Transfer a packet to a station, but don't deliver it.

Increment the given iterator in the process.

Parameters:

  | it | Iterator pointing to a packet in the list.
  | cap | Maximum amount of cargo to be transferred.
  | dest | Cargo list of the station the cargo should be transferred to.
  | payment | Payment object to be updated with the resulting transfer credits.
  | next | ID of the station the cargo wants to go to next.

Returns:
  Amount of cargo actually moved.

Definition at line 464 of file cargopacket.cpp.

References StationCargoList::Append(), CargoPacket::count, CargoPacket::feeder_share, CargoPayment::PayTransfer(), and CargoList< VehicleCargoList, CargoPacketList >::RemovePacket().

Referenced by StationCargoList::TakeFrom().

void VehicleCargoList::Unreserve | ( | StationID | next,
|  | StationCargoList * | dest |
| ) |  |  |

Returns all reserved cargo to the station and removes it from the cache.

Parameters:

  | ID | of next the station the cargo wants to go next.
  | dest | Station the cargo is returned to.

Definition at line 260 of file cargopacket.cpp.

References StationCargoList::Append(), CargoPacket::count, RemoveFromCache(), reserved, and reserved_count.

Referenced by Vehicle::CancelReservation().

## Friends And Related Function Documentation

friend class CargoList< VehicleCargoList, CargoPacketList >`[friend]`

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

Definition at line 280 of file cargopacket.h.

struct SaveLoad* GetVehicleDescription | ( | VehicleType | vt | ) | `[friend]`

The vehicles have a cargo list (and we want that saved).

Parameters:

  | vt | the vehicle type. Can be VEH_END for the common vehicle description data

Returns:
  the saveload description

Save and load of vehicles

Definition at line 553 of file vehicle_sl.cpp.

friend class StationCargoList`[friend]`

The station cargo list needs to control the unloading.

Definition at line 278 of file cargopacket.h.

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

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