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_down_stair, rand_range(2, 3), 3)) return FALSE;
798 /* Place 1 or 2 up stairs near some walls */
799 if (!alloc_stairs(feat_up_stair, 1, 3)) return FALSE;
802 /* Build some rooms */
805 int tunnel_fail_count = 0;
808 * Build each type of room in turn until we cannot build any more.
810 if (!generate_rooms()) return FALSE;
813 /* Make a hole in the dungeon roof sometimes at level 1 */
816 while (one_in_(DUN_MOS_DEN))
818 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
822 /* Destroy the level if necessary */
823 if (dun->destroyed) destroy_level();
825 /* Hack -- Add some rivers */
826 if (one_in_(3) && (randint1(dun_level) > 5))
828 int feat1 = 0, feat2 = 0;
830 /* Choose water or lava */
831 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
833 feat1 = feat_deep_water;
834 feat2 = feat_shallow_water;
836 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
838 feat1 = feat_deep_lava;
839 feat2 = feat_shallow_lava;
845 feature_type *f_ptr = &f_info[feat1];
847 /* Only add river if matches lake type or if have no lake at all */
848 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
849 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
852 add_river(feat1, feat2);
857 /* Hack -- Scramble the room order */
858 for (i = 0; i < dun->cent_n; i++)
861 int pick = rand_range(0, i);
865 dun->cent[i].y = dun->cent[pick].y;
866 dun->cent[i].x = dun->cent[pick].x;
867 dun->cent[pick].y = ty;
868 dun->cent[pick].x = tx;
871 /* Start with no tunnel doors */
874 /* Hack -- connect the first room to the last room */
875 y = dun->cent[dun->cent_n-1].y;
876 x = dun->cent[dun->cent_n-1].x;
878 /* Connect all the rooms together */
879 for (i = 0; i < dun->cent_n; i++)
883 /* Reset the arrays */
887 /* Connect the room to the previous room */
888 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
890 /* make cave-like tunnel */
891 (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
895 /* make normal tunnel */
896 if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
899 if (tunnel_fail_count >= 2) return FALSE;
901 /* Turn the tunnel into corridor */
902 for (j = 0; j < dun->tunn_n; j++)
907 /* Access the grid */
911 /* Access the grid */
913 f_ptr = &f_info[c_ptr->feat];
915 /* Clear previous contents (if not a lake), add a floor */
916 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
918 /* Clear mimic type */
921 place_floor_grid(c_ptr);
925 /* Apply the piercings that we found */
926 for (j = 0; j < dun->wall_n; j++)
930 /* Access the grid */
934 /* Access the grid */
937 /* Clear mimic type */
940 /* Clear previous contents, add up floor */
941 place_floor_grid(c_ptr);
943 /* Occasional doorway */
944 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
946 /* Place a random door */
947 place_random_door(y, x, TRUE);
951 /* Remember the "previous" room */
956 /* Place intersection doors */
957 for (i = 0; i < dun->door_n; i++)
959 /* Extract junction location */
963 /* Try placing doors */
970 /* Place 3 or 4 down stairs near some walls */
971 if (!alloc_stairs(feat_down_stair, rand_range(3, 4), 3)) return FALSE;
973 /* Place 1 or 2 up stairs near some walls */
974 if (!alloc_stairs(feat_up_stair, rand_range(1, 2), 3)) return FALSE;
979 if (d_info[dungeon_type].stream2)
981 /* Hack -- Add some quartz streamers */
982 for (i = 0; i < DUN_STR_QUA; i++)
984 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
988 if (d_info[dungeon_type].stream1)
990 /* Hack -- Add some magma streamers */
991 for (i = 0; i < DUN_STR_MAG; i++)
993 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
998 /* Special boundary walls -- Top and bottom */
999 for (x = 0; x < cur_wid; x++)
1001 set_bound_perm_wall(&cave[0][x]);
1002 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
1005 /* Special boundary walls -- Left and right */
1006 for (y = 1; y < (cur_hgt - 1); y++)
1008 set_bound_perm_wall(&cave[y][0]);
1009 set_bound_perm_wall(&cave[y][cur_wid - 1]);
1012 /* Determine the character location */
1013 if (!new_player_spot()) return FALSE;
1015 if (!place_quest_monsters()) return FALSE;
1017 /* Basic "amount" */
1018 k = (dun_level / 3);
1022 /* Pick a base number of monsters */
1023 i = d_info[dungeon_type].min_m_alloc_level;
1025 /* To make small levels a bit more playable */
1026 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1028 int small_tester = i;
1030 i = (i * cur_hgt) / MAX_HGT;
1031 i = (i * cur_wid) / MAX_WID;
1034 if (i > small_tester) i = small_tester;
1035 else if (cheat_hear)
1038 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
1040 msg_format("Reduced monsters base from %d to %d", small_tester, i);
1048 /* Put some monsters in the dungeon */
1049 for (i = i + k; i > 0; i--)
1051 (void)alloc_monster(0, PM_ALLOW_SLEEP);
1054 /* Place some traps in the dungeon */
1055 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
1057 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
1058 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
1060 /* Mega Hack -- No object at first level of deeper dungeon */
1061 if (p_ptr->enter_dungeon && dun_level > 1)
1063 /* No stair scum! */
1067 /* Put some objects in rooms */
1068 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1070 /* Put some objects/gold in the dungeon */
1071 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1072 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1074 /* Set back to default */
1075 object_level = base_level;
1077 /* Put the Guardian */
1078 if (!alloc_guardian(TRUE)) return FALSE;
1080 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1083 for (y = 0; y < cur_hgt; y++)
1085 for (x = 0; x < cur_wid; x++)
1087 cave[y][x].info |= (CAVE_GLOW);
1097 * Builds the arena after it is entered -KMW-
1099 static void build_arena(void)
1101 int yval, y_height, y_depth, xval, x_left, x_right;
1104 yval = SCREEN_HGT / 2;
1105 xval = SCREEN_WID / 2;
1106 y_height = yval - 10;
1107 y_depth = yval + 10;
1109 x_right = xval + 32;
1111 for (i = y_height; i <= y_height + 5; i++)
1112 for (j = x_left; j <= x_right; j++)
1114 place_extra_perm_bold(i, j);
1115 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1117 for (i = y_depth; i >= y_depth - 5; i--)
1118 for (j = x_left; j <= x_right; j++)
1120 place_extra_perm_bold(i, j);
1121 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1123 for (j = x_left; j <= x_left + 17; j++)
1124 for (i = y_height; i <= y_depth; i++)
1126 place_extra_perm_bold(i, j);
1127 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1129 for (j = x_right; j >= x_right - 17; j--)
1130 for (i = y_height; i <= y_depth; i++)
1132 place_extra_perm_bold(i, j);
1133 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1136 place_extra_perm_bold(y_height+6, x_left+18);
1137 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1138 place_extra_perm_bold(y_depth-6, x_left+18);
1139 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1140 place_extra_perm_bold(y_height+6, x_right-18);
1141 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1142 place_extra_perm_bold(y_depth-6, x_right-18);
1143 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1147 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1148 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1154 * Town logic flow for generation of arena -KMW-
1156 static void arena_gen(void)
1163 cur_hgt = SCREEN_HGT;
1164 cur_wid = SCREEN_WID;
1166 /* Start with solid walls */
1167 for (y = 0; y < MAX_HGT; y++)
1169 for (x = 0; x < MAX_WID; x++)
1171 /* Create "solid" perma-wall */
1172 place_solid_perm_bold(y, x);
1174 /* Illuminate and memorize the walls */
1175 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1179 /* Then place some floors */
1180 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1182 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1184 /* Create empty floor */
1185 cave[y][x].feat = feat_floor;
1191 if(!place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx, (PM_NO_KAGE | PM_NO_PET)))
1193 p_ptr->exit_bldg = TRUE;
1194 p_ptr->arena_number++;
1196 msg_print("Áê¼ê¤Ï·ç¾ì¤·¤¿¡£¤¢¤Ê¤¿¤ÎÉÔÀᄀ¤À¡£");
1198 msg_print("The enemy is unable appear. You won by default.");
1207 * Builds the arena after it is entered -KMW-
1209 static void build_battle(void)
1211 int yval, y_height, y_depth, xval, x_left, x_right;
1214 yval = SCREEN_HGT / 2;
1215 xval = SCREEN_WID / 2;
1216 y_height = yval - 10;
1217 y_depth = yval + 10;
1219 x_right = xval + 32;
1221 for (i = y_height; i <= y_height + 5; i++)
1222 for (j = x_left; j <= x_right; j++)
1224 place_extra_perm_bold(i, j);
1225 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1227 for (i = y_depth; i >= y_depth - 3; i--)
1228 for (j = x_left; j <= x_right; j++)
1230 place_extra_perm_bold(i, j);
1231 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1233 for (j = x_left; j <= x_left + 17; j++)
1234 for (i = y_height; i <= y_depth; i++)
1236 place_extra_perm_bold(i, j);
1237 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1239 for (j = x_right; j >= x_right - 17; j--)
1240 for (i = y_height; i <= y_depth; i++)
1242 place_extra_perm_bold(i, j);
1243 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1246 place_extra_perm_bold(y_height+6, x_left+18);
1247 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1248 place_extra_perm_bold(y_depth-4, x_left+18);
1249 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1250 place_extra_perm_bold(y_height+6, x_right-18);
1251 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1252 place_extra_perm_bold(y_depth-4, x_right-18);
1253 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1255 for (i = y_height + 1; i <= y_height + 5; i++)
1256 for (j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++)
1258 cave[i][j].feat = feat_permanent_glass_wall;
1263 cave[i][j].feat = f_tag_to_index("BUILDING_3");
1264 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1270 * Town logic flow for generation of arena -KMW-
1272 static void battle_gen(void)
1278 /* Start with solid walls */
1279 for (y = 0; y < MAX_HGT; y++)
1281 for (x = 0; x < MAX_WID; x++)
1283 /* Create "solid" perma-wall */
1284 place_solid_perm_bold(y, x);
1286 /* Illuminate and memorize the walls */
1287 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1291 /* Then place some floors */
1292 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1294 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1296 /* Create empty floor */
1297 cave[y][x].feat = feat_floor;
1305 place_monster_aux(0, py + 8 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1306 (PM_NO_KAGE | PM_NO_PET));
1307 set_friendly(&m_list[cave[py+8+(i/2)*4][px-2+(i%2)*4].m_idx]);
1309 for(i = 1; i < m_max; i++)
1311 monster_type *m_ptr = &m_list[i];
1313 if (!m_ptr->r_idx) continue;
1315 /* Hack -- Detect monster */
1316 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1318 /* Update the monster */
1319 update_mon(i, FALSE);
1325 * Generate a quest level
1327 static void quest_gen(void)
1332 /* Start with perm walls */
1333 for (y = 0; y < cur_hgt; y++)
1335 for (x = 0; x < cur_wid; x++)
1337 place_solid_perm_bold(y, x);
1341 /* Set the quest level */
1342 base_level = quest[p_ptr->inside_quest].level;
1343 dun_level = base_level;
1344 object_level = base_level;
1345 monster_level = base_level;
1347 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1349 /* Prepare allocation table */
1350 get_mon_num_prep(get_monster_hook(), NULL);
1352 init_flags = INIT_CREATE_DUNGEON;
1354 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1357 /* Make a real level */
1358 static bool level_gen(cptr *why)
1360 int level_height, level_width;
1362 if ((always_small_levels || ironman_small_levels ||
1363 (one_in_(SMALL_LEVEL) && small_levels) ||
1364 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1365 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1366 !(d_info[dungeon_type].flags1 & DF1_BIG))
1370 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1372 msg_print("A 'small' dungeon level.");
1375 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1380 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1389 level_height = randint1(MAX_HGT/SCREEN_HGT);
1390 level_width = randint1(MAX_WID/SCREEN_WID);
1392 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1393 (level_width == MAX_WID/SCREEN_WID));
1396 cur_hgt = level_height * SCREEN_HGT;
1397 cur_wid = level_width * SCREEN_WID;
1399 /* Assume illegal panel */
1400 panel_row_min = cur_hgt;
1401 panel_col_min = cur_wid;
1404 msg_format("X:%d, Y:%d.", cur_wid, cur_hgt);
1412 /* Assume illegal panel */
1413 panel_row_min = cur_hgt;
1414 panel_col_min = cur_wid;
1417 /* Make a dungeon */
1421 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1423 *why = "could not place player";
1433 * Wipe all unnecessary flags after cave generation
1435 void wipe_generate_cave_flags(void)
1439 for (y = 0; y < cur_hgt; y++)
1441 for (x = 0; x < cur_wid; x++)
1443 /* Wipe unused flags */
1444 cave[y][x].info &= ~(CAVE_MASK);
1450 for (y = 1; y < cur_hgt - 1; y++)
1452 for (x = 1; x < cur_wid - 1; x++)
1454 /* There might be trap */
1455 cave[y][x].info |= CAVE_UNSAFE;
1463 * Clear and empty the cave
1465 void clear_cave(void)
1469 /* Very simplified version of wipe_o_list() */
1470 (void)C_WIPE(o_list, o_max, object_type);
1474 /* Very simplified version of wipe_m_list() */
1475 for (i = 1; i < max_r_idx; i++)
1476 r_info[i].cur_num = 0;
1477 (void)C_WIPE(m_list, m_max, monster_type);
1480 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1482 /* Pre-calc cur_num of pets in party_mon[] */
1483 precalc_cur_num_of_pet();
1486 /* Start with a blank cave */
1487 for (y = 0; y < MAX_HGT; y++)
1489 for (x = 0; x < MAX_WID; x++)
1491 cave_type *c_ptr = &cave[y][x];
1518 /* Mega-Hack -- no player yet */
1521 /* Set the base level */
1522 base_level = dun_level;
1524 /* Reset the monster generation level */
1525 monster_level = base_level;
1527 /* Reset the object generation level */
1528 object_level = base_level;
1533 * Generates a random dungeon level -RAK-
1535 * Hack -- regenerate any "overflow" levels
1537 void generate_cave(void)
1541 /* Fill the arrays of floors and walls in the good proportions */
1542 set_floor_and_wall(dungeon_type);
1545 for (num = 0; TRUE; num++)
1551 /* Clear and empty the cave */
1554 /* Build the arena -KMW- */
1555 if (p_ptr->inside_arena)
1561 /* Build the battle -KMW- */
1562 else if (p_ptr->inside_battle)
1568 else if (p_ptr->inside_quest)
1573 /* Build the town */
1574 else if (!dun_level)
1576 /* Make the wilderness */
1577 if (p_ptr->wild_mode) wilderness_gen_small();
1578 else wilderness_gen();
1581 /* Build a real level */
1584 okay = level_gen(&why);
1588 /* Prevent object over-flow */
1589 if (o_max >= max_o_idx)
1593 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1595 why = "too many objects";
1602 /* Prevent monster over-flow */
1603 else if (m_max >= max_m_idx)
1607 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1609 why = "too many monsters";
1622 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1624 if (why) msg_format("Generation restarted (%s)", why);
1628 /* Wipe the objects */
1631 /* Wipe the monsters */
1635 /* Glow deep lava and building entrances */
1636 glow_deep_lava_and_bldg();
1639 p_ptr->enter_dungeon = FALSE;
1641 wipe_generate_cave_flags();