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

Method selectRandomTarget

src/Battlescape/AlienBAIState.cpp:1086–1104  ·  view source on GitHub ↗

* Selects a random known living Xcom or civilian unit. * @return if we found one. */

Source from the content-addressed store, hash-verified

1084 * @return if we found one.
1085 */
1086bool AlienBAIState::selectRandomTarget()
1087{
1088 int farthest = -100;
1089 _aggroTarget = 0;
1090
1091 for (std::vector<BattleUnit*>::const_iterator i = _save->getUnits()->begin(); i != _save->getUnits()->end(); ++i)
1092 {
1093 if (validTarget(*i, true, true))
1094 {
1095 int dist = RNG::generate(0,20) - _save->getTileEngine()->distance(_unit->getPosition(), (*i)->getPosition());
1096 if (dist > farthest)
1097 {
1098 farthest = dist;
1099 _aggroTarget = *i;
1100 }
1101 }
1102 }
1103 return _aggroTarget != 0;
1104}
1105
1106/**
1107 * Selects a point near enough to our target to perform a melee attack.

Callers

nothing calls this directly

Calls 5

generateFunction · 0.85
getUnitsMethod · 0.80
distanceMethod · 0.80
getTileEngineMethod · 0.45
getPositionMethod · 0.45

Tested by

no test coverage detected