Source:NetHack 3.6.0/src/steal.c

From NetHackWiki
(Redirected from Steal.c)
Jump to: navigation, search

Below is the full text to steal.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/steal.c#line123]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

Top of file

  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. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_PTR int NDECL(stealarm);
  8.  
  9.  STATIC_DCL const char *FDECL(equipname, (struct obj *));
  10.  

equipname

  1.  STATIC_OVL const char *
  2.  equipname(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      return ((otmp == uarmu)
  6.                  ? "shirt"
  7.                  : (otmp == uarmf)
  8.                        ? "boots"
  9.                        : (otmp == uarms)
  10.                              ? "shield"
  11.                              : (otmp == uarmg)
  12.                                    ? "gloves"
  13.                                    : (otmp == uarmc)
  14.                                          ? cloak_simple_name(otmp)
  15.                                          : (otmp == uarmh)
  16.                                                ? helm_simple_name(otmp)
  17.                                                : suit_simple_name(otmp));
  18.  }
  19.  

somegold

  1.  /* proportional subset of gold; return value actually fits in an int */
  2.  long
  3.  somegold(lmoney)
  4.  long lmoney;
  5.  {
  6.  #ifdef LINT /* long conv. ok */
  7.      int igold = 0;
  8.  #else
  9.      int igold = (lmoney >= (long) LARGEST_INT) ? LARGEST_INT : (int) lmoney;
  10.  #endif
  11.  
  12.      if (igold < 50)
  13.          ; /* all gold */
  14.      else if (igold < 100)
  15.          igold = rn1(igold - 25 + 1, 25);
  16.      else if (igold < 500)
  17.          igold = rn1(igold - 50 + 1, 50);
  18.      else if (igold < 1000)
  19.          igold = rn1(igold - 100 + 1, 100);
  20.      else if (igold < 5000)
  21.          igold = rn1(igold - 500 + 1, 500);
  22.      else if (igold < 10000)
  23.          igold = rn1(igold - 1000 + 1, 1000);
  24.      else
  25.          igold = rn1(igold - 5000 + 1, 5000);
  26.  
  27.      return (long) igold;
  28.  }
  29.  

findgold

  1.  /*
  2.   * Find the first (and hopefully only) gold object in a chain.
  3.   * Used when leprechaun (or you as leprechaun) looks for
  4.   * someone else's gold.  Returns a pointer so the gold may
  5.   * be seized without further searching.
  6.   * May search containers too.
  7.   * Deals in gold only, as leprechauns don't care for lesser coins.
  8.  */
  9.  struct obj *
  10.  findgold(chain)
  11.  register struct obj *chain;
  12.  {
  13.      while (chain && chain->otyp != GOLD_PIECE)
  14.          chain = chain->nobj;
  15.      return chain;
  16.  }
  17.  

stealgold

  1.  /*
  2.   * Steal gold coins only.  Leprechauns don't care for lesser coins.
  3.  */
  4.  void
  5.  stealgold(mtmp)
  6.  register struct monst *mtmp;
  7.  {
  8.      register struct obj *fgold = g_at(u.ux, u.uy);
  9.      register struct obj *ygold;
  10.      register long tmp;
  11.      struct monst *who;
  12.      const char *whose, *what;
  13.  
  14.      /* skip lesser coins on the floor */
  15.      while (fgold && fgold->otyp != GOLD_PIECE)
  16.          fgold = fgold->nexthere;
  17.  
  18.      /* Do you have real gold? */
  19.      ygold = findgold(invent);
  20.  
  21.      if (fgold && (!ygold || fgold->quan > ygold->quan || !rn2(5))) {
  22.          obj_extract_self(fgold);
  23.          add_to_minv(mtmp, fgold);
  24.          newsym(u.ux, u.uy);
  25.          if (u.usteed) {
  26.              who = u.usteed;
  27.              whose = s_suffix(y_monnam(who));
  28.              what = makeplural(mbodypart(who, FOOT));
  29.          } else {
  30.              who = &youmonst;
  31.              whose = "your";
  32.              what = makeplural(body_part(FOOT));
  33.          }
  34.          /* [ avoid "between your rear regions" :-] */
  35.          if (slithy(who->data))
  36.              what = "coils";
  37.          /* reduce "rear hooves/claws" to "hooves/claws" */
  38.          if (!strncmp(what, "rear ", 5))
  39.              what += 5;
  40.          pline("%s quickly snatches some gold from %s %s %s!", Monnam(mtmp),
  41.                (Levitation || Flying) ? "beneath" : "between", whose, what);
  42.          if (!ygold || !rn2(5)) {
  43.              if (!tele_restrict(mtmp))
  44.                  (void) rloc(mtmp, TRUE);
  45.              monflee(mtmp, 0, FALSE, FALSE);
  46.          }
  47.      } else if (ygold) {
  48.          const int gold_price = objects[GOLD_PIECE].oc_cost;
  49.  
  50.          tmp = (somegold(money_cnt(invent)) + gold_price - 1) / gold_price;
  51.          tmp = min(tmp, ygold->quan);
  52.          if (tmp < ygold->quan)
  53.              ygold = splitobj(ygold, tmp);
  54.          else
  55.              setnotworn(ygold);
  56.          freeinv(ygold);
  57.          add_to_minv(mtmp, ygold);
  58.          Your("purse feels lighter.");
  59.          if (!tele_restrict(mtmp))
  60.              (void) rloc(mtmp, TRUE);
  61.          monflee(mtmp, 0, FALSE, FALSE);
  62.          context.botl = 1;
  63.      }
  64.  }
  65.  

