Source:NetHack 3.6.1/src/explode.c

From NetHackWiki
(Redirected from Source:Ref/explode)
Jump to: navigation, search

Below is the full text to explode.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/explode.c#line123]], for example.

Top of file

  1.  /* NetHack 3.6	explode.c	$NHDT-Date: 1522454717 2018/03/31 00:05:17 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.56 $ */
  2.  /*      Copyright (C) 1990 by Ken Arromdee */
  3.  /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1.  
  2.  #include "hack.h"
  3.  
  4.  /* Note: Arrays are column first, while the screen is row first */
  5.  static int explosion[3][3] = { { S_explode1, S_explode4, S_explode7 },
  6.                                 { S_explode2, S_explode5, S_explode8 },
  7.                                 { S_explode3, S_explode6, S_explode9 } };
  8.  
  9.  /* Note: I had to choose one of three possible kinds of "type" when writing
  10.   * this function: a wand type (like in zap.c), an adtyp, or an object type.
  11.   * Wand types get complex because they must be converted to adtyps for
  12.   * determining such things as fire resistance.  Adtyps get complex in that
  13.   * they don't supply enough information--was it a player or a monster that
  14.   * did it, and with a wand, spell, or breath weapon?  Object types share both
  15.   * these disadvantages....
  16.   *
  17.   * Important note about Half_physical_damage:
  18.   *      Unlike losehp(), explode() makes the Half_physical_damage adjustments
  19.   *      itself, so the caller should never have done that ahead of time.
  20.   *      It has to be done this way because the damage value is applied to
  21.   *      things beside the player. Care is taken within explode() to ensure
  22.   *      that Half_physical_damage only affects the damage applied to the hero.
  23.   */

