OpenTTD Source  1.11.2
cargoaction.h
Go to the documentation of this file.
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  */
7 
10 #ifndef CARGOACTION_H
11 #define CARGOACTION_H
12 
13 #include "cargopacket.h"
14 
19 template<class Tsource>
20 class CargoRemoval {
21 protected:
22  Tsource *source;
23  uint max_move;
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) {}
28 
33  uint MaxMove() { return this->max_move; }
34 
35  bool operator()(CargoPacket *cp);
36 };
37 
39 class CargoDelivery : public CargoRemoval<VehicleCargoList> {
40 protected:
42 public:
45  bool operator()(CargoPacket *cp);
46 };
47 
53 template<class Tsource, class Tdest>
55 protected:
56  Tsource *source;
57  Tdest *destination;
58  uint max_move;
60 public:
62 
67  uint MaxMove() { return this->max_move; }
68 };
69 
71 class CargoTransfer : public CargoMovement<VehicleCargoList, StationCargoList> {
72 public:
75  bool operator()(CargoPacket *cp);
76 };
77 
79 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
80 protected:
82 public:
85  bool operator()(CargoPacket *cp);
86 };
87 
89 class CargoReservation : public CargoLoad {
90 public:
93  bool operator()(CargoPacket *cp);
94 };
95 
97 class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
98  StationID next;
99 public:
102  bool operator()(CargoPacket *cp);
103 };
104 
106 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
107 public:
110  bool operator()(CargoPacket *cp);
111 };
112 
114 template<class Tlist>
115 class CargoReroute : public CargoMovement<Tlist, Tlist> {
116 protected:
117  StationID avoid;
118  StationID avoid2;
119  const GoodsEntry *ge;
120 public:
121  CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
122  CargoMovement<Tlist, Tlist>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
123 };
124 
126 class StationCargoReroute : public CargoReroute<StationCargoList> {
127 public:
128  StationCargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
129  CargoReroute<StationCargoList>(source, dest, max_move, avoid, avoid2, ge) {}
130  bool operator()(CargoPacket *cp);
131 };
132 
134 class VehicleCargoReroute : public CargoReroute<VehicleCargoList> {
135 public:
136  VehicleCargoReroute(VehicleCargoList *source, VehicleCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
137  CargoReroute<VehicleCargoList>(source, dest, max_move, avoid, avoid2, ge)
138  {
139  assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
140  }
141  bool operator()(CargoPacket *cp);
142 };
143 
144 #endif /* CARGOACTION_H */
CargoReroute
Action of rerouting cargo between different cargo lists and/or next hops.
Definition: cargoaction.h:115
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
CargoReservation
Action of reserving cargo from a station to be loaded onto a vehicle.
Definition: cargoaction.h:89
CargoShift::operator()
bool operator()(CargoPacket *cp)
Shifts some cargo from a vehicle to another one.
Definition: cargoaction.cpp:181
CargoReservation::operator()
bool operator()(CargoPacket *cp)
Reserves some cargo for loading.
Definition: cargoaction.cpp:134
CargoDelivery::operator()
bool operator()(CargoPacket *cp)
Delivers some cargo.
Definition: cargoaction.cpp:106
CargoMovement::destination
Tdest * destination
Destination for the cargo.
Definition: cargoaction.h:57
CargoMovement::Preprocess
CargoPacket * Preprocess(CargoPacket *cp)
Decides if a packet needs to be split.
Definition: cargoaction.cpp:24
StationCargoList
CargoList that is used for stations.
Definition: cargopacket.h:448
CargoReturn
Action of returning previously reserved cargo from the vehicle to the station.
Definition: cargoaction.h:97
CargoRemoval::Preprocess
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:42
VehicleCargoList
CargoList that is used for vehicles.
Definition: cargopacket.h:268
VehicleCargoReroute::operator()
bool operator()(CargoPacket *cp)
Reroutes some cargo in a VehicleCargoList.
Definition: cargoaction.cpp:218
VehicleCargoReroute
Action of rerouting cargo staged for transfer in a vehicle.
Definition: cargoaction.h:134
CargoMovement::max_move
uint max_move
Maximum amount of cargo to be moved with this action.
Definition: cargoaction.h:58
CargoPayment
Helper class to perform the cargo payment.
Definition: economy_base.h:24
CargoDelivery
Action of final delivery of cargo.
Definition: cargoaction.h:39
CargoRemoval::MaxMove
uint MaxMove()
Returns how much more cargo can be removed with this action.
Definition: cargoaction.h:33
cargopacket.h
CargoLoad::operator()
bool operator()(CargoPacket *cp)
Loads some cargo onto a vehicle.
Definition: cargoaction.cpp:119
CargoList< VehicleCargoList, CargoPacketList >::MTA_TRANSFER
@ MTA_TRANSFER
Transfer the cargo to the station.
Definition: cargopacket.h:214
CargoMovement::MaxMove
uint MaxMove()
Returns how much more cargo can be moved with this action.
Definition: cargoaction.h:67
CargoShift
Action of shifting cargo from one vehicle to another.
Definition: cargoaction.h:106
CargoMovement
Abstract action for moving cargo from one list to another.
Definition: cargoaction.h:54
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:170
CargoTransfer
Action of transferring cargo from a vehicle to a station.
Definition: cargoaction.h:71
CargoRemoval
Abstract action of removing cargo from a vehicle or a station.
Definition: cargoaction.h:20
CargoRemoval::max_move
uint max_move
Maximum amount of cargo to be removed with this action.
Definition: cargoaction.h:23
CargoRemoval::source
Tsource * source
Source of the cargo.
Definition: cargoaction.h:22
CargoReturn::operator()
bool operator()(CargoPacket *cp)
Returns some reserved cargo.
Definition: cargoaction.cpp:150
CargoLoad::load_place
TileIndex load_place
TileIndex to be saved in the packets' loaded_at_xy.
Definition: cargoaction.h:81
CargoTransfer::operator()
bool operator()(CargoPacket *cp)
Transfers some cargo from a vehicle to a station.
Definition: cargoaction.cpp:166
CargoPacket
Container for cargo from the same location and time.
Definition: cargopacket.h:42
CargoRemoval::Postprocess
bool Postprocess(CargoPacket *cp, uint remove)
Finalize cargo removal.
Definition: cargoaction.cpp:61
CargoMovement::source
Tsource * source
Source of the cargo.
Definition: cargoaction.h:56
CargoDelivery::payment
CargoPayment * payment
Payment object where payments will be registered.
Definition: cargoaction.h:41
StationCargoReroute
Action of rerouting cargo in a station.
Definition: cargoaction.h:126
StationCargoReroute::operator()
bool operator()(CargoPacket *cp)
Reroutes some cargo from one Station sublist to another.
Definition: cargoaction.cpp:195
CargoLoad
Action of loading cargo from a station onto a vehicle.
Definition: cargoaction.h:79