3 * Purpose: make rooms. Used by generate.c when creating dungeons.
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
9 * This software may be copied and distributed for educational, research,
10 * and not for profit purposes provided that this copyright and statement
11 * are included in all such copies. Other copyrights may also apply.
21 * [from SAngband (originally from OAngband)]
23 * Table of values that control how many times each type of room will
24 * appear. Each type of room has its own row, and each column
25 * corresponds to dungeon levels 0, 10, 20, and so on. The final
26 * value is the minimum depth the room can appear at. -LM-
28 * Level 101 and below use the values for level 100.
30 * Rooms with lots of monsters or loot may not be generated if the
31 * object or monster lists are already nearly full. Rooms will not
32 * appear above their minimum depth. Tiny levels will not have space
33 * for all the rooms you ask for.
35 static room_info_type room_info_normal[ROOM_T_MAX] =
38 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
40 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
41 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
42 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
43 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
44 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
45 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
46 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
47 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
48 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
49 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
50 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
51 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
52 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
53 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
57 /* Build rooms in descending order of difficulty. */
58 static byte room_build_order[ROOM_T_MAX] = {
76 static void place_locked_door(int y, int x)
78 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
80 place_floor_bold(y, x);
84 set_cave_feat(y, x, feat_locked_door[randint0(num_locked_door)]);
85 cave[y][x].info &= ~(CAVE_FLOOR);
90 static void place_secret_door(int y, int x)
92 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
94 place_floor_bold(y, x);
98 cave_type *c_ptr = &cave[y][x];
100 /* Create secret door */
101 place_closed_door(y, x);
103 if (c_ptr->feat != feat_closed_curtain)
105 /* Hide by inner wall because this is used in rooms only */
106 c_ptr->mimic = feat_wall_inner;
108 /* Floor type terrain cannot hide a door */
109 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
111 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
113 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
119 c_ptr->info &= ~(CAVE_FLOOR);
120 delete_monster(y, x);
125 * This funtion makes a very small room centred at (x0, y0)
126 * This is used in crypts, and random elemental vaults.
128 * Note - this should be used only on allocated regions
129 * within another room.
131 static void build_small_room(int x0, int y0)
135 for (y = y0 - 1; y <= y0 + 1; y++)
137 place_inner_bold(y, x0 - 1);
138 place_inner_bold(y, x0 + 1);
141 for (x = x0 - 1; x <= x0 + 1; x++)
143 place_inner_bold(y0 - 1, x);
144 place_inner_bold(y0 + 1, x);
147 /* Place a secret door on one side */
150 case 0: place_secret_door(y0, x0 - 1); break;
151 case 1: place_secret_door(y0, x0 + 1); break;
152 case 2: place_secret_door(y0 - 1, x0); break;
153 case 3: place_secret_door(y0 + 1, x0); break;
156 /* Clear mimic type */
157 cave[y0][x0].mimic = 0;
159 /* Add inner open space */
160 place_floor_bold(y0, x0);
165 * This function tunnels around a room if
166 * it will cut off part of a cave system.
168 static void check_room_boundary(int x1, int y1, int x2, int y2)
171 bool old_is_floor, new_is_floor;
177 old_is_floor = get_is_floor(x1 - 1, y1);
180 * Count the number of floor-wall boundaries around the room
181 * Note: diagonal squares are ignored since the player can move diagonally
182 * to bypass these if needed.
185 /* Above the top boundary */
186 for (x = x1; x <= x2; x++)
188 new_is_floor = get_is_floor(x, y1 - 1);
190 /* Increment counter if they are different */
191 if (new_is_floor != old_is_floor) count++;
193 old_is_floor = new_is_floor;
197 for (y = y1; y <= y2; y++)
199 new_is_floor = get_is_floor(x2 + 1, y);
201 /* increment counter if they are different */
202 if (new_is_floor != old_is_floor) count++;
204 old_is_floor = new_is_floor;
207 /* Bottom boundary */
208 for (x = x2; x >= x1; x--)
210 new_is_floor = get_is_floor(x, y2 + 1);
212 /* increment counter if they are different */
213 if (new_is_floor != old_is_floor) count++;
215 old_is_floor = new_is_floor;
219 for (y = y2; y >= y1; y--)
221 new_is_floor = get_is_floor(x1 - 1, y);
223 /* increment counter if they are different */
224 if (new_is_floor != old_is_floor) count++;
226 old_is_floor = new_is_floor;
229 /* If all the same, or only one connection exit. */
230 if (count <= 2) return;
233 /* Tunnel around the room so to prevent problems with caves */
234 for (y = y1; y <= y2; y++)
236 for (x = x1; x <= x2; x++)
245 * Helper function for find_space().
247 * Is this a good location?
249 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
251 int by1, bx1, by2, bx2, by, bx;
253 /* Itty-bitty rooms must shift about within their rectangle */
256 if ((blocks_wide == 2) && (block_x % 3) == 2)
260 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
261 else if ((blocks_wide % 3) == 0)
263 /* Must be aligned to the left edge of a 11x33 rectangle. */
264 if ((block_x % 3) != 0)
269 * Big rooms that do not have a width divisible by 3 must be
270 * aligned towards the edge of the dungeon closest to them.
274 /* Shift towards left edge of dungeon. */
275 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
277 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
279 if ((block_x % 3) == 1)
283 /* Shift toward right edge of dungeon. */
286 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
288 if ((block_x % 3) == 1)
296 by2 = block_y + blocks_high;
297 bx2 = block_x + blocks_wide;
299 /* Never run off the screen */
300 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
301 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
303 /* Verify available space */
304 for (by = by1; by < by2; by++)
306 for (bx = bx1; bx < bx2; bx++)
308 if (dun->room_map[by][bx])
315 /* This location is okay */
321 * Find a good spot for the next room. -LM-
323 * Find and allocate a free space in the dungeon large enough to hold
324 * the room calling this function.
326 * We allocate space in 11x11 blocks, but want to make sure that rooms
327 * align neatly on the standard screen. Therefore, we make them use
328 * blocks in few 11x33 rectangles as possible.
330 * Be careful to include the edges of the room in height and width!
332 * Return TRUE and values for the center of the room if all went well.
333 * Otherwise, return FALSE.
335 static bool find_space(int *y, int *x, int height, int width)
337 int candidates, pick;
338 int by, bx, by1, bx1, by2, bx2;
339 int block_y = 0, block_x = 0;
342 /* Find out how many blocks we need. */
343 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
344 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
346 /* There are no way to allocate such huge space */
347 if (dun->row_rooms < blocks_high) return FALSE;
348 if (dun->col_rooms < blocks_wide) return FALSE;
353 /* Count the number of varid places */
354 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
356 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
358 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
360 /* Find a varid place */
373 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
375 /* Choose a random one */
376 pick = randint1(candidates);
379 /* NO_CAVE dungeon (Castle) */
382 /* Always choose the center one */
383 pick = candidates/2 + 1;
386 /* Pick up the choosen location */
387 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
389 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
391 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
395 /* This one is picked? */
406 by2 = block_y + blocks_high;
407 bx2 = block_x + blocks_wide;
410 * It is *extremely* important that the following calculation
411 * be *exactly* correct to prevent memory errors
414 /* Acquire the location of the room */
415 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
416 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
418 /* Save the room location */
419 if (dun->cent_n < CENT_MAX)
421 dun->cent[dun->cent_n].y = *y;
422 dun->cent[dun->cent_n].x = *x;
426 /* Reserve some blocks. */
427 for (by = by1; by < by2; by++)
429 for (bx = bx1; bx < bx2; bx++)
431 dun->room_map[by][bx] = TRUE;
437 * Hack- See if room will cut off a cavern.
439 * If so, fix by tunneling outside the room in such a
440 * way as to connect the caves.
442 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
452 * Room building routines.
458 * 4 -- large room with features
462 * 8 -- greater vaults
464 * 10 -- random vaults
465 * 11 -- circular rooms
467 * 13 -- trapped monster pits
473 * Type 1 -- normal rectangular rooms
475 static bool build_type1(void)
477 int y, x, y2, x2, yval, xval;
478 int y1, x1, xsize, ysize;
484 bool curtain = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
485 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 48 : 512);
487 /* Pick a room size */
496 /* Find and reserve some space in the dungeon. Get center of room. */
497 if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
499 /* Limit to the minimum room size, and retry */
508 /* Find and reserve some space in the dungeon. Get center of room. */
509 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
512 /* Choose lite or dark */
513 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
516 /* Get corner values */
517 y1 = yval - ysize / 2;
518 x1 = xval - xsize / 2;
519 y2 = yval + (ysize - 1) / 2;
520 x2 = xval + (xsize - 1) / 2;
523 /* Place a full floor under the room */
524 for (y = y1 - 1; y <= y2 + 1; y++)
526 for (x = x1 - 1; x <= x2 + 1; x++)
529 place_floor_grid(c_ptr);
530 c_ptr->info |= (CAVE_ROOM);
531 if (light) c_ptr->info |= (CAVE_GLOW);
535 /* Walls around the room */
536 for (y = y1 - 1; y <= y2 + 1; y++)
538 c_ptr = &cave[y][x1 - 1];
539 place_outer_grid(c_ptr);
540 c_ptr = &cave[y][x2 + 1];
541 place_outer_grid(c_ptr);
543 for (x = x1 - 1; x <= x2 + 1; x++)
545 c_ptr = &cave[y1 - 1][x];
546 place_outer_grid(c_ptr);
547 c_ptr = &cave[y2 + 1][x];
548 place_outer_grid(c_ptr);
552 /* Hack -- Occasional curtained room */
553 if (curtain && (y2 - y1 > 2) && (x2 - x1 > 2))
555 for (y = y1; y <= y2; y++)
557 c_ptr = &cave[y][x1];
558 c_ptr->feat = feat_closed_curtain;
559 c_ptr->info &= ~(CAVE_MASK);
560 c_ptr = &cave[y][x2];
561 c_ptr->feat = feat_closed_curtain;
562 c_ptr->info &= ~(CAVE_MASK);
564 for (x = x1; x <= x2; x++)
566 c_ptr = &cave[y1][x];
567 c_ptr->feat = feat_closed_curtain;
568 c_ptr->info &= ~(CAVE_MASK);
569 c_ptr = &cave[y2][x];
570 c_ptr->feat = feat_closed_curtain;
571 c_ptr->info &= ~(CAVE_MASK);
576 /* Hack -- Occasional pillar room */
579 for (y = y1; y <= y2; y += 2)
581 for (x = x1; x <= x2; x += 2)
584 place_inner_grid(c_ptr);
589 /* Hack -- Occasional room with four pillars */
590 else if (one_in_(20))
592 if ((y1 + 4 < y2) && (x1 + 4 < x2))
594 c_ptr = &cave[y1 + 1][x1 + 1];
595 place_inner_grid(c_ptr);
597 c_ptr = &cave[y1 + 1][x2 - 1];
598 place_inner_grid(c_ptr);
600 c_ptr = &cave[y2 - 1][x1 + 1];
601 place_inner_grid(c_ptr);
603 c_ptr = &cave[y2 - 1][x2 - 1];
604 place_inner_grid(c_ptr);
608 /* Hack -- Occasional ragged-edge room */
609 else if (one_in_(50))
611 for (y = y1 + 2; y <= y2 - 2; y += 2)
613 c_ptr = &cave[y][x1];
614 place_inner_grid(c_ptr);
615 c_ptr = &cave[y][x2];
616 place_inner_grid(c_ptr);
618 for (x = x1 + 2; x <= x2 - 2; x += 2)
620 c_ptr = &cave[y1][x];
621 place_inner_grid(c_ptr);
622 c_ptr = &cave[y2][x];
623 place_inner_grid(c_ptr);
626 /* Hack -- Occasional divided room */
627 else if (one_in_(50))
629 bool curtain2 = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
630 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 2 : 128);
632 if (randint1(100) < 50)
634 /* Horizontal wall */
635 for (x = x1; x <= x2; x++)
637 place_inner_bold(yval, x);
638 if (curtain2) cave[yval][x].feat = feat_closed_curtain;
641 /* Prevent edge of wall from being tunneled */
642 place_solid_bold(yval, x1 - 1);
643 place_solid_bold(yval, x2 + 1);
648 for (y = y1; y <= y2; y++)
650 place_inner_bold(y, xval);
651 if (curtain2) cave[y][xval].feat = feat_closed_curtain;
654 /* Prevent edge of wall from being tunneled */
655 place_solid_bold(y1 - 1, xval);
656 place_solid_bold(y2 + 1, xval);
659 place_random_door(yval, xval, TRUE);
660 if (curtain2) cave[yval][xval].feat = feat_closed_curtain;
668 * Type 2 -- Overlapping rectangular rooms
670 static bool build_type2(void)
672 int y, x, xval, yval;
673 int y1a, x1a, y2a, x2a;
674 int y1b, x1b, y2b, x2b;
678 /* Find and reserve some space in the dungeon. Get center of room. */
679 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
681 /* Choose lite or dark */
682 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
684 /* Determine extents of the first room */
685 y1a = yval - randint1(4);
686 y2a = yval + randint1(3);
687 x1a = xval - randint1(11);
688 x2a = xval + randint1(10);
690 /* Determine extents of the second room */
691 y1b = yval - randint1(3);
692 y2b = yval + randint1(4);
693 x1b = xval - randint1(10);
694 x2b = xval + randint1(11);
697 /* Place a full floor for room "a" */
698 for (y = y1a - 1; y <= y2a + 1; y++)
700 for (x = x1a - 1; x <= x2a + 1; x++)
703 place_floor_grid(c_ptr);
704 c_ptr->info |= (CAVE_ROOM);
705 if (light) c_ptr->info |= (CAVE_GLOW);
709 /* Place a full floor for room "b" */
710 for (y = y1b - 1; y <= y2b + 1; y++)
712 for (x = x1b - 1; x <= x2b + 1; x++)
715 place_floor_grid(c_ptr);
716 c_ptr->info |= (CAVE_ROOM);
717 if (light) c_ptr->info |= (CAVE_GLOW);
722 /* Place the walls around room "a" */
723 for (y = y1a - 1; y <= y2a + 1; y++)
725 c_ptr = &cave[y][x1a - 1];
726 place_outer_grid(c_ptr);
727 c_ptr = &cave[y][x2a + 1];
728 place_outer_grid(c_ptr);
730 for (x = x1a - 1; x <= x2a + 1; x++)
732 c_ptr = &cave[y1a - 1][x];
733 place_outer_grid(c_ptr);
734 c_ptr = &cave[y2a + 1][x];
735 place_outer_grid(c_ptr);
738 /* Place the walls around room "b" */
739 for (y = y1b - 1; y <= y2b + 1; y++)
741 c_ptr = &cave[y][x1b - 1];
742 place_outer_grid(c_ptr);
743 c_ptr = &cave[y][x2b + 1];
744 place_outer_grid(c_ptr);
746 for (x = x1b - 1; x <= x2b + 1; x++)
748 c_ptr = &cave[y1b - 1][x];
749 place_outer_grid(c_ptr);
750 c_ptr = &cave[y2b + 1][x];
751 place_outer_grid(c_ptr);
756 /* Replace the floor for room "a" */
757 for (y = y1a; y <= y2a; y++)
759 for (x = x1a; x <= x2a; x++)
762 place_floor_grid(c_ptr);
766 /* Replace the floor for room "b" */
767 for (y = y1b; y <= y2b; y++)
769 for (x = x1b; x <= x2b; x++)
772 place_floor_grid(c_ptr);
782 * Type 3 -- Cross shaped rooms
784 * Builds a room at a row, column coordinate
786 * Room "a" runs north/south, and Room "b" runs east/east
787 * So the "central pillar" runs from x1a, y1b to x2a, y2b.
789 * Note that currently, the "center" is always 3x3, but I think that
790 * the code below will work (with "bounds checking") for 5x5, or even
791 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.
793 static bool build_type3(void)
795 int y, x, dy, dx, wy, wx;
796 int y1a, x1a, y2a, x2a;
797 int y1b, x1b, y2b, x2b;
803 /* Find and reserve some space in the dungeon. Get center of room. */
804 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
807 /* Choose lite or dark */
808 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
810 /* For now, always 3x3 */
813 /* Pick max vertical size (at most 4) */
814 dy = rand_range(3, 4);
816 /* Pick max horizontal size (at most 15) */
817 dx = rand_range(3, 11);
820 /* Determine extents of the north/south room */
826 /* Determine extents of the east/west room */
833 /* Place a full floor for room "a" */
834 for (y = y1a - 1; y <= y2a + 1; y++)
836 for (x = x1a - 1; x <= x2a + 1; x++)
839 place_floor_grid(c_ptr);
840 c_ptr->info |= (CAVE_ROOM);
841 if (light) c_ptr->info |= (CAVE_GLOW);
845 /* Place a full floor for room "b" */
846 for (y = y1b - 1; y <= y2b + 1; y++)
848 for (x = x1b - 1; x <= x2b + 1; x++)
851 place_floor_grid(c_ptr);
852 c_ptr->info |= (CAVE_ROOM);
853 if (light) c_ptr->info |= (CAVE_GLOW);
858 /* Place the walls around room "a" */
859 for (y = y1a - 1; y <= y2a + 1; y++)
861 c_ptr = &cave[y][x1a - 1];
862 place_outer_grid(c_ptr);
863 c_ptr = &cave[y][x2a + 1];
864 place_outer_grid(c_ptr);
866 for (x = x1a - 1; x <= x2a + 1; x++)
868 c_ptr = &cave[y1a - 1][x];
869 place_outer_grid(c_ptr);
870 c_ptr = &cave[y2a + 1][x];
871 place_outer_grid(c_ptr);
874 /* Place the walls around room "b" */
875 for (y = y1b - 1; y <= y2b + 1; y++)
877 c_ptr = &cave[y][x1b - 1];
878 place_outer_grid(c_ptr);
879 c_ptr = &cave[y][x2b + 1];
880 place_outer_grid(c_ptr);
882 for (x = x1b - 1; x <= x2b + 1; x++)
884 c_ptr = &cave[y1b - 1][x];
885 place_outer_grid(c_ptr);
886 c_ptr = &cave[y2b + 1][x];
887 place_outer_grid(c_ptr);
891 /* Replace the floor for room "a" */
892 for (y = y1a; y <= y2a; y++)
894 for (x = x1a; x <= x2a; x++)
897 place_floor_grid(c_ptr);
901 /* Replace the floor for room "b" */
902 for (y = y1b; y <= y2b; y++)
904 for (x = x1b; x <= x2b; x++)
907 place_floor_grid(c_ptr);
913 /* Special features (3/4) */
916 /* Large solid middle pillar */
919 for (y = y1b; y <= y2b; y++)
921 for (x = x1a; x <= x2a; x++)
924 place_inner_grid(c_ptr);
930 /* Inner treasure vault */
933 /* Build the vault */
934 for (y = y1b; y <= y2b; y++)
936 c_ptr = &cave[y][x1a];
937 place_inner_grid(c_ptr);
938 c_ptr = &cave[y][x2a];
939 place_inner_grid(c_ptr);
941 for (x = x1a; x <= x2a; x++)
943 c_ptr = &cave[y1b][x];
944 place_inner_grid(c_ptr);
945 c_ptr = &cave[y2b][x];
946 place_inner_grid(c_ptr);
949 /* Place a secret door on the inner room */
952 case 0: place_secret_door(y1b, xval); break;
953 case 1: place_secret_door(y2b, xval); break;
954 case 2: place_secret_door(yval, x1a); break;
955 case 3: place_secret_door(yval, x2a); break;
958 /* Place a treasure in the vault */
959 place_object(yval, xval, 0L);
961 /* Let's guard the treasure well */
962 vault_monsters(yval, xval, randint0(2) + 3);
964 /* Traps naturally */
965 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
973 /* Occasionally pinch the center shut */
976 /* Pinch the east/west sides */
977 for (y = y1b; y <= y2b; y++)
979 if (y == yval) continue;
980 c_ptr = &cave[y][x1a - 1];
981 place_inner_grid(c_ptr);
982 c_ptr = &cave[y][x2a + 1];
983 place_inner_grid(c_ptr);
986 /* Pinch the north/south sides */
987 for (x = x1a; x <= x2a; x++)
989 if (x == xval) continue;
990 c_ptr = &cave[y1b - 1][x];
991 place_inner_grid(c_ptr);
992 c_ptr = &cave[y2b + 1][x];
993 place_inner_grid(c_ptr);
996 /* Sometimes shut using secret doors */
999 place_secret_door(yval, x1a - 1);
1000 place_secret_door(yval, x2a + 1);
1001 place_secret_door(y1b - 1, xval);
1002 place_secret_door(y2b + 1, xval);
1006 /* Occasionally put a "plus" in the center */
1007 else if (one_in_(3))
1009 c_ptr = &cave[yval][xval];
1010 place_inner_grid(c_ptr);
1011 c_ptr = &cave[y1b][xval];
1012 place_inner_grid(c_ptr);
1013 c_ptr = &cave[y2b][xval];
1014 place_inner_grid(c_ptr);
1015 c_ptr = &cave[yval][x1a];
1016 place_inner_grid(c_ptr);
1017 c_ptr = &cave[yval][x2a];
1018 place_inner_grid(c_ptr);
1021 /* Occasionally put a pillar in the center */
1022 else if (one_in_(3))
1024 c_ptr = &cave[yval][xval];
1025 place_inner_grid(c_ptr);
1037 * Type 4 -- Large room with inner features
1039 * Possible sub-types:
1040 * 1 - Just an inner room with one door
1041 * 2 - An inner room within an inner room
1042 * 3 - An inner room with pillar(s)
1043 * 4 - Inner room has a maze
1044 * 5 - A set of four inner rooms
1046 static bool build_type4(void)
1049 int y2, x2, tmp, yval, xval;
1054 /* Find and reserve some space in the dungeon. Get center of room. */
1055 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
1057 /* Choose lite or dark */
1058 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1066 /* Place a full floor under the room */
1067 for (y = y1 - 1; y <= y2 + 1; y++)
1069 for (x = x1 - 1; x <= x2 + 1; x++)
1071 c_ptr = &cave[y][x];
1072 place_floor_grid(c_ptr);
1073 c_ptr->info |= (CAVE_ROOM);
1074 if (light) c_ptr->info |= (CAVE_GLOW);
1079 for (y = y1 - 1; y <= y2 + 1; y++)
1081 c_ptr = &cave[y][x1 - 1];
1082 place_outer_grid(c_ptr);
1083 c_ptr = &cave[y][x2 + 1];
1084 place_outer_grid(c_ptr);
1086 for (x = x1 - 1; x <= x2 + 1; x++)
1088 c_ptr = &cave[y1 - 1][x];
1089 place_outer_grid(c_ptr);
1090 c_ptr = &cave[y2 + 1][x];
1091 place_outer_grid(c_ptr);
1095 /* The inner room */
1101 /* The inner walls */
1102 for (y = y1 - 1; y <= y2 + 1; y++)
1104 c_ptr = &cave[y][x1 - 1];
1105 place_inner_grid(c_ptr);
1106 c_ptr = &cave[y][x2 + 1];
1107 place_inner_grid(c_ptr);
1109 for (x = x1 - 1; x <= x2 + 1; x++)
1111 c_ptr = &cave[y1 - 1][x];
1112 place_inner_grid(c_ptr);
1113 c_ptr = &cave[y2 + 1][x];
1114 place_inner_grid(c_ptr);
1118 /* Inner room variations */
1119 switch (randint1(5))
1121 /* Just an inner room with a monster */
1124 /* Place a secret door */
1125 switch (randint1(4))
1127 case 1: place_secret_door(y1 - 1, xval); break;
1128 case 2: place_secret_door(y2 + 1, xval); break;
1129 case 3: place_secret_door(yval, x1 - 1); break;
1130 case 4: place_secret_door(yval, x2 + 1); break;
1133 /* Place a monster in the room */
1134 vault_monsters(yval, xval, 1);
1139 /* Treasure Vault (with a door) */
1142 /* Place a secret door */
1143 switch (randint1(4))
1145 case 1: place_secret_door(y1 - 1, xval); break;
1146 case 2: place_secret_door(y2 + 1, xval); break;
1147 case 3: place_secret_door(yval, x1 - 1); break;
1148 case 4: place_secret_door(yval, x2 + 1); break;
1151 /* Place another inner room */
1152 for (y = yval - 1; y <= yval + 1; y++)
1154 for (x = xval - 1; x <= xval + 1; x++)
1156 if ((x == xval) && (y == yval)) continue;
1157 c_ptr = &cave[y][x];
1158 place_inner_grid(c_ptr);
1162 /* Place a locked door on the inner room */
1163 switch (randint1(4))
1165 case 1: place_locked_door(yval - 1, xval); break;
1166 case 2: place_locked_door(yval + 1, xval); break;
1167 case 3: place_locked_door(yval, xval - 1); break;
1168 case 4: place_locked_door(yval, xval + 1); break;
1171 /* Monsters to guard the "treasure" */
1172 vault_monsters(yval, xval, randint1(3) + 2);
1175 if (randint0(100) < 80)
1177 place_object(yval, xval, 0L);
1183 place_random_stairs(yval, xval);
1186 /* Traps to protect the treasure */
1187 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
1192 /* Inner pillar(s). */
1195 /* Place a secret door */
1196 switch (randint1(4))
1198 case 1: place_secret_door(y1 - 1, xval); break;
1199 case 2: place_secret_door(y2 + 1, xval); break;
1200 case 3: place_secret_door(yval, x1 - 1); break;
1201 case 4: place_secret_door(yval, x2 + 1); break;
1204 /* Large Inner Pillar */
1205 for (y = yval - 1; y <= yval + 1; y++)
1207 for (x = xval - 1; x <= xval + 1; x++)
1209 c_ptr = &cave[y][x];
1210 place_inner_grid(c_ptr);
1214 /* Occasionally, two more Large Inner Pillars */
1218 for (y = yval - 1; y <= yval + 1; y++)
1220 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1222 c_ptr = &cave[y][x];
1223 place_inner_grid(c_ptr);
1225 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1227 c_ptr = &cave[y][x];
1228 place_inner_grid(c_ptr);
1233 /* Occasionally, some Inner rooms */
1236 /* Long horizontal walls */
1237 for (x = xval - 5; x <= xval + 5; x++)
1239 c_ptr = &cave[yval - 1][x];
1240 place_inner_grid(c_ptr);
1241 c_ptr = &cave[yval + 1][x];
1242 place_inner_grid(c_ptr);
1245 /* Close off the left/right edges */
1246 c_ptr = &cave[yval][xval - 5];
1247 place_inner_grid(c_ptr);
1248 c_ptr = &cave[yval][xval + 5];
1249 place_inner_grid(c_ptr);
1251 /* Secret doors (random top/bottom) */
1252 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3);
1253 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3);
1256 vault_monsters(yval, xval - 2, randint1(2));
1257 vault_monsters(yval, xval + 2, randint1(2));
1260 if (one_in_(3)) place_object(yval, xval - 2, 0L);
1261 if (one_in_(3)) place_object(yval, xval + 2, 0L);
1270 /* Place a secret door */
1271 switch (randint1(4))
1273 case 1: place_secret_door(y1 - 1, xval); break;
1274 case 2: place_secret_door(y2 + 1, xval); break;
1275 case 3: place_secret_door(yval, x1 - 1); break;
1276 case 4: place_secret_door(yval, x2 + 1); break;
1279 /* Maze (really a checkerboard) */
1280 for (y = y1; y <= y2; y++)
1282 for (x = x1; x <= x2; x++)
1286 c_ptr = &cave[y][x];
1287 place_inner_grid(c_ptr);
1292 /* Monsters just love mazes. */
1293 vault_monsters(yval, xval - 5, randint1(3));
1294 vault_monsters(yval, xval + 5, randint1(3));
1296 /* Traps make them entertaining. */
1297 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1298 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1300 /* Mazes should have some treasure too. */
1301 vault_objects(yval, xval, 3);
1306 /* Four small rooms. */
1310 for (y = y1; y <= y2; y++)
1312 c_ptr = &cave[y][xval];
1313 place_inner_grid(c_ptr);
1315 for (x = x1; x <= x2; x++)
1317 c_ptr = &cave[yval][x];
1318 place_inner_grid(c_ptr);
1321 /* Doors into the rooms */
1322 if (randint0(100) < 50)
1324 int i = randint1(10);
1325 place_secret_door(y1 - 1, xval - i);
1326 place_secret_door(y1 - 1, xval + i);
1327 place_secret_door(y2 + 1, xval - i);
1328 place_secret_door(y2 + 1, xval + i);
1332 int i = randint1(3);
1333 place_secret_door(yval + i, x1 - 1);
1334 place_secret_door(yval - i, x1 - 1);
1335 place_secret_door(yval + i, x2 + 1);
1336 place_secret_door(yval - i, x2 + 1);
1339 /* Treasure, centered at the center of the cross */
1340 vault_objects(yval, xval, 2 + randint1(2));
1342 /* Gotta have some monsters. */
1343 vault_monsters(yval + 1, xval - 4, randint1(4));
1344 vault_monsters(yval + 1, xval + 4, randint1(4));
1345 vault_monsters(yval - 1, xval - 4, randint1(4));
1346 vault_monsters(yval - 1, xval + 4, randint1(4));
1357 * The following functions are used to determine if the given monster
1358 * is appropriate for inclusion in a monster nest or monster pit or
1361 * None of the pits/nests are allowed to include "unique" monsters.
1366 * Monster validation macro
1368 * Line 1 -- forbid town monsters
1369 * Line 2 -- forbid uniques
1370 * Line 3 -- forbid aquatic monsters
1372 #define vault_monster_okay(I) \
1373 (mon_hook_dungeon(I) && \
1374 !(r_info[I].flags1 & RF1_UNIQUE) && \
1375 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1376 !(r_info[I].flagsr & RFR_RES_ALL) && \
1377 !(r_info[I].flags7 & RF7_AQUATIC))
1380 /* Race index for "monster pit (clone)" */
1381 static int vault_aux_race;
1383 /* Race index for "monster pit (symbol clone)" */
1384 static char vault_aux_char;
1386 /* Breath mask for "monster pit (dragon)" */
1387 static u32b vault_aux_dragon_mask4;
1391 * Helper monster selection function
1393 static bool vault_aux_simple(int r_idx)
1396 return (vault_monster_okay(r_idx));
1401 * Helper function for "monster nest (jelly)"
1403 static bool vault_aux_jelly(int r_idx)
1405 monster_race *r_ptr = &r_info[r_idx];
1407 /* Validate the monster */
1408 if (!vault_monster_okay(r_idx)) return (FALSE);
1410 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1412 /* Also decline evil jellies (like death molds and shoggoths) */
1413 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1415 /* Require icky thing, jelly, mold, or mushroom */
1416 if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
1424 * Helper function for "monster nest (animal)"
1426 static bool vault_aux_animal(int r_idx)
1428 monster_race *r_ptr = &r_info[r_idx];
1430 /* Validate the monster */
1431 if (!vault_monster_okay(r_idx)) return (FALSE);
1433 /* Require "animal" flag */
1434 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1442 * Helper function for "monster nest (undead)"
1444 static bool vault_aux_undead(int r_idx)
1446 monster_race *r_ptr = &r_info[r_idx];
1448 /* Validate the monster */
1449 if (!vault_monster_okay(r_idx)) return (FALSE);
1451 /* Require Undead */
1452 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1460 * Helper function for "monster nest (chapel)"
1462 static bool vault_aux_chapel_g(int r_idx)
1464 static int chapel_list[] = {
1465 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1466 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1467 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1472 monster_race *r_ptr = &r_info[r_idx];
1474 /* Validate the monster */
1475 if (!vault_monster_okay(r_idx)) return (FALSE);
1477 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1478 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1480 /* Require "priest" or Angel */
1482 if (r_ptr->d_char == 'A') return TRUE;
1484 for (i = 0; chapel_list[i]; i++)
1485 if (r_idx == chapel_list[i]) return TRUE;
1492 * Helper function for "monster nest (kennel)"
1494 static bool vault_aux_kennel(int r_idx)
1496 monster_race *r_ptr = &r_info[r_idx];
1498 /* Validate the monster */
1499 if (!vault_monster_okay(r_idx)) return (FALSE);
1501 /* Require a Zephyr Hound or a dog */
1502 if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
1510 * Helper function for "monster nest (mimic)"
1512 static bool vault_aux_mimic(int r_idx)
1514 monster_race *r_ptr = &r_info[r_idx];
1516 /* Validate the monster */
1517 if (!vault_monster_okay(r_idx)) return (FALSE);
1520 if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
1527 * Helper function for "monster nest (clone)"
1529 static bool vault_aux_clone(int r_idx)
1531 /* Validate the monster */
1532 if (!vault_monster_okay(r_idx)) return (FALSE);
1534 return (r_idx == vault_aux_race);
1539 * Helper function for "monster nest (symbol clone)"
1541 static bool vault_aux_symbol_e(int r_idx)
1543 monster_race *r_ptr = &r_info[r_idx];
1545 /* Validate the monster */
1546 if (!vault_monster_okay(r_idx)) return (FALSE);
1548 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1550 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1552 /* Decline incorrect symbol */
1553 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1561 * Helper function for "monster nest (symbol clone)"
1563 static bool vault_aux_symbol_g(int r_idx)
1565 monster_race *r_ptr = &r_info[r_idx];
1567 /* Validate the monster */
1568 if (!vault_monster_okay(r_idx)) return (FALSE);
1570 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1572 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1574 /* Decline incorrect symbol */
1575 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1583 * Helper function for "monster pit (orc)"
1585 static bool vault_aux_orc(int r_idx)
1587 monster_race *r_ptr = &r_info[r_idx];
1589 /* Validate the monster */
1590 if (!vault_monster_okay(r_idx)) return (FALSE);
1593 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1595 /* Decline undead */
1596 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1604 * Helper function for "monster pit (troll)"
1606 static bool vault_aux_troll(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_TROLL)) return (FALSE);
1616 /* Decline undead */
1617 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1625 * Helper function for "monster pit (giant)"
1627 static bool vault_aux_giant(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_GIANT)) return (FALSE);
1637 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1639 /* Decline undead */
1640 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1648 * Helper function for "monster pit (dragon)"
1650 static bool vault_aux_dragon(int r_idx)
1652 monster_race *r_ptr = &r_info[r_idx];
1654 /* Validate the monster */
1655 if (!vault_monster_okay(r_idx)) return (FALSE);
1657 /* Require dragon */
1658 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1660 /* Hack -- Require correct "breath attack" */
1661 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1663 /* Decline undead */
1664 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1672 * Helper function for "monster pit (demon)"
1674 static bool vault_aux_demon(int r_idx)
1676 monster_race *r_ptr = &r_info[r_idx];
1678 /* Validate the monster */
1679 if (!vault_monster_okay(r_idx)) return (FALSE);
1681 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1684 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1692 * Helper function for "monster pit (lovecraftian)"
1694 static bool vault_aux_cthulhu(int r_idx)
1696 monster_race *r_ptr = &r_info[r_idx];
1698 /* Validate the monster */
1699 if (!vault_monster_okay(r_idx)) return (FALSE);
1701 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1703 /* Require eldritch horror */
1704 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1712 * Helper function for "monster pit (clone)"
1714 static void vault_prep_clone(void)
1716 /* Apply the monster restriction */
1717 get_mon_num_prep(vault_aux_simple, NULL);
1719 /* Pick a race to clone */
1720 vault_aux_race = get_mon_num(dun_level + 10);
1722 /* Remove the monster restriction */
1723 get_mon_num_prep(NULL, NULL);
1728 * Helper function for "monster pit (symbol clone)"
1730 static void vault_prep_symbol(void)
1734 /* Apply the monster restriction */
1735 get_mon_num_prep(vault_aux_simple, NULL);
1737 /* Pick a race to clone */
1738 r_idx = get_mon_num(dun_level + 10);
1740 /* Remove the monster restriction */
1741 get_mon_num_prep(NULL, NULL);
1743 /* Extract the symbol */
1744 vault_aux_char = r_info[r_idx].d_char;
1749 * Helper function for "monster pit (dragon)"
1751 static void vault_prep_dragon(void)
1753 /* Pick dragon type */
1754 switch (randint0(6))
1759 /* Restrict dragon breath type */
1760 vault_aux_dragon_mask4 = RF4_BR_ACID;
1769 /* Restrict dragon breath type */
1770 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1779 /* Restrict dragon breath type */
1780 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1789 /* Restrict dragon breath type */
1790 vault_aux_dragon_mask4 = RF4_BR_COLD;
1799 /* Restrict dragon breath type */
1800 vault_aux_dragon_mask4 = RF4_BR_POIS;
1809 /* Restrict dragon breath type */
1810 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1811 RF4_BR_FIRE | RF4_BR_COLD |
1822 * Helper function for "monster pit (dark elf)"
1824 static bool vault_aux_dark_elf(int r_idx)
1827 static int dark_elf_list[] =
1829 MON_D_ELF, MON_D_ELF_MAGE, MON_D_ELF_WARRIOR, MON_D_ELF_PRIEST,
1830 MON_D_ELF_LORD, MON_D_ELF_WARLOCK, MON_D_ELF_DRUID, MON_NIGHTBLADE,
1831 MON_D_ELF_SORC, MON_D_ELF_SHADE, 0,
1834 /* Validate the monster */
1835 if (!vault_monster_okay(r_idx)) return FALSE;
1837 /* Require dark elves */
1838 for (i = 0; dark_elf_list[i]; i++)
1839 if (r_idx == dark_elf_list[i]) return TRUE;
1846 typedef struct vault_aux_type vault_aux_type;
1849 struct vault_aux_type
1852 bool (*hook_func)(int r_idx);
1853 void (*prep_func)(void);
1859 static int pick_vault_type(vault_aux_type *l_ptr, s16b allow_flag_mask)
1861 int tmp, total, count;
1863 vault_aux_type *n_ptr;
1865 /* Calculate the total possibilities */
1866 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1869 if (!n_ptr->name) break;
1871 /* Ignore excessive depth */
1872 if (n_ptr->level > dun_level) continue;
1874 /* Not matched with pit/nest flag */
1875 if (!(allow_flag_mask & (1L << count))) continue;
1877 /* Count this possibility */
1878 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1881 /* Pick a random type */
1882 tmp = randint0(total);
1884 /* Find this type */
1885 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1888 if (!n_ptr->name) break;
1890 /* Ignore excessive depth */
1891 if (n_ptr->level > dun_level) continue;
1893 /* Not matched with pit/nest flag */
1894 if (!(allow_flag_mask & (1L << count))) continue;
1896 /* Count this possibility */
1897 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1899 /* Found the type */
1900 if (tmp < total) break;
1903 return n_ptr->name ? count : -1;
1906 static vault_aux_type nest_types[] =
1909 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1910 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1911 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1912 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1913 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1914 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1915 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1916 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1917 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1918 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1919 {NULL, NULL, NULL, 0, 0},
1921 {"clone", vault_aux_clone, vault_prep_clone, 5, 3},
1922 {"jelly", vault_aux_jelly, NULL, 5, 6},
1923 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1924 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1925 {"mimic", vault_aux_mimic, NULL, 30, 4},
1926 {"lovecraftian", vault_aux_cthulhu, NULL, 70, 2},
1927 {"kennel", vault_aux_kennel, NULL, 45, 4},
1928 {"animal", vault_aux_animal, NULL, 35, 5},
1929 {"chapel", vault_aux_chapel_g, NULL, 75, 4},
1930 {"undead", vault_aux_undead, NULL, 75, 5},
1931 {NULL, NULL, NULL, 0, 0},
1935 static vault_aux_type pit_types[] =
1938 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1939 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1940 {"¥¸¥ã¥¤¥¢¥ó¥È", vault_aux_giant, NULL, 50, 6},
1941 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1942 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1943 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1944 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
1945 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
1946 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
1947 {"¥À¡¼¥¯¥¨¥ë¥Õ", vault_aux_dark_elf, NULL, 45, 4},
1948 {NULL, NULL, NULL, 0, 0},
1950 {"orc", vault_aux_orc, NULL, 5, 6},
1951 {"troll", vault_aux_troll, NULL, 20, 6},
1952 {"giant", vault_aux_giant, NULL, 50, 6},
1953 {"lovecraftian", vault_aux_cthulhu, NULL, 80, 2},
1954 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1955 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1956 {"chapel", vault_aux_chapel_g, NULL, 65, 2},
1957 {"dragon", vault_aux_dragon, vault_prep_dragon, 70, 6},
1958 {"demon", vault_aux_demon, NULL, 80, 6},
1959 {"dark elf", vault_aux_dark_elf, NULL, 45, 4},
1960 {NULL, NULL, NULL, 0, 0},
1965 /* Nest types code */
1966 #define NEST_TYPE_CLONE 0
1967 #define NEST_TYPE_JELLY 1
1968 #define NEST_TYPE_SYMBOL_GOOD 2
1969 #define NEST_TYPE_SYMBOL_EVIL 3
1970 #define NEST_TYPE_MIMIC 4
1971 #define NEST_TYPE_LOVECRAFTIAN 5
1972 #define NEST_TYPE_KENNEL 6
1973 #define NEST_TYPE_ANIMAL 7
1974 #define NEST_TYPE_CHAPEL 8
1975 #define NEST_TYPE_UNDEAD 9
1977 /* Pit types code */
1978 #define PIT_TYPE_ORC 0
1979 #define PIT_TYPE_TROLL 1
1980 #define PIT_TYPE_GIANT 2
1981 #define PIT_TYPE_LOVECRAFTIAN 3
1982 #define PIT_TYPE_SYMBOL_GOOD 4
1983 #define PIT_TYPE_SYMBOL_EVIL 5
1984 #define PIT_TYPE_CHAPEL 6
1985 #define PIT_TYPE_DRAGON 7
1986 #define PIT_TYPE_DEMON 8
1987 #define PIT_TYPE_DARK_ELF 9
1991 * Hack -- Get the string describing subtype of pit/nest
1992 * Determined in prepare function (some pit/nest only)
1994 static cptr pit_subtype_string(int type, bool nest)
1996 static char inner_buf[256] = "";
1998 inner_buf[0] = '\0'; /* Init string */
2000 if (nest) /* Nests */
2004 case NEST_TYPE_CLONE:
2005 sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
2007 case NEST_TYPE_SYMBOL_GOOD:
2008 case NEST_TYPE_SYMBOL_EVIL:
2009 sprintf(inner_buf, "(%c)", vault_aux_char);
2017 case PIT_TYPE_SYMBOL_GOOD:
2018 case PIT_TYPE_SYMBOL_EVIL:
2019 sprintf(inner_buf, "(%c)", vault_aux_char);
2021 case PIT_TYPE_DRAGON:
2022 switch (vault_aux_dragon_mask4)
2025 case RF4_BR_ACID: strcpy(inner_buf, "(»À)"); break;
2026 case RF4_BR_ELEC: strcpy(inner_buf, "(°ðºÊ)"); break;
2027 case RF4_BR_FIRE: strcpy(inner_buf, "(²Ð±ê)"); break;
2028 case RF4_BR_COLD: strcpy(inner_buf, "(Î䵤)"); break;
2029 case RF4_BR_POIS: strcpy(inner_buf, "(ÆÇ)"); break;
2030 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2031 strcpy(inner_buf, "(Ëü¿§)"); break;
2032 default: strcpy(inner_buf, "(̤ÄêµÁ)"); break;
2034 case RF4_BR_ACID: strcpy(inner_buf, "(acid)"); break;
2035 case RF4_BR_ELEC: strcpy(inner_buf, "(lightning)"); break;
2036 case RF4_BR_FIRE: strcpy(inner_buf, "(fire)"); break;
2037 case RF4_BR_COLD: strcpy(inner_buf, "(frost)"); break;
2038 case RF4_BR_POIS: strcpy(inner_buf, "(poison)"); break;
2039 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2040 strcpy(inner_buf, "(multi-hued)"); break;
2041 default: strcpy(inner_buf, "(undefined)"); break;
2052 /* A struct for nest monster information with cheat_hear */
2062 * Comp function for sorting nest monster information
2064 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
2066 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2067 int w1 = nest_mon_info[a].r_idx;
2068 int w2 = nest_mon_info[b].r_idx;
2069 monster_race *r1_ptr = &r_info[w1];
2070 monster_race *r2_ptr = &r_info[w2];
2076 /* Extract used info */
2077 z1 = nest_mon_info[a].used;
2078 z2 = nest_mon_info[b].used;
2080 /* Compare used status */
2081 if (z1 < z2) return FALSE;
2082 if (z1 > z2) return TRUE;
2084 /* Compare levels */
2085 if (r1_ptr->level < r2_ptr->level) return TRUE;
2086 if (r1_ptr->level > r2_ptr->level) return FALSE;
2088 /* Compare experience */
2089 if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
2090 if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
2092 /* Compare indexes */
2098 * Swap function for sorting nest monster information
2100 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
2102 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2103 nest_mon_info_type holder;
2109 holder = nest_mon_info[a];
2110 nest_mon_info[a] = nest_mon_info[b];
2111 nest_mon_info[b] = holder;
2115 #define NUM_NEST_MON_TYPE 64
2118 * Type 5 -- Monster nests
2120 * A monster nest is a "big" room, with an "inner" room, containing
2121 * a "collection" of monsters of a given type strewn about the room.
2123 * The monsters are chosen from a set of 64 randomly selected monster
2124 * races, to allow the nest creation to fail instead of having "holes".
2126 * Note the use of the "get_mon_num_prep()" function, and the special
2127 * "get_mon_num_hook()" restriction function, to prepare the "monster
2128 * allocation table" in such a way as to optimize the selection of
2129 * "appropriate" non-unique monsters for the nest.
2131 * Note that the "get_mon_num()" function may (rarely) fail, in which
2132 * case the nest will be empty.
2134 * Note that "monster nests" will never contain "unique" monsters.
2136 static bool build_type5(void)
2138 int y, x, y1, x1, y2, x2, xval, yval;
2140 nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
2146 int cur_nest_type = pick_vault_type(nest_types, d_info[dungeon_type].nest);
2147 vault_aux_type *n_ptr;
2149 /* No type available */
2150 if (cur_nest_type < 0) return FALSE;
2152 n_ptr = &nest_types[cur_nest_type];
2154 /* Process a preparation function if necessary */
2155 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2157 /* Prepare allocation table */
2158 get_mon_num_prep(n_ptr->hook_func, NULL);
2160 align.sub_align = SUB_ALIGN_NEUTRAL;
2162 /* Pick some monster types */
2163 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2165 int r_idx = 0, attempts = 100;
2166 monster_race *r_ptr = NULL;
2170 /* Get a (hard) monster type */
2171 r_idx = get_mon_num(dun_level + 11);
2172 r_ptr = &r_info[r_idx];
2174 /* Decline incorrect alignment */
2175 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2177 /* Accept this monster */
2181 /* Notice failure */
2182 if (!r_idx || !attempts) return FALSE;
2184 /* Note the alignment */
2185 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2186 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2188 nest_mon_info[i].r_idx = r_idx;
2189 nest_mon_info[i].used = FALSE;
2192 /* Find and reserve some space in the dungeon. Get center of room. */
2193 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2201 /* Place the floor area */
2202 for (y = y1 - 1; y <= y2 + 1; y++)
2204 for (x = x1 - 1; x <= x2 + 1; x++)
2206 c_ptr = &cave[y][x];
2207 place_floor_grid(c_ptr);
2208 c_ptr->info |= (CAVE_ROOM);
2212 /* Place the outer walls */
2213 for (y = y1 - 1; y <= y2 + 1; y++)
2215 c_ptr = &cave[y][x1 - 1];
2216 place_outer_grid(c_ptr);
2217 c_ptr = &cave[y][x2 + 1];
2218 place_outer_grid(c_ptr);
2220 for (x = x1 - 1; x <= x2 + 1; x++)
2222 c_ptr = &cave[y1 - 1][x];
2223 place_outer_grid(c_ptr);
2224 c_ptr = &cave[y2 + 1][x];
2225 place_outer_grid(c_ptr);
2229 /* Advance to the center room */
2235 /* The inner walls */
2236 for (y = y1 - 1; y <= y2 + 1; y++)
2238 c_ptr = &cave[y][x1 - 1];
2239 place_inner_grid(c_ptr);
2240 c_ptr = &cave[y][x2 + 1];
2241 place_inner_grid(c_ptr);
2244 for (x = x1 - 1; x <= x2 + 1; x++)
2246 c_ptr = &cave[y1 - 1][x];
2247 place_inner_grid(c_ptr);
2248 c_ptr = &cave[y2 + 1][x];
2249 place_inner_grid(c_ptr);
2251 for (y = y1; y <= y2; y++)
2253 for (x = x1; x <= x2; x++)
2255 add_cave_info(y, x, CAVE_ICKY);
2259 /* Place a secret door */
2260 switch (randint1(4))
2262 case 1: place_secret_door(y1 - 1, xval); break;
2263 case 2: place_secret_door(y2 + 1, xval); break;
2264 case 3: place_secret_door(yval, x1 - 1); break;
2265 case 4: place_secret_door(yval, x2 + 1); break;
2273 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(nest)(%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2275 msg_format("Monster nest (%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2279 /* Place some monsters */
2280 for (y = yval - 2; y <= yval + 2; y++)
2282 for (x = xval - 9; x <= xval + 9; x++)
2286 i = randint0(NUM_NEST_MON_TYPE);
2287 r_idx = nest_mon_info[i].r_idx;
2289 /* Place that "random" monster (no groups) */
2290 (void)place_monster_aux(0, y, x, r_idx, 0L);
2292 nest_mon_info[i].used = TRUE;
2296 if (cheat_room && cheat_hear)
2298 ang_sort_comp = ang_sort_comp_nest_mon_info;
2299 ang_sort_swap = ang_sort_swap_nest_mon_info;
2300 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2302 /* Dump the entries (prevent multi-printing) */
2303 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2305 if (!nest_mon_info[i].used) break;
2306 for (; i < NUM_NEST_MON_TYPE - 1; i++)
2308 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2309 if (!nest_mon_info[i + 1].used) break;
2311 msg_print(r_name + r_info[nest_mon_info[i].r_idx].name);
2320 * Type 6 -- Monster pits
2322 * A monster pit is a "big" room, with an "inner" room, containing
2323 * a "collection" of monsters of a given type organized in the room.
2325 * The inside room in a monster pit appears as shown below, where the
2326 * actual monsters in each location depend on the type of the pit
2328 * #####################
2329 * #0000000000000000000#
2330 * #0112233455543322110#
2331 * #0112233467643322110#
2332 * #0112233455543322110#
2333 * #0000000000000000000#
2334 * #####################
2336 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
2337 * to request 16 "appropriate" monsters, sorting them by level, and using
2338 * the "even" entries in this sorted list for the contents of the pit.
2340 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
2341 * which is handled by requiring a specific "breath" attack for all of the
2342 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
2343 * be present in many of the dragon pits, if they have the proper breath.
2345 * Note the use of the "get_mon_num_prep()" function, and the special
2346 * "get_mon_num_hook()" restriction function, to prepare the "monster
2347 * allocation table" in such a way as to optimize the selection of
2348 * "appropriate" non-unique monsters for the pit.
2350 * Note that the "get_mon_num()" function may (rarely) fail, in which case
2351 * the pit will be empty.
2353 * Note that "monster pits" will never contain "unique" monsters.
2355 static bool build_type6(void)
2357 int y, x, y1, x1, y2, x2, xval, yval;
2366 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2367 vault_aux_type *n_ptr;
2369 /* No type available */
2370 if (cur_pit_type < 0) return FALSE;
2372 n_ptr = &pit_types[cur_pit_type];
2374 /* Process a preparation function if necessary */
2375 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2377 /* Prepare allocation table */
2378 get_mon_num_prep(n_ptr->hook_func, NULL);
2380 align.sub_align = SUB_ALIGN_NEUTRAL;
2382 /* Pick some monster types */
2383 for (i = 0; i < 16; i++)
2385 int r_idx = 0, attempts = 100;
2386 monster_race *r_ptr = NULL;
2390 /* Get a (hard) monster type */
2391 r_idx = get_mon_num(dun_level + 11);
2392 r_ptr = &r_info[r_idx];
2394 /* Decline incorrect alignment */
2395 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2397 /* Accept this monster */
2401 /* Notice failure */
2402 if (!r_idx || !attempts) return FALSE;
2404 /* Note the alignment */
2405 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2406 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2411 /* Find and reserve some space in the dungeon. Get center of room. */
2412 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2420 /* Place the floor area */
2421 for (y = y1 - 1; y <= y2 + 1; y++)
2423 for (x = x1 - 1; x <= x2 + 1; x++)
2425 c_ptr = &cave[y][x];
2426 place_floor_grid(c_ptr);
2427 c_ptr->info |= (CAVE_ROOM);
2431 /* Place the outer walls */
2432 for (y = y1 - 1; y <= y2 + 1; y++)
2434 c_ptr = &cave[y][x1 - 1];
2435 place_outer_grid(c_ptr);
2436 c_ptr = &cave[y][x2 + 1];
2437 place_outer_grid(c_ptr);
2439 for (x = x1 - 1; x <= x2 + 1; x++)
2441 c_ptr = &cave[y1 - 1][x];
2442 place_outer_grid(c_ptr);
2443 c_ptr = &cave[y2 + 1][x];
2444 place_outer_grid(c_ptr);
2447 /* Advance to the center room */
2453 /* The inner walls */
2454 for (y = y1 - 1; y <= y2 + 1; y++)
2456 c_ptr = &cave[y][x1 - 1];
2457 place_inner_grid(c_ptr);
2458 c_ptr = &cave[y][x2 + 1];
2459 place_inner_grid(c_ptr);
2461 for (x = x1 - 1; x <= x2 + 1; x++)
2463 c_ptr = &cave[y1 - 1][x];
2464 place_inner_grid(c_ptr);
2465 c_ptr = &cave[y2 + 1][x];
2466 place_inner_grid(c_ptr);
2468 for (y = y1; y <= y2; y++)
2470 for (x = x1; x <= x2; x++)
2472 add_cave_info(y, x, CAVE_ICKY);
2476 /* Place a secret door */
2477 switch (randint1(4))
2479 case 1: place_secret_door(y1 - 1, xval); break;
2480 case 2: place_secret_door(y2 + 1, xval); break;
2481 case 3: place_secret_door(yval, x1 - 1); break;
2482 case 4: place_secret_door(yval, x2 + 1); break;
2485 /* Sort the entries */
2486 for (i = 0; i < 16 - 1; i++)
2488 /* Sort the entries */
2489 for (j = 0; j < 16 - 1; j++)
2494 int p1 = r_info[what[i1]].level;
2495 int p2 = r_info[what[i2]].level;
2501 what[i1] = what[i2];
2512 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(pit)(%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2514 msg_format("Monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2518 /* Select the entries */
2519 for (i = 0; i < 8; i++)
2521 /* Every other entry */
2522 what[i] = what[i * 2];
2527 msg_print(r_name + r_info[what[i]].name);
2531 /* Top and bottom rows */
2532 for (x = xval - 9; x <= xval + 9; x++)
2534 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2535 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2538 /* Middle columns */
2539 for (y = yval - 1; y <= yval + 1; y++)
2541 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2542 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2544 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2545 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2547 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2548 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2550 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2551 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2553 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2554 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2556 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2557 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2559 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2560 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2562 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2563 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2566 /* Above/Below the center monster */
2567 for (x = xval - 1; x <= xval + 1; x++)
2569 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2570 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2573 /* Next to the center monster */
2574 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2575 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2577 /* Center monster */
2578 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2584 /* coordinate translation code */
2585 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2591 * transno specifies what transformation is required. (0-7)
2592 * The lower two bits indicate by how much the vault is rotated,
2593 * and the upper bit indicates a reflection.
2594 * This is done by using rotation matrices... however since
2595 * these are mostly zeros for rotations by 90 degrees this can
2596 * be expressed simply in terms of swapping and inverting the
2597 * x and y coordinates.
2599 for (i = 0; i < transno % 4; i++)
2601 /* rotate by 90 degrees */
2609 /* Reflect depending on status of 3rd bit. */
2613 /* Add offsets so vault stays in the first quadrant */
2620 * Hack -- fill in "vault" rooms
2622 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2623 int xoffset, int yoffset, int transno)
2625 int dx, dy, x, y, i, j;
2632 /* Place dungeon features and objects */
2633 for (t = data, dy = 0; dy < ymax; dy++)
2635 for (dx = 0; dx < xmax; dx++, t++)
2637 /* prevent loop counter from being overwritten */
2642 coord_trans(&i, &j, xoffset, yoffset, transno);
2644 /* Extract the location */
2645 if (transno % 2 == 0)
2647 /* no swap of x/y */
2648 x = xval - (xmax / 2) + i;
2649 y = yval - (ymax / 2) + j;
2654 x = xval - (ymax / 2) + i;
2655 y = yval - (xmax / 2) + j;
2658 /* Hack -- skip "non-grids" */
2659 if (*t == ' ') continue;
2661 /* Access the grid */
2662 c_ptr = &cave[y][x];
2664 /* Lay down a floor */
2665 place_floor_grid(c_ptr);
2667 /* Remove any mimic */
2670 /* Part of a vault */
2671 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2673 /* Analyze the grid */
2676 /* Granite wall (outer) */
2678 place_outer_noperm_grid(c_ptr);
2681 /* Granite wall (inner) */
2683 place_inner_grid(c_ptr);
2686 /* Permanent wall (inner) */
2688 place_inner_perm_grid(c_ptr);
2693 if (randint0(100) < 75)
2695 place_object(y, x, 0L);
2705 place_secret_door(y, x);
2713 /* Black market in a dungeon */
2715 set_cave_feat(y, x, feat_black_market);
2716 store_init(NO_TOWN, STORE_BLACK);
2721 set_cave_feat(y, x, feat_pattern_start);
2725 set_cave_feat(y, x, feat_pattern_1);
2729 set_cave_feat(y, x, feat_pattern_2);
2733 set_cave_feat(y, x, feat_pattern_3);
2737 set_cave_feat(y, x, feat_pattern_4);
2741 set_cave_feat(y, x, feat_pattern_end);
2745 set_cave_feat(y, x, feat_pattern_exit);
2749 /* Reward for Pattern walk */
2750 object_level = base_level + 12;
2751 place_object(y, x, AM_GOOD | AM_GREAT);
2752 object_level = base_level;
2759 /* Place dungeon monsters and objects */
2760 for (t = data, dy = 0; dy < ymax; dy++)
2762 for (dx = 0; dx < xmax; dx++, t++)
2764 /* prevent loop counter from being overwritten */
2769 coord_trans(&i, &j, xoffset, yoffset, transno);
2771 /* Extract the location */
2772 if (transno % 2 == 0)
2774 /* no swap of x/y */
2775 x = xval - (xmax / 2) + i;
2776 y = yval - (ymax / 2) + j;
2781 x = xval - (ymax / 2) + i;
2782 y = yval - (xmax / 2) + j;
2785 /* Hack -- skip "non-grids" */
2786 if (*t == ' ') continue;
2788 /* Analyze the symbol */
2794 monster_level = base_level + 5;
2795 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2796 monster_level = base_level;
2800 /* Meaner monster */
2803 monster_level = base_level + 11;
2804 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2805 monster_level = base_level;
2809 /* Meaner monster, plus treasure */
2812 monster_level = base_level + 9;
2813 place_monster(y, x, PM_ALLOW_SLEEP);
2814 monster_level = base_level;
2815 object_level = base_level + 7;
2816 place_object(y, x, AM_GOOD);
2817 object_level = base_level;
2821 /* Nasty monster and treasure */
2824 monster_level = base_level + 40;
2825 place_monster(y, x, PM_ALLOW_SLEEP);
2826 monster_level = base_level;
2827 object_level = base_level + 20;
2828 place_object(y, x, AM_GOOD | AM_GREAT);
2829 object_level = base_level;
2833 /* Monster and/or object */
2836 if (randint0(100) < 50)
2838 monster_level = base_level + 3;
2839 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2840 monster_level = base_level;
2842 if (randint0(100) < 50)
2844 object_level = base_level + 7;
2845 place_object(y, x, 0L);
2846 object_level = base_level;
2858 * Type 7 -- simple vaults (see "v_info.txt")
2860 static bool build_type7(void)
2866 int xoffset, yoffset;
2869 /* Pick a lesser vault */
2870 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2872 /* Access a random vault record */
2873 v_ptr = &v_info[randint0(max_v_idx)];
2875 /* Accept the first lesser vault */
2876 if (v_ptr->typ == 7) break;
2879 /* No lesser vault found */
2880 if (dummy >= SAFE_MAX_ATTEMPTS)
2885 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2887 msg_print("Warning! Could not place lesser vault!");
2893 /* pick type of transformation (0-7) */
2894 transno = randint0(8);
2896 /* calculate offsets */
2900 /* Some huge vault cannot be ratated to fit in the dungeon */
2901 if (x+2 > cur_hgt-2)
2903 /* Forbid 90 or 270 degree ratation */
2907 coord_trans(&x, &y, 0, 0, transno);
2927 /* Find and reserve some space in the dungeon. Get center of room. */
2928 if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
2936 if (cheat_room) msg_format("¾®¤µ¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
2938 if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
2941 /* Hack -- Build the vault */
2942 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2943 v_text + v_ptr->text, xoffset, yoffset, transno);
2950 * Type 8 -- greater vaults (see "v_info.txt")
2952 static bool build_type8(void)
2959 int xoffset, yoffset;
2961 /* Pick a greater vault */
2962 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2964 /* Access a random vault record */
2965 v_ptr = &v_info[randint0(max_v_idx)];
2967 /* Accept the first greater vault */
2968 if (v_ptr->typ == 8) break;
2971 /* No greater vault found */
2972 if (dummy >= SAFE_MAX_ATTEMPTS)
2977 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2979 msg_print("Warning! Could not place greater vault!");
2985 /* pick type of transformation (0-7) */
2986 transno = randint0(8);
2988 /* calculate offsets */
2992 /* Some huge vault cannot be ratated to fit in the dungeon */
2993 if (x+2 > cur_hgt-2)
2995 /* Forbid 90 or 270 degree ratation */
2999 coord_trans(&x, &y, 0, 0, transno);
3020 * Try to allocate space for room. If fails, exit
3022 * Hack -- Prepare a bit larger space (+2, +2) to
3023 * prevent generation of vaults with no-entrance.
3025 /* Find and reserve some space in the dungeon. Get center of room. */
3026 if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
3029 v_ptr = &v_info[76 + randint1(3)];
3034 if (cheat_room) msg_format("µðÂç¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3036 if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
3039 /* Hack -- Build the vault */
3040 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3041 v_text + v_ptr->text, xoffset, yoffset, transno);
3047 * Structure to hold all "fill" data
3050 typedef struct fill_data_type fill_data_type;
3052 struct fill_data_type
3065 /* features to fill with */
3074 /* number of filled squares */
3078 static fill_data_type fill_data;
3081 /* Store routine for the fractal cave generator */
3082 /* this routine probably should be an inline function or a macro. */
3083 static void store_height(int x, int y, int val)
3085 /* if on boundary set val > cutoff so walls are not as square */
3086 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3087 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3088 (val <= fill_data.c1)) val = fill_data.c1 + 1;
3090 /* store the value in height-map format */
3091 cave[y][x].feat = val;
3098 * Explanation of the plasma fractal algorithm:
3100 * A grid of points is created with the properties of a 'height-map'
3101 * This is done by making the corners of the grid have a random value.
3102 * The grid is then subdivided into one with twice the resolution.
3103 * The new points midway between two 'known' points can be calculated
3104 * by taking the average value of the 'known' ones and randomly adding
3105 * or subtracting an amount proportional to the distance between those
3106 * points. The final 'middle' points of the grid are then calculated
3107 * by averaging all four of the originally 'known' corner points. An
3108 * random amount is added or subtracted from this to get a value of the
3109 * height at that point. The scaling factor here is adjusted to the
3110 * slightly larger distance diagonally as compared to orthogonally.
3112 * This is then repeated recursively to fill an entire 'height-map'
3113 * A rectangular map is done the same way, except there are different
3114 * scaling factors along the x and y directions.
3116 * A hack to change the amount of correlation between points is done using
3117 * the grd variable. If the current step size is greater than grd then
3118 * the point will be random, otherwise it will be calculated by the
3119 * above algorithm. This makes a maximum distance at which two points on
3120 * the height map can affect each other.
3122 * How fractal caves are made:
3124 * When the map is complete, a cut-off value is used to create a cave.
3125 * Heights below this value are "floor", and heights above are "wall".
3126 * This also can be used to create lakes, by adding more height levels
3127 * representing shallow and deep water/ lava etc.
3129 * The grd variable affects the width of passages.
3130 * The roug variable affects the roughness of those passages
3132 * The tricky part is making sure the created cave is connected. This
3133 * is done by 'filling' from the inside and only keeping the 'filled'
3134 * floor. Walls bounding the 'filled' floor are also kept. Everything
3135 * else is converted to the normal _extra_.
3140 * Note that this uses the cave.feat array in a very hackish way
3141 * the values are first set to zero, and then each array location
3142 * is used as a "heightmap"
3143 * The heightmap then needs to be converted back into the "feat" format.
3145 * grd=level at which fractal turns on. smaller gives more mazelike caves
3146 * roug=roughness level. 16=normal. higher values make things more convoluted
3147 * small values are good for smooth walls.
3148 * size=length of the side of the square cave system.
3150 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3152 int xhsize, yhsize, xsize, ysize, maxsize;
3155 * fixed point variables- these are stored as 256 x normal value
3156 * this gives 8 binary places of fractional part + 8 places of normal part
3159 u16b xstep, xhstep, ystep, yhstep;
3160 u16b xstep2, xhstep2, ystep2, yhstep2;
3161 u16b i, j, ii, jj, diagsize, xxsize, yysize;
3163 /* Cache for speed */
3164 u16b xm, xp, ym, yp;
3166 /* redefine size so can change the value if out of range */
3170 /* Paranoia about size of the system of caves */
3171 if (xsize > 254) xsize = 254;
3172 if (xsize < 4) xsize = 4;
3173 if (ysize > 254) ysize = 254;
3174 if (ysize < 4) ysize = 4;
3176 /* get offsets to middle of array */
3180 /* fix rounding problem */
3184 /* get limits of region */
3185 fill_data.xmin = x0 - xhsize;
3186 fill_data.ymin = y0 - yhsize;
3187 fill_data.xmax = x0 + xhsize;
3188 fill_data.ymax = y0 + yhsize;
3190 /* Store cutoff in global for quick access */
3191 fill_data.c1 = cutoff;
3194 * Scale factor for middle points:
3195 * About sqrt(2) * 256 - correct for a square lattice
3196 * approximately correct for everything else.
3200 /* maximum of xsize and ysize */
3201 maxsize = (xsize > ysize) ? xsize : ysize;
3203 /* Clear the section */
3204 for (i = 0; i <= xsize; i++)
3206 for (j = 0; j <= ysize; j++)
3208 /* -1 is a flag for "not done yet" */
3209 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3210 /* Clear icky flag because may be redoing the cave */
3211 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3215 /* Boundaries are walls */
3216 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
3217 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
3218 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
3219 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
3221 /* Set the middle square to be an open area. */
3222 cave[y0][x0].feat = 0;
3224 /* Initialize the step sizes */
3225 xstep = xhstep = xsize * 256;
3226 ystep = yhstep = ysize * 256;
3227 xxsize = xsize * 256;
3228 yysize = ysize * 256;
3231 * Fill in the rectangle with fractal height data -
3232 * like the 'plasma fractal' in fractint.
3234 while ((xhstep > 256) || (yhstep > 256))
3236 /* Halve the step sizes */
3242 /* cache well used values */
3243 xstep2 = xstep / 256;
3244 ystep2 = ystep / 256;
3246 xhstep2 = xhstep / 256;
3247 yhstep2 = yhstep / 256;
3249 /* middle top to bottom. */
3250 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3252 for (j = 0; j <= yysize; j += ystep)
3254 /* cache often used values */
3255 ii = i / 256 + fill_data.xmin;
3256 jj = j / 256 + fill_data.ymin;
3259 if (cave[jj][ii].feat == -1)
3263 /* If greater than 'grid' level then is random */
3264 store_height(ii, jj, randint1(maxsize));
3268 /* Average of left and right points +random bit */
3269 store_height(ii, jj,
3270 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3271 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3272 + (randint1(xstep2) - xhstep2) * roug / 16);
3279 /* middle left to right. */
3280 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3282 for (i = 0; i <= xxsize; i += xstep)
3284 /* cache often used values */
3285 ii = i / 256 + fill_data.xmin;
3286 jj = j / 256 + fill_data.ymin;
3289 if (cave[jj][ii].feat == -1)
3293 /* If greater than 'grid' level then is random */
3294 store_height(ii, jj, randint1(maxsize));
3298 /* Average of up and down points +random bit */
3299 store_height(ii, jj,
3300 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3301 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3302 + (randint1(ystep2) - yhstep2) * roug / 16);
3309 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3311 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3313 /* cache often used values */
3314 ii = i / 256 + fill_data.xmin;
3315 jj = j / 256 + fill_data.ymin;
3318 if (cave[jj][ii].feat == -1)
3322 /* If greater than 'grid' level then is random */
3323 store_height(ii, jj, randint1(maxsize));
3327 /* Cache reused values. */
3328 xm = fill_data.xmin + (i - xhstep) / 256;
3329 xp = fill_data.xmin + (i + xhstep) / 256;
3330 ym = fill_data.ymin + (j - yhstep) / 256;
3331 yp = fill_data.ymin + (j + yhstep) / 256;
3334 * Average over all four corners + scale by diagsize to
3335 * reduce the effect of the square grid on the shape of the fractal
3337 store_height(ii, jj,
3338 (cave[ym][xm].feat + cave[yp][xm].feat
3339 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3340 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3349 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)
3352 * function used to convert from height-map back to the
3353 * normal angband cave format
3355 if (cave[y][x].info & CAVE_ICKY)
3362 /* Show that have looked at this square */
3363 cave[y][x].info|= (CAVE_ICKY);
3365 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3366 if (cave[y][x].feat <= c1)
3368 /* 25% of the time use the other tile : it looks better this way */
3369 if (randint1(100) < 75)
3371 cave[y][x].feat = feat1;
3372 cave[y][x].info &= ~(CAVE_MASK);
3373 cave[y][x].info |= info1;
3378 cave[y][x].feat = feat2;
3379 cave[y][x].info &= ~(CAVE_MASK);
3380 cave[y][x].info |= info2;
3384 else if (cave[y][x].feat <= c2)
3386 /* 25% of the time use the other tile : it looks better this way */
3387 if (randint1(100) < 75)
3389 cave[y][x].feat = feat2;
3390 cave[y][x].info &= ~(CAVE_MASK);
3391 cave[y][x].info |= info2;
3396 cave[y][x].feat = feat1;
3397 cave[y][x].info &= ~(CAVE_MASK);
3398 cave[y][x].info |= info1;
3402 else if (cave[y][x].feat <= c3)
3404 cave[y][x].feat = feat3;
3405 cave[y][x].info |= info3;
3408 /* if greater than cutoff then is a wall */
3411 place_outer_bold(y, x);
3421 * Quick and nasty fill routine used to find the connected region
3422 * of floor in the middle of the cave
3424 static void cave_fill(byte y, byte x)
3433 /*** Start Grid ***/
3435 /* Enqueue that entry */
3440 /* Now process the queue */
3441 while (flow_head != flow_tail)
3443 /* Extract the next entry */
3444 ty = temp_y[flow_head];
3445 tx = temp_x[flow_head];
3447 /* Forget that entry */
3448 if (++flow_head == TEMP_MAX) flow_head = 0;
3450 /* Add the "children" */
3451 for (d = 0; d < 8; d++)
3453 int old_head = flow_tail;
3455 /* Child location */
3456 j = ty + ddy_ddd[d];
3457 i = tx + ddx_ddd[d];
3459 /* Paranoia Don't leave the cave */
3460 if (!in_bounds(j, i))
3462 /* affect boundary */
3463 cave[j][i].info |= CAVE_ICKY;
3467 /* If within bounds */
3468 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3469 && (j > fill_data.ymin) && (j < fill_data.ymax))
3471 /* If not a wall or floor done before */
3472 if (hack_isnt_wall(j, i,
3473 fill_data.c1, fill_data.c2, fill_data.c3,
3474 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3475 fill_data.info1, fill_data.info2, fill_data.info3))
3477 /* Enqueue that entry */
3478 temp_y[flow_tail] = j;
3479 temp_x[flow_tail] = i;
3481 /* Advance the queue */
3482 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3484 /* Hack -- Overflow by forgetting new entry */
3485 if (flow_tail == flow_head)
3487 flow_tail = old_head;
3491 /* keep tally of size of cave system */
3492 (fill_data.amount)++;
3498 /* affect boundary */
3499 cave[j][i].info |= CAVE_ICKY;
3506 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3508 int x, y, i, xhsize, yhsize;
3510 /* offsets to middle from corner */
3516 * select region connected to center of cave system
3517 * this gets rid of alot of isolated one-sqaures that
3518 * can make teleport traps instadeaths...
3522 fill_data.c1 = cutoff;
3526 /* features to fill with */
3527 fill_data.feat1 = floor_type[randint0(100)];
3528 fill_data.feat2 = floor_type[randint0(100)];
3529 fill_data.feat3 = floor_type[randint0(100)];
3531 fill_data.info1 = CAVE_FLOOR;
3532 fill_data.info2 = CAVE_FLOOR;
3533 fill_data.info3 = CAVE_FLOOR;
3535 /* number of filled squares */
3536 fill_data.amount = 0;
3538 cave_fill((byte)y0, (byte)x0);
3540 /* if tally too small, try again */
3541 if (fill_data.amount < 10)
3543 /* too small - clear area and try again later */
3544 for (x = 0; x <= xsize; ++x)
3546 for (y = 0; y <= ysize; ++y)
3548 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3549 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3556 * Do boundarys-check to see if they are next to a filled region
3557 * If not then they are set to normal granite
3558 * If so then they are marked as room walls.
3560 for (i = 0; i <= xsize; ++i)
3563 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3565 /* Next to a 'filled' region? - set to be room walls */
3566 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3567 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3568 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3569 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3573 /* set to be normal granite */
3574 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3577 /* bottom boundary */
3578 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3580 /* Next to a 'filled' region? - set to be room walls */
3581 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3582 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3583 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3584 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3588 /* set to be normal granite */
3589 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3592 /* clear the icky flag-don't need it any more */
3593 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3594 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3597 /* Do the left and right boundaries minus the corners (done above) */
3598 for (i = 1; i < ysize; ++i)
3601 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3604 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3605 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3606 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3607 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3612 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3614 /* right boundary */
3615 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3618 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3619 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3620 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3621 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3626 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3629 /* clear icky flag -done with it */
3630 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3631 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3635 /* Do the rest: convert back to the normal format */
3636 for (x = 1; x < xsize; ++x)
3638 for (y = 1; y < ysize; ++y)
3640 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3641 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3643 /* Clear the icky flag in the filled region */
3644 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3646 /* Set appropriate flags */
3647 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3648 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3650 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3651 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3654 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3655 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3658 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3663 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3664 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3669 /* Clear the unconnected regions */
3670 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3671 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3677 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3678 * Extra doors appear inside the system. (Its not very noticeable though.)
3679 * This can be removed by "filling" from the outside in. This allows a separation
3680 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
3681 * The extra effort for what seems to be only a minor thing (even non-existant if you
3682 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3691 * Driver routine to create fractal cave system
3693 static bool build_type9(void)
3695 int grd, roug, cutoff, xsize, ysize, y0, x0;
3697 bool done, light, room;
3699 /* get size: note 'Evenness'*/
3700 xsize = randint1(22) * 2 + 6;
3701 ysize = randint1(15) * 2 + 6;
3703 /* Find and reserve some space in the dungeon. Get center of room. */
3704 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3706 /* Limit to the minimum room size, and retry */
3710 /* Find and reserve some space in the dungeon. Get center of room. */
3711 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3717 return build_type1();
3721 light = done = FALSE;
3724 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3728 /* Note: size must be even or there are rounding problems
3729 * This causes the tunnels not to connect properly to the room */
3731 /* testing values for these parameters feel free to adjust */
3732 grd = 1 << (randint0(4));
3734 /* want average of about 16 */
3735 roug = randint1(8) * randint1(4);
3738 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3739 randint1(xsize / 4) + randint1(ysize / 4);
3742 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3744 /* Convert to normal format + clean up */
3745 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3751 #ifdef ALLOW_CAVERNS_AND_LAKES
3753 * Builds a cave system in the center of the dungeon.
3755 void build_cavern(void)
3757 int grd, roug, cutoff, xsize, ysize, x0, y0;
3760 light = done = FALSE;
3761 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3763 /* Make a cave the size of the dungeon */
3764 xsize = cur_wid - 1;
3765 ysize = cur_hgt - 1;
3769 /* Paranoia: make size even */
3775 /* testing values for these parameters: feel free to adjust */
3776 grd = randint1(4) + 4;
3778 /* want average of about 16 */
3779 roug = randint1(8) * randint1(4);
3785 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3787 /* Convert to normal format+ clean up */
3788 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3792 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3794 int x, y, i, xhsize, yhsize;
3795 int feat1, feat2, feat3;
3797 /* offsets to middle from corner */
3801 /* Get features based on type */
3804 case LAKE_T_LAVA: /* Lava */
3805 feat1 = feat_deep_lava;
3806 feat2 = feat_shallow_lava;
3807 feat3 = floor_type[randint0(100)];
3809 case LAKE_T_WATER: /* Water */
3810 feat1 = feat_deep_water;
3811 feat2 = feat_shallow_water;
3812 feat3 = floor_type[randint0(100)];
3814 case LAKE_T_CAVE: /* Collapsed cave */
3815 feat1 = floor_type[randint0(100)];
3816 feat2 = floor_type[randint0(100)];
3817 feat3 = feat_rubble;
3819 case LAKE_T_EARTH_VAULT: /* Earth vault */
3820 feat1 = feat_rubble;
3821 feat2 = floor_type[randint0(100)];
3822 feat3 = feat_rubble;
3824 case LAKE_T_AIR_VAULT: /* Air vault */
3829 case LAKE_T_WATER_VAULT: /* Water vault */
3830 feat1 = feat_shallow_water;
3831 feat2 = feat_deep_water;
3832 feat3 = feat_shallow_water;
3834 case LAKE_T_FIRE_VAULT: /* Fire Vault */
3835 feat1 = feat_shallow_lava;
3836 feat2 = feat_deep_lava;
3837 feat3 = feat_shallow_lava;
3841 default: return FALSE;
3845 * select region connected to center of cave system
3846 * this gets rid of alot of isolated one-sqaures that
3847 * can make teleport traps instadeaths...
3855 /* features to fill with */
3856 fill_data.feat1 = feat1;
3857 fill_data.feat2 = feat2;
3858 fill_data.feat3 = feat3;
3860 fill_data.info1 = 0;
3861 fill_data.info2 = 0;
3862 fill_data.info3 = 0;
3864 /* number of filled squares */
3865 fill_data.amount = 0;
3867 /* select region connected to center of cave system
3868 * this gets rid of alot of isolated one-sqaures that
3869 * can make teleport traps instadeaths... */
3870 cave_fill((byte)y0, (byte)x0);
3872 /* if tally too small, try again */
3873 if (fill_data.amount < 10)
3875 /* too small -clear area and try again later */
3876 for (x = 0; x <= xsize; ++x)
3878 for (y = 0; y <= ysize; ++y)
3880 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3881 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3887 /* Do boundarys- set to normal granite */
3888 for (i = 0; i <= xsize; ++i)
3890 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3891 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3893 /* clear the icky flag-don't need it any more */
3894 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3895 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3898 /* Do the left and right boundaries minus the corners (done above) */
3900 for (i = 1; i < ysize; ++i)
3902 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3903 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3905 /* clear icky flag -done with it */
3906 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3907 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3911 /* Do the rest: convert back to the normal format */
3912 for (x = 1; x < xsize; ++x)
3914 for (y = 1; y < ysize; ++y)
3916 /* Fill unconnected regions with granite */
3917 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3918 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3919 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3921 /* turn off icky flag (no longer needed.) */
3922 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3925 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
3927 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3937 * makes a lake/collapsed cave system in the center of the dungeon
3939 void build_lake(int type)
3941 int grd, roug, xsize, ysize, x0, y0;
3945 /* paranoia - exit if lake type out of range. */
3946 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
3948 msg_format("Invalid lake type (%d)", type);
3952 /* Make the size of the dungeon */
3953 xsize = cur_wid - 1;
3954 ysize = cur_hgt - 1;
3958 /* Paranoia: make size even */
3964 /* testing values for these parameters: feel free to adjust */
3965 grd = randint1(3) + 4;
3967 /* want average of about 16 */
3968 roug = randint1(8) * randint1(4);
3970 /* Make up size of various componants */
3974 /* Deep water/lava */
3975 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
3977 /* Shallow boundary */
3981 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
3983 /* Convert to normal format+ clean up */
3984 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
3987 #endif /* ALLOW_CAVERNS_AND_LAKES */
3991 * Routine used by the random vault creators to add a door to a location
3992 * Note that range checking has to be done in the calling routine.
3994 * The doors must be INSIDE the allocated region.
3996 static void add_door(int x, int y)
3998 /* Need to have a wall in the center square */
3999 if (!is_outer_bold(y, x)) return;
4006 * where x=don't care
4010 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
4011 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
4014 place_secret_door(y, x);
4016 /* set boundarys so don't get wide doors */
4017 place_solid_bold(y, x - 1);
4018 place_solid_bold(y, x + 1);
4027 * where x = don't care
4030 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4031 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4034 place_secret_door(y, x);
4036 /* set boundarys so don't get wide doors */
4037 place_solid_bold(y - 1, x);
4038 place_solid_bold(y + 1, x);
4044 * Routine that fills the empty areas of a room with treasure and monsters.
4046 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4048 int x, y, cx, cy, size;
4051 /* center of room:*/
4055 /* Rough measure of size of vault= sum of lengths of sides */
4056 size = abs(x2 - x1) + abs(y2 - y1);
4058 for (x = x1; x <= x2; x++)
4060 for (y = y1; y <= y2; y++)
4062 /* Thing added based on distance to center of vault
4063 * Difficulty is 1-easy to 10-hard */
4064 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4066 /* hack- empty square part of the time */
4067 if ((randint1(100) - difficulty * 3) > 50) value = 20;
4069 /* if floor, shallow water and lava */
4070 if (is_floor_bold(y, x) ||
4071 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4073 /* The smaller 'value' is, the better the stuff */
4076 /* Meanest monster + treasure */
4077 monster_level = base_level + 40;
4078 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4079 monster_level = base_level;
4080 object_level = base_level + 20;
4081 place_object(y, x, AM_GOOD);
4082 object_level = base_level;
4086 /* Mean monster +treasure */
4087 monster_level = base_level + 20;
4088 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4089 monster_level = base_level;
4090 object_level = base_level + 10;
4091 place_object(y, x, AM_GOOD);
4092 object_level = base_level;
4094 else if (value < 10)
4097 monster_level = base_level + 9;
4098 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4099 monster_level = base_level;
4101 else if (value < 17)
4103 /* Intentional Blank space */
4106 * (Want some of the vault to be empty
4107 * so have room for group monsters.
4108 * This is used in the hack above to lower
4109 * the density of stuff in the vault.)
4112 else if (value < 23)
4114 /* Object or trap */
4115 if (randint0(100) < 25)
4117 place_object(y, x, 0L);
4124 else if (value < 30)
4126 /* Monster and trap */
4127 monster_level = base_level + 5;
4128 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4129 monster_level = base_level;
4132 else if (value < 40)
4134 /* Monster or object */
4135 if (randint0(100) < 50)
4137 monster_level = base_level + 3;
4138 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4139 monster_level = base_level;
4141 if (randint0(100) < 50)
4143 object_level = base_level + 7;
4144 place_object(y, x, 0L);
4145 object_level = base_level;
4148 else if (value < 50)
4157 /* 20% monster, 40% trap, 20% object, 20% blank space */
4158 if (randint0(100) < 20)
4160 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4162 else if (randint0(100) < 50)
4166 else if (randint0(100) < 50)
4168 place_object(y, x, 0L);
4179 * This function creates a random vault that looks like a collection of bubbles.
4180 * It works by getting a set of coordinates that represent the center of each
4181 * bubble. The entire room is made by seeing which bubble center is closest. If
4182 * two centers are equidistant then the square is a wall, otherwise it is a floor.
4183 * The only exception is for squares really near a center, these are always floor.
4184 * (It looks better than without this check.)
4186 * Note: If two centers are on the same point then this algorithm will create a
4187 * blank bubble filled with walls. - This is prevented from happening.
4189 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4191 #define BUBBLENUM 10 /* number of bubbles */
4193 /* array of center points of bubbles */
4194 coord center[BUBBLENUM];
4197 u16b min1, min2, temp;
4200 /* Offset from center to top left hand corner */
4201 int xhsize = xsize / 2;
4202 int yhsize = ysize / 2;
4205 if (cheat_room) msg_print("Bubble Vault");
4207 /* Allocate center of bubbles */
4208 center[0].x = randint1(xsize - 3) + 1;
4209 center[0].y = randint1(ysize - 3) + 1;
4211 for (i = 1; i < BUBBLENUM; i++)
4215 /* get center and check to see if it is unique */
4220 x = randint1(xsize - 3) + 1;
4221 y = randint1(ysize - 3) + 1;
4223 for (j = 0; j < i; j++)
4225 /* rough test to see if there is an overlap */
4226 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4235 /* Top and bottom boundaries */
4236 for (i = 0; i < xsize; i++)
4238 int x = x0 - xhsize + i;
4240 place_outer_noperm_bold(y0 - yhsize + 0, x);
4241 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4242 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4243 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4246 /* Left and right boundaries */
4247 for (i = 1; i < ysize - 1; i++)
4249 int y = y0 - yhsize + i;
4251 place_outer_noperm_bold(y, x0 - xhsize + 0);
4252 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4253 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4254 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4257 /* Fill in middle with bubbles */
4258 for (x = 1; x < xsize - 1; x++)
4260 for (y = 1; y < ysize - 1; y++)
4262 /* Get distances to two closest centers */
4265 min1 = distance(x, y, center[0].x, center[0].y);
4266 min2 = distance(x, y, center[1].x, center[1].y);
4270 /* swap if in wrong order */
4277 for (i = 2; i < BUBBLENUM; i++)
4279 temp = distance(x, y, center[i].x, center[i].y);
4287 else if (temp < min2)
4289 /* second smallest */
4293 if (((min2 - min1) <= 2) && (!(min1 < 3)))
4295 /* Boundary at midpoint+ not at inner region of bubble */
4296 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4300 /* middle of a bubble */
4301 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4304 /* clean up rest of flags */
4305 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4309 /* Try to add some random doors */
4310 for (i = 0; i < 500; i++)
4312 x = randint1(xsize - 3) - xhsize + x0 + 1;
4313 y = randint1(ysize - 3) - yhsize + y0 + 1;
4317 /* Fill with monsters and treasure, low difficulty */
4318 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4323 * Overlay a rectangular room given its bounds
4324 * This routine is used by build_room_vault
4325 * The area inside the walls is not touched:
4326 * only granite is removed- normal walls stay
4328 static void build_room(int x1, int x2, int y1, int y2)
4330 int x, y, i, xsize, ysize, temp;
4332 /* Check if rectangle has no width */
4333 if ((x1 == x2) || (y1 == y2)) return;
4338 /* Swap boundaries if in wrong order */
4346 /* Swap boundaries if in wrong order */
4352 /* get total widths */
4357 /* Top and bottom boundaries */
4358 for (i = 0; i <= xsize; i++)
4360 place_outer_noperm_bold(y1, x1 + i);
4361 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4362 place_outer_noperm_bold(y2, x1 + i);
4363 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4366 /* Left and right boundaries */
4367 for (i = 1; i < ysize; i++)
4369 place_outer_noperm_bold(y1 + i, x1);
4370 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4371 place_outer_noperm_bold(y1 + i, x2);
4372 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4376 for (x = 1; x < xsize; x++)
4378 for (y = 1; y < ysize; y++)
4380 if (is_extra_bold(y1+y, x1+x))
4382 /* clear the untouched region */
4383 place_floor_bold(y1 + y, x1 + x);
4384 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4388 /* make it a room- but don't touch */
4389 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4396 /* Create a random vault that looks like a collection of overlapping rooms */
4398 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4400 int i, x1, x2, y1, y2, xhsize, yhsize;
4402 /* get offset from center */
4406 if (cheat_room) msg_print("Room Vault");
4408 /* fill area so don't get problems with arena levels */
4409 for (x1 = 0; x1 < xsize; x1++)
4411 int x = x0 - xhsize + x1;
4413 for (y1 = 0; y1 < ysize; y1++)
4415 int y = y0 - yhsize + y1;
4417 place_extra_bold(y, x);
4418 cave[y][x].info &= (~CAVE_ICKY);
4422 /* add ten random rooms */
4423 for (i = 0; i < 10; i++)
4425 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4426 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4427 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4428 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4429 build_room(x1, x2, y1, y2);
4432 /* Add some random doors */
4433 for (i = 0; i < 500; i++)
4435 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4436 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4440 /* Fill with monsters and treasure, high difficulty */
4441 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4445 /* Create a random vault out of a fractal cave */
4446 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4448 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4449 bool done, light, room;
4451 /* round to make sizes even */
4457 if (cheat_room) msg_print("Cave Vault");
4459 light = done = FALSE;
4464 /* testing values for these parameters feel free to adjust */
4465 grd = 1 << randint0(4);
4467 /* want average of about 16 */
4468 roug = randint1(8) * randint1(4);
4471 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4472 randint1(xsize / 4) + randint1(ysize / 4);
4475 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4477 /* Convert to normal format+ clean up */
4478 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4481 /* Set icky flag because is a vault */
4482 for (x = 0; x <= xsize; x++)
4484 for (y = 0; y <= ysize; y++)
4486 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4490 /* Fill with monsters and treasure, low difficulty */
4491 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4495 * maze vault -- rectangular labyrinthine rooms
4497 * maze vault uses two routines:
4498 * r_visit - a recursive routine that builds the labyrinth
4499 * build_maze_vault - a driver routine that calls r_visit and adds
4500 * monsters, traps and treasure
4502 * The labyrinth is built by creating a spanning tree of a graph.
4503 * The graph vertices are at
4504 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4505 * and the edges are the vertical and horizontal nearest neighbors.
4507 * The spanning tree is created by performing a suitably randomized
4508 * depth-first traversal of the graph. The only adjustable parameter
4509 * is the randint0(3) below; it governs the relative density of
4510 * twists and turns in the labyrinth: smaller number, more twists.
4512 static void r_visit(int y1, int x1, int y2, int x2,
4513 int node, int dir, int *visited)
4515 int i, j, m, n, temp, x, y, adj[4];
4517 /* dimensions of vertex array */
4518 m = (x2 - x1) / 2 + 1;
4519 n = (y2 - y1) / 2 + 1;
4521 /* mark node visited and set it to a floor */
4523 x = 2 * (node % m) + x1;
4524 y = 2 * (node / m) + y1;
4525 place_floor_bold(y, x);
4527 /* setup order of adjacent node visits */
4530 /* pick a random ordering */
4531 for (i = 0; i < 4; i++)
4533 for (i = 0; i < 4; i++)
4544 /* pick a random ordering with dir first */
4546 for (i = 1; i < 4; i++)
4548 for (i = 1; i < 4; i++)
4550 j = 1 + randint0(3);
4557 for (i = 0; i < 4; i++)
4562 /* (0,+) - check for bottom boundary */
4563 if ((node / m < n - 1) && (visited[node + m] == 0))
4565 place_floor_bold(y + 1, x);
4566 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4570 /* (0,-) - check for top boundary */
4571 if ((node / m > 0) && (visited[node - m] == 0))
4573 place_floor_bold(y - 1, x);
4574 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4578 /* (+,0) - check for right boundary */
4579 if ((node % m < m - 1) && (visited[node + 1] == 0))
4581 place_floor_bold(y, x + 1);
4582 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4586 /* (-,0) - check for left boundary */
4587 if ((node % m > 0) && (visited[node - 1] == 0))
4589 place_floor_bold(y, x - 1);
4590 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4597 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4601 int m, n, num_vertices, *visited;
4606 if (cheat_room && is_vault) msg_print("Maze Vault");
4608 /* Choose lite or dark */
4609 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4611 /* Pick a random room size - randomized by calling routine */
4620 /* generate the room */
4621 for (y = y1 - 1; y <= y2 + 1; y++)
4623 for (x = x1 - 1; x <= x2 + 1; x++)
4625 c_ptr = &cave[y][x];
4626 c_ptr->info |= CAVE_ROOM;
4627 if (is_vault) c_ptr->info |= CAVE_ICKY;
4628 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4630 place_outer_grid(c_ptr);
4634 place_extra_grid(c_ptr);
4638 place_inner_grid(c_ptr);
4640 if (light) c_ptr->info |= (CAVE_GLOW);
4644 /* dimensions of vertex array */
4647 num_vertices = m * n;
4649 /* initialize array of visited vertices */
4650 C_MAKE(visited, num_vertices, int);
4652 /* traverse the graph to create a spaning tree, pick a random root */
4653 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4655 /* Fill with monsters and treasure, low difficulty */
4656 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4658 C_KILL(visited, num_vertices, int);
4662 /* Build a "mini" checkerboard vault
4664 * This is done by making a permanent wall maze and setting
4665 * the diagonal sqaures of the checker board to be granite.
4666 * The vault has two entrances on opposite sides to guarantee
4667 * a way to get in even if the vault abuts a side of the dungeon.
4669 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4672 int y1, x1, y2, x2, y, x, total;
4673 int m, n, num_vertices;
4676 if (cheat_room) msg_print("Mini Checker Board Vault");
4678 /* Pick a random room size */
4688 /* generate the room */
4689 for (x = x1 - 2; x <= x2 + 2; x++)
4691 if (!in_bounds(y1-2,x)) break;
4693 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4695 place_outer_noperm_bold(y1-2, x);
4698 for (x = x1 - 2; x <= x2 + 2; x++)
4700 if (!in_bounds(y2+2,x)) break;
4702 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4704 place_outer_noperm_bold(y2+2, x);
4707 for (y = y1 - 2; y <= y2 + 2; y++)
4709 if (!in_bounds(y,x1-2)) break;
4711 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4713 place_outer_noperm_bold(y, x1-2);
4716 for (y = y1 - 2; y <= y2 + 2; y++)
4718 if (!in_bounds(y,x2+2)) break;
4720 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4722 place_outer_noperm_bold(y, x2+2);
4725 for (y = y1 - 1; y <= y2 + 1; y++)
4727 for (x = x1 - 1; x <= x2 + 1; x++)
4729 cave_type *c_ptr = &cave[y][x];
4731 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4733 /* Permanent walls */
4734 place_inner_perm_grid(c_ptr);
4739 /* dimensions of vertex array */
4742 num_vertices = m * n;
4744 /* initialize array of visited vertices */
4745 C_MAKE(visited, num_vertices, int);
4747 /* traverse the graph to create a spannng tree, pick a random root */
4748 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4750 /* Make it look like a checker board vault */
4751 for (x = x1; x <= x2; x++)
4753 for (y = y1; y <= y2; y++)
4755 total = x - x1 + y - y1;
4756 /* If total is odd- and is a floor then make a wall */
4757 if ((total % 2 == 1) && is_floor_bold(y, x))
4759 place_inner_bold(y, x);
4764 /* Make a couple of entrances */
4767 /* left and right */
4768 y = randint1(dy) + dy / 2;
4769 place_inner_bold(y1 + y, x1 - 1);
4770 place_inner_bold(y1 + y, x2 + 1);
4774 /* top and bottom */
4775 x = randint1(dx) + dx / 2;
4776 place_inner_bold(y1 - 1, x1 + x);
4777 place_inner_bold(y2 + 1, x1 + x);
4780 /* Fill with monsters and treasure, highest difficulty */
4781 fill_treasure(x1, x2, y1, y2, 10);
4783 C_KILL(visited, num_vertices, int);
4787 /* Build a town/ castle by using a recursive algorithm.
4788 * Basically divide each region in a probalistic way to create
4789 * smaller regions. When the regions get too small stop.
4791 * The power variable is a measure of how well defended a region is.
4792 * This alters the possible choices.
4794 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4800 /* Temp variables */
4806 if ((power < 3) && (xsize > 12) && (ysize > 12))
4808 /* Need outside wall +keep */
4815 /* Make rooms + subdivide */
4816 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4822 choice = randint1(2) + 1;
4827 /* Mostly subdivide */
4828 choice = randint1(3) + 1;
4832 /* Based on the choice made above, do something */
4840 /* top and bottom */
4841 for (x = x1; x <= x2; x++)
4843 place_outer_bold(y1, x);
4844 place_outer_bold(y2, x);
4847 /* left and right */
4848 for (y = y1 + 1; y < y2; y++)
4850 place_outer_bold(y, x1);
4851 place_outer_bold(y, x2);
4854 /* Make a couple of entrances */
4857 /* left and right */
4858 y = randint1(ysize) + y1;
4859 place_floor_bold(y, x1);
4860 place_floor_bold(y, x2);
4864 /* top and bottom */
4865 x = randint1(xsize) + x1;
4866 place_floor_bold(y1, x);
4867 place_floor_bold(y2, x);
4870 /* Select size of keep */
4871 t1 = randint1(ysize / 3) + y1;
4872 t2 = y2 - randint1(ysize / 3);
4873 t3 = randint1(xsize / 3) + x1;
4874 t4 = x2 - randint1(xsize / 3);
4876 /* Do outside areas */
4878 /* Above and below keep */
4879 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4880 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4882 /* Left and right of keep */
4883 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4884 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4886 /* Make the keep itself: */
4899 /* Try to build a room */
4900 if ((xsize < 3) || (ysize < 3))
4902 for (y = y1; y < y2; y++)
4904 for (x = x1; x < x2; x++)
4906 place_inner_bold(y, x);
4914 /* Make outside walls */
4915 /* top and bottom */
4916 for (x = x1 + 1; x <= x2 - 1; x++)
4918 place_inner_bold(y1 + 1, x);
4919 place_inner_bold(y2 - 1, x);
4922 /* left and right */
4923 for (y = y1 + 1; y <= y2 - 1; y++)
4925 place_inner_bold(y, x1 + 1);
4926 place_inner_bold(y, x2 - 1);
4930 y = randint1(ysize - 3) + y1 + 1;
4935 place_floor_bold(y, x1 + 1);
4940 place_floor_bold(y, x2 - 1);
4943 /* Build the room */
4944 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4949 /* Try and divide vertically */
4953 for (y = y1; y < y2; y++)
4955 for (x = x1; x < x2; x++)
4957 place_inner_bold(y, x);
4963 t1 = randint1(xsize - 2) + x1 + 1;
4964 build_recursive_room(x1, y1, t1, y2, power - 2);
4965 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
4970 /* Try and divide horizontally */
4974 for (y = y1; y < y2; y++)
4976 for (x = x1; x < x2; x++)
4978 place_inner_bold(y, x);
4984 t1 = randint1(ysize - 2) + y1 + 1;
4985 build_recursive_room(x1, y1, x2, t1, power - 2);
4986 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
4993 /* Build a castle */
4995 /* Driver routine: clear the region and call the recursive
4998 *This makes a vault that looks like a castle/ city in the dungeon.
5000 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
5006 /* Pick a random room size */
5015 if (cheat_room) msg_print("Castle Vault");
5017 /* generate the room */
5018 for (y = y1 - 1; y <= y2 + 1; y++)
5020 for (x = x1 - 1; x <= x2 + 1; x++)
5022 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5023 /* Make everything a floor */
5024 place_floor_bold(y, x);
5028 /* Make the castle */
5029 build_recursive_room(x1, y1, x2, y2, randint1(5));
5031 /* Fill with monsters and treasure, low difficulty */
5032 fill_treasure(x1, x2, y1, y2, randint1(3));
5037 * Add outer wall to a floored region
5038 * Note: no range checking is done so must be inside dungeon
5039 * This routine also stomps on doors
5041 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5044 feature_type *f_ptr;
5047 if (!in_bounds(y, x)) return;
5049 c_ptr = &cave[y][x];
5051 /* hack- check to see if square has been visited before
5052 * if so, then exit (use room flag to do this) */
5053 if (c_ptr->info & CAVE_ROOM) return;
5056 c_ptr->info |= CAVE_ROOM;
5058 f_ptr = &f_info[c_ptr->feat];
5060 if (is_floor_bold(y, x))
5062 for (i = -1; i <= 1; i++)
5064 for (j = -1; j <= 1; j++)
5066 if ((x + i >= x1) && (x + i <= x2) &&
5067 (y + j >= y1) && (y + j <= y2))
5069 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5070 if (light) c_ptr->info |= CAVE_GLOW;
5075 else if (is_extra_bold(y, x))
5077 /* Set bounding walls */
5078 place_outer_bold(y, x);
5079 if (light) c_ptr->info |= CAVE_GLOW;
5081 else if (permanent_wall(f_ptr))
5083 /* Set bounding walls */
5084 if (light) c_ptr->info |= CAVE_GLOW;
5090 * Hacked distance formula - gives the 'wrong' answer.
5091 * Used to build crypts
5093 static int dist2(int x1, int y1, int x2, int y2,
5094 int h1, int h2, int h3, int h4)
5100 /* Basically this works by taking the normal pythagorean formula
5101 * and using an expansion to express this in a way without the
5102 * square root. This approximate formula is then perturbed to give
5103 * the distorted results. (I found this by making a mistake when I was
5104 * trying to fix the circular rooms.)
5107 /* h1-h4 are constants that describe the metric */
5108 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5109 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5110 return (((dx + dy) * 128) / 181 +
5111 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5112 /* 128/181 is approx. 1/sqrt(2) */
5117 * Build target vault.
5118 * This is made by two concentric "crypts" with perpendicular
5119 * walls creating the cross-hairs.
5121 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5125 /* Make a random metric */
5127 h1 = randint1(32) - 16;
5130 h4 = randint1(32) - 16;
5132 if (cheat_room) msg_print("Target Vault");
5134 /* work out outer radius */
5145 for (x = x0 - rad; x <= x0 + rad; x++)
5147 for (y = y0 - rad; y <= y0 + rad; y++)
5149 /* clear room flag */
5150 cave[y][x].info &= ~(CAVE_ROOM);
5152 /* Vault - so is "icky" */
5153 cave[y][x].info |= CAVE_ICKY;
5155 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5157 /* inside- so is floor */
5158 place_floor_bold(y, x);
5162 /* make granite outside so arena works */
5163 place_extra_bold(y, x);
5166 /* proper boundary for arena */
5167 if (((y + rad) == y0) || ((y - rad) == y0) ||
5168 ((x + rad) == x0) || ((x - rad) == x0))
5170 place_extra_bold(y, x);
5175 /* Find visible outer walls and set to be FEAT_OUTER */
5176 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5177 x0 + rad + 1, y0 + rad + 1);
5179 /* Add inner wall */
5180 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5182 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5184 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5186 /* Make an internal wall */
5187 place_inner_bold(y, x);
5192 /* Add perpendicular walls */
5193 for (x = x0 - rad; x <= x0 + rad; x++)
5195 place_inner_bold(y0, x);
5198 for (y = y0 - rad; y <= y0 + rad; y++)
5200 place_inner_bold(y, x0);
5203 /* Make inner vault */
5204 for (y = y0 - 1; y <= y0 + 1; y++)
5206 place_inner_bold(y, x0 - 1);
5207 place_inner_bold(y, x0 + 1);
5209 for (x = x0 - 1; x <= x0 + 1; x++)
5211 place_inner_bold(y0 - 1, x);
5212 place_inner_bold(y0 + 1, x);
5215 place_floor_bold(y0, x0);
5218 /* Add doors to vault */
5219 /* get two distances so can place doors relative to centre */
5220 x = (rad - 2) / 4 + 1;
5223 add_door(x0 + x, y0);
5224 add_door(x0 + y, y0);
5225 add_door(x0 - x, y0);
5226 add_door(x0 - y, y0);
5227 add_door(x0, y0 + x);
5228 add_door(x0, y0 + y);
5229 add_door(x0, y0 - x);
5230 add_door(x0, y0 - y);
5232 /* Fill with stuff - medium difficulty */
5233 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5237 #ifdef ALLOW_CAVERNS_AND_LAKES
5239 * This routine uses a modified version of the lake code to make a
5240 * distribution of some terrain type over the vault. This type
5241 * depends on the dungeon depth.
5243 * Miniture rooms are then scattered across the vault.
5245 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5250 int xsize, ysize, xhsize, yhsize, x, y, i;
5254 if (cheat_room) msg_print("Elemental Vault");
5256 /* round to make sizes even */
5264 /* Earth vault (Rubble) */
5265 type = LAKE_T_EARTH_VAULT;
5267 else if (dun_level < 50)
5269 /* Air vault (Trees) */
5270 type = LAKE_T_AIR_VAULT;
5272 else if (dun_level < 75)
5274 /* Water vault (shallow water) */
5275 type = LAKE_T_WATER_VAULT;
5279 /* Fire vault (shallow lava) */
5280 type = LAKE_T_FIRE_VAULT;
5285 /* testing values for these parameters: feel free to adjust */
5286 grd = 1 << (randint0(3));
5288 /* want average of about 16 */
5289 roug = randint1(8) * randint1(4);
5291 /* Make up size of various componants */
5295 /* Deep water/lava */
5296 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5298 /* Shallow boundary */
5302 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5304 /* Convert to normal format+ clean up */
5305 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5308 /* Set icky flag because is a vault */
5309 for (x = 0; x <= xsize; x++)
5311 for (y = 0; y <= ysize; y++)
5313 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5317 /* make a few rooms in the vault */
5318 for (i = 1; i <= (xsize * ysize) / 50; i++)
5320 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5321 y0 + randint0(ysize - 4) - ysize / 2 + 2);
5324 /* Fill with monsters and treasure, low difficulty */
5325 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5326 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5328 #endif /* ALLOW_CAVERNS_AND_LAKES */
5334 static bool build_type10(void)
5336 int y0, x0, xsize, ysize, vtype;
5339 /* big enough to look good, small enough to be fairly common. */
5340 xsize = randint1(22) + 22;
5341 ysize = randint1(11) + 11;
5343 /* Find and reserve some space in the dungeon. Get center of room. */
5344 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5346 /* Select type of vault */
5347 #ifdef ALLOW_CAVERNS_AND_LAKES
5350 vtype = randint1(15);
5352 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5353 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
5354 #else /* ALLOW_CAVERNS_AND_LAKES */
5357 vtype = randint1(7);
5359 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5360 ((vtype == 1) || (vtype == 3)));
5361 #endif /* ALLOW_CAVERNS_AND_LAKES */
5365 /* Build an appropriate room */
5366 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
5367 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5368 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5369 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5370 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5371 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5372 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5373 #ifdef ALLOW_CAVERNS_AND_LAKES
5374 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5375 #endif /* ALLOW_CAVERNS_AND_LAKES */
5376 /* I know how to add a few more... give me some time. */
5379 default: return FALSE;
5387 * Build an vertical oval room.
5388 * For every grid in the possible square, check the distance.
5389 * If it's less than the radius, make it a room square.
5391 * When done fill from the inside to find the walls,
5393 static bool build_type11(void)
5395 int rad, x, y, x0, y0;
5398 /* Occasional light */
5399 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5403 /* Find and reserve some space in the dungeon. Get center of room. */
5404 if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5406 /* Make circular floor */
5407 for (x = x0 - rad; x <= x0 + rad; x++)
5409 for (y = y0 - rad; y <= y0 + rad; y++)
5411 if (distance(y0, x0, y, x) <= rad - 1)
5413 /* inside- so is floor */
5414 place_floor_bold(y, x);
5416 else if (distance(y0, x0, y, x) <= rad + 1)
5418 /* make granite outside so arena works */
5419 place_extra_bold(y, x);
5424 /* Find visible outer walls and set to be FEAT_OUTER */
5425 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5433 * For every grid in the possible square, check the (fake) 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_type12(void)
5440 int rad, x, y, x0, y0;
5442 bool emptyflag = TRUE;
5444 /* Make a random metric */
5446 h1 = randint1(32) - 16;
5449 h4 = randint1(32) - 16;
5451 /* Occasional light */
5452 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5456 /* Find and reserve some space in the dungeon. Get center of room. */
5457 if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5460 for (x = x0 - rad; x <= x0 + rad; x++)
5462 for (y = y0 - rad; y <= y0 + rad; y++)
5464 /* clear room flag */
5465 cave[y][x].info &= ~(CAVE_ROOM);
5467 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5469 /* inside - so is floor */
5470 place_floor_bold(y, x);
5472 else if (distance(y0, x0, y, x) < 3)
5474 place_floor_bold(y, x);
5478 /* make granite outside so arena works */
5479 place_extra_bold(y, x);
5482 /* proper boundary for arena */
5483 if (((y + rad) == y0) || ((y - rad) == y0) ||
5484 ((x + rad) == x0) || ((x - rad) == x0))
5486 place_extra_bold(y, x);
5491 /* Find visible outer walls and set to be FEAT_OUTER */
5492 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5493 x0 + rad + 1, y0 + rad + 1);
5495 /* Check to see if there is room for an inner vault */
5496 for (x = x0 - 2; x <= x0 + 2; x++)
5498 for (y = y0 - 2; y <= y0 + 2; y++)
5500 if (!is_floor_bold(y, x))
5502 /* Wall in the way */
5508 if (emptyflag && one_in_(2))
5510 /* Build the vault */
5511 build_small_room(x0, y0);
5513 /* Place a treasure in the vault */
5514 place_object(y0, x0, 0L);
5516 /* Let's guard the treasure well */
5517 vault_monsters(y0, x0, randint0(2) + 3);
5519 /* Traps naturally */
5520 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5528 * Helper function for "trapped monster pit"
5530 static bool vault_aux_trapped_pit(int r_idx)
5532 monster_race *r_ptr = &r_info[r_idx];
5534 /* Validate the monster */
5535 if (!vault_monster_okay(r_idx)) return (FALSE);
5537 /* No wall passing monster */
5538 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5546 * Type 12 -- Trapped monster pits
5548 * A trapped monster pit is a "big" room with a straight corridor in
5549 * which wall opening traps are placed, and with two "inner" rooms
5550 * containing a "collection" of monsters of a given type organized in
5553 * The trapped monster pit appears as shown below, where the actual
5554 * monsters in each location depend on the type of the pit
5556 * #########################
5558 * ####################### #
5559 * #####001123454321100### #
5560 * ###0012234567654322100# #
5561 * ####################### #
5563 * # #######################
5564 * # #0012234567654322100###
5565 * # ###001123454321100#####
5566 * # #######################
5568 * #########################
5570 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5571 * to request 16 "appropriate" monsters, sorting them by level, and using
5572 * the "even" entries in this sorted list for the contents of the pit.
5574 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5575 * which is handled by requiring a specific "breath" attack for all of the
5576 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5577 * be present in many of the dragon pits, if they have the proper breath.
5579 * Note the use of the "get_mon_num_prep()" function, and the special
5580 * "get_mon_num_hook()" restriction function, to prepare the "monster
5581 * allocation table" in such a way as to optimize the selection of
5582 * "appropriate" non-unique monsters for the pit.
5584 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5585 * the pit will be empty.
5587 * Note that "monster pits" will never contain "unique" monsters.
5589 static bool build_type13(void)
5591 static int placing[][3] = {
5592 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5593 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5594 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5595 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5596 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5597 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5598 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5599 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5600 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5601 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5602 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5603 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5604 {-2, -4, 3}, {-3, -2, 3},
5605 {+2, -4, 3}, {+3, -2, 3},
5606 {-2, +4, 3}, {-3, +2, 3},
5607 {+2, +4, 3}, {+3, +2, 3},
5608 {-2, -3, 4}, {-3, -1, 4},
5609 {+2, -3, 4}, {+3, -1, 4},
5610 {-2, +3, 4}, {-3, +1, 4},
5611 {+2, +3, 4}, {+3, +1, 4},
5612 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5613 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5614 {-2, -1, 6}, {-2, +1, 6},
5615 {+2, -1, 6}, {+2, +1, 6},
5616 {-2, 0, 7}, {+2, 0, 7},
5620 int y, x, y1, x1, y2, x2, xval, yval;
5629 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5630 vault_aux_type *n_ptr;
5632 /* Only in Angband */
5633 if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5635 /* No type available */
5636 if (cur_pit_type < 0) return FALSE;
5638 n_ptr = &pit_types[cur_pit_type];
5640 /* Process a preparation function if necessary */
5641 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5643 /* Prepare allocation table */
5644 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5646 align.sub_align = SUB_ALIGN_NEUTRAL;
5648 /* Pick some monster types */
5649 for (i = 0; i < 16; i++)
5651 int r_idx = 0, attempts = 100;
5652 monster_race *r_ptr = NULL;
5656 /* Get a (hard) monster type */
5657 r_idx = get_mon_num(dun_level + 0);
5658 r_ptr = &r_info[r_idx];
5660 /* Decline incorrect alignment */
5661 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5663 /* Accept this monster */
5667 /* Notice failure */
5668 if (!r_idx || !attempts) return FALSE;
5670 /* Note the alignment */
5671 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5672 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5677 /* Find and reserve some space in the dungeon. Get center of room. */
5678 if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5686 /* Fill with inner walls */
5687 for (y = y1 - 1; y <= y2 + 1; y++)
5689 for (x = x1 - 1; x <= x2 + 1; x++)
5691 c_ptr = &cave[y][x];
5692 place_inner_grid(c_ptr);
5693 c_ptr->info |= (CAVE_ROOM);
5697 /* Place the floor area 1 */
5698 for (x = x1 + 3; x <= x2 - 3; x++)
5700 c_ptr = &cave[yval-2][x];
5701 place_floor_grid(c_ptr);
5702 add_cave_info(yval-2, x, CAVE_ICKY);
5704 c_ptr = &cave[yval+2][x];
5705 place_floor_grid(c_ptr);
5706 add_cave_info(yval+2, x, CAVE_ICKY);
5709 /* Place the floor area 2 */
5710 for (x = x1 + 5; x <= x2 - 5; x++)
5712 c_ptr = &cave[yval-3][x];
5713 place_floor_grid(c_ptr);
5714 add_cave_info(yval-3, x, CAVE_ICKY);
5716 c_ptr = &cave[yval+3][x];
5717 place_floor_grid(c_ptr);
5718 add_cave_info(yval+3, x, CAVE_ICKY);
5722 for (x = x1; x <= x2; x++)
5724 c_ptr = &cave[yval][x];
5725 place_floor_grid(c_ptr);
5726 c_ptr = &cave[y1][x];
5727 place_floor_grid(c_ptr);
5728 c_ptr = &cave[y2][x];
5729 place_floor_grid(c_ptr);
5732 /* Place the outer walls */
5733 for (y = y1 - 1; y <= y2 + 1; y++)
5735 c_ptr = &cave[y][x1 - 1];
5736 place_outer_grid(c_ptr);
5737 c_ptr = &cave[y][x2 + 1];
5738 place_outer_grid(c_ptr);
5740 for (x = x1 - 1; x <= x2 + 1; x++)
5742 c_ptr = &cave[y1 - 1][x];
5743 place_outer_grid(c_ptr);
5744 c_ptr = &cave[y2 + 1][x];
5745 place_outer_grid(c_ptr);
5748 /* Random corridor */
5751 for (y = y1; y <= yval; y++)
5753 place_floor_bold(y, x2);
5754 place_solid_bold(y, x1-1);
5756 for (y = yval; y <= y2 + 1; y++)
5758 place_floor_bold(y, x1);
5759 place_solid_bold(y, x2+1);
5764 for (y = yval; y <= y2 + 1; y++)
5766 place_floor_bold(y, x1);
5767 place_solid_bold(y, x2+1);
5769 for (y = y1; y <= yval; y++)
5771 place_floor_bold(y, x2);
5772 place_solid_bold(y, x1-1);
5776 /* Place the wall open trap */
5777 cave[yval][xval].mimic = cave[yval][xval].feat;
5778 cave[yval][xval].feat = feat_trap_open;
5780 /* Sort the entries */
5781 for (i = 0; i < 16 - 1; i++)
5783 /* Sort the entries */
5784 for (j = 0; j < 16 - 1; j++)
5789 int p1 = r_info[what[i1]].level;
5790 int p2 = r_info[what[i2]].level;
5796 what[i1] = what[i2];
5807 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5809 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5813 /* Select the entries */
5814 for (i = 0; i < 8; i++)
5816 /* Every other entry */
5817 what[i] = what[i * 2];
5822 msg_print(r_name + r_info[what[i]].name);
5826 for (i = 0; placing[i][2] >= 0; i++)
5828 y = yval + placing[i][0];
5829 x = xval + placing[i][1];
5830 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5838 * Type 14 -- trapped rooms
5840 * A special trap is placed at center of the room
5842 static bool build_type14(void)
5844 int y, x, y2, x2, yval, xval;
5845 int y1, x1, xsize, ysize;
5852 /* Pick a room size */
5858 xsize = x1 + x2 + 1;
5859 ysize = y1 + y2 + 1;
5861 /* Find and reserve some space in the dungeon. Get center of room. */
5862 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5864 /* Choose lite or dark */
5865 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5868 /* Get corner values */
5869 y1 = yval - ysize / 2;
5870 x1 = xval - xsize / 2;
5871 y2 = yval + (ysize - 1) / 2;
5872 x2 = xval + (xsize - 1) / 2;
5875 /* Place a full floor under the room */
5876 for (y = y1 - 1; y <= y2 + 1; y++)
5878 for (x = x1 - 1; x <= x2 + 1; x++)
5880 c_ptr = &cave[y][x];
5881 place_floor_grid(c_ptr);
5882 c_ptr->info |= (CAVE_ROOM);
5883 if (light) c_ptr->info |= (CAVE_GLOW);
5887 /* Walls around the room */
5888 for (y = y1 - 1; y <= y2 + 1; y++)
5890 c_ptr = &cave[y][x1 - 1];
5891 place_outer_grid(c_ptr);
5892 c_ptr = &cave[y][x2 + 1];
5893 place_outer_grid(c_ptr);
5895 for (x = x1 - 1; x <= x2 + 1; x++)
5897 c_ptr = &cave[y1 - 1][x];
5898 place_outer_grid(c_ptr);
5899 c_ptr = &cave[y2 + 1][x];
5900 place_outer_grid(c_ptr);
5903 if (dun_level < 30 + randint1(30))
5904 trap = feat_trap_piranha;
5906 trap = feat_trap_armageddon;
5908 /* Place a special trap */
5909 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
5910 c_ptr->mimic = c_ptr->feat;
5917 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5919 msg_format("Room of %s", f_name + f_info[trap].name);
5928 * Attempt to build a room of the given type at the given block
5930 * Note that we restrict the number of "crowded" rooms to reduce
5931 * the chance of overflowing the monster list during level creation.
5933 static bool room_build(int typ)
5938 /* Build an appropriate room */
5939 case ROOM_T_NORMAL: return build_type1();
5940 case ROOM_T_OVERLAP: return build_type2();
5941 case ROOM_T_CROSS: return build_type3();
5942 case ROOM_T_INNER_FEAT: return build_type4();
5943 case ROOM_T_NEST: return build_type5();
5944 case ROOM_T_PIT: return build_type6();
5945 case ROOM_T_LESSER_VAULT: return build_type7();
5946 case ROOM_T_GREATER_VAULT: return build_type8();
5947 case ROOM_T_FRACAVE: return build_type9();
5948 case ROOM_T_RANDOM_VAULT: return build_type10();
5949 case ROOM_T_OVAL: return build_type11();
5950 case ROOM_T_CRYPT: return build_type12();
5951 case ROOM_T_TRAP_PIT: return build_type13();
5952 case ROOM_T_TRAP: return build_type14();
5960 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
5963 * [from SAngband (originally from OAngband)]
5965 * Generate rooms in dungeon. Build bigger rooms at first.
5967 bool generate_rooms(void)
5973 int prob_list[ROOM_T_MAX];
5974 int rooms_built = 0;
5975 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
5976 int level_index = MIN(10, div_round(dun_level, 10));
5978 /* Number of each type of room on this level */
5979 s16b room_num[ROOM_T_MAX];
5981 /* Limit number of rooms */
5982 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
5984 /* Assume normal cave */
5985 room_info_type *room_info_ptr = room_info_normal;
5988 * Initialize probability list.
5990 for (i = 0; i < ROOM_T_MAX; i++)
5992 /* No rooms allowed above their minimum depth. */
5993 if (dun_level < room_info_ptr[i].min_level)
5999 prob_list[i] = room_info_ptr[i].prob[level_index];
6004 * XXX -- Various dungeon types and options.
6007 /* Ironman sees only Greater Vaults */
6008 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
6010 for (i = 0; i < ROOM_T_MAX; i++)
6012 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6013 else prob_list[i] = 0;
6017 /* Forbidden vaults */
6018 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6020 prob_list[ROOM_T_LESSER_VAULT] = 0;
6021 prob_list[ROOM_T_GREATER_VAULT] = 0;
6022 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6026 /* NO_CAVE dungeon (Castle)*/
6027 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6029 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6030 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6031 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6034 /* CAVE dungeon (Orc cave etc.) */
6035 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6037 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6040 /* No caves when a (random) cavern exists: they look bad */
6041 else if (dun->cavern || dun->empty_level)
6043 prob_list[ROOM_T_FRACAVE] = 0;
6048 * Initialize number of rooms,
6049 * And calcurate total probability.
6051 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6054 total_prob += prob_list[i];
6058 * Prepare the number of rooms, of all types, we should build
6061 for (i = dun_rooms; i > 0; i--)
6064 int rand = randint0(total_prob);
6066 /* Get room_type randomly */
6067 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6069 if (rand < prob_list[room_type]) break;
6070 else rand -= prob_list[room_type];
6074 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6076 /* Increase the number of rooms of that type we should build. */
6077 room_num[room_type]++;
6083 case ROOM_T_LESSER_VAULT:
6084 case ROOM_T_TRAP_PIT:
6090 case ROOM_T_GREATER_VAULT:
6091 case ROOM_T_RANDOM_VAULT:
6100 * Build each type of room one by one until we cannot build any more.
6101 * [from SAngband (originally from OAngband)]
6105 /* Assume no remaining rooms */
6108 for (i = 0; i < ROOM_T_MAX; i++)
6110 /* What type of room are we building now? */
6111 int room_type = room_build_order[i];
6113 /* Go next if none available */
6114 if (!room_num[room_type]) continue;
6116 /* Use up one unit */
6117 room_num[room_type]--;
6119 /* Build the room. */
6120 if (room_build(room_type))
6122 /* Increase the room built count. */
6125 /* Mark as there was some remaining rooms */
6132 case ROOM_T_TRAP_PIT:
6134 /* Avoid too many monsters */
6137 room_num[ROOM_T_PIT] = 0;
6138 room_num[ROOM_T_NEST] = 0;
6139 room_num[ROOM_T_TRAP_PIT] = 0;
6145 /* End loop if no room remain */
6149 if (rooms_built < 1) return FALSE;
6154 msg_format("Éô²°¿ô: %d", rooms_built);
6156 msg_format("Number of Rooms: %d", rooms_built);