Source:NetHack 3.6.1/src/dbridge.c

From NetHackWiki
(Redirected from Source:Ref/is db wall)
Jump to: navigation, search

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

Top of file

  1.  /* NetHack 3.6	dbridge.c	$NHDT-Date: 1503355815 2017/08/21 22:50:15 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.39 $ */
  2.  /*      Copyright (c) 1989 by Jean-Christophe Collet              */
  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.  /*
  3.   * This file contains the drawbridge manipulation (create, open, close,
  4.   * destroy).
  5.   *
  6.   * Added comprehensive monster-handling, and the "entity" structure to
  7.   * deal with players as well. - 11/89
  8.   *
  9.   * Any traps and/or engravings at either the portcullis or span location
  10.   * are destroyed whenever the bridge is lowered, raised, or destroyed.
  11.   * (Engraving handling could be extended to flag whether an engraving on
  12.   * the DB_UNDER surface is hidden by the lowered bridge, or one on the
  13.   * bridge itself is hidden because the bridge has been raised, but that
  14.   * seems like an awful lot of effort for very little gain.)
  15.   */
  16.  
  17.  #include "hack.h"
  18.  
  19.  STATIC_DCL void FDECL(get_wall_for_db, (int *, int *));
  20.  STATIC_DCL struct entity *FDECL(e_at, (int, int));
  21.  STATIC_DCL void FDECL(m_to_e, (struct monst *, int, int, struct entity *));
  22.  STATIC_DCL void FDECL(u_to_e, (struct entity *));
  23.  STATIC_DCL void FDECL(set_entity, (int, int, struct entity *));
  24.  STATIC_DCL const char *FDECL(e_nam, (struct entity *));
  25.  STATIC_DCL const char *FDECL(E_phrase, (struct entity *, const char *));
  26.  STATIC_DCL boolean FDECL(e_survives_at, (struct entity *, int, int));
  27.  STATIC_DCL void FDECL(e_died, (struct entity *, int, int));
  28.  STATIC_DCL boolean FDECL(automiss, (struct entity *));
  29.  STATIC_DCL boolean FDECL(e_missed, (struct entity *, BOOLEAN_P));
  30.  STATIC_DCL boolean FDECL(e_jumps, (struct entity *));
  31.  STATIC_DCL void FDECL(do_entity, (struct entity *));
  32.  

is_pool

  1.  boolean
  2.  is_pool(x, y)
  3.  int x, y;
  4.  {
  5.      schar ltyp;
  6.  
  7.      if (!isok(x, y))
  8.          return FALSE;
  9.      ltyp = levl[x][y].typ;
  10.      /* The ltyp == MOAT is not redundant with is_moat, because the
  11.       * Juiblex level does not have moats, although it has MOATs. There
  12.       * is probably a better way to express this. */
  13.      if (ltyp == POOL || ltyp == MOAT || ltyp == WATER || is_moat(x, y))
  14.          return TRUE;
  15.      return FALSE;
  16.  }
  17.  

is_lava

  1.  boolean
  2.  is_lava(x, y)
  3.  int x, y;
  4.  {
  5.      schar ltyp;
  6.  
  7.      if (!isok(x, y))
  8.          return FALSE;
  9.      ltyp = levl[x][y].typ;
  10.      if (ltyp == LAVAPOOL
  11.          || (ltyp == DRAWBRIDGE_UP
  12.              && (levl[x][y].drawbridgemask & DB_UNDER) == DB_LAVA))
  13.          return TRUE;
  14.      return FALSE;
  15.  }
  16.  

is_pool_or_lava

  1.  boolean
  2.  is_pool_or_lava(x, y)
  3.  int x, y;
  4.  {
  5.      if (is_pool(x, y) || is_lava(x, y))
  6.          return TRUE;
  7.      else
  8.          return FALSE;
  9.  }
  10.  

is_ice

  1.  boolean
  2.  is_ice(x, y)
  3.  int x, y;
  4.  {
  5.      schar ltyp;
  6.  
  7.      if (!isok(x, y))
  8.          return FALSE;
  9.      ltyp = levl[x][y].typ;
  10.      if (ltyp == ICE || (ltyp == DRAWBRIDGE_UP
  11.                          && (levl[x][y].drawbridgemask & DB_UNDER) == DB_ICE))
  12.          return TRUE;
  13.      return FALSE;
  14.  }
  15.  

is_moat

  1.  boolean
  2.  is_moat(x, y)
  3.  int x, y;
  4.  {
  5.      schar ltyp;
  6.  
  7.      if (!isok(x, y))
  8.          return FALSE;
  9.      ltyp = levl[x][y].typ;
  10.      if (!Is_juiblex_level(&u.uz)
  11.          && (ltyp == MOAT
  12.              || (ltyp == DRAWBRIDGE_UP
  13.                  && (levl[x][y].drawbridgemask & DB_UNDER) == DB_MOAT)))
  14.          return TRUE;
  15.      return FALSE;
  16.  }
  17.  

db_under_typ

  1.  schar
  2.  db_under_typ(mask)
  3.  int mask;
  4.  {
  5.      switch (mask & DB_UNDER) {
  6.      case DB_ICE:
  7.          return ICE;
  8.      case DB_LAVA:
  9.          return LAVAPOOL;
  10.      case DB_MOAT:
  11.          return MOAT;
  12.      default:
  13.          return STONE;
  14.      }
  15.  }
  16.  

