* Get the "main hand weapon" from the unit. * @param quickest Whether to get the quickest weapon, default true * @return Pointer to item. */
| 1740 | * @return Pointer to item. |
| 1741 | */ |
| 1742 | BattleItem *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) |
no test coverage detected