Source:NetHack 3.6.0/src/pray.c

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

Below is the full text to pray.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/pray.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	pray.c	$NHDT-Date: 1446854232 2015/11/06 23:57:12 $  $NHDT-Branch: master $:$NHDT-Revision: 1.87 $ */
  2.  /* Copyright (c) Benson I. Margulies, Mike Stephenson, Steve Linhart, 1989. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  STATIC_PTR int NDECL(prayer_done);
  8.  STATIC_DCL struct obj *NDECL(worst_cursed_item);
  9.  STATIC_DCL int NDECL(in_trouble);
  10.  STATIC_DCL void FDECL(fix_worst_trouble, (int));
  11.  STATIC_DCL void FDECL(angrygods, (ALIGNTYP_P));
  12.  STATIC_DCL void FDECL(at_your_feet, (const char *));
  13.  STATIC_DCL void NDECL(gcrownu);
  14.  STATIC_DCL void FDECL(pleased, (ALIGNTYP_P));
  15.  STATIC_DCL void FDECL(godvoice, (ALIGNTYP_P, const char *));
  16.  STATIC_DCL void FDECL(god_zaps_you, (ALIGNTYP_P));
  17.  STATIC_DCL void FDECL(fry_by_god, (ALIGNTYP_P, BOOLEAN_P));
  18.  STATIC_DCL void FDECL(gods_angry, (ALIGNTYP_P));
  19.  STATIC_DCL void FDECL(gods_upset, (ALIGNTYP_P));
  20.  STATIC_DCL void FDECL(consume_offering, (struct obj *));
  21.  STATIC_DCL boolean FDECL(water_prayer, (BOOLEAN_P));
  22.  STATIC_DCL boolean FDECL(blocked_boulder, (int, int));
  23.  
  24.  /* simplify a few tests */
  25.  #define Cursed_obj(obj, typ) ((obj) && (obj)->otyp == (typ) && (obj)->cursed)
  26.  
  27.  /*
  28.   * Logic behind deities and altars and such:
  29.   * + prayers are made to your god if not on an altar, and to the altar's god
  30.   *   if you are on an altar
  31.   * + If possible, your god answers all prayers, which is why bad things happen
  32.   *   if you try to pray on another god's altar
  33.   * + sacrifices work basically the same way, but the other god may decide to
  34.   *   accept your allegiance, after which they are your god.  If rejected,
  35.   *   your god takes over with your punishment.
  36.   * + if you're in Gehennom, all messages come from Moloch
  37.   */
  38.  
  39.  /*
  40.   *      Moloch, who dwells in Gehennom, is the "renegade" cruel god
  41.   *      responsible for the theft of the Amulet from Marduk, the Creator.
  42.   *      Moloch is unaligned.
  43.   */
  44.  static const char *Moloch = "Moloch";
  45.  
  46.  static const char *godvoices[] = {
  47.      "booms out", "thunders", "rings out", "booms",
  48.  };
  49.  
  50.  /* values calculated when prayer starts, and used when completed */
  51.  static aligntyp p_aligntyp;
  52.  static int p_trouble;
  53.  static int p_type; /* (-1)-3: (-1)=really naughty, 3=really good */
  54.  
  55.  #define PIOUS 20
  56.  #define DEVOUT 14
  57.  #define FERVENT 9
  58.  #define STRIDENT 4
  59.  
  60.  /*
  61.   * The actual trouble priority is determined by the order of the
  62.   * checks performed in in_trouble() rather than by these numeric
  63.   * values, so keep that code and these values synchronized in
  64.   * order to have the values be meaningful.
  65.   */
  66.  
  67.  #define TROUBLE_STONED 14
  68.  #define TROUBLE_SLIMED 13
  69.  #define TROUBLE_STRANGLED 12
  70.  #define TROUBLE_LAVA 11
  71.  #define TROUBLE_SICK 10
  72.  #define TROUBLE_STARVING 9
  73.  #define TROUBLE_REGION 8 /* stinking cloud */
  74.  #define TROUBLE_HIT 7
  75.  #define TROUBLE_LYCANTHROPE 6
  76.  #define TROUBLE_COLLAPSING 5
  77.  #define TROUBLE_STUCK_IN_WALL 4
  78.  #define TROUBLE_CURSED_LEVITATION 3
  79.  #define TROUBLE_UNUSEABLE_HANDS 2
  80.  #define TROUBLE_CURSED_BLINDFOLD 1
  81.  
  82.  #define TROUBLE_PUNISHED (-1)
  83.  #define TROUBLE_FUMBLING (-2)
  84.  #define TROUBLE_CURSED_ITEMS (-3)
  85.  #define TROUBLE_SADDLE (-4)
  86.  #define TROUBLE_BLIND (-5)
  87.  #define TROUBLE_POISONED (-6)
  88.  #define TROUBLE_WOUNDED_LEGS (-7)
  89.  #define TROUBLE_HUNGRY (-8)
  90.  #define TROUBLE_STUNNED (-9)
  91.  #define TROUBLE_CONFUSED (-10)
  92.  #define TROUBLE_HALLUCINATION (-11)
  93.  
  94.  
  95.  #define ugod_is_angry() (u.ualign.record < 0)
  96.  #define on_altar() IS_ALTAR(levl[u.ux][u.uy].typ)
  97.  #define on_shrine() ((levl[u.ux][u.uy].altarmask & AM_SHRINE) != 0)
  98.  #define a_align(x, y) ((aligntyp) Amask2align(levl[x][y].altarmask & AM_MASK))
  99.  

critically_low_hp

  1.  /* critically low hit points if hp <= 5 or hp <= maxhp/N for some N */
  2.  boolean
  3.  critically_low_hp(only_if_injured)
  4.  boolean only_if_injured; /* determines whether maxhp <= 5 matters */
  5.  {
  6.      int divisor, hplim, curhp = Upolyd ? u.mh : u.uhp,
  7.                          maxhp = Upolyd ? u.mhmax : u.uhpmax;
  8.  
  9.      if (only_if_injured && !(curhp < maxhp))
  10.          return FALSE;
  11.      /* if maxhp is extremely high, use lower threshold for the division test
  12.         (golden glow cuts off at 11+5*lvl, nurse interaction at 25*lvl; this
  13.         ought to use monster hit dice--and a smaller multiplier--rather than
  14.         ulevel when polymorphed, but polyself doesn't maintain that) */
  15.      hplim = 15 * u.ulevel;
  16.      if (maxhp > hplim)
  17.          maxhp = hplim;
  18.      /* 7 used to be the unconditional divisor */
  19.      switch (xlev_to_rank(u.ulevel)) { /* maps 1..30 into 0..8 */
  20.      case 0:
  21.      case 1:
  22.          divisor = 5;
  23.          break; /* explvl 1 to 5 */
  24.      case 2:
  25.      case 3:
  26.          divisor = 6;
  27.          break; /* explvl 6 to 13 */
  28.      case 4:
  29.      case 5:
  30.          divisor = 7;
  31.          break; /* explvl 14 to 21 */
  32.      case 6:
  33.      case 7:
  34.          divisor = 8;
  35.          break; /* explvl 22 to 29 */
  36.      default:
  37.          divisor = 9;
  38.          break; /* explvl 30+ */
  39.      }
  40.      /* 5 is a magic number in TROUBLE_HIT handling below */
  41.      return (boolean) (curhp <= 5 || curhp * divisor <= maxhp);
  42.  }
  43.  

in_trouble

  1.  /*
  2.   * Return 0 if nothing particular seems wrong, positive numbers for
  3.   * serious trouble, and negative numbers for comparative annoyances.
  4.   * This returns the worst problem. There may be others, and the gods
  5.   * may fix more than one.
  6.   *
  7.   * This could get as bizarre as noting surrounding opponents, (or
  8.   * hostile dogs), but that's really hard.
  9.   *
  10.   * We could force rehumanize of polyselfed people, but we can't tell
  11.   * unintentional shape changes from the other kind. Oh well.
  12.   * 3.4.2: make an exception if polymorphed into a form which lacks
  13.   * hands; that's a case where the ramifications override this doubt.
  14.   */
  15.  STATIC_OVL int
  16.  in_trouble()
  17.  {
  18.      struct obj *otmp;
  19.      int i, j, count = 0;
  20.  
  21.      /*
  22.       * major troubles
  23.       */
  24.      if (Stoned)
  25.          return TROUBLE_STONED;
  26.      if (Slimed)
  27.          return TROUBLE_SLIMED;
  28.      if (Strangled)
  29.          return TROUBLE_STRANGLED;
  30.      if (u.utrap && u.utraptype == TT_LAVA)
  31.          return TROUBLE_LAVA;
  32.      if (Sick)
  33.          return TROUBLE_SICK;
  34.      if (u.uhs >= WEAK)
  35.          return TROUBLE_STARVING;
  36.      if (region_danger())
  37.          return TROUBLE_REGION;
  38.      if (critically_low_hp(FALSE))
  39.          return TROUBLE_HIT;
  40.      if (u.ulycn >= LOW_PM)
  41.          return TROUBLE_LYCANTHROPE;
  42.      if (near_capacity() >= EXT_ENCUMBER && AMAX(A_STR) - ABASE(A_STR) > 3)
  43.          return TROUBLE_COLLAPSING;
  44.  
  45.      for (i = -1; i <= 1; i++)
  46.          for (j = -1; j <= 1; j++) {
  47.              if (!i && !j)
  48.                  continue;
  49.              if (!isok(u.ux + i, u.uy + j)
  50.                  || IS_ROCK(levl[u.ux + i][u.uy + j].typ)
  51.                  || (blocked_boulder(i, j) && !throws_rocks(youmonst.data)))
  52.                  count++;
  53.          }
  54.      if (count == 8 && !Passes_walls)
  55.          return TROUBLE_STUCK_IN_WALL;
  56.  
  57.      if (Cursed_obj(uarmf, LEVITATION_BOOTS)
  58.          || stuck_ring(uleft, RIN_LEVITATION)
  59.          || stuck_ring(uright, RIN_LEVITATION))
  60.          return TROUBLE_CURSED_LEVITATION;
  61.      if (nohands(youmonst.data) || !freehand()) {
  62.          /* for bag/box access [cf use_container()]...
  63.             make sure it's a case that we know how to handle;
  64.             otherwise "fix all troubles" would get stuck in a loop */
  65.          if (welded(uwep))
  66.              return TROUBLE_UNUSEABLE_HANDS;
  67.          if (Upolyd && nohands(youmonst.data)
  68.              && (!Unchanging || ((otmp = unchanger()) != 0 && otmp->cursed)))
  69.              return TROUBLE_UNUSEABLE_HANDS;
  70.      }
  71.      if (Blindfolded && ublindf->cursed)
  72.          return TROUBLE_CURSED_BLINDFOLD;
  73.  
  74.      /*
  75.       * minor troubles
  76.       */
  77.      if (Punished || (u.utrap && u.utraptype == TT_BURIEDBALL))
  78.          return TROUBLE_PUNISHED;
  79.      if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING)
  80.          || Cursed_obj(uarmf, FUMBLE_BOOTS))
  81.          return TROUBLE_FUMBLING;
  82.      if (worst_cursed_item())
  83.          return TROUBLE_CURSED_ITEMS;
  84.      if (u.usteed) { /* can't voluntarily dismount from a cursed saddle */
  85.          otmp = which_armor(u.usteed, W_SADDLE);
  86.          if (Cursed_obj(otmp, SADDLE))
  87.              return TROUBLE_SADDLE;
  88.      }
  89.  
  90.      if (Blinded > 1 && haseyes(youmonst.data)
  91.          && (!u.uswallow
  92.              || !attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)))
  93.          return TROUBLE_BLIND;
  94.      for (i = 0; i < A_MAX; i++)
  95.          if (ABASE(i) < AMAX(i))
  96.              return TROUBLE_POISONED;
  97.      if (Wounded_legs && !u.usteed)
  98.          return TROUBLE_WOUNDED_LEGS;
  99.      if (u.uhs >= HUNGRY)
  100.          return TROUBLE_HUNGRY;
  101.      if (HStun & TIMEOUT)
  102.          return TROUBLE_STUNNED;
  103.      if (HConfusion & TIMEOUT)
  104.          return TROUBLE_CONFUSED;
  105.      if (HHallucination & TIMEOUT)
  106.          return TROUBLE_HALLUCINATION;
  107.      return 0;
  108.  }
  109.  

