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 (have_flag(f_flags_bold(y + 1, x), FF_WALL)) k++;
132 if (have_flag(f_flags_bold(y - 1, x), FF_WALL)) k++;
133 if (have_flag(f_flags_bold(y, x + 1), FF_WALL)) k++;
134 if (have_flag(f_flags_bold(y, x - 1), FF_WALL)) k++;
141 * Places some staircases near walls
143 static bool alloc_stairs(int feat, int num, int walls)
145 int y, x, i, j, flag;
149 feature_type *f_ptr = &f_info[feat];
151 if (have_flag(f_ptr->flags, FF_LESS))
153 /* No up stairs in town or in ironman mode */
154 if (ironman_downward || !dun_level) return TRUE;
156 if (dun_level > d_info[dungeon_type].mindepth)
157 shaft_num = (randint1(num+1))/2;
159 else if (have_flag(f_ptr->flags, FF_MORE))
161 int q_idx = quest_number(dun_level);
163 /* No downstairs on quest levels */
164 if (dun_level > 1 && q_idx)
166 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
168 /* The quest monster(s) is still alive? */
169 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
173 /* No downstairs at the bottom */
174 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
176 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
177 shaft_num = (randint1(num)+1)/2;
184 /* There very few walls in an arena level */
185 if (dun->empty_level) walls = 1;
187 /* Place "num" stairs */
188 for (i = 0; i < num; i++)
190 /* Try several times */
191 for (flag = FALSE; !flag; )
193 /* Try several times, then decrease "walls" */
194 for (j = 0; j <= 3000; j++)
196 /* Pick a random grid */
197 y = randint1(cur_hgt-2);
198 x = randint1(cur_wid-2);
200 /* Access the grid */
203 /* Require "naked" floor grid */
204 if (!is_floor_grid(c_ptr) || pattern_tile(y,x) || c_ptr->o_idx || c_ptr->m_idx) continue;
206 /* Require a certain number of adjacent walls */
207 if (next_to_walls(y, x) < walls) continue;
209 /* Clear possible garbage of hidden trap */
212 /* Clear previous contents, add stairs */
213 c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat;
220 /* Require fewer walls */
229 * Allocates some objects (using "place" and "type")
231 static void alloc_object(int set, int typ, int num)
237 /* A small level has few objects. */
238 num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
240 /* Place some objects */
241 for (k = 0; k < num; k++)
243 /* Pick a "legal" spot */
244 while (dummy < SAFE_MAX_ATTEMPTS)
251 y = randint0(cur_hgt);
252 x = randint0(cur_wid);
256 /* Require "naked" floor grid */
257 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
259 /* Avoid player location */
260 if (player_bold(y, x)) continue;
262 /* Check for "room" */
263 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
265 /* Require corridor? */
266 if ((set == ALLOC_SET_CORR) && room) continue;
269 if ((set == ALLOC_SET_ROOM) && !room) continue;
275 if (dummy >= SAFE_MAX_ATTEMPTS)
280 msg_print("·Ù¹ð¡ª¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
282 msg_print("Warning! Could not place object!");
290 /* Place something */
293 case ALLOC_TYP_RUBBLE:
296 cave[y][x].info &= ~(CAVE_FLOOR);
303 cave[y][x].info &= ~(CAVE_FLOOR);
313 case ALLOC_TYP_OBJECT:
315 place_object(y, x, 0L);
324 * Count the number of "corridor" grids adjacent to the given grid.
326 * Note -- Assumes "in_bounds(y1, x1)"
328 * XXX XXX This routine currently only counts actual "empty floor"
329 * grids which are not in rooms. We might want to also count stairs,
330 * open doors, closed doors, etc.
332 static int next_to_corr(int y1, int x1)
338 /* Scan adjacent grids */
339 for (i = 0; i < 4; i++)
341 /* Extract the location */
345 /* Access the grid */
348 /* Skip non floors */
349 if (!cave_floor_grid(c_ptr)) continue;
351 /* Skip non "empty floor" grids */
352 if (!is_floor_grid(c_ptr))
355 /* Skip grids inside rooms */
356 if (c_ptr->info & (CAVE_ROOM)) continue;
358 /* Count these grids */
362 /* Return the number of corridors */
368 * Determine if the given location is "between" two walls,
369 * and "next to" two corridor spaces. XXX XXX XXX
371 * Assumes "in_bounds(y, x)"
373 static bool possible_doorway(int y, int x)
375 /* Count the adjacent corridors */
376 if (next_to_corr(y, x) >= 2)
379 if (have_flag(f_flags_bold(y - 1, x), FF_WALL) &&
380 have_flag(f_flags_bold(y + 1, x), FF_WALL))
385 /* Check Horizontal */
386 if (have_flag(f_flags_bold(y, x - 1), FF_WALL) &&
387 have_flag(f_flags_bold(y, x + 1), FF_WALL))
399 * Places door at y, x position if at least 2 walls found
401 static void try_door(int y, int x)
404 if (!in_bounds(y, x)) return;
407 if (!cave_floor_bold(y, x)) return;
409 /* Ignore room grids */
410 if (cave[y][x].info & (CAVE_ROOM)) return;
412 /* Occasional door (if allowed) */
413 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
416 place_random_door(y, x, FALSE);
421 /* Place quest monsters */
422 void place_quest_monsters(void)
426 /* Handle the quest monster placements */
427 for (i = 0; i < max_quests; i++)
433 if (quest[i].status != QUEST_STATUS_TAKEN ||
434 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
435 quest[i].type != QUEST_TYPE_RANDOM) ||
436 quest[i].level != dun_level ||
437 dungeon_type != quest[i].dungeon ||
438 (quest[i].flags & QUEST_FLAG_PRESET))
444 r_ptr = &r_info[quest[i].r_idx];
446 /* Hack -- "unique" monsters must be "unique" */
447 if ((r_ptr->flags1 & RF1_UNIQUE) &&
448 (r_ptr->cur_num >= r_ptr->max_num)) continue;
450 mode = (PM_NO_KAGE | PM_NO_PET);
452 if (!(r_ptr->flags1 & RF1_FRIENDS))
453 mode |= PM_ALLOW_GROUP;
455 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
459 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
464 /* Find an empty grid */
465 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
467 y = randint0(cur_hgt);
468 x = randint0(cur_wid);
470 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
471 if (distance(y, x, py, px) < 10) continue;
475 /* Failed to place */
478 /* Try to place the monster */
479 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
486 /* Failure - Try again */
496 * Set boundary mimic and add "solid" perma-wall
498 static void set_bound_perm_wall(cave_type *c_ptr)
500 if (bound_walls_perm)
502 /* Clear boundary mimic */
507 feature_type *f_ptr = &f_info[c_ptr->feat];
509 /* Hack -- Decline boundary walls with known treasure */
510 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
511 !have_flag(f_ptr->flags, FF_SECRET))
512 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
514 /* Set boundary mimic */
515 c_ptr->mimic = c_ptr->feat;
518 /* Add "solid" perma-wall */
519 place_solid_perm_grid(c_ptr);
524 * Generate various caverns and lakes
526 * There were moved from cave_gen().
528 static void gen_caverns_and_lakes(void)
530 #ifdef ALLOW_CAVERNS_AND_LAKES
531 /* Possible "destroyed" level */
532 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
534 dun->destroyed = TRUE;
536 /* extra rubble around the place looks cool */
537 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
540 /* Make a lake some of the time */
541 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
542 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
545 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
546 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
547 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
548 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
550 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
553 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
557 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
561 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
564 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
568 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
572 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
575 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
578 /* Lake of rubble2 */
579 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
584 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
590 msg_print("¸Ð¤òÀ¸À®¡£");
592 msg_print("Lake on the level.");
595 build_lake(dun->laketype);
599 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
600 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
601 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
605 /* make a large fractal cave in the middle of the dungeon */
609 msg_print("ƶ·¢¤òÀ¸À®¡£");
611 msg_print("Cavern on level.");
616 #endif /* ALLOW_CAVERNS_AND_LAKES */
618 /* Hack -- No destroyed "quest" levels */
619 if (quest_number(dun_level)) dun->destroyed = FALSE;
625 * Generate a new dungeon level
627 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
629 static bool cave_gen(void)
638 dun->destroyed = FALSE;
639 dun->empty_level = FALSE;
643 /* Fill the arrays of floors and walls in the good proportions */
644 set_floor_and_wall(dungeon_type);
646 /* Prepare allocation table */
647 get_mon_num_prep(get_monster_hook(), NULL);
649 /* Randomize the dungeon creation values */
650 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
651 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
652 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
653 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
654 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
656 /* Actual maximum number of rooms on this level */
657 dun->row_rooms = cur_hgt / BLOCK_HGT;
658 dun->col_rooms = cur_wid / BLOCK_WID;
660 /* Initialize the room table */
661 for (y = 0; y < dun->row_rooms; y++)
663 for (x = 0; x < dun->col_rooms; x++)
665 dun->room_map[y][x] = FALSE;
672 /* Empty arena levels */
673 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
675 dun->empty_level = TRUE;
679 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
681 msg_print("Arena level.");
685 if (dun->empty_level)
687 /* Start with floors */
688 for (y = 0; y < cur_hgt; y++)
690 for (x = 0; x < cur_wid; x++)
692 place_floor_bold(y, x);
696 /* Special boundary walls -- Top and bottom */
697 for (x = 0; x < cur_wid; x++)
699 place_extra_bold(0, x);
700 place_extra_bold(cur_hgt - 1, x);
703 /* Special boundary walls -- Left and right */
704 for (y = 1; y < (cur_hgt - 1); y++)
706 place_extra_bold(y, 0);
707 place_extra_bold(y, cur_wid - 1);
712 /* Start with walls */
713 for (y = 0; y < cur_hgt; y++)
715 for (x = 0; x < cur_wid; x++)
717 place_extra_bold(y, x);
723 /* Generate various caverns and lakes */
724 gen_caverns_and_lakes();
728 if (d_info[dungeon_type].flags1 & DF1_MAZE)
730 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
732 /* Place 3 or 4 down stairs near some walls */
733 if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
735 /* Place 1 or 2 up stairs near some walls */
736 if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
739 /* Build some rooms */
743 * Build each type of room in turn until we cannot build any more.
748 /* Make a hole in the dungeon roof sometimes at level 1 */
751 while (one_in_(DUN_MOS_DEN))
753 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
757 /* Destroy the level if necessary */
758 if (dun->destroyed) destroy_level();
760 /* Hack -- Add some rivers */
761 if (one_in_(3) && (randint1(dun_level) > 5))
763 int feat1 = 0, feat2 = 0;
765 /* Choose water or lava */
766 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
768 feat1 = FEAT_DEEP_WATER;
769 feat2 = FEAT_SHAL_WATER;
771 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
773 feat1 = FEAT_DEEP_LAVA;
774 feat2 = FEAT_SHAL_LAVA;
780 feature_type *f_ptr = &f_info[feat1];
782 /* Only add river if matches lake type or if have no lake at all */
783 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
784 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
787 add_river(feat1, feat2);
792 /* Hack -- Scramble the room order */
793 for (i = 0; i < dun->cent_n; i++)
796 int pick = rand_range(0, i);
800 dun->cent[i].y = dun->cent[pick].y;
801 dun->cent[i].x = dun->cent[pick].x;
802 dun->cent[pick].y = ty;
803 dun->cent[pick].x = tx;
806 /* Start with no tunnel doors */
809 /* Hack -- connect the first room to the last room */
810 y = dun->cent[dun->cent_n-1].y;
811 x = dun->cent[dun->cent_n-1].x;
813 /* Connect all the rooms together */
814 for (i = 0; i < dun->cent_n; i++)
818 /* Reset the arrays */
822 /* Connect the room to the previous room */
823 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
825 /* make cave-like tunnel */
826 build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
830 /* make normal tunnel */
831 build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
834 /* Turn the tunnel into corridor */
835 for (j = 0; j < dun->tunn_n; j++)
840 /* Access the grid */
844 /* Access the grid */
846 f_ptr = &f_info[c_ptr->feat];
848 /* Clear previous contents (if not a lake), add a floor */
849 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
851 /* Clear mimic type */
854 place_floor_grid(c_ptr);
858 /* Apply the piercings that we found */
859 for (j = 0; j < dun->wall_n; j++)
863 /* Access the grid */
867 /* Access the grid */
870 /* Clear mimic type */
873 /* Clear previous contents, add up floor */
874 place_floor_grid(c_ptr);
876 /* Occasional doorway */
877 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
879 /* Place a random door */
880 place_random_door(y, x, TRUE);
884 /* Remember the "previous" room */
889 /* Place intersection doors */
890 for (i = 0; i < dun->door_n; i++)
892 /* Extract junction location */
896 /* Try placing doors */
903 /* Place 3 or 4 down stairs near some walls */
904 if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
906 /* Place 1 or 2 up stairs near some walls */
907 if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
912 if (d_info[dungeon_type].stream2)
914 /* Hack -- Add some quartz streamers */
915 for (i = 0; i < DUN_STR_QUA; i++)
917 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
921 if (d_info[dungeon_type].stream1)
923 /* Hack -- Add some magma streamers */
924 for (i = 0; i < DUN_STR_MAG; i++)
926 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
931 /* Special boundary walls -- Top and bottom */
932 for (x = 0; x < cur_wid; x++)
934 set_bound_perm_wall(&cave[0][x]);
935 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
938 /* Special boundary walls -- Left and right */
939 for (y = 1; y < (cur_hgt - 1); y++)
941 set_bound_perm_wall(&cave[y][0]);
942 set_bound_perm_wall(&cave[y][cur_wid - 1]);
945 /* Determine the character location */
946 if (!new_player_spot()) return FALSE;
948 place_quest_monsters();
955 /* Pick a base number of monsters */
956 i = d_info[dungeon_type].min_m_alloc_level;
958 /* To make small levels a bit more playable */
959 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
961 int small_tester = i;
963 i = (i * cur_hgt) / MAX_HGT;
964 i = (i * cur_wid) / MAX_WID;
967 if (i > small_tester) i = small_tester;
971 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
973 msg_format("Reduced monsters base from %d to %d", small_tester, i);
981 /* Put some monsters in the dungeon */
982 for (i = i + k; i > 0; i--)
984 (void)alloc_monster(0, PM_ALLOW_SLEEP);
987 /* Place some traps in the dungeon */
988 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
990 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
991 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
993 /* Mega Hack -- No object at first level of deeper dungeon */
994 if (p_ptr->enter_dungeon && dun_level > 1)
1000 /* Put some objects in rooms */
1001 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1003 /* Put some objects/gold in the dungeon */
1004 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1005 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1007 /* Set back to default */
1008 object_level = base_level;
1010 /* Put the Guardian */
1011 (void)alloc_guardian();
1013 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1016 for (y = 0; y < cur_hgt; y++)
1018 for (x = 0; x < cur_wid; x++)
1020 cave[y][x].info |= (CAVE_GLOW);
1030 * Builds the arena after it is entered -KMW-
1032 static void build_arena(void)
1034 int yval, y_height, y_depth, xval, x_left, x_right;
1037 yval = SCREEN_HGT / 2;
1038 xval = SCREEN_WID / 2;
1039 y_height = yval - 10;
1040 y_depth = yval + 10;
1042 x_right = xval + 32;
1044 for (i = y_height; i <= y_height + 5; i++)
1045 for (j = x_left; j <= x_right; j++)
1047 place_extra_perm_bold(i, j);
1048 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1050 for (i = y_depth; i >= y_depth - 5; i--)
1051 for (j = x_left; j <= x_right; j++)
1053 place_extra_perm_bold(i, j);
1054 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1056 for (j = x_left; j <= x_left + 17; j++)
1057 for (i = y_height; i <= y_depth; i++)
1059 place_extra_perm_bold(i, j);
1060 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1062 for (j = x_right; j >= x_right - 17; j--)
1063 for (i = y_height; i <= y_depth; i++)
1065 place_extra_perm_bold(i, j);
1066 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1069 place_extra_perm_bold(y_height+6, x_left+18);
1070 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1071 place_extra_perm_bold(y_depth-6, x_left+18);
1072 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1073 place_extra_perm_bold(y_height+6, x_right-18);
1074 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1075 place_extra_perm_bold(y_depth-6, x_right-18);
1076 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1080 cave[i][j].feat = FEAT_BLDG_HEAD + 2;
1081 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1087 * Town logic flow for generation of arena -KMW-
1089 static void arena_gen(void)
1096 cur_hgt = SCREEN_HGT;
1097 cur_wid = SCREEN_WID;
1099 /* Start with solid walls */
1100 for (y = 0; y < MAX_HGT; y++)
1102 for (x = 0; x < MAX_WID; x++)
1104 /* Create "solid" perma-wall */
1105 place_solid_perm_bold(y, x);
1107 /* Illuminate and memorize the walls */
1108 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1112 /* Then place some floors */
1113 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1115 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1117 /* Create empty floor */
1118 cave[y][x].feat = FEAT_FLOOR;
1124 place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx,
1125 (PM_NO_KAGE | PM_NO_PET));
1131 * Builds the arena after it is entered -KMW-
1133 static void build_battle(void)
1135 int yval, y_height, y_depth, xval, x_left, x_right;
1138 yval = SCREEN_HGT / 2;
1139 xval = SCREEN_WID / 2;
1140 y_height = yval - 10;
1141 y_depth = yval + 10;
1143 x_right = xval + 32;
1145 for (i = y_height; i <= y_height + 5; i++)
1146 for (j = x_left; j <= x_right; j++)
1148 place_extra_perm_bold(i, j);
1149 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1151 for (i = y_depth; i >= y_depth - 3; i--)
1152 for (j = x_left; j <= x_right; j++)
1154 place_extra_perm_bold(i, j);
1155 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1157 for (j = x_left; j <= x_left + 17; j++)
1158 for (i = y_height; i <= y_depth; i++)
1160 place_extra_perm_bold(i, j);
1161 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1163 for (j = x_right; j >= x_right - 17; j--)
1164 for (i = y_height; i <= y_depth; i++)
1166 place_extra_perm_bold(i, j);
1167 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1170 place_extra_perm_bold(y_height+6, x_left+18);
1171 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1172 place_extra_perm_bold(y_depth-4, x_left+18);
1173 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1174 place_extra_perm_bold(y_height+6, x_right-18);
1175 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1176 place_extra_perm_bold(y_depth-4, x_right-18);
1177 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1181 cave[i][j].feat = FEAT_BLDG_HEAD + 3;
1182 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1188 * Town logic flow for generation of arena -KMW-
1190 static void battle_gen(void)
1196 /* Start with solid walls */
1197 for (y = 0; y < MAX_HGT; y++)
1199 for (x = 0; x < MAX_WID; x++)
1201 /* Create "solid" perma-wall */
1202 place_solid_perm_bold(y, x);
1204 /* Illuminate and memorize the walls */
1205 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1209 /* Then place some floors */
1210 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1212 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1214 /* Create empty floor */
1215 cave[y][x].feat = FEAT_FLOOR;
1223 place_monster_aux(0, py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1224 (PM_NO_KAGE | PM_NO_PET));
1225 set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
1227 for(i = 1; i < m_max; i++)
1229 monster_type *m_ptr = &m_list[i];
1231 if (!m_ptr->r_idx) continue;
1233 /* Hack -- Detect monster */
1234 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1236 /* Update the monster */
1237 update_mon(i, FALSE);
1243 * Generate a quest level
1245 static void quest_gen(void)
1250 /* Start with perm walls */
1251 for (y = 0; y < cur_hgt; y++)
1253 for (x = 0; x < cur_wid; x++)
1255 place_solid_perm_bold(y, x);
1259 /* Set the quest level */
1260 base_level = quest[p_ptr->inside_quest].level;
1261 dun_level = base_level;
1262 object_level = base_level;
1263 monster_level = base_level;
1265 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1267 /* Prepare allocation table */
1268 get_mon_num_prep(get_monster_hook(), NULL);
1270 init_flags = INIT_CREATE_DUNGEON | INIT_ASSIGN;
1272 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1275 /* Make a real level */
1276 static bool level_gen(cptr *why)
1278 int level_height, level_width;
1280 if ((always_small_levels || ironman_small_levels ||
1281 (one_in_(SMALL_LEVEL) && small_levels) ||
1282 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1283 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1284 !(d_info[dungeon_type].flags1 & DF1_BIG))
1288 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1290 msg_print("A 'small' dungeon level.");
1294 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1299 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1308 level_height = randint1(MAX_HGT/SCREEN_HGT);
1309 level_width = randint1(MAX_WID/SCREEN_WID);
1311 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1312 (level_width == MAX_WID/SCREEN_WID));
1315 cur_hgt = level_height * SCREEN_HGT;
1316 cur_wid = level_width * SCREEN_WID;
1318 /* Assume illegal panel */
1319 panel_row_min = cur_hgt;
1320 panel_col_min = cur_wid;
1323 msg_format("X:%d, Y:%d.", cur_hgt, cur_wid);
1331 /* Assume illegal panel */
1332 panel_row_min = cur_hgt;
1333 panel_col_min = cur_wid;
1336 /* Make a dungeon */
1340 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1342 *why = "could not place player";
1350 static byte extract_feeling(void)
1352 /* Hack -- no feeling in the town */
1353 if (!dun_level) return 0;
1355 /* Hack -- Have a special feeling sometimes */
1356 if (good_item_flag && !preserve_mode) return 1;
1358 if (rating > 100) return 2;
1359 if (rating > 80) return 3;
1360 if (rating > 60) return 4;
1361 if (rating > 40) return 5;
1362 if (rating > 30) return 6;
1363 if (rating > 20) return 7;
1364 if (rating > 10) return 8;
1365 if (rating > 0) return 9;
1367 if((turn - old_turn) > TURNS_PER_TICK * TOWN_DAWN /2)
1368 chg_virtue(V_PATIENCE, 1);
1375 * Wipe all unnecessary flags after cave generation
1377 static void wipe_generate_cave_flags(void)
1381 for (y = 0; y < cur_hgt; y++)
1383 for (x = 0; x < cur_wid; x++)
1385 /* Wipe unused flags */
1386 cave[y][x].info &= ~(CAVE_MASK);
1392 for (y = 1; y < cur_hgt - 1; y++)
1394 for (x = 1; x < cur_wid - 1; x++)
1396 /* There might be trap */
1397 cave[y][x].info |= CAVE_UNSAFE;
1405 * Clear and empty the cave
1407 void clear_cave(void)
1411 /* Very simplified version of wipe_o_list() */
1412 C_WIPE(o_list, o_max, object_type);
1416 /* Very simplified version of wipe_m_list() */
1417 for (i = 1; i < max_r_idx; i++)
1418 r_info[i].cur_num = 0;
1419 C_WIPE(m_list, m_max, monster_type);
1423 /* Pre-calc cur_num of pets in party_mon[] */
1424 precalc_cur_num_of_pet();
1427 /* Start with a blank cave */
1428 for (y = 0; y < MAX_HGT; y++)
1430 for (x = 0; x < MAX_WID; x++)
1432 cave_type *c_ptr = &cave[y][x];
1459 /* Mega-Hack -- no player yet */
1462 /* Set the base level */
1463 base_level = dun_level;
1465 /* Reset the monster generation level */
1466 monster_level = base_level;
1468 /* Reset the object generation level */
1469 object_level = base_level;
1471 /* Nothing special here yet */
1472 good_item_flag = FALSE;
1474 /* Nothing good here yet */
1480 * Generates a random dungeon level -RAK-
1482 * Hack -- regenerate any "overflow" levels
1484 * Hack -- allow auto-scumming via a gameplay option.
1486 void generate_cave(void)
1490 /* Fill the arrays of floors and walls in the good proportions */
1491 set_floor_and_wall(dungeon_type);
1494 for (num = 0; TRUE; num++)
1500 /* Clear and empty the cave */
1503 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
1505 if (have_flag(f_info[d_info[dungeon_type].fill[i].feat].flags, FF_HAS_GOLD))
1512 /* Build the arena -KMW- */
1513 if (p_ptr->inside_arena)
1519 /* Build the battle -KMW- */
1520 else if (p_ptr->inside_battle)
1526 else if (p_ptr->inside_quest)
1531 /* Build the town */
1532 else if (!dun_level)
1534 /* Make the wilderness */
1535 if (p_ptr->wild_mode) wilderness_gen_small();
1536 else wilderness_gen();
1539 /* Build a real level */
1542 okay = level_gen(&why);
1545 /* Extract the feeling */
1546 feeling = extract_feeling();
1548 /* Prevent object over-flow */
1549 if (o_max >= max_o_idx)
1553 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1555 why = "too many objects";
1562 /* Prevent monster over-flow */
1563 else if (m_max >= max_m_idx)
1567 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1569 why = "too many monsters";
1582 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1584 if (why) msg_format("Generation restarted (%s)", why);
1588 /* Wipe the objects */
1591 /* Wipe the monsters */
1595 /* Glow deep lava and building entrances */
1596 glow_deep_lava_and_bldg();
1599 p_ptr->enter_dungeon = FALSE;
1601 wipe_generate_cave_flags();