*/
bool new_player_spot(void)
{
- int y, x;
+ POSITION y = 0, x = 0;
int max_attempts = 10000;
cave_type *c_ptr;
while (max_attempts--)
{
/* Pick a legal spot */
- y = rand_range(1, cur_hgt - 2);
- x = rand_range(1, cur_wid - 2);
+ y = (POSITION)rand_range(1, cur_hgt - 2);
+ x = (POSITION)rand_range(1, cur_wid - 2);
c_ptr = &cave[y][x];
return FALSE;
/* Save the new player grid */
- py = y;
- px = x;
+ p_ptr->y = y;
+ p_ptr->x = x;
return TRUE;
}
}
/*!
+* @brief 鍵のかかったドアを配置する
+* @param y 配置したいフロアのY座標
+* @param x 配置したいフロアのX座標
+* @return なし
+*/
+void place_locked_door(int y, int x)
+{
+ if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
+ {
+ place_floor_bold(y, x);
+ }
+ else
+ {
+ set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
+ cave[y][x].info &= ~(CAVE_FLOOR);
+ delete_monster(y, x);
+ }
+}
+
+
+/*!
+* @brief 隠しドアを配置する
+* @param y 配置したいフロアのY座標
+* @param x 配置したいフロアのX座標
+* @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
+* @return なし
+*/
+void place_secret_door(int y, int x, int type)
+{
+ if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
+ {
+ place_floor_bold(y, x);
+ }
+ else
+ {
+ cave_type *c_ptr = &cave[y][x];
+
+ if (type == DOOR_DEFAULT)
+ {
+ type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
+ one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
+ ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
+ }
+
+ /* Create secret door */
+ place_closed_door(y, x, type);
+
+ if (type != DOOR_CURTAIN)
+ {
+ /* Hide by inner wall because this is used in rooms only */
+ c_ptr->mimic = feat_wall_inner;
+
+ /* 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;
+ }
+ }
+
+ c_ptr->info &= ~(CAVE_FLOOR);
+ delete_monster(y, x);
+ }
+}
+
+/*
+ * Routine used by the random vault creators to add a door to a location
+ * Note that range checking has to be done in the calling routine.
+ *
+ * The doors must be INSIDE the allocated region.
+ */
+void add_door(int x, int y)
+{
+ /* Need to have a wall in the center square */
+ if (!is_outer_bold(y, x)) return;
+
+ /* look at:
+ * x#x
+ * .#.
+ * x#x
+ *
+ * where x=don't care
+ * .=floor, #=wall
+ */
+
+ if (is_floor_bold(y - 1, x) && is_floor_bold(y + 1, x) &&
+ (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
+ {
+ /* secret door */
+ place_secret_door(y, x, DOOR_DEFAULT);
+
+ /* set boundarys so don't get wide doors */
+ place_solid_bold(y, x - 1);
+ place_solid_bold(y, x + 1);
+ }
+
+
+ /* look at:
+ * x#x
+ * .#.
+ * x#x
+ *
+ * where x = don't care
+ * .=floor, #=wall
+ */
+ if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
+ is_floor_bold(y, x - 1) && is_floor_bold(y, x + 1))
+ {
+ /* secret door */
+ place_secret_door(y, x, DOOR_DEFAULT);
+
+ /* set boundarys so don't get wide doors */
+ place_solid_bold(y - 1, x);
+ place_solid_bold(y + 1, x);
+ }
+}
+
+/*!
+* @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
+* @param y1 基準となるマスのY座標
+* @param x1 基準となるマスのX座標
+* @return 通路の数
+* @note Assumes "in_bounds(y1, x1)"
+* @details
+* XXX XXX This routine currently only counts actual "empty floor"\n
+* grids which are not in rooms. We might want to also count stairs,\n
+* open doors, closed doors, etc.
+*/
+static int next_to_corr(int y1, int x1)
+{
+ int i, y, x, k = 0;
+
+ cave_type *c_ptr;
+
+ /* Scan adjacent grids */
+ for (i = 0; i < 4; i++)
+ {
+ /* Extract the location */
+ y = y1 + ddy_ddd[i];
+ x = x1 + ddx_ddd[i];
+
+ /* Access the grid */
+ c_ptr = &cave[y][x];
+
+ /* Skip non floors */
+ if (cave_have_flag_grid(c_ptr, FF_WALL)) continue;
+
+ /* Skip non "empty floor" grids */
+ if (!is_floor_grid(c_ptr))
+ continue;
+
+ /* Skip grids inside rooms */
+ if (c_ptr->info & (CAVE_ROOM)) continue;
+
+ /* Count these grids */
+ k++;
+ }
+
+ /* Return the number of corridors */
+ return (k);
+}
+
+/*!
+* @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
+* @param y 判定を行いたいマスのY座標
+* @param x 判定を行いたいマスのX座標
+* @return ドアを設置可能ならばTRUEを返す
+* @note Assumes "in_bounds(y1, x1)"
+* @details
+* XXX XXX XXX\n
+* Assumes "in_bounds(y, x)"\n
+*/
+static bool possible_doorway(int y, int x)
+{
+ /* Count the adjacent corridors */
+ if (next_to_corr(y, x) >= 2)
+ {
+ /* Check Vertical */
+ if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
+ cave_have_flag_bold(y + 1, x, FF_WALL))
+ {
+ return (TRUE);
+ }
+
+ /* Check Horizontal */
+ if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
+ cave_have_flag_bold(y, x + 1, FF_WALL))
+ {
+ return (TRUE);
+ }
+ }
+
+ /* No doorway */
+ return (FALSE);
+}
+
+/*!
+* @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
+* @param y 設置を行いたいマスのY座標
+* @param x 設置を行いたいマスのX座標
+* @return なし
+*/
+void try_door(int y, int x)
+{
+ /* Paranoia */
+ if (!in_bounds(y, x)) return;
+
+ /* Ignore walls */
+ if (cave_have_flag_bold(y, x, FF_WALL)) return;
+
+ /* Ignore room grids */
+ if (cave[y][x].info & (CAVE_ROOM)) return;
+
+ /* Occasional door (if allowed) */
+ if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
+ {
+ /* Place a door */
+ place_random_door(y, x, FALSE);
+ }
+}
+
+
+/*!
* @brief 長方形の空洞を生成する / Make an empty square floor, for the middle of rooms
* @param x1 長方形の左端X座標(-1)
* @param x2 長方形の右端X座標(+1)
*/
void vault_monsters(int y1, int x1, int num)
{
- int k, i, y, x;
+ int k, i;
+ POSITION y, x;
cave_type *c_ptr;
/* Try to summon "num" monsters "near" the given location */
* outer -- outer room walls\n
* solid -- solid room walls\n
*/
-bool build_tunnel(int row1, int col1, int row2, int col2)
+bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2)
{
int y, x;
- int tmp_row, tmp_col;
+ POSITION tmp_row, tmp_col;
int row_dir, col_dir;
int start_row, start_col;
int main_loop_count = 0;
if (is_solid_bold(y, x)) continue;
/* Accept this location */
- row1 = tmp_row;
- col1 = tmp_col;
+ row1 = (POSITION)tmp_row;
+ col1 = (POSITION)tmp_col;
/* Save the wall location */
if (dun->wall_n < WALL_MAX)
* routine.\n
* @todo 特に詳細な処理の意味を調査すべし
*/
-static bool set_tunnel(int *x, int *y, bool affectwall)
+static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall)
{
int i, j, dx, dy;
* Note that this routine is only called on "even" squares - so it gives
* a natural checkerboard pattern.
*/
-static void create_cata_tunnel(int x, int y)
+static void create_cata_tunnel(POSITION x, POSITION y)
{
- int x1, y1;
+ POSITION x1, y1;
/* Build tunnel */
x1 = x - 1;
*/
static void short_seg_hack(int x1, int y1, int x2, int y2, int type, int count, bool *fail)
{
- int i, x, y;
+ int i;
+ POSITION x, y;
int length;
/* Check for early exit */
/*!
* @brief 特定の壁(永久壁など)を避けながら部屋間の通路を作成する / This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
* @return なし
- * @todo 詳細用調査
+ * @todo 詳細要調査
* @details
* Permanent rock is ignored in this path finding- sometimes there is no\n
* path around anyway -so there will be a crash if we try to find one.\n
* Note it is VERY important that the "stop if hit another passage" logic\n
* stays as is. Without this the dungeon turns into Swiss Cheese...\n
*/
-bool build_tunnel2(int x1, int y1, int x2, int y2, int type, int cutoff)
+bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff)
{
- int x3, y3, dx, dy;
+ POSITION x3, y3, dx, dy;
int changex, changey;
int length;
int i;
/* perturbation perpendicular to path */
changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
-
- /* perturbation perpendicular to path */
changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
/* Work out "mid" ponit */
/* Save the door location */
if (dun->door_n < DOOR_MAX)
{
- dun->door[dun->door_n].y = y3;
- dun->door[dun->door_n].x = x3;
+ dun->door[dun->door_n].y = (POSITION)y3;
+ dun->door[dun->door_n].x = (POSITION)x3;
dun->door_n++;
}
else return FALSE;
else
{
/* tunnel through walls */
- if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
+ if (build_tunnel2(x1, y1, (POSITION)x3, (POSITION)y3, type, cutoff))
{
- retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
+ retval = build_tunnel2((POSITION)x3, (POSITION)y3, x2, y2, type, cutoff);
firstsuccede = TRUE;
}
else