OSDN Git Service

無双三段の途中で壁にぶつかる等して中断した時、MPを消費するように修正。
[hengband/hengband.git] / src / generate.c
index 61b6d5d..a5a542f 100644 (file)
@@ -118,23 +118,66 @@ 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 (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++;
+       if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++;
+       if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++;
+       if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++;
+
+       return (k);
+}
+
+
+/*
+ *  Helper function for alloc_stairs().
+ *
+ *  Is this a good location for stairs?
+ */
+static bool alloc_stairs_aux(int y, int x, int walls)
+{
+       /* Access the grid */
+       cave_type *c_ptr = &cave[y][x];
+
+       /* Require "naked" floor grid */
+       if (!is_floor_grid(c_ptr)) return FALSE;
+       if (pattern_tile(y, x)) return FALSE;
+       if (c_ptr->o_idx || c_ptr->m_idx) return FALSE;
+
+       /* Require a certain number of adjacent walls */
+       if (next_to_walls(y, x) < walls) return FALSE;
+
+       return TRUE;
+}
+
+
+/*
  * 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;
-       cave_type   *c_ptr;
+       int i;
+       int shaft_num = 0;
+
+       feature_type *f_ptr = &f_info[feat];
 
-       if (feat == FEAT_LESS)
+       if (have_flag(f_ptr->flags, FF_LESS))
        {
                /* No up stairs in town or in ironman mode */
                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 (feat == FEAT_MORE)
+       else if (have_flag(f_ptr->flags, FF_MORE))
        {
                int q_idx = quest_number(dun_level);
 
@@ -152,45 +195,80 @@ 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;
+
+
        /* Place "num" stairs */
        for (i = 0; i < num; i++)
        {
-               /* Place some stairs */
-               for (flag = FALSE; !flag; )
+               while (TRUE)
                {
-                       /* Try several times, then decrease "walls" */
-                       for (j = 0; !flag && j <= 3000; j++)
+                       int y = 0, x = 0;
+                       cave_type *c_ptr;
+
+                       int candidates = 0;
+                       int pick;
+
+                       for (y = 1; y < cur_hgt - 1; y++)
                        {
-                               /* Pick a random grid */
-                               y = randint1(cur_hgt-2);
-                               x = randint1(cur_wid-2);
+                               for (x = 1; x < cur_wid - 1; x++)
+                               {
+                                       if (alloc_stairs_aux(y, x, walls))
+                                       {
+                                               /* A valid space found */
+                                               candidates++;
+                                       }
+                               }
+                       }
 
-                               /* Access the grid */
-                               c_ptr = &cave[y][x];
+                       /* No valid place! */
+                       if (!candidates)
+                       {
+                               /* There are exactly no place! */
+                               if (walls <= 0) return FALSE;
 
-                               /* Require "naked" floor grid */
-                               if (!is_floor_grid(c_ptr) || pattern_tile(y,x) || c_ptr->o_idx || c_ptr->m_idx) continue;
+                               /* Decrease walls limit, and try again */
+                               walls--;
+                               continue;
+                       }
 
-                               /* Require a certain number of adjacent walls */
-                               if (next_to_walls(y, x) < walls) continue;
+                       /* Choose a random one */
+                       pick = randint1(candidates);
 
-                               /* Clear possible garbage of hidden trap */
-                               c_ptr->mimic = 0;
+                       for (y = 1; y < cur_hgt - 1; y++)
+                       {
+                               for (x = 1; x < cur_wid - 1; x++)
+                               {
+                                       if (alloc_stairs_aux(y, x, walls))
+                                       {
+                                               pick--;
 
-                               /* Clear previous contents, add stairs */
-                               if (i < more_num) c_ptr->feat = feat+0x07;
-                               else c_ptr->feat = feat;
+                                               /* Is this a picked one? */
+                                               if (!pick) break;
+                                       }
+                               }
 
-                               /* All done */
-                               flag = TRUE;
+                               if (!pick) break;
                        }
 
-                       if (!flag) return FALSE;
-                       /* Require fewer walls */
-                       if (walls) walls--;
+                       /* Access the grid */
+                       c_ptr = &cave[y][x];
+
+                       /* Clear possible garbage of hidden trap */
+                       c_ptr->mimic = 0;
+
+                       /* Clear previous contents, add stairs */
+                       c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
+
+                       /* No longer "FLOOR" */
+                       c_ptr->info &= ~(CAVE_FLOOR);
+
+                       /* Success */
+                       break;
                }
        }
        return TRUE;
@@ -318,7 +396,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))
@@ -348,15 +426,15 @@ static bool possible_doorway(int y, int x)
        if (next_to_corr(y, x) >= 2)
        {
                /* Check Vertical */
-               if ((cave[y-1][x].feat >= FEAT_MAGMA) &&
-                   (cave[y+1][x].feat >= FEAT_MAGMA))
+               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[y][x-1].feat >= FEAT_MAGMA) &&
-                   (cave[y][x+1].feat >= FEAT_MAGMA))
+               if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
+                   cave_have_flag_bold(y, x + 1, FF_WALL))
                {
                        return (TRUE);
                }
