Source:NetHack 3.6.1/src/do.c

From NetHackWiki
(Redirected from Source:Ref/donull)
Jump to: navigation, search

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

Top of file

  1.  /* NetHack 3.6	do.c	$NHDT-Date: 1472809073 2016/09/02 09:37:53 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.158 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Derek S. Ray, 2015. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

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.

  1.  
  2.  /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) */
  3.  
  4.  #include "hack.h"
  5.  #include "lev.h"
  6.  
  7.  STATIC_DCL void FDECL(trycall, (struct obj *));
  8.  STATIC_DCL void NDECL(polymorph_sink);
  9.  STATIC_DCL boolean NDECL(teleport_sink);
  10.  STATIC_DCL void FDECL(dosinkring, (struct obj *));
  11.  STATIC_PTR int FDECL(drop, (struct obj *));
  12.  STATIC_PTR int NDECL(wipeoff);
  13.  STATIC_DCL int FDECL(menu_drop, (int));
  14.  STATIC_DCL int NDECL(currentlevel_rewrite);
  15.  STATIC_DCL void NDECL(final_level);
  16.  /* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */
  17.  
  18.  extern int n_dgns; /* number of dungeons, from dungeon.c */
  19.  
  20.  static NEARDATA const char drop_types[] = { ALLOW_COUNT, COIN_CLASS,
  21.                                              ALL_CLASSES, 0 };
  22.  

dodrop

  1.  /* 'd' command: drop one inventory item */
  2.  int
  3.  dodrop()
  4.  {
  5.      int result, i = (invent) ? 0 : (SIZE(drop_types) - 1);
  6.  
  7.      if (*u.ushops)
  8.          sellobj_state(SELL_DELIBERATE);
  9.      result = drop(getobj(&drop_types[i], "drop"));
  10.      if (*u.ushops)
  11.          sellobj_state(SELL_NORMAL);
  12.      if (result)
  13.          reset_occupations();
  14.  
  15.      return result;
  16.  }
  17.  

boulder_hits_pool

  1.  /* Called when a boulder is dropped, thrown, or pushed.  If it ends up
  2.   * in a pool, it either fills the pool up or sinks away.  In either case,
  3.   * it's gone for good...  If the destination is not a pool, returns FALSE.
  4.   */
  5.  boolean
  6.  boulder_hits_pool(otmp, rx, ry, pushing)
  7.  struct obj *otmp;
  8.  register int rx, ry;
  9.  boolean pushing;
  10.  {
  11.      if (!otmp || otmp->otyp != BOULDER) {
  12.          impossible("Not a boulder?");
  13.      } else if (!Is_waterlevel(&u.uz) && is_pool_or_lava(rx, ry)) {
  14.          boolean lava = is_lava(rx, ry), fills_up;
  15.          const char *what = waterbody_name(rx, ry);
  16.          schar ltyp = levl[rx][ry].typ;
  17.          int chance = rn2(10); /* water: 90%; lava: 10% */
  18.          fills_up = lava ? chance == 0 : chance != 0;
  19.  
  20.          if (fills_up) {
  21.              struct trap *ttmp = t_at(rx, ry);
  22.  
  23.              if (ltyp == DRAWBRIDGE_UP) {
  24.                  levl[rx][ry].drawbridgemask &= ~DB_UNDER; /* clear lava */
  25.                  levl[rx][ry].drawbridgemask |= DB_FLOOR;
  26.              } else
  27.                  levl[rx][ry].typ = ROOM;
  28.  
  29.              if (ttmp)
  30.                  (void) delfloortrap(ttmp);
  31.              bury_objs(rx, ry);
  32.  
  33.              newsym(rx, ry);
  34.              if (pushing) {
  35.                  char whobuf[BUFSZ];
  36.  
  37.                  Strcpy(whobuf, "you");
  38.                  if (u.usteed)
  39.                      Strcpy(whobuf, y_monnam(u.usteed));
  40.                  pline("%s %s %s into the %s.", upstart(whobuf),
  41.                        vtense(whobuf, "push"), the(xname(otmp)), what);
  42.                  if (flags.verbose && !Blind)
  43.                      pline("Now you can cross it!");
  44.                  /* no splashing in this case */
  45.              }
  46.          }
  47.          if (!fills_up || !pushing) { /* splashing occurs */
  48.              if (!u.uinwater) {
  49.                  if (pushing ? !Blind : cansee(rx, ry)) {
  50.                      There("is a large splash as %s %s the %s.",
  51.                            the(xname(otmp)), fills_up ? "fills" : "falls into",
  52.                            what);
  53.                  } else if (!Deaf)
  54.                      You_hear("a%s splash.", lava ? " sizzling" : "");
  55.                  wake_nearto(rx, ry, 40);
  56.              }
  57.  
  58.              if (fills_up && u.uinwater && distu(rx, ry) == 0) {
  59.                  u.uinwater = 0;
  60.                  docrt();
  61.                  vision_full_recalc = 1;
  62.                  You("find yourself on dry land again!");
  63.              } else if (lava && distu(rx, ry) <= 2) {
  64.                  int dmg;
  65.                  You("are hit by molten %s%c",
  66.                      hliquid("lava"), Fire_resistance ? '.' : '!');
  67.                  burn_away_slime();
  68.                  dmg = d((Fire_resistance ? 1 : 3), 6);
  69.                  losehp(Maybe_Half_Phys(dmg), /* lava damage */
  70.                         "molten lava", KILLED_BY);
  71.              } else if (!fills_up && flags.verbose
  72.                         && (pushing ? !Blind : cansee(rx, ry)))
  73.                  pline("It sinks without a trace!");
  74.          }
  75.  
  76.          /* boulder is now gone */
  77.          if (pushing)
  78.              delobj(otmp);
  79.          else
  80.              obfree(otmp, (struct obj *) 0);
  81.          return TRUE;
  82.      }
  83.      return FALSE;
  84.  }
  85.  

flooreffects

  1.  /* Used for objects which sometimes do special things when dropped; must be
  2.   * called with the object not in any chain.  Returns TRUE if the object goes
  3.   * away.
  4.   */
  5.  boolean
  6.  flooreffects(obj, x, y, verb)
  7.  struct obj *obj;
  8.  int x, y;
  9.  const char *verb;
  10.  {
  11.      struct trap *t;
  12.      struct monst *mtmp;
  13.      struct obj *otmp;
  14.  
  15.      if (obj->where != OBJ_FREE)
  16.          panic("flooreffects: obj not free");
  17.  
  18.      /* make sure things like water_damage() have no pointers to follow */
  19.      obj->nobj = obj->nexthere = (struct obj *) 0;
  20.  
  21.      if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE)) {
  22.          return TRUE;
  23.      } else if (obj->otyp == BOULDER && (t = t_at(x, y)) != 0
  24.               && (t->ttyp == PIT || t->ttyp == SPIKED_PIT
  25.                   || t->ttyp == TRAPDOOR || t->ttyp == HOLE)) {
  26.          if (((mtmp = m_at(x, y)) && mtmp->mtrapped)
  27.              || (u.utrap && u.ux == x && u.uy == y)) {
  28.              if (*verb)
  29.                  pline_The("boulder %s into the pit%s.",
  30.                            vtense((const char *) 0, verb),
  31.                            (mtmp) ? "" : " with you");
  32.              if (mtmp) {
  33.                  if (!passes_walls(mtmp->data) && !throws_rocks(mtmp->data)) {
  34.                      int dieroll = rnd(20);
  35.  
  36.                      if (hmon(mtmp, obj, HMON_THROWN, dieroll)
  37.                          && !is_whirly(mtmp->data))
  38.                          return FALSE; /* still alive */
  39.                  }
  40.                  mtmp->mtrapped = 0;
  41.              } else {
  42.                  if (!Passes_walls && !throws_rocks(youmonst.data)) {
  43.                      losehp(Maybe_Half_Phys(rnd(15)),
  44.                             "squished under a boulder", NO_KILLER_PREFIX);
  45.                      return FALSE; /* player remains trapped */
  46.                  } else
  47.                      u.utrap = 0;
  48.              }
  49.          }
  50.          if (*verb) {
  51.              if (Blind && (x == u.ux) && (y == u.uy)) {
  52.                  You_hear("a CRASH! beneath you.");
  53.              } else if (!Blind && cansee(x, y)) {
  54.                  pline_The("boulder %s%s.", t->tseen ? "" : "triggers and ",
  55.                            t->ttyp == TRAPDOOR
  56.                                ? "plugs a trap door"
  57.                                : t->ttyp == HOLE ? "plugs a hole"
  58.                                                  : "fills a pit");
  59.              } else {
  60.                  You_hear("a boulder %s.", verb);
  61.              }
  62.          }
  63.          deltrap(t);
  64.          useupf(obj, 1L);
  65.          bury_objs(x, y);
  66.          newsym(x, y);
  67.          return TRUE;
  68.      } else if (is_lava(x, y)) {
  69.          return lava_damage(obj, x, y);
  70.      } else if (is_pool(x, y)) {
  71.          /* Reasonably bulky objects (arbitrary) splash when dropped.
  72.           * If you're floating above the water even small things make
  73.           * noise.  Stuff dropped near fountains always misses */
  74.          if ((Blind || (Levitation || Flying)) && !Deaf
  75.              && ((x == u.ux) && (y == u.uy))) {
  76.              if (!Underwater) {
  77.                  if (weight(obj) > 9) {
  78.                      pline("Splash!");
  79.                  } else if (Levitation || Flying) {
  80.                      pline("Plop!");
  81.                  }
  82.              }
  83.              map_background(x, y, 0);
  84.              newsym(x, y);
  85.          }
  86.          return water_damage(obj, NULL, FALSE) == ER_DESTROYED;
  87.      } else if (u.ux == x && u.uy == y && (t = t_at(x, y)) != 0
  88.                 && uteetering_at_seen_pit(t)) {
  89.          if (Blind && !Deaf)
  90.              You_hear("%s tumble downwards.", the(xname(obj)));
  91.          else
  92.              pline("%s %s into %s pit.", The(xname(obj)),
  93.                    otense(obj, "tumble"), the_your[t->madeby_u]);
  94.      } else if (obj->globby) {
  95.          /* Globby things like puddings might stick together */
  96.          while (obj && (otmp = obj_nexto_xy(obj, x, y, TRUE)) != 0) {
  97.              pudding_merge_message(obj, otmp);
  98.              /* intentionally not getting the melded object; obj_meld may set
  99.               * obj to null. */
  100.              (void) obj_meld(&obj, &otmp);
  101.          }
  102.          return (boolean) !obj;
  103.      }
  104.      return FALSE;
  105.  }
  106.  

