3 /* Purpose: Dungeon generation */
6 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
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 = (randint(num+1))/2;
138 else if (feat == FEAT_MORE)
140 /* No downstairs on quest levels */
141 if ((dun_level > 1) && quest_number(dun_level)) return TRUE;
143 /* No downstairs at the bottom */
144 if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE;
146 if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1))
147 more_num = (randint(num)+1)/2;
150 /* Place "num" stairs */
151 for (i = 0; i < num; i++)
153 /* Place some stairs */
154 for (flag = FALSE; !flag; )
156 /* Try several times, then decrease "walls" */
157 for (j = 0; !flag && j <= 3000; j++)
159 /* Pick a random grid */
160 y = randint(cur_hgt-2);
161 x = randint(cur_wid-2);
163 /* Access the grid */
166 /* Require "naked" floor grid */
167 if (!is_floor_grid(c_ptr) || pattern_tile(y,x) || c_ptr->o_idx || c_ptr->m_idx) continue;
169 /* Require a certain number of adjacent walls */
170 if (next_to_walls(y, x) < walls) continue;
172 /* Clear previous contents, add stairs */
173 if (i < more_num) c_ptr->feat = feat+0x07;
174 else c_ptr->feat = feat;
180 if (!flag) return FALSE;
181 /* Require fewer walls */
190 * Allocates some objects (using "place" and "type")
192 static void alloc_object(int set, int typ, int num)
198 /* Place some objects */
199 for (k = 0; k < num; k++)
201 /* Pick a "legal" spot */
202 while (dummy < SAFE_MAX_ATTEMPTS)
209 y = rand_int(cur_hgt);
210 x = rand_int(cur_wid);
214 /* Require "naked" floor grid */
215 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
217 /* Check for "room" */
218 room = (cave[y][x].info & CAVE_ROOM) ? TRUE : FALSE;
220 /* Require corridor? */
221 if ((set == ALLOC_SET_CORR) && room) continue;
224 if ((set == ALLOC_SET_ROOM) && !room) continue;
230 if (dummy >= SAFE_MAX_ATTEMPTS)
235 msg_print("·Ù¹ð¡ª¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
237 msg_print("Warning! Could not place object!");
245 /* Place something */
248 case ALLOC_TYP_RUBBLE:
251 cave[y][x].info &= ~(CAVE_FLOOR);
258 cave[y][x].info &= ~(CAVE_FLOOR);
268 case ALLOC_TYP_OBJECT:
270 place_object(y, x, FALSE, FALSE);
279 * Count the number of "corridor" grids adjacent to the given grid.
281 * Note -- Assumes "in_bounds(y1, x1)"
283 * XXX XXX This routine currently only counts actual "empty floor"
284 * grids which are not in rooms. We might want to also count stairs,
285 * open doors, closed doors, etc.
287 static int next_to_corr(int y1, int x1)
293 /* Scan adjacent grids */
294 for (i = 0; i < 4; i++)
296 /* Extract the location */
300 /* Access the grid */
303 /* Skip non floors */
304 if (!cave_floor_grid(c_ptr)) continue;
306 /* Skip non "empty floor" grids */
307 if (!is_floor_grid(c_ptr))
310 /* Skip grids inside rooms */
311 if (c_ptr->info & (CAVE_ROOM)) continue;
313 /* Count these grids */
317 /* Return the number of corridors */
323 * Determine if the given location is "between" two walls,
324 * and "next to" two corridor spaces. XXX XXX XXX
326 * Assumes "in_bounds(y, x)"
328 static bool possible_doorway(int y, int x)
330 /* Count the adjacent corridors */
331 if (next_to_corr(y, x) >= 2)
334 if ((cave[y-1][x].feat >= FEAT_MAGMA) &&
335 (cave[y+1][x].feat >= FEAT_MAGMA))
340 /* Check Horizontal */
341 if ((cave[y][x-1].feat >= FEAT_MAGMA) &&
342 (cave[y][x+1].feat >= FEAT_MAGMA))
354 * Places door at y, x position if at least 2 walls found
356 static void try_door(int y, int x)
359 if (!in_bounds(y, x)) return;
362 if (cave[y][x].feat >= FEAT_MAGMA) return;
364 /* Ignore room grids */
365 if (cave[y][x].info & (CAVE_ROOM)) return;
367 /* Occasional door (if allowed) */
368 if ((rand_int(100) < dun_tun_jct) && possible_doorway(y, x) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
371 place_random_door(y, x);
378 * Generate a new dungeon level
380 * Note that "dun_body" adds about 4000 bytes of memory to the stack.
382 static bool cave_gen(void)
384 int i, j, k, y, x, y1, x1;
386 int max_vault_ok = 2;
388 int feat1 = 0, feat2 = 0;
392 bool destroyed = FALSE;
393 bool empty_level = FALSE;
400 /* Fill the arrays of floors and walls in the good proportions */
401 for (i = 0; i < 100; i++)
403 int lim1, lim2, lim3;
405 lim1 = d_info[dungeon_type].floor_percent1;
406 lim2 = lim1 + d_info[dungeon_type].floor_percent2;
407 lim3 = lim2 + d_info[dungeon_type].floor_percent3;
410 floor_type[i] = d_info[dungeon_type].floor1;
412 floor_type[i] = d_info[dungeon_type].floor2;
414 floor_type[i] = d_info[dungeon_type].floor3;
416 lim1 = d_info[dungeon_type].fill_percent1;
417 lim2 = lim1 + d_info[dungeon_type].fill_percent2;
418 lim3 = lim2 + d_info[dungeon_type].fill_percent3;
420 fill_type[i] = d_info[dungeon_type].fill_type1;
422 fill_type[i] = d_info[dungeon_type].fill_type2;
424 fill_type[i] = d_info[dungeon_type].fill_type3;
427 /* Prepare allocation table */
428 get_mon_num_prep(get_monster_hook(), NULL);
430 feat_wall_outer = d_info[dungeon_type].outer_wall;
431 feat_wall_inner = d_info[dungeon_type].inner_wall;
432 feat_wall_solid = d_info[dungeon_type].outer_wall;
437 if (!max_panel_rows) max_vault_ok--;
438 if (!max_panel_cols) max_vault_ok--;
440 /* Randomize the dungeon creation values */
441 dun_rooms = rand_range(DUN_ROOMS_MIN, DUN_ROOMS_MAX);
442 dun_tun_rnd = rand_range(DUN_TUN_RND_MIN, DUN_TUN_RND_MAX);
443 dun_tun_chg = rand_range(DUN_TUN_CHG_MIN, DUN_TUN_CHG_MAX);
444 dun_tun_con = rand_range(DUN_TUN_CON_MIN, DUN_TUN_CON_MAX);
445 dun_tun_pen = rand_range(DUN_TUN_PEN_MIN, DUN_TUN_PEN_MAX);
446 dun_tun_jct = rand_range(DUN_TUN_JCT_MIN, DUN_TUN_JCT_MAX);
448 /* Empty arena levels */
449 if (ironman_empty_levels || ((d_info[dungeon_type].flags1 & DF1_ARENA) && (empty_levels && (randint(EMPTY_LEVEL) == 1))))
455 msg_print("¥¢¥ê¡¼¥Ê¥ì¥Ù¥ë");
457 msg_print("Arena level.");
463 /* Hack -- Start with basic granite */
464 for (y = 0; y < cur_hgt; y++)
466 for (x = 0; x < cur_wid; x++)
468 cave_type *c_ptr = &cave[y][x];
472 place_floor_grid(c_ptr);
476 /* Create granite wall */
477 place_extra_grid(c_ptr);
482 #ifdef ALLOW_CAVERNS_AND_LAKES
483 /* Possible "destroyed" level */
484 if ((dun_level > 30) && (rand_int(DUN_DEST*2) == 0) && (small_levels) && (d_info[dungeon_type].flags1 & DF1_DESTROY))
488 /* extra rubble around the place looks cool */
489 build_lake(3+rand_int(2));
492 /* Make a lake some of the time */
493 if ((rand_int(LAKE_LEVEL) == 0) && !empty_level && !destroyed &&
494 (d_info[dungeon_type].flags1 & DF1_LAKE_MASK))
497 if (d_info[dungeon_type].flags1 & DF1_LAKE_WATER) count += 3;
498 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA) count += 3;
499 if (d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) count += 3;
500 if (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) count += 3;
502 if (d_info[dungeon_type].flags1 & DF1_LAKE_LAVA)
505 if ((dun_level > 80) && (rand_int(count) < 2)) laketype = 1;
509 if (!laketype && (dun_level > 80) && one_in_(count)) laketype = 7;
513 if ((d_info[dungeon_type].flags1 & DF1_LAKE_WATER) && !laketype)
516 if ((dun_level > 50) && rand_int(count) < 2) laketype = 2;
520 if (!laketype && (dun_level > 50) && one_in_(count)) laketype = 6;
524 if ((d_info[dungeon_type].flags1 & DF1_LAKE_RUBBLE) && !laketype)
527 if ((dun_level > 35) && (rand_int(count) < 2)) laketype = 3;
530 /* Lake of rubble2 */
531 if (!laketype && (dun_level > 35) && one_in_(count)) laketype = 4;
536 if ((dun_level > 5) && (d_info[dungeon_type].flags1 & DF1_LAKE_TREE) && !laketype) laketype = 5;
542 msg_print("¸Ð¤òÀ¸À®¡£");
544 msg_print("Lake on the level.");
547 build_lake(laketype);
551 if ((dun_level > DUN_CAVERN) && !empty_level &&
552 (d_info[dungeon_type].flags1 & DF1_CAVERN) &&
553 (laketype == 0) && !destroyed && (randint(1000) < dun_level))
557 /* make a large fractal cave in the middle of the dungeon */
561 msg_print("ƶ·¢¤òÀ¸À®¡£");
563 msg_print("Cavern on level.");
569 #endif /* ALLOW_CAVERNS_AND_LAKES */
571 /* Hack -- No destroyed "quest" levels */
572 if (quest_number(dun_level)) destroyed = FALSE;
574 /* Actual maximum number of rooms on this level */
575 dun->row_rooms = cur_hgt / BLOCK_HGT;
576 dun->col_rooms = cur_wid / BLOCK_WID;
578 /* Initialize the room table */
579 for (y = 0; y < dun->row_rooms; y++)
581 for (x = 0; x < dun->col_rooms; x++)
583 dun->room_map[y][x] = FALSE;
588 /* No "crowded" rooms yet */
596 /* Build some rooms */
597 if (!(d_info[dungeon_type].flags1 & DF1_MAZE))
599 for (i = 0; i < dun_rooms; i++)
601 bool force_rooms = (ironman_rooms && !((d_info[dungeon_type].flags1 & DF1_BEGINNER) || (d_info[dungeon_type].flags1 & DF1_CHAMELEON)));
603 /* Pick a block for the room */
604 y = rand_int(dun->row_rooms);
605 x = rand_int(dun->col_rooms);
607 /* Align dungeon rooms */
608 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
610 /* Slide some rooms right */
611 if ((x % 3) == 0) x++;
613 /* Slide some rooms left */
614 if ((x % 3) == 2) x--;
617 /* Attempt an "unusual" room */
618 if (force_rooms || (rand_int(DUN_UNUSUAL) < dun_level))
620 /* Roll for room type */
623 k = (force_rooms ? 0 : rand_int(100));
624 if (force_rooms) break;
625 if ((d_info[dungeon_type].flags1 & DF1_NO_VAULT) && (k < 14)) continue;
629 /* Attempt a very unusual room */
630 if (force_rooms || (rand_int(DUN_UNUSUAL) < dun_level))
633 if (room_build(y, x, 8)) continue;
635 /* Type 8 -- Greater vault (4%) */
638 if (max_vault_ok > 1)
640 if (room_build(y, x, 8)) continue;
645 if (cheat_room) msg_print("µðÂç¤ÊÃϲ¼¼¼¤òµÑ²¼¤·¤Þ¤¹¡£");
647 if (cheat_room) msg_print("Refusing a greater vault.");
653 /* Type 7 -- Lesser vault (6%) */
656 if (max_vault_ok > 0)
658 if (room_build(y, x, 7)) continue;
663 if (cheat_room) msg_print("¾®¤µ¤ÊÃϲ¼¼¼¤òµÑ²¼¤·¤Þ¤¹¡£");
665 if (cheat_room) msg_print("Refusing a lesser vault.");
672 /* Type 10 -- Random vault (4%) */
673 if ((k < 14) && room_build(y, x, 10)) continue;
675 /* Type 5 -- Monster nest (8%) */
676 if ((k < 22) && room_build(y, x, 5)) continue;
678 /* Type 6 -- Monster pit (10%) */
679 if ((k < 32) && room_build(y, x, 6)) continue;
684 /* Type 2 -- Overlapping (25%) */
685 if ((k < 25) && room_build(y, x, 2)) continue;
687 /* Type 3 -- Cross room (25%) */
688 if ((k < 50) && room_build(y, x, 3)) continue;
690 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
692 if (room_build(y, x, 4)) continue;
696 /* Type 4 -- Large room (25%) */
697 if ((k < 75) && room_build(y, x, 4)) continue;
699 /* Type 11 -- Circular (10%) */
700 if ((k < 85) && room_build(y, x, 11)) continue;
702 /* Type 12 -- Crypt (15%) */
703 if ((k < 100) && room_build(y, x, 12)) continue;
707 /* The deeper you are, the more cavelike the rooms are */
710 /* No caves when a cavern exists: they look bad */
711 if (((k < dun_level) || (d_info[dungeon_type].flags1 & DF1_CAVE)) && (!cavern) && (!empty_level) && (laketype == 0) && !(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
713 /* Type 9 -- Fractal cave */
714 if (room_build(y, x, 9)) continue;
717 /* Attempt a "trivial" room */
719 if (room_build(y, x, 1)) continue;
723 /* Make a hole in the dungeon roof sometimes at level 1 */
724 if ((dun_level == 1) && terrain_streams)
726 while (randint(DUN_MOS_DEN) == 1)
728 place_trees(randint(cur_wid - 2), randint(cur_hgt - 2));
732 /* Destroy the level if necessary */
733 if (destroyed) destroy_level();
735 /* Hack -- Add some rivers */
736 if ((randint(3) == 1) && (randint(dun_level) > 5) && terrain_streams)
738 /* Choose water or lava */
739 if ((randint(MAX_DEPTH * 2) - 1 > dun_level) && (d_info[dungeon_type].flags1 & DF1_WATER_RIVER))
741 feat1 = FEAT_DEEP_WATER;
742 feat2 = FEAT_SHAL_WATER;
744 else if (d_info[dungeon_type].flags1 & DF1_LAVA_RIVER)
746 feat1 = FEAT_DEEP_LAVA;
747 feat2 = FEAT_SHAL_LAVA;
752 /* Only add river if matches lake type or if have no lake at all */
753 if ((((laketype == 1) && (feat1 == FEAT_DEEP_LAVA)) ||
754 ((laketype == 2) && (feat1 == FEAT_DEEP_WATER)) ||
755 (laketype == 0)) && feat1)
757 add_river(feat1, feat2);
762 /* Special boundary walls -- Top */
763 for (x = 0; x < cur_wid; x++)
765 cave_type *c_ptr = &cave[0][x];
767 /* Clear previous contents, add "solid" perma-wall */
768 c_ptr->feat = FEAT_PERM_SOLID;
769 c_ptr->info &= ~(CAVE_MASK);
772 /* Special boundary walls -- Bottom */
773 for (x = 0; x < cur_wid; x++)
775 cave_type *c_ptr = &cave[cur_hgt-1][x];
777 /* Clear previous contents, add "solid" perma-wall */
778 c_ptr->feat = FEAT_PERM_SOLID;
779 c_ptr->info &= ~(CAVE_MASK);
782 /* Special boundary walls -- Left */
783 for (y = 0; y < cur_hgt; y++)
785 cave_type *c_ptr = &cave[y][0];
787 /* Clear previous contents, add "solid" perma-wall */
788 c_ptr->feat = FEAT_PERM_SOLID;
789 c_ptr->info &= ~(CAVE_MASK);
792 /* Special boundary walls -- Right */
793 for (y = 0; y < cur_hgt; y++)
795 cave_type *c_ptr = &cave[y][cur_wid-1];
797 /* Clear previous contents, add "solid" perma-wall */
798 c_ptr->feat = FEAT_PERM_SOLID;
799 c_ptr->info &= ~(CAVE_MASK);
803 if (d_info[dungeon_type].flags1 & DF1_MAZE)
805 build_maze_vault(cur_wid/2-1, cur_hgt/2-1, cur_wid-4, cur_hgt-4, FALSE);
807 /* Place 3 or 4 down stairs near some walls */
808 if (!alloc_stairs(FEAT_MORE, rand_range(2, 3), 3)) return FALSE;
810 /* Place 1 or 2 up stairs near some walls */
811 if (!alloc_stairs(FEAT_LESS, 1, 3)) return FALSE;
815 /* Hack -- Scramble the room order */
816 for (i = 0; i < dun->cent_n; i++)
818 int pick1 = rand_int(dun->cent_n);
819 int pick2 = rand_int(dun->cent_n);
820 y1 = dun->cent[pick1].y;
821 x1 = dun->cent[pick1].x;
822 dun->cent[pick1].y = dun->cent[pick2].y;
823 dun->cent[pick1].x = dun->cent[pick2].x;
824 dun->cent[pick2].y = y1;
825 dun->cent[pick2].x = x1;
828 /* Start with no tunnel doors */
831 /* Hack -- connect the first room to the last room */
832 y = dun->cent[dun->cent_n-1].y;
833 x = dun->cent[dun->cent_n-1].x;
835 /* Connect all the rooms together */
836 for (i = 0; i < dun->cent_n; i++)
839 /* Reset the arrays */
843 /* Connect the room to the previous room */
844 if (randint(dun_level) > d_info[dungeon_type].tunnel_percent)
846 /* make cave-like tunnel */
847 build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
851 /* make normal tunnel */
852 build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
855 /* Turn the tunnel into corridor */
856 for (j = 0; j < dun->tunn_n; j++)
858 /* Access the grid */
862 /* Access the grid */
865 /* Clear previous contents (if not a lake), add a floor */
866 if ((c_ptr->feat < FEAT_DEEP_WATER) ||
867 (c_ptr->feat > FEAT_SHAL_LAVA))
869 place_floor_grid(c_ptr);
873 /* Apply the piercings that we found */
874 for (j = 0; j < dun->wall_n; j++)
876 /* Access the grid */
880 /* Access the grid */
883 /* Clear previous contents, add up floor */
884 place_floor_grid(c_ptr);
886 /* Occasional doorway */
887 if ((rand_int(100) < dun_tun_pen) && !(d_info[dungeon_type].flags1 & DF1_NO_DOORS))
889 /* Place a random door */
890 place_random_door(y, x);
894 /* Remember the "previous" room */
899 /* Place intersection doors */
900 for (i = 0; i < dun->door_n; i++)
902 /* Extract junction location */
906 /* Try placing doors */
913 /* Place 3 or 4 down stairs near some walls */
914 if (!alloc_stairs(FEAT_MORE, rand_range(3, 4), 3)) return FALSE;
916 /* Place 1 or 2 up stairs near some walls */
917 if (!alloc_stairs(FEAT_LESS, rand_range(1, 2), 3)) return FALSE;
923 if (d_info[dungeon_type].stream1)
925 /* Hack -- Add some magma streamers */
926 for (i = 0; i < DUN_STR_MAG; i++)
928 build_streamer(d_info[dungeon_type].stream1, DUN_STR_MC);
932 if (d_info[dungeon_type].stream2)
934 /* Hack -- Add some quartz streamers */
935 for (i = 0; i < DUN_STR_QUA; i++)
937 build_streamer(d_info[dungeon_type].stream2, DUN_STR_QC);
942 /* Handle the quest monster placements */
943 for (i = 0; i < max_quests; i++)
945 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
946 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
947 (quest[i].type == QUEST_TYPE_RANDOM)) &&
948 (quest[i].level == dun_level) && (dungeon_type == quest[i].dungeon) &&
949 !(quest[i].flags & QUEST_FLAG_PRESET))
951 monster_race *r_ptr = &r_info[quest[i].r_idx];
953 /* Hack -- "unique" monsters must be "unique" */
954 if ((r_ptr->flags1 & RF1_UNIQUE) &&
955 (r_ptr->cur_num >= r_ptr->max_num))
957 /* The unique is already dead */
958 quest[i].status = QUEST_STATUS_FINISHED;
964 for (j = 0; j < (quest[i].max_num - quest[i].cur_num); j++)
966 for (k = 0; k < SAFE_MAX_ATTEMPTS; k++)
968 /* Find an empty grid */
971 y = rand_int(cur_hgt);
972 x = rand_int(cur_wid);
974 /* Access the grid */
977 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
978 if (distance(y, x, py, px) < 10) continue;
982 if (r_ptr->flags1 & RF1_FRIENDS)
987 /* Try to place the monster */
988 if (place_monster_aux(y, x, quest[i].r_idx, FALSE, group, FALSE, FALSE, TRUE, TRUE))
995 /* Failure - Try again */
1005 /* Basic "amount" */
1006 k = (dun_level / 3);
1010 /* Pick a base number of monsters */
1011 i = d_info[dungeon_type].min_m_alloc_level;
1013 /* To make small levels a bit more playable */
1014 if (cur_hgt < MAX_HGT || cur_wid < MAX_WID)
1016 int small_tester = i;
1018 i = (i * cur_hgt) / MAX_HGT;
1019 i = (i * cur_wid) / MAX_WID;
1022 if (i > small_tester) i = small_tester;
1023 else if (cheat_hear)
1026 msg_format("¥â¥ó¥¹¥¿¡¼¿ô´ðËÜÃͤò %d ¤«¤é %d ¤Ë¸º¤é¤·¤Þ¤¹", small_tester, i);
1028 msg_format("Reduced monsters base from %d to %d", small_tester, i);
1036 /* Put some monsters in the dungeon */
1037 for (i = i + k; i > 0; i--)
1039 (void)alloc_monster(0, TRUE);
1042 /* Place some traps in the dungeon */
1043 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint(k));
1045 /* Put some rubble in corridors */
1046 alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint(k));
1048 /* Put some objects in rooms */
1049 alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ROOM, 3));
1051 /* Put some objects/gold in the dungeon */
1052 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, randnor(DUN_AMT_ITEM, 3));
1053 alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, randnor(DUN_AMT_GOLD, 3));
1055 /* Put an Artifact and Artifact Guardian is requested */
1056 if(d_info[dungeon_type].final_guardian && (d_info[dungeon_type].maxdepth == dun_level))
1062 /* Find a good position */
1065 /* Get a random spot */
1066 oy = randint(cur_hgt - 4) + 2;
1067 ox = randint(cur_wid - 4) + 2;
1069 /* Is it a good spot ? */
1070 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[d_info[dungeon_type].final_guardian]))
1072 /* Place the guardian */
1073 if (place_monster_aux(oy, ox, d_info[dungeon_type].final_guardian, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE)) break;
1080 if ((empty_level && ((randint(DARK_EMPTY) != 1) || (randint(100) > dun_level))) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS))
1083 for (y = 0; y < cur_hgt; y++)
1085 for (x = 0; x < cur_wid; x++)
1087 cave[y][x].info |= (CAVE_GLOW);
1092 /* Determine the character location */
1093 if (!new_player_spot())
1101 * Builds the arena after it is entered -KMW-
1103 static void build_arena(void)
1105 int yval, y_height, y_depth, xval, x_left, x_right;
1108 yval = SCREEN_HGT / 2;
1109 xval = SCREEN_WID / 2;
1110 y_height = yval - 10 + SCREEN_HGT;
1111 y_depth = yval + 10 + SCREEN_HGT;
1112 x_left = xval - 32 + SCREEN_WID;
1113 x_right = xval + 32 + SCREEN_WID;
1115 for (i = y_height; i <= y_height + 5; i++)
1116 for (j = x_left; j <= x_right; j++)
1118 cave[i][j].feat = FEAT_PERM_EXTRA;
1119 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1121 for (i = y_depth; i >= y_depth - 5; i--)
1122 for (j = x_left; j <= x_right; j++)
1124 cave[i][j].feat = FEAT_PERM_EXTRA;
1125 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1127 for (j = x_left; j <= x_left + 17; j++)
1128 for (i = y_height; i <= y_depth; i++)
1130 cave[i][j].feat = FEAT_PERM_EXTRA;
1131 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1133 for (j = x_right; j >= x_right - 17; j--)
1134 for (i = y_height; i <= y_depth; i++)
1136 cave[i][j].feat = FEAT_PERM_EXTRA;
1137 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1140 cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
1141 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1142 cave[y_depth-6][x_left+18].feat = FEAT_PERM_EXTRA;
1143 cave[y_depth-6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1144 cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
1145 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1146 cave[y_depth-6][x_right-18].feat = FEAT_PERM_EXTRA;
1147 cave[y_depth-6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1150 j = xval + SCREEN_WID;
1151 cave[i][j].feat = FEAT_BLDG_HEAD + 2;
1152 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1153 player_place(i + 1, j);
1158 * Town logic flow for generation of arena -KMW-
1160 static void arena_gen(void)
1163 int qy = SCREEN_HGT;
1164 int qx = SCREEN_WID;
1168 if ((turn % (20L * TOWN_DAWN)) < ((20L * TOWN_DAWN) / 2))
1175 /* Start with solid walls */
1176 for (y = 0; y < MAX_HGT; y++)
1178 for (x = 0; x < MAX_WID; x++)
1180 /* Create "solid" perma-wall */
1181 cave[y][x].feat = FEAT_PERM_SOLID;
1183 /* Illuminate and memorize the walls */
1184 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1188 /* Then place some floors */
1189 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1191 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1193 /* Create empty floor */
1194 cave[y][x].feat = FEAT_FLOOR;
1200 place_monster_aux(py + 5, px, arena_monsters[p_ptr->arena_number],
1201 FALSE, FALSE, FALSE, FALSE, TRUE, TRUE);
1207 * Builds the arena after it is entered -KMW-
1209 static void build_battle(void)
1211 int yval, y_height, y_depth, xval, x_left, x_right;
1214 yval = SCREEN_HGT / 2;
1215 xval = SCREEN_WID / 2;
1216 y_height = yval - 10 + SCREEN_HGT;
1217 y_depth = yval + 10 + SCREEN_HGT;
1218 x_left = xval - 32 + SCREEN_WID;
1219 x_right = xval + 32 + SCREEN_WID;
1221 for (i = y_height; i <= y_height + 5; i++)
1222 for (j = x_left; j <= x_right; j++)
1224 cave[i][j].feat = FEAT_PERM_EXTRA;
1225 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1227 for (i = y_depth; i >= y_depth - 3; i--)
1228 for (j = x_left; j <= x_right; j++)
1230 cave[i][j].feat = FEAT_PERM_EXTRA;
1231 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1233 for (j = x_left; j <= x_left + 17; j++)
1234 for (i = y_height; i <= y_depth; i++)
1236 cave[i][j].feat = FEAT_PERM_EXTRA;
1237 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1239 for (j = x_right; j >= x_right - 17; j--)
1240 for (i = y_height; i <= y_depth; i++)
1242 cave[i][j].feat = FEAT_PERM_EXTRA;
1243 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1246 cave[y_height+6][x_left+18].feat = FEAT_PERM_EXTRA;
1247 cave[y_height+6][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1248 cave[y_depth-4][x_left+18].feat = FEAT_PERM_EXTRA;
1249 cave[y_depth-4][x_left+18].info |= (CAVE_GLOW | CAVE_MARK);
1250 cave[y_height+6][x_right-18].feat = FEAT_PERM_EXTRA;
1251 cave[y_height+6][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1252 cave[y_depth-4][x_right-18].feat = FEAT_PERM_EXTRA;
1253 cave[y_depth-4][x_right-18].info |= (CAVE_GLOW | CAVE_MARK);
1256 j = xval + SCREEN_WID;
1257 cave[i][j].feat = FEAT_BLDG_HEAD + 3;
1258 cave[i][j].info |= (CAVE_GLOW | CAVE_MARK);
1264 * Town logic flow for generation of arena -KMW-
1266 static void battle_gen(void)
1269 int qy = SCREEN_HGT;
1270 int qx = SCREEN_WID;
1272 /* Start with solid walls */
1273 for (y = 0; y < MAX_HGT; y++)
1275 for (x = 0; x < MAX_WID; x++)
1277 /* Create "solid" perma-wall */
1278 cave[y][x].feat = FEAT_PERM_SOLID;
1280 /* Illuminate and memorize the walls */
1281 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1285 /* Then place some floors */
1286 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
1288 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
1290 /* Create empty floor */
1291 cave[y][x].feat = FEAT_FLOOR;
1299 place_monster_aux(py + 5 + (i/2)*4, px - 2 + (i%2)*4, battle_mon[i],
1300 FALSE, FALSE, FALSE, FALSE, TRUE, TRUE);
1301 set_friendly(&m_list[cave[py+5+(i/2)*4][px-2+(i%2)*4].m_idx]);
1303 for(i = 1; i < m_max; i++)
1305 monster_type *m_ptr = &m_list[i];
1307 if (!m_ptr->r_idx) continue;
1309 /* Hack -- Detect monster */
1310 m_ptr->mflag |= (MFLAG_MARK | MFLAG_SHOW);
1312 /* Update the monster */
1313 update_mon(i, FALSE);
1319 * Generate a quest level
1321 static void quest_gen(void)
1326 /* Start with perm walls */
1327 for (y = 0; y < cur_hgt; y++)
1329 for (x = 0; x < cur_wid; x++)
1331 cave[y][x].feat = FEAT_PERM_SOLID;
1335 /* Set the quest level */
1336 base_level = quest[p_ptr->inside_quest].level;
1337 dun_level = base_level;
1338 object_level = base_level;
1339 monster_level = base_level;
1341 if (record_stair) do_cmd_write_nikki(NIKKI_TO_QUEST, p_ptr->inside_quest, NULL);
1343 /* Prepare allocation table */
1344 get_mon_num_prep(get_monster_hook(), NULL);
1346 init_flags = INIT_CREATE_DUNGEON | INIT_ASSIGN;
1348 process_dungeon_file("q_info_j.txt", 0, 0, MAX_HGT, MAX_WID);
1351 /* Make a real level */
1352 static bool level_gen(cptr *why)
1354 int level_height, level_width;
1356 if ((always_small_levels || ironman_small_levels ||
1357 ((randint(SMALL_LEVEL) == 1) && small_levels) ||
1358 (d_info[dungeon_type].flags1 & DF1_BEGINNER) ||
1359 (d_info[dungeon_type].flags1 & DF1_SMALLEST)) &&
1360 !(d_info[dungeon_type].flags1 & DF1_BIG))
1364 msg_print("¾®¤µ¤Ê¥Õ¥í¥¢");
1366 msg_print("A 'small' dungeon level.");
1370 if (d_info[dungeon_type].flags1 & DF1_SMALLEST)
1375 else if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
1384 level_height = randint(MAX_HGT/SCREEN_HGT);
1385 level_width = randint(MAX_WID/SCREEN_WID);
1387 while ((level_height == MAX_HGT/SCREEN_HGT) &&
1388 (level_width == MAX_WID/SCREEN_WID));
1391 cur_hgt = level_height * SCREEN_HGT;
1392 cur_wid = level_width * SCREEN_WID;
1394 /* Determine number of panels */
1395 max_panel_rows = level_height * 2 - 2;
1396 max_panel_cols = level_width * 2 - 2;
1398 /* Assume illegal panel */
1399 panel_row = max_panel_rows;
1400 panel_col = max_panel_cols;
1403 msg_format("X:%d, Y:%d.", max_panel_cols, max_panel_rows);
1411 /* Determine number of panels */
1412 max_panel_rows = (cur_hgt / SCREEN_HGT) * 2 - 2;
1413 max_panel_cols = (cur_wid / SCREEN_WID) * 2 - 2;
1415 /* Assume illegal panel */
1416 panel_row = max_panel_rows;
1417 panel_col = max_panel_cols;
1420 /* Make a dungeon */
1424 *why = "¥À¥ó¥¸¥ç¥óÀ¸À®¤Ë¼ºÇÔ";
1426 *why = "could not place player";
1434 static byte extract_feeling(void)
1436 /* Hack -- no feeling in the town */
1437 if (!dun_level) return 0;
1439 /* Hack -- Have a special feeling sometimes */
1440 if (good_item_flag && !preserve_mode) return 1;
1442 if (rating > 100) return 2;
1443 if (rating > 80) return 3;
1444 if (rating > 60) return 4;
1445 if (rating > 40) return 5;
1446 if (rating > 30) return 6;
1447 if (rating > 20) return 7;
1448 if (rating > 10) return 8;
1449 if (rating > 0) return 9;
1451 if((turn - old_turn) > 100000L)
1452 chg_virtue(V_PATIENCE, 1);
1458 static void place_pet(void)
1462 if (p_ptr->wild_mode)
1467 for (i = 0; i < max_num; i++)
1471 if (!(party_mon[i].r_idx)) continue;
1477 p_ptr->riding = m_idx;
1488 for(d = 1; d < 6; d++)
1490 for(j = 1000; j > 0; j--)
1492 scatter(&cy, &cx, py, px, d, 0);
1493 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !((cy == py) && (cx == px))) break;
1497 if (d == 6 || p_ptr->inside_arena || p_ptr->inside_battle)
1505 monster_type *m_ptr = &m_list[m_idx];
1506 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1508 cave[cy][cx].m_idx = m_idx;
1509 m_ptr->r_idx = party_mon[i].r_idx;
1512 m_ptr->cdis = party_mon[i].cdis;
1513 m_ptr->mflag = party_mon[i].mflag;
1514 m_ptr->mflag2 = party_mon[i].mflag2;
1516 m_ptr->hp = party_mon[i].hp;
1517 m_ptr->maxhp = party_mon[i].maxhp;
1518 m_ptr->max_maxhp = party_mon[i].max_maxhp;
1519 m_ptr->mspeed = party_mon[i].mspeed;
1520 m_ptr->fast = party_mon[i].fast;
1521 m_ptr->slow = party_mon[i].slow;
1522 m_ptr->stunned = party_mon[i].stunned;
1523 m_ptr->confused = party_mon[i].confused;
1524 m_ptr->monfear = party_mon[i].monfear;
1525 m_ptr->invulner = party_mon[i].invulner;
1526 m_ptr->smart = party_mon[i].smart;
1528 m_ptr->nickname = party_mon[i].nickname;
1529 m_ptr->energy = party_mon[i].energy;
1530 m_ptr->exp = party_mon[i].exp;
1533 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
1535 /* Monster is still being nice */
1536 m_ptr->mflag |= (MFLAG_NICE);
1538 /* Must repair monsters */
1539 repair_monsters = TRUE;
1542 /* Update the monster */
1543 update_mon(m_idx, TRUE);
1548 /* Hack -- Count the number of "reproducers" */
1549 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
1551 /* Hack -- Notice new multi-hued monsters */
1552 if (r_ptr->flags1 & RF1_ATTR_MULTI) shimmer_monsters = TRUE;
1558 monster_desc(m_name, &party_mon[i], 0);
1560 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
1562 msg_format("You have lost sight of %s.", m_name);
1564 if (record_named_pet && party_mon[i].nickname)
1566 monster_desc(m_name, &party_mon[i], 0x08);
1567 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
1574 * Generates a random dungeon level -RAK-
1576 * Hack -- regenerate any "overflow" levels
1578 * Hack -- allow auto-scumming via a gameplay option.
1580 void generate_cave(void)
1585 /* The dungeon is not ready */
1586 character_dungeon = FALSE;
1589 for (num = 0; TRUE; num++)
1596 /* XXX XXX XXX XXX */
1600 /* Start with a blank cave */
1601 for (y = 0; y < MAX_HGT; y++)
1603 for (x = 0; x < MAX_WID; x++)
1606 cave[y][x].info = 0;
1609 cave[y][x].feat = 0;
1612 cave[y][x].o_idx = 0;
1615 cave[y][x].m_idx = 0;
1618 cave[y][x].mimic = 0;
1621 cave[y][x].cost = 0;
1622 cave[y][x].dist = 0;
1623 cave[y][x].when = 0;
1627 /* Mega-Hack -- no player yet */
1630 /* Mega-Hack -- no panel yet */
1636 /* Set the base level */
1637 base_level = dun_level;
1639 /* Reset the monster generation level */
1640 monster_level = base_level;
1642 /* Reset the object generation level */
1643 object_level = base_level;
1645 /* Nothing special here yet */
1646 good_item_flag = FALSE;
1648 /* Nothing good here yet */
1651 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;
1653 ambush_flag = FALSE;
1655 /* Fill the arrays of floors and walls in the good proportions */
1656 for (i = 0; i < 100; i++)
1658 int lim1, lim2, lim3;
1660 lim1 = d_info[0].floor_percent1;
1661 lim2 = lim1 + d_info[0].floor_percent2;
1662 lim3 = lim2 + d_info[0].floor_percent3;
1665 floor_type[i] = d_info[0].floor1;
1667 floor_type[i] = d_info[0].floor2;
1669 floor_type[i] = d_info[0].floor3;
1671 lim1 = d_info[0].fill_percent1;
1672 lim2 = lim1 + d_info[0].fill_percent2;
1673 lim3 = lim2 + d_info[0].fill_percent3;
1675 fill_type[i] = d_info[0].fill_type1;
1677 fill_type[i] = d_info[0].fill_type2;
1679 fill_type[i] = d_info[0].fill_type3;
1682 /* Build the arena -KMW- */
1683 if (p_ptr->inside_arena)
1689 /* Build the battle -KMW- */
1690 else if (p_ptr->inside_battle)
1696 else if (p_ptr->inside_quest)
1701 /* Build the town */
1702 else if (!dun_level)
1704 /* Make the wilderness */
1705 if (p_ptr->wild_mode) wilderness_gen_small();
1706 else wilderness_gen();
1709 /* Build a real level */
1712 okay = level_gen(&why);
1715 /* Extract the feeling */
1716 feeling = extract_feeling();
1718 /* Prevent object over-flow */
1719 if (o_max >= max_o_idx)
1723 why = "¥¢¥¤¥Æ¥à¤¬Â¿¤¹¤®¤ë";
1725 why = "too many objects";
1732 /* Prevent monster over-flow */
1733 else if (m_max >= max_m_idx)
1737 why = "¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë";
1739 why = "too many monsters";
1747 /* Mega-Hack -- "auto-scum" */
1748 else if ((auto_scum || ironman_autoscum) && (num < 100) &&
1749 !p_ptr->inside_quest && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1751 /* Require "goodness" */
1752 if ((feeling > 9) ||
1753 ((dun_level >= 7) && (feeling > 8)) ||
1754 ((dun_level >= 15) && (feeling > 7)) ||
1755 ((dun_level >= 35) && (feeling > 6)) ||
1756 ((dun_level >= 70) && (feeling > 5)))
1758 /* Give message to cheaters */
1759 if (cheat_room || cheat_hear ||
1760 cheat_peek || cheat_xtra)
1766 why = "boring level";
1781 if (why) msg_format("À¸À®¤ä¤êľ¤·(%s)", why);
1783 if (why) msg_format("Generation restarted (%s)", why);
1787 /* Wipe the objects */
1790 /* Wipe the monsters */
1794 for (y = 1; y < cur_hgt - 1; y++)
1796 for (x = 1; x < cur_wid - 1; x++)
1798 if ((cave[y][x].feat == FEAT_DEEP_LAVA))
1801 for (i = 0; i < 9; i++)
1803 cave[y+ddy_ddd[i]][x+ddx_ddd[i]].info |= CAVE_GLOW;
1811 /* The dungeon is ready */
1812 character_dungeon = TRUE;
1814 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) wiz_lite(TRUE, (bool)(p_ptr->pclass == CLASS_NINJA));
1816 /* Remember when this level was "created" */