OSDN Git Service

[Refactor] #38997 place_trap() に floor_type * 引数を追加. / Add floor_type * argument...
[hengband/hengband.git] / src / floor-generate.c
index 0ca2700..95423b5 100644 (file)
@@ -147,14 +147,14 @@ dun_data *dun;
  * @note Assumes "in_bounds(p_ptr->current_floor_ptr, y, x)"
  * @details We count only granite walls and permanent walls.
  */
-static int next_to_walls(POSITION y, POSITION x)
+static int next_to_walls(floor_type* floor_ptr, POSITION y, POSITION x)
 {
        int k = 0;
 
-       if (in_bounds(p_ptr->current_floor_ptr, y + 1, x) && is_extra_bold(p_ptr->current_floor_ptr, y + 1, x)) k++;
-       if (in_bounds(p_ptr->current_floor_ptr, y - 1, x) && is_extra_bold(p_ptr->current_floor_ptr, y - 1, x)) k++;
-       if (in_bounds(p_ptr->current_floor_ptr, y, x + 1) && is_extra_bold(p_ptr->current_floor_ptr, y, x + 1)) k++;
-       if (in_bounds(p_ptr->current_floor_ptr, y, x - 1) && is_extra_bold(p_ptr->current_floor_ptr, y, x - 1)) k++;
+       if (in_bounds(floor_ptr, y + 1, x) && is_extra_bold(floor_ptr, y + 1, x)) k++;
+       if (in_bounds(floor_ptr, y - 1, x) && is_extra_bold(floor_ptr, y - 1, x)) k++;
+       if (in_bounds(floor_ptr, y, x + 1) && is_extra_bold(floor_ptr, y, x + 1)) k++;
+       if (in_bounds(floor_ptr, y, x - 1) && is_extra_bold(floor_ptr, y, x - 1)) k++;
 
        return (k);
 }
@@ -166,9 +166,9 @@ static int next_to_walls(POSITION y, POSITION x)
  * @param walls 最低減隣接させたい外壁の数
  * @return 階段を生成して問題がないならばTRUEを返す。
  */
-static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
+static bool alloc_stairs_aux(floor_type *floor_ptr, POSITION y, POSITION x, int walls)
 {
-       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
 
        /* Require "naked" floor grid */
        if (!is_floor_grid(g_ptr)) return FALSE;
@@ -176,7 +176,7 @@ static bool alloc_stairs_aux(POSITION y, POSITION x, int walls)
        if (g_ptr->o_idx || g_ptr->m_idx) return FALSE;
 
        /* Require a certain number of adjacent walls */
-       if (next_to_walls(y, x) < walls) return FALSE;
+       if (next_to_walls(floor_ptr, y, x) < walls) return FALSE;
 
        return TRUE;
 }
@@ -201,7 +201,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                /* No up stairs in town or in ironman mode */
                if (ironman_downward || !floor_ptr->dun_level) return TRUE;
 
-               if (floor_ptr->dun_level > d_info[p_ptr->dungeon_idx].mindepth)
+               if (floor_ptr->dun_level > d_info[floor_ptr->dungeon_idx].mindepth)
                        shaft_num = (randint1(num+1))/2;
        }
        else if (have_flag(f_ptr->flags, FF_MORE))
@@ -219,9 +219,9 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                }
 
                /* No downstairs at the bottom */
-               if (floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) return TRUE;
+               if (floor_ptr->dun_level >= d_info[floor_ptr->dungeon_idx].maxdepth) return TRUE;
 
-               if ((floor_ptr->dun_level < d_info[p_ptr->dungeon_idx].maxdepth-1) && !quest_number(floor_ptr->dun_level+1))
+               if ((floor_ptr->dun_level < d_info[floor_ptr->dungeon_idx].maxdepth-1) && !quest_number(floor_ptr->dun_level+1))
                        shaft_num = (randint1(num)+1)/2;
        }
        else return FALSE;
