(svn r27953) -Cleanup: Adjust other languages for r27952
[openttd.git] / src / cargoaction.h
blob0311efcae17751a65e513efe5f91577825541e85
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 */
10 /** @file cargoaction.h Actions to be applied to cargo packets. */
12 #ifndef CARGOACTION_H
13 #define CARGOACTION_H
15 #include "cargopacket.h"
17 /**
18 * Abstract action of removing cargo from a vehicle or a station.
19 * @tparam Tsource CargoList subclass to remove cargo from.
21 template<class Tsource>
22 class CargoRemoval {
23 protected:
24 Tsource *source; ///< Source of the cargo.
25 uint max_move; ///< Maximum amount of cargo to be removed with this action.
26 uint Preprocess(CargoPacket *cp);
27 bool Postprocess(CargoPacket *cp, uint remove);
28 public:
29 CargoRemoval(Tsource *source, uint max_move) : source(source), max_move(max_move) {}
31 /**
32 * Returns how much more cargo can be removed with this action.
33 * @return Amount of cargo this action can still remove.
35 uint MaxMove() { return this->max_move; }
37 bool operator()(CargoPacket *cp);
40 /** Action of final delivery of cargo. */
41 class CargoDelivery : public CargoRemoval<VehicleCargoList> {
42 protected:
43 CargoPayment *payment; ///< Payment object where payments will be registered.
44 public:
45 CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment) :
46 CargoRemoval<VehicleCargoList>(source, max_move), payment(payment) {}
47 bool operator()(CargoPacket *cp);
50 /**
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>
56 class CargoMovement {
57 protected:
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);
62 public:
63 CargoMovement(Tsource *source, Tdest *destination, uint max_move) : source(source), destination(destination), max_move(max_move) {}
65 /**
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> {
74 public:
75 CargoTransfer(VehicleCargoList *source, StationCargoList *destination, uint max_move) :
76 CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move) {}
77 bool operator()(CargoPacket *cp);
80 /** Action of loading cargo from a station onto a vehicle. */
81 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
82 protected:
83 TileIndex load_place; ///< TileIndex to be saved in the packets' loaded_at_xy.
84 public:
85 CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
86 CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), load_place(load_place) {}
87 bool operator()(CargoPacket *cp);
90 /** Action of reserving cargo from a station to be loaded onto a vehicle. */
91 class CargoReservation : public CargoLoad {
92 public:
93 CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
94 CargoLoad(source, destination, max_move, load_place) {}
95 bool operator()(CargoPacket *cp);
98 /** Action of returning previously reserved cargo from the vehicle to the station. */
99 class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
100 StationID next;
101 public:
102 CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next) :
103 CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), next(next) {}
104 bool operator()(CargoPacket *cp);
107 /** Action of shifting cargo from one vehicle to another. */
108 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
109 public:
110 CargoShift(VehicleCargoList *source, VehicleCargoList *destination, uint max_move) :
111 CargoMovement<VehicleCargoList, VehicleCargoList>(source, destination, max_move) {}
112 bool operator()(CargoPacket *cp);
115 /** Action of rerouting cargo between different cargo lists and/or next hops. */
116 template<class Tlist>
117 class CargoReroute : public CargoMovement<Tlist, Tlist> {
118 protected:
119 StationID avoid;
120 StationID avoid2;
121 const GoodsEntry *ge;
122 public:
123 CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
124 CargoMovement<Tlist, Tlist>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
127 /** Action of rerouting cargo in a station. */
128 class StationCargoReroute : public CargoReroute<StationCargoList> {
129 public:
130 StationCargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
131 CargoReroute<StationCargoList>(source, dest, max_move, avoid, avoid2, ge) {}
132 bool operator()(CargoPacket *cp);
135 /** Action of rerouting cargo staged for transfer in a vehicle. */
136 class VehicleCargoReroute : public CargoReroute<VehicleCargoList> {
137 public:
138 VehicleCargoReroute(VehicleCargoList *source, VehicleCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
139 CargoReroute<VehicleCargoList>(source, dest, max_move, avoid, avoid2, ge)
141 assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
143 bool operator()(CargoPacket *cp);
146 #endif /* CARGOACTION_H */