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