Sort supported hardware by name.
[netbsd-mini2440.git] / games / hack / hack.read.c
blob16d263f87f5fbaf6e55432f456434a49da4282f2
1 /* $NetBSD: hack.read.c,v 1.8 2003/04/02 18:36:39 jsm Exp $ */
3 /*
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5 * Amsterdam
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
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
22 * written permission.
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
43 * are met:
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>
65 #ifndef lint
66 __RCSID("$NetBSD: hack.read.c,v 1.8 2003/04/02 18:36:39 jsm Exp $");
67 #endif /* not lint */
69 #include <stdlib.h>
70 #include "hack.h"
71 #include "extern.h"
73 int
74 doread(void)
76 struct obj *scroll;
77 boolean confused = (Confusion != 0);
78 boolean known = FALSE;
80 scroll = getobj("?", "read");
81 if (!scroll)
82 return (0);
83 if (!scroll->dknown && Blind) {
84 pline("Being blind, you cannot read the formula on the scroll.");
85 return (0);
87 if (Blind)
88 pline("As you pronounce the formula on it, the scroll disappears.");
89 else
90 pline("As you read the scroll, it disappears.");
91 if (confused)
92 pline("Being confused, you mispronounce the magic words ... ");
94 switch (scroll->otyp) {
95 #ifdef MAIL
96 case SCR_MAIL:
97 readmail( /* scroll */ );
98 break;
99 #endif /* MAIL */
100 case SCR_ENCHANT_ARMOR:
102 struct obj *otmp = some_armor();
103 if (!otmp) {
104 strange_feeling(scroll, "Your skin glows then fades.");
105 return (1);
107 if (confused) {
108 pline("Your %s glows silver for a moment.",
109 objects[otmp->otyp].oc_name);
110 otmp->rustfree = 1;
111 break;
113 if (otmp->spe > 3 && rn2(otmp->spe)) {
114 pline("Your %s glows violently green for a while, then evaporates.",
115 objects[otmp->otyp].oc_name);
116 useup(otmp);
117 break;
119 pline("Your %s glows green for a moment.",
120 objects[otmp->otyp].oc_name);
121 otmp->cursed = 0;
122 otmp->spe++;
123 break;
125 case SCR_DESTROY_ARMOR:
126 if (confused) {
127 struct obj *otmp = some_armor();
128 if (!otmp) {
129 strange_feeling(scroll, "Your bones itch.");
130 return (1);
132 pline("Your %s glows purple for a moment.",
133 objects[otmp->otyp].oc_name);
134 otmp->rustfree = 0;
135 break;
137 if (uarm) {
138 pline("Your armor turns to dust and falls to the floor!");
139 useup(uarm);
140 } else if (uarmh) {
141 pline("Your helmet turns to dust and is blown away!");
142 useup(uarmh);
143 } else if (uarmg) {
144 pline("Your gloves vanish!");
145 useup(uarmg);
146 selftouch("You");
147 } else {
148 strange_feeling(scroll, "Your skin itches.");
149 return (1);
151 break;
152 case SCR_CONFUSE_MONSTER:
153 if (confused) {
154 pline("Your hands begin to glow purple.");
155 Confusion += rnd(100);
156 } else {
157 pline("Your hands begin to glow blue.");
158 u.umconf = 1;
160 break;
161 case SCR_SCARE_MONSTER:
163 int ct = 0;
164 struct monst *mtmp;
166 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
167 if (cansee(mtmp->mx, mtmp->my)) {
168 if (confused)
169 mtmp->mflee = mtmp->mfroz =
170 mtmp->msleep = 0;
171 else
172 mtmp->mflee = 1;
173 ct++;
175 if (!ct) {
176 if (confused)
177 pline("You hear sad wailing in the distance.");
178 else
179 pline("You hear maniacal laughter in the distance.");
181 break;
183 case SCR_BLANK_PAPER:
184 if (confused)
185 pline("You see strange patterns on this scroll.");
186 else
187 pline("This scroll seems to be blank.");
188 break;
189 case SCR_REMOVE_CURSE:
191 struct obj *obj;
192 if (confused)
193 pline("You feel like you need some help.");
194 else
195 pline("You feel like someone is helping you.");
196 for (obj = invent; obj; obj = obj->nobj)
197 if (obj->owornmask)
198 obj->cursed = confused;
199 if (Punished && !confused) {
200 Punished = 0;
201 freeobj(uchain);
202 unpobj(uchain);
203 free((char *) uchain);
204 uball->spe = 0;
205 uball->owornmask &= ~W_BALL;
206 uchain = uball = (struct obj *) 0;
208 break;
210 case SCR_CREATE_MONSTER:
212 int cnt = 1;
214 if (!rn2(73))
215 cnt += rnd(4);
216 if (confused)
217 cnt += 12;
218 while (cnt--)
219 (void) makemon(confused ? PM_ACID_BLOB :
220 (struct permonst *) 0, u.ux, u.uy);
221 break;
223 case SCR_ENCHANT_WEAPON:
224 if (uwep && confused) {
225 pline("Your %s glows silver for a moment.",
226 objects[uwep->otyp].oc_name);
227 uwep->rustfree = 1;
228 } else if (!chwepon(scroll, 1)) /* tests for !uwep */
229 return (1);
230 break;
231 case SCR_DAMAGE_WEAPON:
232 if (uwep && confused) {
233 pline("Your %s glows purple for a moment.",
234 objects[uwep->otyp].oc_name);
235 uwep->rustfree = 0;
236 } else if (!chwepon(scroll, -1)) /* tests for !uwep */
237 return (1);
238 break;
239 case SCR_TAMING:
241 int i, j;
242 int bd = confused ? 5 : 1;
243 struct monst *mtmp;
245 for (i = -bd; i <= bd; i++)
246 for (j = -bd; j <= bd; j++)
247 if ((mtmp = m_at(u.ux + i, u.uy + j)) != NULL)
248 (void) tamedog(mtmp, (struct obj *) 0);
249 break;
251 case SCR_GENOCIDE:
253 char buf[BUFSZ];
254 struct monst *mtmp, *mtmp2;
256 pline("You have found a scroll of genocide!");
257 known = TRUE;
258 if (confused)
259 *buf = u.usym;
260 else
261 do {
262 pline("What monster do you want to genocide (Type the letter)? ");
263 getlin(buf);
264 } while (strlen(buf) != 1 || !monstersym(*buf));
265 if (!strchr(fut_geno, *buf))
266 charcat(fut_geno, *buf);
267 if (!strchr(genocided, *buf))
268 charcat(genocided, *buf);
269 else {
270 pline("Such monsters do not exist in this world.");
271 break;
273 for (mtmp = fmon; mtmp; mtmp = mtmp2) {
274 mtmp2 = mtmp->nmon;
275 if (mtmp->data->mlet == *buf)
276 mondead(mtmp);
278 pline("Wiped out all %c's.", *buf);
279 if (*buf == u.usym) {
280 killer = "scroll of genocide";
281 u.uhp = -1;
283 break;
285 case SCR_LIGHT:
286 if (!Blind)
287 known = TRUE;
288 litroom(!confused);
289 break;
290 case SCR_TELEPORTATION:
291 if (confused)
292 level_tele();
293 else {
294 #ifdef QUEST
295 int oux = u.ux, ouy = u.uy;
296 tele();
297 if (dist(oux, ouy) > 100)
298 known = TRUE;
299 #else /* QUEST */
300 int uroom = inroom(u.ux, u.uy);
301 tele();
302 if (uroom != inroom(u.ux, u.uy))
303 known = TRUE;
304 #endif /* QUEST */
306 break;
307 case SCR_GOLD_DETECTION:
309 * Unfortunately this code has become slightly less elegant,
310 * now that gold and traps no longer are of the same type.
312 if (confused) {
313 struct trap *ttmp;
315 if (!ftrap) {
316 strange_feeling(scroll, "Your toes stop itching.");
317 return (1);
318 } else {
319 for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
320 if (ttmp->tx != u.ux || ttmp->ty != u.uy)
321 goto outtrapmap;
323 * only under me - no separate display
324 * required
326 pline("Your toes itch!");
327 break;
328 outtrapmap:
329 cls();
330 for (ttmp = ftrap; ttmp; ttmp = ttmp->ntrap)
331 at(ttmp->tx, ttmp->ty, '$');
332 prme();
333 pline("You feel very greedy!");
335 } else {
336 struct gold *gtmp;
338 if (!fgold) {
339 strange_feeling(scroll, "You feel materially poor.");
340 return (1);
341 } else {
342 known = TRUE;
343 for (gtmp = fgold; gtmp; gtmp = gtmp->ngold)
344 if (gtmp->gx != u.ux || gtmp->gy != u.uy)
345 goto outgoldmap;
347 * only under me - no separate display
348 * required
350 pline("You notice some gold between your feet.");
351 break;
352 outgoldmap:
353 cls();
354 for (gtmp = fgold; gtmp; gtmp = gtmp->ngold)
355 at(gtmp->gx, gtmp->gy, '$');
356 prme();
357 pline("You feel very greedy, and sense gold!");
360 /* common sequel */
361 more();
362 docrt();
363 break;
364 case SCR_FOOD_DETECTION:
366 int ct = 0, ctu = 0;
367 struct obj *obj;
368 char foodsym = confused ? POTION_SYM : FOOD_SYM;
370 for (obj = fobj; obj; obj = obj->nobj)
371 if (obj->olet == FOOD_SYM) {
372 if (obj->ox == u.ux && obj->oy == u.uy)
373 ctu++;
374 else
375 ct++;
377 if (!ct && !ctu) {
378 strange_feeling(scroll, "Your nose twitches.");
379 return (1);
380 } else if (!ct) {
381 known = TRUE;
382 pline("You smell %s close nearby.",
383 confused ? "something" : "food");
385 } else {
386 known = TRUE;
387 cls();
388 for (obj = fobj; obj; obj = obj->nobj)
389 if (obj->olet == foodsym)
390 at(obj->ox, obj->oy, FOOD_SYM);
391 prme();
392 pline("Your nose tingles and you smell %s!",
393 confused ? "something" : "food");
394 more();
395 docrt();
397 break;
399 case SCR_IDENTIFY:
400 /* known = TRUE; */
401 if (confused)
402 pline("You identify this as an identify scroll.");
403 else
404 pline("This is an identify scroll.");
405 useup(scroll);
406 objects[SCR_IDENTIFY].oc_name_known = 1;
407 if (!confused)
408 while (
409 !ggetobj("identify", identify, rn2(5) ? 1 : rn2(5))
410 && invent
412 return (1);
413 case SCR_MAGIC_MAPPING:
415 struct rm *lev;
416 int num, zx, zy;
418 known = TRUE;
419 pline("On this scroll %s a map!",
420 confused ? "was" : "is");
421 for (zy = 0; zy < ROWNO; zy++)
422 for (zx = 0; zx < COLNO; zx++) {
423 if (confused && rn2(7))
424 continue;
425 lev = &(levl[zx][zy]);
426 if ((num = lev->typ) == 0)
427 continue;
428 if (num == SCORR) {
429 lev->typ = CORR;
430 lev->scrsym = CORR_SYM;
431 } else if (num == SDOOR) {
432 lev->typ = DOOR;
433 lev->scrsym = '+';
434 /* do sth in doors ? */
435 } else if (lev->seen)
436 continue;
437 #ifndef QUEST
438 if (num != ROOM)
439 #endif /* QUEST */
441 lev->seen = lev->new = 1;
442 if (lev->scrsym == ' ' || !lev->scrsym)
443 newsym(zx, zy);
444 else
445 on_scr(zx, zy);
448 break;
450 case SCR_AMNESIA:
452 int zx, zy;
454 known = TRUE;
455 for (zx = 0; zx < COLNO; zx++)
456 for (zy = 0; zy < ROWNO; zy++)
457 if (!confused || rn2(7))
458 if (!cansee(zx, zy))
459 levl[zx][zy].seen = 0;
460 docrt();
461 pline("Thinking of Maud you forget everything else.");
462 break;
464 case SCR_FIRE:
466 int num = 0;
467 struct monst *mtmp;
469 known = TRUE;
470 if (confused) {
471 pline("The scroll catches fire and you burn your hands.");
472 losehp(1, "scroll of fire");
473 } else {
474 pline("The scroll erupts in a tower of flame!");
475 if (Fire_resistance)
476 pline("You are uninjured.");
477 else {
478 num = rnd(6);
479 u.uhpmax -= num;
480 losehp(num, "scroll of fire");
483 num = (2 * num + 1) / 3;
484 for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
485 if (dist(mtmp->mx, mtmp->my) < 3) {
486 mtmp->mhp -= num;
487 if (strchr("FY", mtmp->data->mlet))
488 mtmp->mhp -= 3 * num; /* this might well kill
489 * 'F's */
490 if (mtmp->mhp < 1) {
491 killed(mtmp);
492 break; /* primitive */
496 break;
498 case SCR_PUNISHMENT:
499 known = TRUE;
500 if (confused) {
501 pline("You feel guilty.");
502 break;
504 pline("You are being punished for your misbehaviour!");
505 if (Punished) {
506 pline("Your iron ball gets heavier.");
507 uball->owt += 15;
508 break;
510 Punished = INTRINSIC;
511 setworn(mkobj_at(CHAIN_SYM, u.ux, u.uy), W_CHAIN);
512 setworn(mkobj_at(BALL_SYM, u.ux, u.uy), W_BALL);
513 uball->spe = 1; /* special ball (see save) */
514 break;
515 default:
516 impossible("What weird language is this written in? (%u)",
517 scroll->otyp);
519 if (!objects[scroll->otyp].oc_name_known) {
520 if (known && !confused) {
521 objects[scroll->otyp].oc_name_known = 1;
522 more_experienced(0, 10);
523 } else if (!objects[scroll->otyp].oc_uname)
524 docall(scroll);
526 useup(scroll);
527 return (1);
531 identify(struct obj *otmp) /* also called by newmail() */
533 objects[otmp->otyp].oc_name_known = 1;
534 otmp->known = otmp->dknown = 1;
535 prinv(otmp);
536 return (1);
539 void
540 litroom(boolean on)
542 #ifndef QUEST
543 int num, zx, zy;
544 #endif
546 /* first produce the text (provided he is not blind) */
547 if (Blind)
548 goto do_it;
549 if (!on) {
550 if (u.uswallow || !xdnstair || levl[u.ux][u.uy].typ == CORR ||
551 !levl[u.ux][u.uy].lit) {
552 pline("It seems even darker in here than before.");
553 return;
554 } else
555 pline("It suddenly becomes dark in here.");
556 } else {
557 if (u.uswallow) {
558 pline("%s's stomach is lit.", Monnam(u.ustuck));
559 return;
561 if (!xdnstair) {
562 pline("Nothing Happens.");
563 return;
565 #ifdef QUEST
566 pline("The cave lights up around you, then fades.");
567 return;
568 #else /* QUEST */
569 if (levl[u.ux][u.uy].typ == CORR) {
570 pline("The corridor lights up around you, then fades.");
571 return;
572 } else if (levl[u.ux][u.uy].lit) {
573 pline("The light here seems better now.");
574 return;
575 } else
576 pline("The room is lit.");
577 #endif /* QUEST */
580 do_it:
581 #ifdef QUEST
582 return;
583 #else /* QUEST */
584 if (levl[u.ux][u.uy].lit == on)
585 return;
586 if (levl[u.ux][u.uy].typ == DOOR) {
587 if (IS_ROOM(levl[u.ux][u.uy + 1].typ))
588 zy = u.uy + 1;
589 else if (IS_ROOM(levl[u.ux][u.uy - 1].typ))
590 zy = u.uy - 1;
591 else
592 zy = u.uy;
593 if (IS_ROOM(levl[u.ux + 1][u.uy].typ))
594 zx = u.ux + 1;
595 else if (IS_ROOM(levl[u.ux - 1][u.uy].typ))
596 zx = u.ux - 1;
597 else
598 zx = u.ux;
599 } else {
600 zx = u.ux;
601 zy = u.uy;
603 for (seelx = u.ux; (num = levl[seelx - 1][zy].typ) != CORR && num != 0;
604 seelx--);
605 for (seehx = u.ux; (num = levl[seehx + 1][zy].typ) != CORR && num != 0;
606 seehx++);
607 for (seely = u.uy; (num = levl[zx][seely - 1].typ) != CORR && num != 0;
608 seely--);
609 for (seehy = u.uy; (num = levl[zx][seehy + 1].typ) != CORR && num != 0;
610 seehy++);
611 for (zy = seely; zy <= seehy; zy++)
612 for (zx = seelx; zx <= seehx; zx++) {
613 levl[zx][zy].lit = on;
614 if (!Blind && dist(zx, zy) > 2) {
615 if (on)
616 prl(zx, zy);
617 else
618 nosee(zx, zy);
621 if (!on)
622 seehx = 0;
623 #endif /* QUEST */
626 /* Test whether we may genocide all monsters with symbol ch */
628 monstersym(int ch) /* arnold@ucsfcgl */
630 const struct permonst *mp;
633 * can't genocide certain monsters
635 if (strchr("12 &:", ch))
636 return FALSE;
638 if (ch == pm_eel.mlet)
639 return TRUE;
640 for (mp = mons; mp < &mons[CMNUM + 2]; mp++)
641 if (mp->mlet == ch)
642 return TRUE;
643 return FALSE;