CargoList that is used for vehicles. More...
#include <cargopacket.h>
Public Member Functions | |
StationID | Source () const |
Returns source of the first cargo packet in this list. | |
Money | FeederShare () const |
Returns total sum of the feeder share for all packets. | |
uint | ActionCount (MoveToAction action) const |
Returns the amount of cargo designated for a given purpose. | |
uint | StoredCount () const |
Returns sum of cargo on board the vehicle (ie not only reserved). | |
uint | TotalCount () const |
Returns sum of cargo, including reserved cargo. | |
uint | ReservedCount () const |
Returns sum of reserved cargo. | |
uint | UnloadCount () const |
Returns sum of cargo to be moved out of the vehicle at the current station. | |
uint | RemainingCount () const |
Returns the sum of cargo to be kept in the vehicle at the current station. | |
void | Append (CargoPacket *cp, MoveToAction action=MTA_KEEP) |
Appends the given cargo packet. | |
void | AgeCargo () |
Ages the all cargo in this list. | |
void | InvalidateCache () |
Invalidates the cached data and rebuild it. | |
void | SetTransferLoadPlace (TileIndex xy) |
Sets loaded_at_xy to the current station for all cargo to be transfered. | |
bool | Stage (bool accepted, StationID current_station, StationID next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment) |
Stages cargo for unloading. | |
void | KeepAll () |
Marks all cargo in the vehicle as to be kept. | |
uint | Reassign (uint max_move, MoveToAction from, MoveToAction to) |
Moves some cargo from one designation to another. | |
uint | Return (uint max_move, StationCargoList *dest, StationID next_station) |
Returns reserved cargo to the station and removes it from the cache. | |
uint | Unload (uint max_move, StationCargoList *dest, CargoPayment *payment) |
Unloads cargo at the given station. | |
uint | Shift (uint max_move, VehicleCargoList *dest) |
Shifts cargo between two vehicles. | |
uint | Truncate (uint max_move=UINT_MAX) |
Truncates the cargo in this list to the given amount. | |
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 | |
template<class Taction > | |
void | ShiftCargo (Taction action) |
Shifts cargo from the front of the packet list and applies some action to it. | |
template<class Taction > | |
void | PopCargo (Taction action) |
Pops cargo from the back of the packet list and applies some action to it. | |
void | AssertCountConsistency () const |
Assert that the designation counts add up. | |
void | AddToCache (const CargoPacket *cp) |
Update the cache to reflect adding of this packet. | |
void | RemoveFromCache (const CargoPacket *cp, uint count) |
Update the cached values to reflect the removal of this packet or part of it. | |
void | AddToMeta (const CargoPacket *cp, MoveToAction action) |
Adds a packet to the metadata. | |
void | RemoveFromMeta (const CargoPacket *cp, MoveToAction action, uint count) |
Removes a packet or part of it from the metadata. | |
Protected Attributes | |
Money | feeder_share |
Cache for the feeder share. | |
uint | action_counts [NUM_MOVE_TO_ACTION] |
Counts of cargo to be transfered, delivered, kept and loaded. | |
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. | |
class | CargoShift |
class | CargoTransfer |
class | CargoDelivery |
class | CargoRemoval |
class | CargoReturn |
struct SaveLoad * | GetVehicleDescription (VehicleType vt) |
The vehicles have a cargo list (and we want that saved). |
CargoList that is used for vehicles.
Definition at line 277 of file cargopacket.h.
typedef CargoList<VehicleCargoList, CargoPacketList> VehicleCargoList::Parent [protected] |
The (direct) parent of this class.
Definition at line 280 of file cargopacket.h.
uint VehicleCargoList::ActionCount | ( | MoveToAction | action | ) | const [inline] |
Returns the amount of cargo designated for a given purpose.
action | Action the cargo is designated for. |
Definition at line 346 of file cargopacket.h.
References action_counts.
Referenced by Vehicle::CancelReservation(), and StationCargoList::Load().
void VehicleCargoList::AddToCache | ( | const CargoPacket * | cp | ) | [protected] |
Update the cache to reflect adding of this packet.
Increases count, feeder share and days_in_transit.
cp | New packet to be inserted. |
Reimplemented from CargoList< VehicleCargoList, CargoPacketList >.
Definition at line 346 of file cargopacket.cpp.
References CargoList< VehicleCargoList, CargoPacketList >::AddToCache(), CargoPacket::feeder_share, and feeder_share.
Referenced by AddToMeta().
void VehicleCargoList::AddToMeta | ( | const CargoPacket * | cp, | |
MoveToAction | action | |||
) | [protected] |
Adds a packet to the metadata.
cp | Packet to be added. | |
action | MoveToAction of the packet. |
Definition at line 371 of file cargopacket.cpp.
References action_counts, AddToCache(), AssertCountConsistency(), and CargoPacket::count.
Referenced by Append().
void VehicleCargoList::Append | ( | CargoPacket * | cp, | |
MoveToAction | action = MTA_KEEP | |||
) |
Appends the given cargo packet.
Tries to merge it with another one in the packets list. If no fitting packet is found, appends it. You can only append packets to the ranges of packets designated for keeping or loading. Furthermore if there are already packets reserved for loading you cannot directly add packets to the "keep" list. You first have to load the reserved ones.
cp | Cargo packet to add. | |
action | Either MTA_KEEP if you want to add the packet directly or MTA_LOAD if you want to reserve it first. |
Definition at line 252 of file cargopacket.cpp.
References action_counts, AddToMeta(), CargoPacket::count, CargoList< VehicleCargoList, CargoPacketList >::count, CargoList< VehicleCargoList, CargoPacketList >::MTA_KEEP, CargoList< VehicleCargoList, CargoPacketList >::MTA_LOAD, CargoList< VehicleCargoList, CargoPacketList >::packets, and CargoList< VehicleCargoList, CargoPacketList >::TryMerge().
Referenced by Load_VEHS(), LoadOldVehicle(), CargoShift::operator()(), CargoReservation::operator()(), and CargoLoad::operator()().
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?
cp1 | First CargoPacket. | |
cp2 | Second CargoPacket. |
Definition at line 435 of file cargopacket.h.
References CargoPacket::days_in_transit, CargoPacket::loaded_at_xy, CargoPacket::source_id, CargoPacket::source_type, and CargoPacket::source_xy.
Money VehicleCargoList::FeederShare | ( | ) | const [inline] |
Returns total sum of the feeder share for all packets.
Definition at line 336 of file cargopacket.h.
References feeder_share.
Referenced by DrawRoadVehDetails(), and DrawShipDetails().
void VehicleCargoList::InvalidateCache | ( | ) |
Invalidates the cached data and rebuild it.
Reimplemented from CargoList< VehicleCargoList, CargoPacketList >.
Definition at line 492 of file cargopacket.cpp.
References feeder_share, and CargoList< VehicleCargoList, CargoPacketList >::InvalidateCache().
Referenced by CargoPacket::AfterLoad(), and CheckCaches().
void VehicleCargoList::KeepAll | ( | ) | [inline] |
Marks all cargo in the vehicle as to be kept.
This is mostly useful for loading old savegames. When loading is aborted the reserved cargo has to be returned first.
Definition at line 412 of file cargopacket.h.
References action_counts, and CargoList< VehicleCargoList, CargoPacketList >::count.
Referenced by CargoPacket::AfterLoad(), and Vehicle::CancelReservation().
void VehicleCargoList::PopCargo | ( | Taction | action | ) | [protected] |
Pops cargo from the back of the packet list and applies some action to it.
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. |
action | Action instance to be applied. |
Definition at line 309 of file cargopacket.cpp.
References CargoList< VehicleCargoList, CargoPacketList >::packets.
Referenced by Return(), Shift(), and Truncate().
uint VehicleCargoList::Reassign | ( | uint | max_move, | |
MoveToAction | from, | |||
MoveToAction | to | |||
) |
Moves some cargo from one designation to another.
You can only move between adjacent designations. E.g. you can keep cargo that was previously reserved (MTA_LOAD) or you can mark cargo to be transferred that was previously marked as to be delivered, but you can't reserve cargo that's marked as to be delivered.
Definition at line 505 of file cargopacket.cpp.
References action_counts, Delta(), and min().
Referenced by StationCargoList::Load().
uint VehicleCargoList::RemainingCount | ( | ) | const [inline] |
Returns the sum of cargo to be kept in the vehicle at the current station.
Definition at line 392 of file cargopacket.h.
References action_counts.
Referenced by LoadUnloadVehicle(), and ReserveConsist().
void VehicleCargoList::RemoveFromCache | ( | const CargoPacket * | cp, | |
uint | count | |||
) | [protected] |
Update the cached values to reflect the removal of this packet or part of it.
Decreases count, feeder share and days_in_transit.
cp | Packet to be removed from cache. | |
count | Amount of cargo from the given packet to be removed. |
Reimplemented from CargoList< VehicleCargoList, CargoPacketList >.
Definition at line 335 of file cargopacket.cpp.
References feeder_share, CargoPacket::FeederShare(), and CargoList< VehicleCargoList, CargoPacketList >::RemoveFromCache().
Referenced by RemoveFromMeta().
void VehicleCargoList::RemoveFromMeta | ( | const CargoPacket * | cp, | |
MoveToAction | action, | |||
uint | count | |||
) | [protected] |
Removes a packet or part of it from the metadata.
cp | Packet to be removed. | |
action | MoveToAction of the packet (for updating the counts). | |
count | Amount of cargo to be removed. |
Definition at line 358 of file cargopacket.cpp.
References action_counts, AssertCountConsistency(), and RemoveFromCache().
Referenced by CargoShift::operator()(), CargoTransfer::operator()(), CargoReturn::operator()(), and CargoDelivery::operator()().
uint VehicleCargoList::ReservedCount | ( | ) | const [inline] |
Returns sum of reserved cargo.
Definition at line 374 of file cargopacket.h.
References action_counts.
uint VehicleCargoList::Return | ( | uint | max_move, | |
StationCargoList * | dest, | |||
StationID | next | |||
) |
Returns reserved cargo to the station and removes it from the cache.
max_move | Maximum amount of cargo to move. | |
dest | Station the cargo is returned to. | |
ID | of next the station the cargo wants to go next. |
Definition at line 521 of file cargopacket.cpp.
References action_counts, min(), CargoList< VehicleCargoList, CargoPacketList >::MTA_LOAD, and PopCargo().
Referenced by Vehicle::CancelReservation().
void VehicleCargoList::SetTransferLoadPlace | ( | TileIndex | xy | ) |
Sets loaded_at_xy to the current station for all cargo to be transfered.
This is done when stopping or skipping while the vehicle is unloading. In that case the vehicle will get part of its transfer credits early and it may get more transfer credits than it's entitled to.
xy | New loaded_at_xy for the cargo. |
Definition at line 401 of file cargopacket.cpp.
References action_counts, CargoPacket::count, CargoPacket::loaded_at_xy, and CargoList< VehicleCargoList, CargoPacketList >::packets.
Referenced by Vehicle::CancelReservation().
uint VehicleCargoList::Shift | ( | uint | max_move, | |
VehicleCargoList * | dest | |||
) |
Shifts cargo between two vehicles.
dest | Other vehicle's cargo list. | |
max_move | Maximum amount of cargo to be moved. |
Definition at line 534 of file cargopacket.cpp.
References CargoList< VehicleCargoList, CargoPacketList >::count, min(), and PopCargo().
void VehicleCargoList::ShiftCargo | ( | Taction | action | ) | [protected] |
Shifts cargo from the front of the packet list and applies some action to it.
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. |
action | Action instance to be applied. |
Definition at line 287 of file cargopacket.cpp.
References CargoList< VehicleCargoList, CargoPacketList >::packets.
Referenced by Unload().
StationID VehicleCargoList::Source | ( | ) | const [inline] |
Returns source of the first cargo packet in this list.
Definition at line 327 of file cargopacket.h.
References CargoList< VehicleCargoList, CargoPacketList >::count, and CargoList< VehicleCargoList, CargoPacketList >::packets.
Referenced by DrawRoadVehDetails(), DrawShipDetails(), and GetCargoSummaryOfArticulatedVehicle().
bool VehicleCargoList::Stage | ( | bool | accepted, | |
StationID | current_station, | |||
StationID | next_station, | |||
uint8 | order_flags, | |||
const GoodsEntry * | ge, | |||
CargoPayment * | payment | |||
) |
Stages cargo for unloading.
The cargo is sorted so that packets to be transferred, delivered or kept are in consecutive chunks in the list. At the same time the designation_counts are updated to reflect the size of those chunks.
accepted | If the cargo will be accepted at the station. | |
current_station | ID of the station. | |
next_station | ID of the station the vehicle will go to next. | |
order_flags | OrderUnloadFlags that will apply to the unload operation. | |
ge | GoodsEntry for getting the flows. | |
payment | Payment object for registering transfers. return If any cargo will be unloaded. |
Definition at line 424 of file cargopacket.cpp.
References action_counts, CargoPacket::AddFeederShare(), AssertCountConsistency(), CargoPacket::count, CargoList< VehicleCargoList, CargoPacketList >::count, feeder_share, GoodsEntry::GetVia(), CargoList< VehicleCargoList, CargoPacketList >::MTA_DELIVER, CargoList< VehicleCargoList, CargoPacketList >::MTA_KEEP, CargoList< VehicleCargoList, CargoPacketList >::MTA_LOAD, CargoList< VehicleCargoList, CargoPacketList >::MTA_TRANSFER, CargoPacket::next_station, OUFB_TRANSFER, CargoList< VehicleCargoList, CargoPacketList >::packets, CargoPayment::PayTransfer(), and CargoPacket::source.
uint VehicleCargoList::StoredCount | ( | ) | const [inline] |
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition at line 356 of file cargopacket.h.
References action_counts, and CargoList< VehicleCargoList, CargoPacketList >::count.
Referenced by CalcPercentVehicleFilled(), DrawRoadVehDetails(), DrawShipDetails(), GetCargoSummaryOfArticulatedVehicle(), Vehicle::GetConsistFreeCapacities(), Train::GetImage(), RoadVehicle::GetImage(), Train::GetWeight(), RoadVehicle::GetWeight(), IncreaseStats(), LoadUnloadVehicle(), and VehicleResolverObject::ResolveReal().
uint VehicleCargoList::TotalCount | ( | ) | const [inline] |
Returns sum of cargo, including reserved cargo.
Definition at line 365 of file cargopacket.h.
References CargoList< VehicleCargoList, CargoPacketList >::count.
Referenced by Vehicle::Crash(), IsArticulatedVehicleEmpty(), LoadUnloadVehicle(), RefitVehicle(), and TransferCargo().
uint VehicleCargoList::Truncate | ( | uint | max_move = UINT_MAX |
) |
Truncates the cargo in this list to the given amount.
It leaves the first cargo entities and removes max_move from the back of the list.
max_move | Maximum amount of entities to be removed from the list. |
Definition at line 571 of file cargopacket.cpp.
References CargoList< VehicleCargoList, CargoPacketList >::count, min(), and PopCargo().
Referenced by CrashAirplane(), Vehicle::PreDestructor(), and RefitVehicle().
uint VehicleCargoList::Unload | ( | uint | max_move, | |
StationCargoList * | dest, | |||
CargoPayment * | payment | |||
) |
Unloads cargo at the given station.
Deliver or transfer, depending on the ranges defined by designation_counts.
dest | StationCargoList to add transferred cargo to. | |
max_move | Maximum amount of cargo to move. | |
payment | Payment object to register payments in. |
Definition at line 549 of file cargopacket.cpp.
References action_counts, min(), CargoList< VehicleCargoList, CargoPacketList >::MTA_DELIVER, CargoList< VehicleCargoList, CargoPacketList >::MTA_TRANSFER, and ShiftCargo().
uint VehicleCargoList::UnloadCount | ( | ) | const [inline] |
Returns sum of cargo to be moved out of the vehicle at the current station.
Definition at line 383 of file cargopacket.h.
References action_counts.
friend class CargoList< VehicleCargoList, CargoPacketList > [friend] |
The super class ought to know what it's doing.
Definition at line 312 of file cargopacket.h.
struct SaveLoad* GetVehicleDescription | ( | VehicleType | vt | ) | [friend] |
The vehicles have a cargo list (and we want that saved).
vt | the vehicle type. Can be VEH_END for the common vehicle description data |
Save and load of vehicles
Definition at line 568 of file vehicle_sl.cpp.
friend class StationCargoList [friend] |
The station cargo list needs to control the unloading.
Definition at line 310 of file cargopacket.h.