Source:NetHack 3.6.0/src/read.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to read.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/read.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	read.c	$NHDT-Date: 1448862378 2015/11/30 05:46:18 $  $NHDT-Branch: master $:$NHDT-Revision: 1.125 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  #define Your_Own_Role(mndx)  \
  8.     ((mndx) == urole.malenum \
  9.      || (urole.femalenum != NON_PM && (mndx) == urole.femalenum))
  10.  #define Your_Own_Race(mndx)  \
  11.     ((mndx) == urace.malenum \
  12.      || (urace.femalenum != NON_PM && (mndx) == urace.femalenum))
  13.  
  14.  boolean known;
  15.  
  16.  static NEARDATA const char readable[] = { ALL_CLASSES, SCROLL_CLASS,
  17.                                           SPBOOK_CLASS, 0 };
  18.  static const char all_count[] = { ALLOW_COUNT, ALL_CLASSES, 0 };
  19.  
  20.  STATIC_DCL boolean FDECL(learnscrolltyp, (SHORT_P));
  21.  STATIC_DCL char * FDECL(erode_obj_text, (struct obj *, char *));
  22.  STATIC_DCL void NDECL(do_class_genocide);
  23.  STATIC_DCL void FDECL(stripspe, (struct obj *));
  24.  STATIC_DCL void FDECL(p_glow1, (struct obj *));
  25.  STATIC_DCL void FDECL(p_glow2, (struct obj *, const char *));
  26.  STATIC_DCL void FDECL(randomize, (int *, int));
  27.  STATIC_DCL void FDECL(forget_single_object, (int));
  28.  STATIC_DCL void FDECL(forget, (int));
  29.  STATIC_DCL int FDECL(maybe_tame, (struct monst *, struct obj *));
  30.  STATIC_DCL boolean FDECL(is_valid_stinking_cloud_pos, (int, int, BOOLEAN_P));
  31.  STATIC_DCL void FDECL(display_stinking_cloud_positions, (int));
  32.  STATIC_PTR void FDECL(set_lit, (int, int, genericptr));
  33.  

learnscrolltyp

  1.  STATIC_OVL boolean
  2.  learnscrolltyp(scrolltyp)
  3.  short scrolltyp;
  4.  {
  5.     if (!objects[scrolltyp].oc_name_known) {
  6.         makeknown(scrolltyp);
  7.         more_experienced(0, 10);
  8.         return TRUE;
  9.     } else
  10.         return FALSE;
  11.  }
  12.  

learnscroll

  1.  /* also called from teleport.c for scroll of teleportation */
  2.  void
  3.  learnscroll(sobj)
  4.  struct obj *sobj;
  5.  {
  6.     /* it's implied that sobj->dknown is set;
  7.        we couldn't be reading this scroll otherwise */
  8.     if (sobj->oclass != SPBOOK_CLASS)
  9.         (void) learnscrolltyp(sobj->otyp);
  10.  }
  11.  

erode_obj_text

  1.  char *
  2.  erode_obj_text(otmp, buf)
  3.  struct obj *otmp;
  4.  char *buf;
  5.  {
  6.     int erosion = greatest_erosion(otmp);
  7.     if (erosion)
  8.         wipeout_text(buf, (int) (strlen(buf) * erosion / (2 * MAX_ERODE)),
  9.                      otmp->o_id ^ (unsigned) ubirthday);
  10.     return buf;
  11.  }
  12.  

tshirt_text

  1.  char *
  2.  tshirt_text(tshirt, buf)
  3.  struct obj *tshirt;
  4.  char *buf;
  5.  {
  6.     static const char *shirt_msgs[] = {
  7.         /* Scott Bigham */
  8.       "I explored the Dungeons of Doom and all I got was this lousy T-shirt!",
  9.         "Is that Mjollnir in your pocket or are you just happy to see me?",
  10.       "It's not the size of your sword, it's how #enhance'd you are with it.",
  11.         "Madame Elvira's House O' Succubi Lifetime Customer",
  12.         "Madame Elvira's House O' Succubi Employee of the Month",
  13.         "Ludios Vault Guards Do It In Small, Dark Rooms",
  14.         "Yendor Military Soldiers Do It In Large Groups",
  15.         "I survived Yendor Military Boot Camp",
  16.         "Ludios Accounting School Intra-Mural Lacrosse Team",
  17.         "Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest",
  18.         "Hey, black dragon!  Disintegrate THIS!",
  19.         "I'm With Stupid -->",
  20.         "Don't blame me, I voted for Izchak!",
  21.         "Don't Panic", /* HHGTTG */
  22.         "Furinkan High School Athletic Dept.",                /* Ranma 1/2 */
  23.         "Hel-LOOO, Nurse!",                                   /* Animaniacs */
  24.         "=^.^=",
  25.         "100% goblin hair - do not wash",
  26.         "Aberzombie and Fitch",
  27.         "cK -- Cockatrice touches the Kop",
  28.         "Don't ask me, I only adventure here",
  29.         "Down with pants!",
  30.         "d, your dog or a killer?",
  31.         "FREE PUG AND NEWT!",
  32.         "Go team ant!",
  33.         "Got newt?",
  34.         "Hello, my darlings!", /* Charlie Drake */
  35.         "Hey! Nymphs! Steal This T-Shirt!",
  36.         "I <3 Dungeon of Doom",
  37.         "I <3 Maud",
  38.         "I am a Valkyrie. If you see me running, try to keep up.",
  39.         "I am not a pack rat - I am a collector",
  40.         "I bounced off a rubber tree",         /* Monkey Island */
  41.         "Plunder Island Brimstone Beach Club", /* Monkey Island */
  42.         "If you can read this, I can hit you with my polearm",
  43.         "I'm confused!",
  44.         "I scored with the princess",
  45.         "I want to live forever or die in the attempt.",
  46.         "Lichen Park",
  47.         "LOST IN THOUGHT - please send search party",
  48.         "Meat is Mordor",
  49.         "Minetown Better Business Bureau",
  50.         "Minetown Watch",
  51.  "Ms. Palm's House of Negotiable Affection -- A Very Reputable House Of Disrepute",
  52.         "Protection Racketeer",
  53.         "Real men love Crom",
  54.         "Somebody stole my Mojo!",
  55.         "The Hellhound Gang",
  56.         "The Werewolves",
  57.         "They Might Be Storm Giants",
  58.         "Weapons don't kill people, I kill people",
  59.         "White Zombie",
  60.         "You're killing me!",
  61.         "Anhur State University - Home of the Fighting Fire Ants!",
  62.         "FREE HUGS",
  63.         "Serial Ascender",
  64.         "Real men are valkyries",
  65.         "Young Men's Cavedigging Association",
  66.         "Occupy Fort Ludios",
  67.         "I couldn't afford this T-shirt so I stole it!",
  68.         "Mind flayers suck",
  69.         "I'm not wearing any pants",
  70.         "Down with the living!",
  71.         "Pudding farmer",
  72.         "Vegetarian",
  73.         "Hello, I'm War!",
  74.     };
  75.  
  76.     Strcpy(buf, shirt_msgs[tshirt->o_id % SIZE(shirt_msgs)]);
  77.     return erode_obj_text(tshirt, buf);
  78.  }
  79.  

apron_text

  1.  char *
  2.  apron_text(apron, buf)
  3.  struct obj *apron;
  4.  char *buf;
  5.  {
  6.     static const char *apron_msgs[] = {
  7.         "Kiss the cook",
  8.         "I'm making SCIENCE!",
  9.         "Don't mess with the chef",
  10.         "Don't make me poison you",
  11.         "Gehennom's Kitchen",
  12.         "Rat: The other white meat",
  13.         "If you can't stand the heat, get out of Gehennom!",
  14.         "If we weren't meant to eat animals, why are they made out of meat?",
  15.         "If you don't like the food, I'll stab you",
  16.     };
  17.  
  18.     Strcpy(buf, apron_msgs[apron->o_id % SIZE(apron_msgs)]);
  19.     return erode_obj_text(apron, buf);
  20.  }
  21.  

doread

  1.  int
  2.  doread()
  3.  {
  4.     register struct obj *scroll;
  5.     boolean confused, nodisappear;
  6.  
  7.     known = FALSE;
  8.     if (check_capacity((char *) 0))
  9.         return 0;
  10.     scroll = getobj(readable, "read");
  11.     if (!scroll)
  12.         return 0;
  13.  
  14.     /* outrumor has its own blindness check */
  15.     if (scroll->otyp == FORTUNE_COOKIE) {
  16.         if (flags.verbose)
  17.             You("break up the cookie and throw away the pieces.");
  18.         outrumor(bcsign(scroll), BY_COOKIE);
  19.         if (!Blind)
  20.             u.uconduct.literate++;
  21.         useup(scroll);
  22.         return 1;
  23.     } else if (scroll->otyp == T_SHIRT || scroll->otyp == ALCHEMY_SMOCK) {
  24.         char buf[BUFSZ];
  25.         if (Blind) {
  26.             You_cant("feel any Braille writing.");
  27.             return 0;
  28.         }
  29.         /* can't read shirt worn under suit (under cloak is ok though) */
  30.         if (scroll->otyp == T_SHIRT && uarm && scroll == uarmu) {
  31.             pline("%s shirt is obscured by %s%s.",
  32.                   scroll->unpaid ? "That" : "Your", shk_your(buf, uarm),
  33.                   suit_simple_name(uarm));
  34.             return 0;
  35.         }
  36.         u.uconduct.literate++;
  37.         if (flags.verbose)
  38.             pline("It reads:");
  39.         pline("\"%s\"", (scroll->otyp == T_SHIRT) ? tshirt_text(scroll, buf)
  40.                                                   : apron_text(scroll, buf));
  41.         return 1;
  42.     } else if (scroll->otyp == CREDIT_CARD) {
  43.         static const char *card_msgs[] = {
  44.             "Leprechaun Gold Tru$t - Shamrock Card",
  45.             "Magic Memory Vault Charge Card", "Larn National Bank", /* Larn */
  46.             "First Bank of Omega",               /* Omega */
  47.             "Bank of Zork - Frobozz Magic Card", /* Zork */
  48.             "Ankh-Morpork Merchant's Guild Barter Card",
  49.             "Ankh-Morpork Thieves' Guild Unlimited Transaction Card",
  50.             "Ransmannsby Moneylenders Association",
  51.             "Bank of Gehennom - 99% Interest Card",
  52.             "Yendorian Express - Copper Card",
  53.             "Yendorian Express - Silver Card",
  54.             "Yendorian Express - Gold Card",
  55.             "Yendorian Express - Mithril Card",
  56.             "Yendorian Express - Platinum Card", /* must be last */
  57.         };
  58.  
  59.         if (Blind) {
  60.             You("feel the embossed numbers:");
  61.         } else {
  62.             if (flags.verbose)
  63.                 pline("It reads:");
  64.             pline("\"%s\"",
  65.                   scroll->oartifact
  66.                       ? card_msgs[SIZE(card_msgs) - 1]
  67.                       : card_msgs[scroll->o_id % (SIZE(card_msgs) - 1)]);
  68.         }
  69.         /* Make a credit card number */
  70.         pline("\"%d0%d %d%d1 0%d%d0\"", ((scroll->o_id % 89) + 10),
  71.               (scroll->o_id % 4), (((scroll->o_id * 499) % 899999) + 100000),
  72.               (scroll->o_id % 10), (!(scroll->o_id % 3)),
  73.               ((scroll->o_id * 7) % 10));
  74.         u.uconduct.literate++;
  75.         return 1;
  76.     } else if (scroll->otyp == CAN_OF_GREASE) {
  77.         pline("This %s has no label.", singular(scroll, xname));
  78.         return 0;
  79.     } else if (scroll->otyp == MAGIC_MARKER) {
  80.         if (Blind) {
  81.             You_cant("feel any Braille writing.");
  82.             return 0;
  83.         }
  84.         if (flags.verbose)
  85.             pline("It reads:");
  86.         pline("\"Magic Marker(TM) Red Ink Marker Pen. Water Soluble.\"");
  87.         u.uconduct.literate++;
  88.         return 1;
  89.     } else if (scroll->oclass == COIN_CLASS) {
  90.         if (Blind)
  91.             You("feel the embossed words:");
  92.         else if (flags.verbose)
  93.             You("read:");
  94.         pline("\"1 Zorkmid. 857 GUE. In Frobs We Trust.\"");
  95.         u.uconduct.literate++;
  96.         return 1;
  97.     } else if (scroll->oartifact == ART_ORB_OF_FATE) {
  98.         if (Blind)
  99.             You("feel the engraved signature:");
  100.         else
  101.             pline("It is signed:");
  102.         pline("\"Odin.\"");
  103.         u.uconduct.literate++;
  104.         return 1;
  105.     } else if (scroll->otyp == CANDY_BAR) {
  106.         static const char *wrapper_msgs[] = {
  107.             "Apollo",       /* Lost */
  108.             "Moon Crunchy", /* South Park */
  109.             "Snacky Cake",    "Chocolate Nuggie", "The Small Bar",
  110.             "Crispy Yum Yum", "Nilla Crunchie",   "Berry Bar",
  111.             "Choco Nummer",   "Om-nom", /* Cat Macro */
  112.             "Fruity Oaty",              /* Serenity */
  113.             "Wonka Bar" /* Charlie and the Chocolate Factory */
  114.         };
  115.  
  116.         if (Blind) {
  117.             You_cant("feel any Braille writing.");
  118.             return 0;
  119.         }
  120.         pline("The wrapper reads: \"%s\"",
  121.               wrapper_msgs[scroll->o_id % SIZE(wrapper_msgs)]);
  122.         u.uconduct.literate++;
  123.         return 1;
  124.     } else if (scroll->oclass != SCROLL_CLASS
  125.                && scroll->oclass != SPBOOK_CLASS) {
  126.         pline(silly_thing_to, "read");
  127.         return 0;
  128.     } else if (Blind && (scroll->otyp != SPE_BOOK_OF_THE_DEAD)) {
  129.         const char *what = 0;
  130.         if (scroll->oclass == SPBOOK_CLASS)
  131.             what = "mystic runes";
  132.         else if (!scroll->dknown)
  133.             what = "formula on the scroll";
  134.         if (what) {
  135.             pline("Being blind, you cannot read the %s.", what);
  136.             return 0;
  137.         }
  138.     }
  139.  
  140.     confused = (Confusion != 0);
  141.  #ifdef MAIL
  142.     if (scroll->otyp == SCR_MAIL) {
  143.         confused = FALSE; /* override */
  144.         /* reading mail is a convenience for the player and takes
  145.            place outside the game, so shouldn't affect gameplay;
  146.            on the other hand, it starts by explicitly making the
  147.            hero actively read something, which is pretty hard
  148.            to simply ignore; as a compromise, if the player has
  149.            maintained illiterate conduct so far, and this mail
  150.            scroll didn't come from bones, ask for confirmation */
  151.         if (!u.uconduct.literate) {
  152.             if (!scroll->spe && yn(
  153.              "Reading mail will violate \"illiterate\" conduct.  Read anyway?"
  154.                                    ) != 'y')
  155.                 return 0;
  156.         }
  157.     }
  158.  #endif
  159.  
  160.     /* Actions required to win the game aren't counted towards conduct */
  161.     /* Novel conduct is handled in read_tribute so exclude it too*/
  162.     if (scroll->otyp != SPE_BOOK_OF_THE_DEAD
  163.         && scroll->otyp != SPE_BLANK_PAPER && scroll->otyp != SCR_BLANK_PAPER
  164.         && scroll->otyp != SPE_NOVEL)
  165.         u.uconduct.literate++;
  166.  
  167.     if (scroll->oclass == SPBOOK_CLASS) {
  168.         return study_book(scroll);
  169.     }
  170.     scroll->in_use = TRUE; /* scroll, not spellbook, now being read */
  171.     if (scroll->otyp != SCR_BLANK_PAPER) {
  172.         /* a few scroll feedback messages describe something happening
  173.            to the scroll itself, so avoid "it disappears" for those */
  174.         nodisappear = (scroll->otyp == SCR_FIRE
  175.                        || (scroll->otyp == SCR_REMOVE_CURSE
  176.                            && scroll->cursed));
  177.         if (Blind)
  178.             pline(nodisappear
  179.                       ? "You %s the formula on the scroll."
  180.                       : "As you %s the formula on it, the scroll disappears.",
  181.                   is_silent(youmonst.data) ? "cogitate" : "pronounce");
  182.         else
  183.             pline(nodisappear ? "You read the scroll."
  184.                               : "As you read the scroll, it disappears.");
  185.         if (confused) {
  186.             if (Hallucination)
  187.                 pline("Being so trippy, you screw up...");
  188.             else
  189.                 pline("Being confused, you %s the magic words...",
  190.                       is_silent(youmonst.data) ? "misunderstand"
  191.                                                : "mispronounce");
  192.         }
  193.     }
  194.     if (!seffects(scroll)) {
  195.         if (!objects[scroll->otyp].oc_name_known) {
  196.             if (known)
  197.                 learnscroll(scroll);
  198.             else if (!objects[scroll->otyp].oc_uname)
  199.                 docall(scroll);
  200.         }
  201.         scroll->in_use = FALSE;
  202.         if (scroll->otyp != SCR_BLANK_PAPER)
  203.             useup(scroll);
  204.     }
  205.     return 1;
  206.  }
  207.  

