00001
00002
00003
00004
00005
00006
00007
00008
00014
00015
00016
00017
00018
00019
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 class Vehicle;
00034 class Player;
00035
00040 class ContainerBase {
00041 friend class ConvertContainer;
00042 friend class ChangeContainerProperty;
00043 protected:
00044
00049 int repairedThisTurn;
00050
00052 GameMap* gamemap;
00053
00056 ContainerBase* cargoParent;
00057
00058
00072 void paintField ( const Surface& src, Surface& dest, SPoint pos, int dir, bool shaded, int shadowDist = -1 ) const;
00073
00074 ContainerBase ( const ContainerBaseType* bt, GameMap* map, int player );
00075 public:
00076
00077 virtual bool isBuilding() const = 0;
00078
00080 const ContainerBaseType* baseType;
00081
00085 virtual Surface getImage() const = 0;
00086
00087 typedef vector<const VehicleType*> Production;
00088
00089 const Production& getProduction() const;
00090 Resources getProductionCost( const VehicleType* unit ) const;
00091 void deleteProductionLine( const VehicleType* type );
00092 void deleteAllProductionLines();
00093 void addProductionLine( const VehicleType* type );
00094 bool hasProductionLine( const VehicleType* type );
00095 void setProductionLines( const Production& production );
00096 private:
00097 mutable Production productionCache;
00098 protected:
00099 Production internalUnitProduction;
00100 public:
00101
00102
00104
00105
00106 typedef vector<Vehicle*> Cargo;
00107 protected:
00108 Cargo cargo;
00109
00110 private:
00112 void compactCargo();
00113
00114 public:
00115 const Cargo& getCargo() const { return cargo; };
00116
00117 int getCargoCount() const { return cargo.size(); };
00118
00123 Vehicle* getCargo( int i );
00124
00126 void clearCargo();
00127
00128 SigC::Signal0<void> cargoChanged;
00129
00130
00132 ASCString name;
00133
00135 ASCString privateName;
00136
00141 void addToCargo( Vehicle* veh, int position = -1 );
00142
00144 bool removeUnitFromCargo( Vehicle* veh, bool recursive = false );
00145 bool removeUnitFromCargo( int nwid, bool recursive = false );
00146
00147
00149 int vehiclesLoaded ( void ) const;
00150
00152 ContainerBase* getCarrier() const;
00153
00155 Vehicle* findUnit ( int nwid, bool recursive = true ) const;
00156
00160 bool vehicleLoadable ( const Vehicle* vehicle, int uheight = -1, const bool* attacked = NULL ) const;
00161
00167 int vehicleUnloadable ( const VehicleType* vehicleType, int carrierHeight = -1 ) const;
00168
00170 const ContainerBaseType::TransportationIO* vehicleUnloadSystem ( const VehicleType* vehicle, int height );
00171
00173 int vehicleDocking ( const Vehicle* vehicle, bool out ) const;
00174
00177 bool vehicleFit ( const Vehicle* vehicle ) const;
00178
00180 int cargoWeight() const;
00181
00183 int cargoNestingDepth();
00184
00185 private:
00187 bool canCarryWeight( int additionalWeight, const Vehicle* vehicle ) const;
00189
00190 public:
00191
00192 virtual int getArmor() const = 0;
00193
00194
00196 int damage;
00197
00200 int color;
00201
00203 int getOwner() const { return color >> 3; };
00204
00206 Player& getOwningPlayer() const;
00207
00209 virtual void registerForNewOwner( int player ) = 0;
00210
00211
00212
00213 virtual void write ( tnstream& stream, bool includeLoadedUnits = true ) const = 0;
00214 virtual void read ( tnstream& stream ) = 0;
00215
00217 virtual void addview ( void ) = 0;
00218
00220 virtual void removeview ( void ) = 0;
00221
00222
00223
00225
00226
00232 virtual int putResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 ) = 0;
00233 virtual int getResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 ) = 0;
00234 virtual int getAvailableResource ( int amount, int resourcetype, int scope = 1 ) const = 0;
00235
00236 Resources putResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 );
00237 Resources getResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 );
00238 Resources getResource ( const Resources& res ) const;
00239
00241 Resources getResourceUsage ( );
00242
00243 Resources getResourcePlus ( );
00244
00246 Resources getStorageCapacity() const;
00247
00249 Resources netResourcePlus( ) const;
00250
00252 void setInternalResourcePlus( const Resources& res );
00254 void setInternalResourceMaxPlus( const Resources& res );
00255
00257 Resources getInternalResourcePlus() const;
00259 Resources getInternalResourceMaxPlus() const;
00260
00262 Resources plus;
00263
00265 Resources maxplus;
00266
00268 Resources bi_resourceplus;
00269
00271
00272
00273
00275
00276
00280 virtual const ResourceMatrix& getRepairEfficiency() const = 0;
00281
00283 virtual void postRepair ( int oldDamage ) = 0;
00284
00286 virtual bool canRepair( const ContainerBase* item ) const = 0;
00287
00290 int getMaxRepair ( const ContainerBase* item ) const;
00291 int getMaxRepair ( const ContainerBase* item, int newDamage, Resources& cost, bool ignoreCost = false ) const;
00292 int repairItem ( ContainerBase* item, int newDamage = 0 );
00293
00295 virtual int repairableDamage() const = 0;
00296
00298
00299 GameMap* getMap ( ) const { return gamemap; };
00300
00301 virtual int getIdentification() const = 0;
00302
00304 virtual int getHeight() const = 0;
00305
00306 virtual ASCString getName ( ) const = 0;
00307 ASCString getPrivateName ( ) const;
00308 virtual void setName ( const ASCString& name );
00309
00310 virtual int getAmmo( int type, int num, bool queryOnly ) = 0;
00311 virtual int getAmmo( int type, int num ) const = 0;
00312 virtual int putAmmo( int type, int num, bool queryOnly ) = 0;
00313 virtual int maxAmmo( int type ) const = 0 ;
00314
00315
00316 SigC::Signal0<void> conquered;
00317 SigC::Signal0<void> destroyed;
00318 static SigC::Signal1<void,ContainerBase*> anyContainerDestroyed;
00319 static SigC::Signal1<void,ContainerBase*> anyContainerConquered;
00320
00321 static int calcShadowDist( int binaryHeight );
00322
00323
00325 int researchpoints;
00326
00327 int maxresearchpoints;
00328
00330 virtual void endOwnTurn( void );
00331
00333 virtual void endAnyTurn( void );
00334
00336 virtual void endRound ( void );
00337
00338 int view;
00339
00340 class Work {
00341 public:
00342 virtual bool finished() = 0;
00343 virtual bool run() = 0;
00344 virtual Resources getPlus() = 0;
00345 virtual Resources getUsage() = 0;
00346 virtual ~Work() {};
00347 };
00348
00349 class WorkClassFactory {
00350 public:
00351 virtual bool available( const ContainerBase* cnt ) = 0;
00352 virtual Work* produce( ContainerBase* cnt, bool queryOnly ) = 0;
00353 virtual ~WorkClassFactory() {};
00354 };
00355
00356 static bool registerWorkClassFactory( WorkClassFactory* wcf, bool ASCmode = true );
00357 private:
00358 typedef list<WorkClassFactory*> WorkerClassList;
00359 static WorkerClassList* workClassFactoriesASC;
00360 static WorkerClassList* workClassFactoriesBI;
00361 public:
00362
00363 Work* spawnWorkClasses( bool justQuery );
00364
00365
00366 virtual MapCoordinate3D getPosition ( ) const = 0;
00367 virtual ~ContainerBase();
00368
00369 virtual vector<MapCoordinate> getCoveredFields() = 0;
00370 };
00371
00372 class TemporaryContainerStorage {
00373 ContainerBase* cb;
00374 MemoryStreamStorage buf;
00375 bool _storeCargo;
00376 public:
00377 TemporaryContainerStorage ( ContainerBase* _cb, bool storeCargo = false );
00378 void restore();
00379 };
00380
00381
00382 #endif