Source:NetHack 5.0.0/src/read.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to read.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/read.c#line12]], 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.

1. /* NetHack 5.0	read.c	$NHDT-Date: 1762577372 2025/11/07 20:49:32 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.323 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2012. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. #define Your_Own_Role(mndx)  ((mndx) == gu.urole.mnum)
9. #define Your_Own_Race(mndx)  ((mndx) == gu.urace.mnum)
10. 
11. staticfn boolean learnscrolltyp(short);
12. staticfn void cap_spe(struct obj *);
13. staticfn char *erode_obj_text(struct obj *, char *);
14. staticfn char *hawaiian_design(struct obj *, char *);
15. staticfn int read_ok(struct obj *);
16. staticfn void stripspe(struct obj *);
17. staticfn void p_glow1(struct obj *);
18. staticfn void p_glow2(struct obj *, const char *);
19. staticfn void p_glow3(struct obj *, const char *);
20. staticfn void forget(int);
21. staticfn int maybe_tame(struct monst *, struct obj *);
22. staticfn boolean can_center_cloud(coordxy, coordxy);
23. staticfn void display_stinking_cloud_positions(boolean);
24. staticfn void seffect_enchant_armor(struct obj **);
25. staticfn boolean disintegrate_cursed_armor(void);
26. staticfn void seffect_destroy_armor(struct obj **);
27. staticfn void seffect_confuse_monster(struct obj **);
28. staticfn void seffect_scare_monster(struct obj **);
29. staticfn void seffect_remove_curse(struct obj **);
30. staticfn void seffect_create_monster(struct obj **);
31. staticfn void seffect_enchant_weapon(struct obj **);
32. staticfn void seffect_taming(struct obj **);
33. staticfn void seffect_genocide(struct obj **);
34. staticfn void seffect_light(struct obj **);
35. staticfn void seffect_charging(struct obj **);
36. staticfn void seffect_amnesia(struct obj **);
37. staticfn void seffect_fire(struct obj **);
38. staticfn void seffect_earth(struct obj **);
39. staticfn void seffect_punishment(struct obj **);
40. staticfn void seffect_stinking_cloud(struct obj **);
41. staticfn void seffect_blank_paper(struct obj **);
42. staticfn void seffect_teleportation(struct obj **);
43. staticfn void seffect_gold_detection(struct obj **);
44. staticfn void seffect_food_detection(struct obj **);
45. staticfn void seffect_identify(struct obj **);
46. staticfn void seffect_magic_mapping(struct obj **);
47. #ifdef MAIL_STRUCTURES
48. staticfn void seffect_mail(struct obj **);
49. #endif /* MAIL_STRUCTURES */
50. staticfn void set_lit(coordxy, coordxy, genericptr);
51. staticfn void do_class_genocide(void);
52. staticfn void do_stinking_cloud(struct obj *, boolean);
53. staticfn boolean create_particular_parse(char *,
54.                                        struct _create_particular_data *);
55. staticfn boolean create_particular_creation(struct _create_particular_data *);
56. 
57. staticfn boolean
58. learnscrolltyp(short scrolltyp)
59. {
60.     if (!objects[scrolltyp].oc_name_known) {
61.         makeknown(scrolltyp);
62.         more_experienced(0, 10);
63.         return TRUE;
64.     } else
65.         return FALSE;
66. }
67. 
68. /* also called from teleport.c for scroll of teleportation */
69. void
70. learnscroll(struct obj *sobj)
71. {
72.     /* it's implied that sobj->dknown is set;
73.        we couldn't be reading this scroll otherwise */
74.     if (sobj->oclass != SPBOOK_CLASS)
75.         (void) learnscrolltyp(sobj->otyp);
76. }
77. 
78. /* max spe is +99, min is -99 */
79. staticfn void
80. cap_spe(struct obj *obj)
81. {
82.     if (obj) {
83.         if (abs(obj->spe) > SPE_LIM)
84.             obj->spe = sgn(obj->spe) * SPE_LIM;
85.     }
86. }
87. 
88. staticfn char *
89. erode_obj_text(struct obj *otmp, char *buf)
90. {
91.     int erosion = greatest_erosion(otmp);
92. 
93.     if (erosion)
94.         wipeout_text(buf, (int) (strlen(buf) * erosion / (2 * MAX_ERODE)),
95.                      otmp->o_id ^ (unsigned) ubirthday);
96.     return buf;
97. }
98. 
99. char *
100. tshirt_text(struct obj *tshirt, char *buf)
101. {
102.     static const char *const shirt_msgs[] = {
103.         /* Scott Bigham */
104.       "I explored the Dungeons of Doom and all I got was this lousy T-shirt!",
105.         "Is that Mjollnir in your pocket or are you just happy to see me?",
106.       "It's not the size of your sword, it's how #enhance'd you are with it.",
107.         "Madame Elvira's House O' Succubi Lifetime Customer",
108.         "Madame Elvira's House O' Succubi Employee of the Month",
109.         "Ludios Vault Guards Do It In Small, Dark Rooms",
110.         "Yendor Military Soldiers Do It In Large Groups",
111.         "I survived Yendor Military Boot Camp",
112.         "Ludios Accounting School Intra-Mural Lacrosse Team",
113.         "Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest",
114.         "Hey, black dragon!  Disintegrate THIS!",
115.         "I'm With Stupid -->",
116.         "Don't blame me, I voted for Izchak!",
117.         "Don't Panic", /* HHGTTG */
118.         "Furinkan High School Athletic Dept.",                /* Ranma 1/2 */
119.         "Hel-LOOO, Nurse!",                                   /* Animaniacs */
120.         "=^.^=",
121.         "100% goblin hair - do not wash",
122.         "Aberzombie and Fitch",
123.         "cK -- Cockatrice touches the Kop",
124.         "Don't ask me, I only adventure here",
125.         "Down with pants!",
126.         "d, your dog or a killer?",
127.         "FREE PUG AND NEWT!",
128.         "Go team ant!",
129.         "Got newt?",
130.         "Hello, my darlings!", /* Charlie Drake */
131.         "Hey!  Nymphs!  Steal This T-Shirt!",
132.         "I <3 Dungeon of Doom",
133.         "I <3 Maud",
134.         /* note: there is a similarly worded apron (alchemy smock) slogan */
135.         "I am a Valkyrie.  If you see me running, try to keep up.",
136.         "I am not a pack rat - I am a collector",
137.         "I bounced off a rubber tree",         /* Monkey Island */
138.         "Plunder Island Brimstone Beach Club", /* Monkey Island */
139.         "If you can read this, I can hit you with my polearm",
140.         "I'm confused!",
141.         "I scored with the princess",
142.         "I want to live forever or die in the attempt.",
143.         "Lichen Park",
144.         "LOST IN THOUGHT - please send search party",
145.         "Meat is Mordor",
146.         "Minetown Better Business Bureau",
147.         "Minetown Watch",
148.         /* Discworld riff; unfortunately long */
149.         ("Ms. Palm's House of Negotiable Affection--A Very Reputable"
150.             " House Of Disrepute"),
151.         "Protection Racketeer",
152.         "Real men love Crom",
153.         "Somebody stole my Mojo!",
154.         "The Hellhound Gang",
155.         "The Werewolves",
156.         "They Might Be Storm Giants",
157.         "Weapons don't kill people, I kill people",
158.         "White Zombie",
159.         "You're killing me!",
160.         "Anhur State University - Home of the Fighting Fire Ants!",
161.         "FREE HUGS",
162.         "Serial Ascender",
163.         "Real men are valkyries",
164.         "Young Men's Cavedigging Association",
165.         "Occupy Fort Ludios",
166.         "I couldn't afford this T-shirt so I stole it!",
167.         "Mind flayers suck",
168.         "I'm not wearing any pants",
169.         "Down with the living!",
170.         "Pudding farmer",
171.         "Vegetarian",
172.         "Hello, I'm War!",
173.         "It is better to light a candle than to curse the darkness",
174.         "It is easier to curse the darkness than to light a candle",
175.         /* expanded "rock--paper--scissors" featured in TV show "Big Bang
176.            Theory" although they didn't create it (and an actual T-shirt
177.            with pentagonal diagram showing which choices defeat which) */
178.         "rock--paper--scissors--lizard--Spock!",
179.         /* "All men must die -- all men must serve" challenge and response
180.            from book series _A_Song_of_Ice_and_Fire_ by George R.R. Martin,
181.            TV show "Game of Thrones" (probably an actual T-shirt too...) */
182.         "/Valar morghulis/ -- /Valar dohaeris/",
183.     };
184. 
185.     Strcpy(buf, shirt_msgs[tshirt->o_id % SIZE(shirt_msgs)]);
186.     return erode_obj_text(tshirt, buf);
187. }
188. 
189. char *
190. hawaiian_motif(struct obj *shirt, char *buf)
191. {
192.     static const char *const hawaiian_motifs[] = {
193.         /* birds */
194.         "flamingo",
195.         "parrot",
196.         "toucan",
197.         "bird of paradise", /* could be a bird or a flower */
198.         /* sea creatures */
199.         "sea turtle",
200.         "tropical fish",
201.         "jellyfish",
202.         "giant eel",
203.         "water nymph",
204.         /* plants */
205.         "plumeria",
206.         "orchid",
207.         "hibiscus flower",
208.         "palm tree",
209.         /* other */
210.         "hula dancer",
211.         "sailboat",
212.         "ukulele",
213.     };
214. 
215.     /* a tourist's starting shirt always has the same o_id; we need some
216.        additional randomness or else its design will never differ */
217.     unsigned motif = shirt->o_id ^ (unsigned) ubirthday;
218. 
219.     Strcpy(buf, hawaiian_motifs[motif % SIZE(hawaiian_motifs)]);
220.     return buf;
221. }
222. 
223. staticfn char *
224. hawaiian_design(struct obj *shirt, char *buf)
225. {
226.     static const char *const hawaiian_bgs[] = {
227.         /* solid colors */
228.         "purple",
229.         "yellow",
230.         "red",
231.         "blue",
232.         "orange",
233.         "black",
234.         "green",
235.         /* adjectives */
236.         "abstract",
237.         "geometric",
238.         "patterned",
239.         "naturalistic",
240.     };
241. 
242.     /* This hash method is slightly different than the one in hawaiian_motif;
243.        using the same formula in both cases may lead to some shirt combos
244.        never appearing, if the sizes of the two lists have common factors. */
245.     unsigned bg = shirt->o_id ^ (unsigned) ~ubirthday;
246. 
247.     Sprintf(buf, "%s on %s background",
248.             makeplural(hawaiian_motif(shirt, buf)),
249.             an(hawaiian_bgs[bg % SIZE(hawaiian_bgs)]));
250.     return buf;
251. }
252. 
253. char *
254. apron_text(struct obj *apron, char *buf)
255. {
256.     static const char *const apron_msgs[] = {
257.         "Kiss the cook",
258.         "I'm making SCIENCE!",
259.         "Don't mess with the chef",
260.         "Don't make me poison you",
261.         "Gehennom's Kitchen",
262.         "Rat: The other white meat",
263.         "If you can't stand the heat, get out of Gehennom!",
264.         "If we weren't meant to eat animals, why are they made out of meat?",
265.         "If you don't like the food, I'll stab you",
266.         /* In the movie "The Sum of All Fears", a Russian worker in a weapons
267.            facility wears a T-shirt that a translator says reads, "I am a
268.            bomb technician, if you see me running ... try to catch up."
269.            In nethack, the quote is far more suitable to an alchemy smock
270.            (particularly since so many of these others are about cooking)
271.            than a T-shirt and is paraphrased to simplify/shorten it.
272.            [later... turns out that this is already a T-shirt message:
273.             "I am a Valkyrie.  If you see me running, try to keep up."
274.            so this one has been revised a little:  added alchemist prefix,
275.            changed "keep up" to original source's "catch up"] */
276.         "I am an alchemist; if you see me running, try to catch up...",
277.     };
278. 
279.     Strcpy(buf, apron_msgs[apron->o_id % SIZE(apron_msgs)]);
280.     return erode_obj_text(apron, buf);
281. }
282. 
283. static const char *const candy_wrappers[] = {
284.     "",                         /* (none -- should never happen) */
285.     "Apollo",                   /* Lost */
286.     "Moon Crunchy",             /* South Park */
287.     "Snacky Cake",    "Chocolate Nuggie", "The Small Bar",
288.     "Crispy Yum Yum", "Nilla Crunchie",   "Berry Bar",
289.     "Choco Nummer",   "Om-nom", /* Cat Macro */
290.     "Fruity Oaty",              /* Serenity */
291.     "Wonka Bar",                /* Charlie and the Chocolate Factory */
292. };
293. 
294. /* return the text of a candy bar's wrapper */
295. const char *
296. candy_wrapper_text(struct obj *obj)
297. {
298.     /* modulo operation is just bullet proofing; 'spe' is already in range */
299.     return candy_wrappers[obj->spe % SIZE(candy_wrappers)];
300. }
301. 
302. /* assign a wrapper to a candy bar stack */
303. void
304. assign_candy_wrapper(struct obj *obj)
305. {
306.     if (obj->otyp == CANDY_BAR) {
307.         /* skips candy_wrappers[0] */
308.         obj->spe = 1 + rn2(SIZE(candy_wrappers) - 1);
309.     }
310.     return;
311. }
312. 
313. /* getobj callback for object to read */
314. staticfn int
315. read_ok(struct obj *obj)
316. {
317.     if (!obj)
318.         return GETOBJ_EXCLUDE;
319. 
320.     if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS)
321.         return GETOBJ_SUGGEST;
322. 
323.     return GETOBJ_DOWNPLAY;
324. }
325. 
326. DISABLE_WARNING_FORMAT_NONLITERAL
327. 
328. /* the #read command; read a scroll or spell book or various other things */
329. int
330. doread(void)
331. {
332.     static const char find_any_braille[] = "feel any Braille writing.";
333.     struct obj *scroll;
334.     boolean confused, nodisappear;
335.     int otyp;
336. 
337.     /*
338.      * Reading while blind is allowed in most cases, including the
339.      * Book of the Dead but not regular spellbooks.  For scrolls, the
340.      * description has to have been seen or magically learned (so only
341.      * when scroll->dknown is true):  hero recites the label while
342.      * holding the unfurled scroll.  We deliberately don't require
343.      * free hands because that would cripple scroll of remove curse,
344.      * but we ought to be requiring hands or at least limbs.  The
345.      * recitation could be sub-vocal; actual speech isn't required.
346.      *
347.      * Reading while confused is allowed and can produce alternate
348.      * outcome.
349.      *
350.      * Reading while stunned is currently allowed but probably should
351.      * be prevented....
352.      */
353. 
354.     gk.known = FALSE;
355.     if (check_capacity((char *) 0))
356.         return ECMD_OK;
357. 
358.     scroll = getobj("read", read_ok, GETOBJ_PROMPT);
359.     if (!scroll)
360.         return ECMD_CANCEL;
361.     otyp = scroll->otyp;
362.     scroll->pickup_prev = 0; /* no longer 'just picked up' */
363. 
364.     /* outrumor has its own blindness check */
365.     if (otyp == FORTUNE_COOKIE) {
366.         if (flags.verbose)
367.             You("break up the cookie and throw away the pieces.");
368.         outrumor(bcsign(scroll), BY_COOKIE);
369.         if (!Blind)
370.             if (!u.uconduct.literate++)
371.                 livelog_printf(LL_CONDUCT,
372.                                "became literate by reading a fortune cookie");
373.         useup(scroll);
374.         return ECMD_TIME;
375.     } else if (otyp == T_SHIRT || otyp == ALCHEMY_SMOCK
376.                || otyp == HAWAIIAN_SHIRT) {
377.         char buf[BUFSZ], *mesg;
378.         const char *endpunct;
379. 
380.         if (Blind) {
381.             You_cant(find_any_braille);
382.             return ECMD_OK;
383.         }
384.         /* can't read shirt worn under suit (under cloak is ok though) */
385.         if ((otyp == T_SHIRT || otyp == HAWAIIAN_SHIRT) && uarm
386.             && scroll == uarmu) {
387.             pline("%s shirt is obscured by %s%s.",
388.                   scroll->unpaid ? "That" : "Your", shk_your(buf, uarm),
389.                   suit_simple_name(uarm));
390.             return ECMD_OK;
391.         }
392.         if (otyp == HAWAIIAN_SHIRT) {
393.             pline("%s features %s.", flags.verbose ? "The design" : "It",
394.                   hawaiian_design(scroll, buf));
395.             return ECMD_TIME;
396.         }
397.         if (!u.uconduct.literate++)
398.             livelog_printf(LL_CONDUCT, "became literate by reading %s",
399.                            (scroll->otyp == T_SHIRT) ? "a T-shirt"
400.                            : "an apron");
401. 
402.         /* populate 'buf[]' */
403.         mesg = (otyp == T_SHIRT) ? tshirt_text(scroll, buf)
404.                                  : apron_text(scroll, buf);
405.         endpunct = "";
406.         if (flags.verbose) {
407.             int ln = (int) strlen(mesg);
408. 
409.             /* we will be displaying a sentence; need ending punctuation */
410.             if (ln > 0 && !strchr(".!?", mesg[ln - 1]))
411.                 endpunct = ".";
412.             pline("It reads:");
413.         }
414.         pline("\"%s\"%s", mesg, endpunct);
415.         return ECMD_TIME;
416.     } else if ((otyp == DUNCE_CAP || otyp == CORNUTHAUM)
417.         /* note: "DUNCE" isn't directly connected to tourists but
418.            if everyone could read it, they would always be able to
419.            trivially distinguish between the two types of conical hat;
420.            limiting this to tourists is better than rejecting it */
421.                && Role_if(PM_TOURIST)) {
422.         /* another note: the misspelling, "wizzard", is correct;
423.            that's what is written on Rincewind's pointy hat from
424.            Pratchett's Discworld series, along with a lot of stars;
425.            rather than inked on or painted on, treat them as stitched
426.            or even separate pieces of fabric which have been attached
427.            (don't recall whether the books mention anything like that...) */
428.         const char *cap_text = (otyp == DUNCE_CAP) ? "DUNCE" : "WIZZARD";
429. 
430.         if (scroll->o_id % 3) {
431.             /* no need to vary this when blind; "on this ___" is important
432.                because it suggests that there might be something on others */
433.             You_cant("find anything to read on this %s.",
434.                      simpleonames(scroll));
435.             return ECMD_OK;
436.         }
437.         pline("%s on the %s.  It reads:  %s.",
438.               !Blind ? "There is writing" : "You feel lettering",
439.               simpleonames(scroll), cap_text);
440.         if (!u.uconduct.literate++)
441.             livelog_printf(LL_CONDUCT, "became literate by reading %s",
442.                            (otyp == DUNCE_CAP) ? "a dunce cap"
443.                                                : "a cornuthaum");
444. 
445.         /* yet another note: despite the fact that player will recognize
446.            the object type, don't make it become a discovery for hero */
447.         trycall(scroll);
448.         return ECMD_TIME;
449.     } else if (otyp == CREDIT_CARD) {
450.         static const char *const card_msgs[] = {
451.             "Leprechaun Gold Tru$t - Shamrock Card",
452.             "Magic Memory Vault Charge Card",
453.             "Larn National Bank",                /* Larn */
454.             "First Bank of Omega",               /* Omega */
455.             "Bank of Zork - Frobozz Magic Card", /* Zork */
456.             "Ankh-Morpork Merchant's Guild Barter Card",
457.             "Ankh-Morpork Thieves' Guild Unlimited Transaction Card",
458.             "Ransmannsby Moneylenders Association",
459.             "Bank of Gehennom - 99% Interest Card",
460.             "Yendorian Express - Copper Card",
461.             "Yendorian Express - Silver Card",
462.             "Yendorian Express - Gold Card",
463.             "Yendorian Express - Mithril Card",
464.             "Yendorian Express - Platinum Card", /* must be last */
465.         };
466. 
467.         if (Blind) {
468.             You("feel the embossed numbers:");
469.         } else {
470.             if (flags.verbose)
471.                 pline("It reads:");
472.             pline("\"%s\"",
473.                   scroll->oartifact
474.                       ? card_msgs[SIZE(card_msgs) - 1]
475.                       : card_msgs[scroll->o_id % (SIZE(card_msgs) - 1)]);
476.         }
477.         /* Make a credit card number */
478.         pline("\"%d0%d %ld%d1 0%d%d0\"%s",
479.               (((int) scroll->o_id % 89) + 10),
480.               ((int) scroll->o_id % 4),
481.               ((((long) scroll->o_id * 499L) % 899999L) + 100000L),
482.               ((int) scroll->o_id % 10),
483.               (!((int) scroll->o_id % 3)),
484.               (((int) scroll->o_id * 7) % 10),
485.               (flags.verbose || Blind) ? "." : "");
486.         if (!u.uconduct.literate++)
487.             livelog_printf(LL_CONDUCT,
488.                            "became literate by reading a credit card");
489. 
490.         return ECMD_TIME;
491.     } else if (otyp == CAN_OF_GREASE) {
492.         pline("This %s has no label.", singular(scroll, xname));
493.         return ECMD_OK;
494.     } else if (otyp == MAGIC_MARKER) {
495.         static const int red_mons[] = {
496.             PM_FIRE_ANT, PM_PYROLISK, PM_HELL_HOUND, PM_IMP,
497.             PM_LARGE_MIMIC, PM_LEOCROTTA, PM_SCORPION, PM_XAN,
498.             PM_GIANT_BAT, PM_WATER_MOCCASIN, PM_FLESH_GOLEM,
499.             PM_BARBED_DEVIL, PM_MARILITH, PM_PIRANHA
500.         };
501.         char buf[BUFSZ];
502.         struct permonst *pm = &mons[red_mons[scroll->o_id % SIZE(red_mons)]];
503. 
504.         if (Blind) {
505.             You_cant(find_any_braille);
506.             return ECMD_OK;
507.         }
508.         if (flags.verbose)
509.             pline("It reads:");
510.         Sprintf(buf, "%s", pmname(pm, NEUTRAL));
511.         pline("\"Magic Marker(TM) %s Red Ink Marker Pen.  Water Soluble.\"",
512.               upwords(buf));
513.         if (!u.uconduct.literate++)
514.             livelog_printf(LL_CONDUCT,
515.                            "became literate by reading a magic marker");
516. 
517.         return ECMD_TIME;
518.     } else if (scroll->oclass == COIN_CLASS) {
519.         if (Blind)
520.             You("feel the embossed words:");
521.         else if (flags.verbose)
522.             You("read:");
523.         pline("\"1 Zorkmid.  857 GUE.  In Frobs We Trust.\"");
524.         if (!u.uconduct.literate++)
525.             livelog_printf(LL_CONDUCT,
526.                            "became literate by reading a coin's engravings");
527. 
528.         return ECMD_TIME;
529.     } else if (is_art(scroll, ART_ORB_OF_FATE)) {
530.         if (Blind)
531.             You("feel the engraved signature:");
532.         else
533.             pline("It is signed:");
534.         pline("\"Odin.\"");
535.         if (!u.uconduct.literate++)
536.             livelog_printf(LL_CONDUCT,
537.                    "became literate by reading the divine signature of Odin");
538. 
539.         return ECMD_TIME;
540.     } else if (otyp == CANDY_BAR) {
541.         const char *wrapper = candy_wrapper_text(scroll);
542. 
543.         if (Blind) {
544.             You_cant(find_any_braille);
545.             return ECMD_OK;
546.         }
547.         if (!*wrapper) {
548.             pline("The candy bar's wrapper is blank.");
549.             return ECMD_OK;
550.         }
551.         pline("The wrapper reads: \"%s\".", wrapper);
552.         if (!u.uconduct.literate++)
553.             livelog_printf(LL_CONDUCT,
554.                            "became literate by reading a candy bar wrapper");
555. 
556.         return ECMD_TIME;
557.     } else if (scroll->oclass != SCROLL_CLASS
558.                && scroll->oclass != SPBOOK_CLASS) {
559.         pline(silly_thing_to, "read");
560.         return ECMD_OK;
561.     } else if (Blind && otyp != SPE_BOOK_OF_THE_DEAD) {
562.         const char *what = 0;
563. 
564.         if (otyp == SPE_NOVEL)
565.             /* unseen novels are already distinguishable from unseen
566.                spellbooks so this isn't revealing any extra information */
567.             what = "words";
568.         else if (scroll->oclass == SPBOOK_CLASS)
569.             what = "mystic runes";
570.         else if (!scroll->dknown)
571.             what = "formula on the scroll";
572.         if (what) {
573.             pline("Being blind, you cannot read the %s.", what);
574.             return ECMD_OK;
575.         }
576.     }
577. 
578.     confused = (Confusion != 0);
579. #ifdef MAIL_STRUCTURES
580.     if (otyp == SCR_MAIL) {
581.         confused = FALSE; /* override */
582.         /* reading mail is a convenience for the player and takes
583.            place outside the game, so shouldn't affect gameplay;
584.            on the other hand, it starts by explicitly making the
585.            hero actively read something, which is pretty hard
586.            to simply ignore; as a compromise, if the player has
587.            maintained illiterate conduct so far, and this mail
588.            scroll didn't come from bones, ask for confirmation */
589.         if (!u.uconduct.literate) {
590.             if (!scroll->spe && y_n(
591.              "Reading mail will violate \"illiterate\" conduct.  Read anyway?"
592.                                    ) != 'y')
593.                 return ECMD_OK;
594.         }
595.     }
596. #endif
597. 
598.     /* Actions required to win the game aren't counted towards conduct */
599.     /* Novel conduct is handled in read_tribute so exclude it too */
600.     if (otyp != SPE_BOOK_OF_THE_DEAD && otyp != SPE_NOVEL
601.         && otyp != SPE_BLANK_PAPER && otyp != SCR_BLANK_PAPER)
602.         if (!u.uconduct.literate++)
603.             livelog_printf(LL_CONDUCT, "became literate by reading %s",
604.                            (scroll->oclass == SPBOOK_CLASS) ? "a book"
605.                            : (scroll->oclass == SCROLL_CLASS) ? "a scroll"
606.                              : something);
607. 
608.     if (scroll->oclass == SPBOOK_CLASS) {
609.         return study_book(scroll) ? ECMD_TIME : ECMD_OK;
610.     }
611.     scroll->in_use = TRUE; /* scroll, not spellbook, now being read */
612.     if (otyp != SCR_BLANK_PAPER) {
613.         boolean silently = !can_chant(&gy.youmonst);
614. 
615.         /* a few scroll feedback messages describe something happening
616.            to the scroll itself, so avoid "it disappears" for those */
617.         nodisappear = (otyp == SCR_FIRE
618.                        || (otyp == SCR_REMOVE_CURSE && scroll->cursed));
619.         if (Blind)
620.             pline(nodisappear
621.                       ? "You %s the formula on the scroll."
622.                       : "As you %s the formula on it, the scroll disappears.",
623.                   silently ? "cogitate" : "pronounce");
624.         else
625.             pline(nodisappear ? "You read the scroll."
626.                               : "As you read the scroll, it disappears.");
627.         if (confused) {
628.             if (Hallucination)
629.                 pline("Being so trippy, you screw up...");
630.             else
631.                 pline("Being confused, you %s the magic words...",
632.                       silently ? "misunderstand" : "mispronounce");
633.         }
634.     }
635.     if (!seffects(scroll)) {
636.         if (!objects[otyp].oc_name_known) {
637.             if (gk.known)
638.                 learnscroll(scroll);
639.             else
640.                 trycall(scroll);
641.         }
642.         scroll->in_use = FALSE;
643.         if (otyp != SCR_BLANK_PAPER)
644.             useup(scroll);
645.     }
646.     return ECMD_TIME;
647. }
648. 
649. RESTORE_WARNING_FORMAT_NONLITERAL
650. 
651. staticfn void
652. stripspe(struct obj *obj)
653. {
654.     if (obj->blessed || obj->spe <= 0) {
655.         pline1(nothing_happens);
656.     } else {
657.         /* order matters: message, shop handling, actual transformation */
658.         pline("%s briefly.", Yobjnam2(obj, "vibrate"));
659.         costly_alteration(obj, COST_UNCHRG);
660.         obj->spe = 0;
661.         if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN)
662.             obj->age = 0;
663.     }
664. }
665. 
666. staticfn void
667. p_glow1(struct obj *otmp)
668. {
669.     pline("%s briefly.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"));
670. }
671. 
672. staticfn void
673. p_glow2(struct obj *otmp, const char *color)
674. {
675.     pline("%s%s%s for a moment.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"),
676.           Blind ? "" : " ", Blind ? "" : hcolor(color));
677. }
678. 
679. staticfn void
680. p_glow3(struct obj *otmp, const char *color)
681. {
682.     pline("%s feebly%s%s for a moment.",
683.           Yobjnam2(otmp, Blind ? "vibrate" : "glow"),
684.           Blind ? "" : " ", Blind ? "" : hcolor(color));
685. }
686. 
687. /* getobj callback for object to charge */
688. int
689. charge_ok(struct obj *obj)
690. {
691.     if (!obj)
692.         return GETOBJ_EXCLUDE;
693. 
694.     if (obj->oclass == WAND_CLASS)
695.         return GETOBJ_SUGGEST;
696. 
697.     if (obj->oclass == RING_CLASS && objects[obj->otyp].oc_charged
698.         && obj->dknown && objects[obj->otyp].oc_name_known)
699.         return GETOBJ_SUGGEST;
700. 
701.     if (is_weptool(obj)) /* specific check before general tools */
702.         return GETOBJ_EXCLUDE;
703. 
704.     if (obj->oclass == TOOL_CLASS) {
705.         /* suggest tools that aren't oc_charged but can still be recharged */
706.         if (obj->otyp == BRASS_LANTERN
707.             || (obj->otyp == OIL_LAMP)
708.             /* only list magic lamps if they are not identified yet */
709.             || (obj->otyp == MAGIC_LAMP
710.                 && !objects[MAGIC_LAMP].oc_name_known)) {
711.             return GETOBJ_SUGGEST;
712.         }
713.         /* suggest chargeable tools only if discovered, to prevent leaking
714.            info (e.g. revealing if an unidentified 'flute' is magic or not) */
715.         if (objects[obj->otyp].oc_charged) {
716.             return (obj->dknown && objects[obj->otyp].oc_name_known)
717.                      ? GETOBJ_SUGGEST : GETOBJ_DOWNPLAY;
718.         }
719.         return GETOBJ_EXCLUDE;
720.     }
721.     /* why are weapons/armor considered charged anyway?
722.      * make them selectable even so for "feeling of loss" message */
723.     return GETOBJ_EXCLUDE_SELECTABLE;
724. }
725. 
726. /* recharge an object; curse_bless is -1 if the recharging implement
727.    was cursed, +1 if blessed, 0 otherwise. */
728. void
729. recharge(struct obj *obj, int curse_bless)
730. {
731.     int n;
732.     boolean is_cursed, is_blessed;
733. 
734.     is_cursed = curse_bless < 0;
735.     is_blessed = curse_bless > 0;
736. 
737.     if (obj->oclass == WAND_CLASS) {
738.         int lim = (obj->otyp == WAN_WISHING)
739.                       ? 1
740.                       : (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15;
741. 
742.         /* undo any prior cancellation, even when is_cursed */
743.         if (obj->spe == -1)
744.             obj->spe = 0;
745. 
746.         /*
747.          * Recharging might cause wands to explode.
748.          *      v = number of previous recharges
749.          *            v = percentage chance to explode on this attempt
750.          *                    v = cumulative odds for exploding
751.          *      0 :   0       0
752.          *      1 :   0.29    0.29
753.          *      2 :   2.33    2.62
754.          *      3 :   7.87   10.28
755.          *      4 :  18.66   27.02
756.          *      5 :  36.44   53.62
757.          *      6 :  62.97   82.83
758.          *      7 : 100     100
759.          */
760.         n = (int) obj->recharged;
761.         if (n > 0 && (obj->otyp == WAN_WISHING
762.                       || (n * n * n > rn2(7 * 7 * 7)))) { /* recharge_limit */
763.             wand_explode(obj, rnd(lim));
764.             return;
765.         }
766.         /* didn't explode, so increment the recharge count */
767.         obj->recharged = (unsigned) (n + 1);
768. 
769.         /* now handle the actual recharging */
770.         if (is_cursed) {
771.             stripspe(obj);
772.         } else {
773.             n = (lim == 1) ? 1 : rn1(5, lim + 1 - 5);
774.             if (!is_blessed)
775.                 n = rnd(n);
776. 
777.             if (obj->spe < n)
778.                 obj->spe = n;
779.             else
780.                 obj->spe++;
781.             if (obj->otyp == WAN_WISHING && obj->spe > 3) {
782.                 /* wands can't give more than three wishes; this code is
783.                    currently unreachable but left in case the rules for
784.                    wands of wishing change in future */
785.                 wand_explode(obj, 1);
786.                 return;
787.             }
788.             if (lim == 1)
789.                 p_glow3(obj, NH_BLUE);
790.             else if (obj->spe >= lim)
791.                 p_glow2(obj, NH_BLUE);
792.             else
793.                 p_glow1(obj);
794. #if 0 /*[shop price doesn't vary by charge count]*/
795.             /* update shop bill to reflect new higher price */
796.             if (obj->unpaid)
797.                 alter_cost(obj, 0L);
798. #endif
799.         }
800. 
801.     } else if (obj->oclass == RING_CLASS && objects[obj->otyp].oc_charged) {
802.         /* charging does not affect ring's curse/bless status */
803.         int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1;
804.         boolean is_on = (obj == uleft || obj == uright);
805. 
806.         /* destruction depends on current state, not adjustment */
807.         if (obj->spe > rn2(7) || obj->spe <= -5) {
808.             pline("%s momentarily, then %s!", Yobjnam2(obj, "pulsate"),
809.                   otense(obj, "explode"));
810.             if (is_on)
811.                 Ring_gone(obj);
812.             s = rnd(3 * abs(obj->spe)); /* amount of damage */
813.             useup(obj), obj = 0;
814.             losehp(Maybe_Half_Phys(s), "exploding ring", KILLED_BY_AN);
815.         } else {
816.             long mask = is_on ? (obj == uleft ? LEFT_RING : RIGHT_RING) : 0L;
817. 
818.             pline("%s spins %sclockwise for a moment.", Yname2(obj),
819.                   s < 0 ? "counter" : "");
820.             if (s < 0)
821.                 costly_alteration(obj, COST_DECHNT);
822.             /* cause attributes and/or properties to be updated */
823.             if (is_on)
824.                 Ring_off(obj);
825.             obj->spe += s; /* update the ring while it's off */
826.             if (is_on)
827.                 setworn(obj, mask), Ring_on(obj);
828.             /* oartifact: if a touch-sensitive artifact ring is
829.                ever created the above will need to be revised  */
830.             /* update shop bill to reflect new higher price */
831.             if (s > 0 && obj->unpaid)
832.                 alter_cost(obj, 0L);
833.         }
834. 
835.     } else if (obj->oclass == TOOL_CLASS) {
836.         int rechrg = (int) obj->recharged;
837. 
838.         if (objects[obj->otyp].oc_charged) {
839.             /* tools don't have a limit, but the counter used does */
840.             if (rechrg < 7) /* recharge_limit */
841.                 obj->recharged++;
842.         }
843.         switch (obj->otyp) {
844.         case BELL_OF_OPENING:
845.             if (is_cursed)
846.                 stripspe(obj);
847.             else if (is_blessed)
848.                 obj->spe += rnd(3);
849.             else
850.                 obj->spe += 1;
851.             if (obj->spe > 5)
852.                 obj->spe = 5;
853.             break;
854.         case MAGIC_MARKER:
855.         case TINNING_KIT:
856.         case EXPENSIVE_CAMERA:
857.             if (is_cursed) {
858.                 stripspe(obj);
859.             } else if (rechrg && obj->otyp == MAGIC_MARKER) {
860.                 /* previously recharged */
861.                 obj->recharged = 1; /* override increment done above */
862.                 if (obj->spe < 3)
863.                     Your("marker seems permanently dried out.");
864.                 else
865.                     pline1(nothing_happens);
866.             } else if (is_blessed) {
867.                 n = rn1(16, 15); /* 15..30 */
868.                 if (obj->spe + n <= 50)
869.                     obj->spe = 50;
870.                 else if (obj->spe + n <= 75)
871.                     obj->spe = 75;
872.                 else {
873.                     int chrg = (int) obj->spe;
874.                     if ((chrg + n) > 127)
875.                         obj->spe = 127;
876.                     else
877.                         obj->spe += n;
878.                 }
879.                 p_glow2(obj, NH_BLUE);
880.             } else {
881.                 n = rn1(11, 10); /* 10..20 */
882.                 if (obj->spe + n <= 50)
883.                     obj->spe = 50;
884.                 else {
885.                     int chrg = (int) obj->spe;
886. 
887.                     if (chrg + n > SPE_LIM)
888.                         obj->spe = SPE_LIM;
889.                     else
890.                         obj->spe += n;
891.                 }
892.                 p_glow2(obj, NH_WHITE);
893.             }
894.             break;
895.         case OIL_LAMP:
896.         case BRASS_LANTERN:
897.             if (is_cursed) {
898.                 stripspe(obj);
899.                 if (obj->lamplit) {
900.                     if (!Blind)
901.                         pline("%s out!", Tobjnam(obj, "go"));
902.                     end_burn(obj, TRUE);
903.                 }
904.             } else if (is_blessed) {
905.                 obj->spe = 1;
906.                 obj->age = 1500;
907.                 p_glow2(obj, NH_BLUE);
908.             } else {
909.                 obj->spe = 1;
910.                 obj->age += 750;
911.                 if (obj->age > 1500)
912.                     obj->age = 1500;
913.                 p_glow1(obj);
914.             }
915.             break;
916.         case CRYSTAL_BALL:
917.             if (obj->spe == -1) /* like wands, first uncancel */
918.                 obj->spe = 0;
919. 
920.             if (is_cursed) {
921.                 /* cursed scroll removes charges and curses ball */
922.                 /*stripspe(obj); -- doesn't do quite what we want...*/
923.                 if (!obj->cursed) {
924.                     p_glow2(obj, NH_BLACK);
925.                     curse(obj);
926.                 } else {
927.                     pline("%s briefly.", Yobjnam2(obj, "vibrate"));
928.                 }
929.                 if (obj->spe > 0)
930.                     costly_alteration(obj, COST_UNCHRG);
931.                 obj->spe = 0;
932.             } else if (is_blessed) {
933.                 /* blessed scroll sets charges to max and blesses ball */
934.                 obj->spe = 7;
935.                 p_glow2(obj, !obj->blessed ? NH_LIGHT_BLUE : NH_BLUE);
936.                 if (!obj->blessed)
937.                     bless(obj);
938.                 /* [shop price stays the same regardless of charges or BUC] */
939.             } else {
940.                 /* uncursed scroll increments charges and uncurses ball */
941.                 if (obj->spe < 7 || obj->cursed) {
942.                     n = rnd(2);
943.                     obj->spe = min(obj->spe + n, 7);
944.                     if (!obj->cursed) {
945.                         p_glow1(obj);
946.                     } else {
947.                         p_glow2(obj, NH_AMBER);
948.                         uncurse(obj);
949.                     }
950.                 } else {
951.                     /* charges at max and ball not being uncursed */
952.                     pline1(nothing_happens);
953.                 }
954.             }
955.             break;
956.         case HORN_OF_PLENTY:
957.         case BAG_OF_TRICKS:
958.         case CAN_OF_GREASE:
959.             if (is_cursed) {
960.                 stripspe(obj);
961.             } else if (is_blessed) {
962.                 if (obj->spe <= 10)
963.                     obj->spe += rn1(10, 6);
964.                 else
965.                     obj->spe += rn1(5, 6);
966.                 if (obj->spe > 50)
967.                     obj->spe = 50;
968.                 p_glow2(obj, NH_BLUE);
969.             } else {
970.                 obj->spe += rn1(5, 2);
971.                 if (obj->spe > 50)
972.                     obj->spe = 50;
973.                 p_glow1(obj);
974.             }
975.             break;
976.         case MAGIC_FLUTE:
977.         case MAGIC_HARP:
978.         case FROST_HORN:
979.         case FIRE_HORN:
980.         case DRUM_OF_EARTHQUAKE:
981.             if (is_cursed) {
982.                 stripspe(obj);
983.             } else if (is_blessed) {
984.                 obj->spe += d(2, 4);
985.                 if (obj->spe > 20)
986.                     obj->spe = 20;
987.                 p_glow2(obj, NH_BLUE);
988.             } else {
989.                 obj->spe += rnd(4);
990.                 if (obj->spe > 20)
991.                     obj->spe = 20;
992.                 p_glow1(obj);
993.             }
994.             break;
995.         default:
996.             goto not_chargable;
997.             /*NOTREACHED*/
998.             break;
999.         } /* switch */
1000. 
1001.     } else {
1002.  not_chargable:
1003.         You("have a feeling of loss.");
1004.     }
1005. 
1006.     /* prevent enchantment from getting out of range */
1007.     cap_spe(obj);
1008. }
1009. 
1010. /*
1011.  * Forget some things (e.g. after reading a scroll of amnesia).  When called,
1012.  * the following are always forgotten:
1013.  *      - felt ball & chain
1014.  *      - skill training
1015.  *
1016.  * Other things are subject to flags:
1017.  *      howmuch & ALL_SPELLS    = forget all spells
1018.  */
1019. staticfn void
1020. forget(int howmuch)
1021. {
1022.     struct monst *mtmp;
1023. 
1024.     if (Punished)
1025.         u.bc_felt = 0; /* forget felt ball&chain */
1026. 
1027.     if (howmuch & ALL_SPELLS)
1028.         losespells();
1029. 
1030.     /* Forget some skills. */
1031.     drain_weapon_skill(rnd(howmuch ? 5 : 3));
1032. 
1033.     /* forget having seen monsts (affects recognizing unseen ones by sound) */
1034.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
1035.         if (mtmp != u.usteed && mtmp != u.ustuck)
1036.             mtmp->meverseen = 0;
1037.     /* [perhaps ought to forget having seen every monster on every level] */
1038.     for (mtmp = gm.migrating_mons; mtmp; mtmp = mtmp->nmon)
1039.         mtmp->meverseen = 0;
1040. }
1041. 
1042. /* monster is hit by scroll of taming's effect */
1043. staticfn int
1044. maybe_tame(struct monst *mtmp, struct obj *sobj)
1045. {
1046.     int was_tame = mtmp->mtame;
1047.     unsigned was_peaceful = mtmp->mpeaceful;
1048. 
1049.     if (sobj->cursed) {
1050.         setmangry(mtmp, FALSE);
1051.         if (was_peaceful && !mtmp->mpeaceful)
1052.             return -1;
1053.     } else {
1054.         /* for a shopkeeper, tamedog() will call make_happy_shk() but
1055.            not tame the target, so call it even if taming gets resisted */
1056.         if (!resist(mtmp, sobj->oclass, 0, NOTELL) || mtmp->isshk)
1057.             (void) tamedog(mtmp, sobj, FALSE);
1058. 
1059.         if ((!was_peaceful && mtmp->mpeaceful) || was_tame != mtmp->mtame)
1060.             return 1;
1061.     }
1062.     return 0;
1063. }
1064. 
1065. /* Can a stinking cloud physically exist at a certain position?
1066.  * NOT the same thing as can_center_cloud.
1067.  */
1068. boolean
1069. valid_cloud_pos(coordxy x, coordxy y)
1070. {
1071.     if (!isok(x,y))
1072.         return FALSE;
1073.     return ACCESSIBLE(levl[x][y].typ) || is_pool(x, y) || is_lava(x, y);
1074. }
1075. 
1076. /* Callback for getpos_sethilite, also used in determining whether a scroll
1077.  * should have its regular effects, or not because it was out of range.
1078.  */
1079. staticfn boolean
1080. can_center_cloud(coordxy x, coordxy y)
1081. {
1082.     if (!valid_cloud_pos(x, y))
1083.         return FALSE;
1084.     return (cansee(x, y) && distu(x, y) < 32);
1085. }
1086. 
1087. staticfn void
1088. display_stinking_cloud_positions(boolean on_off)
1089. {
1090.     coordxy x, y, dx, dy;
1091.     int dist = 6;
1092. 
1093.     if (on_off) {
1094.         /* on */
1095.         tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos));
1096.         for (dx = -dist; dx <= dist; dx++)
1097.             for (dy = -dist; dy <= dist; dy++) {
1098.                 x = u.ux + dx;
1099.                 y = u.uy + dy;
1100.                 /* hero's location is allowed but highlighting the hero's
1101.                    spot makes map harder to read (if using '$' rather than
1102.                    by changing background color) */
1103.                 if (u_at(x, y))
1104.                     continue;
1105.                 if (can_center_cloud(x, y))
1106.                     tmp_at(x, y);
1107.             }
1108.     } else {
1109.         /* off */
1110.         tmp_at(DISP_END, 0);
1111.     }
1112. }
1113. 
1114. staticfn void
1115. seffect_enchant_armor(struct obj **sobjp)
1116. {
1117.     struct obj *sobj = *sobjp;
1118.     schar s;
1119.     boolean special_armor;
1120.     boolean same_color;
1121.     struct obj *otmp = some_armor(&gy.youmonst);
1122.     boolean sblessed = sobj->blessed;
1123.     boolean scursed = sobj->cursed;
1124.     boolean confused = (Confusion != 0);
1125.     boolean old_erodeproof, new_erodeproof;
1126. 
1127.     if (!otmp) {
1128.         strange_feeling(sobj, !Blind
1129.                         ? "Your skin glows then fades."
1130.                         : "Your skin feels warm for a moment.");
1131.         *sobjp = 0; /* useup() in strange_feeling() */
1132.         exercise(A_CON, !scursed);
1133.         exercise(A_STR, !scursed);
1134.         return;
1135.     }
1136.     if (confused) {
1137.         old_erodeproof = (otmp->oerodeproof != 0);
1138.         new_erodeproof = !scursed;
1139.         otmp->oerodeproof = 0; /* for messages */
1140.         if (Blind) {
1141.             otmp->rknown = FALSE;
1142.             pline("%s warm for a moment.", Yobjnam2(otmp, "feel"));
1143.         } else {
1144.             otmp->rknown = TRUE;
1145.             pline("%s covered by a %s %s %s!", Yobjnam2(otmp, "are"),
1146.                   scursed ? "mottled" : "shimmering",
1147.                   hcolor(scursed ? NH_BLACK : NH_GOLDEN),
1148.                   scursed ? "glow"
1149.                   : (is_shield(otmp) ? "layer" : "shield"));
1150.         }
1151.         if (new_erodeproof && (otmp->oeroded || otmp->oeroded2)) {
1152.             otmp->oeroded = otmp->oeroded2 = 0;
1153.             pline("%s as good as new!",
1154.                   Yobjnam2(otmp, Blind ? "feel" : "look"));
1155.         }
1156.         if (old_erodeproof && !new_erodeproof) {
1157.             /* restore old_erodeproof before shop charges */
1158.             otmp->oerodeproof = 1;
1159.             costly_alteration(otmp, COST_DEGRD);
1160.         }
1161.         otmp->oerodeproof = new_erodeproof ? 1 : 0;
1162.         return;
1163.     }
1164.     /* elven armor vibrates warningly when enchanted beyond a limit */
1165.     special_armor = is_elven_armor(otmp)
1166.         || (Role_if(PM_WIZARD) && otmp->otyp == CORNUTHAUM);
1167.     if (scursed)
1168.         same_color = (otmp->otyp == BLACK_DRAGON_SCALE_MAIL
1169.                       || otmp->otyp == BLACK_DRAGON_SCALES);
1170.     else
1171.         same_color = (otmp->otyp == SILVER_DRAGON_SCALE_MAIL
1172.                       || otmp->otyp == SILVER_DRAGON_SCALES
1173.                       || otmp->otyp == SHIELD_OF_REFLECTION);
1174.     if (Blind)
1175.         same_color = FALSE;
1176. 
1177.     /* KMH -- catch underflow */
1178.     s = scursed ? -otmp->spe : otmp->spe;
1179.     if (s > (special_armor ? 5 : 3) && rn2(s)) {
1180.         otmp->in_use = TRUE;
1181.         pline("%s violently %s%s%s for a while, then %s.", Yname2(otmp),
1182.               otense(otmp, Blind ? "vibrate" : "glow"),
1183.               (!Blind && !same_color) ? " " : "",
1184.               (Blind || same_color) ? "" : hcolor(scursed ? NH_BLACK
1185.                                                   : NH_SILVER),
1186.               otense(otmp, "evaporate"));
1187.         remove_worn_item(otmp, FALSE);
1188.         useup(otmp);
1189.         return;
1190.     }
1191.     if (s < -100)
1192.         s = -100; /* avoid integer overflow with very negative armor */
1193. 
1194.     /* Base power of the enchantment:
1195. 
1196.        2 for -1 to +0 armor;
1197.        1 for +1 to +2 armor;
1198.        0 for +3 to +4 armor, etc.
1199. 
1200.        When disenchanting, everything is done with reversed signs. */
1201.     s = (4 - s) / 2;
1202. 
1203.     /* Elven/artifact and nonmagical armor is easier to enchant;
1204.        blessed scrolls are more effective. */
1205.     if (special_armor)
1206.         ++s;
1207.     if (!objects[otmp->otyp].oc_magic)
1208.         ++s;
1209.     if (sblessed)
1210.         ++s;
1211. 
1212.     if (s <= 0) {
1213.         s = 0;
1214.         if (otmp->spe > 0 && !rn2(otmp->spe))
1215.             s = 1;
1216.     } else {
1217.         s = rnd(s);
1218.     }
1219.     if (s > 11)
1220.         s = 11;    /* unlikely but possible: avoids an overflow later */
1221. 
1222.     if (scursed)
1223.         s = -s;
1224. 
1225.     if (s >= 0 && Is_dragon_scales(otmp)) {
1226.         unsigned was_lit = otmp->lamplit;
1227.         int old_light = artifact_light(otmp) ? arti_light_radius(otmp) : 0;
1228. 
1229.         /* dragon scales get turned into dragon scale mail */
1230.         pline("%s merges and hardens!", Yname2(otmp));
1231.         setworn((struct obj *) 0, W_ARM);
1232.         /* assumes same order */
1233.         otmp->otyp += GRAY_DRAGON_SCALE_MAIL - GRAY_DRAGON_SCALES;
1234.         otmp->lamplit = 0; /* don't want bless() or uncurse() to adjust
1235.                             * light radius because scales -> scale_mail will
1236.                             * result in a second increase with own message */
1237.         if (sblessed) {
1238.             otmp->spe++;
1239.             cap_spe(otmp);
1240.             if (!otmp->blessed)
1241.                 bless(otmp);
1242.         } else if (otmp->cursed)
1243.             uncurse(otmp);
1244.         otmp->known = 1;
1245.         setworn(otmp, W_ARM);
1246.         if (otmp->unpaid)
1247.             alter_cost(otmp, 0L); /* shop bill */
1248.         otmp->lamplit = was_lit;
1249.         if (old_light)
1250.             maybe_adjust_light(otmp, old_light);
1251.         return;
1252.     }
1253.     pline("%s %s%s%s%s for a %s.", Yname2(otmp),
1254.           (s == 0) ? "violently " : "",
1255.           otense(otmp, Blind ? "vibrate" : "glow"),
1256.           (!Blind && !same_color) ? " " : "",
1257.           (Blind || same_color)
1258.           ? "" : hcolor(scursed ? NH_BLACK : NH_SILVER),
1259.           (s * s > 1) ? "while" : "moment");
1260.     /* [this cost handling will need updating if shop pricing is
1261.        ever changed to care about curse/bless status of armor] */
1262.     if (s < 0)
1263.         costly_alteration(otmp, COST_DECHNT);
1264.     if (scursed && !otmp->cursed)
1265.         curse(otmp);
1266.     else if (sblessed && !otmp->blessed)
1267.         bless(otmp);
1268.     else if (!scursed && otmp->cursed)
1269.         uncurse(otmp);
1270.     if (s) {
1271.         int oldspe = otmp->spe;
1272.         /* despite being schar, it shouldn't be possible for spe to wrap
1273.            here because it has been capped at 99 and s is quite small;
1274.            however, might need to change s if it takes spe past 99 */
1275.         otmp->spe += s;
1276.         cap_spe(otmp); /* make sure that it doesn't exceed SPE_LIM */
1277.         s = otmp->spe - oldspe; /* cap_spe() might have throttled 's' */
1278.         if (s) /* skip if it got changed to 0 */
1279.             adj_abon(otmp, s); /* adjust armor bonus for Dex or Int+Wis */
1280.         gk.known = otmp->known;
1281.         /* update shop bill to reflect new higher price */
1282.         if (s > 0 && otmp->unpaid)
1283.             alter_cost(otmp, 0L);
1284.     }
1285. 
1286.     if ((otmp->spe > (special_armor ? 5 : 3))
1287.         && (special_armor || !rn2(7)))
1288.         pline("%s %s.", Yobjnam2(otmp, "suddenly vibrate"),
1289.               Blind ? "again" : "unexpectedly");
1290. }
1291. 
1292. /* destroy a random cursed armor worn by hero */
1293. staticfn boolean
1294. disintegrate_cursed_armor(void)
1295. {
1296.     struct obj *armors[10];
1297.     int idx = 0;
1298. 
1299.     armors[0] = NULL;
1300.     if (uarm && uarm->cursed)
1301.         armors[idx++] = uarm;
1302.     if (uarmc && uarmc->cursed)
1303.         armors[idx++] = uarmc;
1304.     if (uarmh && uarmh->cursed)
1305.         armors[idx++] = uarmh;
1306.     if (uarms && uarms->cursed)
1307.         armors[idx++] = uarms;
1308.     if (uarmg && uarmg->cursed)
1309.         armors[idx++] = uarmg;
1310.     if (uarmf && uarmf->cursed)
1311.         armors[idx++] = uarmf;
1312.     if (uarmu && uarmu->cursed)
1313.         armors[idx++] = uarmu;
1314.     if (!idx)
1315.         return FALSE;
1316. 
1317.     if (disintegrate_arm(armors[rn2(idx)]))
1318.         return TRUE;
1319. 
1320.     return FALSE;
1321. }
1322. 
1323. staticfn void
1324. seffect_destroy_armor(struct obj **sobjp)
1325. {
1326.     struct obj *sobj = *sobjp;
1327.     struct obj *otmp = some_armor(&gy.youmonst);
1328.     boolean scursed = sobj->cursed;
1329.     boolean confused = (Confusion != 0);
1330.     boolean old_erodeproof, new_erodeproof;
1331. 
1332.     if (confused) {
1333.         if (!otmp) {
1334.             strange_feeling(sobj, "Your bones itch.");
1335.             *sobjp = 0; /* useup() in strange_feeling() */
1336.             exercise(A_STR, FALSE);
1337.             exercise(A_CON, FALSE);
1338.             return;
1339.         }
1340.         old_erodeproof = (otmp->oerodeproof != 0);
1341.         new_erodeproof = scursed;
1342.         otmp->oerodeproof = 0; /* for messages */
1343.         p_glow2(otmp, NH_PURPLE);
1344.         if (old_erodeproof && !new_erodeproof) {
1345.             /* restore old_erodeproof before shop charges */
1346.             otmp->oerodeproof = 1;
1347.             costly_alteration(otmp, COST_DEGRD);
1348.         }
1349.         otmp->oerodeproof = new_erodeproof ? 1 : 0;
1350.         return;
1351.     }
1352. 
1353.     if (scursed) {
1354.         if (otmp && otmp->cursed) {
1355.             /* armor and scroll both cursed */
1356.             pline("%s.", Yobjnam2(otmp, "vibrate"));
1357.             if (otmp->spe >= -6) {
1358.                 otmp->spe += -1;
1359.                 adj_abon(otmp, -1);
1360.             }
1361.             make_stunned((HStun & TIMEOUT) + (long) rn1(10, 10), TRUE);
1362.         } else if (disintegrate_arm(otmp)) {
1363.             gk.known = TRUE;
1364.             return;
1365.         }
1366.     } else {
1367.         boolean gets_choice = (otmp && sobj && sobj->blessed
1368.                                && count_worn_armor() > 1);
1369. 
1370.         if (gets_choice) {
1371.             struct obj *atmp;
1372. 
1373.             if (!objects[sobj->otyp].oc_name_known)
1374.                 pline("This is %s!", an(actualoname(sobj)));
1375.             gk.known = TRUE;
1376.             atmp = getobj("destroy", any_worn_armor_ok, GETOBJ_PROMPT);
1377.             /* check the return value, if user picked non-valid obj */
1378.             if (any_worn_armor_ok(atmp) == GETOBJ_SUGGEST)
1379.                 otmp = atmp;
1380.             if (disintegrate_arm(otmp)) {
1381.                 gk.known = TRUE;
1382.                 return;
1383.             }
1384.         } else if (sobj->blessed && disintegrate_cursed_armor()) {
1385.             gk.known = TRUE;
1386.             return;
1387.         } else if (!destroy_arm()) {
1388.             strange_feeling(sobj, "Your skin itches.");
1389.             *sobjp = 0; /* useup() in strange_feeling() */
1390.             exercise(A_STR, FALSE);
1391.             exercise(A_CON, FALSE);
1392.             return;
1393.         } else
1394.             gk.known = TRUE;
1395.     }
1396. }
1397. 
1398. staticfn void
1399. seffect_confuse_monster(struct obj **sobjp)
1400. {
1401.     struct obj *sobj = *sobjp;
1402.     boolean sblessed = sobj->blessed,
1403.             scursed = sobj->cursed,
1404.             confused = (Confusion != 0),
1405.             altfeedback = (Blind || Invisible);
1406.     const char *const hands = makeplural(body_part(HAND));
1407. 
1408.     if (gy.youmonst.data->mlet != S_HUMAN || scursed) {
1409.         if (!HConfusion)
1410.             You_feel("confused.");
1411.         make_confused(HConfusion + rnd(100), FALSE);
1412.     } else if (confused) {
1413.         if (!sblessed) {
1414.             Your("%s begin to %s%s.", hands,
1415.                  altfeedback ? "tingle" : "glow ",
1416.                  altfeedback ? "" : hcolor(NH_PURPLE));
1417.             make_confused(HConfusion + rnd(100), FALSE);
1418.         } else {
1419.             pline("A %s%s surrounds your %s.",
1420.                   altfeedback ? "" : hcolor(NH_RED),
1421.                   altfeedback ? "faint buzz" : " glow", body_part(HEAD));
1422.             make_confused(0L, TRUE);
1423.         }
1424.     } else {
1425.         /* scroll vs spell */
1426.         int incr = (sobj->oclass == SCROLL_CLASS) ? 3 : 0;
1427. 
1428.         if (!sblessed) {
1429.             if (altfeedback)
1430.                 Your("%s tingle%s.", hands, u.umconf ? " even more" : "");
1431.             else if (!u.umconf)
1432.                 Your("%s begin to glow %s.", hands, hcolor(NH_RED));
1433.             else
1434.                 pline_The("%s glow of your %s intensifies.", hcolor(NH_RED),
1435.                           hands);
1436.             incr += rnd(2);
1437.         } else {
1438.             if (altfeedback)
1439.                 Your("%s tingle %s sharply.", hands,
1440.                      u.umconf ? "even more" : "very");
1441.             else
1442.                 Your("%s glow %s brilliant %s.", hands,
1443.                      u.umconf ? "an even more" : "a", hcolor(NH_RED));
1444.             incr += rn1(8, 2);
1445.         }
1446.         /* after a while, repeated uses become less effective */
1447.         if (u.umconf >= 40)
1448.             incr = 1;
1449.         u.umconf += (unsigned) incr;
1450.     }
1451. }
1452. 
1453. staticfn void
1454. seffect_scare_monster(struct obj **sobjp)
1455. {
1456.     struct obj *sobj = *sobjp;
1457.     int otyp = sobj->otyp;
1458.     boolean scursed = sobj->cursed;
1459.     boolean confused = (Confusion != 0);
1460.     int ct = 0;
1461.     struct monst *mtmp;
1462. 
1463.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1464.         if (DEADMONSTER(mtmp))
1465.             continue;
1466.         if (cansee(mtmp->mx, mtmp->my)) {
1467.             if (confused || scursed) {
1468.                 mtmp->mflee = mtmp->mfrozen = mtmp->msleeping = 0;
1469.                 mtmp->mcanmove = 1;
1470.             } else if (!resist(mtmp, sobj->oclass, 0, NOTELL))
1471.                 monflee(mtmp, 0, FALSE, FALSE);
1472.             if (!mtmp->mtame)
1473.                 ct++; /* pets don't laugh at you */
1474.         }
1475.     }
1476.     if (otyp == SCR_SCARE_MONSTER || !ct) {
1477.         if (confused || scursed) {
1478.             Soundeffect(se_sad_wailing, 50);
1479.         } else {
1480.             Soundeffect(se_maniacal_laughter, 50);
1481.         }
1482.         You_hear("%s %s.", (confused || scursed) ? "sad wailing"
1483.                  : "maniacal laughter",
1484.                  !ct ? "in the distance" : "close by");
1485.     }
1486. }
1487. 
1488. staticfn void
1489. seffect_remove_curse(struct obj **sobjp)
1490. {
1491.     struct obj *sobj = *sobjp; /* scroll or fake spellbook */
1492.     int otyp = sobj->otyp;
1493.     boolean sblessed = sobj->blessed;
1494.     boolean scursed = sobj->cursed;
1495.     boolean confused = (Confusion != 0);
1496.     struct obj *obj, *nxto;
1497.     long wornmask;
1498. 
1499.     You_feel(!Hallucination
1500.              ? (!confused ? "like someone is helping you."
1501.                 : "like you need some help.")
1502.              : (!confused ? "in touch with the Universal Oneness."
1503.                 : "the power of the Force against you!"));
1504. 
1505.     if (scursed) {
1506.         pline_The("scroll disintegrates.");
1507.     } else {
1508.         /* 5.0: this used to use a straight
1509.                for (obj = invent; obj; obj = obj->nobj) {}
1510.            traversal, but for the confused case, secondary weapon might
1511.            become cursed and be dropped, moving it from the invent chain
1512.            to the floor chain at hero's spot, so we have to remember the
1513.            next object prior to processing the current one */
1514.         for (obj = gi.invent; obj; obj = nxto) {
1515.             nxto = obj->nobj;
1516.             /* gold isn't subject to cursing and blessing */
1517.             if (obj->oclass == COIN_CLASS)
1518.                 continue;
1519.             /* hide current scroll from itself so that perm_invent won't
1520.                show known blessed scroll losing bknown when confused */
1521.             if (obj == sobj && obj->quan == 1L)
1522.                 continue;
1523.             wornmask = (obj->owornmask & ~(W_BALL | W_ART | W_ARTI));
1524.             if (wornmask && !sblessed) {
1525.                 /* handle a couple of special cases; we don't
1526.                    allow auxiliary weapon slots to be used to
1527.                    artificially increase number of worn items */
1528.                 if (obj == uswapwep) {
1529.                     if (!u.twoweap)
1530.                         wornmask = 0L;
1531.                 } else if (obj == uquiver) {
1532.                     if (obj->oclass == WEAPON_CLASS) {
1533.                         /* mergeable weapon test covers ammo,
1534.                            missiles, spears, daggers & knives */
1535.                         if (!objects[obj->otyp].oc_merge)
1536.                             wornmask = 0L;
1537.                     } else if (obj->oclass == GEM_CLASS) {
1538.                         /* possibly ought to check whether
1539.                            alternate weapon is a sling... */
1540.                         if (!uslinging())
1541.                             wornmask = 0L;
1542.                     } else {
1543.                         /* weptools don't merge and aren't
1544.                            reasonable quivered weapons */
1545.                         wornmask = 0L;
1546.                     }
1547.                 }
1548.             }
1549.             if (sblessed || wornmask || obj->otyp == LOADSTONE
1550.                 /* this treats an in-use leash as a worn item but does not
1551.                    do the same for lit lamp/candle [seems inconsistent] */
1552.                 || (obj->otyp == LEASH && obj->leashmon)) {
1553.                 /* water price varies by curse/bless status */
1554.                 boolean shop_h2o = (obj->unpaid && obj->otyp == POT_WATER);
1555. 
1556.                 if (confused) {
1557.                     blessorcurse(obj, 2);
1558.                     /* lose knowledge of this object's curse/bless
1559.                        state (even if it didn't actually change) */
1560.                     obj->bknown = 0;
1561.                     /* blessorcurse() only affects uncursed items
1562.                        so no need to worry about price of water
1563.                        going down (hence no costly_alteration) */
1564.                     if (shop_h2o && (obj->cursed || obj->blessed))
1565.                         alter_cost(obj, 0L); /* price goes up */
1566.                 } else if (obj->cursed) {
1567.                     if (shop_h2o)
1568.                         costly_alteration(obj, COST_UNCURS);
1569.                     uncurse(obj);
1570.                     /* if the object was known to be cursed and is now
1571.                        known not to be, make the scroll known; it's
1572.                        trivial to identify anyway by comparing inventory
1573.                        before and after */
1574.                     if (obj->bknown && otyp == SCR_REMOVE_CURSE)
1575.                         learnscrolltyp(SCR_REMOVE_CURSE);
1576.                 }
1577.             }
1578.         }
1579.         /* if riding, treat steed's saddle as if part of hero's invent */
1580.         if (u.usteed && (obj = which_armor(u.usteed, W_SADDLE)) != 0) {
1581.             if (confused) {
1582.                 blessorcurse(obj, 2);
1583.                 obj->bknown = 0; /* skip set_bknown() */
1584.             } else if (obj->cursed) {
1585.                 uncurse(obj);
1586.                 /* like rndcurse(sit.c), effect on regular inventory
1587.                    doesn't show things glowing but saddle does */
1588.                 if (!Blind) {
1589.                     pline("%s %s.", Yobjnam2(obj, "glow"),
1590.                               hcolor("amber"));
1591.                     obj->bknown = Hallucination ? 0 : 1;
1592.                 } else {
1593.                     obj->bknown = 0; /* skip set_bknown() */
1594.                 }
1595.             }
1596.         }
1597.     }
1598.     if (Punished && !confused)
1599.         unpunish();
1600.     if (u.utrap && u.utraptype == TT_BURIEDBALL) {
1601.         buried_ball_to_freedom();
1602.         pline_The("clasp on your %s vanishes.", body_part(LEG));
1603.     }
1604.     update_inventory();
1605. }
1606. 
1607. staticfn void
1608. seffect_create_monster(struct obj **sobjp)
1609. {
1610.     struct obj *sobj = *sobjp;
1611.     boolean sblessed = sobj->blessed;
1612.     boolean scursed = sobj->cursed;
1613.     boolean confused = (Confusion != 0);
1614. 
1615.     if (create_critters(1 + ((confused || scursed) ? 12 : 0)
1616.                         + ((sblessed || rn2(73)) ? 0 : rnd(4)),
1617.                         confused ? &mons[PM_ACID_BLOB]
1618.                         : (struct permonst *) 0,
1619.                         FALSE))
1620.         gk.known = TRUE;
1621.     /* no need to flush monsters; we ask for identification only if the
1622.      * monsters are not visible
1623.      */
1624. }
1625. 
1626. staticfn void
1627. seffect_enchant_weapon(struct obj **sobjp)
1628. {
1629.     struct obj *sobj = *sobjp;
1630.     boolean sblessed = sobj->blessed;
1631.     boolean scursed = sobj->cursed;
1632.     boolean confused = (Confusion != 0);
1633.     boolean old_erodeproof, new_erodeproof;
1634.     int s;
1635. 
1636.     /* [What about twoweapon mode?  Proofing/repairing/enchanting both
1637.        would be too powerful, but shouldn't we choose randomly between
1638.        primary and secondary instead of always acting on primary?] */
1639.     if (confused && uwep
1640.         && erosion_matters(uwep) && uwep->oclass != ARMOR_CLASS) {
1641.         old_erodeproof = (uwep->oerodeproof != 0);
1642.         new_erodeproof = !scursed;
1643.         uwep->oerodeproof = 0; /* for messages */
1644.         if (Blind) {
1645.             uwep->rknown = FALSE;
1646.             Your("weapon feels warm for a moment.");
1647.         } else {
1648.             uwep->rknown = TRUE;
1649.             pline("%s covered by a %s %s %s!", Yobjnam2(uwep, "are"),
1650.                   scursed ? "mottled" : "shimmering",
1651.                   hcolor(scursed ? NH_PURPLE : NH_GOLDEN),
1652.                   scursed ? "glow" : "shield");
1653.         }
1654.         if (new_erodeproof && (uwep->oeroded || uwep->oeroded2)) {
1655.             uwep->oeroded = uwep->oeroded2 = 0;
1656.             pline("%s as good as new!",
1657.                   Yobjnam2(uwep, Blind ? "feel" : "look"));
1658.         }
1659.         if (old_erodeproof && !new_erodeproof) {
1660.             /* restore old_erodeproof before shop charges */
1661.             uwep->oerodeproof = 1;
1662.             costly_alteration(uwep, COST_DEGRD);
1663.         }
1664.         uwep->oerodeproof = new_erodeproof ? 1 : 0;
1665.         return;
1666.     }
1667.     s = scursed ? -1
1668.         : !uwep ? 1 /* guard further tests against null pointer */
1669.           : (uwep->spe >= 9) ? (rn2(uwep->spe) == 0) /* usually 0, maybe  1 */
1670.             : sblessed ? rnd(3 - uwep->spe / 3) /* >= 9 case prevents rnd(0) */
1671.               : 1; /* uncursed */
1672.     if (!chwepon(sobj, s))
1673.         *sobjp = 0; /* nothing enchanted: strange_feeling -> useup */
1674.     if (uwep)
1675.         cap_spe(uwep);
1676. }
1677. 
1678. staticfn void
1679. seffect_taming(struct obj **sobjp)
1680. {
1681.     struct obj *sobj = *sobjp;
1682.     boolean confused = (Confusion != 0);
1683.     int candidates, res, results, vis_results;
1684. 
1685.     if (u.uswallow) {
1686.         candidates = 1;
1687.         results = vis_results = maybe_tame(u.ustuck, sobj);
1688.     } else {
1689.         int i, j, bd = confused ? 5 : 1;
1690.         struct monst *mtmp;
1691. 
1692.         /* note: maybe_tame() can return either positive or
1693.            negative values, but not both for the same scroll */
1694.         candidates = results = vis_results = 0;
1695.         for (i = -bd; i <= bd; i++)
1696.             for (j = -bd; j <= bd; j++) {
1697.                 if (!isok(u.ux + i, u.uy + j))
1698.                     continue;
1699.                 if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0
1700.                     || (!i && !j && (mtmp = u.usteed) != 0)) {
1701.                     ++candidates;
1702.                     res = maybe_tame(mtmp, sobj);
1703.                     results += res;
1704.                     if (canspotmon(mtmp))
1705.                         vis_results += res;
1706.                 }
1707.             }
1708.     }
1709.     if (!results) {
1710.         pline("Nothing interesting %s.",
1711.               !candidates ? "happens" : "seems to happen");
1712.     } else {
1713.         pline_The("neighborhood %s %sfriendlier.",
1714.                   vis_results ? "is" : "seems",
1715.                   (results < 0) ? "un" : "");
1716.         if (vis_results > 0)
1717.             gk.known = TRUE;
1718.     }
1719. }
1720. 
1721. staticfn void
1722. seffect_genocide(struct obj **sobjp)
1723. {
1724.     struct obj *sobj = *sobjp;
1725.     int otyp = sobj->otyp;
1726.     boolean sblessed = sobj->blessed;
1727.     boolean scursed = sobj->cursed;
1728.     boolean already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
1729.                              || objects[otyp].oc_name_known);
1730. 
1731.     if (!already_known)
1732.         You("have found a scroll of genocide!");
1733.     gk.known = TRUE;
1734.     if (sblessed)
1735.         do_class_genocide();
1736.     else
1737.         do_genocide((!scursed) | (2 * !!Confusion));
1738. }
1739. 
1740. staticfn void
1741. seffect_light(struct obj **sobjp)
1742. {
1743.     struct obj *sobj = *sobjp;
1744.     boolean sblessed = sobj->blessed;
1745.     boolean scursed = sobj->cursed;
1746.     boolean confused = (Confusion != 0);
1747. 
1748.     if (!confused) {
1749.         if (!Blind)
1750.             gk.known = TRUE;
1751.         litroom(!scursed, sobj);
1752.         if (!scursed) {
1753.             if (lightdamage(sobj, TRUE, 5))
1754.                 gk.known = TRUE;
1755.         }
1756.     } else {
1757.         int pm = scursed ? PM_BLACK_LIGHT : PM_YELLOW_LIGHT;
1758. 
1759.         if ((svm.mvitals[pm].mvflags & G_GONE)) {
1760.             pline("Tiny lights sparkle in the air momentarily.");
1761.         } else {
1762.             /* surround with cancelled tame lights which won't explode */
1763.             struct monst *mon;
1764.             boolean sawlights = FALSE;
1765.             int i, numlights = rn1(2, 3) + (sblessed * 2);
1766. 
1767.             for (i = 0; i < numlights; ++i) {
1768.                 mon = makemon(&mons[pm], u.ux, u.uy,
1769.                               MM_EDOG | NO_MINVENT | MM_NOMSG);
1770.                 if (mon) {
1771.                     initedog(mon, TRUE);
1772.                     mon->msleeping = 0;
1773.                     mon->mcan = TRUE;
1774.                     if (canspotmon(mon))
1775.                         sawlights = TRUE;
1776.                     newsym(mon->mx, mon->my);
1777.                 }
1778.             }
1779.             if (sawlights) {
1780.                 pline("Lights appear all around you!");
1781.                 gk.known = TRUE;
1782.             }
1783.         }
1784.     }
1785. }
1786. 
1787. staticfn void
1788. seffect_charging(struct obj **sobjp)
1789. {
1790.     struct obj *sobj = *sobjp;
1791.     int otyp = sobj->otyp;
1792.     boolean sblessed = sobj->blessed;
1793.     boolean scursed = sobj->cursed;
1794.     boolean confused = (Confusion != 0);
1795.     boolean already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
1796.                              || objects[otyp].oc_name_known);
1797.     struct obj *otmp;
1798. 
1799.     if (confused) {
1800.         if (scursed) {
1801.             You_feel("discharged.");
1802.             u.uen = 0;
1803.         } else {
1804.             You_feel("charged up!");
1805.             u.uen += d(sblessed ? 6 : 4, 4);
1806.             if (u.uen > u.uenmax) /* if current energy is already at   */
1807.                 u.uenmax = u.uen; /* or near maximum, increase maximum */
1808.             else
1809.                 u.uen = u.uenmax; /* otherwise restore current to max  */
1810.         }
1811.         disp.botl = TRUE;
1812.         return;
1813.     }
1814.     /* known = TRUE; -- handled inline here */
1815.     if (!already_known) {
1816.         pline("This is a charging scroll.");
1817.         learnscroll(sobj);
1818.     }
1819.     /* use it up now to prevent it from showing in the
1820.        getobj picklist because the "disappears" message
1821.        was already delivered */
1822.     useup(sobj);
1823.     *sobjp = 0; /* it's gone */
1824.     otmp = getobj("charge", charge_ok, GETOBJ_PROMPT | GETOBJ_ALLOWCNT);
1825.     if (otmp)
1826.         recharge(otmp, scursed ? -1 : sblessed ? 1 : 0);
1827. }
1828. 
1829. staticfn void
1830. seffect_amnesia(struct obj **sobjp)
1831. {
1832.     struct obj *sobj = *sobjp;
1833.     boolean sblessed = sobj->blessed;
1834. 
1835.     gk.known = TRUE;
1836.     forget((!sblessed ? ALL_SPELLS : 0));
1837.     if (Hallucination) /* Ommmmmm! */
1838.         Your("mind releases itself from mundane concerns.");
1839.     else if (!strncmpi(svp.plname, "Maud", 4))
1840.         pline("As your mind turns inward on itself,"
1841.               " you forget everything else.");
1842.     else if (rn2(2))
1843.         pline("Who was that Maud person anyway?");
1844.     else
1845.         pline("Thinking of Maud you forget everything else.");
1846.     exercise(A_WIS, FALSE);
1847. }
1848. 
1849. staticfn void
1850. seffect_fire(struct obj **sobjp)
1851. {
1852.     struct obj *sobj = *sobjp;
1853.     int otyp = sobj->otyp;
1854.     boolean sblessed = sobj->blessed;
1855.     boolean confused = (Confusion != 0);
1856.     boolean already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
1857.                              || objects[otyp].oc_name_known);
1858.     coord cc;
1859.     int dam, cval;
1860. 
1861.     cc.x = u.ux;
1862.     cc.y = u.uy;
1863.     cval = bcsign(sobj);
1864.     dam = (2 * (rn1(3, 3) + 2 * cval) + 1) / 3;
1865.     useup(sobj);
1866.     *sobjp = 0; /* it's gone */
1867.     if (!already_known)
1868.         (void) learnscrolltyp(SCR_FIRE);
1869.     if (confused) {
1870.         if (Underwater) {
1871.             pline("A little %s around you vaporizes.", hliquid("water"));
1872.         }
1873.         else if (Fire_resistance) {
1874.             shieldeff(u.ux, u.uy);
1875.             monstseesu(M_SEEN_FIRE);
1876.             if (!Blind)
1877.                 pline("Oh, look, what a pretty fire in your %s.",
1878.                       makeplural(body_part(HAND)));
1879.             else
1880.                 You_feel("a pleasant warmth in your %s.",
1881.                          makeplural(body_part(HAND)));
1882.         } else {
1883.             monstunseesu(M_SEEN_FIRE);
1884.             pline_The("scroll catches fire and you burn your %s.",
1885.                       makeplural(body_part(HAND)));
1886.             losehp(1, "scroll of fire", KILLED_BY_AN);
1887.         }
1888.         return;
1889.     }
1890.     if (Underwater) {
1891.         pline_The("%s around you vaporizes violently!", hliquid("water"));
1892.     } else {
1893.         if (sblessed) {
1894.             if (!already_known)
1895.                 pline("This is a scroll of fire!");
1896.             dam *= 5;
1897.             pline("Where do you want to center the explosion?");
1898.             getpos_sethilite(display_stinking_cloud_positions,
1899.                              can_center_cloud);
1900.             (void) getpos(&cc, TRUE, "the desired position");
1901.             if (!can_center_cloud(cc.x, cc.y)) {
1902.                 /* try to reach too far, get burned */
1903.                 cc.x = u.ux;
1904.                 cc.y = u.uy;
1905.             }
1906.         }
1907.         if (u_at(cc.x, cc.y)) {
1908.             pline_The("scroll erupts in a tower of flame!");
1909.             iflags.last_msg = PLNMSG_TOWER_OF_FLAME; /* for explode() */
1910.             burn_away_slime();
1911.         }
1912.     }
1913. #define ZT_SPELL_O_FIRE 11 /* explained in splatter_burning_oil(explode.c) */
1914.     explode(cc.x, cc.y, ZT_SPELL_O_FIRE, dam, SCROLL_CLASS, EXPL_FIERY);
1915. #undef ZT_SPELL_O_FIRE
1916. }
1917. 
1918. staticfn void
1919. seffect_earth(struct obj **sobjp)
1920. {
1921.     struct obj *sobj = *sobjp;
1922.     boolean sblessed = sobj->blessed;
1923.     boolean scursed = sobj->cursed;
1924.     boolean confused = (Confusion != 0);
1925. 
1926.     /* TODO: handle steeds */
1927.     if (!Is_rogue_level(&u.uz) && has_ceiling(&u.uz)
1928.         && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
1929.         coordxy x, y;
1930.         int nboulders = 0;
1931. 
1932.         /* Identify the scroll */
1933.         if (u.uswallow) {
1934.             You_hear("rumbling.");
1935.         } else {
1936.             if (!avoid_ceiling(&u.uz)) {
1937.                 pline_The("%s rumbles %s you!", ceiling(u.ux, u.uy),
1938.                           sblessed ? "around" : "above");
1939.             } else {
1940.                 char matbuf[BUFSZ];
1941.                 const char *const avalanche = "avalanche";
1942. 
1943.                 Sprintf(matbuf, "%s",
1944.                         sblessed ? makeplural(avalanche) : an(avalanche));
1945.                 pline("%s of boulders %s %s you!",
1946.                       upstart(matbuf), vtense(matbuf, "materialize"),
1947.                       sblessed ? "around" : "above");
1948.             }
1949.         }
1950.         gk.known = 1;
1951.         sokoban_guilt();
1952. 
1953.         /* Loop through the surrounding squares */
1954.         if (!scursed)
1955.             for (x = u.ux - 1; x <= u.ux + 1; x++) {
1956.                 for (y = u.uy - 1; y <= u.uy + 1; y++) {
1957.                     /* Is this a suitable spot? */
1958.                     if (isok(x, y) && !closed_door(x, y)
1959.                         && !IS_OBSTRUCTED(levl[x][y].typ)
1960.                         && !IS_AIR(levl[x][y].typ)
1961.                         && (x != u.ux || y != u.uy)) {
1962.                         nboulders +=
1963.                             drop_boulder_on_monster(x, y, confused, TRUE);
1964.                     }
1965.                 }
1966.             }
1967.         /* Attack the player */
1968.         if (!sblessed) {
1969.             drop_boulder_on_player(confused, !scursed, TRUE, FALSE);
1970.         } else if (!nboulders)
1971.             pline("But nothing else happens.");
1972.     }
1973. }
1974. 
1975. staticfn void
1976. seffect_punishment(struct obj **sobjp)
1977. {
1978.     struct obj *sobj = *sobjp;
1979.     boolean sblessed = sobj->blessed;
1980.     boolean confused = (Confusion != 0);
1981. 
1982.     gk.known = TRUE;
1983.     if (confused || sblessed) {
1984.         You_feel("guilty.");
1985.         return;
1986.     }
1987.     punish(sobj);
1988. }
1989. 
1990. staticfn void
1991. seffect_stinking_cloud(struct obj **sobjp)
1992. {
1993.     struct obj *sobj = *sobjp;
1994.     int otyp = sobj->otyp;
1995.     boolean already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
1996.                              || objects[otyp].oc_name_known);
1997. 
1998.     if (!already_known)
1999.         You("have found a scroll of stinking cloud!");
2000.     gk.known = TRUE;
2001.     do_stinking_cloud(sobj, already_known);
2002. }
2003. 
2004. staticfn void
2005. seffect_blank_paper(struct obj **sobjp UNUSED)
2006. {
2007.     if (Blind)
2008.         You("don't remember there being any magic words on this scroll.");
2009.     else
2010.         pline("This scroll seems to be blank.");
2011.     gk.known = TRUE;
2012. }
2013. 
2014. staticfn void
2015. seffect_teleportation(struct obj **sobjp)
2016. {
2017.     struct obj *sobj = *sobjp;
2018.     boolean scursed = sobj->cursed;
2019.     boolean confused = (Confusion != 0);
2020. 
2021.     if (confused || scursed) {
2022.         level_tele();
2023.         /* gives "materialize on different/same level!" message, must
2024.            be a teleport scroll */
2025.         gk.known = TRUE;
2026.     } else {
2027.         scrolltele(sobj);
2028.         /* this will call learnscroll() as appropriate, and has results
2029.            which maybe shouldn't result in the scroll becoming known;
2030.            either way, no need to set gk.known here */
2031.     }
2032. }
2033. 
2034. staticfn void
2035. seffect_gold_detection(struct obj **sobjp)
2036. {
2037.     struct obj *sobj = *sobjp;
2038.     boolean scursed = sobj->cursed;
2039.     boolean confused = (Confusion != 0);
2040. 
2041.     if ((confused || scursed) ? trap_detect(sobj) : gold_detect(sobj))
2042.         *sobjp = 0; /* failure: strange_feeling() -> useup() */
2043. }
2044. 
2045. staticfn void
2046. seffect_food_detection(struct obj **sobjp)
2047. {
2048.     struct obj *sobj = *sobjp;
2049. 
2050.     if (food_detect(sobj))
2051.         *sobjp = 0; /* nothing detected: strange_feeling -> useup */
2052. }
2053. 
2054. staticfn void
2055. seffect_identify(struct obj **sobjp)
2056. {
2057.     struct obj *sobj = *sobjp;
2058.     int otyp = sobj->otyp;
2059.     boolean is_scroll = (sobj->oclass == SCROLL_CLASS);
2060.     boolean sblessed = sobj->blessed;
2061.     boolean scursed = sobj->cursed;
2062.     boolean confused = (Confusion != 0);
2063.     boolean already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
2064.                              || objects[otyp].oc_name_known);
2065. 
2066.     if (is_scroll) { /* scroll of identify */
2067.         /* known = TRUE; -- handled inline here */
2068.         /* use up the scroll first, before learnscrolltyp() -> makeknown()
2069.            performs perm_invent update; also simplifies empty invent check */
2070.         useup(sobj);
2071.         *sobjp = 0; /* it's gone */
2072.         /* scroll just identifies itself for any scroll read while confused
2073.            or for cursed scroll read without knowing identify yet */
2074.         if (confused || (scursed && !already_known))
2075.             You("identify this as an identify scroll.");
2076.         else if (!already_known)
2077.             pline("This is an identify scroll.");
2078.         if (!already_known)
2079.             (void) learnscrolltyp(SCR_IDENTIFY);
2080.         if (confused || (scursed && !already_known))
2081.             return;
2082.     }
2083. 
2084.     if (gi.invent) {
2085.         int cval = 1;
2086.         if (sblessed || (!scursed && !rn2(5))) {
2087.             cval = rn2(5);
2088.             /* note: if cval==0, identify all items */
2089.             if (cval == 1 && sblessed && Luck > 0)
2090.                 ++cval;
2091.         }
2092.         identify_pack(cval, !already_known);
2093.     } else {
2094.         /* spell cast with inventory empty or scroll read when it's
2095.            the only item leaving empty inventory after being used up */
2096.         pline("You're not carrying anything%s to be identified.",
2097.               (is_scroll) ? " else" : "");
2098.     }
2099. }
2100. 
2101. staticfn void
2102. seffect_magic_mapping(struct obj **sobjp)
2103. {
2104.     struct obj *sobj = *sobjp;
2105.     boolean is_scroll = (sobj->oclass == SCROLL_CLASS);
2106.     boolean sblessed = sobj->blessed;
2107.     boolean scursed = sobj->cursed;
2108.     boolean confused = (Confusion != 0);
2109.     int cval;
2110. 
2111.     if (is_scroll) {
2112.         if (svl.level.flags.nommap) {
2113.             Your("mind is filled with crazy lines!");
2114.             if (Hallucination)
2115.                 pline("Wow!  Modern art.");
2116.             else
2117.                 Your("%s spins in bewilderment.", body_part(HEAD));
2118.             make_confused(HConfusion + rnd(30), FALSE);
2119.             return;
2120.         }
2121.         if (sblessed) {
2122.             coordxy x, y;
2123. 
2124.             for (x = 1; x < COLNO; x++)
2125.                 for (y = 0; y < ROWNO; y++)
2126.                     if (levl[x][y].typ == SDOOR) {
2127.                         cvt_sdoor_to_door(&levl[x][y]);
2128.                         if (Is_rogue_level(&u.uz))
2129.                             unblock_point(x, y);
2130.                     }
2131.             /* do_mapping() already reveals secret passages */
2132.         }
2133.         gk.known = TRUE;
2134.     }
2135. 
2136.     if (svl.level.flags.nommap) {
2137.         Your("%s spins as %s blocks the spell!", body_part(HEAD),
2138.              something);
2139.         make_confused(HConfusion + rnd(30), FALSE);
2140.         return;
2141.     }
2142.     pline("A map coalesces in your mind!");
2143.     cval = (scursed && !confused);
2144.     if (cval)
2145.         HConfusion = 1; /* to screw up map */
2146.     notice_mon_off();
2147.     do_mapping();
2148.     notice_mon_on();
2149.     if (cval) {
2150.         HConfusion = 0; /* restore */
2151.         pline("Unfortunately, you can't grasp the details.");
2152.     }
2153. }
2154. 
2155. #ifdef MAIL_STRUCTURES
2156. staticfn void
2157. seffect_mail(struct obj **sobjp)
2158. {
2159.     struct obj *sobj = *sobjp;
2160.     boolean odd = (sobj->o_id % 2) == 1;
2161. 
2162.     gk.known = TRUE;
2163.     switch (sobj->spe) {
2164.     case 2:
2165.         /* "stamped scroll" created via magic marker--without a stamp */
2166.         pline("This scroll is marked \"%s\".",
2167.               odd ? "Postage Due" : "Return to Sender");
2168.         break;
2169.     case 1:
2170.         /* scroll of mail obtained from bones file or from wishing;
2171.            note to the puzzled: the game Larn actually sends you junk
2172.            mail if you win! */
2173.         pline("This seems to be %s.",
2174.               odd ? "a chain letter threatening your luck"
2175.               : "junk mail addressed to the finder of the Eye of Larn");
2176.         break;
2177.     default:
2178. #ifdef MAIL
2179.         readmail(sobj);
2180. #else
2181.         /* unreachable since with MAIL undefined, sobj->spe won't be 0;
2182.            as a precaution, be prepared to give arbitrary feedback;
2183.            caller has already reported that it disappears upon reading */
2184.         pline("That was a scroll of mail?");
2185. #endif
2186.         break;
2187.     }
2188. }
2189. #endif /* MAIL_STRUCTURES */
2190. 
2191. /* scroll effects; return 1 if we use up the scroll and possibly make it
2192.    become discovered, 0 if caller should take care of those side-effects */
2193. int
2194. seffects(
2195.     struct obj *sobj) /* sobj - scroll or fake spellbook for spell */
2196. {
2197.     int otyp = sobj->otyp;
2198. 
2199.     if (objects[otyp].oc_magic)
2200.         exercise(A_WIS, TRUE);                       /* just for trying */
2201. 
2202.     switch (otyp) {
2203. #ifdef MAIL_STRUCTURES
2204.     case SCR_MAIL:
2205.         seffect_mail(&sobj);
2206.         break;
2207. #endif
2208.     case SCR_ENCHANT_ARMOR:
2209.         seffect_enchant_armor(&sobj);
2210.         break;
2211.     case SCR_DESTROY_ARMOR:
2212.         seffect_destroy_armor(&sobj);
2213.         break;
2214.     case SCR_CONFUSE_MONSTER:
2215.     case SPE_CONFUSE_MONSTER:
2216.         seffect_confuse_monster(&sobj);
2217.         break;
2218.     case SCR_SCARE_MONSTER:
2219.     case SPE_CAUSE_FEAR:
2220.         seffect_scare_monster(&sobj);
2221.         break;
2222.     case SCR_BLANK_PAPER:
2223.         seffect_blank_paper(&sobj);
2224.         break;
2225.     case SCR_REMOVE_CURSE:
2226.     case SPE_REMOVE_CURSE:
2227.         seffect_remove_curse(&sobj);
2228.         break;
2229.     case SCR_CREATE_MONSTER:
2230.     case SPE_CREATE_MONSTER:
2231.         seffect_create_monster(&sobj);
2232.         break;
2233.     case SCR_ENCHANT_WEAPON:
2234.         seffect_enchant_weapon(&sobj);
2235.         break;
2236.     case SCR_TAMING:
2237.     case SPE_CHARM_MONSTER:
2238.         seffect_taming(&sobj);
2239.         break;
2240.     case SCR_GENOCIDE:
2241.         seffect_genocide(&sobj);
2242.         break;
2243.     case SCR_LIGHT:
2244.         seffect_light(&sobj);
2245.         break;
2246.     case SCR_TELEPORTATION:
2247.         seffect_teleportation(&sobj);
2248.         break;
2249.     case SCR_GOLD_DETECTION:
2250.         seffect_gold_detection(&sobj);
2251.         break;
2252.     case SCR_FOOD_DETECTION:
2253.     case SPE_DETECT_FOOD:
2254.         seffect_food_detection(&sobj);
2255.         break;
2256.     case SCR_IDENTIFY:
2257.     case SPE_IDENTIFY:
2258.         seffect_identify(&sobj);
2259.         break;
2260.     case SCR_CHARGING:
2261.         seffect_charging(&sobj);
2262.         break;
2263.     case SCR_MAGIC_MAPPING:
2264.     case SPE_MAGIC_MAPPING:
2265.         seffect_magic_mapping(&sobj);
2266.         break;
2267.     case SCR_AMNESIA:
2268.         seffect_amnesia(&sobj);
2269.         break;
2270.     case SCR_FIRE:
2271.         seffect_fire(&sobj);
2272.         break;
2273.     case SCR_EARTH:
2274.         seffect_earth(&sobj);
2275.         break;
2276.     case SCR_PUNISHMENT:
2277.         seffect_punishment(&sobj);
2278.         break;
2279.     case SCR_STINKING_CLOUD:
2280.         seffect_stinking_cloud(&sobj);
2281.         break;
2282.     default:
2283.         impossible("What weird effect is this? (%u)", otyp);
2284.     }
2285.     /* if sobj is gone, we've already called useup() above and the
2286.        update_inventory() that it performs might have come too soon
2287.        (before charging an item, for instance) */
2288.     if (!sobj)
2289.         update_inventory();
2290.     return sobj ? 0 : 1;
2291. }
2292. 
2293. void
2294. drop_boulder_on_player(
2295.     boolean confused,
2296.     boolean helmet_protects,
2297.     boolean byu,
2298.     boolean skip_uswallow)
2299. {
2300.     int dmg;
2301.     struct obj *otmp2;
2302. 
2303.     /* hit monster if swallowed */
2304.     if (u.uswallow && !skip_uswallow) {
2305.         drop_boulder_on_monster(u.ux, u.uy, confused, byu);
2306.         return;
2307.     }
2308. 
2309.     otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
2310.     if (!otmp2)
2311.         return;
2312.     otmp2->quan = confused ? rn1(5, 2) : 1;
2313.     otmp2->owt = weight(otmp2);
2314.     if (!amorphous(gy.youmonst.data) && !Passes_walls
2315.         && !noncorporeal(gy.youmonst.data) && !unsolid(gy.youmonst.data)) {
2316.         You("are hit by %s!", doname(otmp2));
2317.         dmg = (int) (dmgval(otmp2, &gy.youmonst) * otmp2->quan);
2318.         if (uarmh && helmet_protects) {
2319.             if (hard_helmet(uarmh)) {
2320.                 pline("Fortunately, you are wearing a hard helmet.");
2321.                 if (dmg > 2)
2322.                     dmg = 2;
2323.             } else if (flags.verbose) {
2324.                 pline("%s does not protect you.", Yname2(uarmh));
2325.             }
2326.         }
2327.     } else
2328.         dmg = 0;
2329.     wake_nearto(u.ux, u.uy, 4 * 4);
2330.     /* Must be before the losehp(), for bones files */
2331.     if (!flooreffects(otmp2, u.ux, u.uy, "fall")) {
2332.         place_object(otmp2, u.ux, u.uy);
2333.         stackobj(otmp2);
2334.         newsym(u.ux, u.uy);
2335.     }
2336.     if (dmg)
2337.         losehp(Maybe_Half_Phys(dmg), "scroll of earth", KILLED_BY_AN);
2338. }
2339. 
2340. boolean
2341. drop_boulder_on_monster(coordxy x, coordxy y, boolean confused, boolean byu)
2342. {
2343.     struct obj *otmp2;
2344.     struct monst *mtmp;
2345. 
2346.     /* Make the object(s) */
2347.     otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
2348.     if (!otmp2)
2349.         return FALSE; /* Shouldn't happen */
2350.     otmp2->quan = confused ? rn1(5, 2) : 1;
2351.     otmp2->owt = weight(otmp2);
2352. 
2353.     /* Find the monster here (won't be player) */
2354.     mtmp = m_at(x, y);
2355.     if (mtmp && !amorphous(mtmp->data) && !passes_walls(mtmp->data)
2356.         && !noncorporeal(mtmp->data) && !unsolid(mtmp->data)) {
2357.         struct obj *helmet = which_armor(mtmp, W_ARMH);
2358.         long mdmg;
2359. 
2360.         if (cansee(mtmp->mx, mtmp->my)) {
2361.             pline("%s is hit by %s!", Monnam(mtmp), doname(otmp2));
2362.             if (mtmp->minvis && !canspotmon(mtmp))
2363.                 map_invisible(mtmp->mx, mtmp->my);
2364.         } else if (engulfing_u(mtmp))
2365.             You_hear("something hit %s %s over your %s!",
2366.                      s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH),
2367.                      body_part(HEAD));
2368. 
2369.         mdmg = dmgval(otmp2, mtmp) * otmp2->quan;
2370.         if (helmet) {
2371.             if (hard_helmet(helmet)) {
2372.                 if (canspotmon(mtmp))
2373.                     pline("Fortunately, %s is wearing a hard helmet.",
2374.                           mon_nam(mtmp));
2375.                 else if (!Deaf)
2376.                     You_hear("a clanging sound.");
2377.                 if (mdmg > 2)
2378.                     mdmg = 2;
2379.             } else {
2380.                 if (canspotmon(mtmp))
2381.                     pline("%s's %s does not protect %s.", Monnam(mtmp),
2382.                           xname(helmet), mhim(mtmp));
2383.             }
2384.         }
2385.         mtmp->mhp -= mdmg;
2386.         if (DEADMONSTER(mtmp)) {
2387.             if (byu) {
2388.                 killed(mtmp);
2389.             } else {
2390.                 pline("%s is killed.", Monnam(mtmp));
2391.                 mondied(mtmp);
2392.             }
2393.         } else {
2394.             wakeup(mtmp, byu);
2395.         }
2396.         wake_nearto(x, y, 4 * 4);
2397.     } else if (engulfing_u(mtmp)) {
2398.         obfree(otmp2, (struct obj *) 0);
2399.         /* fall through to player */
2400.         drop_boulder_on_player(confused, TRUE, FALSE, TRUE);
2401.         return 1;
2402.     }
2403.     /* Drop the rock/boulder to the floor */
2404.     if (!flooreffects(otmp2, x, y, "fall")) {
2405.         place_object(otmp2, x, y);
2406.         stackobj(otmp2);
2407.         newsym(x, y); /* map the rock */
2408.     }
2409.     return TRUE;
2410. }
2411. 
2412. /* overcharging any wand or zapping/engraving cursed wand */
2413. void
2414. wand_explode(struct obj *obj, int chg /* recharging */)
2415. {
2416.     const char *expl = !chg ? "suddenly" : "vibrates violently and";
2417.     int dmg, n, k;
2418. 
2419.     /* number of damage dice */
2420.     if (!chg)
2421.         chg = 2; /* zap/engrave adjustment */
2422.     n = obj->spe + chg;
2423.     if (n < 2)
2424.         n = 2; /* arbitrary minimum */
2425.     /* size of damage dice */
2426.     switch (obj->otyp) {
2427.     case WAN_WISHING:
2428.         k = 12;
2429.         break;
2430.     case WAN_CANCELLATION:
2431.     case WAN_DEATH:
2432.     case WAN_POLYMORPH:
2433.     case WAN_UNDEAD_TURNING:
2434.         k = 10;
2435.         break;
2436.     case WAN_COLD:
2437.     case WAN_FIRE:
2438.     case WAN_LIGHTNING:
2439.     case WAN_MAGIC_MISSILE:
2440.         k = 8;
2441.         break;
2442.     case WAN_NOTHING:
2443.         k = 4;
2444.         break;
2445.     default:
2446.         k = 6;
2447.         break;
2448.     }
2449.     /* inflict damage and destroy the wand */
2450.     dmg = d(n, k);
2451.     obj->in_use = TRUE; /* in case losehp() is fatal (or --More--^C) */
2452.     pline("%s %s explodes!", Yname2(obj), expl);
2453.     losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN);
2454.     useup(obj);
2455.     /* obscure side-effect */
2456.     exercise(A_STR, FALSE);
2457. }
2458. 
2459. /* used to collect gremlins being hit by light so that they can be processed
2460.    after vision for the entire lit area has been brought up to date */
2461. struct litmon {
2462.     struct monst *mon;
2463.     struct litmon *nxt;
2464. };
2465. static struct litmon *gremlins = 0;
2466. 
2467. /*
2468.  * Low-level lit-field update routine.
2469.  */
2470. staticfn void
2471. set_lit(coordxy x, coordxy y, genericptr_t val)
2472. {
2473.     struct monst *mtmp;
2474.     struct litmon *gremlin;
2475. 
2476.     if (val) {
2477.         levl[x][y].lit = 1;
2478.         if ((mtmp = m_at(x, y)) != 0 && mtmp->data == &mons[PM_GREMLIN]) {
2479.             gremlin = (struct litmon *) alloc(sizeof *gremlin);
2480.             gremlin->mon = mtmp;
2481.             gremlin->nxt = gremlins;
2482.             gremlins = gremlin;
2483.         }
2484.     } else {
2485.         levl[x][y].lit = 0;
2486.         snuff_light_source(x, y);
2487.     }
2488. }
2489. 
2490. void
2491. litroom(
2492.     boolean on,      /* True: make nearby area lit; False: cursed scroll */
2493.     struct obj *obj) /* scroll, spellbook (for spell), or wand of light */
2494. {
2495.     struct obj *otmp, *nextobj;
2496.     boolean blessed_effect = (obj && obj->oclass == SCROLL_CLASS
2497.                               && obj->blessed);
2498.     boolean no_op = (u.uswallow || Underwater || Is_waterlevel(&u.uz));
2499.     char is_lit = 0; /* value is irrelevant but assign something anyway; its
2500.                       * address is used as a 'not null' flag for set_lit() */
2501. 
2502.     /* update object lights and produce message (provided you're not blind) */
2503.     if (!on) {
2504.         int still_lit = 0;
2505. 
2506.         /*
2507.          * The magic douses lamps,&c too and might curse artifact lights.
2508.          *
2509.          * FIXME?
2510.          *  Shouldn't this affect all lit objects in the area of effect
2511.          *  rather than just those carried by the hero?
2512.          */
2513.         for (otmp = gi.invent; otmp; otmp = nextobj) {
2514.             nextobj = otmp->nobj;
2515.             if (otmp->lamplit) {
2516.                 if (!artifact_light(otmp))
2517.                     (void) snuff_lit(otmp);
2518.                 else
2519.                     /* wielded Sunsword or worn gold dragon scales/mail;
2520.                        maybe lower its BUC state if not already cursed */
2521.                     impact_arti_light(otmp, TRUE, (boolean) !Blind);
2522. 
2523.                 if (otmp->lamplit)
2524.                     ++still_lit;
2525.             }
2526.         }
2527.         /* scroll of light becomes discovered when not blind, so some
2528.            message to justify that is needed */
2529.         if (!Blind) {
2530.             /* for the still_lit case, we don't know at this point whether
2531.                anything currently visibly lit is going to go dark; if this
2532.                message came after the darkening, we could count visibly
2533.                lit squares before and after to know; we do know that being
2534.                swallowed won't be affected--the interior is still lit */
2535.             if (still_lit)
2536.                 pline_The("ambient light seems dimmer.");
2537.             else if (u.uswallow)
2538.                 pline("It seems even darker in here than before.");
2539.             else
2540.                 You("are surrounded by darkness!");
2541.         }
2542.     } else { /* on */
2543.         if (blessed_effect) {
2544.             /* might bless artifact lights; no effect on ordinary lights */
2545.             for (otmp = gi.invent; otmp; otmp = nextobj) {
2546.                 nextobj = otmp->nobj;
2547.                 if (otmp->lamplit && artifact_light(otmp))
2548.                     /* wielded Sunsword or worn gold dragon scales/mail;
2549.                        maybe raise its BUC state if not already blessed */
2550.                     impact_arti_light(otmp, FALSE, (boolean) !Blind);
2551.             }
2552.         }
2553.         if (u.uswallow) {
2554.             if (Blind)
2555.                 ; /* no feedback */
2556.             else if (digests(u.ustuck->data))
2557.                 pline("%s %s is lit.", s_suffix(Monnam(u.ustuck)),
2558.                       mbodypart(u.ustuck, STOMACH));
2559.             else if (is_whirly(u.ustuck->data))
2560.                 pline("%s shines briefly.", Monnam(u.ustuck));
2561.             else
2562.                 pline("%s glistens.", Monnam(u.ustuck));
2563.         } else if (!Blind && (!Is_rogue_level(&u.uz)
2564.                               || levl[u.ux][u.uy].typ != CORR)) {
2565.             pline("A lit field %ssurrounds you!", no_op ? "briefly " : "");
2566.         }
2567.     }
2568. 
2569.     /* No-op when swallowed or in water */
2570.     if (no_op)
2571.         return;
2572.     /*
2573.      *  If we are darkening the room and the hero is punished but not
2574.      *  blind, then we have to pick up and replace the ball and chain so
2575.      *  that we don't remember them if they are out of sight.
2576.      */
2577.     if (Punished && !on && !Blind)
2578.         move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
2579. 
2580.     if (Is_rogue_level(&u.uz)) {
2581.         /* Can't use do_clear_area because MAX_RADIUS is too small */
2582.         /* rogue lighting must light the entire room */
2583.         int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET;
2584.         int rx, ry;
2585. 
2586.         if (rnum >= 0) {
2587.             for (rx = svr.rooms[rnum].lx - 1; rx <= svr.rooms[rnum].hx + 1;
2588.                  rx++)
2589.                 for (ry = svr.rooms[rnum].ly - 1;
2590.                      ry <= svr.rooms[rnum].hy + 1; ry++)
2591.                     set_lit(rx, ry,
2592.                             (genericptr_t) (on ? &is_lit : (char *) 0));
2593.             svr.rooms[rnum].rlit = on;
2594.         }
2595.         /* hallways remain dark on the rogue level */
2596.     } else if (is_art(obj, ART_SUNSWORD)) {
2597.         /* Sunsword's #invoke power directed up or down lights hero's spot
2598.            (do_clear_area() rejects radius 0 so call set_lit() directly) */
2599.         set_lit(u.ux, u.uy, (genericptr_t) &is_lit);
2600.     } else {
2601.         do_clear_area(u.ux, u.uy, blessed_effect ? 9 : 5,
2602.                       set_lit, (genericptr_t) (on ? &is_lit : (char *) 0));
2603.     }
2604. 
2605.     /*
2606.      *  If we are not blind, then force a redraw on all positions in sight
2607.      *  by temporarily blinding the hero.  The vision recalculation will
2608.      *  correctly update all previously seen positions *and* correctly
2609.      *  set the waslit bit [could be messed up from above].
2610.      */
2611.     if (!Blind) {
2612.         vision_recalc(2);
2613. 
2614.         /* replace ball&chain */
2615.         if (Punished && !on)
2616.             move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
2617.     }
2618. 
2619.     gv.vision_full_recalc = 1; /* delayed vision recalculation */
2620.     if (gremlins) {
2621.         struct litmon *gremlin;
2622. 
2623.         /* can't delay vision recalc after all */
2624.         vision_recalc(0);
2625.         /* after vision has been updated, monsters who are affected
2626.            when hit by light can now be hit by it */
2627.         do {
2628.             gremlin = gremlins;
2629.             gremlins = gremlin->nxt;
2630.             light_hits_gremlin(gremlin->mon, rnd(5));
2631.             free((genericptr_t) gremlin);
2632.         } while (gremlins);
2633.     }
2634.     return;
2635. }
2636. 
2637. staticfn void
2638. do_class_genocide(void)
2639. {
2640.     int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0;
2641.     int ll_done = 0;
2642.     char buf[BUFSZ], promptbuf[QBUFSZ];
2643.     boolean gameover = FALSE; /* true iff killed self */
2644. 
2645.     buf[0] = '\0'; /* for EDIT_GETLIN */
2646.     for (j = 0; ; j++) {
2647.         if (j >= 5) {
2648.             pline1(thats_enough_tries);
2649.             return;
2650.         }
2651.         Strcpy(promptbuf, "What class of monsters do you want to genocide?");
2652.         if (j > 0)
2653.             Snprintf(eos(promptbuf), sizeof promptbuf - strlen(promptbuf),
2654.                      " [enter %s]",
2655.                      iflags.cmdassist
2656.                        ? "the symbol or name representing a class, or '?'"
2657.                        : "'?' to see previous genocides");
2658.         getlin(promptbuf, buf);
2659.         (void) mungspaces(buf);
2660.         /* avoid 'that does not represent any monster' for empty input */
2661.         if (!*buf) {
2662.             pline("%s.", (j + 1 < 5)
2663.                          ? "Type letter (or punctuation)"
2664.                            " or name used for a class of monsters or 'none'"
2665.                          /* next iteration gives "that's enough tries"
2666.                             so don't suggest typing anything this time */
2667.                          : "No class of monsters specified");
2668.             continue; /* try again */
2669.         }
2670.         /* choosing "none" preserves genocideless conduct */
2671.         if (*buf == '\033' || !strcmpi(buf, "none")
2672.             || !strcmpi(buf, "'none'") || !strcmpi(buf, "nothing")) {
2673.             livelog_printf(LL_GENOCIDE,
2674.                            "declined to perform class genocide");
2675.             return;
2676.         }
2677.         /* "?" runs #genocided to show existing genocides, then re-prompts;
2678.            accept "'?'" too because the prompt's hint shows it that way */
2679.         if (!strcmp(buf, "?") || !strcmp(buf, "'?'")) {
2680.             list_genocided('g', FALSE);
2681.             --j; /* don't count this iteration as one of the tries */
2682.             continue;
2683.         }
2684. 
2685.         class = name_to_monclass(buf, (int *) 0);
2686.         if (class == 0 && (i = name_to_mon(buf, (int *) 0)) != NON_PM)
2687.             class = mons[i].mlet;
2688.         immunecnt = gonecnt = goodcnt = 0;
2689.         for (i = LOW_PM; i < NUMMONS; i++) {
2690.             if (mons[i].mlet == class) {
2691.                 if (!(mons[i].geno & G_GENO))
2692.                     immunecnt++;
2693.                 else if (svm.mvitals[i].mvflags & G_GENOD)
2694.                     gonecnt++;
2695.                 else
2696.                     goodcnt++;
2697.             }
2698.         }
2699.         if (!goodcnt && class != mons[gu.urole.mnum].mlet
2700.             && class != mons[gu.urace.mnum].mlet) {
2701.             if (gonecnt)
2702.                 pline("All such monsters are already nonexistent.");
2703.             else if (immunecnt || class == S_invisible)
2704.                 You("aren't permitted to genocide such monsters.");
2705.             else if (wizard && buf[0] == '*') {
2706.                 struct monst *mtmp, *mtmp2;
2707. 
2708.                 gonecnt = 0;
2709.                 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
2710.                     mtmp2 = mtmp->nmon;
2711.                     if (DEADMONSTER(mtmp))
2712.                         continue;
2713.                     mongone(mtmp);
2714.                     gonecnt++;
2715.                 }
2716.                 pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt));
2717.                 return;
2718.             } else
2719.                 pline("That %s does not represent any monster.",
2720.                       strlen(buf) == 1 ? "symbol" : "response");
2721.             continue;
2722.         }
2723. 
2724.         for (i = LOW_PM; i < NUMMONS; i++) {
2725.             if (mons[i].mlet == class) {
2726.                 char nam[BUFSZ];
2727. 
2728.                 Strcpy(nam, makeplural(mons[i].pmnames[NEUTRAL]));
2729.                 /* Although "genus" is Latin for race, the hero benefits
2730.                  * from both race and role; thus genocide affects either.
2731.                  */
2732.                 if (Your_Own_Role(i) || Your_Own_Race(i)
2733.                     || ((mons[i].geno & G_GENO)
2734.                         && !(svm.mvitals[i].mvflags & G_GENOD))) {
2735.                     /* This check must be first since player monsters might
2736.                      * have G_GENOD or !G_GENO.
2737.                      */
2738.                     if (!ll_done++) {
2739.                         if (!num_genocides())
2740.                             livelog_printf(LL_CONDUCT | LL_GENOCIDE,
2741.                                      "performed %s first genocide (class %c)",
2742.                                            uhis(), def_monsyms[class].sym);
2743.                         else
2744.                             livelog_printf(LL_GENOCIDE, "genocided class %c",
2745.                                            def_monsyms[class].sym);
2746.                     }
2747. 
2748.                     svm.mvitals[i].mvflags |= (G_GENOD | G_NOCORPSE);
2749.                     kill_genocided_monsters();
2750.                     update_inventory(); /* eggs & tins */
2751.                     pline("Wiped out all %s.", nam);
2752.                     if (Upolyd && vampshifted(&gy.youmonst)
2753.                         /* current shifted form or base vampire form */
2754.                         && (i == u.umonnum || i == gy.youmonst.cham))
2755.                         polyself(POLY_REVERT); /* vampshifter to vampire */
2756.                     if (Upolyd && i == u.umonnum) {
2757.                         u.mh = -1;
2758.                         if (Unchanging) {
2759.                             if (!feel_dead++)
2760.                                 urgent_pline("You die.");
2761.                             /* finish genociding this class of
2762.                                monsters before ultimately dying */
2763.                             gameover = TRUE;
2764.                         } else
2765.                             rehumanize();
2766.                     }
2767.                     /* Self-genocide if it matches either your race
2768.                        or role.  Assumption:  male and female forms
2769.                        share same monster class. */
2770.                     if (i == gu.urole.mnum || i == gu.urace.mnum) {
2771.                         u.uhp = -1;
2772.                         if (Upolyd) {
2773.                             if (!feel_dead++)
2774.                                 You_feel("%s inside.", udeadinside());
2775.                         } else {
2776.                             if (!feel_dead++)
2777.                                 urgent_pline("You die.");
2778.                             gameover = TRUE;
2779.                         }
2780.                     }
2781.                 } else if (svm.mvitals[i].mvflags & G_GENOD) {
2782.                     if (!gameover)
2783.                         pline("%s are already nonexistent.", upstart(nam));
2784.                 } else if (!gameover) {
2785.                     /* suppress feedback about quest beings except
2786.                        for those applicable to our own role */
2787.                     if ((mons[i].msound != MS_LEADER
2788.                          || quest_info(MS_LEADER) == i)
2789.                         && (mons[i].msound != MS_NEMESIS
2790.                             || quest_info(MS_NEMESIS) == i)
2791.                         && (mons[i].msound != MS_GUARDIAN
2792.                             || quest_info(MS_GUARDIAN) == i)
2793.                         /* non-leader/nemesis/guardian role-specific monster
2794.                            */
2795.                         && (i != PM_NINJA /* nuisance */
2796.                             || Role_if(PM_SAMURAI))) {
2797.                         boolean named, uniq;
2798. 
2799.                         named = type_is_pname(&mons[i]) ? TRUE : FALSE;
2800.                         uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE;
2801.                         /* one special case */
2802.                         if (i == PM_HIGH_CLERIC)
2803.                             uniq = FALSE;
2804. 
2805.                         You("aren't permitted to genocide %s%s.",
2806.                             (uniq && !named) ? "the " : "",
2807.                             (uniq || named) ? mons[i].pmnames[NEUTRAL] : nam);
2808.                     }
2809.                 }
2810.             }
2811.         }
2812.         if (gameover || u.uhp == -1) {
2813.             svk.killer.format = KILLED_BY_AN;
2814.             Strcpy(svk.killer.name, "scroll of genocide");
2815.             if (gameover)
2816.                 done(GENOCIDED);
2817.         }
2818.         return;
2819.     }
2820. }
2821. 
2822. #define REALLY 1
2823. #define PLAYER 2
2824. #define ONTHRONE 4
2825. void
2826. do_genocide(
2827.     int how) /* 0 = no genocide; create monsters (cursed scroll)
2828.               * 1 = normal genocide
2829.               * 3 = forced genocide of player
2830.               * 5 (4 | 1) = normal genocide from throne */
2831. {
2832.     char buf[BUFSZ], realbuf[BUFSZ], promptbuf[QBUFSZ];
2833.     int i, killplayer = 0;
2834.     int mndx;
2835.     struct permonst *ptr;
2836.     const char *which;
2837. 
2838.     if (how & PLAYER) {
2839.         mndx = u.umonster; /* non-polymorphed mon num */
2840.         ptr = &mons[mndx];
2841.         Strcpy(buf, pmname(ptr, Ugender));
2842.         killplayer++;
2843.     } else {
2844.         buf[0] = '\0'; /* init for EDIT_GETLIN */
2845.         for (i = 0; ; i++) {
2846.             if (i >= 5) {
2847.                 /* cursed effect => no free pass (unless rndmonst() fails) */
2848.                 if (!(how & REALLY) && (ptr = rndmonst()) != 0)
2849.                     break;
2850. 
2851.                 pline1(thats_enough_tries);
2852.                 return;
2853.             }
2854.             Strcpy(promptbuf,
2855.                    "What type of monster do you want to genocide?");
2856.             if (i > 0)
2857.                 Snprintf(eos(promptbuf), sizeof promptbuf - strlen(promptbuf),
2858.                          " [enter %s]",
2859.                          iflags.cmdassist
2860.                            ? "the name of a type of monster, or '?'"
2861.                            : "'?' to see previous genocides");
2862.             getlin(promptbuf, buf);
2863.             (void) mungspaces(buf);
2864.             /* avoid 'such creatures do not exist' for empty input */
2865.             if (!*buf) {
2866.                 pline("%s.", (i + 1 < 5)
2867.                              ? "Type the name of a type of monster or 'none'"
2868.                              /* next iteration gives "that's enough tries"
2869.                                 so don't suggest typing anything this time */
2870.                              : "No type of monster specified");
2871.                 continue; /* try again */
2872.             }
2873.             /* choosing "none" preserves genocideless conduct */
2874.             if (*buf == '\033' || !strcmpi(buf, "none")
2875.                 || !strcmpi(buf, "'none'") || !strcmpi(buf, "nothing")) {
2876.                 /* ... but no free pass if cursed */
2877.                 if (!(how & REALLY) && (ptr = rndmonst()) != 0)
2878.                     break; /* remaining checks don't apply */
2879. 
2880.                 livelog_printf(LL_GENOCIDE, "declined to perform genocide");
2881.                 return;
2882.             }
2883.             /* "?" or "'?'" runs #genocided to show existing genocides */
2884.             if (!strcmp(buf, "?") || !strcmp(buf, "'?'")) {
2885.                 list_genocided('g', FALSE);
2886.                 --i; /* don't count this iteration as one of the tries */
2887.                 continue;
2888.             }
2889. 
2890.             mndx = name_to_mon(buf, (int *) 0);
2891.             if (mndx == NON_PM || (svm.mvitals[mndx].mvflags & G_GENOD)) {
2892.                 pline("Such creatures %s exist in this world.",
2893.                       (mndx == NON_PM) ? "do not" : "no longer");
2894.                 continue;
2895.             }
2896.             ptr = &mons[mndx];
2897.             /* first revert if current shifted form or base vampire form */
2898.             if (Upolyd && vampshifted(&gy.youmonst)
2899.                 && (mndx == u.umonnum || mndx == gy.youmonst.cham))
2900.                 polyself(POLY_REVERT); /* vampshifter (bat, &c) to vampire */
2901.             /* Although "genus" is Latin for race, the hero benefits
2902.              * from both race and role; thus genocide affects either.
2903.              */
2904.             if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) {
2905.                 killplayer++;
2906.                 break;
2907.             }
2908.             if (is_human(ptr))
2909.                 adjalign(-sgn(u.ualign.type));
2910.             if (is_demon(ptr))
2911.                 adjalign(sgn(u.ualign.type));
2912. 
2913.             if (!(ptr->geno & G_GENO)) {
2914.                 if (!Deaf) {
2915.                     /* FIXME: unconditional "caverns" will be silly in some
2916.                      * circumstances.  Who's speaking?  Divine pronouncements
2917.                      * aren't supposed to be hampered by deafness....
2918.                      */
2919.                     if (flags.verbose)
2920.                         pline("A thunderous voice booms"
2921.                               " through the caverns:");
2922.                     SetVoice((struct monst *) 0, 0, 80, voice_deity);
2923.                     /* FIXME? shouldn't this override deafness? */
2924.                     verbalize("No, mortal!  That will not be done.");
2925.                 }
2926.                 continue;
2927.             }
2928.             /* KMH -- Unchanging prevents rehumanization */
2929.             if (Unchanging && ptr == gy.youmonst.data)
2930.                 killplayer++;
2931.             break;
2932.         }
2933.         mndx = monsndx(ptr); /* needed for the 'no free pass' cases */
2934.     }
2935. 
2936.     which = "all ";
2937.     Strcpy(realbuf, ptr->pmnames[NEUTRAL]); /* standard singular */
2938.     if (Hallucination) {
2939.         /* hallucinate hero's type */
2940.         if (Upolyd) {
2941.             Strcpy(buf, pmname(gy.youmonst.data,
2942.                                flags.female ? FEMALE : MALE));
2943.         } else {
2944.             Strcpy(buf, (flags.female && gu.urole.name.f) ? gu.urole.name.f
2945.                                                           : gu.urole.name.m);
2946.             buf[0] = lowc(buf[0]);
2947.         }
2948.     } else {
2949.         /* use actual type */
2950.         Strcpy(buf, realbuf);
2951.         if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_CLERIC])
2952.             which = !type_is_pname(ptr) ? "the " : "";
2953.     }
2954. 
2955.     if (how & REALLY) {
2956.         if (!num_genocides())
2957.             livelog_printf(LL_CONDUCT | LL_GENOCIDE,
2958.                            "performed %s first genocide (%s)",
2959.                            uhis(), makeplural(realbuf));
2960.         else
2961.             livelog_printf(LL_GENOCIDE, "genocided %s", makeplural(realbuf));
2962. 
2963.         /* setting no-corpse affects wishing and random tin generation */
2964.         svm.mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE);
2965.         pline("Wiped out %s%s.", which,
2966.               (*which != 'a') ? buf : makeplural(buf));
2967. 
2968.         if (killplayer) {
2969.             u.uhp = -1;
2970.             if (how & PLAYER) {
2971.                 svk.killer.format = KILLED_BY;
2972.                 Strcpy(svk.killer.name, "genocidal confusion");
2973.             } else if (how & ONTHRONE) {
2974.                 /* player selected while on a throne */
2975.                 svk.killer.format = KILLED_BY_AN;
2976.                 Strcpy(svk.killer.name, "imperious order");
2977.             } else { /* selected player deliberately, not confused */
2978.                 svk.killer.format = KILLED_BY_AN;
2979.                 Strcpy(svk.killer.name, "scroll of genocide");
2980.             }
2981. 
2982.             /* Polymorphed characters will die as soon as they're rehumanized.
2983.                KMH -- Unchanging prevents rehumanization. */
2984.             if (Upolyd && ptr != gy.youmonst.data) {
2985.                 delayed_killer(POLYMORPH, svk.killer.format, svk.killer.name);
2986.                 You_feel("%s inside.", udeadinside());
2987.             } else {
2988.                 done(GENOCIDED);
2989.             }
2990.         } else if (ptr == gy.youmonst.data) {
2991.             rehumanize();
2992.         }
2993.         kill_genocided_monsters();
2994.         update_inventory(); /* in case identified eggs were affected */
2995.     } else {
2996.         int cnt = 0, census = monster_census(FALSE);
2997. 
2998.         if (!(mons[mndx].geno & G_UNIQ)
2999.             && !(svm.mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT)))
3000.             for (i = rn1(3, 4); i > 0; i--) {
3001.                 if (!makemon(ptr, u.ux, u.uy, NO_MINVENT | MM_NOMSG))
3002.                     break; /* couldn't make one */
3003.                 ++cnt;
3004.                 if (svm.mvitals[mndx].mvflags & G_EXTINCT)
3005.                     break; /* just made last one */
3006.             }
3007.         if (cnt) {
3008.             /* accumulated 'cnt' doesn't take groups into account;
3009.                assume bringing in new mon(s) didn't remove any old ones */
3010.             cnt = monster_census(FALSE) - census;
3011.             pline("Sent in %s%s.", (cnt > 1) ? "some " : "",
3012.                   (cnt > 1) ? makeplural(buf) : an(buf));
3013.         } else
3014.             pline1(nothing_happens);
3015.     }
3016. }
3017. 
3018. void
3019. punish(struct obj *sobj)
3020. {
3021.     /* angrygods() calls this with NULL sobj arg */
3022.     struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL)
3023.                                 ? sobj : (struct obj *) 0;
3024.     /* analyzer doesn't know that the one caller that passes a NULL
3025.      * sobj (angrygods) checks !Punished first, so add a guard */
3026.     int cursed_levy = (sobj && sobj->cursed) ? 1 : 0;
3027. 
3028.     /* KMH -- Punishment is still okay when you are riding */
3029.     if (!reuse_ball)
3030.         You("are being punished for your misbehavior!");
3031.     if (Punished) {
3032.         Your("iron ball gets heavier.");
3033.         uball->owt += WT_IRON_BALL_INCR * (1 + cursed_levy);
3034.         return;
3035.     }
3036.     if (amorphous(gy.youmonst.data) || is_whirly(gy.youmonst.data)
3037.         || unsolid(gy.youmonst.data)) {
3038.         if (!reuse_ball) {
3039.             pline("A ball and chain appears, then falls away.");
3040.             dropy(mkobj(BALL_CLASS, TRUE));
3041.         } else {
3042.             dropy(reuse_ball);
3043.         }
3044.         return;
3045.     }
3046.     setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN);
3047.     if (!reuse_ball)
3048.         setworn(mkobj(BALL_CLASS, TRUE), W_BALL);
3049.     else
3050.         setworn(reuse_ball, W_BALL);
3051. 
3052.     /*
3053.      *  Place ball & chain if not swallowed.  If swallowed, the ball & chain
3054.      *  variables will be set at the next call to placebc().
3055.      */
3056.     if (!u.uswallow) {
3057.         placebc();
3058.         if (Blind)
3059.             set_bc(1);      /* set up ball and chain variables */
3060.         newsym(u.ux, u.uy); /* see ball&chain if can't see self */
3061.     }
3062. }
3063. 
3064. /* remove the ball and chain */
3065. void
3066. unpunish(void)
3067. {
3068.     struct obj *savechain = uchain;
3069. 
3070.     /* chain goes away */
3071.     setworn((struct obj *) 0, W_CHAIN); /* sets 'uchain' to Null */
3072.     /* for floor, unhides monster hidden under chain, calls newsym() */
3073.     delobj(savechain);
3074. 
3075.     /* the chain is gone but the no longer attached ball persists */
3076.     setworn((struct obj *) 0, W_BALL); /* sets 'uball' to Null */
3077. }
3078. 
3079. /* prompt the player to create a stinking cloud and then create it if they
3080.    give a location */
3081. staticfn void
3082. do_stinking_cloud(struct obj *sobj, boolean mention_stinking)
3083. {
3084.     coord cc;
3085. 
3086.     pline("Where do you want to center the %scloud?",
3087.           mention_stinking ? "stinking " : "");
3088.     cc.x = u.ux;
3089.     cc.y = u.uy;
3090.     getpos_sethilite(display_stinking_cloud_positions, can_center_cloud);
3091.     if (getpos(&cc, TRUE, "the desired position") < 0) {
3092.         pline1(Never_mind);
3093.         return;
3094.     } else if (!can_center_cloud(cc.x, cc.y)) {
3095.         if (Hallucination)
3096.             pline("Ugh... someone cut the cheese.");
3097.         else
3098.             pline("%s a whiff of rotten eggs.",
3099.                   sobj->oclass == SCROLL_CLASS ? "The scroll crumbles with"
3100.                                                : "You smell");
3101.         return;
3102.     }
3103.     (void) create_gas_cloud(cc.x, cc.y, 15 + 10 * bcsign(sobj),
3104.                             8 + 4 * bcsign(sobj));
3105. }
3106. 
3107. /* some creatures have special data structures that only make sense in their
3108.  * normal locations -- if the player tries to create one elsewhere, or to
3109.  * revive one, the disoriented creature becomes a zombie
3110.  */
3111. boolean
3112. cant_revive(
3113.     int *mtype,
3114.     boolean revival,
3115.     struct obj *from_obj)
3116. {
3117.     /* SHOPKEEPERS can be revived now */
3118.     if (*mtype == PM_GUARD || (*mtype == PM_SHOPKEEPER && !revival)
3119.         || *mtype == PM_HIGH_CLERIC || *mtype == PM_ALIGNED_CLERIC
3120.         || *mtype == PM_ANGEL) {
3121.         *mtype = PM_HUMAN_ZOMBIE;
3122.         return TRUE;
3123.     } else if (*mtype == PM_LONG_WORM_TAIL) { /* for create_particular() */
3124.         *mtype = PM_LONG_WORM;
3125.         return TRUE;
3126.     } else if (unique_corpstat(&mons[*mtype])
3127.                && (!from_obj || !has_omonst(from_obj))) {
3128.         /* unique corpses (from bones or wizard mode wish) or
3129.            statues (bones or any wish) end up as shapechangers */
3130.         *mtype = PM_DOPPELGANGER;
3131.         return TRUE;
3132.     }
3133.     return FALSE;
3134. }
3135. 
3136. staticfn boolean
3137. create_particular_parse(
3138.     char *str,
3139.     struct _create_particular_data *d)
3140. {
3141.     int gender_name_var = NEUTRAL;
3142.     char *bufp = str;
3143.     char *tmpp;
3144. 
3145.     d->quan = 1 + ((gm.multi > 0) ? (int) gm.multi : 0);
3146.     d->monclass = MAXMCLASSES;
3147.     d->which = gu.urole.mnum; /* an arbitrary index into mons[] */
3148.     d->fem = -1;     /* gender not specified */
3149.     d->genderconf = -1;  /* no confusion on which gender to assign */
3150.     d->randmonst = FALSE;
3151.     d->maketame = d->makepeaceful = d->makehostile = FALSE;
3152.     d->sleeping = d->saddled = d->invisible = d->hidden = FALSE;
3153. 
3154.     /* quantity */
3155.     if (digit(*bufp)) {
3156.         d->quan = atoi(bufp);
3157.         while (digit(*bufp))
3158.             bufp++;
3159.         while (*bufp == ' ')
3160.             bufp++;
3161.     }
3162. #define QUAN_LIMIT (ROWNO * (COLNO - 1))
3163.     /* maximum possible quantity is one per cell: (0..ROWNO-1) x (1..COLNO-1)
3164.        [21*79==1659 for default map size; could subtract 1 for hero's spot] */
3165.     if (d->quan < 1 || d->quan > QUAN_LIMIT)
3166.         d->quan = QUAN_LIMIT - monster_census(FALSE);
3167. #undef QUAN_LIMIT
3168.     /* gear -- extremely limited number of possibilities supported */
3169.     if ((tmpp = strstri(bufp, "saddled ")) != 0) {
3170.         d->saddled = TRUE;
3171.         (void) memset(tmpp, ' ', sizeof "saddled " - 1);
3172.     }
3173.     /* state -- limited number of possibilities supported */
3174.     if ((tmpp = strstri(bufp, "sleeping ")) != 0) {
3175.         d->sleeping = TRUE;
3176.         (void) memset(tmpp, ' ', sizeof "sleeping " - 1);
3177.     }
3178.     if ((tmpp = strstri(bufp, "invisible ")) != 0) {
3179.         d->invisible = TRUE;
3180.         (void) memset(tmpp, ' ', sizeof "invisible " - 1);
3181.     }
3182.     if ((tmpp = strstri(bufp, "hidden ")) != 0) {
3183.         d->hidden = TRUE;
3184.         (void) memset(tmpp, ' ', sizeof "hidden " - 1);
3185.     }
3186.     /* check "female" before "male" to avoid false hit mid-word */
3187.     if ((tmpp = strstri(bufp, "female ")) != 0) {
3188.         d->fem = 1;
3189.         (void) memset(tmpp, ' ', sizeof "female " - 1);
3190.     }
3191.     if ((tmpp = strstri(bufp, "male ")) != 0) {
3192.         d->fem = 0;
3193.         (void) memset(tmpp, ' ', sizeof "male " - 1);
3194.     }
3195.     bufp = mungspaces(bufp); /* after potential memset(' ') */
3196.     /* allow the initial disposition to be specified */
3197.     if (!strncmpi(bufp, "tame ", 5)) {
3198.         bufp += 5;
3199.         d->maketame = TRUE;
3200.     } else if (!strncmpi(bufp, "peaceful ", 9)) {
3201.         bufp += 9;
3202.         d->makepeaceful = TRUE;
3203.     } else if (!strncmpi(bufp, "hostile ", 8)) {
3204.         bufp += 8;
3205.         d->makehostile = TRUE;
3206.     }
3207.     /* decide whether a valid monster was chosen */
3208.     if (wizard && (!strcmp(bufp, "*") || !strcmp(bufp, "random"))) {
3209.         d->randmonst = TRUE;
3210.         return TRUE;
3211.     }
3212.     d->which = name_to_mon(bufp, &gender_name_var);
3213.     /*
3214.      * With the introduction of male and female monster names
3215.      * in 5.0, preserve that detail.
3216.      *
3217.      * If d->fem is already set to MALE or FEMALE at this juncture, it means
3218.      * one of those terms was explicitly specified.
3219.      */
3220.     if (d->fem == MALE || d->fem == FEMALE) {     /* explicitly expressed */
3221.         if ((gender_name_var != NEUTRAL) && (d->fem != gender_name_var)) {
3222.             /* apparent selection incompatibility */
3223.             d->genderconf = gender_name_var;        /* resolve later */
3224.         }
3225.         /* otherwise keep the value of d->fem, as it's okay */
3226.     } else {  /* no explicit gender term was specified */
3227.         d->fem = gender_name_var;
3228.     }
3229.     if (ismnum(d->which))
3230.         return TRUE; /* got one */
3231.     d->monclass = name_to_monclass(bufp, &d->which);
3232. 
3233.     if (ismnum(d->which)) {
3234.         d->monclass = MAXMCLASSES; /* matters below */
3235.         return TRUE;
3236.     } else if (d->monclass == S_invisible) { /* not an actual monster class */
3237.         d->which = PM_STALKER;
3238.         d->monclass = MAXMCLASSES;
3239.         return TRUE;
3240.     } else if (d->monclass == S_WORM_TAIL) { /* empty monster class */
3241.         d->which = PM_LONG_WORM;
3242.         d->monclass = MAXMCLASSES;
3243.         return TRUE;
3244.     } else if (d->monclass > 0) {
3245.         d->which = gu.urole.mnum; /* reset from NON_PM */
3246.         return TRUE;
3247.     }
3248.     return FALSE;
3249. }
3250. 
3251. staticfn boolean
3252. create_particular_creation(
3253.     struct _create_particular_data *d)
3254. {
3255.     struct permonst *whichpm = NULL;
3256.     int i, mx, my, firstchoice = NON_PM;
3257.     struct monst *mtmp;
3258.     boolean madeany = FALSE;
3259. 
3260.     if (!d->randmonst) {
3261.         firstchoice = d->which;
3262.         if (cant_revive(&d->which, FALSE, (struct obj *) 0)
3263.             && firstchoice != PM_LONG_WORM_TAIL) {
3264.             /* wizard mode can override handling of special monsters */
3265.             char buf[BUFSZ];
3266. 
3267.             Sprintf(buf, "Creating %s instead; force %s?",
3268.                     mons[d->which].pmnames[NEUTRAL],
3269.                     mons[firstchoice].pmnames[NEUTRAL]);
3270.             if (y_n(buf) == 'y')
3271.                 d->which = firstchoice;
3272.         }
3273.         whichpm = &mons[d->which];
3274.     }
3275.     for (i = 0; i < d->quan; i++) {
3276.         mmflags_nht mmflags = NO_MM_FLAGS;
3277. 
3278.         if (d->monclass != MAXMCLASSES)
3279.             whichpm = mkclass(d->monclass, 0);
3280.         else if (d->randmonst)
3281.             whichpm = rndmonst();
3282.         if (d->genderconf == -1) {
3283.             /* no conflict exists between explicit gender term and
3284.                the specified monster name */
3285.             if (d->fem != -1 && (!whichpm || (!is_male(whichpm)
3286.                                               && !is_female(whichpm))))
3287.                 mmflags |= (d->fem == FEMALE) ? MM_FEMALE
3288.                                : (d->fem == MALE) ? MM_MALE : 0;
3289.             /* no surprise; "<mon> appears." rather than "<mon> appears!" */
3290.             mmflags |= MM_NOEXCLAM;
3291.         } else {
3292.             /* conundrum alert: an explicit gender term conflicts with an
3293.                explicit gender-tied naming term (i.e. male cavewoman) */
3294. 
3295.             /* option not gone with: name overrides the explicit gender as
3296.                commented out here */
3297.             /*  d->fem = d->genderconf; */
3298. 
3299.             /* option chosen: let the explicit gender term (male or female)
3300.                override the gender-tied naming term, so leave d->fem as-is */
3301. 
3302.             mmflags |= (d->fem == FEMALE) ? MM_FEMALE
3303.                            : (d->fem == MALE) ? MM_MALE : 0;
3304. 
3305.             /* another option would be to consider it a faulty specification
3306.                and reject the request completely and produce a random monster
3307.                with a gender matching that specified instead (i.e. there is
3308.                no such thing as a male cavewoman) */
3309.             /* whichpm = rndmonst(); */
3310.             /* mmflags |= (d->fem == FEMALE) ? MM_FEMALE : MM_MALE; */
3311.         }
3312.         if (d->invisible)
3313.             mmflags |= MM_MINVIS;
3314. 
3315.         mtmp = makemon(whichpm, u.ux, u.uy, mmflags);
3316.         if (!mtmp) {
3317.             /* quit trying if creation failed and is going to repeat */
3318.             if (d->monclass == MAXMCLASSES && !d->randmonst)
3319.                 break;
3320.             /* otherwise try again */
3321.             continue;
3322.         }
3323.         mx = mtmp->mx, my = mtmp->my;
3324.         if (d->maketame) {
3325.             (void) tamedog(mtmp, (struct obj *) 0, FALSE);
3326.         } else if (d->makepeaceful || d->makehostile) {
3327.             mtmp->mtame = 0; /* sanity precaution */
3328.             mtmp->mpeaceful = d->makepeaceful ? 1 : 0;
3329.             set_malign(mtmp);
3330.         }
3331.         if (d->saddled && can_saddle(mtmp) && !which_armor(mtmp, W_SADDLE)) {
3332.             /* NULL obj arg means put_saddle_on_mon()
3333.              * will create the saddle itself */
3334.             put_saddle_on_mon((struct obj *) 0, mtmp);
3335.         }
3336.         if (d->hidden
3337.            && ((is_hider(mtmp->data) && mtmp->data->mlet != S_MIMIC)
3338.                || (hides_under(mtmp->data) && OBJ_AT(mx, my))
3339.                || (mtmp->data->mlet == S_EEL && is_pool(mx, my))))
3340.             mtmp->mundetected = 1;
3341.         if (d->sleeping)
3342.             mtmp->msleeping = 1;
3343.         /* if asking for 'hidden', show location of every created monster
3344.            that can't be seen--whether that's due to successfully hiding
3345.            or vision issues (line-of-sight, invisibility, blindness) */
3346.         if ((d->hidden || d->invisible) && !canspotmon(mtmp))
3347.             flash_mon(mtmp);
3348. 
3349.         madeany = TRUE;
3350.         /* in case we got a doppelganger instead of what was asked
3351.            for, make it start out looking like what was asked for */
3352.         if (mtmp->cham != NON_PM && firstchoice != NON_PM
3353.             && mtmp->cham != firstchoice)
3354.             (void) newcham(mtmp, &mons[firstchoice], NO_NC_FLAGS);
3355.     }
3356.     return madeany;
3357. }
3358. 
3359. /*
3360.  * Make a new monster with the type controlled by the user.
3361.  *
3362.  * Note:  when creating a monster by class letter, specifying the
3363.  * "strange object" (']') symbol produces a random monster rather
3364.  * than a mimic.  This behavior quirk is useful so don't "fix" it
3365.  * (use 'm'--or "mimic"--to create a random mimic).
3366.  *
3367.  * Used in wizard mode only (for ^G command and for scroll or spell
3368.  * of create monster).  Once upon a time, an earlier incarnation of
3369.  * this code was also used for the scroll/spell in explore mode.
3370.  */
3371. boolean
3372. create_particular(void)
3373. {
3374. #define CP_TRYLIM 5
3375.     struct _create_particular_data d;
3376.     char *bufp, buf[BUFSZ], prompt[QBUFSZ];
3377.     int  tryct = CP_TRYLIM, altmsg = 0;
3378. 
3379.     buf[0] = '\0'; /* for EDIT_GETLIN */
3380.     Strcpy(prompt, "Create what kind of monster?");
3381.     do {
3382.         getlin(prompt, buf);
3383.         bufp = mungspaces(buf);
3384.         if (*bufp == '\033')
3385.             return FALSE;
3386. 
3387.         if (create_particular_parse(bufp, &d))
3388.             break;
3389. 
3390.         /* no good; try again... */
3391.         if (*bufp || altmsg || tryct < 2) {
3392.             pline("I've never heard of such monsters.");
3393.         } else {
3394.             pline("Try again (type * for random, ESC to cancel).");
3395.             ++altmsg;
3396.         }
3397.         /* when a second try is needed, expand the prompt */
3398.         if (tryct == CP_TRYLIM)
3399.             Strcat(prompt, " [type name or symbol]");
3400.     } while (--tryct > 0);
3401. 
3402.     if (!tryct)
3403.         pline1(thats_enough_tries);
3404.     else
3405.         return create_particular_creation(&d);
3406. 
3407.     return FALSE;
3408. }
3409. 
3410. /*read.c*/