dumplog message history groundwork
[aNetHack.git] / src / read.c
blobefc36e3cb8c7c8fc679422f8b9e7a2c74432bed2
1 /* NetHack 3.6 read.c $NHDT-Date: 1467718299 2016/07/05 11:31:39 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.140 $ */
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, FALSE);
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);
1418 break;
1419 case SCR_TELEPORTATION:
1420 if (confused || scursed) {
1421 level_tele();
1422 } else {
1423 known = scrolltele(sobj);
1425 break;
1426 case SCR_GOLD_DETECTION:
1427 if ((confused || scursed) ? trap_detect(sobj) : gold_detect(sobj))
1428 sobj = 0; /* failure: strange_feeling() -> useup() */
1429 break;
1430 case SCR_FOOD_DETECTION:
1431 case SPE_DETECT_FOOD:
1432 if (food_detect(sobj))
1433 sobj = 0; /* nothing detected: strange_feeling -> useup */
1434 break;
1435 case SCR_IDENTIFY:
1436 /* known = TRUE; -- handled inline here */
1437 /* use up the scroll first, before makeknown() performs a
1438 perm_invent update; also simplifies empty invent check */
1439 useup(sobj);
1440 sobj = 0; /* it's gone */
1441 if (confused)
1442 You("identify this as an identify scroll.");
1443 else if (!already_known || !invent)
1444 /* force feedback now if invent became
1445 empty after using up this scroll */
1446 pline("This is an identify scroll.");
1447 if (!already_known)
1448 (void) learnscrolltyp(SCR_IDENTIFY);
1449 /*FALLTHRU*/
1450 case SPE_IDENTIFY:
1451 cval = 1;
1452 if (sblessed || (!scursed && !rn2(5))) {
1453 cval = rn2(5);
1454 /* note: if cval==0, identify all items */
1455 if (cval == 1 && sblessed && Luck > 0)
1456 ++cval;
1458 if (invent && !confused) {
1459 identify_pack(cval, !already_known);
1460 } else if (otyp == SPE_IDENTIFY) {
1461 /* when casting a spell we know we're not confused,
1462 so inventory must be empty (another message has
1463 already been given above if reading a scroll) */
1464 pline("You're not carrying anything to be identified.");
1466 break;
1467 case SCR_CHARGING:
1468 if (confused) {
1469 if (scursed) {
1470 You_feel("discharged.");
1471 u.uen = 0;
1472 } else {
1473 You_feel("charged up!");
1474 u.uen += d(sblessed ? 6 : 4, 4);
1475 if (u.uen > u.uenmax) /* if current energy is already at */
1476 u.uenmax = u.uen; /* or near maximum, increase maximum */
1477 else
1478 u.uen = u.uenmax; /* otherwise restore current to max */
1480 context.botl = 1;
1481 break;
1483 /* known = TRUE; -- handled inline here */
1484 if (!already_known) {
1485 pline("This is a charging scroll.");
1486 learnscroll(sobj);
1488 /* use it up now to prevent it from showing in the
1489 getobj picklist because the "disappears" message
1490 was already delivered */
1491 useup(sobj);
1492 sobj = 0; /* it's gone */
1493 otmp = getobj(all_count, "charge");
1494 if (otmp)
1495 recharge(otmp, scursed ? -1 : sblessed ? 1 : 0);
1496 break;
1497 case SCR_MAGIC_MAPPING:
1498 if (level.flags.nommap) {
1499 Your("mind is filled with crazy lines!");
1500 if (Hallucination)
1501 pline("Wow! Modern art.");
1502 else
1503 Your("%s spins in bewilderment.", body_part(HEAD));
1504 make_confused(HConfusion + rnd(30), FALSE);
1505 break;
1507 if (sblessed) {
1508 register int x, y;
1510 for (x = 1; x < COLNO; x++)
1511 for (y = 0; y < ROWNO; y++)
1512 if (levl[x][y].typ == SDOOR)
1513 cvt_sdoor_to_door(&levl[x][y]);
1514 /* do_mapping() already reveals secret passages */
1516 known = TRUE;
1517 case SPE_MAGIC_MAPPING:
1518 if (level.flags.nommap) {
1519 Your("%s spins as %s blocks the spell!", body_part(HEAD),
1520 something);
1521 make_confused(HConfusion + rnd(30), FALSE);
1522 break;
1524 pline("A map coalesces in your mind!");
1525 cval = (scursed && !confused);
1526 if (cval)
1527 HConfusion = 1; /* to screw up map */
1528 do_mapping();
1529 if (cval) {
1530 HConfusion = 0; /* restore */
1531 pline("Unfortunately, you can't grasp the details.");
1533 break;
1534 case SCR_AMNESIA:
1535 known = TRUE;
1536 forget((!sblessed ? ALL_SPELLS : 0)
1537 | (!confused || scursed ? ALL_MAP : 0));
1538 if (Hallucination) /* Ommmmmm! */
1539 Your("mind releases itself from mundane concerns.");
1540 else if (!strncmpi(plname, "Maud", 4))
1541 pline(
1542 "As your mind turns inward on itself, you forget everything else.");
1543 else if (rn2(2))
1544 pline("Who was that Maud person anyway?");
1545 else
1546 pline("Thinking of Maud you forget everything else.");
1547 exercise(A_WIS, FALSE);
1548 break;
1549 case SCR_FIRE:
1550 cval = bcsign(sobj);
1551 useup(sobj);
1552 sobj = 0; /* it's gone */
1553 if (!already_known)
1554 (void) learnscrolltyp(SCR_FIRE);
1555 if (confused) {
1556 if (Fire_resistance) {
1557 shieldeff(u.ux, u.uy);
1558 if (!Blind)
1559 pline("Oh, look, what a pretty fire in your %s.",
1560 makeplural(body_part(HAND)));
1561 else
1562 You_feel("a pleasant warmth in your %s.",
1563 makeplural(body_part(HAND)));
1564 } else {
1565 pline_The("scroll catches fire and you burn your %s.",
1566 makeplural(body_part(HAND)));
1567 losehp(1, "scroll of fire", KILLED_BY_AN);
1569 break;
1571 if (Underwater) {
1572 pline_The("%s around you vaporizes violently!", hliquid("water"));
1573 } else {
1574 pline_The("scroll erupts in a tower of flame!");
1575 iflags.last_msg = PLNMSG_TOWER_OF_FLAME; /* for explode() */
1576 burn_away_slime();
1578 explode(u.ux, u.uy, 11, (2 * (rn1(3, 3) + 2 * cval) + 1) / 3,
1579 SCROLL_CLASS, EXPL_FIERY);
1580 break;
1581 case SCR_EARTH:
1582 /* TODO: handle steeds */
1583 if (!Is_rogue_level(&u.uz) && has_ceiling(&u.uz)
1584 && (!In_endgame(&u.uz) || Is_earthlevel(&u.uz))) {
1585 register int x, y;
1586 int nboulders = 0;
1588 /* Identify the scroll */
1589 if (u.uswallow)
1590 You_hear("rumbling.");
1591 else
1592 pline_The("%s rumbles %s you!", ceiling(u.ux, u.uy),
1593 sblessed ? "around" : "above");
1594 known = 1;
1595 sokoban_guilt();
1597 /* Loop through the surrounding squares */
1598 if (!scursed)
1599 for (x = u.ux - 1; x <= u.ux + 1; x++) {
1600 for (y = u.uy - 1; y <= u.uy + 1; y++) {
1601 /* Is this a suitable spot? */
1602 if (isok(x, y) && !closed_door(x, y)
1603 && !IS_ROCK(levl[x][y].typ)
1604 && !IS_AIR(levl[x][y].typ)
1605 && (x != u.ux || y != u.uy)) {
1606 nboulders +=
1607 drop_boulder_on_monster(x, y, confused, TRUE);
1611 /* Attack the player */
1612 if (!sblessed) {
1613 drop_boulder_on_player(confused, !scursed, TRUE, FALSE);
1614 } else if (!nboulders)
1615 pline("But nothing else happens.");
1617 break;
1618 case SCR_PUNISHMENT:
1619 known = TRUE;
1620 if (confused || sblessed) {
1621 You_feel("guilty.");
1622 break;
1624 punish(sobj);
1625 break;
1626 case SCR_STINKING_CLOUD: {
1627 coord cc;
1629 if (!already_known)
1630 You("have found a scroll of stinking cloud!");
1631 known = TRUE;
1632 pline("Where do you want to center the %scloud?",
1633 already_known ? "stinking " : "");
1634 cc.x = u.ux;
1635 cc.y = u.uy;
1636 getpos_sethilite(display_stinking_cloud_positions);
1637 if (getpos(&cc, TRUE, "the desired position") < 0) {
1638 pline1(Never_mind);
1639 break;
1641 if (!is_valid_stinking_cloud_pos(cc.x, cc.y, TRUE))
1642 break;
1643 (void) create_gas_cloud(cc.x, cc.y, 3 + bcsign(sobj),
1644 8 + 4 * bcsign(sobj));
1645 break;
1647 default:
1648 impossible("What weird effect is this? (%u)", otyp);
1650 return sobj ? 0 : 1;
1653 void
1654 drop_boulder_on_player(confused, helmet_protects, byu, skip_uswallow)
1655 boolean confused, helmet_protects, byu, skip_uswallow;
1657 int dmg;
1658 struct obj *otmp2;
1660 /* hit monster if swallowed */
1661 if (u.uswallow && !skip_uswallow) {
1662 drop_boulder_on_monster(u.ux, u.uy, confused, byu);
1663 return;
1666 otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
1667 if (!otmp2)
1668 return;
1669 otmp2->quan = confused ? rn1(5, 2) : 1;
1670 otmp2->owt = weight(otmp2);
1671 if (!amorphous(youmonst.data) && !Passes_walls
1672 && !noncorporeal(youmonst.data) && !unsolid(youmonst.data)) {
1673 You("are hit by %s!", doname(otmp2));
1674 dmg = dmgval(otmp2, &youmonst) * otmp2->quan;
1675 if (uarmh && helmet_protects) {
1676 if (is_metallic(uarmh)) {
1677 pline("Fortunately, you are wearing a hard helmet.");
1678 if (dmg > 2)
1679 dmg = 2;
1680 } else if (flags.verbose) {
1681 pline("%s does not protect you.", Yname2(uarmh));
1684 } else
1685 dmg = 0;
1686 /* Must be before the losehp(), for bones files */
1687 if (!flooreffects(otmp2, u.ux, u.uy, "fall")) {
1688 place_object(otmp2, u.ux, u.uy);
1689 stackobj(otmp2);
1690 newsym(u.ux, u.uy);
1692 if (dmg)
1693 losehp(Maybe_Half_Phys(dmg), "scroll of earth", KILLED_BY_AN);
1696 boolean
1697 drop_boulder_on_monster(x, y, confused, byu)
1698 int x, y;
1699 boolean confused, byu;
1701 register struct obj *otmp2;
1702 register struct monst *mtmp;
1704 /* Make the object(s) */
1705 otmp2 = mksobj(confused ? ROCK : BOULDER, FALSE, FALSE);
1706 if (!otmp2)
1707 return FALSE; /* Shouldn't happen */
1708 otmp2->quan = confused ? rn1(5, 2) : 1;
1709 otmp2->owt = weight(otmp2);
1711 /* Find the monster here (won't be player) */
1712 mtmp = m_at(x, y);
1713 if (mtmp && !amorphous(mtmp->data) && !passes_walls(mtmp->data)
1714 && !noncorporeal(mtmp->data) && !unsolid(mtmp->data)) {
1715 struct obj *helmet = which_armor(mtmp, W_ARMH);
1716 int mdmg;
1718 if (cansee(mtmp->mx, mtmp->my)) {
1719 pline("%s is hit by %s!", Monnam(mtmp), doname(otmp2));
1720 if (mtmp->minvis && !canspotmon(mtmp))
1721 map_invisible(mtmp->mx, mtmp->my);
1722 } else if (u.uswallow && mtmp == u.ustuck)
1723 You_hear("something hit %s %s over your %s!",
1724 s_suffix(mon_nam(mtmp)), mbodypart(mtmp, STOMACH),
1725 body_part(HEAD));
1727 mdmg = dmgval(otmp2, mtmp) * otmp2->quan;
1728 if (helmet) {
1729 if (is_metallic(helmet)) {
1730 if (canspotmon(mtmp))
1731 pline("Fortunately, %s is wearing a hard helmet.",
1732 mon_nam(mtmp));
1733 else if (!Deaf)
1734 You_hear("a clanging sound.");
1735 if (mdmg > 2)
1736 mdmg = 2;
1737 } else {
1738 if (canspotmon(mtmp))
1739 pline("%s's %s does not protect %s.", Monnam(mtmp),
1740 xname(helmet), mhim(mtmp));
1743 mtmp->mhp -= mdmg;
1744 if (mtmp->mhp <= 0) {
1745 if (byu) {
1746 killed(mtmp);
1747 } else {
1748 pline("%s is killed.", Monnam(mtmp));
1749 mondied(mtmp);
1752 } else if (u.uswallow && mtmp == u.ustuck) {
1753 obfree(otmp2, (struct obj *) 0);
1754 /* fall through to player */
1755 drop_boulder_on_player(confused, TRUE, FALSE, TRUE);
1756 return 1;
1758 /* Drop the rock/boulder to the floor */
1759 if (!flooreffects(otmp2, x, y, "fall")) {
1760 place_object(otmp2, x, y);
1761 stackobj(otmp2);
1762 newsym(x, y); /* map the rock */
1764 return TRUE;
1767 /* overcharging any wand or zapping/engraving cursed wand */
1768 void
1769 wand_explode(obj, chg)
1770 struct obj *obj;
1771 int chg; /* recharging */
1773 const char *expl = !chg ? "suddenly" : "vibrates violently and";
1774 int dmg, n, k;
1776 /* number of damage dice */
1777 if (!chg)
1778 chg = 2; /* zap/engrave adjustment */
1779 n = obj->spe + chg;
1780 if (n < 2)
1781 n = 2; /* arbitrary minimum */
1782 /* size of damage dice */
1783 switch (obj->otyp) {
1784 case WAN_WISHING:
1785 k = 12;
1786 break;
1787 case WAN_CANCELLATION:
1788 case WAN_DEATH:
1789 case WAN_POLYMORPH:
1790 case WAN_UNDEAD_TURNING:
1791 k = 10;
1792 break;
1793 case WAN_COLD:
1794 case WAN_FIRE:
1795 case WAN_LIGHTNING:
1796 case WAN_MAGIC_MISSILE:
1797 k = 8;
1798 break;
1799 case WAN_NOTHING:
1800 k = 4;
1801 break;
1802 default:
1803 k = 6;
1804 break;
1806 /* inflict damage and destroy the wand */
1807 dmg = d(n, k);
1808 obj->in_use = TRUE; /* in case losehp() is fatal (or --More--^C) */
1809 pline("%s %s explodes!", Yname2(obj), expl);
1810 losehp(Maybe_Half_Phys(dmg), "exploding wand", KILLED_BY_AN);
1811 useup(obj);
1812 /* obscure side-effect */
1813 exercise(A_STR, FALSE);
1816 /* used to collect gremlins being hit by light so that they can be processed
1817 after vision for the entire lit area has been brought up to date */
1818 struct litmon {
1819 struct monst *mon;
1820 struct litmon *nxt;
1822 STATIC_VAR struct litmon *gremlins = 0;
1825 * Low-level lit-field update routine.
1827 STATIC_PTR void
1828 set_lit(x, y, val)
1829 int x, y;
1830 genericptr_t val;
1832 struct monst *mtmp;
1833 struct litmon *gremlin;
1835 if (val) {
1836 levl[x][y].lit = 1;
1837 if ((mtmp = m_at(x, y)) != 0 && mtmp->data == &mons[PM_GREMLIN]) {
1838 gremlin = (struct litmon *) alloc(sizeof *gremlin);
1839 gremlin->mon = mtmp;
1840 gremlin->nxt = gremlins;
1841 gremlins = gremlin;
1843 } else {
1844 levl[x][y].lit = 0;
1845 snuff_light_source(x, y);
1849 void
1850 litroom(on, obj)
1851 register boolean on;
1852 struct obj *obj;
1854 char is_lit; /* value is irrelevant; we use its address
1855 as a `not null' flag for set_lit() */
1857 /* first produce the text (provided you're not blind) */
1858 if (!on) {
1859 register struct obj *otmp;
1861 if (!Blind) {
1862 if (u.uswallow) {
1863 pline("It seems even darker in here than before.");
1864 } else {
1865 if (uwep && artifact_light(uwep) && uwep->lamplit)
1866 pline("Suddenly, the only light left comes from %s!",
1867 the(xname(uwep)));
1868 else
1869 You("are surrounded by darkness!");
1873 /* the magic douses lamps, et al, too */
1874 for (otmp = invent; otmp; otmp = otmp->nobj)
1875 if (otmp->lamplit)
1876 (void) snuff_lit(otmp);
1877 } else { /* on */
1878 if (u.uswallow) {
1879 if (Blind)
1880 ; /* no feedback */
1881 else if (is_animal(u.ustuck->data))
1882 pline("%s %s is lit.", s_suffix(Monnam(u.ustuck)),
1883 mbodypart(u.ustuck, STOMACH));
1884 else if (is_whirly(u.ustuck->data))
1885 pline("%s shines briefly.", Monnam(u.ustuck));
1886 else
1887 pline("%s glistens.", Monnam(u.ustuck));
1888 } else if (!Blind)
1889 pline("A lit field surrounds you!");
1892 /* No-op when swallowed or in water */
1893 if (u.uswallow || Underwater || Is_waterlevel(&u.uz))
1894 return;
1896 * If we are darkening the room and the hero is punished but not
1897 * blind, then we have to pick up and replace the ball and chain so
1898 * that we don't remember them if they are out of sight.
1900 if (Punished && !on && !Blind)
1901 move_bc(1, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
1903 if (Is_rogue_level(&u.uz)) {
1904 /* Can't use do_clear_area because MAX_RADIUS is too small */
1905 /* rogue lighting must light the entire room */
1906 int rnum = levl[u.ux][u.uy].roomno - ROOMOFFSET;
1907 int rx, ry;
1909 if (rnum >= 0) {
1910 for (rx = rooms[rnum].lx - 1; rx <= rooms[rnum].hx + 1; rx++)
1911 for (ry = rooms[rnum].ly - 1; ry <= rooms[rnum].hy + 1; ry++)
1912 set_lit(rx, ry,
1913 (genericptr_t) (on ? &is_lit : (char *) 0));
1914 rooms[rnum].rlit = on;
1916 /* hallways remain dark on the rogue level */
1917 } else
1918 do_clear_area(u.ux, u.uy,
1919 (obj && obj->oclass == SCROLL_CLASS && obj->blessed)
1920 ? 9 : 5,
1921 set_lit, (genericptr_t) (on ? &is_lit : (char *) 0));
1924 * If we are not blind, then force a redraw on all positions in sight
1925 * by temporarily blinding the hero. The vision recalculation will
1926 * correctly update all previously seen positions *and* correctly
1927 * set the waslit bit [could be messed up from above].
1929 if (!Blind) {
1930 vision_recalc(2);
1932 /* replace ball&chain */
1933 if (Punished && !on)
1934 move_bc(0, 0, uball->ox, uball->oy, uchain->ox, uchain->oy);
1937 vision_full_recalc = 1; /* delayed vision recalculation */
1938 if (gremlins) {
1939 struct litmon *gremlin;
1941 /* can't delay vision recalc after all */
1942 vision_recalc(0);
1943 /* after vision has been updated, monsters who are affected
1944 when hit by light can now be hit by it */
1945 do {
1946 gremlin = gremlins;
1947 gremlins = gremlin->nxt;
1948 light_hits_gremlin(gremlin->mon, rnd(5));
1949 free((genericptr_t) gremlin);
1950 } while (gremlins);
1954 STATIC_OVL void
1955 do_class_genocide()
1957 int i, j, immunecnt, gonecnt, goodcnt, class, feel_dead = 0;
1958 char buf[BUFSZ];
1959 boolean gameover = FALSE; /* true iff killed self */
1961 for (j = 0;; j++) {
1962 if (j >= 5) {
1963 pline1(thats_enough_tries);
1964 return;
1966 do {
1967 getlin("What class of monsters do you wish to genocide?", buf);
1968 (void) mungspaces(buf);
1969 } while (!*buf);
1970 /* choosing "none" preserves genocideless conduct */
1971 if (*buf == '\033' || !strcmpi(buf, "none")
1972 || !strcmpi(buf, "nothing"))
1973 return;
1975 class = name_to_monclass(buf, (int *) 0);
1976 if (class == 0 && (i = name_to_mon(buf)) != NON_PM)
1977 class = mons[i].mlet;
1978 immunecnt = gonecnt = goodcnt = 0;
1979 for (i = LOW_PM; i < NUMMONS; i++) {
1980 if (mons[i].mlet == class) {
1981 if (!(mons[i].geno & G_GENO))
1982 immunecnt++;
1983 else if (mvitals[i].mvflags & G_GENOD)
1984 gonecnt++;
1985 else
1986 goodcnt++;
1989 if (!goodcnt && class != mons[urole.malenum].mlet
1990 && class != mons[urace.malenum].mlet) {
1991 if (gonecnt)
1992 pline("All such monsters are already nonexistent.");
1993 else if (immunecnt || class == S_invisible)
1994 You("aren't permitted to genocide such monsters.");
1995 else if (wizard && buf[0] == '*') {
1996 register struct monst *mtmp, *mtmp2;
1998 gonecnt = 0;
1999 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
2000 mtmp2 = mtmp->nmon;
2001 if (DEADMONSTER(mtmp))
2002 continue;
2003 mongone(mtmp);
2004 gonecnt++;
2006 pline("Eliminated %d monster%s.", gonecnt, plur(gonecnt));
2007 return;
2008 } else
2009 pline("That %s does not represent any monster.",
2010 strlen(buf) == 1 ? "symbol" : "response");
2011 continue;
2014 for (i = LOW_PM; i < NUMMONS; i++) {
2015 if (mons[i].mlet == class) {
2016 char nam[BUFSZ];
2018 Strcpy(nam, makeplural(mons[i].mname));
2019 /* Although "genus" is Latin for race, the hero benefits
2020 * from both race and role; thus genocide affects either.
2022 if (Your_Own_Role(i) || Your_Own_Race(i)
2023 || ((mons[i].geno & G_GENO)
2024 && !(mvitals[i].mvflags & G_GENOD))) {
2025 /* This check must be first since player monsters might
2026 * have G_GENOD or !G_GENO.
2028 mvitals[i].mvflags |= (G_GENOD | G_NOCORPSE);
2029 reset_rndmonst(i);
2030 kill_genocided_monsters();
2031 update_inventory(); /* eggs & tins */
2032 pline("Wiped out all %s.", nam);
2033 if (Upolyd && i == u.umonnum) {
2034 u.mh = -1;
2035 if (Unchanging) {
2036 if (!feel_dead++)
2037 You("die.");
2038 /* finish genociding this class of
2039 monsters before ultimately dying */
2040 gameover = TRUE;
2041 } else
2042 rehumanize();
2044 /* Self-genocide if it matches either your race
2045 or role. Assumption: male and female forms
2046 share same monster class. */
2047 if (i == urole.malenum || i == urace.malenum) {
2048 u.uhp = -1;
2049 if (Upolyd) {
2050 if (!feel_dead++)
2051 You_feel("dead inside.");
2052 } else {
2053 if (!feel_dead++)
2054 You("die.");
2055 gameover = TRUE;
2058 } else if (mvitals[i].mvflags & G_GENOD) {
2059 if (!gameover)
2060 pline("All %s are already nonexistent.", nam);
2061 } else if (!gameover) {
2062 /* suppress feedback about quest beings except
2063 for those applicable to our own role */
2064 if ((mons[i].msound != MS_LEADER
2065 || quest_info(MS_LEADER) == i)
2066 && (mons[i].msound != MS_NEMESIS
2067 || quest_info(MS_NEMESIS) == i)
2068 && (mons[i].msound != MS_GUARDIAN
2069 || quest_info(MS_GUARDIAN) == i)
2070 /* non-leader/nemesis/guardian role-specific monster
2072 && (i != PM_NINJA /* nuisance */
2073 || Role_if(PM_SAMURAI))) {
2074 boolean named, uniq;
2076 named = type_is_pname(&mons[i]) ? TRUE : FALSE;
2077 uniq = (mons[i].geno & G_UNIQ) ? TRUE : FALSE;
2078 /* one special case */
2079 if (i == PM_HIGH_PRIEST)
2080 uniq = FALSE;
2082 You("aren't permitted to genocide %s%s.",
2083 (uniq && !named) ? "the " : "",
2084 (uniq || named) ? mons[i].mname : nam);
2089 if (gameover || u.uhp == -1) {
2090 killer.format = KILLED_BY_AN;
2091 Strcpy(killer.name, "scroll of genocide");
2092 if (gameover)
2093 done(GENOCIDED);
2095 return;
2099 #define REALLY 1
2100 #define PLAYER 2
2101 #define ONTHRONE 4
2102 void
2103 do_genocide(how)
2104 int how;
2105 /* 0 = no genocide; create monsters (cursed scroll) */
2106 /* 1 = normal genocide */
2107 /* 3 = forced genocide of player */
2108 /* 5 (4 | 1) = normal genocide from throne */
2110 char buf[BUFSZ];
2111 register int i, killplayer = 0;
2112 register int mndx;
2113 register struct permonst *ptr;
2114 const char *which;
2116 if (how & PLAYER) {
2117 mndx = u.umonster; /* non-polymorphed mon num */
2118 ptr = &mons[mndx];
2119 Strcpy(buf, ptr->mname);
2120 killplayer++;
2121 } else {
2122 for (i = 0;; i++) {
2123 if (i >= 5) {
2124 /* cursed effect => no free pass (unless rndmonst() fails) */
2125 if (!(how & REALLY) && (ptr = rndmonst()) != 0)
2126 break;
2128 pline1(thats_enough_tries);
2129 return;
2131 getlin("What monster do you want to genocide? [type the name]",
2132 buf);
2133 (void) mungspaces(buf);
2134 /* choosing "none" preserves genocideless conduct */
2135 if (*buf == '\033' || !strcmpi(buf, "none")
2136 || !strcmpi(buf, "nothing")) {
2137 /* ... but no free pass if cursed */
2138 if (!(how & REALLY) && (ptr = rndmonst()) != 0)
2139 break; /* remaining checks don't apply */
2141 return;
2144 mndx = name_to_mon(buf);
2145 if (mndx == NON_PM || (mvitals[mndx].mvflags & G_GENOD)) {
2146 pline("Such creatures %s exist in this world.",
2147 (mndx == NON_PM) ? "do not" : "no longer");
2148 continue;
2150 ptr = &mons[mndx];
2151 /* Although "genus" is Latin for race, the hero benefits
2152 * from both race and role; thus genocide affects either.
2154 if (Your_Own_Role(mndx) || Your_Own_Race(mndx)) {
2155 killplayer++;
2156 break;
2158 if (is_human(ptr))
2159 adjalign(-sgn(u.ualign.type));
2160 if (is_demon(ptr))
2161 adjalign(sgn(u.ualign.type));
2163 if (!(ptr->geno & G_GENO)) {
2164 if (!Deaf) {
2165 /* FIXME: unconditional "caverns" will be silly in some
2166 * circumstances. Who's speaking? Divine pronouncements
2167 * aren't supposed to be hampered by deafness....
2169 if (flags.verbose)
2170 pline("A thunderous voice booms through the caverns:");
2171 verbalize("No, mortal! That will not be done.");
2173 continue;
2175 /* KMH -- Unchanging prevents rehumanization */
2176 if (Unchanging && ptr == youmonst.data)
2177 killplayer++;
2178 break;
2180 mndx = monsndx(ptr); /* needed for the 'no free pass' cases */
2183 which = "all ";
2184 if (Hallucination) {
2185 if (Upolyd)
2186 Strcpy(buf, youmonst.data->mname);
2187 else {
2188 Strcpy(buf, (flags.female && urole.name.f) ? urole.name.f
2189 : urole.name.m);
2190 buf[0] = lowc(buf[0]);
2192 } else {
2193 Strcpy(buf, ptr->mname); /* make sure we have standard singular */
2194 if ((ptr->geno & G_UNIQ) && ptr != &mons[PM_HIGH_PRIEST])
2195 which = !type_is_pname(ptr) ? "the " : "";
2197 if (how & REALLY) {
2198 /* setting no-corpse affects wishing and random tin generation */
2199 mvitals[mndx].mvflags |= (G_GENOD | G_NOCORPSE);
2200 pline("Wiped out %s%s.", which,
2201 (*which != 'a') ? buf : makeplural(buf));
2203 if (killplayer) {
2204 /* might need to wipe out dual role */
2205 if (urole.femalenum != NON_PM && mndx == urole.malenum)
2206 mvitals[urole.femalenum].mvflags |= (G_GENOD | G_NOCORPSE);
2207 if (urole.femalenum != NON_PM && mndx == urole.femalenum)
2208 mvitals[urole.malenum].mvflags |= (G_GENOD | G_NOCORPSE);
2209 if (urace.femalenum != NON_PM && mndx == urace.malenum)
2210 mvitals[urace.femalenum].mvflags |= (G_GENOD | G_NOCORPSE);
2211 if (urace.femalenum != NON_PM && mndx == urace.femalenum)
2212 mvitals[urace.malenum].mvflags |= (G_GENOD | G_NOCORPSE);
2214 u.uhp = -1;
2215 if (how & PLAYER) {
2216 killer.format = KILLED_BY;
2217 Strcpy(killer.name, "genocidal confusion");
2218 } else if (how & ONTHRONE) {
2219 /* player selected while on a throne */
2220 killer.format = KILLED_BY_AN;
2221 Strcpy(killer.name, "imperious order");
2222 } else { /* selected player deliberately, not confused */
2223 killer.format = KILLED_BY_AN;
2224 Strcpy(killer.name, "scroll of genocide");
2227 /* Polymorphed characters will die as soon as they're rehumanized.
2229 /* KMH -- Unchanging prevents rehumanization */
2230 if (Upolyd && ptr != youmonst.data) {
2231 delayed_killer(POLYMORPH, killer.format, killer.name);
2232 You_feel("dead inside.");
2233 } else
2234 done(GENOCIDED);
2235 } else if (ptr == youmonst.data) {
2236 rehumanize();
2238 reset_rndmonst(mndx);
2239 kill_genocided_monsters();
2240 update_inventory(); /* in case identified eggs were affected */
2241 } else {
2242 int cnt = 0, census = monster_census(FALSE);
2244 if (!(mons[mndx].geno & G_UNIQ)
2245 && !(mvitals[mndx].mvflags & (G_GENOD | G_EXTINCT)))
2246 for (i = rn1(3, 4); i > 0; i--) {
2247 if (!makemon(ptr, u.ux, u.uy, NO_MINVENT))
2248 break; /* couldn't make one */
2249 ++cnt;
2250 if (mvitals[mndx].mvflags & G_EXTINCT)
2251 break; /* just made last one */
2253 if (cnt) {
2254 /* accumulated 'cnt' doesn't take groups into account;
2255 assume bringing in new mon(s) didn't remove any old ones */
2256 cnt = monster_census(FALSE) - census;
2257 pline("Sent in %s%s.", (cnt > 1) ? "some " : "",
2258 (cnt > 1) ? makeplural(buf) : an(buf));
2259 } else
2260 pline1(nothing_happens);
2264 void
2265 punish(sobj)
2266 struct obj *sobj;
2268 struct obj *reuse_ball = (sobj && sobj->otyp == HEAVY_IRON_BALL)
2269 ? sobj : (struct obj *) 0;
2271 /* KMH -- Punishment is still okay when you are riding */
2272 if (!reuse_ball)
2273 You("are being punished for your misbehavior!");
2274 if (Punished) {
2275 Your("iron ball gets heavier.");
2276 uball->owt += IRON_BALL_W_INCR * (1 + sobj->cursed);
2277 return;
2279 if (amorphous(youmonst.data) || is_whirly(youmonst.data)
2280 || unsolid(youmonst.data)) {
2281 if (!reuse_ball) {
2282 pline("A ball and chain appears, then falls away.");
2283 dropy(mkobj(BALL_CLASS, TRUE));
2284 } else {
2285 dropy(reuse_ball);
2287 return;
2289 setworn(mkobj(CHAIN_CLASS, TRUE), W_CHAIN);
2290 if (!reuse_ball)
2291 setworn(mkobj(BALL_CLASS, TRUE), W_BALL);
2292 else
2293 setworn(reuse_ball, W_BALL);
2294 uball->spe = 1; /* special ball (see save) */
2297 * Place ball & chain if not swallowed. If swallowed, the ball &
2298 * chain variables will be set at the next call to placebc().
2300 if (!u.uswallow) {
2301 placebc();
2302 if (Blind)
2303 set_bc(1); /* set up ball and chain variables */
2304 newsym(u.ux, u.uy); /* see ball&chain if can't see self */
2308 /* remove the ball and chain */
2309 void
2310 unpunish()
2312 struct obj *savechain = uchain;
2314 obj_extract_self(uchain);
2315 newsym(uchain->ox, uchain->oy);
2316 setworn((struct obj *) 0, W_CHAIN);
2317 dealloc_obj(savechain);
2318 uball->spe = 0;
2319 setworn((struct obj *) 0, W_BALL);
2322 /* some creatures have special data structures that only make sense in their
2323 * normal locations -- if the player tries to create one elsewhere, or to
2324 * revive one, the disoriented creature becomes a zombie
2326 boolean
2327 cant_revive(mtype, revival, from_obj)
2328 int *mtype;
2329 boolean revival;
2330 struct obj *from_obj;
2332 /* SHOPKEEPERS can be revived now */
2333 if (*mtype == PM_GUARD || (*mtype == PM_SHOPKEEPER && !revival)
2334 || *mtype == PM_HIGH_PRIEST || *mtype == PM_ALIGNED_PRIEST
2335 || *mtype == PM_ANGEL) {
2336 *mtype = PM_HUMAN_ZOMBIE;
2337 return TRUE;
2338 } else if (*mtype == PM_LONG_WORM_TAIL) { /* for create_particular() */
2339 *mtype = PM_LONG_WORM;
2340 return TRUE;
2341 } else if (unique_corpstat(&mons[*mtype])
2342 && (!from_obj || !has_omonst(from_obj))) {
2343 /* unique corpses (from bones or wizard mode wish) or
2344 statues (bones or any wish) end up as shapechangers */
2345 *mtype = PM_DOPPELGANGER;
2346 return TRUE;
2348 return FALSE;
2352 * Make a new monster with the type controlled by the user.
2354 * Note: when creating a monster by class letter, specifying the
2355 * "strange object" (']') symbol produces a random monster rather
2356 * than a mimic. This behavior quirk is useful so don't "fix" it
2357 * (use 'm'--or "mimic"--to create a random mimic).
2359 * Used in wizard mode only (for ^G command and for scroll or spell
2360 * of create monster). Once upon a time, an earlier incarnation of
2361 * this code was also used for the scroll/spell in explore mode.
2363 boolean
2364 create_particular()
2366 char buf[BUFSZ], *bufp, monclass;
2367 char *tmpp;
2368 int which, tryct, i, firstchoice = NON_PM;
2369 struct permonst *whichpm = NULL;
2370 struct monst *mtmp;
2371 boolean madeany = FALSE, randmonst = FALSE,
2372 maketame, makepeaceful, makehostile, saddled, invisible,
2373 sleeping;
2374 int fem;
2376 tryct = 5;
2377 do {
2378 monclass = MAXMCLASSES;
2379 which = urole.malenum; /* an arbitrary index into mons[] */
2380 maketame = makepeaceful = makehostile = FALSE;
2381 sleeping = saddled = invisible = FALSE;
2382 fem = -1; /* gender not specified */
2383 getlin("Create what kind of monster? [type the name or symbol]", buf);
2384 bufp = mungspaces(buf);
2385 if (*bufp == '\033')
2386 return FALSE;
2387 if ((tmpp = strstri(bufp, "saddled ")) != 0) {
2388 saddled = TRUE;
2389 (void) memset(tmpp, ' ', sizeof "saddled " - 1);
2391 if ((tmpp = strstri(bufp, "sleeping ")) != 0) {
2392 sleeping = TRUE;
2393 (void) memset(tmpp, ' ', sizeof "sleeping " - 1);
2395 if ((tmpp = strstri(bufp, "invisible ")) != 0) {
2396 invisible = TRUE;
2397 (void) memset(tmpp, ' ', sizeof "invisible " - 1);
2399 /* check "female" before "male" to avoid false hit mid-word */
2400 if ((tmpp = strstri(bufp, "female ")) != 0) {
2401 fem = 1;
2402 (void) memset(tmpp, ' ', sizeof "female " - 1);
2404 if ((tmpp = strstri(bufp, "male ")) != 0) {
2405 fem = 0;
2406 (void) memset(tmpp, ' ', sizeof "male " - 1);
2408 bufp = mungspaces(bufp); /* after potential memset(' ') */
2409 /* allow the initial disposition to be specified */
2410 if (!strncmpi(bufp, "tame ", 5)) {
2411 bufp += 5;
2412 maketame = TRUE;
2413 } else if (!strncmpi(bufp, "peaceful ", 9)) {
2414 bufp += 9;
2415 makepeaceful = TRUE;
2416 } else if (!strncmpi(bufp, "hostile ", 8)) {
2417 bufp += 8;
2418 makehostile = TRUE;
2420 /* decide whether a valid monster was chosen */
2421 if (wizard && (!strcmp(bufp, "*") || !strcmp(bufp, "random"))) {
2422 randmonst = TRUE;
2423 break;
2425 which = name_to_mon(bufp);
2426 if (which >= LOW_PM)
2427 break; /* got one */
2428 monclass = name_to_monclass(bufp, &which);
2429 if (which >= LOW_PM) {
2430 monclass = MAXMCLASSES; /* matters below */
2431 break;
2432 } else if (monclass > 0) {
2433 which = urole.malenum; /* reset from NON_PM */
2434 break;
2436 /* no good; try again... */
2437 pline("I've never heard of such monsters.");
2438 } while (--tryct > 0);
2440 if (!tryct) {
2441 pline1(thats_enough_tries);
2442 } else {
2443 if (!randmonst) {
2444 firstchoice = which;
2445 if (cant_revive(&which, FALSE, (struct obj *) 0)) {
2446 /* wizard mode can override handling of special monsters */
2447 Sprintf(buf, "Creating %s instead; force %s?",
2448 mons[which].mname, mons[firstchoice].mname);
2449 if (yn(buf) == 'y')
2450 which = firstchoice;
2452 whichpm = &mons[which];
2454 for (i = 0; i <= multi; i++) {
2455 if (monclass != MAXMCLASSES)
2456 whichpm = mkclass(monclass, 0);
2457 else if (randmonst)
2458 whichpm = rndmonst();
2459 mtmp = makemon(whichpm, u.ux, u.uy, NO_MM_FLAGS);
2460 if (!mtmp) {
2461 /* quit trying if creation failed and is going to repeat */
2462 if (monclass == MAXMCLASSES && !randmonst)
2463 break;
2464 /* otherwise try again */
2465 continue;
2467 /* 'is_FOO()' ought to be called 'always_FOO()' */
2468 if (fem != -1 && !is_male(mtmp->data) && !is_female(mtmp->data))
2469 mtmp->female = fem; /* ignored for is_neuter() */
2470 if (maketame) {
2471 (void) tamedog(mtmp, (struct obj *) 0);
2472 } else if (makepeaceful || makehostile) {
2473 mtmp->mtame = 0; /* sanity precaution */
2474 mtmp->mpeaceful = makepeaceful ? 1 : 0;
2475 set_malign(mtmp);
2477 if (saddled && can_saddle(mtmp) && !which_armor(mtmp, W_SADDLE)) {
2478 struct obj *otmp = mksobj(SADDLE, TRUE, FALSE);
2480 put_saddle_on_mon(otmp, mtmp);
2482 if (invisible)
2483 mon_set_minvis(mtmp);
2484 if (sleeping)
2485 mtmp->msleeping = 1;
2486 madeany = TRUE;
2487 /* in case we got a doppelganger instead of what was asked
2488 for, make it start out looking like what was asked for */
2489 if (mtmp->cham != NON_PM && firstchoice != NON_PM
2490 && mtmp->cham != firstchoice)
2491 (void) newcham(mtmp, &mons[firstchoice], FALSE, FALSE);
2494 return madeany;
2497 /*read.c*/