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 protected:
00075   CargoPayment *payment;  
00076 public:
00077   CargoTransfer(VehicleCargoList *source, StationCargoList *destination, uint max_move, CargoPayment *payment) :
00078       CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), payment(payment) {}
00079   bool operator()(CargoPacket *cp);
00080 };
00081 
00083 class CargoLoad : public CargoMovement<StationCargoList, VehicleCargoList> {
00084 protected:
00085   TileIndex load_place; 
00086 public:
00087   CargoLoad(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
00088       CargoMovement<StationCargoList, VehicleCargoList>(source, destination, max_move), load_place(load_place) {}
00089   bool operator()(CargoPacket *cp);
00090 };
00091 
00093 class CargoReservation: public CargoLoad {
00094 public:
00095   CargoReservation(StationCargoList *source, VehicleCargoList *destination, uint max_move, TileIndex load_place) :
00096       CargoLoad(source, destination, max_move, load_place) {}
00097   bool operator()(CargoPacket *cp);
00098 };
00099 
00101 class CargoReturn: public CargoMovement<VehicleCargoList, StationCargoList> {
00102   StationID next;
00103 public:
00104   CargoReturn(VehicleCargoList *source, StationCargoList *destination, uint max_move, StationID next) :
00105       CargoMovement<VehicleCargoList, StationCargoList>(source, destination, max_move), next(next) {}
00106   bool operator()(CargoPacket *cp);
00107 };
00108 
00110 class CargoShift : public CargoMovement<VehicleCargoList, VehicleCargoList> {
00111 public:
00112   CargoShift(VehicleCargoList *source, VehicleCargoList *destination, uint max_move) :
00113       CargoMovement<VehicleCargoList, VehicleCargoList>(source, destination, max_move) {}
00114   bool operator()(CargoPacket *cp);
00115 };
00116 
00118 class CargoReroute : public CargoMovement<StationCargoList, StationCargoList> {
00119 protected:
00120   StationID avoid;
00121   StationID avoid2;
00122   const GoodsEntry *ge;
00123 public:
00124   CargoReroute(StationCargoList *source, StationCargoList *dest, uint max_move, StationID avoid, StationID avoid2, const GoodsEntry *ge) :
00125       CargoMovement<StationCargoList, StationCargoList>(source, dest, max_move), avoid(avoid), avoid2(avoid2), ge(ge) {}
00126   bool operator()(CargoPacket *cp);
00127 };
00128 
00129 #endif /* CARGOACTION_H */