doaltarobj

  1.  /* obj is an object dropped on an altar */
  2.  void
  3.  doaltarobj(obj)
  4.  register struct obj *obj;
  5.  {
  6.      if (Blind)
  7.          return;
  8.  
  9.      if (obj->oclass != COIN_CLASS) {
  10.          /* KMH, conduct */
  11.          u.uconduct.gnostic++;
  12.      } else {
  13.          /* coins don't have bless/curse status */
  14.          obj->blessed = obj->cursed = 0;
  15.      }
  16.  
  17.      if (obj->blessed || obj->cursed) {
  18.          There("is %s flash as %s %s the altar.",
  19.                an(hcolor(obj->blessed ? NH_AMBER : NH_BLACK)), doname(obj),
  20.                otense(obj, "hit"));
  21.          if (!Hallucination)
  22.              obj->bknown = 1;
  23.      } else {
  24.          pline("%s %s on the altar.", Doname2(obj), otense(obj, "land"));
  25.          if (obj->oclass != COIN_CLASS)
  26.              obj->bknown = 1;
  27.      }
  28.  }
  29.  

trycall

  1.  STATIC_OVL void
  2.  trycall(obj)
  3.  register struct obj *obj;
  4.  {
  5.      if (!objects[obj->otyp].oc_name_known && !objects[obj->otyp].oc_uname)
  6.          docall(obj);
  7.  }
  8.  

polymorph_sink

  1.  /* Transforms the sink at the player's position into
  2.     a fountain, throne, altar or grave. */
  3.  STATIC_DCL void
  4.  polymorph_sink()
  5.  {
  6.      uchar sym = S_sink;
  7.  
  8.      if (levl[u.ux][u.uy].typ != SINK)
  9.          return;
  10.  
  11.      level.flags.nsinks--;
  12.      levl[u.ux][u.uy].doormask = 0;
  13.      switch (rn2(4)) {
  14.      default:
  15.      case 0:
  16.          sym = S_fountain;
  17.          levl[u.ux][u.uy].typ = FOUNTAIN;
  18.          level.flags.nfountains++;
  19.          break;
  20.      case 1:
  21.          sym = S_throne;
  22.          levl[u.ux][u.uy].typ = THRONE;
  23.          break;
  24.      case 2:
  25.          sym = S_altar;
  26.          levl[u.ux][u.uy].typ = ALTAR;
  27.          levl[u.ux][u.uy].altarmask = Align2amask(rn2((int) A_LAWFUL + 2) - 1);
  28.          break;
  29.      case 3:
  30.          sym = S_room;
  31.          levl[u.ux][u.uy].typ = ROOM;
  32.          make_grave(u.ux, u.uy, (char *) 0);
  33.          if (levl[u.ux][u.uy].typ == GRAVE)
  34.              sym = S_grave;
  35.          break;
  36.      }
  37.      /* give message even if blind; we know we're not levitating,
  38.         so can feel the outcome even if we can't directly see it */
  39.      if (levl[u.ux][u.uy].typ != ROOM)
  40.          pline_The("sink transforms into %s!", an(defsyms[sym].explanation));
  41.      else
  42.          pline_The("sink vanishes.");
  43.      newsym(u.ux, u.uy);
  44.  }
  45.  

teleport_sink

  1.  /* Teleports the sink at the player's position;
  2.     return True if sink teleported. */
  3.  STATIC_DCL boolean
  4.  teleport_sink()
  5.  {
  6.      int cx, cy;
  7.      int cnt = 0;
  8.      struct trap *trp;
  9.      struct engr *eng;
  10.  
  11.      do {
  12.          cx = rnd(COLNO - 1);
  13.          cy = rn2(ROWNO);
  14.          trp = t_at(cx, cy);
  15.          eng = engr_at(cx, cy);
  16.      } while ((levl[cx][cy].typ != ROOM || trp || eng || cansee(cx, cy))
  17.               && cnt++ < 200);
  18.  
  19.      if (levl[cx][cy].typ == ROOM && !trp && !eng) {
  20.          /* create sink at new position */
  21.          levl[cx][cy].typ = SINK;
  22.          levl[cx][cy].looted = levl[u.ux][u.uy].looted;
  23.          newsym(cx, cy);
  24.          /* remove old sink */
  25.          levl[u.ux][u.uy].typ = ROOM;
  26.          levl[u.ux][u.uy].looted = 0;
  27.          newsym(u.ux, u.uy);
  28.          return TRUE;
  29.      }
  30.      return FALSE;
  31.  }
  32.  

dosinkring

  1.  /* obj is a ring being dropped over a kitchen sink */
  2.  STATIC_OVL void
  3.  dosinkring(obj)
  4.  register struct obj *obj;
  5.  {
  6.      struct obj *otmp, *otmp2;
  7.      boolean ideed = TRUE;
  8.      boolean nosink = FALSE;
  9.  
  10.      You("drop %s down the drain.", doname(obj));
  11.      obj->in_use = TRUE;  /* block free identification via interrupt */
  12.      switch (obj->otyp) { /* effects that can be noticed without eyes */
  13.      case RIN_SEARCHING:
  14.          You("thought %s got lost in the sink, but there it is!", yname(obj));
  15.          goto giveback;
  16.      case RIN_SLOW_DIGESTION:
  17.          pline_The("ring is regurgitated!");
  18.      giveback:
  19.          obj->in_use = FALSE;
  20.          dropx(obj);
  21.          trycall(obj);
  22.          return;
  23.      case RIN_LEVITATION:
  24.          pline_The("sink quivers upward for a moment.");
  25.          break;
  26.      case RIN_POISON_RESISTANCE:
  27.          You("smell rotten %s.", makeplural(fruitname(FALSE)));
  28.          break;
  29.      case RIN_AGGRAVATE_MONSTER:
  30.          pline("Several %s buzz angrily around the sink.",
  31.                Hallucination ? makeplural(rndmonnam(NULL)) : "flies");
  32.          break;
  33.      case RIN_SHOCK_RESISTANCE:
  34.          pline("Static electricity surrounds the sink.");
  35.          break;
  36.      case RIN_CONFLICT:
  37.          You_hear("loud noises coming from the drain.");
  38.          break;
  39.      case RIN_SUSTAIN_ABILITY: /* KMH */
  40.          pline_The("%s flow seems fixed.", hliquid("water"));
  41.          break;
  42.      case RIN_GAIN_STRENGTH:
  43.          pline_The("%s flow seems %ser now.",
  44.                    hliquid("water"),
  45.                    (obj->spe < 0) ? "weak" : "strong");
  46.          break;
  47.      case RIN_GAIN_CONSTITUTION:
  48.          pline_The("%s flow seems %ser now.",
  49.                    hliquid("water"),
  50.                    (obj->spe < 0) ? "less" : "great");
  51.          break;
  52.      case RIN_INCREASE_ACCURACY: /* KMH */
  53.          pline_The("%s flow %s the drain.",
  54.                    hliquid("water"),
  55.                    (obj->spe < 0) ? "misses" : "hits");
  56.          break;
  57.      case RIN_INCREASE_DAMAGE:
  58.          pline_The("water's force seems %ser now.",
  59.                    (obj->spe < 0) ? "small" : "great");
  60.          break;
  61.      case RIN_HUNGER:
  62.          ideed = FALSE;
  63.          for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) {
  64.              otmp2 = otmp->nexthere;
  65.              if (otmp != uball && otmp != uchain
  66.                  && !obj_resists(otmp, 1, 99)) {
  67.                  if (!Blind) {
  68.                      pline("Suddenly, %s %s from the sink!", doname(otmp),
  69.                            otense(otmp, "vanish"));
  70.                      ideed = TRUE;
  71.                  }
  72.                  delobj(otmp);
  73.              }
  74.          }
  75.          break;
  76.      case MEAT_RING:
  77.          /* Not the same as aggravate monster; besides, it's obvious. */
  78.          pline("Several flies buzz around the sink.");
  79.          break;
  80.      case RIN_TELEPORTATION:
  81.          nosink = teleport_sink();
  82.          /* give message even if blind; we know we're not levitating,
  83.             so can feel the outcome even if we can't directly see it */
  84.          pline_The("sink %svanishes.", nosink ? "" : "momentarily ");
  85.          ideed = FALSE;
  86.          break;
  87.      case RIN_POLYMORPH:
  88.          polymorph_sink();
  89.          nosink = TRUE;
  90.          /* for S_room case, same message as for teleportation is given */
  91.          ideed = (levl[u.ux][u.uy].typ != ROOM);
  92.          break;
  93.      default:
  94.          ideed = FALSE;
  95.          break;
  96.      }
  97.      if (!Blind && !ideed) {
  98.          ideed = TRUE;
  99.          switch (obj->otyp) { /* effects that need eyes */
  100.          case RIN_ADORNMENT:
  101.              pline_The("faucets flash brightly for a moment.");
  102.              break;
  103.          case RIN_REGENERATION:
  104.              pline_The("sink looks as good as new.");
  105.              break;
  106.          case RIN_INVISIBILITY:
  107.              You("don't see anything happen to the sink.");
  108.              break;
  109.          case RIN_FREE_ACTION:
  110.              You_see("the ring slide right down the drain!");
  111.              break;
  112.          case RIN_SEE_INVISIBLE:
  113.              You_see("some %s in the sink.",
  114.                      Hallucination ? "oxygen molecules" : "air");
  115.              break;
  116.          case RIN_STEALTH:
  117.              pline_The("sink seems to blend into the floor for a moment.");
  118.              break;
  119.          case RIN_FIRE_RESISTANCE:
  120.              pline_The("hot %s faucet flashes brightly for a moment.",
  121.                        hliquid("water"));
  122.              break;
  123.          case RIN_COLD_RESISTANCE:
  124.              pline_The("cold %s faucet flashes brightly for a moment.",
  125.                        hliquid("water"));
  126.              break;
  127.          case RIN_PROTECTION_FROM_SHAPE_CHAN:
  128.              pline_The("sink looks nothing like a fountain.");
  129.              break;
  130.          case RIN_PROTECTION:
  131.              pline_The("sink glows %s for a moment.",
  132.                        hcolor((obj->spe < 0) ? NH_BLACK : NH_SILVER));
  133.              break;
  134.          case RIN_WARNING:
  135.              pline_The("sink glows %s for a moment.", hcolor(NH_WHITE));
  136.              break;
  137.          case RIN_TELEPORT_CONTROL:
  138.              pline_The("sink looks like it is being beamed aboard somewhere.");
  139.              break;
  140.          case RIN_POLYMORPH_CONTROL:
  141.              pline_The(
  142.                    "sink momentarily looks like a regularly erupting geyser.");
  143.              break;
  144.          default:
  145.              break;
  146.          }
  147.      }
  148.      if (ideed)
  149.          trycall(obj);
  150.      else if (!nosink)
  151.          You_hear("the ring bouncing down the drainpipe.");
  152.  
  153.      if (!rn2(20) && !nosink) {
  154.          pline_The("sink backs up, leaving %s.", doname(obj));
  155.          obj->in_use = FALSE;
  156.          dropx(obj);
  157.      } else if (!rn2(5)) {
  158.          freeinv(obj);
  159.          obj->in_use = FALSE;
  160.          obj->ox = u.ux;
  161.          obj->oy = u.uy;
  162.          add_to_buried(obj);
  163.      } else
  164.          useup(obj);
  165.  }
  166.  