worst_cursed_item

  1.  /* select an item for TROUBLE_CURSED_ITEMS */
  2.  STATIC_OVL struct obj *
  3.  worst_cursed_item()
  4.  {
  5.      register struct obj *otmp;
  6.  
  7.      /* if strained or worse, check for loadstone first */
  8.      if (near_capacity() >= HVY_ENCUMBER) {
  9.          for (otmp = invent; otmp; otmp = otmp->nobj)
  10.              if (Cursed_obj(otmp, LOADSTONE))
  11.                  return otmp;
  12.      }
  13.      /* weapon takes precedence if it is interfering
  14.         with taking off a ring or putting on a shield */
  15.      if (welded(uwep) && (uright || bimanual(uwep))) { /* weapon */
  16.          otmp = uwep;
  17.          /* gloves come next, due to rings */
  18.      } else if (uarmg && uarmg->cursed) { /* gloves */
  19.          otmp = uarmg;
  20.          /* then shield due to two handed weapons and spells */
  21.      } else if (uarms && uarms->cursed) { /* shield */
  22.          otmp = uarms;
  23.          /* then cloak due to body armor */
  24.      } else if (uarmc && uarmc->cursed) { /* cloak */
  25.          otmp = uarmc;
  26.      } else if (uarm && uarm->cursed) { /* suit */
  27.          otmp = uarm;
  28.      } else if (uarmh && uarmh->cursed) { /* helmet */
  29.          otmp = uarmh;
  30.      } else if (uarmf && uarmf->cursed) { /* boots */
  31.          otmp = uarmf;
  32.      } else if (uarmu && uarmu->cursed) { /* shirt */
  33.          otmp = uarmu;
  34.      } else if (uamul && uamul->cursed) { /* amulet */
  35.          otmp = uamul;
  36.      } else if (uleft && uleft->cursed) { /* left ring */
  37.          otmp = uleft;
  38.      } else if (uright && uright->cursed) { /* right ring */
  39.          otmp = uright;
  40.      } else if (ublindf && ublindf->cursed) { /* eyewear */
  41.          otmp = ublindf;                      /* must be non-blinding lenses */
  42.          /* if weapon wasn't handled above, do it now */
  43.      } else if (welded(uwep)) { /* weapon */
  44.          otmp = uwep;
  45.          /* active secondary weapon even though it isn't welded */
  46.      } else if (uswapwep && uswapwep->cursed && u.twoweap) {
  47.          otmp = uswapwep;
  48.          /* all worn items ought to be handled by now */
  49.      } else {
  50.          for (otmp = invent; otmp; otmp = otmp->nobj) {
  51.              if (!otmp->cursed)
  52.                  continue;
  53.              if (otmp->otyp == LOADSTONE || confers_luck(otmp))
  54.                  break;
  55.          }
  56.      }
  57.      return otmp;
  58.  }
  59.  

fix_worst_trouble

  1.  STATIC_OVL void
  2.  fix_worst_trouble(trouble)
  3.  int trouble;
  4.  {
  5.      int i;
  6.      struct obj *otmp = 0;
  7.      const char *what = (const char *) 0;
  8.      static NEARDATA const char leftglow[] = "Your left ring softly glows",
  9.                                 rightglow[] = "Your right ring softly glows";
  10.  
  11.      switch (trouble) {
  12.      case TROUBLE_STONED:
  13.          make_stoned(0L, "You feel more limber.", 0, (char *) 0);
  14.          break;
  15.      case TROUBLE_SLIMED:
  16.          make_slimed(0L, "The slime disappears.");
  17.          break;
  18.      case TROUBLE_STRANGLED:
  19.          if (uamul && uamul->otyp == AMULET_OF_STRANGULATION) {
  20.              Your("amulet vanishes!");
  21.              useup(uamul);
  22.          }
  23.          You("can breathe again.");
  24.          Strangled = 0;
  25.          context.botl = 1;
  26.          break;
  27.      case TROUBLE_LAVA:
  28.          You("are back on solid ground.");
  29.          /* teleport should always succeed, but if not,
  30.           * just untrap them.
  31.           */
  32.          if (!safe_teleds(FALSE))
  33.              u.utrap = 0;
  34.          break;
  35.      case TROUBLE_STARVING:
  36.          losestr(-1);
  37.          /*FALLTHRU*/
  38.      case TROUBLE_HUNGRY:
  39.          Your("%s feels content.", body_part(STOMACH));
  40.          init_uhunger();
  41.          context.botl = 1;
  42.          break;
  43.      case TROUBLE_SICK:
  44.          You_feel("better.");
  45.          make_sick(0L, (char *) 0, FALSE, SICK_ALL);
  46.          break;
  47.      case TROUBLE_REGION:
  48.          /* stinking cloud, with hero vulnerable to HP loss */
  49.          region_safety();
  50.          break;
  51.      case TROUBLE_HIT:
  52.          /* "fix all troubles" will keep trying if hero has
  53.             5 or less hit points, so make sure they're always
  54.             boosted to be more than that */
  55.          You_feel("much better.");
  56.          if (Upolyd) {
  57.              u.mhmax += rnd(5);
  58.              if (u.mhmax <= 5)
  59.                  u.mhmax = 5 + 1;
  60.              u.mh = u.mhmax;
  61.          }
  62.          if (u.uhpmax < u.ulevel * 5 + 11)
  63.              u.uhpmax += rnd(5);
  64.          if (u.uhpmax <= 5)
  65.              u.uhpmax = 5 + 1;
  66.          u.uhp = u.uhpmax;
  67.          context.botl = 1;
  68.          break;
  69.      case TROUBLE_COLLAPSING:
  70.          /* override Fixed_abil; uncurse that if feasible */
  71.          You_feel("%sstronger.",
  72.                   (AMAX(A_STR) - ABASE(A_STR) > 6) ? "much " : "");
  73.          ABASE(A_STR) = AMAX(A_STR);
  74.          context.botl = 1;
  75.          if (Fixed_abil) {
  76.              if ((otmp = stuck_ring(uleft, RIN_SUSTAIN_ABILITY)) != 0) {
  77.                  if (otmp == uleft)
  78.                      what = leftglow;
  79.              } else if ((otmp = stuck_ring(uright, RIN_SUSTAIN_ABILITY))
  80.                         != 0) {
  81.                  if (otmp == uright)
  82.                      what = rightglow;
  83.              }
  84.              if (otmp)
  85.                  goto decurse;
  86.          }
  87.          break;
  88.      case TROUBLE_STUCK_IN_WALL:
  89.          Your("surroundings change.");
  90.          /* no control, but works on no-teleport levels */
  91.          (void) safe_teleds(FALSE);
  92.          break;
  93.      case TROUBLE_CURSED_LEVITATION:
  94.          if (Cursed_obj(uarmf, LEVITATION_BOOTS)) {
  95.              otmp = uarmf;
  96.          } else if ((otmp = stuck_ring(uleft, RIN_LEVITATION)) != 0) {
  97.              if (otmp == uleft)
  98.                  what = leftglow;
  99.          } else if ((otmp = stuck_ring(uright, RIN_LEVITATION)) != 0) {
  100.              if (otmp == uright)
  101.                  what = rightglow;
  102.          }
  103.          goto decurse;
  104.      case TROUBLE_UNUSEABLE_HANDS:
  105.          if (welded(uwep)) {
  106.              otmp = uwep;
  107.              goto decurse;
  108.          }
  109.          if (Upolyd && nohands(youmonst.data)) {
  110.              if (!Unchanging) {
  111.                  Your("shape becomes uncertain.");
  112.                  rehumanize(); /* "You return to {normal} form." */
  113.              } else if ((otmp = unchanger()) != 0 && otmp->cursed) {
  114.                  /* otmp is an amulet of unchanging */
  115.                  goto decurse;
  116.              }
  117.          }
  118.          if (nohands(youmonst.data) || !freehand())
  119.              impossible("fix_worst_trouble: couldn't cure hands.");
  120.          break;
  121.      case TROUBLE_CURSED_BLINDFOLD:
  122.          otmp = ublindf;
  123.          goto decurse;
  124.      case TROUBLE_LYCANTHROPE:
  125.          you_unwere(TRUE);
  126.          break;
  127.      /*
  128.       */
  129.      case TROUBLE_PUNISHED:
  130.          Your("chain disappears.");
  131.          if (u.utrap && u.utraptype == TT_BURIEDBALL)
  132.              buried_ball_to_freedom();
  133.          else
  134.              unpunish();
  135.          break;
  136.      case TROUBLE_FUMBLING:
  137.          if (Cursed_obj(uarmg, GAUNTLETS_OF_FUMBLING))
  138.              otmp = uarmg;
  139.          else if (Cursed_obj(uarmf, FUMBLE_BOOTS))
  140.              otmp = uarmf;
  141.          goto decurse;
  142.          /*NOTREACHED*/
  143.          break;
  144.      case TROUBLE_CURSED_ITEMS:
  145.          otmp = worst_cursed_item();
  146.          if (otmp == uright)
  147.              what = rightglow;
  148.          else if (otmp == uleft)
  149.              what = leftglow;
  150.      decurse:
  151.          if (!otmp) {
  152.              impossible("fix_worst_trouble: nothing to uncurse.");
  153.              return;
  154.          }
  155.          if (!Blind || (otmp == ublindf && Blindfolded_only)) {
  156.              pline("%s %s.",
  157.                    what ? what : (const char *) Yobjnam2(otmp, "softly glow"),
  158.                    hcolor(NH_AMBER));
  159.              iflags.last_msg = PLNMSG_OBJ_GLOWS;
  160.              otmp->bknown = TRUE;
  161.          }
  162.          uncurse(otmp);
  163.          update_inventory();
  164.          break;
  165.      case TROUBLE_POISONED:
  166.          /* override Fixed_abil; ignore items which confer that */
  167.          if (Hallucination)
  168.              pline("There's a tiger in your tank.");
  169.          else
  170.              You_feel("in good health again.");
  171.          for (i = 0; i < A_MAX; i++) {
  172.              if (ABASE(i) < AMAX(i)) {
  173.                  ABASE(i) = AMAX(i);
  174.                  context.botl = 1;
  175.              }
  176.          }
  177.          (void) encumber_msg();
  178.          break;
  179.      case TROUBLE_BLIND: {
  180.          const char *eyes = body_part(EYE);
  181.  
  182.          if (eyecount(youmonst.data) != 1)
  183.              eyes = makeplural(eyes);
  184.          Your("%s %s better.", eyes, vtense(eyes, "feel"));
  185.          u.ucreamed = 0;
  186.          make_blinded(0L, FALSE);
  187.          break;
  188.      }
  189.      case TROUBLE_WOUNDED_LEGS:
  190.          heal_legs();
  191.          break;
  192.      case TROUBLE_STUNNED:
  193.          make_stunned(0L, TRUE);
  194.          break;
  195.      case TROUBLE_CONFUSED:
  196.          make_confused(0L, TRUE);
  197.          break;
  198.      case TROUBLE_HALLUCINATION:
  199.          pline("Looks like you are back in Kansas.");
  200.          (void) make_hallucinated(0L, FALSE, 0L);
  201.          break;
  202.      case TROUBLE_SADDLE:
  203.          otmp = which_armor(u.usteed, W_SADDLE);
  204.          if (!Blind) {
  205.              pline("%s %s.", Yobjnam2(otmp, "softly glow"), hcolor(NH_AMBER));
  206.              otmp->bknown = TRUE;
  207.          }
  208.          uncurse(otmp);
  209.          break;
  210.      }
  211.  }
  212.  

