Move generic usernames to sysconf
[aNetHack.git] / src / read.c
blobfbf9f820188f439200b6c60fd3082c35d38c8807
1 /* NetHack 3.6 read.c $NHDT-Date: 1457660917 2016/03/11 01:48:37 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.136 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
5 #include "hack.h"
7 #define Your_Own_Role(mndx) \
8 ((mndx) == urole.malenum \
9 || (urole.femalenum != NON_PM && (mndx) == urole.femalenum))
10 #define Your_Own_Race(mndx) \
11 ((mndx) == urace.malenum \
12 || (urace.femalenum != NON_PM && (mndx) == urace.femalenum))
14 boolean known;
16 static NEARDATA const char readable[] = { ALL_CLASSES, SCROLL_CLASS,
17 SPBOOK_CLASS, 0 };
18 static const char all_count[] = { ALLOW_COUNT, ALL_CLASSES, 0 };
20 STATIC_DCL boolean FDECL(learnscrolltyp, (SHORT_P));
21 STATIC_DCL char * FDECL(erode_obj_text, (struct obj *, char *));
22 STATIC_DCL void NDECL(do_class_genocide);
23 STATIC_DCL void FDECL(stripspe, (struct obj *));
24 STATIC_DCL void FDECL(p_glow1, (struct obj *));
25 STATIC_DCL void FDECL(p_glow2, (struct obj *, const char *));
26 STATIC_DCL void FDECL(randomize, (int *, int));
27 STATIC_DCL void FDECL(forget_single_object, (int));
28 STATIC_DCL void FDECL(forget, (int));
29 STATIC_DCL int FDECL(maybe_tame, (struct monst *, struct obj *));
30 STATIC_DCL boolean FDECL(is_valid_stinking_cloud_pos, (int, int, BOOLEAN_P));
31 STATIC_DCL void FDECL(display_stinking_cloud_positions, (int));
32 STATIC_PTR void FDECL(set_lit, (int, int, genericptr));
34 STATIC_OVL boolean
35 learnscrolltyp(scrolltyp)
36 short scrolltyp;
38 if (!objects[scrolltyp].oc_name_known) {
39 makeknown(scrolltyp);
40 more_experienced(0, 10);
41 return TRUE;
42 } else
43 return FALSE;
46 /* also called from teleport.c for scroll of teleportation */
47 void
48 learnscroll(sobj)
49 struct obj *sobj;
51 /* it's implied that sobj->dknown is set;
52 we couldn't be reading this scroll otherwise */
53 if (sobj->oclass != SPBOOK_CLASS)
54 (void) learnscrolltyp(sobj->otyp);
57 char *
58 erode_obj_text(otmp, buf)
59 struct obj *otmp;
60 char *buf;
62 int erosion = greatest_erosion(otmp);
64 if (erosion)
65 wipeout_text(buf, (int) (strlen(buf) * erosion / (2 * MAX_ERODE)),
66 otmp->o_id ^ (unsigned) ubirthday);
67 return buf;
70 char *
71 tshirt_text(tshirt, buf)
72 struct obj *tshirt;
73 char *buf;
75 static const char *shirt_msgs[] = {
76 /* Scott Bigham */
77 "I explored the Dungeons of Doom and all I got was this lousy T-shirt!",
78 "Is that Mjollnir in your pocket or are you just happy to see me?",
79 "It's not the size of your sword, it's how #enhance'd you are with it.",
80 "Madame Elvira's House O' Succubi Lifetime Customer",
81 "Madame Elvira's House O' Succubi Employee of the Month",
82 "Ludios Vault Guards Do It In Small, Dark Rooms",
83 "Yendor Military Soldiers Do It In Large Groups",
84 "I survived Yendor Military Boot Camp",
85 "Ludios Accounting School Intra-Mural Lacrosse Team",
86 "Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest",
87 "Hey, black dragon! Disintegrate THIS!",
88 "I'm With Stupid -->",
89 "Don't blame me, I voted for Izchak!",
90 "Don't Panic", /* HHGTTG */
91 "Furinkan High School Athletic Dept.", /* Ranma 1/2 */
92 "Hel-LOOO, Nurse!", /* Animaniacs */
93 "=^.^=",
94 "100% goblin hair - do not wash",
95 "Aberzombie and Fitch",
96 "cK -- Cockatrice touches the Kop",
97 "Don't ask me, I only adventure here",
98 "Down with pants!",
99 "d, your dog or a killer?",
100 "FREE PUG AND NEWT!",
101 "Go team ant!",
102 "Got newt?",
103 "Hello, my darlings!", /* Charlie Drake */
104 "Hey! Nymphs! Steal This T-Shirt!",
105 "I <3 Dungeon of Doom",
106 "I <3 Maud",
107 "I am a Valkyrie. If you see me running, try to keep up.",
108 "I am not a pack rat - I am a collector",
109 "I bounced off a rubber tree", /* Monkey Island */
110 "Plunder Island Brimstone Beach Club", /* Monkey Island */
111 "If you can read this, I can hit you with my polearm",
112 "I'm confused!",
113 "I scored with the princess",
114 "I want to live forever or die in the attempt.",
115 "Lichen Park",
116 "LOST IN THOUGHT - please send search party",
117 "Meat is Mordor",
118 "Minetown Better Business Bureau",
119 "Minetown Watch",
120 "Ms. Palm's House of Negotiable Affection -- A Very Reputable House Of Disrepute",
121 "Protection Racketeer",
122 "Real men love Crom",
123 "Somebody stole my Mojo!",
124 "The Hellhound Gang",
125 "The Werewolves",
126 "They Might Be Storm Giants",
127 "Weapons don't kill people, I kill people",
128 "White Zombie",
129 "You're killing me!",
130 "Anhur State University - Home of the Fighting Fire Ants!",
131 "FREE HUGS",
132 "Serial Ascender",
133 "Real men are valkyries",
134 "Young Men's Cavedigging Association",
135 "Occupy Fort Ludios",
136 "I couldn't afford this T-shirt so I stole it!",
137 "Mind flayers suck",
138 "I'm not wearing any pants",
139 "Down with the living!",
140 "Pudding farmer",
141 "Vegetarian",
142 "Hello, I'm War!",
145 Strcpy(buf, shirt_msgs[tshirt->o_id % SIZE(shirt_msgs)]);
146 return erode_obj_text(tshirt, buf);
149 char *
150 apron_text(apron, buf)
151 struct obj *apron;
152 char *buf;
154 static const char *apron_msgs[] = {
155 "Kiss the cook",
156 "I'm making SCIENCE!",
157 "Don't mess with the chef",
158 "Don't make me poison you",
159 "Gehennom's Kitchen",
160 "Rat: The other white meat",
161 "If you can't stand the heat, get out of Gehennom!",
162 "If we weren't meant to eat animals, why are they made out of meat?",
163 "If you don't like the food, I'll stab you",
166 Strcpy(buf, apron_msgs[apron->o_id % SIZE(apron_msgs)]);
167 return erode_obj_text(apron, buf);
171 doread()
173 register struct obj *scroll;
174 boolean confused, nodisappear;
176 known = FALSE;
177 if (check_capacity((char *) 0))
178 return 0;
179 scroll = getobj(readable, "read");
180 if (!scroll)
181 return 0;
183 /* outrumor has its own blindness check */
184 if (scroll->otyp == FORTUNE_COOKIE) {
185 if (flags.verbose)
186 You("break up the cookie and throw away the pieces.");
187 outrumor(bcsign(scroll), BY_COOKIE);
188 if (!Blind)
189 u.uconduct.literate++;
190 useup(scroll);
191 return 1;
192 } else if (scroll->otyp == T_SHIRT || scroll->otyp == ALCHEMY_SMOCK) {
193 char buf[BUFSZ];
194 if (Blind) {
195 You_cant("feel any Braille writing.");
196 return 0;
198 /* can't read shirt worn under suit (under cloak is ok though) */
199 if (scroll->otyp == T_SHIRT && uarm && scroll == uarmu) {
200 pline("%s shirt is obscured by %s%s.",
201 scroll->unpaid ? "That" : "Your", shk_your(buf, uarm),
202 suit_simple_name(uarm));
203 return 0;
205 u.uconduct.literate++;
206 if (flags.verbose)
207 pline("It reads:");
208 pline("\"%s\"", (scroll->otyp == T_SHIRT) ? tshirt_text(scroll, buf)
209 : apron_text(scroll, buf));
210 return 1;
211 } else if (scroll->otyp == CREDIT_CARD) {
212 static const char *card_msgs[] = {
213 "Leprechaun Gold Tru$t - Shamrock Card",
214 "Magic Memory Vault Charge Card", "Larn National Bank", /* Larn */
215 "First Bank of Omega", /* Omega */
216 "Bank of Zork - Frobozz Magic Card", /* Zork */
217 "Ankh-Morpork Merchant's Guild Barter Card",
218 "Ankh-Morpork Thieves' Guild Unlimited Transaction Card",
219 "Ransmannsby Moneylenders Association",
220 "Bank of Gehennom - 99% Interest Card",
221 "Yendorian Express - Copper Card",
222 "Yendorian Express - Silver Card",
223 "Yendorian Express - Gold Card",
224 "Yendorian Express - Mithril Card",
225 "Yendorian Express - Platinum Card", /* must be last */
228 if (Blind) {
229 You("feel the embossed numbers:");
230 } else {
231 if (flags.verbose)
232 pline("It reads:");
233 pline("\"%s\"",
234 scroll->oartifact
235 ? card_msgs[SIZE(card_msgs) - 1]
236 : card_msgs[scroll->o_id % (SIZE(card_msgs) - 1)]);
238 /* Make a credit card number */
239 pline("\"%d0%d %d%d1 0%d%d0\"", ((scroll->o_id % 89) + 10),
240 (scroll->o_id % 4), (((scroll->o_id * 499) % 899999) + 100000),
241 (scroll->o_id % 10), (!(scroll->o_id % 3)),
242 ((scroll->o_id * 7) % 10));
243 u.uconduct.literate++;
244 return 1;
245 } else if (scroll->otyp == CAN_OF_GREASE) {
246 pline("This %s has no label.", singular(scroll, xname));
247 return 0;
248 } else if (scroll->otyp == MAGIC_MARKER) {
249 if (Blind) {
250 You_cant("feel any Braille writing.");
251 return 0;
253 if (flags.verbose)
254 pline("It reads:");
255 pline("\"Magic Marker(TM) Red Ink Marker Pen. Water Soluble.\"");
256 u.uconduct.literate++;
257 return 1;
258 } else if (scroll->oclass == COIN_CLASS) {
259 if (Blind)
260 You("feel the embossed words:");
261 else if (flags.verbose)
262 You("read:");
263 pline("\"1 Zorkmid. 857 GUE. In Frobs We Trust.\"");
264 u.uconduct.literate++;
265 return 1;
266 } else if (scroll->oartifact == ART_ORB_OF_FATE) {
267 if (Blind)
268 You("feel the engraved signature:");
269 else
270 pline("It is signed:");
271 pline("\"Odin.\"");
272 u.uconduct.literate++;
273 return 1;
274 } else if (scroll->otyp == CANDY_BAR) {
275 static const char *wrapper_msgs[] = {
276 "Apollo", /* Lost */
277 "Moon Crunchy", /* South Park */
278 "Snacky Cake", "Chocolate Nuggie", "The Small Bar",
279 "Crispy Yum Yum", "Nilla Crunchie", "Berry Bar",
280 "Choco Nummer", "Om-nom", /* Cat Macro */
281 "Fruity Oaty", /* Serenity */
282 "Wonka Bar" /* Charlie and the Chocolate Factory */
285 if (Blind) {
286 You_cant("feel any Braille writing.");
287 return 0;
289 pline("The wrapper reads: \"%s\"",
290 wrapper_msgs[scroll->o_id % SIZE(wrapper_msgs)]);
291 u.uconduct.literate++;
292 return 1;
293 } else if (scroll->oclass != SCROLL_CLASS
294 && scroll->oclass != SPBOOK_CLASS) {
295 pline(silly_thing_to, "read");
296 return 0;
297 } else if (Blind && (scroll->otyp != SPE_BOOK_OF_THE_DEAD)) {
298 const char *what = 0;
299 if (scroll->oclass == SPBOOK_CLASS)
300 what = "mystic runes";
301 else if (!scroll->dknown)
302 what = "formula on the scroll";
303 if (what) {
304 pline("Being blind, you cannot read the %s.", what);
305 return 0;
309 confused = (Confusion != 0);
310 #ifdef MAIL
311 if (scroll->otyp == SCR_MAIL) {
312 confused = FALSE; /* override */
313 /* reading mail is a convenience for the player and takes
314 place outside the game, so shouldn't affect gameplay;
315 on the other hand, it starts by explicitly making the
316 hero actively read something, which is pretty hard
317 to simply ignore; as a compromise, if the player has
318 maintained illiterate conduct so far, and this mail
319 scroll didn't come from bones, ask for confirmation */
320 if (!u.uconduct.literate) {
321 if (!scroll->spe && yn(
322 "Reading mail will violate \"illiterate\" conduct. Read anyway?"
323 ) != 'y')
324 return 0;
327 #endif
329 /* Actions required to win the game aren't counted towards conduct */
330 /* Novel conduct is handled in read_tribute so exclude it too*/
331 if (scroll->otyp != SPE_BOOK_OF_THE_DEAD
332 && scroll->otyp != SPE_BLANK_PAPER && scroll->otyp != SCR_BLANK_PAPER
333 && scroll->otyp != SPE_NOVEL)
334 u.uconduct.literate++;
336 if (scroll->oclass == SPBOOK_CLASS) {
337 return study_book(scroll);
339 scroll->in_use = TRUE; /* scroll, not spellbook, now being read */
340 if (scroll->otyp != SCR_BLANK_PAPER) {
341 /* a few scroll feedback messages describe something happening
342 to the scroll itself, so avoid "it disappears" for those */
343 nodisappear = (scroll->otyp == SCR_FIRE
344 || (scroll->otyp == SCR_REMOVE_CURSE
345 && scroll->cursed));
346 if (Blind)
347 pline(nodisappear
348 ? "You %s the formula on the scroll."
349 : "As you %s the formula on it, the scroll disappears.",
350 is_silent(youmonst.data) ? "cogitate" : "pronounce");
351 else
352 pline(nodisappear ? "You read the scroll."
353 : "As you read the scroll, it disappears.");
354 if (confused) {
355 if (Hallucination)
356 pline("Being so trippy, you screw up...");
357 else
358 pline("Being confused, you %s the magic words...",
359 is_silent(youmonst.data) ? "misunderstand"
360 : "mispronounce");
363 if (!seffects(scroll)) {
364 if (!objects[scroll->otyp].oc_name_known) {
365 if (known)
366 learnscroll(scroll);
367 else if (!objects[scroll->otyp].oc_uname)
368 docall(scroll);
370 scroll->in_use = FALSE;
371 if (scroll->otyp != SCR_BLANK_PAPER)
372 useup(scroll);
374 return 1;
377 STATIC_OVL void
378 stripspe(obj)
379 register struct obj *obj;
381 if (obj->blessed || obj->spe <= 0) {
382 pline1(nothing_happens);
383 } else {
384 /* order matters: message, shop handling, actual transformation */
385 pline("%s briefly.", Yobjnam2(obj, "vibrate"));
386 costly_alteration(obj, COST_UNCHRG);
387 obj->spe = 0;
388 if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN)
389 obj->age = 0;
393 STATIC_OVL void
394 p_glow1(otmp)
395 register struct obj *otmp;
397 pline("%s briefly.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"));
400 STATIC_OVL void
401 p_glow2(otmp, color)
402 register struct obj *otmp;
403 register const char *color;
405 pline("%s%s%s for a moment.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"),
406 Blind ? "" : " ", Blind ? "" : hcolor(color));
409 /* Is the object chargeable? For purposes of inventory display; it is
410 possible to be able to charge things for which this returns FALSE. */
411 boolean
412 is_chargeable(obj)
413 struct obj *obj;
415 if (obj->oclass == WAND_CLASS)
416 return TRUE;
417 /* known && !oc_name_known is possible after amnesia/mind flayer */
418 if (obj->oclass == RING_CLASS)
419 return (boolean) (objects[obj->otyp].oc_charged
420 && (obj->known
421 || (obj->dknown
422 && objects[obj->otyp].oc_name_known)));
423 if (is_weptool(obj)) /* specific check before general tools */
424 return FALSE;
425 if (obj->oclass == TOOL_CLASS)
426 return (boolean) objects[obj->otyp].oc_charged;
427 return FALSE; /* why are weapons/armor considered charged anyway? */
430 /* recharge an object; curse_bless is -1 if the recharging implement
431 was cursed, +1 if blessed, 0 otherwise. */
432 void
433 recharge(obj, curse_bless)
434 struct obj *obj;
435 int curse_bless;
437 register int n;
438 boolean is_cursed, is_blessed;
440 is_cursed = curse_bless < 0;
441 is_blessed = curse_bless > 0;
443 if (obj->oclass == WAND_CLASS) {
444 int lim = (obj->otyp == WAN_WISHING)
446 : (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15;
448 /* undo any prior cancellation, even when is_cursed */
449 if (obj->spe == -1)
450 obj->spe = 0;
453 * Recharging might cause wands to explode.
454 * v = number of previous recharges
455 * v = percentage chance to explode on this attempt
456 * v = cumulative odds for exploding
457 * 0 : 0 0
458 * 1 : 0.29 0.29
459 * 2 : 2.33 2.62
460 * 3 : 7.87 10.28
461 * 4 : 18.66 27.02
462 * 5 : 36.44 53.62
463 * 6 : 62.97 82.83
464 * 7 : 100 100
466 n = (int) obj->recharged;
467 if (n > 0 && (obj->otyp == WAN_WISHING
468 || (n * n * n > rn2(7 * 7 * 7)))) { /* recharge_limit */
469 wand_explode(obj, rnd(lim));
470 return;
472 /* didn't explode, so increment the recharge count */
473 obj->recharged = (unsigned) (n + 1);
475 /* now handle the actual recharging */
476 if (is_cursed) {
477 stripspe(obj);
478 } else {
479 n = (lim == 3) ? 3 : rn1(5, lim + 1 - 5);
480 if (!is_blessed)
481 n = rnd(n);
483 if (obj->spe < n)
484 obj->spe = n;
485 else
486 obj->spe++;
487 if (obj->otyp == WAN_WISHING && obj->spe > 3) {
488 wand_explode(obj, 1);
489 return;
491 if (obj->spe >= lim)
492 p_glow2(obj, NH_BLUE);
493 else
494 p_glow1(obj);
495 #if 0 /*[shop price doesn't vary by charge count]*/
496 /* update shop bill to reflect new higher price */
497 if (obj->unpaid)
498 alter_cost(obj, 0L);
499 #endif
502 } else if (obj->oclass == RING_CLASS && objects[obj->otyp].oc_charged) {
503 /* charging does not affect ring's curse/bless status */
504 int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1;
505 boolean is_on = (obj == uleft || obj == uright);
507 /* destruction depends on current state, not adjustment */
508 if (obj->spe > rn2(7) || obj->spe <= -5) {
509 pline("%s momentarily, then %s!", Yobjnam2(obj, "pulsate"),
510 otense(obj, "explode"));
511 if (is_on)
512 Ring_gone(obj);
513 s = rnd(3 * abs(obj->spe)); /* amount of damage */
514 useup(obj);
515 losehp(Maybe_Half_Phys(s), "exploding ring", KILLED_BY_AN);
516 } else {
517 long mask = is_on ? (obj == uleft ? LEFT_RING : RIGHT_RING) : 0L;
519 pline("%s spins %sclockwise for a moment.", Yname2(obj),
520 s < 0 ? "counter" : "");
521 if (s < 0)
522 costly_alteration(obj, COST_DECHNT);
523 /* cause attributes and/or properties to be updated */
524 if (is_on)
525 Ring_off(obj);
526 obj->spe += s; /* update the ring while it's off */
527 if (is_on)
528 setworn(obj, mask), Ring_on(obj);
529 /* oartifact: if a touch-sensitive artifact ring is
530 ever created the above will need to be revised */
531 /* update shop bill to reflect new higher price */
532 if (s > 0 && obj->unpaid)
533 alter_cost(obj, 0L);
536 } else if (obj->oclass == TOOL_CLASS) {
537 int rechrg = (int) obj->recharged;
539 if (objects[obj->otyp].oc_charged) {
540 /* tools don't have a limit, but the counter used does */
541 if (rechrg < 7) /* recharge_limit */
542 obj->recharged++;
544 switch (obj->otyp) {
545 case BELL_OF_OPENING:
546 if (is_cursed)
547 stripspe(obj);
548 else if (is_blessed)
549 obj->spe += rnd(3);
550 else
551 obj->spe += 1;
552 if (obj->spe > 5)
553 obj->spe = 5;
554 break;
555 case MAGIC_MARKER:
556 case TINNING_KIT:
557 case EXPENSIVE_CAMERA:
558 if (is_cursed)
559 stripspe(obj);
560 else if (rechrg
561 && obj->otyp
562 == MAGIC_MARKER) { /* previously recharged */
563 obj->recharged = 1; /* override increment done above */
564 if (obj->spe < 3)
565 Your("marker seems permanently dried out.");
566 else
567 pline1(nothing_happens);
568 } else if (is_blessed) {
569 n = rn1(16, 15); /* 15..30 */
570 if (obj->spe + n <= 50)
571 obj->spe = 50;
572 else if (obj->spe + n <= 75)
573 obj->spe = 75;
574 else {
575 int chrg = (int) obj->spe;
576 if ((chrg + n) > 127)
577 obj->spe = 127;
578 else
579 obj->spe += n;
581 p_glow2(obj, NH_BLUE);
582 } else {
583 n = rn1(11, 10); /* 10..20 */
584 if (obj->spe + n <= 50)
585 obj->spe = 50;
586 else {
587 int chrg = (int) obj->spe;
588 if ((chrg + n) > 127)
589 obj->spe = 127;
590 else
591 obj->spe += n;
593 p_glow2(obj, NH_WHITE);
595 break;
596 case OIL_LAMP:
597 case BRASS_LANTERN:
598 if (is_cursed) {
599 stripspe(obj);
600 if (obj->lamplit) {
601 if (!Blind)
602 pline("%s out!", Tobjnam(obj, "go"));
603 end_burn(obj, TRUE);
605 } else if (is_blessed) {
606 obj->spe = 1;
607 obj->age = 1500;
608 p_glow2(obj, NH_BLUE);
609 } else {
610 obj->spe = 1;
611 obj->age += 750;
612 if (obj->age > 1500)
613 obj->age = 1500;
614 p_glow1(obj);
616 break;
617 case CRYSTAL_BALL:
618 if (is_cursed) {
619 stripspe(obj);
620 } else if (is_blessed) {
621 obj->spe = 6;
622 p_glow2(obj, NH_BLUE);
623 } else {
624 if (obj->spe < 5) {
625 obj->spe++;
626 p_glow1(obj);
627 } else
628 pline1(nothing_happens);
630 break;
631 case HORN_OF_PLENTY:
632 case BAG_OF_TRICKS:
633 case CAN_OF_GREASE:
634 if (is_cursed) {
635 stripspe(obj);
636 } else if (is_blessed) {
637 if (obj->spe <= 10)
638 obj->spe += rn1(10, 6);
639 else
640 obj->spe += rn1(5, 6);
641 if (obj->spe > 50)
642 obj->spe = 50;
643 p_glow2(obj, NH_BLUE);
644 } else {
645 obj->spe += rnd(5);
646 if (obj->spe > 50)
647 obj->spe = 50;
648 p_glow1(obj);
650 break;
651 case MAGIC_FLUTE:
652 case MAGIC_HARP:
653 case FROST_HORN:
654 case FIRE_HORN:
655 case DRUM_OF_EARTHQUAKE:
656 if (is_cursed) {
657 stripspe(obj);
658 } else if (is_blessed) {
659 obj->spe += d(2, 4);
660 if (obj->spe > 20)
661 obj->spe = 20;
662 p_glow2(obj, NH_BLUE);
663 } else {
664 obj->spe += rnd(4);
665 if (obj->spe > 20)
666 obj->spe = 20;
667 p_glow1(obj);
669 break;
670 default:
671 goto not_chargable;
672 /*NOTREACHED*/
673 break;
674 } /* switch */
676 } else {
677 not_chargable:
678 You("have a feeling of loss.");
682 /* Forget known information about this object type. */
683 STATIC_OVL void
684 forget_single_object(obj_id)
685 int obj_id;
687 objects[obj_id].oc_name_known = 0;
688 objects[obj_id].oc_pre_discovered = 0; /* a discovery when relearned */
689 if (objects[obj_id].oc_uname) {
690 free((genericptr_t) objects[obj_id].oc_uname);
691 objects[obj_id].oc_uname = 0;
693 undiscover_object(obj_id); /* after clearing oc_name_known */
695 /* clear & free object names from matching inventory items too? */
698 #if 0 /* here if anyone wants it.... */
699 /* Forget everything known about a particular object class. */
700 STATIC_OVL void
701 forget_objclass(oclass)
702 int oclass;
704 int i;
706 for (i = bases[oclass];
707 i < NUM_OBJECTS && objects[i].oc_class == oclass; i++)
708 forget_single_object(i);
710 #endif
712 /* randomize the given list of numbers 0 <= i < count */
713 STATIC_OVL void
714 randomize(indices, count)
715 int *indices;
716 int count;
718 int i, iswap, temp;
720 for (i = count - 1; i > 0; i--) {
721 if ((iswap = rn2(i + 1)) == i)
722 continue;
723 temp = indices[i];
724 indices[i] = indices[iswap];
725 indices[iswap] = temp;
729 /* Forget % of known objects. */
730 void
731 forget_objects(percent)
732 int percent;
734 int i, count;
735 int indices[NUM_OBJECTS];
737 if (percent == 0)
738 return;
739 if (percent <= 0 || percent > 100) {
740 impossible("forget_objects: bad percent %d", percent);
741 return;
744 indices[0] = 0; /* lint suppression */
745 for (count = 0, i = 1; i < NUM_OBJECTS; i++)
746 if (OBJ_DESCR(objects[i])
747 && (objects[i].oc_name_known || objects[i].oc_uname))
748 indices[count++] = i;
750 if (count > 0) {
751 randomize(indices, count);
753 /* forget first % of randomized indices */
754 count = ((count * percent) + rn2(100)) / 100;
755 for (i = 0; i < count; i++)
756 forget_single_object(indices[i]);
760 /* Forget some or all of map (depends on parameters). */
761 void
762 forget_map(howmuch)
763 int howmuch;
765 register int zx, zy;
767 if (Sokoban)
768 return;
770 known = TRUE;
771 for (zx = 0; zx < COLNO; zx++)
772 for (zy = 0; zy < ROWNO; zy++)
773 if (howmuch & ALL_MAP || rn2(7)) {
774 /* Zonk all memory of this location. */
775 levl[zx][zy].seenv = 0;
776 levl[zx][zy].waslit = 0;
777 levl[zx][zy].glyph = cmap_to_glyph(S_stone);
778 lastseentyp[zx][zy] = STONE;
780 /* forget overview data for this level */
781 forget_mapseen(ledger_no(&u.uz));
784 /* Forget all traps on the level. */
785 void
786 forget_traps()
788 register struct trap *trap;
790 /* forget all traps (except the one the hero is in :-) */
791 for (trap = ftrap; trap; trap = trap->ntrap)
792 if ((trap->tx != u.ux || trap->ty != u.uy) && (trap->ttyp != HOLE))
793 trap->tseen = 0;
797 * Forget given % of all levels that the hero has visited and not forgotten,
798 * except this one.
800 void
801 forget_levels(percent)
802 int percent;
804 int i, count;
805 xchar maxl, this_lev;
806 int indices[MAXLINFO];
808 if (percent == 0)
809 return;
811 if (percent <= 0 || percent > 100) {
812 impossible("forget_levels: bad percent %d", percent);
813 return;
816 this_lev = ledger_no(&u.uz);
817 maxl = maxledgerno();
819 /* count & save indices of non-forgotten visited levels */
820 /* Sokoban levels are pre-mapped for the player, and should stay
821 * so, or they become nearly impossible to solve. But try to
822 * shift the forgetting elsewhere by fiddling with percent
823 * instead of forgetting fewer levels.
825 indices[0] = 0; /* lint suppression */
826 for (count = 0, i = 0; i <= maxl; i++)
827 if ((level_info[i].flags & VISITED)
828 && !(level_info[i].flags & FORGOTTEN) && i != this_lev) {
829 if (ledger_to_dnum(i) == sokoban_dnum)
830 percent += 2;
831 else
832 indices[count++] = i;
835 if (percent > 100)
836 percent = 100;
838 if (count > 0) {
839 randomize(indices, count);
841 /* forget first % of randomized indices */
842 count = ((count * percent) + 50) / 100;
843 for (i = 0; i < count; i++) {
844 level_info[indices[i]].flags |= FORGOTTEN;
845 forget_mapseen(indices[i]);
851 * Forget some things (e.g. after reading a scroll of amnesia). When called,
852 * the following are always forgotten:
853 * - felt ball & chain
854 * - traps
855 * - part (6 out of 7) of the map
857 * Other things are subject to flags:
858 * howmuch & ALL_MAP = forget whole map
859 * howmuch & ALL_SPELLS = forget all spells
861 STATIC_OVL void
862 forget(howmuch)
863 int howmuch;
865 if (Punished)
866 u.bc_felt = 0; /* forget felt ball&chain */
868 forget_map(howmuch);
869 forget_traps();
871 /* 1 in 3 chance of forgetting some levels */
872 if (!rn2(3))
873 forget_levels(rn2(25));
875 /* 1 in 3 chance of forgetting some objects */
876 if (!rn2(3))
877 forget_objects(rn2(25));
879 if (howmuch & ALL_SPELLS)
880 losespells();
882 * Make sure that what was seen is restored correctly. To do this,
883 * we need to go blind for an instant --- turn off the display,
884 * then restart it. All this work is needed to correctly handle
885 * walls which are stone on one side and wall on the other. Turning
886 * off the seen bits above will make the wall revert to stone, but
887 * there are cases where we don't want this to happen. The easiest
888 * thing to do is to run it through the vision system again, which
889 * is always correct.
891 docrt(); /* this correctly will reset vision */
894 /* monster is hit by scroll of taming's effect */
895 STATIC_OVL int
896 maybe_tame(mtmp, sobj)
897 struct monst *mtmp;
898 struct obj *sobj;
900 int was_tame = mtmp->mtame;
901 unsigned was_peaceful = mtmp->mpeaceful;
903 if (sobj->cursed) {
904 setmangry(mtmp);
905 if (was_peaceful && !mtmp->mpeaceful)
906 return -1;
907 } else {
908 if (mtmp->isshk)
909 make_happy_shk(mtmp, FALSE);
910 else if (!resist(mtmp, sobj->oclass, 0, NOTELL))
911 (void) tamedog(mtmp, (struct obj *) 0);
912 if ((!was_peaceful && mtmp->mpeaceful) || (!was_tame && mtmp->mtame))
913 return 1;
915 return 0;
918 boolean
919 is_valid_stinking_cloud_pos(x, y, showmsg)
920 int x, y;
921 boolean showmsg;
923 if (!cansee(x, y) || !ACCESSIBLE(levl[x][y].typ) || distu(x, y) >= 32) {
924 if (showmsg)
925 You("smell rotten eggs.");
926 return FALSE;
928 return TRUE;
931 void
932 display_stinking_cloud_positions(state)
933 int state;
935 if (state == 0) {
936 tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos));
937 } else if (state == 1) {
938 int x, y, dx, dy;
939 int dist = 6;
941 for (dx = -dist; dx <= dist; dx++)
942 for (dy = -dist; dy <= dist; dy++) {
943 x = u.ux + dx;
944 y = u.uy + dy;
945 if (isok(x, y) && is_valid_stinking_cloud_pos(x, y, FALSE))
946 tmp_at(x, y);
948 } else {
949 tmp_at(DISP_END, 0);
953 /* scroll effects; return 1 if we use up the scroll and possibly make it
954 become discovered, 0 if caller should take care of those side-effects */
956 seffects(sobj)
957 struct obj *sobj; /* scroll, or fake spellbook object for scroll-like spell */
959 int cval, otyp = sobj->otyp;
960 boolean confused = (Confusion != 0), sblessed = sobj->blessed,
961 scursed = sobj->cursed, already_known, old_erodeproof,
962 new_erodeproof;
963 struct obj *otmp;
965 if (objects[otyp].oc_magic)
966 exercise(A_WIS, TRUE); /* just for trying */
967 already_known = (sobj->oclass == SPBOOK_CLASS /* spell */
968 || objects[otyp].oc_name_known);
970 switch (otyp) {
971 #ifdef MAIL
972 case SCR_MAIL:
973 known = TRUE;
974 if (sobj->spe == 2)
975 /* "stamped scroll" created via magic marker--without a stamp */
976 pline("This scroll is marked \"postage due\".");
977 else if (sobj->spe)
978 /* scroll of mail obtained from bones file or from wishing;
979 * note to the puzzled: the game Larn actually sends you junk
980 * mail if you win!
982 pline(
983 "This seems to be junk mail addressed to the finder of the Eye of Larn.");
984 else
985 readmail(sobj);
986 break;
987 #endif
988 case SCR_ENCHANT_ARMOR: {
989 register schar s;
990 boolean special_armor;
991 boolean same_color;
993 otmp = some_armor(&youmonst);
994 if (!otmp) {
995 strange_feeling(sobj, !Blind
996 ? "Your skin glows then fades."
997 : "Your skin feels warm for a moment.");
998 sobj = 0; /* useup() in strange_feeling() */
999 exercise(A_CON, !scursed);
1000 exercise(A_STR, !scursed);
1001 break;
1003 if (confused) {
1004 old_erodeproof = (otmp->oerodeproof != 0);
1005 new_erodeproof = !scursed;
1006 otmp->oerodeproof = 0; /* for messages */
1007 if (Blind) {
1008 otmp->rknown = FALSE;
1009 pline("%s warm for a moment.", Yobjnam2(otmp, "feel"));
1010 } else {
1011 otmp->rknown = TRUE;
1012 pline("%s covered by a %s %s %s!", Yobjnam2(otmp, "are"),
1013 scursed ? "mottled" : "shimmering",
1014 hcolor(scursed ? NH_BLACK : NH_GOLDEN),
1015 scursed ? "glow"
1016 : (is_shield(otmp) ? "layer" : "shield"));
1018 if (new_erodeproof && (otmp->oeroded || otmp->oeroded2)) {
1019 otmp->oeroded = otmp->oeroded2 = 0;
1020 pline("%s as good as new!",
1021 Yobjnam2(otmp, Blind ? "feel" : "look"));
1023 if (old_erodeproof && !new_erodeproof) {
1024 /* restore old_erodeproof before shop charges */
1025 otmp->oerodeproof = 1;
1026 costly_alteration(otmp, COST_DEGRD);
1028 otmp->oerodeproof = new_erodeproof ? 1 : 0;
1029 break;
1031 /* elven armor vibrates warningly when enchanted beyond a limit */
1032 special_armor = is_elven_armor(otmp)
1033 || (Role_if(PM_WIZARD) && otmp->otyp == CORNUTHAUM);
1034 if (scursed)
1035 same_color = (otmp->otyp == BLACK_DRAGON_SCALE_MAIL
1036 || otmp->otyp == BLACK_DRAGON_SCALES);
1037 else
1038 same_color = (otmp->otyp == SILVER_DRAGON_SCALE_MAIL
1039 || otmp->otyp == SILVER_DRAGON_SCALES
1040 || otmp->otyp == SHIELD_OF_REFLECTION);
1041 if (Blind)
1042 same_color = FALSE;
1044 /* KMH -- catch underflow */
1045 s = scursed ? -otmp->spe : otmp->spe;
1046 if (s > (special_armor ? 5 : 3) && rn2(s)) {
1047 otmp->in_use = TRUE;
1048 pline("%s violently %s%s%s for a while, then %s.", Yname2(otmp),
1049 otense(otmp, Blind ? "vibrate" : "glow"),
1050 (!Blind && !same_color) ? " " : "",
1051 (Blind || same_color) ? "" : hcolor(scursed ? NH_BLACK
1052 : NH_SILVER),
1053 otense(otmp, "evaporate"));
1054 remove_worn_item(otmp, FALSE);
1055 useup(otmp);
1056 break;
1058 s = scursed ? -1
1059 : (otmp->spe >= 9)
1060 ? (rn2(otmp->spe) == 0)
1061 : sblessed
1062 ? rnd(3 - otmp->spe / 3)
1063 : 1;
1064 if (s >= 0 && Is_dragon_scales(otmp)) {
1065 /* dragon scales get turned into dragon scale mail */
1066 pline("%s merges and hardens!", Yname2(otmp));
1067 setworn((struct obj *) 0, W_ARM);
1068 /* assumes same order */
1069 otmp->otyp += GRAY_DRAGON_SCALE_MAIL - GRAY_DRAGON_SCALES;
1070 if (sblessed) {
1071 otmp->spe++;
1072 if (!otmp->blessed)
1073 bless(otmp);
1074 } else if (otmp->cursed)
1075 uncurse(otmp);
1076 otmp->known = 1;
1077 setworn(otmp, W_ARM);
1078 if (otmp->unpaid)
1079 alter_cost(otmp, 0L); /* shop bill */
1080 break;
1082 pline("%s %s%s%s%s for a %s.", Yname2(otmp),
1083 s == 0 ? "violently " : "",
1084 otense(otmp, Blind ? "vibrate" : "glow"),
1085 (!Blind && !same_color) ? " " : "",
1086 (Blind || same_color)
1087 ? "" : hcolor(scursed ? NH_BLACK : NH_SILVER),
1088 (s * s > 1) ? "while" : "moment");
1089 /* [this cost handling will need updating if shop pricing is
1090 ever changed to care about curse/bless status of armor] */
1091 if (s < 0)
1092 costly_alteration(otmp, COST_DECHNT);
1093 if (scursed && !otmp->cursed)
1094 curse(otmp);
1095 else if (sblessed && !otmp->blessed)
1096 bless(otmp);
1097 else if (!scursed && otmp->cursed)
1098 uncurse(otmp);
1099 if (s) {
1100 otmp->spe += s;
1101 adj_abon(otmp, s);
1102 known = otmp->known;
1103 /* update shop bill to reflect new higher price */
1104 if (s > 0 && otmp->unpaid)
1105 alter_cost(otmp, 0L);
1108 if ((otmp->spe > (special_armor ? 5 : 3))
1109 && (special_armor || !rn2(7)))
1110 pline("%s %s.", Yobjnam2(otmp, "suddenly vibrate"),
1111 Blind ? "again" : "unexpectedly");
1112 break;
1114 case SCR_DESTROY_ARMOR: {
1115 otmp = some_armor(&youmonst);
1116 if (confused) {
1117 if (!otmp) {
1118 strange_feeling(sobj, "Your bones itch.");
1119 sobj = 0; /* useup() in strange_feeling() */
1120 exercise(A_STR, FALSE);
1121 exercise(A_CON, FALSE);
1122 break;
1124 old_erodeproof = (otmp->oerodeproof != 0);
1125 new_erodeproof = scursed;
1126 otmp->oerodeproof = 0; /* for messages */
1127 p_glow2(otmp, NH_PURPLE);
1128 if (old_erodeproof && !new_erodeproof) {
1129 /* restore old_erodeproof before shop charges */
1130 otmp->oerodeproof = 1;
1131 costly_alteration(otmp, COST_DEGRD);
1133 otmp->oerodeproof = new_erodeproof ? 1 : 0;
1134 break;
1136 if (!scursed || !otmp || !otmp->cursed) {
1137 if (!destroy_arm(otmp)) {
1138 strange_feeling(sobj, "Your skin itches.");
1139 sobj = 0; /* useup() in strange_feeling() */
1140 exercise(A_STR, FALSE);
1141 exercise(A_CON, FALSE);
1142 break;
1143 } else
1144 known = TRUE;
1145 } else { /* armor and scroll both cursed */
1146 pline("%s.", Yobjnam2(otmp, "vibrate"));
1147 if (otmp->spe >= -6) {
1148 otmp->spe += -1;
1149 adj_abon(otmp, -1);
1151 make_stunned((HStun & TIMEOUT) + (long) rn1(10, 10), TRUE);
1153 } break;
1154 case SCR_CONFUSE_MONSTER:
1155 case SPE_CONFUSE_MONSTER:
1156 if (youmonst.data->mlet != S_HUMAN || scursed) {
1157 if (!HConfusion)
1158 You_feel("confused.");
1159 make_confused(HConfusion + rnd(100), FALSE);
1160 } else if (confused) {
1161 if (!sblessed) {
1162 Your("%s begin to %s%s.", makeplural(body_part(HAND)),
1163 Blind ? "tingle" : "glow ",
1164 Blind ? "" : hcolor(NH_PURPLE));
1165 make_confused(HConfusion + rnd(100), FALSE);
1166 } else {
1167 pline("A %s%s surrounds your %s.",
1168 Blind ? "" : hcolor(NH_RED),
1169 Blind ? "faint buzz" : " glow", body_part(HEAD));
1170 make_confused(0L, TRUE);
1172 } else {
1173 if (!sblessed) {
1174 Your("%s%s %s%s.", makeplural(body_part(HAND)),
1175 Blind ? "" : " begin to glow",
1176 Blind ? (const char *) "tingle" : hcolor(NH_RED),
1177 u.umconf ? " even more" : "");
1178 u.umconf++;
1179 } else {
1180 if (Blind)
1181 Your("%s tingle %s sharply.", makeplural(body_part(HAND)),
1182 u.umconf ? "even more" : "very");
1183 else
1184 Your("%s glow a%s brilliant %s.",
1185 makeplural(body_part(HAND)),
1186 u.umconf ? "n even more" : "", hcolor(NH_RED));
1187 /* after a while, repeated uses become less effective */
1188 if (u.umconf >= 40)
1189 u.umconf++;
1190 else
1191 u.umconf += rn1(8, 2);
1194 break;
1195 case SCR_SCARE_MONSTER:
1196 case SPE_CAUSE_FEAR: {
1197 register int ct = 0;
1198 register struct monst *mtmp;
1200 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1201 if (DEADMONSTER(mtmp))
1202 continue;
1203 if (cansee(mtmp->mx, mtmp->my)) {
1204 if (confused || scursed) {
1205 mtmp->mflee = mtmp->mfrozen = mtmp->msleeping = 0;
1206 mtmp->mcanmove = 1;
1207 } else if (!resist(mtmp, sobj->oclass, 0, NOTELL))
1208 monflee(mtmp, 0, FALSE, FALSE);
1209 if (!mtmp->mtame)
1210 ct++; /* pets don't laugh at you */
1213 if (otyp == SCR_SCARE_MONSTER || !ct)
1214 You_hear("%s %s.", (confused || scursed) ? "sad wailing"
1215 : "maniacal laughter",
1216 !ct ? "in the distance" : "close by");
1217 break;
1219 case SCR_BLANK_PAPER:
1220 if (Blind)
1221 You("don't remember there being any magic words on this scroll.");
1222 else
1223 pline("This scroll seems to be blank.");
1224 known = TRUE;
1225 break;
1226 case SCR_REMOVE_CURSE:
1227 case SPE_REMOVE_CURSE: {
1228 register struct obj *obj;
1230 You_feel(!Hallucination
1231 ? (!confused ? "like someone is helping you."
1232 : "like you need some help.")
1233 : (!confused ? "in touch with the Universal Oneness."
1234 : "the power of the Force against you!"));
1236 if (scursed) {
1237 pline_The("scroll disintegrates.");
1238 } else {
1239 for (obj = invent; obj; obj = obj->nobj) {
1240 long wornmask;
1242 /* gold isn't subject to cursing and blessing */
1243 if (obj->oclass == COIN_CLASS)
1244 continue;
1245 wornmask = (obj->owornmask & ~(W_BALL | W_ART | W_ARTI));
1246 if (wornmask && !sblessed) {
1247 /* handle a couple of special cases; we don't
1248 allow auxiliary weapon slots to be used to
1249 artificially increase number of worn items */
1250 if (obj == uswapwep) {
1251 if (!u.twoweap)
1252 wornmask = 0L;
1253 } else if (obj == uquiver) {
1254 if (obj->oclass == WEAPON_CLASS) {
1255 /* mergeable weapon test covers ammo,
1256 missiles, spears, daggers & knives */
1257 if (!objects[obj->otyp].oc_merge)
1258 wornmask = 0L;
1259 } else if (obj->oclass == GEM_CLASS) {
1260 /* possibly ought to check whether
1261 alternate weapon is a sling... */
1262 if (!uslinging())
1263 wornmask = 0L;
1264 } else {
1265 /* weptools don't merge and aren't
1266 reasonable quivered weapons */
1267 wornmask = 0L;
1271 if (sblessed || wornmask || obj->otyp == LOADSTONE
1272 || (obj->otyp == LEASH && obj->leashmon)) {
1273 /* water price varies by curse/bless status */
1274 boolean shop_h2o = (obj->unpaid && obj->otyp == POT_WATER);
1276 if (confused) {
1277 blessorcurse(obj, 2);
1278 /* lose knowledge of this object's curse/bless
1279 state (even if it didn't actually change) */
1280 obj->bknown = 0;
1281 /* blessorcurse() only affects uncursed items
1282 so no need to worry about price of water
1283 going down (hence no costly_alteration) */
1284 if (shop_h2o && (obj->cursed || obj->blessed))
1285 alter_cost(obj, 0L); /* price goes up */
1286 } else if (obj->cursed) {
1287 if (shop_h2o)
1288 costly_alteration(obj, COST_UNCURS);
1289 uncurse(obj);
1294 if (Punished && !confused)
1295 unpunish();
1296 if (u.utrap && u.utraptype == TT_BURIEDBALL) {
1297 buried_ball_to_freedom();
1298 pline_The("clasp on your %s vanishes.", body_part(LEG));
1300 update_inventory();
1301 break;
1303 case SCR_CREATE_MONSTER:
1304 case SPE_CREATE_MONSTER:
1305 if (create_critters(1 + ((confused || scursed) ? 12 : 0)
1306 + ((sblessed || rn2(73)) ? 0 : rnd(4)),
1307 confused ? &mons[PM_ACID_BLOB]
1308 : (struct permonst *) 0,
1309 FALSE))
1310 known = TRUE;
1311 /* no need to flush monsters; we ask for identification only if the
1312 * monsters are not visible
1314 break;
1315 case SCR_ENCHANT_WEAPON:
1316 /* [What about twoweapon mode? Proofing/repairing/enchanting both
1317 would be too powerful, but shouldn't we choose randomly between
1318 primary and secondary instead of always acting on primary?] */
1319 if (confused && uwep
1320 && erosion_matters(uwep) && uwep->oclass != ARMOR_CLASS) {
1321 old_erodeproof = (uwep->oerodeproof != 0);
1322 new_erodeproof = !scursed;
1323 uwep->oerodeproof = 0; /* for messages */
1324 if (Blind) {
1325 uwep->rknown = FALSE;
1326 Your("weapon feels warm for a moment.");
1327 } else {
1328 uwep->rknown = TRUE;
1329 pline("%s covered by a %s %s %s!", Yobjnam2(uwep, "are"),
1330 scursed ? "mottled" : "shimmering",
1331 hcolor(scursed ? NH_PURPLE : NH_GOLDEN),
1332 scursed ? "glow" : "shield");
1334 if (new_erodeproof && (uwep->oeroded || uwep->oeroded2)) {
1335 uwep->oeroded = uwep->oeroded2 = 0;
1336 pline("%s as good as new!",
1337 Yobjnam2(uwep, Blind ? "feel" : "look"));
1339 if (old_erodeproof && !new_erodeproof) {
1340 /* restore old_erodeproof before shop charges */
1341 uwep->oerodeproof = 1;
1342 costly_alteration(uwep, COST_DEGRD);
1344 uwep->oerodeproof = new_erodeproof ? 1 : 0;
1345 break;
1347 if (!chwepon(sobj, scursed ? -1
1348 : !uwep ? 1
1349 : (uwep->spe >= 9) ? !rn2(uwep->spe)
1350 : sblessed ? rnd(3 - uwep->spe / 3)
1351 : 1))
1352 sobj = 0; /* nothing enchanted: strange_feeling -> useup */
1353 break;
1354 case SCR_TAMING:
1355 case SPE_CHARM_MONSTER: {
1356 int candidates, res, results, vis_results;
1358 if (u.uswallow) {
1359 candidates = 1;
1360 results = vis_results = maybe_tame(u.ustuck, sobj);
1361 } else {
1362 int i, j, bd = confused ? 5 : 1;
1363 struct monst *mtmp;
1365 /* note: maybe_tame() can return either positive or
1366 negative values, but not both for the same scroll */
1367 candidates = results = vis_results = 0;
1368 for (i = -bd; i <= bd; i++)
1369 for (j = -bd; j <= bd; j++) {
1370 if (!isok(u.ux + i, u.uy + j))
1371 continue;
1372 if ((mtmp = m_at(u.ux + i, u.uy + j)) != 0
1373 || (!i && !j && (mtmp = u.usteed) != 0)) {
1374 ++candidates;
1375 res = maybe_tame(mtmp, sobj);
1376 results += res;
1377 if (canspotmon(mtmp))
1378 vis_results += res;
1382 if (!results) {
1383 pline("Nothing interesting %s.",
1384 !candidates ? "happens" : "seems to happen");
1385 } else {
1386 pline_The("neighborhood %s %sfriendlier.",
1387 vis_results ? "is" : "seems",
1388 (results < 0) ? "un" : "");
1389 if (vis_results > 0)
1390 known = TRUE;
1392 break;
1394 case SCR_GENOCIDE:
1395 if (!already_known)
1396 You("have found a scroll of genocide!");
1397 known = TRUE;
1398 if (sblessed)
1399 do_class_genocide();
1400 else
1401 do_genocide(!scursed | (2 * !!Confusion));
1402 break;
1403 case SCR_LIGHT:
1404 if (!confused || rn2(5)) {
1405 if (!Blind)
1406 known = TRUE;
1407 litroom(!confused && !scursed, sobj);
1408 if (!confused && !scursed) {
1409 if (lightdamage(sobj, TRUE, 5))
1410 known = TRUE;
1412 } else {
1413 /* could be scroll of create monster, don't set known ...*/
1414 (void) create_critters(1, !scursed ? &mons[PM_YELLOW_LIGHT]
1415 : &mons[PM_BLACK_LIGHT],
1416 TRUE);
1417 if (!objects[sobj->otyp].oc_uname)
1418 docall(sobj);
1420 break;
1421 case SCR_TELEPORTATION:
1422 if (confused || scursed) {
1423 level_tele();
1424 } else {
1425 known = scrolltele(sobj);
1427 break;
1428 case SCR_GOLD_DETECTION:
1429 if ((confused || scursed) ? trap_detect(sobj) : gold_detect(sobj))
1430 sobj = 0; /* failure: strange_feeling() -> useup() */
1431 break;
1432 case SCR_FOOD_DETECTION:
1433 case SPE_DETECT_FOOD:
1434 if (food_detect(sobj))
1435 sobj = 0; /* nothing detected: strange_feeling -> useup */
1436 break;
1437 case SCR_IDENTIFY:
1438 /* known = TRUE; -- handled inline here */
1439 /* use up the scroll first, before makeknown() performs a
1440 perm_invent update; also simplifies empty invent check */
1441 useup(sobj);
1442 sobj = 0; /* it's gone */
1443 if (confused)
1444 You("identify this as an identify scroll.");
1445 else if (!already_known || !invent)
1446 /* force feedback now if invent became
1447 empty after using up this scroll */
1448 pline("This is an identify scroll.");
1449 if (!already_known)
1450 (void) learnscrolltyp(SCR_IDENTIFY);
1451 /*FALLTHRU*/
1452 case SPE_IDENTIFY:
1453 cval = 1;
1454 if (sblessed || (!scursed && !rn2(5))) {
1455 cval = rn2(5);
1456 /* note: if cval==0, identify all items */
1457 if (cval == 1 && sblessed && Luck > 0)
1458 ++cval;
1460 if (invent && !confused) {
1461 identify_pack(cval, !already_known);
1462 } else if (otyp == SPE_IDENTIFY) {
1463 /* when casting a spell we know we're not confused,
1464 so inventory must be empty (another message has
1465 already been given above if reading a scroll) */
1466 pline("You're not carrying anything to be identified.");
1468 break;
1469 case SCR_CHARGING:
1470 if (confused) {
1471 if (scursed) {
1472 You_feel("discharged.");
1473 u.uen = 0;
1474 } else {
1475 You_feel("charged up!");
1476 u.uen += d(sblessed ? 6 : 4, 4);
1477 if (u.uen > u.uenmax) /* if current energy is already at */
1478 u.uenmax = u.uen; /* or near maximum, increase maximum */
1479 else
1480 u.uen = u.uenmax; /* otherwise restore current to max */
1482 context.botl = 1;
1483 break;
1485 /* known = TRUE; -- handled inline here */
1486 if (!already_known) {
1487 pline("This is a charging scroll.");
1488 learnscroll(sobj);
1490 /* use it up now to prevent it from showing in the
1491 getobj picklist because the "disappears" message
1492 was already delivered */
1493 useup(sobj);
1494 sobj = 0; /* it's gone */
1495 otmp = getobj(all_count, "charge");
1496 if (otmp)
1497 recharge(otmp, scursed ? -1 : sblessed ? 1 : 0);
1498 break;
1499 case SCR_MAGIC_MAPPING:
1500 if (level.flags.nommap) {
1501 Your("mind is filled with crazy lines!");
1502 if (Hallucination)
1503 pline("Wow! Modern art.");
1504 else
1505 Your("%s spins in bewilderment.", body_part(HEAD));
1506 make_confused(HConfusion + rnd(30), FALSE);
1507 break;
1509 if (sblessed) {
1510 register int x, y;
1512 for (x = 1; x < COLNO; x++)
1513 for (y = 0; y < ROWNO; y++)
1514 if (levl[x][y].typ == SDOOR)
1515 cvt_sdoor_to_door(&levl[x][y]);
1516 /* do_mapping() already reveals secret passages */
1518 known = TRUE;
1519 case SPE_MAGIC_MAPPING:
1520 if (level.flags.nommap) {
1521 Your("%s spins as %s blocks the spell!", body_part(HEAD),
1522 something);
1523 make_confused(HConfusion + rnd(30), FALSE);
1524 break;
1526 pline("A map coalesces in your mind!");
1527 cval = (scursed && !confused);
1528 if (cval)
1529 HConfusion = 1; /* to screw up map */
1530 do_mapping();
1531 if (cval) {
1532 HConfusion = 0; /* restore */
1533 pline("Unfortunately, you can't grasp the details.");
1535 break;
1536 case SCR_AMNESIA:
1537 known = TRUE;
1538 forget((!sblessed ? ALL_SPELLS : 0)
1539 | (!confused || scursed ? ALL_MAP : 0));
1540 if (Hallucination) /* Ommmmmm! */
1541 Your("mind releases itself from mundane concerns.");
1542 else if (!strncmpi(plname, "Maud", 4))
1543 pline(
1544 "As your mind turns inward on itself, you forget everything else.");
1545 else if (rn2(2))
1546 pline("Who was that Maud person anyway?");
1547 else
1548 pline("Thinking of Maud you forget everything else.");
1549 exercise(A_WIS, FALSE);
1550 break;
1551 case SCR_FIRE:
1552 cval = bcsign(sobj);
1553 useup(sobj);
1554 sobj = 0; /* it's gone */
1555 if (!already_known)
1556 (void) learnscrolltyp(SCR_FIRE);
1557 if (confused) {
1558 if (Fire_resistance) {
1559 shieldeff(u.ux, u.uy);
1560 if (!Blind)
1561 pline("Oh, look, what a pretty fire in your %s.",
1562 makeplural(body_part(HAND)));
1563 else
1564 You_feel("a pleasant warmth in your %s.",
1565 makeplural(body_part(HAND)));
1566 } else {
1567 pline_The("scroll catches fire and you burn your %s.",
1568 makeplural(body_part(HAND)));
1569 losehp(1, "scroll of fire", KILLED_BY_AN);
1571 break;
1573 if (Underwater) {
1574 pline_The("%s around you vaporizes violently!", hliquid("water"));
1575 } else {
1576 pline_The("scroll erupts in a tower of flame!");
1577 iflags.last_msg = PLNMSG_TOWER_OF_FLAME; /* for explode() */
1578 burn_away_slime();
1580 explode(u.ux, u.uy, 11, (2 * (rn1(3, 3) + 2 * cval) + 1) / 3,
1581 SCROLL_CLASS, EXPL_FIERY);
1582 break;
1583 case SCR_EARTH:
1584 /* TODO: handle steeds */
1585 if (!Is_rogue_level(&u.uz) && has_ceiling(&u.uz)
1586 && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
1587 register int x, y;
1588 int nboulders = 0;
1590 /* Identify the scroll */
1591 if (u.uswallow)
1592 You_hear("rumbling.");
1593 else
1594 pline_The("%s rumbles %s you!", ceiling(u.ux, u.uy),
1595 sblessed ? "around" : "above");
1596 known = 1;
1597 sokoban_guilt();
1599 /* Loop through the surrounding squares */
1600 if (!scursed)
1601 for (x = u.ux - 1; x <= u.ux + 1; x++) {
1602 for (y = u.uy - 1; y <= u.uy + 1; y++) {
1603 /* Is this a suitable spot? */
1604 if (isok(x, y) && !closed_door(x, y)
1605 && !IS_ROCK(levl[x][y].typ)
1606 && !IS_AIR(levl[x][y].typ)
1607 && (x != u.ux || y != u.uy)) {
1608 nboulders +=
1609 drop_boulder_on_monster(x, y, confused, TRUE);
1613 /* Attack the player */
1614 if (!sblessed) {
1615 drop_boulder_on_player(confused, !scursed, TRUE, FALSE);
1616 } else if (!nboulders)
1617 pline("But nothing else happens.");
1619 break;
1620 case SCR_PUNISHMENT:
1621 known = TRUE;
1622 if (confused || sblessed) {
1623 You_feel("guilty.");
1624 break;
1626 punish(sobj);
1627 break;
1628 case SCR_STINKING_CLOUD: {
1629 coord cc;
1631 if (!already_known)
1632 You("have found a scroll of stinking cloud!");
1633 known = TRUE;
1634 pline("Where do you want to center the %scloud?",
1635 already_known ? "stinking " : "");
1636 cc.x = u.ux;
1637 cc.y = u.uy;
1638 getpos_sethilite(display_stinking_cloud_positions);
1639 if (getpos(&cc, TRUE, "the desired position") < 0) {
1640 pline1(Never_mind);
1641 break;
1643 if (!is_valid_stinking_cloud_pos(cc.x, cc.y, TRUE))
1644 break;
1645 (void) create_gas_cloud(cc.x, cc.y, 3 + bcsign(sobj),
1646 8 + 4 * bcsign(sobj));
1647 break;
1649 default:
1650 impossible("What weird effect is this? (%u)", otyp);
1652 return sobj ? 0 : 1;
1655 void
1656 drop_boulder_on_player(confused, helmet_protects, byu, skip_uswallow)
1657 boolean confused, helmet_protects, byu, skip_uswallow;
1659 int dmg;
1660 struct obj *otmp2;
1662 /* hit monster if swallowed */
1663 if (u.uswallow && !skip_uswallow) {
1664 drop_boulder_on_monster(u.ux, u.uy, confused, byu);
1665 return;
1668 otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
1669 if (!otmp2)
1670 return;
1671 otmp2->quan = confused ? rn1(5, 2) : 1;
1672 otmp2->owt = weight(otmp2);
1673 if (!amorphous(youmonst.data) && !Passes_walls
1674 && !noncorporeal(youmonst.data) && !unsolid(youmonst.data)) {
1675 You("are hit by %s!", doname(otmp2));
1676 dmg = dmgval(otmp2, &youmonst) * otmp2->quan;
1677 if (uarmh && helmet_protects) {
1678 if (is_metallic(uarmh)) {
1679 pline("Fortunately, you are wearing a hard helmet.");
1680 if (dmg > 2)
1681 dmg = 2;
1682 } else if (flags.verbose) {
1683 pline("%s does not protect you.", Yname2(uarmh));
1686 } else
1687 dmg = 0;
1688 /* Must be before the losehp(), for bones files */
1689 if (!flooreffects(otmp2, u.ux, u.uy, "fall")) {
1690 place_object(otmp2, u.ux, u.uy);
1691 stackobj(otmp2);
1692 newsym(u.ux, u.uy);
1694 if (dmg)
1695 losehp(Maybe_Half_Phys(dmg), "scroll of earth", KILLED_BY_AN);
1698 boolean
1699 drop_boulder_on_monster(x, y, confused, byu)
1700 int x, y;
1701 boolean confused, byu;
1703 register struct obj *otmp2;
1704 register struct monst *mtmp;
1706 /* Make the object(s) */
1707 otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
1708 if (!otmp2)
1709 return FALSE; /* Shouldn't happen */
1710 otmp2->quan = confused ? rn1(5, 2) : 1;
1711 otmp2->owt = weight(otmp2);
1713 /* Find the monster here (won't be player) */
1714 mtmp = m_at(x, y);
1715 if (mtmp && !amorphous(mtmp->data) && !passes_walls(mtmp->data)
1716 && !noncorporeal(mtmp->data) && !unsolid(mtmp->data)) {
1717 struct obj *helmet = which_armor(mtmp, W_ARMH);
1718 int mdmg;
1720 if (cansee(mtmp->mx, mtmp->my)) {
1721 pline("%s is hit by %s!", Monnam(mtmp), doname(otmp2));
1722 if (mtmp->minvis && !canspotmon(mtmp))
1723 map_invisible(mtmp->mx, mtmp->my);
1724 } else if (u.uswallow && mtmp == u.ustuck)
1725 You_hear("something hit %s %s over your %s!",
1726 s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH),
1727 body_part(HEAD));
1729 mdmg = dmgval(otmp2, mtmp) * otmp2->quan;
1730 if (helmet) {
1731 if (is_metallic(helmet)) {
1732 if (canspotmon(mtmp))
1733 pline("Fortunately, %s is wearing a hard helmet.",
1734 mon_nam(mtmp));
1735 else if (!Deaf)
1736 You_hear("a clanging sound.");
1737 if (mdmg > 2)
1738 mdmg = 2;
1739 } else {
1740 if (canspotmon(mtmp))
1741 pline("%s's %s does not protect %s.", Monnam(mtmp),
1742 xname(helmet), mhim(mtmp));
1745 mtmp->mhp -= mdmg;
1746 if (mtmp->mhp <= 0) {
1747 if (byu) {
1748 killed(mtmp);
1749 } else {
1750 pline("%s is killed.", Monnam(mtmp));
1751 mondied(mtmp);
1754 } else if (u.uswallow && mtmp == u.ustuck) {
1755 obfree(otmp2, (struct obj *) 0);
1756 /* fall through to player */
1757 drop_boulder_on_player(confused, TRUE, FALSE, TRUE);
1758 return 1;
1760 /* Drop the rock/boulder to the floor */
1761 if (!flooreffects(otmp2, x, y, "fall")) {
1762 place_object(otmp2, x, y);
1763 stackobj(otmp2);
1764 newsym(x, y); /* map the rock */
1766 return TRUE;
1769 /* overcharging any wand or zapping/engraving cursed wand */
1770 void
1771 wand_explode(obj, chg)
1772 struct obj *obj;
1773 int chg; /* recharging */
1775 const char *expl = !chg ? "suddenly" : "vibrates violently and";
1776 int dmg, n, k;
1778 /* number of damage dice */
1779 if (!chg)
1780 chg = 2; /* zap/engrave adjustment */
1781 n = obj->spe + chg;
1782 if (n < 2)
1783 n = 2; /* arbitrary minimum */
1784 /* size of damage dice */
1785 switch (obj->otyp) {
1786 case WAN_WISHING:
1787 k = 12;
1788 break;
1789 case WAN_CANCELLATION:
1790 case WAN_DEATH:
1791 case WAN_POLYMORPH:
1792 case WAN_UNDEAD_TURNING:
1793 k = 10;
1794 break;
1795 case WAN_COLD:
1796 case WAN_FIRE:
1797 case WAN_LIGHTNING:
1798 case WAN_MAGIC_MISSILE:
1799 k = 8;
1800 break;
1801 case WAN_NOTHING:
1802 k = 4;
1803 break;
1804 default:
1805 k = 6;
1806 break;
1808 /* inflict damage and destroy the wand */
1809 dmg = d(n, k);
1810 obj->in_use = TRUE; /* in case losehp() is fatal (or --More--^C) */
1811 pline("%s %s explodes!", Yname2(obj), expl);
1812 losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN);
1813 useup(obj);
1814 /* obscure side-effect */
1815 exercise(A_STR, FALSE);
1818 /* used to collect gremlins being hit by light so that they can be processed
1819 after vision for the entire lit area has been brought up to date */
1820 struct litmon {
1821 struct monst *mon;
1822 struct litmon *nxt;
1824 STATIC_VAR struct litmon *gremlins = 0;
1827 * Low-level lit-field update routine.
1829 STATIC_PTR void
1830 set_lit(x, y, val)
1831 int x, y;
1832 genericptr_t val;
1834 struct monst *mtmp;
1835 struct litmon *gremlin;
1837 if (val) {
1838 levl[x][y].lit = 1;
1839 if ((mtmp = m_at(x, y)) != 0 && mtmp->data == &mons[PM_GREMLIN]) {
1840 gremlin = (struct litmon *) alloc(sizeof *gremlin);
1841 gremlin->mon = mtmp;
1842 gremlin->nxt = gremlins;
1843 gremlins = gremlin;
1845 } else {
1846 levl[x][y].lit = 0;
1847 snuff_light_source(x, y);
1851 void
1852 litroom(on, obj)
1853 register boolean on;
1854 struct obj *obj;
1856 char is_lit; /* value is irrelevant; we use its address
1857 as a `not null' flag for set_lit() */
1859 /* first produce the text (provided you're not blind) */
1860 if (!on) {
1861 register struct obj *otmp;
1863 if (!Blind) {
1864 if (u.uswallow) {
1865 pline("It seems even darker in here than before.");
1866 } else {
1867 if (uwep && artifact_light(uwep) && uwep->lamplit)
1868 pline("Suddenly, the only light left comes from %s!",
1869 the(xname(uwep)));
1870 else
1871 You("are surrounded by darkness!");
1875 /* the magic douses lamps, et al, too */
1876 for (otmp = invent; otmp; otmp = otmp->nobj)
1877 if (otmp->lamplit)
1878 (void) snuff_lit(otmp);
1879 } else { /* on */
1880 if (u.uswallow) {
1881 if (Blind)
1882 ; /* no feedback */
1883 else if (is_animal(u.ustuck->data))
1884 pline("%s %s is lit.", s_suffix(Monnam(u.ustuck)),
1885 mbodypart(u.ustuck, STOMACH));
1886 else if (is_whirly(u.ustuck->data))
1887 pline("%s shines briefly.", Monnam(u.ustuck));
1888 else
1889 pline("%s glistens.", Monnam(u.ustuck));
1890 } else if (!Blind)
1891 pline("A lit field surrounds you!");
1894 /* No-op when swallowed or in water */
1895 if (u.uswallow || Underwater || Is_waterlevel(&u.uz))
1896 return;
1898 * If we are darkening the room and the hero is punished but not
1899 * blind, then we have to pick up and replace the ball and chain so
1900 * that we don't remember them if they are out of sight.
1902 if (Punished && !on && !Blind)
1903 move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
1905 if (Is_rogue_level(&u.uz)) {
1906 /* Can't use do_clear_area because MAX_RADIUS is too small */
1907 /* rogue lighting must light the entire room */
1908 int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET;
1909 int rx, ry;
1911 if (rnum >= 0) {
1912 for (rx = rooms[rnum].lx - 1; rx <= rooms[rnum].hx + 1; rx++)
1913 for (ry = rooms[rnum].ly - 1; ry <= rooms[rnum].hy + 1; ry++)
1914 set_lit(rx, ry,
1915 (genericptr_t) (on ? &is_lit : (char *) 0));
1916 rooms[rnum].rlit = on;
1918 /* hallways remain dark on the rogue level */
1919 } else
1920 do_clear_area(u.ux, u.uy,
1921 (obj && obj->oclass == SCROLL_CLASS && obj->blessed)
1922 ? 9 : 5,
1923 set_lit, (genericptr_t) (on ? &is_lit : (char *) 0));
1926 * If we are not blind, then force a redraw on all positions in sight
1927 * by temporarily blinding the hero. The vision recalculation will
1928 * correctly update all previously seen positions *and* correctly
1929 * set the waslit bit [could be messed up from above].
1931 if (!Blind) {
1932 vision_recalc(2);
1934 /* replace ball&chain */
1935 if (Punished && !on)
1936 move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
1939 vision_full_recalc = 1; /* delayed vision recalculation */
1940 if (gremlins) {
1941 struct litmon *gremlin;
1943 /* can't delay vision recalc after all */
1944 vision_recalc(0);
1945 /* after vision has been updated, monsters who are affected
1946 when hit by light can now be hit by it */
1947 do {
1948 gremlin = gremlins;
1949 gremlins = gremlin->nxt;
1950 light_hits_gremlin(gremlin->mon, rnd(5));
1951 free((genericptr_t) gremlin);
1952 } while (gremlins);
1956 STATIC_OVL void
1957 do_class_genocide()
1959 int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0;
1960 char buf[BUFSZ];
1961 boolean gameover = FALSE; /* true iff killed self */
1963 for (j = 0;; j++) {
1964 if (j >= 5) {
1965 pline1(thats_enough_tries);
1966 return;
1968 do {
1969 getlin("What class of monsters do you wish to genocide?", buf);
1970 (void) mungspaces(buf);
1971 } while (!*buf);
1972 /* choosing "none" preserves genocideless conduct */
1973 if (*buf == '\033' || !strcmpi(buf, "none")
1974 || !strcmpi(buf, "nothing"))
1975 return;
1977 class = name_to_monclass(buf, (int *) 0);
1978 if (class == 0 && (i = name_to_mon(buf)) != NON_PM)
1979 class = mons[i].mlet;
1980 immunecnt = gonecnt = goodcnt = 0;
1981 for (i = LOW_PM; i < NUMMONS; i++) {
1982 if (mons[i].mlet == class) {
1983 if (!(mons[i].geno & G_GENO))
1984 immunecnt++;
1985 else if (mvitals[i].mvflags & G_GENOD)
1986 gonecnt++;
1987 else
1988 goodcnt++;
1991 if (!goodcnt && class != mons[urole.malenum].mlet
1992 && class != mons[urace.malenum].mlet) {
1993 if (gonecnt)
1994 pline("All such monsters are already nonexistent.");
1995 else if (immunecnt || class == S_invisible)
1996 You("aren't permitted to genocide such monsters.");
1997 else if (wizard && buf[0] == '*') {
1998 register struct monst *mtmp, *mtmp2;
2000 gonecnt = 0;
2001 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
2002 mtmp2 = mtmp->nmon;
2003 if (DEADMONSTER(mtmp))
2004 continue;
2005 mongone(mtmp);
2006 gonecnt++;
2008 pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt));
2009 return;
2010 } else
2011 pline("That %s does not represent any monster.",
2012 strlen(buf) == 1 ? "symbol" : "response");
2013 continue;
2016 for (i = LOW_PM; i < NUMMONS; i++) {
2017 if (mons[i].mlet == class) {
2018 char nam[BUFSZ];
2020 Strcpy(nam, makeplural(mons[i].mname));
2021 /* Although "genus" is Latin for race, the hero benefits
2022 * from both race and role; thus genocide affects either.
2024 if (Your_Own_Role(i) || Your_Own_Race(i)
2025 || ((mons[i].geno & G_GENO)
2026 && !(mvitals[i].mvflags & G_GENOD))) {
2027 /* This check must be first since player monsters might
2028 * have G_GENOD or !G_GENO.
2030 mvitals[i].mvflags |= (G_GENOD | G_NOCORPSE);
2031 reset_rndmonst(i);
2032 kill_genocided_monsters();
2033 update_inventory(); /* eggs & tins */
2034 pline("Wiped out all %s.", nam);
2035 if (Upolyd && i == u.umonnum) {
2036 u.mh = -1;
2037 if (Unchanging) {
2038 if (!feel_dead++)
2039 You("die.");
2040 /* finish genociding this class of
2041 monsters before ultimately dying */
2042 gameover = TRUE;
2043 } else
2044 rehumanize();
2046 /* Self-genocide if it matches either your race
2047 or role. Assumption: male and female forms
2048 share same monster class. */
2049 if (i == urole.malenum || i == urace.malenum) {
2050 u.uhp = -1;
2051 if (Upolyd) {
2052 if (!feel_dead++)
2053 You_feel("dead inside.");
2054 } else {
2055 if (!feel_dead++)
2056 You("die.");
2057 gameover = TRUE;
2060 } else if (mvitals[i].mvflags & G_GENOD) {
2061 if (!gameover)
2062 pline("All %s are already nonexistent.", nam);
2063 } else if (!gameover) {
2064 /* suppress feedback about quest beings except
2065 for those applicable to our own role */
2066 if ((mons[i].msound != MS_LEADER
2067 || quest_info(MS_LEADER) == i)
2068 && (mons[i].msound != MS_NEMESIS
2069 || quest_info(MS_NEMESIS) == i)
2070 && (mons[i].msound != MS_GUARDIAN
2071 || quest_info(MS_GUARDIAN) == i)
2072 /* non-leader/nemesis/guardian role-specific monster
2074 && (i != PM_NINJA /* nuisance */
2075 || Role_if(PM_SAMURAI))) {
2076 boolean named, uniq;
2078 named = type_is_pname(&mons[i]) ? TRUE : FALSE;
2079 uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE;
2080 /* one special case */
2081 if (i == PM_HIGH_PRIEST)
2082 uniq = FALSE;
2084 You("aren't permitted to genocide %s%s.",
2085 (uniq && !named) ? "the " : "",
2086 (uniq || named) ? mons[i].mname : nam);
2091 if (gameover || u.uhp == -1) {
2092 killer.format = KILLED_BY_AN;
2093 Strcpy(killer.name, "scroll of genocide");
2094 if (gameover)
2095 done(GENOCIDED);
2097 return;
2101 #define REALLY 1
2102 #define PLAYER 2
2103 #define ONTHRONE 4
2104 void
2105 do_genocide(how)
2106 int how;
2107 /* 0 = no genocide; create monsters (cursed scroll) */
2108 /* 1 = normal genocide */
2109 /* 3 = forced genocide of player */
2110 /* 5 (4 | 1) = normal genocide from throne */
2112 char buf[BUFSZ];
2113 register int i, killplayer = 0;
2114 register int mndx;
2115 register struct permonst *ptr;
2116 const char *which;
2118 if (how & PLAYER) {
2119 mndx = u.umonster; /* non-polymorphed mon num */
2120 ptr = &mons[mndx];
2121 Strcpy(buf, ptr->mname);
2122 killplayer++;
2123 } else {
2124 for (i = 0;; i++) {
2125 if (i >= 5) {
2126 /* cursed effect => no free pass (unless rndmonst() fails) */
2127 if (!(how & REALLY) && (ptr = rndmonst()) != 0)
2128 break;
2130 pline1(thats_enough_tries);
2131 return;
2133 getlin("What monster do you want to genocide? [type the name]",
2134 buf);
2135 (void) mungspaces(buf);
2136 /* choosing "none" preserves genocideless conduct */
2137 if (*buf == '\033' || !strcmpi(buf, "none")
2138 || !strcmpi(buf, "nothing")) {
2139 /* ... but no free pass if cursed */
2140 if (!(how & REALLY) && (ptr = rndmonst()) != 0)
2141 break; /* remaining checks don't apply */
2143 return;
2146 mndx = name_to_mon(buf);
2147 if (mndx == NON_PM || (mvitals[mndx].mvflags & G_GENOD)) {
2148 pline("Such creatures %s exist in this world.",
2149 (mndx == NON_PM) ? "do not" : "no longer");
2150 continue;
2152 ptr = &mons[mndx];
2153 /* Although "genus" is Latin for race, the hero benefits
2154 * from both race and role; thus genocide affects either.
2156 if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) {
2157 killplayer++;
2158 break;
2160 if (is_human(ptr))
2161 adjalign(-sgn(u.ualign.type));
2162 if (is_demon(ptr))
2163 adjalign(sgn(u.ualign.type));
2165 if (!(ptr->geno & G_GENO)) {
2166 if (!Deaf) {
2167 /* FIXME: unconditional "caverns" will be silly in some
2168 * circumstances. Who's speaking? Divine pronouncements
2169 * aren't supposed to be hampered by deafness....
2171 if (flags.verbose)
2172 pline("A thunderous voice booms through the caverns:");
2173 verbalize("No, mortal! That will not be done.");
2175 continue;
2177 /* KMH -- Unchanging prevents rehumanization */
2178 if (Unchanging && ptr == youmonst.data)
2179 killplayer++;
2180 break;
2182 mndx = monsndx(ptr); /* needed for the 'no free pass' cases */
2185 which = "all ";
2186 if (Hallucination) {
2187 if (Upolyd)
2188 Strcpy(buf, youmonst.data->mname);
2189 else {
2190 Strcpy(buf, (flags.female && urole.name.f) ? urole.name.f
2191 : urole.name.m);
2192 buf[0] = lowc(buf[0]);
2194 } else {
2195 Strcpy(buf, ptr->mname); /* make sure we have standard singular */
2196 if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_PRIEST])
2197 which = !type_is_pname(ptr) ? "the " : "";
2199 if (how & REALLY) {
2200 /* setting no-corpse affects wishing and random tin generation */
2201 mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE);
2202 pline("Wiped out %s%s.", which,
2203 (*which != 'a') ? buf : makeplural(buf));
2205 if (killplayer) {
2206 /* might need to wipe out dual role */
2207 if (urole.femalenum != NON_PM && mndx == urole.malenum)
2208 mvitals[urole.femalenum].mvflags |= (G_GENOD | G_NOCORPSE);
2209 if (urole.femalenum != NON_PM && mndx == urole.femalenum)
2210 mvitals[urole.malenum].mvflags |= (G_GENOD | G_NOCORPSE);
2211 if (urace.femalenum != NON_PM && mndx == urace.malenum)
2212 mvitals[urace.femalenum].mvflags |= (G_GENOD | G_NOCORPSE);
2213 if (urace.femalenum != NON_PM && mndx == urace.femalenum)
2214 mvitals[urace.malenum].mvflags |= (G_GENOD | G_NOCORPSE);
2216 u.uhp = -1;
2217 if (how & PLAYER) {
2218 killer.format = KILLED_BY;
2219 Strcpy(killer.name, "genocidal confusion");
2220 } else if (how & ONTHRONE) {
2221 /* player selected while on a throne */
2222 killer.format = KILLED_BY_AN;
2223 Strcpy(killer.name, "imperious order");
2224 } else { /* selected player deliberately, not confused */
2225 killer.format = KILLED_BY_AN;
2226 Strcpy(killer.name, "scroll of genocide");
2229 /* Polymorphed characters will die as soon as they're rehumanized.
2231 /* KMH -- Unchanging prevents rehumanization */
2232 if (Upolyd && ptr != youmonst.data) {
2233 delayed_killer(POLYMORPH, killer.format, killer.name);
2234 You_feel("dead inside.");
2235 } else
2236 done(GENOCIDED);
2237 } else if (ptr == youmonst.data) {
2238 rehumanize();
2240 reset_rndmonst(mndx);
2241 kill_genocided_monsters();
2242 update_inventory(); /* in case identified eggs were affected */
2243 } else {
2244 int cnt = 0, census = monster_census(FALSE);
2246 if (!(mons[mndx].geno & G_UNIQ)
2247 && !(mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT)))
2248 for (i = rn1(3, 4); i > 0; i--) {
2249 if (!makemon(ptr, u.ux, u.uy, NO_MINVENT))
2250 break; /* couldn't make one */
2251 ++cnt;
2252 if (mvitals[mndx].mvflags & G_EXTINCT)
2253 break; /* just made last one */
2255 if (cnt) {
2256 /* accumulated 'cnt' doesn't take groups into account;
2257 assume bringing in new mon(s) didn't remove any old ones */
2258 cnt = monster_census(FALSE) - census;
2259 pline("Sent in %s%s.", (cnt > 1) ? "some " : "",
2260 (cnt > 1) ? makeplural(buf) : an(buf));
2261 } else
2262 pline1(nothing_happens);
2266 void
2267 punish(sobj)
2268 struct obj *sobj;
2270 struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL)
2271 ? sobj : (struct obj *) 0;
2273 /* KMH -- Punishment is still okay when you are riding */
2274 if (!reuse_ball)
2275 You("are being punished for your misbehavior!");
2276 if (Punished) {
2277 Your("iron ball gets heavier.");
2278 uball->owt += IRON_BALL_W_INCR * (1 + sobj->cursed);
2279 return;
2281 if (amorphous(youmonst.data) || is_whirly(youmonst.data)
2282 || unsolid(youmonst.data)) {
2283 if (!reuse_ball) {
2284 pline("A ball and chain appears, then falls away.");
2285 dropy(mkobj(BALL_CLASS, TRUE));
2286 } else {
2287 dropy(reuse_ball);
2289 return;
2291 setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN);
2292 if (!reuse_ball)
2293 setworn(mkobj(BALL_CLASS, TRUE), W_BALL);
2294 else
2295 setworn(reuse_ball, W_BALL);
2296 uball->spe = 1; /* special ball (see save) */
2299 * Place ball & chain if not swallowed. If swallowed, the ball &
2300 * chain variables will be set at the next call to placebc().
2302 if (!u.uswallow) {
2303 placebc();
2304 if (Blind)
2305 set_bc(1); /* set up ball and chain variables */
2306 newsym(u.ux, u.uy); /* see ball&chain if can't see self */
2310 /* remove the ball and chain */
2311 void
2312 unpunish()
2314 struct obj *savechain = uchain;
2316 obj_extract_self(uchain);
2317 newsym(uchain->ox, uchain->oy);
2318 setworn((struct obj *) 0, W_CHAIN);
2319 dealloc_obj(savechain);
2320 uball->spe = 0;
2321 setworn((struct obj *) 0, W_BALL);
2324 /* some creatures have special data structures that only make sense in their
2325 * normal locations -- if the player tries to create one elsewhere, or to
2326 * revive one, the disoriented creature becomes a zombie
2328 boolean
2329 cant_revive(mtype, revival, from_obj)
2330 int *mtype;
2331 boolean revival;
2332 struct obj *from_obj;
2334 /* SHOPKEEPERS can be revived now */
2335 if (*mtype == PM_GUARD || (*mtype == PM_SHOPKEEPER && !revival)
2336 || *mtype == PM_HIGH_PRIEST || *mtype == PM_ALIGNED_PRIEST
2337 || *mtype == PM_ANGEL) {
2338 *mtype = PM_HUMAN_ZOMBIE;
2339 return TRUE;
2340 } else if (*mtype == PM_LONG_WORM_TAIL) { /* for create_particular() */
2341 *mtype = PM_LONG_WORM;
2342 return TRUE;
2343 } else if (unique_corpstat(&mons[*mtype])
2344 && (!from_obj || !has_omonst(from_obj))) {
2345 /* unique corpses (from bones or wizard mode wish) or
2346 statues (bones or any wish) end up as shapechangers */
2347 *mtype = PM_DOPPELGANGER;
2348 return TRUE;
2350 return FALSE;
2354 * Make a new monster with the type controlled by the user.
2356 * Note: when creating a monster by class letter, specifying the
2357 * "strange object" (']') symbol produces a random monster rather
2358 * than a mimic. This behavior quirk is useful so don't "fix" it
2359 * (use 'm'--or "mimic"--to create a random mimic).
2361 * Used in wizard mode only (for ^G command and for scroll or spell
2362 * of create monster). Once upon a time, an earlier incarnation of
2363 * this code was also used for the scroll/spell in explore mode.
2365 boolean
2366 create_particular()
2368 char buf[BUFSZ], *bufp, monclass;
2369 char *tmpp;
2370 int which, tryct, i, firstchoice = NON_PM;
2371 struct permonst *whichpm = NULL;
2372 struct monst *mtmp;
2373 boolean madeany = FALSE, randmonst = FALSE,
2374 maketame, makepeaceful, makehostile, saddled, invisible,
2375 sleeping;
2376 int fem;
2378 tryct = 5;
2379 do {
2380 monclass = MAXMCLASSES;
2381 which = urole.malenum; /* an arbitrary index into mons[] */
2382 maketame = makepeaceful = makehostile = FALSE;
2383 sleeping = saddled = invisible = FALSE;
2384 fem = -1; /* gender not specified */
2385 getlin("Create what kind of monster? [type the name or symbol]", buf);
2386 bufp = mungspaces(buf);
2387 if (*bufp == '\033')
2388 return FALSE;
2389 if ((tmpp = strstri(bufp, "saddled ")) != 0) {
2390 saddled = TRUE;
2391 (void) memset(tmpp, ' ', sizeof "saddled " - 1);
2393 if ((tmpp = strstri(bufp, "sleeping ")) != 0) {
2394 sleeping = TRUE;
2395 (void) memset(tmpp, ' ', sizeof "sleeping " - 1);
2397 if ((tmpp = strstri(bufp, "invisible ")) != 0) {
2398 invisible = TRUE;
2399 (void) memset(tmpp, ' ', sizeof "invisible " - 1);
2401 /* check "female" before "male" to avoid false hit mid-word */
2402 if ((tmpp = strstri(bufp, "female ")) != 0) {
2403 fem = 1;
2404 (void) memset(tmpp, ' ', sizeof "female " - 1);
2406 if ((tmpp = strstri(bufp, "male ")) != 0) {
2407 fem = 0;
2408 (void) memset(tmpp, ' ', sizeof "male " - 1);
2410 bufp = mungspaces(bufp); /* after potential memset(' ') */
2411 /* allow the initial disposition to be specified */
2412 if (!strncmpi(bufp, "tame ", 5)) {
2413 bufp += 5;
2414 maketame = TRUE;
2415 } else if (!strncmpi(bufp, "peaceful ", 9)) {
2416 bufp += 9;
2417 makepeaceful = TRUE;
2418 } else if (!strncmpi(bufp, "hostile ", 8)) {
2419 bufp += 8;
2420 makehostile = TRUE;
2422 /* decide whether a valid monster was chosen */
2423 if (wizard && (!strcmp(bufp, "*") || !strcmp(bufp, "random"))) {
2424 randmonst = TRUE;
2425 break;
2427 which = name_to_mon(bufp);
2428 if (which >= LOW_PM)
2429 break; /* got one */
2430 monclass = name_to_monclass(bufp, &which);
2431 if (which >= LOW_PM) {
2432 monclass = MAXMCLASSES; /* matters below */
2433 break;
2434 } else if (monclass > 0) {
2435 which = urole.malenum; /* reset from NON_PM */
2436 break;
2438 /* no good; try again... */
2439 pline("I've never heard of such monsters.");
2440 } while (--tryct > 0);
2442 if (!tryct) {
2443 pline1(thats_enough_tries);
2444 } else {
2445 if (!randmonst) {
2446 firstchoice = which;
2447 if (cant_revive(&which, FALSE, (struct obj *) 0)) {
2448 /* wizard mode can override handling of special monsters */
2449 Sprintf(buf, "Creating %s instead; force %s?",
2450 mons[which].mname, mons[firstchoice].mname);
2451 if (yn(buf) == 'y')
2452 which = firstchoice;
2454 whichpm = &mons[which];
2456 for (i = 0; i <= multi; i++) {
2457 if (monclass != MAXMCLASSES)
2458 whichpm = mkclass(monclass, 0);
2459 else if (randmonst)
2460 whichpm = rndmonst();
2461 mtmp = makemon(whichpm, u.ux, u.uy, NO_MM_FLAGS);
2462 if (!mtmp) {
2463 /* quit trying if creation failed and is going to repeat */
2464 if (monclass == MAXMCLASSES && !randmonst)
2465 break;
2466 /* otherwise try again */
2467 continue;
2469 /* 'is_FOO()' ought to be called 'always_FOO()' */
2470 if (fem != -1 && !is_male(mtmp->data) && !is_female(mtmp->data))
2471 mtmp->female = fem; /* ignored for is_neuter() */
2472 if (maketame) {
2473 (void) tamedog(mtmp, (struct obj *) 0);
2474 } else if (makepeaceful || makehostile) {
2475 mtmp->mtame = 0; /* sanity precaution */
2476 mtmp->mpeaceful = makepeaceful ? 1 : 0;
2477 set_malign(mtmp);
2479 if (saddled && can_saddle(mtmp) && !which_armor(mtmp, W_SADDLE)) {
2480 struct obj *otmp = mksobj(SADDLE, TRUE, FALSE);
2482 put_saddle_on_mon(otmp, mtmp);
2484 if (invisible)
2485 mon_set_minvis(mtmp);
2486 if (sleeping)
2487 mtmp->msleeping = 1;
2488 madeany = TRUE;
2489 /* in case we got a doppelganger instead of what was asked
2490 for, make it start out looking like what was asked for */
2491 if (mtmp->cham != NON_PM && firstchoice != NON_PM
2492 && mtmp->cham != firstchoice)
2493 (void) newcham(mtmp, &mons[firstchoice], FALSE, FALSE);
2496 return madeany;
2499 /*read.c*/