@@ -242,7 +242,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                        {
                                for (x = 1; x < floor_ptr->width - 1; x++)
                                {
-                                       if (alloc_stairs_aux(y, x, walls))
+                                       if (alloc_stairs_aux(floor_ptr, y, x, walls))
                                        {
                                                /* A valid space found */
                                                candidates++;
@@ -268,7 +268,7 @@ static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int wall
                        {
                                for (x = 1; x < floor_ptr->width - 1; x++)
                                {
-                                       if (alloc_stairs_aux(y, x, walls))
+                                       if (alloc_stairs_aux(floor_ptr, y, x, walls))
                                        {
                                                pick--;
 
@@ -333,7 +333,7 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
                        if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
 
                        /* Avoid player location */
-                       if (player_bold(y, x)) continue;
+                       if (player_bold(p_ptr, y, x)) continue;
 
                        /* Check for "room" */
                        room = (floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
@@ -367,7 +367,7 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
 
                        case ALLOC_TYP_TRAP:
                        {
-                               place_trap(y, x);
+                               place_trap(floor_ptr, y, x);
                                floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
                                break;
                        }
@@ -392,9 +392,11 @@ static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num)
 
 /*!
  * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
+ * @param floor_ptr 配置するフロアの参照ポインタ
+ * @param subject_ptr 近隣への即出現を避けるためのプレイヤークリーチャー参照ポインタ
  * @return 成功したならばTRUEを返す
  */
-bool place_quest_monsters(void)
+bool place_quest_monsters(floor_type *floor_ptr, player_type *creature_ptr)
 {
        int i;
 
@@ -408,8 +410,8 @@ bool place_quest_monsters(void)
                if (quest[i].status != QUEST_STATUS_TAKEN ||
                    (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
                     quest[i].type != QUEST_TYPE_RANDOM) ||
-                   quest[i].level != p_ptr->current_floor_ptr->dun_level ||
-                   p_ptr->dungeon_idx != quest[i].dungeon ||
+                   quest[i].level != floor_ptr->dun_level ||
+                   creature_ptr->dungeon_idx != quest[i].dungeon ||
                    (quest[i].flags & QUEST_FLAG_PRESET))
                {
                        /* Ignore it */
@@ -442,15 +444,15 @@ bool place_quest_monsters(void)
                                        grid_type    *g_ptr;
                                        feature_type *f_ptr;
 
-                                       y = randint0(p_ptr->current_floor_ptr->height);
-                                       x = randint0(p_ptr->current_floor_ptr->width);
+                                       y = randint0(floor_ptr->height);
+                                       x = randint0(floor_ptr->width);
 
-                                       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
+                                       g_ptr = &floor_ptr->grid_array[y][x];
                                        f_ptr = &f_info[g_ptr->feat];
 
                                        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, p_ptr->y, p_ptr->x) < 10) continue;
+                                       if (distance(y, x, creature_ptr->y, creature_ptr->x) < 10) continue;
                                        if (g_ptr->info & CAVE_ICKY) continue;
                                        else break;
                                }
@@ -493,7 +495,7 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
                dun->destroyed = TRUE;
 
                /* extra rubble around the place looks cool */
-               build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
+               build_lake(floor_ptr, one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
        }
 
        /* Make a lake some of the time */
@@ -545,7 +547,7 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
                if (dun->laketype)
                {
                        msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
-                       build_lake(dun->laketype);
+                       build_lake(floor_ptr, dun->laketype);
                }
        }
 
@@ -558,7 +560,7 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
                /* make a large fractal floor_ptr->grid_array in the middle of the dungeon */
 
                msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
-               build_cavern();
+               build_cavern(floor_ptr);
        }
 #endif /* ALLOW_CAVERNS_AND_LAKES */
 
@@ -572,12 +574,14 @@ static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_p
  * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
  * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
  */
-static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
+static bool cave_gen(floor_type *floor_ptr)
 {
        int i, k;
        POSITION y, x;
        dun_data dun_body;
 
+       dungeon_type* dungeon_ptr = &d_info[floor_ptr->dungeon_idx];
+
        floor_ptr->lite_n = 0;
        floor_ptr->mon_lite_n = 0;
        floor_ptr->redraw_n = 0;
@@ -683,9 +687,9 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                int tunnel_fail_count = 0;
 
                /*
-                * Build each type of room in current_world_ptr->game_turn until we cannot build any more.
+                * Build each type of room in turn until we cannot build any more.
                 */
-               if (!generate_rooms()) return FALSE;
+               if (!generate_rooms(floor_ptr)) return FALSE;
 
 
                /* Make a hole in the dungeon roof sometimes at level 1 */
@@ -693,7 +697,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                {
                        while (one_in_(DUN_MOS_DEN))
                        {
-                               place_trees(randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
+                               place_trees(floor_ptr, randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2));
                        }
                }
 
@@ -758,7 +762,7 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
                                    ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
                                     !dun->laketype)
                                {
-                                       add_river(feat1, feat2);
+                                       add_river(floor_ptr, feat1, feat2);
                                }
                        }
                }
@@ -911,9 +915,9 @@ static bool cave_gen(dungeon_type* dungeon_ptr, floor_type *floor_ptr)
        }
 
        /* Determine the character location */
