1 /* $NetBSD: hack.read.c,v 1.9 2009/06/07 18:30:39 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.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.read.c,v 1.9 2009/06/07 18:30:39 dholland Exp $");
73 static int identify(struct obj
*);
74 static int monstersym(int);
80 boolean confused
= (Confusion
!= 0);
81 boolean known
= FALSE
;
83 scroll
= getobj("?", "read");
86 if (!scroll
->dknown
&& Blind
) {
87 pline("Being blind, you cannot read the formula on the scroll.");
91 pline("As you pronounce the formula on it, the scroll disappears.");
93 pline("As you read the scroll, it disappears.");
95 pline("Being confused, you mispronounce the magic words ... ");
97 switch (scroll
->otyp
) {
100 readmail( /* scroll */ );
103 case SCR_ENCHANT_ARMOR
:
105 struct obj
*otmp
= some_armor();
107 strange_feeling(scroll
, "Your skin glows then fades.");
111 pline("Your %s glows silver for a moment.",
112 objects
[otmp
->otyp
].oc_name
);
116 if (otmp
->spe
> 3 && rn2(otmp
->spe
)) {
117 pline("Your %s glows violently green for a while, then evaporates.",
118 objects
[otmp
->otyp
].oc_name
);
122 pline("Your %s glows green for a moment.",
123 objects
[otmp
->otyp
].oc_name
);
128 case SCR_DESTROY_ARMOR
:
130 struct obj
*otmp
= some_armor();
132 strange_feeling(scroll
, "Your bones itch.");
135 pline("Your %s glows purple for a moment.",
136 objects
[otmp
->otyp
].oc_name
);
141 pline("Your armor turns to dust and falls to the floor!");
144 pline("Your helmet turns to dust and is blown away!");
147 pline("Your gloves vanish!");
151 strange_feeling(scroll
, "Your skin itches.");
155 case SCR_CONFUSE_MONSTER
:
157 pline("Your hands begin to glow purple.");
158 Confusion
+= rnd(100);
160 pline("Your hands begin to glow blue.");
164 case SCR_SCARE_MONSTER
:
169 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
)
170 if (cansee(mtmp
->mx
, mtmp
->my
)) {
172 mtmp
->mflee
= mtmp
->mfroz
=
180 pline("You hear sad wailing in the distance.");
182 pline("You hear maniacal laughter in the distance.");
186 case SCR_BLANK_PAPER
:
188 pline("You see strange patterns on this scroll.");
190 pline("This scroll seems to be blank.");
192 case SCR_REMOVE_CURSE
:
196 pline("You feel like you need some help.");
198 pline("You feel like someone is helping you.");
199 for (obj
= invent
; obj
; obj
= obj
->nobj
)
201 obj
->cursed
= confused
;
202 if (Punished
&& !confused
) {
206 free((char *) uchain
);
208 uball
->owornmask
&= ~W_BALL
;
209 uchain
= uball
= (struct obj
*) 0;
213 case SCR_CREATE_MONSTER
:
222 (void) makemon(confused
? PM_ACID_BLOB
:
223 (struct permonst
*) 0, u
.ux
, u
.uy
);
226 case SCR_ENCHANT_WEAPON
:
227 if (uwep
&& confused
) {
228 pline("Your %s glows silver for a moment.",
229 objects
[uwep
->otyp
].oc_name
);
231 } else if (!chwepon(scroll
, 1)) /* tests for !uwep */
234 case SCR_DAMAGE_WEAPON
:
235 if (uwep
&& confused
) {
236 pline("Your %s glows purple for a moment.",
237 objects
[uwep
->otyp
].oc_name
);
239 } else if (!chwepon(scroll
, -1)) /* tests for !uwep */
245 int bd
= confused
? 5 : 1;
248 for (i
= -bd
; i
<= bd
; i
++)
249 for (j
= -bd
; j
<= bd
; j
++)
250 if ((mtmp
= m_at(u
.ux
+ i
, u
.uy
+ j
)) != NULL
)
251 (void) tamedog(mtmp
, (struct obj
*) 0);
257 struct monst
*mtmp
, *mtmp2
;
259 pline("You have found a scroll of genocide!");
265 pline("What monster do you want to genocide (Type the letter)? ");
267 } while (strlen(buf
) != 1 || !monstersym(*buf
));
268 if (!strchr(fut_geno
, *buf
))
269 charcat(fut_geno
, *buf
);
270 if (!strchr(genocided
, *buf
))
271 charcat(genocided
, *buf
);
273 pline("Such monsters do not exist in this world.");
276 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp2
) {
278 if (mtmp
->data
->mlet
== *buf
)
281 pline("Wiped out all %c's.", *buf
);
282 if (*buf
== u
.usym
) {
283 killer
= "scroll of genocide";
293 case SCR_TELEPORTATION
:
298 int oux
= u
.ux
, ouy
= u
.uy
;
300 if (dist(oux
, ouy
) > 100)
303 int uroom
= inroom(u
.ux
, u
.uy
);
305 if (uroom
!= inroom(u
.ux
, u
.uy
))
310 case SCR_GOLD_DETECTION
:
312 * Unfortunately this code has become slightly less elegant,
313 * now that gold and traps no longer are of the same type.
319 strange_feeling(scroll
, "Your toes stop itching.");
322 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
)
323 if (ttmp
->tx
!= u
.ux
|| ttmp
->ty
!= u
.uy
)
326 * only under me - no separate display
329 pline("Your toes itch!");
333 for (ttmp
= ftrap
; ttmp
; ttmp
= ttmp
->ntrap
)
334 at(ttmp
->tx
, ttmp
->ty
, '$');
336 pline("You feel very greedy!");
342 strange_feeling(scroll
, "You feel materially poor.");
346 for (gtmp
= fgold
; gtmp
; gtmp
= gtmp
->ngold
)
347 if (gtmp
->gx
!= u
.ux
|| gtmp
->gy
!= u
.uy
)
350 * only under me - no separate display
353 pline("You notice some gold between your feet.");
357 for (gtmp
= fgold
; gtmp
; gtmp
= gtmp
->ngold
)
358 at(gtmp
->gx
, gtmp
->gy
, '$');
360 pline("You feel very greedy, and sense gold!");
367 case SCR_FOOD_DETECTION
:
371 char foodsym
= confused
? POTION_SYM
: FOOD_SYM
;
373 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
374 if (obj
->olet
== FOOD_SYM
) {
375 if (obj
->ox
== u
.ux
&& obj
->oy
== u
.uy
)
381 strange_feeling(scroll
, "Your nose twitches.");
385 pline("You smell %s close nearby.",
386 confused
? "something" : "food");
391 for (obj
= fobj
; obj
; obj
= obj
->nobj
)
392 if (obj
->olet
== foodsym
)
393 at(obj
->ox
, obj
->oy
, FOOD_SYM
);
395 pline("Your nose tingles and you smell %s!",
396 confused
? "something" : "food");
405 pline("You identify this as an identify scroll.");
407 pline("This is an identify scroll.");
409 objects
[SCR_IDENTIFY
].oc_name_known
= 1;
412 !ggetobj("identify", identify
, rn2(5) ? 1 : rn2(5))
416 case SCR_MAGIC_MAPPING
:
422 pline("On this scroll %s a map!",
423 confused
? "was" : "is");
424 for (zy
= 0; zy
< ROWNO
; zy
++)
425 for (zx
= 0; zx
< COLNO
; zx
++) {
426 if (confused
&& rn2(7))
428 lev
= &(levl
[zx
][zy
]);
429 if ((num
= lev
->typ
) == 0)
433 lev
->scrsym
= CORR_SYM
;
434 } else if (num
== SDOOR
) {
437 /* do sth in doors ? */
438 } else if (lev
->seen
)
444 lev
->seen
= lev
->new = 1;
445 if (lev
->scrsym
== ' ' || !lev
->scrsym
)
458 for (zx
= 0; zx
< COLNO
; zx
++)
459 for (zy
= 0; zy
< ROWNO
; zy
++)
460 if (!confused
|| rn2(7))
462 levl
[zx
][zy
].seen
= 0;
464 pline("Thinking of Maud you forget everything else.");
474 pline("The scroll catches fire and you burn your hands.");
475 losehp(1, "scroll of fire");
477 pline("The scroll erupts in a tower of flame!");
479 pline("You are uninjured.");
483 losehp(num
, "scroll of fire");
486 num
= (2 * num
+ 1) / 3;
487 for (mtmp
= fmon
; mtmp
; mtmp
= mtmp
->nmon
) {
488 if (dist(mtmp
->mx
, mtmp
->my
) < 3) {
490 if (strchr("FY", mtmp
->data
->mlet
))
491 mtmp
->mhp
-= 3 * num
; /* this might well kill
495 break; /* primitive */
504 pline("You feel guilty.");
507 pline("You are being punished for your misbehaviour!");
509 pline("Your iron ball gets heavier.");
513 Punished
= INTRINSIC
;
514 setworn(mkobj_at(CHAIN_SYM
, u
.ux
, u
.uy
), W_CHAIN
);
515 setworn(mkobj_at(BALL_SYM
, u
.ux
, u
.uy
), W_BALL
);
516 uball
->spe
= 1; /* special ball (see save) */
519 impossible("What weird language is this written in? (%u)",
522 if (!objects
[scroll
->otyp
].oc_name_known
) {
523 if (known
&& !confused
) {
524 objects
[scroll
->otyp
].oc_name_known
= 1;
525 more_experienced(0, 10);
526 } else if (!objects
[scroll
->otyp
].oc_uname
)
534 identify(struct obj
*otmp
) /* also called by newmail() */
536 objects
[otmp
->otyp
].oc_name_known
= 1;
537 otmp
->known
= otmp
->dknown
= 1;
549 /* first produce the text (provided he is not blind) */
553 if (u
.uswallow
|| !xdnstair
|| levl
[u
.ux
][u
.uy
].typ
== CORR
||
554 !levl
[u
.ux
][u
.uy
].lit
) {
555 pline("It seems even darker in here than before.");
558 pline("It suddenly becomes dark in here.");
561 pline("%s's stomach is lit.", Monnam(u
.ustuck
));
565 pline("Nothing Happens.");
569 pline("The cave lights up around you, then fades.");
572 if (levl
[u
.ux
][u
.uy
].typ
== CORR
) {
573 pline("The corridor lights up around you, then fades.");
575 } else if (levl
[u
.ux
][u
.uy
].lit
) {
576 pline("The light here seems better now.");
579 pline("The room is lit.");
587 if (levl
[u
.ux
][u
.uy
].lit
== on
)
589 if (levl
[u
.ux
][u
.uy
].typ
== DOOR
) {
590 if (IS_ROOM(levl
[u
.ux
][u
.uy
+ 1].typ
))
592 else if (IS_ROOM(levl
[u
.ux
][u
.uy
- 1].typ
))
596 if (IS_ROOM(levl
[u
.ux
+ 1][u
.uy
].typ
))
598 else if (IS_ROOM(levl
[u
.ux
- 1][u
.uy
].typ
))
606 for (seelx
= u
.ux
; (num
= levl
[seelx
- 1][zy
].typ
) != CORR
&& num
!= 0;
608 for (seehx
= u
.ux
; (num
= levl
[seehx
+ 1][zy
].typ
) != CORR
&& num
!= 0;
610 for (seely
= u
.uy
; (num
= levl
[zx
][seely
- 1].typ
) != CORR
&& num
!= 0;
612 for (seehy
= u
.uy
; (num
= levl
[zx
][seehy
+ 1].typ
) != CORR
&& num
!= 0;
614 for (zy
= seely
; zy
<= seehy
; zy
++)
615 for (zx
= seelx
; zx
<= seehx
; zx
++) {
616 levl
[zx
][zy
].lit
= on
;
617 if (!Blind
&& dist(zx
, zy
) > 2) {
629 /* Test whether we may genocide all monsters with symbol ch */
631 monstersym(int ch
) /* arnold@ucsfcgl */
633 const struct permonst
*mp
;
636 * can't genocide certain monsters
638 if (strchr("12 &:", ch
))
641 if (ch
== pm_eel
.mlet
)
643 for (mp
= mons
; mp
< &mons
[CMNUM
+ 2]; mp
++)