X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Ffloor-generate.c;h=95423b52283f664b22df6b80072c90ac8b463e1e;hb=b1380fe955b9e95ccfa15afc3757b819860d7aeb;hp=f4dcd2ce00fb1c407cdac78ea8fdab68a72cb913;hpb=fe0b88a4c55133c0e21edd46db41775e4c45c267;p=hengband%2Fhengband.git diff --git a/src/floor-generate.c b/src/floor-generate.c index f4dcd2ce0..95423b522 100644 --- a/src/floor-generate.c +++ b/src/floor-generate.c @@ -97,17 +97,34 @@ */ #include "angband.h" -#include "generate.h" +#include "util.h" +#include "core.h" +#include "bldg.h" + +#include "cmd-dump.h" #include "grid.h" #include "rooms.h" +#include "dungeon.h" +#include "floor.h" +#include "floor-save.h" #include "floor-streams.h" #include "floor-generate.h" +#include "floor-events.h" +#include "floor-generate.h" +#include "feature.h" #include "trap.h" #include "monster.h" #include "quest.h" #include "player-status.h" #include "wild.h" #include "monster-status.h" +#include "dungeon-file.h" +#include "init.h" +#include "feature.h" +#include "spells.h" + +#include "world.h" +#include "view-mainwindow.h" int dun_tun_rnd; int dun_tun_chg; @@ -127,17 +144,17 @@ dun_data *dun; * @param y 基準のy座標 * @param x 基準のx座標 * @return 隣接する外壁の数 - * @note Assumes "in_bounds(y, x)" + * @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(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++; + 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); } @@ -149,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 = ¤t_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; @@ -159,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; } @@ -172,7 +189,7 @@ static bool alloc_stairs_aux(POSITION y, POSITION x, int walls) * @param walls 最低減隣接させたい外壁の数 * @return 規定数通りに生成に成功したらTRUEを返す。 */ -static bool alloc_stairs(IDX feat, int num, int walls) +static bool alloc_stairs(floor_type *floor_ptr, FEAT_IDX feat, int num, int walls) { int i; int shaft_num = 0; @@ -182,17 +199,17 @@ static bool alloc_stairs(IDX feat, int num, int walls) if (have_flag(f_ptr->flags, FF_LESS)) { /* No up stairs in town or in ironman mode */ - if (ironman_downward || !current_floor_ptr->dun_level) return TRUE; + if (ironman_downward || !floor_ptr->dun_level) return TRUE; - if (current_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)) { - QUEST_IDX q_idx = quest_number(current_floor_ptr->dun_level); + QUEST_IDX q_idx = quest_number(floor_ptr->dun_level); /* No downstairs on quest levels */ - if (current_floor_ptr->dun_level > 1 && q_idx) + if (floor_ptr->dun_level > 1 && q_idx) { monster_race *r_ptr = &r_info[quest[q_idx].r_idx]; @@ -202,13 +219,11 @@ static bool alloc_stairs(IDX feat, int num, int walls) } /* No downstairs at the bottom */ - if (current_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 ((current_floor_ptr->dun_level < d_info[p_ptr->dungeon_idx].maxdepth-1) && !quest_number(current_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; } - - /* Paranoia */ else return FALSE; @@ -223,11 +238,11 @@ static bool alloc_stairs(IDX feat, int num, int walls) int candidates = 0; int pick; - for (y = 1; y < current_floor_ptr->height - 1; y++) + for (y = 1; y < floor_ptr->height - 1; y++) { - for (x = 1; x < current_floor_ptr->width - 1; x++) + 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++; @@ -249,11 +264,11 @@ static bool alloc_stairs(IDX feat, int num, int walls) /* Choose a random one */ pick = randint1(candidates); - for (y = 1; y < current_floor_ptr->height - 1; y++) + for (y = 1; y < floor_ptr->height - 1; y++) { - for (x = 1; x < current_floor_ptr->width - 1; x++) + 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--; @@ -264,7 +279,7 @@ static bool alloc_stairs(IDX feat, int num, int walls) if (!pick) break; } - g_ptr = ¤t_floor_ptr->grid_array[y][x]; + g_ptr = &floor_ptr->grid_array[y][x]; /* Clear possible garbage of hidden trap */ g_ptr->mimic = 0; @@ -289,7 +304,7 @@ static bool alloc_stairs(IDX feat, int num, int walls) * @param num 配置したい数 * @return 規定数通りに生成に成功したらTRUEを返す。 */ -static void alloc_object(int set, EFFECT_ID typ, int num) +static void alloc_object(floor_type *floor_ptr, int set, EFFECT_ID typ, int num) { POSITION y = 0, x = 0; int k; @@ -297,7 +312,7 @@ static void alloc_object(int set, EFFECT_ID typ, int num) grid_type *g_ptr; /* A small level has few objects. */ - num = num * current_floor_ptr->height * current_floor_ptr->width / (MAX_HGT*MAX_WID) +1; + num = num * floor_ptr->height * floor_ptr->width / (MAX_HGT*MAX_WID) +1; /* Place some objects */ for (k = 0; k < num; k++) @@ -309,19 +324,19 @@ static void alloc_object(int set, EFFECT_ID typ, int num) dummy++; - y = randint0(current_floor_ptr->height); - x = randint0(current_floor_ptr->width); + y = randint0(floor_ptr->height); + x = randint0(floor_ptr->width); - g_ptr = ¤t_floor_ptr->grid_array[y][x]; + g_ptr = &floor_ptr->grid_array[y][x]; /* Require "naked" floor grid */ 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 = (current_floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE; + room = (floor_ptr->grid_array[y][x].info & CAVE_ROOM) ? TRUE : FALSE; /* Require corridor? */ if ((set == ALLOC_SET_CORR) && room) continue; @@ -345,15 +360,15 @@ static void alloc_object(int set, EFFECT_ID typ, int num) { case ALLOC_TYP_RUBBLE: { - place_rubble(y, x); - current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR); + place_rubble(floor_ptr, y, x); + floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR); break; } case ALLOC_TYP_TRAP: { - place_trap(y, x); - current_floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR); + place_trap(floor_ptr, y, x); + floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR); break; } @@ -377,9 +392,11 @@ static void alloc_object(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; @@ -393,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 != 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 */ @@ -427,15 +444,15 @@ bool place_quest_monsters(void) grid_type *g_ptr; feature_type *f_ptr; - y = randint0(current_floor_ptr->height); - x = randint0(current_floor_ptr->width); + y = randint0(floor_ptr->height); + x = randint0(floor_ptr->width); - g_ptr = ¤t_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; } @@ -469,86 +486,86 @@ bool place_quest_monsters(void) * @details There were moved from cave_gen(). * @return なし */ -static void gen_caverns_and_lakes(void) +static void gen_caverns_and_lakes(dungeon_type *dungeon_ptr, floor_type *floor_ptr) { #ifdef ALLOW_CAVERNS_AND_LAKES /* Possible "destroyed" level */ - if ((current_floor_ptr->dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_DESTROY)) + if ((floor_ptr->dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (dungeon_ptr->flags1 & DF1_DESTROY)) { 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 */ if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed && - (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_MASK)) + (dungeon_ptr->flags1 & DF1_LAKE_MASK)) { int count = 0; - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_WATER) count += 3; - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_LAVA) count += 3; - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_RUBBLE) count += 3; - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_TREE) count += 3; + if (dungeon_ptr->flags1 & DF1_LAKE_WATER) count += 3; + if (dungeon_ptr->flags1 & DF1_LAKE_LAVA) count += 3; + if (dungeon_ptr->flags1 & DF1_LAKE_RUBBLE) count += 3; + if (dungeon_ptr->flags1 & DF1_LAKE_TREE) count += 3; - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_LAVA) + if (dungeon_ptr->flags1 & DF1_LAKE_LAVA) { /* Lake of Lava */ - if ((current_floor_ptr->dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA; + if ((floor_ptr->dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA; count -= 2; /* Lake of Lava2 */ - if (!dun->laketype && (current_floor_ptr->dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT; + if (!dun->laketype && (floor_ptr->dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT; count--; } - if ((d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_WATER) && !dun->laketype) + if ((dungeon_ptr->flags1 & DF1_LAKE_WATER) && !dun->laketype) { /* Lake of Water */ - if ((current_floor_ptr->dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER; + if ((floor_ptr->dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER; count -= 2; /* Lake of Water2 */ - if (!dun->laketype && (current_floor_ptr->dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT; + if (!dun->laketype && (floor_ptr->dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT; count--; } - if ((d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype) + if ((dungeon_ptr->flags1 & DF1_LAKE_RUBBLE) && !dun->laketype) { /* Lake of rubble */ - if ((current_floor_ptr->dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE; + if ((floor_ptr->dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE; count -= 2; /* Lake of rubble2 */ - if (!dun->laketype && (current_floor_ptr->dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT; + if (!dun->laketype && (floor_ptr->dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT; count--; } /* Lake of tree */ - if ((current_floor_ptr->dun_level > 5) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT; + if ((floor_ptr->dun_level > 5) && (dungeon_ptr->flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT; if (dun->laketype) { msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level.")); - build_lake(dun->laketype); + build_lake(floor_ptr, dun->laketype); } } - if ((current_floor_ptr->dun_level > DUN_CAVERN) && !dun->empty_level && - (d_info[p_ptr->dungeon_idx].flags1 & DF1_CAVERN) && - !dun->laketype && !dun->destroyed && (randint1(1000) < current_floor_ptr->dun_level)) + if ((floor_ptr->dun_level > DUN_CAVERN) && !dun->empty_level && + (dungeon_ptr->flags1 & DF1_CAVERN) && + !dun->laketype && !dun->destroyed && (randint1(1000) < floor_ptr->dun_level)) { dun->cavern = TRUE; - /* make a large fractal current_floor_ptr->grid_array in the middle of the dungeon */ + /* 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 */ /* Hack -- No destroyed "quest" levels */ - if (quest_number(current_floor_ptr->dun_level)) dun->destroyed = FALSE; + if (quest_number(floor_ptr->dun_level)) dun->destroyed = FALSE; } @@ -557,16 +574,18 @@ static void gen_caverns_and_lakes(void) * @details Note that "dun_body" adds about 4000 bytes of memory to the stack. * @return ダンジョン生成が全て無事に成功したらTRUEを返す。 */ -static bool cave_gen(void) +static bool cave_gen(floor_type *floor_ptr) { int i, k; POSITION y, x; dun_data dun_body; - current_floor_ptr->lite_n = 0; - current_floor_ptr->mon_lite_n = 0; - current_floor_ptr->redraw_n = 0; - current_floor_ptr->view_n = 0; + 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; + floor_ptr->view_n = 0; /* Global data */ dun = &dun_body; @@ -588,8 +607,8 @@ static bool cave_gen(void) dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX); /* Actual maximum number of rooms on this level */ - dun->row_rooms = current_floor_ptr->height / BLOCK_HGT; - dun->col_rooms = current_floor_ptr->width / BLOCK_WID; + dun->row_rooms = floor_ptr->height / BLOCK_HGT; + dun->col_rooms = floor_ptr->width / BLOCK_WID; /* Initialize the room table */ for (y = 0; y < dun->row_rooms; y++) @@ -604,7 +623,7 @@ static bool cave_gen(void) dun->cent_n = 0; /* Empty arena levels */ - if (ironman_empty_levels || ((d_info[p_ptr->dungeon_idx].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL)))) + if (ironman_empty_levels || ((dungeon_ptr->flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL)))) { dun->empty_level = TRUE; msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level.")); @@ -613,34 +632,34 @@ static bool cave_gen(void) if (dun->empty_level) { /* Start with floors */ - for (y = 0; y < current_floor_ptr->height; y++) + for (y = 0; y < floor_ptr->height; y++) { - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { place_floor_bold(y, x); } } /* Special boundary walls -- Top and bottom */ - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { place_extra_bold(0, x); - place_extra_bold(current_floor_ptr->height - 1, x); + place_extra_bold(floor_ptr->height - 1, x); } /* Special boundary walls -- Left and right */ - for (y = 1; y < (current_floor_ptr->height - 1); y++) + for (y = 1; y < (floor_ptr->height - 1); y++) { place_extra_bold(y, 0); - place_extra_bold(y, current_floor_ptr->width - 1); + place_extra_bold(y, floor_ptr->width - 1); } } else { /* Start with walls */ - for (y = 0; y < current_floor_ptr->height; y++) + for (y = 0; y < floor_ptr->height; y++) { - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { place_extra_bold(y, x); } @@ -648,18 +667,18 @@ static bool cave_gen(void) } /* Generate various caverns and lakes */ - gen_caverns_and_lakes(); + gen_caverns_and_lakes(dungeon_ptr, floor_ptr); /* Build maze */ - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE) + if (dungeon_ptr->flags1 & DF1_MAZE) { - build_maze_vault(current_floor_ptr->width/2-1, current_floor_ptr->height/2-1, current_floor_ptr->width-4, current_floor_ptr->height-4, FALSE); + build_maze_vault(floor_ptr->width/2-1, floor_ptr->height/2-1, floor_ptr->width-4, floor_ptr->height-4, FALSE); /* Place 3 or 4 down stairs near some walls */ - if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE; + if (!alloc_stairs(floor_ptr, feat_down_stair, rand_range(2, 3), 3)) return FALSE; /* Place 1 or 2 up stairs near some walls */ - if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE; + if (!alloc_stairs(floor_ptr, feat_up_stair, 1, 3)) return FALSE; } /* Build some rooms */ @@ -668,17 +687,17 @@ static bool cave_gen(void) 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 */ - if (current_floor_ptr->dun_level == 1) + if (floor_ptr->dun_level == 1) { while (one_in_(DUN_MOS_DEN)) { - place_trees(randint1(current_floor_ptr->width - 2), randint1(current_floor_ptr->height - 2)); + place_trees(floor_ptr, randint1(floor_ptr->width - 2), randint1(floor_ptr->height - 2)); } } @@ -686,12 +705,12 @@ static bool cave_gen(void) if (dun->destroyed) destroy_level(); /* Hack -- Add some rivers */ - if (one_in_(3) && (randint1(current_floor_ptr->dun_level) > 5)) + if (one_in_(3) && (randint1(floor_ptr->dun_level) > 5)) { FEAT_IDX feat1 = 0, feat2 = 0; /* Choose water mainly */ - if ((randint1(MAX_DEPTH * 2) - 1 > current_floor_ptr->dun_level) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_WATER_RIVER)) + if ((randint1(MAX_DEPTH * 2) - 1 > floor_ptr->dun_level) && (dungeon_ptr->flags1 & DF1_WATER_RIVER)) { feat1 = feat_deep_water; feat2 = feat_shallow_water; @@ -702,28 +721,36 @@ static bool cave_gen(void) FEAT_IDX select_shallow_feat[10]; int select_id_max = 0, selected; - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_LAVA_RIVER) + if (dungeon_ptr->flags1 & DF1_LAVA_RIVER) { select_deep_feat[select_id_max] = feat_deep_lava; select_shallow_feat[select_id_max] = feat_shallow_lava; select_id_max++; } - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_POISONOUS_RIVER) + if (dungeon_ptr->flags1 & DF1_POISONOUS_RIVER) { select_deep_feat[select_id_max] = feat_deep_poisonous_puddle; select_shallow_feat[select_id_max] = feat_shallow_poisonous_puddle; select_id_max++; } - if (d_info[p_ptr->dungeon_idx].flags1 & DF1_ACID_RIVER) + if (dungeon_ptr->flags1 & DF1_ACID_RIVER) { select_deep_feat[select_id_max] = feat_deep_acid_puddle; select_shallow_feat[select_id_max] = feat_shallow_acid_puddle; select_id_max++; } - selected = randint0(select_id_max); - feat1 = select_deep_feat[selected]; - feat2 = select_shallow_feat[selected]; + if (select_id_max > 0) + { + selected = randint0(select_id_max); + feat1 = select_deep_feat[selected]; + feat2 = select_shallow_feat[selected]; + } + else + { + feat1 = feat_deep_water; + feat2 = feat_shallow_water; + } } if (feat1) @@ -735,7 +762,7 @@ static bool cave_gen(void) ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) || !dun->laketype) { - add_river(feat1, feat2); + add_river(floor_ptr, feat1, feat2); } } } @@ -771,15 +798,15 @@ static bool cave_gen(void) dun->wall_n = 0; /* Connect the room to the previous room */ - if (randint1(current_floor_ptr->dun_level) > d_info[p_ptr->dungeon_idx].tunnel_percent) + if (randint1(floor_ptr->dun_level) > dungeon_ptr->tunnel_percent) { /* make cavelike tunnel */ - (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2); + (void)build_tunnel2(floor_ptr, dun->cent[i].x, dun->cent[i].y, x, y, 2, 2); } else { /* make normal tunnel */ - if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++; + if (!build_tunnel(floor_ptr, dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++; } if (tunnel_fail_count >= 2) return FALSE; @@ -791,7 +818,7 @@ static bool cave_gen(void) feature_type *f_ptr; y = dun->tunn[j].y; x = dun->tunn[j].x; - g_ptr = ¤t_floor_ptr->grid_array[y][x]; + g_ptr = &floor_ptr->grid_array[y][x]; f_ptr = &f_info[g_ptr->feat]; /* Clear previous contents (if not a lake), add a floor */ @@ -810,7 +837,7 @@ static bool cave_gen(void) grid_type *g_ptr; y = dun->wall[j].y; x = dun->wall[j].x; - g_ptr = ¤t_floor_ptr->grid_array[y][x]; + g_ptr = &floor_ptr->grid_array[y][x]; /* Clear mimic type */ g_ptr->mimic = 0; @@ -819,7 +846,7 @@ static bool cave_gen(void) place_floor_grid(g_ptr); /* Occasional doorway */ - if ((randint0(100) < dun_tun_pen) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)) + if ((randint0(100) < dun_tun_pen) && !(dungeon_ptr->flags1 & DF1_NO_DOORS)) { /* Place a random door */ place_random_door(y, x, TRUE); @@ -846,67 +873,67 @@ static bool cave_gen(void) } /* Place 3 or 4 down stairs near some walls */ - if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE; + if (!alloc_stairs(floor_ptr, feat_down_stair, rand_range(3, 4), 3)) return FALSE; /* Place 1 or 2 up stairs near some walls */ - if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE; + if (!alloc_stairs(floor_ptr, feat_up_stair, rand_range(1, 2), 3)) return FALSE; } if (!dun->laketype) { - if (d_info[p_ptr->dungeon_idx].stream2) + if (dungeon_ptr->stream2) { /* Hack -- Add some quartz streamers */ for (i = 0; i < DUN_STR_QUA; i++) { - build_streamer(d_info[p_ptr->dungeon_idx].stream2, DUN_STR_QC); + build_streamer(dungeon_ptr->stream2, DUN_STR_QC); } } - if (d_info[p_ptr->dungeon_idx].stream1) + if (dungeon_ptr->stream1) { /* Hack -- Add some magma streamers */ for (i = 0; i < DUN_STR_MAG; i++) { - build_streamer(d_info[p_ptr->dungeon_idx].stream1, DUN_STR_MC); + build_streamer(dungeon_ptr->stream1, DUN_STR_MC); } } } /* Special boundary walls -- Top and bottom */ - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { - place_bound_perm_wall(¤t_floor_ptr->grid_array[0][x]); - place_bound_perm_wall(¤t_floor_ptr->grid_array[current_floor_ptr->height - 1][x]); + place_bound_perm_wall(&floor_ptr->grid_array[0][x]); + place_bound_perm_wall(&floor_ptr->grid_array[floor_ptr->height - 1][x]); } /* Special boundary walls -- Left and right */ - for (y = 1; y < (current_floor_ptr->height - 1); y++) + for (y = 1; y < (floor_ptr->height - 1); y++) { - place_bound_perm_wall(¤t_floor_ptr->grid_array[y][0]); - place_bound_perm_wall(¤t_floor_ptr->grid_array[y][current_floor_ptr->width - 1]); + place_bound_perm_wall(&floor_ptr->grid_array[y][0]); + place_bound_perm_wall(&floor_ptr->grid_array[y][floor_ptr->width - 1]); } /* 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 = (current_floor_ptr->dun_level / 3); + k = (floor_ptr->dun_level / 3); if (k > 10) k = 10; if (k < 2) k = 2; /* Pick a base number of monsters */ - i = d_info[p_ptr->dungeon_idx].min_m_alloc_level; + i = dungeon_ptr->min_m_alloc_level; /* To make small levels a bit more playable */ - if (current_floor_ptr->height < MAX_HGT || current_floor_ptr->width < MAX_WID) + if (floor_ptr->height < MAX_HGT || floor_ptr->width < MAX_WID) { int small_tester = i; - i = (i * current_floor_ptr->height) / MAX_HGT; - i = (i * current_floor_ptr->width) / MAX_WID; + i = (i * floor_ptr->height) / MAX_HGT; + i = (i * floor_ptr->width) / MAX_WID; i += 1; if (i > small_tester) i = small_tester; @@ -924,39 +951,39 @@ static bool cave_gen(void) } /* Place some traps in the dungeon */ - alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k)); + alloc_object(floor_ptr, ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k)); /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */ - if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k)); + if (!(dungeon_ptr->flags1 & DF1_NO_CAVE)) alloc_object(floor_ptr, ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k)); /* Mega Hack -- No object at first level of deeper dungeon */ - if (p_ptr->enter_dungeon && current_floor_ptr->dun_level > 1) + if (p_ptr->enter_dungeon && floor_ptr->dun_level > 1) { /* No stair scum! */ - current_floor_ptr->object_level = 1; + floor_ptr->object_level = 1; } /* Put some objects in rooms */ - alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3)); + alloc_object(floor_ptr, ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3)); /* Put some objects/gold in the dungeon */ - alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3)); - alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3)); + alloc_object(floor_ptr, ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3)); + alloc_object(floor_ptr, ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3)); /* Set back to default */ - current_floor_ptr->object_level = current_floor_ptr->base_level; + floor_ptr->object_level = floor_ptr->base_level; /* Put the Guardian */ if (!alloc_guardian(TRUE)) return FALSE; - if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > current_floor_ptr->dun_level)) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) + if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > floor_ptr->dun_level)) && !(dungeon_ptr->flags1 & DF1_DARKNESS)) { - /* Lite the current_floor_ptr->grid_array */ - for (y = 0; y < current_floor_ptr->height; y++) + /* Lite the floor_ptr->grid_array */ + for (y = 0; y < floor_ptr->height; y++) { - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { - current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW); + floor_ptr->grid_array[y][x].info |= (CAVE_GLOW); } } } @@ -968,7 +995,7 @@ static bool cave_gen(void) * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW- * @return なし */ -static void build_arena(void) +static void build_arena(floor_type *floor_ptr) { POSITION yval, y_height, y_depth, xval, x_left, x_right; register int i, j; @@ -984,56 +1011,56 @@ static void build_arena(void) for (j = x_left; j <= x_right; j++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } for (i = y_depth; i >= y_depth - 5; i--) for (j = x_left; j <= x_right; j++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } for (j = x_left; j <= x_left + 17; j++) for (i = y_height; i <= y_depth; i++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } for (j = x_right; j >= x_right - 17; j--) for (i = y_height; i <= y_depth; i++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } place_extra_perm_bold(y_height+6, x_left+18); - current_floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); place_extra_perm_bold(y_depth-6, x_left+18); - current_floor_ptr->grid_array[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); place_extra_perm_bold(y_height+6, x_right-18); - current_floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); place_extra_perm_bold(y_depth-6, x_right-18); - current_floor_ptr->grid_array[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); i = y_height + 5; j = xval; - current_floor_ptr->grid_array[i][j].feat = f_tag_to_index("ARENA_GATE"); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); - player_place(i, j); + floor_ptr->grid_array[i][j].feat = f_tag_to_index("ARENA_GATE"); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + player_place(p_ptr, i, j); } /*! * @brief 挑戦時闘技場への入場処理 / Town logic flow for generation of arena -KMW- * @return なし */ -static void generate_challenge_arena(void) +static void generate_challenge_arena(floor_type *floor_ptr) { POSITION y, x; POSITION qy = 0; POSITION qx = 0; /* Smallest area */ - current_floor_ptr->height = SCREEN_HGT; - current_floor_ptr->width = SCREEN_WID; + floor_ptr->height = SCREEN_HGT; + floor_ptr->width = SCREEN_WID; /* Start with solid walls */ for (y = 0; y < MAX_HGT; y++) @@ -1044,7 +1071,7 @@ static void generate_challenge_arena(void) place_solid_perm_bold(y, x); /* Illuminate and memorize the walls */ - current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK); } } @@ -1054,11 +1081,11 @@ static void generate_challenge_arena(void) for (x = qx + 1; x < qx + SCREEN_WID - 1; x++) { /* Create empty floor */ - current_floor_ptr->grid_array[y][x].feat = feat_floor; + floor_ptr->grid_array[y][x].feat = feat_floor; } } - build_arena(); + build_arena(floor_ptr); if(!place_monster_aux(0, p_ptr->y + 5, p_ptr->x, arena_info[p_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET))) { @@ -1073,7 +1100,7 @@ static void generate_challenge_arena(void) * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW- * @return なし */ -static void build_battle(void) +static void build_battle(floor_type *floor_ptr) { POSITION yval, y_height, y_depth, xval, x_left, x_right; register int i, j; @@ -1089,54 +1116,54 @@ static void build_battle(void) for (j = x_left; j <= x_right; j++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } for (i = y_depth; i >= y_depth - 3; i--) for (j = x_left; j <= x_right; j++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } for (j = x_left; j <= x_left + 17; j++) for (i = y_height; i <= y_depth; i++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } for (j = x_right; j >= x_right - 17; j--) for (i = y_height; i <= y_depth; i++) { place_extra_perm_bold(i, j); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); } place_extra_perm_bold(y_height+6, x_left+18); - current_floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); place_extra_perm_bold(y_depth-4, x_left+18); - current_floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK); place_extra_perm_bold(y_height+6, x_right-18); - current_floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); place_extra_perm_bold(y_depth-4, x_right-18); - current_floor_ptr->grid_array[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK); 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++) { - current_floor_ptr->grid_array[i][j].feat = feat_permanent_glass_wall; + floor_ptr->grid_array[i][j].feat = feat_permanent_glass_wall; } i = y_height + 1; j = xval; - current_floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3"); - current_floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); - player_place(i, j); + floor_ptr->grid_array[i][j].feat = f_tag_to_index("BUILDING_3"); + floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK); + player_place(p_ptr, i, j); } /*! * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW- * @return なし */ -static void generate_gambling_arena(void) +static void generate_gambling_arena(floor_type *floor_ptr, player_type *creature_ptr) { POSITION y, x; MONSTER_IDX i; @@ -1152,7 +1179,7 @@ static void generate_gambling_arena(void) place_solid_perm_bold(y, x); /* Illuminate and memorize the walls */ - current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK); + floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK); } } @@ -1162,20 +1189,20 @@ static void generate_gambling_arena(void) for (x = qx + 1; x < qx + SCREEN_WID - 1; x++) { /* Create empty floor */ - current_floor_ptr->grid_array[y][x].feat = feat_floor; + floor_ptr->grid_array[y][x].feat = feat_floor; } } - build_battle(); + build_battle(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(¤t_floor_ptr->m_list[current_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 < m_max; i++) + for(i = 1; i < floor_ptr->m_max; i++) { - monster_type *m_ptr = ¤t_floor_ptr->m_list[i]; + monster_type *m_ptr = &floor_ptr->m_list[i]; if (!monster_is_valid(m_ptr)) continue; @@ -1188,26 +1215,26 @@ static void generate_gambling_arena(void) * @brief 固定マップクエストのフロア生成 / Generate a quest level * @return なし */ -static void generate_fixed_floor(void) +static void generate_fixed_floor(floor_type *floor_ptr) { POSITION x, y; /* Start with perm walls */ - for (y = 0; y < current_floor_ptr->height; y++) + for (y = 0; y < floor_ptr->height; y++) { - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { place_solid_perm_bold(y, x); } } /* Set the quest level */ - current_floor_ptr->base_level = quest[p_ptr->inside_quest].level; - current_floor_ptr->dun_level = current_floor_ptr->base_level; - current_floor_ptr->object_level = current_floor_ptr->base_level; - current_floor_ptr->monster_level = current_floor_ptr->base_level; + floor_ptr->base_level = quest[p_ptr->inside_quest].level; + floor_ptr->dun_level = floor_ptr->base_level; + floor_ptr->object_level = floor_ptr->base_level; + floor_ptr->monster_level = floor_ptr->base_level; - if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL); + if (record_stair) exe_write_diary(p_ptr, NIKKI_TO_QUEST, p_ptr->inside_quest, NULL); get_mon_num_prep(get_monster_hook(), NULL); init_flags = INIT_CREATE_DUNGEON; @@ -1219,22 +1246,23 @@ static void generate_fixed_floor(void) * @brief ダンジョン時のランダムフロア生成 / Make a real level * @return フロアの生成に成功したらTRUE */ -static bool level_gen(concptr *why) +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; @@ -1249,30 +1277,31 @@ static bool level_gen(concptr *why) while ((level_height == MAX_HGT/SCREEN_HGT) && (level_width == MAX_WID/SCREEN_WID)); } - current_floor_ptr->height = level_height * SCREEN_HGT; - current_floor_ptr->width = level_width * SCREEN_WID; + floor_ptr->height = level_height * SCREEN_HGT; + floor_ptr->width = level_width * SCREEN_WID; /* Assume illegal panel */ - panel_row_min = current_floor_ptr->height; - panel_col_min = current_floor_ptr->width; + panel_row_min = floor_ptr->height; + panel_col_min = floor_ptr->width; msg_format_wizard(CHEAT_DUNGEON, _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."), - current_floor_ptr->width, current_floor_ptr->height); + floor_ptr->width, floor_ptr->height); } else { /* Big dungeon */ - current_floor_ptr->height = MAX_HGT; - current_floor_ptr->width = MAX_WID; + floor_ptr->height = MAX_HGT; + floor_ptr->width = MAX_WID; /* Assume illegal panel */ - panel_row_min = current_floor_ptr->height; - panel_col_min = current_floor_ptr->width; + panel_row_min = floor_ptr->height; + panel_col_min = floor_ptr->width; } /* Make a dungeon */ - if (!cave_gen()) + floor_ptr->dungeon_idx = d_idx; + if (!cave_gen(floor_ptr)) { *why = _("ダンジョン生成に失敗", "could not place player"); return FALSE; @@ -1281,67 +1310,67 @@ static bool level_gen(concptr *why) } /*! - * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after current_floor_ptr->grid_array generation + * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after p_ptr->current_floor_ptr->grid_array generation * @return なし */ -void wipe_generate_random_floor_flags(void) +void wipe_generate_random_floor_flags(floor_type *floor_ptr) { POSITION x, y; - for (y = 0; y < current_floor_ptr->height; y++) + for (y = 0; y < floor_ptr->height; y++) { - for (x = 0; x < current_floor_ptr->width; x++) + for (x = 0; x < floor_ptr->width; x++) { /* Wipe unused flags */ - current_floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK); + floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK); } } - if (current_floor_ptr->dun_level) + if (floor_ptr->dun_level) { - for (y = 1; y < current_floor_ptr->height - 1; y++) + for (y = 1; y < floor_ptr->height - 1; y++) { - for (x = 1; x < current_floor_ptr->width - 1; x++) + for (x = 1; x < floor_ptr->width - 1; x++) { /* There might be trap */ - current_floor_ptr->grid_array[y][x].info |= CAVE_UNSAFE; + floor_ptr->grid_array[y][x].info |= CAVE_UNSAFE; } } } } /*! - * @brief フロアの全情報を初期化する / Clear and empty the current_floor_ptr->grid_array + * @brief フロアの全情報を初期化する / Clear and empty the p_ptr->current_floor_ptr->grid_array * @return なし */ -void clear_cave(void) +void clear_cave(floor_type *floor_ptr) { POSITION x, y; int i; /* Very simplified version of wipe_o_list() */ - (void)C_WIPE(current_floor_ptr->o_list, o_max, object_type); - o_max = 1; - o_cnt = 0; + (void)C_WIPE(floor_ptr->o_list, floor_ptr->o_max, object_type); + floor_ptr->o_max = 1; + floor_ptr->o_cnt = 0; /* Very simplified version of wipe_m_list() */ for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0; - (void)C_WIPE(current_floor_ptr->m_list, m_max, monster_type); - m_max = 1; - m_cnt = 0; - for (i = 0; i < MAX_MTIMED; i++) current_floor_ptr->mproc_max[i] = 0; + (void)C_WIPE(floor_ptr->m_list, floor_ptr->m_max, monster_type); + floor_ptr->m_max = 1; + floor_ptr->m_cnt = 0; + for (i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0; /* Pre-calc cur_num of pets in party_mon[] */ precalc_cur_num_of_pet(); - /* Start with a blank current_floor_ptr->grid_array */ + /* Start with a blank floor_ptr->grid_array */ for (y = 0; y < MAX_HGT; y++) { for (x = 0; x < MAX_WID; x++) { - grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x]; + grid_type *g_ptr = &floor_ptr->grid_array[y][x]; g_ptr->info = 0; g_ptr->feat = 0; g_ptr->o_idx = 0; @@ -1358,13 +1387,13 @@ void clear_cave(void) p_ptr->x = p_ptr->y = 0; /* Set the base level */ - current_floor_ptr->base_level = current_floor_ptr->dun_level; + floor_ptr->base_level = floor_ptr->dun_level; /* Reset the monster generation level */ - current_floor_ptr->monster_level = current_floor_ptr->base_level; + floor_ptr->monster_level = floor_ptr->base_level; /* Reset the object generation level */ - current_floor_ptr->object_level = current_floor_ptr->base_level; + floor_ptr->object_level = floor_ptr->base_level; } @@ -1373,65 +1402,59 @@ void clear_cave(void) * @return なし * @note Hack -- regenerate any "overflow" levels */ -void generate_random_floor(void) +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++) { bool okay = TRUE; - concptr why = NULL; - /* Clear and empty the current_floor_ptr->grid_array */ - clear_cave(); + clear_cave(floor_ptr); - /* Build the arena -KMW- */ if (p_ptr->inside_arena) { - /* Small arena */ - generate_challenge_arena(); + generate_challenge_arena(floor_ptr); } - /* Build the battle -KMW- */ - else if (p_ptr->inside_battle) + else if (p_ptr->phase_out) { - /* Small arena */ - generate_gambling_arena(); + generate_gambling_arena(floor_ptr, p_ptr); } else if (p_ptr->inside_quest) { - generate_fixed_floor(); + generate_fixed_floor(floor_ptr); } /* Build the town */ - else if (!current_floor_ptr->dun_level) + 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 */ else { - okay = level_gen(&why); + okay = level_gen(floor_ptr, &why); } /* Prevent object over-flow */ - if (o_max >= current_floor_ptr->max_o_idx) + if (floor_ptr->o_max >= current_world_ptr->max_o_idx) { why = _("アイテムが多すぎる", "too many objects"); okay = FALSE; } /* Prevent monster over-flow */ - else if (m_max >= current_floor_ptr->max_m_idx) + else if (floor_ptr->m_max >= current_world_ptr->max_m_idx) { why = _("モンスターが多すぎる", "too many monsters"); okay = FALSE; @@ -1447,12 +1470,12 @@ void generate_random_floor(void) } /* Glow deep lava and building entrances */ - glow_deep_lava_and_bldg(); + glow_deep_lava_and_bldg(floor_ptr); /* Reset flag */ p_ptr->enter_dungeon = FALSE; - wipe_generate_random_floor_flags(); + wipe_generate_random_floor_flags(floor_ptr); } /*! @@ -1532,7 +1555,7 @@ static void correct_dir(POSITION *rdir, POSITION *cdir, POSITION y1, POSITION x1 * outer -- outer room walls\n * solid -- solid room walls\n */ -bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2) +bool build_tunnel(floor_type *floor_ptr, POSITION row1, POSITION col1, POSITION row2, POSITION col2) { POSITION y, x; POSITION tmp_row, tmp_col; @@ -1576,7 +1599,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2) /* Extremely Important -- do not leave the dungeon */ - while (!in_bounds(tmp_row, tmp_col)) + while (!in_bounds(floor_ptr, tmp_row, tmp_col)) { /* Acquire the correct direction */ correct_dir(&row_dir, &col_dir, row1, col1, row2, col2); @@ -1592,7 +1615,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2) tmp_col = col1 + col_dir; } - g_ptr = ¤t_floor_ptr->grid_array[tmp_row][tmp_col]; + g_ptr = &floor_ptr->grid_array[tmp_row][tmp_col]; /* Avoid "solid" walls */ if (is_solid_grid(g_ptr)) continue; @@ -1605,8 +1628,8 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2) x = tmp_col + col_dir; /* Hack -- Avoid outer/solid walls */ - if (is_outer_bold(y, x)) continue; - if (is_solid_bold(y, x)) continue; + if (is_outer_bold(floor_ptr, y, x)) continue; + if (is_solid_bold(floor_ptr, y, x)) continue; /* Accept this location */ row1 = tmp_row; @@ -1627,7 +1650,7 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2) for (x = col1 - 1; x <= col1 + 1; x++) { /* Convert adjacent "outer" walls as "solid" walls */ - if (is_outer_bold(y, x)) + if (is_outer_bold(floor_ptr, y, x)) { /* Change the wall to a "solid" wall */ place_solid_noperm_bold(y, x); @@ -1726,20 +1749,20 @@ bool build_tunnel(POSITION row1, POSITION col1, POSITION row2, POSITION col2) * routine.\n * @todo 特に詳細な処理の意味を調査すべし */ -static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall) +static bool set_tunnel(floor_type *floor_ptr, POSITION *x, POSITION *y, bool affectwall) { int i, j, dx, dy; - grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x]; + grid_type *g_ptr = &floor_ptr->grid_array[*y][*x]; - if (!in_bounds(*y, *x)) return TRUE; + if (!in_bounds(floor_ptr, *y, *x)) return TRUE; if (is_inner_grid(g_ptr)) { return TRUE; } - if (is_extra_bold(*y, *x)) + if (is_extra_bold(floor_ptr, *y, *x)) { /* Save the tunnel location */ if (dun->tunn_n < TUNN_MAX) @@ -1753,7 +1776,7 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall) else return FALSE; } - if (is_floor_bold(*y, *x)) + if (is_floor_bold(floor_ptr, *y, *x)) { /* Don't do anything */ return TRUE; @@ -1776,7 +1799,7 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall) for (i = *x - 1; i <= *x + 1; i++) { /* Convert adjacent "outer" walls as "solid" walls */ - if (is_outer_bold(j, i)) + if (is_outer_bold(floor_ptr, j, i)) { /* Change the wall to a "solid" wall */ place_solid_noperm_bold(j, i); @@ -1785,7 +1808,7 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall) } /* Clear mimic type */ - current_floor_ptr->grid_array[*y][*x].mimic = 0; + floor_ptr->grid_array[*y][*x].mimic = 0; place_floor_bold(*y, *x); @@ -1802,12 +1825,12 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall) dy = 0; dx = 0; - while ((i > 0) && is_solid_bold(*y + dy, *x + dx)) + while ((i > 0) && is_solid_bold(floor_ptr, *y + dy, *x + dx)) { dy = randint0(3) - 1; dx = randint0(3) - 1; - if (!in_bounds(*y + dy, *x + dx)) + if (!in_bounds(floor_ptr, *y + dy, *x + dx)) { dx = 0; dy = 0; @@ -1844,26 +1867,26 @@ static bool set_tunnel(POSITION *x, POSITION *y, bool affectwall) * 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(&x1, &y1, FALSE); + set_tunnel(floor_ptr, &x1, &y1, FALSE); x1 = x + 1; y1 = y; - set_tunnel(&x1, &y1, FALSE); + set_tunnel(floor_ptr, &x1, &y1, FALSE); x1 = x; y1 = y - 1; - set_tunnel(&x1, &y1, FALSE); + set_tunnel(floor_ptr, &x1, &y1, FALSE); x1 = x; y1 = y + 1; - set_tunnel(&x1, &y1, FALSE); + set_tunnel(floor_ptr, &x1, &y1, FALSE); } @@ -1889,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; @@ -1909,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(&x, &y, TRUE)) + if (!set_tunnel(floor_ptr, &x, &y, TRUE)) { if (count > 50) { @@ -1919,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); } } } @@ -1932,15 +1955,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i { x = i; y = y1; - if (!set_tunnel(&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); } } } @@ -1950,15 +1973,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i { x = i; y = y1; - if (!set_tunnel(&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); } } @@ -1969,15 +1992,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i { x = x2; y = i; - if (!set_tunnel(&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); } } } @@ -1987,15 +2010,15 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i { x = x2; y = i; - if (!set_tunnel(&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); } } } @@ -2017,7 +2040,7 @@ static void short_seg_hack(POSITION x1, POSITION y1, POSITION x2, POSITION y2, i * 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(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff) +bool build_tunnel2(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, int cutoff) { POSITION x3, y3, dx, dy; POSITION changex, changey; @@ -2045,13 +2068,13 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, y3 = y1 + dy + changey; /* See if in bounds - if not - do not perturb point */ - if (!in_bounds(y3, x3)) + if (!in_bounds(floor_ptr, y3, x3)) { x3 = (x1 + x2) / 2; y3 = (y1 + y2) / 2; } /* cache g_ptr */ - g_ptr = ¤t_floor_ptr->grid_array[y3][x3]; + g_ptr = &floor_ptr->grid_array[y3][x3]; if (is_solid_grid(g_ptr)) { /* move midpoint a bit to avoid problem. */ @@ -2060,11 +2083,11 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, dy = 0; dx = 0; - while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx)) + while ((i > 0) && is_solid_bold(floor_ptr, y3 + dy, x3 + dx)) { dy = randint0(3) - 1; dx = randint0(3) - 1; - if (!in_bounds(y3 + dy, x3 + dx)) + if (!in_bounds(floor_ptr, y3 + dy, x3 + dx)) { dx = 0; dy = 0; @@ -2081,17 +2104,17 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, } y3 += dy; x3 += dx; - g_ptr = ¤t_floor_ptr->grid_array[y3][x3]; + g_ptr = &floor_ptr->grid_array[y3][x3]; } if (is_floor_grid(g_ptr)) { - if (build_tunnel2(x1, y1, x3, y3, type, cutoff)) + if (build_tunnel2(floor_ptr, x1, y1, x3, y3, type, cutoff)) { - if ((current_floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95)) + if ((floor_ptr->grid_array[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95)) { /* do second half only if works + if have hit a room */ - retval = build_tunnel2(x3, y3, x2, y2, type, cutoff); + retval = build_tunnel2(floor_ptr, x3, y3, x2, y2, type, cutoff); } else { @@ -2119,9 +2142,9 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, else { /* tunnel through walls */ - if (build_tunnel2(x1, y1, x3, y3, type, cutoff)) + if (build_tunnel2(floor_ptr, x1, y1, x3, y3, type, cutoff)) { - retval = build_tunnel2(x3, y3, x2, y2, type, cutoff); + retval = build_tunnel2(floor_ptr, x3, y3, x2, y2, type, cutoff); firstsuccede = TRUE; } else @@ -2134,7 +2157,7 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, if (firstsuccede) { /* only do this if the first half has worked */ - set_tunnel(&x3, &y3, TRUE); + set_tunnel(floor_ptr, &x3, &y3, TRUE); } /* return value calculated above */ return retval; @@ -2143,7 +2166,7 @@ bool build_tunnel2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int type, { /* 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;