stripspe

  1.  STATIC_OVL void
  2.  stripspe(obj)
  3.  register struct obj *obj;
  4.  {
  5.     if (obj->blessed || obj->spe <= 0) {
  6.         pline1(nothing_happens);
  7.     } else {
  8.         /* order matters: message, shop handling, actual transformation */
  9.         pline("%s briefly.", Yobjnam2(obj, "vibrate"));
  10.         costly_alteration(obj, COST_UNCHRG);
  11.         obj->spe = 0;
  12.         if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN)
  13.             obj->age = 0;
  14.     }
  15.  }
  16.  

p_glow1

  1.  STATIC_OVL void
  2.  p_glow1(otmp)
  3.  register struct obj *otmp;
  4.  {
  5.     pline("%s briefly.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"));
  6.  }
  7.  

p_glow2

  1.  STATIC_OVL void
  2.  p_glow2(otmp, color)
  3.  register struct obj *otmp;
  4.  register const char *color;
  5.  {
  6.     pline("%s%s%s for a moment.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"),
  7.           Blind ? "" : " ", Blind ? "" : hcolor(color));
  8.  }
  9.  

is_chargeable

  1.  /* Is the object chargeable?  For purposes of inventory display; it is
  2.    possible to be able to charge things for which this returns FALSE. */
  3.  boolean
  4.  is_chargeable(obj)
  5.  struct obj *obj;
  6.  {
  7.     if (obj->oclass == WAND_CLASS)
  8.         return TRUE;
  9.     /* known && !oc_name_known is possible after amnesia/mind flayer */
  10.     if (obj->oclass == RING_CLASS)
  11.         return (boolean) (objects[obj->otyp].oc_charged
  12.                           && (obj->known
  13.                               || (obj->dknown
  14.                                   && objects[obj->otyp].oc_name_known)));
  15.     if (is_weptool(obj)) /* specific check before general tools */
  16.         return FALSE;
  17.     if (obj->oclass == TOOL_CLASS)
  18.         return (boolean) objects[obj->otyp].oc_charged;
  19.     return FALSE; /* why are weapons/armor considered charged anyway? */
  20.  }
  21.  