stealarm

  1.  /* steal armor after you finish taking it off */
  2.  unsigned int stealoid; /* object to be stolen */
  3.  unsigned int stealmid; /* monster doing the stealing */
  4.  
  5.  STATIC_PTR int
  6.  stealarm(VOID_ARGS)
  7.  {
  8.      register struct monst *mtmp;
  9.      register struct obj *otmp;
  10.  
  11.      for (otmp = invent; otmp; otmp = otmp->nobj) {
  12.          if (otmp->o_id == stealoid) {
  13.              for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  14.                  if (mtmp->m_id == stealmid) {
  15.                      if (DEADMONSTER(mtmp))
  16.                          impossible("stealarm(): dead monster stealing");
  17.                      if (!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */
  18.                          goto botm;
  19.                      if (otmp->unpaid)
  20.                          subfrombill(otmp, shop_keeper(*u.ushops));
  21.                      freeinv(otmp);
  22.                      pline("%s steals %s!", Monnam(mtmp), doname(otmp));
  23.                      (void) mpickobj(mtmp, otmp); /* may free otmp */
  24.                      /* Implies seduction, "you gladly hand over ..."
  25.                         so we don't set mavenge bit here. */
  26.                      monflee(mtmp, 0, FALSE, FALSE);
  27.                      if (!tele_restrict(mtmp))
  28.                          (void) rloc(mtmp, TRUE);
  29.                      break;
  30.                  }
  31.              }
  32.              break;
  33.          }
  34.      }
  35.  botm:
  36.      stealoid = 0;
  37.      return 0;
  38.  }
  39.  

remove_worn_item

  1.  /* An object you're wearing has been taken off by a monster (theft or
  2.     seduction).  Also used if a worn item gets transformed (stone to flesh). */
  3.  void
  4.  remove_worn_item(obj, unchain_ball)
  5.  struct obj *obj;
  6.  boolean unchain_ball; /* whether to unpunish or just unwield */
  7.  {
  8.      if (donning(obj))
  9.          cancel_don();
  10.      if (!obj->owornmask)
  11.          return;
  12.  
  13.      if (obj->owornmask & W_ARMOR) {
  14.          if (obj == uskin) {
  15.              impossible("Removing embedded scales?");
  16.              skinback(TRUE); /* uarm = uskin; uskin = 0; */
  17.          }
  18.          if (obj == uarm)
  19.              (void) Armor_off();
  20.          else if (obj == uarmc)
  21.              (void) Cloak_off();
  22.          else if (obj == uarmf)
  23.              (void) Boots_off();
  24.          else if (obj == uarmg)
  25.              (void) Gloves_off();
  26.          else if (obj == uarmh)
  27.              (void) Helmet_off();
  28.          else if (obj == uarms)
  29.              (void) Shield_off();
  30.          else if (obj == uarmu)
  31.              (void) Shirt_off();
  32.          /* catchall -- should never happen */
  33.          else
  34.              setworn((struct obj *) 0, obj->owornmask & W_ARMOR);
  35.      } else if (obj->owornmask & W_AMUL) {
  36.          Amulet_off();
  37.      } else if (obj->owornmask & W_RING) {
  38.          Ring_gone(obj);
  39.      } else if (obj->owornmask & W_TOOL) {
  40.          Blindf_off(obj);
  41.      } else if (obj->owornmask & W_WEAPON) {
  42.          if (obj == uwep)
  43.              uwepgone();
  44.          if (obj == uswapwep)
  45.              uswapwepgone();
  46.          if (obj == uquiver)
  47.              uqwepgone();
  48.      }
  49.  
  50.      if (obj->owornmask & (W_BALL | W_CHAIN)) {
  51.          if (unchain_ball)
  52.              unpunish();
  53.      } else if (obj->owornmask) {
  54.          /* catchall */
  55.          setnotworn(obj);
  56.      }
  57.  }
  58.  

