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