00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef servicingH
00023 #define servicingH
00024
00025 #include "../containerbase.h"
00026 #include "../vehicletype.h"
00027
00028
00029 class ResourceWatch {
00030 ContainerBase* container;
00031 Resources available;
00032 Resources storagelimit;
00033 Resources orgAmount;
00034 public:
00035 ResourceWatch( ContainerBase* container );
00036 ContainerBase* getContainer();
00037 SigC::Signal1<void, int> sigChanged;
00038
00039 const Resources amount();
00040 const Resources avail();
00041 const Resources limit();
00042 bool putResource( int resourcetype, int amount );
00043 bool getResource( int resourcetype, int amount );
00044 bool getResources( Resources res );
00045 };
00046
00047 class Transferrable: public SigC::Object {
00048 protected:
00049 ResourceWatch& source;
00050 ResourceWatch& dest;
00051
00052 ResourceWatch& getResourceWatch( const ContainerBase* unit );
00053 ResourceWatch& getOpposingResourceWatch( const ContainerBase* unit );
00054 ContainerBase* opposingContainer( const ContainerBase* unit );
00055
00056 void show( const ContainerBase* unit );
00057
00058 public:
00059 Transferrable( ResourceWatch& s, ResourceWatch& d );
00060 virtual ASCString getName() = 0;
00061
00066 virtual int getMax( ContainerBase* c, bool avail ) = 0;
00067 virtual int getMin( ContainerBase* c, bool avail ) = 0;
00068 virtual int transfer( ContainerBase* target, int delta ) = 0;
00069 virtual int getAmount ( const ContainerBase* target ) = 0;
00070 virtual void commit() = 0;
00071 virtual bool isExchangable() const = 0;
00072
00073
00074 ContainerBase* getSrcContainer();
00075 ContainerBase* getDstContainer();
00076 bool setDestAmount( long amount );
00077 void showAll();
00078
00079 SigC::Signal1<void,const std::string&> sigSourceAmount;
00080 SigC::Signal1<void,const std::string&> sigDestAmount;
00081
00082 int setAmount( ContainerBase* target, int newamount );
00083 void fill( ContainerBase* target );
00084 void empty( ContainerBase* target );
00085 virtual ~Transferrable() {};
00086 };
00087
00088
00089
00090 class ServiceChecker {
00091 protected:
00092 ContainerBase* source;
00093 int ignoreChecks;
00094
00095 const SingleWeapon* getServiceWeapon();
00096 virtual void ammo( ContainerBase* dest, int type ) = 0;
00097 virtual void resource( ContainerBase* dest, int type, bool active ) = 0;
00098
00099
00100 private:
00101 bool serviceWeaponFits( ContainerBase* dest );
00102
00103 public:
00104 static const int ignoreHeight = 1;
00105 static const int ignoreDistance = 2;
00106 ServiceChecker( ContainerBase* src, int skipChecks = 0 );
00107
00108
00109 void check( ContainerBase* dest );
00110 virtual ~ServiceChecker() {};
00111 };
00112
00113
00114 class ServiceTargetSearcher : protected ServiceChecker {
00115
00116 private:
00117 GameMap* gamemap;
00118
00119 void fieldChecker( const MapCoordinate& pos );
00120 void addTarget( ContainerBase* target );
00121 public:
00122 typedef vector<ContainerBase*> Targets;
00123 protected:
00124 Targets targets;
00125
00126 void ammo( ContainerBase* dest, int type );
00127 void resource( ContainerBase* dest, int type, bool active );
00128
00129 public:
00130 bool available();
00131 ServiceTargetSearcher( ContainerBase* src );
00132 void startSearch();
00133 const Targets& getTargets() const { return targets; };
00134 };
00135
00136
00137
00138
00139 class TransferHandler : public SigC::Object, protected ServiceChecker {
00140 private:
00141 ResourceWatch sourceRes;
00142 ResourceWatch destRes;
00143 public:
00144 typedef deallocating_vector<Transferrable*> Transfers;
00145 private:
00146 Transfers transfers;
00147
00148 bool allowProduction;
00149
00150 ContainerBase* source;
00151 ContainerBase* dest;
00152
00153 protected:
00154 void ammo( ContainerBase* dest, int type );
00155 void resource( ContainerBase* dest, int type, bool active );
00156
00157 public:
00158 TransferHandler( ContainerBase* src, ContainerBase* dst );
00159 bool allowAmmoProduction( bool allow );
00160 bool allowAmmoProductionAllowed();
00161 bool ammoProductionPossible();
00162 Transfers& getTransfers();
00163 void fillDest();
00164 void emptyDest();
00165 bool commit();
00166
00167 SigC::Signal0<bool> updateRanges;
00168 ~TransferHandler();
00169 };
00170
00171
00172
00173 #endif
00174