canletgo

  1.  /* some common tests when trying to drop or throw items */
  2.  boolean
  3.  canletgo(obj, word)
  4.  struct obj *obj;
  5.  const char *word;
  6.  {
  7.      if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) {
  8.          if (*word)
  9.              Norep("You cannot %s %s you are wearing.", word, something);
  10.          return FALSE;
  11.      }
  12.      if (obj->otyp == LOADSTONE && obj->cursed) {
  13.          /* getobj() kludge sets corpsenm to user's specified count
  14.             when refusing to split a stack of cursed loadstones */
  15.          if (*word) {
  16.              /* getobj() ignores a count for throwing since that is
  17.                 implicitly forced to be 1; replicate its kludge... */
  18.              if (!strcmp(word, "throw") && obj->quan > 1L)
  19.                  obj->corpsenm = 1;
  20.              pline("For some reason, you cannot %s%s the stone%s!", word,
  21.                    obj->corpsenm ? " any of" : "", plur(obj->quan));
  22.          }
  23.          obj->corpsenm = 0; /* reset */
  24.          obj->bknown = 1;
  25.          return FALSE;
  26.      }
  27.      if (obj->otyp == LEASH && obj->leashmon != 0) {
  28.          if (*word)
  29.              pline_The("leash is tied around your %s.", body_part(HAND));
  30.          return FALSE;
  31.      }
  32.      if (obj->owornmask & W_SADDLE) {
  33.          if (*word)
  34.              You("cannot %s %s you are sitting on.", word, something);
  35.          return FALSE;
  36.      }
  37.      return TRUE;
  38.  }
  39.  

drop

  1.  STATIC_PTR int
  2.  drop(obj)
  3.  register struct obj *obj;
  4.  {
  5.      if (!obj)
  6.          return 0;
  7.      if (!canletgo(obj, "drop"))
  8.          return 0;
  9.      if (obj == uwep) {
  10.          if (welded(uwep)) {
  11.              weldmsg(obj);
  12.              return 0;
  13.          }
  14.          setuwep((struct obj *) 0);
  15.      }
  16.      if (obj == uquiver) {
  17.          setuqwep((struct obj *) 0);
  18.      }
  19.      if (obj == uswapwep) {
  20.          setuswapwep((struct obj *) 0);
  21.      }
  22.  
  23.      if (u.uswallow) {
  24.          /* barrier between you and the floor */
  25.          if (flags.verbose) {
  26.              char buf[BUFSZ];
  27.  
  28.              /* doname can call s_suffix, reusing its buffer */
  29.              Strcpy(buf, s_suffix(mon_nam(u.ustuck)));
  30.              You("drop %s into %s %s.", doname(obj), buf,
  31.                  mbodypart(u.ustuck, STOMACH));
  32.          }
  33.      } else {
  34.          if ((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING)
  35.              && IS_SINK(levl[u.ux][u.uy].typ)) {
  36.              dosinkring(obj);
  37.              return 1;
  38.          }
  39.          if (!can_reach_floor(TRUE)) {
  40.              /* we might be levitating due to #invoke Heart of Ahriman;
  41.                 if so, levitation would end during call to freeinv()
  42.                 and we want hitfloor() to happen before float_down() */
  43.              boolean levhack = finesse_ahriman(obj);
  44.  
  45.              if (levhack)
  46.                  ELevitation = W_ART; /* other than W_ARTI */
  47.              if (flags.verbose)
  48.                  You("drop %s.", doname(obj));
  49.              /* Ensure update when we drop gold objects */
  50.              if (obj->oclass == COIN_CLASS)
  51.                  context.botl = 1;
  52.              freeinv(obj);
  53.              hitfloor(obj);
  54.              if (levhack)
  55.                  float_down(I_SPECIAL | TIMEOUT, W_ARTI | W_ART);
  56.              return 1;
  57.          }
  58.          if (!IS_ALTAR(levl[u.ux][u.uy].typ) && flags.verbose)
  59.              You("drop %s.", doname(obj));
  60.      }
  61.      dropx(obj);
  62.      return 1;
  63.  }
  64.  

dropx

  1.  /* dropx - take dropped item out of inventory;
  2.     called in several places - may produce output
  3.     (eg ship_object() and dropy() -> sellobj() both produce output) */
  4.  void
  5.  dropx(obj)
  6.  register struct obj *obj;
  7.  {
  8.      /* Ensure update when we drop gold objects */
  9.      if (obj->oclass == COIN_CLASS)
  10.          context.botl = 1;
  11.      freeinv(obj);
  12.      if (!u.uswallow) {
  13.          if (ship_object(obj, u.ux, u.uy, FALSE))
  14.              return;
  15.          if (IS_ALTAR(levl[u.ux][u.uy].typ))
  16.              doaltarobj(obj); /* set bknown */
  17.      }
  18.      dropy(obj);
  19.  }
  20.  

dropy

  1.  /* dropy - put dropped object at destination; called from lots of places */
  2.  void
  3.  dropy(obj)
  4.  struct obj *obj;
  5.  {
  6.      dropz(obj, FALSE);
  7.  }
  8.  

dropz

  1.  /* dropz - really put dropped object at its destination... */
  2.  void
  3.  dropz(obj, with_impact)
  4.  struct obj *obj;
  5.  boolean with_impact;
  6.  {
  7.      if (obj == uwep)
  8.          setuwep((struct obj *) 0);
  9.      if (obj == uquiver)
  10.          setuqwep((struct obj *) 0);
  11.      if (obj == uswapwep)
  12.          setuswapwep((struct obj *) 0);
  13.  
  14.      if (!u.uswallow && flooreffects(obj, u.ux, u.uy, "drop"))
  15.          return;
  16.      /* uswallow check done by GAN 01/29/87 */
  17.      if (u.uswallow) {
  18.          boolean could_petrify = FALSE;
  19.          boolean could_poly = FALSE;
  20.          boolean could_slime = FALSE;
  21.          boolean could_grow = FALSE;
  22.          boolean could_heal = FALSE;
  23.  
  24.          if (obj != uball) { /* mon doesn't pick up ball */
  25.              if (obj->otyp == CORPSE) {
  26.                  could_petrify = touch_petrifies(&mons[obj->corpsenm]);
  27.                  could_poly = polyfodder(obj);
  28.                  could_slime = (obj->corpsenm == PM_GREEN_SLIME);
  29.                  could_grow = (obj->corpsenm == PM_WRAITH);
  30.                  could_heal = (obj->corpsenm == PM_NURSE);
  31.              }
  32.              (void) mpickobj(u.ustuck, obj);
  33.              if (is_animal(u.ustuck->data)) {
  34.                  if (could_poly || could_slime) {
  35.                      (void) newcham(u.ustuck,
  36.                                     could_poly ? (struct permonst *) 0
  37.                                                : &mons[PM_GREEN_SLIME],
  38.                                     FALSE, could_slime);
  39.                      delobj(obj); /* corpse is digested */
  40.                  } else if (could_petrify) {
  41.                      minstapetrify(u.ustuck, TRUE);
  42.                      /* Don't leave a cockatrice corpse in a statue */
  43.                      if (!u.uswallow)
  44.                          delobj(obj);
  45.                  } else if (could_grow) {
  46.                      (void) grow_up(u.ustuck, (struct monst *) 0);
  47.                      delobj(obj); /* corpse is digested */
  48.                  } else if (could_heal) {
  49.                      u.ustuck->mhp = u.ustuck->mhpmax;
  50.                      delobj(obj); /* corpse is digested */
  51.                  }
  52.              }
  53.          }
  54.      } else {
  55.          place_object(obj, u.ux, u.uy);
  56.          if (with_impact)
  57.              container_impact_dmg(obj, u.ux, u.uy);
  58.          if (obj == uball)
  59.              drop_ball(u.ux, u.uy);
  60.          else if (level.flags.has_shop)
  61.              sellobj(obj, u.ux, u.uy);
  62.          stackobj(obj);
  63.          if (Blind && Levitation)
  64.              map_object(obj, 0);
  65.          newsym(u.ux, u.uy); /* remap location under self */
  66.      }
  67.  }
  68.  

