OSDN Git Service

upgrade to 3.6.2
[jnethack/source.git] / src / steal.c
1 /* NetHack 3.6  steal.c $NHDT-Date: 1554580626 2019/04/06 19:57:06 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.72 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /*-Copyright (c) Robert Patrick Rankin, 2012. */
4 /* NetHack may be freely redistributed.  See license for details. */
5
6 /* JNetHack Copyright */
7 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
8 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2019            */
9 /* JNetHack may be freely redistributed.  See license for details. */
10
11 #include "hack.h"
12
13 STATIC_PTR int NDECL(stealarm);
14
15 STATIC_DCL const char *FDECL(equipname, (struct obj *));
16
17 STATIC_OVL const char *
18 equipname(otmp)
19 register struct obj *otmp;
20 {
21     return ((otmp == uarmu)
22 /*JP
23                 ? "shirt"
24 */
25                 ? "\83V\83\83\83c"
26                 : (otmp == uarmf)
27 /*JP
28                       ? "boots"
29 */
30                       ? "\8cC"
31                       : (otmp == uarms)
32 /*JP
33                             ? "shield"
34 */
35                             ? "\8f\82"
36                             : (otmp == uarmg)
37 /*JP
38                                   ? "gloves"
39 */
40                                   ? "\8f¬\8eè"
41                                   : (otmp == uarmc)
42                                         ? cloak_simple_name(otmp)
43                                         : (otmp == uarmh)
44                                               ? helm_simple_name(otmp)
45                                               : suit_simple_name(otmp));
46 }
47
48 /* proportional subset of gold; return value actually fits in an int */
49 long
50 somegold(lmoney)
51 long lmoney;
52 {
53 #ifdef LINT /* long conv. ok */
54     int igold = 0;
55 #else
56     int igold = (lmoney >= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney;
57 #endif
58
59     if (igold < 50)
60         ; /* all gold */
61     else if (igold < 100)
62         igold = rn1(igold - 25 + 1, 25);
63     else if (igold < 500)
64         igold = rn1(igold - 50 + 1, 50);
65     else if (igold < 1000)
66         igold = rn1(igold - 100 + 1, 100);
67     else if (igold < 5000)
68         igold = rn1(igold - 500 + 1, 500);
69     else if (igold < 10000)
70         igold = rn1(igold - 1000 + 1, 1000);
71     else
72         igold = rn1(igold - 5000 + 1, 5000);
73
74     return (long) igold;
75 }
76
77 /*
78  * Find the first (and hopefully only) gold object in a chain.
79  * Used when leprechaun (or you as leprechaun) looks for
80  * someone else's gold.  Returns a pointer so the gold may
81  * be seized without further searching.
82  * May search containers too.
83  * Deals in gold only, as leprechauns don't care for lesser coins.
84 */
85 struct obj *
86 findgold(chain)
87 register struct obj *chain;
88 {
89     while (chain && chain->otyp != GOLD_PIECE)
90         chain = chain->nobj;
91     return chain;
92 }
93
94 /*
95  * Steal gold coins only.  Leprechauns don't care for lesser coins.
96 */
97 void
98 stealgold(mtmp)
99 register struct monst *mtmp;
100 {
101     register struct obj *fgold = g_at(u.ux, u.uy);
102     register struct obj *ygold;
103     register long tmp;
104 #if 0 /*JP*/
105     struct monst *who;
106     const char *whose, *what;
107 #endif
108
109     /* skip lesser coins on the floor */
110     while (fgold && fgold->otyp != GOLD_PIECE)
111         fgold = fgold->nexthere;
112
113     /* Do you have real gold? */
114     ygold = findgold(invent);
115
116     if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) {
117         obj_extract_self(fgold);
118         add_to_minv(mtmp, fgold);
119         newsym(u.ux, u.uy);
120 #if 0 /*JP*/
121         if (u.usteed) {
122             who = u.usteed;
123             whose = s_suffix(y_monnam(who));
124             what = makeplural(mbodypart(who, FOOT));
125         } else {
126             who = &youmonst;
127             whose = "your";
128             what = makeplural(body_part(FOOT));
129         }
130         /* [ avoid "between your rear regions" :-] */
131         if (slithy(who->data))
132             what = "coils";
133         /* reduce "rear hooves/claws" to "hooves/claws" */
134         if (!strncmp(what, "rear ", 5))
135             what += 5;
136         pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp),
137               (Levitation || Flying) ? "beneath" : "between", whose, what);
138 #else /*JP:\91«\82ª\96³\82­\82Ä\82à\81u\91«\8c³\81v\82Å\82æ\82µ\82Æ\82·\82é*/
139         pline("%s\82Í\91f\91\81\82­\82 \82È\82½\82Ì%s\82©\82ç\8bà\82ð\82Ð\82Á\82½\82­\82Á\82½\81I", Monnam(mtmp),
140               (Levitation || Flying) ? "\89º" : "\91«\8c³");
141 #endif
142         if (!ygold || !rn2(5)) {
143             if (!tele_restrict(mtmp))
144                 (void) rloc(mtmp, TRUE);
145             monflee(mtmp, 0, FALSE, FALSE);
146         }
147     } else if (ygold) {
148         const int gold_price = objects[GOLD_PIECE].oc_cost;
149
150         tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price;
151         tmp = min(tmp, ygold->quan);
152         if (tmp < ygold->quan)
153             ygold = splitobj(ygold, tmp);
154         else
155             setnotworn(ygold);
156         freeinv(ygold);
157         add_to_minv(mtmp, ygold);
158 /*JP
159         Your("purse feels lighter.");
160 */
161         Your("\8dà\95z\82Í\8cy\82­\82È\82Á\82½\81D");
162         if (!tele_restrict(mtmp))
163             (void) rloc(mtmp, TRUE);
164         monflee(mtmp, 0, FALSE, FALSE);
165         context.botl = 1;
166     }
167 }
168
169 /* steal armor after you finish taking it off */
170 unsigned int stealoid; /* object to be stolen */
171 unsigned int stealmid; /* monster doing the stealing */
172
173 STATIC_PTR int
174 stealarm(VOID_ARGS)
175 {
176     register struct monst *mtmp;
177     register struct obj *otmp;
178
179     for (otmp = invent; otmp; otmp = otmp->nobj) {
180         if (otmp->o_id == stealoid) {
181             for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
182                 if (mtmp->m_id == stealmid) {
183                     if (DEADMONSTER(mtmp))
184                         impossible("stealarm(): dead monster stealing");
185                     if (!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */
186                         goto botm;
187                     if (otmp->unpaid)
188                         subfrombill(otmp, shop_keeper(*u.ushops));
189                     freeinv(otmp);
190 /*JP
191                     pline("%s steals %s!", Monnam(mtmp), doname(otmp));
192 */
193                     pline("%s\82Í%s\82ð\93\90\82ñ\82¾\81I", Monnam(mtmp), doname(otmp));
194                     (void) mpickobj(mtmp, otmp); /* may free otmp */
195                     /* Implies seduction, "you gladly hand over ..."
196                        so we don't set mavenge bit here. */
197                     monflee(mtmp, 0, FALSE, FALSE);
198                     if (!tele_restrict(mtmp))
199                         (void) rloc(mtmp, TRUE);
200                     break;
201                 }
202             }
203             break;
204         }
205     }
206 botm:
207     stealoid = 0;
208     return 0;
209 }
210
211 /* An object you're wearing has been taken off by a monster (theft or
212    seduction).  Also used if a worn item gets transformed (stone to flesh). */
213 void
214 remove_worn_item(obj, unchain_ball)
215 struct obj *obj;
216 boolean unchain_ball; /* whether to unpunish or just unwield */
217 {
218     if (donning(obj))
219         cancel_don();
220     if (!obj->owornmask)
221         return;
222
223     if (obj->owornmask & W_ARMOR) {
224         if (obj == uskin) {
225             impossible("Removing embedded scales?");
226             skinback(TRUE); /* uarm = uskin; uskin = 0; */
227         }
228         if (obj == uarm)
229             (void) Armor_off();
230         else if (obj == uarmc)
231             (void) Cloak_off();
232         else if (obj == uarmf)
233             (void) Boots_off();
234         else if (obj == uarmg)
235             (void) Gloves_off();
236         else if (obj == uarmh)
237             (void) Helmet_off();
238         else if (obj == uarms)
239             (void) Shield_off();
240         else if (obj == uarmu)
241             (void) Shirt_off();
242         /* catchall -- should never happen */
243         else
244             setworn((struct obj *) 0, obj->owornmask & W_ARMOR);
245     } else if (obj->owornmask & W_AMUL) {
246         Amulet_off();
247     } else if (obj->owornmask & W_RING) {
248         Ring_gone(obj);
249     } else if (obj->owornmask & W_TOOL) {
250         Blindf_off(obj);
251     } else if (obj->owornmask & W_WEAPON) {
252         if (obj == uwep)
253             uwepgone();
254         if (obj == uswapwep)
255             uswapwepgone();
256         if (obj == uquiver)
257             uqwepgone();
258     }
259
260     if (obj->owornmask & (W_BALL | W_CHAIN)) {
261         if (unchain_ball)
262             unpunish();
263     } else if (obj->owornmask) {
264         /* catchall */
265         setnotworn(obj);
266     }
267 }
268
269 /* Returns 1 when something was stolen (or at least, when N should flee now)
270  * Returns -1 if the monster died in the attempt
271  * Avoid stealing the object stealoid
272  * Nymphs and monkeys won't steal coins
273  */
274 int
275 steal(mtmp, objnambuf)
276 struct monst *mtmp;
277 char *objnambuf;
278 {
279     struct obj *otmp;
280     int tmp, could_petrify, armordelay, olddelay, named = 0, retrycnt = 0;
281     boolean monkey_business, /* true iff an animal is doing the thievery */
282         was_doffing;
283
284     if (objnambuf)
285         *objnambuf = '\0';
286     /* the following is true if successful on first of two attacks. */
287     if (!monnear(mtmp, u.ux, u.uy))
288         return 0;
289
290     /* food being eaten might already be used up but will not have
291        been removed from inventory yet; we don't want to steal that,
292        so this will cause it to be removed now */
293     if (occupation)
294         (void) maybe_finished_meal(FALSE);
295
296     if (!invent || (inv_cnt(FALSE) == 1 && uskin)) {
297     nothing_to_steal:
298         /* Not even a thousand men in armor can strip a naked man. */
299         if (Blind)
300 /*JP
301             pline("Somebody tries to rob you, but finds nothing to steal.");
302 */
303             pline("\92N\82©\82ª\82 \82È\82½\82©\82ç\93\90\82à\82¤\82Æ\82µ\82½\82ª\81C\93\90\82Þ\82à\82Ì\82ª\82È\82¢\82±\82Æ\82É\8bC\82ª\82Â\82¢\82½\81D");
304         else
305 /*JP
306             pline("%s tries to rob you, but there is nothing to steal!",
307 */
308             pline("%s\82Í\82 \82È\82½\82©\82ç\93\90\82à\82¤\82Æ\82µ\82½\82ª\81C\93\90\82Þ\82à\82Ì\82ª\82È\82¢\82±\82Æ\82É\8bC\82ª\82Â\82¢\82½\81I",
309                   Monnam(mtmp));
310         return 1; /* let her flee */
311     }
312
313     monkey_business = is_animal(mtmp->data);
314     if (monkey_business || uarmg) {
315         ; /* skip ring special cases */
316     } else if (Adornment & LEFT_RING) {
317         otmp = uleft;
318         goto gotobj;
319     } else if (Adornment & RIGHT_RING) {
320         otmp = uright;
321         goto gotobj;
322     }
323
324 retry:
325     tmp = 0;
326     for (otmp = invent; otmp; otmp = otmp->nobj)
327         if ((!uarm || otmp != uarmc) && otmp != uskin
328             && otmp->oclass != COIN_CLASS)
329             tmp += (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
330     if (!tmp)
331         goto nothing_to_steal;
332     tmp = rn2(tmp);
333     for (otmp = invent; otmp; otmp = otmp->nobj)
334         if ((!uarm || otmp != uarmc) && otmp != uskin
335             && otmp->oclass != COIN_CLASS) {
336             tmp -= (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
337             if (tmp < 0)
338                 break;
339         }
340     if (!otmp) {
341         impossible("Steal fails!");
342         return 0;
343     }
344     /* can't steal ring(s) while wearing gloves */
345     if ((otmp == uleft || otmp == uright) && uarmg)
346         otmp = uarmg;
347     /* can't steal gloves while wielding - so steal the wielded item. */
348     if (otmp == uarmg && uwep)
349         otmp = uwep;
350     /* can't steal armor while wearing cloak - so steal the cloak. */
351     else if (otmp == uarm && uarmc)
352         otmp = uarmc;
353     /* can't steal shirt while wearing cloak or suit */
354     else if (otmp == uarmu && uarmc)
355         otmp = uarmc;
356     else if (otmp == uarmu && uarm)
357         otmp = uarm;
358
359 gotobj:
360     if (otmp->o_id == stealoid)
361         return 0;
362
363     if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) {
364         if (!retrycnt++)
365             goto retry;
366         goto cant_take;
367     }
368     /* animals can't overcome curse stickiness nor unlock chains */
369     if (monkey_business) {
370         boolean ostuck;
371         /* is the player prevented from voluntarily giving up this item?
372            (ignores loadstones; the !can_carry() check will catch those) */
373         if (otmp == uball)
374             ostuck = TRUE; /* effectively worn; curse is implicit */
375         else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap))
376             ostuck = FALSE; /* not really worn; curse doesn't matter */
377         else
378             ostuck = ((otmp->cursed && otmp->owornmask)
379                       /* nymphs can steal rings from under
380                          cursed weapon but animals can't */
381                       || (otmp == uright && welded(uwep))
382                       || (otmp == uleft && welded(uwep) && bimanual(uwep)));
383
384         if (ostuck || can_carry(mtmp, otmp) == 0) {
385 #if 0 /*JP*/
386             static const char *const how[] = { "steal", "snatch", "grab",
387                                                "take" };
388         cant_take:
389             pline("%s tries to %s %s%s but gives up.", Monnam(mtmp),
390                   how[rn2(SIZE(how))],
391                   (otmp->owornmask & W_ARMOR) ? "your " : "",
392                   (otmp->owornmask & W_ARMOR) ? equipname(otmp)
393                                               : yname(otmp));
394 #else
395         cant_take:
396             pline("%s\82Í%s\82ð\93\90\82à\82¤\82Æ\82µ\82½\82ª\92ú\82ß\82½\81D", Monnam(mtmp),
397                   (otmp->owornmask & W_ARMOR) ? equipname(otmp)
398                                               : yname(otmp));
399 #endif
400             /* the fewer items you have, the less likely the thief
401                is going to stick around to try again (0) instead of
402                running away (1) */
403             return !rn2(inv_cnt(FALSE) / 5 + 2);
404         }
405     }
406
407     if (otmp->otyp == LEASH && otmp->leashmon) {
408         if (monkey_business && otmp->cursed)
409             goto cant_take;
410         o_unleash(otmp);
411     }
412
413     was_doffing = doffing(otmp);
414     /* stop donning/doffing now so that afternmv won't be clobbered
415        below; stop_occupation doesn't handle donning/doffing */
416     olddelay = stop_donning(otmp);
417     /* you're going to notice the theft... */
418     stop_occupation();
419
420     if (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) {
421         switch (otmp->oclass) {
422         case TOOL_CLASS:
423         case AMULET_CLASS:
424         case RING_CLASS:
425         case FOOD_CLASS: /* meat ring */
426             remove_worn_item(otmp, TRUE);
427             break;
428         case ARMOR_CLASS:
429             armordelay = objects[otmp->otyp].oc_delay;
430             if (olddelay > 0 && olddelay < armordelay)
431                 armordelay = olddelay;
432             if (monkey_business) {
433                 /* animals usually don't have enough patience
434                    to take off items which require extra time */
435                 if (armordelay >= 1 && !olddelay && rn2(10))
436                     goto cant_take;
437                 remove_worn_item(otmp, TRUE);
438                 break;
439             } else {
440                 int curssv = otmp->cursed;
441                 int slowly;
442                 boolean seen = canspotmon(mtmp);
443
444                 otmp->cursed = 0;
445                 /* can't charm you without first waking you */
446                 if (Unaware)
447                     unmul((char *) 0);
448                 slowly = (armordelay >= 1 || multi < 0);
449                 if (flags.female)
450 #if 0 /*JP*/
451                     pline("%s charms you.  You gladly %s your %s.",
452                           !seen ? "She" : Monnam(mtmp),
453                           curssv ? "let her take"
454                                  : !slowly ? "hand over"
455                                            : was_doffing ? "continue removing"
456                                                          : "start removing",
457                           equipname(otmp));
458 #else
459                     pline("%s\82Í\82 \82È\82½\82ð\96£\97¹\82µ\82½\81D\82 \82È\82½\82Í\82æ\82ë\82±\82ñ\82Å%s\82ð%s\82½\81D",
460                           !seen ? "\94Þ\8f\97" : Monnam(mtmp),
461                           equipname(otmp),
462                           curssv ? "\82Í\82¸\82µ\82Ä\82à\82ç\82Á"
463                                  : !slowly ? "\82Í\82¸\82µ\82Ä\8eè\93n\82µ"
464                                            : was_doffing ? "\82Í\82¸\82µ\91±\82¯"
465                                                          : "\82Í\82¸\82µ\8en\82ß");
466 #endif
467                 else
468 #if 0 /*JP*/
469                     pline("%s seduces you and %s off your %s.",
470                           !seen ? "She" : Adjmonnam(mtmp, "beautiful"),
471                           curssv
472                               ? "helps you to take"
473                               : !slowly ? "you take"
474                                         : was_doffing ? "you continue taking"
475                                                       : "you start taking",
476                           equipname(otmp));
477 #else
478                     pline("%s\82Í\82 \82È\82½\82ð\97U\98f\82µ\82½\81D\82 \82È\82½\82Í%s\82ð%s\81D",
479                           !seen ? "\94Þ\8f\97" : Adjmonnam(mtmp, "\94ü\82µ\82¢"),
480                           equipname(otmp),
481                           curssv
482                               ? "\82Í\82¸\82µ\82Ä\82à\82ç\82Á"
483                               : !slowly ? "\82Í\82¸\82µ"
484                                         : was_doffing ? "\82Í\82¸\82µ\91±\82¯"
485                                                       : "\82Í\82¸\82µ\8en\82ß");
486 #endif
487                 named++;
488                 /* the following is to set multi for later on */
489                 nomul(-armordelay);
490 /*JP
491                 multi_reason = "taking off clothes";
492 */
493                 multi_reason = "\95\9e\82ð\92E\82¢\82Å\82¢\82é\8e\9e\82É";
494                 nomovemsg = 0;
495                 remove_worn_item(otmp, TRUE);
496                 otmp->cursed = curssv;
497                 if (multi < 0) {
498                     /*
499                     multi = 0;
500                     afternmv = 0;
501                     */
502                     stealoid = otmp->o_id;
503                     stealmid = mtmp->m_id;
504                     afternmv = stealarm;
505                     return 0;
506                 }
507             }
508             break;
509         default:
510             impossible("Tried to steal a strange worn thing. [%d]",
511                        otmp->oclass);
512         }
513     } else if (otmp->owornmask)
514         remove_worn_item(otmp, TRUE);
515
516     /* do this before removing it from inventory */
517     if (objnambuf)
518         Strcpy(objnambuf, yname(otmp));
519     /* set mavenge bit so knights won't suffer an
520      * alignment penalty during retaliation;
521      */
522     mtmp->mavenge = 1;
523
524     if (otmp->unpaid)
525         subfrombill(otmp, shop_keeper(*u.ushops));
526     freeinv(otmp);
527 /*JP
528     pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
529 */
530     pline("%s\82Í%s\82ð\93\90\82ñ\82¾\81D", named ? "\94Þ\8f\97" : Monnam(mtmp), doname(otmp));
531     could_petrify =
532         (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]));
533     (void) mpickobj(mtmp, otmp); /* may free otmp */
534     if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) {
535         minstapetrify(mtmp, TRUE);
536         return -1;
537     }
538     return (multi < 0) ? 0 : 1;
539 }
540
541 /* Returns 1 if otmp is free'd, 0 otherwise. */
542 int
543 mpickobj(mtmp, otmp)
544 register struct monst *mtmp;
545 register struct obj *otmp;
546 {
547     int freed_otmp;
548     boolean snuff_otmp = FALSE;
549
550     /* if monster is acquiring a thrown or kicked object, the throwing
551        or kicking code shouldn't continue to track and place it */
552     if (otmp == thrownobj)
553         thrownobj = 0;
554     else if (otmp == kickedobj)
555         kickedobj = 0;
556     /* don't want hidden light source inside the monster; assumes that
557        engulfers won't have external inventories; whirly monsters cause
558        the light to be extinguished rather than letting it shine thru */
559     if (obj_sheds_light(otmp) && attacktype(mtmp->data, AT_ENGL)) {
560         /* this is probably a burning object that you dropped or threw */
561         if (u.uswallow && mtmp == u.ustuck && !Blind)
562 /*JP
563             pline("%s out.", Tobjnam(otmp, "go"));
564 */
565             pline("%s\82Í\94ò\82Ñ\82¾\82µ\82½\81D", xname(otmp));
566         snuff_otmp = TRUE;
567     }
568     /* for hero owned object on shop floor, mtmp is taking possession
569        and if it's eventually dropped in a shop, shk will claim it */
570     if (!mtmp->mtame)
571         otmp->no_charge = 0;
572     /* Must do carrying effects on object prior to add_to_minv() */
573     carry_obj_effects(otmp);
574     /* add_to_minv() might free otmp [if merged with something else],
575        so we have to call it after doing the object checks */
576     freed_otmp = add_to_minv(mtmp, otmp);
577     /* and we had to defer this until object is in mtmp's inventory */
578     if (snuff_otmp)
579         snuff_light_source(mtmp->mx, mtmp->my);
580     return freed_otmp;
581 }
582
583 /* called for AD_SAMU (the Wizard and quest nemeses) */
584 void
585 stealamulet(mtmp)
586 struct monst *mtmp;
587 {
588     char buf[BUFSZ];
589     struct obj *otmp = 0, *obj = 0;
590     int real = 0, fake = 0, n;
591
592     /* target every quest artifact, not just current role's;
593        if hero has more than one, choose randomly so that player
594        can't use inventory ordering to influence the theft */
595     for (n = 0, obj = invent; obj; obj = obj->nobj)
596         if (any_quest_artifact(obj))
597             ++n, otmp = obj;
598     if (n > 1) {
599         n = rnd(n);
600         for (otmp = invent; otmp; otmp = otmp->nobj)
601             if (any_quest_artifact(otmp) && !--n)
602                 break;
603     }
604
605     if (!otmp) {
606         /* if we didn't find any quest arifact, find another valuable item */
607         if (u.uhave.amulet) {
608             real = AMULET_OF_YENDOR;
609             fake = FAKE_AMULET_OF_YENDOR;
610         } else if (u.uhave.bell) {
611             real = BELL_OF_OPENING;
612             fake = BELL;
613         } else if (u.uhave.book) {
614             real = SPE_BOOK_OF_THE_DEAD;
615         } else if (u.uhave.menorah) {
616             real = CANDELABRUM_OF_INVOCATION;
617         } else
618             return; /* you have nothing of special interest */
619
620         /* If we get here, real and fake have been set up. */
621         for (n = 0, obj = invent; obj; obj = obj->nobj)
622             if (obj->otyp == real || (obj->otyp == fake && !mtmp->iswiz))
623                 ++n, otmp = obj;
624         if (n > 1) {
625             n = rnd(n);
626             for (otmp = invent; otmp; otmp = otmp->nobj)
627                 if ((otmp->otyp == real
628                      || (otmp->otyp == fake && !mtmp->iswiz)) && !--n)
629                     break;
630         }
631     }
632
633     if (otmp) { /* we have something to snatch */
634         /* take off outer gear if we're targetting [hypothetical]
635            quest artifact suit, shirt, gloves, or rings */
636         if ((otmp == uarm || otmp == uarmu) && uarmc)
637             remove_worn_item(uarmc, FALSE);
638         if (otmp == uarmu && uarm)
639             remove_worn_item(uarm, FALSE);
640         if ((otmp == uarmg || ((otmp == uright || otmp == uleft) && uarmg))
641             && uwep) {
642             /* gloves are about to be unworn; unwield weapon(s) first */
643             if (u.twoweap)    /* remove_worn_item(uswapwep) indirectly */
644                 remove_worn_item(uswapwep, FALSE); /* clears u.twoweap */
645             remove_worn_item(uwep, FALSE);
646         }
647         if ((otmp == uright || otmp == uleft) && uarmg)
648             /* calls Gloves_off() to handle wielded cockatrice corpse */
649             remove_worn_item(uarmg, FALSE);
650
651         /* finally, steal the target item */
652         if (otmp->owornmask)
653             remove_worn_item(otmp, TRUE);
654         if (otmp->unpaid)
655             subfrombill(otmp, shop_keeper(*u.ushops));
656         freeinv(otmp);
657         Strcpy(buf, doname(otmp));
658         (void) mpickobj(mtmp, otmp); /* could merge and free otmp but won't */
659 /*JP
660         pline("%s steals %s!", Monnam(mtmp), buf);
661 */
662         pline("%s\82Í%s\82ð\93\90\82ñ\82¾\81I", Monnam(mtmp), buf);
663         if (can_teleport(mtmp->data) && !tele_restrict(mtmp))
664             (void) rloc(mtmp, TRUE);
665     }
666 }
667
668 /* when a mimic gets poked with something, it might take that thing
669    (at present, only implemented for when the hero does the poking) */
670 void
671 maybe_absorb_item(mon, obj, ochance, achance)
672 struct monst *mon;
673 struct obj *obj;
674 int ochance, achance; /* percent chance for ordinary item, artifact */
675 {
676     if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS
677         || obj_resists(obj, 100 - ochance, 100 - achance)
678         || !touch_artifact(obj, mon))
679         return;
680
681     if (carried(obj)) {
682         if (obj->owornmask)
683             remove_worn_item(obj, TRUE);
684         if (obj->unpaid)
685             subfrombill(obj, shop_keeper(*u.ushops));
686         if (cansee(mon->mx, mon->my)) {
687             const char *MonName = Monnam(mon);
688
689 #if 0 /*JP*//*\93ú\96{\8cê\82Å\82Í\95s\97v*/
690             /* mon might be invisible; avoid "It pulls ... and absorbs it!" */
691             if (!strcmp(MonName, "It"))
692                 MonName = "Something";
693 #endif
694 #if 0 /*JP*/
695             pline("%s pulls %s away from you and absorbs %s!", MonName,
696                   yname(obj), (obj->quan > 1L) ? "them" : "it");
697 #else
698             pline("%s\82Í%s\82ð\88ø\82Á\82Ï\82è\8d\9e\82ñ\82Å\8bz\8eû\82µ\82½\81I", MonName,
699                   yname(obj));
700 #endif
701         } else {
702             const char *hand_s = body_part(HAND);
703
704             if (bimanual(obj))
705                 hand_s = makeplural(hand_s);
706 #if 0 /*JP*/
707             pline("%s %s pulled from your %s!", upstart(yname(obj)),
708                   otense(obj, "are"), hand_s);
709 #else
710             pline("%s\82Í\82 \82È\82½\82Ì%s\82©\82ç\88ø\82Á\82Ï\82è\8d\9e\82Ü\82ê\82½\81I", upstart(yname(obj)),
711                   hand_s);
712 #endif
713         }
714         freeinv(obj);
715     } else {
716         /* not carried; presumably thrown or kicked */
717         if (canspotmon(mon))
718 /*JP
719             pline("%s absorbs %s!", Monnam(mon), yname(obj));
720 */
721             pline("%s\82Í%s\82ð\8bz\8eû\82µ\82½\81I", Monnam(mon), yname(obj));
722     }
723     /* add to mon's inventory */
724     (void) mpickobj(mon, obj);
725 }
726
727 /* drop one object taken from a (possibly dead) monster's inventory */
728 void
729 mdrop_obj(mon, obj, verbosely)
730 struct monst *mon;
731 struct obj *obj;
732 boolean verbosely;
733 {
734     int omx = mon->mx, omy = mon->my;
735     boolean update_mon = FALSE;
736
737     if (obj->owornmask) {
738         /* perform worn item handling if the monster is still alive */
739         if (!DEADMONSTER(mon)) {
740             mon->misc_worn_check &= ~obj->owornmask;
741             update_mon = TRUE;
742
743         /* don't charge for an owned saddle on dead steed (provided
744            that the hero is within the same shop at the time) */
745         } else if (mon->mtame && (obj->owornmask & W_SADDLE) != 0L
746                    && !obj->unpaid && costly_spot(omx, omy)
747                    /* being at costly_spot guarantees lev->roomno is not 0 */
748                    && index(in_rooms(u.ux, u.uy, SHOPBASE),
749                             levl[omx][omy].roomno)) {
750             obj->no_charge = 1;
751         }
752         /* this should be done even if the monster has died */
753         if (obj->owornmask & W_WEP)
754             setmnotwielded(mon, obj);
755         obj->owornmask = 0L;
756     }
757     /* obj_no_longer_held(obj); -- done by place_object */
758     if (verbosely && cansee(omx, omy))
759 /*JP
760         pline("%s drops %s.", Monnam(mon), distant_name(obj, doname));
761 */
762         pline("%s\82Í%s\82ð\92u\82¢\82½\81D", Monnam(mon), distant_name(obj, doname));
763 /*JP
764     if (!flooreffects(obj, omx, omy, "fall")) {
765 */
766     if (!flooreffects(obj, omx, omy, "\97\8e\82¿\82é")) {
767         place_object(obj, omx, omy);
768         stackobj(obj);
769     }
770     /* do this last, after placing obj on floor; removing steed's saddle
771        throws rider, possibly inflicting fatal damage and producing bones */
772     if (update_mon)
773         update_mon_intrinsics(mon, obj, FALSE, TRUE);
774 }
775
776 /* some monsters bypass the normal rules for moving between levels or
777    even leaving the game entirely; when that happens, prevent them from
778    taking the Amulet, invocation items, or quest artifact with them */
779 void
780 mdrop_special_objs(mon)
781 struct monst *mon;
782 {
783     struct obj *obj, *otmp;
784
785     for (obj = mon->minvent; obj; obj = otmp) {
786         otmp = obj->nobj;
787         /* the Amulet, invocation tools, and Rider corpses resist even when
788            artifacts and ordinary objects are given 0% resistance chance;
789            current role's quest artifact is rescued too--quest artifacts
790            for the other roles are not */
791         if (obj_resists(obj, 0, 0) || is_quest_artifact(obj)) {
792             obj_extract_self(obj);
793             if (mon->mx) {
794                 mdrop_obj(mon, obj, FALSE);
795             } else { /* migrating monster not on map */
796                 if (obj->owornmask) {
797                     mon->misc_worn_check &= ~obj->owornmask;
798                     if (obj->owornmask & W_WEP)
799                         setmnotwielded(mon, obj);
800                     obj->owornmask = 0L;
801                 }
802                 rloco(obj);
803             }
804         }
805     }
806 }
807
808 /* release the objects the creature is carrying */
809 void
810 relobj(mtmp, show, is_pet)
811 struct monst *mtmp;
812 int show;
813 boolean is_pet; /* If true, pet should keep wielded/worn items */
814 {
815     struct obj *otmp;
816     int omx = mtmp->mx, omy = mtmp->my;
817
818     /* vault guard's gold goes away rather than be dropped... */
819     if (mtmp->isgd && (otmp = findgold(mtmp->minvent)) != 0) {
820         if (canspotmon(mtmp))
821 #if 0 /*JP*/
822             pline("%s gold %s.", s_suffix(Monnam(mtmp)),
823                   canseemon(mtmp) ? "vanishes" : "seems to vanish");
824 #else
825             pline("%s\82Ì\8bà\82Í\8fÁ\82¦\82½%s\81D", Monnam(mtmp),
826                   canseemon(mtmp) ? "" : "\82æ\82¤\82¾");
827 #endif
828         obj_extract_self(otmp);
829         obfree(otmp, (struct obj *) 0);
830     } /* isgd && has gold */
831
832     while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) {
833         obj_extract_self(otmp);
834         mdrop_obj(mtmp, otmp, is_pet && flags.verbose);
835     }
836
837     if (show && cansee(omx, omy))
838         newsym(omx, omy);
839 }
840
841 /*steal.c*/