1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.zap.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.zap.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.zap.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ */
8 extern struct obj *mkobj_at();
9 extern struct monst *makemon(), *mkmon_at(), youmonst;
21 /* Routines for IMMEDIATE wands. */
22 /* bhitm: monster mtmp was hit by the effect of wand otmp */
30 if(u.uswallow || rnd(20) < 10+mtmp->data->ac) {
32 hit("wand", mtmp, exclam(tmp));
34 if(mtmp->mhp < 1) killed(mtmp);
35 } else miss("wand", mtmp);
37 case WAN_SLOW_MONSTER:
40 case WAN_SPEED_MONSTER:
43 case WAN_UNDEAD_TURNING:
44 if(index(UNDEAD,mtmp->data->mlet)) {
46 if(mtmp->mhp < 1) killed(mtmp);
51 if( newcham(mtmp,&mons[rn2(CMNUM)]) )
52 objects[otmp->otyp].oc_name_known = 1;
54 case WAN_CANCELLATION:
57 case WAN_TELEPORTATION:
60 case WAN_MAKE_INVISIBLE:
69 impossible("What an interesting wand (%u)", otmp->otyp);
73 bhito(obj, otmp) /* object obj was hit by the effect of wand otmp */
74 struct obj *obj, *otmp; /* returns TRUE if sth was done */
78 if(obj == uball || obj == uchain)
83 /* preserve symbol and quantity, but turn rocks into gems */
84 mkobj_at((obj->otyp == ROCK || obj->otyp == ENORMOUS_ROCK)
85 ? GEM_SYM : obj->olet,
86 obj->ox, obj->oy) -> quan = obj->quan;
90 if(obj->otyp == ENORMOUS_ROCK)
95 case WAN_CANCELLATION:
96 if(obj->spe && obj->olet != AMULET_SYM) {
101 case WAN_TELEPORTATION:
104 case WAN_MAKE_INVISIBLE:
107 case WAN_UNDEAD_TURNING:
110 case WAN_SLOW_MONSTER: /* no effect on objects */
111 case WAN_SPEED_MONSTER:
118 impossible("What an interesting wand (%u)", otmp->otyp);
128 obj = getobj("/", "zap");
130 if(obj->spe < 0 || (obj->spe == 0 && rn2(121))) {
131 pline("Nothing Happens.");
135 pline("You wrest one more spell from the worn-out wand.");
136 if(!(objects[obj->otyp].bits & NODIR) && !getdir(1))
137 return(1); /* make him pay for knowing !NODIR */
139 if(objects[obj->otyp].bits & IMMEDIATE) {
141 bhitm(u.ustuck, obj);
144 struct obj *otmp = o_at(u.ux, u.uy);
146 (void) bhito(otmp, obj);
149 (void) bhit(u.dx,u.dy,rn1(8,6),0,bhitm,bhito,obj);
155 case WAN_SECRET_DOOR_DETECTION:
156 if(!findit()) return(1);
158 case WAN_CREATE_MONSTER:
160 if(!rn2(23)) cnt += rn2(7) + 1;
162 (void) makemon((struct permonst *) 0, u.ux, u.uy);
168 extern struct obj *readobjnam(), *addinv();
169 if(u.uluck + rn2(5) < 0) {
170 pline("Unfortunately, nothing happens.");
173 pline("You may wish for an object. What do you want? ");
175 if(buf[0] == '\033') buf[0] = 0;
176 otmp = readobjnam(buf);
182 /* Original effect (approximately):
183 * from CORR: dig until we pierce a wall
184 * from ROOM: piece wall and dig until we reach
185 * an ACCESSIBLE place.
186 * Currently: dig for digdepth positions;
187 * also down on request of Lennart Augustsson.
192 struct monst *mtmp = u.ustuck;
194 pline("You pierce %s's stomach wall!",
196 mtmp->mhp = 1; /* almost dead */
203 pline("You loosen a rock from the ceiling.");
204 pline("It falls on your head!");
205 losehp(1, "falling rock");
206 mksobj_at(ROCK, u.ux, u.uy);
209 if(Invisible) newsym(u.ux, u.uy);
217 digdepth = 8 + rn2(18);
218 Tmp_at(-1, '*'); /* open call */
219 while(--digdepth >= 0) {
220 if(!isok(zx,zy)) break;
221 room = &levl[zx][zy];
224 if(zx < 3 || zx > COLNO-3 ||
225 zy < 3 || zy > ROWNO-3)
227 if(room->typ == HWALL ||
233 if(room->typ == HWALL || room->typ == VWALL ||
234 room->typ == SDOOR || room->typ == LDOOR){
238 if(room->typ == SCORR || !room->typ) {
246 mnewsym(zx,zy); /* not always necessary */
247 Tmp_at(-1,-1); /* closing call */
251 buzz((int) obj->otyp - WAN_MAGIC_MISSILE,
252 u.ux, u.uy, u.dx, u.dy);
255 if(!objects[obj->otyp].oc_name_known) {
256 objects[obj->otyp].oc_name_known = 1;
257 more_experienced(0,10);
267 /* force == 0 occurs e.g. with sleep ray */
268 /* note that large force is usual with wands so that !! would
269 require information about hand/weapon/wand */
270 return( (force < 0) ? "?" : (force <= 4) ? "." : "!" );
276 char *force; /* usually either "." or "!" */
278 if(!cansee(mtmp->mx,mtmp->my)) pline("The %s hits it.", str);
279 else pline("The %s hits %s%s", str, monnam(mtmp), force);
286 if(!cansee(mtmp->mx,mtmp->my)) pline("The %s misses it.",str);
287 else pline("The %s misses %s.",str,monnam(mtmp));
290 /* bhit: called when a weapon is thrown (sym = obj->olet) or when an
291 IMMEDIATE wand is zapped (sym = 0); the weapon falls down at end of
292 range or when a monster is hit; the monster is returned, and bhitpos
293 is set to the final position of the weapon thrown; the ray of a wand
294 may affect several objects and monsters on its path - for each of
295 these an argument function is called. */
296 /* check !u.uswallow before calling bhit() */
299 bhit(ddx,ddy,range,sym,fhitm,fhito,obj)
300 int ddx,ddy,range; /* direction and range */
301 char sym; /* symbol displayed on path */
302 int (*fhitm)(), (*fhito)(); /* fns called when mon/obj hit */
303 struct obj *obj; /* 2nd arg to fhitm/fhito */
312 if(sym) tmp_at(-1, sym); /* open call */
316 typ = levl[bhitpos.x][bhitpos.y].typ;
317 if(mtmp = m_at(bhitpos.x,bhitpos.y)){
319 tmp_at(-1, -1); /* close call */
325 if(fhito && (otmp = o_at(bhitpos.x,bhitpos.y))){
326 if((*fhito)(otmp, obj))
334 if(sym) tmp_at(bhitpos.x, bhitpos.y);
337 /* leave last symbol unless in a pool */
339 tmp_at(-1, (levl[bhitpos.x][bhitpos.y].typ == POOL) ? -1 : 0);
348 extern schar xdir[], ydir[];
353 for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break;
354 tmp_at(-1, sym); /* open call */
355 for(ct=0; ct<10; ct++) {
357 sym = ')' + '(' - sym;
358 tmp_at(-2, sym); /* change let call */
363 if(mtmp = m_at(bhitpos.x, bhitpos.y)){
367 if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
372 if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
373 if(rn2(20) >= 10+u.ulevel){ /* we hit ourselves */
374 (void) thitu(10, rnd(10), "boomerang");
376 } else { /* we catch it */
378 pline("Skillfully, you catch the boomerang.");
382 tmp_at(bhitpos.x, bhitpos.y);
385 tmp_at(-1, -1); /* do not leave last symbol */
390 dirlet(dx,dy) int dx,dy; {
392 (dx == dy) ? '\\' : (dx && dy) ? '/' : dx ? '-' : '|';
395 /* type == -1: monster spitting fire at you */
396 /* type == -1,-2,-3: bolts sent out by wizard */
397 /* called with dx = dy = 0 with vertical bolts */
398 buzz(type,sx,sy,dx,dy)
403 int abstype = abs(type);
404 char *fltxt = (type == -1) ? "blaze of fire" : fl[abstype];
413 tmp = zhit(u.ustuck, type);
414 pline("The %s rips into %s%s",
415 fltxt, monnam(u.ustuck), exclam(tmp));
420 Tmp_at(-1, dirlet(dx,dy)); /* open call */
424 if((lev = &levl[sx][sy])->typ) Tmp_at(sx,sy);
427 if(cansee(sx-dx,sy-dy))
428 pline("The %s bounces!", fltxt);
429 if(ZAP_POS(levl[sx][sy-dy].typ))
431 if(ZAP_POS(levl[sx-dx][sy].typ)) {
432 if(!bounce || rn2(2)) bounce = 2;
448 Tmp_at(-2,dirlet(dx,dy));
451 if(lev->typ == POOL && abstype == 1 /* fire */) {
456 pline("The water evaporates.");
458 pline("You hear a hissing sound.");
460 if((mon = m_at(sx,sy)) &&
461 (type != -1 || mon->data->mlet != 'D')) {
463 if(rnd(20) < 18 + mon->data->ac) {
464 int tmp = zhit(mon,abstype);
467 if(cansee(mon->mx,mon->my))
468 pline("%s is killed by the %s!",
474 hit(fltxt, mon, exclam(tmp));
478 } else if(sx == u.ux && sy == u.uy) {
480 if(rnd(20) < 18+u.uac) {
483 pline("The %s hits you!",fltxt);
490 pline("You don't feel hot!");
496 nomul(-rnd(25)); /* sleep ray */
500 pline("You don't feel cold!");
507 } else pline("The %s whizzes by you!",fltxt);
510 if(!ZAP_POS(lev->typ)) {
512 if(cansee(sx,sy)) pline("The %s bounces!",fltxt);
514 if(!dx || !dy || !rn2(20)){
518 if(ZAP_POS(rmn = levl[sx][sy-dy].typ) &&
519 (IS_ROOM(rmn) || ZAP_POS(levl[sx+dx][sy-dy].typ)))
521 if(ZAP_POS(rmn = levl[sx-dx][sy].typ) &&
522 (IS_ROOM(rmn) || ZAP_POS(levl[sx-dx][sy+dy].typ)))
523 if(!bounce || rn2(2))
538 Tmp_at(-2, dirlet(dx,dy));
545 zhit(mon,type) /* returns damage to mon */
552 case 0: /* magic missile */
555 case -1: /* Dragon blazing fire */
557 if(index("Dg", mon->data->mlet)) break;
559 if(index("YF", mon->data->mlet)) tmp += 7;
565 if(index("YFgf", mon->data->mlet)) break;
567 if(mon->data->mlet == 'D') tmp += 7;
570 if(index(UNDEAD, mon->data->mlet)) break;
578 #define CORPSE_I_TO_C(otyp) (char) ((otyp >= DEAD_ACID_BLOB)\
579 ? 'a' + (otyp - DEAD_ACID_BLOB)\
580 : '@' + (otyp - DEAD_HUMAN))
586 if(obj->olet == FOOD_SYM && obj->otyp > CORPSE) {
587 /* do not (yet) revive shopkeepers */
588 /* Note: this might conceivably produce two monsters
589 at the same position - strange, but harmless */
590 mtmp = mkmon_at(CORPSE_I_TO_C(obj->otyp),obj->ox,obj->oy);
593 return(!!mtmp); /* TRUE if some monster created */
606 } while(!goodpos(tx,ty));
613 fracture_rock(obj) /* fractured by pick-axe or wand of striking */
614 struct obj *obj; /* no texts here! */
618 obj->quan = 7 + rn2(60);
619 obj->owt = weight(obj);
620 obj->olet = WEAPON_SYM;
621 if(cansee(obj->ox,obj->oy))
622 prl(obj->ox,obj->oy);
627 struct obj *obj, *obj2;
630 for(obj = invent; obj; obj = obj2) {
632 if(obj->olet == SCROLL_SYM) {
638 pline("Your scrolls catch fire!");
639 losehp(cnt, "burning scrolls");
641 pline("Your scroll catches fire!");
642 losehp(1, "burning scroll");