obj_no_longer_held

  1.  /* things that must change when not held; recurse into containers.
  2.     Called for both player and monsters */
  3.  void
  4.  obj_no_longer_held(obj)
  5.  struct obj *obj;
  6.  {
  7.      if (!obj) {
  8.          return;
  9.      } else if (Has_contents(obj)) {
  10.          struct obj *contents;
  11.  
  12.          for (contents = obj->cobj; contents; contents = contents->nobj)
  13.              obj_no_longer_held(contents);
  14.      }
  15.      switch (obj->otyp) {
  16.      case CRYSKNIFE:
  17.          /* Normal crysknife reverts to worm tooth when not held by hero
  18.           * or monster; fixed crysknife has only 10% chance of reverting.
  19.           * When a stack of the latter is involved, it could be worthwhile
  20.           * to give each individual crysknife its own separate 10% chance,
  21.           * but we aren't in any position to handle stack splitting here.
  22.           */
  23.          if (!obj->oerodeproof || !rn2(10)) {
  24.              /* if monsters aren't moving, assume player is responsible */
  25.              if (!context.mon_moving && !program_state.gameover)
  26.                  costly_alteration(obj, COST_DEGRD);
  27.              obj->otyp = WORM_TOOTH;
  28.              obj->oerodeproof = 0;
  29.          }
  30.          break;
  31.      }
  32.  }
  33.  

doddrop

  1.  /* 'D' command: drop several things */
  2.  int
  3.  doddrop()
  4.  {
  5.      int result = 0;
  6.  
  7.      if (!invent) {
  8.          You("have nothing to drop.");
  9.          return 0;
  10.      }
  11.      add_valid_menu_class(0); /* clear any classes already there */
  12.      if (*u.ushops)
  13.          sellobj_state(SELL_DELIBERATE);
  14.      if (flags.menu_style != MENU_TRADITIONAL
  15.          || (result = ggetobj("drop", drop, 0, FALSE, (unsigned *) 0)) < -1)
  16.          result = menu_drop(result);
  17.      if (*u.ushops)
  18.          sellobj_state(SELL_NORMAL);
  19.      if (result)
  20.          reset_occupations();
  21.  
  22.      return result;
  23.  }
  24.  

menu_drop

  1.  /* Drop things from the hero's inventory, using a menu. */
  2.  STATIC_OVL int
  3.  menu_drop(retry)
  4.  int retry;
  5.  {
  6.      int n, i, n_dropped = 0;
  7.      long cnt;
  8.      struct obj *otmp, *otmp2;
  9.      menu_item *pick_list;
  10.      boolean all_categories = TRUE;
  11.      boolean drop_everything = FALSE;
  12.  
  13.      if (retry) {
  14.          all_categories = (retry == -2);
  15.      } else if (flags.menu_style == MENU_FULL) {
  16.          all_categories = FALSE;
  17.          n = query_category("Drop what type of items?", invent,
  18.                             UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL | BUC_BLESSED
  19.                                 | BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN,
  20.                             &pick_list, PICK_ANY);
  21.          if (!n)
  22.              goto drop_done;
  23.          for (i = 0; i < n; i++) {
  24.              if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
  25.                  all_categories = TRUE;
  26.              else if (pick_list[i].item.a_int == 'A')
  27.                  drop_everything = TRUE;
  28.              else
  29.                  add_valid_menu_class(pick_list[i].item.a_int);
  30.          }
  31.          free((genericptr_t) pick_list);
  32.      } else if (flags.menu_style == MENU_COMBINATION) {
  33.          unsigned ggoresults = 0;
  34.  
  35.          all_categories = FALSE;
  36.          /* Gather valid classes via traditional NetHack method */
  37.          i = ggetobj("drop", drop, 0, TRUE, &ggoresults);
  38.          if (i == -2)
  39.              all_categories = TRUE;
  40.          if (ggoresults & ALL_FINISHED) {
  41.              n_dropped = i;
  42.              goto drop_done;
  43.          }
  44.      }
  45.  
  46.      if (drop_everything) {
  47.          /*
  48.           * Dropping a burning potion of oil while levitating can cause
  49.           * an explosion which might destroy some of hero's inventory,
  50.           * so the old code
  51.           *      for (otmp = invent; otmp; otmp = otmp2) {
  52.           *          otmp2 = otmp->nobj;
  53.           *          n_dropped += drop(otmp);
  54.           *      }
  55.           * was unreliable and could lead to an "object lost" panic.
  56.           *
  57.           * Use the bypass bit to mark items already processed (hence
  58.           * not droppable) and rescan inventory until no unbypassed
  59.           * items remain.
  60.           */
  61.          bypass_objlist(invent, FALSE); /* clear bypass bit for invent */
  62.          while ((otmp = nxt_unbypassed_obj(invent)) != 0)
  63.              n_dropped += drop(otmp);
  64.          /* we might not have dropped everything (worn armor, welded weapon,
  65.             cursed loadstones), so reset any remaining inventory to normal */
  66.          bypass_objlist(invent, FALSE);
  67.      } else {
  68.          /* should coordinate with perm invent, maybe not show worn items */
  69.          n = query_objlist("What would you like to drop?", &invent,
  70.                            (USE_INVLET | INVORDER_SORT), &pick_list, PICK_ANY,
  71.                            all_categories ? allow_all : allow_category);
  72.          if (n > 0) {
  73.              /*
  74.               * picklist[] contains a set of pointers into inventory, but
  75.               * as soon as something gets dropped, they might become stale
  76.               * (see the drop_everything code above for an explanation).
  77.               * Just checking to see whether one is still in the invent
  78.               * chain is not sufficient validation since destroyed items
  79.               * will be freed and items we've split here might have already
  80.               * reused that memory and put the same pointer value back into
  81.               * invent.  Ditto for using invlet to validate.  So we start
  82.               * by setting bypass on all of invent, then check each pointer
  83.               * to verify that it is in invent and has that bit set.
  84.               */
  85.              bypass_objlist(invent, TRUE);
  86.              for (i = 0; i < n; i++) {
  87.                  otmp = pick_list[i].item.a_obj;
  88.                  for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj)
  89.                      if (otmp2 == otmp)
  90.                          break;
  91.                  if (!otmp2 || !otmp2->bypass)
  92.                      continue;
  93.                  /* found next selected invent item */
  94.                  cnt = pick_list[i].count;
  95.                  if (cnt < otmp->quan) {
  96.                      if (welded(otmp)) {
  97.                          ; /* don't split */
  98.                      } else if (otmp->otyp == LOADSTONE && otmp->cursed) {
  99.                          /* same kludge as getobj(), for canletgo()'s use */
  100.                          otmp->corpsenm = (int) cnt; /* don't split */
  101.                      } else {
  102.                          otmp = splitobj(otmp, cnt);
  103.                      }
  104.                  }
  105.                  n_dropped += drop(otmp);
  106.              }
  107.              bypass_objlist(invent, FALSE); /* reset invent to normal */
  108.              free((genericptr_t) pick_list);
  109.          }
  110.      }
  111.  
  112.  drop_done:
  113.      return n_dropped;
  114.  }
  115.  
  116.  /* on a ladder, used in goto_level */
  117.  static NEARDATA boolean at_ladder = FALSE;
  118.  

