Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StarSystem::Statistics Struct Reference

#include <star_system_generic.h>

Public Member Functions

 Statistics ()
 
void AddUnit (Unit *un)
 
void RemoveUnit (Unit *un)
 
void CheckVitals (StarSystem *ss)
 

Public Attributes

std::vector< UnitContainernavs [3]
 
vsUMap< std::string,
UnitContainer
jumpPoints
 
int system_faction
 
int newfriendlycount
 
int newenemycount
 
int newcitizencount
 
int newneutralcount
 
int friendlycount
 
int enemycount
 
int neutralcount
 
int citizencount
 
size_t checkIter
 
size_t navCheckIter
 

Detailed Description

Definition at line 86 of file star_system_generic.h.

Constructor & Destructor Documentation

StarSystem::Statistics::Statistics ( )

Member Function Documentation

void StarSystem::Statistics::AddUnit ( Unit un)

Definition at line 418 of file star_system_generic.cpp.

References Unit::faction, Unit::GetDestinations(), UnitUtil::getRelationFromFaction(), UnitUtil::isAsteroid(), FactionUtil::isCitizenInt(), Unit::isJumppoint(), Unit::isPlanet(), UnitUtil::isSignificant(), and k.

Referenced by StarSystem::AddUnit().

419 {
421  if ( FactionUtil::isCitizenInt( un->faction ) ) {
422  ++citizencount;
423  } else {
424  if (rel > 0.05)
425  ++friendlycount;
426  else if (rel < 0.)
427  ++enemycount;
428  else
429  ++neutralcount;
430  }
431  if ( un->GetDestinations().size() )
432  jumpPoints[un->GetDestinations()[0]].SetUnit( un );
433  if ( UnitUtil::isSignificant( un ) ) {
434  int k = 0;
435  if (rel > 0) k = 1; //base
436  if ( un->isPlanet() && !un->isJumppoint() )
437  k = 1; //friendly planet
438  //asteroid field/debris field
439  if ( UnitUtil::isAsteroid( un ) ) k = 2;
440  navs[k].push_back( UnitContainer( un ) );
441  }
442 }
void StarSystem::Statistics::CheckVitals ( StarSystem ss)

Definition at line 348 of file star_system_generic.cpp.

References StarSystem::AddUnit(), StarSystem::collidemap, UnitCollection::createIterator(), StarSystemGent::faction, Unit::faction, FactionUtil::GetFactionIndex(), StarSystem::getFileName(), UniverseUtil::GetGalaxyFaction(), UnitUtil::getRelationFromFaction(), StarSystem::getUnitList(), FactionUtil::isCitizenInt(), k, Collidable::radius, Collidable::ref, size, CollideArray::sorted, Collidable::CollideRef::unit, and Unit::UNIT_ONLY.

Referenced by StarSystem::AddUnit(), and StarSystem::UpdateUnitPhysics().