explode

  1.  void
  2.  explode(x, y, type, dam, olet, expltype)
  3.  int x, y;
  4.  int type; /* the same as in zap.c; passes -(wand typ) for some WAND_CLASS */
  5.  int dam;
  6.  char olet;
  7.  int expltype;
  8.  {
  9.      int i, j, k, damu = dam;
  10.      boolean starting = 1;
  11.      boolean visible, any_shield;
  12.      int uhurt = 0; /* 0=unhurt, 1=items damaged, 2=you and items damaged */
  13.      const char *str = (const char *) 0;
  14.      int idamres, idamnonres;
  15.      struct monst *mtmp, *mdef = 0;
  16.      uchar adtyp;
  17.      int explmask[3][3]; /* 0=normal explosion, 1=do shieldeff, 2=do nothing */
  18.      boolean shopdamage = FALSE, generic = FALSE, physical_dmg = FALSE,
  19.              do_hallu = FALSE, inside_engulfer, grabbed, grabbing;
  20.      coord grabxy;
  21.      char hallu_buf[BUFSZ], killr_buf[BUFSZ];
  22.      short exploding_wand_typ = 0;
  23.  
  24.      if (olet == WAND_CLASS) { /* retributive strike */
  25.          /* 'type' is passed as (wand's object type * -1); save
  26.             object type and convert 'type' itself to zap-type */
  27.          if (type < 0) {
  28.              type = -type;
  29.              exploding_wand_typ = (short) type;
  30.              /* most attack wands produce specific explosions;
  31.                 other types produce a generic magical explosion */
  32.              if (objects[type].oc_dir == RAY
  33.                  && type != WAN_DIGGING && type != WAN_SLEEP) {
  34.                  type -= WAN_MAGIC_MISSILE;
  35.                  if (type < 0 || type > 9) {
  36.                      impossible("explode: wand has bad zap type (%d).", type);
  37.                      type = 0;
  38.                  }
  39.              } else
  40.                  type = 0;
  41.          }
  42.          switch (Role_switch) {
  43.          case PM_PRIEST:
  44.          case PM_MONK:
  45.          case PM_WIZARD:
  46.              damu /= 5;
  47.              break;
  48.          case PM_HEALER:
  49.          case PM_KNIGHT:
  50.              damu /= 2;
  51.              break;
  52.          default:
  53.              break;
  54.          }
  55.      }
  56.      /* muse_unslime: SCR_FIRE */
  57.      if (expltype < 0) {
  58.          /* hero gets credit/blame for killing this monster, not others */
  59.          mdef = m_at(x, y);
  60.          expltype = -expltype;
  61.      }
  62.      /* if hero is engulfed and caused the explosion, only hero and
  63.         engulfer will be affected */
  64.      inside_engulfer = (u.uswallow && type >= 0);
  65.      /* held but not engulfed implies holder is reaching into second spot
  66.         so might get hit by double damage */
  67.      grabbed = grabbing = FALSE;
  68.      if (u.ustuck && !u.uswallow) {
  69.          if (Upolyd && sticks(youmonst.data))
  70.              grabbing = TRUE;
  71.          else
  72.              grabbed = TRUE;
  73.          grabxy.x = u.ustuck->mx;
  74.          grabxy.y = u.ustuck->my;
  75.      } else
  76.          grabxy.x = grabxy.y = 0; /* lint suppression */
  77.      /* FIXME:
  78.       *  It is possible for a grabber to be outside the explosion
  79.       *  radius and reaching inside to hold the hero.  If so, it ought
  80.       *  to take damage (the extra half of double damage).  It is also
  81.       *  possible for poly'd hero to be outside the radius and reaching
  82.       *  in to hold a monster.  Hero should take damage in that situation.
  83.       *
  84.       *  Probably the simplest way to handle this would be to expand
  85.       *  the radius used when collecting targets but exclude everything
  86.       *  beyond the regular radius which isn't reaching inside.  Then
  87.       *  skip harm to gear of any extended targets when inflicting damage.
  88.       */
  89.  
  90.      if (olet == MON_EXPLODE) {
  91.          /* when explode() is called recursively, killer.name might change so
  92.             we need to retain a copy of the current value for this explosion */
  93.          str = strcpy(killr_buf, killer.name);
  94.          do_hallu = (Hallucination
  95.                      && (strstri(str, "'s explosion")
  96.                          || strstri(str, "s' explosion")));
  97.          adtyp = AD_PHYS;
  98.      } else
  99.          switch (abs(type) % 10) {
  100.          case 0:
  101.              str = "magical blast";
  102.              adtyp = AD_MAGM;
  103.              break;
  104.          case 1:
  105.              str = (olet == BURNING_OIL) ? "burning oil"
  106.                       : (olet == SCROLL_CLASS) ? "tower of flame" : "fireball";
  107.              /* fire damage, not physical damage */
  108.              adtyp = AD_FIRE;
  109.              break;
  110.          case 2:
  111.              str = "ball of cold";
  112.              adtyp = AD_COLD;
  113.              break;
  114.          case 4:
  115.              str = (olet == WAND_CLASS) ? "death field"
  116.                                         : "disintegration field";
  117.              adtyp = AD_DISN;
  118.              break;
  119.          case 5:
  120.              str = "ball of lightning";
  121.              adtyp = AD_ELEC;
  122.              break;
  123.          case 6:
  124.              str = "poison gas cloud";
  125.              adtyp = AD_DRST;
  126.              break;
  127.          case 7:
  128.              str = "splash of acid";
  129.              adtyp = AD_ACID;
  130.              break;
  131.          default:
  132.              impossible("explosion base type %d?", type);
  133.              return;
  134.          }
  135.  
  136.      any_shield = visible = FALSE;
  137.      for (i = 0; i < 3; i++)
  138.          for (j = 0; j < 3; j++) {
  139.              if (!isok(i + x - 1, j + y - 1)) {
  140.                  explmask[i][j] = 2;
  141.                  continue;
  142.              } else
  143.                  explmask[i][j] = 0;
  144.  
  145.              if (i + x - 1 == u.ux && j + y - 1 == u.uy) {
  146.                  switch (adtyp) {
  147.                  case AD_PHYS:
  148.                      explmask[i][j] = 0;
  149.                      break;
  150.                  case AD_MAGM:
  151.                      explmask[i][j] = !!Antimagic;
  152.                      break;
  153.                  case AD_FIRE:
  154.                      explmask[i][j] = !!Fire_resistance;
  155.                      break;
  156.                  case AD_COLD:
  157.                      explmask[i][j] = !!Cold_resistance;
  158.                      break;
  159.                  case AD_DISN:
  160.                      explmask[i][j] = (olet == WAND_CLASS)
  161.                                           ? !!(nonliving(youmonst.data)
  162.                                                || is_demon(youmonst.data))
  163.                                           : !!Disint_resistance;
  164.                      break;
  165.                  case AD_ELEC:
  166.                      explmask[i][j] = !!Shock_resistance;
  167.                      break;
  168.                  case AD_DRST:
  169.                      explmask[i][j] = !!Poison_resistance;
  170.                      break;
  171.                  case AD_ACID:
  172.                      explmask[i][j] = !!Acid_resistance;
  173.                      physical_dmg = TRUE;
  174.                      break;
  175.                  default:
  176.                      impossible("explosion type %d?", adtyp);
  177.                      break;
  178.                  }
  179.              }
  180.              /* can be both you and mtmp if you're swallowed or riding */
  181.              mtmp = m_at(i + x - 1, j + y - 1);
  182.              if (!mtmp && i + x - 1 == u.ux && j + y - 1 == u.uy)
  183.                  mtmp = u.usteed;
  184.              if (mtmp) {
  185.                  if (mtmp->mhp < 1)
  186.                      explmask[i][j] = 2;
  187.                  else
  188.                      switch (adtyp) {
  189.                      case AD_PHYS:
  190.                          break;
  191.                      case AD_MAGM:
  192.                          explmask[i][j] |= resists_magm(mtmp);
  193.                          break;
  194.                      case AD_FIRE:
  195.                          explmask[i][j] |= resists_fire(mtmp);
  196.                          break;
  197.                      case AD_COLD:
  198.                          explmask[i][j] |= resists_cold(mtmp);
  199.                          break;
  200.                      case AD_DISN:
  201.                          explmask[i][j] |= (olet == WAND_CLASS)
  202.                                                ? (nonliving(mtmp->data)
  203.                                                   || is_demon(mtmp->data)
  204.                                                   || is_vampshifter(mtmp))
  205.                                                : resists_disint(mtmp);
  206.                          break;
  207.                      case AD_ELEC:
  208.                          explmask[i][j] |= resists_elec(mtmp);
  209.                          break;
  210.                      case AD_DRST:
  211.                          explmask[i][j] |= resists_poison(mtmp);
  212.                          break;
  213.                      case AD_ACID:
  214.                          explmask[i][j] |= resists_acid(mtmp);
  215.                          break;
  216.                      default:
  217.                          impossible("explosion type %d?", adtyp);
  218.                          break;
  219.                      }
  220.              }
  221.              if (mtmp && cansee(i + x - 1, j + y - 1) && !canspotmon(mtmp))
  222.                  map_invisible(i + x - 1, j + y - 1);
  223.              else if (!mtmp)
  224.                  (void) unmap_invisible(i + x - 1, j + y - 1);
  225.              if (cansee(i + x - 1, j + y - 1))
  226.                  visible = TRUE;
  227.              if (explmask[i][j] == 1)
  228.                  any_shield = TRUE;
  229.          }
  230.  
  231.      if (visible) {
  232.          /* Start the explosion */
  233.          for (i = 0; i < 3; i++)
  234.              for (j = 0; j < 3; j++) {
  235.                  if (explmask[i][j] == 2)
  236.                      continue;
  237.                  tmp_at(starting ? DISP_BEAM : DISP_CHANGE,
  238.                         explosion_to_glyph(expltype, explosion[i][j]));
  239.                  tmp_at(i + x - 1, j + y - 1);
  240.                  starting = 0;
  241.              }
  242.          curs_on_u(); /* will flush screen and output */
  243.  
  244.          if (any_shield && flags.sparkle) { /* simulate shield effect */
  245.              for (k = 0; k < SHIELD_COUNT; k++) {
  246.                  for (i = 0; i < 3; i++)
  247.                      for (j = 0; j < 3; j++) {
  248.                          if (explmask[i][j] == 1)
  249.                              /*
  250.                               * Bypass tmp_at() and send the shield glyphs
  251.                               * directly to the buffered screen.  tmp_at()
  252.                               * will clean up the location for us later.
  253.                               */
  254.                              show_glyph(i + x - 1, j + y - 1,
  255.                                         cmap_to_glyph(shield_static[k]));
  256.                      }
  257.                  curs_on_u(); /* will flush screen and output */
  258.                  delay_output();
  259.              }
  260.  
  261.              /* Cover last shield glyph with blast symbol. */
  262.              for (i = 0; i < 3; i++)
  263.                  for (j = 0; j < 3; j++) {
  264.                      if (explmask[i][j] == 1)
  265.                          show_glyph(
  266.                              i + x - 1, j + y - 1,
  267.                              explosion_to_glyph(expltype, explosion[i][j]));
  268.                  }
  269.  
  270.          } else { /* delay a little bit. */
  271.              delay_output();
  272.              delay_output();
  273.          }
  274.  
  275.          tmp_at(DISP_END, 0); /* clear the explosion */
  276.      } else {
  277.          if (olet == MON_EXPLODE) {
  278.              str = "explosion";
  279.              generic = TRUE;
  280.          }
  281.          if (!Deaf && olet != SCROLL_CLASS)
  282.              You_hear("a blast.");
  283.      }
  284.  
  285.      if (dam)
  286.          for (i = 0; i < 3; i++)
  287.              for (j = 0; j < 3; j++) {
  288.                  if (explmask[i][j] == 2)
  289.                      continue;
  290.                  if (i + x - 1 == u.ux && j + y - 1 == u.uy)
  291.                      uhurt = (explmask[i][j] == 1) ? 1 : 2;
  292.                  /* for inside_engulfer, only <u.ux,u.uy> is affected */
  293.                  else if (inside_engulfer)
  294.                      continue;
  295.                  idamres = idamnonres = 0;
  296.                  if (type >= 0 && !u.uswallow)
  297.                      (void) zap_over_floor((xchar) (i + x - 1),
  298.                                            (xchar) (j + y - 1), type,
  299.                                            &shopdamage, exploding_wand_typ);
  300.  
  301.                  mtmp = m_at(i + x - 1, j + y - 1);
  302.                  if (!mtmp && i + x - 1 == u.ux && j + y - 1 == u.uy)
  303.                      mtmp = u.usteed;
  304.                  if (!mtmp)
  305.                      continue;
  306.                  if (do_hallu) {
  307.                      /* replace "gas spore" with a different description
  308.                         for each target (we can't distinguish personal names
  309.                         like "Barney" here in order to suppress "the" below,
  310.                         so avoid any which begins with a capital letter) */
  311.                      do {
  312.                          Sprintf(hallu_buf, "%s explosion",
  313.                                  s_suffix(rndmonnam((char *) 0)));
  314.                      } while (*hallu_buf != lowc(*hallu_buf));
  315.                      str = hallu_buf;
  316.                  }
  317.                  if (u.uswallow && mtmp == u.ustuck) {
  318.                      const char *adj = (char *) 0;
  319.  
  320.                      if (is_animal(u.ustuck->data)) {
  321.                          switch (adtyp) {
  322.                          case AD_FIRE:
  323.                              adj = "heartburn";
  324.                              break;
  325.                          case AD_COLD:
  326.                              adj = "chilly";
  327.                              break;
  328.                          case AD_DISN:
  329.                              if (olet == WAND_CLASS)
  330.                                  adj = "irradiated by pure energy";
  331.                              else
  332.                                  adj = "perforated";
  333.                              break;
  334.                          case AD_ELEC:
  335.                              adj = "shocked";
  336.                              break;
  337.                          case AD_DRST:
  338.                              adj = "poisoned";
  339.                              break;
  340.                          case AD_ACID:
  341.                              adj = "an upset stomach";
  342.                              break;
  343.                          default:
  344.                              adj = "fried";
  345.                              break;
  346.                          }
  347.                          pline("%s gets %s!", Monnam(u.ustuck), adj);
  348.                      } else {
  349.                          switch (adtyp) {
  350.                          case AD_FIRE:
  351.                              adj = "toasted";
  352.                              break;
  353.                          case AD_COLD:
  354.                              adj = "chilly";
  355.                              break;
  356.                          case AD_DISN:
  357.                              if (olet == WAND_CLASS)
  358.                                  adj = "overwhelmed by pure energy";
  359.                              else
  360.                                  adj = "perforated";
  361.                              break;
  362.                          case AD_ELEC:
  363.                              adj = "shocked";
  364.                              break;
  365.                          case AD_DRST:
  366.                              adj = "intoxicated";
  367.                              break;
  368.                          case AD_ACID:
  369.                              adj = "burned";
  370.                              break;
  371.                          default:
  372.                              adj = "fried";
  373.                              break;
  374.                          }
  375.                          pline("%s gets slightly %s!", Monnam(u.ustuck), adj);
  376.                      }
  377.                  } else if (cansee(i + x - 1, j + y - 1)) {
  378.                      if (mtmp->m_ap_type)
  379.                          seemimic(mtmp);
  380.                      pline("%s is caught in the %s!", Monnam(mtmp), str);
  381.                  }
  382.  
  383.                  idamres += destroy_mitem(mtmp, SCROLL_CLASS, (int) adtyp);
  384.                  idamres += destroy_mitem(mtmp, SPBOOK_CLASS, (int) adtyp);
  385.                  idamnonres += destroy_mitem(mtmp, POTION_CLASS, (int) adtyp);
  386.                  idamnonres += destroy_mitem(mtmp, WAND_CLASS, (int) adtyp);
  387.                  idamnonres += destroy_mitem(mtmp, RING_CLASS, (int) adtyp);
  388.  
  389.                  if (explmask[i][j] == 1) {
  390.                      golemeffects(mtmp, (int) adtyp, dam + idamres);
  391.                      mtmp->mhp -= idamnonres;
  392.                  } else {
  393.                      /* call resist with 0 and do damage manually so 1) we can
  394.                       * get out the message before doing the damage, and 2) we
  395.                       * can call mondied, not killed, if it's not your blast
  396.                       */
  397.                      int mdam = dam;
  398.  
  399.                      if (resist(mtmp, olet, 0, FALSE)) {
  400.                          /* inside_engulfer: <i+x-1,j+y-1> == <u.ux,u.uy> */
  401.                          if (cansee(i + x - 1, j + y - 1) || inside_engulfer)
  402.                              pline("%s resists the %s!", Monnam(mtmp), str);
  403.                          mdam = (dam + 1) / 2;
  404.                      }
  405.                      /* if grabber is reaching into hero's spot and
  406.                         hero's spot is within explosion radius, grabber
  407.                         gets hit by double damage */
  408.                      if (grabbed && mtmp == u.ustuck && distu(x, y) <= 2)
  409.                          mdam *= 2;
  410.                      /* being resistant to opposite type of damage makes
  411.                         target more vulnerable to current type of damage
  412.                         (when target is also resistant to current type,
  413.                         we won't get here) */
  414.                      if (resists_cold(mtmp) && adtyp == AD_FIRE)
  415.                          mdam *= 2;
  416.                      else if (resists_fire(mtmp) && adtyp == AD_COLD)
  417.                          mdam *= 2;
  418.                      mtmp->mhp -= mdam;
  419.                      mtmp->mhp -= (idamres + idamnonres);
  420.                  }
  421.                  if (mtmp->mhp <= 0) {
  422.                      int xkflg = ((adtyp == AD_FIRE
  423.                                    && completelyburns(mtmp->data))
  424.                                   ? XKILL_NOCORPSE : 0);
  425.  
  426.                      if (!context.mon_moving) {
  427.                          xkilled(mtmp, XKILL_GIVEMSG | xkflg);
  428.                      } else if (mdef && mtmp == mdef) {
  429.                          /* 'mdef' killed self trying to cure being turned
  430.                           * into slime due to some action by the player.
  431.                           * Hero gets the credit (experience) and most of
  432.                           * the blame (possible loss of alignment and/or
  433.                           * luck and/or telepathy depending on mtmp) but
  434.                           * doesn't break pacifism.  xkilled()'s message
  435.                           * would be "you killed <mdef>" so give our own.
  436.                           */
  437.                          if (cansee(mtmp->mx, mtmp->my) || canspotmon(mtmp))
  438.                              pline("%s is %s!", Monnam(mtmp),
  439.                                    xkflg ? "burned completely"
  440.                                          : nonliving(mtmp->data) ? "destroyed"
  441.                                                                  : "killed");
  442.                          xkilled(mtmp, XKILL_NOMSG | XKILL_NOCONDUCT | xkflg);
  443.                      } else {
  444.                          if (xkflg)
  445.                              adtyp = AD_RBRE; /* no corpse */
  446.                          monkilled(mtmp, "", (int) adtyp);
  447.                      }
  448.                  } else if (!context.mon_moving) {
  449.                      /* all affected monsters, even if mdef is set */
  450.                      setmangry(mtmp, TRUE);
  451.                  }
  452.              }
  453.  
  454.      /* Do your injury last */
  455.      if (uhurt) {
  456.          /* give message for any monster-induced explosion
  457.             or player-induced one other than scroll of fire */
  458.          if (flags.verbose && (type < 0 || olet != SCROLL_CLASS)) {
  459.              if (do_hallu) { /* (see explanation above) */
  460.                  do {
  461.                      Sprintf(hallu_buf, "%s explosion",
  462.                              s_suffix(rndmonnam((char *) 0)));
  463.                  } while (*hallu_buf != lowc(*hallu_buf));
  464.                  str = hallu_buf;
  465.              }
  466.              You("are caught in the %s!", str);
  467.              iflags.last_msg = PLNMSG_CAUGHT_IN_EXPLOSION;
  468.          }
  469.          /* do property damage first, in case we end up leaving bones */
  470.          if (adtyp == AD_FIRE)
  471.              burn_away_slime();
  472.          if (Invulnerable) {
  473.              damu = 0;
  474.              You("are unharmed!");
  475.          } else if (adtyp == AD_PHYS || physical_dmg)
  476.              damu = Maybe_Half_Phys(damu);
  477.          if (adtyp == AD_FIRE)
  478.              (void) burnarmor(&youmonst);
  479.          destroy_item(SCROLL_CLASS, (int) adtyp);
  480.          destroy_item(SPBOOK_CLASS, (int) adtyp);
  481.          destroy_item(POTION_CLASS, (int) adtyp);
  482.          destroy_item(RING_CLASS, (int) adtyp);
  483.          destroy_item(WAND_CLASS, (int) adtyp);
  484.  
  485.          ugolemeffects((int) adtyp, damu);
  486.          if (uhurt == 2) {
  487.              /* if poly'd hero is grabbing another victim, hero takes
  488.                 double damage (note: don't rely on u.ustuck here because
  489.                 that victim might have been killed when hit by the blast) */
  490.              if (grabbing && dist2((int) grabxy.x, (int) grabxy.y, x, y) <= 2)
  491.                  damu *= 2;
  492.              /* hero does not get same fire-resistant vs cold and
  493.                 cold-resistant vs fire double damage as monsters [why not?] */
  494.              if (Upolyd)
  495.                  u.mh -= damu;
  496.              else
  497.                  u.uhp -= damu;
  498.              context.botl = 1;
  499.          }
  500.  
  501.          if (u.uhp <= 0 || (Upolyd && u.mh <= 0)) {
  502.              if (Upolyd) {
  503.                  rehumanize();
  504.              } else {
  505.                  if (olet == MON_EXPLODE) {
  506.                      if (generic) /* explosion was unseen; str=="explosion", */
  507.                          ;        /* killer.name=="gas spore's explosion"    */
  508.                      else if (str != killer.name && str != hallu_buf)
  509.                          Strcpy(killer.name, str);
  510.                      killer.format = KILLED_BY_AN;
  511.                  } else if (type >= 0 && olet != SCROLL_CLASS) {
  512.                      killer.format = NO_KILLER_PREFIX;
  513.                      Sprintf(killer.name, "caught %sself in %s own %s", uhim(),
  514.                              uhis(), str);
  515.                  } else {
  516.                      killer.format = (!strcmpi(str, "tower of flame")
  517.                                       || !strcmpi(str, "fireball"))
  518.                                          ? KILLED_BY_AN
  519.                                          : KILLED_BY;
  520.                      Strcpy(killer.name, str);
  521.                  }
  522.                  if (iflags.last_msg == PLNMSG_CAUGHT_IN_EXPLOSION
  523.                      || iflags.last_msg == PLNMSG_TOWER_OF_FLAME) /*seffects()*/
  524.                      pline("It is fatal.");
  525.                  else
  526.                      pline_The("%s is fatal.", str);
  527.                  /* Known BUG: BURNING suppresses corpse in bones data,
  528.                     but done does not handle killer reason correctly */
  529.                  done((adtyp == AD_FIRE) ? BURNING : DIED);
  530.              }
  531.          }
  532.          exercise(A_STR, FALSE);
  533.      }
  534.  
  535.      if (shopdamage) {
  536.          pay_for_damage((adtyp == AD_FIRE) ? "burn away"
  537.                            : (adtyp == AD_COLD) ? "shatter"
  538.                               : (adtyp == AD_DISN) ? "disintegrate"
  539.                                  : "destroy",
  540.                         FALSE);
  541.      }
  542.  
  543.      /* explosions are noisy */
  544.      i = dam * dam;
  545.      if (i < 50)
  546.          i = 50; /* in case random damage is very small */
  547.      if (inside_engulfer)
  548.          i = (i + 3) / 4;
  549.      wake_nearto(x, y, i);
  550.  }
  551.  
  552.  struct scatter_chain {
  553.      struct scatter_chain *next; /* pointer to next scatter item */
  554.      struct obj *obj;            /* pointer to the object        */
  555.      xchar ox;                   /* location of                  */
  556.      xchar oy;                   /*      item                    */
  557.      schar dx;                   /* direction of                 */
  558.      schar dy;                   /*      travel                  */
  559.      int range;                  /* range of object              */
  560.      boolean stopped;            /* flag for in-motion/stopped   */
  561.  };
  562.  
  563.  /*
  564.   * scflags:
  565.   *      VIS_EFFECTS     Add visual effects to display
  566.   *      MAY_HITMON      Objects may hit monsters
  567.   *      MAY_HITYOU      Objects may hit hero
  568.   *      MAY_HIT         Objects may hit you or monsters
  569.   *      MAY_DESTROY     Objects may be destroyed at random
  570.   *      MAY_FRACTURE    Stone objects can be fractured (statues, boulders)
  571.   */
  572.  

