4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Dungeon generation */
14 * Note that Level generation is *not* an important bottleneck,
15 * though it can be annoyingly slow on older machines... Thus
16 * we emphasize "simplicity" and "correctness" over "speed".
18 * This entire file is only needed for generating levels.
19 * This may allow smart compilers to only load it when needed.
21 * Consider the "v_info.txt" file for vault generation.
23 * In this file, we use the "special" granite and perma-wall sub-types,
24 * where "basic" is normal, "inner" is inside a room, "outer" is the
25 * outer wall of a room, and "solid" is the outer wall of the dungeon
26 * or any walls that may not be pierced by corridors. Thus the only
27 * wall type that may be pierced by a corridor is the "outer granite"
28 * type. The "basic granite" type yields the "actual" corridors.
30 * Note that we use the special "solid" granite wall type to prevent
31 * multiple corridors from piercing a wall in two adjacent locations,
32 * which would be messy, and we use the special "outer" granite wall
33 * to indicate which walls "surround" rooms, and may thus be "pierced"
34 * by corridors entering or leaving the room.
36 * Note that a tunnel which attempts to leave a room near the "edge"
37 * of the dungeon in a direction toward that edge will cause "silly"
38 * wall piercings, but will have no permanently incorrect effects,
39 * as long as the tunnel can *eventually* exit from another side.
40 * And note that the wall may not come back into the room by the
41 * hole it left through, so it must bend to the left or right and
42 * then optionally re-enter the room (at least 2 grids away). This
43 * is not a problem since every room that is large enough to block
44 * the passage of tunnels is also large enough to allow the tunnel
45 * to pierce the room itself several times.
47 * Note that no two corridors may enter a room through adjacent grids,
48 * they must either share an entryway or else use entryways at least
49 * two grids apart. This prevents "large" (or "silly") doorways.
51 * To create rooms in the dungeon, we first divide the dungeon up
52 * into "blocks" of 11x11 grids each, and require that all rooms
53 * occupy a rectangular group of blocks. As long as each room type
54 * reserves a sufficient number of blocks, the room building routines
55 * will not need to check bounds. Note that most of the normal rooms
56 * actually only use 23x11 grids, and so reserve 33x11 grids.
58 * Note that the use of 11x11 blocks (instead of the old 33x11 blocks)
59 * allows more variability in the horizontal placement of rooms, and
60 * at the same time has the disadvantage that some rooms (two thirds
61 * of the normal rooms) may be "split" by panel boundaries. This can
62 * induce a situation where a player is in a room and part of the room
63 * is off the screen. It may be annoying enough to go back to 33x11
64 * blocks to prevent this visual situation.
66 * Note that the dungeon generation routines are much different (2.7.5)
67 * and perhaps "DUN_ROOMS" should be less than 50.
69 * XXX XXX XXX Note that it is possible to create a room which is only
70 * connected to itself, because the "tunnel generation" code allows a
71 * tunnel to leave a room, wander around, and then re-enter the room.
73 * XXX XXX XXX Note that it is possible to create a set of rooms which
74 * are only connected to other rooms in that set, since there is nothing
75 * explicit in the code to prevent this from happening. But this is less
76 * likely than the "isolated room" problem, because each room attempts to
77 * connect to another room, in a giant cycle, thus requiring at least two
78 * bizarre occurances to create an isolated section of the dungeon.
80 * Note that (2.7.9) monster pits have been split into monster "nests"
81 * and monster "pits". The "nests" have a collection of monsters of a
82 * given type strewn randomly around the room (jelly, animal, or undead),
83 * while the "pits" have a collection of monsters of a given type placed
84 * around the room in an organized manner (orc, troll, giant, dragon, or
85 * demon). Note that both "nests" and "pits" are now "level dependant",
86 * and both make 16 "expensive" calls to the "get_mon_num()" function.
88 * Note that the cave grid flags changed in a rather drastic manner
89 * for Angband 2.8.0 (and 2.7.9+), in particular, dungeon terrain
90 * features, such as doors and stairs and traps and rubble and walls,
91 * are all handled as a set of 64 possible "terrain features", and
92 * not as "fake" objects (440-479) as in pre-2.8.0 versions.
94 * The 64 new "dungeon features" will also be used for "visual display"
95 * but we must be careful not to allow, for example, the user to display
96 * hidden traps in a different way from floors, or secret doors in a way
97 * different from granite walls, or even permanent granite in a different
98 * way from granite. XXX XXX XXX
102 #include "generate.h"
115 * Dungeon generation data -- see "cave_gen()"
121 * Count the number of walls adjacent to the given grid.
123 * Note -- Assumes "in_bounds(y, x)"
125 * We count only granite walls and permanent walls.
127 static int next_to_walls(int y, int x)
131 if (in_bounds(y + 1, x) && is_extra_bold(y + 1, x)) k++;
132 if (in_bounds(y - 1, x) && is_extra_bold(y - 1, x)) k++;
133 if (in_bounds(y, x + 1) && is_extra_bold(y, x + 1)) k++;
134 if (in_bounds(y, x - 1) && is_extra_bold(y, x - 1)) k++;
141 * Helper function for alloc_stairs().
143 * Is this a good location for stairs?
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 * Places some staircases near walls
165 static bool alloc_stairs(int feat, int num, int walls)
170 feature_type *f_ptr = &f_info[feat];
172 if (have_flag(f_ptr->flags, FF_LESS))
174 /* No up stairs in town or in ironman mode */
175 if (ironman_downward || !dun_level) return TRUE;
177 if (dun_level > d_info[dungeon_type].mindepth)
178 shaft_num = (randint1(num+1))/2;
180 else if (have_flag(f_ptr->flags, FF_MORE))
182 int q_idx = quest_number(dun_level);
184 /* No downstairs on quest levels */
185 if (dun_level > 1 && q_idx)
187 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
189 /* The quest monster(s) is still alive? */
190 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
194 /* No downstairs at the bottom */
195 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
197 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
198 shaft_num = (randint1(num)+1)/2;
205 /* Place "num" stairs */
206 for (i = 0; i < num; i++)
216 for (y = 1; y < cur_hgt - 1; y++)
218 for (x = 1; x < cur_wid - 1; x++)
220 if (alloc_stairs_aux(y, x, walls))
222 /* A valid space found */
228 /* No valid place! */
231 /* There are exactly no place! */
232 if (walls <= 0) return FALSE;
234 /* Decrease walls limit, and try again */
239 /* Choose a random one */
240 pick = randint1(candidates);
242 for (y = 1; y < cur_hgt - 1; y++)
244 for (x = 1; x < cur_wid - 1; x++)
246 if (alloc_stairs_aux(y, x, walls))
250 /* Is this a picked one? */
258 /* Access the grid */
261 /* Clear possible garbage of hidden trap */
264 /* Clear previous contents, add stairs */
265 c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
267 /* No longer "FLOOR" */
268 c_ptr->info &= ~(CAVE_FLOOR);
279 * Allocates some objects (using "place" and "type")
281 static void alloc_object(int set, int typ, int num)
287 /* A small level has few objects. */
288 num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
290 /* Place some objects */
291 for (k = 0; k < num; k++)
293 /* Pick a "legal" spot */
294 while (dummy < SAFE_MAX_ATTEMPTS)
301 y = randint0(cur_hgt);
302 x = randint0(cur_wid);
306 /* Require "naked" floor grid */
307 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
309 /* Avoid player location */
310 if (player_bold(y, x)) continue;
312 /* Check for "room" */
313 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
315 /* Require corridor? */
316 if ((set == ALLOC_SET_CORR) && room) continue;
319 if ((set == ALLOC_SET_ROOM) && !room) continue;
325 if (dummy >= SAFE_MAX_ATTEMPTS)
330 msg_print("·Ù¹ð¡ª¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
332 msg_print("Warning! Could not place object!");
340 /* Place something */
343 case ALLOC_TYP_RUBBLE:
346 cave[y][x].info &= ~(CAVE_FLOOR);
353 cave[y][x].info &= ~(CAVE_FLOOR);
363 case ALLOC_TYP_OBJECT:
365 place_object(y, x, 0L);
374 * Count the number of "corridor" grids adjacent to the given grid.
376 * Note -- Assumes "in_bounds(y1, x1)"
378 * XXX XXX This routine currently only counts actual "empty floor"
379 * grids which are not in rooms. We might want to also count stairs,
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 * Determine if the given location is "between" two walls,
419 * and "next to" two corridor spaces. XXX XXX XXX
421 * Assumes "in_bounds(y, x)"
423 static bool possible_doorway(int y, int x)
425 /* Count the adjacent corridors */
426 if (next_to_corr(y, x) >= 2)
429 if (cave_have_flag_bold(y - 1, x, FF_WALL) &&
430 cave_have_flag_bold(y + 1, x, FF_WALL))
435 /* Check Horizontal */
436 if (cave_have_flag_bold(y, x - 1, FF_WALL) &&
437 cave_have_flag_bold(y, x + 1, FF_WALL))
449 * Places door at y, x position if at least 2 walls found
451 static void try_door(int y, int x)
454 if (!in_bounds(y, x)) return;
457 if (cave_have_flag_bold(y, x, FF_WALL)) return;
459 /* Ignore room grids */
460 if (cave[y][x].info & (CAVE_ROOM)) return;
462 /* Occasional door (if allowed) */
463 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
466 place_random_door(y, x, FALSE);
471 /* Place quest monsters */
472 bool place_quest_monsters(void)
476 /* Handle the quest monster placements */
477 for (i = 0; i < max_quests; i++)
483 if (quest[i].status != QUEST_STATUS_TAKEN ||
484 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
485 quest[i].type != QUEST_TYPE_RANDOM) ||
486 quest[i].level != dun_level ||
487 dungeon_type != quest[i].dungeon ||
488 (quest[i].flags & QUEST_FLAG_PRESET))
494 r_ptr = &r_info[quest[i].r_idx];
496 /* Hack -- "unique" monsters must be "unique" */
497 if ((r_ptr->flags1 & RF1_UNIQUE) &&
498 (r_ptr->cur_num >= r_ptr->max_num)) continue;
500 mode = (PM_NO_KAGE | PM_NO_PET);
502 if (!(r_ptr->flags1 & RF1_FRIENDS))
503 mode |= PM_ALLOW_GROUP;
505 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
509 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
514 /* Find an empty grid */
515 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
520 y = randint0(cur_hgt);
521 x = randint0(cur_wid);
524 f_ptr = &f_info[c_ptr->feat];
526 if (!have_flag(f_ptr->flags, FF_MOVE) && !have_flag(f_ptr->flags, FF_CAN_FLY)) continue;
527 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
528 if (distance(y, x, py, px) < 10) continue;
529 if (c_ptr->info & CAVE_ICKY) continue;
533 /* Failed to place */
534 if (!l) return FALSE;
536 /* Try to place the monster */
537 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
544 /* Failure - Try again */
549 /* Failed to place */
550 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
559 * Set boundary mimic and add "solid" perma-wall
561 static void set_bound_perm_wall(cave_type *c_ptr)
563 if (bound_walls_perm)
565 /* Clear boundary mimic */
570 feature_type *f_ptr = &f_info[c_ptr->feat];
572 /* Hack -- Decline boundary walls with known treasure */
573 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
574 !have_flag(f_ptr->flags, FF_SECRET))
575 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
577 /* Set boundary mimic */
578 c_ptr->mimic = c_ptr->feat;
581 /* Add "solid" perma-wall */
582 place_solid_perm_grid(c_ptr);
587 * Generate various caverns and lakes
589 * There were moved from cave_gen().
591 static void gen_caverns_and_lakes(void)
593 #ifdef ALLOW_CAVERNS_AND_LAKES
594 /* Possible "destroyed" level */
595 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
597 dun->destroyed = TRUE;
599 /* extra rubble around the place looks cool */
600 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
603 /* Make a lake some of the time */
604 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
605 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
608 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
609 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
610 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
611 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
613 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
616 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
620 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
624 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
627 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
631 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
635 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
638 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
641 /* Lake of rubble2 */
642 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
647 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
653 msg_print("¸Ð¤òÀ¸À®¡£");
655 msg_print("Lake on the level.");
658 build_lake(dun->laketype);
662 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
663 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
664 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
668 /* make a large fractal cave in the middle of the dungeon */
672 msg_print("ƶ·¢¤òÀ¸À®¡£");
674 msg_print("Cavern on level.");
679 #endif /* ALLOW_CAVERNS_AND_LAKES */
681 /* Hack -- No destroyed "quest" levels */
682 if (quest_number(dun_level)) dun->destroyed = FALSE;
688 * Generate a new dungeon level
690 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
692 static bool cave_gen(void)
701 dun->destroyed = FALSE;
702 dun->empty_level = FALSE;
706 /* Fill the arrays of floors and walls in the good proportions */
707 set_floor_and_wall(dungeon_type);
709 /* Prepare allocation table */
710 get_mon_num_prep(get_monster_hook(), NULL);
712 /* Randomize the dungeon creation values */
713 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
714 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
715 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
716 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
717 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
719 /* Actual maximum number of rooms on this level */
720 dun->row_rooms = cur_hgt / BLOCK_HGT;
721 dun->col_rooms = cur_wid / BLOCK_WID;
723 /* Initialize the room table */
724 for (y = 0; y < dun->row_rooms; y++)
726 for (x = 0; x < dun->col_rooms; x++)
728 dun->room_map[y][x] = FALSE;
735 /* Empty arena levels */
736 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
738 dun->empty_level = TRUE;
742 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
744 msg_print("Arena level.");
748 if (dun->empty_level)
750 /* Start with floors */
751 for (y = 0; y < cur_hgt; y++)
753 for (x = 0; x < cur_wid; x++)
755 place_floor_bold(y, x);
759 /* Special boundary walls -- Top and bottom */
760 for (x = 0; x < cur_wid; x++)
762 place_extra_bold(0, x);
763 place_extra_bold(cur_hgt - 1, x);
766 /* Special boundary walls -- Left and right */
767 for (y = 1; y < (cur_hgt - 1); y++)
769 place_extra_bold(y, 0);
770 place_extra_bold(y, cur_wid - 1);
775 /* Start with walls */
776 for (y = 0; y < cur_hgt; y++)
778 for (x = 0; x < cur_wid; x++)
780 place_extra_bold(y, x);
786 /* Generate various caverns and lakes */
787 gen_caverns_and_lakes();
791 if (d_info[dungeon_type].flags1 & DF1_MAZE)
793 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
795 /* Place 3 or 4 down stairs near some walls */
796 if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
798 /* Place 1 or 2 up stairs near some walls */
799 if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
802 /* Build some rooms */
806 * Build each type of room in turn until we cannot build any more.
808 if (!generate_rooms()) return FALSE;
811 /* Make a hole in the dungeon roof sometimes at level 1 */
814 while (one_in_(DUN_MOS_DEN))
816 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
820 /* Destroy the level if necessary */
821 if (dun->destroyed) destroy_level();
823 /* Hack -- Add some rivers */
824 if (one_in_(3) && (randint1(dun_level) > 5))
826 int feat1 = 0, feat2 = 0;
828 /* Choose water or lava */
829 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
831 feat1 = FEAT_DEEP_WATER;
832 feat2 = FEAT_SHAL_WATER;
834 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
836 feat1 = FEAT_DEEP_LAVA;
837 feat2 = FEAT_SHAL_LAVA;
843 feature_type *f_ptr = &f_info[feat1];
845 /* Only add river if matches lake type or if have no lake at all */
846 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
847 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
850 add_river(feat1, feat2);
855 /* Hack -- Scramble the room order */
856 for (i = 0; i < dun->cent_n; i++)
859 int pick = rand_range(0, i);
863 dun->cent[i].y = dun->cent[pick].y;
864 dun->cent[i].x = dun->cent[pick].x;
865 dun->cent[pick].y = ty;
866 dun->cent[pick].x = tx;
869 /* Start with no tunnel doors */
872 /* Hack -- connect the first room to the last room */
873 y = dun->cent[dun->cent_n-1].y;
874 x = dun->cent[dun->cent_n-1].x;
876 /* Connect all the rooms together */
877 for (i = 0; i < dun->cent_n; i++)
881 /* Reset the arrays */
885 /* Connect the room to the previous room */
886 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
888 /* make cave-like tunnel */
889 build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
893 /* make normal tunnel */
894 build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
897 /* Turn the tunnel into corridor */
898 for (j = 0; j < dun->tunn_n; j++)
903 /* Access the grid */
907 /* Access the grid */
909 f_ptr = &f_info[c_ptr->feat];
911 /* Clear previous contents (if not a lake), add a floor */
912 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
914 /* Clear mimic type */
917 place_floor_grid(c_ptr);
921 /* Apply the piercings that we found */
922 for (j = 0; j < dun->wall_n; j++)
926 /* Access the grid */
930 /* Access the grid */
933 /* Clear mimic type */
936 /* Clear previous contents, add up floor */
937 place_floor_grid(c_ptr);
939 /* Occasional doorway */
940 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
942 /* Place a random door */
943 place_random_door(y, x, TRUE);
947 /* Remember the "previous" room */
952 /* Place intersection doors */
953 for (i = 0; i < dun->door_n; i++)
955 /* Extract junction location */
959 /* Try placing doors */
966 /* Place 3 or 4 down stairs near some walls */
967 if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
969 /* Place 1 or 2 up stairs near some walls */
970 if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
975 if (d_info[dungeon_type].stream2)
977 /* Hack -- Add some quartz streamers */
978 for (i = 0; i < DUN_STR_QUA; i++)
980 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
984 if (d_info[dungeon_type].stream1)
986 /* Hack -- Add some magma streamers */
987 for (i = 0; i < DUN_STR_MAG; i++)
989 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
994 /* Special boundary walls -- Top and bottom */
995 for (x = 0; x < cur_wid; x++)
997 set_bound_perm_wall(&cave[0][x]);
998 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
1001 /* Special boundary walls -- Left and right */
1002 for (y = 1; y < (cur_hgt - 1); y++)
1004 set_bound_perm_wall(&cave[y][0]);
1005 set_bound_perm_wall(&cave[y][cur_wid - 1]);
1008 /* Determine the character location */
1009 if (!new_player_spot()) return FALSE;
1011 if (!place_quest_monsters()) return FALSE;
1013 /* Basic "amount" */
1014 k = (dun_level / 3);
1018 /* Pick a base number of monsters */
1019 i = d_info[dungeon_type].min_m_alloc_level;
1021 /* To make small levels a bit more playable */
1022 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1024 int small_tester = i;
1026 i = (i * cur_hgt) / MAX_HGT;
1027 i = (i * cur_wid) / MAX_WID;
1030 if (i > small_tester) i = small_tester;
1031 else if (cheat_hear)
1034 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
1036 msg_format("Reduced monsters base from %d to %d", small_tester, i);
1044 /* Put some monsters in the dungeon */
1045 for (i = i + k; i > 0; i--)
1047 (void)alloc_monster(0, PM_ALLOW_SLEEP);
1050 /* Place some traps in the dungeon */
1051 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
1053 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
1054 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
1056 /* Mega Hack -- No object at first level of deeper dungeon */
1057 if (p_ptr->enter_dungeon && dun_level > 1)
1059 /* No stair scum! */
1063 /* Put some objects in rooms */
1064 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1066 /* Put some objects/gold in the dungeon */
1067 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1068 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1070 /* Set back to default */
1071 object_level = base_level;
1073 /* Put the Guardian */
1074 (void)alloc_guardian();
1076 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1079 for (y = 0; y < cur_hgt; y++)
1081 for (x = 0; x < cur_wid; x++)
1083 cave[y][x].info |= (CAVE_GLOW);
1093 * Builds the arena after it is entered -KMW-
1095 static void build_arena(void)
1097 int yval, y_height, y_depth, xval, x_left, x_right;
1100 yval = SCREEN_HGT / 2;
1101 xval = SCREEN_WID / 2;
1102 y_height = yval - 10;
1103 y_depth = yval + 10;
1105 x_right = xval + 32;
1107 for (i = y_height; i <= y_height + 5; i++)
1108 for (j = x_left; j <= x_right; j++)
1110 place_extra_perm_bold(i, j);
1111 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1113 for (i = y_depth; i >= y_depth - 5; i--)
1114 for (j = x_left; j <= x_right; j++)
1116 place_extra_perm_bold(i, j);
1117 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1119 for (j = x_left; j <= x_left + 17; j++)
1120 for (i = y_height; i <= y_depth; i++)
1122 place_extra_perm_bold(i, j);
1123 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1125 for (j = x_right; j >= x_right - 17; j--)
1126 for (i = y_height; i <= y_depth; i++)
1128 place_extra_perm_bold(i, j);
1129 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1132 place_extra_perm_bold(y_height+6, x_left+18);
1133 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1134 place_extra_perm_bold(y_depth-6, x_left+18);
1135 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1136 place_extra_perm_bold(y_height+6, x_right-18);
1137 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1138 place_extra_perm_bold(y_depth-6, x_right-18);
1139 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1143 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1144 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1150 * Town logic flow for generation of arena -KMW-
1152 static void arena_gen(void)
1159 cur_hgt = SCREEN_HGT;
1160 cur_wid = SCREEN_WID;
1162 /* Start with solid walls */
1163 for (y = 0; y < MAX_HGT; y++)
1165 for (x = 0; x < MAX_WID; x++)
1167 /* Create "solid" perma-wall */
1168 place_solid_perm_bold(y, x);
1170 /* Illuminate and memorize the walls */
1171 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1175 /* Then place some floors */
1176 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1178 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1180 /* Create empty floor */
1181 cave[y][x].feat = FEAT_FLOOR;
1187 place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx,
1188 (PM_NO_KAGE | PM_NO_PET));
1194 * Builds the arena after it is entered -KMW-
1196 static void build_battle(void)
1198 int yval, y_height, y_depth, xval, x_left, x_right;
1201 yval = SCREEN_HGT / 2;
1202 xval = SCREEN_WID / 2;
1203 y_height = yval - 10;
1204 y_depth = yval + 10;
1206 x_right = xval + 32;
1208 for (i = y_height; i <= y_height + 5; i++)
1209 for (j = x_left; j <= x_right; j++)
1211 place_extra_perm_bold(i, j);
1212 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1214 for (i = y_depth; i >= y_depth - 3; i--)
1215 for (j = x_left; j <= x_right; j++)
1217 place_extra_perm_bold(i, j);
1218 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1220 for (j = x_left; j <= x_left + 17; j++)
1221 for (i = y_height; i <= y_depth; i++)
1223 place_extra_perm_bold(i, j);
1224 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1226 for (j = x_right; j >= x_right - 17; j--)
1227 for (i = y_height; i <= y_depth; i++)
1229 place_extra_perm_bold(i, j);
1230 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1233 place_extra_perm_bold(y_height+6, x_left+18);
1234 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1235 place_extra_perm_bold(y_depth-4, x_left+18);
1236 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1237 place_extra_perm_bold(y_height+6, x_right-18);
1238 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1239 place_extra_perm_bold(y_depth-4, x_right-18);
1240 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1244 cave[i][j].feat = FEAT_BLDG_HEAD + 3;
1245 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1251 * Town logic flow for generation of arena -KMW-
1253 static void battle_gen(void)
1259 /* Start with solid walls */
1260 for (y = 0; y < MAX_HGT; y++)
1262 for (x = 0; x < MAX_WID; x++)
1264 /* Create "solid" perma-wall */
1265 place_solid_perm_bold(y, x);
1267 /* Illuminate and memorize the walls */
1268 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1272 /* Then place some floors */
1273 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1275 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1277 /* Create empty floor */
1278 cave[y][x].feat = FEAT_FLOOR;
1286 place_monster_aux(0, py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1287 (PM_NO_KAGE | PM_NO_PET));
1288 set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
1290 for(i = 1; i < m_max; i++)
1292 monster_type *m_ptr = &m_list[i];
1294 if (!m_ptr->r_idx) continue;
1296 /* Hack -- Detect monster */
1297 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1299 /* Update the monster */
1300 update_mon(i, FALSE);
1306 * Generate a quest level
1308 static void quest_gen(void)
1313 /* Start with perm walls */
1314 for (y = 0; y < cur_hgt; y++)
1316 for (x = 0; x < cur_wid; x++)
1318 place_solid_perm_bold(y, x);
1322 /* Set the quest level */
1323 base_level = quest[p_ptr->inside_quest].level;
1324 dun_level = base_level;
1325 object_level = base_level;
1326 monster_level = base_level;
1328 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1330 /* Prepare allocation table */
1331 get_mon_num_prep(get_monster_hook(), NULL);
1333 init_flags = INIT_CREATE_DUNGEON | INIT_ASSIGN;
1335 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1338 /* Make a real level */
1339 static bool level_gen(cptr *why)
1341 int level_height, level_width;
1343 if ((always_small_levels || ironman_small_levels ||
1344 (one_in_(SMALL_LEVEL) && small_levels) ||
1345 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1346 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1347 !(d_info[dungeon_type].flags1 & DF1_BIG))
1351 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1353 msg_print("A 'small' dungeon level.");
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;
1385 msg_format("X:%d, Y:%d.", cur_wid, cur_hgt);
1393 /* Assume illegal panel */
1394 panel_row_min = cur_hgt;
1395 panel_col_min = cur_wid;
1398 /* Make a dungeon */
1402 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1404 *why = "could not place player";
1414 * Wipe all unnecessary flags after cave generation
1416 static void wipe_generate_cave_flags(void)
1420 for (y = 0; y < cur_hgt; y++)
1422 for (x = 0; x < cur_wid; x++)
1424 /* Wipe unused flags */
1425 cave[y][x].info &= ~(CAVE_MASK);
1431 for (y = 1; y < cur_hgt - 1; y++)
1433 for (x = 1; x < cur_wid - 1; x++)
1435 /* There might be trap */
1436 cave[y][x].info |= CAVE_UNSAFE;
1444 * Clear and empty the cave
1446 void clear_cave(void)
1450 /* Very simplified version of wipe_o_list() */
1451 C_WIPE(o_list, o_max, object_type);
1455 /* Very simplified version of wipe_m_list() */
1456 for (i = 1; i < max_r_idx; i++)
1457 r_info[i].cur_num = 0;
1458 C_WIPE(m_list, m_max, monster_type);
1461 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1463 /* Pre-calc cur_num of pets in party_mon[] */
1464 precalc_cur_num_of_pet();
1467 /* Start with a blank cave */
1468 for (y = 0; y < MAX_HGT; y++)
1470 for (x = 0; x < MAX_WID; x++)
1472 cave_type *c_ptr = &cave[y][x];
1499 /* Mega-Hack -- no player yet */
1502 /* Set the base level */
1503 base_level = dun_level;
1505 /* Reset the monster generation level */
1506 monster_level = base_level;
1508 /* Reset the object generation level */
1509 object_level = base_level;
1514 * Generates a random dungeon level -RAK-
1516 * Hack -- regenerate any "overflow" levels
1518 void generate_cave(void)
1522 /* Fill the arrays of floors and walls in the good proportions */
1523 set_floor_and_wall(dungeon_type);
1526 for (num = 0; TRUE; num++)
1532 /* Clear and empty the cave */
1535 /* Build the arena -KMW- */
1536 if (p_ptr->inside_arena)
1542 /* Build the battle -KMW- */
1543 else if (p_ptr->inside_battle)
1549 else if (p_ptr->inside_quest)
1554 /* Build the town */
1555 else if (!dun_level)
1557 /* Make the wilderness */
1558 if (p_ptr->wild_mode) wilderness_gen_small();
1559 else wilderness_gen();
1562 /* Build a real level */
1565 okay = level_gen(&why);
1569 /* Prevent object over-flow */
1570 if (o_max >= max_o_idx)
1574 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1576 why = "too many objects";
1583 /* Prevent monster over-flow */
1584 else if (m_max >= max_m_idx)
1588 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1590 why = "too many monsters";
1603 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1605 if (why) msg_format("Generation restarted (%s)", why);
1609 /* Wipe the objects */
1612 /* Wipe the monsters */
1616 /* Glow deep lava and building entrances */
1617 glow_deep_lava_and_bldg();
1620 p_ptr->enter_dungeon = FALSE;
1622 wipe_generate_cave_flags();