Source:NetHack 3.6.0/src/sit.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to sit.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/sit.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	sit.c	$NHDT-Date: 1445906863 2015/10/27 00:47:43 $  $NHDT-Branch: master $:$NHDT-Revision: 1.51 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  #include "artifact.h"
  7.  
  8.  

take_gold

  1.  /* take away the hero's money */
  2.  void
  3.  take_gold()
  4.  {
  5.      struct obj *otmp, *nobj;
  6.      int lost_money = 0;
  7.  
  8.      for (otmp = invent; otmp; otmp = nobj) {
  9.          nobj = otmp->nobj;
  10.          if (otmp->oclass == COIN_CLASS) {
  11.              lost_money = 1;
  12.              remove_worn_item(otmp, FALSE);
  13.              delobj(otmp);
  14.          }
  15.      }
  16.      if (!lost_money) {
  17.          You_feel("a strange sensation.");
  18.      } else {
  19.          You("notice you have no money!");
  20.          context.botl = 1;
  21.      }
  22.  }
  23.  

dosit

  1.  /* #sit command */
  2.  int
  3.  dosit()
  4.  {
  5.      static const char sit_message[] = "sit on the %s.";
  6.      register struct trap *trap = t_at(u.ux, u.uy);
  7.      register int typ = levl[u.ux][u.uy].typ;
  8.  
  9.      if (u.usteed) {
  10.          You("are already sitting on %s.", mon_nam(u.usteed));
  11.          return 0;
  12.      }
  13.      if (u.uundetected && is_hider(youmonst.data) && u.umonnum != PM_TRAPPER)
  14.          u.uundetected = 0; /* no longer on the ceiling */
  15.  
  16.      if (!can_reach_floor(FALSE)) {
  17.          if (u.uswallow)
  18.              There("are no seats in here!");
  19.          else if (Levitation)
  20.              You("tumble in place.");
  21.          else
  22.              You("are sitting on air.");
  23.          return 0;
  24.      } else if (u.ustuck && !sticks(youmonst.data)) {
  25.          /* holding monster is next to hero rather than beneath, but
  26.             hero is in no condition to actually sit at has/her own spot */
  27.          if (humanoid(u.ustuck->data))
  28.              pline("%s won't offer %s lap.", Monnam(u.ustuck), mhis(u.ustuck));
  29.          else
  30.              pline("%s has no lap.", Monnam(u.ustuck));
  31.          return 0;
  32.      } else if (is_pool(u.ux, u.uy) && !Underwater) { /* water walking */
  33.          goto in_water;
  34.      }
  35.  
  36.      if (OBJ_AT(u.ux, u.uy)
  37.          /* ensure we're not standing on the precipice */
  38.          && !uteetering_at_seen_pit(trap)) {
  39.          register struct obj *obj;
  40.  
  41.          obj = level.objects[u.ux][u.uy];
  42.          if (youmonst.data->mlet == S_DRAGON && obj->oclass == COIN_CLASS) {
  43.              You("coil up around your %shoard.",
  44.                  (obj->quan + money_cnt(invent) < u.ulevel * 1000) ? "meager "
  45.                                                                    : "");
  46.          } else {
  47.              You("sit on %s.", the(xname(obj)));
  48.              if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH))
  49.                  pline("It's not very comfortable...");
  50.          }
  51.      } else if (trap != 0 || (u.utrap && (u.utraptype >= TT_LAVA))) {
  52.          if (u.utrap) {
  53.              exercise(A_WIS, FALSE); /* you're getting stuck longer */
  54.              if (u.utraptype == TT_BEARTRAP) {
  55.                  You_cant("sit down with your %s in the bear trap.",
  56.                           body_part(FOOT));
  57.                  u.utrap++;
  58.              } else if (u.utraptype == TT_PIT) {
  59.                  if (trap && trap->ttyp == SPIKED_PIT) {
  60.                      You("sit down on a spike.  Ouch!");
  61.                      losehp(Half_physical_damage ? rn2(2) : 1,
  62.                             "sitting on an iron spike", KILLED_BY);
  63.                      exercise(A_STR, FALSE);
  64.                  } else
  65.                      You("sit down in the pit.");
  66.                  u.utrap += rn2(5);
  67.              } else if (u.utraptype == TT_WEB) {
  68.                  You("sit in the spider web and get entangled further!");
  69.                  u.utrap += rn1(10, 5);
  70.              } else if (u.utraptype == TT_LAVA) {
  71.                  /* Must have fire resistance or they'd be dead already */
  72.                  You("sit in the lava!");
  73.                  if (Slimed)
  74.                      burn_away_slime();
  75.                  u.utrap += rnd(4);
  76.                  losehp(d(2, 10), "sitting in lava",
  77.                         KILLED_BY); /* lava damage */
  78.              } else if (u.utraptype == TT_INFLOOR
  79.                         || u.utraptype == TT_BURIEDBALL) {
  80.                  You_cant("maneuver to sit!");
  81.                  u.utrap++;
  82.              }
  83.          } else {
  84.              You("sit down.");
  85.              dotrap(trap, 0);
  86.          }
  87.      } else if (Underwater || Is_waterlevel(&u.uz)) {
  88.          if (Is_waterlevel(&u.uz))
  89.              There("are no cushions floating nearby.");
  90.          else
  91.              You("sit down on the muddy bottom.");
  92.      } else if (is_pool(u.ux, u.uy)) {
  93.      in_water:
  94.          You("sit in the water.");
  95.          if (!rn2(10) && uarm)
  96.              (void) water_damage(uarm, "armor", TRUE);
  97.          if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS)
  98.              (void) water_damage(uarm, "armor", TRUE);
  99.      } else if (IS_SINK(typ)) {
  100.          You(sit_message, defsyms[S_sink].explanation);
  101.          Your("%s gets wet.", humanoid(youmonst.data) ? "rump" : "underside");
  102.      } else if (IS_ALTAR(typ)) {
  103.          You(sit_message, defsyms[S_altar].explanation);
  104.          altar_wrath(u.ux, u.uy);
  105.      } else if (IS_GRAVE(typ)) {
  106.          You(sit_message, defsyms[S_grave].explanation);
  107.      } else if (typ == STAIRS) {
  108.          You(sit_message, "stairs");
  109.      } else if (typ == LADDER) {
  110.          You(sit_message, "ladder");
  111.      } else if (is_lava(u.ux, u.uy)) {
  112.          /* must be WWalking */
  113.          You(sit_message, "lava");
  114.          burn_away_slime();
  115.          if (likes_lava(youmonst.data)) {
  116.              pline_The("lava feels warm.");
  117.              return 1;
  118.          }
  119.          pline_The("lava burns you!");
  120.          losehp(d((Fire_resistance ? 2 : 10), 10), /* lava damage */
  121.                 "sitting on lava", KILLED_BY);
  122.      } else if (is_ice(u.ux, u.uy)) {
  123.          You(sit_message, defsyms[S_ice].explanation);
  124.          if (!Cold_resistance)
  125.              pline_The("ice feels cold.");
  126.      } else if (typ == DRAWBRIDGE_DOWN) {
  127.          You(sit_message, "drawbridge");
  128.      } else if (IS_THRONE(typ)) {
  129.          You(sit_message, defsyms[S_throne].explanation);
  130.          if (rnd(6) > 4) {
  131.              switch (rnd(13)) {
  132.              case 1:
  133.                  (void) adjattrib(rn2(A_MAX), -rn1(4, 3), FALSE);
  134.                  losehp(rnd(10), "cursed throne", KILLED_BY_AN);
  135.                  break;
  136.              case 2:
  137.                  (void) adjattrib(rn2(A_MAX), 1, FALSE);
  138.                  break;
  139.              case 3:
  140.                  pline("A%s electric shock shoots through your body!",
  141.                        (Shock_resistance) ? "n" : " massive");
  142.                  losehp(Shock_resistance ? rnd(6) : rnd(30), "electric chair",
  143.                         KILLED_BY_AN);
  144.                  exercise(A_CON, FALSE);
  145.                  break;
  146.              case 4:
  147.                  You_feel("much, much better!");
  148.                  if (Upolyd) {
  149.                      if (u.mh >= (u.mhmax - 5))
  150.                          u.mhmax += 4;
  151.                      u.mh = u.mhmax;
  152.                  }
  153.                  if (u.uhp >= (u.uhpmax - 5))
  154.                      u.uhpmax += 4;
  155.                  u.uhp = u.uhpmax;
  156.                  make_blinded(0L, TRUE);
  157.                  make_sick(0L, (char *) 0, FALSE, SICK_ALL);
  158.                  heal_legs();
  159.                  context.botl = 1;
  160.                  break;
  161.              case 5:
  162.                  take_gold();
  163.                  break;
  164.              case 6:
  165.                  if (u.uluck + rn2(5) < 0) {
  166.                      You_feel("your luck is changing.");
  167.                      change_luck(1);
  168.                  } else
  169.                      makewish();
  170.                  break;
  171.              case 7:
  172.                {
  173.                  int cnt = rnd(10);
  174.  
  175.                  /* Magical voice not affected by deafness */
  176.                  pline("A voice echoes:");
  177.                  verbalize("Thy audience hath been summoned, %s!",
  178.                            flags.female ? "Dame" : "Sire");
  179.                  while (cnt--)
  180.                      (void) makemon(courtmon(), u.ux, u.uy, NO_MM_FLAGS);
  181.                  break;
  182.                }
  183.              case 8:
  184.                  /* Magical voice not affected by deafness */
  185.                  pline("A voice echoes:");
  186.                  verbalize("By thine Imperious order, %s...",
  187.                            flags.female ? "Dame" : "Sire");
  188.                  do_genocide(5); /* REALLY|ONTHRONE, see do_genocide() */
  189.                  break;
  190.              case 9:
  191.                  /* Magical voice not affected by deafness */
  192.                  pline("A voice echoes:");
  193.                  verbalize(
  194.                   "A curse upon thee for sitting upon this most holy throne!");
  195.                  if (Luck > 0) {
  196.                      make_blinded(Blinded + rn1(100, 250), TRUE);
  197.                  } else
  198.                      rndcurse();
  199.                  break;
  200.              case 10:
  201.                  if (Luck < 0 || (HSee_invisible & INTRINSIC)) {
  202.                      if (level.flags.nommap) {
  203.                          pline("A terrible drone fills your head!");
  204.                          make_confused((HConfusion & TIMEOUT) + (long) rnd(30),
  205.                                        FALSE);
  206.                      } else {
  207.                          pline("An image forms in your mind.");
  208.                          do_mapping();
  209.                      }
  210.                  } else {
  211.                      Your("vision becomes clear.");
  212.                      HSee_invisible |= FROMOUTSIDE;
  213.                      newsym(u.ux, u.uy);
  214.                  }
  215.                  break;
  216.              case 11:
  217.                  if (Luck < 0) {
  218.                      You_feel("threatened.");
  219.                      aggravate();
  220.                  } else {
  221.                      You_feel("a wrenching sensation.");
  222.                      tele(); /* teleport him */
  223.                  }
  224.                  break;
  225.              case 12:
  226.                  You("are granted an insight!");
  227.                  if (invent) {
  228.                      /* rn2(5) agrees w/seffects() */
  229.                      identify_pack(rn2(5), FALSE);
  230.                  }
  231.                  break;
  232.              case 13:
  233.                  Your("mind turns into a pretzel!");
  234.                  make_confused((HConfusion & TIMEOUT) + (long) rn1(7, 16),
  235.                                FALSE);
  236.                  break;
  237.              default:
  238.                  impossible("throne effect");
  239.                  break;
  240.              }
  241.          } else {
  242.              if (is_prince(youmonst.data))
  243.                  You_feel("very comfortable here.");
  244.              else
  245.                  You_feel("somehow out of place...");
  246.          }
  247.  
  248.          if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) {
  249.              /* may have teleported */
  250.              levl[u.ux][u.uy].typ = ROOM;
  251.              pline_The("throne vanishes in a puff of logic.");
  252.              newsym(u.ux, u.uy);
  253.          }
  254.      } else if (lays_eggs(youmonst.data)) {
  255.          struct obj *uegg;
  256.  
  257.          if (!flags.female) {
  258.              pline("%s can't lay eggs!",
  259.                    Hallucination
  260.                        ? "You may think you are a platypus, but a male still"
  261.                        : "Males");
  262.              return 0;
  263.          } else if (u.uhunger < (int) objects[EGG].oc_nutrition) {
  264.              You("don't have enough energy to lay an egg.");
  265.              return 0;
  266.          }
  267.  
  268.          uegg = mksobj(EGG, FALSE, FALSE);
  269.          uegg->spe = 1;
  270.          uegg->quan = 1L;
  271.          uegg->owt = weight(uegg);
  272.          /* this sets hatch timers if appropriate */
  273.          set_corpsenm(uegg, egg_type_from_parent(u.umonnum, FALSE));
  274.          uegg->known = uegg->dknown = 1;
  275.          You("lay an egg.");
  276.          dropy(uegg);
  277.          stackobj(uegg);
  278.          morehungry((int) objects[EGG].oc_nutrition);
  279.      } else {
  280.          pline("Having fun sitting on the %s?", surface(u.ux, u.uy));
  281.      }
  282.      return 1;
  283.  }
  284.  

