OpenTTD Source  20241108-master-g80f628063a
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 
23 typedef uint32_t CargoPacketID;
24 struct CargoPacket;
25 
30 
31 struct GoodsEntry; // forward-declare for Stage() and RerouteStalePackets()
32 
33 template <class Tinst, class Tcont> class CargoList;
34 class StationCargoList; // forward-declare, so we can use it in VehicleCargoList.
36 
40 struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> {
41 private:
42  /* A mathematical vector from (0,0). */
43  struct Vector {
44  int16_t x;
45  int16_t y;
46  };
47 
48  uint16_t count = 0;
49  uint16_t periods_in_transit = 0;
50 
52 
54  Vector travelled{0, 0};
55 
58 
59 #ifdef WITH_ASSERT
60  bool in_vehicle = false;
61 #endif /* WITH_ASSERT */
62 
63  StationID first_station = INVALID_STATION;
64  StationID next_hop = INVALID_STATION;
65 
67  template <class Tinst, class Tcont> friend class CargoList;
68  friend class VehicleCargoList;
69  friend class StationCargoList;
72 public:
74  static const uint16_t MAX_COUNT = UINT16_MAX;
75 
76  CargoPacket();
79  CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original);
80 
83 
84  CargoPacket *Split(uint new_size);
85  void Merge(CargoPacket *cp);
86  void Reduce(uint count);
87 
92  void SetNextHop(StationID next_hop)
93  {
94  this->next_hop = next_hop;
95  }
96 
112  {
113  if (this->source_xy == INVALID_TILE) {
114  this->source_xy = tile;
115  }
116 
117 #ifdef WITH_ASSERT
118  assert(!this->in_vehicle);
119  this->in_vehicle = true;
120 #endif /* WITH_ASSERT */
121 
122  /* We want to calculate the vector from tile-unload to tile-load. As
123  * we currently only know the latter, add it. When we know where we unload,
124  * we subtract is, giving us our vector (unload - load). */
125  this->travelled.x += TileX(tile);
126  this->travelled.y += TileY(tile);
127  }
128 
135  {
136 #ifdef WITH_ASSERT
137  assert(this->in_vehicle);
138  this->in_vehicle = false;
139 #endif /* WITH_ASSERT */
140 
141  this->travelled.x -= TileX(tile);
142  this->travelled.y -= TileY(tile);
143  }
144 
149  void AddFeederShare(Money new_share)
150  {
151  this->feeder_share += new_share;
152  }
153 
158  inline uint16_t Count() const
159  {
160  return this->count;
161  }
162 
168  inline Money GetFeederShare() const
169  {
170  return this->feeder_share;
171  }
172 
179  inline Money GetFeederShare(uint part) const
180  {
181  return this->feeder_share * part / static_cast<uint>(this->count);
182  }
183 
191  inline uint16_t GetPeriodsInTransit() const
192  {
193  return this->periods_in_transit;
194  }
195 
200  inline SourceType GetSourceType() const
201  {
202  return this->source_type;
203  }
204 
209  inline SourceID GetSourceID() const
210  {
211  return this->source_id;
212  }
213 
218  inline StationID GetFirstStation() const
219  {
220  return this->first_station;
221  }
222 
229  inline uint GetDistance(TileIndex current_tile) const
230  {
231  assert(this->source_xy != INVALID_TILE);
232 #ifdef WITH_ASSERT
233  assert(this->in_vehicle);
234 #endif /* WITH_ASSERT */
235 
236  /* Distance is always requested when the cargo is still inside the
237  * vehicle. So first finish the calculation for travelled to
238  * become a vector. */
239  auto local_travelled = travelled;
240  local_travelled.x -= TileX(current_tile);
241  local_travelled.y -= TileY(current_tile);
242 
243  /* Cargo-movement is a vector that indicates how much the cargo has
244  * actually traveled in a vehicle. This is the distance you get paid
245  * for. However, one could construct a route where this vector would
246  * be really long. To not overpay the player, cap out at the distance
247  * between source and destination.
248  *
249  * This way of calculating is to counter people moving cargo for free
250  * and instantly in stations, where you deliver it in one part of the
251  * station and pick it up in another. By using the actual distance
252  * traveled in a vehicle, using this trick doesn't give you more money.
253  *
254  * However, especially in large networks with large transfer station,
255  * etc, one could actually make the route a lot longer. In that case,
256  * use the actual distance between source and destination.
257  */
258 
259  uint distance_travelled = abs(local_travelled.x) + abs(local_travelled.y);
260  uint distance_source_dest = DistanceManhattan(this->source_xy, current_tile);
261  return std::min(distance_travelled, distance_source_dest);
262  }
263 
268  inline StationID GetNextHop() const
269  {
270  return this->next_hop;
271  }
272 
273  static void InvalidateAllFrom(SourceType src_type, SourceID src);
274  static void InvalidateAllFrom(StationID sid);
275  static void AfterLoad();
276 };
277 
282 template <class Tinst, class Tcont>
283 class CargoList {
284 public:
286  typedef typename Tcont::iterator Iterator;
288  typedef typename Tcont::reverse_iterator ReverseIterator;
290  typedef typename Tcont::const_iterator ConstIterator;
292  typedef typename Tcont::const_reverse_iterator ConstReverseIterator;
293 
296  MTA_BEGIN = 0,
301  MTA_END,
302  NUM_MOVE_TO_ACTION = MTA_END
303  };
304 
305 protected:
306  uint count;
308 
309  Tcont packets;
310 
311  void AddToCache(const CargoPacket *cp);
312 
313  void RemoveFromCache(const CargoPacket *cp, uint count);
314 
315  static bool TryMerge(CargoPacket *cp, CargoPacket *icp);
316 
317 public:
320 
321  ~CargoList();
322 
323  void OnCleanPool();
324 
329  inline const Tcont *Packets() const
330  {
331  return &this->packets;
332  }
333 
338  inline uint PeriodsInTransit() const
339  {
340  return this->count == 0 ? 0 : this->cargo_periods_in_transit / this->count;
341  }
342 
343  void InvalidateCache();
344 };
345 
346 typedef std::list<CargoPacket *> CargoPacketList;
347 
351 class VehicleCargoList : public CargoList<VehicleCargoList, CargoPacketList> {
352 protected:
355 
357  uint action_counts[NUM_MOVE_TO_ACTION];
358 
359  template<class Taction>
360  void ShiftCargo(Taction action);
361 
362  template<class Taction>
363  void PopCargo(Taction action);
364 
368  inline void AssertCountConsistency() const
369  {
370  assert(this->action_counts[MTA_KEEP] +
371  this->action_counts[MTA_DELIVER] +
372  this->action_counts[MTA_TRANSFER] +
373  this->action_counts[MTA_LOAD] == this->count);
374  }
375 
376  void AddToCache(const CargoPacket *cp);
377  void RemoveFromCache(const CargoPacket *cp, uint count);
378 
379  void AddToMeta(const CargoPacket *cp, MoveToAction action);
380  void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count);
381 
382  static MoveToAction ChooseAction(const CargoPacket *cp, StationID cargo_next,
383  StationID current_station, bool accepted, StationIDStack next_station);
384 
385 public:
387  friend class StationCargoList;
389  friend class CargoList<VehicleCargoList, CargoPacketList>;
390  /* So we can use private/protected variables in the saveload code */
391  friend class SlVehicleCommon;
392 
393  friend class CargoShift;
394  friend class CargoTransfer;
395  friend class CargoDelivery;
396  template<class Tsource>
397  friend class CargoRemoval;
398  friend class CargoReturn;
399  friend class VehicleCargoReroute;
400 
405  inline StationID GetFirstStation() const
406  {
407  return this->count == 0 ? INVALID_STATION : this->packets.front()->first_station;
408  }
409 
414  inline Money GetFeederShare() const
415  {
416  return this->feeder_share;
417  }
418 
424  inline uint ActionCount(MoveToAction action) const
425  {
426  return this->action_counts[action];
427  }
428 
434  inline uint StoredCount() const
435  {
436  return this->count - this->action_counts[MTA_LOAD];
437  }
438 
443  inline uint TotalCount() const
444  {
445  return this->count;
446  }
447 
452  inline uint ReservedCount() const
453  {
454  return this->action_counts[MTA_LOAD];
455  }
456 
461  inline uint UnloadCount() const
462  {
463  return this->action_counts[MTA_TRANSFER] + this->action_counts[MTA_DELIVER];
464  }
465 
470  inline uint RemainingCount() const
471  {
472  return this->action_counts[MTA_KEEP] + this->action_counts[MTA_LOAD];
473  }
474 
475  void Append(CargoPacket *cp, MoveToAction action = MTA_KEEP);
476 
477  void AgeCargo();
478 
479  void InvalidateCache();
480 
481  bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoID cargo, CargoPayment *payment, TileIndex current_tile);
482 
488  inline void KeepAll()
489  {
490  this->action_counts[MTA_DELIVER] = this->action_counts[MTA_TRANSFER] = this->action_counts[MTA_LOAD] = 0;
491  this->action_counts[MTA_KEEP] = this->count;
492  }
493 
494  /* Methods for moving cargo around. First parameter is always maximum
495  * amount of cargo to be moved. Second parameter is destination (if
496  * applicable), return value is amount of cargo actually moved. */
497 
498  template<MoveToAction Tfrom, MoveToAction Tto>
499  uint Reassign(uint max_move);
500  uint Return(uint max_move, StationCargoList *dest, StationID next_station, TileIndex current_tile);
501  uint Unload(uint max_move, StationCargoList *dest, CargoID cargo, CargoPayment *payment, TileIndex current_tile);
502  uint Shift(uint max_move, VehicleCargoList *dest);
503  uint Truncate(uint max_move = UINT_MAX);
504  uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
505 
513  static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
514  {
515  return cp1->source_xy == cp2->source_xy &&
516  cp1->periods_in_transit == cp2->periods_in_transit &&
517  cp1->source_type == cp2->source_type &&
518  cp1->first_station == cp2->first_station &&
519  cp1->source_id == cp2->source_id;
520  }
521 };
522 
524 typedef std::map<StationID, uint> StationCargoAmountMap;
525 
529 class StationCargoList : public CargoList<StationCargoList, StationCargoPacketMap> {
530 protected:
533 
535 
536 public:
539  /* So we can use private/protected variables in the saveload code */
540  friend class SlStationGoods;
541 
542  friend class CargoLoad;
543  friend class CargoTransfer;
544  template<class Tsource>
545  friend class CargoRemoval;
546  friend class CargoReservation;
547  friend class CargoReturn;
548  friend class StationCargoReroute;
549 
550  static void InvalidateAllFrom(SourceType src_type, SourceID src);
551 
552  template<class Taction>
553  bool ShiftCargo(Taction &action, StationID next);
554 
555  template<class Taction>
556  uint ShiftCargo(Taction action, StationIDStack next, bool include_invalid);
557 
558  void Append(CargoPacket *cp, StationID next);
559 
565  inline bool HasCargoFor(StationIDStack next) const
566  {
567  while (!next.IsEmpty()) {
568  if (this->packets.find(next.Pop()) != this->packets.end()) return true;
569  }
570  /* Packets for INVALID_STATION can go anywhere. */
571  return this->packets.find(INVALID_STATION) != this->packets.end();
572  }
573 
578  inline StationID GetFirstStation() const
579  {
580  return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->first_station;
581  }
582 
588  inline uint AvailableCount() const
589  {
590  return this->count;
591  }
592 
597  inline uint ReservedCount() const
598  {
599  return this->reserved_count;
600  }
601 
607  inline uint TotalCount() const
608  {
609  return this->count + this->reserved_count;
610  }
611 
612  /* Methods for moving cargo around. First parameter is always maximum
613  * amount of cargo to be moved. Second parameter is destination (if
614  * applicable), return value is amount of cargo actually moved. */
615 
616  uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile);
617  uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile);
618  uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr);
619  uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
620 
628  static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
629  {
630  return cp1->source_xy == cp2->source_xy &&
631  cp1->periods_in_transit == cp2->periods_in_transit &&
632  cp1->source_type == cp2->source_type &&
633  cp1->first_station == cp2->first_station &&
634  cp1->source_id == cp2->source_id;
635  }
636 };
637 
638 #endif /* CARGOPACKET_H */
Types related to cargoes...
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
uint16_t SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:143
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
Definition: cargo_type.h:144
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:137
@ Industry
Source/destination is an industry.
CargoPacketPool _cargopacket_pool
The actual pool with cargo packets.
uint32_t CargoPacketID
Unique identifier for a single cargo packet.
Definition: cargopacket.h:23
SaveLoadTable GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
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:24
Action of final delivery of cargo.
Definition: cargoaction.h:39
Simple collection class for a list of cargo packets.
Definition: cargopacket.h:283
Tcont::reverse_iterator ReverseIterator
The reverse iterator for our container.
Definition: cargopacket.h:288
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
MoveToAction
Kind of actions that could be done with packets on move.
Definition: cargopacket.h:295
@ MTA_KEEP
Keep the cargo in the vehicle.
Definition: cargopacket.h:299
@ MTA_DELIVER
Deliver the cargo to some town or industry.
Definition: cargopacket.h:298
@ MTA_LOAD
Load the cargo from the station.
Definition: cargopacket.h:300
@ MTA_TRANSFER
Transfer the cargo to the station.
Definition: cargopacket.h:297
Tcont packets
The cargo packets in this list.
Definition: cargopacket.h:309
~CargoList()
Destroy the cargolist ("frees" all cargo packets).
Tcont::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:290
uint count
Cache for the number of cargo entities.
Definition: cargopacket.h:306
CargoList()
Create the cargo list.
Definition: cargopacket.h:319
uint64_t cargo_periods_in_transit
Cache for the sum of number of cargo aging periods in transit of each entity; comparable to man-hours...
Definition: cargopacket.h:307
static bool TryMerge(CargoPacket *cp, CargoPacket *icp)
Tries to merge the second packet into the first and return if that was successful.
Tcont::iterator Iterator
The iterator for our container.
Definition: cargopacket.h:286
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:329
Tcont::const_reverse_iterator ConstReverseIterator
The const reverse iterator for our container.
Definition: cargopacket.h:292
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
Definition: cargopacket.h:338
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
void InvalidateCache()
Invalidates the cached data and rebuilds it.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
Action of loading cargo from a station onto a vehicle.
Definition: cargoaction.h:83
uint max_move
Maximum amount of cargo to be moved with this action.
Definition: cargoaction.h:60
Abstract action of removing cargo from a vehicle or a station.
Definition: cargoaction.h:20
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition: cargoaction.h:93
Action of returning previously reserved cargo from the vehicle to the station.
Definition: cargoaction.h:101
Action of shifting cargo from one vehicle to another.
Definition: cargoaction.h:112
Action of transferring cargo from a vehicle to a station.
Definition: cargoaction.h:73
Hand-rolled multimap as map of lists.
Definition: multimap.hpp:281
Minimal stack that uses a pool to avoid pointers.
Titem Pop()
Pop an item from the stack.
bool IsEmpty() const
Check if the stack is empty.
CargoList that is used for stations.
Definition: cargopacket.h:529
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
Definition: cargopacket.h:532
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:607
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.
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Definition: cargopacket.h:597
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:588
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile)
Reserves cargo for loading onto the vehicle.
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 ShiftCargo(Taction &action, StationID next)
Shifts cargo from the front of the packet list for a specific station and applies some action to it.
uint reserved_count
Amount of cargo being reserved for loading.
Definition: cargopacket.h:534
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:628
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile)
Loads cargo onto a vehicle.
bool HasCargoFor(StationIDStack next) const
Check for cargo headed for a specific station.
Definition: cargopacket.h:565
StationID GetFirstStation() const
Returns first station of the first cargo packet in this list.
Definition: cargopacket.h:578
Action of rerouting cargo in a station.
Definition: cargoaction.h:132
CargoList that is used for vehicles.
Definition: cargopacket.h:351
uint Shift(uint max_move, VehicleCargoList *dest)
Shifts cargo between two vehicles.
void AddToMeta(const CargoPacket *cp, MoveToAction action)
Adds a packet to the metadata.
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.
Definition: cargopacket.h:461
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoID cargo, CargoPayment *payment, TileIndex current_tile)
Stages cargo for unloading.
void PopCargo(Taction action)
Pops cargo from the back of the packet list and applies some action to it.
Money GetFeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:414
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.
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
Definition: cargopacket.h:424
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
uint Unload(uint max_move, StationCargoList *dest, CargoID cargo, CargoPayment *payment, TileIndex current_tile)
Unloads cargo at the given station.
void AssertCountConsistency() const
Assert that the designation counts add up.
Definition: cargopacket.h:368
void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count)
Removes a packet or part of it from the metadata.
uint Return(uint max_move, StationCargoList *dest, StationID next_station, TileIndex current_tile)
Returns reserved cargo to the station and removes it from the cache.
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:513
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
Definition: cargopacket.h:443
uint action_counts[NUM_MOVE_TO_ACTION]
Counts of cargo to be transferred, delivered, kept and loaded.
Definition: cargopacket.h:357
uint ReservedCount() const
Returns sum of reserved cargo.
Definition: cargopacket.h:452
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 RemainingCount() const
Returns the sum of cargo to be kept in the vehicle at the current station.
Definition: cargopacket.h:470
CargoList< VehicleCargoList, CargoPacketList > Parent
The (direct) parent of this class.
Definition: cargopacket.h:354
Money feeder_share
Cache for the feeder share.
Definition: cargopacket.h:356
void Append(CargoPacket *cp, MoveToAction action=MTA_KEEP)
Appends the given cargo packet.
void RemoveFromCache(const CargoPacket *cp, uint count)
Update the cached values to reflect the removal of this packet or part of it.
uint Reassign(uint max_move)
Moves some cargo from one designation to another.
void InvalidateCache()
Invalidates the cached data and rebuild it.
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
void KeepAll()
Marks all cargo in the vehicle as to be kept.
Definition: cargopacket.h:488
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
Definition: cargopacket.h:405
void AgeCargo()
Ages the all cargo in this list.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:434
void ShiftCargo(Taction action)
Shifts cargo from the front of the packet list and applies some action to it.
Action of rerouting cargo staged for transfer in a vehicle.
Definition: cargoaction.h:140
Types related to the economy.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:146
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:425
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:415
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
Multimap with deterministic ordering of items with equal keys.
Types related to orders.
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
Functions/types related to saving and loading games.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition: saveload.h:511
Types related to stations.
Container for cargo from the same location and time.
Definition: cargopacket.h:40
void Reduce(uint count)
Reduce the packet by the given amount and remove the feeder share.
uint16_t Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:158
Money GetFeederShare(uint part) const
Gets part of the amount of money already paid to earlier vehicles in the feeder chain.
Definition: cargopacket.h:179
~CargoPacket()
Destroy the packet.
Definition: cargopacket.h:82
void Merge(CargoPacket *cp)
Merge another packet into this one.
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
Definition: cargopacket.h:51
static const uint16_t MAX_COUNT
Maximum number of items in a single cargo packet.
Definition: cargopacket.h:74
TileIndex source_xy
The origin of the cargo.
Definition: cargopacket.h:53
void SetNextHop(StationID next_hop)
Sets the station where the packet is supposed to go next.
Definition: cargopacket.h:92
SourceID source_id
Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
Definition: cargopacket.h:56
CargoPacket * Split(uint new_size)
Split this packet in two and return the split off part.
Definition: cargopacket.cpp:99
StationID next_hop
Station where the cargo wants to go next.
Definition: cargopacket.h:64
void UpdateLoadingTile(TileIndex tile)
Update for the cargo being loaded on this tile.
Definition: cargopacket.h:111
friend SaveLoadTable GetCargoPacketDesc()
We want this to be saved, right?
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
Definition: cargopacket.h:149
SourceID GetSourceID() const
Gets the ID of the cargo's source.
Definition: cargopacket.h:209
SourceType source_type
Type of source_id.
Definition: cargopacket.h:57
static void AfterLoad()
Savegame conversion for cargopackets.
StationID GetNextHop() const
Gets the ID of station the cargo wants to go next.
Definition: cargopacket.h:268
uint16_t count
The amount of cargo in this packet.
Definition: cargopacket.h:48
CargoPacket()
Create a new packet for savegame loading.
Definition: cargopacket.cpp:27
Money GetFeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Definition: cargopacket.h:168
StationID GetFirstStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:218
uint GetDistance(TileIndex current_tile) const
Get the current distance the cargo has traveled.
Definition: cargopacket.h:229
StationID first_station
The station where the cargo came from first.
Definition: cargopacket.h:63
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Vector travelled
If cargo is in station: the vector from the unload tile to the source tile. If in vehicle: an interme...
Definition: cargopacket.h:54
uint16_t GetPeriodsInTransit() const
Gets the number of cargo aging periods this cargo has been in transit.
Definition: cargopacket.h:191
void UpdateUnloadingTile(TileIndex tile)
Update for the cargo being unloaded on this tile.
Definition: cargopacket.h:134
SourceType GetSourceType() const
Gets the type of the cargo's source.
Definition: cargopacket.h:200
uint16_t periods_in_transit
Amount of cargo aging periods this packet has been in transit.
Definition: cargopacket.h:49
Helper class to perform the cargo payment.
Definition: economy_base.h:24
Stores station stats for a single cargo.
Definition: station_base.h:166
Base class for all PoolItems.
Definition: pool_type.hpp:237
Base class for all pools.
Definition: pool_type.hpp:80
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
Types related to vehicles.