1 /* NetHack 3.6 steal.c $NHDT-Date: 1446713643 2015/11/05 08:54:03 $ $NHDT-Branch: master $:$NHDT-Revision: 1.65 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016 */
8 /* JNetHack may be freely redistributed. See license for details. */
12 STATIC_PTR int NDECL(stealarm);
14 STATIC_DCL const char *FDECL(equipname, (struct obj *));
16 STATIC_OVL const char *
18 register struct obj *otmp;
20 return ((otmp == uarmu)
41 ? cloak_simple_name(otmp)
43 ? helm_simple_name(otmp)
44 : suit_simple_name(otmp));
47 /* proportional subset of gold; return value actually fits in an int */
52 #ifdef LINT /* long conv. ok */
55 int igold = (lmoney >= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney;
61 igold = rn1(igold - 25 + 1, 25);
63 igold = rn1(igold - 50 + 1, 50);
64 else if (igold < 1000)
65 igold = rn1(igold - 100 + 1, 100);
66 else if (igold < 5000)
67 igold = rn1(igold - 500 + 1, 500);
68 else if (igold < 10000)
69 igold = rn1(igold - 1000 + 1, 1000);
71 igold = rn1(igold - 5000 + 1, 5000);
77 * Find the first (and hopefully only) gold object in a chain.
78 * Used when leprechaun (or you as leprechaun) looks for
79 * someone else's gold. Returns a pointer so the gold may
80 * be seized without further searching.
81 * May search containers too.
82 * Deals in gold only, as leprechauns don't care for lesser coins.
86 register struct obj *chain;
88 while (chain && chain->otyp != GOLD_PIECE)
94 * Steal gold coins only. Leprechauns don't care for lesser coins.
98 register struct monst *mtmp;
100 register struct obj *fgold = g_at(u.ux, u.uy);
101 register struct obj *ygold;
104 const char *whose, *what;
106 /* skip lesser coins on the floor */
107 while (fgold && fgold->otyp != GOLD_PIECE)
108 fgold = fgold->nexthere;
110 /* Do you have real gold? */
111 ygold = findgold(invent);
113 if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) {
114 obj_extract_self(fgold);
115 add_to_minv(mtmp, fgold);
120 whose = s_suffix(y_monnam(who));
121 what = makeplural(mbodypart(who, FOOT));
125 what = makeplural(body_part(FOOT));
127 /* [ avoid "between your rear regions" :-] */
128 if (slithy(who->data))
130 /* reduce "rear hooves/claws" to "hooves/claws" */
131 if (!strncmp(what, "rear ", 5))
133 pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp),
134 (Levitation || Flying) ? "beneath" : "between", whose, what);
135 #else /*JP:
\91«
\82ª
\96³
\82
\82Ä
\82à
\81u
\91«
\8c³
\81v
\82Å
\82æ
\82µ
\82Æ
\82·
\82é*/
136 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),
137 (Levitation || Flying) ? "
\89º" : "
\91«
\8c³");
139 if (!ygold || !rn2(5)) {
140 if (!tele_restrict(mtmp))
141 (void) rloc(mtmp, TRUE);
142 monflee(mtmp, 0, FALSE, FALSE);
145 const int gold_price = objects[GOLD_PIECE].oc_cost;
147 tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price;
148 tmp = min(tmp, ygold->quan);
149 if (tmp < ygold->quan)
150 ygold = splitobj(ygold, tmp);
154 add_to_minv(mtmp, ygold);
156 Your("purse feels lighter.");
158 Your("
\8dà
\95z
\82Í
\8cy
\82
\82È
\82Á
\82½
\81D");
159 if (!tele_restrict(mtmp))
160 (void) rloc(mtmp, TRUE);
161 monflee(mtmp, 0, FALSE, FALSE);
166 /* steal armor after you finish taking it off */
167 unsigned int stealoid; /* object to be stolen */
168 unsigned int stealmid; /* monster doing the stealing */
173 register struct monst *mtmp;
174 register struct obj *otmp;
176 for (otmp = invent; otmp; otmp = otmp->nobj) {
177 if (otmp->o_id == stealoid) {
178 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
179 if (mtmp->m_id == stealmid) {
180 if (DEADMONSTER(mtmp))
181 impossible("stealarm(): dead monster stealing");
182 if (!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */
185 subfrombill(otmp, shop_keeper(*u.ushops));
188 pline("%s steals %s!", Monnam(mtmp), doname(otmp));
190 pline("%s
\82Í%s
\82ð
\93\90\82ñ
\82¾
\81I", Monnam(mtmp), doname(otmp));
191 (void) mpickobj(mtmp, otmp); /* may free otmp */
192 /* Implies seduction, "you gladly hand over ..."
193 so we don't set mavenge bit here. */
194 monflee(mtmp, 0, FALSE, FALSE);
195 if (!tele_restrict(mtmp))
196 (void) rloc(mtmp, TRUE);
208 /* An object you're wearing has been taken off by a monster (theft or
209 seduction). Also used if a worn item gets transformed (stone to flesh). */
211 remove_worn_item(obj, unchain_ball)
213 boolean unchain_ball; /* whether to unpunish or just unwield */
220 if (obj->owornmask & W_ARMOR) {
222 impossible("Removing embedded scales?");
223 skinback(TRUE); /* uarm = uskin; uskin = 0; */
227 else if (obj == uarmc)
229 else if (obj == uarmf)
231 else if (obj == uarmg)
233 else if (obj == uarmh)
235 else if (obj == uarms)
237 else if (obj == uarmu)
239 /* catchall -- should never happen */
241 setworn((struct obj *) 0, obj->owornmask & W_ARMOR);
242 } else if (obj->owornmask & W_AMUL) {
244 } else if (obj->owornmask & W_RING) {
246 } else if (obj->owornmask & W_TOOL) {
248 } else if (obj->owornmask & W_WEAPON) {
257 if (obj->owornmask & (W_BALL | W_CHAIN)) {
260 } else if (obj->owornmask) {
266 /* Returns 1 when something was stolen (or at least, when N should flee now)
267 * Returns -1 if the monster died in the attempt
268 * Avoid stealing the object stealoid
269 * Nymphs and monkeys won't steal coins
272 steal(mtmp, objnambuf)
277 int tmp, could_petrify, armordelay, olddelay, named = 0, retrycnt = 0;
278 boolean monkey_business, /* true iff an animal is doing the thievery */
283 /* the following is true if successful on first of two attacks. */
284 if (!monnear(mtmp, u.ux, u.uy))
287 /* food being eaten might already be used up but will not have
288 been removed from inventory yet; we don't want to steal that,
289 so this will cause it to be removed now */
291 (void) maybe_finished_meal(FALSE);
293 if (!invent || (inv_cnt(FALSE) == 1 && uskin)) {
295 /* Not even a thousand men in armor can strip a naked man. */
298 pline("Somebody tries to rob you, but finds nothing to steal.");
300 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");
303 pline("%s tries to rob you, but there is nothing to steal!",
305 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",
307 return 1; /* let her flee */
310 monkey_business = is_animal(mtmp->data);
311 if (monkey_business || uarmg) {
312 ; /* skip ring special cases */
313 } else if (Adornment & LEFT_RING) {
316 } else if (Adornment & RIGHT_RING) {
323 for (otmp = invent; otmp; otmp = otmp->nobj)
324 if ((!uarm || otmp != uarmc) && otmp != uskin
325 && otmp->oclass != COIN_CLASS)
326 tmp += (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
328 goto nothing_to_steal;
330 for (otmp = invent; otmp; otmp = otmp->nobj)
331 if ((!uarm || otmp != uarmc) && otmp != uskin
332 && otmp->oclass != COIN_CLASS) {
333 tmp -= (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
338 impossible("Steal fails!");
341 /* can't steal ring(s) while wearing gloves */
342 if ((otmp == uleft || otmp == uright) && uarmg)
344 /* can't steal gloves while wielding - so steal the wielded item. */
345 if (otmp == uarmg && uwep)
347 /* can't steal armor while wearing cloak - so steal the cloak. */
348 else if (otmp == uarm && uarmc)
350 /* can't steal shirt while wearing cloak or suit */
351 else if (otmp == uarmu && uarmc)
353 else if (otmp == uarmu && uarm)
357 if (otmp->o_id == stealoid)
360 if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) {
365 /* animals can't overcome curse stickiness nor unlock chains */
366 if (monkey_business) {
368 /* is the player prevented from voluntarily giving up this item?
369 (ignores loadstones; the !can_carry() check will catch those) */
371 ostuck = TRUE; /* effectively worn; curse is implicit */
372 else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap))
373 ostuck = FALSE; /* not really worn; curse doesn't matter */
375 ostuck = ((otmp->cursed && otmp->owornmask)
376 /* nymphs can steal rings from under
377 cursed weapon but animals can't */
378 || (otmp == uright && welded(uwep))
379 || (otmp == uleft && welded(uwep) && bimanual(uwep)));
381 if (ostuck || can_carry(mtmp, otmp) == 0) {
383 static const char *const how[] = { "steal", "snatch", "grab",
386 pline("%s tries to %s %s%s but gives up.", Monnam(mtmp),
388 (otmp->owornmask & W_ARMOR) ? "your " : "",
389 (otmp->owornmask & W_ARMOR) ? equipname(otmp)
393 pline("%s
\82Í%s
\82ð
\93\90\82à
\82¤
\82Æ
\82µ
\82½
\82ª
\92ú
\82ß
\82½
\81D", Monnam(mtmp),
394 (otmp->owornmask & W_ARMOR) ? equipname(otmp)
397 /* the fewer items you have, the less likely the thief
398 is going to stick around to try again (0) instead of
400 return !rn2(inv_cnt(FALSE) / 5 + 2);
404 if (otmp->otyp == LEASH && otmp->leashmon) {
405 if (monkey_business && otmp->cursed)
410 was_doffing = doffing(otmp);
411 /* stop donning/doffing now so that afternmv won't be clobbered
412 below; stop_occupation doesn't handle donning/doffing */
413 olddelay = stop_donning(otmp);
414 /* you're going to notice the theft... */
417 if (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) {
418 switch (otmp->oclass) {
422 case FOOD_CLASS: /* meat ring */
423 remove_worn_item(otmp, TRUE);
426 armordelay = objects[otmp->otyp].oc_delay;
427 if (olddelay > 0 && olddelay < armordelay)
428 armordelay = olddelay;
429 if (monkey_business) {
430 /* animals usually don't have enough patience
431 to take off items which require extra time */
432 if (armordelay >= 1 && !olddelay && rn2(10))
434 remove_worn_item(otmp, TRUE);
437 int curssv = otmp->cursed;
439 boolean seen = canspotmon(mtmp);
442 /* can't charm you without first waking you */
445 slowly = (armordelay >= 1 || multi < 0);
448 pline("%s charms you. You gladly %s your %s.",
449 !seen ? "She" : Monnam(mtmp),
450 curssv ? "let her take"
451 : !slowly ? "hand over"
452 : was_doffing ? "continue removing"
456 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",
457 !seen ? "
\94Þ
\8f\97" : Monnam(mtmp),
459 curssv ? "
\82Í
\82¸
\82µ
\82Ä
\82à
\82ç
\82Á"
460 : !slowly ? "
\82Í
\82¸
\82µ
\82Ä
\8eè
\93n
\82µ"
461 : was_doffing ? "
\82Í
\82¸
\82µ
\91±
\82¯"
462 : "
\82Í
\82¸
\82µ
\8en
\82ß");
466 pline("%s seduces you and %s off your %s.",
467 !seen ? "She" : Adjmonnam(mtmp, "beautiful"),
469 ? "helps you to take"
470 : !slowly ? "you take"
471 : was_doffing ? "you continue taking"
472 : "you start taking",
475 pline("%s
\82Í
\82 \82È
\82½
\82ð
\97U
\98f
\82µ
\82½
\81D
\82 \82È
\82½
\82Í%s
\82ð%s
\81D",
476 !seen ? "
\94Þ
\8f\97" : Adjmonnam(mtmp, "
\94ü
\82µ
\82¢"),
479 ? "
\82Í
\82¸
\82µ
\82Ä
\82à
\82ç
\82Á"
480 : !slowly ? "
\82Í
\82¸
\82µ"
481 : was_doffing ? "
\82Í
\82¸
\82µ
\91±
\82¯"
482 : "
\82Í
\82¸
\82µ
\8en
\82ß");
485 /* the following is to set multi for later on */
487 multi_reason = "taking off clothes";
489 remove_worn_item(otmp, TRUE);
490 otmp->cursed = curssv;
496 stealoid = otmp->o_id;
497 stealmid = mtmp->m_id;
504 impossible("Tried to steal a strange worn thing. [%d]",
507 } else if (otmp->owornmask)
508 remove_worn_item(otmp, TRUE);
510 /* do this before removing it from inventory */
512 Strcpy(objnambuf, yname(otmp));
513 /* set mavenge bit so knights won't suffer an
514 * alignment penalty during retaliation;
519 subfrombill(otmp, shop_keeper(*u.ushops));
522 pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
524 pline("%s
\82Í%s
\82ð
\93\90\82ñ
\82¾
\81D", named ? "
\94Þ
\8f\97" : Monnam(mtmp), doname(otmp));
526 (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]));
527 (void) mpickobj(mtmp, otmp); /* may free otmp */
528 if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) {
529 minstapetrify(mtmp, TRUE);
532 return (multi < 0) ? 0 : 1;
535 /* Returns 1 if otmp is free'd, 0 otherwise. */
538 register struct monst *mtmp;
539 register struct obj *otmp;
542 boolean snuff_otmp = FALSE;
544 /* if monster is acquiring a thrown or kicked object, the throwing
545 or kicking code shouldn't continue to track and place it */
546 if (otmp == thrownobj)
548 else if (otmp == kickedobj)
550 /* don't want hidden light source inside the monster; assumes that
551 engulfers won't have external inventories; whirly monsters cause
552 the light to be extinguished rather than letting it shine thru */
553 if (obj_sheds_light(otmp) && attacktype(mtmp->data, AT_ENGL)) {
554 /* this is probably a burning object that you dropped or threw */
555 if (u.uswallow && mtmp == u.ustuck && !Blind)
557 pline("%s out.", Tobjnam(otmp, "go"));
559 pline("%s
\82Í
\94ò
\82Ñ
\82¾
\82µ
\82½
\81D", xname(otmp));
562 /* for hero owned object on shop floor, mtmp is taking possession
563 and if it's eventually dropped in a shop, shk will claim it */
566 /* Must do carrying effects on object prior to add_to_minv() */
567 carry_obj_effects(otmp);
568 /* add_to_minv() might free otmp [if merged with something else],
569 so we have to call it after doing the object checks */
570 freed_otmp = add_to_minv(mtmp, otmp);
571 /* and we had to defer this until object is in mtmp's inventory */
573 snuff_light_source(mtmp->mx, mtmp->my);
581 struct obj *otmp = (struct obj *) 0;
582 int real = 0, fake = 0;
584 /* select the artifact to steal */
585 if (u.uhave.amulet) {
586 real = AMULET_OF_YENDOR;
587 fake = FAKE_AMULET_OF_YENDOR;
588 } else if (u.uhave.questart) {
589 for (otmp = invent; otmp; otmp = otmp->nobj)
590 if (is_quest_artifact(otmp))
593 return; /* should we panic instead? */
594 } else if (u.uhave.bell) {
595 real = BELL_OF_OPENING;
597 } else if (u.uhave.book) {
598 real = SPE_BOOK_OF_THE_DEAD;
599 } else if (u.uhave.menorah) {
600 real = CANDELABRUM_OF_INVOCATION;
602 return; /* you have nothing of special interest */
605 /* If we get here, real and fake have been set up. */
606 for (otmp = invent; otmp; otmp = otmp->nobj)
607 if (otmp->otyp == real || (otmp->otyp == fake && !mtmp->iswiz))
611 if (otmp) { /* we have something to snatch */
613 remove_worn_item(otmp, TRUE);
615 subfrombill(otmp, shop_keeper(*u.ushops));
617 /* mpickobj wont merge otmp because none of the above things
618 to steal are mergable */
619 (void) mpickobj(mtmp, otmp); /* may merge and free otmp */
621 pline("%s stole %s!", Monnam(mtmp), doname(otmp));
623 pline("%s
\82Í%s
\82ð
\93\90\82ñ
\82¾
\81I", Monnam(mtmp), doname(otmp));
624 if (can_teleport(mtmp->data) && !tele_restrict(mtmp))
625 (void) rloc(mtmp, TRUE);
629 /* when a mimic gets poked with something, it might take that thing
630 (at present, only implemented for when the hero does the poking) */
632 maybe_absorb_item(mon, obj, ochance, achance)
635 int ochance, achance; /* percent chance for ordinary item, artifact */
637 if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS
638 || obj_resists(obj, 100 - ochance, 100 - achance)
639 || !touch_artifact(obj, mon))
644 remove_worn_item(obj, TRUE);
646 subfrombill(obj, shop_keeper(*u.ushops));
647 if (cansee(mon->mx, mon->my)) {
648 const char *MonName = Monnam(mon);
650 /* mon might be invisible; avoid "It pulls ... and absorbs it!" */
651 if (!strcmp(MonName, "It"))
652 MonName = "Something";
653 pline("%s pulls %s away from you and absorbs %s!", MonName,
654 yname(obj), (obj->quan > 1L) ? "them" : "it");
656 const char *hand_s = body_part(HAND);
659 hand_s = makeplural(hand_s);
660 pline("%s %s pulled from your %s!", upstart(yname(obj)),
661 otense(obj, "are"), hand_s);
665 /* not carried; presumably thrown or kicked */
667 pline("%s absorbs %s!", Monnam(mon), yname(obj));
669 /* add to mon's inventory */
670 (void) mpickobj(mon, obj);
673 /* drop one object taken from a (possibly dead) monster's inventory */
675 mdrop_obj(mon, obj, verbosely)
680 int omx = mon->mx, omy = mon->my;
681 boolean update_mon = FALSE;
683 if (obj->owornmask) {
684 /* perform worn item handling if the monster is still alive */
686 mon->misc_worn_check &= ~obj->owornmask;
688 /* don't charge for an owned saddle on dead steed (provided
689 that the hero is within the same shop at the time) */
690 } else if (mon->mtame && (obj->owornmask & W_SADDLE) && !obj->unpaid
691 && costly_spot(omx, omy)
692 /* being at costly_spot guarantees lev->roomno is not 0 */
693 && index(in_rooms(u.ux, u.uy, SHOPBASE),
694 levl[omx][omy].roomno)) {
697 /* this should be done even if the monster has died */
698 if (obj->owornmask & W_WEP)
699 setmnotwielded(mon, obj);
702 /* obj_no_longer_held(obj); -- done by place_object */
703 if (verbosely && cansee(omx, omy))
705 pline("%s drops %s.", Monnam(mon), distant_name(obj, doname));
707 pline("%s
\82Í%s
\82ð
\92u
\82¢
\82½
\81D", Monnam(mon), distant_name(obj, doname));
709 if (!flooreffects(obj, omx, omy, "fall")) {
711 if (!flooreffects(obj, omx, omy, "
\97\8e\82¿
\82é")) {
712 place_object(obj, omx, omy);
715 /* do this last, after placing obj on floor; removing steed's saddle
716 throws rider, possibly inflicting fatal damage and producing bones */
718 update_mon_intrinsics(mon, obj, FALSE, TRUE);
721 /* some monsters bypass the normal rules for moving between levels or
722 even leaving the game entirely; when that happens, prevent them from
723 taking the Amulet or invocation tools with them */
725 mdrop_special_objs(mon)
728 struct obj *obj, *otmp;
730 for (obj = mon->minvent; obj; obj = otmp) {
732 /* the Amulet, invocation tools, and Rider corpses resist even when
733 artifacts and ordinary objects are given 0% resistance chance */
734 if (obj_resists(obj, 0, 0)) {
735 obj_extract_self(obj);
736 mdrop_obj(mon, obj, FALSE);
741 /* release the objects the creature is carrying */
743 relobj(mtmp, show, is_pet)
746 boolean is_pet; /* If true, pet should keep wielded/worn items */
749 int omx = mtmp->mx, omy = mtmp->my;
751 /* vault guard's gold goes away rather than be dropped... */
752 if (mtmp->isgd && (otmp = findgold(mtmp->minvent)) != 0) {
753 if (canspotmon(mtmp))
754 pline("%s gold %s.", s_suffix(Monnam(mtmp)),
755 canseemon(mtmp) ? "vanishes" : "seems to vanish");
756 obj_extract_self(otmp);
757 obfree(otmp, (struct obj *) 0);
758 } /* isgd && has gold */
760 while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) {
761 obj_extract_self(otmp);
762 mdrop_obj(mtmp, otmp, is_pet && flags.verbose);
765 if (show && cansee(omx, omy))