# cargoaction.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef CARGOACTION_H
    00013 #define CARGOACTION_H
    00014
    00015 #include "cargopacket.h"
    00016
    00022 template<class Tsource>
    00023 class CargoRemoval {
    00024 protected:
    00025   Tsource *source;
    00026   uint max_move;
    00027   uint Preprocess(CargoPacket *cp);
    00028   bool Postprocess(CargoPacket *cp, uint remove);
    00029 public:
    00030   CargoRemoval(Tsource *source, uint max_move) : source(source), max_move(max_move) {}
    00031
    00036   uint MaxMove() { return this->max_move; }
    00037
    00038   bool operator()(CargoPacket *cp);
    00039 };
    00040
    00042 class CargoDelivery : public CargoRemoval<VehicleCargoList> {
    00043 protected:
    00044   CargoPayment *payment;
    00045 public:
    00046   CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment) :
    00047       CargoRemoval<VehicleCargoList>(source, max_move), payment(payment) {}
    00048   bool operator()(CargoPacket *cp);
    00049 };
    00050
    00056 template<class Tsource, class Tdest>
    00057 class CargoMovement {
    00058 protected:
    00059   Tsource *source;
    00060   Tdest *destination;
    00061   uint max_move;
    00062   CargoPacket *Preprocess(CargoPacket *cp);
    00063 public:
    00064   CargoMovement(Tsource *source, Tdest *destination, uint max_move) : source(source), destination(destination), max_move(max_move) {}
    00065
    00070   uint MaxMove() { return this->max_move; }
    00071 };
    00072
    00074 class CargoTransfer : public CargoMovement<VehicleCargoList, StationCargoList> {
    00075 protected:
    00076   CargoPayment *payment;
    00077 public:
    00078   CargoTransfer(VehicleCargoList *source, StationCargoList *destination, uint max_move, CargoPayment *payment) :
    00079       CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), payment(payment) {}
    00080   bool operator()(CargoPacket *cp);
    00081 };
    00082
    00084 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
    00085 protected:
    00086   TileIndex load_place;
    00087 public:
    00088   CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
    00089       CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), load_place(load_place) {}
    00090   bool operator()(CargoPacket *cp);
    00091 };
    00092
    00094 class CargoReservation: public CargoLoad {
    00095 public:
    00096   CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
    00097       CargoLoad(source, destination, max_move, load_place) {}
    00098   bool operator()(CargoPacket *cp);
    00099 };
    00100
    00102 class CargoReturn: public CargoMovement<VehicleCargoList, StationCargoList> {
    00103   StationID next;
    00104 public:
    00105   CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next) :
    00106       CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), next(next) {}
    00107   bool operator()(CargoPacket *cp);
    00108 };
    00109
    00111 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
    00112 public:
    00113   CargoShift(VehicleCargoList *source, VehicleCargoList *destination, uint max_move) :
    00114       CargoMovement<VehicleCargoList, VehicleCargoList>(source, destination, max_move) {}
    00115   bool operator()(CargoPacket *cp);
    00116 };
    00117
    00119 class CargoReroute : public CargoMovement<StationCargoList, StationCargoList> {
    00120 protected:
    00121   StationID avoid;
    00122   const GoodsEntry *ge;
    00123 public:
    00124   CargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, const GoodsEntry *ge) :
    00125       CargoMovement<StationCargoList, StationCargoList>(source, dest, max_move), avoid(avoid), ge(ge) {}
    00126   bool operator()(CargoPacket *cp);
    00127 };
    00128
    00129 #endif /* CARGOACTION_H */