is_drawbridge_wall

  1.  /*
  2.   * We want to know whether a wall (or a door) is the portcullis (passageway)
  3.   * of an eventual drawbridge.
  4.   *
  5.   * Return value:  the direction of the drawbridge.
  6.   */
  7.  
  8.  int
  9.  is_drawbridge_wall(x, y)
  10.  int x, y;
  11.  {
  12.      struct rm *lev;
  13.  
  14.      lev = &levl[x][y];
  15.      if (lev->typ != DOOR && lev->typ != DBWALL)
  16.          return -1;
  17.  
  18.      if (IS_DRAWBRIDGE(levl[x + 1][y].typ)
  19.          && (levl[x + 1][y].drawbridgemask & DB_DIR) == DB_WEST)
  20.          return DB_WEST;
  21.      if (IS_DRAWBRIDGE(levl[x - 1][y].typ)
  22.          && (levl[x - 1][y].drawbridgemask & DB_DIR) == DB_EAST)
  23.          return DB_EAST;
  24.      if (IS_DRAWBRIDGE(levl[x][y - 1].typ)
  25.          && (levl[x][y - 1].drawbridgemask & DB_DIR) == DB_SOUTH)
  26.          return DB_SOUTH;
  27.      if (IS_DRAWBRIDGE(levl[x][y + 1].typ)
  28.          && (levl[x][y + 1].drawbridgemask & DB_DIR) == DB_NORTH)
  29.          return DB_NORTH;
  30.  
  31.      return -1;
  32.  }
  33.  

is_db_wall

  1.  /*
  2.   * Use is_db_wall where you want to verify that a
  3.   * drawbridge "wall" is UP in the location x, y
  4.   * (instead of UP or DOWN, as with is_drawbridge_wall).
  5.   */
  6.  boolean
  7.  is_db_wall(x, y)
  8.  int x, y;
  9.  {
  10.      return (boolean) (levl[x][y].typ == DBWALL);
  11.  }
  12.  

find_drawbridge

  1.  /*
  2.   * Return true with x,y pointing to the drawbridge if x,y initially indicate
  3.   * a drawbridge or drawbridge wall.
  4.   */
  5.  boolean
  6.  find_drawbridge(x, y)
  7.  int *x, *y;
  8.  {
  9.      int dir;
  10.  
  11.      if (IS_DRAWBRIDGE(levl[*x][*y].typ))
  12.          return TRUE;
  13.      dir = is_drawbridge_wall(*x, *y);
  14.      if (dir >= 0) {
  15.          switch (dir) {
  16.          case DB_NORTH:
  17.              (*y)++;
  18.              break;
  19.          case DB_SOUTH:
  20.              (*y)--;
  21.              break;
  22.          case DB_EAST:
  23.              (*x)--;
  24.              break;
  25.          case DB_WEST:
  26.              (*x)++;
  27.              break;
  28.          }
  29.          return TRUE;
  30.      }
  31.      return FALSE;
  32.  }
  33.  

get_wall_for_db

  1.  /*
  2.   * Find the drawbridge wall associated with a drawbridge.
  3.   */
  4.  STATIC_OVL void
  5.  get_wall_for_db(x, y)
  6.  int *x, *y;
  7.  {
  8.      switch (levl[*x][*y].drawbridgemask & DB_DIR) {
  9.      case DB_NORTH:
  10.          (*y)--;
  11.          break;
  12.      case DB_SOUTH:
  13.          (*y)++;
  14.          break;
  15.      case DB_EAST:
  16.          (*x)++;
  17.          break;
  18.      case DB_WEST:
  19.          (*x)--;
  20.          break;
  21.      }
  22.  }
  23.  

create_drawbridge

  1.  /*
  2.   * Creation of a drawbridge at pos x,y.
  3.   *     dir is the direction.
  4.   *     flag must be put to TRUE if we want the drawbridge to be opened.
  5.   */
  6.  boolean
  7.  create_drawbridge(x, y, dir, flag)
  8.  int x, y, dir;
  9.  boolean flag;
  10.  {
  11.      int x2, y2;
  12.      boolean horiz;
  13.      boolean lava = levl[x][y].typ == LAVAPOOL; /* assume initialized map */
  14.  
  15.      x2 = x;
  16.      y2 = y;
  17.      switch (dir) {
  18.      case DB_NORTH:
  19.          horiz = TRUE;
  20.          y2--;
  21.          break;
  22.      case DB_SOUTH:
  23.          horiz = TRUE;
  24.          y2++;
  25.          break;
  26.      case DB_EAST:
  27.          horiz = FALSE;
  28.          x2++;
  29.          break;
  30.      default:
  31.          impossible("bad direction in create_drawbridge");
  32.          /*FALLTHRU*/
  33.      case DB_WEST:
  34.          horiz = FALSE;
  35.          x2--;
  36.          break;
  37.      }
  38.      if (!IS_WALL(levl[x2][y2].typ))
  39.          return FALSE;
  40.      if (flag) { /* We want the bridge open */
  41.          levl[x][y].typ = DRAWBRIDGE_DOWN;
  42.          levl[x2][y2].typ = DOOR;
  43.          levl[x2][y2].doormask = D_NODOOR;
  44.      } else {
  45.          levl[x][y].typ = DRAWBRIDGE_UP;
  46.          levl[x2][y2].typ = DBWALL;
  47.          /* Drawbridges are non-diggable. */
  48.          levl[x2][y2].wall_info = W_NONDIGGABLE;
  49.      }
  50.      levl[x][y].horizontal = !horiz;
  51.      levl[x2][y2].horizontal = horiz;
  52.      levl[x][y].drawbridgemask = dir;
  53.      if (lava)
  54.          levl[x][y].drawbridgemask |= DB_LAVA;
  55.      return  TRUE;
  56.  }
  57.  
  58.  struct entity {
  59.      struct monst *emon;     /* youmonst for the player */
  60.      struct permonst *edata; /* must be non-zero for record to be valid */
  61.      int ex, ey;
  62.  };
  63.  
  64.  #define ENTITIES 2
  65.  
  66.  static NEARDATA struct entity occupants[ENTITIES];
  67.  

