MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / selectNearestTarget

Method selectNearestTarget

src/Battlescape/CivilianBAIState.cpp:213–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213int CivilianBAIState::selectNearestTarget()
214{
215 int tally = 0;
216 int closest = 100;
217 _aggroTarget = 0;
218 Position origin = _save->getTileEngine()->getSightOriginVoxel(_unit);
219 origin.z -= 4;
220 Position target;
221 for (std::vector<BattleUnit*>::const_iterator i = _save->getUnits()->begin(); i != _save->getUnits()->end(); ++i)
222 {
223 if (!(*i)->isOut() && (*i)->getFaction() == FACTION_HOSTILE)
224 {
225 if (_save->getTileEngine()->visible(_unit, (*i)->getTile()))
226 {
227 tally++;
228 int dist = _save->getTileEngine()->distance(_unit->getPosition(), (*i)->getPosition());
229 if (dist < closest)
230 {
231 bool valid = _save->getTileEngine()->canTargetUnit(&origin, (*i)->getTile(), &target, _unit);
232 if (valid)
233 {
234 closest = dist;
235 _aggroTarget = *i;
236 }
237 }
238 }
239 }
240 }
241 if (_aggroTarget)
242 return tally;
243
244 return 0;
245}
246
247int CivilianBAIState::getSpottingUnits(Position pos) const
248{

Callers

nothing calls this directly

Calls 10

getSightOriginVoxelMethod · 0.80
getUnitsMethod · 0.80
isOutMethod · 0.80
getFactionMethod · 0.80
visibleMethod · 0.80
distanceMethod · 0.80
canTargetUnitMethod · 0.80
getTileEngineMethod · 0.45
getTileMethod · 0.45
getPositionMethod · 0.45

Tested by

no test coverage detected