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 
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 class CargoReroute : public CargoMovement<StationCargoList, StationCargoList> {
00117 protected:
00118   StationID avoid;
00119   StationID avoid2;
00120   const GoodsEntry *ge;
00121 public:
00122   CargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
00123       CargoMovement<StationCargoList, StationCargoList>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
00124   bool operator()(CargoPacket *cp);
00125 };
00126 
00127 #endif /* CARGOACTION_H */