Source:NetHack 3.6.0/src/extralev.c

From NetHackWiki
Jump to: navigation, search

Below is the full text to extralev.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/extralev.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	extralev.c	$NHDT-Date: 1446975468 2015/11/08 09:37:48 $  $NHDT-Branch: master $:$NHDT-Revision: 1.12 $ */
  2.  /*      Copyright 1988, 1989 by Ken Arromdee                      */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  /*
  6.   * Support code for "rogue"-style level.
  7.   */
  8.  
  9.  #include "hack.h"
  10.  
  11.  struct rogueroom {
  12.      xchar rlx, rly;
  13.      xchar dx, dy;
  14.      boolean real;
  15.      uchar doortable;
  16.      int nroom; /* Only meaningful for "real" rooms */
  17.  };
  18.  #define UP 1
  19.  #define DOWN 2
  20.  #define LEFT 4
  21.  #define RIGHT 8
  22.  
  23.  static NEARDATA struct rogueroom r[3][3];
  24.  STATIC_DCL void FDECL(roguejoin, (int, int, int, int, int));
  25.  STATIC_DCL void FDECL(roguecorr, (int, int, int));
  26.  STATIC_DCL void FDECL(miniwalk, (int, int));
  27.  

roguejoin

  1.  STATIC_OVL
  2.  void
  3.  roguejoin(x1, y1, x2, y2, horiz)
  4.  int x1, y1, x2, y2;
  5.  int horiz;
  6.  {
  7.      register int x, y, middle;
  8.      if (horiz) {
  9.          middle = x1 + rn2(x2 - x1 + 1);
  10.          for (x = min(x1, middle); x <= max(x1, middle); x++)
  11.              corr(x, y1);
  12.          for (y = min(y1, y2); y <= max(y1, y2); y++)
  13.              corr(middle, y);
  14.          for (x = min(middle, x2); x <= max(middle, x2); x++)
  15.              corr(x, y2);
  16.      } else {
  17.          middle = y1 + rn2(y2 - y1 + 1);
  18.          for (y = min(y1, middle); y <= max(y1, middle); y++)
  19.              corr(x1, y);
  20.          for (x = min(x1, x2); x <= max(x1, x2); x++)
  21.              corr(x, middle);
  22.          for (y = min(middle, y2); y <= max(middle, y2); y++)
  23.              corr(x2, y);
  24.      }
  25.  }
  26.  

