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

Function weapon_hit_bonus

src/weapon.c:1544–1636  ·  view source on GitHub ↗

* Return hit 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

1542 * Treat restricted weapons as unskilled.
1543 */
1544int
1545weapon_hit_bonus(struct obj *weapon)
1546{
1547 int type, wep_type, skill, bonus = 0;
1548 static const char bad_skill[] = "weapon_hit_bonus: bad skill %d";
1549
1550 wep_type = weapon_type(weapon);
1551 /* use two weapon skill only if attacking with one of the wielded weapons
1552 */
1553 type = (u.twoweap && (weapon == uwep || weapon == uswapwep))
1554 ? P_TWO_WEAPON_COMBAT
1555 : wep_type;
1556 if (type == P_NONE) {
1557 bonus = 0;
1558 } else if (type <= P_LAST_WEAPON) {
1559 switch (P_SKILL(type)) {
1560 default:
1561 impossible(bad_skill, P_SKILL(type));
1562 FALLTHROUGH;
1563 /* FALLTHRU */
1564 case P_ISRESTRICTED:
1565 case P_UNSKILLED:
1566 bonus = -4;
1567 break;
1568 case P_BASIC:
1569 bonus = 0;
1570 break;
1571 case P_SKILLED:
1572 bonus = 2;
1573 break;
1574 case P_EXPERT:
1575 bonus = 3;
1576 break;
1577 }
1578 } else if (type == P_TWO_WEAPON_COMBAT) {
1579 skill = P_SKILL(P_TWO_WEAPON_COMBAT);
1580 if (P_SKILL(wep_type) < skill)
1581 skill = P_SKILL(wep_type);
1582 switch (skill) {
1583 default:
1584 impossible(bad_skill, skill);
1585 FALLTHROUGH;
1586 /* FALLTHRU */
1587 case P_ISRESTRICTED:
1588 case P_UNSKILLED:
1589 bonus = -9;
1590 break;
1591 case P_BASIC:
1592 bonus = -7;
1593 break;
1594 case P_SKILLED:
1595 bonus = -5;
1596 break;
1597 case P_EXPERT:
1598 bonus = -3;
1599 break;
1600 }
1601 } else if (type == P_BARE_HANDED_COMBAT) {

Callers 2

find_roll_to_hitFunction · 0.85
thitmonstFunction · 0.85

Calls 2

weapon_typeFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected