3 * Purpose: make rooms. Used by generate.c when creating dungeons.
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
9 * This software may be copied and distributed for educational, research,
10 * and not for profit purposes provided that this copyright and statement
11 * are included in all such copies. Other copyrights may also apply.
21 * [from SAngband (originally from OAngband)]
23 * Table of values that control how many times each type of room will
24 * appear. Each type of room has its own row, and each column
25 * corresponds to dungeon levels 0, 10, 20, and so on. The final
26 * value is the minimum depth the room can appear at. -LM-
28 * Level 101 and below use the values for level 100.
30 * Rooms with lots of monsters or loot may not be generated if the
31 * object or monster lists are already nearly full. Rooms will not
32 * appear above their minimum depth. Tiny levels will not have space
33 * for all the rooms you ask for.
35 static room_info_type room_info_normal[ROOM_T_MAX] =
38 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
40 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
41 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
42 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
43 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
44 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
45 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
46 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
47 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
48 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
49 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
50 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
51 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
52 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
53 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
57 /* Build rooms in descending order of difficulty. */
58 static byte room_build_order[ROOM_T_MAX] = {
76 static void place_locked_door(int y, int x)
78 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
80 place_floor_bold(y, x);
84 set_cave_feat(y, x, FEAT_DOOR_HEAD+randint1(7));
85 cave[y][x].info &= ~(CAVE_FLOOR);
89 static void place_secret_door(int y, int x)
91 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
93 place_floor_bold(y, x);
97 cave_type *c_ptr = &cave[y][x];
99 /* Create secret door */
100 place_closed_door(y, x);
102 /* Hide by inner wall because this is used in rooms only */
103 c_ptr->mimic = feat_wall_inner;
105 /* Floor type terrain cannot hide a door */
106 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
108 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
110 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
115 c_ptr->info &= ~(CAVE_FLOOR);
120 * This funtion makes a very small room centred at (x0, y0)
121 * This is used in crypts, and random elemental vaults.
123 * Note - this should be used only on allocated regions
124 * within another room.
126 static void build_small_room(int x0, int y0)
130 for (y = y0 - 1; y <= y0 + 1; y++)
132 place_inner_bold(y, x0 - 1);
133 place_inner_bold(y, x0 + 1);
136 for (x = x0 - 1; x <= x0 + 1; x++)
138 place_inner_bold(y0 - 1, x);
139 place_inner_bold(y0 + 1, x);
142 /* Place a secret door on one side */
145 case 0: place_secret_door(y0, x0 - 1); break;
146 case 1: place_secret_door(y0, x0 + 1); break;
147 case 2: place_secret_door(y0 - 1, x0); break;
148 case 3: place_secret_door(y0 + 1, x0); break;
151 /* Clear mimic type */
152 cave[y0][x0].mimic = 0;
154 /* Add inner open space */
155 place_floor_bold(y0, x0);
160 * This function tunnels around a room if
161 * it will cut off part of a cave system.
163 static void check_room_boundary(int x1, int y1, int x2, int y2)
166 bool old_is_floor, new_is_floor;
172 old_is_floor = get_is_floor(x1 - 1, y1);
175 * Count the number of floor-wall boundaries around the room
176 * Note: diagonal squares are ignored since the player can move diagonally
177 * to bypass these if needed.
180 /* Above the top boundary */
181 for (x = x1; x <= x2; x++)
183 new_is_floor = get_is_floor(x, y1 - 1);
185 /* Increment counter if they are different */
186 if (new_is_floor != old_is_floor) count++;
188 old_is_floor = new_is_floor;
192 for (y = y1; y <= y2; y++)
194 new_is_floor = get_is_floor(x2 + 1, y);
196 /* increment counter if they are different */
197 if (new_is_floor != old_is_floor) count++;
199 old_is_floor = new_is_floor;
202 /* Bottom boundary */
203 for (x = x2; x >= x1; x--)
205 new_is_floor = get_is_floor(x, y2 + 1);
207 /* increment counter if they are different */
208 if (new_is_floor != old_is_floor) count++;
210 old_is_floor = new_is_floor;
214 for (y = y2; y >= y1; y--)
216 new_is_floor = get_is_floor(x1 - 1, y);
218 /* increment counter if they are different */
219 if (new_is_floor != old_is_floor) count++;
221 old_is_floor = new_is_floor;
224 /* If all the same, or only one connection exit. */
225 if (count <= 2) return;
228 /* Tunnel around the room so to prevent problems with caves */
229 for (y = y1; y <= y2; y++)
231 for (x = x1; x <= x2; x++)
240 * Helper function for find_space().
242 * Is this a good location?
244 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
246 int by1, bx1, by2, bx2, by, bx;
248 /* Itty-bitty rooms must shift about within their rectangle */
251 if ((blocks_wide == 2) && (block_x % 3) == 2)
255 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
256 else if ((blocks_wide % 3) == 0)
258 /* Must be aligned to the left edge of a 11x33 rectangle. */
259 if ((block_x % 3) != 0)
264 * Big rooms that do not have a width divisible by 3 must be
265 * aligned towards the edge of the dungeon closest to them.
269 /* Shift towards left edge of dungeon. */
270 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
272 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
274 if ((block_x % 3) == 1)
278 /* Shift toward right edge of dungeon. */
281 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
283 if ((block_x % 3) == 1)
291 by2 = block_y + blocks_high;
292 bx2 = block_x + blocks_wide;
294 /* Never run off the screen */
295 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
296 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
298 /* Verify available space */
299 for (by = by1; by < by2; by++)
301 for (bx = bx1; bx < bx2; bx++)
303 if (dun->room_map[by][bx])
310 /* This location is okay */
316 * Find a good spot for the next room. -LM-
318 * Find and allocate a free space in the dungeon large enough to hold
319 * the room calling this function.
321 * We allocate space in 11x11 blocks, but want to make sure that rooms
322 * align neatly on the standard screen. Therefore, we make them use
323 * blocks in few 11x33 rectangles as possible.
325 * Be careful to include the edges of the room in height and width!
327 * Return TRUE and values for the center of the room if all went well.
328 * Otherwise, return FALSE.
330 static bool find_space(int *y, int *x, int height, int width)
332 int candidates, pick;
333 int by, bx, by1, bx1, by2, bx2;
334 int block_y = 0, block_x = 0;
337 /* Find out how many blocks we need. */
338 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
339 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
341 /* There are no way to allocate such huge space */
342 if (dun->row_rooms < blocks_high) return FALSE;
343 if (dun->col_rooms < blocks_wide) return FALSE;
346 /* Sometimes, little rooms like to have more space. */
347 if (blocks_wide == 2)
349 if (one_in_(3)) blocks_wide = 3;
351 else if (blocks_wide == 1)
353 if (one_in_(2)) blocks_wide = rand_range(2, 3);
360 /* Count the number of varid places */
361 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
363 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
365 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
367 /* Find a varid place */
380 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
382 /* Choose a random one */
383 pick = randint1(candidates);
386 /* NO_CAVE dungeon (Castle) */
389 /* Always choose the center one */
390 pick = candidates/2 + 1;
393 /* Pick up the choosen location */
394 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
396 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
398 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
402 /* This one is picked? */
413 by2 = block_y + blocks_high;
414 bx2 = block_x + blocks_wide;
417 * It is *extremely* important that the following calculation
418 * be *exactly* correct to prevent memory errors
421 /* Acquire the location of the room */
422 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
423 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
425 /* Save the room location */
426 if (dun->cent_n < CENT_MAX)
428 dun->cent[dun->cent_n].y = *y;
429 dun->cent[dun->cent_n].x = *x;
433 /* Reserve some blocks. */
434 for (by = by1; by < by2; by++)
436 for (bx = bx1; bx < bx2; bx++)
438 dun->room_map[by][bx] = TRUE;
444 * Hack- See if room will cut off a cavern.
446 * If so, fix by tunneling outside the room in such a
447 * way as to connect the caves.
449 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
459 * Room building routines.
465 * 4 -- large room with features
469 * 8 -- greater vaults
471 * 10 -- random vaults
472 * 11 -- circular rooms
474 * 13 -- trapped monster pits
480 * Type 1 -- normal rectangular rooms
482 static bool build_type1(void)
484 int y, x, y2, x2, yval, xval;
485 int y1, x1, xsize, ysize;
491 /* Pick a room size */
500 /* Find and reserve some space in the dungeon. Get center of room. */
501 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
503 /* Choose lite or dark */
504 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
507 /* Get corner values */
508 y1 = yval - ysize / 2;
509 x1 = xval - xsize / 2;
510 y2 = yval + (ysize - 1) / 2;
511 x2 = xval + (xsize - 1) / 2;
514 /* Place a full floor under the room */
515 for (y = y1 - 1; y <= y2 + 1; y++)
517 for (x = x1 - 1; x <= x2 + 1; x++)
520 place_floor_grid(c_ptr);
521 c_ptr->info |= (CAVE_ROOM);
522 if (light) c_ptr->info |= (CAVE_GLOW);
526 /* Walls around the room */
527 for (y = y1 - 1; y <= y2 + 1; y++)
529 c_ptr = &cave[y][x1 - 1];
530 place_outer_grid(c_ptr);
531 c_ptr = &cave[y][x2 + 1];
532 place_outer_grid(c_ptr);
534 for (x = x1 - 1; x <= x2 + 1; x++)
536 c_ptr = &cave[y1 - 1][x];
537 place_outer_grid(c_ptr);
538 c_ptr = &cave[y2 + 1][x];
539 place_outer_grid(c_ptr);
543 /* Hack -- Occasional pillar room */
546 for (y = y1; y <= y2; y += 2)
548 for (x = x1; x <= x2; x += 2)
551 place_inner_grid(c_ptr);
556 /* Hack -- Occasional room with four pillars */
557 else if (one_in_(20))
559 if ((y1 + 4 < y2) && (x1 + 4 < x2))
561 c_ptr = &cave[y1 + 1][x1 + 1];
562 place_inner_grid(c_ptr);
564 c_ptr = &cave[y1 + 1][x2 - 1];
565 place_inner_grid(c_ptr);
567 c_ptr = &cave[y2 - 1][x1 + 1];
568 place_inner_grid(c_ptr);
570 c_ptr = &cave[y2 - 1][x2 - 1];
571 place_inner_grid(c_ptr);
575 /* Hack -- Occasional ragged-edge room */
576 else if (one_in_(50))
578 for (y = y1 + 2; y <= y2 - 2; y += 2)
580 c_ptr = &cave[y][x1];
581 place_inner_grid(c_ptr);
582 c_ptr = &cave[y][x2];
583 place_inner_grid(c_ptr);
585 for (x = x1 + 2; x <= x2 - 2; x += 2)
587 c_ptr = &cave[y1][x];
588 place_inner_grid(c_ptr);
589 c_ptr = &cave[y2][x];
590 place_inner_grid(c_ptr);
593 /* Hack -- Occasional divided room */
594 else if (one_in_(50))
596 if (randint1(100) < 50)
598 /* Horizontal wall */
599 for (x = x1; x <= x2; x++)
601 place_inner_bold(yval, x);
604 /* Prevent edge of wall from being tunneled */
605 place_solid_bold(yval, x1 - 1);
606 place_solid_bold(yval, x2 + 1);
611 for (y = y1; y <= y2; y++)
613 place_inner_bold(y, xval);
616 /* Prevent edge of wall from being tunneled */
617 place_solid_bold(y1 - 1, xval);
618 place_solid_bold(y2 + 1, xval);
621 place_random_door(yval, xval, TRUE);
629 * Type 2 -- Overlapping rectangular rooms
631 static bool build_type2(void)
633 int y, x, xval, yval;
634 int y1a, x1a, y2a, x2a;
635 int y1b, x1b, y2b, x2b;
639 /* Find and reserve some space in the dungeon. Get center of room. */
640 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
642 /* Choose lite or dark */
643 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
645 /* Determine extents of the first room */
646 y1a = yval - randint1(4);
647 y2a = yval + randint1(3);
648 x1a = xval - randint1(11);
649 x2a = xval + randint1(10);
651 /* Determine extents of the second room */
652 y1b = yval - randint1(3);
653 y2b = yval + randint1(4);
654 x1b = xval - randint1(10);
655 x2b = xval + randint1(11);
658 /* Place a full floor for room "a" */
659 for (y = y1a - 1; y <= y2a + 1; y++)
661 for (x = x1a - 1; x <= x2a + 1; x++)
664 place_floor_grid(c_ptr);
665 c_ptr->info |= (CAVE_ROOM);
666 if (light) c_ptr->info |= (CAVE_GLOW);
670 /* Place a full floor for room "b" */
671 for (y = y1b - 1; y <= y2b + 1; y++)
673 for (x = x1b - 1; x <= x2b + 1; x++)
676 place_floor_grid(c_ptr);
677 c_ptr->info |= (CAVE_ROOM);
678 if (light) c_ptr->info |= (CAVE_GLOW);
683 /* Place the walls around room "a" */
684 for (y = y1a - 1; y <= y2a + 1; y++)
686 c_ptr = &cave[y][x1a - 1];
687 place_outer_grid(c_ptr);
688 c_ptr = &cave[y][x2a + 1];
689 place_outer_grid(c_ptr);
691 for (x = x1a - 1; x <= x2a + 1; x++)
693 c_ptr = &cave[y1a - 1][x];
694 place_outer_grid(c_ptr);
695 c_ptr = &cave[y2a + 1][x];
696 place_outer_grid(c_ptr);
699 /* Place the walls around room "b" */
700 for (y = y1b - 1; y <= y2b + 1; y++)
702 c_ptr = &cave[y][x1b - 1];
703 place_outer_grid(c_ptr);
704 c_ptr = &cave[y][x2b + 1];
705 place_outer_grid(c_ptr);
707 for (x = x1b - 1; x <= x2b + 1; x++)
709 c_ptr = &cave[y1b - 1][x];
710 place_outer_grid(c_ptr);
711 c_ptr = &cave[y2b + 1][x];
712 place_outer_grid(c_ptr);
717 /* Replace the floor for room "a" */
718 for (y = y1a; y <= y2a; y++)
720 for (x = x1a; x <= x2a; x++)
723 place_floor_grid(c_ptr);
727 /* Replace the floor for room "b" */
728 for (y = y1b; y <= y2b; y++)
730 for (x = x1b; x <= x2b; x++)
733 place_floor_grid(c_ptr);
743 * Type 3 -- Cross shaped rooms
745 * Builds a room at a row, column coordinate
747 * Room "a" runs north/south, and Room "b" runs east/east
748 * So the "central pillar" runs from x1a, y1b to x2a, y2b.
750 * Note that currently, the "center" is always 3x3, but I think that
751 * the code below will work (with "bounds checking") for 5x5, or even
752 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.
754 static bool build_type3(void)
756 int y, x, dy, dx, wy, wx;
757 int y1a, x1a, y2a, x2a;
758 int y1b, x1b, y2b, x2b;
764 /* Find and reserve some space in the dungeon. Get center of room. */
765 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
768 /* Choose lite or dark */
769 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
771 /* For now, always 3x3 */
774 /* Pick max vertical size (at most 4) */
775 dy = rand_range(3, 4);
777 /* Pick max horizontal size (at most 15) */
778 dx = rand_range(3, 11);
781 /* Determine extents of the north/south room */
787 /* Determine extents of the east/west room */
794 /* Place a full floor for room "a" */
795 for (y = y1a - 1; y <= y2a + 1; y++)
797 for (x = x1a - 1; x <= x2a + 1; x++)
800 place_floor_grid(c_ptr);
801 c_ptr->info |= (CAVE_ROOM);
802 if (light) c_ptr->info |= (CAVE_GLOW);
806 /* Place a full floor for room "b" */
807 for (y = y1b - 1; y <= y2b + 1; y++)
809 for (x = x1b - 1; x <= x2b + 1; x++)
812 place_floor_grid(c_ptr);
813 c_ptr->info |= (CAVE_ROOM);
814 if (light) c_ptr->info |= (CAVE_GLOW);
819 /* Place the walls around room "a" */
820 for (y = y1a - 1; y <= y2a + 1; y++)
822 c_ptr = &cave[y][x1a - 1];
823 place_outer_grid(c_ptr);
824 c_ptr = &cave[y][x2a + 1];
825 place_outer_grid(c_ptr);
827 for (x = x1a - 1; x <= x2a + 1; x++)
829 c_ptr = &cave[y1a - 1][x];
830 place_outer_grid(c_ptr);
831 c_ptr = &cave[y2a + 1][x];
832 place_outer_grid(c_ptr);
835 /* Place the walls around room "b" */
836 for (y = y1b - 1; y <= y2b + 1; y++)
838 c_ptr = &cave[y][x1b - 1];
839 place_outer_grid(c_ptr);
840 c_ptr = &cave[y][x2b + 1];
841 place_outer_grid(c_ptr);
843 for (x = x1b - 1; x <= x2b + 1; x++)
845 c_ptr = &cave[y1b - 1][x];
846 place_outer_grid(c_ptr);
847 c_ptr = &cave[y2b + 1][x];
848 place_outer_grid(c_ptr);
852 /* Replace the floor for room "a" */
853 for (y = y1a; y <= y2a; y++)
855 for (x = x1a; x <= x2a; x++)
858 place_floor_grid(c_ptr);
862 /* Replace the floor for room "b" */
863 for (y = y1b; y <= y2b; y++)
865 for (x = x1b; x <= x2b; x++)
868 place_floor_grid(c_ptr);
874 /* Special features (3/4) */
877 /* Large solid middle pillar */
880 for (y = y1b; y <= y2b; y++)
882 for (x = x1a; x <= x2a; x++)
885 place_inner_grid(c_ptr);
891 /* Inner treasure vault */
894 /* Build the vault */
895 for (y = y1b; y <= y2b; y++)
897 c_ptr = &cave[y][x1a];
898 place_inner_grid(c_ptr);
899 c_ptr = &cave[y][x2a];
900 place_inner_grid(c_ptr);
902 for (x = x1a; x <= x2a; x++)
904 c_ptr = &cave[y1b][x];
905 place_inner_grid(c_ptr);
906 c_ptr = &cave[y2b][x];
907 place_inner_grid(c_ptr);
910 /* Place a secret door on the inner room */
913 case 0: place_secret_door(y1b, xval); break;
914 case 1: place_secret_door(y2b, xval); break;
915 case 2: place_secret_door(yval, x1a); break;
916 case 3: place_secret_door(yval, x2a); break;
919 /* Place a treasure in the vault */
920 place_object(yval, xval, 0L);
922 /* Let's guard the treasure well */
923 vault_monsters(yval, xval, randint0(2) + 3);
925 /* Traps naturally */
926 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
934 /* Occasionally pinch the center shut */
937 /* Pinch the east/west sides */
938 for (y = y1b; y <= y2b; y++)
940 if (y == yval) continue;
941 c_ptr = &cave[y][x1a - 1];
942 place_inner_grid(c_ptr);
943 c_ptr = &cave[y][x2a + 1];
944 place_inner_grid(c_ptr);
947 /* Pinch the north/south sides */
948 for (x = x1a; x <= x2a; x++)
950 if (x == xval) continue;
951 c_ptr = &cave[y1b - 1][x];
952 place_inner_grid(c_ptr);
953 c_ptr = &cave[y2b + 1][x];
954 place_inner_grid(c_ptr);
957 /* Sometimes shut using secret doors */
960 place_secret_door(yval, x1a - 1);
961 place_secret_door(yval, x2a + 1);
962 place_secret_door(y1b - 1, xval);
963 place_secret_door(y2b + 1, xval);
967 /* Occasionally put a "plus" in the center */
970 c_ptr = &cave[yval][xval];
971 place_inner_grid(c_ptr);
972 c_ptr = &cave[y1b][xval];
973 place_inner_grid(c_ptr);
974 c_ptr = &cave[y2b][xval];
975 place_inner_grid(c_ptr);
976 c_ptr = &cave[yval][x1a];
977 place_inner_grid(c_ptr);
978 c_ptr = &cave[yval][x2a];
979 place_inner_grid(c_ptr);
982 /* Occasionally put a pillar in the center */
985 c_ptr = &cave[yval][xval];
986 place_inner_grid(c_ptr);
998 * Type 4 -- Large room with inner features
1000 * Possible sub-types:
1001 * 1 - Just an inner room with one door
1002 * 2 - An inner room within an inner room
1003 * 3 - An inner room with pillar(s)
1004 * 4 - Inner room has a maze
1005 * 5 - A set of four inner rooms
1007 static bool build_type4(void)
1010 int y2, x2, tmp, yval, xval;
1015 /* Find and reserve some space in the dungeon. Get center of room. */
1016 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
1018 /* Choose lite or dark */
1019 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1027 /* Place a full floor under the room */
1028 for (y = y1 - 1; y <= y2 + 1; y++)
1030 for (x = x1 - 1; x <= x2 + 1; x++)
1032 c_ptr = &cave[y][x];
1033 place_floor_grid(c_ptr);
1034 c_ptr->info |= (CAVE_ROOM);
1035 if (light) c_ptr->info |= (CAVE_GLOW);
1040 for (y = y1 - 1; y <= y2 + 1; y++)
1042 c_ptr = &cave[y][x1 - 1];
1043 place_outer_grid(c_ptr);
1044 c_ptr = &cave[y][x2 + 1];
1045 place_outer_grid(c_ptr);
1047 for (x = x1 - 1; x <= x2 + 1; x++)
1049 c_ptr = &cave[y1 - 1][x];
1050 place_outer_grid(c_ptr);
1051 c_ptr = &cave[y2 + 1][x];
1052 place_outer_grid(c_ptr);
1056 /* The inner room */
1062 /* The inner walls */
1063 for (y = y1 - 1; y <= y2 + 1; y++)
1065 c_ptr = &cave[y][x1 - 1];
1066 place_inner_grid(c_ptr);
1067 c_ptr = &cave[y][x2 + 1];
1068 place_inner_grid(c_ptr);
1070 for (x = x1 - 1; x <= x2 + 1; x++)
1072 c_ptr = &cave[y1 - 1][x];
1073 place_inner_grid(c_ptr);
1074 c_ptr = &cave[y2 + 1][x];
1075 place_inner_grid(c_ptr);
1079 /* Inner room variations */
1080 switch (randint1(5))
1082 /* Just an inner room with a monster */
1085 /* Place a secret door */
1086 switch (randint1(4))
1088 case 1: place_secret_door(y1 - 1, xval); break;
1089 case 2: place_secret_door(y2 + 1, xval); break;
1090 case 3: place_secret_door(yval, x1 - 1); break;
1091 case 4: place_secret_door(yval, x2 + 1); break;
1094 /* Place a monster in the room */
1095 vault_monsters(yval, xval, 1);
1100 /* Treasure Vault (with a door) */
1103 /* Place a secret door */
1104 switch (randint1(4))
1106 case 1: place_secret_door(y1 - 1, xval); break;
1107 case 2: place_secret_door(y2 + 1, xval); break;
1108 case 3: place_secret_door(yval, x1 - 1); break;
1109 case 4: place_secret_door(yval, x2 + 1); break;
1112 /* Place another inner room */
1113 for (y = yval - 1; y <= yval + 1; y++)
1115 for (x = xval - 1; x <= xval + 1; x++)
1117 if ((x == xval) && (y == yval)) continue;
1118 c_ptr = &cave[y][x];
1119 place_inner_grid(c_ptr);
1123 /* Place a locked door on the inner room */
1124 switch (randint1(4))
1126 case 1: place_locked_door(yval - 1, xval); break;
1127 case 2: place_locked_door(yval + 1, xval); break;
1128 case 3: place_locked_door(yval, xval - 1); break;
1129 case 4: place_locked_door(yval, xval + 1); break;
1132 /* Monsters to guard the "treasure" */
1133 vault_monsters(yval, xval, randint1(3) + 2);
1136 if (randint0(100) < 80)
1138 place_object(yval, xval, 0L);
1144 place_random_stairs(yval, xval);
1147 /* Traps to protect the treasure */
1148 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
1153 /* Inner pillar(s). */
1156 /* Place a secret door */
1157 switch (randint1(4))
1159 case 1: place_secret_door(y1 - 1, xval); break;
1160 case 2: place_secret_door(y2 + 1, xval); break;
1161 case 3: place_secret_door(yval, x1 - 1); break;
1162 case 4: place_secret_door(yval, x2 + 1); break;
1165 /* Large Inner Pillar */
1166 for (y = yval - 1; y <= yval + 1; y++)
1168 for (x = xval - 1; x <= xval + 1; x++)
1170 c_ptr = &cave[y][x];
1171 place_inner_grid(c_ptr);
1175 /* Occasionally, two more Large Inner Pillars */
1179 for (y = yval - 1; y <= yval + 1; y++)
1181 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1183 c_ptr = &cave[y][x];
1184 place_inner_grid(c_ptr);
1186 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1188 c_ptr = &cave[y][x];
1189 place_inner_grid(c_ptr);
1194 /* Occasionally, some Inner rooms */
1197 /* Long horizontal walls */
1198 for (x = xval - 5; x <= xval + 5; x++)
1200 c_ptr = &cave[yval - 1][x];
1201 place_inner_grid(c_ptr);
1202 c_ptr = &cave[yval + 1][x];
1203 place_inner_grid(c_ptr);
1206 /* Close off the left/right edges */
1207 c_ptr = &cave[yval][xval - 5];
1208 place_inner_grid(c_ptr);
1209 c_ptr = &cave[yval][xval + 5];
1210 place_inner_grid(c_ptr);
1212 /* Secret doors (random top/bottom) */
1213 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3);
1214 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3);
1217 vault_monsters(yval, xval - 2, randint1(2));
1218 vault_monsters(yval, xval + 2, randint1(2));
1221 if (one_in_(3)) place_object(yval, xval - 2, 0L);
1222 if (one_in_(3)) place_object(yval, xval + 2, 0L);
1231 /* Place a secret door */
1232 switch (randint1(4))
1234 case 1: place_secret_door(y1 - 1, xval); break;
1235 case 2: place_secret_door(y2 + 1, xval); break;
1236 case 3: place_secret_door(yval, x1 - 1); break;
1237 case 4: place_secret_door(yval, x2 + 1); break;
1240 /* Maze (really a checkerboard) */
1241 for (y = y1; y <= y2; y++)
1243 for (x = x1; x <= x2; x++)
1247 c_ptr = &cave[y][x];
1248 place_inner_grid(c_ptr);
1253 /* Monsters just love mazes. */
1254 vault_monsters(yval, xval - 5, randint1(3));
1255 vault_monsters(yval, xval + 5, randint1(3));
1257 /* Traps make them entertaining. */
1258 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1259 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1261 /* Mazes should have some treasure too. */
1262 vault_objects(yval, xval, 3);
1267 /* Four small rooms. */
1271 for (y = y1; y <= y2; y++)
1273 c_ptr = &cave[y][xval];
1274 place_inner_grid(c_ptr);
1276 for (x = x1; x <= x2; x++)
1278 c_ptr = &cave[yval][x];
1279 place_inner_grid(c_ptr);
1282 /* Doors into the rooms */
1283 if (randint0(100) < 50)
1285 int i = randint1(10);
1286 place_secret_door(y1 - 1, xval - i);
1287 place_secret_door(y1 - 1, xval + i);
1288 place_secret_door(y2 + 1, xval - i);
1289 place_secret_door(y2 + 1, xval + i);
1293 int i = randint1(3);
1294 place_secret_door(yval + i, x1 - 1);
1295 place_secret_door(yval - i, x1 - 1);
1296 place_secret_door(yval + i, x2 + 1);
1297 place_secret_door(yval - i, x2 + 1);
1300 /* Treasure, centered at the center of the cross */
1301 vault_objects(yval, xval, 2 + randint1(2));
1303 /* Gotta have some monsters. */
1304 vault_monsters(yval + 1, xval - 4, randint1(4));
1305 vault_monsters(yval + 1, xval + 4, randint1(4));
1306 vault_monsters(yval - 1, xval - 4, randint1(4));
1307 vault_monsters(yval - 1, xval + 4, randint1(4));
1318 * The following functions are used to determine if the given monster
1319 * is appropriate for inclusion in a monster nest or monster pit or
1322 * None of the pits/nests are allowed to include "unique" monsters.
1327 * Monster validation macro
1329 * Line 1 -- forbid town monsters
1330 * Line 2 -- forbid uniques
1331 * Line 3 -- forbid aquatic monsters
1333 #define vault_monster_okay(I) \
1334 (mon_hook_dungeon(I) && \
1335 !(r_info[I].flags1 & RF1_UNIQUE) && \
1336 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1337 !(r_info[I].flagsr & RFR_RES_ALL) && \
1338 !(r_info[I].flags7 & RF7_AQUATIC))
1341 /* Race index for "monster pit (clone)" */
1342 static int vault_aux_race;
1344 /* Race index for "monster pit (symbol clone)" */
1345 static char vault_aux_char;
1347 /* Breath mask for "monster pit (dragon)" */
1348 static u32b vault_aux_dragon_mask4;
1352 * Helper monster selection function
1354 static bool vault_aux_simple(int r_idx)
1357 return (vault_monster_okay(r_idx));
1362 * Helper function for "monster nest (jelly)"
1364 static bool vault_aux_jelly(int r_idx)
1366 monster_race *r_ptr = &r_info[r_idx];
1368 /* Validate the monster */
1369 if (!vault_monster_okay(r_idx)) return (FALSE);
1371 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1373 /* Also decline evil jellies (like death molds and shoggoths) */
1374 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1376 /* Require icky thing, jelly, mold, or mushroom */
1377 if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
1385 * Helper function for "monster nest (animal)"
1387 static bool vault_aux_animal(int r_idx)
1389 monster_race *r_ptr = &r_info[r_idx];
1391 /* Validate the monster */
1392 if (!vault_monster_okay(r_idx)) return (FALSE);
1394 /* Require "animal" flag */
1395 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1403 * Helper function for "monster nest (undead)"
1405 static bool vault_aux_undead(int r_idx)
1407 monster_race *r_ptr = &r_info[r_idx];
1409 /* Validate the monster */
1410 if (!vault_monster_okay(r_idx)) return (FALSE);
1412 /* Require Undead */
1413 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1421 * Helper function for "monster nest (chapel)"
1423 static bool vault_aux_chapel_g(int r_idx)
1425 static int chapel_list[] = {
1426 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1427 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1428 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1433 monster_race *r_ptr = &r_info[r_idx];
1435 /* Validate the monster */
1436 if (!vault_monster_okay(r_idx)) return (FALSE);
1438 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1439 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1441 /* Require "priest" or Angel */
1443 if (r_ptr->d_char == 'A') return TRUE;
1445 for (i = 0; chapel_list[i]; i++)
1446 if (r_idx == chapel_list[i]) return TRUE;
1453 * Helper function for "monster nest (kennel)"
1455 static bool vault_aux_kennel(int r_idx)
1457 monster_race *r_ptr = &r_info[r_idx];
1459 /* Validate the monster */
1460 if (!vault_monster_okay(r_idx)) return (FALSE);
1462 /* Require a Zephyr Hound or a dog */
1463 if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
1471 * Helper function for "monster nest (mimic)"
1473 static bool vault_aux_mimic(int r_idx)
1475 monster_race *r_ptr = &r_info[r_idx];
1477 /* Validate the monster */
1478 if (!vault_monster_okay(r_idx)) return (FALSE);
1481 if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
1488 * Helper function for "monster nest (clone)"
1490 static bool vault_aux_clone(int r_idx)
1492 /* Validate the monster */
1493 if (!vault_monster_okay(r_idx)) return (FALSE);
1495 return (r_idx == vault_aux_race);
1500 * Helper function for "monster nest (symbol clone)"
1502 static bool vault_aux_symbol_e(int r_idx)
1504 monster_race *r_ptr = &r_info[r_idx];
1506 /* Validate the monster */
1507 if (!vault_monster_okay(r_idx)) return (FALSE);
1509 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1511 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1513 /* Decline incorrect symbol */
1514 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1522 * Helper function for "monster nest (symbol clone)"
1524 static bool vault_aux_symbol_g(int r_idx)
1526 monster_race *r_ptr = &r_info[r_idx];
1528 /* Validate the monster */
1529 if (!vault_monster_okay(r_idx)) return (FALSE);
1531 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1533 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1535 /* Decline incorrect symbol */
1536 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1544 * Helper function for "monster pit (orc)"
1546 static bool vault_aux_orc(int r_idx)
1548 monster_race *r_ptr = &r_info[r_idx];
1550 /* Validate the monster */
1551 if (!vault_monster_okay(r_idx)) return (FALSE);
1554 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1556 /* Decline undead */
1557 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1565 * Helper function for "monster pit (troll)"
1567 static bool vault_aux_troll(int r_idx)
1569 monster_race *r_ptr = &r_info[r_idx];
1571 /* Validate the monster */
1572 if (!vault_monster_okay(r_idx)) return (FALSE);
1575 if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1577 /* Decline undead */
1578 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1586 * Helper function for "monster pit (giant)"
1588 static bool vault_aux_giant(int r_idx)
1590 monster_race *r_ptr = &r_info[r_idx];
1592 /* Validate the monster */
1593 if (!vault_monster_okay(r_idx)) return (FALSE);
1596 if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1598 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1600 /* Decline undead */
1601 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1609 * Helper function for "monster pit (dragon)"
1611 static bool vault_aux_dragon(int r_idx)
1613 monster_race *r_ptr = &r_info[r_idx];
1615 /* Validate the monster */
1616 if (!vault_monster_okay(r_idx)) return (FALSE);
1618 /* Require dragon */
1619 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1621 /* Hack -- Require correct "breath attack" */
1622 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1624 /* Decline undead */
1625 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1633 * Helper function for "monster pit (demon)"
1635 static bool vault_aux_demon(int r_idx)
1637 monster_race *r_ptr = &r_info[r_idx];
1639 /* Validate the monster */
1640 if (!vault_monster_okay(r_idx)) return (FALSE);
1642 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1645 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1653 * Helper function for "monster pit (lovecraftian)"
1655 static bool vault_aux_cthulhu(int r_idx)
1657 monster_race *r_ptr = &r_info[r_idx];
1659 /* Validate the monster */
1660 if (!vault_monster_okay(r_idx)) return (FALSE);
1662 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1664 /* Require eldritch horror */
1665 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1673 * Helper function for "monster pit (clone)"
1675 static void vault_prep_clone(void)
1677 /* Apply the monster restriction */
1678 get_mon_num_prep(vault_aux_simple, NULL);
1680 /* Pick a race to clone */
1681 vault_aux_race = get_mon_num(dun_level + 10);
1683 /* Remove the monster restriction */
1684 get_mon_num_prep(NULL, NULL);
1689 * Helper function for "monster pit (symbol clone)"
1691 static void vault_prep_symbol(void)
1695 /* Apply the monster restriction */
1696 get_mon_num_prep(vault_aux_simple, NULL);
1698 /* Pick a race to clone */
1699 r_idx = get_mon_num(dun_level + 10);
1701 /* Remove the monster restriction */
1702 get_mon_num_prep(NULL, NULL);
1704 /* Extract the symbol */
1705 vault_aux_char = r_info[r_idx].d_char;
1710 * Helper function for "monster pit (dragon)"
1712 static void vault_prep_dragon(void)
1714 /* Pick dragon type */
1715 switch (randint0(6))
1720 /* Restrict dragon breath type */
1721 vault_aux_dragon_mask4 = RF4_BR_ACID;
1730 /* Restrict dragon breath type */
1731 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1740 /* Restrict dragon breath type */
1741 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1750 /* Restrict dragon breath type */
1751 vault_aux_dragon_mask4 = RF4_BR_COLD;
1760 /* Restrict dragon breath type */
1761 vault_aux_dragon_mask4 = RF4_BR_POIS;
1770 /* Restrict dragon breath type */
1771 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1772 RF4_BR_FIRE | RF4_BR_COLD |
1783 * Helper function for "monster pit (dark elf)"
1785 static bool vault_aux_dark_elf(int r_idx)
1788 static int dark_elf_list[] =
1790 MON_D_ELF, MON_D_ELF_MAGE, MON_D_ELF_WARRIOR, MON_D_ELF_PRIEST,
1791 MON_D_ELF_LORD, MON_D_ELF_WARLOCK, MON_D_ELF_DRUID, MON_NIGHTBLADE,
1792 MON_D_ELF_SORC, MON_D_ELF_SHADE, 0,
1795 /* Validate the monster */
1796 if (!vault_monster_okay(r_idx)) return FALSE;
1798 /* Require dark elves */
1799 for (i = 0; dark_elf_list[i]; i++)
1800 if (r_idx == dark_elf_list[i]) return TRUE;
1807 typedef struct vault_aux_type vault_aux_type;
1810 struct vault_aux_type
1813 bool (*hook_func)(int r_idx);
1814 void (*prep_func)(void);
1820 static int pick_vault_type(vault_aux_type *l_ptr, s16b allow_flag_mask)
1822 int tmp, total, count;
1824 vault_aux_type *n_ptr;
1826 /* Calculate the total possibilities */
1827 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1830 if (!n_ptr->name) break;
1832 /* Ignore excessive depth */
1833 if (n_ptr->level > dun_level) continue;
1835 /* Not matched with pit/nest flag */
1836 if (!(allow_flag_mask & (1L << count))) continue;
1838 /* Count this possibility */
1839 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1842 /* Pick a random type */
1843 tmp = randint0(total);
1845 /* Find this type */
1846 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1849 if (!n_ptr->name) break;
1851 /* Ignore excessive depth */
1852 if (n_ptr->level > dun_level) continue;
1854 /* Not matched with pit/nest flag */
1855 if (!(allow_flag_mask & (1L << count))) continue;
1857 /* Count this possibility */
1858 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1860 /* Found the type */
1861 if (tmp < total) break;
1864 return n_ptr->name ? count : -1;
1867 static vault_aux_type nest_types[] =
1870 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1871 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1872 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1873 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1874 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1875 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1876 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1877 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1878 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1879 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1880 {NULL, NULL, NULL, 0, 0},
1882 {"clone", vault_aux_clone, vault_prep_clone, 5, 3},
1883 {"jelly", vault_aux_jelly, NULL, 5, 6},
1884 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1885 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1886 {"mimic", vault_aux_mimic, NULL, 30, 4},
1887 {"lovecraftian", vault_aux_cthulhu, NULL, 70, 2},
1888 {"kennel", vault_aux_kennel, NULL, 45, 4},
1889 {"animal", vault_aux_animal, NULL, 35, 5},
1890 {"chapel", vault_aux_chapel_g, NULL, 75, 4},
1891 {"undead", vault_aux_undead, NULL, 75, 5},
1892 {NULL, NULL, NULL, 0, 0},
1896 static vault_aux_type pit_types[] =
1899 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1900 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1901 {"¥¸¥ã¥¤¥¢¥ó¥È", vault_aux_giant, NULL, 50, 6},
1902 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1903 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1904 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1905 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
1906 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
1907 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
1908 {"¥À¡¼¥¯¥¨¥ë¥Õ", vault_aux_dark_elf, NULL, 45, 4},
1909 {NULL, NULL, NULL, 0, 0},
1911 {"orc", vault_aux_orc, NULL, 5, 6},
1912 {"troll", vault_aux_troll, NULL, 20, 6},
1913 {"giant", vault_aux_giant, NULL, 50, 6},
1914 {"lovecraftian", vault_aux_cthulhu, NULL, 80, 2},
1915 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1916 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1917 {"chapel", vault_aux_chapel_g, NULL, 65, 2},
1918 {"dragon", vault_aux_dragon, vault_prep_dragon, 70, 6},
1919 {"demon", vault_aux_demon, NULL, 80, 6},
1920 {"dark elf", vault_aux_dark_elf, NULL, 45, 4},
1921 {NULL, NULL, NULL, 0, 0},
1926 /* Nest types code */
1927 #define NEST_TYPE_CLONE 0
1928 #define NEST_TYPE_JELLY 1
1929 #define NEST_TYPE_SYMBOL_GOOD 2
1930 #define NEST_TYPE_SYMBOL_EVIL 3
1931 #define NEST_TYPE_MIMIC 4
1932 #define NEST_TYPE_LOVECRAFTIAN 5
1933 #define NEST_TYPE_KENNEL 6
1934 #define NEST_TYPE_ANIMAL 7
1935 #define NEST_TYPE_CHAPEL 8
1936 #define NEST_TYPE_UNDEAD 9
1938 /* Pit types code */
1939 #define PIT_TYPE_ORC 0
1940 #define PIT_TYPE_TROLL 1
1941 #define PIT_TYPE_GIANT 2
1942 #define PIT_TYPE_LOVECRAFTIAN 3
1943 #define PIT_TYPE_SYMBOL_GOOD 4
1944 #define PIT_TYPE_SYMBOL_EVIL 5
1945 #define PIT_TYPE_CHAPEL 6
1946 #define PIT_TYPE_DRAGON 7
1947 #define PIT_TYPE_DEMON 8
1948 #define PIT_TYPE_DARK_ELF 9
1952 * Hack -- Get the string describing subtype of pit/nest
1953 * Determined in prepare function (some pit/nest only)
1955 static cptr pit_subtype_string(int type, bool nest)
1957 static char inner_buf[256] = "";
1959 inner_buf[0] = '\0'; /* Init string */
1961 if (nest) /* Nests */
1965 case NEST_TYPE_CLONE:
1966 sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
1968 case NEST_TYPE_SYMBOL_GOOD:
1969 case NEST_TYPE_SYMBOL_EVIL:
1970 sprintf(inner_buf, "(%c)", vault_aux_char);
1978 case PIT_TYPE_SYMBOL_GOOD:
1979 case PIT_TYPE_SYMBOL_EVIL:
1980 sprintf(inner_buf, "(%c)", vault_aux_char);
1982 case PIT_TYPE_DRAGON:
1983 switch (vault_aux_dragon_mask4)
1986 case RF4_BR_ACID: strcpy(inner_buf, "(»À)"); break;
1987 case RF4_BR_ELEC: strcpy(inner_buf, "(°ðºÊ)"); break;
1988 case RF4_BR_FIRE: strcpy(inner_buf, "(²Ð±ê)"); break;
1989 case RF4_BR_COLD: strcpy(inner_buf, "(Î䵤)"); break;
1990 case RF4_BR_POIS: strcpy(inner_buf, "(ÆÇ)"); break;
1991 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
1992 strcpy(inner_buf, "(Ëü¿§)"); break;
1993 default: strcpy(inner_buf, "(̤ÄêµÁ)"); break;
1995 case RF4_BR_ACID: strcpy(inner_buf, "(acid)"); break;
1996 case RF4_BR_ELEC: strcpy(inner_buf, "(lightning)"); break;
1997 case RF4_BR_FIRE: strcpy(inner_buf, "(fire)"); break;
1998 case RF4_BR_COLD: strcpy(inner_buf, "(frost)"); break;
1999 case RF4_BR_POIS: strcpy(inner_buf, "(poison)"); break;
2000 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2001 strcpy(inner_buf, "(multi-hued)"); break;
2002 default: strcpy(inner_buf, "(undefined)"); break;
2013 /* A struct for nest monster information with cheat_hear */
2023 * Comp function for sorting nest monster information
2025 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
2027 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2028 int w1 = nest_mon_info[a].r_idx;
2029 int w2 = nest_mon_info[b].r_idx;
2030 monster_race *r1_ptr = &r_info[w1];
2031 monster_race *r2_ptr = &r_info[w2];
2037 /* Extract used info */
2038 z1 = nest_mon_info[a].used;
2039 z2 = nest_mon_info[b].used;
2041 /* Compare used status */
2042 if (z1 < z2) return FALSE;
2043 if (z1 > z2) return TRUE;
2045 /* Compare levels */
2046 if (r1_ptr->level < r2_ptr->level) return TRUE;
2047 if (r1_ptr->level > r2_ptr->level) return FALSE;
2049 /* Compare experience */
2050 if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
2051 if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
2053 /* Compare indexes */
2059 * Swap function for sorting nest monster information
2061 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
2063 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2064 nest_mon_info_type holder;
2070 holder = nest_mon_info[a];
2071 nest_mon_info[a] = nest_mon_info[b];
2072 nest_mon_info[b] = holder;
2076 #define NUM_NEST_MON_TYPE 64
2079 * Type 5 -- Monster nests
2081 * A monster nest is a "big" room, with an "inner" room, containing
2082 * a "collection" of monsters of a given type strewn about the room.
2084 * The monsters are chosen from a set of 64 randomly selected monster
2085 * races, to allow the nest creation to fail instead of having "holes".
2087 * Note the use of the "get_mon_num_prep()" function, and the special
2088 * "get_mon_num_hook()" restriction function, to prepare the "monster
2089 * allocation table" in such a way as to optimize the selection of
2090 * "appropriate" non-unique monsters for the nest.
2092 * Note that the "get_mon_num()" function may (rarely) fail, in which
2093 * case the nest will be empty, and will not affect the level rating.
2095 * Note that "monster nests" will never contain "unique" monsters.
2097 static bool build_type5(void)
2099 int y, x, y1, x1, y2, x2, xval, yval;
2101 nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
2107 int cur_nest_type = pick_vault_type(nest_types, d_info[dungeon_type].nest);
2108 vault_aux_type *n_ptr;
2110 /* No type available */
2111 if (cur_nest_type < 0) return FALSE;
2113 n_ptr = &nest_types[cur_nest_type];
2115 /* Process a preparation function if necessary */
2116 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2118 /* Prepare allocation table */
2119 get_mon_num_prep(n_ptr->hook_func, NULL);
2121 align.sub_align = SUB_ALIGN_NEUTRAL;
2123 /* Pick some monster types */
2124 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2126 int r_idx = 0, attempts = 100;
2127 monster_race *r_ptr = NULL;
2131 /* Get a (hard) monster type */
2132 r_idx = get_mon_num(dun_level + 11);
2133 r_ptr = &r_info[r_idx];
2135 /* Decline incorrect alignment */
2136 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2138 /* Accept this monster */
2142 /* Notice failure */
2143 if (!r_idx || !attempts) return FALSE;
2145 /* Note the alignment */
2146 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2147 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2149 nest_mon_info[i].r_idx = r_idx;
2150 nest_mon_info[i].used = FALSE;
2153 /* Find and reserve some space in the dungeon. Get center of room. */
2154 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2162 /* Place the floor area */
2163 for (y = y1 - 1; y <= y2 + 1; y++)
2165 for (x = x1 - 1; x <= x2 + 1; x++)
2167 c_ptr = &cave[y][x];
2168 place_floor_grid(c_ptr);
2169 c_ptr->info |= (CAVE_ROOM);
2173 /* Place the outer walls */
2174 for (y = y1 - 1; y <= y2 + 1; y++)
2176 c_ptr = &cave[y][x1 - 1];
2177 place_outer_grid(c_ptr);
2178 c_ptr = &cave[y][x2 + 1];
2179 place_outer_grid(c_ptr);
2181 for (x = x1 - 1; x <= x2 + 1; x++)
2183 c_ptr = &cave[y1 - 1][x];
2184 place_outer_grid(c_ptr);
2185 c_ptr = &cave[y2 + 1][x];
2186 place_outer_grid(c_ptr);
2190 /* Advance to the center room */
2196 /* The inner walls */
2197 for (y = y1 - 1; y <= y2 + 1; y++)
2199 c_ptr = &cave[y][x1 - 1];
2200 place_inner_grid(c_ptr);
2201 c_ptr = &cave[y][x2 + 1];
2202 place_inner_grid(c_ptr);
2205 for (x = x1 - 1; x <= x2 + 1; x++)
2207 c_ptr = &cave[y1 - 1][x];
2208 place_inner_grid(c_ptr);
2209 c_ptr = &cave[y2 + 1][x];
2210 place_inner_grid(c_ptr);
2212 for (y = y1; y <= y2; y++)
2214 for (x = x1; x <= x2; x++)
2216 add_cave_info(y, x, CAVE_ICKY);
2220 /* Place a secret door */
2221 switch (randint1(4))
2223 case 1: place_secret_door(y1 - 1, xval); break;
2224 case 2: place_secret_door(y2 + 1, xval); break;
2225 case 3: place_secret_door(yval, x1 - 1); break;
2226 case 4: place_secret_door(yval, x2 + 1); break;
2234 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(nest)(%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2236 msg_format("Monster nest (%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2240 /* Increase the level rating */
2243 /* (Sometimes) Cause a "special feeling" (for "Monster Nests") */
2244 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
2246 good_item_flag = TRUE;
2249 /* Place some monsters */
2250 for (y = yval - 2; y <= yval + 2; y++)
2252 for (x = xval - 9; x <= xval + 9; x++)
2256 i = randint0(NUM_NEST_MON_TYPE);
2257 r_idx = nest_mon_info[i].r_idx;
2259 /* Place that "random" monster (no groups) */
2260 (void)place_monster_aux(0, y, x, r_idx, 0L);
2262 nest_mon_info[i].used = TRUE;
2266 if (cheat_room && cheat_hear)
2268 ang_sort_comp = ang_sort_comp_nest_mon_info;
2269 ang_sort_swap = ang_sort_swap_nest_mon_info;
2270 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2272 /* Dump the entries (prevent multi-printing) */
2273 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2275 if (!nest_mon_info[i].used) break;
2276 for (; i < NUM_NEST_MON_TYPE - 1; i++)
2278 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2279 if (!nest_mon_info[i + 1].used) break;
2281 msg_print(r_name + r_info[nest_mon_info[i].r_idx].name);
2290 * Type 6 -- Monster pits
2292 * A monster pit is a "big" room, with an "inner" room, containing
2293 * a "collection" of monsters of a given type organized in the room.
2295 * The inside room in a monster pit appears as shown below, where the
2296 * actual monsters in each location depend on the type of the pit
2298 * #####################
2299 * #0000000000000000000#
2300 * #0112233455543322110#
2301 * #0112233467643322110#
2302 * #0112233455543322110#
2303 * #0000000000000000000#
2304 * #####################
2306 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
2307 * to request 16 "appropriate" monsters, sorting them by level, and using
2308 * the "even" entries in this sorted list for the contents of the pit.
2310 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
2311 * which is handled by requiring a specific "breath" attack for all of the
2312 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
2313 * be present in many of the dragon pits, if they have the proper breath.
2315 * Note the use of the "get_mon_num_prep()" function, and the special
2316 * "get_mon_num_hook()" restriction function, to prepare the "monster
2317 * allocation table" in such a way as to optimize the selection of
2318 * "appropriate" non-unique monsters for the pit.
2320 * Note that the "get_mon_num()" function may (rarely) fail, in which case
2321 * the pit will be empty, and will not effect the level rating.
2323 * Note that "monster pits" will never contain "unique" monsters.
2325 static bool build_type6(void)
2327 int y, x, y1, x1, y2, x2, xval, yval;
2336 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2337 vault_aux_type *n_ptr;
2339 /* No type available */
2340 if (cur_pit_type < 0) return FALSE;
2342 n_ptr = &pit_types[cur_pit_type];
2344 /* Process a preparation function if necessary */
2345 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2347 /* Prepare allocation table */
2348 get_mon_num_prep(n_ptr->hook_func, NULL);
2350 align.sub_align = SUB_ALIGN_NEUTRAL;
2352 /* Pick some monster types */
2353 for (i = 0; i < 16; i++)
2355 int r_idx = 0, attempts = 100;
2356 monster_race *r_ptr = NULL;
2360 /* Get a (hard) monster type */
2361 r_idx = get_mon_num(dun_level + 11);
2362 r_ptr = &r_info[r_idx];
2364 /* Decline incorrect alignment */
2365 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2367 /* Accept this monster */
2371 /* Notice failure */
2372 if (!r_idx || !attempts) return FALSE;
2374 /* Note the alignment */
2375 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2376 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2381 /* Find and reserve some space in the dungeon. Get center of room. */
2382 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2390 /* Place the floor area */
2391 for (y = y1 - 1; y <= y2 + 1; y++)
2393 for (x = x1 - 1; x <= x2 + 1; x++)
2395 c_ptr = &cave[y][x];
2396 place_floor_grid(c_ptr);
2397 c_ptr->info |= (CAVE_ROOM);
2401 /* Place the outer walls */
2402 for (y = y1 - 1; y <= y2 + 1; y++)
2404 c_ptr = &cave[y][x1 - 1];
2405 place_outer_grid(c_ptr);
2406 c_ptr = &cave[y][x2 + 1];
2407 place_outer_grid(c_ptr);
2409 for (x = x1 - 1; x <= x2 + 1; x++)
2411 c_ptr = &cave[y1 - 1][x];
2412 place_outer_grid(c_ptr);
2413 c_ptr = &cave[y2 + 1][x];
2414 place_outer_grid(c_ptr);
2417 /* Advance to the center room */
2423 /* The inner walls */
2424 for (y = y1 - 1; y <= y2 + 1; y++)
2426 c_ptr = &cave[y][x1 - 1];
2427 place_inner_grid(c_ptr);
2428 c_ptr = &cave[y][x2 + 1];
2429 place_inner_grid(c_ptr);
2431 for (x = x1 - 1; x <= x2 + 1; x++)
2433 c_ptr = &cave[y1 - 1][x];
2434 place_inner_grid(c_ptr);
2435 c_ptr = &cave[y2 + 1][x];
2436 place_inner_grid(c_ptr);
2438 for (y = y1; y <= y2; y++)
2440 for (x = x1; x <= x2; x++)
2442 add_cave_info(y, x, CAVE_ICKY);
2446 /* Place a secret door */
2447 switch (randint1(4))
2449 case 1: place_secret_door(y1 - 1, xval); break;
2450 case 2: place_secret_door(y2 + 1, xval); break;
2451 case 3: place_secret_door(yval, x1 - 1); break;
2452 case 4: place_secret_door(yval, x2 + 1); break;
2455 /* Sort the entries */
2456 for (i = 0; i < 16 - 1; i++)
2458 /* Sort the entries */
2459 for (j = 0; j < 16 - 1; j++)
2464 int p1 = r_info[what[i1]].level;
2465 int p2 = r_info[what[i2]].level;
2471 what[i1] = what[i2];
2482 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(pit)(%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2484 msg_format("Monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2488 /* Select the entries */
2489 for (i = 0; i < 8; i++)
2491 /* Every other entry */
2492 what[i] = what[i * 2];
2497 msg_print(r_name + r_info[what[i]].name);
2501 /* Increase the level rating */
2504 /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
2505 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
2507 good_item_flag = TRUE;
2510 /* Top and bottom rows */
2511 for (x = xval - 9; x <= xval + 9; x++)
2513 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2514 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2517 /* Middle columns */
2518 for (y = yval - 1; y <= yval + 1; y++)
2520 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2521 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2523 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2524 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2526 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2527 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2529 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2530 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2532 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2533 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2535 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2536 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2538 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2539 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2541 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2542 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2545 /* Above/Below the center monster */
2546 for (x = xval - 1; x <= xval + 1; x++)
2548 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2549 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2552 /* Next to the center monster */
2553 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2554 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2556 /* Center monster */
2557 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2563 /* coordinate translation code */
2564 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2570 * transno specifies what transformation is required. (0-7)
2571 * The lower two bits indicate by how much the vault is rotated,
2572 * and the upper bit indicates a reflection.
2573 * This is done by using rotation matrices... however since
2574 * these are mostly zeros for rotations by 90 degrees this can
2575 * be expressed simply in terms of swapping and inverting the
2576 * x and y coordinates.
2578 for (i = 0; i < transno % 4; i++)
2580 /* rotate by 90 degrees */
2588 /* Reflect depending on status of 3rd bit. */
2592 /* Add offsets so vault stays in the first quadrant */
2599 * Hack -- fill in "vault" rooms
2601 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2602 int xoffset, int yoffset, int transno)
2604 int dx, dy, x, y, i, j;
2611 /* Place dungeon features and objects */
2612 for (t = data, dy = 0; dy < ymax; dy++)
2614 for (dx = 0; dx < xmax; dx++, t++)
2616 /* prevent loop counter from being overwritten */
2621 coord_trans(&i, &j, xoffset, yoffset, transno);
2623 /* Extract the location */
2624 if (transno % 2 == 0)
2626 /* no swap of x/y */
2627 x = xval - (xmax / 2) + i;
2628 y = yval - (ymax / 2) + j;
2633 x = xval - (ymax / 2) + i;
2634 y = yval - (xmax / 2) + j;
2637 /* Hack -- skip "non-grids" */
2638 if (*t == ' ') continue;
2640 /* Access the grid */
2641 c_ptr = &cave[y][x];
2643 /* Lay down a floor */
2644 place_floor_grid(c_ptr);
2646 /* Remove any mimic */
2649 /* Part of a vault */
2650 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2652 /* Analyze the grid */
2655 /* Granite wall (outer) */
2657 place_outer_noperm_grid(c_ptr);
2660 /* Granite wall (inner) */
2662 place_inner_grid(c_ptr);
2665 /* Permanent wall (inner) */
2667 place_inner_perm_grid(c_ptr);
2672 if (randint0(100) < 75)
2674 place_object(y, x, 0L);
2684 place_secret_door(y, x);
2692 /* Black market in a dungeon */
2694 set_cave_feat(y, x, FEAT_SHOP_HEAD + STORE_BLACK);
2695 store_init(NO_TOWN, STORE_BLACK);
2700 set_cave_feat(y, x, FEAT_PATTERN_START);
2704 set_cave_feat(y, x, FEAT_PATTERN_1);
2708 set_cave_feat(y, x, FEAT_PATTERN_2);
2712 set_cave_feat(y, x, FEAT_PATTERN_3);
2716 set_cave_feat(y, x, FEAT_PATTERN_4);
2720 set_cave_feat(y, x, FEAT_PATTERN_END);
2724 set_cave_feat(y, x, FEAT_PATTERN_XTRA1);
2728 /* Reward for Pattern walk */
2729 object_level = base_level + 12;
2730 place_object(y, x, AM_GOOD | AM_GREAT);
2731 object_level = base_level;
2738 /* Place dungeon monsters and objects */
2739 for (t = data, dy = 0; dy < ymax; dy++)
2741 for (dx = 0; dx < xmax; dx++, t++)
2743 /* prevent loop counter from being overwritten */
2748 coord_trans(&i, &j, xoffset, yoffset, transno);
2750 /* Extract the location */
2751 if (transno % 2 == 0)
2753 /* no swap of x/y */
2754 x = xval - (xmax / 2) + i;
2755 y = yval - (ymax / 2) + j;
2760 x = xval - (ymax / 2) + i;
2761 y = yval - (xmax / 2) + j;
2764 /* Hack -- skip "non-grids" */
2765 if (*t == ' ') continue;
2767 /* Analyze the symbol */
2773 monster_level = base_level + 5;
2774 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2775 monster_level = base_level;
2779 /* Meaner monster */
2782 monster_level = base_level + 11;
2783 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2784 monster_level = base_level;
2788 /* Meaner monster, plus treasure */
2791 monster_level = base_level + 9;
2792 place_monster(y, x, PM_ALLOW_SLEEP);
2793 monster_level = base_level;
2794 object_level = base_level + 7;
2795 place_object(y, x, AM_GOOD);
2796 object_level = base_level;
2800 /* Nasty monster and treasure */
2803 monster_level = base_level + 40;
2804 place_monster(y, x, PM_ALLOW_SLEEP);
2805 monster_level = base_level;
2806 object_level = base_level + 20;
2807 place_object(y, x, AM_GOOD | AM_GREAT);
2808 object_level = base_level;
2812 /* Monster and/or object */
2815 if (randint0(100) < 50)
2817 monster_level = base_level + 3;
2818 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2819 monster_level = base_level;
2821 if (randint0(100) < 50)
2823 object_level = base_level + 7;
2824 place_object(y, x, 0L);
2825 object_level = base_level;
2837 * Type 7 -- simple vaults (see "v_info.txt")
2839 static bool build_type7(void)
2845 int xoffset, yoffset;
2848 /* Pick a lesser vault */
2849 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2851 /* Access a random vault record */
2852 v_ptr = &v_info[randint0(max_v_idx)];
2854 /* Accept the first lesser vault */
2855 if (v_ptr->typ == 7) break;
2858 /* No lesser vault found */
2859 if (dummy >= SAFE_MAX_ATTEMPTS)
2864 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2866 msg_print("Warning! Could not place lesser vault!");
2872 /* pick type of transformation (0-7) */
2873 transno = randint0(8);
2875 /* calculate offsets */
2879 /* Some huge vault cannot be ratated to fit in the dungeon */
2880 if (x+2 > cur_hgt-2)
2882 /* Forbid 90 or 270 degree ratation */
2886 coord_trans(&x, &y, 0, 0, transno);
2906 /* Find and reserve some space in the dungeon. Get center of room. */
2907 if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
2915 if (cheat_room) msg_format("¾®¤µ¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
2917 if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
2920 /* Boost the rating */
2921 rating += v_ptr->rat;
2923 /* (Sometimes) Cause a special feeling */
2924 if ((dun_level <= 50) ||
2925 (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
2927 good_item_flag = TRUE;
2930 /* Hack -- Build the vault */
2931 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2932 v_text + v_ptr->text, xoffset, yoffset, transno);
2939 * Type 8 -- greater vaults (see "v_info.txt")
2941 static bool build_type8(void)
2948 int xoffset, yoffset;
2950 /* Pick a greater vault */
2951 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2953 /* Access a random vault record */
2954 v_ptr = &v_info[randint0(max_v_idx)];
2956 /* Accept the first greater vault */
2957 if (v_ptr->typ == 8) break;
2960 /* No greater vault found */
2961 if (dummy >= SAFE_MAX_ATTEMPTS)
2966 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2968 msg_print("Warning! Could not place greater vault!");
2974 /* pick type of transformation (0-7) */
2975 transno = randint0(8);
2977 /* calculate offsets */
2981 /* Some huge vault cannot be ratated to fit in the dungeon */
2982 if (x+2 > cur_hgt-2)
2984 /* Forbid 90 or 270 degree ratation */
2988 coord_trans(&x, &y, 0, 0, transno);
3009 * Try to allocate space for room. If fails, exit
3011 * Hack -- Prepare a bit larger space (+2, +2) to
3012 * prevent generation of vaults with no-entrance.
3014 /* Find and reserve some space in the dungeon. Get center of room. */
3015 if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
3018 v_ptr = &v_info[76 + randint1(3)];
3023 if (cheat_room) msg_format("µðÂç¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3025 if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
3028 /* Boost the rating */
3029 rating += v_ptr->rat;
3031 /* (Sometimes) Cause a special feeling */
3032 if ((dun_level <= 50) ||
3033 (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
3035 good_item_flag = TRUE;
3038 /* Hack -- Build the vault */
3039 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3040 v_text + v_ptr->text, xoffset, yoffset, transno);
3046 * Structure to hold all "fill" data
3049 typedef struct fill_data_type fill_data_type;
3051 struct fill_data_type
3064 /* features to fill with */
3073 /* number of filled squares */
3077 static fill_data_type fill_data;
3080 /* Store routine for the fractal cave generator */
3081 /* this routine probably should be an inline function or a macro. */
3082 static void store_height(int x, int y, int val)
3084 /* if on boundary set val > cutoff so walls are not as square */
3085 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3086 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3087 (val <= fill_data.c1)) val = fill_data.c1 + 1;
3089 /* store the value in height-map format */
3090 cave[y][x].feat = val;
3097 * Explanation of the plasma fractal algorithm:
3099 * A grid of points is created with the properties of a 'height-map'
3100 * This is done by making the corners of the grid have a random value.
3101 * The grid is then subdivided into one with twice the resolution.
3102 * The new points midway between two 'known' points can be calculated
3103 * by taking the average value of the 'known' ones and randomly adding
3104 * or subtracting an amount proportional to the distance between those
3105 * points. The final 'middle' points of the grid are then calculated
3106 * by averaging all four of the originally 'known' corner points. An
3107 * random amount is added or subtracted from this to get a value of the
3108 * height at that point. The scaling factor here is adjusted to the
3109 * slightly larger distance diagonally as compared to orthogonally.
3111 * This is then repeated recursively to fill an entire 'height-map'
3112 * A rectangular map is done the same way, except there are different
3113 * scaling factors along the x and y directions.
3115 * A hack to change the amount of correlation between points is done using
3116 * the grd variable. If the current step size is greater than grd then
3117 * the point will be random, otherwise it will be calculated by the
3118 * above algorithm. This makes a maximum distance at which two points on
3119 * the height map can affect each other.
3121 * How fractal caves are made:
3123 * When the map is complete, a cut-off value is used to create a cave.
3124 * Heights below this value are "floor", and heights above are "wall".
3125 * This also can be used to create lakes, by adding more height levels
3126 * representing shallow and deep water/ lava etc.
3128 * The grd variable affects the width of passages.
3129 * The roug variable affects the roughness of those passages
3131 * The tricky part is making sure the created cave is connected. This
3132 * is done by 'filling' from the inside and only keeping the 'filled'
3133 * floor. Walls bounding the 'filled' floor are also kept. Everything
3134 * else is converted to the normal _extra_.
3139 * Note that this uses the cave.feat array in a very hackish way
3140 * the values are first set to zero, and then each array location
3141 * is used as a "heightmap"
3142 * The heightmap then needs to be converted back into the "feat" format.
3144 * grd=level at which fractal turns on. smaller gives more mazelike caves
3145 * roug=roughness level. 16=normal. higher values make things more convoluted
3146 * small values are good for smooth walls.
3147 * size=length of the side of the square cave system.
3149 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3151 int xhsize, yhsize, xsize, ysize, maxsize;
3154 * fixed point variables- these are stored as 256 x normal value
3155 * this gives 8 binary places of fractional part + 8 places of normal part
3158 u16b xstep, xhstep, ystep, yhstep;
3159 u16b xstep2, xhstep2, ystep2, yhstep2;
3160 u16b i, j, ii, jj, diagsize, xxsize, yysize;
3162 /* Cache for speed */
3163 u16b xm, xp, ym, yp;
3165 /* redefine size so can change the value if out of range */
3169 /* Paranoia about size of the system of caves */
3170 if (xsize > 254) xsize = 254;
3171 if (xsize < 4) xsize = 4;
3172 if (ysize > 254) ysize = 254;
3173 if (ysize < 4) ysize = 4;
3175 /* get offsets to middle of array */
3179 /* fix rounding problem */
3183 /* get limits of region */
3184 fill_data.xmin = x0 - xhsize;
3185 fill_data.ymin = y0 - yhsize;
3186 fill_data.xmax = x0 + xhsize;
3187 fill_data.ymax = y0 + yhsize;
3189 /* Store cutoff in global for quick access */
3190 fill_data.c1 = cutoff;
3193 * Scale factor for middle points:
3194 * About sqrt(2) * 256 - correct for a square lattice
3195 * approximately correct for everything else.
3199 /* maximum of xsize and ysize */
3200 maxsize = (xsize > ysize) ? xsize : ysize;
3202 /* Clear the section */
3203 for (i = 0; i <= xsize; i++)
3205 for (j = 0; j <= ysize; j++)
3207 /* -1 is a flag for "not done yet" */
3208 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3209 /* Clear icky flag because may be redoing the cave */
3210 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3214 /* Boundaries are walls */
3215 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
3216 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
3217 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
3218 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
3220 /* Set the middle square to be an open area. */
3221 cave[y0][x0].feat = 0;
3223 /* Initialize the step sizes */
3224 xstep = xhstep = xsize * 256;
3225 ystep = yhstep = ysize * 256;
3226 xxsize = xsize * 256;
3227 yysize = ysize * 256;
3230 * Fill in the rectangle with fractal height data -
3231 * like the 'plasma fractal' in fractint.
3233 while ((xhstep > 256) || (yhstep > 256))
3235 /* Halve the step sizes */
3241 /* cache well used values */
3242 xstep2 = xstep / 256;
3243 ystep2 = ystep / 256;
3245 xhstep2 = xhstep / 256;
3246 yhstep2 = yhstep / 256;
3248 /* middle top to bottom. */
3249 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3251 for (j = 0; j <= yysize; j += ystep)
3253 /* cache often used values */
3254 ii = i / 256 + fill_data.xmin;
3255 jj = j / 256 + fill_data.ymin;
3258 if (cave[jj][ii].feat == -1)
3262 /* If greater than 'grid' level then is random */
3263 store_height(ii, jj, randint1(maxsize));
3267 /* Average of left and right points +random bit */
3268 store_height(ii, jj,
3269 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3270 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3271 + (randint1(xstep2) - xhstep2) * roug / 16);
3278 /* middle left to right. */
3279 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3281 for (i = 0; i <= xxsize; i += xstep)
3283 /* cache often used values */
3284 ii = i / 256 + fill_data.xmin;
3285 jj = j / 256 + fill_data.ymin;
3288 if (cave[jj][ii].feat == -1)
3292 /* If greater than 'grid' level then is random */
3293 store_height(ii, jj, randint1(maxsize));
3297 /* Average of up and down points +random bit */
3298 store_height(ii, jj,
3299 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3300 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3301 + (randint1(ystep2) - yhstep2) * roug / 16);
3308 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3310 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3312 /* cache often used values */
3313 ii = i / 256 + fill_data.xmin;
3314 jj = j / 256 + fill_data.ymin;
3317 if (cave[jj][ii].feat == -1)
3321 /* If greater than 'grid' level then is random */
3322 store_height(ii, jj, randint1(maxsize));
3326 /* Cache reused values. */
3327 xm = fill_data.xmin + (i - xhstep) / 256;
3328 xp = fill_data.xmin + (i + xhstep) / 256;
3329 ym = fill_data.ymin + (j - yhstep) / 256;
3330 yp = fill_data.ymin + (j + yhstep) / 256;
3333 * Average over all four corners + scale by diagsize to
3334 * reduce the effect of the square grid on the shape of the fractal
3336 store_height(ii, jj,
3337 (cave[ym][xm].feat + cave[yp][xm].feat
3338 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3339 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3348 static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int feat2, int feat3, int info1, int info2, int info3)
3351 * function used to convert from height-map back to the
3352 * normal angband cave format
3354 if (cave[y][x].info & CAVE_ICKY)
3361 /* Show that have looked at this square */
3362 cave[y][x].info|= (CAVE_ICKY);
3364 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3365 if (cave[y][x].feat <= c1)
3367 /* 25% of the time use the other tile : it looks better this way */
3368 if (randint1(100) < 75)
3370 cave[y][x].feat = feat1;
3371 cave[y][x].info &= ~(CAVE_MASK);
3372 cave[y][x].info |= info1;
3377 cave[y][x].feat = feat2;
3378 cave[y][x].info &= ~(CAVE_MASK);
3379 cave[y][x].info |= info2;
3383 else if (cave[y][x].feat <= c2)
3385 /* 25% of the time use the other tile : it looks better this way */
3386 if (randint1(100) < 75)
3388 cave[y][x].feat = feat2;
3389 cave[y][x].info &= ~(CAVE_MASK);
3390 cave[y][x].info |= info2;
3395 cave[y][x].feat = feat1;
3396 cave[y][x].info &= ~(CAVE_MASK);
3397 cave[y][x].info |= info1;
3401 else if (cave[y][x].feat <= c3)
3403 cave[y][x].feat = feat3;
3404 cave[y][x].info |= info3;
3407 /* if greater than cutoff then is a wall */
3410 place_outer_bold(y, x);
3420 * Quick and nasty fill routine used to find the connected region
3421 * of floor in the middle of the cave
3423 static void cave_fill(byte y, byte x)
3432 /*** Start Grid ***/
3434 /* Enqueue that entry */
3439 /* Now process the queue */
3440 while (flow_head != flow_tail)
3442 /* Extract the next entry */
3443 ty = temp_y[flow_head];
3444 tx = temp_x[flow_head];
3446 /* Forget that entry */
3447 if (++flow_head == TEMP_MAX) flow_head = 0;
3449 /* Add the "children" */
3450 for (d = 0; d < 8; d++)
3452 int old_head = flow_tail;
3454 /* Child location */
3455 j = ty + ddy_ddd[d];
3456 i = tx + ddx_ddd[d];
3458 /* Paranoia Don't leave the cave */
3459 if (!in_bounds(j, i))
3461 /* affect boundary */
3462 cave[j][i].info |= CAVE_ICKY;
3466 /* If within bounds */
3467 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3468 && (j > fill_data.ymin) && (j < fill_data.ymax))
3470 /* If not a wall or floor done before */
3471 if (hack_isnt_wall(j, i,
3472 fill_data.c1, fill_data.c2, fill_data.c3,
3473 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3474 fill_data.info1, fill_data.info2, fill_data.info3))
3476 /* Enqueue that entry */
3477 temp_y[flow_tail] = j;
3478 temp_x[flow_tail] = i;
3480 /* Advance the queue */
3481 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3483 /* Hack -- Overflow by forgetting new entry */
3484 if (flow_tail == flow_head)
3486 flow_tail = old_head;
3490 /* keep tally of size of cave system */
3491 (fill_data.amount)++;
3497 /* affect boundary */
3498 cave[j][i].info |= CAVE_ICKY;
3505 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3507 int x, y, i, xhsize, yhsize;
3509 /* offsets to middle from corner */
3515 * select region connected to center of cave system
3516 * this gets rid of alot of isolated one-sqaures that
3517 * can make teleport traps instadeaths...
3521 fill_data.c1 = cutoff;
3525 /* features to fill with */
3526 fill_data.feat1 = floor_type[randint0(100)];
3527 fill_data.feat2 = floor_type[randint0(100)];
3528 fill_data.feat3 = floor_type[randint0(100)];
3530 fill_data.info1 = CAVE_FLOOR;
3531 fill_data.info2 = CAVE_FLOOR;
3532 fill_data.info3 = CAVE_FLOOR;
3534 /* number of filled squares */
3535 fill_data.amount = 0;
3537 cave_fill((byte)y0, (byte)x0);
3539 /* if tally too small, try again */
3540 if (fill_data.amount < 10)
3542 /* too small - clear area and try again later */
3543 for (x = 0; x <= xsize; ++x)
3545 for (y = 0; y <= ysize; ++y)
3547 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3548 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3555 * Do boundarys-check to see if they are next to a filled region
3556 * If not then they are set to normal granite
3557 * If so then they are marked as room walls.
3559 for (i = 0; i <= xsize; ++i)
3562 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3564 /* Next to a 'filled' region? - set to be room walls */
3565 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3566 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3567 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3568 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3572 /* set to be normal granite */
3573 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3576 /* bottom boundary */
3577 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3579 /* Next to a 'filled' region? - set to be room walls */
3580 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3581 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3582 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3583 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3587 /* set to be normal granite */
3588 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3591 /* clear the icky flag-don't need it any more */
3592 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3593 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3596 /* Do the left and right boundaries minus the corners (done above) */
3597 for (i = 1; i < ysize; ++i)
3600 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3603 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3604 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3605 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3606 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3611 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3613 /* right boundary */
3614 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3617 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3618 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3619 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3620 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3625 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3628 /* clear icky flag -done with it */
3629 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3630 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3634 /* Do the rest: convert back to the normal format */
3635 for (x = 1; x < xsize; ++x)
3637 for (y = 1; y < ysize; ++y)
3639 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3640 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3642 /* Clear the icky flag in the filled region */
3643 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3645 /* Set appropriate flags */
3646 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3647 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3649 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3650 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3653 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3654 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3657 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3662 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3663 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3668 /* Clear the unconnected regions */
3669 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3670 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3676 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3677 * Extra doors appear inside the system. (Its not very noticeable though.)
3678 * This can be removed by "filling" from the outside in. This allows a separation
3679 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
3680 * The extra effort for what seems to be only a minor thing (even non-existant if you
3681 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3690 * Driver routine to create fractal cave system
3692 static bool build_type9(void)
3694 int grd, roug, cutoff, xsize, ysize, y0, x0;
3696 bool done, light, room;
3698 /* get size: note 'Evenness'*/
3699 xsize = randint1(22) * 2 + 6;
3700 ysize = randint1(15) * 2 + 6;
3702 /* Find and reserve some space in the dungeon. Get center of room. */
3703 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
3705 light = done = FALSE;
3708 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3712 /* Note: size must be even or there are rounding problems
3713 * This causes the tunnels not to connect properly to the room */
3715 /* testing values for these parameters feel free to adjust */
3716 grd = 1 << (randint0(4));
3718 /* want average of about 16 */
3719 roug = randint1(8) * randint1(4);
3722 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3723 randint1(xsize / 4) + randint1(ysize / 4);
3726 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3728 /* Convert to normal format + clean up */
3729 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3735 #ifdef ALLOW_CAVERNS_AND_LAKES
3737 * Builds a cave system in the center of the dungeon.
3739 void build_cavern(void)
3741 int grd, roug, cutoff, xsize, ysize, x0, y0;
3744 light = done = FALSE;
3745 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3747 /* Make a cave the size of the dungeon */
3748 xsize = cur_wid - 1;
3749 ysize = cur_hgt - 1;
3753 /* Paranoia: make size even */
3759 /* testing values for these parameters: feel free to adjust */
3760 grd = randint1(4) + 4;
3762 /* want average of about 16 */
3763 roug = randint1(8) * randint1(4);
3769 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3771 /* Convert to normal format+ clean up */
3772 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3776 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3778 int x, y, i, xhsize, yhsize;
3779 int feat1, feat2, feat3;
3781 /* offsets to middle from corner */
3785 /* Get features based on type */
3788 case LAKE_T_LAVA: /* Lava */
3789 feat1 = FEAT_DEEP_LAVA;
3790 feat2 = FEAT_SHAL_LAVA;
3791 feat3 = floor_type[randint0(100)];
3793 case LAKE_T_WATER: /* Water */
3794 feat1 = FEAT_DEEP_WATER;
3795 feat2 = FEAT_SHAL_WATER;
3796 feat3 = floor_type[randint0(100)];
3798 case LAKE_T_CAVE: /* Collapsed cave */
3799 feat1 = floor_type[randint0(100)];
3800 feat2 = floor_type[randint0(100)];
3801 feat3 = FEAT_RUBBLE;
3803 case LAKE_T_EARTH_VAULT: /* Earth vault */
3804 feat1 = FEAT_RUBBLE;
3805 feat2 = floor_type[randint0(100)];
3806 feat3 = FEAT_RUBBLE;
3808 case LAKE_T_AIR_VAULT: /* Air vault */
3813 case LAKE_T_WATER_VAULT: /* Water vault */
3814 feat1 = FEAT_SHAL_WATER;
3815 feat2 = FEAT_DEEP_WATER;
3816 feat3 = FEAT_SHAL_WATER;
3818 case LAKE_T_FIRE_VAULT: /* Fire Vault */
3819 feat1 = FEAT_SHAL_LAVA;
3820 feat2 = FEAT_DEEP_LAVA;
3821 feat3 = FEAT_SHAL_LAVA;
3825 default: return FALSE;
3829 * select region connected to center of cave system
3830 * this gets rid of alot of isolated one-sqaures that
3831 * can make teleport traps instadeaths...
3839 /* features to fill with */
3840 fill_data.feat1 = feat1;
3841 fill_data.feat2 = feat2;
3842 fill_data.feat3 = feat3;
3844 fill_data.info1 = 0;
3845 fill_data.info2 = 0;
3846 fill_data.info3 = 0;
3848 /* number of filled squares */
3849 fill_data.amount = 0;
3851 /* select region connected to center of cave system
3852 * this gets rid of alot of isolated one-sqaures that
3853 * can make teleport traps instadeaths... */
3854 cave_fill((byte)y0, (byte)x0);
3856 /* if tally too small, try again */
3857 if (fill_data.amount < 10)
3859 /* too small -clear area and try again later */
3860 for (x = 0; x <= xsize; ++x)
3862 for (y = 0; y <= ysize; ++y)
3864 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3865 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3871 /* Do boundarys- set to normal granite */
3872 for (i = 0; i <= xsize; ++i)
3874 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3875 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3877 /* clear the icky flag-don't need it any more */
3878 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3879 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3882 /* Do the left and right boundaries minus the corners (done above) */
3884 for (i = 1; i < ysize; ++i)
3886 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3887 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3889 /* clear icky flag -done with it */
3890 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3891 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3895 /* Do the rest: convert back to the normal format */
3896 for (x = 1; x < xsize; ++x)
3898 for (y = 1; y < ysize; ++y)
3900 /* Fill unconnected regions with granite */
3901 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3902 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3903 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3905 /* turn off icky flag (no longer needed.) */
3906 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3909 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
3911 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3921 * makes a lake/collapsed cave system in the center of the dungeon
3923 void build_lake(int type)
3925 int grd, roug, xsize, ysize, x0, y0;
3929 /* paranoia - exit if lake type out of range. */
3930 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
3932 msg_format("Invalid lake type (%d)", type);
3936 /* Make the size of the dungeon */
3937 xsize = cur_wid - 1;
3938 ysize = cur_hgt - 1;
3942 /* Paranoia: make size even */
3948 /* testing values for these parameters: feel free to adjust */
3949 grd = randint1(3) + 4;
3951 /* want average of about 16 */
3952 roug = randint1(8) * randint1(4);
3954 /* Make up size of various componants */
3958 /* Deep water/lava */
3959 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
3961 /* Shallow boundary */
3965 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
3967 /* Convert to normal format+ clean up */
3968 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
3971 #endif /* ALLOW_CAVERNS_AND_LAKES */
3975 * Routine used by the random vault creators to add a door to a location
3976 * Note that range checking has to be done in the calling routine.
3978 * The doors must be INSIDE the allocated region.
3980 static void add_door(int x, int y)
3982 /* Need to have a wall in the center square */
3983 if (!is_outer_bold(y, x)) return;
3990 * where x=don't care
3994 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
3995 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
3998 place_secret_door(y, x);
4000 /* set boundarys so don't get wide doors */
4001 place_solid_bold(y, x - 1);
4002 place_solid_bold(y, x + 1);
4011 * where x = don't care
4014 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4015 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4018 place_secret_door(y, x);
4020 /* set boundarys so don't get wide doors */
4021 place_solid_bold(y - 1, x);
4022 place_solid_bold(y + 1, x);
4028 * Routine that fills the empty areas of a room with treasure and monsters.
4030 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4032 int x, y, cx, cy, size;
4035 /* center of room:*/
4039 /* Rough measure of size of vault= sum of lengths of sides */
4040 size = abs(x2 - x1) + abs(y2 - y1);
4042 for (x = x1; x <= x2; x++)
4044 for (y = y1; y <= y2; y++)
4046 /* Thing added based on distance to center of vault
4047 * Difficulty is 1-easy to 10-hard */
4048 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4050 /* hack- empty square part of the time */
4051 if ((randint1(100) - difficulty * 3) > 50) value = 20;
4053 /* if floor, shallow water and lava */
4054 if (is_floor_bold(y, x) ||
4055 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4057 /* The smaller 'value' is, the better the stuff */
4060 /* Meanest monster + treasure */
4061 monster_level = base_level + 40;
4062 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4063 monster_level = base_level;
4064 object_level = base_level + 20;
4065 place_object(y, x, AM_GOOD);
4066 object_level = base_level;
4070 /* Mean monster +treasure */
4071 monster_level = base_level + 20;
4072 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4073 monster_level = base_level;
4074 object_level = base_level + 10;
4075 place_object(y, x, AM_GOOD);
4076 object_level = base_level;
4078 else if (value < 10)
4081 monster_level = base_level + 9;
4082 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4083 monster_level = base_level;
4085 else if (value < 17)
4087 /* Intentional Blank space */
4090 * (Want some of the vault to be empty
4091 * so have room for group monsters.
4092 * This is used in the hack above to lower
4093 * the density of stuff in the vault.)
4096 else if (value < 23)
4098 /* Object or trap */
4099 if (randint0(100) < 25)
4101 place_object(y, x, 0L);
4108 else if (value < 30)
4110 /* Monster and trap */
4111 monster_level = base_level + 5;
4112 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4113 monster_level = base_level;
4116 else if (value < 40)
4118 /* Monster or object */
4119 if (randint0(100) < 50)
4121 monster_level = base_level + 3;
4122 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4123 monster_level = base_level;
4125 if (randint0(100) < 50)
4127 object_level = base_level + 7;
4128 place_object(y, x, 0L);
4129 object_level = base_level;
4132 else if (value < 50)
4141 /* 20% monster, 40% trap, 20% object, 20% blank space */
4142 if (randint0(100) < 20)
4144 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4146 else if (randint0(100) < 50)
4150 else if (randint0(100) < 50)
4152 place_object(y, x, 0L);
4163 * This function creates a random vault that looks like a collection of bubbles.
4164 * It works by getting a set of coordinates that represent the center of each
4165 * bubble. The entire room is made by seeing which bubble center is closest. If
4166 * two centers are equidistant then the square is a wall, otherwise it is a floor.
4167 * The only exception is for squares really near a center, these are always floor.
4168 * (It looks better than without this check.)
4170 * Note: If two centers are on the same point then this algorithm will create a
4171 * blank bubble filled with walls. - This is prevented from happening.
4173 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4175 #define BUBBLENUM 10 /* number of bubbles */
4177 /* array of center points of bubbles */
4178 coord center[BUBBLENUM];
4181 u16b min1, min2, temp;
4184 /* Offset from center to top left hand corner */
4185 int xhsize = xsize / 2;
4186 int yhsize = ysize / 2;
4189 if (cheat_room) msg_print("Bubble Vault");
4191 /* Allocate center of bubbles */
4192 center[0].x = randint1(xsize - 3) + 1;
4193 center[0].y = randint1(ysize - 3) + 1;
4195 for (i = 1; i < BUBBLENUM; i++)
4199 /* get center and check to see if it is unique */
4204 x = randint1(xsize - 3) + 1;
4205 y = randint1(ysize - 3) + 1;
4207 for (j = 0; j < i; j++)
4209 /* rough test to see if there is an overlap */
4210 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4219 /* Top and bottom boundaries */
4220 for (i = 0; i < xsize; i++)
4222 int x = x0 - xhsize + i;
4224 place_outer_noperm_bold(y0 - yhsize + 0, x);
4225 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4226 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4227 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4230 /* Left and right boundaries */
4231 for (i = 1; i < ysize - 1; i++)
4233 int y = y0 - yhsize + i;
4235 place_outer_noperm_bold(y, x0 - xhsize + 0);
4236 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4237 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4238 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4241 /* Fill in middle with bubbles */
4242 for (x = 1; x < xsize - 1; x++)
4244 for (y = 1; y < ysize - 1; y++)
4246 /* Get distances to two closest centers */
4249 min1 = distance(x, y, center[0].x, center[0].y);
4250 min2 = distance(x, y, center[1].x, center[1].y);
4254 /* swap if in wrong order */
4261 for (i = 2; i < BUBBLENUM; i++)
4263 temp = distance(x, y, center[i].x, center[i].y);
4271 else if (temp < min2)
4273 /* second smallest */
4277 if (((min2 - min1) <= 2) && (!(min1 < 3)))
4279 /* Boundary at midpoint+ not at inner region of bubble */
4280 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4284 /* middle of a bubble */
4285 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4288 /* clean up rest of flags */
4289 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4293 /* Try to add some random doors */
4294 for (i = 0; i < 500; i++)
4296 x = randint1(xsize - 3) - xhsize + x0 + 1;
4297 y = randint1(ysize - 3) - yhsize + y0 + 1;
4301 /* Fill with monsters and treasure, low difficulty */
4302 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4307 * Overlay a rectangular room given its bounds
4308 * This routine is used by build_room_vault
4309 * The area inside the walls is not touched:
4310 * only granite is removed- normal walls stay
4312 static void build_room(int x1, int x2, int y1, int y2)
4314 int x, y, i, xsize, ysize, temp;
4316 /* Check if rectangle has no width */
4317 if ((x1 == x2) || (y1 == y2)) return;
4322 /* Swap boundaries if in wrong order */
4330 /* Swap boundaries if in wrong order */
4336 /* get total widths */
4341 /* Top and bottom boundaries */
4342 for (i = 0; i <= xsize; i++)
4344 place_outer_noperm_bold(y1, x1 + i);
4345 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4346 place_outer_noperm_bold(y2, x1 + i);
4347 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4350 /* Left and right boundaries */
4351 for (i = 1; i < ysize; i++)
4353 place_outer_noperm_bold(y1 + i, x1);
4354 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4355 place_outer_noperm_bold(y1 + i, x2);
4356 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4360 for (x = 1; x < xsize; x++)
4362 for (y = 1; y < ysize; y++)
4364 if (is_extra_bold(y1+y, x1+x))
4366 /* clear the untouched region */
4367 place_floor_bold(y1 + y, x1 + x);
4368 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4372 /* make it a room- but don't touch */
4373 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4380 /* Create a random vault that looks like a collection of overlapping rooms */
4382 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4384 int i, x1, x2, y1, y2, xhsize, yhsize;
4386 /* get offset from center */
4390 if (cheat_room) msg_print("Room Vault");
4392 /* fill area so don't get problems with arena levels */
4393 for (x1 = 0; x1 < xsize; x1++)
4395 int x = x0 - xhsize + x1;
4397 for (y1 = 0; y1 < ysize; y1++)
4399 int y = y0 - yhsize + y1;
4401 place_extra_bold(y, x);
4402 cave[y][x].info &= (~CAVE_ICKY);
4406 /* add ten random rooms */
4407 for (i = 0; i < 10; i++)
4409 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4410 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4411 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4412 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4413 build_room(x1, x2, y1, y2);
4416 /* Add some random doors */
4417 for (i = 0; i < 500; i++)
4419 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4420 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4424 /* Fill with monsters and treasure, high difficulty */
4425 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4429 /* Create a random vault out of a fractal cave */
4430 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4432 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4433 bool done, light, room;
4435 /* round to make sizes even */
4441 if (cheat_room) msg_print("Cave Vault");
4443 light = done = FALSE;
4448 /* testing values for these parameters feel free to adjust */
4449 grd = 1 << randint0(4);
4451 /* want average of about 16 */
4452 roug = randint1(8) * randint1(4);
4455 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4456 randint1(xsize / 4) + randint1(ysize / 4);
4459 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4461 /* Convert to normal format+ clean up */
4462 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4465 /* Set icky flag because is a vault */
4466 for (x = 0; x <= xsize; x++)
4468 for (y = 0; y <= ysize; y++)
4470 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4474 /* Fill with monsters and treasure, low difficulty */
4475 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4479 * maze vault -- rectangular labyrinthine rooms
4481 * maze vault uses two routines:
4482 * r_visit - a recursive routine that builds the labyrinth
4483 * build_maze_vault - a driver routine that calls r_visit and adds
4484 * monsters, traps and treasure
4486 * The labyrinth is built by creating a spanning tree of a graph.
4487 * The graph vertices are at
4488 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4489 * and the edges are the vertical and horizontal nearest neighbors.
4491 * The spanning tree is created by performing a suitably randomized
4492 * depth-first traversal of the graph. The only adjustable parameter
4493 * is the randint0(3) below; it governs the relative density of
4494 * twists and turns in the labyrinth: smaller number, more twists.
4496 static void r_visit(int y1, int x1, int y2, int x2,
4497 int node, int dir, int *visited)
4499 int i, j, m, n, temp, x, y, adj[4];
4501 /* dimensions of vertex array */
4502 m = (x2 - x1) / 2 + 1;
4503 n = (y2 - y1) / 2 + 1;
4505 /* mark node visited and set it to a floor */
4507 x = 2 * (node % m) + x1;
4508 y = 2 * (node / m) + y1;
4509 place_floor_bold(y, x);
4511 /* setup order of adjacent node visits */
4514 /* pick a random ordering */
4515 for (i = 0; i < 4; i++)
4517 for (i = 0; i < 4; i++)
4528 /* pick a random ordering with dir first */
4530 for (i = 1; i < 4; i++)
4532 for (i = 1; i < 4; i++)
4534 j = 1 + randint0(3);
4541 for (i = 0; i < 4; i++)
4546 /* (0,+) - check for bottom boundary */
4547 if ((node / m < n - 1) && (visited[node + m] == 0))
4549 place_floor_bold(y + 1, x);
4550 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4554 /* (0,-) - check for top boundary */
4555 if ((node / m > 0) && (visited[node - m] == 0))
4557 place_floor_bold(y - 1, x);
4558 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4562 /* (+,0) - check for right boundary */
4563 if ((node % m < m - 1) && (visited[node + 1] == 0))
4565 place_floor_bold(y, x + 1);
4566 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4570 /* (-,0) - check for left boundary */
4571 if ((node % m > 0) && (visited[node - 1] == 0))
4573 place_floor_bold(y, x - 1);
4574 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4581 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4585 int m, n, num_vertices, *visited;
4590 if (cheat_room && is_vault) msg_print("Maze Vault");
4592 /* Choose lite or dark */
4593 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4595 /* Pick a random room size - randomized by calling routine */
4604 /* generate the room */
4605 for (y = y1 - 1; y <= y2 + 1; y++)
4607 for (x = x1 - 1; x <= x2 + 1; x++)
4609 c_ptr = &cave[y][x];
4610 c_ptr->info |= CAVE_ROOM;
4611 if (is_vault) c_ptr->info |= CAVE_ICKY;
4612 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4614 place_outer_grid(c_ptr);
4618 place_extra_grid(c_ptr);
4622 place_inner_grid(c_ptr);
4624 if (light) c_ptr->info |= (CAVE_GLOW);
4628 /* dimensions of vertex array */
4631 num_vertices = m * n;
4633 /* initialize array of visited vertices */
4634 C_MAKE(visited, num_vertices, int);
4636 /* traverse the graph to create a spaning tree, pick a random root */
4637 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4639 /* Fill with monsters and treasure, low difficulty */
4640 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4642 C_KILL(visited, num_vertices, int);
4646 /* Build a "mini" checkerboard vault
4648 * This is done by making a permanent wall maze and setting
4649 * the diagonal sqaures of the checker board to be granite.
4650 * The vault has two entrances on opposite sides to guarantee
4651 * a way to get in even if the vault abuts a side of the dungeon.
4653 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4656 int y1, x1, y2, x2, y, x, total;
4657 int m, n, num_vertices;
4660 if (cheat_room) msg_print("Mini Checker Board Vault");
4662 /* Pick a random room size */
4672 /* generate the room */
4673 for (x = x1 - 2; x <= x2 + 2; x++)
4675 if (!in_bounds(y1-2,x)) break;
4677 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4679 place_outer_noperm_bold(y1-2, x);
4682 for (x = x1 - 2; x <= x2 + 2; x++)
4684 if (!in_bounds(y2+2,x)) break;
4686 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4688 place_outer_noperm_bold(y2+2, x);
4691 for (y = y1 - 2; y <= y2 + 2; y++)
4693 if (!in_bounds(y,x1-2)) break;
4695 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4697 place_outer_noperm_bold(y, x1-2);
4700 for (y = y1 - 2; y <= y2 + 2; y++)
4702 if (!in_bounds(y,x2+2)) break;
4704 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4706 place_outer_noperm_bold(y, x2+2);
4709 for (y = y1 - 1; y <= y2 + 1; y++)
4711 for (x = x1 - 1; x <= x2 + 1; x++)
4713 cave_type *c_ptr = &cave[y][x];
4715 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4717 /* Permanent walls */
4718 place_inner_perm_grid(c_ptr);
4723 /* dimensions of vertex array */
4726 num_vertices = m * n;
4728 /* initialize array of visited vertices */
4729 C_MAKE(visited, num_vertices, int);
4731 /* traverse the graph to create a spannng tree, pick a random root */
4732 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4734 /* Make it look like a checker board vault */
4735 for (x = x1; x <= x2; x++)
4737 for (y = y1; y <= y2; y++)
4739 total = x - x1 + y - y1;
4740 /* If total is odd- and is a floor then make a wall */
4741 if ((total % 2 == 1) && is_floor_bold(y, x))
4743 place_inner_bold(y, x);
4748 /* Make a couple of entrances */
4751 /* left and right */
4752 y = randint1(dy) + dy / 2;
4753 place_inner_bold(y1 + y, x1 - 1);
4754 place_inner_bold(y1 + y, x2 + 1);
4758 /* top and bottom */
4759 x = randint1(dx) + dx / 2;
4760 place_inner_bold(y1 - 1, x1 + x);
4761 place_inner_bold(y2 + 1, x1 + x);
4764 /* Fill with monsters and treasure, highest difficulty */
4765 fill_treasure(x1, x2, y1, y2, 10);
4767 C_KILL(visited, num_vertices, int);
4771 /* Build a town/ castle by using a recursive algorithm.
4772 * Basically divide each region in a probalistic way to create
4773 * smaller regions. When the regions get too small stop.
4775 * The power variable is a measure of how well defended a region is.
4776 * This alters the possible choices.
4778 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4784 /* Temp variables */
4790 if ((power < 3) && (xsize > 12) && (ysize > 12))
4792 /* Need outside wall +keep */
4799 /* Make rooms + subdivide */
4800 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4806 choice = randint1(2) + 1;
4811 /* Mostly subdivide */
4812 choice = randint1(3) + 1;
4816 /* Based on the choice made above, do something */
4824 /* top and bottom */
4825 for (x = x1; x <= x2; x++)
4827 place_outer_bold(y1, x);
4828 place_outer_bold(y2, x);
4831 /* left and right */
4832 for (y = y1 + 1; y < y2; y++)
4834 place_outer_bold(y, x1);
4835 place_outer_bold(y, x2);
4838 /* Make a couple of entrances */
4841 /* left and right */
4842 y = randint1(ysize) + y1;
4843 place_floor_bold(y, x1);
4844 place_floor_bold(y, x2);
4848 /* top and bottom */
4849 x = randint1(xsize) + x1;
4850 place_floor_bold(y1, x);
4851 place_floor_bold(y2, x);
4854 /* Select size of keep */
4855 t1 = randint1(ysize / 3) + y1;
4856 t2 = y2 - randint1(ysize / 3);
4857 t3 = randint1(xsize / 3) + x1;
4858 t4 = x2 - randint1(xsize / 3);
4860 /* Do outside areas */
4862 /* Above and below keep */
4863 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4864 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4866 /* Left and right of keep */
4867 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4868 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4870 /* Make the keep itself: */
4883 /* Try to build a room */
4884 if ((xsize < 3) || (ysize < 3))
4886 for (y = y1; y < y2; y++)
4888 for (x = x1; x < x2; x++)
4890 place_inner_bold(y, x);
4898 /* Make outside walls */
4899 /* top and bottom */
4900 for (x = x1 + 1; x <= x2 - 1; x++)
4902 place_inner_bold(y1 + 1, x);
4903 place_inner_bold(y2 - 1, x);
4906 /* left and right */
4907 for (y = y1 + 1; y <= y2 - 1; y++)
4909 place_inner_bold(y, x1 + 1);
4910 place_inner_bold(y, x2 - 1);
4914 y = randint1(ysize - 3) + y1 + 1;
4919 place_floor_bold(y, x1 + 1);
4924 place_floor_bold(y, x2 - 1);
4927 /* Build the room */
4928 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4933 /* Try and divide vertically */
4937 for (y = y1; y < y2; y++)
4939 for (x = x1; x < x2; x++)
4941 place_inner_bold(y, x);
4947 t1 = randint1(xsize - 2) + x1 + 1;
4948 build_recursive_room(x1, y1, t1, y2, power - 2);
4949 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
4954 /* Try and divide horizontally */
4958 for (y = y1; y < y2; y++)
4960 for (x = x1; x < x2; x++)
4962 place_inner_bold(y, x);
4968 t1 = randint1(ysize - 2) + y1 + 1;
4969 build_recursive_room(x1, y1, x2, t1, power - 2);
4970 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
4977 /* Build a castle */
4979 /* Driver routine: clear the region and call the recursive
4982 *This makes a vault that looks like a castle/ city in the dungeon.
4984 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
4990 /* Pick a random room size */
4999 if (cheat_room) msg_print("Castle Vault");
5001 /* generate the room */
5002 for (y = y1 - 1; y <= y2 + 1; y++)
5004 for (x = x1 - 1; x <= x2 + 1; x++)
5006 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5007 /* Make everything a floor */
5008 place_floor_bold(y, x);
5012 /* Make the castle */
5013 build_recursive_room(x1, y1, x2, y2, randint1(5));
5015 /* Fill with monsters and treasure, low difficulty */
5016 fill_treasure(x1, x2, y1, y2, randint1(3));
5021 * Add outer wall to a floored region
5022 * Note: no range checking is done so must be inside dungeon
5023 * This routine also stomps on doors
5025 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5028 feature_type *f_ptr;
5031 if (!in_bounds(y, x)) return;
5033 c_ptr = &cave[y][x];
5035 /* hack- check to see if square has been visited before
5036 * if so, then exit (use room flag to do this) */
5037 if (c_ptr->info & CAVE_ROOM) return;
5040 c_ptr->info |= CAVE_ROOM;
5042 f_ptr = &f_info[c_ptr->feat];
5044 if (is_floor_bold(y, x))
5046 for (i = -1; i <= 1; i++)
5048 for (j = -1; j <= 1; j++)
5050 if ((x + i >= x1) && (x + i <= x2) &&
5051 (y + j >= y1) && (y + j <= y2))
5053 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5054 if (light) c_ptr->info |= CAVE_GLOW;
5059 else if (is_extra_bold(y, x))
5061 /* Set bounding walls */
5062 place_outer_bold(y, x);
5063 if (light) c_ptr->info |= CAVE_GLOW;
5065 else if (permanent_wall(f_ptr))
5067 /* Set bounding walls */
5068 if (light) c_ptr->info |= CAVE_GLOW;
5074 * Hacked distance formula - gives the 'wrong' answer.
5075 * Used to build crypts
5077 static int dist2(int x1, int y1, int x2, int y2,
5078 int h1, int h2, int h3, int h4)
5084 /* Basically this works by taking the normal pythagorean formula
5085 * and using an expansion to express this in a way without the
5086 * square root. This approximate formula is then perturbed to give
5087 * the distorted results. (I found this by making a mistake when I was
5088 * trying to fix the circular rooms.)
5091 /* h1-h4 are constants that describe the metric */
5092 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5093 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5094 return (((dx + dy) * 128) / 181 +
5095 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5096 /* 128/181 is approx. 1/sqrt(2) */
5101 * Build target vault.
5102 * This is made by two concentric "crypts" with perpendicular
5103 * walls creating the cross-hairs.
5105 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5109 /* Make a random metric */
5111 h1 = randint1(32) - 16;
5114 h4 = randint1(32) - 16;
5116 if (cheat_room) msg_print("Target Vault");
5118 /* work out outer radius */
5129 for (x = x0 - rad; x <= x0 + rad; x++)
5131 for (y = y0 - rad; y <= y0 + rad; y++)
5133 /* clear room flag */
5134 cave[y][x].info &= ~(CAVE_ROOM);
5136 /* Vault - so is "icky" */
5137 cave[y][x].info |= CAVE_ICKY;
5139 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5141 /* inside- so is floor */
5142 place_floor_bold(y, x);
5146 /* make granite outside so arena works */
5147 place_extra_bold(y, x);
5150 /* proper boundary for arena */
5151 if (((y + rad) == y0) || ((y - rad) == y0) ||
5152 ((x + rad) == x0) || ((x - rad) == x0))
5154 place_extra_bold(y, x);
5159 /* Find visible outer walls and set to be FEAT_OUTER */
5160 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5161 x0 + rad + 1, y0 + rad + 1);
5163 /* Add inner wall */
5164 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5166 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5168 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5170 /* Make an internal wall */
5171 place_inner_bold(y, x);
5176 /* Add perpendicular walls */
5177 for (x = x0 - rad; x <= x0 + rad; x++)
5179 place_inner_bold(y0, x);
5182 for (y = y0 - rad; y <= y0 + rad; y++)
5184 place_inner_bold(y, x0);
5187 /* Make inner vault */
5188 for (y = y0 - 1; y <= y0 + 1; y++)
5190 place_inner_bold(y, x0 - 1);
5191 place_inner_bold(y, x0 + 1);
5193 for (x = x0 - 1; x <= x0 + 1; x++)
5195 place_inner_bold(y0 - 1, x);
5196 place_inner_bold(y0 + 1, x);
5199 place_floor_bold(y0, x0);
5202 /* Add doors to vault */
5203 /* get two distances so can place doors relative to centre */
5204 x = (rad - 2) / 4 + 1;
5207 add_door(x0 + x, y0);
5208 add_door(x0 + y, y0);
5209 add_door(x0 - x, y0);
5210 add_door(x0 - y, y0);
5211 add_door(x0, y0 + x);
5212 add_door(x0, y0 + y);
5213 add_door(x0, y0 - x);
5214 add_door(x0, y0 - y);
5216 /* Fill with stuff - medium difficulty */
5217 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5221 #ifdef ALLOW_CAVERNS_AND_LAKES
5223 * This routine uses a modified version of the lake code to make a
5224 * distribution of some terrain type over the vault. This type
5225 * depends on the dungeon depth.
5227 * Miniture rooms are then scattered across the vault.
5229 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5234 int xsize, ysize, xhsize, yhsize, x, y, i;
5238 if (cheat_room) msg_print("Elemental Vault");
5240 /* round to make sizes even */
5248 /* Earth vault (Rubble) */
5249 type = LAKE_T_EARTH_VAULT;
5251 else if (dun_level < 50)
5253 /* Air vault (Trees) */
5254 type = LAKE_T_AIR_VAULT;
5256 else if (dun_level < 75)
5258 /* Water vault (shallow water) */
5259 type = LAKE_T_WATER_VAULT;
5263 /* Fire vault (shallow lava) */
5264 type = LAKE_T_FIRE_VAULT;
5269 /* testing values for these parameters: feel free to adjust */
5270 grd = 1 << (randint0(3));
5272 /* want average of about 16 */
5273 roug = randint1(8) * randint1(4);
5275 /* Make up size of various componants */
5279 /* Deep water/lava */
5280 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5282 /* Shallow boundary */
5286 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5288 /* Convert to normal format+ clean up */
5289 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5292 /* Set icky flag because is a vault */
5293 for (x = 0; x <= xsize; x++)
5295 for (y = 0; y <= ysize; y++)
5297 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5301 /* make a few rooms in the vault */
5302 for (i = 1; i <= (xsize * ysize) / 50; i++)
5304 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5305 y0 + randint0(ysize - 4) - ysize / 2 + 2);
5308 /* Fill with monsters and treasure, low difficulty */
5309 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5310 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5312 #endif /* ALLOW_CAVERNS_AND_LAKES */
5318 static bool build_type10(void)
5320 int y0, x0, xsize, ysize, vtype;
5323 /* big enough to look good, small enough to be fairly common. */
5324 xsize = randint1(22) + 22;
5325 ysize = randint1(11) + 11;
5327 /* Find and reserve some space in the dungeon. Get center of room. */
5328 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5330 /* Boost the rating- higher than lesser vaults and lower than greater vaults */
5333 /* (Sometimes) Cause a special feeling */
5334 if ((dun_level <= 50) ||
5335 (randint1((dun_level - 40) * (dun_level - 40) + 1) < 400))
5337 good_item_flag = TRUE;
5340 /* Select type of vault */
5341 #ifdef ALLOW_CAVERNS_AND_LAKES
5342 vtype = randint1(15);
5343 #else /* ALLOW_CAVERNS_AND_LAKES */
5344 vtype = randint1(7);
5345 #endif /* ALLOW_CAVERNS_AND_LAKES */
5349 /* Build an appropriate room */
5350 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
5351 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5352 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5353 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5354 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5355 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5356 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5357 #ifdef ALLOW_CAVERNS_AND_LAKES
5358 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5359 #endif /* ALLOW_CAVERNS_AND_LAKES */
5360 /* I know how to add a few more... give me some time. */
5363 default: return FALSE;
5371 * Build an vertical oval room.
5372 * For every grid in the possible square, check the distance.
5373 * If it's less than the radius, make it a room square.
5375 * When done fill from the inside to find the walls,
5377 static bool build_type11(void)
5379 int rad, x, y, x0, y0;
5382 /* Occasional light */
5383 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5387 /* Find and reserve some space in the dungeon. Get center of room. */
5388 if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5390 /* Make circular floor */
5391 for (x = x0 - rad; x <= x0 + rad; x++)
5393 for (y = y0 - rad; y <= y0 + rad; y++)
5395 if (distance(y0, x0, y, x) <= rad - 1)
5397 /* inside- so is floor */
5398 place_floor_bold(y, x);
5400 else if (distance(y0, x0, y, x) <= rad + 1)
5402 /* make granite outside so arena works */
5403 place_extra_bold(y, x);
5408 /* Find visible outer walls and set to be FEAT_OUTER */
5409 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5417 * For every grid in the possible square, check the (fake) distance.
5418 * If it's less than the radius, make it a room square.
5420 * When done fill from the inside to find the walls,
5422 static bool build_type12(void)
5424 int rad, x, y, x0, y0;
5426 bool emptyflag = TRUE;
5428 /* Make a random metric */
5430 h1 = randint1(32) - 16;
5433 h4 = randint1(32) - 16;
5435 /* Occasional light */
5436 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5440 /* Find and reserve some space in the dungeon. Get center of room. */
5441 if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5444 for (x = x0 - rad; x <= x0 + rad; x++)
5446 for (y = y0 - rad; y <= y0 + rad; y++)
5448 /* clear room flag */
5449 cave[y][x].info &= ~(CAVE_ROOM);
5451 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5453 /* inside - so is floor */
5454 place_floor_bold(y, x);
5456 else if (distance(y0, x0, y, x) < 3)
5458 place_floor_bold(y, x);
5462 /* make granite outside so arena works */
5463 place_extra_bold(y, x);
5466 /* proper boundary for arena */
5467 if (((y + rad) == y0) || ((y - rad) == y0) ||
5468 ((x + rad) == x0) || ((x - rad) == x0))
5470 place_extra_bold(y, x);
5475 /* Find visible outer walls and set to be FEAT_OUTER */
5476 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5477 x0 + rad + 1, y0 + rad + 1);
5479 /* Check to see if there is room for an inner vault */
5480 for (x = x0 - 2; x <= x0 + 2; x++)
5482 for (y = y0 - 2; y <= y0 + 2; y++)
5484 if (!is_floor_bold(y, x))
5486 /* Wall in the way */
5492 if (emptyflag && one_in_(2))
5494 /* Build the vault */
5495 build_small_room(x0, y0);
5497 /* Place a treasure in the vault */
5498 place_object(y0, x0, 0L);
5500 /* Let's guard the treasure well */
5501 vault_monsters(y0, x0, randint0(2) + 3);
5503 /* Traps naturally */
5504 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5512 * Helper function for "trapped monster pit"
5514 static bool vault_aux_trapped_pit(int r_idx)
5516 monster_race *r_ptr = &r_info[r_idx];
5518 /* Validate the monster */
5519 if (!vault_monster_okay(r_idx)) return (FALSE);
5521 /* No wall passing monster */
5522 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5530 * Type 12 -- Trapped monster pits
5532 * A trapped monster pit is a "big" room with a straight corridor in
5533 * which wall opening traps are placed, and with two "inner" rooms
5534 * containing a "collection" of monsters of a given type organized in
5537 * The trapped monster pit appears as shown below, where the actual
5538 * monsters in each location depend on the type of the pit
5540 * #########################
5542 * ####################### #
5543 * #####001123454321100### #
5544 * ###0012234567654322100# #
5545 * ####################### #
5547 * # #######################
5548 * # #0012234567654322100###
5549 * # ###001123454321100#####
5550 * # #######################
5552 * #########################
5554 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5555 * to request 16 "appropriate" monsters, sorting them by level, and using
5556 * the "even" entries in this sorted list for the contents of the pit.
5558 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5559 * which is handled by requiring a specific "breath" attack for all of the
5560 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5561 * be present in many of the dragon pits, if they have the proper breath.
5563 * Note the use of the "get_mon_num_prep()" function, and the special
5564 * "get_mon_num_hook()" restriction function, to prepare the "monster
5565 * allocation table" in such a way as to optimize the selection of
5566 * "appropriate" non-unique monsters for the pit.
5568 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5569 * the pit will be empty, and will not effect the level rating.
5571 * Note that "monster pits" will never contain "unique" monsters.
5573 static bool build_type13(void)
5575 static int placing[][3] = {
5576 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5577 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5578 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5579 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5580 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5581 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5582 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5583 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5584 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5585 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5586 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5587 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5588 {-2, -4, 3}, {-3, -2, 3},
5589 {+2, -4, 3}, {+3, -2, 3},
5590 {-2, +4, 3}, {-3, +2, 3},
5591 {+2, +4, 3}, {+3, +2, 3},
5592 {-2, -3, 4}, {-3, -1, 4},
5593 {+2, -3, 4}, {+3, -1, 4},
5594 {-2, +3, 4}, {-3, +1, 4},
5595 {+2, +3, 4}, {+3, +1, 4},
5596 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5597 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5598 {-2, -1, 6}, {-2, +1, 6},
5599 {+2, -1, 6}, {+2, +1, 6},
5600 {-2, 0, 7}, {+2, 0, 7},
5604 int y, x, y1, x1, y2, x2, xval, yval;
5613 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5614 vault_aux_type *n_ptr;
5616 /* Only in Angband */
5617 if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5619 /* No type available */
5620 if (cur_pit_type < 0) return FALSE;
5622 n_ptr = &pit_types[cur_pit_type];
5624 /* Process a preparation function if necessary */
5625 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5627 /* Prepare allocation table */
5628 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5630 align.sub_align = SUB_ALIGN_NEUTRAL;
5632 /* Pick some monster types */
5633 for (i = 0; i < 16; i++)
5635 int r_idx = 0, attempts = 100;
5636 monster_race *r_ptr = NULL;
5640 /* Get a (hard) monster type */
5641 r_idx = get_mon_num(dun_level + 0);
5642 r_ptr = &r_info[r_idx];
5644 /* Decline incorrect alignment */
5645 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5647 /* Accept this monster */
5651 /* Notice failure */
5652 if (!r_idx || !attempts) return FALSE;
5654 /* Note the alignment */
5655 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5656 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5661 /* Find and reserve some space in the dungeon. Get center of room. */
5662 if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5670 /* Fill with inner walls */
5671 for (y = y1 - 1; y <= y2 + 1; y++)
5673 for (x = x1 - 1; x <= x2 + 1; x++)
5675 c_ptr = &cave[y][x];
5676 place_inner_grid(c_ptr);
5677 c_ptr->info |= (CAVE_ROOM);
5681 /* Place the floor area 1 */
5682 for (x = x1 + 3; x <= x2 - 3; x++)
5684 c_ptr = &cave[yval-2][x];
5685 place_floor_grid(c_ptr);
5686 add_cave_info(yval-2, x, CAVE_ICKY);
5688 c_ptr = &cave[yval+2][x];
5689 place_floor_grid(c_ptr);
5690 add_cave_info(yval+2, x, CAVE_ICKY);
5693 /* Place the floor area 2 */
5694 for (x = x1 + 5; x <= x2 - 5; x++)
5696 c_ptr = &cave[yval-3][x];
5697 place_floor_grid(c_ptr);
5698 add_cave_info(yval-3, x, CAVE_ICKY);
5700 c_ptr = &cave[yval+3][x];
5701 place_floor_grid(c_ptr);
5702 add_cave_info(yval+3, x, CAVE_ICKY);
5706 for (x = x1; x <= x2; x++)
5708 c_ptr = &cave[yval][x];
5709 place_floor_grid(c_ptr);
5710 c_ptr = &cave[y1][x];
5711 place_floor_grid(c_ptr);
5712 c_ptr = &cave[y2][x];
5713 place_floor_grid(c_ptr);
5716 /* Place the outer walls */
5717 for (y = y1 - 1; y <= y2 + 1; y++)
5719 c_ptr = &cave[y][x1 - 1];
5720 place_outer_grid(c_ptr);
5721 c_ptr = &cave[y][x2 + 1];
5722 place_outer_grid(c_ptr);
5724 for (x = x1 - 1; x <= x2 + 1; x++)
5726 c_ptr = &cave[y1 - 1][x];
5727 place_outer_grid(c_ptr);
5728 c_ptr = &cave[y2 + 1][x];
5729 place_outer_grid(c_ptr);
5732 /* Random corridor */
5735 for (y = y1; y <= yval; y++)
5737 place_floor_bold(y, x2);
5738 place_solid_bold(y, x1-1);
5740 for (y = yval; y <= y2 + 1; y++)
5742 place_floor_bold(y, x1);
5743 place_solid_bold(y, x2+1);
5748 for (y = yval; y <= y2 + 1; y++)
5750 place_floor_bold(y, x1);
5751 place_solid_bold(y, x2+1);
5753 for (y = y1; y <= yval; y++)
5755 place_floor_bold(y, x2);
5756 place_solid_bold(y, x1-1);
5760 /* Place the wall open trap */
5761 cave[yval][xval].mimic = cave[yval][xval].feat;
5762 cave[yval][xval].feat = FEAT_TRAP_OPEN;
5764 /* Sort the entries */
5765 for (i = 0; i < 16 - 1; i++)
5767 /* Sort the entries */
5768 for (j = 0; j < 16 - 1; j++)
5773 int p1 = r_info[what[i1]].level;
5774 int p2 = r_info[what[i2]].level;
5780 what[i1] = what[i2];
5791 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5793 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5797 /* Select the entries */
5798 for (i = 0; i < 8; i++)
5800 /* Every other entry */
5801 what[i] = what[i * 2];
5806 msg_print(r_name + r_info[what[i]].name);
5810 /* Increase the level rating */
5813 /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
5814 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
5816 good_item_flag = TRUE;
5819 for (i = 0; placing[i][2] >= 0; i++)
5821 y = yval + placing[i][0];
5822 x = xval + placing[i][1];
5823 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5831 * Type 14 -- trapped rooms
5833 * A special trap is placed at center of the room
5835 static bool build_type14(void)
5837 int y, x, y2, x2, yval, xval;
5838 int y1, x1, xsize, ysize;
5845 /* Pick a room size */
5851 xsize = x1 + x2 + 1;
5852 ysize = y1 + y2 + 1;
5854 /* Find and reserve some space in the dungeon. Get center of room. */
5855 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5857 /* Choose lite or dark */
5858 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5861 /* Get corner values */
5862 y1 = yval - ysize / 2;
5863 x1 = xval - xsize / 2;
5864 y2 = yval + (ysize - 1) / 2;
5865 x2 = xval + (xsize - 1) / 2;
5868 /* Place a full floor under the room */
5869 for (y = y1 - 1; y <= y2 + 1; y++)
5871 for (x = x1 - 1; x <= x2 + 1; x++)
5873 c_ptr = &cave[y][x];
5874 place_floor_grid(c_ptr);
5875 c_ptr->info |= (CAVE_ROOM);
5876 if (light) c_ptr->info |= (CAVE_GLOW);
5880 /* Walls around the room */
5881 for (y = y1 - 1; y <= y2 + 1; y++)
5883 c_ptr = &cave[y][x1 - 1];
5884 place_outer_grid(c_ptr);
5885 c_ptr = &cave[y][x2 + 1];
5886 place_outer_grid(c_ptr);
5888 for (x = x1 - 1; x <= x2 + 1; x++)
5890 c_ptr = &cave[y1 - 1][x];
5891 place_outer_grid(c_ptr);
5892 c_ptr = &cave[y2 + 1][x];
5893 place_outer_grid(c_ptr);
5896 if (dun_level < 30 + randint1(30))
5897 trap = FEAT_TRAP_PIRANHA;
5899 trap = FEAT_TRAP_ARMAGEDDON;
5901 /* Place a special trap */
5902 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
5903 c_ptr->mimic = c_ptr->feat;
5910 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5912 msg_format("Room of %s", f_name + f_info[trap].name);
5921 * Attempt to build a room of the given type at the given block
5923 * Note that we restrict the number of "crowded" rooms to reduce
5924 * the chance of overflowing the monster list during level creation.
5926 bool room_build(int typ)
5931 /* Build an appropriate room */
5932 case ROOM_T_NORMAL: return build_type1();
5933 case ROOM_T_OVERLAP: return build_type2();
5934 case ROOM_T_CROSS: return build_type3();
5935 case ROOM_T_INNER_FEAT: return build_type4();
5936 case ROOM_T_NEST: return build_type5();
5937 case ROOM_T_PIT: return build_type6();
5938 case ROOM_T_LESSER_VAULT: return build_type7();
5939 case ROOM_T_GREATER_VAULT: return build_type8();
5940 case ROOM_T_FRACAVE: return build_type9();
5941 case ROOM_T_RANDOM_VAULT: return build_type10();
5942 case ROOM_T_OVAL: return build_type11();
5943 case ROOM_T_CRYPT: return build_type12();
5944 case ROOM_T_TRAP_PIT: return build_type13();
5945 case ROOM_T_TRAP: return build_type14();
5953 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
5956 * [from SAngband (originally from OAngband)]
5958 * Generate rooms in dungeon. Build bigger rooms at first.
5960 bool generate_rooms(void)
5966 int prob_list[ROOM_T_MAX];
5967 int rooms_built = 0;
5968 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
5969 int level_index = MIN(10, div_round(dun_level, 10));
5971 /* Number of each type of room on this level */
5972 s16b room_num[ROOM_T_MAX];
5974 /* Limit number of rooms */
5975 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
5977 /* Limit minimum number of rooms */
5978 int min_rooms = 8 - ((MAX_HGT/ cur_hgt) + (MAX_WID / cur_wid));
5980 /* Assume normal cave */
5981 room_info_type *room_info_ptr = room_info_normal;
5983 bool greater_vault_only = FALSE;
5986 * Initialize probability list.
5988 for (i = 0; i < ROOM_T_MAX; i++)
5990 /* No rooms allowed above their minimum depth. */
5991 if (dun_level < room_info_ptr[i].min_level)
5997 prob_list[i] = room_info_ptr[i].prob[level_index];
6002 * XXX -- Various dungeon types and options.
6005 /* Ironman sees only Greater Vaults */
6006 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON))))
6008 for (i = 0; i < ROOM_T_MAX; i++)
6010 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6011 else prob_list[i] = 0;
6014 greater_vault_only = TRUE;
6017 /* Forbidden vaults */
6018 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6020 prob_list[ROOM_T_LESSER_VAULT] = 0;
6021 prob_list[ROOM_T_GREATER_VAULT] = 0;
6022 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6026 /* NO_CAVE dungeon (Castle)*/
6027 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6029 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6030 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6031 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6034 /* CAVE dungeon (Orc cave etc.) */
6035 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6037 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6040 /* No caves when a (random) cavern exists: they look bad */
6041 else if (dun->cavern || dun->empty_level)
6043 prob_list[ROOM_T_FRACAVE] = 0;
6048 * Initialize number of rooms,
6049 * And calcurate total probability.
6051 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6054 total_prob += prob_list[i];
6058 * Prepare the number of rooms, of all types, we should build
6061 for (i = dun_rooms; i > 0; i--)
6064 int rand = randint0(total_prob);
6066 /* Get room_type randomly */
6067 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6069 if (rand < prob_list[room_type]) break;
6070 else rand -= prob_list[room_type];
6074 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6076 /* Increase the number of rooms of that type we should build. */
6077 room_num[room_type]++;
6083 case ROOM_T_LESSER_VAULT:
6084 case ROOM_T_TRAP_PIT:
6090 case ROOM_T_GREATER_VAULT:
6091 case ROOM_T_RANDOM_VAULT:
6099 if (greater_vault_only)
6101 /* Increase the room built count. */
6102 if (room_build(ROOM_T_NORMAL)) rooms_built++;
6107 * Build each type of room one by one until we cannot build any more.
6108 * [from SAngband (originally from OAngband)]
6112 /* Assume no remaining rooms */
6115 for (i = 0; i < ROOM_T_MAX; i++)
6117 /* What type of room are we building now? */
6118 int room_type = room_build_order[i];
6120 /* Go next if none available */
6121 if (!room_num[room_type]) continue;
6123 /* Use up one unit */
6124 room_num[room_type]--;
6126 /* Build the room. */
6127 if (room_build(room_type))
6129 /* Increase the room built count. */
6132 /* Mark as there was some remaining rooms */
6139 case ROOM_T_TRAP_PIT:
6141 /* Avoid too many monsters */
6144 room_num[ROOM_T_PIT] = 0;
6145 room_num[ROOM_T_NEST] = 0;
6146 room_num[ROOM_T_TRAP_PIT] = 0;
6151 /* Stop building this type on failure. */
6154 room_num[room_type] = 0;
6158 /* End loop if no room remain */
6162 if (rooms_built < min_rooms) return FALSE;
6167 msg_format("Éô²°¿ô: %d", rooms_built);
6169 msg_format("Number of Rooms: %d", rooms_built);