@@ -376,7 +454,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;
@@ -391,7 +469,7 @@ static void try_door(int y, int x)
 
 
 /* Place quest monsters */
-void place_quest_monsters(void)
+bool place_quest_monsters(void)
 {
        int i;
 
@@ -401,7 +479,7 @@ void place_quest_monsters(void)
                monster_race *r_ptr;
                u32b mode;
                int j;
-                       
+
                if (quest[i].status != QUEST_STATUS_TAKEN ||
                    (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
                     quest[i].type != QUEST_TYPE_RANDOM) ||
@@ -436,19 +514,24 @@ void place_quest_monsters(void)
                                /* Find an empty grid */
                                for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
                                {
-                                       cave_type *c_ptr;
+                                       cave_type    *c_ptr;
+                                       feature_type *f_ptr;
 
                                        y = randint0(cur_hgt);
                                        x = randint0(cur_wid);
+
                                        c_ptr = &cave[y][x];
+                                       f_ptr = &f_info[c_ptr->feat];
 
-                                       if (!cave_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
+                                       if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
+                                       if (!monster_can_enter(y, x, r_ptr, 0)) continue;
                                        if (distance(y, x, py, px) < 10) continue;
+                                       if (c_ptr->info & CAVE_ICKY) continue;
                                        else break;
                                }
 
                                /* Failed to place */
-                               if (!l) break;
+                               if (!l) return FALSE;
 
                                /* Try to place the monster */
                                if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
@@ -462,8 +545,13 @@ void place_quest_monsters(void)
                                        continue;
                                }
                        }
+
+                       /* Failed to place */
+                       if (k == SAFE_MAX_ATTEMPTS) return FALSE;
                }
        }
+
+       return TRUE;
 }
 
 
@@ -479,16 +567,19 @@ static void set_bound_perm_wall(cave_type *c_ptr)
        }
        else
        {
+               feature_type *f_ptr = &f_info[c_ptr->feat];
+
                /* Hack -- Decline boundary walls with known treasure  */
-               if ((c_ptr->feat == FEAT_MAGMA_K) || (c_ptr->feat == FEAT_QUARTZ_K))
-                       c_ptr->feat -= (FEAT_MAGMA_K - FEAT_MAGMA);
+               if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
+                   !have_flag(f_ptr->flags, FF_SECRET))
+                       c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
 
                /* Set boundary mimic */
                c_ptr->mimic = c_ptr->feat;
        }
 
        /* Add "solid" perma-wall */
-       c_ptr->feat = FEAT_PERM_SOLID;
+       place_solid_perm_grid(c_ptr);
 }
 
 
@@ -615,14 +706,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);
@@ -707,19 +793,21 @@ static bool cave_gen(void)
                build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
 
                /* Place 3 or 4 down stairs near some walls */
-               if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
+               if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
 
                /* Place 1 or 2 up stairs near some walls */
-               if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
+               if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
        }
 
        /* Build some rooms */
        else
        {
+               int tunnel_fail_count = 0;
+
                /*
                 * 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 */
@@ -742,23 +830,27 @@ static bool cave_gen(void)
                        /* Choose water or lava */
                        if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
                        {
-                               feat1 = FEAT_DEEP_WATER;
-                               feat2 = FEAT_SHAL_WATER;
+                               feat1 = feat_deep_water;
+                               feat2 = feat_shallow_water;
                        }
                        else if  (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
                        {
-                               feat1 = FEAT_DEEP_LAVA;
-                               feat2 = FEAT_SHAL_LAVA;
+                               feat1 = feat_deep_lava;
+                               feat2 = feat_shallow_lava;
                        }
                        else feat1 = 0;
 
-
-                       /* Only add river if matches lake type or if have no lake at all */
-                       if ((((dun->laketype == LAKE_T_LAVA) && (feat1 == FEAT_DEEP_LAVA)) ||
-                            ((dun->laketype == LAKE_T_WATER) && (feat1 == FEAT_DEEP_WATER)) ||
-                             !dun->laketype) && feat1)
+                       if (feat1)
                        {
-                               add_river(feat1, feat2);
+                               feature_type *f_ptr = &f_info[feat1];
+
+                               /* Only add river if matches lake type or if have no lake at all */
+                               if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
+                                   ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
+                                    !dun->laketype)
+                               {
+                                       add_river(feat1, feat2);
+                               }
                        }
                }
 
