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
unit_find.h File Reference
#include "unit_util.h"

Go to the source code of this file.

Classes

class  NearestUnitLocator
 
class  NearestBoltLocator
 
class  NearestObjectLocator
 
class  NearestNavLocator
 
class  NearestNavOrCapshipLocator
 
class  UnitWithinRangeLocator< T >
 
class  UnitWithinRangeOfPosition< T >
 
class  UnitPtrLocator
 

Functions

template<class Locator >
void findObjectsFromPosition (CollideMap *cm, CollideMap::iterator location, Locator *check, QVector thispos, float thisrad, bool acquire_on_location)
 
template<class Locator >
void findObjects (CollideMap *cm, CollideMap::iterator location, Locator *check)
 

Function Documentation

template<class Locator >
void findObjects ( CollideMap cm,
CollideMap::iterator  location,
Locator *  check 
)

Definition at line 72 of file unit_find.h.

References findObjectsFromPosition(), is_null(), and QVector.

Referenced by CalculateNearestWarpUnit(), ChooseNearNavPoint(), Orders::FireAt::ChooseTargets(), Radar::Sensor::FindTracksInRange(), CommunicatingAI::GetRandomUnit(), and UniverseUtil::getUnitByPtr().

73 {
74  if ( is_null( location ) )
75  return;
76  QVector thispos = (**location).GetPosition();
77  float thisrad = fabs( (*location)->radius );
78  findObjectsFromPosition( cm, location, check, thispos, thisrad, false );
79 }
template<class Locator >
void findObjectsFromPosition ( CollideMap cm,
CollideMap::iterator  location,
Locator *  check,
QVector  thispos,
float  thisrad,
bool  acquire_on_location 
)

Definition at line 5 of file unit_find.h.

References CollideArray::begin(), CollideArray::end(), f, is_null(), CollideArray::Iterable(), Magnitude(), Collidable::radius, and CollideArray::CollidableBackref::toflattenhints_offset.

Referenced by GameStarSystem::Draw(), and findObjects().

11 {
12  CollideMap::iterator cmend = cm->end();
13  CollideMap::iterator cmbegin = cm->begin();
14  if ( cmend != cmbegin && !is_null( location ) ) {
15  CollideMap::iterator tless = location;
16  CollideMap::iterator tmore = location;
17  bool workA = true;
18  bool workB = true;
19  if ( location != cmend && !cm->Iterable( location ) ) {
21  location = cmbegin+br->toflattenhints_offset;
22  if (location == cmend)
23  location--;
24  tmore = location;
25  tless = location;
26  } else if (location != cmend) {
27  ++tmore;
28  } else {
29  //location == cmend
30  --location;
31  if (acquire_on_location)
32  --tless; //allowed because cmend!=cmbegin
33  workB = false;
34  }
35  check->init( cm, location );
36  if (!acquire_on_location) {
37  if (tless != cmbegin)
38  --tless;
39  else
40  workA = false;
41  }
42  while (workA || workB) {
43  if ( workA
44  && !check->cullless( tless ) ) {
45  float rad = (*tless)->radius;
46  if ( rad != 0.0f && ( check->BoltsOrUnits() || ( check->UnitsOnly() == (rad > 0) ) ) ) {
47  float trad =
48  check->NeedDistance() ? ( (*tless)->GetPosition()-thispos ).Magnitude()-fabs( rad )-thisrad : 0;
49  if ( !check->acquire( trad, tless ) )
50  workA = false;
51  }
52  if (tless != cmbegin)
53  tless--;
54  else
55  workA = false;
56  } else {workA = false; } if ( workB
57  && tmore != cmend
58  && !check->cullmore( tmore ) ) {
59  float rad = (*tmore)->radius;
60  if (rad!=0.0f&&(check->BoltsOrUnits()||(check->UnitsOnly()==(rad>0)))) {
61  float trad =
62  check->NeedDistance() ? ( (*tmore)->GetPosition()-thispos ).Magnitude()-fabs( rad )-thisrad : 0;
63  if ( !check->acquire( trad, tmore ) )
64  workB = false;
65  }
66  tmore++;
67  } else {workB = false; }}
68  }
69 }