OSDN Git Service

地形フラグ参照に関して, have_flag(f_flags_*(), フラグ)として使われて
[hengband/hengband.git] / src / generate.c
index a2ee034..74049cf 100644 (file)
@@ -118,12 +118,32 @@ dun_data *dun;
 
 
 /*
+ * Count the number of walls adjacent to the given grid.
+ *
+ * Note -- Assumes "in_bounds(y, x)"
+ *
+ * We count only granite walls and permanent walls.
+ */
+static int next_to_walls(int y, int x)
+{
+       int     k = 0;
+
+       if (cave_have_flag_bold(y + 1, x, FF_WALL)) k++;
+       if (cave_have_flag_bold(y - 1, x, FF_WALL)) k++;
+       if (cave_have_flag_bold(y, x + 1, FF_WALL)) k++;
+       if (cave_have_flag_bold(y, x - 1, FF_WALL)) k++;
+
+       return (k);
+}
+
+
+/*
  * Places some staircases near walls
  */
 static bool alloc_stairs(int feat, int num, int walls)
 {
        int          y, x, i, j, flag;
-       int          more_num = 0;
+       int          shaft_num = 0;
        cave_type    *c_ptr;
 
        feature_type *f_ptr = &f_info[feat];
@@ -134,7 +154,7 @@ static bool alloc_stairs(int feat, int num, int walls)
                if (ironman_downward || !dun_level) return TRUE;
 
                if (dun_level > d_info[dungeon_type].mindepth)
-                       more_num = (randint1(num+1))/2;
+                       shaft_num = (randint1(num+1))/2;
        }
        else if (have_flag(f_ptr->flags, FF_MORE))
        {
@@ -154,20 +174,24 @@ static bool alloc_stairs(int feat, int num, int walls)
                if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
 
                if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
-                       more_num = (randint1(num)+1)/2;
+                       shaft_num = (randint1(num)+1)/2;
        }
 
        /* Paranoia */
        else return FALSE;
 
+
+       /* There very few walls in an arena level */
+       if (dun->empty_level) walls = 1;
+
        /* Place "num" stairs */
        for (i = 0; i < num; i++)
        {
-               /* Place some stairs */
+               /* Try several times */
                for (flag = FALSE; !flag; )
                {
                        /* Try several times, then decrease "walls" */
-                       for (j = 0; !flag && j <= 3000; j++)
+                       for (j = 0; j <= 3000; j++)
                        {
                                /* Pick a random grid */
                                y = randint1(cur_hgt-2);
@@ -186,13 +210,13 @@ static bool alloc_stairs(int feat, int num, int walls)
                                c_ptr->mimic = 0;
 
                                /* Clear previous contents, add stairs */
-                               c_ptr->feat = (i < more_num) ? feat_state(feat, FF_SHAFT) : feat;
+                               c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
 
                                /* All done */
                                flag = TRUE;
+                               break;
                        }
 
-                       if (!flag) return FALSE;
                        /* Require fewer walls */
                        if (walls) walls--;
                }
@@ -322,7 +346,7 @@ static int next_to_corr(int y1, int x1)
                c_ptr = &cave[y][x];
 
                /* Skip non floors */
-               if (!cave_floor_grid(c_ptr)) continue;
+               if (cave_have_flag_grid(c_ptr, FF_WALL)) continue;
 
                /* Skip non "empty floor" grids */
                if (!is_floor_grid(c_ptr))
@@ -352,15 +376,15 @@ static bool possible_doorway(int y, int x)
        if (next_to_corr(y, x) >= 2)
        {
                /* Check Vertical */
-               if (have_flag(f_flags_bold(y - 1, x), FF_WALL) &&
-                   have_flag(f_flags_bold(y + 1, x), FF_WALL))
+               if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
+                   cave_have_flag_bold(y + 1, x, FF_WALL))
                {
                        return (TRUE);
                }
 
                /* Check Horizontal */
-               if (have_flag(f_flags_bold(y, x - 1), FF_WALL) &&
-                   have_flag(f_flags_bold(y, x + 1), FF_WALL))
+               if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
+                   cave_have_flag_bold(y, x + 1, FF_WALL))
                {
                        return (TRUE);
                }
@@ -380,7 +404,7 @@ static void try_door(int y, int x)
        if (!in_bounds(y, x)) return;
 
        /* Ignore walls */
