Home | History | Annotate | Line # | Download | only in hack
      1  1.10  dholland /*	$NetBSD: hack.trap.c,v 1.10 2011/08/07 06:03:45 dholland Exp $	*/
      2   1.4  christos 
      3   1.2   mycroft /*
      4   1.7       jsm  * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
      5   1.7       jsm  * Amsterdam
      6   1.7       jsm  * All rights reserved.
      7   1.7       jsm  *
      8   1.7       jsm  * Redistribution and use in source and binary forms, with or without
      9   1.7       jsm  * modification, are permitted provided that the following conditions are
     10   1.7       jsm  * met:
     11   1.7       jsm  *
     12   1.7       jsm  * - Redistributions of source code must retain the above copyright notice,
     13   1.7       jsm  * this list of conditions and the following disclaimer.
     14   1.7       jsm  *
     15   1.7       jsm  * - Redistributions in binary form must reproduce the above copyright
     16   1.7       jsm  * notice, this list of conditions and the following disclaimer in the
     17   1.7       jsm  * documentation and/or other materials provided with the distribution.
     18   1.7       jsm  *
     19   1.7       jsm  * - Neither the name of the Stichting Centrum voor Wiskunde en
     20   1.7       jsm  * Informatica, nor the names of its contributors may be used to endorse or
     21   1.7       jsm  * promote products derived from this software without specific prior
     22   1.7       jsm  * written permission.
     23   1.7       jsm  *
     24   1.7       jsm  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     25   1.7       jsm  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26   1.7       jsm  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     27   1.7       jsm  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     28   1.7       jsm  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     29   1.7       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     30   1.7       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     31   1.7       jsm  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     32   1.7       jsm  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     33   1.7       jsm  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     34   1.7       jsm  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35   1.7       jsm  */
     36   1.7       jsm 
     37   1.7       jsm /*
     38   1.7       jsm  * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
     39   1.7       jsm  * All rights reserved.
     40   1.7       jsm  *
     41   1.7       jsm  * Redistribution and use in source and binary forms, with or without
     42   1.7       jsm  * modification, are permitted provided that the following conditions
     43   1.7       jsm  * are met:
     44   1.7       jsm  * 1. Redistributions of source code must retain the above copyright
     45   1.7       jsm  *    notice, this list of conditions and the following disclaimer.
     46   1.7       jsm  * 2. Redistributions in binary form must reproduce the above copyright
     47   1.7       jsm  *    notice, this list of conditions and the following disclaimer in the
     48   1.7       jsm  *    documentation and/or other materials provided with the distribution.
     49   1.7       jsm  * 3. The name of the author may not be used to endorse or promote products
     50   1.7       jsm  *    derived from this software without specific prior written permission.
     51   1.7       jsm  *
     52   1.7       jsm  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     53   1.7       jsm  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     54   1.7       jsm  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
     55   1.7       jsm  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     56   1.7       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     57   1.7       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     58   1.7       jsm  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     59   1.7       jsm  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     60   1.7       jsm  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     61   1.7       jsm  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62   1.2   mycroft  */
     63   1.2   mycroft 
     64   1.4  christos #include <sys/cdefs.h>
     65   1.2   mycroft #ifndef lint
     66  1.10  dholland __RCSID("$NetBSD: hack.trap.c,v 1.10 2011/08/07 06:03:45 dholland Exp $");
     67   1.4  christos #endif				/* not lint */
     68   1.1       cgd 
     69   1.4  christos #include <stdlib.h>
     70   1.4  christos #include "hack.h"
     71   1.4  christos #include "extern.h"
     72   1.4  christos #include "def.mkroom.h"
     73   1.1       cgd 
     74   1.6       jsm const char            vowels[] = "aeiou";
     75   1.1       cgd 
     76   1.6       jsm const char           *const traps[] = {
     77   1.1       cgd 	" bear trap",
     78   1.1       cgd 	"n arrow trap",
     79   1.1       cgd 	" dart trap",
     80   1.1       cgd 	" trapdoor",
     81   1.1       cgd 	" teleportation trap",
     82   1.1       cgd 	" pit",
     83   1.1       cgd 	" sleeping gas trap",
     84   1.1       cgd 	" piercer",
     85   1.1       cgd 	" mimic"
     86   1.1       cgd };
     87   1.1       cgd 
     88   1.9  dholland static void vtele(void);
     89   1.9  dholland static void teleds(int, int);
     90   1.9  dholland static int teleok(int, int);
     91   1.9  dholland 
     92   1.4  christos struct trap    *
     93   1.8  dholland maketrap(int x, int y, int typ)
     94   1.1       cgd {
     95   1.4  christos 	struct trap    *ttmp;
     96   1.1       cgd 
     97   1.1       cgd 	ttmp = newtrap();
     98   1.1       cgd 	ttmp->ttyp = typ;
     99   1.1       cgd 	ttmp->tseen = 0;
    100   1.1       cgd 	ttmp->once = 0;
    101   1.1       cgd 	ttmp->tx = x;
    102   1.1       cgd 	ttmp->ty = y;
    103   1.1       cgd 	ttmp->ntrap = ftrap;
    104   1.1       cgd 	ftrap = ttmp;
    105   1.4  christos 	return (ttmp);
    106   1.1       cgd }
    107   1.1       cgd 
    108   1.4  christos void
    109   1.8  dholland dotrap(struct trap *trap)
    110   1.4  christos {
    111   1.4  christos 	int             ttype = trap->ttyp;
    112   1.1       cgd 
    113   1.1       cgd 	nomul(0);
    114   1.4  christos 	if (trap->tseen && !rn2(5) && ttype != PIT)
    115   1.1       cgd 		pline("You escape a%s.", traps[ttype]);
    116   1.1       cgd 	else {
    117   1.1       cgd 		trap->tseen = 1;
    118   1.4  christos 		switch (ttype) {
    119   1.1       cgd 		case SLP_GAS_TRAP:
    120   1.1       cgd 			pline("A cloud of gas puts you to sleep!");
    121   1.1       cgd 			nomul(-rnd(25));
    122   1.1       cgd 			break;
    123   1.1       cgd 		case BEAR_TRAP:
    124   1.4  christos 			if (Levitation) {
    125   1.1       cgd 				pline("You float over a bear trap.");
    126   1.1       cgd 				break;
    127   1.1       cgd 			}
    128   1.1       cgd 			u.utrap = 4 + rn2(4);
    129   1.1       cgd 			u.utraptype = TT_BEARTRAP;
    130   1.1       cgd 			pline("A bear trap closes on your foot!");
    131   1.1       cgd 			break;
    132   1.1       cgd 		case PIERC:
    133   1.1       cgd 			deltrap(trap);
    134   1.4  christos 			if (makemon(PM_PIERCER, u.ux, u.uy)) {
    135   1.4  christos 				pline("A piercer suddenly drops from the ceiling!");
    136   1.4  christos 				if (uarmh)
    137   1.4  christos 					pline("Its blow glances off your helmet.");
    138   1.4  christos 				else
    139   1.4  christos 					(void) thitu(3, d(4, 6), "falling piercer");
    140   1.1       cgd 			}
    141   1.1       cgd 			break;
    142   1.1       cgd 		case ARROW_TRAP:
    143   1.1       cgd 			pline("An arrow shoots out at you!");
    144   1.4  christos 			if (!thitu(8, rnd(6), "arrow")) {
    145   1.1       cgd 				mksobj_at(ARROW, u.ux, u.uy);
    146   1.1       cgd 				fobj->quan = 1;
    147   1.1       cgd 			}
    148   1.1       cgd 			break;
    149   1.1       cgd 		case TRAPDOOR:
    150   1.4  christos 			if (!xdnstair) {
    151   1.4  christos 				pline("A trap door in the ceiling opens and a rock falls on your head!");
    152   1.4  christos 				if (uarmh)
    153   1.4  christos 					pline("Fortunately, you are wearing a helmet!");
    154   1.4  christos 				losehp(uarmh ? 2 : d(2, 10), "falling rock");
    155   1.4  christos 				mksobj_at(ROCK, u.ux, u.uy);
    156   1.4  christos 				fobj->quan = 1;
    157   1.4  christos 				stackobj(fobj);
    158   1.4  christos 				if (Invisible)
    159   1.4  christos 					newsym(u.ux, u.uy);
    160   1.1       cgd 			} else {
    161   1.4  christos 				int             newlevel = dlevel + 1;
    162   1.4  christos 				while (!rn2(4) && newlevel < 29)
    163   1.1       cgd 					newlevel++;
    164   1.1       cgd 				pline("A trap door opens up under you!");
    165   1.4  christos 				if (Levitation || u.ustuck) {
    166   1.4  christos 					pline("For some reason you don't fall in.");
    167   1.1       cgd 					break;
    168   1.1       cgd 				}
    169   1.1       cgd 				goto_level(newlevel, FALSE);
    170   1.1       cgd 			}
    171   1.1       cgd 			break;
    172   1.1       cgd 		case DART_TRAP:
    173   1.1       cgd 			pline("A little dart shoots out at you!");
    174   1.4  christos 			if (thitu(7, rnd(3), "little dart")) {
    175   1.4  christos 				if (!rn2(6))
    176   1.4  christos 					poisoned("dart", "poison dart");
    177   1.1       cgd 			} else {
    178   1.1       cgd 				mksobj_at(DART, u.ux, u.uy);
    179   1.1       cgd 				fobj->quan = 1;
    180   1.1       cgd 			}
    181   1.1       cgd 			break;
    182   1.1       cgd 		case TELEP_TRAP:
    183   1.4  christos 			if (trap->once) {
    184   1.1       cgd 				deltrap(trap);
    185   1.4  christos 				newsym(u.ux, u.uy);
    186   1.1       cgd 				vtele();
    187   1.1       cgd 			} else {
    188   1.4  christos 				newsym(u.ux, u.uy);
    189   1.1       cgd 				tele();
    190   1.1       cgd 			}
    191   1.1       cgd 			break;
    192   1.1       cgd 		case PIT:
    193   1.4  christos 			if (Levitation) {
    194   1.1       cgd 				pline("A pit opens up under you!");
    195   1.1       cgd 				pline("You don't fall in!");
    196   1.1       cgd 				break;
    197   1.1       cgd 			}
    198   1.1       cgd 			pline("You fall into a pit!");
    199   1.4  christos 			u.utrap = rn1(6, 2);
    200   1.1       cgd 			u.utraptype = TT_PIT;
    201   1.4  christos 			losehp(rnd(6), "fall into a pit");
    202   1.1       cgd 			selftouch("Falling, you");
    203   1.1       cgd 			break;
    204   1.1       cgd 		default:
    205   1.1       cgd 			impossible("You hit a trap of type %u", trap->ttyp);
    206   1.1       cgd 		}
    207   1.1       cgd 	}
    208   1.1       cgd }
    209   1.1       cgd 
    210   1.4  christos int
    211   1.8  dholland mintrap(struct monst *mtmp)
    212   1.4  christos {
    213   1.4  christos 	struct trap    *trap = t_at(mtmp->mx, mtmp->my);
    214   1.4  christos 	int             wasintrap = mtmp->mtrapped;
    215   1.1       cgd 
    216   1.4  christos 	if (!trap) {
    217   1.1       cgd 		mtmp->mtrapped = 0;	/* perhaps teleported? */
    218   1.4  christos 	} else if (wasintrap) {
    219   1.4  christos 		if (!rn2(40))
    220   1.4  christos 			mtmp->mtrapped = 0;
    221   1.1       cgd 	} else {
    222   1.4  christos 		int             tt = trap->ttyp;
    223   1.4  christos 		int             in_sight = cansee(mtmp->mx, mtmp->my);
    224   1.4  christos 
    225   1.4  christos 		if (mtmp->mtrapseen & (1 << tt)) {
    226   1.4  christos 			/* he has been in such a trap - perhaps he escapes */
    227   1.4  christos 			if (rn2(4))
    228   1.4  christos 				return (0);
    229   1.4  christos 		}
    230   1.4  christos 		mtmp->mtrapseen |= (1 << tt);
    231   1.4  christos 		switch (tt) {
    232   1.1       cgd 		case BEAR_TRAP:
    233   1.4  christos 			if (strchr(mlarge, mtmp->data->mlet)) {
    234   1.4  christos 				if (in_sight)
    235   1.4  christos 					pline("%s is caught in a bear trap!",
    236   1.4  christos 					      Monnam(mtmp));
    237   1.4  christos 				else if (mtmp->data->mlet == 'o')
    238   1.4  christos 					pline("You hear the roaring of an angry bear!");
    239   1.1       cgd 				mtmp->mtrapped = 1;
    240   1.1       cgd 			}
    241   1.1       cgd 			break;
    242   1.1       cgd 		case PIT:
    243   1.1       cgd 			/* there should be a mtmp/data -> floating */
    244   1.4  christos 			if (!strchr("EywBfk'& ", mtmp->data->mlet)) {	/* ab */
    245   1.1       cgd 				mtmp->mtrapped = 1;
    246   1.4  christos 				if (in_sight)
    247   1.4  christos 					pline("%s falls in a pit!", Monnam(mtmp));
    248   1.1       cgd 			}
    249   1.1       cgd 			break;
    250   1.1       cgd 		case SLP_GAS_TRAP:
    251   1.4  christos 			if (!mtmp->msleep && !mtmp->mfroz) {
    252   1.1       cgd 				mtmp->msleep = 1;
    253   1.4  christos 				if (in_sight)
    254   1.4  christos 					pline("%s suddenly falls asleep!",
    255   1.4  christos 					      Monnam(mtmp));
    256   1.1       cgd 			}
    257   1.1       cgd 			break;
    258   1.1       cgd 		case TELEP_TRAP:
    259   1.1       cgd 			rloc(mtmp);
    260   1.4  christos 			if (in_sight && !cansee(mtmp->mx, mtmp->my))
    261   1.1       cgd 				pline("%s suddenly disappears!",
    262   1.4  christos 				      Monnam(mtmp));
    263   1.1       cgd 			break;
    264   1.1       cgd 		case ARROW_TRAP:
    265   1.4  christos 			if (in_sight) {
    266   1.1       cgd 				pline("%s is hit by an arrow!",
    267   1.4  christos 				      Monnam(mtmp));
    268   1.1       cgd 			}
    269   1.1       cgd 			mtmp->mhp -= 3;
    270   1.1       cgd 			break;
    271   1.1       cgd 		case DART_TRAP:
    272   1.4  christos 			if (in_sight) {
    273   1.1       cgd 				pline("%s is hit by a dart!",
    274   1.4  christos 				      Monnam(mtmp));
    275   1.1       cgd 			}
    276   1.1       cgd 			mtmp->mhp -= 2;
    277   1.1       cgd 			/* not mondied here !! */
    278   1.1       cgd 			break;
    279   1.1       cgd 		case TRAPDOOR:
    280   1.4  christos 			if (!xdnstair) {
    281   1.1       cgd 				mtmp->mhp -= 10;
    282   1.4  christos 				if (in_sight)
    283   1.4  christos 					pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
    284   1.1       cgd 				break;
    285   1.1       cgd 			}
    286   1.4  christos 			if (mtmp->data->mlet != 'w') {
    287   1.1       cgd 				fall_down(mtmp);
    288   1.4  christos 				if (in_sight)
    289   1.4  christos 					pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
    290   1.4  christos 				return (2);	/* no longer on this level */
    291   1.1       cgd 			}
    292   1.1       cgd 			break;
    293   1.1       cgd 		case PIERC:
    294   1.1       cgd 			break;
    295   1.1       cgd 		default:
    296   1.1       cgd 			impossible("Some monster encountered a strange trap.");
    297   1.4  christos 		}
    298   1.1       cgd 	}
    299   1.4  christos 	return (mtmp->mtrapped);
    300   1.1       cgd }
    301   1.1       cgd 
    302   1.4  christos void
    303   1.8  dholland selftouch(const char *arg)
    304   1.4  christos {
    305   1.4  christos 	if (uwep && uwep->otyp == DEAD_COCKATRICE) {
    306   1.1       cgd 		pline("%s touch the dead cockatrice.", arg);
    307   1.1       cgd 		pline("You turn to stone.");
    308   1.1       cgd 		killer = objects[uwep->otyp].oc_name;
    309   1.1       cgd 		done("died");
    310   1.1       cgd 	}
    311   1.1       cgd }
    312   1.1       cgd 
    313   1.4  christos void
    314   1.8  dholland float_up(void)
    315   1.4  christos {
    316   1.4  christos 	if (u.utrap) {
    317   1.4  christos 		if (u.utraptype == TT_PIT) {
    318   1.1       cgd 			u.utrap = 0;
    319   1.1       cgd 			pline("You float up, out of the pit!");
    320   1.1       cgd 		} else {
    321   1.1       cgd 			pline("You float up, only your leg is still stuck.");
    322   1.1       cgd 		}
    323   1.1       cgd 	} else
    324   1.1       cgd 		pline("You start to float in the air!");
    325   1.1       cgd }
    326   1.1       cgd 
    327   1.4  christos void
    328   1.8  dholland float_down(void)
    329   1.4  christos {
    330   1.4  christos 	struct trap    *trap;
    331   1.1       cgd 	pline("You float gently to the ground.");
    332   1.4  christos 	if ((trap = t_at(u.ux, u.uy)) != NULL)
    333   1.4  christos 		switch (trap->ttyp) {
    334   1.1       cgd 		case PIERC:
    335   1.1       cgd 			break;
    336   1.1       cgd 		case TRAPDOOR:
    337   1.4  christos 			if (!xdnstair || u.ustuck)
    338   1.4  christos 				break;
    339  1.10  dholland 			/* FALLTHROUGH */
    340   1.1       cgd 		default:
    341   1.1       cgd 			dotrap(trap);
    342   1.4  christos 		}
    343   1.1       cgd 	pickup(1);
    344   1.1       cgd }
    345   1.1       cgd 
    346   1.9  dholland static void
    347   1.8  dholland vtele(void)
    348   1.4  christos {
    349   1.4  christos 	struct mkroom  *croom;
    350   1.4  christos 	for (croom = &rooms[0]; croom->hx >= 0; croom++)
    351   1.4  christos 		if (croom->rtype == VAULT) {
    352   1.4  christos 			int x, y;
    353   1.4  christos 
    354   1.4  christos 			x = rn2(2) ? croom->lx : croom->hx;
    355   1.4  christos 			y = rn2(2) ? croom->ly : croom->hy;
    356   1.4  christos 			if (teleok(x, y)) {
    357   1.4  christos 				teleds(x, y);
    358   1.4  christos 				return;
    359   1.4  christos 			}
    360   1.1       cgd 		}
    361   1.1       cgd 	tele();
    362   1.1       cgd }
    363   1.1       cgd 
    364   1.4  christos void
    365   1.8  dholland tele(void)
    366   1.4  christos {
    367   1.4  christos 	coord           cc;
    368   1.4  christos 	int             nux, nuy;
    369   1.1       cgd 
    370   1.4  christos 	if (Teleport_control) {
    371   1.1       cgd 		pline("To what position do you want to be teleported?");
    372   1.4  christos 		cc = getpos(1, "the desired position");	/* 1: force valid */
    373   1.4  christos 		/*
    374   1.4  christos 		 * possible extensions: introduce a small error if magic
    375   1.4  christos 		 * power is low; allow transfer to solid rock
    376   1.4  christos 		 */
    377   1.4  christos 		if (teleok(cc.x, cc.y)) {
    378   1.1       cgd 			teleds(cc.x, cc.y);
    379   1.1       cgd 			return;
    380   1.1       cgd 		}
    381   1.1       cgd 		pline("Sorry ...");
    382   1.1       cgd 	}
    383   1.1       cgd 	do {
    384   1.4  christos 		nux = rnd(COLNO - 1);
    385   1.1       cgd 		nuy = rn2(ROWNO);
    386   1.4  christos 	} while (!teleok(nux, nuy));
    387   1.1       cgd 	teleds(nux, nuy);
    388   1.1       cgd }
    389   1.1       cgd 
    390   1.9  dholland static void
    391   1.8  dholland teleds(int nux, int nuy)
    392   1.1       cgd {
    393   1.4  christos 	if (Punished)
    394   1.4  christos 		unplacebc();
    395   1.1       cgd 	unsee();
    396   1.1       cgd 	u.utrap = 0;
    397   1.1       cgd 	u.ustuck = 0;
    398   1.1       cgd 	u.ux = nux;
    399   1.1       cgd 	u.uy = nuy;
    400   1.1       cgd 	setsee();
    401   1.4  christos 	if (Punished)
    402   1.4  christos 		placebc(1);
    403   1.4  christos 	if (u.uswallow) {
    404   1.1       cgd 		u.uswldtim = u.uswallow = 0;
    405   1.1       cgd 		docrt();
    406   1.1       cgd 	}
    407   1.1       cgd 	nomul(0);
    408   1.4  christos 	if (levl[nux][nuy].typ == POOL && !Levitation)
    409   1.1       cgd 		drown();
    410   1.1       cgd 	(void) inshop();
    411   1.1       cgd 	pickup(1);
    412   1.4  christos 	if (!Blind)
    413   1.4  christos 		read_engr_at(u.ux, u.uy);
    414   1.1       cgd }
    415   1.1       cgd 
    416   1.9  dholland static int
    417   1.8  dholland teleok(int x, int y)
    418   1.4  christos {				/* might throw him into a POOL */
    419   1.4  christos 	return (isok(x, y) && !IS_ROCK(levl[x][y].typ) && !m_at(x, y) &&
    420   1.4  christos 		!sobj_at(ENORMOUS_ROCK, x, y) && !t_at(x, y)
    421   1.4  christos 		);
    422   1.1       cgd 	/* Note: gold is permitted (because of vaults) */
    423   1.1       cgd }
    424   1.1       cgd 
    425   1.4  christos int
    426   1.8  dholland dotele(void)
    427   1.4  christos {
    428   1.4  christos 	if (
    429   1.1       cgd #ifdef WIZARD
    430   1.4  christos 	    !wizard &&
    431   1.4  christos #endif	/* WIZARD */
    432   1.4  christos 	    (!Teleportation || u.ulevel < 6 ||
    433   1.4  christos 	     (pl_character[0] != 'W' && u.ulevel < 10))) {
    434   1.1       cgd 		pline("You are not able to teleport at will.");
    435   1.4  christos 		return (0);
    436   1.1       cgd 	}
    437   1.4  christos 	if (u.uhunger <= 100 || u.ustr < 6) {
    438   1.1       cgd 		pline("You miss the strength for a teleport spell.");
    439   1.4  christos 		return (1);
    440   1.1       cgd 	}
    441   1.1       cgd 	tele();
    442   1.1       cgd 	morehungry(100);
    443   1.4  christos 	return (1);
    444   1.1       cgd }
    445   1.1       cgd 
    446   1.4  christos void
    447   1.8  dholland placebc(int attach)
    448   1.4  christos {
    449   1.4  christos 	if (!uchain || !uball) {
    450   1.1       cgd 		impossible("Where are your chain and ball??");
    451   1.1       cgd 		return;
    452   1.1       cgd 	}
    453   1.1       cgd 	uball->ox = uchain->ox = u.ux;
    454   1.1       cgd 	uball->oy = uchain->oy = u.uy;
    455   1.4  christos 	if (attach) {
    456   1.1       cgd 		uchain->nobj = fobj;
    457   1.1       cgd 		fobj = uchain;
    458   1.4  christos 		if (!carried(uball)) {
    459   1.1       cgd 			uball->nobj = fobj;
    460   1.1       cgd 			fobj = uball;
    461   1.1       cgd 		}
    462   1.1       cgd 	}
    463   1.1       cgd }
    464   1.1       cgd 
    465   1.4  christos void
    466   1.8  dholland unplacebc(void)
    467   1.4  christos {
    468   1.4  christos 	if (!carried(uball)) {
    469   1.1       cgd 		freeobj(uball);
    470   1.1       cgd 		unpobj(uball);
    471   1.1       cgd 	}
    472   1.1       cgd 	freeobj(uchain);
    473   1.1       cgd 	unpobj(uchain);
    474   1.1       cgd }
    475   1.1       cgd 
    476   1.4  christos void
    477   1.8  dholland level_tele(void)
    478   1.4  christos {
    479   1.4  christos 	int             newlevel;
    480   1.4  christos 	if (Teleport_control) {
    481   1.4  christos 		char            buf[BUFSZ];
    482   1.4  christos 
    483   1.4  christos 		do {
    484   1.4  christos 			pline("To what level do you want to teleport? [type a number] ");
    485   1.4  christos 			getlin(buf);
    486   1.4  christos 		} while (!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
    487   1.4  christos 		newlevel = atoi(buf);
    488   1.1       cgd 	} else {
    489   1.4  christos 		newlevel = 5 + rn2(20);	/* 5 - 24 */
    490   1.5     veego 		if (dlevel == newlevel) {
    491   1.4  christos 			if (!xdnstair)
    492   1.4  christos 				newlevel--;
    493   1.4  christos 			else
    494   1.4  christos 				newlevel++;
    495   1.5     veego 		}
    496   1.4  christos 	}
    497   1.4  christos 	if (newlevel >= 30) {
    498   1.4  christos 		if (newlevel > MAXLEVEL)
    499   1.4  christos 			newlevel = MAXLEVEL;
    500   1.4  christos 		pline("You arrive at the center of the earth ...");
    501   1.4  christos 		pline("Unfortunately it is here that hell is located.");
    502   1.4  christos 		if (Fire_resistance) {
    503   1.4  christos 			pline("But the fire doesn't seem to harm you.");
    504   1.4  christos 		} else {
    505   1.4  christos 			pline("You burn to a crisp.");
    506   1.4  christos 			dlevel = maxdlevel = newlevel;
    507   1.4  christos 			killer = "visit to the hell";
    508   1.4  christos 			done("burned");
    509   1.4  christos 		}
    510   1.4  christos 	}
    511   1.4  christos 	if (newlevel < 0) {
    512   1.4  christos 		newlevel = 0;
    513   1.4  christos 		pline("You are now high above the clouds ...");
    514   1.4  christos 		if (Levitation) {
    515   1.4  christos 			pline("You float gently down to earth.");
    516   1.4  christos 			done("escaped");
    517   1.4  christos 		}
    518   1.4  christos 		pline("Unfortunately, you don't know how to fly.");
    519   1.4  christos 		pline("You fall down a few thousand feet and break your neck.");
    520   1.4  christos 		dlevel = 0;
    521   1.4  christos 		killer = "fall";
    522   1.4  christos 		done("died");
    523   1.1       cgd 	}
    524   1.4  christos 	goto_level(newlevel, FALSE);	/* calls done("escaped") if
    525   1.4  christos 					 * newlevel==0 */
    526   1.1       cgd }
    527   1.1       cgd 
    528   1.4  christos void
    529   1.8  dholland drown(void)
    530   1.1       cgd {
    531   1.1       cgd 	pline("You fall into a pool!");
    532   1.1       cgd 	pline("You can't swim!");
    533   1.4  christos 	if (rn2(3) < u.uluck + 2) {
    534   1.1       cgd 		/* most scrolls become unreadable */
    535   1.4  christos 		struct obj     *obj;
    536   1.1       cgd 
    537   1.4  christos 		for (obj = invent; obj; obj = obj->nobj)
    538   1.4  christos 			if (obj->olet == SCROLL_SYM && rn2(12) > u.uluck)
    539   1.1       cgd 				obj->otyp = SCR_BLANK_PAPER;
    540   1.1       cgd 		/* we should perhaps merge these scrolls ? */
    541   1.1       cgd 
    542   1.1       cgd 		pline("You attempt a teleport spell.");	/* utcsri!carroll */
    543   1.1       cgd 		(void) dotele();
    544   1.4  christos 		if (levl[u.ux][u.uy].typ != POOL)
    545   1.4  christos 			return;
    546   1.1       cgd 	}
    547   1.1       cgd 	pline("You drown ...");
    548   1.1       cgd 	killer = "pool of water";
    549   1.1       cgd 	done("drowned");
    550   1.1       cgd }
    551