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
ChooseTargetClass< numTuple > Class Template Reference

Public Member Functions

 ChooseTargetClass ()
 
void init (FireAt *fireat, Unit *un, float gunrange, vector< TurretBin > *tbin, const StaticTuple< float, numTuple > &innermaxrange, char maxrolepriority, int maxtargets)
 
bool acquire (Unit *un, float distance)
 
bool ShouldTargetUnit (Unit *un, float distance)
 

Public Attributes

Unitmytarg
 

Detailed Description

template<size_t numTuple>
class ChooseTargetClass< numTuple >

Definition at line 303 of file fire.cpp.

Constructor & Destructor Documentation

template<size_t numTuple>
ChooseTargetClass< numTuple >::ChooseTargetClass ( )
inline

Definition at line 321 of file fire.cpp.

321 {}

Member Function Documentation

template<size_t numTuple>
bool ChooseTargetClass< numTuple >::acquire ( Unit un,
float  distance 
)
inline

Definition at line 353 of file fire.cpp.

References Collidable::getKey(), i, Unit::location, and Unit::UNIT_ONLY.

354  {
355  double unkey = un->location[Unit::UNIT_ONLY]->getKey();
356  bool lesscheck = unkey < maxinnerrangeless[0];
357  bool morecheck = unkey > maxinnerrangemore[0];
358  if (reachedMore == false || reachedLess == false) {
359  if (lesscheck || morecheck) {
360  if (lesscheck)
361  reachedLess = true;
362  if (morecheck)
363  reachedMore = true;
364  if (mytarg && rolepriority < maxrolepriority) {
365  return false;
366  } else if (reachedLess == true && reachedMore == true) {
367  for (size_t i = 1; i < numTuple; ++i)
368  if (unkey > maxinnerrangeless[i] && unkey < maxinnerrangemore[i]) {
369  maxinnerrangeless[0] = maxinnerrangeless[i];
370  maxinnerrangemore[0] = maxinnerrangemore[i];
371  reachedLess = false;
372  reachedMore = false;
373  }
374  }
375  }
376  }
377  return ShouldTargetUnit( un, distance );
378  }
template<size_t numTuple>
void ChooseTargetClass< numTuple >::init ( FireAt fireat,
Unit un,
float  gunrange,
vector< TurretBin > *  tbin,
const StaticTuple< float, numTuple > &  innermaxrange,
char  maxrolepriority,
int  maxtargets 
)
inline

Definition at line 322 of file fire.cpp.

References Collidable::getKey(), UniverseUtil::getUnitByPtr(), i, is_null(), Unit::location, Unit::owner, and Unit::UNIT_ONLY.

329  {
330  this->fireat = fireat;
331  this->tbin = tbin;
332  this->parent = un;
333  this->parentparent = un->owner ? UniverseUtil::getUnitByPtr( un->owner, un, false ) : 0;
334  mytarg = NULL;
335  double currad = 0;
336  if ( !is_null( un->location[Unit::UNIT_ONLY] ) )
337  currad = un->location[Unit::UNIT_ONLY]->getKey();
338  for (size_t i = 0; i < numTuple; ++i) {
339  double tmpless = currad-innermaxrange[i];
340  double tmpmore = currad+innermaxrange[i];
341  this->maxinnerrangeless[i] = tmpless;
342  this->maxinnerrangemore[i] = tmpmore;
343  }
344  this->maxrolepriority = maxrolepriority; //max priority that will allow gun range to be ok
345  reachedMore = false;
346  reachedLess = false;
347  this->priority = -1;
348  this->rolepriority = 31;
349  this->gunrange = gunrange;
350  this->numtargets = 0;
351  this->maxtargets = maxtargets;
352  }
template<size_t numTuple>
bool ChooseTargetClass< numTuple >::ShouldTargetUnit ( Unit un,
float  distance 
)
inline

Definition at line 379 of file fire.cpp.

References Unit::CloakVisible(), ROLES::getPriority(), i, k, Priority(), and Unit::unitRole().

380  {
381  if (un->CloakVisible() > .8) {
382  float rangetotarget = distance;
383  float rel0 = parent->getRelation( un );
384  float rel[] = {
385  rel0 //not initialized until after array
386  , (parentparent ? parentparent->getRelation( un ) : rel0) //not initialized till after array
387  };
388  float relationship = rel0;
389  for (unsigned int i = 1; i < sizeof (rel)/sizeof (*rel); i++)
390  if (rel[i] < relationship)
391  relationship = rel[i];
392  char rp = 31;
393  float tmp = Priority( parent, un, gunrange, rangetotarget, relationship, &rp );
394  if (tmp > priority) {
395  mytarg = un;
396  priority = tmp;
397  rolepriority = rp;
398  }
399  for (vector< TurretBin >::iterator k = tbin->begin(); k != tbin->end(); ++k) {
400  if (rangetotarget > k->maxrange)
401  break;
402  const char tprior = ROLES::getPriority( k->turret[0].tur->attackPreference() )[un->unitRole()];
403  if (relationship < 0) {
404  if (tprior < 16) {
405  k->listOfTargets[0].push_back( TargetAndRange( un, rangetotarget, relationship ) );
406  numtargets++;
407  } else if (tprior < 31) {
408  k->listOfTargets[1].push_back( TargetAndRange( un, rangetotarget, relationship ) );
409  numtargets++;
410  }
411  }
412  }
413  }
414  return (maxtargets == 0) || (numtargets < maxtargets);
415  }

Member Data Documentation

template<size_t numTuple>
Unit* ChooseTargetClass< numTuple >::mytarg

Definition at line 320 of file fire.cpp.


The documentation for this class was generated from the following file: