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

Method wayPointAction

src/Battlescape/AlienBAIState.cpp:1611–1678  ·  view source on GitHub ↗

* Attempts to fire a waypoint projectile at an enemy we, or one of our teammates sees. * * Waypoint targeting: pick from any units currently spotted by our allies. */

Source from the content-addressed store, hash-verified

1609 * Waypoint targeting: pick from any units currently spotted by our allies.
1610 */
1611void AlienBAIState::wayPointAction()
1612{
1613 _aggroTarget = 0;
1614 for (std::vector<BattleUnit*>::const_iterator i = _save->getUnits()->begin(); i != _save->getUnits()->end() && _aggroTarget == 0; ++i)
1615 {
1616 if (!validTarget(*i, true, true))
1617 continue;
1618 _save->getPathfinding()->calculate(_unit, (*i)->getPosition(), *i, -1);
1619 if (_save->getPathfinding()->getStartDirection() != -1 &&
1620 explosiveEfficacy((*i)->getPosition(), _unit, (_unit->getMainHandWeapon()->getAmmoItem()->getRules()->getPower()/20)+1, _attackAction->diff))
1621 {
1622 _aggroTarget = *i;
1623 }
1624 _save->getPathfinding()->abortPath();
1625 }
1626
1627 if (_aggroTarget != 0)
1628 {
1629 _attackAction->type = BA_LAUNCH;
1630 _attackAction->TU = _unit->getActionTUs(BA_LAUNCH, _attackAction->weapon);
1631 if (_attackAction->TU > _unit->getTimeUnits())
1632 {
1633 _attackAction->type = BA_RETHINK;
1634 return;
1635 }
1636 _attackAction->waypoints.clear();
1637
1638 int PathDirection;
1639 int CollidesWith;
1640 Position LastWayPoint = _unit->getPosition();
1641 Position LastPosition = _unit->getPosition();
1642 Position CurrentPosition = _unit->getPosition();
1643 Position DirectionVector;
1644
1645 _save->getPathfinding()->calculate(_unit, _aggroTarget->getPosition(), _aggroTarget, -1);
1646 PathDirection = _save->getPathfinding()->dequeuePath();
1647 while (PathDirection != -1)
1648 {
1649 LastPosition = CurrentPosition;
1650 _save->getPathfinding()->directionToVector(PathDirection, &DirectionVector);
1651 CurrentPosition = CurrentPosition + DirectionVector;
1652 Position voxelPosA ((CurrentPosition.x * 16)+8, (CurrentPosition.y * 16)+8, (CurrentPosition.z * 24)+16);
1653 Position voxelPosb ((LastWayPoint.x * 16)+8, (LastWayPoint.y * 16)+8, (LastWayPoint.z * 24)+16);
1654 CollidesWith = _save->getTileEngine()->calculateLine(voxelPosA, voxelPosb, false, 0, _unit, true);
1655 if (CollidesWith > V_EMPTY && CollidesWith < V_UNIT)
1656 {
1657 _attackAction->waypoints.push_back(LastPosition);
1658 LastWayPoint = LastPosition;
1659 }
1660 else if (CollidesWith == V_UNIT)
1661 {
1662 BattleUnit* target = _save->getTile(CurrentPosition)->getUnit();
1663 if (target == _aggroTarget)
1664 {
1665 _attackAction->waypoints.push_back(CurrentPosition);
1666 LastWayPoint = CurrentPosition;
1667 }
1668 }

Callers

nothing calls this directly

Calls 15

getUnitsMethod · 0.80
calculateMethod · 0.80
getStartDirectionMethod · 0.80
getPowerMethod · 0.80
getMainHandWeaponMethod · 0.80
abortPathMethod · 0.80
getActionTUsMethod · 0.80
getTimeUnitsMethod · 0.80
dequeuePathMethod · 0.80
directionToVectorMethod · 0.80
calculateLineMethod · 0.80
getPathfindingMethod · 0.45

Tested by

no test coverage detected