OpenTTD Source 20260421-master-gc2fbc6fdeb
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef CARGOACTION_H
11#define CARGOACTION_H
12
13#include "cargopacket.h"
14
19template <class Tsource>
21protected:
22 Tsource *source;
23 uint max_move;
24 uint Preprocess(CargoPacket *cp);
25 bool Postprocess(CargoPacket *cp, uint remove);
26public:
33
38 uint MaxMove() { return this->max_move; }
39
40 bool operator()(CargoPacket *cp);
41};
42
62
68template <class Tsource, class Tdest>
70protected:
71 Tsource *source;
72 Tdest *destination;
73 uint max_move;
75public:
83
88 uint MaxMove() { return this->max_move; }
89};
90
92class CargoTransfer : public CargoMovement<VehicleCargoList, StationCargoList> {
93protected:
95public:
98 bool operator()(CargoPacket *cp);
99};
100
102class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
103protected:
105public:
108 bool operator()(CargoPacket *cp);
109};
110
112class CargoReservation : public CargoLoad {
113public:
115 CargoLoad(source, destination, max_move, current_tile) {}
116 bool operator()(CargoPacket *cp);
117};
118
120class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
121protected:
123 StationID next;
124public:
125 CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next, TileIndex current_tile) :
127 bool operator()(CargoPacket *cp);
128};
129
131class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
132public:
135 bool operator()(CargoPacket *cp);
136};
137
139template <class Tlist>
140class CargoReroute : public CargoMovement<Tlist, Tlist> {
141protected:
142 StationID avoid;
143 StationID avoid2;
144 const GoodsEntry *ge;
145public:
155 CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
156 CargoMovement<Tlist, Tlist>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
157};
158
160class StationCargoReroute : public CargoReroute<StationCargoList> {
161public:
162 StationCargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
164 bool operator()(CargoPacket *cp);
165};
166
168class VehicleCargoReroute : public CargoReroute<VehicleCargoList> {
169public:
170 VehicleCargoReroute(VehicleCargoList *source, VehicleCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
172 {
174 }
175 bool operator()(CargoPacket *cp);
176};
177
178#endif /* CARGOACTION_H */
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
Base class for cargo packets.
CargoPayment * payment
Payment object where payments will be registered.
Definition cargoaction.h:47
CargoType cargo
The cargo type of the cargo.
Definition cargoaction.h:48
TileIndex current_tile
Current tile cargo delivery is happening.
Definition cargoaction.h:46
bool operator()(CargoPacket *cp)
Delivers some cargo.
CargoDelivery(VehicleCargoList *source, uint max_move, CargoType cargo, CargoPayment *payment, TileIndex current_tile)
Create the delivery.
Definition cargoaction.h:58
bool operator()(CargoPacket *cp)
Loads some cargo onto a vehicle.
TileIndex current_tile
Current tile cargo loading is happening.
uint MaxMove()
Returns how much more cargo can be moved with this action.
Definition cargoaction.h:88
Tsource * source
Source of the cargo.
Definition cargoaction.h:71
CargoPacket * Preprocess(CargoPacket *cp)
Decides if a packet needs to be split.
CargoMovement(Tsource *source, Tdest *destination, uint max_move)
Create the movement.
Definition cargoaction.h:82
Tdest * destination
Destination for the cargo.
Definition cargoaction.h:72
uint max_move
Maximum amount of cargo to be moved with this action.
Definition cargoaction.h:73
uint Preprocess(CargoPacket *cp)
Determines the amount of cargo to be removed from a packet and removes that from the metadata of the ...
bool Postprocess(CargoPacket *cp, uint remove)
Finalize cargo removal.
Tsource * source
Source of the cargo.
Definition cargoaction.h:22
uint max_move
Maximum amount of cargo to be removed with this action.
Definition cargoaction.h:23
CargoRemoval(Tsource *source, uint max_move)
Create the removal.
Definition cargoaction.h:32
uint MaxMove()
Returns how much more cargo can be removed with this action.
Definition cargoaction.h:38
CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge)
Create the movement.
const GoodsEntry * ge
Goods that are to be rerouted.
StationID avoid2
Second station to avoid during rerouting, could be StationID::Invalid().
StationID avoid
First station to avoid during rerouting.
bool operator()(CargoPacket *cp)
Reserves some cargo for loading.
TileIndex current_tile
Current tile cargo unloading is happening.
bool operator()(CargoPacket *cp)
Returns some reserved cargo.
bool operator()(CargoPacket *cp)
Shifts some cargo from a vehicle to another one.
bool operator()(CargoPacket *cp)
Transfers some cargo from a vehicle to a station.
TileIndex current_tile
Current tile cargo unloading is happening.
Definition cargoaction.h:94
CargoList that is used for stations.
bool operator()(CargoPacket *cp)
Reroutes some cargo from one Station sublist to another.
CargoList that is used for vehicles.
bool operator()(CargoPacket *cp)
Reroutes some cargo in a VehicleCargoList.
Container for cargo from the same location and time.
Definition cargopacket.h:41
Helper class to perform the cargo payment.
Stores station stats for a single cargo.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92