2011-08-07 00:29:37 +04:00
|
|
|
/* $NetBSD: hack.steal.c,v 1.8 2011/08/06 20:29:37 dholland Exp $ */
|
1997-10-19 20:56:41 +04:00
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
2003-04-02 22:36:33 +04:00
|
|
|
* Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
|
|
|
|
* Amsterdam
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of the Stichting Centrum voor Wiskunde en
|
|
|
|
* Informatica, nor the names of its contributors may be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1993-08-02 21:18:41 +04:00
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
2011-08-07 00:29:37 +04:00
|
|
|
__RCSID("$NetBSD: hack.steal.c,v 1.8 2011/08/06 20:29:37 dholland Exp $");
|
1997-10-19 20:56:41 +04:00
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-08-12 11:28:40 +04:00
|
|
|
static int stealarm(void);
|
|
|
|
|
2009-06-07 22:30:39 +04:00
|
|
|
/*
|
|
|
|
* actually returns something that fits in an int
|
|
|
|
*/
|
|
|
|
long
|
|
|
|
somegold(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
return ((u.ugold < 100) ? u.ugold :
|
|
|
|
(u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
stealgold(struct monst *mtmp)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
struct gold *gold = g_at(u.ux, u.uy);
|
|
|
|
long tmp;
|
|
|
|
if (gold && (!u.ugold || gold->amount > u.ugold || !rn2(5))) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mtmp->mgold += gold->amount;
|
|
|
|
freegold(gold);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (Invisible)
|
|
|
|
newsym(u.ux, u.uy);
|
1993-03-21 12:45:37 +03:00
|
|
|
pline("%s quickly snatches some gold from between your feet!",
|
1997-10-19 20:56:41 +04:00
|
|
|
Monnam(mtmp));
|
|
|
|
if (!u.ugold || !rn2(5)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
rloc(mtmp);
|
|
|
|
mtmp->mflee = 1;
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
} else if (u.ugold) {
|
1993-03-21 12:45:37 +03:00
|
|
|
u.ugold -= (tmp = somegold());
|
|
|
|
pline("Your purse feels lighter.");
|
|
|
|
mtmp->mgold += tmp;
|
|
|
|
rloc(mtmp);
|
|
|
|
mtmp->mflee = 1;
|
|
|
|
flags.botl = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* steal armor after he finishes taking it off */
|
2009-08-12 11:28:40 +04:00
|
|
|
static unsigned stealoid; /* object to be stolen */
|
|
|
|
static unsigned stealmid; /* monster doing the stealing */
|
|
|
|
static int
|
2009-06-07 22:30:39 +04:00
|
|
|
stealarm(void)
|
1997-10-19 20:56:41 +04:00
|
|
|
{
|
|
|
|
struct monst *mtmp;
|
|
|
|
struct obj *otmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
for (otmp = invent; otmp; otmp = otmp->nobj)
|
|
|
|
if (otmp->o_id == stealoid) {
|
|
|
|
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
|
|
|
|
if (mtmp->m_id == stealmid) {
|
|
|
|
if (dist(mtmp->mx, mtmp->my) < 3) {
|
|
|
|
freeinv(otmp);
|
|
|
|
pline("%s steals %s!", Monnam(mtmp), doname(otmp));
|
|
|
|
mpickobj(mtmp, otmp);
|
|
|
|
mtmp->mflee = 1;
|
|
|
|
rloc(mtmp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
stealoid = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns 1 when something was stolen */
|
|
|
|
/* (or at least, when N should flee now) */
|
|
|
|
/* avoid stealing the object stealoid */
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2009-06-07 22:30:39 +04:00
|
|
|
steal(struct monst *mtmp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *otmp;
|
|
|
|
int tmp;
|
|
|
|
int named = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
if (!invent) {
|
|
|
|
if (Blind)
|
|
|
|
pline("Somebody tries to rob you, but finds nothing to steal.");
|
|
|
|
else
|
|
|
|
pline("%s tries to rob you, but she finds nothing to steal!",
|
|
|
|
Monnam(mtmp));
|
|
|
|
return (1); /* let her flee */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
tmp = 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (otmp = invent; otmp; otmp = otmp->nobj)
|
|
|
|
if (otmp != uarm2)
|
|
|
|
tmp += ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
tmp = rn2(tmp);
|
1997-10-19 20:56:41 +04:00
|
|
|
for (otmp = invent; otmp; otmp = otmp->nobj)
|
|
|
|
if (otmp != uarm2)
|
|
|
|
if ((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1))
|
|
|
|
< 0)
|
|
|
|
break;
|
|
|
|
if (!otmp) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("Steal fails!");
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (otmp->o_id == stealoid)
|
|
|
|
return (0);
|
|
|
|
if ((otmp->owornmask & (W_ARMOR | W_RING))) {
|
|
|
|
switch (otmp->olet) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case RING_SYM:
|
|
|
|
ringoff(otmp);
|
|
|
|
break;
|
|
|
|
case ARMOR_SYM:
|
1997-10-19 20:56:41 +04:00
|
|
|
if (multi < 0 || otmp == uarms) {
|
|
|
|
setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
|
|
|
|
break;
|
|
|
|
} {
|
|
|
|
int curssv = otmp->cursed;
|
|
|
|
otmp->cursed = 0;
|
|
|
|
stop_occupation();
|
|
|
|
pline("%s seduces you and %s off your %s.",
|
|
|
|
Amonnam(mtmp, Blind ? "gentle" : "beautiful"),
|
|
|
|
otmp->cursed ? "helps you to take"
|
|
|
|
: "you start taking",
|
|
|
|
(otmp == uarmg) ? "gloves" :
|
|
|
|
(otmp == uarmh) ? "helmet" : "armor");
|
|
|
|
named++;
|
|
|
|
(void) armoroff(otmp);
|
|
|
|
otmp->cursed = curssv;
|
|
|
|
if (multi < 0) {
|
|
|
|
/*
|
|
|
|
multi = 0;
|
|
|
|
nomovemsg = 0;
|
|
|
|
afternmv = 0;
|
|
|
|
*/
|
|
|
|
stealoid = otmp->o_id;
|
|
|
|
stealmid = mtmp->m_id;
|
|
|
|
afternmv = stealarm;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
impossible("Tried to steal a strange worn thing.");
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
} else if (otmp == uwep)
|
1993-03-21 12:45:37 +03:00
|
|
|
setuwep((struct obj *) 0);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (otmp->olet == CHAIN_SYM) {
|
1993-03-21 12:45:37 +03:00
|
|
|
impossible("How come you are carrying that chain?");
|
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
if (Punished && otmp == uball) {
|
1993-03-21 12:45:37 +03:00
|
|
|
Punished = 0;
|
|
|
|
freeobj(uchain);
|
2011-08-07 00:29:37 +04:00
|
|
|
free(uchain);
|
1993-03-21 12:45:37 +03:00
|
|
|
uchain = (struct obj *) 0;
|
|
|
|
uball->spe = 0;
|
|
|
|
uball = (struct obj *) 0; /* superfluous */
|
|
|
|
}
|
|
|
|
freeinv(otmp);
|
|
|
|
pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
|
1997-10-19 20:56:41 +04:00
|
|
|
mpickobj(mtmp, otmp);
|
|
|
|
return ((multi < 0) ? 0 : 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
mpickobj(struct monst *mtmp, struct obj *otmp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
otmp->nobj = mtmp->minvent;
|
|
|
|
mtmp->minvent = otmp;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
int
|
2009-06-07 22:30:39 +04:00
|
|
|
stealamulet(struct monst *mtmp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *otmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
for (otmp = invent; otmp; otmp = otmp->nobj) {
|
|
|
|
if (otmp->olet == AMULET_SYM) {
|
|
|
|
/* might be an imitation one */
|
|
|
|
if (otmp == uwep)
|
|
|
|
setuwep((struct obj *) 0);
|
|
|
|
freeinv(otmp);
|
|
|
|
mpickobj(mtmp, otmp);
|
|
|
|
pline("%s stole %s!", Monnam(mtmp), doname(otmp));
|
|
|
|
return (1);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release the objects the killed animal has stolen */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
2009-06-07 22:30:39 +04:00
|
|
|
relobj(struct monst *mtmp, int show)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 20:56:41 +04:00
|
|
|
struct obj *otmp, *otmp2;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
for (otmp = mtmp->minvent; otmp; otmp = otmp2) {
|
1993-03-21 12:45:37 +03:00
|
|
|
otmp->ox = mtmp->mx;
|
|
|
|
otmp->oy = mtmp->my;
|
|
|
|
otmp2 = otmp->nobj;
|
|
|
|
otmp->nobj = fobj;
|
|
|
|
fobj = otmp;
|
|
|
|
stackobj(fobj);
|
1997-10-19 20:56:41 +04:00
|
|
|
if (show & cansee(mtmp->mx, mtmp->my))
|
|
|
|
atl(otmp->ox, otmp->oy, otmp->olet);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
mtmp->minvent = (struct obj *) 0;
|
1997-10-19 20:56:41 +04:00
|
|
|
if (mtmp->mgold || mtmp->data->mlet == 'L') {
|
|
|
|
long tmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
tmp = (mtmp->mgold > 10000) ? 10000 : mtmp->mgold;
|
1997-10-19 20:56:41 +04:00
|
|
|
mkgold((long) (tmp + d(dlevel, 30)), mtmp->mx, mtmp->my);
|
|
|
|
if (show & cansee(mtmp->mx, mtmp->my))
|
|
|
|
atl(mtmp->mx, mtmp->my, '$');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|