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

containerbase.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           containerbase.h  -  description
00003                              -------------------
00004     begin                : Fri Sep 29 2000
00005     copyright            : (C) 2000 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00014 /***************************************************************************
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef containerbaseH
00024  #define containerbaseH
00025 
00026  #include <sigc++/sigc++.h>
00027 
00028  #include "typen.h"
00029  #include "containerbasetype.h"
00030  #include "graphics/surface.h"
00031  
00032 
00033 
00034 class Vehicle;
00035 class Player;
00036 
00041 class ContainerBase {
00042    protected:
00043       GameMap* gamemap;
00044       ContainerBase* cargoParent;
00045       virtual const ResourceMatrix& getRepairEfficiency ( void ) = 0;
00046 
00048       virtual void postRepair ( int oldDamage ) = 0;
00049 
00050       void paintField ( const Surface& src, Surface& dest, SPoint pos, int dir, bool shaded, int shadowDist = -1 ) const;
00051       
00052       ContainerBase ( const ContainerBaseType* bt, GameMap* map, int player );
00053    public:
00054 
00055       virtual bool isBuilding() const = 0;
00056 
00057       const ContainerBaseType*  baseType;
00058 
00059       virtual Surface getImage() const = 0;
00060 
00061       typedef vector<const Vehicletype*> Production;
00062 
00063       const Production& getProduction() const;
00064       Resources getProductionCost( const Vehicletype* unit ) const;
00065       void deleteProductionLine( const Vehicletype* type );
00066       void deleteAllProductionLines();
00067       void addProductionLine( const Vehicletype* type  );
00068       void setProductionLines( const Production& production  );
00069    private:
00070       mutable Production productionCache;
00071    protected:
00072       Production internalUnitProduction;
00073    public:
00074       
00075 
00077 
00078 
00079       typedef vector<Vehicle*> Cargo;
00080    protected:  
00081       Cargo cargo;
00082 
00083    public:
00084       const Cargo& getCargo() const { return cargo; };
00085 
00087       void clearCargo();
00088 
00089       SigC::Signal0<void> cargoChanged;
00090 
00091       virtual int  getArmor() const = 0;
00092       
00093       void addToCargo( Vehicle* veh );
00094       
00096       bool removeUnitFromCargo( Vehicle* veh, bool recursive = false );
00097       bool removeUnitFromCargo( int nwid, bool recursive = false );
00098       
00099       bool unitLoaded( int nwid );
00100       
00102       int vehiclesLoaded ( void ) const;
00103       
00105       ContainerBase* getCarrier() const;
00106 
00108       Vehicle* findUnit ( int nwid ) const;
00109       
00113       bool vehicleLoadable ( const Vehicle* vehicle, int uheight = -1, const bool* attacked = NULL ) const;
00114 
00116       int  vehicleUnloadable ( const Vehicletype* vehicleType ) const;
00117 
00119       const ContainerBaseType::TransportationIO* vehicleUnloadSystem ( const Vehicletype* vehicle, int height );
00120 
00122       int  vehicleDocking ( const Vehicle* vehicle, bool out  ) const;
00123 
00126       bool vehicleFit ( const Vehicle* vehicle ) const;
00127 
00129       int cargoWeight() const;
00130 
00132       int cargoNestingDepth();
00133 
00134    private:
00136       bool canCarryWeight( int additionalWeight ) const;
00138 
00139    public:
00140      
00141       int damage;
00142       
00143       int color;
00145       int getOwner() const { return color >> 3; };
00146       Player& getOwningPlayer() const;;
00147       
00148       virtual void convert ( int player ) = 0;
00149       
00150 
00151 
00152       virtual void write ( tnstream& stream, bool includeLoadedUnits = true ) = 0;
00153       virtual void read ( tnstream& stream ) = 0;
00154 
00155       virtual void addview ( void ) = 0;
00156       virtual void removeview ( void ) = 0;
00157 
00158 
00159       
00160 
00162 
00163 
00169       virtual int putResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 ) = 0;
00170       virtual int getResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 ) = 0;
00171       virtual int getAvailableResource ( int amount, int resourcetype, int scope = 1 ) const = 0;
00172 
00173       Resources putResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 );
00174       Resources getResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 );
00175       Resources getResource ( const Resources& res ) const;
00176 
00178       Resources getResourceUsage ( );
00179 
00180       Resources getResourcePlus ( );
00181       
00183       Resources getStorageCapacity() const;
00184       
00186       Resources netResourcePlus( ) const;
00187 
00188 
00190       Resources   plus;
00191 
00193       Resources   maxplus;
00194 
00196       Resources    bi_resourceplus;
00197       
00199       
00200 
00201       
00202       
00203       virtual bool canRepair( const ContainerBase* item ) const = 0;
00204 
00205       int getMaxRepair ( const ContainerBase* item );
00206       int getMaxRepair ( const ContainerBase* item, int newDamage, Resources& cost, bool ignoreCost = false  );
00207       int repairItem   ( ContainerBase* item, int newDamage = 0 );
00208       
00210       virtual int repairableDamage() = 0;
00211 
00212 
00213       GameMap* getMap ( ) const { return gamemap; };
00214       
00215       virtual int getIdentification() = 0;
00216 
00218       virtual int getHeight() const = 0;
00219 
00220       virtual ASCString getName ( ) const = 0;
00221 
00222       virtual int getAmmo( int type, int num, bool queryOnly )  = 0;
00223       virtual int getAmmo( int type, int num ) const  = 0;
00224       virtual int putAmmo( int type, int num, bool queryOnly )  = 0;
00225       virtual int maxAmmo( int type ) const = 0 ;
00226 
00227 
00228       SigC::Signal0<void> conquered;
00229       SigC::Signal0<void> destroyed;
00230       static SigC::Signal1<void,ContainerBase*> anyContainerDestroyed;
00231       static SigC::Signal1<void,ContainerBase*> anyContainerConquered;
00232 
00233       static int calcShadowDist( int binaryHeight );
00234 
00235 
00237       int         researchpoints;
00238 
00239       int         maxresearchpoints;
00240 
00242       virtual void endOwnTurn( void );
00243 
00245       virtual void endAnyTurn( void );
00246 
00248       virtual void endRound ( void );
00249       
00250 
00251       class Work {
00252          public:
00253             virtual bool finished() = 0;
00254             virtual bool run() = 0;
00255             virtual Resources getPlus() = 0;
00256             virtual Resources getUsage() = 0;
00257             virtual ~Work() {};
00258       };
00259 
00260       class WorkClassFactory {
00261          public:
00262             virtual bool available( const ContainerBase* cnt ) = 0;
00263             virtual Work* produce( ContainerBase* cnt, bool queryOnly ) = 0;
00264             virtual ~WorkClassFactory() {};
00265       };
00266 
00267       static bool registerWorkClassFactory( WorkClassFactory* wcf, bool ASCmode = true );
00268    private:
00269       typedef list<WorkClassFactory*> WorkerClassList;
00270       static WorkerClassList* workClassFactoriesASC;
00271       static WorkerClassList* workClassFactoriesBI;
00272    public:
00273       
00274       Work* spawnWorkClasses( bool justQuery );
00275 
00276       
00277       virtual MapCoordinate3D getPosition ( ) const = 0;
00278       virtual ~ContainerBase();
00279 
00280       virtual vector<MapCoordinate> getCoveredFields() = 0;
00281 };
00282 
00283 class TemporaryContainerStorage  {
00284         ContainerBase* cb;
00285         tmemorystreambuf buf;
00286         bool _storeCargo;
00287      public:
00288         TemporaryContainerStorage ( ContainerBase* _cb, bool storeCargo = false );
00289         void restore();
00290 };
00291 
00292 
00293 #endif

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