*/
/*
- * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
*
- * This software may be copied and distributed for educational, research, and
- * not for profit purposes provided that this copyright and statement are
- * included in all such copies.
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies. Other copyrights may also apply.
*/
#include "angband.h"
bool new_player_spot(void)
{
int y, x;
- int max_attempts = 5000;
+ int max_attempts = 10000;
cave_type *c_ptr;
+ feature_type *f_ptr;
/* Place the player */
while (max_attempts--)
c_ptr = &cave[y][x];
/* Must be a "naked" floor grid */
- if (!cave_clean_bold(y, x) || c_ptr->m_idx) continue;
- if (!in_bounds(y,x)) continue;
+ if (c_ptr->m_idx) continue;
+ if (dun_level)
+ {
+ f_ptr = &f_info[c_ptr->feat];
+
+ if (max_attempts > 5000) /* Rule 1 */
+ {
+ if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
+ }
+ else /* Rule 2 */
+ {
+ if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
+ if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
+ }
+
+ /* Refuse to start on anti-teleport grids in dungeon */
+ if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
+ }
+ if (!player_can_enter(c_ptr->feat, 0)) continue;
+ if (!in_bounds(y, x)) continue;
/* Refuse to start on anti-teleport grids */
if (c_ptr->info & (CAVE_ICKY)) continue;
if (down_stairs && up_stairs)
{
/* Choose a staircase randomly */
- if (rand_int(100) < 50)
+ if (randint0(100) < 50)
up_stairs = FALSE;
else
down_stairs = FALSE;
/*
* Place a random type of door at the given location
*/
-void place_random_door(int y, int x)
+void place_random_door(int y, int x, bool room)
{
int tmp;
+ cave_type *c_ptr = &cave[y][x];
+ /* Initialize mimic info */
+ c_ptr->mimic = 0;
+
if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
{
place_floor_bold(y, x);
}
/* Choose an object */
- tmp = rand_int(1000);
+ tmp = randint0(1000);
/* Open doors (300/1000) */
if (tmp < 300)
{
/* Create open door */
- cave_set_feat(y, x, FEAT_OPEN);
+ set_cave_feat(y, x, FEAT_OPEN);
}
/* Broken doors (100/1000) */
else if (tmp < 400)
{
/* Create broken door */
- cave_set_feat(y, x, FEAT_BROKEN);
+ set_cave_feat(y, x, FEAT_BROKEN);
}
/* Secret doors (200/1000) */
else if (tmp < 600)
{
/* Create secret door */
- cave_set_feat(y, x, FEAT_SECRET);
+ place_closed_door(y, x);
+
+ /* Hide. If on the edge of room, use outer wall. */
+ c_ptr->mimic = room ? feat_wall_outer : fill_type[randint0(100)];
+
+ /* Floor type terrain cannot hide a door */
+ if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
+ {
+ if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
+ {
+ c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
+ }
+ c_ptr->mimic = 0;
+ }
}
/* Closed, locked, or stuck doors (400/1000) */
else place_closed_door(y, x);
+
+ delete_monster(y, x);
}
}
/* Choose an object */
- tmp = rand_int(400);
+ tmp = randint0(400);
/* Closed doors (300/400) */
if (tmp < 300)
else if (tmp < 399)
{
/* Create locked door */
- cave_set_feat(y, x, FEAT_DOOR_HEAD + randint(7));
+ cave_set_feat(y, x, FEAT_DOOR_HEAD + randint1(7));
}
/* Stuck doors (1/400) */
else
{
/* Create jammed door */
- cave_set_feat(y, x, FEAT_DOOR_HEAD + 0x08 + rand_int(8));
+ cave_set_feat(y, x, FEAT_DOOR_HEAD + 0x08 + randint0(8));
}
+
+ /* Now it is not floor */
+ cave[y][x].info &= ~(CAVE_MASK);
}
if (!is_floor_grid(c_ptr) || c_ptr->o_idx) continue;
/* Place an item */
- if (rand_int(100) < 75)
+ if (randint0(100) < 75)
{
- place_object(j, k, FALSE, FALSE);
+ place_object(j, k, 0L);
}
/* Place gold */
/* Place the monster (allow groups) */
monster_level = base_level + 2;
- (void)place_monster(y, x, TRUE, TRUE);
+ (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
monster_level = base_level;
}
}
/*
- * Count the number of walls adjacent to the given grid.
- *
- * Note -- Assumes "in_bounds(y, x)"
- *
- * We count only granite walls and permanent walls.
- */
-int next_to_walls(int y, int x)
-{
- int k = 0;
-
- if (cave_floor_grid(&cave[y + 1][x])) k++;
- if (cave_floor_grid(&cave[y - 1][x])) k++;
- if (cave_floor_grid(&cave[y][x + 1])) k++;
- if (cave_floor_grid(&cave[y][x - 1])) k++;
-
- return (k);
-}
-
-
-/*
* Always picks a correct direction
*/
void correct_dir(int *rdir, int *cdir, int y1, int x1, int y2, int x2)
/* Never move diagonally */
if (*rdir && *cdir)
{
- if (rand_int(100) < 50)
+ if (randint0(100) < 50)
*rdir = 0;
else
*cdir = 0;
}
-
/*
* Pick a random direction
*/
void rand_dir(int *rdir, int *cdir)
{
/* Pick a random direction */
- int i = rand_int(4);
+ int i = randint0(4);
/* Extract the dy/dx components */
*rdir = ddy_ddd[i];
* corners of rooms off, as well as "silly" door placement, and
* "excessively wide" room entrances.
*
- * Useful "feat" values:
- * FEAT_WALL_EXTRA -- granite walls
- * FEAT_WALL_INNER -- inner room walls
- * FEAT_WALL_OUTER -- outer room walls
- * FEAT_WALL_SOLID -- solid room walls
- * FEAT_PERM_EXTRA -- shop walls (perma)
- * FEAT_PERM_INNER -- inner room walls (perma)
- * FEAT_PERM_OUTER -- outer room walls (perma)
- * FEAT_PERM_SOLID -- dungeon border (perma)
+ * Kind of walls:
+ * extra -- walls
+ * inner -- inner room walls
+ * outer -- outer room walls
+ * solid -- solid room walls
*/
void build_tunnel(int row1, int col1, int row2, int col2)
{
if (main_loop_count++ > 2000) break;
/* Allow bends in the tunnel */
- if (rand_int(100) < dun_tun_chg)
+ if (randint0(100) < dun_tun_chg)
{
/* Acquire the correct direction */
correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
/* Random direction */
- if (rand_int(100) < dun_tun_rnd)
+ if (randint0(100) < dun_tun_rnd)
{
rand_dir(&row_dir, &col_dir);
}
correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
/* Random direction */
- if (rand_int(100) < dun_tun_rnd)
+ if (randint0(100) < dun_tun_rnd)
{
rand_dir(&row_dir, &col_dir);
}
/* Access the location */
c_ptr = &cave[tmp_row][tmp_col];
+ if (permanent_wall(&f_info[c_ptr->feat]))
+ {
+ /* Avoid the edge of vaults */
+ if (is_inner_grid(c_ptr)) continue;
+ }
- /* Avoid the edge of the dungeon */
- if (c_ptr->feat == FEAT_PERM_SOLID) continue;
-
- /* Avoid the edge of vaults */
- if (c_ptr->feat == FEAT_PERM_OUTER) continue;
-
- /* Avoid "solid" granite walls */
+ /* Avoid "solid" walls */
if (is_solid_grid(c_ptr)) continue;
/* Pierce "outer" walls of rooms */
y = tmp_row + row_dir;
x = tmp_col + col_dir;
- /* Hack -- Avoid outer/solid permanent walls */
- if (cave[y][x].feat == FEAT_PERM_SOLID) continue;
- if (cave[y][x].feat == FEAT_PERM_OUTER) continue;
-
- /* Hack -- Avoid outer/solid granite walls */
+ /* Hack -- Avoid outer/solid walls */
if (is_outer_bold(y, x)) continue;
if (is_solid_bold(y, x)) continue;
}
/* Hack -- allow pre-emptive tunnel termination */
- if (rand_int(100) >= dun_tun_con)
+ if (randint0(100) >= dun_tun_con)
{
/* Distance between row1 and start_row */
tmp_row = row1 - start_row;
*/
static bool set_tunnel(int *x, int *y, bool affectwall)
{
- int feat, i, j, dx, dy;
+ int i, j, dx, dy;
cave_type *c_ptr = &cave[*y][*x];
if (!in_bounds(*y, *x)) return TRUE;
- feat = c_ptr->feat;
-
- if ((feat == FEAT_PERM_OUTER) ||
- (feat == FEAT_PERM_INNER) ||
- is_inner_grid(c_ptr))
+ if (is_inner_grid(c_ptr))
{
- /*
- * Ignore permanent walls - sometimes cannot tunnel around them anyway
- * so don't try - it just complicates things unnecessarily.
- */
return TRUE;
}
/* Save the tunnel location */
if (dun->tunn_n < TUNN_MAX)
{
- dun->tunn[dun->tunn_n].y = *y;
- dun->tunn[dun->tunn_n].x = *x;
- dun->tunn_n++;
+ dun->tunn[dun->tunn_n].y = *y;
+ dun->tunn[dun->tunn_n].x = *x;
+ dun->tunn_n++;
}
return TRUE;
}
}
}
+
+ /* Clear mimic type */
+ cave[*y][*x].mimic = 0;
+
place_floor_bold(*y, *x);
return TRUE;
dx = 0;
while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
{
- dy = rand_int(3) - 1;
- dx = rand_int(3) - 1;
+ dy = randint0(3) - 1;
+ dx = randint0(3) - 1;
if (!in_bounds(*y + dy, *x + dx))
{
{
int x3, y3, dx, dy;
int changex, changey;
- int midval;
int length;
int i;
bool retval, firstsuccede;
{
/*
* Divide path in half and call routine twice.
- */
+ */
dx = (x2 - x1) / 2;
dy = (y2 - y1) / 2;
/* perturbation perpendicular to path */
- changex = (rand_int(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
+ changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
/* perturbation perpendicular to path */
- changey = (rand_int(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
+ changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
/* Work out "mid" ponit */
x3 = x1 + dx + changex;
x3 = (x1 + x2) / 2;
y3 = (y1 + y2) / 2;
}
- /* cache midvalue */
+ /* cache c_ptr */
c_ptr = &cave[y3][x3];
- midval = cave[y3][x3].feat;
if (is_solid_grid(c_ptr))
{
/* move midpoint a bit to avoid problem. */
dx = 0;
while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
{
- dy = rand_int(3) - 1;
- dx = rand_int(3) - 1;
+ dy = randint0(3) - 1;
+ dx = randint0(3) - 1;
if (!in_bounds(y3 + dy, x3 + dx))
{
dx = 0;
y3 += dy;
x3 += dx;
c_ptr = &cave[y3][x3];
- midval = cave[y3][x3].feat;
}
if (is_floor_grid(c_ptr))
{
if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
{
- if ((cave[y3][x3].info & CAVE_ROOM) || (randint(100) > 95))
+ if ((cave[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
{
/* do second half only if works + if have hit a room */
retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
return TRUE;
}
}
+