dodown

  1.  /* the '>' command */
  2.  int
  3.  dodown()
  4.  {
  5.      struct trap *trap = 0;
  6.      boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair)
  7.                             || (u.ux == sstairs.sx && u.uy == sstairs.sy
  8.                                 && !sstairs.up)),
  9.              ladder_down = (u.ux == xdnladder && u.uy == ydnladder);
  10.  
  11.      if (u_rooted())
  12.          return 1;
  13.  
  14.      if (stucksteed(TRUE)) {
  15.          return 0;
  16.      }
  17.      /* Levitation might be blocked, but player can still use '>' to
  18.         turn off controlled levitation */
  19.      if (HLevitation || ELevitation) {
  20.          if ((HLevitation & I_SPECIAL) || (ELevitation & W_ARTI)) {
  21.              /* end controlled levitation */
  22.              if (ELevitation & W_ARTI) {
  23.                  struct obj *obj;
  24.  
  25.                  for (obj = invent; obj; obj = obj->nobj) {
  26.                      if (obj->oartifact
  27.                          && artifact_has_invprop(obj, LEVITATION)) {
  28.                          if (obj->age < monstermoves)
  29.                              obj->age = monstermoves;
  30.                          obj->age += rnz(100);
  31.                      }
  32.                  }
  33.              }
  34.              if (float_down(I_SPECIAL | TIMEOUT, W_ARTI)) {
  35.                  return 1; /* came down, so moved */
  36.              } else if (!HLevitation && !ELevitation) {
  37.                  Your("latent levitation ceases.");
  38.                  return 1; /* did something, effectively moved */
  39.              }
  40.          }
  41.          if (BLevitation) {
  42.              ; /* weren't actually floating after all */
  43.          } else if (Blind) {
  44.              /* Avoid alerting player to an unknown stair or ladder.
  45.               * Changes the message for a covered, known staircase
  46.               * too; staircase knowledge is not stored anywhere.
  47.               */
  48.              if (stairs_down)
  49.                  stairs_down =
  50.                      (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair);
  51.              else if (ladder_down)
  52.                  ladder_down =
  53.                      (glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder);
  54.          }
  55.          if (Is_airlevel(&u.uz))
  56.              You("are floating in the %s.", surface(u.ux, u.uy));
  57.          else if (Is_waterlevel(&u.uz))
  58.              You("are floating in %s.",
  59.                  is_pool(u.ux, u.uy) ? "the water" : "a bubble of air");
  60.          else
  61.              floating_above(stairs_down ? "stairs" : ladder_down
  62.                                                      ? "ladder"
  63.                                                      : surface(u.ux, u.uy));
  64.          return 0; /* didn't move */
  65.      }
  66.      if (!stairs_down && !ladder_down) {
  67.          trap = t_at(u.ux, u.uy);
  68.          if (trap && uteetering_at_seen_pit(trap)) {
  69.              dotrap(trap, TOOKPLUNGE);
  70.              return 1;
  71.          } else if (!trap || (trap->ttyp != TRAPDOOR && trap->ttyp != HOLE)
  72.                     || !Can_fall_thru(&u.uz) || !trap->tseen) {
  73.              if (flags.autodig && !context.nopick && uwep && is_pick(uwep)) {
  74.                  return use_pick_axe2(uwep);
  75.              } else {
  76.                  You_cant("go down here.");
  77.                  return 0;
  78.              }
  79.          }
  80.      }
  81.      if (u.ustuck) {
  82.          You("are %s, and cannot go down.",
  83.              !u.uswallow ? "being held" : is_animal(u.ustuck->data)
  84.                                               ? "swallowed"
  85.                                               : "engulfed");
  86.          return 1;
  87.      }
  88.      if (on_level(&valley_level, &u.uz) && !u.uevent.gehennom_entered) {
  89.          You("are standing at the gate to Gehennom.");
  90.          pline("Unspeakable cruelty and harm lurk down there.");
  91.          if (yn("Are you sure you want to enter?") != 'y')
  92.              return 0;
  93.          else
  94.              pline("So be it.");
  95.          u.uevent.gehennom_entered = 1; /* don't ask again */
  96.      }
  97.  
  98.      if (!next_to_u()) {
  99.          You("are held back by your pet!");
  100.          return 0;
  101.      }
  102.  
  103.      if (trap)
  104.          You("%s %s.", Flying ? "fly" : locomotion(youmonst.data, "jump"),
  105.              trap->ttyp == HOLE ? "down the hole" : "through the trap door");
  106.  
  107.      if (trap && Is_stronghold(&u.uz)) {
  108.          goto_hell(FALSE, TRUE);
  109.      } else {
  110.          at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
  111.          next_level(!trap);
  112.          at_ladder = FALSE;
  113.      }
  114.      return 1;
  115.  }
  116.  

