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