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

Method getMainHandWeapon

src/Savegame/BattleUnit.cpp:1742–1772  ·  view source on GitHub ↗

* Get the "main hand weapon" from the unit. * @param quickest Whether to get the quickest weapon, default true * @return Pointer to item. */

Source from the content-addressed store, hash-verified

1740 * @return Pointer to item.
1741 */
1742BattleItem *BattleUnit::getMainHandWeapon(bool quickest) const
1743{
1744 BattleItem *weaponRightHand = getItem("STR_RIGHT_HAND");
1745 BattleItem *weaponLeftHand = getItem("STR_LEFT_HAND");
1746
1747 // ignore weapons without ammo (rules out grenades)
1748 if (!weaponRightHand || !weaponRightHand->getAmmoItem() || !weaponRightHand->getAmmoItem()->getAmmoQuantity())
1749 weaponRightHand = 0;
1750 if (!weaponLeftHand || !weaponLeftHand->getAmmoItem() || !weaponLeftHand->getAmmoItem()->getAmmoQuantity())
1751 weaponLeftHand = 0;
1752
1753 // if there is only one weapon, it's easy:
1754 if (weaponRightHand && !weaponLeftHand)
1755 return weaponRightHand;
1756 else if (!weaponRightHand && weaponLeftHand)
1757 return weaponLeftHand;
1758 else if (!weaponRightHand && !weaponLeftHand)
1759 return 0;
1760
1761 // otherwise pick the one with the least snapshot TUs
1762 int tuRightHand = weaponRightHand->getRules()->getTUSnap();
1763 int tuLeftHand = weaponLeftHand->getRules()->getTUSnap();
1764 if (tuLeftHand >= tuRightHand)
1765 {
1766 return quickest?weaponRightHand:weaponLeftHand;
1767 }
1768 else
1769 {
1770 return quickest?weaponLeftHand:weaponRightHand;
1771 }
1772}
1773
1774/**
1775 * Get a grenade from the belt (used for AI)

Callers 11

openDoorMethod · 0.80
thinkMethod · 0.80
setupPatrolMethod · 0.80
meleeActionMethod · 0.80
wayPointActionMethod · 0.80
postPathProceduresMethod · 0.80
handleAIMethod · 0.80
checkReservedTUMethod · 0.80
handlePanickingUnitMethod · 0.80
canMakeSnapMethod · 0.80
tryReactionSnapMethod · 0.80

Calls 4

getAmmoQuantityMethod · 0.80
getTUSnapMethod · 0.80
getAmmoItemMethod · 0.45
getRulesMethod · 0.45

Tested by

no test coverage detected