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:
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);
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:
102  CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next) :
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 */
Action of rerouting cargo in a station.
Definition: cargoaction.h:128
Action of rerouting cargo between different cargo lists and/or next hops.
Definition: cargoaction.h:117
CargoList that is used for stations.
Definition: cargopacket.h:463
Action of shifting cargo from one vehicle to another.
Definition: cargoaction.h:108
Stores station stats for a single cargo.
Definition: station_base.h:170
Action of rerouting cargo staged for transfer in a vehicle.
Definition: cargoaction.h:136
uint max_move
Maximum amount of cargo to be removed with this action.
Definition: cargoaction.h:25
bool Postprocess(CargoPacket *cp, uint remove)
Finalize cargo removal.
Definition: cargoaction.cpp:63
Tsource * source
Source of the cargo.
Definition: cargoaction.h:24
Base class for cargo packets.
Container for cargo from the same location and time.
Definition: cargopacket.h:44
uint MaxMove()
Returns how much more cargo can be moved with this action.
Definition: cargoaction.h:69
TileIndex load_place
TileIndex to be saved in the packets&#39; loaded_at_xy.
Definition: cargoaction.h:83
Abstract action for moving cargo from one list to another.
Definition: cargoaction.h:56
CargoPayment * payment
Payment object where payments will be registered.
Definition: cargoaction.h:43
Helper class to perform the cargo payment.
Definition: economy_base.h:26
Action of transferring cargo from a vehicle to a station.
Definition: cargoaction.h:73
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition: cargoaction.h:91
CargoList that is used for vehicles.
Definition: cargopacket.h:283
uint MaxMove()
Returns how much more cargo can be removed with this action.
Definition: cargoaction.h:35
uint max_move
Maximum amount of cargo to be moved with this action.
Definition: cargoaction.h:60
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Action of returning previously reserved cargo from the vehicle to the station.
Definition: cargoaction.h:99
Tsource * source
Source of the cargo.
Definition: cargoaction.h:58
Abstract action of removing cargo from a vehicle or a station.
Definition: cargoaction.h:22
uint Preprocess(CargoPacket *cp)
Determines the amount of cargo to be removed from a packet and removes that from the metadata of the ...
Definition: cargoaction.cpp:44
Action of final delivery of cargo.
Definition: cargoaction.h:41
Action of loading cargo from a station onto a vehicle.
Definition: cargoaction.h:81
Tdest * destination
Destination for the cargo.
Definition: cargoaction.h:59