steal

  1.  /* Returns 1 when something was stolen (or at least, when N should flee now)
  2.   * Returns -1 if the monster died in the attempt
  3.   * Avoid stealing the object stealoid
  4.   * Nymphs and monkeys won't steal coins
  5.   */
  6.  int
  7.  steal(mtmp, objnambuf)
  8.  struct monst *mtmp;
  9.  char *objnambuf;
  10.  {
  11.      struct obj *otmp;
  12.      int tmp, could_petrify, armordelay, olddelay, named = 0, retrycnt = 0;
  13.      boolean monkey_business, /* true iff an animal is doing the thievery */
  14.          was_doffing;
  15.  
  16.      if (objnambuf)
  17.          *objnambuf = '\0';
  18.      /* the following is true if successful on first of two attacks. */
  19.      if (!monnear(mtmp, u.ux, u.uy))
  20.          return 0;
  21.  
  22.      /* food being eaten might already be used up but will not have
  23.         been removed from inventory yet; we don't want to steal that,
  24.         so this will cause it to be removed now */
  25.      if (occupation)
  26.          (void) maybe_finished_meal(FALSE);
  27.  
  28.      if (!invent || (inv_cnt(FALSE) == 1 && uskin)) {
  29.      nothing_to_steal:
  30.          /* Not even a thousand men in armor can strip a naked man. */
  31.          if (Blind)
  32.              pline("Somebody tries to rob you, but finds nothing to steal.");
  33.          else
  34.              pline("%s tries to rob you, but there is nothing to steal!",
  35.                    Monnam(mtmp));
  36.          return 1; /* let her flee */
  37.      }
  38.  
  39.      monkey_business = is_animal(mtmp->data);
  40.      if (monkey_business || uarmg) {
  41.          ; /* skip ring special cases */
  42.      } else if (Adornment & LEFT_RING) {
  43.          otmp = uleft;
  44.          goto gotobj;
  45.      } else if (Adornment & RIGHT_RING) {
  46.          otmp = uright;
  47.          goto gotobj;
  48.      }
  49.  
  50.  retry:
  51.      tmp = 0;
  52.      for (otmp = invent; otmp; otmp = otmp->nobj)
  53.          if ((!uarm || otmp != uarmc) && otmp != uskin
  54.              && otmp->oclass != COIN_CLASS)
  55.              tmp += (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
  56.      if (!tmp)
  57.          goto nothing_to_steal;
  58.      tmp = rn2(tmp);
  59.      for (otmp = invent; otmp; otmp = otmp->nobj)
  60.          if ((!uarm || otmp != uarmc) && otmp != uskin
  61.              && otmp->oclass != COIN_CLASS) {
  62.              tmp -= (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
  63.              if (tmp < 0)
  64.                  break;
  65.          }
  66.      if (!otmp) {
  67.          impossible("Steal fails!");
  68.          return 0;
  69.      }
  70.      /* can't steal ring(s) while wearing gloves */
  71.      if ((otmp == uleft || otmp == uright) && uarmg)
  72.          otmp = uarmg;
  73.      /* can't steal gloves while wielding - so steal the wielded item. */
  74.      if (otmp == uarmg && uwep)
  75.          otmp = uwep;
  76.      /* can't steal armor while wearing cloak - so steal the cloak. */
  77.      else if (otmp == uarm && uarmc)
  78.          otmp = uarmc;
  79.      /* can't steal shirt while wearing cloak or suit */
  80.      else if (otmp == uarmu && uarmc)
  81.          otmp = uarmc;
  82.      else if (otmp == uarmu && uarm)
  83.          otmp = uarm;
  84.  
  85.  gotobj:
  86.      if (otmp->o_id == stealoid)
  87.          return 0;
  88.  
  89.      if (otmp->otyp == BOULDER && !throws_rocks(mtmp->data)) {
  90.          if (!retrycnt++)
  91.              goto retry;
  92.          goto cant_take;
  93.      }
  94.      /* animals can't overcome curse stickiness nor unlock chains */
  95.      if (monkey_business) {
  96.          boolean ostuck;
  97.          /* is the player prevented from voluntarily giving up this item?
  98.             (ignores loadstones; the !can_carry() check will catch those) */
  99.          if (otmp == uball)
  100.              ostuck = TRUE; /* effectively worn; curse is implicit */
  101.          else if (otmp == uquiver || (otmp == uswapwep && !u.twoweap))
  102.              ostuck = FALSE; /* not really worn; curse doesn't matter */
  103.          else
  104.              ostuck = ((otmp->cursed && otmp->owornmask)
  105.                        /* nymphs can steal rings from under
  106.                           cursed weapon but animals can't */
  107.                        || (otmp == uright && welded(uwep))
  108.                        || (otmp == uleft && welded(uwep) && bimanual(uwep)));
  109.  
  110.          if (ostuck || can_carry(mtmp, otmp) == 0) {
  111.              static const char *const how[] = { "steal", "snatch", "grab",
  112.                                                 "take" };
  113.          cant_take:
  114.              pline("%s tries to %s %s%s but gives up.", Monnam(mtmp),
  115.                    how[rn2(SIZE(how))],
  116.                    (otmp->owornmask & W_ARMOR) ? "your " : "",
  117.                    (otmp->owornmask & W_ARMOR) ? equipname(otmp)
  118.                                                : yname(otmp));
  119.              /* the fewer items you have, the less likely the thief
  120.                 is going to stick around to try again (0) instead of
  121.                 running away (1) */
  122.              return !rn2(inv_cnt(FALSE) / 5 + 2);
  123.          }
  124.      }
  125.  
  126.      if (otmp->otyp == LEASH && otmp->leashmon) {
  127.          if (monkey_business && otmp->cursed)
  128.              goto cant_take;
  129.          o_unleash(otmp);
  130.      }
  131.  
  132.      was_doffing = doffing(otmp);
  133.      /* stop donning/doffing now so that afternmv won't be clobbered
  134.         below; stop_occupation doesn't handle donning/doffing */
  135.      olddelay = stop_donning(otmp);
  136.      /* you're going to notice the theft... */
  137.      stop_occupation();
  138.  
  139.      if (otmp->owornmask & (W_ARMOR | W_ACCESSORY)) {
  140.          switch (otmp->oclass) {
  141.          case TOOL_CLASS:
  142.          case AMULET_CLASS:
  143.          case RING_CLASS:
  144.          case FOOD_CLASS: /* meat ring */
  145.              remove_worn_item(otmp, TRUE);
  146.              break;
  147.          case ARMOR_CLASS:
  148.              armordelay = objects[otmp->otyp].oc_delay;
  149.              if (olddelay > 0 && olddelay < armordelay)
  150.                  armordelay = olddelay;
  151.              if (monkey_business) {
  152.                  /* animals usually don't have enough patience
  153.                     to take off items which require extra time */
  154.                  if (armordelay >= 1 && !olddelay && rn2(10))
  155.                      goto cant_take;
  156.                  remove_worn_item(otmp, TRUE);
  157.                  break;
  158.              } else {
  159.                  int curssv = otmp->cursed;
  160.                  int slowly;
  161.                  boolean seen = canspotmon(mtmp);
  162.  
  163.                  otmp->cursed = 0;
  164.                  /* can't charm you without first waking you */
  165.                  if (Unaware)
  166.                      unmul((char *) 0);
  167.                  slowly = (armordelay >= 1 || multi < 0);
  168.                  if (flags.female)
  169.                      pline("%s charms you.  You gladly %s your %s.",
  170.                            !seen ? "She" : Monnam(mtmp),
  171.                            curssv ? "let her take"
  172.                                   : !slowly ? "hand over"
  173.                                             : was_doffing ? "continue removing"
  174.                                                           : "start removing",
  175.                            equipname(otmp));
  176.                  else
  177.                      pline("%s seduces you and %s off your %s.",
  178.                            !seen ? "She" : Adjmonnam(mtmp, "beautiful"),
  179.                            curssv
  180.                                ? "helps you to take"
  181.                                : !slowly ? "you take"
  182.                                          : was_doffing ? "you continue taking"
  183.                                                        : "you start taking",
  184.                            equipname(otmp));
  185.                  named++;
  186.                  /* the following is to set multi for later on */
  187.                  nomul(-armordelay);
  188.                  multi_reason = "taking off clothes";
  189.                  nomovemsg = 0;
  190.                  remove_worn_item(otmp, TRUE);
  191.                  otmp->cursed = curssv;
  192.                  if (multi < 0) {
  193.                      /*
  194.                      multi = 0;
  195.                      afternmv = 0;
  196.                      */
  197.                      stealoid = otmp->o_id;
  198.                      stealmid = mtmp->m_id;
  199.                      afternmv = stealarm;
  200.                      return 0;
  201.                  }
  202.              }
  203.              break;
  204.          default:
  205.              impossible("Tried to steal a strange worn thing. [%d]",
  206.                         otmp->oclass);
  207.          }
  208.      } else if (otmp->owornmask)
  209.          remove_worn_item(otmp, TRUE);
  210.  
  211.      /* do this before removing it from inventory */
  212.      if (objnambuf)
  213.          Strcpy(objnambuf, yname(otmp));
  214.      /* set mavenge bit so knights won't suffer an
  215.       * alignment penalty during retaliation;
  216.       */
  217.      mtmp->mavenge = 1;
  218.  
  219.      if (otmp->unpaid)
  220.          subfrombill(otmp, shop_keeper(*u.ushops));
  221.      freeinv(otmp);
  222.      pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
  223.      could_petrify =
  224.          (otmp->otyp == CORPSE && touch_petrifies(&mons[otmp->corpsenm]));
  225.      (void) mpickobj(mtmp, otmp); /* may free otmp */
  226.      if (could_petrify && !(mtmp->misc_worn_check & W_ARMG)) {
  227.          minstapetrify(mtmp, TRUE);
  228.          return -1;
  229.      }
  230.      return (multi < 0) ? 0 : 1;
  231.  }
  232.  

mpickobj

  1.  /* Returns 1 if otmp is free'd, 0 otherwise. */
  2.  int
  3.  mpickobj(mtmp, otmp)
  4.  register struct monst *mtmp;
  5.  register struct obj *otmp;
  6.  {
  7.      int freed_otmp;
  8.      boolean snuff_otmp = FALSE;
  9.  
  10.      /* if monster is acquiring a thrown or kicked object, the throwing
  11.         or kicking code shouldn't continue to track and place it */
  12.      if (otmp == thrownobj)
  13.          thrownobj = 0;
  14.      else if (otmp == kickedobj)
  15.          kickedobj = 0;
  16.      /* don't want hidden light source inside the monster; assumes that
  17.         engulfers won't have external inventories; whirly monsters cause
  18.         the light to be extinguished rather than letting it shine thru */
  19.      if (obj_sheds_light(otmp) && attacktype(mtmp->data, AT_ENGL)) {
  20.          /* this is probably a burning object that you dropped or threw */
  21.          if (u.uswallow && mtmp == u.ustuck && !Blind)
  22.              pline("%s out.", Tobjnam(otmp, "go"));
  23.          snuff_otmp = TRUE;
  24.      }
  25.      /* for hero owned object on shop floor, mtmp is taking possession
  26.         and if it's eventually dropped in a shop, shk will claim it */
  27.      if (!mtmp->mtame)
  28.          otmp->no_charge = 0;
  29.      /* Must do carrying effects on object prior to add_to_minv() */
  30.      carry_obj_effects(otmp);
  31.      /* add_to_minv() might free otmp [if merged with something else],
  32.         so we have to call it after doing the object checks */
  33.      freed_otmp = add_to_minv(mtmp, otmp);
  34.      /* and we had to defer this until object is in mtmp's inventory */
  35.      if (snuff_otmp)
  36.          snuff_light_source(mtmp->mx, mtmp->my);
  37.      return freed_otmp;
  38.  }
  39.  

stealamulet

  1.  void
  2.  stealamulet(mtmp)
  3.  struct monst *mtmp;
  4.  {
  5.      struct obj *otmp = (struct obj *) 0;
  6.      int real = 0, fake = 0;
  7.  
  8.      /* select the artifact to steal */
  9.      if (u.uhave.amulet) {
  10.          real = AMULET_OF_YENDOR;
  11.          fake = FAKE_AMULET_OF_YENDOR;
  12.      } else if (u.uhave.questart) {
  13.          for (otmp = invent; otmp; otmp = otmp->nobj)
  14.              if (is_quest_artifact(otmp))
  15.                  break;
  16.          if (!otmp)
  17.              return; /* should we panic instead? */
  18.      } else if (u.uhave.bell) {
  19.          real = BELL_OF_OPENING;
  20.          fake = BELL;
  21.      } else if (u.uhave.book) {
  22.          real = SPE_BOOK_OF_THE_DEAD;
  23.      } else if (u.uhave.menorah) {
  24.          real = CANDELABRUM_OF_INVOCATION;
  25.      } else
  26.          return; /* you have nothing of special interest */
  27.  
  28.      if (!otmp) {
  29.          /* If we get here, real and fake have been set up. */
  30.          for (otmp = invent; otmp; otmp = otmp->nobj)
  31.              if (otmp->otyp == real || (otmp->otyp == fake && !mtmp->iswiz))
  32.                  break;
  33.      }
  34.  
  35.      if (otmp) { /* we have something to snatch */
  36.          if (otmp->owornmask)
  37.              remove_worn_item(otmp, TRUE);
  38.          if (otmp->unpaid)
  39.              subfrombill(otmp, shop_keeper(*u.ushops));
  40.          freeinv(otmp);
  41.          /* mpickobj wont merge otmp because none of the above things
  42.             to steal are mergable */
  43.          (void) mpickobj(mtmp, otmp); /* may merge and free otmp */
  44.          pline("%s stole %s!", Monnam(mtmp), doname(otmp));
  45.          if (can_teleport(mtmp->data) && !tele_restrict(mtmp))
  46.              (void) rloc(mtmp, TRUE);
  47.      }
  48.  }
  49.  

maybe_absorb_item

  1.  /* when a mimic gets poked with something, it might take that thing
  2.     (at present, only implemented for when the hero does the poking) */
  3.  void
  4.  maybe_absorb_item(mon, obj, ochance, achance)
  5.  struct monst *mon;
  6.  struct obj *obj;
  7.  int ochance, achance; /* percent chance for ordinary item, artifact */
  8.  {
  9.      if (obj == uball || obj == uchain || obj->oclass == ROCK_CLASS
  10.          || obj_resists(obj, 100 - ochance, 100 - achance)
  11.          || !touch_artifact(obj, mon))
  12.          return;
  13.  
  14.      if (carried(obj)) {
  15.          if (obj->owornmask)
  16.              remove_worn_item(obj, TRUE);
  17.          if (obj->unpaid)
  18.              subfrombill(obj, shop_keeper(*u.ushops));
  19.          if (cansee(mon->mx, mon->my)) {
  20.              const char *MonName = Monnam(mon);
  21.  
  22.              /* mon might be invisible; avoid "It pulls ... and absorbs it!" */
  23.              if (!strcmp(MonName, "It"))
  24.                  MonName = "Something";
  25.              pline("%s pulls %s away from you and absorbs %s!", MonName,
  26.                    yname(obj), (obj->quan > 1L) ? "them" : "it");
  27.          } else {
  28.              const char *hand_s = body_part(HAND);
  29.  
  30.              if (bimanual(obj))
  31.                  hand_s = makeplural(hand_s);
  32.              pline("%s %s pulled from your %s!", upstart(yname(obj)),
  33.                    otense(obj, "are"), hand_s);
  34.          }
  35.          freeinv(obj);
  36.      } else {
  37.          /* not carried; presumably thrown or kicked */
  38.          if (canspotmon(mon))
  39.              pline("%s absorbs %s!", Monnam(mon), yname(obj));
  40.      }
  41.      /* add to mon's inventory */
  42.      (void) mpickobj(mon, obj);
  43.  }
  44.  

mdrop_obj

  1.  /* drop one object taken from a (possibly dead) monster's inventory */
  2.  void
  3.  mdrop_obj(mon, obj, verbosely)
  4.  struct monst *mon;
  5.  struct obj *obj;
  6.  boolean verbosely;
  7.  {
  8.      int omx = mon->mx, omy = mon->my;
  9.      boolean update_mon = FALSE;
  10.  
  11.      if (obj->owornmask) {
  12.          /* perform worn item handling if the monster is still alive */
  13.          if (mon->mhp > 0) {
  14.              mon->misc_worn_check &= ~obj->owornmask;
  15.              update_mon = TRUE;
  16.              /* don't charge for an owned saddle on dead steed (provided
  17.                 that the hero is within the same shop at the time) */
  18.          } else if (mon->mtame && (obj->owornmask & W_SADDLE) && !obj->unpaid
  19.                     && costly_spot(omx, omy)
  20.                     /* being at costly_spot guarantees lev->roomno is not 0 */
  21.                     && index(in_rooms(u.ux, u.uy, SHOPBASE),
  22.                              levl[omx][omy].roomno)) {
  23.              obj->no_charge = 1;
  24.          }
  25.          /* this should be done even if the monster has died */
  26.          if (obj->owornmask & W_WEP)
  27.              setmnotwielded(mon, obj);
  28.          obj->owornmask = 0L;
  29.      }
  30.      /* obj_no_longer_held(obj); -- done by place_object */
  31.      if (verbosely && cansee(omx, omy))
  32.          pline("%s drops %s.", Monnam(mon), distant_name(obj, doname));
  33.      if (!flooreffects(obj, omx, omy, "fall")) {
  34.          place_object(obj, omx, omy);
  35.          stackobj(obj);
  36.      }
  37.      /* do this last, after placing obj on floor; removing steed's saddle
  38.         throws rider, possibly inflicting fatal damage and producing bones */
  39.      if (update_mon)
  40.          update_mon_intrinsics(mon, obj, FALSE, TRUE);
  41.  }
  42.  

mdrop_special_objs

  1.  /* some monsters bypass the normal rules for moving between levels or
  2.     even leaving the game entirely; when that happens, prevent them from
  3.     taking the Amulet or invocation tools with them */
  4.  void
  5.  mdrop_special_objs(mon)
  6.  struct monst *mon;
  7.  {
  8.      struct obj *obj, *otmp;
  9.  
  10.      for (obj = mon->minvent; obj; obj = otmp) {
  11.          otmp = obj->nobj;
  12.          /* the Amulet, invocation tools, and Rider corpses resist even when
  13.             artifacts and ordinary objects are given 0% resistance chance */
  14.          if (obj_resists(obj, 0, 0)) {
  15.              obj_extract_self(obj);
  16.              mdrop_obj(mon, obj, FALSE);
  17.          }
  18.      }
  19.  }
  20.  

relobj

  1.  /* release the objects the creature is carrying */
  2.  void
  3.  relobj(mtmp, show, is_pet)
  4.  struct monst *mtmp;
  5.  int show;
  6.  boolean is_pet; /* If true, pet should keep wielded/worn items */
  7.  {
  8.      struct obj *otmp;
  9.      int omx = mtmp->mx, omy = mtmp->my;
  10.  
  11.      /* vault guard's gold goes away rather than be dropped... */
  12.      if (mtmp->isgd && (otmp = findgold(mtmp->minvent)) != 0) {
  13.          if (canspotmon(mtmp))
  14.              pline("%s gold %s.", s_suffix(Monnam(mtmp)),
  15.                    canseemon(mtmp) ? "vanishes" : "seems to vanish");
  16.          obj_extract_self(otmp);
  17.          obfree(otmp, (struct obj *) 0);
  18.      } /* isgd && has gold */
  19.  
  20.      while ((otmp = (is_pet ? droppables(mtmp) : mtmp->minvent)) != 0) {
  21.          obj_extract_self(otmp);
  22.          mdrop_obj(mtmp, otmp, is_pet && flags.verbose);
  23.      }
  24.  
  25.      if (show && cansee(omx, omy))
  26.          newsym(omx, omy);
  27.  }
  28.  
  29.  /*steal.c*/