rndcurse

  1.  /* curse a few inventory items at random! */
  2.  void
  3.  rndcurse()
  4.  {
  5.      int nobj = 0;
  6.      int cnt, onum;
  7.      struct obj *otmp;
  8.      static const char mal_aura[] = "feel a malignant aura surround %s.";
  9.  
  10.      if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) {
  11.          You(mal_aura, "the magic-absorbing blade");
  12.          return;
  13.      }
  14.  
  15.      if (Antimagic) {
  16.          shieldeff(u.ux, u.uy);
  17.          You(mal_aura, "you");
  18.      }
  19.  
  20.      for (otmp = invent; otmp; otmp = otmp->nobj) {
  21.          /* gold isn't subject to being cursed or blessed */
  22.          if (otmp->oclass == COIN_CLASS)
  23.              continue;
  24.          nobj++;
  25.      }
  26.      if (nobj) {
  27.          for (cnt = rnd(6 / ((!!Antimagic) + (!!Half_spell_damage) + 1));
  28.               cnt > 0; cnt--) {
  29.              onum = rnd(nobj);
  30.              for (otmp = invent; otmp; otmp = otmp->nobj) {
  31.                  /* as above */
  32.                  if (otmp->oclass == COIN_CLASS)
  33.                      continue;
  34.                  if (--onum == 0)
  35.                      break; /* found the target */
  36.              }
  37.              /* the !otmp case should never happen; picking an already
  38.                 cursed item happens--avoid "resists" message in that case */
  39.              if (!otmp || otmp->cursed)
  40.                  continue; /* next target */
  41.  
  42.              if (otmp->oartifact && spec_ability(otmp, SPFX_INTEL)
  43.                  && rn2(10) < 8) {
  44.                  pline("%s!", Tobjnam(otmp, "resist"));
  45.                  continue;
  46.              }
  47.  
  48.              if (otmp->blessed)
  49.                  unbless(otmp);
  50.              else
  51.                  curse(otmp);
  52.          }
  53.          update_inventory();
  54.      }
  55.  
  56.      /* treat steed's saddle as extended part of hero's inventory */
  57.      if (u.usteed && !rn2(4) && (otmp = which_armor(u.usteed, W_SADDLE)) != 0
  58.          && !otmp->cursed) { /* skip if already cursed */
  59.          if (otmp->blessed)
  60.              unbless(otmp);
  61.          else
  62.              curse(otmp);
  63.          if (!Blind) {
  64.              pline("%s %s.", Yobjnam2(otmp, "glow"),
  65.                    hcolor(otmp->cursed ? NH_BLACK : (const char *) "brown"));
  66.              otmp->bknown = TRUE;
  67.          }
  68.      }
  69.  }
  70.  