@@ -796,18 +888,21 @@ static bool cave_gen(void)
                        if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
                        {
                                /* make cave-like tunnel */
-                               build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
+                               (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
                        }
                        else
                        {
                                /* make normal tunnel */
-                               build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
+                               if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
                        }
 
+                       if (tunnel_fail_count >= 2) return FALSE;
+
                        /* Turn the tunnel into corridor */
                        for (j = 0; j < dun->tunn_n; j++)
                        {
                                cave_type *c_ptr;
+                               feature_type *f_ptr;
 
                                /* Access the grid */
                                y = dun->tunn[j].y;
@@ -815,10 +910,10 @@ static bool cave_gen(void)
 
                                /* Access the grid */
                                c_ptr = &cave[y][x];
+                               f_ptr = &f_info[c_ptr->feat];
 
                                /* Clear previous contents (if not a lake), add a floor */
-                               if ((c_ptr->feat < FEAT_DEEP_WATER) ||
-                                   (c_ptr->feat > FEAT_SHAL_LAVA))
+                               if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
                                {
                                        /* Clear mimic type */
                                        c_ptr->mimic = 0;
@@ -873,10 +968,10 @@ static bool cave_gen(void)
                }
 
                /* Place 3 or 4 down stairs near some walls */
-               if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
+               if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
 
                /* Place 1 or 2 up stairs near some walls */
-               if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
+               if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
        }
 
        if (!dun->laketype)
@@ -917,7 +1012,7 @@ static bool cave_gen(void)
        /* Determine the character location */
        if (!new_player_spot()) return FALSE;
 
-       place_quest_monsters();
+       if (!place_quest_monsters()) return FALSE;
 
        /* Basic "amount" */
        k = (dun_level / 3);
@@ -980,7 +1075,7 @@ msg_format("
        object_level = base_level;
 
        /* Put the Guardian */
-       (void)alloc_guardian();
+       if (!alloc_guardian(TRUE)) return FALSE;
 
        if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
        {
@@ -1016,40 +1111,40 @@ static void build_arena(void)
        for (i = y_height; i <= y_height + 5; i++)
                for (j = x_left; j <= x_right; j++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (i = y_depth; i >= y_depth - 5; i--)
                for (j = x_left; j <= x_right; j++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_left; j <= x_left + 17; j++)
                for (i = y_height; i <= y_depth; i++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_right; j >= x_right - 17; j--)
                for (i = y_height; i <= y_depth; i++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
+       place_extra_perm_bold(y_height+6, x_left+18);
        cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       cave[y_depth-6][x_left+18].feat = FEAT_PERM_EXTRA;
+       place_extra_perm_bold(y_depth-6, x_left+18);
        cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
+       place_extra_perm_bold(y_height+6, x_right-18);
        cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       cave[y_depth-6][x_right-18].feat = FEAT_PERM_EXTRA;
+       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;
        j = xval;
-       cave[i][j].feat = FEAT_BLDG_HEAD + 2;
+       cave[i][j].feat = f_tag_to_index("ARENA_GATE");
        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
        player_place(i, j);
 }
@@ -1074,7 +1169,7 @@ static void arena_gen(void)
                for (x = 0; x < MAX_WID; x++)
                {
                        /* Create "solid" perma-wall */
-                       cave[y][x].feat = FEAT_PERM_SOLID;
+                       place_solid_perm_bold(y, x);
 
                        /* Illuminate and memorize the walls */
                        cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
@@ -1087,7 +1182,7 @@ static void arena_gen(void)
                for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
                {
                        /* Create empty floor */
-                       cave[y][x].feat = FEAT_FLOOR;
+                       cave[y][x].feat = feat_floor;
                }
        }
 
@@ -1117,40 +1212,46 @@ static void build_battle(void)
        for (i = y_height; i <= y_height + 5; i++)
                for (j = x_left; j <= x_right; j++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (i = y_depth; i >= y_depth - 3; i--)
                for (j = x_left; j <= x_right; j++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_left; j <= x_left + 17; j++)
                for (i = y_height; i <= y_depth; i++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
        for (j = x_right; j >= x_right - 17; j--)
                for (i = y_height; i <= y_depth; i++)
                {
-                       cave[i][j].feat = FEAT_PERM_EXTRA;
+                       place_extra_perm_bold(i, j);
                        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
                }
 
-       cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
+       place_extra_perm_bold(y_height+6, x_left+18);
        cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       cave[y_depth-4][x_left+18].feat = FEAT_PERM_EXTRA;
+       place_extra_perm_bold(y_depth-4, x_left+18);
        cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
-       cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
+       place_extra_perm_bold(y_height+6, x_right-18);
        cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
-       cave[y_depth-4][x_right-18].feat = FEAT_PERM_EXTRA;
+       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;
+       for (i = y_height + 1; i <= y_height + 5; i++)
+               for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
+               {
+                       cave[i][j].feat = feat_permanent_glass_wall;
+               }
+
+       i = y_height + 1;
        j = xval;
-       cave[i][j].feat = FEAT_BLDG_HEAD + 3;
+       cave[i][j].feat = f_tag_to_index("BUILDING_3");
        cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
        player_place(i, j);
 }
@@ -1171,7 +1272,7 @@ static void battle_gen(void)
                for (x = 0; x < MAX_WID; x++)
                {
                        /* Create "solid" perma-wall */
-                       cave[y][x].feat = FEAT_PERM_SOLID;
+                       place_solid_perm_bold(y, x);
 
                        /* Illuminate and memorize the walls */
                        cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
@@ -1184,7 +1285,7 @@ static void battle_gen(void)
                for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
                {
                        /* Create empty floor */
-                       cave[y][x].feat = FEAT_FLOOR;
+                       cave[y][x].feat = feat_floor;
                }
        }
 
@@ -1192,9 +1293,9 @@ static void battle_gen(void)
 
        for(i=0;i<4;i++)
        {
-               place_monster_aux(0, py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
+               place_monster_aux(0, py + 8 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
                                  (PM_NO_KAGE | PM_NO_PET));
-               set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
+               set_friendly(&m_list[cave[py+8+(i/2)*4][px-2+(i%2)*4].m_idx]);
        }
        for(i = 1; i < m_max; i++)
        {
@@ -1224,7 +1325,7 @@ static void quest_gen(void)
        {
                for (x = 0; x < cur_wid; x++)
                {
-                       cave[y][x].feat = FEAT_PERM_SOLID;
+                       place_solid_perm_bold(y, x);
                }
        }
 
@@ -1257,12 +1358,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;
@@ -1292,7 +1392,7 @@ msg_print("
                panel_col_min = cur_wid;
 
                if (cheat_room)
-                 msg_format("X:%d, Y:%d.", cur_hgt, cur_wid);
+                 msg_format("X:%d, Y:%d.", cur_wid, cur_hgt);
        }
        else
        {
@@ -1319,34 +1419,11 @@ msg_print("
        else return TRUE;
 }
 
-static byte extract_feeling(void)
-{
-       /* Hack -- no feeling in the town */
-       if (!dun_level) return 0;
-
-       /* Hack -- Have a special feeling sometimes */
-       if (good_item_flag && !preserve_mode) return 1;
-
-       if (rating > 100) return 2;
-       if (rating > 80) return 3;
-       if (rating > 60) return 4;
-       if (rating > 40) return 5;
-       if (rating > 30) return 6;
-       if (rating > 20) return 7;
-       if (rating > 10) return 8;
-       if (rating > 0) return 9;
-
-       if((turn - old_turn) > TURNS_PER_TICK * TOWN_DAWN /2)
-               chg_virtue(V_PATIENCE, 1);
-
-       return 10;
-}
-
 
 /*
  * Wipe all unnecessary flags after cave generation
  */
-static void wipe_generate_cave_flags(void)
+void wipe_generate_cave_flags(void)
 {
        int x, y;
 
@@ -1391,6 +1468,7 @@ void clear_cave(void)
        C_WIPE(m_list, m_max, monster_type);
        m_max = 1;
        m_cnt = 0;
+       for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
 
        /* Pre-calc cur_num of pets in party_mon[] */
        precalc_cur_num_of_pet();
@@ -1439,12 +1517,6 @@ void clear_cave(void)
 
        /* Reset the object generation level */
        object_level = base_level;
-
-       /* Nothing special here yet */
-       good_item_flag = FALSE;
-
-       /* Nothing good here yet */
-       rating = 0;
 }
 
 
@@ -1452,8 +1524,6 @@ 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)
 {
@@ -1472,8 +1542,6 @@ void generate_cave(void)
                /* Clear and empty the cave */
                clear_cave();
 
-               if ((d_info[dungeon_type].fill_type1 == FEAT_MAGMA_K) || (d_info[dungeon_type].fill_type2 == FEAT_MAGMA_K) || (d_info[dungeon_type].fill_type3 == FEAT_MAGMA_K)) rating += 40;
-
                /* Build the arena -KMW- */
                if (p_ptr->inside_arena)
                {
@@ -1507,8 +1575,6 @@ void generate_cave(void)
                        okay = level_gen(&why);
                }
 
-               /* Extract the feeling */
-               feeling = extract_feeling();
 
                /* Prevent object over-flow */
                if (o_max >= max_o_idx)