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
missile_generic.cpp File Reference
#include "universe_util.h"
#include "missile_generic.h"
#include "unit_generic.h"
#include "vegastrike.h"
#include "vs_globals.h"
#include "configxml.h"
#include "images.h"
#include "collection.h"
#include "star_system_generic.h"
#include "role_bitmask.h"
#include "ai/order.h"
#include "faction_generic.h"
#include "unit_util.h"

Go to the source code of this file.

Functions

UnitgetNearestTarget (Unit *me)
 

Function Documentation

Unit* getNearestTarget ( Unit me)

Definition at line 103 of file missile_generic.cpp.

References _Universe, Universe::activeStarSystem(), UnitCollection::createIterator(), UnitUtil::getFactionRelation(), StarSystem::getUnitList(), i, UnitUtil::isSun(), Magnitude(), Unit::Position(), QVector, and UNITPTR.

104 {
105  return NULL; //THIS FUNCTION IS TOO SLOW__AND ECM SHOULD WORK DIFFERENTLY ANYHOW...WILL SAVE FIXING IT FOR LATER
106 
107  QVector pos( me->Position() );
108  Unit *un = NULL;
109  Unit *targ = NULL;
110  double minrange = FLT_MAX;
112  ( un = (*i) );
113  ++i) {
114  if (un == me)
115  continue;
116  if (un->isUnit() != UNITPTR)
117  continue;
118  if (un->hull < 0)
119  continue;
120  if (UnitUtil::getFactionRelation( me, un ) >= 0)
121  continue;
122  double temp = (un->Position()-pos).Magnitude()-un->rSize();
123  if (targ == NULL) {
124  targ = un;
125  minrange = temp;
126  } else if (temp < minrange) {
127  targ = un;
128  }
129  }
130  if (targ == NULL) {
132  ( un = (*i) );
133  ++i)
134  if ( UnitUtil::isSun( un ) ) {
135  targ = un;
136  break;
137  }
138  }
139  return targ;
140 }