OpenTTD Source: src/cargopacket.h Source File

OpenTTD Source 1.11.0-RC1

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 <list>
21
23 typedef uint32 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 const struct SaveLoad *GetCargoPacketDesc();
36
37 typedef uint32 TileOrStationID;
38
42 struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> {
43 private:
44 Money feeder_share;
45 uint16 count;
46 byte days_in_transit;
47 SourceType source_type;
48 SourceID source_id;
49 StationID source;
50 TileIndex source_xy;
51 union {
52 TileOrStationID loaded_at_xy;
53 TileOrStationID next_station;
54 };
55
57 template <class Tinst, class Tcont> friend class CargoList;
58 friend class VehicleCargoList;
59 friend class StationCargoList;
61 friend const struct SaveLoad *GetCargoPacketDesc();
62 public:
64 static const uint16 MAX_COUNT = UINT16_MAX;
65
66 CargoPacket();
67 CargoPacket(StationID source, TileIndex source_xy, uint16 count, SourceType source_type, SourceID source_id);
68 CargoPacket(uint16 count, byte days_in_transit, StationID source, TileIndex source_xy, TileIndex loaded_at_xy, Money feeder_share = 0, SourceType source_type = ST_INDUSTRY, SourceID source_id = INVALID_SOURCE);
69
71 ~CargoPacket() { }
72
73 CargoPacket *Split(uint new_size);
74 void Merge(CargoPacket *cp);
75 void Reduce(uint count);
76
81 void SetLoadPlace(TileIndex load_place) { this->loaded_at_xy = load_place; }
82
87 void SetNextStation(StationID next_station) { this->next_station = next_station; }
88
93 void AddFeederShare(Money new_share) { this->feeder_share += new_share; }
94
99 inline uint16 Count() const
100 {
101 return this->count;
102 }
103
109 inline Money FeederShare() const
110 {
111 return this->feeder_share;
112 }
113
120 inline Money FeederShare(uint part) const
121 {
122 return this->feeder_share * part / static_cast<uint>(this->count);
123 }
124
131 inline byte DaysInTransit() const
132 {
133 return this->days_in_transit;
134 }
135
140 inline SourceType SourceSubsidyType() const
141 {
142 return this->source_type;
143 }
144
149 inline SourceID SourceSubsidyID() const
150 {
151 return this->source_id;
152 }
153
158 inline StationID SourceStation() const
159 {
160 return this->source;
161 }
162
167 inline TileIndex SourceStationXY() const
168 {
169 return this->source_xy;
170 }
171
176 inline TileIndex LoadedAtXY() const
177 {
178 return this->loaded_at_xy;
179 }
180
185 inline StationID NextStation() const
186 {
187 return this->next_station;
188 }
189
190 static void InvalidateAllFrom(SourceType src_type, SourceID src);
191 static void InvalidateAllFrom(StationID sid);
192 static void AfterLoad();
193 };
194
199 template <class Tinst, class Tcont>
200 class CargoList {
201 public:
203 typedef typename Tcont::iterator Iterator;
205 typedef typename Tcont::reverse_iterator ReverseIterator;
207 typedef typename Tcont::const_iterator ConstIterator;
209 typedef typename Tcont::const_reverse_iterator ConstReverseIterator;
210
212 enum MoveToAction {
213 MTA_BEGIN = 0,
214 MTA_TRANSFER = 0,
215 MTA_DELIVER,
216 MTA_KEEP,
217 MTA_LOAD,
218 MTA_END,
219 NUM_MOVE_TO_ACTION = MTA_END
220 };
221
222 protected:
223 uint count;
224 uint cargo_days_in_transit;
225
226 Tcont packets;
227
228 void AddToCache(const CargoPacket *cp);
229
230 void RemoveFromCache(const CargoPacket *cp, uint count);
231
232 static bool TryMerge(CargoPacket *cp, CargoPacket *icp);
233
234 public:
236 CargoList() {}
237
238 ~CargoList();
239
240 void OnCleanPool();
241
246 inline const Tcont *Packets() const
247 {
248 return &this->packets;
249 }
250
255 inline uint DaysInTransit() const
256 {
257 return this->count == 0 ? 0 : this->cargo_days_in_transit / this->count;
258 }
259
260 void InvalidateCache();
261 };
262
263 typedef std::list<CargoPacket *> CargoPacketList;
264
268 class VehicleCargoList : public CargoList<VehicleCargoList, CargoPacketList> {
269 protected:
271 typedef CargoList<VehicleCargoList, CargoPacketList> Parent;
272
273 Money feeder_share;
274 uint action_counts[NUM_MOVE_TO_ACTION];
275
276 template<class Taction>
277 void ShiftCargo(Taction action);
278
279 template<class Taction>
280 void PopCargo(Taction action);
281
285 inline void AssertCountConsistency() const
286 {
287 assert(this->action_counts[MTA_KEEP] +
288 this->action_counts[MTA_DELIVER] +
289 this->action_counts[MTA_TRANSFER] +
290 this->action_counts[MTA_LOAD] == this->count);
291 }
292
293 void AddToCache(const CargoPacket *cp);
294 void RemoveFromCache(const CargoPacket *cp, uint count);
295
296 void AddToMeta(const CargoPacket *cp, MoveToAction action);
297 void RemoveFromMeta(const CargoPacket *cp, MoveToAction action, uint count);
298
299 static MoveToAction ChooseAction(const CargoPacket *cp, StationID cargo_next,
300 StationID current_station, bool accepted, StationIDStack next_station);
301
302 public:
304 friend class StationCargoList;
306 friend class CargoList<VehicleCargoList, CargoPacketList>;
308 friend const struct SaveLoad *GetVehicleDescription(VehicleType vt);
309
310 friend class CargoShift;
311 friend class CargoTransfer;
312 friend class CargoDelivery;
313 template<class Tsource>
314 friend class CargoRemoval;
315 friend class CargoReturn;
316 friend class VehicleCargoReroute;
317
322 inline StationID Source() const
323 {
324 return this->count == 0 ? INVALID_STATION : this->packets.front()->source;
325 }
326
331 inline Money FeederShare() const
332 {
333 return this->feeder_share;
334 }
335
341 inline uint ActionCount(MoveToAction action) const
342 {
343 return this->action_counts[action];
344 }
345
351 inline uint StoredCount() const
352 {
353 return this->count - this->action_counts[MTA_LOAD];
354 }
355
360 inline uint TotalCount() const
361 {
362 return this->count;
363 }
364
369 inline uint ReservedCount() const
370 {
371 return this->action_counts[MTA_LOAD];
372 }
373
378 inline uint UnloadCount() const
379 {
380 return this->action_counts[MTA_TRANSFER] + this->action_counts[MTA_DELIVER];
381 }
382
387 inline uint RemainingCount() const
388 {
389 return this->action_counts[MTA_KEEP] + this->action_counts[MTA_LOAD];
390 }
391
392 void Append(CargoPacket *cp, MoveToAction action = MTA_KEEP);
393
394 void AgeCargo();
395
396 void InvalidateCache();
397
398 void SetTransferLoadPlace(TileIndex xy);
399
400 bool Stage(bool accepted, StationID current_station, StationIDStack next_station, uint8 order_flags, const GoodsEntry *ge, CargoPayment *payment);
401
407 inline void KeepAll()
408 {
409 this->action_counts[MTA_DELIVER] = this->action_counts[MTA_TRANSFER] = this->action_counts[MTA_LOAD] = 0;
410 this->action_counts[MTA_KEEP] = this->count;
411 }
412
413 /* Methods for moving cargo around. First parameter is always maximum
414 * amount of cargo to be moved. Second parameter is destination (if
415 * applicable), return value is amount of cargo actually moved. */
416
417 template<MoveToAction Tfrom, MoveToAction Tto>
418 uint Reassign(uint max_move, TileOrStationID update = INVALID_TILE);
419 uint Return(uint max_move, StationCargoList *dest, StationID next_station);
420 uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment);
421 uint Shift(uint max_move, VehicleCargoList *dest);
422 uint Truncate(uint max_move = UINT_MAX);
423 uint Reroute(uint max_move, VehicleCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
424
432 static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
433 {
434 return cp1->source_xy == cp2->source_xy &&
435 cp1->days_in_transit == cp2->days_in_transit &&
436 cp1->source_type == cp2->source_type &&
437 cp1->source_id == cp2->source_id &&
438 cp1->loaded_at_xy == cp2->loaded_at_xy;
439 }
440 };
441
442 typedef MultiMap<StationID, CargoPacket *> StationCargoPacketMap;
443 typedef std::map<StationID, uint> StationCargoAmountMap;
444
448 class StationCargoList : public CargoList<StationCargoList, StationCargoPacketMap> {
449 protected:
451 typedef CargoList<StationCargoList, StationCargoPacketMap> Parent;
452
453 uint reserved_count;
454
455 public:
457 friend class CargoList<StationCargoList, StationCargoPacketMap>;
459 friend const struct SaveLoad *GetGoodsDesc();
460
461 friend class CargoLoad;
462 friend class CargoTransfer;
463 template<class Tsource>
464 friend class CargoRemoval;
465 friend class CargoReservation;
466 friend class CargoReturn;
467 friend class StationCargoReroute;
468
469 static void InvalidateAllFrom(SourceType src_type, SourceID src);
470
471 template<class Taction>
472 bool ShiftCargo(Taction &action, StationID next);
473
474 template<class Taction>
475 uint ShiftCargo(Taction action, StationIDStack next, bool include_invalid);
476
477 void Append(CargoPacket *cp, StationID next);
478
484 inline bool HasCargoFor(StationIDStack next) const
485 {
486 while (!next.IsEmpty()) {
487 if (this->packets.find(next.Pop()) != this->packets.end()) return true;
488 }
489 /* Packets for INVALID_STATION can go anywhere. */
490 return this->packets.find(INVALID_STATION) != this->packets.end();
491 }
492
497 inline StationID Source() const
498 {
499 return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->source;
500 }
501
507 inline uint AvailableCount() const
508 {
509 return this->count;
510 }
511
516 inline uint ReservedCount() const
517 {
518 return this->reserved_count;
519 }
520
526 inline uint TotalCount() const
527 {
528 return this->count + this->reserved_count;
529 }
530
531 /* Methods for moving cargo around. First parameter is always maximum
532 * amount of cargo to be moved. Second parameter is destination (if
533 * applicable), return value is amount of cargo actually moved. */
534
535 uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
536 uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
537 uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr);
538 uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
539
547 static bool AreMergable(const CargoPacket *cp1, const CargoPacket *cp2)
548 {
549 return cp1->source_xy == cp2->source_xy &&
550 cp1->days_in_transit == cp2->days_in_transit &&
551 cp1->source_type == cp2->source_type &&
552 cp1->source_id == cp2->source_id;
553 }
554 };
555
556 #endif /* CARGOPACKET_H */
VehicleCargoList::TotalCount
uint TotalCount() const
Returns sum of cargo, including reserved cargo.
Definition: cargopacket.h:360
CargoPacket::feeder_share
Money feeder_share
Value of feeder pickup to be paid for on delivery of cargo.
Definition: cargopacket.h:44
CargoList::CargoList
CargoList()
Create the cargo list.
Definition: cargopacket.h:236
CargoList::ConstIterator
Tcont::const_iterator ConstIterator
The const iterator for our container.
Definition: cargopacket.h:207
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
VehicleCargoList::StoredCount
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
Definition: cargopacket.h:351
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:212
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:255
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:246
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:453
CargoPacket::source
StationID source
The station where the cargo came from first.
Definition: cargopacket.h:49
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:24
VehicleCargoList::ReservedCount
uint ReservedCount() const
Returns sum of reserved cargo.
Definition: cargopacket.h:369
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:285
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:448
CargoList::~CargoList
~CargoList()
Destroy the cargolist ("frees" all cargo packets).
Definition: cargopacket.cpp:155
CargoPacket::DaysInTransit
byte DaysInTransit() const
Gets the number of days this cargo has been in transit.
Definition: cargopacket.h:131
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:46
CargoPacket::loaded_at_xy
TileOrStationID loaded_at_xy
Location where this cargo has been loaded into the vehicle.
Definition: cargopacket.h:52
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:526
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:268
CargoPacket::Merge
void Merge(CargoPacket *cp)
Merge another packet into this one.
Definition: cargopacket.cpp:104
VehicleCargoList::UnloadCount
uint UnloadCount() const
Returns sum of cargo to be moved out of the vehicle at the current station.
Definition: cargopacket.h:378
StationCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:497
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
GetCargoPacketDesc
const struct SaveLoad * GetCargoPacketDesc()
Wrapper function to get the CargoPacket's internal structure while some of the variables itself are p...
Definition: cargopacket_sl.cpp:86
SourceID
uint16 SourceID
Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
Definition: cargo_type.h:152
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:50
CargoPacket::SourceStation
StationID SourceStation() const
Gets the ID of the station where the cargo was loaded for the first time.
Definition: cargopacket.h:158
StationCargoList::GetGoodsDesc
friend const struct SaveLoad * GetGoodsDesc()
The stations, via GoodsEntry, have a CargoList.
Definition: station_sl.cpp:258
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:273
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:484
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:147
CargoPacket::SourceSubsidyID
SourceID SourceSubsidyID() const
Gets the ID of the cargo's source.
Definition: cargopacket.h:149
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:224
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:223
CargoPacket::MAX_COUNT
static const uint16 MAX_COUNT
Maximum number of items in a single cargo packet.
Definition: cargopacket.h:64
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:140
CargoPacket::source_id
SourceID source_id
Index of source, INVALID_SOURCE if unknown/invalid.
Definition: cargopacket.h:48
CargoPacket::AddFeederShare
void AddFeederShare(Money new_share)
Adds some feeder share to the packet.
Definition: cargopacket.h:93
CargoPacket::Count
uint16 Count() const
Gets the number of 'items' in this packet.
Definition: cargopacket.h:99
CargoList::MTA_TRANSFER
@ MTA_TRANSFER
Transfer the cargo to the station.
Definition: cargopacket.h:214
VehicleCargoList::KeepAll
void KeepAll()
Marks all cargo in the vehicle as to be kept.
Definition: cargopacket.h:407
VehicleCargoList::action_counts
uint action_counts[NUM_MOVE_TO_ACTION]
Counts of cargo to be transferred, delivered, kept and loaded.
Definition: cargopacket.h:274
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the sation.
Definition: cargopacket.h:507
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
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:21
VehicleCargoList::Parent
CargoList< VehicleCargoList, CargoPacketList > Parent
The (direct) parent of this class.
Definition: cargopacket.h:271
CargoPacket::source_type
SourceType source_type
Type of source_id.
Definition: cargopacket.h:47
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:205
CargoPacket::LoadedAtXY
TileIndex LoadedAtXY() const
Gets the coordinates of the cargo's last loading station.
Definition: cargopacket.h:176
StationCargoList::ReservedCount
uint ReservedCount() const
Returns sum of cargo reserved for loading onto vehicles.
Definition: cargopacket.h:516
CargoList::packets
Tcont packets
The cargo packets in this list.
Definition: cargopacket.h:226
CargoList
Simple collection class for a list of cargo packets.
Definition: cargopacket.h:33
CargoPacket::GetCargoPacketDesc
friend const struct SaveLoad * GetCargoPacketDesc()
We want this to be saved, right?
Definition: cargopacket_sl.cpp:86
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:170
vehicle_type.h
CargoPacket::next_station
TileOrStationID next_station
Station where the cargo wants to go next.
Definition: cargopacket.h:53
SourceType
SourceType
Types of cargo source and destination.
Definition: cargo_type.h:146
CargoPacketID
uint32 CargoPacketID
Unique identifier for a single cargo packet.
Definition: cargopacket.h:23
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
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:217
VehicleCargoList::RemainingCount
uint RemainingCount() const
Returns the sum of cargo to be kept in the vehicle at the current station.
Definition: cargopacket.h:387
CargoPacket::count
uint16 count
The amount of cargo in this packet.
Definition: cargopacket.h:45
CargoPacket::SetNextStation
void SetNextStation(StationID next_station)
Sets the station where the packet is supposed to go next.
Definition: cargopacket.h:87
INVALID_SOURCE
static const SourceID INVALID_SOURCE
Invalid/unknown index of source.
Definition: cargo_type.h:153
CargoPacket::SetLoadPlace
void SetLoadPlace(TileIndex load_place)
Sets the tile where the packet was loaded last.
Definition: cargopacket.h:81
VehicleCargoList::Source
StationID Source() const
Returns source of the first cargo packet in this list.
Definition: cargopacket.h:322
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:432
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:547
multimap.hpp
CargoPacket::NextStation
StationID NextStation() const
Gets the ID of station the cargo wants to go next.
Definition: cargopacket.h:185
CargoList::Iterator
Tcont::iterator Iterator
The iterator for our container.
Definition: cargopacket.h:203
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:42
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:216
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
VehicleCargoList::ActionCount
uint ActionCount(MoveToAction action) const
Returns the amount of cargo designated for a given purpose.
Definition: cargopacket.h:341
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
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:215
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.
VehicleCargoList::GetVehicleDescription
friend const struct SaveLoad * GetVehicleDescription(VehicleType vt)
The vehicles have a cargo list (and we want that saved).
Definition: vehicle_sl.cpp:581
StationCargoList::Parent
CargoList< StationCargoList, StationCargoPacketMap > Parent
The (direct) parent of this class.
Definition: cargopacket.h:451
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:109
economy_type.h
SaveLoad
SaveLoad type struct.
Definition: saveload.h:516
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:209
VehicleCargoList::FeederShare
Money FeederShare() const
Returns total sum of the feeder share for all packets.
Definition: cargopacket.h:331
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:226
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:120
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:167
station_type.h
CargoPacket::~CargoPacket
~CargoPacket()
Destroy the packet.
Definition: cargopacket.h:71
CargoList::AddToCache
void AddToCache(const CargoPacket *cp)
Update the cache to reflect adding of this packet.
Definition: cargopacket.cpp:192