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);
375 * @brief クエストに関わるモンスターの配置を行う / Place quest monsters
376 * @return 成功したならばTRUEを返す
378 bool place_quest_monsters(void)
382 /* Handle the quest monster placements */
383 for (i = 0; i < max_q_idx; i++)
389 if (quest[i].status != QUEST_STATUS_TAKEN ||
390 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
391 quest[i].type != QUEST_TYPE_RANDOM) ||
392 quest[i].level != dun_level ||
393 dungeon_type != quest[i].dungeon ||
394 (quest[i].flags & QUEST_FLAG_PRESET))
400 r_ptr = &r_info[quest[i].r_idx];
402 /* Hack -- "unique" monsters must be "unique" */
403 if ((r_ptr->flags1 & RF1_UNIQUE) &&
404 (r_ptr->cur_num >= r_ptr->max_num)) continue;
406 mode = (PM_NO_KAGE | PM_NO_PET);
408 if (!(r_ptr->flags1 & RF1_FRIENDS))
409 mode |= PM_ALLOW_GROUP;
411 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
415 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
420 /* Find an empty grid */
421 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
426 y = randint0(cur_hgt);
427 x = randint0(cur_wid);
430 f_ptr = &f_info[c_ptr->feat];
432 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
433 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
434 if (distance(y, x, p_ptr->y, p_ptr->x) < 10) continue;
435 if (c_ptr->info & CAVE_ICKY) continue;
439 /* Failed to place */
440 if (!l) return FALSE;
442 /* Try to place the monster */
443 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
450 /* Failure - Try again */
455 /* Failed to place */
456 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
465 * @brief マスにフロア端用の永久壁を配置する / Set boundary mimic and add "solid" perma-wall
466 * @param c_ptr 永久壁を廃止したいマス構造体の参照ポインタ
469 static void set_bound_perm_wall(cave_type *c_ptr)
471 if (bound_walls_perm)
473 /* Clear boundary mimic */
478 feature_type *f_ptr = &f_info[c_ptr->feat];
480 /* Hack -- Decline boundary walls with known treasure */
481 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
482 !have_flag(f_ptr->flags, FF_SECRET))
483 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
485 /* Set boundary mimic */
486 c_ptr->mimic = c_ptr->feat;
489 /* Add "solid" perma-wall */
490 place_solid_perm_grid(c_ptr);
494 * @brief フロアに洞窟や湖を配置する / Generate various caverns and lakes
495 * @details There were moved from cave_gen().
498 static void gen_caverns_and_lakes(void)
500 #ifdef ALLOW_CAVERNS_AND_LAKES
501 /* Possible "destroyed" level */
502 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
504 dun->destroyed = TRUE;
506 /* extra rubble around the place looks cool */
507 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
510 /* Make a lake some of the time */
511 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
512 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
515 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
516 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
517 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
518 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
520 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
523 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
527 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
531 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
534 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
538 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
542 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
545 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
548 /* Lake of rubble2 */
549 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
554 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
558 msg_print_wizard(CHEAT_DUNGEON, _("湖を生成します。", "Lake on the level."));
559 build_lake(dun->laketype);
563 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
564 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
565 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
569 /* make a large fractal cave in the middle of the dungeon */
571 msg_print_wizard(CHEAT_DUNGEON, _("洞窟を生成。", "Cavern on level."));
574 #endif /* ALLOW_CAVERNS_AND_LAKES */
576 /* Hack -- No destroyed "quest" levels */
577 if (quest_number(dun_level)) dun->destroyed = FALSE;
582 * @brief ダンジョン生成のメインルーチン / Generate a new dungeon level
583 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
584 * @return ダンジョン生成が全て無事に成功したらTRUEを返す。
586 static bool cave_gen(void)
595 dun->destroyed = FALSE;
596 dun->empty_level = FALSE;
600 /* Fill the arrays of floors and walls in the good proportions */
601 set_floor_and_wall(dungeon_type);
603 /* Prepare allocation table */
604 get_mon_num_prep(get_monster_hook(), NULL);
606 /* Randomize the dungeon creation values */
607 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
608 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
609 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
610 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
611 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
613 /* Actual maximum number of rooms on this level */
614 dun->row_rooms = cur_hgt / BLOCK_HGT;
615 dun->col_rooms = cur_wid / BLOCK_WID;
617 /* Initialize the room table */
618 for (y = 0; y < dun->row_rooms; y++)
620 for (x = 0; x < dun->col_rooms; x++)
622 dun->room_map[y][x] = FALSE;
629 /* Empty arena levels */
630 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
632 dun->empty_level = TRUE;
633 msg_print_wizard(CHEAT_DUNGEON, _("アリーナレベルを生成。", "Arena level."));
636 if (dun->empty_level)
638 /* Start with floors */
639 for (y = 0; y < cur_hgt; y++)
641 for (x = 0; x < cur_wid; x++)
643 place_floor_bold(y, x);
647 /* Special boundary walls -- Top and bottom */
648 for (x = 0; x < cur_wid; x++)
650 place_extra_bold(0, x);
651 place_extra_bold(cur_hgt - 1, x);
654 /* Special boundary walls -- Left and right */
655 for (y = 1; y < (cur_hgt - 1); y++)
657 place_extra_bold(y, 0);
658 place_extra_bold(y, cur_wid - 1);
663 /* Start with walls */
664 for (y = 0; y < cur_hgt; y++)
666 for (x = 0; x < cur_wid; x++)
668 place_extra_bold(y, x);
674 /* Generate various caverns and lakes */
675 gen_caverns_and_lakes();
679 if (d_info[dungeon_type].flags1 & DF1_MAZE)
681 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
683 /* Place 3 or 4 down stairs near some walls */
684 if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
686 /* Place 1 or 2 up stairs near some walls */
687 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
690 /* Build some rooms */
693 int tunnel_fail_count = 0;
696 * Build each type of room in turn until we cannot build any more.
698 if (!generate_rooms()) return FALSE;
701 /* Make a hole in the dungeon roof sometimes at level 1 */
704 while (one_in_(DUN_MOS_DEN))
706 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
710 /* Destroy the level if necessary */
711 if (dun->destroyed) destroy_level();
713 /* Hack -- Add some rivers */
714 if (one_in_(3) && (randint1(dun_level) > 5))
716 IDX feat1 = 0, feat2 = 0;
718 /* Choose water or lava */
719 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
721 feat1 = feat_deep_water;
722 feat2 = feat_shallow_water;
724 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
726 feat1 = feat_deep_lava;
727 feat2 = feat_shallow_lava;
733 feature_type *f_ptr = &f_info[feat1];
735 /* Only add river if matches lake type or if have no lake at all */
736 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
737 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
740 add_river(feat1, feat2);
745 /* Hack -- Scramble the room order */
746 for (i = 0; i < dun->cent_n; i++)
749 int pick = rand_range(0, i);
753 dun->cent[i].y = dun->cent[pick].y;
754 dun->cent[i].x = dun->cent[pick].x;
755 dun->cent[pick].y = ty;
756 dun->cent[pick].x = tx;
759 /* Start with no tunnel doors */
762 /* Hack -- connect the first room to the last room */
763 y = dun->cent[dun->cent_n-1].y;
764 x = dun->cent[dun->cent_n-1].x;
766 /* Connect all the rooms together */
767 for (i = 0; i < dun->cent_n; i++)
771 /* Reset the arrays */
775 /* Connect the room to the previous room */
776 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
778 /* make cave-like tunnel */
779 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
783 /* make normal tunnel */
784 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
787 if (tunnel_fail_count >= 2) return FALSE;
789 /* Turn the tunnel into corridor */
790 for (j = 0; j < dun->tunn_n; j++)
795 /* Access the grid */
799 /* Access the grid */
801 f_ptr = &f_info[c_ptr->feat];
803 /* Clear previous contents (if not a lake), add a floor */
804 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
806 /* Clear mimic type */
809 place_floor_grid(c_ptr);
813 /* Apply the piercings that we found */
814 for (j = 0; j < dun->wall_n; j++)
818 /* Access the grid */
822 /* Access the grid */
825 /* Clear mimic type */
828 /* Clear previous contents, add up floor */
829 place_floor_grid(c_ptr);
831 /* Occasional doorway */
832 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
834 /* Place a random door */
835 place_random_door(y, x, TRUE);
839 /* Remember the "previous" room */
844 /* Place intersection doors */
845 for (i = 0; i < dun->door_n; i++)
847 /* Extract junction location */
851 /* Try placing doors */
858 /* Place 3 or 4 down stairs near some walls */
859 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
861 /* Place 1 or 2 up stairs near some walls */
862 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
867 if (d_info[dungeon_type].stream2)
869 /* Hack -- Add some quartz streamers */
870 for (i = 0; i < DUN_STR_QUA; i++)
872 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
876 if (d_info[dungeon_type].stream1)
878 /* Hack -- Add some magma streamers */
879 for (i = 0; i < DUN_STR_MAG; i++)
881 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
886 /* Special boundary walls -- Top and bottom */
887 for (x = 0; x < cur_wid; x++)
889 set_bound_perm_wall(&cave[0][x]);
890 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
893 /* Special boundary walls -- Left and right */
894 for (y = 1; y < (cur_hgt - 1); y++)
896 set_bound_perm_wall(&cave[y][0]);
897 set_bound_perm_wall(&cave[y][cur_wid - 1]);
900 /* Determine the character location */
901 if (!new_player_spot()) return FALSE;
903 if (!place_quest_monsters()) return FALSE;
910 /* Pick a base number of monsters */
911 i = d_info[dungeon_type].min_m_alloc_level;
913 /* To make small levels a bit more playable */
914 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
916 int small_tester = i;
918 i = (i * cur_hgt) / MAX_HGT;
919 i = (i * cur_wid) / MAX_WID;
922 if (i > small_tester) i = small_tester;
923 else msg_format_wizard(CHEAT_DUNGEON,
924 _("モンスター数基本値を %d から %d に減らします", "Reduced monsters base from %d to %d"), small_tester, i);
930 /* Put some monsters in the dungeon */
931 for (i = i + k; i > 0; i--)
933 (void)alloc_monster(0, PM_ALLOW_SLEEP);
936 /* Place some traps in the dungeon */
937 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
939 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
940 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
942 /* Mega Hack -- No object at first level of deeper dungeon */
943 if (p_ptr->enter_dungeon && dun_level > 1)
949 /* Put some objects in rooms */
950 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
952 /* Put some objects/gold in the dungeon */
953 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
954 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
956 /* Set back to default */
957 object_level = base_level;
959 /* Put the Guardian */
960 if (!alloc_guardian(TRUE)) return FALSE;
962 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
965 for (y = 0; y < cur_hgt; y++)
967 for (x = 0; x < cur_wid; x++)
969 cave[y][x].info |= (CAVE_GLOW);
978 * @brief 闘技場用のアリーナ地形を作成する / Builds the arena after it is entered -KMW-
981 static void build_arena(void)
983 int yval, y_height, y_depth, xval, x_left, x_right;
986 yval = SCREEN_HGT / 2;
987 xval = SCREEN_WID / 2;
988 y_height = yval - 10;
993 for (i = y_height; i <= y_height + 5; i++)
994 for (j = x_left; j <= x_right; j++)
996 place_extra_perm_bold(i, j);
997 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
999 for (i = y_depth; i >= y_depth - 5; i--)
1000 for (j = x_left; j <= x_right; j++)
1002 place_extra_perm_bold(i, j);
1003 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1005 for (j = x_left; j <= x_left + 17; j++)
1006 for (i = y_height; i <= y_depth; i++)
1008 place_extra_perm_bold(i, j);
1009 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1011 for (j = x_right; j >= x_right - 17; j--)
1012 for (i = y_height; i <= y_depth; i++)
1014 place_extra_perm_bold(i, j);
1015 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1018 place_extra_perm_bold(y_height+6, x_left+18);
1019 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1020 place_extra_perm_bold(y_depth-6, x_left+18);
1021 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1022 place_extra_perm_bold(y_height+6, x_right-18);
1023 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1024 place_extra_perm_bold(y_depth-6, x_right-18);
1025 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1029 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1030 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1035 * @brief 闘技場への入場処理 / Town logic flow for generation of arena -KMW-
1038 static void arena_gen(void)
1045 cur_hgt = SCREEN_HGT;
1046 cur_wid = SCREEN_WID;
1048 /* Start with solid walls */
1049 for (y = 0; y < MAX_HGT; y++)
1051 for (x = 0; x < MAX_WID; x++)
1053 /* Create "solid" perma-wall */
1054 place_solid_perm_bold(y, x);
1056 /* Illuminate and memorize the walls */
1057 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1061 /* Then place some floors */
1062 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1064 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1066 /* Create empty floor */
1067 cave[y][x].feat = feat_floor;
1073 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)))
1075 p_ptr->exit_bldg = TRUE;
1076 p_ptr->arena_number++;
1077 msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable appear. You won by default."));
1083 * @brief モンスター闘技場のフロア生成 / Builds the arena after it is entered -KMW-
1086 static void build_battle(void)
1088 int yval, y_height, y_depth, xval, x_left, x_right;
1091 yval = SCREEN_HGT / 2;
1092 xval = SCREEN_WID / 2;
1093 y_height = yval - 10;
1094 y_depth = yval + 10;
1096 x_right = xval + 32;
1098 for (i = y_height; i <= y_height + 5; i++)
1099 for (j = x_left; j <= x_right; j++)
1101 place_extra_perm_bold(i, j);
1102 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1104 for (i = y_depth; i >= y_depth - 3; i--)
1105 for (j = x_left; j <= x_right; j++)
1107 place_extra_perm_bold(i, j);
1108 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1110 for (j = x_left; j <= x_left + 17; j++)
1111 for (i = y_height; i <= y_depth; i++)
1113 place_extra_perm_bold(i, j);
1114 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1116 for (j = x_right; j >= x_right - 17; j--)
1117 for (i = y_height; i <= y_depth; i++)
1119 place_extra_perm_bold(i, j);
1120 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1123 place_extra_perm_bold(y_height+6, x_left+18);
1124 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1125 place_extra_perm_bold(y_depth-4, x_left+18);
1126 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1127 place_extra_perm_bold(y_height+6, x_right-18);
1128 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1129 place_extra_perm_bold(y_depth-4, x_right-18);
1130 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1132 for (i = y_height + 1; i <= y_height + 5; i++)
1133 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1135 cave[i][j].feat = feat_permanent_glass_wall;
1140 cave[i][j].feat = f_tag_to_index("BUILDING_3");
1141 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1146 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of arena -KMW-
1149 static void battle_gen(void)
1156 /* Start with solid walls */
1157 for (y = 0; y < MAX_HGT; y++)
1159 for (x = 0; x < MAX_WID; x++)
1161 /* Create "solid" perma-wall */
1162 place_solid_perm_bold(y, x);
1164 /* Illuminate and memorize the walls */
1165 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1169 /* Then place some floors */
1170 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1172 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1174 /* Create empty floor */
1175 cave[y][x].feat = feat_floor;
1181 for(i = 0; i < 4; i++)
1183 place_monster_aux(0, p_ptr->y + 8 + (i/2)*4, p_ptr->x - 2 + (i%2)*4, battle_mon[i],
1184 (PM_NO_KAGE | PM_NO_PET));
1185 set_friendly(&m_list[cave[p_ptr->y+8+(i/2)*4][p_ptr->x-2+(i%2)*4].m_idx]);
1187 for(i = 1; i < m_max; i++)
1189 monster_type *m_ptr = &m_list[i];
1191 if (!m_ptr->r_idx) continue;
1193 /* Hack -- Detect monster */
1194 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1196 /* Update the monster */
1197 update_mon(i, FALSE);
1202 * @brief 固定マップクエストのフロア生成 / Generate a quest level
1205 static void quest_gen(void)
1210 /* Start with perm walls */
1211 for (y = 0; y < cur_hgt; y++)
1213 for (x = 0; x < cur_wid; x++)
1215 place_solid_perm_bold(y, x);
1219 /* Set the quest level */
1220 base_level = quest[p_ptr->inside_quest].level;
1221 dun_level = base_level;
1222 object_level = base_level;
1223 monster_level = base_level;
1225 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1227 /* Prepare allocation table */
1228 get_mon_num_prep(get_monster_hook(), NULL);
1230 init_flags = INIT_CREATE_DUNGEON;
1232 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1236 * @brief ダンジョン時のランダムフロア生成 / Make a real level
1237 * @return フロアの生成に成功したらTRUE
1239 static bool level_gen(cptr *why)
1241 int level_height, level_width;
1243 if ((always_small_levels || ironman_small_levels ||
1244 (one_in_(SMALL_LEVEL) && small_levels) ||
1245 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1246 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1247 !(d_info[dungeon_type].flags1 & DF1_BIG))
1249 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1254 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1263 level_height = randint1(MAX_HGT/SCREEN_HGT);
1264 level_width = randint1(MAX_WID/SCREEN_WID);
1266 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1267 (level_width == MAX_WID/SCREEN_WID));
1270 cur_hgt = level_height * SCREEN_HGT;
1271 cur_wid = level_width * SCREEN_WID;
1273 /* Assume illegal panel */
1274 panel_row_min = cur_hgt;
1275 panel_col_min = cur_wid;
1277 msg_format_wizard(CHEAT_DUNGEON,
1278 _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."),
1287 /* Assume illegal panel */
1288 panel_row_min = cur_hgt;
1289 panel_col_min = cur_wid;
1292 /* Make a dungeon */
1296 *why = "ダンジョン生成に失敗";
1298 *why = "could not place player";
1307 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after cave generation
1310 void wipe_generate_cave_flags(void)
1314 for (y = 0; y < cur_hgt; y++)
1316 for (x = 0; x < cur_wid; x++)
1318 /* Wipe unused flags */
1319 cave[y][x].info &= ~(CAVE_MASK);
1325 for (y = 1; y < cur_hgt - 1; y++)
1327 for (x = 1; x < cur_wid - 1; x++)
1329 /* There might be trap */
1330 cave[y][x].info |= CAVE_UNSAFE;
1337 * @brief フロアの全情報を初期化する / Clear and empty the cave
1340 void clear_cave(void)
1344 /* Very simplified version of wipe_o_list() */
1345 (void)C_WIPE(o_list, o_max, object_type);
1349 /* Very simplified version of wipe_m_list() */
1350 for (i = 1; i < max_r_idx; i++)
1351 r_info[i].cur_num = 0;
1352 (void)C_WIPE(m_list, m_max, monster_type);
1355 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1357 /* Pre-calc cur_num of pets in party_mon[] */
1358 precalc_cur_num_of_pet();
1361 /* Start with a blank cave */
1362 for (y = 0; y < MAX_HGT; y++)
1364 for (x = 0; x < MAX_WID; x++)
1366 cave_type *c_ptr = &cave[y][x];
1393 /* Mega-Hack -- no player yet */
1394 p_ptr->x = p_ptr->y = 0;
1396 /* Set the base level */
1397 base_level = dun_level;
1399 /* Reset the monster generation level */
1400 monster_level = base_level;
1402 /* Reset the object generation level */
1403 object_level = base_level;
1408 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
1410 * @note Hack -- regenerate any "overflow" levels
1412 void generate_cave(void)
1416 /* Fill the arrays of floors and walls in the good proportions */
1417 set_floor_and_wall(dungeon_type);
1420 for (num = 0; TRUE; num++)
1426 /* Clear and empty the cave */
1429 /* Build the arena -KMW- */
1430 if (p_ptr->inside_arena)
1436 /* Build the battle -KMW- */
1437 else if (p_ptr->inside_battle)
1443 else if (p_ptr->inside_quest)
1448 /* Build the town */
1449 else if (!dun_level)
1451 /* Make the wilderness */
1452 if (p_ptr->wild_mode) wilderness_gen_small();
1453 else wilderness_gen();
1456 /* Build a real level */
1459 okay = level_gen(&why);
1463 /* Prevent object over-flow */
1464 if (o_max >= max_o_idx)
1470 why = "too many objects";
1477 /* Prevent monster over-flow */
1478 else if (m_max >= max_m_idx)
1484 why = "too many monsters";
1497 if (why) msg_format("生成やり直し(%s)", why);
1499 if (why) msg_format("Generation restarted (%s)", why);
1503 /* Wipe the objects */
1506 /* Wipe the monsters */
1510 /* Glow deep lava and building entrances */
1511 glow_deep_lava_and_bldg();
1514 p_ptr->enter_dungeon = FALSE;
1516 wipe_generate_cave_flags();