349 {
351  if (faction != system_faction) {
352  *this = Statistics(); //invoke copy constructor to clear it
353  this->system_faction = faction;
354  Unit *un;
355  for (un_iter ui = ss->getUnitList().createIterator();
356  (un = *ui) != NULL;
357  ++ui)
358  this->AddUnit( un ); //siege will take some time
359  return; //no need to check vitals now, they're all set
360  }
361  size_t iter = navCheckIter;
362  int k = 0;
363  if ( iter >= navs[0].size() ) {
364  iter -= navs[0].size();
365  k = 1;
366  }
367  if ( iter >= navs[1].size() ) {
368  iter -= navs[1].size();
369  k = 2;
370  }
371  size_t totalnavchecking = 25;
372  size_t totalsyschecking = 25;
373  while ( iter < totalnavchecking && iter < navs[k].size() ) {
374  if (navs[k][iter].GetUnit() == NULL) {
375  navs[k].erase( navs[k].begin()+iter );
376  } else {
377  ++iter;
378  ++navCheckIter;
379  }
380  }
381  if ( k == 2 && iter >= navs[k].size() )
382  navCheckIter = 0; //start over next time
383  size_t sortedsize = ss->collidemap[Unit::UNIT_ONLY]->sorted.size();
384  int sysfac = system_faction;
385  size_t counter = checkIter+totalsyschecking;
386  for (; checkIter < counter && checkIter < sortedsize; ++checkIter) {
388  if (collide->radius > 0) {
389  Unit *un = collide->ref.unit;
390  float rel = UnitUtil::getRelationFromFaction( un, sysfac );
391  if ( FactionUtil::isCitizenInt( un->faction ) ) {
392  ++newcitizencount;
393  } else {
394  if (rel > 0.05)
396  else if (rel < 0.)
397  ++newenemycount;
398  else
399  ++newneutralcount;
400  }
401  }
402  }
403  if (checkIter >= sortedsize && sortedsize
404  > (unsigned int) (enemycount+neutralcount+friendlycount
405  +citizencount)/4 /*suppose at least 1/4 survive a given frame*/) {
407  newcitizencount = 0;
409  newenemycount = 0;
411  newneutralcount = 0;
413  newfriendlycount = 0;
414  checkIter = 0; //start over with list
415  }
416 }
void StarSystem::Statistics::RemoveUnit ( Unit un)

Definition at line 444 of file star_system_generic.cpp.

References Unit::faction, Unit::GetDestinations(), UnitUtil::getRelationFromFaction(), i, FactionUtil::isCitizenInt(), UnitUtil::isSignificant(), and k.

Referenced by StarSystem::RemoveUnit().

445 {
447  if ( FactionUtil::isCitizenInt( un->faction ) ) {
448  --citizencount;
449  } else {
450  if (rel > 0.05)
451  --friendlycount;
452  else if (rel < 0.)
453  --enemycount;
454  else
455  --neutralcount;
456  }
457  if ( un->GetDestinations().size() ) {
458  //make sure it is there
459  jumpPoints[(un->GetDestinations()[0])].SetUnit( NULL );
460  //kill it--stupid I know--but hardly time critical
461  jumpPoints.erase( jumpPoints.find( un->GetDestinations()[0] ) );
462  }
463  if ( UnitUtil::isSignificant( un ) ) {
464  for (int k = 0; k < 3; ++k)
465  for (size_t i = 0; i < navs[k].size();) {
466  if (navs[k][i].GetUnit() == un)
467  //slow but who cares
468  navs[k].erase( navs[k].begin()+i );
469  else ++i; //only increment if you didn't erase current
470  }
471  }
472 }

Member Data Documentation

size_t StarSystem::Statistics::checkIter

Definition at line 100 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::citizencount

Definition at line 99 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::enemycount

Definition at line 97 of file star_system_generic.h.

Referenced by ChooseNavPoint(), and Statistics().

int StarSystem::Statistics::friendlycount

Definition at line 96 of file star_system_generic.h.

Referenced by ChooseNavPoint(), and Statistics().

vsUMap< std::string, UnitContainer > StarSystem::Statistics::jumpPoints

Definition at line 90 of file star_system_generic.h.

Referenced by ChooseNavPoint().

size_t StarSystem::Statistics::navCheckIter

Definition at line 101 of file star_system_generic.h.

Referenced by Statistics().

std::vector< UnitContainer > StarSystem::Statistics::navs[3]

Definition at line 89 of file star_system_generic.h.

Referenced by ChooseNavPoint().

int StarSystem::Statistics::neutralcount

Definition at line 98 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::newcitizencount

Definition at line 94 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::newenemycount

Definition at line 93 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::newfriendlycount

Definition at line 92 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::newneutralcount

Definition at line 95 of file star_system_generic.h.

Referenced by Statistics().

int StarSystem::Statistics::system_faction

Definition at line 91 of file star_system_generic.h.

Referenced by StarSystem::AddUnit(), ChooseNavPoint(), and Statistics().


The documentation for this struct was generated from the following files: