Advanced Strategic Command
containerbase-functions.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include <algorithm>
11 #include <cmath>
13 #include "typen.h"
14 #include "containercontrols.h"
15 #include "resourcenet.h"
16 #include <iostream>
17 
18 #include "tos.h"
19 
20 using namespace toString;
21 
22 
23 template <class T, ContainerBaseType::ContainerFunctions f>
25 {
26  bool available( const ContainerBase* cnt )
27  {
28  return cnt->baseType->hasFunction( f );
29  };
30 
31  ContainerBase::Work* produce( ContainerBase* cnt, bool queryOnly )
32  {
33  return new T(cnt);
34  };
35 };
36 
37 
39 {
40  bool available( const ContainerBase* cnt )
41  {
42  return true;
43  };
44 
45  ContainerBase::Work* produce( ContainerBase* cnt, bool queryOnly )
46  {
47  return new BiResourceGeneration(cnt);
48  };
49 };
50 
52 {
53  bool available( const ContainerBase* cnt )
54  {
56  };
57 
58  ContainerBase::Work* produce( ContainerBase* cnt, bool queryOnly )
59  {
60  return new MiningStation(cnt, queryOnly);
61  };
62 };
63 
65 {
66  bool available( const ContainerBase* cnt )
67  {
69  };
70 
71  ContainerBase::Work* produce( ContainerBase* cnt, bool queryOnly )
72  {
73  return new AutoHarvestObjects(cnt, queryOnly);
74  };
75 };
76 
77 namespace
78 {
86 }
87 
89 {
90  base = _bld;
91  justQuery = justQuery_;
92  hasRun = false;
93  fieldCounter = 0;
94 }
95 
97 {
98  return hasRun;
99 }
100 
101 
102 void AutoHarvestObjects::harvestObject( const MapCoordinate& pos, const ObjectType* obj )
103 {
104  MapField* currentField = base->getMap()->getField(pos);
105  if ( !currentField )
106  return;
107 
108  Object* object = currentField->checkForObject( obj );
109  if ( !object )
110  return;
111 
112  // we are only harvesting on fields who have non-harvestable neighbouring field,
113  // to prevent clearing of areas where the 'island' fields that are supposed to remain
114  // are not covered by the oject
115  int regrowFields = 0;
116  int spreadingFields = 0;
117  for ( int i = 0; i < 6; ++i ) {
118  MapCoordinate nextField = getNeighbouringFieldCoordinate( pos, i );
119  if ( !harvestOnPosition(nextField)) {
120  MapField* fld = base->getMap()->getField( nextField);
121  if ( fld ) {
122  if ( fld->checkForObject(obj))
123  ++regrowFields ;
124  else {
125  if ( obj->buildable(fld))
126  ++spreadingFields;
127  }
128  }
129  }
130  }
131  if ( regrowFields <= 0 || spreadingFields > 0 )
132  return;
133 
134 
135 
136  if( object != NULL ) {
137  Resources removeValue = object->typ->removecost;
138  Resources removeCost;
139  Resources removeBenefit;
140 
141  if( removeValue.energy < 0 )
142  removeBenefit.energy = -removeValue.energy;
143  else
144  removeCost.energy = removeValue.energy;
145 
146  if( removeValue.material < 0 )
147  removeBenefit.material = -removeValue.material;
148  else
149  removeCost.material = removeValue.material;
150 
151  if( removeValue.fuel < 0 )
152  removeBenefit.fuel = -removeValue.fuel;
153  else
154  removeCost.fuel = removeValue.fuel;
155 
156  if( base->getResource( removeCost, true, 1, base->getOwner() ) == removeCost ) {
157  cost += removeCost;
158  harvested += removeBenefit;
159  if( !justQuery ) {
160  base->getResource( removeCost, false, 1, base->getOwner());
161  base->putResource( removeBenefit, false, 1, base->getOwner() );
162  currentField->removeObject( obj, true );
163  }
164  ++fieldCounter;
165 
166  logMessage("ResourceWork", "AutoHarvester " + tos( base->getPosition() ) + ": harvested object " + tos(obj->id) + " on field " + tos(pos) + " and got " + removeBenefit.toString() );
167 
168  }
169  }
170 }
171 
172 void AutoHarvestObjects::processField( const MapCoordinate& pos )
173 {
174  MapField* currentField = base->getMap()->getField(pos);
175  if ( !currentField )
176  return;
177 
178  if ( currentField->building )
179  return;
180 
181  if ( fieldCounter >= base->baseType->autoHarvest.maxFieldsPerTurn )
182  return;
183 
184  for ( vector<IntRange>::const_iterator i = base->baseType->autoHarvest.objectsHarvestable.begin(); i != base->baseType->autoHarvest.objectsHarvestable.end(); ++i )
185  for( int id=i->from; id <= i->to; ++id ) {
186  const ObjectType *obj = base->getMap()->getobjecttype_byid( id );
187  if ( obj )
188  harvestObject( pos, obj );
189  }
190 
191  for ( vector<IntRange>::const_iterator i = base->baseType->autoHarvest.objectGroupsHarvestable.begin(); i != base->baseType->autoHarvest.objectGroupsHarvestable.end(); ++i )
192  for( int j = 0; j < base->getMap()->getObjectTypeNum(); ++j ) {
193  const ObjectType *obj = base->getMap()->getobjecttype_bypos( j );
194  if ( obj->groupID >= i->from && obj->groupID <= i->to )
195  harvestObject( pos, obj );
196  }
197 
198 }
199 
200 
201 
202 bool AutoHarvestObjects::harvestOnPosition( const MapCoordinate& pos )
203 {
204  if ((pos.y+1)%3)
205  return true;
206  else
207  return false;
208 }
209 
210 void AutoHarvestObjects::iterateField( const MapCoordinate& pos )
211 {
212  /*
213  if ( pos.y & 1 ) {
214  processField(pos);
215  return ;
216  } else {
217  if ( (((pos.y >> 1) & 1) && (pos.x & 1 )) || (((pos.y >> 1 ) & 1 )==0 && (pos.x & 1 )==0 )) {
218  processField(pos);
219  return;
220  }
221  }
222  */
223  if ( harvestOnPosition(pos ) )
224  // y+1 is to match the harvesting pattern of player Xyphagoroszh on PBP planet Lussx :)
225  processField(pos);
226 
227 }
228 
229 
230 
231 
233 {
234  hasRun = true;
235  if( base->getCarrier() != NULL )
236  return false;
237 
238  circularFieldIterator( base->getMap(), base->getPosition(), 0, base->baseType->autoHarvest.range, FieldIterationFunctor( this, &AutoHarvestObjects::iterateField ));
239 
240  return true;
241 }
242 
244 {
245  return harvested;
246 }
247 
249 {
250  return Resources();
251 }
252 
253 
254 float getminingstationeficency ( int dist )
255 {
256  // f ( x ) = a / ( b * ( x + d ) ) - c
257 
258  double a,b,c,d;
259 
260  a = 10426.400 ;
261  b = 1.0710969 ;
262  c = 568.88887 ;
263  d = 6.1111109 ;
264 
265  return (a / ( b * (dist + d)) - c) / 1024;
266 }
267 
268 
270 {
271  for ( int i = 0; i < maxminingrange+2; i++ )
272  efficiency[i] = 0;
273  nextMiningDistance = -1;
274 }
275 
276 GetMiningInfo :: GetMiningInfo ( const ContainerBase* container ) : SearchFields ( container->getMap() ), miningStation( container )
277 {
278  run();
279 }
280 
282 {
283  MapField* fld = gamemap->getField ( mc );
284  if ( miningInfo.efficiency[ dist ] == 0 )
286 
291  if ( miningInfo.nextMiningDistance == -1 ) {
292  if ( miningStation->maxplus.fuel > 0 && fld->fuel > 0 )
294 
295  if ( miningStation->maxplus.material > 0 && fld->material > 0 )
297  }
298 }
299 
300 
301 void GetMiningInfo :: run ()
302 {
303  initsearch ( miningStation->getPosition(), 0, maxminingrange );
304  startsearch();
305 }
306 
307 
308 
309 
310 MatterConverter :: MatterConverter( ContainerBase* _bld ) : bld ( _bld ), percentage ( 100 )
311 {}
312 
314 {
315  int perc = percentage;
316 
317  logMessage("ResourceWork", "MatterConverter " + tos( bld->getPosition() ) + ": still needs to do " + tos(perc) + "% of work");
318 
319 
320  int usageNum = 0;
321  for ( int r = 0; r < 3; r++ )
322  if ( bld->plus.resource(r) < 0 )
323  ++usageNum;
324 
325  if ( usageNum > 0 ) {
326  // if the resource generation requires other resources, don't waste anything
327  // by producing more than storage capacity available
328 
329  for ( int r = 0; r < 3; r++ )
330  if ( bld->plus.resource(r) > 0 ) {
331  int p = bld->putResource ( bld->plus.resource(r), r, true, 1, bld->getOwner() );
332 
333  if ( perc > 100 * p / bld->plus.resource(r) )
334  perc = 100 * p / bld->plus.resource(r) ;
335  }
336  }
337 
338  logMessage("ResourceWork", "MatterConverter " + tos(bld->getPosition()) + ": checked storage, limiting to " + tos(perc) + "% of work");
339 
340 
341  Resources toGet = bld->plus * perc / 100 ;
342  for ( int r = 0; r < 3; r++ )
343  if ( toGet.resource(r) < 0 )
344  toGet.resource(r) = - toGet.resource(r) ;
345  else
346  toGet.resource(r) = 0;
347 
348 
349  Resources avail = bld->getResource ( toGet, true, 1, bld->getOwner() );
350 
351  for ( int r = 0; r < 3; r++ ) {
352  if ( bld->plus.resource(r) < 0 ) {
353  int p = 100 * avail.resource(r) / -bld->plus.resource(r);
354  if ( p < perc )
355  perc = p;
356  }
357  }
358 
359  logMessage("ResourceWork", "MatterConverter " + tos( bld->getPosition() ) + ": checked required res, limiting to " + tos(perc) + "% of work");
360 
361  bool didSomething = false;
362 
363  for ( int r = 0; r < 3; r++ )
364  if ( bld->plus.resource(r) > 0 ) {
365  int toput = bld->plus.resource(r) * perc / 100;
366  int didput = bld->putResource( toput, r , false, 1, bld->getOwner() );
367  if ( toput > 0)
368  didSomething = true;
369 
370  logMessage("ResourceWork", "MatterConverter " + tos( bld->getPosition()) + ": generated " + tos(toput) + " of " + Resources::name(r) + ", successfully stored " + tos(didput) + " of it");
371 
372  } else {
373  if ( bld->plus.resource(r) < 0 ) {
374  int toget = -bld->plus.resource(r) * perc / 100;
375  int got = bld->getResource( toget, r , false, 1, bld->getOwner());
376  logMessage("ResourceWork", "MatterConverter " + tos( bld->getPosition()) + ": needed " + tos(toget) + " of " + Resources::name(r) + ", successfully got " + tos(got) + " of it");
377  }
378  }
379 
380 
381  percentage -= perc;
382 
383  logMessage("ResourceWork", "MatterConverter " + tos(bld->getPosition()) + ": did " + tos(perc) + "% of work, " + tos(percentage) + "% left");
384 
385  return didSomething;
386 }
387 
388 
390 {
391  return percentage == 0;
392 }
393 
395 {
396  Resources r;
397  for ( int i = 0; i < 3; i++ )
398  if ( bld->plus.resource(i) > 0 )
399  r.resource(i) = bld->plus.resource(i);
400  return r;
401 }
402 
404 {
405  Resources r;
406  for ( int i = 0; i < 3; i++ )
407  if ( bld->plus.resource(i) < 0 )
408  r.resource(i) = -bld->plus.resource(i);
409  return r;
410 }
411 
412 
414 {
415  toGet = bld->plus;
416  for ( int r = 0; r < 3; r++ )
417  if ( toGet.resource(r) < 0 )
418  toGet.resource(r) = - toGet.resource(r) ;
419  else
420  toGet.resource(r) = 0;
421 }
422 
424 {
425  Resources got = bld->getResource( toGet, false, 1, bld->getOwner() );
426  toGet -= got;
427  for ( int r = 0; r < 3; r++ )
428  if ( got.resource(r) > 0 )
429  return true;
430 
431  return false;
432 }
433 
434 
436 {
437  for ( int r = 0; r < 3; r++ )
438  if ( toGet.resource(r) > 0 )
439  return false;
440  return true;
441 }
442 
444 {
445  return Resources();
446 }
447 
449 {
450  Resources r;
451  for ( int i = 0; i < 3; i++ )
452  if ( bld->plus.resource(i) < 0 )
453  r.resource(i) = -bld->plus.resource(i);
454  return r;
455 }
456 
457 
458 /*
459 Research :: Research( Building* _bld ) : bld ( _bld ), percentage ( 100 )
460 {
461 }
462 
463 bool Research :: run()
464 {
465  int perc = percentage;
466 
467  int usageNum = 0;
468  for ( int r = 0; r < 3; r++ )
469  if ( plus.resource(r) < 0 )
470  ++usageNum;
471 
472  if ( usageNum > 0 ) {
473  // if the resource generation requires other resources, don't waste anything
474  // by producing more than storage capacity available
475 
476  for ( int r = 0; r < 3; r++ )
477  if ( bld->plus.resource(r) > 0 ) {
478  int p = putResource ( bld->plus.resource(r), 0, 1 );
479 
480  if ( perc > 100 * p / bld->plus.resource(r) )
481  perc = 100 * p / bld->plus.resource(r) ;
482 }
483 }
484 
485  Resources toGet = bld->plus * perc / 100 ;
486  for ( int r = 0; r < 3; r++ )
487  if ( toGet.resource(r) < 0 )
488  toGet.resource(r) = - toGet.resource(r) ;
489  else
490  toGet.resource(r) = 0;
491 
492 
493  Resources avail = bld->getResource ( toGet, 1 );
494 
495  for ( int r = 0; r < 3; r++ ) {
496  if ( bld->plus.resource(r) ) {
497  int p = 100 * avail.resource(r) / bld->plus.resource(r);
498  if ( p < perc )
499  perc = P;
500 }
501 }
502 
503 
504  bool didSomething = false;
505 
506  for ( int r = 0; r < 3; r++ )
507  if ( bld->plus.resource(r) > 0 ) {
508  bld->putResource( bld->plus.resource(r) * perc / 100, r , 0);
509  if ( bld->plus.resource(r) * perc / 100 > 0)
510  didSomething = true;
511 
512 } else {
513  bld->getResource( -bld->plus.resource(r) * perc / 100, r , 0);
514 }
515 
516  percentage = perc;
517  return didSomething;
518 }
519 
520 
521 bool Research :: finished()
522 {
523  return percentage == 0;
524 }
525 
526 Resources Research :: getUsage()
527 {
528  Resources r;
529  for ( int i = 0; i < 3; i++ 9
530  if ( bld->plus.resource(r) < 0 )
531  r.resource(r) = -bld->plus.resource(r)
532  return r;
533 }
534  **/
535 
537 {}
538 
540 {
541  for( int r = 0; r < 3; r++ )
542  if ( toProduce.resource(r) > 0 )
543  return false;
544  return true;
545 }
546 
548 {
549  Resources tp = bld->putResource( toProduce , false, 1, bld->getOwner() );
550  bool didSomething = false;
551  for ( int r = 0; r < 3; r++ )
552  if ( tp.resource(r) ) {
553  didSomething = true;
554  toProduce.resource(r) -= tp.resource(r);
555  }
556  return didSomething;
557 }
558 
560 {
561  return Resources();
562 }
563 
565 {
566  Resources p;
567  for ( int r = 0; r < 3; r++ )
568  p.resource(r) = bld->maxplus.resource(r) * bld->getMap()->weather.windSpeed / 255;
569  return p;
570 }
571 
573 {
574  int sum = 0;
575  int num = 0;
576  vector<MapCoordinate> fields = bld->getCoveredFields();
577  for ( vector<MapCoordinate>::iterator i = fields.begin(); i != fields.end(); ++i ) {
578  MapField* fld = bld->getMap()->getField ( *i );
579  int weather = 0;
580  while ( fld->typ != fld->typ->terraintype->weather[weather] )
581  weather++;
582 
583  sum += csolarkraftwerkleistung[weather];
584  num ++;
585  }
586 
587  Resources rplus;
588  for ( int r = 0; r < 3; r++ )
589  rplus.resource(r) = bld->maxplus.resource(r) * sum / ( num * 1024 );
590  return rplus;
591 }
592 
593 
595 {
596  return bld->bi_resourceplus;
597 }
598 
599 
600 
601 
602 MiningStation :: MiningStation( ContainerBase* bld_ , bool justQuery_) : SearchFields ( bld_->getMap() ), bld ( bld_ ), justQuery( justQuery_ )
603 {
604  int counter = 0;
605  for ( int r = 1; r < 3; r++ ) {
606  if ( bld->plus.resource(r) > 0 ) {
607  ++counter;
608  if ( counter == 2 )
609  fatalError( ASCString("A mining station can only produce ONE kind of resource; building ID" ) + strrr(bld->baseType->id) + " is violating this" );
610 
611  toExtract_thisTurn.resource(r) = bld->plus.resource(r);
612 
613  for ( int rr = 0; rr < 3; rr++ )
614  if ( bld->plus.resource(rr) < 0 )
615  usageRatio[rr] = -double(bld->plus.resource(rr)) / double(bld->plus.resource(r));
616  else
617  usageRatio[rr] = 0;
618  }
619  }
620 
621  if( justQuery ) {
622  hasRun = false;
623  run();
624  hasRun = true;
625  } else
626  hasRun = false;
627 }
628 
630 {
631  if ( justQuery && hasRun )
632  return false;
633 
634  actuallyExtracted = Resources();
635 
636  for ( int r = 0; r < 3;++r)
637  consumed[r] = 0;
638 
639  if ( !justQuery ) {
640  spaceAvail = bld->putResource( toExtract_thisTurn, true, 1, bld->getOwner() );
641  for ( int r = 0; r <3; ++r )
642  if ( spaceAvail.resource(r) < 0 ) {
643  warningMessage( ASCString("map corruption detected; building space availability is negative! ") + resourceNames[r] );
644  spaceAvail.resource( r ) = 0;
645  }
646  } else
647  spaceAvail = toExtract_thisTurn;
648 
649  Resources toConsume;
650  for ( int r = 0; r < 3; r++ )
651  if ( bld->plus.resource(r) < 0 )
652  toConsume.resource(r) = -bld->plus.resource(r);
653 
654  if ( !justQuery ) {
655  powerAvail = bld->getResource( toConsume, true, 1, bld->getOwner() );
656  for ( int r = 0; r <3; ++r )
657  if ( powerAvail.resource(r) < 0 ) {
658  warningMessage( ASCString("map corruption detected; available power for mining station is negative! ") + resourceNames[r] );
659  powerAvail.resource( r ) = 0;
660  }
661  } else
662  powerAvail = toConsume;
663 
664 
665  initsearch( bld->getPosition(), 0, maxminingrange );
666  startsearch();
667 
668  if ( !justQuery) {
669  for ( int r = 0; r < 3; ++r )
670  bld->getResource( int(consumed[r]), r, false, 1, bld->getOwner() );
671  bld->putResource(actuallyExtracted, false, 1, bld->getOwner() );
672  }
673 
674  for ( int r = 0; r < 3; r++ )
675  if ( actuallyExtracted.resource(r) > 0 )
676  return true;
677 
678  return false;
679 }
680 
682 {
683  cancelSearch = true;
684  for ( int r = 0; r < 3; r++ )
685  if ( toExtract_thisTurn.resource(r) > 0 )
686  cancelSearch = false;
687 
688  if ( cancelSearch == false ) {
689  MapField* fld = gamemap->getField ( mc );
690  float distEfficiency = getminingstationeficency ( dist );
691 
692  for ( int r = 1; r < 3; r++ ) {
693  if ( toExtract_thisTurn.resource(r) > 0 ) {
694 
695  float resourceFactor;
696  Uint8 *fieldResource;
697 
698  if ( r==1) {
699  // resourceFactor = resource_material_factor * double(bld->baseType->efficiencymaterial) / 1024;
700  resourceFactor = resource_material_factor;
701  fieldResource = &fld->material;
702  } else {
703  // resourceFactor = resource_fuel_factor * double(bld->baseType->efficiencyfuel) / 1024;
704  resourceFactor = resource_fuel_factor;
705  fieldResource = &fld->fuel;
706  }
707 
708  float perc = 1;
709 
710  // is enough resource available on the field
711  perc = min ( perc, (*fieldResource * resourceFactor) / (toExtract_thisTurn.resource(r) * distEfficiency));
712 
713  perc = min ( perc, float( double(spaceAvail.resource(r)) / (toExtract_thisTurn.resource(r) * distEfficiency )));
714 
715  for ( int i = 0; i < 3; ++i )
716  if ( usageRatio[i] * toExtract_thisTurn.resource(r) > 0 )
717  perc = min ( perc, float( double(powerAvail.resource(i)) / usageRatio[i] * toExtract_thisTurn.resource(r)));
718 
719  if ( perc < 0 ) {
720  warningMessage("Warning: mining station inconsistency\n");
721  perc = 0;
722  }
723 
724  if ( !justQuery )
725  *fieldResource -= int( toExtract_thisTurn.resource(r) * perc * distEfficiency / resourceFactor );
726 
727  int ex = int( ceil(toExtract_thisTurn.resource(r) * perc * distEfficiency));
728  actuallyExtracted.resource(r) += ex;
729  spaceAvail.resource(r) -= ex;
730  for ( int i = 0; i < 3; ++i) {
731  if ( spaceAvail.resource(i) < -2 ) // we allow for small deviations due to rounding errors
732  warningMessage("Warning: mining station inconsistency 2!\n");
733 
734  if ( spaceAvail.resource(i) < 0 )
735  spaceAvail.resource(i) = 0;
736  }
737 
738 
739  for ( int i = 0; i < 3; i++ ) {
740  float c = usageRatio[i] * toExtract_thisTurn.resource(r) * perc;
741  consumed[i] += c;
742  powerAvail.resource(i) -= int( ceil(c) );
743  if ( powerAvail.resource(i) < 0 )
744  powerAvail.resource(i) = 0;
745 
746  }
747 
748  toExtract_thisTurn.resource(r) -= int( toExtract_thisTurn.resource(r) * perc);
749 
750 
751  if ( !justQuery ) {
752  if ( !fld->resourceview )
754  fld->resourceview->visible |= 1 << bld->getOwner();
755  fld->resourceview->fuelvisible[bld->getOwner()] = fld->fuel;
756  fld->resourceview->materialvisible[bld->getOwner()] = fld->material;
757  }
758  }
759  }
760  }
761 }
762 
764 {
765  for ( int r = 0; r < 3; r++ )
766  if ( toExtract_thisTurn.resource(r) )
767  return false;
768  return true;
769 }
770 
772 {
773  return actuallyExtracted;
774 }
775 
777 {
778  Resources res;
779  for ( int r = 0; r < 3; ++r)
780  res.resource(r) = int( ceil(consumed[r]));
781  return res;
782 }
783 
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
Uint8 materialvisible[8]
Definition: mapfield.h:110
int fuel
Definition: typen.h:101
AutoHarvestObjects(ContainerBase *_bld, bool justQuery_)
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...
int id
the id of the object, used when referencing objects in files
Definition: objecttype.h:35
void logMessage(const ASCString &category, const ASCString &message)
int energy
Definition: typen.h:99
ASCString tos(int i)
Definition: tos.cpp:26
const int csolarkraftwerkleistung[cwettertypennum]
Definition: typen.cpp:87
Uint8 material
Definition: mapfield.h:54
ASCString toString() const
Definition: typen.cpp:268
TerrainType * terraintype
pointer to the outer structure
Definition: terraintype.h:128
Weather * weather[cwettertypennum]
Definition: terraintype.h:140
bool hasFunction(ContainerFunctions function) const
int getOwner() const
returns the number of the player this vehicle/building belongs to
virtual Resources getPlus()
int efficiency[maxminingrange+2]
void warningMessage(const ASCString &str)
void testfield(const MapCoordinate &mc)
a single field of the map
Definition: mapfield.h:26
static const char * name(int r)
Definition: typen.cpp:190
struct GameMap::Weather weather
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
Resources max[maxminingrange+2]
RegenerativePowerPlant(ContainerBase *_bld)
virtual Resources getPlus()
Handling the connection of buildings by pipelines, powerlines etc.
virtual vector< MapCoordinate > getCoveredFields()=0
virtual Resources getPlus()
virtual int getResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
MatterConverter(ContainerBase *_bld)
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
const int maxminingrange
The maximum number of fields a mining station can extract mineral resources from; Counted from its en...
Definition: typen.h:542
void initsearch(const MapCoordinate &startPosition, int _firstDistance, int _lastDistance)
Uint8 fuel
mineral resources on this field.
Definition: mapfield.h:54
virtual Resources getPlus()
GameMap * getMap() const
Definition: mapfield.h:38
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
void circularFieldIterator(GameMap *gamemap, const MapCoordinate &center, int startDist, int stopDist, FieldIterationFunctor functor)
searches fields in hexagonal "circles" around a field and calls testfield for each field ...
Definition: mapalgorithms.h:28
virtual void startsearch(void)
Resources maxplus
the maximum amount of Resources that the building can produce each turn in the ASC resource mode ; se...
int material
Definition: typen.h:100
virtual Resources getPlus()
virtual Resources getPlus()
Resources plus
the Resources that are produced each turn
virtual Resources getUsage()
bool buildable(MapField *fld) const
can the object be build on the field fld
Definition: objecttype.cpp:77
const int resource_material_factor
Definition: typen.h:529
ResourceSink(ContainerBase *_bld)
Resources bi_resourceplus
the maximum amount of Resources that the building can produce each turn in the BI resource mode ; see...
int groupID
the group ID allows units to specify whole groups of objects to be buildable / removable without spec...
Definition: objecttype.h:41
int & resource(int type)
Definition: typen.h:105
Building * building
Definition: mapfield.h:102
helper functions to convert various data to Strings
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)
const char * resourceNames[3]
the names of the different resources. Redundent, as we already have Resources::name ...
Definition: typen.cpp:79
GetMiningInfo(const ContainerBase *container)
GameMap * getMap() const
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
float getminingstationeficency(int dist)
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
an instance of an object type (ObjectType) on the map
Definition: objects.h:46
Resources are basically the currency of ASC.
Definition: typen.h:97
void testfield(const MapCoordinate &mc)
Resources avail[maxminingrange+2]
virtual Resources getUsage()
Object * checkForObject(const ObjectType *o)
checks if there are objects from the given type on the field and returns them
Definition: mapfield.cpp:648
void fatalError(const ASCString &string)
bool removeObject(const ObjectType *obj, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
removes all objects of the given type from the field
Definition: mapfield.cpp:256
GameMap * gamemap
Definition: mapalgorithms.h:30
virtual Resources getUsage()
virtual Resources getUsage()
Loki::Functor< void, LOKI_TYPELIST_1(const MapCoordinate &) > FieldIterationFunctor
Definition: mapalgorithms.h:43
Resourceview * resourceview
the mineral resources that were seen by a player on this field; since the actual amount may have decr...
Definition: mapfield.h:114
MiningStation(ContainerBase *_bld, bool justQuery_)
MapCoordinate3D getNeighbouringFieldCoordinate(const MapCoordinate3D &pos, int direc)
returns the coordinate of the field that is adjecent to the given field in the direction of direc ...
const int resource_fuel_factor
the conversion factor between mineral resources in the ground and the normal game Resources at nomina...
Definition: typen.h:528
MapField * getField(int x, int y)
Definition: gamemap.h:465
virtual MapCoordinate3D getPosition() const =0