Advanced Strategic Command
containerbase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  containerbase.cpp - description
3  -------------------
4  begin : Fri Sep 29 2000
5  copyright : (C) 2003 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 #include <algorithm>
24 #include "typen.h"
25 #include "containerbase.h"
26 #include "vehicletype.h"
27 #include "vehicle.h"
28 #include "spfst.h"
29 #include "graphics/blitter.h"
31 #include "containercontrols.h"
32 #include "resourcenet.h"
33 #include "accessconstraints.h"
34 
35 
36 ContainerBase :: ContainerBase ( const ContainerBaseType* bt, GameMap* map, int player ) : gamemap ( map ), cargoParent(NULL), baseType (bt)
37 {
38  view = bt->view;
39  damage = 0;
40  color = player*8;
44  repairedThisTurn = 0;
45 
47 
48  for ( int i = 0; i < map->getVehicleTypeNum(); ++i ) {
49  const VehicleType* vt = map->getvehicletype_bypos(i);
50  if ( vt )
51  for ( int j = 0; j < bt->vehiclesInternallyProduceable.size(); ++j )
52  if ( vt->id >= bt->vehiclesInternallyProduceable[j].from && vt->id <= bt->vehiclesInternallyProduceable[j].to )
53  internalUnitProduction.push_back ( vt );
54  }
55 }
56 
57 
59 {
60  if ( privateName.empty())
61  return getName();
62  else
63  return privateName;
64 }
65 
66 
67 sigc::signal<void,ContainerBase*> ContainerBase :: anyContainerDestroyed;
68 sigc::signal<void,ContainerBase*> ContainerBase :: anyContainerConquered;
69 
70 
71 Resources ContainerBase :: putResource ( const Resources& res, bool queryonly, int scope, int player)
72 {
73  Resources result;
74  for ( int i = 0; i < resourceNum; i++ )
75  result.resource(i) = putResource ( res.resource(i), i , queryonly, scope, player );
76  return result;
77 }
78 
79 
80 Resources ContainerBase :: getResource ( const Resources& res, bool queryonly, int scope, int player)
81 {
82  Resources result;
83  for ( int i = 0; i < resourceNum; i++ )
84  result.resource(i) = getResource ( res.resource(i), i , queryonly, scope, player );
85  return result;
86 }
87 
89 {
90  Resources result;
91  for ( int i = 0; i < resourceNum; i++ )
92  result.resource(i) = getAvailableResource ( res.resource(i), i );
93  return result;
94 }
95 
96 
97 int ContainerBase :: repairItem ( ContainerBase* item, int newDamage, bool autoRepair )
98 {
99  if ( !canRepair( item ) )
100  return item->damage;
101 
102  if ( item == this )
103  if ( damage - repairableDamage() > newDamage )
104  newDamage = damage - repairableDamage();
105 
106  int orgdam = item->damage;
107 
108  Resources cost;
109  newDamage = getMaxRepair ( item, newDamage, cost );
110  item->damage = newDamage;
111  getResource ( cost, 0 );
112 
113  item->postRepair( orgdam, autoRepair );
114 
115  return newDamage;
116 }
117 
119 {
120  Resources res;
121  return getMaxRepair ( item, 0, res );
122 }
123 
124 int ContainerBase :: getMaxRepair ( const ContainerBase* item, int newDamage, Resources& cost, bool ignoreCost ) const
125 {
126  if ( !canRepair( item ) )
127  return item->damage;
128 
129  if ( item == this ) {
130  if ( damage - repairableDamage() > newDamage )
131  newDamage = damage - repairableDamage();
132  } else if ( item->getCarrier() != this ) {
133  if ( newDamage < item->baseType->minFieldRepairDamage )
134  newDamage = item->baseType->minFieldRepairDamage;
135  }
136 
137  if ( newDamage > item->damage )
138  newDamage = item->damage;
139 
140  int toRepair = item->damage - newDamage;
141 
142  Resources maxNeeded = getRepairEfficiency() * item->baseType->productionCost;
143 
144  Resources needed;
145  for ( int i = 0; i < resourceTypeNum; i++ )
146  needed.resource(i) = maxNeeded.resource(i) * (item->damage-newDamage) / 100;
147 
148  if ( !ignoreCost ) {
149  Resources avail = getResource ( needed );
150 
151  for ( int i = 0; i < resourceTypeNum; i++ )
152  if ( needed.resource(i) ) {
153  int repairable = toRepair * avail.resource(i) / needed.resource(i);
154  if ( item->damage - repairable > newDamage )
155  newDamage = item->damage - repairable;
156  }
157  }
158 
159  for ( int i = 0; i < resourceTypeNum; i++ )
160  cost.resource(i) = maxNeeded.resource(i) * (item->damage-newDamage) / 100;
161 
162  return newDamage;
163 }
164 
166 {
167  int a = 0;
168 
169  for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
170  if ( *i )
171  ++a;
172 
173  return a;
174 }
175 
176 
178 {
179  int w = 0;
180  for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
181  if ( *i )
182  w += (*i)->weight();
183 
184  return w;
185 }
186 
187 
189 {
190  ContainerBase* cb = getCarrier();
191  if ( cb )
192  return cb->cargoNestingDepth() +1;
193  else
194  return 0;
195 }
196 
197 void ContainerBase :: compactCargo()
198 {
199  for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ) {
200  if ( *i == NULL )
201  i = cargo.erase(i);
202  else
203  ++i;
204  }
205 }
206 
207 
209 {
210  if ( i < 0 || i >= cargo.size() )
211  return NULL;
212  else
213  return cargo.at(i);
214 }
215 
216 
217 
219 {
220  return cargoParent;
221 }
222 
223 
224 Vehicle* ContainerBase :: findUnit ( int nwid, bool recursive ) const
225 {
226  for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
227  if ( *i ) {
228  if ( (*i)->networkid == nwid )
229  return *i;
230  else {
231  if ( recursive ) {
232  Vehicle* cb = (*i)->findUnit( nwid );
233  if ( cb )
234  return cb;
235  }
236  }
237  }
238 
239  return NULL;
240 }
241 
242 
243 template<int pixelSize>
245 { }
246 ;
247 
248 template<>
250 {
251  public:
253  {
254  setTranslationTable( *xlatpictgraytable );
255  };
256 };
257 
258 template<>
260 {
261  public:
263  {}
264 }
265 ;
266 
267 
268 int ContainerBase::calcShadowDist( int binaryHeight )
269 {
270  if ( binaryHeight <= 1 )
271  return 0;
272 
273  if ( binaryHeight <= 3 )
274  return 1;
275 
276  return 6 * ( binaryHeight - getFirstBit ( chfahrend ));
277 }
278 
279 
280 void ContainerBase::paintField ( const Surface& img, Surface& dest, SPoint pos, int dir, bool shaded, int shadowDist ) const
281 {
282 
283  pair<const Surface*, int> dirpair = make_pair(&img, directionangle[dir]);
284 
285  int height = getHeight();
286  if ( height <= chgetaucht ) {
287  if ( shaded ) {
292  ( img, dest, pos, nullParam,nullParam, dirpair, nullParam);
293  } else {
294  if ( img.GetPixelFormat().BytesPerPixel() == 1 ) {
296  blitter.setPlayer( getOwner() );
297  blitter.setAngle( img, directionangle[dir] );
298  blitter.blit( img, dest, pos );
299 
300  /*
301  megaBlitter< ColorTransform_PlayerCol,
302  ColorMerger_AlphaMixer,
303  SourcePixelSelector_CacheRotation,
304  TargetPixelSelector_All>
305  ( img, dest, pos, getOwner(),nullParam, dirpair, nullParam);
306  */
307  } else {
309  blitter.setColor( gamemap->player[getOwner()].getColor() );
310  blitter.setAngle( img, directionangle[dir] );
311  blitter.blit( img, dest, pos );
312 
313  }
314  }
315  } else {
316  if ( height >= chfahrend && shadowDist ) {
317  if ( shadowDist == -1 )
318  shadowDist = calcShadowDist( getFirstBit( height ));
319 
324  ( img, dest, SPoint(pos.x+shadowDist, pos.y+shadowDist), nullParam,nullParam, dirpair, nullParam);
325  }
326 
327  if ( shaded ) {
332  ( img, dest, pos, nullParam,nullParam, dirpair, nullParam);
333  } else {
334  if ( img.GetPixelFormat().BytesPerPixel() == 1 ) {
336  blitter.setPlayer( getOwner() );
337  blitter.setAngle( img, directionangle[dir] );
338  blitter.blit( img, dest, pos );
339  } else {
342  blitter.setColor( gamemap->player[getOwner()].getColor() );
343  blitter.setAngle( img, directionangle[dir] );
344  blitter.blit( img, dest, pos );
345  }
346  }
347  }
348 }
349 
350 
352 {
353  while ( !cargo.empty() )
354  if ( cargo.front() )
355  delete cargo.front();
356  else
357  cargo.erase( cargo.begin() );
358 
359  cargoChanged();
360 }
361 
362 
363 void ContainerBase :: addToCargo( Vehicle* veh, int position )
364 {
365  if ( veh == this )
366  fatalError ("Trying to add unit to its own cargo");
367 
368  bool slotFound = false;
369  for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
370  if ( ! (*i) && (position == -1 || position == i - cargo.begin() )) {
371  *i = veh;
372  slotFound = true;
373  break;
374  }
375 
376  if ( !slotFound )
377  cargo.push_back( veh );
378 
379  veh->cargoParent = this;
380  veh->setnewposition(getPosition());
381  cargoChanged();
382 }
383 
385 {
386  veh->unregisterPosition();
387  addToCargo(veh);
388 }
389 
390 
391 bool ContainerBase :: removeUnitFromCargo( Vehicle* veh, bool recursive )
392 {
393  if ( !veh )
394  return false;
395  else {
396  if ( removeUnitFromCargo( veh->networkid, recursive )) {
397  cargoChanged();
398  return true;
399  } else
400  return false;
401  }
402 }
403 
404 bool ContainerBase :: removeUnitFromCargo( int nwid, bool recursive )
405 {
406  for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
407  if ( *i ) {
408  if ( (*i)->networkid == nwid ) {
409  (*i)->cargoParent = NULL;
410  *i = NULL;
411 
412  if ( cargo.size() > baseType->maxLoadableUnits ) {
413  // we only compact the cargo when we have more slots than allowed (may happen when conquering fully occupied buildings).
414  // because else we would confuse the user if the position of units in the cargo dialog changes
415  compactCargo();
416  }
417 
418  cargoChanged();
419  return true;
420  }
421  if ( recursive )
422  if ( (*i)->removeUnitFromCargo( nwid, recursive ))
423  return true;
424  }
425 
426  return false;
427 }
428 
429 bool ContainerBase :: canCarryWeight( int additionalWeight, const Vehicle* vehicle) const
430 {
431  // if the unit already carries this unit, there is no additional weight to check
432  if ( vehicle && findUnit( vehicle->networkid ))
433  additionalWeight = 0;
434 
435 
436  if ( cargoWeight() + additionalWeight > baseType->maxLoadableWeight )
437  return false;
438  else
439  if ( getCarrier() )
440  return getCarrier()->canCarryWeight( additionalWeight, vehicle );
441  else
442  return true;
443 }
444 
445 
446 bool ContainerBase :: doesVehicleFit ( const Vehicle* vehicle ) const
447 {
448  bool isConquering = isBuilding() && getMap()->getPlayer(this).diplomacy.isHostile( vehicle) && vehicle->color != color;
449  if ( baseType->vehicleFit ( vehicle->typ )) // checks size and type
450  if ( vehiclesLoaded() < baseType->maxLoadableUnits || isConquering )
451  if ( canCarryWeight( vehicle->weight(), vehicle ) || findUnit ( vehicle->networkid ) || isConquering) // if the unit is already loaded, the container already bears its weight
452  return true;
453 
454  return false;
455 }
456 
457 
458 bool ContainerBase :: vehicleLoadable ( const Vehicle* vehicle, int uheight, const bool* attacked ) const
459 {
460  if ( vehicle->attacked )
461  return false;
462 
463  bool hasAttacked = vehicle->attacked;
464  if ( attacked )
465  hasAttacked = *attacked;
466 
467  if ( uheight == -1 )
468  uheight = vehicle->height;
469 
470  if ( doesVehicleFit ( vehicle ))
471  for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
472  if ( (i->height_abs & uheight) || (i->height_abs == 0 ))
474  if ( i->height_rel == -100 || i->height_rel == getheightdelta ( getPosition().getNumericalHeight(), getFirstBit(uheight) ) )
475  if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
476  if ( vehicle->typ->hasAnyFunction(i->requiresUnitFeature) || i->requiresUnitFeature.none() )
477  if ( i->vehicleCategoriesLoadable & (1<<vehicle->typ->movemalustyp)) {
478  if ( getMap()->getPlayer(this).diplomacy.isAllied( vehicle->getOwner()) )
479  return true;
480 
481  if ( isBuilding() ) {
482  if ( !hasAttacked ) {
483  if ( getOwner() == 8 )
484  return true;
485  if ( gamemap->getPlayer(this).diplomacy.isHostile( vehicle->getOwner()) )
487  return true;
488  }
489  }
490  }
491  return false;
492 }
493 
494 int ContainerBase :: vehicleUnloadable ( const VehicleType* vehicleType, int carrierHeight ) const
495 {
496  if (carrierHeight == -1 )
497  return baseType->vehicleUnloadable( vehicleType, getPosition().getNumericalHeight());
498  else
499  return baseType->vehicleUnloadable( vehicleType, carrierHeight );
500 
501 }
502 
504 {
505  if ( baseType->vehicleFit ( vehicleType ))
506  for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
508  if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
509  if ( i->vehicleCategoriesLoadable & (1<<vehicleType->movemalustyp))
510  if ( vehicleType->hasAnyFunction(i->requiresUnitFeature) || i->requiresUnitFeature.none() ) {
511  if ( i->height_abs != 0 && i->height_rel != -100 ) {
512  if ( height & ( i->height_abs & (1 << (getPosition().getNumericalHeight() + i->height_rel ))))
513  return &(*i);
514  } else
515  if ( i->height_rel != -100 ) {
516  if ( height & ( 1 << (getPosition().getNumericalHeight() + i->height_rel)))
517  return &(*i);
518  } else
519  if ( height & i->height_abs )
520  return &(*i);
521  }
522  return NULL;
523 
524 }
525 
526 int ContainerBase :: vehicleDocking ( const Vehicle* vehicle, bool out ) const
527 {
528  if ( vehicle == this )
529  return 0;
530 
531  int height = 0;
532 
533  if ( baseType->vehicleFit ( vehicle->typ ) && ( doesVehicleFit( vehicle ) || out ) )
534  for ( ContainerBaseType::EntranceSystems::const_iterator i = baseType->entranceSystems.begin(); i != baseType->entranceSystems.end(); i++ )
536  if ( (i->container_height & getPosition().getBitmappedHeight()) || (i->container_height == 0))
537  if ( i->vehicleCategoriesLoadable & (1<<vehicle->typ->movemalustyp)) {
538  if ( i->dockingHeight_abs != 0 && i->dockingHeight_rel != -100 )
539  height |= i->dockingHeight_abs & (1 << (getPosition().getNumericalHeight() + i->dockingHeight_rel ));
540  else
541  if ( i->dockingHeight_rel != -100 )
542  height |= 1 << (getPosition().getNumericalHeight() + i->dockingHeight_rel) ;
543  else
544  height |= i->dockingHeight_abs ;
545  }
546  return height;
547 }
548 
550 {
551  if ( productionCache.empty() && !internalUnitProduction.empty() ) {
552  for ( int height = 0; height < 8; ++height )
553  if ( (1 << height) & baseType->height )
554  for ( Production::const_iterator i = internalUnitProduction.begin(); i != internalUnitProduction.end(); ++i )
556  if( find ( productionCache.begin(), productionCache.end(), *i ) == productionCache.end() )
557  productionCache.push_back ( *i );
558  }
559 
560  return productionCache;
561 }
562 
564 {
566 }
567 
568 
570 {
572  productionCache.clear();
573 }
574 
576 {
577  internalUnitProduction.clear();
578  productionCache.clear();
579 }
580 
582 {
583  if ( find ( internalUnitProduction.begin(), internalUnitProduction.end(), type ) == internalUnitProduction.end() )
584  internalUnitProduction.push_back( type );
585  productionCache.clear();
586 }
587 
589 {
590  return find ( internalUnitProduction.begin(), internalUnitProduction.end(), type ) != internalUnitProduction.end();
591 }
592 
593 
595 {
596  internalUnitProduction = production;
597  productionCache.clear();
598 }
599 
600 
602 {
603  if ( !checkModificationConstraints( this ) )
604  return;
605 
606  this->name = name;
607 }
608 
609 
611 {
612  /* removing a unit from cargo (which is done when deleting) may cause a call to compactCargo,
613  which in turn invalidates the iterators to cargo
614  That's why we iterate through a copy of cargo */
615  Cargo toDelete = cargo;
616 
617  for ( Cargo::iterator i = toDelete.begin(); i != toDelete.end(); ++i )
618  if ( *i )
619  delete *i;
620 
621  if ( gamemap->state != GameMap::Destruction ) {
622  destroyed();
623  anyContainerDestroyed( this );
624  }
625 }
626 
627 
629 {
630  cb = _cb;
631  MemoryStream stream ( &buf, tnstream::writing );
632  cb->write ( stream, storeCargo );
633  _storeCargo = storeCargo;
634 }
635 
637 {
638  if ( _storeCargo ) {
639  cb->clearCargo();
640  }
641 
642  MemoryStream stream ( &buf, tnstream::reading );
643  cb->read ( stream );
644 }
645 
646 
647 
648 
649 
650 
652 {
653 }
654 
656 {
657 }
658 
660 {
661  view = baseType->view;
662 }
663 
664 
665 
667 {
668  Resources res;
669  for ( int resourcetype = 0; resourcetype < resourceTypeNum; resourcetype++ ) {
670  GetResourcePlus grp ( getMap() );
671  res.resource(resourcetype) += grp.getresource ( getPosition().x, getPosition().y, resourcetype, color/8, 1 );
672  }
673  return res;
674 }
675 
676 
677 
679 {
680  return getMap()->getPlayer(this);
681 }
682 
684 {
685  for ( int r = 0; r < Resources::count; ++r )
686  plus.resource(r) = min ( res.resource(r), min( maxplus.resource(r), baseType->maxplus.resource(r)));
687 }
688 
690 {
691  for ( int r = 0; r < Resources::count; ++r )
692  maxplus.resource(r) = min ( res.resource(r), baseType->maxplus.resource(r));
693 }
694 
696 {
697  return plus;
698 }
699 
701 {
702  return maxplus;
703 }
704 
705 
707 {
708  Work* w = spawnWorkClasses ( true );
709  Resources r;
710  if ( w )
711  r = w->getPlus();
712  delete w;
713 
714  // printf ("building %s %d / %d : plus %d %d %d \n", typ->name.c_str(), getPosition().x, getPosition().y, r.energy, r.material, r.fuel );
715 
716  return r;
717 }
718 
720 {
721  Work* w = spawnWorkClasses ( true );
722  Resources r;
723  if ( w )
724  r = w->getUsage();
725  delete w;
726 
729 
730 
731  return r;
732 }
733 
735 {
736  if ( gamemap && gamemap->_resourcemode == 1 && isBuilding() )
737  return baseType->getStorageCapacity( 1 );
738  else
739  return baseType->getStorageCapacity( 0 );
740 }
741 
742 
743 
744 
746 {
747  if ( ASCmode ) {
748  if ( !workClassFactoriesASC )
749  workClassFactoriesASC = new WorkerClassList;
750 
751  workClassFactoriesASC->push_back( wcf );
752  } else {
753  if ( !workClassFactoriesBI )
754  workClassFactoriesBI = new WorkerClassList;
755 
756  workClassFactoriesBI->push_back( wcf );
757  }
758  return true;
759 }
760 
761 ContainerBase::WorkerClassList* ContainerBase::workClassFactoriesASC = NULL;
762 ContainerBase::WorkerClassList* ContainerBase::workClassFactoriesBI = NULL;
763 
764 
766 {
767  if ( getMap()->_resourcemode != 1 ) {
768  for ( WorkerClassList::iterator i = workClassFactoriesASC->begin(); i != workClassFactoriesASC->end(); ++i )
769  if ( (*i)->available( this ) )
770  return (*i)->produce(this, justQuery);
771  } else {
772  for ( WorkerClassList::iterator i = workClassFactoriesBI->begin(); i != workClassFactoriesBI->end(); ++i )
773  if ( (*i)->available( this ) )
774  return (*i)->produce(this, justQuery);
775  }
776  return NULL;
777 }
778 
779 
780 
Vehicle * findUnit(int nwid, bool recursive=true) const
searches for a the unit in carrier and optionally all inner carriers
The base class for buildings and vehicles.
int getVehicleTypeNum()
Definition: gamemap.cpp:1856
int defaultMaxResearchpoints
when a building of this type is placed on a map, its maxResearch property will be set to this value ...
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
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.
int maxLoadableUnits
the maximum number of units that can be loaded
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...
map accessing and usage routines used by ASC and the mapeditor
Resources getResourceUsage()
returns the resource that the building consumes for its operation.
int getresource(int x, int y, int resource, int _player, int _scope)
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 isHostile(PlayerID towardsPlayer) const
Definition: player.h:80
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
void setnewposition(int x, int y)
checks whether the unit can construct a building of the given type.
Definition: vehicle.cpp:808
int repairItem(ContainerBase *item, int newDamage=0, bool autoRepair=false)
Resources getResourcePlus()
void blit(const Surface &src, Surface &dst, SPoint dstPos)
Definition: blitter.h:349
bool checkModificationConstraints(const ContainerBase *container)
checks if a modification is allowed under the current circumstances A player may for example not alte...
int getheightdelta(const ContainerBase *c1, const ContainerBase *c2)
calculate the height difference between two levels of height.
Definition: spfst.cpp:393
virtual ASCString getName() const =0
virtual void write(tnstream &stream, bool includeLoadedUnits=true) const =0
NullParamType nullParam
Definition: blitter.cpp:30
ColorTransform_UnitGray(NullParamType npt=nullParam)
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
ResourceMatrix productionEfficiency
Resources getStorageCapacity() const
returns the local storage capacity for the given resource, which depends on the resource mode of the ...
DiplomaticStateVector diplomacy
Definition: player.h:209
bool hasFunction(ContainerFunctions function) const
int getOwner() const
returns the number of the player this vehicle/building belongs to
void deleteAllProductionLines()
int weight(void) const
weight of unit including cargo
Definition: vehicle.cpp:395
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
int getNumericalHeight() const
Definition: typen.h:242
sigc::signal< void > cargoChanged
virtual bool isBuilding() const =0
ppixelxlattable xlatpictgraytable
Definition: palette.cpp:35
ASCString getPrivateName() const
bool vehicleFit(const VehicleType *type) const
can units of the given type be moved into this buildtype? This is a prerequisite - but not the only r...
static int calcShadowDist(int binaryHeight)
virtual Resources getPlus()=0
ColorTransform_UnitGray(NullParamType npt=nullParam)
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
vector< IntRange > vehiclesInternallyProduceable
the default production capabilities of this container.
int view
the visibility range
Handling the connection of buildings by pipelines, powerlines etc.
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.
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
TemporaryContainerStorage(ContainerBase *_cb, bool storeCargo=false)
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
const int minimumBuildingDamageForConquering
if a building has at least this amount of damage, then any unit can conquer the build (and not only u...
Definition: typen.h:492
const int resourceTypeNum
The number of different resources that ASC uses.
Definition: typen.h:77
int vehicleUnloadable(const VehicleType *vehicleType, int carrierHeight) const
checks the unloading of a unit type
bool hasAnyFunction(std::bitset< 64 > functions) const
Resources getProductionCost(const VehicleType *unit) const
const int directionangle[sidenum]
Definition: typen.cpp:81
int movemalustyp
The category of the unit. Original used only to distinguish only between different movement costs for...
Definition: vehicletype.h:206
Reads data from or writes data to a MemoryStreamStorage This allows a completely volatile storage of ...
Definition: basestrm.h:204
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
EntranceSystems entranceSystems
int _resourcemode
how are Resources handled on this map 0= "ASC mode": complex system with mineral resources etc 1= "BI...
Definition: gamemap.h:250
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)
VehicleType * getvehicletype_bypos(int pos)
Definition: gamemap.cpp:1831
Resources returnResourcenUseForResearch(const ContainerBase *bld, int research)
Calculates the resources that are needed to research the given number of research.
Definition: research.cpp:937
#define chfahrend
Definition: typen.h:413
SDLmm::SPoint SPoint
Definition: surface.h:27
Player player[9]
Definition: gamemap.h:253
Resources plus
the Resources that are produced each turn
const int resourceNum
The number of different resources that ASC uses.
Definition: typen.h:79
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
Resources getStorageCapacity(int mode) const
returns the Storage capacity of the unit
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
int height
the levels of height which this unit can enter
bool hasProductionLine(const VehicleType *type)
const ContainerBaseType::TransportationIO * vehicleUnloadSystem(const VehicleType *vehicle, int height)
returns the unloading system
int color
The owner of the container.
int nominalresearchpoints
the number of reseach points for which the plus settings apllies
bool doesVehicleFit(const Vehicle *vehicle) const
Does the vehicle fit into the container? This does not include checking if it can reach the entry...
int & resource(int type)
Definition: typen.h:105
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.
int getBitmappedHeight() const
Definition: typen.h:241
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
const VehicleType * typ
Definition: vehicle.h:83
virtual void endAnyTurn(void)
hook that is called when any player (including owner) ends turn
bool isAllied(PlayerID towardsPlayer) const
Definition: player.h:82
bool attacked
did the unit already attack this turn
Definition: vehicle.h:109
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.
static const int count
Definition: typen.h:103
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)
GameMap * getMap() const
enum GameMap::State state
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
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
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
void megaBlitter(const Surface &src, Surface &dst, const SPoint &pos, const SourceColorTransformParameter &scmp=nullParam, const ColorMergerParameter &cmp=nullParam, const SourcePixelSelectorParameter spsp=nullParam, const TargetPixelSelectorParameter tpsp=nullParam)
Definition: blitter.h:410
int researchpoints
the current amount of research that the building conducts every turn
#define chgetaucht
Definition: typen.h:411
bool removeUnitFromCargo(Vehicle *veh, bool recursive=false)
removes the given unit from the container.
const Cargo & getCargo() const
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...
int minFieldRepairDamage
if the unit is repaired in the field (that is, not inside a transport or building), it can only be repaired up to this level 0 would result in a complete repair being possible, 20 that it can only be restored to 20% damage (80% health).
int maxLoadableWeight
the maximum total weight of all loaded units
void fatalError(const ASCString &string)
static sigc::signal< void, ContainerBase * > anyContainerDestroyed
void setInternalResourceMaxPlus(const Resources &res)
The ResourceMaxPlus is used for different purposes by different building or vehicle functions...
Resources defaultProduction
if a new building is constructed, this will be the resource production of the building ...
virtual void read(tnstream &stream)=0
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
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...
void unregisterPosition()
unregisters the unit at its current position (e.g. from a map field, or inside a transport) ...
Definition: vehicle.cpp:830
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