recharge

  1.  /* recharge an object; curse_bless is -1 if the recharging implement
  2.    was cursed, +1 if blessed, 0 otherwise. */
  3.  void
  4.  recharge(obj, curse_bless)
  5.  struct obj *obj;
  6.  int curse_bless;
  7.  {
  8.     register int n;
  9.     boolean is_cursed, is_blessed;
  10.  
  11.     is_cursed = curse_bless < 0;
  12.     is_blessed = curse_bless > 0;
  13.  
  14.     if (obj->oclass == WAND_CLASS) {
  15.         int lim = (obj->otyp == WAN_WISHING)
  16.                       ? 3
  17.                       : (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15;
  18.  
  19.         /* undo any prior cancellation, even when is_cursed */
  20.         if (obj->spe == -1)
  21.             obj->spe = 0;
  22.  
  23.         /*
  24.          * Recharging might cause wands to explode.
  25.          *      v = number of previous recharges
  26.          *            v = percentage chance to explode on this attempt
  27.          *                    v = cumulative odds for exploding
  28.          *      0 :   0       0
  29.          *      1 :   0.29    0.29
  30.          *      2 :   2.33    2.62
  31.          *      3 :   7.87   10.28
  32.          *      4 :  18.66   27.02
  33.          *      5 :  36.44   53.62
  34.          *      6 :  62.97   82.83
  35.          *      7 : 100     100
  36.          */
  37.         n = (int) obj->recharged;
  38.         if (n > 0 && (obj->otyp == WAN_WISHING
  39.                       || (n * n * n > rn2(7 * 7 * 7)))) { /* recharge_limit */
  40.             wand_explode(obj, rnd(lim));
  41.             return;
  42.         }
  43.         /* didn't explode, so increment the recharge count */
  44.         obj->recharged = (unsigned) (n + 1);
  45.  
  46.         /* now handle the actual recharging */
  47.         if (is_cursed) {
  48.             stripspe(obj);
  49.         } else {
  50.             n = (lim == 3) ? 3 : rn1(5, lim + 1 - 5);
  51.             if (!is_blessed)
  52.                 n = rnd(n);
  53.  
  54.             if (obj->spe < n)
  55.                 obj->spe = n;
  56.             else
  57.                 obj->spe++;
  58.             if (obj->otyp == WAN_WISHING && obj->spe > 3) {
  59.                 wand_explode(obj, 1);
  60.                 return;
  61.             }
  62.             if (obj->spe >= lim)
  63.                 p_glow2(obj, NH_BLUE);
  64.             else
  65.                 p_glow1(obj);
  66.  #if 0 /*[shop price doesn't vary by charge count]*/
  67.             /* update shop bill to reflect new higher price */
  68.             if (obj->unpaid)
  69.                 alter_cost(obj, 0L);
  70.  #endif
  71.         }
  72.  
  73.     } else if (obj->oclass == RING_CLASS && objects[obj->otyp].oc_charged) {
  74.         /* charging does not affect ring's curse/bless status */
  75.         int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1;
  76.         boolean is_on = (obj == uleft || obj == uright);
  77.  
  78.         /* destruction depends on current state, not adjustment */
  79.         if (obj->spe > rn2(7) || obj->spe <= -5) {
  80.             pline("%s momentarily, then %s!", Yobjnam2(obj, "pulsate"),
  81.                   otense(obj, "explode"));
  82.             if (is_on)
  83.                 Ring_gone(obj);
  84.             s = rnd(3 * abs(obj->spe)); /* amount of damage */
  85.             useup(obj);
  86.             losehp(Maybe_Half_Phys(s), "exploding ring", KILLED_BY_AN);
  87.         } else {
  88.             long mask = is_on ? (obj == uleft ? LEFT_RING : RIGHT_RING) : 0L;
  89.  
  90.             pline("%s spins %sclockwise for a moment.", Yname2(obj),
  91.                   s < 0 ? "counter" : "");
  92.             if (s < 0)
  93.                 costly_alteration(obj, COST_DECHNT);
  94.             /* cause attributes and/or properties to be updated */
  95.             if (is_on)
  96.                 Ring_off(obj);
  97.             obj->spe += s; /* update the ring while it's off */
  98.             if (is_on)
  99.                 setworn(obj, mask), Ring_on(obj);
  100.             /* oartifact: if a touch-sensitive artifact ring is
  101.                ever created the above will need to be revised  */
  102.             /* update shop bill to reflect new higher price */
  103.             if (s > 0 && obj->unpaid)
  104.                 alter_cost(obj, 0L);
  105.         }
  106.  
  107.     } else if (obj->oclass == TOOL_CLASS) {
  108.         int rechrg = (int) obj->recharged;
  109.  
  110.         if (objects[obj->otyp].oc_charged) {
  111.             /* tools don't have a limit, but the counter used does */
  112.             if (rechrg < 7) /* recharge_limit */
  113.                 obj->recharged++;
  114.         }
  115.         switch (obj->otyp) {
  116.         case BELL_OF_OPENING:
  117.             if (is_cursed)
  118.                 stripspe(obj);
  119.             else if (is_blessed)
  120.                 obj->spe += rnd(3);
  121.             else
  122.                 obj->spe += 1;
  123.             if (obj->spe > 5)
  124.                 obj->spe = 5;
  125.             break;
  126.         case MAGIC_MARKER:
  127.         case TINNING_KIT:
  128.         case EXPENSIVE_CAMERA:
  129.             if (is_cursed)
  130.                 stripspe(obj);
  131.             else if (rechrg
  132.                      && obj->otyp
  133.                             == MAGIC_MARKER) { /* previously recharged */
  134.                 obj->recharged = 1; /* override increment done above */
  135.                 if (obj->spe < 3)
  136.                     Your("marker seems permanently dried out.");
  137.                 else
  138.                     pline1(nothing_happens);
  139.             } else if (is_blessed) {
  140.                 n = rn1(16, 15); /* 15..30 */
  141.                 if (obj->spe + n <= 50)
  142.                     obj->spe = 50;
  143.                 else if (obj->spe + n <= 75)
  144.                     obj->spe = 75;
  145.                 else {
  146.                     int chrg = (int) obj->spe;
  147.                     if ((chrg + n) > 127)
  148.                         obj->spe = 127;
  149.                     else
  150.                         obj->spe += n;
  151.                 }
  152.                 p_glow2(obj, NH_BLUE);
  153.             } else {
  154.                 n = rn1(11, 10); /* 10..20 */
  155.                 if (obj->spe + n <= 50)
  156.                     obj->spe = 50;
  157.                 else {
  158.                     int chrg = (int) obj->spe;
  159.                     if ((chrg + n) > 127)
  160.                         obj->spe = 127;
  161.                     else
  162.                         obj->spe += n;
  163.                 }
  164.                 p_glow2(obj, NH_WHITE);
  165.             }
  166.             break;
  167.         case OIL_LAMP:
  168.         case BRASS_LANTERN:
  169.             if (is_cursed) {
  170.                 stripspe(obj);
  171.                 if (obj->lamplit) {
  172.                     if (!Blind)
  173.                         pline("%s out!", Tobjnam(obj, "go"));
  174.                     end_burn(obj, TRUE);
  175.                 }
  176.             } else if (is_blessed) {
  177.                 obj->spe = 1;
  178.                 obj->age = 1500;
  179.                 p_glow2(obj, NH_BLUE);
  180.             } else {
  181.                 obj->spe = 1;
  182.                 obj->age += 750;
  183.                 if (obj->age > 1500)
  184.                     obj->age = 1500;
  185.                 p_glow1(obj);
  186.             }
  187.             break;
  188.         case CRYSTAL_BALL:
  189.             if (is_cursed) {
  190.                 stripspe(obj);
  191.             } else if (is_blessed) {
  192.                 obj->spe = 6;
  193.                 p_glow2(obj, NH_BLUE);
  194.             } else {
  195.                 if (obj->spe < 5) {
  196.                     obj->spe++;
  197.                     p_glow1(obj);
  198.                 } else
  199.                     pline1(nothing_happens);
  200.             }
  201.             break;
  202.         case HORN_OF_PLENTY:
  203.         case BAG_OF_TRICKS:
  204.         case CAN_OF_GREASE:
  205.             if (is_cursed) {
  206.                 stripspe(obj);
  207.             } else if (is_blessed) {
  208.                 if (obj->spe <= 10)
  209.                     obj->spe += rn1(10, 6);
  210.                 else
  211.                     obj->spe += rn1(5, 6);
  212.                 if (obj->spe > 50)
  213.                     obj->spe = 50;
  214.                 p_glow2(obj, NH_BLUE);
  215.             } else {
  216.                 obj->spe += rnd(5);
  217.                 if (obj->spe > 50)
  218.                     obj->spe = 50;
  219.                 p_glow1(obj);
  220.             }
  221.             break;
  222.         case MAGIC_FLUTE:
  223.         case MAGIC_HARP:
  224.         case FROST_HORN:
  225.         case FIRE_HORN:
  226.         case DRUM_OF_EARTHQUAKE:
  227.             if (is_cursed) {
  228.                 stripspe(obj);
  229.             } else if (is_blessed) {
  230.                 obj->spe += d(2, 4);
  231.                 if (obj->spe > 20)
  232.                     obj->spe = 20;
  233.                 p_glow2(obj, NH_BLUE);
  234.             } else {
  235.                 obj->spe += rnd(4);
  236.                 if (obj->spe > 20)
  237.                     obj->spe = 20;
  238.                 p_glow1(obj);
  239.             }
  240.             break;
  241.         default:
  242.             goto not_chargable;
  243.             /*NOTREACHED*/
  244.             break;
  245.         } /* switch */
  246.  
  247.     } else {
  248.     not_chargable:
  249.         You("have a feeling of loss.");
  250.     }
  251.  }
  252.  

forget_single_object

  1.  /* Forget known information about this object type. */
  2.  STATIC_OVL void
  3.  forget_single_object(obj_id)
  4.  int obj_id;
  5.  {
  6.     objects[obj_id].oc_name_known = 0;
  7.     objects[obj_id].oc_pre_discovered = 0; /* a discovery when relearned */
  8.     if (objects[obj_id].oc_uname) {
  9.         free((genericptr_t) objects[obj_id].oc_uname);
  10.         objects[obj_id].oc_uname = 0;
  11.     }
  12.     undiscover_object(obj_id); /* after clearing oc_name_known */
  13.  
  14.     /* clear & free object names from matching inventory items too? */
  15.  }
  16.  

forget_objclass

  1.  #if 0 /* here if anyone wants it.... */
  2.  /* Forget everything known about a particular object class. */
  3.  STATIC_OVL void
  4.  forget_objclass(oclass)
  5.  int oclass;
  6.  {
  7.     int i;
  8.  
  9.     for (i = bases[oclass];
  10.          i < NUM_OBJECTS && objects[i].oc_class == oclass; i++)
  11.         forget_single_object(i);
  12.  }
  13.  #endif

randomize

  1.  
  2.  /* randomize the given list of numbers  0 <= i < count */
  3.  STATIC_OVL void
  4.  randomize(indices, count)
  5.  int *indices;
  6.  int count;
  7.  {
  8.     int i, iswap, temp;
  9.  
  10.     for (i = count - 1; i > 0; i--) {
  11.         if ((iswap = rn2(i + 1)) == i)
  12.             continue;
  13.         temp = indices[i];
  14.         indices[i] = indices[iswap];
  15.         indices[iswap] = temp;
  16.     }
  17.  }
  18.  

forget_objects

  1.  /* Forget % of known objects. */
  2.  void
  3.  forget_objects(percent)
  4.  int percent;
  5.  {
  6.     int i, count;
  7.     int indices[NUM_OBJECTS];
  8.  
  9.     if (percent == 0)
  10.         return;
  11.     if (percent <= 0 || percent > 100) {
  12.         impossible("forget_objects: bad percent %d", percent);
  13.         return;
  14.     }
  15.  
  16.     indices[0] = 0; /* lint suppression */
  17.     for (count = 0, i = 1; i < NUM_OBJECTS; i++)
  18.         if (OBJ_DESCR(objects[i])
  19.             && (objects[i].oc_name_known || objects[i].oc_uname))
  20.             indices[count++] = i;
  21.  
  22.     if (count > 0) {
  23.         randomize(indices, count);
  24.  
  25.         /* forget first % of randomized indices */
  26.         count = ((count * percent) + rn2(100)) / 100;
  27.         for (i = 0; i < count; i++)
  28.             forget_single_object(indices[i]);
  29.     }
  30.  }
  31.  

forget_map

  1.  /* Forget some or all of map (depends on parameters). */
  2.  void
  3.  forget_map(howmuch)
  4.  int howmuch;
  5.  {
  6.     register int zx, zy;
  7.  
  8.     if (Sokoban)
  9.         return;
  10.  
  11.     known = TRUE;
  12.     for (zx = 0; zx < COLNO; zx++)
  13.         for (zy = 0; zy < ROWNO; zy++)
  14.             if (howmuch & ALL_MAP || rn2(7)) {
  15.                 /* Zonk all memory of this location. */
  16.                 levl[zx][zy].seenv = 0;
  17.                 levl[zx][zy].waslit = 0;
  18.                 levl[zx][zy].glyph = cmap_to_glyph(S_stone);
  19.                 lastseentyp[zx][zy] = STONE;
  20.             }
  21.     /* forget overview data for this level */
  22.     forget_mapseen(ledger_no(&u.uz));
  23.  }
  24.  

forget_traps

  1.  /* Forget all traps on the level. */
  2.  void
  3.  forget_traps()
  4.  {
  5.     register struct trap *trap;
  6.  
  7.     /* forget all traps (except the one the hero is in :-) */
  8.     for (trap = ftrap; trap; trap = trap->ntrap)
  9.         if ((trap->tx != u.ux || trap->ty != u.uy) && (trap->ttyp != HOLE))
  10.             trap->tseen = 0;
  11.  }
  12.  

forget_levels

  1.  /*
  2.  * Forget given % of all levels that the hero has visited and not forgotten,
  3.  * except this one.
  4.  */
  5.  void
  6.  forget_levels(percent)
  7.  int percent;
  8.  {
  9.     int i, count;
  10.     xchar maxl, this_lev;
  11.     int indices[MAXLINFO];
  12.  
  13.     if (percent == 0)
  14.         return;
  15.  
  16.     if (percent <= 0 || percent > 100) {
  17.         impossible("forget_levels: bad percent %d", percent);
  18.         return;
  19.     }
  20.  
  21.     this_lev = ledger_no(&u.uz);
  22.     maxl = maxledgerno();
  23.  
  24.     /* count & save indices of non-forgotten visited levels */
  25.     /* Sokoban levels are pre-mapped for the player, and should stay
  26.      * so, or they become nearly impossible to solve.  But try to
  27.      * shift the forgetting elsewhere by fiddling with percent
  28.      * instead of forgetting fewer levels.
  29.      */
  30.     indices[0] = 0; /* lint suppression */
  31.     for (count = 0, i = 0; i <= maxl; i++)
  32.         if ((level_info[i].flags & VISITED)
  33.             && !(level_info[i].flags & FORGOTTEN) && i != this_lev) {
  34.             if (ledger_to_dnum(i) == sokoban_dnum)
  35.                 percent += 2;
  36.             else
  37.                 indices[count++] = i;
  38.         }
  39.  
  40.     if (percent > 100)
  41.         percent = 100;
  42.  
  43.     if (count > 0) {
  44.         randomize(indices, count);
  45.  
  46.         /* forget first % of randomized indices */
  47.         count = ((count * percent) + 50) / 100;
  48.         for (i = 0; i < count; i++) {
  49.             level_info[indices[i]].flags |= FORGOTTEN;
  50.             forget_mapseen(indices[i]);
  51.         }
  52.     }
  53.  }
  54.  

forget

  1.  /*
  2.  * Forget some things (e.g. after reading a scroll of amnesia).  When called,
  3.  * the following are always forgotten:
  4.  *      - felt ball & chain
  5.  *      - traps
  6.  *      - part (6 out of 7) of the map
  7.  *
  8.  * Other things are subject to flags:
  9.  *      howmuch & ALL_MAP       = forget whole map
  10.  *      howmuch & ALL_SPELLS    = forget all spells
  11.  */
  12.  STATIC_OVL void
  13.  forget(howmuch)
  14.  int howmuch;
  15.  {
  16.     if (Punished)
  17.         u.bc_felt = 0; /* forget felt ball&chain */
  18.  
  19.     forget_map(howmuch);
  20.     forget_traps();
  21.  
  22.     /* 1 in 3 chance of forgetting some levels */
  23.     if (!rn2(3))
  24.         forget_levels(rn2(25));
  25.  
  26.     /* 1 in 3 chance of forgetting some objects */
  27.     if (!rn2(3))
  28.         forget_objects(rn2(25));
  29.  
  30.     if (howmuch & ALL_SPELLS)
  31.         losespells();
  32.     /*
  33.      * Make sure that what was seen is restored correctly.  To do this,
  34.      * we need to go blind for an instant --- turn off the display,
  35.      * then restart it.  All this work is needed to correctly handle
  36.      * walls which are stone on one side and wall on the other.  Turning
  37.      * off the seen bits above will make the wall revert to stone,  but
  38.      * there are cases where we don't want this to happen.  The easiest
  39.      * thing to do is to run it through the vision system again, which
  40.      * is always correct.
  41.      */
  42.     docrt(); /* this correctly will reset vision */
  43.  }
  44.  

maybe_tame

  1.  /* monster is hit by scroll of taming's effect */
  2.  STATIC_OVL int
  3.  maybe_tame(mtmp, sobj)
  4.  struct monst *mtmp;
  5.  struct obj *sobj;
  6.  {
  7.     int was_tame = mtmp->mtame;
  8.     unsigned was_peaceful = mtmp->mpeaceful;
  9.  
  10.     if (sobj->cursed) {
  11.         setmangry(mtmp);
  12.         if (was_peaceful && !mtmp->mpeaceful)
  13.             return -1;
  14.     } else {
  15.         if (mtmp->isshk)
  16.             make_happy_shk(mtmp, FALSE);
  17.         else if (!resist(mtmp, sobj->oclass, 0, NOTELL))
  18.             (void) tamedog(mtmp, (struct obj *) 0);
  19.         if ((!was_peaceful && mtmp->mpeaceful) || (!was_tame && mtmp->mtame))
  20.             return 1;
  21.     }
  22.     return 0;
  23.  }
  24.  

is_valid_stinking_cloud_pos

  1.  boolean
  2.  is_valid_stinking_cloud_pos(x, y, showmsg)
  3.  int x, y;
  4.  boolean showmsg;
  5.  {
  6.     if (!cansee(x, y) || !ACCESSIBLE(levl[x][y].typ) || distu(x, y) >= 32) {
  7.         if (showmsg)
  8.             You("smell rotten eggs.");
  9.         return FALSE;
  10.     }
  11.     return TRUE;
  12.  }
  13.  

display_stinking_cloud_positions

  1.  void
  2.  display_stinking_cloud_positions(state)
  3.  int state;
  4.  {
  5.     if (state == 0) {
  6.         tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos));
  7.     } else if (state == 1) {
  8.         int x, y, dx, dy;
  9.         int dist = 6;
  10.  
  11.         for (dx = -dist; dx <= dist; dx++)
  12.             for (dy = -dist; dy <= dist; dy++) {
  13.                 x = u.ux + dx;
  14.                 y = u.uy + dy;
  15.                 if (isok(x, y) && is_valid_stinking_cloud_pos(x, y, FALSE))
  16.                     tmp_at(x, y);
  17.             }
  18.     } else {
  19.         tmp_at(DISP_END, 0);
  20.     }
  21.  }
  22.  

