MCPcopy Create free account
hub / github.com/NetHack/NetHack / weapon_dam_bonus

Function weapon_dam_bonus

src/weapon.c:1643–1729  ·  view source on GitHub ↗

* Return damage bonus/penalty based on skill of weapon. * weapon can be null, meaning bare-handed combat. * Treat restricted weapons as unskilled. */

Source from the content-addressed store, hash-verified

1641 * Treat restricted weapons as unskilled.
1642 */
1643int
1644weapon_dam_bonus(struct obj *weapon)
1645{
1646 int type, wep_type, skill, bonus = 0;
1647
1648 wep_type = weapon_type(weapon);
1649 /* use two weapon skill only if attacking with one of the wielded weapons
1650 */
1651 type = (u.twoweap && (weapon == uwep || weapon == uswapwep))
1652 ? P_TWO_WEAPON_COMBAT
1653 : wep_type;
1654 if (type == P_NONE) {
1655 bonus = 0;
1656 } else if (type <= P_LAST_WEAPON) {
1657 switch (P_SKILL(type)) {
1658 default:
1659 impossible("weapon_dam_bonus: bad skill %d", P_SKILL(type));
1660 FALLTHROUGH;
1661 /* FALLTHRU */
1662 case P_ISRESTRICTED:
1663 case P_UNSKILLED:
1664 bonus = -2;
1665 break;
1666 case P_BASIC:
1667 bonus = 0;
1668 break;
1669 case P_SKILLED:
1670 bonus = 1;
1671 break;
1672 case P_EXPERT:
1673 bonus = 2;
1674 break;
1675 }
1676 } else if (type == P_TWO_WEAPON_COMBAT) {
1677 skill = P_SKILL(P_TWO_WEAPON_COMBAT);
1678 if (P_SKILL(wep_type) < skill)
1679 skill = P_SKILL(wep_type);
1680 switch (skill) {
1681 default:
1682 case P_ISRESTRICTED:
1683 case P_UNSKILLED:
1684 bonus = -3;
1685 break;
1686 case P_BASIC:
1687 bonus = -1;
1688 break;
1689 case P_SKILLED:
1690 bonus = 0;
1691 break;
1692 case P_EXPERT:
1693 bonus = 1;
1694 break;
1695 }
1696 } else if (type == P_BARE_HANDED_COMBAT) {
1697 /*
1698 * b.h. m.a.
1699 * unskl: 0 n/a
1700 * basic: +1 +3

Callers 1

hmon_hitmon_dmg_recalcFunction · 0.85

Calls 2

weapon_typeFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected