3 * @brief ダンジョンの生成 / Dungeon generation
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen. \n
12 * Note that Level generation is *not* an important bottleneck,\n
13 * though it can be annoyingly slow on older machines... Thus\n
14 * we emphasize "simplicity" and "correctness" over "speed".\n
16 * This entire file is only needed for generating levels.\n
17 * This may allow smart compilers to only load it when needed.\n
19 * Consider the "v_info.txt" file for vault generation.\n
21 * In this file, we use the "special" granite and perma-wall sub-types,\n
22 * where "basic" is normal, "inner" is inside a room, "outer" is the\n
23 * outer wall of a room, and "solid" is the outer wall of the dungeon\n
24 * or any walls that may not be pierced by corridors. Thus the only\n
25 * wall type that may be pierced by a corridor is the "outer granite"\n
26 * type. The "basic granite" type yields the "actual" corridors.\n
28 * Note that we use the special "solid" granite wall type to prevent\n
29 * multiple corridors from piercing a wall in two adjacent locations,\n
30 * which would be messy, and we use the special "outer" granite wall\n
31 * to indicate which walls "surround" rooms, and may thus be "pierced"\n
32 * by corridors entering or leaving the room.\n
34 * Note that a tunnel which attempts to leave a room near the "edge"\n
35 * of the dungeon in a direction toward that edge will cause "silly"\n
36 * wall piercings, but will have no permanently incorrect effects,\n
37 * as long as the tunnel can *eventually* exit from another side.\n
38 * And note that the wall may not come back into the room by the\n
39 * hole it left through, so it must bend to the left or right and\n
40 * then optionally re-enter the room (at least 2 grids away). This\n
41 * is not a problem since every room that is large enough to block\n
42 * the passage of tunnels is also large enough to allow the tunnel\n
43 * to pierce the room itself several times.\n
45 * Note that no two corridors may enter a room through adjacent grids,\n
46 * they must either share an entryway or else use entryways at least\n
47 * two grids apart. This prevents "large" (or "silly") doorways.\n
49 * To create rooms in the dungeon, we first divide the dungeon up\n
50 * into "blocks" of 11x11 grids each, and require that all rooms\n
51 * occupy a rectangular group of blocks. As long as each room type\n
52 * reserves a sufficient number of blocks, the room building routines\n
53 * will not need to check bounds. Note that most of the normal rooms\n
54 * actually only use 23x11 grids, and so reserve 33x11 grids.\n
56 * Note that the use of 11x11 blocks (instead of the old 33x11 blocks)\n
57 * allows more variability in the horizontal placement of rooms, and\n
58 * at the same time has the disadvantage that some rooms (two thirds\n
59 * of the normal rooms) may be "split" by panel boundaries. This can\n
60 * induce a situation where a player is in a room and part of the room\n
61 * is off the screen. It may be annoying enough to go back to 33x11\n
62 * blocks to prevent this visual situation.\n
64 * Note that the dungeon generation routines are much different (2.7.5)\n
65 * and perhaps "DUN_ROOMS" should be less than 50.\n
67 * XXX XXX XXX Note that it is possible to create a room which is only\n
68 * connected to itself, because the "tunnel generation" code allows a\n
69 * tunnel to leave a room, wander around, and then re-enter the room.\n
71 * XXX XXX XXX Note that it is possible to create a set of rooms which\n
72 * are only connected to other rooms in that set, since there is nothing\n
73 * explicit in the code to prevent this from happening. But this is less\n
74 * likely than the "isolated room" problem, because each room attempts to\n
75 * connect to another room, in a giant cycle, thus requiring at least two\n
76 * bizarre occurances to create an isolated section of the dungeon.\n
78 * Note that (2.7.9) monster pits have been split into monster "nests"\n
79 * and monster "pits". The "nests" have a collection of monsters of a\n
80 * given type strewn randomly around the room (jelly, animal, or undead),\n
81 * while the "pits" have a collection of monsters of a given type placed\n
82 * around the room in an organized manner (orc, troll, giant, dragon, or\n
83 * demon). Note that both "nests" and "pits" are now "level dependant",\n
84 * and both make 16 "expensive" calls to the "get_mon_num()" function.\n
86 * Note that the cave grid flags changed in a rather drastic manner\n
87 * for Angband 2.8.0 (and 2.7.9+), in particular, dungeon terrain\n
88 * features, such as doors and stairs and traps and rubble and walls,\n
89 * are all handled as a set of 64 possible "terrain features", and\n
90 * not as "fake" objects (440-479) as in pre-2.8.0 versions.\n
92 * The 64 new "dungeon features" will also be used for "visual display"\n
93 * but we must be careful not to allow, for example, the user to display\n
94 * hidden traps in a different way from floors, or secret doors in a way\n
95 * different from granite walls, or even permanent granite in a different\n
96 * way from granite. XXX XXX XXX\n
100 #include "generate.h"
113 * Dungeon generation data -- see "cave_gen()"
119 * @brief 上下左右の外壁数をカウントする / Count the number of walls adjacent to the given grid.
123 * @note Assumes "in_bounds(y, x)"
124 * @details We count only granite walls and permanent walls.
126 static int next_to_walls(int y, int x)
130 if (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++;
131 if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++;
132 if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++;
133 if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++;
139 * @brief alloc_stairs()の補助として指定の位置に階段を生成できるかの判定を行う / Helper function for alloc_stairs(). Is this a good location for stairs?
142 * @param walls 最低減隣接させたい外壁の数
143 * @return 階段を生成して問題がないならばTRUEを返す。
145 static bool alloc_stairs_aux(int y, int x, int walls)
147 /* Access the grid */
148 cave_type *c_ptr = &cave[y][x];
150 /* Require "naked" floor grid */
151 if (!is_floor_grid(c_ptr)) return FALSE;
152 if (pattern_tile(y, x)) return FALSE;
153 if (c_ptr->o_idx || c_ptr->m_idx) return FALSE;
155 /* Require a certain number of adjacent walls */
156 if (next_to_walls(y, x) < walls) return FALSE;
163 * @brief 外壁に隣接させて階段を生成する / Places some staircases near walls
164 * @param feat 配置したい地形ID
165 * @param num 配置したい階段の数
166 * @param walls 最低減隣接させたい外壁の数
167 * @return 規定数通りに生成に成功したらTRUEを返す。
169 static bool alloc_stairs(IDX feat, int num, int walls)
174 feature_type *f_ptr = &f_info[feat];
176 if (have_flag(f_ptr->flags, FF_LESS))
178 /* No up stairs in town or in ironman mode */
179 if (ironman_downward || !dun_level) return TRUE;
181 if (dun_level > d_info[dungeon_type].mindepth)
182 shaft_num = (randint1(num+1))/2;
184 else if (have_flag(f_ptr->flags, FF_MORE))
186 int q_idx = quest_number(dun_level);
188 /* No downstairs on quest levels */
189 if (dun_level > 1 && q_idx)
191 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
193 /* The quest monster(s) is still alive? */
194 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
198 /* No downstairs at the bottom */
199 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
201 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
202 shaft_num = (randint1(num)+1)/2;
209 /* Place "num" stairs */
210 for (i = 0; i < num; i++)
220 for (y = 1; y < cur_hgt - 1; y++)
222 for (x = 1; x < cur_wid - 1; x++)
224 if (alloc_stairs_aux(y, x, walls))
226 /* A valid space found */
232 /* No valid place! */
235 /* There are exactly no place! */
236 if (walls <= 0) return FALSE;
238 /* Decrease walls limit, and try again */
243 /* Choose a random one */
244 pick = randint1(candidates);
246 for (y = 1; y < cur_hgt - 1; y++)
248 for (x = 1; x < cur_wid - 1; x++)
250 if (alloc_stairs_aux(y, x, walls))
254 /* Is this a picked one? */
262 /* Access the grid */
265 /* Clear possible garbage of hidden trap */
268 /* Clear previous contents, add stairs */
269 c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
271 /* No longer "FLOOR" */
272 c_ptr->info &= ~(CAVE_FLOOR);
282 * @brief フロア上のランダム位置に各種オブジェクトを配置する / Allocates some objects (using "place" and "type")
283 * @param set 配置したい地形の種類
284 * @param typ 配置したいオブジェクトの種類
286 * @return 規定数通りに生成に成功したらTRUEを返す。
288 static void alloc_object(int set, int typ, int num)
294 /* A small level has few objects. */
295 num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
297 /* Place some objects */
298 for (k = 0; k < num; k++)
300 /* Pick a "legal" spot */
301 while (dummy < SAFE_MAX_ATTEMPTS)
308 y = randint0(cur_hgt);
309 x = randint0(cur_wid);
313 /* Require "naked" floor grid */
314 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
316 /* Avoid player location */
317 if (player_bold(y, x)) continue;
319 /* Check for "room" */
320 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
322 /* Require corridor? */
323 if ((set == ALLOC_SET_CORR) && room) continue;
326 if ((set == ALLOC_SET_ROOM) && !room) continue;
332 if (dummy >= SAFE_MAX_ATTEMPTS)
334 msg_print_wizard(CHEAT_DUNGEON, _("アイテムの配置に失敗しました。", "Failed to place object."));
339 /* Place something */
342 case ALLOC_TYP_RUBBLE:
345 cave[y][x].info &= ~(CAVE_FLOOR);
352 cave[y][x].info &= ~(CAVE_FLOOR);
362 case ALLOC_TYP_OBJECT:
364 place_object(y, x, 0L);
372 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
373 * @param y1 基準となるマスのY座標
374 * @param x1 基準となるマスのX座標
376 * @note Assumes "in_bounds(y1, x1)"
378 * XXX XXX This routine currently only counts actual "empty floor"\n
379 * grids which are not in rooms. We might want to also count stairs,\n
380 * open doors, closed doors, etc.
382 static int next_to_corr(int y1, int x1)
388 /* Scan adjacent grids */
389 for (i = 0; i < 4; i++)
391 /* Extract the location */
395 /* Access the grid */
398 /* Skip non floors */
399 if (cave_have_flag_grid(c_ptr, FF_WALL)) continue;
401 /* Skip non "empty floor" grids */
402 if (!is_floor_grid(c_ptr))
405 /* Skip grids inside rooms */
406 if (c_ptr->info & (CAVE_ROOM)) continue;
408 /* Count these grids */
412 /* Return the number of corridors */
418 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
419 * @param y 判定を行いたいマスのY座標
420 * @param x 判定を行いたいマスのX座標
421 * @return ドアを設置可能ならばTRUEを返す
422 * @note Assumes "in_bounds(y1, x1)"
425 * Assumes "in_bounds(y, x)"\n
427 static bool possible_doorway(int y, int x)
429 /* Count the adjacent corridors */
430 if (next_to_corr(y, x) >= 2)
433 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
434 cave_have_flag_bold(y + 1, x, FF_WALL))
439 /* Check Horizontal */
440 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
441 cave_have_flag_bold(y, x + 1, FF_WALL))
452 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
453 * @param y 設置を行いたいマスのY座標
454 * @param x 設置を行いたいマスのX座標
457 static void try_door(int y, int x)
460 if (!in_bounds(y, x)) return;
463 if (cave_have_flag_bold(y, x, FF_WALL)) return;
465 /* Ignore room grids */
466 if (cave[y][x].info & (CAVE_ROOM)) return;
468 /* Occasional door (if allowed) */
469 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
472 place_random_door(y, x, FALSE);
478 * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
479 * @return 成功したならばTRUEを返す
481 bool place_quest_monsters(void)
485 /* Handle the quest monster placements */
486 for (i = 0; i < max_quests; i++)
492 if (quest[i].status != QUEST_STATUS_TAKEN ||
493 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
494 quest[i].type != QUEST_TYPE_RANDOM) ||
495 quest[i].level != dun_level ||
496 dungeon_type != quest[i].dungeon ||
497 (quest[i].flags & QUEST_FLAG_PRESET))
503 r_ptr = &r_info[quest[i].r_idx];
505 /* Hack -- "unique" monsters must be "unique" */
506 if ((r_ptr->flags1 & RF1_UNIQUE) &&
507 (r_ptr->cur_num >= r_ptr->max_num)) continue;
509 mode = (PM_NO_KAGE | PM_NO_PET);
511 if (!(r_ptr->flags1 & RF1_FRIENDS))
512 mode |= PM_ALLOW_GROUP;
514 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
518 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
523 /* Find an empty grid */
524 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
529 y = randint0(cur_hgt);
530 x = randint0(cur_wid);
533 f_ptr = &f_info[c_ptr->feat];
535 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
536 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
537 if (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
538 if (c_ptr->info & CAVE_ICKY) continue;
542 /* Failed to place */
543 if (!l) return FALSE;
545 /* Try to place the monster */
546 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
553 /* Failure - Try again */
558 /* Failed to place */
559 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
568 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
569 * @param c_ptr 永久壁を廃止したいマス構造体の参照ポインタ
572 static void set_bound_perm_wall(cave_type *c_ptr)
574 if (bound_walls_perm)
576 /* Clear boundary mimic */
581 feature_type *f_ptr = &f_info[c_ptr->feat];
583 /* Hack -- Decline boundary walls with known treasure */
584 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
585 !have_flag(f_ptr->flags, FF_SECRET))
586 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
588 /* Set boundary mimic */
589 c_ptr->mimic = c_ptr->feat;
592 /* Add "solid" perma-wall */
593 place_solid_perm_grid(c_ptr);
597 * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
598 * @details There were moved from cave_gen().
601 static void gen_caverns_and_lakes(void)
603 #ifdef ALLOW_CAVERNS_AND_LAKES
604 /* Possible "destroyed" level */
605 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
607 dun->destroyed = TRUE;
609 /* extra rubble around the place looks cool */
610 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
613 /* Make a lake some of the time */
614 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
615 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
618 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
619 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
620 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
621 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
623 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
626 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
630 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
634 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
637 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
641 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
645 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
648 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
651 /* Lake of rubble2 */
652 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
657 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
661 msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
662 build_lake(dun->laketype);
666 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
667 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
668 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
672 /* make a large fractal cave in the middle of the dungeon */
674 msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
677 #endif /* ALLOW_CAVERNS_AND_LAKES */
679 /* Hack -- No destroyed "quest" levels */
680 if (quest_number(dun_level)) dun->destroyed = FALSE;
685 * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
686 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
687 * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
689 static bool cave_gen(void)
698 dun->destroyed = FALSE;
699 dun->empty_level = FALSE;
703 /* Fill the arrays of floors and walls in the good proportions */
704 set_floor_and_wall(dungeon_type);
706 /* Prepare allocation table */
707 get_mon_num_prep(get_monster_hook(), NULL);
709 /* Randomize the dungeon creation values */
710 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
711 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
712 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
713 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
714 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
716 /* Actual maximum number of rooms on this level */
717 dun->row_rooms = cur_hgt / BLOCK_HGT;
718 dun->col_rooms = cur_wid / BLOCK_WID;
720 /* Initialize the room table */
721 for (y = 0; y < dun->row_rooms; y++)
723 for (x = 0; x < dun->col_rooms; x++)
725 dun->room_map[y][x] = FALSE;
732 /* Empty arena levels */
733 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
735 dun->empty_level = TRUE;
736 msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
739 if (dun->empty_level)
741 /* Start with floors */
742 for (y = 0; y < cur_hgt; y++)
744 for (x = 0; x < cur_wid; x++)
746 place_floor_bold(y, x);
750 /* Special boundary walls -- Top and bottom */
751 for (x = 0; x < cur_wid; x++)
753 place_extra_bold(0, x);
754 place_extra_bold(cur_hgt - 1, x);
757 /* Special boundary walls -- Left and right */
758 for (y = 1; y < (cur_hgt - 1); y++)
760 place_extra_bold(y, 0);
761 place_extra_bold(y, cur_wid - 1);
766 /* Start with walls */
767 for (y = 0; y < cur_hgt; y++)
769 for (x = 0; x < cur_wid; x++)
771 place_extra_bold(y, x);
777 /* Generate various caverns and lakes */
778 gen_caverns_and_lakes();
782 if (d_info[dungeon_type].flags1 & DF1_MAZE)
784 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
786 /* Place 3 or 4 down stairs near some walls */
787 if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
789 /* Place 1 or 2 up stairs near some walls */
790 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
793 /* Build some rooms */
796 int tunnel_fail_count = 0;
799 * Build each type of room in turn until we cannot build any more.
801 if (!generate_rooms()) return FALSE;
804 /* Make a hole in the dungeon roof sometimes at level 1 */
807 while (one_in_(DUN_MOS_DEN))
809 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
813 /* Destroy the level if necessary */
814 if (dun->destroyed) destroy_level();
816 /* Hack -- Add some rivers */
817 if (one_in_(3) && (randint1(dun_level) > 5))
819 IDX feat1 = 0, feat2 = 0;
821 /* Choose water or lava */
822 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
824 feat1 = feat_deep_water;
825 feat2 = feat_shallow_water;
827 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
829 feat1 = feat_deep_lava;
830 feat2 = feat_shallow_lava;
836 feature_type *f_ptr = &f_info[feat1];
838 /* Only add river if matches lake type or if have no lake at all */
839 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
840 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
843 add_river(feat1, feat2);
848 /* Hack -- Scramble the room order */
849 for (i = 0; i < dun->cent_n; i++)
852 int pick = rand_range(0, i);
856 dun->cent[i].y = dun->cent[pick].y;
857 dun->cent[i].x = dun->cent[pick].x;
858 dun->cent[pick].y = ty;
859 dun->cent[pick].x = tx;
862 /* Start with no tunnel doors */
865 /* Hack -- connect the first room to the last room */
866 y = dun->cent[dun->cent_n-1].y;
867 x = dun->cent[dun->cent_n-1].x;
869 /* Connect all the rooms together */
870 for (i = 0; i < dun->cent_n; i++)
874 /* Reset the arrays */
878 /* Connect the room to the previous room */
879 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
881 /* make cave-like tunnel */
882 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
886 /* make normal tunnel */
887 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
890 if (tunnel_fail_count >= 2) return FALSE;
892 /* Turn the tunnel into corridor */
893 for (j = 0; j < dun->tunn_n; j++)
898 /* Access the grid */
902 /* Access the grid */
904 f_ptr = &f_info[c_ptr->feat];
906 /* Clear previous contents (if not a lake), add a floor */
907 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
909 /* Clear mimic type */
912 place_floor_grid(c_ptr);
916 /* Apply the piercings that we found */
917 for (j = 0; j < dun->wall_n; j++)
921 /* Access the grid */
925 /* Access the grid */
928 /* Clear mimic type */
931 /* Clear previous contents, add up floor */
932 place_floor_grid(c_ptr);
934 /* Occasional doorway */
935 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
937 /* Place a random door */
938 place_random_door(y, x, TRUE);
942 /* Remember the "previous" room */
947 /* Place intersection doors */
948 for (i = 0; i < dun->door_n; i++)
950 /* Extract junction location */
954 /* Try placing doors */
961 /* Place 3 or 4 down stairs near some walls */
962 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
964 /* Place 1 or 2 up stairs near some walls */
965 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
970 if (d_info[dungeon_type].stream2)
972 /* Hack -- Add some quartz streamers */
973 for (i = 0; i < DUN_STR_QUA; i++)
975 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
979 if (d_info[dungeon_type].stream1)
981 /* Hack -- Add some magma streamers */
982 for (i = 0; i < DUN_STR_MAG; i++)
984 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
989 /* Special boundary walls -- Top and bottom */
990 for (x = 0; x < cur_wid; x++)
992 set_bound_perm_wall(&cave[0][x]);
993 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
996 /* Special boundary walls -- Left and right */
997 for (y = 1; y < (cur_hgt - 1); y++)
999 set_bound_perm_wall(&cave[y][0]);
1000 set_bound_perm_wall(&cave[y][cur_wid - 1]);
1003 /* Determine the character location */
1004 if (!new_player_spot()) return FALSE;
1006 if (!place_quest_monsters()) return FALSE;
1008 /* Basic "amount" */
1009 k = (dun_level / 3);
1013 /* Pick a base number of monsters */
1014 i = d_info[dungeon_type].min_m_alloc_level;
1016 /* To make small levels a bit more playable */
1017 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1019 int small_tester = i;
1021 i = (i * cur_hgt) / MAX_HGT;
1022 i = (i * cur_wid) / MAX_WID;
1025 if (i > small_tester) i = small_tester;
1026 else msg_format_wizard(CHEAT_DUNGEON,
1027 _("モンスター数基本値を %d から %d に減らします", "Reduced monsters base from %d to %d"), small_tester, i);
1033 /* Put some monsters in the dungeon */
1034 for (i = i + k; i > 0; i--)
1036 (void)alloc_monster(0, PM_ALLOW_SLEEP);
1039 /* Place some traps in the dungeon */
1040 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
1042 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
1043 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
1045 /* Mega Hack -- No object at first level of deeper dungeon */
1046 if (p_ptr->enter_dungeon && dun_level > 1)
1048 /* No stair scum! */
1052 /* Put some objects in rooms */
1053 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1055 /* Put some objects/gold in the dungeon */
1056 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1057 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1059 /* Set back to default */
1060 object_level = base_level;
1062 /* Put the Guardian */
1063 if (!alloc_guardian(TRUE)) return FALSE;
1065 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1068 for (y = 0; y < cur_hgt; y++)
1070 for (x = 0; x < cur_wid; x++)
1072 cave[y][x].info |= (CAVE_GLOW);
1081 * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
1084 static void build_arena(void)
1086 int yval, y_height, y_depth, xval, x_left, x_right;
1089 yval = SCREEN_HGT / 2;
1090 xval = SCREEN_WID / 2;
1091 y_height = yval - 10;
1092 y_depth = yval + 10;
1094 x_right = xval + 32;
1096 for (i = y_height; i <= y_height + 5; i++)
1097 for (j = x_left; j <= x_right; j++)
1099 place_extra_perm_bold(i, j);
1100 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1102 for (i = y_depth; i >= y_depth - 5; i--)
1103 for (j = x_left; j <= x_right; j++)
1105 place_extra_perm_bold(i, j);
1106 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1108 for (j = x_left; j <= x_left + 17; j++)
1109 for (i = y_height; i <= y_depth; i++)
1111 place_extra_perm_bold(i, j);
1112 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1114 for (j = x_right; j >= x_right - 17; j--)
1115 for (i = y_height; i <= y_depth; i++)
1117 place_extra_perm_bold(i, j);
1118 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1121 place_extra_perm_bold(y_height+6, x_left+18);
1122 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1123 place_extra_perm_bold(y_depth-6, x_left+18);
1124 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1125 place_extra_perm_bold(y_height+6, x_right-18);
1126 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1127 place_extra_perm_bold(y_depth-6, x_right-18);
1128 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1132 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1133 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1138 * @brief 闘技場への入場処理 / Town logic flow for generation of arena -KMW-
1141 static void arena_gen(void)
1148 cur_hgt = SCREEN_HGT;
1149 cur_wid = SCREEN_WID;
1151 /* Start with solid walls */
1152 for (y = 0; y < MAX_HGT; y++)
1154 for (x = 0; x < MAX_WID; x++)
1156 /* Create "solid" perma-wall */
1157 place_solid_perm_bold(y, x);
1159 /* Illuminate and memorize the walls */
1160 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1164 /* Then place some floors */
1165 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1167 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1169 /* Create empty floor */
1170 cave[y][x].feat = feat_floor;
1176 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)))
1178 p_ptr->exit_bldg = TRUE;
1179 p_ptr->arena_number++;
1181 msg_print("相手は欠場した。あなたの不戦勝だ。");
1183 msg_print("The enemy is unable appear. You won by default.");
1190 * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
1193 static void build_battle(void)
1195 int yval, y_height, y_depth, xval, x_left, x_right;
1198 yval = SCREEN_HGT / 2;
1199 xval = SCREEN_WID / 2;
1200 y_height = yval - 10;
1201 y_depth = yval + 10;
1203 x_right = xval + 32;
1205 for (i = y_height; i <= y_height + 5; i++)
1206 for (j = x_left; j <= x_right; j++)
1208 place_extra_perm_bold(i, j);
1209 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1211 for (i = y_depth; i >= y_depth - 3; i--)
1212 for (j = x_left; j <= x_right; j++)
1214 place_extra_perm_bold(i, j);
1215 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1217 for (j = x_left; j <= x_left + 17; j++)
1218 for (i = y_height; i <= y_depth; i++)
1220 place_extra_perm_bold(i, j);
1221 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1223 for (j = x_right; j >= x_right - 17; j--)
1224 for (i = y_height; i <= y_depth; i++)
1226 place_extra_perm_bold(i, j);
1227 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1230 place_extra_perm_bold(y_height+6, x_left+18);
1231 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1232 place_extra_perm_bold(y_depth-4, x_left+18);
1233 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1234 place_extra_perm_bold(y_height+6, x_right-18);
1235 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1236 place_extra_perm_bold(y_depth-4, x_right-18);
1237 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1239 for (i = y_height + 1; i <= y_height + 5; i++)
1240 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1242 cave[i][j].feat = feat_permanent_glass_wall;
1247 cave[i][j].feat = f_tag_to_index("BUILDING_3");
1248 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1253 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
1256 static void battle_gen(void)
1263 /* Start with solid walls */
1264 for (y = 0; y < MAX_HGT; y++)
1266 for (x = 0; x < MAX_WID; x++)
1268 /* Create "solid" perma-wall */
1269 place_solid_perm_bold(y, x);
1271 /* Illuminate and memorize the walls */
1272 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1276 /* Then place some floors */
1277 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1279 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1281 /* Create empty floor */
1282 cave[y][x].feat = feat_floor;
1288 for(i = 0; i < 4; i++)
1290 place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i],
1291 (PM_NO_KAGE | PM_NO_PET));
1292 set_friendly(&m_list[cave[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
1294 for(i = 1; i < m_max; i++)
1296 monster_type *m_ptr = &m_list[i];
1298 if (!m_ptr->r_idx) continue;
1300 /* Hack -- Detect monster */
1301 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1303 /* Update the monster */
1304 update_mon(i, FALSE);
1309 * @brief 固定マップクエストのフロア生成 / Generate a quest level
1312 static void quest_gen(void)
1317 /* Start with perm walls */
1318 for (y = 0; y < cur_hgt; y++)
1320 for (x = 0; x < cur_wid; x++)
1322 place_solid_perm_bold(y, x);
1326 /* Set the quest level */
1327 base_level = quest[p_ptr->inside_quest].level;
1328 dun_level = base_level;
1329 object_level = base_level;
1330 monster_level = base_level;
1332 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1334 /* Prepare allocation table */
1335 get_mon_num_prep(get_monster_hook(), NULL);
1337 init_flags = INIT_CREATE_DUNGEON;
1339 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1343 * @brief ダンジョン時のランダムフロア生成 / Make a real level
1344 * @return フロアの生成に成功したらTRUE
1346 static bool level_gen(cptr *why)
1348 int level_height, level_width;
1350 if ((always_small_levels || ironman_small_levels ||
1351 (one_in_(SMALL_LEVEL) && small_levels) ||
1352 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1353 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1354 !(d_info[dungeon_type].flags1 & DF1_BIG))
1356 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1361 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1370 level_height = randint1(MAX_HGT/SCREEN_HGT);
1371 level_width = randint1(MAX_WID/SCREEN_WID);
1373 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1374 (level_width == MAX_WID/SCREEN_WID));
1377 cur_hgt = level_height * SCREEN_HGT;
1378 cur_wid = level_width * SCREEN_WID;
1380 /* Assume illegal panel */
1381 panel_row_min = cur_hgt;
1382 panel_col_min = cur_wid;
1384 msg_format_wizard(CHEAT_DUNGEON,
1385 _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
1394 /* Assume illegal panel */
1395 panel_row_min = cur_hgt;
1396 panel_col_min = cur_wid;
1399 /* Make a dungeon */
1403 *why = "ダンジョン生成に失敗";
1405 *why = "could not place player";
1414 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after cave generation
1417 void wipe_generate_cave_flags(void)
1421 for (y = 0; y < cur_hgt; y++)
1423 for (x = 0; x < cur_wid; x++)
1425 /* Wipe unused flags */
1426 cave[y][x].info &= ~(CAVE_MASK);
1432 for (y = 1; y < cur_hgt - 1; y++)
1434 for (x = 1; x < cur_wid - 1; x++)
1436 /* There might be trap */
1437 cave[y][x].info |= CAVE_UNSAFE;
1444 * @brief フロアの全情報を初期化する / Clear and empty the cave
1447 void clear_cave(void)
1451 /* Very simplified version of wipe_o_list() */
1452 (void)C_WIPE(o_list, o_max, object_type);
1456 /* Very simplified version of wipe_m_list() */
1457 for (i = 1; i < max_r_idx; i++)
1458 r_info[i].cur_num = 0;
1459 (void)C_WIPE(m_list, m_max, monster_type);
1462 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1464 /* Pre-calc cur_num of pets in party_mon[] */
1465 precalc_cur_num_of_pet();
1468 /* Start with a blank cave */
1469 for (y = 0; y < MAX_HGT; y++)
1471 for (x = 0; x < MAX_WID; x++)
1473 cave_type *c_ptr = &cave[y][x];
1500 /* Mega-Hack -- no player yet */
1501 p_ptr->x = p_ptr->y = 0;
1503 /* Set the base level */
1504 base_level = dun_level;
1506 /* Reset the monster generation level */
1507 monster_level = base_level;
1509 /* Reset the object generation level */
1510 object_level = base_level;
1515 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
1517 * @note Hack -- regenerate any "overflow" levels
1519 void generate_cave(void)
1523 /* Fill the arrays of floors and walls in the good proportions */
1524 set_floor_and_wall(dungeon_type);
1527 for (num = 0; TRUE; num++)
1533 /* Clear and empty the cave */
1536 /* Build the arena -KMW- */
1537 if (p_ptr->inside_arena)
1543 /* Build the battle -KMW- */
1544 else if (p_ptr->inside_battle)
1550 else if (p_ptr->inside_quest)
1555 /* Build the town */
1556 else if (!dun_level)
1558 /* Make the wilderness */
1559 if (p_ptr->wild_mode) wilderness_gen_small();
1560 else wilderness_gen();
1563 /* Build a real level */
1566 okay = level_gen(&why);
1570 /* Prevent object over-flow */
1571 if (o_max >= max_o_idx)
1577 why = "too many objects";
1584 /* Prevent monster over-flow */
1585 else if (m_max >= max_m_idx)
1591 why = "too many monsters";
1604 if (why) msg_format("生成やり直し(%s)", why);
1606 if (why) msg_format("Generation restarted (%s)", why);
1610 /* Wipe the objects */
1613 /* Wipe the monsters */
1617 /* Glow deep lava and building entrances */
1618 glow_deep_lava_and_bldg();
1621 p_ptr->enter_dungeon = FALSE;
1623 wipe_generate_cave_flags();