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

Method selectFireMethod

src/Battlescape/AlienBAIState.cpp:1698–1757  ·  view source on GitHub ↗

* Selects a fire method based on range, time units, and time units reserved for cover. */

Source from the content-addressed store, hash-verified

1696 * Selects a fire method based on range, time units, and time units reserved for cover.
1697 */
1698void AlienBAIState::selectFireMethod()
1699{
1700 int distance = _save->getTileEngine()->distance(_unit->getPosition(), _attackAction->target);
1701 _attackAction->type = BA_RETHINK;
1702 int tuAuto = _attackAction->weapon->getRules()->getTUAuto();
1703 int tuSnap = _attackAction->weapon->getRules()->getTUSnap();
1704 int tuAimed = _attackAction->weapon->getRules()->getTUAimed();
1705 int currentTU = _unit->getTimeUnits();
1706
1707 if (distance < 4)
1708 {
1709 if ( tuAuto && currentTU >= _unit->getActionTUs(BA_AUTOSHOT, _attackAction->weapon) )
1710 {
1711 _attackAction->type = BA_AUTOSHOT;
1712 return;
1713 }
1714 if ( !tuSnap || currentTU < _unit->getActionTUs(BA_SNAPSHOT, _attackAction->weapon) )
1715 {
1716 if ( tuAimed && currentTU >= _unit->getActionTUs(BA_AIMEDSHOT, _attackAction->weapon) )
1717 {
1718 _attackAction->type = BA_AIMEDSHOT;
1719 }
1720 return;
1721 }
1722 _attackAction->type = BA_SNAPSHOT;
1723 return;
1724 }
1725
1726
1727 if ( distance > 12 )
1728 {
1729 if ( tuAimed && currentTU >= _unit->getActionTUs(BA_AIMEDSHOT, _attackAction->weapon) )
1730 {
1731 _attackAction->type = BA_AIMEDSHOT;
1732 return;
1733 }
1734 if ( distance < 20
1735 && tuSnap
1736 && currentTU >= _unit->getActionTUs(BA_SNAPSHOT, _attackAction->weapon) )
1737 {
1738 _attackAction->type = BA_SNAPSHOT;
1739 return;
1740 }
1741 }
1742
1743 if ( tuSnap && currentTU >= _unit->getActionTUs(BA_SNAPSHOT, _attackAction->weapon) )
1744 {
1745 _attackAction->type = BA_SNAPSHOT;
1746 return;
1747 }
1748 if ( tuAimed && currentTU >= _unit->getActionTUs(BA_AIMEDSHOT, _attackAction->weapon) )
1749 {
1750 _attackAction->type = BA_AIMEDSHOT;
1751 return;
1752 }
1753 if ( tuAuto && currentTU >= _unit->getActionTUs(BA_AUTOSHOT, _attackAction->weapon) )
1754 {
1755 _attackAction->type = BA_AUTOSHOT;

Callers

nothing calls this directly

Calls 9

distanceMethod · 0.80
getTUAutoMethod · 0.80
getTUSnapMethod · 0.80
getTUAimedMethod · 0.80
getTimeUnitsMethod · 0.80
getActionTUsMethod · 0.80
getTileEngineMethod · 0.45
getPositionMethod · 0.45
getRulesMethod · 0.45

Tested by

no test coverage detected