Wikia

Wikihack

Source:NetHack 2.3e/zap.c

2,032pages on
this wiki
Talk0

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

Around Wikia's network

Random Wiki