doup

  1.  /* the '<' command */
  2.  int
  3.  doup()
  4.  {
  5.      if (u_rooted())
  6.          return 1;
  7.  
  8.      /* "up" to get out of a pit... */
  9.      if (u.utrap && u.utraptype == TT_PIT) {
  10.          climb_pit();
  11.          return 1;
  12.      }
  13.  
  14.      if ((u.ux != xupstair || u.uy != yupstair)
  15.          && (!xupladder || u.ux != xupladder || u.uy != yupladder)
  16.          && (!sstairs.sx || u.ux != sstairs.sx || u.uy != sstairs.sy
  17.              || !sstairs.up)) {
  18.          You_cant("go up here.");
  19.          return 0;
  20.      }
  21.      if (stucksteed(TRUE)) {
  22.          return 0;
  23.      }
  24.      if (u.ustuck) {
  25.          You("are %s, and cannot go up.",
  26.              !u.uswallow ? "being held" : is_animal(u.ustuck->data)
  27.                                               ? "swallowed"
  28.                                               : "engulfed");
  29.          return 1;
  30.      }
  31.      if (near_capacity() > SLT_ENCUMBER) {
  32.          /* No levitation check; inv_weight() already allows for it */
  33.          Your("load is too heavy to climb the %s.",
  34.               levl[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder");
  35.          return 1;
  36.      }
  37.      if (ledger_no(&u.uz) == 1) {
  38.          if (yn("Beware, there will be no return! Still climb?") != 'y')
  39.              return 0;
  40.      }
  41.      if (!next_to_u()) {
  42.          You("are held back by your pet!");
  43.          return 0;
  44.      }
  45.      at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
  46.      prev_level(TRUE);
  47.      at_ladder = FALSE;
  48.      return 1;
  49.  }
  50.  
  51.  d_level save_dlevel = { 0, 0 };
  52.  

currentlevel_rewrite

  1.  /* check that we can write out the current level */
  2.  STATIC_OVL int
  3.  currentlevel_rewrite()
  4.  {
  5.      register int fd;
  6.      char whynot[BUFSZ];
  7.  
  8.      /* since level change might be a bit slow, flush any buffered screen
  9.       *  output (like "you fall through a trap door") */
  10.      mark_synch();
  11.  
  12.      fd = create_levelfile(ledger_no(&u.uz), whynot);
  13.      if (fd < 0) {
  14.          /*
  15.           * This is not quite impossible: e.g., we may have
  16.           * exceeded our quota. If that is the case then we
  17.           * cannot leave this level, and cannot save either.
  18.           * Another possibility is that the directory was not
  19.           * writable.
  20.           */
  21.          pline1(whynot);
  22.          return -1;
  23.      }
  24.  
  25.  #ifdef MFLOPPY
  26.      if (!savelev(fd, ledger_no(&u.uz), COUNT_SAVE)) {
  27.          (void) nhclose(fd);
  28.          delete_levelfile(ledger_no(&u.uz));
  29.          pline("NetHack is out of disk space for making levels!");
  30.          You("can save, quit, or continue playing.");
  31.          return -1;
  32.      }
  33.  #endif
  34.      return fd;
  35.  }
  36.  

save_currentstate

  1.  #ifdef INSURANCE
  2.  void
  3.  save_currentstate()
  4.  {
  5.      int fd;
  6.  
  7.      if (flags.ins_chkpt) {
  8.          /* write out just-attained level, with pets and everything */
  9.          fd = currentlevel_rewrite();
  10.          if (fd < 0)
  11.              return;
  12.          bufon(fd);
  13.          savelev(fd, ledger_no(&u.uz), WRITE_SAVE);
  14.          bclose(fd);
  15.      }
  16.  
  17.      /* write out non-level state */
  18.      savestateinlock();
  19.  }
  20.  #endif
  21.  
  22.  /*
  23.  static boolean
  24.  badspot(x, y)
  25.  register xchar x, y;
  26.  {
  27.      return (boolean) ((levl[x][y].typ != ROOM
  28.                         && levl[x][y].typ != AIR
  29.                         && levl[x][y].typ != CORR)
  30.                        || MON_AT(x, y));
  31.  }
  32.  */
  33.  

goto_level

  1.  void
  2.  goto_level(newlevel, at_stairs, falling, portal)
  3.  d_level *newlevel;
  4.  boolean at_stairs, falling, portal;
  5.  {
  6.      int fd, l_idx;
  7.      xchar new_ledger;
  8.      boolean cant_go_back, great_effort,
  9.              up = (depth(newlevel) < depth(&u.uz)),
  10.              newdungeon = (u.uz.dnum != newlevel->dnum),
  11.              was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz),
  12.              familiar = FALSE,
  13.              new = FALSE; /* made a new level? */
  14.      struct monst *mtmp;
  15.      char whynot[BUFSZ];
  16.      char *annotation;
  17.  
  18.      if (dunlev(newlevel) > dunlevs_in_dungeon(newlevel))
  19.          newlevel->dlevel = dunlevs_in_dungeon(newlevel);
  20.      if (newdungeon && In_endgame(newlevel)) { /* 1st Endgame Level !!! */
  21.          if (!u.uhave.amulet)
  22.              return;  /* must have the Amulet */
  23.          if (!wizard) /* wizard ^V can bypass Earth level */
  24.              assign_level(newlevel, &earth_level); /* (redundant) */
  25.      }
  26.      new_ledger = ledger_no(newlevel);
  27.      if (new_ledger <= 0)
  28.          done(ESCAPED); /* in fact < 0 is impossible */
  29.  
  30.      /* If you have the amulet and are trying to get out of Gehennom,
  31.       * going up a set of stairs sometimes does some very strange things!
  32.       * Biased against law and towards chaos.  (The chance to be sent
  33.       * down multiple levels when attempting to go up are significantly
  34.       * less than the corresponding comment in older versions indicated
  35.       * due to overlooking the effect of the call to assign_rnd_lvl().)
  36.       *
  37.       * Odds for making it to the next level up, or of being sent down:
  38.       *  "up"    L      N      C
  39.       *   +1   75.0   75.0   75.0
  40.       *    0    6.25   8.33  12.5
  41.       *   -1   11.46  12.50  12.5
  42.       *   -2    5.21   4.17   0.0
  43.       *   -3    2.08   0.0    0.0
  44.       */
  45.      if (Inhell && up && u.uhave.amulet && !newdungeon && !portal
  46.          && (dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz) - 3)) {
  47.          if (!rn2(4)) {
  48.              int odds = 3 + (int) u.ualign.type,   /* 2..4 */
  49.                  diff = odds <= 1 ? 0 : rn2(odds); /* paranoia */
  50.  
  51.              if (diff != 0) {
  52.                  assign_rnd_level(newlevel, &u.uz, diff);
  53.                  /* if inside the tower, stay inside */
  54.                  if (was_in_W_tower && !On_W_tower_level(newlevel))
  55.                      diff = 0;
  56.              }
  57.              if (diff == 0)
  58.                  assign_level(newlevel, &u.uz);
  59.  
  60.              new_ledger = ledger_no(newlevel);
  61.  
  62.              pline("A mysterious force momentarily surrounds you...");
  63.              if (on_level(newlevel, &u.uz)) {
  64.                  (void) safe_teleds(FALSE);
  65.                  (void) next_to_u();
  66.                  return;
  67.              } else
  68.                  at_stairs = at_ladder = FALSE;
  69.          }
  70.      }
  71.  
  72.      /* Prevent the player from going past the first quest level unless
  73.       * (s)he has been given the go-ahead by the leader.
  74.       */
  75.      if (on_level(&u.uz, &qstart_level) && !newdungeon && !ok_to_quest()) {
  76.          pline("A mysterious force prevents you from descending.");
  77.          return;
  78.      }
  79.  
  80.      if (on_level(newlevel, &u.uz))
  81.          return; /* this can happen */
  82.  
  83.      /* tethered movement makes level change while trapped feasible */
  84.      if (u.utrap && u.utraptype == TT_BURIEDBALL)
  85.          buried_ball_to_punishment(); /* (before we save/leave old level) */
  86.  
  87.      fd = currentlevel_rewrite();
  88.      if (fd < 0)
  89.          return;
  90.  
  91.      if (falling) /* assuming this is only trap door or hole */
  92.          impact_drop((struct obj *) 0, u.ux, u.uy, newlevel->dlevel);
  93.  
  94.      check_special_room(TRUE); /* probably was a trap door */
  95.      if (Punished)
  96.          unplacebc();
  97.      u.utrap = 0; /* needed in level_tele */
  98.      fill_pit(u.ux, u.uy);
  99.      u.ustuck = 0; /* idem */
  100.      u.uinwater = 0;
  101.      u.uundetected = 0; /* not hidden, even if means are available */
  102.      keepdogs(FALSE);
  103.      if (u.uswallow) /* idem */
  104.          u.uswldtim = u.uswallow = 0;
  105.      recalc_mapseen(); /* recalculate map overview before we leave the level */
  106.      /*
  107.       *  We no longer see anything on the level.  Make sure that this
  108.       *  follows u.uswallow set to null since uswallow overrides all
  109.       *  normal vision.
  110.       */
  111.      vision_recalc(2);
  112.  
  113.      /*
  114.       * Save the level we're leaving.  If we're entering the endgame,
  115.       * we can get rid of all existing levels because they cannot be
  116.       * reached any more.  We still need to use savelev()'s cleanup
  117.       * for the level being left, to recover dynamic memory in use and
  118.       * to avoid dangling timers and light sources.
  119.       */
  120.      cant_go_back = (newdungeon && In_endgame(newlevel));
  121.      if (!cant_go_back) {
  122.          update_mlstmv(); /* current monsters are becoming inactive */
  123.          bufon(fd);       /* use buffered output */
  124.      }
  125.      savelev(fd, ledger_no(&u.uz),
  126.              cant_go_back ? FREE_SAVE : (WRITE_SAVE | FREE_SAVE));
  127.      bclose(fd);
  128.      if (cant_go_back) {
  129.          /* discard unreachable levels; keep #0 */
  130.          for (l_idx = maxledgerno(); l_idx > 0; --l_idx)
  131.              delete_levelfile(l_idx);
  132.          /* mark #overview data for all dungeon branches as uninteresting */
  133.          for (l_idx = 0; l_idx < n_dgns; ++l_idx)
  134.              remdun_mapseen(l_idx);
  135.      }
  136.  
  137.      if (Is_rogue_level(newlevel) || Is_rogue_level(&u.uz))
  138.          assign_graphics(Is_rogue_level(newlevel) ? ROGUESET : PRIMARY);
  139.  #ifdef USE_TILES
  140.      substitute_tiles(newlevel);
  141.  #endif
  142.      check_gold_symbol();
  143.      /* record this level transition as a potential seen branch unless using
  144.       * some non-standard means of transportation (level teleport).
  145.       */
  146.      if ((at_stairs || falling || portal) && (u.uz.dnum != newlevel->dnum))
  147.          recbranch_mapseen(&u.uz, newlevel);
  148.      assign_level(&u.uz0, &u.uz);
  149.      assign_level(&u.uz, newlevel);
  150.      assign_level(&u.utolev, newlevel);
  151.      u.utotype = 0;
  152.      if (!builds_up(&u.uz)) { /* usual case */
  153.          if (dunlev(&u.uz) > dunlev_reached(&u.uz))
  154.              dunlev_reached(&u.uz) = dunlev(&u.uz);
  155.      } else {
  156.          if (dunlev_reached(&u.uz) == 0
  157.              || dunlev(&u.uz) < dunlev_reached(&u.uz))
  158.              dunlev_reached(&u.uz) = dunlev(&u.uz);
  159.      }
  160.      reset_rndmonst(NON_PM); /* u.uz change affects monster generation */
  161.  
  162.      /* set default level change destination areas */
  163.      /* the special level code may override these */
  164.      (void) memset((genericptr_t) &updest, 0, sizeof updest);
  165.      (void) memset((genericptr_t) &dndest, 0, sizeof dndest);
  166.  
  167.      if (!(level_info[new_ledger].flags & LFILE_EXISTS)) {
  168.          /* entering this level for first time; make it now */
  169.          if (level_info[new_ledger].flags & (FORGOTTEN | VISITED)) {
  170.              impossible("goto_level: returning to discarded level?");
  171.              level_info[new_ledger].flags &= ~(FORGOTTEN | VISITED);
  172.          }
  173.          mklev();
  174.          new = TRUE; /* made the level */
  175.      } else {
  176.          /* returning to previously visited level; reload it */
  177.          fd = open_levelfile(new_ledger, whynot);
  178.          if (tricked_fileremoved(fd, whynot)) {
  179.              /* we'll reach here if running in wizard mode */
  180.              error("Cannot continue this game.");
  181.          }
  182.          minit(); /* ZEROCOMP */
  183.          getlev(fd, hackpid, new_ledger, FALSE);
  184.          (void) nhclose(fd);
  185.          oinit(); /* reassign level dependent obj probabilities */
  186.      }
  187.      reglyph_darkroom();
  188.      /* do this prior to level-change pline messages */
  189.      vision_reset();         /* clear old level's line-of-sight */
  190.      vision_full_recalc = 0; /* don't let that reenable vision yet */
  191.      flush_screen(-1);       /* ensure all map flushes are postponed */
  192.  
  193.      if (portal && !In_endgame(&u.uz)) {
  194.          /* find the portal on the new level */
  195.          register struct trap *ttrap;
  196.  
  197.          for (ttrap = ftrap; ttrap; ttrap = ttrap->ntrap)
  198.              if (ttrap->ttyp == MAGIC_PORTAL)
  199.                  break;
  200.  
  201.          if (!ttrap)
  202.              panic("goto_level: no corresponding portal!");
  203.          seetrap(ttrap);
  204.          u_on_newpos(ttrap->tx, ttrap->ty);
  205.      } else if (at_stairs && !In_endgame(&u.uz)) {
  206.          if (up) {
  207.              if (at_ladder)
  208.                  u_on_newpos(xdnladder, ydnladder);
  209.              else if (newdungeon)
  210.                  u_on_sstairs(1);
  211.              else
  212.                  u_on_dnstairs();
  213.              /* you climb up the {stairs|ladder};
  214.                 fly up the stairs; fly up along the ladder */
  215.              great_effort = (Punished && !Levitation);
  216.              if (flags.verbose || great_effort)
  217.                  pline("%s %s up%s the %s.",
  218.                        great_effort ? "With great effort, you" : "You",
  219.                        Levitation ? "float" : Flying ? "fly" : "climb",
  220.                        (Flying && at_ladder) ? " along" : "",
  221.                        at_ladder ? "ladder" : "stairs");
  222.          } else { /* down */
  223.              if (at_ladder)
  224.                  u_on_newpos(xupladder, yupladder);
  225.              else if (newdungeon)
  226.                  u_on_sstairs(0);
  227.              else
  228.                  u_on_upstairs();
  229.              if (!u.dz) {
  230.                  ; /* stayed on same level? (no transit effects) */
  231.              } else if (Flying) {
  232.                  if (flags.verbose)
  233.                      You("fly down %s.",
  234.                          at_ladder ? "along the ladder" : "the stairs");
  235.              } else if (near_capacity() > UNENCUMBERED
  236.                         || Punished || Fumbling) {
  237.                  You("fall down the %s.", at_ladder ? "ladder" : "stairs");
  238.                  if (Punished) {
  239.                      drag_down();
  240.                      ballrelease(FALSE);
  241.                  }
  242.                  /* falling off steed has its own losehp() call */
  243.                  if (u.usteed)
  244.                      dismount_steed(DISMOUNT_FELL);
  245.                  else
  246.                      losehp(Maybe_Half_Phys(rnd(3)),
  247.                             at_ladder ? "falling off a ladder"
  248.                                       : "tumbling down a flight of stairs",
  249.                             KILLED_BY);
  250.                  selftouch("Falling, you");
  251.              } else { /* ordinary descent */
  252.                  if (flags.verbose)
  253.                      You("%s.", at_ladder ? "climb down the ladder"
  254.                                           : "descend the stairs");
  255.              }
  256.          }
  257.      } else { /* trap door or level_tele or In_endgame */
  258.          u_on_rndspot((up ? 1 : 0) | (was_in_W_tower ? 2 : 0));
  259.          if (falling) {
  260.              if (Punished)
  261.                  ballfall();
  262.              selftouch("Falling, you");
  263.          }
  264.      }
  265.  
  266.      if (Punished)
  267.          placebc();
  268.      obj_delivery(FALSE);
  269.      losedogs();
  270.      kill_genocided_monsters(); /* for those wiped out while in limbo */
  271.      /*
  272.       * Expire all timers that have gone off while away.  Must be
  273.       * after migrating monsters and objects are delivered
  274.       * (losedogs and obj_delivery).
  275.       */
  276.      run_timers();
  277.  
  278.      initrack();
  279.  
  280.      if ((mtmp = m_at(u.ux, u.uy)) != 0 && mtmp != u.usteed) {
  281.          /* There's a monster at your target destination; it might be one
  282.             which accompanied you--see mon_arrive(dogmove.c)--or perhaps
  283.             it was already here.  Randomly move you to an adjacent spot
  284.             or else the monster to any nearby location.  Prior to 3.3.0
  285.             the latter was done unconditionally. */
  286.          coord cc;
  287.  
  288.          if (!rn2(2) && enexto(&cc, u.ux, u.uy, youmonst.data)
  289.              && distu(cc.x, cc.y) <= 2)
  290.              u_on_newpos(cc.x, cc.y); /*[maybe give message here?]*/
  291.          else
  292.              mnexto(mtmp);
  293.  
  294.          if ((mtmp = m_at(u.ux, u.uy)) != 0) {
  295.              /* there was an unconditional impossible("mnearto failed")
  296.                 here, but it's not impossible and we're prepared to cope
  297.                 with the situation, so only say something when debugging */
  298.              if (wizard)
  299.                  pline("(monster in hero's way)");
  300.              if (!rloc(mtmp, TRUE))
  301.                  /* no room to move it; send it away, to return later */
  302.                  migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_RANDOM,
  303.                                   (coord *) 0);
  304.          }
  305.      }
  306.  
  307.      /* initial movement of bubbles just before vision_recalc */
  308.      if (Is_waterlevel(&u.uz) || Is_airlevel(&u.uz))
  309.          movebubbles();
  310.      else if (Is_firelevel(&u.uz))
  311.          fumaroles();
  312.  
  313.      if (level_info[new_ledger].flags & FORGOTTEN) {
  314.          forget_map(ALL_MAP); /* forget the map */
  315.          forget_traps();      /* forget all traps too */
  316.          familiar = TRUE;
  317.          level_info[new_ledger].flags &= ~FORGOTTEN;
  318.      }
  319.  
  320.      /* Reset the screen. */
  321.      vision_reset(); /* reset the blockages */
  322.      docrt();        /* does a full vision recalc */
  323.      flush_screen(-1);
  324.  
  325.      /*
  326.       *  Move all plines beyond the screen reset.
  327.       */
  328.  
  329.      /* special levels can have a custom arrival message */
  330.      deliver_splev_message();
  331.  
  332.      /* give room entrance message, if any */
  333.      check_special_room(FALSE);
  334.  
  335.      /* deliver objects traveling with player */
  336.      obj_delivery(TRUE);
  337.  
  338.      /* Check whether we just entered Gehennom. */
  339.      if (!In_hell(&u.uz0) && Inhell) {
  340.          if (Is_valley(&u.uz)) {
  341.              You("arrive at the Valley of the Dead...");
  342.              pline_The("odor of burnt flesh and decay pervades the air.");
  343.  #ifdef MICRO
  344.              display_nhwindow(WIN_MESSAGE, FALSE);
  345.  #endif
  346.              You_hear("groans and moans everywhere.");
  347.          } else
  348.              pline("It is hot here.  You smell smoke...");
  349.          u.uachieve.enter_gehennom = 1;
  350.      }
  351.      /* in case we've managed to bypass the Valley's stairway down */
  352.      if (Inhell && !Is_valley(&u.uz))
  353.          u.uevent.gehennom_entered = 1;
  354.  
  355.      if (familiar) {
  356.          static const char *const fam_msgs[4] = {
  357.              "You have a sense of deja vu.",
  358.              "You feel like you've been here before.",
  359.              "This place %s familiar...", 0 /* no message */
  360.          };
  361.          static const char *const halu_fam_msgs[4] = {
  362.              "Whoa!  Everything %s different.",
  363.              "You are surrounded by twisty little passages, all alike.",
  364.              "Gee, this %s like uncle Conan's place...", 0 /* no message */
  365.          };
  366.          const char *mesg;
  367.          char buf[BUFSZ];
  368.          int which = rn2(4);
  369.  
  370.          if (Hallucination)
  371.              mesg = halu_fam_msgs[which];
  372.          else
  373.              mesg = fam_msgs[which];
  374.          if (mesg && index(mesg, '%')) {
  375.              Sprintf(buf, mesg, !Blind ? "looks" : "seems");
  376.              mesg = buf;
  377.          }
  378.          if (mesg)
  379.              pline1(mesg);
  380.      }
  381.  
  382.      /* special location arrival messages/events */
  383.      if (In_endgame(&u.uz)) {
  384.          if (new &&on_level(&u.uz, &astral_level))
  385.              final_level(); /* guardian angel,&c */
  386.          else if (newdungeon && u.uhave.amulet)
  387.              resurrect(); /* force confrontation with Wizard */
  388.      } else if (In_quest(&u.uz)) {
  389.          onquest(); /* might be reaching locate|goal level */
  390.      } else if (In_V_tower(&u.uz)) {
  391.          if (newdungeon && In_hell(&u.uz0))
  392.              pline_The("heat and smoke are gone.");
  393.      } else if (Is_knox(&u.uz)) {
  394.          /* alarm stops working once Croesus has died */
  395.          if (new || !mvitals[PM_CROESUS].died) {
  396.              You("have penetrated a high security area!");
  397.              pline("An alarm sounds!");
  398.              for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  399.                  if (DEADMONSTER(mtmp))
  400.                      continue;
  401.                  mtmp->msleeping = 0;
  402.              }
  403.          }
  404.      } else {
  405.          if (new && Is_rogue_level(&u.uz))
  406.              You("enter what seems to be an older, more primitive world.");
  407.          /* main dungeon message from your quest leader */
  408.          if (!In_quest(&u.uz0) && at_dgn_entrance("The Quest")
  409.              && !(u.uevent.qcompleted || u.uevent.qexpelled
  410.                   || quest_status.leader_is_dead)) {
  411.              if (!u.uevent.qcalled) {
  412.                  u.uevent.qcalled = 1;
  413.                  com_pager(2); /* main "leader needs help" message */
  414.              } else {          /* reminder message */
  415.                  com_pager(Role_if(PM_ROGUE) ? 4 : 3);
  416.              }
  417.          }
  418.      }
  419.  
  420.      assign_level(&u.uz0, &u.uz); /* reset u.uz0 */
  421.  #ifdef INSURANCE
  422.      save_currentstate();
  423.  #endif
  424.  
  425.      if ((annotation = get_annotation(&u.uz)) != 0)
  426.          You("remember this level as %s.", annotation);
  427.  
  428.      /* assume this will always return TRUE when changing level */
  429.      (void) in_out_region(u.ux, u.uy);
  430.      (void) pickup(1);
  431.  
  432.      /* discard context which applied to previous level */
  433.      maybe_reset_pick(); /* for door or for box not accompanying hero */
  434.      reset_trapset(); /* even if to-be-armed trap obj is accompanying hero */
  435.      iflags.travelcc.x = iflags.travelcc.y = -1; /* travel destination cache */
  436.      context.polearm.hitmon = (struct monst *) 0; /* polearm target */
  437.      /* digging context is level-aware and can actually be resumed if
  438.         hero returns to the previous level without any intervening dig */
  439.  }
  440.  

