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.3 2004/11/06 12:29:17 eirikn Exp $ */
8 extern struct monst *makemon();
10 char vowels[] = "aeiou";
17 " teleportation trap",
41 dotrap(trap) struct trap *trap; {
42 int ttype = trap->ttyp;
45 if(trap->tseen && !rn2(5) && ttype != PIT)
46 pline("You escape a%s.", traps[ttype]);
51 pline("A cloud of gas puts you to sleep!");
56 pline("You float over a bear trap.");
60 u.utraptype = TT_BEARTRAP;
61 pline("A bear trap closes on your foot!");
65 if(makemon(PM_PIERCER,u.ux,u.uy)) {
66 pline("A piercer suddenly drops from the ceiling!");
68 pline("Its blow glances off your helmet.");
70 (void) thitu(3,d(4,6),"falling piercer");
74 pline("An arrow shoots out at you!");
75 if(!thitu(8,rnd(6),"arrow")){
76 mksobj_at(ARROW, u.ux, u.uy);
82 pline("A trap door in the ceiling opens and a rock falls on your head!");
83 if(uarmh) pline("Fortunately, you are wearing a helmet!");
84 losehp(uarmh ? 2 : d(2,10),"falling rock");
85 mksobj_at(ROCK, u.ux, u.uy);
88 if(Invisible) newsym(u.ux, u.uy);
90 int newlevel = dlevel + 1;
91 while(!rn2(4) && newlevel < 29)
93 pline("A trap door opens up under you!");
94 if(Levitation || u.ustuck) {
95 pline("For some reason you don't fall in.");
99 goto_level(newlevel, FALSE);
103 pline("A little dart shoots out at you!");
104 if(thitu(7,rnd(3),"little dart")) {
106 poisoned("dart","poison dart");
108 mksobj_at(DART, u.ux, u.uy);
124 pline("A pit opens up under you!");
125 pline("You don't fall in!");
128 pline("You fall into a pit!");
130 u.utraptype = TT_PIT;
131 losehp(rnd(6),"fall into a pit");
132 selftouch("Falling, you");
135 impossible("You hit a trap of type %u", trap->ttyp);
140 mintrap(mtmp) struct monst *mtmp; {
141 struct trap *trap = t_at(mtmp->mx, mtmp->my);
142 int wasintrap = mtmp->mtrapped;
145 mtmp->mtrapped = 0; /* perhaps teleported? */
146 } else if(wasintrap) {
147 if(!rn2(40)) mtmp->mtrapped = 0;
150 int in_sight = cansee(mtmp->mx,mtmp->my);
151 extern char mlarge[];
153 if(mtmp->mtrapseen & (1 << tt)) {
154 /* he has been in such a trap - perhaps he escapes */
155 if(rn2(4)) return(0);
157 mtmp->mtrapseen |= (1 << tt);
160 if(index(mlarge, mtmp->data->mlet)) {
162 pline("%s is caught in a bear trap!",
165 if(mtmp->data->mlet == 'o')
166 pline("You hear the roaring of an angry bear!");
171 /* there should be a mtmp/data -> floating */
172 if(!index("EywBfk'& ", mtmp->data->mlet)) { /* ab */
175 pline("%s falls in a pit!", Monnam(mtmp));
179 if(!mtmp->msleep && !mtmp->mfroz) {
182 pline("%s suddenly falls asleep!",
188 if(in_sight && !cansee(mtmp->mx,mtmp->my))
189 pline("%s suddenly disappears!",
194 pline("%s is hit by an arrow!",
201 pline("%s is hit by a dart!",
205 /* not mondied here !! */
211 pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
214 if(mtmp->data->mlet != 'w'){
217 pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
218 return(2); /* no longer on this level */
224 impossible("Some monster encountered a strange trap.");
227 return(mtmp->mtrapped);
230 selftouch(arg) char *arg; {
231 if(uwep && uwep->otyp == DEAD_COCKATRICE){
232 pline("%s touch the dead cockatrice.", arg);
233 pline("You turn to stone.");
234 killer = objects[uwep->otyp].oc_name;
241 if(u.utraptype == TT_PIT) {
243 pline("You float up, out of the pit!");
245 pline("You float up, only your leg is still stuck.");
248 pline("You start to float in the air!");
253 pline("You float gently to the ground.");
254 if(trap = t_at(u.ux,u.uy))
259 if(!xdnstair || u.ustuck) break;
260 /* fall into next case */
268 #include "def.mkroom.h"
269 struct mkroom *croom;
270 for(croom = &rooms[0]; croom->hx >= 0; croom++)
271 if(croom->rtype == VAULT) {
274 x = rn2(2) ? croom->lx : croom->hx;
275 y = rn2(2) ? croom->ly : croom->hy;
285 extern coord getpos();
289 if(Teleport_control) {
290 pline("To what position do you want to be teleported?");
291 cc = getpos(1, "the desired position"); /* 1: force valid */
292 /* possible extensions: introduce a small error if
293 magic power is low; allow transfer to solid rock */
294 if(teleok(cc.x, cc.y)){
303 } while(!teleok(nux, nuy));
310 if(Punished) unplacebc();
317 if(Punished) placebc(1);
319 u.uswldtim = u.uswallow = 0;
323 if(levl[nux][nuy].typ == POOL && !Levitation)
327 if(!Blind) read_engr_at(u.ux,u.uy);
330 teleok(x,y) int x,y; { /* might throw him into a POOL */
331 return( isok(x,y) && !IS_ROCK(levl[x][y].typ) && !m_at(x,y) &&
332 !sobj_at(ENORMOUS_ROCK,x,y) && !t_at(x,y)
334 /* Note: gold is permitted (because of vaults) */
338 extern char pl_character[];
344 (!Teleportation || u.ulevel < 6 ||
345 (pl_character[0] != 'W' && u.ulevel < 10))) {
346 pline("You are not able to teleport at will.");
349 if(u.uhunger <= 100 || u.ustr < 6) {
350 pline("You miss the strength for a teleport spell.");
358 placebc(attach) int attach; {
359 if(!uchain || !uball){
360 impossible("Where are your chain and ball??");
363 uball->ox = uchain->ox = u.ux;
364 uball->oy = uchain->oy = u.uy;
386 if(Teleport_control) {
390 pline("To what level do you want to teleport? [type a number] ");
392 } while(!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
393 newlevel = atoi(buf);
395 newlevel = 5 + rn2(20); /* 5 - 24 */
396 if(dlevel == newlevel) {
397 if(!xdnstair) newlevel--; else newlevel++;
401 if(newlevel > MAXLEVEL) newlevel = MAXLEVEL;
402 pline("You arrive at the center of the earth ...");
403 pline("Unfortunately it is here that hell is located.");
404 if(Fire_resistance) {
405 pline("But the fire doesn't seem to harm you.");
407 pline("You burn to a crisp.");
408 dlevel = maxdlevel = newlevel;
409 killer = "visit to the hell";
415 pline("You are now high above the clouds ...");
417 pline("You float gently down to earth.");
420 pline("Unfortunately, you don't know how to fly.");
421 pline("You fall down a few thousand feet and break your neck.");
427 goto_level(newlevel, FALSE); /* calls done("escaped") if newlevel==0 */
432 pline("You fall into a pool!");
433 pline("You can't swim!");
434 if(rn2(3) < u.uluck+2) {
435 /* most scrolls become unreadable */
438 for(obj = invent; obj; obj = obj->nobj)
439 if(obj->olet == SCROLL_SYM && rn2(12) > u.uluck)
440 obj->otyp = SCR_BLANK_PAPER;
441 /* we should perhaps merge these scrolls ? */
443 pline("You attempt a teleport spell."); /* utcsri!carroll */
445 if(levl[u.ux][u.uy].typ != POOL) return;
447 pline("You drown ...");
448 killer = "pool of water";