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!");
86 if(uarmh
) pline("Fortunately, you are wearing a helmet!");
87 losehp(uarmh
? 2 : d(2,10),"falling rock");
88 mksobj_at(ROCK
, u
.ux
, u
.uy
);
91 if(Invisible
) newsym(u
.ux
, u
.uy
);
93 int newlevel
= dlevel
+ 1;
94 while(!rn2(4) && newlevel
< 29)
96 pline("A trap door opens up under you!");
97 if(Levitation
|| u
.ustuck
) {
98 pline("For some reason you don't fall in.");
102 goto_level(newlevel
, FALSE
);
106 pline("A little dart shoots out at you!");
107 if(thitu(7,rnd(3),"little dart")) {
109 poisoned("dart","poison dart");
111 mksobj_at(DART
, u
.ux
, u
.uy
);
127 pline("A pit opens up under you!");
128 pline("You don't fall in!");
131 pline("You fall into a pit!");
133 u
.utraptype
= TT_PIT
;
134 losehp(rnd(6),"fall into a pit");
135 selftouch("Falling, you");
138 impossible("You hit a trap of type %u", trap
->ttyp
);
144 mintrap(struct monst
*mtmp
)
146 struct trap
*trap
= t_at(mtmp
->mx
, mtmp
->my
);
147 int wasintrap
= mtmp
->mtrapped
;
150 mtmp
->mtrapped
= 0; /* perhaps teleported? */
151 } else if(wasintrap
) {
152 if(!rn2(40)) mtmp
->mtrapped
= 0;
155 int in_sight
= cansee(mtmp
->mx
,mtmp
->my
);
157 if(mtmp
->mtrapseen
& (1 << tt
)) {
158 /* he has been in such a trap - perhaps he escapes */
159 if(rn2(4)) return(0);
161 mtmp
->mtrapseen
|= (1 << tt
);
164 if(index(mlarge
, mtmp
->data
->mlet
)) {
166 pline("%s is caught in a bear trap!",
169 if(mtmp
->data
->mlet
== 'o')
170 pline("You hear the roaring of an angry bear!");
175 /* there should be a mtmp/data -> floating */
176 if(!index("EywBfk'& ", mtmp
->data
->mlet
)) { /* ab */
179 pline("%s falls in a pit!", Monnam(mtmp
));
183 if(!mtmp
->msleep
&& !mtmp
->mfroz
) {
186 pline("%s suddenly falls asleep!",
192 if(in_sight
&& !cansee(mtmp
->mx
,mtmp
->my
))
193 pline("%s suddenly disappears!",
198 pline("%s is hit by an arrow!",
205 pline("%s is hit by a dart!",
209 /* not mondied here !! */
215 pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp
));
218 if(mtmp
->data
->mlet
!= 'w'){
221 pline("Suddenly, %s disappears out of sight.", monnam(mtmp
));
222 return(2); /* no longer on this level */
228 impossible("Some monster encountered a strange trap.");
231 return(mtmp
->mtrapped
);
235 selftouch(const char *arg
)
237 if(uwep
&& uwep
->otyp
== DEAD_COCKATRICE
){
238 pline("%s touch the dead cockatrice.", arg
);
239 pline("You turn to stone.");
240 killer
= objects
[uwep
->otyp
].oc_name
;
249 if(u
.utraptype
== TT_PIT
) {
251 pline("You float up, out of the pit!");
253 pline("You float up, only your leg is still stuck.");
256 pline("You start to float in the air!");
263 pline("You float gently to the ground.");
264 if((trap
= t_at(u
.ux
,u
.uy
)))
269 if(!xdnstair
|| u
.ustuck
) break;
270 /* fall into next case */
280 struct mkroom
*croom
;
281 for(croom
= &rooms
[0]; croom
->hx
>= 0; croom
++)
282 if(croom
->rtype
== VAULT
) {
285 x
= rn2(2) ? croom
->lx
: croom
->hx
;
286 y
= rn2(2) ? croom
->ly
: croom
->hy
;
301 if(Teleport_control
) {
302 pline("To what position do you want to be teleported?");
303 cc
= getpos(1, "the desired position"); /* 1: force valid */
304 /* possible extensions: introduce a small error if
305 magic power is low; allow transfer to solid rock */
306 if(teleok(cc
.x
, cc
.y
)){
315 } while(!teleok(nux
, nuy
));
320 teleds(int nux
, int nuy
)
322 if(Punished
) unplacebc();
329 if(Punished
) placebc(1);
331 u
.uswldtim
= u
.uswallow
= 0;
335 if(levl
[nux
][nuy
].typ
== POOL
&& !Levitation
)
339 if(!Blind
) read_engr_at(u
.ux
,u
.uy
);
343 teleok(int x
, int y
) /* might throw him into a POOL */
345 return( isok(x
,y
) && !IS_ROCK(levl
[x
][y
].typ
) && !m_at(x
,y
) &&
346 !sobj_at(ENORMOUS_ROCK
,x
,y
) && !t_at(x
,y
)
348 /* Note: gold is permitted (because of vaults) */
358 (!Teleportation
|| u
.ulevel
< 6 ||
359 (pl_character
[0] != 'W' && u
.ulevel
< 10))) {
360 pline("You are not able to teleport at will.");
363 if(u
.uhunger
<= 100 || u
.ustr
< 6) {
364 pline("You miss the strength for a teleport spell.");
375 if(!uchain
|| !uball
){
376 impossible("Where are your chain and ball??");
379 uball
->ox
= uchain
->ox
= u
.ux
;
380 uball
->oy
= uchain
->oy
= u
.uy
;
406 if(Teleport_control
) {
410 pline("To what level do you want to teleport? [type a number] ");
412 } while(!digit(buf
[0]) && (buf
[0] != '-' || !digit(buf
[1])));
413 newlevel
= atoi(buf
);
415 newlevel
= 5 + rn2(20); /* 5 - 24 */
416 if(dlevel
== newlevel
) {
417 if(!xdnstair
) newlevel
--; else newlevel
++;
421 if(newlevel
> MAXLEVEL
) newlevel
= MAXLEVEL
;
422 pline("You arrive at the center of the earth ...");
423 pline("Unfortunately it is here that hell is located.");
424 if(Fire_resistance
) {
425 pline("But the fire doesn't seem to harm you.");
427 pline("You burn to a crisp.");
428 dlevel
= maxdlevel
= newlevel
;
429 killer
= "visit to the hell";
435 pline("You are now high above the clouds ...");
437 pline("You float gently down to earth.");
440 pline("Unfortunately, you don't know how to fly.");
441 pline("You fall down a few thousand feet and break your neck.");
447 goto_level(newlevel
, FALSE
); /* calls done("escaped") if newlevel==0 */
453 pline("You fall into a pool!");
454 pline("You can't swim!");
455 if(rn2(3) < u
.uluck
+2) {
456 /* most scrolls become unreadable */
459 for(obj
= invent
; obj
; obj
= obj
->nobj
)
460 if(obj
->olet
== SCROLL_SYM
&& rn2(12) > u
.uluck
)
461 obj
->otyp
= SCR_BLANK_PAPER
;
462 /* we should perhaps merge these scrolls ? */
464 pline("You attempt a teleport spell."); /* utcsri!carroll */
466 if(levl
[u
.ux
][u
.uy
].typ
!= POOL
) return;
468 pline("You drown ...");
469 killer
= "pool of water";