final_level

  1.  STATIC_OVL void
  2.  final_level()
  3.  {
  4.      struct monst *mtmp;
  5.  
  6.      /* reset monster hostility relative to player */
  7.      for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  8.          if (DEADMONSTER(mtmp))
  9.              continue;
  10.          reset_hostility(mtmp);
  11.      }
  12.  
  13.      /* create some player-monsters */
  14.      create_mplayers(rn1(4, 3), TRUE);
  15.  
  16.      /* create a guardian angel next to player, if worthy */
  17.      gain_guardian_angel();
  18.  }
  19.  
  20.  static char *dfr_pre_msg = 0,  /* pline() before level change */
  21.              *dfr_post_msg = 0; /* pline() after level change */
  22.  

schedule_goto

  1.  /* change levels at the end of this turn, after monsters finish moving */
  2.  void
  3.  schedule_goto(tolev, at_stairs, falling, portal_flag, pre_msg, post_msg)
  4.  d_level *tolev;
  5.  boolean at_stairs, falling;
  6.  int portal_flag;
  7.  const char *pre_msg, *post_msg;
  8.  {
  9.      int typmask = 0100; /* non-zero triggers `deferred_goto' */
  10.  
  11.      /* destination flags (`goto_level' args) */
  12.      if (at_stairs)
  13.          typmask |= 1;
  14.      if (falling)
  15.          typmask |= 2;
  16.      if (portal_flag)
  17.          typmask |= 4;
  18.      if (portal_flag < 0)
  19.          typmask |= 0200; /* flag for portal removal */
  20.      u.utotype = typmask;
  21.      /* destination level */
  22.      assign_level(&u.utolev, tolev);
  23.  
  24.      if (pre_msg)
  25.          dfr_pre_msg = dupstr(pre_msg);
  26.      if (post_msg)
  27.          dfr_post_msg = dupstr(post_msg);
  28.  }
  29.  

deferred_goto

  1.  /* handle something like portal ejection */
  2.  void
  3.  deferred_goto()
  4.  {
  5.      if (!on_level(&u.uz, &u.utolev)) {
  6.          d_level dest;
  7.          int typmask = u.utotype; /* save it; goto_level zeroes u.utotype */
  8.  
  9.          assign_level(&dest, &u.utolev);
  10.          if (dfr_pre_msg)
  11.              pline1(dfr_pre_msg);
  12.          goto_level(&dest, !!(typmask & 1), !!(typmask & 2), !!(typmask & 4));
  13.          if (typmask & 0200) { /* remove portal */
  14.              struct trap *t = t_at(u.ux, u.uy);
  15.  
  16.              if (t) {
  17.                  deltrap(t);
  18.                  newsym(u.ux, u.uy);
  19.              }
  20.          }
  21.          if (dfr_post_msg)
  22.              pline1(dfr_post_msg);
  23.      }
  24.      u.utotype = 0; /* our caller keys off of this */
  25.      if (dfr_pre_msg)
  26.          free((genericptr_t) dfr_pre_msg), dfr_pre_msg = 0;
  27.      if (dfr_post_msg)
  28.          free((genericptr_t) dfr_post_msg), dfr_post_msg = 0;
  29.  }
  30.  