roguecorr

  1.  STATIC_OVL
  2.  void
  3.  roguecorr(x, y, dir)
  4.  int x, y, dir;
  5.  {
  6.      register int fromx, fromy, tox, toy;
  7.  
  8.      if (dir == DOWN) {
  9.          r[x][y].doortable &= ~DOWN;
  10.          if (!r[x][y].real) {
  11.              fromx = r[x][y].rlx;
  12.              fromy = r[x][y].rly;
  13.              fromx += 1 + 26 * x;
  14.              fromy += 7 * y;
  15.          } else {
  16.              fromx = r[x][y].rlx + rn2(r[x][y].dx);
  17.              fromy = r[x][y].rly + r[x][y].dy;
  18.              fromx += 1 + 26 * x;
  19.              fromy += 7 * y;
  20.              if (!IS_WALL(levl[fromx][fromy].typ))
  21.                  impossible("down: no wall at %d,%d?", fromx, fromy);
  22.              dodoor(fromx, fromy, &rooms[r[x][y].nroom]);
  23.              levl[fromx][fromy].doormask = D_NODOOR;
  24.              fromy++;
  25.          }
  26.          if (y >= 2) {
  27.              impossible("down door from %d,%d going nowhere?", x, y);
  28.              return;
  29.          }
  30.          y++;
  31.          r[x][y].doortable &= ~UP;
  32.          if (!r[x][y].real) {
  33.              tox = r[x][y].rlx;
  34.              toy = r[x][y].rly;
  35.              tox += 1 + 26 * x;
  36.              toy += 7 * y;
  37.          } else {
  38.              tox = r[x][y].rlx + rn2(r[x][y].dx);
  39.              toy = r[x][y].rly - 1;
  40.              tox += 1 + 26 * x;
  41.              toy += 7 * y;
  42.              if (!IS_WALL(levl[tox][toy].typ))
  43.                  impossible("up: no wall at %d,%d?", tox, toy);
  44.              dodoor(tox, toy, &rooms[r[x][y].nroom]);
  45.              levl[tox][toy].doormask = D_NODOOR;
  46.              toy--;
  47.          }
  48.          roguejoin(fromx, fromy, tox, toy, FALSE);
  49.          return;
  50.      } else if (dir == RIGHT) {
  51.          r[x][y].doortable &= ~RIGHT;
  52.          if (!r[x][y].real) {
  53.              fromx = r[x][y].rlx;
  54.              fromy = r[x][y].rly;
  55.              fromx += 1 + 26 * x;
  56.              fromy += 7 * y;
  57.          } else {
  58.              fromx = r[x][y].rlx + r[x][y].dx;
  59.              fromy = r[x][y].rly + rn2(r[x][y].dy);
  60.              fromx += 1 + 26 * x;
  61.              fromy += 7 * y;
  62.              if (!IS_WALL(levl[fromx][fromy].typ))
  63.                  impossible("down: no wall at %d,%d?", fromx, fromy);
  64.              dodoor(fromx, fromy, &rooms[r[x][y].nroom]);
  65.              levl[fromx][fromy].doormask = D_NODOOR;
  66.              fromx++;
  67.          }
  68.          if (x >= 2) {
  69.              impossible("right door from %d,%d going nowhere?", x, y);
  70.              return;
  71.          }
  72.          x++;
  73.          r[x][y].doortable &= ~LEFT;
  74.          if (!r[x][y].real) {
  75.              tox = r[x][y].rlx;
  76.              toy = r[x][y].rly;
  77.              tox += 1 + 26 * x;
  78.              toy += 7 * y;
  79.          } else {
  80.              tox = r[x][y].rlx - 1;
  81.              toy = r[x][y].rly + rn2(r[x][y].dy);
  82.              tox += 1 + 26 * x;
  83.              toy += 7 * y;
  84.              if (!IS_WALL(levl[tox][toy].typ))
  85.                  impossible("left: no wall at %d,%d?", tox, toy);
  86.              dodoor(tox, toy, &rooms[r[x][y].nroom]);
  87.              levl[tox][toy].doormask = D_NODOOR;
  88.              tox--;
  89.          }
  90.          roguejoin(fromx, fromy, tox, toy, TRUE);
  91.          return;
  92.      } else
  93.          impossible("corridor in direction %d?", dir);
  94.  }
  95.  

miniwalk

  1.  /* Modified walkfrom() from mkmaze.c */
  2.  STATIC_OVL
  3.  void
  4.  miniwalk(x, y)
  5.  int x, y;
  6.  {
  7.      register int q, dir;
  8.      int dirs[4];
  9.  
  10.      while (1) {
  11.          q = 0;
  12.  #define doorhere (r[x][y].doortable)
  13.          if (x > 0 && (!(doorhere & LEFT))
  14.              && (!r[x - 1][y].doortable || !rn2(10)))
  15.              dirs[q++] = 0;
  16.          if (x < 2 && (!(doorhere & RIGHT))
  17.              && (!r[x + 1][y].doortable || !rn2(10)))
  18.              dirs[q++] = 1;
  19.          if (y > 0 && (!(doorhere & UP))
  20.              && (!r[x][y - 1].doortable || !rn2(10)))
  21.              dirs[q++] = 2;
  22.          if (y < 2 && (!(doorhere & DOWN))
  23.              && (!r[x][y + 1].doortable || !rn2(10)))
  24.              dirs[q++] = 3;
  25.          /* Rogue levels aren't just 3 by 3 mazes; they have some extra
  26.           * connections, thus that 1/10 chance
  27.           */
  28.          if (!q)
  29.              return;
  30.          dir = dirs[rn2(q)];
  31.          switch (dir) { /* Move in direction */
  32.          case 0:
  33.              doorhere |= LEFT;
  34.              x--;
  35.              doorhere |= RIGHT;
  36.              break;
  37.          case 1:
  38.              doorhere |= RIGHT;
  39.              x++;
  40.              doorhere |= LEFT;
  41.              break;
  42.          case 2:
  43.              doorhere |= UP;
  44.              y--;
  45.              doorhere |= DOWN;
  46.              break;
  47.          case 3:
  48.              doorhere |= DOWN;
  49.              y++;
  50.              doorhere |= UP;
  51.              break;
  52.          }
  53.          miniwalk(x, y);
  54.      }
  55.  }
  56.  

makeroguerooms

  1.  void
  2.  makeroguerooms()
  3.  {
  4.      register int x, y;
  5.      /* Rogue levels are structured 3 by 3, with each section containing
  6.       * a room or an intersection.  The minimum width is 2 each way.
  7.       * One difference between these and "real" Rogue levels: real Rogue
  8.       * uses 24 rows and NetHack only 23.  So we cheat a bit by making the
  9.       * second row of rooms not as deep.
  10.       *
  11.       * Each normal space has 6/7 rows and 25 columns in which a room may
  12.       * actually be placed.  Walls go from rows 0-5/6 and columns 0-24.
  13.       * Not counting walls, the room may go in
  14.       * rows 1-5 and columns 1-23 (numbering starting at 0).  A room
  15.       * coordinate of this type may be converted to a level coordinate
  16.       * by adding 1+28*x to the column, and 7*y to the row.  (The 1
  17.       * is because column 0 isn't used [we only use 1-78]).
  18.       * Room height may be 2-4 (2-5 on last row), length 2-23 (not
  19.       * counting walls).
  20.       */
  21.  #define here r[x][y]
  22.  
  23.      nroom = 0;
  24.      for (y = 0; y < 3; y++)
  25.          for (x = 0; x < 3; x++) {
  26.              /* Note: we want to insure at least 1 room.  So, if the
  27.               * first 8 are all dummies, force the last to be a room.
  28.               */
  29.              if (!rn2(5) && (nroom || (x < 2 && y < 2))) {
  30.                  /* Arbitrary: dummy rooms may only go where real
  31.                   * ones do.
  32.                   */
  33.                  here.real = FALSE;
  34.                  here.rlx = rn1(22, 2);
  35.                  here.rly = rn1((y == 2) ? 4 : 3, 2);
  36.              } else {
  37.                  here.real = TRUE;
  38.                  here.dx = rn1(22, 2); /* 2-23 long, plus walls */
  39.                  here.dy = rn1((y == 2) ? 4 : 3, 2); /* 2-5 high, plus walls */
  40.  
  41.                  /* boundaries of room floor */
  42.                  here.rlx = rnd(23 - here.dx + 1);
  43.                  here.rly = rnd(((y == 2) ? 5 : 4) - here.dy + 1);
  44.                  nroom++;
  45.              }
  46.              here.doortable = 0;
  47.          }
  48.      miniwalk(rn2(3), rn2(3));
  49.      nroom = 0;
  50.      for (y = 0; y < 3; y++)
  51.          for (x = 0; x < 3; x++) {
  52.              if (here.real) { /* Make a room */
  53.                  int lowx, lowy, hix, hiy;
  54.  
  55.                  r[x][y].nroom = nroom;
  56.                  smeq[nroom] = nroom;
  57.  
  58.                  lowx = 1 + 26 * x + here.rlx;
  59.                  lowy = 7 * y + here.rly;
  60.                  hix = 1 + 26 * x + here.rlx + here.dx - 1;
  61.                  hiy = 7 * y + here.rly + here.dy - 1;
  62.                  /* Strictly speaking, it should be lit only if above
  63.                   * level 10, but since Rogue rooms are only
  64.                   * encountered below level 10, use !rn2(7).
  65.                   */
  66.                  add_room(lowx, lowy, hix, hiy, (boolean) !rn2(7), OROOM,
  67.                           FALSE);
  68.              }
  69.          }
  70.  
  71.      /* Now, add connecting corridors. */
  72.      for (y = 0; y < 3; y++)
  73.          for (x = 0; x < 3; x++) {
  74.              if (here.doortable & DOWN)
  75.                  roguecorr(x, y, DOWN);
  76.              if (here.doortable & RIGHT)
  77.                  roguecorr(x, y, RIGHT);
  78.              if (here.doortable & LEFT)
  79.                  impossible("left end of %d, %d never connected?", x, y);
  80.              if (here.doortable & UP)
  81.                  impossible("up end of %d, %d never connected?", x, y);
  82.          }
  83.  }
  84.  