-       if (!cave_floor_bold(y, x)) return;
+       if (cave_have_flag_bold(y, x, FF_WALL)) return;
 
        /* Ignore room grids */
        if (cave[y][x].info & (CAVE_ROOM)) return;
@@ -440,13 +464,10 @@ void place_quest_monsters(void)
                                /* Find an empty grid */
                                for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
                                {
-                                       cave_type *c_ptr;
-
                                        y = randint0(cur_hgt);
                                        x = randint0(cur_wid);
-                                       c_ptr = &cave[y][x];
 
-                                       if (!cave_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
+                                       if (!monster_can_enter(y, x, r_ptr, 0)) continue;
                                        if (distance(y, x, py, px) < 10) continue;
                                        else break;
                                }
@@ -622,14 +643,9 @@ static bool cave_gen(void)
        /* Fill the arrays of floors and walls in the good proportions */
        set_floor_and_wall(dungeon_type);
 
-
        /* Prepare allocation table */
        get_mon_num_prep(get_monster_hook(), NULL);
 
-       feat_wall_outer = d_info[dungeon_type].outer_wall;
-       feat_wall_inner = d_info[dungeon_type].inner_wall;
-       feat_wall_solid = d_info[dungeon_type].outer_wall;
-
        /* Randomize the dungeon creation values */
        dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
        dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
@@ -726,7 +742,7 @@ static bool cave_gen(void)
                /*
                 * Build each type of room in turn until we cannot build any more.
                 */
-               generate_rooms();
+               if (!generate_rooms()) return FALSE;
 
 
                /* Make a hole in the dungeon roof sometimes at level 1 */
@@ -1052,11 +1068,11 @@ static void build_arena(void)
 
        place_extra_perm_bold(y_height+6, x_left+18);
        cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height-6, x_left+18);
+       place_extra_perm_bold(y_depth-6, x_left+18);
        cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height+6, x_left-18);
+       place_extra_perm_bold(y_height+6, x_right-18);
        cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height-6, x_left-18);
+       place_extra_perm_bold(y_depth-6, x_right-18);
        cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
 
        i = y_height + 5;
@@ -1153,11 +1169,11 @@ static void build_battle(void)
 
        place_extra_perm_bold(y_height+6, x_left+18);
        cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height-4, x_left+18);
+       place_extra_perm_bold(y_depth-4, x_left+18);
        cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height+6, x_left-18);
+       place_extra_perm_bold(y_height+6, x_right-18);
        cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       place_extra_perm_bold(y_height-4, x_left-18);
+       place_extra_perm_bold(y_depth-4, x_right-18);
        cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
 
        i = y_height + 4;
@@ -1269,12 +1285,11 @@ static bool level_gen(cptr *why)
        {
                if (cheat_room)
 #ifdef JP
-msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
+                       msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
 #else
-                 msg_print("A 'small' dungeon level.");
+                       msg_print("A 'small' dungeon level.");
 #endif
 
-
                if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
                {
                        level_height = 1;
@@ -1464,12 +1479,10 @@ void clear_cave(void)
  * Generates a random dungeon level                    -RAK-
  *
  * Hack -- regenerate any "overflow" levels
- *
- * Hack -- allow auto-scumming via a gameplay option.
  */
 void generate_cave(void)
 {
-       int num;
+       int num, i;
 
        /* Fill the arrays of floors and walls in the good proportions */
        set_floor_and_wall(dungeon_type);
@@ -1484,9 +1497,14 @@ void generate_cave(void)
                /* Clear and empty the cave */
                clear_cave();
 
-               if (have_flag(f_info[d_info[dungeon_type].fill_type1].flags, FF_HAS_GOLD) ||
-                   have_flag(f_info[d_info[dungeon_type].fill_type2].flags, FF_HAS_GOLD) ||
-                   have_flag(f_info[d_info[dungeon_type].fill_type3].flags, FF_HAS_GOLD)) rating += 40;
+               for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
+               {
+                       if (have_flag(f_info[d_info[dungeon_type].fill[i].feat].flags, FF_HAS_GOLD))
+                       {
+                               rating += 40;
+                               break;
+                       }
+               }
 
                /* Build the arena -KMW- */
                if (p_ptr->inside_arena)