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 void 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--)
517 y = randint0(cur_hgt);
518 x = randint0(cur_wid);
520 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
521 if (distance(y, x, py, px) < 10) continue;
525 /* Failed to place */
528 /* Try to place the monster */
529 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
536 /* Failure - Try again */
546 * Set boundary mimic and add "solid" perma-wall
548 static void set_bound_perm_wall(cave_type *c_ptr)
550 if (bound_walls_perm)
552 /* Clear boundary mimic */
557 feature_type *f_ptr = &f_info[c_ptr->feat];
559 /* Hack -- Decline boundary walls with known treasure */
560 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
561 !have_flag(f_ptr->flags, FF_SECRET))
562 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
564 /* Set boundary mimic */
565 c_ptr->mimic = c_ptr->feat;
568 /* Add "solid" perma-wall */
569 place_solid_perm_grid(c_ptr);
574 * Generate various caverns and lakes
576 * There were moved from cave_gen().
578 static void gen_caverns_and_lakes(void)
580 #ifdef ALLOW_CAVERNS_AND_LAKES
581 /* Possible "destroyed" level */
582 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
584 dun->destroyed = TRUE;
586 /* extra rubble around the place looks cool */
587 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
590 /* Make a lake some of the time */
591 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
592 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
595 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
596 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
597 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
598 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
600 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
603 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
607 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
611 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
614 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
618 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
622 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
625 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
628 /* Lake of rubble2 */
629 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
634 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
640 msg_print("¸Ð¤òÀ¸À®¡£");
642 msg_print("Lake on the level.");
645 build_lake(dun->laketype);
649 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
650 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
651 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
655 /* make a large fractal cave in the middle of the dungeon */
659 msg_print("ƶ·¢¤òÀ¸À®¡£");
661 msg_print("Cavern on level.");
666 #endif /* ALLOW_CAVERNS_AND_LAKES */
668 /* Hack -- No destroyed "quest" levels */
669 if (quest_number(dun_level)) dun->destroyed = FALSE;
675 * Generate a new dungeon level
677 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
679 static bool cave_gen(void)
688 dun->destroyed = FALSE;
689 dun->empty_level = FALSE;
693 /* Fill the arrays of floors and walls in the good proportions */
694 set_floor_and_wall(dungeon_type);
696 /* Prepare allocation table */
697 get_mon_num_prep(get_monster_hook(), NULL);
699 /* Randomize the dungeon creation values */
700 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
701 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
702 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
703 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
704 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
706 /* Actual maximum number of rooms on this level */
707 dun->row_rooms = cur_hgt / BLOCK_HGT;
708 dun->col_rooms = cur_wid / BLOCK_WID;
710 /* Initialize the room table */
711 for (y = 0; y < dun->row_rooms; y++)
713 for (x = 0; x < dun->col_rooms; x++)
715 dun->room_map[y][x] = FALSE;
722 /* Empty arena levels */
723 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
725 dun->empty_level = TRUE;
729 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
731 msg_print("Arena level.");
735 if (dun->empty_level)
737 /* Start with floors */
738 for (y = 0; y < cur_hgt; y++)
740 for (x = 0; x < cur_wid; x++)
742 place_floor_bold(y, x);
746 /* Special boundary walls -- Top and bottom */
747 for (x = 0; x < cur_wid; x++)
749 place_extra_bold(0, x);
750 place_extra_bold(cur_hgt - 1, x);
753 /* Special boundary walls -- Left and right */
754 for (y = 1; y < (cur_hgt - 1); y++)
756 place_extra_bold(y, 0);
757 place_extra_bold(y, cur_wid - 1);
762 /* Start with walls */
763 for (y = 0; y < cur_hgt; y++)
765 for (x = 0; x < cur_wid; x++)
767 place_extra_bold(y, x);
773 /* Generate various caverns and lakes */
774 gen_caverns_and_lakes();
778 if (d_info[dungeon_type].flags1 & DF1_MAZE)
780 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
782 /* Place 3 or 4 down stairs near some walls */
783 if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
785 /* Place 1 or 2 up stairs near some walls */
786 if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
789 /* Build some rooms */
793 * Build each type of room in turn until we cannot build any more.
795 if (!generate_rooms()) return FALSE;
798 /* Make a hole in the dungeon roof sometimes at level 1 */
801 while (one_in_(DUN_MOS_DEN))
803 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
807 /* Destroy the level if necessary */
808 if (dun->destroyed) destroy_level();
810 /* Hack -- Add some rivers */
811 if (one_in_(3) && (randint1(dun_level) > 5))
813 int feat1 = 0, feat2 = 0;
815 /* Choose water or lava */
816 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
818 feat1 = FEAT_DEEP_WATER;
819 feat2 = FEAT_SHAL_WATER;
821 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
823 feat1 = FEAT_DEEP_LAVA;
824 feat2 = FEAT_SHAL_LAVA;
830 feature_type *f_ptr = &f_info[feat1];
832 /* Only add river if matches lake type or if have no lake at all */
833 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
834 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
837 add_river(feat1, feat2);
842 /* Hack -- Scramble the room order */
843 for (i = 0; i < dun->cent_n; i++)
846 int pick = rand_range(0, i);
850 dun->cent[i].y = dun->cent[pick].y;
851 dun->cent[i].x = dun->cent[pick].x;
852 dun->cent[pick].y = ty;
853 dun->cent[pick].x = tx;
856 /* Start with no tunnel doors */
859 /* Hack -- connect the first room to the last room */
860 y = dun->cent[dun->cent_n-1].y;
861 x = dun->cent[dun->cent_n-1].x;
863 /* Connect all the rooms together */
864 for (i = 0; i < dun->cent_n; i++)
868 /* Reset the arrays */
872 /* Connect the room to the previous room */
873 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
875 /* make cave-like tunnel */
876 build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
880 /* make normal tunnel */
881 build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
884 /* Turn the tunnel into corridor */
885 for (j = 0; j < dun->tunn_n; j++)
890 /* Access the grid */
894 /* Access the grid */
896 f_ptr = &f_info[c_ptr->feat];
898 /* Clear previous contents (if not a lake), add a floor */
899 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
901 /* Clear mimic type */
904 place_floor_grid(c_ptr);
908 /* Apply the piercings that we found */
909 for (j = 0; j < dun->wall_n; j++)
913 /* Access the grid */
917 /* Access the grid */
920 /* Clear mimic type */
923 /* Clear previous contents, add up floor */
924 place_floor_grid(c_ptr);
926 /* Occasional doorway */
927 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
929 /* Place a random door */
930 place_random_door(y, x, TRUE);
934 /* Remember the "previous" room */
939 /* Place intersection doors */
940 for (i = 0; i < dun->door_n; i++)
942 /* Extract junction location */
946 /* Try placing doors */
953 /* Place 3 or 4 down stairs near some walls */
954 if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
956 /* Place 1 or 2 up stairs near some walls */
957 if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
962 if (d_info[dungeon_type].stream2)
964 /* Hack -- Add some quartz streamers */
965 for (i = 0; i < DUN_STR_QUA; i++)
967 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
971 if (d_info[dungeon_type].stream1)
973 /* Hack -- Add some magma streamers */
974 for (i = 0; i < DUN_STR_MAG; i++)
976 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
981 /* Special boundary walls -- Top and bottom */
982 for (x = 0; x < cur_wid; x++)
984 set_bound_perm_wall(&cave[0][x]);
985 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
988 /* Special boundary walls -- Left and right */
989 for (y = 1; y < (cur_hgt - 1); y++)
991 set_bound_perm_wall(&cave[y][0]);
992 set_bound_perm_wall(&cave[y][cur_wid - 1]);
995 /* Determine the character location */
996 if (!new_player_spot()) return FALSE;
998 place_quest_monsters();
1000 /* Basic "amount" */
1001 k = (dun_level / 3);
1005 /* Pick a base number of monsters */
1006 i = d_info[dungeon_type].min_m_alloc_level;
1008 /* To make small levels a bit more playable */
1009 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1011 int small_tester = i;
1013 i = (i * cur_hgt) / MAX_HGT;
1014 i = (i * cur_wid) / MAX_WID;
1017 if (i > small_tester) i = small_tester;
1018 else if (cheat_hear)
1021 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
1023 msg_format("Reduced monsters base from %d to %d", small_tester, i);
1031 /* Put some monsters in the dungeon */
1032 for (i = i + k; i > 0; i--)
1034 (void)alloc_monster(0, PM_ALLOW_SLEEP);
1037 /* Place some traps in the dungeon */
1038 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
1040 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
1041 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
1043 /* Mega Hack -- No object at first level of deeper dungeon */
1044 if (p_ptr->enter_dungeon && dun_level > 1)
1046 /* No stair scum! */
1050 /* Put some objects in rooms */
1051 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1053 /* Put some objects/gold in the dungeon */
1054 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1055 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1057 /* Set back to default */
1058 object_level = base_level;
1060 /* Put the Guardian */
1061 (void)alloc_guardian();
1063 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1066 for (y = 0; y < cur_hgt; y++)
1068 for (x = 0; x < cur_wid; x++)
1070 cave[y][x].info |= (CAVE_GLOW);
1080 * Builds the arena after it is entered -KMW-
1082 static void build_arena(void)
1084 int yval, y_height, y_depth, xval, x_left, x_right;
1087 yval = SCREEN_HGT / 2;
1088 xval = SCREEN_WID / 2;
1089 y_height = yval - 10;
1090 y_depth = yval + 10;
1092 x_right = xval + 32;
1094 for (i = y_height; i <= y_height + 5; i++)
1095 for (j = x_left; j <= x_right; j++)
1097 place_extra_perm_bold(i, j);
1098 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1100 for (i = y_depth; i >= y_depth - 5; i--)
1101 for (j = x_left; j <= x_right; j++)
1103 place_extra_perm_bold(i, j);
1104 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1106 for (j = x_left; j <= x_left + 17; j++)
1107 for (i = y_height; i <= y_depth; i++)
1109 place_extra_perm_bold(i, j);
1110 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1112 for (j = x_right; j >= x_right - 17; j--)
1113 for (i = y_height; i <= y_depth; i++)
1115 place_extra_perm_bold(i, j);
1116 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1119 place_extra_perm_bold(y_height+6, x_left+18);
1120 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1121 place_extra_perm_bold(y_depth-6, x_left+18);
1122 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1123 place_extra_perm_bold(y_height+6, x_right-18);
1124 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1125 place_extra_perm_bold(y_depth-6, x_right-18);
1126 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1130 cave[i][j].feat = f_tag_to_index("ARENA_GATE");
1131 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1137 * Town logic flow for generation of arena -KMW-
1139 static void arena_gen(void)
1146 cur_hgt = SCREEN_HGT;
1147 cur_wid = SCREEN_WID;
1149 /* Start with solid walls */
1150 for (y = 0; y < MAX_HGT; y++)
1152 for (x = 0; x < MAX_WID; x++)
1154 /* Create "solid" perma-wall */
1155 place_solid_perm_bold(y, x);
1157 /* Illuminate and memorize the walls */
1158 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1162 /* Then place some floors */
1163 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1165 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1167 /* Create empty floor */
1168 cave[y][x].feat = FEAT_FLOOR;
1174 place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx,
1175 (PM_NO_KAGE | PM_NO_PET));
1181 * Builds the arena after it is entered -KMW-
1183 static void build_battle(void)
1185 int yval, y_height, y_depth, xval, x_left, x_right;
1188 yval = SCREEN_HGT / 2;
1189 xval = SCREEN_WID / 2;
1190 y_height = yval - 10;
1191 y_depth = yval + 10;
1193 x_right = xval + 32;
1195 for (i = y_height; i <= y_height + 5; i++)
1196 for (j = x_left; j <= x_right; j++)
1198 place_extra_perm_bold(i, j);
1199 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1201 for (i = y_depth; i >= y_depth - 3; i--)
1202 for (j = x_left; j <= x_right; j++)
1204 place_extra_perm_bold(i, j);
1205 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1207 for (j = x_left; j <= x_left + 17; j++)
1208 for (i = y_height; i <= y_depth; i++)
1210 place_extra_perm_bold(i, j);
1211 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1213 for (j = x_right; j >= x_right - 17; j--)
1214 for (i = y_height; i <= y_depth; i++)
1216 place_extra_perm_bold(i, j);
1217 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1220 place_extra_perm_bold(y_height+6, x_left+18);
1221 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1222 place_extra_perm_bold(y_depth-4, x_left+18);
1223 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1224 place_extra_perm_bold(y_height+6, x_right-18);
1225 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1226 place_extra_perm_bold(y_depth-4, x_right-18);
1227 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1231 cave[i][j].feat = FEAT_BLDG_HEAD + 3;
1232 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1238 * Town logic flow for generation of arena -KMW-
1240 static void battle_gen(void)
1246 /* Start with solid walls */
1247 for (y = 0; y < MAX_HGT; y++)
1249 for (x = 0; x < MAX_WID; x++)
1251 /* Create "solid" perma-wall */
1252 place_solid_perm_bold(y, x);
1254 /* Illuminate and memorize the walls */
1255 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1259 /* Then place some floors */
1260 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1262 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1264 /* Create empty floor */
1265 cave[y][x].feat = FEAT_FLOOR;
1273 place_monster_aux(0, py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1274 (PM_NO_KAGE | PM_NO_PET));
1275 set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
1277 for(i = 1; i < m_max; i++)
1279 monster_type *m_ptr = &m_list[i];
1281 if (!m_ptr->r_idx) continue;
1283 /* Hack -- Detect monster */
1284 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1286 /* Update the monster */
1287 update_mon(i, FALSE);
1293 * Generate a quest level
1295 static void quest_gen(void)
1300 /* Start with perm walls */
1301 for (y = 0; y < cur_hgt; y++)
1303 for (x = 0; x < cur_wid; x++)
1305 place_solid_perm_bold(y, x);
1309 /* Set the quest level */
1310 base_level = quest[p_ptr->inside_quest].level;
1311 dun_level = base_level;
1312 object_level = base_level;
1313 monster_level = base_level;
1315 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1317 /* Prepare allocation table */
1318 get_mon_num_prep(get_monster_hook(), NULL);
1320 init_flags = INIT_CREATE_DUNGEON | INIT_ASSIGN;
1322 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1325 /* Make a real level */
1326 static bool level_gen(cptr *why)
1328 int level_height, level_width;
1330 if ((always_small_levels || ironman_small_levels ||
1331 (one_in_(SMALL_LEVEL) && small_levels) ||
1332 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1333 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1334 !(d_info[dungeon_type].flags1 & DF1_BIG))
1338 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1340 msg_print("A 'small' dungeon level.");
1343 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1348 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1357 level_height = randint1(MAX_HGT/SCREEN_HGT);
1358 level_width = randint1(MAX_WID/SCREEN_WID);
1360 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1361 (level_width == MAX_WID/SCREEN_WID));
1364 cur_hgt = level_height * SCREEN_HGT;
1365 cur_wid = level_width * SCREEN_WID;
1367 /* Assume illegal panel */
1368 panel_row_min = cur_hgt;
1369 panel_col_min = cur_wid;
1372 msg_format("X:%d, Y:%d.", cur_wid, cur_hgt);
1380 /* Assume illegal panel */
1381 panel_row_min = cur_hgt;
1382 panel_col_min = cur_wid;
1385 /* Make a dungeon */
1389 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1391 *why = "could not place player";
1401 * Wipe all unnecessary flags after cave generation
1403 static void wipe_generate_cave_flags(void)
1407 for (y = 0; y < cur_hgt; y++)
1409 for (x = 0; x < cur_wid; x++)
1411 /* Wipe unused flags */
1412 cave[y][x].info &= ~(CAVE_MASK);
1418 for (y = 1; y < cur_hgt - 1; y++)
1420 for (x = 1; x < cur_wid - 1; x++)
1422 /* There might be trap */
1423 cave[y][x].info |= CAVE_UNSAFE;
1431 * Clear and empty the cave
1433 void clear_cave(void)
1437 /* Very simplified version of wipe_o_list() */
1438 C_WIPE(o_list, o_max, object_type);
1442 /* Very simplified version of wipe_m_list() */
1443 for (i = 1; i < max_r_idx; i++)
1444 r_info[i].cur_num = 0;
1445 C_WIPE(m_list, m_max, monster_type);
1448 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
1450 /* Pre-calc cur_num of pets in party_mon[] */
1451 precalc_cur_num_of_pet();
1454 /* Start with a blank cave */
1455 for (y = 0; y < MAX_HGT; y++)
1457 for (x = 0; x < MAX_WID; x++)
1459 cave_type *c_ptr = &cave[y][x];
1486 /* Mega-Hack -- no player yet */
1489 /* Set the base level */
1490 base_level = dun_level;
1492 /* Reset the monster generation level */
1493 monster_level = base_level;
1495 /* Reset the object generation level */
1496 object_level = base_level;
1501 * Generates a random dungeon level -RAK-
1503 * Hack -- regenerate any "overflow" levels
1505 void generate_cave(void)
1509 /* Fill the arrays of floors and walls in the good proportions */
1510 set_floor_and_wall(dungeon_type);
1513 for (num = 0; TRUE; num++)
1519 /* Clear and empty the cave */
1522 /* Build the arena -KMW- */
1523 if (p_ptr->inside_arena)
1529 /* Build the battle -KMW- */
1530 else if (p_ptr->inside_battle)
1536 else if (p_ptr->inside_quest)
1541 /* Build the town */
1542 else if (!dun_level)
1544 /* Make the wilderness */
1545 if (p_ptr->wild_mode) wilderness_gen_small();
1546 else wilderness_gen();
1549 /* Build a real level */
1552 okay = level_gen(&why);
1556 /* Prevent object over-flow */
1557 if (o_max >= max_o_idx)
1561 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1563 why = "too many objects";
1570 /* Prevent monster over-flow */
1571 else if (m_max >= max_m_idx)
1575 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1577 why = "too many monsters";
1590 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1592 if (why) msg_format("Generation restarted (%s)", why);
1596 /* Wipe the objects */
1599 /* Wipe the monsters */
1603 /* Glow deep lava and building entrances */
1604 glow_deep_lava_and_bldg();
1607 p_ptr->enter_dungeon = FALSE;
1609 wipe_generate_cave_flags();