seffects

  1.  /* scroll effects; return 1 if we use up the scroll and possibly make it
  2.    become discovered, 0 if caller should take care of those side-effects */
  3.  int
  4.  seffects(sobj)
  5.  struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */
  6.  {
  7.     int cval, otyp = sobj->otyp;
  8.     boolean confused = (Confusion != 0), sblessed = sobj->blessed,
  9.             scursed = sobj->cursed, already_known, old_erodeproof,
  10.             new_erodeproof;
  11.     struct obj *otmp;
  12.  
  13.     if (objects[otyp].oc_magic)
  14.         exercise(A_WIS, TRUE);                       /* just for trying */
  15.     already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
  16.                      || objects[otyp].oc_name_known);
  17.  
  18.     switch (otyp) {
  19.  #ifdef MAIL
  20.     case SCR_MAIL:
  21.         known = TRUE;
  22.         if (sobj->spe)
  23.             pline(
  24.     "This seems to be junk mail addressed to the finder of the Eye of Larn.");
  25.         /* note to the puzzled: the game Larn actually sends you junk
  26.          * mail if you win!
  27.          */
  28.         else
  29.             readmail(sobj);
  30.         break;
  31.  #endif
  32.     case SCR_ENCHANT_ARMOR: {
  33.         register schar s;
  34.         boolean special_armor;
  35.         boolean same_color;
  36.  
  37.         otmp = some_armor(&youmonst);
  38.         if (!otmp) {
  39.             strange_feeling(sobj, !Blind
  40.                                       ? "Your skin glows then fades."
  41.                                       : "Your skin feels warm for a moment.");
  42.             sobj = 0; /* useup() in strange_feeling() */
  43.             exercise(A_CON, !scursed);
  44.             exercise(A_STR, !scursed);
  45.             break;
  46.         }
  47.         if (confused) {
  48.             old_erodeproof = (otmp->oerodeproof != 0);
  49.             new_erodeproof = !scursed;
  50.             otmp->oerodeproof = 0; /* for messages */
  51.             if (Blind) {
  52.                 otmp->rknown = FALSE;
  53.                 pline("%s warm for a moment.", Yobjnam2(otmp, "feel"));
  54.             } else {
  55.                 otmp->rknown = TRUE;
  56.                 pline("%s covered by a %s %s %s!", Yobjnam2(otmp, "are"),
  57.                       scursed ? "mottled" : "shimmering",
  58.                       hcolor(scursed ? NH_BLACK : NH_GOLDEN),
  59.                       scursed ? "glow"
  60.                               : (is_shield(otmp) ? "layer" : "shield"));
  61.             }
  62.             if (new_erodeproof && (otmp->oeroded || otmp->oeroded2)) {
  63.                 otmp->oeroded = otmp->oeroded2 = 0;
  64.                 pline("%s as good as new!",
  65.                       Yobjnam2(otmp, Blind ? "feel" : "look"));
  66.             }
  67.             if (old_erodeproof && !new_erodeproof) {
  68.                 /* restore old_erodeproof before shop charges */
  69.                 otmp->oerodeproof = 1;
  70.                 costly_alteration(otmp, COST_DEGRD);
  71.             }
  72.             otmp->oerodeproof = new_erodeproof ? 1 : 0;
  73.             break;
  74.         }
  75.         /* elven armor vibrates warningly when enchanted beyond a limit */
  76.         special_armor = is_elven_armor(otmp)
  77.                         || (Role_if(PM_WIZARD) && otmp->otyp == CORNUTHAUM);
  78.         if (scursed)
  79.             same_color = (otmp->otyp == BLACK_DRAGON_SCALE_MAIL
  80.                           || otmp->otyp == BLACK_DRAGON_SCALES);
  81.         else
  82.             same_color = (otmp->otyp == SILVER_DRAGON_SCALE_MAIL
  83.                           || otmp->otyp == SILVER_DRAGON_SCALES
  84.                           || otmp->otyp == SHIELD_OF_REFLECTION);
  85.         if (Blind)
  86.             same_color = FALSE;
  87.  
  88.         /* KMH -- catch underflow */
  89.         s = scursed ? -otmp->spe : otmp->spe;
  90.         if (s > (special_armor ? 5 : 3) && rn2(s)) {
  91.             otmp->in_use = TRUE;
  92.             pline("%s violently %s%s%s for a while, then %s.", Yname2(otmp),
  93.                   otense(otmp, Blind ? "vibrate" : "glow"),
  94.                   (!Blind && !same_color) ? " " : "",
  95.                   (Blind || same_color) ? "" : hcolor(scursed ? NH_BLACK
  96.                                                               : NH_SILVER),
  97.                   otense(otmp, "evaporate"));
  98.             remove_worn_item(otmp, FALSE);
  99.             useup(otmp);
  100.             break;
  101.         }
  102.         s = scursed ? -1 : otmp->spe >= 9
  103.                                ? (rn2(otmp->spe) == 0)
  104.                                : sblessed ? rnd(3 - otmp->spe / 3) : 1;
  105.         if (s >= 0 && Is_dragon_scales(otmp)) {
  106.             /* dragon scales get turned into dragon scale mail */
  107.             pline("%s merges and hardens!", Yname2(otmp));
  108.             setworn((struct obj *) 0, W_ARM);
  109.             /* assumes same order */
  110.             otmp->otyp += GRAY_DRAGON_SCALE_MAIL - GRAY_DRAGON_SCALES;
  111.             if (sblessed) {
  112.                 otmp->spe++;
  113.                 if (!otmp->blessed)
  114.                     bless(otmp);
  115.             } else if (otmp->cursed)
  116.                 uncurse(otmp);
  117.             otmp->known = 1;
  118.             setworn(otmp, W_ARM);
  119.             if (otmp->unpaid)
  120.                 alter_cost(otmp, 0L); /* shop bill */
  121.             break;
  122.         }
  123.         pline("%s %s%s%s%s for a %s.", Yname2(otmp),
  124.               s == 0 ? "violently " : "",
  125.               otense(otmp, Blind ? "vibrate" : "glow"),
  126.               (!Blind && !same_color) ? " " : "",
  127.               (Blind || same_color) ? ""
  128.                                     : hcolor(scursed ? NH_BLACK : NH_SILVER),
  129.               (s * s > 1) ? "while" : "moment");
  130.         /* [this cost handling will need updating if shop pricing is
  131.            ever changed to care about curse/bless status of armor] */
  132.         if (s < 0)
  133.             costly_alteration(otmp, COST_DECHNT);
  134.         if (scursed && !otmp->cursed)
  135.             curse(otmp);
  136.         else if (sblessed && !otmp->blessed)
  137.             bless(otmp);
  138.         if (s) {
  139.             otmp->spe += s;
  140.             adj_abon(otmp, s);
  141.             known = otmp->known;
  142.             /* update shop bill to reflect new higher price */
  143.             if (s > 0 && otmp->unpaid)
  144.                 alter_cost(otmp, 0L);
  145.         }
  146.  
  147.         if ((otmp->spe > (special_armor ? 5 : 3))
  148.             && (special_armor || !rn2(7)))
  149.             pline("%s %s.", Yobjnam2(otmp, "suddenly vibrate"),
  150.                   Blind ? "again" : "unexpectedly");
  151.         break;
  152.     }
  153.     case SCR_DESTROY_ARMOR: {
  154.         otmp = some_armor(&youmonst);
  155.         if (confused) {
  156.             if (!otmp) {
  157.                 strange_feeling(sobj, "Your bones itch.");
  158.                 sobj = 0; /* useup() in strange_feeling() */
  159.                 exercise(A_STR, FALSE);
  160.                 exercise(A_CON, FALSE);
  161.                 break;
  162.             }
  163.             old_erodeproof = (otmp->oerodeproof != 0);
  164.             new_erodeproof = scursed;
  165.             otmp->oerodeproof = 0; /* for messages */
  166.             p_glow2(otmp, NH_PURPLE);
  167.             if (old_erodeproof && !new_erodeproof) {
  168.                 /* restore old_erodeproof before shop charges */
  169.                 otmp->oerodeproof = 1;
  170.                 costly_alteration(otmp, COST_DEGRD);
  171.             }
  172.             otmp->oerodeproof = new_erodeproof ? 1 : 0;
  173.             break;
  174.         }
  175.         if (!scursed || !otmp || !otmp->cursed) {
  176.             if (!destroy_arm(otmp)) {
  177.                 strange_feeling(sobj, "Your skin itches.");
  178.                 sobj = 0; /* useup() in strange_feeling() */
  179.                 exercise(A_STR, FALSE);
  180.                 exercise(A_CON, FALSE);
  181.                 break;
  182.             } else
  183.                 known = TRUE;
  184.         } else { /* armor and scroll both cursed */
  185.             pline("%s.", Yobjnam2(otmp, "vibrate"));
  186.             if (otmp->spe >= -6) {
  187.                 otmp->spe += -1;
  188.                 adj_abon(otmp, -1);
  189.             }
  190.             make_stunned((HStun & TIMEOUT) + (long) rn1(10, 10), TRUE);
  191.         }
  192.     } break;
  193.     case SCR_CONFUSE_MONSTER:
  194.     case SPE_CONFUSE_MONSTER:
  195.         if (youmonst.data->mlet != S_HUMAN || scursed) {
  196.             if (!HConfusion)
  197.                 You_feel("confused.");
  198.             make_confused(HConfusion + rnd(100), FALSE);
  199.         } else if (confused) {
  200.             if (!sblessed) {
  201.                 Your("%s begin to %s%s.", makeplural(body_part(HAND)),
  202.                      Blind ? "tingle" : "glow ",
  203.                      Blind ? "" : hcolor(NH_PURPLE));
  204.                 make_confused(HConfusion + rnd(100), FALSE);
  205.             } else {
  206.                 pline("A %s%s surrounds your %s.",
  207.                       Blind ? "" : hcolor(NH_RED),
  208.                       Blind ? "faint buzz" : " glow", body_part(HEAD));
  209.                 make_confused(0L, TRUE);
  210.             }
  211.         } else {
  212.             if (!sblessed) {
  213.                 Your("%s%s %s%s.", makeplural(body_part(HAND)),
  214.                      Blind ? "" : " begin to glow",
  215.                      Blind ? (const char *) "tingle" : hcolor(NH_RED),
  216.                      u.umconf ? " even more" : "");
  217.                 u.umconf++;
  218.             } else {
  219.                 if (Blind)
  220.                     Your("%s tingle %s sharply.", makeplural(body_part(HAND)),
  221.                          u.umconf ? "even more" : "very");
  222.                 else
  223.                     Your("%s glow a%s brilliant %s.",
  224.                          makeplural(body_part(HAND)),
  225.                          u.umconf ? "n even more" : "", hcolor(NH_RED));
  226.                 /* after a while, repeated uses become less effective */
  227.                 if (u.umconf >= 40)
  228.                     u.umconf++;
  229.                 else
  230.                     u.umconf += rn1(8, 2);
  231.             }
  232.         }
  233.         break;
  234.     case SCR_SCARE_MONSTER:
  235.     case SPE_CAUSE_FEAR: {
  236.         register int ct = 0;
  237.         register struct monst *mtmp;
  238.  
  239.         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  240.             if (DEADMONSTER(mtmp))
  241.                 continue;
  242.             if (cansee(mtmp->mx, mtmp->my)) {
  243.                 if (confused || scursed) {
  244.                     mtmp->mflee = mtmp->mfrozen = mtmp->msleeping = 0;
  245.                     mtmp->mcanmove = 1;
  246.                 } else if (!resist(mtmp, sobj->oclass, 0, NOTELL))
  247.                     monflee(mtmp, 0, FALSE, FALSE);
  248.                 if (!mtmp->mtame)
  249.                     ct++; /* pets don't laugh at you */
  250.             }
  251.         }
  252.         if (otyp == SCR_SCARE_MONSTER || !ct)
  253.             You_hear("%s %s.", (confused || scursed) ? "sad wailing"
  254.                                                      : "maniacal laughter",
  255.                      !ct ? "in the distance" : "close by");
  256.         break;
  257.     }
  258.     case SCR_BLANK_PAPER:
  259.         if (Blind)
  260.             You("don't remember there being any magic words on this scroll.");
  261.         else
  262.             pline("This scroll seems to be blank.");
  263.         known = TRUE;
  264.         break;
  265.     case SCR_REMOVE_CURSE:
  266.     case SPE_REMOVE_CURSE: {
  267.         register struct obj *obj;
  268.  
  269.         You_feel(!Hallucination
  270.                      ? (!confused ? "like someone is helping you."
  271.                                   : "like you need some help.")
  272.                      : (!confused ? "in touch with the Universal Oneness."
  273.                                   : "the power of the Force against you!"));
  274.  
  275.         if (scursed) {
  276.             pline_The("scroll disintegrates.");
  277.         } else {
  278.             for (obj = invent; obj; obj = obj->nobj) {
  279.                 long wornmask;
  280.                 /* gold isn't subject to cursing and blessing */
  281.                 if (obj->oclass == COIN_CLASS)
  282.                     continue;
  283.                 wornmask = (obj->owornmask & ~(W_BALL | W_ART | W_ARTI));
  284.                 if (wornmask && !sblessed) {
  285.                     /* handle a couple of special cases; we don't
  286.                        allow auxiliary weapon slots to be used to
  287.                        artificially increase number of worn items */
  288.                     if (obj == uswapwep) {
  289.                         if (!u.twoweap)
  290.                             wornmask = 0L;
  291.                     } else if (obj == uquiver) {
  292.                         if (obj->oclass == WEAPON_CLASS) {
  293.                             /* mergeable weapon test covers ammo,
  294.                                missiles, spears, daggers & knives */
  295.                             if (!objects[obj->otyp].oc_merge)
  296.                                 wornmask = 0L;
  297.                         } else if (obj->oclass == GEM_CLASS) {
  298.                             /* possibly ought to check whether
  299.                                alternate weapon is a sling... */
  300.                             if (!uslinging())
  301.                                 wornmask = 0L;
  302.                         } else {
  303.                             /* weptools don't merge and aren't
  304.                                reasonable quivered weapons */
  305.                             wornmask = 0L;
  306.                         }
  307.                     }
  308.                 }
  309.                 if (sblessed || wornmask || obj->otyp == LOADSTONE
  310.                     || (obj->otyp == LEASH && obj->leashmon)) {
  311.                     /* water price varies by curse/bless status */
  312.                     boolean shop_h2o =
  313.                         (obj->unpaid && obj->otyp == POT_WATER);
  314.  
  315.                     if (confused) {
  316.                         blessorcurse(obj, 2);
  317.                         /* lose knowledge of this object's curse/bless
  318.                            state (even if it didn't actually change) */
  319.                         obj->bknown = 0;
  320.                         /* blessorcurse() only affects uncursed items
  321.                            so no need to worry about price of water
  322.                            going down (hence no costly_alteration) */
  323.                         if (shop_h2o && (obj->cursed || obj->blessed))
  324.                             alter_cost(obj, 0L); /* price goes up */
  325.                     } else if (obj->cursed) {
  326.                         if (shop_h2o)
  327.                             costly_alteration(obj, COST_UNCURS);
  328.                         uncurse(obj);
  329.                     }
  330.                 }
  331.             }
  332.         }
  333.         if (Punished && !confused)
  334.             unpunish();
  335.         if (u.utrap && u.utraptype == TT_BURIEDBALL) {
  336.             buried_ball_to_freedom();
  337.             pline_The("clasp on your %s vanishes.", body_part(LEG));
  338.         }
  339.         update_inventory();
  340.         break;
  341.     }
  342.     case SCR_CREATE_MONSTER:
  343.     case SPE_CREATE_MONSTER:
  344.         if (create_critters(1 + ((confused || scursed) ? 12 : 0)
  345.                                 + ((sblessed || rn2(73)) ? 0 : rnd(4)),
  346.                             confused ? &mons[PM_ACID_BLOB]
  347.                                      : (struct permonst *) 0,
  348.                             FALSE))
  349.             known = TRUE;
  350.         /* no need to flush monsters; we ask for identification only if the
  351.          * monsters are not visible
  352.          */
  353.         break;
  354.     case SCR_ENCHANT_WEAPON:
  355.         if (confused && uwep
  356.             && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))) {
  357.             old_erodeproof = (uwep->oerodeproof != 0);
  358.             new_erodeproof = !scursed;
  359.             uwep->oerodeproof = 0; /* for messages */
  360.             if (Blind) {
  361.                 uwep->rknown = FALSE;
  362.                 Your("weapon feels warm for a moment.");
  363.             } else {
  364.                 uwep->rknown = TRUE;
  365.                 pline("%s covered by a %s %s %s!", Yobjnam2(uwep, "are"),
  366.                       scursed ? "mottled" : "shimmering",
  367.                       hcolor(scursed ? NH_PURPLE : NH_GOLDEN),
  368.                       scursed ? "glow" : "shield");
  369.             }
  370.             if (new_erodeproof && (uwep->oeroded || uwep->oeroded2)) {
  371.                 uwep->oeroded = uwep->oeroded2 = 0;
  372.                 pline("%s as good as new!",
  373.                       Yobjnam2(uwep, Blind ? "feel" : "look"));
  374.             }
  375.             if (old_erodeproof && !new_erodeproof) {
  376.                 /* restore old_erodeproof before shop charges */
  377.                 uwep->oerodeproof = 1;
  378.                 costly_alteration(uwep, COST_DEGRD);
  379.             }
  380.             uwep->oerodeproof = new_erodeproof ? 1 : 0;
  381.             break;
  382.         }
  383.         if (!chwepon(sobj,
  384.                      scursed
  385.                          ? -1
  386.                          : !uwep ? 1 : (uwep->spe >= 9)
  387.                                            ? !rn2(uwep->spe)
  388.                                            : sblessed ? rnd(3 - uwep->spe / 3)
  389.                                                       : 1))
  390.             sobj = 0; /* nothing enchanted: strange_feeling -> useup */
  391.         break;
  392.     case SCR_TAMING:
  393.     case SPE_CHARM_MONSTER: {
  394.         int candidates, res, results, vis_results;
  395.  
  396.         if (u.uswallow) {
  397.             candidates = 1;
  398.             results = vis_results = maybe_tame(u.ustuck, sobj);
  399.         } else {
  400.             int i, j, bd = confused ? 5 : 1;
  401.             struct monst *mtmp;
  402.  
  403.             /* note: maybe_tame() can return either positive or
  404.                negative values, but not both for the same scroll */
  405.             candidates = results = vis_results = 0;
  406.             for (i = -bd; i <= bd; i++)
  407.                 for (j = -bd; j <= bd; j++) {
  408.                     if (!isok(u.ux + i, u.uy + j))
  409.                         continue;
  410.                     if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0
  411.                         || (!i && !j && (mtmp = u.usteed) != 0)) {
  412.                         ++candidates;
  413.                         res = maybe_tame(mtmp, sobj);
  414.                         results += res;
  415.                         if (canspotmon(mtmp))
  416.                             vis_results += res;
  417.                     }
  418.                 }
  419.         }
  420.         if (!results) {
  421.             pline("Nothing interesting %s.",
  422.                   !candidates ? "happens" : "seems to happen");
  423.         } else {
  424.             pline_The("neighborhood %s %sfriendlier.",
  425.                       vis_results ? "is" : "seems",
  426.                       (results < 0) ? "un" : "");
  427.             if (vis_results > 0)
  428.                 known = TRUE;
  429.         }
  430.     } break;
  431.     case SCR_GENOCIDE:
  432.         if (!already_known)
  433.             You("have found a scroll of genocide!");
  434.         known = TRUE;
  435.         if (sblessed)
  436.             do_class_genocide();
  437.         else
  438.             do_genocide(!scursed | (2 * !!Confusion));
  439.         break;
  440.     case SCR_LIGHT:
  441.         if (!confused || rn2(5)) {
  442.             if (!Blind)
  443.                 known = TRUE;
  444.             litroom(!confused && !scursed, sobj);
  445.             if (!confused && !scursed) {
  446.                 if (lightdamage(sobj, TRUE, 5))
  447.                     known = TRUE;
  448.             }
  449.         } else {
  450.             /* could be scroll of create monster, don't set known ...*/
  451.             (void) create_critters(1, !scursed ? &mons[PM_YELLOW_LIGHT]
  452.                                                : &mons[PM_BLACK_LIGHT],
  453.                                    TRUE);
  454.             if (!objects[sobj->otyp].oc_uname)
  455.                 docall(sobj);
  456.         }
  457.         break;
  458.     case SCR_TELEPORTATION:
  459.         if (confused || scursed) {
  460.             level_tele();
  461.         } else {
  462.             known = scrolltele(sobj);
  463.         }
  464.         break;
  465.     case SCR_GOLD_DETECTION:
  466.         if ((confused || scursed) ? trap_detect(sobj) : gold_detect(sobj))
  467.             sobj = 0; /* failure: strange_feeling() -> useup() */
  468.         break;
  469.     case SCR_FOOD_DETECTION:
  470.     case SPE_DETECT_FOOD:
  471.         if (food_detect(sobj))
  472.             sobj = 0; /* nothing detected: strange_feeling -> useup */
  473.         break;
  474.     case SCR_IDENTIFY:
  475.         /* known = TRUE; -- handled inline here */
  476.         /* use up the scroll first, before makeknown() performs a
  477.            perm_invent update; also simplifies empty invent check */
  478.         useup(sobj);
  479.         sobj = 0; /* it's gone */
  480.         if (confused)
  481.             You("identify this as an identify scroll.");
  482.         else if (!already_known || !invent)
  483.             /* force feedback now if invent became
  484.                empty after using up this scroll */
  485.             pline("This is an identify scroll.");
  486.         if (!already_known)
  487.             (void) learnscrolltyp(SCR_IDENTIFY);
  488.         /*FALLTHRU*/
  489.     case SPE_IDENTIFY:
  490.         cval = 1;
  491.         if (sblessed || (!scursed && !rn2(5))) {
  492.             cval = rn2(5);
  493.             /* note: if cval==0, identify all items */
  494.             if (cval == 1 && sblessed && Luck > 0)
  495.                 ++cval;
  496.         }
  497.         if (invent && !confused) {
  498.             identify_pack(cval, !already_known);
  499.         } else if (otyp == SPE_IDENTIFY) {
  500.             /* when casting a spell we know we're not confused,
  501.                so inventory must be empty (another message has
  502.                already been given above if reading a scroll) */
  503.             pline("You're not carrying anything to be identified.");
  504.         }
  505.         break;
  506.     case SCR_CHARGING:
  507.         if (confused) {
  508.             if (scursed) {
  509.                 You_feel("discharged.");
  510.                 u.uen = 0;
  511.             } else {
  512.                 You_feel("charged up!");
  513.                 u.uen += d(sblessed ? 6 : 4, 4);
  514.                 if (u.uen > u.uenmax) /* if current energy is already at   */
  515.                     u.uenmax = u.uen; /* or near maximum, increase maximum */
  516.                 else
  517.                     u.uen = u.uenmax; /* otherwise restore current to max  */
  518.             }
  519.             context.botl = 1;
  520.             break;
  521.         }
  522.         /* known = TRUE; -- handled inline here */
  523.         if (!already_known) {
  524.             pline("This is a charging scroll.");
  525.             learnscroll(sobj);
  526.         }
  527.         /* use it up now to prevent it from showing in the
  528.            getobj picklist because the "disappears" message
  529.            was already delivered */
  530.         useup(sobj);
  531.         sobj = 0; /* it's gone */
  532.         otmp = getobj(all_count, "charge");
  533.         if (otmp)
  534.             recharge(otmp, scursed ? -1 : sblessed ? 1 : 0);
  535.         break;
  536.     case SCR_MAGIC_MAPPING:
  537.         if (level.flags.nommap) {
  538.             Your("mind is filled with crazy lines!");
  539.             if (Hallucination)
  540.                 pline("Wow!  Modern art.");
  541.             else
  542.                 Your("%s spins in bewilderment.", body_part(HEAD));
  543.             make_confused(HConfusion + rnd(30), FALSE);
  544.             break;
  545.         }
  546.         if (sblessed) {
  547.             register int x, y;
  548.  
  549.             for (x = 1; x < COLNO; x++)
  550.                 for (y = 0; y < ROWNO; y++)
  551.                     if (levl[x][y].typ == SDOOR)
  552.                         cvt_sdoor_to_door(&levl[x][y]);
  553.             /* do_mapping() already reveals secret passages */
  554.         }
  555.         known = TRUE;
  556.     case SPE_MAGIC_MAPPING:
  557.         if (level.flags.nommap) {
  558.             Your("%s spins as %s blocks the spell!", body_part(HEAD),
  559.                  something);
  560.             make_confused(HConfusion + rnd(30), FALSE);
  561.             break;
  562.         }
  563.         pline("A map coalesces in your mind!");
  564.         cval = (scursed && !confused);
  565.         if (cval)
  566.             HConfusion = 1; /* to screw up map */
  567.         do_mapping();
  568.         if (cval) {
  569.             HConfusion = 0; /* restore */
  570.             pline("Unfortunately, you can't grasp the details.");
  571.         }
  572.         break;
  573.     case SCR_AMNESIA:
  574.         known = TRUE;
  575.         forget((!sblessed ? ALL_SPELLS : 0)
  576.                | (!confused || scursed ? ALL_MAP : 0));
  577.         if (Hallucination) /* Ommmmmm! */
  578.             Your("mind releases itself from mundane concerns.");
  579.         else if (!strncmpi(plname, "Maud", 4))
  580.             pline(
  581.           "As your mind turns inward on itself, you forget everything else.");
  582.         else if (rn2(2))
  583.             pline("Who was that Maud person anyway?");
  584.         else
  585.             pline("Thinking of Maud you forget everything else.");
  586.         exercise(A_WIS, FALSE);
  587.         break;
  588.     case SCR_FIRE:
  589.         cval = bcsign(sobj);
  590.         useup(sobj);
  591.         sobj = 0; /* it's gone */
  592.         if (!already_known)
  593.             (void) learnscrolltyp(SCR_FIRE);
  594.         if (confused) {
  595.             if (Fire_resistance) {
  596.                 shieldeff(u.ux, u.uy);
  597.                 if (!Blind)
  598.                     pline("Oh, look, what a pretty fire in your %s.",
  599.                           makeplural(body_part(HAND)));
  600.                 else
  601.                     You_feel("a pleasant warmth in your %s.",
  602.                              makeplural(body_part(HAND)));
  603.             } else {
  604.                 pline_The("scroll catches fire and you burn your %s.",
  605.                           makeplural(body_part(HAND)));
  606.                 losehp(1, "scroll of fire", KILLED_BY_AN);
  607.             }
  608.             break;
  609.         }
  610.         if (Underwater) {
  611.             pline_The("water around you vaporizes violently!");
  612.         } else {
  613.             pline_The("scroll erupts in a tower of flame!");
  614.             iflags.last_msg = PLNMSG_TOWER_OF_FLAME; /* for explode() */
  615.             burn_away_slime();
  616.         }
  617.         explode(u.ux, u.uy, 11, (2 * (rn1(3, 3) + 2 * cval) + 1) / 3,
  618.                 SCROLL_CLASS, EXPL_FIERY);
  619.         break;
  620.     case SCR_EARTH:
  621.         /* TODO: handle steeds */
  622.         if (!Is_rogue_level(&u.uz) && has_ceiling(&u.uz)
  623.             && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
  624.             register int x, y;
  625.             int nboulders = 0;
  626.  
  627.             /* Identify the scroll */
  628.             if (u.uswallow)
  629.                 You_hear("rumbling.");
  630.             else
  631.                 pline_The("%s rumbles %s you!", ceiling(u.ux, u.uy),
  632.                           sblessed ? "around" : "above");
  633.             known = 1;
  634.             sokoban_guilt();
  635.  
  636.             /* Loop through the surrounding squares */
  637.             if (!scursed)
  638.                 for (x = u.ux - 1; x <= u.ux + 1; x++) {
  639.                     for (y = u.uy - 1; y <= u.uy + 1; y++) {
  640.                         /* Is this a suitable spot? */
  641.                         if (isok(x, y) && !closed_door(x, y)
  642.                             && !IS_ROCK(levl[x][y].typ)
  643.                             && !IS_AIR(levl[x][y].typ)
  644.                             && (x != u.ux || y != u.uy)) {
  645.                             nboulders +=
  646.                                 drop_boulder_on_monster(x, y, confused, TRUE);
  647.                         }
  648.                     }
  649.                 }
  650.             /* Attack the player */
  651.             if (!sblessed) {
  652.                 drop_boulder_on_player(confused, !scursed, TRUE, FALSE);
  653.             } else if (!nboulders)
  654.                 pline("But nothing else happens.");
  655.         }
  656.         break;
  657.     case SCR_PUNISHMENT:
  658.         known = TRUE;
  659.         if (confused || sblessed) {
  660.             You_feel("guilty.");
  661.             break;
  662.         }
  663.         punish(sobj);
  664.         break;
  665.     case SCR_STINKING_CLOUD: {
  666.         coord cc;
  667.  
  668.         if (!already_known)
  669.             You("have found a scroll of stinking cloud!");
  670.         known = TRUE;
  671.         pline("Where do you want to center the %scloud?",
  672.               already_known ? "stinking " : "");
  673.         cc.x = u.ux;
  674.         cc.y = u.uy;
  675.         getpos_sethilite(display_stinking_cloud_positions);
  676.         if (getpos(&cc, TRUE, "the desired position") < 0) {
  677.             pline1(Never_mind);
  678.             break;
  679.         }
  680.         if (!is_valid_stinking_cloud_pos(cc.x, cc.y, TRUE))
  681.             break;
  682.         (void) create_gas_cloud(cc.x, cc.y, 3 + bcsign(sobj),
  683.                                 8 + 4 * bcsign(sobj));
  684.         break;
  685.     }
  686.     default:
  687.         impossible("What weird effect is this? (%u)", otyp);
  688.     }
  689.     return sobj ? 0 : 1;
  690.  }
  691.  

