Home | History | Annotate | Line # | Download | only in hack
hack.trap.c revision 1.8
      1  1.8  dholland /*	$NetBSD: hack.trap.c,v 1.8 2009/06/07 18:30:39 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.8  dholland __RCSID("$NetBSD: hack.trap.c,v 1.8 2009/06/07 18:30:39 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.4  christos struct trap    *
     89  1.8  dholland maketrap(int x, int y, int typ)
     90  1.1       cgd {
     91  1.4  christos 	struct trap    *ttmp;
     92  1.1       cgd 
     93  1.1       cgd 	ttmp = newtrap();
     94  1.1       cgd 	ttmp->ttyp = typ;
     95  1.1       cgd 	ttmp->tseen = 0;
     96  1.1       cgd 	ttmp->once = 0;
     97  1.1       cgd 	ttmp->tx = x;
     98  1.1       cgd 	ttmp->ty = y;
     99  1.1       cgd 	ttmp->ntrap = ftrap;
    100  1.1       cgd 	ftrap = ttmp;
    101  1.4  christos 	return (ttmp);
    102  1.1       cgd }
    103  1.1       cgd 
    104  1.4  christos void
    105  1.8  dholland dotrap(struct trap *trap)
    106  1.4  christos {
    107  1.4  christos 	int             ttype = trap->ttyp;
    108  1.1       cgd 
    109  1.1       cgd 	nomul(0);
    110  1.4  christos 	if (trap->tseen && !rn2(5) && ttype != PIT)
    111  1.1       cgd 		pline("You escape a%s.", traps[ttype]);
    112  1.1       cgd 	else {
    113  1.1       cgd 		trap->tseen = 1;
    114  1.4  christos 		switch (ttype) {
    115  1.1       cgd 		case SLP_GAS_TRAP:
    116  1.1       cgd 			pline("A cloud of gas puts you to sleep!");
    117  1.1       cgd 			nomul(-rnd(25));
    118  1.1       cgd 			break;
    119  1.1       cgd 		case BEAR_TRAP:
    120  1.4  christos 			if (Levitation) {
    121  1.1       cgd 				pline("You float over a bear trap.");
    122  1.1       cgd 				break;
    123  1.1       cgd 			}
    124  1.1       cgd 			u.utrap = 4 + rn2(4);
    125  1.1       cgd 			u.utraptype = TT_BEARTRAP;
    126  1.1       cgd 			pline("A bear trap closes on your foot!");
    127  1.1       cgd 			break;
    128  1.1       cgd 		case PIERC:
    129  1.1       cgd 			deltrap(trap);
    130  1.4  christos 			if (makemon(PM_PIERCER, u.ux, u.uy)) {
    131  1.4  christos 				pline("A piercer suddenly drops from the ceiling!");
    132  1.4  christos 				if (uarmh)
    133  1.4  christos 					pline("Its blow glances off your helmet.");
    134  1.4  christos 				else
    135  1.4  christos 					(void) thitu(3, d(4, 6), "falling piercer");
    136  1.1       cgd 			}
    137  1.1       cgd 			break;
    138  1.1       cgd 		case ARROW_TRAP:
    139  1.1       cgd 			pline("An arrow shoots out at you!");
    140  1.4  christos 			if (!thitu(8, rnd(6), "arrow")) {
    141  1.1       cgd 				mksobj_at(ARROW, u.ux, u.uy);
    142  1.1       cgd 				fobj->quan = 1;
    143  1.1       cgd 			}
    144  1.1       cgd 			break;
    145  1.1       cgd 		case TRAPDOOR:
    146  1.4  christos 			if (!xdnstair) {
    147  1.4  christos 				pline("A trap door in the ceiling opens and a rock falls on your head!");
    148  1.4  christos 				if (uarmh)
    149  1.4  christos 					pline("Fortunately, you are wearing a helmet!");
    150  1.4  christos 				losehp(uarmh ? 2 : d(2, 10), "falling rock");
    151  1.4  christos 				mksobj_at(ROCK, u.ux, u.uy);
    152  1.4  christos 				fobj->quan = 1;
    153  1.4  christos 				stackobj(fobj);
    154  1.4  christos 				if (Invisible)
    155  1.4  christos 					newsym(u.ux, u.uy);
    156  1.1       cgd 			} else {
    157  1.4  christos 				int             newlevel = dlevel + 1;
    158  1.4  christos 				while (!rn2(4) && newlevel < 29)
    159  1.1       cgd 					newlevel++;
    160  1.1       cgd 				pline("A trap door opens up under you!");
    161  1.4  christos 				if (Levitation || u.ustuck) {
    162  1.4  christos 					pline("For some reason you don't fall in.");
    163  1.1       cgd 					break;
    164  1.1       cgd 				}
    165  1.1       cgd 				goto_level(newlevel, FALSE);
    166  1.1       cgd 			}
    167  1.1       cgd 			break;
    168  1.1       cgd 		case DART_TRAP:
    169  1.1       cgd 			pline("A little dart shoots out at you!");
    170  1.4  christos 			if (thitu(7, rnd(3), "little dart")) {
    171  1.4  christos 				if (!rn2(6))
    172  1.4  christos 					poisoned("dart", "poison dart");
    173  1.1       cgd 			} else {
    174  1.1       cgd 				mksobj_at(DART, u.ux, u.uy);
    175  1.1       cgd 				fobj->quan = 1;
    176  1.1       cgd 			}
    177  1.1       cgd 			break;
    178  1.1       cgd 		case TELEP_TRAP:
    179  1.4  christos 			if (trap->once) {
    180  1.1       cgd 				deltrap(trap);
    181  1.4  christos 				newsym(u.ux, u.uy);
    182  1.1       cgd 				vtele();
    183  1.1       cgd 			} else {
    184  1.4  christos 				newsym(u.ux, u.uy);
    185  1.1       cgd 				tele();
    186  1.1       cgd 			}
    187  1.1       cgd 			break;
    188  1.1       cgd 		case PIT:
    189  1.4  christos 			if (Levitation) {
    190  1.1       cgd 				pline("A pit opens up under you!");
    191  1.1       cgd 				pline("You don't fall in!");
    192  1.1       cgd 				break;
    193  1.1       cgd 			}
    194  1.1       cgd 			pline("You fall into a pit!");
    195  1.4  christos 			u.utrap = rn1(6, 2);
    196  1.1       cgd 			u.utraptype = TT_PIT;
    197  1.4  christos 			losehp(rnd(6), "fall into a pit");
    198  1.1       cgd 			selftouch("Falling, you");
    199  1.1       cgd 			break;
    200  1.1       cgd 		default:
    201  1.1       cgd 			impossible("You hit a trap of type %u", trap->ttyp);
    202  1.1       cgd 		}
    203  1.1       cgd 	}
    204  1.1       cgd }
    205  1.1       cgd 
    206  1.4  christos int
    207  1.8  dholland mintrap(struct monst *mtmp)
    208  1.4  christos {
    209  1.4  christos 	struct trap    *trap = t_at(mtmp->mx, mtmp->my);
    210  1.4  christos 	int             wasintrap = mtmp->mtrapped;
    211  1.1       cgd 
    212  1.4  christos 	if (!trap) {
    213  1.1       cgd 		mtmp->mtrapped = 0;	/* perhaps teleported? */
    214  1.4  christos 	} else if (wasintrap) {
    215  1.4  christos 		if (!rn2(40))
    216  1.4  christos 			mtmp->mtrapped = 0;
    217  1.1       cgd 	} else {
    218  1.4  christos 		int             tt = trap->ttyp;
    219  1.4  christos 		int             in_sight = cansee(mtmp->mx, mtmp->my);
    220  1.4  christos 
    221  1.4  christos 		if (mtmp->mtrapseen & (1 << tt)) {
    222  1.4  christos 			/* he has been in such a trap - perhaps he escapes */
    223  1.4  christos 			if (rn2(4))
    224  1.4  christos 				return (0);
    225  1.4  christos 		}
    226  1.4  christos 		mtmp->mtrapseen |= (1 << tt);
    227  1.4  christos 		switch (tt) {
    228  1.1       cgd 		case BEAR_TRAP:
    229  1.4  christos 			if (strchr(mlarge, mtmp->data->mlet)) {
    230  1.4  christos 				if (in_sight)
    231  1.4  christos 					pline("%s is caught in a bear trap!",
    232  1.4  christos 					      Monnam(mtmp));
    233  1.4  christos 				else if (mtmp->data->mlet == 'o')
    234  1.4  christos 					pline("You hear the roaring of an angry bear!");
    235  1.1       cgd 				mtmp->mtrapped = 1;
    236  1.1       cgd 			}
    237  1.1       cgd 			break;
    238  1.1       cgd 		case PIT:
    239  1.1       cgd 			/* there should be a mtmp/data -> floating */
    240  1.4  christos 			if (!strchr("EywBfk'& ", mtmp->data->mlet)) {	/* ab */
    241  1.1       cgd 				mtmp->mtrapped = 1;
    242  1.4  christos 				if (in_sight)
    243  1.4  christos 					pline("%s falls in a pit!", Monnam(mtmp));
    244  1.1       cgd 			}
    245  1.1       cgd 			break;
    246  1.1       cgd 		case SLP_GAS_TRAP:
    247  1.4  christos 			if (!mtmp->msleep && !mtmp->mfroz) {
    248  1.1       cgd 				mtmp->msleep = 1;
    249  1.4  christos 				if (in_sight)
    250  1.4  christos 					pline("%s suddenly falls asleep!",
    251  1.4  christos 					      Monnam(mtmp));
    252  1.1       cgd 			}
    253  1.1       cgd 			break;
    254  1.1       cgd 		case TELEP_TRAP:
    255  1.1       cgd 			rloc(mtmp);
    256  1.4  christos 			if (in_sight && !cansee(mtmp->mx, mtmp->my))
    257  1.1       cgd 				pline("%s suddenly disappears!",
    258  1.4  christos 				      Monnam(mtmp));
    259  1.1       cgd 			break;
    260  1.1       cgd 		case ARROW_TRAP:
    261  1.4  christos 			if (in_sight) {
    262  1.1       cgd 				pline("%s is hit by an arrow!",
    263  1.4  christos 				      Monnam(mtmp));
    264  1.1       cgd 			}
    265  1.1       cgd 			mtmp->mhp -= 3;
    266  1.1       cgd 			break;
    267  1.1       cgd 		case DART_TRAP:
    268  1.4  christos 			if (in_sight) {
    269  1.1       cgd 				pline("%s is hit by a dart!",
    270  1.4  christos 				      Monnam(mtmp));
    271  1.1       cgd 			}
    272  1.1       cgd 			mtmp->mhp -= 2;
    273  1.1       cgd 			/* not mondied here !! */
    274  1.1       cgd 			break;
    275  1.1       cgd 		case TRAPDOOR:
    276  1.4  christos 			if (!xdnstair) {
    277  1.1       cgd 				mtmp->mhp -= 10;
    278  1.4  christos 				if (in_sight)
    279  1.4  christos 					pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
    280  1.1       cgd 				break;
    281  1.1       cgd 			}
    282  1.4  christos 			if (mtmp->data->mlet != 'w') {
    283  1.1       cgd 				fall_down(mtmp);
    284  1.4  christos 				if (in_sight)
    285  1.4  christos 					pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
    286  1.4  christos 				return (2);	/* no longer on this level */
    287  1.1       cgd 			}
    288  1.1       cgd 			break;
    289  1.1       cgd 		case PIERC:
    290  1.1       cgd 			break;
    291  1.1       cgd 		default:
    292  1.1       cgd 			impossible("Some monster encountered a strange trap.");
    293  1.4  christos 		}
    294  1.1       cgd 	}
    295  1.4  christos 	return (mtmp->mtrapped);
    296  1.1       cgd }
    297  1.1       cgd 
    298  1.4  christos void
    299  1.8  dholland selftouch(const char *arg)
    300  1.4  christos {
    301  1.4  christos 	if (uwep && uwep->otyp == DEAD_COCKATRICE) {
    302  1.1       cgd 		pline("%s touch the dead cockatrice.", arg);
    303  1.1       cgd 		pline("You turn to stone.");
    304  1.1       cgd 		killer = objects[uwep->otyp].oc_name;
    305  1.1       cgd 		done("died");
    306  1.1       cgd 	}
    307  1.1       cgd }
    308  1.1       cgd 
    309  1.4  christos void
    310  1.8  dholland float_up(void)
    311  1.4  christos {
    312  1.4  christos 	if (u.utrap) {
    313  1.4  christos 		if (u.utraptype == TT_PIT) {
    314  1.1       cgd 			u.utrap = 0;
    315  1.1       cgd 			pline("You float up, out of the pit!");
    316  1.1       cgd 		} else {
    317  1.1       cgd 			pline("You float up, only your leg is still stuck.");
    318  1.1       cgd 		}
    319  1.1       cgd 	} else
    320  1.1       cgd 		pline("You start to float in the air!");
    321  1.1       cgd }
    322  1.1       cgd 
    323  1.4  christos void
    324  1.8  dholland float_down(void)
    325  1.4  christos {
    326  1.4  christos 	struct trap    *trap;
    327  1.1       cgd 	pline("You float gently to the ground.");
    328  1.4  christos 	if ((trap = t_at(u.ux, u.uy)) != NULL)
    329  1.4  christos 		switch (trap->ttyp) {
    330  1.1       cgd 		case PIERC:
    331  1.1       cgd 			break;
    332  1.1       cgd 		case TRAPDOOR:
    333  1.4  christos 			if (!xdnstair || u.ustuck)
    334  1.4  christos 				break;
    335  1.1       cgd 			/* fall into next case */
    336  1.1       cgd 		default:
    337  1.1       cgd 			dotrap(trap);
    338  1.4  christos 		}
    339  1.1       cgd 	pickup(1);
    340  1.1       cgd }
    341  1.1       cgd 
    342  1.4  christos void
    343  1.8  dholland vtele(void)
    344  1.4  christos {
    345  1.4  christos 	struct mkroom  *croom;
    346  1.4  christos 	for (croom = &rooms[0]; croom->hx >= 0; croom++)
    347  1.4  christos 		if (croom->rtype == VAULT) {
    348  1.4  christos 			int x, y;
    349  1.4  christos 
    350  1.4  christos 			x = rn2(2) ? croom->lx : croom->hx;
    351  1.4  christos 			y = rn2(2) ? croom->ly : croom->hy;
    352  1.4  christos 			if (teleok(x, y)) {
    353  1.4  christos 				teleds(x, y);
    354  1.4  christos 				return;
    355  1.4  christos 			}
    356  1.1       cgd 		}
    357  1.1       cgd 	tele();
    358  1.1       cgd }
    359  1.1       cgd 
    360  1.4  christos void
    361  1.8  dholland tele(void)
    362  1.4  christos {
    363  1.4  christos 	coord           cc;
    364  1.4  christos 	int             nux, nuy;
    365  1.1       cgd 
    366  1.4  christos 	if (Teleport_control) {
    367  1.1       cgd 		pline("To what position do you want to be teleported?");
    368  1.4  christos 		cc = getpos(1, "the desired position");	/* 1: force valid */
    369  1.4  christos 		/*
    370  1.4  christos 		 * possible extensions: introduce a small error if magic
    371  1.4  christos 		 * power is low; allow transfer to solid rock
    372  1.4  christos 		 */
    373  1.4  christos 		if (teleok(cc.x, cc.y)) {
    374  1.1       cgd 			teleds(cc.x, cc.y);
    375  1.1       cgd 			return;
    376  1.1       cgd 		}
    377  1.1       cgd 		pline("Sorry ...");
    378  1.1       cgd 	}
    379  1.1       cgd 	do {
    380  1.4  christos 		nux = rnd(COLNO - 1);
    381  1.1       cgd 		nuy = rn2(ROWNO);
    382  1.4  christos 	} while (!teleok(nux, nuy));
    383  1.1       cgd 	teleds(nux, nuy);
    384  1.1       cgd }
    385  1.1       cgd 
    386  1.4  christos void
    387  1.8  dholland teleds(int nux, int nuy)
    388  1.1       cgd {
    389  1.4  christos 	if (Punished)
    390  1.4  christos 		unplacebc();
    391  1.1       cgd 	unsee();
    392  1.1       cgd 	u.utrap = 0;
    393  1.1       cgd 	u.ustuck = 0;
    394  1.1       cgd 	u.ux = nux;
    395  1.1       cgd 	u.uy = nuy;
    396  1.1       cgd 	setsee();
    397  1.4  christos 	if (Punished)
    398  1.4  christos 		placebc(1);
    399  1.4  christos 	if (u.uswallow) {
    400  1.1       cgd 		u.uswldtim = u.uswallow = 0;
    401  1.1       cgd 		docrt();
    402  1.1       cgd 	}
    403  1.1       cgd 	nomul(0);
    404  1.4  christos 	if (levl[nux][nuy].typ == POOL && !Levitation)
    405  1.1       cgd 		drown();
    406  1.1       cgd 	(void) inshop();
    407  1.1       cgd 	pickup(1);
    408  1.4  christos 	if (!Blind)
    409  1.4  christos 		read_engr_at(u.ux, u.uy);
    410  1.1       cgd }
    411  1.1       cgd 
    412  1.4  christos int
    413  1.8  dholland teleok(int x, int y)
    414  1.4  christos {				/* might throw him into a POOL */
    415  1.4  christos 	return (isok(x, y) && !IS_ROCK(levl[x][y].typ) && !m_at(x, y) &&
    416  1.4  christos 		!sobj_at(ENORMOUS_ROCK, x, y) && !t_at(x, y)
    417  1.4  christos 		);
    418  1.1       cgd 	/* Note: gold is permitted (because of vaults) */
    419  1.1       cgd }
    420  1.1       cgd 
    421  1.4  christos int
    422  1.8  dholland dotele(void)
    423  1.4  christos {
    424  1.4  christos 	if (
    425  1.1       cgd #ifdef WIZARD
    426  1.4  christos 	    !wizard &&
    427  1.4  christos #endif	/* WIZARD */
    428  1.4  christos 	    (!Teleportation || u.ulevel < 6 ||
    429  1.4  christos 	     (pl_character[0] != 'W' && u.ulevel < 10))) {
    430  1.1       cgd 		pline("You are not able to teleport at will.");
    431  1.4  christos 		return (0);
    432  1.1       cgd 	}
    433  1.4  christos 	if (u.uhunger <= 100 || u.ustr < 6) {
    434  1.1       cgd 		pline("You miss the strength for a teleport spell.");
    435  1.4  christos 		return (1);
    436  1.1       cgd 	}
    437  1.1       cgd 	tele();
    438  1.1       cgd 	morehungry(100);
    439  1.4  christos 	return (1);
    440  1.1       cgd }
    441  1.1       cgd 
    442  1.4  christos void
    443  1.8  dholland placebc(int attach)
    444  1.4  christos {
    445  1.4  christos 	if (!uchain || !uball) {
    446  1.1       cgd 		impossible("Where are your chain and ball??");
    447  1.1       cgd 		return;
    448  1.1       cgd 	}
    449  1.1       cgd 	uball->ox = uchain->ox = u.ux;
    450  1.1       cgd 	uball->oy = uchain->oy = u.uy;
    451  1.4  christos 	if (attach) {
    452  1.1       cgd 		uchain->nobj = fobj;
    453  1.1       cgd 		fobj = uchain;
    454  1.4  christos 		if (!carried(uball)) {
    455  1.1       cgd 			uball->nobj = fobj;
    456  1.1       cgd 			fobj = uball;
    457  1.1       cgd 		}
    458  1.1       cgd 	}
    459  1.1       cgd }
    460  1.1       cgd 
    461  1.4  christos void
    462  1.8  dholland unplacebc(void)
    463  1.4  christos {
    464  1.4  christos 	if (!carried(uball)) {
    465  1.1       cgd 		freeobj(uball);
    466  1.1       cgd 		unpobj(uball);
    467  1.1       cgd 	}
    468  1.1       cgd 	freeobj(uchain);
    469  1.1       cgd 	unpobj(uchain);
    470  1.1       cgd }
    471  1.1       cgd 
    472  1.4  christos void
    473  1.8  dholland level_tele(void)
    474  1.4  christos {
    475  1.4  christos 	int             newlevel;
    476  1.4  christos 	if (Teleport_control) {
    477  1.4  christos 		char            buf[BUFSZ];
    478  1.4  christos 
    479  1.4  christos 		do {
    480  1.4  christos 			pline("To what level do you want to teleport? [type a number] ");
    481  1.4  christos 			getlin(buf);
    482  1.4  christos 		} while (!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
    483  1.4  christos 		newlevel = atoi(buf);
    484  1.1       cgd 	} else {
    485  1.4  christos 		newlevel = 5 + rn2(20);	/* 5 - 24 */
    486  1.5     veego 		if (dlevel == newlevel) {
    487  1.4  christos 			if (!xdnstair)
    488  1.4  christos 				newlevel--;
    489  1.4  christos 			else
    490  1.4  christos 				newlevel++;
    491  1.5     veego 		}
    492  1.4  christos 	}
    493  1.4  christos 	if (newlevel >= 30) {
    494  1.4  christos 		if (newlevel > MAXLEVEL)
    495  1.4  christos 			newlevel = MAXLEVEL;
    496  1.4  christos 		pline("You arrive at the center of the earth ...");
    497  1.4  christos 		pline("Unfortunately it is here that hell is located.");
    498  1.4  christos 		if (Fire_resistance) {
    499  1.4  christos 			pline("But the fire doesn't seem to harm you.");
    500  1.4  christos 		} else {
    501  1.4  christos 			pline("You burn to a crisp.");
    502  1.4  christos 			dlevel = maxdlevel = newlevel;
    503  1.4  christos 			killer = "visit to the hell";
    504  1.4  christos 			done("burned");
    505  1.4  christos 		}
    506  1.4  christos 	}
    507  1.4  christos 	if (newlevel < 0) {
    508  1.4  christos 		newlevel = 0;
    509  1.4  christos 		pline("You are now high above the clouds ...");
    510  1.4  christos 		if (Levitation) {
    511  1.4  christos 			pline("You float gently down to earth.");
    512  1.4  christos 			done("escaped");
    513  1.4  christos 		}
    514  1.4  christos 		pline("Unfortunately, you don't know how to fly.");
    515  1.4  christos 		pline("You fall down a few thousand feet and break your neck.");
    516  1.4  christos 		dlevel = 0;
    517  1.4  christos 		killer = "fall";
    518  1.4  christos 		done("died");
    519  1.1       cgd 	}
    520  1.4  christos 	goto_level(newlevel, FALSE);	/* calls done("escaped") if
    521  1.4  christos 					 * newlevel==0 */
    522  1.1       cgd }
    523  1.1       cgd 
    524  1.4  christos void
    525  1.8  dholland drown(void)
    526  1.1       cgd {
    527  1.1       cgd 	pline("You fall into a pool!");
    528  1.1       cgd 	pline("You can't swim!");
    529  1.4  christos 	if (rn2(3) < u.uluck + 2) {
    530  1.1       cgd 		/* most scrolls become unreadable */
    531  1.4  christos 		struct obj     *obj;
    532  1.1       cgd 
    533  1.4  christos 		for (obj = invent; obj; obj = obj->nobj)
    534  1.4  christos 			if (obj->olet == SCROLL_SYM && rn2(12) > u.uluck)
    535  1.1       cgd 				obj->otyp = SCR_BLANK_PAPER;
    536  1.1       cgd 		/* we should perhaps merge these scrolls ? */
    537  1.1       cgd 
    538  1.1       cgd 		pline("You attempt a teleport spell.");	/* utcsri!carroll */
    539  1.1       cgd 		(void) dotele();
    540  1.4  christos 		if (levl[u.ux][u.uy].typ != POOL)
    541  1.4  christos 			return;
    542  1.1       cgd 	}
    543  1.1       cgd 	pline("You drown ...");
    544  1.1       cgd 	killer = "pool of water";
    545  1.1       cgd 	done("drowned");
    546  1.1       cgd }
    547