Source:NetHack 3.6.0/src/explode.c

From NetHackWiki
Jump to: navigation, search

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

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.

Top of file

  1.  /* NetHack 3.6	explode.c	$NHDT-Date: 1446955298 2015/11/08 04:01:38 $  $NHDT-Branch: master $:$NHDT-Revision: 1.44 $ */
  2.  /*      Copyright (C) 1990 by Ken Arromdee */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  
  7.  /* Note: Arrays are column first, while the screen is row first */
  8.  static int explosion[3][3] = { { S_explode1, S_explode4, S_explode7 },
  9.                                 { S_explode2, S_explode5, S_explode8 },
  10.                                 { S_explode3, S_explode6, S_explode9 } };
  11.  

explode

  1.  /* Note: I had to choose one of three possible kinds of "type" when writing
  2.   * this function: a wand type (like in zap.c), an adtyp, or an object type.
  3.   * Wand types get complex because they must be converted to adtyps for
  4.   * determining such things as fire resistance.  Adtyps get complex in that
  5.   * they don't supply enough information--was it a player or a monster that
  6.   * did it, and with a wand, spell, or breath weapon?  Object types share both
  7.   * these disadvantages....
  8.   *
  9.   * Important note about Half_physical_damage:
  10.   *      Unlike losehp(), explode() makes the Half_physical_damage adjustments
  11.   *      itself, so the caller should never have done that ahead of time.
  12.   *      It has to be done this way because the damage value is applied to
  13.   *      things beside the player. Care is taken within explode() to ensure
  14.   *      that Half_physical_damage only affects the damage applied to the hero.
  15.   */
  16.  void
  17.  explode(x, y, type, dam, olet, expltype)
  18.  int x, y;
  19.  int type; /* the same as in zap.c; passes -(wand typ) for some WAND_CLASS */
  20.  int dam;
  21.  char olet;
  22.  int expltype;
  23.  {
  24.      int i, j, k, damu = dam;
  25.      boolean starting = 1;
  26.      boolean visible, any_shield;
  27.      int uhurt = 0; /* 0=unhurt, 1=items damaged, 2=you and items damaged */
  28.      const char *str = (const char *) 0;
  29.      int idamres, idamnonres;
  30.      struct monst *mtmp, *mdef = 0;
  31.      uchar adtyp;
  32.      int explmask[3][3];
  33.      /* 0=normal explosion, 1=do shieldeff, 2=do nothing */
  34.      boolean shopdamage = FALSE, generic = FALSE, physical_dmg = FALSE,
  35.              do_hallu = FALSE, inside_engulfer;
  36.      char hallu_buf[BUFSZ];
  37.      short exploding_wand_typ = 0;
  38.  
  39.      if (olet == WAND_CLASS) { /* retributive strike */
  40.          /* 'type' is passed as (wand's object type * -1); save
  41.             object type and convert 'type' itself to zap-type */
  42.          if (type < 0) {
  43.              type = -type;
  44.              exploding_wand_typ = (short) type;
  45.              /* most attack wands produce specific explosions;
  46.                 other types produce a generic magical explosion */
  47.              if (objects[type].oc_dir == RAY
  48.                  && type != WAN_DIGGING && type != WAN_SLEEP) {
  49.                  type -= WAN_MAGIC_MISSILE;
  50.                  if (type < 0 || type > 9) {
  51.                      impossible("explode: wand has bad zap type (%d).", type);
  52.                      type = 0;
  53.                  }
  54.              } else
  55.                  type = 0;
  56.          }
  57.          switch (Role_switch) {
  58.          case PM_PRIEST:
  59.          case PM_MONK:
  60.          case PM_WIZARD:
  61.              damu /= 5;
  62.              break;
  63.          case PM_HEALER:
  64.          case PM_KNIGHT:
  65.              damu /= 2;
  66.              break;
  67.          default:
  68.              break;
  69.          }
  70.      }
  71.      /* muse_unslime: SCR_FIRE */
  72.      if (expltype < 0) {
  73.          /* hero gets credit/blame for killing this monster, not others */
  74.          mdef = m_at(x, y);
  75.          expltype = -expltype;
  76.      }
  77.      /* if hero is engulfed and caused the explosion, only hero and
  78.         engulfer will be affected */
  79.      inside_engulfer = (u.uswallow && type >= 0);
  80.  
  81.      if (olet == MON_EXPLODE) {
  82.          str = killer.name;
  83.          do_hallu = Hallucination && strstri(str, "'s explosion");
  84.          adtyp = AD_PHYS;
  85.      } else
  86.          switch (abs(type) % 10) {
  87.          case 0:
  88.              str = "magical blast";
  89.              adtyp = AD_MAGM;
  90.              break;
  91.          case 1:
  92.              str = (olet == BURNING_OIL) ? "burning oil"
  93.                       : (olet == SCROLL_CLASS) ? "tower of flame" : "fireball";
  94.              /* fire damage, not physical damage */
  95.              adtyp = AD_FIRE;
  96.              break;
  97.          case 2:
  98.              str = "ball of cold";
  99.              adtyp = AD_COLD;
  100.              break;
  101.          case 4:
  102.              str = (olet == WAND_CLASS) ? "death field"
  103.                                         : "disintegration field";
  104.              adtyp = AD_DISN;
  105.              break;
  106.          case 5:
  107.              str = "ball of lightning";
  108.              adtyp = AD_ELEC;
  109.              break;
  110.          case 6:
  111.              str = "poison gas cloud";
  112.              adtyp = AD_DRST;
  113.              break;
  114.          case 7:
  115.              str = "splash of acid";
  116.              adtyp = AD_ACID;
  117.              break;
  118.          default:
  119.              impossible("explosion base type %d?", type);
  120.              return;
  121.          }
  122.  
  123.      any_shield = visible = FALSE;
  124.      for (i = 0; i < 3; i++)
  125.          for (j = 0; j < 3; j++) {
  126.              if (!isok(i + x - 1, j + y - 1)) {
  127.                  explmask[i][j] = 2;
  128.                  continue;
  129.              } else
  130.                  explmask[i][j] = 0;
  131.  
  132.              if (i + x - 1 == u.ux && j + y - 1 == u.uy) {
  133.                  switch (adtyp) {
  134.                  case AD_PHYS:
  135.                      explmask[i][j] = 0;
  136.                      break;
  137.                  case AD_MAGM:
  138.                      explmask[i][j] = !!Antimagic;
  139.                      break;
  140.                  case AD_FIRE:
  141.                      explmask[i][j] = !!Fire_resistance;
  142.                      break;
  143.                  case AD_COLD:
  144.                      explmask[i][j] = !!Cold_resistance;
  145.                      break;
  146.                  case AD_DISN:
  147.                      explmask[i][j] = (olet == WAND_CLASS)
  148.                                           ? !!(nonliving(youmonst.data)
  149.                                                || is_demon(youmonst.data))
  150.                                           : !!Disint_resistance;
  151.                      break;
  152.                  case AD_ELEC:
  153.                      explmask[i][j] = !!Shock_resistance;
  154.                      break;
  155.                  case AD_DRST:
  156.                      explmask[i][j] = !!Poison_resistance;
  157.                      break;
  158.                  case AD_ACID:
  159.                      explmask[i][j] = !!Acid_resistance;
  160.                      physical_dmg = TRUE;
  161.                      break;
  162.                  default:
  163.                      impossible("explosion type %d?", adtyp);
  164.                      break;
  165.                  }
  166.              }
  167.              /* can be both you and mtmp if you're swallowed */
  168.              mtmp = m_at(i + x - 1, j + y - 1);
  169.              if (!mtmp && i + x - 1 == u.ux && j + y - 1 == u.uy)
  170.                  mtmp = u.usteed;
  171.              if (mtmp) {
  172.                  if (mtmp->mhp < 1)
  173.                      explmask[i][j] = 2;
  174.                  else
  175.                      switch (adtyp) {
  176.                      case AD_PHYS:
  177.                          break;
  178.                      case AD_MAGM:
  179.                          explmask[i][j] |= resists_magm(mtmp);
  180.                          break;
  181.                      case AD_FIRE:
  182.                          explmask[i][j] |= resists_fire(mtmp);
  183.                          break;
  184.                      case AD_COLD:
  185.                          explmask[i][j] |= resists_cold(mtmp);
  186.                          break;
  187.                      case AD_DISN:
  188.                          explmask[i][j] |= (olet == WAND_CLASS)
  189.                                                ? (nonliving(mtmp->data)
  190.                                                   || is_demon(mtmp->data)
  191.                                                   || is_vampshifter(mtmp))
  192.                                                : resists_disint(mtmp);
  193.                          break;
  194.                      case AD_ELEC:
  195.                          explmask[i][j] |= resists_elec(mtmp);
  196.                          break;
  197.                      case AD_DRST:
  198.                          explmask[i][j] |= resists_poison(mtmp);
  199.                          break;
  200.                      case AD_ACID:
  201.                          explmask[i][j] |= resists_acid(mtmp);
  202.                          break;
  203.                      default:
  204.                          impossible("explosion type %d?", adtyp);
  205.                          break;
  206.                      }
  207.              }
  208.              if (mtmp && cansee(i + x - 1, j + y - 1) && !canspotmon(mtmp))
  209.                  map_invisible(i + x - 1, j + y - 1);
  210.              else if (!mtmp && glyph_is_invisible(
  211.                                    levl[i + x - 1][j + y - 1].glyph)) {
  212.                  unmap_object(i + x - 1, j + y - 1);
  213.                  newsym(i + x - 1, j + y - 1);
  214.              }
  215.              if (cansee(i + x - 1, j + y - 1))
  216.                  visible = TRUE;
  217.              if (explmask[i][j] == 1)
  218.                  any_shield = TRUE;
  219.          }
  220.  
  221.      if (visible) {
  222.          /* Start the explosion */
  223.          for (i = 0; i < 3; i++)
  224.              for (j = 0; j < 3; j++) {
  225.                  if (explmask[i][j] == 2)
  226.                      continue;
  227.                  tmp_at(starting ? DISP_BEAM : DISP_CHANGE,
  228.                         explosion_to_glyph(expltype, explosion[i][j]));
  229.                  tmp_at(i + x - 1, j + y - 1);
  230.                  starting = 0;
  231.              }
  232.          curs_on_u(); /* will flush screen and output */
  233.  
  234.          if (any_shield && flags.sparkle) { /* simulate shield effect */
  235.              for (k = 0; k < SHIELD_COUNT; k++) {
  236.                  for (i = 0; i < 3; i++)
  237.                      for (j = 0; j < 3; j++) {
  238.                          if (explmask[i][j] == 1)
  239.                              /*
  240.                               * Bypass tmp_at() and send the shield glyphs
  241.                               * directly to the buffered screen.  tmp_at()
  242.                               * will clean up the location for us later.
  243.                               */
  244.                              show_glyph(i + x - 1, j + y - 1,
  245.                                         cmap_to_glyph(shield_static[k]));
  246.                      }
  247.                  curs_on_u(); /* will flush screen and output */
  248.                  delay_output();
  249.              }
  250.  
  251.              /* Cover last shield glyph with blast symbol. */
  252.              for (i = 0; i < 3; i++)
  253.                  for (j = 0; j < 3; j++) {
  254.                      if (explmask[i][j] == 1)
  255.                          show_glyph(
  256.                              i + x - 1, j + y - 1,
  257.                              explosion_to_glyph(expltype, explosion[i][j]));
  258.                  }
  259.  
  260.          } else { /* delay a little bit. */
  261.              delay_output();
  262.              delay_output();
  263.          }
  264.  
  265.          tmp_at(DISP_END, 0); /* clear the explosion */
  266.      } else {
  267.          if (olet == MON_EXPLODE) {
  268.              str = "explosion";
  269.              generic = TRUE;
  270.          }
  271.          if (!Deaf && olet != SCROLL_CLASS)
  272.              You_hear("a blast.");
  273.      }
  274.  
  275.      if (dam)
  276.          for (i = 0; i < 3; i++)
  277.              for (j = 0; j < 3; j++) {
  278.                  if (explmask[i][j] == 2)
  279.                      continue;
  280.                  if (i + x - 1 == u.ux && j + y - 1 == u.uy)
  281.                      uhurt = (explmask[i][j] == 1) ? 1 : 2;
  282.                  /* for inside_engulfer, only <u.ux,u.uy> is affected */
  283.                  else if (inside_engulfer)
  284.                      continue;
  285.                  idamres = idamnonres = 0;
  286.                  if (type >= 0 && !u.uswallow)
  287.                      (void) zap_over_floor((xchar) (i + x - 1),
  288.                                            (xchar) (j + y - 1), type,
  289.                                            &shopdamage, exploding_wand_typ);
  290.  
  291.                  mtmp = m_at(i + x - 1, j + y - 1);
  292.                  if (!mtmp && i + x - 1 == u.ux && j + y - 1 == u.uy)
  293.                      mtmp = u.usteed;
  294.                  if (!mtmp)
  295.                      continue;
  296.                  if (do_hallu) {
  297.                      /* replace "gas spore" with a different description
  298.                         for each target (we can't distinguish personal names
  299.                         like "Barney" here in order to suppress "the" below,
  300.                         so avoid any which begins with a capital letter) */
  301.                      do {
  302.                          Sprintf(hallu_buf, "%s explosion",
  303.                                  s_suffix(rndmonnam(NULL)));
  304.                      } while (*hallu_buf != lowc(*hallu_buf));
  305.                      str = hallu_buf;
  306.                  }
  307.                  if (u.uswallow && mtmp == u.ustuck) {
  308.                      const char *adj = NULL;
  309.                      if (is_animal(u.ustuck->data)) {
  310.                          switch (adtyp) {
  311.                          case AD_FIRE:
  312.                              adj = "heartburn";
  313.                              break;
  314.                          case AD_COLD:
  315.                              adj = "chilly";
  316.                              break;
  317.                          case AD_DISN:
  318.                              if (olet == WAND_CLASS)
  319.                                  adj = "irradiated by pure energy";
  320.                              else
  321.                                  adj = "perforated";
  322.                              break;
  323.                          case AD_ELEC:
  324.                              adj = "shocked";
  325.                              break;
  326.                          case AD_DRST:
  327.                              adj = "poisoned";
  328.                              break;
  329.                          case AD_ACID:
  330.                              adj = "an upset stomach";
  331.                              break;
  332.                          default:
  333.                              adj = "fried";
  334.                              break;
  335.                          }
  336.                          pline("%s gets %s!", Monnam(u.ustuck), adj);
  337.                      } else {
  338.                          switch (adtyp) {
  339.                          case AD_FIRE:
  340.                              adj = "toasted";
  341.                              break;
  342.                          case AD_COLD:
  343.                              adj = "chilly";
  344.                              break;
  345.                          case AD_DISN:
  346.                              if (olet == WAND_CLASS)
  347.                                  adj = "overwhelmed by pure energy";
  348.                              else
  349.                                  adj = "perforated";
  350.                              break;
  351.                          case AD_ELEC:
  352.                              adj = "shocked";
  353.                              break;
  354.                          case AD_DRST:
  355.                              adj = "intoxicated";
  356.                              break;
  357.                          case AD_ACID:
  358.                              adj = "burned";
  359.                              break;
  360.                          default:
  361.                              adj = "fried";
  362.                              break;
  363.                          }
  364.                          pline("%s gets slightly %s!", Monnam(u.ustuck), adj);
  365.                      }
  366.                  } else if (cansee(i + x - 1, j + y - 1)) {
  367.                      if (mtmp->m_ap_type)
  368.                          seemimic(mtmp);
  369.                      pline("%s is caught in the %s!", Monnam(mtmp), str);
  370.                  }
  371.  
  372.                  idamres += destroy_mitem(mtmp, SCROLL_CLASS, (int) adtyp);
  373.                  idamres += destroy_mitem(mtmp, SPBOOK_CLASS, (int) adtyp);
  374.                  idamnonres += destroy_mitem(mtmp, POTION_CLASS, (int) adtyp);
  375.                  idamnonres += destroy_mitem(mtmp, WAND_CLASS, (int) adtyp);
  376.                  idamnonres += destroy_mitem(mtmp, RING_CLASS, (int) adtyp);
  377.  
  378.                  if (explmask[i][j] == 1) {
  379.                      golemeffects(mtmp, (int) adtyp, dam + idamres);
  380.                      mtmp->mhp -= idamnonres;
  381.                  } else {
  382.                      /* call resist with 0 and do damage manually so 1) we can
  383.                       * get out the message before doing the damage, and 2) we
  384.                       * can
  385.                       * call mondied, not killed, if it's not your blast
  386.                       */
  387.                      int mdam = dam;
  388.  
  389.                      if (resist(mtmp, olet, 0, FALSE)) {
  390.                          /* inside_engulfer: <i+x-1,j+y-1> == <u.ux,u.uy> */
  391.                          if (cansee(i + x - 1, j + y - 1) || inside_engulfer)
  392.                              pline("%s resists the %s!", Monnam(mtmp), str);
  393.                          mdam = (dam + 1) / 2;
  394.                      }
  395.                      if (mtmp == u.ustuck)
  396.                          mdam *= 2;
  397.                      if (resists_cold(mtmp) && adtyp == AD_FIRE)
  398.                          mdam *= 2;
  399.                      else if (resists_fire(mtmp) && adtyp == AD_COLD)
  400.                          mdam *= 2;
  401.                      mtmp->mhp -= mdam;
  402.                      mtmp->mhp -= (idamres + idamnonres);
  403.                  }
  404.                  if (mtmp->mhp <= 0) {
  405.                      if (mdef ? (mtmp == mdef) : !context.mon_moving)
  406.                          killed(mtmp);
  407.                      else
  408.                          monkilled(mtmp, "", (int) adtyp);
  409.                  } else if (!context.mon_moving) {
  410.                      /* all affected monsters, even if mdef is set */
  411.                      setmangry(mtmp);
  412.                  }
  413.              }
  414.  
  415.      /* Do your injury last */
  416.      if (uhurt) {
  417.          /* give message for any monster-induced explosion
  418.             or player-induced one other than scroll of fire */
  419.          if (flags.verbose && (type < 0 || olet != SCROLL_CLASS)) {
  420.              if (do_hallu) { /* (see explanation above) */
  421.                  do {
  422.                      Sprintf(hallu_buf, "%s explosion",
  423.                              s_suffix(rndmonnam(NULL)));
  424.                  } while (*hallu_buf != lowc(*hallu_buf));
  425.                  str = hallu_buf;
  426.              }
  427.              You("are caught in the %s!", str);
  428.              iflags.last_msg = PLNMSG_CAUGHT_IN_EXPLOSION;
  429.          }
  430.          /* do property damage first, in case we end up leaving bones */
  431.          if (adtyp == AD_FIRE)
  432.              burn_away_slime();
  433.          if (Invulnerable) {
  434.              damu = 0;
  435.              You("are unharmed!");
  436.          } else if (adtyp == AD_PHYS || physical_dmg)
  437.              damu = Maybe_Half_Phys(damu);
  438.          if (adtyp == AD_FIRE)
  439.              (void) burnarmor(&youmonst);
  440.          destroy_item(SCROLL_CLASS, (int) adtyp);
  441.          destroy_item(SPBOOK_CLASS, (int) adtyp);
  442.          destroy_item(POTION_CLASS, (int) adtyp);
  443.          destroy_item(RING_CLASS, (int) adtyp);
  444.          destroy_item(WAND_CLASS, (int) adtyp);
  445.  
  446.          ugolemeffects((int) adtyp, damu);
  447.          if (uhurt == 2) {
  448.              if (Upolyd)
  449.                  u.mh -= damu;
  450.              else
  451.                  u.uhp -= damu;
  452.              context.botl = 1;
  453.          }
  454.  
  455.          if (u.uhp <= 0 || (Upolyd && u.mh <= 0)) {
  456.              if (Upolyd) {
  457.                  rehumanize();
  458.              } else {
  459.                  if (olet == MON_EXPLODE) {
  460.                      /* killer handled by caller */
  461.                      if (generic)
  462.                          killer.name[0] = 0;
  463.                      else if (str != killer.name && str != hallu_buf)
  464.                          Strcpy(killer.name, str);
  465.                      killer.format = KILLED_BY_AN;
  466.                  } else if (type >= 0 && olet != SCROLL_CLASS) {
  467.                      killer.format = NO_KILLER_PREFIX;
  468.                      Sprintf(killer.name, "caught %sself in %s own %s", uhim(),
  469.                              uhis(), str);
  470.                  } else {
  471.                      killer.format = (!strcmpi(str, "tower of flame")
  472.                                       || !strcmpi(str, "fireball"))
  473.                                          ? KILLED_BY_AN
  474.                                          : KILLED_BY;
  475.                      Strcpy(killer.name, str);
  476.                  }
  477.                  if (iflags.last_msg == PLNMSG_CAUGHT_IN_EXPLOSION
  478.                      || iflags.last_msg
  479.                             == PLNMSG_TOWER_OF_FLAME) /*seffects()*/
  480.                      pline("It is fatal.");
  481.                  else
  482.                      pline_The("%s is fatal.", str);
  483.                  /* Known BUG: BURNING suppresses corpse in bones data,
  484.                     but done does not handle killer reason correctly */
  485.                  done((adtyp == AD_FIRE) ? BURNING : DIED);
  486.              }
  487.          }
  488.          exercise(A_STR, FALSE);
  489.      }
  490.  
  491.      if (shopdamage) {
  492.          pay_for_damage(adtyp == AD_FIRE
  493.                             ? "burn away"
  494.                             : adtyp == AD_COLD
  495.                                   ? "shatter"
  496.                                   : adtyp == AD_DISN ? "disintegrate"
  497.                                                      : "destroy",
  498.                         FALSE);
  499.      }
  500.  
  501.      /* explosions are noisy */
  502.      i = dam * dam;
  503.      if (i < 50)
  504.          i = 50; /* in case random damage is very small */
  505.      if (inside_engulfer)
  506.          i = (i + 3) / 4;
  507.      wake_nearto(x, y, i);
  508.  }
  509.  

scatter

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

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*/