servicing.h

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 
00022 #ifndef servicingH
00023 #define servicingH
00024 
00025 #include "../containerbase.h"
00026 #include "../vehicletype.h"
00027 
00028 class Context;
00029 
00030 class ResourceWatch {
00031       ContainerBase* container;
00032       Resources available;
00033       Resources storagelimit;
00034       Resources orgAmount;
00035    public:
00036       ResourceWatch( ContainerBase* container );
00037       ContainerBase* getContainer();
00038       SigC::Signal1<void, int> sigChanged;
00039 
00040       const Resources amount();
00041       const Resources avail();
00042       const Resources limit();
00043       bool putResource( int resourcetype, int amount );
00044       bool getResource( int resourcetype, int amount );
00045       bool getResources( Resources res );
00046 };
00047 
00048 class Transferrable: public SigC::Object {
00049    protected:
00050       ResourceWatch& source;
00051       ResourceWatch& dest;
00052 
00053       ResourceWatch& getResourceWatch( const ContainerBase* unit );
00054       ResourceWatch& getOpposingResourceWatch( const ContainerBase* unit );
00055       ContainerBase* opposingContainer( const ContainerBase* unit );
00056 
00057       void show( const ContainerBase* unit );
00058       
00059    public:
00060       Transferrable( ResourceWatch& s, ResourceWatch& d );
00061       virtual ASCString getName() = 0;
00062 
00067       virtual int getMax( ContainerBase* c, bool avail ) = 0;
00068       virtual int getMin( ContainerBase* c, bool avail ) = 0;
00069       virtual int transfer( ContainerBase* target, int delta ) = 0;
00070       virtual int getAmount ( const ContainerBase* target ) = 0;
00071       
00072       virtual void commit( const Context& context ) = 0;
00073       virtual bool isExchangable() const = 0;
00074 
00076       virtual int getID() = 0;
00077       
00078       ContainerBase* getSrcContainer();
00079       ContainerBase* getDstContainer();
00080       bool setDestAmount( long amount );
00081       void showAll();
00082       
00083       SigC::Signal1<void,const std::string&> sigSourceAmount;
00084       SigC::Signal1<void,const std::string&> sigDestAmount;
00085       
00086       int setAmount( ContainerBase* target, int newamount );
00087       void fill( ContainerBase* target );
00088       void empty( ContainerBase* target );
00089       virtual ~Transferrable() {};
00090 };
00091 
00092 
00093 
00094 
00095 
00096 class ServiceChecker {
00097    protected:
00098       ContainerBase* source;
00099       int ignoreChecks;
00100 
00101       const SingleWeapon* getServiceWeapon();
00102       virtual void ammo( ContainerBase* dest, int type ) = 0;
00103       virtual void resource( ContainerBase* dest, int type, bool active )  = 0;
00104       virtual void repair( ContainerBase* dest ) = 0;
00105 
00106    private:
00107       bool serviceWeaponFits( ContainerBase* dest );
00108 
00109    public:
00110       static const int ignoreHeight = 1;
00111       static const int ignoreDistance = 2;
00112       ServiceChecker( ContainerBase* src, int skipChecks = 0 );
00113 
00114 
00115       void check( ContainerBase* dest );
00116       virtual ~ServiceChecker() {};
00117 };
00118 
00119 
00120 class ServiceTargetSearcher : protected ServiceChecker {
00121 
00122    private:
00123       GameMap* gamemap;
00124       int checks;
00125 
00126       void fieldChecker( const MapCoordinate& pos );
00127       void addTarget( ContainerBase* target );
00128    public:
00129       typedef vector<ContainerBase*> Targets;
00130    protected:
00131       Targets targets;
00132 
00133       void ammo( ContainerBase* dest, int type );
00134       void resource( ContainerBase* dest, int type, bool active );
00135       void repair( ContainerBase* dest );
00136 
00137    public:
00138       bool externallyAvailable();
00139       static const int checkAmmo = 1;
00140       static const int checkResources = 2;
00141       static const int checkRepair = 4;
00142       
00143       ServiceTargetSearcher( ContainerBase* src, int checkFlags );
00144       void startSearch();
00145       const Targets& getTargets() const { return targets; };
00146 };
00147 
00148 
00149 
00150 
00151 class TransferHandler : public SigC::Object, protected ServiceChecker {
00152    private:
00153       ResourceWatch sourceRes;
00154       ResourceWatch destRes;
00155    public:
00156       typedef deallocating_vector<Transferrable*> Transfers;
00157    private:
00158       Transfers transfers;
00159 
00160       bool allowProduction;
00161 
00162       ContainerBase* source;
00163       ContainerBase* dest;
00164       
00165    protected:
00166       void ammo( ContainerBase* dest, int type );
00167       void resource( ContainerBase* dest, int type, bool active );
00168       void repair( ContainerBase* dest ) {};
00169       
00170    public:
00171       TransferHandler( ContainerBase* src, ContainerBase* dst, int flags = 0 );
00172       
00173       using ServiceChecker::ignoreHeight;
00174       using ServiceChecker::ignoreDistance;
00175       
00176       bool allowAmmoProduction( bool allow );
00177       bool ammoProductionPossible();
00178       Transfers& getTransfers();
00179       void fillDest();
00180       void fillDestAmmo();
00181       void fillDestResource();
00182       void emptyDest();
00183       bool commit( const Context& context );
00184 
00185       SigC::Signal0<bool> updateRanges;
00186       ~TransferHandler();
00187 };
00188 
00189 
00190 
00191 #endif
00192 

Generated on Mon May 21 01:26:37 2012 for Advanced Strategic Command by  doxygen 1.5.1