drop_boulder_on_player

  1.  void
  2.  drop_boulder_on_player(confused, helmet_protects, byu, skip_uswallow)
  3.  boolean confused, helmet_protects, byu, skip_uswallow;
  4.  {
  5.     int dmg;
  6.     struct obj *otmp2;
  7.  
  8.     /* hit monster if swallowed */
  9.     if (u.uswallow && !skip_uswallow) {
  10.         drop_boulder_on_monster(u.ux, u.uy, confused, byu);
  11.         return;
  12.     }
  13.  
  14.     otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
  15.     if (!otmp2)
  16.         return;
  17.     otmp2->quan = confused ? rn1(5, 2) : 1;
  18.     otmp2->owt = weight(otmp2);
  19.     if (!amorphous(youmonst.data) && !Passes_walls
  20.         && !noncorporeal(youmonst.data) && !unsolid(youmonst.data)) {
  21.         You("are hit by %s!", doname(otmp2));
  22.         dmg = dmgval(otmp2, &youmonst) * otmp2->quan;
  23.         if (uarmh && helmet_protects) {
  24.             if (is_metallic(uarmh)) {
  25.                 pline("Fortunately, you are wearing a hard helmet.");
  26.                 if (dmg > 2)
  27.                     dmg = 2;
  28.             } else if (flags.verbose) {
  29.                 pline("%s does not protect you.", Yname2(uarmh));
  30.             }
  31.         }
  32.     } else
  33.         dmg = 0;
  34.     /* Must be before the losehp(), for bones files */
  35.     if (!flooreffects(otmp2, u.ux, u.uy, "fall")) {
  36.         place_object(otmp2, u.ux, u.uy);
  37.         stackobj(otmp2);
  38.         newsym(u.ux, u.uy);
  39.     }
  40.     if (dmg)
  41.         losehp(Maybe_Half_Phys(dmg), "scroll of earth", KILLED_BY_AN);
  42.  }
  43.  

