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

Method selectPointNearTarget

src/Battlescape/AlienBAIState.cpp:1112–1149  ·  view source on GitHub ↗

* Selects a point near enough to our target to perform a melee attack. * @param target Pointer to a target. * @param maxTUs Maximum time units the path to the target can cost. * @return True if a point was found. */

Source from the content-addressed store, hash-verified

1110 * @return True if a point was found.
1111 */
1112bool AlienBAIState::selectPointNearTarget(BattleUnit *target, int maxTUs) const
1113{
1114 int size = _unit->getArmor()->getSize();
1115 int targetsize = target->getArmor()->getSize();
1116 bool returnValue = false;
1117 int distance = 1000;
1118 for (int z = -1; z <= 1; ++z)
1119 {
1120 for (int x = -size; x <= targetsize; ++x)
1121 {
1122 for (int y = -size; y <= targetsize; ++y)
1123 {
1124 if (x || y) // skip the unit itself
1125 {
1126 Position checkPath = target->getPosition() + Position (x, y, z);
1127 if (_save->getTile(checkPath) == 0 || std::find(_reachable.begin(), _reachable.end(), _save->getTileIndex(checkPath)) == _reachable.end())
1128 continue;
1129 int dir = _save->getTileEngine()->getDirectionTo(checkPath, target->getPosition());
1130 bool valid = _save->getTileEngine()->validMeleeRange(checkPath, dir, _unit, target, 0);
1131 bool fitHere = _save->setUnitPosition(_unit, checkPath, true);
1132
1133 if (valid && fitHere && !_save->getTile(checkPath)->getDangerous())
1134 {
1135 _save->getPathfinding()->calculate(_unit, checkPath, 0, maxTUs);
1136 if (_save->getPathfinding()->getStartDirection() != -1 && _save->getPathfinding()->getPath().size() < distance)
1137 {
1138 _attackAction->target = checkPath;
1139 returnValue = true;
1140 distance = _save->getPathfinding()->getPath().size();
1141 }
1142 _save->getPathfinding()->abortPath();
1143 }
1144 }
1145 }
1146 }
1147 }
1148 return returnValue;
1149}
1150
1151/**
1152 * Selects an AI mode based on a number of factors, some RNG and the results of the rest of the determinations.

Callers

nothing calls this directly

Calls 15

getTileIndexMethod · 0.80
getDirectionToMethod · 0.80
validMeleeRangeMethod · 0.80
setUnitPositionMethod · 0.80
getDangerousMethod · 0.80
calculateMethod · 0.80
getStartDirectionMethod · 0.80
abortPathMethod · 0.80
PositionClass · 0.70
getSizeMethod · 0.45
getArmorMethod · 0.45
getPositionMethod · 0.45

Tested by

no test coverage detected