OpenTTD Source: src/cargopacket.h Source File

OpenTTD Source 14.0-beta1

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
27 typedef Pool<CargoPacket, CargoPacketID, 1024, 0xFFF000, PT_NORMAL, true, false> CargoPacketPool;
29 extern CargoPacketPool _cargopacket_pool;
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.
35 extern SaveLoadTable GetCargoPacketDesc();
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
51 Money feeder_share{0};
52
53 TileIndex source_xy{INVALID_TILE};
54 Vector travelled{0, 0};
55
56 SourceID source_id{INVALID_SOURCE};
57 SourceType source_type{SourceType::Industry};
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;
71 friend SaveLoadTable GetCargoPacketDesc();
72 public:
74 static const uint16_t MAX_COUNT = UINT16_MAX;
75
76 CargoPacket();
77 CargoPacket(StationID first_station, uint16_t count, SourceType source_type, SourceID source_id);
78 CargoPacket(uint16_t count, uint16_t periods_in_transit, StationID first_station, TileIndex source_xy, Money feeder_share);
79 CargoPacket(uint16_t count, Money feeder_share, CargoPacket &original);
80
82 ~CargoPacket() { }
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
111 void UpdateLoadingTile(TileIndex tile)
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
134 void UpdateUnloadingTile(TileIndex tile)
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
295 enum MoveToAction {
296 MTA_BEGIN = 0,
297 MTA_TRANSFER = 0,
298 MTA_DELIVER,
299 MTA_KEEP,
300 MTA_LOAD,
301 MTA_END,
302 NUM_MOVE_TO_ACTION = MTA_END
303 };
304
305 protected:
306 uint count;
307 uint64_t cargo_periods_in_transit;
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:
319 CargoList() {}
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:
354 typedef CargoList<VehicleCargoList, CargoPacketList> Parent;
355
356 Money feeder_share;
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, 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, 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
523 typedef MultiMap<StationID, CargoPacket *> StationCargoPacketMap;
524 typedef std::map<StationID, uint> StationCargoAmountMap;
525
529 class StationCargoList : public CargoList<StationCargoList, StationCargoPacketMap> {
530 protected:
532 typedef CargoList<StationCargoList, StationCargoPacketMap> Parent;
533
534 uint reserved_count;
535
536 public:
538 friend class CargoList<StationCargoList, StationCargoPacketMap>;
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 */
VehicleCargoList::TotalCount
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
Definition: cargopacket.h:443
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
CargoPacket::feeder_share
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
Definition: cargopacket.h:51
CargoList::CargoList
CargoList()
Create the cargo list.
Definition: cargopacket.h:319
CargoList::ConstIterator
Tcont::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:290
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:434
SmallStack
Minimal stack that uses a pool to avoid pointers.
Definition: smallstack_type.hpp:135
VehicleCargoList::ShiftCargo
void ShiftCargo(Taction action)
Shifts cargo from the front of the packet list and applies some action to it.
Definition: cargopacket.cpp:295
SmallStack::Pop
Titem Pop()
Pop an item from the stack.
Definition: smallstack_type.hpp:212
CargoList< VehicleCargoList, CargoPacketList >::MoveToAction
MoveToAction
Kind of actions that could be done with packets on move.
Definition: cargopacket.h:295
CargoReservation
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition: cargoaction.h:92
VehicleCargoList::Shift
uint Shift(uint max_move, VehicleCargoList *dest)
Shifts cargo between two vehicles.
Definition: cargopacket.cpp:610
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:177
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:663
VehicleCargoList::Stage
bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8_t order_flags, const GoodsEntry *ge, CargoPayment *payment, TileIndex current_tile)
Stages cargo for unloading.
Definition: cargopacket.cpp:439
CargoPacket::GetNextHop
StationID GetNextHop() const
Gets the ID of station the cargo wants to go next.
Definition: cargopacket.h:268
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:228
SaveLoadTable
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition: saveload.h:494
CargoPacket::travelled
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
StationCargoList::Load
uint Load(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile)
Loads cargo onto a vehicle.
Definition: cargopacket.cpp:834
VehicleCargoList::Unload
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment, TileIndex current_tile)
Unloads cargo at the given station.
Definition: cargopacket.cpp:626
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:329
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:137
StationCargoList::reserved_count
uint reserved_count
Amount of cargo being reserved for loading.
Definition: cargopacket.h:534
VehicleCargoList::InvalidateCache
void InvalidateCache()
Invalidates the cached data and rebuild it.
Definition: cargopacket.cpp:531
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:24
VehicleCargoList::ReservedCount
uint ReservedCount() const
Returns sum of reserved cargo.
Definition: cargopacket.h:452
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
VehicleCargoList::RemoveFromMeta
void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count)
Removes a packet or part of it from the metadata.
Definition: cargopacket.cpp:366
VehicleCargoList::AssertCountConsistency
void AssertCountConsistency() const
Assert that the designation counts add up.
Definition: cargopacket.h:368
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:529
CargoList::~CargoList
~CargoList()
Destroy the cargolist ("frees" all cargo packets).
Definition: cargopacket.cpp:165
saveload.h
CargoReturn
Action of returning previously reserved cargo from the vehicle to the station.
Definition: cargoaction.h:100
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
VehicleCargoList::Return
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.
Definition: cargopacket.cpp:597
VehicleCargoList::AddToCache
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
Definition: cargopacket.cpp:354
VehicleCargoList::GetFirstStation
StationID GetFirstStation() const
Returns the first station of the first cargo packet in this list.
Definition: cargopacket.h:405
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:607
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:351
CargoPacket::first_station
StationID first_station
The station where the cargo came from first.
Definition: cargopacket.h:63
CargoPacket::Merge
void Merge(CargoPacket *cp)
Merge another packet into this one.
Definition: cargopacket.cpp:114
CargoPacket::count
uint16_t count
The amount of cargo in this packet.
Definition: cargopacket.h:48
SlVehicleCommon
Definition: vehicle_sl.cpp:606
CargoPacket::GetFirstStation
StationID GetFirstStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:218
VehicleCargoList::UnloadCount
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.
Definition: cargopacket.h:461
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
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:854
VehicleCargoReroute
Action of rerouting cargo staged for transfer in a vehicle.
Definition: cargoaction.h:139
CargoPacketID
uint32_t CargoPacketID
Unique identifier for a single cargo packet.
Definition: cargopacket.h:23
VehicleCargoList::Truncate
uint Truncate(uint max_move=UINT_MAX)
Truncates the cargo in this list to the given amount.
Definition: cargopacket.cpp:648
CargoPacket::source_xy
TileIndex source_xy
The origin of the cargo.
Definition: cargopacket.h:53
CargoPacket::UpdateLoadingTile
void UpdateLoadingTile(TileIndex tile)
Update for the cargo being loaded on this tile.
Definition: cargopacket.h:111
CargoPacket::GetFeederShare
Money GetFeederShare() const
Gets the amount of money already paid to earlier vehicles in the feeder chain.
Definition: cargopacket.h:168
CargoPacket::GetSourceType
SourceType GetSourceType() const
Gets the type of the cargo's source.
Definition: cargopacket.h:200
CargoPacket::GetFeederShare
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
VehicleCargoList::Reassign
uint Reassign(uint max_move)
Moves some cargo from one designation to another.
Definition: cargopacket.cpp:550
VehicleCargoList::AgeCargo
void AgeCargo()
Ages the all cargo in this list.
Definition: cargopacket.cpp:391
VehicleCargoList::feeder_share
Money feeder_share
Cache for the feeder share.
Definition: cargopacket.h:356
CargoMovement< VehicleCargoList, VehicleCargoList >::max_move
uint max_move
Maximum amount of cargo to be moved with this action.
Definition: cargoaction.h:59
StationCargoList::HasCargoFor
bool HasCargoFor(StationIDStack next) const
Check for cargo headed for a specific station.
Definition: cargopacket.h:565
VehicleCargoList::AddToMeta
void AddToMeta(const CargoPacket *cp, MoveToAction action)
Adds a packet to the metadata.
Definition: cargopacket.cpp:380
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:260
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:99
CargoList::InvalidateCache
void InvalidateCache()
Invalidates the cached data and rebuilds it.
Definition: cargopacket.cpp:210
SourceID
uint16_t SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:126
CargoPacket::GetDistance
uint GetDistance(TileIndex current_tile) const
Get the current distance the cargo has traveled.
Definition: cargopacket.h:229
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:411
CargoList::count
uint count
Cache for the number of cargo entities.
Definition: cargopacket.h:306
CargoPacket::Vector
Definition: cargopacket.h:43
CargoPacket::SetNextHop
void SetNextHop(StationID next_hop)
Sets the station where the packet is supposed to go next.
Definition: cargopacket.h:92
CargoPacket::MAX_COUNT
static const uint16_t MAX_COUNT
Maximum number of items in a single cargo packet.
Definition: cargopacket.h:74
CargoPacket::source_id
SourceID source_id
Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid.
Definition: cargopacket.h:56
CargoPacket::AddFeederShare
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
Definition: cargopacket.h:149
CargoList::MTA_TRANSFER
@ MTA_TRANSFER
Transfer the cargo to the station.
Definition: cargopacket.h:297
VehicleCargoList::KeepAll
void KeepAll()
Marks all cargo in the vehicle as to be kept.
Definition: cargopacket.h:488
VehicleCargoList::action_counts
uint action_counts[NUM_MOVE_TO_ACTION]
Counts of cargo to be transferred, delivered, kept and loaded.
Definition: cargopacket.h:357
SourceType::Industry
@ Industry
Source/destination is an industry.
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:588
CargoList::PeriodsInTransit
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
Definition: cargopacket.h:338
CargoList::cargo_periods_in_transit
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
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:343
CargoPacket::GetSourceID
SourceID GetSourceID() const
Gets the ID of the cargo's source.
Definition: cargopacket.h:209
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:354
CargoPacket::source_type
SourceType source_type
Type of source_id.
Definition: cargopacket.h:57
CargoPacket::Reduce
void Reduce(uint count)
Reduce the packet by the given amount and remove the feeder share.
Definition: cargopacket.cpp:125
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:189
CargoShift
Action of shifting cargo from one vehicle to another.
Definition: cargoaction.h:111
CargoList::ReverseIterator
Tcont::reverse_iterator ReverseIterator
The reverse iterator for our container.
Definition: cargopacket.h:288
StationCargoList::ReservedCount
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Definition: cargopacket.h:597
CargoPacket::periods_in_transit
uint16_t periods_in_transit
Amount of cargo aging periods this packet has been in transit.
Definition: cargopacket.h:49
CargoList::packets
Tcont packets
The cargo packets in this list.
Definition: cargopacket.h:309
CargoPacket::GetPeriodsInTransit
uint16_t GetPeriodsInTransit() const
Gets the number of cargo aging periods this cargo has been in transit.
Definition: cargopacket.h:191
CargoList
Simple collection class for a list of cargo packets.
Definition: cargopacket.h:33
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:166
vehicle_type.h
SourceType
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:120
CargoPacket::next_hop
StationID next_hop
Station where the cargo wants to go next.
Definition: cargopacket.h:64
Pool
Base class for all pools.
Definition: pool_type.hpp:80
VehicleCargoList::GetFeederShare
Money GetFeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:414
CargoTransfer
Action of transferring cargo from a vehicle to a station.
Definition: cargoaction.h:72
SlStationGoods
Definition: station_sl.cpp:354
abs
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:23
GetCargoPacketDesc
SaveLoadTable GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
Definition: cargopacket_sl.cpp:119
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:300
VehicleCargoList::RemainingCount
uint RemainingCount() const
Returns the sum of cargo to be kept in the vehicle at the current station.
Definition: cargopacket.h:470
CargoPacket::UpdateUnloadingTile
void UpdateUnloadingTile(TileIndex tile)
Update for the cargo being unloaded on this tile.
Definition: cargopacket.h:134
INVALID_SOURCE
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
Definition: cargo_type.h:127
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:513
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:712
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:628
multimap.hpp
CargoPacket::GetCargoPacketDesc
friend SaveLoadTable GetCargoPacketDesc()
We want this to be saved, right?
Definition: cargopacket_sl.cpp:119
CargoList::Iterator
Tcont::iterator Iterator
The iterator for our container.
Definition: cargopacket.h:286
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:40
SmallStack::IsEmpty
bool IsEmpty() const
Check if the stack is empty.
Definition: smallstack_type.hpp:243
CargoList::MTA_KEEP
@ MTA_KEEP
Keep the cargo in the vehicle.
Definition: cargopacket.h:299
OverflowSafeInt< int64_t >
VehicleCargoList::ActionCount
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
Definition: cargopacket.h:424
CargoList::MTA_DELIVER
@ MTA_DELIVER
Deliver the cargo to some town or industry.
Definition: cargopacket.h:298
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:684
_cargopacket_pool
CargoPacketPool _cargopacket_pool
The actual pool with cargo packets.
CargoPacket::Count
uint16_t Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:158
StationCargoList::Parent
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
Definition: cargopacket.h:532
pool_type.hpp
StationCargoList::Reserve
uint Reserve(uint max_move, VehicleCargoList *dest, StationIDStack next, TileIndex current_tile)
Reserves cargo for loading onto the vehicle.
Definition: cargopacket.cpp:817
VehicleCargoList::PopCargo
void PopCargo(Taction action)
Pops cargo from the back of the packet list and applies some action to it.
Definition: cargopacket.cpp:317
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
economy_type.h
StationCargoReroute
Action of rerouting cargo in a station.
Definition: cargoaction.h:131
MultiMap
Hand-rolled multimap as map of lists.
Definition: multimap.hpp:14
CargoList::ConstReverseIterator
Tcont::const_reverse_iterator ConstReverseIterator
The const reverse iterator for our container.
Definition: cargopacket.h:292
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:233
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:763
StationCargoList::GetFirstStation
StationID GetFirstStation() const
Returns first station of the first cargo packet in this list.
Definition: cargopacket.h:578
CargoPacket::CargoPacket
CargoPacket()
Create a new packet for savegame loading.
Definition: cargopacket.cpp:27
CargoLoad
Action of loading cargo from a station onto a vehicle.
Definition: cargoaction.h:82
station_type.h
CargoPacket::~CargoPacket
~CargoPacket()
Destroy the packet.
Definition: cargopacket.h:82
CargoList::AddToCache
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
Definition: cargopacket.cpp:202