static int get_table_region(lua_State *, const char *, int *, int *, int *,
int *, boolean);
static void set_wallprop_in_selection(lua_State *, int);
+static xchar random_wdir(void);
static int floodfillchk_match_under(int, int);
static int floodfillchk_match_accessible(int, int);
static boolean sel_flood_havepoint(int, int, xchar *, xchar *, int);
if (dd->secret == -1)
dd->secret = rn2(2);
+ if (dd->wall == W_RANDOM)
+ dd->wall = W_ANY; /* speeds things up in the below loop */
+
if (dd->mask == -1) {
/* is it a locked door, closed, or a doorway? */
if (!dd->secret) {
}
for (trycnt = 0; trycnt < 100; ++trycnt) {
- int dwall, dpos;
-
- dwall = dd->wall;
- if (dwall == -1) /* The wall is RANDOM */
- dwall = 1 << rn2(4);
-
- dpos = dd->pos;
+ int dwall = dd->wall, dpos = dd->pos;
/* Convert wall and pos into an absolute coordinate! */
switch (rn2(4)) {
levl[x][y].doormask = dd->mask;
}
-/*
- * Create a secret door in croom on any one of the specified walls.
- */
-void
-create_secret_door(
- struct mkroom *croom,
- xchar walls) /* any of W_NORTH | W_SOUTH | W_EAST | W_WEST (or W_ANY) */
-{
- xchar sx, sy; /* location of the secret door */
- int count;
-
- for (count = 0; count < 100; count++) {
- sx = rn1(croom->hx - croom->lx + 1, croom->lx);
- sy = rn1(croom->hy - croom->ly + 1, croom->ly);
-
- switch (rn2(4)) {
- case 0: /* top */
- if (!(walls & W_NORTH))
- continue;
- sy = croom->ly - 1;
- break;
- case 1: /* bottom */
- if (!(walls & W_SOUTH))
- continue;
- sy = croom->hy + 1;
- break;
- case 2: /* left */
- if (!(walls & W_EAST))
- continue;
- sx = croom->lx - 1;
- break;
- case 3: /* right */
- if (!(walls & W_WEST))
- continue;
- sx = croom->hx + 1;
- break;
- }
-
- if (okdoor(sx, sy)) {
- levl[sx][sy].typ = SDOOR;
- levl[sx][sy].doormask = D_CLOSED;
- return;
- }
- }
-
- impossible("couldn't create secret door on any walls 0x%x", walls);
-}
-
/*
* Create a trap in a room.
*/
return;
}
+ /* Safety railings - if there's ever a case where des.corridor() needs to be
+ * called with src/destwall="random", that logic first needs to be
+ * implemented in search_door. */
+ if (c->src.wall == W_ANY || c->src.wall == W_RANDOM
+ || c->dest.wall == W_ANY || c->dest.wall == W_RANDOM) {
+ impossible("create_corridor to/from a random wall");
+ return;
+ }
if (!search_door(&g.rooms[c->src.room], &org.x, &org.y, c->src.wall,
c->src.door))
return;
"all", "random", "north", "west", "east", "south", NULL
};
static const int walldirs2i[] = {
- W_ANY, -1, W_NORTH, W_WEST, W_EAST, W_SOUTH, 0
+ W_ANY, W_RANDOM, W_NORTH, W_WEST, W_EAST, W_SOUTH, 0
};
corridor tc;
return 0;
}
+/* Choose a single random W_* direction. */
+static xchar
+random_wdir(void)
+{
+ static const xchar wdirs[4] = { W_NORTH, W_SOUTH, W_EAST, W_WEST };
+ return wdirs[rn2(4)];
+}
+
void
selection_do_grow(struct selectionvar* ov, int dir)
{
if (!ov || !tmp)
return;
+ if (dir == W_RANDOM)
+ dir = random_wdir();
+
for (x = 1; x < ov->wid; x++)
for (y = 0; y < ov->hei; y++) {
/* note: dir is a mask of multiple directions, but the only
static const char *const walldirs[] = {
"all", "random", "north", "west", "east", "south", NULL
};
+ /* Note that "random" is also W_ANY, because create_door just wants a
+ * mask of acceptable walls */
static const int walldirs2i[] = {
W_ANY, W_ANY, W_NORTH, W_WEST, W_EAST, W_SOUTH, 0
};
static const char *const mwdirs[] = {
"north", "south", "east", "west", "random", NULL
};
- static const int mwdirs2i[] = { W_NORTH, W_SOUTH, W_EAST, W_WEST, -1, -2 };
+ static const int mwdirs2i[] = { W_NORTH, W_SOUTH, W_EAST, W_WEST, W_RANDOM, -2 };
xchar x, y;
int mx, my;
xchar ftyp = ROOM;
ftyp = g.level.flags.corrmaze ? CORR : ROOM;
}
- if (dir == -1)
- dir = mwdirs2i[rn2(4)];
+ if (dir == W_RANDOM)
+ dir = random_wdir();
/* don't use move() - it doesn't use W_NORTH, etc. */
switch (dir) {