OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
72 feeder_share(feeder_share),
74 days_in_transit(days_in_transit),
78 loaded_at_xy(loaded_at_xy)
96 this->
count -= new_size;
117 assert(count < this->
count);
119 this->count -=
count;
130 if (cp->source_type == src_type && cp->source_id == src) cp->source_id =
INVALID_SOURCE;
141 if (cp->source == sid) cp->source = INVALID_STATION;
154 template <
class Tinst,
class Tcont>
157 for (
Iterator it(this->packets.begin()); it != this->packets.end(); ++it) {
166 template <
class Tinst,
class Tcont>
169 this->packets.clear();
178 template <
class Tinst,
class Tcont>
181 assert(count <= cp->count);
182 this->count -= count;
191 template <
class Tinst,
class Tcont>
194 this->count += cp->
count;
199 template <
class Tinst,
class Tcont>
203 this->cargo_days_in_transit = 0;
205 for (
ConstIterator it(this->packets.begin()); it != this->packets.end(); it++) {
206 static_cast<Tinst *
>(
this)->AddToCache(*it);
217 template <
class Tinst,
class Tcont>
220 if (Tinst::AreMergable(icp, cp) &&
252 assert(cp !=
nullptr);
262 uint sum = cp->
count;
284 template<
class Taction>
288 while (it != this->
packets.end() && action.MaxMove() > 0) {
306 template<
class Taction>
309 if (this->
packets.empty())
return;
312 while (action.MaxMove() > 0) {
420 StationID current_station,
bool accepted,
StationIDStack next_station)
422 if (cargo_next == INVALID_STATION) {
424 }
else if (cargo_next == current_station) {
426 }
else if (next_station.
Contains(cargo_next)) {
456 bool force_unload = (order_flags &
OUFB_UNLOAD) != 0;
459 while (sum < this->
count) {
463 StationID cargo_next = INVALID_STATION;
467 }
else if (force_unload && accepted && cp->
source != current_station) {
469 }
else if (force_transfer) {
473 FlowStatMap::const_iterator flow_it(ge->
flows.find(cp->
source));
474 if (flow_it == ge->
flows.end()) {
475 cargo_next = INVALID_STATION;
477 FlowStat new_shares = flow_it->second;
484 cargo_next = INVALID_STATION;
486 cargo_next = new_shares.
GetVia();
492 if (cp->
source == INVALID_STATION && !ge->
flows.empty()) {
495 bool restricted =
false;
496 FlowStatMap::const_iterator flow_it(ge->
flows.find(cp->
source));
497 if (flow_it == ge->
flows.end()) {
498 cargo_next = INVALID_STATION;
500 cargo_next = flow_it->second.GetViaWithRestricted(restricted);
506 cargo_next = flow_it->second.GetVia();
514 if (deliver == this->
packets.end()) --deliver;
517 this->
packets.insert(deliver, cp);
556 template<VehicleCargoList::MoveToAction Tfrom, VehicleCargoList::MoveToAction Tto>
560 static_assert(Tfrom - Tto == 1 || Tto - Tfrom == 1);
575 uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER>(uint max_move, TileOrStationID next_station)
577 max_move = std::min(this->action_counts[MTA_DELIVER], max_move);
580 for (Iterator it(this->packets.begin()); sum < this->action_counts[MTA_TRANSFER] + max_move;) {
583 if (sum <= this->action_counts[MTA_TRANSFER])
continue;
584 if (sum > this->action_counts[MTA_TRANSFER] + max_move) {
585 CargoPacket *cp_split = cp->
Split(sum - this->action_counts[MTA_TRANSFER] + max_move);
586 sum -= cp_split->
Count();
587 this->packets.insert(it, cp_split);
592 this->action_counts[MTA_DELIVER] -= max_move;
593 this->action_counts[MTA_TRANSFER] += max_move;
619 max_move = std::min(this->
count, max_move);
656 max_move = std::min(this->
count, max_move);
692 assert(cp !=
nullptr);
695 StationCargoPacketMap::List &list = this->
packets[next];
696 for (StationCargoPacketMap::List::reverse_iterator it(list.rbegin());
697 it != list.rend(); it++) {
717 template <
class Taction>
721 for (
Iterator it(range.first); it != range.second && it.GetKey() == next;) {
722 if (action.MaxMove() == 0)
return false;
747 template <
class Taction>
750 uint max_move = action.MaxMove();
753 if (action.MaxMove() == 0)
break;
755 if (include_invalid && action.MaxMove() > 0) {
758 return max_move - action.MaxMove();
771 max_move = std::min(max_move, this->
count);
772 uint prev_count = this->
count;
775 bool do_count = cargo_per_source !=
nullptr;
776 while (max_move > moved) {
779 if (prev_count > max_move &&
RandomRange(prev_count) < prev_count - max_move) {
780 if (do_count && loop == 0) {
786 uint diff = max_move - moved;
787 if (cp->
count > diff) {
794 if (do_count) (*cargo_per_source)[cp->
source] -= diff;
797 if (do_count) (*cargo_per_source)[cp->
source] += cp->
count;
802 if (do_count && loop > 0) {
870 template uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_KEEP>(uint, TileOrStationID);
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
CargoPacketList ::const_iterator ConstIterator
The const iterator for our container.
uint32 TileIndex
The index/ID of a Tile.
Minimal stack that uses a pool to avoid pointers.
void ShiftCargo(Taction action)
Shifts cargo from the front of the packet list and applies some action to it.
Titem Pop()
Pop an item from the stack.
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment)
Unloads cargo at the given station.
@ OUFB_UNLOAD
Force unloading all cargo onto the platform, possibly not getting paid.
MoveToAction
Kind of actions that could be done with packets on move.
Action of reserving cargo from a station to be loaded onto a vehicle.
uint Shift(uint max_move, VehicleCargoList *dest)
Shifts cargo between two vehicles.
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
static bool TryMerge(CargoPacket *cp, CargoPacket *icp)
Tries to merge the second packet into the first and return if that was successful.
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment)
Stages cargo for unloading.
@ OUFB_TRANSFER
Transfer all cargo onto the platform.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
uint reserved_count
Amount of cargo being reserved for loading.
StationID source
The station where the cargo came from first.
void InvalidateCache()
Invalidates the cached data and rebuild it.
void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count)
Removes a packet or part of it from the metadata.
void AssertCountConsistency() const
Assert that the designation counts add up.
CargoList that is used for stations.
~CargoList()
Destroy the cargolist ("frees" all cargo packets).
Action of returning previously reserved cargo from the vehicle to the station.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
Reserves cargo for loading onto the vehicle.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
byte days_in_transit
Amount of days this packet has been in transit.
TileOrStationID loaded_at_xy
Location where this cargo has been loaded into the vehicle.
CargoList that is used for vehicles.
void Merge(CargoPacket *cp)
Merge another packet into this one.
Flow statistics telling how much flow should be sent along a link.
uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Routes packets with station "avoid" as next hop to a different place.
Action of rerouting cargo staged for transfer in a vehicle.
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
TileIndex source_xy
The origin of the cargo (first station in feeder chain).
void AgeCargo()
Ages the all cargo in this list.
Money feeder_share
Cache for the feeder share.
void AddToMeta(const CargoPacket *cp, MoveToAction action)
Adds a packet to the metadata.
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
iterator erase(iterator it)
Erase the value pointed to by an iterator.
Helper class to perform the cargo payment.
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
Action of final delivery of cargo.
CargoPacket * Split(uint new_size)
Split this packet in two and return the split off part.
void InvalidateCache()
Invalidates the cached data and rebuilds it.
@ ST_INDUSTRY
Source/destination is an industry.
uint cargo_days_in_transit
Cache for the sum of number of days in transit of each entity; comparable to man-hours.
static MoveToAction ChooseAction(const CargoPacket *cp, StationID cargo_next, StationID current_station, bool accepted, StationIDStack next_station)
Choose action to be performed with the given cargo packet.
uint count
Cache for the number of cargo entities.
static const uint16 MAX_COUNT
Maximum number of items in a single cargo packet.
void SetTransferLoadPlace(TileIndex xy)
Sets loaded_at_xy to the current station for all cargo to be transferred.
SourceID source_id
Index of source, INVALID_SOURCE if unknown/invalid.
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
uint16 Count() const
Gets the number of 'items' in this packet.
@ MTA_TRANSFER
Transfer the cargo to the station.
uint action_counts[NUM_MOVE_TO_ACTION]
Counts of cargo to be transferred, delivered, kept and loaded.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
SourceType source_type
Type of source_id.
void Reduce(uint count)
Reduce the packet by the given amount and remove the feeder share.
std::pair< iterator, iterator > equal_range(const Tkey &key)
Get a pair of iterators specifying a range of items with equal keys.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
Action of shifting cargo from one vehicle to another.
CargoPacketList ::reverse_iterator ReverseIterator
The reverse iterator for our container.
CargoPacketList packets
The cargo packets in this list.
Stores station stats for a single cargo.
TileOrStationID next_station
Station where the cargo wants to go next.
SourceType
Types of cargo source and destination.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Base class for all pools.
Action of transferring cargo from a vehicle to a station.
FlowStatMap flows
Planned flows through this station.
@ OUFB_NO_UNLOAD
Totally no unloading will be done.
Money PayTransfer(const CargoPacket *cp, uint count)
Handle payment for transfer of the given cargo packet.
@ MTA_LOAD
Load the cargo from the station.
uint16 count
The amount of cargo in this packet.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
StationID GetVia() const
Get a station a package can be routed to.
TileIndex xy
Base tile of the station.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
bool ShiftCargo(Taction &action, StationID next)
Shifts cargo from the front of the packet list for a specific station and applies some action to it.
CargoPacketList ::iterator Iterator
The iterator for our container.
Container for cargo from the same location and time.
bool IsEmpty() const
Check if the stack is empty.
@ MTA_KEEP
Keep the cargo in the vehicle.
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
uint Reassign(uint max_move, TileOrStationID update=INVALID_TILE)
Moves some cargo from one designation to another.
@ MTA_DELIVER
Deliver the cargo to some town or industry.
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
void PopCargo(Taction action)
Pops cargo from the back of the packet list and applies some action to it.
Money FeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Action of rerouting cargo in a station.
uint Return(uint max_move, StationCargoList *dest, StationID next_station)
Returns reserved cargo to the station and removes it from the cache.
CargoPacketPool _cargopacket_pool("CargoPacket")
The actual pool with cargo packets.
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
bool Contains(const Titem &item) const
Check if the given item is contained in the stack.
void ChangeShare(StationID st, int flow)
Change share for specified station.
CargoPacket()
Create a new packet for savegame loading.
uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
Loads cargo onto a vehicle.
Action of loading cargo from a station onto a vehicle.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.