OpenTTD Source: src/cargoaction.h Source File

OpenTTD Source 14.1

cargoaction.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 CARGOACTION_H
11 #define CARGOACTION_H
12
13 #include "cargopacket.h"
14
19 template<class Tsource>
20 class CargoRemoval {
21 protected:
22 Tsource *source;
23 uint max_move;
24 uint Preprocess(CargoPacket *cp);
25 bool Postprocess(CargoPacket *cp, uint remove);
26 public:
27 CargoRemoval(Tsource *source, uint max_move) : source(source), max_move(max_move) {}
28
33 uint MaxMove() { return this->max_move; }
34
35 bool operator()(CargoPacket *cp);
36 };
37
39 class CargoDelivery : public CargoRemoval<VehicleCargoList> {
40 protected:
41 TileIndex current_tile;
42 CargoPayment *payment;
43 public:
44 CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment, TileIndex current_tile) :
45 CargoRemoval<VehicleCargoList>(source, max_move), current_tile(current_tile), payment(payment) {}
46 bool operator()(CargoPacket *cp);
47 };
48
54 template<class Tsource, class Tdest>
55 class CargoMovement {
56 protected:
57 Tsource *source;
58 Tdest *destination;
59 uint max_move;
60 CargoPacket *Preprocess(CargoPacket *cp);
61 public:
62 CargoMovement(Tsource *source, Tdest *destination, uint max_move) : source(source), destination(destination), max_move(max_move) {}
63
68 uint MaxMove() { return this->max_move; }
69 };
70
72 class CargoTransfer : public CargoMovement<VehicleCargoList, StationCargoList> {
73 protected:
74 TileIndex current_tile;
75 public:
76 CargoTransfer(VehicleCargoList *source, StationCargoList *destination, uint max_move, TileIndex current_tile) :
77 CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), current_tile(current_tile) {}
78 bool operator()(CargoPacket *cp);
79 };
80
82 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
83 protected:
84 TileIndex current_tile;
85 public:
86 CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex current_tile) :
87 CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), current_tile(current_tile) {}
88 bool operator()(CargoPacket *cp);
89 };
90
92 class CargoReservation : public CargoLoad {
93 public:
94 CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex current_tile) :
95 CargoLoad(source, destination, max_move, current_tile) {}
96 bool operator()(CargoPacket *cp);
97 };
98
100 class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
101 protected:
102 TileIndex current_tile;
103 StationID next;
104 public:
105 CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next, TileIndex current_tile) :
106 CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), current_tile(current_tile), next(next) {}
107 bool operator()(CargoPacket *cp);
108 };
109
111 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
112 public:
113 CargoShift(VehicleCargoList *source, VehicleCargoList *destination, uint max_move) :
114 CargoMovement<VehicleCargoList, VehicleCargoList>(source, destination, max_move) {}
115 bool operator()(CargoPacket *cp);
116 };
117
119 template<class Tlist>
120 class CargoReroute : public CargoMovement<Tlist, Tlist> {
121 protected:
122 StationID avoid;
123 StationID avoid2;
124 const GoodsEntry *ge;
125 public:
126 CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
127 CargoMovement<Tlist, Tlist>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
128 };
129
131 class StationCargoReroute : public CargoReroute<StationCargoList> {
132 public:
133 StationCargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
134 CargoReroute<StationCargoList>(source, dest, max_move, avoid, avoid2, ge) {}
135 bool operator()(CargoPacket *cp);
136 };
137
139 class VehicleCargoReroute : public CargoReroute<VehicleCargoList> {
140 public:
141 VehicleCargoReroute(VehicleCargoList *source, VehicleCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
142 CargoReroute<VehicleCargoList>(source, dest, max_move, avoid, avoid2, ge)
143 {
144 assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
145 }
146 bool operator()(CargoPacket *cp);
147 };
148
149 #endif /* CARGOACTION_H */
CargoReroute
Action of rerouting cargo between different cargo lists and/or next hops.
Definition: cargoaction.h:120
CargoReservation
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition: cargoaction.h:92
CargoShift::operator()
bool operator()(CargoPacket *cp)
Shifts some cargo from a vehicle to another one.
Definition: cargoaction.cpp:183
CargoReservation::operator()
bool operator()(CargoPacket *cp)
Reserves some cargo for loading.
Definition: cargoaction.cpp:134
CargoDelivery::current_tile
TileIndex current_tile
Current tile cargo delivery is happening.
Definition: cargoaction.h:41
CargoDelivery::operator()
bool operator()(CargoPacket *cp)
Delivers some cargo.
Definition: cargoaction.cpp:106
CargoMovement::destination
Tdest * destination
Destination for the cargo.
Definition: cargoaction.h:58
CargoMovement::Preprocess
CargoPacket * Preprocess(CargoPacket *cp)
Decides if a packet needs to be split.
Definition: cargoaction.cpp:24
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:529
CargoReturn
Action of returning previously reserved cargo from the vehicle to the station.
Definition: cargoaction.h:100
CargoRemoval::Preprocess
uint Preprocess(CargoPacket *cp)
Determines the amount of cargo to be removed from a packet and removes that from the metadata of the ...
Definition: cargoaction.cpp:42
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
CargoLoad::current_tile
TileIndex current_tile
Current tile cargo loading is happening.
Definition: cargoaction.h:84
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:351
VehicleCargoReroute::operator()
bool operator()(CargoPacket *cp)
Reroutes some cargo in a VehicleCargoList.
Definition: cargoaction.cpp:220
VehicleCargoReroute
Action of rerouting cargo staged for transfer in a vehicle.
Definition: cargoaction.h:139
CargoMovement::max_move
uint max_move
Maximum amount of cargo to be moved with this action.
Definition: cargoaction.h:59
CargoPayment
Helper class to perform the cargo payment.
Definition: economy_base.h:24
CargoDelivery
Action of final delivery of cargo.
Definition: cargoaction.h:39
CargoRemoval::MaxMove
uint MaxMove()
Returns how much more cargo can be removed with this action.
Definition: cargoaction.h:33
cargopacket.h
CargoLoad::operator()
bool operator()(CargoPacket *cp)
Loads some cargo onto a vehicle.
Definition: cargoaction.cpp:119
CargoList< VehicleCargoList, CargoPacketList >::MTA_TRANSFER
@ MTA_TRANSFER
Transfer the cargo to the station.
Definition: cargopacket.h:297
CargoMovement::MaxMove
uint MaxMove()
Returns how much more cargo can be moved with this action.
Definition: cargoaction.h:68
CargoShift
Action of shifting cargo from one vehicle to another.
Definition: cargoaction.h:111
CargoMovement
Abstract action for moving cargo from one list to another.
Definition: cargoaction.h:55
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:166
CargoTransfer
Action of transferring cargo from a vehicle to a station.
Definition: cargoaction.h:72
CargoTransfer::current_tile
TileIndex current_tile
Current tile cargo unloading is happening.
Definition: cargoaction.h:74
CargoRemoval
Abstract action of removing cargo from a vehicle or a station.
Definition: cargoaction.h:20
CargoRemoval::max_move
uint max_move
Maximum amount of cargo to be removed with this action.
Definition: cargoaction.h:23
CargoRemoval::source
Tsource * source
Source of the cargo.
Definition: cargoaction.h:22
CargoReturn::operator()
bool operator()(CargoPacket *cp)
Returns some reserved cargo.
Definition: cargoaction.cpp:150
CargoTransfer::operator()
bool operator()(CargoPacket *cp)
Transfers some cargo from a vehicle to a station.
Definition: cargoaction.cpp:167
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:40
CargoReturn::current_tile
TileIndex current_tile
Current tile cargo unloading is happening.
Definition: cargoaction.h:102
CargoRemoval::Postprocess
bool Postprocess(CargoPacket *cp, uint remove)
Finalize cargo removal.
Definition: cargoaction.cpp:61
CargoMovement::source
Tsource * source
Source of the cargo.
Definition: cargoaction.h:57
CargoDelivery::payment
CargoPayment * payment
Payment object where payments will be registered.
Definition: cargoaction.h:42
StationCargoReroute
Action of rerouting cargo in a station.
Definition: cargoaction.h:131
StationCargoReroute::operator()
bool operator()(CargoPacket *cp)
Reroutes some cargo from one Station sublist to another.
Definition: cargoaction.cpp:197
CargoLoad
Action of loading cargo from a station onto a vehicle.
Definition: cargoaction.h:82