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.
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
);
50 * Abstract action for moving cargo from one list to another.
51 * @tparam Tsource CargoList subclass to remove cargo from.
52 * @tparam Tdest CargoList subclass to add cargo to.
54 template<class Tsource
, class Tdest
>
57 Tsource
*source
; ///< Source of the cargo.
58 Tdest
*destination
; ///< Destination for the cargo.
59 uint max_move
; ///< Maximum amount of cargo to be moved with this action.
60 CargoPacket
*Preprocess(CargoPacket
*cp
);
62 CargoMovement(Tsource
*source
, Tdest
*destination
, uint max_move
) : source(source
), destination(destination
), max_move(max_move
) {}
65 * Returns how much more cargo can be moved with this action.
66 * @return Amount of cargo this action can still move.
68 uint
MaxMove() { return this->max_move
; }
71 /** Action of transferring cargo from a vehicle to a station. */
72 class CargoTransfer
: public CargoMovement
<VehicleCargoList
, StationCargoList
> {
74 TileIndex current_tile
; ///< Current tile cargo unloading is happening.
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
);
81 /** Action of loading cargo from a station onto a vehicle. */
82 class CargoLoad
: public CargoMovement
<StationCargoList
, VehicleCargoList
> {
84 TileIndex current_tile
; ///< Current tile cargo loading is happening.
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
);
91 /** Action of reserving cargo from a station to be loaded onto a vehicle. */
92 class CargoReservation
: public CargoLoad
{
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
);
99 /** Action of returning previously reserved cargo from the vehicle to the station. */
100 class CargoReturn
: public CargoMovement
<VehicleCargoList
, StationCargoList
> {
102 TileIndex current_tile
; ///< Current tile cargo unloading is happening.
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
);
110 /** Action of shifting cargo from one vehicle to another. */
111 class CargoShift
: public CargoMovement
<VehicleCargoList
, VehicleCargoList
> {
113 CargoShift(VehicleCargoList
*source
, VehicleCargoList
*destination
, uint max_move
) :
114 CargoMovement
<VehicleCargoList
, VehicleCargoList
>(source
, destination
, max_move
) {}
115 bool operator()(CargoPacket
*cp
);
118 /** Action of rerouting cargo between different cargo lists and/or next hops. */
119 template<class Tlist
>
120 class CargoReroute
: public CargoMovement
<Tlist
, Tlist
> {
124 const GoodsEntry
*ge
;
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
) {}
130 /** Action of rerouting cargo in a station. */
131 class StationCargoReroute
: public CargoReroute
<StationCargoList
> {
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
);
138 /** Action of rerouting cargo staged for transfer in a vehicle. */
139 class VehicleCargoReroute
: public CargoReroute
<VehicleCargoList
> {
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
)
144 assert(this->max_move
<= source
->ActionCount(VehicleCargoList::MTA_TRANSFER
));
146 bool operator()(CargoPacket
*cp
);
149 #endif /* CARGOACTION_H */