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 */
39 20, /* 14 = Piranha/Armageddon trap room */
43 static void place_locked_door(int y, int x)
45 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
47 place_floor_bold(y, x);
51 set_cave_feat(y, x, FEAT_DOOR_HEAD+randint1(7));
52 cave[y][x].info &= ~(CAVE_FLOOR);
56 static void place_secret_door(int y, int x)
58 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
60 place_floor_bold(y, x);
64 cave_type *c_ptr = &cave[y][x];
66 /* Create secret door */
67 place_closed_door(y, x);
70 c_ptr->mimic = fill_type[randint0(100)];
72 /* Floor type terrain cannot hide a door */
73 if (!(c_ptr->mimic & 0x20))
75 c_ptr->feat = c_ptr->mimic;
79 c_ptr->info &= ~(CAVE_FLOOR);
84 * This funtion makes a very small room centred at (x0, y0)
85 * This is used in crypts, and random elemental vaults.
87 * Note - this should be used only on allocated regions
88 * within another room.
90 static void build_small_room(int x0, int y0)
94 for (y = y0 - 1; y <= y0 + 1; y++)
96 place_inner_bold(y, x0 - 1);
97 place_inner_bold(y, x0 + 1);
100 for (x = x0 - 1; x <= x0 + 1; x++)
102 place_inner_bold(y0 - 1, x);
103 place_inner_bold(y0 + 1, x);
106 /* Place a secret door on one side */
109 case 0: place_secret_door(y0, x0 - 1); break;
110 case 1: place_secret_door(y0, x0 + 1); break;
111 case 2: place_secret_door(y0 - 1, x0); break;
112 case 3: place_secret_door(y0 + 1, x0); break;
115 /* Clear mimic type */
116 cave[y0][x0].mimic = 0;
118 /* Add inner open space */
119 place_floor_bold(y0, x0);
124 * This function tunnels around a room if
125 * it will cut off part of a cave system.
127 static void check_room_boundary(int x1, int y1, int x2, int y2)
130 bool old_is_floor, new_is_floor;
136 old_is_floor = get_is_floor(x1 - 1, y1);
139 * Count the number of floor-wall boundaries around the room
140 * Note: diagonal squares are ignored since the player can move diagonally
141 * to bypass these if needed.
144 /* Above the top boundary */
145 for (x = x1; x <= x2; x++)
147 new_is_floor = get_is_floor(x, y1 - 1);
149 /* Increment counter if they are different */
150 if (new_is_floor != old_is_floor) count++;
152 old_is_floor = new_is_floor;
156 for (y = y1; y <= y2; y++)
158 new_is_floor = get_is_floor(x2 + 1, y);
160 /* increment counter if they are different */
161 if (new_is_floor != old_is_floor) count++;
163 old_is_floor = new_is_floor;
166 /* Bottom boundary */
167 for (x = x2; x >= x1; x--)
169 new_is_floor = get_is_floor(x, y2 + 1);
171 /* increment counter if they are different */
172 if (new_is_floor != old_is_floor) count++;
174 old_is_floor = new_is_floor;
178 for (y = y2; y >= y1; y--)
180 new_is_floor = get_is_floor(x1 - 1, y);
182 /* increment counter if they are different */
183 if (new_is_floor != old_is_floor) count++;
185 old_is_floor = new_is_floor;
188 /* If all the same, or only one connection exit. */
189 if (count <= 2) return;
192 /* Tunnel around the room so to prevent problems with caves */
193 for (y = y1; y <= y2; y++)
195 for (x = x1; x <= x2; x++)
204 * This function is used to allocate the space needed by a room in the room_map
206 * x, y represent the size of the room (0...x-1) by (0...y-1).
207 * crowded is used to denote a monset nest.
208 * by0, bx0 are the positions in the room_map array given to the build_type'x'
210 * xx, yy are the returned center of the allocated room in coordinates for
211 * cave.feat and cave.info etc.
213 static bool room_alloc(int x, int y, bool crowded, int by0, int bx0, int *xx, int *yy)
215 int temp, bx1, bx2, by1, by2, by, bx;
217 /* Calculate number of room_map squares to allocate */
219 /* temp is total number along width */
220 temp = ((x - 1) / BLOCK_WID) + 1;
222 /* bx2 = ending block */
223 bx2 = temp / 2 + bx0;
225 /* bx1 = starting block (Note: rounding taken care of here.) */
226 bx1 = bx2 + 1 - temp;
228 /* temp is total number along height */
229 temp = ((y - 1) / BLOCK_HGT) + 1;
231 /* by2 = ending block */
232 by2 = temp / 2 + by0;
234 /* by1 = starting block */
235 by1 = by2 + 1 - temp;
238 /* Never run off the screen */
239 if ((by1 < 0) || (by2 >= dun->row_rooms)) return (FALSE);
240 if ((bx1 < 0) || (bx2 >= dun->col_rooms)) return (FALSE);
242 /* Verify open space */
243 for (by = by1; by <= by2; by++)
245 for (bx = bx1; bx <= bx2; bx++)
247 if (dun->room_map[by][bx]) return (FALSE);
251 /* It is *extremely* important that the following calculation */
252 /* be *exactly* correct to prevent memory errors XXX XXX XXX */
254 /* Acquire the location of the room */
255 *yy = ((by1 + by2 + 1) * BLOCK_HGT) / 2;
256 *xx = ((bx1 + bx2 + 1) * BLOCK_WID) / 2;
259 /* Save the room location */
260 if (dun->cent_n < CENT_MAX)
262 dun->cent[dun->cent_n].y = *yy;
263 dun->cent[dun->cent_n].x = *xx;
267 /* Reserve some blocks */
268 for (by = by1; by <= by2; by++)
270 for (bx = bx1; bx <= bx2; bx++)
272 dun->room_map[by][bx] = TRUE;
276 /* Count "crowded" rooms */
277 if (crowded) dun->crowded++;
280 * Hack- See if room will cut off a cavern.
281 * If so, fix by tunneling outside the room in such a way as to connect the caves.
283 check_room_boundary(*xx - x / 2 - 1, *yy - y / 2 - 1,
284 *xx + (x - 1) / 2 + 1, *yy + (y - 1) / 2 + 1);
291 * Room building routines.
297 * 4 -- large room with features
301 * 8 -- greater vaults
303 * 10 -- random vaults
304 * 11 -- circular rooms
306 * 13 -- trapped monster pits
312 * Type 1 -- normal rectangular rooms
314 static void build_type1(int by0, int bx0)
316 int y, x, y2, x2, yval, xval;
317 int y1, x1, xsize, ysize;
323 /* Pick a room size */
332 /* Try to allocate space for room. If fails, exit */
333 if (!room_alloc(xsize + 2, ysize + 2, FALSE, by0, bx0, &xval, &yval)) return;
335 /* Choose lite or dark */
336 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
339 /* Get corner values */
340 y1 = yval - ysize / 2;
341 x1 = xval - xsize / 2;
342 y2 = yval + (ysize - 1) / 2;
343 x2 = xval + (xsize - 1) / 2;
346 /* Place a full floor under the room */
347 for (y = y1 - 1; y <= y2 + 1; y++)
349 for (x = x1 - 1; x <= x2 + 1; x++)
352 place_floor_grid(c_ptr);
353 c_ptr->info |= (CAVE_ROOM);
354 if (light) c_ptr->info |= (CAVE_GLOW);
358 /* Walls around the room */
359 for (y = y1 - 1; y <= y2 + 1; y++)
361 c_ptr = &cave[y][x1 - 1];
362 place_outer_grid(c_ptr);
363 c_ptr = &cave[y][x2 + 1];
364 place_outer_grid(c_ptr);
366 for (x = x1 - 1; x <= x2 + 1; x++)
368 c_ptr = &cave[y1 - 1][x];
369 place_outer_grid(c_ptr);
370 c_ptr = &cave[y2 + 1][x];
371 place_outer_grid(c_ptr);
375 /* Hack -- Occasional pillar room */
378 for (y = y1; y <= y2; y += 2)
380 for (x = x1; x <= x2; x += 2)
383 place_inner_grid(c_ptr);
388 /* Hack -- Occasional room with four pillars */
389 else if (one_in_(20))
391 if ((y1 + 4 < y2) && (x1 + 4 < x2))
393 c_ptr = &cave[y1 + 1][x1 + 1];
394 place_inner_grid(c_ptr);
396 c_ptr = &cave[y1 + 1][x2 - 1];
397 place_inner_grid(c_ptr);
399 c_ptr = &cave[y2 - 1][x1 + 1];
400 place_inner_grid(c_ptr);
402 c_ptr = &cave[y2 - 1][x2 - 1];
403 place_inner_grid(c_ptr);
407 /* Hack -- Occasional ragged-edge room */
408 else if (one_in_(50))
410 for (y = y1 + 2; y <= y2 - 2; y += 2)
412 c_ptr = &cave[y][x1];
413 place_inner_grid(c_ptr);
414 c_ptr = &cave[y][x2];
415 place_inner_grid(c_ptr);
417 for (x = x1 + 2; x <= x2 - 2; x += 2)
419 c_ptr = &cave[y1][x];
420 place_inner_grid(c_ptr);
421 c_ptr = &cave[y2][x];
422 place_inner_grid(c_ptr);
425 /* Hack -- Occasional divided room */
426 else if (one_in_(50))
428 if (randint1(100) < 50)
430 /* Horizontal wall */
431 for (x = x1; x <= x2; x++)
433 place_inner_bold(yval, x);
436 /* Prevent edge of wall from being tunneled */
437 place_solid_bold(yval, x1 - 1);
438 place_solid_bold(yval, x2 + 1);
443 for (y = y1; y <= y2; y++)
445 place_inner_bold(y, xval);
448 /* Prevent edge of wall from being tunneled */
449 place_solid_bold(y1 - 1, xval);
450 place_solid_bold(y2 + 1, xval);
453 place_random_door(yval, xval);
459 * Type 2 -- Overlapping rectangular rooms
461 static void build_type2(int by0, int bx0)
463 int y, x, xval, yval;
464 int y1a, x1a, y2a, x2a;
465 int y1b, x1b, y2b, x2b;
470 /* Try to allocate space for room. If fails, exit */
471 if (!room_alloc(25, 11, FALSE, by0, bx0, &xval, &yval)) return;
473 /* Choose lite or dark */
474 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
476 /* Determine extents of the first room */
477 y1a = yval - randint1(4);
478 y2a = yval + randint1(3);
479 x1a = xval - randint1(11);
480 x2a = xval + randint1(10);
482 /* Determine extents of the second room */
483 y1b = yval - randint1(3);
484 y2b = yval + randint1(4);
485 x1b = xval - randint1(10);
486 x2b = xval + randint1(11);
489 /* Place a full floor for room "a" */
490 for (y = y1a - 1; y <= y2a + 1; y++)
492 for (x = x1a - 1; x <= x2a + 1; x++)
495 place_floor_grid(c_ptr);
496 c_ptr->info |= (CAVE_ROOM);
497 if (light) c_ptr->info |= (CAVE_GLOW);
501 /* Place a full floor for room "b" */
502 for (y = y1b - 1; y <= y2b + 1; y++)
504 for (x = x1b - 1; x <= x2b + 1; x++)
507 place_floor_grid(c_ptr);
508 c_ptr->info |= (CAVE_ROOM);
509 if (light) c_ptr->info |= (CAVE_GLOW);
514 /* Place the walls around room "a" */
515 for (y = y1a - 1; y <= y2a + 1; y++)
517 c_ptr = &cave[y][x1a - 1];
518 place_outer_grid(c_ptr);
519 c_ptr = &cave[y][x2a + 1];
520 place_outer_grid(c_ptr);
522 for (x = x1a - 1; x <= x2a + 1; x++)
524 c_ptr = &cave[y1a - 1][x];
525 place_outer_grid(c_ptr);
526 c_ptr = &cave[y2a + 1][x];
527 place_outer_grid(c_ptr);
530 /* Place the walls around room "b" */
531 for (y = y1b - 1; y <= y2b + 1; y++)
533 c_ptr = &cave[y][x1b - 1];
534 place_outer_grid(c_ptr);
535 c_ptr = &cave[y][x2b + 1];
536 place_outer_grid(c_ptr);
538 for (x = x1b - 1; x <= x2b + 1; x++)
540 c_ptr = &cave[y1b - 1][x];
541 place_outer_grid(c_ptr);
542 c_ptr = &cave[y2b + 1][x];
543 place_outer_grid(c_ptr);
548 /* Replace the floor for room "a" */
549 for (y = y1a; y <= y2a; y++)
551 for (x = x1a; x <= x2a; x++)
554 place_floor_grid(c_ptr);
558 /* Replace the floor for room "b" */
559 for (y = y1b; y <= y2b; y++)
561 for (x = x1b; x <= x2b; x++)
564 place_floor_grid(c_ptr);
572 * Type 3 -- Cross shaped rooms
574 * Builds a room at a row, column coordinate
576 * Room "a" runs north/south, and Room "b" runs east/east
577 * So the "central pillar" runs from x1a, y1b to x2a, y2b.
579 * Note that currently, the "center" is always 3x3, but I think that
580 * the code below will work (with "bounds checking") for 5x5, or even
581 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.
583 static void build_type3(int by0, int bx0)
585 int y, x, dy, dx, wy, wx;
586 int y1a, x1a, y2a, x2a;
587 int y1b, x1b, y2b, x2b;
593 /* Try to allocate space for room. */
594 if (!room_alloc(25, 11, FALSE, by0, bx0, &xval, &yval)) return;
596 /* Choose lite or dark */
597 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
599 /* For now, always 3x3 */
602 /* Pick max vertical size (at most 4) */
603 dy = rand_range(3, 4);
605 /* Pick max horizontal size (at most 15) */
606 dx = rand_range(3, 11);
609 /* Determine extents of the north/south room */
615 /* Determine extents of the east/west room */
622 /* Place a full floor for room "a" */
623 for (y = y1a - 1; y <= y2a + 1; y++)
625 for (x = x1a - 1; x <= x2a + 1; x++)
628 place_floor_grid(c_ptr);
629 c_ptr->info |= (CAVE_ROOM);
630 if (light) c_ptr->info |= (CAVE_GLOW);
634 /* Place a full floor for room "b" */
635 for (y = y1b - 1; y <= y2b + 1; y++)
637 for (x = x1b - 1; x <= x2b + 1; x++)
640 place_floor_grid(c_ptr);
641 c_ptr->info |= (CAVE_ROOM);
642 if (light) c_ptr->info |= (CAVE_GLOW);
647 /* Place the walls around room "a" */
648 for (y = y1a - 1; y <= y2a + 1; y++)
650 c_ptr = &cave[y][x1a - 1];
651 place_outer_grid(c_ptr);
652 c_ptr = &cave[y][x2a + 1];
653 place_outer_grid(c_ptr);
655 for (x = x1a - 1; x <= x2a + 1; x++)
657 c_ptr = &cave[y1a - 1][x];
658 place_outer_grid(c_ptr);
659 c_ptr = &cave[y2a + 1][x];
660 place_outer_grid(c_ptr);
663 /* Place the walls around room "b" */
664 for (y = y1b - 1; y <= y2b + 1; y++)
666 c_ptr = &cave[y][x1b - 1];
667 place_outer_grid(c_ptr);
668 c_ptr = &cave[y][x2b + 1];
669 place_outer_grid(c_ptr);
671 for (x = x1b - 1; x <= x2b + 1; x++)
673 c_ptr = &cave[y1b - 1][x];
674 place_outer_grid(c_ptr);
675 c_ptr = &cave[y2b + 1][x];
676 place_outer_grid(c_ptr);
680 /* Replace the floor for room "a" */
681 for (y = y1a; y <= y2a; y++)
683 for (x = x1a; x <= x2a; x++)
686 place_floor_grid(c_ptr);
690 /* Replace the floor for room "b" */
691 for (y = y1b; y <= y2b; y++)
693 for (x = x1b; x <= x2b; x++)
696 place_floor_grid(c_ptr);
702 /* Special features (3/4) */
705 /* Large solid middle pillar */
708 for (y = y1b; y <= y2b; y++)
710 for (x = x1a; x <= x2a; x++)
713 place_inner_grid(c_ptr);
719 /* Inner treasure vault */
722 /* Build the vault */
723 for (y = y1b; y <= y2b; y++)
725 c_ptr = &cave[y][x1a];
726 place_inner_grid(c_ptr);
727 c_ptr = &cave[y][x2a];
728 place_inner_grid(c_ptr);
730 for (x = x1a; x <= x2a; x++)
732 c_ptr = &cave[y1b][x];
733 place_inner_grid(c_ptr);
734 c_ptr = &cave[y2b][x];
735 place_inner_grid(c_ptr);
738 /* Place a secret door on the inner room */
741 case 0: place_secret_door(y1b, xval); break;
742 case 1: place_secret_door(y2b, xval); break;
743 case 2: place_secret_door(yval, x1a); break;
744 case 3: place_secret_door(yval, x2a); break;
747 /* Place a treasure in the vault */
748 place_object(yval, xval, FALSE, FALSE);
750 /* Let's guard the treasure well */
751 vault_monsters(yval, xval, randint0(2) + 3);
753 /* Traps naturally */
754 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
762 /* Occasionally pinch the center shut */
765 /* Pinch the east/west sides */
766 for (y = y1b; y <= y2b; y++)
768 if (y == yval) continue;
769 c_ptr = &cave[y][x1a - 1];
770 place_inner_grid(c_ptr);
771 c_ptr = &cave[y][x2a + 1];
772 place_inner_grid(c_ptr);
775 /* Pinch the north/south sides */
776 for (x = x1a; x <= x2a; x++)
778 if (x == xval) continue;
779 c_ptr = &cave[y1b - 1][x];
780 place_inner_grid(c_ptr);
781 c_ptr = &cave[y2b + 1][x];
782 place_inner_grid(c_ptr);
785 /* Sometimes shut using secret doors */
788 place_secret_door(yval, x1a - 1);
789 place_secret_door(yval, x2a + 1);
790 place_secret_door(y1b - 1, xval);
791 place_secret_door(y2b + 1, xval);
795 /* Occasionally put a "plus" in the center */
798 c_ptr = &cave[yval][xval];
799 place_inner_grid(c_ptr);
800 c_ptr = &cave[y1b][xval];
801 place_inner_grid(c_ptr);
802 c_ptr = &cave[y2b][xval];
803 place_inner_grid(c_ptr);
804 c_ptr = &cave[yval][x1a];
805 place_inner_grid(c_ptr);
806 c_ptr = &cave[yval][x2a];
807 place_inner_grid(c_ptr);
810 /* Occasionally put a pillar in the center */
813 c_ptr = &cave[yval][xval];
814 place_inner_grid(c_ptr);
824 * Type 4 -- Large room with inner features
826 * Possible sub-types:
827 * 1 - Just an inner room with one door
828 * 2 - An inner room within an inner room
829 * 3 - An inner room with pillar(s)
830 * 4 - Inner room has a maze
831 * 5 - A set of four inner rooms
833 static void build_type4(int by0, int bx0)
836 int y2, x2, tmp, yval, xval;
841 /* Try to allocate space for room. */
842 if (!room_alloc(25, 11, FALSE, by0, bx0, &xval, &yval)) return;
844 /* Choose lite or dark */
845 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
853 /* Place a full floor under the room */
854 for (y = y1 - 1; y <= y2 + 1; y++)
856 for (x = x1 - 1; x <= x2 + 1; x++)
859 place_floor_grid(c_ptr);
860 c_ptr->info |= (CAVE_ROOM);
861 if (light) c_ptr->info |= (CAVE_GLOW);
866 for (y = y1 - 1; y <= y2 + 1; y++)
868 c_ptr = &cave[y][x1 - 1];
869 place_outer_grid(c_ptr);
870 c_ptr = &cave[y][x2 + 1];
871 place_outer_grid(c_ptr);
873 for (x = x1 - 1; x <= x2 + 1; x++)
875 c_ptr = &cave[y1 - 1][x];
876 place_outer_grid(c_ptr);
877 c_ptr = &cave[y2 + 1][x];
878 place_outer_grid(c_ptr);
888 /* The inner walls */
889 for (y = y1 - 1; y <= y2 + 1; y++)
891 c_ptr = &cave[y][x1 - 1];
892 place_inner_grid(c_ptr);
893 c_ptr = &cave[y][x2 + 1];
894 place_inner_grid(c_ptr);
896 for (x = x1 - 1; x <= x2 + 1; x++)
898 c_ptr = &cave[y1 - 1][x];
899 place_inner_grid(c_ptr);
900 c_ptr = &cave[y2 + 1][x];
901 place_inner_grid(c_ptr);
905 /* Inner room variations */
908 /* Just an inner room with a monster */
911 /* Place a secret door */
914 case 1: place_secret_door(y1 - 1, xval); break;
915 case 2: place_secret_door(y2 + 1, xval); break;
916 case 3: place_secret_door(yval, x1 - 1); break;
917 case 4: place_secret_door(yval, x2 + 1); break;
920 /* Place a monster in the room */
921 vault_monsters(yval, xval, 1);
926 /* Treasure Vault (with a door) */
929 /* Place a secret door */
932 case 1: place_secret_door(y1 - 1, xval); break;
933 case 2: place_secret_door(y2 + 1, xval); break;
934 case 3: place_secret_door(yval, x1 - 1); break;
935 case 4: place_secret_door(yval, x2 + 1); break;
938 /* Place another inner room */
939 for (y = yval - 1; y <= yval + 1; y++)
941 for (x = xval - 1; x <= xval + 1; x++)
943 if ((x == xval) && (y == yval)) continue;
945 place_inner_grid(c_ptr);
949 /* Place a locked door on the inner room */
952 case 1: place_locked_door(yval - 1, xval); break;
953 case 2: place_locked_door(yval + 1, xval); break;
954 case 3: place_locked_door(yval, xval - 1); break;
955 case 4: place_locked_door(yval, xval + 1); break;
958 /* Monsters to guard the "treasure" */
959 vault_monsters(yval, xval, randint1(3) + 2);
962 if (randint0(100) < 80)
964 place_object(yval, xval, FALSE, FALSE);
970 place_random_stairs(yval, xval);
973 /* Traps to protect the treasure */
974 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
979 /* Inner pillar(s). */
982 /* Place a secret door */
985 case 1: place_secret_door(y1 - 1, xval); break;
986 case 2: place_secret_door(y2 + 1, xval); break;
987 case 3: place_secret_door(yval, x1 - 1); break;
988 case 4: place_secret_door(yval, x2 + 1); break;
991 /* Large Inner Pillar */
992 for (y = yval - 1; y <= yval + 1; y++)
994 for (x = xval - 1; x <= xval + 1; x++)
997 place_inner_grid(c_ptr);
1001 /* Occasionally, two more Large Inner Pillars */
1005 for (y = yval - 1; y <= yval + 1; y++)
1007 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1009 c_ptr = &cave[y][x];
1010 place_inner_grid(c_ptr);
1012 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1014 c_ptr = &cave[y][x];
1015 place_inner_grid(c_ptr);
1020 /* Occasionally, some Inner rooms */
1023 /* Long horizontal walls */
1024 for (x = xval - 5; x <= xval + 5; x++)
1026 c_ptr = &cave[yval - 1][x];
1027 place_inner_grid(c_ptr);
1028 c_ptr = &cave[yval + 1][x];
1029 place_inner_grid(c_ptr);
1032 /* Close off the left/right edges */
1033 c_ptr = &cave[yval][xval - 5];
1034 place_inner_grid(c_ptr);
1035 c_ptr = &cave[yval][xval + 5];
1036 place_inner_grid(c_ptr);
1038 /* Secret doors (random top/bottom) */
1039 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3);
1040 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3);
1043 vault_monsters(yval, xval - 2, randint1(2));
1044 vault_monsters(yval, xval + 2, randint1(2));
1047 if (one_in_(3)) place_object(yval, xval - 2, FALSE, FALSE);
1048 if (one_in_(3)) place_object(yval, xval + 2, FALSE, FALSE);
1057 /* Place a secret door */
1058 switch (randint1(4))
1060 case 1: place_secret_door(y1 - 1, xval); break;
1061 case 2: place_secret_door(y2 + 1, xval); break;
1062 case 3: place_secret_door(yval, x1 - 1); break;
1063 case 4: place_secret_door(yval, x2 + 1); break;
1066 /* Maze (really a checkerboard) */
1067 for (y = y1; y <= y2; y++)
1069 for (x = x1; x <= x2; x++)
1073 c_ptr = &cave[y][x];
1074 place_inner_grid(c_ptr);
1079 /* Monsters just love mazes. */
1080 vault_monsters(yval, xval - 5, randint1(3));
1081 vault_monsters(yval, xval + 5, randint1(3));
1083 /* Traps make them entertaining. */
1084 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1085 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1087 /* Mazes should have some treasure too. */
1088 vault_objects(yval, xval, 3);
1093 /* Four small rooms. */
1097 for (y = y1; y <= y2; y++)
1099 c_ptr = &cave[y][xval];
1100 place_inner_grid(c_ptr);
1102 for (x = x1; x <= x2; x++)
1104 c_ptr = &cave[yval][x];
1105 place_inner_grid(c_ptr);
1108 /* Doors into the rooms */
1109 if (randint0(100) < 50)
1111 int i = randint1(10);
1112 place_secret_door(y1 - 1, xval - i);
1113 place_secret_door(y1 - 1, xval + i);
1114 place_secret_door(y2 + 1, xval - i);
1115 place_secret_door(y2 + 1, xval + i);
1119 int i = randint1(3);
1120 place_secret_door(yval + i, x1 - 1);
1121 place_secret_door(yval - i, x1 - 1);
1122 place_secret_door(yval + i, x2 + 1);
1123 place_secret_door(yval - i, x2 + 1);
1126 /* Treasure, centered at the center of the cross */
1127 vault_objects(yval, xval, 2 + randint1(2));
1129 /* Gotta have some monsters. */
1130 vault_monsters(yval + 1, xval - 4, randint1(4));
1131 vault_monsters(yval + 1, xval + 4, randint1(4));
1132 vault_monsters(yval - 1, xval - 4, randint1(4));
1133 vault_monsters(yval - 1, xval + 4, randint1(4));
1142 * The following functions are used to determine if the given monster
1143 * is appropriate for inclusion in a monster nest or monster pit or
1146 * None of the pits/nests are allowed to include "unique" monsters.
1151 * Monster validation macro
1153 * Line 1 -- forbid town monsters
1154 * Line 2 -- forbid uniques
1155 * Line 3 -- forbid aquatic monsters
1157 #define vault_monster_okay(I) \
1158 (monster_dungeon(I) && \
1159 !(r_info[I].flags1 & RF1_UNIQUE) && \
1160 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1161 !(r_info[I].flags3 & RF3_RES_ALL) && \
1162 !(r_info[I].flags7 & RF7_AQUATIC))
1165 /* Race index for "monster pit (clone)" */
1166 static int vault_aux_race;
1168 /* Race index for "monster pit (symbol clone)" */
1169 static char vault_aux_char;
1171 /* Breath mask for "monster pit (dragon)" */
1172 static u32b vault_aux_dragon_mask4;
1176 * Helper monster selection function
1178 static bool vault_aux_simple(int r_idx)
1181 return (vault_monster_okay(r_idx));
1186 * Helper function for "monster nest (jelly)"
1188 static bool vault_aux_jelly(int r_idx)
1190 monster_race *r_ptr = &r_info[r_idx];
1192 /* Validate the monster */
1193 if (!vault_monster_okay(r_idx)) return (FALSE);
1195 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1197 /* Also decline evil jellies (like death molds and shoggoths) */
1198 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1200 /* Require icky thing, jelly, mold, or mushroom */
1201 if (!strchr("ijm,", r_ptr->d_char)) return (FALSE);
1209 * Helper function for "monster nest (animal)"
1211 static bool vault_aux_animal(int r_idx)
1213 monster_race *r_ptr = &r_info[r_idx];
1215 /* Validate the monster */
1216 if (!vault_monster_okay(r_idx)) return (FALSE);
1218 /* Require "animal" flag */
1219 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1227 * Helper function for "monster nest (undead)"
1229 static bool vault_aux_undead(int r_idx)
1231 monster_race *r_ptr = &r_info[r_idx];
1233 /* Validate the monster */
1234 if (!vault_monster_okay(r_idx)) return (FALSE);
1236 /* Require Undead */
1237 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1245 * Helper function for "monster nest (chapel)"
1247 static bool vault_aux_chapel_g(int r_idx)
1249 static int chapel_list[] = {
1250 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1251 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1252 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1257 monster_race *r_ptr = &r_info[r_idx];
1259 /* Validate the monster */
1260 if (!vault_monster_okay(r_idx)) return (FALSE);
1262 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1263 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1265 /* Require "priest" or Angel */
1267 if (r_ptr->d_char == 'A') return TRUE;
1269 for (i = 0; chapel_list[i]; i++)
1270 if (r_idx == chapel_list[i]) return TRUE;
1277 * Helper function for "monster nest (kennel)"
1279 static bool vault_aux_kennel(int r_idx)
1281 monster_race *r_ptr = &r_info[r_idx];
1283 /* Validate the monster */
1284 if (!vault_monster_okay(r_idx)) return (FALSE);
1286 /* Require a Zephyr Hound or a dog */
1287 if (!strchr("CZ", r_ptr->d_char)) return (FALSE);
1295 * Helper function for "monster nest (mimic)"
1297 static bool vault_aux_mimic(int r_idx)
1299 monster_race *r_ptr = &r_info[r_idx];
1301 /* Validate the monster */
1302 if (!vault_monster_okay(r_idx)) return (FALSE);
1305 if (!strchr("!|$?=", r_ptr->d_char)) return (FALSE);
1312 * Helper function for "monster nest (clone)"
1314 static bool vault_aux_clone(int r_idx)
1316 /* Validate the monster */
1317 if (!vault_monster_okay(r_idx)) return (FALSE);
1319 return (r_idx == vault_aux_race);
1324 * Helper function for "monster nest (symbol clone)"
1326 static bool vault_aux_symbol_e(int r_idx)
1328 monster_race *r_ptr = &r_info[r_idx];
1330 /* Validate the monster */
1331 if (!vault_monster_okay(r_idx)) return (FALSE);
1333 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1335 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1337 /* Decline incorrect symbol */
1338 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1346 * Helper function for "monster nest (symbol clone)"
1348 static bool vault_aux_symbol_g(int r_idx)
1350 monster_race *r_ptr = &r_info[r_idx];
1352 /* Validate the monster */
1353 if (!vault_monster_okay(r_idx)) return (FALSE);
1355 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1357 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1359 /* Decline incorrect symbol */
1360 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1368 * Helper function for "monster pit (orc)"
1370 static bool vault_aux_orc(int r_idx)
1372 monster_race *r_ptr = &r_info[r_idx];
1374 /* Validate the monster */
1375 if (!vault_monster_okay(r_idx)) return (FALSE);
1378 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1380 /* Decline undead */
1381 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1389 * Helper function for "monster pit (troll)"
1391 static bool vault_aux_troll(int r_idx)
1393 monster_race *r_ptr = &r_info[r_idx];
1395 /* Validate the monster */
1396 if (!vault_monster_okay(r_idx)) return (FALSE);
1399 if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1401 /* Decline undead */
1402 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1410 * Helper function for "monster pit (giant)"
1412 static bool vault_aux_giant(int r_idx)
1414 monster_race *r_ptr = &r_info[r_idx];
1416 /* Validate the monster */
1417 if (!vault_monster_okay(r_idx)) return (FALSE);
1420 if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1422 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1424 /* Decline undead */
1425 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1433 * Helper function for "monster pit (dragon)"
1435 static bool vault_aux_dragon(int r_idx)
1437 monster_race *r_ptr = &r_info[r_idx];
1439 /* Validate the monster */
1440 if (!vault_monster_okay(r_idx)) return (FALSE);
1442 /* Require dragon */
1443 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1445 /* Hack -- Require correct "breath attack" */
1446 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1448 /* Decline undead */
1449 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1457 * Helper function for "monster pit (demon)"
1459 static bool vault_aux_demon(int r_idx)
1461 monster_race *r_ptr = &r_info[r_idx];
1463 /* Validate the monster */
1464 if (!vault_monster_okay(r_idx)) return (FALSE);
1466 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1469 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1477 * Helper function for "monster pit (lovecraftian)"
1479 static bool vault_aux_cthulhu(int r_idx)
1481 monster_race *r_ptr = &r_info[r_idx];
1483 /* Validate the monster */
1484 if (!vault_monster_okay(r_idx)) return (FALSE);
1486 if (r_ptr->flags2 & (RF2_KILL_BODY)) return (FALSE);
1488 /* Require eldritch horror */
1489 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1497 * Helper function for "monster pit (clone)"
1499 static void vault_prep_clone(void)
1501 /* Apply the monster restriction */
1502 get_mon_num_prep(vault_aux_simple, NULL);
1504 /* Pick a race to clone */
1505 vault_aux_race = get_mon_num(dun_level + 10);
1507 /* Remove the monster restriction */
1508 get_mon_num_prep(NULL, NULL);
1513 * Helper function for "monster pit (symbol clone)"
1515 static void vault_prep_symbol(void)
1519 /* Apply the monster restriction */
1520 get_mon_num_prep(vault_aux_simple, NULL);
1522 /* Pick a race to clone */
1523 r_idx = get_mon_num(dun_level + 10);
1525 /* Remove the monster restriction */
1526 get_mon_num_prep(NULL, NULL);
1528 /* Extract the symbol */
1529 vault_aux_char = r_info[r_idx].d_char;
1534 * Helper function for "monster pit (dragon)"
1536 static void vault_prep_dragon(void)
1538 /* Pick dragon type */
1539 switch (randint0(6))
1544 /* Restrict dragon breath type */
1545 vault_aux_dragon_mask4 = RF4_BR_ACID;
1554 /* Restrict dragon breath type */
1555 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1564 /* Restrict dragon breath type */
1565 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1574 /* Restrict dragon breath type */
1575 vault_aux_dragon_mask4 = RF4_BR_COLD;
1584 /* Restrict dragon breath type */
1585 vault_aux_dragon_mask4 = RF4_BR_POIS;
1594 /* Restrict dragon breath type */
1595 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1596 RF4_BR_FIRE | RF4_BR_COLD |
1609 typedef struct vault_aux_type vault_aux_type;
1612 struct vault_aux_type
1615 bool (*hook_func)(int r_idx);
1616 void (*prep_func)(void);
1622 static vault_aux_type *pick_vault_type(vault_aux_type *l_ptr, int room)
1624 int tmp, total, count;
1626 vault_aux_type *n_ptr;
1628 /* Calculate the total possibilities */
1629 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1632 if (!n_ptr->name) break;
1634 /* Ignore excessive depth */
1635 if (n_ptr->level > dun_level) continue;
1637 if (room == ROOM_PIT)
1639 if (!(d_info[dungeon_type].pit & (1L << count))) continue;
1641 else if (room == ROOM_NEST)
1643 if(!(d_info[dungeon_type].nest & (1L << count))) continue;
1646 /* Count this possibility */
1647 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1650 /* Pick a random type */
1651 tmp = randint0(total);
1653 /* Find this type */
1654 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1657 if (!n_ptr->name) break;
1659 /* Ignore excessive depth */
1660 if (n_ptr->level > dun_level) continue;
1662 if (room == ROOM_PIT)
1664 if (!(d_info[dungeon_type].pit & (1L << count))) continue;
1666 else if (room == ROOM_NEST)
1668 if(!(d_info[dungeon_type].nest & (1L << count))) continue;
1671 /* Count this possibility */
1672 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1674 /* Found the type */
1675 if (tmp < total) break;
1678 return (n_ptr->name ? n_ptr : NULL);
1681 static void build_type6(int by0, int bx0, bool nest);
1682 static void build_type5(int by0, int bx0, bool nest);
1684 static vault_aux_type nest_types[] =
1687 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1688 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1689 {"¥·¥ó¥Ü¥ë(Á±)",vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1690 {"¥·¥ó¥Ü¥ë(°)",vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1691 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1692 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1693 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1694 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1695 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1696 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1697 {NULL, NULL, NULL, 0, 0},
1699 {"clone", vault_aux_clone, vault_prep_clone, 5, 3},
1700 {"jelly", vault_aux_jelly, NULL, 5, 6},
1701 {"symbol good",vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1702 {"symbol evil",vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1703 {"mimic", vault_aux_mimic, NULL, 30, 4},
1704 {"lovecraftian",vault_aux_cthulhu, NULL, 70, 2},
1705 {"kennel", vault_aux_kennel, NULL, 45, 4},
1706 {"animal", vault_aux_animal, NULL, 35, 5},
1707 {"chapel", vault_aux_chapel_g, NULL, 75, 4},
1708 {"undead", vault_aux_undead, NULL, 75, 5},
1709 {NULL, NULL, NULL, 0, 0},
1715 * Type 5 -- Monster nests
1717 * A monster nest is a "big" room, with an "inner" room, containing
1718 * a "collection" of monsters of a given type strewn about the room.
1720 * The monsters are chosen from a set of 64 randomly selected monster
1721 * races, to allow the nest creation to fail instead of having "holes".
1723 * Note the use of the "get_mon_num_prep()" function, and the special
1724 * "get_mon_num_hook()" restriction function, to prepare the "monster
1725 * allocation table" in such a way as to optimize the selection of
1726 * "appropriate" non-unique monsters for the nest.
1728 * Note that the "get_mon_num()" function may (rarely) fail, in which
1729 * case the nest will be empty, and will not affect the level rating.
1731 * Note that "monster nests" will never contain "unique" monsters.
1733 static void build_type5(int by0, int bx0, bool pit)
1735 int y, x, y1, x1, y2, x2, xval, yval;
1743 vault_aux_type *n_ptr = pick_vault_type(nest_types, ROOM_NEST);
1745 /* Try to allocate space for room. */
1746 if (!room_alloc(25, 11, TRUE, by0, bx0, &xval, &yval)) return;
1748 /* No type available */
1752 else {build_type6(by0, bx0, TRUE);return;}
1755 /* Process a preparation function if necessary */
1756 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
1764 /* Place the floor area */
1765 for (y = y1 - 1; y <= y2 + 1; y++)
1767 for (x = x1 - 1; x <= x2 + 1; x++)
1769 c_ptr = &cave[y][x];
1770 place_floor_grid(c_ptr);
1771 c_ptr->info |= (CAVE_ROOM);
1775 /* Place the outer walls */
1776 for (y = y1 - 1; y <= y2 + 1; y++)
1778 c_ptr = &cave[y][x1 - 1];
1779 place_outer_grid(c_ptr);
1780 c_ptr = &cave[y][x2 + 1];
1781 place_outer_grid(c_ptr);
1783 for (x = x1 - 1; x <= x2 + 1; x++)
1785 c_ptr = &cave[y1 - 1][x];
1786 place_outer_grid(c_ptr);
1787 c_ptr = &cave[y2 + 1][x];
1788 place_outer_grid(c_ptr);
1792 /* Advance to the center room */
1798 /* The inner walls */
1799 for (y = y1 - 1; y <= y2 + 1; y++)
1801 c_ptr = &cave[y][x1 - 1];
1802 place_inner_grid(c_ptr);
1803 c_ptr = &cave[y][x2 + 1];
1804 place_inner_grid(c_ptr);
1807 for (x = x1 - 1; x <= x2 + 1; x++)
1809 c_ptr = &cave[y1 - 1][x];
1810 place_inner_grid(c_ptr);
1811 c_ptr = &cave[y2 + 1][x];
1812 place_inner_grid(c_ptr);
1814 for (y = y1; y <= y2; y++)
1816 for (x = x1; x <= x2; x++)
1818 add_cave_info(y, x, CAVE_ICKY);
1823 /* Place a secret door */
1824 switch (randint1(4))
1826 case 1: place_secret_door(y1 - 1, xval); break;
1827 case 2: place_secret_door(y2 + 1, xval); break;
1828 case 3: place_secret_door(yval, x1 - 1); break;
1829 case 4: place_secret_door(yval, x2 + 1); break;
1833 /* Prepare allocation table */
1834 get_mon_num_prep(n_ptr->hook_func, NULL);
1836 /* Pick some monster types */
1837 for (i = 0; i < 64; i++)
1839 int r_idx = 0, attempts = 100;
1843 /* Get a (hard) monster type */
1844 r_idx = get_mon_num(dun_level + 10);
1846 /* Decline incorrect alignment */
1847 if (((align < 0) && (r_info[r_idx].flags3 & RF3_GOOD)) ||
1848 ((align > 0) && (r_info[r_idx].flags3 & RF3_EVIL)))
1853 /* Accept this monster */
1857 /* Notice failure */
1858 if (!r_idx || !attempts) return;
1860 /* Note the alignment */
1861 if (r_info[r_idx].flags3 & RF3_GOOD) align++;
1862 else if (r_info[r_idx].flags3 & RF3_EVIL) align--;
1872 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(%s)", n_ptr->name);
1874 msg_format("Monster nest (%s)", n_ptr->name);
1880 /* Increase the level rating */
1883 /* (Sometimes) Cause a "special feeling" (for "Monster Nests") */
1884 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
1886 good_item_flag = TRUE;
1889 /* Place some monsters */
1890 for (y = yval - 2; y <= yval + 2; y++)
1892 for (x = xval - 9; x <= xval + 9; x++)
1894 int r_idx = what[randint0(64)];
1896 /* Place that "random" monster (no groups) */
1897 (void)place_monster_aux(0, y, x, r_idx, 0L);
1903 static vault_aux_type pit_types[] =
1906 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1907 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1908 {"¥¸¥ã¥¤¥¢¥ó¥È",vault_aux_giant, NULL, 50, 6},
1909 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1910 {"¥·¥ó¥Ü¥ë(Á±)",vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1911 {"¥·¥ó¥Ü¥ë(°)",vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1912 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
1913 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
1914 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
1915 {NULL, NULL, NULL, 0, 0},
1917 {"orc", vault_aux_orc, NULL, 5, 6},
1918 {"troll", vault_aux_troll, NULL, 20, 6},
1919 {"giant", vault_aux_giant, NULL, 50, 6},
1920 {"lovecraftian",vault_aux_cthulhu, NULL, 80, 2},
1921 {"symbol good",vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1922 {"symbol evil",vault_aux_symbol_e, vault_prep_symbol, 70, 1},
1923 {"chapel", vault_aux_chapel_g, NULL, 65, 2},
1924 {"dragon", vault_aux_dragon, vault_prep_dragon, 70, 6},
1925 {"demon", vault_aux_demon, NULL, 80, 6},
1926 {NULL, NULL, NULL, 0, 0},
1932 * Type 6 -- Monster pits
1934 * A monster pit is a "big" room, with an "inner" room, containing
1935 * a "collection" of monsters of a given type organized in the room.
1937 * The inside room in a monster pit appears as shown below, where the
1938 * actual monsters in each location depend on the type of the pit
1940 * #####################
1941 * #0000000000000000000#
1942 * #0112233455543322110#
1943 * #0112233467643322110#
1944 * #0112233455543322110#
1945 * #0000000000000000000#
1946 * #####################
1948 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
1949 * to request 16 "appropriate" monsters, sorting them by level, and using
1950 * the "even" entries in this sorted list for the contents of the pit.
1952 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
1953 * which is handled by requiring a specific "breath" attack for all of the
1954 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
1955 * be present in many of the dragon pits, if they have the proper breath.
1957 * Note the use of the "get_mon_num_prep()" function, and the special
1958 * "get_mon_num_hook()" restriction function, to prepare the "monster
1959 * allocation table" in such a way as to optimize the selection of
1960 * "appropriate" non-unique monsters for the pit.
1962 * Note that the "get_mon_num()" function may (rarely) fail, in which case
1963 * the pit will be empty, and will not effect the level rating.
1965 * Note that "monster pits" will never contain "unique" monsters.
1967 static void build_type6(int by0, int bx0, bool nest)
1969 int y, x, y1, x1, y2, x2, xval, yval;
1978 vault_aux_type *n_ptr = pick_vault_type(pit_types, ROOM_PIT);
1980 /* Try to allocate space for room. */
1981 if (!room_alloc(25, 11, TRUE, by0, bx0, &xval, &yval)) return;
1983 /* No type available */
1987 else {build_type5(by0, bx0, TRUE);return;}
1990 /* Process a preparation function if necessary */
1991 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
1999 /* Place the floor area */
2000 for (y = y1 - 1; y <= y2 + 1; y++)
2002 for (x = x1 - 1; x <= x2 + 1; x++)
2004 c_ptr = &cave[y][x];
2005 place_floor_grid(c_ptr);
2006 c_ptr->info |= (CAVE_ROOM);
2010 /* Place the outer walls */
2011 for (y = y1 - 1; y <= y2 + 1; y++)
2013 c_ptr = &cave[y][x1 - 1];
2014 place_outer_grid(c_ptr);
2015 c_ptr = &cave[y][x2 + 1];
2016 place_outer_grid(c_ptr);
2018 for (x = x1 - 1; x <= x2 + 1; x++)
2020 c_ptr = &cave[y1 - 1][x];
2021 place_outer_grid(c_ptr);
2022 c_ptr = &cave[y2 + 1][x];
2023 place_outer_grid(c_ptr);
2026 /* Advance to the center room */
2032 /* The inner walls */
2033 for (y = y1 - 1; y <= y2 + 1; y++)
2035 c_ptr = &cave[y][x1 - 1];
2036 place_inner_grid(c_ptr);
2037 c_ptr = &cave[y][x2 + 1];
2038 place_inner_grid(c_ptr);
2040 for (x = x1 - 1; x <= x2 + 1; x++)
2042 c_ptr = &cave[y1 - 1][x];
2043 place_inner_grid(c_ptr);
2044 c_ptr = &cave[y2 + 1][x];
2045 place_inner_grid(c_ptr);
2047 for (y = y1; y <= y2; y++)
2049 for (x = x1; x <= x2; x++)
2051 add_cave_info(y, x, CAVE_ICKY);
2055 /* Place a secret door */
2056 switch (randint1(4))
2058 case 1: place_secret_door(y1 - 1, xval); break;
2059 case 2: place_secret_door(y2 + 1, xval); break;
2060 case 3: place_secret_door(yval, x1 - 1); break;
2061 case 4: place_secret_door(yval, x2 + 1); break;
2065 /* Prepare allocation table */
2066 get_mon_num_prep(n_ptr->hook_func, NULL);
2068 /* Pick some monster types */
2069 for (i = 0; i < 16; i++)
2071 int r_idx = 0, attempts = 100;
2075 /* Get a (hard) monster type */
2076 r_idx = get_mon_num(dun_level + 10);
2078 /* Decline incorrect alignment */
2079 if (((align < 0) && (r_info[r_idx].flags3 & RF3_GOOD)) ||
2080 ((align > 0) && (r_info[r_idx].flags3 & RF3_EVIL)))
2085 /* Accept this monster */
2089 /* Notice failure */
2090 if (!r_idx || !attempts) return;
2092 /* Note the alignment */
2093 if (r_info[r_idx].flags3 & RF3_GOOD) align++;
2094 else if (r_info[r_idx].flags3 & RF3_EVIL) align--;
2099 /* Sort the entries */
2100 for (i = 0; i < 16 - 1; i++)
2102 /* Sort the entries */
2103 for (j = 0; j < 16 - 1; j++)
2108 int p1 = r_info[what[i1]].level;
2109 int p2 = r_info[what[i2]].level;
2115 what[i1] = what[i2];
2125 msg_format("%s¤ÎÁã", n_ptr->name);
2128 msg_format("Monster pit (%s)", n_ptr->name);
2132 /* Select the entries */
2133 for (i = 0; i < 8; i++)
2135 /* Every other entry */
2136 what[i] = what[i * 2];
2141 msg_print(r_name + r_info[what[i]].name);
2145 /* Increase the level rating */
2148 /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
2149 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
2151 good_item_flag = TRUE;
2154 /* Top and bottom rows */
2155 for (x = xval - 9; x <= xval + 9; x++)
2157 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2158 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2161 /* Middle columns */
2162 for (y = yval - 1; y <= yval + 1; y++)
2164 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2165 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2167 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2168 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2170 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2171 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2173 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2174 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2176 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2177 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2179 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2180 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2182 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2183 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2185 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2186 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2189 /* Above/Below the center monster */
2190 for (x = xval - 1; x <= xval + 1; x++)
2192 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2193 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2196 /* Next to the center monster */
2197 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2198 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2200 /* Center monster */
2201 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2205 /* coordinate translation code */
2206 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2212 * transno specifies what transformation is required. (0-7)
2213 * The lower two bits indicate by how much the vault is rotated,
2214 * and the upper bit indicates a reflection.
2215 * This is done by using rotation matrices... however since
2216 * these are mostly zeros for rotations by 90 degrees this can
2217 * be expressed simply in terms of swapping and inverting the
2218 * x and y coordinates.
2220 for (i = 0; i <= transno % 4; i++)
2222 /* rotate by 90 degrees */
2230 /* Reflect depending on status of 3rd bit. */
2234 /* Add offsets so vault stays in the first quadrant */
2241 * Hack -- fill in "vault" rooms
2243 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2244 int xoffset, int yoffset, int transno)
2246 int dx, dy, x, y, i, j;
2253 /* Place dungeon features and objects */
2254 for (t = data, dy = 0; dy < ymax; dy++)
2256 for (dx = 0; dx < xmax; dx++, t++)
2258 /* prevent loop counter from being overwritten */
2263 coord_trans(&i, &j, xoffset, yoffset, transno);
2265 /* Extract the location */
2268 /* no swap of x/y */
2269 x = xval - (xmax / 2) + i;
2270 y = yval - (ymax / 2) + j;
2275 x = xval - (ymax / 2) + i;
2276 y = yval - (xmax / 2) + j;
2279 /* Hack -- skip "non-grids" */
2280 if (*t == ' ') continue;
2282 /* Access the grid */
2283 c_ptr = &cave[y][x];
2285 /* Lay down a floor */
2286 place_floor_grid(c_ptr);
2288 /* Remove any mimic */
2291 /* Part of a vault */
2292 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2294 /* Analyze the grid */
2297 /* Granite wall (outer) */
2299 place_outer_noperm_grid(c_ptr);
2302 /* Granite wall (inner) */
2304 place_inner_grid(c_ptr);
2307 /* Permanent wall (inner) */
2309 c_ptr->feat = FEAT_PERM_INNER;
2310 c_ptr->info &= ~(CAVE_MASK);
2311 c_ptr->info |= CAVE_INNER;
2316 if (randint0(100) < 75)
2318 place_object(y, x, FALSE, FALSE);
2328 place_secret_door(y, x);
2336 /* Black market in a dungeon */
2338 set_cave_feat(y, x, FEAT_SHOP_HEAD + STORE_BLACK);
2339 store_init(NO_TOWN, STORE_BLACK);
2344 set_cave_feat(y, x, FEAT_PATTERN_START);
2348 set_cave_feat(y, x, FEAT_PATTERN_1);
2352 set_cave_feat(y, x, FEAT_PATTERN_2);
2356 set_cave_feat(y, x, FEAT_PATTERN_3);
2360 set_cave_feat(y, x, FEAT_PATTERN_4);
2364 set_cave_feat(y, x, FEAT_PATTERN_END);
2368 set_cave_feat(y, x, FEAT_PATTERN_XTRA1);
2372 /* Reward for Pattern walk */
2373 object_level = base_level + 12;
2374 place_object(y, x, TRUE, FALSE);
2375 object_level = base_level;
2382 /* Place dungeon monsters and objects */
2383 for (t = data, dy = 0; dy < ymax; dy++)
2385 for (dx = 0; dx < xmax; dx++, t++)
2387 /* prevent loop counter from being overwritten */
2392 coord_trans(&i, &j, xoffset, yoffset, transno);
2394 /* Extract the location */
2397 /* no swap of x/y */
2398 x = xval - (xmax / 2) + i;
2399 y = yval - (ymax / 2) + j;
2404 x = xval - (ymax / 2) + i;
2405 y = yval - (xmax / 2) + j;
2408 /* Hack -- skip "non-grids" */
2409 if (*t == ' ') continue;
2411 /* Analyze the symbol */
2417 monster_level = base_level + 5;
2418 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2419 monster_level = base_level;
2423 /* Meaner monster */
2426 monster_level = base_level + 11;
2427 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2428 monster_level = base_level;
2432 /* Meaner monster, plus treasure */
2435 monster_level = base_level + 9;
2436 place_monster(y, x, PM_ALLOW_SLEEP);
2437 monster_level = base_level;
2438 object_level = base_level + 7;
2439 place_object(y, x, TRUE, FALSE);
2440 object_level = base_level;
2444 /* Nasty monster and treasure */
2447 monster_level = base_level + 40;
2448 place_monster(y, x, PM_ALLOW_SLEEP);
2449 monster_level = base_level;
2450 object_level = base_level + 20;
2451 place_object(y, x, TRUE, TRUE);
2452 object_level = base_level;
2456 /* Monster and/or object */
2459 if (randint0(100) < 50)
2461 monster_level = base_level + 3;
2462 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2463 monster_level = base_level;
2465 if (randint0(100) < 50)
2467 object_level = base_level + 7;
2468 place_object(y, x, FALSE, FALSE);
2469 object_level = base_level;
2481 * Type 7 -- simple vaults (see "v_info.txt")
2483 static void build_type7(int by0, int bx0)
2485 vault_type *v_ptr = NULL;
2489 int xoffset, yoffset;
2492 /* Pick a lesser vault */
2493 while (dummy < SAFE_MAX_ATTEMPTS)
2497 /* Access a random vault record */
2498 v_ptr = &v_info[randint0(max_v_idx)];
2500 /* Accept the first lesser vault */
2501 if (v_ptr->typ == 7) break;
2504 /* No lesser vault found */
2507 /* pick type of transformation (0-7) */
2508 transno = randint0(8);
2510 /* calculate offsets */
2514 coord_trans(&x, &y, 0, 0, transno);
2534 /* Try to allocate space for room. */
2535 if (!room_alloc(abs(x), abs(y), FALSE, by0, bx0, &xval, &yval)) return;
2537 if (dummy >= SAFE_MAX_ATTEMPTS)
2542 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2544 msg_print("Warning! Could not place lesser vault!");
2557 if (cheat_room) msg_format("%s", v_name + v_ptr->name);
2559 /* Boost the rating */
2560 rating += v_ptr->rat;
2562 /* (Sometimes) Cause a special feeling */
2563 if ((dun_level <= 50) ||
2564 (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
2566 good_item_flag = TRUE;
2569 /* Hack -- Build the vault */
2570 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2571 v_text + v_ptr->text, xoffset, yoffset, transno);
2576 * Type 8 -- greater vaults (see "v_info.txt")
2578 static void build_type8(int by0, int bx0)
2580 vault_type *v_ptr = NULL;
2585 int xoffset, yoffset;
2587 /* Pick a greater vault */
2588 while (dummy < SAFE_MAX_ATTEMPTS)
2592 /* Access a random vault record */
2593 v_ptr = &v_info[randint0(max_v_idx)];
2595 /* Accept the first greater vault */
2596 if (v_ptr->typ == 8) break;
2599 /* No greater vault found */
2602 /* pick type of transformation (0-7) */
2603 transno = randint0(8);
2605 /* calculate offsets */
2609 coord_trans(&x, &y, 0, 0, transno);
2629 /* Try to allocate space for room. If fails, exit */
2630 if (!room_alloc(abs(x), abs(y), FALSE, by0, bx0, &xval, &yval)) return;
2632 if (dummy >= SAFE_MAX_ATTEMPTS)
2637 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2639 msg_print("Warning! Could not place greater vault!");
2648 v_ptr = &v_info[76 + randint1(3)];
2652 if (cheat_room) msg_format("%s", v_name + v_ptr->name);
2654 /* Boost the rating */
2655 rating += v_ptr->rat;
2657 /* (Sometimes) Cause a special feeling */
2658 if ((dun_level <= 50) ||
2659 (randint1((dun_level - 40) * (dun_level - 40) + 50) < 400))
2661 good_item_flag = TRUE;
2664 /* Hack -- Build the vault */
2665 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
2666 v_text + v_ptr->text, xoffset, yoffset, transno);
2670 * Structure to hold all "fill" data
2673 typedef struct fill_data_type fill_data_type;
2675 struct fill_data_type
2688 /* features to fill with */
2697 /* number of filled squares */
2701 static fill_data_type fill_data;
2704 /* Store routine for the fractal cave generator */
2705 /* this routine probably should be an inline function or a macro. */
2706 static void store_height(int x, int y, int val)
2708 /* if on boundary set val > cutoff so walls are not as square */
2709 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
2710 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
2711 (val <= fill_data.c1)) val = fill_data.c1 + 1;
2713 /* store the value in height-map format */
2714 cave[y][x].feat = val;
2721 * Explanation of the plasma fractal algorithm:
2723 * A grid of points is created with the properties of a 'height-map'
2724 * This is done by making the corners of the grid have a random value.
2725 * The grid is then subdivided into one with twice the resolution.
2726 * The new points midway between two 'known' points can be calculated
2727 * by taking the average value of the 'known' ones and randomly adding
2728 * or subtracting an amount proportional to the distance between those
2729 * points. The final 'middle' points of the grid are then calculated
2730 * by averaging all four of the originally 'known' corner points. An
2731 * random amount is added or subtracted from this to get a value of the
2732 * height at that point. The scaling factor here is adjusted to the
2733 * slightly larger distance diagonally as compared to orthogonally.
2735 * This is then repeated recursively to fill an entire 'height-map'
2736 * A rectangular map is done the same way, except there are different
2737 * scaling factors along the x and y directions.
2739 * A hack to change the amount of correlation between points is done using
2740 * the grd variable. If the current step size is greater than grd then
2741 * the point will be random, otherwise it will be calculated by the
2742 * above algorithm. This makes a maximum distance at which two points on
2743 * the height map can affect each other.
2745 * How fractal caves are made:
2747 * When the map is complete, a cut-off value is used to create a cave.
2748 * Heights below this value are "floor", and heights above are "wall".
2749 * This also can be used to create lakes, by adding more height levels
2750 * representing shallow and deep water/ lava etc.
2752 * The grd variable affects the width of passages.
2753 * The roug variable affects the roughness of those passages
2755 * The tricky part is making sure the created cave is connected. This
2756 * is done by 'filling' from the inside and only keeping the 'filled'
2757 * floor. Walls bounding the 'filled' floor are also kept. Everything
2758 * else is converted to the normal granite FEAT_WALL_EXTRA.
2763 * Note that this uses the cave.feat array in a very hackish way
2764 * the values are first set to zero, and then each array location
2765 * is used as a "heightmap"
2766 * The heightmap then needs to be converted back into the "feat" format.
2768 * grd=level at which fractal turns on. smaller gives more mazelike caves
2769 * roug=roughness level. 16=normal. higher values make things more convoluted
2770 * small values are good for smooth walls.
2771 * size=length of the side of the square cave system.
2773 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
2775 int xhsize, yhsize, xsize, ysize, maxsize;
2778 * fixed point variables- these are stored as 256 x normal value
2779 * this gives 8 binary places of fractional part + 8 places of normal part
2782 u16b xstep, xhstep, ystep, yhstep;
2783 u16b xstep2, xhstep2, ystep2, yhstep2;
2784 u16b i, j, ii, jj, diagsize, xxsize, yysize;
2786 /* Cache for speed */
2787 u16b xm, xp, ym, yp;
2789 /* redefine size so can change the value if out of range */
2793 /* Paranoia about size of the system of caves */
2794 if (xsize > 254) xsize = 254;
2795 if (xsize < 4) xsize = 4;
2796 if (ysize > 254) ysize = 254;
2797 if (ysize < 4) ysize = 4;
2799 /* get offsets to middle of array */
2803 /* fix rounding problem */
2807 /* get limits of region */
2808 fill_data.xmin = x0 - xhsize;
2809 fill_data.ymin = y0 - yhsize;
2810 fill_data.xmax = x0 + xhsize;
2811 fill_data.ymax = y0 + yhsize;
2813 /* Store cutoff in global for quick access */
2814 fill_data.c1 = cutoff;
2817 * Scale factor for middle points:
2818 * About sqrt(2) * 256 - correct for a square lattice
2819 * approximately correct for everything else.
2823 /* maximum of xsize and ysize */
2824 maxsize = (xsize > ysize) ? xsize : ysize;
2826 /* Clear the section */
2827 for (i = 0; i <= xsize; i++)
2829 for (j = 0; j <= ysize; j++)
2831 /* 255 is a flag for "not done yet" */
2832 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = 255;
2833 /* Clear icky flag because may be redoing the cave */
2834 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
2838 /* Boundaries are walls */
2839 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
2840 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
2841 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
2842 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
2844 /* Set the middle square to be an open area. */
2845 cave[y0][x0].feat = 0;
2847 /* Initialize the step sizes */
2848 xstep = xhstep = xsize * 256;
2849 ystep = yhstep = ysize * 256;
2850 xxsize = xsize * 256;
2851 yysize = ysize * 256;
2854 * Fill in the rectangle with fractal height data -
2855 * like the 'plasma fractal' in fractint.
2857 while ((xhstep > 256) || (yhstep > 256))
2859 /* Halve the step sizes */
2865 /* cache well used values */
2866 xstep2 = xstep / 256;
2867 ystep2 = ystep / 256;
2869 xhstep2 = xhstep / 256;
2870 yhstep2 = yhstep / 256;
2872 /* middle top to bottom. */
2873 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
2875 for (j = 0; j <= yysize; j += ystep)
2877 /* cache often used values */
2878 ii = i / 256 + fill_data.xmin;
2879 jj = j / 256 + fill_data.ymin;
2882 if (cave[jj][ii].feat == 255)
2886 /* If greater than 'grid' level then is random */
2887 store_height(ii, jj, randint1(maxsize));
2891 /* Average of left and right points +random bit */
2892 store_height(ii, jj,
2893 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
2894 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
2895 + (randint1(xstep2) - xhstep2) * roug / 16);
2902 /* middle left to right. */
2903 for (j = yhstep; j <= yysize - yhstep; j += ystep)
2905 for (i = 0; i <= xxsize; i += xstep)
2907 /* cache often used values */
2908 ii = i / 256 + fill_data.xmin;
2909 jj = j / 256 + fill_data.ymin;
2912 if (cave[jj][ii].feat == 255)
2916 /* If greater than 'grid' level then is random */
2917 store_height(ii, jj, randint1(maxsize));
2921 /* Average of up and down points +random bit */
2922 store_height(ii, jj,
2923 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
2924 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
2925 + (randint1(ystep2) - yhstep2) * roug / 16);
2932 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
2934 for (j = yhstep; j <= yysize - yhstep; j += ystep)
2936 /* cache often used values */
2937 ii = i / 256 + fill_data.xmin;
2938 jj = j / 256 + fill_data.ymin;
2941 if (cave[jj][ii].feat == 255)
2945 /* If greater than 'grid' level then is random */
2946 store_height(ii, jj, randint1(maxsize));
2950 /* Cache reused values. */
2951 xm = fill_data.xmin + (i - xhstep) / 256;
2952 xp = fill_data.xmin + (i + xhstep) / 256;
2953 ym = fill_data.ymin + (j - yhstep) / 256;
2954 yp = fill_data.ymin + (j + yhstep) / 256;
2957 * Average over all four corners + scale by diagsize to
2958 * reduce the effect of the square grid on the shape of the fractal
2960 store_height(ii, jj,
2961 (cave[ym][xm].feat + cave[yp][xm].feat
2962 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
2963 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
2972 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)
2975 * function used to convert from height-map back to the
2976 * normal angband cave format
2978 if (cave[y][x].info & CAVE_ICKY)
2985 /* Show that have looked at this square */
2986 cave[y][x].info|= (CAVE_ICKY);
2988 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
2989 if (cave[y][x].feat <= c1)
2991 /* 25% of the time use the other tile : it looks better this way */
2992 if (randint1(100) < 75)
2994 cave[y][x].feat = feat1;
2995 cave[y][x].info &= ~(CAVE_MASK);
2996 cave[y][x].info |= info1;
3001 cave[y][x].feat = feat2;
3002 cave[y][x].info &= ~(CAVE_MASK);
3003 cave[y][x].info |= info2;
3007 else if (cave[y][x].feat <= c2)
3009 /* 25% of the time use the other tile : it looks better this way */
3010 if (randint1(100) < 75)
3012 cave[y][x].feat = feat2;
3013 cave[y][x].info &= ~(CAVE_MASK);
3014 cave[y][x].info |= info2;
3019 cave[y][x].feat = feat1;
3020 cave[y][x].info &= ~(CAVE_MASK);
3021 cave[y][x].info |= info1;
3025 else if (cave[y][x].feat <= c3)
3027 cave[y][x].feat = feat3;
3028 cave[y][x].info |= info3;
3031 /* if greater than cutoff then is a wall */
3034 place_outer_bold(y, x);
3044 * Quick and nasty fill routine used to find the connected region
3045 * of floor in the middle of the cave
3047 static void cave_fill(byte y, byte x)
3056 /*** Start Grid ***/
3058 /* Enqueue that entry */
3063 /* Now process the queue */
3064 while (flow_head != flow_tail)
3066 /* Extract the next entry */
3067 ty = temp_y[flow_head];
3068 tx = temp_x[flow_head];
3070 /* Forget that entry */
3071 if (++flow_head == TEMP_MAX) flow_head = 0;
3073 /* Add the "children" */
3074 for (d = 0; d < 8; d++)
3076 int old_head = flow_tail;
3078 /* Child location */
3079 j = ty + ddy_ddd[d];
3080 i = tx + ddx_ddd[d];
3082 /* Paranoia Don't leave the cave */
3083 if (!in_bounds(j, i))
3085 /* affect boundary */
3086 cave[j][i].info |= CAVE_ICKY;
3090 /* If within bounds */
3091 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3092 && (j > fill_data.ymin) && (j < fill_data.ymax))
3094 /* If not a wall or floor done before */
3095 if (hack_isnt_wall(j, i,
3096 fill_data.c1, fill_data.c2, fill_data.c3,
3097 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3098 fill_data.info1, fill_data.info2, fill_data.info3))
3100 /* Enqueue that entry */
3101 temp_y[flow_tail] = j;
3102 temp_x[flow_tail] = i;
3104 /* Advance the queue */
3105 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3107 /* Hack -- Overflow by forgetting new entry */
3108 if (flow_tail == flow_head)
3110 flow_tail = old_head;
3114 /* keep tally of size of cave system */
3115 (fill_data.amount)++;
3121 /* affect boundary */
3122 cave[j][i].info |= CAVE_ICKY;
3129 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3131 int x, y, i, xhsize, yhsize;
3134 /* offsets to middle from corner */
3140 * select region connected to center of cave system
3141 * this gets rid of alot of isolated one-sqaures that
3142 * can make teleport traps instadeaths...
3146 fill_data.c1 = cutoff;
3150 /* features to fill with */
3151 fill_data.feat1 = floor_type[randint0(100)];
3152 fill_data.feat2 = floor_type[randint0(100)];
3153 fill_data.feat3 = floor_type[randint0(100)];
3155 fill_data.info1 = CAVE_FLOOR;
3156 fill_data.info2 = CAVE_FLOOR;
3157 fill_data.info3 = CAVE_FLOOR;
3159 /* number of filled squares */
3160 fill_data.amount = 0;
3162 cave_fill((byte)y0, (byte)x0);
3164 /* if tally too small, try again */
3165 if (fill_data.amount < 10)
3167 /* too small - clear area and try again later */
3168 for (x = 0; x <= xsize; ++x)
3170 for (y = 0; y <= ysize; ++y)
3172 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3173 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3180 * Do boundarys-check to see if they are next to a filled region
3181 * If not then they are set to normal granite
3182 * If so then they are marked as room walls.
3184 for (i = 0; i <= xsize; ++i)
3187 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3189 /* Next to a 'filled' region? - set to be room walls */
3190 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3191 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3192 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3193 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3197 /* set to be normal granite */
3198 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3201 /* bottom boundary */
3202 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3204 /* Next to a 'filled' region? - set to be room walls */
3205 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3206 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3207 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3208 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3212 /* set to be normal granite */
3213 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3216 /* clear the icky flag-don't need it any more */
3217 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3218 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3221 /* Do the left and right boundaries minus the corners (done above) */
3222 for (i = 1; i < ysize; ++i)
3225 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3228 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3229 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3230 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3231 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3236 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3238 /* right boundary */
3239 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3242 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3243 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3244 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3245 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3250 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3253 /* clear icky flag -done with it */
3254 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3255 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3259 /* Do the rest: convert back to the normal format */
3260 for (x = 1; x < xsize; ++x)
3262 for (y = 1; y < ysize; ++y)
3264 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3265 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3267 /* Clear the icky flag in the filled region */
3268 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3270 /* Set appropriate flags */
3271 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3272 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3274 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3275 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3278 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3279 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3282 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3287 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3288 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3293 /* Clear the unconnected regions */
3294 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3295 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3301 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3302 * Extra doors appear inside the system. (Its not very noticeable though.)
3303 * This can be removed by "filling" from the outside in. This allows a separation
3304 * from FEAT_WALL_OUTER with FEAT_WALL_INNER. (Internal walls are F.W.OUTER instead.)
3305 * The extra effort for what seems to be only a minor thing (even non-existant if you
3306 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3315 * Driver routine to create fractal cave system
3317 static void build_type9(int by0, int bx0)
3319 int grd, roug, cutoff, xsize, ysize, y0, x0;
3321 bool done, light, room;
3323 /* get size: note 'Evenness'*/
3324 xsize = randint1(22) * 2 + 6;
3325 ysize = randint1(15) * 2 + 6;
3327 /* Try to allocate space for room. If fails, exit */
3328 if (!room_alloc(xsize + 1, ysize + 1, FALSE, by0, bx0, &x0, &y0)) return;
3330 light = done = FALSE;
3333 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3337 /* Note: size must be even or there are rounding problems
3338 * This causes the tunnels not to connect properly to the room */
3340 /* testing values for these parameters feel free to adjust */
3341 grd = 1 << (randint0(4));
3343 /* want average of about 16 */
3344 roug = randint1(8) * randint1(4);
3347 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3348 randint1(xsize / 4) + randint1(ysize / 4);
3351 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3353 /* Convert to normal format + clean up */
3354 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3358 #ifdef ALLOW_CAVERNS_AND_LAKES
3360 * Builds a cave system in the center of the dungeon.
3362 void build_cavern(void)
3364 int grd, roug, cutoff, xsize, ysize, x0, y0;
3367 light = done = FALSE;
3368 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3370 /* Make a cave the size of the dungeon */
3371 xsize = cur_wid - 1;
3372 ysize = cur_hgt - 1;
3376 /* Paranoia: make size even */
3382 /* testing values for these parameters: feel free to adjust */
3383 grd = randint1(4) + 4;
3385 /* want average of about 16 */
3386 roug = randint1(8) * randint1(4);
3392 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3394 /* Convert to normal format+ clean up */
3395 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3399 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3401 int x, y, i, xhsize, yhsize;
3402 int feat1, feat2, feat3;
3404 /* offsets to middle from corner */
3408 /* Get features based on type */
3413 feat1 = FEAT_DEEP_LAVA;
3414 feat2 = FEAT_SHAL_LAVA;
3415 feat3 = floor_type[randint0(100)];
3419 feat1 = FEAT_DEEP_WATER;
3420 feat2 = FEAT_SHAL_WATER;
3421 feat3 = floor_type[randint0(100)];
3424 /* Collapsed cave */
3425 feat1 = floor_type[randint0(100)];
3426 feat2 = floor_type[randint0(100)];
3427 feat3 = FEAT_RUBBLE;
3431 feat1 = FEAT_RUBBLE;
3432 feat2 = floor_type[randint0(100)];
3433 feat3 = FEAT_RUBBLE;
3443 feat1 = FEAT_SHAL_WATER;
3444 feat2 = FEAT_DEEP_WATER;
3445 feat3 = FEAT_SHAL_WATER;
3449 feat1 = FEAT_SHAL_LAVA;
3450 feat2 = FEAT_DEEP_LAVA;
3451 feat3 = FEAT_SHAL_LAVA;
3455 default: return FALSE;
3459 * select region connected to center of cave system
3460 * this gets rid of alot of isolated one-sqaures that
3461 * can make teleport traps instadeaths...
3469 /* features to fill with */
3470 fill_data.feat1 = feat1;
3471 fill_data.feat2 = feat2;
3472 fill_data.feat3 = feat3;
3474 fill_data.info1 = 0;
3475 fill_data.info2 = 0;
3476 fill_data.info3 = 0;
3478 /* number of filled squares */
3479 fill_data.amount = 0;
3481 /* select region connected to center of cave system
3482 * this gets rid of alot of isolated one-sqaures that
3483 * can make teleport traps instadeaths... */
3484 cave_fill((byte)y0, (byte)x0);
3486 /* if tally too small, try again */
3487 if (fill_data.amount < 10)
3489 /* too small -clear area and try again later */
3490 for (x = 0; x <= xsize; ++x)
3492 for (y = 0; y <= ysize; ++y)
3494 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3495 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3501 /* Do boundarys- set to normal granite */
3502 for (i = 0; i <= xsize; ++i)
3504 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3505 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3507 /* clear the icky flag-don't need it any more */
3508 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3509 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3512 /* Do the left and right boundaries minus the corners (done above) */
3514 for (i = 1; i < ysize; ++i)
3516 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3517 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3519 /* clear icky flag -done with it */
3520 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3521 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3525 /* Do the rest: convert back to the normal format */
3526 for (x = 1; x < xsize; ++x)
3528 for (y = 1; y < ysize; ++y)
3530 /* Fill unconnected regions with granite */
3531 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3532 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3533 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3535 /* turn off icky flag (no longer needed.) */
3536 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3538 /* Light lava and trees */
3539 if ((cave[y0 + y - yhsize][x0 + x - xhsize].feat == FEAT_DEEP_LAVA) ||
3540 (cave[y0 + y - yhsize][x0 + x - xhsize].feat == FEAT_SHAL_LAVA))
3542 cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
3552 * makes a lake/collapsed cave system in the center of the dungeon
3554 void build_lake(int type)
3556 int grd, roug, xsize, ysize, x0, y0;
3560 /* paranoia - exit if lake type out of range. */
3561 if ((type < 1) || (type > 7))
3563 msg_format("Invalid lake type (%d)", type);
3567 /* Make the size of the dungeon */
3568 xsize = cur_wid - 1;
3569 ysize = cur_hgt - 1;
3573 /* Paranoia: make size even */
3579 /* testing values for these parameters: feel free to adjust */
3580 grd = randint1(3) + 4;
3582 /* want average of about 16 */
3583 roug = randint1(8) * randint1(4);
3585 /* Make up size of various componants */
3589 /* Deep water/lava */
3590 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
3592 /* Shallow boundary */
3596 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
3598 /* Convert to normal format+ clean up */
3599 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
3602 #endif /* ALLOW_CAVERNS_AND_LAKES */
3606 * Routine used by the random vault creators to add a door to a location
3607 * Note that range checking has to be done in the calling routine.
3609 * The doors must be INSIDE the allocated region.
3611 static void add_door(int x, int y)
3613 /* Need to have a wall in the center square */
3614 if (!is_outer_bold(y, x)) return;
3621 * where x=don't care
3625 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
3626 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
3629 place_secret_door(y, x);
3631 /* set boundarys so don't get wide doors */
3632 place_solid_bold(y, x - 1);
3633 place_solid_bold(y, x + 1);
3642 * where x = don't care
3645 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
3646 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
3649 place_secret_door(y, x);
3651 /* set boundarys so don't get wide doors */
3652 place_solid_bold(y - 1, x);
3653 place_solid_bold(y + 1, x);
3659 * Routine that fills the empty areas of a room with treasure and monsters.
3661 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
3663 int x, y, cx, cy, size;
3666 /* center of room:*/
3670 /* Rough measure of size of vault= sum of lengths of sides */
3671 size = abs(x2 - x1) + abs(y2 - y1);
3673 for (x = x1; x <= x2; x++)
3675 for (y = y1; y <= y2; y++)
3677 /* Thing added based on distance to center of vault
3678 * Difficulty is 1-easy to 10-hard */
3679 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
3681 /* hack- empty square part of the time */
3682 if ((randint1(100) - difficulty * 3) > 50) value = 20;
3684 /* if floor, shallow water and lava */
3685 if (is_floor_bold(y, x) ||
3686 (cave[y][x].feat == FEAT_SHAL_WATER) ||
3687 (cave[y][x].feat == FEAT_SHAL_LAVA))
3689 /* The smaller 'value' is, the better the stuff */
3692 /* Meanest monster + treasure */
3693 monster_level = base_level + 40;
3694 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3695 monster_level = base_level;
3696 object_level = base_level + 20;
3697 place_object(y, x, TRUE, FALSE);
3698 object_level = base_level;
3702 /* Mean monster +treasure */
3703 monster_level = base_level + 20;
3704 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3705 monster_level = base_level;
3706 object_level = base_level + 10;
3707 place_object(y, x, TRUE, FALSE);
3708 object_level = base_level;
3710 else if (value < 10)
3713 monster_level = base_level + 9;
3714 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3715 monster_level = base_level;
3717 else if (value < 17)
3719 /* Intentional Blank space */
3722 * (Want some of the vault to be empty
3723 * so have room for group monsters.
3724 * This is used in the hack above to lower
3725 * the density of stuff in the vault.)
3728 else if (value < 23)
3730 /* Object or trap */
3731 if (randint0(100) < 25)
3733 place_object(y, x, FALSE, FALSE);
3740 else if (value < 30)
3742 /* Monster and trap */
3743 monster_level = base_level + 5;
3744 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3745 monster_level = base_level;
3748 else if (value < 40)
3750 /* Monster or object */
3751 if (randint0(100) < 50)
3753 monster_level = base_level + 3;
3754 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3755 monster_level = base_level;
3757 if (randint0(100) < 50)
3759 object_level = base_level + 7;
3760 place_object(y, x, FALSE, FALSE);
3761 object_level = base_level;
3764 else if (value < 50)
3773 /* 20% monster, 40% trap, 20% object, 20% blank space */
3774 if (randint0(100) < 20)
3776 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3778 else if (randint0(100) < 50)
3782 else if (randint0(100) < 50)
3784 place_object(y, x, FALSE, FALSE);
3795 * This function creates a random vault that looks like a collection of bubbles.
3796 * It works by getting a set of coordinates that represent the center of each
3797 * bubble. The entire room is made by seeing which bubble center is closest. If
3798 * two centers are equidistant then the square is a wall, otherwise it is a floor.
3799 * The only exception is for squares really near a center, these are always floor.
3800 * (It looks better than without this check.)
3802 * Note: If two centers are on the same point then this algorithm will create a
3803 * blank bubble filled with walls. - This is prevented from happening.
3805 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
3807 #define BUBBLENUM 10 /* number of bubbles */
3809 /* array of center points of bubbles */
3810 coord center[BUBBLENUM];
3813 u16b min1, min2, temp;
3816 /* Offset from center to top left hand corner */
3817 int xhsize = xsize / 2;
3818 int yhsize = ysize / 2;
3821 if (cheat_room) msg_print("Bubble Vault");
3823 /* Allocate center of bubbles */
3824 center[0].x = randint1(xsize - 3) + 1;
3825 center[0].y = randint1(ysize - 3) + 1;
3827 for (i = 1; i < BUBBLENUM; i++)
3831 /* get center and check to see if it is unique */
3836 x = randint1(xsize - 3) + 1;
3837 y = randint1(ysize - 3) + 1;
3839 for (j = 0; j < i; j++)
3841 /* rough test to see if there is an overlap */
3842 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
3851 /* Top and bottom boundaries */
3852 for (i = 0; i < xsize; i++)
3854 int x = x0 - xhsize + i;
3856 place_outer_noperm_bold(y0 - yhsize + 0, x);
3857 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
3858 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
3859 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
3862 /* Left and right boundaries */
3863 for (i = 1; i < ysize - 1; i++)
3865 int y = y0 - yhsize + i;
3867 place_outer_noperm_bold(y, x0 - xhsize + 0);
3868 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
3869 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
3870 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
3873 /* Fill in middle with bubbles */
3874 for (x = 1; x < xsize - 1; x++)
3876 for (y = 1; y < ysize - 1; y++)
3878 /* Get distances to two closest centers */
3881 min1 = distance(x, y, center[0].x, center[0].y);
3882 min2 = distance(x, y, center[1].x, center[1].y);
3886 /* swap if in wrong order */
3893 for (i = 2; i < BUBBLENUM; i++)
3895 temp = distance(x, y, center[i].x, center[i].y);
3903 else if (temp < min2)
3905 /* second smallest */
3909 if (((min2 - min1) <= 2) && (!(min1 < 3)))
3911 /* Boundary at midpoint+ not at inner region of bubble */
3912 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
3916 /* middle of a bubble */
3917 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
3920 /* clean up rest of flags */
3921 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
3925 /* Try to add some random doors */
3926 for (i = 0; i < 500; i++)
3928 x = randint1(xsize - 3) - xhsize + x0 + 1;
3929 y = randint1(ysize - 3) - yhsize + y0 + 1;
3933 /* Fill with monsters and treasure, low difficulty */
3934 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
3939 * Overlay a rectangular room given its bounds
3940 * This routine is used by build_room_vault
3941 * The area inside the walls is not touched:
3942 * only granite is removed- normal walls stay
3944 static void build_room(int x1, int x2, int y1, int y2)
3946 int x, y, i, xsize, ysize, temp;
3948 /* Check if rectangle has no width */
3949 if ((x1 == x2) || (y1 == y2)) return;
3954 /* Swap boundaries if in wrong order */
3962 /* Swap boundaries if in wrong order */
3968 /* get total widths */
3973 /* Top and bottom boundaries */
3974 for (i = 0; i <= xsize; i++)
3976 place_outer_noperm_bold(y1, x1 + i);
3977 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
3978 place_outer_noperm_bold(y2, x1 + i);
3979 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
3982 /* Left and right boundaries */
3983 for (i = 1; i < ysize; i++)
3985 place_outer_noperm_bold(y1 + i, x1);
3986 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
3987 place_outer_noperm_bold(y1 + i, x2);
3988 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
3992 for (x = 1; x < xsize; x++)
3994 for (y = 1; y < ysize; y++)
3996 if (is_extra_bold(y1+y, x1+x))
3998 /* clear the untouched region */
3999 place_floor_bold(y1 + y, x1 + x);
4000 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4004 /* make it a room- but don't touch */
4005 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4012 /* Create a random vault that looks like a collection of overlapping rooms */
4014 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4016 int i, x1, x2, y1, y2, xhsize, yhsize;
4018 /* get offset from center */
4022 if (cheat_room) msg_print("Room Vault");
4024 /* fill area so don't get problems with arena levels */
4025 for (x1 = 0; x1 < xsize; x1++)
4027 int x = x0 - xhsize + x1;
4029 for (y1 = 0; y1 < ysize; y1++)
4031 int y = y0 - yhsize + y1;
4033 place_extra_bold(y, x);
4034 cave[y][x].info &= (~CAVE_ICKY);
4038 /* add ten random rooms */
4039 for (i = 0; i < 10; i++)
4041 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4042 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4043 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4044 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4045 build_room(x1, x2, y1, y2);
4048 /* Add some random doors */
4049 for (i = 0; i < 500; i++)
4051 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4052 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4056 /* Fill with monsters and treasure, high difficulty */
4057 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4061 /* Create a random vault out of a fractal cave */
4062 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4064 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4065 bool done, light, room;
4067 /* round to make sizes even */
4073 if (cheat_room) msg_print("Cave Vault");
4075 light = done = FALSE;
4080 /* testing values for these parameters feel free to adjust */
4081 grd = 1 << randint0(4);
4083 /* want average of about 16 */
4084 roug = randint1(8) * randint1(4);
4087 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4088 randint1(xsize / 4) + randint1(ysize / 4);
4091 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4093 /* Convert to normal format+ clean up */
4094 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4097 /* Set icky flag because is a vault */
4098 for (x = 0; x <= xsize; x++)
4100 for (y = 0; y <= ysize; y++)
4102 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4106 /* Fill with monsters and treasure, low difficulty */
4107 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4111 * maze vault -- rectangular labyrinthine rooms
4113 * maze vault uses two routines:
4114 * r_visit - a recursive routine that builds the labyrinth
4115 * build_maze_vault - a driver routine that calls r_visit and adds
4116 * monsters, traps and treasure
4118 * The labyrinth is built by creating a spanning tree of a graph.
4119 * The graph vertices are at
4120 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4121 * and the edges are the vertical and horizontal nearest neighbors.
4123 * The spanning tree is created by performing a suitably randomized
4124 * depth-first traversal of the graph. The only adjustable parameter
4125 * is the randint0(3) below; it governs the relative density of
4126 * twists and turns in the labyrinth: smaller number, more twists.
4128 static void r_visit(int y1, int x1, int y2, int x2,
4129 int node, int dir, int *visited)
4131 int i, j, m, n, temp, x, y, adj[4];
4133 /* dimensions of vertex array */
4134 m = (x2 - x1) / 2 + 1;
4135 n = (y2 - y1) / 2 + 1;
4137 /* mark node visited and set it to a floor */
4139 x = 2 * (node % m) + x1;
4140 y = 2 * (node / m) + y1;
4141 place_floor_bold(y, x);
4143 /* setup order of adjacent node visits */
4146 /* pick a random ordering */
4147 for (i = 0; i < 4; i++)
4149 for (i = 0; i < 4; i++)
4160 /* pick a random ordering with dir first */
4162 for (i = 1; i < 4; i++)
4164 for (i = 1; i < 4; i++)
4166 j = 1 + randint0(3);
4173 for (i = 0; i < 4; i++)
4178 /* (0,+) - check for bottom boundary */
4179 if ((node / m < n - 1) && (visited[node + m] == 0))
4181 place_floor_bold(y + 1, x);
4182 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4186 /* (0,-) - check for top boundary */
4187 if ((node / m > 0) && (visited[node - m] == 0))
4189 place_floor_bold(y - 1, x);
4190 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4194 /* (+,0) - check for right boundary */
4195 if ((node % m < m - 1) && (visited[node + 1] == 0))
4197 place_floor_bold(y, x + 1);
4198 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4202 /* (-,0) - check for left boundary */
4203 if ((node % m > 0) && (visited[node - 1] == 0))
4205 place_floor_bold(y, x - 1);
4206 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4213 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4217 int m, n, num_vertices, *visited;
4222 if (cheat_room && is_vault) msg_print("Maze Vault");
4224 /* Choose lite or dark */
4225 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4227 /* Pick a random room size - randomized by calling routine */
4236 /* generate the room */
4237 for (y = y1 - 1; y <= y2 + 1; y++)
4239 for (x = x1 - 1; x <= x2 + 1; x++)
4241 c_ptr = &cave[y][x];
4242 c_ptr->info |= CAVE_ROOM;
4243 if (is_vault) c_ptr->info |= CAVE_ICKY;
4244 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4246 place_outer_grid(c_ptr);
4250 place_extra_grid(c_ptr);
4254 place_inner_grid(c_ptr);
4256 if (light) c_ptr->info |= (CAVE_GLOW);
4260 /* dimensions of vertex array */
4263 num_vertices = m * n;
4265 /* initialize array of visited vertices */
4266 C_MAKE(visited, num_vertices, int);
4268 /* traverse the graph to create a spaning tree, pick a random root */
4269 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4271 /* Fill with monsters and treasure, low difficulty */
4272 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4274 C_KILL(visited, num_vertices, int);
4278 /* Build a "mini" checkerboard vault
4280 * This is done by making a permanent wall maze and setting
4281 * the diagonal sqaures of the checker board to be granite.
4282 * The vault has two entrances on opposite sides to guarantee
4283 * a way to get in even if the vault abuts a side of the dungeon.
4285 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4288 int y1, x1, y2, x2, y, x, total;
4289 int m, n, num_vertices;
4292 if (cheat_room) msg_print("Mini Checker Board Vault");
4294 /* Pick a random room size */
4304 /* generate the room */
4305 for (x = x1 - 2; x <= x2 + 2; x++)
4307 if (!in_bounds(y1-2,x)) break;
4309 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4311 place_extra_noperm_bold(y1-2, x);
4314 for (x = x1 - 2; x <= x2 + 2; x++)
4316 if (!in_bounds(y2+2,x)) break;
4318 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4320 place_extra_noperm_bold(y2+2, x);
4323 for (y = y1 - 2; y <= y2 + 2; y++)
4325 if (!in_bounds(y,x1-2)) break;
4327 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4329 place_extra_noperm_bold(y, x1-2);
4332 for (y = y1 - 2; y <= y2 + 2; y++)
4334 if (!in_bounds(y,x2+2)) break;
4336 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4338 place_extra_noperm_bold(y, x2+2);
4341 for (y = y1 - 1; y <= y2 + 1; y++)
4343 for (x = x1 - 1; x <= x2 + 1; x++)
4345 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
4347 /* Permanent walls */
4348 cave[y][x].feat = FEAT_PERM_INNER;
4353 /* dimensions of vertex array */
4356 num_vertices = m * n;
4358 /* initialize array of visited vertices */
4359 C_MAKE(visited, num_vertices, int);
4361 /* traverse the graph to create a spannng tree, pick a random root */
4362 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4364 /* Make it look like a checker board vault */
4365 for (x = x1; x <= x2; x++)
4367 for (y = y1; y <= y2; y++)
4369 total = x - x1 + y - y1;
4370 /* If total is odd- and is a floor then make a wall */
4371 if ((total % 2 == 1) && is_floor_bold(y, x))
4373 place_inner_bold(y, x);
4378 /* Make a couple of entrances */
4381 /* left and right */
4382 y = randint1(dy) + dy / 2;
4383 place_outer_noperm_bold(y1 + y, x1 - 1);
4384 place_outer_noperm_bold(y1 + y, x2 + 1);
4388 /* top and bottom */
4389 x = randint1(dx) + dx / 2;
4390 place_outer_noperm_bold(y1 - 1, x1 + x);
4391 place_outer_noperm_bold(y2 + 1, x1 + x);
4394 /* Fill with monsters and treasure, highest difficulty */
4395 fill_treasure(x1, x2, y1, y2, 10);
4397 C_KILL(visited, num_vertices, int);
4401 /* Build a town/ castle by using a recursive algorithm.
4402 * Basically divide each region in a probalistic way to create
4403 * smaller regions. When the regions get too small stop.
4405 * The power variable is a measure of how well defended a region is.
4406 * This alters the possible choices.
4408 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4414 /* Temp variables */
4420 if ((power < 3) && (xsize > 12) && (ysize > 12))
4422 /* Need outside wall +keep */
4429 /* Make rooms + subdivide */
4430 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4436 choice = randint1(2) + 1;
4441 /* Mostly subdivide */
4442 choice = randint1(3) + 1;
4446 /* Based on the choice made above, do something */
4454 /* top and bottom */
4455 for (x = x1; x <= x2; x++)
4457 place_outer_bold(y1, x);
4458 place_outer_bold(y2, x);
4461 /* left and right */
4462 for (y = y1 + 1; y < y2; y++)
4464 place_outer_bold(y, x1);
4465 place_outer_bold(y, x2);
4468 /* Make a couple of entrances */
4471 /* left and right */
4472 y = randint1(ysize) + y1;
4473 place_floor_bold(y, x1);
4474 place_floor_bold(y, x2);
4478 /* top and bottom */
4479 x = randint1(xsize) + x1;
4480 place_floor_bold(y1, x);
4481 place_floor_bold(y2, x);
4484 /* Select size of keep */
4485 t1 = randint1(ysize / 3) + y1;
4486 t2 = y2 - randint1(ysize / 3);
4487 t3 = randint1(xsize / 3) + x1;
4488 t4 = x2 - randint1(xsize / 3);
4490 /* Do outside areas */
4492 /* Above and below keep */
4493 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4494 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4496 /* Left and right of keep */
4497 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4498 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4500 /* Make the keep itself: */
4513 /* Try to build a room */
4514 if ((xsize < 3) || (ysize < 3))
4516 for (y = y1; y < y2; y++)
4518 for (x = x1; x < x2; x++)
4520 place_inner_bold(y, x);
4528 /* Make outside walls */
4529 /* top and bottom */
4530 for (x = x1 + 1; x <= x2 - 1; x++)
4532 place_inner_bold(y1 + 1, x);
4533 place_inner_bold(y2 - 1, x);
4536 /* left and right */
4537 for (y = y1 + 1; y <= y2 - 1; y++)
4539 place_inner_bold(y, x1 + 1);
4540 place_inner_bold(y, x2 - 1);
4544 y = randint1(ysize - 3) + y1 + 1;
4549 place_floor_bold(y, x1 + 1);
4554 place_floor_bold(y, x2 - 1);
4557 /* Build the room */
4558 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
4563 /* Try and divide vertically */
4567 for (y = y1; y < y2; y++)
4569 for (x = x1; x < x2; x++)
4571 place_inner_bold(y, x);
4577 t1 = randint1(xsize - 2) + x1 + 1;
4578 build_recursive_room(x1, y1, t1, y2, power - 2);
4579 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
4584 /* Try and divide horizontally */
4588 for (y = y1; y < y2; y++)
4590 for (x = x1; x < x2; x++)
4592 place_inner_bold(y, x);
4598 t1 = randint1(ysize - 2) + y1 + 1;
4599 build_recursive_room(x1, y1, x2, t1, power - 2);
4600 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
4607 /* Build a castle */
4609 /* Driver routine: clear the region and call the recursive
4612 *This makes a vault that looks like a castle/ city in the dungeon.
4614 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
4620 /* Pick a random room size */
4629 if (cheat_room) msg_print("Castle Vault");
4631 /* generate the room */
4632 for (y = y1 - 1; y <= y2 + 1; y++)
4634 for (x = x1 - 1; x <= x2 + 1; x++)
4636 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
4637 /* Make everything a floor */
4638 place_floor_bold(y, x);
4642 /* Make the castle */
4643 build_recursive_room(x1, y1, x2, y2, randint1(5));
4645 /* Fill with monsters and treasure, low difficulty */
4646 fill_treasure(x1, x2, y1, y2, randint1(3));
4651 * Add outer wall to a floored region
4652 * Note: no range checking is done so must be inside dungeon
4653 * This routine also stomps on doors
4655 static void add_outer_wall(int x, int y, int light,
4656 int x1, int y1, int x2, int y2)
4660 if (!in_bounds(y, x)) return;
4662 /* hack- check to see if square has been visited before
4663 * if so, then exit (use room flag to do this) */
4664 if (cave[y][x].info & CAVE_ROOM) return;
4667 cave[y][x].info |= CAVE_ROOM;
4669 if (is_floor_bold(y, x))
4671 for (i = -1; i <= 1; i++)
4673 for (j = -1; j <= 1; j++)
4675 if ((x + i >= x1) && (x + i <= x2) &&
4676 (y + j >= y1) && (y + j <= y2))
4678 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
4679 if (light) cave[y][x].info |= CAVE_GLOW;
4684 else if (is_extra_bold(y, x))
4686 /* Set bounding walls */
4687 place_outer_bold(y, x);
4688 if (light == TRUE) cave[y][x].info |= CAVE_GLOW;
4690 else if (cave[y][x].feat == FEAT_PERM_OUTER)
4692 /* Set bounding walls */
4693 if (light == TRUE) cave[y][x].info |= CAVE_GLOW;
4699 * Hacked distance formula - gives the 'wrong' answer.
4700 * Used to build crypts
4702 static int dist2(int x1, int y1, int x2, int y2,
4703 int h1, int h2, int h3, int h4)
4709 /* Basically this works by taking the normal pythagorean formula
4710 * and using an expansion to express this in a way without the
4711 * square root. This approximate formula is then perturbed to give
4712 * the distorted results. (I found this by making a mistake when I was
4713 * trying to fix the circular rooms.)
4716 /* h1-h4 are constants that describe the metric */
4717 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
4718 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
4719 return (((dx + dy) * 128) / 181 +
4720 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
4721 /* 128/181 is approx. 1/sqrt(2) */
4726 * Build target vault.
4727 * This is made by two concentric "crypts" with perpendicular
4728 * walls creating the cross-hairs.
4730 static void build_target_vault(int x0, int y0, int xsize, int ysize)
4734 /* Make a random metric */
4736 h1 = randint1(32) - 16;
4739 h4 = randint1(32) - 16;
4741 if (cheat_room) msg_print("Target Vault");
4743 /* work out outer radius */
4754 for (x = x0 - rad; x <= x0 + rad; x++)
4756 for (y = y0 - rad; y <= y0 + rad; y++)
4758 /* clear room flag */
4759 cave[y][x].info &= ~(CAVE_ROOM);
4761 /* Vault - so is "icky" */
4762 cave[y][x].info |= CAVE_ICKY;
4764 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
4766 /* inside- so is floor */
4767 place_floor_bold(y, x);
4771 /* make granite outside so arena works */
4772 place_extra_bold(y, x);
4775 /* proper boundary for arena */
4776 if (((y + rad) == y0) || ((y - rad) == y0) ||
4777 ((x + rad) == x0) || ((x - rad) == x0))
4779 place_extra_bold(y, x);
4784 /* Find visible outer walls and set to be FEAT_OUTER */
4785 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
4786 x0 + rad + 1, y0 + rad + 1);
4788 /* Add inner wall */
4789 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
4791 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
4793 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
4795 /* Make an internal wall */
4796 place_inner_bold(y, x);
4801 /* Add perpendicular walls */
4802 for (x = x0 - rad; x <= x0 + rad; x++)
4804 place_inner_bold(y0, x);
4807 for (y = y0 - rad; y <= y0 + rad; y++)
4809 place_inner_bold(y, x0);
4812 /* Make inner vault */
4813 for (y = y0 - 1; y <= y0 + 1; y++)
4815 place_inner_bold(y, x0 - 1);
4816 place_inner_bold(y, x0 + 1);
4818 for (x = x0 - 1; x <= x0 + 1; x++)
4820 place_inner_bold(y0 - 1, x);
4821 place_inner_bold(y0 + 1, x);
4824 place_floor_bold(y0, x0);
4827 /* Add doors to vault */
4828 /* get two distances so can place doors relative to centre */
4829 x = (rad - 2) / 4 + 1;
4832 add_door(x0 + x, y0);
4833 add_door(x0 + y, y0);
4834 add_door(x0 - x, y0);
4835 add_door(x0 - y, y0);
4836 add_door(x0, y0 + x);
4837 add_door(x0, y0 + y);
4838 add_door(x0, y0 - x);
4839 add_door(x0, y0 - y);
4841 /* Fill with stuff - medium difficulty */
4842 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
4846 #ifdef ALLOW_CAVERNS_AND_LAKES
4848 * This routine uses a modified version of the lake code to make a
4849 * distribution of some terrain type over the vault. This type
4850 * depends on the dungeon depth.
4852 * Miniture rooms are then scattered across the vault.
4854 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
4859 int xsize, ysize, xhsize, yhsize, x, y, i;
4863 if (cheat_room) msg_print("Elemental Vault");
4865 /* round to make sizes even */
4873 /* Earth vault (Rubble) */
4876 else if (dun_level < 50)
4878 /* Air vault (Trees) */
4881 else if (dun_level < 75)
4883 /* Water vault (shallow water) */
4888 /* Fire vault (shallow lava) */
4894 /* testing values for these parameters: feel free to adjust */
4895 grd = 1 << (randint0(3));
4897 /* want average of about 16 */
4898 roug = randint1(8) * randint1(4);
4900 /* Make up size of various componants */
4904 /* Deep water/lava */
4905 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4907 /* Shallow boundary */
4911 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
4913 /* Convert to normal format+ clean up */
4914 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
4917 /* Set icky flag because is a vault */
4918 for (x = 0; x <= xsize; x++)
4920 for (y = 0; y <= ysize; y++)
4922 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4926 /* make a few rooms in the vault */
4927 for (i = 1; i <= (xsize * ysize) / 50; i++)
4929 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
4930 y0 + randint0(ysize - 4) - ysize / 2 + 2);
4933 /* Fill with monsters and treasure, low difficulty */
4934 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
4935 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4937 #endif /* ALLOW_CAVERNS_AND_LAKES */
4943 static void build_type10(int by0, int bx0)
4945 int y0, x0, xsize, ysize, vtype;
4948 /* big enough to look good, small enough to be fairly common. */
4949 xsize = randint1(22) + 22;
4950 ysize = randint1(11) + 11;
4952 /* Allocate in room_map. If will not fit, exit */
4953 if (!room_alloc(xsize + 1, ysize + 1, FALSE, by0, bx0, &x0, &y0)) return;
4955 /* Boost the rating- higher than lesser vaults and lower than greater vaults */
4958 /* (Sometimes) Cause a special feeling */
4959 if ((dun_level <= 50) ||
4960 (randint1((dun_level - 40) * (dun_level - 40) + 1) < 400))
4962 good_item_flag = TRUE;
4965 /* Select type of vault */
4966 #ifdef ALLOW_CAVERNS_AND_LAKES
4967 vtype = randint1(15);
4968 #else /* ALLOW_CAVERNS_AND_LAKES */
4969 vtype = randint1(7);
4970 #endif /* ALLOW_CAVERNS_AND_LAKES */
4974 /* Build an appropriate room */
4975 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
4976 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
4977 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
4978 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
4979 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
4980 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
4981 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
4982 #ifdef ALLOW_CAVERNS_AND_LAKES
4983 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
4984 #endif /* ALLOW_CAVERNS_AND_LAKES */
4985 /* I know how to add a few more... give me some time. */
4994 * Build an vertical oval room.
4995 * For every grid in the possible square, check the distance.
4996 * If it's less than the radius, make it a room square.
4998 * When done fill from the inside to find the walls,
5000 static void build_type11(int by0, int bx0)
5002 int rad, x, y, x0, y0;
5005 /* Occasional light */
5006 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5010 /* Allocate in room_map. If will not fit, exit */
5011 if (!room_alloc(rad * 2 + 1, rad * 2 + 1, FALSE, by0, bx0, &x0, &y0)) return;
5013 /* Make circular floor */
5014 for (x = x0 - rad; x <= x0 + rad; x++)
5016 for (y = y0 - rad; y <= y0 + rad; y++)
5018 if (distance(y0, x0, y, x) <= rad - 1)
5020 /* inside- so is floor */
5021 place_floor_bold(y, x);
5023 else if (distance(y0, x0, y, x) <= rad + 1)
5025 /* make granite outside so arena works */
5026 place_extra_bold(y, x);
5031 /* Find visible outer walls and set to be FEAT_OUTER */
5032 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5038 * For every grid in the possible square, check the (fake) distance.
5039 * If it's less than the radius, make it a room square.
5041 * When done fill from the inside to find the walls,
5043 static void build_type12(int by0, int bx0)
5045 int rad, x, y, x0, y0;
5047 bool emptyflag = TRUE;
5049 /* Make a random metric */
5051 h1 = randint1(32) - 16;
5054 h4 = randint1(32) - 16;
5056 /* Occasional light */
5057 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5061 /* Allocate in room_map. If will not fit, exit */
5062 if (!room_alloc(rad * 2 + 3, rad * 2 + 3, FALSE, by0, bx0, &x0, &y0)) return;
5065 for (x = x0 - rad; x <= x0 + rad; x++)
5067 for (y = y0 - rad; y <= y0 + rad; y++)
5069 /* clear room flag */
5070 cave[y][x].info &= ~(CAVE_ROOM);
5072 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5074 /* inside - so is floor */
5075 place_floor_bold(y, x);
5077 else if (distance(y0, x0, y, x) < 3)
5079 place_floor_bold(y, x);
5083 /* make granite outside so arena works */
5084 place_extra_bold(y, x);
5087 /* proper boundary for arena */
5088 if (((y + rad) == y0) || ((y - rad) == y0) ||
5089 ((x + rad) == x0) || ((x - rad) == x0))
5091 place_extra_bold(y, x);
5096 /* Find visible outer walls and set to be FEAT_OUTER */
5097 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5098 x0 + rad + 1, y0 + rad + 1);
5100 /* Check to see if there is room for an inner vault */
5101 for (x = x0 - 2; x <= x0 + 2; x++)
5103 for (y = y0 - 2; y <= y0 + 2; y++)
5105 if (!is_floor_bold(y, x))
5107 /* Wall in the way */
5113 if (emptyflag && one_in_(2))
5115 /* Build the vault */
5116 build_small_room(x0, y0);
5118 /* Place a treasure in the vault */
5119 place_object(y0, x0, FALSE, FALSE);
5121 /* Let's guard the treasure well */
5122 vault_monsters(y0, x0, randint0(2) + 3);
5124 /* Traps naturally */
5125 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5131 * Helper function for "trapped monster pit"
5133 static bool vault_aux_trapped_pit(int r_idx)
5135 monster_race *r_ptr = &r_info[r_idx];
5137 /* Validate the monster */
5138 if (!vault_monster_okay(r_idx)) return (FALSE);
5140 /* No wall passing monster */
5141 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5149 * Type 12 -- Trapped monster pits
5151 * A trapped monster pit is a "big" room with a straight corridor in
5152 * which wall opening traps are placed, and with two "inner" rooms
5153 * containing a "collection" of monsters of a given type organized in
5156 * The trapped monster pit appears as shown below, where the actual
5157 * monsters in each location depend on the type of the pit
5159 * #########################
5161 * ####################### #
5162 * #####001123454321100### #
5163 * ###0012234567654322100# #
5164 * ####################### #
5166 * # #######################
5167 * # #0012234567654322100###
5168 * # ###001123454321100#####
5169 * # #######################
5171 * #########################
5173 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5174 * to request 16 "appropriate" monsters, sorting them by level, and using
5175 * the "even" entries in this sorted list for the contents of the pit.
5177 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5178 * which is handled by requiring a specific "breath" attack for all of the
5179 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5180 * be present in many of the dragon pits, if they have the proper breath.
5182 * Note the use of the "get_mon_num_prep()" function, and the special
5183 * "get_mon_num_hook()" restriction function, to prepare the "monster
5184 * allocation table" in such a way as to optimize the selection of
5185 * "appropriate" non-unique monsters for the pit.
5187 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5188 * the pit will be empty, and will not effect the level rating.
5190 * Note that "monster pits" will never contain "unique" monsters.
5192 static void build_type13(int by0, int bx0)
5194 static int placing[][3] = {
5195 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5196 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5197 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5198 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5199 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5200 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5201 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5202 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5203 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5204 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5205 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5206 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5207 {-2, -4, 3}, {-3, -2, 3},
5208 {+2, -4, 3}, {+3, -2, 3},
5209 {-2, +4, 3}, {-3, +2, 3},
5210 {+2, +4, 3}, {+3, +2, 3},
5211 {-2, -3, 4}, {-3, -1, 4},
5212 {+2, -3, 4}, {+3, -1, 4},
5213 {-2, +3, 4}, {-3, +1, 4},
5214 {+2, +3, 4}, {+3, +1, 4},
5215 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5216 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5217 {-2, -1, 6}, {-2, +1, 6},
5218 {+2, -1, 6}, {+2, +1, 6},
5219 {-2, 0, 7}, {+2, 0, 7},
5223 int y, x, y1, x1, y2, x2, xval, yval;
5232 vault_aux_type *n_ptr = pick_vault_type(pit_types, ROOM_PIT);
5234 /* Only in Angband */
5235 if (dungeon_type != 1) return;
5237 /* Try to allocate space for room. */
5238 if (!room_alloc(25, 13, TRUE, by0, bx0, &xval, &yval)) return;
5240 /* No type available */
5243 /* Process a preparation function if necessary */
5244 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5252 /* Fill with inner walls */
5253 for (y = y1 - 1; y <= y2 + 1; y++)
5255 for (x = x1 - 1; x <= x2 + 1; x++)
5257 c_ptr = &cave[y][x];
5258 place_inner_grid(c_ptr);
5259 c_ptr->info |= (CAVE_ROOM);
5263 /* Place the floor area 1 */
5264 for (x = x1 + 3; x <= x2 - 3; x++)
5266 c_ptr = &cave[yval-2][x];
5267 place_floor_grid(c_ptr);
5268 add_cave_info(yval-2, x, CAVE_ICKY);
5270 c_ptr = &cave[yval+2][x];
5271 place_floor_grid(c_ptr);
5272 add_cave_info(yval+2, x, CAVE_ICKY);
5275 /* Place the floor area 2 */
5276 for (x = x1 + 5; x <= x2 - 5; x++)
5278 c_ptr = &cave[yval-3][x];
5279 place_floor_grid(c_ptr);
5280 add_cave_info(yval-3, x, CAVE_ICKY);
5282 c_ptr = &cave[yval+3][x];
5283 place_floor_grid(c_ptr);
5284 add_cave_info(yval+3, x, CAVE_ICKY);
5288 for (x = x1; x <= x2; x++)
5290 c_ptr = &cave[yval][x];
5291 place_floor_grid(c_ptr);
5292 c_ptr = &cave[y1][x];
5293 place_floor_grid(c_ptr);
5294 c_ptr = &cave[y2][x];
5295 place_floor_grid(c_ptr);
5298 /* Place the outer walls */
5299 for (y = y1 - 1; y <= y2 + 1; y++)
5301 c_ptr = &cave[y][x1 - 1];
5302 place_outer_grid(c_ptr);
5303 c_ptr = &cave[y][x2 + 1];
5304 place_outer_grid(c_ptr);
5306 for (x = x1 - 1; x <= x2 + 1; x++)
5308 c_ptr = &cave[y1 - 1][x];
5309 place_outer_grid(c_ptr);
5310 c_ptr = &cave[y2 + 1][x];
5311 place_outer_grid(c_ptr);
5314 /* Random corridor */
5317 for (y = y1; y <= yval; y++)
5319 place_floor_bold(y, x2);
5320 place_solid_bold(y, x1-1);
5322 for (y = yval; y <= y2 + 1; y++)
5324 place_floor_bold(y, x1);
5325 place_solid_bold(y, x2+1);
5330 for (y = yval; y <= y2 + 1; y++)
5332 place_floor_bold(y, x1);
5333 place_solid_bold(y, x2+1);
5335 for (y = y1; y <= yval; y++)
5337 place_floor_bold(y, x2);
5338 place_solid_bold(y, x1-1);
5342 /* Place the wall open trap */
5343 cave[yval][xval].mimic = cave[yval][xval].feat;
5344 cave[yval][xval].feat = FEAT_TRAP_OPEN;
5346 /* Prepare allocation table */
5347 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5349 /* Pick some monster types */
5350 for (i = 0; i < 16; i++)
5352 int r_idx = 0, attempts = 100;
5356 /* Get a (hard) monster type */
5357 r_idx = get_mon_num(dun_level + 0);
5359 /* Decline incorrect alignment */
5360 if (((align < 0) && (r_info[r_idx].flags3 & RF3_GOOD)) ||
5361 ((align > 0) && (r_info[r_idx].flags3 & RF3_EVIL)))
5366 /* Accept this monster */
5370 /* Notice failure */
5371 if (!r_idx || !attempts) return;
5373 /* Note the alignment */
5374 if (r_info[r_idx].flags3 & RF3_GOOD) align++;
5375 else if (r_info[r_idx].flags3 & RF3_EVIL) align--;
5380 /* Sort the entries */
5381 for (i = 0; i < 16 - 1; i++)
5383 /* Sort the entries */
5384 for (j = 0; j < 16 - 1; j++)
5389 int p1 = r_info[what[i1]].level;
5390 int p2 = r_info[what[i2]].level;
5396 what[i1] = what[i2];
5406 msg_format("%s¤Î櫥ԥåÈ", n_ptr->name);
5409 msg_format("Trapped monster pit (%s)", n_ptr->name);
5413 /* Select the entries */
5414 for (i = 0; i < 8; i++)
5416 /* Every other entry */
5417 what[i] = what[i * 2];
5422 msg_print(r_name + r_info[what[i]].name);
5426 /* Increase the level rating */
5429 /* (Sometimes) Cause a "special feeling" (for "Monster Pits") */
5430 if ((dun_level <= 40) && (randint1(dun_level * dun_level + 50) < 300))
5432 good_item_flag = TRUE;
5436 for (i = 0; placing[i][2] >= 0; i++)
5438 y = yval + placing[i][0];
5439 x = xval + placing[i][1];
5440 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5446 * Type 14 -- trapped rooms
5448 * A special trap is placed at center of the room
5450 static void build_type14(int by0, int bx0)
5452 int y, x, y2, x2, yval, xval;
5453 int y1, x1, xsize, ysize;
5460 /* Pick a room size */
5466 xsize = x1 + x2 + 1;
5467 ysize = y1 + y2 + 1;
5469 /* Try to allocate space for room. If fails, exit */
5470 if (!room_alloc(xsize + 2, ysize + 2, FALSE, by0, bx0, &xval, &yval)) return;
5472 /* Choose lite or dark */
5473 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5476 /* Get corner values */
5477 y1 = yval - ysize / 2;
5478 x1 = xval - xsize / 2;
5479 y2 = yval + (ysize - 1) / 2;
5480 x2 = xval + (xsize - 1) / 2;
5483 /* Place a full floor under the room */
5484 for (y = y1 - 1; y <= y2 + 1; y++)
5486 for (x = x1 - 1; x <= x2 + 1; x++)
5488 c_ptr = &cave[y][x];
5489 place_floor_grid(c_ptr);
5490 c_ptr->info |= (CAVE_ROOM);
5491 if (light) c_ptr->info |= (CAVE_GLOW);
5495 /* Walls around the room */
5496 for (y = y1 - 1; y <= y2 + 1; y++)
5498 c_ptr = &cave[y][x1 - 1];
5499 place_outer_grid(c_ptr);
5500 c_ptr = &cave[y][x2 + 1];
5501 place_outer_grid(c_ptr);
5503 for (x = x1 - 1; x <= x2 + 1; x++)
5505 c_ptr = &cave[y1 - 1][x];
5506 place_outer_grid(c_ptr);
5507 c_ptr = &cave[y2 + 1][x];
5508 place_outer_grid(c_ptr);
5511 if (dun_level < 30 + randint1(30))
5512 trap = FEAT_TRAP_PIRANHA;
5514 trap = FEAT_TRAP_ARMAGEDDON;
5516 /* Place a special trap */
5517 cave[yval][xval].mimic = cave[yval][xval].feat;
5518 cave[yval][xval].feat = trap;
5524 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5526 msg_format("Room of %s", f_name + f_info[trap].name);
5533 * Attempt to build a room of the given type at the given block
5535 * Note that we restrict the number of "crowded" rooms to reduce
5536 * the chance of overflowing the monster list during level creation.
5538 bool room_build(int by0, int bx0, int typ)
5540 /* Restrict level */
5541 if ((dun_level < roomdep[typ]) && !ironman_rooms) return (FALSE);
5543 /* Restrict "crowded" rooms */
5544 if ((dun->crowded >= 2) && ((typ == 5) || (typ == 6) || (typ == 13))) return (FALSE);
5549 /* Build an appropriate room */
5550 case 14: build_type14(by0, bx0); break;
5551 case 13: build_type13(by0, bx0); break;
5552 case 12: build_type12(by0, bx0); break;
5553 case 11: build_type11(by0, bx0); break;
5554 case 10: build_type10(by0, bx0); break;
5555 case 9: build_type9(by0, bx0); break;
5556 case 8: build_type8(by0, bx0); break;
5557 case 7: build_type7(by0, bx0); break;
5558 case 6: build_type6(by0, bx0, FALSE); break;
5559 case 5: build_type5(by0, bx0, FALSE); break;
5560 case 4: build_type4(by0, bx0); break;
5561 case 3: build_type3(by0, bx0); break;
5562 case 2: build_type2(by0, bx0); break;
5563 case 1: build_type1(by0, bx0); break;
5566 default: return (FALSE);