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 */
54 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
58 /* Build rooms in descending order of difficulty. */
59 static byte room_build_order[ROOM_T_MAX] = {
78 static void place_locked_door(int y, int x)
80 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
82 place_floor_bold(y, x);
86 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
87 cave[y][x].info &= ~(CAVE_FLOOR);
92 static void place_secret_door(int y, int x, int type)
94 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
96 place_floor_bold(y, x);
100 cave_type *c_ptr = &cave[y][x];
102 if (type == DOOR_DEFAULT)
104 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
105 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
106 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
109 /* Create secret door */
110 place_closed_door(y, x, type);
112 if (type != DOOR_CURTAIN)
114 /* Hide by inner wall because this is used in rooms only */
115 c_ptr->mimic = feat_wall_inner;
117 /* Floor type terrain cannot hide a door */
118 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
120 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
122 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
128 c_ptr->info &= ~(CAVE_FLOOR);
129 delete_monster(y, x);
134 * This funtion makes a very small room centred at (x0, y0)
135 * This is used in crypts, and random elemental vaults.
137 * Note - this should be used only on allocated regions
138 * within another room.
140 static void build_small_room(int x0, int y0)
144 for (y = y0 - 1; y <= y0 + 1; y++)
146 place_inner_bold(y, x0 - 1);
147 place_inner_bold(y, x0 + 1);
150 for (x = x0 - 1; x <= x0 + 1; x++)
152 place_inner_bold(y0 - 1, x);
153 place_inner_bold(y0 + 1, x);
156 /* Place a secret door on one side */
159 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
160 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
161 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
162 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
165 /* Clear mimic type */
166 cave[y0][x0].mimic = 0;
168 /* Add inner open space */
169 place_floor_bold(y0, x0);
174 * This function tunnels around a room if
175 * it will cut off part of a cave system.
177 static void check_room_boundary(int x1, int y1, int x2, int y2)
180 bool old_is_floor, new_is_floor;
186 old_is_floor = get_is_floor(x1 - 1, y1);
189 * Count the number of floor-wall boundaries around the room
190 * Note: diagonal squares are ignored since the player can move diagonally
191 * to bypass these if needed.
194 /* Above the top boundary */
195 for (x = x1; x <= x2; x++)
197 new_is_floor = get_is_floor(x, y1 - 1);
199 /* Increment counter if they are different */
200 if (new_is_floor != old_is_floor) count++;
202 old_is_floor = new_is_floor;
206 for (y = y1; y <= y2; y++)
208 new_is_floor = get_is_floor(x2 + 1, y);
210 /* increment counter if they are different */
211 if (new_is_floor != old_is_floor) count++;
213 old_is_floor = new_is_floor;
216 /* Bottom boundary */
217 for (x = x2; x >= x1; x--)
219 new_is_floor = get_is_floor(x, y2 + 1);
221 /* increment counter if they are different */
222 if (new_is_floor != old_is_floor) count++;
224 old_is_floor = new_is_floor;
228 for (y = y2; y >= y1; y--)
230 new_is_floor = get_is_floor(x1 - 1, y);
232 /* increment counter if they are different */
233 if (new_is_floor != old_is_floor) count++;
235 old_is_floor = new_is_floor;
238 /* If all the same, or only one connection exit. */
239 if (count <= 2) return;
242 /* Tunnel around the room so to prevent problems with caves */
243 for (y = y1; y <= y2; y++)
245 for (x = x1; x <= x2; x++)
254 * Helper function for find_space().
256 * Is this a good location?
258 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
260 int by1, bx1, by2, bx2, by, bx;
262 /* Itty-bitty rooms must shift about within their rectangle */
265 if ((blocks_wide == 2) && (block_x % 3) == 2)
269 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
270 else if ((blocks_wide % 3) == 0)
272 /* Must be aligned to the left edge of a 11x33 rectangle. */
273 if ((block_x % 3) != 0)
278 * Big rooms that do not have a width divisible by 3 must be
279 * aligned towards the edge of the dungeon closest to them.
283 /* Shift towards left edge of dungeon. */
284 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
286 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
288 if ((block_x % 3) == 1)
292 /* Shift toward right edge of dungeon. */
295 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
297 if ((block_x % 3) == 1)
305 by2 = block_y + blocks_high;
306 bx2 = block_x + blocks_wide;
308 /* Never run off the screen */
309 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
310 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
312 /* Verify available space */
313 for (by = by1; by < by2; by++)
315 for (bx = bx1; bx < bx2; bx++)
317 if (dun->room_map[by][bx])
324 /* This location is okay */
330 * Find a good spot for the next room. -LM-
332 * Find and allocate a free space in the dungeon large enough to hold
333 * the room calling this function.
335 * We allocate space in 11x11 blocks, but want to make sure that rooms
336 * align neatly on the standard screen. Therefore, we make them use
337 * blocks in few 11x33 rectangles as possible.
339 * Be careful to include the edges of the room in height and width!
341 * Return TRUE and values for the center of the room if all went well.
342 * Otherwise, return FALSE.
344 static bool find_space(int *y, int *x, int height, int width)
346 int candidates, pick;
347 int by, bx, by1, bx1, by2, bx2;
348 int block_y = 0, block_x = 0;
351 /* Find out how many blocks we need. */
352 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
353 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
355 /* There are no way to allocate such huge space */
356 if (dun->row_rooms < blocks_high) return FALSE;
357 if (dun->col_rooms < blocks_wide) return FALSE;
362 /* Count the number of varid places */
363 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
365 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
367 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
369 /* Find a varid place */
382 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
384 /* Choose a random one */
385 pick = randint1(candidates);
388 /* NO_CAVE dungeon (Castle) */
391 /* Always choose the center one */
392 pick = candidates/2 + 1;
395 /* Pick up the choosen location */
396 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
398 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
400 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
404 /* This one is picked? */
415 by2 = block_y + blocks_high;
416 bx2 = block_x + blocks_wide;
419 * It is *extremely* important that the following calculation
420 * be *exactly* correct to prevent memory errors
423 /* Acquire the location of the room */
424 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
425 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
427 /* Save the room location */
428 if (dun->cent_n < CENT_MAX)
430 dun->cent[dun->cent_n].y = *y;
431 dun->cent[dun->cent_n].x = *x;
435 /* Reserve some blocks. */
436 for (by = by1; by < by2; by++)
438 for (bx = bx1; bx < bx2; bx++)
440 dun->room_map[by][bx] = TRUE;
446 * Hack- See if room will cut off a cavern.
448 * If so, fix by tunneling outside the room in such a
449 * way as to connect the caves.
451 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
461 * Room building routines.
467 * 4 -- large room with features
471 * 8 -- greater vaults
473 * 10 -- random vaults
474 * 11 -- circular rooms
476 * 13 -- trapped monster pits
482 * Type 1 -- normal rectangular rooms
484 static bool build_type1(void)
486 int y, x, y2, x2, yval, xval;
487 int y1, x1, xsize, ysize;
493 bool curtain = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
494 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 48 : 512);
496 /* Pick a room size */
505 /* Find and reserve some space in the dungeon. Get center of room. */
506 if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
508 /* Limit to the minimum room size, and retry */
517 /* Find and reserve some space in the dungeon. Get center of room. */
518 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
521 /* Choose lite or dark */
522 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
525 /* Get corner values */
526 y1 = yval - ysize / 2;
527 x1 = xval - xsize / 2;
528 y2 = yval + (ysize - 1) / 2;
529 x2 = xval + (xsize - 1) / 2;
532 /* Place a full floor under the room */
533 for (y = y1 - 1; y <= y2 + 1; y++)
535 for (x = x1 - 1; x <= x2 + 1; x++)
538 place_floor_grid(c_ptr);
539 c_ptr->info |= (CAVE_ROOM);
540 if (light) c_ptr->info |= (CAVE_GLOW);
544 /* Walls around the room */
545 for (y = y1 - 1; y <= y2 + 1; y++)
547 c_ptr = &cave[y][x1 - 1];
548 place_outer_grid(c_ptr);
549 c_ptr = &cave[y][x2 + 1];
550 place_outer_grid(c_ptr);
552 for (x = x1 - 1; x <= x2 + 1; x++)
554 c_ptr = &cave[y1 - 1][x];
555 place_outer_grid(c_ptr);
556 c_ptr = &cave[y2 + 1][x];
557 place_outer_grid(c_ptr);
561 /* Hack -- Occasional curtained room */
562 if (curtain && (y2 - y1 > 2) && (x2 - x1 > 2))
564 for (y = y1; y <= y2; y++)
566 c_ptr = &cave[y][x1];
567 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
568 c_ptr->info &= ~(CAVE_MASK);
569 c_ptr = &cave[y][x2];
570 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
571 c_ptr->info &= ~(CAVE_MASK);
573 for (x = x1; x <= x2; x++)
575 c_ptr = &cave[y1][x];
576 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
577 c_ptr->info &= ~(CAVE_MASK);
578 c_ptr = &cave[y2][x];
579 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
580 c_ptr->info &= ~(CAVE_MASK);
585 /* Hack -- Occasional pillar room */
588 for (y = y1; y <= y2; y += 2)
590 for (x = x1; x <= x2; x += 2)
593 place_inner_grid(c_ptr);
598 /* Hack -- Occasional room with four pillars */
599 else if (one_in_(20))
601 if ((y1 + 4 < y2) && (x1 + 4 < x2))
603 c_ptr = &cave[y1 + 1][x1 + 1];
604 place_inner_grid(c_ptr);
606 c_ptr = &cave[y1 + 1][x2 - 1];
607 place_inner_grid(c_ptr);
609 c_ptr = &cave[y2 - 1][x1 + 1];
610 place_inner_grid(c_ptr);
612 c_ptr = &cave[y2 - 1][x2 - 1];
613 place_inner_grid(c_ptr);
617 /* Hack -- Occasional ragged-edge room */
618 else if (one_in_(50))
620 for (y = y1 + 2; y <= y2 - 2; y += 2)
622 c_ptr = &cave[y][x1];
623 place_inner_grid(c_ptr);
624 c_ptr = &cave[y][x2];
625 place_inner_grid(c_ptr);
627 for (x = x1 + 2; x <= x2 - 2; x += 2)
629 c_ptr = &cave[y1][x];
630 place_inner_grid(c_ptr);
631 c_ptr = &cave[y2][x];
632 place_inner_grid(c_ptr);
635 /* Hack -- Occasional divided room */
636 else if (one_in_(50))
638 bool curtain2 = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
639 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 2 : 128);
641 if (randint1(100) < 50)
643 /* Horizontal wall */
644 for (x = x1; x <= x2; x++)
646 place_inner_bold(yval, x);
647 if (curtain2) cave[yval][x].feat = feat_door[DOOR_CURTAIN].closed;
650 /* Prevent edge of wall from being tunneled */
651 place_solid_bold(yval, x1 - 1);
652 place_solid_bold(yval, x2 + 1);
657 for (y = y1; y <= y2; y++)
659 place_inner_bold(y, xval);
660 if (curtain2) cave[y][xval].feat = feat_door[DOOR_CURTAIN].closed;
663 /* Prevent edge of wall from being tunneled */
664 place_solid_bold(y1 - 1, xval);
665 place_solid_bold(y2 + 1, xval);
668 place_random_door(yval, xval, TRUE);
669 if (curtain2) cave[yval][xval].feat = feat_door[DOOR_CURTAIN].closed;
677 * Type 2 -- Overlapping rectangular rooms
679 static bool build_type2(void)
681 int y, x, xval, yval;
682 int y1a, x1a, y2a, x2a;
683 int y1b, x1b, y2b, x2b;
687 /* Find and reserve some space in the dungeon. Get center of room. */
688 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
690 /* Choose lite or dark */
691 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
693 /* Determine extents of the first room */
694 y1a = yval - randint1(4);
695 y2a = yval + randint1(3);
696 x1a = xval - randint1(11);
697 x2a = xval + randint1(10);
699 /* Determine extents of the second room */
700 y1b = yval - randint1(3);
701 y2b = yval + randint1(4);
702 x1b = xval - randint1(10);
703 x2b = xval + randint1(11);
706 /* Place a full floor for room "a" */
707 for (y = y1a - 1; y <= y2a + 1; y++)
709 for (x = x1a - 1; x <= x2a + 1; x++)
712 place_floor_grid(c_ptr);
713 c_ptr->info |= (CAVE_ROOM);
714 if (light) c_ptr->info |= (CAVE_GLOW);
718 /* Place a full floor for room "b" */
719 for (y = y1b - 1; y <= y2b + 1; y++)
721 for (x = x1b - 1; x <= x2b + 1; x++)
724 place_floor_grid(c_ptr);
725 c_ptr->info |= (CAVE_ROOM);
726 if (light) c_ptr->info |= (CAVE_GLOW);
731 /* Place the walls around room "a" */
732 for (y = y1a - 1; y <= y2a + 1; y++)
734 c_ptr = &cave[y][x1a - 1];
735 place_outer_grid(c_ptr);
736 c_ptr = &cave[y][x2a + 1];
737 place_outer_grid(c_ptr);
739 for (x = x1a - 1; x <= x2a + 1; x++)
741 c_ptr = &cave[y1a - 1][x];
742 place_outer_grid(c_ptr);
743 c_ptr = &cave[y2a + 1][x];
744 place_outer_grid(c_ptr);
747 /* Place the walls around room "b" */
748 for (y = y1b - 1; y <= y2b + 1; y++)
750 c_ptr = &cave[y][x1b - 1];
751 place_outer_grid(c_ptr);
752 c_ptr = &cave[y][x2b + 1];
753 place_outer_grid(c_ptr);
755 for (x = x1b - 1; x <= x2b + 1; x++)
757 c_ptr = &cave[y1b - 1][x];
758 place_outer_grid(c_ptr);
759 c_ptr = &cave[y2b + 1][x];
760 place_outer_grid(c_ptr);
765 /* Replace the floor for room "a" */
766 for (y = y1a; y <= y2a; y++)
768 for (x = x1a; x <= x2a; x++)
771 place_floor_grid(c_ptr);
775 /* Replace the floor for room "b" */
776 for (y = y1b; y <= y2b; y++)
778 for (x = x1b; x <= x2b; x++)
781 place_floor_grid(c_ptr);
791 * Type 3 -- Cross shaped rooms
793 * Builds a room at a row, column coordinate
795 * Room "a" runs north/south, and Room "b" runs east/east
796 * So the "central pillar" runs from x1a, y1b to x2a, y2b.
798 * Note that currently, the "center" is always 3x3, but I think that
799 * the code below will work (with "bounds checking") for 5x5, or even
800 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.
802 static bool build_type3(void)
804 int y, x, dy, dx, wy, wx;
805 int y1a, x1a, y2a, x2a;
806 int y1b, x1b, y2b, x2b;
812 /* Find and reserve some space in the dungeon. Get center of room. */
813 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
816 /* Choose lite or dark */
817 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
819 /* For now, always 3x3 */
822 /* Pick max vertical size (at most 4) */
823 dy = rand_range(3, 4);
825 /* Pick max horizontal size (at most 15) */
826 dx = rand_range(3, 11);
829 /* Determine extents of the north/south room */
835 /* Determine extents of the east/west room */
842 /* Place a full floor for room "a" */
843 for (y = y1a - 1; y <= y2a + 1; y++)
845 for (x = x1a - 1; x <= x2a + 1; x++)
848 place_floor_grid(c_ptr);
849 c_ptr->info |= (CAVE_ROOM);
850 if (light) c_ptr->info |= (CAVE_GLOW);
854 /* Place a full floor for room "b" */
855 for (y = y1b - 1; y <= y2b + 1; y++)
857 for (x = x1b - 1; x <= x2b + 1; x++)
860 place_floor_grid(c_ptr);
861 c_ptr->info |= (CAVE_ROOM);
862 if (light) c_ptr->info |= (CAVE_GLOW);
867 /* Place the walls around room "a" */
868 for (y = y1a - 1; y <= y2a + 1; y++)
870 c_ptr = &cave[y][x1a - 1];
871 place_outer_grid(c_ptr);
872 c_ptr = &cave[y][x2a + 1];
873 place_outer_grid(c_ptr);
875 for (x = x1a - 1; x <= x2a + 1; x++)
877 c_ptr = &cave[y1a - 1][x];
878 place_outer_grid(c_ptr);
879 c_ptr = &cave[y2a + 1][x];
880 place_outer_grid(c_ptr);
883 /* Place the walls around room "b" */
884 for (y = y1b - 1; y <= y2b + 1; y++)
886 c_ptr = &cave[y][x1b - 1];
887 place_outer_grid(c_ptr);
888 c_ptr = &cave[y][x2b + 1];
889 place_outer_grid(c_ptr);
891 for (x = x1b - 1; x <= x2b + 1; x++)
893 c_ptr = &cave[y1b - 1][x];
894 place_outer_grid(c_ptr);
895 c_ptr = &cave[y2b + 1][x];
896 place_outer_grid(c_ptr);
900 /* Replace the floor for room "a" */
901 for (y = y1a; y <= y2a; y++)
903 for (x = x1a; x <= x2a; x++)
906 place_floor_grid(c_ptr);
910 /* Replace the floor for room "b" */
911 for (y = y1b; y <= y2b; y++)
913 for (x = x1b; x <= x2b; x++)
916 place_floor_grid(c_ptr);
922 /* Special features (3/4) */
925 /* Large solid middle pillar */
928 for (y = y1b; y <= y2b; y++)
930 for (x = x1a; x <= x2a; x++)
933 place_inner_grid(c_ptr);
939 /* Inner treasure vault */
942 /* Build the vault */
943 for (y = y1b; y <= y2b; y++)
945 c_ptr = &cave[y][x1a];
946 place_inner_grid(c_ptr);
947 c_ptr = &cave[y][x2a];
948 place_inner_grid(c_ptr);
950 for (x = x1a; x <= x2a; x++)
952 c_ptr = &cave[y1b][x];
953 place_inner_grid(c_ptr);
954 c_ptr = &cave[y2b][x];
955 place_inner_grid(c_ptr);
958 /* Place a secret door on the inner room */
961 case 0: place_secret_door(y1b, xval, DOOR_DEFAULT); break;
962 case 1: place_secret_door(y2b, xval, DOOR_DEFAULT); break;
963 case 2: place_secret_door(yval, x1a, DOOR_DEFAULT); break;
964 case 3: place_secret_door(yval, x2a, DOOR_DEFAULT); break;
967 /* Place a treasure in the vault */
968 place_object(yval, xval, 0L);
970 /* Let's guard the treasure well */
971 vault_monsters(yval, xval, randint0(2) + 3);
973 /* Traps naturally */
974 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
982 /* Occasionally pinch the center shut */
985 /* Pinch the east/west sides */
986 for (y = y1b; y <= y2b; y++)
988 if (y == yval) continue;
989 c_ptr = &cave[y][x1a - 1];
990 place_inner_grid(c_ptr);
991 c_ptr = &cave[y][x2a + 1];
992 place_inner_grid(c_ptr);
995 /* Pinch the north/south sides */
996 for (x = x1a; x <= x2a; x++)
998 if (x == xval) continue;
999 c_ptr = &cave[y1b - 1][x];
1000 place_inner_grid(c_ptr);
1001 c_ptr = &cave[y2b + 1][x];
1002 place_inner_grid(c_ptr);
1005 /* Sometimes shut using secret doors */
1008 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1009 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1010 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1012 place_secret_door(yval, x1a - 1, door_type);
1013 place_secret_door(yval, x2a + 1, door_type);
1014 place_secret_door(y1b - 1, xval, door_type);
1015 place_secret_door(y2b + 1, xval, door_type);
1019 /* Occasionally put a "plus" in the center */
1020 else if (one_in_(3))
1022 c_ptr = &cave[yval][xval];
1023 place_inner_grid(c_ptr);
1024 c_ptr = &cave[y1b][xval];
1025 place_inner_grid(c_ptr);
1026 c_ptr = &cave[y2b][xval];
1027 place_inner_grid(c_ptr);
1028 c_ptr = &cave[yval][x1a];
1029 place_inner_grid(c_ptr);
1030 c_ptr = &cave[yval][x2a];
1031 place_inner_grid(c_ptr);
1034 /* Occasionally put a pillar in the center */
1035 else if (one_in_(3))
1037 c_ptr = &cave[yval][xval];
1038 place_inner_grid(c_ptr);
1050 * Type 4 -- Large room with inner features
1052 * Possible sub-types:
1053 * 1 - Just an inner room with one door
1054 * 2 - An inner room within an inner room
1055 * 3 - An inner room with pillar(s)
1056 * 4 - Inner room has a maze
1057 * 5 - A set of four inner rooms
1059 static bool build_type4(void)
1062 int y2, x2, tmp, yval, xval;
1067 /* Find and reserve some space in the dungeon. Get center of room. */
1068 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
1070 /* Choose lite or dark */
1071 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1079 /* Place a full floor under the room */
1080 for (y = y1 - 1; y <= y2 + 1; y++)
1082 for (x = x1 - 1; x <= x2 + 1; x++)
1084 c_ptr = &cave[y][x];
1085 place_floor_grid(c_ptr);
1086 c_ptr->info |= (CAVE_ROOM);
1087 if (light) c_ptr->info |= (CAVE_GLOW);
1092 for (y = y1 - 1; y <= y2 + 1; y++)
1094 c_ptr = &cave[y][x1 - 1];
1095 place_outer_grid(c_ptr);
1096 c_ptr = &cave[y][x2 + 1];
1097 place_outer_grid(c_ptr);
1099 for (x = x1 - 1; x <= x2 + 1; x++)
1101 c_ptr = &cave[y1 - 1][x];
1102 place_outer_grid(c_ptr);
1103 c_ptr = &cave[y2 + 1][x];
1104 place_outer_grid(c_ptr);
1108 /* The inner room */
1114 /* The inner walls */
1115 for (y = y1 - 1; y <= y2 + 1; y++)
1117 c_ptr = &cave[y][x1 - 1];
1118 place_inner_grid(c_ptr);
1119 c_ptr = &cave[y][x2 + 1];
1120 place_inner_grid(c_ptr);
1122 for (x = x1 - 1; x <= x2 + 1; x++)
1124 c_ptr = &cave[y1 - 1][x];
1125 place_inner_grid(c_ptr);
1126 c_ptr = &cave[y2 + 1][x];
1127 place_inner_grid(c_ptr);
1131 /* Inner room variations */
1132 switch (randint1(5))
1134 /* Just an inner room with a monster */
1137 /* Place a secret door */
1138 switch (randint1(4))
1140 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1141 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1142 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1143 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1146 /* Place a monster in the room */
1147 vault_monsters(yval, xval, 1);
1152 /* Treasure Vault (with a door) */
1155 /* Place a secret door */
1156 switch (randint1(4))
1158 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1159 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1160 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1161 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1164 /* Place another inner room */
1165 for (y = yval - 1; y <= yval + 1; y++)
1167 for (x = xval - 1; x <= xval + 1; x++)
1169 if ((x == xval) && (y == yval)) continue;
1170 c_ptr = &cave[y][x];
1171 place_inner_grid(c_ptr);
1175 /* Place a locked door on the inner room */
1176 switch (randint1(4))
1178 case 1: place_locked_door(yval - 1, xval); break;
1179 case 2: place_locked_door(yval + 1, xval); break;
1180 case 3: place_locked_door(yval, xval - 1); break;
1181 case 4: place_locked_door(yval, xval + 1); break;
1184 /* Monsters to guard the "treasure" */
1185 vault_monsters(yval, xval, randint1(3) + 2);
1188 if (randint0(100) < 80)
1190 place_object(yval, xval, 0L);
1196 place_random_stairs(yval, xval);
1199 /* Traps to protect the treasure */
1200 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
1205 /* Inner pillar(s). */
1208 /* Place a secret door */
1209 switch (randint1(4))
1211 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1212 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1213 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1214 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1217 /* Large Inner Pillar */
1218 for (y = yval - 1; y <= yval + 1; y++)
1220 for (x = xval - 1; x <= xval + 1; x++)
1222 c_ptr = &cave[y][x];
1223 place_inner_grid(c_ptr);
1227 /* Occasionally, two more Large Inner Pillars */
1231 for (y = yval - 1; y <= yval + 1; y++)
1233 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1235 c_ptr = &cave[y][x];
1236 place_inner_grid(c_ptr);
1238 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1240 c_ptr = &cave[y][x];
1241 place_inner_grid(c_ptr);
1246 /* Occasionally, some Inner rooms */
1249 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1250 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1251 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1253 /* Long horizontal walls */
1254 for (x = xval - 5; x <= xval + 5; x++)
1256 c_ptr = &cave[yval - 1][x];
1257 place_inner_grid(c_ptr);
1258 c_ptr = &cave[yval + 1][x];
1259 place_inner_grid(c_ptr);
1262 /* Close off the left/right edges */
1263 c_ptr = &cave[yval][xval - 5];
1264 place_inner_grid(c_ptr);
1265 c_ptr = &cave[yval][xval + 5];
1266 place_inner_grid(c_ptr);
1268 /* Secret doors (random top/bottom) */
1269 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3, door_type);
1270 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3, door_type);
1273 vault_monsters(yval, xval - 2, randint1(2));
1274 vault_monsters(yval, xval + 2, randint1(2));
1277 if (one_in_(3)) place_object(yval, xval - 2, 0L);
1278 if (one_in_(3)) place_object(yval, xval + 2, 0L);
1287 /* Place a secret door */
1288 switch (randint1(4))
1290 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1291 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1292 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1293 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1296 /* Maze (really a checkerboard) */
1297 for (y = y1; y <= y2; y++)
1299 for (x = x1; x <= x2; x++)
1303 c_ptr = &cave[y][x];
1304 place_inner_grid(c_ptr);
1309 /* Monsters just love mazes. */
1310 vault_monsters(yval, xval - 5, randint1(3));
1311 vault_monsters(yval, xval + 5, randint1(3));
1313 /* Traps make them entertaining. */
1314 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1315 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1317 /* Mazes should have some treasure too. */
1318 vault_objects(yval, xval, 3);
1323 /* Four small rooms. */
1326 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1327 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1328 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1331 for (y = y1; y <= y2; y++)
1333 c_ptr = &cave[y][xval];
1334 place_inner_grid(c_ptr);
1336 for (x = x1; x <= x2; x++)
1338 c_ptr = &cave[yval][x];
1339 place_inner_grid(c_ptr);
1342 /* Doors into the rooms */
1343 if (randint0(100) < 50)
1345 int i = randint1(10);
1346 place_secret_door(y1 - 1, xval - i, door_type);
1347 place_secret_door(y1 - 1, xval + i, door_type);
1348 place_secret_door(y2 + 1, xval - i, door_type);
1349 place_secret_door(y2 + 1, xval + i, door_type);
1353 int i = randint1(3);
1354 place_secret_door(yval + i, x1 - 1, door_type);
1355 place_secret_door(yval - i, x1 - 1, door_type);
1356 place_secret_door(yval + i, x2 + 1, door_type);
1357 place_secret_door(yval - i, x2 + 1, door_type);
1360 /* Treasure, centered at the center of the cross */
1361 vault_objects(yval, xval, 2 + randint1(2));
1363 /* Gotta have some monsters. */
1364 vault_monsters(yval + 1, xval - 4, randint1(4));
1365 vault_monsters(yval + 1, xval + 4, randint1(4));
1366 vault_monsters(yval - 1, xval - 4, randint1(4));
1367 vault_monsters(yval - 1, xval + 4, randint1(4));
1378 * The following functions are used to determine if the given monster
1379 * is appropriate for inclusion in a monster nest or monster pit or
1382 * None of the pits/nests are allowed to include "unique" monsters.
1387 * Monster validation macro
1389 * Line 1 -- forbid town monsters
1390 * Line 2 -- forbid uniques
1391 * Line 3 -- forbid aquatic monsters
1393 #define vault_monster_okay(I) \
1394 (mon_hook_dungeon(I) && \
1395 !(r_info[I].flags1 & RF1_UNIQUE) && \
1396 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1397 !(r_info[I].flagsr & RFR_RES_ALL) && \
1398 !(r_info[I].flags7 & RF7_AQUATIC))
1401 /* Race index for "monster pit (clone)" */
1402 static int vault_aux_race;
1404 /* Race index for "monster pit (symbol clone)" */
1405 static char vault_aux_char;
1407 /* Breath mask for "monster pit (dragon)" */
1408 static u32b vault_aux_dragon_mask4;
1412 * Helper monster selection function
1414 static bool vault_aux_simple(int r_idx)
1417 return (vault_monster_okay(r_idx));
1422 * Helper function for "monster nest (jelly)"
1424 static bool vault_aux_jelly(int r_idx)
1426 monster_race *r_ptr = &r_info[r_idx];
1428 /* Validate the monster */
1429 if (!vault_monster_okay(r_idx)) return (FALSE);
1431 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1433 /* Also decline evil jellies (like death molds and shoggoths) */
1434 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1436 /* Require icky thing, jelly, mold, or mushroom */
1437 if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
1445 * Helper function for "monster nest (animal)"
1447 static bool vault_aux_animal(int r_idx)
1449 monster_race *r_ptr = &r_info[r_idx];
1451 /* Validate the monster */
1452 if (!vault_monster_okay(r_idx)) return (FALSE);
1454 /* Require "animal" flag */
1455 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1463 * Helper function for "monster nest (undead)"
1465 static bool vault_aux_undead(int r_idx)
1467 monster_race *r_ptr = &r_info[r_idx];
1469 /* Validate the monster */
1470 if (!vault_monster_okay(r_idx)) return (FALSE);
1472 /* Require Undead */
1473 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1481 * Helper function for "monster nest (chapel)"
1483 static bool vault_aux_chapel_g(int r_idx)
1485 static int chapel_list[] = {
1486 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1487 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1488 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1493 monster_race *r_ptr = &r_info[r_idx];
1495 /* Validate the monster */
1496 if (!vault_monster_okay(r_idx)) return (FALSE);
1498 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1499 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1501 /* Require "priest" or Angel */
1503 if (r_ptr->d_char == 'A') return TRUE;
1505 for (i = 0; chapel_list[i]; i++)
1506 if (r_idx == chapel_list[i]) return TRUE;
1513 * Helper function for "monster nest (kennel)"
1515 static bool vault_aux_kennel(int r_idx)
1517 monster_race *r_ptr = &r_info[r_idx];
1519 /* Validate the monster */
1520 if (!vault_monster_okay(r_idx)) return (FALSE);
1522 /* Require a Zephyr Hound or a dog */
1523 if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
1531 * Helper function for "monster nest (mimic)"
1533 static bool vault_aux_mimic(int r_idx)
1535 monster_race *r_ptr = &r_info[r_idx];
1537 /* Validate the monster */
1538 if (!vault_monster_okay(r_idx)) return (FALSE);
1541 if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
1548 * Helper function for "monster nest (clone)"
1550 static bool vault_aux_clone(int r_idx)
1552 /* Validate the monster */
1553 if (!vault_monster_okay(r_idx)) return (FALSE);
1555 return (r_idx == vault_aux_race);
1560 * Helper function for "monster nest (symbol clone)"
1562 static bool vault_aux_symbol_e(int r_idx)
1564 monster_race *r_ptr = &r_info[r_idx];
1566 /* Validate the monster */
1567 if (!vault_monster_okay(r_idx)) return (FALSE);
1569 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1571 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1573 /* Decline incorrect symbol */
1574 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1582 * Helper function for "monster nest (symbol clone)"
1584 static bool vault_aux_symbol_g(int r_idx)
1586 monster_race *r_ptr = &r_info[r_idx];
1588 /* Validate the monster */
1589 if (!vault_monster_okay(r_idx)) return (FALSE);
1591 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1593 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1595 /* Decline incorrect symbol */
1596 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1604 * Helper function for "monster pit (orc)"
1606 static bool vault_aux_orc(int r_idx)
1608 monster_race *r_ptr = &r_info[r_idx];
1610 /* Validate the monster */
1611 if (!vault_monster_okay(r_idx)) return (FALSE);
1614 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1616 /* Decline undead */
1617 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1625 * Helper function for "monster pit (troll)"
1627 static bool vault_aux_troll(int r_idx)
1629 monster_race *r_ptr = &r_info[r_idx];
1631 /* Validate the monster */
1632 if (!vault_monster_okay(r_idx)) return (FALSE);
1635 if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1637 /* Decline undead */
1638 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1646 * Helper function for "monster pit (giant)"
1648 static bool vault_aux_giant(int r_idx)
1650 monster_race *r_ptr = &r_info[r_idx];
1652 /* Validate the monster */
1653 if (!vault_monster_okay(r_idx)) return (FALSE);
1656 if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1658 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1660 /* Decline undead */
1661 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1669 * Helper function for "monster pit (dragon)"
1671 static bool vault_aux_dragon(int r_idx)
1673 monster_race *r_ptr = &r_info[r_idx];
1675 /* Validate the monster */
1676 if (!vault_monster_okay(r_idx)) return (FALSE);
1678 /* Require dragon */
1679 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1681 /* Hack -- Require correct "breath attack" */
1682 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1684 /* Decline undead */
1685 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1693 * Helper function for "monster pit (demon)"
1695 static bool vault_aux_demon(int r_idx)
1697 monster_race *r_ptr = &r_info[r_idx];
1699 /* Validate the monster */
1700 if (!vault_monster_okay(r_idx)) return (FALSE);
1702 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1705 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1713 * Helper function for "monster pit (lovecraftian)"
1715 static bool vault_aux_cthulhu(int r_idx)
1717 monster_race *r_ptr = &r_info[r_idx];
1719 /* Validate the monster */
1720 if (!vault_monster_okay(r_idx)) return (FALSE);
1722 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1724 /* Require eldritch horror */
1725 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1733 * Helper function for "monster pit (clone)"
1735 static void vault_prep_clone(void)
1737 /* Apply the monster restriction */
1738 get_mon_num_prep(vault_aux_simple, NULL);
1740 /* Pick a race to clone */
1741 vault_aux_race = get_mon_num(dun_level + 10);
1743 /* Remove the monster restriction */
1744 get_mon_num_prep(NULL, NULL);
1749 * Helper function for "monster pit (symbol clone)"
1751 static void vault_prep_symbol(void)
1755 /* Apply the monster restriction */
1756 get_mon_num_prep(vault_aux_simple, NULL);
1758 /* Pick a race to clone */
1759 r_idx = get_mon_num(dun_level + 10);
1761 /* Remove the monster restriction */
1762 get_mon_num_prep(NULL, NULL);
1764 /* Extract the symbol */
1765 vault_aux_char = r_info[r_idx].d_char;
1770 * Helper function for "monster pit (dragon)"
1772 static void vault_prep_dragon(void)
1774 /* Pick dragon type */
1775 switch (randint0(6))
1780 /* Restrict dragon breath type */
1781 vault_aux_dragon_mask4 = RF4_BR_ACID;
1790 /* Restrict dragon breath type */
1791 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1800 /* Restrict dragon breath type */
1801 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1810 /* Restrict dragon breath type */
1811 vault_aux_dragon_mask4 = RF4_BR_COLD;
1820 /* Restrict dragon breath type */
1821 vault_aux_dragon_mask4 = RF4_BR_POIS;
1830 /* Restrict dragon breath type */
1831 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1832 RF4_BR_FIRE | RF4_BR_COLD |
1843 * Helper function for "monster pit (dark elf)"
1845 static bool vault_aux_dark_elf(int r_idx)
1848 static int dark_elf_list[] =
1850 MON_D_ELF, MON_D_ELF_MAGE, MON_D_ELF_WARRIOR, MON_D_ELF_PRIEST,
1851 MON_D_ELF_LORD, MON_D_ELF_WARLOCK, MON_D_ELF_DRUID, MON_NIGHTBLADE,
1852 MON_D_ELF_SORC, MON_D_ELF_SHADE, 0,
1855 /* Validate the monster */
1856 if (!vault_monster_okay(r_idx)) return FALSE;
1858 /* Require dark elves */
1859 for (i = 0; dark_elf_list[i]; i++)
1860 if (r_idx == dark_elf_list[i]) return TRUE;
1867 typedef struct vault_aux_type vault_aux_type;
1870 struct vault_aux_type
1873 bool (*hook_func)(int r_idx);
1874 void (*prep_func)(void);
1880 static int pick_vault_type(vault_aux_type *l_ptr, s16b allow_flag_mask)
1882 int tmp, total, count;
1884 vault_aux_type *n_ptr;
1886 /* Calculate the total possibilities */
1887 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1890 if (!n_ptr->name) break;
1892 /* Ignore excessive depth */
1893 if (n_ptr->level > dun_level) continue;
1895 /* Not matched with pit/nest flag */
1896 if (!(allow_flag_mask & (1L << count))) continue;
1898 /* Count this possibility */
1899 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1902 /* Pick a random type */
1903 tmp = randint0(total);
1905 /* Find this type */
1906 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1909 if (!n_ptr->name) break;
1911 /* Ignore excessive depth */
1912 if (n_ptr->level > dun_level) continue;
1914 /* Not matched with pit/nest flag */
1915 if (!(allow_flag_mask & (1L << count))) continue;
1917 /* Count this possibility */
1918 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1920 /* Found the type */
1921 if (tmp < total) break;
1924 return n_ptr->name ? count : -1;
1927 static vault_aux_type nest_types[] =
1930 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1931 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1932 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1933 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1934 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1935 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1936 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1937 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1938 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1939 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1940 {NULL, NULL, NULL, 0, 0},
1942 {"clone", vault_aux_clone, vault_prep_clone, 5, 3},
1943 {"jelly", vault_aux_jelly, NULL, 5, 6},
1944 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1945 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1946 {"mimic", vault_aux_mimic, NULL, 30, 4},
1947 {"lovecraftian", vault_aux_cthulhu, NULL, 70, 2},
1948 {"kennel", vault_aux_kennel, NULL, 45, 4},
1949 {"animal", vault_aux_animal, NULL, 35, 5},
1950 {"chapel", vault_aux_chapel_g, NULL, 75, 4},
1951 {"undead", vault_aux_undead, NULL, 75, 5},
1952 {NULL, NULL, NULL, 0, 0},
1956 static vault_aux_type pit_types[] =
1959 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1960 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1961 {"¥¸¥ã¥¤¥¢¥ó¥È", vault_aux_giant, NULL, 50, 6},
1962 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1963 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1964 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1965 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
1966 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
1967 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
1968 {"¥À¡¼¥¯¥¨¥ë¥Õ", vault_aux_dark_elf, NULL, 45, 4},
1969 {NULL, NULL, NULL, 0, 0},
1971 {"orc", vault_aux_orc, NULL, 5, 6},
1972 {"troll", vault_aux_troll, NULL, 20, 6},
1973 {"giant", vault_aux_giant, NULL, 50, 6},
1974 {"lovecraftian", vault_aux_cthulhu, NULL, 80, 2},
1975 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1976 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1977 {"chapel", vault_aux_chapel_g, NULL, 65, 2},
1978 {"dragon", vault_aux_dragon, vault_prep_dragon, 70, 6},
1979 {"demon", vault_aux_demon, NULL, 80, 6},
1980 {"dark elf", vault_aux_dark_elf, NULL, 45, 4},
1981 {NULL, NULL, NULL, 0, 0},
1986 /* Nest types code */
1987 #define NEST_TYPE_CLONE 0
1988 #define NEST_TYPE_JELLY 1
1989 #define NEST_TYPE_SYMBOL_GOOD 2
1990 #define NEST_TYPE_SYMBOL_EVIL 3
1991 #define NEST_TYPE_MIMIC 4
1992 #define NEST_TYPE_LOVECRAFTIAN 5
1993 #define NEST_TYPE_KENNEL 6
1994 #define NEST_TYPE_ANIMAL 7
1995 #define NEST_TYPE_CHAPEL 8
1996 #define NEST_TYPE_UNDEAD 9
1998 /* Pit types code */
1999 #define PIT_TYPE_ORC 0
2000 #define PIT_TYPE_TROLL 1
2001 #define PIT_TYPE_GIANT 2
2002 #define PIT_TYPE_LOVECRAFTIAN 3
2003 #define PIT_TYPE_SYMBOL_GOOD 4
2004 #define PIT_TYPE_SYMBOL_EVIL 5
2005 #define PIT_TYPE_CHAPEL 6
2006 #define PIT_TYPE_DRAGON 7
2007 #define PIT_TYPE_DEMON 8
2008 #define PIT_TYPE_DARK_ELF 9
2012 * Hack -- Get the string describing subtype of pit/nest
2013 * Determined in prepare function (some pit/nest only)
2015 static cptr pit_subtype_string(int type, bool nest)
2017 static char inner_buf[256] = "";
2019 inner_buf[0] = '\0'; /* Init string */
2021 if (nest) /* Nests */
2025 case NEST_TYPE_CLONE:
2026 sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
2028 case NEST_TYPE_SYMBOL_GOOD:
2029 case NEST_TYPE_SYMBOL_EVIL:
2030 sprintf(inner_buf, "(%c)", vault_aux_char);
2038 case PIT_TYPE_SYMBOL_GOOD:
2039 case PIT_TYPE_SYMBOL_EVIL:
2040 sprintf(inner_buf, "(%c)", vault_aux_char);
2042 case PIT_TYPE_DRAGON:
2043 switch (vault_aux_dragon_mask4)
2046 case RF4_BR_ACID: strcpy(inner_buf, "(»À)"); break;
2047 case RF4_BR_ELEC: strcpy(inner_buf, "(°ðºÊ)"); break;
2048 case RF4_BR_FIRE: strcpy(inner_buf, "(²Ð±ê)"); break;
2049 case RF4_BR_COLD: strcpy(inner_buf, "(Î䵤)"); break;
2050 case RF4_BR_POIS: strcpy(inner_buf, "(ÆÇ)"); break;
2051 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2052 strcpy(inner_buf, "(Ëü¿§)"); break;
2053 default: strcpy(inner_buf, "(̤ÄêµÁ)"); break;
2055 case RF4_BR_ACID: strcpy(inner_buf, "(acid)"); break;
2056 case RF4_BR_ELEC: strcpy(inner_buf, "(lightning)"); break;
2057 case RF4_BR_FIRE: strcpy(inner_buf, "(fire)"); break;
2058 case RF4_BR_COLD: strcpy(inner_buf, "(frost)"); break;
2059 case RF4_BR_POIS: strcpy(inner_buf, "(poison)"); break;
2060 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2061 strcpy(inner_buf, "(multi-hued)"); break;
2062 default: strcpy(inner_buf, "(undefined)"); break;
2073 /* A struct for nest monster information with cheat_hear */
2083 * Comp function for sorting nest monster information
2085 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
2087 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2088 int w1 = nest_mon_info[a].r_idx;
2089 int w2 = nest_mon_info[b].r_idx;
2090 monster_race *r1_ptr = &r_info[w1];
2091 monster_race *r2_ptr = &r_info[w2];
2097 /* Extract used info */
2098 z1 = nest_mon_info[a].used;
2099 z2 = nest_mon_info[b].used;
2101 /* Compare used status */
2102 if (z1 < z2) return FALSE;
2103 if (z1 > z2) return TRUE;
2105 /* Compare levels */
2106 if (r1_ptr->level < r2_ptr->level) return TRUE;
2107 if (r1_ptr->level > r2_ptr->level) return FALSE;
2109 /* Compare experience */
2110 if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
2111 if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
2113 /* Compare indexes */
2119 * Swap function for sorting nest monster information
2121 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
2123 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2124 nest_mon_info_type holder;
2130 holder = nest_mon_info[a];
2131 nest_mon_info[a] = nest_mon_info[b];
2132 nest_mon_info[b] = holder;
2136 #define NUM_NEST_MON_TYPE 64
2139 * Type 5 -- Monster nests
2141 * A monster nest is a "big" room, with an "inner" room, containing
2142 * a "collection" of monsters of a given type strewn about the room.
2144 * The monsters are chosen from a set of 64 randomly selected monster
2145 * races, to allow the nest creation to fail instead of having "holes".
2147 * Note the use of the "get_mon_num_prep()" function, and the special
2148 * "get_mon_num_hook()" restriction function, to prepare the "monster
2149 * allocation table" in such a way as to optimize the selection of
2150 * "appropriate" non-unique monsters for the nest.
2152 * Note that the "get_mon_num()" function may (rarely) fail, in which
2153 * case the nest will be empty.
2155 * Note that "monster nests" will never contain "unique" monsters.
2157 static bool build_type5(void)
2159 int y, x, y1, x1, y2, x2, xval, yval;
2161 nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
2167 int cur_nest_type = pick_vault_type(nest_types, d_info[dungeon_type].nest);
2168 vault_aux_type *n_ptr;
2170 /* No type available */
2171 if (cur_nest_type < 0) return FALSE;
2173 n_ptr = &nest_types[cur_nest_type];
2175 /* Process a preparation function if necessary */
2176 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2178 /* Prepare allocation table */
2179 get_mon_num_prep(n_ptr->hook_func, NULL);
2181 align.sub_align = SUB_ALIGN_NEUTRAL;
2183 /* Pick some monster types */
2184 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2186 int r_idx = 0, attempts = 100;
2187 monster_race *r_ptr = NULL;
2191 /* Get a (hard) monster type */
2192 r_idx = get_mon_num(dun_level + 11);
2193 r_ptr = &r_info[r_idx];
2195 /* Decline incorrect alignment */
2196 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2198 /* Accept this monster */
2202 /* Notice failure */
2203 if (!r_idx || !attempts) return FALSE;
2205 /* Note the alignment */
2206 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2207 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2209 nest_mon_info[i].r_idx = r_idx;
2210 nest_mon_info[i].used = FALSE;
2213 /* Find and reserve some space in the dungeon. Get center of room. */
2214 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2222 /* Place the floor area */
2223 for (y = y1 - 1; y <= y2 + 1; y++)
2225 for (x = x1 - 1; x <= x2 + 1; x++)
2227 c_ptr = &cave[y][x];
2228 place_floor_grid(c_ptr);
2229 c_ptr->info |= (CAVE_ROOM);
2233 /* Place the outer walls */
2234 for (y = y1 - 1; y <= y2 + 1; y++)
2236 c_ptr = &cave[y][x1 - 1];
2237 place_outer_grid(c_ptr);
2238 c_ptr = &cave[y][x2 + 1];
2239 place_outer_grid(c_ptr);
2241 for (x = x1 - 1; x <= x2 + 1; x++)
2243 c_ptr = &cave[y1 - 1][x];
2244 place_outer_grid(c_ptr);
2245 c_ptr = &cave[y2 + 1][x];
2246 place_outer_grid(c_ptr);
2250 /* Advance to the center room */
2256 /* The inner walls */
2257 for (y = y1 - 1; y <= y2 + 1; y++)
2259 c_ptr = &cave[y][x1 - 1];
2260 place_inner_grid(c_ptr);
2261 c_ptr = &cave[y][x2 + 1];
2262 place_inner_grid(c_ptr);
2265 for (x = x1 - 1; x <= x2 + 1; x++)
2267 c_ptr = &cave[y1 - 1][x];
2268 place_inner_grid(c_ptr);
2269 c_ptr = &cave[y2 + 1][x];
2270 place_inner_grid(c_ptr);
2272 for (y = y1; y <= y2; y++)
2274 for (x = x1; x <= x2; x++)
2276 add_cave_info(y, x, CAVE_ICKY);
2280 /* Place a secret door */
2281 switch (randint1(4))
2283 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2284 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2285 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2286 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2294 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(nest)(%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2296 msg_format("Monster nest (%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2300 /* Place some monsters */
2301 for (y = yval - 2; y <= yval + 2; y++)
2303 for (x = xval - 9; x <= xval + 9; x++)
2307 i = randint0(NUM_NEST_MON_TYPE);
2308 r_idx = nest_mon_info[i].r_idx;
2310 /* Place that "random" monster (no groups) */
2311 (void)place_monster_aux(0, y, x, r_idx, 0L);
2313 nest_mon_info[i].used = TRUE;
2317 if (cheat_room && cheat_hear)
2319 ang_sort_comp = ang_sort_comp_nest_mon_info;
2320 ang_sort_swap = ang_sort_swap_nest_mon_info;
2321 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2323 /* Dump the entries (prevent multi-printing) */
2324 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2326 if (!nest_mon_info[i].used) break;
2327 for (; i < NUM_NEST_MON_TYPE - 1; i++)
2329 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2330 if (!nest_mon_info[i + 1].used) break;
2332 msg_print(r_name + r_info[nest_mon_info[i].r_idx].name);
2341 * Type 6 -- Monster pits
2343 * A monster pit is a "big" room, with an "inner" room, containing
2344 * a "collection" of monsters of a given type organized in the room.
2346 * The inside room in a monster pit appears as shown below, where the
2347 * actual monsters in each location depend on the type of the pit
2349 * #####################
2350 * #0000000000000000000#
2351 * #0112233455543322110#
2352 * #0112233467643322110#
2353 * #0112233455543322110#
2354 * #0000000000000000000#
2355 * #####################
2357 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
2358 * to request 16 "appropriate" monsters, sorting them by level, and using
2359 * the "even" entries in this sorted list for the contents of the pit.
2361 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
2362 * which is handled by requiring a specific "breath" attack for all of the
2363 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
2364 * be present in many of the dragon pits, if they have the proper breath.
2366 * Note the use of the "get_mon_num_prep()" function, and the special
2367 * "get_mon_num_hook()" restriction function, to prepare the "monster
2368 * allocation table" in such a way as to optimize the selection of
2369 * "appropriate" non-unique monsters for the pit.
2371 * Note that the "get_mon_num()" function may (rarely) fail, in which case
2372 * the pit will be empty.
2374 * Note that "monster pits" will never contain "unique" monsters.
2376 static bool build_type6(void)
2378 int y, x, y1, x1, y2, x2, xval, yval;
2387 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2388 vault_aux_type *n_ptr;
2390 /* No type available */
2391 if (cur_pit_type < 0) return FALSE;
2393 n_ptr = &pit_types[cur_pit_type];
2395 /* Process a preparation function if necessary */
2396 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2398 /* Prepare allocation table */
2399 get_mon_num_prep(n_ptr->hook_func, NULL);
2401 align.sub_align = SUB_ALIGN_NEUTRAL;
2403 /* Pick some monster types */
2404 for (i = 0; i < 16; i++)
2406 int r_idx = 0, attempts = 100;
2407 monster_race *r_ptr = NULL;
2411 /* Get a (hard) monster type */
2412 r_idx = get_mon_num(dun_level + 11);
2413 r_ptr = &r_info[r_idx];
2415 /* Decline incorrect alignment */
2416 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2418 /* Accept this monster */
2422 /* Notice failure */
2423 if (!r_idx || !attempts) return FALSE;
2425 /* Note the alignment */
2426 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2427 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2432 /* Find and reserve some space in the dungeon. Get center of room. */
2433 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2441 /* Place the floor area */
2442 for (y = y1 - 1; y <= y2 + 1; y++)
2444 for (x = x1 - 1; x <= x2 + 1; x++)
2446 c_ptr = &cave[y][x];
2447 place_floor_grid(c_ptr);
2448 c_ptr->info |= (CAVE_ROOM);
2452 /* Place the outer walls */
2453 for (y = y1 - 1; y <= y2 + 1; y++)
2455 c_ptr = &cave[y][x1 - 1];
2456 place_outer_grid(c_ptr);
2457 c_ptr = &cave[y][x2 + 1];
2458 place_outer_grid(c_ptr);
2460 for (x = x1 - 1; x <= x2 + 1; x++)
2462 c_ptr = &cave[y1 - 1][x];
2463 place_outer_grid(c_ptr);
2464 c_ptr = &cave[y2 + 1][x];
2465 place_outer_grid(c_ptr);
2468 /* Advance to the center room */
2474 /* The inner walls */
2475 for (y = y1 - 1; y <= y2 + 1; y++)
2477 c_ptr = &cave[y][x1 - 1];
2478 place_inner_grid(c_ptr);
2479 c_ptr = &cave[y][x2 + 1];
2480 place_inner_grid(c_ptr);
2482 for (x = x1 - 1; x <= x2 + 1; x++)
2484 c_ptr = &cave[y1 - 1][x];
2485 place_inner_grid(c_ptr);
2486 c_ptr = &cave[y2 + 1][x];
2487 place_inner_grid(c_ptr);
2489 for (y = y1; y <= y2; y++)
2491 for (x = x1; x <= x2; x++)
2493 add_cave_info(y, x, CAVE_ICKY);
2497 /* Place a secret door */
2498 switch (randint1(4))
2500 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2501 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2502 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2503 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2506 /* Sort the entries */
2507 for (i = 0; i < 16 - 1; i++)
2509 /* Sort the entries */
2510 for (j = 0; j < 16 - 1; j++)
2515 int p1 = r_info[what[i1]].level;
2516 int p2 = r_info[what[i2]].level;
2522 what[i1] = what[i2];
2533 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(pit)(%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2535 msg_format("Monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2539 /* Select the entries */
2540 for (i = 0; i < 8; i++)
2542 /* Every other entry */
2543 what[i] = what[i * 2];
2548 msg_print(r_name + r_info[what[i]].name);
2552 /* Top and bottom rows */
2553 for (x = xval - 9; x <= xval + 9; x++)
2555 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2556 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2559 /* Middle columns */
2560 for (y = yval - 1; y <= yval + 1; y++)
2562 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2563 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2565 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2566 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2568 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2569 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2571 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2572 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2574 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2575 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2577 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2578 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2580 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2581 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2583 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2584 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2587 /* Above/Below the center monster */
2588 for (x = xval - 1; x <= xval + 1; x++)
2590 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2591 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2594 /* Next to the center monster */
2595 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2596 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2598 /* Center monster */
2599 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2605 /* coordinate translation code */
2606 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2612 * transno specifies what transformation is required. (0-7)
2613 * The lower two bits indicate by how much the vault is rotated,
2614 * and the upper bit indicates a reflection.
2615 * This is done by using rotation matrices... however since
2616 * these are mostly zeros for rotations by 90 degrees this can
2617 * be expressed simply in terms of swapping and inverting the
2618 * x and y coordinates.
2620 for (i = 0; i < transno % 4; i++)
2622 /* rotate by 90 degrees */
2630 /* Reflect depending on status of 3rd bit. */
2634 /* Add offsets so vault stays in the first quadrant */
2641 * Hack -- fill in "vault" rooms
2643 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2644 int xoffset, int yoffset, int transno)
2646 int dx, dy, x, y, i, j;
2653 /* Place dungeon features and objects */
2654 for (t = data, dy = 0; dy < ymax; dy++)
2656 for (dx = 0; dx < xmax; dx++, t++)
2658 /* prevent loop counter from being overwritten */
2663 coord_trans(&i, &j, xoffset, yoffset, transno);
2665 /* Extract the location */
2666 if (transno % 2 == 0)
2668 /* no swap of x/y */
2669 x = xval - (xmax / 2) + i;
2670 y = yval - (ymax / 2) + j;
2675 x = xval - (ymax / 2) + i;
2676 y = yval - (xmax / 2) + j;
2679 /* Hack -- skip "non-grids" */
2680 if (*t == ' ') continue;
2682 /* Access the grid */
2683 c_ptr = &cave[y][x];
2685 /* Lay down a floor */
2686 place_floor_grid(c_ptr);
2688 /* Remove any mimic */
2691 /* Part of a vault */
2692 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2694 /* Analyze the grid */
2697 /* Granite wall (outer) */
2699 place_outer_noperm_grid(c_ptr);
2702 /* Granite wall (inner) */
2704 place_inner_grid(c_ptr);
2707 /* Glass wall (inner) */
2709 place_inner_grid(c_ptr);
2710 c_ptr->feat = feat_glass_wall;
2713 /* Permanent wall (inner) */
2715 place_inner_perm_grid(c_ptr);
2718 /* Permanent glass wall (inner) */
2720 place_inner_perm_grid(c_ptr);
2721 c_ptr->feat = feat_permanent_glass_wall;
2726 if (randint0(100) < 75)
2728 place_object(y, x, 0L);
2738 place_secret_door(y, x, DOOR_DEFAULT);
2741 /* Secret glass doors */
2743 place_secret_door(y, x, DOOR_GLASS_DOOR);
2744 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
2749 place_secret_door(y, x, DOOR_CURTAIN);
2757 /* Black market in a dungeon */
2759 set_cave_feat(y, x, feat_black_market);
2760 store_init(NO_TOWN, STORE_BLACK);
2765 set_cave_feat(y, x, feat_pattern_start);
2769 set_cave_feat(y, x, feat_pattern_1);
2773 set_cave_feat(y, x, feat_pattern_2);
2777 set_cave_feat(y, x, feat_pattern_3);
2781 set_cave_feat(y, x, feat_pattern_4);
2785 set_cave_feat(y, x, feat_pattern_end);
2789 set_cave_feat(y, x, feat_pattern_exit);
2793 /* Reward for Pattern walk */
2794 object_level = base_level + 12;
2795 place_object(y, x, AM_GOOD | AM_GREAT);
2796 object_level = base_level;
2803 /* Place dungeon monsters and objects */
2804 for (t = data, dy = 0; dy < ymax; dy++)
2806 for (dx = 0; dx < xmax; dx++, t++)
2808 /* prevent loop counter from being overwritten */
2813 coord_trans(&i, &j, xoffset, yoffset, transno);
2815 /* Extract the location */
2816 if (transno % 2 == 0)
2818 /* no swap of x/y */
2819 x = xval - (xmax / 2) + i;
2820 y = yval - (ymax / 2) + j;
2825 x = xval - (ymax / 2) + i;
2826 y = yval - (xmax / 2) + j;
2829 /* Hack -- skip "non-grids" */
2830 if (*t == ' ') continue;
2832 /* Analyze the symbol */
2838 monster_level = base_level + 5;
2839 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2840 monster_level = base_level;
2844 /* Meaner monster */
2847 monster_level = base_level + 11;
2848 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2849 monster_level = base_level;
2853 /* Meaner monster, plus treasure */
2856 monster_level = base_level + 9;
2857 place_monster(y, x, PM_ALLOW_SLEEP);
2858 monster_level = base_level;
2859 object_level = base_level + 7;
2860 place_object(y, x, AM_GOOD);
2861 object_level = base_level;
2865 /* Nasty monster and treasure */
2868 monster_level = base_level + 40;
2869 place_monster(y, x, PM_ALLOW_SLEEP);
2870 monster_level = base_level;
2871 object_level = base_level + 20;
2872 place_object(y, x, AM_GOOD | AM_GREAT);
2873 object_level = base_level;
2877 /* Monster and/or object */
2880 if (randint0(100) < 50)
2882 monster_level = base_level + 3;
2883 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2884 monster_level = base_level;
2886 if (randint0(100) < 50)
2888 object_level = base_level + 7;
2889 place_object(y, x, 0L);
2890 object_level = base_level;
2902 * Type 7 -- simple vaults (see "v_info.txt")
2904 static bool build_type7(void)
2910 int xoffset, yoffset;
2913 /* Pick a lesser vault */
2914 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2916 /* Access a random vault record */
2917 v_ptr = &v_info[randint0(max_v_idx)];
2919 /* Accept the first lesser vault */
2920 if (v_ptr->typ == 7) break;
2923 /* No lesser vault found */
2924 if (dummy >= SAFE_MAX_ATTEMPTS)
2929 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2931 msg_print("Warning! Could not place lesser vault!");
2937 /* pick type of transformation (0-7) */
2938 transno = randint0(8);
2940 /* calculate offsets */
2944 /* Some huge vault cannot be ratated to fit in the dungeon */
2945 if (x+2 > cur_hgt-2)
2947 /* Forbid 90 or 270 degree ratation */
2951 coord_trans(&x, &y, 0, 0, transno);
2971 /* Find and reserve some space in the dungeon. Get center of room. */
2972 if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
2980 if (cheat_room) msg_format("¾®¤µ¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
2982 if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
2985 /* Hack -- Build the vault */
2986 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2987 v_text + v_ptr->text, xoffset, yoffset, transno);
2994 * Type 8 -- greater vaults (see "v_info.txt")
2996 static bool build_type8(void)
3003 int xoffset, yoffset;
3005 /* Pick a greater vault */
3006 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
3008 /* Access a random vault record */
3009 v_ptr = &v_info[randint0(max_v_idx)];
3011 /* Accept the first greater vault */
3012 if (v_ptr->typ == 8) break;
3015 /* No greater vault found */
3016 if (dummy >= SAFE_MAX_ATTEMPTS)
3021 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
3023 msg_print("Warning! Could not place greater vault!");
3029 /* pick type of transformation (0-7) */
3030 transno = randint0(8);
3032 /* calculate offsets */
3036 /* Some huge vault cannot be ratated to fit in the dungeon */
3037 if (x+2 > cur_hgt-2)
3039 /* Forbid 90 or 270 degree ratation */
3043 coord_trans(&x, &y, 0, 0, transno);
3064 * Try to allocate space for room. If fails, exit
3066 * Hack -- Prepare a bit larger space (+2, +2) to
3067 * prevent generation of vaults with no-entrance.
3069 /* Find and reserve some space in the dungeon. Get center of room. */
3070 if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
3073 v_ptr = &v_info[76 + randint1(3)];
3078 if (cheat_room) msg_format("µðÂç¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3080 if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
3083 /* Hack -- Build the vault */
3084 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3085 v_text + v_ptr->text, xoffset, yoffset, transno);
3091 * Structure to hold all "fill" data
3094 typedef struct fill_data_type fill_data_type;
3096 struct fill_data_type
3109 /* features to fill with */
3118 /* number of filled squares */
3122 static fill_data_type fill_data;
3125 /* Store routine for the fractal cave generator */
3126 /* this routine probably should be an inline function or a macro. */
3127 static void store_height(int x, int y, int val)
3129 /* if on boundary set val > cutoff so walls are not as square */
3130 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3131 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3132 (val <= fill_data.c1)) val = fill_data.c1 + 1;
3134 /* store the value in height-map format */
3135 cave[y][x].feat = val;
3142 * Explanation of the plasma fractal algorithm:
3144 * A grid of points is created with the properties of a 'height-map'
3145 * This is done by making the corners of the grid have a random value.
3146 * The grid is then subdivided into one with twice the resolution.
3147 * The new points midway between two 'known' points can be calculated
3148 * by taking the average value of the 'known' ones and randomly adding
3149 * or subtracting an amount proportional to the distance between those
3150 * points. The final 'middle' points of the grid are then calculated
3151 * by averaging all four of the originally 'known' corner points. An
3152 * random amount is added or subtracted from this to get a value of the
3153 * height at that point. The scaling factor here is adjusted to the
3154 * slightly larger distance diagonally as compared to orthogonally.
3156 * This is then repeated recursively to fill an entire 'height-map'
3157 * A rectangular map is done the same way, except there are different
3158 * scaling factors along the x and y directions.
3160 * A hack to change the amount of correlation between points is done using
3161 * the grd variable. If the current step size is greater than grd then
3162 * the point will be random, otherwise it will be calculated by the
3163 * above algorithm. This makes a maximum distance at which two points on
3164 * the height map can affect each other.
3166 * How fractal caves are made:
3168 * When the map is complete, a cut-off value is used to create a cave.
3169 * Heights below this value are "floor", and heights above are "wall".
3170 * This also can be used to create lakes, by adding more height levels
3171 * representing shallow and deep water/ lava etc.
3173 * The grd variable affects the width of passages.
3174 * The roug variable affects the roughness of those passages
3176 * The tricky part is making sure the created cave is connected. This
3177 * is done by 'filling' from the inside and only keeping the 'filled'
3178 * floor. Walls bounding the 'filled' floor are also kept. Everything
3179 * else is converted to the normal _extra_.
3184 * Note that this uses the cave.feat array in a very hackish way
3185 * the values are first set to zero, and then each array location
3186 * is used as a "heightmap"
3187 * The heightmap then needs to be converted back into the "feat" format.
3189 * grd=level at which fractal turns on. smaller gives more mazelike caves
3190 * roug=roughness level. 16=normal. higher values make things more convoluted
3191 * small values are good for smooth walls.
3192 * size=length of the side of the square cave system.
3194 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3196 int xhsize, yhsize, xsize, ysize, maxsize;
3199 * fixed point variables- these are stored as 256 x normal value
3200 * this gives 8 binary places of fractional part + 8 places of normal part
3203 u16b xstep, xhstep, ystep, yhstep;
3204 u16b xstep2, xhstep2, ystep2, yhstep2;
3205 u16b i, j, ii, jj, diagsize, xxsize, yysize;
3207 /* Cache for speed */
3208 u16b xm, xp, ym, yp;
3210 /* redefine size so can change the value if out of range */
3214 /* Paranoia about size of the system of caves */
3215 if (xsize > 254) xsize = 254;
3216 if (xsize < 4) xsize = 4;
3217 if (ysize > 254) ysize = 254;
3218 if (ysize < 4) ysize = 4;
3220 /* get offsets to middle of array */
3224 /* fix rounding problem */
3228 /* get limits of region */
3229 fill_data.xmin = x0 - xhsize;
3230 fill_data.ymin = y0 - yhsize;
3231 fill_data.xmax = x0 + xhsize;
3232 fill_data.ymax = y0 + yhsize;
3234 /* Store cutoff in global for quick access */
3235 fill_data.c1 = cutoff;
3238 * Scale factor for middle points:
3239 * About sqrt(2) * 256 - correct for a square lattice
3240 * approximately correct for everything else.
3244 /* maximum of xsize and ysize */
3245 maxsize = (xsize > ysize) ? xsize : ysize;
3247 /* Clear the section */
3248 for (i = 0; i <= xsize; i++)
3250 for (j = 0; j <= ysize; j++)
3252 /* -1 is a flag for "not done yet" */
3253 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3254 /* Clear icky flag because may be redoing the cave */
3255 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3259 /* Boundaries are walls */
3260 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
3261 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
3262 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
3263 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
3265 /* Set the middle square to be an open area. */
3266 cave[y0][x0].feat = 0;
3268 /* Initialize the step sizes */
3269 xstep = xhstep = xsize * 256;
3270 ystep = yhstep = ysize * 256;
3271 xxsize = xsize * 256;
3272 yysize = ysize * 256;
3275 * Fill in the rectangle with fractal height data -
3276 * like the 'plasma fractal' in fractint.
3278 while ((xhstep > 256) || (yhstep > 256))
3280 /* Halve the step sizes */
3286 /* cache well used values */
3287 xstep2 = xstep / 256;
3288 ystep2 = ystep / 256;
3290 xhstep2 = xhstep / 256;
3291 yhstep2 = yhstep / 256;
3293 /* middle top to bottom. */
3294 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3296 for (j = 0; j <= yysize; j += ystep)
3298 /* cache often used values */
3299 ii = i / 256 + fill_data.xmin;
3300 jj = j / 256 + fill_data.ymin;
3303 if (cave[jj][ii].feat == -1)
3307 /* If greater than 'grid' level then is random */
3308 store_height(ii, jj, randint1(maxsize));
3312 /* Average of left and right points +random bit */
3313 store_height(ii, jj,
3314 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3315 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3316 + (randint1(xstep2) - xhstep2) * roug / 16);
3323 /* middle left to right. */
3324 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3326 for (i = 0; i <= xxsize; i += xstep)
3328 /* cache often used values */
3329 ii = i / 256 + fill_data.xmin;
3330 jj = j / 256 + fill_data.ymin;
3333 if (cave[jj][ii].feat == -1)
3337 /* If greater than 'grid' level then is random */
3338 store_height(ii, jj, randint1(maxsize));
3342 /* Average of up and down points +random bit */
3343 store_height(ii, jj,
3344 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3345 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3346 + (randint1(ystep2) - yhstep2) * roug / 16);
3353 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3355 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3357 /* cache often used values */
3358 ii = i / 256 + fill_data.xmin;
3359 jj = j / 256 + fill_data.ymin;
3362 if (cave[jj][ii].feat == -1)
3366 /* If greater than 'grid' level then is random */
3367 store_height(ii, jj, randint1(maxsize));
3371 /* Cache reused values. */
3372 xm = fill_data.xmin + (i - xhstep) / 256;
3373 xp = fill_data.xmin + (i + xhstep) / 256;
3374 ym = fill_data.ymin + (j - yhstep) / 256;
3375 yp = fill_data.ymin + (j + yhstep) / 256;
3378 * Average over all four corners + scale by diagsize to
3379 * reduce the effect of the square grid on the shape of the fractal
3381 store_height(ii, jj,
3382 (cave[ym][xm].feat + cave[yp][xm].feat
3383 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3384 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3393 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)
3396 * function used to convert from height-map back to the
3397 * normal angband cave format
3399 if (cave[y][x].info & CAVE_ICKY)
3406 /* Show that have looked at this square */
3407 cave[y][x].info|= (CAVE_ICKY);
3409 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3410 if (cave[y][x].feat <= c1)
3412 /* 25% of the time use the other tile : it looks better this way */
3413 if (randint1(100) < 75)
3415 cave[y][x].feat = feat1;
3416 cave[y][x].info &= ~(CAVE_MASK);
3417 cave[y][x].info |= info1;
3422 cave[y][x].feat = feat2;
3423 cave[y][x].info &= ~(CAVE_MASK);
3424 cave[y][x].info |= info2;
3428 else if (cave[y][x].feat <= c2)
3430 /* 25% of the time use the other tile : it looks better this way */
3431 if (randint1(100) < 75)
3433 cave[y][x].feat = feat2;
3434 cave[y][x].info &= ~(CAVE_MASK);
3435 cave[y][x].info |= info2;
3440 cave[y][x].feat = feat1;
3441 cave[y][x].info &= ~(CAVE_MASK);
3442 cave[y][x].info |= info1;
3446 else if (cave[y][x].feat <= c3)
3448 cave[y][x].feat = feat3;
3449 cave[y][x].info |= info3;
3452 /* if greater than cutoff then is a wall */
3455 place_outer_bold(y, x);
3465 * Quick and nasty fill routine used to find the connected region
3466 * of floor in the middle of the cave
3468 static void cave_fill(byte y, byte x)
3477 /*** Start Grid ***/
3479 /* Enqueue that entry */
3484 /* Now process the queue */
3485 while (flow_head != flow_tail)
3487 /* Extract the next entry */
3488 ty = temp_y[flow_head];
3489 tx = temp_x[flow_head];
3491 /* Forget that entry */
3492 if (++flow_head == TEMP_MAX) flow_head = 0;
3494 /* Add the "children" */
3495 for (d = 0; d < 8; d++)
3497 int old_head = flow_tail;
3499 /* Child location */
3500 j = ty + ddy_ddd[d];
3501 i = tx + ddx_ddd[d];
3503 /* Paranoia Don't leave the cave */
3504 if (!in_bounds(j, i))
3506 /* affect boundary */
3507 cave[j][i].info |= CAVE_ICKY;
3511 /* If within bounds */
3512 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3513 && (j > fill_data.ymin) && (j < fill_data.ymax))
3515 /* If not a wall or floor done before */
3516 if (hack_isnt_wall(j, i,
3517 fill_data.c1, fill_data.c2, fill_data.c3,
3518 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3519 fill_data.info1, fill_data.info2, fill_data.info3))
3521 /* Enqueue that entry */
3522 temp_y[flow_tail] = j;
3523 temp_x[flow_tail] = i;
3525 /* Advance the queue */
3526 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3528 /* Hack -- Overflow by forgetting new entry */
3529 if (flow_tail == flow_head)
3531 flow_tail = old_head;
3535 /* keep tally of size of cave system */
3536 (fill_data.amount)++;
3542 /* affect boundary */
3543 cave[j][i].info |= CAVE_ICKY;
3550 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3552 int x, y, i, xhsize, yhsize;
3554 /* offsets to middle from corner */
3560 * select region connected to center of cave system
3561 * this gets rid of alot of isolated one-sqaures that
3562 * can make teleport traps instadeaths...
3566 fill_data.c1 = cutoff;
3570 /* features to fill with */
3571 fill_data.feat1 = floor_type[randint0(100)];
3572 fill_data.feat2 = floor_type[randint0(100)];
3573 fill_data.feat3 = floor_type[randint0(100)];
3575 fill_data.info1 = CAVE_FLOOR;
3576 fill_data.info2 = CAVE_FLOOR;
3577 fill_data.info3 = CAVE_FLOOR;
3579 /* number of filled squares */
3580 fill_data.amount = 0;
3582 cave_fill((byte)y0, (byte)x0);
3584 /* if tally too small, try again */
3585 if (fill_data.amount < 10)
3587 /* too small - clear area and try again later */
3588 for (x = 0; x <= xsize; ++x)
3590 for (y = 0; y <= ysize; ++y)
3592 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3593 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3600 * Do boundarys-check to see if they are next to a filled region
3601 * If not then they are set to normal granite
3602 * If so then they are marked as room walls.
3604 for (i = 0; i <= xsize; ++i)
3607 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3609 /* Next to a 'filled' region? - set to be room walls */
3610 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3611 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3612 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3613 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3617 /* set to be normal granite */
3618 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3621 /* bottom boundary */
3622 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3624 /* Next to a 'filled' region? - set to be room walls */
3625 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3626 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3627 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3628 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3632 /* set to be normal granite */
3633 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3636 /* clear the icky flag-don't need it any more */
3637 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3638 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3641 /* Do the left and right boundaries minus the corners (done above) */
3642 for (i = 1; i < ysize; ++i)
3645 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3648 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3649 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3650 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3651 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3656 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3658 /* right boundary */
3659 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3662 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3663 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3664 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3665 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3670 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3673 /* clear icky flag -done with it */
3674 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3675 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3679 /* Do the rest: convert back to the normal format */
3680 for (x = 1; x < xsize; ++x)
3682 for (y = 1; y < ysize; ++y)
3684 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3685 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3687 /* Clear the icky flag in the filled region */
3688 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3690 /* Set appropriate flags */
3691 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3692 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3694 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3695 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3698 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3699 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3702 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3707 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3708 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3713 /* Clear the unconnected regions */
3714 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3715 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3721 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3722 * Extra doors appear inside the system. (Its not very noticeable though.)
3723 * This can be removed by "filling" from the outside in. This allows a separation
3724 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
3725 * The extra effort for what seems to be only a minor thing (even non-existant if you
3726 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3735 * Driver routine to create fractal cave system
3737 static bool build_type9(void)
3739 int grd, roug, cutoff, xsize, ysize, y0, x0;
3741 bool done, light, room;
3743 /* get size: note 'Evenness'*/
3744 xsize = randint1(22) * 2 + 6;
3745 ysize = randint1(15) * 2 + 6;
3747 /* Find and reserve some space in the dungeon. Get center of room. */
3748 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3750 /* Limit to the minimum room size, and retry */
3754 /* Find and reserve some space in the dungeon. Get center of room. */
3755 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3761 return build_type1();
3765 light = done = FALSE;
3768 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3772 /* Note: size must be even or there are rounding problems
3773 * This causes the tunnels not to connect properly to the room */
3775 /* testing values for these parameters feel free to adjust */
3776 grd = 1 << (randint0(4));
3778 /* want average of about 16 */
3779 roug = randint1(8) * randint1(4);
3782 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3783 randint1(xsize / 4) + randint1(ysize / 4);
3786 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3788 /* Convert to normal format + clean up */
3789 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3795 #ifdef ALLOW_CAVERNS_AND_LAKES
3797 * Builds a cave system in the center of the dungeon.
3799 void build_cavern(void)
3801 int grd, roug, cutoff, xsize, ysize, x0, y0;
3804 light = done = FALSE;
3805 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3807 /* Make a cave the size of the dungeon */
3808 xsize = cur_wid - 1;
3809 ysize = cur_hgt - 1;
3813 /* Paranoia: make size even */
3819 /* testing values for these parameters: feel free to adjust */
3820 grd = randint1(4) + 4;
3822 /* want average of about 16 */
3823 roug = randint1(8) * randint1(4);
3829 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3831 /* Convert to normal format+ clean up */
3832 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3836 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3838 int x, y, i, xhsize, yhsize;
3839 int feat1, feat2, feat3;
3841 /* offsets to middle from corner */
3845 /* Get features based on type */
3848 case LAKE_T_LAVA: /* Lava */
3849 feat1 = feat_deep_lava;
3850 feat2 = feat_shallow_lava;
3851 feat3 = floor_type[randint0(100)];
3853 case LAKE_T_WATER: /* Water */
3854 feat1 = feat_deep_water;
3855 feat2 = feat_shallow_water;
3856 feat3 = floor_type[randint0(100)];
3858 case LAKE_T_CAVE: /* Collapsed cave */
3859 feat1 = floor_type[randint0(100)];
3860 feat2 = floor_type[randint0(100)];
3861 feat3 = feat_rubble;
3863 case LAKE_T_EARTH_VAULT: /* Earth vault */
3864 feat1 = feat_rubble;
3865 feat2 = floor_type[randint0(100)];
3866 feat3 = feat_rubble;
3868 case LAKE_T_AIR_VAULT: /* Air vault */
3873 case LAKE_T_WATER_VAULT: /* Water vault */
3874 feat1 = feat_shallow_water;
3875 feat2 = feat_deep_water;
3876 feat3 = feat_shallow_water;
3878 case LAKE_T_FIRE_VAULT: /* Fire Vault */
3879 feat1 = feat_shallow_lava;
3880 feat2 = feat_deep_lava;
3881 feat3 = feat_shallow_lava;
3885 default: return FALSE;
3889 * select region connected to center of cave system
3890 * this gets rid of alot of isolated one-sqaures that
3891 * can make teleport traps instadeaths...
3899 /* features to fill with */
3900 fill_data.feat1 = feat1;
3901 fill_data.feat2 = feat2;
3902 fill_data.feat3 = feat3;
3904 fill_data.info1 = 0;
3905 fill_data.info2 = 0;
3906 fill_data.info3 = 0;
3908 /* number of filled squares */
3909 fill_data.amount = 0;
3911 /* select region connected to center of cave system
3912 * this gets rid of alot of isolated one-sqaures that
3913 * can make teleport traps instadeaths... */
3914 cave_fill((byte)y0, (byte)x0);
3916 /* if tally too small, try again */
3917 if (fill_data.amount < 10)
3919 /* too small -clear area and try again later */
3920 for (x = 0; x <= xsize; ++x)
3922 for (y = 0; y <= ysize; ++y)
3924 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3925 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3931 /* Do boundarys- set to normal granite */
3932 for (i = 0; i <= xsize; ++i)
3934 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3935 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3937 /* clear the icky flag-don't need it any more */
3938 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3939 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3942 /* Do the left and right boundaries minus the corners (done above) */
3944 for (i = 1; i < ysize; ++i)
3946 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3947 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3949 /* clear icky flag -done with it */
3950 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3951 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3955 /* Do the rest: convert back to the normal format */
3956 for (x = 1; x < xsize; ++x)
3958 for (y = 1; y < ysize; ++y)
3960 /* Fill unconnected regions with granite */
3961 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3962 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3963 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3965 /* turn off icky flag (no longer needed.) */
3966 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3969 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
3971 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3981 * makes a lake/collapsed cave system in the center of the dungeon
3983 void build_lake(int type)
3985 int grd, roug, xsize, ysize, x0, y0;
3989 /* paranoia - exit if lake type out of range. */
3990 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
3992 msg_format("Invalid lake type (%d)", type);
3996 /* Make the size of the dungeon */
3997 xsize = cur_wid - 1;
3998 ysize = cur_hgt - 1;
4002 /* Paranoia: make size even */
4008 /* testing values for these parameters: feel free to adjust */
4009 grd = randint1(3) + 4;
4011 /* want average of about 16 */
4012 roug = randint1(8) * randint1(4);
4014 /* Make up size of various componants */
4018 /* Deep water/lava */
4019 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4021 /* Shallow boundary */
4025 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
4027 /* Convert to normal format+ clean up */
4028 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
4031 #endif /* ALLOW_CAVERNS_AND_LAKES */
4035 * Routine used by the random vault creators to add a door to a location
4036 * Note that range checking has to be done in the calling routine.
4038 * The doors must be INSIDE the allocated region.
4040 static void add_door(int x, int y)
4042 /* Need to have a wall in the center square */
4043 if (!is_outer_bold(y, x)) return;
4050 * where x=don't care
4054 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
4055 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
4058 place_secret_door(y, x, DOOR_DEFAULT);
4060 /* set boundarys so don't get wide doors */
4061 place_solid_bold(y, x - 1);
4062 place_solid_bold(y, x + 1);
4071 * where x = don't care
4074 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4075 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4078 place_secret_door(y, x, DOOR_DEFAULT);
4080 /* set boundarys so don't get wide doors */
4081 place_solid_bold(y - 1, x);
4082 place_solid_bold(y + 1, x);
4088 * Routine that fills the empty areas of a room with treasure and monsters.
4090 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4092 int x, y, cx, cy, size;
4095 /* center of room:*/
4099 /* Rough measure of size of vault= sum of lengths of sides */
4100 size = abs(x2 - x1) + abs(y2 - y1);
4102 for (x = x1; x <= x2; x++)
4104 for (y = y1; y <= y2; y++)
4106 /* Thing added based on distance to center of vault
4107 * Difficulty is 1-easy to 10-hard */
4108 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4110 /* hack- empty square part of the time */
4111 if ((randint1(100) - difficulty * 3) > 50) value = 20;
4113 /* if floor, shallow water and lava */
4114 if (is_floor_bold(y, x) ||
4115 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4117 /* The smaller 'value' is, the better the stuff */
4120 /* Meanest monster + treasure */
4121 monster_level = base_level + 40;
4122 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4123 monster_level = base_level;
4124 object_level = base_level + 20;
4125 place_object(y, x, AM_GOOD);
4126 object_level = base_level;
4130 /* Mean monster +treasure */
4131 monster_level = base_level + 20;
4132 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4133 monster_level = base_level;
4134 object_level = base_level + 10;
4135 place_object(y, x, AM_GOOD);
4136 object_level = base_level;
4138 else if (value < 10)
4141 monster_level = base_level + 9;
4142 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4143 monster_level = base_level;
4145 else if (value < 17)
4147 /* Intentional Blank space */
4150 * (Want some of the vault to be empty
4151 * so have room for group monsters.
4152 * This is used in the hack above to lower
4153 * the density of stuff in the vault.)
4156 else if (value < 23)
4158 /* Object or trap */
4159 if (randint0(100) < 25)
4161 place_object(y, x, 0L);
4168 else if (value < 30)
4170 /* Monster and trap */
4171 monster_level = base_level + 5;
4172 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4173 monster_level = base_level;
4176 else if (value < 40)
4178 /* Monster or object */
4179 if (randint0(100) < 50)
4181 monster_level = base_level + 3;
4182 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4183 monster_level = base_level;
4185 if (randint0(100) < 50)
4187 object_level = base_level + 7;
4188 place_object(y, x, 0L);
4189 object_level = base_level;
4192 else if (value < 50)
4201 /* 20% monster, 40% trap, 20% object, 20% blank space */
4202 if (randint0(100) < 20)
4204 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4206 else if (randint0(100) < 50)
4210 else if (randint0(100) < 50)
4212 place_object(y, x, 0L);
4223 * This function creates a random vault that looks like a collection of bubbles.
4224 * It works by getting a set of coordinates that represent the center of each
4225 * bubble. The entire room is made by seeing which bubble center is closest. If
4226 * two centers are equidistant then the square is a wall, otherwise it is a floor.
4227 * The only exception is for squares really near a center, these are always floor.
4228 * (It looks better than without this check.)
4230 * Note: If two centers are on the same point then this algorithm will create a
4231 * blank bubble filled with walls. - This is prevented from happening.
4233 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4235 #define BUBBLENUM 10 /* number of bubbles */
4237 /* array of center points of bubbles */
4238 coord center[BUBBLENUM];
4241 u16b min1, min2, temp;
4244 /* Offset from center to top left hand corner */
4245 int xhsize = xsize / 2;
4246 int yhsize = ysize / 2;
4249 if (cheat_room) msg_print("Bubble Vault");
4251 /* Allocate center of bubbles */
4252 center[0].x = randint1(xsize - 3) + 1;
4253 center[0].y = randint1(ysize - 3) + 1;
4255 for (i = 1; i < BUBBLENUM; i++)
4259 /* get center and check to see if it is unique */
4264 x = randint1(xsize - 3) + 1;
4265 y = randint1(ysize - 3) + 1;
4267 for (j = 0; j < i; j++)
4269 /* rough test to see if there is an overlap */
4270 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4279 /* Top and bottom boundaries */
4280 for (i = 0; i < xsize; i++)
4282 int x = x0 - xhsize + i;
4284 place_outer_noperm_bold(y0 - yhsize + 0, x);
4285 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4286 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4287 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4290 /* Left and right boundaries */
4291 for (i = 1; i < ysize - 1; i++)
4293 int y = y0 - yhsize + i;
4295 place_outer_noperm_bold(y, x0 - xhsize + 0);
4296 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4297 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4298 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4301 /* Fill in middle with bubbles */
4302 for (x = 1; x < xsize - 1; x++)
4304 for (y = 1; y < ysize - 1; y++)
4306 /* Get distances to two closest centers */
4309 min1 = distance(x, y, center[0].x, center[0].y);
4310 min2 = distance(x, y, center[1].x, center[1].y);
4314 /* swap if in wrong order */
4321 for (i = 2; i < BUBBLENUM; i++)
4323 temp = distance(x, y, center[i].x, center[i].y);
4331 else if (temp < min2)
4333 /* second smallest */
4337 if (((min2 - min1) <= 2) && (!(min1 < 3)))
4339 /* Boundary at midpoint+ not at inner region of bubble */
4340 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4344 /* middle of a bubble */
4345 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4348 /* clean up rest of flags */
4349 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4353 /* Try to add some random doors */
4354 for (i = 0; i < 500; i++)
4356 x = randint1(xsize - 3) - xhsize + x0 + 1;
4357 y = randint1(ysize - 3) - yhsize + y0 + 1;
4361 /* Fill with monsters and treasure, low difficulty */
4362 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4367 * Overlay a rectangular room given its bounds
4368 * This routine is used by build_room_vault
4369 * The area inside the walls is not touched:
4370 * only granite is removed- normal walls stay
4372 static void build_room(int x1, int x2, int y1, int y2)
4374 int x, y, i, xsize, ysize, temp;
4376 /* Check if rectangle has no width */
4377 if ((x1 == x2) || (y1 == y2)) return;
4382 /* Swap boundaries if in wrong order */
4390 /* Swap boundaries if in wrong order */
4396 /* get total widths */
4401 /* Top and bottom boundaries */
4402 for (i = 0; i <= xsize; i++)
4404 place_outer_noperm_bold(y1, x1 + i);
4405 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4406 place_outer_noperm_bold(y2, x1 + i);
4407 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4410 /* Left and right boundaries */
4411 for (i = 1; i < ysize; i++)
4413 place_outer_noperm_bold(y1 + i, x1);
4414 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4415 place_outer_noperm_bold(y1 + i, x2);
4416 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4420 for (x = 1; x < xsize; x++)
4422 for (y = 1; y < ysize; y++)
4424 if (is_extra_bold(y1+y, x1+x))
4426 /* clear the untouched region */
4427 place_floor_bold(y1 + y, x1 + x);
4428 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4432 /* make it a room- but don't touch */
4433 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4440 /* Create a random vault that looks like a collection of overlapping rooms */
4442 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4444 int i, x1, x2, y1, y2, xhsize, yhsize;
4446 /* get offset from center */
4450 if (cheat_room) msg_print("Room Vault");
4452 /* fill area so don't get problems with arena levels */
4453 for (x1 = 0; x1 < xsize; x1++)
4455 int x = x0 - xhsize + x1;
4457 for (y1 = 0; y1 < ysize; y1++)
4459 int y = y0 - yhsize + y1;
4461 place_extra_bold(y, x);
4462 cave[y][x].info &= (~CAVE_ICKY);
4466 /* add ten random rooms */
4467 for (i = 0; i < 10; i++)
4469 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4470 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4471 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4472 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4473 build_room(x1, x2, y1, y2);
4476 /* Add some random doors */
4477 for (i = 0; i < 500; i++)
4479 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4480 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4484 /* Fill with monsters and treasure, high difficulty */
4485 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4489 /* Create a random vault out of a fractal cave */
4490 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4492 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4493 bool done, light, room;
4495 /* round to make sizes even */
4501 if (cheat_room) msg_print("Cave Vault");
4503 light = done = FALSE;
4508 /* testing values for these parameters feel free to adjust */
4509 grd = 1 << randint0(4);
4511 /* want average of about 16 */
4512 roug = randint1(8) * randint1(4);
4515 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4516 randint1(xsize / 4) + randint1(ysize / 4);
4519 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4521 /* Convert to normal format+ clean up */
4522 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4525 /* Set icky flag because is a vault */
4526 for (x = 0; x <= xsize; x++)
4528 for (y = 0; y <= ysize; y++)
4530 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4534 /* Fill with monsters and treasure, low difficulty */
4535 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4539 * maze vault -- rectangular labyrinthine rooms
4541 * maze vault uses two routines:
4542 * r_visit - a recursive routine that builds the labyrinth
4543 * build_maze_vault - a driver routine that calls r_visit and adds
4544 * monsters, traps and treasure
4546 * The labyrinth is built by creating a spanning tree of a graph.
4547 * The graph vertices are at
4548 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4549 * and the edges are the vertical and horizontal nearest neighbors.
4551 * The spanning tree is created by performing a suitably randomized
4552 * depth-first traversal of the graph. The only adjustable parameter
4553 * is the randint0(3) below; it governs the relative density of
4554 * twists and turns in the labyrinth: smaller number, more twists.
4556 static void r_visit(int y1, int x1, int y2, int x2,
4557 int node, int dir, int *visited)
4559 int i, j, m, n, temp, x, y, adj[4];
4561 /* dimensions of vertex array */
4562 m = (x2 - x1) / 2 + 1;
4563 n = (y2 - y1) / 2 + 1;
4565 /* mark node visited and set it to a floor */
4567 x = 2 * (node % m) + x1;
4568 y = 2 * (node / m) + y1;
4569 place_floor_bold(y, x);
4571 /* setup order of adjacent node visits */
4574 /* pick a random ordering */
4575 for (i = 0; i < 4; i++)
4577 for (i = 0; i < 4; i++)
4588 /* pick a random ordering with dir first */
4590 for (i = 1; i < 4; i++)
4592 for (i = 1; i < 4; i++)
4594 j = 1 + randint0(3);
4601 for (i = 0; i < 4; i++)
4606 /* (0,+) - check for bottom boundary */
4607 if ((node / m < n - 1) && (visited[node + m] == 0))
4609 place_floor_bold(y + 1, x);
4610 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4614 /* (0,-) - check for top boundary */
4615 if ((node / m > 0) && (visited[node - m] == 0))
4617 place_floor_bold(y - 1, x);
4618 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4622 /* (+,0) - check for right boundary */
4623 if ((node % m < m - 1) && (visited[node + 1] == 0))
4625 place_floor_bold(y, x + 1);
4626 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4630 /* (-,0) - check for left boundary */
4631 if ((node % m > 0) && (visited[node - 1] == 0))
4633 place_floor_bold(y, x - 1);
4634 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4641 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4645 int m, n, num_vertices, *visited;
4650 if (cheat_room && is_vault) msg_print("Maze Vault");
4652 /* Choose lite or dark */
4653 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4655 /* Pick a random room size - randomized by calling routine */
4664 /* generate the room */
4665 for (y = y1 - 1; y <= y2 + 1; y++)
4667 for (x = x1 - 1; x <= x2 + 1; x++)
4669 c_ptr = &cave[y][x];
4670 c_ptr->info |= CAVE_ROOM;
4671 if (is_vault) c_ptr->info |= CAVE_ICKY;
4672 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4674 place_outer_grid(c_ptr);
4678 place_extra_grid(c_ptr);
4682 place_inner_grid(c_ptr);
4684 if (light) c_ptr->info |= (CAVE_GLOW);
4688 /* dimensions of vertex array */
4691 num_vertices = m * n;
4693 /* initialize array of visited vertices */
4694 C_MAKE(visited, num_vertices, int);
4696 /* traverse the graph to create a spaning tree, pick a random root */
4697 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4699 /* Fill with monsters and treasure, low difficulty */
4700 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4702 C_KILL(visited, num_vertices, int);
4706 /* Build a "mini" checkerboard vault
4708 * This is done by making a permanent wall maze and setting
4709 * the diagonal sqaures of the checker board to be granite.
4710 * The vault has two entrances on opposite sides to guarantee
4711 * a way to get in even if the vault abuts a side of the dungeon.
4713 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4716 int y1, x1, y2, x2, y, x, total;
4717 int m, n, num_vertices;
4720 if (cheat_room) msg_print("Mini Checker Board Vault");
4722 /* Pick a random room size */
4732 /* generate the room */
4733 for (x = x1 - 2; x <= x2 + 2; x++)
4735 if (!in_bounds(y1-2,x)) break;
4737 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4739 place_outer_noperm_bold(y1-2, x);
4742 for (x = x1 - 2; x <= x2 + 2; x++)
4744 if (!in_bounds(y2+2,x)) break;
4746 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4748 place_outer_noperm_bold(y2+2, x);
4751 for (y = y1 - 2; y <= y2 + 2; y++)
4753 if (!in_bounds(y,x1-2)) break;
4755 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4757 place_outer_noperm_bold(y, x1-2);
4760 for (y = y1 - 2; y <= y2 + 2; y++)
4762 if (!in_bounds(y,x2+2)) break;
4764 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4766 place_outer_noperm_bold(y, x2+2);
4769 for (y = y1 - 1; y <= y2 + 1; y++)
4771 for (x = x1 - 1; x <= x2 + 1; x++)
4773 cave_type *c_ptr = &cave[y][x];
4775 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4777 /* Permanent walls */
4778 place_inner_perm_grid(c_ptr);
4783 /* dimensions of vertex array */
4786 num_vertices = m * n;
4788 /* initialize array of visited vertices */
4789 C_MAKE(visited, num_vertices, int);
4791 /* traverse the graph to create a spannng tree, pick a random root */
4792 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4794 /* Make it look like a checker board vault */
4795 for (x = x1; x <= x2; x++)
4797 for (y = y1; y <= y2; y++)
4799 total = x - x1 + y - y1;
4800 /* If total is odd- and is a floor then make a wall */
4801 if ((total % 2 == 1) && is_floor_bold(y, x))
4803 place_inner_bold(y, x);
4808 /* Make a couple of entrances */
4811 /* left and right */
4812 y = randint1(dy) + dy / 2;
4813 place_inner_bold(y1 + y, x1 - 1);
4814 place_inner_bold(y1 + y, x2 + 1);
4818 /* top and bottom */
4819 x = randint1(dx) + dx / 2;
4820 place_inner_bold(y1 - 1, x1 + x);
4821 place_inner_bold(y2 + 1, x1 + x);
4824 /* Fill with monsters and treasure, highest difficulty */
4825 fill_treasure(x1, x2, y1, y2, 10);
4827 C_KILL(visited, num_vertices, int);
4831 /* Build a town/ castle by using a recursive algorithm.
4832 * Basically divide each region in a probalistic way to create
4833 * smaller regions. When the regions get too small stop.
4835 * The power variable is a measure of how well defended a region is.
4836 * This alters the possible choices.
4838 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4844 /* Temp variables */
4850 if ((power < 3) && (xsize > 12) && (ysize > 12))
4852 /* Need outside wall +keep */
4859 /* Make rooms + subdivide */
4860 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4866 choice = randint1(2) + 1;
4871 /* Mostly subdivide */
4872 choice = randint1(3) + 1;
4876 /* Based on the choice made above, do something */
4884 /* top and bottom */
4885 for (x = x1; x <= x2; x++)
4887 place_outer_bold(y1, x);
4888 place_outer_bold(y2, x);
4891 /* left and right */
4892 for (y = y1 + 1; y < y2; y++)
4894 place_outer_bold(y, x1);
4895 place_outer_bold(y, x2);
4898 /* Make a couple of entrances */
4901 /* left and right */
4902 y = randint1(ysize) + y1;
4903 place_floor_bold(y, x1);
4904 place_floor_bold(y, x2);
4908 /* top and bottom */
4909 x = randint1(xsize) + x1;
4910 place_floor_bold(y1, x);
4911 place_floor_bold(y2, x);
4914 /* Select size of keep */
4915 t1 = randint1(ysize / 3) + y1;
4916 t2 = y2 - randint1(ysize / 3);
4917 t3 = randint1(xsize / 3) + x1;
4918 t4 = x2 - randint1(xsize / 3);
4920 /* Do outside areas */
4922 /* Above and below keep */
4923 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4924 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4926 /* Left and right of keep */
4927 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4928 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4930 /* Make the keep itself: */
4943 /* Try to build a room */
4944 if ((xsize < 3) || (ysize < 3))
4946 for (y = y1; y < y2; y++)
4948 for (x = x1; x < x2; x++)
4950 place_inner_bold(y, x);
4958 /* Make outside walls */
4959 /* top and bottom */
4960 for (x = x1 + 1; x <= x2 - 1; x++)
4962 place_inner_bold(y1 + 1, x);
4963 place_inner_bold(y2 - 1, x);
4966 /* left and right */
4967 for (y = y1 + 1; y <= y2 - 1; y++)
4969 place_inner_bold(y, x1 + 1);
4970 place_inner_bold(y, x2 - 1);
4974 y = randint1(ysize - 3) + y1 + 1;
4979 place_floor_bold(y, x1 + 1);
4984 place_floor_bold(y, x2 - 1);
4987 /* Build the room */
4988 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4993 /* Try and divide vertically */
4997 for (y = y1; y < y2; y++)
4999 for (x = x1; x < x2; x++)
5001 place_inner_bold(y, x);
5007 t1 = randint1(xsize - 2) + x1 + 1;
5008 build_recursive_room(x1, y1, t1, y2, power - 2);
5009 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
5014 /* Try and divide horizontally */
5018 for (y = y1; y < y2; y++)
5020 for (x = x1; x < x2; x++)
5022 place_inner_bold(y, x);
5028 t1 = randint1(ysize - 2) + y1 + 1;
5029 build_recursive_room(x1, y1, x2, t1, power - 2);
5030 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
5037 /* Build a castle */
5039 /* Driver routine: clear the region and call the recursive
5042 *This makes a vault that looks like a castle/ city in the dungeon.
5044 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
5050 /* Pick a random room size */
5059 if (cheat_room) msg_print("Castle Vault");
5061 /* generate the room */
5062 for (y = y1 - 1; y <= y2 + 1; y++)
5064 for (x = x1 - 1; x <= x2 + 1; x++)
5066 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5067 /* Make everything a floor */
5068 place_floor_bold(y, x);
5072 /* Make the castle */
5073 build_recursive_room(x1, y1, x2, y2, randint1(5));
5075 /* Fill with monsters and treasure, low difficulty */
5076 fill_treasure(x1, x2, y1, y2, randint1(3));
5081 * Add outer wall to a floored region
5082 * Note: no range checking is done so must be inside dungeon
5083 * This routine also stomps on doors
5085 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5088 feature_type *f_ptr;
5091 if (!in_bounds(y, x)) return;
5093 c_ptr = &cave[y][x];
5095 /* hack- check to see if square has been visited before
5096 * if so, then exit (use room flag to do this) */
5097 if (c_ptr->info & CAVE_ROOM) return;
5100 c_ptr->info |= CAVE_ROOM;
5102 f_ptr = &f_info[c_ptr->feat];
5104 if (is_floor_bold(y, x))
5106 for (i = -1; i <= 1; i++)
5108 for (j = -1; j <= 1; j++)
5110 if ((x + i >= x1) && (x + i <= x2) &&
5111 (y + j >= y1) && (y + j <= y2))
5113 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5114 if (light) c_ptr->info |= CAVE_GLOW;
5119 else if (is_extra_bold(y, x))
5121 /* Set bounding walls */
5122 place_outer_bold(y, x);
5123 if (light) c_ptr->info |= CAVE_GLOW;
5125 else if (permanent_wall(f_ptr))
5127 /* Set bounding walls */
5128 if (light) c_ptr->info |= CAVE_GLOW;
5134 * Hacked distance formula - gives the 'wrong' answer.
5135 * Used to build crypts
5137 static int dist2(int x1, int y1, int x2, int y2,
5138 int h1, int h2, int h3, int h4)
5144 /* Basically this works by taking the normal pythagorean formula
5145 * and using an expansion to express this in a way without the
5146 * square root. This approximate formula is then perturbed to give
5147 * the distorted results. (I found this by making a mistake when I was
5148 * trying to fix the circular rooms.)
5151 /* h1-h4 are constants that describe the metric */
5152 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5153 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5154 return (((dx + dy) * 128) / 181 +
5155 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5156 /* 128/181 is approx. 1/sqrt(2) */
5161 * Build target vault.
5162 * This is made by two concentric "crypts" with perpendicular
5163 * walls creating the cross-hairs.
5165 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5169 /* Make a random metric */
5171 h1 = randint1(32) - 16;
5174 h4 = randint1(32) - 16;
5176 if (cheat_room) msg_print("Target Vault");
5178 /* work out outer radius */
5189 for (x = x0 - rad; x <= x0 + rad; x++)
5191 for (y = y0 - rad; y <= y0 + rad; y++)
5193 /* clear room flag */
5194 cave[y][x].info &= ~(CAVE_ROOM);
5196 /* Vault - so is "icky" */
5197 cave[y][x].info |= CAVE_ICKY;
5199 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5201 /* inside- so is floor */
5202 place_floor_bold(y, x);
5206 /* make granite outside so arena works */
5207 place_extra_bold(y, x);
5210 /* proper boundary for arena */
5211 if (((y + rad) == y0) || ((y - rad) == y0) ||
5212 ((x + rad) == x0) || ((x - rad) == x0))
5214 place_extra_bold(y, x);
5219 /* Find visible outer walls and set to be FEAT_OUTER */
5220 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5221 x0 + rad + 1, y0 + rad + 1);
5223 /* Add inner wall */
5224 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5226 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5228 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5230 /* Make an internal wall */
5231 place_inner_bold(y, x);
5236 /* Add perpendicular walls */
5237 for (x = x0 - rad; x <= x0 + rad; x++)
5239 place_inner_bold(y0, x);
5242 for (y = y0 - rad; y <= y0 + rad; y++)
5244 place_inner_bold(y, x0);
5247 /* Make inner vault */
5248 for (y = y0 - 1; y <= y0 + 1; y++)
5250 place_inner_bold(y, x0 - 1);
5251 place_inner_bold(y, x0 + 1);
5253 for (x = x0 - 1; x <= x0 + 1; x++)
5255 place_inner_bold(y0 - 1, x);
5256 place_inner_bold(y0 + 1, x);
5259 place_floor_bold(y0, x0);
5262 /* Add doors to vault */
5263 /* get two distances so can place doors relative to centre */
5264 x = (rad - 2) / 4 + 1;
5267 add_door(x0 + x, y0);
5268 add_door(x0 + y, y0);
5269 add_door(x0 - x, y0);
5270 add_door(x0 - y, y0);
5271 add_door(x0, y0 + x);
5272 add_door(x0, y0 + y);
5273 add_door(x0, y0 - x);
5274 add_door(x0, y0 - y);
5276 /* Fill with stuff - medium difficulty */
5277 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5281 #ifdef ALLOW_CAVERNS_AND_LAKES
5283 * This routine uses a modified version of the lake code to make a
5284 * distribution of some terrain type over the vault. This type
5285 * depends on the dungeon depth.
5287 * Miniture rooms are then scattered across the vault.
5289 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5294 int xsize, ysize, xhsize, yhsize, x, y, i;
5298 if (cheat_room) msg_print("Elemental Vault");
5300 /* round to make sizes even */
5308 /* Earth vault (Rubble) */
5309 type = LAKE_T_EARTH_VAULT;
5311 else if (dun_level < 50)
5313 /* Air vault (Trees) */
5314 type = LAKE_T_AIR_VAULT;
5316 else if (dun_level < 75)
5318 /* Water vault (shallow water) */
5319 type = LAKE_T_WATER_VAULT;
5323 /* Fire vault (shallow lava) */
5324 type = LAKE_T_FIRE_VAULT;
5329 /* testing values for these parameters: feel free to adjust */
5330 grd = 1 << (randint0(3));
5332 /* want average of about 16 */
5333 roug = randint1(8) * randint1(4);
5335 /* Make up size of various componants */
5339 /* Deep water/lava */
5340 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5342 /* Shallow boundary */
5346 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5348 /* Convert to normal format+ clean up */
5349 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5352 /* Set icky flag because is a vault */
5353 for (x = 0; x <= xsize; x++)
5355 for (y = 0; y <= ysize; y++)
5357 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5361 /* make a few rooms in the vault */
5362 for (i = 1; i <= (xsize * ysize) / 50; i++)
5364 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5365 y0 + randint0(ysize - 4) - ysize / 2 + 2);
5368 /* Fill with monsters and treasure, low difficulty */
5369 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5370 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5372 #endif /* ALLOW_CAVERNS_AND_LAKES */
5378 static bool build_type10(void)
5380 int y0, x0, xsize, ysize, vtype;
5383 /* big enough to look good, small enough to be fairly common. */
5384 xsize = randint1(22) + 22;
5385 ysize = randint1(11) + 11;
5387 /* Find and reserve some space in the dungeon. Get center of room. */
5388 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5390 /* Select type of vault */
5391 #ifdef ALLOW_CAVERNS_AND_LAKES
5394 vtype = randint1(15);
5396 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5397 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
5398 #else /* ALLOW_CAVERNS_AND_LAKES */
5401 vtype = randint1(7);
5403 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5404 ((vtype == 1) || (vtype == 3)));
5405 #endif /* ALLOW_CAVERNS_AND_LAKES */
5409 /* Build an appropriate room */
5410 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
5411 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5412 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5413 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5414 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5415 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5416 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5417 #ifdef ALLOW_CAVERNS_AND_LAKES
5418 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5419 #endif /* ALLOW_CAVERNS_AND_LAKES */
5420 /* I know how to add a few more... give me some time. */
5423 default: return FALSE;
5431 * Build an vertical oval room.
5432 * For every grid in the possible square, check the distance.
5433 * If it's less than the radius, make it a room square.
5435 * When done fill from the inside to find the walls,
5437 static bool build_type11(void)
5439 int rad, x, y, x0, y0;
5442 /* Occasional light */
5443 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5447 /* Find and reserve some space in the dungeon. Get center of room. */
5448 if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5450 /* Make circular floor */
5451 for (x = x0 - rad; x <= x0 + rad; x++)
5453 for (y = y0 - rad; y <= y0 + rad; y++)
5455 if (distance(y0, x0, y, x) <= rad - 1)
5457 /* inside- so is floor */
5458 place_floor_bold(y, x);
5460 else if (distance(y0, x0, y, x) <= rad + 1)
5462 /* make granite outside so arena works */
5463 place_extra_bold(y, x);
5468 /* Find visible outer walls and set to be FEAT_OUTER */
5469 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5477 * For every grid in the possible square, check the (fake) distance.
5478 * If it's less than the radius, make it a room square.
5480 * When done fill from the inside to find the walls,
5482 static bool build_type12(void)
5484 int rad, x, y, x0, y0;
5486 bool emptyflag = TRUE;
5488 /* Make a random metric */
5490 h1 = randint1(32) - 16;
5493 h4 = randint1(32) - 16;
5495 /* Occasional light */
5496 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5500 /* Find and reserve some space in the dungeon. Get center of room. */
5501 if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5504 for (x = x0 - rad; x <= x0 + rad; x++)
5506 for (y = y0 - rad; y <= y0 + rad; y++)
5508 /* clear room flag */
5509 cave[y][x].info &= ~(CAVE_ROOM);
5511 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5513 /* inside - so is floor */
5514 place_floor_bold(y, x);
5516 else if (distance(y0, x0, y, x) < 3)
5518 place_floor_bold(y, x);
5522 /* make granite outside so arena works */
5523 place_extra_bold(y, x);
5526 /* proper boundary for arena */
5527 if (((y + rad) == y0) || ((y - rad) == y0) ||
5528 ((x + rad) == x0) || ((x - rad) == x0))
5530 place_extra_bold(y, x);
5535 /* Find visible outer walls and set to be FEAT_OUTER */
5536 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5537 x0 + rad + 1, y0 + rad + 1);
5539 /* Check to see if there is room for an inner vault */
5540 for (x = x0 - 2; x <= x0 + 2; x++)
5542 for (y = y0 - 2; y <= y0 + 2; y++)
5544 if (!is_floor_bold(y, x))
5546 /* Wall in the way */
5552 if (emptyflag && one_in_(2))
5554 /* Build the vault */
5555 build_small_room(x0, y0);
5557 /* Place a treasure in the vault */
5558 place_object(y0, x0, 0L);
5560 /* Let's guard the treasure well */
5561 vault_monsters(y0, x0, randint0(2) + 3);
5563 /* Traps naturally */
5564 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5572 * Helper function for "trapped monster pit"
5574 static bool vault_aux_trapped_pit(int r_idx)
5576 monster_race *r_ptr = &r_info[r_idx];
5578 /* Validate the monster */
5579 if (!vault_monster_okay(r_idx)) return (FALSE);
5581 /* No wall passing monster */
5582 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5590 * Type 13 -- Trapped monster pits
5592 * A trapped monster pit is a "big" room with a straight corridor in
5593 * which wall opening traps are placed, and with two "inner" rooms
5594 * containing a "collection" of monsters of a given type organized in
5597 * The trapped monster pit appears as shown below, where the actual
5598 * monsters in each location depend on the type of the pit
5600 * #########################
5602 * ####################### #
5603 * #####001123454321100### #
5604 * ###0012234567654322100# #
5605 * ####################### #
5607 * # #######################
5608 * # #0012234567654322100###
5609 * # ###001123454321100#####
5610 * # #######################
5612 * #########################
5614 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5615 * to request 16 "appropriate" monsters, sorting them by level, and using
5616 * the "even" entries in this sorted list for the contents of the pit.
5618 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5619 * which is handled by requiring a specific "breath" attack for all of the
5620 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5621 * be present in many of the dragon pits, if they have the proper breath.
5623 * Note the use of the "get_mon_num_prep()" function, and the special
5624 * "get_mon_num_hook()" restriction function, to prepare the "monster
5625 * allocation table" in such a way as to optimize the selection of
5626 * "appropriate" non-unique monsters for the pit.
5628 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5629 * the pit will be empty.
5631 * Note that "monster pits" will never contain "unique" monsters.
5633 static bool build_type13(void)
5635 static int placing[][3] = {
5636 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5637 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5638 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5639 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5640 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5641 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5642 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5643 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5644 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5645 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5646 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5647 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5648 {-2, -4, 3}, {-3, -2, 3},
5649 {+2, -4, 3}, {+3, -2, 3},
5650 {-2, +4, 3}, {-3, +2, 3},
5651 {+2, +4, 3}, {+3, +2, 3},
5652 {-2, -3, 4}, {-3, -1, 4},
5653 {+2, -3, 4}, {+3, -1, 4},
5654 {-2, +3, 4}, {-3, +1, 4},
5655 {+2, +3, 4}, {+3, +1, 4},
5656 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5657 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5658 {-2, -1, 6}, {-2, +1, 6},
5659 {+2, -1, 6}, {+2, +1, 6},
5660 {-2, 0, 7}, {+2, 0, 7},
5664 int y, x, y1, x1, y2, x2, xval, yval;
5673 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5674 vault_aux_type *n_ptr;
5676 /* Only in Angband */
5677 if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5679 /* No type available */
5680 if (cur_pit_type < 0) return FALSE;
5682 n_ptr = &pit_types[cur_pit_type];
5684 /* Process a preparation function if necessary */
5685 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5687 /* Prepare allocation table */
5688 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5690 align.sub_align = SUB_ALIGN_NEUTRAL;
5692 /* Pick some monster types */
5693 for (i = 0; i < 16; i++)
5695 int r_idx = 0, attempts = 100;
5696 monster_race *r_ptr = NULL;
5700 /* Get a (hard) monster type */
5701 r_idx = get_mon_num(dun_level + 0);
5702 r_ptr = &r_info[r_idx];
5704 /* Decline incorrect alignment */
5705 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5707 /* Accept this monster */
5711 /* Notice failure */
5712 if (!r_idx || !attempts) return FALSE;
5714 /* Note the alignment */
5715 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5716 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5721 /* Find and reserve some space in the dungeon. Get center of room. */
5722 if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5730 /* Fill with inner walls */
5731 for (y = y1 - 1; y <= y2 + 1; y++)
5733 for (x = x1 - 1; x <= x2 + 1; x++)
5735 c_ptr = &cave[y][x];
5736 place_inner_grid(c_ptr);
5737 c_ptr->info |= (CAVE_ROOM);
5741 /* Place the floor area 1 */
5742 for (x = x1 + 3; x <= x2 - 3; x++)
5744 c_ptr = &cave[yval-2][x];
5745 place_floor_grid(c_ptr);
5746 add_cave_info(yval-2, x, CAVE_ICKY);
5748 c_ptr = &cave[yval+2][x];
5749 place_floor_grid(c_ptr);
5750 add_cave_info(yval+2, x, CAVE_ICKY);
5753 /* Place the floor area 2 */
5754 for (x = x1 + 5; x <= x2 - 5; x++)
5756 c_ptr = &cave[yval-3][x];
5757 place_floor_grid(c_ptr);
5758 add_cave_info(yval-3, x, CAVE_ICKY);
5760 c_ptr = &cave[yval+3][x];
5761 place_floor_grid(c_ptr);
5762 add_cave_info(yval+3, x, CAVE_ICKY);
5766 for (x = x1; x <= x2; x++)
5768 c_ptr = &cave[yval][x];
5769 place_floor_grid(c_ptr);
5770 c_ptr = &cave[y1][x];
5771 place_floor_grid(c_ptr);
5772 c_ptr = &cave[y2][x];
5773 place_floor_grid(c_ptr);
5776 /* Place the outer walls */
5777 for (y = y1 - 1; y <= y2 + 1; y++)
5779 c_ptr = &cave[y][x1 - 1];
5780 place_outer_grid(c_ptr);
5781 c_ptr = &cave[y][x2 + 1];
5782 place_outer_grid(c_ptr);
5784 for (x = x1 - 1; x <= x2 + 1; x++)
5786 c_ptr = &cave[y1 - 1][x];
5787 place_outer_grid(c_ptr);
5788 c_ptr = &cave[y2 + 1][x];
5789 place_outer_grid(c_ptr);
5792 /* Random corridor */
5795 for (y = y1; y <= yval; y++)
5797 place_floor_bold(y, x2);
5798 place_solid_bold(y, x1-1);
5800 for (y = yval; y <= y2 + 1; y++)
5802 place_floor_bold(y, x1);
5803 place_solid_bold(y, x2+1);
5808 for (y = yval; y <= y2 + 1; y++)
5810 place_floor_bold(y, x1);
5811 place_solid_bold(y, x2+1);
5813 for (y = y1; y <= yval; y++)
5815 place_floor_bold(y, x2);
5816 place_solid_bold(y, x1-1);
5820 /* Place the wall open trap */
5821 cave[yval][xval].mimic = cave[yval][xval].feat;
5822 cave[yval][xval].feat = feat_trap_open;
5824 /* Sort the entries */
5825 for (i = 0; i < 16 - 1; i++)
5827 /* Sort the entries */
5828 for (j = 0; j < 16 - 1; j++)
5833 int p1 = r_info[what[i1]].level;
5834 int p2 = r_info[what[i2]].level;
5840 what[i1] = what[i2];
5851 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5853 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5857 /* Select the entries */
5858 for (i = 0; i < 8; i++)
5860 /* Every other entry */
5861 what[i] = what[i * 2];
5866 msg_print(r_name + r_info[what[i]].name);
5870 for (i = 0; placing[i][2] >= 0; i++)
5872 y = yval + placing[i][0];
5873 x = xval + placing[i][1];
5874 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5882 * Type 14 -- trapped rooms
5884 * A special trap is placed at center of the room
5886 static bool build_type14(void)
5888 int y, x, y2, x2, yval, xval;
5889 int y1, x1, xsize, ysize;
5896 /* Pick a room size */
5902 xsize = x1 + x2 + 1;
5903 ysize = y1 + y2 + 1;
5905 /* Find and reserve some space in the dungeon. Get center of room. */
5906 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5908 /* Choose lite or dark */
5909 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5912 /* Get corner values */
5913 y1 = yval - ysize / 2;
5914 x1 = xval - xsize / 2;
5915 y2 = yval + (ysize - 1) / 2;
5916 x2 = xval + (xsize - 1) / 2;
5919 /* Place a full floor under the room */
5920 for (y = y1 - 1; y <= y2 + 1; y++)
5922 for (x = x1 - 1; x <= x2 + 1; x++)
5924 c_ptr = &cave[y][x];
5925 place_floor_grid(c_ptr);
5926 c_ptr->info |= (CAVE_ROOM);
5927 if (light) c_ptr->info |= (CAVE_GLOW);
5931 /* Walls around the room */
5932 for (y = y1 - 1; y <= y2 + 1; y++)
5934 c_ptr = &cave[y][x1 - 1];
5935 place_outer_grid(c_ptr);
5936 c_ptr = &cave[y][x2 + 1];
5937 place_outer_grid(c_ptr);
5939 for (x = x1 - 1; x <= x2 + 1; x++)
5941 c_ptr = &cave[y1 - 1][x];
5942 place_outer_grid(c_ptr);
5943 c_ptr = &cave[y2 + 1][x];
5944 place_outer_grid(c_ptr);
5947 if (dun_level < 30 + randint1(30))
5948 trap = feat_trap_piranha;
5950 trap = feat_trap_armageddon;
5952 /* Place a special trap */
5953 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
5954 c_ptr->mimic = c_ptr->feat;
5961 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5963 msg_format("Room of %s", f_name + f_info[trap].name);
5972 * Helper function for "glass room"
5974 static bool vault_aux_lite(int r_idx)
5976 monster_race *r_ptr = &r_info[r_idx];
5978 /* Validate the monster */
5979 if (!vault_monster_okay(r_idx)) return FALSE;
5981 /* Require lite attack */
5982 if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->flags5 & RF5_BA_LITE)) return FALSE;
5984 /* No wall passing monsters */
5985 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
5987 /* No disintegrating monsters */
5988 if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
5994 * Helper function for "glass room"
5996 static bool vault_aux_shards(int r_idx)
5998 monster_race *r_ptr = &r_info[r_idx];
6000 /* Validate the monster */
6001 if (!vault_monster_okay(r_idx)) return FALSE;
6003 /* Require shards breath attack */
6004 if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
6010 * Hack -- determine if a template is potion
6012 static bool kind_is_potion(int k_idx)
6014 return k_info[k_idx].tval == TV_POTION;
6018 * Type 15 -- glass rooms
6020 static bool build_type15(void)
6022 int y, x, y2, x2, yval, xval;
6023 int y1, x1, xsize, ysize;
6028 /* Pick a room size */
6029 xsize = rand_range(9, 13);
6030 ysize = rand_range(9, 13);
6032 /* Find and reserve some space in the dungeon. Get center of room. */
6033 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
6035 /* Choose lite or dark */
6036 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
6038 /* Get corner values */
6039 y1 = yval - ysize / 2;
6040 x1 = xval - xsize / 2;
6041 y2 = yval + (ysize - 1) / 2;
6042 x2 = xval + (xsize - 1) / 2;
6044 /* Place a full floor under the room */
6045 for (y = y1 - 1; y <= y2 + 1; y++)
6047 for (x = x1 - 1; x <= x2 + 1; x++)
6049 c_ptr = &cave[y][x];
6050 place_floor_grid(c_ptr);
6051 c_ptr->feat = feat_glass_floor;
6052 c_ptr->info |= (CAVE_ROOM);
6053 if (light) c_ptr->info |= (CAVE_GLOW);
6057 /* Walls around the room */
6058 for (y = y1 - 1; y <= y2 + 1; y++)
6060 c_ptr = &cave[y][x1 - 1];
6061 place_outer_grid(c_ptr);
6062 c_ptr->feat = feat_glass_wall;
6063 c_ptr = &cave[y][x2 + 1];
6064 place_outer_grid(c_ptr);
6065 c_ptr->feat = feat_glass_wall;
6067 for (x = x1 - 1; x <= x2 + 1; x++)
6069 c_ptr = &cave[y1 - 1][x];
6070 place_outer_grid(c_ptr);
6071 c_ptr->feat = feat_glass_wall;
6072 c_ptr = &cave[y2 + 1][x];
6073 place_outer_grid(c_ptr);
6074 c_ptr->feat = feat_glass_wall;
6077 switch (randint1(3))
6079 case 1: /* 4 lite breathers + potion */
6083 /* Prepare allocation table */
6084 get_mon_num_prep(vault_aux_lite, NULL);
6086 /* Place fixed lite berathers */
6087 for (dir1 = 4; dir1 < 8; dir1++)
6089 int r_idx = get_mon_num(dun_level);
6091 y = yval + 2 * ddy_ddd[dir1];
6092 x = xval + 2 * ddx_ddd[dir1];
6093 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
6095 /* Walls around the breather */
6096 for (dir2 = 0; dir2 < 8; dir2++)
6098 c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
6099 place_inner_grid(c_ptr);
6100 c_ptr->feat = feat_glass_wall;
6104 /* Walls around the potion */
6105 for (dir1 = 0; dir1 < 4; dir1++)
6107 y = yval + 2 * ddy_ddd[dir1];
6108 x = xval + 2 * ddx_ddd[dir1];
6109 c_ptr = &cave[y][x];
6110 place_inner_perm_grid(c_ptr);
6111 c_ptr->feat = feat_permanent_glass_wall;
6116 y = yval + 2 * ddy_ddd[dir1];
6117 x = xval + 2 * ddx_ddd[dir1];
6118 place_secret_door(y, x, DOOR_GLASS_DOOR);
6119 c_ptr = &cave[y][x];
6120 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
6122 /* Place a potion */
6123 get_obj_num_hook = kind_is_potion;
6124 place_object(yval, xval, AM_NO_FIXED_ART);
6128 case 2: /* 1 lite breather + random object */
6133 c_ptr = &cave[y1 + 1][x1 + 1];
6134 place_inner_grid(c_ptr);
6135 c_ptr->feat = feat_glass_wall;
6137 c_ptr = &cave[y1 + 1][x2 - 1];
6138 place_inner_grid(c_ptr);
6139 c_ptr->feat = feat_glass_wall;
6141 c_ptr = &cave[y2 - 1][x1 + 1];
6142 place_inner_grid(c_ptr);
6143 c_ptr->feat = feat_glass_wall;
6145 c_ptr = &cave[y2 - 1][x2 - 1];
6146 place_inner_grid(c_ptr);
6147 c_ptr->feat = feat_glass_wall;
6149 /* Prepare allocation table */
6150 get_mon_num_prep(vault_aux_lite, NULL);
6152 r_idx = get_mon_num(dun_level);
6153 if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
6155 /* Walls around the breather */
6156 for (dir1 = 0; dir1 < 8; dir1++)
6158 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
6159 place_inner_grid(c_ptr);
6160 c_ptr->feat = feat_glass_wall;
6163 /* Curtains around the breather */
6164 for (y = yval - 1; y <= yval + 1; y++)
6166 place_closed_door(y, xval - 2, DOOR_CURTAIN);
6167 place_closed_door(y, xval + 2, DOOR_CURTAIN);
6169 for (x = xval - 1; x <= xval + 1; x++)
6171 place_closed_door(yval - 2, x, DOOR_CURTAIN);
6172 place_closed_door(yval + 2, x, DOOR_CURTAIN);
6175 /* Place an object */
6176 place_object(yval, xval, AM_NO_FIXED_ART);
6180 case 3: /* 4 shards breathers + 2 potions */
6184 /* Walls around the potion */
6185 for (y = yval - 2; y <= yval + 2; y++)
6187 c_ptr = &cave[y][xval - 3];
6188 place_inner_grid(c_ptr);
6189 c_ptr->feat = feat_glass_wall;
6190 c_ptr = &cave[y][xval + 3];
6191 place_inner_grid(c_ptr);
6192 c_ptr->feat = feat_glass_wall;
6194 for (x = xval - 2; x <= xval + 2; x++)
6196 c_ptr = &cave[yval - 3][x];
6197 place_inner_grid(c_ptr);
6198 c_ptr->feat = feat_glass_wall;
6199 c_ptr = &cave[yval + 3][x];
6200 place_inner_grid(c_ptr);
6201 c_ptr->feat = feat_glass_wall;
6203 for (dir1 = 4; dir1 < 8; dir1++)
6205 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
6206 place_inner_grid(c_ptr);
6207 c_ptr->feat = feat_glass_wall;
6210 /* Prepare allocation table */
6211 get_mon_num_prep(vault_aux_shards, NULL);
6213 /* Place shard berathers */
6214 for (dir1 = 4; dir1 < 8; dir1++)
6216 int r_idx = get_mon_num(dun_level);
6218 y = yval + ddy_ddd[dir1];
6219 x = xval + ddx_ddd[dir1];
6220 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
6223 /* Place two potions */
6226 get_obj_num_hook = kind_is_potion;
6227 place_object(yval, xval - 1, AM_NO_FIXED_ART);
6228 get_obj_num_hook = kind_is_potion;
6229 place_object(yval, xval + 1, AM_NO_FIXED_ART);
6233 get_obj_num_hook = kind_is_potion;
6234 place_object(yval - 1, xval, AM_NO_FIXED_ART);
6235 get_obj_num_hook = kind_is_potion;
6236 place_object(yval + 1, xval, AM_NO_FIXED_ART);
6246 msg_print("¥¬¥é¥¹¤ÎÉô²°");
6248 msg_print("Glass room");
6257 * Attempt to build a room of the given type at the given block
6259 * Note that we restrict the number of "crowded" rooms to reduce
6260 * the chance of overflowing the monster list during level creation.
6262 static bool room_build(int typ)
6267 /* Build an appropriate room */
6268 case ROOM_T_NORMAL: return build_type1();
6269 case ROOM_T_OVERLAP: return build_type2();
6270 case ROOM_T_CROSS: return build_type3();
6271 case ROOM_T_INNER_FEAT: return build_type4();
6272 case ROOM_T_NEST: return build_type5();
6273 case ROOM_T_PIT: return build_type6();
6274 case ROOM_T_LESSER_VAULT: return build_type7();
6275 case ROOM_T_GREATER_VAULT: return build_type8();
6276 case ROOM_T_FRACAVE: return build_type9();
6277 case ROOM_T_RANDOM_VAULT: return build_type10();
6278 case ROOM_T_OVAL: return build_type11();
6279 case ROOM_T_CRYPT: return build_type12();
6280 case ROOM_T_TRAP_PIT: return build_type13();
6281 case ROOM_T_TRAP: return build_type14();
6282 case ROOM_T_GLASS: return build_type15();
6290 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
6293 * [from SAngband (originally from OAngband)]
6295 * Generate rooms in dungeon. Build bigger rooms at first.
6297 bool generate_rooms(void)
6303 int prob_list[ROOM_T_MAX];
6304 int rooms_built = 0;
6305 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
6306 int level_index = MIN(10, div_round(dun_level, 10));
6308 /* Number of each type of room on this level */
6309 s16b room_num[ROOM_T_MAX];
6311 /* Limit number of rooms */
6312 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
6314 /* Assume normal cave */
6315 room_info_type *room_info_ptr = room_info_normal;
6318 * Initialize probability list.
6320 for (i = 0; i < ROOM_T_MAX; i++)
6322 /* No rooms allowed above their minimum depth. */
6323 if (dun_level < room_info_ptr[i].min_level)
6329 prob_list[i] = room_info_ptr[i].prob[level_index];
6334 * XXX -- Various dungeon types and options.
6337 /* Ironman sees only Greater Vaults */
6338 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
6340 for (i = 0; i < ROOM_T_MAX; i++)
6342 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6343 else prob_list[i] = 0;
6347 /* Forbidden vaults */
6348 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6350 prob_list[ROOM_T_LESSER_VAULT] = 0;
6351 prob_list[ROOM_T_GREATER_VAULT] = 0;
6352 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6356 /* NO_CAVE dungeon (Castle)*/
6357 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6359 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6360 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6361 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6364 /* CAVE dungeon (Orc cave etc.) */
6365 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6367 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6370 /* No caves when a (random) cavern exists: they look bad */
6371 else if (dun->cavern || dun->empty_level)
6373 prob_list[ROOM_T_FRACAVE] = 0;
6376 /* Forbidden glass rooms */
6377 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
6379 prob_list[ROOM_T_GLASS] = 0;
6384 * Initialize number of rooms,
6385 * And calcurate total probability.
6387 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6390 total_prob += prob_list[i];
6394 * Prepare the number of rooms, of all types, we should build
6397 for (i = dun_rooms; i > 0; i--)
6400 int rand = randint0(total_prob);
6402 /* Get room_type randomly */
6403 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6405 if (rand < prob_list[room_type]) break;
6406 else rand -= prob_list[room_type];
6410 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6412 /* Increase the number of rooms of that type we should build. */
6413 room_num[room_type]++;
6419 case ROOM_T_LESSER_VAULT:
6420 case ROOM_T_TRAP_PIT:
6427 case ROOM_T_GREATER_VAULT:
6428 case ROOM_T_RANDOM_VAULT:
6437 * Build each type of room one by one until we cannot build any more.
6438 * [from SAngband (originally from OAngband)]
6442 /* Assume no remaining rooms */
6445 for (i = 0; i < ROOM_T_MAX; i++)
6447 /* What type of room are we building now? */
6448 int room_type = room_build_order[i];
6450 /* Go next if none available */
6451 if (!room_num[room_type]) continue;
6453 /* Use up one unit */
6454 room_num[room_type]--;
6456 /* Build the room. */
6457 if (room_build(room_type))
6459 /* Increase the room built count. */
6462 /* Mark as there was some remaining rooms */
6469 case ROOM_T_TRAP_PIT:
6471 /* Avoid too many monsters */
6474 room_num[ROOM_T_PIT] = 0;
6475 room_num[ROOM_T_NEST] = 0;
6476 room_num[ROOM_T_TRAP_PIT] = 0;
6482 /* End loop if no room remain */
6486 if (rooms_built < 1) return FALSE;
6491 msg_format("Éô²°¿ô: %d", rooms_built);
6493 msg_format("Number of Rooms: %d", rooms_built);