-       if (!new_player_spot()) return FALSE;
+       if (!new_player_spot(p_ptr)) return FALSE;
 
-       if (!place_quest_monsters()) return FALSE;
+       if (!place_quest_monsters(floor_ptr, p_ptr)) return FALSE;
 
        /* Basic "amount" */
        k = (floor_ptr->dun_level / 3);
@@ -1159,7 +1163,7 @@ static void build_battle(floor_type *floor_ptr)
  * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
  * @return なし
  */
-static void generate_gambling_arena(floor_type *floor_ptr)
+static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature_ptr)
 {
        POSITION y, x;
        MONSTER_IDX i;
@@ -1193,8 +1197,8 @@ static void generate_gambling_arena(floor_type *floor_ptr)
 
        for(i = 0; i < 4; i++)
        {
-               place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
-               set_friendly(&floor_ptr->m_list[floor_ptr->grid_array[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
+               place_monster_aux(0, creature_ptr->y + 8 + (i/2)*4, creature_ptr->x - 2 + (i%2)*4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
+               set_friendly(&floor_ptr->m_list[floor_ptr->grid_array[creature_ptr->y+8+(i/2)*4][creature_ptr->x-2+(i%2)*4].m_idx]);
        }
        for(i = 1; i < floor_ptr->m_max; i++)
        {
@@ -1245,19 +1249,20 @@ static void generate_fixed_floor(floor_type *floor_ptr)
 static bool level_gen(floor_type *floor_ptr, concptr *why)
 {
        int level_height, level_width;
+       DUNGEON_IDX d_idx = floor_ptr->dungeon_idx;
 
        if ((always_small_levels || ironman_small_levels ||
            (one_in_(SMALL_LEVEL) && small_levels) ||
-            (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER) ||
-           (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)) &&
-           !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BIG))
+            (d_info[d_idx].flags1 & DF1_BEGINNER) ||
+           (d_info[d_idx].flags1 & DF1_SMALLEST)) &&
+           !(d_info[d_idx].flags1 & DF1_BIG))
        {
-               if (d_info[p_ptr->dungeon_idx].flags1 & DF1_SMALLEST)
+               if (d_info[d_idx].flags1 & DF1_SMALLEST)
                {
                        level_height = 1;
                        level_width = 1;
                }
-               else if (d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
+               else if (d_info[d_idx].flags1 & DF1_BEGINNER)
                {
                        level_height = 2;
                        level_width = 2;
@@ -1295,7 +1300,8 @@ static bool level_gen(floor_type *floor_ptr, concptr *why)
        }
 
        /* Make a dungeon */
-       if (!cave_gen(&d_info[p_ptr->dungeon_idx], floor_ptr))
+       floor_ptr->dungeon_idx = d_idx;
+       if (!cave_gen(floor_ptr))
        {
                *why = _("ダンジョン生成に失敗", "could not place player");
                return FALSE;
@@ -1396,12 +1402,12 @@ void clear_cave(floor_type *floor_ptr)
  * @return なし
  * @note Hack -- regenerate any "overflow" levels
  */
-void generate_random_floor(floor_type *floor_ptr)
+void generate_floor(floor_type *floor_ptr)
 {
        int num;
 
        /* Fill the arrays of floors and walls in the good proportions */
-       set_floor_and_wall(p_ptr->dungeon_idx);
+       set_floor_and_wall(floor_ptr->dungeon_idx);
 
        /* Generate */
        for (num = 0; TRUE; num++)
@@ -1418,7 +1424,7 @@ void generate_random_floor(floor_type *floor_ptr)
 
                else if (p_ptr->phase_out)
                {
-                       generate_gambling_arena(floor_ptr);
+                       generate_gambling_arena(floor_ptr, p_ptr);
                }
 
                else if (p_ptr->inside_quest)
@@ -1430,8 +1436,8 @@ void generate_random_floor(floor_type *floor_ptr)
                else if (!floor_ptr->dun_level)
                {
                        /* Make the wilderness */
-                       if (p_ptr->wild_mode) wilderness_gen_small();
-                       else wilderness_gen();
+                       if (p_ptr->wild_mode) wilderness_gen_small(p_ptr, floor_ptr);
+                       else wilderness_gen(floor_ptr);
                }
 
                /* Build a real level */
@@ -1861,26 +1867,26 @@ static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool aff
 * Note that this routine is only called on "even" squares - so it gives
 * a natural checkerboard pattern.
 */
-static void create_cata_tunnel(POSITION x, POSITION y)
+static void create_cata_tunnel(floor_type *floor_ptr, POSITION x, POSITION y)
 {
        POSITION x1, y1;
 
        /* Build tunnel */
        x1 = x - 1;
        y1 = y;
-       set_tunnel(p_ptr->current_floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 
        x1 = x + 1;
        y1 = y;
-       set_tunnel(p_ptr->current_floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 
        x1 = x;
        y1 = y - 1;
-       set_tunnel(p_ptr->current_floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 
        x1 = x;
        y1 = y + 1;
-       set_tunnel(p_ptr->current_floor_ptr, &x1, &y1, FALSE);
+       set_tunnel(floor_ptr, &x1, &y1, FALSE);
 }
 
 
@@ -1906,7 +1912,7 @@ static void create_cata_tunnel(POSITION x, POSITION y)
 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near\n
 * the surface.\n
 */
-static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
+static void short_seg_hack(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int count, bool *fail)
 {
        int i;
        POSITION x, y;
@@ -1926,7 +1932,7 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                {
                        x = x1 + i * (x2 - x1) / length;
                        y = y1 + i * (y2 - y1) / length;
-                       if (!set_tunnel(p_ptr->current_floor_ptr, &x, &y, TRUE))
+                       if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                        {
                                if (count > 50)
                                {
@@ -1936,8 +1942,8 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                                }
 
                                /* solid wall - so try to go around */
-                               short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
-                               short_seg_hack(x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
+                               short_seg_hack(floor_ptr, x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
+                               short_seg_hack(floor_ptr, x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
                        }
                }
        }
@@ -1949,15 +1955,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = i;
                                y = y1;
-                               if (!set_tunnel(p_ptr->current_floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, i - 1, y1, 1, count, fail);
-                                       short_seg_hack(x, y, i + 1, y1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, i - 1, y1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, i + 1, y1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(i, y1);
+                                       create_cata_tunnel(floor_ptr, i, y1);
                                }
                        }
                }
@@ -1967,15 +1973,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = i;
                                y = y1;
-                               if (!set_tunnel(p_ptr->current_floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, i - 1, y1, 1, count, fail);
-                                       short_seg_hack(x, y, i + 1, y1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, i - 1, y1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, i + 1, y1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(i, y1);
+                                       create_cata_tunnel(floor_ptr, i, y1);
                                }
                        }
 
@@ -1986,15 +1992,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = x2;
                                y = i;
-                               if (!set_tunnel(p_ptr->current_floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, x2, i - 1, 1, count, fail);
-                                       short_seg_hack(x, y, x2, i + 1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, x2, i - 1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, x2, i + 1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(x2, i);
+                                       create_cata_tunnel(floor_ptr, x2, i);
                                }
                        }
                }
@@ -2004,15 +2010,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i
                        {
                                x = x2;
                                y = i;
-                               if (!set_tunnel(p_ptr->current_floor_ptr, &x, &y, TRUE))
+                               if (!set_tunnel(floor_ptr, &x, &y, TRUE))
                                {
                                        /* solid wall - so try to go around */
-                                       short_seg_hack(x, y, x2, i - 1, 1, count, fail);
-                                       short_seg_hack(x, y, x2, i + 1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, x2, i - 1, 1, count, fail);
+                                       short_seg_hack(floor_ptr, x, y, x2, i + 1, 1, count, fail);
                                }
                                if ((type == 3) && ((x + y) % 2))
                                {
-                                       create_cata_tunnel(x2, i);
+                                       create_cata_tunnel(floor_ptr, x2, i);
                                }
                        }
                }
@@ -2160,7 +2166,7 @@ bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2,
        {
                /* Do a short segment */
                retval = TRUE;
-               short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
+               short_seg_hack(floor_ptr, x1, y1, x2, y2, type, 0, &retval);
 
                /* Hack - ignore return value so avoid infinite loops */
                return TRUE;