Advanced Strategic Command
containerbase.h
Go to the documentation of this file.
1 /***************************************************************************
2  containerbase.h - description
3  -------------------
4  begin : Fri Sep 29 2000
5  copyright : (C) 2000 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 #ifndef containerbaseH
24  #define containerbaseH
25 
26  #include <sigc++/sigc++.h>
27 
28  #include "typen.h"
29  #include "containerbasetype.h"
30  #include "graphics/surface.h"
31 
32 
33 class Vehicle;
34 class Player;
35 
41  friend class ConvertContainer;
43  protected:
44 
50 
53 
57 
58 
72  void paintField ( const Surface& src, Surface& dest, SPoint pos, int dir, bool shaded, int shadowDist = -1 ) const;
73 
74  ContainerBase ( const ContainerBaseType* bt, GameMap* map, int player );
75  public:
76 
77  virtual bool isBuilding() const = 0;
78 
81 
85  virtual Surface getImage() const = 0;
86 
87  typedef vector<const VehicleType*> Production;
88 
89  const Production& getProduction() const;
90  Resources getProductionCost( const VehicleType* unit ) const;
91  void deleteProductionLine( const VehicleType* type );
93  void addProductionLine( const VehicleType* type );
94  bool hasProductionLine( const VehicleType* type );
95  void setProductionLines( const Production& production );
96  private:
97  mutable Production productionCache;
98  protected:
100  public:
101 
102 
104 
105 
106  typedef vector<Vehicle*> Cargo;
107  protected:
109 
110  private:
112  void compactCargo();
113 
114  public:
115  const Cargo& getCargo() const { return cargo; };
116 
117  int getCargoCount() const { return cargo.size(); };
118 
123  Vehicle* getCargo( int i );
124 
126  void clearCargo();
127 
128  sigc::signal<void> cargoChanged;
129 
130 
133 
136 
141  void addToCargo( Vehicle* veh, int position = -1 );
142 
144  void moveToCargo( Vehicle* veh );
145 
147  bool removeUnitFromCargo( Vehicle* veh, bool recursive = false );
148  bool removeUnitFromCargo( int nwid, bool recursive = false );
149 
150 
152  int vehiclesLoaded ( void ) const;
153 
155  ContainerBase* getCarrier() const;
156 
158  Vehicle* findUnit ( int nwid, bool recursive = true ) const;
159 
163  bool vehicleLoadable ( const Vehicle* vehicle, int uheight = -1, const bool* attacked = NULL ) const;
164 
170  int vehicleUnloadable ( const VehicleType* vehicleType, int carrierHeight = -1 ) const;
171 
173  const ContainerBaseType::TransportationIO* vehicleUnloadSystem ( const VehicleType* vehicle, int height );
174 
176  int vehicleDocking ( const Vehicle* vehicle, bool out ) const;
177 
180  bool doesVehicleFit ( const Vehicle* vehicle ) const;
181 
183  int cargoWeight() const;
184 
186  int cargoNestingDepth();
187 
188  private:
190  bool canCarryWeight( int additionalWeight, const Vehicle* vehicle ) const;
192 
193  public:
194 
195  virtual int getArmor() const = 0;
196 
197 
199  int damage;
200 
203  int color;
204 
206  int getOwner() const { return color >> 3; };
207 
209  Player& getOwningPlayer() const;
210 
212  virtual void registerForNewOwner( int player ) = 0;
213 
214 
215 
216  virtual void write ( tnstream& stream, bool includeLoadedUnits = true ) const = 0;
217  virtual void read ( tnstream& stream ) = 0;
218 
220  virtual void addview ( void ) = 0;
221 
223  virtual void removeview ( void ) = 0;
224 
225 
226 
228 
229 
235  virtual int putResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 ) = 0;
236  virtual int getResource ( int amount, int resourcetype, bool queryonly, int scope = 1, int player = -1 ) = 0;
237  virtual int getAvailableResource ( int amount, int resourcetype, int scope = 1 ) const = 0;
238 
239  Resources putResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 );
240  Resources getResource ( const Resources& res, bool queryonly, int scope = 1, int player = -1 );
241  Resources getResource ( const Resources& res ) const;
242 
245 
247 
250 
252  Resources netResourcePlus( ) const;
253 
255  void setInternalResourcePlus( const Resources& res );
257  void setInternalResourceMaxPlus( const Resources& res );
258 
263 
266 
269 
272 
274 
275 
276 
278 
279 
283  virtual const ResourceMatrix& getRepairEfficiency() const = 0;
284 
286  virtual void postRepair ( int oldDamage, bool autoRepair ) = 0;
287 
289  virtual bool canRepair( const ContainerBase* item ) const = 0;
290 
293  int getMaxRepair ( const ContainerBase* item ) const;
294  int getMaxRepair ( const ContainerBase* item, int newDamage, Resources& cost, bool ignoreCost = false ) const;
295  int repairItem ( ContainerBase* item, int newDamage = 0, bool autoRepair = false );
296 
298  virtual int repairableDamage() const = 0;
299 
301 
302  GameMap* getMap ( ) const { return gamemap; };
303 
304  virtual int getIdentification() const = 0;
305 
307  virtual int getHeight() const = 0;
308 
309  virtual ASCString getName ( ) const = 0;
310  ASCString getPrivateName ( ) const;
311  virtual void setName ( const ASCString& name );
312 
313  virtual int getAmmo( int type, int num, bool queryOnly ) = 0;
314  virtual int getAmmo( int type, int num ) const = 0;
315  virtual int putAmmo( int type, int num, bool queryOnly ) = 0;
316  virtual int maxAmmo( int type ) const = 0 ;
317 
318 
319  sigc::signal<void> conquered;
320  sigc::signal<void> destroyed;
321  static sigc::signal<void,ContainerBase*> anyContainerDestroyed;
322  static sigc::signal<void,ContainerBase*> anyContainerConquered;
323 
324  static int calcShadowDist( int binaryHeight );
325 
326 
329 
331 
333  virtual void endOwnTurn( void );
334 
336  virtual void endAnyTurn( void );
337 
339  virtual void endRound ( void );
340 
341  int view;
342 
343  class Work {
344  public:
345  virtual bool finished() = 0;
346  virtual bool run() = 0;
347  virtual Resources getPlus() = 0;
348  virtual Resources getUsage() = 0;
349  virtual ~Work() {};
350  };
351 
353  public:
354  virtual bool available( const ContainerBase* cnt ) = 0;
355  virtual Work* produce( ContainerBase* cnt, bool queryOnly ) = 0;
356  virtual ~WorkClassFactory() {};
357  };
358 
359  static bool registerWorkClassFactory( WorkClassFactory* wcf, bool ASCmode = true );
360  private:
361  typedef list<WorkClassFactory*> WorkerClassList;
362  static WorkerClassList* workClassFactoriesASC;
363  static WorkerClassList* workClassFactoriesBI;
364  public:
365 
366  Work* spawnWorkClasses( bool justQuery );
367 
368 
369  virtual MapCoordinate3D getPosition ( ) const = 0;
370  virtual ~ContainerBase();
371 
372  virtual vector<MapCoordinate> getCoveredFields() = 0;
373 };
374 
376  ContainerBase* cb;
378  bool _storeCargo;
379  public:
380  TemporaryContainerStorage ( ContainerBase* _cb, bool storeCargo = false );
381  void restore();
382 };
383 
384 
385 #endif
Vehicle * findUnit(int nwid, bool recursive=true) const
searches for a the unit in carrier and optionally all inner carriers
A mathematical matrix for transforming Resources instance (which is mathematically a vector) into a d...
Definition: typen.h:158
An in-memory storage of streamed data.
Definition: basestrm.h:172
Resources getInternalResourcePlus() const
The ResourcePlus is used for different purposes by different building or vehicle functions, or not at all.
Resources netResourcePlus() const
returns the amount of resources that the net which the building is connected to produces each turn ...
void paintField(const Surface &src, Surface &dest, SPoint pos, int dir, bool shaded, int shadowDist=-1) const
displays an image of this container on the surface.
virtual int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
virtual Surface getImage() const =0
returns an image for the Container.
virtual bool finished()=0
Resources getResourceUsage()
returns the resource that the building consumes for its operation.
ContainerBase * cargoParent
if this container is transported inside a carrier, this is carrier
Definition: containerbase.h:56
int getMaxRepair(const ContainerBase *item) const
returns the maximum amount of damage that the given item can be repaired
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
ContainerBase(const ContainerBaseType *bt, GameMap *map, int player)
bool vehicleLoadable(const Vehicle *vehicle, int uheight=-1, const bool *attacked=NULL) const
can the vehicle be loaded.
ASCString name
a name given by the user or the map creator
int repairItem(ContainerBase *item, int newDamage=0, bool autoRepair=false)
Resources getResourcePlus()
virtual ASCString getName() const =0
virtual void write(tnstream &stream, bool includeLoadedUnits=true) const =0
Resources getStorageCapacity() const
returns the local storage capacity for the given resource, which depends on the resource mode of the ...
int getOwner() const
returns the number of the player this vehicle/building belongs to
void deleteAllProductionLines()
void moveToCargo(Vehicle *veh)
adds the unit to the cargo, and removes its from its current position
virtual const ResourceMatrix & getRepairEfficiency() const =0
when a ContainerBase is repair by this ContainerBase, the default cost can be customized with this ma...
static sigc::signal< void, ContainerBase * > anyContainerConquered
virtual int getIdentification() const =0
sigc::signal< void > cargoChanged
virtual bool isBuilding() const =0
ASCString getPrivateName() const
The interface for all kinds of IO stream.
static int calcShadowDist(int binaryHeight)
int getCargoCount() const
virtual void removeview(void)=0
removes the containers view (=radar) on the map
virtual Resources getPlus()=0
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual int getAvailableResource(int amount, int resourcetype, int scope=1) const =0
const Production & getProduction() const
Production internalUnitProduction
Definition: containerbase.h:99
virtual vector< MapCoordinate > getCoveredFields()=0
Work * spawnWorkClasses(bool justQuery)
virtual void postRepair(int oldDamage, bool autoRepair)=0
is called after a repair is performed. Vehicles use this to reduce their experience.
TemporaryContainerStorage(ContainerBase *_cb, bool storeCargo=false)
virtual void addview(void)=0
registers the containers view (=radar) on the map
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
Player & getOwningPlayer() const
returns the player this vehicle/building belongs to
virtual ~ContainerBase()
int vehicleUnloadable(const VehicleType *vehicleType, int carrierHeight=-1) const
checks the unloading of a unit type
virtual int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
virtual Work * produce(ContainerBase *cnt, bool queryOnly)=0
Resources getProductionCost(const VehicleType *unit) const
sigc::signal< void > destroyed
virtual int getHeight() const =0
returns the bitmapped level of height. Only one bit will be set, of course
void clearCargo()
removes ALL units from cargo
Resources maxplus
the maximum amount of Resources that the building can produce each turn in the ASC resource mode ; se...
void addProductionLine(const VehicleType *type)
virtual bool run()=0
SDLmm::SPoint SPoint
Definition: surface.h:27
Resources plus
the Resources that are produced each turn
int repairedThisTurn
the percantage that this container has already been repaired this turn.
Definition: containerbase.h:49
GameMap * gamemap
the map that this container is placed on
Definition: containerbase.h:52
virtual void endOwnTurn(void)
hook that is called when a player ends his turn
virtual Resources getUsage()=0
int vehiclesLoaded(void) const
returns the number of loaded units
bool hasProductionLine(const VehicleType *type)
const ContainerBaseType::TransportationIO * vehicleUnloadSystem(const VehicleType *vehicle, int height)
returns the unloading system
Resources bi_resourceplus
the maximum amount of Resources that the building can produce each turn in the BI resource mode ; see...
int color
The owner of the container.
bool doesVehicleFit(const Vehicle *vehicle) const
Does the vehicle fit into the container? This does not include checking if it can reach the entry...
Resources getInternalResourceMaxPlus() const
The ResourceMaxPlus is used for different purposes by different building or vehicle functions...
ContainerBase * getCarrier() const
if this is a unit and it is inside a building or transport, returns the transport. NULL otherwise.
vector< const VehicleType * > Production
Definition: containerbase.h:87
void setInternalResourcePlus(const Resources &res)
The ResourcePlus is used for different purposes by different building or vehicle functions, or not at all.
void addToCargo(Vehicle *veh, int position=-1)
adds the unit to the cargo
virtual void endAnyTurn(void)
hook that is called when any player (including owner) ends turn
virtual int getAmmo(int type, int num, bool queryOnly)=0
Coordinate on the map including height.
Definition: typen.h:238
virtual int repairableDamage() const =0
returns the amount of damage that can still be repaired this turn
virtual void endRound(void)
hook that is called the next round begins ( active player switching from player8 to player1 ) ...
int cargoWeight() const
weight of all loaded units
ASCString privateName
a name given by the user which is only visible to him and his allies.
const ContainerBaseType * baseType
the type descriping all non-instance specific properties of the container
Definition: containerbase.h:80
static bool registerWorkClassFactory(WorkClassFactory *wcf, bool ASCmode=true)
sigc::signal< void > conquered
GameMap * getMap() const
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
virtual bool canRepair(const ContainerBase *item) const =0
checks whether the item can be repaired provided that it is in range
void deleteProductionLine(const VehicleType *type)
vector< Vehicle * > Cargo
the different players in ASC. There may be 8 players (0..7) and neutral units (8) ...
Definition: player.h:99
Resources are basically the currency of ASC.
Definition: typen.h:97
virtual int maxAmmo(int type) const =0
int researchpoints
the current amount of research that the building conducts every turn
bool removeUnitFromCargo(Vehicle *veh, bool recursive=false)
removes the given unit from the container.
virtual int getArmor() const =0
const Cargo & getCargo() const
virtual int putAmmo(int type, int num, bool queryOnly)=0
virtual void registerForNewOwner(int player)=0
this is a low level functions that changes the registration in the map. It's called by convert(int...
int vehicleDocking(const Vehicle *vehicle, bool out) const
returns the levels of height on which this unit can be transfered by docking; or 0 if no unloading is...
static sigc::signal< void, ContainerBase * > anyContainerDestroyed
void setInternalResourceMaxPlus(const Resources &res)
The ResourceMaxPlus is used for different purposes by different building or vehicle functions...
virtual void read(tnstream &stream)=0
virtual bool available(const ContainerBase *cnt)=0
virtual void setName(const ASCString &name)
int cargoNestingDepth()
returns the nesting depth of the cargo. The unit standing on the field is 0, its cargo is 1...
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
void setProductionLines(const Production &production)
virtual MapCoordinate3D getPosition() const =0