drop_boulder_on_monster

  1.  boolean
  2.  drop_boulder_on_monster(x, y, confused, byu)
  3.  int x, y;
  4.  boolean confused, byu;
  5.  {
  6.     register struct obj *otmp2;
  7.     register struct monst *mtmp;
  8.  
  9.     /* Make the object(s) */
  10.     otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
  11.     if (!otmp2)
  12.         return FALSE; /* Shouldn't happen */
  13.     otmp2->quan = confused ? rn1(5, 2) : 1;
  14.     otmp2->owt = weight(otmp2);
  15.  
  16.     /* Find the monster here (won't be player) */
  17.     mtmp = m_at(x, y);
  18.     if (mtmp && !amorphous(mtmp->data) && !passes_walls(mtmp->data)
  19.         && !noncorporeal(mtmp->data) && !unsolid(mtmp->data)) {
  20.         struct obj *helmet = which_armor(mtmp, W_ARMH);
  21.         int mdmg;
  22.  
  23.         if (cansee(mtmp->mx, mtmp->my)) {
  24.             pline("%s is hit by %s!", Monnam(mtmp), doname(otmp2));
  25.             if (mtmp->minvis && !canspotmon(mtmp))
  26.                 map_invisible(mtmp->mx, mtmp->my);
  27.         } else if (u.uswallow && mtmp == u.ustuck)
  28.             You_hear("something hit %s %s over your %s!",
  29.                      s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH),
  30.                      body_part(HEAD));
  31.  
  32.         mdmg = dmgval(otmp2, mtmp) * otmp2->quan;
  33.         if (helmet) {
  34.             if (is_metallic(helmet)) {
  35.                 if (canspotmon(mtmp))
  36.                     pline("Fortunately, %s is wearing a hard helmet.",
  37.                           mon_nam(mtmp));
  38.                 else if (!Deaf)
  39.                     You_hear("a clanging sound.");
  40.                 if (mdmg > 2)
  41.                     mdmg = 2;
  42.             } else {
  43.                 if (canspotmon(mtmp))
  44.                     pline("%s's %s does not protect %s.", Monnam(mtmp),
  45.                           xname(helmet), mhim(mtmp));
  46.             }
  47.         }
  48.         mtmp->mhp -= mdmg;
  49.         if (mtmp->mhp <= 0) {
  50.             if (byu)
  51.                 xkilled(mtmp, 1);
  52.             else {
  53.                 pline("%s is killed.", Monnam(mtmp));
  54.                 mondied(mtmp);
  55.             }
  56.         }
  57.     } else if (u.uswallow && mtmp == u.ustuck) {
  58.         obfree(otmp2, (struct obj *) 0);
  59.         /* fall through to player */
  60.         drop_boulder_on_player(confused, TRUE, FALSE, TRUE);
  61.         return 1;
  62.     }
  63.     /* Drop the rock/boulder to the floor */
  64.     if (!flooreffects(otmp2, x, y, "fall")) {
  65.         place_object(otmp2, x, y);
  66.         stackobj(otmp2);
  67.         newsym(x, y); /* map the rock */
  68.     }
  69.     return TRUE;
  70.  }
  71.  

wand_explode

  1.  /* overcharging any wand or zapping/engraving cursed wand */
  2.  void
  3.  wand_explode(obj, chg)
  4.  struct obj *obj;
  5.  int chg; /* recharging */
  6.  {
  7.     const char *expl = !chg ? "suddenly" : "vibrates violently and";
  8.     int dmg, n, k;
  9.  
  10.     /* number of damage dice */
  11.     if (!chg)
  12.         chg = 2; /* zap/engrave adjustment */
  13.     n = obj->spe + chg;
  14.     if (n < 2)
  15.         n = 2; /* arbitrary minimum */
  16.     /* size of damage dice */
  17.     switch (obj->otyp) {
  18.     case WAN_WISHING:
  19.         k = 12;
  20.         break;
  21.     case WAN_CANCELLATION:
  22.     case WAN_DEATH:
  23.     case WAN_POLYMORPH:
  24.     case WAN_UNDEAD_TURNING:
  25.         k = 10;
  26.         break;
  27.     case WAN_COLD:
  28.     case WAN_FIRE:
  29.     case WAN_LIGHTNING:
  30.     case WAN_MAGIC_MISSILE:
  31.         k = 8;
  32.         break;
  33.     case WAN_NOTHING:
  34.         k = 4;
  35.         break;
  36.     default:
  37.         k = 6;
  38.         break;
  39.     }
  40.     /* inflict damage and destroy the wand */
  41.     dmg = d(n, k);
  42.     obj->in_use = TRUE; /* in case losehp() is fatal (or --More--^C) */
  43.     pline("%s %s explodes!", Yname2(obj), expl);
  44.     losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN);
  45.     useup(obj);
  46.     /* obscure side-effect */
  47.     exercise(A_STR, FALSE);
  48.  }
  49.  

set_lit

  1.  /* used to collect gremlins being hit by light so that they can be processed
  2.    after vision for the entire lit area has been brought up to date */
  3.  struct litmon {
  4.     struct monst *mon;
  5.     struct litmon *nxt;
  6.  };
  7.  STATIC_VAR struct litmon *gremlins = 0;
  8.  
  9.  /*
  10.  * Low-level lit-field update routine.
  11.  */
  12.  STATIC_PTR void
  13.  set_lit(x, y, val)
  14.  int x, y;
  15.  genericptr_t val;
  16.  {
  17.     struct monst *mtmp;
  18.     struct litmon *gremlin;
  19.  
  20.     if (val) {
  21.         levl[x][y].lit = 1;
  22.         if ((mtmp = m_at(x, y)) != 0 && mtmp->data == &mons[PM_GREMLIN]) {
  23.             gremlin = (struct litmon *) alloc(sizeof *gremlin);
  24.             gremlin->mon = mtmp;
  25.             gremlin->nxt = gremlins;
  26.             gremlins = gremlin;
  27.         }
  28.     } else {
  29.         levl[x][y].lit = 0;
  30.         snuff_light_source(x, y);
  31.     }
  32.  }
  33.  