god_zaps_you

  1.  /* "I am sometimes shocked by...  the nuns who never take a bath without
  2.   * wearing a bathrobe all the time.  When asked why, since no man can see
  3.   * them,
  4.   * they reply 'Oh, but you forget the good God'.  Apparently they conceive of
  5.   * the Deity as a Peeping Tom, whose omnipotence enables Him to see through
  6.   * bathroom walls, but who is foiled by bathrobes." --Bertrand Russell, 1943
  7.   * Divine wrath, dungeon walls, and armor follow the same principle.
  8.   */
  9.  STATIC_OVL void
  10.  god_zaps_you(resp_god)
  11.  aligntyp resp_god;
  12.  {
  13.      if (u.uswallow) {
  14.          pline(
  15.            "Suddenly a bolt of lightning comes down at you from the heavens!");
  16.          pline("It strikes %s!", mon_nam(u.ustuck));
  17.          if (!resists_elec(u.ustuck)) {
  18.              pline("%s fries to a crisp!", Monnam(u.ustuck));
  19.              /* Yup, you get experience.  It takes guts to successfully
  20.               * pull off this trick on your god, anyway.
  21.               */
  22.              xkilled(u.ustuck, 0);
  23.          } else
  24.              pline("%s seems unaffected.", Monnam(u.ustuck));
  25.      } else {
  26.          pline("Suddenly, a bolt of lightning strikes you!");
  27.          if (Reflecting) {
  28.              shieldeff(u.ux, u.uy);
  29.              if (Blind)
  30.                  pline("For some reason you're unaffected.");
  31.              else
  32.                  (void) ureflects("%s reflects from your %s.", "It");
  33.          } else if (Shock_resistance) {
  34.              shieldeff(u.ux, u.uy);
  35.              pline("It seems not to affect you.");
  36.          } else
  37.              fry_by_god(resp_god, FALSE);
  38.      }
  39.  
  40.      pline("%s is not deterred...", align_gname(resp_god));
  41.      if (u.uswallow) {
  42.          pline("A wide-angle disintegration beam aimed at you hits %s!",
  43.                mon_nam(u.ustuck));
  44.          if (!resists_disint(u.ustuck)) {
  45.              pline("%s disintegrates into a pile of dust!", Monnam(u.ustuck));
  46.              xkilled(u.ustuck, 2); /* no corpse */
  47.          } else
  48.              pline("%s seems unaffected.", Monnam(u.ustuck));
  49.      } else {
  50.          pline("A wide-angle disintegration beam hits you!");
  51.  
  52.          /* disintegrate shield and body armor before disintegrating
  53.           * the impudent mortal, like black dragon breath -3.
  54.           */
  55.          if (uarms && !(EReflecting & W_ARMS)
  56.              && !(EDisint_resistance & W_ARMS))
  57.              (void) destroy_arm(uarms);
  58.          if (uarmc && !(EReflecting & W_ARMC)
  59.              && !(EDisint_resistance & W_ARMC))
  60.              (void) destroy_arm(uarmc);
  61.          if (uarm && !(EReflecting & W_ARM) && !(EDisint_resistance & W_ARM)
  62.              && !uarmc)
  63.              (void) destroy_arm(uarm);
  64.          if (uarmu && !uarm && !uarmc)
  65.              (void) destroy_arm(uarmu);
  66.          if (!Disint_resistance)
  67.              fry_by_god(resp_god, TRUE);
  68.          else {
  69.              You("bask in its %s glow for a minute...", NH_BLACK);
  70.              godvoice(resp_god, "I believe it not!");
  71.          }
  72.          if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) {
  73.              /* one more try for high altars */
  74.              verbalize("Thou cannot escape my wrath, mortal!");
  75.              summon_minion(resp_god, FALSE);
  76.              summon_minion(resp_god, FALSE);
  77.              summon_minion(resp_god, FALSE);
  78.              verbalize("Destroy %s, my servants!", uhim());
  79.          }
  80.      }
  81.  }
  82.  

fry_by_god

  1.  STATIC_OVL void
  2.  fry_by_god(resp_god, via_disintegration)
  3.  aligntyp resp_god;
  4.  boolean via_disintegration;
  5.  {
  6.      You("%s!", !via_disintegration ? "fry to a crisp"
  7.                                     : "disintegrate into a pile of dust");
  8.      killer.format = KILLED_BY;
  9.      Sprintf(killer.name, "the wrath of %s", align_gname(resp_god));
  10.      done(DIED);
  11.  }
  12.  

angrygods

  1.  STATIC_OVL void
  2.  angrygods(resp_god)
  3.  aligntyp resp_god;
  4.  {
  5.      int maxanger;
  6.  
  7.      if (Inhell)
  8.          resp_god = A_NONE;
  9.      u.ublessed = 0;
  10.  
  11.      /* changed from tmp = u.ugangr + abs (u.uluck) -- rph */
  12.      /* added test for alignment diff -dlc */
  13.      if (resp_god != u.ualign.type)
  14.          maxanger = u.ualign.record / 2 + (Luck > 0 ? -Luck / 3 : -Luck);
  15.      else
  16.          maxanger = 3 * u.ugangr + ((Luck > 0 || u.ualign.record >= STRIDENT)
  17.                                     ? -Luck / 3
  18.                                     : -Luck);
  19.      if (maxanger < 1)
  20.          maxanger = 1; /* possible if bad align & good luck */
  21.      else if (maxanger > 15)
  22.          maxanger = 15; /* be reasonable */
  23.  
  24.      switch (rn2(maxanger)) {
  25.      case 0:
  26.      case 1:
  27.          You_feel("that %s is %s.", align_gname(resp_god),
  28.                   Hallucination ? "bummed" : "displeased");
  29.          break;
  30.      case 2:
  31.      case 3:
  32.          godvoice(resp_god, (char *) 0);
  33.          pline("\"Thou %s, %s.\"",
  34.                (ugod_is_angry() && resp_god == u.ualign.type)
  35.                    ? "hast strayed from the path"
  36.                    : "art arrogant",
  37.                youmonst.data->mlet == S_HUMAN ? "mortal" : "creature");
  38.          verbalize("Thou must relearn thy lessons!");
  39.          (void) adjattrib(A_WIS, -1, FALSE);
  40.          losexp((char *) 0);
  41.          break;
  42.      case 6:
  43.          if (!Punished) {
  44.              gods_angry(resp_god);
  45.              punish((struct obj *) 0);
  46.              break;
  47.          } /* else fall thru */
  48.      case 4:
  49.      case 5:
  50.          gods_angry(resp_god);
  51.          if (!Blind && !Antimagic)
  52.              pline("%s glow surrounds you.", An(hcolor(NH_BLACK)));
  53.          rndcurse();
  54.          break;
  55.      case 7:
  56.      case 8:
  57.          godvoice(resp_god, (char *) 0);
  58.          verbalize("Thou durst %s me?",
  59.                    (on_altar() && (a_align(u.ux, u.uy) != resp_god))
  60.                        ? "scorn"
  61.                        : "call upon");
  62.          pline("\"Then die, %s!\"",
  63.                youmonst.data->mlet == S_HUMAN ? "mortal" : "creature");
  64.          summon_minion(resp_god, FALSE);
  65.          break;
  66.  
  67.      default:
  68.          gods_angry(resp_god);
  69.          god_zaps_you(resp_god);
  70.          break;
  71.      }
  72.      u.ublesscnt = rnz(300);
  73.      return;
  74.  }
  75.  

at_your_feet

  1.  /* helper to print "str appears at your feet", or appropriate */
  2.  static void
  3.  at_your_feet(str)
  4.  const char *str;
  5.  {
  6.      if (Blind)
  7.          str = Something;
  8.      if (u.uswallow) {
  9.          /* barrier between you and the floor */
  10.          pline("%s %s into %s %s.", str, vtense(str, "drop"),
  11.                s_suffix(mon_nam(u.ustuck)), mbodypart(u.ustuck, STOMACH));
  12.      } else {
  13.          pline("%s %s %s your %s!", str,
  14.                Blind ? "lands" : vtense(str, "appear"),
  15.                Levitation ? "beneath" : "at", makeplural(body_part(FOOT)));
  16.      }
  17.  }
  18.  

