OpenTTD Source 20241224-master-gee860a5c8e
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
19template<class Tsource>
21protected:
22 Tsource *source;
23 uint max_move;
24 uint Preprocess(CargoPacket *cp);
25 bool Postprocess(CargoPacket *cp, uint remove);
26public:
28
33 uint MaxMove() { return this->max_move; }
34
35 bool operator()(CargoPacket *cp);
36};
37
49
55template<class Tsource, class Tdest>
57protected:
58 Tsource *source;
59 Tdest *destination;
60 uint max_move;
62public:
64
69 uint MaxMove() { return this->max_move; }
70};
71
81
91
99
101class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
102protected:
104 StationID next;
105public:
108 bool operator()(CargoPacket *cp);
109};
110
118
120template<class Tlist>
121class CargoReroute : public CargoMovement<Tlist, Tlist> {
122protected:
123 StationID avoid;
124 StationID avoid2;
125 const GoodsEntry *ge;
126public:
127 CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
128 CargoMovement<Tlist, Tlist>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
129};
130
132class StationCargoReroute : public CargoReroute<StationCargoList> {
133public:
134 StationCargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
135 CargoReroute<StationCargoList>(source, dest, max_move, avoid, avoid2, ge) {}
136 bool operator()(CargoPacket *cp);
137};
138
140class VehicleCargoReroute : public CargoReroute<VehicleCargoList> {
141public:
142 VehicleCargoReroute(VehicleCargoList *source, VehicleCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
143 CargoReroute<VehicleCargoList>(source, dest, max_move, avoid, avoid2, ge)
144 {
145 assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
146 }
147 bool operator()(CargoPacket *cp);
148};
149
150#endif /* CARGOACTION_H */
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
Base class for cargo packets.
Action of final delivery of cargo.
Definition cargoaction.h:39
CargoPayment * payment
Payment object where payments will be registered.
Definition cargoaction.h:42
TileIndex current_tile
Current tile cargo delivery is happening.
Definition cargoaction.h:41
bool operator()(CargoPacket *cp)
Delivers some cargo.
CargoID cargo
The cargo type of the cargo.
Definition cargoaction.h:43
@ MTA_TRANSFER
Transfer the cargo to the station.
Action of loading cargo from a station onto a vehicle.
Definition cargoaction.h:83
bool operator()(CargoPacket *cp)
Loads some cargo onto a vehicle.
TileIndex current_tile
Current tile cargo loading is happening.
Definition cargoaction.h:85
Abstract action for moving cargo from one list to another.
Definition cargoaction.h:56
uint MaxMove()
Returns how much more cargo can be moved with this action.
Definition cargoaction.h:69
Tsource * source
Source of the cargo.
Definition cargoaction.h:58
CargoPacket * Preprocess(CargoPacket *cp)
Decides if a packet needs to be split.
Tdest * destination
Destination for the cargo.
Definition cargoaction.h:59
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
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
uint MaxMove()
Returns how much more cargo can be removed with this action.
Definition cargoaction.h:33
Action of rerouting cargo between different cargo lists and/or next hops.
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition cargoaction.h:93
bool operator()(CargoPacket *cp)
Reserves some cargo for loading.
Action of returning previously reserved cargo from the vehicle to the station.
TileIndex current_tile
Current tile cargo unloading is happening.
bool operator()(CargoPacket *cp)
Returns some reserved cargo.
Action of shifting cargo from one vehicle to another.
bool operator()(CargoPacket *cp)
Shifts some cargo from a vehicle to another one.
Action of transferring cargo from a vehicle to a station.
Definition cargoaction.h:73
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:75
CargoList that is used for stations.
Action of rerouting cargo in a station.
bool operator()(CargoPacket *cp)
Reroutes some cargo from one Station sublist to another.
CargoList that is used for vehicles.
Action of rerouting cargo staged for transfer in a vehicle.
bool operator()(CargoPacket *cp)
Reroutes some cargo in a VehicleCargoList.
Container for cargo from the same location and time.
Definition cargopacket.h:40
Helper class to perform the cargo payment.
Stores station stats for a single cargo.