litroom

  1.  void
  2.  litroom(on, obj)
  3.  register boolean on;
  4.  struct obj *obj;
  5.  {
  6.     char is_lit; /* value is irrelevant; we use its address
  7.                     as a `not null' flag for set_lit() */
  8.  
  9.     /* first produce the text (provided you're not blind) */
  10.     if (!on) {
  11.         register struct obj *otmp;
  12.  
  13.         if (!Blind) {
  14.             if (u.uswallow) {
  15.                 pline("It seems even darker in here than before.");
  16.             } else {
  17.                 if (uwep && artifact_light(uwep) && uwep->lamplit)
  18.                     pline("Suddenly, the only light left comes from %s!",
  19.                           the(xname(uwep)));
  20.                 else
  21.                     You("are surrounded by darkness!");
  22.             }
  23.         }
  24.  
  25.         /* the magic douses lamps, et al, too */
  26.         for (otmp = invent; otmp; otmp = otmp->nobj)
  27.             if (otmp->lamplit)
  28.                 (void) snuff_lit(otmp);
  29.     } else { /* on */
  30.         if (u.uswallow) {
  31.             if (Blind)
  32.                 ; /* no feedback */
  33.             else if (is_animal(u.ustuck->data))
  34.                 pline("%s %s is lit.", s_suffix(Monnam(u.ustuck)),
  35.                       mbodypart(u.ustuck, STOMACH));
  36.             else if (is_whirly(u.ustuck->data))
  37.                 pline("%s shines briefly.", Monnam(u.ustuck));
  38.             else
  39.                 pline("%s glistens.", Monnam(u.ustuck));
  40.         } else if (!Blind)
  41.             pline("A lit field surrounds you!");
  42.     }
  43.  
  44.     /* No-op when swallowed or in water */
  45.     if (u.uswallow || Underwater || Is_waterlevel(&u.uz))
  46.         return;
  47.     /*
  48.      *  If we are darkening the room and the hero is punished but not
  49.      *  blind, then we have to pick up and replace the ball and chain so
  50.      *  that we don't remember them if they are out of sight.
  51.      */
  52.     if (Punished && !on && !Blind)
  53.         move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
  54.  
  55.     if (Is_rogue_level(&u.uz)) {
  56.         /* Can't use do_clear_area because MAX_RADIUS is too small */
  57.         /* rogue lighting must light the entire room */
  58.         int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET;
  59.         int rx, ry;
  60.  
  61.         if (rnum >= 0) {
  62.             for (rx = rooms[rnum].lx - 1; rx <= rooms[rnum].hx + 1; rx++)
  63.                 for (ry = rooms[rnum].ly - 1; ry <= rooms[rnum].hy + 1; ry++)
  64.                     set_lit(rx, ry,
  65.                             (genericptr_t) (on ? &is_lit : (char *) 0));
  66.             rooms[rnum].rlit = on;
  67.         }
  68.         /* hallways remain dark on the rogue level */
  69.     } else
  70.         do_clear_area(u.ux, u.uy,
  71.                       (obj && obj->oclass == SCROLL_CLASS && obj->blessed)
  72.                          ? 9 : 5,
  73.                       set_lit, (genericptr_t) (on ? &is_lit : (char *) 0));
  74.  
  75.     /*
  76.      *  If we are not blind, then force a redraw on all positions in sight
  77.      *  by temporarily blinding the hero.  The vision recalculation will
  78.      *  correctly update all previously seen positions *and* correctly
  79.      *  set the waslit bit [could be messed up from above].
  80.      */
  81.     if (!Blind) {
  82.         vision_recalc(2);
  83.  
  84.         /* replace ball&chain */
  85.         if (Punished && !on)
  86.             move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
  87.     }
  88.  
  89.     vision_full_recalc = 1; /* delayed vision recalculation */
  90.     if (gremlins) {
  91.         struct litmon *gremlin;
  92.  
  93.         /* can't delay vision recalc after all */
  94.         vision_recalc(0);
  95.         /* after vision has been updated, monsters who are affected
  96.            when hit by light can now be hit by it */
  97.         do {
  98.             gremlin = gremlins;
  99.             gremlins = gremlin->nxt;
  100.             light_hits_gremlin(gremlin->mon, rnd(5));
  101.             free((genericptr_t) gremlin);
  102.         } while (gremlins);
  103.     }
  104.  }
  105.  

do_class_genocide

  1.  STATIC_OVL void
  2.  do_class_genocide()
  3.  {
  4.     int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0;
  5.     char buf[BUFSZ];
  6.     boolean gameover = FALSE; /* true iff killed self */
  7.  
  8.     for (j = 0;; j++) {
  9.         if (j >= 5) {
  10.             pline1(thats_enough_tries);
  11.             return;
  12.         }
  13.         do {
  14.             getlin("What class of monsters do you wish to genocide?", buf);
  15.             (void) mungspaces(buf);
  16.         } while (!*buf);
  17.         /* choosing "none" preserves genocideless conduct */
  18.         if (*buf == '\033' || !strcmpi(buf, "none")
  19.             || !strcmpi(buf, "nothing"))
  20.             return;
  21.  
  22.         class = name_to_monclass(buf, (int *) 0);
  23.         if (class == 0 && (i = name_to_mon(buf)) != NON_PM)
  24.             class = mons[i].mlet;
  25.         immunecnt = gonecnt = goodcnt = 0;
  26.         for (i = LOW_PM; i < NUMMONS; i++) {
  27.             if (mons[i].mlet == class) {
  28.                 if (!(mons[i].geno & G_GENO))
  29.                     immunecnt++;
  30.                 else if (mvitals[i].mvflags & G_GENOD)
  31.                     gonecnt++;
  32.                 else
  33.                     goodcnt++;
  34.             }
  35.         }
  36.         if (!goodcnt && class != mons[urole.malenum].mlet
  37.             && class != mons[urace.malenum].mlet) {
  38.             if (gonecnt)
  39.                 pline("All such monsters are already nonexistent.");
  40.             else if (immunecnt || class == S_invisible)
  41.                 You("aren't permitted to genocide such monsters.");
  42.             else if (wizard && buf[0] == '*') {
  43.                 register struct monst *mtmp, *mtmp2;
  44.  
  45.                 gonecnt = 0;
  46.                 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  47.                     mtmp2 = mtmp->nmon;
  48.                     if (DEADMONSTER(mtmp))
  49.                         continue;
  50.                     mongone(mtmp);
  51.                     gonecnt++;
  52.                 }
  53.                 pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt));
  54.                 return;
  55.             } else
  56.                 pline("That %s does not represent any monster.",
  57.                       strlen(buf) == 1 ? "symbol" : "response");
  58.             continue;
  59.         }
  60.  
  61.         for (i = LOW_PM; i < NUMMONS; i++) {
  62.             if (mons[i].mlet == class) {
  63.                 char nam[BUFSZ];
  64.  
  65.                 Strcpy(nam, makeplural(mons[i].mname));
  66.                 /* Although "genus" is Latin for race, the hero benefits
  67.                  * from both race and role; thus genocide affects either.
  68.                  */
  69.                 if (Your_Own_Role(i) || Your_Own_Race(i)
  70.                     || ((mons[i].geno & G_GENO)
  71.                         && !(mvitals[i].mvflags & G_GENOD))) {
  72.                     /* This check must be first since player monsters might
  73.                      * have G_GENOD or !G_GENO.
  74.                      */
  75.                     mvitals[i].mvflags |= (G_GENOD | G_NOCORPSE);
  76.                     reset_rndmonst(i);
  77.                     kill_genocided_monsters();
  78.                     update_inventory(); /* eggs & tins */
  79.                     pline("Wiped out all %s.", nam);
  80.                     if (Upolyd && i == u.umonnum) {
  81.                         u.mh = -1;
  82.                         if (Unchanging) {
  83.                             if (!feel_dead++)
  84.                                 You("die.");
  85.                             /* finish genociding this class of
  86.                                monsters before ultimately dying */
  87.                             gameover = TRUE;
  88.                         } else
  89.                             rehumanize();
  90.                     }
  91.                     /* Self-genocide if it matches either your race
  92.                        or role.  Assumption:  male and female forms
  93.                        share same monster class. */
  94.                     if (i == urole.malenum || i == urace.malenum) {
  95.                         u.uhp = -1;
  96.                         if (Upolyd) {
  97.                             if (!feel_dead++)
  98.                                 You_feel("dead inside.");
  99.                         } else {
  100.                             if (!feel_dead++)
  101.                                 You("die.");
  102.                             gameover = TRUE;
  103.                         }
  104.                     }
  105.                 } else if (mvitals[i].mvflags & G_GENOD) {
  106.                     if (!gameover)
  107.                         pline("All %s are already nonexistent.", nam);
  108.                 } else if (!gameover) {
  109.                     /* suppress feedback about quest beings except
  110.                        for those applicable to our own role */
  111.                     if ((mons[i].msound != MS_LEADER
  112.                          || quest_info(MS_LEADER) == i)
  113.                         && (mons[i].msound != MS_NEMESIS
  114.                             || quest_info(MS_NEMESIS) == i)
  115.                         && (mons[i].msound != MS_GUARDIAN
  116.                             || quest_info(MS_GUARDIAN) == i)
  117.                         /* non-leader/nemesis/guardian role-specific monster
  118.                            */
  119.                         && (i != PM_NINJA /* nuisance */
  120.                             || Role_if(PM_SAMURAI))) {
  121.                         boolean named, uniq;
  122.  
  123.                         named = type_is_pname(&mons[i]) ? TRUE : FALSE;
  124.                         uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE;
  125.                         /* one special case */
  126.                         if (i == PM_HIGH_PRIEST)
  127.                             uniq = FALSE;
  128.  
  129.                         You("aren't permitted to genocide %s%s.",
  130.                             (uniq && !named) ? "the " : "",
  131.                             (uniq || named) ? mons[i].mname : nam);
  132.                     }
  133.                 }
  134.             }
  135.         }
  136.         if (gameover || u.uhp == -1) {
  137.             killer.format = KILLED_BY_AN;
  138.             Strcpy(killer.name, "scroll of genocide");
  139.             if (gameover)
  140.                 done(GENOCIDED);
  141.         }
  142.         return;
  143.     }
  144.  }
  145.  