e_at

  1.  STATIC_OVL
  2.  struct entity *
  3.  e_at(x, y)
  4.  int x, y;
  5.  {
  6.      int entitycnt;
  7.  
  8.      for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++)
  9.          if ((occupants[entitycnt].edata) && (occupants[entitycnt].ex == x)
  10.              && (occupants[entitycnt].ey == y))
  11.              break;
  12.      debugpline1("entitycnt = %d", entitycnt);
  13.  #ifdef D_DEBUG
  14.      wait_synch();
  15.  #endif
  16.      return (entitycnt == ENTITIES) ? (struct entity *) 0
  17.                                     : &(occupants[entitycnt]);
  18.  }
  19.  

m_to_e

  1.  STATIC_OVL void
  2.  m_to_e(mtmp, x, y, etmp)
  3.  struct monst *mtmp;
  4.  int x, y;
  5.  struct entity *etmp;
  6.  {
  7.      etmp->emon = mtmp;
  8.      if (mtmp) {
  9.          etmp->ex = x;
  10.          etmp->ey = y;
  11.          if (mtmp->wormno && (x != mtmp->mx || y != mtmp->my))
  12.              etmp->edata = &mons[PM_LONG_WORM_TAIL];
  13.          else
  14.              etmp->edata = mtmp->data;
  15.      } else
  16.          etmp->edata = (struct permonst *) 0;
  17.  }
  18.  

u_to_e

  1.  STATIC_OVL void
  2.  u_to_e(etmp)
  3.  struct entity *etmp;
  4.  {
  5.      etmp->emon = &youmonst;
  6.      etmp->ex = u.ux;
  7.      etmp->ey = u.uy;
  8.      etmp->edata = youmonst.data;
  9.  }

set_entity

  1.  
  2.  STATIC_OVL void
  3.  set_entity(x, y, etmp)
  4.  int x, y;
  5.  struct entity *etmp;
  6.  {
  7.      if ((x == u.ux) && (y == u.uy))
  8.          u_to_e(etmp);
  9.      else if (MON_AT(x, y))
  10.          m_to_e(m_at(x, y), x, y, etmp);
  11.      else
  12.          etmp->edata = (struct permonst *) 0;
  13.  }
  14.  
  15.  #define is_u(etmp) (etmp->emon == &youmonst)
  16.  #define e_canseemon(etmp) \
  17.      (is_u(etmp) ? (boolean) TRUE : canseemon(etmp->emon))
  18.  
  19.  /*
  20.   * e_strg is a utility routine which is not actually in use anywhere, since
  21.   * the specialized routines below suffice for all current purposes.
  22.   */
  23.  

e_nam

  1.  /* #define e_strg(etmp, func) (is_u(etmp)? (char *)0 : func(etmp->emon)) */
  2.  
  3.  STATIC_OVL const char *
  4.  e_nam(etmp)
  5.  struct entity *etmp;
  6.  {
  7.      return is_u(etmp) ? "you" : mon_nam(etmp->emon);
  8.  }
  9.  

E_phrase

  1.  /*
  2.   * Generates capitalized entity name, makes 2nd -> 3rd person conversion on
  3.   * verb, where necessary.
  4.   */
  5.  STATIC_OVL const char *
  6.  E_phrase(etmp, verb)
  7.  struct entity *etmp;
  8.  const char *verb;
  9.  {
  10.      static char wholebuf[80];
  11.  
  12.      Strcpy(wholebuf, is_u(etmp) ? "You" : Monnam(etmp->emon));
  13.      if (!verb || !*verb)
  14.          return wholebuf;
  15.      Strcat(wholebuf, " ");
  16.      if (is_u(etmp))
  17.          Strcat(wholebuf, verb);
  18.      else
  19.          Strcat(wholebuf, vtense((char *) 0, verb));
  20.      return wholebuf;
  21.  }
  22.  

e_survives_at

  1.  /*
  2.   * Simple-minded "can it be here?" routine
  3.   */
  4.  STATIC_OVL boolean
  5.  e_survives_at(etmp, x, y)
  6.  struct entity *etmp;
  7.  int x, y;
  8.  {
  9.      if (noncorporeal(etmp->edata))
  10.          return TRUE;
  11.      if (is_pool(x, y))
  12.          return (boolean) ((is_u(etmp) && (Wwalking || Amphibious || Swimming
  13.                                            || Flying || Levitation))
  14.                            || is_swimmer(etmp->edata)
  15.                            || is_flyer(etmp->edata)
  16.                            || is_floater(etmp->edata));
  17.      /* must force call to lava_effects in e_died if is_u */
  18.      if (is_lava(x, y))
  19.          return (boolean) ((is_u(etmp) && (Levitation || Flying))
  20.                            || likes_lava(etmp->edata)
  21.                            || is_flyer(etmp->edata));
  22.      if (is_db_wall(x, y))
  23.          return (boolean) (is_u(etmp) ? Passes_walls
  24.                            : passes_walls(etmp->edata));
  25.      return TRUE;
  26.  }
  27.  

