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.
120 * @param y ´ð½à¤ÎyºÂɸ
121 * @param x ´ð½à¤ÎxºÂɸ
122 * @return ÎÙÀܤ¹¤ë³°Êɤοô
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?
140 * @param y ´ð½à¤ÎyºÂɸ
141 * @param x ´ð½à¤ÎxºÂɸ
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(int 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 ÇÛÃÖ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¼ïÎà
285 * @param num ÇÛÃÖ¤·¤¿¤¤¿ô
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)
337 msg_print("·Ù¹ð¡ª¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
339 msg_print("Warning! Could not place object!");
347 /* Place something */
350 case ALLOC_TYP_RUBBLE:
353 cave[y][x].info &= ~(CAVE_FLOOR);
360 cave[y][x].info &= ~(CAVE_FLOOR);
370 case ALLOC_TYP_OBJECT:
372 place_object(y, x, 0L);
380 * @brief ÎÙÀÜ4¥Þ¥¹¤Ë¸ºß¤¹¤ëÄÌÏ©¤Î¿ô¤òÊÖ¤¹ / Count the number of "corridor" grids adjacent to the given grid.
381 * @param y1 ´ð½à¤È¤Ê¤ë¥Þ¥¹¤ÎYºÂɸ
382 * @param x1 ´ð½à¤È¤Ê¤ë¥Þ¥¹¤ÎXºÂɸ
384 * @note Assumes "in_bounds(y1, x1)"
386 * XXX XXX This routine currently only counts actual "empty floor"\n
387 * grids which are not in rooms. We might want to also count stairs,\n
388 * open doors, closed doors, etc.
390 static int next_to_corr(int y1, int x1)
396 /* Scan adjacent grids */
397 for (i = 0; i < 4; i++)
399 /* Extract the location */
403 /* Access the grid */
406 /* Skip non floors */
407 if (cave_have_flag_grid(c_ptr, FF_WALL)) continue;
409 /* Skip non "empty floor" grids */
410 if (!is_floor_grid(c_ptr))
413 /* Skip grids inside rooms */
414 if (c_ptr->info & (CAVE_ROOM)) continue;
416 /* Count these grids */
420 /* Return the number of corridors */
426 * @brief ¥É¥¢¤òÀßÃÖ²Äǽ¤ÊÃÏ·Á¤«¤òÊÖ¤¹ / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
427 * @param y ȽÄê¤ò¹Ô¤¤¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
428 * @param x ȽÄê¤ò¹Ô¤¤¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
429 * @return ¥É¥¢¤òÀßÃÖ²Äǽ¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
430 * @note Assumes "in_bounds(y1, x1)"
433 * Assumes "in_bounds(y, x)"\n
435 static bool possible_doorway(int y, int x)
437 /* Count the adjacent corridors */
438 if (next_to_corr(y, x) >= 2)
441 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
442 cave_have_flag_bold(y + 1, x, FF_WALL))
447 /* Check Horizontal */
448 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
449 cave_have_flag_bold(y, x + 1, FF_WALL))
460 * @brief ¥É¥¢¤ÎÀßÃÖ¤ò»î¤ß¤ë / Places door at y, x position if at least 2 walls found
461 * @param y ÀßÃÖ¤ò¹Ô¤¤¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
462 * @param x ÀßÃÖ¤ò¹Ô¤¤¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
465 static void try_door(int y, int x)
468 if (!in_bounds(y, x)) return;
471 if (cave_have_flag_bold(y, x, FF_WALL)) return;
473 /* Ignore room grids */
474 if (cave[y][x].info & (CAVE_ROOM)) return;
476 /* Occasional door (if allowed) */
477 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
480 place_random_door(y, x, FALSE);
486 * @brief ¥¯¥¨¥¹¥È¤Ë´Ø¤ï¤ë¥â¥ó¥¹¥¿¡¼¤ÎÇÛÃÖ¤ò¹Ô¤¦ / Place quest monsters
487 * @return À®¸ù¤·¤¿¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
489 bool place_quest_monsters(void)
493 /* Handle the quest monster placements */
494 for (i = 0; i < max_quests; i++)
500 if (quest[i].status != QUEST_STATUS_TAKEN ||
501 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
502 quest[i].type != QUEST_TYPE_RANDOM) ||
503 quest[i].level != dun_level ||
504 dungeon_type != quest[i].dungeon ||
505 (quest[i].flags & QUEST_FLAG_PRESET))
511 r_ptr = &r_info[quest[i].r_idx];
513 /* Hack -- "unique" monsters must be "unique" */
514 if ((r_ptr->flags1 & RF1_UNIQUE) &&
515 (r_ptr->cur_num >= r_ptr->max_num)) continue;
517 mode = (PM_NO_KAGE | PM_NO_PET);
519 if (!(r_ptr->flags1 & RF1_FRIENDS))
520 mode |= PM_ALLOW_GROUP;
522 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
526 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
531 /* Find an empty grid */
532 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
537 y = randint0(cur_hgt);
538 x = randint0(cur_wid);
541 f_ptr = &f_info[c_ptr->feat];
543 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
544 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
545 if (distance(y, x, py, px) < 10) continue;
546 if (c_ptr->info & CAVE_ICKY) continue;
550 /* Failed to place */
551 if (!l) return FALSE;
553 /* Try to place the monster */
554 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
561 /* Failure - Try again */
566 /* Failed to place */
567 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
576 * @brief ¥Þ¥¹¤Ë¥Õ¥í¥¢Ã¼ÍѤαʵ×ÊɤòÇÛÃÖ¤¹¤ë / Set boundary mimic and add "solid" perma-wall
577 * @param c_ptr ±Êµ×ÊɤòÇѻߤ·¤¿¤¤¥Þ¥¹¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
580 static void set_bound_perm_wall(cave_type *c_ptr)
582 if (bound_walls_perm)
584 /* Clear boundary mimic */
589 feature_type *f_ptr = &f_info[c_ptr->feat];
591 /* Hack -- Decline boundary walls with known treasure */
592 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
593 !have_flag(f_ptr->flags, FF_SECRET))
594 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
596 /* Set boundary mimic */
597 c_ptr->mimic = c_ptr->feat;
600 /* Add "solid" perma-wall */
601 place_solid_perm_grid(c_ptr);
605 * @brief ¥Õ¥í¥¢¤Ëƶ·¢¤ä¸Ð¤òÇÛÃÖ¤¹¤ë / Generate various caverns and lakes
606 * @details There were moved from cave_gen().
609 static void gen_caverns_and_lakes(void)
611 #ifdef ALLOW_CAVERNS_AND_LAKES
612 /* Possible "destroyed" level */
613 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
615 dun->destroyed = TRUE;
617 /* extra rubble around the place looks cool */
618 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
621 /* Make a lake some of the time */
622 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
623 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
626 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
627 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
628 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
629 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
631 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
634 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
638 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
642 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
645 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
649 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
653 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
656 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
659 /* Lake of rubble2 */
660 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
665 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
671 msg_print("¸Ð¤òÀ¸À®¡£");
673 msg_print("Lake on the level.");
676 build_lake(dun->laketype);
680 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
681 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
682 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
686 /* make a large fractal cave in the middle of the dungeon */
690 msg_print("ƶ·¢¤òÀ¸À®¡£");
692 msg_print("Cavern on level.");
697 #endif /* ALLOW_CAVERNS_AND_LAKES */
699 /* Hack -- No destroyed "quest" levels */
700 if (quest_number(dun_level)) dun->destroyed = FALSE;
705 * @brief ¥À¥ó¥¸¥ç¥óÀ¸À®¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó / Generate a new dungeon level
706 * @details Note that "dun_body" adds about 4000 bytes of memory to the stack.
707 * @return ¥À¥ó¥¸¥ç¥óÀ¸À®¤¬Á´¤Æ̵»ö¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹¡£
709 static bool cave_gen(void)
718 dun->destroyed = FALSE;
719 dun->empty_level = FALSE;
723 /* Fill the arrays of floors and walls in the good proportions */
724 set_floor_and_wall(dungeon_type);
726 /* Prepare allocation table */
727 get_mon_num_prep(get_monster_hook(), NULL);
729 /* Randomize the dungeon creation values */
730 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
731 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
732 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
733 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
734 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
736 /* Actual maximum number of rooms on this level */
737 dun->row_rooms = cur_hgt / BLOCK_HGT;
738 dun->col_rooms = cur_wid / BLOCK_WID;
740 /* Initialize the room table */
741 for (y = 0; y < dun->row_rooms; y++)
743 for (x = 0; x < dun->col_rooms; x++)
745 dun->room_map[y][x] = FALSE;
752 /* Empty arena levels */
753 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
755 dun->empty_level = TRUE;
759 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
761 msg_print("Arena level.");
765 if (dun->empty_level)
767 /* Start with floors */
768 for (y = 0; y < cur_hgt; y++)
770 for (x = 0; x < cur_wid; x++)
772 place_floor_bold(y, x);
776 /* Special boundary walls -- Top and bottom */
777 for (x = 0; x < cur_wid; x++)
779 place_extra_bold(0, x);
780 place_extra_bold(cur_hgt - 1, x);
783 /* Special boundary walls -- Left and right */
784 for (y = 1; y < (cur_hgt - 1); y++)
786 place_extra_bold(y, 0);
787 place_extra_bold(y, cur_wid - 1);
792 /* Start with walls */
793 for (y = 0; y < cur_hgt; y++)
795 for (x = 0; x < cur_wid; x++)
797 place_extra_bold(y, x);
803 /* Generate various caverns and lakes */
804 gen_caverns_and_lakes();
808 if (d_info[dungeon_type].flags1 & DF1_MAZE)
810 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
812 /* Place 3 or 4 down stairs near some walls */
813 if (!alloc_stairs(feat_down_stair, rand_range(2, 3), 3)) return FALSE;
815 /* Place 1 or 2 up stairs near some walls */
816 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
819 /* Build some rooms */
822 int tunnel_fail_count = 0;
825 * Build each type of room in turn until we cannot build any more.
827 if (!generate_rooms()) return FALSE;
830 /* Make a hole in the dungeon roof sometimes at level 1 */
833 while (one_in_(DUN_MOS_DEN))
835 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
839 /* Destroy the level if necessary */
840 if (dun->destroyed) destroy_level();
842 /* Hack -- Add some rivers */
843 if (one_in_(3) && (randint1(dun_level) > 5))
845 int feat1 = 0, feat2 = 0;
847 /* Choose water or lava */
848 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
850 feat1 = feat_deep_water;
851 feat2 = feat_shallow_water;
853 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
855 feat1 = feat_deep_lava;
856 feat2 = feat_shallow_lava;
862 feature_type *f_ptr = &f_info[feat1];
864 /* Only add river if matches lake type or if have no lake at all */
865 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
866 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
869 add_river(feat1, feat2);
874 /* Hack -- Scramble the room order */
875 for (i = 0; i < dun->cent_n; i++)
878 int pick = rand_range(0, i);
882 dun->cent[i].y = dun->cent[pick].y;
883 dun->cent[i].x = dun->cent[pick].x;
884 dun->cent[pick].y = ty;
885 dun->cent[pick].x = tx;
888 /* Start with no tunnel doors */
891 /* Hack -- connect the first room to the last room */
892 y = dun->cent[dun->cent_n-1].y;
893 x = dun->cent[dun->cent_n-1].x;
895 /* Connect all the rooms together */
896 for (i = 0; i < dun->cent_n; i++)
900 /* Reset the arrays */
904 /* Connect the room to the previous room */
905 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
907 /* make cave-like tunnel */
908 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
912 /* make normal tunnel */
913 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
916 if (tunnel_fail_count >= 2) return FALSE;
918 /* Turn the tunnel into corridor */
919 for (j = 0; j < dun->tunn_n; j++)
924 /* Access the grid */
928 /* Access the grid */
930 f_ptr = &f_info[c_ptr->feat];
932 /* Clear previous contents (if not a lake), add a floor */
933 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
935 /* Clear mimic type */
938 place_floor_grid(c_ptr);
942 /* Apply the piercings that we found */
943 for (j = 0; j < dun->wall_n; j++)
947 /* Access the grid */
951 /* Access the grid */
954 /* Clear mimic type */
957 /* Clear previous contents, add up floor */
958 place_floor_grid(c_ptr);
960 /* Occasional doorway */
961 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
963 /* Place a random door */
964 place_random_door(y, x, TRUE);
968 /* Remember the "previous" room */
973 /* Place intersection doors */
974 for (i = 0; i < dun->door_n; i++)
976 /* Extract junction location */
980 /* Try placing doors */
987 /* Place 3 or 4 down stairs near some walls */
988 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
990 /* Place 1 or 2 up stairs near some walls */
991 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
996 if (d_info[dungeon_type].stream2)
998 /* Hack -- Add some quartz streamers */
999 for (i = 0; i < DUN_STR_QUA; i++)
1001 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
1005 if (d_info[dungeon_type].stream1)
1007 /* Hack -- Add some magma streamers */
1008 for (i = 0; i < DUN_STR_MAG; i++)
1010 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
1015 /* Special boundary walls -- Top and bottom */
1016 for (x = 0; x < cur_wid; x++)
1018 set_bound_perm_wall(&cave[0][x]);
1019 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
1022 /* Special boundary walls -- Left and right */
1023 for (y = 1; y < (cur_hgt - 1); y++)
1025 set_bound_perm_wall(&cave[y][0]);
1026 set_bound_perm_wall(&cave[y][cur_wid - 1]);
1029 /* Determine the character location */
1030 if (!new_player_spot()) return FALSE;
1032 if (!place_quest_monsters()) return FALSE;
1034 /* Basic "amount" */
1035 k = (dun_level / 3);
1039 /* Pick a base number of monsters */
1040 i = d_info[dungeon_type].min_m_alloc_level;
1042 /* To make small levels a bit more playable */
1043 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1045 int small_tester = i;
1047 i = (i * cur_hgt) / MAX_HGT;
1048 i = (i * cur_wid) / MAX_WID;
1051 if (i > small_tester) i = small_tester;
1052 else if (cheat_hear)
1055 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
1057 msg_format("Reduced monsters base from %d to %d", small_tester, i);
1065 /* Put some monsters in the dungeon */
1066 for (i = i + k; i > 0; i--)
1068 (void)alloc_monster(0, PM_ALLOW_SLEEP);
1071 /* Place some traps in the dungeon */
1072 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
1074 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
1075 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
1077 /* Mega Hack -- No object at first level of deeper dungeon */
1078 if (p_ptr->enter_dungeon && dun_level > 1)
1080 /* No stair scum! */
1084 /* Put some objects in rooms */
1085 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1087 /* Put some objects/gold in the dungeon */
1088 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1089 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1091 /* Set back to default */
1092 object_level = base_level;
1094 /* Put the Guardian */
1095 if (!alloc_guardian(TRUE)) return FALSE;
1097 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1100 for (y = 0; y < cur_hgt; y++)
1102 for (x = 0; x < cur_wid; x++)
1104 cave[y][x].info |= (CAVE_GLOW);
1113 * @brief Æ®µ»¾ìÍѤΥ¢¥ê¡¼¥ÊÃÏ·Á¤òºîÀ®¤¹¤ë / Builds the arena after it is entered -KMW-
1116 static void build_arena(void)
1118 int yval, y_height, y_depth, xval, x_left, x_right;
1121 yval = SCREEN_HGT / 2;
1122 xval = SCREEN_WID / 2;
1123 y_height = yval - 10;
1124 y_depth = yval + 10;
1126 x_right = xval + 32;
1128 for (i = y_height; i <= y_height + 5; i++)
1129 for (j = x_left; j <= x_right; j++)
1131 place_extra_perm_bold(i, j);
1132 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1134 for (i = y_depth; i >= y_depth - 5; i--)
1135 for (j = x_left; j <= x_right; j++)
1137 place_extra_perm_bold(i, j);
1138 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1140 for (j = x_left; j <= x_left + 17; j++)
1141 for (i = y_height; i <= y_depth; i++)
1143 place_extra_perm_bold(i, j);
1144 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1146 for (j = x_right; j >= x_right - 17; j--)
1147 for (i = y_height; i <= y_depth; i++)
1149 place_extra_perm_bold(i, j);
1150 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1153 place_extra_perm_bold(y_height+6, x_left+18);
1154 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1155 place_extra_perm_bold(y_depth-6, x_left+18);
1156 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1157 place_extra_perm_bold(y_height+6, x_right-18);
1158 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1159 place_extra_perm_bold(y_depth-6, x_right-18);
1160 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1164 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1165 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1170 * @brief Æ®µ»¾ì¤Ø¤ÎÆþ¾ì½èÍý / Town logic flow for generation of arena -KMW-
1173 static void arena_gen(void)
1180 cur_hgt = SCREEN_HGT;
1181 cur_wid = SCREEN_WID;
1183 /* Start with solid walls */
1184 for (y = 0; y < MAX_HGT; y++)
1186 for (x = 0; x < MAX_WID; x++)
1188 /* Create "solid" perma-wall */
1189 place_solid_perm_bold(y, x);
1191 /* Illuminate and memorize the walls */
1192 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1196 /* Then place some floors */
1197 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1199 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1201 /* Create empty floor */
1202 cave[y][x].feat = feat_floor;
1208 if(!place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
1210 p_ptr->exit_bldg = TRUE;
1211 p_ptr->arena_number++;
1213 msg_print("Áê¼ê¤Ï·ç¾ì¤·¤¿¡£¤¢¤Ê¤¿¤ÎÉÔÀᄀ¤À¡£");
1215 msg_print("The enemy is unable appear. You won by default.");
1222 * @brief ¥â¥ó¥¹¥¿¡¼Æ®µ»¾ì¤Î¥Õ¥í¥¢À¸À® / Builds the arena after it is entered -KMW-
1225 static void build_battle(void)
1227 int yval, y_height, y_depth, xval, x_left, x_right;
1230 yval = SCREEN_HGT / 2;
1231 xval = SCREEN_WID / 2;
1232 y_height = yval - 10;
1233 y_depth = yval + 10;
1235 x_right = xval + 32;
1237 for (i = y_height; i <= y_height + 5; i++)
1238 for (j = x_left; j <= x_right; j++)
1240 place_extra_perm_bold(i, j);
1241 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1243 for (i = y_depth; i >= y_depth - 3; i--)
1244 for (j = x_left; j <= x_right; j++)
1246 place_extra_perm_bold(i, j);
1247 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1249 for (j = x_left; j <= x_left + 17; j++)
1250 for (i = y_height; i <= y_depth; i++)
1252 place_extra_perm_bold(i, j);
1253 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1255 for (j = x_right; j >= x_right - 17; j--)
1256 for (i = y_height; i <= y_depth; i++)
1258 place_extra_perm_bold(i, j);
1259 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1262 place_extra_perm_bold(y_height+6, x_left+18);
1263 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1264 place_extra_perm_bold(y_depth-4, x_left+18);
1265 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1266 place_extra_perm_bold(y_height+6, x_right-18);
1267 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1268 place_extra_perm_bold(y_depth-4, x_right-18);
1269 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1271 for (i = y_height + 1; i <= y_height + 5; i++)
1272 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1274 cave[i][j].feat = feat_permanent_glass_wall;
1279 cave[i][j].feat = f_tag_to_index("BUILDING_3");
1280 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1285 * @brief ¥â¥ó¥¹¥¿¡¼Æ®µ»¾ì¤Ø¤ÎƳÆþ½èÍý / Town logic flow for generation of arena -KMW-
1288 static void battle_gen(void)
1294 /* Start with solid walls */
1295 for (y = 0; y < MAX_HGT; y++)
1297 for (x = 0; x < MAX_WID; x++)
1299 /* Create "solid" perma-wall */
1300 place_solid_perm_bold(y, x);
1302 /* Illuminate and memorize the walls */
1303 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1307 /* Then place some floors */
1308 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1310 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1312 /* Create empty floor */
1313 cave[y][x].feat = feat_floor;
1321 place_monster_aux(0, py + 8 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1322 (PM_NO_KAGE | PM_NO_PET));
1323 set_friendly(&m_list[cave[py+8+(i/2)*4][px-2+(i%2)*4].m_idx]);
1325 for(i = 1; i < m_max; i++)
1327 monster_type *m_ptr = &m_list[i];
1329 if (!m_ptr->r_idx) continue;
1331 /* Hack -- Detect monster */
1332 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1334 /* Update the monster */
1335 update_mon(i, FALSE);
1340 * @brief ¸ÇÄê¥Þ¥Ã¥×¥¯¥¨¥¹¥È¤Î¥Õ¥í¥¢À¸À® / Generate a quest level
1343 static void quest_gen(void)
1348 /* Start with perm walls */
1349 for (y = 0; y < cur_hgt; y++)
1351 for (x = 0; x < cur_wid; x++)
1353 place_solid_perm_bold(y, x);
1357 /* Set the quest level */
1358 base_level = quest[p_ptr->inside_quest].level;
1359 dun_level = base_level;
1360 object_level = base_level;
1361 monster_level = base_level;
1363 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1365 /* Prepare allocation table */
1366 get_mon_num_prep(get_monster_hook(), NULL);
1368 init_flags = INIT_CREATE_DUNGEON;
1370 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1374 * @brief ¥À¥ó¥¸¥ç¥ó»þ¤Î¥é¥ó¥À¥à¥Õ¥í¥¢À¸À® / Make a real level
1375 * @return ¥Õ¥í¥¢¤ÎÀ¸À®¤ËÀ®¸ù¤·¤¿¤éTRUE
1377 static bool level_gen(cptr *why)
1379 int level_height, level_width;
1381 if ((always_small_levels || ironman_small_levels ||
1382 (one_in_(SMALL_LEVEL) && small_levels) ||
1383 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1384 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1385 !(d_info[dungeon_type].flags1 & DF1_BIG))
1389 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1391 msg_print("A 'small' dungeon level.");
1394 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1399 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1408 level_height = randint1(MAX_HGT/SCREEN_HGT);
1409 level_width = randint1(MAX_WID/SCREEN_WID);
1411 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1412 (level_width == MAX_WID/SCREEN_WID));
1415 cur_hgt = level_height * SCREEN_HGT;
1416 cur_wid = level_width * SCREEN_WID;
1418 /* Assume illegal panel */
1419 panel_row_min = cur_hgt;
1420 panel_col_min = cur_wid;
1423 msg_format("X:%d, Y:%d.", cur_wid, cur_hgt);
1431 /* Assume illegal panel */
1432 panel_row_min = cur_hgt;
1433 panel_col_min = cur_wid;
1436 /* Make a dungeon */
1440 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1442 *why = "could not place player";
1451 * @brief ¥Õ¥í¥¢¤Ë¸ºß¤¹¤ëÁ´¥Þ¥¹¤Îµ²±¾õÂÖ¤ò½é´ü²½¤¹¤ë / Wipe all unnecessary flags after cave generation
1454 void wipe_generate_cave_flags(void)
1458 for (y = 0; y < cur_hgt; y++)
1460 for (x = 0; x < cur_wid; x++)
1462 /* Wipe unused flags */
1463 cave[y][x].info &= ~(CAVE_MASK);
1469 for (y = 1; y < cur_hgt - 1; y++)
1471 for (x = 1; x < cur_wid - 1; x++)
1473 /* There might be trap */
1474 cave[y][x].info |= CAVE_UNSAFE;
1481 * @brief ¥Õ¥í¥¢¤ÎÁ´¾ðÊó¤ò½é´ü²½¤¹¤ë / Clear and empty the cave
1484 void clear_cave(void)
1488 /* Very simplified version of wipe_o_list() */
1489 (void)C_WIPE(o_list, o_max, object_type);
1493 /* Very simplified version of wipe_m_list() */
1494 for (i = 1; i < max_r_idx; i++)
1495 r_info[i].cur_num = 0;
1496 (void)C_WIPE(m_list, m_max, monster_type);
1499 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1501 /* Pre-calc cur_num of pets in party_mon[] */
1502 precalc_cur_num_of_pet();
1505 /* Start with a blank cave */
1506 for (y = 0; y < MAX_HGT; y++)
1508 for (x = 0; x < MAX_WID; x++)
1510 cave_type *c_ptr = &cave[y][x];
1537 /* Mega-Hack -- no player yet */
1540 /* Set the base level */
1541 base_level = dun_level;
1543 /* Reset the monster generation level */
1544 monster_level = base_level;
1546 /* Reset the object generation level */
1547 object_level = base_level;
1552 * ¥À¥ó¥¸¥ç¥ó¤Î¥é¥ó¥À¥à¥Õ¥í¥¢¤òÀ¸À®¤¹¤ë / Generates a random dungeon level -RAK-
1554 * @note Hack -- regenerate any "overflow" levels
1556 void generate_cave(void)
1560 /* Fill the arrays of floors and walls in the good proportions */
1561 set_floor_and_wall(dungeon_type);
1564 for (num = 0; TRUE; num++)
1570 /* Clear and empty the cave */
1573 /* Build the arena -KMW- */
1574 if (p_ptr->inside_arena)
1580 /* Build the battle -KMW- */
1581 else if (p_ptr->inside_battle)
1587 else if (p_ptr->inside_quest)
1592 /* Build the town */
1593 else if (!dun_level)
1595 /* Make the wilderness */
1596 if (p_ptr->wild_mode) wilderness_gen_small();
1597 else wilderness_gen();
1600 /* Build a real level */
1603 okay = level_gen(&why);
1607 /* Prevent object over-flow */
1608 if (o_max >= max_o_idx)
1612 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1614 why = "too many objects";
1621 /* Prevent monster over-flow */
1622 else if (m_max >= max_m_idx)
1626 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1628 why = "too many monsters";
1641 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1643 if (why) msg_format("Generation restarted (%s)", why);
1647 /* Wipe the objects */
1650 /* Wipe the monsters */
1654 /* Glow deep lava and building entrances */
1655 glow_deep_lava_and_bldg();
1658 p_ptr->enter_dungeon = FALSE;
1660 wipe_generate_cave_flags();