1 /* $NetBSD: hack.read.c,v 1.11 2011/08/06 20:29:37 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 static int identify(struct obj
*);
69 static int monstersym(int);
75 boolean confused
= (Confusion
!= 0);
76 boolean known
= FALSE
;
78 scroll
= getobj("?", "read");
81 if (!scroll
->dknown
&& Blind
) {
82 pline("Being blind, you cannot read the formula on the scroll.");
86 pline("As you pronounce the formula on it, the scroll disappears.");
88 pline("As you read the scroll, it disappears.");
90 pline("Being confused, you mispronounce the magic words ... ");
92 switch (scroll
->otyp
) {
95 readmail( /* scroll */ );
98 case SCR_ENCHANT_ARMOR
:
100 struct obj
*otmp
= some_armor();
102 strange_feeling(scroll
, "Your skin glows then fades.");
106 pline("Your %s glows silver for a moment.",
107 objects
[otmp
->otyp
].oc_name
);
111 if (otmp
->spe
> 3 && rn2(otmp
->spe
)) {
112 pline("Your %s glows violently green for a while, then evaporates.",
113 objects
[otmp
->otyp
].oc_name
);
117 pline("Your %s glows green for a moment.",
118 objects
[otmp
->otyp
].oc_name
);
123 case SCR_DESTROY_ARMOR
:
125 struct obj
*otmp
= some_armor();
127 strange_feeling(scroll
, "Your bones itch.");
130 pline("Your %s glows purple for a moment.",
131 objects
[otmp
->otyp
].oc_name
);
136 pline("Your armor turns to dust and falls to the floor!");
139 pline("Your helmet turns to dust and is blown away!");
142 pline("Your gloves vanish!");
146 strange_feeling(scroll
, "Your skin itches.");
150 case SCR_CONFUSE_MONSTER
:
152 pline("Your hands begin to glow purple.");
153 Confusion
+= rnd(100);
155 pline("Your hands begin to glow blue.");
159 case SCR_SCARE_MONSTER
:
164 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
165 if (cansee(mtmp
->mx
, mtmp
->my
)) {
167 mtmp
->mflee
= mtmp
->mfroz
=
175 pline("You hear sad wailing in the distance.");
177 pline("You hear maniacal laughter in the distance.");
181 case SCR_BLANK_PAPER
:
183 pline("You see strange patterns on this scroll.");
185 pline("This scroll seems to be blank.");
187 case SCR_REMOVE_CURSE
:
191 pline("You feel like you need some help.");
193 pline("You feel like someone is helping you.");
194 for (obj
= invent
; obj
; obj
= obj
->nobj
)
196 obj
->cursed
= confused
;
197 if (Punished
&& !confused
) {
203 uball
->owornmask
&= ~W_BALL
;
204 uchain
= uball
= (struct obj
*) 0;
208 case SCR_CREATE_MONSTER
:
217 (void) makemon(confused
? PM_ACID_BLOB
:
218 (struct permonst
*) 0, u
.ux
, u
.uy
);
221 case SCR_ENCHANT_WEAPON
:
222 if (uwep
&& confused
) {
223 pline("Your %s glows silver for a moment.",
224 objects
[uwep
->otyp
].oc_name
);
226 } else if (!chwepon(scroll
, 1)) /* tests for !uwep */
229 case SCR_DAMAGE_WEAPON
:
230 if (uwep
&& confused
) {
231 pline("Your %s glows purple for a moment.",
232 objects
[uwep
->otyp
].oc_name
);
234 } else if (!chwepon(scroll
, -1)) /* tests for !uwep */
240 int bd
= confused
? 5 : 1;
243 for (i
= -bd
; i
<= bd
; i
++)
244 for (j
= -bd
; j
<= bd
; j
++)
245 if ((mtmp
= m_at(u
.ux
+ i
, u
.uy
+ j
)) != NULL
)
246 (void) tamedog(mtmp
, (struct obj
*) 0);
252 struct monst
*mtmp
, *mtmp2
;
254 pline("You have found a scroll of genocide!");
260 pline("What monster do you want to genocide (Type the letter)? ");
262 } while (strlen(buf
) != 1 || !monstersym(*buf
));
263 if (!strchr(fut_geno
, *buf
))
264 charcat(fut_geno
, *buf
);
265 if (!strchr(genocided
, *buf
))
266 charcat(genocided
, *buf
);
268 pline("Such monsters do not exist in this world.");
271 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp2
) {
273 if (mtmp
->data
->mlet
== *buf
)
276 pline("Wiped out all %c's.", *buf
);
277 if (*buf
== u
.usym
) {
278 killer
= "scroll of genocide";
288 case SCR_TELEPORTATION
:
293 int oux
= u
.ux
, ouy
= u
.uy
;
295 if (dist(oux
, ouy
) > 100)
298 int uroom
= inroom(u
.ux
, u
.uy
);
300 if (uroom
!= inroom(u
.ux
, u
.uy
))
305 case SCR_GOLD_DETECTION
:
307 * Unfortunately this code has become slightly less elegant,
308 * now that gold and traps no longer are of the same type.
314 strange_feeling(scroll
, "Your toes stop itching.");
317 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
)
318 if (ttmp
->tx
!= u
.ux
|| ttmp
->ty
!= u
.uy
)
321 * only under me - no separate display
324 pline("Your toes itch!");
328 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
)
329 at(ttmp
->tx
, ttmp
->ty
, '$');
331 pline("You feel very greedy!");
337 strange_feeling(scroll
, "You feel materially poor.");
341 for (gtmp
= fgold
; gtmp
; gtmp
= gtmp
->ngold
)
342 if (gtmp
->gx
!= u
.ux
|| gtmp
->gy
!= u
.uy
)
345 * only under me - no separate display
348 pline("You notice some gold between your feet.");
352 for (gtmp
= fgold
; gtmp
; gtmp
= gtmp
->ngold
)
353 at(gtmp
->gx
, gtmp
->gy
, '$');
355 pline("You feel very greedy, and sense gold!");
362 case SCR_FOOD_DETECTION
:
366 char foodsym
= confused
? POTION_SYM
: FOOD_SYM
;
368 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
369 if (obj
->olet
== FOOD_SYM
) {
370 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
376 strange_feeling(scroll
, "Your nose twitches.");
380 pline("You smell %s close nearby.",
381 confused
? "something" : "food");
386 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
387 if (obj
->olet
== foodsym
)
388 at(obj
->ox
, obj
->oy
, FOOD_SYM
);
390 pline("Your nose tingles and you smell %s!",
391 confused
? "something" : "food");
400 pline("You identify this as an identify scroll.");
402 pline("This is an identify scroll.");
404 objects
[SCR_IDENTIFY
].oc_name_known
= 1;
407 !ggetobj("identify", identify
, rn2(5) ? 1 : rn2(5))
411 case SCR_MAGIC_MAPPING
:
417 pline("On this scroll %s a map!",
418 confused
? "was" : "is");
419 for (zy
= 0; zy
< ROWNO
; zy
++)
420 for (zx
= 0; zx
< COLNO
; zx
++) {
421 if (confused
&& rn2(7))
423 lev
= &(levl
[zx
][zy
]);
424 if ((num
= lev
->typ
) == 0)
428 lev
->scrsym
= CORR_SYM
;
429 } else if (num
== SDOOR
) {
432 /* do sth in doors ? */
433 } else if (lev
->seen
)
439 lev
->seen
= lev
->new = 1;
440 if (lev
->scrsym
== ' ' || !lev
->scrsym
)
453 for (zx
= 0; zx
< COLNO
; zx
++)
454 for (zy
= 0; zy
< ROWNO
; zy
++)
455 if (!confused
|| rn2(7))
457 levl
[zx
][zy
].seen
= 0;
459 pline("Thinking of Maud you forget everything else.");
469 pline("The scroll catches fire and you burn your hands.");
470 losehp(1, "scroll of fire");
472 pline("The scroll erupts in a tower of flame!");
474 pline("You are uninjured.");
478 losehp(num
, "scroll of fire");
481 num
= (2 * num
+ 1) / 3;
482 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
483 if (dist(mtmp
->mx
, mtmp
->my
) < 3) {
485 if (strchr("FY", mtmp
->data
->mlet
))
486 mtmp
->mhp
-= 3 * num
; /* this might well kill
490 break; /* primitive */
499 pline("You feel guilty.");
502 pline("You are being punished for your misbehaviour!");
504 pline("Your iron ball gets heavier.");
508 Punished
= INTRINSIC
;
509 setworn(mkobj_at(CHAIN_SYM
, u
.ux
, u
.uy
), W_CHAIN
);
510 setworn(mkobj_at(BALL_SYM
, u
.ux
, u
.uy
), W_BALL
);
511 uball
->spe
= 1; /* special ball (see save) */
514 impossible("What weird language is this written in? (%u)",
517 if (!objects
[scroll
->otyp
].oc_name_known
) {
518 if (known
&& !confused
) {
519 objects
[scroll
->otyp
].oc_name_known
= 1;
520 more_experienced(0, 10);
521 } else if (!objects
[scroll
->otyp
].oc_uname
)
529 identify(struct obj
*otmp
) /* also called by newmail() */
531 objects
[otmp
->otyp
].oc_name_known
= 1;
532 otmp
->known
= otmp
->dknown
= 1;
544 /* first produce the text (provided he is not blind) */
548 if (u
.uswallow
|| !xdnstair
|| levl
[u
.ux
][u
.uy
].typ
== CORR
||
549 !levl
[u
.ux
][u
.uy
].lit
) {
550 pline("It seems even darker in here than before.");
553 pline("It suddenly becomes dark in here.");
556 pline("%s's stomach is lit.", Monnam(u
.ustuck
));
560 pline("Nothing Happens.");
564 pline("The cave lights up around you, then fades.");
567 if (levl
[u
.ux
][u
.uy
].typ
== CORR
) {
568 pline("The corridor lights up around you, then fades.");
570 } else if (levl
[u
.ux
][u
.uy
].lit
) {
571 pline("The light here seems better now.");
574 pline("The room is lit.");
582 if (levl
[u
.ux
][u
.uy
].lit
== on
)
584 if (levl
[u
.ux
][u
.uy
].typ
== DOOR
) {
585 if (IS_ROOM(levl
[u
.ux
][u
.uy
+ 1].typ
))
587 else if (IS_ROOM(levl
[u
.ux
][u
.uy
- 1].typ
))
591 if (IS_ROOM(levl
[u
.ux
+ 1][u
.uy
].typ
))
593 else if (IS_ROOM(levl
[u
.ux
- 1][u
.uy
].typ
))
601 for (seelx
= u
.ux
; (num
= levl
[seelx
- 1][zy
].typ
) != CORR
&& num
!= 0;
603 for (seehx
= u
.ux
; (num
= levl
[seehx
+ 1][zy
].typ
) != CORR
&& num
!= 0;
605 for (seely
= u
.uy
; (num
= levl
[zx
][seely
- 1].typ
) != CORR
&& num
!= 0;
607 for (seehy
= u
.uy
; (num
= levl
[zx
][seehy
+ 1].typ
) != CORR
&& num
!= 0;
609 for (zy
= seely
; zy
<= seehy
; zy
++)
610 for (zx
= seelx
; zx
<= seehx
; zx
++) {
611 levl
[zx
][zy
].lit
= on
;
612 if (!Blind
&& dist(zx
, zy
) > 2) {
624 /* Test whether we may genocide all monsters with symbol ch */
626 monstersym(int ch
) /* arnold@ucsfcgl */
628 const struct permonst
*mp
;
631 * can't genocide certain monsters
633 if (strchr("12 &:", ch
))
636 if (ch
== pm_eel
.mlet
)
638 for (mp
= mons
; mp
< &mons
[CMNUM
+ 2]; mp
++)