home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume10 / nethack3p9 / part08 < prev    next >
Internet Message Format  |  1990-07-12  |  61KB

  1. Path: uunet!ns-mx!iowasp.physics.uiowa.edu!maverick.ksu.ksu.edu!ux1.cso.uiuc.edu!brutus.cs.uiuc.edu!wuarchive!mit-eddie!uw-beaver!zephyr.ens.tek.com!tekred!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v10i053:  nethack3p9 -  display oriented dungeons & dragons (Ver. 3.0i), Part08/56
  5. Message-ID: <5908@tekred.CNA.TEK.COM>
  6. Date: 12 Jul 90 00:29:03 GMT
  7. Sender: news@tekred.CNA.TEK.COM
  8. Lines: 2616
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: Izchak Miller <izchak@linc.cis.upenn.edu>
  12. Posting-number: Volume 10, Issue 53
  13. Archive-name: nethack3p9/Part08
  14. Supersedes: NetHack3: Volume 7, Issue 56-93
  15.  
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 8 (of 56)."
  25. # Contents:  src/prisym.c src/trap.c
  26. # Wrapped by billr@saab on Wed Jul 11 17:11:00 1990
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'src/prisym.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'src/prisym.c'\"
  30. else
  31. echo shar: Extracting \"'src/prisym.c'\" \(12560 characters\)
  32. sed "s/^X//" >'src/prisym.c' <<'END_OF_FILE'
  33. X/*    SCCS Id: @(#)prisym.c    3.0    89/11/15
  34. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  35. X/* NetHack may be freely redistributed.  See license for details. */
  36. X
  37. X#include "hack.h"
  38. X
  39. X#ifdef WORM
  40. X#include "wseg.h"
  41. X#include "lev.h"
  42. X
  43. XSTATIC_DCL void FDECL(pwseg, (struct wseg *));
  44. X#endif
  45. X
  46. X#ifdef OVL0
  47. X
  48. Xvoid
  49. Xatl(x,y,ch)
  50. Xregister int x, y;
  51. Xchar ch;
  52. X{
  53. X    register struct rm *crm = &levl[x][y];
  54. X
  55. X    if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1){
  56. X        impossible("atl(%d,%d,%c)",x,y,ch);
  57. X        return;
  58. X    }
  59. X    if(crm->seen && crm->scrsym == ch) return;
  60. X    /* crm->scrsym = (uchar) ch; */
  61. X    /* wrong if characters are signed but uchar is larger than char,
  62. X     * and ch, when passed, was greater than 127.
  63. X     * We probably should _really_ go around changing atl to take a
  64. X     * uchar for its third argument...
  65. X     */
  66. X    crm->scrsym = (uchar)((unsigned char) ch);
  67. X    crm->new = 1;
  68. X    on_scr(x,y);
  69. X}
  70. X
  71. Xvoid
  72. Xon_scr(x,y)
  73. Xregister int x, y;
  74. X{
  75. X    if(x < scrlx) scrlx = x;
  76. X    if(x > scrhx) scrhx = x;
  77. X    if(y < scrly) scrly = y;
  78. X    if(y > scrhy) scrhy = y;
  79. X}
  80. X
  81. X#endif /* OVL0 */
  82. X#ifdef OVL2
  83. X
  84. X/* call: (x,y) - display
  85. X    (-1,0) - close (leave last symbol)
  86. X    (-1,-1)- close (undo last symbol)
  87. X    (-1,let)-open: initialize symbol
  88. X    (-2,let)-change let
  89. X    (-3,let)-set color
  90. X*/
  91. X
  92. Xvoid
  93. Xtmp_at(x, y)
  94. Xint x, y;
  95. X{
  96. X#ifdef LINT    /* static schar prevx, prevy; static char let; */
  97. Xschar prevx=0, prevy=0;
  98. Xuchar let;
  99. Xuchar col;
  100. X#else
  101. Xstatic schar NEARDATA prevx, NEARDATA prevy;
  102. Xstatic uchar NEARDATA let;
  103. Xstatic uchar NEARDATA col;
  104. X#endif
  105. X
  106. X    switch ((int)x) {
  107. X        case -2:        /* change let call */
  108. X        let = y;
  109. X        return;
  110. X        case -1:        /* open or close call */
  111. X        if ((int)y >= 0) {
  112. X            let = y;
  113. X            prevx = -1;
  114. X            col = AT_ZAP;
  115. X            return;
  116. X        }
  117. X        break;
  118. X        case -3:        /* set color call */
  119. X        col = y;
  120. X        return;
  121. X    }
  122. X    if(prevx >= 0 && cansee(prevx,prevy)) {
  123. X        delay_output();
  124. X        prl(prevx, prevy);    /* in case there was a monster */
  125. X        at(prevx, prevy, levl[prevx][prevy].scrsym, AT_APP);
  126. X    }
  127. X    if(x >= 0){    /* normal call */
  128. X        if(cansee(x,y)) at(x,y,let,col);
  129. X        prevx = x;
  130. X        prevy = y;
  131. X    } else {    /* close call */
  132. X        let = 0;
  133. X        prevx = -1;
  134. X    }
  135. X}
  136. X
  137. X/* like the previous, but the symbols are first erased on completion */
  138. Xvoid
  139. XTmp_at2(x, y)
  140. Xint x, y;
  141. X{
  142. X#ifdef LINT    /* static char let; static xchar cnt; static coord tc[COLNO]; */
  143. Xuchar let;
  144. Xxchar cnt;
  145. Xcoord tc[COLNO];    /* but watch reflecting beams! */
  146. X# ifdef TEXTCOLOR
  147. Xuchar col;
  148. X# endif
  149. X#else
  150. Xstatic uchar NEARDATA let;
  151. Xstatic xchar NEARDATA cnt;
  152. Xstatic coord NEARDATA tc[COLNO];    /* but watch reflecting beams! */
  153. X# ifdef TEXTCOLOR
  154. Xstatic uchar NEARDATA col;
  155. X# endif
  156. X#endif
  157. Xregister int xx,yy;
  158. X    switch((int)x) {
  159. X        case -1:
  160. X        if(y > 0) {    /* open call */
  161. X            let = y;
  162. X            cnt = 0;
  163. X#ifdef TEXTCOLOR
  164. X            col = AT_ZAP;
  165. X#endif
  166. X            return;
  167. X        }
  168. X        /* close call (do not distinguish y==0 and y==-1) */
  169. X        while(cnt--) {
  170. X            xx = tc[cnt].x;
  171. X            yy = tc[cnt].y;
  172. X            prl(xx, yy);
  173. X            at(xx, yy, levl[xx][yy].scrsym, AT_APP);
  174. X        }
  175. X        cnt = let = 0;    /* superfluous */
  176. X        return;
  177. X        case -2:        /* change let call */
  178. X        let = y;
  179. X        return;
  180. X#ifdef TEXTCOLOR
  181. X        case -3:        /* set color call */
  182. X        col = y;
  183. X        return;
  184. X#endif
  185. X    }
  186. X    /* normal call */
  187. X    if(cansee(x,y)) {
  188. X        if(cnt) delay_output();
  189. X#ifdef TEXTCOLOR
  190. X        at(x,y,let,col);
  191. X#else
  192. X        at(x,y,let,AT_ZAP);
  193. X#endif
  194. X        tc[cnt].x = x;
  195. X        tc[cnt].y = y;
  196. X        if(++cnt >= COLNO) panic("Tmp_at2 overflow?");
  197. X        levl[x][y].new = 0;    /* prevent pline-nscr erasing --- */
  198. X    }
  199. X}
  200. X
  201. X#endif /* OVL2 */
  202. X#ifdef OVL1
  203. X
  204. Xvoid
  205. Xcurs_on_u()
  206. X{
  207. X#ifdef CLIPPING
  208. X    cliparound(u.ux, u.uy);
  209. X    (void)win_curs(u.ux, u.uy);
  210. X#else
  211. X    curs(u.ux, u.uy+2);
  212. X#endif
  213. X}
  214. X
  215. Xvoid
  216. Xpru()
  217. X{
  218. X    if(u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy))
  219. X        /* if(! levl[u.udisx][u.udisy].new) */
  220. X            if(!vism_at(u.udisx, u.udisy))
  221. X                newsym(u.udisx, u.udisy);
  222. X    if(Invisible
  223. X#ifdef POLYSELF
  224. X            || u.uundetected
  225. X#endif
  226. X                    ) {
  227. X        u.udispl = 0;
  228. X        prl(u.ux,u.uy);
  229. X    } else
  230. X    if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
  231. X        atl(u.ux, u.uy, (char) u.usym);
  232. X        u.udispl = 1;
  233. X        u.udisx = u.ux;
  234. X        u.udisy = u.uy;
  235. X    }
  236. X    levl[u.ux][u.uy].seen = 1;
  237. X}
  238. X
  239. X#endif /* OVL1 */
  240. X#ifdef OVL0
  241. X
  242. X/* print a position that is visible for @ */
  243. Xvoid
  244. Xprl(x,y)
  245. Xint x, y;
  246. X{
  247. X    register struct rm *room;
  248. X    register struct monst *mtmp = (struct monst *)0;
  249. X    register struct obj *otmp;
  250. X    register struct trap *ttmp;
  251. X
  252. X    if(x == u.ux && y == u.uy && !Invisible
  253. X#ifdef POLYSELF
  254. X                        && !u.uundetected
  255. X#endif
  256. X                                ) {
  257. X        pru();
  258. X        return;
  259. X    }
  260. X    if(!isok(x,y)) return;
  261. X    room = &levl[x][y];
  262. X    if((!room->typ) ||
  263. X       (IS_ROCK(room->typ) && levl[u.ux][u.uy].typ == CORR &&
  264. X                  !levl[u.ux][u.uy].lit))
  265. X        /* the only lit corridor squares should be the entrances to
  266. X         * outside castle areas */
  267. X        return;
  268. X    if(MON_AT(x, y)) mtmp = m_at(x,y);
  269. X    if(mtmp && !mtmp->mhide &&
  270. X        (!mtmp->minvis || See_invisible)) {
  271. X#ifdef WORM
  272. X        if(m_atseg)
  273. X            pwseg(m_atseg);
  274. X        else
  275. X#endif
  276. X        pmon(mtmp);
  277. X    }
  278. X    else if(OBJ_AT(x, y) && !is_pool(x,y)) {
  279. X        otmp = level.objects[x][y];
  280. X        atl(x,y,Hallucination ? rndobjsym() : otmp->olet);
  281. X    }
  282. X    else if(room->gmask && !is_pool(x,y))
  283. X        atl(x,y,Hallucination ? rndobjsym() : GOLD_SYM);
  284. X    else if((!mtmp || mtmp->data == &mons[PM_GIANT_SPIDER]) &&
  285. X          (ttmp = t_at(x,y)) && ttmp->ttyp == WEB)
  286. X        atl(x,y,(char)WEB_SYM);
  287. X    else if(mtmp && (!mtmp->minvis || See_invisible)) {
  288. X        /* must be a hiding monster, but not hiding right now */
  289. X        /* assume for the moment that long worms do not hide */
  290. X        pmon(mtmp);
  291. X    }
  292. X    else if(!room->seen || room->scrsym == STONE_SYM) {
  293. X        room->new = room->seen = 1;
  294. X        newsym(x,y);
  295. X        on_scr(x,y);
  296. X    }
  297. X    room->seen = 1;
  298. X}
  299. X
  300. Xuchar
  301. Xnews0(x,y)
  302. Xregister xchar x,y;
  303. X{
  304. X    register struct obj *otmp;
  305. X    register struct trap *ttmp;
  306. X    struct rm *room;
  307. X    register uchar tmp;    /* don't compare char with uchar -- OIS */
  308. X    register int croom;
  309. X
  310. X    room = &levl[x][y];
  311. X    /* note: a zero scrsym means to ignore the presence of objects */
  312. X    if(!room->seen) tmp = STONE_SYM;
  313. X    else if(room->typ == POOL || room->typ == MOAT) tmp = POOL_SYM;
  314. X    else if(OBJ_AT(x, y) && !Blind && room->scrsym) {
  315. X        otmp = level.objects[x][y];
  316. X        tmp = Hallucination ? rndobjsym() : otmp->olet;
  317. X    }
  318. X    else if(room->gmask && !Blind && room->scrsym) 
  319. X        tmp = Hallucination ? rndobjsym() : GOLD_SYM;
  320. X    else if(x == xupstair && y == yupstair) tmp = UP_SYM;
  321. X    else if(x == xdnstair && y == ydnstair) tmp = DN_SYM;
  322. X#ifdef STRONGHOLD
  323. X    else if(x == xupladder && y == yupladder) tmp = UPLADDER_SYM;
  324. X    else if(x == xdnladder && y == ydnladder) tmp = DNLADDER_SYM;
  325. X#endif
  326. X    else if((ttmp = t_at(x,y)) && ttmp->ttyp == WEB) tmp = WEB_SYM;
  327. X    else if(ttmp && ttmp->tseen) tmp = TRAP_SYM;
  328. X    else switch(room->typ) {
  329. X    case SCORR:
  330. X        tmp = ' ';    /* _not_ STONE_SYM! */
  331. X        break;
  332. X    case SDOOR:
  333. X        croom = inroom(x,y);
  334. X        if(croom == -1) {
  335. X#ifdef STRONGHOLD
  336. X            if(IS_WALL(levl[x-1][y].typ)) tmp = HWALL_SYM;
  337. X            else tmp = VWALL_SYM;
  338. X            break;
  339. X#else
  340. X            impossible("door %d %d not in room",x,y);
  341. X#endif
  342. X        }
  343. X        if(rooms[croom].lx-1 == x || rooms[croom].hx+1 == x)
  344. X            tmp = VWALL_SYM;
  345. X        else    /* SDOORs aren't created on corners */
  346. X            tmp = HWALL_SYM;
  347. X          break;
  348. X    case HWALL:
  349. X#ifdef STRONGHOLD
  350. X        if (is_maze_lev && is_drawbridge_wall(x,y) >= 0) tmp = DB_HWALL_SYM;
  351. X        else
  352. X#endif
  353. X        tmp = HWALL_SYM;
  354. X        break;
  355. X    case VWALL:
  356. X#ifdef STRONGHOLD
  357. X        if (is_maze_lev && is_drawbridge_wall(x,y) >= 0) tmp = DB_VWALL_SYM;
  358. X        else
  359. X#endif
  360. X        tmp = VWALL_SYM;
  361. X        break;
  362. X    case TLCORNER:
  363. X        tmp = TLCORN_SYM;
  364. X        break;
  365. X    case TRCORNER:
  366. X        tmp = TRCORN_SYM;
  367. X        break;
  368. X    case BLCORNER:
  369. X        tmp = BLCORN_SYM;
  370. X        break;
  371. X    case BRCORNER:
  372. X        tmp = BRCORN_SYM;
  373. X        break;
  374. X    case DOOR:
  375. X        if (room->doormask == D_NODOOR || room->doormask & D_BROKEN)
  376. X            tmp = NO_DOOR_SYM;
  377. X        else if (room->doormask & (D_CLOSED|D_LOCKED))
  378. X            tmp = CLOSED_DOOR_SYM;
  379. X        /* We know door is open. */
  380. X        else {
  381. X            croom=inroom(x,y);
  382. X            if(croom == -1) {
  383. X#ifdef STRONGHOLD
  384. X            if(IS_WALL(levl[x-1][y].typ)||IS_WALL(levl[x+1][y].typ))
  385. X                tmp = H_OPEN_DOOR_SYM;
  386. X            else
  387. X                tmp = V_OPEN_DOOR_SYM;
  388. X#else
  389. X            impossible("door %d %d not in room",x,y);
  390. X#endif
  391. X            } else if(rooms[croom].ly<=y && y<=rooms[croom].hy)
  392. X            tmp = V_OPEN_DOOR_SYM;
  393. X            else
  394. X            tmp = H_OPEN_DOOR_SYM;
  395. X        }
  396. X        break;
  397. X    case CORR:
  398. X        tmp = CORR_SYM;
  399. X        break;
  400. X#ifdef STRONGHOLD
  401. X    case DRAWBRIDGE_UP:
  402. X        if((room->drawbridgemask & DB_UNDER) == DB_MOAT) tmp = POOL_SYM;
  403. X        else tmp = ROOM_SYM;
  404. X        break;
  405. X    case DRAWBRIDGE_DOWN:
  406. X#endif /* STRONGHOLD /**/
  407. X    case ROOM:
  408. X        if(room->lit || cansee(x,y) || Blind) tmp = ROOM_SYM;
  409. X        else tmp = STONE_SYM;
  410. X        break;
  411. X#ifdef POLYSELF
  412. X    case STONE:
  413. X        tmp = STONE_SYM;
  414. X        break;
  415. X#endif
  416. X#ifdef FOUNTAINS
  417. X    case FOUNTAIN:
  418. X        tmp = FOUNTAIN_SYM;
  419. X        break;
  420. X#endif
  421. X#ifdef THRONES
  422. X    case THRONE:
  423. X        tmp = THRONE_SYM;
  424. X        break;
  425. X#endif
  426. X#ifdef SINKS
  427. X    case SINK:
  428. X        tmp = SINK_SYM;
  429. X        break;
  430. X#endif
  431. X#ifdef ALTARS
  432. X    case ALTAR:
  433. X        tmp = ALTAR_SYM;
  434. X        break;
  435. X#endif
  436. X    case CROSSWALL:
  437. X        tmp = CRWALL_SYM;
  438. X        break;
  439. X    case TUWALL:
  440. X        tmp = TUWALL_SYM;
  441. X        break;
  442. X    case TDWALL:
  443. X        tmp = TDWALL_SYM;
  444. X        break;
  445. X    case TLWALL:
  446. X        tmp = TLWALL_SYM;
  447. X        break;
  448. X    case TRWALL:
  449. X        tmp = TRWALL_SYM;
  450. X        break;
  451. X/*
  452. X    case POOL:
  453. X        tmp = POOL_SYM;
  454. X        break;
  455. X*/
  456. X    default:
  457. X        tmp = ERRCHAR;
  458. X    }
  459. X    return(tmp);
  460. X}
  461. X
  462. Xvoid
  463. Xnewsym(x,y)
  464. Xregister int x, y;
  465. X{
  466. X    atl(x,y,(char)news0(x,y));
  467. X}
  468. X
  469. X#endif /* OVL0 */
  470. X#ifdef OVLB
  471. X
  472. X/* used with wand of digging (or pick-axe): fill scrsym and force display */
  473. X/* also when a POOL evaporates */
  474. Xvoid
  475. Xmnewsym(x, y)
  476. Xregister int x, y;
  477. X{
  478. X    register struct rm *room;
  479. X    uchar newscrsym;    /* OIS */
  480. X
  481. X    if(!vism_at(x,y)) {
  482. X        room = &levl[x][y];
  483. X        newscrsym = news0(x,y);
  484. X        if(room->scrsym != newscrsym) {
  485. X            room->scrsym = newscrsym;
  486. X            room->seen = 0;
  487. X        }
  488. X    }
  489. X}
  490. X
  491. X#endif /* OVLB */
  492. X#ifdef OVL1
  493. X
  494. Xvoid
  495. Xnosee(x,y)
  496. Xregister int x, y;
  497. X{
  498. X    register struct rm *room;
  499. X
  500. X    if(!isok(x,y)) return;
  501. X    room = &levl[x][y];
  502. X    if(levl[x][y].scrsym == ROOM_SYM
  503. X       && !room->lit && !Blind) {
  504. X        room->scrsym = STONE_SYM;    /* was ' ' -- OIS */
  505. X        room->new = 1;
  506. X        on_scr(x,y);
  507. X    }
  508. X}
  509. X
  510. Xvoid
  511. Xprl1(x,y)
  512. Xregister int x, y;
  513. X{
  514. X    if(u.dx) {
  515. X        if(u.dy) {
  516. X            prl(x-(2*u.dx),y);
  517. X            prl(x-u.dx,y);
  518. X            prl(x,y);
  519. X            prl(x,y-u.dy);
  520. X            prl(x,y-(2*u.dy));
  521. X        } else {
  522. X            prl(x,y-1);
  523. X            prl(x,y);
  524. X            prl(x,y+1);
  525. X        }
  526. X    } else {
  527. X        prl(x-1,y);
  528. X        prl(x,y);
  529. X        prl(x+1,y);
  530. X    }
  531. X}
  532. X
  533. Xvoid
  534. Xnose1(x,y)
  535. Xregister int x, y;
  536. X{
  537. X    if(u.dx) {
  538. X        if(u.dy) {
  539. X            nosee(x,u.uy);
  540. X            nosee(x,u.uy-u.dy);
  541. X            nosee(x,y);
  542. X            nosee(u.ux-u.dx,y);
  543. X            nosee(u.ux,y);
  544. X        } else {
  545. X            nosee(x,y-1);
  546. X            nosee(x,y);
  547. X            nosee(x,y+1);
  548. X        }
  549. X    } else {
  550. X        nosee(x-1,y);
  551. X        nosee(x,y);
  552. X        nosee(x+1,y);
  553. X    }
  554. X}
  555. X
  556. Xint
  557. Xvism_at(x,y)
  558. Xregister int x, y;
  559. X{
  560. X    if(x == u.ux && y == u.uy && !Invisible) return(1);
  561. X
  562. X    if(MON_AT(x, y))
  563. X        return(showmon(m_at(x,y)));
  564. X    return(0);
  565. X}
  566. X
  567. X#endif /* OVL1 */
  568. X#ifdef OVLB
  569. X
  570. X#ifdef NEWSCR
  571. Xvoid
  572. Xpobj(obj)
  573. Xregister struct obj *obj;
  574. X{
  575. X    register int show = (!obj->oinvis || See_invisible) &&
  576. X        cansee(obj->ox,obj->oy);
  577. X    if(obj->odispl){
  578. X        if(obj->odx != obj->ox || obj->ody != obj->oy || !show)
  579. X        if(!vism_at(obj->odx,obj->ody)){
  580. X            newsym(obj->odx, obj->ody);
  581. X            obj->odispl = 0;
  582. X        }
  583. X    }
  584. X    if(show && !vism_at(obj->ox,obj->oy)){
  585. X        atl(obj->ox,obj->oy,obj->olet);
  586. X        obj->odispl = 1;
  587. X        obj->odx = obj->ox;
  588. X        obj->ody = obj->oy;
  589. X    }
  590. X}
  591. X#endif /* NEWSCR /**/
  592. X
  593. Xvoid
  594. Xunpobj(obj)
  595. Xregister struct obj *obj;
  596. X{
  597. X/*     if(obj->odispl){
  598. X        if(!vism_at(obj->odx, obj->ody))
  599. X            newsym(obj->odx, obj->ody);
  600. X        obj->odispl = 0;
  601. X    }
  602. X*/
  603. X    if(!vism_at(obj->ox,obj->oy))
  604. X        newsym(obj->ox,obj->oy);
  605. X}
  606. X
  607. X#ifdef WORM
  608. XSTATIC_OVL void
  609. Xpwseg(wtmp)
  610. Xregister struct wseg *wtmp;
  611. X{
  612. X    if(!wtmp->wdispl){
  613. X        atl(wtmp->wx, wtmp->wy, S_WORM_TAIL);
  614. X        wtmp->wdispl = 1;
  615. X    }
  616. X}
  617. X#endif
  618. X
  619. X
  620. X#ifdef STUPID_CPP    /* otherwise these functions are macros in rm.h */
  621. Xboolean IS_WALL(typ)
  622. Xunsigned typ;
  623. X{
  624. X    return(typ && typ <= TRWALL);
  625. X}
  626. X
  627. Xboolean IS_STWALL(typ)
  628. Xunsigned typ;
  629. X{
  630. X    return(typ <= TRWALL);            /* STONE <= (typ) <= TRWALL */
  631. X}
  632. X
  633. Xboolean IS_ROCK(typ)
  634. Xunsigned typ;
  635. X{
  636. X    return(typ < POOL);            /* absolutely nonaccessible */
  637. X}
  638. X
  639. Xboolean IS_DOOR(typ)
  640. Xunsigned typ;
  641. X{
  642. X    return(typ == DOOR);
  643. X}
  644. X
  645. Xboolean ACCESSIBLE(typ)
  646. Xunsigned typ;
  647. X{
  648. X    return(typ >= DOOR);            /* good position */
  649. X}
  650. X
  651. Xboolean IS_ROOM(typ)
  652. Xunsigned typ;
  653. X{
  654. X    return(typ >= ROOM);            /* ROOM, STAIRS, furniture.. */
  655. X}
  656. X
  657. Xboolean ZAP_POS(typ)
  658. Xunsigned typ;
  659. X{
  660. X    return(typ >= POOL);
  661. X}
  662. X
  663. Xboolean SPACE_POS(typ)
  664. Xunsigned typ;
  665. X{
  666. X    return(typ > DOOR);
  667. X}
  668. X
  669. Xboolean IS_POOL(typ)
  670. Xunsigned typ;
  671. X{
  672. X    return(typ >= POOL && typ <= DRAWBRIDGE_UP);
  673. X}
  674. X
  675. Xboolean IS_THRONE(typ)
  676. Xunsigned typ;
  677. X{
  678. X    return(typ == THRONE);
  679. X}
  680. X
  681. Xboolean IS_FOUNTAIN(typ)
  682. Xunsigned typ;
  683. X{
  684. X    return(typ == FOUNTAIN);
  685. X}
  686. X
  687. Xboolean IS_SINK(typ)
  688. Xunsigned typ;
  689. X{
  690. X    return(typ == SINK);
  691. X}
  692. X
  693. Xboolean IS_ALTAR(typ)
  694. Xunsigned typ;
  695. X{
  696. X    return(typ == ALTAR);
  697. X}
  698. X
  699. Xboolean IS_DRAWBRIDGE(typ)
  700. Xunsigned typ;
  701. X{
  702. X    return(typ == DRAWBRIDGE_UP || typ == DRAWBRIDGE_DOWN);
  703. X}
  704. X
  705. Xboolean IS_FURNITURE(typ)
  706. Xunsigned typ;
  707. X{
  708. X    return(typ >= STAIRS && typ <= ALTAR);
  709. X}
  710. X#endif /* STUPID_CPP */
  711. X
  712. X#endif /* OVLB */
  713. END_OF_FILE
  714. if test 12560 -ne `wc -c <'src/prisym.c'`; then
  715.     echo shar: \"'src/prisym.c'\" unpacked with wrong size!
  716. fi
  717. # end of 'src/prisym.c'
  718. fi
  719. if test -f 'src/trap.c' -a "${1}" != "-c" ; then 
  720.   echo shar: Will not clobber existing file \"'src/trap.c'\"
  721. else
  722. echo shar: Extracting \"'src/trap.c'\" \(42990 characters\)
  723. sed "s/^X//" >'src/trap.c' <<'END_OF_FILE'
  724. X/*    SCCS Id: @(#)trap.c    3.0    89/11/20
  725. X/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  726. X/* NetHack may be freely redistributed.  See license for details. */
  727. X
  728. X#include    "hack.h"
  729. X#include    "edog.h"
  730. X
  731. X#ifdef OVLB
  732. X
  733. Xconst char *traps[] = {
  734. X    "",
  735. X    " monster trap",
  736. X    " statue trap",
  737. X    " bear trap",
  738. X    "n arrow trap",
  739. X    " dart trap",
  740. X    " trapdoor",
  741. X    " teleportation trap",
  742. X    " pit",
  743. X    " sleeping gas trap"
  744. X    ," magic trap"
  745. X    ," squeaky board"
  746. X    ," web"
  747. X    ," spiked pit"
  748. X    ," level teleporter"
  749. X#ifdef SPELLS
  750. X    ,"n anti-magic field" 
  751. X#endif
  752. X    ," rust trap"
  753. X#ifdef POLYSELF
  754. X    ," polymorph trap"
  755. X#endif
  756. X    ," land mine"
  757. X};
  758. X
  759. X#endif /* OVLB */
  760. X
  761. Xvoid NDECL(domagictrap);
  762. XSTATIC_DCL boolean FDECL(thitm, (int, struct monst *, struct obj *, int));
  763. X
  764. X#ifdef OVLB
  765. X
  766. Xstatic void NDECL(vtele);
  767. X
  768. X/* Generic rust-armor function.  Returns TRUE if a message was printed;
  769. X * "print", if set, means to print a message (and thus to return TRUE) even
  770. X * if the item could not be rusted; otherwise a message is printed and TRUE is
  771. X * returned only for rustable items.
  772. X */
  773. Xboolean
  774. Xrust_dmg(otmp, ostr, type, print)
  775. Xregister struct obj *otmp;
  776. Xregister const char *ostr;
  777. Xint type;
  778. Xboolean print;
  779. X{
  780. X    static const char NEARDATA *gook[] = { "slag", "rust", "rot", "corrosion" };
  781. X    static const char NEARDATA *action[] = { "smolder", "rust", "rot", "corrode" };
  782. X    static const char NEARDATA *msg[] =  { "burnt", "rusted", "rotten", "corroded" };
  783. X    boolean vulnerable = FALSE;
  784. X    boolean plural;
  785. X
  786. X    if (!otmp) return(FALSE);
  787. X    switch(type) {
  788. X        case 0:
  789. X        case 2: vulnerable = is_flammable(otmp); break;
  790. X        case 1: vulnerable = is_rustprone(otmp); break;
  791. X        case 3: vulnerable = is_corrodeable(otmp); break;
  792. X    }
  793. X
  794. X    if (!print && (!vulnerable || otmp->rustfree || otmp->spe < -2))
  795. X        return FALSE;
  796. X
  797. X    plural = is_gloves(otmp) || is_boots(otmp);
  798. X
  799. X    if (!vulnerable)
  800. X        Your("%s %s not affected!", ostr, plural ? "are" : "is");
  801. X    else if (otmp->spe >= -2) {
  802. X        if (otmp->rustfree)
  803. X            pline("The %s on your %s vanishes instantly!",
  804. X                        gook[type], ostr);
  805. X        else if (otmp->blessed && !rnl(4))
  806. X            pline("Somehow, your %s %s not affected!", ostr,
  807. X                    plural ? "are" : "is");
  808. X        else {
  809. X            Your("%s %s%s!", ostr, action[type],
  810. X                plural ? "" : "s");
  811. X            otmp->spe--;
  812. X            adj_abon(otmp, -1);
  813. X        }
  814. X    } else Your("%s %s%s quite %s.", ostr, Blind ? "feel" : "look",
  815. X                         plural ? "" : "s", msg[type]);
  816. X    return(TRUE);
  817. X}
  818. X
  819. Xstruct trap *
  820. Xmaketrap(x,y,typ)
  821. Xregister int x, y, typ;
  822. X{
  823. X    register struct trap *ttmp;
  824. X    register struct permonst *ptr;
  825. X
  826. X    if (ttmp = t_at(x,y)) {
  827. X        if (u.utrap &&
  828. X          ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP) ||
  829. X          (u.utraptype == TT_WEB && typ != WEB) ||
  830. X          (u.utraptype == TT_PIT && typ != PIT && typ != SPIKED_PIT)))
  831. X            u.utrap = 0;
  832. X        ttmp->ttyp = typ;
  833. X        return ttmp;
  834. X    }
  835. X    ttmp = newtrap();
  836. X    ttmp->ttyp = typ;
  837. X    ttmp->tx = x;
  838. X    ttmp->ty = y;
  839. X    switch(typ) {
  840. X        case MONST_TRAP:        /* create a monster in "hiding" */
  841. X        {    int tryct = 0;
  842. X        if(rn2(5) && (ptr = mkclass(S_PIERCER)))
  843. X            ttmp->pm = monsndx(ptr);
  844. X        else do {
  845. X            ttmp->pm = rndmonnum();
  846. X        } while ((noattacks(&mons[ttmp->pm]) ||
  847. X            !mons[ttmp->pm].mmove) && ++tryct < 100);
  848. X        if (tryct == 100) {
  849. X            free((genericptr_t)ttmp);
  850. X            return(struct trap *)0;
  851. X        }
  852. X        break;
  853. X        }
  854. X        case STATUE_TRAP:        /* create a "living" statue */
  855. X        ttmp->pm = rndmonnum();
  856. X        (void) mkcorpstat(STATUE, &mons[ttmp->pm], x, y);
  857. X        break;
  858. X        default:
  859. X        ttmp->pm = -1;
  860. X        break;
  861. X    }
  862. X    ttmp->tseen = 0;
  863. X    ttmp->once = 0;
  864. X    ttmp->ntrap = ftrap;
  865. X    ftrap = ttmp;
  866. X    return(ttmp);
  867. X}
  868. X
  869. Xint
  870. Xteleok(x, y)
  871. Xregister int x, y;
  872. X{                /* might throw him into a POOL
  873. X                 * removed by GAN 10/20/86
  874. X                 */
  875. X#ifdef STUPID
  876. X    boolean    tmp1, tmp2, tmp3;
  877. X#  ifdef POLYSELF
  878. X    tmp1 = isok(x,y) && (!IS_ROCK(levl[x][y].typ) ||
  879. X        passes_walls(uasmon)) && !MON_AT(x, y);
  880. X#  else
  881. X    tmp1 = isok(x,y) && !IS_ROCK(levl[x][y].typ) && !MON_AT(x, y);
  882. X#  endif
  883. X    tmp2 = !sobj_at(BOULDER,x,y) && !t_at(x,y);
  884. X    tmp3 = !(is_pool(x,y) &&
  885. X           !(Levitation || Wwalking
  886. X#ifdef POLYSELF
  887. X         || is_flyer(uasmon)
  888. X#endif
  889. X        )) && !closed_door(x,y);
  890. X    return(tmp1 && tmp2 && tmp3);
  891. X#else
  892. X    return( isok(x,y) &&
  893. X#  ifdef POLYSELF
  894. X        (!IS_ROCK(levl[x][y].typ) || passes_walls(uasmon)) &&
  895. X#  else
  896. X        !IS_ROCK(levl[x][y].typ) &&
  897. X#  endif
  898. X        !MON_AT(x, y) &&
  899. X        !sobj_at(BOULDER,x,y) && !t_at(x,y) &&
  900. X        !(is_pool(x,y) &&
  901. X        !(Levitation || Wwalking
  902. X#ifdef POLYSELF
  903. X          || is_flyer(uasmon)
  904. X#endif
  905. X          )) && !closed_door(x,y));
  906. X#endif
  907. X    /* Note: gold is permitted (because of vaults) */
  908. X}
  909. X
  910. Xstatic void
  911. Xvtele() {
  912. X    register struct mkroom *croom;
  913. X
  914. X    for(croom = &rooms[0]; croom->hx >= 0; croom++)
  915. X        if(croom->rtype == VAULT) {
  916. X        register int x, y;
  917. X
  918. X        x = rn2(2) ? croom->lx : croom->hx;
  919. X        y = rn2(2) ? croom->ly : croom->hy;
  920. X        if(teleok(x,y)) {
  921. X            teleds(x,y);
  922. X            return;
  923. X        }
  924. X        }
  925. X    tele();
  926. X}
  927. X
  928. Xvoid
  929. Xfall_through(td)
  930. Xboolean td;    /* td == TRUE : trapdoor */
  931. X{
  932. X    register int newlevel = dlevel + 1;
  933. X
  934. X    while(!rn2(4) && newlevel < 29) newlevel++;
  935. X    if(td) pline("A trap door opens up under you!");
  936. X    else pline("The floor opens up under you!");
  937. X    if(Levitation || u.ustuck || dlevel == MAXLEVEL
  938. X#ifdef POLYSELF
  939. X        || is_flyer(uasmon) || u.umonnum == PM_WUMPUS
  940. X#endif
  941. X#ifdef ENDGAME
  942. X        || dlevel == ENDLEVEL
  943. X#endif
  944. X    ) {
  945. X        You("don't fall in.");
  946. X        if(!td) {
  947. X        more();
  948. X        pline("The opening under you closes up.");
  949. X        }
  950. X        return;
  951. X    }
  952. X#ifdef WALKIES
  953. X    if(!next_to_u()) {
  954. X        You("are jerked back by your pet!");
  955. X        if(!td) {
  956. X        more();
  957. X        pline("The opening in the floor closes up.");
  958. X        }
  959. X    } else {
  960. X#endif
  961. X        if(in_shop(u.ux, u.uy)) shopdig(1);
  962. X        unsee();
  963. X        (void) fflush(stdout);
  964. X        goto_level(newlevel, FALSE, TRUE);
  965. X        if(!td) pline("The hole in the ceiling above you closes up.");
  966. X#ifdef WALKIES
  967. X    }
  968. X#endif
  969. X}
  970. X
  971. Xvoid
  972. Xdotrap(trap)
  973. Xregister struct trap *trap;
  974. X{
  975. X    register int ttype = trap->ttyp;
  976. X    register struct monst *mtmp;
  977. X    register struct obj *otmp;
  978. X
  979. X    nomul(0);
  980. X    if(trap->tseen && !Fumbling && !(ttype == PIT
  981. X       || ttype == SPIKED_PIT
  982. X#ifdef SPELLS
  983. X       || ttype == ANTI_MAGIC
  984. X#endif
  985. X        ) && !rn2(5))
  986. X        You("escape a%s.", traps[ttype]);
  987. X    else {
  988. X        trap->tseen = 1;
  989. X        if(Invisible && ttype != MONST_TRAP)
  990. X        newsym(trap->tx,trap->ty);
  991. X        switch(ttype) {
  992. X        case SLP_GAS_TRAP:
  993. X            if(Sleep_resistance) {
  994. X            You("are enveloped in a cloud of gas!");
  995. X            break;
  996. X            }
  997. X            pline("A cloud of gas puts you to sleep!");
  998. X            flags.soundok = 0;
  999. X            nomul(-rnd(25));
  1000. X            afternmv = Hear_again;
  1001. X            break;
  1002. X        case BEAR_TRAP:
  1003. X            if(Levitation
  1004. X#ifdef POLYSELF
  1005. X                || is_flyer(uasmon)) {
  1006. X            You("%s over a bear trap.",
  1007. X                  Levitation ? "float" : "fly");
  1008. X#else
  1009. X                ) {
  1010. X            You("float over a bear trap.");
  1011. X#endif
  1012. X            break;
  1013. X            }
  1014. X#ifdef POLYSELF
  1015. X            if(amorphous(uasmon)) {
  1016. X            pline("A bear trap closes harmlessly through you.");
  1017. X            break;
  1018. X            }
  1019. X#endif
  1020. X            u.utrap = 4 + rn2(4);
  1021. X            u.utraptype = TT_BEARTRAP;
  1022. X            pline("A bear trap closes on your %s!",
  1023. X            body_part(FOOT));
  1024. X#ifdef POLYSELF
  1025. X            if(u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR)
  1026. X            You("howl in anger!");
  1027. X#endif
  1028. X            break;
  1029. X        case STATUE_TRAP:
  1030. X            deltrap(trap);
  1031. X            for(otmp=level.objects[u.ux][u.uy];
  1032. X                        otmp; otmp = otmp->nexthere)
  1033. X            if(otmp->otyp == STATUE && otmp->corpsenm == trap->pm)
  1034. X                if(mtmp=makemon(&mons[trap->pm],u.ux,u.uy)) {
  1035. X                pline("The statue comes to life!");
  1036. X                delobj(otmp);
  1037. X                break;
  1038. X                }
  1039. X            break;
  1040. X        case MONST_TRAP:
  1041. X            if(mtmp=makemon(&mons[trap->pm],u.ux,u.uy)) {
  1042. X              mtmp->mpeaceful = FALSE;
  1043. X              switch(mtmp->data->mlet) {
  1044. X            case S_PIERCER:
  1045. X                pline("%s suddenly drops from the ceiling!",
  1046. X                  Xmonnam(mtmp));
  1047. X                if(uarmh)
  1048. X                pline("Its blow glances off your helmet.");
  1049. X                else
  1050. X                (void) thitu(3,d(4,6),(struct obj *)0,
  1051. X                    "falling piercer");
  1052. X                break;
  1053. X            default:    /* monster surprises you. */
  1054. X                pline("%s attacks you by surprise!",
  1055. X                  Xmonnam(mtmp));
  1056. X                break;
  1057. X              }
  1058. X            }
  1059. X            deltrap(trap);
  1060. X            break;
  1061. X        case ARROW_TRAP:
  1062. X            pline("An arrow shoots out at you!");
  1063. X            if(!thitu(8,rnd(6),(struct obj *)0,"arrow")){
  1064. X            (void) mksobj_at(ARROW, u.ux, u.uy);
  1065. X            fobj->quan = 1;
  1066. X            fobj->owt = weight(fobj);
  1067. X            }
  1068. X            break;
  1069. X        case TRAPDOOR:
  1070. X            if(is_maze_lev
  1071. X#ifdef STRONGHOLD
  1072. X             && (dlevel > stronghold_level)
  1073. X#endif
  1074. X              ) {
  1075. X    pline("A trap door in the ceiling opens and a rock falls on your %s!",
  1076. X                body_part(HEAD));
  1077. X            if(uarmh)
  1078. X                pline("Fortunately, you are wearing a helmet!");
  1079. X            losehp(uarmh ? 2 : d(2,10),"falling rock", KILLED_BY_AN);
  1080. X            (void) mksobj_at(ROCK, u.ux, u.uy);
  1081. X            fobj->quan = 1;
  1082. X            fobj->owt = weight(fobj);
  1083. X            stackobj(fobj);
  1084. X            if(Invisible
  1085. X#ifdef POLYSELF
  1086. X                || u.uundetected
  1087. X#endif
  1088. X                        ) newsym(u.ux, u.uy);
  1089. X            } else fall_through(TRUE);
  1090. X            break;
  1091. X        case DART_TRAP:
  1092. X            pline("A little dart shoots out at you!");
  1093. X            if(thitu(7,rnd(3),(struct obj *)0,"little dart")) {
  1094. X            if(!rn2(6)) poisoned("dart",A_CON,"poison dart",10);
  1095. X            } else {
  1096. X            (void) mksobj_at(DART, u.ux, u.uy);
  1097. X            fobj->quan = 1;
  1098. X            if(!rn2(6)) fobj->opoisoned = 1;
  1099. X            fobj->owt = weight(fobj);
  1100. X            }
  1101. X            break;
  1102. X        case TELEP_TRAP:
  1103. X            if(trap->once) {
  1104. X#ifdef ENDGAME
  1105. X            if(dlevel == ENDLEVEL) {
  1106. X                You("feel a wrenching sensation.");
  1107. X                break;
  1108. X            }
  1109. X#endif
  1110. X            if(Antimagic) {
  1111. X                shieldeff(u.ux, u.uy);
  1112. X                You("feel a wrenching sensation.");
  1113. X            } else {
  1114. X                deltrap(trap);
  1115. X                newsym(u.ux, u.uy);
  1116. X                vtele();
  1117. X            }
  1118. X            } else {
  1119. X#ifdef ENDGAME
  1120. X            if(dlevel == ENDLEVEL) {
  1121. X                You("feel a wrenching sensation.");
  1122. X                break;
  1123. X            }
  1124. X#endif
  1125. X            if(Antimagic) {
  1126. X                shieldeff(u.ux, u.uy);
  1127. X                You("feel a wrenching sensation.");
  1128. X            } else {
  1129. X                newsym(u.ux, u.uy);
  1130. X                tele();
  1131. X            }
  1132. X            }
  1133. X            break;
  1134. X        case RUST_TRAP:
  1135. X#ifdef POLYSELF
  1136. X# ifdef GOLEMS
  1137. X            if (u.umonnum == PM_IRON_GOLEM) {
  1138. X            pline("A gush of water hits you!");
  1139. X            You("are covered with rust!");
  1140. X            rehumanize();
  1141. X            break;
  1142. X            } else
  1143. X# endif /* GOLEMS */
  1144. X            if (u.umonnum == PM_GREMLIN && rn2(3)) {
  1145. X            pline("A gush of water hits you!");
  1146. X            if(mtmp = cloneu()) {
  1147. X                mtmp->mhpmax = (u.mhmax /= 2);
  1148. X                You("multiply.");
  1149. X            }
  1150. X            break;
  1151. X            }
  1152. X#endif
  1153. X        /* Unlike monsters, traps cannot aim their rust attacks at
  1154. X         * you, so instead of looping through and taking either the
  1155. X         * first rustable one or the body, we take whatever we get,
  1156. X         * even if it is not rustable.
  1157. X         */
  1158. X            switch (rn2(5)) {
  1159. X            case 0:
  1160. X                pline("A gush of water hits you on the %s!",
  1161. X                    body_part(HEAD));
  1162. X                (void) rust_dmg(uarmh, "helmet", 1, TRUE);
  1163. X                break;
  1164. X            case 1:
  1165. X                pline("A gush of water hits your left %s!",
  1166. X                    body_part(ARM));
  1167. X                if (rust_dmg(uarms, "shield", 1, TRUE)) break;
  1168. X                if (uwep && bimanual(uwep))
  1169. X                goto two_hand;
  1170. X                /* Two goto statements in a row--aaarrrgggh! */
  1171. Xglovecheck:            (void) rust_dmg(uarmg, "gauntlets", 1, TRUE);
  1172. X                /* Not "metal gauntlets" since it gets called
  1173. X                 * even if it's leather for the message
  1174. X                 */
  1175. X                break;
  1176. X            case 2:
  1177. X                pline("A gush of water hits your right %s!",
  1178. X                    body_part(ARM));
  1179. Xtwo_hand:            corrode_weapon();
  1180. X                goto glovecheck;
  1181. X            default:
  1182. X                pline("A gush of water hits you!");
  1183. X                if (uarmc) (void) rust_dmg(uarmc, "cloak", 1, TRUE);
  1184. X                else if (uarm)
  1185. X                (void) rust_dmg(uarm, "armor", 1, TRUE);
  1186. X#ifdef SHIRT
  1187. X                else if (uarmu)
  1188. X                (void) rust_dmg(uarmu, "shirt", 1, TRUE);
  1189. X#endif
  1190. X            }
  1191. X            break;
  1192. X        case PIT:
  1193. X            if (Levitation
  1194. X#ifdef POLYSELF
  1195. X            || is_flyer(uasmon) || u.umonnum == PM_WUMPUS
  1196. X#endif
  1197. X            ) {
  1198. X            pline("A pit opens up under you!");
  1199. X            You("don't fall in!");
  1200. X            break;
  1201. X            }
  1202. X            You("fall into a pit!");
  1203. X#ifdef POLYSELF
  1204. X            if (!passes_walls(uasmon))
  1205. X#endif
  1206. X            u.utrap = rn1(6,2);
  1207. X            u.utraptype = TT_PIT;
  1208. X            losehp(rnd(6),"fell into a pit", NO_KILLER_PREFIX);
  1209. X            selftouch("Falling, you");
  1210. X            break;
  1211. X        case SPIKED_PIT:
  1212. X            if (Levitation
  1213. X#ifdef POLYSELF
  1214. X            || is_flyer(uasmon) || u.umonnum == PM_WUMPUS
  1215. X#endif
  1216. X            ) {
  1217. X            pline("A pit full of spikes opens up under you!");
  1218. X            You("don't fall in!");
  1219. X            break;
  1220. X            }
  1221. X            You("fall into a pit!");
  1222. X            You("land on a set of sharp iron spikes!");
  1223. X#ifdef POLYSELF
  1224. X            if (!passes_walls(uasmon))
  1225. X#endif
  1226. X            u.utrap = rn1(6,2);
  1227. X            u.utraptype = TT_PIT;
  1228. X            losehp(rnd(10),"fell into a pit of iron spikes",
  1229. X            NO_KILLER_PREFIX);
  1230. X            if(!rn2(6)) poisoned("spikes",A_STR,"fall onto poison spikes",8);
  1231. X            selftouch("Falling, you");
  1232. X            break;
  1233. X        case LEVEL_TELEP:
  1234. X
  1235. X            {    int oldl = dlevel;
  1236. X
  1237. X            You("%s onto a level teleport trap!",
  1238. X              Levitation ? "float" :
  1239. X#ifdef POLYSELF
  1240. X              locomotion(uasmon, "step"));
  1241. X#else
  1242. X              "step");
  1243. X#endif
  1244. X            if(Antimagic) {
  1245. X            pru();
  1246. X            shieldeff(u.ux, u.uy);
  1247. X            }
  1248. X            if(Antimagic
  1249. X#ifdef ENDGAME
  1250. X                || dlevel == ENDLEVEL
  1251. X#endif
  1252. X                            ) {
  1253. X            You("feel a wrenching sensation.");
  1254. X            break;
  1255. X            }
  1256. X            if(!Blind)
  1257. X              You("are momentarily blinded by a flash of light.");
  1258. X            else
  1259. X            You("are momentarily disoriented.");
  1260. X            deltrap(trap);
  1261. X            newsym(u.ux,u.uy);
  1262. X            level_tele();
  1263. X            if(oldl == dlevel && !Invisible
  1264. X#ifdef POLYSELF
  1265. X                        && !u.uundetected
  1266. X#endif
  1267. X                                ) {
  1268. X            levl[u.ux][u.uy].seen = 0; /* force atl */
  1269. X            atl(u.ux,u.uy,(char)u.usym);
  1270. X            }
  1271. X        }
  1272. X            break;
  1273. X#ifdef SPELLS
  1274. X        case ANTI_MAGIC:
  1275. X            if(Antimagic) {
  1276. X            shieldeff(u.ux, u.uy);
  1277. X            You("feel momentarily lethargic.");
  1278. X            } else drain_en(rnd((int)u.ulevel) + 1);
  1279. X            break;
  1280. X#endif
  1281. X#ifdef POLYSELF
  1282. X        case POLY_TRAP:
  1283. X            if(Antimagic) {
  1284. X            shieldeff(u.ux, u.uy);
  1285. X            You("feel momentarily different.");
  1286. X            /* Trap did nothing; don't remove it --KAA */
  1287. X            } else {
  1288. X            You("feel a change coming over you.");
  1289. X            polyself();
  1290. X            deltrap(trap);
  1291. X            }
  1292. X            break;
  1293. X#endif
  1294. X        case MGTRP:        /* A magic trap. */
  1295. X            if (!rn2(30)) {
  1296. X            You("are caught in a magical explosion!");
  1297. X            losehp(rnd(10), "magical explosion", KILLED_BY_AN);
  1298. X#ifdef SPELLS
  1299. X            Your("body absorbs some of the magical energy!");
  1300. X            u.uen = (u.uenmax += 2);
  1301. X#endif
  1302. X            deltrap(trap);
  1303. X            if(Invisible
  1304. X#ifdef POLYSELF
  1305. X                && !u.uundetected
  1306. X#endif
  1307. X                        ) newsym(u.ux,u.uy);
  1308. X            } else domagictrap();
  1309. X            break;
  1310. X        case SQBRD:        /* stepped on a squeaky board */
  1311. X            if (Levitation
  1312. X#ifdef POLYSELF
  1313. X            || is_flyer(uasmon)
  1314. X#endif
  1315. X            ) {
  1316. X            if (Hallucination) You("notice a crease in the linoleum.");
  1317. X            else You("notice a loose board below you.");
  1318. X            } else {
  1319. X            pline("A board beneath you squeaks loudly.");
  1320. X            wake_nearby();
  1321. X            }
  1322. X            break;
  1323. X        case WEB: /* Our luckless player has stumbled into a web. */
  1324. X
  1325. X            You("%s into a spider web!",
  1326. X              Levitation ? "float" :
  1327. X#ifdef POLYSELF
  1328. X              locomotion(uasmon, "stumble"));
  1329. X#else
  1330. X              "stumble");
  1331. X#endif
  1332. X            u.utraptype = TT_WEB;
  1333. X
  1334. X            /* Time stuck in the web depends on your strength. */
  1335. X
  1336. X            if (ACURR(A_STR) == 3) u.utrap = rn1(6,6);
  1337. X            else if (ACURR(A_STR) < 6) u.utrap = rn1(6,4);
  1338. X            else if (ACURR(A_STR) < 9) u.utrap = rn1(4,4);
  1339. X            else if (ACURR(A_STR) < 12) u.utrap = rn1(4,2);
  1340. X            else if (ACURR(A_STR) < 15) u.utrap = rn1(2,2);
  1341. X            else if (ACURR(A_STR) < 18) u.utrap = rnd(2);
  1342. X            else if (ACURR(A_STR) < 69) u.utrap = 1;
  1343. X            else {
  1344. X            u.utrap = 0;
  1345. X            You("tear through the web!");
  1346. X            deltrap(trap);
  1347. X               if(Invisible) newsym(u.ux,u.uy);
  1348. X            }
  1349. X            break;
  1350. X
  1351. X        case LANDMINE: {
  1352. X#ifndef LINT
  1353. X            register struct monst *mtmp = fmon;
  1354. X#endif
  1355. X
  1356. X            if (Levitation
  1357. X#ifdef POLYSELF
  1358. X                    || is_flyer(uasmon)
  1359. X#endif
  1360. X                                ) {
  1361. X            You("see a trigger in a pile of soil below you.");
  1362. X            if (rn2(3)) break;
  1363. X            pline("KAABLAMM!!!  The air currents set it off!");
  1364. X            } else {
  1365. X            pline("KAABLAMM!!!  You triggered a land mine!");
  1366. X            set_wounded_legs(LEFT_SIDE, 40 + rnd(35));
  1367. X            set_wounded_legs(RIGHT_SIDE, 40 + rnd(35));
  1368. X            }
  1369. X            losehp(rnd(16), "land mine", KILLED_BY_AN);
  1370. X            /* wake everything on the level */
  1371. X            while(mtmp) {
  1372. X            if(mtmp->msleep) mtmp->msleep = 0;
  1373. X            mtmp = mtmp->nmon;
  1374. X            }
  1375. X            deltrap(t_at(u.ux, u.uy)); /* mines only explode once */
  1376. X            if(Invisible) newsym(u.ux,u.uy);
  1377. X            }
  1378. X            break;
  1379. X        default:
  1380. X            impossible("You hit a trap of type %u", trap->ttyp);
  1381. X        }
  1382. X    }
  1383. X}
  1384. X
  1385. X#endif /* OVLB */
  1386. X
  1387. X#ifdef WALKIES
  1388. X
  1389. XSTATIC_DCL boolean FDECL(teleport_pet, (struct monst *));
  1390. X
  1391. X#ifdef OVLB
  1392. X
  1393. XSTATIC_OVL boolean
  1394. Xteleport_pet(mtmp)
  1395. Xregister struct monst *mtmp;
  1396. X{
  1397. X    register struct obj *otmp;
  1398. X
  1399. X    if(mtmp->mleashed) {
  1400. X        otmp = get_mleash(mtmp);
  1401. X        if(!otmp)
  1402. X        impossible("%s is leashed, without a leash.", Monnam(mtmp));
  1403. X        if(otmp->cursed) {
  1404. X# ifdef SOUNDS
  1405. X        yelp(mtmp);
  1406. X# endif
  1407. X        return FALSE;
  1408. X        } else {
  1409. X        Your("leash goes slack.");
  1410. X        m_unleash(mtmp);
  1411. X        return TRUE;
  1412. X        }
  1413. X    }
  1414. X    return TRUE;
  1415. X}
  1416. X
  1417. X#endif /* OVLB */
  1418. X
  1419. X#endif /* WALKIES */
  1420. X
  1421. XSTATIC_DCL void FDECL(seetrap, (struct trap *));
  1422. X
  1423. X#ifdef OVLB
  1424. X
  1425. XSTATIC_OVL void
  1426. Xseetrap(trap)
  1427. X
  1428. X    register struct trap *trap;
  1429. X{
  1430. X    if(!trap->tseen) {
  1431. X
  1432. X        trap->tseen = 1;
  1433. X        newsym(trap->tx, trap->ty);
  1434. X    }
  1435. X}
  1436. X
  1437. X#endif /* OVLB */
  1438. X#ifdef OVL1
  1439. X
  1440. Xint
  1441. Xmintrap(mtmp)
  1442. Xregister struct monst *mtmp;
  1443. X{
  1444. X    register struct trap *trap = t_at(mtmp->mx, mtmp->my);
  1445. X    register int newlev, wasintrap = mtmp->mtrapped;
  1446. X    register boolean trapkilled = FALSE, tdoor = FALSE;
  1447. X    struct obj *otmp;
  1448. X
  1449. X    if(!trap) {
  1450. X        mtmp->mtrapped = 0;    /* perhaps teleported? */
  1451. X    } else if(wasintrap) {
  1452. X        if(!rn2(40)) mtmp->mtrapped = 0;
  1453. X    } else {
  1454. X        register int tt = trap->ttyp;
  1455. X
  1456. X    /* A bug fix for dumb messages by ab@unido.
  1457. X     */
  1458. X        int in_sight = cansee(mtmp->mx,mtmp->my)
  1459. X               && (!mtmp->minvis || See_invisible);
  1460. X
  1461. X        if(mtmp->mtrapseen & (1 << tt)) {
  1462. X        /* he has been in such a trap - perhaps he escapes */
  1463. X        if(rn2(4)) return(0);
  1464. X        }
  1465. X        mtmp->mtrapseen |= (1 << tt);
  1466. X        switch (tt) {
  1467. X        case BEAR_TRAP:
  1468. X            if(mtmp->data->msize > MZ_SMALL &&
  1469. X               !amorphous(mtmp->data)) {
  1470. X                mtmp->mtrapped = 1;
  1471. X                if(in_sight) {
  1472. X                  pline("%s is caught in a bear trap!",
  1473. X                    Monnam(mtmp));
  1474. X                  seetrap(trap);
  1475. X                } else
  1476. X                    if((mtmp->data == &mons[PM_OWLBEAR]
  1477. X                    || mtmp->data == &mons[PM_BUGBEAR])
  1478. X                    && flags.soundok)
  1479. X                You("hear the roaring of an angry bear!");
  1480. X            }
  1481. X            break;
  1482. X#ifdef POLYSELF
  1483. X        case POLY_TRAP:
  1484. X            if(!resist(mtmp, WAND_SYM, 0, NOTELL)) {
  1485. X            (void) newcham(mtmp, (struct permonst *)0);
  1486. X            seetrap(trap);
  1487. X            }
  1488. X            break;
  1489. X#endif
  1490. X        case RUST_TRAP:
  1491. X            if(in_sight)
  1492. X                pline("A gush of water hits %s!", mon_nam(mtmp));
  1493. X            if(cansee(mtmp->mx,mtmp->my))
  1494. X                seetrap(trap);
  1495. X#ifdef GOLEMS
  1496. X            if (mtmp->data == &mons[PM_IRON_GOLEM]) {
  1497. X                if (in_sight)
  1498. X                    pline("%s falls to pieces!", Monnam(mtmp));
  1499. X                else if(mtmp->mtame)
  1500. X                    pline("May %s rust in peace.",
  1501. X                                mon_nam(mtmp));
  1502. X                mondied(mtmp);
  1503. X                trapkilled = TRUE;
  1504. X            } else
  1505. X#endif /* GOLEMS */
  1506. X            if (mtmp->data == &mons[PM_GREMLIN] && rn2(3)) {
  1507. X                struct monst *mtmp2 = clone_mon(mtmp);
  1508. X
  1509. X                if (mtmp2) {
  1510. X                    mtmp2->mhpmax = (mtmp->mhpmax /= 2);
  1511. X                    if(in_sight)
  1512. X                    pline("%s multiplies.", Monnam(mtmp));
  1513. X                }
  1514. X            }
  1515. X            break;
  1516. X        case PIT:
  1517. X        case SPIKED_PIT:
  1518. X            /* TO DO: there should be a mtmp/data -> floating */
  1519. X            if(!is_flyer(mtmp->data) &&
  1520. X               mtmp->data != &mons[PM_WUMPUS]) {
  1521. X                if (!passes_walls(mtmp->data))
  1522. X                    mtmp->mtrapped = 1;
  1523. X                if(in_sight) {
  1524. X                    pline("%s falls into a pit!", Monnam(mtmp));
  1525. X                    seetrap(trap);
  1526. X                }
  1527. X                if(thitm(0, mtmp, (struct obj *)0,
  1528. X                     rnd((tt==PIT) ? 6 : 10)))
  1529. X                    trapkilled = TRUE;
  1530. X            }
  1531. X            break;
  1532. X        case SLP_GAS_TRAP:
  1533. X            if(!resists_sleep(mtmp->data) &&
  1534. X               !mtmp->msleep && mtmp->mcanmove) {
  1535. X                mtmp->mcanmove = 0;
  1536. X                mtmp->mfrozen = rnd(25);
  1537. X                if(in_sight)
  1538. X                  pline("%s suddenly falls asleep!",
  1539. X                    Monnam(mtmp));
  1540. X                if(cansee(mtmp->mx,mtmp->my))
  1541. X                    seetrap(trap);
  1542. X            }
  1543. X            break;
  1544. X        case TELEP_TRAP:
  1545. X#ifdef WALKIES
  1546. X            if(teleport_pet(mtmp)) {
  1547. X#endif
  1548. X                /* Note: don't remove the trap if a vault.  Other-
  1549. X                 * the monster will be stuck there, since the guard
  1550. X                 * isn't going to come for it...
  1551. X                 */
  1552. X                if (trap->once) vloc(mtmp);
  1553. X                else rloc(mtmp);
  1554. X                if(in_sight && !cansee(mtmp->mx,mtmp->my)) {
  1555. X                pline("%s suddenly disappears!",
  1556. X                    Monnam(mtmp));
  1557. X                seetrap(trap);
  1558. X                }
  1559. X#ifdef WALKIES
  1560. X            }
  1561. X#endif
  1562. X            break;
  1563. X        case ARROW_TRAP:
  1564. X            otmp = mksobj(ARROW, FALSE);
  1565. X            otmp->quan = 1;
  1566. X            otmp->owt = weight(otmp);
  1567. X            if(in_sight) seetrap(trap);
  1568. X            if(thitm(8, mtmp, otmp, 0)) trapkilled = TRUE;
  1569. X            break;
  1570. X        case DART_TRAP:
  1571. X            otmp = mksobj(DART, FALSE);
  1572. X            otmp->quan = 1;
  1573. X            if (!rn2(6)) otmp->opoisoned = 1;
  1574. X            otmp->owt = weight(otmp);
  1575. X            if(in_sight) seetrap(trap);
  1576. X            if(thitm(7, mtmp, otmp, 0)) trapkilled = TRUE;
  1577. X            break;
  1578. X        case TRAPDOOR:
  1579. X            if(is_maze_lev
  1580. X#ifdef STRONGHOLD
  1581. X               && (dlevel > stronghold_level && dlevel < MAXLEVEL)
  1582. X#endif
  1583. X              ) {
  1584. X                otmp = mksobj(ROCK, FALSE);
  1585. X                otmp->quan = 1;
  1586. X                otmp->owt = weight(otmp);
  1587. X                if(in_sight) seetrap(trap);
  1588. X                if(thitm(0, mtmp, otmp, d(2, 10)))
  1589. X                    trapkilled = TRUE;
  1590. X                break;
  1591. X            }
  1592. X            if (mtmp->data == &mons[PM_WUMPUS]) break;
  1593. X            tdoor = TRUE;
  1594. X            /* Fall through */
  1595. X        case LEVEL_TELEP:
  1596. X            if(!is_flyer(mtmp->data)
  1597. X#ifdef WORM
  1598. X                && !mtmp->wormno
  1599. X                /* long worms with tails mustn't change levels */
  1600. X#endif
  1601. X                ) {
  1602. X#ifdef WALKIES
  1603. X                if(teleport_pet(mtmp)) {
  1604. X#endif
  1605. X                if(tdoor)
  1606. X                    fall_down(mtmp, dlevel+1);
  1607. X                else {
  1608. X                    newlev = rnd(3);
  1609. X                    if(!rn2(2)) newlev = -(newlev);
  1610. X                    newlev = dlevel + newlev;
  1611. X                    if(newlev > MAXLEVEL) {
  1612. X                    if(dlevel != MAXLEVEL)
  1613. X                        newlev = MAXLEVEL;
  1614. X                    else newlev = MAXLEVEL - rnd(3);
  1615. X                    }
  1616. X                    if(newlev < 1) {
  1617. X                    if(dlevel != 1) newlev = 1;
  1618. X                    else newlev = 1 + rnd(3);
  1619. X                    }
  1620. X                    fall_down(mtmp, newlev);
  1621. X                }
  1622. X                if(in_sight) {
  1623. X        pline("Suddenly, %s disappears out of sight.", mon_nam(mtmp));
  1624. X                    seetrap(trap);
  1625. X                }
  1626. X                return(2);    /* no longer on this level */
  1627. X#ifdef WALKIES
  1628. X                }
  1629. X#endif
  1630. X            }
  1631. X            break;
  1632. X        case MONST_TRAP:
  1633. X        case STATUE_TRAP:
  1634. X            break;
  1635. X        case MGTRP:
  1636. X            /* A magic trap.  Monsters immune. */
  1637. X            break;
  1638. X        case SQBRD: {
  1639. X            register struct monst *ztmp = fmon;
  1640. X
  1641. X            if(is_flyer(mtmp->data)) break;
  1642. X            /* stepped on a squeaky board */
  1643. X            if (in_sight) {
  1644. X                pline("A board beneath %s squeaks loudly.", mon_nam(mtmp));
  1645. X                seetrap(trap);
  1646. X            } else
  1647. X               You("hear a distant squeak.");
  1648. X            /* wake up nearby monsters */
  1649. X            while(ztmp) {
  1650. X                if(dist2(mtmp->mx,mtmp->my,ztmp->mx,ztmp->my) < 40)
  1651. X                if(ztmp->msleep) ztmp->msleep = 0;
  1652. X                ztmp = ztmp->nmon;
  1653. X            }
  1654. X            break;
  1655. X        }
  1656. X           case WEB:
  1657. X            /* Monster in a web. */
  1658. X            if(mtmp->data->mlet != S_SPIDER) {
  1659. X                if(in_sight)
  1660. X                pline("%s is caught in a web.", Monnam(mtmp));
  1661. X                else /* Eric Backus */
  1662. X                if(mtmp->data == &mons[PM_OWLBEAR] ||
  1663. X                    mtmp->data == &mons[PM_BUGBEAR])
  1664. X                    You("hear the roaring of a confused bear!");
  1665. X                mtmp->mtrapped = 1;
  1666. X            }
  1667. X            break;
  1668. X#ifdef SPELLS
  1669. X        case ANTI_MAGIC:    break;
  1670. X#endif
  1671. X        case LANDMINE: {
  1672. X            register struct monst *mntmp = fmon;
  1673. X
  1674. X            if(rn2(3))
  1675. X                break; /* monsters usually don't set it off */
  1676. X            if(is_flyer(mtmp->data)) {
  1677. X                if (in_sight) {
  1678. X    pline("A trigger appears in a pile of soil below %s.", Monnam(mtmp));
  1679. X                    seetrap(trap);
  1680. X                }
  1681. X                if (rn2(3)) break;
  1682. X                if (in_sight)
  1683. X                    pline("The air currents set it off!");
  1684. X            } else if(in_sight)
  1685. X                pline("KAABLAMM!!!  %s triggers a land mine!",
  1686. X                  Monnam(mtmp));
  1687. X            if (!in_sight && flags.soundok)
  1688. X                pline("Kaablamm!  You hear an explosion in the distance!");
  1689. X            deltrap(t_at(mtmp->mx, mtmp->my));
  1690. X            if(thitm(0, mtmp, (struct obj *)0, rnd(16)))
  1691. X                trapkilled = TRUE;
  1692. X            /* wake everything on the level */
  1693. X            while(mntmp) {
  1694. X                if(mntmp->msleep)
  1695. X                    mntmp->msleep = 0;
  1696. X                mntmp = mntmp->nmon;
  1697. X            }
  1698. X            break;
  1699. X        }
  1700. X        default:
  1701. X            impossible("Some monster encountered a strange trap of type %d.", tt);
  1702. X        }
  1703. X    }
  1704. X    if(trapkilled) return 2;
  1705. X    else return mtmp->mtrapped;
  1706. X}
  1707. X
  1708. X#endif /* OVL1 */
  1709. X#ifdef OVLB
  1710. X
  1711. Xvoid
  1712. Xselftouch(arg)
  1713. Xconst char *arg;
  1714. X{
  1715. X    if(uwep && (uwep->otyp == CORPSE && uwep->corpsenm == PM_COCKATRICE)
  1716. X#ifdef POLYSELF
  1717. X            && !resists_ston(uasmon)
  1718. X#endif
  1719. X    ){
  1720. X        pline("%s touch the cockatrice corpse.", arg);
  1721. X        You("turn to stone...");
  1722. X        killer_format = KILLED_BY;
  1723. X        killer = "touching a cockatrice corpse";
  1724. X        done(STONING);
  1725. X    }
  1726. X}
  1727. X
  1728. Xvoid
  1729. Xfloat_up() {
  1730. X    if(u.utrap) {
  1731. X        if(u.utraptype == TT_PIT) {
  1732. X            u.utrap = 0;
  1733. X            You("float up, out of the pit!");
  1734. X        } else {
  1735. X            You("float up, only your %s is still stuck.",
  1736. X                body_part(LEG));
  1737. X        }
  1738. X    } else
  1739. X        if (Hallucination)
  1740. X            pline("Up, up, and awaaaay!  You're walking on air!");
  1741. X        else
  1742. X            You("start to float in the air!");
  1743. X}
  1744. X
  1745. Xint
  1746. Xfloat_down() {
  1747. X    register struct trap *trap;
  1748. X
  1749. X    if(Levitation) return(0); /* maybe another ring/potion/boots */
  1750. X
  1751. X    /* check for falling into pool - added by GAN 10/20/86 */
  1752. X    if(is_pool(u.ux,u.uy) && !(Wwalking
  1753. X#ifdef POLYSELF
  1754. X                    || is_flyer(uasmon)
  1755. X#endif
  1756. X                    ))
  1757. X        drown();
  1758. X
  1759. X    You("float gently to the ground.");
  1760. X    if(trap = t_at(u.ux,u.uy))
  1761. X        switch(trap->ttyp) {
  1762. X        case MONST_TRAP:
  1763. X        case STATUE_TRAP:
  1764. X            break;
  1765. X        case TRAPDOOR:
  1766. X            if(is_maze_lev
  1767. X#ifdef STRONGHOLD
  1768. X               && (dlevel >= stronghold_level || dlevel < MAXLEVEL)
  1769. X#endif
  1770. X               || u.ustuck) break;
  1771. X            /* fall into next case */
  1772. X        default:
  1773. X            dotrap(trap);
  1774. X    }
  1775. X    if(!flags.nopick && (OBJ_AT(u.ux, u.uy) || levl[u.ux][u.uy].gmask))
  1776. X        pickup(1);
  1777. X    return 0;
  1778. X}
  1779. X
  1780. X
  1781. Xvoid
  1782. Xtele() {
  1783. X    coord cc;
  1784. X    register int nux,nuy;
  1785. X
  1786. X#ifdef STRONGHOLD
  1787. X    /* Disable teleportation in stronghold && Vlad's Tower */
  1788. X    if(dlevel == stronghold_level ||
  1789. X# ifdef ENDGAME
  1790. X       dlevel == ENDLEVEL ||
  1791. X# endif
  1792. X       (dlevel >= tower_level && dlevel <= tower_level + 2)) {
  1793. X# ifdef WIZARD
  1794. X        if (!wizard) {
  1795. X# endif
  1796. X            pline("A mysterious force prevents you from teleporting!");
  1797. X            return;
  1798. X# ifdef WIZARD
  1799. X        }
  1800. X# endif
  1801. X    }
  1802. X#endif /* STRONGHOLD /**/
  1803. X    if((u.uhave_amulet || dlevel == wiz_level) && !rn2(3)) {
  1804. X        You("feel disoriented for a moment.");
  1805. X        return;
  1806. X    }
  1807. X    if(Teleport_control) {
  1808. X        if (unconscious())
  1809. X        pline("Being unconscious, you cannot control your teleport.");
  1810. X        else {
  1811. X            pline("To what position do you want to be teleported?");
  1812. X            cc.x = u.ux;
  1813. X            cc.y = u.uy;
  1814. X            getpos(&cc, 1, "the desired position"); /* 1: force valid */
  1815. X            /* possible extensions: introduce a small error if
  1816. X               magic power is low; allow transfer to solid rock */
  1817. X            if(teleok(cc.x, cc.y)){
  1818. X            teleds(cc.x, cc.y);
  1819. X            return;
  1820. X            }
  1821. X            pline("Sorry...");
  1822. X        }
  1823. X    }
  1824. X    do {
  1825. X        nux = rnd(COLNO-1);
  1826. X        nuy = rn2(ROWNO);
  1827. X    } while(!teleok(nux, nuy));
  1828. X    teleds(nux, nuy);
  1829. X}
  1830. X
  1831. Xvoid
  1832. Xteleds(nux, nuy)
  1833. Xregister int nux,nuy;
  1834. X{
  1835. X    if(Punished) unplacebc();
  1836. X    unsee();
  1837. X    u.utrap = 0;
  1838. X    u.ustuck = 0;
  1839. X    u.ux0 = u.ux;
  1840. X    u.uy0 = u.uy;
  1841. X    u.ux = nux;
  1842. X    u.uy = nuy;
  1843. X#ifdef POLYSELF
  1844. X    if (hides_under(uasmon))
  1845. X        u.uundetected = (OBJ_AT(nux, nuy) || levl[nux][nuy].gmask);
  1846. X    else 
  1847. X        u.uundetected = 0;
  1848. X    if (u.usym == S_MIMIC_DEF) u.usym = S_MIMIC;
  1849. X#endif
  1850. X    if(Punished) placebc(1);
  1851. X    if(u.uswallow){
  1852. X        u.uswldtim = u.uswallow = 0;
  1853. X        docrt();
  1854. X    }
  1855. X    setsee();
  1856. X    nomul(0);
  1857. X    spoteffects();
  1858. X}
  1859. X
  1860. Xint
  1861. Xdotele()
  1862. X{
  1863. X    struct trap *trap;
  1864. X#ifdef SPELLS
  1865. X    boolean castit = FALSE;
  1866. X# ifdef __GNULINT__
  1867. X    register int sp_no = 0;
  1868. X# else
  1869. X    register int sp_no;
  1870. X# endif
  1871. X#endif
  1872. X
  1873. X    trap = t_at(u.ux, u.uy);
  1874. X    if (trap && (!trap->tseen || trap->ttyp != TELEP_TRAP))
  1875. X        trap = 0;
  1876. X
  1877. X    if (trap) {
  1878. X        if (trap->once) {
  1879. X            pline("This is a vault teleport, usable once only.");
  1880. X            pline("Jump in? ");
  1881. X            if (yn() == 'n')
  1882. X                trap = 0;
  1883. X            else {
  1884. X                deltrap(trap);
  1885. X                newsym(u.ux, u.uy);
  1886. X            }
  1887. X        }
  1888. X        if (trap)
  1889. X#ifdef POLYSELF
  1890. X            You("%s onto the teleportation trap.",
  1891. X                locomotion(uasmon, "jump"));
  1892. X#else
  1893. X            You("jump onto the teleportation trap.");
  1894. X#endif
  1895. X    }
  1896. X    if(!trap && (!Teleportation ||
  1897. X       (u.ulevel < (pl_character[0] == 'W' ? 8 : 12)
  1898. X#ifdef POLYSELF
  1899. X        && !can_teleport(uasmon)
  1900. X#endif
  1901. X       )
  1902. X      )) {
  1903. X#ifdef SPELLS
  1904. X        /* Try to use teleport away spell. */
  1905. X        castit = objects[SPE_TELEPORT_AWAY].oc_name_known;
  1906. X        if (castit) {
  1907. X            for (sp_no = 0; sp_no < MAXSPELL &&
  1908. X                spl_book[sp_no].sp_id != NO_SPELL &&
  1909. X                spl_book[sp_no].sp_id != SPE_TELEPORT_AWAY; sp_no++);
  1910. X
  1911. X            if (sp_no == MAXSPELL ||
  1912. X            spl_book[sp_no].sp_id != SPE_TELEPORT_AWAY)
  1913. X                castit = FALSE;
  1914. X        }
  1915. X#endif
  1916. X#ifdef WIZARD
  1917. X        if (!wizard) {
  1918. X#endif
  1919. X#ifdef SPELLS
  1920. X            if (!castit) {
  1921. X            if (!Teleportation)
  1922. X                You("don't know that spell.");
  1923. X            else
  1924. X#endif
  1925. X                You("are not able to teleport at will.");
  1926. X            return(0);
  1927. X#ifdef SPELLS
  1928. X            }
  1929. X#endif
  1930. X#ifdef WIZARD
  1931. X        }
  1932. X#endif
  1933. X    }
  1934. X
  1935. X    if(!trap && (u.uhunger <= 100 || ACURR(A_STR) < 6)) {
  1936. X        You("lack the strength for a teleport spell.");
  1937. X#ifdef WIZARD
  1938. X        if(!wizard)
  1939. X#endif
  1940. X        return(1);
  1941. X    }
  1942. X
  1943. X#ifdef SPELLS
  1944. X    if (castit)
  1945. X# ifdef WIZARD
  1946. X        if (!spelleffects(++sp_no, TRUE) && !wizard) return(0);
  1947. X# else
  1948. X        return spelleffects(++sp_no, TRUE);
  1949. X# endif
  1950. X#endif
  1951. X
  1952. X#ifdef WALKIES
  1953. X    if(next_to_u()) {
  1954. X#endif
  1955. X        if (trap && trap->once) vtele();
  1956. X        else tele();
  1957. X#ifdef WALKIES
  1958. X        (void) next_to_u();
  1959. X    } else {
  1960. X        You("shudder for a moment.");
  1961. X        return(0);
  1962. X    }
  1963. X#endif
  1964. X    if (!trap) morehungry(100);
  1965. X    return(1);
  1966. X}
  1967. X
  1968. Xvoid
  1969. Xplacebc(attach)
  1970. Xint attach;
  1971. X{
  1972. X    if(!uchain || !uball){
  1973. X        impossible("Where are your ball and chain?");
  1974. X        return;
  1975. X    }
  1976. X    if(!carried(uball))
  1977. X        place_object(uball, u.ux, u.uy);
  1978. X    place_object(uchain, u.ux, u.uy);
  1979. X    if(attach){
  1980. X        uchain->nobj = fobj;
  1981. X        fobj = uchain;
  1982. X        if(!carried(uball)){
  1983. X            uball->nobj = fobj;
  1984. X            fobj = uball;
  1985. X        }
  1986. X    }
  1987. X}
  1988. X
  1989. Xvoid
  1990. Xunplacebc(){
  1991. X    if(!carried(uball)){
  1992. X        freeobj(uball);
  1993. X        unpobj(uball);
  1994. X    }
  1995. X    freeobj(uchain);
  1996. X    unpobj(uchain);
  1997. X}
  1998. X
  1999. Xvoid
  2000. Xlevel_tele() {
  2001. X    register int newlevel;
  2002. X
  2003. X    if(u.uhave_amulet
  2004. X#ifdef ENDGAME
  2005. X        || dlevel == ENDLEVEL
  2006. X#endif
  2007. X    ) {
  2008. X        You("feel very disoriented for a moment.");
  2009. X        return;
  2010. X    }
  2011. X    if(Teleport_control
  2012. X#ifdef WIZARD
  2013. X       || wizard
  2014. X#endif
  2015. X        ) {
  2016. X        char buf[BUFSZ];
  2017. X
  2018. X        do {
  2019. X          pline("To what level do you want to teleport? [type a number] ");
  2020. X          getlin(buf);
  2021. X        } while(!digit(buf[0]) && (buf[0] != '-' || !digit(buf[1])));
  2022. X        newlevel = atoi(buf);
  2023. X    } else {
  2024. X#ifdef STRONGHOLD
  2025. X        /* We cannot send them to Hell if STRONGHOLD is defined, since
  2026. X         * they may find themselves trapped on the other side of the
  2027. X         * stronghold...
  2028. X         */
  2029. X        newlevel = rn2(5) ? rnd(dlevel + 3) : rnd(stronghold_level);
  2030. X#else
  2031. X        newlevel = rn2(5) || !Fire_resistance ? rnd(dlevel + 3) : HELLLEVEL;
  2032. X#endif
  2033. X        if(dlevel == newlevel)
  2034. X        if(is_maze_lev) newlevel--; else newlevel++;
  2035. X    }
  2036. X
  2037. X#ifdef WALKIES
  2038. X    if(!next_to_u()) {
  2039. X        You("shudder for a moment...");
  2040. X        return;
  2041. X    }
  2042. X#endif
  2043. X
  2044. X    if(newlevel < 0) {
  2045. X        if(newlevel <= -10) {
  2046. X            You("arrive in heaven.");
  2047. X            verbalize("Thou art early, but we'll admit thee.");
  2048. X            killer_format = NO_KILLER_PREFIX;
  2049. X            killer = "went to heaven prematurely";
  2050. X            done(DIED);
  2051. X            return;
  2052. X        } else    if (newlevel == -9) {
  2053. X            You("feel deliriously happy. ");
  2054. X            pline("(In fact, you're on Cloud 9!) ");
  2055. X            more();
  2056. X        } else
  2057. X            You("are now high above the clouds...");
  2058. X
  2059. X        if(Levitation) {
  2060. X            You("float gently down to earth.");
  2061. X#ifdef STRONGHOLD
  2062. X            newlevel = 1;
  2063. X#else
  2064. X            done(ESCAPED);
  2065. X#endif
  2066. X        }
  2067. X#ifdef POLYSELF
  2068. X        else if(is_flyer(uasmon)) {
  2069. X            You("fly down to earth.");
  2070. X# ifdef STRONGHOLD
  2071. X            newlevel = 1;
  2072. X# else
  2073. X            done(ESCAPED);
  2074. X# endif
  2075. X        }
  2076. X#endif
  2077. X        else {
  2078. X            int save_dlevel;
  2079. X
  2080. X            save_dlevel = dlevel;
  2081. X            pline("Unfortunately, you don't know how to fly.");
  2082. X            You("plummet a few thousand feet to your death.");
  2083. X            dlevel = 0;
  2084. X            killer_format = NO_KILLER_PREFIX;
  2085. X            killer =
  2086. X    self_pronoun("teleported out of the dungeon and fell to %s death","his");
  2087. X            done(DIED);
  2088. X            dlevel = save_dlevel;
  2089. X            return;  
  2090. X        }
  2091. X    }
  2092. X
  2093. X    /* calls done(ESCAPED) if newlevel==0 */
  2094. X    goto_level(newlevel, FALSE, FALSE);
  2095. X}
  2096. X
  2097. Xvoid
  2098. Xdomagictrap() {
  2099. X    register int fate = rnd(20);
  2100. X
  2101. X    /* What happened to the poor sucker? */
  2102. X
  2103. X    if (fate < 10) {
  2104. X
  2105. X      /* Most of the time, it creates some monsters. */
  2106. X      register int cnt = rnd(4);
  2107. X
  2108. X      /* below checks for blindness added by GAN 10/30/86 */
  2109. X      if (!Blind)  {
  2110. X        You("are momentarily blinded by a flash of light!");
  2111. X        make_blinded((long)rn1(5,10),FALSE);
  2112. X      }  else
  2113. X        You("hear a deafening roar!");
  2114. X      while(cnt--)
  2115. X        (void) makemon((struct permonst *) 0, u.ux, u.uy);
  2116. X    }
  2117. X    else
  2118. X      switch (fate) {
  2119. X
  2120. X         case 10:
  2121. X         case 11:
  2122. X              /* sometimes nothing happens */
  2123. X            break;
  2124. X         case 12:
  2125. X              /* a flash of fire */
  2126. X              {
  2127. X            register int num;
  2128. X
  2129. X            /* changed to be in conformance with
  2130. X             * SCR_FIRE by GAN 11/02/86
  2131. X             */
  2132. X
  2133. X            pline("A tower of flame bursts from the floor!");
  2134. X            if(Fire_resistance) {
  2135. X                shieldeff(u.ux, u.uy);
  2136. X                You("are uninjured.");
  2137. X                break;
  2138. X            } else {
  2139. X                num = rnd(6);
  2140. X                u.uhpmax -= num;
  2141. X                losehp(num,"burst of flame", KILLED_BY_AN);
  2142. X                break;
  2143. X            }
  2144. X              }
  2145. X
  2146. X         /* odd feelings */
  2147. X         case 13:    pline("A shiver runs up and down your %s!",
  2148. X                  body_part(SPINE));
  2149. X            break;
  2150. X         case 14:    You(Hallucination ?
  2151. X                "hear the moon howling at you." :
  2152. X                "hear distant howling.");
  2153. X            break;
  2154. X         case 15:    You("suddenly yearn for %s.",
  2155. X                Hallucination ? "Cleveland" :
  2156. X                        "your distant homeland");
  2157. X            break;
  2158. X         case 16:   Your("pack shakes violently!");
  2159. X            break;
  2160. X         case 17:    You(Hallucination ?
  2161. X                "smell hamburgers." :
  2162. X                "smell charred flesh.");
  2163. X            break;
  2164. X
  2165. X         /* very occasionally something nice happens. */
  2166. X
  2167. X         case 19:
  2168. X            /* tame nearby monsters */
  2169. X           {   register int i,j;
  2170. X               register struct monst *mtmp;
  2171. X
  2172. X               /* below pline added by GAN 10/30/86 */
  2173. X               adjattrib(A_CHA,1,FALSE);
  2174. X               for(i = -1; i <= 1; i++) for(j = -1; j <= 1; j++) {
  2175. X               if(!isok(u.ux+i, u.uy+j)) continue;
  2176. X               mtmp = m_at(u.ux+i, u.uy+j);
  2177. X               if(mtmp)
  2178. X                   (void) tamedog(mtmp, (struct obj *)0);
  2179. X               }
  2180. X               break;
  2181. X           }
  2182. X
  2183. X         case 20:
  2184. X            /* uncurse stuff */
  2185. X           {  register struct obj *obj;
  2186. X
  2187. X            /* below plines added by GAN 10/30/86 */
  2188. X            You(Hallucination ?
  2189. X                "feel in touch with the Universal Oneness." :
  2190. X                "feel like someone is helping you.");
  2191. X            for(obj = invent; obj ; obj = obj->nobj)
  2192. X                   if(obj->owornmask || obj->otyp == LOADSTONE)
  2193. X                    obj->cursed = 0;
  2194. X               if(Punished) unpunish();
  2195. X               break;
  2196. X           }
  2197. X         default: break;
  2198. X      }
  2199. X}
  2200. X
  2201. Xvoid
  2202. Xdrown() {
  2203. X    register struct obj *obj;
  2204. X
  2205. X    /* Scrolls and potions get affected by the water */
  2206. X    for(obj = invent; obj; obj = obj->nobj) {
  2207. X        if(obj->olet == SCROLL_SYM && rn2(12) > Luck
  2208. X#ifdef MAIL
  2209. X            && obj->otyp != SCR_MAIL
  2210. X#endif
  2211. X                                )
  2212. X            obj->otyp = SCR_BLANK_PAPER;
  2213. X        if(obj->olet == POTION_SYM && rn2(12) > Luck) {
  2214. X            if (obj->spe == -1) {
  2215. X                obj->otyp = POT_WATER;
  2216. X                obj->blessed = obj->cursed = 0;
  2217. X                obj->spe = 0;
  2218. X            } else obj->spe--;
  2219. X        }
  2220. X    }
  2221. X
  2222. X#ifdef POLYSELF
  2223. X    if(u.umonnum == PM_GREMLIN && rn2(3)) {
  2224. X        struct monst *mtmp;
  2225. X        if(mtmp = cloneu()) {
  2226. X            mtmp->mhpmax = (u.mhmax /= 2);
  2227. X            You("multiply.");
  2228. X        }
  2229. X    }
  2230. X
  2231. X    if(is_swimmer(uasmon)) return;
  2232. X#endif
  2233. X
  2234. X    You("fell into %s!",
  2235. X          levl[u.ux][u.uy].typ == POOL ? "a pool" : "the moat");
  2236. X    You("can't swim!");
  2237. X    if(
  2238. X#ifdef WIZARD
  2239. X    wizard ||
  2240. X#endif
  2241. X    rn2(3) < Luck+2) {
  2242. X        You("attempt a teleport spell.");    /* utcsri!carroll */
  2243. X        (void) dotele();
  2244. X        if(!is_pool(u.ux,u.uy)) return;
  2245. X    }
  2246. X    You("drown.");
  2247. X    killer_format = KILLED_BY_AN;
  2248. X    killer = levl[u.ux][u.uy].typ == POOL ? "pool of water" : "moat";
  2249. X    done(DROWNING);
  2250. X}
  2251. X
  2252. X#ifdef SPELLS
  2253. Xvoid
  2254. Xdrain_en(n)
  2255. Xregister int n;
  2256. X{
  2257. X    if (!u.uenmax) return;
  2258. X    You("feel your magical energy drain away!");
  2259. X    u.uen -= n;
  2260. X    if(u.uen < 0)  {
  2261. X        u.uenmax += u.uen;
  2262. X        if(u.uenmax < 0) u.uenmax = 0;
  2263. X        u.uen = 0;
  2264. X    }
  2265. X    flags.botl = 1;
  2266. X}
  2267. X#endif
  2268. X
  2269. Xint
  2270. Xdountrap() {    /* disarm a trapped object */
  2271. X    register struct obj *otmp;
  2272. X    register boolean confused = (Confusion > 0 || Hallucination > 0);
  2273. X    register int x,y;
  2274. X    int ch;
  2275. X    struct trap *ttmp;
  2276. X
  2277. X#ifdef POLYSELF
  2278. X    if(nohands(uasmon)) {
  2279. X        pline("And just how do you expect to do that?");
  2280. X        return(0);
  2281. X    }
  2282. X#endif
  2283. X    if(!getdir(TRUE)) return(0);
  2284. X    x = u.ux + u.dx;
  2285. X    y = u.uy + u.dy;
  2286. X
  2287. X    if(!u.dx && !u.dy) {
  2288. X        for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  2289. X        if(Is_box(otmp)) {
  2290. X            pline("There is %s here, check for traps? ", doname(otmp));
  2291. X
  2292. X            switch (ynq()) {
  2293. X            case 'q': return(0);
  2294. X            case 'n': continue;
  2295. X            }
  2296. X
  2297. X            if((otmp->otrapped && !confused 
  2298. X                && rn2(MAXLEVEL+2-dlevel) < 10)
  2299. X               || confused && !rn2(3)) {
  2300. X            You("find a trap on the %s!  Disarm it? ", xname(otmp));
  2301. X
  2302. X            switch (ynq()) {
  2303. X                case 'q': return(1);
  2304. X                case 'n': continue;
  2305. X            }
  2306. X
  2307. X            if(otmp->otrapped) {
  2308. X                ch = 15 + (pl_character[0] == 'R') ? u.ulevel*3
  2309. X                                : u.ulevel;
  2310. X                if(confused || Fumbling || rnd(75+dlevel/2) > ch) {
  2311. X                You("set it off!");
  2312. X                (void) chest_trap(otmp, FINGER);
  2313. X                } else {
  2314. X                You("disarm it!");
  2315. X                otmp->otrapped = 0;
  2316. X                }
  2317. X            } else pline("That %s was not trapped.", doname(otmp));
  2318. X            return(1);
  2319. X            } else {
  2320. X            You("find no traps on the %s.", xname(otmp));
  2321. X            return(1);
  2322. X            }
  2323. X        }
  2324. X        if ((ttmp = t_at(x,y)) && ttmp->tseen)
  2325. X        You("cannot disable this trap.");
  2326. X        else
  2327. X        You("know of no traps here.");
  2328. X        return(0);
  2329. X    }
  2330. X
  2331. X    if (!IS_DOOR(levl[x][y].typ)) {
  2332. X        if ((ttmp = t_at(x,y)) && ttmp->tseen)
  2333. X        You("cannot disable that trap.");
  2334. X        else
  2335. X        You("know of no traps there.");
  2336. X        return(0);
  2337. X    }
  2338. X
  2339. X    switch (levl[x][y].doormask) {
  2340. X        case D_NODOOR:
  2341. X        You("%s no door there.", Blind ? "feel" : "see");
  2342. X        return(0);
  2343. X        case D_ISOPEN:
  2344. X        pline("This door is safely open.");
  2345. X        return(0);
  2346. X        case D_BROKEN:
  2347. X        pline("This door is broken.");
  2348. X        return(0);
  2349. X    }
  2350. X
  2351. X    if ((levl[x][y].doormask & D_TRAPPED && !confused &&
  2352. X         rn2(MAXLEVEL+2-dlevel) < 10)
  2353. X        || confused && !rn2(3)) {
  2354. X        You("find a trap on the door!  Disarm it? ");
  2355. X        if (ynq() != 'y') return(1);
  2356. X        if (levl[x][y].doormask & D_TRAPPED) {
  2357. X            ch = 15 +
  2358. X             (pl_character[0] == 'R') ? u.ulevel*3 :
  2359. X             u.ulevel;
  2360. X            if(confused || Fumbling || rnd(75+dlevel/2) > ch) {
  2361. X                You("set it off!");
  2362. X                b_trapped("door");
  2363. X            } else
  2364. X                You("disarm it!");
  2365. X            levl[x][y].doormask &= ~D_TRAPPED;
  2366. X        } else pline("This door was not trapped.");
  2367. X        return(1);
  2368. X    } else {
  2369. X        You("find no traps on the door.");
  2370. X        return(1);
  2371. X    }
  2372. X}
  2373. X
  2374. X/* only called when the player is doing something to the chest directly */
  2375. Xboolean
  2376. Xchest_trap(obj, bodypart)
  2377. Xregister struct obj *obj;
  2378. Xregister int bodypart;
  2379. X{
  2380. X    register struct obj *otmp,*otmp2;
  2381. X    char    buf[80];
  2382. X
  2383. X    if(Luck > -13 && rn2(13+Luck) > 7) return FALSE;
  2384. X
  2385. X    otmp = obj;
  2386. X    switch(rn2(20) ? ((Luck >= 13) ? 0 : rn2(13-Luck)) : rn2(26)) {
  2387. X        case 25:
  2388. X        case 24:
  2389. X        case 23:
  2390. X        case 22:
  2391. X        case 21:
  2392. X            pline("The %s explodes!", xname(obj));
  2393. X            Sprintf(buf, "exploding %s", xname(obj));
  2394. X
  2395. X            delete_contents(obj);
  2396. X            for(otmp = level.objects[u.ux][u.uy];
  2397. X                            otmp; otmp = otmp2) {
  2398. X                otmp2 = otmp->nexthere;
  2399. X                delobj(otmp);
  2400. X            }
  2401. X
  2402. X            losehp(d(6,6), buf, KILLED_BY_AN);
  2403. X            wake_nearby();
  2404. X            return TRUE;
  2405. X        case 20:
  2406. X        case 19:
  2407. X        case 18:
  2408. X        case 17:
  2409. X            pline("A cloud of noxious gas billows from the %s.",
  2410. X                  xname(obj));
  2411. X            poisoned("gas cloud", A_STR, "cloud of poison gas",15);
  2412. X            break;
  2413. X        case 16:
  2414. X        case 15:
  2415. X        case 14:
  2416. X        case 13:
  2417. X            You("feel a needle prick your %s.",body_part(bodypart));
  2418. X            poisoned("needle", A_CON, "poison needle",10);
  2419. X            break;
  2420. X        case 12:
  2421. X        case 11:
  2422. X        case 10:
  2423. X        case 9:
  2424. X            pline("A tower of flame erupts from the %s",
  2425. X                  xname(obj));
  2426. X            if(Fire_resistance) {
  2427. X                shieldeff(u.ux, u.uy);
  2428. X                You("don't seem to be affected.");
  2429. X            } else    losehp(d(4, 6), "tower of flame", KILLED_BY_AN);
  2430. X            destroy_item(SCROLL_SYM, AD_FIRE);
  2431. X#ifdef SPELLS
  2432. X            destroy_item(SPBOOK_SYM, AD_FIRE);
  2433. X#endif
  2434. X            destroy_item(POTION_SYM, AD_FIRE);
  2435. X            break;
  2436. X        case 8:
  2437. X        case 7:
  2438. X        case 6:
  2439. X            You("are jolted by a surge of electricity!");
  2440. X            if(Shock_resistance)  {
  2441. X                shieldeff(u.ux, u.uy);
  2442. X                You("don't seem to be affected.");
  2443. X            } else    losehp(d(4, 4), "electric shock", KILLED_BY_AN);
  2444. X            destroy_item(RING_SYM, AD_ELEC);
  2445. X            destroy_item(WAND_SYM, AD_ELEC);
  2446. X            break;
  2447. X        case 5:
  2448. X        case 4:
  2449. X        case 3:
  2450. X            pline("Suddenly you are frozen in place!");
  2451. X            nomul(-d(5, 6));
  2452. X            nomovemsg = "You can move again.";
  2453. X            break;
  2454. X        case 2:
  2455. X        case 1:
  2456. X        case 0:
  2457. X            pline("A cloud of %s gas billows from the %s",
  2458. X                  hcolor(), xname(obj));
  2459. X            if(!Stunned)
  2460. X                if (Hallucination)
  2461. X                pline("What a groovy feeling!");
  2462. X                else
  2463. X                You("stagger and your vision blurs...");
  2464. X            make_stunned(HStun + rn1(7, 16),FALSE);
  2465. X            make_hallucinated(Hallucination + rn1(5, 16),FALSE);
  2466. X            break;
  2467. X        default: impossible("bad chest trap");
  2468. X            break;
  2469. X    }
  2470. X    bot();             /* to get immediate botl re-display */
  2471. X    otmp->otrapped = 0;        /* these traps are one-shot things */
  2472. X
  2473. X    return FALSE;
  2474. X}
  2475. X
  2476. X#endif /* OVLB */
  2477. X#ifdef OVL2
  2478. X
  2479. Xvoid
  2480. Xwake_nearby() {            /* Wake up nearby monsters. */
  2481. X    register struct monst *mtmp;
  2482. X
  2483. X    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  2484. X        if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) {
  2485. X        if(mtmp->msleep)  mtmp->msleep = 0;
  2486. X        if(mtmp->mtame)   EDOG(mtmp)->whistletime = moves;
  2487. X        }
  2488. X    }
  2489. X}
  2490. X
  2491. X#endif /* OVL2 */
  2492. X#ifdef OVL0
  2493. X
  2494. Xstruct trap *
  2495. Xt_at(x,y)
  2496. Xregister int x, y;
  2497. X{
  2498. X    register struct trap *trap = ftrap;
  2499. X    while(trap) {
  2500. X        if(trap->tx == x && trap->ty == y) return(trap);
  2501. X        trap = trap->ntrap;
  2502. X    }
  2503. X    return((struct trap *)0);
  2504. X}
  2505. X
  2506. X#endif /* OVL0 */
  2507. X#ifdef OVLB
  2508. X
  2509. Xvoid
  2510. Xdeltrap(trap)
  2511. Xregister struct trap *trap;
  2512. X{
  2513. X    register struct trap *ttmp;
  2514. X
  2515. X    if(trap == ftrap)
  2516. X        ftrap = ftrap->ntrap;
  2517. X    else {
  2518. X        for(ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) ;
  2519. X        ttmp->ntrap = trap->ntrap;
  2520. X    }
  2521. X    free((genericptr_t) trap);
  2522. X}
  2523. X
  2524. Xvoid
  2525. Xb_trapped(item)        /* used for doors. can be used */
  2526. Xregister const char *item;    /* for anything else that opens */
  2527. X{
  2528. X    register int dmg = rnd(5+(dlevel < 5 ? dlevel : 2+dlevel/2));
  2529. X
  2530. X    pline("KABOOM!!  The %s was booby-trapped!", item);
  2531. X    if(u.ulevel < 4 && dlevel < 3 && !rnl(3))
  2532. X        You("are shaken, but luckily unhurt.");        
  2533. X    else losehp(dmg, "explosion", KILLED_BY_AN);
  2534. X    make_stunned(HStun + dmg, TRUE);
  2535. X}
  2536. X
  2537. X/* Monster is hit by trap. */
  2538. X/* Note: doesn't work if both obj and d_override are null */
  2539. XSTATIC_OVL boolean
  2540. Xthitm(tlev, mon, obj, d_override)
  2541. Xregister int tlev;
  2542. Xregister struct monst *mon;
  2543. Xregister struct obj *obj;
  2544. Xint d_override;
  2545. X{
  2546. X    register int strike;
  2547. X    register boolean trapkilled = FALSE;
  2548. X
  2549. X    if (d_override) strike = 1;
  2550. X    else if (obj) strike = (mon->data->ac + tlev + obj->spe <= rnd(20));
  2551. X    else strike = (mon->data->ac + tlev <= rnd(20));
  2552. X
  2553. X    /* Actually more accurate than thitu, which doesn't take
  2554. X     * obj->spe into account.
  2555. X     */
  2556. X    if(!strike) {
  2557. X        if (cansee(mon->mx, mon->my))
  2558. X            pline("%s is almost hit by %s!", Monnam(mon),
  2559. X                                doname(obj));
  2560. X    } else {
  2561. X        int dam = 1;
  2562. X
  2563. X        if (obj && cansee(mon->mx, mon->my))
  2564. X            pline("%s is hit by %s!", Monnam(mon), doname(obj));
  2565. X        if (d_override) dam = d_override;
  2566. X        else if (obj) {
  2567. X            dam = dmgval(obj, mon->data);
  2568. X            if (dam < 1) dam = 1;
  2569. X        }
  2570. X        if ((mon->mhp -= dam) <= 0) {
  2571. X            int xx = mon->mx;
  2572. X            int yy = mon->my;
  2573. X
  2574. X            if (cansee(mon->mx, mon->my))
  2575. X                pline("%s is killed!", Monnam(mon));
  2576. X            else if (mon->mtame)
  2577. X    You("have a sad feeling for a moment, then it passes.");
  2578. X            mondied(mon);
  2579. X            newsym(xx, yy);
  2580. X            trapkilled = TRUE;
  2581. X        }
  2582. X    }
  2583. X    if (obj && (!strike || d_override)) {
  2584. X        place_object(obj, mon->mx, mon->my);
  2585. X        obj->nobj = fobj;
  2586. X        fobj = obj;
  2587. X        stackobj(fobj);
  2588. X    } else if (obj) free ((genericptr_t)obj);
  2589. X
  2590. X    return trapkilled;
  2591. X}
  2592. X
  2593. Xboolean
  2594. Xunconscious()
  2595. X{
  2596. X    return (multi < 0 && (!nomovemsg ||
  2597. X        !strncmp(nomovemsg,"You wake", 8) ||
  2598. X        !strncmp(nomovemsg,"You awake", 9) ||
  2599. X        !strncmp(nomovemsg,"You regain con", 15) ||
  2600. X        !strncmp(nomovemsg,"You are consci", 15)));
  2601. X}
  2602. X
  2603. X#endif /* OVLB */
  2604. END_OF_FILE
  2605. if test 42990 -ne `wc -c <'src/trap.c'`; then
  2606.     echo shar: \"'src/trap.c'\" unpacked with wrong size!
  2607. fi
  2608. # end of 'src/trap.c'
  2609. fi
  2610. echo shar: End of archive 8 \(of 56\).
  2611. cp /dev/null ark8isdone
  2612. MISSING=""
  2613. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ; do
  2614.     if test ! -f ark${I}isdone ; then
  2615.     MISSING="${MISSING} ${I}"
  2616.     fi
  2617. done
  2618. if test "${MISSING}" = "" ; then
  2619.     echo You have unpacked all 56 archives.
  2620.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2621. else
  2622.     echo You still need to unpack the following archives:
  2623.     echo "        " ${MISSING}
  2624. fi
  2625. ##  End of shell archive.
  2626. exit 0
  2627.