# Source:NetHack 3.6.1/src/weapon.c
Below is the full text to weapon.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/weapon.c#line123]], for example.

Contents

1 Top of file
2 give_may_advance_msg
3 weapon_descr
4 hitval
5 dmgval
6 oselect
7 select_rwep
8 select_hwep
9 possibly_unwield
10 mon_wield_item
11 mwepgone
12 abon
13 dbon
14 wet_a_towel
15 dry_a_towel
16 skill_level_name
17 slots_required
18 can_advance
19 could_advance
20 peaked_skill
21 skill_advance
22 enhance_weapon_skill
23 unrestrict_weapon_skill
24 use_skill
25 add_weapon_skill
26 lose_weapon_skill
27 weapon_type
28 uwep_skill_type
29 weapon_hit_bonus
30 weapon_dam_bonus
31 skill_init
32 setmnotwielded

Top of file
&nbsp;/* NetHack 3.6	weapon.c	$NHDT-Date: 1454660575 2016/02/05 08:22:55 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.57 $ */
&nbsp;/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
&nbsp;/*-Copyright (c) Robert Patrick Rankin, 2011. */
&nbsp;/* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

&nbsp;
&nbsp;/*
&nbsp; *      This module contains code for calculation of "to hit" and damage
&nbsp; *      bonuses for any given weapon used, as well as weapons selection
&nbsp; *      code for monsters.
&nbsp; */
&nbsp;#include "hack.h"
&nbsp;
&nbsp;/* Categories whose names don't come from OBJ_NAME(objects[type])
&nbsp; */
&nbsp;#define PN_BARE_HANDED (-1) /* includes martial arts */
&nbsp;#define PN_TWO_WEAPONS (-2)
&nbsp;#define PN_RIDING (-3)
&nbsp;#define PN_POLEARMS (-4)
&nbsp;#define PN_SABER (-5)
&nbsp;#define PN_HAMMER (-6)
&nbsp;#define PN_WHIP (-7)
&nbsp;#define PN_ATTACK_SPELL (-8)
&nbsp;#define PN_HEALING_SPELL (-9)
&nbsp;#define PN_DIVINATION_SPELL (-10)
&nbsp;#define PN_ENCHANTMENT_SPELL (-11)
&nbsp;#define PN_CLERIC_SPELL (-12)
&nbsp;#define PN_ESCAPE_SPELL (-13)
&nbsp;#define PN_MATTER_SPELL (-14)
&nbsp;
&nbsp;STATIC_DCL void FDECL(give_may_advance_msg, (int));
&nbsp;
&nbsp;STATIC_VAR NEARDATA const short skill_names_indices[P_NUM_SKILLS] = {
&nbsp;    0, DAGGER, KNIFE, AXE, PICK_AXE, SHORT_SWORD, BROADSWORD, LONG_SWORD,
&nbsp;    TWO_HANDED_SWORD, SCIMITAR, PN_SABER, CLUB, MACE, MORNING_STAR, FLAIL,
&nbsp;    PN_HAMMER, QUARTERSTAFF, PN_POLEARMS, SPEAR, TRIDENT, LANCE, BOW, SLING,
&nbsp;    CROSSBOW, DART, SHURIKEN, BOOMERANG, PN_WHIP, UNICORN_HORN,
&nbsp;    PN_ATTACK_SPELL, PN_HEALING_SPELL, PN_DIVINATION_SPELL,
&nbsp;    PN_ENCHANTMENT_SPELL, PN_CLERIC_SPELL, PN_ESCAPE_SPELL, PN_MATTER_SPELL,
&nbsp;    PN_BARE_HANDED, PN_TWO_WEAPONS, PN_RIDING
&nbsp;};
&nbsp;
&nbsp;/* note: entry [0] isn't used */
&nbsp;STATIC_VAR NEARDATA const char *const odd_skill_names[] = {
&nbsp;    "no skill", "bare hands", /* use barehands_or_martial[] instead */
&nbsp;    "two weapon combat", "riding", "polearms", "saber", "hammer", "whip",
&nbsp;    "attack spells", "healing spells", "divination spells",
&nbsp;    "enchantment spells", "clerical spells", "escape spells", "matter spells",
&nbsp;};
&nbsp;/* indexed vis `is_martial() */
&nbsp;STATIC_VAR NEARDATA const char *const barehands_or_martial[] = {
&nbsp;    "bare handed combat", "martial arts"
&nbsp;};
&nbsp;
give_may_advance_msg
&nbsp;STATIC_OVL void
&nbsp;give_may_advance_msg(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    You_feel("more confident in your %sskills.",
&nbsp;             skill == P_NONE ? "" : skill &lt;= P_LAST_WEAPON
&nbsp;                                        ? "weapon "
&nbsp;                                        : skill &lt;= P_LAST_SPELL
&nbsp;                                              ? "spell casting "
&nbsp;                                              : "fighting ");
&nbsp;}
&nbsp;
&nbsp;STATIC_DCL boolean FDECL(can_advance, (int, BOOLEAN_P));
&nbsp;STATIC_DCL boolean FDECL(could_advance, (int));
&nbsp;STATIC_DCL boolean FDECL(peaked_skill, (int));
&nbsp;STATIC_DCL int FDECL(slots_required, (int));
&nbsp;STATIC_DCL char *FDECL(skill_level_name, (int, char *));
&nbsp;STATIC_DCL void FDECL(skill_advance, (int));
&nbsp;
&nbsp;#define P_NAME(type)                                    \
&nbsp;    ((skill_names_indices[type] &gt; 0)                    \
&nbsp;         ? OBJ_NAME(objects[skill_names_indices[type]]) \
&nbsp;         : (type == P_BARE_HANDED_COMBAT)               \
&nbsp;               ? barehands_or_martial[martial_bonus()]  \
&nbsp;               : odd_skill_names[-skill_names_indices[type]])
&nbsp;
&nbsp;static NEARDATA const char kebabable[] = { S_XORN, S_DRAGON, S_JABBERWOCK,
&nbsp;                                           S_NAGA, S_GIANT,  '\0' };
&nbsp;
weapon_descr
&nbsp;/* weapon's skill category name for use as generalized description of weapon;
&nbsp;   mostly used to shorten "you drop your 

<weapon>" messages when slippery
&nbsp;   fingers or polymorph causes hero to involuntarily drop wielded weapon(s) */
&nbsp;const char *
&nbsp;weapon_descr(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    int skill = weapon_type(obj);
&nbsp;    const char *descr = P_NAME(skill);
&nbsp;
&nbsp;    /* assorted special cases */
&nbsp;    switch (skill) {
&nbsp;    case P_NONE:
&nbsp;        /* not a weapon or weptool: use item class name;
&nbsp;           override class name "food" for corpses, tins, and eggs,
&nbsp;           "large rock" for statues and boulders, and "tool" for towels */
&nbsp;        descr = (obj-&gt;otyp == CORPSE || obj-&gt;otyp == TIN || obj-&gt;otyp == EGG
&nbsp;                 || obj-&gt;otyp == STATUE || obj-&gt;otyp == BOULDER
&nbsp;                 || obj-&gt;otyp == TOWEL)
&nbsp;                    ? OBJ_NAME(objects[obj-&gt;otyp])
&nbsp;                    : def_oc_syms[(int) obj-&gt;oclass].name;
&nbsp;        break;
&nbsp;    case P_SLING:
&nbsp;        if (is_ammo(obj))
&nbsp;            descr = (obj-&gt;otyp == ROCK || is_graystone(obj))
&nbsp;                        ? "stone"
&nbsp;                        /* avoid "rock"; what about known glass? */
&nbsp;                        : (obj-&gt;oclass == GEM_CLASS)
&nbsp;                            ? "gem"
&nbsp;                            /* in case somebody adds odd sling ammo */
&nbsp;                            : def_oc_syms[(int) obj-&gt;oclass].name;
&nbsp;        break;
&nbsp;    case P_BOW:
&nbsp;        if (is_ammo(obj))
&nbsp;            descr = "arrow";
&nbsp;        break;
&nbsp;    case P_CROSSBOW:
&nbsp;        if (is_ammo(obj))
&nbsp;            descr = "bolt";
&nbsp;        break;
&nbsp;    case P_FLAIL:
&nbsp;        if (obj-&gt;otyp == GRAPPLING_HOOK)
&nbsp;            descr = "hook";
&nbsp;        break;
&nbsp;    case P_PICK_AXE:
&nbsp;        /* even if "dwarvish mattock" hasn't been discovered yet */
&nbsp;        if (obj-&gt;otyp == DWARVISH_MATTOCK)
&nbsp;            descr = "mattock";
&nbsp;        break;
&nbsp;    default:
&nbsp;        break;
&nbsp;    }
&nbsp;    return makesingular(descr);
&nbsp;}
&nbsp;
hitval
&nbsp;/*
&nbsp; *      hitval returns an integer representing the "to hit" bonuses
&nbsp; *      of "otmp" against the monster.
&nbsp; */
&nbsp;int
&nbsp;hitval(otmp, mon)
&nbsp;struct obj *otmp;
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    int tmp = 0;
&nbsp;    struct permonst *ptr = mon-&gt;data;
&nbsp;    boolean Is_weapon = (otmp-&gt;oclass == WEAPON_CLASS || is_weptool(otmp));
&nbsp;
&nbsp;    if (Is_weapon)
&nbsp;        tmp += otmp-&gt;spe;
&nbsp;
&nbsp;    /* Put weapon specific "to hit" bonuses in below: */
&nbsp;    tmp += objects[otmp-&gt;otyp].oc_hitbon;
&nbsp;
&nbsp;    /* Put weapon vs. monster type "to hit" bonuses in below: */
&nbsp;
&nbsp;    /* Blessed weapons used against undead or demons */
&nbsp;    if (Is_weapon &amp;&amp; otmp-&gt;blessed
&nbsp;        &amp;&amp; (is_demon(ptr) || is_undead(ptr) || is_vampshifter(mon)))
&nbsp;        tmp += 2;
&nbsp;
&nbsp;    if (is_spear(otmp) &amp;&amp; index(kebabable, ptr-&gt;mlet))
&nbsp;        tmp += 2;
&nbsp;
&nbsp;    /* trident is highly effective against swimmers */
&nbsp;    if (otmp-&gt;otyp == TRIDENT &amp;&amp; is_swimmer(ptr)) {
&nbsp;        if (is_pool(mon-&gt;mx, mon-&gt;my))
&nbsp;            tmp += 4;
&nbsp;        else if (ptr-&gt;mlet == S_EEL || ptr-&gt;mlet == S_SNAKE)
&nbsp;            tmp += 2;
&nbsp;    }
&nbsp;
&nbsp;    /* Picks used against xorns and earth elementals */
&nbsp;    if (is_pick(otmp) &amp;&amp; (passes_walls(ptr) &amp;&amp; thick_skinned(ptr)))
&nbsp;        tmp += 2;
&nbsp;
&nbsp;    /* Check specially named weapon "to hit" bonuses */
&nbsp;    if (otmp-&gt;oartifact)
&nbsp;        tmp += spec_abon(otmp, mon);
&nbsp;
&nbsp;    return tmp;
&nbsp;}
&nbsp;
&nbsp;/* Historical note: The original versions of Hack used a range of damage
&nbsp; * which was similar to, but not identical to the damage used in Advanced
&nbsp; * Dungeons and Dragons.  I figured that since it was so close, I may as well
&nbsp; * make it exactly the same as AD&amp;D, adding some more weapons in the process.
&nbsp; * This has the advantage that it is at least possible that the player would
&nbsp; * already know the damage of at least some of the weapons.  This was circa
&nbsp; * 1987 and I used the table from Unearthed Arcana until I got tired of typing
&nbsp; * them in (leading to something of an imbalance towards weapons early in
&nbsp; * alphabetical order).  The data structure still doesn't include fields that
&nbsp; * fully allow the appropriate damage to be described (there's no way to say
&nbsp; * 3d6 or 1d6+1) so we add on the extra damage in dmgval() if the weapon
&nbsp; * doesn't do an exact die of damage.
&nbsp; *
&nbsp; * Of course new weapons were added later in the development of Nethack.  No
&nbsp; * AD&amp;D consistency was kept, but most of these don't exist in AD&amp;D anyway.
&nbsp; *
&nbsp; * Second edition AD&amp;D came out a few years later; luckily it used the same
&nbsp; * table.  As of this writing (1999), third edition is in progress but not
&nbsp; * released.  Let's see if the weapon table stays the same.  --KAA
&nbsp; * October 2000: It didn't.  Oh, well.
&nbsp; */
&nbsp;
dmgval
&nbsp;/*
&nbsp; *      dmgval returns an integer representing the damage bonuses
&nbsp; *      of "otmp" against the monster.
&nbsp; */
&nbsp;int
&nbsp;dmgval(otmp, mon)
&nbsp;struct obj *otmp;
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    int tmp = 0, otyp = otmp-&gt;otyp;
&nbsp;    struct permonst *ptr = mon-&gt;data;
&nbsp;    boolean Is_weapon = (otmp-&gt;oclass == WEAPON_CLASS || is_weptool(otmp));
&nbsp;
&nbsp;    if (otyp == CREAM_PIE)
&nbsp;        return 0;
&nbsp;
&nbsp;    if (bigmonst(ptr)) {
&nbsp;        if (objects[otyp].oc_wldam)
&nbsp;            tmp = rnd(objects[otyp].oc_wldam);
&nbsp;        switch (otyp) {
&nbsp;        case IRON_CHAIN:
&nbsp;        case CROSSBOW_BOLT:
&nbsp;        case MORNING_STAR:
&nbsp;        case PARTISAN:
&nbsp;        case RUNESWORD:
&nbsp;        case ELVEN_BROADSWORD:
&nbsp;        case BROADSWORD:
&nbsp;            tmp++;
&nbsp;            break;
&nbsp;
&nbsp;        case FLAIL:
&nbsp;        case RANSEUR:
&nbsp;        case VOULGE:
&nbsp;            tmp += rnd(4);
&nbsp;            break;
&nbsp;
&nbsp;        case ACID_VENOM:
&nbsp;        case HALBERD:
&nbsp;        case SPETUM:
&nbsp;            tmp += rnd(6);
&nbsp;            break;
&nbsp;
&nbsp;        case BATTLE_AXE:
&nbsp;        case BARDICHE:
&nbsp;        case TRIDENT:
&nbsp;            tmp += d(2, 4);
&nbsp;            break;
&nbsp;
&nbsp;        case TSURUGI:
&nbsp;        case DWARVISH_MATTOCK:
&nbsp;        case TWO_HANDED_SWORD:
&nbsp;            tmp += d(2, 6);
&nbsp;            break;
&nbsp;        }
&nbsp;    } else {
&nbsp;        if (objects[otyp].oc_wsdam)
&nbsp;            tmp = rnd(objects[otyp].oc_wsdam);
&nbsp;        switch (otyp) {
&nbsp;        case IRON_CHAIN:
&nbsp;        case CROSSBOW_BOLT:
&nbsp;        case MACE:
&nbsp;        case WAR_HAMMER:
&nbsp;        case FLAIL:
&nbsp;        case SPETUM:
&nbsp;        case TRIDENT:
&nbsp;            tmp++;
&nbsp;            break;
&nbsp;
&nbsp;        case BATTLE_AXE:
&nbsp;        case BARDICHE:
&nbsp;        case BILL_GUISARME:
&nbsp;        case GUISARME:
&nbsp;        case LUCERN_HAMMER:
&nbsp;        case MORNING_STAR:
&nbsp;        case RANSEUR:
&nbsp;        case BROADSWORD:
&nbsp;        case ELVEN_BROADSWORD:
&nbsp;        case RUNESWORD:
&nbsp;        case VOULGE:
&nbsp;            tmp += rnd(4);
&nbsp;            break;
&nbsp;
&nbsp;        case ACID_VENOM:
&nbsp;            tmp += rnd(6);
&nbsp;            break;
&nbsp;        }
&nbsp;    }
&nbsp;    if (Is_weapon) {
&nbsp;        tmp += otmp-&gt;spe;
&nbsp;        /* negative enchantment mustn't produce negative damage */
&nbsp;        if (tmp &lt; 0)
&nbsp;            tmp = 0;
&nbsp;    }
&nbsp;
&nbsp;    if (objects[otyp].oc_material &lt;= LEATHER &amp;&amp; thick_skinned(ptr))
&nbsp;        /* thick skinned/scaled creatures don't feel it */
&nbsp;        tmp = 0;
&nbsp;    if (ptr == &amp;mons[PM_SHADE] &amp;&amp; !shade_glare(otmp))
&nbsp;        tmp = 0;
&nbsp;
&nbsp;    /* "very heavy iron ball"; weight increase is in increments */
&nbsp;    if (otyp == HEAVY_IRON_BALL &amp;&amp; tmp &gt; 0) {
&nbsp;        int wt = (int) objects[HEAVY_IRON_BALL].oc_weight;
&nbsp;
&nbsp;        if ((int) otmp-&gt;owt &gt; wt) {
&nbsp;            wt = ((int) otmp-&gt;owt - wt) / IRON_BALL_W_INCR;
&nbsp;            tmp += rnd(4 * wt);
&nbsp;            if (tmp &gt; 25)
&nbsp;                tmp = 25; /* objects[].oc_wldam */
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* Put weapon vs. monster type damage bonuses in below: */
&nbsp;    if (Is_weapon || otmp-&gt;oclass == GEM_CLASS || otmp-&gt;oclass == BALL_CLASS
&nbsp;        || otmp-&gt;oclass == CHAIN_CLASS) {
&nbsp;        int bonus = 0;
&nbsp;
&nbsp;        if (otmp-&gt;blessed
&nbsp;            &amp;&amp; (is_undead(ptr) || is_demon(ptr) || is_vampshifter(mon)))
&nbsp;            bonus += rnd(4);
&nbsp;        if (is_axe(otmp) &amp;&amp; is_wooden(ptr))
&nbsp;            bonus += rnd(4);
&nbsp;        if (objects[otyp].oc_material == SILVER &amp;&amp; mon_hates_silver(mon))
&nbsp;            bonus += rnd(20);
&nbsp;
&nbsp;        /* if the weapon is going to get a double damage bonus, adjust
&nbsp;           this bonus so that effectively it's added after the doubling */
&nbsp;        if (bonus &gt; 1 &amp;&amp; otmp-&gt;oartifact &amp;&amp; spec_dbon(otmp, mon, 25) &gt;= 25)
&nbsp;            bonus = (bonus + 1) / 2;
&nbsp;
&nbsp;        tmp += bonus;
&nbsp;    }
&nbsp;
&nbsp;    if (tmp &gt; 0) {
&nbsp;        /* It's debatable whether a rusted blunt instrument
&nbsp;           should do less damage than a pristine one, since
&nbsp;           it will hit with essentially the same impact, but
&nbsp;           there ought to some penalty for using damaged gear
&nbsp;           so always subtract erosion even for blunt weapons. */
&nbsp;        tmp -= greatest_erosion(otmp);
&nbsp;        if (tmp &lt; 1)
&nbsp;            tmp = 1;
&nbsp;    }
&nbsp;
&nbsp;    return  tmp;
&nbsp;}
&nbsp;
&nbsp;STATIC_DCL struct obj *FDECL(oselect, (struct monst *, int));
&nbsp;#define Oselect(x)                      \
&nbsp;    if ((otmp = oselect(mtmp, x)) != 0) \
&nbsp;        return otmp;
&nbsp;
oselect
&nbsp;STATIC_OVL struct obj *
&nbsp;oselect(mtmp, x)
&nbsp;struct monst *mtmp;
&nbsp;int x;
&nbsp;{
&nbsp;    struct obj *otmp;
&nbsp;
&nbsp;    for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj) {
&nbsp;        if (otmp-&gt;otyp == x
&nbsp;            /* never select non-cockatrice corpses */
&nbsp;            &amp;&amp; !((x == CORPSE || x == EGG)
&nbsp;                 &amp;&amp; !touch_petrifies(&amp;mons[otmp-&gt;corpsenm]))
&nbsp;            &amp;&amp; (!otmp-&gt;oartifact || touch_artifact(otmp, mtmp)))
&nbsp;            return otmp;
&nbsp;    }
&nbsp;    return (struct obj *) 0;
&nbsp;}
&nbsp;
&nbsp;static NEARDATA const int rwep[] = {
&nbsp;    DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, JAVELIN,
&nbsp;    SHURIKEN, YA, SILVER_ARROW, ELVEN_ARROW, ARROW, ORCISH_ARROW,
&nbsp;    CROSSBOW_BOLT, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, KNIFE,
&nbsp;    FLINT, ROCK, LOADSTONE, LUCKSTONE, DART,
&nbsp;    /* BOOMERANG, */ CREAM_PIE
&nbsp;};
&nbsp;
&nbsp;static NEARDATA const int pwep[] = { HALBERD,       BARDICHE, SPETUM,
&nbsp;                                     BILL_GUISARME, VOULGE,   RANSEUR,
&nbsp;                                     GUISARME,      GLAIVE,   LUCERN_HAMMER,
&nbsp;                                     BEC_DE_CORBIN, FAUCHARD, PARTISAN,
&nbsp;                                     LANCE };
&nbsp;
&nbsp;static struct obj *propellor;
&nbsp;
select_rwep
&nbsp;/* select a ranged weapon for the monster */
&nbsp;struct obj *
&nbsp;select_rwep(mtmp)
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    register struct obj *otmp;
&nbsp;    struct obj *mwep;
&nbsp;    boolean mweponly;
&nbsp;    int i;
&nbsp;
&nbsp;    char mlet = mtmp-&gt;data-&gt;mlet;
&nbsp;
&nbsp;    propellor = &amp;zeroobj
&nbsp;    Oselect(EGG);      /* cockatrice egg */
&nbsp;    if (mlet == S_KOP) /* pies are first choice for Kops */
&nbsp;        Oselect(CREAM_PIE);
&nbsp;    if (throws_rocks(mtmp-&gt;data)) /* ...boulders for giants */
&nbsp;        Oselect(BOULDER);
&nbsp;
&nbsp;    /* Select polearms first; they do more damage and aren't expendable.
&nbsp;       But don't pick one if monster's weapon is welded, because then
&nbsp;       we'd never have a chance to throw non-wielding missiles. */
&nbsp;    /* The limit of 13 here is based on the monster polearm range limit
&nbsp;     * (defined as 5 in mthrowu.c).  5 corresponds to a distance of 2 in
&nbsp;     * one direction and 1 in another; one space beyond that would be 3 in
&nbsp;     * one direction and 2 in another; 3^2+2^2=13.
&nbsp;     */
&nbsp;    mwep = MON_WEP(mtmp);
&nbsp;    /* NO_WEAPON_WANTED means we already tried to wield and failed */
&nbsp;    mweponly = (mwelded(mwep) &amp;&amp; mtmp-&gt;weapon_check == NO_WEAPON_WANTED);
&nbsp;    if (dist2(mtmp-&gt;mx, mtmp-&gt;my, mtmp-&gt;mux, mtmp-&gt;muy) &lt;= 13
&nbsp;        &amp;&amp; couldsee(mtmp-&gt;mx, mtmp-&gt;my)) {
&nbsp;        for (i = 0; i &lt; SIZE(pwep); i++) {
&nbsp;            /* Only strong monsters can wield big (esp. long) weapons.
&nbsp;             * Big weapon is basically the same as bimanual.
&nbsp;             * All monsters can wield the remaining weapons.
&nbsp;             */
&nbsp;            if (((strongmonst(mtmp-&gt;data)
&nbsp;                  &amp;&amp; (mtmp-&gt;misc_worn_check &amp; W_ARMS) == 0)
&nbsp;                 || !objects[pwep[i]].oc_bimanual)
&nbsp;                &amp;&amp; (objects[pwep[i]].oc_material != SILVER
&nbsp;                    || !mon_hates_silver(mtmp))) {
&nbsp;                if ((otmp = oselect(mtmp, pwep[i])) != 0
&nbsp;                    &amp;&amp; (otmp == mwep || !mweponly)) {
&nbsp;                    propellor = otmp; /* force the monster to wield it */
&nbsp;                    return otmp;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /*
&nbsp;     * other than these two specific cases, always select the
&nbsp;     * most potent ranged weapon to hand.
&nbsp;     */
&nbsp;    for (i = 0; i &lt; SIZE(rwep); i++) {
&nbsp;        int prop;
&nbsp;
&nbsp;        /* shooting gems from slings; this goes just before the darts */
&nbsp;        /* (shooting rocks is already handled via the rwep[] ordering) */
&nbsp;        if (rwep[i] == DART &amp;&amp; !likes_gems(mtmp-&gt;data)
&nbsp;            &amp;&amp; m_carrying(mtmp, SLING)) { /* propellor */
&nbsp;            for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj)
&nbsp;                if (otmp-&gt;oclass == GEM_CLASS
&nbsp;                    &amp;&amp; (otmp-&gt;otyp != LOADSTONE || !otmp-&gt;cursed)) {
&nbsp;                    propellor = m_carrying(mtmp, SLING);
&nbsp;                    return otmp;
&nbsp;                }
&nbsp;        }
&nbsp;
&nbsp;        /* KMH -- This belongs here so darts will work */
&nbsp;        propellor = &amp;zeroobj
&nbsp;
&nbsp;        prop = (objects[rwep[i]]).oc_skill;
&nbsp;        if (prop &lt; 0) {
&nbsp;            switch (-prop) {
&nbsp;            case P_BOW:
&nbsp;                propellor = (oselect(mtmp, YUMI));
&nbsp;                if (!propellor)
&nbsp;                    propellor = (oselect(mtmp, ELVEN_BOW));
&nbsp;                if (!propellor)
&nbsp;                    propellor = (oselect(mtmp, BOW));
&nbsp;                if (!propellor)
&nbsp;                    propellor = (oselect(mtmp, ORCISH_BOW));
&nbsp;                break;
&nbsp;            case P_SLING:
&nbsp;                propellor = (oselect(mtmp, SLING));
&nbsp;                break;
&nbsp;            case P_CROSSBOW:
&nbsp;                propellor = (oselect(mtmp, CROSSBOW));
&nbsp;            }
&nbsp;            if ((otmp = MON_WEP(mtmp)) &amp;&amp; mwelded(otmp) &amp;&amp; otmp != propellor
&nbsp;                &amp;&amp; mtmp-&gt;weapon_check == NO_WEAPON_WANTED)
&nbsp;                propellor = 0;
&nbsp;        }
&nbsp;        /* propellor = obj, propellor to use
&nbsp;         * propellor = &amp;zeroobj, doesn't need a propellor
&nbsp;         * propellor = 0, needed one and didn't have one
&nbsp;         */
&nbsp;        if (propellor != 0) {
&nbsp;            /* Note: cannot use m_carrying for loadstones, since it will
&nbsp;             * always select the first object of a type, and maybe the
&nbsp;             * monster is carrying two but only the first is unthrowable.
&nbsp;             */
&nbsp;            if (rwep[i] != LOADSTONE) {
&nbsp;                /* Don't throw a cursed weapon-in-hand or an artifact */
&nbsp;                if ((otmp = oselect(mtmp, rwep[i])) &amp;&amp; !otmp-&gt;oartifact
&nbsp;                    &amp;&amp; !(otmp == MON_WEP(mtmp) &amp;&amp; mwelded(otmp)))
&nbsp;                    return otmp;
&nbsp;            } else
&nbsp;                for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj) {
&nbsp;                    if (otmp-&gt;otyp == LOADSTONE &amp;&amp; !otmp-&gt;cursed)
&nbsp;                        return otmp;
&nbsp;                }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* failure */
&nbsp;    return (struct obj *) 0;
&nbsp;}
&nbsp;
&nbsp;/* Weapons in order of preference */
&nbsp;static const NEARDATA short hwep[] = {
&nbsp;    CORPSE, /* cockatrice corpse */
&nbsp;    TSURUGI, RUNESWORD, DWARVISH_MATTOCK, TWO_HANDED_SWORD, BATTLE_AXE,
&nbsp;    KATANA, UNICORN_HORN, CRYSKNIFE, TRIDENT, LONG_SWORD, ELVEN_BROADSWORD,
&nbsp;    BROADSWORD, SCIMITAR, SILVER_SABER, MORNING_STAR, ELVEN_SHORT_SWORD,
&nbsp;    DWARVISH_SHORT_SWORD, SHORT_SWORD, ORCISH_SHORT_SWORD, MACE, AXE,
&nbsp;    DWARVISH_SPEAR, SILVER_SPEAR, ELVEN_SPEAR, SPEAR, ORCISH_SPEAR, FLAIL,
&nbsp;    BULLWHIP, QUARTERSTAFF, JAVELIN, AKLYS, CLUB, PICK_AXE, RUBBER_HOSE,
&nbsp;    WAR_HAMMER, SILVER_DAGGER, ELVEN_DAGGER, DAGGER, ORCISH_DAGGER, ATHAME,
&nbsp;    SCALPEL, KNIFE, WORM_TOOTH
&nbsp;};
&nbsp;
select_hwep
&nbsp;/* select a hand to hand weapon for the monster */
&nbsp;struct obj *
&nbsp;select_hwep(mtmp)
&nbsp;register struct monst *mtmp;
&nbsp;{
&nbsp;    register struct obj *otmp;
&nbsp;    register int i;
&nbsp;    boolean strong = strongmonst(mtmp-&gt;data);
&nbsp;    boolean wearing_shield = (mtmp-&gt;misc_worn_check &amp; W_ARMS) != 0;
&nbsp;
&nbsp;    /* prefer artifacts to everything else */
&nbsp;    for (otmp = mtmp-&gt;minvent; otmp; otmp = otmp-&gt;nobj) {
&nbsp;        if (otmp-&gt;oclass == WEAPON_CLASS &amp;&amp; otmp-&gt;oartifact
&nbsp;            &amp;&amp; touch_artifact(otmp, mtmp)
&nbsp;            &amp;&amp; ((strong &amp;&amp; !wearing_shield)
&nbsp;                || !objects[otmp-&gt;otyp].oc_bimanual))
&nbsp;            return otmp;
&nbsp;    }
&nbsp;
&nbsp;    if (is_giant(mtmp-&gt;data)) /* giants just love to use clubs */
&nbsp;        Oselect(CLUB);
&nbsp;
&nbsp;    /* only strong monsters can wield big (esp. long) weapons */
&nbsp;    /* big weapon is basically the same as bimanual */
&nbsp;    /* all monsters can wield the remaining weapons */
&nbsp;    for (i = 0; i &lt; SIZE(hwep); i++) {
&nbsp;        if (hwep[i] == CORPSE &amp;&amp; !(mtmp-&gt;misc_worn_check &amp; W_ARMG)
&nbsp;            &amp;&amp; !resists_ston(mtmp))
&nbsp;            continue;
&nbsp;        if (((strong &amp;&amp; !wearing_shield) || !objects[hwep[i]].oc_bimanual)
&nbsp;            &amp;&amp; (objects[hwep[i]].oc_material != SILVER
&nbsp;                || !mon_hates_silver(mtmp)))
&nbsp;            Oselect(hwep[i]);
&nbsp;    }
&nbsp;
&nbsp;    /* failure */
&nbsp;    return (struct obj *) 0;
&nbsp;}
&nbsp;
possibly_unwield
&nbsp;/* Called after polymorphing a monster, robbing it, etc....  Monsters
&nbsp; * otherwise never unwield stuff on their own.  Might print message.
&nbsp; */
&nbsp;void
&nbsp;possibly_unwield(mon, polyspot)
&nbsp;struct monst *mon;
&nbsp;boolean polyspot;
&nbsp;{
&nbsp;    struct obj *obj, *mw_tmp;
&nbsp;
&nbsp;    if (!(mw_tmp = MON_WEP(mon)))
&nbsp;        return;
&nbsp;    for (obj = mon-&gt;minvent; obj; obj = obj-&gt;nobj)
&nbsp;        if (obj == mw_tmp)
&nbsp;            break;
&nbsp;    if (!obj) { /* The weapon was stolen or destroyed */
&nbsp;        MON_NOWEP(mon);
&nbsp;        mon-&gt;weapon_check = NEED_WEAPON;
&nbsp;        return;
&nbsp;    }
&nbsp;    if (!attacktype(mon-&gt;data, AT_WEAP)) {
&nbsp;        setmnotwielded(mon, mw_tmp);
&nbsp;        mon-&gt;weapon_check = NO_WEAPON_WANTED;
&nbsp;        obj_extract_self(obj);
&nbsp;        if (cansee(mon-&gt;mx, mon-&gt;my)) {
&nbsp;            pline("%s drops %s.", Monnam(mon), distant_name(obj, doname));
&nbsp;            newsym(mon-&gt;mx, mon-&gt;my);
&nbsp;        }
&nbsp;        /* might be dropping object into water or lava */
&nbsp;        if (!flooreffects(obj, mon-&gt;mx, mon-&gt;my, "drop")) {
&nbsp;            if (polyspot)
&nbsp;                bypass_obj(obj);
&nbsp;            place_object(obj, mon-&gt;mx, mon-&gt;my);
&nbsp;            stackobj(obj);
&nbsp;        }
&nbsp;        return;
&nbsp;    }
&nbsp;    /* The remaining case where there is a change is where a monster
&nbsp;     * is polymorphed into a stronger/weaker monster with a different
&nbsp;     * choice of weapons.  This has no parallel for players.  It can
&nbsp;     * be handled by waiting until mon_wield_item is actually called.
&nbsp;     * Though the monster still wields the wrong weapon until then,
&nbsp;     * this is OK since the player can't see it.  (FIXME: Not okay since
&nbsp;     * probing can reveal it.)
&nbsp;     * Note that if there is no change, setting the check to NEED_WEAPON
&nbsp;     * is harmless.
&nbsp;     * Possible problem: big monster with big cursed weapon gets
&nbsp;     * polymorphed into little monster.  But it's not quite clear how to
&nbsp;     * handle this anyway....
&nbsp;     */
&nbsp;    if (!(mwelded(mw_tmp) &amp;&amp; mon-&gt;weapon_check == NO_WEAPON_WANTED))
&nbsp;        mon-&gt;weapon_check = NEED_WEAPON;
&nbsp;    return;
&nbsp;}
&nbsp;
mon_wield_item
&nbsp;/* Let a monster try to wield a weapon, based on mon-&gt;weapon_check.
&nbsp; * Returns 1 if the monster took time to do it, 0 if it did not.
&nbsp; */
&nbsp;int
&nbsp;mon_wield_item(mon)
&nbsp;register struct monst *mon;
&nbsp;{
&nbsp;    struct obj *obj;
&nbsp;
&nbsp;    /* This case actually should never happen */
&nbsp;    if (mon-&gt;weapon_check == NO_WEAPON_WANTED)
&nbsp;        return 0;
&nbsp;    switch (mon-&gt;weapon_check) {
&nbsp;    case NEED_HTH_WEAPON:
&nbsp;        obj = select_hwep(mon);
&nbsp;        break;
&nbsp;    case NEED_RANGED_WEAPON:
&nbsp;        (void) select_rwep(mon);
&nbsp;        obj = propellor;
&nbsp;        break;
&nbsp;    case NEED_PICK_AXE:
&nbsp;        obj = m_carrying(mon, PICK_AXE);
&nbsp;        /* KMH -- allow other picks */
&nbsp;        if (!obj &amp;&amp; !which_armor(mon, W_ARMS))
&nbsp;            obj = m_carrying(mon, DWARVISH_MATTOCK);
&nbsp;        break;
&nbsp;    case NEED_AXE:
&nbsp;        /* currently, only 2 types of axe */
&nbsp;        obj = m_carrying(mon, BATTLE_AXE);
&nbsp;        if (!obj || which_armor(mon, W_ARMS))
&nbsp;            obj = m_carrying(mon, AXE);
&nbsp;        break;
&nbsp;    case NEED_PICK_OR_AXE:
&nbsp;        /* prefer pick for fewer switches on most levels */
&nbsp;        obj = m_carrying(mon, DWARVISH_MATTOCK);
&nbsp;        if (!obj)
&nbsp;            obj = m_carrying(mon, BATTLE_AXE);
&nbsp;        if (!obj || which_armor(mon, W_ARMS)) {
&nbsp;            obj = m_carrying(mon, PICK_AXE);
&nbsp;            if (!obj)
&nbsp;                obj = m_carrying(mon, AXE);
&nbsp;        }
&nbsp;        break;
&nbsp;    default:
&nbsp;        impossible("weapon_check %d for %s?", mon-&gt;weapon_check,
&nbsp;                   mon_nam(mon));
&nbsp;        return 0;
&nbsp;    }
&nbsp;    if (obj &amp;&amp; obj != &amp;zeroobj) {
&nbsp;        struct obj *mw_tmp = MON_WEP(mon);
&nbsp;        if (mw_tmp &amp;&amp; mw_tmp-&gt;otyp == obj-&gt;otyp) {
&nbsp;            /* already wielding it */
&nbsp;            mon-&gt;weapon_check = NEED_WEAPON;
&nbsp;            return 0;
&nbsp;        }
&nbsp;        /* Actually, this isn't necessary--as soon as the monster
&nbsp;         * wields the weapon, the weapon welds itself, so the monster
&nbsp;         * can know it's cursed and needn't even bother trying.
&nbsp;         * Still....
&nbsp;         */
&nbsp;        if (mw_tmp &amp;&amp; mwelded(mw_tmp)) {
&nbsp;            if (canseemon(mon)) {
&nbsp;                char welded_buf[BUFSZ];
&nbsp;                const char *mon_hand = mbodypart(mon, HAND);
&nbsp;
&nbsp;                if (bimanual(mw_tmp))
&nbsp;                    mon_hand = makeplural(mon_hand);
&nbsp;                Sprintf(welded_buf, "%s welded to %s %s",
&nbsp;                        otense(mw_tmp, "are"), mhis(mon), mon_hand);
&nbsp;
&nbsp;                if (obj-&gt;otyp == PICK_AXE) {
&nbsp;                    pline("Since %s weapon%s %s,", s_suffix(mon_nam(mon)),
&nbsp;                          plur(mw_tmp-&gt;quan), welded_buf);
&nbsp;                    pline("%s cannot wield that %s.", mon_nam(mon),
&nbsp;                          xname(obj));
&nbsp;                } else {
&nbsp;                    pline("%s tries to wield %s.", Monnam(mon), doname(obj));
&nbsp;                    pline("%s %s!", Yname2(mw_tmp), welded_buf);
&nbsp;                }
&nbsp;                mw_tmp-&gt;bknown = 1;
&nbsp;            }
&nbsp;            mon-&gt;weapon_check = NO_WEAPON_WANTED;
&nbsp;            return 1;
&nbsp;        }
&nbsp;        mon-&gt;mw = obj; /* wield obj */
&nbsp;        setmnotwielded(mon, mw_tmp);
&nbsp;        mon-&gt;weapon_check = NEED_WEAPON;
&nbsp;        if (canseemon(mon)) {
&nbsp;            pline("%s wields %s!", Monnam(mon), doname(obj));
&nbsp;            if (mwelded(mw_tmp)) {
&nbsp;                pline("%s %s to %s %s!", Tobjnam(obj, "weld"),
&nbsp;                      is_plural(obj) ? "themselves" : "itself",
&nbsp;                      s_suffix(mon_nam(mon)), mbodypart(mon, HAND));
&nbsp;                obj-&gt;bknown = 1;
&nbsp;            }
&nbsp;        }
&nbsp;        if (artifact_light(obj) &amp;&amp; !obj-&gt;lamplit) {
&nbsp;            begin_burn(obj, FALSE);
&nbsp;            if (canseemon(mon))
&nbsp;                pline("%s %s in %s %s!", Tobjnam(obj, "shine"),
&nbsp;                      arti_light_description(obj), s_suffix(mon_nam(mon)),
&nbsp;                      mbodypart(mon, HAND));
&nbsp;        }
&nbsp;        obj-&gt;owornmask = W_WEP;
&nbsp;        return 1;
&nbsp;    }
&nbsp;    mon-&gt;weapon_check = NEED_WEAPON;
&nbsp;    return 0;
&nbsp;}
&nbsp;
mwepgone
&nbsp;/* force monster to stop wielding current weapon, if any */
&nbsp;void
&nbsp;mwepgone(mon)
&nbsp;struct monst *mon;
&nbsp;{
&nbsp;    struct obj *mwep = MON_WEP(mon);
&nbsp;
&nbsp;    if (mwep) {
&nbsp;        setmnotwielded(mon, mwep);
&nbsp;        mon-&gt;weapon_check = NEED_WEAPON;
&nbsp;    }
&nbsp;}
&nbsp;
abon
&nbsp;/* attack bonus for strength &amp; dexterity */
&nbsp;int
&nbsp;abon()
&nbsp;{
&nbsp;    int sbon;
&nbsp;    int str = ACURR(A_STR), dex = ACURR(A_DEX);
&nbsp;
&nbsp;    if (Upolyd)
&nbsp;        return (adj_lev(&amp;mons[u.umonnum]) - 3);
&nbsp;    if (str &lt; 6)
&nbsp;        sbon = -2;
&nbsp;    else if (str &lt; 8)
&nbsp;        sbon = -1;
&nbsp;    else if (str &lt; 17)
&nbsp;        sbon = 0;
&nbsp;    else if (str &lt;= STR18(50))
&nbsp;        sbon = 1; /* up to 18/50 */
&nbsp;    else if (str &lt; STR18(100))
&nbsp;        sbon = 2;
&nbsp;    else
&nbsp;        sbon = 3;
&nbsp;
&nbsp;    /* Game tuning kludge: make it a bit easier for a low level character to
&nbsp;     * hit */
&nbsp;    sbon += (u.ulevel &lt; 3) ? 1 : 0;
&nbsp;
&nbsp;    if (dex &lt; 4)
&nbsp;        return (sbon - 3);
&nbsp;    else if (dex &lt; 6)
&nbsp;        return (sbon - 2);
&nbsp;    else if (dex &lt; 8)
&nbsp;        return (sbon - 1);
&nbsp;    else if (dex &lt; 14)
&nbsp;        return sbon;
&nbsp;    else
&nbsp;        return (sbon + dex - 14);
&nbsp;}
&nbsp;
dbon
&nbsp;/* damage bonus for strength */
&nbsp;int
&nbsp;dbon()
&nbsp;{
&nbsp;    int str = ACURR(A_STR);
&nbsp;
&nbsp;    if (Upolyd)
&nbsp;        return 0;
&nbsp;
&nbsp;    if (str &lt; 6)
&nbsp;        return -1;
&nbsp;    else if (str &lt; 16)
&nbsp;        return 0;
&nbsp;    else if (str &lt; 18)
&nbsp;        return 1;
&nbsp;    else if (str == 18)
&nbsp;        return 2; /* up to 18 */
&nbsp;    else if (str &lt;= STR18(75))
&nbsp;        return 3; /* up to 18/75 */
&nbsp;    else if (str &lt;= STR18(90))
&nbsp;        return 4; /* up to 18/90 */
&nbsp;    else if (str &lt; STR18(100))
&nbsp;        return 5; /* up to 18/99 */
&nbsp;    else
&nbsp;        return 6;
&nbsp;}
&nbsp;
wet_a_towel
&nbsp;/* increase a towel's wetness */
&nbsp;void
&nbsp;wet_a_towel(obj, amt, verbose)
&nbsp;struct obj *obj;
&nbsp;int amt; /* positive: new value; negative: increment by -amt; zero: no-op */
&nbsp;boolean verbose;
&nbsp;{
&nbsp;    int newspe = (amt &lt;= 0) ? obj-&gt;spe - amt : amt;
&nbsp;
&nbsp;    /* new state is only reported if it's an increase */
&nbsp;    if (newspe &gt; obj-&gt;spe) {
&nbsp;        if (verbose) {
&nbsp;            const char *wetness = (newspe &lt; 3)
&nbsp;                                     ? (!obj-&gt;spe ? "damp" : "damper")
&nbsp;                                     : (!obj-&gt;spe ? "wet" : "wetter");
&nbsp;
&nbsp;            if (carried(obj))
&nbsp;                pline("%s gets %s.", Yobjnam2(obj, (const char *) 0),
&nbsp;                      wetness);
&nbsp;            else if (mcarried(obj) &amp;&amp; canseemon(obj-&gt;ocarry))
&nbsp;                pline("%s %s gets %s.", s_suffix(Monnam(obj-&gt;ocarry)),
&nbsp;                      xname(obj), wetness);
&nbsp;        }
&nbsp;    }
&nbsp;    obj-&gt;spe = min(newspe, 7);
&nbsp;
&nbsp;    /* if hero is wielding this towel, don't give "you begin bashing
&nbsp;       with your wet towel" message on next attack with it */
&nbsp;    if (obj == uwep)
&nbsp;        unweapon = !is_wet_towel(obj);
&nbsp;}
&nbsp;
dry_a_towel
&nbsp;/* decrease a towel's wetness */
&nbsp;void
&nbsp;dry_a_towel(obj, amt, verbose)
&nbsp;struct obj *obj;
&nbsp;int amt; /* positive: new value; negative: decrement by -amt; zero: no-op */
&nbsp;boolean verbose;
&nbsp;{
&nbsp;    int newspe = (amt &lt;= 0) ? obj-&gt;spe + amt : amt;
&nbsp;
&nbsp;    /* new state is only reported if it's a decrease */
&nbsp;    if (newspe &lt; obj-&gt;spe) {
&nbsp;        if (verbose) {
&nbsp;            if (carried(obj))
&nbsp;                pline("%s dries%s.", Yobjnam2(obj, (const char *) 0),
&nbsp;                      !newspe ? " out" : "");
&nbsp;            else if (mcarried(obj) &amp;&amp; canseemon(obj-&gt;ocarry))
&nbsp;                pline("%s %s drie%s.", s_suffix(Monnam(obj-&gt;ocarry)),
&nbsp;                      xname(obj), !newspe ? " out" : "");
&nbsp;        }
&nbsp;    }
&nbsp;    newspe = min(newspe, 7);
&nbsp;    obj-&gt;spe = max(newspe, 0);
&nbsp;
&nbsp;    /* if hero is wielding this towel and it is now dry, give "you begin
&nbsp;       bashing with your towel" message on next attack with it */
&nbsp;    if (obj == uwep)
&nbsp;        unweapon = !is_wet_towel(obj);
&nbsp;}
&nbsp;
skill_level_name
&nbsp;/* copy the skill level name into the given buffer */
&nbsp;STATIC_OVL char *
&nbsp;skill_level_name(skill, buf)
&nbsp;int skill;
&nbsp;char *buf;
&nbsp;{
&nbsp;    const char *ptr;
&nbsp;
&nbsp;    switch (P_SKILL(skill)) {
&nbsp;    case P_UNSKILLED:
&nbsp;        ptr = "Unskilled";
&nbsp;        break;
&nbsp;    case P_BASIC:
&nbsp;        ptr = "Basic";
&nbsp;        break;
&nbsp;    case P_SKILLED:
&nbsp;        ptr = "Skilled";
&nbsp;        break;
&nbsp;    case P_EXPERT:
&nbsp;        ptr = "Expert";
&nbsp;        break;
&nbsp;    /* these are for unarmed combat/martial arts only */
&nbsp;    case P_MASTER:
&nbsp;        ptr = "Master";
&nbsp;        break;
&nbsp;    case P_GRAND_MASTER:
&nbsp;        ptr = "Grand Master";
&nbsp;        break;
&nbsp;    default:
&nbsp;        ptr = "Unknown";
&nbsp;        break;
&nbsp;    }
&nbsp;    Strcpy(buf, ptr);
&nbsp;    return buf;
&nbsp;}
&nbsp;
slots_required
&nbsp;/* return the # of slots required to advance the skill */
&nbsp;STATIC_OVL int
&nbsp;slots_required(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    int tmp = P_SKILL(skill);
&nbsp;
&nbsp;    /* The more difficult the training, the more slots it takes.
&nbsp;     *  unskilled -&gt; basic      1
&nbsp;     *  basic -&gt; skilled        2
&nbsp;     *  skilled -&gt; expert       3
&nbsp;     */
&nbsp;    if (skill &lt;= P_LAST_WEAPON || skill == P_TWO_WEAPON_COMBAT)
&nbsp;        return tmp;
&nbsp;
&nbsp;    /* Fewer slots used up for unarmed or martial.
&nbsp;     *  unskilled -&gt; basic      1
&nbsp;     *  basic -&gt; skilled        1
&nbsp;     *  skilled -&gt; expert       2
&nbsp;     *  expert -&gt; master        2
&nbsp;     *  master -&gt; grand master  3
&nbsp;     */
&nbsp;    return (tmp + 1) / 2;
&nbsp;}
&nbsp;
can_advance
&nbsp;/* return true if this skill can be advanced */
&nbsp;/*ARGSUSED*/
&nbsp;STATIC_OVL boolean
&nbsp;can_advance(skill, speedy)
&nbsp;int skill;
&nbsp;boolean speedy;
&nbsp;{
&nbsp;    if (P_RESTRICTED(skill)
&nbsp;        || P_SKILL(skill) &gt;= P_MAX_SKILL(skill)
&nbsp;        || u.skills_advanced &gt;= P_SKILL_LIMIT)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    if (wizard &amp;&amp; speedy)
&nbsp;        return TRUE;
&nbsp;
&nbsp;    return (boolean) ((int) P_ADVANCE(skill)
&nbsp;                      &gt;= practice_needed_to_advance(P_SKILL(skill))
&nbsp;                      &amp;&amp; u.weapon_slots &gt;= slots_required(skill));
&nbsp;}
&nbsp;
could_advance
&nbsp;/* return true if this skill could be advanced if more slots were available */
&nbsp;STATIC_OVL boolean
&nbsp;could_advance(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    if (P_RESTRICTED(skill)
&nbsp;        || P_SKILL(skill) &gt;= P_MAX_SKILL(skill)
&nbsp;        || u.skills_advanced &gt;= P_SKILL_LIMIT)
&nbsp;        return FALSE;
&nbsp;
&nbsp;    return (boolean) ((int) P_ADVANCE(skill)
&nbsp;                      &gt;= practice_needed_to_advance(P_SKILL(skill)));
&nbsp;}
&nbsp;
peaked_skill
&nbsp;/* return true if this skill has reached its maximum and there's been enough
&nbsp;   practice to become eligible for the next step if that had been possible */
&nbsp;STATIC_OVL boolean
&nbsp;peaked_skill(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    if (P_RESTRICTED(skill))
&nbsp;        return FALSE;
&nbsp;
&nbsp;    return (boolean) (P_SKILL(skill) &gt;= P_MAX_SKILL(skill)
&nbsp;                      &amp;&amp; ((int) P_ADVANCE(skill)
&nbsp;                          &gt;= practice_needed_to_advance(P_SKILL(skill))));
&nbsp;}
&nbsp;
skill_advance
&nbsp;STATIC_OVL void
&nbsp;skill_advance(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    u.weapon_slots -= slots_required(skill);
&nbsp;    P_SKILL(skill)++;
&nbsp;    u.skill_record[u.skills_advanced++] = skill;
&nbsp;    /* subtly change the advance message to indicate no more advancement */
&nbsp;    You("are now %s skilled in %s.",
&nbsp;        P_SKILL(skill) &gt;= P_MAX_SKILL(skill) ? "most" : "more",
&nbsp;        P_NAME(skill));
&nbsp;}
&nbsp;
&nbsp;static const struct skill_range {
&nbsp;    short first, last;
&nbsp;    const char *name;
&nbsp;} skill_ranges[] = {
&nbsp;    { P_FIRST_H_TO_H, P_LAST_H_TO_H, "Fighting Skills" },
&nbsp;    { P_FIRST_WEAPON, P_LAST_WEAPON, "Weapon Skills" },
&nbsp;    { P_FIRST_SPELL, P_LAST_SPELL, "Spellcasting Skills" },
&nbsp;};
&nbsp;
enhance_weapon_skill
&nbsp;/*
&nbsp; * The `#enhance' extended command.  What we _really_ would like is
&nbsp; * to keep being able to pick things to advance until we couldn't any
&nbsp; * more.  This is currently not possible -- the menu code has no way
&nbsp; * to call us back for instant action.  Even if it did, we would also need
&nbsp; * to be able to update the menu since selecting one item could make
&nbsp; * others unselectable.
&nbsp; */
&nbsp;int
&nbsp;enhance_weapon_skill()
&nbsp;{
&nbsp;    int pass, i, n, len, longest, to_advance, eventually_advance, maxxed_cnt;
&nbsp;    char buf[BUFSZ], sklnambuf[BUFSZ];
&nbsp;    const char *prefix;
&nbsp;    menu_item *selected;
&nbsp;    anything any;
&nbsp;    winid win;
&nbsp;    boolean speedy = FALSE;
&nbsp;
&nbsp;    if (wizard &amp;&amp; yn("Advance skills without practice?") == 'y')
&nbsp;        speedy = TRUE;
&nbsp;
&nbsp;    do {
&nbsp;        /* find longest available skill name, count those that can advance */
&nbsp;        to_advance = eventually_advance = maxxed_cnt = 0;
&nbsp;        for (longest = 0, i = 0; i &lt; P_NUM_SKILLS; i++) {
&nbsp;            if (P_RESTRICTED(i))
&nbsp;                continue;
&nbsp;            if ((len = strlen(P_NAME(i))) &gt; longest)
&nbsp;                longest = len;
&nbsp;            if (can_advance(i, speedy))
&nbsp;                to_advance++;
&nbsp;            else if (could_advance(i))
&nbsp;                eventually_advance++;
&nbsp;            else if (peaked_skill(i))
&nbsp;                maxxed_cnt++;
&nbsp;        }
&nbsp;
&nbsp;        win = create_nhwindow(NHW_MENU);
&nbsp;        start_menu(win);
&nbsp;
&nbsp;        /* start with a legend if any entries will be annotated
&nbsp;           with "*" or "#" below */
&nbsp;        if (eventually_advance &gt; 0 || maxxed_cnt &gt; 0) {
&nbsp;            any = zeroany;
&nbsp;            if (eventually_advance &gt; 0) {
&nbsp;                Sprintf(buf, "(Skill%s flagged by \"*\" may be enhanced %s.)",
&nbsp;                        plur(eventually_advance),
&nbsp;                        (u.ulevel &lt; MAXULEV)
&nbsp;                            ? "when you're more experienced"
&nbsp;                            : "if skill slots become available");
&nbsp;                add_menu(win, NO_GLYPH, &amp;any, 0, 0, ATR_NONE, buf,
&nbsp;                         MENU_UNSELECTED);
&nbsp;            }
&nbsp;            if (maxxed_cnt &gt; 0) {
&nbsp;                Sprintf(buf,
&nbsp;                 "(Skill%s flagged by \"#\" cannot be enhanced any further.)",
&nbsp;                        plur(maxxed_cnt));
&nbsp;                add_menu(win, NO_GLYPH, &amp;any, 0, 0, ATR_NONE, buf,
&nbsp;                         MENU_UNSELECTED);
&nbsp;            }
&nbsp;            add_menu(win, NO_GLYPH, &amp;any, 0, 0, ATR_NONE, "",
&nbsp;                     MENU_UNSELECTED);
&nbsp;        }
&nbsp;
&nbsp;        /* List the skills, making ones that could be advanced
&nbsp;           selectable.  List the miscellaneous skills first.
&nbsp;           Possible future enhancement:  list spell skills before
&nbsp;           weapon skills for spellcaster roles. */
&nbsp;        for (pass = 0; pass &lt; SIZE(skill_ranges); pass++)
&nbsp;            for (i = skill_ranges[pass].first; i &lt;= skill_ranges[pass].last;
&nbsp;                 i++) {
&nbsp;                /* Print headings for skill types */
&nbsp;                any = zeroany;
&nbsp;                if (i == skill_ranges[pass].first)
&nbsp;                    add_menu(win, NO_GLYPH, &amp;any, 0, 0, iflags.menu_headings,
&nbsp;                             skill_ranges[pass].name, MENU_UNSELECTED);
&nbsp;
&nbsp;                if (P_RESTRICTED(i))
&nbsp;                    continue;
&nbsp;                /*
&nbsp;                 * Sigh, this assumes a monospaced font unless
&nbsp;                 * iflags.menu_tab_sep is set in which case it puts
&nbsp;                 * tabs between columns.
&nbsp;                 * The 12 is the longest skill level name.
&nbsp;                 * The "    " is room for a selection letter and dash, "a - ".
&nbsp;                 */
&nbsp;                if (can_advance(i, speedy))
&nbsp;                    prefix = ""; /* will be preceded by menu choice */
&nbsp;                else if (could_advance(i))
&nbsp;                    prefix = "  * ";
&nbsp;                else if (peaked_skill(i))
&nbsp;                    prefix = "  # ";
&nbsp;                else
&nbsp;                    prefix =
&nbsp;                        (to_advance + eventually_advance + maxxed_cnt &gt; 0)
&nbsp;                            ? "    "
&nbsp;                            : "";
&nbsp;                (void) skill_level_name(i, sklnambuf);
&nbsp;                if (wizard) {
&nbsp;                    if (!iflags.menu_tab_sep)
&nbsp;                        Sprintf(buf, " %s%-*s %-12s %5d(%4d)", prefix,
&nbsp;                                longest, P_NAME(i), sklnambuf, P_ADVANCE(i),
&nbsp;                                practice_needed_to_advance(P_SKILL(i)));
&nbsp;                    else
&nbsp;                        Sprintf(buf, " %s%s\t%s\t%5d(%4d)", prefix, P_NAME(i),
&nbsp;                                sklnambuf, P_ADVANCE(i),
&nbsp;                                practice_needed_to_advance(P_SKILL(i)));
&nbsp;                } else {
&nbsp;                    if (!iflags.menu_tab_sep)
&nbsp;                        Sprintf(buf, " %s %-*s [%s]", prefix, longest,
&nbsp;                                P_NAME(i), sklnambuf);
&nbsp;                    else
&nbsp;                        Sprintf(buf, " %s%s\t[%s]", prefix, P_NAME(i),
&nbsp;                                sklnambuf);
&nbsp;                }
&nbsp;                any.a_int = can_advance(i, speedy) ? i + 1 : 0;
&nbsp;                add_menu(win, NO_GLYPH, &amp;any, 0, 0, ATR_NONE, buf,
&nbsp;                         MENU_UNSELECTED);
&nbsp;            }
&nbsp;
&nbsp;        Strcpy(buf, (to_advance &gt; 0) ? "Pick a skill to advance:"
&nbsp;                                     : "Current skills:");
&nbsp;        if (wizard &amp;&amp; !speedy)
&nbsp;            Sprintf(eos(buf), "  (%d slot%s available)", u.weapon_slots,
&nbsp;                    plur(u.weapon_slots));
&nbsp;        end_menu(win, buf);
&nbsp;        n = select_menu(win, to_advance ? PICK_ONE : PICK_NONE, &amp;selected);
&nbsp;        destroy_nhwindow(win);
&nbsp;        if (n &gt; 0) {
&nbsp;            n = selected[0].item.a_int - 1; /* get item selected */
&nbsp;            free((genericptr_t) selected);
&nbsp;            skill_advance(n);
&nbsp;            /* check for more skills able to advance, if so then .. */
&nbsp;            for (n = i = 0; i &lt; P_NUM_SKILLS; i++) {
&nbsp;                if (can_advance(i, speedy)) {
&nbsp;                    if (!speedy)
&nbsp;                        You_feel("you could be more dangerous!");
&nbsp;                    n++;
&nbsp;                    break;
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;    } while (speedy &amp;&amp; n &gt; 0);
&nbsp;    return 0;
&nbsp;}
&nbsp;
unrestrict_weapon_skill
&nbsp;/*
&nbsp; * Change from restricted to unrestricted, allowing P_BASIC as max.  This
&nbsp; * function may be called with with P_NONE.  Used in pray.c as well as below.
&nbsp; */
&nbsp;void
&nbsp;unrestrict_weapon_skill(skill)
&nbsp;int skill;
&nbsp;{
&nbsp;    if (skill &lt; P_NUM_SKILLS &amp;&amp; P_RESTRICTED(skill)) {
&nbsp;        P_SKILL(skill) = P_UNSKILLED;
&nbsp;        P_MAX_SKILL(skill) = P_BASIC;
&nbsp;        P_ADVANCE(skill) = 0;
&nbsp;    }
&nbsp;}
&nbsp;
use_skill
&nbsp;void
&nbsp;use_skill(skill, degree)
&nbsp;int skill;
&nbsp;int degree;
&nbsp;{
&nbsp;    boolean advance_before;
&nbsp;
&nbsp;    if (skill != P_NONE &amp;&amp; !P_RESTRICTED(skill)) {
&nbsp;        advance_before = can_advance(skill, FALSE);
&nbsp;        P_ADVANCE(skill) += degree;
&nbsp;        if (!advance_before &amp;&amp; can_advance(skill, FALSE))
&nbsp;            give_may_advance_msg(skill);
&nbsp;    }
&nbsp;}
&nbsp;
add_weapon_skill
&nbsp;void
&nbsp;add_weapon_skill(n)
&nbsp;int n; /* number of slots to gain; normally one */
&nbsp;{
&nbsp;    int i, before, after;
&nbsp;
&nbsp;    for (i = 0, before = 0; i &lt; P_NUM_SKILLS; i++)
&nbsp;        if (can_advance(i, FALSE))
&nbsp;            before++;
&nbsp;    u.weapon_slots += n;
&nbsp;    for (i = 0, after = 0; i &lt; P_NUM_SKILLS; i++)
&nbsp;        if (can_advance(i, FALSE))
&nbsp;            after++;
&nbsp;    if (before &lt; after)
&nbsp;        give_may_advance_msg(P_NONE);
&nbsp;}
&nbsp;
lose_weapon_skill
&nbsp;void
&nbsp;lose_weapon_skill(n)
&nbsp;int n; /* number of slots to lose; normally one */
&nbsp;{
&nbsp;    int skill;
&nbsp;
&nbsp;    while (--n &gt;= 0) {
&nbsp;        /* deduct first from unused slots then from last placed one, if any */
&nbsp;        if (u.weapon_slots) {
&nbsp;            u.weapon_slots--;
&nbsp;        } else if (u.skills_advanced) {
&nbsp;            skill = u.skill_record[--u.skills_advanced];
&nbsp;            if (P_SKILL(skill) &lt;= P_UNSKILLED)
&nbsp;                panic("lose_weapon_skill (%d)", skill);
&nbsp;            P_SKILL(skill)--; /* drop skill one level */
&nbsp;            /* Lost skill might have taken more than one slot; refund rest. */
&nbsp;            u.weapon_slots = slots_required(skill) - 1;
&nbsp;            /* It might now be possible to advance some other pending
&nbsp;               skill by using the refunded slots, but giving a message
&nbsp;               to that effect would seem pretty confusing.... */
&nbsp;        }
&nbsp;    }
&nbsp;}
&nbsp;
weapon_type
&nbsp;int
&nbsp;weapon_type(obj)
&nbsp;struct obj *obj;
&nbsp;{
&nbsp;    /* KMH -- now uses the object table */
&nbsp;    int type;
&nbsp;
&nbsp;    if (!obj)
&nbsp;        return P_BARE_HANDED_COMBAT; /* Not using a weapon */
&nbsp;    if (obj-&gt;oclass != WEAPON_CLASS &amp;&amp; obj-&gt;oclass != TOOL_CLASS
&nbsp;        &amp;&amp; obj-&gt;oclass != GEM_CLASS)
&nbsp;        return P_NONE; /* Not a weapon, weapon-tool, or ammo */
&nbsp;    type = objects[obj-&gt;otyp].oc_skill;
&nbsp;    return (type &lt; 0) ? -type : type;
&nbsp;}
&nbsp;
uwep_skill_type
&nbsp;int
&nbsp;uwep_skill_type()
&nbsp;{
&nbsp;    if (u.twoweap)
&nbsp;        return P_TWO_WEAPON_COMBAT;
&nbsp;    return weapon_type(uwep);
&nbsp;}
&nbsp;
weapon_hit_bonus
&nbsp;/*
&nbsp; * Return hit bonus/penalty based on skill of weapon.
&nbsp; * Treat restricted weapons as unskilled.
&nbsp; */
&nbsp;int
&nbsp;weapon_hit_bonus(weapon)
&nbsp;struct obj *weapon;
&nbsp;{
&nbsp;    int type, wep_type, skill, bonus = 0;
&nbsp;    static const char bad_skill[] = "weapon_hit_bonus: bad skill %d";
&nbsp;
&nbsp;    wep_type = weapon_type(weapon);
&nbsp;    /* use two weapon skill only if attacking with one of the wielded weapons
&nbsp;     */
&nbsp;    type = (u.twoweap &amp;&amp; (weapon == uwep || weapon == uswapwep))
&nbsp;               ? P_TWO_WEAPON_COMBAT
&nbsp;               : wep_type;
&nbsp;    if (type == P_NONE) {
&nbsp;        bonus = 0;
&nbsp;    } else if (type &lt;= P_LAST_WEAPON) {
&nbsp;        switch (P_SKILL(type)) {
&nbsp;        default:
&nbsp;            impossible(bad_skill, P_SKILL(type)); /* fall through */
&nbsp;        case P_ISRESTRICTED:
&nbsp;        case P_UNSKILLED:
&nbsp;            bonus = -4;
&nbsp;            break;
&nbsp;        case P_BASIC:
&nbsp;            bonus = 0;
&nbsp;            break;
&nbsp;        case P_SKILLED:
&nbsp;            bonus = 2;
&nbsp;            break;
&nbsp;        case P_EXPERT:
&nbsp;            bonus = 3;
&nbsp;            break;
&nbsp;        }
&nbsp;    } else if (type == P_TWO_WEAPON_COMBAT) {
&nbsp;        skill = P_SKILL(P_TWO_WEAPON_COMBAT);
&nbsp;        if (P_SKILL(wep_type) &lt; skill)
&nbsp;            skill = P_SKILL(wep_type);
&nbsp;        switch (skill) {
&nbsp;        default:
&nbsp;            impossible(bad_skill, skill); /* fall through */
&nbsp;        case P_ISRESTRICTED:
&nbsp;        case P_UNSKILLED:
&nbsp;            bonus = -9;
&nbsp;            break;
&nbsp;        case P_BASIC:
&nbsp;            bonus = -7;
&nbsp;            break;
&nbsp;        case P_SKILLED:
&nbsp;            bonus = -5;
&nbsp;            break;
&nbsp;        case P_EXPERT:
&nbsp;            bonus = -3;
&nbsp;            break;
&nbsp;        }
&nbsp;    } else if (type == P_BARE_HANDED_COMBAT) {
&nbsp;        /*
&nbsp;         *        b.h. m.a.
&nbsp;         * unskl:  +1  n/a
&nbsp;         * basic:  +1   +3
&nbsp;         * skild:  +2   +4
&nbsp;         * exprt:  +2   +5
&nbsp;         * mastr:  +3   +6
&nbsp;         * grand:  +3   +7
&nbsp;         */
&nbsp;        bonus = P_SKILL(type);
&nbsp;        bonus = max(bonus, P_UNSKILLED) - 1; /* unskilled =&gt; 0 */
&nbsp;        bonus = ((bonus + 2) * (martial_bonus() ? 2 : 1)) / 2;
&nbsp;    }
&nbsp;
&nbsp;    /* KMH -- It's harder to hit while you are riding */
&nbsp;    if (u.usteed) {
&nbsp;        switch (P_SKILL(P_RIDING)) {
&nbsp;        case P_ISRESTRICTED:
&nbsp;        case P_UNSKILLED:
&nbsp;            bonus -= 2;
&nbsp;            break;
&nbsp;        case P_BASIC:
&nbsp;            bonus -= 1;
&nbsp;            break;
&nbsp;        case P_SKILLED:
&nbsp;            break;
&nbsp;        case P_EXPERT:
&nbsp;            break;
&nbsp;        }
&nbsp;        if (u.twoweap)
&nbsp;            bonus -= 2;
&nbsp;    }
&nbsp;
&nbsp;    return bonus;
&nbsp;}
&nbsp;
weapon_dam_bonus
&nbsp;/*
&nbsp; * Return damage bonus/penalty based on skill of weapon.
&nbsp; * Treat restricted weapons as unskilled.
&nbsp; */
&nbsp;int
&nbsp;weapon_dam_bonus(weapon)
&nbsp;struct obj *weapon;
&nbsp;{
&nbsp;    int type, wep_type, skill, bonus = 0;
&nbsp;
&nbsp;    wep_type = weapon_type(weapon);
&nbsp;    /* use two weapon skill only if attacking with one of the wielded weapons
&nbsp;     */
&nbsp;    type = (u.twoweap &amp;&amp; (weapon == uwep || weapon == uswapwep))
&nbsp;               ? P_TWO_WEAPON_COMBAT
&nbsp;               : wep_type;
&nbsp;    if (type == P_NONE) {
&nbsp;        bonus = 0;
&nbsp;    } else if (type &lt;= P_LAST_WEAPON) {
&nbsp;        switch (P_SKILL(type)) {
&nbsp;        default:
&nbsp;            impossible("weapon_dam_bonus: bad skill %d", P_SKILL(type));
&nbsp;        /* fall through */
&nbsp;        case P_ISRESTRICTED:
&nbsp;        case P_UNSKILLED:
&nbsp;            bonus = -2;
&nbsp;            break;
&nbsp;        case P_BASIC:
&nbsp;            bonus = 0;
&nbsp;            break;
&nbsp;        case P_SKILLED:
&nbsp;            bonus = 1;
&nbsp;            break;
&nbsp;        case P_EXPERT:
&nbsp;            bonus = 2;
&nbsp;            break;
&nbsp;        }
&nbsp;    } else if (type == P_TWO_WEAPON_COMBAT) {
&nbsp;        skill = P_SKILL(P_TWO_WEAPON_COMBAT);
&nbsp;        if (P_SKILL(wep_type) &lt; skill)
&nbsp;            skill = P_SKILL(wep_type);
&nbsp;        switch (skill) {
&nbsp;        default:
&nbsp;        case P_ISRESTRICTED:
&nbsp;        case P_UNSKILLED:
&nbsp;            bonus = -3;
&nbsp;            break;
&nbsp;        case P_BASIC:
&nbsp;            bonus = -1;
&nbsp;            break;
&nbsp;        case P_SKILLED:
&nbsp;            bonus = 0;
&nbsp;            break;
&nbsp;        case P_EXPERT:
&nbsp;            bonus = 1;
&nbsp;            break;
&nbsp;        }
&nbsp;    } else if (type == P_BARE_HANDED_COMBAT) {
&nbsp;        /*
&nbsp;         *        b.h. m.a.
&nbsp;         * unskl:   0  n/a
&nbsp;         * basic:  +1   +3
&nbsp;         * skild:  +1   +4
&nbsp;         * exprt:  +2   +6
&nbsp;         * mastr:  +2   +7
&nbsp;         * grand:  +3   +9
&nbsp;         */
&nbsp;        bonus = P_SKILL(type);
&nbsp;        bonus = max(bonus, P_UNSKILLED) - 1; /* unskilled =&gt; 0 */
&nbsp;        bonus = ((bonus + 1) * (martial_bonus() ? 3 : 1)) / 2;
&nbsp;    }
&nbsp;
&nbsp;    /* KMH -- Riding gives some thrusting damage */
&nbsp;    if (u.usteed &amp;&amp; type != P_TWO_WEAPON_COMBAT) {
&nbsp;        switch (P_SKILL(P_RIDING)) {
&nbsp;        case P_ISRESTRICTED:
&nbsp;        case P_UNSKILLED:
&nbsp;            break;
&nbsp;        case P_BASIC:
&nbsp;            break;
&nbsp;        case P_SKILLED:
&nbsp;            bonus += 1;
&nbsp;            break;
&nbsp;        case P_EXPERT:
&nbsp;            bonus += 2;
&nbsp;            break;
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    return bonus;
&nbsp;}
&nbsp;
skill_init
&nbsp;/*
&nbsp; * Initialize weapon skill array for the game.  Start by setting all
&nbsp; * skills to restricted, then set the skill for every weapon the
&nbsp; * hero is holding, finally reading the given array that sets
&nbsp; * maximums.
&nbsp; */
&nbsp;void
&nbsp;skill_init(class_skill)
&nbsp;const struct def_skill *class_skill;
&nbsp;{
&nbsp;    struct obj *obj;
&nbsp;    int skmax, skill;
&nbsp;
&nbsp;    /* initialize skill array; by default, everything is restricted */
&nbsp;    for (skill = 0; skill &lt; P_NUM_SKILLS; skill++) {
&nbsp;        P_SKILL(skill) = P_ISRESTRICTED;
&nbsp;        P_MAX_SKILL(skill) = P_ISRESTRICTED;
&nbsp;        P_ADVANCE(skill) = 0;
&nbsp;    }
&nbsp;
&nbsp;    /* Set skill for all weapons in inventory to be basic */
&nbsp;    for (obj = invent; obj; obj = obj-&gt;nobj) {
&nbsp;        /* don't give skill just because of carried ammo, wait until
&nbsp;           we see the relevant launcher (prevents an archeologist's
&nbsp;           touchstone from inadvertently providing skill in sling) */
&nbsp;        if (is_ammo(obj))
&nbsp;            continue;
&nbsp;
&nbsp;        skill = weapon_type(obj);
&nbsp;        if (skill != P_NONE)
&nbsp;            P_SKILL(skill) = P_BASIC;
&nbsp;    }
&nbsp;
&nbsp;    /* set skills for magic */
&nbsp;    if (Role_if(PM_HEALER) || Role_if(PM_MONK)) {
&nbsp;        P_SKILL(P_HEALING_SPELL) = P_BASIC;
&nbsp;    } else if (Role_if(PM_PRIEST)) {
&nbsp;        P_SKILL(P_CLERIC_SPELL) = P_BASIC;
&nbsp;    } else if (Role_if(PM_WIZARD)) {
&nbsp;        P_SKILL(P_ATTACK_SPELL) = P_BASIC;
&nbsp;        P_SKILL(P_ENCHANTMENT_SPELL) = P_BASIC;
&nbsp;    }
&nbsp;
&nbsp;    /* walk through array to set skill maximums */
&nbsp;    for (; class_skill-&gt;skill != P_NONE; class_skill++) {
&nbsp;        skmax = class_skill-&gt;skmax;
&nbsp;        skill = class_skill-&gt;skill;
&nbsp;
&nbsp;        P_MAX_SKILL(skill) = skmax;
&nbsp;        if (P_SKILL(skill) == P_ISRESTRICTED) /* skill pre-set */
&nbsp;            P_SKILL(skill) = P_UNSKILLED;
&nbsp;    }
&nbsp;
&nbsp;    /* High potential fighters already know how to use their hands. */
&nbsp;    if (P_MAX_SKILL(P_BARE_HANDED_COMBAT) &gt; P_EXPERT)
&nbsp;        P_SKILL(P_BARE_HANDED_COMBAT) = P_BASIC;
&nbsp;
&nbsp;    /* Roles that start with a horse know how to ride it */
&nbsp;    if (urole.petnum == PM_PONY)
&nbsp;        P_SKILL(P_RIDING) = P_BASIC;
&nbsp;
&nbsp;    /*
&nbsp;     * Make sure we haven't missed setting the max on a skill
&nbsp;     * &amp; set advance
&nbsp;     */
&nbsp;    for (skill = 0; skill &lt; P_NUM_SKILLS; skill++) {
&nbsp;        if (!P_RESTRICTED(skill)) {
&nbsp;            if (P_MAX_SKILL(skill) &lt; P_SKILL(skill)) {
&nbsp;                impossible("skill_init: curr &gt; max: %s", P_NAME(skill));
&nbsp;                P_MAX_SKILL(skill) = P_SKILL(skill);
&nbsp;            }
&nbsp;            P_ADVANCE(skill) = practice_needed_to_advance(P_SKILL(skill) - 1);
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /* each role has a special spell; allow at least basic for its type
&nbsp;       (despite the function name, this works for spell skills too) */
&nbsp;    unrestrict_weapon_skill(spell_skilltype(urole.spelspec));
&nbsp;}
&nbsp;
setmnotwielded
&nbsp;void
&nbsp;setmnotwielded(mon, obj)
&nbsp;register struct monst *mon;
&nbsp;register struct obj *obj;
&nbsp;{
&nbsp;    if (!obj)
&nbsp;        return;
&nbsp;    if (artifact_light(obj) &amp;&amp; obj-&gt;lamplit) {
&nbsp;        end_burn(obj, FALSE);
&nbsp;        if (canseemon(mon))
&nbsp;            pline("%s in %s %s %s shining.", The(xname(obj)),
&nbsp;                  s_suffix(mon_nam(mon)), mbodypart(mon, HAND),
&nbsp;                  otense(obj, "stop"));
&nbsp;    }
&nbsp;    if (MON_WEP(mon) == obj)
&nbsp;        MON_NOWEP(mon);
&nbsp;    obj-&gt;owornmask &amp;= ~W_WEP;
&nbsp;}
&nbsp;
&nbsp;/*weapon.c*/

</weapon>