Wikihack
Advertisement

Below is the full text to zap.c from the source code of NetHack 2.2a. To link to a particular line, write [[NetHack 2.2a/zap.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

Screenshots and source code from Hack are used under the CWI license.
1.    /*	SCCS Id: @(#)zap.c	2.1	87/11/10
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    
4.    #include "hack.h"
5.    
6.    extern struct obj *mkobj_at();
7.    extern struct monst *makemon(), *mkmon_at(), youmonst;
8.    struct monst *bhit();
9.    char *exclam();
10.   #ifdef KAA
11.   extern char *xname();
12.   #endif
13.   
14.   char *fl[]= {
15.   	"magic missile",
16.   	"bolt of fire",
17.   	"sleep ray",
18.   	"bolt of cold",
19.   	"death ray",
20.   	"magic missile",	/* Spell equivalents of above wands */
21.   	"fireball",
22.   	"sleep ray",
23.   	"cone of cold",
24.   	"finger of death"
25.   };
26.   
27.   /* Routines for IMMEDIATE wands and spells. */
28.   /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
29.   bhitm(mtmp, otmp)
30.   register struct monst *mtmp;
31.   register struct obj *otmp;
32.   {
33.   	wakeup(mtmp);
34.   	switch(otmp->otyp) {
35.   	case WAN_STRIKING:
36.   #ifdef SPELLS
37.   	case SPE_FORCE_BOLT:
38.   #endif
39.   		if(u.uswallow || rnd(20) < 10+mtmp->data->ac) {
40.   			register int tmp = d(2,12);
41.   			hit((otmp->otyp == WAN_STRIKING) ? "wand" : "spell", mtmp, exclam(tmp));
42.   			resist(mtmp, otmp->olet, tmp, TELL);
43.   		} else miss((otmp->otyp == WAN_STRIKING) ? "wand" : "spell", mtmp);
44.   		break;
45.   	case WAN_SLOW_MONSTER:
46.   #ifdef SPELLS
47.   	case SPE_SLOW_MONSTER:
48.   #endif
49.   		if(! resist(mtmp, otmp->olet, 0, NOTELL))
50.   			mtmp->mspeed = MSLOW;
51.   		break;
52.   	case WAN_SPEED_MONSTER:
53.   		if (!resist(mtmp, otmp->olet, 0, NOTELL))
54.   			mtmp->mspeed = MFAST;
55.   		break;
56.   	case WAN_UNDEAD_TURNING:
57.   #ifdef SPELLS
58.   	case SPE_TURN_UNDEAD:
59.   #endif
60.   		if(index(UNDEAD,mtmp->data->mlet)) {
61.   
62.   			if(!resist(mtmp, otmp->olet, rnd(8), NOTELL))
63.   				mtmp->mflee = 1;
64.   		}
65.   		break;
66.   	case WAN_POLYMORPH:
67.   #ifdef SPELLS
68.   	case SPE_POLYMORPH:
69.   #endif
70.   		if(!resist(mtmp, otmp->olet, 0, NOTELL))
71.   		    if( newcham(mtmp,&mons[rn2(CMNUM)]) )
72.   			if (!Hallucination)
73.   			    objects[otmp->otyp].oc_name_known = 1;
74.   		break;
75.   	case WAN_CANCELLATION:
76.   #ifdef SPELLS
77.   	case SPE_CANCELLATION:
78.   #endif
79.   		if(!resist(mtmp, otmp->olet, 0, NOTELL))
80.   			mtmp->mcan = 1;
81.   		break;
82.   	case WAN_TELEPORTATION:
83.   #ifdef SPELLS
84.   	case SPE_TELEPORT_AWAY:
85.   #endif
86.   		rloc(mtmp);
87.   		break;
88.   	case WAN_MAKE_INVISIBLE:
89.   		mtmp->minvis = 1;
90.   		break;
91.   	case WAN_NOTHING:
92.   		break;
93.   	case WAN_PROBING:
94.   #ifdef PROBING
95.   		mstatusline(mtmp);
96.   #else
97.   		pline("Nothing Happens.");
98.   #endif
99.   		break;
100.  	default:
101.  		impossible("What an interesting effect (%u)", otmp->otyp);
102.  	}
103.  }
104.  
105.  bhito(obj, otmp)	/* object obj was hit by the effect of wand otmp */
106.  register struct obj *obj, *otmp;	/* returns TRUE if sth was done */
107.  {
108.  	register int res = TRUE;
109.  #ifdef DGKMOD
110.  	struct obj *otmp2;
111.  #endif
112.  
113.  	if(obj == uball || obj == uchain)
114.  		res = FALSE;
115.  	else
116.  	switch(otmp->otyp) {
117.  	case WAN_POLYMORPH:
118.  #ifdef SPELLS
119.  	case SPE_POLYMORPH:
120.  #endif
121.  		/* preserve symbol and quantity, but turn rocks into gems */
122.  #ifdef DGKMOD
123.  		otmp2 = mkobj_at((obj->otyp == ROCK
124.  			|| obj->otyp == ENORMOUS_ROCK) ? GEM_SYM : obj->olet,
125.  			obj->ox, obj->oy);
126.  		otmp2->quan = obj->quan;
127.  		/* keep special fields (including charges on wands) */
128.  		/* The DGK modification doesn't allow polymorphing a weapon
129.  		   with enchantments into another one, and doesn't allow 
130.  		   polymorphed rings to have plusses.  KAA*/
131.  		if (index("/)[", otmp2->olet)) otmp2->spe = obj->spe;
132.  	        /* Amulets gets cheap   stewr 870807 */
133.  		if (obj->otyp == AMULET_OF_YENDOR) otmp2->spe = obj->spe;
134.  		/* Wands of wishing max 3 stewr 870808 */
135.  		if ((otmp2->otyp == WAN_WISHING) 
136.  		    && (obj->spe > 3)) otmp2->spe = 3;
137.  		otmp2->cursed = otmp->cursed;
138.  		/* update the weight */
139.  		otmp2->owt = weight(otmp2);
140.  #else
141.  		mkobj_at((obj->otyp == ROCK || obj->otyp == ENORMOUS_ROCK)
142.  			? GEM_SYM : obj->olet,
143.  			obj->ox, obj->oy) -> quan = obj->quan;
144.  #endif
145.  		delobj(obj);
146.  		break;
147.  	case WAN_STRIKING:
148.  #ifdef SPELLS
149.  	case SPE_FORCE_BOLT:
150.  #endif
151.  		if(obj->otyp == ENORMOUS_ROCK)
152.  			fracture_rock(obj);
153.  		else
154.  			res = FALSE;
155.  		break;
156.  	case WAN_CANCELLATION:
157.  #ifdef SPELLS
158.  	case SPE_CANCELLATION:
159.  #endif
160.  		if(obj->spe && obj->olet != AMULET_SYM) {
161.  			obj->known = 0;
162.  			obj->spe = (obj->olet == WAND_SYM) ? -1 : 0;
163.  		}
164.  		break;
165.  	case WAN_TELEPORTATION:
166.  #ifdef SPELLS
167.  	case SPE_TELEPORT_AWAY:
168.  #endif
169.  		rloco(obj);
170.  		break;
171.  	case WAN_MAKE_INVISIBLE:
172.  		obj->oinvis = 1;
173.  		break;
174.  	case WAN_UNDEAD_TURNING:
175.  #ifdef SPELLS
176.  	case SPE_TURN_UNDEAD:
177.  #endif
178.  		res = revive(obj);
179.  		break;
180.  	case WAN_SLOW_MONSTER:		/* no effect on objects */
181.  #ifdef SPELLS
182.  	case SPE_SLOW_MONSTER:
183.  #endif
184.  	case WAN_SPEED_MONSTER:
185.  	case WAN_NOTHING:
186.  	case WAN_PROBING:
187.  		res = FALSE;
188.  		break;
189.  	default:
190.  		impossible("What an interesting effect (%u)", otmp->otyp);
191.  	}
192.  	return(res);
193.  }
194.  
195.  /*
196.   * zappable - returns 1 if zap is available, 0 otherwise.
197.   *	      it removes a charge from the wand if zappable.
198.   * added by GAN 11/03/86
199.   */
200.  int
201.  zappable(wand)
202.  register struct obj *wand;
203.  {
204.  	if(wand->spe < 0 || (wand->spe ==0 && rn2(121)))
205.  		return(0);
206.  	else  {
207.  		if(wand->spe == 0)
208.  			pline("You wrest one more spell from the worn-out wand.");
209.  		wand->spe--;
210.  		return(1);
211.  	}
212.  }
213.  
214.  /*
215.   * zapnodir - zaps an NODIR wand.
216.   * added by GAN 11/03/86
217.   */
218.  zapnodir(wand)
219.  register struct obj *wand;
220.  {
221.  	switch(wand->otyp){
222.  		case WAN_LIGHT:
223.  			litroom(TRUE);
224.  			break;
225.  		case WAN_SECRET_DOOR_DETECTION:
226.  			if(!findit()) return;
227.  			break;
228.  		case WAN_CREATE_MONSTER:
229.  			{ register int cnt = 1;
230.  			if(!rn2(23)) cnt += rn2(7) + 1;
231.  			while(cnt--)
232.  			    (void) makemon((struct permonst *) 0, u.ux, u.uy);
233.  			}
234.  			break;
235.  		case WAN_WISHING:
236.  			  
237.  			if(u.uluck + rn2(5) < 0) {
238.  				pline("Unfortunately, nothing happens.");
239.  				break;
240.  			}
241.  			makewish();
242.  			break;
243.  	}
244.  	if(!objects[wand->otyp].oc_name_known) {
245.  			objects[wand->otyp].oc_name_known = 1;
246.  			more_experienced(0,10);
247.  	}
248.  }
249.  
250.  dozap()
251.  {
252.  	register struct obj *obj;
253.  	int	damage;
254.  
255.  	obj = getobj("/", "zap");
256.  	if(!obj) return(0);
257.  	
258.  	/* zappable addition done by GAN 11/03/86 */
259.  	if(!zappable(obj))  {
260.  		pline("Nothing Happens.");
261.  		return(1);
262.  	}
263.  	if(!(objects[obj->otyp].bits & NODIR) && !getdir(1)) {
264.  		pline("The %s glows and fades.",xname(obj));
265.  		return(1);	/* make him pay for knowing !NODIR */
266.  	}
267.  #ifdef KAA
268.       if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].bits & NODIR)) {
269.  
270.  		if((damage = zapyourself(obj)))
271.  			losehp(damage,"self-inflicted injury");
272.  		return(1);
273.       }
274.  #endif
275.  	weffects(obj);
276.  #ifdef HARD
277.  	if (obj->spe < 0) {
278.  	    pline ("The %s glows violently, then turns to dust.", xname(obj));
279.  	    useup(obj);
280.  	}
281.  #endif
282.  	return(1);
283.  }
284.  
285.  #ifdef KAA
286.  #define	makeknown(x)	objects[x].oc_name_known = 1
287.  
288.  zapyourself(obj)
289.  	register struct obj	*obj;
290.  {
291.  struct obj	*otmp;
292.  int	damage = 0;
293.  
294.  	switch(obj->otyp) {
295.  		case WAN_STRIKING:
296.  #ifdef SPELLS
297.  		case SPE_FORCE_BOLT:
298.  #endif
299.  		    pline("You magically bash yourself!");
300.  		    damage=d(8,6);
301.  		    break;
302.  		case WAN_FIRE:
303.  		    makeknown(WAN_FIRE);
304.  #ifdef SPELLS
305.  		case SPE_FIREBALL:
306.  #endif
307.  		    pline("You've set light to yourself!");
308.  		    if (!Fire_resistance) damage=d(12,6);
309.  		    burn_scrolls();
310.  		    boil_potions();
311.  		    break;
312.  		case WAN_COLD:
313.  		    makeknown(WAN_COLD);
314.  #ifdef SPELLS
315.  		case SPE_CONE_OF_COLD:
316.  #endif
317.  		    pline("You imitate a popsicle!");
318.  		    if (!Cold_resistance) damage=d(12,6);
319.  		    break;
320.  		case WAN_MAGIC_MISSILE:
321.  		    makeknown(WAN_MAGIC_MISSILE);
322.  #ifdef SPELLS
323.  		case SPE_MAGIC_MISSILE:
324.  #endif
325.  		    damage = d(4,6);
326.  		    pline("Idiot!  You've shot yourself!"); 
327.  		    break;
328.  		case WAN_POLYMORPH:
329.  		    makeknown(WAN_POLYMORPH);
330.  #ifdef SPELLS
331.  		case SPE_POLYMORPH:
332.  #endif
333.  		    polyself();
334.  		    break;
335.  		case WAN_CANCELLATION:
336.  #ifdef SPELLS
337.  		case SPE_CANCELLATION:
338.  #endif
339.  		    for(otmp = invent; otmp; otmp = otmp->nobj)
340.  		       if(otmp != uball && otmp->otyp != AMULET_OF_YENDOR)
341.  			    otmp->spe = (obj->olet == WAND_SYM) ? -1 : 0;
342.  		    if(u.mtimedone) rehumanize();
343.  		    flags.botl = 1;  /* because of potential AC change */
344.  		    find_ac();
345.  		    break;
346.  	       case WAN_MAKE_INVISIBLE:
347.  		    HInvis |= INTRINSIC;
348.  		    /* Tough luck if you cannot see invisible! */
349.  		    if (!See_invisible) newsym(u.ux, u.uy);
350.  		    break;
351.  	       case WAN_SPEED_MONSTER:
352.  		    Fast |= INTRINSIC;
353.  		    break;
354.  	       case WAN_SLEEP:
355.  		    makeknown(WAN_SLEEP);
356.  #ifdef SPELLS
357.  		case SPE_SLEEP:
358.  #endif
359.  		    pline("The sleep ray hits you!");
360.  		    nomul(-rn2(50));
361.  		    break;
362.  		case WAN_SLOW_MONSTER:
363.  #ifdef SPELLS
364.  		case SPE_SLOW_MONSTER:
365.  #endif
366.  		    Fast = 0;
367.  		    break;
368.  		case WAN_TELEPORTATION:
369.  #ifdef SPELLS
370.  		case SPE_TELEPORT_AWAY:
371.  #endif
372.  		    tele();
373.  		    break;
374.  		case WAN_DEATH:
375.  #ifdef SPELLS
376.  		case SPE_FINGER_OF_DEATH:
377.  #endif
378.  		    killer = "death ray";
379.  		    pline("You irradiate yourself with pure energy!");
380.  		    pline("You die.");
381.  		    done("died");
382.  		    break;
383.  #ifdef SPELLS
384.  		case SPE_LIGHT:
385.  		    pline("You've blinded yourself!");
386.  		    Blinded += rnd(100);
387.  		    break;		
388.  		case SPE_DIG:
389.  		case SPE_TURN_UNDEAD:
390.  		case SPE_DETECT_UNSEEN:
391.  #endif
392.  	       case WAN_PROBING:
393.  #ifdef PROBING
394.  		    ustatusline();
395.  #else
396.  		    pline("Nothing happens.");
397.  #endif
398.  		    break;
399.  		case WAN_DIGGING:
400.  		case WAN_UNDEAD_TURNING:
401.  		case WAN_NOTHING:
402.  		    break;
403.  		default: impossible("object %d used?",obj->otyp);
404.  	}
405.  	return(damage);
406.  }
407.  #endif /* KAA /**/
408.  
409.  /* called for various wand and spell effects - M. Stephenson */
410.  weffects(obj)
411.  	register struct	obj	*obj;
412.  {
413.  	xchar zx,zy;
414.  
415.  	if(objects[obj->otyp].bits & IMMEDIATE) {
416.  		if(u.uswallow)
417.  			bhitm(u.ustuck, obj);
418.  		else if(u.dz) {
419.  			if(u.dz > 0 && o_at(u.ux,u.uy)) {
420.  				register struct obj *otmp;
421.  				
422.  				/* changed by GAN to hit all objects there */
423.  				for(otmp = fobj; otmp ; otmp = otmp->nobj)
424.  					if(otmp->ox == u.ux &&
425.  					   otmp->oy == u.uy)
426.  						(void) bhito(otmp, obj);
427.  			}
428.  		} else
429.  			(void) bhit(u.dx,u.dy,rn1(8,6),0,bhitm,bhito,obj);
430.  	} else {
431.  	    switch(obj->otyp){
432.  		case WAN_LIGHT:
433.  #ifdef SPELLS
434.  		case SPE_LIGHT:
435.  #endif
436.  			litroom(TRUE);
437.  			break;
438.  		case WAN_SECRET_DOOR_DETECTION:
439.  #ifdef SPELLS
440.  		case SPE_DETECT_UNSEEN:
441.  #endif
442.  			if(!findit()) return;
443.  			break;
444.  		case WAN_CREATE_MONSTER:
445.  			{ register int cnt = 1;
446.  			if(!rn2(23)) cnt += rn2(7) + 1;
447.  			while(cnt--)
448.  			    (void) makemon((struct permonst *) 0, u.ux, u.uy);
449.  			}
450.  			break;
451.  		case WAN_WISHING:
452.  			if(u.uluck + rn2(5) < 0) {
453.  			    pline("Unfortunately, nothing happens.");
454.  			    break;
455.  			}
456.  			makewish();
457.  			break;
458.  		case WAN_DIGGING:
459.  #ifdef SPELLS
460.  		case SPE_DIG:
461.  #endif
462.  			/* Original effect (approximately):
463.  			 * from CORR: dig until we pierce a wall
464.  			 * from ROOM: piece wall and dig until we reach
465.  			 * an ACCESSIBLE place.
466.  			 * Currently: dig for digdepth positions;
467.  			 * also down on request of Lennart Augustsson.
468.  			 */
469.  			{ register struct rm *room;
470.  			  register int digdepth;
471.  			if(u.uswallow) {
472.  				register struct monst *mtmp = u.ustuck;
473.  
474.  				pline("You pierce %s's stomach wall!",
475.  					monnam(mtmp));
476.  				mtmp->mhp = 1;	/* almost dead */
477.  				unstuck(mtmp);
478.  				mnexto(mtmp);
479.  				break;
480.  			}
481.  			if(u.dz) {
482.  			    if(u.dz < 0) {
483.  				pline("You loosen a rock from the ceiling.");
484.  				pline("It falls on your head!");
485.  				losehp(1, "falling rock");
486.  				mksobj_at(ROCK, u.ux, u.uy);
487.  				fobj->quan = 1;
488.  				stackobj(fobj);
489.  				if(Invisible) newsym(u.ux, u.uy);
490.  			    } else {
491.  				dighole();
492.  			    }
493.  			    break;
494.  			}
495.  			zx = u.ux+u.dx;
496.  			zy = u.uy+u.dy;
497.  			digdepth = 8 + rn2(18);
498.  			Tmp_at(-1, '*');	/* open call */
499.  			while(--digdepth >= 0) {
500.  				if(!isok(zx,zy)) break;
501.  				room = &levl[zx][zy];
502.  				Tmp_at(zx,zy);
503.  				if(!xdnstair){
504.  					if(zx < 3 || zx > COLNO-3 ||
505.  					    zy < 3 || zy > ROWNO-3)
506.  						break;
507.  					if(room->typ == HWALL ||
508.  					    room->typ == VWALL){
509.  						room->typ = ROOM;
510.  						break;
511.  					}
512.  				} else
513.  				if(room->typ == HWALL || room->typ == VWALL ||
514.  				   room->typ == SDOOR || room->typ == LDOOR){
515.  					room->typ = DOOR;
516.  					digdepth -= 2;
517.  				} else
518.  				if(room->typ == SCORR || !room->typ) {
519.  					room->typ = CORR;
520.  					digdepth--;
521.  				}
522.  				mnewsym(zx,zy);
523.  				zx += u.dx;
524.  				zy += u.dy;
525.  			}
526.  			mnewsym(zx,zy);	/* not always necessary */
527.  			Tmp_at(-1,-1);	/* closing call */
528.  			break;
529.  			}
530.  		default:
531.  #ifdef SPELLS
532.  			if((int) obj->otyp >= SPE_MAGIC_MISSILE) {
533.  
534.  				buzz((int) obj->otyp - SPE_MAGIC_MISSILE + 5,
535.  					u.ux, u.uy, u.dx, u.dy);
536.  			} else
537.  #endif
538.  
539.  				buzz((int) obj->otyp - WAN_MAGIC_MISSILE,
540.  					u.ux, u.uy, u.dx, u.dy);
541.  			break;
542.  		}
543.  		if(!objects[obj->otyp].oc_name_known) {
544.  			objects[obj->otyp].oc_name_known = 1;
545.  			more_experienced(0,10);
546.  		}
547.  	}
548.  	return;
549.  }
550.  
551.  char *
552.  exclam(force)
553.  register int force;
554.  {
555.  	/* force == 0 occurs e.g. with sleep ray */
556.  	/* note that large force is usual with wands so that !! would
557.  		require information about hand/weapon/wand */
558.  	return( (force < 0) ? "?" : (force <= 4) ? "." : "!" );
559.  }
560.  
561.  hit(str,mtmp,force)
562.  register char *str;
563.  register struct monst *mtmp;
564.  register char *force;		/* usually either "." or "!" */
565.  {
566.  	if(!cansee(mtmp->mx,mtmp->my)) pline("The %s hits it.", str);
567.  	else pline("The %s hits %s%s", str, monnam(mtmp), force);
568.  }
569.  
570.  miss(str,mtmp)
571.  register char *str;
572.  register struct monst *mtmp;
573.  {
574.  	if(!cansee(mtmp->mx,mtmp->my)) pline("The %s misses it.",str);
575.  	else pline("The %s misses %s.",str,monnam(mtmp));
576.  }
577.  
578.  /* bhit: called when a weapon is thrown (sym = obj->olet) or when an
579.     IMMEDIATE wand is zapped (sym = 0); the weapon falls down at end of
580.     range or when a monster is hit; the monster is returned, and bhitpos
581.     is set to the final position of the weapon thrown; the ray of a wand
582.     may affect several objects and monsters on its path - for each of
583.     these an argument function is called. */
584.  /* check !u.uswallow before calling bhit() */
585.  
586.  struct monst *
587.  bhit(ddx,ddy,range,sym,fhitm,fhito,obj)
588.  register int ddx,ddy,range;		/* direction and range */
589.  char sym;				/* symbol displayed on path */
590.  int (*fhitm)(), (*fhito)();		/* fns called when mon/obj hit */
591.  struct obj *obj;			/* 2nd arg to fhitm/fhito */
592.  {
593.  	register struct monst *mtmp;
594.  	register struct obj *otmp;
595.  	register int typ;
596.  
597.  	bhitpos.x = u.ux;
598.  	bhitpos.y = u.uy;
599.  
600.  	if(sym) tmp_at(-1, sym);	/* open call */
601.  	while(range-- > 0) {
602.  		bhitpos.x += ddx;
603.  		bhitpos.y += ddy;
604.  		typ = levl[bhitpos.x][bhitpos.y].typ;
605.  		if(mtmp = m_at(bhitpos.x,bhitpos.y)){
606.  			if(sym) {
607.  				tmp_at(-1, -1);	/* close call */
608.  				return(mtmp);
609.  			}
610.  			(*fhitm)(mtmp, obj);
611.  			range -= 3;
612.  		}
613.  		/* modified by GAN to hit all objects */
614.  		if(fhito && o_at(bhitpos.x,bhitpos.y)){
615.  			int hitanything = 0;
616.  			for(otmp = fobj; otmp; otmp = otmp->nobj)
617.  				if(otmp->ox == bhitpos.x &&
618.  				   otmp->oy == bhitpos.y)
619.  					hitanything += (*fhito)(otmp, obj);
620.  			if(hitanything)	range--;
621.  		}
622.  		if(!ZAP_POS(typ)) {
623.  			bhitpos.x -= ddx;
624.  			bhitpos.y -= ddy;
625.  			break;
626.  		}
627.  		if(sym) tmp_at(bhitpos.x, bhitpos.y);
628.  	}
629.  
630.  	/* leave last symbol unless in a pool */
631.  	if(sym)
632.  	   tmp_at(-1, (levl[bhitpos.x][bhitpos.y].typ == POOL) ? -1 : 0);
633.  	return(0);
634.  }
635.  
636.  struct monst *
637.  boomhit(dx,dy) {
638.  	register int i, ct;
639.  	register struct monst *mtmp;
640.  	char sym = ')';
641.  	extern schar xdir[], ydir[];
642.  
643.  	bhitpos.x = u.ux;
644.  	bhitpos.y = u.uy;
645.  
646.  	for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break;
647.  	tmp_at(-1, sym);	/* open call */
648.  	for(ct=0; ct<10; ct++) {
649.  		if(i == 8) i = 0;
650.  		sym = ')' + '(' - sym;
651.  		tmp_at(-2, sym);	/* change let call */
652.  		dx = xdir[i];
653.  		dy = ydir[i];
654.  		bhitpos.x += dx;
655.  		bhitpos.y += dy;
656.  		if(mtmp = m_at(bhitpos.x, bhitpos.y)){
657.  			tmp_at(-1,-1);
658.  			return(mtmp);
659.  		}
660.  		if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
661.  			bhitpos.x -= dx;
662.  			bhitpos.y -= dy;
663.  			break;
664.  		}
665.  		if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
666.  			if(rn2(20) >= 10+u.ulevel){	/* we hit ourselves */
667.  				(void) thitu(10, rnd(10), "boomerang");
668.  				break;
669.  			} else {	/* we catch it */
670.  				tmp_at(-1,-1);
671.  				pline("Skillfully, you catch the boomerang.");
672.  				return(&youmonst);
673.  			}
674.  		}
675.  		tmp_at(bhitpos.x, bhitpos.y);
676.  		if(ct % 5 != 0) i++;
677.  	}
678.  	tmp_at(-1, -1);	/* do not leave last symbol */
679.  	return(0);
680.  }
681.  
682.  uchar
683.  dirlet(dx,dy) register dx,dy; {
684.  	return
685.  		(dx == dy) ? '\\' : (dx && dy) ? '/' : dx ? HWALL_SYM : VWALL_SYM;
686.  }
687.  
688.  /* type == -1: monster spitting fire at you */
689.  /* type == -1,-2,-3: bolts sent out by wizard */
690.  /* called with dx = dy = 0 with vertical bolts */
691.  buzz(type,sx,sy,dx,dy)
692.  register int type;
693.  register xchar sx,sy;
694.  register int dx,dy;
695.  {
696.  	int abstype = (type == 10) ? 1 : abs(type);
697.  	register char *fltxt = (type == -1 || type == 10) ? "blaze of fire" : fl[abstype];
698.  	struct rm *lev;
699.  	xchar range;
700.  	struct monst *mon;
701.  
702.  	if(u.uswallow) {
703.  		register int tmp;
704.  
705.  		if(type < 0) return;
706.  		tmp = zhit(u.ustuck, type);
707.  		if(!u.ustuck)	u.uswallow = 0;
708.  		else	pline("The %s rips into %s%s",
709.  				fltxt, monnam(u.ustuck), exclam(tmp));
710.  		return;
711.  	}
712.  	if(type < 0) pru();
713.  	range = rn1(7,7);
714.  	Tmp_at(-1, dirlet(dx,dy));	/* open call */
715.  	while(range-- > 0) {
716.  		sx += dx;
717.  		sy += dy;
718.  		if((lev = &levl[sx][sy])->typ) Tmp_at(sx,sy);
719.  		else {
720.  			int bounce = 0;
721.  			if(cansee(sx-dx,sy-dy))
722.  				pline("The %s bounces!", fltxt);
723.  			if(ZAP_POS(levl[sx][sy-dy].typ))
724.  				bounce = 1;
725.  			if(ZAP_POS(levl[sx-dx][sy].typ)) {
726.  				if(!bounce || rn2(2)) bounce = 2;
727.  			}
728.  			switch(bounce){
729.  			case 0:
730.  				dx = -dx;
731.  				dy = -dy;
732.  				continue;
733.  			case 1:
734.  				dy = -dy;
735.  				sx -= dx;
736.  				break;
737.  			case 2:
738.  				dx = -dx;
739.  				sy -= dy;
740.  				break;
741.  			}
742.  			Tmp_at(-2,dirlet(dx,dy));
743.  			continue;
744.  		}
745.  		if(lev->typ == POOL && abstype == 1 /* fire */) {
746.  			range -= 3;
747.  			lev->typ = ROOM;
748.  			if(cansee(sx,sy)) {
749.  				mnewsym(sx,sy);
750.  				pline("The water evaporates.");
751.  			} else
752.  				pline("You hear a hissing sound.");
753.  		}
754.  		if(o_at(sx,sy) && abstype == 1)
755.  			if(burn_floor_scrolls(sx,sy) && cansee(sx,sy))  {
756.  				mnewsym(sx,sy);
757.  				pline("You see a puff of smoke.");
758.  			}
759.  		if((mon = m_at(sx,sy)) &&
760.  		   (type != -1 || mon->data->mlet != 'D')) {
761.  			wakeup(mon);
762.  			if(rnd(20) < 18 + mon->data->ac) {
763.  				register int tmp = zhit(mon,abstype);
764.  				if(mon->mhp < 1) {
765.  					if(type < 0) {
766.  					    if(cansee(mon->mx,mon->my))
767.  					      pline("%s is killed by the %s!",
768.  						Monnam(mon), fltxt);
769.  					    mondied(mon);
770.  					} else
771.  					    killed(mon);
772.  				} else
773.  					hit(fltxt, mon, exclam(tmp));
774.  				range -= 2;
775.  			} else
776.  				miss(fltxt,mon);
777.  		} else if(sx == u.ux && sy == u.uy) {
778.  			nomul(0);
779.  			if(rnd(20) < 18+u.uac) {
780.  				register int dam = 0;
781.  				range -= 2;
782.  				pline("The %s hits you!",fltxt);
783.  				switch(abstype) {
784.  				case 0:
785.  				case 5:	dam = d(2,6);
786.  					break;
787.  				case 1:
788.  				case 6:	if(Fire_resistance)
789.  						pline("You don't feel hot!");
790.  					else dam = d(6,6);
791.  					if(!rn2(3)) {
792.  						boil_potions();
793.  						burn_scrolls();
794.  					}
795.  					break;
796.  				case 2:
797.  				case 7:	nomul(-rnd(25)); /* sleep ray */
798.  					break;
799.  				case 3:
800.  				case 8:	if(Cold_resistance)
801.  						pline("You don't feel cold!");
802.  					else dam = d(6,6);
803.  					break;
804.  				case 4:
805.  				case 9:	u.uhp = -1;
806.  					break;
807.  				}
808.  				losehp(dam,fltxt);
809.  			} else pline("The %s whizzes by you!",fltxt);
810.  			stop_occupation();
811.  		}
812.  		if(!ZAP_POS(lev->typ)) {
813.  			int bounce = 0, rmn;
814.  			if(cansee(sx,sy)) pline("The %s bounces!",fltxt);
815.  			range--;
816.  			if(!dx || !dy || !rn2(20)){
817.  				dx = -dx;
818.  				dy = -dy;
819.  			} else {
820.  			  if(ZAP_POS(rmn = levl[sx][sy-dy].typ) &&
821.  			    (IS_ROOM(rmn) || ZAP_POS(levl[sx+dx][sy-dy].typ)))
822.  				bounce = 1;
823.  			  if(ZAP_POS(rmn = levl[sx-dx][sy].typ) &&
824.  			    (IS_ROOM(rmn) || ZAP_POS(levl[sx-dx][sy+dy].typ)))
825.  				if(!bounce || rn2(2))
826.  					bounce = 2;
827.  
828.  			  switch(bounce){
829.  			  case 0:
830.  				dy = -dy;
831.  				dx = -dx;
832.  				break;
833.  			  case 1:
834.  				dy = -dy;
835.  				break;
836.  			  case 2:
837.  				dx = -dx;
838.  				break;
839.  			  }
840.  			  Tmp_at(-2, dirlet(dx,dy));
841.  			}
842.  		}
843.  	}
844.  	Tmp_at(-1,-1);
845.  }
846.  
847.  zhit(mon,type)			/* returns damage to mon */
848.  register struct monst *mon;
849.  register type;
850.  {
851.  	register int tmp = 0;
852.  
853.  	switch(type) {
854.  	case 0:			/* magic missile */
855.  	case 5: tmp = d(2,6);
856.  		break;
857.  	case -1:		/* Dragon blazing fire */
858.  	case 1:			/* fire wand*/
859.  	case 6:			/* fire spell */
860.  	case 10:		/* Polymorphed human blazing fire */
861.  		if(index("Dg", mon->data->mlet)) break;
862.  		tmp = d(6,6);
863.  		if(index("YF", mon->data->mlet)) tmp += 7;
864.  		break;
865.  	case 2:			/* sleep*/
866.  	case 7: tmp = 0;
867.  		if(!resist(mon, (type == 2) ? '/' : '+', 0, NOTELL))
868.  			mon->mfroz = 1;
869.  		break;
870.  	case 3:			/* cold */
871.  	case 8:
872.  		if(index("YFgf", mon->data->mlet)) break;
873.  		tmp = d(6,6);
874.  		if(mon->data->mlet == 'D') tmp += 7;
875.  		break;
876.  	case 4:			/* death*/
877.  	case 9:
878.  		if(index(UNDEAD, mon->data->mlet)) break;
879.  		tmp = mon->mhp+1;
880.  		break;
881.  	}
882.  	if (resist(mon, (type < 5) ? '/' : '+', 0, NOTELL)) tmp /= 2;
883.  	mon->mhp -= tmp;
884.  	return(tmp);
885.  }
886.  
887.  #define	CORPSE_I_TO_C(otyp)	(char) ((otyp >= DEAD_ACID_BLOB)\
888.  		     ?  'a' + (otyp - DEAD_ACID_BLOB)\
889.  		     :	'@' + (otyp - DEAD_HUMAN))
890.  revive(obj)
891.  register struct obj *obj;
892.  {
893.  	register struct monst *mtmp;
894.  	register int let;
895.  
896.  	if(obj->olet == FOOD_SYM && obj->otyp > CORPSE) {
897.  #ifdef KAA
898.  		switch (obj->otyp) {
899.  			case DEAD_HUMAN: { let = 'Z'; break; }
900.  			case DEAD_GIANT: { let = '9'; break; }
901.  			case DEAD_DEMON: { let = '&'; break; }
902.  			default: let = CORPSE_I_TO_C(obj->otyp);
903.  		}
904.  		delobj(obj);
905.  /* Originally there was a bug which caused the object not to be erased
906.     from the screen.  This happened because first the monster got created,
907.     then the corpse removed.  Although delobj() called unpobj(), the object
908.     didn't get erased from the screen because the monster was sitting on top
909.     of it.  Solution: place the delobj() call before the mkmon() call. */
910.  		mtmp = mkmon_at(let, obj->ox, obj->oy);
911.  		if (mtmp && obj->otyp == DEAD_HUMAN) {
912.  			mtmp->mhp = mtmp->mhpmax = 100;
913.  			mtmp->mspeed = MFAST;
914.  		}
915.  #endif
916.  		/* do not (yet) revive shopkeepers */
917.  		/* Note: this might conceivably produce two monsters
918.  			at the same position - strange, but harmless */
919.  #ifndef KAA
920.  		delobj(obj);
921.  		mtmp = mkmon_at(CORPSE_I_TO_C(obj->otyp),obj->ox,obj->oy);
922.  #endif
923.  	}
924.  	return(!!mtmp);		/* TRUE if some monster created */
925.  }
926.  
927.  rloco(obj)
928.  register struct obj *obj;
929.  {
930.  	register tx,ty,otx,oty;
931.  
932.  	otx = obj->ox;
933.  	oty = obj->oy;
934.  	do {
935.  		tx = rn1(COLNO-3,2);
936.  		ty = rn2(ROWNO);
937.  	} while(!goodpos(tx,ty));
938.  	obj->ox = tx;
939.  	obj->oy = ty;
940.  	if(cansee(otx,oty))
941.  		newsym(otx,oty);
942.  }
943.  
944.  fracture_rock(obj)	/* fractured by pick-axe or wand of striking */
945.  register struct obj *obj;			   /* no texts here! */
946.  {
947.  	/* unpobj(obj); */
948.  	obj->otyp = ROCK;
949.  	obj->quan = 7 + rn2(60);
950.  	obj->owt = weight(obj);
951.  	obj->olet = WEAPON_SYM;
952.  	if(cansee(obj->ox,obj->oy))
953.  		prl(obj->ox,obj->oy);
954.  }
955.  
956.  boil_potions()
957.  {
958.  	register struct obj *obj, *obj2;
959.  	register int scrquan, i;
960.  	
961.  	for(obj = invent; obj; obj = obj2) {
962.  		obj2 = obj->nobj;
963.  		if(obj->olet == POTION_SYM) {
964.  			scrquan = obj->quan;
965.  			for(i = 1; i <= scrquan; i++) 
966.  				if(!rn2(3)) {
967.  					pline("%s %s boils and explodes!",
968.  					(obj->quan != 1) ? "One of your" : "Your",
969.  					xname(obj));
970.  					potionbreathe(obj);
971.  					useup(obj);
972.  					losehp(rn2(4),"boiling potion");
973.  				}
974.  		}
975.  	}
976.  }
977.  				
978.  burn_scrolls()
979.  {
980.  	register struct obj *obj, *obj2;
981.  	register int cnt = 0;
982.  	register int scrquan, i;
983.  
984.  	for(obj = invent; obj; obj = obj2) {
985.  		obj2 = obj->nobj;
986.  		if(obj->olet == SCROLL_SYM) {
987.  			scrquan = obj->quan;
988.  			for(i = 1; i <= scrquan ; i++)
989.  				if(!rn2(3))  {
990.  					cnt++;
991.  					useup(obj);
992.  				}
993.  		}
994.  	}
995.  
996.  	/* "Killed by a burning scrolls" doesn't make too much sense.  KAA*/
997.  	if (cnt) {
998.  		pline("%s of your scrolls catch%s fire!",
999.  		cnt==1 ? "One" : "Some", cnt==1 ? "es" : "");
1000. 		if(Fire_resistance)
1001. 			pline("You aren't hurt!");
1002. 		else
1003. 			losehp(cnt,"burning scroll");
1004. 	}
1005. }
1006. 
1007. resist(mtmp, olet, damage, tell)
1008. register struct monst	*mtmp;
1009. register char	olet;
1010. register int	damage, tell;
1011. {
1012. register int	resisted = 0;
1013. #ifdef HARD
1014. register int	level;
1015. 
1016. 	switch(olet)  {
1017. 
1018. 	    case '/':	level = 8;
1019. 			break;
1020. 
1021. 	    case '?':	level = 6;
1022. 			break;
1023. 
1024. 	    case '!':	level = 5;
1025. 			break;
1026. 
1027. 	    default:	level = u.ulevel;
1028. 			break;
1029. 	}
1030. 
1031. 	resisted = (rn2(100) - mtmp->data->mlevel + level) < mtmp->data->mr;
1032. 	if(resisted) {
1033. 
1034. 		if(tell) pline("The %s resists!", mtmp->data->mname);
1035. 		mtmp->mhp -= damage/2;
1036. 	} else
1037. #endif
1038. 		mtmp->mhp -= damage;
1039. 
1040. 	if(mtmp->mhp < 1) killed(mtmp);
1041. 	return(resisted);
1042. }
1043. 
1044. /*
1045.  * burn scrolls on floor at position x,y
1046.  * return the number of scrolls burned
1047.  */
1048. int
1049. burn_floor_scrolls(x,y)
1050. {
1051. 	register struct obj *obj, *obj2;
1052. 	register int scrquan, i;
1053. 	register int cnt = 0;
1054. 
1055. 	for(obj = fobj; obj; obj = obj2) {
1056. 		obj2 = obj->nobj;
1057. 		/* Bug fix - KAA */
1058. 		if(obj->ox == x && obj->oy == y && obj->olet == SCROLL_SYM) {
1059. 			scrquan = obj->quan;
1060. 			for(i = 1; i <= scrquan ; i++)
1061. 				if(!rn2(3))  {
1062. 					cnt++;
1063. 					useupf(obj);
1064. 				}
1065. 		}
1066. 	}
1067. 	return(cnt);
1068. }
1069. 
1070. makewish()	/* Separated as there are now 3 places you can wish at. */
1071. {
1072. 	char buf[BUFSZ];
1073. 	register struct obj *otmp;
1074. 	extern struct obj *readobjnam(), *addinv();
1075. 	int wishquan, mergquan;
1076. 
1077. 	pline("You may wish for an object. What do you want? ");
1078. 	getlin(buf);
1079. 	if(buf[0] == '\033') buf[0] = 0;
1080. 	otmp = readobjnam(buf);
1081. #ifdef KAA
1082. /* Wishing for gold has been implemented in readobjnam() and returns 0
1083.    if successful. */
1084. 	if (otmp) { 
1085. #endif
1086. 		wishquan = otmp->quan;
1087. 		otmp = addinv(otmp);
1088. 		/* indented lines added below so quantity shows
1089. 		 *  right.     GAN - 11/13/86
1090. 		 */
1091. 		  mergquan = otmp->quan;
1092. 		  otmp->quan = wishquan; /* to fool prinv() */
1093. 		prinv(otmp);
1094. 		  otmp->quan = mergquan;
1095. #ifdef KAA
1096. 	}
1097. #endif
1098. }
Advertisement