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

Method grenadeAction

src/Battlescape/AlienBAIState.cpp:1762–1793  ·  view source on GitHub ↗

* Evaluates whether to throw a grenade at an enemy (or group of enemies) we can see. */

Source from the content-addressed store, hash-verified

1760 * Evaluates whether to throw a grenade at an enemy (or group of enemies) we can see.
1761 */
1762void AlienBAIState::grenadeAction()
1763{
1764 // do we have a grenade on our belt?
1765 BattleItem *grenade = _unit->getGrenadeFromBelt();
1766 // distance must be more than X tiles, otherwise it's too dangerous to play with explosives
1767 if (explosiveEfficacy(_aggroTarget->getPosition(), _unit, grenade->getRules()->getExplosionRadius(), _attackAction->diff, true))
1768 {
1769 int tu = 4; // 4TUs for picking up the grenade
1770 tu += _unit->getActionTUs(BA_PRIME, grenade);
1771 tu += _unit->getActionTUs(BA_THROW, grenade);
1772 // do we have enough TUs to prime and throw the grenade?
1773 if (tu <= _unit->getStats()->tu)
1774 {
1775 BattleAction action;
1776 action.weapon = grenade;
1777 action.target = _aggroTarget->getPosition();
1778 action.type = BA_THROW;
1779 action.actor = _unit;
1780 Position originVoxel = _save->getTileEngine()->getOriginVoxel(action, 0);
1781 Position targetVoxel = action.target * Position (16,16,24) + Position (8,8, (2 + -_save->getTile(action.target)->getTerrainLevel()));
1782 // are we within range?
1783 if (_save->getTileEngine()->validateThrow(action, originVoxel, targetVoxel))
1784 {
1785 _attackAction->weapon = grenade;
1786 _attackAction->target = action.target;
1787 _attackAction->type = BA_THROW;
1788 _rifle = false;
1789 _melee = false;
1790 }
1791 }
1792 }
1793}
1794
1795/**
1796 * Attempts a psionic attack on an enemy we "know of".

Callers

nothing calls this directly

Calls 12

getGrenadeFromBeltMethod · 0.80
getExplosionRadiusMethod · 0.80
getActionTUsMethod · 0.80
getOriginVoxelMethod · 0.80
validateThrowMethod · 0.80
PositionClass · 0.70
getPositionMethod · 0.45
getRulesMethod · 0.45
getStatsMethod · 0.45
getTileEngineMethod · 0.45
getTerrainLevelMethod · 0.45
getTileMethod · 0.45

Tested by

no test coverage detected