e_died

  1.  STATIC_OVL void
  2.  e_died(etmp, xkill_flags, how)
  3.  struct entity *etmp;
  4.  int xkill_flags, how;
  5.  {
  6.      if (is_u(etmp)) {
  7.          if (how == DROWNING) {
  8.              killer.name[0] = 0; /* drown() sets its own killer */
  9.              (void) drown();
  10.          } else if (how == BURNING) {
  11.              killer.name[0] = 0; /* lava_effects() sets own killer */
  12.              (void) lava_effects();
  13.          } else {
  14.              coord xy;
  15.  
  16.              /* use more specific killer if specified */
  17.              if (!killer.name[0]) {
  18.                  killer.format = KILLED_BY_AN;
  19.                  Strcpy(killer.name, "falling drawbridge");
  20.              }
  21.              done(how);
  22.              /* So, you didn't die */
  23.              if (!e_survives_at(etmp, etmp->ex, etmp->ey)) {
  24.                  if (enexto(&xy, etmp->ex, etmp->ey, etmp->edata)) {
  25.                      pline("A %s force teleports you away...",
  26.                            Hallucination ? "normal" : "strange");
  27.                      teleds(xy.x, xy.y, FALSE);
  28.                  }
  29.                  /* otherwise on top of the drawbridge is the
  30.                   * only viable spot in the dungeon, so stay there
  31.                   */
  32.              }
  33.          }
  34.          /* we might have crawled out of the moat to survive */
  35.          etmp->ex = u.ux, etmp->ey = u.uy;
  36.      } else {
  37.          int entitycnt;
  38.  
  39.          killer.name[0] = 0;
  40.  /* fake "digested to death" damage-type suppresses corpse */
  41.  #define mk_message(dest) (((dest & XKILL_NOMSG) != 0) ? (char *) 0 : "")
  42.  #define mk_corpse(dest) (((dest & XKILL_NOCORPSE) != 0) ? AD_DGST : AD_PHYS)
  43.          /* if monsters are moving, one of them caused the destruction */
  44.          if (context.mon_moving)
  45.              monkilled(etmp->emon,
  46.                        mk_message(xkill_flags), mk_corpse(xkill_flags));
  47.          else /* you caused it */
  48.              xkilled(etmp->emon, xkill_flags);
  49.          etmp->edata = (struct permonst *) 0;
  50.  
  51.          /* dead long worm handling */
  52.          for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) {
  53.              if (etmp != &(occupants[entitycnt])
  54.                  && etmp->emon == occupants[entitycnt].emon)
  55.                  occupants[entitycnt].edata = (struct permonst *) 0;
  56.          }
  57.  #undef mk_message
  58.  #undef mk_corpse
  59.      }
  60.  }
  61.  

automiss

  1.  /*
  2.   * These are never directly affected by a bridge or portcullis.
  3.   */
  4.  STATIC_OVL boolean
  5.  automiss(etmp)
  6.  struct entity *etmp;
  7.  {
  8.      return (boolean) ((is_u(etmp) ? Passes_walls : passes_walls(etmp->edata))
  9.                        || noncorporeal(etmp->edata));
  10.  }
  11.  

e_missed

  1.  /*
  2.   * Does falling drawbridge or portcullis miss etmp?
  3.   */
  4.  STATIC_OVL boolean
  5.  e_missed(etmp, chunks)
  6.  struct entity *etmp;
  7.  boolean chunks;
  8.  {
  9.      int misses;
  10.  
  11.      if (chunks) {
  12.          debugpline0("Do chunks miss?");
  13.      }
  14.      if (automiss(etmp))
  15.          return TRUE;
  16.  
  17.      if (is_flyer(etmp->edata)
  18.          && (is_u(etmp) ? !Unaware
  19.                         : (etmp->emon->mcanmove && !etmp->emon->msleeping)))
  20.          /* flying requires mobility */
  21.          misses = 5; /* out of 8 */
  22.      else if (is_floater(etmp->edata)
  23.               || (is_u(etmp) && Levitation)) /* doesn't require mobility */
  24.          misses = 3;
  25.      else if (chunks && is_pool(etmp->ex, etmp->ey))
  26.          misses = 2; /* sitting ducks */
  27.      else
  28.          misses = 0;
  29.  
  30.      if (is_db_wall(etmp->ex, etmp->ey))
  31.          misses -= 3; /* less airspace */
  32.  
  33.      debugpline1("Miss chance = %d (out of 8)", misses);
  34.  
  35.      return (misses >= rnd(8)) ? TRUE : FALSE;
  36.  }
  37.  

e_jumps

  1.  /*
  2.   * Can etmp jump from death?
  3.   */
  4.  STATIC_OVL boolean
  5.  e_jumps(etmp)
  6.  struct entity *etmp;
  7.  {
  8.      int tmp = 4; /* out of 10 */
  9.  
  10.      if (is_u(etmp) ? (Unaware || Fumbling)
  11.                     : (!etmp->emon->mcanmove || etmp->emon->msleeping
  12.                        || !etmp->edata->mmove || etmp->emon->wormno))
  13.          return FALSE;
  14.  
  15.      if (is_u(etmp) ? Confusion : etmp->emon->mconf)
  16.          tmp -= 2;
  17.  
  18.      if (is_u(etmp) ? Stunned : etmp->emon->mstun)
  19.          tmp -= 3;
  20.  
  21.      if (is_db_wall(etmp->ex, etmp->ey))
  22.          tmp -= 2; /* less room to maneuver */
  23.  
  24.      debugpline2("%s to jump (%d chances in 10)", E_phrase(etmp, "try"), tmp);
  25.      return (tmp >= rnd(10)) ? TRUE : FALSE;
  26.  }
  27.  

do_entity

  1.  STATIC_OVL void
  2.  do_entity(etmp)
  3.  struct entity *etmp;
  4.  {
  5.      int newx, newy, at_portcullis, oldx, oldy;
  6.      boolean must_jump = FALSE, relocates = FALSE, e_inview;
  7.      struct rm *crm;
  8.  
  9.      if (!etmp->edata)
  10.          return;
  11.  
  12.      e_inview = e_canseemon(etmp);
  13.      oldx = etmp->ex;
  14.      oldy = etmp->ey;
  15.      at_portcullis = is_db_wall(oldx, oldy);
  16.      crm = &levl[oldx][oldy];
  17.  
  18.      if (automiss(etmp) && e_survives_at(etmp, oldx, oldy)) {
  19.          if (e_inview && (at_portcullis || IS_DRAWBRIDGE(crm->typ)))
  20.              pline_The("%s passes through %s!",
  21.                        at_portcullis ? "portcullis" : "drawbridge",
  22.                        e_nam(etmp));
  23.          if (is_u(etmp))
  24.              spoteffects(FALSE);
  25.          return;
  26.      }
  27.      if (e_missed(etmp, FALSE)) {
  28.          if (at_portcullis) {
  29.              pline_The("portcullis misses %s!", e_nam(etmp));
  30.          } else {
  31.              debugpline1("The drawbridge misses %s!", e_nam(etmp));
  32.          }
  33.          if (e_survives_at(etmp, oldx, oldy)) {
  34.              return;
  35.          } else {
  36.              debugpline0("Mon can't survive here");
  37.              if (at_portcullis)
  38.                  must_jump = TRUE;
  39.              else
  40.                  relocates = TRUE; /* just ride drawbridge in */
  41.          }
  42.      } else {
  43.          if (crm->typ == DRAWBRIDGE_DOWN) {
  44.              if (is_u(etmp)) {
  45.                  killer.format = NO_KILLER_PREFIX;
  46.                  Strcpy(killer.name,
  47.                         "crushed to death underneath a drawbridge");
  48.              }
  49.              pline("%s crushed underneath the drawbridge.",
  50.                    E_phrase(etmp, "are"));             /* no jump */
  51.              e_died(etmp,
  52.                     XKILL_NOCORPSE | (e_inview ? XKILL_GIVEMSG : XKILL_NOMSG),
  53.                     CRUSHING); /* no corpse */
  54.              return;       /* Note: Beyond this point, we know we're  */
  55.          }                 /* not at an opened drawbridge, since all  */
  56.          must_jump = TRUE; /* *missable* creatures survive on the     */
  57.      }                     /* square, and all the unmissed ones die.  */
  58.      if (must_jump) {
  59.          if (at_portcullis) {
  60.              if (e_jumps(etmp)) {
  61.                  relocates = TRUE;
  62.                  debugpline0("Jump succeeds!");
  63.              } else {
  64.                  if (e_inview)
  65.                      pline("%s crushed by the falling portcullis!",
  66.                            E_phrase(etmp, "are"));
  67.                  else if (!Deaf)
  68.                      You_hear("a crushing sound.");
  69.                  e_died(etmp,
  70.                         XKILL_NOCORPSE | (e_inview ? XKILL_GIVEMSG
  71.                                                    : XKILL_NOMSG),
  72.                         CRUSHING);
  73.                  /* no corpse */
  74.                  return;
  75.              }
  76.          } else { /* tries to jump off bridge to original square */
  77.              relocates = !e_jumps(etmp);
  78.              debugpline1("Jump %s!", (relocates) ? "fails" : "succeeds");
  79.          }
  80.      }
  81.  
  82.      /*
  83.       * Here's where we try to do relocation.  Assumes that etmp is not
  84.       * arriving at the portcullis square while the drawbridge is
  85.       * falling, since this square would be inaccessible (i.e. etmp
  86.       * started on drawbridge square) or unnecessary (i.e. etmp started
  87.       * here) in such a situation.
  88.       */
  89.      debugpline0("Doing relocation.");
  90.      newx = oldx;
  91.      newy = oldy;
  92.      (void) find_drawbridge(&newx, &newy);
  93.      if ((newx == oldx) && (newy == oldy))
  94.          get_wall_for_db(&newx, &newy);
  95.      debugpline0("Checking new square for occupancy.");
  96.      if (relocates && (e_at(newx, newy))) {
  97.          /*
  98.           * Standoff problem: one or both entities must die, and/or
  99.           * both switch places.  Avoid infinite recursion by checking
  100.           * first whether the other entity is staying put.  Clean up if
  101.           * we happen to move/die in recursion.
  102.           */
  103.          struct entity *other;
  104.  
  105.          other = e_at(newx, newy);
  106.          debugpline1("New square is occupied by %s", e_nam(other));
  107.          if (e_survives_at(other, newx, newy) && automiss(other)) {
  108.              relocates = FALSE; /* "other" won't budge */
  109.              debugpline1("%s suicide.", E_phrase(etmp, "commit"));
  110.          } else {
  111.              debugpline1("Handling %s", e_nam(other));
  112.              while ((e_at(newx, newy) != 0) && (e_at(newx, newy) != etmp))
  113.                  do_entity(other);
  114.              debugpline1("Checking existence of %s", e_nam(etmp));
  115.  #ifdef D_DEBUG
  116.              wait_synch();
  117.  #endif
  118.              if (e_at(oldx, oldy) != etmp) {
  119.                  debugpline1("%s moved or died in recursion somewhere",
  120.                              E_phrase(etmp, "have"));
  121.  #ifdef D_DEBUG
  122.                  wait_synch();
  123.  #endif
  124.                  return;
  125.              }
  126.          }
  127.      }
  128.      if (relocates && !e_at(newx, newy)) { /* if e_at() entity = worm tail */
  129.          debugpline1("Moving %s", e_nam(etmp));
  130.          if (!is_u(etmp)) {
  131.              remove_monster(etmp->ex, etmp->ey);
  132.              place_monster(etmp->emon, newx, newy);
  133.              update_monster_region(etmp->emon);
  134.          } else {
  135.              u.ux = newx;
  136.              u.uy = newy;
  137.          }
  138.          etmp->ex = newx;
  139.          etmp->ey = newy;
  140.          e_inview = e_canseemon(etmp);
  141.      }
  142.      debugpline1("Final disposition of %s", e_nam(etmp));
  143.  #ifdef D_DEBUG
  144.      wait_synch();
  145.  #endif
  146.      if (is_db_wall(etmp->ex, etmp->ey)) {
  147.          debugpline1("%s in portcullis chamber", E_phrase(etmp, "are"));
  148.  #ifdef D_DEBUG
  149.          wait_synch();
  150.  #endif
  151.          if (e_inview) {
  152.              if (is_u(etmp)) {
  153.                  You("tumble towards the closed portcullis!");
  154.                  if (automiss(etmp))
  155.                      You("pass through it!");
  156.                  else
  157.                      pline_The("drawbridge closes in...");
  158.              } else
  159.                  pline("%s behind the drawbridge.",
  160.                        E_phrase(etmp, "disappear"));
  161.          }
  162.          if (!e_survives_at(etmp, etmp->ex, etmp->ey)) {
  163.              killer.format = KILLED_BY_AN;
  164.              Strcpy(killer.name, "closing drawbridge");
  165.              e_died(etmp, XKILL_NOMSG, CRUSHING);
  166.              return;
  167.          }
  168.          debugpline1("%s in here", E_phrase(etmp, "survive"));
  169.      } else {
  170.          debugpline1("%s on drawbridge square", E_phrase(etmp, "are"));
  171.          if (is_pool(etmp->ex, etmp->ey) && !e_inview)
  172.              if (!Deaf)
  173.                  You_hear("a splash.");
  174.          if (e_survives_at(etmp, etmp->ex, etmp->ey)) {
  175.              if (e_inview && !is_flyer(etmp->edata)
  176.                  && !is_floater(etmp->edata))
  177.                  pline("%s from the bridge.", E_phrase(etmp, "fall"));
  178.              return;
  179.          }
  180.          debugpline1("%s cannot survive on the drawbridge square",
  181.                      E_phrase(etmp, NULL));
  182.          if (is_pool(etmp->ex, etmp->ey) || is_lava(etmp->ex, etmp->ey))
  183.              if (e_inview && !is_u(etmp)) {
  184.                  /* drown() will supply msgs if nec. */
  185.                  boolean lava = is_lava(etmp->ex, etmp->ey);
  186.  
  187.                  if (Hallucination)
  188.                      pline("%s the %s and disappears.",
  189.                            E_phrase(etmp, "drink"), lava ? "lava" : "moat");
  190.                  else
  191.                      pline("%s into the %s.", E_phrase(etmp, "fall"),
  192.                            lava ? hliquid("lava") : "moat");
  193.              }
  194.          killer.format = NO_KILLER_PREFIX;
  195.          Strcpy(killer.name, "fell from a drawbridge");
  196.          e_died(etmp, /* CRUSHING is arbitrary */
  197.                 XKILL_NOCORPSE | (e_inview ? XKILL_GIVEMSG : XKILL_NOMSG),
  198.                 is_pool(etmp->ex, etmp->ey) ? DROWNING
  199.                   : is_lava(etmp->ex, etmp->ey) ? BURNING
  200.                     : CRUSHING); /*no corpse*/
  201.          return;
  202.      }
  203.  }
  204.  
  205.  /* clear stale reason for death before returning */
  206.  #define nokiller() (killer.name[0] = '\0', killer.format = 0)
  207.  

close_drawbridge

  1.  /*
  2.   * Close the drawbridge located at x,y
  3.   */
  4.  void
  5.  close_drawbridge(x, y)
  6.  int x, y;
  7.  {
  8.      register struct rm *lev1, *lev2;
  9.      struct trap *t;
  10.      int x2, y2;
  11.  
  12.      lev1 = &levl[x][y];
  13.      if (lev1->typ != DRAWBRIDGE_DOWN)
  14.          return;
  15.      x2 = x;
  16.      y2 = y;
  17.      get_wall_for_db(&x2, &y2);
  18.      if (cansee(x, y) || cansee(x2, y2))
  19.          You_see("a drawbridge %s up!",
  20.                  (((u.ux == x || u.uy == y) && !Underwater)
  21.                   || distu(x2, y2) < distu(x, y))
  22.                      ? "coming"
  23.                      : "going");
  24.      else /* "5 gears turn" for castle drawbridge tune */
  25.          You_hear("chains rattling and gears turning.");
  26.      lev1->typ = DRAWBRIDGE_UP;
  27.      lev2 = &levl[x2][y2];
  28.      lev2->typ = DBWALL;
  29.      switch (lev1->drawbridgemask & DB_DIR) {
  30.      case DB_NORTH:
  31.      case DB_SOUTH:
  32.          lev2->horizontal = TRUE;
  33.          break;
  34.      case DB_WEST:
  35.      case DB_EAST:
  36.          lev2->horizontal = FALSE;
  37.          break;
  38.      }
  39.      lev2->wall_info = W_NONDIGGABLE;
  40.      set_entity(x, y, &(occupants[0]));
  41.      set_entity(x2, y2, &(occupants[1]));
  42.      do_entity(&(occupants[0]));          /* Do set_entity after first */
  43.      set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tail */
  44.      do_entity(&(occupants[1]));
  45.      if (OBJ_AT(x, y) && !Deaf)
  46.          You_hear("smashing and crushing.");
  47.      (void) revive_nasty(x, y, (char *) 0);
  48.      (void) revive_nasty(x2, y2, (char *) 0);
  49.      delallobj(x, y);
  50.      delallobj(x2, y2);
  51.      if ((t = t_at(x, y)) != 0)
  52.          deltrap(t);
  53.      if ((t = t_at(x2, y2)) != 0)
  54.          deltrap(t);
  55.      del_engr_at(x, y);
  56.      del_engr_at(x2, y2);
  57.      newsym(x, y);
  58.      newsym(x2, y2);
  59.      block_point(x2, y2); /* vision */
  60.      nokiller();
  61.  }
  62.  

open_drawbridge

  1.  /*
  2.   * Open the drawbridge located at x,y
  3.   */
  4.  void
  5.  open_drawbridge(x, y)
  6.  int x, y;
  7.  {
  8.      register struct rm *lev1, *lev2;
  9.      struct trap *t;
  10.      int x2, y2;
  11.  
  12.      lev1 = &levl[x][y];
  13.      if (lev1->typ != DRAWBRIDGE_UP)
  14.          return;
  15.      x2 = x;
  16.      y2 = y;
  17.      get_wall_for_db(&x2, &y2);
  18.      if (cansee(x, y) || cansee(x2, y2))
  19.          You_see("a drawbridge %s down!",
  20.                  (distu(x2, y2) < distu(x, y)) ? "going" : "coming");
  21.      else /* "5 gears turn" for castle drawbridge tune */
  22.          You_hear("gears turning and chains rattling.");
  23.      lev1->typ = DRAWBRIDGE_DOWN;
  24.      lev2 = &levl[x2][y2];
  25.      lev2->typ = DOOR;
  26.      lev2->doormask = D_NODOOR;
  27.      set_entity(x, y, &(occupants[0]));
  28.      set_entity(x2, y2, &(occupants[1]));
  29.      do_entity(&(occupants[0]));          /* do set_entity after first */
  30.      set_entity(x2, y2, &(occupants[1])); /* do_entity for worm tails */
  31.      do_entity(&(occupants[1]));
  32.      (void) revive_nasty(x, y, (char *) 0);
  33.      delallobj(x, y);
  34.      if ((t = t_at(x, y)) != 0)
  35.          deltrap(t);
  36.      if ((t = t_at(x2, y2)) != 0)
  37.          deltrap(t);
  38.      del_engr_at(x, y);
  39.      del_engr_at(x2, y2);
  40.      newsym(x, y);
  41.      newsym(x2, y2);
  42.      unblock_point(x2, y2); /* vision */
  43.      if (Is_stronghold(&u.uz))
  44.          u.uevent.uopened_dbridge = TRUE;
  45.      nokiller();
  46.  }
  47.  