corr

  1.  void
  2.  corr(x, y)
  3.  int x, y;
  4.  {
  5.      if (rn2(50)) {
  6.          levl[x][y].typ = CORR;
  7.      } else {
  8.          levl[x][y].typ = SCORR;
  9.      }
  10.  }
  11.  

makerogueghost

  1.  void
  2.  makerogueghost()
  3.  {
  4.      register struct monst *ghost;
  5.      struct obj *ghostobj;
  6.      struct mkroom *croom;
  7.      int x, y;
  8.  
  9.      if (!nroom)
  10.          return; /* Should never happen */
  11.      croom = &rooms[rn2(nroom)];
  12.      x = somex(croom);
  13.      y = somey(croom);
  14.      if (!(ghost = makemon(&mons[PM_GHOST], x, y, NO_MM_FLAGS)))
  15.          return;
  16.      ghost->msleeping = 1;
  17.      ghost = christen_monst(ghost, roguename());
  18.  
  19.      if (rn2(4)) {
  20.          ghostobj = mksobj_at(FOOD_RATION, x, y, FALSE, FALSE);
  21.          ghostobj->quan = (long) rnd(7);
  22.          ghostobj->owt = weight(ghostobj);
  23.      }
  24.      if (rn2(2)) {
  25.          ghostobj = mksobj_at(MACE, x, y, FALSE, FALSE);
  26.          ghostobj->spe = rnd(3);
  27.          if (rn2(4))
  28.              curse(ghostobj);
  29.      } else {
  30.          ghostobj = mksobj_at(TWO_HANDED_SWORD, x, y, FALSE, FALSE);
  31.          ghostobj->spe = rnd(5) - 2;
  32.          if (rn2(4))
  33.              curse(ghostobj);
  34.      }
  35.      ghostobj = mksobj_at(BOW, x, y, FALSE, FALSE);
  36.      ghostobj->spe = 1;
  37.      if (rn2(4))
  38.          curse(ghostobj);
  39.  
  40.      ghostobj = mksobj_at(ARROW, x, y, FALSE, FALSE);
  41.      ghostobj->spe = 0;
  42.      ghostobj->quan = (long) rn1(10, 25);
  43.      ghostobj->owt = weight(ghostobj);
  44.      if (rn2(4))
  45.          curse(ghostobj);
  46.  
  47.      if (rn2(2)) {
  48.          ghostobj = mksobj_at(RING_MAIL, x, y, FALSE, FALSE);
  49.          ghostobj->spe = rn2(3);
  50.          if (!rn2(3))
  51.              ghostobj->oerodeproof = TRUE;
  52.          if (rn2(4))
  53.              curse(ghostobj);
  54.      } else {
  55.          ghostobj = mksobj_at(PLATE_MAIL, x, y, FALSE, FALSE);
  56.          ghostobj->spe = rnd(5) - 2;
  57.          if (!rn2(3))
  58.              ghostobj->oerodeproof = TRUE;
  59.          if (rn2(4))
  60.              curse(ghostobj);
  61.      }
  62.      if (rn2(2)) {
  63.          ghostobj = mksobj_at(FAKE_AMULET_OF_YENDOR, x, y, TRUE, FALSE);
  64.          ghostobj->known = TRUE;
  65.      }
  66.  }
  67.  
  68.  /*extralev.c*/