revive_corpse

  1.  /*
  2.   * Return TRUE if we created a monster for the corpse.  If successful, the
  3.   * corpse is gone.
  4.   */
  5.  boolean
  6.  revive_corpse(corpse)
  7.  struct obj *corpse;
  8.  {
  9.      struct monst *mtmp, *mcarry;
  10.      boolean is_uwep, chewed;
  11.      xchar where;
  12.      char cname[BUFSZ];
  13.      struct obj *container = (struct obj *) 0;
  14.      int container_where = 0;
  15.  
  16.      where = corpse->where;
  17.      is_uwep = (corpse == uwep);
  18.      chewed = (corpse->oeaten != 0);
  19.      Strcpy(cname,
  20.             corpse_xname(corpse, chewed ? "bite-covered" : (const char *) 0,
  21.                          CXN_SINGULAR));
  22.      mcarry = (where == OBJ_MINVENT) ? corpse->ocarry : 0;
  23.  
  24.      if (where == OBJ_CONTAINED) {
  25.          struct monst *mtmp2;
  26.  
  27.          container = corpse->ocontainer;
  28.          mtmp2 =
  29.              get_container_location(container, &container_where, (int *) 0);
  30.          /* container_where is the outermost container's location even if
  31.           * nested */
  32.          if (container_where == OBJ_MINVENT && mtmp2)
  33.              mcarry = mtmp2;
  34.      }
  35.      mtmp = revive(corpse, FALSE); /* corpse is gone if successful */
  36.  
  37.      if (mtmp) {
  38.          switch (where) {
  39.          case OBJ_INVENT:
  40.              if (is_uwep)
  41.                  pline_The("%s writhes out of your grasp!", cname);
  42.              else
  43.                  You_feel("squirming in your backpack!");
  44.              break;
  45.  
  46.          case OBJ_FLOOR:
  47.              if (cansee(mtmp->mx, mtmp->my))
  48.                  pline("%s rises from the dead!",
  49.                        chewed ? Adjmonnam(mtmp, "bite-covered")
  50.                               : Monnam(mtmp));
  51.              break;
  52.  
  53.          case OBJ_MINVENT: /* probably a nymph's */
  54.              if (cansee(mtmp->mx, mtmp->my)) {
  55.                  if (canseemon(mcarry))
  56.                      pline("Startled, %s drops %s as it revives!",
  57.                            mon_nam(mcarry), an(cname));
  58.                  else
  59.                      pline("%s suddenly appears!",
  60.                            chewed ? Adjmonnam(mtmp, "bite-covered")
  61.                                   : Monnam(mtmp));
  62.              }
  63.              break;
  64.          case OBJ_CONTAINED: {
  65.              char sackname[BUFSZ];
  66.  
  67.              if (container_where == OBJ_MINVENT && cansee(mtmp->mx, mtmp->my)
  68.                  && mcarry && canseemon(mcarry) && container) {
  69.                  pline("%s writhes out of %s!", Amonnam(mtmp),
  70.                        yname(container));
  71.              } else if (container_where == OBJ_INVENT && container) {
  72.                  Strcpy(sackname, an(xname(container)));
  73.                  pline("%s %s out of %s in your pack!",
  74.                        Blind ? Something : Amonnam(mtmp),
  75.                        locomotion(mtmp->data, "writhes"), sackname);
  76.              } else if (container_where == OBJ_FLOOR && container
  77.                         && cansee(mtmp->mx, mtmp->my)) {
  78.                  Strcpy(sackname, an(xname(container)));
  79.                  pline("%s escapes from %s!", Amonnam(mtmp), sackname);
  80.              }
  81.              break;
  82.          }
  83.          default:
  84.              /* we should be able to handle the other cases... */
  85.              impossible("revive_corpse: lost corpse @ %d", where);
  86.              break;
  87.          }
  88.          return TRUE;
  89.      }
  90.      return FALSE;
  91.  }
  92.  

revive_mon

  1.  /* Revive the corpse via a timeout. */
  2.  /*ARGSUSED*/
  3.  void
  4.  revive_mon(arg, timeout)
  5.  anything *arg;
  6.  long timeout UNUSED;
  7.  {
  8.      struct obj *body = arg->a_obj;
  9.      struct permonst *mptr = &mons[body->corpsenm];
  10.      struct monst *mtmp;
  11.      xchar x, y;
  12.  
  13.      /* corpse will revive somewhere else if there is a monster in the way;
  14.         Riders get a chance to try to bump the obstacle out of their way */
  15.      if ((mptr->mflags3 & M3_DISPLACES) != 0 && body->where == OBJ_FLOOR
  16.          && get_obj_location(body, &x, &y, 0) && (mtmp = m_at(x, y)) != 0) {
  17.          boolean notice_it = canseemon(mtmp); /* before rloc() */
  18.          char *monname = Monnam(mtmp);
  19.  
  20.          if (rloc(mtmp, TRUE)) {
  21.              if (notice_it && !canseemon(mtmp))
  22.                  pline("%s vanishes.", monname);
  23.              else if (!notice_it && canseemon(mtmp))
  24.                  pline("%s appears.", Monnam(mtmp)); /* not pre-rloc monname */
  25.              else if (notice_it && dist2(mtmp->mx, mtmp->my, x, y) > 2)
  26.                  pline("%s teleports.", monname); /* saw it and still see it */
  27.          }
  28.      }
  29.  
  30.      /* if we succeed, the corpse is gone */
  31.      if (!revive_corpse(body)) {
  32.          long when;
  33.          int action;
  34.  
  35.          if (is_rider(mptr) && rn2(99)) { /* Rider usually tries again */
  36.              action = REVIVE_MON;
  37.              for (when = 3L; when < 67L; when++)
  38.                  if (!rn2(3))
  39.                      break;
  40.          } else { /* rot this corpse away */
  41.              You_feel("%sless hassled.", is_rider(mptr) ? "much " : "");
  42.              action = ROT_CORPSE;
  43.              when = 250L - (monstermoves - body->age);
  44.              if (when < 1L)
  45.                  when = 1L;
  46.          }
  47.          (void) start_timer(when, TIMER_OBJECT, action, arg);
  48.      }
  49.  }
  50.  

donull

  1.  int
  2.  donull()
  3.  {
  4.      return 1; /* Do nothing, but let other things happen */
  5.  }
  6.  

wipeoff

  1.  STATIC_PTR int
  2.  wipeoff(VOID_ARGS)
  3.  {
  4.      if (u.ucreamed < 4)
  5.          u.ucreamed = 0;
  6.      else
  7.          u.ucreamed -= 4;
  8.      if (Blinded < 4)
  9.          Blinded = 0;
  10.      else
  11.          Blinded -= 4;
  12.      if (!Blinded) {
  13.          pline("You've got the glop off.");
  14.          u.ucreamed = 0;
  15.          if (!gulp_blnd_check()) {
  16.              Blinded = 1;
  17.              make_blinded(0L, TRUE);
  18.          }
  19.          return 0;
  20.      } else if (!u.ucreamed) {
  21.          Your("%s feels clean now.", body_part(FACE));
  22.          return 0;
  23.      }
  24.      return 1; /* still busy */
  25.  }
  26.  

dowipe

  1.  int
  2.  dowipe()
  3.  {
  4.      if (u.ucreamed) {
  5.          static NEARDATA char buf[39];
  6.  
  7.          Sprintf(buf, "wiping off your %s", body_part(FACE));
  8.          set_occupation(wipeoff, buf, 0);
  9.          /* Not totally correct; what if they change back after now
  10.           * but before they're finished wiping?
  11.           */
  12.          return 1;
  13.      }
  14.      Your("%s is already clean.", body_part(FACE));
  15.      return 1;
  16.  }
  17.  

set_wounded_legs

  1.  void
  2.  set_wounded_legs(side, timex)
  3.  register long side;
  4.  register int timex;
  5.  {
  6.      /* KMH -- STEED
  7.       * If you are riding, your steed gets the wounded legs instead.
  8.       * You still call this function, but don't lose hp.
  9.       * Caller is also responsible for adjusting messages.
  10.       */
  11.  
  12.      if (!Wounded_legs) {
  13.          ATEMP(A_DEX)--;
  14.          context.botl = 1;
  15.      }
  16.  
  17.      if (!Wounded_legs || (HWounded_legs & TIMEOUT))
  18.          HWounded_legs = timex;
  19.      EWounded_legs = side;
  20.      (void) encumber_msg();
  21.  }
  22.  

heal_legs

  1.  void
  2.  heal_legs()
  3.  {
  4.      if (Wounded_legs) {
  5.          if (ATEMP(A_DEX) < 0) {
  6.              ATEMP(A_DEX)++;
  7.              context.botl = 1;
  8.          }
  9.  
  10.          if (!u.usteed) {
  11.              const char *legs = body_part(LEG);
  12.  
  13.              if ((EWounded_legs & BOTH_SIDES) == BOTH_SIDES)
  14.                  legs = makeplural(legs);
  15.              /* this used to say "somewhat better" but that was
  16.                 misleading since legs are being fully healed */
  17.              Your("%s %s better.", legs, vtense(legs, "feel"));
  18.          }
  19.  
  20.          HWounded_legs = EWounded_legs = 0;
  21.  
  22.          /* Wounded_legs reduces carrying capacity, so we want
  23.             an encumbrance check when they're healed.  However,
  24.             while dismounting, first steed's legs get healed,
  25.             then hero is dropped to floor and a new encumbrance
  26.             check is made [in dismount_steed()].  So don't give
  27.             encumbrance feedback during the dismount stage
  28.             because it could seem to be shown out of order and
  29.             it might be immediately contradicted [able to carry
  30.             more when steed becomes healthy, then possible floor
  31.             feedback, then able to carry less when back on foot]. */
  32.          if (!in_steed_dismounting)
  33.              (void) encumber_msg();
  34.      }
  35.  }
  36.  
  37.  /*do.c*/