3 * @brief ¥À¥ó¥¸¥ç¥ó¥Õ¥í¥¢¤ÎÉô²°À¸À®½èÍý / make rooms. Used by generate.c when creating dungeons.
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen. \n
12 * Room building routines.\n
18 * 4 -- large room with features\n
19 * 5 -- monster nests\n
21 * 7 -- simple vaults\n
22 * 8 -- greater vaults\n
23 * 9 -- fractal caves\n
24 * 10 -- random vaults\n
25 * 11 -- circular rooms\n
27 * 13 -- trapped monster pits\n
28 * 14 -- trapped room\n
30 * 16 -- underground arcade\n
40 * ³ÆÉô²°¥¿¥¤¥×¤ÎÀ¸À®ÈæÄêµÁ
41 *[from SAngband (originally from OAngband)]\n
43 * Table of values that control how many times each type of room will\n
44 * appear. Each type of room has its own row, and each column\n
45 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
46 * value is the minimum depth the room can appear at. -LM-\n
48 * Level 101 and below use the values for level 100.\n
50 * Rooms with lots of monsters or loot may not be generated if the\n
51 * object or monster lists are already nearly full. Rooms will not\n
52 * appear above their minimum depth. Tiny levels will not have space\n
53 * for all the rooms you ask for.\n
55 static room_info_type room_info_normal[ROOM_T_MAX] =
58 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
60 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
61 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
62 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
63 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
64 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
65 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
66 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
67 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
68 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
69 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
70 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
71 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
72 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
73 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
74 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
75 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
79 /*! Éô²°¤ÎÀ¸À®½èÍý½ç / Build rooms in descending order of difficulty. */
80 static byte room_build_order[ROOM_T_MAX] = {
100 * @brief ¸°¤Î¤«¤«¤Ã¤¿¥É¥¢¤òÇÛÃÖ¤¹¤ë
101 * @param y ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎYºÂɸ
102 * @param x ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎXºÂɸ
105 static void place_locked_door(int y, int x)
107 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
109 place_floor_bold(y, x);
113 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
114 cave[y][x].info &= ~(CAVE_FLOOR);
115 delete_monster(y, x);
120 * @brief ±£¤·¥É¥¢¤òÇÛÃÖ¤¹¤ë
121 * @param y ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎYºÂɸ
122 * @param x ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎXºÂɸ
123 * @param type #DOOR_DEFAULT / #DOOR_DOOR / #DOOR_GLASS_DOOR / #DOOR_CURTAIN ¤Î¤¤¤º¤ì¤«
126 static void place_secret_door(int y, int x, int type)
128 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
130 place_floor_bold(y, x);
134 cave_type *c_ptr = &cave[y][x];
136 if (type == DOOR_DEFAULT)
138 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
139 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
140 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
143 /* Create secret door */
144 place_closed_door(y, x, type);
146 if (type != DOOR_CURTAIN)
148 /* Hide by inner wall because this is used in rooms only */
149 c_ptr->mimic = feat_wall_inner;
151 /* Floor type terrain cannot hide a door */
152 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
154 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
156 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
162 c_ptr->info &= ~(CAVE_FLOOR);
163 delete_monster(y, x);
168 * @brief 1¥Þ¥¹¤À¤±¤ÎÉô²°¤òºîÀ®¤·¡¢¾å²¼º¸±¦¤¤¤º¤ì¤«°ì¤Ä¤Ë±£¤·¥É¥¢¤òÇÛÃÖ¤¹¤ë¡£
169 * @param y0 ÇÛÃÖ¤·¤¿¤¤Ãæ¿´¤ÎYºÂɸ
170 * @param x0 ÇÛÃÖ¤·¤¿¤¤Ãæ¿´¤ÎXºÂɸ
172 * This funtion makes a very small room centred at (x0, y0)
173 * This is used in crypts, and random elemental vaults.
175 * Note - this should be used only on allocated regions
176 * within another room.
178 static void build_small_room(int x0, int y0)
182 for (y = y0 - 1; y <= y0 + 1; y++)
184 place_inner_bold(y, x0 - 1);
185 place_inner_bold(y, x0 + 1);
188 for (x = x0 - 1; x <= x0 + 1; x++)
190 place_inner_bold(y0 - 1, x);
191 place_inner_bold(y0 + 1, x);
194 /* Place a secret door on one side */
197 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
198 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
199 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
200 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
203 /* Clear mimic type */
204 cave[y0][x0].mimic = 0;
206 /* Add inner open space */
207 place_floor_bold(y0, x0);
212 * »ØÄêÈϰϤËÄÌÏ©¤¬Ä̤äƤ¤¤ë¤³¤È¤ò³Îǧ¤·¤¿¾å¤Ç¾²¤ÇËä¤á¤ë
213 * This function tunnels around a room if it will cut off part of a cave system.
214 * @param x1 ÈϰϤκ¸Ã¼
215 * @param y1 ÈϰϤξåü
216 * @param x2 ÈϰϤα¦Ã¼
217 * @param y2 ÈϰϤβ¼Ã¼
220 static void check_room_boundary(int x1, int y1, int x2, int y2)
223 bool old_is_floor, new_is_floor;
229 old_is_floor = get_is_floor(x1 - 1, y1);
232 * Count the number of floor-wall boundaries around the room
233 * Note: diagonal squares are ignored since the player can move diagonally
234 * to bypass these if needed.
237 /* Above the top boundary */
238 for (x = x1; x <= x2; x++)
240 new_is_floor = get_is_floor(x, y1 - 1);
242 /* Increment counter if they are different */
243 if (new_is_floor != old_is_floor) count++;
245 old_is_floor = new_is_floor;
249 for (y = y1; y <= y2; y++)
251 new_is_floor = get_is_floor(x2 + 1, y);
253 /* increment counter if they are different */
254 if (new_is_floor != old_is_floor) count++;
256 old_is_floor = new_is_floor;
259 /* Bottom boundary */
260 for (x = x2; x >= x1; x--)
262 new_is_floor = get_is_floor(x, y2 + 1);
264 /* increment counter if they are different */
265 if (new_is_floor != old_is_floor) count++;
267 old_is_floor = new_is_floor;
271 for (y = y2; y >= y1; y--)
273 new_is_floor = get_is_floor(x1 - 1, y);
275 /* increment counter if they are different */
276 if (new_is_floor != old_is_floor) count++;
278 old_is_floor = new_is_floor;
281 /* If all the same, or only one connection exit. */
282 if (count <= 2) return;
285 /* Tunnel around the room so to prevent problems with caves */
286 for (y = y1; y <= y2; y++)
288 for (x = x1; x <= x2; x++)
298 * find_space()¤ÎͽÈ÷½èÍý¤È¤·¤ÆÉô²°¤ÎÀ¸À®¤¬²Äǽ¤«¤òȽÄꤹ¤ë /
299 * Helper function for find_space(). Is this a good location?
300 * @param block_high ÈϰϤι⤵
301 * @param block_wide ÈϰϤÎÉý
302 * @param block_y ÈϰϤξåü
303 * @param block_x ÈϰϤκ¸Ã¼
306 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
308 int by1, bx1, by2, bx2, by, bx;
310 /* Itty-bitty rooms must shift about within their rectangle */
313 if ((blocks_wide == 2) && (block_x % 3) == 2)
317 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
318 else if ((blocks_wide % 3) == 0)
320 /* Must be aligned to the left edge of a 11x33 rectangle. */
321 if ((block_x % 3) != 0)
326 * Big rooms that do not have a width divisible by 3 must be
327 * aligned towards the edge of the dungeon closest to them.
331 /* Shift towards left edge of dungeon. */
332 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
334 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
336 if ((block_x % 3) == 1)
340 /* Shift toward right edge of dungeon. */
343 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
345 if ((block_x % 3) == 1)
353 by2 = block_y + blocks_high;
354 bx2 = block_x + blocks_wide;
356 /* Never run off the screen */
357 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
358 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
360 /* Verify available space */
361 for (by = by1; by < by2; by++)
363 for (bx = bx1; bx < bx2; bx++)
365 if (dun->room_map[by][bx])
372 /* This location is okay */
378 * @brief Éô²°À¸À®¤¬²Äǽ¤Ê¥¹¥Ú¡¼¥¹¤ò³ÎÊݤ¹¤ë / Find a good spot for the next room. -LM-
379 * @param y Éô²°¤ÎÀ¸À®¤¬²Äǽ¤ÊÃæ¿´YºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
380 * @param x Éô²°¤ÎÀ¸À®¤¬²Äǽ¤ÊÃæ¿´XºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
381 * @param height ³ÎÊݤ·¤¿¤¤Îΰè¤Î¹â¤µ
382 * @param width ³ÎÊݤ·¤¿¤¤Îΰè¤ÎÉý
383 * @return ½êÄê¤ÎÈϰϤ¬³ÎÊݤǤ¤¿¾ì¹çTRUE¤òÊÖ¤¹
385 * Find and allocate a free space in the dungeon large enough to hold\n
386 * the room calling this function.\n
388 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
389 * align neatly on the standard screen. Therefore, we make them use\n
390 * blocks in few 11x33 rectangles as possible.\n
392 * Be careful to include the edges of the room in height and width!\n
394 * Return TRUE and values for the center of the room if all went well.\n
395 * Otherwise, return FALSE.\n
397 static bool find_space(int *y, int *x, int height, int width)
399 int candidates, pick;
400 int by, bx, by1, bx1, by2, bx2;
401 int block_y = 0, block_x = 0;
404 /* Find out how many blocks we need. */
405 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
406 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
408 /* There are no way to allocate such huge space */
409 if (dun->row_rooms < blocks_high) return FALSE;
410 if (dun->col_rooms < blocks_wide) return FALSE;
415 /* Count the number of valid places */
416 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
418 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
420 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
422 /* Find a valid place */
435 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
437 /* Choose a random one */
438 pick = randint1(candidates);
441 /* NO_CAVE dungeon (Castle) */
444 /* Always choose the center one */
445 pick = candidates/2 + 1;
448 /* Pick up the choosen location */
449 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
451 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
453 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
457 /* This one is picked? */
468 by2 = block_y + blocks_high;
469 bx2 = block_x + blocks_wide;
472 * It is *extremely* important that the following calculation
473 * be *exactly* correct to prevent memory errors
476 /* Acquire the location of the room */
477 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
478 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
480 /* Save the room location */
481 if (dun->cent_n < CENT_MAX)
483 dun->cent[dun->cent_n].y = *y;
484 dun->cent[dun->cent_n].x = *x;
488 /* Reserve some blocks. */
489 for (by = by1; by < by2; by++)
491 for (bx = bx1; bx < bx2; bx++)
493 dun->room_map[by][bx] = TRUE;
499 * Hack- See if room will cut off a cavern.
501 * If so, fix by tunneling outside the room in such a
502 * way as to connect the caves.
504 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
514 * @brief ¥¿¥¤¥×1¤ÎÉô²°¡ÄÄ̾ï²ÄÊÑĹÊý·Á¤ÎÉô²°¤òÀ¸À®¤¹¤ë / Type 1 -- normal rectangular rooms
517 static bool build_type1(void)
519 int y, x, y2, x2, yval, xval;
520 int y1, x1, xsize, ysize;
526 bool curtain = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
527 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 48 : 512);
529 /* Pick a room size */
538 /* Find and reserve some space in the dungeon. Get center of room. */
539 if (!find_space(&yval, &xval, ysize + 2, xsize + 2))
541 /* Limit to the minimum room size, and retry */
550 /* Find and reserve some space in the dungeon. Get center of room. */
551 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
554 /* Choose lite or dark */
555 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
558 /* Get corner values */
559 y1 = yval - ysize / 2;
560 x1 = xval - xsize / 2;
561 y2 = yval + (ysize - 1) / 2;
562 x2 = xval + (xsize - 1) / 2;
565 /* Place a full floor under the room */
566 for (y = y1 - 1; y <= y2 + 1; y++)
568 for (x = x1 - 1; x <= x2 + 1; x++)
571 place_floor_grid(c_ptr);
572 c_ptr->info |= (CAVE_ROOM);
573 if (light) c_ptr->info |= (CAVE_GLOW);
577 /* Walls around the room */
578 for (y = y1 - 1; y <= y2 + 1; y++)
580 c_ptr = &cave[y][x1 - 1];
581 place_outer_grid(c_ptr);
582 c_ptr = &cave[y][x2 + 1];
583 place_outer_grid(c_ptr);
585 for (x = x1 - 1; x <= x2 + 1; x++)
587 c_ptr = &cave[y1 - 1][x];
588 place_outer_grid(c_ptr);
589 c_ptr = &cave[y2 + 1][x];
590 place_outer_grid(c_ptr);
594 /* Hack -- Occasional curtained room */
595 if (curtain && (y2 - y1 > 2) && (x2 - x1 > 2))
597 for (y = y1; y <= y2; y++)
599 c_ptr = &cave[y][x1];
600 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
601 c_ptr->info &= ~(CAVE_MASK);
602 c_ptr = &cave[y][x2];
603 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
604 c_ptr->info &= ~(CAVE_MASK);
606 for (x = x1; x <= x2; x++)
608 c_ptr = &cave[y1][x];
609 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
610 c_ptr->info &= ~(CAVE_MASK);
611 c_ptr = &cave[y2][x];
612 c_ptr->feat = feat_door[DOOR_CURTAIN].closed;
613 c_ptr->info &= ~(CAVE_MASK);
618 /* Hack -- Occasional pillar room */
621 for (y = y1; y <= y2; y += 2)
623 for (x = x1; x <= x2; x += 2)
626 place_inner_grid(c_ptr);
631 /* Hack -- Occasional room with four pillars */
632 else if (one_in_(20))
634 if ((y1 + 4 < y2) && (x1 + 4 < x2))
636 c_ptr = &cave[y1 + 1][x1 + 1];
637 place_inner_grid(c_ptr);
639 c_ptr = &cave[y1 + 1][x2 - 1];
640 place_inner_grid(c_ptr);
642 c_ptr = &cave[y2 - 1][x1 + 1];
643 place_inner_grid(c_ptr);
645 c_ptr = &cave[y2 - 1][x2 - 1];
646 place_inner_grid(c_ptr);
650 /* Hack -- Occasional ragged-edge room */
651 else if (one_in_(50))
653 for (y = y1 + 2; y <= y2 - 2; y += 2)
655 c_ptr = &cave[y][x1];
656 place_inner_grid(c_ptr);
657 c_ptr = &cave[y][x2];
658 place_inner_grid(c_ptr);
660 for (x = x1 + 2; x <= x2 - 2; x += 2)
662 c_ptr = &cave[y1][x];
663 place_inner_grid(c_ptr);
664 c_ptr = &cave[y2][x];
665 place_inner_grid(c_ptr);
668 /* Hack -- Occasional divided room */
669 else if (one_in_(50))
671 bool curtain2 = (d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
672 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 2 : 128);
674 if (randint1(100) < 50)
676 /* Horizontal wall */
677 for (x = x1; x <= x2; x++)
679 place_inner_bold(yval, x);
680 if (curtain2) cave[yval][x].feat = feat_door[DOOR_CURTAIN].closed;
683 /* Prevent edge of wall from being tunneled */
684 place_solid_bold(yval, x1 - 1);
685 place_solid_bold(yval, x2 + 1);
690 for (y = y1; y <= y2; y++)
692 place_inner_bold(y, xval);
693 if (curtain2) cave[y][xval].feat = feat_door[DOOR_CURTAIN].closed;
696 /* Prevent edge of wall from being tunneled */
697 place_solid_bold(y1 - 1, xval);
698 place_solid_bold(y2 + 1, xval);
701 place_random_door(yval, xval, TRUE);
702 if (curtain2) cave[yval][xval].feat = feat_door[DOOR_CURTAIN].closed;
709 * @brief ¥¿¥¤¥×2¤ÎÉô²°¡ÄÆó½ÅĹÊý·Á¤ÎÉô²°¤òÀ¸À®¤¹¤ë / Type 2 -- Overlapping rectangular rooms
712 static bool build_type2(void)
714 int y, x, xval, yval;
715 int y1a, x1a, y2a, x2a;
716 int y1b, x1b, y2b, x2b;
720 /* Find and reserve some space in the dungeon. Get center of room. */
721 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
723 /* Choose lite or dark */
724 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
726 /* Determine extents of the first room */
727 y1a = yval - randint1(4);
728 y2a = yval + randint1(3);
729 x1a = xval - randint1(11);
730 x2a = xval + randint1(10);
732 /* Determine extents of the second room */
733 y1b = yval - randint1(3);
734 y2b = yval + randint1(4);
735 x1b = xval - randint1(10);
736 x2b = xval + randint1(11);
739 /* Place a full floor for room "a" */
740 for (y = y1a - 1; y <= y2a + 1; y++)
742 for (x = x1a - 1; x <= x2a + 1; x++)
745 place_floor_grid(c_ptr);
746 c_ptr->info |= (CAVE_ROOM);
747 if (light) c_ptr->info |= (CAVE_GLOW);
751 /* Place a full floor for room "b" */
752 for (y = y1b - 1; y <= y2b + 1; y++)
754 for (x = x1b - 1; x <= x2b + 1; x++)
757 place_floor_grid(c_ptr);
758 c_ptr->info |= (CAVE_ROOM);
759 if (light) c_ptr->info |= (CAVE_GLOW);
764 /* Place the walls around room "a" */
765 for (y = y1a - 1; y <= y2a + 1; y++)
767 c_ptr = &cave[y][x1a - 1];
768 place_outer_grid(c_ptr);
769 c_ptr = &cave[y][x2a + 1];
770 place_outer_grid(c_ptr);
772 for (x = x1a - 1; x <= x2a + 1; x++)
774 c_ptr = &cave[y1a - 1][x];
775 place_outer_grid(c_ptr);
776 c_ptr = &cave[y2a + 1][x];
777 place_outer_grid(c_ptr);
780 /* Place the walls around room "b" */
781 for (y = y1b - 1; y <= y2b + 1; y++)
783 c_ptr = &cave[y][x1b - 1];
784 place_outer_grid(c_ptr);
785 c_ptr = &cave[y][x2b + 1];
786 place_outer_grid(c_ptr);
788 for (x = x1b - 1; x <= x2b + 1; x++)
790 c_ptr = &cave[y1b - 1][x];
791 place_outer_grid(c_ptr);
792 c_ptr = &cave[y2b + 1][x];
793 place_outer_grid(c_ptr);
798 /* Replace the floor for room "a" */
799 for (y = y1a; y <= y2a; y++)
801 for (x = x1a; x <= x2a; x++)
804 place_floor_grid(c_ptr);
808 /* Replace the floor for room "b" */
809 for (y = y1b; y <= y2b; y++)
811 for (x = x1b; x <= x2b; x++)
814 place_floor_grid(c_ptr);
824 * @brief ¥¿¥¤¥×2¤ÎÉô²°¡Ä½½»ú·¿¤ÎÉô²°¤òÀ¸À®¤¹¤ë / Type 3 -- Cross shaped rooms
827 * Builds a room at a row, column coordinate\n
829 * Room "a" runs north/south, and Room "b" runs east/east\n
830 * So the "central pillar" runs from x1a, y1b to x2a, y2b.\n
832 * Note that currently, the "center" is always 3x3, but I think that\n
833 * the code below will work (with "bounds checking") for 5x5, or even\n
834 * for unsymetric values like 4x3 or 5x3 or 3x4 or 3x5, or even larger.\n
836 static bool build_type3(void)
838 int y, x, dy, dx, wy, wx;
839 int y1a, x1a, y2a, x2a;
840 int y1b, x1b, y2b, x2b;
846 /* Find and reserve some space in the dungeon. Get center of room. */
847 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
850 /* Choose lite or dark */
851 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
853 /* For now, always 3x3 */
856 /* Pick max vertical size (at most 4) */
857 dy = rand_range(3, 4);
859 /* Pick max horizontal size (at most 15) */
860 dx = rand_range(3, 11);
863 /* Determine extents of the north/south room */
869 /* Determine extents of the east/west room */
876 /* Place a full floor for room "a" */
877 for (y = y1a - 1; y <= y2a + 1; y++)
879 for (x = x1a - 1; x <= x2a + 1; x++)
882 place_floor_grid(c_ptr);
883 c_ptr->info |= (CAVE_ROOM);
884 if (light) c_ptr->info |= (CAVE_GLOW);
888 /* Place a full floor for room "b" */
889 for (y = y1b - 1; y <= y2b + 1; y++)
891 for (x = x1b - 1; x <= x2b + 1; x++)
894 place_floor_grid(c_ptr);
895 c_ptr->info |= (CAVE_ROOM);
896 if (light) c_ptr->info |= (CAVE_GLOW);
901 /* Place the walls around room "a" */
902 for (y = y1a - 1; y <= y2a + 1; y++)
904 c_ptr = &cave[y][x1a - 1];
905 place_outer_grid(c_ptr);
906 c_ptr = &cave[y][x2a + 1];
907 place_outer_grid(c_ptr);
909 for (x = x1a - 1; x <= x2a + 1; x++)
911 c_ptr = &cave[y1a - 1][x];
912 place_outer_grid(c_ptr);
913 c_ptr = &cave[y2a + 1][x];
914 place_outer_grid(c_ptr);
917 /* Place the walls around room "b" */
918 for (y = y1b - 1; y <= y2b + 1; y++)
920 c_ptr = &cave[y][x1b - 1];
921 place_outer_grid(c_ptr);
922 c_ptr = &cave[y][x2b + 1];
923 place_outer_grid(c_ptr);
925 for (x = x1b - 1; x <= x2b + 1; x++)
927 c_ptr = &cave[y1b - 1][x];
928 place_outer_grid(c_ptr);
929 c_ptr = &cave[y2b + 1][x];
930 place_outer_grid(c_ptr);
934 /* Replace the floor for room "a" */
935 for (y = y1a; y <= y2a; y++)
937 for (x = x1a; x <= x2a; x++)
940 place_floor_grid(c_ptr);
944 /* Replace the floor for room "b" */
945 for (y = y1b; y <= y2b; y++)
947 for (x = x1b; x <= x2b; x++)
950 place_floor_grid(c_ptr);
956 /* Special features (3/4) */
959 /* Large solid middle pillar */
962 for (y = y1b; y <= y2b; y++)
964 for (x = x1a; x <= x2a; x++)
967 place_inner_grid(c_ptr);
973 /* Inner treasure vault */
976 /* Build the vault */
977 for (y = y1b; y <= y2b; y++)
979 c_ptr = &cave[y][x1a];
980 place_inner_grid(c_ptr);
981 c_ptr = &cave[y][x2a];
982 place_inner_grid(c_ptr);
984 for (x = x1a; x <= x2a; x++)
986 c_ptr = &cave[y1b][x];
987 place_inner_grid(c_ptr);
988 c_ptr = &cave[y2b][x];
989 place_inner_grid(c_ptr);
992 /* Place a secret door on the inner room */
995 case 0: place_secret_door(y1b, xval, DOOR_DEFAULT); break;
996 case 1: place_secret_door(y2b, xval, DOOR_DEFAULT); break;
997 case 2: place_secret_door(yval, x1a, DOOR_DEFAULT); break;
998 case 3: place_secret_door(yval, x2a, DOOR_DEFAULT); break;
1001 /* Place a treasure in the vault */
1002 place_object(yval, xval, 0L);
1004 /* Let's guard the treasure well */
1005 vault_monsters(yval, xval, randint0(2) + 3);
1007 /* Traps naturally */
1008 vault_traps(yval, xval, 4, 4, randint0(3) + 2);
1013 /* Something else */
1016 /* Occasionally pinch the center shut */
1019 /* Pinch the east/west sides */
1020 for (y = y1b; y <= y2b; y++)
1022 if (y == yval) continue;
1023 c_ptr = &cave[y][x1a - 1];
1024 place_inner_grid(c_ptr);
1025 c_ptr = &cave[y][x2a + 1];
1026 place_inner_grid(c_ptr);
1029 /* Pinch the north/south sides */
1030 for (x = x1a; x <= x2a; x++)
1032 if (x == xval) continue;
1033 c_ptr = &cave[y1b - 1][x];
1034 place_inner_grid(c_ptr);
1035 c_ptr = &cave[y2b + 1][x];
1036 place_inner_grid(c_ptr);
1039 /* Sometimes shut using secret doors */
1042 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1043 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1044 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1046 place_secret_door(yval, x1a - 1, door_type);
1047 place_secret_door(yval, x2a + 1, door_type);
1048 place_secret_door(y1b - 1, xval, door_type);
1049 place_secret_door(y2b + 1, xval, door_type);
1053 /* Occasionally put a "plus" in the center */
1054 else if (one_in_(3))
1056 c_ptr = &cave[yval][xval];
1057 place_inner_grid(c_ptr);
1058 c_ptr = &cave[y1b][xval];
1059 place_inner_grid(c_ptr);
1060 c_ptr = &cave[y2b][xval];
1061 place_inner_grid(c_ptr);
1062 c_ptr = &cave[yval][x1a];
1063 place_inner_grid(c_ptr);
1064 c_ptr = &cave[yval][x2a];
1065 place_inner_grid(c_ptr);
1068 /* Occasionally put a pillar in the center */
1069 else if (one_in_(3))
1071 c_ptr = &cave[yval][xval];
1072 place_inner_grid(c_ptr);
1084 * @brief ¥¿¥¤¥×4¤ÎÉô²°¡Ä¸ÇÄꥵ¥¤¥º¤ÎÆó½Å¹½Â¤Éô²°¤òÀ¸À®¤¹¤ë / Type 4 -- Large room with inner features
1087 * Possible sub-types:\n
1088 * 1 - Just an inner room with one door\n
1089 * 2 - An inner room within an inner room\n
1090 * 3 - An inner room with pillar(s)\n
1091 * 4 - Inner room has a maze\n
1092 * 5 - A set of four inner rooms\n
1094 static bool build_type4(void)
1097 int y2, x2, tmp, yval, xval;
1102 /* Find and reserve some space in the dungeon. Get center of room. */
1103 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
1105 /* Choose lite or dark */
1106 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1114 /* Place a full floor under the room */
1115 for (y = y1 - 1; y <= y2 + 1; y++)
1117 for (x = x1 - 1; x <= x2 + 1; x++)
1119 c_ptr = &cave[y][x];
1120 place_floor_grid(c_ptr);
1121 c_ptr->info |= (CAVE_ROOM);
1122 if (light) c_ptr->info |= (CAVE_GLOW);
1127 for (y = y1 - 1; y <= y2 + 1; y++)
1129 c_ptr = &cave[y][x1 - 1];
1130 place_outer_grid(c_ptr);
1131 c_ptr = &cave[y][x2 + 1];
1132 place_outer_grid(c_ptr);
1134 for (x = x1 - 1; x <= x2 + 1; x++)
1136 c_ptr = &cave[y1 - 1][x];
1137 place_outer_grid(c_ptr);
1138 c_ptr = &cave[y2 + 1][x];
1139 place_outer_grid(c_ptr);
1143 /* The inner room */
1149 /* The inner walls */
1150 for (y = y1 - 1; y <= y2 + 1; y++)
1152 c_ptr = &cave[y][x1 - 1];
1153 place_inner_grid(c_ptr);
1154 c_ptr = &cave[y][x2 + 1];
1155 place_inner_grid(c_ptr);
1157 for (x = x1 - 1; x <= x2 + 1; x++)
1159 c_ptr = &cave[y1 - 1][x];
1160 place_inner_grid(c_ptr);
1161 c_ptr = &cave[y2 + 1][x];
1162 place_inner_grid(c_ptr);
1166 /* Inner room variations */
1167 switch (randint1(5))
1169 /* Just an inner room with a monster */
1172 /* Place a secret door */
1173 switch (randint1(4))
1175 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1176 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1177 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1178 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1181 /* Place a monster in the room */
1182 vault_monsters(yval, xval, 1);
1187 /* Treasure Vault (with a door) */
1190 /* Place a secret door */
1191 switch (randint1(4))
1193 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1194 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1195 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1196 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1199 /* Place another inner room */
1200 for (y = yval - 1; y <= yval + 1; y++)
1202 for (x = xval - 1; x <= xval + 1; x++)
1204 if ((x == xval) && (y == yval)) continue;
1205 c_ptr = &cave[y][x];
1206 place_inner_grid(c_ptr);
1210 /* Place a locked door on the inner room */
1211 switch (randint1(4))
1213 case 1: place_locked_door(yval - 1, xval); break;
1214 case 2: place_locked_door(yval + 1, xval); break;
1215 case 3: place_locked_door(yval, xval - 1); break;
1216 case 4: place_locked_door(yval, xval + 1); break;
1219 /* Monsters to guard the "treasure" */
1220 vault_monsters(yval, xval, randint1(3) + 2);
1223 if (randint0(100) < 80)
1225 place_object(yval, xval, 0L);
1231 place_random_stairs(yval, xval);
1234 /* Traps to protect the treasure */
1235 vault_traps(yval, xval, 4, 10, 2 + randint1(3));
1240 /* Inner pillar(s). */
1243 /* Place a secret door */
1244 switch (randint1(4))
1246 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1247 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1248 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1249 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1252 /* Large Inner Pillar */
1253 for (y = yval - 1; y <= yval + 1; y++)
1255 for (x = xval - 1; x <= xval + 1; x++)
1257 c_ptr = &cave[y][x];
1258 place_inner_grid(c_ptr);
1262 /* Occasionally, two more Large Inner Pillars */
1266 for (y = yval - 1; y <= yval + 1; y++)
1268 for (x = xval - 5 - tmp; x <= xval - 3 - tmp; x++)
1270 c_ptr = &cave[y][x];
1271 place_inner_grid(c_ptr);
1273 for (x = xval + 3 + tmp; x <= xval + 5 + tmp; x++)
1275 c_ptr = &cave[y][x];
1276 place_inner_grid(c_ptr);
1281 /* Occasionally, some Inner rooms */
1284 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1285 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1286 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1288 /* Long horizontal walls */
1289 for (x = xval - 5; x <= xval + 5; x++)
1291 c_ptr = &cave[yval - 1][x];
1292 place_inner_grid(c_ptr);
1293 c_ptr = &cave[yval + 1][x];
1294 place_inner_grid(c_ptr);
1297 /* Close off the left/right edges */
1298 c_ptr = &cave[yval][xval - 5];
1299 place_inner_grid(c_ptr);
1300 c_ptr = &cave[yval][xval + 5];
1301 place_inner_grid(c_ptr);
1303 /* Secret doors (random top/bottom) */
1304 place_secret_door(yval - 3 + (randint1(2) * 2), xval - 3, door_type);
1305 place_secret_door(yval - 3 + (randint1(2) * 2), xval + 3, door_type);
1308 vault_monsters(yval, xval - 2, randint1(2));
1309 vault_monsters(yval, xval + 2, randint1(2));
1312 if (one_in_(3)) place_object(yval, xval - 2, 0L);
1313 if (one_in_(3)) place_object(yval, xval + 2, 0L);
1322 /* Place a secret door */
1323 switch (randint1(4))
1325 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
1326 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
1327 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
1328 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
1331 /* Maze (really a checkerboard) */
1332 for (y = y1; y <= y2; y++)
1334 for (x = x1; x <= x2; x++)
1338 c_ptr = &cave[y][x];
1339 place_inner_grid(c_ptr);
1344 /* Monsters just love mazes. */
1345 vault_monsters(yval, xval - 5, randint1(3));
1346 vault_monsters(yval, xval + 5, randint1(3));
1348 /* Traps make them entertaining. */
1349 vault_traps(yval, xval - 3, 2, 8, randint1(3));
1350 vault_traps(yval, xval + 3, 2, 8, randint1(3));
1352 /* Mazes should have some treasure too. */
1353 vault_objects(yval, xval, 3);
1358 /* Four small rooms. */
1361 int door_type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
1362 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
1363 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
1366 for (y = y1; y <= y2; y++)
1368 c_ptr = &cave[y][xval];
1369 place_inner_grid(c_ptr);
1371 for (x = x1; x <= x2; x++)
1373 c_ptr = &cave[yval][x];
1374 place_inner_grid(c_ptr);
1377 /* Doors into the rooms */
1378 if (randint0(100) < 50)
1380 int i = randint1(10);
1381 place_secret_door(y1 - 1, xval - i, door_type);
1382 place_secret_door(y1 - 1, xval + i, door_type);
1383 place_secret_door(y2 + 1, xval - i, door_type);
1384 place_secret_door(y2 + 1, xval + i, door_type);
1388 int i = randint1(3);
1389 place_secret_door(yval + i, x1 - 1, door_type);
1390 place_secret_door(yval - i, x1 - 1, door_type);
1391 place_secret_door(yval + i, x2 + 1, door_type);
1392 place_secret_door(yval - i, x2 + 1, door_type);
1395 /* Treasure, centered at the center of the cross */
1396 vault_objects(yval, xval, 2 + randint1(2));
1398 /* Gotta have some monsters. */
1399 vault_monsters(yval + 1, xval - 4, randint1(4));
1400 vault_monsters(yval + 1, xval + 4, randint1(4));
1401 vault_monsters(yval - 1, xval - 4, randint1(4));
1402 vault_monsters(yval - 1, xval + 4, randint1(4));
1413 * The following functions are used to determine if the given monster
1414 * is appropriate for inclusion in a monster nest or monster pit or
1417 * None of the pits/nests are allowed to include "unique" monsters.
1422 * Monster validation macro
1424 * Line 1 -- forbid town monsters
1425 * Line 2 -- forbid uniques
1426 * Line 3 -- forbid aquatic monsters
1428 #define vault_monster_okay(I) \
1429 (mon_hook_dungeon(I) && \
1430 !(r_info[I].flags1 & RF1_UNIQUE) && \
1431 !(r_info[I].flags7 & RF7_UNIQUE2) && \
1432 !(r_info[I].flagsr & RFR_RES_ALL) && \
1433 !(r_info[I].flags7 & RF7_AQUATIC))
1436 /* Race index for "monster pit (clone)" */
1437 static int vault_aux_race;
1439 /* Race index for "monster pit (symbol clone)" */
1440 static char vault_aux_char;
1442 /* Breath mask for "monster pit (dragon)" */
1443 static u32b vault_aux_dragon_mask4;
1447 * Helper monster selection function
1449 static bool vault_aux_simple(int r_idx)
1452 return (vault_monster_okay(r_idx));
1457 * Helper function for "monster nest (jelly)"
1459 static bool vault_aux_jelly(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) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1468 /* Also decline evil jellies (like death molds and shoggoths) */
1469 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1471 /* Require icky thing, jelly, mold, or mushroom */
1472 if (!my_strchr("ijm,", r_ptr->d_char)) return (FALSE);
1480 * Helper function for "monster nest (animal)"
1482 static bool vault_aux_animal(int r_idx)
1484 monster_race *r_ptr = &r_info[r_idx];
1486 /* Validate the monster */
1487 if (!vault_monster_okay(r_idx)) return (FALSE);
1489 /* Require "animal" flag */
1490 if (!(r_ptr->flags3 & (RF3_ANIMAL))) return (FALSE);
1498 * Helper function for "monster nest (undead)"
1500 static bool vault_aux_undead(int r_idx)
1502 monster_race *r_ptr = &r_info[r_idx];
1504 /* Validate the monster */
1505 if (!vault_monster_okay(r_idx)) return (FALSE);
1507 /* Require Undead */
1508 if (!(r_ptr->flags3 & (RF3_UNDEAD))) return (FALSE);
1516 * Helper function for "monster nest (chapel)"
1518 static bool vault_aux_chapel_g(int r_idx)
1520 static int chapel_list[] = {
1521 MON_NOV_PRIEST, MON_NOV_PALADIN, MON_NOV_PRIEST_G, MON_NOV_PALADIN_G,
1522 MON_PRIEST, MON_JADE_MONK, MON_IVORY_MONK, MON_ULTRA_PALADIN,
1523 MON_EBONY_MONK, MON_W_KNIGHT, MON_KNI_TEMPLAR, MON_PALADIN,
1528 monster_race *r_ptr = &r_info[r_idx];
1530 /* Validate the monster */
1531 if (!vault_monster_okay(r_idx)) return (FALSE);
1533 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1534 if ((r_idx == MON_A_GOLD) || (r_idx == MON_A_SILVER)) return (FALSE);
1536 /* Require "priest" or Angel */
1538 if (r_ptr->d_char == 'A') return TRUE;
1540 for (i = 0; chapel_list[i]; i++)
1541 if (r_idx == chapel_list[i]) return TRUE;
1548 * Helper function for "monster nest (kennel)"
1550 static bool vault_aux_kennel(int r_idx)
1552 monster_race *r_ptr = &r_info[r_idx];
1554 /* Validate the monster */
1555 if (!vault_monster_okay(r_idx)) return (FALSE);
1557 /* Require a Zephyr Hound or a dog */
1558 if (!my_strchr("CZ", r_ptr->d_char)) return (FALSE);
1566 * Helper function for "monster nest (mimic)"
1568 static bool vault_aux_mimic(int r_idx)
1570 monster_race *r_ptr = &r_info[r_idx];
1572 /* Validate the monster */
1573 if (!vault_monster_okay(r_idx)) return (FALSE);
1576 if (!my_strchr("!$&(/=?[\\|", r_ptr->d_char)) return (FALSE);
1583 * Helper function for "monster nest (clone)"
1585 static bool vault_aux_clone(int r_idx)
1587 /* Validate the monster */
1588 if (!vault_monster_okay(r_idx)) return (FALSE);
1590 return (r_idx == vault_aux_race);
1595 * Helper function for "monster nest (symbol clone)"
1597 static bool vault_aux_symbol_e(int r_idx)
1599 monster_race *r_ptr = &r_info[r_idx];
1601 /* Validate the monster */
1602 if (!vault_monster_okay(r_idx)) return (FALSE);
1604 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1606 if (r_ptr->flags3 & (RF3_GOOD)) return (FALSE);
1608 /* Decline incorrect symbol */
1609 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1617 * Helper function for "monster nest (symbol clone)"
1619 static bool vault_aux_symbol_g(int r_idx)
1621 monster_race *r_ptr = &r_info[r_idx];
1623 /* Validate the monster */
1624 if (!vault_monster_okay(r_idx)) return (FALSE);
1626 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1628 if (r_ptr->flags3 & (RF3_EVIL)) return (FALSE);
1630 /* Decline incorrect symbol */
1631 if (r_ptr->d_char != vault_aux_char) return (FALSE);
1639 * Helper function for "monster pit (orc)"
1641 static bool vault_aux_orc(int r_idx)
1643 monster_race *r_ptr = &r_info[r_idx];
1645 /* Validate the monster */
1646 if (!vault_monster_okay(r_idx)) return (FALSE);
1649 if (!(r_ptr->flags3 & RF3_ORC)) return (FALSE);
1651 /* Decline undead */
1652 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1660 * Helper function for "monster pit (troll)"
1662 static bool vault_aux_troll(int r_idx)
1664 monster_race *r_ptr = &r_info[r_idx];
1666 /* Validate the monster */
1667 if (!vault_monster_okay(r_idx)) return (FALSE);
1670 if (!(r_ptr->flags3 & RF3_TROLL)) return (FALSE);
1672 /* Decline undead */
1673 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1681 * Helper function for "monster pit (giant)"
1683 static bool vault_aux_giant(int r_idx)
1685 monster_race *r_ptr = &r_info[r_idx];
1687 /* Validate the monster */
1688 if (!vault_monster_okay(r_idx)) return (FALSE);
1691 if (!(r_ptr->flags3 & RF3_GIANT)) return (FALSE);
1693 if (r_ptr->flags3 & RF3_GOOD) return (FALSE);
1695 /* Decline undead */
1696 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1704 * Helper function for "monster pit (dragon)"
1706 static bool vault_aux_dragon(int r_idx)
1708 monster_race *r_ptr = &r_info[r_idx];
1710 /* Validate the monster */
1711 if (!vault_monster_okay(r_idx)) return (FALSE);
1713 /* Require dragon */
1714 if (!(r_ptr->flags3 & RF3_DRAGON)) return (FALSE);
1716 /* Hack -- Require correct "breath attack" */
1717 if (r_ptr->flags4 != vault_aux_dragon_mask4) return (FALSE);
1719 /* Decline undead */
1720 if (r_ptr->flags3 & RF3_UNDEAD) return (FALSE);
1728 * Helper function for "monster pit (demon)"
1730 static bool vault_aux_demon(int r_idx)
1732 monster_race *r_ptr = &r_info[r_idx];
1734 /* Validate the monster */
1735 if (!vault_monster_okay(r_idx)) return (FALSE);
1737 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1740 if (!(r_ptr->flags3 & RF3_DEMON)) return (FALSE);
1748 * Helper function for "monster pit (lovecraftian)"
1750 static bool vault_aux_cthulhu(int r_idx)
1752 monster_race *r_ptr = &r_info[r_idx];
1754 /* Validate the monster */
1755 if (!vault_monster_okay(r_idx)) return (FALSE);
1757 if ((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW)) return (FALSE);
1759 /* Require eldritch horror */
1760 if (!(r_ptr->flags2 & (RF2_ELDRITCH_HORROR))) return (FALSE);
1768 * Helper function for "monster pit (clone)"
1770 static void vault_prep_clone(void)
1772 /* Apply the monster restriction */
1773 get_mon_num_prep(vault_aux_simple, NULL);
1775 /* Pick a race to clone */
1776 vault_aux_race = get_mon_num(dun_level + 10);
1778 /* Remove the monster restriction */
1779 get_mon_num_prep(NULL, NULL);
1784 * Helper function for "monster pit (symbol clone)"
1786 static void vault_prep_symbol(void)
1790 /* Apply the monster restriction */
1791 get_mon_num_prep(vault_aux_simple, NULL);
1793 /* Pick a race to clone */
1794 r_idx = get_mon_num(dun_level + 10);
1796 /* Remove the monster restriction */
1797 get_mon_num_prep(NULL, NULL);
1799 /* Extract the symbol */
1800 vault_aux_char = r_info[r_idx].d_char;
1805 * Helper function for "monster pit (dragon)"
1807 static void vault_prep_dragon(void)
1809 /* Pick dragon type */
1810 switch (randint0(6))
1815 /* Restrict dragon breath type */
1816 vault_aux_dragon_mask4 = RF4_BR_ACID;
1825 /* Restrict dragon breath type */
1826 vault_aux_dragon_mask4 = RF4_BR_ELEC;
1835 /* Restrict dragon breath type */
1836 vault_aux_dragon_mask4 = RF4_BR_FIRE;
1845 /* Restrict dragon breath type */
1846 vault_aux_dragon_mask4 = RF4_BR_COLD;
1855 /* Restrict dragon breath type */
1856 vault_aux_dragon_mask4 = RF4_BR_POIS;
1865 /* Restrict dragon breath type */
1866 vault_aux_dragon_mask4 = (RF4_BR_ACID | RF4_BR_ELEC |
1867 RF4_BR_FIRE | RF4_BR_COLD |
1878 * Helper function for "monster pit (dark elf)"
1880 static bool vault_aux_dark_elf(int r_idx)
1883 static int dark_elf_list[] =
1885 MON_D_ELF, MON_D_ELF_MAGE, MON_D_ELF_WARRIOR, MON_D_ELF_PRIEST,
1886 MON_D_ELF_LORD, MON_D_ELF_WARLOCK, MON_D_ELF_DRUID, MON_NIGHTBLADE,
1887 MON_D_ELF_SORC, MON_D_ELF_SHADE, 0,
1890 /* Validate the monster */
1891 if (!vault_monster_okay(r_idx)) return FALSE;
1893 /* Require dark elves */
1894 for (i = 0; dark_elf_list[i]; i++)
1895 if (r_idx == dark_elf_list[i]) return TRUE;
1902 typedef struct vault_aux_type vault_aux_type;
1905 struct vault_aux_type
1908 bool (*hook_func)(int r_idx);
1909 void (*prep_func)(void);
1915 static int pick_vault_type(vault_aux_type *l_ptr, s16b allow_flag_mask)
1917 int tmp, total, count;
1919 vault_aux_type *n_ptr;
1921 /* Calculate the total possibilities */
1922 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1925 if (!n_ptr->name) break;
1927 /* Ignore excessive depth */
1928 if (n_ptr->level > dun_level) continue;
1930 /* Not matched with pit/nest flag */
1931 if (!(allow_flag_mask & (1L << count))) continue;
1933 /* Count this possibility */
1934 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1937 /* Pick a random type */
1938 tmp = randint0(total);
1940 /* Find this type */
1941 for (n_ptr = l_ptr, total = 0, count = 0; TRUE; n_ptr++, count++)
1944 if (!n_ptr->name) break;
1946 /* Ignore excessive depth */
1947 if (n_ptr->level > dun_level) continue;
1949 /* Not matched with pit/nest flag */
1950 if (!(allow_flag_mask & (1L << count))) continue;
1952 /* Count this possibility */
1953 total += n_ptr->chance * MAX_DEPTH / (MIN(dun_level, MAX_DEPTH - 1) - n_ptr->level + 5);
1955 /* Found the type */
1956 if (tmp < total) break;
1959 return n_ptr->name ? count : -1;
1962 static vault_aux_type nest_types[] =
1965 {"¥¯¥í¡¼¥ó", vault_aux_clone, vault_prep_clone, 5, 3},
1966 {"¥¼¥ê¡¼", vault_aux_jelly, NULL, 5, 6},
1967 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1968 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1969 {"¥ß¥ß¥Ã¥¯", vault_aux_mimic, NULL, 30, 4},
1970 {"¶¸µ¤", vault_aux_cthulhu, NULL, 70, 2},
1971 {"¸¤¾®²°", vault_aux_kennel, NULL, 45, 4},
1972 {"ưʪ±à", vault_aux_animal, NULL, 35, 5},
1973 {"¶µ²ñ", vault_aux_chapel_g, NULL, 75, 4},
1974 {"¥¢¥ó¥Ç¥Ã¥É", vault_aux_undead, NULL, 75, 5},
1975 {NULL, NULL, NULL, 0, 0},
1977 {"clone", vault_aux_clone, vault_prep_clone, 5, 3},
1978 {"jelly", vault_aux_jelly, NULL, 5, 6},
1979 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 25, 2},
1980 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 25, 2},
1981 {"mimic", vault_aux_mimic, NULL, 30, 4},
1982 {"lovecraftian", vault_aux_cthulhu, NULL, 70, 2},
1983 {"kennel", vault_aux_kennel, NULL, 45, 4},
1984 {"animal", vault_aux_animal, NULL, 35, 5},
1985 {"chapel", vault_aux_chapel_g, NULL, 75, 4},
1986 {"undead", vault_aux_undead, NULL, 75, 5},
1987 {NULL, NULL, NULL, 0, 0},
1991 static vault_aux_type pit_types[] =
1994 {"¥ª¡¼¥¯", vault_aux_orc, NULL, 5, 6},
1995 {"¥È¥í¥ë", vault_aux_troll, NULL, 20, 6},
1996 {"¥¸¥ã¥¤¥¢¥ó¥È", vault_aux_giant, NULL, 50, 6},
1997 {"¶¸µ¤", vault_aux_cthulhu, NULL, 80, 2},
1998 {"¥·¥ó¥Ü¥ë(Á±)", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
1999 {"¥·¥ó¥Ü¥ë(°)", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
2000 {"¶µ²ñ", vault_aux_chapel_g, NULL, 65, 2},
2001 {"¥É¥é¥´¥ó", vault_aux_dragon, vault_prep_dragon, 70, 6},
2002 {"¥Ç¡¼¥â¥ó", vault_aux_demon, NULL, 80, 6},
2003 {"¥À¡¼¥¯¥¨¥ë¥Õ", vault_aux_dark_elf, NULL, 45, 4},
2004 {NULL, NULL, NULL, 0, 0},
2006 {"orc", vault_aux_orc, NULL, 5, 6},
2007 {"troll", vault_aux_troll, NULL, 20, 6},
2008 {"giant", vault_aux_giant, NULL, 50, 6},
2009 {"lovecraftian", vault_aux_cthulhu, NULL, 80, 2},
2010 {"symbol good", vault_aux_symbol_g, vault_prep_symbol, 70, 1},
2011 {"symbol evil", vault_aux_symbol_e, vault_prep_symbol, 70, 1},
2012 {"chapel", vault_aux_chapel_g, NULL, 65, 2},
2013 {"dragon", vault_aux_dragon, vault_prep_dragon, 70, 6},
2014 {"demon", vault_aux_demon, NULL, 80, 6},
2015 {"dark elf", vault_aux_dark_elf, NULL, 45, 4},
2016 {NULL, NULL, NULL, 0, 0},
2021 /* Nest types code */
2022 #define NEST_TYPE_CLONE 0
2023 #define NEST_TYPE_JELLY 1
2024 #define NEST_TYPE_SYMBOL_GOOD 2
2025 #define NEST_TYPE_SYMBOL_EVIL 3
2026 #define NEST_TYPE_MIMIC 4
2027 #define NEST_TYPE_LOVECRAFTIAN 5
2028 #define NEST_TYPE_KENNEL 6
2029 #define NEST_TYPE_ANIMAL 7
2030 #define NEST_TYPE_CHAPEL 8
2031 #define NEST_TYPE_UNDEAD 9
2033 /* Pit types code */
2034 #define PIT_TYPE_ORC 0
2035 #define PIT_TYPE_TROLL 1
2036 #define PIT_TYPE_GIANT 2
2037 #define PIT_TYPE_LOVECRAFTIAN 3
2038 #define PIT_TYPE_SYMBOL_GOOD 4
2039 #define PIT_TYPE_SYMBOL_EVIL 5
2040 #define PIT_TYPE_CHAPEL 6
2041 #define PIT_TYPE_DRAGON 7
2042 #define PIT_TYPE_DEMON 8
2043 #define PIT_TYPE_DARK_ELF 9
2047 * Hack -- Get the string describing subtype of pit/nest
2048 * Determined in prepare function (some pit/nest only)
2050 static cptr pit_subtype_string(int type, bool nest)
2052 static char inner_buf[256] = "";
2054 inner_buf[0] = '\0'; /* Init string */
2056 if (nest) /* Nests */
2060 case NEST_TYPE_CLONE:
2061 sprintf(inner_buf, "(%s)", r_name + r_info[vault_aux_race].name);
2063 case NEST_TYPE_SYMBOL_GOOD:
2064 case NEST_TYPE_SYMBOL_EVIL:
2065 sprintf(inner_buf, "(%c)", vault_aux_char);
2073 case PIT_TYPE_SYMBOL_GOOD:
2074 case PIT_TYPE_SYMBOL_EVIL:
2075 sprintf(inner_buf, "(%c)", vault_aux_char);
2077 case PIT_TYPE_DRAGON:
2078 switch (vault_aux_dragon_mask4)
2081 case RF4_BR_ACID: strcpy(inner_buf, "(»À)"); break;
2082 case RF4_BR_ELEC: strcpy(inner_buf, "(°ðºÊ)"); break;
2083 case RF4_BR_FIRE: strcpy(inner_buf, "(²Ð±ê)"); break;
2084 case RF4_BR_COLD: strcpy(inner_buf, "(Î䵤)"); break;
2085 case RF4_BR_POIS: strcpy(inner_buf, "(ÆÇ)"); break;
2086 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2087 strcpy(inner_buf, "(Ëü¿§)"); break;
2088 default: strcpy(inner_buf, "(̤ÄêµÁ)"); break;
2090 case RF4_BR_ACID: strcpy(inner_buf, "(acid)"); break;
2091 case RF4_BR_ELEC: strcpy(inner_buf, "(lightning)"); break;
2092 case RF4_BR_FIRE: strcpy(inner_buf, "(fire)"); break;
2093 case RF4_BR_COLD: strcpy(inner_buf, "(frost)"); break;
2094 case RF4_BR_POIS: strcpy(inner_buf, "(poison)"); break;
2095 case (RF4_BR_ACID | RF4_BR_ELEC | RF4_BR_FIRE | RF4_BR_COLD | RF4_BR_POIS):
2096 strcpy(inner_buf, "(multi-hued)"); break;
2097 default: strcpy(inner_buf, "(undefined)"); break;
2108 /* A struct for nest monster information with cheat_hear */
2118 * Comp function for sorting nest monster information
2120 static bool ang_sort_comp_nest_mon_info(vptr u, vptr v, int a, int b)
2122 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2123 int w1 = nest_mon_info[a].r_idx;
2124 int w2 = nest_mon_info[b].r_idx;
2125 monster_race *r1_ptr = &r_info[w1];
2126 monster_race *r2_ptr = &r_info[w2];
2132 /* Extract used info */
2133 z1 = nest_mon_info[a].used;
2134 z2 = nest_mon_info[b].used;
2136 /* Compare used status */
2137 if (z1 < z2) return FALSE;
2138 if (z1 > z2) return TRUE;
2140 /* Compare levels */
2141 if (r1_ptr->level < r2_ptr->level) return TRUE;
2142 if (r1_ptr->level > r2_ptr->level) return FALSE;
2144 /* Compare experience */
2145 if (r1_ptr->mexp < r2_ptr->mexp) return TRUE;
2146 if (r1_ptr->mexp > r2_ptr->mexp) return FALSE;
2148 /* Compare indexes */
2154 * Swap function for sorting nest monster information
2156 static void ang_sort_swap_nest_mon_info(vptr u, vptr v, int a, int b)
2158 nest_mon_info_type *nest_mon_info = (nest_mon_info_type *)u;
2159 nest_mon_info_type holder;
2165 holder = nest_mon_info[a];
2166 nest_mon_info[a] = nest_mon_info[b];
2167 nest_mon_info[b] = holder;
2171 #define NUM_NEST_MON_TYPE 64
2174 * Type 5 -- Monster nests
2176 * A monster nest is a "big" room, with an "inner" room, containing
2177 * a "collection" of monsters of a given type strewn about the room.
2179 * The monsters are chosen from a set of 64 randomly selected monster
2180 * races, to allow the nest creation to fail instead of having "holes".
2182 * Note the use of the "get_mon_num_prep()" function, and the special
2183 * "get_mon_num_hook()" restriction function, to prepare the "monster
2184 * allocation table" in such a way as to optimize the selection of
2185 * "appropriate" non-unique monsters for the nest.
2187 * Note that the "get_mon_num()" function may (rarely) fail, in which
2188 * case the nest will be empty.
2190 * Note that "monster nests" will never contain "unique" monsters.
2192 static bool build_type5(void)
2194 int y, x, y1, x1, y2, x2, xval, yval;
2196 nest_mon_info_type nest_mon_info[NUM_NEST_MON_TYPE];
2202 int cur_nest_type = pick_vault_type(nest_types, d_info[dungeon_type].nest);
2203 vault_aux_type *n_ptr;
2205 /* No type available */
2206 if (cur_nest_type < 0) return FALSE;
2208 n_ptr = &nest_types[cur_nest_type];
2210 /* Process a preparation function if necessary */
2211 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2213 /* Prepare allocation table */
2214 get_mon_num_prep(n_ptr->hook_func, NULL);
2216 align.sub_align = SUB_ALIGN_NEUTRAL;
2218 /* Pick some monster types */
2219 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2221 int r_idx = 0, attempts = 100;
2222 monster_race *r_ptr = NULL;
2226 /* Get a (hard) monster type */
2227 r_idx = get_mon_num(dun_level + 11);
2228 r_ptr = &r_info[r_idx];
2230 /* Decline incorrect alignment */
2231 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2233 /* Accept this monster */
2237 /* Notice failure */
2238 if (!r_idx || !attempts) return FALSE;
2240 /* Note the alignment */
2241 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2242 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2244 nest_mon_info[i].r_idx = r_idx;
2245 nest_mon_info[i].used = FALSE;
2248 /* Find and reserve some space in the dungeon. Get center of room. */
2249 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2257 /* Place the floor area */
2258 for (y = y1 - 1; y <= y2 + 1; y++)
2260 for (x = x1 - 1; x <= x2 + 1; x++)
2262 c_ptr = &cave[y][x];
2263 place_floor_grid(c_ptr);
2264 c_ptr->info |= (CAVE_ROOM);
2268 /* Place the outer walls */
2269 for (y = y1 - 1; y <= y2 + 1; y++)
2271 c_ptr = &cave[y][x1 - 1];
2272 place_outer_grid(c_ptr);
2273 c_ptr = &cave[y][x2 + 1];
2274 place_outer_grid(c_ptr);
2276 for (x = x1 - 1; x <= x2 + 1; x++)
2278 c_ptr = &cave[y1 - 1][x];
2279 place_outer_grid(c_ptr);
2280 c_ptr = &cave[y2 + 1][x];
2281 place_outer_grid(c_ptr);
2285 /* Advance to the center room */
2291 /* The inner walls */
2292 for (y = y1 - 1; y <= y2 + 1; y++)
2294 c_ptr = &cave[y][x1 - 1];
2295 place_inner_grid(c_ptr);
2296 c_ptr = &cave[y][x2 + 1];
2297 place_inner_grid(c_ptr);
2300 for (x = x1 - 1; x <= x2 + 1; x++)
2302 c_ptr = &cave[y1 - 1][x];
2303 place_inner_grid(c_ptr);
2304 c_ptr = &cave[y2 + 1][x];
2305 place_inner_grid(c_ptr);
2307 for (y = y1; y <= y2; y++)
2309 for (x = x1; x <= x2; x++)
2311 add_cave_info(y, x, CAVE_ICKY);
2315 /* Place a secret door */
2316 switch (randint1(4))
2318 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2319 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2320 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2321 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2329 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(nest)(%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2331 msg_format("Monster nest (%s%s)", n_ptr->name, pit_subtype_string(cur_nest_type, TRUE));
2335 /* Place some monsters */
2336 for (y = yval - 2; y <= yval + 2; y++)
2338 for (x = xval - 9; x <= xval + 9; x++)
2342 i = randint0(NUM_NEST_MON_TYPE);
2343 r_idx = nest_mon_info[i].r_idx;
2345 /* Place that "random" monster (no groups) */
2346 (void)place_monster_aux(0, y, x, r_idx, 0L);
2348 nest_mon_info[i].used = TRUE;
2352 if (cheat_room && cheat_hear)
2354 ang_sort_comp = ang_sort_comp_nest_mon_info;
2355 ang_sort_swap = ang_sort_swap_nest_mon_info;
2356 ang_sort(nest_mon_info, NULL, NUM_NEST_MON_TYPE);
2358 /* Dump the entries (prevent multi-printing) */
2359 for (i = 0; i < NUM_NEST_MON_TYPE; i++)
2361 if (!nest_mon_info[i].used) break;
2362 for (; i < NUM_NEST_MON_TYPE - 1; i++)
2364 if (nest_mon_info[i].r_idx != nest_mon_info[i + 1].r_idx) break;
2365 if (!nest_mon_info[i + 1].used) break;
2367 msg_print(r_name + r_info[nest_mon_info[i].r_idx].name);
2376 * Type 6 -- Monster pits
2378 * A monster pit is a "big" room, with an "inner" room, containing
2379 * a "collection" of monsters of a given type organized in the room.
2381 * The inside room in a monster pit appears as shown below, where the
2382 * actual monsters in each location depend on the type of the pit
2384 * #####################
2385 * #0000000000000000000#
2386 * #0112233455543322110#
2387 * #0112233467643322110#
2388 * #0112233455543322110#
2389 * #0000000000000000000#
2390 * #####################
2392 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
2393 * to request 16 "appropriate" monsters, sorting them by level, and using
2394 * the "even" entries in this sorted list for the contents of the pit.
2396 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
2397 * which is handled by requiring a specific "breath" attack for all of the
2398 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
2399 * be present in many of the dragon pits, if they have the proper breath.
2401 * Note the use of the "get_mon_num_prep()" function, and the special
2402 * "get_mon_num_hook()" restriction function, to prepare the "monster
2403 * allocation table" in such a way as to optimize the selection of
2404 * "appropriate" non-unique monsters for the pit.
2406 * Note that the "get_mon_num()" function may (rarely) fail, in which case
2407 * the pit will be empty.
2409 * Note that "monster pits" will never contain "unique" monsters.
2411 static bool build_type6(void)
2413 int y, x, y1, x1, y2, x2, xval, yval;
2422 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
2423 vault_aux_type *n_ptr;
2425 /* No type available */
2426 if (cur_pit_type < 0) return FALSE;
2428 n_ptr = &pit_types[cur_pit_type];
2430 /* Process a preparation function if necessary */
2431 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
2433 /* Prepare allocation table */
2434 get_mon_num_prep(n_ptr->hook_func, NULL);
2436 align.sub_align = SUB_ALIGN_NEUTRAL;
2438 /* Pick some monster types */
2439 for (i = 0; i < 16; i++)
2441 int r_idx = 0, attempts = 100;
2442 monster_race *r_ptr = NULL;
2446 /* Get a (hard) monster type */
2447 r_idx = get_mon_num(dun_level + 11);
2448 r_ptr = &r_info[r_idx];
2450 /* Decline incorrect alignment */
2451 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
2453 /* Accept this monster */
2457 /* Notice failure */
2458 if (!r_idx || !attempts) return FALSE;
2460 /* Note the alignment */
2461 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
2462 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
2467 /* Find and reserve some space in the dungeon. Get center of room. */
2468 if (!find_space(&yval, &xval, 11, 25)) return FALSE;
2476 /* Place the floor area */
2477 for (y = y1 - 1; y <= y2 + 1; y++)
2479 for (x = x1 - 1; x <= x2 + 1; x++)
2481 c_ptr = &cave[y][x];
2482 place_floor_grid(c_ptr);
2483 c_ptr->info |= (CAVE_ROOM);
2487 /* Place the outer walls */
2488 for (y = y1 - 1; y <= y2 + 1; y++)
2490 c_ptr = &cave[y][x1 - 1];
2491 place_outer_grid(c_ptr);
2492 c_ptr = &cave[y][x2 + 1];
2493 place_outer_grid(c_ptr);
2495 for (x = x1 - 1; x <= x2 + 1; x++)
2497 c_ptr = &cave[y1 - 1][x];
2498 place_outer_grid(c_ptr);
2499 c_ptr = &cave[y2 + 1][x];
2500 place_outer_grid(c_ptr);
2503 /* Advance to the center room */
2509 /* The inner walls */
2510 for (y = y1 - 1; y <= y2 + 1; y++)
2512 c_ptr = &cave[y][x1 - 1];
2513 place_inner_grid(c_ptr);
2514 c_ptr = &cave[y][x2 + 1];
2515 place_inner_grid(c_ptr);
2517 for (x = x1 - 1; x <= x2 + 1; x++)
2519 c_ptr = &cave[y1 - 1][x];
2520 place_inner_grid(c_ptr);
2521 c_ptr = &cave[y2 + 1][x];
2522 place_inner_grid(c_ptr);
2524 for (y = y1; y <= y2; y++)
2526 for (x = x1; x <= x2; x++)
2528 add_cave_info(y, x, CAVE_ICKY);
2532 /* Place a secret door */
2533 switch (randint1(4))
2535 case 1: place_secret_door(y1 - 1, xval, DOOR_DEFAULT); break;
2536 case 2: place_secret_door(y2 + 1, xval, DOOR_DEFAULT); break;
2537 case 3: place_secret_door(yval, x1 - 1, DOOR_DEFAULT); break;
2538 case 4: place_secret_door(yval, x2 + 1, DOOR_DEFAULT); break;
2541 /* Sort the entries */
2542 for (i = 0; i < 16 - 1; i++)
2544 /* Sort the entries */
2545 for (j = 0; j < 16 - 1; j++)
2550 int p1 = r_info[what[i1]].level;
2551 int p2 = r_info[what[i2]].level;
2557 what[i1] = what[i2];
2568 msg_format("¥â¥ó¥¹¥¿¡¼Éô²°(pit)(%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2570 msg_format("Monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
2574 /* Select the entries */
2575 for (i = 0; i < 8; i++)
2577 /* Every other entry */
2578 what[i] = what[i * 2];
2583 msg_print(r_name + r_info[what[i]].name);
2587 /* Top and bottom rows */
2588 for (x = xval - 9; x <= xval + 9; x++)
2590 place_monster_aux(0, yval - 2, x, what[0], PM_NO_KAGE);
2591 place_monster_aux(0, yval + 2, x, what[0], PM_NO_KAGE);
2594 /* Middle columns */
2595 for (y = yval - 1; y <= yval + 1; y++)
2597 place_monster_aux(0, y, xval - 9, what[0], PM_NO_KAGE);
2598 place_monster_aux(0, y, xval + 9, what[0], PM_NO_KAGE);
2600 place_monster_aux(0, y, xval - 8, what[1], PM_NO_KAGE);
2601 place_monster_aux(0, y, xval + 8, what[1], PM_NO_KAGE);
2603 place_monster_aux(0, y, xval - 7, what[1], PM_NO_KAGE);
2604 place_monster_aux(0, y, xval + 7, what[1], PM_NO_KAGE);
2606 place_monster_aux(0, y, xval - 6, what[2], PM_NO_KAGE);
2607 place_monster_aux(0, y, xval + 6, what[2], PM_NO_KAGE);
2609 place_monster_aux(0, y, xval - 5, what[2], PM_NO_KAGE);
2610 place_monster_aux(0, y, xval + 5, what[2], PM_NO_KAGE);
2612 place_monster_aux(0, y, xval - 4, what[3], PM_NO_KAGE);
2613 place_monster_aux(0, y, xval + 4, what[3], PM_NO_KAGE);
2615 place_monster_aux(0, y, xval - 3, what[3], PM_NO_KAGE);
2616 place_monster_aux(0, y, xval + 3, what[3], PM_NO_KAGE);
2618 place_monster_aux(0, y, xval - 2, what[4], PM_NO_KAGE);
2619 place_monster_aux(0, y, xval + 2, what[4], PM_NO_KAGE);
2622 /* Above/Below the center monster */
2623 for (x = xval - 1; x <= xval + 1; x++)
2625 place_monster_aux(0, yval + 1, x, what[5], PM_NO_KAGE);
2626 place_monster_aux(0, yval - 1, x, what[5], PM_NO_KAGE);
2629 /* Next to the center monster */
2630 place_monster_aux(0, yval, xval + 1, what[6], PM_NO_KAGE);
2631 place_monster_aux(0, yval, xval - 1, what[6], PM_NO_KAGE);
2633 /* Center monster */
2634 place_monster_aux(0, yval, xval, what[7], PM_NO_KAGE);
2640 /* coordinate translation code */
2641 static void coord_trans(int *x, int *y, int xoffset, int yoffset, int transno)
2647 * transno specifies what transformation is required. (0-7)
2648 * The lower two bits indicate by how much the vault is rotated,
2649 * and the upper bit indicates a reflection.
2650 * This is done by using rotation matrices... however since
2651 * these are mostly zeros for rotations by 90 degrees this can
2652 * be expressed simply in terms of swapping and inverting the
2653 * x and y coordinates.
2655 for (i = 0; i < transno % 4; i++)
2657 /* rotate by 90 degrees */
2665 /* Reflect depending on status of 3rd bit. */
2669 /* Add offsets so vault stays in the first quadrant */
2676 * Hack -- fill in "vault" rooms
2678 static void build_vault(int yval, int xval, int ymax, int xmax, cptr data,
2679 int xoffset, int yoffset, int transno)
2681 int dx, dy, x, y, i, j;
2688 /* Place dungeon features and objects */
2689 for (t = data, dy = 0; dy < ymax; dy++)
2691 for (dx = 0; dx < xmax; dx++, t++)
2693 /* prevent loop counter from being overwritten */
2698 coord_trans(&i, &j, xoffset, yoffset, transno);
2700 /* Extract the location */
2701 if (transno % 2 == 0)
2703 /* no swap of x/y */
2704 x = xval - (xmax / 2) + i;
2705 y = yval - (ymax / 2) + j;
2710 x = xval - (ymax / 2) + i;
2711 y = yval - (xmax / 2) + j;
2714 /* Hack -- skip "non-grids" */
2715 if (*t == ' ') continue;
2717 /* Access the grid */
2718 c_ptr = &cave[y][x];
2720 /* Lay down a floor */
2721 place_floor_grid(c_ptr);
2723 /* Remove any mimic */
2726 /* Part of a vault */
2727 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2729 /* Analyze the grid */
2732 /* Granite wall (outer) */
2734 place_outer_noperm_grid(c_ptr);
2737 /* Granite wall (inner) */
2739 place_inner_grid(c_ptr);
2742 /* Glass wall (inner) */
2744 place_inner_grid(c_ptr);
2745 c_ptr->feat = feat_glass_wall;
2748 /* Permanent wall (inner) */
2750 place_inner_perm_grid(c_ptr);
2753 /* Permanent glass wall (inner) */
2755 place_inner_perm_grid(c_ptr);
2756 c_ptr->feat = feat_permanent_glass_wall;
2761 if (randint0(100) < 75)
2763 place_object(y, x, 0L);
2773 place_secret_door(y, x, DOOR_DEFAULT);
2776 /* Secret glass doors */
2778 place_secret_door(y, x, DOOR_GLASS_DOOR);
2779 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
2784 place_secret_door(y, x, DOOR_CURTAIN);
2792 /* Black market in a dungeon */
2794 set_cave_feat(y, x, feat_black_market);
2795 store_init(NO_TOWN, STORE_BLACK);
2800 set_cave_feat(y, x, feat_pattern_start);
2804 set_cave_feat(y, x, feat_pattern_1);
2808 set_cave_feat(y, x, feat_pattern_2);
2812 set_cave_feat(y, x, feat_pattern_3);
2816 set_cave_feat(y, x, feat_pattern_4);
2820 set_cave_feat(y, x, feat_pattern_end);
2824 set_cave_feat(y, x, feat_pattern_exit);
2828 /* Reward for Pattern walk */
2829 object_level = base_level + 12;
2830 place_object(y, x, AM_GOOD | AM_GREAT);
2831 object_level = base_level;
2838 /* Place dungeon monsters and objects */
2839 for (t = data, dy = 0; dy < ymax; dy++)
2841 for (dx = 0; dx < xmax; dx++, t++)
2843 /* prevent loop counter from being overwritten */
2848 coord_trans(&i, &j, xoffset, yoffset, transno);
2850 /* Extract the location */
2851 if (transno % 2 == 0)
2853 /* no swap of x/y */
2854 x = xval - (xmax / 2) + i;
2855 y = yval - (ymax / 2) + j;
2860 x = xval - (ymax / 2) + i;
2861 y = yval - (xmax / 2) + j;
2864 /* Hack -- skip "non-grids" */
2865 if (*t == ' ') continue;
2867 /* Analyze the symbol */
2873 monster_level = base_level + 5;
2874 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2875 monster_level = base_level;
2879 /* Meaner monster */
2882 monster_level = base_level + 11;
2883 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2884 monster_level = base_level;
2888 /* Meaner monster, plus treasure */
2891 monster_level = base_level + 9;
2892 place_monster(y, x, PM_ALLOW_SLEEP);
2893 monster_level = base_level;
2894 object_level = base_level + 7;
2895 place_object(y, x, AM_GOOD);
2896 object_level = base_level;
2900 /* Nasty monster and treasure */
2903 monster_level = base_level + 40;
2904 place_monster(y, x, PM_ALLOW_SLEEP);
2905 monster_level = base_level;
2906 object_level = base_level + 20;
2907 place_object(y, x, AM_GOOD | AM_GREAT);
2908 object_level = base_level;
2912 /* Monster and/or object */
2915 if (randint0(100) < 50)
2917 monster_level = base_level + 3;
2918 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
2919 monster_level = base_level;
2921 if (randint0(100) < 50)
2923 object_level = base_level + 7;
2924 place_object(y, x, 0L);
2925 object_level = base_level;
2937 * Type 7 -- simple vaults (see "v_info.txt")
2939 static bool build_type7(void)
2945 int xoffset, yoffset;
2948 /* Pick a lesser vault */
2949 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
2951 /* Access a random vault record */
2952 v_ptr = &v_info[randint0(max_v_idx)];
2954 /* Accept the first lesser vault */
2955 if (v_ptr->typ == 7) break;
2958 /* No lesser vault found */
2959 if (dummy >= SAFE_MAX_ATTEMPTS)
2964 msg_print("·Ù¹ð¡ª¾®¤µ¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
2966 msg_print("Warning! Could not place lesser vault!");
2972 /* pick type of transformation (0-7) */
2973 transno = randint0(8);
2975 /* calculate offsets */
2979 /* Some huge vault cannot be ratated to fit in the dungeon */
2980 if (x+2 > cur_hgt-2)
2982 /* Forbid 90 or 270 degree ratation */
2986 coord_trans(&x, &y, 0, 0, transno);
3006 /* Find and reserve some space in the dungeon. Get center of room. */
3007 if (!find_space(&yval, &xval, abs(y), abs(x))) return FALSE;
3015 if (cheat_room) msg_format("¾®¤µ¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3017 if (cheat_room) msg_format("Lesser vault (%s)", v_name + v_ptr->name);
3020 /* Hack -- Build the vault */
3021 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3022 v_text + v_ptr->text, xoffset, yoffset, transno);
3029 * Type 8 -- greater vaults (see "v_info.txt")
3031 static bool build_type8(void)
3038 int xoffset, yoffset;
3040 /* Pick a greater vault */
3041 for (dummy = 0; dummy < SAFE_MAX_ATTEMPTS; dummy++)
3043 /* Access a random vault record */
3044 v_ptr = &v_info[randint0(max_v_idx)];
3046 /* Accept the first greater vault */
3047 if (v_ptr->typ == 8) break;
3050 /* No greater vault found */
3051 if (dummy >= SAFE_MAX_ATTEMPTS)
3056 msg_print("·Ù¹ð¡ªµðÂç¤ÊÃϲ¼¼¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
3058 msg_print("Warning! Could not place greater vault!");
3064 /* pick type of transformation (0-7) */
3065 transno = randint0(8);
3067 /* calculate offsets */
3071 /* Some huge vault cannot be ratated to fit in the dungeon */
3072 if (x+2 > cur_hgt-2)
3074 /* Forbid 90 or 270 degree ratation */
3078 coord_trans(&x, &y, 0, 0, transno);
3099 * Try to allocate space for room. If fails, exit
3101 * Hack -- Prepare a bit larger space (+2, +2) to
3102 * prevent generation of vaults with no-entrance.
3104 /* Find and reserve some space in the dungeon. Get center of room. */
3105 if (!find_space(&yval, &xval, abs(y) + 2, abs(x) + 2)) return FALSE;
3108 v_ptr = &v_info[76 + randint1(3)];
3113 if (cheat_room) msg_format("µðÂç¤ÊÃϲ¼¼¼(%s)", v_name + v_ptr->name);
3115 if (cheat_room) msg_format("Greater vault (%s)", v_name + v_ptr->name);
3118 /* Hack -- Build the vault */
3119 build_vault(yval, xval, v_ptr->hgt, v_ptr->wid,
3120 v_text + v_ptr->text, xoffset, yoffset, transno);
3126 * Structure to hold all "fill" data
3129 typedef struct fill_data_type fill_data_type;
3131 struct fill_data_type
3144 /* features to fill with */
3153 /* number of filled squares */
3157 static fill_data_type fill_data;
3160 /* Store routine for the fractal cave generator */
3161 /* this routine probably should be an inline function or a macro. */
3162 static void store_height(int x, int y, int val)
3164 /* if on boundary set val > cutoff so walls are not as square */
3165 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
3166 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
3167 (val <= fill_data.c1)) val = fill_data.c1 + 1;
3169 /* store the value in height-map format */
3170 cave[y][x].feat = val;
3177 * Explanation of the plasma fractal algorithm:
3179 * A grid of points is created with the properties of a 'height-map'
3180 * This is done by making the corners of the grid have a random value.
3181 * The grid is then subdivided into one with twice the resolution.
3182 * The new points midway between two 'known' points can be calculated
3183 * by taking the average value of the 'known' ones and randomly adding
3184 * or subtracting an amount proportional to the distance between those
3185 * points. The final 'middle' points of the grid are then calculated
3186 * by averaging all four of the originally 'known' corner points. An
3187 * random amount is added or subtracted from this to get a value of the
3188 * height at that point. The scaling factor here is adjusted to the
3189 * slightly larger distance diagonally as compared to orthogonally.
3191 * This is then repeated recursively to fill an entire 'height-map'
3192 * A rectangular map is done the same way, except there are different
3193 * scaling factors along the x and y directions.
3195 * A hack to change the amount of correlation between points is done using
3196 * the grd variable. If the current step size is greater than grd then
3197 * the point will be random, otherwise it will be calculated by the
3198 * above algorithm. This makes a maximum distance at which two points on
3199 * the height map can affect each other.
3201 * How fractal caves are made:
3203 * When the map is complete, a cut-off value is used to create a cave.
3204 * Heights below this value are "floor", and heights above are "wall".
3205 * This also can be used to create lakes, by adding more height levels
3206 * representing shallow and deep water/ lava etc.
3208 * The grd variable affects the width of passages.
3209 * The roug variable affects the roughness of those passages
3211 * The tricky part is making sure the created cave is connected. This
3212 * is done by 'filling' from the inside and only keeping the 'filled'
3213 * floor. Walls bounding the 'filled' floor are also kept. Everything
3214 * else is converted to the normal _extra_.
3219 * Note that this uses the cave.feat array in a very hackish way
3220 * the values are first set to zero, and then each array location
3221 * is used as a "heightmap"
3222 * The heightmap then needs to be converted back into the "feat" format.
3224 * grd=level at which fractal turns on. smaller gives more mazelike caves
3225 * roug=roughness level. 16=normal. higher values make things more convoluted
3226 * small values are good for smooth walls.
3227 * size=length of the side of the square cave system.
3229 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
3231 int xhsize, yhsize, xsize, ysize, maxsize;
3234 * fixed point variables- these are stored as 256 x normal value
3235 * this gives 8 binary places of fractional part + 8 places of normal part
3238 u16b xstep, xhstep, ystep, yhstep;
3239 u16b xstep2, xhstep2, ystep2, yhstep2;
3240 u16b i, j, ii, jj, diagsize, xxsize, yysize;
3242 /* Cache for speed */
3243 u16b xm, xp, ym, yp;
3245 /* redefine size so can change the value if out of range */
3249 /* Paranoia about size of the system of caves */
3250 if (xsize > 254) xsize = 254;
3251 if (xsize < 4) xsize = 4;
3252 if (ysize > 254) ysize = 254;
3253 if (ysize < 4) ysize = 4;
3255 /* get offsets to middle of array */
3259 /* fix rounding problem */
3263 /* get limits of region */
3264 fill_data.xmin = x0 - xhsize;
3265 fill_data.ymin = y0 - yhsize;
3266 fill_data.xmax = x0 + xhsize;
3267 fill_data.ymax = y0 + yhsize;
3269 /* Store cutoff in global for quick access */
3270 fill_data.c1 = cutoff;
3273 * Scale factor for middle points:
3274 * About sqrt(2) * 256 - correct for a square lattice
3275 * approximately correct for everything else.
3279 /* maximum of xsize and ysize */
3280 maxsize = (xsize > ysize) ? xsize : ysize;
3282 /* Clear the section */
3283 for (i = 0; i <= xsize; i++)
3285 for (j = 0; j <= ysize; j++)
3287 /* -1 is a flag for "not done yet" */
3288 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
3289 /* Clear icky flag because may be redoing the cave */
3290 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
3294 /* Boundaries are walls */
3295 cave[fill_data.ymin][fill_data.xmin].feat = maxsize;
3296 cave[fill_data.ymax][fill_data.xmin].feat = maxsize;
3297 cave[fill_data.ymin][fill_data.xmax].feat = maxsize;
3298 cave[fill_data.ymax][fill_data.xmax].feat = maxsize;
3300 /* Set the middle square to be an open area. */
3301 cave[y0][x0].feat = 0;
3303 /* Initialize the step sizes */
3304 xstep = xhstep = xsize * 256;
3305 ystep = yhstep = ysize * 256;
3306 xxsize = xsize * 256;
3307 yysize = ysize * 256;
3310 * Fill in the rectangle with fractal height data -
3311 * like the 'plasma fractal' in fractint.
3313 while ((xhstep > 256) || (yhstep > 256))
3315 /* Halve the step sizes */
3321 /* cache well used values */
3322 xstep2 = xstep / 256;
3323 ystep2 = ystep / 256;
3325 xhstep2 = xhstep / 256;
3326 yhstep2 = yhstep / 256;
3328 /* middle top to bottom. */
3329 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3331 for (j = 0; j <= yysize; j += ystep)
3333 /* cache often used values */
3334 ii = i / 256 + fill_data.xmin;
3335 jj = j / 256 + fill_data.ymin;
3338 if (cave[jj][ii].feat == -1)
3342 /* If greater than 'grid' level then is random */
3343 store_height(ii, jj, randint1(maxsize));
3347 /* Average of left and right points +random bit */
3348 store_height(ii, jj,
3349 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
3350 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
3351 + (randint1(xstep2) - xhstep2) * roug / 16);
3358 /* middle left to right. */
3359 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3361 for (i = 0; i <= xxsize; i += xstep)
3363 /* cache often used values */
3364 ii = i / 256 + fill_data.xmin;
3365 jj = j / 256 + fill_data.ymin;
3368 if (cave[jj][ii].feat == -1)
3372 /* If greater than 'grid' level then is random */
3373 store_height(ii, jj, randint1(maxsize));
3377 /* Average of up and down points +random bit */
3378 store_height(ii, jj,
3379 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
3380 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
3381 + (randint1(ystep2) - yhstep2) * roug / 16);
3388 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
3390 for (j = yhstep; j <= yysize - yhstep; j += ystep)
3392 /* cache often used values */
3393 ii = i / 256 + fill_data.xmin;
3394 jj = j / 256 + fill_data.ymin;
3397 if (cave[jj][ii].feat == -1)
3401 /* If greater than 'grid' level then is random */
3402 store_height(ii, jj, randint1(maxsize));
3406 /* Cache reused values. */
3407 xm = fill_data.xmin + (i - xhstep) / 256;
3408 xp = fill_data.xmin + (i + xhstep) / 256;
3409 ym = fill_data.ymin + (j - yhstep) / 256;
3410 yp = fill_data.ymin + (j + yhstep) / 256;
3413 * Average over all four corners + scale by diagsize to
3414 * reduce the effect of the square grid on the shape of the fractal
3416 store_height(ii, jj,
3417 (cave[ym][xm].feat + cave[yp][xm].feat
3418 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
3419 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
3428 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)
3431 * function used to convert from height-map back to the
3432 * normal angband cave format
3434 if (cave[y][x].info & CAVE_ICKY)
3441 /* Show that have looked at this square */
3442 cave[y][x].info|= (CAVE_ICKY);
3444 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
3445 if (cave[y][x].feat <= c1)
3447 /* 25% of the time use the other tile : it looks better this way */
3448 if (randint1(100) < 75)
3450 cave[y][x].feat = feat1;
3451 cave[y][x].info &= ~(CAVE_MASK);
3452 cave[y][x].info |= info1;
3457 cave[y][x].feat = feat2;
3458 cave[y][x].info &= ~(CAVE_MASK);
3459 cave[y][x].info |= info2;
3463 else if (cave[y][x].feat <= c2)
3465 /* 25% of the time use the other tile : it looks better this way */
3466 if (randint1(100) < 75)
3468 cave[y][x].feat = feat2;
3469 cave[y][x].info &= ~(CAVE_MASK);
3470 cave[y][x].info |= info2;
3475 cave[y][x].feat = feat1;
3476 cave[y][x].info &= ~(CAVE_MASK);
3477 cave[y][x].info |= info1;
3481 else if (cave[y][x].feat <= c3)
3483 cave[y][x].feat = feat3;
3484 cave[y][x].info &= ~(CAVE_MASK);
3485 cave[y][x].info |= info3;
3488 /* if greater than cutoff then is a wall */
3491 place_outer_bold(y, x);
3501 * Quick and nasty fill routine used to find the connected region
3502 * of floor in the middle of the cave
3504 static void cave_fill(byte y, byte x)
3513 /*** Start Grid ***/
3515 /* Enqueue that entry */
3520 /* Now process the queue */
3521 while (flow_head != flow_tail)
3523 /* Extract the next entry */
3524 ty = temp_y[flow_head];
3525 tx = temp_x[flow_head];
3527 /* Forget that entry */
3528 if (++flow_head == TEMP_MAX) flow_head = 0;
3530 /* Add the "children" */
3531 for (d = 0; d < 8; d++)
3533 int old_head = flow_tail;
3535 /* Child location */
3536 j = ty + ddy_ddd[d];
3537 i = tx + ddx_ddd[d];
3539 /* Paranoia Don't leave the cave */
3540 if (!in_bounds(j, i))
3542 /* affect boundary */
3543 cave[j][i].info |= CAVE_ICKY;
3547 /* If within bounds */
3548 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
3549 && (j > fill_data.ymin) && (j < fill_data.ymax))
3551 /* If not a wall or floor done before */
3552 if (hack_isnt_wall(j, i,
3553 fill_data.c1, fill_data.c2, fill_data.c3,
3554 fill_data.feat1, fill_data.feat2, fill_data.feat3,
3555 fill_data.info1, fill_data.info2, fill_data.info3))
3557 /* Enqueue that entry */
3558 temp_y[flow_tail] = j;
3559 temp_x[flow_tail] = i;
3561 /* Advance the queue */
3562 if (++flow_tail == TEMP_MAX) flow_tail = 0;
3564 /* Hack -- Overflow by forgetting new entry */
3565 if (flow_tail == flow_head)
3567 flow_tail = old_head;
3571 /* keep tally of size of cave system */
3572 (fill_data.amount)++;
3578 /* affect boundary */
3579 cave[j][i].info |= CAVE_ICKY;
3586 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
3588 int x, y, i, xhsize, yhsize;
3590 /* offsets to middle from corner */
3596 * select region connected to center of cave system
3597 * this gets rid of alot of isolated one-sqaures that
3598 * can make teleport traps instadeaths...
3602 fill_data.c1 = cutoff;
3606 /* features to fill with */
3607 fill_data.feat1 = floor_type[randint0(100)];
3608 fill_data.feat2 = floor_type[randint0(100)];
3609 fill_data.feat3 = floor_type[randint0(100)];
3611 fill_data.info1 = CAVE_FLOOR;
3612 fill_data.info2 = CAVE_FLOOR;
3613 fill_data.info3 = CAVE_FLOOR;
3615 /* number of filled squares */
3616 fill_data.amount = 0;
3618 cave_fill((byte)y0, (byte)x0);
3620 /* if tally too small, try again */
3621 if (fill_data.amount < 10)
3623 /* too small - clear area and try again later */
3624 for (x = 0; x <= xsize; ++x)
3626 for (y = 0; y <= ysize; ++y)
3628 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3629 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3636 * Do boundarys-check to see if they are next to a filled region
3637 * If not then they are set to normal granite
3638 * If so then they are marked as room walls.
3640 for (i = 0; i <= xsize; ++i)
3643 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3645 /* Next to a 'filled' region? - set to be room walls */
3646 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3647 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
3648 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
3649 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3653 /* set to be normal granite */
3654 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3657 /* bottom boundary */
3658 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
3660 /* Next to a 'filled' region? - set to be room walls */
3661 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3662 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
3663 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
3664 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3668 /* set to be normal granite */
3669 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3672 /* clear the icky flag-don't need it any more */
3673 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3674 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3677 /* Do the left and right boundaries minus the corners (done above) */
3678 for (i = 1; i < ysize; ++i)
3681 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
3684 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3685 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
3686 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
3687 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3692 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3694 /* right boundary */
3695 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
3698 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3699 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
3700 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
3701 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3706 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3709 /* clear icky flag -done with it */
3710 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3711 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3715 /* Do the rest: convert back to the normal format */
3716 for (x = 1; x < xsize; ++x)
3718 for (y = 1; y < ysize; ++y)
3720 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3721 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3723 /* Clear the icky flag in the filled region */
3724 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
3726 /* Set appropriate flags */
3727 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3728 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3730 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
3731 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
3734 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3735 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
3738 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
3743 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3744 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
3749 /* Clear the unconnected regions */
3750 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
3751 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
3757 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
3758 * Extra doors appear inside the system. (Its not very noticeable though.)
3759 * This can be removed by "filling" from the outside in. This allows a separation
3760 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
3761 * The extra effort for what seems to be only a minor thing (even non-existant if you
3762 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
3771 * Driver routine to create fractal cave system
3773 static bool build_type9(void)
3775 int grd, roug, cutoff, xsize, ysize, y0, x0;
3777 bool done, light, room;
3779 /* get size: note 'Evenness'*/
3780 xsize = randint1(22) * 2 + 6;
3781 ysize = randint1(15) * 2 + 6;
3783 /* Find and reserve some space in the dungeon. Get center of room. */
3784 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3786 /* Limit to the minimum room size, and retry */
3790 /* Find and reserve some space in the dungeon. Get center of room. */
3791 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
3797 return build_type1();
3801 light = done = FALSE;
3804 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3808 /* Note: size must be even or there are rounding problems
3809 * This causes the tunnels not to connect properly to the room */
3811 /* testing values for these parameters feel free to adjust */
3812 grd = 1 << (randint0(4));
3814 /* want average of about 16 */
3815 roug = randint1(8) * randint1(4);
3818 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
3819 randint1(xsize / 4) + randint1(ysize / 4);
3822 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
3824 /* Convert to normal format + clean up */
3825 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
3831 #ifdef ALLOW_CAVERNS_AND_LAKES
3833 * Builds a cave system in the center of the dungeon.
3835 void build_cavern(void)
3837 int grd, roug, cutoff, xsize, ysize, x0, y0;
3840 light = done = FALSE;
3841 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
3843 /* Make a cave the size of the dungeon */
3844 xsize = cur_wid - 1;
3845 ysize = cur_hgt - 1;
3849 /* Paranoia: make size even */
3855 /* testing values for these parameters: feel free to adjust */
3856 grd = randint1(4) + 4;
3858 /* want average of about 16 */
3859 roug = randint1(8) * randint1(4);
3865 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
3867 /* Convert to normal format+ clean up */
3868 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
3872 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
3874 int x, y, i, xhsize, yhsize;
3875 int feat1, feat2, feat3;
3877 /* offsets to middle from corner */
3881 /* Get features based on type */
3884 case LAKE_T_LAVA: /* Lava */
3885 feat1 = feat_deep_lava;
3886 feat2 = feat_shallow_lava;
3887 feat3 = floor_type[randint0(100)];
3889 case LAKE_T_WATER: /* Water */
3890 feat1 = feat_deep_water;
3891 feat2 = feat_shallow_water;
3892 feat3 = floor_type[randint0(100)];
3894 case LAKE_T_CAVE: /* Collapsed cave */
3895 feat1 = floor_type[randint0(100)];
3896 feat2 = floor_type[randint0(100)];
3897 feat3 = feat_rubble;
3899 case LAKE_T_EARTH_VAULT: /* Earth vault */
3900 feat1 = feat_rubble;
3901 feat2 = floor_type[randint0(100)];
3902 feat3 = feat_rubble;
3904 case LAKE_T_AIR_VAULT: /* Air vault */
3909 case LAKE_T_WATER_VAULT: /* Water vault */
3910 feat1 = feat_shallow_water;
3911 feat2 = feat_deep_water;
3912 feat3 = feat_shallow_water;
3914 case LAKE_T_FIRE_VAULT: /* Fire Vault */
3915 feat1 = feat_shallow_lava;
3916 feat2 = feat_deep_lava;
3917 feat3 = feat_shallow_lava;
3921 default: return FALSE;
3925 * select region connected to center of cave system
3926 * this gets rid of alot of isolated one-sqaures that
3927 * can make teleport traps instadeaths...
3935 /* features to fill with */
3936 fill_data.feat1 = feat1;
3937 fill_data.feat2 = feat2;
3938 fill_data.feat3 = feat3;
3940 fill_data.info1 = 0;
3941 fill_data.info2 = 0;
3942 fill_data.info3 = 0;
3944 /* number of filled squares */
3945 fill_data.amount = 0;
3947 /* select region connected to center of cave system
3948 * this gets rid of alot of isolated one-sqaures that
3949 * can make teleport traps instadeaths... */
3950 cave_fill((byte)y0, (byte)x0);
3952 /* if tally too small, try again */
3953 if (fill_data.amount < 10)
3955 /* too small -clear area and try again later */
3956 for (x = 0; x <= xsize; ++x)
3958 for (y = 0; y <= ysize; ++y)
3960 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
3961 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
3967 /* Do boundarys- set to normal granite */
3968 for (i = 0; i <= xsize; ++i)
3970 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
3971 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
3973 /* clear the icky flag-don't need it any more */
3974 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3975 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
3978 /* Do the left and right boundaries minus the corners (done above) */
3980 for (i = 1; i < ysize; ++i)
3982 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
3983 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
3985 /* clear icky flag -done with it */
3986 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
3987 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
3991 /* Do the rest: convert back to the normal format */
3992 for (x = 1; x < xsize; ++x)
3994 for (y = 1; y < ysize; ++y)
3996 /* Fill unconnected regions with granite */
3997 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
3998 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
3999 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
4001 /* turn off icky flag (no longer needed.) */
4002 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
4005 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
4007 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
4017 * makes a lake/collapsed cave system in the center of the dungeon
4019 void build_lake(int type)
4021 int grd, roug, xsize, ysize, x0, y0;
4025 /* paranoia - exit if lake type out of range. */
4026 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
4028 msg_format("Invalid lake type (%d)", type);
4032 /* Make the size of the dungeon */
4033 xsize = cur_wid - 1;
4034 ysize = cur_hgt - 1;
4038 /* Paranoia: make size even */
4044 /* testing values for these parameters: feel free to adjust */
4045 grd = randint1(3) + 4;
4047 /* want average of about 16 */
4048 roug = randint1(8) * randint1(4);
4050 /* Make up size of various componants */
4054 /* Deep water/lava */
4055 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
4057 /* Shallow boundary */
4061 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
4063 /* Convert to normal format+ clean up */
4064 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
4067 #endif /* ALLOW_CAVERNS_AND_LAKES */
4071 * Routine used by the random vault creators to add a door to a location
4072 * Note that range checking has to be done in the calling routine.
4074 * The doors must be INSIDE the allocated region.
4076 static void add_door(int x, int y)
4078 /* Need to have a wall in the center square */
4079 if (!is_outer_bold(y, x)) return;
4086 * where x=don't care
4090 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
4091 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
4094 place_secret_door(y, x, DOOR_DEFAULT);
4096 /* set boundarys so don't get wide doors */
4097 place_solid_bold(y, x - 1);
4098 place_solid_bold(y, x + 1);
4107 * where x = don't care
4110 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
4111 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
4114 place_secret_door(y, x, DOOR_DEFAULT);
4116 /* set boundarys so don't get wide doors */
4117 place_solid_bold(y - 1, x);
4118 place_solid_bold(y + 1, x);
4124 * Routine that fills the empty areas of a room with treasure and monsters.
4126 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
4128 int x, y, cx, cy, size;
4131 /* center of room:*/
4135 /* Rough measure of size of vault= sum of lengths of sides */
4136 size = abs(x2 - x1) + abs(y2 - y1);
4138 for (x = x1; x <= x2; x++)
4140 for (y = y1; y <= y2; y++)
4142 /* Thing added based on distance to center of vault
4143 * Difficulty is 1-easy to 10-hard */
4144 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
4146 /* hack- empty square part of the time */
4147 if ((randint1(100) - difficulty * 3) > 50) value = 20;
4149 /* if floor, shallow water and lava */
4150 if (is_floor_bold(y, x) ||
4151 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
4153 /* The smaller 'value' is, the better the stuff */
4156 /* Meanest monster + treasure */
4157 monster_level = base_level + 40;
4158 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4159 monster_level = base_level;
4160 object_level = base_level + 20;
4161 place_object(y, x, AM_GOOD);
4162 object_level = base_level;
4166 /* Mean monster +treasure */
4167 monster_level = base_level + 20;
4168 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4169 monster_level = base_level;
4170 object_level = base_level + 10;
4171 place_object(y, x, AM_GOOD);
4172 object_level = base_level;
4174 else if (value < 10)
4177 monster_level = base_level + 9;
4178 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4179 monster_level = base_level;
4181 else if (value < 17)
4183 /* Intentional Blank space */
4186 * (Want some of the vault to be empty
4187 * so have room for group monsters.
4188 * This is used in the hack above to lower
4189 * the density of stuff in the vault.)
4192 else if (value < 23)
4194 /* Object or trap */
4195 if (randint0(100) < 25)
4197 place_object(y, x, 0L);
4204 else if (value < 30)
4206 /* Monster and trap */
4207 monster_level = base_level + 5;
4208 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4209 monster_level = base_level;
4212 else if (value < 40)
4214 /* Monster or object */
4215 if (randint0(100) < 50)
4217 monster_level = base_level + 3;
4218 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4219 monster_level = base_level;
4221 if (randint0(100) < 50)
4223 object_level = base_level + 7;
4224 place_object(y, x, 0L);
4225 object_level = base_level;
4228 else if (value < 50)
4237 /* 20% monster, 40% trap, 20% object, 20% blank space */
4238 if (randint0(100) < 20)
4240 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4242 else if (randint0(100) < 50)
4246 else if (randint0(100) < 50)
4248 place_object(y, x, 0L);
4259 * This function creates a random vault that looks like a collection of bubbles.
4260 * It works by getting a set of coordinates that represent the center of each
4261 * bubble. The entire room is made by seeing which bubble center is closest. If
4262 * two centers are equidistant then the square is a wall, otherwise it is a floor.
4263 * The only exception is for squares really near a center, these are always floor.
4264 * (It looks better than without this check.)
4266 * Note: If two centers are on the same point then this algorithm will create a
4267 * blank bubble filled with walls. - This is prevented from happening.
4269 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
4271 #define BUBBLENUM 10 /* number of bubbles */
4273 /* array of center points of bubbles */
4274 coord center[BUBBLENUM];
4277 u16b min1, min2, temp;
4280 /* Offset from center to top left hand corner */
4281 int xhsize = xsize / 2;
4282 int yhsize = ysize / 2;
4285 if (cheat_room) msg_print("Bubble Vault");
4287 /* Allocate center of bubbles */
4288 center[0].x = (byte)randint1(xsize - 3) + 1;
4289 center[0].y = (byte)randint1(ysize - 3) + 1;
4291 for (i = 1; i < BUBBLENUM; i++)
4295 /* get center and check to see if it is unique */
4300 x = randint1(xsize - 3) + 1;
4301 y = randint1(ysize - 3) + 1;
4303 for (j = 0; j < i; j++)
4305 /* rough test to see if there is an overlap */
4306 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
4315 /* Top and bottom boundaries */
4316 for (i = 0; i < xsize; i++)
4318 int x = x0 - xhsize + i;
4320 place_outer_noperm_bold(y0 - yhsize + 0, x);
4321 cave[y0 - yhsize + 0][x].info |= (CAVE_ROOM | CAVE_ICKY);
4322 place_outer_noperm_bold(y0 - yhsize + ysize - 1, x);
4323 cave[y0 - yhsize + ysize - 1][x].info |= (CAVE_ROOM | CAVE_ICKY);
4326 /* Left and right boundaries */
4327 for (i = 1; i < ysize - 1; i++)
4329 int y = y0 - yhsize + i;
4331 place_outer_noperm_bold(y, x0 - xhsize + 0);
4332 cave[y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
4333 place_outer_noperm_bold(y, x0 - xhsize + xsize - 1);
4334 cave[y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
4337 /* Fill in middle with bubbles */
4338 for (x = 1; x < xsize - 1; x++)
4340 for (y = 1; y < ysize - 1; y++)
4342 /* Get distances to two closest centers */
4345 min1 = distance(x, y, center[0].x, center[0].y);
4346 min2 = distance(x, y, center[1].x, center[1].y);
4350 /* swap if in wrong order */
4357 for (i = 2; i < BUBBLENUM; i++)
4359 temp = distance(x, y, center[i].x, center[i].y);
4367 else if (temp < min2)
4369 /* second smallest */
4373 if (((min2 - min1) <= 2) && (!(min1 < 3)))
4375 /* Boundary at midpoint+ not at inner region of bubble */
4376 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
4380 /* middle of a bubble */
4381 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
4384 /* clean up rest of flags */
4385 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
4389 /* Try to add some random doors */
4390 for (i = 0; i < 500; i++)
4392 x = randint1(xsize - 3) - xhsize + x0 + 1;
4393 y = randint1(ysize - 3) - yhsize + y0 + 1;
4397 /* Fill with monsters and treasure, low difficulty */
4398 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
4403 * Overlay a rectangular room given its bounds
4404 * This routine is used by build_room_vault
4405 * The area inside the walls is not touched:
4406 * only granite is removed- normal walls stay
4408 static void build_room(int x1, int x2, int y1, int y2)
4410 int x, y, i, xsize, ysize, temp;
4412 /* Check if rectangle has no width */
4413 if ((x1 == x2) || (y1 == y2)) return;
4418 /* Swap boundaries if in wrong order */
4426 /* Swap boundaries if in wrong order */
4432 /* get total widths */
4437 /* Top and bottom boundaries */
4438 for (i = 0; i <= xsize; i++)
4440 place_outer_noperm_bold(y1, x1 + i);
4441 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4442 place_outer_noperm_bold(y2, x1 + i);
4443 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
4446 /* Left and right boundaries */
4447 for (i = 1; i < ysize; i++)
4449 place_outer_noperm_bold(y1 + i, x1);
4450 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
4451 place_outer_noperm_bold(y1 + i, x2);
4452 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
4456 for (x = 1; x < xsize; x++)
4458 for (y = 1; y < ysize; y++)
4460 if (is_extra_bold(y1+y, x1+x))
4462 /* clear the untouched region */
4463 place_floor_bold(y1 + y, x1 + x);
4464 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4468 /* make it a room- but don't touch */
4469 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
4476 /* Create a random vault that looks like a collection of overlapping rooms */
4478 static void build_room_vault(int x0, int y0, int xsize, int ysize)
4480 int i, x1, x2, y1, y2, xhsize, yhsize;
4482 /* get offset from center */
4486 if (cheat_room) msg_print("Room Vault");
4488 /* fill area so don't get problems with arena levels */
4489 for (x1 = 0; x1 < xsize; x1++)
4491 int x = x0 - xhsize + x1;
4493 for (y1 = 0; y1 < ysize; y1++)
4495 int y = y0 - yhsize + y1;
4497 place_extra_bold(y, x);
4498 cave[y][x].info &= (~CAVE_ICKY);
4502 /* add ten random rooms */
4503 for (i = 0; i < 10; i++)
4505 x1 = randint1(xhsize) * 2 + x0 - xhsize;
4506 x2 = randint1(xhsize) * 2 + x0 - xhsize;
4507 y1 = randint1(yhsize) * 2 + y0 - yhsize;
4508 y2 = randint1(yhsize) * 2 + y0 - yhsize;
4509 build_room(x1, x2, y1, y2);
4512 /* Add some random doors */
4513 for (i = 0; i < 500; i++)
4515 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
4516 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
4520 /* Fill with monsters and treasure, high difficulty */
4521 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
4525 /* Create a random vault out of a fractal cave */
4526 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
4528 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
4529 bool done, light, room;
4531 /* round to make sizes even */
4537 if (cheat_room) msg_print("Cave Vault");
4539 light = done = FALSE;
4544 /* testing values for these parameters feel free to adjust */
4545 grd = 1 << randint0(4);
4547 /* want average of about 16 */
4548 roug = randint1(8) * randint1(4);
4551 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
4552 randint1(xsize / 4) + randint1(ysize / 4);
4555 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
4557 /* Convert to normal format+ clean up */
4558 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
4561 /* Set icky flag because is a vault */
4562 for (x = 0; x <= xsize; x++)
4564 for (y = 0; y <= ysize; y++)
4566 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
4570 /* Fill with monsters and treasure, low difficulty */
4571 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
4575 * maze vault -- rectangular labyrinthine rooms
4577 * maze vault uses two routines:
4578 * r_visit - a recursive routine that builds the labyrinth
4579 * build_maze_vault - a driver routine that calls r_visit and adds
4580 * monsters, traps and treasure
4582 * The labyrinth is built by creating a spanning tree of a graph.
4583 * The graph vertices are at
4584 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
4585 * and the edges are the vertical and horizontal nearest neighbors.
4587 * The spanning tree is created by performing a suitably randomized
4588 * depth-first traversal of the graph. The only adjustable parameter
4589 * is the randint0(3) below; it governs the relative density of
4590 * twists and turns in the labyrinth: smaller number, more twists.
4592 static void r_visit(int y1, int x1, int y2, int x2,
4593 int node, int dir, int *visited)
4595 int i, j, m, n, temp, x, y, adj[4];
4597 /* dimensions of vertex array */
4598 m = (x2 - x1) / 2 + 1;
4599 n = (y2 - y1) / 2 + 1;
4601 /* mark node visited and set it to a floor */
4603 x = 2 * (node % m) + x1;
4604 y = 2 * (node / m) + y1;
4605 place_floor_bold(y, x);
4607 /* setup order of adjacent node visits */
4610 /* pick a random ordering */
4611 for (i = 0; i < 4; i++)
4613 for (i = 0; i < 4; i++)
4624 /* pick a random ordering with dir first */
4626 for (i = 1; i < 4; i++)
4628 for (i = 1; i < 4; i++)
4630 j = 1 + randint0(3);
4637 for (i = 0; i < 4; i++)
4642 /* (0,+) - check for bottom boundary */
4643 if ((node / m < n - 1) && (visited[node + m] == 0))
4645 place_floor_bold(y + 1, x);
4646 r_visit(y1, x1, y2, x2, node + m, dir, visited);
4650 /* (0,-) - check for top boundary */
4651 if ((node / m > 0) && (visited[node - m] == 0))
4653 place_floor_bold(y - 1, x);
4654 r_visit(y1, x1, y2, x2, node - m, dir, visited);
4658 /* (+,0) - check for right boundary */
4659 if ((node % m < m - 1) && (visited[node + 1] == 0))
4661 place_floor_bold(y, x + 1);
4662 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
4666 /* (-,0) - check for left boundary */
4667 if ((node % m > 0) && (visited[node - 1] == 0))
4669 place_floor_bold(y, x - 1);
4670 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
4677 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
4681 int m, n, num_vertices, *visited;
4686 if (cheat_room && is_vault) msg_print("Maze Vault");
4688 /* Choose lite or dark */
4689 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
4691 /* Pick a random room size - randomized by calling routine */
4700 /* generate the room */
4701 for (y = y1 - 1; y <= y2 + 1; y++)
4703 for (x = x1 - 1; x <= x2 + 1; x++)
4705 c_ptr = &cave[y][x];
4706 c_ptr->info |= CAVE_ROOM;
4707 if (is_vault) c_ptr->info |= CAVE_ICKY;
4708 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
4710 place_outer_grid(c_ptr);
4714 place_extra_grid(c_ptr);
4718 place_inner_grid(c_ptr);
4720 if (light) c_ptr->info |= (CAVE_GLOW);
4724 /* dimensions of vertex array */
4727 num_vertices = m * n;
4729 /* initialize array of visited vertices */
4730 C_MAKE(visited, num_vertices, int);
4732 /* traverse the graph to create a spaning tree, pick a random root */
4733 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4735 /* Fill with monsters and treasure, low difficulty */
4736 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
4738 C_KILL(visited, num_vertices, int);
4742 /* Build a "mini" checkerboard vault
4744 * This is done by making a permanent wall maze and setting
4745 * the diagonal sqaures of the checker board to be granite.
4746 * The vault has two entrances on opposite sides to guarantee
4747 * a way to get in even if the vault abuts a side of the dungeon.
4749 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
4752 int y1, x1, y2, x2, y, x, total;
4753 int m, n, num_vertices;
4756 if (cheat_room) msg_print("Mini Checker Board Vault");
4758 /* Pick a random room size */
4768 /* generate the room */
4769 for (x = x1 - 2; x <= x2 + 2; x++)
4771 if (!in_bounds(y1-2,x)) break;
4773 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4775 place_outer_noperm_bold(y1-2, x);
4778 for (x = x1 - 2; x <= x2 + 2; x++)
4780 if (!in_bounds(y2+2,x)) break;
4782 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
4784 place_outer_noperm_bold(y2+2, x);
4787 for (y = y1 - 2; y <= y2 + 2; y++)
4789 if (!in_bounds(y,x1-2)) break;
4791 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
4793 place_outer_noperm_bold(y, x1-2);
4796 for (y = y1 - 2; y <= y2 + 2; y++)
4798 if (!in_bounds(y,x2+2)) break;
4800 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
4802 place_outer_noperm_bold(y, x2+2);
4805 for (y = y1 - 1; y <= y2 + 1; y++)
4807 for (x = x1 - 1; x <= x2 + 1; x++)
4809 cave_type *c_ptr = &cave[y][x];
4811 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
4813 /* Permanent walls */
4814 place_inner_perm_grid(c_ptr);
4819 /* dimensions of vertex array */
4822 num_vertices = m * n;
4824 /* initialize array of visited vertices */
4825 C_MAKE(visited, num_vertices, int);
4827 /* traverse the graph to create a spannng tree, pick a random root */
4828 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
4830 /* Make it look like a checker board vault */
4831 for (x = x1; x <= x2; x++)
4833 for (y = y1; y <= y2; y++)
4835 total = x - x1 + y - y1;
4836 /* If total is odd- and is a floor then make a wall */
4837 if ((total % 2 == 1) && is_floor_bold(y, x))
4839 place_inner_bold(y, x);
4844 /* Make a couple of entrances */
4847 /* left and right */
4848 y = randint1(dy) + dy / 2;
4849 place_inner_bold(y1 + y, x1 - 1);
4850 place_inner_bold(y1 + y, x2 + 1);
4854 /* top and bottom */
4855 x = randint1(dx) + dx / 2;
4856 place_inner_bold(y1 - 1, x1 + x);
4857 place_inner_bold(y2 + 1, x1 + x);
4860 /* Fill with monsters and treasure, highest difficulty */
4861 fill_treasure(x1, x2, y1, y2, 10);
4863 C_KILL(visited, num_vertices, int);
4867 /* Build a town/ castle by using a recursive algorithm.
4868 * Basically divide each region in a probalistic way to create
4869 * smaller regions. When the regions get too small stop.
4871 * The power variable is a measure of how well defended a region is.
4872 * This alters the possible choices.
4874 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
4880 /* Temp variables */
4886 if ((power < 3) && (xsize > 12) && (ysize > 12))
4888 /* Need outside wall +keep */
4895 /* Make rooms + subdivide */
4896 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
4902 choice = randint1(2) + 1;
4907 /* Mostly subdivide */
4908 choice = randint1(3) + 1;
4912 /* Based on the choice made above, do something */
4920 /* top and bottom */
4921 for (x = x1; x <= x2; x++)
4923 place_outer_bold(y1, x);
4924 place_outer_bold(y2, x);
4927 /* left and right */
4928 for (y = y1 + 1; y < y2; y++)
4930 place_outer_bold(y, x1);
4931 place_outer_bold(y, x2);
4934 /* Make a couple of entrances */
4937 /* left and right */
4938 y = randint1(ysize) + y1;
4939 place_floor_bold(y, x1);
4940 place_floor_bold(y, x2);
4944 /* top and bottom */
4945 x = randint1(xsize) + x1;
4946 place_floor_bold(y1, x);
4947 place_floor_bold(y2, x);
4950 /* Select size of keep */
4951 t1 = randint1(ysize / 3) + y1;
4952 t2 = y2 - randint1(ysize / 3);
4953 t3 = randint1(xsize / 3) + x1;
4954 t4 = x2 - randint1(xsize / 3);
4956 /* Do outside areas */
4958 /* Above and below keep */
4959 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
4960 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
4962 /* Left and right of keep */
4963 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
4964 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
4966 /* Make the keep itself: */
4979 /* Try to build a room */
4980 if ((xsize < 3) || (ysize < 3))
4982 for (y = y1; y < y2; y++)
4984 for (x = x1; x < x2; x++)
4986 place_inner_bold(y, x);
4994 /* Make outside walls */
4995 /* top and bottom */
4996 for (x = x1 + 1; x <= x2 - 1; x++)
4998 place_inner_bold(y1 + 1, x);
4999 place_inner_bold(y2 - 1, x);
5002 /* left and right */
5003 for (y = y1 + 1; y <= y2 - 1; y++)
5005 place_inner_bold(y, x1 + 1);
5006 place_inner_bold(y, x2 - 1);
5010 y = randint1(ysize - 3) + y1 + 1;
5015 place_floor_bold(y, x1 + 1);
5020 place_floor_bold(y, x2 - 1);
5023 /* Build the room */
5024 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
5029 /* Try and divide vertically */
5033 for (y = y1; y < y2; y++)
5035 for (x = x1; x < x2; x++)
5037 place_inner_bold(y, x);
5043 t1 = randint1(xsize - 2) + x1 + 1;
5044 build_recursive_room(x1, y1, t1, y2, power - 2);
5045 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
5050 /* Try and divide horizontally */
5054 for (y = y1; y < y2; y++)
5056 for (x = x1; x < x2; x++)
5058 place_inner_bold(y, x);
5064 t1 = randint1(ysize - 2) + y1 + 1;
5065 build_recursive_room(x1, y1, x2, t1, power - 2);
5066 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
5073 /* Build a castle */
5075 /* Driver routine: clear the region and call the recursive
5078 *This makes a vault that looks like a castle/ city in the dungeon.
5080 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
5086 /* Pick a random room size */
5095 if (cheat_room) msg_print("Castle Vault");
5097 /* generate the room */
5098 for (y = y1 - 1; y <= y2 + 1; y++)
5100 for (x = x1 - 1; x <= x2 + 1; x++)
5102 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
5103 /* Make everything a floor */
5104 place_floor_bold(y, x);
5108 /* Make the castle */
5109 build_recursive_room(x1, y1, x2, y2, randint1(5));
5111 /* Fill with monsters and treasure, low difficulty */
5112 fill_treasure(x1, x2, y1, y2, randint1(3));
5117 * Add outer wall to a floored region
5118 * Note: no range checking is done so must be inside dungeon
5119 * This routine also stomps on doors
5121 static void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
5124 feature_type *f_ptr;
5127 if (!in_bounds(y, x)) return;
5129 c_ptr = &cave[y][x];
5131 /* hack- check to see if square has been visited before
5132 * if so, then exit (use room flag to do this) */
5133 if (c_ptr->info & CAVE_ROOM) return;
5136 c_ptr->info |= CAVE_ROOM;
5138 f_ptr = &f_info[c_ptr->feat];
5140 if (is_floor_bold(y, x))
5142 for (i = -1; i <= 1; i++)
5144 for (j = -1; j <= 1; j++)
5146 if ((x + i >= x1) && (x + i <= x2) &&
5147 (y + j >= y1) && (y + j <= y2))
5149 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
5150 if (light) c_ptr->info |= CAVE_GLOW;
5155 else if (is_extra_bold(y, x))
5157 /* Set bounding walls */
5158 place_outer_bold(y, x);
5159 if (light) c_ptr->info |= CAVE_GLOW;
5161 else if (permanent_wall(f_ptr))
5163 /* Set bounding walls */
5164 if (light) c_ptr->info |= CAVE_GLOW;
5170 * Hacked distance formula - gives the 'wrong' answer.
5171 * Used to build crypts
5173 static int dist2(int x1, int y1, int x2, int y2,
5174 int h1, int h2, int h3, int h4)
5180 /* Basically this works by taking the normal pythagorean formula
5181 * and using an expansion to express this in a way without the
5182 * square root. This approximate formula is then perturbed to give
5183 * the distorted results. (I found this by making a mistake when I was
5184 * trying to fix the circular rooms.)
5187 /* h1-h4 are constants that describe the metric */
5188 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
5189 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
5190 return (((dx + dy) * 128) / 181 +
5191 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
5192 /* 128/181 is approx. 1/sqrt(2) */
5197 * Build target vault.
5198 * This is made by two concentric "crypts" with perpendicular
5199 * walls creating the cross-hairs.
5201 static void build_target_vault(int x0, int y0, int xsize, int ysize)
5205 /* Make a random metric */
5207 h1 = randint1(32) - 16;
5210 h4 = randint1(32) - 16;
5212 if (cheat_room) msg_print("Target Vault");
5214 /* work out outer radius */
5225 for (x = x0 - rad; x <= x0 + rad; x++)
5227 for (y = y0 - rad; y <= y0 + rad; y++)
5229 /* clear room flag */
5230 cave[y][x].info &= ~(CAVE_ROOM);
5232 /* Vault - so is "icky" */
5233 cave[y][x].info |= CAVE_ICKY;
5235 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5237 /* inside- so is floor */
5238 place_floor_bold(y, x);
5242 /* make granite outside so arena works */
5243 place_extra_bold(y, x);
5246 /* proper boundary for arena */
5247 if (((y + rad) == y0) || ((y - rad) == y0) ||
5248 ((x + rad) == x0) || ((x - rad) == x0))
5250 place_extra_bold(y, x);
5255 /* Find visible outer walls and set to be FEAT_OUTER */
5256 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
5257 x0 + rad + 1, y0 + rad + 1);
5259 /* Add inner wall */
5260 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
5262 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
5264 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
5266 /* Make an internal wall */
5267 place_inner_bold(y, x);
5272 /* Add perpendicular walls */
5273 for (x = x0 - rad; x <= x0 + rad; x++)
5275 place_inner_bold(y0, x);
5278 for (y = y0 - rad; y <= y0 + rad; y++)
5280 place_inner_bold(y, x0);
5283 /* Make inner vault */
5284 for (y = y0 - 1; y <= y0 + 1; y++)
5286 place_inner_bold(y, x0 - 1);
5287 place_inner_bold(y, x0 + 1);
5289 for (x = x0 - 1; x <= x0 + 1; x++)
5291 place_inner_bold(y0 - 1, x);
5292 place_inner_bold(y0 + 1, x);
5295 place_floor_bold(y0, x0);
5298 /* Add doors to vault */
5299 /* get two distances so can place doors relative to centre */
5300 x = (rad - 2) / 4 + 1;
5303 add_door(x0 + x, y0);
5304 add_door(x0 + y, y0);
5305 add_door(x0 - x, y0);
5306 add_door(x0 - y, y0);
5307 add_door(x0, y0 + x);
5308 add_door(x0, y0 + y);
5309 add_door(x0, y0 - x);
5310 add_door(x0, y0 - y);
5312 /* Fill with stuff - medium difficulty */
5313 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
5317 #ifdef ALLOW_CAVERNS_AND_LAKES
5319 * This routine uses a modified version of the lake code to make a
5320 * distribution of some terrain type over the vault. This type
5321 * depends on the dungeon depth.
5323 * Miniture rooms are then scattered across the vault.
5325 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
5330 int xsize, ysize, xhsize, yhsize, x, y, i;
5334 if (cheat_room) msg_print("Elemental Vault");
5336 /* round to make sizes even */
5344 /* Earth vault (Rubble) */
5345 type = LAKE_T_EARTH_VAULT;
5347 else if (dun_level < 50)
5349 /* Air vault (Trees) */
5350 type = LAKE_T_AIR_VAULT;
5352 else if (dun_level < 75)
5354 /* Water vault (shallow water) */
5355 type = LAKE_T_WATER_VAULT;
5359 /* Fire vault (shallow lava) */
5360 type = LAKE_T_FIRE_VAULT;
5365 /* testing values for these parameters: feel free to adjust */
5366 grd = 1 << (randint0(3));
5368 /* want average of about 16 */
5369 roug = randint1(8) * randint1(4);
5371 /* Make up size of various componants */
5375 /* Deep water/lava */
5376 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
5378 /* Shallow boundary */
5382 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
5384 /* Convert to normal format+ clean up */
5385 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
5388 /* Set icky flag because is a vault */
5389 for (x = 0; x <= xsize; x++)
5391 for (y = 0; y <= ysize; y++)
5393 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
5397 /* make a few rooms in the vault */
5398 for (i = 1; i <= (xsize * ysize) / 50; i++)
5400 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
5401 y0 + randint0(ysize - 4) - ysize / 2 + 2);
5404 /* Fill with monsters and treasure, low difficulty */
5405 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
5406 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
5408 #endif /* ALLOW_CAVERNS_AND_LAKES */
5414 static bool build_type10(void)
5416 int y0, x0, xsize, ysize, vtype;
5419 /* big enough to look good, small enough to be fairly common. */
5420 xsize = randint1(22) + 22;
5421 ysize = randint1(11) + 11;
5423 /* Find and reserve some space in the dungeon. Get center of room. */
5424 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
5426 /* Select type of vault */
5427 #ifdef ALLOW_CAVERNS_AND_LAKES
5430 vtype = randint1(15);
5432 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5433 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
5434 #else /* ALLOW_CAVERNS_AND_LAKES */
5437 vtype = randint1(7);
5439 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
5440 ((vtype == 1) || (vtype == 3)));
5441 #endif /* ALLOW_CAVERNS_AND_LAKES */
5445 /* Build an appropriate room */
5446 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
5447 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
5448 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
5449 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
5450 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
5451 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
5452 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
5453 #ifdef ALLOW_CAVERNS_AND_LAKES
5454 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
5455 #endif /* ALLOW_CAVERNS_AND_LAKES */
5456 /* I know how to add a few more... give me some time. */
5459 default: return FALSE;
5467 * Build an vertical oval room.
5468 * For every grid in the possible square, check the distance.
5469 * If it's less than the radius, make it a room square.
5471 * When done fill from the inside to find the walls,
5473 static bool build_type11(void)
5475 int rad, x, y, x0, y0;
5478 /* Occasional light */
5479 if ((randint1(dun_level) <= 15) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5483 /* Find and reserve some space in the dungeon. Get center of room. */
5484 if (!find_space(&y0, &x0, rad * 2 + 1, rad * 2 + 1)) return FALSE;
5486 /* Make circular floor */
5487 for (x = x0 - rad; x <= x0 + rad; x++)
5489 for (y = y0 - rad; y <= y0 + rad; y++)
5491 if (distance(y0, x0, y, x) <= rad - 1)
5493 /* inside- so is floor */
5494 place_floor_bold(y, x);
5496 else if (distance(y0, x0, y, x) <= rad + 1)
5498 /* make granite outside so arena works */
5499 place_extra_bold(y, x);
5504 /* Find visible outer walls and set to be FEAT_OUTER */
5505 add_outer_wall(x0, y0, light, x0 - rad, y0 - rad, x0 + rad, y0 + rad);
5513 * For every grid in the possible square, check the (fake) distance.
5514 * If it's less than the radius, make it a room square.
5516 * When done fill from the inside to find the walls,
5518 static bool build_type12(void)
5520 int rad, x, y, x0, y0;
5522 bool emptyflag = TRUE;
5524 /* Make a random metric */
5526 h1 = randint1(32) - 16;
5529 h4 = randint1(32) - 16;
5531 /* Occasional light */
5532 if ((randint1(dun_level) <= 5) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
5536 /* Find and reserve some space in the dungeon. Get center of room. */
5537 if (!find_space(&y0, &x0, rad * 2 + 3, rad * 2 + 3)) return FALSE;
5540 for (x = x0 - rad; x <= x0 + rad; x++)
5542 for (y = y0 - rad; y <= y0 + rad; y++)
5544 /* clear room flag */
5545 cave[y][x].info &= ~(CAVE_ROOM);
5547 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
5549 /* inside - so is floor */
5550 place_floor_bold(y, x);
5552 else if (distance(y0, x0, y, x) < 3)
5554 place_floor_bold(y, x);
5558 /* make granite outside so arena works */
5559 place_extra_bold(y, x);
5562 /* proper boundary for arena */
5563 if (((y + rad) == y0) || ((y - rad) == y0) ||
5564 ((x + rad) == x0) || ((x - rad) == x0))
5566 place_extra_bold(y, x);
5571 /* Find visible outer walls and set to be FEAT_OUTER */
5572 add_outer_wall(x0, y0, light, x0 - rad - 1, y0 - rad - 1,
5573 x0 + rad + 1, y0 + rad + 1);
5575 /* Check to see if there is room for an inner vault */
5576 for (x = x0 - 2; x <= x0 + 2; x++)
5578 for (y = y0 - 2; y <= y0 + 2; y++)
5580 if (!is_floor_bold(y, x))
5582 /* Wall in the way */
5588 if (emptyflag && one_in_(2))
5590 /* Build the vault */
5591 build_small_room(x0, y0);
5593 /* Place a treasure in the vault */
5594 place_object(y0, x0, 0L);
5596 /* Let's guard the treasure well */
5597 vault_monsters(y0, x0, randint0(2) + 3);
5599 /* Traps naturally */
5600 vault_traps(y0, x0, 4, 4, randint0(3) + 2);
5608 * Helper function for "trapped monster pit"
5610 static bool vault_aux_trapped_pit(int r_idx)
5612 monster_race *r_ptr = &r_info[r_idx];
5614 /* Validate the monster */
5615 if (!vault_monster_okay(r_idx)) return (FALSE);
5617 /* No wall passing monster */
5618 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return (FALSE);
5626 * Type 13 -- Trapped monster pits
5628 * A trapped monster pit is a "big" room with a straight corridor in
5629 * which wall opening traps are placed, and with two "inner" rooms
5630 * containing a "collection" of monsters of a given type organized in
5633 * The trapped monster pit appears as shown below, where the actual
5634 * monsters in each location depend on the type of the pit
5636 * #########################
5638 * ####################### #
5639 * #####001123454321100### #
5640 * ###0012234567654322100# #
5641 * ####################### #
5643 * # #######################
5644 * # #0012234567654322100###
5645 * # ###001123454321100#####
5646 * # #######################
5648 * #########################
5650 * Note that the monsters in the pit are now chosen by using "get_mon_num()"
5651 * to request 16 "appropriate" monsters, sorting them by level, and using
5652 * the "even" entries in this sorted list for the contents of the pit.
5654 * Hack -- all of the "dragons" in a "dragon" pit must be the same "color",
5655 * which is handled by requiring a specific "breath" attack for all of the
5656 * dragons. This may include "multi-hued" breath. Note that "wyrms" may
5657 * be present in many of the dragon pits, if they have the proper breath.
5659 * Note the use of the "get_mon_num_prep()" function, and the special
5660 * "get_mon_num_hook()" restriction function, to prepare the "monster
5661 * allocation table" in such a way as to optimize the selection of
5662 * "appropriate" non-unique monsters for the pit.
5664 * Note that the "get_mon_num()" function may (rarely) fail, in which case
5665 * the pit will be empty.
5667 * Note that "monster pits" will never contain "unique" monsters.
5669 static bool build_type13(void)
5671 static int placing[][3] = {
5672 {-2, -9, 0}, {-2, -8, 0}, {-3, -7, 0}, {-3, -6, 0},
5673 {+2, -9, 0}, {+2, -8, 0}, {+3, -7, 0}, {+3, -6, 0},
5674 {-2, +9, 0}, {-2, +8, 0}, {-3, +7, 0}, {-3, +6, 0},
5675 {+2, +9, 0}, {+2, +8, 0}, {+3, +7, 0}, {+3, +6, 0},
5676 {-2, -7, 1}, {-3, -5, 1}, {-3, -4, 1},
5677 {+2, -7, 1}, {+3, -5, 1}, {+3, -4, 1},
5678 {-2, +7, 1}, {-3, +5, 1}, {-3, +4, 1},
5679 {+2, +7, 1}, {+3, +5, 1}, {+3, +4, 1},
5680 {-2, -6, 2}, {-2, -5, 2}, {-3, -3, 2},
5681 {+2, -6, 2}, {+2, -5, 2}, {+3, -3, 2},
5682 {-2, +6, 2}, {-2, +5, 2}, {-3, +3, 2},
5683 {+2, +6, 2}, {+2, +5, 2}, {+3, +3, 2},
5684 {-2, -4, 3}, {-3, -2, 3},
5685 {+2, -4, 3}, {+3, -2, 3},
5686 {-2, +4, 3}, {-3, +2, 3},
5687 {+2, +4, 3}, {+3, +2, 3},
5688 {-2, -3, 4}, {-3, -1, 4},
5689 {+2, -3, 4}, {+3, -1, 4},
5690 {-2, +3, 4}, {-3, +1, 4},
5691 {+2, +3, 4}, {+3, +1, 4},
5692 {-2, -2, 5}, {-3, 0, 5}, {-2, +2, 5},
5693 {+2, -2, 5}, {+3, 0, 5}, {+2, +2, 5},
5694 {-2, -1, 6}, {-2, +1, 6},
5695 {+2, -1, 6}, {+2, +1, 6},
5696 {-2, 0, 7}, {+2, 0, 7},
5700 int y, x, y1, x1, y2, x2, xval, yval;
5709 int cur_pit_type = pick_vault_type(pit_types, d_info[dungeon_type].pit);
5710 vault_aux_type *n_ptr;
5712 /* Only in Angband */
5713 if (dungeon_type != DUNGEON_ANGBAND) return FALSE;
5715 /* No type available */
5716 if (cur_pit_type < 0) return FALSE;
5718 n_ptr = &pit_types[cur_pit_type];
5720 /* Process a preparation function if necessary */
5721 if (n_ptr->prep_func) (*(n_ptr->prep_func))();
5723 /* Prepare allocation table */
5724 get_mon_num_prep(n_ptr->hook_func, vault_aux_trapped_pit);
5726 align.sub_align = SUB_ALIGN_NEUTRAL;
5728 /* Pick some monster types */
5729 for (i = 0; i < 16; i++)
5731 int r_idx = 0, attempts = 100;
5732 monster_race *r_ptr = NULL;
5736 /* Get a (hard) monster type */
5737 r_idx = get_mon_num(dun_level + 0);
5738 r_ptr = &r_info[r_idx];
5740 /* Decline incorrect alignment */
5741 if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue;
5743 /* Accept this monster */
5747 /* Notice failure */
5748 if (!r_idx || !attempts) return FALSE;
5750 /* Note the alignment */
5751 if (r_ptr->flags3 & RF3_EVIL) align.sub_align |= SUB_ALIGN_EVIL;
5752 if (r_ptr->flags3 & RF3_GOOD) align.sub_align |= SUB_ALIGN_GOOD;
5757 /* Find and reserve some space in the dungeon. Get center of room. */
5758 if (!find_space(&yval, &xval, 13, 25)) return FALSE;
5766 /* Fill with inner walls */
5767 for (y = y1 - 1; y <= y2 + 1; y++)
5769 for (x = x1 - 1; x <= x2 + 1; x++)
5771 c_ptr = &cave[y][x];
5772 place_inner_grid(c_ptr);
5773 c_ptr->info |= (CAVE_ROOM);
5777 /* Place the floor area 1 */
5778 for (x = x1 + 3; x <= x2 - 3; x++)
5780 c_ptr = &cave[yval-2][x];
5781 place_floor_grid(c_ptr);
5782 add_cave_info(yval-2, x, CAVE_ICKY);
5784 c_ptr = &cave[yval+2][x];
5785 place_floor_grid(c_ptr);
5786 add_cave_info(yval+2, x, CAVE_ICKY);
5789 /* Place the floor area 2 */
5790 for (x = x1 + 5; x <= x2 - 5; x++)
5792 c_ptr = &cave[yval-3][x];
5793 place_floor_grid(c_ptr);
5794 add_cave_info(yval-3, x, CAVE_ICKY);
5796 c_ptr = &cave[yval+3][x];
5797 place_floor_grid(c_ptr);
5798 add_cave_info(yval+3, x, CAVE_ICKY);
5802 for (x = x1; x <= x2; x++)
5804 c_ptr = &cave[yval][x];
5805 place_floor_grid(c_ptr);
5806 c_ptr = &cave[y1][x];
5807 place_floor_grid(c_ptr);
5808 c_ptr = &cave[y2][x];
5809 place_floor_grid(c_ptr);
5812 /* Place the outer walls */
5813 for (y = y1 - 1; y <= y2 + 1; y++)
5815 c_ptr = &cave[y][x1 - 1];
5816 place_outer_grid(c_ptr);
5817 c_ptr = &cave[y][x2 + 1];
5818 place_outer_grid(c_ptr);
5820 for (x = x1 - 1; x <= x2 + 1; x++)
5822 c_ptr = &cave[y1 - 1][x];
5823 place_outer_grid(c_ptr);
5824 c_ptr = &cave[y2 + 1][x];
5825 place_outer_grid(c_ptr);
5828 /* Random corridor */
5831 for (y = y1; y <= yval; y++)
5833 place_floor_bold(y, x2);
5834 place_solid_bold(y, x1-1);
5836 for (y = yval; y <= y2 + 1; y++)
5838 place_floor_bold(y, x1);
5839 place_solid_bold(y, x2+1);
5844 for (y = yval; y <= y2 + 1; y++)
5846 place_floor_bold(y, x1);
5847 place_solid_bold(y, x2+1);
5849 for (y = y1; y <= yval; y++)
5851 place_floor_bold(y, x2);
5852 place_solid_bold(y, x1-1);
5856 /* Place the wall open trap */
5857 cave[yval][xval].mimic = cave[yval][xval].feat;
5858 cave[yval][xval].feat = feat_trap_open;
5860 /* Sort the entries */
5861 for (i = 0; i < 16 - 1; i++)
5863 /* Sort the entries */
5864 for (j = 0; j < 16 - 1; j++)
5869 int p1 = r_info[what[i1]].level;
5870 int p2 = r_info[what[i2]].level;
5876 what[i1] = what[i2];
5887 msg_format("%s%s¤Î櫥ԥåÈ", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5889 msg_format("Trapped monster pit (%s%s)", n_ptr->name, pit_subtype_string(cur_pit_type, FALSE));
5893 /* Select the entries */
5894 for (i = 0; i < 8; i++)
5896 /* Every other entry */
5897 what[i] = what[i * 2];
5902 msg_print(r_name + r_info[what[i]].name);
5906 for (i = 0; placing[i][2] >= 0; i++)
5908 y = yval + placing[i][0];
5909 x = xval + placing[i][1];
5910 place_monster_aux(0, y, x, what[placing[i][2]], PM_NO_KAGE);
5918 * Type 14 -- trapped rooms
5920 * A special trap is placed at center of the room
5922 static bool build_type14(void)
5924 int y, x, y2, x2, yval, xval;
5925 int y1, x1, xsize, ysize;
5932 /* Pick a room size */
5938 xsize = x1 + x2 + 1;
5939 ysize = y1 + y2 + 1;
5941 /* Find and reserve some space in the dungeon. Get center of room. */
5942 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
5944 /* Choose lite or dark */
5945 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
5948 /* Get corner values */
5949 y1 = yval - ysize / 2;
5950 x1 = xval - xsize / 2;
5951 y2 = yval + (ysize - 1) / 2;
5952 x2 = xval + (xsize - 1) / 2;
5955 /* Place a full floor under the room */
5956 for (y = y1 - 1; y <= y2 + 1; y++)
5958 for (x = x1 - 1; x <= x2 + 1; x++)
5960 c_ptr = &cave[y][x];
5961 place_floor_grid(c_ptr);
5962 c_ptr->info |= (CAVE_ROOM);
5963 if (light) c_ptr->info |= (CAVE_GLOW);
5967 /* Walls around the room */
5968 for (y = y1 - 1; y <= y2 + 1; y++)
5970 c_ptr = &cave[y][x1 - 1];
5971 place_outer_grid(c_ptr);
5972 c_ptr = &cave[y][x2 + 1];
5973 place_outer_grid(c_ptr);
5975 for (x = x1 - 1; x <= x2 + 1; x++)
5977 c_ptr = &cave[y1 - 1][x];
5978 place_outer_grid(c_ptr);
5979 c_ptr = &cave[y2 + 1][x];
5980 place_outer_grid(c_ptr);
5983 if (dun_level < 30 + randint1(30))
5984 trap = feat_trap_piranha;
5986 trap = feat_trap_armageddon;
5988 /* Place a special trap */
5989 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
5990 c_ptr->mimic = c_ptr->feat;
5997 msg_format("%s¤ÎÉô²°", f_name + f_info[trap].name);
5999 msg_format("Room of %s", f_name + f_info[trap].name);
6008 * Helper function for "glass room"
6010 static bool vault_aux_lite(int r_idx)
6012 monster_race *r_ptr = &r_info[r_idx];
6014 /* Validate the monster */
6015 if (!vault_monster_okay(r_idx)) return FALSE;
6017 /* Require lite attack */
6018 if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->flags5 & RF5_BA_LITE)) return FALSE;
6020 /* No wall passing monsters */
6021 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
6023 /* No disintegrating monsters */
6024 if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
6030 * Helper function for "glass room"
6032 static bool vault_aux_shards(int r_idx)
6034 monster_race *r_ptr = &r_info[r_idx];
6036 /* Validate the monster */
6037 if (!vault_monster_okay(r_idx)) return FALSE;
6039 /* Require shards breath attack */
6040 if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
6046 * Hack -- determine if a template is potion
6048 static bool kind_is_potion(int k_idx)
6050 return k_info[k_idx].tval == TV_POTION;
6054 * Type 15 -- glass rooms
6056 static bool build_type15(void)
6058 int y, x, y2, x2, yval, xval;
6059 int y1, x1, xsize, ysize;
6064 /* Pick a room size */
6065 xsize = rand_range(9, 13);
6066 ysize = rand_range(9, 13);
6068 /* Find and reserve some space in the dungeon. Get center of room. */
6069 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
6071 /* Choose lite or dark */
6072 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
6074 /* Get corner values */
6075 y1 = yval - ysize / 2;
6076 x1 = xval - xsize / 2;
6077 y2 = yval + (ysize - 1) / 2;
6078 x2 = xval + (xsize - 1) / 2;
6080 /* Place a full floor under the room */
6081 for (y = y1 - 1; y <= y2 + 1; y++)
6083 for (x = x1 - 1; x <= x2 + 1; x++)
6085 c_ptr = &cave[y][x];
6086 place_floor_grid(c_ptr);
6087 c_ptr->feat = feat_glass_floor;
6088 c_ptr->info |= (CAVE_ROOM);
6089 if (light) c_ptr->info |= (CAVE_GLOW);
6093 /* Walls around the room */
6094 for (y = y1 - 1; y <= y2 + 1; y++)
6096 c_ptr = &cave[y][x1 - 1];
6097 place_outer_grid(c_ptr);
6098 c_ptr->feat = feat_glass_wall;
6099 c_ptr = &cave[y][x2 + 1];
6100 place_outer_grid(c_ptr);
6101 c_ptr->feat = feat_glass_wall;
6103 for (x = x1 - 1; x <= x2 + 1; x++)
6105 c_ptr = &cave[y1 - 1][x];
6106 place_outer_grid(c_ptr);
6107 c_ptr->feat = feat_glass_wall;
6108 c_ptr = &cave[y2 + 1][x];
6109 place_outer_grid(c_ptr);
6110 c_ptr->feat = feat_glass_wall;
6113 switch (randint1(3))
6115 case 1: /* 4 lite breathers + potion */
6119 /* Prepare allocation table */
6120 get_mon_num_prep(vault_aux_lite, NULL);
6122 /* Place fixed lite berathers */
6123 for (dir1 = 4; dir1 < 8; dir1++)
6125 int r_idx = get_mon_num(dun_level);
6127 y = yval + 2 * ddy_ddd[dir1];
6128 x = xval + 2 * ddx_ddd[dir1];
6129 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
6131 /* Walls around the breather */
6132 for (dir2 = 0; dir2 < 8; dir2++)
6134 c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
6135 place_inner_grid(c_ptr);
6136 c_ptr->feat = feat_glass_wall;
6140 /* Walls around the potion */
6141 for (dir1 = 0; dir1 < 4; dir1++)
6143 y = yval + 2 * ddy_ddd[dir1];
6144 x = xval + 2 * ddx_ddd[dir1];
6145 c_ptr = &cave[y][x];
6146 place_inner_perm_grid(c_ptr);
6147 c_ptr->feat = feat_permanent_glass_wall;
6148 cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]].info |= (CAVE_ICKY);
6153 y = yval + 2 * ddy_ddd[dir1];
6154 x = xval + 2 * ddx_ddd[dir1];
6155 place_secret_door(y, x, DOOR_GLASS_DOOR);
6156 c_ptr = &cave[y][x];
6157 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
6159 /* Place a potion */
6160 get_obj_num_hook = kind_is_potion;
6161 place_object(yval, xval, AM_NO_FIXED_ART);
6162 cave[yval][xval].info |= (CAVE_ICKY);
6166 case 2: /* 1 lite breather + random object */
6171 c_ptr = &cave[y1 + 1][x1 + 1];
6172 place_inner_grid(c_ptr);
6173 c_ptr->feat = feat_glass_wall;
6175 c_ptr = &cave[y1 + 1][x2 - 1];
6176 place_inner_grid(c_ptr);
6177 c_ptr->feat = feat_glass_wall;
6179 c_ptr = &cave[y2 - 1][x1 + 1];
6180 place_inner_grid(c_ptr);
6181 c_ptr->feat = feat_glass_wall;
6183 c_ptr = &cave[y2 - 1][x2 - 1];
6184 place_inner_grid(c_ptr);
6185 c_ptr->feat = feat_glass_wall;
6187 /* Prepare allocation table */
6188 get_mon_num_prep(vault_aux_lite, NULL);
6190 r_idx = get_mon_num(dun_level);
6191 if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
6193 /* Walls around the breather */
6194 for (dir1 = 0; dir1 < 8; dir1++)
6196 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
6197 place_inner_grid(c_ptr);
6198 c_ptr->feat = feat_glass_wall;
6201 /* Curtains around the breather */
6202 for (y = yval - 1; y <= yval + 1; y++)
6204 place_closed_door(y, xval - 2, DOOR_CURTAIN);
6205 place_closed_door(y, xval + 2, DOOR_CURTAIN);
6207 for (x = xval - 1; x <= xval + 1; x++)
6209 place_closed_door(yval - 2, x, DOOR_CURTAIN);
6210 place_closed_door(yval + 2, x, DOOR_CURTAIN);
6213 /* Place an object */
6214 place_object(yval, xval, AM_NO_FIXED_ART);
6215 cave[yval][xval].info |= (CAVE_ICKY);
6219 case 3: /* 4 shards breathers + 2 potions */
6223 /* Walls around the potion */
6224 for (y = yval - 2; y <= yval + 2; y++)
6226 c_ptr = &cave[y][xval - 3];
6227 place_inner_grid(c_ptr);
6228 c_ptr->feat = feat_glass_wall;
6229 c_ptr = &cave[y][xval + 3];
6230 place_inner_grid(c_ptr);
6231 c_ptr->feat = feat_glass_wall;
6233 for (x = xval - 2; x <= xval + 2; x++)
6235 c_ptr = &cave[yval - 3][x];
6236 place_inner_grid(c_ptr);
6237 c_ptr->feat = feat_glass_wall;
6238 c_ptr = &cave[yval + 3][x];
6239 place_inner_grid(c_ptr);
6240 c_ptr->feat = feat_glass_wall;
6242 for (dir1 = 4; dir1 < 8; dir1++)
6244 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
6245 place_inner_grid(c_ptr);
6246 c_ptr->feat = feat_glass_wall;
6249 /* Prepare allocation table */
6250 get_mon_num_prep(vault_aux_shards, NULL);
6252 /* Place shard berathers */
6253 for (dir1 = 4; dir1 < 8; dir1++)
6255 int r_idx = get_mon_num(dun_level);
6257 y = yval + ddy_ddd[dir1];
6258 x = xval + ddx_ddd[dir1];
6259 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
6262 /* Place two potions */
6265 get_obj_num_hook = kind_is_potion;
6266 place_object(yval, xval - 1, AM_NO_FIXED_ART);
6267 get_obj_num_hook = kind_is_potion;
6268 place_object(yval, xval + 1, AM_NO_FIXED_ART);
6272 get_obj_num_hook = kind_is_potion;
6273 place_object(yval - 1, xval, AM_NO_FIXED_ART);
6274 get_obj_num_hook = kind_is_potion;
6275 place_object(yval + 1, xval, AM_NO_FIXED_ART);
6278 for (y = yval - 2; y <= yval + 2; y++)
6279 for (x = xval - 2; x <= xval + 2; x++)
6280 cave[y][x].info |= (CAVE_ICKY);
6290 msg_print("¥¬¥é¥¹¤ÎÉô²°");
6292 msg_print("Glass room");
6300 /* Create a new floor room with optional light */
6301 void generate_room_floor(int y1, int x1, int y2, int x2, int light)
6307 for (y = y1; y <= y2; y++)
6309 for (x = x1; x <= x2; x++)
6312 c_ptr = &cave[y][x];
6313 place_floor_grid(c_ptr);
6314 c_ptr->info |= (CAVE_ROOM);
6315 if (light) c_ptr->info |= (CAVE_GLOW);
6320 void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
6324 for (y = y1; y <= y2; y++)
6326 for (x = x1; x <= x2; x++)
6329 place_inner_perm_bold(y, x);
6334 /* Minimum & maximum town size */
6335 #define MIN_TOWN_WID ((MAX_WID / 3) / 2)
6336 #define MIN_TOWN_HGT ((MAX_HGT / 3) / 2)
6337 #define MAX_TOWN_WID ((MAX_WID / 3) * 2 / 3)
6338 #define MAX_TOWN_HGT ((MAX_HGT / 3) * 2 / 3)
6340 /* Struct for build underground buildings */
6343 int y0, x0; /* North-west corner (relative) */
6344 int y1, x1; /* South-east corner (relative) */
6348 ugbldg_type *ugbldg;
6351 * Precalculate buildings' location of underground arcade
6353 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
6355 int i, y, x, center_y, center_x, tmp, attempt = 10000;
6356 int max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
6357 int max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
6358 ugbldg_type *cur_ugbldg;
6359 bool **ugarcade_used, abort;
6361 /* Allocate "ugarcade_used" array (2-dimension) */
6362 C_MAKE(ugarcade_used, town_hgt, bool *);
6363 C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
6364 for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
6366 /* Calculate building locations */
6367 for (i = 0; i < n; i++)
6369 cur_ugbldg = &ugbldg[i];
6370 (void)WIPE(cur_ugbldg, ugbldg_type);
6374 /* Find the "center" of the store */
6375 center_y = rand_range(2, town_hgt - 3);
6376 center_x = rand_range(2, town_wid - 3);
6378 /* Determine the store boundaries */
6379 tmp = center_y - randint1(max_bldg_hgt);
6380 cur_ugbldg->y0 = MAX(tmp, 1);
6381 tmp = center_x - randint1(max_bldg_wid);
6382 cur_ugbldg->x0 = MAX(tmp, 1);
6383 tmp = center_y + randint1(max_bldg_hgt);
6384 cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
6385 tmp = center_x + randint1(max_bldg_wid);
6386 cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
6388 /* Scan this building's area */
6389 for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
6391 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
6393 if (ugarcade_used[y][x])
6403 while (abort && attempt); /* Accept this building if no overlapping */
6405 /* Failed to generate underground arcade */
6406 if (!attempt) break;
6409 * Mark to ugarcade_used[][] as "used"
6410 * Note: Building-adjacent grids are included for preventing
6411 * connected bulidings.
6413 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
6415 for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
6417 ugarcade_used[y][x] = TRUE;
6422 /* Free "ugarcade_used" array (2-dimension) */
6423 C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
6424 C_KILL(ugarcade_used, town_hgt, bool *);
6426 /* If i < n, generation is not allowed */
6431 * Actually create buildings
6432 * Note: ltcy and ltcx indicate "left top corner".
6434 static void build_stores(int ltcy, int ltcx, int stores[], int n)
6437 ugbldg_type *cur_ugbldg;
6439 for (i = 0; i < n; i++)
6441 cur_ugbldg = &ugbldg[i];
6443 /* Generate new room */
6444 generate_room_floor(
6445 ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
6446 ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
6450 for (i = 0; i < n; i++)
6452 cur_ugbldg = &ugbldg[i];
6454 /* Build an invulnerable rectangular building */
6455 generate_fill_perm_bold(
6456 ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
6457 ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
6459 /* Pick a door direction (S,N,E,W) */
6460 switch (randint0(4))
6465 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
6471 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
6476 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
6482 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
6487 for (j = 0; j < max_f_idx; j++)
6489 if (have_flag(f_info[j].flags, FF_STORE))
6491 if (f_info[j].subtype == stores[i]) break;
6495 /* Clear previous contents, add a store door */
6498 cave_set_feat(ltcy + y, ltcx + x, j);
6501 store_init(NO_TOWN, stores[i]);
6508 * Type 16 -- Underground Arcade
6510 * Town logic flow for generation of new town
6511 * Originally from Vanilla 3.0.3
6513 * We start with a fully wiped cave of normal floors.
6515 * Note that town_gen_hack() plays games with the R.N.G.
6517 * This function does NOT do anything about the owners of the stores,
6518 * nor the contents thereof. It only handles the physical layout.
6520 static bool build_type16(void)
6524 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
6525 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
6527 int n = sizeof stores / sizeof (int);
6528 int i, y, x, y1, x1, yval, xval;
6529 int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
6530 int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
6531 bool prevent_bm = FALSE;
6533 /* Hack -- If already exist black market, prevent building */
6534 for (y = 0; (y < cur_hgt) && !prevent_bm; y++)
6536 for (x = 0; x < cur_wid; x++)
6538 if (cave[y][x].feat == FF_STORE)
6540 prevent_bm = (f_info[cave[y][x].feat].subtype == STORE_BLACK);
6545 for (i = 0; i < n; i++)
6547 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
6549 if (!n) return FALSE;
6551 /* Allocate buildings array */
6552 C_MAKE(ugbldg, n, ugbldg_type);
6554 /* If cannot build stores, abort */
6555 if (!precalc_ugarcade(town_hgt, town_wid, n))
6557 /* Free buildings array */
6558 C_KILL(ugbldg, n, ugbldg_type);
6562 /* Find and reserve some space in the dungeon. Get center of room. */
6563 if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
6565 /* Free buildings array */
6566 C_KILL(ugbldg, n, ugbldg_type);
6570 /* Get top left corner */
6571 y1 = yval - (town_hgt / 2);
6572 x1 = xval - (town_wid / 2);
6574 /* Generate new room */
6575 generate_room_floor(
6576 y1 + town_hgt / 3, x1 + town_wid / 3,
6577 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
6580 build_stores(y1, x1, stores, n);
6583 if (cheat_room) msg_print("Ãϲ¼³¹");
6585 if (cheat_room) msg_print("Underground Arcade");
6588 /* Free buildings array */
6589 C_KILL(ugbldg, n, ugbldg_type);
6596 * Attempt to build a room of the given type at the given block
6598 * Note that we restrict the number of "crowded" rooms to reduce
6599 * the chance of overflowing the monster list during level creation.
6601 static bool room_build(int typ)
6606 /* Build an appropriate room */
6607 case ROOM_T_NORMAL: return build_type1();
6608 case ROOM_T_OVERLAP: return build_type2();
6609 case ROOM_T_CROSS: return build_type3();
6610 case ROOM_T_INNER_FEAT: return build_type4();
6611 case ROOM_T_NEST: return build_type5();
6612 case ROOM_T_PIT: return build_type6();
6613 case ROOM_T_LESSER_VAULT: return build_type7();
6614 case ROOM_T_GREATER_VAULT: return build_type8();
6615 case ROOM_T_FRACAVE: return build_type9();
6616 case ROOM_T_RANDOM_VAULT: return build_type10();
6617 case ROOM_T_OVAL: return build_type11();
6618 case ROOM_T_CRYPT: return build_type12();
6619 case ROOM_T_TRAP_PIT: return build_type13();
6620 case ROOM_T_TRAP: return build_type14();
6621 case ROOM_T_GLASS: return build_type15();
6622 case ROOM_T_ARCADE: return build_type16();
6630 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
6633 * [from SAngband (originally from OAngband)]
6635 * Generate rooms in dungeon. Build bigger rooms at first.
6637 bool generate_rooms(void)
6643 int prob_list[ROOM_T_MAX];
6644 int rooms_built = 0;
6645 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
6646 int level_index = MIN(10, div_round(dun_level, 10));
6648 /* Number of each type of room on this level */
6649 s16b room_num[ROOM_T_MAX];
6651 /* Limit number of rooms */
6652 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
6654 /* Assume normal cave */
6655 room_info_type *room_info_ptr = room_info_normal;
6658 * Initialize probability list.
6660 for (i = 0; i < ROOM_T_MAX; i++)
6662 /* No rooms allowed above their minimum depth. */
6663 if (dun_level < room_info_ptr[i].min_level)
6669 prob_list[i] = room_info_ptr[i].prob[level_index];
6674 * XXX -- Various dungeon types and options.
6677 /* Ironman sees only Greater Vaults */
6678 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
6680 for (i = 0; i < ROOM_T_MAX; i++)
6682 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
6683 else prob_list[i] = 0;
6687 /* Forbidden vaults */
6688 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
6690 prob_list[ROOM_T_LESSER_VAULT] = 0;
6691 prob_list[ROOM_T_GREATER_VAULT] = 0;
6692 prob_list[ROOM_T_RANDOM_VAULT] = 0;
6696 /* NO_CAVE dungeon (Castle)*/
6697 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
6699 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
6700 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
6701 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
6704 /* CAVE dungeon (Orc cave etc.) */
6705 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
6707 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
6710 /* No caves when a (random) cavern exists: they look bad */
6711 else if (dun->cavern || dun->empty_level)
6713 prob_list[ROOM_T_FRACAVE] = 0;
6716 /* Forbidden glass rooms */
6717 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
6719 prob_list[ROOM_T_GLASS] = 0;
6722 if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
6724 prob_list[ROOM_T_ARCADE] = 0;
6728 * Initialize number of rooms,
6729 * And calcurate total probability.
6731 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
6734 total_prob += prob_list[i];
6738 * Prepare the number of rooms, of all types, we should build
6741 for (i = dun_rooms; i > 0; i--)
6744 int rand = randint0(total_prob);
6746 /* Get room_type randomly */
6747 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
6749 if (rand < prob_list[room_type]) break;
6750 else rand -= prob_list[room_type];
6754 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
6756 /* Increase the number of rooms of that type we should build. */
6757 room_num[room_type]++;
6763 case ROOM_T_LESSER_VAULT:
6764 case ROOM_T_TRAP_PIT:
6772 case ROOM_T_GREATER_VAULT:
6773 case ROOM_T_RANDOM_VAULT:
6782 * Build each type of room one by one until we cannot build any more.
6783 * [from SAngband (originally from OAngband)]
6787 /* Assume no remaining rooms */
6790 for (i = 0; i < ROOM_T_MAX; i++)
6792 /* What type of room are we building now? */
6793 int room_type = room_build_order[i];
6795 /* Go next if none available */
6796 if (!room_num[room_type]) continue;
6798 /* Use up one unit */
6799 room_num[room_type]--;
6801 /* Build the room. */
6802 if (room_build(room_type))
6804 /* Increase the room built count. */
6807 /* Mark as there was some remaining rooms */
6814 case ROOM_T_TRAP_PIT:
6816 /* Avoid too many monsters */
6819 room_num[ROOM_T_PIT] = 0;
6820 room_num[ROOM_T_NEST] = 0;
6821 room_num[ROOM_T_TRAP_PIT] = 0;
6827 /* Avoid double-town */
6828 room_num[ROOM_T_ARCADE] = 0;
6834 /* End loop if no room remain */
6838 if (rooms_built < 2) return FALSE;
6843 msg_format("Éô²°¿ô: %d", rooms_built);
6845 msg_format("Number of Rooms: %d", rooms_built);