OpenTTD Source  12.0-beta2
cargopacket.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef CARGOPACKET_H
11 #define CARGOPACKET_H
12 
13 #include "core/pool_type.hpp"
14 #include "economy_type.h"
15 #include "station_type.h"
16 #include "order_type.h"
17 #include "cargo_type.h"
18 #include "vehicle_type.h"
19 #include "core/multimap.hpp"
20 #include "saveload/saveload.h"
21 #include <list>
22 
24 typedef uint32 CargoPacketID;
25 struct CargoPacket;
26 
31 
32 struct GoodsEntry; // forward-declare for Stage() and RerouteStalePackets()
33 
34 template <class Tinst, class Tcont> class CargoList;
35 class StationCargoList; // forward-declare, so we can use it in VehicleCargoList.
37 
38 typedef uint32 TileOrStationID;
39 
43 struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> {
44 private:
46  uint16 count;
50  StationID source;
52  union {
53  TileOrStationID loaded_at_xy;
54  TileOrStationID next_station;
55  };
56 
58  template <class Tinst, class Tcont> friend class CargoList;
59  friend class VehicleCargoList;
60  friend class StationCargoList;
63 public:
65  static const uint16 MAX_COUNT = UINT16_MAX;
66 
67  CargoPacket();
70 
73 
74  CargoPacket *Split(uint new_size);
75  void Merge(CargoPacket *cp);
76  void Reduce(uint count);
77 
82  void SetLoadPlace(TileIndex load_place) { this->loaded_at_xy = load_place; }
83 
88  void SetNextStation(StationID next_station) { this->next_station = next_station; }
89 
94  void AddFeederShare(Money new_share) { this->feeder_share += new_share; }
95 
100  inline uint16 Count() const
101  {
102  return this->count;
103  }
104 
110  inline Money FeederShare() const
111  {
112  return this->feeder_share;
113  }
114 
121  inline Money FeederShare(uint part) const
122  {
123  return this->feeder_share * part / static_cast<uint>(this->count);
124  }
125 
132  inline byte DaysInTransit() const
133  {
134  return this->days_in_transit;
135  }
136 
142  {
143  return this->source_type;
144  }
145 
150  inline SourceID SourceSubsidyID() const
151  {
152  return this->source_id;
153  }
154 
159  inline StationID SourceStation() const
160  {
161  return this->source;
162  }
163 
168  inline TileIndex SourceStationXY() const
169  {
170  return this->source_xy;
171  }
172 
177  inline TileIndex LoadedAtXY() const
178  {
179  return this->loaded_at_xy;
180  }
181 
186  inline StationID NextStation() const
187  {
188  return this->next_station;
189  }
190 
191  static void InvalidateAllFrom(SourceType src_type, SourceID src);
192  static void InvalidateAllFrom(StationID sid);
193  static void AfterLoad();
194 };
195 
200 template <class Tinst, class Tcont>
201 class CargoList {
202 public:
204  typedef typename Tcont::iterator Iterator;
206  typedef typename Tcont::reverse_iterator ReverseIterator;
208  typedef typename Tcont::const_iterator ConstIterator;
210  typedef typename Tcont::const_reverse_iterator ConstReverseIterator;
211 
214  MTA_BEGIN = 0,
219  MTA_END,
220  NUM_MOVE_TO_ACTION = MTA_END
221  };
222 
223 protected:
224  uint count;
226 
227  Tcont packets;
228 
229  void AddToCache(const CargoPacket *cp);
230 
231  void RemoveFromCache(const CargoPacket *cp, uint count);
232 
233  static bool TryMerge(CargoPacket *cp, CargoPacket *icp);
234 
235 public:
238 
239  ~CargoList();
240 
241  void OnCleanPool();
242 
247  inline const Tcont *Packets() const
248  {
249  return &this->packets;
250  }
251 
256  inline uint DaysInTransit() const
257  {
258  return this->count == 0 ? 0 : this->cargo_days_in_transit / this->count;
259  }
260 
261  void InvalidateCache();
262 };
263 
264 typedef std::list<CargoPacket *> CargoPacketList;
265 
269 class VehicleCargoList : public CargoList<VehicleCargoList, CargoPacketList> {
270 protected:
273 
275  uint action_counts[NUM_MOVE_TO_ACTION];
276 
277  template<class Taction>
278  void ShiftCargo(Taction action);
279 
280  template<class Taction>
281  void PopCargo(Taction action);
282 
286  inline void AssertCountConsistency() const
287  {
288  assert(this->action_counts[MTA_KEEP] +
289  this->action_counts[MTA_DELIVER] +
290  this->action_counts[MTA_TRANSFER] +
291  this->action_counts[MTA_LOAD] == this->count);
292  }
293 
294  void AddToCache(const CargoPacket *cp);
295  void RemoveFromCache(const CargoPacket *cp, uint count);
296 
297  void AddToMeta(const CargoPacket *cp, MoveToAction action);
298  void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count);
299 
300  static MoveToAction ChooseAction(const CargoPacket *cp, StationID cargo_next,
301  StationID current_station, bool accepted, StationIDStack next_station);
302 
303 public:
305  friend class StationCargoList;
307  friend class CargoList<VehicleCargoList, CargoPacketList>;
308  /* So we can use private/protected variables in the saveload code */
309  friend class SlVehicleCommon;
310 
311  friend class CargoShift;
312  friend class CargoTransfer;
313  friend class CargoDelivery;
314  template<class Tsource>
315  friend class CargoRemoval;
316  friend class CargoReturn;
317  friend class VehicleCargoReroute;
318 
323  inline StationID Source() const
324  {
325  return this->count == 0 ? INVALID_STATION : this->packets.front()->source;
326  }
327 
332  inline Money FeederShare() const
333  {
334  return this->feeder_share;
335  }
336 
342  inline uint ActionCount(MoveToAction action) const
343  {
344  return this->action_counts[action];
345  }
346 
352  inline uint StoredCount() const
353  {
354  return this->count - this->action_counts[MTA_LOAD];
355  }
356 
361  inline uint TotalCount() const
362  {
363  return this->count;
364  }
365 
370  inline uint ReservedCount() const
371  {
372  return this->action_counts[MTA_LOAD];
373  }
374 
379  inline uint UnloadCount() const
380  {
381  return this->action_counts[MTA_TRANSFER] + this->action_counts[MTA_DELIVER];
382  }
383 
388  inline uint RemainingCount() const
389  {
390  return this->action_counts[MTA_KEEP] + this->action_counts[MTA_LOAD];
391  }
392 
393  void Append(CargoPacket *cp, MoveToAction action = MTA_KEEP);
394 
395  void AgeCargo();
396 
397  void InvalidateCache();
398 
400 
401  bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment);
402 
408  inline void KeepAll()
409  {
410  this->action_counts[MTA_DELIVER] = this->action_counts[MTA_TRANSFER] = this->action_counts[MTA_LOAD] = 0;
411  this->action_counts[MTA_KEEP] = this->count;
412  }
413 
414  /* Methods for moving cargo around. First parameter is always maximum
415  * amount of cargo to be moved. Second parameter is destination (if
416  * applicable), return value is amount of cargo actually moved. */
417 
418  template<MoveToAction Tfrom, MoveToAction Tto>
419  uint Reassign(uint max_move, TileOrStationID update = INVALID_TILE);
420  uint Return(uint max_move, StationCargoList *dest, StationID next_station);
421  uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment);
422  uint Shift(uint max_move, VehicleCargoList *dest);
423  uint Truncate(uint max_move = UINT_MAX);
424  uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
425 
433  static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
434  {
435  return cp1->source_xy == cp2->source_xy &&
436  cp1->days_in_transit == cp2->days_in_transit &&
437  cp1->source_type == cp2->source_type &&
438  cp1->source_id == cp2->source_id &&
439  cp1->loaded_at_xy == cp2->loaded_at_xy;
440  }
441 };
442 
444 typedef std::map<StationID, uint> StationCargoAmountMap;
445 
449 class StationCargoList : public CargoList<StationCargoList, StationCargoPacketMap> {
450 protected:
453 
455 
456 public:
459  /* So we can use private/protected variables in the saveload code */
460  friend class SlStationGoods;
461 
462  friend class CargoLoad;
463  friend class CargoTransfer;
464  template<class Tsource>
465  friend class CargoRemoval;
466  friend class CargoReservation;
467  friend class CargoReturn;
468  friend class StationCargoReroute;
469 
470  static void InvalidateAllFrom(SourceType src_type, SourceID src);
471 
472  template<class Taction>
473  bool ShiftCargo(Taction &action, StationID next);
474 
475  template<class Taction>
476  uint ShiftCargo(Taction action, StationIDStack next, bool include_invalid);
477 
478  void Append(CargoPacket *cp, StationID next);
479 
485  inline bool HasCargoFor(StationIDStack next) const
486  {
487  while (!next.IsEmpty()) {
488  if (this->packets.find(next.Pop()) != this->packets.end()) return true;
489  }
490  /* Packets for INVALID_STATION can go anywhere. */
491  return this->packets.find(INVALID_STATION) != this->packets.end();
492  }
493 
498  inline StationID Source() const
499  {
500  return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->source;
501  }
502 
508  inline uint AvailableCount() const
509  {
510  return this->count;
511  }
512 
517  inline uint ReservedCount() const
518  {
519  return this->reserved_count;
520  }
521 
527  inline uint TotalCount() const
528  {
529  return this->count + this->reserved_count;
530  }
531 
532  /* Methods for moving cargo around. First parameter is always maximum
533  * amount of cargo to be moved. Second parameter is destination (if
534  * applicable), return value is amount of cargo actually moved. */
535 
536  uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
537  uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
538  uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr);
539  uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
540 
548  static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
549  {
550  return cp1->source_xy == cp2->source_xy &&
551  cp1->days_in_transit == cp2->days_in_transit &&
552  cp1->source_type == cp2->source_type &&
553  cp1->source_id == cp2->source_id;
554  }
555 };
556 
557 #endif /* CARGOPACKET_H */
VehicleCargoList::TotalCount
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
Definition: cargopacket.h:361
CargoPacket::feeder_share
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
Definition: cargopacket.h:45
CargoList::CargoList
CargoList()
Create the cargo list.
Definition: cargopacket.h:237
CargoList::ConstIterator
Tcont::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:208
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:352
SmallStack
Minimal stack that uses a pool to avoid pointers.
Definition: smallstack_type.hpp:136
VehicleCargoList::ShiftCargo
void ShiftCargo(Taction action)
Shifts cargo from the front of the packet list and applies some action to it.
Definition: cargopacket.cpp:285
SmallStack::Pop
Titem Pop()
Pop an item from the stack.
Definition: smallstack_type.hpp:213
VehicleCargoList::Unload
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment)
Unloads cargo at the given station.
Definition: cargopacket.cpp:632
CargoList< VehicleCargoList, CargoPacketList >::MoveToAction
MoveToAction
Kind of actions that could be done with packets on move.
Definition: cargopacket.h:213
CargoReservation
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition: cargoaction.h:89
VehicleCargoList::Shift
uint Shift(uint max_move, VehicleCargoList *dest)
Shifts cargo between two vehicles.
Definition: cargopacket.cpp:617
CargoList::OnCleanPool
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
Definition: cargopacket.cpp:167
VehicleCargoList::Reroute
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.
Definition: cargopacket.cpp:669
CargoList::TryMerge
static bool TryMerge(CargoPacket *cp, CargoPacket *icp)
Tries to merge the second packet into the first and return if that was successful.
Definition: cargopacket.cpp:218
CargoList::DaysInTransit
uint DaysInTransit() const
Returns average number of days in transit for a cargo entity.
Definition: cargopacket.h:256
VehicleCargoList::Stage
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment)
Stages cargo for unloading.
Definition: cargopacket.cpp:446
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:247
CargoPacket::InvalidateAllFrom
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Definition: cargopacket.cpp:127
StationCargoList::reserved_count
uint reserved_count
Amount of cargo being reserved for loading.
Definition: cargopacket.h:454
CargoPacket::source
StationID source
The station where the cargo came from first.
Definition: cargopacket.h:50
VehicleCargoList::InvalidateCache
void InvalidateCache()
Invalidates the cached data and rebuild it.
Definition: cargopacket.cpp:538
CargoPacketPool
Pool< CargoPacket, CargoPacketID, 1024, 0xFFF000, PT_NORMAL, true, false > CargoPacketPool
Type of the pool for cargo packets for a little over 16 million packets.
Definition: cargopacket.h:25
VehicleCargoList::ReservedCount
uint ReservedCount() const
Returns sum of reserved cargo.
Definition: cargopacket.h:370
VehicleCargoList::RemoveFromMeta
void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count)
Removes a packet or part of it from the metadata.
Definition: cargopacket.cpp:356
VehicleCargoList::AssertCountConsistency
void AssertCountConsistency() const
Assert that the designation counts add up.
Definition: cargopacket.h:286
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:449
CargoList::~CargoList
~CargoList()
Destroy the cargolist ("frees" all cargo packets).
Definition: cargopacket.cpp:155
saveload.h
CargoPacket::DaysInTransit
byte DaysInTransit() const
Gets the number of days this cargo has been in transit.
Definition: cargopacket.h:132
CargoReturn
Action of returning previously reserved cargo from the vehicle to the station.
Definition: cargoaction.h:97
StationCargoList::Reserve
uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
Reserves cargo for loading onto the vehicle.
Definition: cargopacket.cpp:823
VehicleCargoList::AddToCache
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
Definition: cargopacket.cpp:344
CargoPacket::days_in_transit
byte days_in_transit
Amount of days this packet has been in transit.
Definition: cargopacket.h:47
CargoPacket::loaded_at_xy
TileOrStationID loaded_at_xy
Location where this cargo has been loaded into the vehicle.
Definition: cargopacket.h:53
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:527
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:269
CargoPacket::Merge
void Merge(CargoPacket *cp)
Merge another packet into this one.
Definition: cargopacket.cpp:104
SlVehicleCommon
Definition: vehicle_sl.cpp:578
VehicleCargoList::UnloadCount
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.
Definition: cargopacket.h:379
StationCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:498
StationCargoList::Reroute
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.
Definition: cargopacket.cpp:860
VehicleCargoReroute
Action of rerouting cargo staged for transfer in a vehicle.
Definition: cargoaction.h:134
SourceID
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:153
VehicleCargoList::Truncate
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
Definition: cargopacket.cpp:654
CargoPacket::source_xy
TileIndex source_xy
The origin of the cargo (first station in feeder chain).
Definition: cargopacket.h:51
CargoPacket::SourceStation
StationID SourceStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:159
span
A trimmed down version of what std::span will be in C++20.
Definition: span_type.hpp:60
VehicleCargoList::AgeCargo
void AgeCargo()
Ages the all cargo in this list.
Definition: cargopacket.cpp:381
VehicleCargoList::feeder_share
Money feeder_share
Cache for the feeder share.
Definition: cargopacket.h:274
CargoMovement< VehicleCargoList, VehicleCargoList >::max_move
uint max_move
Maximum amount of cargo to be moved with this action.
Definition: cargoaction.h:58
StationCargoList::HasCargoFor
bool HasCargoFor(StationIDStack next) const
Check for cargo headed for a specific station.
Definition: cargopacket.h:485
VehicleCargoList::AddToMeta
void AddToMeta(const CargoPacket *cp, MoveToAction action)
Adds a packet to the metadata.
Definition: cargopacket.cpp:370
cargo_type.h
CargoPayment
Helper class to perform the cargo payment.
Definition: economy_base.h:24
VehicleCargoList::Append
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
Definition: cargopacket.cpp:250
CargoDelivery
Action of final delivery of cargo.
Definition: cargoaction.h:39
CargoPacket::Split
CargoPacket * Split(uint new_size)
Split this packet in two and return the split off part.
Definition: cargopacket.cpp:89
CargoList::InvalidateCache
void InvalidateCache()
Invalidates the cached data and rebuilds it.
Definition: cargopacket.cpp:200
ST_INDUSTRY
@ ST_INDUSTRY
Source/destination is an industry.
Definition: cargo_type.h:148
CargoPacket::SourceSubsidyID
SourceID SourceSubsidyID() const
Gets the ID of the cargo's source.
Definition: cargopacket.h:150
CargoList::cargo_days_in_transit
uint cargo_days_in_transit
Cache for the sum of number of days in transit of each entity; comparable to man-hours.
Definition: cargopacket.h:225
VehicleCargoList::ChooseAction
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.
Definition: cargopacket.cpp:419
CargoList::count
uint count
Cache for the number of cargo entities.
Definition: cargopacket.h:224
CargoPacket::MAX_COUNT
static const uint16 MAX_COUNT
Maximum number of items in a single cargo packet.
Definition: cargopacket.h:65
VehicleCargoList::SetTransferLoadPlace
void SetTransferLoadPlace(TileIndex xy)
Sets loaded_at_xy to the current station for all cargo to be transferred.
Definition: cargopacket.cpp:400
CargoPacket::SourceSubsidyType
SourceType SourceSubsidyType() const
Gets the type of the cargo's source.
Definition: cargopacket.h:141
CargoPacket::source_id
SourceID source_id
Index of source, INVALID_SOURCE if unknown/invalid.
Definition: cargopacket.h:49
CargoPacket::AddFeederShare
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
Definition: cargopacket.h:94
CargoPacket::Count
uint16 Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:100
CargoList::MTA_TRANSFER
@ MTA_TRANSFER
Transfer the cargo to the station.
Definition: cargopacket.h:215
VehicleCargoList::KeepAll
void KeepAll()
Marks all cargo in the vehicle as to be kept.
Definition: cargopacket.h:408
VehicleCargoList::action_counts
uint action_counts[NUM_MOVE_TO_ACTION]
Counts of cargo to be transferred, delivered, kept and loaded.
Definition: cargopacket.h:275
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:508
VehicleCargoList::RemoveFromCache
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
Definition: cargopacket.cpp:333
CargoPacket::AfterLoad
static void AfterLoad()
Savegame conversion for cargopackets.
Definition: cargopacket_sl.cpp:23
VehicleCargoList::Parent
CargoList< VehicleCargoList, CargoPacketList > Parent
The (direct) parent of this class.
Definition: cargopacket.h:272
CargoPacket::source_type
SourceType source_type
Type of source_id.
Definition: cargopacket.h:48
CargoPacket::Reduce
void Reduce(uint count)
Reduce the packet by the given amount and remove the feeder share.
Definition: cargopacket.cpp:115
CargoList::RemoveFromCache
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
Definition: cargopacket.cpp:179
CargoShift
Action of shifting cargo from one vehicle to another.
Definition: cargoaction.h:106
CargoList::ReverseIterator
Tcont::reverse_iterator ReverseIterator
The reverse iterator for our container.
Definition: cargopacket.h:206
CargoPacket::LoadedAtXY
TileIndex LoadedAtXY() const
Gets the coordinates of the cargo's last loading station.
Definition: cargopacket.h:177
StationCargoList::ReservedCount
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Definition: cargopacket.h:517
CargoList::packets
Tcont packets
The cargo packets in this list.
Definition: cargopacket.h:227
CargoList
Simple collection class for a list of cargo packets.
Definition: cargopacket.h:34
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:167
vehicle_type.h
CargoPacket::next_station
TileOrStationID next_station
Station where the cargo wants to go next.
Definition: cargopacket.h:54
SourceType
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:147
CargoPacketID
uint32 CargoPacketID
Unique identifier for a single cargo packet.
Definition: cargopacket.h:24
Pool
Base class for all pools.
Definition: pool_type.hpp:81
CargoTransfer
Action of transferring cargo from a vehicle to a station.
Definition: cargoaction.h:71
SlStationGoods
Definition: station_sl.cpp:317
GetCargoPacketDesc
SaveLoadTable GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
Definition: cargopacket_sl.cpp:88
CargoRemoval
Abstract action of removing cargo from a vehicle or a station.
Definition: cargoaction.h:20
CargoList::MTA_LOAD
@ MTA_LOAD
Load the cargo from the station.
Definition: cargopacket.h:218
VehicleCargoList::RemainingCount
uint RemainingCount() const
Returns the sum of cargo to be kept in the vehicle at the current station.
Definition: cargopacket.h:388
CargoPacket::count
uint16 count
The amount of cargo in this packet.
Definition: cargopacket.h:46
CargoPacket::SetNextStation
void SetNextStation(StationID next_station)
Sets the station where the packet is supposed to go next.
Definition: cargopacket.h:88
INVALID_SOURCE
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
Definition: cargo_type.h:154
CargoPacket::SetLoadPlace
void SetLoadPlace(TileIndex load_place)
Sets the tile where the packet was loaded last.
Definition: cargopacket.h:82
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:323
VehicleCargoList::AreMergable
static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
Are the two CargoPackets mergeable in the context of a list of CargoPackets for a Vehicle?
Definition: cargopacket.h:433
StationCargoList::ShiftCargo
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.
Definition: cargopacket.cpp:718
StationCargoList::AreMergable
static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
Are the two CargoPackets mergeable in the context of a list of CargoPackets for a Station?
Definition: cargopacket.h:548
multimap.hpp
CargoPacket::NextStation
StationID NextStation() const
Gets the ID of station the cargo wants to go next.
Definition: cargopacket.h:186
CargoPacket::GetCargoPacketDesc
friend SaveLoadTable GetCargoPacketDesc()
We want this to be saved, right?
Definition: cargopacket_sl.cpp:88
CargoList::Iterator
Tcont::iterator Iterator
The iterator for our container.
Definition: cargopacket.h:204
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:43
SmallStack::IsEmpty
bool IsEmpty() const
Check if the stack is empty.
Definition: smallstack_type.hpp:244
CargoList::MTA_KEEP
@ MTA_KEEP
Keep the cargo in the vehicle.
Definition: cargopacket.h:217
OverflowSafeInt< int64 >
VehicleCargoList::ActionCount
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
Definition: cargopacket.h:342
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
VehicleCargoList::Reassign
uint Reassign(uint max_move, TileOrStationID update=INVALID_TILE)
Moves some cargo from one designation to another.
Definition: cargopacket.cpp:557
CargoList::MTA_DELIVER
@ MTA_DELIVER
Deliver the cargo to some town or industry.
Definition: cargopacket.h:216
StationCargoList::Append
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Definition: cargopacket.cpp:690
_cargopacket_pool
CargoPacketPool _cargopacket_pool
The actual pool with cargo packets.
StationCargoList::Parent
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
Definition: cargopacket.h:452
pool_type.hpp
VehicleCargoList::PopCargo
void PopCargo(Taction action)
Pops cargo from the back of the packet list and applies some action to it.
Definition: cargopacket.cpp:307
CargoPacket::FeederShare
Money FeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Definition: cargopacket.h:110
economy_type.h
StationCargoReroute
Action of rerouting cargo in a station.
Definition: cargoaction.h:126
MultiMap
Hand-rolled multimap as map of lists.
Definition: multimap.hpp:17
VehicleCargoList::Return
uint Return(uint max_move, StationCargoList *dest, StationID next_station)
Returns reserved cargo to the station and removes it from the cache.
Definition: cargopacket.cpp:604
CargoList::ConstReverseIterator
Tcont::const_reverse_iterator ConstReverseIterator
The const reverse iterator for our container.
Definition: cargopacket.h:210
VehicleCargoList::FeederShare
Money FeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:332
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:234
order_type.h
StationCargoList::Truncate
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
Definition: cargopacket.cpp:769
CargoPacket::CargoPacket
CargoPacket()
Create a new packet for savegame loading.
Definition: cargopacket.cpp:27
CargoPacket::FeederShare
Money FeederShare(uint part) const
Gets part of the amount of money already paid to earlier vehicles in the feeder chain.
Definition: cargopacket.h:121
StationCargoList::Load
uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next)
Loads cargo onto a vehicle.
Definition: cargopacket.cpp:840
CargoLoad
Action of loading cargo from a station onto a vehicle.
Definition: cargoaction.h:79
CargoPacket::SourceStationXY
TileIndex SourceStationXY() const
Gets the coordinates of the cargo's source station.
Definition: cargopacket.h:168
station_type.h
CargoPacket::~CargoPacket
~CargoPacket()
Destroy the packet.
Definition: cargopacket.h:72
CargoList::AddToCache
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
Definition: cargopacket.cpp:192