Advanced Strategic Command
buildings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  buildings.cpp - description
3  -------------------
4  begin : Sat Feb 17 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include <algorithm>
23 #include <cmath>
24 
25 #include "vehicletype.h"
26 #include "buildingtype.h"
27 #include "buildings.h"
28 #include "viewcalculation.h"
29 #include "errors.h"
30 #include "spfst.h"
31 #include "resourcenet.h"
32 #include "itemrepository.h"
33 #include "containercontrols.h"
34 #include "misc.h"
35 
36 
37 #ifndef BUILDINGVERSIONLIMIT
38 # define BUILDINGVERSIONLIMIT -1000000000
39 #endif
40 
41 
42 const float repairEfficiencyBuilding[resourceTypeNum*resourceTypeNum] = { 1./3., 0, 1. / 3. ,
43  0, 1./3., 0,
44  0, 0, 0 };
45 
46 Building :: Building ( GameMap* actmap, const MapCoordinate& _entryPosition, const BuildingType* type, int player, bool setupImages, bool chainToField )
47  : ContainerBase ( type, actmap, player ), typ ( type ), repairEfficiency ( repairEfficiencyBuilding )
48 {
49 
50  viewOnMap = false;
51 
52  int i;
53  for ( i = 0; i < 8; i++ )
54  aiparam[i] = NULL;
55 
56  _completion = 0;
57  connection = 0;
58 
59  lastmineddist= 0;
60 
61  for ( i = 0; i < waffenanzahl; i++ )
62  ammo[i] = 0;
63 
64  netcontrol = 0;
65 
66  visible = 1;
67  damage = 0;
68 
69  entryPosition = _entryPosition;
70 
71  gamemap->player[player].buildingList.push_back ( this );
72 
73  if ( chainToField )
74  chainbuildingtofield ( entryPosition, setupImages );
75 }
76 
77 
79 {
81  if ( d < 0 )
82  d = 0;
83  if ( d > damage )
84  d = damage;
85  return d;
86 }
87 
88 void Building::postRepair ( int oldDamage, bool autoRepair )
89 {
90  repairedThisTurn += oldDamage - damage;
91 }
92 
93 bool Building::canRepair ( const ContainerBase* item ) const
94 {
97  (item == this ) ;
98 }
99 
101 {
102  return -(getPosition().x + (getPosition().y << 16));
103 }
104 
105 void Building :: convert ( int player, bool recursive )
106 {
107  if (player > 8)
108  fatalError("convertbuilding: \n player must be in range 0..8 sein ");
109 
110  #ifdef sgmain
112  delete this;
113  return;
114  }
115 
116 
117  int oldnetcontrol = netcontrol;
119  Resources put = putResource( actstorage, false );
120  actstorage -= put;
121 
122  netcontrol = oldnetcontrol;
123 
124  #endif
125 
126  int oldcol = getOwner();
127 
128  #ifdef sgmain
129  if ( oldcol == 8 )
130  for ( int r = 0; r < 3; r++ )
131  if ( gamemap->isResourceGlobal( r )) {
132  gamemap->bi_resource[player].resource(r) += actstorage.resource(r);
133  actstorage.resource(r) = 0;
134  }
135 
136  #endif
137  bool hadViewOnMap = viewOnMap;
138  if ( color < 8*8 && hadViewOnMap)
139  removeview();
140 
141  Player::BuildingList::iterator i = find ( gamemap->player[oldcol].buildingList.begin(), gamemap->player[oldcol].buildingList.end(), this );
142  if ( i != gamemap->player[oldcol].buildingList.end())
143  gamemap->player[oldcol].buildingList.erase ( i );
144 
145  gamemap->player[player].buildingList.push_back( this );
146 
147  color = player * 8;
148 
149  if ( (hadViewOnMap && (player < 8)) || ( oldcol ==8 ) )
150  addview();
151 
152  if ( recursive )
153  for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
154  if ( *i )
155  (*i)->convert( player );
156 
157  conquered();
158  anyContainerConquered(this);
159 }
160 
161 
163 {
164  int oldcol = getOwner();
165 
166  if ( oldcol < 8 )
167  removeview();
168 
169  Player::BuildingList::iterator i = find ( gamemap->player[oldcol].buildingList.begin(), gamemap->player[oldcol].buildingList.end(), this );
170  if ( i != gamemap->player[oldcol].buildingList.end())
171  gamemap->player[oldcol].buildingList.erase ( i );
172 
173  gamemap->player[player].buildingList.push_back( this );
174 
175  color = player * 8;
176 
177  if ( player < 8 )
178  addview();
179 
180  conquered();
181  anyContainerConquered(this);
182 
183 }
184 
185 
186 
187 
188 const Surface& Building :: getPicture ( const BuildingType::LocalCoordinate& localCoordinate ) const
189 {
190  static Surface emptySurface;
191  MapField* fld = getField ( localCoordinate );
192  if ( fld ) {
193  return typ->getPicture(localCoordinate, fld->getWeather(), _completion);
194  } else
195  return emptySurface;
196 }
197 
199 {
200  if ( getHeight() <= chfahrend )
201  paintField( getPicture( pos ), s, imgpos, 0, false, 0 );
202  else
203  paintField( getPicture( pos ), s, imgpos, 0, false );
204 }
205 
206 
207 
208 // fucking namespace pollution, we are defining our own...
209 
210 template<typename T>
211 T ASC_min ( T a, T b )
212 {
213  if ( a > b )
214  return b;
215  else
216  return a;
217 }
218 template<typename T>
219 T ASC_max ( T a, T b )
220 {
221  if ( a > b )
222  return a;
223  else
224  return b;
225 }
226 
227 
228 
230 {
231  int minx = maxint;
232  int maxx = 0;
233  int maxy = 0;
234  int miny = maxint;
235 
236  for ( int x = 0; x < 4; x++ )
237  for ( int y = 0; y < 6; y++ )
239  SPoint pos ( x * fielddistx + ( y & 1 ) * fielddisthalfx, y * fielddisty);
240  minx = ASC_min( minx, int(pos.x) );
241  maxx = ASC_max( maxx, int(pos.x) + fieldsizex );
242  miny = ASC_min ( miny, int(pos.y) );
243  maxy = ASC_max ( maxy, int(pos.y) + fieldsizey );
244  }
245 
246  Surface s = Surface::createSurface(maxx-minx+1,maxy-miny+1, 32,Surface::transparent << 24 );
247 
248  typ->paint ( s, SPoint(-minx,-miny), getOwningPlayer().getPlayerColor() );
249  return s;
250 }
251 
252 #ifndef sgmain
253 void Building :: execnetcontrol ( void ) {}
254 int Building :: putResource ( int amount, int resourcetype, bool queryonly, int scope, int player ) { return 0; };
255 int Building :: getResource ( int amount, int resourcetype, bool queryonly, int scope, int player ) { return actstorage.resource(resourcetype); };
256 int Building :: getAvailableResource ( int amount, int resourcetype, int scope ) const { return actstorage.resource(resourcetype); };
257 #endif
258 
259 void Building :: setCompletion ( int completion, bool setupImages )
260 {
261  _completion = completion;
262 }
263 
264 
265 
266 
267 
268 int Building :: chainbuildingtofield ( const MapCoordinate& entryPos, bool setupImages )
269 {
270  MapCoordinate oldpos = entryPosition;
271  entryPosition = entryPos;
272 
273  for ( int a = 0; a < 4; a++)
274  for ( int b = 0; b < 6; b++)
275  if ( typ->fieldExists ( BuildingType::LocalCoordinate( a, b) )) {
277  if ( !f || f->building ) {
278  entryPosition = oldpos;
279  return 1;
280  }
281  }
282 
283  for ( int a = 0; a < 4; a++)
284  for ( int b = 0; b < 6; b++)
285  if ( typ->fieldExists ( BuildingType::LocalCoordinate( a , b ) )) {
287 
288  if ( visible ) {
289  MapField::ObjectContainer::iterator i = field->objects.begin();
290  while ( i != field->objects.end()) {
291  if ( !i->typ->canExistBeneathBuildings )
292  i = field->objects.erase ( i );
293  else
294  i++;
295  };
296  }
297 
298  if ( field->vehicle && (field->vehicle->height < chtieffliegend )) {
299  delete field->vehicle;
300  field->vehicle = NULL;
301  }
302 
303  field->building = this;
304  }
305 
306  for ( Cargo::iterator i = cargo.begin(); i != cargo.end(); ++i )
307  if ( *i )
308  (*i)->setnewposition ( entryPos.x, entryPos.y );
309 
310  MapField* field = getField( typ->entry );
311  if ( field )
313 
314  if ( setupImages )
316 
317 
318  for ( int a = 0; a < 4; a++)
319  for ( int b = 0; b < 6; b++)
323  if ( lc.x != a || lc.y!= b )
324  warningMessage( "bug in building coordinate calculation");
325  }
326 
327 
328  return 0;
329 }
330 
331 
333 {
334  int set = 0;
335  for (int i = 0; i <= 3; i++)
336  for (int j = 0; j <= 5; j++)
339  if ( fld && fld->building == this ) {
340  set = 1;
341  fld->building = NULL;
342 
344  t.flip();
345  fld->bdt &= t;
346  }
347  }
348 
349  return set;
350 }
351 
352 
353 void Building :: addview ( void )
354 {
355  if ( viewOnMap )
356  fatalError ("void Building :: addview - the building is already viewing the map");
357 
358  viewOnMap = true;
359 
361  bes.init( this, +1 );
362  bes.startsearch();
363 }
364 
366 {
367  viewOnMap = false;
368 }
369 
370 
372 {
373  if ( color != 64 ) {
374  if ( !viewOnMap )
375  fatalError ("void Building :: removeview - the building is not viewing the map");
376 
378  bes.init( this, -1 );
379  bes.startsearch();
380 
381  viewOnMap = false;
382  }
383 }
384 
386 {
388  MapCoordinate3D p3;
389  p3.setnum ( e.x, e.y, -1 );
390  return p3;
391 }
392 
393 int Building :: getArmor ( ) const
394 {
396 }
397 
398 
400 {
401  return gamemap->getField ( getFieldCoordinates ( lc ));
402 }
403 
404 
406 {
407  return getField ( typ->entry );
408 }
409 
411 {
412  return MapCoordinate3D( entryPosition, typ->height);
413 }
414 
415 
416 
418 {
419  return typ->getFieldCoordinate ( entryPosition, lc );
420 }
421 
422 
424 {
425  return typ->getLocalCoordinate( entryPosition, field );
426 }
427 
428 
430 {
431  if ( gamemap ) {
432  int c = color/8;
433 
434  Player::BuildingList::iterator i = find ( gamemap->player[c].buildingList.begin(), gamemap->player[c].buildingList.end(), this );
435  if ( i != gamemap->player[c].buildingList.end() )
436  gamemap->player[c].buildingList.erase ( i );
437  }
438 
439  for ( int i = 0; i < 8; ++i ) {
440  delete aiparam[ i ] ;
441  aiparam[ i ] = NULL;
442  }
443 
445 }
446 
447 
448 const int buildingstreamversion = -7;
449 
450 
451 void Building :: write ( tnstream& stream, bool includeLoadedUnits ) const
452 {
453  stream.writeInt ( max( buildingstreamversion, BUILDINGVERSIONLIMIT ));
454 
455  stream.writeInt ( typ->id );
456  int i;
457  for ( i = 0; i< resourceTypeNum; i++ )
458  stream.writeInt ( bi_resourceplus.resource(i) );
459  stream.writeUint8 ( color );
460  stream.writeWord ( getEntry().x );
461  stream.writeWord ( getEntry().y );
462  stream.writeUint8 ( getCompletion() );
463  for ( i = 0; i < waffenanzahl; i++ )
464  stream.writeWord ( 0 ); // was: ammoautoproduction
465 
466  for ( i = 0; i< resourceTypeNum; i++ )
467  stream.writeInt ( plus.resource(i) );
468 
469  for ( i = 0; i< resourceTypeNum; i++ )
470  stream.writeInt ( maxplus.resource(i) );
471 
472  for ( i = 0; i< resourceTypeNum; i++ )
473  stream.writeInt ( actstorage.resource(i) );
474 
475  for ( i = 0; i< waffenanzahl; i++ )
476  stream.writeWord ( ammo[i] );
477 
478  stream.writeWord ( maxresearchpoints );
479  stream.writeWord ( researchpoints );
480  stream.writeUint8 ( visible );
481  stream.writeUint8 ( damage );
482  stream.writeInt ( netcontrol );
483  stream.writeString ( name );
484 
485  stream.writeInt ( repairedThisTurn );
486 
487  int c = 0;
488 
489  if ( includeLoadedUnits )
490  for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
491  if ( *i )
492  ++c;
493 
494  if ( BUILDINGVERSIONLIMIT >= -3 )
495  stream.writeUint8( c );
496  else
497  stream.writeInt ( c );
498 
499  if ( c )
500  for ( Cargo::const_iterator i = cargo.begin(); i != cargo.end(); ++i )
501  if ( *i )
502  (*i)->write ( stream );
503 
504 
505  if ( BUILDINGVERSIONLIMIT >= -4 )
506  stream.writeUint8( internalUnitProduction.size() );
507  else
508  stream.writeInt( internalUnitProduction.size() );
509 
510  for (int k = 0; k < internalUnitProduction.size(); k++ ) {
511  assert( internalUnitProduction[k] );
512  stream.writeInt( internalUnitProduction[k]->id );
513  }
514 
515  if ( BUILDINGVERSIONLIMIT >= -3 )
516  stream.writeUint8(0);
517 
518  stream.writeInt( view );
519  stream.writeString( privateName );
520 }
521 
522 
523 Building* Building::newFromStream ( GameMap* gamemap, tnstream& stream, bool chainToField )
524 {
525  int version = stream.readInt();
526  int xpos, ypos, color;
527  Resources res;
528 
529  BuildingType* typ;
530 
531  if ( version < buildingstreamversion )
532  throw tinvalidversion( stream.getDeviceName(), buildingstreamversion, version );
533 
534  if ( version >= buildingstreamversion && version <= -1 ) {
535 
536  int id = stream.readInt ();
537  typ = gamemap->getbuildingtype_byid ( id );
538  if ( !typ )
539  throw InvalidID ( "building", id );
540 
541  for ( int i = 0; i < 3; i++ )
542  res.resource(i) = stream.readInt();
543 
544  color = stream.readUint8();
545  xpos = stream.readWord() ;
546  } else {
547  int id = version;
548 
549  typ = gamemap->getbuildingtype_byid ( id );
550  if ( !typ )
551  throw InvalidID ( "building", id );
552 
553  color = stream.readUint8();
554  xpos = stream.readWord();
555  }
556 
557  ypos = stream.readWord();
558 
559  Building* bld = new Building ( gamemap, MapCoordinate(xpos,ypos), typ, color/8, false, chainToField );
560  bld->bi_resourceplus = res;
561  bld->readData ( stream, version );
562  return bld;
563 }
564 
565 
566 
567 void Building:: read ( tnstream& stream )
568 {
569  int version = stream.readInt();
570 
571  if ( version >= buildingstreamversion && version <= -1 ) {
572  stream.readInt (); // id
573  for ( int i = 0; i < 3; i++ )
574  bi_resourceplus.resource(i) = stream.readInt();
575 
576  stream.readUint8(); // color
577  stream.readWord(); // xpos
578  stream.readWord(); // ypos
579  } else {
580  // int id = version;
581  stream.readUint8(); // color
582  stream.readWord(); // xpos
583  stream.readWord(); // ypos
584  bi_resourceplus = Resources ( 0, 0, 0);
585  }
586 
587  readData ( stream, version );
588 }
589 
590 
591 void Building :: readData ( tnstream& stream, int version )
592 {
593  setCompletion ( stream.readUint8(), false );
594 
595  int i;
596  for ( i = 0; i < waffenanzahl; i++)
597  stream.readWord(); // was : ammoautoproduction
598 
599  for ( i = 0; i< 3; i++ )
600  plus.resource(i) = stream.readInt();
601 
602  for ( i = 0; i< 3; i++ )
603  maxplus.resource(i) = stream.readInt();
604 
605 
606  for ( i = 0; i< 3; i++ )
608 
609  for ( i = 0; i < waffenanzahl; i++)
610  ammo[i] = stream.readWord();
611 
612  maxresearchpoints = stream.readWord();
613  researchpoints = stream.readWord();
614 
617 
618 
619  visible = stream.readUint8();
620  damage = stream.readUint8();
621 
622  netcontrol = stream.readInt();
623  netcontrol = 0;
624 
625  name = stream.readString ();
626 
627  if ( version <= -2 )
628  repairedThisTurn = stream.readInt ( );
629  else
630  repairedThisTurn = 0;
631 
632  int c;
633  if ( version <= -4 )
634  c = stream.readInt();
635  else
636  c = stream.readUint8();
637 
638  if ( c ) {
639  for ( int k = 0; k < c; k++) {
640  Vehicle* v = Vehicle::newFromStream ( gamemap, stream );
641  v->setnewposition ( getEntry().x, getEntry().y );
642  addToCargo(v);
643 
645  v->reactionfire.disable();
646 
647  }
648  }
649 
650 
651  internalUnitProduction.clear();
652  if ( version <= -5 )
653  c = stream.readInt();
654  else
655  c = stream.readUint8();
656 
657  if ( c ) {
658  for ( int k = 0; k < c ; k++) {
659 
660  int id;
661  if ( version <= -3 )
662  id = stream.readInt();
663  else
664  id = stream.readWord();
665 
666  internalUnitProduction.push_back ( gamemap->getvehicletype_byid ( id ) );
667  if ( !internalUnitProduction[k] )
668  throw InvalidID ( "unit", id );
669  }
670  }
671 
672  if ( version >= -3 ) {
673  c = stream.readUint8();
674  if ( c ) {
675  for ( int k = 0; k < c ; k++) {
676  if ( version <= -3 )
677  stream.readInt();
678  else
679  stream.readWord();
680  }
681  }
682  }
683 
684  for ( i = 0; i< 3; i++ ) {
685  if ( typ->maxplus.resource(i) > 0 ) {
686  if ( plus.resource(i) > typ->maxplus.resource(i) )
687  plus.resource(i) = typ->maxplus.resource(i);
688 
689  if ( maxplus.resource(i) > typ->maxplus.resource(i) )
691  } else {
692  if ( plus.resource(i) < typ->maxplus.resource(i) )
693  plus.resource(i) = typ->maxplus.resource(i);
694 
695  if ( maxplus.resource(i) < typ->maxplus.resource(i) )
697  }
698  }
699 
700  if ( version <= -6 )
701  view = stream.readInt();
702  else
703  view = typ->view;
704 
705  if ( version <= -7 )
706  privateName = stream.readString();
707  else
708  privateName = "";
709 }
710 
712 {
713  if ( name.empty())
714  return typ->name;
715  else
716  return name;
717 }
718 
719 int Building::getAmmo( int type, int num, bool queryOnly )
720 {
721  assert( type >= 0 && type < waffenanzahl );
722  int got = min( ammo[type], num );
723  if ( !queryOnly ) {
724  ammo[type] -= got;
725  // ammoChanged();
726  }
727  return got;
728 }
729 
730 int Building::getAmmo( int type, int num ) const
731 {
732  assert( type >= 0 && type < waffenanzahl );
733  return min( ammo[type], num );
734 }
735 
736 
737 int Building::putAmmo( int type, int num, bool queryOnly )
738 {
739  assert( type >= 0 && type < waffenanzahl );
740  if ( !queryOnly ) {
741  ammo[type] += num;
742  // ammoChanged();
743  }
744  return num;
745 }
746 
747 
748 
749 
751 {
753  repairedThisTurn = 0;
754 }
755 
756 
757 vector<MapCoordinate> Building::getCoveredFields()
758 {
759  vector<MapCoordinate> fields;
760  for ( int x = 0; x < 4; x++ )
761  for ( int y = 0; y < 6; y++)
763  fields.push_back ( getFieldCoordinates( BuildingType::LocalCoordinate(x, y)));
764  return fields;
765 }
766 
767 
769 {
770  return sizeof(*this);
771 }
772 
773 
774 
775 /*
776 void Building :: getresourceusage ( Resources* usage )
777 {
778  returnresourcenuseforpowerplant ( this, 100, usage, 0 );
779  if ( typ->special & cgresearchb ) {
780  int material;
781  int energy;
782  returnresourcenuseforresearch ( this, researchpoints, &energy, &material );
783  usage->material += material;
784  usage->energy += energy;
785  usage->fuel = 0;
786  }
787 }
788 */
789 
790 
791 
793  float eff;
795  bool operator<( const ResearchEfficiency& re) const { return eff > re.eff; };
796  };
797 
798 
799 void doresearch ( GameMap* actmap, int player )
800 {
801  Research& research = actmap->getPlayer(player).research;
802 
803  if ( research.activetechnology == NULL && research.progress ) {
804  // we don't accumulate research if there is not technology to research
805  // this is to prevent player from accumulating lots of unused research points and then
806  // developing several technologies at once
807  return;
808  }
809 
810 
811  typedef vector<ResearchEfficiency> VRE;
812  VRE vre;
813 
814  for ( Player::BuildingList::iterator bi = actmap->player[player].buildingList.begin(); bi != actmap->player[player].buildingList.end(); bi++ ) {
815  Building* bld = *bi;
818 
819  int m = max ( res.energy, max ( res.material, res.fuel));
820 
822  if ( m )
823  re.eff = float(bld->researchpoints) / float(m);
824  else
825  re.eff = maxint;
826 
827  re.bld = bld;
828 
829  vre.push_back(re);
830  } else
831  if ( bld->researchpoints > 0 )
832  research.progress += bld->researchpoints * research.getMultiplier();
833  }
834  sort( vre.begin(), vre.end());
835 
836  for ( VRE::iterator i = vre.begin(); i != vre.end(); ++i ) {
837  Building* bld = i->bld;
839  Resources got = bld->getResource ( r, true, 1, player );
840 
841  int res = bld->researchpoints;
842  if ( got < r ) {
843  int diff = bld->researchpoints / 2;
844  while ( got < r || diff > 1) {
845  if ( got < r )
846  res -= diff;
847  else
848  res += diff;
849 
850  if ( res < 0 )
851  res = 0;
852 
853  if ( diff > 1 )
854  diff /=2;
855  else
856  diff = 1;
857 
858  r = returnResourcenUseForResearch ( bld, res );
859  }
860 
861  /*
862  res = returnResourcenUseForResearch ( bld, res+1 );
863 
864  if ( ena >= energy && maa >= material )
865  res++;
866  else
867  returnresourcenuseforresearch ( bld, res, &energy, &material );
868  */
869 
870  }
871 
872  got = bld->getResource ( r, false, 1, player );
873 
874  if ( got < r )
875  fatalError( "controls : doresearch : inconsistency in getting energy or material for building" );
876 
877  research.progress += res * research.getMultiplier();
878  }
879 }
880 
882 {
883  ASCString s = "The building " + bld->getName();
884  s += " (position: "+ bld->getPosition().toString() + ") ";
885  return s;
886 }
887 
bool operator<(const ResearchEfficiency &re) const
Definition: buildings.cpp:795
int getIdentification() const
Definition: buildings.cpp:100
int fuel
Definition: typen.h:101
bool canRepair(const ContainerBase *item) const
checks whether the item can be repaired provided that it is in range
Definition: buildings.cpp:93
The (base-) classes which are thrown as exceptions.
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
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 void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
MapCoordinate getFieldCoordinate(const MapCoordinate &entryOnMap, const LocalCoordinate &localCoordinate) const
returns the Mapcoordinate of a buildings field
map accessing and usage routines used by ASC and the mapeditor
const BuildingType * typ
Definition: buildings.h:48
miscellaneous functions which are used by ASC and all its tools
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
const float repairEfficiencyBuilding[resourceTypeNum *resourceTypeNum]
Definition: buildings.cpp:42
Vehicle * vehicle
Definition: mapfield.h:89
const int waffenanzahl
The number of different weapon types.
Definition: typen.h:58
int energy
Definition: typen.h:99
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
ASCString getName() const
returns a name for the building. If the building itself has a name, it will be returned. If it doesn't, the name of the building type will be returned.
Definition: buildings.cpp:711
void paintSingleField(Surface &s, SPoint imgpos, BuildingType::LocalCoordinate pos) const
Definition: buildings.cpp:198
ASCString toString(bool coordinates=false) const
Definition: typen.cpp:314
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
virtual ASCString getDeviceName()
returns the name of the stream.
Definition: basestrm.cpp:269
MapCoordinate getFieldCoordinates(const BuildingType::LocalCoordinate &localCoordinates) const
returns the absolute map coordinate of the given part of the building
Definition: buildings.cpp:417
int chainbuildingtofield(const MapCoordinate &entryPos, bool setupImages=true)
registers the building at the given position on the map
Definition: buildings.cpp:268
T ASC_min(T a, T b)
Definition: buildings.cpp:211
static const Uint32 transparent
Definition: surface.h:65
Resources getStorageCapacity() const
returns the local storage capacity for the given resource, which depends on the resource mode of the ...
bool hasFunction(ContainerFunctions function) const
int getOwner() const
returns the number of the player this vehicle/building belongs to
void read(tnstream &stream)
Definition: buildings.cpp:567
A local coordinate referencing a single field that a building covers.
Definition: buildingtype.h:57
MapCoordinate3D getEntry() const
returns the position of the buildings entry
Definition: buildings.cpp:410
void removeview()
Removes the view and jamming of the building from the player's global radar field.
Definition: buildings.cpp:371
static sigc::signal< void, ContainerBase * > anyContainerConquered
virtual int readWord(void)
Reads a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is ...
Definition: basestrm.cpp:291
BuildingType::LocalCoordinate getLocalCoordinate(const MapCoordinate &field) const
converts a global coordinate into a local coordinate.
Definition: buildings.cpp:423
void warningMessage(const ASCString &str)
static Surface createSurface(int width, int height, SDLmm::Color color=255)
Definition: surface.cpp:387
The buildings which a placed on the map.
The interface for all kinds of IO stream.
a single field of the map
Definition: mapfield.h:26
int getCompletion() const
returns the completion of the building.
Definition: buildings.h:164
MapField * getEntryField() const
returns the field the buildings entry is standing on
Definition: buildings.cpp:405
int getAmmo(int type, int num, bool queryOnly)
Definition: buildings.cpp:719
int netcontrol
a bitmapped variable containing the status of the resource-net connection.
Definition: buildings.h:57
virtual Uint8 readUint8(void)
Reads a 8 bit unsigned Integer.
Definition: basestrm.cpp:305
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
Production internalUnitProduction
Definition: containerbase.h:99
int getAvailableResource(int amount, int resourcetype, int scope=1) const
Definition: controls.cpp:260
int getMemoryFootprint() const
Definition: buildings.cpp:768
int view
the visibility range
Handling the connection of buildings by pipelines, powerlines etc.
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
int getWeather()
the weather that is on this field
Definition: mapfield.cpp:370
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
#define fieldsizey
Definition: typen.h:441
#define fielddisthalfx
Definition: typen.h:435
bool fieldExists(const LocalCoordinate &localCoordinate) const
returns whether this building covers the given field
Definition: buildingtype.h:108
class Vehicle::ReactionFire reactionfire
Player & getOwningPlayer() const
returns the player this vehicle/building belongs to
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
Resources bi_resource[8]
in BI resource mode ( see _resourcemode , isResourceGlobal ) , this is where the globally available r...
Definition: gamemap.h:416
T ASC_max(T a, T b)
Definition: buildings.cpp:219
TerrainBits getTerrainBitType(TerrainBitTypes tbt)
virtual int repairableDamage() const
returns the amount of damage that can still be repaired this turn
Definition: buildings.cpp:78
the properties of a terrain describing which units can move onto this field and which can't ...
Definition: terraintype.h:32
const int resourceTypeNum
The number of different resources that ASC uses.
Definition: typen.h:77
void endRound(void)
hook that is called when a turn ends
Definition: buildings.cpp:750
int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
Definition: controls.cpp:226
virtual Surface getImage() const
returns an image for the Container.
Definition: buildings.cpp:229
#define chtieffliegend
Definition: typen.h:414
const Technology * activetechnology
the technology that is currently being researched
Definition: research.h:191
Coordinate on the twodimensional map.
Definition: typen.h:202
void resetview()
resets the internal view state, so that addview() can be executed again
Definition: buildings.cpp:365
MapField * getField(const BuildingType::LocalCoordinate &localCoordinates) const
returns the pointer to the field which the given part of the building is standing on ...
Definition: buildings.cpp:399
int unchainbuildingfromfield(void)
unregister the building from the map position
Definition: buildings.cpp:332
bool isResourceGlobal(int resource)
Definition: gamemap.cpp:1024
virtual void postRepair(int oldDamage, bool autoRepair)
is called after a repair is performed. Vehicles use this to reduce their experience.
Definition: buildings.cpp:88
virtual void writeUint8(Uint8 c)
Writes a 8 bit unsigned Integer.
Definition: basestrm.cpp:380
int ammo[waffenanzahl]
the ammo that is stored in the building
Definition: buildings.h:50
The interface for the buildingtype class.
void setnum(int _x, int _y, int numericalz)
Definition: typen.h:250
void paint(Surface &s, SPoint pos, const PlayerColor &player, int weather=0, int constructionStep=0) const
virtual void startsearch(void)
Resources maxplus
the maximum amount of Resources that the building can produce each turn in the ASC resource mode ; se...
void execnetcontrol(void)
executes the resource net operations, like filling the tanks with fuel.
Definition: controls.cpp:194
int material
Definition: typen.h:100
void setCompletion(int completion, bool setupImages=true)
Sets the level of completion of the building.
Definition: buildings.cpp:259
int putAmmo(int type, int num, bool queryOnly)
Definition: buildings.cpp:737
const Surface & getPicture(const LocalCoordinate &localCoordinate, int weather=0, int constructionStep=0) const
Resources returnResourcenUseForResearch(const ContainerBase *bld, int research)
Calculates the resources that are needed to research the given number of research.
Definition: research.cpp:937
VehicleType * getvehicletype_byid(int id)
Definition: gamemap.cpp:1794
BuildingType * getbuildingtype_byid(int id)
Definition: gamemap.cpp:1805
#define fieldsizex
Definition: typen.h:440
#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
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
static Vehicle * newFromStream(GameMap *gamemap, tnstream &stream, int forceNetworkID=-1)
generates a new unit, loads its parameters from the stream (where they have been previously written w...
Definition: vehicle.cpp:1728
int getHeight() const
returns the bitmapped level of height. Only one bit will be set, of course
Definition: buildings.h:187
const int buildingstreamversion
Definition: buildings.cpp:448
TerrainBits bdt
the terraintype properties. They determine which units can move over the field. This variable is reca...
Definition: mapfield.h:161
int connection
bitmapped: are there events that are triggered by actions affecting this building ...
Definition: buildings.h:60
void doresearch(GameMap *actmap, int player)
Definition: buildings.cpp:799
#define fielddistx
Definition: typen.h:433
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
#define cnet_stopenergyinput
Definition: typen.h:517
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
int lastmineddist
Definition: buildings.h:72
int height
the levels of height which this unit can enter
BuildingList buildingList
a list of all units
Definition: player.h:139
Resources actstorage
the current storage of Resources
Definition: buildings.h:91
int _armor
the armor of the buildingtype.
Definition: buildingtype.h:80
Resources bi_resourceplus
the maximum amount of Resources that the building can produce each turn in the BI resource mode ; see...
void convert(int player, bool recursive=true)
changes the building's owner.
Definition: buildings.cpp:105
int color
The owner of the container.
Research research
the status of the scientific research
Definition: player.h:142
int & resource(int type)
Definition: typen.h:105
void calculateAllObjects(void)
Definition: gamemap.cpp:1002
void addToCargo(Vehicle *veh, int position=-1)
adds the unit to the cargo
ASCString getBuildingReference(Building *bld)
Definition: buildings.cpp:881
const Surface & getPicture(const BuildingType::LocalCoordinate &localCoordinate) const
returns the picture of the building. It may depend on the current weather of the fields the building ...
Definition: buildings.cpp:188
int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
Definition: controls.cpp:243
MapCoordinate3D getPosition3D() const
returns the position of the buildings entry
Definition: buildings.cpp:385
Coordinate on the map including height.
Definition: typen.h:238
Building * building
Definition: mapfield.h:102
virtual void endRound(void)
hook that is called the next round begins ( active player switching from player8 to player1 ) ...
virtual void writeWord(int w)
Writes a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is...
Definition: basestrm.cpp:369
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
#define maxint
Definition: typen.h:462
sigc::signal< void > conquered
GameMap * actmap
Definition: spfst.cpp:64
GameMap * getMap() const
int maxresearchpoints
the maximum number of research points a research center may produce
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
Status getStatus() const
for each player that can still be attacked one bit is set
Definition: vehicle.h:155
Resources are basically the currency of ASC.
Definition: typen.h:97
#define BUILDINGVERSIONLIMIT
Definition: buildings.cpp:38
int researchpoints
the current amount of research that the building conducts every turn
static Building * newFromStream(GameMap *gamemap, tnstream &stream, bool chainToField=true)
Definition: buildings.cpp:523
bool visible
is the building visible? Building can be made invisible, but this feature should be used only in some...
Definition: buildings.h:63
void fatalError(const ASCString &string)
int getArmor() const
returns the armor of the building.
Definition: buildings.cpp:393
int progress
Definition: research.h:189
LocalCoordinate entry
the position of the entrance, which is the field of the building where units can enter and leave ...
Definition: buildingtype.h:74
vector< MapCoordinate > getCoveredFields()
Definition: buildings.cpp:757
Building(GameMap *map, const MapCoordinate &entryPosition, const BuildingType *type, int player, bool setupImages=true, bool chainToField=true)
Definition: buildings.cpp:46
MapCoordinate3D getPosition() const
returns the position of the buildings entry
Definition: buildings.h:152
ASCString name
a short name, for example B-52
LocalCoordinate getLocalCoordinate(const MapCoordinate &entryOnMap, const MapCoordinate &field) const
converts a global coordinate into a local coordinate.
int getMultiplier()
Definition: research.h:232
#define fielddisty
Definition: typen.h:434
void addview()
Adds the view and jamming of the building to the player's global radar field.
Definition: buildings.cpp:353
void registerForNewOwner(int player)
this is a low level functions that changes the registration in the map. It's called by convert(int...
Definition: buildings.cpp:162
ObjectContainer objects
Definition: mapfield.h:124
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
MapField * getField(int x, int y)
Definition: gamemap.h:465
AiValue * aiparam[8]
Definition: buildings.h:65
void write(tnstream &stream, bool includeLoadedUnits=true) const
Definition: buildings.cpp:451
void init(const Building *bld, int _mode)