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
32 * Some functions are used to determine if the given monster\n
33 * is appropriate for inclusion in a monster nest or monster pit or\n
36 * None of the pits/nests are allowed to include "unique" monsters.\n
44 #include "rooms-city.h"
45 #include "rooms-fractal.h"
46 #include "rooms-normal.h"
47 #include "rooms-pitnest.h"
48 #include "rooms-special.h"
49 #include "rooms-trap.h"
50 #include "rooms-vault.h"
59 *[from SAngband (originally from OAngband)]\n
61 * Table of values that control how many times each type of room will\n
62 * appear. Each type of room has its own row, and each column\n
63 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
64 * value is the minimum depth the room can appear at. -LM-\n
66 * Level 101 and below use the values for level 100.\n
68 * Rooms with lots of monsters or loot may not be generated if the\n
69 * object or monster lists are already nearly full. Rooms will not\n
70 * appear above their minimum depth. Tiny levels will not have space\n
71 * for all the rooms you ask for.\n
76 static room_info_type room_info_normal[ROOM_T_MAX] =
79 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
80 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
81 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
82 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
83 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
84 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
85 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
86 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
87 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
88 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
89 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
90 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
91 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
92 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
93 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
94 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
95 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
96 {{ 1, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80}, 1}, /*FIX */
102 static room_info_type room_info_normal[ROOM_T_MAX] =
105 { {999, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0}, 0}, /*NORMAL */
106 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 1 }, /*OVERLAP */
107 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*CROSS */
108 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*INNER_F */
109 { { 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 0}, 10 }, /*NEST */
110 { { 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 0}, 10 }, /*PIT */
111 { { 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 0}, 10 }, /*LESSER_V */
112 { { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 0}, 20 }, /*GREATER_V*/
113 { { 0,100,200,300,400,500,600,700,800,900, 0}, 10 }, /*FRACAVE */
114 { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0}, 10 }, /*RANDOM_V */
115 { { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0}, 3 }, /*OVAL */
116 { { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0}, 10 }, /*CRYPT */
117 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP_PIT */
118 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP */
119 { { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0}, 40 }, /*GLASS */
120 { { 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 0}, 1 }, /*ARCADE */
121 { { 20, 40, 60, 80,100,100,100,100,100,100,100}, 1 }, /*FIX */
128 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
129 static byte room_build_order[ROOM_T_MAX] = {
130 ROOM_T_GREATER_VAULT,
150 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
151 * @param y0 配置したい中心のY座標
152 * @param x0 配置したい中心のX座標
154 * This funtion makes a very small room centred at (x0, y0)
155 * This is used in crypts, and random elemental vaults.
157 * Note - this should be used only on allocated regions
158 * within another room.
160 void build_small_room(POSITION x0, POSITION y0)
164 for (y = y0 - 1; y <= y0 + 1; y++)
166 place_inner_bold(y, x0 - 1);
167 place_inner_bold(y, x0 + 1);
170 for (x = x0 - 1; x <= x0 + 1; x++)
172 place_inner_bold(y0 - 1, x);
173 place_inner_bold(y0 + 1, x);
176 /* Place a secret door on one side */
179 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
180 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
181 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
182 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
185 /* Clear mimic type */
186 cave[y0][x0].mimic = 0;
188 /* Add inner open space */
189 place_floor_bold(y0, x0);
194 * 指定範囲に通路が通っていることを確認した上で床で埋める
195 * This function tunnels around a room if it will cut off part of a cave system.
202 static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION y2)
206 bool old_is_floor, new_is_floor;
209 old_is_floor = get_is_floor(x1 - 1, y1);
212 * Count the number of floor-wall boundaries around the room
213 * Note: diagonal squares are ignored since the player can move diagonally
214 * to bypass these if needed.
217 /* Above the top boundary */
218 for (x = x1; x <= x2; x++)
220 new_is_floor = get_is_floor(x, y1 - 1);
222 /* Increment counter if they are different */
223 if (new_is_floor != old_is_floor) count++;
225 old_is_floor = new_is_floor;
229 for (y = y1; y <= y2; y++)
231 new_is_floor = get_is_floor(x2 + 1, y);
233 /* increment counter if they are different */
234 if (new_is_floor != old_is_floor) count++;
236 old_is_floor = new_is_floor;
239 /* Bottom boundary */
240 for (x = x2; x >= x1; x--)
242 new_is_floor = get_is_floor(x, y2 + 1);
244 /* increment counter if they are different */
245 if (new_is_floor != old_is_floor) count++;
247 old_is_floor = new_is_floor;
251 for (y = y2; y >= y1; y--)
253 new_is_floor = get_is_floor(x1 - 1, y);
255 /* increment counter if they are different */
256 if (new_is_floor != old_is_floor) count++;
258 old_is_floor = new_is_floor;
261 /* If all the same, or only one connection exit. */
262 if (count <= 2) return;
265 /* Tunnel around the room so to prevent problems with caves */
266 for (y = y1; y <= y2; y++)
268 for (x = x1; x <= x2; x++)
278 * find_space()の予備処理として部屋の生成が可能かを判定する /
279 * Helper function for find_space(). Is this a good location?
280 * @param blocks_high 範囲の高さ
281 * @param blocks_wide 範囲の幅
282 * @param block_y 範囲の上端
283 * @param block_x 範囲の左端
286 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
288 POSITION by1, bx1, by2, bx2, by, bx;
290 /* Itty-bitty rooms must shift about within their rectangle */
293 if ((blocks_wide == 2) && (block_x % 3) == 2)
297 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
298 else if ((blocks_wide % 3) == 0)
300 /* Must be aligned to the left edge of a 11x33 rectangle. */
301 if ((block_x % 3) != 0)
306 * Big rooms that do not have a width divisible by 3 must be
307 * aligned towards the edge of the dungeon closest to them.
311 /* Shift towards left edge of dungeon. */
312 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
314 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
316 if ((block_x % 3) == 1)
320 /* Shift toward right edge of dungeon. */
323 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
325 if ((block_x % 3) == 1)
333 by2 = block_y + blocks_high;
334 bx2 = block_x + blocks_wide;
336 /* Never run off the screen */
337 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
338 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
340 /* Verify available space */
341 for (by = by1; by < by2; by++)
343 for (bx = bx1; bx < bx2; bx++)
345 if (dun->room_map[by][bx])
352 /* This location is okay */
358 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
359 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
360 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
361 * @param height 確保したい領域の高さ
362 * @param width 確保したい領域の幅
363 * @return 所定の範囲が確保できた場合TRUEを返す
365 * Find and allocate a free space in the dungeon large enough to hold\n
366 * the room calling this function.\n
368 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
369 * align neatly on the standard screen. Therefore, we make them use\n
370 * blocks in few 11x33 rectangles as possible.\n
372 * Be careful to include the edges of the room in height and width!\n
374 * Return TRUE and values for the center of the room if all went well.\n
375 * Otherwise, return FALSE.\n
377 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
379 int candidates, pick;
380 POSITION by, bx, by1, bx1, by2, bx2;
381 POSITION block_y = 0, block_x = 0;
383 /* Find out how many blocks we need. */
384 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
385 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
387 /* There are no way to allocate such huge space */
388 if (dun->row_rooms < blocks_high) return FALSE;
389 if (dun->col_rooms < blocks_wide) return FALSE;
394 /* Count the number of valid places */
395 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
397 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
399 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
401 /* Find a valid place */
414 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
416 /* Choose a random one */
417 pick = randint1(candidates);
420 /* NO_CAVE dungeon (Castle) */
423 /* Always choose the center one */
424 pick = candidates/2 + 1;
427 /* Pick up the choosen location */
428 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
430 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
432 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
436 /* This one is picked? */
447 by2 = block_y + blocks_high;
448 bx2 = block_x + blocks_wide;
451 * It is *extremely* important that the following calculation
452 * be *exactly* correct to prevent memory errors
455 /* Acquire the location of the room */
456 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
457 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
459 /* Save the room location */
460 if (dun->cent_n < CENT_MAX)
462 dun->cent[dun->cent_n].y = (byte_hack)*y;
463 dun->cent[dun->cent_n].x = (byte_hack)*x;
467 /* Reserve some blocks. */
468 for (by = by1; by < by2; by++)
470 for (bx = bx1; bx < bx2; bx++)
472 dun->room_map[by][bx] = TRUE;
477 * Hack- See if room will cut off a cavern.
479 * If so, fix by tunneling outside the room in such a
480 * way as to connect the caves.
482 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
490 * Structure to hold all "fill" data
493 typedef struct fill_data_type fill_data_type;
495 struct fill_data_type
508 /* features to fill with */
517 /* number of filled squares */
521 static fill_data_type fill_data;
524 /* Store routine for the fractal cave generator */
525 /* this routine probably should be an inline function or a macro. */
526 static void store_height(POSITION x, POSITION y, FEAT_IDX val)
528 /* if on boundary set val > cutoff so walls are not as square */
529 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
530 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
531 (val <= fill_data.c1)) val = fill_data.c1 + 1;
533 /* store the value in height-map format */
534 cave[y][x].feat = val;
541 * Explanation of the plasma fractal algorithm:
543 * A grid of points is created with the properties of a 'height-map'
544 * This is done by making the corners of the grid have a random value.
545 * The grid is then subdivided into one with twice the resolution.
546 * The new points midway between two 'known' points can be calculated
547 * by taking the average value of the 'known' ones and randomly adding
548 * or subtracting an amount proportional to the distance between those
549 * points. The final 'middle' points of the grid are then calculated
550 * by averaging all four of the originally 'known' corner points. An
551 * random amount is added or subtracted from this to get a value of the
552 * height at that point. The scaling factor here is adjusted to the
553 * slightly larger distance diagonally as compared to orthogonally.
555 * This is then repeated recursively to fill an entire 'height-map'
556 * A rectangular map is done the same way, except there are different
557 * scaling factors along the x and y directions.
559 * A hack to change the amount of correlation between points is done using
560 * the grd variable. If the current step size is greater than grd then
561 * the point will be random, otherwise it will be calculated by the
562 * above algorithm. This makes a maximum distance at which two points on
563 * the height map can affect each other.
565 * How fractal caves are made:
567 * When the map is complete, a cut-off value is used to create a cave.
568 * Heights below this value are "floor", and heights above are "wall".
569 * This also can be used to create lakes, by adding more height levels
570 * representing shallow and deep water/ lava etc.
572 * The grd variable affects the width of passages.
573 * The roug variable affects the roughness of those passages
575 * The tricky part is making sure the created cave is connected. This
576 * is done by 'filling' from the inside and only keeping the 'filled'
577 * floor. Walls bounding the 'filled' floor are also kept. Everything
578 * else is converted to the normal _extra_.
583 * Note that this uses the cave.feat array in a very hackish way
584 * the values are first set to zero, and then each array location
585 * is used as a "heightmap"
586 * The heightmap then needs to be converted back into the "feat" format.
588 * grd=level at which fractal turns on. smaller gives more mazelike caves
589 * roug=roughness level. 16=normal. higher values make things more convoluted
590 * small values are good for smooth walls.
591 * size=length of the side of the square cave system.
593 void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
595 POSITION xhsize, yhsize, xsize, ysize, maxsize;
598 * fixed point variables- these are stored as 256 x normal value
599 * this gives 8 binary places of fractional part + 8 places of normal part
602 POSITION xstep, xhstep, ystep, yhstep;
603 POSITION xstep2, xhstep2, ystep2, yhstep2;
604 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
606 /* Cache for speed */
607 POSITION xm, xp, ym, yp;
609 /* redefine size so can change the value if out of range */
613 /* Paranoia about size of the system of caves */
614 if (xsize > 254) xsize = 254;
615 if (xsize < 4) xsize = 4;
616 if (ysize > 254) ysize = 254;
617 if (ysize < 4) ysize = 4;
619 /* get offsets to middle of array */
623 /* fix rounding problem */
627 /* get limits of region */
628 fill_data.xmin = x0 - xhsize;
629 fill_data.ymin = y0 - yhsize;
630 fill_data.xmax = x0 + xhsize;
631 fill_data.ymax = y0 + yhsize;
633 /* Store cutoff in global for quick access */
634 fill_data.c1 = cutoff;
637 * Scale factor for middle points:
638 * About sqrt(2) * 256 - correct for a square lattice
639 * approximately correct for everything else.
643 /* maximum of xsize and ysize */
644 maxsize = (xsize > ysize) ? xsize : ysize;
646 /* Clear the section */
647 for (i = 0; i <= xsize; i++)
649 for (j = 0; j <= ysize; j++)
651 /* -1 is a flag for "not done yet" */
652 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
653 /* Clear icky flag because may be redoing the cave */
654 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
658 /* Boundaries are walls */
659 cave[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
660 cave[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
661 cave[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
662 cave[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
664 /* Set the middle square to be an open area. */
665 cave[y0][x0].feat = 0;
667 /* Initialize the step sizes */
668 xstep = xhstep = xsize * 256;
669 ystep = yhstep = ysize * 256;
670 xxsize = xsize * 256;
671 yysize = ysize * 256;
674 * Fill in the rectangle with fractal height data -
675 * like the 'plasma fractal' in fractint.
677 while ((xhstep > 256) || (yhstep > 256))
679 /* Halve the step sizes */
685 /* cache well used values */
686 xstep2 = xstep / 256;
687 ystep2 = ystep / 256;
689 xhstep2 = xhstep / 256;
690 yhstep2 = yhstep / 256;
692 /* middle top to bottom. */
693 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
695 for (j = 0; j <= yysize; j += ystep)
697 /* cache often used values */
698 ii = i / 256 + fill_data.xmin;
699 jj = j / 256 + fill_data.ymin;
702 if (cave[jj][ii].feat == -1)
706 /* If greater than 'grid' level then is random */
707 store_height(ii, jj, randint1(maxsize));
711 /* Average of left and right points +random bit */
713 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
714 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
715 + (randint1(xstep2) - xhstep2) * roug / 16);
722 /* middle left to right. */
723 for (j = yhstep; j <= yysize - yhstep; j += ystep)
725 for (i = 0; i <= xxsize; i += xstep)
727 /* cache often used values */
728 ii = i / 256 + fill_data.xmin;
729 jj = j / 256 + fill_data.ymin;
732 if (cave[jj][ii].feat == -1)
736 /* If greater than 'grid' level then is random */
737 store_height(ii, jj, randint1(maxsize));
741 /* Average of up and down points +random bit */
743 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
744 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
745 + (randint1(ystep2) - yhstep2) * roug / 16);
752 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
754 for (j = yhstep; j <= yysize - yhstep; j += ystep)
756 /* cache often used values */
757 ii = i / 256 + fill_data.xmin;
758 jj = j / 256 + fill_data.ymin;
761 if (cave[jj][ii].feat == -1)
765 /* If greater than 'grid' level then is random */
766 store_height(ii, jj, randint1(maxsize));
770 /* Cache reused values. */
771 xm = fill_data.xmin + (i - xhstep) / 256;
772 xp = fill_data.xmin + (i + xhstep) / 256;
773 ym = fill_data.ymin + (j - yhstep) / 256;
774 yp = fill_data.ymin + (j + yhstep) / 256;
777 * Average over all four corners + scale by diagsize to
778 * reduce the effect of the square grid on the shape of the fractal
781 (cave[ym][xm].feat + cave[yp][xm].feat
782 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
783 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
792 static bool hack_isnt_wall(POSITION y, POSITION x, int c1, int c2, int c3, FEAT_IDX feat1, FEAT_IDX feat2, FEAT_IDX feat3, BIT_FLAGS info1, BIT_FLAGS info2, BIT_FLAGS info3)
795 * function used to convert from height-map back to the
796 * normal angband cave format
798 if (cave[y][x].info & CAVE_ICKY)
805 /* Show that have looked at this square */
806 cave[y][x].info|= (CAVE_ICKY);
808 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
809 if (cave[y][x].feat <= c1)
811 /* 25% of the time use the other tile : it looks better this way */
812 if (randint1(100) < 75)
814 cave[y][x].feat = feat1;
815 cave[y][x].info &= ~(CAVE_MASK);
816 cave[y][x].info |= info1;
821 cave[y][x].feat = feat2;
822 cave[y][x].info &= ~(CAVE_MASK);
823 cave[y][x].info |= info2;
827 else if (cave[y][x].feat <= c2)
829 /* 25% of the time use the other tile : it looks better this way */
830 if (randint1(100) < 75)
832 cave[y][x].feat = feat2;
833 cave[y][x].info &= ~(CAVE_MASK);
834 cave[y][x].info |= info2;
839 cave[y][x].feat = feat1;
840 cave[y][x].info &= ~(CAVE_MASK);
841 cave[y][x].info |= info1;
845 else if (cave[y][x].feat <= c3)
847 cave[y][x].feat = feat3;
848 cave[y][x].info &= ~(CAVE_MASK);
849 cave[y][x].info |= info3;
852 /* if greater than cutoff then is a wall */
855 place_outer_bold(y, x);
865 * Quick and nasty fill routine used to find the connected region
866 * of floor in the middle of the cave
868 static void cave_fill(POSITION y, POSITION x)
879 /* Enqueue that entry */
883 /* Now process the queue */
884 while (flow_head != flow_tail)
886 /* Extract the next entry */
887 ty = temp_y[flow_head];
888 tx = temp_x[flow_head];
890 /* Forget that entry */
891 if (++flow_head == TEMP_MAX) flow_head = 0;
893 /* Add the "children" */
894 for (d = 0; d < 8; d++)
896 int old_head = flow_tail;
902 /* Paranoia Don't leave the cave */
903 if (!in_bounds(j, i))
905 /* affect boundary */
906 cave[j][i].info |= CAVE_ICKY;
910 /* If within bounds */
911 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
912 && (j > fill_data.ymin) && (j < fill_data.ymax))
914 /* If not a wall or floor done before */
915 if (hack_isnt_wall(j, i,
916 fill_data.c1, fill_data.c2, fill_data.c3,
917 fill_data.feat1, fill_data.feat2, fill_data.feat3,
918 fill_data.info1, fill_data.info2, fill_data.info3))
920 /* Enqueue that entry */
921 temp_y[flow_tail] = (byte_hack)j;
922 temp_x[flow_tail] = (byte_hack)i;
924 /* Advance the queue */
925 if (++flow_tail == TEMP_MAX) flow_tail = 0;
927 /* Hack -- Overflow by forgetting new entry */
928 if (flow_tail == flow_head)
930 flow_tail = old_head;
934 /* keep tally of size of cave system */
935 (fill_data.amount)++;
941 /* affect boundary */
942 cave[j][i].info |= CAVE_ICKY;
949 bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
951 POSITION x, y, xhsize, yhsize;
954 /* offsets to middle from corner */
960 * select region connected to center of cave system
961 * this gets rid of alot of isolated one-sqaures that
962 * can make teleport traps instadeaths...
966 fill_data.c1 = cutoff;
970 /* features to fill with */
971 fill_data.feat1 = feat_ground_type[randint0(100)];
972 fill_data.feat2 = feat_ground_type[randint0(100)];
973 fill_data.feat3 = feat_ground_type[randint0(100)];
975 fill_data.info1 = CAVE_FLOOR;
976 fill_data.info2 = CAVE_FLOOR;
977 fill_data.info3 = CAVE_FLOOR;
979 /* number of filled squares */
980 fill_data.amount = 0;
982 cave_fill((byte)y0, (byte)x0);
984 /* if tally too small, try again */
985 if (fill_data.amount < 10)
987 /* too small - clear area and try again later */
988 for (x = 0; x <= xsize; ++x)
990 for (y = 0; y <= ysize; ++y)
992 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
993 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1000 * Do boundarys-check to see if they are next to a filled region
1001 * If not then they are set to normal granite
1002 * If so then they are marked as room walls.
1004 for (i = 0; i <= xsize; ++i)
1007 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1009 /* Next to a 'filled' region? - set to be room walls */
1010 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1011 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1012 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1013 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1017 /* set to be normal granite */
1018 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1021 /* bottom boundary */
1022 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1024 /* Next to a 'filled' region? - set to be room walls */
1025 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1026 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1027 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1028 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1032 /* set to be normal granite */
1033 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1036 /* clear the icky flag-don't need it any more */
1037 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1038 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1041 /* Do the left and right boundaries minus the corners (done above) */
1042 for (i = 1; i < ysize; ++i)
1045 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1048 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1049 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1050 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1051 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1056 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1058 /* right boundary */
1059 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1062 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1063 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1064 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1065 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1070 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1073 /* clear icky flag -done with it */
1074 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1075 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1079 /* Do the rest: convert back to the normal format */
1080 for (x = 1; x < xsize; ++x)
1082 for (y = 1; y < ysize; ++y)
1084 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1085 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1087 /* Clear the icky flag in the filled region */
1088 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1090 /* Set appropriate flags */
1091 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1092 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1094 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1095 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1098 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1099 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1102 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1107 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1108 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1113 /* Clear the unconnected regions */
1114 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1115 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1121 * There is a slight problem when tunnels pierce the caves:
1122 * Extra doors appear inside the system. (Its not very noticeable though.)
1123 * This can be removed by "filling" from the outside in. This allows a separation
1124 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1125 * The extra effort for what seems to be only a minor thing (even non-existant if you
1126 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1134 #ifdef ALLOW_CAVERNS_AND_LAKES
1136 * Builds a cave system in the center of the dungeon.
1138 void build_cavern(void)
1140 int grd, roug, cutoff;
1141 POSITION xsize, ysize, x0, y0;
1144 light = done = FALSE;
1145 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1147 /* Make a cave the size of the dungeon */
1148 xsize = cur_wid - 1;
1149 ysize = cur_hgt - 1;
1153 /* Paranoia: make size even */
1159 /* testing values for these parameters: feel free to adjust */
1160 grd = randint1(4) + 4;
1162 /* want average of about 16 */
1163 roug = randint1(8) * randint1(4);
1169 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1171 /* Convert to normal format+ clean up */
1172 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1176 bool generate_lake(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1178 POSITION x, y, xhsize, yhsize;
1180 FEAT_IDX feat1, feat2, feat3;
1182 /* offsets to middle from corner */
1186 /* Get features based on type */
1189 case LAKE_T_LAVA: /* Lava */
1190 feat1 = feat_deep_lava;
1191 feat2 = feat_shallow_lava;
1192 feat3 = feat_ground_type[randint0(100)];
1194 case LAKE_T_WATER: /* Water */
1195 feat1 = feat_deep_water;
1196 feat2 = feat_shallow_water;
1197 feat3 = feat_ground_type[randint0(100)];
1199 case LAKE_T_CAVE: /* Collapsed cave */
1200 feat1 = feat_ground_type[randint0(100)];
1201 feat2 = feat_ground_type[randint0(100)];
1202 feat3 = feat_rubble;
1204 case LAKE_T_EARTH_VAULT: /* Earth vault */
1205 feat1 = feat_rubble;
1206 feat2 = feat_ground_type[randint0(100)];
1207 feat3 = feat_rubble;
1209 case LAKE_T_AIR_VAULT: /* Air vault */
1214 case LAKE_T_WATER_VAULT: /* Water vault */
1215 feat1 = feat_shallow_water;
1216 feat2 = feat_deep_water;
1217 feat3 = feat_shallow_water;
1219 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1220 feat1 = feat_shallow_lava;
1221 feat2 = feat_deep_lava;
1222 feat3 = feat_shallow_lava;
1226 default: return FALSE;
1230 * select region connected to center of cave system
1231 * this gets rid of alot of isolated one-sqaures that
1232 * can make teleport traps instadeaths...
1240 /* features to fill with */
1241 fill_data.feat1 = feat1;
1242 fill_data.feat2 = feat2;
1243 fill_data.feat3 = feat3;
1245 fill_data.info1 = 0;
1246 fill_data.info2 = 0;
1247 fill_data.info3 = 0;
1249 /* number of filled squares */
1250 fill_data.amount = 0;
1252 /* select region connected to center of cave system
1253 * this gets rid of alot of isolated one-sqaures that
1254 * can make teleport traps instadeaths... */
1255 cave_fill((byte)y0, (byte)x0);
1257 /* if tally too small, try again */
1258 if (fill_data.amount < 10)
1260 /* too small -clear area and try again later */
1261 for (x = 0; x <= xsize; ++x)
1263 for (y = 0; y <= ysize; ++y)
1265 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1266 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1272 /* Do boundarys- set to normal granite */
1273 for (i = 0; i <= xsize; ++i)
1275 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1276 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1278 /* clear the icky flag-don't need it any more */
1279 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1280 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1283 /* Do the left and right boundaries minus the corners (done above) */
1285 for (i = 1; i < ysize; ++i)
1287 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1288 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1290 /* clear icky flag -done with it */
1291 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1292 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1296 /* Do the rest: convert back to the normal format */
1297 for (x = 1; x < xsize; ++x)
1299 for (y = 1; y < ysize; ++y)
1301 /* Fill unconnected regions with granite */
1302 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1303 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
1304 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1306 /* turn off icky flag (no longer needed.) */
1307 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1310 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1312 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1322 * makes a lake/collapsed cave system in the center of the dungeon
1324 void build_lake(int type)
1326 int grd, roug, xsize, ysize, x0, y0;
1330 /* paranoia - exit if lake type out of range. */
1331 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1333 msg_format("Invalid lake type (%d)", type);
1337 /* Make the size of the dungeon */
1338 xsize = cur_wid - 1;
1339 ysize = cur_hgt - 1;
1343 /* Paranoia: make size even */
1349 /* testing values for these parameters: feel free to adjust */
1350 grd = randint1(3) + 4;
1352 /* want average of about 16 */
1353 roug = randint1(8) * randint1(4);
1355 /* Make up size of various componants */
1359 /* Deep water/lava */
1360 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1362 /* Shallow boundary */
1366 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1368 /* Convert to normal format+ clean up */
1369 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1372 #endif /* ALLOW_CAVERNS_AND_LAKES */
1377 * Routine that fills the empty areas of a room with treasure and monsters.
1379 void fill_treasure(POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1381 POSITION x, y, cx, cy, size;
1384 /* center of room:*/
1388 /* Rough measure of size of vault= sum of lengths of sides */
1389 size = abs(x2 - x1) + abs(y2 - y1);
1391 for (x = x1; x <= x2; x++)
1393 for (y = y1; y <= y2; y++)
1395 /* Thing added based on distance to center of vault
1396 * Difficulty is 1-easy to 10-hard */
1397 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1399 /* hack- empty square part of the time */
1400 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1402 /* if floor, shallow water and lava */
1403 if (is_floor_bold(y, x) ||
1404 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1406 /* The smaller 'value' is, the better the stuff */
1409 /* Meanest monster + treasure */
1410 monster_level = base_level + 40;
1411 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1412 monster_level = base_level;
1413 object_level = base_level + 20;
1414 place_object(y, x, AM_GOOD);
1415 object_level = base_level;
1419 /* Mean monster +treasure */
1420 monster_level = base_level + 20;
1421 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1422 monster_level = base_level;
1423 object_level = base_level + 10;
1424 place_object(y, x, AM_GOOD);
1425 object_level = base_level;
1427 else if (value < 10)
1430 monster_level = base_level + 9;
1431 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1432 monster_level = base_level;
1434 else if (value < 17)
1436 /* Intentional Blank space */
1439 * (Want some of the vault to be empty
1440 * so have room for group monsters.
1441 * This is used in the hack above to lower
1442 * the density of stuff in the vault.)
1445 else if (value < 23)
1447 /* Object or trap */
1448 if (randint0(100) < 25)
1450 place_object(y, x, 0L);
1457 else if (value < 30)
1459 /* Monster and trap */
1460 monster_level = base_level + 5;
1461 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1462 monster_level = base_level;
1465 else if (value < 40)
1467 /* Monster or object */
1468 if (randint0(100) < 50)
1470 monster_level = base_level + 3;
1471 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1472 monster_level = base_level;
1474 if (randint0(100) < 50)
1476 object_level = base_level + 7;
1477 place_object(y, x, 0L);
1478 object_level = base_level;
1481 else if (value < 50)
1490 /* 20% monster, 40% trap, 20% object, 20% blank space */
1491 if (randint0(100) < 20)
1493 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1495 else if (randint0(100) < 50)
1499 else if (randint0(100) < 50)
1501 place_object(y, x, 0L);
1513 * Overlay a rectangular room given its bounds
1514 * This routine is used by build_room_vault
1515 * The area inside the walls is not touched:
1516 * only granite is removed- normal walls stay
1518 void build_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1520 POSITION x, y, xsize, ysize;
1523 /* Check if rectangle has no width */
1524 if ((x1 == x2) || (y1 == y2)) return;
1528 /* Swap boundaries if in wrong order */
1536 /* Swap boundaries if in wrong order */
1542 /* get total widths */
1547 /* Top and bottom boundaries */
1548 for (i = 0; i <= xsize; i++)
1550 place_outer_noperm_bold(y1, x1 + i);
1551 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1552 place_outer_noperm_bold(y2, x1 + i);
1553 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1556 /* Left and right boundaries */
1557 for (i = 1; i < ysize; i++)
1559 place_outer_noperm_bold(y1 + i, x1);
1560 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1561 place_outer_noperm_bold(y1 + i, x2);
1562 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1566 for (x = 1; x < xsize; x++)
1568 for (y = 1; y < ysize; y++)
1570 if (is_extra_bold(y1+y, x1+x))
1572 /* clear the untouched region */
1573 place_floor_bold(y1 + y, x1 + x);
1574 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1578 /* make it a room- but don't touch */
1579 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1588 * maze vault -- rectangular labyrinthine rooms
1590 * maze vault uses two routines:
1591 * r_visit - a recursive routine that builds the labyrinth
1592 * build_maze_vault - a driver routine that calls r_visit and adds
1593 * monsters, traps and treasure
1595 * The labyrinth is built by creating a spanning tree of a graph.
1596 * The graph vertices are at
1597 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1598 * and the edges are the vertical and horizontal nearest neighbors.
1600 * The spanning tree is created by performing a suitably randomized
1601 * depth-first traversal of the graph. The only adjustable parameter
1602 * is the randint0(3) below; it governs the relative density of
1603 * twists and turns in the labyrinth: smaller number, more twists.
1605 void r_visit(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1607 int i, j, m, n, temp, x, y, adj[4];
1609 /* dimensions of vertex array */
1610 m = (x2 - x1) / 2 + 1;
1611 n = (y2 - y1) / 2 + 1;
1613 /* mark node visited and set it to a floor */
1615 x = 2 * (node % m) + x1;
1616 y = 2 * (node / m) + y1;
1617 place_floor_bold(y, x);
1619 /* setup order of adjacent node visits */
1622 /* pick a random ordering */
1623 for (i = 0; i < 4; i++)
1625 for (i = 0; i < 4; i++)
1636 /* pick a random ordering with dir first */
1638 for (i = 1; i < 4; i++)
1640 for (i = 1; i < 4; i++)
1642 j = 1 + randint0(3);
1649 for (i = 0; i < 4; i++)
1654 /* (0,+) - check for bottom boundary */
1655 if ((node / m < n - 1) && (visited[node + m] == 0))
1657 place_floor_bold(y + 1, x);
1658 r_visit(y1, x1, y2, x2, node + m, dir, visited);
1662 /* (0,-) - check for top boundary */
1663 if ((node / m > 0) && (visited[node - m] == 0))
1665 place_floor_bold(y - 1, x);
1666 r_visit(y1, x1, y2, x2, node - m, dir, visited);
1670 /* (+,0) - check for right boundary */
1671 if ((node % m < m - 1) && (visited[node + 1] == 0))
1673 place_floor_bold(y, x + 1);
1674 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
1678 /* (-,0) - check for left boundary */
1679 if ((node % m > 0) && (visited[node - 1] == 0))
1681 place_floor_bold(y, x - 1);
1682 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
1689 void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1691 POSITION y, x, dy, dx;
1692 POSITION y1, x1, y2, x2;
1693 int m, n, num_vertices, *visited;
1697 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1699 /* Choose lite or dark */
1700 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1702 /* Pick a random room size - randomized by calling routine */
1711 /* generate the room */
1712 for (y = y1 - 1; y <= y2 + 1; y++)
1714 for (x = x1 - 1; x <= x2 + 1; x++)
1716 c_ptr = &cave[y][x];
1717 c_ptr->info |= CAVE_ROOM;
1718 if (is_vault) c_ptr->info |= CAVE_ICKY;
1719 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1721 place_outer_grid(c_ptr);
1725 place_extra_grid(c_ptr);
1729 place_inner_grid(c_ptr);
1731 if (light) c_ptr->info |= (CAVE_GLOW);
1735 /* dimensions of vertex array */
1738 num_vertices = m * n;
1740 /* initialize array of visited vertices */
1741 C_MAKE(visited, num_vertices, int);
1743 /* traverse the graph to create a spaning tree, pick a random root */
1744 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1746 /* Fill with monsters and treasure, low difficulty */
1747 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
1749 C_KILL(visited, num_vertices, int);
1753 /* Build a town/ castle by using a recursive algorithm.
1754 * Basically divide each region in a probalistic way to create
1755 * smaller regions. When the regions get too small stop.
1757 * The power variable is a measure of how well defended a region is.
1758 * This alters the possible choices.
1760 void build_recursive_room(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1762 POSITION xsize, ysize;
1766 /* Temp variables */
1772 if ((power < 3) && (xsize > 12) && (ysize > 12))
1774 /* Need outside wall +keep */
1781 /* Make rooms + subdivide */
1782 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1788 choice = randint1(2) + 1;
1793 /* Mostly subdivide */
1794 choice = randint1(3) + 1;
1798 /* Based on the choice made above, do something */
1806 /* top and bottom */
1807 for (x = x1; x <= x2; x++)
1809 place_outer_bold(y1, x);
1810 place_outer_bold(y2, x);
1813 /* left and right */
1814 for (y = y1 + 1; y < y2; y++)
1816 place_outer_bold(y, x1);
1817 place_outer_bold(y, x2);
1820 /* Make a couple of entrances */
1823 /* left and right */
1824 y = randint1(ysize) + y1;
1825 place_floor_bold(y, x1);
1826 place_floor_bold(y, x2);
1830 /* top and bottom */
1831 x = randint1(xsize) + x1;
1832 place_floor_bold(y1, x);
1833 place_floor_bold(y2, x);
1836 /* Select size of keep */
1837 t1 = randint1(ysize / 3) + y1;
1838 t2 = y2 - randint1(ysize / 3);
1839 t3 = randint1(xsize / 3) + x1;
1840 t4 = x2 - randint1(xsize / 3);
1842 /* Do outside areas */
1844 /* Above and below keep */
1845 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1846 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
1848 /* Left and right of keep */
1849 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1850 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1852 /* Make the keep itself: */
1865 /* Try to build a room */
1866 if ((xsize < 3) || (ysize < 3))
1868 for (y = y1; y < y2; y++)
1870 for (x = x1; x < x2; x++)
1872 place_inner_bold(y, x);
1880 /* Make outside walls */
1881 /* top and bottom */
1882 for (x = x1 + 1; x <= x2 - 1; x++)
1884 place_inner_bold(y1 + 1, x);
1885 place_inner_bold(y2 - 1, x);
1888 /* left and right */
1889 for (y = y1 + 1; y <= y2 - 1; y++)
1891 place_inner_bold(y, x1 + 1);
1892 place_inner_bold(y, x2 - 1);
1896 y = randint1(ysize - 3) + y1 + 1;
1901 place_floor_bold(y, x1 + 1);
1906 place_floor_bold(y, x2 - 1);
1909 /* Build the room */
1910 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1915 /* Try and divide vertically */
1919 for (y = y1; y < y2; y++)
1921 for (x = x1; x < x2; x++)
1923 place_inner_bold(y, x);
1929 t1 = randint1(xsize - 2) + x1 + 1;
1930 build_recursive_room(x1, y1, t1, y2, power - 2);
1931 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
1936 /* Try and divide horizontally */
1940 for (y = y1; y < y2; y++)
1942 for (x = x1; x < x2; x++)
1944 place_inner_bold(y, x);
1950 t1 = randint1(ysize - 2) + y1 + 1;
1951 build_recursive_room(x1, y1, x2, t1, power - 2);
1952 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
1960 * Add outer wall to a floored region
1961 * Note: no range checking is done so must be inside dungeon
1962 * This routine also stomps on doors
1964 void add_outer_wall(POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1967 feature_type *f_ptr;
1970 if (!in_bounds(y, x)) return;
1972 c_ptr = &cave[y][x];
1974 /* hack- check to see if square has been visited before
1975 * if so, then exit (use room flag to do this) */
1976 if (c_ptr->info & CAVE_ROOM) return;
1979 c_ptr->info |= CAVE_ROOM;
1981 f_ptr = &f_info[c_ptr->feat];
1983 if (is_floor_bold(y, x))
1985 for (i = -1; i <= 1; i++)
1987 for (j = -1; j <= 1; j++)
1989 if ((x + i >= x1) && (x + i <= x2) &&
1990 (y + j >= y1) && (y + j <= y2))
1992 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
1993 if (light) c_ptr->info |= CAVE_GLOW;
1998 else if (is_extra_bold(y, x))
2000 /* Set bounding walls */
2001 place_outer_bold(y, x);
2002 if (light) c_ptr->info |= CAVE_GLOW;
2004 else if (permanent_wall(f_ptr))
2006 /* Set bounding walls */
2007 if (light) c_ptr->info |= CAVE_GLOW;
2013 * Hacked distance formula - gives the 'wrong' answer.
2014 * Used to build crypts
2016 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
2022 /* Basically this works by taking the normal pythagorean formula
2023 * and using an expansion to express this in a way without the
2024 * square root. This approximate formula is then perturbed to give
2025 * the distorted results. (I found this by making a mistake when I was
2026 * trying to fix the circular rooms.)
2029 /* h1-h4 are constants that describe the metric */
2030 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2031 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2032 return (((dx + dy) * 128) / 181 +
2033 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2034 /* 128/181 is approx. 1/sqrt(2) */
2040 /* Create a new floor room with optional light */
2041 void generate_room_floor(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2047 for (y = y1; y <= y2; y++)
2049 for (x = x1; x <= x2; x++)
2052 c_ptr = &cave[y][x];
2053 place_floor_grid(c_ptr);
2054 c_ptr->info |= (CAVE_ROOM);
2055 if (light) c_ptr->info |= (CAVE_GLOW);
2060 void generate_fill_perm_bold(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2064 for (y = y1; y <= y2; y++)
2066 for (x = x1; x <= x2; x++)
2069 place_inner_perm_bold(y, x);
2076 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2078 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2079 * @return 部屋の精製に成功した場合 TRUE を返す。
2081 static bool room_build(EFFECT_ID typ)
2086 /* Build an appropriate room */
2087 case ROOM_T_NORMAL: return build_type1();
2088 case ROOM_T_OVERLAP: return build_type2();
2089 case ROOM_T_CROSS: return build_type3();
2090 case ROOM_T_INNER_FEAT: return build_type4();
2091 case ROOM_T_NEST: return build_type5();
2092 case ROOM_T_PIT: return build_type6();
2093 case ROOM_T_LESSER_VAULT: return build_type7();
2094 case ROOM_T_GREATER_VAULT: return build_type8();
2095 case ROOM_T_FRACAVE: return build_type9();
2096 case ROOM_T_RANDOM_VAULT: return build_type10();
2097 case ROOM_T_OVAL: return build_type11();
2098 case ROOM_T_CRYPT: return build_type12();
2099 case ROOM_T_TRAP_PIT: return build_type13();
2100 case ROOM_T_TRAP: return build_type14();
2101 case ROOM_T_GLASS: return build_type15();
2102 case ROOM_T_ARCADE: return build_type16();
2103 case ROOM_T_FIXED: return build_type17();
2111 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2112 * @param dst 確率を移す先の部屋種ID
2113 * @param src 確率を与える元の部屋種ID
2115 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2118 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2119 * @return 部屋生成に成功した場合 TRUE を返す。
2121 bool generate_rooms(void)
2127 int prob_list[ROOM_T_MAX];
2128 int rooms_built = 0;
2129 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
2130 int level_index = MIN(10, div_round(dun_level, 10));
2132 /* Number of each type of room on this level */
2133 s16b room_num[ROOM_T_MAX];
2135 /* Limit number of rooms */
2136 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2138 /* Assume normal cave */
2139 room_info_type *room_info_ptr = room_info_normal;
2142 * Initialize probability list.
2144 for (i = 0; i < ROOM_T_MAX; i++)
2146 /* No rooms allowed above their minimum depth. */
2147 if (dun_level < room_info_ptr[i].min_level)
2153 prob_list[i] = room_info_ptr[i].prob[level_index];
2158 * XXX -- Various dungeon types and options.
2161 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2162 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2163 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2164 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2166 for (i = 0; i < ROOM_T_MAX; i++)
2168 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2169 else prob_list[i] = 0;
2173 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2174 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
2176 prob_list[ROOM_T_LESSER_VAULT] = 0;
2177 prob_list[ROOM_T_GREATER_VAULT] = 0;
2178 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2181 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2182 if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
2184 prob_list[ROOM_T_FIXED] = 0;
2187 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2188 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
2190 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2191 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2192 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2195 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
2196 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
2198 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2201 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2202 else if (dun->cavern || dun->empty_level)
2204 prob_list[ROOM_T_FRACAVE] = 0;
2207 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2208 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
2210 prob_list[ROOM_T_GLASS] = 0;
2213 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2214 if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
2216 prob_list[ROOM_T_ARCADE] = 0;
2220 * Initialize number of rooms,
2221 * And calcurate total probability.
2223 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2226 total_prob += prob_list[i];
2230 * Prepare the number of rooms, of all types, we should build
2233 for (i = dun_rooms; i > 0; i--)
2236 int rand = randint0(total_prob);
2238 /* Get room_type randomly */
2239 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2241 if (rand < prob_list[room_type]) break;
2242 else rand -= prob_list[room_type];
2246 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2248 /* Increase the number of rooms of that type we should build. */
2249 room_num[room_type]++;
2255 case ROOM_T_LESSER_VAULT:
2256 case ROOM_T_TRAP_PIT:
2264 case ROOM_T_GREATER_VAULT:
2265 case ROOM_T_RANDOM_VAULT:
2274 * Build each type of room one by one until we cannot build any more.
2275 * [from SAngband (originally from OAngband)]
2279 /* Assume no remaining rooms */
2282 for (i = 0; i < ROOM_T_MAX; i++)
2284 /* What type of room are we building now? */
2285 int room_type = room_build_order[i];
2287 /* Go next if none available */
2288 if (!room_num[room_type]) continue;
2290 /* Use up one unit */
2291 room_num[room_type]--;
2293 /* Build the room. */
2294 if (room_build(room_type))
2296 /* Increase the room built count. */
2299 /* Mark as there was some remaining rooms */
2306 case ROOM_T_TRAP_PIT:
2308 /* Avoid too many monsters */
2311 room_num[ROOM_T_PIT] = 0;
2312 room_num[ROOM_T_NEST] = 0;
2313 room_num[ROOM_T_TRAP_PIT] = 0;
2319 /* Avoid double-town */
2320 room_num[ROOM_T_ARCADE] = 0;
2326 /* End loop if no room remain */
2330 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2331 if (rooms_built < 2)
2333 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2337 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);