gcrownu

  1.  STATIC_OVL void
  2.  gcrownu()
  3.  {
  4.      struct obj *obj;
  5.      boolean already_exists, in_hand;
  6.      short class_gift;
  7.      int sp_no;
  8.  #define ok_wep(o) ((o) && ((o)->oclass == WEAPON_CLASS || is_weptool(o)))
  9.  
  10.      HSee_invisible |= FROMOUTSIDE;
  11.      HFire_resistance |= FROMOUTSIDE;
  12.      HCold_resistance |= FROMOUTSIDE;
  13.      HShock_resistance |= FROMOUTSIDE;
  14.      HSleep_resistance |= FROMOUTSIDE;
  15.      HPoison_resistance |= FROMOUTSIDE;
  16.      godvoice(u.ualign.type, (char *) 0);
  17.  
  18.      obj = ok_wep(uwep) ? uwep : 0;
  19.      already_exists = in_hand = FALSE; /* lint suppression */
  20.      switch (u.ualign.type) {
  21.      case A_LAWFUL:
  22.          u.uevent.uhand_of_elbereth = 1;
  23.          verbalize("I crown thee...  The Hand of Elbereth!");
  24.          break;
  25.      case A_NEUTRAL:
  26.          u.uevent.uhand_of_elbereth = 2;
  27.          in_hand = (uwep && uwep->oartifact == ART_VORPAL_BLADE);
  28.          already_exists =
  29.              exist_artifact(LONG_SWORD, artiname(ART_VORPAL_BLADE));
  30.          verbalize("Thou shalt be my Envoy of Balance!");
  31.          break;
  32.      case A_CHAOTIC:
  33.          u.uevent.uhand_of_elbereth = 3;
  34.          in_hand = (uwep && uwep->oartifact == ART_STORMBRINGER);
  35.          already_exists =
  36.              exist_artifact(RUNESWORD, artiname(ART_STORMBRINGER));
  37.          verbalize("Thou art chosen to %s for My Glory!",
  38.                    already_exists && !in_hand ? "take lives" : "steal souls");
  39.          break;
  40.      }
  41.  
  42.      class_gift = STRANGE_OBJECT;
  43.      /* 3.3.[01] had this in the A_NEUTRAL case below,
  44.         preventing chaotic wizards from receiving a spellbook */
  45.      if (Role_if(PM_WIZARD)
  46.          && (!uwep || (uwep->oartifact != ART_VORPAL_BLADE
  47.                        && uwep->oartifact != ART_STORMBRINGER))
  48.          && !carrying(SPE_FINGER_OF_DEATH)) {
  49.          class_gift = SPE_FINGER_OF_DEATH;
  50.      make_splbk:
  51.          obj = mksobj(class_gift, TRUE, FALSE);
  52.          bless(obj);
  53.          obj->bknown = TRUE;
  54.          at_your_feet("A spellbook");
  55.          dropy(obj);
  56.          u.ugifts++;
  57.          /* when getting a new book for known spell, enhance
  58.             currently wielded weapon rather than the book */
  59.          for (sp_no = 0; sp_no < MAXSPELL; sp_no++)
  60.              if (spl_book[sp_no].sp_id == class_gift) {
  61.                  if (ok_wep(uwep))
  62.                      obj = uwep; /* to be blessed,&c */
  63.                  break;
  64.              }
  65.      } else if (Role_if(PM_MONK) && (!uwep || !uwep->oartifact)
  66.                 && !carrying(SPE_RESTORE_ABILITY)) {
  67.          /* monks rarely wield a weapon */
  68.          class_gift = SPE_RESTORE_ABILITY;
  69.          goto make_splbk;
  70.      }
  71.  
  72.      switch (u.ualign.type) {
  73.      case A_LAWFUL:
  74.          if (class_gift != STRANGE_OBJECT) {
  75.              ; /* already got bonus above */
  76.          } else if (obj && obj->otyp == LONG_SWORD && !obj->oartifact) {
  77.              if (!Blind)
  78.                  Your("sword shines brightly for a moment.");
  79.              obj = oname(obj, artiname(ART_EXCALIBUR));
  80.              if (obj && obj->oartifact == ART_EXCALIBUR)
  81.                  u.ugifts++;
  82.          }
  83.          /* acquire Excalibur's skill regardless of weapon or gift */
  84.          unrestrict_weapon_skill(P_LONG_SWORD);
  85.          if (obj && obj->oartifact == ART_EXCALIBUR)
  86.              discover_artifact(ART_EXCALIBUR);
  87.          break;
  88.      case A_NEUTRAL:
  89.          if (class_gift != STRANGE_OBJECT) {
  90.              ; /* already got bonus above */
  91.          } else if (obj && in_hand) {
  92.              Your("%s goes snicker-snack!", xname(obj));
  93.              obj->dknown = TRUE;
  94.          } else if (!already_exists) {
  95.              obj = mksobj(LONG_SWORD, FALSE, FALSE);
  96.              obj = oname(obj, artiname(ART_VORPAL_BLADE));
  97.              obj->spe = 1;
  98.              at_your_feet("A sword");
  99.              dropy(obj);
  100.              u.ugifts++;
  101.          }
  102.          /* acquire Vorpal Blade's skill regardless of weapon or gift */
  103.          unrestrict_weapon_skill(P_LONG_SWORD);
  104.          if (obj && obj->oartifact == ART_VORPAL_BLADE)
  105.              discover_artifact(ART_VORPAL_BLADE);
  106.          break;
  107.      case A_CHAOTIC: {
  108.          char swordbuf[BUFSZ];
  109.  
  110.          Sprintf(swordbuf, "%s sword", hcolor(NH_BLACK));
  111.          if (class_gift != STRANGE_OBJECT) {
  112.              ; /* already got bonus above */
  113.          } else if (obj && in_hand) {
  114.              Your("%s hums ominously!", swordbuf);
  115.              obj->dknown = TRUE;
  116.          } else if (!already_exists) {
  117.              obj = mksobj(RUNESWORD, FALSE, FALSE);
  118.              obj = oname(obj, artiname(ART_STORMBRINGER));
  119.              obj->spe = 1;
  120.              at_your_feet(An(swordbuf));
  121.              dropy(obj);
  122.              u.ugifts++;
  123.          }
  124.          /* acquire Stormbringer's skill regardless of weapon or gift */
  125.          unrestrict_weapon_skill(P_BROAD_SWORD);
  126.          if (obj && obj->oartifact == ART_STORMBRINGER)
  127.              discover_artifact(ART_STORMBRINGER);
  128.          break;
  129.      }
  130.      default:
  131.          obj = 0; /* lint */
  132.          break;
  133.      }
  134.  
  135.      /* enhance weapon regardless of alignment or artifact status */
  136.      if (ok_wep(obj)) {
  137.          bless(obj);
  138.          obj->oeroded = obj->oeroded2 = 0;
  139.          obj->oerodeproof = TRUE;
  140.          obj->bknown = obj->rknown = TRUE;
  141.          if (obj->spe < 1)
  142.              obj->spe = 1;
  143.          /* acquire skill in this weapon */
  144.          unrestrict_weapon_skill(weapon_type(obj));
  145.      } else if (class_gift == STRANGE_OBJECT) {
  146.          /* opportunity knocked, but there was nobody home... */
  147.          You_feel("unworthy.");
  148.      }
  149.      update_inventory();
  150.  
  151.      /* lastly, confer an extra skill slot/credit beyond the
  152.         up-to-29 you can get from gaining experience levels */
  153.      add_weapon_skill(1);
  154.      return;
  155.  }
  156.  

