3 * Purpose: make rooms. Used by generate.c when creating dungeons.
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
9 * This software may be copied and distributed for educational, research,
10 * and not for profit purposes provided that this copyright and statement
11 * are included in all such copies. Other copyrights may also apply.
21 * [from SAngband (originally from OAngband)]
23 * Table of values that control how many times each type of room will
24 * appear. Each type of room has its own row, and each column
25 * corresponds to dungeon levels 0, 10, 20, and so on. The final
26 * value is the minimum depth the room can appear at. -LM-
28 * Level 101 and below use the values for level 100.
30 * Rooms with lots of monsters or loot may not be generated if the
31 * object or monster lists are already nearly full. Rooms will not
32 * appear above their minimum depth. Tiny levels will not have space
33 * for all the rooms you ask for.
35 static room_info_type room_info_normal[ROOM_T_MAX] =
38 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
40 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
41 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
42 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
43 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
44 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
45 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
46 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
47 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
48 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
49 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
50 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
51 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
52 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
53 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
57 /* Build rooms in descending order of difficulty. */
58 static byte room_build_order[ROOM_T_MAX] = {
76 static void place_locked_door(int y, int x)
78 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
80 place_floor_bold(y, x);
84 set_cave_feat(y, x, FEAT_DOOR_HEAD+randint1(7));
85 cave[y][x].info &= ~(CAVE_FLOOR);
89 static void place_secret_door(int y, int x)
91 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
93 place_floor_bold(y, x);
97 cave_type *c_ptr = &cave[y][x];
99 /* Create secret door */
100 place_closed_door(y, x);
102 /* Hide by inner wall because this is used in rooms only */
103 c_ptr->mimic = feat_wall_inner;
105 /* Floor type terrain cannot hide a door */
106 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
108 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
110 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
115 c_ptr->info &= ~(CAVE_FLOOR);
120 * This funtion makes a very small room centred at (x0, y0)
121 * This is used in crypts, and random elemental vaults.
123 * Note - this should be used only on allocated regions
124 * within another room.
126 static void build_small_room(int x0, int y0)
130 for (y = y0 - 1; y <= y0 + 1; y++)
132 place_inner_bold(y, x0 - 1);
133 place_inner_bold(y, x0 + 1);
136 for (x = x0 - 1; x <= x0 + 1; x++)
138 place_inner_bold(y0 - 1, x);
139 place_inner_bold(y0 + 1, x);
142 /* Place a secret door on one side */
145 case 0: place_secret_door(y0, x0 - 1); break;
146 case 1: place_secret_door(y0, x0 + 1); break;
147 case 2: place_secret_door(y0 - 1, x0); break;
148 case 3: place_secret_door(y0 + 1, x0); break;
151 /* Clear mimic type */
152 cave[y0][x0].mimic = 0;
154 /* Add inner open space */
155 place_floor_bold(y0, x0);
160 * This function tunnels around a room if
161 * it will cut off part of a cave system.
163 static void check_room_boundary(int x1, int y1, int x2, int y2)
166 bool old_is_floor, new_is_floor;
172 old_is_floor = get_is_floor(x1 - 1, y1);
175 * Count the number of floor-wall boundaries around the room
176 * Note: diagonal squares are ignored since the player can move diagonally
177 * to bypass these if needed.
180 /* Above the top boundary */
181 for (x = x1; x <= x2; x++)
183 new_is_floor = get_is_floor(x, y1 - 1);
185 /* Increment counter if they are different */
186 if (new_is_floor != old_is_floor) count++;
188 old_is_floor = new_is_floor;
192 for (y = y1; y <= y2; y++)
194 new_is_floor = get_is_floor(x2 + 1, y);
196 /* increment counter if they are different */
197 if (new_is_floor != old_is_floor) count++;
199 old_is_floor = new_is_floor;
202 /* Bottom boundary */
203 for (x = x2; x >= x1; x--)
205 new_is_floor = get_is_floor(x, y2 + 1);
207 /* increment counter if they are different */
208 if (new_is_floor != old_is_floor) count++;
210 old_is_floor = new_is_floor;
214 for (y = y2; y >= y1; y--)
216 new_is_floor = get_is_floor(x1 - 1, y);
218 /* increment counter if they are different */
219 if (new_is_floor != old_is_floor) count++;
221 old_is_floor = new_is_floor;
224 /* If all the same, or only one connection exit. */
225 if (count <= 2) return;
228 /* Tunnel around the room so to prevent problems with caves */
229 for (y = y1; y <= y2; y++)
231 for (x = x1; x <= x2; x++)
240 * Helper function for find_space().
242 * Is this a good location?
244 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
246 int by1, bx1, by2, bx2, by, bx;
248 /* Itty-bitty rooms must shift about within their rectangle */
251 if ((blocks_wide == 2) && (block_x % 3) == 2)
255 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
256 else if ((blocks_wide % 3) == 0)
258 /* Must be aligned to the left edge of a 11x33 rectangle. */
259 if ((block_x % 3) != 0)
264 * Big rooms that do not have a width divisible by 3 must be
265 * aligned towards the edge of the dungeon closest to them.
269 /* Shift towards left edge of dungeon. */
270 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
272 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
274 if ((block_x % 3) == 1)
278 /* Shift toward right edge of dungeon. */
281 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
283 if ((block_x % 3) == 1)
291 by2 = block_y + blocks_high;
292 bx2 = block_x + blocks_wide;
294 /* Never run off the screen */
295 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
296 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
298 /* Verify available space */
299 for (by = by1; by < by2; by++)
301 for (bx = bx1; bx < bx2; bx++)
303 if (dun->room_map[by][bx])
310 /* This location is okay */
316 * Find a good spot for the next room. -LM-
318 * Find and allocate a free space in the dungeon large enough to hold
319 * the room calling this function.
321 * We allocate space in 11x11 blocks, but want to make sure that rooms
322 * align neatly on the standard screen. Therefore, we make them use
323 * blocks in few 11x33 rectangles as possible.
325 * Be careful to include the edges of the room in height and width!
327 * Return TRUE and values for the center of the room if all went well.
328 * Otherwise, return FALSE.
330 static bool find_space(int *y, int *x, int height, int width)
332 int candidates, pick;
333 int by, bx, by1, bx1, by2, bx2;
334 int block_y = 0, block_x = 0;
337 /* Find out how many blocks we need. */
338 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
339 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
341 /* There are no way to allocate such huge space */
342 if (dun->row_rooms < blocks_high) return FALSE;
343 if (dun->col_rooms < blocks_wide) return FALSE;
348 /* Count the number of varid places */
349 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
351 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
353 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
355 /* Find a varid place */
368 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
370 /* Choose a random one */
371 pick = randint1(candidates);
374 /* NO_CAVE dungeon (Castle) */
377 /* Always choose the center one */
378 pick = candidates/2 + 1;
381 /* Pick up the choosen location */
382 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
384 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
386 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
390 /* This one is picked? */
401 by2 = block_y + blocks_high;
402 bx2 = block_x + blocks_wide;
405 * It is *extremely* important that the following calculation
406 * be *exactly* correct to prevent memory errors
409 /* Acquire the location of the room */
410 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
411 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
413 /* Save the room location */
414 if (dun->cent_n < CENT_MAX)
416 dun->cent[dun->cent_n].y = *y;
417 dun->cent[dun->cent_n].x = *x;
421 /* Reserve some blocks. */
422 for (by = by1; by < by2; by++)
424 for (bx = bx1; bx < bx2; bx++)
426 dun->room_map[by][bx] = TRUE;
432 * Hack- See if room will cut off a cavern.
434 * If so, fix by tunneling outside the room in such a
435 * way as to connect the caves.
437 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
447 * Room building routines.
453 * 4 -- large room with features
457 * 8 -- greater vaults
459 * 10 -- random vaults
460 * 11 -- circular rooms
462 * 13 -- trapped monster pits
468 * Type 1 -- normal rectangular rooms
470 static bool build_type1(void)
472 int y, x, y2, x2, yval, xval;
473 int y1, x1, xsize, ysize;
479 /* Pick a room size */
488 /* Find and reserve some space in the dungeon. Get center of room. */
489 if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
491 /* Limit to the minimum room size, and retry */
500 /* Find and reserve some space in the dungeon. Get center of room. */
501 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
504 /* Choose lite or dark */
505 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
508 /* Get corner values */
509 y1 = yval - ysize / 2;
510 x1 = xval - xsize / 2;
511 y2 = yval + (ysize - 1) / 2;
512 x2 = xval + (xsize - 1) / 2;
515 /* Place a full floor under the room */
516 for (y = y1 - 1; y <= y2 + 1; y++)
518 for (x = x1 - 1; x <= x2 + 1; x++)
521 place_floor_grid(c_ptr);
522 c_ptr->info |= (CAVE_ROOM);
523 if (light) c_ptr->info |= (CAVE_GLOW);
527 /* Walls around the room */
528 for (y = y1 - 1; y <= y2 + 1; y++)
530 c_ptr = &cave[y][x1 - 1];
531 place_outer_grid(c_ptr);
532 c_ptr = &cave[y][x2 + 1];
533 place_outer_grid(c_ptr);
535 for (x = x1 - 1; x <= x2 + 1; x++)
537 c_ptr = &cave[y1 - 1][x];
538 place_outer_grid(c_ptr);
539 c_ptr = &cave[y2 + 1][x];
540 place_outer_grid(c_ptr);
544 /* Hack -- Occasional pillar room */
547 for (y = y1; y <= y2; y += 2)
549 for (x = x1; x <= x2; x += 2)
552 place_inner_grid(c_ptr);
557 /* Hack -- Occasional room with four pillars */
558 else if (one_in_(20))
560 if ((y1 + 4 < y2) && (x1 + 4 < x2))
562 c_ptr = &cave[y1 + 1][x1 + 1];
563 place_inner_grid(c_ptr);
565 c_ptr = &cave[y1 + 1][x2 - 1];
566 place_inner_grid(c_ptr);
568 c_ptr = &cave[y2 - 1][x1 + 1];
569 place_inner_grid(c_ptr);
571 c_ptr = &cave[y2 - 1][x2 - 1];
572 place_inner_grid(c_ptr);
576 /* Hack -- Occasional ragged-edge room */
577 else if (one_in_(50))
579 for (y = y1 + 2; y <= y2 - 2; y += 2)
581 c_ptr = &cave[y][x1];
582 place_inner_grid(c_ptr);
583 c_ptr = &cave[y][x2];
584 place_inner_grid(c_ptr);
586 for (x = x1 + 2; x <= x2 - 2; x += 2)
588 c_ptr = &cave[y1][x];
589 place_inner_grid(c_ptr);
590 c_ptr = &cave[y2][x];
591 place_inner_grid(c_ptr);
594 /* Hack -- Occasional divided room */
595 else if (one_in_(50))
597 if (randint1(100) < 50)
599 /* Horizontal wall */
600 for (x = x1; x <= x2; x++)
602 place_inner_bold(yval, x);
605 /* Prevent edge of wall from being tunneled */
606 place_solid_bold(yval, x1 - 1);
607 place_solid_bold(yval, x2 + 1);
612 for (y = y1; y <= y2; y++)
614 place_inner_bold(y, xval);
617 /* Prevent edge of wall from being tunneled */
618 place_solid_bold(y1 - 1, xval);
619 place_solid_bold(y2 + 1, xval);
622 place_random_door(yval, xval, TRUE);
630 * Type 2 -- Overlapping rectangular rooms
632 static bool build_type2(void)
634 int y, x, xval, yval;
635 int y1a, x1a, y2a, x2a;
636 int y1b, x1b, y2b, x2b;
640 /* Find and reserve some space in the dungeon. Get center of room. */
641 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
643 /* Choose lite or dark */
644 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
646 /* Determine extents of the first room */
647 y1a = yval - randint1(4);
648 y2a = yval + randint1(3);
649 x1a = xval - randint1(11);
650 x2a = xval + randint1(10);
652 /* Determine extents of the second room */
653 y1b = yval - randint1(3);
654 y2b = yval + randint1(4);
655 x1b = xval - randint1(10);
656 x2b = xval + randint1(11);
659 /* Place a full floor for room "a" */
660 for (y = y1a - 1; y <= y2a + 1; y++)
662 for (x = x1a - 1; x <= x2a + 1; x++)
665 place_floor_grid(c_ptr);
666 c_ptr->info |= (CAVE_ROOM);
667 if (light) c_ptr->info |= (CAVE_GLOW);
671 /* Place a full floor for room "b" */
672 for (y = y1b - 1; y <= y2b + 1; y++)
674 for (x = x1b - 1; x <= x2b + 1; x++)
677 place_floor_grid(c_ptr);
678 c_ptr->info |= (CAVE_ROOM);
679 if (light) c_ptr->info |= (CAVE_GLOW);
684 /* Place the walls around room "a" */
685 for (y = y1a - 1; y <= y2a + 1; y++)
687 c_ptr = &cave[y][x1a - 1];
688 place_outer_grid(c_ptr);
689 c_ptr = &cave[y][x2a + 1];
690 place_outer_grid(c_ptr);
692 for (x = x1a - 1; x <= x2a + 1; x++)
694 c_ptr = &cave[y1a - 1][x];
695 place_outer_grid(c_ptr);
696 c_ptr = &cave[y2a + 1][x];
697 place_outer_grid(c_ptr);
700 /* Place the walls around room "b" */
701 for (y = y1b - 1; y <= y2b + 1; y++)
703 c_ptr = &cave[y][x1b - 1];
704 place_outer_grid(c_ptr);
705 c_ptr = &cave[y][x2b + 1];
706 place_outer_grid(c_ptr);
708 for (x = x1b - 1; x <= x2b + 1; x++)
710 c_ptr = &cave[y1b - 1][x];
711 place_outer_grid(c_ptr);
712 c_ptr = &cave[y2b + 1][x];
713 place_outer_grid(c_ptr);
718 /* Replace the floor for room "a" */
719 for (y = y1a; y <= y2a; y++)
721 for (x = x1a; x <= x2a; x++)
724 place_floor_grid(c_ptr);
728 /* Replace the floor for room "b" */
729 for (y = y1b; y <= y2b; y++)
731 for (x = x1b; x <= x2b; x++)
734 place_floor_grid(c_ptr);
744 * Type 3 -- Cross shaped rooms
746 * Builds a room at a row, column coordinate
748 * Room "a" runs north/south, and Room "b" runs east/east
749 * So the "central pillar" runs from x1a, y1b to x2a, y2b.
751 * Note that currently, the "center" is always 3x3, but I think that
752 * the code below will work (with "bounds checking") for 5x5, or even
753 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.
755 static bool build_type3(void)
757 int y, x, dy, dx, wy, wx;
758 int y1a, x1a, y2a, x2a;
759 int y1b, x1b, y2b, x2b;
765 /* Find and reserve some space in the dungeon. Get center of room. */
766 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
769 /* Choose lite or dark */
770 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
772 /* For now, always 3x3 */
775 /* Pick max vertical size (at most 4) */
776 dy = rand_range(3, 4);
778 /* Pick max horizontal size (at most 15) */
779 dx = rand_range(3, 11);
782 /* Determine extents of the north/south room */
788 /* Determine extents of the east/west room */
795 /* Place a full floor for room "a" */
796 for (y = y1a - 1; y <= y2a + 1; y++)
798 for (x = x1a - 1; x <= x2a + 1; x++)
801 place_floor_grid(c_ptr);
802 c_ptr->info |= (CAVE_ROOM);
803 if (light) c_ptr->info |= (CAVE_GLOW);
807 /* Place a full floor for room "b" */
808 for (y = y1b - 1; y <= y2b + 1; y++)
810 for (x = x1b - 1; x <= x2b + 1; x++)
813 place_floor_grid(c_ptr);
814 c_ptr->info |= (CAVE_ROOM);
815 if (light) c_ptr->info |= (CAVE_GLOW);
820 /* Place the walls around room "a" */
821 for (y = y1a - 1; y <= y2a + 1; y++)
823 c_ptr = &cave[y][x1a - 1];
824 place_outer_grid(c_ptr);
825 c_ptr = &cave[y][x2a + 1];
826 place_outer_grid(c_ptr);
828 for (x = x1a - 1; x <= x2a + 1; x++)
830 c_ptr = &cave[y1a - 1][x];
831 place_outer_grid(c_ptr);
832 c_ptr = &cave[y2a + 1][x];
833 place_outer_grid(c_ptr);
836 /* Place the walls around room "b" */
837 for (y = y1b - 1; y <= y2b + 1; y++)
839 c_ptr = &cave[y][x1b - 1];
840 place_outer_grid(c_ptr);
841 c_ptr = &cave[y][x2b + 1];
842 place_outer_grid(c_ptr);
844 for (x = x1b - 1; x <= x2b + 1; x++)
846 c_ptr = &cave[y1b - 1][x];
847 place_outer_grid(c_ptr);
848 c_ptr = &cave[y2b + 1][x];
849 place_outer_grid(c_ptr);
853 /* Replace the floor for room "a" */
854 for (y = y1a; y <= y2a; y++)
856 for (x = x1a; x <= x2a; x++)
859 place_floor_grid(c_ptr);
863 /* Replace the floor for room "b" */
864 for (y = y1b; y <= y2b; y++)
866 for (x = x1b; x <= x2b; x++)
869 place_floor_grid(c_ptr);
875 /* Special features (3/4) */
878 /* Large solid middle pillar */
881 for (y = y1b; y <= y2b; y++)
883 for (x = x1a; x <= x2a; x++)
886 place_inner_grid(c_ptr);
892 /* Inner treasure vault */
895 /* Build the vault */
896 for (y = y1b; y <= y2b; y++)
898 c_ptr = &cave[y][x1a];
899 place_inner_grid(c_ptr);
900 c_ptr = &cave[y][x2a];
901 place_inner_grid(c_ptr);
903 for (x = x1a; x <= x2a; x++)
905 c_ptr = &cave[y1b][x];
906 place_inner_grid(c_ptr);
907 c_ptr = &cave[y2b][x];
908 place_inner_grid(c_ptr);
911 /* Place a secret door on the inner room */
914 case 0: place_secret_door(y1b, xval); break;
915 case 1: place_secret_door(y2b, xval); break;
916 case 2: place_secret_door(yval, x1a); break;
917 case 3: place_secret_door(yval, x2a); break;
920 /* Place a treasure in the vault */
921 place_object(yval, xval, 0L);
923 /* Let's guard the treasure well */
924 vault_monsters(yval, xval, randint0(2) + 3);
926 /* Traps naturally */
927 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
935 /* Occasionally pinch the center shut */
938 /* Pinch the east/west sides */
939 for (y = y1b; y <= y2b; y++)
941 if (y == yval) continue;
942 c_ptr = &cave[y][x1a - 1];
943 place_inner_grid(c_ptr);
944 c_ptr = &cave[y][x2a + 1];
945 place_inner_grid(c_ptr);
948 /* Pinch the north/south sides */
949 for (x = x1a; x <= x2a; x++)
951 if (x == xval) continue;
952 c_ptr = &cave[y1b - 1][x];
953 place_inner_grid(c_ptr);
954 c_ptr = &cave[y2b + 1][x];
955 place_inner_grid(c_ptr);
958 /* Sometimes shut using secret doors */
961 place_secret_door(yval, x1a - 1);
962 place_secret_door(yval, x2a + 1);
963 place_secret_door(y1b - 1, xval);
964 place_secret_door(y2b + 1, xval);
968 /* Occasionally put a "plus" in the center */
971 c_ptr = &cave[yval][xval];
972 place_inner_grid(c_ptr);
973 c_ptr = &cave[y1b][xval];
974 place_inner_grid(c_ptr);
975 c_ptr = &cave[y2b][xval];
976 place_inner_grid(c_ptr);
977 c_ptr = &cave[yval][x1a];
978 place_inner_grid(c_ptr);
979 c_ptr = &cave[yval][x2a];
980 place_inner_grid(c_ptr);
983 /* Occasionally put a pillar in the center */
986 c_ptr = &cave[yval][xval];
987 place_inner_grid(c_ptr);
999 * Type 4 -- Large room with inner features
1001 * Possible sub-types:
1002 * 1 - Just an inner room with one door
1003 * 2 - An inner room within an inner room
1004 * 3 - An inner room with pillar(s)
1005 * 4 - Inner room has a maze
1006 * 5 - A set of four inner rooms
1008 static bool build_type4(void)
1011 int y2, x2, tmp, yval, xval;
1016 /* Find and reserve some space in the dungeon. Get center of room. */
1017 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
1019 /* Choose lite or dark */
1020 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1028 /* Place a full floor under the room */
1029 for (y = y1 - 1; y <= y2 + 1; y++)
1031 for (x = x1 - 1; x <= x2 + 1; x++)
1033 c_ptr = &cave[y][x];
1034 place_floor_grid(c_ptr);
1035 c_ptr->info |= (CAVE_ROOM);
1036 if (light) c_ptr->info |= (CAVE_GLOW);
1041 for (y = y1 - 1; y <= y2 + 1; y++)
1043 c_ptr = &cave[y][x1 - 1];
1044 place_outer_grid(c_ptr);
1045 c_ptr = &cave[y][x2 + 1];
1046 place_outer_grid(c_ptr);
1048 for (x = x1 - 1; x <= x2 + 1; x++)
1050 c_ptr = &cave[y1 - 1][x];
1051 place_outer_grid(c_ptr);
1052 c_ptr = &cave[y2 + 1][x];
1053 place_outer_grid(c_ptr);
1057 /* The inner room */
1063 /* The inner walls */
1064 for (y = y1 - 1; y <= y2 + 1; y++)
1066 c_ptr = &cave[y][x1 - 1];
1067 place_inner_grid(c_ptr);
1068 c_ptr = &cave[y][x2 + 1];
1069 place_inner_grid(c_ptr);
1071 for (x = x1 - 1; x <= x2 + 1; x++)
1073 c_ptr = &cave[y1 - 1][x];
1074 place_inner_grid(c_ptr);
1075 c_ptr = &cave[y2 + 1][x];
1076 place_inner_grid(c_ptr);
1080 /* Inner room variations */
1081 switch (randint1(5))
1083 /* Just an inner room with a monster */
1086 /* Place a secret door */
1087 switch (randint1(4))
1089 case 1: place_secret_door(y1 - 1, xval); break;
1090 case 2: place_secret_door(y2 + 1, xval); break;
1091 case 3: place_secret_door(yval, x1 - 1); break;
1092 case 4: place_secret_door(yval, x2 + 1); break;
1095 /* Place a monster in the room */
1096 vault_monsters(yval, xval, 1);
1101 /* Treasure Vault (with a door) */
1104 /* Place a secret door */
1105 switch (randint1(4))
1107 case 1: place_secret_door(y1 - 1, xval); break;
1108 case 2: place_secret_door(y2 + 1, xval); break;
1109 case 3: place_secret_door(yval, x1 - 1); break;
1110 case 4: place_secret_door(yval, x2 + 1); break;
1113 /* Place another inner room */
1114 for (y = yval - 1; y <= yval + 1; y++)
1116 for (x = xval - 1; x <= xval + 1; x++)
1118 if ((x == xval) && (y == yval)) continue;
1119 c_ptr = &cave[y][x];
1120 place_inner_grid(c_ptr);
1124 /* Place a locked door on the inner room */
1125 switch (randint1(4))
1127 case 1: place_locked_door(yval - 1, xval); break;
1128 case 2: place_locked_door(yval + 1, xval); break;
1129 case 3: place_locked_door(yval, xval - 1); break;
1130 case 4: place_locked_door(yval, xval + 1); break;
1133 /* Monsters to guard the "treasure" */
1134 vault_monsters(yval, xval, randint1(3) + 2);
1137 if (randint0(100) < 80)
1139 place_object(yval, xval, 0L);
1145 place_random_stairs(yval, xval);
1148 /* Traps to protect the treasure */
1149 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
1154 /* Inner pillar(s). */
1157 /* Place a secret door */
1158 switch (randint1(4))
1160 case 1: place_secret_door(y1 - 1, xval); break;
1161 case 2: place_secret_door(y2 + 1, xval); break;
1162 case 3: place_secret_door(yval, x1 - 1); break;
1163 case 4: place_secret_door(yval, x2 + 1); break;
1166 /* Large Inner Pillar */
1167 for (y = yval - 1; y <= yval + 1; y++)
1169 for (x = xval - 1; x <= xval + 1; x++)
1171 c_ptr = &cave[y][x];
1172 place_inner_grid(c_ptr);
1176 /* Occasionally, two more Large Inner Pillars */
1180 for (y = yval - 1; y <= yval + 1; y++)
1182 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1184 c_ptr = &cave[y][x];
1185 place_inner_grid(c_ptr);
1187 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1189 c_ptr = &cave[y][x];
1190 place_inner_grid(c_ptr);
1195 /* Occasionally, some Inner rooms */
1198 /* Long horizontal walls */
1199 for (x = xval - 5; x <= xval + 5; x++)
1201 c_ptr = &cave[yval - 1][x];
1202 place_inner_grid(c_ptr);
1203 c_ptr = &cave[yval + 1][x];
1204 place_inner_grid(c_ptr);
1207 /* Close off the left/right edges */
1208 c_ptr = &cave[yval][xval - 5];
1209 place_inner_grid(c_ptr);
1210 c_ptr = &cave[yval][xval + 5];
1211 place_inner_grid(c_ptr);
1213 /* Secret doors (random top/bottom) */
1214 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3);
1215 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3);
1218 vault_monsters(yval, xval - 2, randint1(2));
1219 vault_monsters(yval, xval + 2, randint1(2));
1222 if (one_in_(3)) place_object(yval, xval - 2, 0L);
1223 if (one_in_(3)) place_object(yval, xval + 2, 0L);
1232 /* Place a secret door */
1233 switch (randint1(4))
1235 case 1: place_secret_door(y1 - 1, xval); break;
1236 case 2: place_secret_door(y2 + 1, xval); break;
1237 case 3: place_secret_door(yval, x1 - 1); break;
1238 case 4: place_secret_door(yval, x2 + 1); break;
1241 /* Maze (really a checkerboard) */
1242 for (y = y1; y <= y2; y++)
1244 for (x = x1; x <= x2; x++)
1248 c_ptr = &cave[y][x];
1249 place_inner_grid(c_ptr);
1254 /* Monsters just love mazes. */
1255 vault_monsters(yval, xval - 5, randint1(3));
1256 vault_monsters(yval, xval + 5, randint1(3));
1258 /* Traps make them entertaining. */
1259 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1260 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1262 /* Mazes should have some treasure too. */
1263 vault_objects(yval, xval, 3);
1268 /* Four small rooms. */
1272 for (y = y1; y <= y2; y++)
1274 c_ptr = &cave[y][xval];
1275 place_inner_grid(c_ptr);
1277 for (x = x1; x <= x2; x++)
1279 c_ptr = &cave[yval][x];
1280 place_inner_grid(c_ptr);
1283 /* Doors into the rooms */
1284 if (randint0(100) < 50)
1286 int i = randint1(10);
1287 place_secret_door(y1 - 1, xval - i);
1288 place_secret_door(y1 - 1, xval + i);
1289 place_secret_door(y2 + 1, xval - i);
1290 place_secret_door(y2 + 1, xval + i);
1294 int i = randint1(3);
1295 place_secret_door(yval + i, x1 - 1);
1296 place_secret_door(yval - i, x1 - 1);
1297 place_secret_door(yval + i, x2 + 1);
1298 place_secret_door(yval - i, x2 + 1);
1301 /* Treasure, centered at the center of the cross */
1302 vault_objects(yval, xval, 2 + randint1(2));
1304 /* Gotta have some monsters. */
1305 vault_monsters(yval + 1, xval - 4, randint1(4));
1306 vault_monsters(yval + 1, xval + 4, randint1(4));
1307 vault_monsters(yval - 1, xval - 4, randint1(4));
1308 vault_monsters(yval - 1, xval + 4, randint1(4));
1319 * The following functions are used to determine if the given monster
1320 * is appropriate for inclusion in a monster nest or monster pit or
1323 * None of the pits/nests are allowed to include "unique" monsters.
1328 * Monster validation macro
1330 * Line 1 -- forbid town monsters
1331 * Line 2 -- forbid uniques
1332 * Line 3 -- forbid aquatic monsters
1334 #define vault_monster_okay(I) \
1335 (mon_hook_dungeon(I) && \
1336 !(r_info[I].flags1 & RF1_UNIQUE) && \
1337 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1338 !(r_info[I].flagsr & RFR_RES_ALL) && \
1339 !(r_info[I].flags7 & RF7_AQUATIC))
1342 /* Race index for "monster pit (clone)" */
1343 static int vault_aux_race;
1345 /* Race index for "monster pit (symbol clone)" */
1346 static char vault_aux_char;
1348 /* Breath mask for "monster pit (dragon)" */
1349 static u32b vault_aux_dragon_mask4;
1353 * Helper monster selection function
1355 static bool vault_aux_simple(int r_idx)
1358 return (vault_monster_okay(r_idx));
1363 * Helper function for "monster nest (jelly)"
1365 static bool vault_aux_jelly(int r_idx)
1367 monster_race *r_ptr = &r_info[r_idx];
1369 /* Validate the monster */
1370 if (!vault_monster_okay(r_idx)) return (FALSE);
1372 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1374 /* Also decline evil jellies (like death molds and shoggoths) */
1375 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1377 /* Require icky thing, jelly, mold, or mushroom */
1378 if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
1386 * Helper function for "monster nest (animal)"
1388 static bool vault_aux_animal(int r_idx)
1390 monster_race *r_ptr = &r_info[r_idx];
1392 /* Validate the monster */
1393 if (!vault_monster_okay(r_idx)) return (FALSE);
1395 /* Require "animal" flag */
1396 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1404 * Helper function for "monster nest (undead)"
1406 static bool vault_aux_undead(int r_idx)
1408 monster_race *r_ptr = &r_info[r_idx];
1410 /* Validate the monster */
1411 if (!vault_monster_okay(r_idx)) return (FALSE);
1413 /* Require Undead */
1414 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1422 * Helper function for "monster nest (chapel)"
1424 static bool vault_aux_chapel_g(int r_idx)
1426 static int chapel_list[] = {
1427 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1428 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1429 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1434 monster_race *r_ptr = &r_info[r_idx];
1436 /* Validate the monster */
1437 if (!vault_monster_okay(r_idx)) return (FALSE);
1439 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1440 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1442 /* Require "priest" or Angel */
1444 if (r_ptr->d_char == 'A') return TRUE;
1446 for (i = 0; chapel_list[i]; i++)
1447 if (r_idx == chapel_list[i]) return TRUE;
1454 * Helper function for "monster nest (kennel)"
1456 static bool vault_aux_kennel(int r_idx)
1458 monster_race *r_ptr = &r_info[r_idx];
1460 /* Validate the monster */
1461 if (!vault_monster_okay(r_idx)) return (FALSE);
1463 /* Require a Zephyr Hound or a dog */
1464 if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
1472 * Helper function for "monster nest (mimic)"
1474 static bool vault_aux_mimic(int r_idx)
1476 monster_race *r_ptr = &r_info[r_idx];
1478 /* Validate the monster */
1479 if (!vault_monster_okay(r_idx)) return (FALSE);
1482 if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
1489 * Helper function for "monster nest (clone)"
1491 static bool vault_aux_clone(int r_idx)
1493 /* Validate the monster */
1494 if (!vault_monster_okay(r_idx)) return (FALSE);
1496 return (r_idx == vault_aux_race);
1501 * Helper function for "monster nest (symbol clone)"
1503 static bool vault_aux_symbol_e(int r_idx)
1505 monster_race *r_ptr = &r_info[r_idx];
1507 /* Validate the monster */
1508 if (!vault_monster_okay(r_idx)) return (FALSE);
1510 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1512 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1514 /* Decline incorrect symbol */
1515 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1523 * Helper function for "monster nest (symbol clone)"
1525 static bool vault_aux_symbol_g(int r_idx)
1527 monster_race *r_ptr = &r_info[r_idx];
1529 /* Validate the monster */
1530 if (!vault_monster_okay(r_idx)) return (FALSE);
1532 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1534 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1536 /* Decline incorrect symbol */
1537 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1545 * Helper function for "monster pit (orc)"
1547 static bool vault_aux_orc(int r_idx)
1549 monster_race *r_ptr = &r_info[r_idx];
1551 /* Validate the monster */
1552 if (!vault_monster_okay(r_idx)) return (FALSE);
1555 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1557 /* Decline undead */
1558 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1566 * Helper function for "monster pit (troll)"
1568 static bool vault_aux_troll(int r_idx)
1570 monster_race *r_ptr = &r_info[r_idx];
1572 /* Validate the monster */
1573 if (!vault_monster_okay(r_idx)) return (FALSE);
1576 if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1578 /* Decline undead */
1579 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1587 * Helper function for "monster pit (giant)"
1589 static bool vault_aux_giant(int r_idx)
1591 monster_race *r_ptr = &r_info[r_idx];
1593 /* Validate the monster */
1594 if (!vault_monster_okay(r_idx)) return (FALSE);
1597 if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1599 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1601 /* Decline undead */
1602 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1610 * Helper function for "monster pit (dragon)"
1612 static bool vault_aux_dragon(int r_idx)
1614 monster_race *r_ptr = &r_info[r_idx];
1616 /* Validate the monster */
1617 if (!vault_monster_okay(r_idx)) return (FALSE);
1619 /* Require dragon */
1620 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1622 /* Hack -- Require correct "breath attack" */
1623 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1625 /* Decline undead */
1626 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1634 * Helper function for "monster pit (demon)"
1636 static bool vault_aux_demon(int r_idx)
1638 monster_race *r_ptr = &r_info[r_idx];
1640 /* Validate the monster */
1641 if (!vault_monster_okay(r_idx)) return (FALSE);
1643 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1646 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1654 * Helper function for "monster pit (lovecraftian)"
1656 static bool vault_aux_cthulhu(int r_idx)
1658 monster_race *r_ptr = &r_info[r_idx];
1660 /* Validate the monster */
1661 if (!vault_monster_okay(r_idx)) return (FALSE);
1663 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1665 /* Require eldritch horror */
1666 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1674 * Helper function for "monster pit (clone)"
1676 static void vault_prep_clone(void)
1678 /* Apply the monster restriction */
1679 get_mon_num_prep(vault_aux_simple, NULL);
1681 /* Pick a race to clone */
1682 vault_aux_race = get_mon_num(dun_level + 10);
1684 /* Remove the monster restriction */
1685 get_mon_num_prep(NULL, NULL);
1690 * Helper function for "monster pit (symbol clone)"
1692 static void vault_prep_symbol(void)
1696 /* Apply the monster restriction */
1697 get_mon_num_prep(vault_aux_simple, NULL);
1699 /* Pick a race to clone */
1700 r_idx = get_mon_num(dun_level + 10);
1702 /* Remove the monster restriction */
1703 get_mon_num_prep(NULL, NULL);
1705 /* Extract the symbol */
1706 vault_aux_char = r_info[r_idx].d_char;
1711 * Helper function for "monster pit (dragon)"
1713 static void vault_prep_dragon(void)
1715 /* Pick dragon type */
1716 switch (randint0(6))
1721 /* Restrict dragon breath type */
1722 vault_aux_dragon_mask4 = RF4_BR_ACID;
1731 /* Restrict dragon breath type */
1732 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1741 /* Restrict dragon breath type */
1742 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1751 /* Restrict dragon breath type */
1752 vault_aux_dragon_mask4 = RF4_BR_COLD;
1761 /* Restrict dragon breath type */
1762 vault_aux_dragon_mask4 = RF4_BR_POIS;
1771 /* Restrict dragon breath type */
1772 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1773 RF4_BR_FIRE | RF4_BR_COLD |
1784 * Helper function for "monster pit (dark elf)"
1786 static bool vault_aux_dark_elf(int r_idx)
1789 static int dark_elf_list[] =
1791 MON_D_ELF, MON_D_ELF_MAGE, MON_D_ELF_WARRIOR, MON_D_ELF_PRIEST,
1792 MON_D_ELF_LORD, MON_D_ELF_WARLOCK, MON_D_ELF_DRUID, MON_NIGHTBLADE,
1793 MON_D_ELF_SORC, MON_D_ELF_SHADE, 0,
1796 /* Validate the monster */
1797 if (!vault_monster_okay(r_idx)) return FALSE;
1799 /* Require dark elves */
1800 for (i = 0; dark_elf_list[i]; i++)
1801 if (r_idx == dark_elf_list[i]) return TRUE;
1808 typedef struct vault_aux_type vault_aux_type;
1811 struct vault_aux_type
1814 bool (*hook_func)(int r_idx);
1815 void (*prep_func)(void);
1821 static int pick_vault_type(vault_aux_type *l_ptr, s16b allow_flag_mask)
1823 int tmp, total, count;
1825 vault_aux_type *n_ptr;
1827 /* Calculate the total possibilities */
1828 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1831 if (!n_ptr->name) break;
1833 /* Ignore excessive depth */
1834 if (n_ptr->level > dun_level) continue;
1836 /* Not matched with pit/nest flag */
1837 if (!(allow_flag_mask & (1L << count))) continue;
1839 /* Count this possibility */
1840 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1843 /* Pick a random type */
1844 tmp = randint0(total);
1846 /* Find this type */
1847 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1850 if (!n_ptr->name) break;
1852 /* Ignore excessive depth */
1853 if (n_ptr->level > dun_level) continue;
1855 /* Not matched with pit/nest flag */
1856 if (!(allow_flag_mask & (1L << count))) continue;
1858 /* Count this possibility */
1859 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1861 /* Found the type */
1862 if (tmp < total) break;
1865 return n_ptr->name ? count : -1;
1868 static vault_aux_type nest_types[] =
1871 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1872 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1873 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1874 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1875 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1876 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1877 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1878 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1879 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1880 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1881 {NULL, NULL, NULL, 0, 0},
1883 {"clone", vault_aux_clone, vault_prep_clone, 5, 3},
1884 {"jelly", vault_aux_jelly, NULL, 5, 6},
1885 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1886 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1887 {"mimic", vault_aux_mimic, NULL, 30, 4},
1888 {"lovecraftian", vault_aux_cthulhu, NULL, 70, 2},
1889 {"kennel", vault_aux_kennel, NULL, 45, 4},
1890 {"animal", vault_aux_animal, NULL, 35, 5},
1891 {"chapel", vault_aux_chapel_g, NULL, 75, 4},
1892 {"undead", vault_aux_undead, NULL, 75, 5},
1893 {NULL, NULL, NULL, 0, 0},
1897 static vault_aux_type pit_types[] =
1900 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1901 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1902 {"¥¸¥ã¥¤¥¢¥ó¥È", vault_aux_giant, NULL, 50, 6},
1903 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1904 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1905 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1906 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
1907 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
1908 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
1909 {"¥À¡¼¥¯¥¨¥ë¥Õ", vault_aux_dark_elf, NULL, 45, 4},
1910 {NULL, NULL, NULL, 0, 0},
1912 {"orc", vault_aux_orc, NULL, 5, 6},
1913 {"troll", vault_aux_troll, NULL, 20, 6},
1914 {"giant", vault_aux_giant, NULL, 50, 6},
1915 {"lovecraftian", vault_aux_cthulhu, NULL, 80, 2},
1916 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1917 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1918 {"chapel", vault_aux_chapel_g, NULL, 65, 2},
1919 {"dragon", vault_aux_dragon, vault_prep_dragon, 70, 6},
1920 {"demon", vault_aux_demon, NULL, 80, 6},
1921 {"dark elf", vault_aux_dark_elf, NULL, 45, 4},
1922 {NULL, NULL, NULL, 0, 0},
1927 /* Nest types code */
1928 #define NEST_TYPE_CLONE 0
1929 #define NEST_TYPE_JELLY 1
1930 #define NEST_TYPE_SYMBOL_GOOD 2
1931 #define NEST_TYPE_SYMBOL_EVIL 3
1932 #define NEST_TYPE_MIMIC 4
1933 #define NEST_TYPE_LOVECRAFTIAN 5
1934 #define NEST_TYPE_KENNEL 6
1935 #define NEST_TYPE_ANIMAL 7
1936 #define NEST_TYPE_CHAPEL 8
1937 #define NEST_TYPE_UNDEAD 9
1939 /* Pit types code */
1940 #define PIT_TYPE_ORC 0
1941 #define PIT_TYPE_TROLL 1
1942 #define PIT_TYPE_GIANT 2
1943 #define PIT_TYPE_LOVECRAFTIAN 3
1944 #define PIT_TYPE_SYMBOL_GOOD 4
1945 #define PIT_TYPE_SYMBOL_EVIL 5
1946 #define PIT_TYPE_CHAPEL 6
1947 #define PIT_TYPE_DRAGON 7
1948 #define PIT_TYPE_DEMON 8
1949 #define PIT_TYPE_DARK_ELF 9
1953 * Hack -- Get the string describing subtype of pit/nest
1954 * Determined in prepare function (some pit/nest only)
1956 static cptr pit_subtype_string(int type, bool nest)
1958 static char inner_buf[256] = "";
1960 inner_buf[0] = '\0'; /* Init string */
1962 if (nest) /* Nests */
1966 case NEST_TYPE_CLONE:
1967 sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
1969 case NEST_TYPE_SYMBOL_GOOD:
1970 case NEST_TYPE_SYMBOL_EVIL:
1971 sprintf(inner_buf, "(%c)", vault_aux_char);
1979 case PIT_TYPE_SYMBOL_GOOD:
1980 case PIT_TYPE_SYMBOL_EVIL:
1981 sprintf(inner_buf, "(%c)", vault_aux_char);
1983 case PIT_TYPE_DRAGON:
1984 switch (vault_aux_dragon_mask4)
1987 case RF4_BR_ACID: strcpy(inner_buf, "(»À)"); break;
1988 case RF4_BR_ELEC: strcpy(inner_buf, "(°ðºÊ)"); break;
1989 case RF4_BR_FIRE: strcpy(inner_buf, "(²Ð±ê)"); break;
1990 case RF4_BR_COLD: strcpy(inner_buf, "(Î䵤)"); break;
1991 case RF4_BR_POIS: strcpy(inner_buf, "(ÆÇ)"); break;
1992 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
1993 strcpy(inner_buf, "(Ëü¿§)"); break;
1994 default: strcpy(inner_buf, "(̤ÄêµÁ)"); break;
1996 case RF4_BR_ACID: strcpy(inner_buf, "(acid)"); break;
1997 case RF4_BR_ELEC: strcpy(inner_buf, "(lightning)"); break;
1998 case RF4_BR_FIRE: strcpy(inner_buf, "(fire)"); break;
1999 case RF4_BR_COLD: strcpy(inner_buf, "(frost)"); break;
2000 case RF4_BR_POIS: strcpy(inner_buf, "(poison)"); break;
2001 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2002 strcpy(inner_buf, "(multi-hued)"); break;
2003 default: strcpy(inner_buf, "(undefined)"); break;
2014 /* A struct for nest monster information with cheat_hear */
2024 * Comp function for sorting nest monster information
2026 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
2028 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2029 int w1 = nest_mon_info[a].r_idx;
2030 int w2 = nest_mon_info[b].r_idx;
2031 monster_race *r1_ptr = &r_info[w1];
2032 monster_race *r2_ptr = &r_info[w2];
2038 /* Extract used info */
2039 z1 = nest_mon_info[a].used;
2040 z2 = nest_mon_info[b].used;
2042 /* Compare used status */
2043 if (z1 < z2) return FALSE;
2044 if (z1 > z2) return TRUE;
2046 /* Compare levels */
2047 if (r1_ptr->level < r2_ptr->level) return TRUE;
2048 if (r1_ptr->level > r2_ptr->level) return FALSE;
2050 /* Compare experience */
2051 if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
2052 if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
2054 /* Compare indexes */
2060 * Swap function for sorting nest monster information
2062 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
2064 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2065 nest_mon_info_type holder;
2071 holder = nest_mon_info[a];
2072 nest_mon_info[a] = nest_mon_info[b];
2073 nest_mon_info[b] = holder;
2077 #define NUM_NEST_MON_TYPE 64
2080 * Type 5 -- Monster nests
2082 * A monster nest is a "big" room, with an "inner" room, containing
2083 * a "collection" of monsters of a given type strewn about the room.
2085 * The monsters are chosen from a set of 64 randomly selected monster
2086 * races, to allow the nest creation to fail instead of having "holes".
2088 * Note the use of the "get_mon_num_prep()" function, and the special
2089 * "get_mon_num_hook()" restriction function, to prepare the "monster
2090 * allocation table" in such a way as to optimize the selection of
2091 * "appropriate" non-unique monsters for the nest.
2093 * Note that the "get_mon_num()" function may (rarely) fail, in which
2094 * case the nest will be empty.
2096 * Note that "monster nests" will never contain "unique" monsters.
2098 static bool build_type5(void)
2100 int y, x, y1, x1, y2, x2, xval, yval;
2102 nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
2108 int cur_nest_type = pick_vault_type(nest_types, d_info[dungeon_type].nest);
2109 vault_aux_type *n_ptr;
2111 /* No type available */
2112 if (cur_nest_type < 0) return FALSE;
2114 n_ptr = &nest_types[cur_nest_type];
2116 /* Process a preparation function if necessary */
2117 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2119 /* Prepare allocation table */
2120 get_mon_num_prep(n_ptr->hook_func, NULL);
2122 align.sub_align = SUB_ALIGN_NEUTRAL;
2124 /* Pick some monster types */
2125 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2127 int r_idx = 0, attempts = 100;
2128 monster_race *r_ptr = NULL;
2132 /* Get a (hard) monster type */
2133 r_idx = get_mon_num(dun_level + 11);
2134 r_ptr = &r_info[r_idx];
2136 /* Decline incorrect alignment */
2137 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2139 /* Accept this monster */
2143 /* Notice failure */
2144 if (!r_idx || !attempts) return FALSE;
2146 /* Note the alignment */
2147 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2148 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2150 nest_mon_info[i].r_idx = r_idx;
2151 nest_mon_info[i].used = FALSE;
2154 /* Find and reserve some space in the dungeon. Get center of room. */
2155 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2163 /* Place the floor area */
2164 for (y = y1 - 1; y <= y2 + 1; y++)
2166 for (x = x1 - 1; x <= x2 + 1; x++)
2168 c_ptr = &cave[y][x];
2169 place_floor_grid(c_ptr);
2170 c_ptr->info |= (CAVE_ROOM);
2174 /* Place the outer walls */
2175 for (y = y1 - 1; y <= y2 + 1; y++)
2177 c_ptr = &cave[y][x1 - 1];
2178 place_outer_grid(c_ptr);
2179 c_ptr = &cave[y][x2 + 1];
2180 place_outer_grid(c_ptr);
2182 for (x = x1 - 1; x <= x2 + 1; x++)
2184 c_ptr = &cave[y1 - 1][x];
2185 place_outer_grid(c_ptr);
2186 c_ptr = &cave[y2 + 1][x];
2187 place_outer_grid(c_ptr);
2191 /* Advance to the center room */
2197 /* The inner walls */
2198 for (y = y1 - 1; y <= y2 + 1; y++)
2200 c_ptr = &cave[y][x1 - 1];
2201 place_inner_grid(c_ptr);
2202 c_ptr = &cave[y][x2 + 1];
2203 place_inner_grid(c_ptr);
2206 for (x = x1 - 1; x <= x2 + 1; x++)
2208 c_ptr = &cave[y1 - 1][x];
2209 place_inner_grid(c_ptr);
2210 c_ptr = &cave[y2 + 1][x];
2211 place_inner_grid(c_ptr);
2213 for (y = y1; y <= y2; y++)
2215 for (x = x1; x <= x2; x++)
2217 add_cave_info(y, x, CAVE_ICKY);
2221 /* Place a secret door */
2222 switch (randint1(4))
2224 case 1: place_secret_door(y1 - 1, xval); break;
2225 case 2: place_secret_door(y2 + 1, xval); break;
2226 case 3: place_secret_door(yval, x1 - 1); break;
2227 case 4: place_secret_door(yval, x2 + 1); break;
2235 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(nest)(%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2237 msg_format("Monster nest (%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2241 /* Place some monsters */
2242 for (y = yval - 2; y <= yval + 2; y++)
2244 for (x = xval - 9; x <= xval + 9; x++)
2248 i = randint0(NUM_NEST_MON_TYPE);
2249 r_idx = nest_mon_info[i].r_idx;
2251 /* Place that "random" monster (no groups) */
2252 (void)place_monster_aux(0, y, x, r_idx, 0L);
2254 nest_mon_info[i].used = TRUE;
2258 if (cheat_room && cheat_hear)
2260 ang_sort_comp = ang_sort_comp_nest_mon_info;
2261 ang_sort_swap = ang_sort_swap_nest_mon_info;
2262 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2264 /* Dump the entries (prevent multi-printing) */
2265 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2267 if (!nest_mon_info[i].used) break;
2268 for (; i < NUM_NEST_MON_TYPE - 1; i++)
2270 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2271 if (!nest_mon_info[i + 1].used) break;
2273 msg_print(r_name + r_info[nest_mon_info[i].r_idx].name);
2282 * Type 6 -- Monster pits
2284 * A monster pit is a "big" room, with an "inner" room, containing
2285 * a "collection" of monsters of a given type organized in the room.
2287 * The inside room in a monster pit appears as shown below, where the
2288 * actual monsters in each location depend on the type of the pit
2290 * #####################
2291 * #0000000000000000000#
2292 * #0112233455543322110#
2293 * #0112233467643322110#
2294 * #0112233455543322110#
2295 * #0000000000000000000#
2296 * #####################
2298 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
2299 * to request 16 "appropriate" monsters, sorting them by level, and using
2300 * the "even" entries in this sorted list for the contents of the pit.
2302 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
2303 * which is handled by requiring a specific "breath" attack for all of the
2304 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
2305 * be present in many of the dragon pits, if they have the proper breath.
2307 * Note the use of the "get_mon_num_prep()" function, and the special
2308 * "get_mon_num_hook()" restriction function, to prepare the "monster
2309 * allocation table" in such a way as to optimize the selection of
2310 * "appropriate" non-unique monsters for the pit.
2312 * Note that the "get_mon_num()" function may (rarely) fail, in which case
2313 * the pit will be empty.
2315 * Note that "monster pits" will never contain "unique" monsters.
2317 static bool build_type6(void)
2319 int y, x, y1, x1, y2, x2, xval, yval;
2328 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2329 vault_aux_type *n_ptr;
2331 /* No type available */
2332 if (cur_pit_type < 0) return FALSE;
2334 n_ptr = &pit_types[cur_pit_type];
2336 /* Process a preparation function if necessary */
2337 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2339 /* Prepare allocation table */
2340 get_mon_num_prep(n_ptr->hook_func, NULL);
2342 align.sub_align = SUB_ALIGN_NEUTRAL;
2344 /* Pick some monster types */
2345 for (i = 0; i < 16; i++)
2347 int r_idx = 0, attempts = 100;
2348 monster_race *r_ptr = NULL;
2352 /* Get a (hard) monster type */
2353 r_idx = get_mon_num(dun_level + 11);
2354 r_ptr = &r_info[r_idx];
2356 /* Decline incorrect alignment */
2357 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2359 /* Accept this monster */
2363 /* Notice failure */
2364 if (!r_idx || !attempts) return FALSE;
2366 /* Note the alignment */
2367 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2368 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2373 /* Find and reserve some space in the dungeon. Get center of room. */
2374 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2382 /* Place the floor area */
2383 for (y = y1 - 1; y <= y2 + 1; y++)
2385 for (x = x1 - 1; x <= x2 + 1; x++)
2387 c_ptr = &cave[y][x];
2388 place_floor_grid(c_ptr);
2389 c_ptr->info |= (CAVE_ROOM);
2393 /* Place the outer walls */
2394 for (y = y1 - 1; y <= y2 + 1; y++)
2396 c_ptr = &cave[y][x1 - 1];
2397 place_outer_grid(c_ptr);
2398 c_ptr = &cave[y][x2 + 1];
2399 place_outer_grid(c_ptr);
2401 for (x = x1 - 1; x <= x2 + 1; x++)
2403 c_ptr = &cave[y1 - 1][x];
2404 place_outer_grid(c_ptr);
2405 c_ptr = &cave[y2 + 1][x];
2406 place_outer_grid(c_ptr);
2409 /* Advance to the center room */
2415 /* The inner walls */
2416 for (y = y1 - 1; y <= y2 + 1; y++)
2418 c_ptr = &cave[y][x1 - 1];
2419 place_inner_grid(c_ptr);
2420 c_ptr = &cave[y][x2 + 1];
2421 place_inner_grid(c_ptr);
2423 for (x = x1 - 1; x <= x2 + 1; x++)
2425 c_ptr = &cave[y1 - 1][x];
2426 place_inner_grid(c_ptr);
2427 c_ptr = &cave[y2 + 1][x];
2428 place_inner_grid(c_ptr);
2430 for (y = y1; y <= y2; y++)
2432 for (x = x1; x <= x2; x++)
2434 add_cave_info(y, x, CAVE_ICKY);
2438 /* Place a secret door */
2439 switch (randint1(4))
2441 case 1: place_secret_door(y1 - 1, xval); break;
2442 case 2: place_secret_door(y2 + 1, xval); break;
2443 case 3: place_secret_door(yval, x1 - 1); break;
2444 case 4: place_secret_door(yval, x2 + 1); break;
2447 /* Sort the entries */
2448 for (i = 0; i < 16 - 1; i++)
2450 /* Sort the entries */
2451 for (j = 0; j < 16 - 1; j++)
2456 int p1 = r_info[what[i1]].level;
2457 int p2 = r_info[what[i2]].level;
2463 what[i1] = what[i2];
2474 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(pit)(%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2476 msg_format("Monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2480 /* Select the entries */
2481 for (i = 0; i < 8; i++)
2483 /* Every other entry */
2484 what[i] = what[i * 2];
2489 msg_print(r_name + r_info[what[i]].name);
2493 /* Top and bottom rows */
2494 for (x = xval - 9; x <= xval + 9; x++)
2496 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2497 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2500 /* Middle columns */
2501 for (y = yval - 1; y <= yval + 1; y++)
2503 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2504 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2506 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2507 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2509 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2510 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2512 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2513 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2515 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2516 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2518 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2519 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2521 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2522 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2524 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2525 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2528 /* Above/Below the center monster */
2529 for (x = xval - 1; x <= xval + 1; x++)
2531 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2532 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2535 /* Next to the center monster */
2536 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2537 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2539 /* Center monster */
2540 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2546 /* coordinate translation code */
2547 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2553 * transno specifies what transformation is required. (0-7)
2554 * The lower two bits indicate by how much the vault is rotated,
2555 * and the upper bit indicates a reflection.
2556 * This is done by using rotation matrices... however since
2557 * these are mostly zeros for rotations by 90 degrees this can
2558 * be expressed simply in terms of swapping and inverting the
2559 * x and y coordinates.
2561 for (i = 0; i < transno % 4; i++)
2563 /* rotate by 90 degrees */
2571 /* Reflect depending on status of 3rd bit. */
2575 /* Add offsets so vault stays in the first quadrant */
2582 * Hack -- fill in "vault" rooms
2584 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2585 int xoffset, int yoffset, int transno)
2587 int dx, dy, x, y, i, j;
2594 /* Place dungeon features and objects */
2595 for (t = data, dy = 0; dy < ymax; dy++)
2597 for (dx = 0; dx < xmax; dx++, t++)
2599 /* prevent loop counter from being overwritten */
2604 coord_trans(&i, &j, xoffset, yoffset, transno);
2606 /* Extract the location */
2607 if (transno % 2 == 0)
2609 /* no swap of x/y */
2610 x = xval - (xmax / 2) + i;
2611 y = yval - (ymax / 2) + j;
2616 x = xval - (ymax / 2) + i;
2617 y = yval - (xmax / 2) + j;
2620 /* Hack -- skip "non-grids" */
2621 if (*t == ' ') continue;
2623 /* Access the grid */
2624 c_ptr = &cave[y][x];
2626 /* Lay down a floor */
2627 place_floor_grid(c_ptr);
2629 /* Remove any mimic */
2632 /* Part of a vault */
2633 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2635 /* Analyze the grid */
2638 /* Granite wall (outer) */
2640 place_outer_noperm_grid(c_ptr);
2643 /* Granite wall (inner) */
2645 place_inner_grid(c_ptr);
2648 /* Permanent wall (inner) */
2650 place_inner_perm_grid(c_ptr);
2655 if (randint0(100) < 75)
2657 place_object(y, x, 0L);
2667 place_secret_door(y, x);
2675 /* Black market in a dungeon */
2677 set_cave_feat(y, x, FEAT_SHOP_HEAD + STORE_BLACK);
2678 store_init(NO_TOWN, STORE_BLACK);
2683 set_cave_feat(y, x, FEAT_PATTERN_START);
2687 set_cave_feat(y, x, FEAT_PATTERN_1);
2691 set_cave_feat(y, x, FEAT_PATTERN_2);
2695 set_cave_feat(y, x, FEAT_PATTERN_3);
2699 set_cave_feat(y, x, FEAT_PATTERN_4);
2703 set_cave_feat(y, x, FEAT_PATTERN_END);
2707 set_cave_feat(y, x, FEAT_PATTERN_XTRA1);
2711 /* Reward for Pattern walk */
2712 object_level = base_level + 12;
2713 place_object(y, x, AM_GOOD | AM_GREAT);
2714 object_level = base_level;
2721 /* Place dungeon monsters and objects */
2722 for (t = data, dy = 0; dy < ymax; dy++)
2724 for (dx = 0; dx < xmax; dx++, t++)
2726 /* prevent loop counter from being overwritten */
2731 coord_trans(&i, &j, xoffset, yoffset, transno);
2733 /* Extract the location */
2734 if (transno % 2 == 0)
2736 /* no swap of x/y */
2737 x = xval - (xmax / 2) + i;
2738 y = yval - (ymax / 2) + j;
2743 x = xval - (ymax / 2) + i;
2744 y = yval - (xmax / 2) + j;
2747 /* Hack -- skip "non-grids" */
2748 if (*t == ' ') continue;
2750 /* Analyze the symbol */
2756 monster_level = base_level + 5;
2757 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2758 monster_level = base_level;
2762 /* Meaner monster */
2765 monster_level = base_level + 11;
2766 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2767 monster_level = base_level;
2771 /* Meaner monster, plus treasure */
2774 monster_level = base_level + 9;
2775 place_monster(y, x, PM_ALLOW_SLEEP);
2776 monster_level = base_level;
2777 object_level = base_level + 7;
2778 place_object(y, x, AM_GOOD);
2779 object_level = base_level;
2783 /* Nasty monster and treasure */
2786 monster_level = base_level + 40;
2787 place_monster(y, x, PM_ALLOW_SLEEP);
2788 monster_level = base_level;
2789 object_level = base_level + 20;
2790 place_object(y, x, AM_GOOD | AM_GREAT);
2791 object_level = base_level;
2795 /* Monster and/or object */
2798 if (randint0(100) < 50)
2800 monster_level = base_level + 3;
2801 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2802 monster_level = base_level;
2804 if (randint0(100) < 50)
2806 object_level = base_level + 7;
2807 place_object(y, x, 0L);
2808 object_level = base_level;
2820 * Type 7 -- simple vaults (see "v_info.txt")
2822 static bool build_type7(void)
2828 int xoffset, yoffset;
2831 /* Pick a lesser vault */
2832 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2834 /* Access a random vault record */
2835 v_ptr = &v_info[randint0(max_v_idx)];
2837 /* Accept the first lesser vault */
2838 if (v_ptr->typ == 7) break;
2841 /* No lesser vault found */
2842 if (dummy >= SAFE_MAX_ATTEMPTS)
2847 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2849 msg_print("Warning! Could not place lesser vault!");
2855 /* pick type of transformation (0-7) */
2856 transno = randint0(8);
2858 /* calculate offsets */
2862 /* Some huge vault cannot be ratated to fit in the dungeon */
2863 if (x+2 > cur_hgt-2)
2865 /* Forbid 90 or 270 degree ratation */
2869 coord_trans(&x, &y, 0, 0, transno);
2889 /* Find and reserve some space in the dungeon. Get center of room. */
2890 if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
2898 if (cheat_room) msg_format("¾®¤µ¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
2900 if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
2903 /* Hack -- Build the vault */
2904 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2905 v_text + v_ptr->text, xoffset, yoffset, transno);
2912 * Type 8 -- greater vaults (see "v_info.txt")
2914 static bool build_type8(void)
2921 int xoffset, yoffset;
2923 /* Pick a greater vault */
2924 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2926 /* Access a random vault record */
2927 v_ptr = &v_info[randint0(max_v_idx)];
2929 /* Accept the first greater vault */
2930 if (v_ptr->typ == 8) break;
2933 /* No greater vault found */
2934 if (dummy >= SAFE_MAX_ATTEMPTS)
2939 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2941 msg_print("Warning! Could not place greater vault!");
2947 /* pick type of transformation (0-7) */
2948 transno = randint0(8);
2950 /* calculate offsets */
2954 /* Some huge vault cannot be ratated to fit in the dungeon */
2955 if (x+2 > cur_hgt-2)
2957 /* Forbid 90 or 270 degree ratation */
2961 coord_trans(&x, &y, 0, 0, transno);
2982 * Try to allocate space for room. If fails, exit
2984 * Hack -- Prepare a bit larger space (+2, +2) to
2985 * prevent generation of vaults with no-entrance.
2987 /* Find and reserve some space in the dungeon. Get center of room. */
2988 if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
2991 v_ptr = &v_info[76 + randint1(3)];
2996 if (cheat_room) msg_format("µðÂç¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
2998 if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
3001 /* Hack -- Build the vault */
3002 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3003 v_text + v_ptr->text, xoffset, yoffset, transno);
3009 * Structure to hold all "fill" data
3012 typedef struct fill_data_type fill_data_type;
3014 struct fill_data_type
3027 /* features to fill with */
3036 /* number of filled squares */
3040 static fill_data_type fill_data;
3043 /* Store routine for the fractal cave generator */
3044 /* this routine probably should be an inline function or a macro. */
3045 static void store_height(int x, int y, int val)
3047 /* if on boundary set val > cutoff so walls are not as square */
3048 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3049 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3050 (val <= fill_data.c1)) val = fill_data.c1 + 1;
3052 /* store the value in height-map format */
3053 cave[y][x].feat = val;
3060 * Explanation of the plasma fractal algorithm:
3062 * A grid of points is created with the properties of a 'height-map'
3063 * This is done by making the corners of the grid have a random value.
3064 * The grid is then subdivided into one with twice the resolution.
3065 * The new points midway between two 'known' points can be calculated
3066 * by taking the average value of the 'known' ones and randomly adding
3067 * or subtracting an amount proportional to the distance between those
3068 * points. The final 'middle' points of the grid are then calculated
3069 * by averaging all four of the originally 'known' corner points. An
3070 * random amount is added or subtracted from this to get a value of the
3071 * height at that point. The scaling factor here is adjusted to the
3072 * slightly larger distance diagonally as compared to orthogonally.
3074 * This is then repeated recursively to fill an entire 'height-map'
3075 * A rectangular map is done the same way, except there are different
3076 * scaling factors along the x and y directions.
3078 * A hack to change the amount of correlation between points is done using
3079 * the grd variable. If the current step size is greater than grd then
3080 * the point will be random, otherwise it will be calculated by the
3081 * above algorithm. This makes a maximum distance at which two points on
3082 * the height map can affect each other.
3084 * How fractal caves are made:
3086 * When the map is complete, a cut-off value is used to create a cave.
3087 * Heights below this value are "floor", and heights above are "wall".
3088 * This also can be used to create lakes, by adding more height levels
3089 * representing shallow and deep water/ lava etc.
3091 * The grd variable affects the width of passages.
3092 * The roug variable affects the roughness of those passages
3094 * The tricky part is making sure the created cave is connected. This
3095 * is done by 'filling' from the inside and only keeping the 'filled'
3096 * floor. Walls bounding the 'filled' floor are also kept. Everything
3097 * else is converted to the normal _extra_.
3102 * Note that this uses the cave.feat array in a very hackish way
3103 * the values are first set to zero, and then each array location
3104 * is used as a "heightmap"
3105 * The heightmap then needs to be converted back into the "feat" format.
3107 * grd=level at which fractal turns on. smaller gives more mazelike caves
3108 * roug=roughness level. 16=normal. higher values make things more convoluted
3109 * small values are good for smooth walls.
3110 * size=length of the side of the square cave system.
3112 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3114 int xhsize, yhsize, xsize, ysize, maxsize;
3117 * fixed point variables- these are stored as 256 x normal value
3118 * this gives 8 binary places of fractional part + 8 places of normal part
3121 u16b xstep, xhstep, ystep, yhstep;
3122 u16b xstep2, xhstep2, ystep2, yhstep2;
3123 u16b i, j, ii, jj, diagsize, xxsize, yysize;
3125 /* Cache for speed */
3126 u16b xm, xp, ym, yp;
3128 /* redefine size so can change the value if out of range */
3132 /* Paranoia about size of the system of caves */
3133 if (xsize > 254) xsize = 254;
3134 if (xsize < 4) xsize = 4;
3135 if (ysize > 254) ysize = 254;
3136 if (ysize < 4) ysize = 4;
3138 /* get offsets to middle of array */
3142 /* fix rounding problem */
3146 /* get limits of region */
3147 fill_data.xmin = x0 - xhsize;
3148 fill_data.ymin = y0 - yhsize;
3149 fill_data.xmax = x0 + xhsize;
3150 fill_data.ymax = y0 + yhsize;
3152 /* Store cutoff in global for quick access */
3153 fill_data.c1 = cutoff;
3156 * Scale factor for middle points:
3157 * About sqrt(2) * 256 - correct for a square lattice
3158 * approximately correct for everything else.
3162 /* maximum of xsize and ysize */
3163 maxsize = (xsize > ysize) ? xsize : ysize;
3165 /* Clear the section */
3166 for (i = 0; i <= xsize; i++)
3168 for (j = 0; j <= ysize; j++)
3170 /* -1 is a flag for "not done yet" */
3171 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3172 /* Clear icky flag because may be redoing the cave */
3173 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3177 /* Boundaries are walls */
3178 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
3179 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
3180 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
3181 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
3183 /* Set the middle square to be an open area. */
3184 cave[y0][x0].feat = 0;
3186 /* Initialize the step sizes */
3187 xstep = xhstep = xsize * 256;
3188 ystep = yhstep = ysize * 256;
3189 xxsize = xsize * 256;
3190 yysize = ysize * 256;
3193 * Fill in the rectangle with fractal height data -
3194 * like the 'plasma fractal' in fractint.
3196 while ((xhstep > 256) || (yhstep > 256))
3198 /* Halve the step sizes */
3204 /* cache well used values */
3205 xstep2 = xstep / 256;
3206 ystep2 = ystep / 256;
3208 xhstep2 = xhstep / 256;
3209 yhstep2 = yhstep / 256;
3211 /* middle top to bottom. */
3212 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3214 for (j = 0; j <= yysize; j += ystep)
3216 /* cache often used values */
3217 ii = i / 256 + fill_data.xmin;
3218 jj = j / 256 + fill_data.ymin;
3221 if (cave[jj][ii].feat == -1)
3225 /* If greater than 'grid' level then is random */
3226 store_height(ii, jj, randint1(maxsize));
3230 /* Average of left and right points +random bit */
3231 store_height(ii, jj,
3232 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3233 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3234 + (randint1(xstep2) - xhstep2) * roug / 16);
3241 /* middle left to right. */
3242 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3244 for (i = 0; i <= xxsize; i += xstep)
3246 /* cache often used values */
3247 ii = i / 256 + fill_data.xmin;
3248 jj = j / 256 + fill_data.ymin;
3251 if (cave[jj][ii].feat == -1)
3255 /* If greater than 'grid' level then is random */
3256 store_height(ii, jj, randint1(maxsize));
3260 /* Average of up and down points +random bit */
3261 store_height(ii, jj,
3262 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3263 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3264 + (randint1(ystep2) - yhstep2) * roug / 16);
3271 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3273 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3275 /* cache often used values */
3276 ii = i / 256 + fill_data.xmin;
3277 jj = j / 256 + fill_data.ymin;
3280 if (cave[jj][ii].feat == -1)
3284 /* If greater than 'grid' level then is random */
3285 store_height(ii, jj, randint1(maxsize));
3289 /* Cache reused values. */
3290 xm = fill_data.xmin + (i - xhstep) / 256;
3291 xp = fill_data.xmin + (i + xhstep) / 256;
3292 ym = fill_data.ymin + (j - yhstep) / 256;
3293 yp = fill_data.ymin + (j + yhstep) / 256;
3296 * Average over all four corners + scale by diagsize to
3297 * reduce the effect of the square grid on the shape of the fractal
3299 store_height(ii, jj,
3300 (cave[ym][xm].feat + cave[yp][xm].feat
3301 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3302 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3311 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)
3314 * function used to convert from height-map back to the
3315 * normal angband cave format
3317 if (cave[y][x].info & CAVE_ICKY)
3324 /* Show that have looked at this square */
3325 cave[y][x].info|= (CAVE_ICKY);
3327 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3328 if (cave[y][x].feat <= c1)
3330 /* 25% of the time use the other tile : it looks better this way */
3331 if (randint1(100) < 75)
3333 cave[y][x].feat = feat1;
3334 cave[y][x].info &= ~(CAVE_MASK);
3335 cave[y][x].info |= info1;
3340 cave[y][x].feat = feat2;
3341 cave[y][x].info &= ~(CAVE_MASK);
3342 cave[y][x].info |= info2;
3346 else if (cave[y][x].feat <= c2)
3348 /* 25% of the time use the other tile : it looks better this way */
3349 if (randint1(100) < 75)
3351 cave[y][x].feat = feat2;
3352 cave[y][x].info &= ~(CAVE_MASK);
3353 cave[y][x].info |= info2;
3358 cave[y][x].feat = feat1;
3359 cave[y][x].info &= ~(CAVE_MASK);
3360 cave[y][x].info |= info1;
3364 else if (cave[y][x].feat <= c3)
3366 cave[y][x].feat = feat3;
3367 cave[y][x].info |= info3;
3370 /* if greater than cutoff then is a wall */
3373 place_outer_bold(y, x);
3383 * Quick and nasty fill routine used to find the connected region
3384 * of floor in the middle of the cave
3386 static void cave_fill(byte y, byte x)
3395 /*** Start Grid ***/
3397 /* Enqueue that entry */
3402 /* Now process the queue */
3403 while (flow_head != flow_tail)
3405 /* Extract the next entry */
3406 ty = temp_y[flow_head];
3407 tx = temp_x[flow_head];
3409 /* Forget that entry */
3410 if (++flow_head == TEMP_MAX) flow_head = 0;
3412 /* Add the "children" */
3413 for (d = 0; d < 8; d++)
3415 int old_head = flow_tail;
3417 /* Child location */
3418 j = ty + ddy_ddd[d];
3419 i = tx + ddx_ddd[d];
3421 /* Paranoia Don't leave the cave */
3422 if (!in_bounds(j, i))
3424 /* affect boundary */
3425 cave[j][i].info |= CAVE_ICKY;
3429 /* If within bounds */
3430 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3431 && (j > fill_data.ymin) && (j < fill_data.ymax))
3433 /* If not a wall or floor done before */
3434 if (hack_isnt_wall(j, i,
3435 fill_data.c1, fill_data.c2, fill_data.c3,
3436 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3437 fill_data.info1, fill_data.info2, fill_data.info3))
3439 /* Enqueue that entry */
3440 temp_y[flow_tail] = j;
3441 temp_x[flow_tail] = i;
3443 /* Advance the queue */
3444 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3446 /* Hack -- Overflow by forgetting new entry */
3447 if (flow_tail == flow_head)
3449 flow_tail = old_head;
3453 /* keep tally of size of cave system */
3454 (fill_data.amount)++;
3460 /* affect boundary */
3461 cave[j][i].info |= CAVE_ICKY;
3468 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3470 int x, y, i, xhsize, yhsize;
3472 /* offsets to middle from corner */
3478 * select region connected to center of cave system
3479 * this gets rid of alot of isolated one-sqaures that
3480 * can make teleport traps instadeaths...
3484 fill_data.c1 = cutoff;
3488 /* features to fill with */
3489 fill_data.feat1 = floor_type[randint0(100)];
3490 fill_data.feat2 = floor_type[randint0(100)];
3491 fill_data.feat3 = floor_type[randint0(100)];
3493 fill_data.info1 = CAVE_FLOOR;
3494 fill_data.info2 = CAVE_FLOOR;
3495 fill_data.info3 = CAVE_FLOOR;
3497 /* number of filled squares */
3498 fill_data.amount = 0;
3500 cave_fill((byte)y0, (byte)x0);
3502 /* if tally too small, try again */
3503 if (fill_data.amount < 10)
3505 /* too small - clear area and try again later */
3506 for (x = 0; x <= xsize; ++x)
3508 for (y = 0; y <= ysize; ++y)
3510 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3511 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3518 * Do boundarys-check to see if they are next to a filled region
3519 * If not then they are set to normal granite
3520 * If so then they are marked as room walls.
3522 for (i = 0; i <= xsize; ++i)
3525 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3527 /* Next to a 'filled' region? - set to be room walls */
3528 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3529 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3530 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3531 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3535 /* set to be normal granite */
3536 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3539 /* bottom boundary */
3540 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3542 /* Next to a 'filled' region? - set to be room walls */
3543 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3544 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3545 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3546 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3550 /* set to be normal granite */
3551 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3554 /* clear the icky flag-don't need it any more */
3555 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3556 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3559 /* Do the left and right boundaries minus the corners (done above) */
3560 for (i = 1; i < ysize; ++i)
3563 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3566 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3567 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3568 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3569 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3574 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3576 /* right boundary */
3577 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3580 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3581 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3582 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3583 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3588 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3591 /* clear icky flag -done with it */
3592 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3593 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3597 /* Do the rest: convert back to the normal format */
3598 for (x = 1; x < xsize; ++x)
3600 for (y = 1; y < ysize; ++y)
3602 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3603 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3605 /* Clear the icky flag in the filled region */
3606 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3608 /* Set appropriate flags */
3609 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3610 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3612 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3613 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3616 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3617 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3620 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3625 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3626 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3631 /* Clear the unconnected regions */
3632 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3633 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3639 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3640 * Extra doors appear inside the system. (Its not very noticeable though.)
3641 * This can be removed by "filling" from the outside in. This allows a separation
3642 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
3643 * The extra effort for what seems to be only a minor thing (even non-existant if you
3644 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3653 * Driver routine to create fractal cave system
3655 static bool build_type9(void)
3657 int grd, roug, cutoff, xsize, ysize, y0, x0;
3659 bool done, light, room;
3661 /* get size: note 'Evenness'*/
3662 xsize = randint1(22) * 2 + 6;
3663 ysize = randint1(15) * 2 + 6;
3665 /* Find and reserve some space in the dungeon. Get center of room. */
3666 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3668 /* Limit to the minimum room size, and retry */
3672 /* Find and reserve some space in the dungeon. Get center of room. */
3673 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3679 return build_type1();
3683 light = done = FALSE;
3686 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3690 /* Note: size must be even or there are rounding problems
3691 * This causes the tunnels not to connect properly to the room */
3693 /* testing values for these parameters feel free to adjust */
3694 grd = 1 << (randint0(4));
3696 /* want average of about 16 */
3697 roug = randint1(8) * randint1(4);
3700 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3701 randint1(xsize / 4) + randint1(ysize / 4);
3704 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3706 /* Convert to normal format + clean up */
3707 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3713 #ifdef ALLOW_CAVERNS_AND_LAKES
3715 * Builds a cave system in the center of the dungeon.
3717 void build_cavern(void)
3719 int grd, roug, cutoff, xsize, ysize, x0, y0;
3722 light = done = FALSE;
3723 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3725 /* Make a cave the size of the dungeon */
3726 xsize = cur_wid - 1;
3727 ysize = cur_hgt - 1;
3731 /* Paranoia: make size even */
3737 /* testing values for these parameters: feel free to adjust */
3738 grd = randint1(4) + 4;
3740 /* want average of about 16 */
3741 roug = randint1(8) * randint1(4);
3747 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3749 /* Convert to normal format+ clean up */
3750 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3754 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3756 int x, y, i, xhsize, yhsize;
3757 int feat1, feat2, feat3;
3759 /* offsets to middle from corner */
3763 /* Get features based on type */
3766 case LAKE_T_LAVA: /* Lava */
3767 feat1 = FEAT_DEEP_LAVA;
3768 feat2 = FEAT_SHAL_LAVA;
3769 feat3 = floor_type[randint0(100)];
3771 case LAKE_T_WATER: /* Water */
3772 feat1 = FEAT_DEEP_WATER;
3773 feat2 = FEAT_SHAL_WATER;
3774 feat3 = floor_type[randint0(100)];
3776 case LAKE_T_CAVE: /* Collapsed cave */
3777 feat1 = floor_type[randint0(100)];
3778 feat2 = floor_type[randint0(100)];
3779 feat3 = FEAT_RUBBLE;
3781 case LAKE_T_EARTH_VAULT: /* Earth vault */
3782 feat1 = FEAT_RUBBLE;
3783 feat2 = floor_type[randint0(100)];
3784 feat3 = FEAT_RUBBLE;
3786 case LAKE_T_AIR_VAULT: /* Air vault */
3791 case LAKE_T_WATER_VAULT: /* Water vault */
3792 feat1 = FEAT_SHAL_WATER;
3793 feat2 = FEAT_DEEP_WATER;
3794 feat3 = FEAT_SHAL_WATER;
3796 case LAKE_T_FIRE_VAULT: /* Fire Vault */
3797 feat1 = FEAT_SHAL_LAVA;
3798 feat2 = FEAT_DEEP_LAVA;
3799 feat3 = FEAT_SHAL_LAVA;
3803 default: return FALSE;
3807 * select region connected to center of cave system
3808 * this gets rid of alot of isolated one-sqaures that
3809 * can make teleport traps instadeaths...
3817 /* features to fill with */
3818 fill_data.feat1 = feat1;
3819 fill_data.feat2 = feat2;
3820 fill_data.feat3 = feat3;
3822 fill_data.info1 = 0;
3823 fill_data.info2 = 0;
3824 fill_data.info3 = 0;
3826 /* number of filled squares */
3827 fill_data.amount = 0;
3829 /* select region connected to center of cave system
3830 * this gets rid of alot of isolated one-sqaures that
3831 * can make teleport traps instadeaths... */
3832 cave_fill((byte)y0, (byte)x0);
3834 /* if tally too small, try again */
3835 if (fill_data.amount < 10)
3837 /* too small -clear area and try again later */
3838 for (x = 0; x <= xsize; ++x)
3840 for (y = 0; y <= ysize; ++y)
3842 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3843 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3849 /* Do boundarys- set to normal granite */
3850 for (i = 0; i <= xsize; ++i)
3852 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3853 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3855 /* clear the icky flag-don't need it any more */
3856 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3857 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3860 /* Do the left and right boundaries minus the corners (done above) */
3862 for (i = 1; i < ysize; ++i)
3864 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3865 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3867 /* clear icky flag -done with it */
3868 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3869 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3873 /* Do the rest: convert back to the normal format */
3874 for (x = 1; x < xsize; ++x)
3876 for (y = 1; y < ysize; ++y)
3878 /* Fill unconnected regions with granite */
3879 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3880 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3881 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3883 /* turn off icky flag (no longer needed.) */
3884 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3887 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
3889 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3899 * makes a lake/collapsed cave system in the center of the dungeon
3901 void build_lake(int type)
3903 int grd, roug, xsize, ysize, x0, y0;
3907 /* paranoia - exit if lake type out of range. */
3908 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
3910 msg_format("Invalid lake type (%d)", type);
3914 /* Make the size of the dungeon */
3915 xsize = cur_wid - 1;
3916 ysize = cur_hgt - 1;
3920 /* Paranoia: make size even */
3926 /* testing values for these parameters: feel free to adjust */
3927 grd = randint1(3) + 4;
3929 /* want average of about 16 */
3930 roug = randint1(8) * randint1(4);
3932 /* Make up size of various componants */
3936 /* Deep water/lava */
3937 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
3939 /* Shallow boundary */
3943 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
3945 /* Convert to normal format+ clean up */
3946 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
3949 #endif /* ALLOW_CAVERNS_AND_LAKES */
3953 * Routine used by the random vault creators to add a door to a location
3954 * Note that range checking has to be done in the calling routine.
3956 * The doors must be INSIDE the allocated region.
3958 static void add_door(int x, int y)
3960 /* Need to have a wall in the center square */
3961 if (!is_outer_bold(y, x)) return;
3968 * where x=don't care
3972 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
3973 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
3976 place_secret_door(y, x);
3978 /* set boundarys so don't get wide doors */
3979 place_solid_bold(y, x - 1);
3980 place_solid_bold(y, x + 1);
3989 * where x = don't care
3992 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
3993 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
3996 place_secret_door(y, x);
3998 /* set boundarys so don't get wide doors */
3999 place_solid_bold(y - 1, x);
4000 place_solid_bold(y + 1, x);
4006 * Routine that fills the empty areas of a room with treasure and monsters.
4008 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4010 int x, y, cx, cy, size;
4013 /* center of room:*/
4017 /* Rough measure of size of vault= sum of lengths of sides */
4018 size = abs(x2 - x1) + abs(y2 - y1);
4020 for (x = x1; x <= x2; x++)
4022 for (y = y1; y <= y2; y++)
4024 /* Thing added based on distance to center of vault
4025 * Difficulty is 1-easy to 10-hard */
4026 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4028 /* hack- empty square part of the time */
4029 if ((randint1(100) - difficulty * 3) > 50) value = 20;
4031 /* if floor, shallow water and lava */
4032 if (is_floor_bold(y, x) ||
4033 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4035 /* The smaller 'value' is, the better the stuff */
4038 /* Meanest monster + treasure */
4039 monster_level = base_level + 40;
4040 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4041 monster_level = base_level;
4042 object_level = base_level + 20;
4043 place_object(y, x, AM_GOOD);
4044 object_level = base_level;
4048 /* Mean monster +treasure */
4049 monster_level = base_level + 20;
4050 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4051 monster_level = base_level;
4052 object_level = base_level + 10;
4053 place_object(y, x, AM_GOOD);
4054 object_level = base_level;
4056 else if (value < 10)
4059 monster_level = base_level + 9;
4060 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4061 monster_level = base_level;
4063 else if (value < 17)
4065 /* Intentional Blank space */
4068 * (Want some of the vault to be empty
4069 * so have room for group monsters.
4070 * This is used in the hack above to lower
4071 * the density of stuff in the vault.)
4074 else if (value < 23)
4076 /* Object or trap */
4077 if (randint0(100) < 25)
4079 place_object(y, x, 0L);
4086 else if (value < 30)
4088 /* Monster and trap */
4089 monster_level = base_level + 5;
4090 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4091 monster_level = base_level;
4094 else if (value < 40)
4096 /* Monster or object */
4097 if (randint0(100) < 50)
4099 monster_level = base_level + 3;
4100 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4101 monster_level = base_level;
4103 if (randint0(100) < 50)
4105 object_level = base_level + 7;
4106 place_object(y, x, 0L);
4107 object_level = base_level;
4110 else if (value < 50)
4119 /* 20% monster, 40% trap, 20% object, 20% blank space */
4120 if (randint0(100) < 20)
4122 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4124 else if (randint0(100) < 50)
4128 else if (randint0(100) < 50)
4130 place_object(y, x, 0L);
4141 * This function creates a random vault that looks like a collection of bubbles.
4142 * It works by getting a set of coordinates that represent the center of each
4143 * bubble. The entire room is made by seeing which bubble center is closest. If
4144 * two centers are equidistant then the square is a wall, otherwise it is a floor.
4145 * The only exception is for squares really near a center, these are always floor.
4146 * (It looks better than without this check.)
4148 * Note: If two centers are on the same point then this algorithm will create a
4149 * blank bubble filled with walls. - This is prevented from happening.
4151 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4153 #define BUBBLENUM 10 /* number of bubbles */
4155 /* array of center points of bubbles */
4156 coord center[BUBBLENUM];
4159 u16b min1, min2, temp;
4162 /* Offset from center to top left hand corner */
4163 int xhsize = xsize / 2;
4164 int yhsize = ysize / 2;
4167 if (cheat_room) msg_print("Bubble Vault");
4169 /* Allocate center of bubbles */
4170 center[0].x = randint1(xsize - 3) + 1;
4171 center[0].y = randint1(ysize - 3) + 1;
4173 for (i = 1; i < BUBBLENUM; i++)
4177 /* get center and check to see if it is unique */
4182 x = randint1(xsize - 3) + 1;
4183 y = randint1(ysize - 3) + 1;
4185 for (j = 0; j < i; j++)
4187 /* rough test to see if there is an overlap */
4188 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4197 /* Top and bottom boundaries */
4198 for (i = 0; i < xsize; i++)
4200 int x = x0 - xhsize + i;
4202 place_outer_noperm_bold(y0 - yhsize + 0, x);
4203 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4204 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4205 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4208 /* Left and right boundaries */
4209 for (i = 1; i < ysize - 1; i++)
4211 int y = y0 - yhsize + i;
4213 place_outer_noperm_bold(y, x0 - xhsize + 0);
4214 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4215 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4216 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4219 /* Fill in middle with bubbles */
4220 for (x = 1; x < xsize - 1; x++)
4222 for (y = 1; y < ysize - 1; y++)
4224 /* Get distances to two closest centers */
4227 min1 = distance(x, y, center[0].x, center[0].y);
4228 min2 = distance(x, y, center[1].x, center[1].y);
4232 /* swap if in wrong order */
4239 for (i = 2; i < BUBBLENUM; i++)
4241 temp = distance(x, y, center[i].x, center[i].y);
4249 else if (temp < min2)
4251 /* second smallest */
4255 if (((min2 - min1) <= 2) && (!(min1 < 3)))
4257 /* Boundary at midpoint+ not at inner region of bubble */
4258 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4262 /* middle of a bubble */
4263 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4266 /* clean up rest of flags */
4267 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4271 /* Try to add some random doors */
4272 for (i = 0; i < 500; i++)
4274 x = randint1(xsize - 3) - xhsize + x0 + 1;
4275 y = randint1(ysize - 3) - yhsize + y0 + 1;
4279 /* Fill with monsters and treasure, low difficulty */
4280 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4285 * Overlay a rectangular room given its bounds
4286 * This routine is used by build_room_vault
4287 * The area inside the walls is not touched:
4288 * only granite is removed- normal walls stay
4290 static void build_room(int x1, int x2, int y1, int y2)
4292 int x, y, i, xsize, ysize, temp;
4294 /* Check if rectangle has no width */
4295 if ((x1 == x2) || (y1 == y2)) return;
4300 /* Swap boundaries if in wrong order */
4308 /* Swap boundaries if in wrong order */
4314 /* get total widths */
4319 /* Top and bottom boundaries */
4320 for (i = 0; i <= xsize; i++)
4322 place_outer_noperm_bold(y1, x1 + i);
4323 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4324 place_outer_noperm_bold(y2, x1 + i);
4325 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4328 /* Left and right boundaries */
4329 for (i = 1; i < ysize; i++)
4331 place_outer_noperm_bold(y1 + i, x1);
4332 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4333 place_outer_noperm_bold(y1 + i, x2);
4334 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4338 for (x = 1; x < xsize; x++)
4340 for (y = 1; y < ysize; y++)
4342 if (is_extra_bold(y1+y, x1+x))
4344 /* clear the untouched region */
4345 place_floor_bold(y1 + y, x1 + x);
4346 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4350 /* make it a room- but don't touch */
4351 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4358 /* Create a random vault that looks like a collection of overlapping rooms */
4360 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4362 int i, x1, x2, y1, y2, xhsize, yhsize;
4364 /* get offset from center */
4368 if (cheat_room) msg_print("Room Vault");
4370 /* fill area so don't get problems with arena levels */
4371 for (x1 = 0; x1 < xsize; x1++)
4373 int x = x0 - xhsize + x1;
4375 for (y1 = 0; y1 < ysize; y1++)
4377 int y = y0 - yhsize + y1;
4379 place_extra_bold(y, x);
4380 cave[y][x].info &= (~CAVE_ICKY);
4384 /* add ten random rooms */
4385 for (i = 0; i < 10; i++)
4387 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4388 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4389 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4390 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4391 build_room(x1, x2, y1, y2);
4394 /* Add some random doors */
4395 for (i = 0; i < 500; i++)
4397 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4398 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4402 /* Fill with monsters and treasure, high difficulty */
4403 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4407 /* Create a random vault out of a fractal cave */
4408 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4410 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4411 bool done, light, room;
4413 /* round to make sizes even */
4419 if (cheat_room) msg_print("Cave Vault");
4421 light = done = FALSE;
4426 /* testing values for these parameters feel free to adjust */
4427 grd = 1 << randint0(4);
4429 /* want average of about 16 */
4430 roug = randint1(8) * randint1(4);
4433 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4434 randint1(xsize / 4) + randint1(ysize / 4);
4437 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4439 /* Convert to normal format+ clean up */
4440 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4443 /* Set icky flag because is a vault */
4444 for (x = 0; x <= xsize; x++)
4446 for (y = 0; y <= ysize; y++)
4448 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4452 /* Fill with monsters and treasure, low difficulty */
4453 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4457 * maze vault -- rectangular labyrinthine rooms
4459 * maze vault uses two routines:
4460 * r_visit - a recursive routine that builds the labyrinth
4461 * build_maze_vault - a driver routine that calls r_visit and adds
4462 * monsters, traps and treasure
4464 * The labyrinth is built by creating a spanning tree of a graph.
4465 * The graph vertices are at
4466 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4467 * and the edges are the vertical and horizontal nearest neighbors.
4469 * The spanning tree is created by performing a suitably randomized
4470 * depth-first traversal of the graph. The only adjustable parameter
4471 * is the randint0(3) below; it governs the relative density of
4472 * twists and turns in the labyrinth: smaller number, more twists.
4474 static void r_visit(int y1, int x1, int y2, int x2,
4475 int node, int dir, int *visited)
4477 int i, j, m, n, temp, x, y, adj[4];
4479 /* dimensions of vertex array */
4480 m = (x2 - x1) / 2 + 1;
4481 n = (y2 - y1) / 2 + 1;
4483 /* mark node visited and set it to a floor */
4485 x = 2 * (node % m) + x1;
4486 y = 2 * (node / m) + y1;
4487 place_floor_bold(y, x);
4489 /* setup order of adjacent node visits */
4492 /* pick a random ordering */
4493 for (i = 0; i < 4; i++)
4495 for (i = 0; i < 4; i++)
4506 /* pick a random ordering with dir first */
4508 for (i = 1; i < 4; i++)
4510 for (i = 1; i < 4; i++)
4512 j = 1 + randint0(3);
4519 for (i = 0; i < 4; i++)
4524 /* (0,+) - check for bottom boundary */
4525 if ((node / m < n - 1) && (visited[node + m] == 0))
4527 place_floor_bold(y + 1, x);
4528 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4532 /* (0,-) - check for top boundary */
4533 if ((node / m > 0) && (visited[node - m] == 0))
4535 place_floor_bold(y - 1, x);
4536 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4540 /* (+,0) - check for right boundary */
4541 if ((node % m < m - 1) && (visited[node + 1] == 0))
4543 place_floor_bold(y, x + 1);
4544 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4548 /* (-,0) - check for left boundary */
4549 if ((node % m > 0) && (visited[node - 1] == 0))
4551 place_floor_bold(y, x - 1);
4552 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4559 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4563 int m, n, num_vertices, *visited;
4568 if (cheat_room && is_vault) msg_print("Maze Vault");
4570 /* Choose lite or dark */
4571 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4573 /* Pick a random room size - randomized by calling routine */
4582 /* generate the room */
4583 for (y = y1 - 1; y <= y2 + 1; y++)
4585 for (x = x1 - 1; x <= x2 + 1; x++)
4587 c_ptr = &cave[y][x];
4588 c_ptr->info |= CAVE_ROOM;
4589 if (is_vault) c_ptr->info |= CAVE_ICKY;
4590 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4592 place_outer_grid(c_ptr);
4596 place_extra_grid(c_ptr);
4600 place_inner_grid(c_ptr);
4602 if (light) c_ptr->info |= (CAVE_GLOW);
4606 /* dimensions of vertex array */
4609 num_vertices = m * n;
4611 /* initialize array of visited vertices */
4612 C_MAKE(visited, num_vertices, int);
4614 /* traverse the graph to create a spaning tree, pick a random root */
4615 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4617 /* Fill with monsters and treasure, low difficulty */
4618 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4620 C_KILL(visited, num_vertices, int);
4624 /* Build a "mini" checkerboard vault
4626 * This is done by making a permanent wall maze and setting
4627 * the diagonal sqaures of the checker board to be granite.
4628 * The vault has two entrances on opposite sides to guarantee
4629 * a way to get in even if the vault abuts a side of the dungeon.
4631 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4634 int y1, x1, y2, x2, y, x, total;
4635 int m, n, num_vertices;
4638 if (cheat_room) msg_print("Mini Checker Board Vault");
4640 /* Pick a random room size */
4650 /* generate the room */
4651 for (x = x1 - 2; x <= x2 + 2; x++)
4653 if (!in_bounds(y1-2,x)) break;
4655 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4657 place_outer_noperm_bold(y1-2, x);
4660 for (x = x1 - 2; x <= x2 + 2; x++)
4662 if (!in_bounds(y2+2,x)) break;
4664 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4666 place_outer_noperm_bold(y2+2, x);
4669 for (y = y1 - 2; y <= y2 + 2; y++)
4671 if (!in_bounds(y,x1-2)) break;
4673 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4675 place_outer_noperm_bold(y, x1-2);
4678 for (y = y1 - 2; y <= y2 + 2; y++)
4680 if (!in_bounds(y,x2+2)) break;
4682 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4684 place_outer_noperm_bold(y, x2+2);
4687 for (y = y1 - 1; y <= y2 + 1; y++)
4689 for (x = x1 - 1; x <= x2 + 1; x++)
4691 cave_type *c_ptr = &cave[y][x];
4693 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4695 /* Permanent walls */
4696 place_inner_perm_grid(c_ptr);
4701 /* dimensions of vertex array */
4704 num_vertices = m * n;
4706 /* initialize array of visited vertices */
4707 C_MAKE(visited, num_vertices, int);
4709 /* traverse the graph to create a spannng tree, pick a random root */
4710 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4712 /* Make it look like a checker board vault */
4713 for (x = x1; x <= x2; x++)
4715 for (y = y1; y <= y2; y++)
4717 total = x - x1 + y - y1;
4718 /* If total is odd- and is a floor then make a wall */
4719 if ((total % 2 == 1) && is_floor_bold(y, x))
4721 place_inner_bold(y, x);
4726 /* Make a couple of entrances */
4729 /* left and right */
4730 y = randint1(dy) + dy / 2;
4731 place_inner_bold(y1 + y, x1 - 1);
4732 place_inner_bold(y1 + y, x2 + 1);
4736 /* top and bottom */
4737 x = randint1(dx) + dx / 2;
4738 place_inner_bold(y1 - 1, x1 + x);
4739 place_inner_bold(y2 + 1, x1 + x);
4742 /* Fill with monsters and treasure, highest difficulty */
4743 fill_treasure(x1, x2, y1, y2, 10);
4745 C_KILL(visited, num_vertices, int);
4749 /* Build a town/ castle by using a recursive algorithm.
4750 * Basically divide each region in a probalistic way to create
4751 * smaller regions. When the regions get too small stop.
4753 * The power variable is a measure of how well defended a region is.
4754 * This alters the possible choices.
4756 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4762 /* Temp variables */
4768 if ((power < 3) && (xsize > 12) && (ysize > 12))
4770 /* Need outside wall +keep */
4777 /* Make rooms + subdivide */
4778 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4784 choice = randint1(2) + 1;
4789 /* Mostly subdivide */
4790 choice = randint1(3) + 1;
4794 /* Based on the choice made above, do something */
4802 /* top and bottom */
4803 for (x = x1; x <= x2; x++)
4805 place_outer_bold(y1, x);
4806 place_outer_bold(y2, x);
4809 /* left and right */
4810 for (y = y1 + 1; y < y2; y++)
4812 place_outer_bold(y, x1);
4813 place_outer_bold(y, x2);
4816 /* Make a couple of entrances */
4819 /* left and right */
4820 y = randint1(ysize) + y1;
4821 place_floor_bold(y, x1);
4822 place_floor_bold(y, x2);
4826 /* top and bottom */
4827 x = randint1(xsize) + x1;
4828 place_floor_bold(y1, x);
4829 place_floor_bold(y2, x);
4832 /* Select size of keep */
4833 t1 = randint1(ysize / 3) + y1;
4834 t2 = y2 - randint1(ysize / 3);
4835 t3 = randint1(xsize / 3) + x1;
4836 t4 = x2 - randint1(xsize / 3);
4838 /* Do outside areas */
4840 /* Above and below keep */
4841 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4842 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4844 /* Left and right of keep */
4845 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4846 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4848 /* Make the keep itself: */
4861 /* Try to build a room */
4862 if ((xsize < 3) || (ysize < 3))
4864 for (y = y1; y < y2; y++)
4866 for (x = x1; x < x2; x++)
4868 place_inner_bold(y, x);
4876 /* Make outside walls */
4877 /* top and bottom */
4878 for (x = x1 + 1; x <= x2 - 1; x++)
4880 place_inner_bold(y1 + 1, x);
4881 place_inner_bold(y2 - 1, x);
4884 /* left and right */
4885 for (y = y1 + 1; y <= y2 - 1; y++)
4887 place_inner_bold(y, x1 + 1);
4888 place_inner_bold(y, x2 - 1);
4892 y = randint1(ysize - 3) + y1 + 1;
4897 place_floor_bold(y, x1 + 1);
4902 place_floor_bold(y, x2 - 1);
4905 /* Build the room */
4906 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4911 /* Try and divide vertically */
4915 for (y = y1; y < y2; y++)
4917 for (x = x1; x < x2; x++)
4919 place_inner_bold(y, x);
4925 t1 = randint1(xsize - 2) + x1 + 1;
4926 build_recursive_room(x1, y1, t1, y2, power - 2);
4927 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
4932 /* Try and divide horizontally */
4936 for (y = y1; y < y2; y++)
4938 for (x = x1; x < x2; x++)
4940 place_inner_bold(y, x);
4946 t1 = randint1(ysize - 2) + y1 + 1;
4947 build_recursive_room(x1, y1, x2, t1, power - 2);
4948 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
4955 /* Build a castle */
4957 /* Driver routine: clear the region and call the recursive
4960 *This makes a vault that looks like a castle/ city in the dungeon.
4962 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
4968 /* Pick a random room size */
4977 if (cheat_room) msg_print("Castle Vault");
4979 /* generate the room */
4980 for (y = y1 - 1; y <= y2 + 1; y++)
4982 for (x = x1 - 1; x <= x2 + 1; x++)
4984 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
4985 /* Make everything a floor */
4986 place_floor_bold(y, x);
4990 /* Make the castle */
4991 build_recursive_room(x1, y1, x2, y2, randint1(5));
4993 /* Fill with monsters and treasure, low difficulty */
4994 fill_treasure(x1, x2, y1, y2, randint1(3));
4999 * Add outer wall to a floored region
5000 * Note: no range checking is done so must be inside dungeon
5001 * This routine also stomps on doors
5003 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5006 feature_type *f_ptr;
5009 if (!in_bounds(y, x)) return;
5011 c_ptr = &cave[y][x];
5013 /* hack- check to see if square has been visited before
5014 * if so, then exit (use room flag to do this) */
5015 if (c_ptr->info & CAVE_ROOM) return;
5018 c_ptr->info |= CAVE_ROOM;
5020 f_ptr = &f_info[c_ptr->feat];
5022 if (is_floor_bold(y, x))
5024 for (i = -1; i <= 1; i++)
5026 for (j = -1; j <= 1; j++)
5028 if ((x + i >= x1) && (x + i <= x2) &&
5029 (y + j >= y1) && (y + j <= y2))
5031 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5032 if (light) c_ptr->info |= CAVE_GLOW;
5037 else if (is_extra_bold(y, x))
5039 /* Set bounding walls */
5040 place_outer_bold(y, x);
5041 if (light) c_ptr->info |= CAVE_GLOW;
5043 else if (permanent_wall(f_ptr))
5045 /* Set bounding walls */
5046 if (light) c_ptr->info |= CAVE_GLOW;
5052 * Hacked distance formula - gives the 'wrong' answer.
5053 * Used to build crypts
5055 static int dist2(int x1, int y1, int x2, int y2,
5056 int h1, int h2, int h3, int h4)
5062 /* Basically this works by taking the normal pythagorean formula
5063 * and using an expansion to express this in a way without the
5064 * square root. This approximate formula is then perturbed to give
5065 * the distorted results. (I found this by making a mistake when I was
5066 * trying to fix the circular rooms.)
5069 /* h1-h4 are constants that describe the metric */
5070 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5071 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5072 return (((dx + dy) * 128) / 181 +
5073 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5074 /* 128/181 is approx. 1/sqrt(2) */
5079 * Build target vault.
5080 * This is made by two concentric "crypts" with perpendicular
5081 * walls creating the cross-hairs.
5083 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5087 /* Make a random metric */
5089 h1 = randint1(32) - 16;
5092 h4 = randint1(32) - 16;
5094 if (cheat_room) msg_print("Target Vault");
5096 /* work out outer radius */
5107 for (x = x0 - rad; x <= x0 + rad; x++)
5109 for (y = y0 - rad; y <= y0 + rad; y++)
5111 /* clear room flag */
5112 cave[y][x].info &= ~(CAVE_ROOM);
5114 /* Vault - so is "icky" */
5115 cave[y][x].info |= CAVE_ICKY;
5117 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5119 /* inside- so is floor */
5120 place_floor_bold(y, x);
5124 /* make granite outside so arena works */
5125 place_extra_bold(y, x);
5128 /* proper boundary for arena */
5129 if (((y + rad) == y0) || ((y - rad) == y0) ||
5130 ((x + rad) == x0) || ((x - rad) == x0))
5132 place_extra_bold(y, x);
5137 /* Find visible outer walls and set to be FEAT_OUTER */
5138 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5139 x0 + rad + 1, y0 + rad + 1);
5141 /* Add inner wall */
5142 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5144 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5146 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5148 /* Make an internal wall */
5149 place_inner_bold(y, x);
5154 /* Add perpendicular walls */
5155 for (x = x0 - rad; x <= x0 + rad; x++)
5157 place_inner_bold(y0, x);
5160 for (y = y0 - rad; y <= y0 + rad; y++)
5162 place_inner_bold(y, x0);
5165 /* Make inner vault */
5166 for (y = y0 - 1; y <= y0 + 1; y++)
5168 place_inner_bold(y, x0 - 1);
5169 place_inner_bold(y, x0 + 1);
5171 for (x = x0 - 1; x <= x0 + 1; x++)
5173 place_inner_bold(y0 - 1, x);
5174 place_inner_bold(y0 + 1, x);
5177 place_floor_bold(y0, x0);
5180 /* Add doors to vault */
5181 /* get two distances so can place doors relative to centre */
5182 x = (rad - 2) / 4 + 1;
5185 add_door(x0 + x, y0);
5186 add_door(x0 + y, y0);
5187 add_door(x0 - x, y0);
5188 add_door(x0 - y, y0);
5189 add_door(x0, y0 + x);
5190 add_door(x0, y0 + y);
5191 add_door(x0, y0 - x);
5192 add_door(x0, y0 - y);
5194 /* Fill with stuff - medium difficulty */
5195 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5199 #ifdef ALLOW_CAVERNS_AND_LAKES
5201 * This routine uses a modified version of the lake code to make a
5202 * distribution of some terrain type over the vault. This type
5203 * depends on the dungeon depth.
5205 * Miniture rooms are then scattered across the vault.
5207 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5212 int xsize, ysize, xhsize, yhsize, x, y, i;
5216 if (cheat_room) msg_print("Elemental Vault");
5218 /* round to make sizes even */
5226 /* Earth vault (Rubble) */
5227 type = LAKE_T_EARTH_VAULT;
5229 else if (dun_level < 50)
5231 /* Air vault (Trees) */
5232 type = LAKE_T_AIR_VAULT;
5234 else if (dun_level < 75)
5236 /* Water vault (shallow water) */
5237 type = LAKE_T_WATER_VAULT;
5241 /* Fire vault (shallow lava) */
5242 type = LAKE_T_FIRE_VAULT;
5247 /* testing values for these parameters: feel free to adjust */
5248 grd = 1 << (randint0(3));
5250 /* want average of about 16 */
5251 roug = randint1(8) * randint1(4);
5253 /* Make up size of various componants */
5257 /* Deep water/lava */
5258 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5260 /* Shallow boundary */
5264 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5266 /* Convert to normal format+ clean up */
5267 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5270 /* Set icky flag because is a vault */
5271 for (x = 0; x <= xsize; x++)
5273 for (y = 0; y <= ysize; y++)
5275 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5279 /* make a few rooms in the vault */
5280 for (i = 1; i <= (xsize * ysize) / 50; i++)
5282 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5283 y0 + randint0(ysize - 4) - ysize / 2 + 2);
5286 /* Fill with monsters and treasure, low difficulty */
5287 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5288 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5290 #endif /* ALLOW_CAVERNS_AND_LAKES */
5296 static bool build_type10(void)
5298 int y0, x0, xsize, ysize, vtype;
5301 /* big enough to look good, small enough to be fairly common. */
5302 xsize = randint1(22) + 22;
5303 ysize = randint1(11) + 11;
5305 /* Find and reserve some space in the dungeon. Get center of room. */
5306 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5308 /* Select type of vault */
5309 #ifdef ALLOW_CAVERNS_AND_LAKES
5310 vtype = randint1(15);
5311 #else /* ALLOW_CAVERNS_AND_LAKES */
5312 vtype = randint1(7);
5313 #endif /* ALLOW_CAVERNS_AND_LAKES */
5317 /* Build an appropriate room */
5318 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
5319 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5320 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5321 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5322 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5323 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5324 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5325 #ifdef ALLOW_CAVERNS_AND_LAKES
5326 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5327 #endif /* ALLOW_CAVERNS_AND_LAKES */
5328 /* I know how to add a few more... give me some time. */
5331 default: return FALSE;
5339 * Build an vertical oval room.
5340 * For every grid in the possible square, check the distance.
5341 * If it's less than the radius, make it a room square.
5343 * When done fill from the inside to find the walls,
5345 static bool build_type11(void)
5347 int rad, x, y, x0, y0;
5350 /* Occasional light */
5351 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5355 /* Find and reserve some space in the dungeon. Get center of room. */
5356 if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5358 /* Make circular floor */
5359 for (x = x0 - rad; x <= x0 + rad; x++)
5361 for (y = y0 - rad; y <= y0 + rad; y++)
5363 if (distance(y0, x0, y, x) <= rad - 1)
5365 /* inside- so is floor */
5366 place_floor_bold(y, x);
5368 else if (distance(y0, x0, y, x) <= rad + 1)
5370 /* make granite outside so arena works */
5371 place_extra_bold(y, x);
5376 /* Find visible outer walls and set to be FEAT_OUTER */
5377 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5385 * For every grid in the possible square, check the (fake) distance.
5386 * If it's less than the radius, make it a room square.
5388 * When done fill from the inside to find the walls,
5390 static bool build_type12(void)
5392 int rad, x, y, x0, y0;
5394 bool emptyflag = TRUE;
5396 /* Make a random metric */
5398 h1 = randint1(32) - 16;
5401 h4 = randint1(32) - 16;
5403 /* Occasional light */
5404 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5408 /* Find and reserve some space in the dungeon. Get center of room. */
5409 if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5412 for (x = x0 - rad; x <= x0 + rad; x++)
5414 for (y = y0 - rad; y <= y0 + rad; y++)
5416 /* clear room flag */
5417 cave[y][x].info &= ~(CAVE_ROOM);
5419 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5421 /* inside - so is floor */
5422 place_floor_bold(y, x);
5424 else if (distance(y0, x0, y, x) < 3)
5426 place_floor_bold(y, x);
5430 /* make granite outside so arena works */
5431 place_extra_bold(y, x);
5434 /* proper boundary for arena */
5435 if (((y + rad) == y0) || ((y - rad) == y0) ||
5436 ((x + rad) == x0) || ((x - rad) == x0))
5438 place_extra_bold(y, x);
5443 /* Find visible outer walls and set to be FEAT_OUTER */
5444 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5445 x0 + rad + 1, y0 + rad + 1);
5447 /* Check to see if there is room for an inner vault */
5448 for (x = x0 - 2; x <= x0 + 2; x++)
5450 for (y = y0 - 2; y <= y0 + 2; y++)
5452 if (!is_floor_bold(y, x))
5454 /* Wall in the way */
5460 if (emptyflag && one_in_(2))
5462 /* Build the vault */
5463 build_small_room(x0, y0);
5465 /* Place a treasure in the vault */
5466 place_object(y0, x0, 0L);
5468 /* Let's guard the treasure well */
5469 vault_monsters(y0, x0, randint0(2) + 3);
5471 /* Traps naturally */
5472 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5480 * Helper function for "trapped monster pit"
5482 static bool vault_aux_trapped_pit(int r_idx)
5484 monster_race *r_ptr = &r_info[r_idx];
5486 /* Validate the monster */
5487 if (!vault_monster_okay(r_idx)) return (FALSE);
5489 /* No wall passing monster */
5490 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5498 * Type 12 -- Trapped monster pits
5500 * A trapped monster pit is a "big" room with a straight corridor in
5501 * which wall opening traps are placed, and with two "inner" rooms
5502 * containing a "collection" of monsters of a given type organized in
5505 * The trapped monster pit appears as shown below, where the actual
5506 * monsters in each location depend on the type of the pit
5508 * #########################
5510 * ####################### #
5511 * #####001123454321100### #
5512 * ###0012234567654322100# #
5513 * ####################### #
5515 * # #######################
5516 * # #0012234567654322100###
5517 * # ###001123454321100#####
5518 * # #######################
5520 * #########################
5522 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5523 * to request 16 "appropriate" monsters, sorting them by level, and using
5524 * the "even" entries in this sorted list for the contents of the pit.
5526 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5527 * which is handled by requiring a specific "breath" attack for all of the
5528 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5529 * be present in many of the dragon pits, if they have the proper breath.
5531 * Note the use of the "get_mon_num_prep()" function, and the special
5532 * "get_mon_num_hook()" restriction function, to prepare the "monster
5533 * allocation table" in such a way as to optimize the selection of
5534 * "appropriate" non-unique monsters for the pit.
5536 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5537 * the pit will be empty.
5539 * Note that "monster pits" will never contain "unique" monsters.
5541 static bool build_type13(void)
5543 static int placing[][3] = {
5544 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5545 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5546 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5547 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5548 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5549 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5550 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5551 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5552 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5553 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5554 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5555 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5556 {-2, -4, 3}, {-3, -2, 3},
5557 {+2, -4, 3}, {+3, -2, 3},
5558 {-2, +4, 3}, {-3, +2, 3},
5559 {+2, +4, 3}, {+3, +2, 3},
5560 {-2, -3, 4}, {-3, -1, 4},
5561 {+2, -3, 4}, {+3, -1, 4},
5562 {-2, +3, 4}, {-3, +1, 4},
5563 {+2, +3, 4}, {+3, +1, 4},
5564 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5565 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5566 {-2, -1, 6}, {-2, +1, 6},
5567 {+2, -1, 6}, {+2, +1, 6},
5568 {-2, 0, 7}, {+2, 0, 7},
5572 int y, x, y1, x1, y2, x2, xval, yval;
5581 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5582 vault_aux_type *n_ptr;
5584 /* Only in Angband */
5585 if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5587 /* No type available */
5588 if (cur_pit_type < 0) return FALSE;
5590 n_ptr = &pit_types[cur_pit_type];
5592 /* Process a preparation function if necessary */
5593 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5595 /* Prepare allocation table */
5596 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5598 align.sub_align = SUB_ALIGN_NEUTRAL;
5600 /* Pick some monster types */
5601 for (i = 0; i < 16; i++)
5603 int r_idx = 0, attempts = 100;
5604 monster_race *r_ptr = NULL;
5608 /* Get a (hard) monster type */
5609 r_idx = get_mon_num(dun_level + 0);
5610 r_ptr = &r_info[r_idx];
5612 /* Decline incorrect alignment */
5613 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5615 /* Accept this monster */
5619 /* Notice failure */
5620 if (!r_idx || !attempts) return FALSE;
5622 /* Note the alignment */
5623 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5624 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5629 /* Find and reserve some space in the dungeon. Get center of room. */
5630 if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5638 /* Fill with inner walls */
5639 for (y = y1 - 1; y <= y2 + 1; y++)
5641 for (x = x1 - 1; x <= x2 + 1; x++)
5643 c_ptr = &cave[y][x];
5644 place_inner_grid(c_ptr);
5645 c_ptr->info |= (CAVE_ROOM);
5649 /* Place the floor area 1 */
5650 for (x = x1 + 3; x <= x2 - 3; x++)
5652 c_ptr = &cave[yval-2][x];
5653 place_floor_grid(c_ptr);
5654 add_cave_info(yval-2, x, CAVE_ICKY);
5656 c_ptr = &cave[yval+2][x];
5657 place_floor_grid(c_ptr);
5658 add_cave_info(yval+2, x, CAVE_ICKY);
5661 /* Place the floor area 2 */
5662 for (x = x1 + 5; x <= x2 - 5; x++)
5664 c_ptr = &cave[yval-3][x];
5665 place_floor_grid(c_ptr);
5666 add_cave_info(yval-3, x, CAVE_ICKY);
5668 c_ptr = &cave[yval+3][x];
5669 place_floor_grid(c_ptr);
5670 add_cave_info(yval+3, x, CAVE_ICKY);
5674 for (x = x1; x <= x2; x++)
5676 c_ptr = &cave[yval][x];
5677 place_floor_grid(c_ptr);
5678 c_ptr = &cave[y1][x];
5679 place_floor_grid(c_ptr);
5680 c_ptr = &cave[y2][x];
5681 place_floor_grid(c_ptr);
5684 /* Place the outer walls */
5685 for (y = y1 - 1; y <= y2 + 1; y++)
5687 c_ptr = &cave[y][x1 - 1];
5688 place_outer_grid(c_ptr);
5689 c_ptr = &cave[y][x2 + 1];
5690 place_outer_grid(c_ptr);
5692 for (x = x1 - 1; x <= x2 + 1; x++)
5694 c_ptr = &cave[y1 - 1][x];
5695 place_outer_grid(c_ptr);
5696 c_ptr = &cave[y2 + 1][x];
5697 place_outer_grid(c_ptr);
5700 /* Random corridor */
5703 for (y = y1; y <= yval; y++)
5705 place_floor_bold(y, x2);
5706 place_solid_bold(y, x1-1);
5708 for (y = yval; y <= y2 + 1; y++)
5710 place_floor_bold(y, x1);
5711 place_solid_bold(y, x2+1);
5716 for (y = yval; y <= y2 + 1; y++)
5718 place_floor_bold(y, x1);
5719 place_solid_bold(y, x2+1);
5721 for (y = y1; y <= yval; y++)
5723 place_floor_bold(y, x2);
5724 place_solid_bold(y, x1-1);
5728 /* Place the wall open trap */
5729 cave[yval][xval].mimic = cave[yval][xval].feat;
5730 cave[yval][xval].feat = FEAT_TRAP_OPEN;
5732 /* Sort the entries */
5733 for (i = 0; i < 16 - 1; i++)
5735 /* Sort the entries */
5736 for (j = 0; j < 16 - 1; j++)
5741 int p1 = r_info[what[i1]].level;
5742 int p2 = r_info[what[i2]].level;
5748 what[i1] = what[i2];
5759 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5761 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5765 /* Select the entries */
5766 for (i = 0; i < 8; i++)
5768 /* Every other entry */
5769 what[i] = what[i * 2];
5774 msg_print(r_name + r_info[what[i]].name);
5778 for (i = 0; placing[i][2] >= 0; i++)
5780 y = yval + placing[i][0];
5781 x = xval + placing[i][1];
5782 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5790 * Type 14 -- trapped rooms
5792 * A special trap is placed at center of the room
5794 static bool build_type14(void)
5796 int y, x, y2, x2, yval, xval;
5797 int y1, x1, xsize, ysize;
5804 /* Pick a room size */
5810 xsize = x1 + x2 + 1;
5811 ysize = y1 + y2 + 1;
5813 /* Find and reserve some space in the dungeon. Get center of room. */
5814 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5816 /* Choose lite or dark */
5817 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5820 /* Get corner values */
5821 y1 = yval - ysize / 2;
5822 x1 = xval - xsize / 2;
5823 y2 = yval + (ysize - 1) / 2;
5824 x2 = xval + (xsize - 1) / 2;
5827 /* Place a full floor under the room */
5828 for (y = y1 - 1; y <= y2 + 1; y++)
5830 for (x = x1 - 1; x <= x2 + 1; x++)
5832 c_ptr = &cave[y][x];
5833 place_floor_grid(c_ptr);
5834 c_ptr->info |= (CAVE_ROOM);
5835 if (light) c_ptr->info |= (CAVE_GLOW);
5839 /* Walls around the room */
5840 for (y = y1 - 1; y <= y2 + 1; y++)
5842 c_ptr = &cave[y][x1 - 1];
5843 place_outer_grid(c_ptr);
5844 c_ptr = &cave[y][x2 + 1];
5845 place_outer_grid(c_ptr);
5847 for (x = x1 - 1; x <= x2 + 1; x++)
5849 c_ptr = &cave[y1 - 1][x];
5850 place_outer_grid(c_ptr);
5851 c_ptr = &cave[y2 + 1][x];
5852 place_outer_grid(c_ptr);
5855 if (dun_level < 30 + randint1(30))
5856 trap = FEAT_TRAP_PIRANHA;
5858 trap = FEAT_TRAP_ARMAGEDDON;
5860 /* Place a special trap */
5861 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
5862 c_ptr->mimic = c_ptr->feat;
5869 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5871 msg_format("Room of %s", f_name + f_info[trap].name);
5880 * Attempt to build a room of the given type at the given block
5882 * Note that we restrict the number of "crowded" rooms to reduce
5883 * the chance of overflowing the monster list during level creation.
5885 static bool room_build(int typ)
5890 /* Build an appropriate room */
5891 case ROOM_T_NORMAL: return build_type1();
5892 case ROOM_T_OVERLAP: return build_type2();
5893 case ROOM_T_CROSS: return build_type3();
5894 case ROOM_T_INNER_FEAT: return build_type4();
5895 case ROOM_T_NEST: return build_type5();
5896 case ROOM_T_PIT: return build_type6();
5897 case ROOM_T_LESSER_VAULT: return build_type7();
5898 case ROOM_T_GREATER_VAULT: return build_type8();
5899 case ROOM_T_FRACAVE: return build_type9();
5900 case ROOM_T_RANDOM_VAULT: return build_type10();
5901 case ROOM_T_OVAL: return build_type11();
5902 case ROOM_T_CRYPT: return build_type12();
5903 case ROOM_T_TRAP_PIT: return build_type13();
5904 case ROOM_T_TRAP: return build_type14();
5912 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
5915 * [from SAngband (originally from OAngband)]
5917 * Generate rooms in dungeon. Build bigger rooms at first.
5919 bool generate_rooms(void)
5925 int prob_list[ROOM_T_MAX];
5926 int rooms_built = 0;
5927 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
5928 int level_index = MIN(10, div_round(dun_level, 10));
5930 /* Number of each type of room on this level */
5931 s16b room_num[ROOM_T_MAX];
5933 /* Limit number of rooms */
5934 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
5936 /* Assume normal cave */
5937 room_info_type *room_info_ptr = room_info_normal;
5940 * Initialize probability list.
5942 for (i = 0; i < ROOM_T_MAX; i++)
5944 /* No rooms allowed above their minimum depth. */
5945 if (dun_level < room_info_ptr[i].min_level)
5951 prob_list[i] = room_info_ptr[i].prob[level_index];
5956 * XXX -- Various dungeon types and options.
5959 /* Ironman sees only Greater Vaults */
5960 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
5962 for (i = 0; i < ROOM_T_MAX; i++)
5964 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
5965 else prob_list[i] = 0;
5969 /* Forbidden vaults */
5970 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
5972 prob_list[ROOM_T_LESSER_VAULT] = 0;
5973 prob_list[ROOM_T_GREATER_VAULT] = 0;
5974 prob_list[ROOM_T_RANDOM_VAULT] = 0;
5978 /* NO_CAVE dungeon (Castle)*/
5979 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
5981 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
5982 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
5983 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
5986 /* CAVE dungeon (Orc cave etc.) */
5987 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
5989 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
5992 /* No caves when a (random) cavern exists: they look bad */
5993 else if (dun->cavern || dun->empty_level)
5995 prob_list[ROOM_T_FRACAVE] = 0;
6000 * Initialize number of rooms,
6001 * And calcurate total probability.
6003 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6006 total_prob += prob_list[i];
6010 * Prepare the number of rooms, of all types, we should build
6013 for (i = dun_rooms; i > 0; i--)
6016 int rand = randint0(total_prob);
6018 /* Get room_type randomly */
6019 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6021 if (rand < prob_list[room_type]) break;
6022 else rand -= prob_list[room_type];
6026 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6028 /* Increase the number of rooms of that type we should build. */
6029 room_num[room_type]++;
6035 case ROOM_T_LESSER_VAULT:
6036 case ROOM_T_TRAP_PIT:
6042 case ROOM_T_GREATER_VAULT:
6043 case ROOM_T_RANDOM_VAULT:
6052 * Build each type of room one by one until we cannot build any more.
6053 * [from SAngband (originally from OAngband)]
6057 /* Assume no remaining rooms */
6060 for (i = 0; i < ROOM_T_MAX; i++)
6062 /* What type of room are we building now? */
6063 int room_type = room_build_order[i];
6065 /* Go next if none available */
6066 if (!room_num[room_type]) continue;
6068 /* Use up one unit */
6069 room_num[room_type]--;
6071 /* Build the room. */
6072 if (room_build(room_type))
6074 /* Increase the room built count. */
6077 /* Mark as there was some remaining rooms */
6084 case ROOM_T_TRAP_PIT:
6086 /* Avoid too many monsters */
6089 room_num[ROOM_T_PIT] = 0;
6090 room_num[ROOM_T_NEST] = 0;
6091 room_num[ROOM_T_TRAP_PIT] = 0;
6097 /* End loop if no room remain */
6101 if (rooms_built < 1) return FALSE;
6106 msg_format("Éô²°¿ô: %d", rooms_built);
6108 msg_format("Number of Rooms: %d", rooms_built);