home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / zap.c < prev   
Encoding:
C/C++ Source or Header  |  1993-08-01  |  66.3 KB  |  2,696 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)zap.c    3.1    93/06/16    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. /* Disintegration rays have special treatment; corpses are never left.
  8.  * But the routine which calculates the damage is separate from the routine
  9.  * which kills the monster.  The damage routine returns this cookie to
  10.  * indicate that the monster should be disintegrated.
  11.  */
  12. #define MAGIC_COOKIE 1000
  13.  
  14. static NEARDATA boolean obj_zapped;
  15. static NEARDATA int poly_zapped;
  16.  
  17. #ifdef MUSE
  18. /* kludge to use mondied instead of killed */
  19. extern boolean m_using;
  20. #endif
  21.  
  22. static boolean FDECL(obj_shudders, (struct obj *));
  23. static void FDECL(polyuse, (struct obj*, int, int));
  24. static void FDECL(do_osshock, (struct obj *));
  25. static void FDECL(create_polymon, (struct obj *));
  26. static int FDECL(burn_floor_paper,(int,int));
  27. static void FDECL(costly_cancel, (struct obj *));
  28. static void FDECL(cancel_item, (struct obj *));
  29. static int FDECL(bhitm, (struct monst *,struct obj *));
  30. #ifndef MUSE
  31. STATIC_PTR int FDECL(bhito, (struct obj *,struct obj *));
  32. #endif
  33. STATIC_PTR int FDECL(bhitpile, (struct obj *,int (*)(OBJ_P,OBJ_P),int,int));
  34. static void FDECL(backfire, (struct obj *));
  35. static int FDECL(zhit, (struct monst *,int,int));
  36.  
  37. #define ZT_MAGIC_MISSILE    (AD_MAGM-1)
  38. #define ZT_FIRE            (AD_FIRE-1)
  39. #define ZT_COLD            (AD_COLD-1)
  40. #define ZT_SLEEP        (AD_SLEE-1)
  41. #define ZT_DEATH        (AD_DISN-1)    /* or disintegration */
  42. #define ZT_LIGHTNING        (AD_ELEC-1)
  43. #define ZT_POISON_GAS        (AD_DRST-1)
  44. #define ZT_ACID            (AD_ACID-1)
  45. /* 8 and 9 are currently unassigned */
  46.  
  47. #define ZT_WAND(x)        (x)
  48. #define ZT_SPELL(x)        (10+(x))
  49. #define ZT_BREATH(x)    (20+(x))
  50.  
  51. const char *flash_types[] = {        /* also used in buzzmu(mcastu.c) */
  52.     "magic missile",    /* Wands must be 0-9 */
  53.     "bolt of fire",
  54.     "bolt of cold",
  55.     "sleep ray",
  56.     "death ray",
  57.     "bolt of lightning",
  58.     "",
  59.     "",
  60.     "",
  61.     "",
  62.  
  63.     "magic missile",    /* Spell equivalents must be 10-19 */
  64.     "fireball",
  65.     "cone of cold",
  66.     "sleep ray",
  67.     "finger of death",
  68.     "bolt of lightning",
  69.     "",
  70.     "",
  71.     "",
  72.     "",
  73.  
  74.     "blast of missiles",    /* Dragon breath equivalents 20-29*/
  75.     "blast of fire",
  76.     "blast of frost",
  77.     "blast of sleep gas",
  78.     "blast of disintegration",
  79.     "blast of lightning",
  80.     "blast of poison gas",
  81.     "blast of acid",
  82.     "",
  83.     ""
  84. };
  85.  
  86.  
  87. /* Routines for IMMEDIATE wands and spells. */
  88. /* bhitm: monster mtmp was hit by the effect of wand or spell otmp */
  89. static int
  90. bhitm(mtmp, otmp)
  91. register struct monst *mtmp;
  92. register struct obj *otmp;
  93. {
  94.     register boolean wake = FALSE;
  95.     register int otyp = otmp->otyp;
  96. #ifdef MULDGN
  97.     boolean dbldam = (pl_character[0] == 'K') && u.uhave.questart;
  98. #endif
  99.     register int dmg;
  100.  
  101.     switch(otyp) {
  102.     case WAN_STRIKING:
  103.     case SPE_FORCE_BOLT:
  104.         wake = TRUE;
  105.         if (u.uswallow || rnd(20) < 10 + find_mac(mtmp)) {
  106.             dmg = d(2,12);
  107. #ifdef MULDGN
  108.             if(dbldam) dmg *= 2;
  109. #endif
  110.             hit((otyp == WAN_STRIKING) ? "wand" : "spell",
  111.                 mtmp, exclam(dmg));
  112.             (void) resist(mtmp, otmp->oclass, dmg, TELL);
  113.         } else miss((otyp == WAN_STRIKING) ? "wand" : "spell", mtmp);
  114.         makeknown(otyp);
  115.         break;
  116.     case WAN_SLOW_MONSTER:
  117.     case SPE_SLOW_MONSTER:
  118.         wake = TRUE;
  119.         if (!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  120.             if (mtmp->mspeed == MFAST) mtmp->mspeed = 0;
  121.             else mtmp->mspeed = MSLOW;
  122.             if (u.uswallow && (mtmp == u.ustuck) &&
  123.                 is_whirly(mtmp->data)) {
  124.                 You("disrupt %s!", mon_nam(mtmp));
  125.                 pline("A huge hole opens up...");
  126.                 expels(mtmp, mtmp->data, TRUE);
  127.             }
  128.         }
  129.         break;
  130.     case WAN_SPEED_MONSTER:
  131.         if (!resist(mtmp, otmp->oclass, 0, NOTELL))
  132.             if (mtmp->mspeed == MSLOW) mtmp->mspeed = 0;
  133.             else mtmp->mspeed = MFAST;
  134.         wake = TRUE;
  135.         break;
  136.     case WAN_UNDEAD_TURNING:
  137.     case SPE_TURN_UNDEAD:
  138.         if (is_undead(mtmp->data)) {
  139.             dmg = rnd(8);
  140. #ifdef MULDGN
  141.             if(dbldam) dmg *= 2;
  142. #endif
  143.             if(!resist(mtmp, otmp->oclass, dmg, NOTELL))
  144.                 mtmp->mflee = TRUE;
  145.             wake = TRUE;
  146.         }
  147.         break;
  148.     case WAN_POLYMORPH:
  149.     case SPE_POLYMORPH:
  150.         wake = TRUE;
  151.         if(!resist(mtmp, otmp->oclass, 0, NOTELL)) {
  152.             if (!rn2(25)) {
  153.             if (canseemon(mtmp)) {
  154.                 pline("%s shudders!", Monnam(mtmp));
  155.                 makeknown(otyp);
  156.             }
  157.             /* no corpse after system shock */
  158.             xkilled(mtmp, 3);
  159.             }
  160.             else if (newcham(mtmp, (struct permonst *)0) )
  161.             if (!Hallucination && (!Blind || sensemon(mtmp)))
  162.                 makeknown(otyp);
  163.         }
  164.         break;
  165.     case WAN_CANCELLATION:
  166.     case SPE_CANCELLATION:
  167.         wake = TRUE;
  168.         cancel_monst(mtmp, otmp, TRUE, TRUE, FALSE);
  169.         break;
  170.     case WAN_TELEPORTATION:
  171.     case SPE_TELEPORT_AWAY:
  172.         if(mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
  173.             pline("%s resists your magic!", Monnam(mtmp));
  174.             wake = TRUE;
  175.             break;
  176.         }
  177.         wake = TRUE;
  178.         if(mtmp->isshk) rloc_shk(mtmp);
  179.         else rloc(mtmp);
  180.         break;
  181.     case WAN_MAKE_INVISIBLE:
  182.         mtmp->minvis = TRUE;
  183.         newsym(mtmp->mx,mtmp->my);    /* make monster disappear */
  184.         if (mtmp->wormno) see_wsegs(mtmp); /* and tail too */
  185.         wake = TRUE;
  186.         break;
  187.     case WAN_NOTHING:
  188.         break;
  189.     case WAN_PROBING:
  190.         makeknown(otyp);
  191.         mstatusline(mtmp);
  192.         break;
  193.     case WAN_OPENING:
  194.         if(u.uswallow && mtmp == u.ustuck) {
  195.             if (is_animal(mtmp->data)) {
  196.                 if (Blind) pline("Its mouth opens!");
  197.                 else pline("%s opens its mouth!", Monnam(mtmp));
  198.             }
  199.             expels(mtmp, mtmp->data, TRUE);
  200.         }
  201.             break;
  202.     case SPE_HEALING:
  203.     case SPE_EXTRA_HEALING:
  204.         mtmp->mhp += (otyp == SPE_HEALING) ? rnd(8) : d(2,8)+2;
  205.         if (mtmp->mhp > mtmp->mhpmax) 
  206.             mtmp->mhp = mtmp->mhpmax;
  207.         if (canseemon(mtmp))
  208.             pline(otyp == SPE_HEALING ? "%s begins to look better." :
  209.               "%s looks much better.", Monnam(mtmp));
  210.         if (mtmp->mtame || mtmp->mpeaceful) {            
  211.             adjalign((pl_character[0] == 'H') ? 1 :
  212.                  sgn(u.ualign.type));
  213.         }
  214.          break;
  215.     case WAN_LOCKING:
  216.     case SPE_KNOCK:
  217.     case SPE_WIZARD_LOCK:
  218.         break;
  219.     default:
  220.         impossible("What an interesting effect (%u)", otyp);
  221.     }
  222.     if(wake) {
  223.         if(mtmp->mhp > 0) {
  224.         wakeup(mtmp);
  225.         m_respond(mtmp);
  226.         if(mtmp->isshk && !*u.ushops) hot_pursuit(mtmp);
  227.         } else if(mtmp->m_ap_type)
  228.         seemimic(mtmp); /* might unblock if mimicing a boulder/door */
  229.     }
  230.     return 0;
  231. }
  232.  
  233. struct monst *
  234. revive(obj,ininv)
  235. register struct obj *obj;
  236. boolean ininv;
  237. {
  238.     register struct monst *mtmp = (struct monst *)0;
  239.  
  240.     if(obj->otyp == CORPSE) {
  241.         int montype = obj->corpsenm;
  242.         int x = ininv ? u.ux : obj->ox;
  243.         int y = ininv ? u.uy : obj->oy;
  244.  
  245.         if (cant_create(&montype)) { /* will make zombie instead */
  246.             mtmp = makemon(&mons[PM_HUMAN_ZOMBIE], x, y);
  247.             if (mtmp) {
  248.                 mtmp->mhp = mtmp->mhpmax = 100;
  249.                 mtmp->mspeed = MFAST;
  250.             }
  251.         } else {
  252.             struct obj *otmp;
  253. #if defined(ARMY) && !defined(MUSE)
  254.             if (is_mercenary(&mons[montype]))
  255.                 montype = PM_UNARMORED_SOLDIER;
  256. #endif
  257.             mtmp = makemon(&mons[montype], x, y);
  258.             if (mtmp) {
  259.                 /* Monster retains its name */
  260.                 if (obj->onamelth)
  261.                     mtmp = christen_monst(mtmp, ONAME(obj));
  262.                 /* No inventory for newly revived monsters */
  263.                 while ((otmp = (mtmp->minvent)) != 0) {
  264.                     mtmp->minvent = otmp->nobj;
  265.                     dealloc_obj(otmp);
  266.                 }
  267.             }
  268.         }
  269.         if (mtmp && obj->oeaten)
  270.             mtmp->mhp = eaten_stat(mtmp->mhp, obj);
  271.         if (ininv) useup(obj);
  272.         else {
  273.             /* not useupf(), which charges */
  274.             if (obj->quan > 1L) obj->quan--;
  275.             else delobj(obj);
  276.         }
  277.         if (x != u.ux || y != u.uy || Invisible)
  278.             newsym(x, y);
  279.     }
  280.     return mtmp;
  281. }
  282.  
  283. static NEARDATA const char charged_objs[] = { WAND_CLASS, WEAPON_CLASS, ARMOR_CLASS, 0 };
  284.  
  285. static void
  286. costly_cancel(obj)
  287. register struct obj *obj;
  288. {
  289.     register struct monst *shkp = (struct monst *)0;
  290.  
  291.     if (carried(obj)) {
  292.         if (obj->unpaid) {
  293.                 shkp = shop_keeper(*in_rooms(u.ux, u.uy, SHOPBASE));
  294.             if (!shkp) return;
  295.             Norep("You cancel an unpaid object, you pay for it!");
  296.             bill_dummy_object(obj);
  297.         }
  298.     } else {
  299.             shkp = shop_keeper(*in_rooms(obj->ox, obj->oy, SHOPBASE));
  300.         if (!shkp || !inhishop(shkp)) return;
  301.         if (!costly_spot(obj->ox, obj->oy)) return;
  302.         if (costly_spot(u.ux, u.uy) && 
  303.                 *in_rooms(u.ux, u.uy, 0) ==
  304.                     *in_rooms(shkp->mx, shkp->my, 0)) {
  305.             Norep("You cancel it, you pay for it!");
  306.             bill_dummy_object(obj);
  307.         } else
  308.             (void) stolen_value(obj, obj->ox, obj->oy, FALSE, FALSE);
  309.     }
  310. }
  311.  
  312. /* cancel obj, possibly carried by you or a monster */
  313. static void
  314. cancel_item(obj)
  315. register struct obj *obj;
  316. {
  317.     boolean    u_ring = (obj == uleft) || (obj == uright);
  318.     register boolean unpaid = (carried(obj) && obj->unpaid);
  319.     register boolean holy = (obj->otyp == POT_WATER && obj->blessed);
  320.  
  321.     switch(obj->otyp) {
  322.         case RIN_GAIN_STRENGTH:
  323.             if ((obj->owornmask & W_RING) && u_ring) {
  324.                 ABON(A_STR) -= obj->spe;
  325.                 flags.botl = 1;
  326.             }
  327.             break;
  328.         case RIN_ADORNMENT:
  329.             if ((obj->owornmask & W_RING) && u_ring) {
  330.                 ABON(A_CHA) -= obj->spe;
  331.                 flags.botl = 1;
  332.             }
  333.             break;
  334.         case RIN_INCREASE_DAMAGE:
  335.             if ((obj->owornmask & W_RING) && u_ring)
  336.                 u.udaminc -= obj->spe;
  337.             break;
  338.         case GAUNTLETS_OF_DEXTERITY:
  339.             if ((obj->owornmask & W_ARMG) && (obj == uarmg)) {
  340.                 ABON(A_DEX) -= obj->spe;
  341.                 flags.botl = 1;
  342.             }
  343.             break;
  344.         case HELM_OF_BRILLIANCE:
  345.             if ((obj->owornmask & W_ARMH) && (obj == uarmh)) {
  346.                 ABON(A_INT) -= obj->spe;
  347.                 ABON(A_WIS) -= obj->spe;
  348.                 flags.botl = 1;
  349.             }
  350.             break;
  351.         /* case RIN_PROTECTION: /* not needed */
  352.     }
  353.     if(obj->spe &&
  354.       !(obj->otyp == WAN_CANCELLATION || /* can't cancel cancellation */
  355.         obj->otyp == TIN || obj->otyp == EGG ||
  356.         obj->otyp == STATUE ||
  357.         obj->otyp == MAGIC_LAMP ||
  358. #ifdef MAIL
  359.         obj->otyp == SCR_MAIL ||
  360. #endif
  361. #ifdef TUTTI_FRUTTI
  362.         obj->otyp == SLIME_MOLD ||
  363. #endif
  364.         obj->otyp == SKELETON_KEY ||
  365.         obj->otyp == LARGE_BOX || obj->otyp == CHEST ||
  366.         obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN ||
  367.         Is_candle(obj) || obj->otyp == CANDELABRUM_OF_INVOCATION)) {
  368.             costly_cancel(obj);
  369.         obj->spe = (obj->oclass == WAND_CLASS) ? -1 : 0;
  370.         if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
  371.         }
  372.     if (obj->oclass == SCROLL_CLASS
  373.         && obj->otyp != SCR_BLANK_PAPER
  374. #ifdef MAIL
  375.         && obj->otyp != SCR_MAIL
  376. #endif
  377.        ) {
  378.         costly_cancel(obj);
  379.         obj->otyp = SCR_BLANK_PAPER;
  380.         if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
  381.         }
  382.     if (obj->oclass == SPBOOK_CLASS &&
  383.                        obj->otyp != SPE_BOOK_OF_THE_DEAD &&
  384.                        obj->otyp != SPE_BLANK_PAPER) {
  385.         costly_cancel(obj);
  386.         obj->otyp = SPE_BLANK_PAPER;
  387.         if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
  388.     }
  389.     if (obj->oclass == POTION_CLASS && obj->otyp != POT_BOOZE) {
  390.         if (obj->otyp==POT_SICKNESS ||
  391.                      obj->otyp==POT_SEE_INVISIBLE) {
  392.                 costly_cancel(obj);
  393.                 obj->otyp = POT_FRUIT_JUICE;
  394.             if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
  395.         } else {
  396.                 if (obj->otyp != POT_FRUIT_JUICE &&
  397.                                  obj->otyp != POT_WATER) {
  398.                 costly_cancel(obj);
  399.                     obj->otyp = POT_WATER;
  400.             if (unpaid) addtobill(obj, TRUE, FALSE, TRUE);
  401.             }
  402.         }
  403.         /* sickness is "biologically contaminated" fruit juice; cancel it
  404.          * and it just becomes fruit juice... whereas see invisible
  405.          * tastes like "enchanted" fruit juice, it similarly cancels.
  406.          */
  407.     }
  408.     if (holy) costly_cancel(obj);
  409.     unbless(obj);
  410.     if (unpaid && holy) addtobill(obj, TRUE, FALSE, TRUE);
  411.     uncurse(obj);
  412. }
  413.  
  414. boolean
  415. obj_resists(obj, ochance, achance)
  416. struct obj *obj;
  417. int ochance, achance;    /* percent chance for ordinary objects, artifacts */
  418. {
  419.     if (obj->otyp == AMULET_OF_YENDOR ||
  420.         obj->otyp == SPE_BOOK_OF_THE_DEAD ||
  421.         obj->otyp == CANDELABRUM_OF_INVOCATION ||
  422.         obj->otyp == BELL_OF_OPENING ||
  423.         (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm]))) {
  424.         return TRUE;
  425.     } else {
  426.         int chance = rn2(100);
  427.  
  428.         return((boolean)(chance < (obj->oartifact ? achance : ochance)));
  429.     }
  430. }
  431.  
  432. static boolean
  433. obj_shudders(obj)
  434. struct obj *obj;
  435. {
  436.     int    zap_odds;
  437.  
  438.     if (obj->oclass == WAND_CLASS)
  439.         zap_odds = 3;    /* half-life = 2 zaps */
  440.     else if (obj->cursed)
  441.         zap_odds = 3;    /* half-life = 2 zaps */
  442.     else if (obj->blessed)
  443.         zap_odds = 12;    /* half-life = 8 zaps */
  444.     else
  445.         zap_odds = 8;    /* half-life = 6 zaps */
  446.  
  447.     /* adjust for "large" quantities of identical things */
  448.     if(obj->quan > 4L) zap_odds /= 2;
  449.  
  450.     return((boolean)(! rn2(zap_odds)));
  451. }
  452.  
  453. /* Use up at least minwt number of things made of material mat.
  454.  * There's also a chance that other stuff will be used up.  Finally,
  455.  * there's a random factor here to keep from always using the stuff
  456.  * at the top of the pile.
  457.  */
  458. static void
  459. polyuse(objhdr, mat, minwt)
  460.     struct obj *objhdr;
  461.     int mat, minwt;
  462. {
  463.     register struct obj *otmp, *otmp2;
  464.  
  465.     for(otmp = objhdr; minwt > 0 && otmp; otmp = otmp2) {
  466.     otmp2 = otmp->nexthere;
  467.     if((objects[otmp->otyp].oc_material == mat) == (rn2(minwt+1) != 0)) {
  468.         /* appropriately add damage to bill */
  469.         if (costly_spot(otmp->ox, otmp->oy))
  470.         if (*u.ushops)
  471.             addtobill(otmp, FALSE, FALSE, FALSE);
  472.         else
  473.             (void)stolen_value(otmp, 
  474.                        otmp->ox, otmp->oy, FALSE, FALSE);
  475.         minwt -= (int)otmp->quan;
  476.         delobj(otmp);
  477.     }
  478.     }
  479. }
  480.  
  481. /*
  482.  * Polymorph some of the stuff in this pile into a monster, preferably
  483.  * a golem of some sort.
  484.  */
  485. static void
  486. create_polymon(obj)
  487.     struct obj *obj;
  488. {
  489.     struct permonst *mdat = (struct permonst *)0;
  490.     struct monst *mtmp;
  491.     const char *material;
  492.     int pm_index;
  493.  
  494.     /* no golems if you zap only one object -- not enough stuff */
  495.     if(!obj || (!obj->nexthere && obj->quan == 1L)) return;
  496.  
  497.     /* some of these choices are arbitrary */
  498.     switch(poly_zapped) {
  499.     case IRON:
  500.     case METAL:
  501.     case MITHRIL:
  502.         pm_index = PM_IRON_GOLEM;
  503.         material = "metal ";
  504.         break;
  505.     case COPPER:
  506.     case SILVER:
  507.     case GOLD:
  508.     case PLATINUM:
  509.     case GEMSTONE:
  510.     case GLASS:
  511.     case MINERAL:
  512.         pm_index = rn2(2) ? PM_STONE_GOLEM : PM_CLAY_GOLEM;
  513.         material = "lithic ";
  514.         break;
  515.     case 0:
  516.         /* there is no flesh type, but all food is type 0, so we use it */
  517.         pm_index = PM_FLESH_GOLEM;
  518.         material = "organic ";
  519.         break;
  520.     case WOOD:
  521.         pm_index = PM_WOOD_GOLEM;
  522.         material = "wood ";
  523.         break;
  524.     case LEATHER:
  525.         pm_index = PM_LEATHER_GOLEM;
  526.         material = "leather ";
  527.         break;
  528.     case CLOTH:
  529.         pm_index = PM_ROPE_GOLEM;
  530.         material = "cloth ";
  531.         break;
  532.     default:
  533.         /* if all else fails... */
  534.         pm_index = PM_STRAW_GOLEM;
  535.         material = "";
  536.         break;
  537.     }
  538.  
  539.     if (! (mons[pm_index].geno & G_GENOD))
  540.         mdat = &mons[pm_index];
  541.  
  542.     mtmp = makemon(mdat, obj->ox, obj->oy);
  543.     polyuse(obj, poly_zapped, (int)mons[pm_index].cwt);
  544.  
  545.     if(!Blind && mtmp) {
  546.         pline("Some %sobjects meld, and %s arises from the pile!",
  547.           material, a_monnam(mtmp));
  548.     }
  549. }
  550.  
  551. static void
  552. do_osshock(obj)
  553. struct obj *obj;
  554. {
  555.     long i;
  556.     obj_zapped = TRUE;
  557.  
  558.     if(poly_zapped < 0) {
  559.         /* some may metamorphosize */
  560.         for(i=obj->quan; i; i--)
  561.         if (! rn2(Luck + 45)) {
  562.             poly_zapped = objects[obj->otyp].oc_material;
  563.             break;
  564.         }
  565.     }
  566.  
  567.     /* if quan > 1 then some will survive intact */
  568.     if (obj->quan > 1L) {
  569.         struct obj *obj2;
  570.  
  571.         obj2 = splitobj(obj, (long)rnd((int)obj->quan - 1));
  572.         move_object(obj2, obj->ox, obj->oy);
  573.     }
  574.  
  575.     /* appropriately add damage to bill */
  576.     if (costly_spot(obj->ox, obj->oy))
  577.         if (*u.ushops)
  578.             addtobill(obj, FALSE, FALSE, FALSE);
  579.         else
  580.             (void)stolen_value(obj, 
  581.                        obj->ox, obj->oy, FALSE, FALSE);
  582.  
  583.     /* zap the object */
  584.     delobj(obj);
  585. }
  586.  
  587. #ifndef MUSE
  588. STATIC_PTR
  589. #endif
  590. int
  591. bhito(obj, otmp)    /* object obj was hit by the effect of wand otmp */
  592. register struct obj *obj, *otmp;    /* returns TRUE if sth was done */
  593. {
  594.     register int res = 1;
  595.     struct obj *otmp2;
  596.  
  597.     if (obj == uball) {
  598.         res = 0;
  599.     } else if (obj == uchain) {
  600.         if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) {
  601.             unpunish();
  602.             res = 1;
  603.             makeknown(otmp->otyp);
  604.         } else
  605.             res = 0;
  606.     } else
  607.     switch(otmp->otyp) {
  608.     case WAN_POLYMORPH:
  609.     case SPE_POLYMORPH:
  610.         if (obj_resists(obj, 5, 95)) {
  611.             res = 0;
  612.             break;
  613.         } else if (obj_shudders(obj)) {
  614.             if (cansee(obj->ox, obj->oy))
  615.             makeknown(otmp->otyp);
  616.             do_osshock(obj);
  617.             break;
  618.         }
  619.  
  620.         /* preserve symbol and quantity */
  621.         otmp2 = mkobj_at(obj->oclass, obj->ox, obj->oy, FALSE);
  622.         otmp2->quan = obj->quan;
  623.         /* preserve the shopkeepers (lack of) interest */
  624.         otmp2->no_charge = obj->no_charge;
  625. #ifdef MAIL
  626.         /* You can't send yourself 100 mail messages and then
  627.          * polymorph them into useful scrolls
  628.          */
  629.         if (obj->otyp == SCR_MAIL) {
  630.             otmp2->otyp = SCR_MAIL;
  631.             otmp2->spe = 1;
  632.         }
  633. #endif
  634.  
  635.         /* avoid abusing eggs laid by you */
  636.         if (obj->otyp == EGG && obj->spe) {
  637.             otmp2->otyp = EGG;
  638.             otmp2->spe = 1;
  639.             otmp2->corpsenm = random_monster();
  640.             while (!lays_eggs(&mons[otmp2->corpsenm]))
  641.                 otmp2->corpsenm = random_monster();
  642.         }
  643.  
  644.         /* keep special fields (including charges on wands) */
  645.         if (index(charged_objs, otmp2->oclass)) otmp2->spe = obj->spe;
  646.  
  647.         otmp2->cursed = obj->cursed;
  648.         otmp2->blessed = obj->blessed;
  649.         otmp2->oeroded = obj->oeroded;
  650.         otmp2->oerodeproof = obj->oerodeproof;
  651.  
  652.         /* reduce spellbook abuse */
  653.         if (obj->oclass == SPBOOK_CLASS)
  654.             otmp2->spestudied = obj->spestudied + 1;
  655.  
  656.         /* Keep chest/box traps and poisoned ammo if we may */
  657.         if (obj->otrapped && Is_box(otmp2))
  658.             otmp2->otrapped = TRUE;
  659.         if (obj->opoisoned &&
  660.             (otmp2->oclass == WEAPON_CLASS && otmp2->otyp <= SHURIKEN))
  661.             otmp2->opoisoned = TRUE;
  662.  
  663.         if (obj->otyp == CORPSE) {
  664.         /* turn crocodile corpses into shoes */
  665.             if (obj->corpsenm == PM_CROCODILE) {
  666.             otmp2->otyp = LOW_BOOTS;
  667.             otmp2->oclass = ARMOR_CLASS;
  668.             otmp2->spe = 0;
  669.             otmp2->oeroded = 0;
  670.             otmp2->oerodeproof = TRUE;
  671.             otmp2->quan = 1L;
  672.             otmp2->cursed = FALSE;
  673.             }
  674.         }
  675.  
  676.         /* no box contents --KAA */
  677.         if (Has_contents(otmp2))
  678.             delete_contents(otmp2);
  679.  
  680.         /* 'n' merged objects may be fused into 1 object */
  681.         if (otmp2->quan > 1L &&
  682.             (!objects[otmp2->otyp].oc_merge ||
  683.                 otmp2->quan > (long)rn2(1000)))
  684.             otmp2->quan = 1L;
  685.  
  686.         if(otmp2->otyp == MAGIC_LAMP) otmp2->otyp = OIL_LAMP;
  687.  
  688.         while(otmp2->otyp == WAN_WISHING ||
  689.                         otmp2->otyp == WAN_POLYMORPH)
  690.             otmp2->otyp = rnd_class(WAN_LIGHT, WAN_LIGHTNING);
  691.  
  692.         /* update the weight */
  693.         otmp2->owt = weight(otmp2);
  694.  
  695.         if(costly_spot(obj->ox, obj->oy)) {
  696.             register struct monst *shkp =
  697.                   shop_keeper(*in_rooms(obj->ox, obj->oy, SHOPBASE));
  698.  
  699.             if ((!obj->no_charge ||
  700.              (Has_contents(obj) &&
  701.                 (contained_cost(obj, shkp, 0L, FALSE) != 0L)))
  702.                && inhishop(shkp)) {
  703.                 if(shkp->mpeaceful) {
  704.                 if(*u.ushops && *in_rooms(u.ux, u.uy, 0) ==
  705.                         *in_rooms(shkp->mx, shkp->my, 0) &&
  706.                         !costly_spot(u.ux, u.uy))
  707.                 make_angry_shk(shkp, obj->ox, obj->oy);
  708.                 else {
  709.                     pline("%s gets angry!", Monnam(shkp));
  710.                 hot_pursuit(shkp);
  711.                 }
  712.             } else Norep("%s is furious!", Monnam(shkp));
  713.             }
  714.         }
  715.         delobj(obj);
  716.         break;
  717.     case WAN_STRIKING:
  718.     case SPE_FORCE_BOLT:
  719.         if (obj->otyp == BOULDER)
  720.             fracture_rock(obj);
  721.         else if (obj->otyp == STATUE)
  722.             (void) break_statue(obj);
  723.         else {
  724.             (void)breaks(obj, FALSE);
  725.             res = 0;
  726.         }
  727.         makeknown(otmp->otyp);
  728.         break;
  729.     case WAN_DIGGING:
  730.     case SPE_DIG:
  731.         /* vaporize boulders */
  732.         if (obj->otyp == BOULDER) {
  733.             delobj(obj);
  734.             res = 0;
  735.         }
  736.         break;
  737.     case WAN_CANCELLATION:
  738.     case SPE_CANCELLATION:
  739.         cancel_item(obj);
  740. #ifdef TEXTCOLOR
  741.         newsym(obj->ox,obj->oy);    /* might change color */
  742. #endif
  743.         break;
  744.     case WAN_TELEPORTATION:
  745.     case SPE_TELEPORT_AWAY:
  746.         rloco(obj);
  747.         break;
  748.     case WAN_MAKE_INVISIBLE:
  749.         obj->oinvis = TRUE;
  750.         newsym(obj->ox,obj->oy);    /* make object disappear */
  751.         break;
  752.     case WAN_UNDEAD_TURNING:
  753.     case SPE_TURN_UNDEAD:
  754.         res = !!revive(obj,FALSE);
  755.         break;
  756.     case WAN_OPENING:
  757.     case SPE_KNOCK:
  758.     case WAN_LOCKING:
  759.     case SPE_WIZARD_LOCK:
  760.         if(Is_box(obj))
  761.             res = boxlock(obj, otmp);
  762.         else
  763.             res = 0;
  764.         if (res /* && otmp->oclass == WAND_CLASS */)
  765.             makeknown(otmp->otyp);
  766.         break;
  767.     case WAN_SLOW_MONSTER:        /* no effect on objects */
  768.     case SPE_SLOW_MONSTER:
  769.     case WAN_SPEED_MONSTER:
  770.     case WAN_NOTHING:
  771.     case WAN_PROBING:
  772.     case SPE_HEALING:
  773.     case SPE_EXTRA_HEALING:
  774.         res = 0;
  775.         break;
  776.     default:
  777.         impossible("What an interesting effect (%u)", otmp->otyp);
  778.     }
  779.     return(res);
  780. }
  781.  
  782. STATIC_PTR
  783. int
  784. bhitpile(obj,fhito,tx,ty)
  785.     register struct obj *obj;    /* returns nonzero of something was hit */
  786.     int FDECL((*fhito), (OBJ_P, OBJ_P));
  787.     int tx, ty;
  788. {
  789.     int hitanything = 0;
  790.     register struct obj *otmp, *next_obj = (struct obj *)0;
  791.  
  792.     /* modified by GAN to hit all objects */
  793.     /* pre-reverse the polymorph pile,  -dave- 3/90 */
  794.     poly_zapped = -1;
  795.     if(obj->otyp == SPE_POLYMORPH || obj->otyp == WAN_POLYMORPH) {
  796.     otmp = level.objects[tx][ty];
  797.     level.objects[tx][ty] = next_obj;
  798.     while(otmp) {
  799.         next_obj = otmp->nexthere;
  800.         otmp->nexthere = level.objects[tx][ty];
  801.         level.objects[tx][ty] = otmp;
  802.         otmp = next_obj;
  803.     }
  804.     }
  805.     for(otmp = level.objects[tx][ty]; otmp; otmp = next_obj) {
  806.     /* Fix for polymorph bug, Tim Wright */
  807.     next_obj = otmp->nexthere;
  808.     hitanything += (*fhito)(otmp, obj);
  809.     }
  810.     if(poly_zapped >= 0)
  811.     create_polymon(level.objects[tx][ty]);
  812.  
  813.     return hitanything;
  814. }
  815.  
  816. /*
  817.  * zappable - returns 1 if zap is available, 0 otherwise.
  818.  *          it removes a charge from the wand if zappable.
  819.  * added by GAN 11/03/86
  820.  */
  821. int
  822. zappable(wand)
  823. register struct obj *wand;
  824. {
  825.     if(wand->spe < 0 || (wand->spe == 0 && rn2(121)))
  826.         return 0;
  827.     if(wand->spe == 0)
  828.         You("wrest one last charge from the worn-out wand.");
  829.     wand->spe--;
  830.     return 1;
  831. }
  832.  
  833. /*
  834.  * zapnodir - zaps a NODIR wand/spell.
  835.  * added by GAN 11/03/86
  836.  */
  837. void
  838. zapnodir(obj)
  839. register struct obj *obj;
  840. {
  841.     switch(obj->otyp) {
  842.         case WAN_LIGHT:
  843.         case SPE_LIGHT:
  844.             litroom(TRUE,obj);
  845.             break;
  846.         case WAN_SECRET_DOOR_DETECTION:
  847.         case SPE_DETECT_UNSEEN:
  848.             if(!findit()) return;
  849.             break;
  850.         case WAN_CREATE_MONSTER:
  851.             { register int cnt = 1;
  852.             if(!rn2(23)) cnt += rn2(7) + 1;
  853.             while(cnt--)
  854.                 (void) makemon((struct permonst *) 0, u.ux, u.uy);
  855.             }
  856.             break;
  857.         case WAN_WISHING:
  858.             if(Luck + rn2(5) < 0) {
  859.                 pline("Unfortunately, nothing happens.");
  860.                 break;
  861.             }
  862.             makewish();
  863.             break;
  864.     }
  865.     if (!objects[obj->otyp].oc_name_known &&
  866.         (!Blind || obj->otyp == WAN_WISHING)) {
  867.             makeknown(obj->otyp);
  868.             more_experienced(0,10);
  869.     }
  870. }
  871.  
  872. static void
  873. backfire(otmp)
  874.  
  875.     register struct obj * otmp;
  876. {
  877.     pline("%s suddenly explodes!", The(xname(otmp)));
  878.     losehp(d(otmp->spe+2,6), "exploding wand", KILLED_BY_AN);
  879.     useup(otmp);
  880. }
  881.  
  882. static NEARDATA const char zap_syms[] = { WAND_CLASS, 0 };
  883.  
  884. int
  885. dozap()
  886. {
  887.     register struct obj *obj;
  888.     int    damage;
  889.  
  890.     if(check_capacity(NULL)) return(0);
  891.     obj = getobj(zap_syms, "zap");
  892.     if(!obj) return(0);
  893.  
  894.     check_unpaid(obj);
  895.  
  896.     /* zappable addition done by GAN 11/03/86 */
  897.     if(!zappable(obj)) pline(nothing_happens);
  898.     else if(obj->cursed && !rn2(100)) {
  899.         backfire(obj);    /* the wand blows up in your face! */
  900.         exercise(A_STR, FALSE);
  901.         return(1);
  902.     } else if(!(objects[obj->otyp].oc_dir == NODIR) && !getdir(NULL)) {
  903.         if (!Blind)
  904.             pline("%s glows and fades.", The(xname(obj)));
  905.         /* make him pay for knowing !NODIR */
  906.     } else if(!u.dx && !u.dy && !u.dz && !(objects[obj->otyp].oc_dir == NODIR)) {
  907.         if((damage = zapyourself(obj)))
  908.         losehp(damage, self_pronoun("zapped %sself with a wand", "him"),
  909.             NO_KILLER_PREFIX);
  910.     } else {
  911.         weffects(obj);
  912.     }
  913.     if (obj->spe < 0) {
  914.         pline("%s turns to dust.", The(xname(obj)));
  915.         useup(obj);
  916.     }
  917.     return(1);
  918. }
  919.  
  920. int
  921. zapyourself(obj)
  922.     register struct obj    *obj;
  923. {
  924.     int    damage = 0;
  925.  
  926.     switch(obj->otyp) {
  927.         case WAN_STRIKING:
  928.         case SPE_FORCE_BOLT:
  929.             if(Antimagic) {
  930.             shieldeff(u.ux, u.uy);
  931.             pline("Boing!");
  932.             } else {
  933.             You("bash yourself!");
  934.             damage=d(8,6);
  935.             exercise(A_STR, FALSE);
  936.             }
  937.             makeknown(obj->otyp);
  938.             break;
  939.         case WAN_LIGHTNING:
  940.             makeknown(WAN_LIGHTNING);
  941.             if (!Shock_resistance) {
  942.             You("shock yourself!");
  943.             damage = d(12,6);
  944.             exercise(A_CON, FALSE);
  945.             } else {
  946.             shieldeff(u.ux, u.uy);
  947.             You("zap yourself, but seem unharmed.");
  948. #ifdef POLYSELF
  949.             ugolemeffects(AD_ELEC, d(12,6));
  950. #endif
  951.             }
  952.             destroy_item(WAND_CLASS, AD_ELEC);
  953.             destroy_item(RING_CLASS, AD_ELEC);
  954.             if(!Blind) {
  955.                 You("are blinded by the flash!");
  956.                 make_blinded((long)rnd(100),FALSE);
  957.             }
  958.             break;
  959.         case SPE_FIREBALL:
  960.             You("explode a fireball on top of yourself!");
  961.             explode(u.ux, u.uy, 11, d(6,6), WAND_CLASS);
  962.             break;
  963.         case WAN_FIRE:
  964.             makeknown(WAN_FIRE);
  965.         case FIRE_HORN:
  966.             if (Fire_resistance) {
  967.             shieldeff(u.ux, u.uy);
  968.             You("feel rather warm.");
  969. #ifdef POLYSELF
  970.             ugolemeffects(AD_FIRE, d(12,6));
  971. #endif
  972.             } else {
  973.             pline("You've set yourself afire!");
  974.             damage = d(12,6);
  975.             }
  976.             destroy_item(SCROLL_CLASS, AD_FIRE);
  977.             destroy_item(POTION_CLASS, AD_FIRE);
  978.             destroy_item(SPBOOK_CLASS, AD_FIRE);
  979.             break;
  980.         case WAN_COLD:
  981.             makeknown(WAN_COLD);
  982.         case SPE_CONE_OF_COLD:
  983.         case FROST_HORN:
  984.             if (Cold_resistance) {
  985.             shieldeff(u.ux, u.uy);
  986.             You("feel a little chill.");
  987. #ifdef POLYSELF
  988.             ugolemeffects(AD_COLD, d(12,6));
  989. #endif
  990.             } else {
  991.             You("imitate a popsicle!");
  992.             damage = d(12,6);
  993.             }
  994.             destroy_item(POTION_CLASS, AD_COLD);
  995.             break;
  996.         case WAN_MAGIC_MISSILE:
  997.             makeknown(WAN_MAGIC_MISSILE);
  998.         case SPE_MAGIC_MISSILE:
  999.             if(Antimagic) {
  1000.             shieldeff(u.ux, u.uy);
  1001.             pline("The missiles bounce!");
  1002.             } else {
  1003.             damage = d(4,6);
  1004.             pline("Idiot!  You've shot yourself!");
  1005.             }
  1006.             break;
  1007.         case WAN_POLYMORPH:
  1008. #ifdef POLYSELF
  1009.             makeknown(WAN_POLYMORPH);
  1010. #endif
  1011.         case SPE_POLYMORPH:
  1012. #ifdef POLYSELF
  1013.             polyself();
  1014. #else
  1015.             newman();
  1016. #endif
  1017.             break;
  1018.         case WAN_CANCELLATION:
  1019.         case SPE_CANCELLATION:
  1020.             cancel_monst(&youmonst, obj, TRUE, FALSE, TRUE);
  1021.             break;
  1022.         case WAN_MAKE_INVISIBLE: {
  1023.             /* have to test before changing HInvis but must change
  1024.              * HInvis before doing newsym().
  1025.              */
  1026.             int msg = (!Blind && !Invis && !See_invisible);
  1027.  
  1028.             HInvis |= FROMOUTSIDE;
  1029.             if (msg) {
  1030.             makeknown(WAN_MAKE_INVISIBLE);
  1031.             newsym(u.ux, u.uy);
  1032.             pline(Hallucination ?
  1033.              "Far out, man!  You can see right through yourself!" :
  1034.              "Gee!  All of a sudden, you can't see yourself.");
  1035.             }
  1036.             break;
  1037.         }
  1038.         case WAN_SPEED_MONSTER:
  1039.             if (!(Fast & INTRINSIC)) {
  1040.             You("seem to be moving faster.");
  1041.             makeknown(WAN_SPEED_MONSTER);
  1042.             exercise(A_DEX, TRUE);
  1043.             }
  1044.             Fast |= FROMOUTSIDE;
  1045.             break;
  1046.         case WAN_SLEEP:
  1047.             makeknown(WAN_SLEEP);
  1048.         case SPE_SLEEP:
  1049.             if(Sleep_resistance) {
  1050.             shieldeff(u.ux, u.uy);
  1051.             You("don't feel sleepy!");
  1052.             } else {
  1053.             pline("The sleep ray hits you!");
  1054.             nomul(-rn2(50));
  1055.             u.usleep = 1;
  1056.             nomovemsg = "You wake up.";
  1057.             }
  1058.             break;
  1059.         case WAN_SLOW_MONSTER:
  1060.         case SPE_SLOW_MONSTER:
  1061.             if(Fast & (TIMEOUT | INTRINSIC)) {
  1062.             Fast &= ~(TIMEOUT | INTRINSIC);
  1063.             You("seem to be moving slower.");
  1064.             exercise(A_DEX, FALSE);
  1065.             }
  1066.             break;
  1067.         case WAN_TELEPORTATION:
  1068.         case SPE_TELEPORT_AWAY:
  1069.             tele();
  1070.             break;
  1071.         case WAN_DEATH:
  1072.         case SPE_FINGER_OF_DEATH:
  1073. #ifdef POLYSELF
  1074.             if (is_undead(uasmon)) {
  1075.             pline((obj->otyp == WAN_DEATH) ?
  1076.               "The wand shoots an apparently harmless beam at you."
  1077.               : "You seem no deader than before.");
  1078.             break;
  1079.             }
  1080. #endif
  1081.             killer_format = NO_KILLER_PREFIX;
  1082.             killer = self_pronoun("shot %sself with a death ray","him");
  1083.             You("irradiate yourself with pure energy!");
  1084.             You("die.");
  1085.             makeknown(WAN_DEATH);
  1086.             /* They might survive with an amulet of life saving */
  1087.             done(DIED);
  1088.             break;
  1089.         case SPE_TURN_UNDEAD:
  1090.         case WAN_UNDEAD_TURNING:
  1091. #ifdef POLYSELF
  1092.             if (is_undead(uasmon)) {
  1093.             You("feel frightened and %sstunned.",
  1094.                  Stunned ? "even more " : "");
  1095.             make_stunned(HStun + rnd(30), FALSE);
  1096.             }
  1097. #endif
  1098.             break;
  1099.         case SPE_HEALING:
  1100.         case SPE_EXTRA_HEALING:
  1101.             healup(obj->otyp == SPE_HEALING ? rnd(8) : d(2,8)+2,
  1102.                0, FALSE, FALSE);
  1103.             You(obj->otyp == SPE_HEALING ? "begin to feel better." :
  1104.             "feel a fair bit better.");
  1105.             break;
  1106.         case WAN_DIGGING:
  1107.         case SPE_DIG:
  1108.         case SPE_DETECT_UNSEEN:
  1109.         case WAN_NOTHING:
  1110.         case WAN_OPENING:
  1111.         case WAN_LOCKING:
  1112.         case SPE_KNOCK:
  1113.         case SPE_WIZARD_LOCK:
  1114.             break;
  1115.         case WAN_PROBING:
  1116.             makeknown(WAN_PROBING);
  1117.             ustatusline();
  1118.             break;
  1119.         default: impossible("object %d used?",obj->otyp);
  1120.     }
  1121.     return(damage);
  1122. }
  1123.  
  1124. /*
  1125.  * cancel a monster (possibly the hero).  inventory is cancelled only
  1126.  * if the monster is zapping itself directly, since otherwise the
  1127.  * effect is too strong.  currently non-hero monsters do not zap
  1128.  * themselves with cancellation.
  1129.  */
  1130. void
  1131. cancel_monst(mdef, obj, youattack, allow_cancel_kill, self_cancel)
  1132. register struct monst    *mdef;
  1133. register struct obj    *obj;
  1134. boolean            youattack, allow_cancel_kill, self_cancel;
  1135. {
  1136.     boolean    youdefend = (mdef == &youmonst);
  1137.     static const char writing_vanishes[] =
  1138.                 "Some writing vanishes from %s head!";
  1139.     static const char your[] = "your";    /* should be extern */
  1140.  
  1141.     if (youdefend ? (!youattack && Antimagic)
  1142.               : resist(mdef, obj->oclass, 0, NOTELL))
  1143.         return;        /* resisted cancellation */
  1144.  
  1145.     if (self_cancel) {    /* 1st cancel inventory */
  1146.         struct obj *otmp;
  1147.  
  1148.         for (otmp = (youdefend ? invent : mdef->minvent);
  1149.                 otmp; otmp = otmp->nobj)
  1150.         cancel_item(otmp);
  1151.         if (youdefend) {
  1152.         flags.botl = 1;    /* potential AC change */
  1153.         find_ac();
  1154.         }
  1155.     }
  1156.  
  1157.     /* now handle special cases */
  1158.     if (youdefend) {
  1159. #ifdef POLYSELF
  1160.         if (u.mtimedone) {
  1161.         if ((u.umonnum == PM_CLAY_GOLEM) && !Blind)
  1162.             pline(writing_vanishes, your);
  1163.         rehumanize();
  1164.         }
  1165. #endif
  1166.     } else {
  1167.         mdef->mcan = TRUE;
  1168.  
  1169.         if (is_were(mdef->data) && mdef->data->mlet != S_HUMAN)
  1170.         were_change(mdef);
  1171.  
  1172.         if (mdef->data == &mons[PM_CLAY_GOLEM]) {
  1173.         if (canseemon(mdef))
  1174.             pline(writing_vanishes, s_suffix(mon_nam(mdef)));
  1175.  
  1176.         if (allow_cancel_kill) {
  1177.             if (youattack)
  1178.             killed(mdef);
  1179.             else
  1180.             monkilled(mdef, "", AD_SPEL);
  1181.         }
  1182.         }
  1183.     }
  1184. }
  1185.  
  1186. /* called for various wand and spell effects - M. Stephenson */
  1187. void
  1188. weffects(obj)
  1189. register struct    obj    *obj;
  1190. {
  1191.     xchar zx,zy;
  1192.  
  1193.     exercise(A_WIS, TRUE);
  1194.     if(objects[obj->otyp].oc_dir == IMMEDIATE) {
  1195.         obj_zapped = FALSE;
  1196.  
  1197.         if(u.uswallow)    (void)bhitm(u.ustuck, obj);
  1198.         else if(u.dz) {
  1199.         if(u.dz > 0) {
  1200.             if(levl[u.ux][u.uy].typ == DRAWBRIDGE_DOWN &&
  1201.                (obj->otyp == WAN_LOCKING
  1202.                || obj->otyp == SPE_WIZARD_LOCK))
  1203.                 close_drawbridge(u.ux, u.uy);
  1204.             else
  1205.             (void) bhitpile(obj, bhito, u.ux, u.uy);
  1206.         }
  1207.         } else (void) bhit(u.dx,u.dy,rn1(8,6),ZAPPED_WAND,bhitm,bhito,obj);
  1208.  
  1209.         /* give a clue if obj_zapped */
  1210.         if (obj_zapped)
  1211.         You("feel shuddering vibrations.");
  1212.  
  1213.     } else if(objects[obj->otyp].oc_dir == NODIR) {
  1214.         zapnodir(obj);
  1215.     } else {
  1216.         switch(obj->otyp) {
  1217.         case WAN_DIGGING:
  1218.         case SPE_DIG:
  1219.             /* Original effect (approximately):
  1220.              * from CORR: dig until we pierce a wall
  1221.              * from ROOM: piece wall and dig until we reach
  1222.              * an ACCESSIBLE place.
  1223.              * Currently: dig for digdepth positions;
  1224.              * also down on request of Lennart Augustsson.
  1225.              */
  1226.             {   register struct rm *room;
  1227.             register int digdepth; 
  1228.             register boolean shopdoor, shopwall;
  1229.  
  1230.             shopdoor = shopwall = FALSE;
  1231.             if(u.uswallow) {
  1232.                 register struct monst *mtmp = u.ustuck;
  1233.  
  1234.                 if (!is_whirly(mtmp->data)) {
  1235.                     if (is_animal(mtmp->data))
  1236.                         You("pierce %s stomach wall!",
  1237.                                s_suffix(mon_nam(mtmp)));
  1238.                     mtmp->mhp = 1;    /* almost dead */
  1239.                     expels(mtmp, mtmp->data,
  1240.                            !is_animal(mtmp->data));
  1241.                 }
  1242.                 break;
  1243.             }
  1244.             if(u.dz) {
  1245.                 if(!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) &&
  1246.                    !Underwater) {
  1247.                 if(u.dz < 0 || On_stairs(u.ux, u.uy)) {
  1248.                     if(On_stairs(u.ux, u.uy))
  1249.                     pline(
  1250.             "The beam bounces off the %s and hits the ceiling.",
  1251.                           (u.ux == xdnladder ||
  1252.                            u.ux == xupladder) ?
  1253.                           "ladder" : "stairs");
  1254.                     You("loosen a rock from the ceiling.");
  1255.                     pline("It falls on your %s!",
  1256.                       body_part(HEAD));
  1257.                     losehp(1, "falling rock", KILLED_BY_AN);
  1258.                     (void) mksobj_at((int)ROCK, u.ux, u.uy, FALSE);
  1259.                     stackobj(fobj);
  1260.                     if(Invisible) newsym(u.ux, u.uy);
  1261.                 } else {
  1262.                     (void) dighole(FALSE);
  1263.                 }
  1264.                 }
  1265.                 break;
  1266.             }
  1267.             zx = u.ux+u.dx;
  1268.             zy = u.uy+u.dy;
  1269.             digdepth = 8 + rn2(18);
  1270.             tmp_at(DISP_BEAM, cmap_to_glyph(S_digbeam));
  1271.             while(--digdepth >= 0) {
  1272.                 if(!isok(zx,zy)) break;
  1273.                 room = &levl[zx][zy];
  1274.                 tmp_at(zx,zy);
  1275.                 delay_output();    /* wait a little bit */
  1276.                 if(level.flags.is_maze_lev &&
  1277.                                 !Is_earthlevel(&u.uz)) {
  1278.                 if(IS_WALL(room->typ)) {
  1279.                     if(!(room->diggable & W_NONDIGGABLE)) {
  1280.                     if(*in_rooms(zx,zy,SHOPBASE)) { 
  1281.                         add_damage(zx, zy, 200L);
  1282.                         shopwall = TRUE;
  1283.                     }
  1284.                     room->typ = ROOM;
  1285.                     unblock_point(zx,zy); /* vision */
  1286.                     } else if(!Blind)
  1287.                     pline("The wall glows then fades.");
  1288.                     break;
  1289.                 }
  1290.                 if(room->typ == STONE) {
  1291.                     if(!(room->diggable & W_NONDIGGABLE)) {
  1292.                     room->typ = CORR;
  1293.                     unblock_point(zx,zy); /* vision */
  1294.                     }else if (!Blind && !Is_airlevel(&u.uz))
  1295.                     pline("The rock glows then fades.");
  1296.                     break;
  1297.                 }
  1298.                 } else if(IS_ROCK(room->typ)) {
  1299.                 if(may_dig(zx,zy)) {
  1300.                     if(IS_WALL(room->typ) ||
  1301.                        room->typ == SDOOR) {
  1302.                     if(*in_rooms(zx,zy,SHOPBASE)) {
  1303.                         add_damage(zx, zy, 200L);
  1304.                         shopwall = TRUE;
  1305.                     }
  1306.                     if (level.flags.is_cavernous_lev) {
  1307.                         room->typ = CORR;
  1308.                     } else {
  1309.                         room->typ = DOOR;
  1310.                         room->doormask = D_NODOOR;
  1311.                     }
  1312.                     digdepth -= 2;
  1313.                     } else {
  1314.                     room->typ = CORR;
  1315.                     digdepth--;
  1316.                     }
  1317.                     unblock_point(zx,zy); /* vision */
  1318.                 } else
  1319.                     break;
  1320.                 } else if(closed_door(zx, zy)) {
  1321.                 if(*in_rooms(zx,zy,SHOPBASE)) {
  1322.                     shopdoor = TRUE;
  1323.                     add_damage(zx, zy, 400L);
  1324.                 }
  1325.                 room->doormask = D_NODOOR;
  1326.                 unblock_point(zx,zy); /* vision */
  1327.                 digdepth -= 2;
  1328.                 }
  1329.                 zx += u.dx;
  1330.                 zy += u.dy;
  1331.             } /* while */
  1332.             tmp_at(DISP_END,0);    /* closing call */
  1333.             if(shopdoor || shopwall)
  1334.                 pay_for_damage(shopdoor? "destroy" : "dig into");
  1335.             break;
  1336.             }
  1337.         default:
  1338.             if((int) obj->otyp >= SPE_MAGIC_MISSILE &&
  1339.                 (int) obj->otyp <= SPE_FINGER_OF_DEATH) {
  1340.  
  1341.                 buzz((int) obj->otyp - SPE_MAGIC_MISSILE + 10,
  1342.                  (int)u.ulevel / 2 + 1, u.ux, u.uy, u.dx, u.dy);
  1343.  
  1344.             } else if((int) obj->otyp >= WAN_MAGIC_MISSILE &&
  1345.                     (int) obj->otyp <= WAN_LIGHTNING) {
  1346.  
  1347.                 buzz((int) obj->otyp - WAN_MAGIC_MISSILE,
  1348.                 (obj->otyp == WAN_MAGIC_MISSILE) ? 2 : 6,
  1349.                  u.ux, u.uy, u.dx, u.dy);
  1350.             } else
  1351.                 impossible("weffects: unexpected spell or wand");
  1352.             break;
  1353.         }
  1354.         if(!objects[obj->otyp].oc_name_known) {
  1355.             makeknown(obj->otyp);
  1356.             more_experienced(0,10);
  1357.         }
  1358.     }
  1359.     return;
  1360. }
  1361.  
  1362. const char *
  1363. exclam(force)
  1364. register int force;
  1365. {
  1366.     /* force == 0 occurs e.g. with sleep ray */
  1367.     /* note that large force is usual with wands so that !! would
  1368.         require information about hand/weapon/wand */
  1369.     return (const char *)((force < 0) ? "?" : (force <= 4) ? "." : "!");
  1370. }
  1371.  
  1372. void
  1373. hit(str,mtmp,force)
  1374. register const char *str;
  1375. register struct monst *mtmp;
  1376. register const char *force;        /* usually either "." or "!" */
  1377. {
  1378.     if(!cansee(bhitpos.x,bhitpos.y) || !flags.verbose)
  1379.         pline("%s hits it.", The(str));
  1380.     else pline("%s hits %s%s", The(str), mon_nam(mtmp), force);
  1381. }
  1382.  
  1383. void
  1384. miss(str,mtmp)
  1385. register const char *str;
  1386. register struct monst *mtmp;
  1387. {
  1388.     pline("%s misses %s.", The(str),
  1389.           (cansee(bhitpos.x,bhitpos.y) && flags.verbose) ?
  1390.           mon_nam(mtmp) : "it");
  1391. }
  1392.  
  1393. /*
  1394.  *  Called for the following distance effects:
  1395.  *    when a weapon is thrown (weapon == THROWN_WEAPON)
  1396.  *    when an object is kicked (KICKED_WEAPON)
  1397.  *    when an IMMEDIATE wand is zapped (ZAPPED_WAND)
  1398.  *    when a light beam is flashed (FLASHED_LIGHT)
  1399.  *    for some invisible effect on a monster (INVIS_BEAM)
  1400.  *  A thrown/kicked object falls down at the end of its range or when a monster
  1401.  *  is hit.  The variable 'bhitpos' is set to the final position of the weapon
  1402.  *  thrown/zapped.  The ray of a wand may affect (by calling a provided
  1403.  *  function) several objects and monsters on its path.  The return value
  1404.  *  is the monster hit (weapon != ZAPPED_WAND), or a null monster pointer.
  1405.  *
  1406.  *  Check !u.uswallow before calling bhit().
  1407.  */
  1408. struct monst *
  1409. bhit(ddx,ddy,range,weapon,fhitm,fhito,obj)
  1410. register int ddx,ddy,range;        /* direction and range */
  1411. int weapon;                /* see values in hack.h */
  1412.                     /* fns called when mon/obj hit */
  1413. int FDECL((*fhitm), (MONST_P, OBJ_P)),
  1414.     FDECL((*fhito), (OBJ_P, OBJ_P));
  1415. struct obj *obj;            /* object tossed/used */
  1416. {
  1417.     register struct monst *mtmp;
  1418.     register uchar typ;
  1419.     register boolean shopdoor = FALSE;
  1420.  
  1421.     if (weapon == KICKED_WEAPON) {
  1422.         /* object starts one square in front of player */
  1423.         bhitpos.x = u.ux + ddx;
  1424.         bhitpos.y = u.uy + ddy;
  1425.         range--;
  1426.     } else {
  1427.         bhitpos.x = u.ux;
  1428.         bhitpos.y = u.uy;
  1429.     }
  1430.  
  1431.     if (weapon == FLASHED_LIGHT) {
  1432.         tmp_at(DISP_BEAM, cmap_to_glyph(S_flashbeam));
  1433.     } else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
  1434.         tmp_at(DISP_FLASH, obj_to_glyph(obj));
  1435.     while(range-- > 0) {
  1436.         int x,y;
  1437.  
  1438.         bhitpos.x += ddx;
  1439.         bhitpos.y += ddy;
  1440.         x = bhitpos.x; y = bhitpos.y;
  1441.  
  1442.         if(!isok(x, y)) {
  1443.             bhitpos.x -= ddx;
  1444.             bhitpos.y -= ddy;
  1445.             break;
  1446.         }
  1447.         if(obj->otyp == PICK_AXE && inside_shop(x, y) &&
  1448.                            shkcatch(obj, x, y)) {
  1449.             tmp_at(DISP_END, 0);
  1450.             return(m_at(x, y));
  1451.         }
  1452.  
  1453.         typ = levl[bhitpos.x][bhitpos.y].typ;
  1454.  
  1455.         if (weapon == ZAPPED_WAND && find_drawbridge(&x,&y))
  1456.             switch (obj->otyp) {
  1457.             case WAN_OPENING:
  1458.             case SPE_KNOCK:
  1459.                 if (is_db_wall(bhitpos.x, bhitpos.y)) {
  1460.                 if (cansee(x,y) || cansee(bhitpos.x,bhitpos.y))
  1461.                     makeknown(obj->otyp);
  1462.                 open_drawbridge(x,y);
  1463.                 }
  1464.                 break;
  1465.             case WAN_LOCKING:
  1466.             case SPE_WIZARD_LOCK:
  1467.                 if ((cansee(x,y) || cansee(bhitpos.x, bhitpos.y))
  1468.                 && levl[x][y].typ == DRAWBRIDGE_DOWN)
  1469.                 makeknown(obj->otyp);
  1470.                 close_drawbridge(x,y);
  1471.                 break;
  1472.             case WAN_STRIKING:
  1473.             case SPE_FORCE_BOLT:
  1474.                 if (typ != DRAWBRIDGE_UP)
  1475.                 destroy_drawbridge(x,y);
  1476.                 makeknown(obj->otyp);
  1477.                 break;
  1478.             }
  1479.  
  1480.         if (weapon == THROWN_WEAPON || weapon == KICKED_WEAPON) {
  1481.             /* can't hit monsters/objects in rock w/solid weapons */
  1482.             /* but beams/zaps _can_, so we need an extra pre-check */
  1483.             if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
  1484.             bhitpos.x -= ddx;
  1485.             bhitpos.y -= ddy;
  1486.             break;
  1487.             }
  1488.         }
  1489.         if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  1490.             if(weapon != ZAPPED_WAND) {
  1491.                 if(weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
  1492.                 return(mtmp);
  1493.             }
  1494.             (*fhitm)(mtmp, obj);
  1495.             range -= 3;
  1496.         }
  1497.         if(fhito) {
  1498.             if(bhitpile(obj,fhito,bhitpos.x,bhitpos.y))
  1499.             range--;
  1500.         } else if(weapon == KICKED_WEAPON && 
  1501.                   ((obj->otyp == GOLD_PIECE && 
  1502.                      OBJ_AT(bhitpos.x, bhitpos.y)) ||
  1503.                         down_gate(bhitpos.x, bhitpos.y) != -1)) {
  1504.             tmp_at(DISP_END, 0);
  1505.             return (struct monst *)0;
  1506.         }
  1507.         if(weapon == ZAPPED_WAND && (IS_DOOR(typ) || typ == SDOOR)) {
  1508.             switch (obj->otyp) {
  1509.             case WAN_OPENING:
  1510.             case WAN_LOCKING:
  1511.             case WAN_STRIKING:
  1512.             case SPE_KNOCK:
  1513.             case SPE_WIZARD_LOCK:
  1514.             case SPE_FORCE_BOLT:
  1515.             if (doorlock(obj, bhitpos.x, bhitpos.y)) {
  1516.                 if (cansee(bhitpos.x, bhitpos.y) ||
  1517.                 (obj->otyp == WAN_STRIKING))
  1518.                 makeknown(obj->otyp);
  1519.                 if (levl[bhitpos.x][bhitpos.y].doormask == D_BROKEN
  1520.                 && *in_rooms(bhitpos.x, bhitpos.y, SHOPBASE)) {
  1521.                 shopdoor = TRUE;
  1522.                 }
  1523.             }
  1524.             break;
  1525.             }
  1526.         }
  1527.         if(!ZAP_POS(typ) || closed_door(bhitpos.x, bhitpos.y)) {
  1528.             bhitpos.x -= ddx;
  1529.             bhitpos.y -= ddy;
  1530.             break;
  1531.         }
  1532.         if(weapon != ZAPPED_WAND && weapon != INVIS_BEAM) {
  1533.             tmp_at(bhitpos.x, bhitpos.y);
  1534.             delay_output();
  1535.             /* kicked objects fall in pools */
  1536.             if((weapon == KICKED_WEAPON) &&
  1537.                is_pool(bhitpos.x, bhitpos.y))
  1538.                 break;
  1539. #ifdef SINKS
  1540.             if(IS_SINK(typ) && weapon != FLASHED_LIGHT)
  1541.                 break;    /* physical objects fall onto sink */
  1542. #endif
  1543.         }
  1544.     }
  1545.  
  1546.     if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM) tmp_at(DISP_END, 0);
  1547.  
  1548.     if(shopdoor)
  1549.         pay_for_damage("destroy");
  1550.  
  1551.     return (struct monst *)0;
  1552. }
  1553.  
  1554. struct monst *
  1555. boomhit(dx, dy)
  1556. int dx, dy;
  1557. {
  1558.     register int i, ct;
  1559.     int boom = S_boomleft;    /* showsym[] index  */
  1560.     struct monst *mtmp;
  1561.  
  1562.     bhitpos.x = u.ux;
  1563.     bhitpos.y = u.uy;
  1564.  
  1565.     for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break;
  1566.     tmp_at(DISP_FLASH, cmap_to_glyph(boom));
  1567.     for(ct=0; ct<10; ct++) {
  1568.         if(i == 8) i = 0;
  1569.         boom = (boom == S_boomleft) ? S_boomright : S_boomleft;
  1570.         tmp_at(DISP_CHANGE, cmap_to_glyph(boom));/* change glyph */
  1571.         dx = xdir[i];
  1572.         dy = ydir[i];
  1573.         bhitpos.x += dx;
  1574.         bhitpos.y += dy;
  1575.         if(MON_AT(bhitpos.x, bhitpos.y)) {
  1576.             mtmp = m_at(bhitpos.x,bhitpos.y);
  1577.             m_respond(mtmp);
  1578.             tmp_at(DISP_END, 0);
  1579.             return(mtmp);
  1580.         }
  1581.         if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ) ||
  1582.            closed_door(bhitpos.x, bhitpos.y)) {
  1583.             bhitpos.x -= dx;
  1584.             bhitpos.y -= dy;
  1585.             break;
  1586.         }
  1587.         if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
  1588.             if(Fumbling || rn2(20) >= ACURR(A_DEX)) {
  1589.                 /* we hit ourselves */
  1590.                 (void) thitu(10, rnd(10), (struct obj *)0,
  1591.                     "boomerang");
  1592.                 break;
  1593.             } else {    /* we catch it */
  1594.                 tmp_at(DISP_END, 0);
  1595.                 pline("You skillfully catch the boomerang.");
  1596.                 return(&youmonst);
  1597.             }
  1598.         }
  1599.         tmp_at(bhitpos.x, bhitpos.y);
  1600.         delay_output();
  1601.         if(ct % 5 != 0) i++;
  1602. #ifdef SINKS
  1603.         if(IS_SINK(levl[bhitpos.x][bhitpos.y].typ))
  1604.             break;    /* boomerang falls on sink */
  1605. #endif
  1606.     }
  1607.     tmp_at(DISP_END, 0);    /* do not leave last symbol */
  1608.     return (struct monst *)0;
  1609. }
  1610.  
  1611. static int
  1612. zhit(mon, type, nd)            /* returns damage to mon */
  1613. register struct monst *mon;
  1614. register int type, nd;
  1615. {
  1616.     register int tmp = 0;
  1617.     register int abstype = abs(type) % 10;
  1618.  
  1619.     switch(abstype) {
  1620.     case ZT_MAGIC_MISSILE:
  1621.         tmp = d(nd,6);
  1622.         break;
  1623.     case ZT_FIRE:
  1624.         if(resists_fire(mon->data)) {
  1625.             shieldeff(mon->mx, mon->my);
  1626.             break;
  1627.         }
  1628.         tmp = d(nd,6);
  1629.         if(resists_cold(mon->data)) tmp += 7;
  1630.         break;
  1631.     case ZT_COLD:
  1632.         if(resists_cold(mon->data)) {
  1633.             shieldeff(mon->mx, mon->my);
  1634.             break;
  1635.         }
  1636.         tmp = d(nd,6);
  1637.         if(resists_fire(mon->data)) tmp += d(nd, 3);
  1638.         break;
  1639.     case ZT_SLEEP:
  1640.         tmp = 0;
  1641.         if(resists_sleep(mon->data) ||
  1642.            resist(mon, (type == ZT_WAND(ZT_SLEEP)) ?
  1643.               WAND_CLASS : '\0', 0, NOTELL))
  1644.             shieldeff(mon->mx, mon->my);
  1645.         else if (mon->mcanmove) {
  1646.             int tmp2 = d(nd,25);
  1647.             mon->mcanmove = 0;
  1648.             if ((unsigned)mon->mfrozen + tmp2 > 127) 
  1649.                 mon->mfrozen = 127;
  1650.             else mon->mfrozen += tmp2;
  1651.         }
  1652.         break;
  1653.     case ZT_DEATH:        /* death/disintegration */
  1654.         if(abs(type) != ZT_BREATH(ZT_DEATH)) {    /* death */
  1655.             if(mon->data == &mons[PM_DEATH]) {
  1656.             mon->mhpmax += mon->mhpmax/2;
  1657.             mon->mhp = mon->mhpmax;
  1658.             tmp = 0;
  1659.             break;
  1660.             }
  1661.             if(is_undead(mon->data)) {
  1662.             shieldeff(mon->mx, mon->my);
  1663.             break;
  1664.             }
  1665.             type = -1; /* so they don't get saving throws */
  1666.         } else {
  1667.             if (resists_disint(mon->data)) {
  1668.             shieldeff(mon->mx, mon->my);
  1669.             break;
  1670.             } else {
  1671.             tmp = MAGIC_COOKIE;
  1672.             break;
  1673.             }
  1674.         }
  1675.         tmp = mon->mhp+1;
  1676.         break;
  1677.     case ZT_LIGHTNING:
  1678.         if(resists_elec(mon->data)) {
  1679.             shieldeff(mon->mx, mon->my);
  1680.             break;
  1681.         }
  1682.         tmp = d(nd,6);
  1683.         if (haseyes(mon->data)) {
  1684.             register unsigned rnd_tmp = rnd(50);
  1685.             mon->mcansee = 0;
  1686.             if((mon->mblinded + rnd_tmp) > 127)
  1687.                 mon->mblinded = 127;
  1688.             else mon->mblinded += rnd_tmp;
  1689.         }
  1690.         break;
  1691.     case ZT_POISON_GAS:
  1692.         if(resists_poison(mon->data)) {
  1693.             shieldeff(mon->mx, mon->my);
  1694.             break;
  1695.         }
  1696.         tmp = d(nd,6);
  1697.         break;
  1698.     case ZT_ACID:
  1699.         if(resists_acid(mon->data)) {
  1700.             shieldeff(mon->mx, mon->my);
  1701.             break;
  1702.         }
  1703.         tmp = d(nd,6);
  1704.         break;
  1705.     }
  1706. #ifdef MULDGN
  1707.     if(pl_character[0] == 'K' && type >= 10 && type <= 19 &&
  1708.        u.uhave.questart) tmp *= 2;
  1709. #endif
  1710.     if (type >= 0)
  1711.         if (resist(mon, (type < ZT_SPELL(0)) ? WAND_CLASS : '\0',
  1712.                0, NOTELL)) tmp /= 2;
  1713.     mon->mhp -= tmp;
  1714.     return(tmp);
  1715. }
  1716.  
  1717. /*
  1718.  * burn scrolls and spell books on floor at position x,y
  1719.  * return the number of scrolls and spell books burned
  1720.  */
  1721. static int
  1722. burn_floor_paper(x, y)
  1723. int x, y;
  1724. {
  1725.     register struct obj *obj, *obj2;
  1726.     register int cnt = 0;
  1727.     register long i, scrquan;
  1728.  
  1729.     for(obj = level.objects[x][y]; obj; obj = obj2) {
  1730.         obj2 = obj->nexthere;
  1731.         /* Bug fix - KAA */
  1732.         if(obj->oclass == SCROLL_CLASS
  1733.             || obj->oclass == SPBOOK_CLASS) {
  1734.         if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL
  1735.             || obj->otyp == SPE_BOOK_OF_THE_DEAD
  1736.                 || obj->oartifact)
  1737.             continue;
  1738.         scrquan = obj->quan;
  1739.         for(i = 1; i <= scrquan ; i++)
  1740.             if(!rn2(3))  {
  1741.             cnt++;
  1742.             /* not useupf(), which charges */
  1743.             if (obj->quan > 1L) obj->quan--;
  1744.             else delobj(obj);
  1745.             }
  1746.         }
  1747.     }
  1748.     return(cnt);
  1749. }
  1750.  
  1751. /* type ==   0 to   9 : you shooting a wand */
  1752. /* type ==  10 to  19 : you casting a spell */
  1753. /* type ==  20 to  29 : you breathing as a monster */
  1754. /* type == -10 to -19 : monster casting spell */
  1755. /* type == -20 to -29 : monster breathing at you */
  1756. /* type == -30 to -39 : monster shooting a wand (MUSE only) */
  1757. /* called with dx = dy = 0 with vertical bolts */
  1758. void
  1759. buzz(type,nd,sx,sy,dx,dy)
  1760. register int type, nd;
  1761. register xchar sx,sy;
  1762. register int dx,dy;
  1763. {
  1764.     int range, abstype = abs(type) % 10;
  1765.     struct rm *lev;
  1766.     register xchar lsx, lsy;
  1767.     struct monst *mon;
  1768.     boolean bodyhit = FALSE, shopdamage = FALSE;
  1769.     register const char *fltxt;
  1770.  
  1771. #ifdef MUSE
  1772.     fltxt = flash_types[(type <= -30) ? abstype : abs(type)];
  1773. #else
  1774.     fltxt = flash_types[abs(type)];
  1775. #endif
  1776.     if(u.uswallow) {
  1777.     register int tmp;
  1778.  
  1779.     if(type < 0) return;
  1780.     tmp = zhit(u.ustuck, type, nd);
  1781.     if(!u.ustuck)    u.uswallow = 0;
  1782.     else    pline("%s rips into %s%s",
  1783.               The(fltxt), mon_nam(u.ustuck), exclam(tmp));
  1784.     /* Using disintegration from the inside only makes a hole... */
  1785.     if (tmp == MAGIC_COOKIE)
  1786.         u.ustuck->mhp = 0;
  1787.     if (u.ustuck->mhp < 1)
  1788.         killed(u.ustuck);
  1789.     return;
  1790.     }
  1791.     if(type < 0) newsym(u.ux,u.uy);
  1792.     range = rn1(7,7);
  1793.     if(dx == 0 && dy == 0) range = 1;
  1794.     tmp_at(DISP_BEAM, zapdir_to_glyph(dx, dy, abstype));
  1795.     while(range-- > 0) {
  1796.     lsx = sx; sx += dx;
  1797.     lsy = sy; sy += dy;
  1798.     if(isok(sx,sy) && (lev = &levl[sx][sy])->typ) {
  1799.         if(cansee(sx,sy)) {
  1800.         if(ZAP_POS(lev->typ) || cansee(lsx,lsy))
  1801.             tmp_at(sx,sy);
  1802.         delay_output(); /* wait a little */
  1803.         }
  1804.     } else
  1805.         goto make_bounce;
  1806.  
  1807.     if (type != ZT_SPELL(ZT_FIRE))
  1808.         /* Fireballs only damage when they explode */
  1809.         range += zap_over_floor(sx, sy, type, &shopdamage);
  1810.     if ((mon = m_at(sx, sy)) != 0) {
  1811.         if (type == ZT_SPELL(ZT_FIRE)) break;
  1812.         if (type >= 0) mon->data->mflags3 &= ~M3_WAITMASK;
  1813.         if (rnd(20) < 18 + find_mac(mon)) {
  1814. #ifdef MUSE
  1815.         if (mon_reflects(mon, "")) {
  1816.             if(cansee(mon->mx,mon->my)) {
  1817.             hit(fltxt, mon, exclam(0));
  1818.             shieldeff(mon->mx, mon->my);
  1819.             (void) mon_reflects(mon, "But it reflects from %s %s!");
  1820.             }
  1821.             dx = -dx;
  1822.             dy = -dy;
  1823.         } else
  1824. #endif
  1825.         {
  1826.             register int tmp = zhit(mon, type, nd);
  1827.  
  1828.             if (is_rider(mon->data) && type == ZT_BREATH(ZT_DEATH)) {
  1829.                 if(cansee(mon->mx, mon->my)) {
  1830.                 hit(fltxt, mon, exclam(tmp));
  1831.                 pline("%s disintegrates.", Monnam(mon));
  1832.                 if(Blind)
  1833.                You("hear the fragments of %s body reassembling!",
  1834.                      s_suffix(mon_nam(mon)));
  1835.                 else
  1836.                pline("%s body reintegrates before your %s!",
  1837.                      s_suffix(Monnam(mon)),
  1838.                      makeplural(body_part(EYE)));
  1839.                     pline("%s resurrects!", Monnam(mon));
  1840.             }
  1841.                 mon->mhp = mon->mhpmax;
  1842.             break; /* Out of while loop */
  1843.             }
  1844.             if(mon->data == &mons[PM_DEATH] && abstype == ZT_DEATH) {
  1845.                 if(cansee(mon->mx,mon->my)) {
  1846.                 hit(fltxt, mon, exclam(tmp));
  1847.                     pline("Death absorbs the deadly %s!",
  1848.                         type == ZT_BREATH(ZT_DEATH) ? 
  1849.                         "blast" : "ray");
  1850.                     pline("It seems even stronger than before.");
  1851.                 }
  1852.                 break; /* Out of while loop */
  1853.             }
  1854.             if (tmp == MAGIC_COOKIE) { /* disintegration */
  1855.             struct obj *otmp, *otmp2;
  1856.             pline("%s is disintegrated!", Monnam(mon));
  1857.             mon->mgold = 0;
  1858.             otmp = mon->minvent;
  1859.             while(otmp) {
  1860. #ifdef MULDGN
  1861.                 if (is_quest_artifact(otmp))
  1862.                 otmp = otmp->nobj;
  1863.                 else {
  1864. #endif
  1865.                 otmp2 = otmp;
  1866.                 if (otmp == mon->minvent)
  1867.                     mon->minvent = otmp->nobj;
  1868.                 otmp = otmp->nobj;
  1869.                 obfree(otmp2, (struct obj *)0);
  1870. #ifdef MULDGN
  1871.                 }
  1872. #endif
  1873.             }
  1874.             if (type < 0)
  1875.                 monkilled(mon, (char *)0, AD_RBRE);
  1876.             else
  1877.                 xkilled(mon, 2);
  1878.             } else if(mon->mhp < 1) {
  1879.             if(type < 0)
  1880.                 monkilled(mon, fltxt, AD_RBRE);
  1881.             else
  1882.                 killed(mon);
  1883.             } else
  1884.             hit(fltxt, mon, exclam(tmp));
  1885.         }
  1886.         range -= 2;
  1887.         } else
  1888.         miss(fltxt,mon);
  1889.     } else if(sx == u.ux && sy == u.uy) {
  1890.         nomul(0);
  1891.         if(rnd(20) < 18+u.uac) {
  1892.         register int dam = 0;
  1893.         range -= 2;
  1894.         pline("%s hits you!", The(fltxt));
  1895.         if (Reflecting) {
  1896.             if (!Blind) {
  1897.             if(Reflecting & WORN_AMUL)
  1898.                 makeknown(AMULET_OF_REFLECTION);
  1899.             else
  1900.                 makeknown(SHIELD_OF_REFLECTION);
  1901.             pline("But it reflects from your %s!",
  1902.                   (Reflecting & W_AMUL) ? "amulet" : "shield");
  1903.             } else
  1904.             pline("For some reason you are not affected.");
  1905.             dx = -dx;
  1906.             dy = -dy;
  1907.             shieldeff(sx, sy);
  1908.         }
  1909.         else switch(abstype) {
  1910.         case ZT_MAGIC_MISSILE:
  1911.             if(Antimagic) {
  1912.             shieldeff(sx, sy);
  1913.             pline("The missiles bounce off!");
  1914.             } else {
  1915.                 dam = d(nd,6);
  1916.             exercise(A_STR, FALSE);
  1917.             }
  1918.             break;
  1919.         case ZT_FIRE:
  1920.             if(Fire_resistance) {
  1921.             shieldeff(sx, sy);
  1922.             You("don't feel hot!");
  1923. #ifdef POLYSELF
  1924.             ugolemeffects(AD_FIRE, d(nd, 6));
  1925. #endif
  1926.             } else dam = d(nd, 6);
  1927.             while (1) {
  1928.             switch(rn2(5)) {
  1929.             case 0:
  1930.                 if (!rust_dmg(uarmh, "leather helmet", 0, FALSE))
  1931.                 continue;
  1932.                 break;
  1933.             case 1:
  1934.                 bodyhit = TRUE;
  1935.                 if (uarmc) break;
  1936.                 if (uarm)
  1937.                 (void)(rust_dmg(uarm, xname(uarm), 0, FALSE));
  1938.                 break;
  1939.             case 2:
  1940.                 if (!rust_dmg(uarms, "wooden shield", 0, FALSE))
  1941.                 continue;
  1942.                 break;
  1943.             case 3:
  1944.                 if (!rust_dmg(uarmg, "gloves", 0, FALSE)) continue;
  1945.                 break;
  1946.             case 4:
  1947.                 if (!rust_dmg(uarmf, "boots", 0, FALSE)) continue;
  1948.                 break;
  1949.             }
  1950.             break; /* Out of while loop */
  1951.             }
  1952.             if(!rn2(3) && bodyhit)
  1953.             destroy_item(POTION_CLASS, AD_FIRE);
  1954.             if(!rn2(3) && bodyhit)
  1955.             destroy_item(SCROLL_CLASS, AD_FIRE);
  1956.             if(!rn2(5) && bodyhit)
  1957.             destroy_item(SPBOOK_CLASS, AD_FIRE);
  1958.             break;
  1959.         case ZT_COLD:
  1960.             if(Cold_resistance) {
  1961.             shieldeff(sx, sy);
  1962.             You("don't feel cold.");
  1963. #ifdef POLYSELF
  1964.             ugolemeffects(AD_COLD, d(nd, 6));
  1965. #endif
  1966.             } else
  1967.             dam = d(nd, 6);
  1968.             if(!rn2(3))
  1969.             destroy_item(POTION_CLASS, AD_COLD);
  1970.             break;
  1971.         case ZT_SLEEP:
  1972.             if(Sleep_resistance) {
  1973.             shieldeff(u.ux, u.uy);
  1974.             You("don't feel sleepy.");
  1975.             } else {
  1976.             /* have to do this _before_ we reset multi */
  1977.             stop_occupation();
  1978.             nomul(-d(nd,25)); /* sleep ray */
  1979.             u.usleep = 1;
  1980.             nomovemsg = "You wake up.";
  1981.             }
  1982.             break;
  1983.         case ZT_DEATH:
  1984.             if(abs(type) == ZT_BREATH(ZT_DEATH)) {
  1985.             if (Disint_resistance) {
  1986.                 You("are not disintegrated.");
  1987.                 break;
  1988.             } else if(uarms) {
  1989.                 (void) destroy_arm(uarms);
  1990.                 break;
  1991.             } else if (uarm)  {
  1992.                 (void) destroy_arm(uarm);
  1993.                 break;
  1994.             }
  1995.             }
  1996. #ifdef POLYSELF
  1997.             else if(is_undead(uasmon)) {
  1998.             shieldeff(sx, sy);
  1999.             You("seem unaffected.");
  2000.             break;
  2001.             }
  2002. #endif
  2003.             else if(Antimagic) {
  2004.             shieldeff(sx, sy);
  2005.             You("aren't affected.");
  2006.             break;
  2007.             }
  2008.             u.uhp = -1;
  2009.             break;
  2010.         case ZT_LIGHTNING:
  2011.             if (Shock_resistance) {
  2012.             shieldeff(sx, sy);
  2013.             You("aren't affected.");
  2014. #ifdef POLYSELF
  2015.             ugolemeffects(AD_ELEC, d(nd, 6));
  2016. #endif
  2017.             } else {
  2018.             dam = d(nd, 6);
  2019.             exercise(A_CON, FALSE);
  2020.             }
  2021.             if(!rn2(3))
  2022.             destroy_item(WAND_CLASS, AD_ELEC);
  2023.             if(!rn2(3))
  2024.             destroy_item(RING_CLASS, AD_ELEC);
  2025.             break;
  2026.         case ZT_POISON_GAS:
  2027.             poisoned("blast", A_DEX, "poisoned blast", 15);
  2028.             break;
  2029.         case ZT_ACID:
  2030. #ifdef POLYSELF
  2031.             if (resists_acid(uasmon))
  2032.             dam = 0;
  2033.             else
  2034. #endif
  2035.             {
  2036.                 pline("The acid burns!");
  2037.                 dam = d(nd,6);
  2038.                 exercise(A_STR, FALSE);
  2039.             }
  2040.             if(!rn2(6)) erode_weapon(TRUE);
  2041.             if(!rn2(6)) erode_armor(TRUE);
  2042.             break;
  2043.         }
  2044.         if(Half_spell_damage && dam &&
  2045.            type < 0 && (type > -20 || type < -29)) /* !Breath */
  2046.             dam = (dam+1) / 2;
  2047.         losehp(dam, fltxt, KILLED_BY_AN);
  2048.         } else pline("%s whizzes by you!", The(fltxt));
  2049.         if (abstype == ZT_LIGHTNING && !Blind) {
  2050.         You("are blinded by the flash!");
  2051.         make_blinded((long)d(nd,50),FALSE);
  2052.         }
  2053.         stop_occupation();
  2054.         nomul(0);
  2055.     }
  2056.     if(!ZAP_POS(lev->typ) || (closed_door(sx, sy) && (range >= 0))) {
  2057.         int bounce;
  2058.         uchar rmn;
  2059.  
  2060.     make_bounce:
  2061.         if (type == ZT_SPELL(ZT_FIRE)) {
  2062.         sx = lsx;
  2063.         sy = lsy;
  2064.         break; /* fireballs explode before the wall */
  2065.         }
  2066.         bounce = 0;
  2067.         range--;
  2068.         if(range && isok(lsx, lsy) && cansee(lsx,lsy))
  2069.         pline("%s bounces!", The(fltxt));
  2070.         if(!dx || !dy || !rn2(20)) {
  2071.         dx = -dx;
  2072.         dy = -dy;
  2073.         } else {
  2074.         if(isok(sx,lsy) && ZAP_POS(rmn = levl[sx][lsy].typ) &&
  2075.            (IS_ROOM(rmn) || (isok(sx+dx,lsy) &&
  2076.                      ZAP_POS(levl[sx+dx][lsy].typ))))
  2077.             bounce = 1;
  2078.         if(isok(lsx,sy) && ZAP_POS(rmn = levl[lsx][sy].typ) &&
  2079.            (IS_ROOM(rmn) || (isok(lsx,sy+dy) &&
  2080.                      ZAP_POS(levl[lsx][sy+dy].typ))))
  2081.             if(!bounce || rn2(2))
  2082.             bounce = 2;
  2083.  
  2084.         switch(bounce) {
  2085.         case 0: dx = -dx; /* fall into... */
  2086.         case 1: dy = -dy; break;
  2087.         case 2: dx = -dx; break;
  2088.         }
  2089.         tmp_at(DISP_CHANGE, zapdir_to_glyph(dx,dy,abstype));
  2090.         }
  2091.     }
  2092.     }
  2093.     tmp_at(DISP_END,0);
  2094.     if (type == ZT_SPELL(ZT_FIRE))
  2095.     explode(sx, sy, type, d(12,6), 0);
  2096.     if (shopdamage)
  2097.     pay_for_damage(abstype == ZT_FIRE ?  "burn away" :
  2098.                abstype == ZT_COLD ?  "shatter" :
  2099.                   abstype == ZT_DEATH ? "disintegrate" : "destroy");
  2100. }
  2101.  
  2102. void
  2103. melt_ice(x, y)
  2104. xchar x, y;
  2105. {
  2106.     struct rm *lev = &levl[x][y];
  2107.  
  2108.     if (lev->typ == DRAWBRIDGE_UP)
  2109.         lev->drawbridgemask &= ~DB_ICE;    /* revert to DB_MOAT */
  2110.     else {    /* lev->typ == ICE */
  2111. #ifdef STUPID
  2112.         if (lev->icedpool == ICED_POOL) lev->typ = POOL;
  2113.         else lev->typ = MOAT;
  2114. #else
  2115.         lev->typ = (lev->icedpool == ICED_POOL ? POOL : MOAT);
  2116. #endif
  2117.         lev->icedpool = 0;
  2118.     }
  2119.     unearth_objs(x, y);
  2120.     newsym(x,y);
  2121.     if (cansee(x,y)) Norep("The ice crackles and melts.");
  2122.     if (x == u.ux && y == u.uy)
  2123.         spoteffects();    /* possibly drown, notice objects */
  2124. }
  2125.  
  2126. /* Burn floor scrolls, evaporate pools, etc...  in a single square.  Used
  2127.  * both for normal bolts of fire, cold, etc... and for fireballs.
  2128.  * Sets shopdamage to TRUE if a shop door is destroyed, and returns the 
  2129.  * amount by which range is reduced (the latter is just ignored by fireballs)
  2130.  */
  2131. int
  2132. zap_over_floor(x, y, type, shopdamage)
  2133. xchar x, y;
  2134. int type;
  2135. boolean *shopdamage;
  2136. {
  2137.     struct monst *mon;
  2138.     int abstype = abs(type) % 10;
  2139.     struct rm *lev = &levl[x][y];
  2140.     int rangemod = 0;
  2141.  
  2142.     if(abstype == ZT_FIRE) {
  2143.         if(is_ice(x, y)) {
  2144.         melt_ice(x, y);
  2145.         } else if(is_pool(x,y)) {
  2146.         const char *msgtxt = "You hear hissing gas.";
  2147.         if(lev->typ != POOL) {    /* MOAT or DRAWBRIDGE_UP */
  2148.             if (cansee(x,y)) msgtxt = "Some water evaporates.";
  2149.         } else {
  2150.             register struct trap *ttmp;
  2151.  
  2152.             rangemod -= 3;
  2153.             lev->typ = ROOM;
  2154.             ttmp = maketrap(x, y, PIT);
  2155.             if (ttmp) ttmp->tseen = 1;
  2156.             if (cansee(x,y)) msgtxt = "The water evaporates.";
  2157.         }
  2158.         Norep(msgtxt);
  2159.         if (lev->typ == ROOM) newsym(x,y);
  2160.         }
  2161.     }
  2162.     else if(abstype == ZT_COLD && (is_pool(x,y) || is_lava(x,y))) {
  2163.         boolean lava = is_lava(x,y);
  2164.         boolean moat = (!lava && (lev->typ != POOL) &&
  2165.                 (lev->typ != WATER) &&
  2166.                 !Is_medusa_level(&u.uz) &&
  2167.                 !Is_waterlevel(&u.uz));
  2168.  
  2169.         if (lev->typ == WATER) {
  2170.             /* For now, don't let WATER freeze. */
  2171.             if (cansee(x,y))
  2172.             pline("The water freezes for a moment.");
  2173.             else
  2174.             You("hear a soft crackling.");
  2175.             rangemod -= 1000;    /* stop */
  2176.         } else {
  2177.             rangemod -= 3;
  2178.             if (lev->typ == DRAWBRIDGE_UP) {
  2179.             lev->drawbridgemask &= ~DB_UNDER;  /* clear lava */
  2180.             lev->drawbridgemask |= (lava ? DB_FLOOR : DB_ICE);
  2181.             } else {
  2182.             if (!lava)
  2183.                 lev->icedpool =
  2184.                     (lev->typ == POOL ? ICED_POOL : ICED_MOAT);
  2185.             lev->typ = (lava ? ROOM : ICE);
  2186.             }
  2187.             bury_objs(x,y);
  2188.             if(cansee(x,y)) {
  2189.             if(moat)
  2190.                 Norep("The moat is bridged with ice!");
  2191.             else if(lava)
  2192.                 Norep("The lava cools and solidifies.");
  2193.             else
  2194.                 Norep("The water freezes.");
  2195.             newsym(x,y);
  2196.             } else if(flags.soundok && !lava)
  2197.             You("hear a crackling sound.");
  2198.             if(x == u.ux && y == u.uy &&
  2199.                    u.utrap && u.utraptype == TT_LAVA) {
  2200. #ifdef POLYSELF
  2201.             if (passes_walls(uasmon))
  2202.                 You("pass through the now-solid rock.");
  2203.             else {
  2204. #endif
  2205.                 u.utrap = rn1(50,20);
  2206.                 u.utraptype = TT_INFLOOR;
  2207.                 You("are firmly stuck in the cooling rock.");
  2208. #ifdef POLYSELF
  2209.             }
  2210. #endif
  2211.             }
  2212.         }
  2213.     }
  2214.     if(closed_door(x, y)) {
  2215.         rangemod = -1000;
  2216.         switch(abstype) {
  2217.         case ZT_FIRE:
  2218.             if(type >= 0 && *in_rooms(x, y, SHOPBASE)) {
  2219.             add_damage(x, y, 400L);
  2220.             *shopdamage = TRUE;
  2221.             }
  2222.             lev->doormask = D_NODOOR;
  2223.             unblock_point(x,y);    /* vision */
  2224.             if(cansee(x,y)) {
  2225.             pline("The door is consumed in flames!");
  2226.             newsym(x,y);
  2227.             }
  2228.             else You("smell smoke.");
  2229.             break;
  2230.         case ZT_COLD:
  2231.             if(type >= 0 && *in_rooms(x, y, SHOPBASE)) {
  2232.             add_damage(x, y, 400L);
  2233.             *shopdamage = TRUE;
  2234.             }
  2235.             lev->doormask = D_NODOOR;
  2236.             unblock_point(x,y);    /* vision */
  2237.             if(cansee(x,y)) {
  2238.             pline("The door freezes and shatters!");
  2239.             newsym(x,y);
  2240.             }
  2241.             else You("feel cold.");
  2242.             break;
  2243.         case ZT_DEATH:
  2244.             /* death spells/wands don't disintegrate */
  2245.             if(abs(type) != ZT_BREATH(ZT_DEATH))
  2246.             goto def_case;
  2247.             if(type >= 0 && *in_rooms(x, y, SHOPBASE)) {
  2248.             add_damage(x, y, 400L);
  2249.             *shopdamage = TRUE;
  2250.             }
  2251.             lev->doormask = D_NODOOR;
  2252.             unblock_point(x,y);    /* vision */
  2253.             if(cansee(x,y)) {
  2254.             pline("The door disintegrates!");
  2255.             newsym(x,y);
  2256.             }
  2257.             else if(flags.soundok)
  2258.             You("hear crashing wood.");
  2259.             break;
  2260.         case ZT_LIGHTNING:
  2261.             if(type >= 0 && *in_rooms(x, y, SHOPBASE)) {
  2262.             add_damage(x, y, 400L);
  2263.             *shopdamage = TRUE;
  2264.             }
  2265.             lev->doormask = D_BROKEN;
  2266.             unblock_point(x,y);    /* vision */
  2267.             if(cansee(x,y)) {
  2268.             pline("The door splinters!");
  2269.             newsym(x,y);
  2270.             }
  2271.             else if(flags.soundok)
  2272.             You("hear crackling.");
  2273.             break;
  2274.         default:
  2275.         def_case:
  2276.             if(cansee(x,y)) {
  2277.             pline("The door absorbs %s %s!",
  2278.                   (type < 0) ? "the" : "your",
  2279.                   abs(type) < ZT_SPELL(0) ? "bolt" :
  2280.                   abs(type) < ZT_BREATH(0) ? "spell" :
  2281.                   "blast");
  2282.             } else You("feel vibrations.");
  2283.             break;
  2284.         }
  2285.     }
  2286.     if(OBJ_AT(x, y) && abstype == ZT_FIRE)
  2287.         if(burn_floor_paper(x,y) && cansee(x,y))  {
  2288.             newsym(x,y);
  2289.             if(!Blind)
  2290.             You("see a puff of smoke.");
  2291.             else
  2292.             You("smell a whiff of smoke.");
  2293.         }
  2294.     if ((mon = m_at(x,y)) != 0) {
  2295.         /* Cannot use wakeup() which also angers the monster */
  2296.         mon->msleep = 0;
  2297.         if(mon->m_ap_type) seemimic(mon);
  2298.         if(type >= 0) {
  2299.             setmangry(mon);
  2300.             if(mon->ispriest && *in_rooms(mon->mx, mon->my, TEMPLE))
  2301.             ghod_hitsu(mon);
  2302.             if(mon->isshk && !*u.ushops)
  2303.             hot_pursuit(mon);
  2304.         }
  2305.     }
  2306.     return rangemod;
  2307. }
  2308.  
  2309. void
  2310. rloco(obj)
  2311. register struct obj *obj;
  2312. {
  2313.     register xchar tx, ty, otx, oty;
  2314.  
  2315.     otx = obj->ox;
  2316.     oty = obj->oy;
  2317.     do {
  2318.         tx = rn1(COLNO-3,2);
  2319.         ty = rn2(ROWNO);
  2320.     } while(!goodpos(tx,ty,(struct monst *)0, (struct permonst *)0));
  2321.     freeobj(obj);
  2322.     if (flooreffects(obj, tx, ty, "fall"))
  2323.         return;
  2324.     if (otx == 0 && oty == 0) {
  2325.         ;    /* fell through a trapdoor; no update of old loc needed */
  2326.     } else {
  2327.         if (costly_spot(otx, oty)
  2328.           && (!costly_spot(tx, ty) ||
  2329.           !index(in_rooms(tx, ty, 0), *in_rooms(otx, oty, 0)))) {
  2330.         if(costly_spot(u.ux, u.uy) &&
  2331.                 index(u.urooms, *in_rooms(otx, oty, 0)))
  2332.             addtobill(obj, FALSE, FALSE, FALSE);
  2333.         else (void)stolen_value(obj, otx, oty, FALSE, FALSE);
  2334.         }
  2335.         newsym(otx, oty);    /* update old location */
  2336.     }
  2337.     obj->nobj = fobj;
  2338.     fobj = obj;
  2339.     place_object(obj, tx, ty);
  2340.     newsym(tx,ty);
  2341. }
  2342.  
  2343. void
  2344. fracture_rock(obj)    /* fractured by pick-axe or wand of striking */
  2345. register struct obj *obj;           /* no texts here! */
  2346. {
  2347.     obj->otyp = ROCK;
  2348.     obj->quan = (long) rn1(60, 7);
  2349.     obj->owt = weight(obj);
  2350.     obj->oclass = GEM_CLASS;
  2351.     obj->known = FALSE;
  2352.     obj->onamelth = 0;        /* no names */
  2353.     if(!does_block(obj->ox,obj->oy,&levl[obj->ox][obj->oy]))
  2354.         unblock_point(obj->ox,obj->oy);
  2355.     if(cansee(obj->ox,obj->oy))
  2356.         newsym(obj->ox,obj->oy);
  2357. }
  2358.  
  2359. boolean
  2360. break_statue(obj)
  2361. register struct obj *obj;
  2362. {
  2363.     struct trap *trap;
  2364.     struct obj *item, *nitem;
  2365.  
  2366.     if((trap = t_at(obj->ox,obj->oy)) && trap->ttyp == STATUE_TRAP)
  2367.         if(makemon(&mons[obj->corpsenm], obj->ox, obj->oy)) {
  2368.         pline("Instead of shattering, the statue suddenly comes alive!");
  2369.         delobj(obj);
  2370.         deltrap(trap);
  2371.         return FALSE;
  2372.         }
  2373.     for(item = obj->cobj; item; item = nitem) {
  2374.         nitem = item->nobj;
  2375.         item->nobj = fobj;
  2376.         fobj = item;
  2377.         place_object(item, obj->ox, obj->oy);
  2378.     }
  2379.     obj->cobj = (struct obj *)0;
  2380.     fracture_rock(obj);
  2381.     return TRUE;
  2382. }
  2383.  
  2384. const char *destroy_strings[] = {
  2385.     "freezes and shatters", "freeze and shatter", "shattered potion",
  2386.     "boils and explodes", "boil and explode", "boiling potion",
  2387.     "catches fire and burns", "catch fire and burn", "burning scroll",
  2388.     "catches fire and burns", "catch fire and burn", "burning book",
  2389.     "turns to dust and vanishes", "turn to dust and vanish", "",
  2390.     "breaks apart and explodes", "break apart and explode", "exploding wand"
  2391. };
  2392.  
  2393. void
  2394. destroy_item(osym, dmgtyp)
  2395. register int osym, dmgtyp;
  2396. {
  2397.     register struct obj *obj, *obj2;
  2398.     register int dmg, xresist, skip;
  2399.     register long i, cnt, quan;
  2400.     register int dindx;
  2401.     const char *mult;
  2402.  
  2403.     for(obj = invent; obj; obj = obj2) {
  2404.  
  2405.         obj2 = obj->nobj;
  2406.         if(obj->oclass != osym) continue; /* test only objs of type osym */
  2407.         if(obj->oartifact) continue; /* don't destroy artifacts */
  2408.         xresist = skip = 0;
  2409. #ifdef GCC_WARN
  2410.         dmg = dindx = 0;
  2411.         quan = 0L;
  2412. #endif
  2413.         switch(dmgtyp) {
  2414.         case AD_COLD:
  2415.             if(osym == POTION_CLASS) {
  2416.             quan = obj->quan;
  2417.             dindx = 0;
  2418.             dmg = rnd(4);
  2419.             } else skip++;
  2420.                 break;
  2421.         case AD_FIRE:
  2422.             xresist = (Fire_resistance && obj->oclass != POTION_CLASS);
  2423.  
  2424.             if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  2425.             skip++;
  2426.             if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  2427.             skip++;
  2428.             if (!Blind)
  2429.                 pline("%s glows a strange %s, but remains intact.",
  2430.                 The(xname(obj)),
  2431.                 Hallucination ? hcolor() : "dark red");
  2432.             }
  2433.             quan = obj->quan;
  2434.             switch(osym) {
  2435.             case POTION_CLASS:
  2436.                 dindx = 1;
  2437.                 dmg = rnd(6);
  2438.                 break;
  2439.             case SCROLL_CLASS:
  2440.                 dindx = 2;
  2441.                 dmg = 1;
  2442.                 break;
  2443.             case SPBOOK_CLASS:
  2444.                 dindx = 3;
  2445.                 dmg = 1;
  2446.                 break;
  2447.             default:
  2448.                 skip++;
  2449.                 break;
  2450.             }
  2451.             break;
  2452.         case AD_ELEC:
  2453.             xresist = (Shock_resistance && obj->oclass != RING_CLASS);
  2454.             quan = obj->quan;
  2455.             switch(osym) {
  2456.             case RING_CLASS:
  2457.                 if(obj->otyp == RIN_SHOCK_RESISTANCE)
  2458.                     { skip++; break; }
  2459.                 dindx = 4;
  2460.                 dmg = 0;
  2461.                 break;
  2462.             case WAND_CLASS:
  2463.                 if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
  2464.                 dindx = 5;
  2465.                 dmg = rnd(10);
  2466.                 break;
  2467.             default:
  2468.                 skip++;
  2469.                 break;
  2470.             }
  2471.             break;
  2472.         default:
  2473.             skip++;
  2474.             break;
  2475.         }
  2476.         if(!skip) {
  2477.         for(i = cnt = 0L; i < quan; i++)
  2478.             if(!rn2(3)) cnt++;
  2479.  
  2480.         if(!cnt) continue;
  2481.         if(cnt == quan)    mult = "Your";
  2482.         else    mult = (cnt == 1L) ? "One of your" : "Some of your";
  2483.         pline("%s %s %s!", mult, xname(obj),
  2484.             (cnt > 1L) ? destroy_strings[dindx*3 + 1]
  2485.                   : destroy_strings[dindx*3]);
  2486.         if(osym == POTION_CLASS && dmgtyp != AD_COLD)
  2487.             potionbreathe(obj);
  2488.         for(i = 0; i < cnt; i++) {
  2489.             if (obj->owornmask) {
  2490.             if (obj->owornmask & W_RING) /* ring being worn */
  2491.                 Ring_gone(obj);
  2492.             else
  2493.                 setnotworn(obj);
  2494.             }
  2495.             useup(obj);
  2496.         }
  2497.         if(dmg) {
  2498.             if(xresist)    You("aren't hurt!");
  2499.             else {
  2500.                 losehp(dmg, (cnt==1L) ? destroy_strings[dindx*3 + 2] :
  2501.                    (const char *)makeplural(destroy_strings[dindx*3 + 2]),
  2502.                    (cnt==1L) ? KILLED_BY_AN : KILLED_BY);
  2503.             exercise(A_STR, FALSE);
  2504.            }
  2505.         }
  2506.         }
  2507.     }
  2508.     return;
  2509. }
  2510.  
  2511. int
  2512. destroy_mitem(mtmp, osym, dmgtyp)
  2513. register struct monst *mtmp;
  2514. register int osym, dmgtyp;
  2515. {
  2516.     register struct obj *obj, *obj2;
  2517.     register int skip, tmp = 0;
  2518.     register long i, cnt, quan;
  2519.     register int dindx;
  2520.     boolean vis=canseemon(mtmp);
  2521.  
  2522.     for(obj = mtmp->minvent; obj; obj = obj2) {
  2523.  
  2524.         obj2 = obj->nobj;
  2525.         if(obj->oclass != osym) continue; /* test only objs of type osym */
  2526.         skip = 0;
  2527. #ifdef GCC_WARN
  2528.         quan = 0L;
  2529.         dindx = 0;
  2530. #endif
  2531.         switch(dmgtyp) {
  2532.         case AD_COLD:
  2533.             if(osym == POTION_CLASS) {
  2534.             quan = obj->quan;
  2535.             dindx = 0;
  2536.             tmp++;
  2537.             } else skip++;
  2538.                 break;
  2539.         case AD_FIRE:
  2540.             if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  2541.             skip++;
  2542.             if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  2543.             skip++;
  2544.             if (vis)
  2545.                 pline("%s glows a strange %s, but remains intact.",
  2546.                 The(distant_name(obj, xname)),
  2547.                 Hallucination ? hcolor() : "dark red");
  2548.             }
  2549.             quan = obj->quan;
  2550.             switch(osym) {
  2551.             case POTION_CLASS:
  2552.                 dindx = 1;
  2553.                 tmp++;
  2554.                 break;
  2555.             case SCROLL_CLASS:
  2556.                 dindx = 2;
  2557.                 tmp++;
  2558.                 break;
  2559.             case SPBOOK_CLASS:
  2560.                 dindx = 3;
  2561.                 tmp++;
  2562.                 break;
  2563.             default:
  2564.                 skip++;
  2565.                 break;
  2566.             }
  2567.             break;
  2568.         case AD_ELEC:
  2569.             quan = obj->quan;
  2570.             switch(osym) {
  2571.             case RING_CLASS:
  2572.                 if(obj->otyp == RIN_SHOCK_RESISTANCE)
  2573.                     { skip++; break; }
  2574.                 dindx = 4;
  2575.                 break;
  2576.             case WAND_CLASS:
  2577.                 if(obj->otyp == WAN_LIGHTNING) { skip++; break; }
  2578.                 dindx = 5;
  2579.                 tmp++;
  2580.                 break;
  2581.             default:
  2582.                 skip++;
  2583.                 break;
  2584.             }
  2585.             break;
  2586.         default:
  2587.             skip++;
  2588.             break;
  2589.         }
  2590.         if(!skip) {
  2591.         for(i = cnt = 0L; i < quan; i++)
  2592.             if(!rn2(3)) cnt++;
  2593.  
  2594.         if(!cnt) continue;
  2595.         if (vis) pline("%s %s %s!", 
  2596.             s_suffix(Monnam(mtmp)), xname(obj),
  2597.             (cnt > 1L) ? destroy_strings[dindx*3 + 1]
  2598.                   : destroy_strings[dindx*3]);
  2599.         for(i = 0; i < cnt; i++) m_useup(mtmp, obj);
  2600.         }
  2601.     }
  2602.     return(tmp);
  2603. }
  2604.  
  2605. /*ARGSUSED*/
  2606. int
  2607. resist(mtmp, class, damage, tell)
  2608. register struct monst    *mtmp;
  2609. register char    class;
  2610. register int    damage, tell;
  2611. {
  2612.     register int    resisted;
  2613.     register int    lev;
  2614.  
  2615.     switch(class)  {
  2616.  
  2617.         case WAND_CLASS:
  2618.             lev = 8;
  2619.             break;
  2620.  
  2621.         case SCROLL_CLASS:
  2622.             lev = 6;
  2623.             break;
  2624.  
  2625.         case POTION_CLASS:
  2626.             lev = 5;
  2627.             break;
  2628.  
  2629.         default:    lev = u.ulevel;
  2630.             break;
  2631.     }
  2632.  
  2633.     resisted = (rn2(100) - (unsigned)mtmp->m_lev + lev) < mtmp->data->mr;
  2634.     if(resisted) {
  2635.  
  2636.         if(tell) {
  2637.             shieldeff(mtmp->mx, mtmp->my);
  2638.             pline("%s resists!", Monnam(mtmp));
  2639.         }
  2640.         mtmp->mhp -= damage/2;
  2641.     } else  mtmp->mhp -= damage;
  2642.  
  2643. #ifdef MUSE
  2644.     if(mtmp->mhp < 1) {
  2645.         if(m_using) monkilled(mtmp, "", AD_RBRE);
  2646.         else killed(mtmp);
  2647.     }
  2648. #else
  2649.     if(mtmp->mhp < 1) killed(mtmp);
  2650. #endif
  2651.     return(resisted);
  2652. }
  2653.  
  2654. void
  2655. makewish()
  2656. {
  2657.     char buf[BUFSZ];
  2658.     register struct obj *otmp;
  2659.     int tries = 0;
  2660.  
  2661.     if (flags.verbose) You("may wish for an object.");
  2662. retry:
  2663.     getlin("For what do you wish?", buf);
  2664.     if(buf[0] == '\033') buf[0] = 0;
  2665.     /*
  2666.      *  Note: if they wished for and got a non-object successfully,
  2667.      *  otmp == &zeroobj
  2668.      */
  2669.     otmp = readobjnam(buf);
  2670.     if (!otmp) {
  2671.         pline("Nothing fitting that description exists in the game.");
  2672.         if (++tries < 5) goto retry;
  2673.         pline(thats_enough_tries);
  2674.         if (!(otmp = readobjnam((char *)0)))
  2675.         return; /* for safety; should never happen */
  2676.     }
  2677.     if (otmp != &zeroobj) {
  2678.         if(otmp->oartifact && !touch_artifact(otmp,&youmonst))
  2679.         dropy(otmp);
  2680.         else
  2681.         /* The(aobjnam()) is safe since otmp is unidentified -dlc */
  2682.         (void) hold_another_object(otmp, u.uswallow ?
  2683.                        "Oops!  %s out of your reach!" :
  2684.                        Is_airlevel(&u.uz) || u.uinwater ?
  2685.                        "Oops!  %s away from you!" :
  2686.                        "Oops!  %s to the floor!",
  2687.                        The(aobjnam(otmp,
  2688.                          Is_airlevel(&u.uz) || u.uinwater ?
  2689.                            "slip" : "drop")),
  2690.                        (const char *)0);
  2691.         u.ublesscnt += rn1(100,50);  /* the gods take notice */
  2692.     }
  2693. }
  2694.  
  2695. /*zap.c*/
  2696.