attrcurse

  1.  /* remove a random INTRINSIC ability */
  2.  void
  3.  attrcurse()
  4.  {
  5.      switch (rnd(11)) {
  6.      case 1:
  7.          if (HFire_resistance & INTRINSIC) {
  8.              HFire_resistance &= ~INTRINSIC;
  9.              You_feel("warmer.");
  10.              break;
  11.          }
  12.      case 2:
  13.          if (HTeleportation & INTRINSIC) {
  14.              HTeleportation &= ~INTRINSIC;
  15.              You_feel("less jumpy.");
  16.              break;
  17.          }
  18.      case 3:
  19.          if (HPoison_resistance & INTRINSIC) {
  20.              HPoison_resistance &= ~INTRINSIC;
  21.              You_feel("a little sick!");
  22.              break;
  23.          }
  24.      case 4:
  25.          if (HTelepat & INTRINSIC) {
  26.              HTelepat &= ~INTRINSIC;
  27.              if (Blind && !Blind_telepat)
  28.                  see_monsters(); /* Can't sense mons anymore! */
  29.              Your("senses fail!");
  30.              break;
  31.          }
  32.      case 5:
  33.          if (HCold_resistance & INTRINSIC) {
  34.              HCold_resistance &= ~INTRINSIC;
  35.              You_feel("cooler.");
  36.              break;
  37.          }
  38.      case 6:
  39.          if (HInvis & INTRINSIC) {
  40.              HInvis &= ~INTRINSIC;
  41.              You_feel("paranoid.");
  42.              break;
  43.          }
  44.      case 7:
  45.          if (HSee_invisible & INTRINSIC) {
  46.              HSee_invisible &= ~INTRINSIC;
  47.              You("%s!", Hallucination ? "tawt you taw a puttie tat"
  48.                                       : "thought you saw something");
  49.              break;
  50.          }
  51.      case 8:
  52.          if (HFast & INTRINSIC) {
  53.              HFast &= ~INTRINSIC;
  54.              You_feel("slower.");
  55.              break;
  56.          }
  57.      case 9:
  58.          if (HStealth & INTRINSIC) {
  59.              HStealth &= ~INTRINSIC;
  60.              You_feel("clumsy.");
  61.              break;
  62.          }
  63.      case 10:
  64.          /* intrinsic protection is just disabled, not set back to 0 */
  65.          if (HProtection & INTRINSIC) {
  66.              HProtection &= ~INTRINSIC;
  67.              You_feel("vulnerable.");
  68.              break;
  69.          }
  70.      case 11:
  71.          if (HAggravate_monster & INTRINSIC) {
  72.              HAggravate_monster &= ~INTRINSIC;
  73.              You_feel("less attractive.");
  74.              break;
  75.          }
  76.      default:
  77.          break;
  78.      }
  79.  }
  80.  
  81.  /*sit.c*/