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/>.
8 /** @file cargoaction.h Actions to be applied to cargo packets. */
13 #include "cargopacket.h"
16 * Abstract action of removing cargo from a vehicle or a station.
17 * @tparam Tsource CargoList subclass to remove cargo from.
19 template<class Tsource
>
22 Tsource
*source
; ///< Source of the cargo.
23 uint max_move
; ///< Maximum amount of cargo to be removed with this action.
24 uint
Preprocess(CargoPacket
*cp
);
25 bool Postprocess(CargoPacket
*cp
, uint remove
);
27 CargoRemoval(Tsource
*source
, uint max_move
) : source(source
), max_move(max_move
) {}
30 * Returns how much more cargo can be removed with this action.
31 * @return Amount of cargo this action can still remove.
33 uint
MaxMove() { return this->max_move
; }
35 bool operator()(CargoPacket
*cp
);
38 /** Action of final delivery of cargo. */
39 class CargoDelivery
: public CargoRemoval
<VehicleCargoList
> {
41 TileIndex current_tile
; ///< Current tile cargo delivery is happening.
42 CargoPayment
*payment
; ///< Payment object where payments will be registered.
43 CargoID cargo
; ///< The cargo type of the cargo.
45 CargoDelivery(VehicleCargoList
*source
, uint max_move
, CargoID cargo
, CargoPayment
*payment
, TileIndex current_tile
) :
46 CargoRemoval
<VehicleCargoList
>(source
, max_move
), current_tile(current_tile
), payment(payment
), cargo(cargo
) {}
47 bool operator()(CargoPacket
*cp
);
51 * Abstract action for moving cargo from one list to another.
52 * @tparam Tsource CargoList subclass to remove cargo from.
53 * @tparam Tdest CargoList subclass to add cargo to.
55 template<class Tsource
, class Tdest
>
58 Tsource
*source
; ///< Source of the cargo.
59 Tdest
*destination
; ///< Destination for the cargo.
60 uint max_move
; ///< Maximum amount of cargo to be moved with this action.
61 CargoPacket
*Preprocess(CargoPacket
*cp
);
63 CargoMovement(Tsource
*source
, Tdest
*destination
, uint max_move
) : source(source
), destination(destination
), max_move(max_move
) {}
66 * Returns how much more cargo can be moved with this action.
67 * @return Amount of cargo this action can still move.
69 uint
MaxMove() { return this->max_move
; }
72 /** Action of transferring cargo from a vehicle to a station. */
73 class CargoTransfer
: public CargoMovement
<VehicleCargoList
, StationCargoList
> {
75 TileIndex current_tile
; ///< Current tile cargo unloading is happening.
77 CargoTransfer(VehicleCargoList
*source
, StationCargoList
*destination
, uint max_move
, TileIndex current_tile
) :
78 CargoMovement
<VehicleCargoList
, StationCargoList
>(source
, destination
, max_move
), current_tile(current_tile
) {}
79 bool operator()(CargoPacket
*cp
);
82 /** Action of loading cargo from a station onto a vehicle. */
83 class CargoLoad
: public CargoMovement
<StationCargoList
, VehicleCargoList
> {
85 TileIndex current_tile
; ///< Current tile cargo loading is happening.
87 CargoLoad(StationCargoList
*source
, VehicleCargoList
*destination
, uint max_move
, TileIndex current_tile
) :
88 CargoMovement
<StationCargoList
, VehicleCargoList
>(source
, destination
, max_move
), current_tile(current_tile
) {}
89 bool operator()(CargoPacket
*cp
);
92 /** Action of reserving cargo from a station to be loaded onto a vehicle. */
93 class CargoReservation
: public CargoLoad
{
95 CargoReservation(StationCargoList
*source
, VehicleCargoList
*destination
, uint max_move
, TileIndex current_tile
) :
96 CargoLoad(source
, destination
, max_move
, current_tile
) {}
97 bool operator()(CargoPacket
*cp
);
100 /** Action of returning previously reserved cargo from the vehicle to the station. */
101 class CargoReturn
: public CargoMovement
<VehicleCargoList
, StationCargoList
> {
103 TileIndex current_tile
; ///< Current tile cargo unloading is happening.
106 CargoReturn(VehicleCargoList
*source
, StationCargoList
*destination
, uint max_move
, StationID next
, TileIndex current_tile
) :
107 CargoMovement
<VehicleCargoList
, StationCargoList
>(source
, destination
, max_move
), current_tile(current_tile
), next(next
) {}
108 bool operator()(CargoPacket
*cp
);
111 /** Action of shifting cargo from one vehicle to another. */
112 class CargoShift
: public CargoMovement
<VehicleCargoList
, VehicleCargoList
> {
114 CargoShift(VehicleCargoList
*source
, VehicleCargoList
*destination
, uint max_move
) :
115 CargoMovement
<VehicleCargoList
, VehicleCargoList
>(source
, destination
, max_move
) {}
116 bool operator()(CargoPacket
*cp
);
119 /** Action of rerouting cargo between different cargo lists and/or next hops. */
120 template<class Tlist
>
121 class CargoReroute
: public CargoMovement
<Tlist
, Tlist
> {
125 const GoodsEntry
*ge
;
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
) {}
131 /** Action of rerouting cargo in a station. */
132 class StationCargoReroute
: public CargoReroute
<StationCargoList
> {
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
);
139 /** Action of rerouting cargo staged for transfer in a vehicle. */
140 class VehicleCargoReroute
: public CargoReroute
<VehicleCargoList
> {
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
)
145 assert(this->max_move
<= source
->ActionCount(VehicleCargoList::MTA_TRANSFER
));
147 bool operator()(CargoPacket
*cp
);
150 #endif /* CARGOACTION_H */