OpenTTD
cargoaction.h
Go to the documentation of this file.
1 /* $Id: cargoaction.h 26108 2013-11-25 14:30:22Z rubidium $ */
2 
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  */
9 
12 #ifndef CARGOACTION_H
13 #define CARGOACTION_H
14 
15 #include "cargopacket.h"
16 
21 template<class Tsource>
22 class CargoRemoval {
23 protected:
24  Tsource *source;
25  uint max_move;
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) {}
30 
35  uint MaxMove() { return this->max_move; }
36 
37  bool operator()(CargoPacket *cp);
38 };
39 
41 class CargoDelivery : public CargoRemoval<VehicleCargoList> {
42 protected:
44 public:
46  CargoRemoval<VehicleCargoList>(source, max_move), payment(payment) {}
47  bool operator()(CargoPacket *cp);
48 };
49 
55 template<class Tsource, class Tdest>
57 protected:
58  Tsource *source;
59  Tdest *destination;
60  uint max_move;
62 public:
63  CargoMovement(Tsource *source, Tdest *destination, uint max_move) : source(source), destination(destination), max_move(max_move) {}
64 
69  uint MaxMove() { return this->max_move; }
70 };
71 
73 class CargoTransfer : public CargoMovement<VehicleCargoList, StationCargoList> {
74 public:
77  bool operator()(CargoPacket *cp);
78 };
79 
81 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
82 protected:
84 public:
86  CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), load_place(load_place) {}
87  bool operator()(CargoPacket *cp);
88 };
89 
91 class CargoReservation : public CargoLoad {
92 public:
94  CargoLoad(source, destination, max_move, load_place) {}
95  bool operator()(CargoPacket *cp);
96 };
97 
99 class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
100  StationID next;
101 public:
104  bool operator()(CargoPacket *cp);
105 };
106 
108 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
109 public:
112  bool operator()(CargoPacket *cp);
113 };
114 
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) {}
125 };
126 
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);
133 };
134 
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)
140  {
141  assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
142  }
143  bool operator()(CargoPacket *cp);
144 };
145 
146 #endif /* CARGOACTION_H */