Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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-1999  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 
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 

Generated on Tue Jun 24 01:27:52 2008 for Advanced Strategic Command by  doxygen 1.4.2