# cargoaction.h

Go to the documentation of this file.

    00001 /* $Id: cargoaction.h 26108 2013-11-25 14:30:22Z rubidium $ */
    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
    00021 template<class Tsource>
    00022 class CargoRemoval {
    00023 protected:
    00024   Tsource *source;
    00025   uint max_move;
    00026   uint Preprocess(CargoPacket *cp);
    00027   bool Postprocess(CargoPacket *cp, uint remove);
    00028 public:
    00029   CargoRemoval(Tsource *source, uint max_move) : source(source), max_move(max_move) {}
    00030
    00035   uint MaxMove() { return this->max_move; }
    00036
    00037   bool operator()(CargoPacket *cp);
    00038 };
    00039
    00041 class CargoDelivery : public CargoRemoval<VehicleCargoList> {
    00042 protected:
    00043   CargoPayment *payment;
    00044 public:
    00045   CargoDelivery(VehicleCargoList *source, uint max_move, CargoPayment *payment) :
    00046       CargoRemoval<VehicleCargoList>(source, max_move), payment(payment) {}
    00047   bool operator()(CargoPacket *cp);
    00048 };
    00049
    00055 template<class Tsource, class Tdest>
    00056 class CargoMovement {
    00057 protected:
    00058   Tsource *source;
    00059   Tdest *destination;
    00060   uint max_move;
    00061   CargoPacket *Preprocess(CargoPacket *cp);
    00062 public:
    00063   CargoMovement(Tsource *source, Tdest *destination, uint max_move) : source(source), destination(destination), max_move(max_move) {}
    00064
    00069   uint MaxMove() { return this->max_move; }
    00070 };
    00071
    00073 class CargoTransfer : public CargoMovement<VehicleCargoList, StationCargoList> {
    00074 public:
    00075   CargoTransfer(VehicleCargoList *source, StationCargoList *destination, uint max_move) :
    00076       CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move) {}
    00077   bool operator()(CargoPacket *cp);
    00078 };
    00079
    00081 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
    00082 protected:
    00083   TileIndex load_place;
    00084 public:
    00085   CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
    00086       CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), load_place(load_place) {}
    00087   bool operator()(CargoPacket *cp);
    00088 };
    00089
    00091 class CargoReservation : public CargoLoad {
    00092 public:
    00093   CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
    00094       CargoLoad(source, destination, max_move, load_place) {}
    00095   bool operator()(CargoPacket *cp);
    00096 };
    00097
    00099 class CargoReturn : public CargoMovement<VehicleCargoList, StationCargoList> {
    00100   StationID next;
    00101 public:
    00102   CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next) :
    00103       CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), next(next) {}
    00104   bool operator()(CargoPacket *cp);
    00105 };
    00106
    00108 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
    00109 public:
    00110   CargoShift(VehicleCargoList *source, VehicleCargoList *destination, uint max_move) :
    00111       CargoMovement<VehicleCargoList, VehicleCargoList>(source, destination, max_move) {}
    00112   bool operator()(CargoPacket *cp);
    00113 };
    00114
    00116 template<class Tlist>
    00117 class CargoReroute : public CargoMovement<Tlist, Tlist> {
    00118 protected:
    00119   StationID avoid;
    00120   StationID avoid2;
    00121   const GoodsEntry *ge;
    00122 public:
    00123   CargoReroute(Tlist *source, Tlist *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
    00124       CargoMovement<Tlist, Tlist>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
    00125 };
    00126
    00128 class StationCargoReroute : public CargoReroute<StationCargoList> {
    00129 public:
    00130   StationCargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
    00131         CargoReroute<StationCargoList>(source, dest, max_move, avoid, avoid2, ge) {}
    00132   bool operator()(CargoPacket *cp);
    00133 };
    00134
    00136 class VehicleCargoReroute : public CargoReroute<VehicleCargoList> {
    00137 public:
    00138   VehicleCargoReroute(VehicleCargoList *source, VehicleCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
    00139       CargoReroute<VehicleCargoList>(source, dest, max_move, avoid, avoid2, ge)
    00140   {
    00141     assert(this->max_move <= source->ActionCount(VehicleCargoList::MTA_TRANSFER));
    00142   }
    00143   bool operator()(CargoPacket *cp);
    00144 };
    00145
    00146 #endif /* CARGOACTION_H */