Wikia

Wikihack

Source:NetHack 2.2a/trap.c

2,032pages on
this wiki
Talk0

Below is the full text to trap.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/trap.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

Screenshots and source code from Hack are used under the CWI license.
1.    /*	SCCS Id: @(#)trap.c	2.1	87/10/18
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    
4.    #include	<stdio.h>
5.    #include	"hack.h"
6.    
7.    extern struct monst *makemon();
8.    #ifdef KAA
9.    extern char *Xmonnam();
10.   extern char *nomovemsg;
11.   #endif
12.   
13.   char vowels[] = "aeiou";
14.   
15.   char *traps[] = {
16.   	"",
17.   	" bear trap",
18.   	"n arrow trap",
19.   	" dart trap",
20.   	" trapdoor",
21.   	" teleportation trap",
22.   	" pit",
23.   	" sleeping gas trap",
24.   	" piercer",
25.   	" mimic"
26.   #ifdef NEWTRAPS
27.   	," magic trap"
28.   	," squeaky board"
29.   #endif
30.   #ifdef SPIDERS
31.   	," web"
32.   #endif
33.   #ifdef NEWCLASS
34.   	," spiked pit"
35.   	," level teleporter"
36.   #endif
37.   #ifdef SPELLS
38.   	," anti-magic field" 
39.   #endif
40.   #ifdef KAA
41.   	," rust trap"
42.   # ifdef RPH
43.   	,"polymorph trap"
44.   # endif
45.   #endif
46.   };
47.   
48.   struct trap *
49.   maketrap(x,y,typ)
50.   register x,y,typ;
51.   {
52.   	register struct trap *ttmp;
53.   
54.   	ttmp = newtrap();
55.   	ttmp->ttyp = typ;
56.   	ttmp->tseen = 0;
57.   	ttmp->once = 0;
58.   	ttmp->tx = x;
59.   	ttmp->ty = y;
60.   	ttmp->ntrap = ftrap;
61.   	ftrap = ttmp;
62.   	return(ttmp);
63.   }
64.   
65.   dotrap(trap) register struct trap *trap; {
66.   	register int ttype = trap->ttyp;
67.   	register struct monst *mtmp;
68.   
69.   	nomul(0);
70.   	if(trap->tseen && !rn2(5) && !(ttype == PIT
71.   #ifdef NEWCLASS
72.   	   || ttype == SPIKED_PIT
73.   #endif
74.   #ifdef SPELLS
75.   	   || ttype == ANTI_MAGIC
76.   #endif
77.   		))
78.   		pline("You escape a%s.", traps[ttype]);
79.   	else {
80.   		trap->tseen = 1;
81.   		switch(ttype) {
82.   		case SLP_GAS_TRAP:
83.   			pline("A cloud of gas puts you to sleep!");
84.   			nomul(-rnd(25));
85.   			break;
86.   		case BEAR_TRAP:
87.   			if(Levitation) {
88.   				pline("You float over a bear trap.");
89.   				break;
90.   			}
91.   			u.utrap = 4 + rn2(4);
92.   			u.utraptype = TT_BEARTRAP;
93.   			pline("A bear trap closes on your foot!");
94.   			if(u.usym=='o') pline("You howl in anger!");
95.   			break;
96.   		case PIERC:
97.   			deltrap(trap);
98.   			if(mtmp=makemon(PM_PIERCER,u.ux,u.uy)) {
99.   			  pline("%s suddenly drops from the ceiling!", Xmonnam(mtmp));
100.  			  if(uarmh)
101.  				pline("Its blow glances off your helmet.");
102.  			  else
103.  				(void) thitu(3,d(4,6),"falling piercer");
104.  			}
105.  			break;
106.  		case ARROW_TRAP:
107.  			pline("An arrow shoots out at you!");
108.  			if(!thitu(8,rnd(6),"arrow")){
109.  				mksobj_at(ARROW, u.ux, u.uy);
110.  				fobj->quan = 1;
111.  			}
112.  			break;
113.  		case TRAPDOOR:
114.  			if(!xdnstair) {
115.  pline("A trap door in the ceiling opens and a rock falls on your head!");
116.  if(uarmh) pline("Fortunately, you are wearing a helmet!");
117.  			    losehp(uarmh ? 2 : d(2,10),"falling rock");
118.  			    mksobj_at(ROCK, u.ux, u.uy);
119.  			    fobj->quan = 1;
120.  			    stackobj(fobj);
121.  			    if(Invisible) newsym(u.ux, u.uy);
122.  			} else {
123.  			    register int newlevel = dlevel + 1;
124.  				while(!rn2(4) && newlevel < 29)
125.  					newlevel++;
126.  				pline("A trap door opens up under you!");
127.  				if(Levitation || u.ustuck) {
128.  				pline("For some reason you don't fall in.");
129.  					break;
130.  				}
131.  				fflush(stdout);
132.  				goto_level(newlevel, FALSE);
133.  			}
134.  			break;
135.  		case DART_TRAP:
136.  			pline("A little dart shoots out at you!");
137.  			if(thitu(7,rnd(3),"little dart")) {
138.  			    if(!rn2(6))
139.  				poisoned("dart","poison dart");
140.  			} else {
141.  				mksobj_at(DART, u.ux, u.uy);
142.  				fobj->quan = 1;
143.  			}
144.  			break;
145.  		case TELEP_TRAP:
146.  			if(trap->once) {
147.  				deltrap(trap);
148.  				newsym(u.ux,u.uy);
149.  				vtele();
150.  			} else {
151.  				newsym(u.ux,u.uy);
152.  				tele();
153.  			}
154.  			break;
155.  #ifdef KAA
156.  		case RUST_TRAP:
157.  			switch (rn2(5)) {
158.  			case 0:
159.  				pline("A gush of water hits you on the head!");
160.  				if (uarmh) {
161.  				    if (uarmh->rustfree)
162.  					pline("Your helmet is not affected!");
163.  				    else if (uarmh->spe > -6) {
164.  					pline("Your helmet rusts!");
165.  					uarmh->spe--;
166.  				    } else
167.  					pline("Your helmet looks quite rusted now.");
168.  				}
169.  				break;
170.  			case 1:
171.  				pline("A gush of water hits your left arm!");
172.  				if (uarms) {
173.  					pline("Your shield is not affected!");
174.  					break;
175.  				}
176.  				if (uwep && uwep->otyp == TWO_HANDED_SWORD) goto two_hand;
177.  				/* Two goto statements in a row--aaarrrgggh! */
178.  		glovecheck: if(uarmg) pline("Your gloves are not affected!");
179.  				break;
180.  			case 2:
181.  				pline("A gush of water hits your right arm!");
182.  		two_hand: corrode_weapon();
183.  				goto glovecheck;
184.  			default:
185.  				pline("A gush of water hits you!");
186.  				if (uarm) {
187.  				    if (uarm->rustfree ||
188.  					uarm->otyp >= STUDDED_LEATHER_ARMOR) 
189.  					    pline("Your %s not affected!",
190.  						  aobjnam(uarm,"are"));
191.  				    else if(uarm->spe > -6) {
192.  					    pline("Your %s!",
193.  						  aobjnam(uarm,"corrode"));
194.  					    uarm->spe--;
195.  				    } else
196.  					    pline("Your %s quite rusted now.",
197.  						  aobjnam(uarm, "look"));
198.  				}
199.  			}
200.  			break;
201.  #endif
202.  		case PIT:
203.  			if (Levitation || index("EyBfk'&",u.usym)) {
204.  				pline("A pit opens up under you!");
205.  				pline("You don't fall in!");
206.  				break;
207.  			}
208.  			pline("You fall into a pit!");
209.  			u.utrap = rn1(6,2);
210.  			u.utraptype = TT_PIT;
211.  			losehp(rnd(6),"fall into a pit");
212.  			selftouch("Falling, you");
213.  			break;
214.  #ifdef NEWCLASS
215.  		case SPIKED_PIT:
216.  			if (Levitation || index("EyBfk'&",u.usym)) {
217.  				pline("A pit opens up under you!");
218.  				pline("You don't fall in!");
219.  				pline("There are spikes in that pit!!!");
220.  				break;
221.  			}
222.  			pline("You fall into a pit!");
223.  			pline("You land on a set of sharp iron spikes!");
224.  			u.utrap = rn1(6,2);
225.  			u.utraptype = TT_PIT;
226.  			losehp(rnd(10),"fall onto iron spikes");
227.  			if(!rn2(6)) poisoned("spikes","poison spikes");
228.  			selftouch("Falling, you");
229.  			break;
230.  		case LEVEL_TELEP:
231.  			if (!Blind)	pline("You are momentarily blinded by a flash of light");
232.  			else		pline("You are momentarily disoriented.");
233.  			deltrap(trap);
234.  			newsym(u.ux,u.uy);
235.  			level_tele();
236.  			break;
237.  #endif
238.  #ifdef SPELLS
239.  		case ANTI_MAGIC:
240.  			pline("You feel your magical energy drain away!");
241.  			u.uen -= (rnd(u.ulevel) + 1);
242.  			if(u.uen < 0)  {
243.  				u.uenmax += u.uen;
244.  				if(u.uenmax < 0) u.uenmax = 0;
245.  				u.uen = 0;
246.  			}
247.  			flags.botl = 1;
248.  			break;
249.  #endif
250.  #if defined(RPH) && defined(KAA)
251.  		case POLY_TRAP:
252.  			    pline("You feel a change coming over you.");
253.  			    polyself();
254.  			    deltrap(trap);
255.  			    break;
256.  #endif
257.  #ifdef NEWTRAPS
258.  		case MGTRP:
259.  			/* A magic trap. */
260.  			domagictrap();
261.  			break;
262.  		case SQBRD: {
263.  #include      "edog.h"
264.  			register struct monst *mtmp = fmon;
265.  			/* Stepped on a squeaky board. */
266.  			pline("A board underfoot gives off a loud squeak!");
267.  			/* Wake up nearby monsters. */
268.  		       while(mtmp) {
269.  			 if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
270.  			       if(mtmp->msleep)
271.  				       mtmp->msleep = 0;
272.  			       if(mtmp->mtame)
273.  				       EDOG(mtmp)->whistletime = moves;
274.  			 }
275.  			 mtmp = mtmp->nmon;
276.  		       }
277.  		}
278.  			break;
279.  #endif
280.  #ifdef SPIDERS
281.  	       case WEB:
282.  
283.  		       /* Our luckless adventurer has stepped into a web. */
284.  
285.  		       pline("You've stumbled into a spider web!");
286.  		       u.utraptype = TT_WEB;
287.  
288.  		       /* Time stuck in the web depends on your strength. */
289.  
290.  		       if (u.ustr == 3) u.utrap = rn1(6,6);
291.  		       else if (u.ustr < 6) u.utrap = rn1(6,4);
292.  		       else if (u.ustr < 9) u.utrap = rn1(4,4);
293.  		       else if (u.ustr < 12) u.utrap = rn1(4,2);
294.  		       else if (u.ustr < 15) u.utrap = rn1(2,2);
295.  		       else if (u.ustr < 18) u.utrap = rnd(2);
296.  		       else if (u.ustr < 69) u.utrap = 1;
297.  		       else {
298.  			       u.utrap = 0;
299.  			       pline("You tear through the web!");
300.  			       deltrap(trap);
301.  			    }
302.  		       break;
303.  #endif
304.  		default:
305.  			impossible("You hit a trap of type %u", trap->ttyp);
306.  		}
307.  	}
308.  }
309.  
310.  mintrap(mtmp) register struct monst *mtmp; {
311.  	register struct trap *trap = t_at(mtmp->mx, mtmp->my);
312.  	register int wasintrap = mtmp->mtrapped;
313.  
314.  	if(!trap) {
315.  		mtmp->mtrapped = 0;	/* perhaps teleported? */
316.  	} else if(wasintrap) {
317.  		if(!rn2(40)) mtmp->mtrapped = 0;
318.  	} else {
319.  	    register int tt = trap->ttyp;
320.  #ifdef DGK
321.  	/* A bug fix for dumb messages by ab@unido.
322.  	 */
323.  	    int in_sight = cansee(mtmp->mx,mtmp->my)
324.  			   && (!mtmp->minvis || See_invisible);
325.  #else
326.  	    int in_sight = cansee(mtmp->mx,mtmp->my);
327.  #endif
328.  	    extern char mlarge[];
329.  
330.  	    if(mtmp->mtrapseen & (1 << tt)) {
331.  		/* he has been in such a trap - perhaps he escapes */
332.  		if(rn2(4)) return(0);
333.  	    }
334.  	    mtmp->mtrapseen |= (1 << tt);
335.  	    switch (tt) {
336.  		case BEAR_TRAP:
337.  			if(index(mlarge, mtmp->data->mlet)) {
338.  				if(in_sight)
339.  				  pline("%s is caught in a bear trap!",
340.  					Monnam(mtmp));
341.  				else
342.  				  if(mtmp->data->mlet == 'o')
343.  			    pline("You hear the roaring of an angry bear!");
344.  				mtmp->mtrapped = 1;
345.  			}
346.  			break;
347.  #ifdef KAA
348.  # ifdef RPH
349.    		case POLY_TRAP:
350.  		    if(!resist(mtmp, '/', 0, NOTELL))
351.  			newcham(mtmp,&mons[rn2(CMNUM)]);
352.  		    break;
353.  # endif
354.  		case RUST_TRAP:
355.  			if(in_sight)
356.  				pline("A gush of water hits %s!",monnam(mtmp));
357.  			break;
358.  #endif
359.  		case PIT:
360.  #ifdef NEWCLASS
361.  		case SPIKED_PIT:
362.  #endif
363.  			/* there should be a mtmp/data -> floating */
364.  			if(!index("EywBIfk'& ", mtmp->data->mlet)) { /* ab */
365.  				mtmp->mtrapped = 1;
366.  				if(in_sight)
367.  				  pline("%s falls into a pit!", Monnam(mtmp));
368.  			}
369.  			break;
370.  		case SLP_GAS_TRAP:
371.  			if(!mtmp->msleep && !mtmp->mfroz) {
372.  				mtmp->msleep = 1;
373.  				if(in_sight)
374.  				  pline("%s suddenly falls asleep!",
375.  					Monnam(mtmp));
376.  			}
377.  			break;
378.  		case TELEP_TRAP:
379.  #ifdef NEWCLASS
380.  		case LEVEL_TELEP:
381.  #endif
382.  			rloc(mtmp);
383.  			if(in_sight && !cansee(mtmp->mx,mtmp->my))
384.  				pline("%s suddenly disappears!",
385.  					Monnam(mtmp));
386.  			break;
387.  		case ARROW_TRAP:
388.  			if(in_sight)
389.  				pline("%s is hit by an arrow!",	Monnam(mtmp));
390.  			mtmp->mhp -= 3;
391.  			break;
392.  		case DART_TRAP:
393.  			if(in_sight)
394.  				pline("%s is hit by a dart!", Monnam(mtmp));
395.  			mtmp->mhp -= 2;
396.  			/* not mondied here !! */
397.  			break;
398.  		case TRAPDOOR:
399.  			if(!xdnstair) {
400.  				mtmp->mhp -= 10;
401.  				if(in_sight)
402.  pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
403.  				break;
404.  			}
405.  			if(!index("EywBIfk", mtmp->data->mlet)){
406.  				fall_down(mtmp);
407.  				if(in_sight)
408.  		pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
409.  				return(2);	/* no longer on this level */
410.  			}
411.  			break;
412.  		case PIERC:
413.  			break;
414.  #ifdef NEWTRAPS
415.  		case MGTRP:
416.  			/* A magic trap.  Monsters immune. */
417.  			break;
418.  		case SQBRD: {
419.  			register struct monst *ztmp = fmon;
420.  			
421.  			if(index("EyBIfk", mtmp->data->mlet)) break;
422.  			/* Stepped on a squeaky board. */
423.  			if (in_sight)
424.  			   pline("%s steps on a squeaky board.", Monnam(mtmp));
425.  			else
426.  			   pline("You hear a distant squeak.");
427.  			/* Wake up nearby monsters. */
428.  		       while(ztmp) {
429.  			 if(dist2(mtmp->mx,mtmp->my,ztmp->mx,ztmp->my) < 40)
430.  			       if(ztmp->msleep) ztmp->msleep = 0;
431.  			 ztmp = ztmp->nmon;
432.  		       }
433.  			break;
434.  		}
435.  #endif
436.  #ifdef SPIDERS
437.  	       case WEB:
438.  		       /* Monster in a web. */
439.  			/* in_sight check and confused bear by Eric Backus */
440.  		       if(mtmp->data->mlet != 's') {
441.  			 if(in_sight)
442.  				pline("%s is caught in a web!", Monnam(mtmp));
443.  			  else
444.  			    if(mtmp->data->mlet == 'o')
445.  			      pline("You hear the roaring of a confused bear!");
446.  			 mtmp->mtrapped = 1;
447.  		       }
448.  		      break;
449.  #endif
450.  #ifdef SPELLS
451.  		case ANTI_MAGIC:	break;
452.  #endif
453.  		default:
454.  			impossible("Some monster encountered a strange trap of type %d.",tt);
455.  	    }
456.  	}
457.  	return(mtmp->mtrapped);
458.  }
459.  
460.  selftouch(arg) char *arg; {
461.  	if(uwep && uwep->otyp == DEAD_COCKATRICE){
462.  		pline("%s touch the dead cockatrice.", arg);
463.  		pline("You turn to stone.");
464.  		pline("You die...");
465.  		killer = objects[uwep->otyp].oc_name;
466.  		done("died");
467.  	}
468.  }
469.  
470.  float_up(){
471.  	if(u.utrap) {
472.  		if(u.utraptype == TT_PIT) {
473.  			u.utrap = 0;
474.  			pline("You float up, out of the pit!");
475.  		} else {
476.  			pline("You float up, only your leg is still stuck.");
477.  		}
478.  	} else
479.  		if (Hallucination)
480.  			pline("Oh wow!  You're floating in the air!");
481.  		else
482.  			pline("You start to float in the air!");
483.  }
484.  
485.  float_down(){
486.  	register struct trap *trap;
487.  	
488.  	/* check for falling into pool - added by GAN 10/20/86 */
489.  	if(IS_POOL(levl[u.ux][u.uy].typ) && !Levitation)
490.  		drown();
491.  
492.  	pline("You float gently to the ground.");
493.  	if(trap = t_at(u.ux,u.uy))
494.  		switch(trap->ttyp) {
495.  		case PIERC:
496.  			break;
497.  		case TRAPDOOR:
498.  			if(!xdnstair || u.ustuck) break;
499.  			/* fall into next case */
500.  		default:
501.  			dotrap(trap);
502.  	}
503.  	pickup(1);
504.  }
505.  
506.  #include "mkroom.h"
507.  
508.  vtele() {
509.  	register struct mkroom *croom;
510.  
511.  	for(croom = &rooms[0]; croom->hx >= 0; croom++)
512.  	    if(croom->rtype == VAULT) {
513.  		register x,y;
514.  
515.  		x = rn2(2) ? croom->lx : croom->hx;
516.  		y = rn2(2) ? croom->ly : croom->hy;
517.  		if(teleok(x,y)) {
518.  		    teleds(x,y);
519.  		    return;
520.  		}
521.  	    }
522.  	tele();
523.  }
524.  
525.  #ifdef BVH
526.  int has_amulet() {
527.      register struct  obj *otmp;
528.  
529.      for(otmp = invent; otmp; otmp = otmp->nobj)
530.  	if(otmp->olet == AMULET_SYM && otmp->spe >= 0)
531.  	    return(1);
532.      return(0);
533.  }
534.  #endif
535.  
536.  tele() {
537.  	coord cc;
538.  	register int nux,nuy;
539.  
540.  #ifdef BVH
541.  	if(has_amulet() && rn2(3)) {
542.  	    pline("You feel disoriented for a moment.");
543.  	    return;
544.  	}
545.  #endif
546.  	if(Teleport_control) {
547.  #ifdef KAA
548.  	    if (multi < 0 && (!nomovemsg ||
549.  			      !strncmp(nomovemsg,"You awake", 9) ||
550.  			      !strncmp(nomovemsg,"You regain con", 15) ||
551.  			      !strncmp(nomovemsg,"You are consci", 15)))
552.   
553.  		pline("Being unconscious, you cannot control your teleport.");
554.  	    else {
555.  #endif
556.  	
557.  		    pline("To what position do you want to be teleported?");
558.  		    getpos(&cc, 1, "the desired position"); /* 1: force valid */
559.  		    /* possible extensions: introduce a small error if
560.  		       magic power is low; allow transfer to solid rock */
561.  		    if(teleok(cc.x, cc.y)){
562.  			teleds(cc.x, cc.y);
563.  			return;
564.  		    }
565.  		    pline("Sorry ...");
566.  #ifdef KAA
567.  		}
568.  #endif
569.  	}
570.  	do {
571.  		nux = rnd(COLNO-1);
572.  		nuy = rn2(ROWNO);
573.  	} while(!teleok(nux, nuy));
574.  	teleds(nux, nuy);
575.  }
576.  
577.  teleds(nux, nuy)
578.  register int nux,nuy;
579.  {
580.  	if(Punished) unplacebc();
581.  	unsee();
582.  	u.utrap = 0;
583.  	u.ustuck = 0;
584.  	u.ux = nux;
585.  	u.uy = nuy;
586.  	setsee();
587.  	if(Punished) placebc(1);
588.  	if(u.uswallow){
589.  		u.uswldtim = u.uswallow = 0;
590.  		docrt();
591.  	}
592.  	nomul(0);
593.  	if(IS_POOL(levl[nux][nuy].typ) && !Levitation)
594.  		drown();
595.  	(void) inshop();
596.  	pickup(1);
597.  	read_engr_at(u.ux,u.uy);
598.  }
599.  
600.  teleok(x,y) register int x,y; {	/* might throw him into a POOL
601.  				 * removed by GAN 10/20/86
602.  				 */
603.  #ifdef STUPID
604.  	boolean	tmp1, tmp2, tmp3;
605.  	tmp1 = isok(x,y) && !IS_ROCK(levl[x][y].typ) && !m_at(x,y);
606.  	tmp2 = !sobj_at(ENORMOUS_ROCK,x,y) && !t_at(x,y);
607.  	tmp3 = !(IS_POOL(levl[x][y].typ) && !Levitation);
608.  	return(tmp1 && tmp2 && tmp3);
609.  #else
610.  	return( isok(x,y) && !IS_ROCK(levl[x][y].typ) && !m_at(x,y) &&
611.  		!sobj_at(ENORMOUS_ROCK,x,y) && !t_at(x,y) &&
612.  		!(IS_POOL(levl[x][y].typ) && !Levitation)
613.  	);
614.  #endif
615.  	/* Note: gold is permitted (because of vaults) */
616.  }
617.  
618.  dotele() {
619.  	extern char pl_character[];
620.  
621.  	if((!index("LNt",u.usym)) &&
622.  #ifdef WIZARD
623.  	   !wizard &&
624.  #endif
625.  		      (!Teleportation || u.ulevel < 6 ||
626.  			(pl_character[0] != 'W' && u.ulevel < 10))) {
627.  		pline("You are not able to teleport at will.");
628.  		return(0);
629.  	}
630.  	if(u.uhunger <= 100 || u.ustr < 6) {
631.  		pline("You miss the strength for a teleport spell.");
632.  #ifdef WIZARD
633.  		if(!wizard)
634.  #endif
635.  		return(1);
636.  	}
637.  	tele();
638.  	morehungry(100);
639.  	return(1);
640.  }
641.  
642.  placebc(attach) int attach; {
643.  	if(!uchain || !uball){
644.  		impossible("Where are your chain and ball??");
645.  		return;
646.  	}
647.  	uball->ox = uchain->ox = u.ux;
648.  	uball->oy = uchain->oy = u.uy;
649.  	if(attach){
650.  		uchain->nobj = fobj;
651.  		fobj = uchain;
652.  		if(!carried(uball)){
653.  			uball->nobj = fobj;
654.  			fobj = uball;
655.  		}
656.  	}
657.  }
658.  
659.  unplacebc(){
660.  	if(!carried(uball)){
661.  		freeobj(uball);
662.  		unpobj(uball);
663.  	}
664.  	freeobj(uchain);
665.  	unpobj(uchain);
666.  }
667.  
668.  level_tele() {
669.  register int newlevel;
670.  
671.  #ifdef BVH
672.  	if(has_amulet() && rn2(5)) {
673.  	    pline("You feel very disoriented for a moment.");
674.  	    return;
675.  	}
676.  #endif
677.  	if(Teleport_control) {
678.  	    char buf[BUFSZ];
679.  
680.  	    do {
681.  	      pline("To what level do you want to teleport? [type a number] ");
682.  	      getlin(buf);
683.  	    } while(!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
684.  	    newlevel = atoi(buf);
685.  	} else {
686.  #ifdef DGKMOD
687.  	    newlevel = rn2(5) | !Fire_resistance ? rnz(dlevel + 3) : 30;
688.  #else
689.  	    newlevel = rnz(dlevel + 3);			/* 5 - 24 */
690.  #endif
691.  	    if(dlevel == newlevel)
692.  		if(!xdnstair) newlevel--; else newlevel++;
693.  	}
694.  	if(newlevel >= 30) {
695.  	    if(newlevel > MAXLEVEL) newlevel = MAXLEVEL;
696.  	    pline("You arrive at the center of the earth ...");
697.  	    pline("Unfortunately it is here that hell is located.");
698.  #ifdef DGK
699.  	    fflush(stdout);
700.  #endif
701.  	    if(Fire_resistance) {
702.  		pline("But the fire doesn't seem to harm you.");
703.  	    } else {
704.  		pline("You burn to a crisp.");
705.  		pline("You die...");
706.  		dlevel = maxdlevel = newlevel;
707.  		killer = "visit to hell";
708.  		done("burned");
709.  	    }
710.  	}
711.  	if(newlevel < 0) {
712.  		if(newlevel <= -10) {
713.  			pline("You arrive in heaven.");
714.  			pline("\"You are here a bit early, but we'll let you in.\"");
715.  			killer = "visit to heaven";
716.  			done("died");
717.  		} else	if (newlevel == -9) {
718.  			pline("You feel deliriously happy. ");
719.  			pline("(In fact, you're on Cloud 9!) ");
720.  			more();
721.  		} else	newlevel = 0;
722.  	    pline("You are now high above the clouds ...");
723.  	    if(Levitation) {
724.  		pline("You float gently down to earth.");
725.  		done("escaped");
726.  	    }
727.  	    pline("Unfortunately, you don't know how to fly.");
728.  	    pline("You plummet a few thousand feet to your death.");
729.  	    dlevel = 0;
730.  	    killer = "long fall";
731.  	    done("died");
732.  	}
733.  
734.  	goto_level(newlevel, FALSE); /* calls done("escaped") if newlevel==0 */
735.  }
736.  
737.  #ifdef NEWTRAPS
738.  
739.  domagictrap()
740.  {
741.  	register int fate = rnd(20);
742.  
743.  	/* What happened to the poor sucker? */
744.  
745.  	if (fate < 10) {
746.  
747.  	  /* Most of the time, it creates some monsters. */
748.  	  register int cnt = rnd(4);
749.  
750.  	  /* below checks for blindness added by GAN 10/30/86 */
751.  	  if (!Blind)  {
752.  		pline("You are momentarily blinded by a flash of light!");
753.  		Blinded += rn1(5,10);
754.  		seeoff(0);
755.  	  }  else
756.  		pline("You hear a deafening roar!");
757.  	  while(cnt--)
758.  	   (void) makemon((struct permonst *) 0, u.ux, u.uy);
759.  	}
760.  	else
761.  	  switch (fate) {
762.  
763.  	     case 10:
764.  	     case 11:
765.  		      /* sometimes nothing happens */
766.  			break;
767.  	     case 12:
768.  		      /* a flash of fire */
769.  		      {
770.  			register int num;
771.  			
772.  			/* changed to be in conformance with
773.  			 * SCR_FIRE by GAN 11/02/86
774.  			 */
775.  			
776.  			pline("A tower of flame bursts from the floor!");
777.  			if(Fire_resistance)
778.  				pline("You are uninjured.");
779.  			else {
780.  				num = rnd(6);
781.  				u.uhpmax -= num;
782.  				losehp(num,"a burst of flame");
783.  				break;
784.  			}
785.  		      }
786.  
787.  	     /* odd feelings */
788.  	     case 13:   pline("A shiver runs up and down your spine!");
789.  			break;
790.  	     case 14:   pline("You hear distant howling.");
791.  			break;
792.  	     case 15:   pline("You suddenly yearn for your distant homeland.");
793.  			break;
794.  	     case 16:   pline("Your pack shakes violently!");
795.  			break;
796.  
797.  	     /* very occasionally something nice happens. */
798.  
799.  	     case 19:
800.  		    /* tame nearby monsters */
801.  		   {   register int i,j;
802.  		       register boolean confused = (Confusion != 0);
803.  		       register int bd = confused ? 5 : 1;
804.  		       register struct monst *mtmp;
805.  
806.  		       /* below pline added by GAN 10/30/86 */
807.  		       pline("You feel charismatic.");
808.  		       for(i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++)
809.  		       if(mtmp = m_at(u.ux+i, u.uy+j))
810.  			       (void) tamedog(mtmp, (struct obj *) 0);
811.  		       break;
812.  		   }
813.  
814.  	     case 20:
815.  		    /* uncurse stuff */
816.  		   {  register struct obj *obj;
817.  		      register boolean confused = (Confusion != 0);
818.  
819.  			/* below plines added by GAN 10/30/86 */
820.  			if (confused)
821.  			    if (Hallucination)
822.  				pline("You feel the power of the Force against you!");
823.  			    else
824.  				pline("You feel like you need some help.");
825.  			else
826.  			    if (Hallucination)
827.  				pline("You feel in touch with the Universal Oneness.");
828.  			    else
829.  				pline("You feel like someone is helping you.");
830.  		       for(obj = invent; obj ; obj = obj->nobj)
831.  			       if(obj->owornmask)
832.  				       obj->cursed = confused;
833.  		       if(Punished && !confused) {
834.  			       Punished = 0;
835.  			       freeobj(uchain);
836.  			       unpobj(uchain);
837.  			       free((char *) uchain);
838.  			       uball->spe = 0;
839.  			       uball->owornmask &= ~W_BALL;
840.  			       uchain = uball = (struct obj *) 0;
841.  		       }
842.  		       break;
843.  		   }
844.  	     default: break;
845.  	  }
846.  }
847.  #endif /* NEWTRAPS /**/
848.  
849.  drown()
850.  {
851.  	pline("You fall into a pool!");
852.  	pline("You can't swim!");
853.  	if(
854.  #ifdef WIZARD
855.  	wizard ||
856.  #endif
857.  	rn2(3) < u.uluck+2) {
858.  		/* most scrolls become unreadable */
859.  		register struct obj *obj;
860.  
861.  		for(obj = invent; obj; obj = obj->nobj)
862.  			if(obj->olet == SCROLL_SYM && rn2(12) > u.uluck)
863.  				obj->otyp = SCR_BLANK_PAPER;
864.  		/* we should perhaps merge these scrolls ? */
865.  
866.  		pline("You attempt a teleport spell.");	/* utcsri!carroll */
867.  		(void) dotele();
868.  		if(!IS_POOL(levl[u.ux][u.uy].typ)) return;
869.  	}
870.  	pline("You drown.");
871.  	pline("You die...");
872.  	killer = "pool of water";
873.  	done("drowned");
874.  }

Around Wikia's network

Random Wiki