3 * Purpose: make rooms. Used by generate.c when creating dungeons.
7 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
9 * This software may be copied and distributed for educational, research, and
10 * not for profit purposes provided that this copyright and statement are
11 * included in all such copies.
21 * Array of minimum room depths
23 static s16b roomdep[] =
26 1, /* 1 = Simple (33x11) */
27 1, /* 2 = Overlapping (33x11) */
28 3, /* 3 = Crossed (33x11) */
29 3, /* 4 = Large (33x11) */
30 10, /* 5 = Monster nest (33x11) */
31 10, /* 6 = Monster pit (33x11) */
32 10, /* 7 = Lesser vault (33x22) */
33 20, /* 8 = Greater vault (66x44) */
34 5, /* 9 = Fractal cave (42x24) */
35 10, /* 10 = Random vault (44x22) */
36 3, /* 11 = Circular rooms (22x22) */
37 10, /* 12 = Crypts (22x22) */
38 20, /* 13 = Trapped monster pit */
42 static void place_locked_door(int y, int x)
44 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
46 place_floor_bold(y, x);
50 set_cave_feat(y, x, FEAT_DOOR_HEAD+randint1(7));
51 cave[y][x].info &= ~(CAVE_FLOOR);
55 static void place_secret_door(int y, int x)
57 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
59 place_floor_bold(y, x);
63 cave_type *c_ptr = &cave[y][x];
65 /* Create secret door */
66 place_closed_door(y, x);
69 c_ptr->mimic = fill_type[randint0(100)];
71 c_ptr->info &= ~(CAVE_FLOOR);
76 * This funtion makes a very small room centred at (x0, y0)
77 * This is used in crypts, and random elemental vaults.
79 * Note - this should be used only on allocated regions
80 * within another room.
82 static void build_small_room(int x0, int y0)
86 for (y = y0 - 1; y <= y0 + 1; y++)
88 place_inner_bold(y, x0 - 1);
89 place_inner_bold(y, x0 + 1);
92 for (x = x0 - 1; x <= x0 + 1; x++)
94 place_inner_bold(y0 - 1, x);
95 place_inner_bold(y0 + 1, x);
98 /* Place a secret door on one side */
101 case 0: place_secret_door(y0, x0 - 1); break;
102 case 1: place_secret_door(y0, x0 + 1); break;
103 case 2: place_secret_door(y0 - 1, x0); break;
104 case 3: place_secret_door(y0 + 1, x0); break;
107 /* Add inner open space */
108 place_floor_bold(y0, x0);
113 * This function tunnels around a room if
114 * it will cut off part of a cave system.
116 static void check_room_boundary(int x1, int y1, int x2, int y2)
119 bool old_is_floor, new_is_floor;
125 old_is_floor = get_is_floor(x1 - 1, y1);
128 * Count the number of floor-wall boundaries around the room
129 * Note: diagonal squares are ignored since the player can move diagonally
130 * to bypass these if needed.
133 /* Above the top boundary */
134 for (x = x1; x <= x2; x++)
136 new_is_floor = get_is_floor(x, y1 - 1);
138 /* Increment counter if they are different */
139 if (new_is_floor != old_is_floor) count++;
141 old_is_floor = new_is_floor;
145 for (y = y1; y <= y2; y++)
147 new_is_floor = get_is_floor(x2 + 1, y);
149 /* increment counter if they are different */
150 if (new_is_floor != old_is_floor) count++;
152 old_is_floor = new_is_floor;
155 /* Bottom boundary */
156 for (x = x2; x >= x1; x--)
158 new_is_floor = get_is_floor(x, y2 + 1);
160 /* increment counter if they are different */
161 if (new_is_floor != old_is_floor) count++;
163 old_is_floor = new_is_floor;
167 for (y = y2; y >= y1; y--)
169 new_is_floor = get_is_floor(x1 - 1, y);
171 /* increment counter if they are different */
172 if (new_is_floor != old_is_floor) count++;
174 old_is_floor = new_is_floor;
177 /* If all the same, or only one connection exit. */
178 if (count <= 2) return;
181 /* Tunnel around the room so to prevent problems with caves */
182 for (y = y1; y <= y2; y++)
184 for (x = x1; x <= x2; x++)
193 * This function is used to allocate the space needed by a room in the room_map
195 * x, y represent the size of the room (0...x-1) by (0...y-1).
196 * crowded is used to denote a monset nest.
197 * by0, bx0 are the positions in the room_map array given to the build_type'x'
199 * xx, yy are the returned center of the allocated room in coordinates for
200 * cave.feat and cave.info etc.
202 static bool room_alloc(int x, int y, bool crowded, int by0, int bx0, int *xx, int *yy)
204 int temp, bx1, bx2, by1, by2, by, bx;
206 /* Calculate number of room_map squares to allocate */
208 /* temp is total number along width */
209 temp = ((x - 1) / BLOCK_WID) + 1;
211 /* bx2 = ending block */
212 bx2 = temp / 2 + bx0;
214 /* bx1 = starting block (Note: rounding taken care of here.) */
215 bx1 = bx2 + 1 - temp;
217 /* temp is total number along height */
218 temp = ((y - 1) / BLOCK_HGT) + 1;
220 /* by2 = ending block */
221 by2 = temp / 2 + by0;
223 /* by1 = starting block */
224 by1 = by2 + 1 - temp;
227 /* Never run off the screen */
228 if ((by1 < 0) || (by2 >= dun->row_rooms)) return (FALSE);
229 if ((bx1 < 0) || (bx2 >= dun->col_rooms)) return (FALSE);
231 /* Verify open space */
232 for (by = by1; by <= by2; by++)
234 for (bx = bx1; bx <= bx2; bx++)
236 if (dun->room_map[by][bx]) return (FALSE);
240 /* It is *extremely* important that the following calculation */
241 /* be *exactly* correct to prevent memory errors XXX XXX XXX */
243 /* Acquire the location of the room */
244 *yy = ((by1 + by2 + 1) * BLOCK_HGT) / 2;
245 *xx = ((bx1 + bx2 + 1) * BLOCK_WID) / 2;
248 /* Save the room location */
249 if (dun->cent_n < CENT_MAX)
251 dun->cent[dun->cent_n].y = *yy;
252 dun->cent[dun->cent_n].x = *xx;
256 /* Reserve some blocks */
257 for (by = by1; by <= by2; by++)
259 for (bx = bx1; bx <= bx2; bx++)
261 dun->room_map[by][bx] = TRUE;
265 /* Count "crowded" rooms */
266 if (crowded) dun->crowded++;
269 * Hack- See if room will cut off a cavern.
270 * If so, fix by tunneling outside the room in such a way as to connect the caves.
272 check_room_boundary(*xx - x / 2 - 1, *yy - y / 2 - 1,
273 *xx + (x - 1) / 2 + 1, *yy + (y - 1) / 2 + 1);
280 * Room building routines.
286 * 4 -- large room with features
290 * 8 -- greater vaults
292 * 10 -- random vaults
293 * 11 -- circular rooms
295 * 13 -- trapped monster pits
300 * Type 1 -- normal rectangular rooms
302 static void build_type1(int by0, int bx0)
304 int y, x, y2, x2, yval, xval;
305 int y1, x1, xsize, ysize;
311 /* Pick a room size */
320 /* Try to allocate space for room. If fails, exit */
321 if (!room_alloc(xsize + 2, ysize + 2, FALSE, by0, bx0, &xval, &yval)) return;
323 /* Choose lite or dark */
324 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
327 /* Get corner values */
328 y1 = yval - ysize / 2;
329 x1 = xval - xsize / 2;
330 y2 = yval + (ysize - 1) / 2;
331 x2 = xval + (xsize - 1) / 2;
334 /* Place a full floor under the room */
335 for (y = y1 - 1; y <= y2 + 1; y++)
337 for (x = x1 - 1; x <= x2 + 1; x++)
340 place_floor_grid(c_ptr);
341 c_ptr->info |= (CAVE_ROOM);
342 if (light) c_ptr->info |= (CAVE_GLOW);
346 /* Walls around the room */
347 for (y = y1 - 1; y <= y2 + 1; y++)
349 c_ptr = &cave[y][x1 - 1];
350 place_outer_grid(c_ptr);
351 c_ptr = &cave[y][x2 + 1];
352 place_outer_grid(c_ptr);
354 for (x = x1 - 1; x <= x2 + 1; x++)
356 c_ptr = &cave[y1 - 1][x];
357 place_outer_grid(c_ptr);
358 c_ptr = &cave[y2 + 1][x];
359 place_outer_grid(c_ptr);
363 /* Hack -- Occasional pillar room */
366 for (y = y1; y <= y2; y += 2)
368 for (x = x1; x <= x2; x += 2)
371 place_inner_grid(c_ptr);
376 /* Hack -- Occasional room with four pillars */
377 else if (one_in_(20))
379 if ((y1 + 4 < y2) && (x1 + 4 < x2))
381 c_ptr = &cave[y1 + 1][x1 + 1];
382 place_inner_grid(c_ptr);
384 c_ptr = &cave[y1 + 1][x2 - 1];
385 place_inner_grid(c_ptr);
387 c_ptr = &cave[y2 - 1][x1 + 1];
388 place_inner_grid(c_ptr);
390 c_ptr = &cave[y2 - 1][x2 - 1];
391 place_inner_grid(c_ptr);
395 /* Hack -- Occasional ragged-edge room */
396 else if (one_in_(50))
398 for (y = y1 + 2; y <= y2 - 2; y += 2)
400 c_ptr = &cave[y][x1];
401 place_inner_grid(c_ptr);
402 c_ptr = &cave[y][x2];
403 place_inner_grid(c_ptr);
405 for (x = x1 + 2; x <= x2 - 2; x += 2)
407 c_ptr = &cave[y1][x];
408 place_inner_grid(c_ptr);
409 c_ptr = &cave[y2][x];
410 place_inner_grid(c_ptr);
413 /* Hack -- Occasional divided room */
414 else if (one_in_(50))
416 if (randint1(100) < 50)
418 /* Horizontal wall */
419 for (x = x1; x <= x2; x++)
421 place_inner_bold(yval, x);
424 /* Prevent edge of wall from being tunneled */
425 place_solid_bold(yval, x1 - 1);
426 place_solid_bold(yval, x2 + 1);
431 for (y = y1; y <= y2; y++)
433 place_inner_bold(y, xval);
436 /* Prevent edge of wall from being tunneled */
437 place_solid_bold(y1 - 1, xval);
438 place_solid_bold(y2 + 1, xval);
441 place_random_door(yval, xval);
447 * Type 2 -- Overlapping rectangular rooms
449 static void build_type2(int by0, int bx0)
451 int y, x, xval, yval;
452 int y1a, x1a, y2a, x2a;
453 int y1b, x1b, y2b, x2b;
458 /* Try to allocate space for room. If fails, exit */
459 if (!room_alloc(25, 11, FALSE, by0, bx0, &xval, &yval)) return;
461 /* Choose lite or dark */
462 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
464 /* Determine extents of the first room */
465 y1a = yval - randint1(4);
466 y2a = yval + randint1(3);
467 x1a = xval - randint1(11);
468 x2a = xval + randint1(10);
470 /* Determine extents of the second room */
471 y1b = yval - randint1(3);
472 y2b = yval + randint1(4);
473 x1b = xval - randint1(10);
474 x2b = xval + randint1(11);
477 /* Place a full floor for room "a" */
478 for (y = y1a - 1; y <= y2a + 1; y++)
480 for (x = x1a - 1; x <= x2a + 1; x++)
483 place_floor_grid(c_ptr);
484 c_ptr->info |= (CAVE_ROOM);
485 if (light) c_ptr->info |= (CAVE_GLOW);
489 /* Place a full floor for room "b" */
490 for (y = y1b - 1; y <= y2b + 1; y++)
492 for (x = x1b - 1; x <= x2b + 1; x++)
495 place_floor_grid(c_ptr);
496 c_ptr->info |= (CAVE_ROOM);
497 if (light) c_ptr->info |= (CAVE_GLOW);
502 /* Place the walls around room "a" */
503 for (y = y1a - 1; y <= y2a + 1; y++)
505 c_ptr = &cave[y][x1a - 1];
506 place_outer_grid(c_ptr);
507 c_ptr = &cave[y][x2a + 1];
508 place_outer_grid(c_ptr);
510 for (x = x1a - 1; x <= x2a + 1; x++)
512 c_ptr = &cave[y1a - 1][x];
513 place_outer_grid(c_ptr);
514 c_ptr = &cave[y2a + 1][x];
515 place_outer_grid(c_ptr);
518 /* Place the walls around room "b" */
519 for (y = y1b - 1; y <= y2b + 1; y++)
521 c_ptr = &cave[y][x1b - 1];
522 place_outer_grid(c_ptr);
523 c_ptr = &cave[y][x2b + 1];
524 place_outer_grid(c_ptr);
526 for (x = x1b - 1; x <= x2b + 1; x++)
528 c_ptr = &cave[y1b - 1][x];
529 place_outer_grid(c_ptr);
530 c_ptr = &cave[y2b + 1][x];
531 place_outer_grid(c_ptr);
536 /* Replace the floor for room "a" */
537 for (y = y1a; y <= y2a; y++)
539 for (x = x1a; x <= x2a; x++)
542 place_floor_grid(c_ptr);
546 /* Replace the floor for room "b" */
547 for (y = y1b; y <= y2b; y++)
549 for (x = x1b; x <= x2b; x++)
552 place_floor_grid(c_ptr);
560 * Type 3 -- Cross shaped rooms
562 * Builds a room at a row, column coordinate
564 * Room "a" runs north/south, and Room "b" runs east/east
565 * So the "central pillar" runs from x1a, y1b to x2a, y2b.
567 * Note that currently, the "center" is always 3x3, but I think that
568 * the code below will work (with "bounds checking") for 5x5, or even
569 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.
571 static void build_type3(int by0, int bx0)
573 int y, x, dy, dx, wy, wx;
574 int y1a, x1a, y2a, x2a;
575 int y1b, x1b, y2b, x2b;
581 /* Try to allocate space for room. */
582 if (!room_alloc(25, 11, FALSE, by0, bx0, &xval, &yval)) return;
584 /* Choose lite or dark */
585 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
587 /* For now, always 3x3 */
590 /* Pick max vertical size (at most 4) */
591 dy = rand_range(3, 4);
593 /* Pick max horizontal size (at most 15) */
594 dx = rand_range(3, 11);
597 /* Determine extents of the north/south room */
603 /* Determine extents of the east/west room */
610 /* Place a full floor for room "a" */
611 for (y = y1a - 1; y <= y2a + 1; y++)
613 for (x = x1a - 1; x <= x2a + 1; x++)
616 place_floor_grid(c_ptr);
617 c_ptr->info |= (CAVE_ROOM);
618 if (light) c_ptr->info |= (CAVE_GLOW);
622 /* Place a full floor for room "b" */
623 for (y = y1b - 1; y <= y2b + 1; y++)
625 for (x = x1b - 1; x <= x2b + 1; x++)
628 place_floor_grid(c_ptr);
629 c_ptr->info |= (CAVE_ROOM);
630 if (light) c_ptr->info |= (CAVE_GLOW);
635 /* Place the walls around room "a" */
636 for (y = y1a - 1; y <= y2a + 1; y++)
638 c_ptr = &cave[y][x1a - 1];
639 place_outer_grid(c_ptr);
640 c_ptr = &cave[y][x2a + 1];
641 place_outer_grid(c_ptr);
643 for (x = x1a - 1; x <= x2a + 1; x++)
645 c_ptr = &cave[y1a - 1][x];
646 place_outer_grid(c_ptr);
647 c_ptr = &cave[y2a + 1][x];
648 place_outer_grid(c_ptr);
651 /* Place the walls around room "b" */
652 for (y = y1b - 1; y <= y2b + 1; y++)
654 c_ptr = &cave[y][x1b - 1];
655 place_outer_grid(c_ptr);
656 c_ptr = &cave[y][x2b + 1];
657 place_outer_grid(c_ptr);
659 for (x = x1b - 1; x <= x2b + 1; x++)
661 c_ptr = &cave[y1b - 1][x];
662 place_outer_grid(c_ptr);
663 c_ptr = &cave[y2b + 1][x];
664 place_outer_grid(c_ptr);
668 /* Replace the floor for room "a" */
669 for (y = y1a; y <= y2a; y++)
671 for (x = x1a; x <= x2a; x++)
674 place_floor_grid(c_ptr);
678 /* Replace the floor for room "b" */
679 for (y = y1b; y <= y2b; y++)
681 for (x = x1b; x <= x2b; x++)
684 place_floor_grid(c_ptr);
690 /* Special features (3/4) */
693 /* Large solid middle pillar */
696 for (y = y1b; y <= y2b; y++)
698 for (x = x1a; x <= x2a; x++)
701 place_inner_grid(c_ptr);
707 /* Inner treasure vault */
710 /* Build the vault */
711 for (y = y1b; y <= y2b; y++)
713 c_ptr = &cave[y][x1a];
714 place_inner_grid(c_ptr);
715 c_ptr = &cave[y][x2a];
716 place_inner_grid(c_ptr);
718 for (x = x1a; x <= x2a; x++)
720 c_ptr = &cave[y1b][x];
721 place_inner_grid(c_ptr);
722 c_ptr = &cave[y2b][x];
723 place_inner_grid(c_ptr);
726 /* Place a secret door on the inner room */
729 case 0: place_secret_door(y1b, xval); break;
730 case 1: place_secret_door(y2b, xval); break;
731 case 2: place_secret_door(yval, x1a); break;
732 case 3: place_secret_door(yval, x2a); break;
735 /* Place a treasure in the vault */
736 place_object(yval, xval, FALSE, FALSE);
738 /* Let's guard the treasure well */
739 vault_monsters(yval, xval, randint0(2) + 3);
741 /* Traps naturally */
742 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
750 /* Occasionally pinch the center shut */
753 /* Pinch the east/west sides */
754 for (y = y1b; y <= y2b; y++)
756 if (y == yval) continue;
757 c_ptr = &cave[y][x1a - 1];
758 place_inner_grid(c_ptr);
759 c_ptr = &cave[y][x2a + 1];
760 place_inner_grid(c_ptr);
763 /* Pinch the north/south sides */
764 for (x = x1a; x <= x2a; x++)
766 if (x == xval) continue;
767 c_ptr = &cave[y1b - 1][x];
768 place_inner_grid(c_ptr);
769 c_ptr = &cave[y2b + 1][x];
770 place_inner_grid(c_ptr);
773 /* Sometimes shut using secret doors */
776 place_secret_door(yval, x1a - 1);
777 place_secret_door(yval, x2a + 1);
778 place_secret_door(y1b - 1, xval);
779 place_secret_door(y2b + 1, xval);
783 /* Occasionally put a "plus" in the center */
786 c_ptr = &cave[yval][xval];
787 place_inner_grid(c_ptr);
788 c_ptr = &cave[y1b][xval];
789 place_inner_grid(c_ptr);
790 c_ptr = &cave[y2b][xval];
791 place_inner_grid(c_ptr);
792 c_ptr = &cave[yval][x1a];
793 place_inner_grid(c_ptr);
794 c_ptr = &cave[yval][x2a];
795 place_inner_grid(c_ptr);
798 /* Occasionally put a pillar in the center */
801 c_ptr = &cave[yval][xval];
802 place_inner_grid(c_ptr);
812 * Type 4 -- Large room with inner features
814 * Possible sub-types:
815 * 1 - Just an inner room with one door
816 * 2 - An inner room within an inner room
817 * 3 - An inner room with pillar(s)
818 * 4 - Inner room has a maze
819 * 5 - A set of four inner rooms
821 static void build_type4(int by0, int bx0)
824 int y2, x2, tmp, yval, xval;
829 /* Try to allocate space for room. */
830 if (!room_alloc(25, 11, FALSE, by0, bx0, &xval, &yval)) return;
832 /* Choose lite or dark */
833 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
841 /* Place a full floor under the room */
842 for (y = y1 - 1; y <= y2 + 1; y++)
844 for (x = x1 - 1; x <= x2 + 1; x++)
847 place_floor_grid(c_ptr);
848 c_ptr->info |= (CAVE_ROOM);
849 if (light) c_ptr->info |= (CAVE_GLOW);
854 for (y = y1 - 1; y <= y2 + 1; y++)
856 c_ptr = &cave[y][x1 - 1];
857 place_outer_grid(c_ptr);
858 c_ptr = &cave[y][x2 + 1];
859 place_outer_grid(c_ptr);
861 for (x = x1 - 1; x <= x2 + 1; x++)
863 c_ptr = &cave[y1 - 1][x];
864 place_outer_grid(c_ptr);
865 c_ptr = &cave[y2 + 1][x];
866 place_outer_grid(c_ptr);
876 /* The inner walls */
877 for (y = y1 - 1; y <= y2 + 1; y++)
879 c_ptr = &cave[y][x1 - 1];
880 place_inner_grid(c_ptr);
881 c_ptr = &cave[y][x2 + 1];
882 place_inner_grid(c_ptr);
884 for (x = x1 - 1; x <= x2 + 1; x++)
886 c_ptr = &cave[y1 - 1][x];
887 place_inner_grid(c_ptr);
888 c_ptr = &cave[y2 + 1][x];
889 place_inner_grid(c_ptr);
893 /* Inner room variations */
896 /* Just an inner room with a monster */
899 /* Place a secret door */
902 case 1: place_secret_door(y1 - 1, xval); break;
903 case 2: place_secret_door(y2 + 1, xval); break;
904 case 3: place_secret_door(yval, x1 - 1); break;
905 case 4: place_secret_door(yval, x2 + 1); break;
908 /* Place a monster in the room */
909 vault_monsters(yval, xval, 1);
914 /* Treasure Vault (with a door) */
917 /* Place a secret door */
920 case 1: place_secret_door(y1 - 1, xval); break;
921 case 2: place_secret_door(y2 + 1, xval); break;
922 case 3: place_secret_door(yval, x1 - 1); break;
923 case 4: place_secret_door(yval, x2 + 1); break;
926 /* Place another inner room */
927 for (y = yval - 1; y <= yval + 1; y++)
929 for (x = xval - 1; x <= xval + 1; x++)
931 if ((x == xval) && (y == yval)) continue;
933 place_inner_grid(c_ptr);
937 /* Place a locked door on the inner room */
940 case 1: place_locked_door(yval - 1, xval); break;
941 case 2: place_locked_door(yval + 1, xval); break;
942 case 3: place_locked_door(yval, xval - 1); break;
943 case 4: place_locked_door(yval, xval + 1); break;
946 /* Monsters to guard the "treasure" */
947 vault_monsters(yval, xval, randint1(3) + 2);
950 if (randint0(100) < 80)
952 place_object(yval, xval, FALSE, FALSE);
958 place_random_stairs(yval, xval);
961 /* Traps to protect the treasure */
962 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
967 /* Inner pillar(s). */
970 /* Place a secret door */
973 case 1: place_secret_door(y1 - 1, xval); break;
974 case 2: place_secret_door(y2 + 1, xval); break;
975 case 3: place_secret_door(yval, x1 - 1); break;
976 case 4: place_secret_door(yval, x2 + 1); break;
979 /* Large Inner Pillar */
980 for (y = yval - 1; y <= yval + 1; y++)
982 for (x = xval - 1; x <= xval + 1; x++)
985 place_inner_grid(c_ptr);
989 /* Occasionally, two more Large Inner Pillars */
993 for (y = yval - 1; y <= yval + 1; y++)
995 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
998 place_inner_grid(c_ptr);
1000 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1002 c_ptr = &cave[y][x];
1003 place_inner_grid(c_ptr);
1008 /* Occasionally, some Inner rooms */
1011 /* Long horizontal walls */
1012 for (x = xval - 5; x <= xval + 5; x++)
1014 c_ptr = &cave[yval - 1][x];
1015 place_inner_grid(c_ptr);
1016 c_ptr = &cave[yval + 1][x];
1017 place_inner_grid(c_ptr);
1020 /* Close off the left/right edges */
1021 c_ptr = &cave[yval][xval - 5];
1022 place_inner_grid(c_ptr);
1023 c_ptr = &cave[yval][xval + 5];
1024 place_inner_grid(c_ptr);
1026 /* Secret doors (random top/bottom) */
1027 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3);
1028 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3);
1031 vault_monsters(yval, xval - 2, randint1(2));
1032 vault_monsters(yval, xval + 2, randint1(2));
1035 if (one_in_(3)) place_object(yval, xval - 2, FALSE, FALSE);
1036 if (one_in_(3)) place_object(yval, xval + 2, FALSE, FALSE);
1045 /* Place a secret door */
1046 switch (randint1(4))
1048 case 1: place_secret_door(y1 - 1, xval); break;
1049 case 2: place_secret_door(y2 + 1, xval); break;
1050 case 3: place_secret_door(yval, x1 - 1); break;
1051 case 4: place_secret_door(yval, x2 + 1); break;
1054 /* Maze (really a checkerboard) */
1055 for (y = y1; y <= y2; y++)
1057 for (x = x1; x <= x2; x++)
1061 c_ptr = &cave[y][x];
1062 place_inner_grid(c_ptr);
1067 /* Monsters just love mazes. */
1068 vault_monsters(yval, xval - 5, randint1(3));
1069 vault_monsters(yval, xval + 5, randint1(3));
1071 /* Traps make them entertaining. */
1072 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1073 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1075 /* Mazes should have some treasure too. */
1076 vault_objects(yval, xval, 3);
1081 /* Four small rooms. */
1085 for (y = y1; y <= y2; y++)
1087 c_ptr = &cave[y][xval];
1088 place_inner_grid(c_ptr);
1090 for (x = x1; x <= x2; x++)
1092 c_ptr = &cave[yval][x];
1093 place_inner_grid(c_ptr);
1096 /* Doors into the rooms */
1097 if (randint0(100) < 50)
1099 int i = randint1(10);
1100 place_secret_door(y1 - 1, xval - i);
1101 place_secret_door(y1 - 1, xval + i);
1102 place_secret_door(y2 + 1, xval - i);
1103 place_secret_door(y2 + 1, xval + i);
1107 int i = randint1(3);
1108 place_secret_door(yval + i, x1 - 1);
1109 place_secret_door(yval - i, x1 - 1);
1110 place_secret_door(yval + i, x2 + 1);
1111 place_secret_door(yval - i, x2 + 1);
1114 /* Treasure, centered at the center of the cross */
1115 vault_objects(yval, xval, 2 + randint1(2));
1117 /* Gotta have some monsters. */
1118 vault_monsters(yval + 1, xval - 4, randint1(4));
1119 vault_monsters(yval + 1, xval + 4, randint1(4));
1120 vault_monsters(yval - 1, xval - 4, randint1(4));
1121 vault_monsters(yval - 1, xval + 4, randint1(4));
1130 * The following functions are used to determine if the given monster
1131 * is appropriate for inclusion in a monster nest or monster pit or
1134 * None of the pits/nests are allowed to include "unique" monsters.
1139 * Monster validation macro
1141 * Line 1 -- forbid town monsters
1142 * Line 2 -- forbid uniques
1143 * Line 3 -- forbid aquatic monsters
1145 #define vault_monster_okay(I) \
1146 (monster_dungeon(I) && \
1147 !(r_info[I].flags1 & RF1_UNIQUE) && \
1148 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1149 !(r_info[I].flags3 & RF3_RES_ALL) && \
1150 !(r_info[I].flags7 & RF7_AQUATIC))
1153 /* Race index for "monster pit (clone)" */
1154 static int vault_aux_race;
1156 /* Race index for "monster pit (symbol clone)" */
1157 static char vault_aux_char;
1159 /* Breath mask for "monster pit (dragon)" */
1160 static u32b vault_aux_dragon_mask4;
1164 * Helper monster selection function
1166 static bool vault_aux_simple(int r_idx)
1169 return (vault_monster_okay(r_idx));
1174 * Helper function for "monster nest (jelly)"
1176 static bool vault_aux_jelly(int r_idx)
1178 monster_race *r_ptr = &r_info[r_idx];
1180 /* Validate the monster */
1181 if (!vault_monster_okay(r_idx)) return (FALSE);
1183 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1185 /* Also decline evil jellies (like death molds and shoggoths) */
1186 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1188 /* Require icky thing, jelly, mold, or mushroom */
1189 if (!strchr("ijm,", r_ptr->d_char)) return (FALSE);
1197 * Helper function for "monster nest (animal)"
1199 static bool vault_aux_animal(int r_idx)
1201 monster_race *r_ptr = &r_info[r_idx];
1203 /* Validate the monster */
1204 if (!vault_monster_okay(r_idx)) return (FALSE);
1206 /* Require "animal" flag */
1207 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1215 * Helper function for "monster nest (undead)"
1217 static bool vault_aux_undead(int r_idx)
1219 monster_race *r_ptr = &r_info[r_idx];
1221 /* Validate the monster */
1222 if (!vault_monster_okay(r_idx)) return (FALSE);
1224 /* Require Undead */
1225 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1233 * Helper function for "monster nest (chapel)"
1235 static bool vault_aux_chapel_g(int r_idx)
1237 static int chapel_list[] = {
1238 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1239 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1240 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1245 monster_race *r_ptr = &r_info[r_idx];
1247 /* Validate the monster */
1248 if (!vault_monster_okay(r_idx)) return (FALSE);
1250 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1251 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1253 /* Require "priest" or Angel */
1255 if (r_ptr->d_char == 'A') return TRUE;
1257 for (i = 0; chapel_list[i]; i++)
1258 if (r_idx == chapel_list[i]) return TRUE;
1265 * Helper function for "monster nest (kennel)"
1267 static bool vault_aux_kennel(int r_idx)
1269 monster_race *r_ptr = &r_info[r_idx];
1271 /* Validate the monster */
1272 if (!vault_monster_okay(r_idx)) return (FALSE);
1274 /* Require a Zephyr Hound or a dog */
1275 if (!strchr("CZ", r_ptr->d_char)) return (FALSE);
1283 * Helper function for "monster nest (mimic)"
1285 static bool vault_aux_mimic(int r_idx)
1287 monster_race *r_ptr = &r_info[r_idx];
1289 /* Validate the monster */
1290 if (!vault_monster_okay(r_idx)) return (FALSE);
1293 if (!strchr("!|$?=", r_ptr->d_char)) return (FALSE);
1300 * Helper function for "monster nest (clone)"
1302 static bool vault_aux_clone(int r_idx)
1304 /* Validate the monster */
1305 if (!vault_monster_okay(r_idx)) return (FALSE);
1307 return (r_idx == vault_aux_race);
1312 * Helper function for "monster nest (symbol clone)"
1314 static bool vault_aux_symbol_e(int r_idx)
1316 monster_race *r_ptr = &r_info[r_idx];
1318 /* Validate the monster */
1319 if (!vault_monster_okay(r_idx)) return (FALSE);
1321 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1323 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1325 /* Decline incorrect symbol */
1326 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1334 * Helper function for "monster nest (symbol clone)"
1336 static bool vault_aux_symbol_g(int r_idx)
1338 monster_race *r_ptr = &r_info[r_idx];
1340 /* Validate the monster */
1341 if (!vault_monster_okay(r_idx)) return (FALSE);
1343 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1345 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1347 /* Decline incorrect symbol */
1348 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1356 * Helper function for "monster pit (orc)"
1358 static bool vault_aux_orc(int r_idx)
1360 monster_race *r_ptr = &r_info[r_idx];
1362 /* Validate the monster */
1363 if (!vault_monster_okay(r_idx)) return (FALSE);
1366 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1368 /* Decline undead */
1369 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1377 * Helper function for "monster pit (troll)"
1379 static bool vault_aux_troll(int r_idx)
1381 monster_race *r_ptr = &r_info[r_idx];
1383 /* Validate the monster */
1384 if (!vault_monster_okay(r_idx)) return (FALSE);
1387 if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1389 /* Decline undead */
1390 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1398 * Helper function for "monster pit (giant)"
1400 static bool vault_aux_giant(int r_idx)
1402 monster_race *r_ptr = &r_info[r_idx];
1404 /* Validate the monster */
1405 if (!vault_monster_okay(r_idx)) return (FALSE);
1408 if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1410 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1412 /* Decline undead */
1413 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1421 * Helper function for "monster pit (dragon)"
1423 static bool vault_aux_dragon(int r_idx)
1425 monster_race *r_ptr = &r_info[r_idx];
1427 /* Validate the monster */
1428 if (!vault_monster_okay(r_idx)) return (FALSE);
1430 /* Require dragon */
1431 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1433 /* Hack -- Require correct "breath attack" */
1434 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1436 /* Decline undead */
1437 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1445 * Helper function for "monster pit (demon)"
1447 static bool vault_aux_demon(int r_idx)
1449 monster_race *r_ptr = &r_info[r_idx];
1451 /* Validate the monster */
1452 if (!vault_monster_okay(r_idx)) return (FALSE);
1454 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1457 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1465 * Helper function for "monster pit (lovecraftian)"
1467 static bool vault_aux_cthulhu(int r_idx)
1469 monster_race *r_ptr = &r_info[r_idx];
1471 /* Validate the monster */
1472 if (!vault_monster_okay(r_idx)) return (FALSE);
1474 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1476 /* Require eldritch horror */
1477 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1485 * Helper function for "monster pit (clone)"
1487 static void vault_prep_clone(void)
1489 /* Apply the monster restriction */
1490 get_mon_num_prep(vault_aux_simple, NULL);
1492 /* Pick a race to clone */
1493 vault_aux_race = get_mon_num(dun_level + 10);
1495 /* Remove the monster restriction */
1496 get_mon_num_prep(NULL, NULL);
1501 * Helper function for "monster pit (symbol clone)"
1503 static void vault_prep_symbol(void)
1507 /* Apply the monster restriction */
1508 get_mon_num_prep(vault_aux_simple, NULL);
1510 /* Pick a race to clone */
1511 r_idx = get_mon_num(dun_level + 10);
1513 /* Remove the monster restriction */
1514 get_mon_num_prep(NULL, NULL);
1516 /* Extract the symbol */
1517 vault_aux_char = r_info[r_idx].d_char;
1522 * Helper function for "monster pit (dragon)"
1524 static void vault_prep_dragon(void)
1526 /* Pick dragon type */
1527 switch (randint0(6))
1532 /* Restrict dragon breath type */
1533 vault_aux_dragon_mask4 = RF4_BR_ACID;
1542 /* Restrict dragon breath type */
1543 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1552 /* Restrict dragon breath type */
1553 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1562 /* Restrict dragon breath type */
1563 vault_aux_dragon_mask4 = RF4_BR_COLD;
1572 /* Restrict dragon breath type */
1573 vault_aux_dragon_mask4 = RF4_BR_POIS;
1582 /* Restrict dragon breath type */
1583 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1584 RF4_BR_FIRE | RF4_BR_COLD |
1597 typedef struct vault_aux_type vault_aux_type;
1600 struct vault_aux_type
1603 bool (*hook_func)(int r_idx);
1604 void (*prep_func)(void);
1610 static vault_aux_type *pick_vault_type(vault_aux_type *l_ptr, int room)
1612 int tmp, total, count;
1614 vault_aux_type *n_ptr;
1616 /* Calculate the total possibilities */
1617 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1620 if (!n_ptr->name) break;
1622 /* Ignore excessive depth */
1623 if (n_ptr->level > dun_level) continue;
1625 if (room == ROOM_PIT)
1627 if (!(d_info[dungeon_type].pit & (1L << count))) continue;
1629 else if (room == ROOM_NEST)
1631 if(!(d_info[dungeon_type].nest & (1L << count))) continue;
1634 /* Count this possibility */
1635 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1638 /* Pick a random type */
1639 tmp = randint0(total);
1641 /* Find this type */
1642 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1645 if (!n_ptr->name) break;
1647 /* Ignore excessive depth */
1648 if (n_ptr->level > dun_level) continue;
1650 if (room == ROOM_PIT)
1652 if (!(d_info[dungeon_type].pit & (1L << count))) continue;
1654 else if (room == ROOM_NEST)
1656 if(!(d_info[dungeon_type].nest & (1L << count))) continue;
1659 /* Count this possibility */
1660 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1662 /* Found the type */
1663 if (tmp < total) break;
1666 return (n_ptr->name ? n_ptr : NULL);
1669 static void build_type6(int by0, int bx0, bool nest);
1670 static void build_type5(int by0, int bx0, bool nest);
1672 static vault_aux_type nest_types[] =
1675 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1676 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1677 {"¥·¥ó¥Ü¥ë(Á±)",vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1678 {"¥·¥ó¥Ü¥ë(°)",vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1679 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1680 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1681 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1682 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1683 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1684 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1685 {NULL, NULL, NULL, 0, 0},
1687 {"clone", vault_aux_clone, vault_prep_clone, 7, 3},
1688 {"jelly", vault_aux_jelly, NULL, 7, 6},
1689 {"symbol good",vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1690 {"symbol evil",vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1691 {"mimic", vault_aux_mimic, NULL, 45, 6},
1692 {"lovecraftian",vault_aux_cthulhu, NULL, 80, 2},
1693 {"kennel", vault_aux_kennel, NULL, 50, 2},
1694 {"animal", vault_aux_animal, NULL, 50, 4},
1695 {"chapel", vault_aux_chapel_g, NULL, 90, 2},
1696 {"undead", vault_aux_undead, NULL, 90, 4},
1697 {NULL, NULL, NULL, 0, 0},
1703 * Type 5 -- Monster nests
1705 * A monster nest is a "big" room, with an "inner" room, containing
1706 * a "collection" of monsters of a given type strewn about the room.
1708 * The monsters are chosen from a set of 64 randomly selected monster
1709 * races, to allow the nest creation to fail instead of having "holes".
1711 * Note the use of the "get_mon_num_prep()" function, and the special
1712 * "get_mon_num_hook()" restriction function, to prepare the "monster
1713 * allocation table" in such a way as to optimize the selection of
1714 * "appropriate" non-unique monsters for the nest.
1716 * Note that the "get_mon_num()" function may (rarely) fail, in which
1717 * case the nest will be empty, and will not affect the level rating.
1719 * Note that "monster nests" will never contain "unique" monsters.
1721 static void build_type5(int by0, int bx0, bool pit)
1723 int y, x, y1, x1, y2, x2, xval, yval;
1731 vault_aux_type *n_ptr = pick_vault_type(nest_types, ROOM_NEST);
1733 /* Try to allocate space for room. */
1734 if (!room_alloc(25, 11, TRUE, by0, bx0, &xval, &yval)) return;
1736 /* No type available */
1740 else {build_type6(by0, bx0, TRUE);return;}
1743 /* Process a preparation function if necessary */
1744 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
1752 /* Place the floor area */
1753 for (y = y1 - 1; y <= y2 + 1; y++)
1755 for (x = x1 - 1; x <= x2 + 1; x++)
1757 c_ptr = &cave[y][x];
1758 place_floor_grid(c_ptr);
1759 c_ptr->info |= (CAVE_ROOM);
1763 /* Place the outer walls */
1764 for (y = y1 - 1; y <= y2 + 1; y++)
1766 c_ptr = &cave[y][x1 - 1];
1767 place_outer_grid(c_ptr);
1768 c_ptr = &cave[y][x2 + 1];
1769 place_outer_grid(c_ptr);
1771 for (x = x1 - 1; x <= x2 + 1; x++)
1773 c_ptr = &cave[y1 - 1][x];
1774 place_outer_grid(c_ptr);
1775 c_ptr = &cave[y2 + 1][x];
1776 place_outer_grid(c_ptr);
1780 /* Advance to the center room */
1786 /* The inner walls */
1787 for (y = y1 - 1; y <= y2 + 1; y++)
1789 c_ptr = &cave[y][x1 - 1];
1790 place_inner_grid(c_ptr);
1791 c_ptr = &cave[y][x2 + 1];
1792 place_inner_grid(c_ptr);
1795 for (x = x1 - 1; x <= x2 + 1; x++)
1797 c_ptr = &cave[y1 - 1][x];
1798 place_inner_grid(c_ptr);
1799 c_ptr = &cave[y2 + 1][x];
1800 place_inner_grid(c_ptr);
1802 for (y = y1; y <= y2; y++)
1804 for (x = x1; x <= x2; x++)
1806 add_cave_info(y, x, CAVE_ICKY);
1811 /* Place a secret door */
1812 switch (randint1(4))
1814 case 1: place_secret_door(y1 - 1, xval); break;
1815 case 2: place_secret_door(y2 + 1, xval); break;
1816 case 3: place_secret_door(yval, x1 - 1); break;
1817 case 4: place_secret_door(yval, x2 + 1); break;
1821 /* Prepare allocation table */
1822 get_mon_num_prep(n_ptr->hook_func, NULL);
1824 /* Pick some monster types */
1825 for (i = 0; i < 64; i++)
1827 int r_idx = 0, attempts = 100;
1831 /* Get a (hard) monster type */
1832 r_idx = get_mon_num(dun_level + 10);
1834 /* Decline incorrect alignment */
1835 if (((align < 0) && (r_info[r_idx].flags3 & RF3_GOOD)) ||
1836 ((align > 0) && (r_info[r_idx].flags3 & RF3_EVIL)))
1841 /* Accept this monster */
1845 /* Notice failure */
1846 if (!r_idx || !attempts) return;
1848 /* Note the alignment */
1849 if (r_info[r_idx].flags3 & RF3_GOOD) align++;
1850 else if (r_info[r_idx].flags3 & RF3_EVIL) align--;
1860 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(%s)", n_ptr->name);
1862 msg_format("Monster nest (%s)", n_ptr->name);
1868 /* Increase the level rating */
1871 /* (Sometimes) Cause a "special feeling" (for "Monster Nests") */
1872 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
1874 good_item_flag = TRUE;
1877 /* Place some monsters */
1878 for (y = yval - 2; y <= yval + 2; y++)
1880 for (x = xval - 9; x <= xval + 9; x++)
1882 int r_idx = what[randint0(64)];
1884 /* Place that "random" monster (no groups) */
1885 (void)place_monster_aux(0, y, x, r_idx, 0L);
1891 static vault_aux_type pit_types[] =
1894 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1895 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1896 {"¥¸¥ã¥¤¥¢¥ó¥È",vault_aux_giant, NULL, 50, 6},
1897 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1898 {"¥·¥ó¥Ü¥ë(Á±)",vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1899 {"¥·¥ó¥Ü¥ë(°)",vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1900 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
1901 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
1902 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
1903 {NULL, NULL, NULL, 0, 0},
1905 {"orc", vault_aux_orc, NULL, 7, 4},
1906 {"troll", vault_aux_troll, NULL, 35, 4},
1907 {"giant", vault_aux_giant, NULL, 70, 4},
1908 {"lovecraftian",vault_aux_cthulhu, NULL, 90, 4},
1909 {"symbol good",vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1910 {"symbol evil",vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1911 {"chapel", vault_aux_chapel_g, NULL, 85, 1},
1912 {"dragon", vault_aux_dragon, vault_prep_dragon, 80, 4},
1913 {"demon", vault_aux_demon, NULL, 90, 4},
1914 {NULL, NULL, NULL, 0, 0},
1920 * Type 6 -- Monster pits
1922 * A monster pit is a "big" room, with an "inner" room, containing
1923 * a "collection" of monsters of a given type organized in the room.
1925 * The inside room in a monster pit appears as shown below, where the
1926 * actual monsters in each location depend on the type of the pit
1928 * #####################
1929 * #0000000000000000000#
1930 * #0112233455543322110#
1931 * #0112233467643322110#
1932 * #0112233455543322110#
1933 * #0000000000000000000#
1934 * #####################
1936 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
1937 * to request 16 "appropriate" monsters, sorting them by level, and using
1938 * the "even" entries in this sorted list for the contents of the pit.
1940 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
1941 * which is handled by requiring a specific "breath" attack for all of the
1942 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
1943 * be present in many of the dragon pits, if they have the proper breath.
1945 * Note the use of the "get_mon_num_prep()" function, and the special
1946 * "get_mon_num_hook()" restriction function, to prepare the "monster
1947 * allocation table" in such a way as to optimize the selection of
1948 * "appropriate" non-unique monsters for the pit.
1950 * Note that the "get_mon_num()" function may (rarely) fail, in which case
1951 * the pit will be empty, and will not effect the level rating.
1953 * Note that "monster pits" will never contain "unique" monsters.
1955 static void build_type6(int by0, int bx0, bool nest)
1957 int y, x, y1, x1, y2, x2, xval, yval;
1966 vault_aux_type *n_ptr = pick_vault_type(pit_types, ROOM_PIT);
1968 /* Try to allocate space for room. */
1969 if (!room_alloc(25, 11, TRUE, by0, bx0, &xval, &yval)) return;
1971 /* No type available */
1975 else {build_type5(by0, bx0, TRUE);return;}
1978 /* Process a preparation function if necessary */
1979 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
1987 /* Place the floor area */
1988 for (y = y1 - 1; y <= y2 + 1; y++)
1990 for (x = x1 - 1; x <= x2 + 1; x++)
1992 c_ptr = &cave[y][x];
1993 place_floor_grid(c_ptr);
1994 c_ptr->info |= (CAVE_ROOM);
1998 /* Place the outer walls */
1999 for (y = y1 - 1; y <= y2 + 1; y++)
2001 c_ptr = &cave[y][x1 - 1];
2002 place_outer_grid(c_ptr);
2003 c_ptr = &cave[y][x2 + 1];
2004 place_outer_grid(c_ptr);
2006 for (x = x1 - 1; x <= x2 + 1; x++)
2008 c_ptr = &cave[y1 - 1][x];
2009 place_outer_grid(c_ptr);
2010 c_ptr = &cave[y2 + 1][x];
2011 place_outer_grid(c_ptr);
2014 /* Advance to the center room */
2020 /* The inner walls */
2021 for (y = y1 - 1; y <= y2 + 1; y++)
2023 c_ptr = &cave[y][x1 - 1];
2024 place_inner_grid(c_ptr);
2025 c_ptr = &cave[y][x2 + 1];
2026 place_inner_grid(c_ptr);
2028 for (x = x1 - 1; x <= x2 + 1; x++)
2030 c_ptr = &cave[y1 - 1][x];
2031 place_inner_grid(c_ptr);
2032 c_ptr = &cave[y2 + 1][x];
2033 place_inner_grid(c_ptr);
2035 for (y = y1; y <= y2; y++)
2037 for (x = x1; x <= x2; x++)
2039 add_cave_info(y, x, CAVE_ICKY);
2043 /* Place a secret door */
2044 switch (randint1(4))
2046 case 1: place_secret_door(y1 - 1, xval); break;
2047 case 2: place_secret_door(y2 + 1, xval); break;
2048 case 3: place_secret_door(yval, x1 - 1); break;
2049 case 4: place_secret_door(yval, x2 + 1); break;
2053 /* Prepare allocation table */
2054 get_mon_num_prep(n_ptr->hook_func, NULL);
2056 /* Pick some monster types */
2057 for (i = 0; i < 16; i++)
2059 int r_idx = 0, attempts = 100;
2063 /* Get a (hard) monster type */
2064 r_idx = get_mon_num(dun_level + 10);
2066 /* Decline incorrect alignment */
2067 if (((align < 0) && (r_info[r_idx].flags3 & RF3_GOOD)) ||
2068 ((align > 0) && (r_info[r_idx].flags3 & RF3_EVIL)))
2073 /* Accept this monster */
2077 /* Notice failure */
2078 if (!r_idx || !attempts) return;
2080 /* Note the alignment */
2081 if (r_info[r_idx].flags3 & RF3_GOOD) align++;
2082 else if (r_info[r_idx].flags3 & RF3_EVIL) align--;
2087 /* Sort the entries */
2088 for (i = 0; i < 16 - 1; i++)
2090 /* Sort the entries */
2091 for (j = 0; j < 16 - 1; j++)
2096 int p1 = r_info[what[i1]].level;
2097 int p2 = r_info[what[i2]].level;
2103 what[i1] = what[i2];
2113 msg_format("%s¤ÎÁã", n_ptr->name);
2116 msg_format("Monster pit (%s)", n_ptr->name);
2120 /* Select the entries */
2121 for (i = 0; i < 8; i++)
2123 /* Every other entry */
2124 what[i] = what[i * 2];
2129 msg_print(r_name + r_info[what[i]].name);
2133 /* Increase the level rating */
2136 /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
2137 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
2139 good_item_flag = TRUE;
2142 /* Top and bottom rows */
2143 for (x = xval - 9; x <= xval + 9; x++)
2145 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2146 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2149 /* Middle columns */
2150 for (y = yval - 1; y <= yval + 1; y++)
2152 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2153 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2155 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2156 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2158 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2159 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2161 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2162 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2164 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2165 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2167 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2168 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2170 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2171 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2173 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2174 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2177 /* Above/Below the center monster */
2178 for (x = xval - 1; x <= xval + 1; x++)
2180 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2181 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2184 /* Next to the center monster */
2185 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2186 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2188 /* Center monster */
2189 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2193 /* coordinate translation code */
2194 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2200 * transno specifies what transformation is required. (0-7)
2201 * The lower two bits indicate by how much the vault is rotated,
2202 * and the upper bit indicates a reflection.
2203 * This is done by using rotation matrices... however since
2204 * these are mostly zeros for rotations by 90 degrees this can
2205 * be expressed simply in terms of swapping and inverting the
2206 * x and y coordinates.
2208 for (i = 0; i <= transno % 4; i++)
2210 /* rotate by 90 degrees */
2218 /* Reflect depending on status of 3rd bit. */
2222 /* Add offsets so vault stays in the first quadrant */
2229 * Hack -- fill in "vault" rooms
2231 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2232 int xoffset, int yoffset, int transno)
2234 int dx, dy, x, y, i, j;
2241 /* Place dungeon features and objects */
2242 for (t = data, dy = 0; dy < ymax; dy++)
2244 for (dx = 0; dx < xmax; dx++, t++)
2246 /* prevent loop counter from being overwritten */
2251 coord_trans(&i, &j, xoffset, yoffset, transno);
2253 /* Extract the location */
2256 /* no swap of x/y */
2257 x = xval - (xmax / 2) + i;
2258 y = yval - (ymax / 2) + j;
2263 x = xval - (ymax / 2) + i;
2264 y = yval - (xmax / 2) + j;
2267 /* Hack -- skip "non-grids" */
2268 if (*t == ' ') continue;
2270 /* Access the grid */
2271 c_ptr = &cave[y][x];
2273 /* Lay down a floor */
2274 place_floor_grid(c_ptr);
2276 /* Part of a vault */
2277 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2279 /* Analyze the grid */
2282 /* Granite wall (outer) */
2284 place_outer_noperm_grid(c_ptr);
2287 /* Granite wall (inner) */
2289 place_inner_grid(c_ptr);
2292 /* Permanent wall (inner) */
2294 c_ptr->feat = FEAT_PERM_INNER;
2295 c_ptr->info &= ~(CAVE_MASK);
2296 c_ptr->info |= CAVE_INNER;
2301 if (randint0(100) < 75)
2303 place_object(y, x, FALSE, FALSE);
2313 place_secret_door(y, x);
2325 /* Place dungeon monsters and objects */
2326 for (t = data, dy = 0; dy < ymax; dy++)
2328 for (dx = 0; dx < xmax; dx++, t++)
2330 /* prevent loop counter from being overwritten */
2335 coord_trans(&i, &j, xoffset, yoffset, transno);
2337 /* Extract the location */
2340 /* no swap of x/y */
2341 x = xval - (xmax / 2) + i;
2342 y = yval - (ymax / 2) + j;
2347 x = xval - (ymax / 2) + i;
2348 y = yval - (xmax / 2) + j;
2351 /* Hack -- skip "non-grids" */
2352 if (*t == ' ') continue;
2354 /* Analyze the symbol */
2360 monster_level = base_level + 5;
2361 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2362 monster_level = base_level;
2366 /* Meaner monster */
2369 monster_level = base_level + 11;
2370 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2371 monster_level = base_level;
2375 /* Meaner monster, plus treasure */
2378 monster_level = base_level + 9;
2379 place_monster(y, x, PM_ALLOW_SLEEP);
2380 monster_level = base_level;
2381 object_level = base_level + 7;
2382 place_object(y, x, TRUE, FALSE);
2383 object_level = base_level;
2387 /* Nasty monster and treasure */
2390 monster_level = base_level + 40;
2391 place_monster(y, x, PM_ALLOW_SLEEP);
2392 monster_level = base_level;
2393 object_level = base_level + 20;
2394 place_object(y, x, TRUE, TRUE);
2395 object_level = base_level;
2399 /* Monster and/or object */
2402 if (randint0(100) < 50)
2404 monster_level = base_level + 3;
2405 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2406 monster_level = base_level;
2408 if (randint0(100) < 50)
2410 object_level = base_level + 7;
2411 place_object(y, x, FALSE, FALSE);
2412 object_level = base_level;
2418 cave_set_feat(y, x, FEAT_SHOP_HEAD + STORE_BLACK);
2419 store_init(NO_TOWN, STORE_BLACK);
2423 cave_set_feat(y, x, FEAT_PATTERN_START);
2427 cave_set_feat(y, x, FEAT_PATTERN_1);
2431 cave_set_feat(y, x, FEAT_PATTERN_2);
2435 cave_set_feat(y, x, FEAT_PATTERN_3);
2439 cave_set_feat(y, x, FEAT_PATTERN_4);
2443 cave_set_feat(y, x, FEAT_PATTERN_END);
2447 cave_set_feat(y, x, FEAT_PATTERN_XTRA1);
2452 object_level = base_level + 12;
2453 place_object(y, x, TRUE, FALSE);
2454 object_level = base_level;
2464 * Type 7 -- simple vaults (see "v_info.txt")
2466 static void build_type7(int by0, int bx0)
2468 vault_type *v_ptr = NULL;
2472 int xoffset, yoffset;
2475 /* Pick a lesser vault */
2476 while (dummy < SAFE_MAX_ATTEMPTS)
2480 /* Access a random vault record */
2481 v_ptr = &v_info[randint0(max_v_idx)];
2483 /* Accept the first lesser vault */
2484 if (v_ptr->typ == 7) break;
2487 /* No lesser vault found */
2490 /* pick type of transformation (0-7) */
2491 transno = randint0(8);
2493 /* calculate offsets */
2497 coord_trans(&x, &y, 0, 0, transno);
2517 /* Try to allocate space for room. */
2518 if (!room_alloc(abs(x), abs(y), FALSE, by0, bx0, &xval, &yval)) return;
2520 if (dummy >= SAFE_MAX_ATTEMPTS)
2525 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2527 msg_print("Warning! Could not place lesser vault!");
2540 if (cheat_room) msg_format("%s", v_name + v_ptr->name);
2542 /* Boost the rating */
2543 rating += v_ptr->rat;
2545 /* (Sometimes) Cause a special feeling */
2546 if ((dun_level <= 50) ||
2547 (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
2549 good_item_flag = TRUE;
2552 /* Hack -- Build the vault */
2553 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2554 v_text + v_ptr->text, xoffset, yoffset, transno);
2559 * Type 8 -- greater vaults (see "v_info.txt")
2561 static void build_type8(int by0, int bx0)
2563 vault_type *v_ptr = NULL;
2568 int xoffset, yoffset;
2570 /* Pick a greater vault */
2571 while (dummy < SAFE_MAX_ATTEMPTS)
2575 /* Access a random vault record */
2576 v_ptr = &v_info[randint0(max_v_idx)];
2578 /* Accept the first greater vault */
2579 if (v_ptr->typ == 8) break;
2582 /* No greater vault found */
2585 /* pick type of transformation (0-7) */
2586 transno = randint0(8);
2588 /* calculate offsets */
2592 coord_trans(&x, &y, 0, 0, transno);
2612 /* Try to allocate space for room. If fails, exit */
2613 if (!room_alloc(abs(x), abs(y), FALSE, by0, bx0, &xval, &yval)) return;
2615 if (dummy >= SAFE_MAX_ATTEMPTS)
2620 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2622 msg_print("Warning! Could not place greater vault!");
2631 v_ptr = &v_info[76 + randint1(3)];
2635 if (cheat_room) msg_format("%s", v_name + v_ptr->name);
2637 /* Boost the rating */
2638 rating += v_ptr->rat;
2640 /* (Sometimes) Cause a special feeling */
2641 if ((dun_level <= 50) ||
2642 (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
2644 good_item_flag = TRUE;
2647 /* Hack -- Build the vault */
2648 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2649 v_text + v_ptr->text, xoffset, yoffset, transno);
2653 * Structure to hold all "fill" data
2656 typedef struct fill_data_type fill_data_type;
2658 struct fill_data_type
2671 /* features to fill with */
2680 /* number of filled squares */
2684 static fill_data_type fill_data;
2687 /* Store routine for the fractal cave generator */
2688 /* this routine probably should be an inline function or a macro. */
2689 static void store_height(int x, int y, int val)
2691 /* if on boundary set val > cutoff so walls are not as square */
2692 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
2693 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
2694 (val <= fill_data.c1)) val = fill_data.c1 + 1;
2696 /* store the value in height-map format */
2697 cave[y][x].feat = val;
2704 * Explanation of the plasma fractal algorithm:
2706 * A grid of points is created with the properties of a 'height-map'
2707 * This is done by making the corners of the grid have a random value.
2708 * The grid is then subdivided into one with twice the resolution.
2709 * The new points midway between two 'known' points can be calculated
2710 * by taking the average value of the 'known' ones and randomly adding
2711 * or subtracting an amount proportional to the distance between those
2712 * points. The final 'middle' points of the grid are then calculated
2713 * by averaging all four of the originally 'known' corner points. An
2714 * random amount is added or subtracted from this to get a value of the
2715 * height at that point. The scaling factor here is adjusted to the
2716 * slightly larger distance diagonally as compared to orthogonally.
2718 * This is then repeated recursively to fill an entire 'height-map'
2719 * A rectangular map is done the same way, except there are different
2720 * scaling factors along the x and y directions.
2722 * A hack to change the amount of correlation between points is done using
2723 * the grd variable. If the current step size is greater than grd then
2724 * the point will be random, otherwise it will be calculated by the
2725 * above algorithm. This makes a maximum distance at which two points on
2726 * the height map can affect each other.
2728 * How fractal caves are made:
2730 * When the map is complete, a cut-off value is used to create a cave.
2731 * Heights below this value are "floor", and heights above are "wall".
2732 * This also can be used to create lakes, by adding more height levels
2733 * representing shallow and deep water/ lava etc.
2735 * The grd variable affects the width of passages.
2736 * The roug variable affects the roughness of those passages
2738 * The tricky part is making sure the created cave is connected. This
2739 * is done by 'filling' from the inside and only keeping the 'filled'
2740 * floor. Walls bounding the 'filled' floor are also kept. Everything
2741 * else is converted to the normal granite FEAT_WALL_EXTRA.
2746 * Note that this uses the cave.feat array in a very hackish way
2747 * the values are first set to zero, and then each array location
2748 * is used as a "heightmap"
2749 * The heightmap then needs to be converted back into the "feat" format.
2751 * grd=level at which fractal turns on. smaller gives more mazelike caves
2752 * roug=roughness level. 16=normal. higher values make things more convoluted
2753 * small values are good for smooth walls.
2754 * size=length of the side of the square cave system.
2756 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
2758 int xhsize, yhsize, xsize, ysize, maxsize;
2761 * fixed point variables- these are stored as 256 x normal value
2762 * this gives 8 binary places of fractional part + 8 places of normal part
2765 u16b xstep, xhstep, ystep, yhstep;
2766 u16b xstep2, xhstep2, ystep2, yhstep2;
2767 u16b i, j, ii, jj, diagsize, xxsize, yysize;
2769 /* Cache for speed */
2770 u16b xm, xp, ym, yp;
2772 /* redefine size so can change the value if out of range */
2776 /* Paranoia about size of the system of caves */
2777 if (xsize > 254) xsize = 254;
2778 if (xsize < 4) xsize = 4;
2779 if (ysize > 254) ysize = 254;
2780 if (ysize < 4) ysize = 4;
2782 /* get offsets to middle of array */
2786 /* fix rounding problem */
2790 /* get limits of region */
2791 fill_data.xmin = x0 - xhsize;
2792 fill_data.ymin = y0 - yhsize;
2793 fill_data.xmax = x0 + xhsize;
2794 fill_data.ymax = y0 + yhsize;
2796 /* Store cutoff in global for quick access */
2797 fill_data.c1 = cutoff;
2800 * Scale factor for middle points:
2801 * About sqrt(2) * 256 - correct for a square lattice
2802 * approximately correct for everything else.
2806 /* maximum of xsize and ysize */
2807 maxsize = (xsize > ysize) ? xsize : ysize;
2809 /* Clear the section */
2810 for (i = 0; i <= xsize; i++)
2812 for (j = 0; j <= ysize; j++)
2814 /* 255 is a flag for "not done yet" */
2815 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = 255;
2816 /* Clear icky flag because may be redoing the cave */
2817 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
2821 /* Boundaries are walls */
2822 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
2823 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
2824 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
2825 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
2827 /* Set the middle square to be an open area. */
2828 cave[y0][x0].feat = 0;
2830 /* Initialize the step sizes */
2831 xstep = xhstep = xsize * 256;
2832 ystep = yhstep = ysize * 256;
2833 xxsize = xsize * 256;
2834 yysize = ysize * 256;
2837 * Fill in the rectangle with fractal height data -
2838 * like the 'plasma fractal' in fractint.
2840 while ((xhstep > 256) || (yhstep > 256))
2842 /* Halve the step sizes */
2848 /* cache well used values */
2849 xstep2 = xstep / 256;
2850 ystep2 = ystep / 256;
2852 xhstep2 = xhstep / 256;
2853 yhstep2 = yhstep / 256;
2855 /* middle top to bottom. */
2856 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
2858 for (j = 0; j <= yysize; j += ystep)
2860 /* cache often used values */
2861 ii = i / 256 + fill_data.xmin;
2862 jj = j / 256 + fill_data.ymin;
2865 if (cave[jj][ii].feat == 255)
2869 /* If greater than 'grid' level then is random */
2870 store_height(ii, jj, randint1(maxsize));
2874 /* Average of left and right points +random bit */
2875 store_height(ii, jj,
2876 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
2877 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
2878 + (randint1(xstep2) - xhstep2) * roug / 16);
2885 /* middle left to right. */
2886 for (j = yhstep; j <= yysize - yhstep; j += ystep)
2888 for (i = 0; i <= xxsize; i += xstep)
2890 /* cache often used values */
2891 ii = i / 256 + fill_data.xmin;
2892 jj = j / 256 + fill_data.ymin;
2895 if (cave[jj][ii].feat == 255)
2899 /* If greater than 'grid' level then is random */
2900 store_height(ii, jj, randint1(maxsize));
2904 /* Average of up and down points +random bit */
2905 store_height(ii, jj,
2906 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
2907 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
2908 + (randint1(ystep2) - yhstep2) * roug / 16);
2915 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
2917 for (j = yhstep; j <= yysize - yhstep; j += ystep)
2919 /* cache often used values */
2920 ii = i / 256 + fill_data.xmin;
2921 jj = j / 256 + fill_data.ymin;
2924 if (cave[jj][ii].feat == 255)
2928 /* If greater than 'grid' level then is random */
2929 store_height(ii, jj, randint1(maxsize));
2933 /* Cache reused values. */
2934 xm = fill_data.xmin + (i - xhstep) / 256;
2935 xp = fill_data.xmin + (i + xhstep) / 256;
2936 ym = fill_data.ymin + (j - yhstep) / 256;
2937 yp = fill_data.ymin + (j + yhstep) / 256;
2940 * Average over all four corners + scale by diagsize to
2941 * reduce the effect of the square grid on the shape of the fractal
2943 store_height(ii, jj,
2944 (cave[ym][xm].feat + cave[yp][xm].feat
2945 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
2946 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
2955 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)
2958 * function used to convert from height-map back to the
2959 * normal angband cave format
2961 if (cave[y][x].info & CAVE_ICKY)
2968 /* Show that have looked at this square */
2969 cave[y][x].info|= (CAVE_ICKY);
2971 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
2972 if (cave[y][x].feat <= c1)
2974 /* 25% of the time use the other tile : it looks better this way */
2975 if (randint1(100) < 75)
2977 cave[y][x].feat = feat1;
2978 cave[y][x].info &= ~(CAVE_MASK);
2979 cave[y][x].info |= info1;
2984 cave[y][x].feat = feat2;
2985 cave[y][x].info &= ~(CAVE_MASK);
2986 cave[y][x].info |= info2;
2990 else if (cave[y][x].feat <= c2)
2992 /* 25% of the time use the other tile : it looks better this way */
2993 if (randint1(100) < 75)
2995 cave[y][x].feat = feat2;
2996 cave[y][x].info &= ~(CAVE_MASK);
2997 cave[y][x].info |= info2;
3002 cave[y][x].feat = feat1;
3003 cave[y][x].info &= ~(CAVE_MASK);
3004 cave[y][x].info |= info1;
3008 else if (cave[y][x].feat <= c3)
3010 cave[y][x].feat = feat3;
3011 cave[y][x].info |= info3;
3014 /* if greater than cutoff then is a wall */
3017 place_outer_bold(y, x);
3027 * Quick and nasty fill routine used to find the connected region
3028 * of floor in the middle of the cave
3030 static void cave_fill(byte y, byte x)
3039 /*** Start Grid ***/
3041 /* Enqueue that entry */
3046 /* Now process the queue */
3047 while (flow_head != flow_tail)
3049 /* Extract the next entry */
3050 ty = temp_y[flow_head];
3051 tx = temp_x[flow_head];
3053 /* Forget that entry */
3054 if (++flow_head == TEMP_MAX) flow_head = 0;
3056 /* Add the "children" */
3057 for (d = 0; d < 8; d++)
3059 int old_head = flow_tail;
3061 /* Child location */
3062 j = ty + ddy_ddd[d];
3063 i = tx + ddx_ddd[d];
3065 /* Paranoia Don't leave the cave */
3066 if (!in_bounds(j, i))
3068 /* affect boundary */
3069 cave[j][i].info |= CAVE_ICKY;
3073 /* If within bounds */
3074 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3075 && (j > fill_data.ymin) && (j < fill_data.ymax))
3077 /* If not a wall or floor done before */
3078 if (hack_isnt_wall(j, i,
3079 fill_data.c1, fill_data.c2, fill_data.c3,
3080 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3081 fill_data.info1, fill_data.info2, fill_data.info3))
3083 /* Enqueue that entry */
3084 temp_y[flow_tail] = j;
3085 temp_x[flow_tail] = i;
3087 /* Advance the queue */
3088 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3090 /* Hack -- Overflow by forgetting new entry */
3091 if (flow_tail == flow_head)
3093 flow_tail = old_head;
3097 /* keep tally of size of cave system */
3098 (fill_data.amount)++;
3104 /* affect boundary */
3105 cave[j][i].info |= CAVE_ICKY;
3112 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3114 int x, y, i, xhsize, yhsize;
3117 /* offsets to middle from corner */
3123 * select region connected to center of cave system
3124 * this gets rid of alot of isolated one-sqaures that
3125 * can make teleport traps instadeaths...
3129 fill_data.c1 = cutoff;
3133 /* features to fill with */
3134 fill_data.feat1 = floor_type[randint0(100)];
3135 fill_data.feat2 = floor_type[randint0(100)];
3136 fill_data.feat3 = floor_type[randint0(100)];
3138 fill_data.info1 = CAVE_FLOOR;
3139 fill_data.info2 = CAVE_FLOOR;
3140 fill_data.info3 = CAVE_FLOOR;
3142 /* number of filled squares */
3143 fill_data.amount = 0;
3145 cave_fill((byte)y0, (byte)x0);
3147 /* if tally too small, try again */
3148 if (fill_data.amount < 10)
3150 /* too small - clear area and try again later */
3151 for (x = 0; x <= xsize; ++x)
3153 for (y = 0; y <= ysize; ++y)
3155 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3156 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3163 * Do boundarys-check to see if they are next to a filled region
3164 * If not then they are set to normal granite
3165 * If so then they are marked as room walls.
3167 for (i = 0; i <= xsize; ++i)
3170 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3172 /* Next to a 'filled' region? - set to be room walls */
3173 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3174 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3175 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3176 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3180 /* set to be normal granite */
3181 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3184 /* bottom boundary */
3185 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3187 /* Next to a 'filled' region? - set to be room walls */
3188 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3189 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3190 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3191 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3195 /* set to be normal granite */
3196 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3199 /* clear the icky flag-don't need it any more */
3200 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3201 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3204 /* Do the left and right boundaries minus the corners (done above) */
3205 for (i = 1; i < ysize; ++i)
3208 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3211 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3212 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3213 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3214 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3219 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3221 /* right boundary */
3222 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3225 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3226 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3227 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3228 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3233 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3236 /* clear icky flag -done with it */
3237 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3238 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3242 /* Do the rest: convert back to the normal format */
3243 for (x = 1; x < xsize; ++x)
3245 for (y = 1; y < ysize; ++y)
3247 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3248 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3250 /* Clear the icky flag in the filled region */
3251 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3253 /* Set appropriate flags */
3254 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3255 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3257 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3258 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3261 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3262 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3265 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3270 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3271 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3276 /* Clear the unconnected regions */
3277 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3278 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3284 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3285 * Extra doors appear inside the system. (Its not very noticeable though.)
3286 * This can be removed by "filling" from the outside in. This allows a separation
3287 * from FEAT_WALL_OUTER with FEAT_WALL_INNER. (Internal walls are F.W.OUTER instead.)
3288 * The extra effort for what seems to be only a minor thing (even non-existant if you
3289 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3298 * Driver routine to create fractal cave system
3300 static void build_type9(int by0, int bx0)
3302 int grd, roug, cutoff, xsize, ysize, y0, x0;
3304 bool done, light, room;
3306 /* get size: note 'Evenness'*/
3307 xsize = randint1(22) * 2 + 6;
3308 ysize = randint1(15) * 2 + 6;
3310 /* Try to allocate space for room. If fails, exit */
3311 if (!room_alloc(xsize + 1, ysize + 1, FALSE, by0, bx0, &x0, &y0)) return;
3313 light = done = FALSE;
3316 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3320 /* Note: size must be even or there are rounding problems
3321 * This causes the tunnels not to connect properly to the room */
3323 /* testing values for these parameters feel free to adjust */
3324 grd = 1 << (randint0(4));
3326 /* want average of about 16 */
3327 roug = randint1(8) * randint1(4);
3330 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3331 randint1(xsize / 4) + randint1(ysize / 4);
3334 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3336 /* Convert to normal format + clean up */
3337 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3341 #ifdef ALLOW_CAVERNS_AND_LAKES
3343 * Builds a cave system in the center of the dungeon.
3345 void build_cavern(void)
3347 int grd, roug, cutoff, xsize, ysize, x0, y0;
3350 light = done = FALSE;
3351 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3353 /* Make a cave the size of the dungeon */
3354 xsize = cur_wid - 1;
3355 ysize = cur_hgt - 1;
3359 /* Paranoia: make size even */
3365 /* testing values for these parameters: feel free to adjust */
3366 grd = randint1(4) + 4;
3368 /* want average of about 16 */
3369 roug = randint1(8) * randint1(4);
3375 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3377 /* Convert to normal format+ clean up */
3378 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3382 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3384 int x, y, i, xhsize, yhsize;
3385 int feat1, feat2, feat3;
3387 /* offsets to middle from corner */
3391 /* Get features based on type */
3396 feat1 = FEAT_DEEP_LAVA;
3397 feat2 = FEAT_SHAL_LAVA;
3398 feat3 = floor_type[randint0(100)];
3402 feat1 = FEAT_DEEP_WATER;
3403 feat2 = FEAT_SHAL_WATER;
3404 feat3 = floor_type[randint0(100)];
3407 /* Collapsed cave */
3408 feat1 = floor_type[randint0(100)];
3409 feat2 = floor_type[randint0(100)];
3410 feat3 = FEAT_RUBBLE;
3414 feat1 = FEAT_RUBBLE;
3415 feat2 = floor_type[randint0(100)];
3416 feat3 = FEAT_RUBBLE;
3426 feat1 = FEAT_SHAL_WATER;
3427 feat2 = FEAT_DEEP_WATER;
3428 feat3 = FEAT_SHAL_WATER;
3432 feat1 = FEAT_SHAL_LAVA;
3433 feat2 = FEAT_DEEP_LAVA;
3434 feat3 = FEAT_SHAL_LAVA;
3438 default: return FALSE;
3442 * select region connected to center of cave system
3443 * this gets rid of alot of isolated one-sqaures that
3444 * can make teleport traps instadeaths...
3452 /* features to fill with */
3453 fill_data.feat1 = feat1;
3454 fill_data.feat2 = feat2;
3455 fill_data.feat3 = feat3;
3457 fill_data.info1 = 0;
3458 fill_data.info2 = 0;
3459 fill_data.info3 = 0;
3461 /* number of filled squares */
3462 fill_data.amount = 0;
3464 /* select region connected to center of cave system
3465 * this gets rid of alot of isolated one-sqaures that
3466 * can make teleport traps instadeaths... */
3467 cave_fill((byte)y0, (byte)x0);
3469 /* if tally too small, try again */
3470 if (fill_data.amount < 10)
3472 /* too small -clear area and try again later */
3473 for (x = 0; x <= xsize; ++x)
3475 for (y = 0; y <= ysize; ++y)
3477 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3478 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3484 /* Do boundarys- set to normal granite */
3485 for (i = 0; i <= xsize; ++i)
3487 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3488 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3490 /* clear the icky flag-don't need it any more */
3491 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3492 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3495 /* Do the left and right boundaries minus the corners (done above) */
3497 for (i = 1; i < ysize; ++i)
3499 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3500 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3502 /* clear icky flag -done with it */
3503 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3504 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3508 /* Do the rest: convert back to the normal format */
3509 for (x = 1; x < xsize; ++x)
3511 for (y = 1; y < ysize; ++y)
3513 /* Fill unconnected regions with granite */
3514 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3515 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3516 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3518 /* turn off icky flag (no longer needed.) */
3519 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3521 /* Light lava and trees */
3522 if ((cave[y0 + y - yhsize][x0 + x - xhsize].feat == FEAT_DEEP_LAVA) ||
3523 (cave[y0 + y - yhsize][x0 + x - xhsize].feat == FEAT_SHAL_LAVA))
3525 cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3535 * makes a lake/collapsed cave system in the center of the dungeon
3537 void build_lake(int type)
3539 int grd, roug, xsize, ysize, x0, y0;
3543 /* paranoia - exit if lake type out of range. */
3544 if ((type < 1) || (type > 7))
3546 msg_format("Invalid lake type (%d)", type);
3550 /* Make the size of the dungeon */
3551 xsize = cur_wid - 1;
3552 ysize = cur_hgt - 1;
3556 /* Paranoia: make size even */
3562 /* testing values for these parameters: feel free to adjust */
3563 grd = randint1(3) + 4;
3565 /* want average of about 16 */
3566 roug = randint1(8) * randint1(4);
3568 /* Make up size of various componants */
3572 /* Deep water/lava */
3573 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
3575 /* Shallow boundary */
3579 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
3581 /* Convert to normal format+ clean up */
3582 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
3585 #endif /* ALLOW_CAVERNS_AND_LAKES */
3589 * Routine used by the random vault creators to add a door to a location
3590 * Note that range checking has to be done in the calling routine.
3592 * The doors must be INSIDE the allocated region.
3594 static void add_door(int x, int y)
3596 /* Need to have a wall in the center square */
3597 if (!is_outer_bold(y, x)) return;
3604 * where x=don't care
3608 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
3609 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
3612 place_secret_door(y, x);
3614 /* set boundarys so don't get wide doors */
3615 place_solid_bold(y, x - 1);
3616 place_solid_bold(y, x + 1);
3625 * where x = don't care
3628 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
3629 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
3632 place_secret_door(y, x);
3634 /* set boundarys so don't get wide doors */
3635 place_solid_bold(y - 1, x);
3636 place_solid_bold(y + 1, x);
3642 * Routine that fills the empty areas of a room with treasure and monsters.
3644 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
3646 int x, y, cx, cy, size;
3649 /* center of room:*/
3653 /* Rough measure of size of vault= sum of lengths of sides */
3654 size = abs(x2 - x1) + abs(y2 - y1);
3656 for (x = x1; x <= x2; x++)
3658 for (y = y1; y <= y2; y++)
3660 /* Thing added based on distance to center of vault
3661 * Difficulty is 1-easy to 10-hard */
3662 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
3664 /* hack- empty square part of the time */
3665 if ((randint1(100) - difficulty * 3) > 50) value = 20;
3667 /* if floor, shallow water and lava */
3668 if (is_floor_bold(y, x) ||
3669 (cave[y][x].feat == FEAT_SHAL_WATER) ||
3670 (cave[y][x].feat == FEAT_SHAL_LAVA))
3672 /* The smaller 'value' is, the better the stuff */
3675 /* Meanest monster + treasure */
3676 monster_level = base_level + 40;
3677 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3678 monster_level = base_level;
3679 object_level = base_level + 20;
3680 place_object(y, x, TRUE, FALSE);
3681 object_level = base_level;
3685 /* Mean monster +treasure */
3686 monster_level = base_level + 20;
3687 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3688 monster_level = base_level;
3689 object_level = base_level + 10;
3690 place_object(y, x, TRUE, FALSE);
3691 object_level = base_level;
3693 else if (value < 10)
3696 monster_level = base_level + 9;
3697 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3698 monster_level = base_level;
3700 else if (value < 17)
3702 /* Intentional Blank space */
3705 * (Want some of the vault to be empty
3706 * so have room for group monsters.
3707 * This is used in the hack above to lower
3708 * the density of stuff in the vault.)
3711 else if (value < 23)
3713 /* Object or trap */
3714 if (randint0(100) < 25)
3716 place_object(y, x, FALSE, FALSE);
3723 else if (value < 30)
3725 /* Monster and trap */
3726 monster_level = base_level + 5;
3727 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3728 monster_level = base_level;
3731 else if (value < 40)
3733 /* Monster or object */
3734 if (randint0(100) < 50)
3736 monster_level = base_level + 3;
3737 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3738 monster_level = base_level;
3740 if (randint0(100) < 50)
3742 object_level = base_level + 7;
3743 place_object(y, x, FALSE, FALSE);
3744 object_level = base_level;
3747 else if (value < 50)
3756 /* 20% monster, 40% trap, 20% object, 20% blank space */
3757 if (randint0(100) < 20)
3759 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3761 else if (randint0(100) < 50)
3765 else if (randint0(100) < 50)
3767 place_object(y, x, FALSE, FALSE);
3778 * This function creates a random vault that looks like a collection of bubbles.
3779 * It works by getting a set of coordinates that represent the center of each
3780 * bubble. The entire room is made by seeing which bubble center is closest. If
3781 * two centers are equidistant then the square is a wall, otherwise it is a floor.
3782 * The only exception is for squares really near a center, these are always floor.
3783 * (It looks better than without this check.)
3785 * Note: If two centers are on the same point then this algorithm will create a
3786 * blank bubble filled with walls. - This is prevented from happening.
3788 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
3790 #define BUBBLENUM 10 /* number of bubbles */
3792 /* array of center points of bubbles */
3793 coord center[BUBBLENUM];
3796 u16b min1, min2, temp;
3799 /* Offset from center to top left hand corner */
3800 int xhsize = xsize / 2;
3801 int yhsize = ysize / 2;
3804 if (cheat_room) msg_print("Bubble Vault");
3806 /* Allocate center of bubbles */
3807 center[0].x = randint1(xsize - 3) + 1;
3808 center[0].y = randint1(ysize - 3) + 1;
3810 for (i = 1; i < BUBBLENUM; i++)
3814 /* get center and check to see if it is unique */
3819 x = randint1(xsize - 3) + 1;
3820 y = randint1(ysize - 3) + 1;
3822 for (j = 0; j < i; j++)
3824 /* rough test to see if there is an overlap */
3825 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
3834 /* Top and bottom boundaries */
3835 for (i = 0; i < xsize; i++)
3837 int x = x0 - xhsize + i;
3839 place_outer_noperm_bold(y0 - yhsize + 0, x);
3840 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
3841 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
3842 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
3845 /* Left and right boundaries */
3846 for (i = 1; i < ysize - 1; i++)
3848 int y = y0 - yhsize + i;
3850 place_outer_noperm_bold(y, x0 - xhsize + 0);
3851 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
3852 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
3853 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
3856 /* Fill in middle with bubbles */
3857 for (x = 1; x < xsize - 1; x++)
3859 for (y = 1; y < ysize - 1; y++)
3861 /* Get distances to two closest centers */
3864 min1 = distance(x, y, center[0].x, center[0].y);
3865 min2 = distance(x, y, center[1].x, center[1].y);
3869 /* swap if in wrong order */
3876 for (i = 2; i < BUBBLENUM; i++)
3878 temp = distance(x, y, center[i].x, center[i].y);
3886 else if (temp < min2)
3888 /* second smallest */
3892 if (((min2 - min1) <= 2) && (!(min1 < 3)))
3894 /* Boundary at midpoint+ not at inner region of bubble */
3895 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
3899 /* middle of a bubble */
3900 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
3903 /* clean up rest of flags */
3904 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
3908 /* Try to add some random doors */
3909 for (i = 0; i < 500; i++)
3911 x = randint1(xsize - 3) - xhsize + x0 + 1;
3912 y = randint1(ysize - 3) - yhsize + y0 + 1;
3916 /* Fill with monsters and treasure, low difficulty */
3917 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
3922 * Overlay a rectangular room given its bounds
3923 * This routine is used by build_room_vault
3924 * The area inside the walls is not touched:
3925 * only granite is removed- normal walls stay
3927 static void build_room(int x1, int x2, int y1, int y2)
3929 int x, y, i, xsize, ysize, temp;
3931 /* Check if rectangle has no width */
3932 if ((x1 == x2) || (y1 == y2)) return;
3937 /* Swap boundaries if in wrong order */
3945 /* Swap boundaries if in wrong order */
3951 /* get total widths */
3956 /* Top and bottom boundaries */
3957 for (i = 0; i <= xsize; i++)
3959 place_outer_noperm_bold(y1, x1 + i);
3960 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
3961 place_outer_noperm_bold(y2, x1 + i);
3962 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
3965 /* Left and right boundaries */
3966 for (i = 1; i < ysize; i++)
3968 place_outer_noperm_bold(y1 + i, x1);
3969 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
3970 place_outer_noperm_bold(y1 + i, x2);
3971 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
3975 for (x = 1; x < xsize; x++)
3977 for (y = 1; y < ysize; y++)
3979 if (is_extra_bold(y1+y, x1+x))
3981 /* clear the untouched region */
3982 place_floor_bold(y1 + y, x1 + x);
3983 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
3987 /* make it a room- but don't touch */
3988 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
3995 /* Create a random vault that looks like a collection of overlapping rooms */
3997 static void build_room_vault(int x0, int y0, int xsize, int ysize)
3999 int i, x1, x2, y1, y2, xhsize, yhsize;
4001 /* get offset from center */
4005 if (cheat_room) msg_print("Room Vault");
4007 /* fill area so don't get problems with arena levels */
4008 for (x1 = 0; x1 < xsize; x1++)
4010 int x = x0 - xhsize + x1;
4012 for (y1 = 0; y1 < ysize; y1++)
4014 int y = y0 - yhsize + y1;
4016 place_extra_bold(y, x);
4017 cave[y][x].info &= (~CAVE_ICKY);
4021 /* add ten random rooms */
4022 for (i = 0; i < 10; i++)
4024 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4025 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4026 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4027 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4028 build_room(x1, x2, y1, y2);
4031 /* Add some random doors */
4032 for (i = 0; i < 500; i++)
4034 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4035 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4039 /* Fill with monsters and treasure, high difficulty */
4040 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4044 /* Create a random vault out of a fractal cave */
4045 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4047 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4048 bool done, light, room;
4050 /* round to make sizes even */
4056 if (cheat_room) msg_print("Cave Vault");
4058 light = done = FALSE;
4063 /* testing values for these parameters feel free to adjust */
4064 grd = 1 << randint0(4);
4066 /* want average of about 16 */
4067 roug = randint1(8) * randint1(4);
4070 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4071 randint1(xsize / 4) + randint1(ysize / 4);
4074 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4076 /* Convert to normal format+ clean up */
4077 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4080 /* Set icky flag because is a vault */
4081 for (x = 0; x <= xsize; x++)
4083 for (y = 0; y <= ysize; y++)
4085 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4089 /* Fill with monsters and treasure, low difficulty */
4090 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4094 * maze vault -- rectangular labyrinthine rooms
4096 * maze vault uses two routines:
4097 * r_visit - a recursive routine that builds the labyrinth
4098 * build_maze_vault - a driver routine that calls r_visit and adds
4099 * monsters, traps and treasure
4101 * The labyrinth is built by creating a spanning tree of a graph.
4102 * The graph vertices are at
4103 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4104 * and the edges are the vertical and horizontal nearest neighbors.
4106 * The spanning tree is created by performing a suitably randomized
4107 * depth-first traversal of the graph. The only adjustable parameter
4108 * is the randint0(3) below; it governs the relative density of
4109 * twists and turns in the labyrinth: smaller number, more twists.
4111 static void r_visit(int y1, int x1, int y2, int x2,
4112 int node, int dir, int *visited)
4114 int i, j, m, n, temp, x, y, adj[4];
4116 /* dimensions of vertex array */
4117 m = (x2 - x1) / 2 + 1;
4118 n = (y2 - y1) / 2 + 1;
4120 /* mark node visited and set it to a floor */
4122 x = 2 * (node % m) + x1;
4123 y = 2 * (node / m) + y1;
4124 place_floor_bold(y, x);
4126 /* setup order of adjacent node visits */
4129 /* pick a random ordering */
4130 for (i = 0; i < 4; i++)
4132 for (i = 0; i < 4; i++)
4143 /* pick a random ordering with dir first */
4145 for (i = 1; i < 4; i++)
4147 for (i = 1; i < 4; i++)
4149 j = 1 + randint0(3);
4156 for (i = 0; i < 4; i++)
4161 /* (0,+) - check for bottom boundary */
4162 if ((node / m < n - 1) && (visited[node + m] == 0))
4164 place_floor_bold(y + 1, x);
4165 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4169 /* (0,-) - check for top boundary */
4170 if ((node / m > 0) && (visited[node - m] == 0))
4172 place_floor_bold(y - 1, x);
4173 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4177 /* (+,0) - check for right boundary */
4178 if ((node % m < m - 1) && (visited[node + 1] == 0))
4180 place_floor_bold(y, x + 1);
4181 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4185 /* (-,0) - check for left boundary */
4186 if ((node % m > 0) && (visited[node - 1] == 0))
4188 place_floor_bold(y, x - 1);
4189 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4196 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4200 int m, n, num_vertices, *visited;
4205 if (cheat_room && is_vault) msg_print("Maze Vault");
4207 /* Choose lite or dark */
4208 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4210 /* Pick a random room size - randomized by calling routine */
4219 /* generate the room */
4220 for (y = y1 - 1; y <= y2 + 1; y++)
4222 for (x = x1 - 1; x <= x2 + 1; x++)
4224 c_ptr = &cave[y][x];
4225 c_ptr->info |= CAVE_ROOM;
4226 if (is_vault) c_ptr->info |= CAVE_ICKY;
4227 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4229 place_outer_grid(c_ptr);
4233 place_extra_grid(c_ptr);
4237 place_inner_grid(c_ptr);
4239 if (light) c_ptr->info |= (CAVE_GLOW);
4243 /* dimensions of vertex array */
4246 num_vertices = m * n;
4248 /* initialize array of visited vertices */
4249 C_MAKE(visited, num_vertices, int);
4251 /* traverse the graph to create a spaning tree, pick a random root */
4252 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4254 /* Fill with monsters and treasure, low difficulty */
4255 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4257 C_KILL(visited, num_vertices, int);
4261 /* Build a "mini" checkerboard vault
4263 * This is done by making a permanent wall maze and setting
4264 * the diagonal sqaures of the checker board to be granite.
4265 * The vault has two entrances on opposite sides to guarantee
4266 * a way to get in even if the vault abuts a side of the dungeon.
4268 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4271 int y1, x1, y2, x2, y, x, total;
4272 int m, n, num_vertices;
4275 if (cheat_room) msg_print("Mini Checker Board Vault");
4277 /* Pick a random room size */
4287 /* generate the room */
4288 for (x = x1 - 2; x <= x2 + 2; x++)
4290 if (!in_bounds(y1-2,x)) break;
4292 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4294 place_extra_noperm_bold(y1-2, x);
4297 for (x = x1 - 2; x <= x2 + 2; x++)
4299 if (!in_bounds(y2+2,x)) break;
4301 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4303 place_extra_noperm_bold(y2+2, x);
4306 for (y = y1 - 2; y <= y2 + 2; y++)
4308 if (!in_bounds(y,x1-2)) break;
4310 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4312 place_extra_noperm_bold(y, x1-2);
4315 for (y = y1 - 2; y <= y2 + 2; y++)
4317 if (!in_bounds(y,x2+2)) break;
4319 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4321 place_extra_noperm_bold(y, x2+2);
4324 for (y = y1 - 1; y <= y2 + 1; y++)
4326 for (x = x1 - 1; x <= x2 + 1; x++)
4328 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
4330 /* Permanent walls */
4331 cave[y][x].feat = FEAT_PERM_INNER;
4336 /* dimensions of vertex array */
4339 num_vertices = m * n;
4341 /* initialize array of visited vertices */
4342 C_MAKE(visited, num_vertices, int);
4344 /* traverse the graph to create a spannng tree, pick a random root */
4345 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4347 /* Make it look like a checker board vault */
4348 for (x = x1; x <= x2; x++)
4350 for (y = y1; y <= y2; y++)
4352 total = x - x1 + y - y1;
4353 /* If total is odd- and is a floor then make a wall */
4354 if ((total % 2 == 1) && is_floor_bold(y, x))
4356 place_inner_bold(y, x);
4361 /* Make a couple of entrances */
4364 /* left and right */
4365 y = randint1(dy) + dy / 2;
4366 place_outer_noperm_bold(y1 + y, x1 - 1);
4367 place_outer_noperm_bold(y1 + y, x2 + 1);
4371 /* top and bottom */
4372 x = randint1(dx) + dx / 2;
4373 place_outer_noperm_bold(y1 - 1, x1 + x);
4374 place_outer_noperm_bold(y2 + 1, x1 + x);
4377 /* Fill with monsters and treasure, highest difficulty */
4378 fill_treasure(x1, x2, y1, y2, 10);
4380 C_KILL(visited, num_vertices, int);
4384 /* Build a town/ castle by using a recursive algorithm.
4385 * Basically divide each region in a probalistic way to create
4386 * smaller regions. When the regions get too small stop.
4388 * The power variable is a measure of how well defended a region is.
4389 * This alters the possible choices.
4391 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4397 /* Temp variables */
4403 if ((power < 3) && (xsize > 12) && (ysize > 12))
4405 /* Need outside wall +keep */
4412 /* Make rooms + subdivide */
4413 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4419 choice = randint1(2) + 1;
4424 /* Mostly subdivide */
4425 choice = randint1(3) + 1;
4429 /* Based on the choice made above, do something */
4437 /* top and bottom */
4438 for (x = x1; x <= x2; x++)
4440 place_outer_bold(y1, x);
4441 place_outer_bold(y2, x);
4444 /* left and right */
4445 for (y = y1 + 1; y < y2; y++)
4447 place_outer_bold(y, x1);
4448 place_outer_bold(y, x2);
4451 /* Make a couple of entrances */
4454 /* left and right */
4455 y = randint1(ysize) + y1;
4456 place_floor_bold(y, x1);
4457 place_floor_bold(y, x2);
4461 /* top and bottom */
4462 x = randint1(xsize) + x1;
4463 place_floor_bold(y1, x);
4464 place_floor_bold(y2, x);
4467 /* Select size of keep */
4468 t1 = randint1(ysize / 3) + y1;
4469 t2 = y2 - randint1(ysize / 3);
4470 t3 = randint1(xsize / 3) + x1;
4471 t4 = x2 - randint1(xsize / 3);
4473 /* Do outside areas */
4475 /* Above and below keep */
4476 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4477 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4479 /* Left and right of keep */
4480 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4481 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4483 /* Make the keep itself: */
4496 /* Try to build a room */
4497 if ((xsize < 3) || (ysize < 3))
4499 for (y = y1; y < y2; y++)
4501 for (x = x1; x < x2; x++)
4503 place_inner_bold(y, x);
4511 /* Make outside walls */
4512 /* top and bottom */
4513 for (x = x1 + 1; x <= x2 - 1; x++)
4515 place_inner_bold(y1 + 1, x);
4516 place_inner_bold(y2 - 1, x);
4519 /* left and right */
4520 for (y = y1 + 1; y <= y2 - 1; y++)
4522 place_inner_bold(y, x1 + 1);
4523 place_inner_bold(y, x2 - 1);
4527 y = randint1(ysize - 3) + y1 + 1;
4532 place_floor_bold(y, x1 + 1);
4537 place_floor_bold(y, x2 - 1);
4540 /* Build the room */
4541 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4546 /* Try and divide vertically */
4550 for (y = y1; y < y2; y++)
4552 for (x = x1; x < x2; x++)
4554 place_inner_bold(y, x);
4560 t1 = randint1(xsize - 2) + x1 + 1;
4561 build_recursive_room(x1, y1, t1, y2, power - 2);
4562 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
4567 /* Try and divide horizontally */
4571 for (y = y1; y < y2; y++)
4573 for (x = x1; x < x2; x++)
4575 place_inner_bold(y, x);
4581 t1 = randint1(ysize - 2) + y1 + 1;
4582 build_recursive_room(x1, y1, x2, t1, power - 2);
4583 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
4590 /* Build a castle */
4592 /* Driver routine: clear the region and call the recursive
4595 *This makes a vault that looks like a castle/ city in the dungeon.
4597 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
4603 /* Pick a random room size */
4612 if (cheat_room) msg_print("Castle Vault");
4614 /* generate the room */
4615 for (y = y1 - 1; y <= y2 + 1; y++)
4617 for (x = x1 - 1; x <= x2 + 1; x++)
4619 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
4620 /* Make everything a floor */
4621 place_floor_bold(y, x);
4625 /* Make the castle */
4626 build_recursive_room(x1, y1, x2, y2, randint1(5));
4628 /* Fill with monsters and treasure, low difficulty */
4629 fill_treasure(x1, x2, y1, y2, randint1(3));
4634 * Add outer wall to a floored region
4635 * Note: no range checking is done so must be inside dungeon
4636 * This routine also stomps on doors
4638 static void add_outer_wall(int x, int y, int light,
4639 int x1, int y1, int x2, int y2)
4643 if (!in_bounds(y, x)) return;
4645 /* hack- check to see if square has been visited before
4646 * if so, then exit (use room flag to do this) */
4647 if (cave[y][x].info & CAVE_ROOM) return;
4650 cave[y][x].info |= CAVE_ROOM;
4652 if (is_floor_bold(y, x))
4654 for (i = -1; i <= 1; i++)
4656 for (j = -1; j <= 1; j++)
4658 if ((x + i >= x1) && (x + i <= x2) &&
4659 (y + j >= y1) && (y + j <= y2))
4661 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
4662 if (light) cave[y][x].info |= CAVE_GLOW;
4667 else if (is_extra_bold(y, x))
4669 /* Set bounding walls */
4670 place_outer_bold(y, x);
4671 if (light == TRUE) cave[y][x].info |= CAVE_GLOW;
4673 else if (cave[y][x].feat == FEAT_PERM_OUTER)
4675 /* Set bounding walls */
4676 if (light == TRUE) cave[y][x].info |= CAVE_GLOW;
4682 * Hacked distance formula - gives the 'wrong' answer.
4683 * Used to build crypts
4685 static int dist2(int x1, int y1, int x2, int y2,
4686 int h1, int h2, int h3, int h4)
4692 /* Basically this works by taking the normal pythagorean formula
4693 * and using an expansion to express this in a way without the
4694 * square root. This approximate formula is then perturbed to give
4695 * the distorted results. (I found this by making a mistake when I was
4696 * trying to fix the circular rooms.)
4699 /* h1-h4 are constants that describe the metric */
4700 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
4701 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
4702 return (((dx + dy) * 128) / 181 +
4703 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
4704 /* 128/181 is approx. 1/sqrt(2) */
4709 * Build target vault.
4710 * This is made by two concentric "crypts" with perpendicular
4711 * walls creating the cross-hairs.
4713 static void build_target_vault(int x0, int y0, int xsize, int ysize)
4717 /* Make a random metric */
4719 h1 = randint1(32) - 16;
4722 h4 = randint1(32) - 16;
4724 if (cheat_room) msg_print("Target Vault");
4726 /* work out outer radius */
4737 for (x = x0 - rad; x <= x0 + rad; x++)
4739 for (y = y0 - rad; y <= y0 + rad; y++)
4741 /* clear room flag */
4742 cave[y][x].info &= ~(CAVE_ROOM);
4744 /* Vault - so is "icky" */
4745 cave[y][x].info |= CAVE_ICKY;
4747 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
4749 /* inside- so is floor */
4750 place_floor_bold(y, x);
4754 /* make granite outside so arena works */
4755 place_extra_bold(y, x);
4758 /* proper boundary for arena */
4759 if (((y + rad) == y0) || ((y - rad) == y0) ||
4760 ((x + rad) == x0) || ((x - rad) == x0))
4762 place_extra_bold(y, x);
4767 /* Find visible outer walls and set to be FEAT_OUTER */
4768 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
4769 x0 + rad + 1, y0 + rad + 1);
4771 /* Add inner wall */
4772 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
4774 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
4776 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
4778 /* Make an internal wall */
4779 place_inner_bold(y, x);
4784 /* Add perpendicular walls */
4785 for (x = x0 - rad; x <= x0 + rad; x++)
4787 place_inner_bold(y0, x);
4790 for (y = y0 - rad; y <= y0 + rad; y++)
4792 place_inner_bold(y, x0);
4795 /* Make inner vault */
4796 for (y = y0 - 1; y <= y0 + 1; y++)
4798 place_inner_bold(y, x0 - 1);
4799 place_inner_bold(y, x0 + 1);
4801 for (x = x0 - 1; x <= x0 + 1; x++)
4803 place_inner_bold(y0 - 1, x);
4804 place_inner_bold(y0 + 1, x);
4807 place_floor_bold(y0, x0);
4810 /* Add doors to vault */
4811 /* get two distances so can place doors relative to centre */
4812 x = (rad - 2) / 4 + 1;
4815 add_door(x0 + x, y0);
4816 add_door(x0 + y, y0);
4817 add_door(x0 - x, y0);
4818 add_door(x0 - y, y0);
4819 add_door(x0, y0 + x);
4820 add_door(x0, y0 + y);
4821 add_door(x0, y0 - x);
4822 add_door(x0, y0 - y);
4824 /* Fill with stuff - medium difficulty */
4825 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
4829 #ifdef ALLOW_CAVERNS_AND_LAKES
4831 * This routine uses a modified version of the lake code to make a
4832 * distribution of some terrain type over the vault. This type
4833 * depends on the dungeon depth.
4835 * Miniture rooms are then scattered across the vault.
4837 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
4842 int xsize, ysize, xhsize, yhsize, x, y, i;
4846 if (cheat_room) msg_print("Elemental Vault");
4848 /* round to make sizes even */
4856 /* Earth vault (Rubble) */
4859 else if (dun_level < 50)
4861 /* Air vault (Trees) */
4864 else if (dun_level < 75)
4866 /* Water vault (shallow water) */
4871 /* Fire vault (shallow lava) */
4877 /* testing values for these parameters: feel free to adjust */
4878 grd = 1 << (randint0(3));
4880 /* want average of about 16 */
4881 roug = randint1(8) * randint1(4);
4883 /* Make up size of various componants */
4887 /* Deep water/lava */
4888 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4890 /* Shallow boundary */
4894 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
4896 /* Convert to normal format+ clean up */
4897 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
4900 /* Set icky flag because is a vault */
4901 for (x = 0; x <= xsize; x++)
4903 for (y = 0; y <= ysize; y++)
4905 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4909 /* make a few rooms in the vault */
4910 for (i = 1; i <= (xsize * ysize) / 50; i++)
4912 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
4913 y0 + randint0(ysize - 4) - ysize / 2 + 2);
4916 /* Fill with monsters and treasure, low difficulty */
4917 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
4918 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4920 #endif /* ALLOW_CAVERNS_AND_LAKES */
4926 static void build_type10(int by0, int bx0)
4928 int y0, x0, xsize, ysize, vtype;
4931 /* big enough to look good, small enough to be fairly common. */
4932 xsize = randint1(22) + 22;
4933 ysize = randint1(11) + 11;
4935 /* Allocate in room_map. If will not fit, exit */
4936 if (!room_alloc(xsize + 1, ysize + 1, FALSE, by0, bx0, &x0, &y0)) return;
4938 /* Boost the rating- higher than lesser vaults and lower than greater vaults */
4941 /* (Sometimes) Cause a special feeling */
4942 if ((dun_level <= 50) ||
4943 (randint1((dun_level - 40) * (dun_level - 40) + 1) < 400))
4945 good_item_flag = TRUE;
4948 /* Select type of vault */
4949 #ifdef ALLOW_CAVERNS_AND_LAKES
4950 vtype = randint1(15);
4951 #else /* ALLOW_CAVERNS_AND_LAKES */
4952 vtype = randint1(7);
4953 #endif /* ALLOW_CAVERNS_AND_LAKES */
4957 /* Build an appropriate room */
4958 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
4959 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
4960 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
4961 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
4962 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
4963 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
4964 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
4965 #ifdef ALLOW_CAVERNS_AND_LAKES
4966 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
4967 #endif /* ALLOW_CAVERNS_AND_LAKES */
4968 /* I know how to add a few more... give me some time. */
4977 * Build an vertical oval room.
4978 * For every grid in the possible square, check the distance.
4979 * If it's less than the radius, make it a room square.
4981 * When done fill from the inside to find the walls,
4983 static void build_type11(int by0, int bx0)
4985 int rad, x, y, x0, y0;
4988 /* Occasional light */
4989 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
4993 /* Allocate in room_map. If will not fit, exit */
4994 if (!room_alloc(rad * 2 + 1, rad * 2 + 1, FALSE, by0, bx0, &x0, &y0)) return;
4996 /* Make circular floor */
4997 for (x = x0 - rad; x <= x0 + rad; x++)
4999 for (y = y0 - rad; y <= y0 + rad; y++)
5001 if (distance(y0, x0, y, x) <= rad - 1)
5003 /* inside- so is floor */
5004 place_floor_bold(y, x);
5006 else if (distance(y0, x0, y, x) <= rad + 1)
5008 /* make granite outside so arena works */
5009 place_extra_bold(y, x);
5014 /* Find visible outer walls and set to be FEAT_OUTER */
5015 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5021 * For every grid in the possible square, check the (fake) distance.
5022 * If it's less than the radius, make it a room square.
5024 * When done fill from the inside to find the walls,
5026 static void build_type12(int by0, int bx0)
5028 int rad, x, y, x0, y0;
5030 bool emptyflag = TRUE;
5032 /* Make a random metric */
5034 h1 = randint1(32) - 16;
5037 h4 = randint1(32) - 16;
5039 /* Occasional light */
5040 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5044 /* Allocate in room_map. If will not fit, exit */
5045 if (!room_alloc(rad * 2 + 3, rad * 2 + 3, FALSE, by0, bx0, &x0, &y0)) return;
5048 for (x = x0 - rad; x <= x0 + rad; x++)
5050 for (y = y0 - rad; y <= y0 + rad; y++)
5052 /* clear room flag */
5053 cave[y][x].info &= ~(CAVE_ROOM);
5055 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5057 /* inside - so is floor */
5058 place_floor_bold(y, x);
5060 else if (distance(y0, x0, y, x) < 3)
5062 place_floor_bold(y, x);
5066 /* make granite outside so arena works */
5067 place_extra_bold(y, x);
5070 /* proper boundary for arena */
5071 if (((y + rad) == y0) || ((y - rad) == y0) ||
5072 ((x + rad) == x0) || ((x - rad) == x0))
5074 place_extra_bold(y, x);
5079 /* Find visible outer walls and set to be FEAT_OUTER */
5080 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5081 x0 + rad + 1, y0 + rad + 1);
5083 /* Check to see if there is room for an inner vault */
5084 for (x = x0 - 2; x <= x0 + 2; x++)
5086 for (y = y0 - 2; y <= y0 + 2; y++)
5088 if (!is_floor_bold(y, x))
5090 /* Wall in the way */
5096 if (emptyflag && one_in_(2))
5098 /* Build the vault */
5099 build_small_room(x0, y0);
5101 /* Place a treasure in the vault */
5102 place_object(y0, x0, FALSE, FALSE);
5104 /* Let's guard the treasure well */
5105 vault_monsters(y0, x0, randint0(2) + 3);
5107 /* Traps naturally */
5108 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5114 * Helper function for "trapped monster pit"
5116 static bool vault_aux_trapped_pit(int r_idx)
5118 monster_race *r_ptr = &r_info[r_idx];
5120 /* Validate the monster */
5121 if (!vault_monster_okay(r_idx)) return (FALSE);
5123 /* No wall passing monster */
5124 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5132 * Type 12 -- Trapped monster pits
5134 * A trapped monster pit is a "big" room with a straight corridor in
5135 * which wall opening traps are placed, and with two "inner" rooms
5136 * containing a "collection" of monsters of a given type organized in
5139 * The trapped monster pit appears as shown below, where the actual
5140 * monsters in each location depend on the type of the pit
5142 * #########################
5144 * ####################### #
5145 * #####001123454321100### #
5146 * ###0012234567654322100# #
5147 * ####################### #
5149 * # #######################
5150 * # #0012234567654322100###
5151 * # ###001123454321100#####
5152 * # #######################
5154 * #########################
5156 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5157 * to request 16 "appropriate" monsters, sorting them by level, and using
5158 * the "even" entries in this sorted list for the contents of the pit.
5160 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5161 * which is handled by requiring a specific "breath" attack for all of the
5162 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5163 * be present in many of the dragon pits, if they have the proper breath.
5165 * Note the use of the "get_mon_num_prep()" function, and the special
5166 * "get_mon_num_hook()" restriction function, to prepare the "monster
5167 * allocation table" in such a way as to optimize the selection of
5168 * "appropriate" non-unique monsters for the pit.
5170 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5171 * the pit will be empty, and will not effect the level rating.
5173 * Note that "monster pits" will never contain "unique" monsters.
5175 static void build_type13(int by0, int bx0)
5177 static int placing[][3] = {
5178 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5179 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5180 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5181 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5182 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5183 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5184 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5185 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5186 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5187 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5188 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5189 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5190 {-2, -4, 3}, {-3, -2, 3},
5191 {+2, -4, 3}, {+3, -2, 3},
5192 {-2, +4, 3}, {-3, +2, 3},
5193 {+2, +4, 3}, {+3, +2, 3},
5194 {-2, -3, 4}, {-3, -1, 4},
5195 {+2, -3, 4}, {+3, -1, 4},
5196 {-2, +3, 4}, {-3, +1, 4},
5197 {+2, +3, 4}, {+3, +1, 4},
5198 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5199 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5200 {-2, -1, 6}, {-2, +1, 6},
5201 {+2, -1, 6}, {+2, +1, 6},
5202 {-2, 0, 7}, {+2, 0, 7},
5206 int y, x, y1, x1, y2, x2, xval, yval;
5215 vault_aux_type *n_ptr = pick_vault_type(pit_types, ROOM_PIT);
5217 /* Only in Angband */
5218 if (dungeon_type != 1) return;
5220 /* Try to allocate space for room. */
5221 if (!room_alloc(25, 13, TRUE, by0, bx0, &xval, &yval)) return;
5223 /* No type available */
5226 /* Process a preparation function if necessary */
5227 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5235 /* Fill with inner walls */
5236 for (y = y1 - 1; y <= y2 + 1; y++)
5238 for (x = x1 - 1; x <= x2 + 1; x++)
5240 c_ptr = &cave[y][x];
5241 place_solid_grid(c_ptr);
5245 /* Place the floor area 1 */
5246 for (x = x1 + 3; x <= x2 - 3; x++)
5248 c_ptr = &cave[yval-2][x];
5249 place_floor_grid(c_ptr);
5250 c_ptr->info |= (CAVE_ROOM);
5251 add_cave_info(yval-2, x, CAVE_ICKY);
5253 c_ptr = &cave[yval+2][x];
5254 place_floor_grid(c_ptr);
5255 c_ptr->info |= (CAVE_ROOM);
5256 add_cave_info(yval+2, x, CAVE_ICKY);
5259 /* Place the floor area 2 */
5260 for (x = x1 + 5; x <= x2 - 5; x++)
5262 c_ptr = &cave[yval-3][x];
5263 place_floor_grid(c_ptr);
5264 c_ptr->info |= (CAVE_ROOM);
5265 add_cave_info(yval-3, x, CAVE_ICKY);
5267 c_ptr = &cave[yval+3][x];
5268 place_floor_grid(c_ptr);
5269 c_ptr->info |= (CAVE_ROOM);
5270 add_cave_info(yval+3, x, CAVE_ICKY);
5274 for (x = x1; x <= x2; x++)
5276 c_ptr = &cave[yval][x];
5277 place_floor_grid(c_ptr);
5278 c_ptr = &cave[y1][x];
5279 place_floor_grid(c_ptr);
5280 c_ptr = &cave[y2][x];
5281 place_floor_grid(c_ptr);
5284 /* Random corridor */
5287 for (y = y1; y <= yval; y++)
5289 c_ptr = &cave[y][x1];
5290 place_floor_grid(c_ptr);
5292 for (y = yval; y <= y2 + 1; y++)
5294 c_ptr = &cave[y][x2];
5295 place_floor_grid(c_ptr);
5300 for (y = yval; y <= y2 + 1; y++)
5302 c_ptr = &cave[y][x1];
5303 place_floor_grid(c_ptr);
5305 for (y = y1; y <= yval; y++)
5307 c_ptr = &cave[y][x2];
5308 place_floor_grid(c_ptr);
5312 /* Place the outer walls */
5313 for (y = y1 - 1; y <= y2 + 1; y++)
5315 c_ptr = &cave[y][x1 - 1];
5316 place_outer_grid(c_ptr);
5317 c_ptr = &cave[y][x2 + 1];
5318 place_outer_grid(c_ptr);
5320 for (x = x1 - 1; x <= x2 + 1; x++)
5322 c_ptr = &cave[y1 - 1][x];
5323 place_outer_grid(c_ptr);
5324 c_ptr = &cave[y2 + 1][x];
5325 place_outer_grid(c_ptr);
5328 /* Place the wall open trap */
5329 cave[yval][xval].mimic = cave[yval][xval].feat;
5330 cave[yval][xval].feat = FEAT_TRAP_OPEN;
5331 add_cave_info(yval, xval, CAVE_ROOM);
5333 /* Prepare allocation table */
5334 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5336 /* Pick some monster types */
5337 for (i = 0; i < 16; i++)
5339 int r_idx = 0, attempts = 100;
5343 /* Get a (hard) monster type */
5344 r_idx = get_mon_num(dun_level + 0);
5346 /* Decline incorrect alignment */
5347 if (((align < 0) && (r_info[r_idx].flags3 & RF3_GOOD)) ||
5348 ((align > 0) && (r_info[r_idx].flags3 & RF3_EVIL)))
5353 /* Accept this monster */
5357 /* Notice failure */
5358 if (!r_idx || !attempts) return;
5360 /* Note the alignment */
5361 if (r_info[r_idx].flags3 & RF3_GOOD) align++;
5362 else if (r_info[r_idx].flags3 & RF3_EVIL) align--;
5367 /* Sort the entries */
5368 for (i = 0; i < 16 - 1; i++)
5370 /* Sort the entries */
5371 for (j = 0; j < 16 - 1; j++)
5376 int p1 = r_info[what[i1]].level;
5377 int p2 = r_info[what[i2]].level;
5383 what[i1] = what[i2];
5393 msg_format("%s¤Î櫥ԥåÈ", n_ptr->name);
5396 msg_format("Trapped monster pit (%s)", n_ptr->name);
5400 /* Select the entries */
5401 for (i = 0; i < 8; i++)
5403 /* Every other entry */
5404 what[i] = what[i * 2];
5409 msg_print(r_name + r_info[what[i]].name);
5413 /* Increase the level rating */
5416 /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
5417 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
5419 good_item_flag = TRUE;
5423 for (i = 0; placing[i][2] >= 0; i++)
5425 y = yval + placing[i][0];
5426 x = xval + placing[i][1];
5427 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5433 * Attempt to build a room of the given type at the given block
5435 * Note that we restrict the number of "crowded" rooms to reduce
5436 * the chance of overflowing the monster list during level creation.
5438 bool room_build(int by0, int bx0, int typ)
5440 /* Restrict level */
5441 if ((dun_level < roomdep[typ]) && !ironman_rooms) return (FALSE);
5443 /* Restrict "crowded" rooms */
5444 if ((dun->crowded >= 2) && ((typ == 5) || (typ == 6) || (typ == 13))) return (FALSE);
5449 /* Build an appropriate room */
5450 case 13: build_type13(by0, bx0); break;
5451 case 12: build_type12(by0, bx0); break;
5452 case 11: build_type11(by0, bx0); break;
5453 case 10: build_type10(by0, bx0); break;
5454 case 9: build_type9(by0, bx0); break;
5455 case 8: build_type8(by0, bx0); break;
5456 case 7: build_type7(by0, bx0); break;
5457 case 6: build_type6(by0, bx0, FALSE); break;
5458 case 5: build_type5(by0, bx0, FALSE); break;
5459 case 4: build_type4(by0, bx0); break;
5460 case 3: build_type3(by0, bx0); break;
5461 case 2: build_type2(by0, bx0); break;
5462 case 1: build_type1(by0, bx0); break;
5465 default: return (FALSE);