home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / nethack / part03 / zap.c < prev   
C/C++ Source or Header  |  1987-07-28  |  24KB  |  1,042 lines

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