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

Function skill_init

src/weapon.c:1737–1811  ·  view source on GitHub ↗

* Initialize weapon skill array for the game. Start by setting all * skills to restricted, then set the skill for every weapon the * hero is holding, finally reading the given array that sets * maximums. */

Source from the content-addressed store, hash-verified

1735 * maximums.
1736 */
1737void
1738skill_init(const struct def_skill *class_skill)
1739{
1740 struct obj *obj;
1741 int skmax, skill;
1742
1743 /* initialize skill array; by default, everything is restricted */
1744 for (skill = 0; skill < P_NUM_SKILLS; skill++) {
1745 P_SKILL(skill) = P_ISRESTRICTED;
1746 P_MAX_SKILL(skill) = P_ISRESTRICTED;
1747 P_ADVANCE(skill) = 0;
1748 }
1749
1750 /* Set skill for all weapons in inventory to be basic */
1751 for (obj = gi.invent; obj; obj = obj->nobj) {
1752 /* don't give skill just because of carried ammo, wait until
1753 we see the relevant launcher (prevents an archeologist's
1754 touchstone from inadvertently providing skill in sling) */
1755 if (is_ammo(obj))
1756 continue;
1757
1758 skill = weapon_type(obj);
1759 if (skill != P_NONE)
1760 P_SKILL(skill) = P_BASIC;
1761 }
1762
1763 /* set skills for magic */
1764 if (Role_if(PM_HEALER) || Role_if(PM_MONK)) {
1765 P_SKILL(P_HEALING_SPELL) = P_BASIC;
1766 } else if (Role_if(PM_CLERIC)) {
1767 P_SKILL(P_CLERIC_SPELL) = P_BASIC;
1768 } else if (Role_if(PM_WIZARD)) {
1769 P_SKILL(P_ATTACK_SPELL) = P_BASIC;
1770 P_SKILL(P_ENCHANTMENT_SPELL) = P_BASIC;
1771 }
1772
1773 /* walk through array to set skill maximums */
1774 for (; class_skill->skill != P_NONE; class_skill++) {
1775 skmax = class_skill->skmax;
1776 skill = class_skill->skill;
1777
1778 P_MAX_SKILL(skill) = skmax;
1779 if (P_SKILL(skill) == P_ISRESTRICTED) /* skill pre-set */
1780 P_SKILL(skill) = P_UNSKILLED;
1781 }
1782
1783 /* High potential fighters already know how to use their hands. */
1784 if (P_MAX_SKILL(P_BARE_HANDED_COMBAT) > P_EXPERT)
1785 P_SKILL(P_BARE_HANDED_COMBAT) = P_BASIC;
1786
1787 /* Roles that start with a horse know how to ride it */
1788 if (gu.urole.petnum == PM_PONY)
1789 P_SKILL(P_RIDING) = P_BASIC;
1790
1791 /*
1792 * Make sure we haven't missed setting the max on a skill
1793 * & set advance
1794 */

Callers 1

Calls 5

weapon_typeFunction · 0.85
unrestrict_weapon_skillFunction · 0.85
spell_skilltypeFunction · 0.85
skill_based_spellbook_idFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected