Source:NetHack 3.6.0/src/dbridge.c

From NetHackWiki
Jump to: navigation, search

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

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.          break;
  9.      case DB_LAVA:
  10.          return LAVAPOOL;
  11.          break;
  12.      case DB_MOAT:
  13.          return MOAT;
  14.          break;
  15.      default:
  16.          return STONE;
  17.          break;
  18.      }
  19.  }
  20.  

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.  
  7.  boolean
  8.  create_drawbridge(x, y, dir, flag)
  9.  int x, y, dir;
  10.  boolean flag;
  11.  {
  12.      int x2, y2;
  13.      boolean horiz;
  14.      boolean lava = levl[x][y].typ == LAVAPOOL; /* assume initialized map */
  15.  
  16.      x2 = x;
  17.      y2 = y;
  18.      switch (dir) {
  19.      case DB_NORTH:
  20.          horiz = TRUE;
  21.          y2--;
  22.          break;
  23.      case DB_SOUTH:
  24.          horiz = TRUE;
  25.          y2++;
  26.          break;
  27.      case DB_EAST:
  28.          horiz = FALSE;
  29.          x2++;
  30.          break;
  31.      default:
  32.          impossible("bad direction in create_drawbridge");
  33.          /*FALLTHRU*/
  34.      case DB_WEST:
  35.          horiz = FALSE;
  36.          x2--;
  37.          break;
  38.      }
  39.      if (!IS_WALL(levl[x2][y2].typ))
  40.          return FALSE;
  41.      if (flag) { /* We want the bridge open */
  42.          levl[x][y].typ = DRAWBRIDGE_DOWN;
  43.          levl[x2][y2].typ = DOOR;
  44.          levl[x2][y2].doormask = D_NODOOR;
  45.      } else {
  46.          levl[x][y].typ = DRAWBRIDGE_UP;
  47.          levl[x2][y2].typ = DBWALL;
  48.          /* Drawbridges are non-diggable. */
  49.          levl[x2][y2].wall_info = W_NONDIGGABLE;
  50.      }
  51.      levl[x][y].horizontal = !horiz;
  52.      levl[x2][y2].horizontal = horiz;
  53.      levl[x][y].drawbridgemask = dir;
  54.      if (lava)
  55.          levl[x][y].drawbridgemask |= DB_LAVA;
  56.      return  TRUE;
  57.  }
  58.  

e_at

  1.  struct entity {
  2.      struct monst *emon;     /* youmonst for the player */
  3.      struct permonst *edata; /* must be non-zero for record to be valid */
  4.      int ex, ey;
  5.  };
  6.  
  7.  #define ENTITIES 2
  8.  
  9.  static NEARDATA struct entity occupants[ENTITIES];
  10.  
  11.  STATIC_OVL
  12.  struct entity *
  13.  e_at(x, y)
  14.  int x, y;
  15.  {
  16.      int entitycnt;
  17.  
  18.      for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++)
  19.          if ((occupants[entitycnt].edata) && (occupants[entitycnt].ex == x)
  20.              && (occupants[entitycnt].ey == y))
  21.              break;
  22.      debugpline1("entitycnt = %d", entitycnt);
  23.  #ifdef D_DEBUG
  24.      wait_synch();
  25.  #endif
  26.      return (entitycnt == ENTITIES) ? (struct entity *) 0
  27.                                     : &(occupants[entitycnt]);
  28.  }
  29.  

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.  }
  10.  

set_entity

  1.  STATIC_OVL void
  2.  set_entity(x, y, etmp)
  3.  int x, y;
  4.  struct entity *etmp;
  5.  {
  6.      if ((x == u.ux) && (y == u.uy))
  7.          u_to_e(etmp);
  8.      else if (MON_AT(x, y))
  9.          m_to_e(m_at(x, y), x, y, etmp);
  10.      else
  11.          etmp->edata = (struct permonst *) 0;
  12.  }
  13.  

e_nam

  1.  #define is_u(etmp) (etmp->emon == &youmonst)
  2.  #define e_canseemon(etmp) \
  3.      (is_u(etmp) ? (boolean) TRUE : canseemon(etmp->emon))
  4.  
  5.  /*
  6.   * e_strg is a utility routine which is not actually in use anywhere, since
  7.   * the specialized routines below suffice for all current purposes.
  8.   */
  9.  
  10.  /* #define e_strg(etmp, func) (is_u(etmp)? (char *)0 : func(etmp->emon)) */
  11.  
  12.  STATIC_OVL const char *
  13.  e_nam(etmp)
  14.  struct entity *etmp;
  15.  {
  16.      return is_u(etmp) ? "you" : mon_nam(etmp->emon);
  17.  }
  18.  

E_phrase

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

e_survives_at

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

e_died

  1.  STATIC_OVL void
  2.  e_died(etmp, dest, how)
  3.  struct entity *etmp;
  4.  int dest, 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 & 1) ? "" : (char *) 0)
  42.  #define mk_corpse(dest) ((dest & 2) ? AD_DGST : AD_PHYS)
  43.          /* if monsters are moving, one of them caused the destruction */
  44.          if (context.mon_moving)
  45.              monkilled(etmp->emon, mk_message(dest), mk_corpse(dest));
  46.          else /* you caused it */
  47.              xkilled(etmp->emon, dest);
  48.          etmp->edata = (struct permonst *) 0;
  49.  
  50.          /* dead long worm handling */
  51.          for (entitycnt = 0; entitycnt < ENTITIES; entitycnt++) {
  52.              if (etmp != &(occupants[entitycnt])
  53.                  && etmp->emon == occupants[entitycnt].emon)
  54.                  occupants[entitycnt].edata = (struct permonst *) 0;
  55.          }
  56.  #undef mk_message
  57.  #undef mk_corpse
  58.      }
  59.  }
  60.  

automiss

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

e_missed

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

e_jumps

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

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

close_drawbridge

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

open_drawbridge

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

destroy_drawbridge

  1.  /*
  2.   * Let's destroy the drawbridge located at x,y
  3.   */
  4.  
  5.  void
  6.  destroy_drawbridge(x, y)
  7.  int x, y;
  8.  {
  9.      register struct rm *lev1, *lev2;
  10.      struct trap *t;
  11.      struct obj *otmp;
  12.      int x2, y2, i;
  13.      boolean e_inview;
  14.      struct entity *etmp1 = &(occupants[0]), *etmp2 = &(occupants[1]);
  15.  
  16.      lev1 = &levl[x][y];
  17.      if (!IS_DRAWBRIDGE(lev1->typ))
  18.          return;
  19.      x2 = x;
  20.      y2 = y;
  21.      get_wall_for_db(&x2, &y2);
  22.      lev2 = &levl[x2][y2];
  23.      if ((lev1->drawbridgemask & DB_UNDER) == DB_MOAT
  24.          || (lev1->drawbridgemask & DB_UNDER) == DB_LAVA) {
  25.          struct obj *otmp2;
  26.          boolean lava = (lev1->drawbridgemask & DB_UNDER) == DB_LAVA;
  27.          if (lev1->typ == DRAWBRIDGE_UP) {
  28.              if (cansee(x2, y2))
  29.                  pline_The("portcullis of the drawbridge falls into the %s!",
  30.                            lava ? "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 ? "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, e_inview ? 3 : 2, CRUSHING); /*no corpse*/
  90.          } /* nothing which is vulnerable can survive this */
  91.      }
  92.      set_entity(x, y, etmp1);
  93.      if (etmp1->edata) {
  94.          e_inview = e_canseemon(etmp1);
  95.          if (e_missed(etmp1, TRUE)) {
  96.              debugpline1("%s spared!", E_phrase(etmp1, "are"));
  97.              /* if there is water or lava here, fall in now */
  98.              if (is_u(etmp1))
  99.                  spoteffects(FALSE);
  100.              else
  101.                  (void) minliquid(etmp1->emon);
  102.          } else {
  103.              if (e_inview) {
  104.                  if (!is_u(etmp1) && Hallucination)
  105.                      pline("%s into some heavy metal!",
  106.                            E_phrase(etmp1, "get"));
  107.                  else
  108.                      pline("%s hit by a huge chunk of metal!",
  109.                            E_phrase(etmp1, "are"));
  110.              } else {
  111.                  if (!Deaf && !is_u(etmp1) && !is_pool(x, y)) {
  112.                      You_hear("a crushing sound.");
  113.                  } else {
  114.                      debugpline1("%s from shrapnel", E_phrase(etmp1, "die"));
  115.                  }
  116.              }
  117.              killer.format = KILLED_BY_AN;
  118.              Strcpy(killer.name, "collapsing drawbridge");
  119.              e_died(etmp1, e_inview ? 3 : 2, CRUSHING); /*no corpse*/
  120.              if (levl[etmp1->ex][etmp1->ey].typ == MOAT)
  121.                  do_entity(etmp1);
  122.          }
  123.      }
  124.  }
  125.  
  126.  /*dbridge.c*/