scatter

  1.  /* returns number of scattered objects */
  2.  long
  3.  scatter(sx, sy, blastforce, scflags, obj)
  4.  int sx, sy;     /* location of objects to scatter */
  5.  int blastforce; /* force behind the scattering */
  6.  unsigned int scflags;
  7.  struct obj *obj; /* only scatter this obj        */
  8.  {
  9.      register struct obj *otmp;
  10.      register int tmp;
  11.      int farthest = 0;
  12.      uchar typ;
  13.      long qtmp;
  14.      boolean used_up;
  15.      boolean individual_object = obj ? TRUE : FALSE;
  16.      struct monst *mtmp;
  17.      struct scatter_chain *stmp, *stmp2 = 0;
  18.      struct scatter_chain *schain = (struct scatter_chain *) 0;
  19.      long total = 0L;
  20.  
  21.      while ((otmp = (individual_object ? obj : level.objects[sx][sy])) != 0) {
  22.          if (otmp->quan > 1L) {
  23.              qtmp = otmp->quan - 1L;
  24.              if (qtmp > LARGEST_INT)
  25.                  qtmp = LARGEST_INT;
  26.              qtmp = (long) rnd((int) qtmp);
  27.              otmp = splitobj(otmp, qtmp);
  28.          } else {
  29.              obj = (struct obj *) 0; /* all used */
  30.          }
  31.          obj_extract_self(otmp);
  32.          used_up = FALSE;
  33.  
  34.          /* 9 in 10 chance of fracturing boulders or statues */
  35.          if ((scflags & MAY_FRACTURE) != 0
  36.              && (otmp->otyp == BOULDER || otmp->otyp == STATUE)
  37.              && rn2(10)) {
  38.              if (otmp->otyp == BOULDER) {
  39.                  if (cansee(sx, sy))
  40.                      pline("%s apart.", Tobjnam(otmp, "break"));
  41.                  else
  42.                      You_hear("stone breaking.");
  43.                  fracture_rock(otmp);
  44.                  place_object(otmp, sx, sy);
  45.                  if ((otmp = sobj_at(BOULDER, sx, sy)) != 0) {
  46.                      /* another boulder here, restack it to the top */
  47.                      obj_extract_self(otmp);
  48.                      place_object(otmp, sx, sy);
  49.                  }
  50.              } else {
  51.                  struct trap *trap;
  52.  
  53.                  if ((trap = t_at(sx, sy)) && trap->ttyp == STATUE_TRAP)
  54.                      deltrap(trap);
  55.                  if (cansee(sx, sy))
  56.                      pline("%s.", Tobjnam(otmp, "crumble"));
  57.                  else
  58.                      You_hear("stone crumbling.");
  59.                  (void) break_statue(otmp);
  60.                  place_object(otmp, sx, sy); /* put fragments on floor */
  61.              }
  62.              used_up = TRUE;
  63.  
  64.              /* 1 in 10 chance of destruction of obj; glass, egg destruction */
  65.          } else if ((scflags & MAY_DESTROY) != 0
  66.                     && (!rn2(10) || (objects[otmp->otyp].oc_material == GLASS
  67.                                      || otmp->otyp == EGG))) {
  68.              if (breaks(otmp, (xchar) sx, (xchar) sy))
  69.                  used_up = TRUE;
  70.          }
  71.  
  72.          if (!used_up) {
  73.              stmp = (struct scatter_chain *) alloc(sizeof *stmp);
  74.              stmp->next = (struct scatter_chain *) 0;
  75.              stmp->obj = otmp;
  76.              stmp->ox = sx;
  77.              stmp->oy = sy;
  78.              tmp = rn2(8); /* get the direction */
  79.              stmp->dx = xdir[tmp];
  80.              stmp->dy = ydir[tmp];
  81.              tmp = blastforce - (otmp->owt / 40);
  82.              if (tmp < 1)
  83.                  tmp = 1;
  84.              stmp->range = rnd(tmp); /* anywhere up to that determ. by wt */
  85.              if (farthest < stmp->range)
  86.                  farthest = stmp->range;
  87.              stmp->stopped = FALSE;
  88.              if (!schain)
  89.                  schain = stmp;
  90.              else
  91.                  stmp2->next = stmp;
  92.              stmp2 = stmp;
  93.          }
  94.      }
  95.  
  96.      while (farthest-- > 0) {
  97.          for (stmp = schain; stmp; stmp = stmp->next) {
  98.              if ((stmp->range-- > 0) && (!stmp->stopped)) {
  99.                  bhitpos.x = stmp->ox + stmp->dx;
  100.                  bhitpos.y = stmp->oy + stmp->dy;
  101.                  typ = levl[bhitpos.x][bhitpos.y].typ;
  102.                  if (!isok(bhitpos.x, bhitpos.y)) {
  103.                      bhitpos.x -= stmp->dx;
  104.                      bhitpos.y -= stmp->dy;
  105.                      stmp->stopped = TRUE;
  106.                  } else if (!ZAP_POS(typ)
  107.                             || closed_door(bhitpos.x, bhitpos.y)) {
  108.                      bhitpos.x -= stmp->dx;
  109.                      bhitpos.y -= stmp->dy;
  110.                      stmp->stopped = TRUE;
  111.                  } else if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  112.                      if (scflags & MAY_HITMON) {
  113.                          stmp->range--;
  114.                          if (ohitmon(mtmp, stmp->obj, 1, FALSE)) {
  115.                              stmp->obj = (struct obj *) 0;
  116.                              stmp->stopped = TRUE;
  117.                          }
  118.                      }
  119.                  } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
  120.                      if (scflags & MAY_HITYOU) {
  121.                          int hitvalu, hitu;
  122.  
  123.                          if (multi)
  124.                              nomul(0);
  125.                          hitvalu = 8 + stmp->obj->spe;
  126.                          if (bigmonst(youmonst.data))
  127.                              hitvalu++;
  128.                          hitu = thitu(hitvalu, dmgval(stmp->obj, &youmonst),
  129.                                       &stmp->obj, (char *) 0);
  130.                          if (!stmp->obj)
  131.                              stmp->stopped = TRUE;
  132.                          if (hitu) {
  133.                              stmp->range -= 3;
  134.                              stop_occupation();
  135.                          }
  136.                      }
  137.                  } else {
  138.                      if (scflags & VIS_EFFECTS) {
  139.                          /* tmp_at(bhitpos.x, bhitpos.y); */
  140.                          /* delay_output(); */
  141.                      }
  142.                  }
  143.                  stmp->ox = bhitpos.x;
  144.                  stmp->oy = bhitpos.y;
  145.              }
  146.          }
  147.      }
  148.      for (stmp = schain; stmp; stmp = stmp2) {
  149.          int x, y;
  150.  
  151.          stmp2 = stmp->next;
  152.          x = stmp->ox;
  153.          y = stmp->oy;
  154.          if (stmp->obj) {
  155.              if (x != sx || y != sy)
  156.                  total += stmp->obj->quan;
  157.              place_object(stmp->obj, x, y);
  158.              stackobj(stmp->obj);
  159.          }
  160.          free((genericptr_t) stmp);
  161.          newsym(x, y);
  162.      }
  163.  
  164.      return total;
  165.  }
  166.  

