]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.steal.c
0164609ace0e97e5a67970c1eb196d7abebe3358
1 /* $NetBSD: hack.steal.c,v 1.6 2009/06/07 18:30:39 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.steal.c,v 1.6 2009/06/07 18:30:39 dholland Exp $");
74 * actually returns something that fits in an int
79 return ((u
.ugold
< 100) ? u
.ugold
:
80 (u
.ugold
> 10000) ? rnd(10000) : rnd((int) u
.ugold
));
84 stealgold(struct monst
*mtmp
)
86 struct gold
*gold
= g_at(u
.ux
, u
.uy
);
88 if (gold
&& (!u
.ugold
|| gold
->amount
> u
.ugold
|| !rn2(5))) {
89 mtmp
->mgold
+= gold
->amount
;
93 pline("%s quickly snatches some gold from between your feet!",
95 if (!u
.ugold
|| !rn2(5)) {
100 u
.ugold
-= (tmp
= somegold());
101 pline("Your purse feels lighter.");
109 /* steal armor after he finishes taking it off */
110 unsigned stealoid
; /* object to be stolen */
111 unsigned stealmid
; /* monster doing the stealing */
118 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
119 if (otmp
->o_id
== stealoid
) {
120 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
121 if (mtmp
->m_id
== stealmid
) {
122 if (dist(mtmp
->mx
, mtmp
->my
) < 3) {
124 pline("%s steals %s!", Monnam(mtmp
), doname(otmp
));
125 mpickobj(mtmp
, otmp
);
137 /* returns 1 when something was stolen */
138 /* (or at least, when N should flee now) */
139 /* avoid stealing the object stealoid */
141 steal(struct monst
*mtmp
)
149 pline("Somebody tries to rob you, but finds nothing to steal.");
151 pline("%s tries to rob you, but she finds nothing to steal!",
153 return (1); /* let her flee */
156 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
158 tmp
+= ((otmp
->owornmask
& (W_ARMOR
| W_RING
)) ? 5 : 1);
160 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
162 if ((tmp
-= ((otmp
->owornmask
& (W_ARMOR
| W_RING
)) ? 5 : 1))
166 impossible("Steal fails!");
169 if (otmp
->o_id
== stealoid
)
171 if ((otmp
->owornmask
& (W_ARMOR
| W_RING
))) {
172 switch (otmp
->olet
) {
177 if (multi
< 0 || otmp
== uarms
) {
178 setworn((struct obj
*) 0, otmp
->owornmask
& W_ARMOR
);
181 int curssv
= otmp
->cursed
;
184 pline("%s seduces you and %s off your %s.",
185 Amonnam(mtmp
, Blind
? "gentle" : "beautiful"),
186 otmp
->cursed
? "helps you to take"
187 : "you start taking",
188 (otmp
== uarmg
) ? "gloves" :
189 (otmp
== uarmh
) ? "helmet" : "armor");
191 (void) armoroff(otmp
);
192 otmp
->cursed
= curssv
;
199 stealoid
= otmp
->o_id
;
200 stealmid
= mtmp
->m_id
;
207 impossible("Tried to steal a strange worn thing.");
209 } else if (otmp
== uwep
)
210 setuwep((struct obj
*) 0);
211 if (otmp
->olet
== CHAIN_SYM
) {
212 impossible("How come you are carrying that chain?");
214 if (Punished
&& otmp
== uball
) {
217 free((char *) uchain
);
218 uchain
= (struct obj
*) 0;
220 uball
= (struct obj
*) 0; /* superfluous */
223 pline("%s stole %s.", named
? "She" : Monnam(mtmp
), doname(otmp
));
224 mpickobj(mtmp
, otmp
);
225 return ((multi
< 0) ? 0 : 1);
229 mpickobj(struct monst
*mtmp
, struct obj
*otmp
)
231 otmp
->nobj
= mtmp
->minvent
;
232 mtmp
->minvent
= otmp
;
236 stealamulet(struct monst
*mtmp
)
240 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
241 if (otmp
->olet
== AMULET_SYM
) {
242 /* might be an imitation one */
244 setuwep((struct obj
*) 0);
246 mpickobj(mtmp
, otmp
);
247 pline("%s stole %s!", Monnam(mtmp
), doname(otmp
));
254 /* release the objects the killed animal has stolen */
256 relobj(struct monst
*mtmp
, int show
)
258 struct obj
*otmp
, *otmp2
;
260 for (otmp
= mtmp
->minvent
; otmp
; otmp
= otmp2
) {
267 if (show
& cansee(mtmp
->mx
, mtmp
->my
))
268 atl(otmp
->ox
, otmp
->oy
, otmp
->olet
);
270 mtmp
->minvent
= (struct obj
*) 0;
271 if (mtmp
->mgold
|| mtmp
->data
->mlet
== 'L') {
274 tmp
= (mtmp
->mgold
> 10000) ? 10000 : mtmp
->mgold
;
275 mkgold((long) (tmp
+ d(dlevel
, 30)), mtmp
->mx
, mtmp
->my
);
276 if (show
& cansee(mtmp
->mx
, mtmp
->my
))
277 atl(mtmp
->mx
, mtmp
->my
, '$');