Exemple #1
0
/* release the objects the creature is carrying */
void
relobj(struct monst *mtmp, int show, boolean is_pet)
{       /* If true, pet should keep wielded/worn items */
    struct obj *otmp;
    int omx = mtmp->mx, omy = mtmp->my;
    struct obj *keepobj = 0;
    struct obj *wep = MON_WEP(mtmp), *hwep = attacktype(mtmp->data, AT_WEAP)
        ? select_hwep(mtmp) : (struct obj *)0, *proj =
        attacktype(mtmp->data, AT_WEAP)
        ? select_rwep(mtmp) : (struct obj *)0, *rwep;
    boolean item1 = FALSE, item2 = FALSE;

    rwep = attacktype(mtmp->data, AT_WEAP) ? propellor : &zeroobj;


    if (!is_pet || mindless(mtmp->data) || is_animal(mtmp->data))
        item1 = item2 = TRUE;
    if (!tunnels(mtmp->data) || !needspick(mtmp->data))
        item1 = TRUE;

    while ((otmp = mtmp->minvent) != 0) {
        obj_extract_self(otmp);
        /* special case: pick-axe and unicorn horn are non-worn */
        /* items that we also want pets to keep 1 of */
        /* (It is a coincidence that these can also be wielded.) */
        if (otmp->owornmask || otmp == wep || otmp == hwep || otmp == rwep ||
            otmp == proj ||
            would_prefer_hwep(mtmp, otmp) ||  /* cursed item in hand? */
            would_prefer_rwep(mtmp, otmp) || could_use_item(mtmp, otmp) ||
            ((!rwep || rwep == &zeroobj) &&
             (is_ammo(otmp) || is_launcher(otmp))) ||
            (rwep && rwep != &zeroobj && ammo_and_launcher(otmp, rwep)) ||
            ((!item1 && otmp->otyp == PICK_AXE) ||
             (!item2 && otmp->otyp == UNICORN_HORN && !otmp->cursed))) {
            if (is_pet) {       /* dont drop worn/wielded item */
                if (otmp->otyp == PICK_AXE)
                    item1 = TRUE;
                if (otmp->otyp == UNICORN_HORN && !otmp->cursed)
                    item2 = TRUE;
                otmp->nobj = keepobj;
                keepobj = otmp;
                continue;
            }
        }
        if (otmp == wep)
            setmnotwielded(mtmp, otmp);
        mdrop_obj(mtmp, otmp, is_pet && flags.verbose);
    }

    /* put kept objects back */
    while ((otmp = keepobj) != NULL) {
        keepobj = otmp->nobj;
        add_to_minv(mtmp, otmp);
    }

    if (show & cansee(omx, omy))
        newsym(omx, omy);
}
Exemple #2
0
static struct obj *
DROPPABLES(struct monst *mon)
{
    struct obj *obj;
    struct obj *wep = MON_WEP(mon), *hwep = attacktype(mon->data, AT_WEAP)
        ? select_hwep(mon) : (struct obj *)0, *proj =
        attacktype(mon->data, AT_WEAP)
        ? select_rwep(mon) : (struct obj *)0, *rwep;
    boolean item1 = FALSE, item2 = FALSE;

    rwep = attacktype(mon->data, AT_WEAP) ? propellor : &zeroobj;

    if (is_animal(mon->data) || mindless(mon->data))
        item1 = item2 = TRUE;
    if (!tunnels(mon->data) || !needspick(mon->data))
        item1 = TRUE;
    for (obj = mon->minvent; obj; obj = obj->nobj) {
        if (!item1 && is_pick(obj) &&
            (obj->otyp != DWARVISH_MATTOCK || !which_armor(mon, W_ARMS))) {
            item1 = TRUE;
            continue;
        }
        if (!item2 && obj->otyp == UNICORN_HORN && !obj->cursed) {
            item2 = TRUE;
            continue;
        }
        if (!obj->owornmask && obj != wep && obj != rwep &&
            obj != proj && obj != hwep &&
            !would_prefer_hwep(mon, obj)  /* cursed item in hand?  */
            && !would_prefer_rwep(mon, obj)
            && ((rwep != &zeroobj) || (!is_ammo(obj) && !is_launcher(obj)))
            && (rwep == &zeroobj || !ammo_and_launcher(obj, rwep))
            && !could_use_item(mon, obj))
            return obj;
    }
    return NULL;
}
Exemple #3
0
/* monster attempts ranged weapon attack against a square */
void
thrwmq(struct monst *mtmp, int xdef, int ydef)
{
    struct obj *otmp, *mwep;
    schar skill;
    int multishot;
    const char *onm;

    /* Rearranged beginning so monsters can use polearms not in a line */
    if (mtmp->weapon_check == NEED_WEAPON || !MON_WEP(mtmp)) {
        mtmp->weapon_check = NEED_RANGED_WEAPON;
        /* mon_wield_item resets weapon_check as appropriate */
        if (mon_wield_item(mtmp) != 0)
            return;
    }

    /* Pick a weapon */
    otmp = select_rwep(mtmp);
    if (!otmp)
        return;

    if (is_pole(otmp)) {
        int dam, hitv;

        if (otmp != MON_WEP(mtmp))
            return;  /* polearm must be wielded */

        /* TODO: LOE function between two arbitrary points. */
        if (dist2(mtmp->mx, mtmp->my, xdef, ydef) > POLE_LIM ||
            (xdef == u.ux && ydef == u.uy && !couldsee(mtmp->mx, mtmp->my)))
            return;     /* Out of range, or intervening wall */

        if (mon_visible(mtmp)) {
            onm = singular(otmp, xname);
            pline("%s thrusts %s.", Monnam(mtmp),
                  obj_is_pname(otmp) ? the(onm) : an(onm));
        }

        if (xdef == u.ux && ydef == u.uy) {

            dam = dmgval(otmp, &youmonst);
            hitv = 3 - distmin(u.ux, u.uy, mtmp->mx, mtmp->my);
            if (hitv < -4)
                hitv = -4;
            if (bigmonst(youmonst.data))
                hitv++;
            hitv += 8 + otmp->spe;
            if (objects[otmp->otyp].oc_class == WEAPON_CLASS ||
                objects[otmp->otyp].oc_class == VENOM_CLASS)
                hitv += objects[otmp->otyp].oc_hitbon;
            if (dam < 1)
                dam = 1;

            thitu(hitv, dam, otmp, NULL);
            action_interrupted();

        } else if (MON_AT(level, xdef, ydef))
            (void)ohitmon(m_at(level, xdef, ydef), otmp, 0, FALSE);
        else if (mon_visible(mtmp))
            pline("But it misses wildly.");

        return;
    }

    if (!qlined_up(mtmp, xdef, ydef, FALSE, FALSE) ||
        !ai_use_at_range(BOLT_LIM - distmin(mtmp->mx, mtmp->my, xdef, ydef)))
        return;

    skill = objects[otmp->otyp].oc_skill;
    mwep = MON_WEP(mtmp);       /* wielded weapon */

    /* Multishot calculations */
    multishot = 1;
    if ((ammo_and_launcher(otmp, mwep) || skill == P_DAGGER || skill == -P_DART
         || skill == -P_SHURIKEN) && !mtmp->mconf) {
        /* Assumes lords are skilled, princes are expert */
        if (is_prince(mtmp->data))
            multishot += 2;
        else if (is_lord(mtmp->data))
            multishot++;

        switch (monsndx(mtmp->data)) {
        case PM_RANGER:
            multishot++;
            break;
        case PM_ROGUE:
            if (skill == P_DAGGER)
                multishot++;
            break;
        case PM_NINJA:
        case PM_SAMURAI:
            if (otmp->otyp == YA && mwep && mwep->otyp == YUMI)
                multishot++;
            break;
        default:
            break;
        }
        /* racial bonus */
        if ((is_elf(mtmp->data) && otmp->otyp == ELVEN_ARROW && mwep &&
             mwep->otyp == ELVEN_BOW) || (is_orc(mtmp->data) &&
                                          otmp->otyp == ORCISH_ARROW && mwep &&
                                          mwep->otyp == ORCISH_BOW))
            multishot++;

        if ((long)multishot > otmp->quan)
            multishot = (int)otmp->quan;
        if (multishot < 1)
            multishot = 1;
        else
            multishot = rnd(multishot);
    }

    if (mon_visible(mtmp)) {
        if (multishot > 1) {
            /* "N arrows"; multishot > 1 implies otmp->quan > 1, so xname()'s
               result will already be pluralized */
            onm = msgprintf("%d %s", multishot, xname(otmp));
        } else {
            /* "an arrow" */
            onm = singular(otmp, xname);
            onm = obj_is_pname(otmp) ? the(onm) : an(onm);
        }
        m_shot.s = ammo_and_launcher(otmp, mwep) ? TRUE : FALSE;
        pline("%s %s %s!", Monnam(mtmp), m_shot.s ? "shoots" : "throws", onm);
        m_shot.o = otmp->otyp;
    } else {
        m_shot.o = STRANGE_OBJECT;      /* don't give multishot feedback */
    }

    m_shot.n = multishot;
    for (m_shot.i = 1; m_shot.i <= m_shot.n; m_shot.i++) {
        m_throw(mtmp, mtmp->mx, mtmp->my, sgn(tbx), sgn(tby),
                distmin(mtmp->mx, mtmp->my, xdef, ydef), otmp, TRUE);
        /* conceptually all N missiles are in flight at once, but
           if mtmp gets killed (shot kills adjacent gas spore and
           triggers explosion, perhaps), inventory will be dropped
           and otmp might go away via merging into another stack;
           if we then use it, we could cause undefined behavior */
        if (mtmp->mhp <= 0 && m_shot.i < m_shot.n) {
            /* cancel pending shots (ought to give a message here since
               we gave one above about throwing/shooting N missiles) */
            break;  /* endmultishot(FALSE); */
        }
    }
    m_shot.n = m_shot.i = 0;
    m_shot.o = STRANGE_OBJECT;
    m_shot.s = FALSE;

    action_interrupted();
}