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"
117 * Dungeon generation data -- see "cave_gen()"
122 * Places some staircases near walls
124 static bool alloc_stairs(int feat, int num, int walls)
126 int y, x, i, j, flag;
130 if (feat == FEAT_LESS)
132 /* No up stairs in town or in ironman mode */
133 if (ironman_downward || !dun_level) return TRUE;
135 if (dun_level > d_info[dungeon_type].mindepth)
136 more_num = (randint1(num+1))/2;
138 else if (feat == FEAT_MORE)
140 int q_idx = quest_number(dun_level);
142 /* No downstairs on quest levels */
143 if (dun_level > 1 && q_idx)
145 monster_race *r_ptr = &r_info[quest[q_idx].r_idx];
147 /* The quest monster(s) is still alive? */
148 if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num)
152 /* No downstairs at the bottom */
153 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
155 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
156 more_num = (randint1(num)+1)/2;
159 /* Place "num" stairs */
160 for (i = 0; i < num; i++)
162 /* Place some stairs */
163 for (flag = FALSE; !flag; )
165 /* Try several times, then decrease "walls" */
166 for (j = 0; !flag && j <= 3000; j++)
168 /* Pick a random grid */
169 y = randint1(cur_hgt-2);
170 x = randint1(cur_wid-2);
172 /* Access the grid */
175 /* Require "naked" floor grid */
176 if (!is_floor_grid(c_ptr) || pattern_tile(y,x) || c_ptr->o_idx || c_ptr->m_idx) continue;
178 /* Require a certain number of adjacent walls */
179 if (next_to_walls(y, x) < walls) continue;
181 /* Clear possible garbage of hidden trap */
184 /* Clear previous contents, add stairs */
185 if (i < more_num) c_ptr->feat = feat+0x07;
186 else c_ptr->feat = feat;
188 /* No longer a "FLOOR" */
189 c_ptr->info &= ~(CAVE_FLOOR);
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 /* Place some objects */
214 for (k = 0; k < num; k++)
216 /* Pick a "legal" spot */
217 while (dummy < SAFE_MAX_ATTEMPTS)
224 y = randint0(cur_hgt);
225 x = randint0(cur_wid);
229 /* Require "naked" floor grid */
230 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
232 /* Avoid player location */
233 if (player_bold(y, x)) continue;
235 /* Check for "room" */
236 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
238 /* Require corridor? */
239 if ((set == ALLOC_SET_CORR) && room) continue;
242 if ((set == ALLOC_SET_ROOM) && !room) continue;
248 if (dummy >= SAFE_MAX_ATTEMPTS)
253 msg_print("·Ù¹ð¡ª¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
255 msg_print("Warning! Could not place object!");
263 /* Place something */
266 case ALLOC_TYP_RUBBLE:
269 cave[y][x].info &= ~(CAVE_FLOOR);
276 cave[y][x].info &= ~(CAVE_FLOOR);
286 case ALLOC_TYP_OBJECT:
288 place_object(y, x, 0L);
297 * Count the number of "corridor" grids adjacent to the given grid.
299 * Note -- Assumes "in_bounds(y1, x1)"
301 * XXX XXX This routine currently only counts actual "empty floor"
302 * grids which are not in rooms. We might want to also count stairs,
303 * open doors, closed doors, etc.
305 static int next_to_corr(int y1, int x1)
311 /* Scan adjacent grids */
312 for (i = 0; i < 4; i++)
314 /* Extract the location */
318 /* Access the grid */
321 /* Skip non floors */
322 if (!cave_floor_grid(c_ptr)) continue;
324 /* Skip non "empty floor" grids */
325 if (!is_floor_grid(c_ptr))
328 /* Skip grids inside rooms */
329 if (c_ptr->info & (CAVE_ROOM)) continue;
331 /* Count these grids */
335 /* Return the number of corridors */
341 * Determine if the given location is "between" two walls,
342 * and "next to" two corridor spaces. XXX XXX XXX
344 * Assumes "in_bounds(y, x)"
346 static bool possible_doorway(int y, int x)
348 /* Count the adjacent corridors */
349 if (next_to_corr(y, x) >= 2)
352 if ((cave[y-1][x].feat >= FEAT_MAGMA) &&
353 (cave[y+1][x].feat >= FEAT_MAGMA))
358 /* Check Horizontal */
359 if ((cave[y][x-1].feat >= FEAT_MAGMA) &&
360 (cave[y][x+1].feat >= FEAT_MAGMA))
372 * Places door at y, x position if at least 2 walls found
374 static void try_door(int y, int x)
377 if (!in_bounds(y, x)) return;
380 if (!cave_floor_bold(y, x)) return;
382 /* Ignore room grids */
383 if (cave[y][x].info & (CAVE_ROOM)) return;
385 /* Occasional door (if allowed) */
386 if ((randint0(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
389 place_random_door(y, x, FALSE);
394 /* Place quest monsters */
395 bool place_quest_monsters(void)
399 /* Handle the quest monster placements */
400 for (i = 0; i < max_quests; i++)
406 if (quest[i].status != QUEST_STATUS_TAKEN ||
407 (quest[i].type != QUEST_TYPE_KILL_LEVEL &&
408 quest[i].type != QUEST_TYPE_RANDOM) ||
409 quest[i].level != dun_level ||
410 dungeon_type != quest[i].dungeon ||
411 (quest[i].flags & QUEST_FLAG_PRESET))
417 r_ptr = &r_info[quest[i].r_idx];
419 /* Hack -- "unique" monsters must be "unique" */
420 if ((r_ptr->flags1 & RF1_UNIQUE) &&
421 (r_ptr->cur_num >= r_ptr->max_num)) continue;
423 mode = (PM_NO_KAGE | PM_NO_PET);
425 if (!(r_ptr->flags1 & RF1_FRIENDS))
426 mode |= PM_ALLOW_GROUP;
428 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
432 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
437 /* Find an empty grid */
438 for (l = SAFE_MAX_ATTEMPTS; l > 0; l--)
442 y = randint0(cur_hgt);
443 x = randint0(cur_wid);
446 if (!cave_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
447 if (distance(y, x, py, px) < 10) continue;
448 if (c_ptr->info & CAVE_ICKY) continue;
452 /* Failed to place */
453 if (!l) return FALSE;
455 /* Try to place the monster */
456 if (place_monster_aux(0, y, x, quest[i].r_idx, mode))
463 /* Failure - Try again */
468 /* Failed to place */
469 if (k == SAFE_MAX_ATTEMPTS) return FALSE;
478 * Set boundary mimic and add "solid" perma-wall
480 static void set_bound_perm_wall(cave_type *c_ptr)
482 if (bound_walls_perm)
484 /* Clear boundary mimic */
489 /* Hack -- Decline boundary walls with known treasure */
490 if ((c_ptr->feat == FEAT_MAGMA_K) || (c_ptr->feat == FEAT_QUARTZ_K))
491 c_ptr->feat -= (FEAT_MAGMA_K - FEAT_MAGMA);
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 a new dungeon level
505 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
507 static bool cave_gen(void)
509 int i, j, k, y, x, y1, x1;
511 int max_vault_ok = 2;
513 int feat1 = 0, feat2 = 0;
517 bool destroyed = FALSE;
518 bool empty_level = FALSE;
525 /* Fill the arrays of floors and walls in the good proportions */
526 set_floor_and_wall(dungeon_type);
529 /* Prepare allocation table */
530 get_mon_num_prep(get_monster_hook(), NULL);
532 feat_wall_outer = d_info[dungeon_type].outer_wall;
533 feat_wall_inner = d_info[dungeon_type].inner_wall;
534 feat_wall_solid = d_info[dungeon_type].outer_wall;
539 if (cur_hgt <= SCREEN_HGT / 2 - 2) max_vault_ok--;
540 if (cur_wid <= SCREEN_WID / 2 - 2) max_vault_ok--;
542 /* Randomize the dungeon creation values */
543 dun_rooms = rand_range(DUN_ROOMS_MIN, DUN_ROOMS_MAX);
544 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
545 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
546 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
547 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
548 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
550 /* Actual maximum number of rooms on this level */
551 dun->row_rooms = cur_hgt / BLOCK_HGT;
552 dun->col_rooms = cur_wid / BLOCK_WID;
554 /* Initialize the room table */
555 for (y = 0; y < dun->row_rooms; y++)
557 for (x = 0; x < dun->col_rooms; x++)
559 dun->room_map[y][x] = FALSE;
563 /* No "crowded" rooms yet */
569 /* Empty arena levels */
570 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && one_in_(EMPTY_LEVEL))))
576 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
578 msg_print("Arena level.");
584 /* Start with floors */
585 for (y = 0; y < cur_hgt; y++)
587 for (x = 0; x < cur_wid; x++)
589 place_floor_bold(y, x);
593 /* Special boundary walls -- Top and bottom */
594 for (x = 0; x < cur_wid; x++)
596 place_extra_bold(0, x);
597 place_extra_bold(cur_hgt - 1, x);
600 /* Special boundary walls -- Left and right */
601 for (y = 1; y < (cur_hgt - 1); y++)
603 place_extra_bold(y, 0);
604 place_extra_bold(y, cur_wid - 1);
609 /* Start with walls */
610 for (y = 0; y < cur_hgt; y++)
612 for (x = 0; x < cur_wid; x++)
614 place_extra_bold(y, x);
619 #ifdef ALLOW_CAVERNS_AND_LAKES
620 /* Possible "destroyed" level */
621 if ((dun_level > 30) && one_in_(DUN_DEST*2) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
625 /* extra rubble around the place looks cool */
626 build_lake(one_in_(2) ? GEN_LAKE_TYPE_CAVE : GEN_LAKE_TYPE_EARTH_VAULT);
629 /* Make a lake some of the time */
630 if (one_in_(LAKE_LEVEL) && !empty_level && !destroyed &&
631 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
634 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
635 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
636 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
637 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
639 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
642 if ((dun_level > 80) && (randint0(count) < 2)) laketype = GEN_LAKE_TYPE_LAVA;
646 if (!laketype && (dun_level > 80) && one_in_(count)) laketype = GEN_LAKE_TYPE_FIRE_VAULT;
650 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !laketype)
653 if ((dun_level > 50) && randint0(count) < 2) laketype = GEN_LAKE_TYPE_WATER;
657 if (!laketype && (dun_level > 50) && one_in_(count)) laketype = GEN_LAKE_TYPE_WATER_VAULT;
661 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !laketype)
664 if ((dun_level > 35) && (randint0(count) < 2)) laketype = GEN_LAKE_TYPE_CAVE;
667 /* Lake of rubble2 */
668 if (!laketype && (dun_level > 35) && one_in_(count)) laketype = GEN_LAKE_TYPE_EARTH_VAULT;
673 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !laketype) laketype = GEN_LAKE_TYPE_AIR_VAULT;
679 msg_print("¸Ð¤òÀ¸À®¡£");
681 msg_print("Lake on the level.");
684 build_lake(laketype);
688 if ((dun_level > DUN_CAVERN) && !empty_level &&
689 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
690 !laketype && !destroyed && (randint1(1000) < dun_level))
694 /* make a large fractal cave in the middle of the dungeon */
698 msg_print("ƶ·¢¤òÀ¸À®¡£");
700 msg_print("Cavern on level.");
705 #endif /* ALLOW_CAVERNS_AND_LAKES */
707 /* Hack -- No destroyed "quest" levels */
708 if (quest_number(dun_level)) destroyed = FALSE;
711 if (d_info[dungeon_type].flags1 & DF1_MAZE)
713 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
715 /* Place 3 or 4 down stairs near some walls */
716 if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
718 /* Place 1 or 2 up stairs near some walls */
719 if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
722 /* Build some rooms */
725 for (i = 0; i < dun_rooms; i++)
727 bool force_rooms = (ironman_rooms && !((d_info[dungeon_type].flags1 & DF1_BEGINNER) || (d_info[dungeon_type].flags1 & DF1_CHAMELEON)));
729 /* Pick a block for the room */
730 y = randint0(dun->row_rooms);
731 x = randint0(dun->col_rooms);
733 /* Align dungeon rooms */
734 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
736 /* Slide some rooms right */
737 if ((x % 3) == 0) x++;
739 /* Slide some rooms left */
740 if ((x % 3) == 2) x--;
743 /* Attempt an "unusual" room */
744 if (force_rooms || (randint0(DUN_UNUSUAL) < dun_level))
746 /* Roll for room type */
749 k = (force_rooms ? 0 : randint0(100));
750 if (force_rooms) break;
751 if ((d_info[dungeon_type].flags1 & DF1_NO_VAULT) && (k < 14)) continue;
755 /* Attempt a very unusual room */
756 if (force_rooms || (randint0(DUN_UNUSUAL) < dun_level))
759 if (room_build(y, x, ROOM_BUILD_TYPE_GREATER_VAULT)) continue;
761 /* Type 8 -- Greater vault (4%) */
764 if (max_vault_ok > 1)
766 if (room_build(y, x, ROOM_BUILD_TYPE_GREATER_VAULT)) continue;
771 if (cheat_room) msg_print("µðÂç¤ÊÃϲ¼¼¼¤òµÑ²¼¤·¤Þ¤¹¡£");
773 if (cheat_room) msg_print("Refusing a greater vault.");
778 /* Type 7 -- Lesser vault (6%) */
781 if (max_vault_ok > 0)
783 if (room_build(y, x, ROOM_BUILD_TYPE_LESSER_VAULT)) continue;
788 if (cheat_room) msg_print("¾®¤µ¤ÊÃϲ¼¼¼¤òµÑ²¼¤·¤Þ¤¹¡£");
790 if (cheat_room) msg_print("Refusing a lesser vault.");
796 /* Type 10 -- Random vault (4%) */
797 if ((k < 14) && room_build(y, x, ROOM_BUILD_TYPE_RANDOM_VAULT)) continue;
799 /* Type 5 -- Monster nest (8%) */
800 if ((k < 22) && room_build(y, x, ROOM_BUILD_TYPE_NEST)) continue;
802 /* Type 6 -- Monster pit (10%) */
803 if ((k < 32) && room_build(y, x, ROOM_BUILD_TYPE_PIT)) continue;
805 /* Type 13 -- Trapped monster pit (5%) */
806 if ((k < 37) && room_build(y, x, ROOM_BUILD_TYPE_TRAP_PIT)) continue;
808 /* Type 14 -- Trapped room (5%) */
809 if ((k < 42) && room_build(y, x, ROOM_BUILD_TYPE_TRAP)) continue;
813 /* Type 2 -- Overlapping (25%) */
814 if ((k < 25) && room_build(y, x, ROOM_BUILD_TYPE_OVERLAP)) continue;
816 /* Type 3 -- Cross room (25%) */
817 if ((k < 50) && room_build(y, x, ROOM_BUILD_TYPE_CROSS)) continue;
819 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
821 if (room_build(y, x, ROOM_BUILD_TYPE_INNER_FEAT)) continue;
825 /* Type 4 -- Large room (25%) */
826 if ((k < 75) && room_build(y, x, ROOM_BUILD_TYPE_INNER_FEAT)) continue;
828 /* Type 11 -- Circular (10%) */
829 if ((k < 85) && room_build(y, x, ROOM_BUILD_TYPE_OVAL)) continue;
831 /* Type 12 -- Crypt (15%) */
832 if ((k < 100) && room_build(y, x, ROOM_BUILD_TYPE_CRYPT)) continue;
836 /* The deeper you are, the more cavelike the rooms are */
839 /* No caves when a cavern exists: they look bad */
840 if (((k < dun_level) || (d_info[dungeon_type].flags1 & DF1_CAVE))
841 && !cavern && !empty_level && !laketype
842 && !(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
844 /* Type 9 -- Fractal cave */
845 if (room_build(y, x, ROOM_BUILD_TYPE_FRACAVE)) continue;
849 /* Attempt a "trivial" room */
850 if (room_build(y, x, ROOM_BUILD_TYPE_NORMAL)) continue;
856 /* Make a hole in the dungeon roof sometimes at level 1 */
859 while (one_in_(DUN_MOS_DEN))
861 place_trees(randint1(cur_wid - 2), randint1(cur_hgt - 2));
865 /* Destroy the level if necessary */
866 if (destroyed) destroy_level();
868 /* Hack -- Add some rivers */
869 if (one_in_(3) && (randint1(dun_level) > 5))
871 /* Choose water or lava */
872 if ((randint1(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
874 feat1 = FEAT_DEEP_WATER;
875 feat2 = FEAT_SHAL_WATER;
877 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
879 feat1 = FEAT_DEEP_LAVA;
880 feat2 = FEAT_SHAL_LAVA;
885 /* Only add river if matches lake type or if have no lake at all */
886 if ((((laketype == GEN_LAKE_TYPE_LAVA) && (feat1 == FEAT_DEEP_LAVA)) ||
887 ((laketype == GEN_LAKE_TYPE_WATER) && (feat1 == FEAT_DEEP_WATER)) ||
890 add_river(feat1, feat2);
894 /* Hack -- Scramble the room order */
895 for (i = 0; i < dun->cent_n; i++)
897 int pick1 = randint0(dun->cent_n);
898 int pick2 = randint0(dun->cent_n);
899 y1 = dun->cent[pick1].y;
900 x1 = dun->cent[pick1].x;
901 dun->cent[pick1].y = dun->cent[pick2].y;
902 dun->cent[pick1].x = dun->cent[pick2].x;
903 dun->cent[pick2].y = y1;
904 dun->cent[pick2].x = x1;
907 /* Start with no tunnel doors */
910 /* Hack -- connect the first room to the last room */
911 y = dun->cent[dun->cent_n-1].y;
912 x = dun->cent[dun->cent_n-1].x;
914 /* Connect all the rooms together */
915 for (i = 0; i < dun->cent_n; i++)
917 /* Reset the arrays */
921 /* Connect the room to the previous room */
922 if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
924 /* make cave-like tunnel */
925 build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
929 /* make normal tunnel */
930 build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
933 /* Turn the tunnel into corridor */
934 for (j = 0; j < dun->tunn_n; j++)
936 /* Access the grid */
940 /* Access the grid */
943 /* Clear previous contents (if not a lake), add a floor */
944 if ((c_ptr->feat < FEAT_DEEP_WATER) ||
945 (c_ptr->feat > FEAT_SHAL_LAVA))
947 /* Clear mimic type */
950 place_floor_grid(c_ptr);
954 /* Apply the piercings that we found */
955 for (j = 0; j < dun->wall_n; j++)
957 /* Access the grid */
961 /* Access the grid */
964 /* Clear mimic type */
967 /* Clear previous contents, add up floor */
968 place_floor_grid(c_ptr);
970 /* Occasional doorway */
971 if ((randint0(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
973 /* Place a random door */
974 place_random_door(y, x, TRUE);
978 /* Remember the "previous" room */
983 /* Place intersection doors */
984 for (i = 0; i < dun->door_n; i++)
986 /* Extract junction location */
990 /* Try placing doors */
997 /* Place 3 or 4 down stairs near some walls */
998 if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
1000 /* Place 1 or 2 up stairs near some walls */
1001 if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
1006 if (d_info[dungeon_type].stream2)
1008 /* Hack -- Add some quartz streamers */
1009 for (i = 0; i < DUN_STR_QUA; i++)
1011 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
1015 if (d_info[dungeon_type].stream1)
1017 /* Hack -- Add some magma streamers */
1018 for (i = 0; i < DUN_STR_MAG; i++)
1020 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
1025 /* Special boundary walls -- Top and bottom */
1026 for (x = 0; x < cur_wid; x++)
1028 set_bound_perm_wall(&cave[0][x]);
1029 set_bound_perm_wall(&cave[cur_hgt - 1][x]);
1032 /* Special boundary walls -- Left and right */
1033 for (y = 1; y < (cur_hgt - 1); y++)
1035 set_bound_perm_wall(&cave[y][0]);
1036 set_bound_perm_wall(&cave[y][cur_wid - 1]);
1039 /* Determine the character location */
1040 if (!new_player_spot()) return FALSE;
1042 if (!place_quest_monsters()) return FALSE;
1044 /* Basic "amount" */
1045 k = (dun_level / 3);
1049 /* Pick a base number of monsters */
1050 i = d_info[dungeon_type].min_m_alloc_level;
1052 /* To make small levels a bit more playable */
1053 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1055 int small_tester = i;
1057 i = (i * cur_hgt) / MAX_HGT;
1058 i = (i * cur_wid) / MAX_WID;
1061 if (i > small_tester) i = small_tester;
1062 else if (cheat_hear)
1065 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
1067 msg_format("Reduced monsters base from %d to %d", small_tester, i);
1075 /* Put some monsters in the dungeon */
1076 for (i = i + k; i > 0; i--)
1078 (void)alloc_monster(0, PM_ALLOW_SLEEP);
1081 /* Place some traps in the dungeon */
1082 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint1(k));
1084 /* Put some rubble in corridors */
1085 alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint1(k));
1087 /* Mega Hack -- No object at first level of deeper dungeon */
1088 if (p_ptr->enter_dungeon && dun_level > 1)
1090 /* No stair scum! */
1094 /* Put some objects in rooms */
1095 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1097 /* Put some objects/gold in the dungeon */
1098 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1099 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1102 /* Put the Guardian */
1103 if (!alloc_guardian(TRUE)) return FALSE;
1105 if (empty_level && (!one_in_(DARK_EMPTY) || (randint1(100) > dun_level)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1108 for (y = 0; y < cur_hgt; y++)
1110 for (x = 0; x < cur_wid; x++)
1112 cave[y][x].info |= (CAVE_GLOW);
1122 * Builds the arena after it is entered -KMW-
1124 static void build_arena(void)
1126 int yval, y_height, y_depth, xval, x_left, x_right;
1129 yval = SCREEN_HGT / 2;
1130 xval = SCREEN_WID / 2;
1131 y_height = yval - 10;
1132 y_depth = yval + 10;
1134 x_right = xval + 32;
1136 for (i = y_height; i <= y_height + 5; i++)
1137 for (j = x_left; j <= x_right; j++)
1139 cave[i][j].feat = FEAT_PERM_EXTRA;
1140 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1142 for (i = y_depth; i >= y_depth - 5; i--)
1143 for (j = x_left; j <= x_right; j++)
1145 cave[i][j].feat = FEAT_PERM_EXTRA;
1146 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1148 for (j = x_left; j <= x_left + 17; j++)
1149 for (i = y_height; i <= y_depth; i++)
1151 cave[i][j].feat = FEAT_PERM_EXTRA;
1152 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1154 for (j = x_right; j >= x_right - 17; j--)
1155 for (i = y_height; i <= y_depth; i++)
1157 cave[i][j].feat = FEAT_PERM_EXTRA;
1158 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1161 cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
1162 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1163 cave[y_depth-6][x_left+18].feat = FEAT_PERM_EXTRA;
1164 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1165 cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
1166 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1167 cave[y_depth-6][x_right-18].feat = FEAT_PERM_EXTRA;
1168 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1172 cave[i][j].feat = FEAT_BLDG_HEAD + 2;
1173 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1174 player_place(i + 1, j);
1179 * Town logic flow for generation of arena -KMW-
1181 static void arena_gen(void)
1188 cur_hgt = SCREEN_HGT;
1189 cur_wid = SCREEN_WID;
1191 /* Start with solid walls */
1192 for (y = 0; y < MAX_HGT; y++)
1194 for (x = 0; x < MAX_WID; x++)
1196 /* Create "solid" perma-wall */
1197 cave[y][x].feat = FEAT_PERM_SOLID;
1199 /* Illuminate and memorize the walls */
1200 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1204 /* Then place some floors */
1205 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1207 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1209 /* Create empty floor */
1210 cave[y][x].feat = FEAT_FLOOR;
1216 place_monster_aux(0, py + 5, px, arena_info[p_ptr->arena_number].r_idx,
1217 (PM_NO_KAGE | PM_NO_PET));
1223 * Builds the arena after it is entered -KMW-
1225 static void build_battle(void)
1227 int yval, y_height, y_depth, xval, x_left, x_right;
1230 yval = SCREEN_HGT / 2;
1231 xval = SCREEN_WID / 2;
1232 y_height = yval - 10;
1233 y_depth = yval + 10;
1235 x_right = xval + 32;
1237 for (i = y_height; i <= y_height + 5; i++)
1238 for (j = x_left; j <= x_right; j++)
1240 cave[i][j].feat = FEAT_PERM_EXTRA;
1241 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1243 for (i = y_depth; i >= y_depth - 3; i--)
1244 for (j = x_left; j <= x_right; j++)
1246 cave[i][j].feat = FEAT_PERM_EXTRA;
1247 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1249 for (j = x_left; j <= x_left + 17; j++)
1250 for (i = y_height; i <= y_depth; i++)
1252 cave[i][j].feat = FEAT_PERM_EXTRA;
1253 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1255 for (j = x_right; j >= x_right - 17; j--)
1256 for (i = y_height; i <= y_depth; i++)
1258 cave[i][j].feat = FEAT_PERM_EXTRA;
1259 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1262 cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
1263 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1264 cave[y_depth-4][x_left+18].feat = FEAT_PERM_EXTRA;
1265 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1266 cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
1267 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1268 cave[y_depth-4][x_right-18].feat = FEAT_PERM_EXTRA;
1269 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1273 cave[i][j].feat = FEAT_BLDG_HEAD + 3;
1274 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1280 * Town logic flow for generation of arena -KMW-
1282 static void battle_gen(void)
1288 /* Start with solid walls */
1289 for (y = 0; y < MAX_HGT; y++)
1291 for (x = 0; x < MAX_WID; x++)
1293 /* Create "solid" perma-wall */
1294 cave[y][x].feat = FEAT_PERM_SOLID;
1296 /* Illuminate and memorize the walls */
1297 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1301 /* Then place some floors */
1302 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1304 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1306 /* Create empty floor */
1307 cave[y][x].feat = FEAT_FLOOR;
1315 place_monster_aux(0, py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1316 (PM_NO_KAGE | PM_NO_PET));
1317 set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
1319 for(i = 1; i < m_max; i++)
1321 monster_type *m_ptr = &m_list[i];
1323 if (!m_ptr->r_idx) continue;
1325 /* Hack -- Detect monster */
1326 m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
1328 /* Update the monster */
1329 update_mon(i, FALSE);
1335 * Generate a quest level
1337 static void quest_gen(void)
1342 /* Start with perm walls */
1343 for (y = 0; y < cur_hgt; y++)
1345 for (x = 0; x < cur_wid; x++)
1347 cave[y][x].feat = FEAT_PERM_SOLID;
1351 /* Set the quest level */
1352 base_level = quest[p_ptr->inside_quest].level;
1353 dun_level = base_level;
1354 object_level = base_level;
1355 monster_level = base_level;
1357 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1359 /* Prepare allocation table */
1360 get_mon_num_prep(get_monster_hook(), NULL);
1362 init_flags = INIT_CREATE_DUNGEON | INIT_ASSIGN;
1364 process_dungeon_file("q_info.txt", 0, 0, MAX_HGT, MAX_WID);
1367 /* Make a real level */
1368 static bool level_gen(cptr *why)
1370 int level_height, level_width;
1372 if ((always_small_levels || ironman_small_levels ||
1373 (one_in_(SMALL_LEVEL) && small_levels) ||
1374 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1375 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1376 !(d_info[dungeon_type].flags1 & DF1_BIG))
1380 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1382 msg_print("A 'small' dungeon level.");
1386 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1391 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1400 level_height = randint1(MAX_HGT/SCREEN_HGT);
1401 level_width = randint1(MAX_WID/SCREEN_WID);
1403 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1404 (level_width == MAX_WID/SCREEN_WID));
1407 cur_hgt = level_height * SCREEN_HGT;
1408 cur_wid = level_width * SCREEN_WID;
1410 /* Assume illegal panel */
1411 panel_row_min = cur_hgt;
1412 panel_col_min = cur_wid;
1415 msg_format("X:%d, Y:%d.", cur_wid, cur_hgt);
1423 /* Assume illegal panel */
1424 panel_row_min = cur_hgt;
1425 panel_col_min = cur_wid;
1428 /* Make a dungeon */
1432 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1434 *why = "could not place player";
1442 static byte extract_feeling(void)
1444 /* Hack -- no feeling in the town */
1445 if (!dun_level) return 0;
1447 /* Hack -- Have a special feeling sometimes */
1448 if (good_item_flag && !preserve_mode) return 1;
1450 if (rating > 100) return 2;
1451 if (rating > 80) return 3;
1452 if (rating > 60) return 4;
1453 if (rating > 40) return 5;
1454 if (rating > 30) return 6;
1455 if (rating > 20) return 7;
1456 if (rating > 10) return 8;
1457 if (rating > 0) return 9;
1459 if((turn - old_turn) > TURNS_PER_TICK * TOWN_DAWN /2)
1460 chg_virtue(V_PATIENCE, 1);
1467 * Wipe all unnecessary flags after cave generation
1469 void wipe_generate_cave_flags(void)
1473 for (y = 0; y < cur_hgt; y++)
1475 for (x = 0; x < cur_wid; x++)
1477 /* Wipe unused flags */
1478 cave[y][x].info &= ~(CAVE_MASK);
1484 for (y = 1; y < cur_hgt - 1; y++)
1486 for (x = 1; x < cur_wid - 1; x++)
1488 /* There might be trap */
1489 cave[y][x].info |= CAVE_UNSAFE;
1497 * Clear and empty the cave
1499 void clear_cave(void)
1503 /* Very simplified version of wipe_o_list() */
1504 C_WIPE(o_list, o_max, object_type);
1508 /* Very simplified version of wipe_m_list() */
1509 for (i = 1; i < max_r_idx; i++)
1510 r_info[i].cur_num = 0;
1511 C_WIPE(m_list, m_max, monster_type);
1514 precalc_cur_num_of_pet();
1517 /* Start with a blank cave */
1518 for (y = 0; y < MAX_HGT; y++)
1520 for (x = 0; x < MAX_WID; x++)
1522 cave_type *c_ptr = &cave[y][x];
1549 /* Mega-Hack -- no player yet */
1552 /* Set the base level */
1553 base_level = dun_level;
1555 /* Reset the monster generation level */
1556 monster_level = base_level;
1558 /* Reset the object generation level */
1559 object_level = base_level;
1561 /* Nothing special here yet */
1562 good_item_flag = FALSE;
1564 /* Nothing good here yet */
1570 * Generates a random dungeon level -RAK-
1572 * Hack -- regenerate any "overflow" levels
1574 * Hack -- allow auto-scumming via a gameplay option.
1576 void generate_cave(void)
1580 /* Fill the arrays of floors and walls in the good proportions */
1581 set_floor_and_wall(dungeon_type);
1584 for (num = 0; TRUE; num++)
1590 /* Clear and empty the cave */
1593 if ((d_info[dungeon_type].fill_type1 == FEAT_MAGMA_K) || (d_info[dungeon_type].fill_type2 == FEAT_MAGMA_K) || (d_info[dungeon_type].fill_type3 == FEAT_MAGMA_K)) rating += 40;
1595 /* Build the arena -KMW- */
1596 if (p_ptr->inside_arena)
1602 /* Build the battle -KMW- */
1603 else if (p_ptr->inside_battle)
1609 else if (p_ptr->inside_quest)
1614 /* Build the town */
1615 else if (!dun_level)
1617 /* Make the wilderness */
1618 if (p_ptr->wild_mode) wilderness_gen_small();
1619 else wilderness_gen();
1622 /* Build a real level */
1625 okay = level_gen(&why);
1628 /* Extract the feeling */
1629 feeling = extract_feeling();
1631 /* Prevent object over-flow */
1632 if (o_max >= max_o_idx)
1636 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1638 why = "too many objects";
1645 /* Prevent monster over-flow */
1646 else if (m_max >= max_m_idx)
1650 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1652 why = "too many monsters";
1660 /* Mega-Hack -- "auto-scum" */
1661 else if ((auto_scum || ironman_autoscum) && (num < 100) &&
1662 !p_ptr->inside_quest &&
1663 !(d_info[dungeon_type].flags1 & DF1_BEGINNER) &&
1664 !p_ptr->enter_dungeon)
1666 /* Require "goodness" */
1667 if ((feeling > 9) ||
1668 ((dun_level >= 7) && (feeling > 8)) ||
1669 ((dun_level >= 15) && (feeling > 7)) ||
1670 ((dun_level >= 35) && (feeling > 6)) ||
1671 ((dun_level >= 70) && (feeling > 5)))
1673 /* Give message to cheaters */
1674 if (cheat_room || cheat_hear ||
1675 cheat_peek || cheat_xtra)
1681 why = "boring level";
1696 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1698 if (why) msg_format("Generation restarted (%s)", why);
1702 /* Wipe the objects */
1705 /* Wipe the monsters */
1709 /* Glow deep lava and building entrances */
1710 glow_deep_lava_and_bldg();
1713 p_ptr->enter_dungeon = FALSE;
1715 wipe_generate_cave_flags();