hack.zap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /* $NetBSD: hack.zap.c,v 1.7 2004/01/27 20:30:29 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
  4. * Amsterdam
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * - Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. *
  14. * - Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * - Neither the name of the Stichting Centrum voor Wiskunde en
  19. * Informatica, nor the names of its contributors may be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  24. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  25. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  26. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  27. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /*
  36. * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
  37. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. * 1. Redistributions of source code must retain the above copyright
  43. * notice, this list of conditions and the following disclaimer.
  44. * 2. Redistributions in binary form must reproduce the above copyright
  45. * notice, this list of conditions and the following disclaimer in the
  46. * documentation and/or other materials provided with the distribution.
  47. * 3. The name of the author may not be used to endorse or promote products
  48. * derived from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  51. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  52. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  53. * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  54. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  55. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  56. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  57. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  58. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  59. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60. */
  61. #include <sys/cdefs.h>
  62. #ifndef lint
  63. __RCSID("$NetBSD: hack.zap.c,v 1.7 2004/01/27 20:30:29 jsm Exp $");
  64. #endif /* not lint */
  65. #include "hack.h"
  66. #include "extern.h"
  67. const char *const fl[] = {
  68. "magic missile",
  69. "bolt of fire",
  70. "sleep ray",
  71. "bolt of cold",
  72. "death ray"
  73. };
  74. /* Routines for IMMEDIATE wands. */
  75. /* bhitm: monster mtmp was hit by the effect of wand otmp */
  76. void
  77. bhitm(mtmp, otmp)
  78. struct monst *mtmp;
  79. struct obj *otmp;
  80. {
  81. wakeup(mtmp);
  82. switch (otmp->otyp) {
  83. case WAN_STRIKING:
  84. if (u.uswallow || rnd(20) < 10 + mtmp->data->ac) {
  85. int tmp = d(2, 12);
  86. hit("wand", mtmp, exclam(tmp));
  87. mtmp->mhp -= tmp;
  88. if (mtmp->mhp < 1)
  89. killed(mtmp);
  90. } else
  91. miss("wand", mtmp);
  92. break;
  93. case WAN_SLOW_MONSTER:
  94. mtmp->mspeed = MSLOW;
  95. break;
  96. case WAN_SPEED_MONSTER:
  97. mtmp->mspeed = MFAST;
  98. break;
  99. case WAN_UNDEAD_TURNING:
  100. if (strchr(UNDEAD, mtmp->data->mlet)) {
  101. mtmp->mhp -= rnd(8);
  102. if (mtmp->mhp < 1)
  103. killed(mtmp);
  104. else
  105. mtmp->mflee = 1;
  106. }
  107. break;
  108. case WAN_POLYMORPH:
  109. if (newcham(mtmp, &mons[rn2(CMNUM)]))
  110. objects[otmp->otyp].oc_name_known = 1;
  111. break;
  112. case WAN_CANCELLATION:
  113. mtmp->mcan = 1;
  114. break;
  115. case WAN_TELEPORTATION:
  116. rloc(mtmp);
  117. break;
  118. case WAN_MAKE_INVISIBLE:
  119. mtmp->minvis = 1;
  120. break;
  121. #ifdef WAN_PROBING
  122. case WAN_PROBING:
  123. mstatusline(mtmp);
  124. break;
  125. #endif /* WAN_PROBING */
  126. default:
  127. impossible("What an interesting wand (%u)", otmp->otyp);
  128. }
  129. }
  130. int
  131. bhito(obj, otmp) /* object obj was hit by the effect of wand
  132. * otmp */
  133. struct obj *obj, *otmp; /* returns TRUE if sth was done */
  134. {
  135. int res = TRUE;
  136. if (obj == uball || obj == uchain)
  137. res = FALSE;
  138. else
  139. switch (otmp->otyp) {
  140. case WAN_POLYMORPH:
  141. /*
  142. * preserve symbol and quantity, but turn rocks into
  143. * gems
  144. */
  145. mkobj_at((obj->otyp == ROCK || obj->otyp == ENORMOUS_ROCK)
  146. ? GEM_SYM : obj->olet,
  147. obj->ox, obj->oy)->quan = obj->quan;
  148. delobj(obj);
  149. break;
  150. case WAN_STRIKING:
  151. if (obj->otyp == ENORMOUS_ROCK)
  152. fracture_rock(obj);
  153. else
  154. res = FALSE;
  155. break;
  156. case WAN_CANCELLATION:
  157. if (obj->spe && obj->olet != AMULET_SYM) {
  158. obj->known = 0;
  159. obj->spe = 0;
  160. }
  161. break;
  162. case WAN_TELEPORTATION:
  163. rloco(obj);
  164. break;
  165. case WAN_MAKE_INVISIBLE:
  166. obj->oinvis = 1;
  167. break;
  168. case WAN_UNDEAD_TURNING:
  169. res = revive(obj);
  170. break;
  171. case WAN_SLOW_MONSTER: /* no effect on objects */
  172. case WAN_SPEED_MONSTER:
  173. #ifdef WAN_PROBING
  174. case WAN_PROBING:
  175. #endif /* WAN_PROBING */
  176. res = FALSE;
  177. break;
  178. default:
  179. impossible("What an interesting wand (%u)", otmp->otyp);
  180. }
  181. return (res);
  182. }
  183. int
  184. dozap()
  185. {
  186. struct obj *obj;
  187. xchar zx, zy;
  188. obj = getobj("/", "zap");
  189. if (!obj)
  190. return (0);
  191. if (obj->spe < 0 || (obj->spe == 0 && rn2(121))) {
  192. pline("Nothing Happens.");
  193. return (1);
  194. }
  195. if (obj->spe == 0)
  196. pline("You wrest one more spell from the worn-out wand.");
  197. if (!(objects[obj->otyp].bits & NODIR) && !getdir(1))
  198. return (1); /* make him pay for knowing !NODIR */
  199. obj->spe--;
  200. if (objects[obj->otyp].bits & IMMEDIATE) {
  201. if (u.uswallow)
  202. bhitm(u.ustuck, obj);
  203. else if (u.dz) {
  204. if (u.dz > 0) {
  205. struct obj *otmp = o_at(u.ux, u.uy);
  206. if (otmp)
  207. (void) bhito(otmp, obj);
  208. }
  209. } else
  210. (void) bhit(u.dx, u.dy, rn1(8, 6), 0, bhitm, bhito, obj);
  211. } else {
  212. switch (obj->otyp) {
  213. case WAN_LIGHT:
  214. litroom(TRUE);
  215. break;
  216. case WAN_SECRET_DOOR_DETECTION:
  217. if (!findit())
  218. return (1);
  219. break;
  220. case WAN_CREATE_MONSTER:
  221. {
  222. int cnt = 1;
  223. if (!rn2(23))
  224. cnt += rn2(7) + 1;
  225. while (cnt--)
  226. (void) makemon((struct permonst *) 0, u.ux, u.uy);
  227. }
  228. break;
  229. case WAN_WISHING:
  230. {
  231. char buf[BUFSZ];
  232. struct obj *otmp;
  233. if (u.uluck + rn2(5) < 0) {
  234. pline("Unfortunately, nothing happens.");
  235. break;
  236. }
  237. pline("You may wish for an object. What do you want? ");
  238. getlin(buf);
  239. if (buf[0] == '\033')
  240. buf[0] = 0;
  241. otmp = readobjnam(buf);
  242. otmp = addinv(otmp);
  243. prinv(otmp);
  244. break;
  245. }
  246. case WAN_DIGGING:
  247. /*
  248. * Original effect (approximately): from CORR: dig
  249. * until we pierce a wall from ROOM: piece wall and
  250. * dig until we reach an ACCESSIBLE place. Currently:
  251. * dig for digdepth positions; also down on request
  252. * of Lennart Augustsson.
  253. */
  254. {
  255. struct rm *room;
  256. int digdepth;
  257. if (u.uswallow) {
  258. struct monst *mtmp = u.ustuck;
  259. pline("You pierce %s's stomach wall!",
  260. monnam(mtmp));
  261. mtmp->mhp = 1; /* almost dead */
  262. unstuck(mtmp);
  263. mnexto(mtmp);
  264. break;
  265. }
  266. if (u.dz) {
  267. if (u.dz < 0) {
  268. pline("You loosen a rock from the ceiling.");
  269. pline("It falls on your head!");
  270. losehp(1, "falling rock");
  271. mksobj_at(ROCK, u.ux, u.uy);
  272. fobj->quan = 1;
  273. stackobj(fobj);
  274. if (Invisible)
  275. newsym(u.ux, u.uy);
  276. } else {
  277. dighole();
  278. }
  279. break;
  280. }
  281. zx = u.ux + u.dx;
  282. zy = u.uy + u.dy;
  283. digdepth = 8 + rn2(18);
  284. Tmp_at(-1, '*'); /* open call */
  285. while (--digdepth >= 0) {
  286. if (!isok(zx, zy))
  287. break;
  288. room = &levl[zx][zy];
  289. Tmp_at(zx, zy);
  290. if (!xdnstair) {
  291. if (zx < 3 || zx > COLNO - 3 ||
  292. zy < 3 || zy > ROWNO - 3)
  293. break;
  294. if (room->typ == HWALL ||
  295. room->typ == VWALL) {
  296. room->typ = ROOM;
  297. break;
  298. }
  299. } else if (room->typ == HWALL || room->typ == VWALL ||
  300. room->typ == SDOOR || room->typ == LDOOR) {
  301. room->typ = DOOR;
  302. digdepth -= 2;
  303. } else if (room->typ == SCORR || !room->typ) {
  304. room->typ = CORR;
  305. digdepth--;
  306. }
  307. mnewsym(zx, zy);
  308. zx += u.dx;
  309. zy += u.dy;
  310. }
  311. mnewsym(zx, zy); /* not always necessary */
  312. Tmp_at(-1, -1); /* closing call */
  313. break;
  314. }
  315. default:
  316. buzz((int) obj->otyp - WAN_MAGIC_MISSILE,
  317. u.ux, u.uy, u.dx, u.dy);
  318. break;
  319. }
  320. if (!objects[obj->otyp].oc_name_known) {
  321. objects[obj->otyp].oc_name_known = 1;
  322. more_experienced(0, 10);
  323. }
  324. }
  325. return (1);
  326. }
  327. const char *
  328. exclam(force)
  329. int force;
  330. {
  331. /* force == 0 occurs e.g. with sleep ray */
  332. /*
  333. * note that large force is usual with wands so that !! would require
  334. * information about hand/weapon/wand
  335. */
  336. return ((force < 0) ? "?" : (force <= 4) ? "." : "!");
  337. }
  338. void
  339. hit(str, mtmp, force)
  340. const char *str;
  341. struct monst *mtmp;
  342. const char *force; /* usually either "." or "!" */
  343. {
  344. if (!cansee(mtmp->mx, mtmp->my))
  345. pline("The %s hits it.", str);
  346. else
  347. pline("The %s hits %s%s", str, monnam(mtmp), force);
  348. }
  349. void
  350. miss(str, mtmp)
  351. const char *str;
  352. struct monst *mtmp;
  353. {
  354. if (!cansee(mtmp->mx, mtmp->my))
  355. pline("The %s misses it.", str);
  356. else
  357. pline("The %s misses %s.", str, monnam(mtmp));
  358. }
  359. /*
  360. * bhit: called when a weapon is thrown (sym = obj->olet) or when an
  361. * IMMEDIATE wand is zapped (sym = 0); the weapon falls down at end of range
  362. * or when a monster is hit; the monster is returned, and bhitpos is set to
  363. * the final position of the weapon thrown; the ray of a wand may affect
  364. * several objects and monsters on its path - for each of these an argument
  365. * function is called.
  366. */
  367. /* check !u.uswallow before calling bhit() */
  368. struct monst *
  369. bhit(ddx, ddy, range, sym, fhitm, fhito, obj)
  370. int ddx, ddy, range; /* direction and range */
  371. char sym; /* symbol displayed on path */
  372. /* fns called when mon/obj hit */
  373. void (*fhitm)(struct monst *, struct obj *);
  374. int (*fhito)(struct obj *, struct obj *);
  375. struct obj *obj; /* 2nd arg to fhitm/fhito */
  376. {
  377. struct monst *mtmp;
  378. struct obj *otmp;
  379. int typ;
  380. bhitpos.x = u.ux;
  381. bhitpos.y = u.uy;
  382. if (sym)
  383. tmp_at(-1, sym);/* open call */
  384. while (range-- > 0) {
  385. bhitpos.x += ddx;
  386. bhitpos.y += ddy;
  387. typ = levl[bhitpos.x][bhitpos.y].typ;
  388. if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != NULL) {
  389. if (sym) {
  390. tmp_at(-1, -1); /* close call */
  391. return (mtmp);
  392. }
  393. (*fhitm) (mtmp, obj);
  394. range -= 3;
  395. }
  396. if (fhito && (otmp = o_at(bhitpos.x, bhitpos.y))) {
  397. if ((*fhito) (otmp, obj))
  398. range--;
  399. }
  400. if (!ZAP_POS(typ)) {
  401. bhitpos.x -= ddx;
  402. bhitpos.y -= ddy;
  403. break;
  404. }
  405. if (sym)
  406. tmp_at(bhitpos.x, bhitpos.y);
  407. }
  408. /* leave last symbol unless in a pool */
  409. if (sym)
  410. tmp_at(-1, (levl[bhitpos.x][bhitpos.y].typ == POOL) ? -1 : 0);
  411. return (0);
  412. }
  413. struct monst *
  414. boomhit(int dx, int dy)
  415. {
  416. int i, ct;
  417. struct monst *mtmp;
  418. char sym = ')';
  419. bhitpos.x = u.ux;
  420. bhitpos.y = u.uy;
  421. for (i = 0; i < 8; i++)
  422. if (xdir[i] == dx && ydir[i] == dy)
  423. break;
  424. tmp_at(-1, sym); /* open call */
  425. for (ct = 0; ct < 10; ct++) {
  426. if (i == 8)
  427. i = 0;
  428. sym = ')' + '(' - sym;
  429. tmp_at(-2, sym);/* change let call */
  430. dx = xdir[i];
  431. dy = ydir[i];
  432. bhitpos.x += dx;
  433. bhitpos.y += dy;
  434. if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != NULL) {
  435. tmp_at(-1, -1);
  436. return (mtmp);
  437. }
  438. if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
  439. bhitpos.x -= dx;
  440. bhitpos.y -= dy;
  441. break;
  442. }
  443. if (bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
  444. if (rn2(20) >= 10 + u.ulevel) { /* we hit ourselves */
  445. (void) thitu(10, rnd(10), "boomerang");
  446. break;
  447. } else {/* we catch it */
  448. tmp_at(-1, -1);
  449. pline("Skillfully, you catch the boomerang.");
  450. return (&youmonst);
  451. }
  452. }
  453. tmp_at(bhitpos.x, bhitpos.y);
  454. if (ct % 5 != 0)
  455. i++;
  456. }
  457. tmp_at(-1, -1); /* do not leave last symbol */
  458. return (0);
  459. }
  460. char
  461. dirlet(dx, dy)
  462. int dx, dy;
  463. {
  464. return
  465. (dx == dy) ? '\\' : (dx && dy) ? '/' : dx ? '-' : '|';
  466. }
  467. /* type == -1: monster spitting fire at you */
  468. /* type == -1,-2,-3: bolts sent out by wizard */
  469. /* called with dx = dy = 0 with vertical bolts */
  470. void
  471. buzz(type, sx, sy, dx, dy)
  472. int type;
  473. xchar sx, sy;
  474. int dx, dy;
  475. {
  476. int abstype = abs(type);
  477. const char *fltxt = (type == -1) ? "blaze of fire" : fl[abstype];
  478. struct rm *lev;
  479. xchar range;
  480. struct monst *mon;
  481. if (u.uswallow) {
  482. int tmp;
  483. if (type < 0)
  484. return;
  485. tmp = zhit(u.ustuck, type);
  486. pline("The %s rips into %s%s",
  487. fltxt, monnam(u.ustuck), exclam(tmp));
  488. return;
  489. }
  490. if (type < 0)
  491. pru();
  492. range = rn1(7, 7);
  493. Tmp_at(-1, dirlet(dx, dy)); /* open call */
  494. while (range-- > 0) {
  495. sx += dx;
  496. sy += dy;
  497. if ((lev = &levl[sx][sy])->typ)
  498. Tmp_at(sx, sy);
  499. else {
  500. int bounce = 0;
  501. if (cansee(sx - dx, sy - dy))
  502. pline("The %s bounces!", fltxt);
  503. if (ZAP_POS(levl[sx][sy - dy].typ))
  504. bounce = 1;
  505. if (ZAP_POS(levl[sx - dx][sy].typ)) {
  506. if (!bounce || rn2(2))
  507. bounce = 2;
  508. }
  509. switch (bounce) {
  510. case 0:
  511. dx = -dx;
  512. dy = -dy;
  513. continue;
  514. case 1:
  515. dy = -dy;
  516. sx -= dx;
  517. break;
  518. case 2:
  519. dx = -dx;
  520. sy -= dy;
  521. break;
  522. }
  523. Tmp_at(-2, dirlet(dx, dy));
  524. continue;
  525. }
  526. if (lev->typ == POOL && abstype == 1 /* fire */ ) {
  527. range -= 3;
  528. lev->typ = ROOM;
  529. if (cansee(sx, sy)) {
  530. mnewsym(sx, sy);
  531. pline("The water evaporates.");
  532. } else
  533. pline("You hear a hissing sound.");
  534. }
  535. if ((mon = m_at(sx, sy)) &&
  536. (type != -1 || mon->data->mlet != 'D')) {
  537. wakeup(mon);
  538. if (rnd(20) < 18 + mon->data->ac) {
  539. int tmp = zhit(mon, abstype);
  540. if (mon->mhp < 1) {
  541. if (type < 0) {
  542. if (cansee(mon->mx, mon->my))
  543. pline("%s is killed by the %s!",
  544. Monnam(mon), fltxt);
  545. mondied(mon);
  546. } else
  547. killed(mon);
  548. } else
  549. hit(fltxt, mon, exclam(tmp));
  550. range -= 2;
  551. } else
  552. miss(fltxt, mon);
  553. } else if (sx == u.ux && sy == u.uy) {
  554. nomul(0);
  555. if (rnd(20) < 18 + u.uac) {
  556. int dam = 0;
  557. range -= 2;
  558. pline("The %s hits you!", fltxt);
  559. switch (abstype) {
  560. case 0:
  561. dam = d(2, 6);
  562. break;
  563. case 1:
  564. if (Fire_resistance)
  565. pline("You don't feel hot!");
  566. else
  567. dam = d(6, 6);
  568. if (!rn2(3))
  569. burn_scrolls();
  570. break;
  571. case 2:
  572. nomul(-rnd(25)); /* sleep ray */
  573. break;
  574. case 3:
  575. if (Cold_resistance)
  576. pline("You don't feel cold!");
  577. else
  578. dam = d(6, 6);
  579. break;
  580. case 4:
  581. u.uhp = -1;
  582. }
  583. losehp(dam, fltxt);
  584. } else
  585. pline("The %s whizzes by you!", fltxt);
  586. stop_occupation();
  587. }
  588. if (!ZAP_POS(lev->typ)) {
  589. int bounce = 0, rmn;
  590. if (cansee(sx, sy))
  591. pline("The %s bounces!", fltxt);
  592. range--;
  593. if (!dx || !dy || !rn2(20)) {
  594. dx = -dx;
  595. dy = -dy;
  596. } else {
  597. if (ZAP_POS(rmn = levl[sx][sy - dy].typ) &&
  598. (IS_ROOM(rmn) || ZAP_POS(levl[sx + dx][sy - dy].typ)))
  599. bounce = 1;
  600. if (ZAP_POS(rmn = levl[sx - dx][sy].typ) &&
  601. (IS_ROOM(rmn) || ZAP_POS(levl[sx - dx][sy + dy].typ)))
  602. if (!bounce || rn2(2))
  603. bounce = 2;
  604. switch (bounce) {
  605. case 0:
  606. dy = -dy;
  607. dx = -dx;
  608. break;
  609. case 1:
  610. dy = -dy;
  611. break;
  612. case 2:
  613. dx = -dx;
  614. break;
  615. }
  616. Tmp_at(-2, dirlet(dx, dy));
  617. }
  618. }
  619. }
  620. Tmp_at(-1, -1);
  621. }
  622. int
  623. zhit(mon, type) /* returns damage to mon */
  624. struct monst *mon;
  625. int type;
  626. {
  627. int tmp = 0;
  628. switch (type) {
  629. case 0: /* magic missile */
  630. tmp = d(2, 6);
  631. break;
  632. case -1: /* Dragon blazing fire */
  633. case 1: /* fire */
  634. if (strchr("Dg", mon->data->mlet))
  635. break;
  636. tmp = d(6, 6);
  637. if (strchr("YF", mon->data->mlet))
  638. tmp += 7;
  639. break;
  640. case 2: /* sleep */
  641. mon->mfroz = 1;
  642. break;
  643. case 3: /* cold */
  644. if (strchr("YFgf", mon->data->mlet))
  645. break;
  646. tmp = d(6, 6);
  647. if (mon->data->mlet == 'D')
  648. tmp += 7;
  649. break;
  650. case 4: /* death */
  651. if (strchr(UNDEAD, mon->data->mlet))
  652. break;
  653. tmp = mon->mhp + 1;
  654. break;
  655. }
  656. mon->mhp -= tmp;
  657. return (tmp);
  658. }
  659. #define CORPSE_I_TO_C(otyp) (char) ((otyp >= DEAD_ACID_BLOB)\
  660. ? 'a' + (otyp - DEAD_ACID_BLOB)\
  661. : '@' + (otyp - DEAD_HUMAN))
  662. int
  663. revive(obj)
  664. struct obj *obj;
  665. {
  666. struct monst *mtmp = NULL;
  667. if (obj->olet == FOOD_SYM && obj->otyp > CORPSE) {
  668. /* do not (yet) revive shopkeepers */
  669. /*
  670. * Note: this might conceivably produce two monsters at the
  671. * same position - strange, but harmless
  672. */
  673. mtmp = mkmon_at(CORPSE_I_TO_C(obj->otyp), obj->ox, obj->oy);
  674. delobj(obj);
  675. }
  676. return (!!mtmp); /* TRUE if some monster created */
  677. }
  678. void
  679. rloco(obj)
  680. struct obj *obj;
  681. {
  682. int tx, ty, otx, oty;
  683. otx = obj->ox;
  684. oty = obj->oy;
  685. do {
  686. tx = rn1(COLNO - 3, 2);
  687. ty = rn2(ROWNO);
  688. } while (!goodpos(tx, ty));
  689. obj->ox = tx;
  690. obj->oy = ty;
  691. if (cansee(otx, oty))
  692. newsym(otx, oty);
  693. }
  694. void
  695. fracture_rock(obj) /* fractured by pick-axe or wand of striking */
  696. struct obj *obj; /* no texts here! */
  697. {
  698. /* unpobj(obj); */
  699. obj->otyp = ROCK;
  700. obj->quan = 7 + rn2(60);
  701. obj->owt = weight(obj);
  702. obj->olet = WEAPON_SYM;
  703. if (cansee(obj->ox, obj->oy))
  704. prl(obj->ox, obj->oy);
  705. }
  706. void
  707. burn_scrolls()
  708. {
  709. struct obj *obj, *obj2;
  710. int cnt = 0;
  711. for (obj = invent; obj; obj = obj2) {
  712. obj2 = obj->nobj;
  713. if (obj->olet == SCROLL_SYM) {
  714. cnt++;
  715. useup(obj);
  716. }
  717. }
  718. if (cnt > 1) {
  719. pline("Your scrolls catch fire!");
  720. losehp(cnt, "burning scrolls");
  721. } else if (cnt) {
  722. pline("Your scroll catches fire!");
  723. losehp(1, "burning scroll");
  724. }
  725. }