do_genocide

  1.  #define REALLY 1
  2.  #define PLAYER 2
  3.  #define ONTHRONE 4
  4.  void
  5.  do_genocide(how)
  6.  int how;
  7.  /* 0 = no genocide; create monsters (cursed scroll) */
  8.  /* 1 = normal genocide */
  9.  /* 3 = forced genocide of player */
  10.  /* 5 (4 | 1) = normal genocide from throne */
  11.  {
  12.     char buf[BUFSZ];
  13.     register int i, killplayer = 0;
  14.     register int mndx;
  15.     register struct permonst *ptr;
  16.     const char *which;
  17.  
  18.     if (how & PLAYER) {
  19.         mndx = u.umonster; /* non-polymorphed mon num */
  20.         ptr = &mons[mndx];
  21.         Strcpy(buf, ptr->mname);
  22.         killplayer++;
  23.     } else {
  24.         for (i = 0;; i++) {
  25.             if (i >= 5) {
  26.                 pline1(thats_enough_tries);
  27.                 return;
  28.             }
  29.             getlin("What monster do you want to genocide? [type the name]",
  30.                    buf);
  31.             (void) mungspaces(buf);
  32.             /* choosing "none" preserves genocideless conduct */
  33.             if (!strcmpi(buf, "none") || !strcmpi(buf, "nothing")) {
  34.                 /* ... but no free pass if cursed */
  35.                 if (!(how & REALLY)) {
  36.                     ptr = rndmonst();
  37.                     if (!ptr)
  38.                         return; /* no message, like normal case */
  39.                     mndx = monsndx(ptr);
  40.                     break; /* remaining checks don't apply */
  41.                 } else
  42.                     return;
  43.             }
  44.  
  45.             mndx = name_to_mon(buf);
  46.             if (mndx == NON_PM || (mvitals[mndx].mvflags & G_GENOD)) {
  47.                 pline("Such creatures %s exist in this world.",
  48.                       (mndx == NON_PM) ? "do not" : "no longer");
  49.                 continue;
  50.             }
  51.             ptr = &mons[mndx];
  52.             /* Although "genus" is Latin for race, the hero benefits
  53.              * from both race and role; thus genocide affects either.
  54.              */
  55.             if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) {
  56.                 killplayer++;
  57.                 break;
  58.             }
  59.             if (is_human(ptr))
  60.                 adjalign(-sgn(u.ualign.type));
  61.             if (is_demon(ptr))
  62.                 adjalign(sgn(u.ualign.type));
  63.  
  64.             if (!(ptr->geno & G_GENO)) {
  65.                 if (!Deaf) {
  66.                     /* fixme: unconditional "caverns" will be silly in some
  67.                      * circumstances */
  68.                     if (flags.verbose)
  69.                         pline(
  70.                             "A thunderous voice booms through the caverns:");
  71.                     verbalize("No, mortal!  That will not be done.");
  72.                 }
  73.                 continue;
  74.             }
  75.             /* KMH -- Unchanging prevents rehumanization */
  76.             if (Unchanging && ptr == youmonst.data)
  77.                 killplayer++;
  78.             break;
  79.         }
  80.     }
  81.  
  82.     which = "all ";
  83.     if (Hallucination) {
  84.         if (Upolyd)
  85.             Strcpy(buf, youmonst.data->mname);
  86.         else {
  87.             Strcpy(buf, (flags.female && urole.name.f) ? urole.name.f
  88.                                                        : urole.name.m);
  89.             buf[0] = lowc(buf[0]);
  90.         }
  91.     } else {
  92.         Strcpy(buf, ptr->mname); /* make sure we have standard singular */
  93.         if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_PRIEST])
  94.             which = !type_is_pname(ptr) ? "the " : "";
  95.     }
  96.     if (how & REALLY) {
  97.         /* setting no-corpse affects wishing and random tin generation */
  98.         mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE);
  99.         pline("Wiped out %s%s.", which,
  100.               (*which != 'a') ? buf : makeplural(buf));
  101.  
  102.         if (killplayer) {
  103.             /* might need to wipe out dual role */
  104.             if (urole.femalenum != NON_PM && mndx == urole.malenum)
  105.                 mvitals[urole.femalenum].mvflags |= (G_GENOD | G_NOCORPSE);
  106.             if (urole.femalenum != NON_PM && mndx == urole.femalenum)
  107.                 mvitals[urole.malenum].mvflags |= (G_GENOD | G_NOCORPSE);
  108.             if (urace.femalenum != NON_PM && mndx == urace.malenum)
  109.                 mvitals[urace.femalenum].mvflags |= (G_GENOD | G_NOCORPSE);
  110.             if (urace.femalenum != NON_PM && mndx == urace.femalenum)
  111.                 mvitals[urace.malenum].mvflags |= (G_GENOD | G_NOCORPSE);
  112.  
  113.             u.uhp = -1;
  114.             if (how & PLAYER) {
  115.                 killer.format = KILLED_BY;
  116.                 Strcpy(killer.name, "genocidal confusion");
  117.             } else if (how & ONTHRONE) {
  118.                 /* player selected while on a throne */
  119.                 killer.format = KILLED_BY_AN;
  120.                 Strcpy(killer.name, "imperious order");
  121.             } else { /* selected player deliberately, not confused */
  122.                 killer.format = KILLED_BY_AN;
  123.                 Strcpy(killer.name, "scroll of genocide");
  124.             }
  125.  
  126.             /* Polymorphed characters will die as soon as they're rehumanized.
  127.              */
  128.             /* KMH -- Unchanging prevents rehumanization */
  129.             if (Upolyd && ptr != youmonst.data) {
  130.                 delayed_killer(POLYMORPH, killer.format, killer.name);
  131.                 You_feel("dead inside.");
  132.             } else
  133.                 done(GENOCIDED);
  134.         } else if (ptr == youmonst.data) {
  135.             rehumanize();
  136.         }
  137.         reset_rndmonst(mndx);
  138.         kill_genocided_monsters();
  139.         update_inventory(); /* in case identified eggs were affected */
  140.     } else {
  141.         int cnt = 0, census = monster_census(FALSE);
  142.  
  143.         if (!(mons[mndx].geno & G_UNIQ)
  144.             && !(mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT)))
  145.             for (i = rn1(3, 4); i > 0; i--) {
  146.                 if (!makemon(ptr, u.ux, u.uy, NO_MINVENT))
  147.                     break; /* couldn't make one */
  148.                 ++cnt;
  149.                 if (mvitals[mndx].mvflags & G_EXTINCT)
  150.                     break; /* just made last one */
  151.             }
  152.         if (cnt) {
  153.             /* accumulated 'cnt' doesn't take groups into account;
  154.                assume bringing in new mon(s) didn't remove any old ones */
  155.             cnt = monster_census(FALSE) - census;
  156.             pline("Sent in %s%s.", (cnt > 1) ? "some " : "",
  157.                   (cnt > 1) ? makeplural(buf) : an(buf));
  158.         } else
  159.             pline1(nothing_happens);
  160.     }
  161.  }
  162.  

punish

  1.  void
  2.  punish(sobj)
  3.  struct obj *sobj;
  4.  {
  5.     struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL)
  6.                                 ? sobj : (struct obj *) 0;
  7.  
  8.     /* KMH -- Punishment is still okay when you are riding */
  9.     if (!reuse_ball)
  10.         You("are being punished for your misbehavior!");
  11.     if (Punished) {
  12.         Your("iron ball gets heavier.");
  13.         uball->owt += 160 * (1 + sobj->cursed);
  14.         return;
  15.     }
  16.     if (amorphous(youmonst.data) || is_whirly(youmonst.data)
  17.         || unsolid(youmonst.data)) {
  18.         if (!reuse_ball) {
  19.             pline("A ball and chain appears, then falls away.");
  20.             dropy(mkobj(BALL_CLASS, TRUE));
  21.         } else {
  22.             dropy(reuse_ball);
  23.         }
  24.         return;
  25.     }
  26.     setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN);
  27.     if (!reuse_ball)
  28.         setworn(mkobj(BALL_CLASS, TRUE), W_BALL);
  29.     else
  30.         setworn(reuse_ball, W_BALL);
  31.     uball->spe = 1; /* special ball (see save) */
  32.  
  33.     /*
  34.      *  Place ball & chain if not swallowed.  If swallowed, the ball &
  35.      *  chain variables will be set at the next call to placebc().
  36.      */
  37.     if (!u.uswallow) {
  38.         placebc();
  39.         if (Blind)
  40.             set_bc(1);      /* set up ball and chain variables */
  41.         newsym(u.ux, u.uy); /* see ball&chain if can't see self */
  42.     }
  43.  }
  44.  

unpunish

  1.  /* remove the ball and chain */
  2.  void
  3.  unpunish()
  4.  {
  5.     struct obj *savechain = uchain;
  6.  
  7.     obj_extract_self(uchain);
  8.     newsym(uchain->ox, uchain->oy);
  9.     setworn((struct obj *) 0, W_CHAIN);
  10.     dealloc_obj(savechain);
  11.     uball->spe = 0;
  12.     setworn((struct obj *) 0, W_BALL);
  13.  }
  14.  

cant_revive

  1.  /* some creatures have special data structures that only make sense in their
  2.  * normal locations -- if the player tries to create one elsewhere, or to
  3.  * revive one, the disoriented creature becomes a zombie
  4.  */
  5.  boolean
  6.  cant_revive(mtype, revival, from_obj)
  7.  int *mtype;
  8.  boolean revival;
  9.  struct obj *from_obj;
  10.  {
  11.     /* SHOPKEEPERS can be revived now */
  12.     if (*mtype == PM_GUARD || (*mtype == PM_SHOPKEEPER && !revival)
  13.         || *mtype == PM_HIGH_PRIEST || *mtype == PM_ALIGNED_PRIEST
  14.         || *mtype == PM_ANGEL) {
  15.         *mtype = PM_HUMAN_ZOMBIE;
  16.         return TRUE;
  17.     } else if (*mtype == PM_LONG_WORM_TAIL) { /* for create_particular() */
  18.         *mtype = PM_LONG_WORM;
  19.         return TRUE;
  20.     } else if (unique_corpstat(&mons[*mtype])
  21.                && (!from_obj || !has_omonst(from_obj))) {
  22.         /* unique corpses (from bones or wizard mode wish) or
  23.            statues (bones or any wish) end up as shapechangers */
  24.         *mtype = PM_DOPPELGANGER;
  25.         return TRUE;
  26.     }
  27.     return FALSE;
  28.  }
  29.  

create_particular

  1.  /*
  2.  * Make a new monster with the type controlled by the user.
  3.  *
  4.  * Note:  when creating a monster by class letter, specifying the
  5.  * "strange object" (']') symbol produces a random monster rather
  6.  * than a mimic.  This behavior quirk is useful so don't "fix" it
  7.  * (use 'm'--or "mimic"--to create a random mimic).
  8.  *
  9.  * Used in wizard mode only (for ^G command and for scroll or spell
  10.  * of create monster).  Once upon a time, an earlier incarnation of
  11.  * this code was also used for the scroll/spell in explore mode.
  12.  */
  13.  boolean
  14.  create_particular()
  15.  {
  16.     char buf[BUFSZ], *bufp, monclass;
  17.     int which, tryct, i, firstchoice = NON_PM;
  18.     struct permonst *whichpm = NULL;
  19.     struct monst *mtmp;
  20.     boolean madeany = FALSE;
  21.     boolean maketame, makepeaceful, makehostile;
  22.     boolean randmonst = FALSE;
  23.  
  24.     tryct = 5;
  25.     do {
  26.         monclass = MAXMCLASSES;
  27.         which = urole.malenum; /* an arbitrary index into mons[] */
  28.         maketame = makepeaceful = makehostile = FALSE;
  29.         getlin("Create what kind of monster? [type the name or symbol]", buf);
  30.         bufp = mungspaces(buf);
  31.         if (*bufp == '\033')
  32.             return FALSE;
  33.         /* allow the initial disposition to be specified */
  34.         if (!strncmpi(bufp, "tame ", 5)) {
  35.             bufp += 5;
  36.             maketame = TRUE;
  37.         } else if (!strncmpi(bufp, "peaceful ", 9)) {
  38.             bufp += 9;
  39.             makepeaceful = TRUE;
  40.         } else if (!strncmpi(bufp, "hostile ", 8)) {
  41.             bufp += 8;
  42.             makehostile = TRUE;
  43.         }
  44.         /* decide whether a valid monster was chosen */
  45.         if (wizard && (!strcmp(bufp, "*") || !strcmp(bufp, "random"))) {
  46.             randmonst = TRUE;
  47.             break;
  48.         }
  49.         which = name_to_mon(bufp);
  50.         if (which >= LOW_PM)
  51.             break; /* got one */
  52.         monclass = name_to_monclass(bufp, &which);
  53.         if (which >= LOW_PM) {
  54.             monclass = MAXMCLASSES; /* matters below */
  55.             break;
  56.         } else if (monclass > 0) {
  57.             which = urole.malenum; /* reset from NON_PM */
  58.             break;
  59.         }
  60.         /* no good; try again... */
  61.         pline("I've never heard of such monsters.");
  62.     } while (--tryct > 0);
  63.  
  64.     if (!tryct) {
  65.         pline1(thats_enough_tries);
  66.     } else {
  67.         if (!randmonst) {
  68.             firstchoice = which;
  69.             if (cant_revive(&which, FALSE, (struct obj *) 0)) {
  70.                 /* wizard mode can override handling of special monsters */
  71.                 Sprintf(buf, "Creating %s instead; force %s?",
  72.                         mons[which].mname, mons[firstchoice].mname);
  73.                 if (yn(buf) == 'y')
  74.                     which = firstchoice;
  75.             }
  76.             whichpm = &mons[which];
  77.         }
  78.         for (i = 0; i <= multi; i++) {
  79.             if (monclass != MAXMCLASSES)
  80.                 whichpm = mkclass(monclass, 0);
  81.             else if (randmonst)
  82.                 whichpm = rndmonst();
  83.             mtmp = makemon(whichpm, u.ux, u.uy, NO_MM_FLAGS);
  84.             if (!mtmp) {
  85.                 /* quit trying if creation failed and is going to repeat */
  86.                 if (monclass == MAXMCLASSES && !randmonst)
  87.                     break;
  88.                 /* otherwise try again */
  89.                 continue;
  90.             }
  91.             if (maketame) {
  92.                 (void) tamedog(mtmp, (struct obj *) 0);
  93.             } else if (makepeaceful || makehostile) {
  94.                 mtmp->mtame = 0; /* sanity precaution */
  95.                 mtmp->mpeaceful = makepeaceful ? 1 : 0;
  96.                 set_malign(mtmp);
  97.             }
  98.             madeany = TRUE;
  99.             /* in case we got a doppelganger instead of what was asked
  100.                for, make it start out looking like what was asked for */
  101.             if (mtmp->cham != NON_PM && firstchoice != NON_PM
  102.                 && mtmp->cham != firstchoice)
  103.                 (void) newcham(mtmp, &mons[firstchoice], FALSE, FALSE);
  104.         }
  105.     }
  106.     return madeany;
  107.  }
  108.  
  109.  /*read.c*/