1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.trap.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.trap.c,v 1.5 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.trap.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
8 char vowels
[] = "aeiou";
10 const char *traps
[] = {
15 " teleportation trap",
22 static void vtele(void);
23 static void teleds(int, int);
24 static bool teleok(int, int);
27 maketrap(int x
, int y
, int typ
)
43 dotrap(struct trap
*trap
)
45 int ttype
= trap
->ttyp
;
48 if (trap
->tseen
&& !rn2(5) && ttype
!= PIT
)
49 pline("You escape a%s.", traps
[ttype
]);
54 pline("A cloud of gas puts you to sleep!");
59 pline("You float over a bear trap.");
63 u
.utraptype
= TT_BEARTRAP
;
64 pline("A bear trap closes on your foot!");
68 if (makemon(PM_PIERCER
, u
.ux
, u
.uy
)) {
69 pline("A piercer suddenly drops from the ceiling!");
71 pline("Its blow glances off your helmet.");
73 thitu(3, d(4, 6), "falling piercer");
77 pline("An arrow shoots out at you!");
78 if (!thitu(8, rnd(6), "arrow")) {
79 mksobj_at(ARROW
, u
.ux
, u
.uy
);
85 pline("A trap door in the ceiling opens and a rock falls on your head!");
87 pline("Fortunately, you are wearing a helmet!");
88 losehp(uarmh
? 2 : d(2, 10), "falling rock");
89 mksobj_at(ROCK
, u
.ux
, u
.uy
);
95 int newlevel
= dlevel
+ 1;
96 while (!rn2(4) && newlevel
< 29)
98 pline("A trap door opens up under you!");
99 if (Levitation
|| u
.ustuck
) {
100 pline("For some reason you don't fall in.");
104 goto_level(newlevel
, FALSE
);
108 pline("A little dart shoots out at you!");
109 if (thitu(7, rnd(3), "little dart")) {
111 poisoned("dart", "poison dart");
113 mksobj_at(DART
, u
.ux
, u
.uy
);
129 pline("A pit opens up under you!");
130 pline("You don't fall in!");
133 pline("You fall into a pit!");
135 u
.utraptype
= TT_PIT
;
136 losehp(rnd(6), "fall into a pit");
137 selftouch("Falling, you");
140 impossible("You hit a trap of type %u", trap
->ttyp
);
146 mintrap(struct monst
*mtmp
)
148 struct trap
*trap
= t_at(mtmp
->mx
, mtmp
->my
);
149 int wasintrap
= mtmp
->mtrapped
;
152 mtmp
->mtrapped
= 0; /* perhaps teleported? */
153 else if (wasintrap
) {
158 int in_sight
= cansee(mtmp
->mx
, mtmp
->my
);
160 if (mtmp
->mtrapseen
& (1 << tt
)) {
161 /* he has been in such a trap - perhaps he escapes */
165 mtmp
->mtrapseen
|= (1 << tt
);
168 if (strchr(mlarge
, mtmp
->data
->mlet
)) {
170 pline("%s is caught in a bear trap!",
172 else if (mtmp
->data
->mlet
== 'o')
173 pline("You hear the roaring of an angry bear!");
178 /* there should be a mtmp/data -> floating */
179 if (!strchr("EywBfk'& ", mtmp
->data
->mlet
)) { /* ab */
182 pline("%s falls in a pit!", Monnam(mtmp
));
186 if (!mtmp
->msleep
&& !mtmp
->mfroz
) {
189 pline("%s suddenly falls asleep!",
195 if (in_sight
&& !cansee(mtmp
->mx
, mtmp
->my
))
196 pline("%s suddenly disappears!",
201 pline("%s is hit by an arrow!",
208 pline("%s is hit by a dart!",
212 /* not mondied here !! */
218 pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp
));
221 if (mtmp
->data
->mlet
!= 'w') {
224 pline("Suddenly, %s disappears out of sight.", monnam(mtmp
));
225 return (2); /* no longer on this level */
231 impossible("Some monster encountered a strange trap.");
234 return (mtmp
->mtrapped
);
238 selftouch(const char *arg
)
240 if (uwep
&& uwep
->otyp
== DEAD_COCKATRICE
) {
241 pline("%s touch the dead cockatrice.", arg
);
242 pline("You turn to stone.");
243 killer
= objects
[uwep
->otyp
].oc_name
;
252 if (u
.utraptype
== TT_PIT
) {
254 pline("You float up, out of the pit!");
256 pline("You float up, only your leg is still stuck.");
259 pline("You start to float in the air!");
267 pline("You float gently to the ground.");
268 if ((trap
= t_at(u
.ux
, u
.uy
)) != NULL
)
269 switch (trap
->ttyp
) {
273 if (!xdnstair
|| u
.ustuck
)
275 /* fall into next case */
285 struct mkroom
*croom
;
287 for (croom
= &rooms
[0]; croom
->hx
>= 0; croom
++)
288 if (croom
->rtype
== VAULT
) {
291 x
= rn2(2) ? croom
->lx
: croom
->hx
;
292 y
= rn2(2) ? croom
->ly
: croom
->hy
;
307 if (Teleport_control
) {
308 pline("To what position do you want to be teleported?");
309 cc
= getpos(1, "the desired position"); /* 1: force valid */
311 * possible extensions: introduce a small error if magic
312 * power is low; allow transfer to solid rock
314 if (teleok(cc
.x
, cc
.y
)) {
321 nux
= rnd(COLNO
- 1);
323 } while (!teleok(nux
, nuy
));
328 teleds(int nux
, int nuy
)
341 u
.uswldtim
= u
.uswallow
= 0;
345 if (levl
[nux
][nuy
].typ
== POOL
&& !Levitation
)
350 read_engr_at(u
.ux
, u
.uy
);
354 teleok(int x
, int y
) /* might throw him into a POOL */
356 return (isok(x
, y
) && !IS_ROCK(levl
[x
][y
].typ
) && !m_at(x
, y
) &&
357 !sobj_at(ENORMOUS_ROCK
, x
, y
) && !t_at(x
, y
)
359 /* Note: gold is permitted (because of vaults) */
369 (!Teleportation
|| u
.ulevel
< 6 ||
370 (pl_character
[0] != 'W' && u
.ulevel
< 10))) {
371 pline("You are not able to teleport at will.");
374 if (u
.uhunger
<= 100 || u
.ustr
< 6) {
375 pline("You miss the strength for a teleport spell.");
386 if (!uchain
|| !uball
) {
387 impossible("Where are your chain and ball??");
390 uball
->ox
= uchain
->ox
= u
.ux
;
391 uball
->oy
= uchain
->oy
= u
.uy
;
395 if (!carried(uball
)) {
405 if (!carried(uball
)) {
418 if (Teleport_control
) {
422 pline("To what level do you want to teleport? [type a number] ");
424 } while (!digit(buf
[0]) && (buf
[0] != '-' || !digit(buf
[1])));
425 newlevel
= atoi(buf
);
427 newlevel
= 5 + rn2(20); /* 5 - 24 */
428 if (dlevel
== newlevel
) {
435 if (newlevel
>= 30) {
436 if (newlevel
> MAXLEVEL
)
438 pline("You arrive at the center of the earth ...");
439 pline("Unfortunately it is here that hell is located.");
440 if (Fire_resistance
) {
441 pline("But the fire doesn't seem to harm you.");
443 pline("You burn to a crisp.");
444 dlevel
= maxdlevel
= newlevel
;
445 killer
= "visit to the hell";
451 pline("You are now high above the clouds ...");
453 pline("You float gently down to earth.");
456 pline("Unfortunately, you don't know how to fly.");
457 pline("You fall down a few thousand feet and break your neck.");
463 goto_level(newlevel
, FALSE
); /* calls done("escaped") if newlevel==0 */
469 pline("You fall into a pool!");
470 pline("You can't swim!");
471 if (rn2(3) < u
.uluck
+ 2) {
472 /* most scrolls become unreadable */
475 for (obj
= invent
; obj
; obj
= obj
->nobj
)
476 if (obj
->olet
== SCROLL_SYM
&& rn2(12) > u
.uluck
)
477 obj
->otyp
= SCR_BLANK_PAPER
;
478 /* we should perhaps merge these scrolls ? */
480 pline("You attempt a teleport spell."); /* utcsri!carroll */
482 if (levl
[u
.ux
][u
.uy
].typ
!= POOL
)
485 pline("You drown ...");
486 killer
= "pool of water";