1 /* $NetBSD: hack.trap.c,v 1.8 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.trap.c,v 1.8 2009/06/07 18:30:39 dholland Exp $");
72 #include "def.mkroom.h"
74 const char vowels
[] = "aeiou";
76 const char *const traps
[] = {
81 " teleportation trap",
88 static void vtele(void);
89 static void teleds(int, int);
90 static int teleok(int, int);
93 maketrap(int x
, int y
, int typ
)
109 dotrap(struct trap
*trap
)
111 int ttype
= trap
->ttyp
;
114 if (trap
->tseen
&& !rn2(5) && ttype
!= PIT
)
115 pline("You escape a%s.", traps
[ttype
]);
120 pline("A cloud of gas puts you to sleep!");
125 pline("You float over a bear trap.");
128 u
.utrap
= 4 + rn2(4);
129 u
.utraptype
= TT_BEARTRAP
;
130 pline("A bear trap closes on your foot!");
134 if (makemon(PM_PIERCER
, u
.ux
, u
.uy
)) {
135 pline("A piercer suddenly drops from the ceiling!");
137 pline("Its blow glances off your helmet.");
139 (void) thitu(3, d(4, 6), "falling piercer");
143 pline("An arrow shoots out at you!");
144 if (!thitu(8, rnd(6), "arrow")) {
145 mksobj_at(ARROW
, u
.ux
, u
.uy
);
151 pline("A trap door in the ceiling opens and a rock falls on your head!");
153 pline("Fortunately, you are wearing a helmet!");
154 losehp(uarmh
? 2 : d(2, 10), "falling rock");
155 mksobj_at(ROCK
, u
.ux
, u
.uy
);
161 int newlevel
= dlevel
+ 1;
162 while (!rn2(4) && newlevel
< 29)
164 pline("A trap door opens up under you!");
165 if (Levitation
|| u
.ustuck
) {
166 pline("For some reason you don't fall in.");
169 goto_level(newlevel
, FALSE
);
173 pline("A little dart shoots out at you!");
174 if (thitu(7, rnd(3), "little dart")) {
176 poisoned("dart", "poison dart");
178 mksobj_at(DART
, u
.ux
, u
.uy
);
194 pline("A pit opens up under you!");
195 pline("You don't fall in!");
198 pline("You fall into a pit!");
200 u
.utraptype
= TT_PIT
;
201 losehp(rnd(6), "fall into a pit");
202 selftouch("Falling, you");
205 impossible("You hit a trap of type %u", trap
->ttyp
);
211 mintrap(struct monst
*mtmp
)
213 struct trap
*trap
= t_at(mtmp
->mx
, mtmp
->my
);
214 int wasintrap
= mtmp
->mtrapped
;
217 mtmp
->mtrapped
= 0; /* perhaps teleported? */
218 } else if (wasintrap
) {
223 int in_sight
= cansee(mtmp
->mx
, mtmp
->my
);
225 if (mtmp
->mtrapseen
& (1 << tt
)) {
226 /* he has been in such a trap - perhaps he escapes */
230 mtmp
->mtrapseen
|= (1 << tt
);
233 if (strchr(mlarge
, mtmp
->data
->mlet
)) {
235 pline("%s is caught in a bear trap!",
237 else if (mtmp
->data
->mlet
== 'o')
238 pline("You hear the roaring of an angry bear!");
243 /* there should be a mtmp/data -> floating */
244 if (!strchr("EywBfk'& ", mtmp
->data
->mlet
)) { /* ab */
247 pline("%s falls in a pit!", Monnam(mtmp
));
251 if (!mtmp
->msleep
&& !mtmp
->mfroz
) {
254 pline("%s suddenly falls asleep!",
260 if (in_sight
&& !cansee(mtmp
->mx
, mtmp
->my
))
261 pline("%s suddenly disappears!",
266 pline("%s is hit by an arrow!",
273 pline("%s is hit by a dart!",
277 /* not mondied here !! */
283 pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp
));
286 if (mtmp
->data
->mlet
!= 'w') {
289 pline("Suddenly, %s disappears out of sight.", monnam(mtmp
));
290 return (2); /* no longer on this level */
296 impossible("Some monster encountered a strange trap.");
299 return (mtmp
->mtrapped
);
303 selftouch(const char *arg
)
305 if (uwep
&& uwep
->otyp
== DEAD_COCKATRICE
) {
306 pline("%s touch the dead cockatrice.", arg
);
307 pline("You turn to stone.");
308 killer
= objects
[uwep
->otyp
].oc_name
;
317 if (u
.utraptype
== TT_PIT
) {
319 pline("You float up, out of the pit!");
321 pline("You float up, only your leg is still stuck.");
324 pline("You start to float in the air!");
331 pline("You float gently to the ground.");
332 if ((trap
= t_at(u
.ux
, u
.uy
)) != NULL
)
333 switch (trap
->ttyp
) {
337 if (!xdnstair
|| u
.ustuck
)
339 /* fall into next case */
349 struct mkroom
*croom
;
350 for (croom
= &rooms
[0]; croom
->hx
>= 0; croom
++)
351 if (croom
->rtype
== VAULT
) {
354 x
= rn2(2) ? croom
->lx
: croom
->hx
;
355 y
= rn2(2) ? croom
->ly
: croom
->hy
;
370 if (Teleport_control
) {
371 pline("To what position do you want to be teleported?");
372 cc
= getpos(1, "the desired position"); /* 1: force valid */
374 * possible extensions: introduce a small error if magic
375 * power is low; allow transfer to solid rock
377 if (teleok(cc
.x
, cc
.y
)) {
384 nux
= rnd(COLNO
- 1);
386 } while (!teleok(nux
, nuy
));
391 teleds(int nux
, int nuy
)
404 u
.uswldtim
= u
.uswallow
= 0;
408 if (levl
[nux
][nuy
].typ
== POOL
&& !Levitation
)
413 read_engr_at(u
.ux
, u
.uy
);
418 { /* might throw him into a POOL */
419 return (isok(x
, y
) && !IS_ROCK(levl
[x
][y
].typ
) && !m_at(x
, y
) &&
420 !sobj_at(ENORMOUS_ROCK
, x
, y
) && !t_at(x
, y
)
422 /* Note: gold is permitted (because of vaults) */
432 (!Teleportation
|| u
.ulevel
< 6 ||
433 (pl_character
[0] != 'W' && u
.ulevel
< 10))) {
434 pline("You are not able to teleport at will.");
437 if (u
.uhunger
<= 100 || u
.ustr
< 6) {
438 pline("You miss the strength for a teleport spell.");
449 if (!uchain
|| !uball
) {
450 impossible("Where are your chain and ball??");
453 uball
->ox
= uchain
->ox
= u
.ux
;
454 uball
->oy
= uchain
->oy
= u
.uy
;
458 if (!carried(uball
)) {
468 if (!carried(uball
)) {
480 if (Teleport_control
) {
484 pline("To what level do you want to teleport? [type a number] ");
486 } while (!digit(buf
[0]) && (buf
[0] != '-' || !digit(buf
[1])));
487 newlevel
= atoi(buf
);
489 newlevel
= 5 + rn2(20); /* 5 - 24 */
490 if (dlevel
== newlevel
) {
497 if (newlevel
>= 30) {
498 if (newlevel
> MAXLEVEL
)
500 pline("You arrive at the center of the earth ...");
501 pline("Unfortunately it is here that hell is located.");
502 if (Fire_resistance
) {
503 pline("But the fire doesn't seem to harm you.");
505 pline("You burn to a crisp.");
506 dlevel
= maxdlevel
= newlevel
;
507 killer
= "visit to the hell";
513 pline("You are now high above the clouds ...");
515 pline("You float gently down to earth.");
518 pline("Unfortunately, you don't know how to fly.");
519 pline("You fall down a few thousand feet and break your neck.");
524 goto_level(newlevel
, FALSE
); /* calls done("escaped") if
531 pline("You fall into a pool!");
532 pline("You can't swim!");
533 if (rn2(3) < u
.uluck
+ 2) {
534 /* most scrolls become unreadable */
537 for (obj
= invent
; obj
; obj
= obj
->nobj
)
538 if (obj
->olet
== SCROLL_SYM
&& rn2(12) > u
.uluck
)
539 obj
->otyp
= SCR_BLANK_PAPER
;
540 /* we should perhaps merge these scrolls ? */
542 pline("You attempt a teleport spell."); /* utcsri!carroll */
544 if (levl
[u
.ux
][u
.uy
].typ
!= POOL
)
547 pline("You drown ...");
548 killer
= "pool of water";