pleased

  1.  STATIC_OVL void
  2.  pleased(g_align)
  3.  aligntyp g_align;
  4.  {
  5.      /* don't use p_trouble, worst trouble may get fixed while praying */
  6.      int trouble = in_trouble(); /* what's your worst difficulty? */
  7.      int pat_on_head = 0, kick_on_butt;
  8.  
  9.      You_feel("that %s is %s.", align_gname(g_align),
  10.               (u.ualign.record >= DEVOUT)
  11.                   ? Hallucination ? "pleased as punch" : "well-pleased"
  12.                   : (u.ualign.record >= STRIDENT)
  13.                         ? Hallucination ? "ticklish" : "pleased"
  14.                         : Hallucination ? "full" : "satisfied");
  15.  
  16.      /* not your deity */
  17.      if (on_altar() && p_aligntyp != u.ualign.type) {
  18.          adjalign(-1);
  19.          return;
  20.      } else if (u.ualign.record < 2 && trouble <= 0)
  21.          adjalign(1);
  22.  
  23.      /*
  24.       * Depending on your luck & align level, the god you prayed to will:
  25.       *  - fix your worst problem if it's major;
  26.       *  - fix all your major problems;
  27.       *  - fix your worst problem if it's minor;
  28.       *  - fix all of your problems;
  29.       *  - do you a gratuitous favor.
  30.       *
  31.       * If you make it to the the last category, you roll randomly again
  32.       * to see what they do for you.
  33.       *
  34.       * If your luck is at least 0, then you are guaranteed rescued from
  35.       * your worst major problem.
  36.       */
  37.      if (!trouble && u.ualign.record >= DEVOUT) {
  38.          /* if hero was in trouble, but got better, no special favor */
  39.          if (p_trouble == 0)
  40.              pat_on_head = 1;
  41.      } else {
  42.          int action, prayer_luck;
  43.          int tryct = 0;
  44.  
  45.          /* Negative luck is normally impossible here (can_pray() forces
  46.             prayer failure in that situation), but it's possible for
  47.             Luck to drop during the period of prayer occupation and
  48.             become negative by the time we get here.  [Reported case
  49.             was lawful character whose stinking cloud caused a delayed
  50.             killing of a peaceful human, triggering the "murderer"
  51.             penalty while successful prayer was in progress.  It could
  52.             also happen due to inconvenient timing on Friday 13th, but
  53.             the magnitude there (-1) isn't big enough to cause trouble.]
  54.             We don't bother remembering start-of-prayer luck, just make
  55.             sure it's at least -1 so that Luck+2 is big enough to avoid
  56.             a divide by zero crash when generating a random number.  */
  57.          prayer_luck = max(Luck, -1); /* => (prayer_luck + 2 > 0) */
  58.          action = rn1(prayer_luck + (on_altar() ? 3 + on_shrine() : 2), 1);
  59.          if (!on_altar())
  60.              action = min(action, 3);
  61.          if (u.ualign.record < STRIDENT)
  62.              action = (u.ualign.record > 0 || !rnl(2)) ? 1 : 0;
  63.  
  64.          switch (min(action, 5)) {
  65.          case 5:
  66.              pat_on_head = 1;
  67.          case 4:
  68.              do
  69.                  fix_worst_trouble(trouble);
  70.              while ((trouble = in_trouble()) != 0);
  71.              break;
  72.  
  73.          case 3:
  74.              fix_worst_trouble(trouble);
  75.          case 2:
  76.              /* arbitrary number of tries */
  77.              while ((trouble = in_trouble()) > 0 && (++tryct < 10))
  78.                  fix_worst_trouble(trouble);
  79.              break;
  80.  
  81.          case 1:
  82.              if (trouble > 0)
  83.                  fix_worst_trouble(trouble);
  84.          case 0:
  85.              break; /* your god blows you off, too bad */
  86.          }
  87.      }
  88.  
  89.      /* note: can't get pat_on_head unless all troubles have just been
  90.         fixed or there were no troubles to begin with; hallucination
  91.         won't be in effect so special handling for it is superfluous */
  92.      if (pat_on_head)
  93.          switch (rn2((Luck + 6) >> 1)) {
  94.          case 0:
  95.              break;
  96.          case 1:
  97.              if (uwep && (welded(uwep) || uwep->oclass == WEAPON_CLASS
  98.                           || is_weptool(uwep))) {
  99.                  char repair_buf[BUFSZ];
  100.  
  101.                  *repair_buf = '\0';
  102.                  if (uwep->oeroded || uwep->oeroded2)
  103.                      Sprintf(repair_buf, " and %s now as good as new",
  104.                              otense(uwep, "are"));
  105.  
  106.                  if (uwep->cursed) {
  107.                      if (!Blind) {
  108.                          pline("%s %s%s.", Yobjnam2(uwep, "softly glow"),
  109.                                hcolor(NH_AMBER), repair_buf);
  110.                          iflags.last_msg = PLNMSG_OBJ_GLOWS;
  111.                      } else
  112.                          You_feel("the power of %s over %s.", u_gname(),
  113.                                   yname(uwep));
  114.                      uncurse(uwep);
  115.                      uwep->bknown = TRUE;
  116.                      *repair_buf = '\0';
  117.                  } else if (!uwep->blessed) {
  118.                      if (!Blind) {
  119.                          pline("%s with %s aura%s.",
  120.                                Yobjnam2(uwep, "softly glow"),
  121.                                an(hcolor(NH_LIGHT_BLUE)), repair_buf);
  122.                          iflags.last_msg = PLNMSG_OBJ_GLOWS;
  123.                      } else
  124.                          You_feel("the blessing of %s over %s.", u_gname(),
  125.                                   yname(uwep));
  126.                      bless(uwep);
  127.                      uwep->bknown = TRUE;
  128.                      *repair_buf = '\0';
  129.                  }
  130.  
  131.                  /* fix any rust/burn/rot damage, but don't protect
  132.                     against future damage */
  133.                  if (uwep->oeroded || uwep->oeroded2) {
  134.                      uwep->oeroded = uwep->oeroded2 = 0;
  135.                      /* only give this message if we didn't just bless
  136.                         or uncurse (which has already given a message) */
  137.                      if (*repair_buf)
  138.                          pline("%s as good as new!",
  139.                                Yobjnam2(uwep, Blind ? "feel" : "look"));
  140.                  }
  141.                  update_inventory();
  142.              }
  143.              break;
  144.          case 3:
  145.              /* takes 2 hints to get the music to enter the stronghold;
  146.                 skip if you've solved it via mastermind or destroyed the
  147.                 drawbridge (both set uopened_dbridge) or if you've already
  148.                 travelled past the Valley of the Dead (gehennom_entered) */
  149.              if (!u.uevent.uopened_dbridge && !u.uevent.gehennom_entered) {
  150.                  if (u.uevent.uheard_tune < 1) {
  151.                      godvoice(g_align, (char *) 0);
  152.                      verbalize("Hark, %s!", youmonst.data->mlet == S_HUMAN
  153.                                                 ? "mortal"
  154.                                                 : "creature");
  155.                      verbalize(
  156.                         "To enter the castle, thou must play the right tune!");
  157.                      u.uevent.uheard_tune++;
  158.                      break;
  159.                  } else if (u.uevent.uheard_tune < 2) {
  160.                      You_hear("a divine music...");
  161.                      pline("It sounds like:  \"%s\".", tune);
  162.                      u.uevent.uheard_tune++;
  163.                      break;
  164.                  }
  165.              }
  166.          /* Otherwise, falls into next case */
  167.          case 2:
  168.              if (!Blind)
  169.                  You("are surrounded by %s glow.", an(hcolor(NH_GOLDEN)));
  170.              /* if any levels have been lost (and not yet regained),
  171.                 treat this effect like blessed full healing */
  172.              if (u.ulevel < u.ulevelmax) {
  173.                  u.ulevelmax -= 1; /* see potion.c */
  174.                  pluslvl(FALSE);
  175.              } else {
  176.                  u.uhpmax += 5;
  177.                  if (Upolyd)
  178.                      u.mhmax += 5;
  179.              }
  180.              u.uhp = u.uhpmax;
  181.              if (Upolyd)
  182.                  u.mh = u.mhmax;
  183.              ABASE(A_STR) = AMAX(A_STR);
  184.              if (u.uhunger < 900)
  185.                  init_uhunger();
  186.              if (u.uluck < 0)
  187.                  u.uluck = 0;
  188.              make_blinded(0L, TRUE);
  189.              context.botl = 1;
  190.              break;
  191.          case 4: {
  192.              register struct obj *otmp;
  193.              int any = 0;
  194.  
  195.              if (Blind)
  196.                  You_feel("the power of %s.", u_gname());
  197.              else
  198.                  You("are surrounded by %s aura.", an(hcolor(NH_LIGHT_BLUE)));
  199.              for (otmp = invent; otmp; otmp = otmp->nobj) {
  200.                  if (otmp->cursed) {
  201.                      if (!Blind) {
  202.                          pline("%s %s.", Yobjnam2(otmp, "softly glow"),
  203.                                hcolor(NH_AMBER));
  204.                          iflags.last_msg = PLNMSG_OBJ_GLOWS;
  205.                          otmp->bknown = TRUE;
  206.                          ++any;
  207.                      }
  208.                      uncurse(otmp);
  209.                  }
  210.              }
  211.              if (any)
  212.                  update_inventory();
  213.              break;
  214.          }
  215.          case 5: {
  216.              static NEARDATA const char msg[] =
  217.                  "\"and thus I grant thee the gift of %s!\"";
  218.  
  219.              godvoice(u.ualign.type,
  220.                       "Thou hast pleased me with thy progress,");
  221.              if (!(HTelepat & INTRINSIC)) {
  222.                  HTelepat |= FROMOUTSIDE;
  223.                  pline(msg, "Telepathy");
  224.                  if (Blind)
  225.                      see_monsters();
  226.              } else if (!(HFast & INTRINSIC)) {
  227.                  HFast |= FROMOUTSIDE;
  228.                  pline(msg, "Speed");
  229.              } else if (!(HStealth & INTRINSIC)) {
  230.                  HStealth |= FROMOUTSIDE;
  231.                  pline(msg, "Stealth");
  232.              } else {
  233.                  if (!(HProtection & INTRINSIC)) {
  234.                      HProtection |= FROMOUTSIDE;
  235.                      if (!u.ublessed)
  236.                          u.ublessed = rn1(3, 2);
  237.                  } else
  238.                      u.ublessed++;
  239.                  pline(msg, "my protection");
  240.              }
  241.              verbalize("Use it wisely in my name!");
  242.              break;
  243.          }
  244.          case 7:
  245.          case 8:
  246.              if (u.ualign.record >= PIOUS && !u.uevent.uhand_of_elbereth) {
  247.                  gcrownu();
  248.                  break;
  249.              } /* else FALLTHRU */
  250.          case 6: {
  251.              struct obj *otmp;
  252.              int sp_no, trycnt = u.ulevel + 1;
  253.  
  254.              /* not yet known spells given preference over already known ones
  255.               */
  256.              /* Also, try to grant a spell for which there is a skill slot */
  257.              otmp = mkobj(SPBOOK_CLASS, TRUE);
  258.              while (--trycnt > 0) {
  259.                  if (otmp->otyp != SPE_BLANK_PAPER) {
  260.                      for (sp_no = 0; sp_no < MAXSPELL; sp_no++)
  261.                          if (spl_book[sp_no].sp_id == otmp->otyp)
  262.                              break;
  263.                      if (sp_no == MAXSPELL
  264.                          && !P_RESTRICTED(spell_skilltype(otmp->otyp)))
  265.                          break; /* usable, but not yet known */
  266.                  } else {
  267.                      if (!objects[SPE_BLANK_PAPER].oc_name_known
  268.                          || carrying(MAGIC_MARKER))
  269.                          break;
  270.                  }
  271.                  otmp->otyp = rnd_class(bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
  272.              }
  273.              bless(otmp);
  274.              at_your_feet("A spellbook");
  275.              place_object(otmp, u.ux, u.uy);
  276.              newsym(u.ux, u.uy);
  277.              break;
  278.          }
  279.          default:
  280.              impossible("Confused deity!");
  281.              break;
  282.          }
  283.  
  284.      u.ublesscnt = rnz(350);
  285.      kick_on_butt = u.uevent.udemigod ? 1 : 0;
  286.      if (u.uevent.uhand_of_elbereth)
  287.          kick_on_butt++;
  288.      if (kick_on_butt)
  289.          u.ublesscnt += kick_on_butt * rnz(1000);
  290.  
  291.      return;
  292.  }
  293.  

water_prayer

  1.  /* either blesses or curses water on the altar,
  2.   * returns true if it found any water here.
  3.   */
  4.  STATIC_OVL boolean
  5.  water_prayer(bless_water)
  6.  boolean bless_water;
  7.  {
  8.      register struct obj *otmp;
  9.      register long changed = 0;
  10.      boolean other = FALSE, bc_known = !(Blind || Hallucination);
  11.  
  12.      for (otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere) {
  13.          /* turn water into (un)holy water */
  14.          if (otmp->otyp == POT_WATER
  15.              && (bless_water ? !otmp->blessed : !otmp->cursed)) {
  16.              otmp->blessed = bless_water;
  17.              otmp->cursed = !bless_water;
  18.              otmp->bknown = bc_known;
  19.              changed += otmp->quan;
  20.          } else if (otmp->oclass == POTION_CLASS)
  21.              other = TRUE;
  22.      }
  23.      if (!Blind && changed) {
  24.          pline("%s potion%s on the altar glow%s %s for a moment.",
  25.                ((other && changed > 1L) ? "Some of the"
  26.                                         : (other ? "One of the" : "The")),
  27.                ((other || changed > 1L) ? "s" : ""), (changed > 1L ? "" : "s"),
  28.                (bless_water ? hcolor(NH_LIGHT_BLUE) : hcolor(NH_BLACK)));
  29.      }
  30.      return (boolean) (changed > 0L);
  31.  }
  32.  

godvoice

  1.  STATIC_OVL void
  2.  godvoice(g_align, words)
  3.  aligntyp g_align;
  4.  const char *words;
  5.  {
  6.      const char *quot = "";
  7.  
  8.      if (words)
  9.          quot = "\"";
  10.      else
  11.          words = "";
  12.  
  13.      pline_The("voice of %s %s: %s%s%s", align_gname(g_align),
  14.                godvoices[rn2(SIZE(godvoices))], quot, words, quot);
  15.  }
  16.  

gods_angry

  1.  STATIC_OVL void
  2.  gods_angry(g_align)
  3.  aligntyp g_align;
  4.  {
  5.      godvoice(g_align, "Thou hast angered me.");
  6.  }
  7.  

gods_upset

  1.  /* The g_align god is upset with you. */
  2.  STATIC_OVL void
  3.  gods_upset(g_align)
  4.  aligntyp g_align;
  5.  {
  6.      if (g_align == u.ualign.type)
  7.          u.ugangr++;
  8.      else if (u.ugangr)
  9.          u.ugangr--;
  10.      angrygods(g_align);
  11.  }
  12.  

consume_offering

  1.  STATIC_OVL void
  2.  consume_offering(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.      if (Hallucination)
  6.          switch (rn2(3)) {
  7.          case 0:
  8.              Your("sacrifice sprouts wings and a propeller and roars away!");
  9.              break;
  10.          case 1:
  11.              Your("sacrifice puffs up, swelling bigger and bigger, and pops!");
  12.              break;
  13.          case 2:
  14.              Your(
  15.       "sacrifice collapses into a cloud of dancing particles and fades away!");
  16.              break;
  17.          }
  18.      else if (Blind && u.ualign.type == A_LAWFUL)
  19.          Your("sacrifice disappears!");
  20.      else
  21.          Your("sacrifice is consumed in a %s!",
  22.               u.ualign.type == A_LAWFUL ? "flash of light" : "burst of flame");
  23.      if (carried(otmp))
  24.          useup(otmp);
  25.      else
  26.          useupf(otmp, 1L);
  27.      exercise(A_WIS, TRUE);
  28.  }
  29.  

dosacrifice

  1.  int
  2.  dosacrifice()
  3.  {
  4.      static NEARDATA const char cloud_of_smoke[] =
  5.          "A cloud of %s smoke surrounds you...";
  6.      register struct obj *otmp;
  7.      int value = 0, pm;
  8.      boolean highaltar;
  9.      aligntyp altaralign = a_align(u.ux, u.uy);
  10.  
  11.      if (!on_altar() || u.uswallow) {
  12.          You("are not standing on an altar.");
  13.          return 0;
  14.      }
  15.      highaltar = ((Is_astralevel(&u.uz) || Is_sanctum(&u.uz))
  16.                   && (levl[u.ux][u.uy].altarmask & AM_SHRINE));
  17.  
  18.      otmp = floorfood("sacrifice", 1);
  19.      if (!otmp)
  20.          return 0;
  21.      /*
  22.       * Was based on nutritional value and aging behavior (< 50 moves).
  23.       * Sacrificing a food ration got you max luck instantly, making the
  24.       * gods as easy to please as an angry dog!
  25.       *
  26.       * Now only accepts corpses, based on the game's evaluation of their
  27.       * toughness.  Human and pet sacrifice, as well as sacrificing unicorns
  28.       * of your alignment, is strongly discouraged.
  29.       */
  30.  #define MAXVALUE 24 /* Highest corpse value (besides Wiz) */
  31.  
  32.      if (otmp->otyp == CORPSE) {
  33.          register struct permonst *ptr = &mons[otmp->corpsenm];
  34.          struct monst *mtmp;
  35.          extern const int monstr[];
  36.  
  37.          /* KMH, conduct */
  38.          u.uconduct.gnostic++;
  39.  
  40.          /* you're handling this corpse, even if it was killed upon the altar
  41.           */
  42.          feel_cockatrice(otmp, TRUE);
  43.          if (rider_corpse_revival(otmp, FALSE))
  44.              return 1;
  45.  
  46.          if (otmp->corpsenm == PM_ACID_BLOB
  47.              || (monstermoves <= peek_at_iced_corpse_age(otmp) + 50)) {
  48.              value = monstr[otmp->corpsenm] + 1;
  49.              if (otmp->oeaten)
  50.                  value = eaten_stat(value, otmp);
  51.          }
  52.  
  53.          if (your_race(ptr)) {
  54.              if (is_demon(youmonst.data)) {
  55.                  You("find the idea very satisfying.");
  56.                  exercise(A_WIS, TRUE);
  57.              } else if (u.ualign.type != A_CHAOTIC) {
  58.                  pline("You'll regret this infamous offense!");
  59.                  exercise(A_WIS, FALSE);
  60.              }
  61.  
  62.              if (highaltar
  63.                  && (altaralign != A_CHAOTIC || u.ualign.type != A_CHAOTIC)) {
  64.                  goto desecrate_high_altar;
  65.              } else if (altaralign != A_CHAOTIC && altaralign != A_NONE) {
  66.                  /* curse the lawful/neutral altar */
  67.                  pline_The("altar is stained with %s blood.", urace.adj);
  68.                  levl[u.ux][u.uy].altarmask = AM_CHAOTIC;
  69.                  angry_priest();
  70.              } else {
  71.                  struct monst *dmon;
  72.                  const char *demonless_msg;
  73.  
  74.                  /* Human sacrifice on a chaotic or unaligned altar */
  75.                  /* is equivalent to demon summoning */
  76.                  if (altaralign == A_CHAOTIC && u.ualign.type != A_CHAOTIC) {
  77.                      pline(
  78.                      "The blood floods the altar, which vanishes in %s cloud!",
  79.                            an(hcolor(NH_BLACK)));
  80.                      levl[u.ux][u.uy].typ = ROOM;
  81.                      levl[u.ux][u.uy].altarmask = 0;
  82.                      newsym(u.ux, u.uy);
  83.                      angry_priest();
  84.                      demonless_msg = "cloud dissipates";
  85.                  } else {
  86.                      /* either you're chaotic or altar is Moloch's or both */
  87.                      pline_The("blood covers the altar!");
  88.                      change_luck(altaralign == A_NONE ? -2 : 2);
  89.                      demonless_msg = "blood coagulates";
  90.                  }
  91.                  if ((pm = dlord(altaralign)) != NON_PM
  92.                      && (dmon = makemon(&mons[pm], u.ux, u.uy, NO_MM_FLAGS))
  93.                             != 0) {
  94.                      char dbuf[BUFSZ];
  95.  
  96.                      Strcpy(dbuf, a_monnam(dmon));
  97.                      if (!strcmpi(dbuf, "it"))
  98.                          Strcpy(dbuf, "something dreadful");
  99.                      else
  100.                          dmon->mstrategy &= ~STRAT_APPEARMSG;
  101.                      You("have summoned %s!", dbuf);
  102.                      if (sgn(u.ualign.type) == sgn(dmon->data->maligntyp))
  103.                          dmon->mpeaceful = TRUE;
  104.                      You("are terrified, and unable to move.");
  105.                      nomul(-3);
  106.                      multi_reason = "being terrified of a demon";
  107.                      nomovemsg = 0;
  108.                  } else
  109.                      pline_The("%s.", demonless_msg);
  110.              }
  111.  
  112.              if (u.ualign.type != A_CHAOTIC) {
  113.                  adjalign(-5);
  114.                  u.ugangr += 3;
  115.                  (void) adjattrib(A_WIS, -1, TRUE);
  116.                  if (!Inhell)
  117.                      angrygods(u.ualign.type);
  118.                  change_luck(-5);
  119.              } else
  120.                  adjalign(5);
  121.              if (carried(otmp))
  122.                  useup(otmp);
  123.              else
  124.                  useupf(otmp, 1L);
  125.              return 1;
  126.          } else if (has_omonst(otmp)
  127.                     && (mtmp = get_mtraits(otmp, FALSE)) != 0
  128.                     && mtmp->mtame) {
  129.                  /* mtmp is a temporary pointer to a tame monster's attributes,
  130.                   * not a real monster */
  131.              pline("So this is how you repay loyalty?");
  132.              adjalign(-3);
  133.              value = -1;
  134.              HAggravate_monster |= FROMOUTSIDE;
  135.          } else if (is_undead(ptr)) { /* Not demons--no demon corpses */
  136.              if (u.ualign.type != A_CHAOTIC)
  137.                  value += 1;
  138.          } else if (is_unicorn(ptr)) {
  139.              int unicalign = sgn(ptr->maligntyp);
  140.  
  141.              if (unicalign == altaralign) {
  142.                  /* When same as altar, always a very bad action.
  143.                   */
  144.                  pline("Such an action is an insult to %s!",
  145.                        (unicalign == A_CHAOTIC) ? "chaos"
  146.                           : unicalign ? "law" : "balance");
  147.                  (void) adjattrib(A_WIS, -1, TRUE);
  148.                  value = -5;
  149.              } else if (u.ualign.type == altaralign) {
  150.                  /* When different from altar, and altar is same as yours,
  151.                   * it's a very good action.
  152.                   */
  153.                  if (u.ualign.record < ALIGNLIM)
  154.                      You_feel("appropriately %s.", align_str(u.ualign.type));
  155.                  else
  156.                      You_feel("you are thoroughly on the right path.");
  157.                  adjalign(5);
  158.                  value += 3;
  159.              } else if (unicalign == u.ualign.type) {
  160.                  /* When sacrificing unicorn of your alignment to altar not of
  161.                   * your alignment, your god gets angry and it's a conversion.
  162.                   */
  163.                  u.ualign.record = -1;
  164.                  value = 1;
  165.              } else {
  166.                  /* Otherwise, unicorn's alignment is different from yours
  167.                   * and different from the altar's.  It's an ordinary (well,
  168.                   * with a bonus) sacrifice on a cross-aligned altar.
  169.                   */
  170.                  value += 3;
  171.              }
  172.          }
  173.      } /* corpse */
  174.  
  175.      if (otmp->otyp == AMULET_OF_YENDOR) {
  176.          if (!highaltar) {
  177.          too_soon:
  178.              if (altaralign == A_NONE && Inhell)
  179.                  /* hero has left Moloch's Sanctum so is in the process
  180.                     of getting away with the Amulet (outside of Gehennom,
  181.                     fall through to the "ashamed" feedback) */
  182.                  gods_upset(A_NONE);
  183.              else
  184.                  You_feel("%s.",
  185.                           Hallucination
  186.                              ? "homesick"
  187.                              /* if on track, give a big hint */
  188.                              : (altaralign == u.ualign.type)
  189.                                 ? "an urge to return to the surface"
  190.                                 /* else headed towards celestial disgrace */
  191.                                 : "ashamed");
  192.              return 1;
  193.          } else {
  194.              /* The final Test.  Did you win? */
  195.              if (uamul == otmp)
  196.                  Amulet_off();
  197.              u.uevent.ascended = 1;
  198.              if (carried(otmp))
  199.                  useup(otmp); /* well, it's gone now */
  200.              else
  201.                  useupf(otmp, 1L);
  202.              You("offer the Amulet of Yendor to %s...", a_gname());
  203.              if (altaralign == A_NONE) {
  204.                  /* Moloch's high altar */
  205.                  if (u.ualign.record > -99)
  206.                      u.ualign.record = -99;
  207.                  /*[apparently shrug/snarl can be sensed without being seen]*/
  208.                  pline("%s shrugs and retains dominion over %s,", Moloch,
  209.                        u_gname());
  210.                  pline("then mercilessly snuffs out your life.");
  211.                  Sprintf(killer.name, "%s indifference", s_suffix(Moloch));
  212.                  killer.format = KILLED_BY;
  213.                  done(DIED);
  214.                  /* life-saved (or declined to die in wizard/explore mode) */
  215.                  pline("%s snarls and tries again...", Moloch);
  216.                  fry_by_god(A_NONE, TRUE); /* wrath of Moloch */
  217.                  /* declined to die in wizard or explore mode */
  218.                  pline(cloud_of_smoke, hcolor(NH_BLACK));
  219.                  done(ESCAPED);
  220.              } else if (u.ualign.type != altaralign) {
  221.                  /* And the opposing team picks you up and
  222.                     carries you off on their shoulders */
  223.                  adjalign(-99);
  224.                  pline("%s accepts your gift, and gains dominion over %s...",
  225.                        a_gname(), u_gname());
  226.                  pline("%s is enraged...", u_gname());
  227.                  pline("Fortunately, %s permits you to live...", a_gname());
  228.                  pline(cloud_of_smoke, hcolor(NH_ORANGE));
  229.                  done(ESCAPED);
  230.              } else { /* super big win */
  231.                  adjalign(10);
  232.                  u.uachieve.ascended = 1;
  233.                  pline(
  234.                 "An invisible choir sings, and you are bathed in radiance...");
  235.                  godvoice(altaralign, "Congratulations, mortal!");
  236.                  display_nhwindow(WIN_MESSAGE, FALSE);
  237.                  verbalize(
  238.            "In return for thy service, I grant thee the gift of Immortality!");
  239.                  You("ascend to the status of Demigod%s...",
  240.                      flags.female ? "dess" : "");
  241.                  done(ASCENDED);
  242.              }
  243.          }
  244.      } /* real Amulet */
  245.  
  246.      if (otmp->otyp == FAKE_AMULET_OF_YENDOR) {
  247.          if (!highaltar && !otmp->known)
  248.              goto too_soon;
  249.          You_hear("a nearby thunderclap.");
  250.          if (!otmp->known) {
  251.              You("realize you have made a %s.",
  252.                  Hallucination ? "boo-boo" : "mistake");
  253.              otmp->known = TRUE;
  254.              change_luck(-1);
  255.              return 1;
  256.          } else {
  257.              /* don't you dare try to fool the gods */
  258.              if (Deaf)
  259.                  pline("Oh, no."); /* didn't hear thunderclap */
  260.              change_luck(-3);
  261.              adjalign(-1);
  262.              u.ugangr += 3;
  263.              value = -3;
  264.          }
  265.      } /* fake Amulet */
  266.  
  267.      if (value == 0) {
  268.          pline1(nothing_happens);
  269.          return 1;
  270.      }
  271.  
  272.      if (altaralign != u.ualign.type && highaltar) {
  273.      desecrate_high_altar:
  274.          /*
  275.           * REAL BAD NEWS!!! High altars cannot be converted.  Even an attempt
  276.           * gets the god who owns it truly pissed off.
  277.           */
  278.          You_feel("the air around you grow charged...");
  279.          pline("Suddenly, you realize that %s has noticed you...", a_gname());
  280.          godvoice(altaralign,
  281.                   "So, mortal!  You dare desecrate my High Temple!");
  282.          /* Throw everything we have at the player */
  283.          god_zaps_you(altaralign);
  284.      } else if (value
  285.                 < 0) { /* I don't think the gods are gonna like this... */
  286.          gods_upset(altaralign);
  287.      } else {
  288.          int saved_anger = u.ugangr;
  289.          int saved_cnt = u.ublesscnt;
  290.          int saved_luck = u.uluck;
  291.  
  292.          /* Sacrificing at an altar of a different alignment */
  293.          if (u.ualign.type != altaralign) {
  294.              /* Is this a conversion ? */
  295.              /* An unaligned altar in Gehennom will always elicit rejection. */
  296.              if (ugod_is_angry() || (altaralign == A_NONE && Inhell)) {
  297.                  if (u.ualignbase[A_CURRENT] == u.ualignbase[A_ORIGINAL]
  298.                      && altaralign != A_NONE) {
  299.                      You("have a strong feeling that %s is angry...",
  300.                          u_gname());
  301.                      consume_offering(otmp);
  302.                      pline("%s accepts your allegiance.", a_gname());
  303.  
  304.                      uchangealign(altaralign, 0);
  305.                      /* Beware, Conversion is costly */
  306.                      change_luck(-3);
  307.                      u.ublesscnt += 300;
  308.                  } else {
  309.                      u.ugangr += 3;
  310.                      adjalign(-5);
  311.                      pline("%s rejects your sacrifice!", a_gname());
  312.                      godvoice(altaralign, "Suffer, infidel!");
  313.                      change_luck(-5);
  314.                      (void) adjattrib(A_WIS, -2, TRUE);
  315.                      if (!Inhell)
  316.                          angrygods(u.ualign.type);
  317.                  }
  318.                  return 1;
  319.              } else {
  320.                  consume_offering(otmp);
  321.                  You("sense a conflict between %s and %s.", u_gname(),
  322.                      a_gname());
  323.                  if (rn2(8 + u.ulevel) > 5) {
  324.                      struct monst *pri;
  325.                      You_feel("the power of %s increase.", u_gname());
  326.                      exercise(A_WIS, TRUE);
  327.                      change_luck(1);
  328.                      /* Yes, this is supposed to be &=, not |= */
  329.                      levl[u.ux][u.uy].altarmask &= AM_SHRINE;
  330.                      /* the following accommodates stupid compilers */
  331.                      levl[u.ux][u.uy].altarmask =
  332.                          levl[u.ux][u.uy].altarmask
  333.                          | (Align2amask(u.ualign.type));
  334.                      if (!Blind)
  335.                          pline_The("altar glows %s.",
  336.                                    hcolor((u.ualign.type == A_LAWFUL)
  337.                                              ? NH_WHITE
  338.                                              : u.ualign.type
  339.                                                 ? NH_BLACK
  340.                                                 : (const char *) "gray"));
  341.  
  342.                      if (rnl(u.ulevel) > 6 && u.ualign.record > 0
  343.                          && rnd(u.ualign.record) > (3 * ALIGNLIM) / 4)
  344.                          summon_minion(altaralign, TRUE);
  345.                      /* anger priest; test handles bones files */
  346.                      if ((pri = findpriest(temple_occupied(u.urooms)))
  347.                          && !p_coaligned(pri))
  348.                          angry_priest();
  349.                  } else {
  350.                      pline("Unluckily, you feel the power of %s decrease.",
  351.                            u_gname());
  352.                      change_luck(-1);
  353.                      exercise(A_WIS, FALSE);
  354.                      if (rnl(u.ulevel) > 6 && u.ualign.record > 0
  355.                          && rnd(u.ualign.record) > (7 * ALIGNLIM) / 8)
  356.                          summon_minion(altaralign, TRUE);
  357.                  }
  358.                  return 1;
  359.              }
  360.          }
  361.  
  362.          consume_offering(otmp);
  363.          /* OK, you get brownie points. */
  364.          if (u.ugangr) {
  365.              u.ugangr -= ((value * (u.ualign.type == A_CHAOTIC ? 2 : 3))
  366.                           / MAXVALUE);
  367.              if (u.ugangr < 0)
  368.                  u.ugangr = 0;
  369.              if (u.ugangr != saved_anger) {
  370.                  if (u.ugangr) {
  371.                      pline("%s seems %s.", u_gname(),
  372.                            Hallucination ? "groovy" : "slightly mollified");
  373.  
  374.                      if ((int) u.uluck < 0)
  375.                          change_luck(1);
  376.                  } else {
  377.                      pline("%s seems %s.", u_gname(),
  378.                            Hallucination ? "cosmic (not a new fact)"
  379.                                          : "mollified");
  380.  
  381.                      if ((int) u.uluck < 0)
  382.                          u.uluck = 0;
  383.                  }
  384.              } else { /* not satisfied yet */
  385.                  if (Hallucination)
  386.                      pline_The("gods seem tall.");
  387.                  else
  388.                      You("have a feeling of inadequacy.");
  389.              }
  390.          } else if (ugod_is_angry()) {
  391.              if (value > MAXVALUE)
  392.                  value = MAXVALUE;
  393.              if (value > -u.ualign.record)
  394.                  value = -u.ualign.record;
  395.              adjalign(value);
  396.              You_feel("partially absolved.");
  397.          } else if (u.ublesscnt > 0) {
  398.              u.ublesscnt -= ((value * (u.ualign.type == A_CHAOTIC ? 500 : 300))
  399.                              / MAXVALUE);
  400.              if (u.ublesscnt < 0)
  401.                  u.ublesscnt = 0;
  402.              if (u.ublesscnt != saved_cnt) {
  403.                  if (u.ublesscnt) {
  404.                      if (Hallucination)
  405.                          You("realize that the gods are not like you and I.");
  406.                      else
  407.                          You("have a hopeful feeling.");
  408.                      if ((int) u.uluck < 0)
  409.                          change_luck(1);
  410.                  } else {
  411.                      if (Hallucination)
  412.                          pline("Overall, there is a smell of fried onions.");
  413.                      else
  414.                          You("have a feeling of reconciliation.");
  415.                      if ((int) u.uluck < 0)
  416.                          u.uluck = 0;
  417.                  }
  418.              }
  419.          } else {
  420.              int nartifacts = nartifact_exist();
  421.  
  422.              /* you were already in pretty good standing */
  423.              /* The player can gain an artifact */
  424.              /* The chance goes down as the number of artifacts goes up */
  425.              if (u.ulevel > 2 && u.uluck >= 0
  426.                  && !rn2(10 + (2 * u.ugifts * nartifacts))) {
  427.                  otmp = mk_artifact((struct obj *) 0, a_align(u.ux, u.uy));
  428.                  if (otmp) {
  429.                      if (otmp->spe < 0)
  430.                          otmp->spe = 0;
  431.                      if (otmp->cursed)
  432.                          uncurse(otmp);
  433.                      otmp->oerodeproof = TRUE;
  434.                      at_your_feet("An object");
  435.                      dropy(otmp);
  436.                      godvoice(u.ualign.type, "Use my gift wisely!");
  437.                      u.ugifts++;
  438.                      u.ublesscnt = rnz(300 + (50 * nartifacts));
  439.                      exercise(A_WIS, TRUE);
  440.                      /* make sure we can use this weapon */
  441.                      unrestrict_weapon_skill(weapon_type(otmp));
  442.                      if (!Hallucination && !Blind) {
  443.                          otmp->dknown = 1;
  444.                          makeknown(otmp->otyp);
  445.                          discover_artifact(otmp->oartifact);
  446.                      }
  447.                      return 1;
  448.                  }
  449.              }
  450.              change_luck((value * LUCKMAX) / (MAXVALUE * 2));
  451.              if ((int) u.uluck < 0)
  452.                  u.uluck = 0;
  453.              if (u.uluck != saved_luck) {
  454.                  if (Blind)
  455.                      You("think %s brushed your %s.", something,
  456.                          body_part(FOOT));
  457.                  else
  458.                      You(Hallucination
  459.                      ? "see crabgrass at your %s.  A funny thing in a dungeon."
  460.                              : "glimpse a four-leaf clover at your %s.",
  461.                          makeplural(body_part(FOOT)));
  462.              }
  463.          }
  464.      }
  465.      return 1;
  466.  }
  467.  

can_pray

  1.  /* determine prayer results in advance; also used for enlightenment */
  2.  boolean
  3.  can_pray(praying)
  4.  boolean praying; /* false means no messages should be given */
  5.  {
  6.      int alignment;
  7.  
  8.      p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
  9.      p_trouble = in_trouble();
  10.  
  11.      if (is_demon(youmonst.data) && (p_aligntyp != A_CHAOTIC)) {
  12.          if (praying)
  13.              pline_The("very idea of praying to a %s god is repugnant to you.",
  14.                        p_aligntyp ? "lawful" : "neutral");
  15.          return FALSE;
  16.      }
  17.  
  18.      if (praying)
  19.          You("begin praying to %s.", align_gname(p_aligntyp));
  20.  
  21.      if (u.ualign.type && u.ualign.type == -p_aligntyp)
  22.          alignment = -u.ualign.record; /* Opposite alignment altar */
  23.      else if (u.ualign.type != p_aligntyp)
  24.          alignment = u.ualign.record / 2; /* Different alignment altar */
  25.      else
  26.          alignment = u.ualign.record;
  27.  
  28.      if ((p_trouble > 0) ? (u.ublesscnt > 200)      /* big trouble */
  29.             : (p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulties */
  30.                : (u.ublesscnt > 0))                 /* not in trouble */
  31.          p_type = 0;                     /* too soon... */
  32.      else if ((int) Luck < 0 || u.ugangr || alignment < 0)
  33.          p_type = 1; /* too naughty... */
  34.      else /* alignment >= 0 */ {
  35.          if (on_altar() && u.ualign.type != p_aligntyp)
  36.              p_type = 2;
  37.          else
  38.              p_type = 3;
  39.      }
  40.  
  41.      if (is_undead(youmonst.data) && !Inhell
  42.          && (p_aligntyp == A_LAWFUL || (p_aligntyp == A_NEUTRAL && !rn2(10))))
  43.          p_type = -1;
  44.      /* Note:  when !praying, the random factor for neutrals makes the
  45.         return value a non-deterministic approximation for enlightenment.
  46.         This case should be uncommon enough to live with... */
  47.  
  48.      return !praying ? (boolean) (p_type == 3 && !Inhell) : TRUE;
  49.  }
  50.  

dopray

  1.  /* #pray commmand */
  2.  int
  3.  dopray()
  4.  {
  5.      /* Confirm accidental slips of Alt-P */
  6.      if (ParanoidPray && yn("Are you sure you want to pray?") != 'y')
  7.          return 0;
  8.  
  9.      u.uconduct.gnostic++;
  10.  
  11.      /* set up p_type and p_alignment */
  12.      if (!can_pray(TRUE))
  13.          return 0;
  14.  
  15.      if (wizard && p_type >= 0) {
  16.          if (yn("Force the gods to be pleased?") == 'y') {
  17.              u.ublesscnt = 0;
  18.              if (u.uluck < 0)
  19.                  u.uluck = 0;
  20.              if (u.ualign.record <= 0)
  21.                  u.ualign.record = 1;
  22.              u.ugangr = 0;
  23.              if (p_type < 2)
  24.                  p_type = 3;
  25.          }
  26.      }
  27.      nomul(-3);
  28.      multi_reason = "praying";
  29.      nomovemsg = "You finish your prayer.";
  30.      afternmv = prayer_done;
  31.  
  32.      if (p_type == 3 && !Inhell) {
  33.          /* if you've been true to your god you can't die while you pray */
  34.          if (!Blind)
  35.              You("are surrounded by a shimmering light.");
  36.          u.uinvulnerable = TRUE;
  37.      }
  38.  
  39.      return 1;
  40.  }
  41.  

prayer_done

  1.  STATIC_PTR int
  2.  prayer_done() /* M. Stephenson (1.0.3b) */
  3.  {
  4.      aligntyp alignment = p_aligntyp;
  5.  
  6.      u.uinvulnerable = FALSE;
  7.      if (p_type == -1) {
  8.          godvoice(alignment,
  9.                   (alignment == A_LAWFUL)
  10.                      ? "Vile creature, thou durst call upon me?"
  11.                      : "Walk no more, perversion of nature!");
  12.          You_feel("like you are falling apart.");
  13.          /* KMH -- Gods have mastery over unchanging */
  14.          rehumanize();
  15.          /* no Half_physical_damage adjustment here */
  16.          losehp(rnd(20), "residual undead turning effect", KILLED_BY_AN);
  17.          exercise(A_CON, FALSE);
  18.          return 1;
  19.      }
  20.      if (Inhell) {
  21.          pline("Since you are in Gehennom, %s won't help you.",
  22.                align_gname(alignment));
  23.          /* haltingly aligned is least likely to anger */
  24.          if (u.ualign.record <= 0 || rnl(u.ualign.record))
  25.              angrygods(u.ualign.type);
  26.          return 0;
  27.      }
  28.  
  29.      if (p_type == 0) {
  30.          if (on_altar() && u.ualign.type != alignment)
  31.              (void) water_prayer(FALSE);
  32.          u.ublesscnt += rnz(250);
  33.          change_luck(-3);
  34.          gods_upset(u.ualign.type);
  35.      } else if (p_type == 1) {
  36.          if (on_altar() && u.ualign.type != alignment)
  37.              (void) water_prayer(FALSE);
  38.          angrygods(u.ualign.type); /* naughty */
  39.      } else if (p_type == 2) {
  40.          if (water_prayer(FALSE)) {
  41.              /* attempted water prayer on a non-coaligned altar */
  42.              u.ublesscnt += rnz(250);
  43.              change_luck(-3);
  44.              gods_upset(u.ualign.type);
  45.          } else
  46.              pleased(alignment);
  47.      } else {
  48.          /* coaligned */
  49.          if (on_altar())
  50.              (void) water_prayer(TRUE);
  51.          pleased(alignment); /* nice */
  52.      }
  53.      return 1;
  54.  }
  55.  

doturn

  1.  /* #turn command */
  2.  int
  3.  doturn()
  4.  {
  5.      /* Knights & Priest(esse)s only please */
  6.      struct monst *mtmp, *mtmp2;
  7.      int once, range, xlev;
  8.  
  9.      if (!Role_if(PM_PRIEST) && !Role_if(PM_KNIGHT)) {
  10.          /* Try to use the "turn undead" spell.
  11.           *
  12.           * This used to be based on whether hero knows the name of the
  13.           * turn undead spellbook, but it's possible to know--and be able
  14.           * to cast--the spell while having lost the book ID to amnesia.
  15.           * (It also used to tell spelleffects() to cast at self?)
  16.           */
  17.          int sp_no;
  18.  
  19.          for (sp_no = 0; sp_no < MAXSPELL; ++sp_no) {
  20.              if (spl_book[sp_no].sp_id == NO_SPELL)
  21.                  break;
  22.              else if (spl_book[sp_no].sp_id == SPE_TURN_UNDEAD)
  23.                  return spelleffects(sp_no, FALSE);
  24.          }
  25.          You("don't know how to turn undead!");
  26.          return 0;
  27.      }
  28.      u.uconduct.gnostic++;
  29.  
  30.      if ((u.ualign.type != A_CHAOTIC
  31.           && (is_demon(youmonst.data) || is_undead(youmonst.data)))
  32.          || u.ugangr > 6) { /* "Die, mortal!" */
  33.          pline("For some reason, %s seems to ignore you.", u_gname());
  34.          aggravate();
  35.          exercise(A_WIS, FALSE);
  36.          return 0;
  37.      }
  38.      if (Inhell) {
  39.          pline("Since you are in Gehennom, %s won't help you.", u_gname());
  40.          aggravate();
  41.          return 0;
  42.      }
  43.      pline("Calling upon %s, you chant an arcane formula.", u_gname());
  44.      exercise(A_WIS, TRUE);
  45.  
  46.      /* note: does not perform unturn_dead() on victims' inventories */
  47.      range = BOLT_LIM + (u.ulevel / 5); /* 5 to 11 */
  48.      range *= range;
  49.      once = 0;
  50.      for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  51.          mtmp2 = mtmp->nmon;
  52.  
  53.          if (DEADMONSTER(mtmp))
  54.              continue;
  55.          if (!cansee(mtmp->mx, mtmp->my) || distu(mtmp->mx, mtmp->my) > range)
  56.              continue;
  57.  
  58.          if (!mtmp->mpeaceful
  59.              && (is_undead(mtmp->data) || is_vampshifter(mtmp)
  60.                  || (is_demon(mtmp->data) && (u.ulevel > (MAXULEV / 2))))) {
  61.              mtmp->msleeping = 0;
  62.              if (Confusion) {
  63.                  if (!once++)
  64.                      pline("Unfortunately, your voice falters.");
  65.                  mtmp->mflee = 0;
  66.                  mtmp->mfrozen = 0;
  67.                  mtmp->mcanmove = 1;
  68.              } else if (!resist(mtmp, '\0', 0, TELL)) {
  69.                  xlev = 6;
  70.                  switch (mtmp->data->mlet) {
  71.                  /* this is intentional, lichs are tougher
  72.                     than zombies. */
  73.                  case S_LICH:
  74.                      xlev += 2; /*FALLTHRU*/
  75.                  case S_GHOST:
  76.                      xlev += 2; /*FALLTHRU*/
  77.                  case S_VAMPIRE:
  78.                      xlev += 2; /*FALLTHRU*/
  79.                  case S_WRAITH:
  80.                      xlev += 2; /*FALLTHRU*/
  81.                  case S_MUMMY:
  82.                      xlev += 2; /*FALLTHRU*/
  83.                  case S_ZOMBIE:
  84.                      if (u.ulevel >= xlev && !resist(mtmp, '\0', 0, NOTELL)) {
  85.                          if (u.ualign.type == A_CHAOTIC) {
  86.                              mtmp->mpeaceful = 1;
  87.                              set_malign(mtmp);
  88.                          } else { /* damn them */
  89.                              killed(mtmp);
  90.                          }
  91.                          break;
  92.                      } /* else flee */
  93.                  /*FALLTHRU*/
  94.                  default:
  95.                      monflee(mtmp, 0, FALSE, TRUE);
  96.                      break;
  97.                  }
  98.              }
  99.          }
  100.      }
  101.      nomul(-5);
  102.      multi_reason = "trying to turn the monsters";
  103.      nomovemsg = You_can_move_again;
  104.      return 1;
  105.  }
  106.  

a_gname

  1.  const char *
  2.  a_gname()
  3.  {
  4.      return a_gname_at(u.ux, u.uy);
  5.  }
  6.  

a_gname_at

  1.  /* returns the name of an altar's deity */
  2.  const char *
  3.  a_gname_at(x, y)
  4.  xchar x, y;
  5.  {
  6.      if (!IS_ALTAR(levl[x][y].typ))
  7.          return (char *) 0;
  8.  
  9.      return align_gname(a_align(x, y));
  10.  }
  11.  

u_gname

  1.  /* returns the name of the hero's deity */
  2.  const char *
  3.  u_gname()
  4.  {
  5.      return align_gname(u.ualign.type);
  6.  }
  7.  

align_gname

  1.  const char *
  2.  align_gname(alignment)
  3.  aligntyp alignment;
  4.  {
  5.      const char *gnam;
  6.  
  7.      switch (alignment) {
  8.      case A_NONE:
  9.          gnam = Moloch;
  10.          break;
  11.      case A_LAWFUL:
  12.          gnam = urole.lgod;
  13.          break;
  14.      case A_NEUTRAL:
  15.          gnam = urole.ngod;
  16.          break;
  17.      case A_CHAOTIC:
  18.          gnam = urole.cgod;
  19.          break;
  20.      default:
  21.          impossible("unknown alignment.");
  22.          gnam = "someone";
  23.          break;
  24.      }
  25.      if (*gnam == '_')
  26.          ++gnam;
  27.      return gnam;
  28.  }
  29.  

halu_gname

  1.  static const char *hallu_gods[] = {
  2.      "the Flying Spaghetti Monster", /* Church of the FSM */
  3.      "Eris",                         /* Discordianism */
  4.      "the Martians",                 /* every science fiction ever */
  5.      "Xom",                          /* Crawl */
  6.      "AnDoR dRaKoN",                 /* ADOM */
  7.      "the Central Bank of Yendor",   /* economics */
  8.      "Tooth Fairy",                  /* real world(?) */
  9.      "Om",                           /* Discworld */
  10.      "Yawgmoth",                     /* Magic: the Gathering */
  11.      "Morgoth",                      /* LoTR */
  12.      "Cthulhu",                      /* Lovecraft */
  13.      "the Ori",                      /* Stargate */
  14.      "destiny",                      /* why not? */
  15.      "your Friend the Computer",     /* Paranoia */
  16.  };
  17.  
  18.  /* hallucination handling for priest/minion names: select a random god
  19.     iff character is hallucinating */
  20.  const char *
  21.  halu_gname(alignment)
  22.  aligntyp alignment;
  23.  {
  24.      const char *gnam = NULL;
  25.      int which;
  26.  
  27.      if (!Hallucination)
  28.          return align_gname(alignment);
  29.  
  30.      /* The priest may not have initialized god names. If this is the
  31.       * case, and we roll priest, we need to try again. */
  32.      do
  33.          which = randrole();
  34.      while (!roles[which].lgod);
  35.  
  36.      switch (rn2(9)) {
  37.      case 0:
  38.      case 1:
  39.          gnam = roles[which].lgod;
  40.          break;
  41.      case 2:
  42.      case 3:
  43.          gnam = roles[which].ngod;
  44.          break;
  45.      case 4:
  46.      case 5:
  47.          gnam = roles[which].cgod;
  48.          break;
  49.      case 6:
  50.      case 7:
  51.          gnam = hallu_gods[rn2(sizeof hallu_gods / sizeof *hallu_gods)];
  52.          break;
  53.      case 8:
  54.          gnam = Moloch;
  55.          break;
  56.      default:
  57.          impossible("rn2 broken in halu_gname?!?");
  58.      }
  59.      if (!gnam) {
  60.          impossible("No random god name?");
  61.          gnam = "your Friend the Computer"; /* Paranoia */
  62.      }
  63.      if (*gnam == '_')
  64.          ++gnam;
  65.      return gnam;
  66.  }
  67.  

align_gtitle

  1.  /* deity's title */
  2.  const char *
  3.  align_gtitle(alignment)
  4.  aligntyp alignment;
  5.  {
  6.      const char *gnam, *result = "god";
  7.  
  8.      switch (alignment) {
  9.      case A_LAWFUL:
  10.          gnam = urole.lgod;
  11.          break;
  12.      case A_NEUTRAL:
  13.          gnam = urole.ngod;
  14.          break;
  15.      case A_CHAOTIC:
  16.          gnam = urole.cgod;
  17.          break;
  18.      default:
  19.          gnam = 0;
  20.          break;
  21.      }
  22.      if (gnam && *gnam == '_')
  23.          result = "goddess";
  24.      return result;
  25.  }
  26.  

altar_wrath

  1.  void
  2.  altar_wrath(x, y)
  3.  register int x, y;
  4.  {
  5.      aligntyp altaralign = a_align(x, y);
  6.  
  7.      if (!strcmp(align_gname(altaralign), u_gname())) {
  8.          godvoice(altaralign, "How darest thou desecrate my altar!");
  9.          (void) adjattrib(A_WIS, -1, FALSE);
  10.      } else {
  11.          pline("A voice (could it be %s?) whispers:", align_gname(altaralign));
  12.          verbalize("Thou shalt pay, infidel!");
  13.          change_luck(-1);
  14.      }
  15.  }
  16.  

blocked_boulder

  1.  /* assumes isok() at one space away, but not necessarily at two */
  2.  STATIC_OVL boolean
  3.  blocked_boulder(dx, dy)
  4.  int dx, dy;
  5.  {
  6.      register struct obj *otmp;
  7.      long count = 0L;
  8.  
  9.      for (otmp = level.objects[u.ux + dx][u.uy + dy]; otmp;
  10.           otmp = otmp->nexthere) {
  11.          if (otmp->otyp == BOULDER)
  12.              count += otmp->quan;
  13.      }
  14.  
  15.      switch (count) {
  16.      case 0:
  17.          /* no boulders--not blocked */
  18.          return FALSE;
  19.      case 1:
  20.          /* possibly blocked depending on if it's pushable */
  21.          break;
  22.      default:
  23.          /* more than one boulder--blocked after they push the top one;
  24.             don't force them to push it first to find out */
  25.          return TRUE;
  26.      }
  27.  
  28.      if (!isok(u.ux + 2 * dx, u.uy + 2 * dy))
  29.          return TRUE;
  30.      if (IS_ROCK(levl[u.ux + 2 * dx][u.uy + 2 * dy].typ))
  31.          return TRUE;
  32.      if (sobj_at(BOULDER, u.ux + 2 * dx, u.uy + 2 * dy))
  33.          return TRUE;
  34.  
  35.      return FALSE;
  36.  }
  37.  
  38.  /*pray.c*/