OSDN Git Service

プレイヤーの周囲にアイテムを置けない状況でアーティファクトを落とした
[hengband/hengband.git] / src / rooms.c
index 7614a1d..0171aa7 100644 (file)
@@ -44,9 +44,9 @@ static room_info_type room_info_normal[ROOM_T_MAX] =
        {{  0,  1,  1,  1,  2,  3,  5,  6,  8, 10, 13}, 10}, /*NEST     */
        {{  0,  1,  1,  2,  3,  4,  6,  8, 10, 13, 16}, 10}, /*PIT      */
        {{  0,  1,  1,  1,  2,  2,  3,  5,  6,  8, 10}, 10}, /*LESSER_V */
-       {{  0,  0,  1,  1,  1,  1,  1,  1,  2,  2,  3}, 20}, /*GREATER_V*/
+       {{  0,  0,  1,  1,  1,  2,  2,  2,  3,  3,  4}, 20}, /*GREATER_V*/
        {{  0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE  */
-       {{  0,  1,  1,  1,  1,  1,  1,  2,  2,  3,  3}, 10}, /*RANDOM_V */
+       {{  0,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2}, 10}, /*RANDOM_V */
        {{  0,  4,  8, 12, 16, 20, 24, 28, 32, 36, 40},  3}, /*OVAL     */
        {{  1,  6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT    */
        {{  0,  0,  1,  1,  1,  2,  3,  4,  5,  6,  8}, 20}, /*TRAP_PIT */
@@ -83,6 +83,7 @@ static void place_locked_door(int y, int x)
        {
                set_cave_feat(y, x, FEAT_DOOR_HEAD+randint1(7));
                cave[y][x].info &= ~(CAVE_FLOOR);
+               delete_monster(y, x);
        }
 }
 
@@ -103,13 +104,17 @@ static void place_secret_door(int y, int x)
                c_ptr->mimic = feat_wall_inner;
 
                /* Floor type terrain cannot hide a door */
-               if (feat_floor(c_ptr->mimic))
+               if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
                {
-                       c_ptr->feat = c_ptr->mimic;
+                       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);
        }
 }
 
@@ -339,18 +344,6 @@ static bool find_space(int *y, int *x, int height, int width)
        if (dun->row_rooms < blocks_high) return FALSE;
        if (dun->col_rooms < blocks_wide) return FALSE;
 
-#if 0
-       /* Sometimes, little rooms like to have more space. */
-       if (blocks_wide == 2)
-       {
-               if (one_in_(3)) blocks_wide = 3;
-       }
-       else if (blocks_wide == 1)
-       {
-               if (one_in_(2)) blocks_wide = rand_range(2, 3);
-       }
-#endif
-
        /* Initiallize */
        candidates = 0;
 
@@ -495,7 +488,20 @@ static bool build_type1(void)
        ysize = y1 + y2 + 1;
 
        /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
+       if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
+       {
+               /* Limit to the minimum room size, and retry */
+               y1 = 1;
+               x1 = 1;
+               y2 = 1;
+               x2 = 1;
+
+               xsize = x1 + x2 + 1;
+               ysize = y1 + y2 + 1;
+
+               /* Find and reserve some space in the dungeon.  Get center of room. */
+               if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
+       }
 
        /* Choose lite or dark */
        light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
@@ -1371,7 +1377,7 @@ static bool vault_aux_jelly(int r_idx)
        if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
 
        /* Require icky thing, jelly, mold, or mushroom */
-       if (!strchr("ijm,", r_ptr->d_char)) return (FALSE);
+       if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
 
        /* Okay */
        return (TRUE);
@@ -1457,7 +1463,7 @@ static bool vault_aux_kennel(int r_idx)
        if (!vault_monster_okay(r_idx)) return (FALSE);
 
        /* Require a Zephyr Hound or a dog */
-       if (!strchr("CZ", r_ptr->d_char)) return (FALSE);
+       if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
   
        /* Okay */
        return (TRUE);
@@ -1473,9 +1479,9 @@ static bool vault_aux_mimic(int r_idx)
 
        /* Validate the monster */
        if (!vault_monster_okay(r_idx)) return (FALSE);
-  
+
        /* Require mimic */
-       if (!strchr("!|$?=", r_ptr->d_char)) return (FALSE);
+       if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
 
        /* Okay */
        return (TRUE);
@@ -2087,7 +2093,7 @@ static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
  * "appropriate" non-unique monsters for the nest.
  *
  * Note that the "get_mon_num()" function may (rarely) fail, in which
- * case the nest will be empty, and will not affect the level rating.
+ * case the nest will be empty.
  *
  * Note that "monster nests" will never contain "unique" monsters.
  */
@@ -2126,7 +2132,7 @@ static bool build_type5(void)
                while (attempts--)
                {
                        /* Get a (hard) monster type */
-                       r_idx = get_mon_num(dun_level + 10);
+                       r_idx = get_mon_num(dun_level + 11);
                        r_ptr = &r_info[r_idx];
 
                        /* Decline incorrect alignment */
@@ -2234,15 +2240,6 @@ static bool build_type5(void)
 #endif
        }
 
-       /* Increase the level rating */
-       rating += 10;
-
-       /* (Sometimes) Cause a "special feeling" (for "Monster Nests") */
-       if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
-       {
-               good_item_flag = TRUE;
-       }
-
        /* Place some monsters */
        for (y = yval - 2; y <= yval + 2; y++)
        {
@@ -2315,7 +2312,7 @@ static bool build_type5(void)
  * "appropriate" non-unique monsters for the pit.
  *
  * Note that the "get_mon_num()" function may (rarely) fail, in which case
- * the pit will be empty, and will not effect the level rating.
+ * the pit will be empty.
  *
  * Note that "monster pits" will never contain "unique" monsters.
  */
@@ -2355,7 +2352,7 @@ static bool build_type6(void)
                while (attempts--)
                {
                        /* Get a (hard) monster type */
-                       r_idx = get_mon_num(dun_level + 10);
+                       r_idx = get_mon_num(dun_level + 11);
                        r_ptr = &r_info[r_idx];
 
                        /* Decline incorrect alignment */
@@ -2495,15 +2492,6 @@ static bool build_type6(void)
                }
        }
 
-       /* Increase the level rating */
-       rating += 10;
-
-       /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
-       if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
-       {
-               good_item_flag = TRUE;
-       }
-
        /* Top and bottom rows */
        for (x = xval - 9; x <= xval + 9; x++)
        {
@@ -2661,9 +2649,7 @@ static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
 
                                /* Permanent wall (inner) */
                        case 'X':
-                               c_ptr->feat = FEAT_PERM_INNER;
-                               c_ptr->info &= ~(CAVE_MASK);
-                               c_ptr->info |= CAVE_INNER;
+                               place_inner_perm_grid(c_ptr);
                                break;
 
                                /* Treasure/trap */
@@ -2916,16 +2902,6 @@ static bool build_type7(void)
        if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
 #endif
 
-       /* Boost the rating */
-       rating += v_ptr->rat;
-
-       /* (Sometimes) Cause a special feeling */
-       if ((dun_level <= 50) ||
-               (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
-       {
-               good_item_flag = TRUE;
-       }
-
        /* Hack -- Build the vault */
        build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
                    v_text + v_ptr->text, xoffset, yoffset, transno);
@@ -3024,16 +3000,6 @@ static bool build_type8(void)
        if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
 #endif
 
-       /* Boost the rating */
-       rating += v_ptr->rat;
-
-       /* (Sometimes) Cause a special feeling */
-       if ((dun_level <= 50) ||
-           (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
-       {
-               good_item_flag = TRUE;
-       }
-
        /* Hack -- Build the vault */
        build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
                    v_text + v_ptr->text, xoffset, yoffset, transno);
@@ -3130,7 +3096,7 @@ static void store_height(int x, int y, int val)
 * The tricky part is making sure the created cave is connected.  This
 * is done by 'filling' from the inside and only keeping the 'filled'
 * floor.  Walls bounding the 'filled' floor are also kept.  Everything
-* else is converted to the normal granite FEAT_WALL_EXTRA.
+* else is converted to the normal _extra_.
  */
 
 
@@ -3184,10 +3150,10 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
        fill_data.ymin = y0 - yhsize;
        fill_data.xmax = x0 + xhsize;
        fill_data.ymax = y0 + yhsize;
-       
+
        /* Store cutoff in global for quick access */
        fill_data.c1 = cutoff;
-       
+
        /*
        * Scale factor for middle points:
        * About sqrt(2) * 256 - correct for a square lattice
@@ -3203,8 +3169,8 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
        {
                for (j = 0; j <= ysize; j++)
                {
-                       /* 255 is a flag for "not done yet" */
-                       cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = 255;
+                       /* -1 is a flag for "not done yet" */
+                       cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
                        /* Clear icky flag because may be redoing the cave */
                        cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
                }
@@ -3236,11 +3202,11 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
                xhstep /= 2;
                ystep = yhstep;
                yhstep /= 2;
-               
+
                /* cache well used values */
                xstep2 = xstep / 256;
                ystep2 = ystep / 256;
-               
+
                xhstep2 = xhstep / 256;
                yhstep2 = yhstep / 256;
 
@@ -3252,10 +3218,10 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
                                /* cache often used values */
                                ii = i / 256 + fill_data.xmin;
                                jj = j / 256 + fill_data.ymin;
-                               
+
                                /* Test square */
-                               if (cave[jj][ii].feat == 255)
-                               {                               
+                               if (cave[jj][ii].feat == -1)
+                               {
                                        if (xhstep2 > grd)
                                        {
                                                /* If greater than 'grid' level then is random */
@@ -3282,9 +3248,9 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
                                /* cache often used values */
                                ii = i / 256 + fill_data.xmin;
                                jj = j / 256 + fill_data.ymin;
-                               
+
                                /* Test square */
-                               if (cave[jj][ii].feat == 255)
+                               if (cave[jj][ii].feat == -1)
                                {
                                        if (xhstep2 > grd)
                                        {
@@ -3311,10 +3277,10 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
                                /* cache often used values */
                                ii = i / 256 + fill_data.xmin;
                                jj = j / 256 + fill_data.ymin;
-                               
+
                                /* Test square */
-                               if (cave[jj][ii].feat == 255)
-                               {                               
+                               if (cave[jj][ii].feat == -1)
+                               {
                                        if (xhstep2 > grd)
                                        {
                                                /* If greater than 'grid' level then is random */
@@ -3326,12 +3292,12 @@ static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug,
                                                xm = fill_data.xmin + (i - xhstep) / 256;
                                                xp = fill_data.xmin + (i + xhstep) / 256;
                                                ym = fill_data.ymin + (j - yhstep) / 256;
-                                               yp = fill_data.ymin + (j + yhstep) / 256;                                       
-                                       
+                                               yp = fill_data.ymin + (j + yhstep) / 256;
+
                                                /* 
                                                 * Average over all four corners + scale by diagsize to
                                                 * reduce the effect of the square grid on the shape of the fractal
-                                                */                             
+                                                */
                                                store_height(ii, jj,
                                                        (cave[ym][xm].feat + cave[yp][xm].feat
                                                        + cave[ym][xp].feat + cave[yp][xp].feat) / 4
@@ -3504,7 +3470,6 @@ static void cave_fill(byte y, byte x)
 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
 {
        int x, y, i, xhsize, yhsize;
-       
 
        /* offsets to middle from corner */
        xhsize = xsize / 2;
@@ -3676,7 +3641,7 @@ static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, b
         * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
         * Extra doors appear inside the system.  (Its not very noticeable though.)
         * This can be removed by "filling" from the outside in.  This allows a separation
-        * from FEAT_WALL_OUTER with FEAT_WALL_INNER.  (Internal walls are  F.W.OUTER instead.)
+        * from _outer_ with _inner_.  (Internal walls are  _outer_ instead.)
         * The extra effort for what seems to be only a minor thing (even non-existant if you
         * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
         * worth it.
@@ -3700,7 +3665,22 @@ static bool build_type9(void)
        ysize = randint1(15) * 2 + 6;
 
        /* Find and reserve some space in the dungeon.  Get center of room. */
-       if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
+       if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
+       {
+               /* Limit to the minimum room size, and retry */
+               xsize = 8;
+               ysize = 8;
+
+               /* Find and reserve some space in the dungeon.  Get center of room. */
+               if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
+               {
+                       /*
+                        * Still no space?!
+                        * Try normal room
+                        */
+                       return build_type1();
+               }
+       }
 
        light = done = FALSE;
        room = TRUE;
@@ -3905,9 +3885,8 @@ static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2,
                        /* turn off icky flag (no longer needed.) */
                        cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
 
-                       /* Light lava and trees */
-                       if ((cave[y0 + y - yhsize][x0 + x - xhsize].feat == FEAT_DEEP_LAVA) ||
-                               (cave[y0 + y - yhsize][x0 + x - xhsize].feat == FEAT_SHAL_LAVA))
+                       /* Light lava */
+                       if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
                        {
                                if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
                        }
@@ -4053,8 +4032,7 @@ static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
 
                         /* if floor, shallow water and lava */
                        if (is_floor_bold(y, x) ||
-                           (cave[y][x].feat == FEAT_SHAL_WATER) ||
-                           (cave[y][x].feat == FEAT_SHAL_LAVA))
+                           (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
                        {
                                /* The smaller 'value' is, the better the stuff */
                                if (value < 0)
@@ -4717,9 +4695,7 @@ static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
                        c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
 
                        /* Permanent walls */
-                       c_ptr->feat = FEAT_PERM_INNER;
-                       c_ptr->info &= ~(CAVE_MASK);
-                       c_ptr->info |= CAVE_INNER;
+                       place_inner_perm_grid(c_ptr);
                }
        }
 
@@ -5026,19 +5002,24 @@ static void build_castle_vault(int x0, int y0, int xsize, int ysize)
  * Note: no range checking is done so must be inside dungeon
  * This routine also stomps on doors
  */
-static void add_outer_wall(int x, int y, int light,
-                                                                       int x1, int y1, int x2, int y2)
+static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
 {
+       cave_type *c_ptr;
+       feature_type *f_ptr;
        int i, j;
 
        if (!in_bounds(y, x)) return;
 
+       c_ptr = &cave[y][x];
+
        /* hack- check to see if square has been visited before
        * if so, then exit (use room flag to do this) */
-       if (cave[y][x].info & CAVE_ROOM) return;
+       if (c_ptr->info & CAVE_ROOM) return;
 
        /* set room flag */
-       cave[y][x].info |= CAVE_ROOM;
+       c_ptr->info |= CAVE_ROOM;
+
+       f_ptr = &f_info[c_ptr->feat];
 
        if (is_floor_bold(y, x))
        {
@@ -5050,7 +5031,7 @@ static void add_outer_wall(int x, int y, int light,
                                         (y + j >= y1) && (y + j <= y2))
                                {
                                        add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
-                                       if (light) cave[y][x].info |= CAVE_GLOW;
+                                       if (light) c_ptr->info |= CAVE_GLOW;
                                }
                        }
                }
@@ -5059,12 +5040,12 @@ static void add_outer_wall(int x, int y, int light,
        {
                /* Set bounding walls */
                place_outer_bold(y, x);
-               if (light) cave[y][x].info |= CAVE_GLOW;
+               if (light) c_ptr->info |= CAVE_GLOW;
        }
-       else if (cave[y][x].feat == FEAT_PERM_OUTER)
+       else if (permanent_wall(f_ptr))
        {
                /* Set bounding walls */
-               if (light) cave[y][x].info |= CAVE_GLOW;
+               if (light) c_ptr->info |= CAVE_GLOW;
        }
 }
 
@@ -5326,16 +5307,6 @@ static bool build_type10(void)
        /* Find and reserve some space in the dungeon.  Get center of room. */
        if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
 
-       /* Boost the rating- higher than lesser vaults and lower than greater vaults */
-       rating += 10;
-
-       /* (Sometimes) Cause a special feeling */
-       if ((dun_level <= 50) ||
-           (randint1((dun_level - 40) * (dun_level - 40) + 1) < 400))
-       {
-               good_item_flag = TRUE;
-       }
-
        /* Select type of vault */
 #ifdef ALLOW_CAVERNS_AND_LAKES
        vtype = randint1(15);
@@ -5565,7 +5536,7 @@ static bool vault_aux_trapped_pit(int r_idx)
  * "appropriate" non-unique monsters for the pit.
  *
  * Note that the "get_mon_num()" function may (rarely) fail, in which case
- * the pit will be empty, and will not effect the level rating.
+ * the pit will be empty.
  *
  * Note that "monster pits" will never contain "unique" monsters.
  */
@@ -5806,15 +5777,6 @@ static bool build_type13(void)
                }
        }
 
-       /* Increase the level rating */
-       rating += 20;
-
-       /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
-       if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
-       {
-               good_item_flag = TRUE;
-       }
-
        for (i = 0; placing[i][2] >= 0; i++)
        {
                y = yval + placing[i][0];
@@ -5839,7 +5801,7 @@ static bool build_type14(void)
        bool light;
 
        cave_type *c_ptr;
-       byte trap;
+       s16b trap;
 
        /* Pick a room size */
        y1 = randint1(4);
@@ -5922,7 +5884,7 @@ static bool build_type14(void)
  * Note that we restrict the number of "crowded" rooms to reduce
  * the chance of overflowing the monster list during level creation.
  */
-bool room_build(int typ)
+static bool room_build(int typ)
 {
        /* Build a room */
        switch (typ)
@@ -5956,7 +5918,7 @@ bool room_build(int typ)
  * 
  * Generate rooms in dungeon.  Build bigger rooms at first.
  */
-void generate_rooms(void)
+bool generate_rooms(void)
 {
        int i;
        bool remain;
@@ -5976,7 +5938,6 @@ void generate_rooms(void)
        /* Assume normal cave */
        room_info_type *room_info_ptr = room_info_normal;
 
-
        /*
         * Initialize probability list.
         */
@@ -5998,7 +5959,7 @@ void generate_rooms(void)
         */
 
        /* Ironman sees only Greater Vaults */
-       if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON))))
+       if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
        {
                for (i = 0; i < ROOM_T_MAX; i++)
                {
@@ -6133,18 +6094,14 @@ void generate_rooms(void)
                                        }
                                }
                        }
-
-                       /* Stop building this type on failure. */
-                       else
-                       {
-                               room_num[room_type] = 0;
-                       }
                }
 
                /* End loop if no room remain */
                if (!remain) break;
        }
 
+       if (rooms_built < 1) return FALSE;
+
        if (cheat_room)
        {
 #ifdef JP
@@ -6153,4 +6110,6 @@ void generate_rooms(void)
                msg_format("Number of Rooms: %d", rooms_built);
 #endif
        }
+
+       return TRUE;
 }