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 * Places some staircases near walls
123 static bool alloc_stairs(int feat, int num, int walls)
125 int y, x, i, j, flag;
129 feature_type *f_ptr = &f_info[feat];
131 if (have_flag(f_ptr->flags, FF_LESS))
133 /* No up stairs in town or in ironman mode */
134 if (ironman_downward || !dun_level) return TRUE;
136 if (dun_level > d_info[dungeon_type].mindepth)
137 more_num = (randint1(num+1))/2;
139 else if (have_flag(f_ptr->flags, FF_MORE))
141 int q_idx = quest_number(dun_level);
143 /* No downstairs on quest levels */
144 if (dun_level > 1 && q_idx)
146 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
148 /* The quest monster(s) is still alive? */
149 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
153 /* No downstairs at the bottom */
154 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
156 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
157 more_num = (randint1(num)+1)/2;
163 /* Place "num" stairs */
164 for (i = 0; i < num; i++)
166 /* Place some stairs */
167 for (flag = FALSE; !flag; )
169 /* Try several times, then decrease "walls" */
170 for (j = 0; !flag && j <= 3000; j++)
172 /* Pick a random grid */
173 y = randint1(cur_hgt-2);
174 x = randint1(cur_wid-2);
176 /* Access the grid */
179 /* Require "naked" floor grid */
180 if (!is_floor_grid(c_ptr) || pattern_tile(y,x) || c_ptr->o_idx || c_ptr->m_idx) continue;
182 /* Require a certain number of adjacent walls */
183 if (next_to_walls(y, x) < walls) continue;
185 /* Clear possible garbage of hidden trap */
188 /* Clear previous contents, add stairs */
189 c_ptr->feat = (i < more_num) ? feat_state(feat, FF_SHAFT) : feat;
195 if (!flag) return FALSE;
196 /* Require fewer walls */
205 * Allocates some objects (using "place" and "type")
207 static void alloc_object(int set, int typ, int num)
213 /* A small level has few objects. */
214 num = num * cur_hgt * cur_wid / (MAX_HGT*MAX_WID) +1;
216 /* Place some objects */
217 for (k = 0; k < num; k++)
219 /* Pick a "legal" spot */
220 while (dummy < SAFE_MAX_ATTEMPTS)
227 y = randint0(cur_hgt);
228 x = randint0(cur_wid);
232 /* Require "naked" floor grid */
233 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
235 /* Avoid player location */
236 if (player_bold(y, x)) continue;
238 /* Check for "room" */
239 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
241 /* Require corridor? */
242 if ((set == ALLOC_SET_CORR) && room) continue;
245 if ((set == ALLOC_SET_ROOM) && !room) continue;
251 if (dummy >= SAFE_MAX_ATTEMPTS)
256 msg_print("·Ù¹ð¡ª¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
258 msg_print("Warning! Could not place object!");
266 /* Place something */
269 case ALLOC_TYP_RUBBLE:
272 cave[y][x].info &= ~(CAVE_FLOOR);
279 cave[y][x].info &= ~(CAVE_FLOOR);
289 case ALLOC_TYP_OBJECT:
291 place_object(y, x, 0L);
300 * Count the number of "corridor" grids adjacent to the given grid.
302 * Note -- Assumes "in_bounds(y1, x1)"
304 * XXX XXX This routine currently only counts actual "empty floor"
305 * grids which are not in rooms. We might want to also count stairs,
306 * open doors, closed doors, etc.
308 static int next_to_corr(int y1, int x1)
314 /* Scan adjacent grids */
315 for (i = 0; i < 4; i++)
317 /* Extract the location */
321 /* Access the grid */
324 /* Skip non floors */
325 if (!cave_floor_grid(c_ptr)) continue;
327 /* Skip non "empty floor" grids */
328 if (!is_floor_grid(c_ptr))
331 /* Skip grids inside rooms */
332 if (c_ptr->info & (CAVE_ROOM)) continue;
334 /* Count these grids */
338 /* Return the number of corridors */
344 * Determine if the given location is "between" two walls,
345 * and "next to" two corridor spaces. XXX XXX XXX
347 * Assumes "in_bounds(y, x)"
349 static bool possible_doorway(int y, int x)
351 /* Count the adjacent corridors */
352 if (next_to_corr(y, x) >= 2)
355 if (have_flag(f_flags_bold(y - 1, x), FF_WALL) &&
356 have_flag(f_flags_bold(y + 1, x), FF_WALL))
361 /* Check Horizontal */
362 if (have_flag(f_flags_bold(y, x - 1), FF_WALL) &&
363 have_flag(f_flags_bold(y, x + 1), FF_WALL))
375 * Places door at y, x position if at least 2 walls found
377 static void try_door(int y, int x)
380 if (!in_bounds(y, x)) return;
383 if (!cave_floor_bold(y, x)) return;
385 /* Ignore room grids */
386 if (cave[y][x].info & (CAVE_ROOM)) return;
388 /* Occasional door (if allowed) */
389 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
392 place_random_door(y, x, FALSE);
397 /* Place quest monsters */
398 void place_quest_monsters(void)
402 /* Handle the quest monster placements */
403 for (i = 0; i < max_quests; i++)
409 if (quest[i].status != QUEST_STATUS_TAKEN ||
410 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
411 quest[i].type != QUEST_TYPE_RANDOM) ||
412 quest[i].level != dun_level ||
413 dungeon_type != quest[i].dungeon ||
414 (quest[i].flags & QUEST_FLAG_PRESET))
420 r_ptr = &r_info[quest[i].r_idx];
422 /* Hack -- "unique" monsters must be "unique" */
423 if ((r_ptr->flags1 & RF1_UNIQUE) &&
424 (r_ptr->cur_num >= r_ptr->max_num)) continue;
426 mode = (PM_NO_KAGE | PM_NO_PET);
428 if (!(r_ptr->flags1 & RF1_FRIENDS))
429 mode |= PM_ALLOW_GROUP;
431 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
435 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
440 /* Find an empty grid */
441 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
445 y = randint0(cur_hgt);
446 x = randint0(cur_wid);
449 if (!cave_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
450 if (distance(y, x, py, px) < 10) continue;
454 /* Failed to place */
457 /* Try to place the monster */
458 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
465 /* Failure - Try again */
475 * Set boundary mimic and add "solid" perma-wall
477 static void set_bound_perm_wall(cave_type *c_ptr)
479 if (bound_walls_perm)
481 /* Clear boundary mimic */
486 feature_type *f_ptr = &f_info[c_ptr->feat];
488 /* Hack -- Decline boundary walls with known treasure */
489 if ((have_flag(f_ptr->flags, FF_HAS_GOLD) || have_flag(f_ptr->flags, FF_HAS_ITEM)) &&
490 !have_flag(f_ptr->flags, FF_SECRET))
491 c_ptr->feat = feat_state(c_ptr->feat, FF_ENSECRET);
493 /* Set boundary mimic */
494 c_ptr->mimic = c_ptr->feat;
497 /* Add "solid" perma-wall */
498 c_ptr->feat = FEAT_PERM_SOLID;
503 * Generate various caverns and lakes
505 * There were moved from cave_gen().
507 static void gen_caverns_and_lakes(void)
509 #ifdef ALLOW_CAVERNS_AND_LAKES
510 /* Possible "destroyed" level */
511 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
513 dun->destroyed = TRUE;
515 /* extra rubble around the place looks cool */
516 build_lake(one_in_(2) ? LAKE_T_CAVE : LAKE_T_EARTH_VAULT);
519 /* Make a lake some of the time */
520 if (one_in_(LAKE_LEVEL) && !dun->empty_level && !dun->destroyed &&
521 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
524 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
525 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
526 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
527 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
529 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
532 if ((dun_level > 80) && (randint0(count) < 2)) dun->laketype = LAKE_T_LAVA;
536 if (!dun->laketype && (dun_level > 80) && one_in_(count)) dun->laketype = LAKE_T_FIRE_VAULT;
540 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !dun->laketype)
543 if ((dun_level > 50) && randint0(count) < 2) dun->laketype = LAKE_T_WATER;
547 if (!dun->laketype && (dun_level > 50) && one_in_(count)) dun->laketype = LAKE_T_WATER_VAULT;
551 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !dun->laketype)
554 if ((dun_level > 35) && (randint0(count) < 2)) dun->laketype = LAKE_T_CAVE;
557 /* Lake of rubble2 */
558 if (!dun->laketype && (dun_level > 35) && one_in_(count)) dun->laketype = LAKE_T_EARTH_VAULT;
563 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !dun->laketype) dun->laketype = LAKE_T_AIR_VAULT;
569 msg_print("¸Ð¤òÀ¸À®¡£");
571 msg_print("Lake on the level.");
574 build_lake(dun->laketype);
578 if ((dun_level > DUN_CAVERN) && !dun->empty_level &&
579 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
580 !dun->laketype && !dun->destroyed && (randint1(1000) < dun_level))
584 /* make a large fractal cave in the middle of the dungeon */
588 msg_print("ƶ·¢¤òÀ¸À®¡£");
590 msg_print("Cavern on level.");
595 #endif /* ALLOW_CAVERNS_AND_LAKES */
597 /* Hack -- No destroyed "quest" levels */
598 if (quest_number(dun_level)) dun->destroyed = FALSE;
604 * Generate a new dungeon level
606 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
608 static bool cave_gen(void)
617 dun->destroyed = FALSE;
618 dun->empty_level = FALSE;
622 /* Fill the arrays of floors and walls in the good proportions */
623 set_floor_and_wall(dungeon_type);
626 /* Prepare allocation table */
627 get_mon_num_prep(get_monster_hook(), NULL);
629 feat_wall_outer = d_info[dungeon_type].outer_wall;
630 feat_wall_inner = d_info[dungeon_type].inner_wall;
631 feat_wall_solid = d_info[dungeon_type].outer_wall;
633 /* Randomize the dungeon creation values */
634 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
635 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
636 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
637 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
638 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
640 /* Actual maximum number of rooms on this level */
641 dun->row_rooms = cur_hgt / BLOCK_HGT;
642 dun->col_rooms = cur_wid / BLOCK_WID;
644 /* Initialize the room table */
645 for (y = 0; y < dun->row_rooms; y++)
647 for (x = 0; x < dun->col_rooms; x++)
649 dun->room_map[y][x] = FALSE;
656 /* Empty arena levels */
657 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
659 dun->empty_level = TRUE;
663 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
665 msg_print("Arena level.");
669 if (dun->empty_level)
671 /* Start with floors */
672 for (y = 0; y < cur_hgt; y++)
674 for (x = 0; x < cur_wid; x++)
676 place_floor_bold(y, x);
680 /* Special boundary walls -- Top and bottom */
681 for (x = 0; x < cur_wid; x++)
683 place_extra_bold(0, x);
684 place_extra_bold(cur_hgt - 1, x);
687 /* Special boundary walls -- Left and right */
688 for (y = 1; y < (cur_hgt - 1); y++)
690 place_extra_bold(y, 0);
691 place_extra_bold(y, cur_wid - 1);
696 /* Start with walls */
697 for (y = 0; y < cur_hgt; y++)
699 for (x = 0; x < cur_wid; x++)
701 place_extra_bold(y, x);
707 /* Generate various caverns and lakes */
708 gen_caverns_and_lakes();
712 if (d_info[dungeon_type].flags1 & DF1_MAZE)
714 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
716 /* Place 3 or 4 down stairs near some walls */
717 if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
719 /* Place 1 or 2 up stairs near some walls */
720 if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
723 /* Build some rooms */
727 * Build each type of room in turn until we cannot build any more.
732 /* Make a hole in the dungeon roof sometimes at level 1 */
735 while (one_in_(DUN_MOS_DEN))
737 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
741 /* Destroy the level if necessary */
742 if (dun->destroyed) destroy_level();
744 /* Hack -- Add some rivers */
745 if (one_in_(3) && (randint1(dun_level) > 5))
747 int feat1 = 0, feat2 = 0;
749 /* Choose water or lava */
750 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
752 feat1 = FEAT_DEEP_WATER;
753 feat2 = FEAT_SHAL_WATER;
755 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
757 feat1 = FEAT_DEEP_LAVA;
758 feat2 = FEAT_SHAL_LAVA;
764 feature_type *f_ptr = &f_info[feat1];
766 /* Only add river if matches lake type or if have no lake at all */
767 if (((dun->laketype == LAKE_T_LAVA) && have_flag(f_ptr->flags, FF_LAVA)) ||
768 ((dun->laketype == LAKE_T_WATER) && have_flag(f_ptr->flags, FF_WATER)) ||
771 add_river(feat1, feat2);
776 /* Hack -- Scramble the room order */
777 for (i = 0; i < dun->cent_n; i++)
780 int pick = rand_range(0, i);
784 dun->cent[i].y = dun->cent[pick].y;
785 dun->cent[i].x = dun->cent[pick].x;
786 dun->cent[pick].y = ty;
787 dun->cent[pick].x = tx;
790 /* Start with no tunnel doors */
793 /* Hack -- connect the first room to the last room */
794 y = dun->cent[dun->cent_n-1].y;
795 x = dun->cent[dun->cent_n-1].x;
797 /* Connect all the rooms together */
798 for (i = 0; i < dun->cent_n; i++)
802 /* Reset the arrays */
806 /* Connect the room to the previous room */
807 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
809 /* make cave-like tunnel */
810 build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
814 /* make normal tunnel */
815 build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
818 /* Turn the tunnel into corridor */
819 for (j = 0; j < dun->tunn_n; j++)
824 /* Access the grid */
828 /* Access the grid */
830 f_ptr = &f_info[c_ptr->feat];
832 /* Clear previous contents (if not a lake), add a floor */
833 if (!have_flag(f_ptr->flags, FF_MOVE) || (!have_flag(f_ptr->flags, FF_WATER) && !have_flag(f_ptr->flags, FF_LAVA)))
835 /* Clear mimic type */
838 place_floor_grid(c_ptr);
842 /* Apply the piercings that we found */
843 for (j = 0; j < dun->wall_n; j++)
847 /* Access the grid */
851 /* Access the grid */
854 /* Clear mimic type */
857 /* Clear previous contents, add up floor */
858 place_floor_grid(c_ptr);
860 /* Occasional doorway */
861 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
863 /* Place a random door */
864 place_random_door(y, x, TRUE);
868 /* Remember the "previous" room */
873 /* Place intersection doors */
874 for (i = 0; i < dun->door_n; i++)
876 /* Extract junction location */
880 /* Try placing doors */
887 /* Place 3 or 4 down stairs near some walls */
888 if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
890 /* Place 1 or 2 up stairs near some walls */
891 if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
896 if (d_info[dungeon_type].stream2)
898 /* Hack -- Add some quartz streamers */
899 for (i = 0; i < DUN_STR_QUA; i++)
901 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
905 if (d_info[dungeon_type].stream1)
907 /* Hack -- Add some magma streamers */
908 for (i = 0; i < DUN_STR_MAG; i++)
910 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
915 /* Special boundary walls -- Top and bottom */
916 for (x = 0; x < cur_wid; x++)
918 set_bound_perm_wall(&cave[0][x]);
919 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
922 /* Special boundary walls -- Left and right */
923 for (y = 1; y < (cur_hgt - 1); y++)
925 set_bound_perm_wall(&cave[y][0]);
926 set_bound_perm_wall(&cave[y][cur_wid - 1]);
929 /* Determine the character location */
930 if (!new_player_spot()) return FALSE;
932 place_quest_monsters();
939 /* Pick a base number of monsters */
940 i = d_info[dungeon_type].min_m_alloc_level;
942 /* To make small levels a bit more playable */
943 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
945 int small_tester = i;
947 i = (i * cur_hgt) / MAX_HGT;
948 i = (i * cur_wid) / MAX_WID;
951 if (i > small_tester) i = small_tester;
955 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
957 msg_format("Reduced monsters base from %d to %d", small_tester, i);
965 /* Put some monsters in the dungeon */
966 for (i = i + k; i > 0; i--)
968 (void)alloc_monster(0, PM_ALLOW_SLEEP);
971 /* Place some traps in the dungeon */
972 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
974 /* Put some rubble in corridors (except NO_CAVE dungeon (Castle)) */
975 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE)) alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
977 /* Mega Hack -- No object at first level of deeper dungeon */
978 if (p_ptr->enter_dungeon && dun_level > 1)
984 /* Put some objects in rooms */
985 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
987 /* Put some objects/gold in the dungeon */
988 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
989 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
991 /* Set back to default */
992 object_level = base_level;
994 /* Put the Guardian */
995 (void)alloc_guardian();
997 if (dun->empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1000 for (y = 0; y < cur_hgt; y++)
1002 for (x = 0; x < cur_wid; x++)
1004 cave[y][x].info |= (CAVE_GLOW);
1014 * Builds the arena after it is entered -KMW-
1016 static void build_arena(void)
1018 int yval, y_height, y_depth, xval, x_left, x_right;
1021 yval = SCREEN_HGT / 2;
1022 xval = SCREEN_WID / 2;
1023 y_height = yval - 10;
1024 y_depth = yval + 10;
1026 x_right = xval + 32;
1028 for (i = y_height; i <= y_height + 5; i++)
1029 for (j = x_left; j <= x_right; j++)
1031 cave[i][j].feat = FEAT_PERM_EXTRA;
1032 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1034 for (i = y_depth; i >= y_depth - 5; i--)
1035 for (j = x_left; j <= x_right; j++)
1037 cave[i][j].feat = FEAT_PERM_EXTRA;
1038 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1040 for (j = x_left; j <= x_left + 17; j++)
1041 for (i = y_height; i <= y_depth; i++)
1043 cave[i][j].feat = FEAT_PERM_EXTRA;
1044 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1046 for (j = x_right; j >= x_right - 17; j--)
1047 for (i = y_height; i <= y_depth; i++)
1049 cave[i][j].feat = FEAT_PERM_EXTRA;
1050 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1053 cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
1054 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1055 cave[y_depth-6][x_left+18].feat = FEAT_PERM_EXTRA;
1056 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1057 cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
1058 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1059 cave[y_depth-6][x_right-18].feat = FEAT_PERM_EXTRA;
1060 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1064 cave[i][j].feat = FEAT_BLDG_HEAD + 2;
1065 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1071 * Town logic flow for generation of arena -KMW-
1073 static void arena_gen(void)
1080 cur_hgt = SCREEN_HGT;
1081 cur_wid = SCREEN_WID;
1083 /* Start with solid walls */
1084 for (y = 0; y < MAX_HGT; y++)
1086 for (x = 0; x < MAX_WID; x++)
1088 /* Create "solid" perma-wall */
1089 cave[y][x].feat = FEAT_PERM_SOLID;
1091 /* Illuminate and memorize the walls */
1092 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1096 /* Then place some floors */
1097 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1099 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1101 /* Create empty floor */
1102 cave[y][x].feat = FEAT_FLOOR;
1108 place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx,
1109 (PM_NO_KAGE | PM_NO_PET));
1115 * Builds the arena after it is entered -KMW-
1117 static void build_battle(void)
1119 int yval, y_height, y_depth, xval, x_left, x_right;
1122 yval = SCREEN_HGT / 2;
1123 xval = SCREEN_WID / 2;
1124 y_height = yval - 10;
1125 y_depth = yval + 10;
1127 x_right = xval + 32;
1129 for (i = y_height; i <= y_height + 5; i++)
1130 for (j = x_left; j <= x_right; j++)
1132 cave[i][j].feat = FEAT_PERM_EXTRA;
1133 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1135 for (i = y_depth; i >= y_depth - 3; i--)
1136 for (j = x_left; j <= x_right; j++)
1138 cave[i][j].feat = FEAT_PERM_EXTRA;
1139 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1141 for (j = x_left; j <= x_left + 17; j++)
1142 for (i = y_height; i <= y_depth; i++)
1144 cave[i][j].feat = FEAT_PERM_EXTRA;
1145 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1147 for (j = x_right; j >= x_right - 17; j--)
1148 for (i = y_height; i <= y_depth; i++)
1150 cave[i][j].feat = FEAT_PERM_EXTRA;
1151 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1154 cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
1155 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1156 cave[y_depth-4][x_left+18].feat = FEAT_PERM_EXTRA;
1157 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1158 cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
1159 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1160 cave[y_depth-4][x_right-18].feat = FEAT_PERM_EXTRA;
1161 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1165 cave[i][j].feat = FEAT_BLDG_HEAD + 3;
1166 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1172 * Town logic flow for generation of arena -KMW-
1174 static void battle_gen(void)
1180 /* Start with solid walls */
1181 for (y = 0; y < MAX_HGT; y++)
1183 for (x = 0; x < MAX_WID; x++)
1185 /* Create "solid" perma-wall */
1186 cave[y][x].feat = FEAT_PERM_SOLID;
1188 /* Illuminate and memorize the walls */
1189 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1193 /* Then place some floors */
1194 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1196 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1198 /* Create empty floor */
1199 cave[y][x].feat = FEAT_FLOOR;
1207 place_monster_aux(0, py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1208 (PM_NO_KAGE | PM_NO_PET));
1209 set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
1211 for(i = 1; i < m_max; i++)
1213 monster_type *m_ptr = &m_list[i];
1215 if (!m_ptr->r_idx) continue;
1217 /* Hack -- Detect monster */
1218 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1220 /* Update the monster */
1221 update_mon(i, FALSE);
1227 * Generate a quest level
1229 static void quest_gen(void)
1234 /* Start with perm walls */
1235 for (y = 0; y < cur_hgt; y++)
1237 for (x = 0; x < cur_wid; x++)
1239 cave[y][x].feat = FEAT_PERM_SOLID;
1243 /* Set the quest level */
1244 base_level = quest[p_ptr->inside_quest].level;
1245 dun_level = base_level;
1246 object_level = base_level;
1247 monster_level = base_level;
1249 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1251 /* Prepare allocation table */
1252 get_mon_num_prep(get_monster_hook(), NULL);
1254 init_flags = INIT_CREATE_DUNGEON | INIT_ASSIGN;
1256 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1259 /* Make a real level */
1260 static bool level_gen(cptr *why)
1262 int level_height, level_width;
1264 if ((always_small_levels || ironman_small_levels ||
1265 (one_in_(SMALL_LEVEL) && small_levels) ||
1266 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1267 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1268 !(d_info[dungeon_type].flags1 & DF1_BIG))
1272 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1274 msg_print("A 'small' dungeon level.");
1278 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1283 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1292 level_height = randint1(MAX_HGT/SCREEN_HGT);
1293 level_width = randint1(MAX_WID/SCREEN_WID);
1295 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1296 (level_width == MAX_WID/SCREEN_WID));
1299 cur_hgt = level_height * SCREEN_HGT;
1300 cur_wid = level_width * SCREEN_WID;
1302 /* Assume illegal panel */
1303 panel_row_min = cur_hgt;
1304 panel_col_min = cur_wid;
1307 msg_format("X:%d, Y:%d.", cur_hgt, cur_wid);
1315 /* Assume illegal panel */
1316 panel_row_min = cur_hgt;
1317 panel_col_min = cur_wid;
1320 /* Make a dungeon */
1324 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1326 *why = "could not place player";
1334 static byte extract_feeling(void)
1336 /* Hack -- no feeling in the town */
1337 if (!dun_level) return 0;
1339 /* Hack -- Have a special feeling sometimes */
1340 if (good_item_flag && !preserve_mode) return 1;
1342 if (rating > 100) return 2;
1343 if (rating > 80) return 3;
1344 if (rating > 60) return 4;
1345 if (rating > 40) return 5;
1346 if (rating > 30) return 6;
1347 if (rating > 20) return 7;
1348 if (rating > 10) return 8;
1349 if (rating > 0) return 9;
1351 if((turn - old_turn) > TURNS_PER_TICK * TOWN_DAWN /2)
1352 chg_virtue(V_PATIENCE, 1);
1359 * Wipe all unnecessary flags after cave generation
1361 static void wipe_generate_cave_flags(void)
1365 for (y = 0; y < cur_hgt; y++)
1367 for (x = 0; x < cur_wid; x++)
1369 /* Wipe unused flags */
1370 cave[y][x].info &= ~(CAVE_MASK);
1376 for (y = 1; y < cur_hgt - 1; y++)
1378 for (x = 1; x < cur_wid - 1; x++)
1380 /* There might be trap */
1381 cave[y][x].info |= CAVE_UNSAFE;
1389 * Clear and empty the cave
1391 void clear_cave(void)
1395 /* Very simplified version of wipe_o_list() */
1396 C_WIPE(o_list, o_max, object_type);
1400 /* Very simplified version of wipe_m_list() */
1401 for (i = 1; i < max_r_idx; i++)
1402 r_info[i].cur_num = 0;
1403 C_WIPE(m_list, m_max, monster_type);
1407 /* Pre-calc cur_num of pets in party_mon[] */
1408 precalc_cur_num_of_pet();
1411 /* Start with a blank cave */
1412 for (y = 0; y < MAX_HGT; y++)
1414 for (x = 0; x < MAX_WID; x++)
1416 cave_type *c_ptr = &cave[y][x];
1443 /* Mega-Hack -- no player yet */
1446 /* Set the base level */
1447 base_level = dun_level;
1449 /* Reset the monster generation level */
1450 monster_level = base_level;
1452 /* Reset the object generation level */
1453 object_level = base_level;
1455 /* Nothing special here yet */
1456 good_item_flag = FALSE;
1458 /* Nothing good here yet */
1464 * Generates a random dungeon level -RAK-
1466 * Hack -- regenerate any "overflow" levels
1468 * Hack -- allow auto-scumming via a gameplay option.
1470 void generate_cave(void)
1474 /* Fill the arrays of floors and walls in the good proportions */
1475 set_floor_and_wall(dungeon_type);
1478 for (num = 0; TRUE; num++)
1484 /* Clear and empty the cave */
1487 if (have_flag(f_info[d_info[dungeon_type].fill_type1].flags, FF_HAS_GOLD) ||
1488 have_flag(f_info[d_info[dungeon_type].fill_type2].flags, FF_HAS_GOLD) ||
1489 have_flag(f_info[d_info[dungeon_type].fill_type3].flags, FF_HAS_GOLD)) rating += 40;
1491 /* Build the arena -KMW- */
1492 if (p_ptr->inside_arena)
1498 /* Build the battle -KMW- */
1499 else if (p_ptr->inside_battle)
1505 else if (p_ptr->inside_quest)
1510 /* Build the town */
1511 else if (!dun_level)
1513 /* Make the wilderness */
1514 if (p_ptr->wild_mode) wilderness_gen_small();
1515 else wilderness_gen();
1518 /* Build a real level */
1521 okay = level_gen(&why);
1524 /* Extract the feeling */
1525 feeling = extract_feeling();
1527 /* Prevent object over-flow */
1528 if (o_max >= max_o_idx)
1532 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1534 why = "too many objects";
1541 /* Prevent monster over-flow */
1542 else if (m_max >= max_m_idx)
1546 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1548 why = "too many monsters";
1561 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1563 if (why) msg_format("Generation restarted (%s)", why);
1567 /* Wipe the objects */
1570 /* Wipe the monsters */
1574 /* Glow deep lava and building entrances */
1575 glow_deep_lava_and_bldg();
1578 p_ptr->enter_dungeon = FALSE;
1580 wipe_generate_cave_flags();