splatter_burning_oil

  1.  /*
  2.   * Splatter burning oil from x,y to the surrounding area.
  3.   *
  4.   * This routine should really take a how and direction parameters.
  5.   * The how is how it was caused, e.g. kicked verses thrown.  The
  6.   * direction is which way to spread the flaming oil.  Different
  7.   * "how"s would give different dispersal patterns.  For example,
  8.   * kicking a burning flask will splatter differently from a thrown
  9.   * flask hitting the ground.
  10.   *
  11.   * For now, just perform a "regular" explosion.
  12.   */
  13.  void
  14.  splatter_burning_oil(x, y)
  15.  int x, y;
  16.  {
  17.  /* ZT_SPELL(ZT_FIRE) = ZT_SPELL(AD_FIRE-1) = 10+(2-1) = 11 */
  18.  #define ZT_SPELL_O_FIRE 11 /* value kludge, see zap.c */
  19.      explode(x, y, ZT_SPELL_O_FIRE, d(4, 4), BURNING_OIL, EXPL_FIERY);
  20.  }
  21.  

explode_oil

  1.  /* lit potion of oil is exploding; extinguish it as a light source before
  2.     possibly killing the hero and attempting to save bones */
  3.  void
  4.  explode_oil(obj, x, y)
  5.  struct obj *obj;
  6.  int x, y;
  7.  {
  8.      if (!obj->lamplit)
  9.          impossible("exploding unlit oil");
  10.      end_burn(obj, TRUE);
  11.      splatter_burning_oil(x, y);
  12.  }
  13.  
  14.  /*explode.c*/