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 valid 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 valid 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 &= ~(CAVE_MASK);
3450 cave[y][x].info |= info3;
3453 /* if greater than cutoff then is a wall */
3456 place_outer_bold(y, x);
3466 * Quick and nasty fill routine used to find the connected region
3467 * of floor in the middle of the cave
3469 static void cave_fill(byte y, byte x)
3478 /*** Start Grid ***/
3480 /* Enqueue that entry */
3485 /* Now process the queue */
3486 while (flow_head != flow_tail)
3488 /* Extract the next entry */
3489 ty = temp_y[flow_head];
3490 tx = temp_x[flow_head];
3492 /* Forget that entry */
3493 if (++flow_head == TEMP_MAX) flow_head = 0;
3495 /* Add the "children" */
3496 for (d = 0; d < 8; d++)
3498 int old_head = flow_tail;
3500 /* Child location */
3501 j = ty + ddy_ddd[d];
3502 i = tx + ddx_ddd[d];
3504 /* Paranoia Don't leave the cave */
3505 if (!in_bounds(j, i))
3507 /* affect boundary */
3508 cave[j][i].info |= CAVE_ICKY;
3512 /* If within bounds */
3513 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3514 && (j > fill_data.ymin) && (j < fill_data.ymax))
3516 /* If not a wall or floor done before */
3517 if (hack_isnt_wall(j, i,
3518 fill_data.c1, fill_data.c2, fill_data.c3,
3519 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3520 fill_data.info1, fill_data.info2, fill_data.info3))
3522 /* Enqueue that entry */
3523 temp_y[flow_tail] = j;
3524 temp_x[flow_tail] = i;
3526 /* Advance the queue */
3527 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3529 /* Hack -- Overflow by forgetting new entry */
3530 if (flow_tail == flow_head)
3532 flow_tail = old_head;
3536 /* keep tally of size of cave system */
3537 (fill_data.amount)++;
3543 /* affect boundary */
3544 cave[j][i].info |= CAVE_ICKY;
3551 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3553 int x, y, i, xhsize, yhsize;
3555 /* offsets to middle from corner */
3561 * select region connected to center of cave system
3562 * this gets rid of alot of isolated one-sqaures that
3563 * can make teleport traps instadeaths...
3567 fill_data.c1 = cutoff;
3571 /* features to fill with */
3572 fill_data.feat1 = floor_type[randint0(100)];
3573 fill_data.feat2 = floor_type[randint0(100)];
3574 fill_data.feat3 = floor_type[randint0(100)];
3576 fill_data.info1 = CAVE_FLOOR;
3577 fill_data.info2 = CAVE_FLOOR;
3578 fill_data.info3 = CAVE_FLOOR;
3580 /* number of filled squares */
3581 fill_data.amount = 0;
3583 cave_fill((byte)y0, (byte)x0);
3585 /* if tally too small, try again */
3586 if (fill_data.amount < 10)
3588 /* too small - clear area and try again later */
3589 for (x = 0; x <= xsize; ++x)
3591 for (y = 0; y <= ysize; ++y)
3593 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3594 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3601 * Do boundarys-check to see if they are next to a filled region
3602 * If not then they are set to normal granite
3603 * If so then they are marked as room walls.
3605 for (i = 0; i <= xsize; ++i)
3608 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3610 /* Next to a 'filled' region? - set to be room walls */
3611 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3612 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3613 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3614 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3618 /* set to be normal granite */
3619 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3622 /* bottom boundary */
3623 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3625 /* Next to a 'filled' region? - set to be room walls */
3626 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3627 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3628 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3629 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3633 /* set to be normal granite */
3634 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3637 /* clear the icky flag-don't need it any more */
3638 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3639 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3642 /* Do the left and right boundaries minus the corners (done above) */
3643 for (i = 1; i < ysize; ++i)
3646 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3649 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3650 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3651 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3652 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3657 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3659 /* right boundary */
3660 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3663 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3664 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3665 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3666 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3671 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3674 /* clear icky flag -done with it */
3675 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3676 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3680 /* Do the rest: convert back to the normal format */
3681 for (x = 1; x < xsize; ++x)
3683 for (y = 1; y < ysize; ++y)
3685 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3686 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3688 /* Clear the icky flag in the filled region */
3689 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3691 /* Set appropriate flags */
3692 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3693 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3695 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3696 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3699 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3700 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3703 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3708 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3709 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3714 /* Clear the unconnected regions */
3715 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3716 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3722 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3723 * Extra doors appear inside the system. (Its not very noticeable though.)
3724 * This can be removed by "filling" from the outside in. This allows a separation
3725 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
3726 * The extra effort for what seems to be only a minor thing (even non-existant if you
3727 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3736 * Driver routine to create fractal cave system
3738 static bool build_type9(void)
3740 int grd, roug, cutoff, xsize, ysize, y0, x0;
3742 bool done, light, room;
3744 /* get size: note 'Evenness'*/
3745 xsize = randint1(22) * 2 + 6;
3746 ysize = randint1(15) * 2 + 6;
3748 /* Find and reserve some space in the dungeon. Get center of room. */
3749 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3751 /* Limit to the minimum room size, and retry */
3755 /* Find and reserve some space in the dungeon. Get center of room. */
3756 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3762 return build_type1();
3766 light = done = FALSE;
3769 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3773 /* Note: size must be even or there are rounding problems
3774 * This causes the tunnels not to connect properly to the room */
3776 /* testing values for these parameters feel free to adjust */
3777 grd = 1 << (randint0(4));
3779 /* want average of about 16 */
3780 roug = randint1(8) * randint1(4);
3783 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3784 randint1(xsize / 4) + randint1(ysize / 4);
3787 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3789 /* Convert to normal format + clean up */
3790 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3796 #ifdef ALLOW_CAVERNS_AND_LAKES
3798 * Builds a cave system in the center of the dungeon.
3800 void build_cavern(void)
3802 int grd, roug, cutoff, xsize, ysize, x0, y0;
3805 light = done = FALSE;
3806 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3808 /* Make a cave the size of the dungeon */
3809 xsize = cur_wid - 1;
3810 ysize = cur_hgt - 1;
3814 /* Paranoia: make size even */
3820 /* testing values for these parameters: feel free to adjust */
3821 grd = randint1(4) + 4;
3823 /* want average of about 16 */
3824 roug = randint1(8) * randint1(4);
3830 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3832 /* Convert to normal format+ clean up */
3833 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3837 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3839 int x, y, i, xhsize, yhsize;
3840 int feat1, feat2, feat3;
3842 /* offsets to middle from corner */
3846 /* Get features based on type */
3849 case LAKE_T_LAVA: /* Lava */
3850 feat1 = feat_deep_lava;
3851 feat2 = feat_shallow_lava;
3852 feat3 = floor_type[randint0(100)];
3854 case LAKE_T_WATER: /* Water */
3855 feat1 = feat_deep_water;
3856 feat2 = feat_shallow_water;
3857 feat3 = floor_type[randint0(100)];
3859 case LAKE_T_CAVE: /* Collapsed cave */
3860 feat1 = floor_type[randint0(100)];
3861 feat2 = floor_type[randint0(100)];
3862 feat3 = feat_rubble;
3864 case LAKE_T_EARTH_VAULT: /* Earth vault */
3865 feat1 = feat_rubble;
3866 feat2 = floor_type[randint0(100)];
3867 feat3 = feat_rubble;
3869 case LAKE_T_AIR_VAULT: /* Air vault */
3874 case LAKE_T_WATER_VAULT: /* Water vault */
3875 feat1 = feat_shallow_water;
3876 feat2 = feat_deep_water;
3877 feat3 = feat_shallow_water;
3879 case LAKE_T_FIRE_VAULT: /* Fire Vault */
3880 feat1 = feat_shallow_lava;
3881 feat2 = feat_deep_lava;
3882 feat3 = feat_shallow_lava;
3886 default: return FALSE;
3890 * select region connected to center of cave system
3891 * this gets rid of alot of isolated one-sqaures that
3892 * can make teleport traps instadeaths...
3900 /* features to fill with */
3901 fill_data.feat1 = feat1;
3902 fill_data.feat2 = feat2;
3903 fill_data.feat3 = feat3;
3905 fill_data.info1 = 0;
3906 fill_data.info2 = 0;
3907 fill_data.info3 = 0;
3909 /* number of filled squares */
3910 fill_data.amount = 0;
3912 /* select region connected to center of cave system
3913 * this gets rid of alot of isolated one-sqaures that
3914 * can make teleport traps instadeaths... */
3915 cave_fill((byte)y0, (byte)x0);
3917 /* if tally too small, try again */
3918 if (fill_data.amount < 10)
3920 /* too small -clear area and try again later */
3921 for (x = 0; x <= xsize; ++x)
3923 for (y = 0; y <= ysize; ++y)
3925 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3926 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3932 /* Do boundarys- set to normal granite */
3933 for (i = 0; i <= xsize; ++i)
3935 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3936 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3938 /* clear the icky flag-don't need it any more */
3939 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3940 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3943 /* Do the left and right boundaries minus the corners (done above) */
3945 for (i = 1; i < ysize; ++i)
3947 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3948 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3950 /* clear icky flag -done with it */
3951 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3952 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3956 /* Do the rest: convert back to the normal format */
3957 for (x = 1; x < xsize; ++x)
3959 for (y = 1; y < ysize; ++y)
3961 /* Fill unconnected regions with granite */
3962 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3963 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3964 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3966 /* turn off icky flag (no longer needed.) */
3967 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3970 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
3972 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3982 * makes a lake/collapsed cave system in the center of the dungeon
3984 void build_lake(int type)
3986 int grd, roug, xsize, ysize, x0, y0;
3990 /* paranoia - exit if lake type out of range. */
3991 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
3993 msg_format("Invalid lake type (%d)", type);
3997 /* Make the size of the dungeon */
3998 xsize = cur_wid - 1;
3999 ysize = cur_hgt - 1;
4003 /* Paranoia: make size even */
4009 /* testing values for these parameters: feel free to adjust */
4010 grd = randint1(3) + 4;
4012 /* want average of about 16 */
4013 roug = randint1(8) * randint1(4);
4015 /* Make up size of various componants */
4019 /* Deep water/lava */
4020 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4022 /* Shallow boundary */
4026 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
4028 /* Convert to normal format+ clean up */
4029 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
4032 #endif /* ALLOW_CAVERNS_AND_LAKES */
4036 * Routine used by the random vault creators to add a door to a location
4037 * Note that range checking has to be done in the calling routine.
4039 * The doors must be INSIDE the allocated region.
4041 static void add_door(int x, int y)
4043 /* Need to have a wall in the center square */
4044 if (!is_outer_bold(y, x)) return;
4051 * where x=don't care
4055 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
4056 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
4059 place_secret_door(y, x, DOOR_DEFAULT);
4061 /* set boundarys so don't get wide doors */
4062 place_solid_bold(y, x - 1);
4063 place_solid_bold(y, x + 1);
4072 * where x = don't care
4075 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4076 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4079 place_secret_door(y, x, DOOR_DEFAULT);
4081 /* set boundarys so don't get wide doors */
4082 place_solid_bold(y - 1, x);
4083 place_solid_bold(y + 1, x);
4089 * Routine that fills the empty areas of a room with treasure and monsters.
4091 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4093 int x, y, cx, cy, size;
4096 /* center of room:*/
4100 /* Rough measure of size of vault= sum of lengths of sides */
4101 size = abs(x2 - x1) + abs(y2 - y1);
4103 for (x = x1; x <= x2; x++)
4105 for (y = y1; y <= y2; y++)
4107 /* Thing added based on distance to center of vault
4108 * Difficulty is 1-easy to 10-hard */
4109 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4111 /* hack- empty square part of the time */
4112 if ((randint1(100) - difficulty * 3) > 50) value = 20;
4114 /* if floor, shallow water and lava */
4115 if (is_floor_bold(y, x) ||
4116 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4118 /* The smaller 'value' is, the better the stuff */
4121 /* Meanest monster + treasure */
4122 monster_level = base_level + 40;
4123 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4124 monster_level = base_level;
4125 object_level = base_level + 20;
4126 place_object(y, x, AM_GOOD);
4127 object_level = base_level;
4131 /* Mean monster +treasure */
4132 monster_level = base_level + 20;
4133 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4134 monster_level = base_level;
4135 object_level = base_level + 10;
4136 place_object(y, x, AM_GOOD);
4137 object_level = base_level;
4139 else if (value < 10)
4142 monster_level = base_level + 9;
4143 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4144 monster_level = base_level;
4146 else if (value < 17)
4148 /* Intentional Blank space */
4151 * (Want some of the vault to be empty
4152 * so have room for group monsters.
4153 * This is used in the hack above to lower
4154 * the density of stuff in the vault.)
4157 else if (value < 23)
4159 /* Object or trap */
4160 if (randint0(100) < 25)
4162 place_object(y, x, 0L);
4169 else if (value < 30)
4171 /* Monster and trap */
4172 monster_level = base_level + 5;
4173 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4174 monster_level = base_level;
4177 else if (value < 40)
4179 /* Monster or object */
4180 if (randint0(100) < 50)
4182 monster_level = base_level + 3;
4183 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4184 monster_level = base_level;
4186 if (randint0(100) < 50)
4188 object_level = base_level + 7;
4189 place_object(y, x, 0L);
4190 object_level = base_level;
4193 else if (value < 50)
4202 /* 20% monster, 40% trap, 20% object, 20% blank space */
4203 if (randint0(100) < 20)
4205 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4207 else if (randint0(100) < 50)
4211 else if (randint0(100) < 50)
4213 place_object(y, x, 0L);
4224 * This function creates a random vault that looks like a collection of bubbles.
4225 * It works by getting a set of coordinates that represent the center of each
4226 * bubble. The entire room is made by seeing which bubble center is closest. If
4227 * two centers are equidistant then the square is a wall, otherwise it is a floor.
4228 * The only exception is for squares really near a center, these are always floor.
4229 * (It looks better than without this check.)
4231 * Note: If two centers are on the same point then this algorithm will create a
4232 * blank bubble filled with walls. - This is prevented from happening.
4234 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4236 #define BUBBLENUM 10 /* number of bubbles */
4238 /* array of center points of bubbles */
4239 coord center[BUBBLENUM];
4242 u16b min1, min2, temp;
4245 /* Offset from center to top left hand corner */
4246 int xhsize = xsize / 2;
4247 int yhsize = ysize / 2;
4250 if (cheat_room) msg_print("Bubble Vault");
4252 /* Allocate center of bubbles */
4253 center[0].x = randint1(xsize - 3) + 1;
4254 center[0].y = randint1(ysize - 3) + 1;
4256 for (i = 1; i < BUBBLENUM; i++)
4260 /* get center and check to see if it is unique */
4265 x = randint1(xsize - 3) + 1;
4266 y = randint1(ysize - 3) + 1;
4268 for (j = 0; j < i; j++)
4270 /* rough test to see if there is an overlap */
4271 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4280 /* Top and bottom boundaries */
4281 for (i = 0; i < xsize; i++)
4283 int x = x0 - xhsize + i;
4285 place_outer_noperm_bold(y0 - yhsize + 0, x);
4286 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4287 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4288 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4291 /* Left and right boundaries */
4292 for (i = 1; i < ysize - 1; i++)
4294 int y = y0 - yhsize + i;
4296 place_outer_noperm_bold(y, x0 - xhsize + 0);
4297 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4298 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4299 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4302 /* Fill in middle with bubbles */
4303 for (x = 1; x < xsize - 1; x++)
4305 for (y = 1; y < ysize - 1; y++)
4307 /* Get distances to two closest centers */
4310 min1 = distance(x, y, center[0].x, center[0].y);
4311 min2 = distance(x, y, center[1].x, center[1].y);
4315 /* swap if in wrong order */
4322 for (i = 2; i < BUBBLENUM; i++)
4324 temp = distance(x, y, center[i].x, center[i].y);
4332 else if (temp < min2)
4334 /* second smallest */
4338 if (((min2 - min1) <= 2) && (!(min1 < 3)))
4340 /* Boundary at midpoint+ not at inner region of bubble */
4341 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4345 /* middle of a bubble */
4346 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4349 /* clean up rest of flags */
4350 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4354 /* Try to add some random doors */
4355 for (i = 0; i < 500; i++)
4357 x = randint1(xsize - 3) - xhsize + x0 + 1;
4358 y = randint1(ysize - 3) - yhsize + y0 + 1;
4362 /* Fill with monsters and treasure, low difficulty */
4363 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4368 * Overlay a rectangular room given its bounds
4369 * This routine is used by build_room_vault
4370 * The area inside the walls is not touched:
4371 * only granite is removed- normal walls stay
4373 static void build_room(int x1, int x2, int y1, int y2)
4375 int x, y, i, xsize, ysize, temp;
4377 /* Check if rectangle has no width */
4378 if ((x1 == x2) || (y1 == y2)) return;
4383 /* Swap boundaries if in wrong order */
4391 /* Swap boundaries if in wrong order */
4397 /* get total widths */
4402 /* Top and bottom boundaries */
4403 for (i = 0; i <= xsize; i++)
4405 place_outer_noperm_bold(y1, x1 + i);
4406 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4407 place_outer_noperm_bold(y2, x1 + i);
4408 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4411 /* Left and right boundaries */
4412 for (i = 1; i < ysize; i++)
4414 place_outer_noperm_bold(y1 + i, x1);
4415 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4416 place_outer_noperm_bold(y1 + i, x2);
4417 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4421 for (x = 1; x < xsize; x++)
4423 for (y = 1; y < ysize; y++)
4425 if (is_extra_bold(y1+y, x1+x))
4427 /* clear the untouched region */
4428 place_floor_bold(y1 + y, x1 + x);
4429 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4433 /* make it a room- but don't touch */
4434 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4441 /* Create a random vault that looks like a collection of overlapping rooms */
4443 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4445 int i, x1, x2, y1, y2, xhsize, yhsize;
4447 /* get offset from center */
4451 if (cheat_room) msg_print("Room Vault");
4453 /* fill area so don't get problems with arena levels */
4454 for (x1 = 0; x1 < xsize; x1++)
4456 int x = x0 - xhsize + x1;
4458 for (y1 = 0; y1 < ysize; y1++)
4460 int y = y0 - yhsize + y1;
4462 place_extra_bold(y, x);
4463 cave[y][x].info &= (~CAVE_ICKY);
4467 /* add ten random rooms */
4468 for (i = 0; i < 10; i++)
4470 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4471 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4472 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4473 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4474 build_room(x1, x2, y1, y2);
4477 /* Add some random doors */
4478 for (i = 0; i < 500; i++)
4480 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4481 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4485 /* Fill with monsters and treasure, high difficulty */
4486 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4490 /* Create a random vault out of a fractal cave */
4491 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4493 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4494 bool done, light, room;
4496 /* round to make sizes even */
4502 if (cheat_room) msg_print("Cave Vault");
4504 light = done = FALSE;
4509 /* testing values for these parameters feel free to adjust */
4510 grd = 1 << randint0(4);
4512 /* want average of about 16 */
4513 roug = randint1(8) * randint1(4);
4516 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4517 randint1(xsize / 4) + randint1(ysize / 4);
4520 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4522 /* Convert to normal format+ clean up */
4523 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4526 /* Set icky flag because is a vault */
4527 for (x = 0; x <= xsize; x++)
4529 for (y = 0; y <= ysize; y++)
4531 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4535 /* Fill with monsters and treasure, low difficulty */
4536 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4540 * maze vault -- rectangular labyrinthine rooms
4542 * maze vault uses two routines:
4543 * r_visit - a recursive routine that builds the labyrinth
4544 * build_maze_vault - a driver routine that calls r_visit and adds
4545 * monsters, traps and treasure
4547 * The labyrinth is built by creating a spanning tree of a graph.
4548 * The graph vertices are at
4549 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4550 * and the edges are the vertical and horizontal nearest neighbors.
4552 * The spanning tree is created by performing a suitably randomized
4553 * depth-first traversal of the graph. The only adjustable parameter
4554 * is the randint0(3) below; it governs the relative density of
4555 * twists and turns in the labyrinth: smaller number, more twists.
4557 static void r_visit(int y1, int x1, int y2, int x2,
4558 int node, int dir, int *visited)
4560 int i, j, m, n, temp, x, y, adj[4];
4562 /* dimensions of vertex array */
4563 m = (x2 - x1) / 2 + 1;
4564 n = (y2 - y1) / 2 + 1;
4566 /* mark node visited and set it to a floor */
4568 x = 2 * (node % m) + x1;
4569 y = 2 * (node / m) + y1;
4570 place_floor_bold(y, x);
4572 /* setup order of adjacent node visits */
4575 /* pick a random ordering */
4576 for (i = 0; i < 4; i++)
4578 for (i = 0; i < 4; i++)
4589 /* pick a random ordering with dir first */
4591 for (i = 1; i < 4; i++)
4593 for (i = 1; i < 4; i++)
4595 j = 1 + randint0(3);
4602 for (i = 0; i < 4; i++)
4607 /* (0,+) - check for bottom boundary */
4608 if ((node / m < n - 1) && (visited[node + m] == 0))
4610 place_floor_bold(y + 1, x);
4611 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4615 /* (0,-) - check for top boundary */
4616 if ((node / m > 0) && (visited[node - m] == 0))
4618 place_floor_bold(y - 1, x);
4619 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4623 /* (+,0) - check for right boundary */
4624 if ((node % m < m - 1) && (visited[node + 1] == 0))
4626 place_floor_bold(y, x + 1);
4627 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4631 /* (-,0) - check for left boundary */
4632 if ((node % m > 0) && (visited[node - 1] == 0))
4634 place_floor_bold(y, x - 1);
4635 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4642 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4646 int m, n, num_vertices, *visited;
4651 if (cheat_room && is_vault) msg_print("Maze Vault");
4653 /* Choose lite or dark */
4654 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4656 /* Pick a random room size - randomized by calling routine */
4665 /* generate the room */
4666 for (y = y1 - 1; y <= y2 + 1; y++)
4668 for (x = x1 - 1; x <= x2 + 1; x++)
4670 c_ptr = &cave[y][x];
4671 c_ptr->info |= CAVE_ROOM;
4672 if (is_vault) c_ptr->info |= CAVE_ICKY;
4673 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4675 place_outer_grid(c_ptr);
4679 place_extra_grid(c_ptr);
4683 place_inner_grid(c_ptr);
4685 if (light) c_ptr->info |= (CAVE_GLOW);
4689 /* dimensions of vertex array */
4692 num_vertices = m * n;
4694 /* initialize array of visited vertices */
4695 C_MAKE(visited, num_vertices, int);
4697 /* traverse the graph to create a spaning tree, pick a random root */
4698 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4700 /* Fill with monsters and treasure, low difficulty */
4701 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4703 C_KILL(visited, num_vertices, int);
4707 /* Build a "mini" checkerboard vault
4709 * This is done by making a permanent wall maze and setting
4710 * the diagonal sqaures of the checker board to be granite.
4711 * The vault has two entrances on opposite sides to guarantee
4712 * a way to get in even if the vault abuts a side of the dungeon.
4714 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4717 int y1, x1, y2, x2, y, x, total;
4718 int m, n, num_vertices;
4721 if (cheat_room) msg_print("Mini Checker Board Vault");
4723 /* Pick a random room size */
4733 /* generate the room */
4734 for (x = x1 - 2; x <= x2 + 2; x++)
4736 if (!in_bounds(y1-2,x)) break;
4738 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4740 place_outer_noperm_bold(y1-2, x);
4743 for (x = x1 - 2; x <= x2 + 2; x++)
4745 if (!in_bounds(y2+2,x)) break;
4747 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4749 place_outer_noperm_bold(y2+2, x);
4752 for (y = y1 - 2; y <= y2 + 2; y++)
4754 if (!in_bounds(y,x1-2)) break;
4756 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4758 place_outer_noperm_bold(y, x1-2);
4761 for (y = y1 - 2; y <= y2 + 2; y++)
4763 if (!in_bounds(y,x2+2)) break;
4765 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4767 place_outer_noperm_bold(y, x2+2);
4770 for (y = y1 - 1; y <= y2 + 1; y++)
4772 for (x = x1 - 1; x <= x2 + 1; x++)
4774 cave_type *c_ptr = &cave[y][x];
4776 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4778 /* Permanent walls */
4779 place_inner_perm_grid(c_ptr);
4784 /* dimensions of vertex array */
4787 num_vertices = m * n;
4789 /* initialize array of visited vertices */
4790 C_MAKE(visited, num_vertices, int);
4792 /* traverse the graph to create a spannng tree, pick a random root */
4793 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4795 /* Make it look like a checker board vault */
4796 for (x = x1; x <= x2; x++)
4798 for (y = y1; y <= y2; y++)
4800 total = x - x1 + y - y1;
4801 /* If total is odd- and is a floor then make a wall */
4802 if ((total % 2 == 1) && is_floor_bold(y, x))
4804 place_inner_bold(y, x);
4809 /* Make a couple of entrances */
4812 /* left and right */
4813 y = randint1(dy) + dy / 2;
4814 place_inner_bold(y1 + y, x1 - 1);
4815 place_inner_bold(y1 + y, x2 + 1);
4819 /* top and bottom */
4820 x = randint1(dx) + dx / 2;
4821 place_inner_bold(y1 - 1, x1 + x);
4822 place_inner_bold(y2 + 1, x1 + x);
4825 /* Fill with monsters and treasure, highest difficulty */
4826 fill_treasure(x1, x2, y1, y2, 10);
4828 C_KILL(visited, num_vertices, int);
4832 /* Build a town/ castle by using a recursive algorithm.
4833 * Basically divide each region in a probalistic way to create
4834 * smaller regions. When the regions get too small stop.
4836 * The power variable is a measure of how well defended a region is.
4837 * This alters the possible choices.
4839 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4845 /* Temp variables */
4851 if ((power < 3) && (xsize > 12) && (ysize > 12))
4853 /* Need outside wall +keep */
4860 /* Make rooms + subdivide */
4861 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4867 choice = randint1(2) + 1;
4872 /* Mostly subdivide */
4873 choice = randint1(3) + 1;
4877 /* Based on the choice made above, do something */
4885 /* top and bottom */
4886 for (x = x1; x <= x2; x++)
4888 place_outer_bold(y1, x);
4889 place_outer_bold(y2, x);
4892 /* left and right */
4893 for (y = y1 + 1; y < y2; y++)
4895 place_outer_bold(y, x1);
4896 place_outer_bold(y, x2);
4899 /* Make a couple of entrances */
4902 /* left and right */
4903 y = randint1(ysize) + y1;
4904 place_floor_bold(y, x1);
4905 place_floor_bold(y, x2);
4909 /* top and bottom */
4910 x = randint1(xsize) + x1;
4911 place_floor_bold(y1, x);
4912 place_floor_bold(y2, x);
4915 /* Select size of keep */
4916 t1 = randint1(ysize / 3) + y1;
4917 t2 = y2 - randint1(ysize / 3);
4918 t3 = randint1(xsize / 3) + x1;
4919 t4 = x2 - randint1(xsize / 3);
4921 /* Do outside areas */
4923 /* Above and below keep */
4924 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4925 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4927 /* Left and right of keep */
4928 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4929 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4931 /* Make the keep itself: */
4944 /* Try to build a room */
4945 if ((xsize < 3) || (ysize < 3))
4947 for (y = y1; y < y2; y++)
4949 for (x = x1; x < x2; x++)
4951 place_inner_bold(y, x);
4959 /* Make outside walls */
4960 /* top and bottom */
4961 for (x = x1 + 1; x <= x2 - 1; x++)
4963 place_inner_bold(y1 + 1, x);
4964 place_inner_bold(y2 - 1, x);
4967 /* left and right */
4968 for (y = y1 + 1; y <= y2 - 1; y++)
4970 place_inner_bold(y, x1 + 1);
4971 place_inner_bold(y, x2 - 1);
4975 y = randint1(ysize - 3) + y1 + 1;
4980 place_floor_bold(y, x1 + 1);
4985 place_floor_bold(y, x2 - 1);
4988 /* Build the room */
4989 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4994 /* Try and divide vertically */
4998 for (y = y1; y < y2; y++)
5000 for (x = x1; x < x2; x++)
5002 place_inner_bold(y, x);
5008 t1 = randint1(xsize - 2) + x1 + 1;
5009 build_recursive_room(x1, y1, t1, y2, power - 2);
5010 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
5015 /* Try and divide horizontally */
5019 for (y = y1; y < y2; y++)
5021 for (x = x1; x < x2; x++)
5023 place_inner_bold(y, x);
5029 t1 = randint1(ysize - 2) + y1 + 1;
5030 build_recursive_room(x1, y1, x2, t1, power - 2);
5031 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
5038 /* Build a castle */
5040 /* Driver routine: clear the region and call the recursive
5043 *This makes a vault that looks like a castle/ city in the dungeon.
5045 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
5051 /* Pick a random room size */
5060 if (cheat_room) msg_print("Castle Vault");
5062 /* generate the room */
5063 for (y = y1 - 1; y <= y2 + 1; y++)
5065 for (x = x1 - 1; x <= x2 + 1; x++)
5067 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5068 /* Make everything a floor */
5069 place_floor_bold(y, x);
5073 /* Make the castle */
5074 build_recursive_room(x1, y1, x2, y2, randint1(5));
5076 /* Fill with monsters and treasure, low difficulty */
5077 fill_treasure(x1, x2, y1, y2, randint1(3));
5082 * Add outer wall to a floored region
5083 * Note: no range checking is done so must be inside dungeon
5084 * This routine also stomps on doors
5086 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5089 feature_type *f_ptr;
5092 if (!in_bounds(y, x)) return;
5094 c_ptr = &cave[y][x];
5096 /* hack- check to see if square has been visited before
5097 * if so, then exit (use room flag to do this) */
5098 if (c_ptr->info & CAVE_ROOM) return;
5101 c_ptr->info |= CAVE_ROOM;
5103 f_ptr = &f_info[c_ptr->feat];
5105 if (is_floor_bold(y, x))
5107 for (i = -1; i <= 1; i++)
5109 for (j = -1; j <= 1; j++)
5111 if ((x + i >= x1) && (x + i <= x2) &&
5112 (y + j >= y1) && (y + j <= y2))
5114 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5115 if (light) c_ptr->info |= CAVE_GLOW;
5120 else if (is_extra_bold(y, x))
5122 /* Set bounding walls */
5123 place_outer_bold(y, x);
5124 if (light) c_ptr->info |= CAVE_GLOW;
5126 else if (permanent_wall(f_ptr))
5128 /* Set bounding walls */
5129 if (light) c_ptr->info |= CAVE_GLOW;
5135 * Hacked distance formula - gives the 'wrong' answer.
5136 * Used to build crypts
5138 static int dist2(int x1, int y1, int x2, int y2,
5139 int h1, int h2, int h3, int h4)
5145 /* Basically this works by taking the normal pythagorean formula
5146 * and using an expansion to express this in a way without the
5147 * square root. This approximate formula is then perturbed to give
5148 * the distorted results. (I found this by making a mistake when I was
5149 * trying to fix the circular rooms.)
5152 /* h1-h4 are constants that describe the metric */
5153 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5154 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5155 return (((dx + dy) * 128) / 181 +
5156 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5157 /* 128/181 is approx. 1/sqrt(2) */
5162 * Build target vault.
5163 * This is made by two concentric "crypts" with perpendicular
5164 * walls creating the cross-hairs.
5166 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5170 /* Make a random metric */
5172 h1 = randint1(32) - 16;
5175 h4 = randint1(32) - 16;
5177 if (cheat_room) msg_print("Target Vault");
5179 /* work out outer radius */
5190 for (x = x0 - rad; x <= x0 + rad; x++)
5192 for (y = y0 - rad; y <= y0 + rad; y++)
5194 /* clear room flag */
5195 cave[y][x].info &= ~(CAVE_ROOM);
5197 /* Vault - so is "icky" */
5198 cave[y][x].info |= CAVE_ICKY;
5200 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5202 /* inside- so is floor */
5203 place_floor_bold(y, x);
5207 /* make granite outside so arena works */
5208 place_extra_bold(y, x);
5211 /* proper boundary for arena */
5212 if (((y + rad) == y0) || ((y - rad) == y0) ||
5213 ((x + rad) == x0) || ((x - rad) == x0))
5215 place_extra_bold(y, x);
5220 /* Find visible outer walls and set to be FEAT_OUTER */
5221 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5222 x0 + rad + 1, y0 + rad + 1);
5224 /* Add inner wall */
5225 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5227 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5229 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5231 /* Make an internal wall */
5232 place_inner_bold(y, x);
5237 /* Add perpendicular walls */
5238 for (x = x0 - rad; x <= x0 + rad; x++)
5240 place_inner_bold(y0, x);
5243 for (y = y0 - rad; y <= y0 + rad; y++)
5245 place_inner_bold(y, x0);
5248 /* Make inner vault */
5249 for (y = y0 - 1; y <= y0 + 1; y++)
5251 place_inner_bold(y, x0 - 1);
5252 place_inner_bold(y, x0 + 1);
5254 for (x = x0 - 1; x <= x0 + 1; x++)
5256 place_inner_bold(y0 - 1, x);
5257 place_inner_bold(y0 + 1, x);
5260 place_floor_bold(y0, x0);
5263 /* Add doors to vault */
5264 /* get two distances so can place doors relative to centre */
5265 x = (rad - 2) / 4 + 1;
5268 add_door(x0 + x, y0);
5269 add_door(x0 + y, y0);
5270 add_door(x0 - x, y0);
5271 add_door(x0 - y, y0);
5272 add_door(x0, y0 + x);
5273 add_door(x0, y0 + y);
5274 add_door(x0, y0 - x);
5275 add_door(x0, y0 - y);
5277 /* Fill with stuff - medium difficulty */
5278 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5282 #ifdef ALLOW_CAVERNS_AND_LAKES
5284 * This routine uses a modified version of the lake code to make a
5285 * distribution of some terrain type over the vault. This type
5286 * depends on the dungeon depth.
5288 * Miniture rooms are then scattered across the vault.
5290 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5295 int xsize, ysize, xhsize, yhsize, x, y, i;
5299 if (cheat_room) msg_print("Elemental Vault");
5301 /* round to make sizes even */
5309 /* Earth vault (Rubble) */
5310 type = LAKE_T_EARTH_VAULT;
5312 else if (dun_level < 50)
5314 /* Air vault (Trees) */
5315 type = LAKE_T_AIR_VAULT;
5317 else if (dun_level < 75)
5319 /* Water vault (shallow water) */
5320 type = LAKE_T_WATER_VAULT;
5324 /* Fire vault (shallow lava) */
5325 type = LAKE_T_FIRE_VAULT;
5330 /* testing values for these parameters: feel free to adjust */
5331 grd = 1 << (randint0(3));
5333 /* want average of about 16 */
5334 roug = randint1(8) * randint1(4);
5336 /* Make up size of various componants */
5340 /* Deep water/lava */
5341 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5343 /* Shallow boundary */
5347 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5349 /* Convert to normal format+ clean up */
5350 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5353 /* Set icky flag because is a vault */
5354 for (x = 0; x <= xsize; x++)
5356 for (y = 0; y <= ysize; y++)
5358 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5362 /* make a few rooms in the vault */
5363 for (i = 1; i <= (xsize * ysize) / 50; i++)
5365 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5366 y0 + randint0(ysize - 4) - ysize / 2 + 2);
5369 /* Fill with monsters and treasure, low difficulty */
5370 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5371 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5373 #endif /* ALLOW_CAVERNS_AND_LAKES */
5379 static bool build_type10(void)
5381 int y0, x0, xsize, ysize, vtype;
5384 /* big enough to look good, small enough to be fairly common. */
5385 xsize = randint1(22) + 22;
5386 ysize = randint1(11) + 11;
5388 /* Find and reserve some space in the dungeon. Get center of room. */
5389 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5391 /* Select type of vault */
5392 #ifdef ALLOW_CAVERNS_AND_LAKES
5395 vtype = randint1(15);
5397 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5398 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
5399 #else /* ALLOW_CAVERNS_AND_LAKES */
5402 vtype = randint1(7);
5404 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5405 ((vtype == 1) || (vtype == 3)));
5406 #endif /* ALLOW_CAVERNS_AND_LAKES */
5410 /* Build an appropriate room */
5411 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
5412 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5413 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5414 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5415 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5416 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5417 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5418 #ifdef ALLOW_CAVERNS_AND_LAKES
5419 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5420 #endif /* ALLOW_CAVERNS_AND_LAKES */
5421 /* I know how to add a few more... give me some time. */
5424 default: return FALSE;
5432 * Build an vertical oval room.
5433 * For every grid in the possible square, check the distance.
5434 * If it's less than the radius, make it a room square.
5436 * When done fill from the inside to find the walls,
5438 static bool build_type11(void)
5440 int rad, x, y, x0, y0;
5443 /* Occasional light */
5444 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5448 /* Find and reserve some space in the dungeon. Get center of room. */
5449 if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5451 /* Make circular floor */
5452 for (x = x0 - rad; x <= x0 + rad; x++)
5454 for (y = y0 - rad; y <= y0 + rad; y++)
5456 if (distance(y0, x0, y, x) <= rad - 1)
5458 /* inside- so is floor */
5459 place_floor_bold(y, x);
5461 else if (distance(y0, x0, y, x) <= rad + 1)
5463 /* make granite outside so arena works */
5464 place_extra_bold(y, x);
5469 /* Find visible outer walls and set to be FEAT_OUTER */
5470 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5478 * For every grid in the possible square, check the (fake) distance.
5479 * If it's less than the radius, make it a room square.
5481 * When done fill from the inside to find the walls,
5483 static bool build_type12(void)
5485 int rad, x, y, x0, y0;
5487 bool emptyflag = TRUE;
5489 /* Make a random metric */
5491 h1 = randint1(32) - 16;
5494 h4 = randint1(32) - 16;
5496 /* Occasional light */
5497 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5501 /* Find and reserve some space in the dungeon. Get center of room. */
5502 if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5505 for (x = x0 - rad; x <= x0 + rad; x++)
5507 for (y = y0 - rad; y <= y0 + rad; y++)
5509 /* clear room flag */
5510 cave[y][x].info &= ~(CAVE_ROOM);
5512 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5514 /* inside - so is floor */
5515 place_floor_bold(y, x);
5517 else if (distance(y0, x0, y, x) < 3)
5519 place_floor_bold(y, x);
5523 /* make granite outside so arena works */
5524 place_extra_bold(y, x);
5527 /* proper boundary for arena */
5528 if (((y + rad) == y0) || ((y - rad) == y0) ||
5529 ((x + rad) == x0) || ((x - rad) == x0))
5531 place_extra_bold(y, x);
5536 /* Find visible outer walls and set to be FEAT_OUTER */
5537 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5538 x0 + rad + 1, y0 + rad + 1);
5540 /* Check to see if there is room for an inner vault */
5541 for (x = x0 - 2; x <= x0 + 2; x++)
5543 for (y = y0 - 2; y <= y0 + 2; y++)
5545 if (!is_floor_bold(y, x))
5547 /* Wall in the way */
5553 if (emptyflag && one_in_(2))
5555 /* Build the vault */
5556 build_small_room(x0, y0);
5558 /* Place a treasure in the vault */
5559 place_object(y0, x0, 0L);
5561 /* Let's guard the treasure well */
5562 vault_monsters(y0, x0, randint0(2) + 3);
5564 /* Traps naturally */
5565 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5573 * Helper function for "trapped monster pit"
5575 static bool vault_aux_trapped_pit(int r_idx)
5577 monster_race *r_ptr = &r_info[r_idx];
5579 /* Validate the monster */
5580 if (!vault_monster_okay(r_idx)) return (FALSE);
5582 /* No wall passing monster */
5583 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5591 * Type 13 -- Trapped monster pits
5593 * A trapped monster pit is a "big" room with a straight corridor in
5594 * which wall opening traps are placed, and with two "inner" rooms
5595 * containing a "collection" of monsters of a given type organized in
5598 * The trapped monster pit appears as shown below, where the actual
5599 * monsters in each location depend on the type of the pit
5601 * #########################
5603 * ####################### #
5604 * #####001123454321100### #
5605 * ###0012234567654322100# #
5606 * ####################### #
5608 * # #######################
5609 * # #0012234567654322100###
5610 * # ###001123454321100#####
5611 * # #######################
5613 * #########################
5615 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5616 * to request 16 "appropriate" monsters, sorting them by level, and using
5617 * the "even" entries in this sorted list for the contents of the pit.
5619 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5620 * which is handled by requiring a specific "breath" attack for all of the
5621 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5622 * be present in many of the dragon pits, if they have the proper breath.
5624 * Note the use of the "get_mon_num_prep()" function, and the special
5625 * "get_mon_num_hook()" restriction function, to prepare the "monster
5626 * allocation table" in such a way as to optimize the selection of
5627 * "appropriate" non-unique monsters for the pit.
5629 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5630 * the pit will be empty.
5632 * Note that "monster pits" will never contain "unique" monsters.
5634 static bool build_type13(void)
5636 static int placing[][3] = {
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, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
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, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
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, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5649 {-2, -4, 3}, {-3, -2, 3},
5650 {+2, -4, 3}, {+3, -2, 3},
5651 {-2, +4, 3}, {-3, +2, 3},
5652 {+2, +4, 3}, {+3, +2, 3},
5653 {-2, -3, 4}, {-3, -1, 4},
5654 {+2, -3, 4}, {+3, -1, 4},
5655 {-2, +3, 4}, {-3, +1, 4},
5656 {+2, +3, 4}, {+3, +1, 4},
5657 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5658 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5659 {-2, -1, 6}, {-2, +1, 6},
5660 {+2, -1, 6}, {+2, +1, 6},
5661 {-2, 0, 7}, {+2, 0, 7},
5665 int y, x, y1, x1, y2, x2, xval, yval;
5674 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5675 vault_aux_type *n_ptr;
5677 /* Only in Angband */
5678 if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5680 /* No type available */
5681 if (cur_pit_type < 0) return FALSE;
5683 n_ptr = &pit_types[cur_pit_type];
5685 /* Process a preparation function if necessary */
5686 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5688 /* Prepare allocation table */
5689 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5691 align.sub_align = SUB_ALIGN_NEUTRAL;
5693 /* Pick some monster types */
5694 for (i = 0; i < 16; i++)
5696 int r_idx = 0, attempts = 100;
5697 monster_race *r_ptr = NULL;
5701 /* Get a (hard) monster type */
5702 r_idx = get_mon_num(dun_level + 0);
5703 r_ptr = &r_info[r_idx];
5705 /* Decline incorrect alignment */
5706 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5708 /* Accept this monster */
5712 /* Notice failure */
5713 if (!r_idx || !attempts) return FALSE;
5715 /* Note the alignment */
5716 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5717 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5722 /* Find and reserve some space in the dungeon. Get center of room. */
5723 if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5731 /* Fill with inner walls */
5732 for (y = y1 - 1; y <= y2 + 1; y++)
5734 for (x = x1 - 1; x <= x2 + 1; x++)
5736 c_ptr = &cave[y][x];
5737 place_inner_grid(c_ptr);
5738 c_ptr->info |= (CAVE_ROOM);
5742 /* Place the floor area 1 */
5743 for (x = x1 + 3; x <= x2 - 3; x++)
5745 c_ptr = &cave[yval-2][x];
5746 place_floor_grid(c_ptr);
5747 add_cave_info(yval-2, x, CAVE_ICKY);
5749 c_ptr = &cave[yval+2][x];
5750 place_floor_grid(c_ptr);
5751 add_cave_info(yval+2, x, CAVE_ICKY);
5754 /* Place the floor area 2 */
5755 for (x = x1 + 5; x <= x2 - 5; x++)
5757 c_ptr = &cave[yval-3][x];
5758 place_floor_grid(c_ptr);
5759 add_cave_info(yval-3, x, CAVE_ICKY);
5761 c_ptr = &cave[yval+3][x];
5762 place_floor_grid(c_ptr);
5763 add_cave_info(yval+3, x, CAVE_ICKY);
5767 for (x = x1; x <= x2; x++)
5769 c_ptr = &cave[yval][x];
5770 place_floor_grid(c_ptr);
5771 c_ptr = &cave[y1][x];
5772 place_floor_grid(c_ptr);
5773 c_ptr = &cave[y2][x];
5774 place_floor_grid(c_ptr);
5777 /* Place the outer walls */
5778 for (y = y1 - 1; y <= y2 + 1; y++)
5780 c_ptr = &cave[y][x1 - 1];
5781 place_outer_grid(c_ptr);
5782 c_ptr = &cave[y][x2 + 1];
5783 place_outer_grid(c_ptr);
5785 for (x = x1 - 1; x <= x2 + 1; x++)
5787 c_ptr = &cave[y1 - 1][x];
5788 place_outer_grid(c_ptr);
5789 c_ptr = &cave[y2 + 1][x];
5790 place_outer_grid(c_ptr);
5793 /* Random corridor */
5796 for (y = y1; y <= yval; y++)
5798 place_floor_bold(y, x2);
5799 place_solid_bold(y, x1-1);
5801 for (y = yval; y <= y2 + 1; y++)
5803 place_floor_bold(y, x1);
5804 place_solid_bold(y, x2+1);
5809 for (y = yval; y <= y2 + 1; y++)
5811 place_floor_bold(y, x1);
5812 place_solid_bold(y, x2+1);
5814 for (y = y1; y <= yval; y++)
5816 place_floor_bold(y, x2);
5817 place_solid_bold(y, x1-1);
5821 /* Place the wall open trap */
5822 cave[yval][xval].mimic = cave[yval][xval].feat;
5823 cave[yval][xval].feat = feat_trap_open;
5825 /* Sort the entries */
5826 for (i = 0; i < 16 - 1; i++)
5828 /* Sort the entries */
5829 for (j = 0; j < 16 - 1; j++)
5834 int p1 = r_info[what[i1]].level;
5835 int p2 = r_info[what[i2]].level;
5841 what[i1] = what[i2];
5852 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5854 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5858 /* Select the entries */
5859 for (i = 0; i < 8; i++)
5861 /* Every other entry */
5862 what[i] = what[i * 2];
5867 msg_print(r_name + r_info[what[i]].name);
5871 for (i = 0; placing[i][2] >= 0; i++)
5873 y = yval + placing[i][0];
5874 x = xval + placing[i][1];
5875 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5883 * Type 14 -- trapped rooms
5885 * A special trap is placed at center of the room
5887 static bool build_type14(void)
5889 int y, x, y2, x2, yval, xval;
5890 int y1, x1, xsize, ysize;
5897 /* Pick a room size */
5903 xsize = x1 + x2 + 1;
5904 ysize = y1 + y2 + 1;
5906 /* Find and reserve some space in the dungeon. Get center of room. */
5907 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5909 /* Choose lite or dark */
5910 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5913 /* Get corner values */
5914 y1 = yval - ysize / 2;
5915 x1 = xval - xsize / 2;
5916 y2 = yval + (ysize - 1) / 2;
5917 x2 = xval + (xsize - 1) / 2;
5920 /* Place a full floor under the room */
5921 for (y = y1 - 1; y <= y2 + 1; y++)
5923 for (x = x1 - 1; x <= x2 + 1; x++)
5925 c_ptr = &cave[y][x];
5926 place_floor_grid(c_ptr);
5927 c_ptr->info |= (CAVE_ROOM);
5928 if (light) c_ptr->info |= (CAVE_GLOW);
5932 /* Walls around the room */
5933 for (y = y1 - 1; y <= y2 + 1; y++)
5935 c_ptr = &cave[y][x1 - 1];
5936 place_outer_grid(c_ptr);
5937 c_ptr = &cave[y][x2 + 1];
5938 place_outer_grid(c_ptr);
5940 for (x = x1 - 1; x <= x2 + 1; x++)
5942 c_ptr = &cave[y1 - 1][x];
5943 place_outer_grid(c_ptr);
5944 c_ptr = &cave[y2 + 1][x];
5945 place_outer_grid(c_ptr);
5948 if (dun_level < 30 + randint1(30))
5949 trap = feat_trap_piranha;
5951 trap = feat_trap_armageddon;
5953 /* Place a special trap */
5954 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
5955 c_ptr->mimic = c_ptr->feat;
5962 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5964 msg_format("Room of %s", f_name + f_info[trap].name);
5973 * Helper function for "glass room"
5975 static bool vault_aux_lite(int r_idx)
5977 monster_race *r_ptr = &r_info[r_idx];
5979 /* Validate the monster */
5980 if (!vault_monster_okay(r_idx)) return FALSE;
5982 /* Require lite attack */
5983 if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->flags5 & RF5_BA_LITE)) return FALSE;
5985 /* No wall passing monsters */
5986 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
5988 /* No disintegrating monsters */
5989 if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
5995 * Helper function for "glass room"
5997 static bool vault_aux_shards(int r_idx)
5999 monster_race *r_ptr = &r_info[r_idx];
6001 /* Validate the monster */
6002 if (!vault_monster_okay(r_idx)) return FALSE;
6004 /* Require shards breath attack */
6005 if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
6011 * Hack -- determine if a template is potion
6013 static bool kind_is_potion(int k_idx)
6015 return k_info[k_idx].tval == TV_POTION;
6019 * Type 15 -- glass rooms
6021 static bool build_type15(void)
6023 int y, x, y2, x2, yval, xval;
6024 int y1, x1, xsize, ysize;
6029 /* Pick a room size */
6030 xsize = rand_range(9, 13);
6031 ysize = rand_range(9, 13);
6033 /* Find and reserve some space in the dungeon. Get center of room. */
6034 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
6036 /* Choose lite or dark */
6037 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
6039 /* Get corner values */
6040 y1 = yval - ysize / 2;
6041 x1 = xval - xsize / 2;
6042 y2 = yval + (ysize - 1) / 2;
6043 x2 = xval + (xsize - 1) / 2;
6045 /* Place a full floor under the room */
6046 for (y = y1 - 1; y <= y2 + 1; y++)
6048 for (x = x1 - 1; x <= x2 + 1; x++)
6050 c_ptr = &cave[y][x];
6051 place_floor_grid(c_ptr);
6052 c_ptr->feat = feat_glass_floor;
6053 c_ptr->info |= (CAVE_ROOM);
6054 if (light) c_ptr->info |= (CAVE_GLOW);
6058 /* Walls around the room */
6059 for (y = y1 - 1; y <= y2 + 1; y++)
6061 c_ptr = &cave[y][x1 - 1];
6062 place_outer_grid(c_ptr);
6063 c_ptr->feat = feat_glass_wall;
6064 c_ptr = &cave[y][x2 + 1];
6065 place_outer_grid(c_ptr);
6066 c_ptr->feat = feat_glass_wall;
6068 for (x = x1 - 1; x <= x2 + 1; x++)
6070 c_ptr = &cave[y1 - 1][x];
6071 place_outer_grid(c_ptr);
6072 c_ptr->feat = feat_glass_wall;
6073 c_ptr = &cave[y2 + 1][x];
6074 place_outer_grid(c_ptr);
6075 c_ptr->feat = feat_glass_wall;
6078 switch (randint1(3))
6080 case 1: /* 4 lite breathers + potion */
6084 /* Prepare allocation table */
6085 get_mon_num_prep(vault_aux_lite, NULL);
6087 /* Place fixed lite berathers */
6088 for (dir1 = 4; dir1 < 8; dir1++)
6090 int r_idx = get_mon_num(dun_level);
6092 y = yval + 2 * ddy_ddd[dir1];
6093 x = xval + 2 * ddx_ddd[dir1];
6094 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
6096 /* Walls around the breather */
6097 for (dir2 = 0; dir2 < 8; dir2++)
6099 c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
6100 place_inner_grid(c_ptr);
6101 c_ptr->feat = feat_glass_wall;
6105 /* Walls around the potion */
6106 for (dir1 = 0; dir1 < 4; dir1++)
6108 y = yval + 2 * ddy_ddd[dir1];
6109 x = xval + 2 * ddx_ddd[dir1];
6110 c_ptr = &cave[y][x];
6111 place_inner_perm_grid(c_ptr);
6112 c_ptr->feat = feat_permanent_glass_wall;
6113 cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]].info |= (CAVE_ICKY);
6118 y = yval + 2 * ddy_ddd[dir1];
6119 x = xval + 2 * ddx_ddd[dir1];
6120 place_secret_door(y, x, DOOR_GLASS_DOOR);
6121 c_ptr = &cave[y][x];
6122 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
6124 /* Place a potion */
6125 get_obj_num_hook = kind_is_potion;
6126 place_object(yval, xval, AM_NO_FIXED_ART);
6127 cave[yval][xval].info |= (CAVE_ICKY);
6131 case 2: /* 1 lite breather + random object */
6136 c_ptr = &cave[y1 + 1][x1 + 1];
6137 place_inner_grid(c_ptr);
6138 c_ptr->feat = feat_glass_wall;
6140 c_ptr = &cave[y1 + 1][x2 - 1];
6141 place_inner_grid(c_ptr);
6142 c_ptr->feat = feat_glass_wall;
6144 c_ptr = &cave[y2 - 1][x1 + 1];
6145 place_inner_grid(c_ptr);
6146 c_ptr->feat = feat_glass_wall;
6148 c_ptr = &cave[y2 - 1][x2 - 1];
6149 place_inner_grid(c_ptr);
6150 c_ptr->feat = feat_glass_wall;
6152 /* Prepare allocation table */
6153 get_mon_num_prep(vault_aux_lite, NULL);
6155 r_idx = get_mon_num(dun_level);
6156 if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
6158 /* Walls around the breather */
6159 for (dir1 = 0; dir1 < 8; dir1++)
6161 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
6162 place_inner_grid(c_ptr);
6163 c_ptr->feat = feat_glass_wall;
6166 /* Curtains around the breather */
6167 for (y = yval - 1; y <= yval + 1; y++)
6169 place_closed_door(y, xval - 2, DOOR_CURTAIN);
6170 place_closed_door(y, xval + 2, DOOR_CURTAIN);
6172 for (x = xval - 1; x <= xval + 1; x++)
6174 place_closed_door(yval - 2, x, DOOR_CURTAIN);
6175 place_closed_door(yval + 2, x, DOOR_CURTAIN);
6178 /* Place an object */
6179 place_object(yval, xval, AM_NO_FIXED_ART);
6180 cave[yval][xval].info |= (CAVE_ICKY);
6184 case 3: /* 4 shards breathers + 2 potions */
6188 /* Walls around the potion */
6189 for (y = yval - 2; y <= yval + 2; y++)
6191 c_ptr = &cave[y][xval - 3];
6192 place_inner_grid(c_ptr);
6193 c_ptr->feat = feat_glass_wall;
6194 c_ptr = &cave[y][xval + 3];
6195 place_inner_grid(c_ptr);
6196 c_ptr->feat = feat_glass_wall;
6198 for (x = xval - 2; x <= xval + 2; x++)
6200 c_ptr = &cave[yval - 3][x];
6201 place_inner_grid(c_ptr);
6202 c_ptr->feat = feat_glass_wall;
6203 c_ptr = &cave[yval + 3][x];
6204 place_inner_grid(c_ptr);
6205 c_ptr->feat = feat_glass_wall;
6207 for (dir1 = 4; dir1 < 8; dir1++)
6209 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
6210 place_inner_grid(c_ptr);
6211 c_ptr->feat = feat_glass_wall;
6214 /* Prepare allocation table */
6215 get_mon_num_prep(vault_aux_shards, NULL);
6217 /* Place shard berathers */
6218 for (dir1 = 4; dir1 < 8; dir1++)
6220 int r_idx = get_mon_num(dun_level);
6222 y = yval + ddy_ddd[dir1];
6223 x = xval + ddx_ddd[dir1];
6224 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
6227 /* Place two potions */
6230 get_obj_num_hook = kind_is_potion;
6231 place_object(yval, xval - 1, AM_NO_FIXED_ART);
6232 get_obj_num_hook = kind_is_potion;
6233 place_object(yval, xval + 1, AM_NO_FIXED_ART);
6237 get_obj_num_hook = kind_is_potion;
6238 place_object(yval - 1, xval, AM_NO_FIXED_ART);
6239 get_obj_num_hook = kind_is_potion;
6240 place_object(yval + 1, xval, AM_NO_FIXED_ART);
6243 for (y = yval - 2; y <= yval + 2; y++)
6244 for (x = xval - 2; x <= xval + 2; x++)
6245 cave[y][x].info |= (CAVE_ICKY);
6255 msg_print("¥¬¥é¥¹¤ÎÉô²°");
6257 msg_print("Glass room");
6266 * Attempt to build a room of the given type at the given block
6268 * Note that we restrict the number of "crowded" rooms to reduce
6269 * the chance of overflowing the monster list during level creation.
6271 static bool room_build(int typ)
6276 /* Build an appropriate room */
6277 case ROOM_T_NORMAL: return build_type1();
6278 case ROOM_T_OVERLAP: return build_type2();
6279 case ROOM_T_CROSS: return build_type3();
6280 case ROOM_T_INNER_FEAT: return build_type4();
6281 case ROOM_T_NEST: return build_type5();
6282 case ROOM_T_PIT: return build_type6();
6283 case ROOM_T_LESSER_VAULT: return build_type7();
6284 case ROOM_T_GREATER_VAULT: return build_type8();
6285 case ROOM_T_FRACAVE: return build_type9();
6286 case ROOM_T_RANDOM_VAULT: return build_type10();
6287 case ROOM_T_OVAL: return build_type11();
6288 case ROOM_T_CRYPT: return build_type12();
6289 case ROOM_T_TRAP_PIT: return build_type13();
6290 case ROOM_T_TRAP: return build_type14();
6291 case ROOM_T_GLASS: return build_type15();
6299 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
6302 * [from SAngband (originally from OAngband)]
6304 * Generate rooms in dungeon. Build bigger rooms at first.
6306 bool generate_rooms(void)
6312 int prob_list[ROOM_T_MAX];
6313 int rooms_built = 0;
6314 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
6315 int level_index = MIN(10, div_round(dun_level, 10));
6317 /* Number of each type of room on this level */
6318 s16b room_num[ROOM_T_MAX];
6320 /* Limit number of rooms */
6321 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
6323 /* Assume normal cave */
6324 room_info_type *room_info_ptr = room_info_normal;
6327 * Initialize probability list.
6329 for (i = 0; i < ROOM_T_MAX; i++)
6331 /* No rooms allowed above their minimum depth. */
6332 if (dun_level < room_info_ptr[i].min_level)
6338 prob_list[i] = room_info_ptr[i].prob[level_index];
6343 * XXX -- Various dungeon types and options.
6346 /* Ironman sees only Greater Vaults */
6347 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
6349 for (i = 0; i < ROOM_T_MAX; i++)
6351 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6352 else prob_list[i] = 0;
6356 /* Forbidden vaults */
6357 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6359 prob_list[ROOM_T_LESSER_VAULT] = 0;
6360 prob_list[ROOM_T_GREATER_VAULT] = 0;
6361 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6365 /* NO_CAVE dungeon (Castle)*/
6366 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6368 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6369 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6370 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6373 /* CAVE dungeon (Orc cave etc.) */
6374 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6376 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6379 /* No caves when a (random) cavern exists: they look bad */
6380 else if (dun->cavern || dun->empty_level)
6382 prob_list[ROOM_T_FRACAVE] = 0;
6385 /* Forbidden glass rooms */
6386 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
6388 prob_list[ROOM_T_GLASS] = 0;
6393 * Initialize number of rooms,
6394 * And calcurate total probability.
6396 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6399 total_prob += prob_list[i];
6403 * Prepare the number of rooms, of all types, we should build
6406 for (i = dun_rooms; i > 0; i--)
6409 int rand = randint0(total_prob);
6411 /* Get room_type randomly */
6412 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6414 if (rand < prob_list[room_type]) break;
6415 else rand -= prob_list[room_type];
6419 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6421 /* Increase the number of rooms of that type we should build. */
6422 room_num[room_type]++;
6428 case ROOM_T_LESSER_VAULT:
6429 case ROOM_T_TRAP_PIT:
6436 case ROOM_T_GREATER_VAULT:
6437 case ROOM_T_RANDOM_VAULT:
6446 * Build each type of room one by one until we cannot build any more.
6447 * [from SAngband (originally from OAngband)]
6451 /* Assume no remaining rooms */
6454 for (i = 0; i < ROOM_T_MAX; i++)
6456 /* What type of room are we building now? */
6457 int room_type = room_build_order[i];
6459 /* Go next if none available */
6460 if (!room_num[room_type]) continue;
6462 /* Use up one unit */
6463 room_num[room_type]--;
6465 /* Build the room. */
6466 if (room_build(room_type))
6468 /* Increase the room built count. */
6471 /* Mark as there was some remaining rooms */
6478 case ROOM_T_TRAP_PIT:
6480 /* Avoid too many monsters */
6483 room_num[ROOM_T_PIT] = 0;
6484 room_num[ROOM_T_NEST] = 0;
6485 room_num[ROOM_T_TRAP_PIT] = 0;
6491 /* End loop if no room remain */
6495 if (rooms_built < 1) return FALSE;
6500 msg_format("Éô²°¿ô: %d", rooms_built);
6502 msg_format("Number of Rooms: %d", rooms_built);