Update: Translations from eints
[openttd-github.git] / src / cargoaction.h
blobc0c58b12cd8985a7e70ddffd00a56cad0e1f4295
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 */
8 /** @file cargoaction.h Actions to be applied to cargo packets. */
10 #ifndef CARGOACTION_H
11 #define CARGOACTION_H
13 #include "cargopacket.h"
15 /**
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>
20 class CargoRemoval {
21 protected:
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);
26 public:
27 CargoRemoval(Tsource *source, uint max_move) : source(source), max_move(max_move) {}
29 /**
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> {
40 protected:
41 TileIndex current_tile; ///< Current tile cargo delivery is happening.
42 CargoPayment *payment; ///< Payment object where payments will be registered.
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);
49 /**
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>
55 class CargoMovement {
56 protected:
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);
61 public:
62 CargoMovement(Tsource *source, Tdest *destination, uint max_move) : source(source), destination(destination), max_move(max_move) {}
64 /**
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> {
73 protected:
74 TileIndex current_tile; ///< Current tile cargo unloading is happening.
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);
81 /** Action of loading cargo from a station onto a vehicle. */
82 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
83 protected:
84 TileIndex current_tile; ///< Current tile cargo loading is happening.
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);
91 /** Action of reserving cargo from a station to be loaded onto a vehicle. */
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);
99 /** Action of returning previously reserved cargo from the vehicle to the station. */
100 class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
101 protected:
102 TileIndex current_tile; ///< Current tile cargo unloading is happening.
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);
110 /** Action of shifting cargo from one vehicle to another. */
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);
118 /** Action of rerouting cargo between different cargo lists and/or next hops. */
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) {}
130 /** Action of rerouting cargo in a station. */
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);
138 /** Action of rerouting cargo staged for transfer in a vehicle. */
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)
144 assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
146 bool operator()(CargoPacket *cp);
149 #endif /* CARGOACTION_H */