destroy_drawbridge

  1.  /*
  2.   * Let's destroy the drawbridge located at x,y
  3.   */
  4.  void
  5.  destroy_drawbridge(x, y)
  6.  int x, y;
  7.  {
  8.      register struct rm *lev1, *lev2;
  9.      struct trap *t;
  10.      struct obj *otmp;
  11.      int x2, y2, i;
  12.      boolean e_inview;
  13.      struct entity *etmp1 = &(occupants[0]), *etmp2 = &(occupants[1]);
  14.  
  15.      lev1 = &levl[x][y];
  16.      if (!IS_DRAWBRIDGE(lev1->typ))
  17.          return;
  18.      x2 = x;
  19.      y2 = y;
  20.      get_wall_for_db(&x2, &y2);
  21.      lev2 = &levl[x2][y2];
  22.      if ((lev1->drawbridgemask & DB_UNDER) == DB_MOAT
  23.          || (lev1->drawbridgemask & DB_UNDER) == DB_LAVA) {
  24.          struct obj *otmp2;
  25.          boolean lava = (lev1->drawbridgemask & DB_UNDER) == DB_LAVA;
  26.  
  27.          if (lev1->typ == DRAWBRIDGE_UP) {
  28.              if (cansee(x2, y2))
  29.                  pline_The("portcullis of the drawbridge falls into the %s!",
  30.                            lava ? hliquid("lava") : "moat");
  31.              else if (!Deaf)
  32.                  You_hear("a loud *SPLASH*!");
  33.          } else {
  34.              if (cansee(x, y))
  35.                  pline_The("drawbridge collapses into the %s!",
  36.                            lava ? hliquid("lava") : "moat");
  37.              else if (!Deaf)
  38.                  You_hear("a loud *SPLASH*!");
  39.          }
  40.          lev1->typ = lava ? LAVAPOOL : MOAT;
  41.          lev1->drawbridgemask = 0;
  42.          if ((otmp2 = sobj_at(BOULDER, x, y)) != 0) {
  43.              obj_extract_self(otmp2);
  44.              (void) flooreffects(otmp2, x, y, "fall");
  45.          }
  46.      } else {
  47.          if (cansee(x, y))
  48.              pline_The("drawbridge disintegrates!");
  49.          else
  50.              You_hear("a loud *CRASH*!");
  51.          lev1->typ = ((lev1->drawbridgemask & DB_ICE) ? ICE : ROOM);
  52.          lev1->icedpool = ((lev1->drawbridgemask & DB_ICE) ? ICED_MOAT : 0);
  53.      }
  54.      wake_nearto(x, y, 500);
  55.      lev2->typ = DOOR;
  56.      lev2->doormask = D_NODOOR;
  57.      if ((t = t_at(x, y)) != 0)
  58.          deltrap(t);
  59.      if ((t = t_at(x2, y2)) != 0)
  60.          deltrap(t);
  61.      del_engr_at(x, y);
  62.      del_engr_at(x2, y2);
  63.      for (i = rn2(6); i > 0; --i) { /* scatter some debris */
  64.          /* doesn't matter if we happen to pick <x,y2> or <x2,y>;
  65.             since drawbridges are never placed diagonally, those
  66.             pairings will always match one of <x,y> or <x2,y2> */
  67.          otmp = mksobj_at(IRON_CHAIN, rn2(2) ? x : x2, rn2(2) ? y : y2, TRUE,
  68.                           FALSE);
  69.          /* a force of 5 here would yield a radius of 2 for
  70.             iron chain; anything less produces a radius of 1 */
  71.          (void) scatter(otmp->ox, otmp->oy, 1, MAY_HIT, otmp);
  72.      }
  73.      newsym(x, y);
  74.      newsym(x2, y2);
  75.      if (!does_block(x2, y2, lev2))
  76.          unblock_point(x2, y2); /* vision */
  77.      if (Is_stronghold(&u.uz))
  78.          u.uevent.uopened_dbridge = TRUE;
  79.  
  80.      set_entity(x2, y2, etmp2); /* currently only automissers can be here */
  81.      if (etmp2->edata) {
  82.          e_inview = e_canseemon(etmp2);
  83.          if (!automiss(etmp2)) {
  84.              if (e_inview)
  85.                  pline("%s blown apart by flying debris.",
  86.                        E_phrase(etmp2, "are"));
  87.              killer.format = KILLED_BY_AN;
  88.              Strcpy(killer.name, "exploding drawbridge");
  89.              e_died(etmp2,
  90.                     XKILL_NOCORPSE | (e_inview ? XKILL_GIVEMSG : XKILL_NOMSG),
  91.                     CRUSHING); /*no corpse*/
  92.          } /* nothing which is vulnerable can survive this */
  93.      }
  94.      set_entity(x, y, etmp1);
  95.      if (etmp1->edata) {
  96.          e_inview = e_canseemon(etmp1);
  97.          if (e_missed(etmp1, TRUE)) {
  98.              debugpline1("%s spared!", E_phrase(etmp1, "are"));
  99.              /* if there is water or lava here, fall in now */
  100.              if (is_u(etmp1))
  101.                  spoteffects(FALSE);
  102.              else
  103.                  (void) minliquid(etmp1->emon);
  104.          } else {
  105.              if (e_inview) {
  106.                  if (!is_u(etmp1) && Hallucination)
  107.                      pline("%s into some heavy metal!",
  108.                            E_phrase(etmp1, "get"));
  109.                  else
  110.                      pline("%s hit by a huge chunk of metal!",
  111.                            E_phrase(etmp1, "are"));
  112.              } else {
  113.                  if (!Deaf && !is_u(etmp1) && !is_pool(x, y)) {
  114.                      You_hear("a crushing sound.");
  115.                  } else {
  116.                      debugpline1("%s from shrapnel", E_phrase(etmp1, "die"));
  117.                  }
  118.              }
  119.              killer.format = KILLED_BY_AN;
  120.              Strcpy(killer.name, "collapsing drawbridge");
  121.              e_died(etmp1,
  122.                     XKILL_NOCORPSE | (e_inview ? XKILL_GIVEMSG : XKILL_NOMSG),
  123.                     CRUSHING); /*no corpse*/
  124.              if (levl[etmp1->ex][etmp1->ey].typ == MOAT)
  125.                  do_entity(etmp1);
  126.          }
  127.      }
  128.      nokiller();
  129.  }
  130.  
  131.  /*dbridge.c*/