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"
57 *[from SAngband (originally from OAngband)]\n
59 * Table of values that control how many times each type of room will\n
60 * appear. Each type of room has its own row, and each column\n
61 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
62 * value is the minimum depth the room can appear at. -LM-\n
64 * Level 101 and below use the values for level 100.\n
66 * Rooms with lots of monsters or loot may not be generated if the\n
67 * object or monster lists are already nearly full. Rooms will not\n
68 * appear above their minimum depth. Tiny levels will not have space\n
69 * for all the rooms you ask for.\n
74 static room_info_type room_info_normal[ROOM_T_MAX] =
77 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
78 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
79 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
80 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
81 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
82 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
83 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
84 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
85 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
86 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
87 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
88 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
89 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
90 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
91 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
92 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
93 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
94 {{ 1, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80}, 1}, /*FIX */
100 static room_info_type room_info_normal[ROOM_T_MAX] =
103 { {999, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0}, 0}, /*NORMAL */
104 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 1 }, /*OVERLAP */
105 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*CROSS */
106 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*INNER_F */
107 { { 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 0}, 10 }, /*NEST */
108 { { 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 0}, 10 }, /*PIT */
109 { { 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 0}, 10 }, /*LESSER_V */
110 { { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 0}, 20 }, /*GREATER_V*/
111 { { 0,100,200,300,400,500,600,700,800,900, 0}, 10 }, /*FRACAVE */
112 { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0}, 10 }, /*RANDOM_V */
113 { { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0}, 3 }, /*OVAL */
114 { { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0}, 10 }, /*CRYPT */
115 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP_PIT */
116 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP */
117 { { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0}, 40 }, /*GLASS */
118 { { 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 0}, 1 }, /*ARCADE */
119 { { 20, 40, 60, 80,100,100,100,100,100,100,100}, 1 }, /*FIX */
126 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
127 static byte room_build_order[ROOM_T_MAX] = {
128 ROOM_T_GREATER_VAULT,
148 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
149 * @param y0 配置したい中心のY座標
150 * @param x0 配置したい中心のX座標
152 * This funtion makes a very small room centred at (x0, y0)
153 * This is used in crypts, and random elemental vaults.
155 * Note - this should be used only on allocated regions
156 * within another room.
158 void build_small_room(POSITION x0, POSITION y0)
162 for (y = y0 - 1; y <= y0 + 1; y++)
164 place_inner_bold(y, x0 - 1);
165 place_inner_bold(y, x0 + 1);
168 for (x = x0 - 1; x <= x0 + 1; x++)
170 place_inner_bold(y0 - 1, x);
171 place_inner_bold(y0 + 1, x);
174 /* Place a secret door on one side */
177 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
178 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
179 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
180 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
183 /* Clear mimic type */
184 cave[y0][x0].mimic = 0;
186 /* Add inner open space */
187 place_floor_bold(y0, x0);
192 * 指定範囲に通路が通っていることを確認した上で床で埋める
193 * This function tunnels around a room if it will cut off part of a cave system.
200 static void check_room_boundary(POSITION x1, POSITION y1, POSITION x2, POSITION y2)
204 bool old_is_floor, new_is_floor;
207 old_is_floor = get_is_floor(x1 - 1, y1);
210 * Count the number of floor-wall boundaries around the room
211 * Note: diagonal squares are ignored since the player can move diagonally
212 * to bypass these if needed.
215 /* Above the top boundary */
216 for (x = x1; x <= x2; x++)
218 new_is_floor = get_is_floor(x, y1 - 1);
220 /* Increment counter if they are different */
221 if (new_is_floor != old_is_floor) count++;
223 old_is_floor = new_is_floor;
227 for (y = y1; y <= y2; y++)
229 new_is_floor = get_is_floor(x2 + 1, y);
231 /* increment counter if they are different */
232 if (new_is_floor != old_is_floor) count++;
234 old_is_floor = new_is_floor;
237 /* Bottom boundary */
238 for (x = x2; x >= x1; x--)
240 new_is_floor = get_is_floor(x, y2 + 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 = y2; y >= y1; y--)
251 new_is_floor = get_is_floor(x1 - 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 /* If all the same, or only one connection exit. */
260 if (count <= 2) return;
263 /* Tunnel around the room so to prevent problems with caves */
264 for (y = y1; y <= y2; y++)
266 for (x = x1; x <= x2; x++)
276 * find_space()の予備処理として部屋の生成が可能かを判定する /
277 * Helper function for find_space(). Is this a good location?
278 * @param blocks_high 範囲の高さ
279 * @param blocks_wide 範囲の幅
280 * @param block_y 範囲の上端
281 * @param block_x 範囲の左端
284 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
286 POSITION by1, bx1, by2, bx2, by, bx;
288 /* Itty-bitty rooms must shift about within their rectangle */
291 if ((blocks_wide == 2) && (block_x % 3) == 2)
295 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
296 else if ((blocks_wide % 3) == 0)
298 /* Must be aligned to the left edge of a 11x33 rectangle. */
299 if ((block_x % 3) != 0)
304 * Big rooms that do not have a width divisible by 3 must be
305 * aligned towards the edge of the dungeon closest to them.
309 /* Shift towards left edge of dungeon. */
310 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
312 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
314 if ((block_x % 3) == 1)
318 /* Shift toward right edge of dungeon. */
321 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
323 if ((block_x % 3) == 1)
331 by2 = block_y + blocks_high;
332 bx2 = block_x + blocks_wide;
334 /* Never run off the screen */
335 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
336 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
338 /* Verify available space */
339 for (by = by1; by < by2; by++)
341 for (bx = bx1; bx < bx2; bx++)
343 if (dun->room_map[by][bx])
350 /* This location is okay */
356 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
357 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
358 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
359 * @param height 確保したい領域の高さ
360 * @param width 確保したい領域の幅
361 * @return 所定の範囲が確保できた場合TRUEを返す
363 * Find and allocate a free space in the dungeon large enough to hold\n
364 * the room calling this function.\n
366 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
367 * align neatly on the standard screen. Therefore, we make them use\n
368 * blocks in few 11x33 rectangles as possible.\n
370 * Be careful to include the edges of the room in height and width!\n
372 * Return TRUE and values for the center of the room if all went well.\n
373 * Otherwise, return FALSE.\n
375 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
377 int candidates, pick;
378 POSITION by, bx, by1, bx1, by2, bx2;
379 POSITION block_y = 0, block_x = 0;
381 /* Find out how many blocks we need. */
382 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
383 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
385 /* There are no way to allocate such huge space */
386 if (dun->row_rooms < blocks_high) return FALSE;
387 if (dun->col_rooms < blocks_wide) return FALSE;
392 /* Count the number of valid places */
393 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
395 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
397 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
399 /* Find a valid place */
412 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
414 /* Choose a random one */
415 pick = randint1(candidates);
418 /* NO_CAVE dungeon (Castle) */
421 /* Always choose the center one */
422 pick = candidates/2 + 1;
425 /* Pick up the choosen location */
426 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
428 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
430 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
434 /* This one is picked? */
445 by2 = block_y + blocks_high;
446 bx2 = block_x + blocks_wide;
449 * It is *extremely* important that the following calculation
450 * be *exactly* correct to prevent memory errors
453 /* Acquire the location of the room */
454 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
455 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
457 /* Save the room location */
458 if (dun->cent_n < CENT_MAX)
460 dun->cent[dun->cent_n].y = (byte_hack)*y;
461 dun->cent[dun->cent_n].x = (byte_hack)*x;
465 /* Reserve some blocks. */
466 for (by = by1; by < by2; by++)
468 for (bx = bx1; bx < bx2; bx++)
470 dun->room_map[by][bx] = TRUE;
475 * Hack- See if room will cut off a cavern.
477 * If so, fix by tunneling outside the room in such a
478 * way as to connect the caves.
480 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
488 * Structure to hold all "fill" data
491 typedef struct fill_data_type fill_data_type;
493 struct fill_data_type
506 /* features to fill with */
515 /* number of filled squares */
519 static fill_data_type fill_data;
522 /* Store routine for the fractal cave generator */
523 /* this routine probably should be an inline function or a macro. */
524 static void store_height(POSITION x, POSITION y, FEAT_IDX val)
526 /* if on boundary set val > cutoff so walls are not as square */
527 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
528 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
529 (val <= fill_data.c1)) val = fill_data.c1 + 1;
531 /* store the value in height-map format */
532 cave[y][x].feat = val;
539 * Explanation of the plasma fractal algorithm:
541 * A grid of points is created with the properties of a 'height-map'
542 * This is done by making the corners of the grid have a random value.
543 * The grid is then subdivided into one with twice the resolution.
544 * The new points midway between two 'known' points can be calculated
545 * by taking the average value of the 'known' ones and randomly adding
546 * or subtracting an amount proportional to the distance between those
547 * points. The final 'middle' points of the grid are then calculated
548 * by averaging all four of the originally 'known' corner points. An
549 * random amount is added or subtracted from this to get a value of the
550 * height at that point. The scaling factor here is adjusted to the
551 * slightly larger distance diagonally as compared to orthogonally.
553 * This is then repeated recursively to fill an entire 'height-map'
554 * A rectangular map is done the same way, except there are different
555 * scaling factors along the x and y directions.
557 * A hack to change the amount of correlation between points is done using
558 * the grd variable. If the current step size is greater than grd then
559 * the point will be random, otherwise it will be calculated by the
560 * above algorithm. This makes a maximum distance at which two points on
561 * the height map can affect each other.
563 * How fractal caves are made:
565 * When the map is complete, a cut-off value is used to create a cave.
566 * Heights below this value are "floor", and heights above are "wall".
567 * This also can be used to create lakes, by adding more height levels
568 * representing shallow and deep water/ lava etc.
570 * The grd variable affects the width of passages.
571 * The roug variable affects the roughness of those passages
573 * The tricky part is making sure the created cave is connected. This
574 * is done by 'filling' from the inside and only keeping the 'filled'
575 * floor. Walls bounding the 'filled' floor are also kept. Everything
576 * else is converted to the normal _extra_.
581 * Note that this uses the cave.feat array in a very hackish way
582 * the values are first set to zero, and then each array location
583 * is used as a "heightmap"
584 * The heightmap then needs to be converted back into the "feat" format.
586 * grd=level at which fractal turns on. smaller gives more mazelike caves
587 * roug=roughness level. 16=normal. higher values make things more convoluted
588 * small values are good for smooth walls.
589 * size=length of the side of the square cave system.
591 void generate_hmap(POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
593 POSITION xhsize, yhsize, xsize, ysize, maxsize;
596 * fixed point variables- these are stored as 256 x normal value
597 * this gives 8 binary places of fractional part + 8 places of normal part
600 POSITION xstep, xhstep, ystep, yhstep;
601 POSITION xstep2, xhstep2, ystep2, yhstep2;
602 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
604 /* Cache for speed */
605 POSITION xm, xp, ym, yp;
607 /* redefine size so can change the value if out of range */
611 /* Paranoia about size of the system of caves */
612 if (xsize > 254) xsize = 254;
613 if (xsize < 4) xsize = 4;
614 if (ysize > 254) ysize = 254;
615 if (ysize < 4) ysize = 4;
617 /* get offsets to middle of array */
621 /* fix rounding problem */
625 /* get limits of region */
626 fill_data.xmin = x0 - xhsize;
627 fill_data.ymin = y0 - yhsize;
628 fill_data.xmax = x0 + xhsize;
629 fill_data.ymax = y0 + yhsize;
631 /* Store cutoff in global for quick access */
632 fill_data.c1 = cutoff;
635 * Scale factor for middle points:
636 * About sqrt(2) * 256 - correct for a square lattice
637 * approximately correct for everything else.
641 /* maximum of xsize and ysize */
642 maxsize = (xsize > ysize) ? xsize : ysize;
644 /* Clear the section */
645 for (i = 0; i <= xsize; i++)
647 for (j = 0; j <= ysize; j++)
649 /* -1 is a flag for "not done yet" */
650 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
651 /* Clear icky flag because may be redoing the cave */
652 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
656 /* Boundaries are walls */
657 cave[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
658 cave[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
659 cave[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
660 cave[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
662 /* Set the middle square to be an open area. */
663 cave[y0][x0].feat = 0;
665 /* Initialize the step sizes */
666 xstep = xhstep = xsize * 256;
667 ystep = yhstep = ysize * 256;
668 xxsize = xsize * 256;
669 yysize = ysize * 256;
672 * Fill in the rectangle with fractal height data -
673 * like the 'plasma fractal' in fractint.
675 while ((xhstep > 256) || (yhstep > 256))
677 /* Halve the step sizes */
683 /* cache well used values */
684 xstep2 = xstep / 256;
685 ystep2 = ystep / 256;
687 xhstep2 = xhstep / 256;
688 yhstep2 = yhstep / 256;
690 /* middle top to bottom. */
691 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
693 for (j = 0; j <= yysize; j += ystep)
695 /* cache often used values */
696 ii = i / 256 + fill_data.xmin;
697 jj = j / 256 + fill_data.ymin;
700 if (cave[jj][ii].feat == -1)
704 /* If greater than 'grid' level then is random */
705 store_height(ii, jj, randint1(maxsize));
709 /* Average of left and right points +random bit */
711 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
712 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
713 + (randint1(xstep2) - xhstep2) * roug / 16);
720 /* middle left to right. */
721 for (j = yhstep; j <= yysize - yhstep; j += ystep)
723 for (i = 0; i <= xxsize; i += xstep)
725 /* cache often used values */
726 ii = i / 256 + fill_data.xmin;
727 jj = j / 256 + fill_data.ymin;
730 if (cave[jj][ii].feat == -1)
734 /* If greater than 'grid' level then is random */
735 store_height(ii, jj, randint1(maxsize));
739 /* Average of up and down points +random bit */
741 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
742 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
743 + (randint1(ystep2) - yhstep2) * roug / 16);
750 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
752 for (j = yhstep; j <= yysize - yhstep; j += ystep)
754 /* cache often used values */
755 ii = i / 256 + fill_data.xmin;
756 jj = j / 256 + fill_data.ymin;
759 if (cave[jj][ii].feat == -1)
763 /* If greater than 'grid' level then is random */
764 store_height(ii, jj, randint1(maxsize));
768 /* Cache reused values. */
769 xm = fill_data.xmin + (i - xhstep) / 256;
770 xp = fill_data.xmin + (i + xhstep) / 256;
771 ym = fill_data.ymin + (j - yhstep) / 256;
772 yp = fill_data.ymin + (j + yhstep) / 256;
775 * Average over all four corners + scale by diagsize to
776 * reduce the effect of the square grid on the shape of the fractal
779 (cave[ym][xm].feat + cave[yp][xm].feat
780 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
781 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
790 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)
793 * function used to convert from height-map back to the
794 * normal angband cave format
796 if (cave[y][x].info & CAVE_ICKY)
803 /* Show that have looked at this square */
804 cave[y][x].info|= (CAVE_ICKY);
806 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
807 if (cave[y][x].feat <= c1)
809 /* 25% of the time use the other tile : it looks better this way */
810 if (randint1(100) < 75)
812 cave[y][x].feat = feat1;
813 cave[y][x].info &= ~(CAVE_MASK);
814 cave[y][x].info |= info1;
819 cave[y][x].feat = feat2;
820 cave[y][x].info &= ~(CAVE_MASK);
821 cave[y][x].info |= info2;
825 else if (cave[y][x].feat <= c2)
827 /* 25% of the time use the other tile : it looks better this way */
828 if (randint1(100) < 75)
830 cave[y][x].feat = feat2;
831 cave[y][x].info &= ~(CAVE_MASK);
832 cave[y][x].info |= info2;
837 cave[y][x].feat = feat1;
838 cave[y][x].info &= ~(CAVE_MASK);
839 cave[y][x].info |= info1;
843 else if (cave[y][x].feat <= c3)
845 cave[y][x].feat = feat3;
846 cave[y][x].info &= ~(CAVE_MASK);
847 cave[y][x].info |= info3;
850 /* if greater than cutoff then is a wall */
853 place_outer_bold(y, x);
863 * Quick and nasty fill routine used to find the connected region
864 * of floor in the middle of the cave
866 static void cave_fill(POSITION y, POSITION x)
877 /* Enqueue that entry */
881 /* Now process the queue */
882 while (flow_head != flow_tail)
884 /* Extract the next entry */
885 ty = temp_y[flow_head];
886 tx = temp_x[flow_head];
888 /* Forget that entry */
889 if (++flow_head == TEMP_MAX) flow_head = 0;
891 /* Add the "children" */
892 for (d = 0; d < 8; d++)
894 int old_head = flow_tail;
900 /* Paranoia Don't leave the cave */
901 if (!in_bounds(j, i))
903 /* affect boundary */
904 cave[j][i].info |= CAVE_ICKY;
908 /* If within bounds */
909 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
910 && (j > fill_data.ymin) && (j < fill_data.ymax))
912 /* If not a wall or floor done before */
913 if (hack_isnt_wall(j, i,
914 fill_data.c1, fill_data.c2, fill_data.c3,
915 fill_data.feat1, fill_data.feat2, fill_data.feat3,
916 fill_data.info1, fill_data.info2, fill_data.info3))
918 /* Enqueue that entry */
919 temp_y[flow_tail] = (byte_hack)j;
920 temp_x[flow_tail] = (byte_hack)i;
922 /* Advance the queue */
923 if (++flow_tail == TEMP_MAX) flow_tail = 0;
925 /* Hack -- Overflow by forgetting new entry */
926 if (flow_tail == flow_head)
928 flow_tail = old_head;
932 /* keep tally of size of cave system */
933 (fill_data.amount)++;
939 /* affect boundary */
940 cave[j][i].info |= CAVE_ICKY;
947 bool generate_fracave(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
949 POSITION x, y, xhsize, yhsize;
952 /* offsets to middle from corner */
958 * select region connected to center of cave system
959 * this gets rid of alot of isolated one-sqaures that
960 * can make teleport traps instadeaths...
964 fill_data.c1 = cutoff;
968 /* features to fill with */
969 fill_data.feat1 = floor_type[randint0(100)];
970 fill_data.feat2 = floor_type[randint0(100)];
971 fill_data.feat3 = floor_type[randint0(100)];
973 fill_data.info1 = CAVE_FLOOR;
974 fill_data.info2 = CAVE_FLOOR;
975 fill_data.info3 = CAVE_FLOOR;
977 /* number of filled squares */
978 fill_data.amount = 0;
980 cave_fill((byte)y0, (byte)x0);
982 /* if tally too small, try again */
983 if (fill_data.amount < 10)
985 /* too small - clear area and try again later */
986 for (x = 0; x <= xsize; ++x)
988 for (y = 0; y <= ysize; ++y)
990 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
991 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
998 * Do boundarys-check to see if they are next to a filled region
999 * If not then they are set to normal granite
1000 * If so then they are marked as room walls.
1002 for (i = 0; i <= xsize; ++i)
1005 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1007 /* Next to a 'filled' region? - set to be room walls */
1008 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1009 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1010 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1011 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1015 /* set to be normal granite */
1016 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1019 /* bottom boundary */
1020 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1022 /* Next to a 'filled' region? - set to be room walls */
1023 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1024 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1025 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1026 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1030 /* set to be normal granite */
1031 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1034 /* clear the icky flag-don't need it any more */
1035 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1036 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1039 /* Do the left and right boundaries minus the corners (done above) */
1040 for (i = 1; i < ysize; ++i)
1043 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1046 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1047 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1048 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1049 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1054 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1056 /* right boundary */
1057 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1060 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1061 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1062 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1063 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1068 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1071 /* clear icky flag -done with it */
1072 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1073 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1077 /* Do the rest: convert back to the normal format */
1078 for (x = 1; x < xsize; ++x)
1080 for (y = 1; y < ysize; ++y)
1082 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1083 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1085 /* Clear the icky flag in the filled region */
1086 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1088 /* Set appropriate flags */
1089 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1090 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1092 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1093 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1096 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1097 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1100 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1105 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1106 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1111 /* Clear the unconnected regions */
1112 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1113 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1119 * There is a slight problem when tunnels pierce the caves:
1120 * Extra doors appear inside the system. (Its not very noticeable though.)
1121 * This can be removed by "filling" from the outside in. This allows a separation
1122 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1123 * The extra effort for what seems to be only a minor thing (even non-existant if you
1124 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1132 #ifdef ALLOW_CAVERNS_AND_LAKES
1134 * Builds a cave system in the center of the dungeon.
1136 void build_cavern(void)
1138 int grd, roug, cutoff;
1139 POSITION xsize, ysize, x0, y0;
1142 light = done = FALSE;
1143 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1145 /* Make a cave the size of the dungeon */
1146 xsize = cur_wid - 1;
1147 ysize = cur_hgt - 1;
1151 /* Paranoia: make size even */
1157 /* testing values for these parameters: feel free to adjust */
1158 grd = randint1(4) + 4;
1160 /* want average of about 16 */
1161 roug = randint1(8) * randint1(4);
1167 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1169 /* Convert to normal format+ clean up */
1170 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1174 bool generate_lake(POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1176 POSITION x, y, xhsize, yhsize;
1178 FEAT_IDX feat1, feat2, feat3;
1180 /* offsets to middle from corner */
1184 /* Get features based on type */
1187 case LAKE_T_LAVA: /* Lava */
1188 feat1 = feat_deep_lava;
1189 feat2 = feat_shallow_lava;
1190 feat3 = floor_type[randint0(100)];
1192 case LAKE_T_WATER: /* Water */
1193 feat1 = feat_deep_water;
1194 feat2 = feat_shallow_water;
1195 feat3 = floor_type[randint0(100)];
1197 case LAKE_T_CAVE: /* Collapsed cave */
1198 feat1 = floor_type[randint0(100)];
1199 feat2 = floor_type[randint0(100)];
1200 feat3 = feat_rubble;
1202 case LAKE_T_EARTH_VAULT: /* Earth vault */
1203 feat1 = feat_rubble;
1204 feat2 = floor_type[randint0(100)];
1205 feat3 = feat_rubble;
1207 case LAKE_T_AIR_VAULT: /* Air vault */
1212 case LAKE_T_WATER_VAULT: /* Water vault */
1213 feat1 = feat_shallow_water;
1214 feat2 = feat_deep_water;
1215 feat3 = feat_shallow_water;
1217 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1218 feat1 = feat_shallow_lava;
1219 feat2 = feat_deep_lava;
1220 feat3 = feat_shallow_lava;
1224 default: return FALSE;
1228 * select region connected to center of cave system
1229 * this gets rid of alot of isolated one-sqaures that
1230 * can make teleport traps instadeaths...
1238 /* features to fill with */
1239 fill_data.feat1 = feat1;
1240 fill_data.feat2 = feat2;
1241 fill_data.feat3 = feat3;
1243 fill_data.info1 = 0;
1244 fill_data.info2 = 0;
1245 fill_data.info3 = 0;
1247 /* number of filled squares */
1248 fill_data.amount = 0;
1250 /* select region connected to center of cave system
1251 * this gets rid of alot of isolated one-sqaures that
1252 * can make teleport traps instadeaths... */
1253 cave_fill((byte)y0, (byte)x0);
1255 /* if tally too small, try again */
1256 if (fill_data.amount < 10)
1258 /* too small -clear area and try again later */
1259 for (x = 0; x <= xsize; ++x)
1261 for (y = 0; y <= ysize; ++y)
1263 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1264 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1270 /* Do boundarys- set to normal granite */
1271 for (i = 0; i <= xsize; ++i)
1273 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1274 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1276 /* clear the icky flag-don't need it any more */
1277 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1278 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1281 /* Do the left and right boundaries minus the corners (done above) */
1283 for (i = 1; i < ysize; ++i)
1285 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1286 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1288 /* clear icky flag -done with it */
1289 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1290 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1294 /* Do the rest: convert back to the normal format */
1295 for (x = 1; x < xsize; ++x)
1297 for (y = 1; y < ysize; ++y)
1299 /* Fill unconnected regions with granite */
1300 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1301 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
1302 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1304 /* turn off icky flag (no longer needed.) */
1305 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1308 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1310 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1320 * makes a lake/collapsed cave system in the center of the dungeon
1322 void build_lake(int type)
1324 int grd, roug, xsize, ysize, x0, y0;
1328 /* paranoia - exit if lake type out of range. */
1329 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1331 msg_format("Invalid lake type (%d)", type);
1335 /* Make the size of the dungeon */
1336 xsize = cur_wid - 1;
1337 ysize = cur_hgt - 1;
1341 /* Paranoia: make size even */
1347 /* testing values for these parameters: feel free to adjust */
1348 grd = randint1(3) + 4;
1350 /* want average of about 16 */
1351 roug = randint1(8) * randint1(4);
1353 /* Make up size of various componants */
1357 /* Deep water/lava */
1358 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1360 /* Shallow boundary */
1364 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1366 /* Convert to normal format+ clean up */
1367 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1370 #endif /* ALLOW_CAVERNS_AND_LAKES */
1375 * Routine that fills the empty areas of a room with treasure and monsters.
1377 void fill_treasure(POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1379 POSITION x, y, cx, cy, size;
1382 /* center of room:*/
1386 /* Rough measure of size of vault= sum of lengths of sides */
1387 size = abs(x2 - x1) + abs(y2 - y1);
1389 for (x = x1; x <= x2; x++)
1391 for (y = y1; y <= y2; y++)
1393 /* Thing added based on distance to center of vault
1394 * Difficulty is 1-easy to 10-hard */
1395 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1397 /* hack- empty square part of the time */
1398 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1400 /* if floor, shallow water and lava */
1401 if (is_floor_bold(y, x) ||
1402 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1404 /* The smaller 'value' is, the better the stuff */
1407 /* Meanest monster + treasure */
1408 monster_level = base_level + 40;
1409 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1410 monster_level = base_level;
1411 object_level = base_level + 20;
1412 place_object(y, x, AM_GOOD);
1413 object_level = base_level;
1417 /* Mean monster +treasure */
1418 monster_level = base_level + 20;
1419 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1420 monster_level = base_level;
1421 object_level = base_level + 10;
1422 place_object(y, x, AM_GOOD);
1423 object_level = base_level;
1425 else if (value < 10)
1428 monster_level = base_level + 9;
1429 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1430 monster_level = base_level;
1432 else if (value < 17)
1434 /* Intentional Blank space */
1437 * (Want some of the vault to be empty
1438 * so have room for group monsters.
1439 * This is used in the hack above to lower
1440 * the density of stuff in the vault.)
1443 else if (value < 23)
1445 /* Object or trap */
1446 if (randint0(100) < 25)
1448 place_object(y, x, 0L);
1455 else if (value < 30)
1457 /* Monster and trap */
1458 monster_level = base_level + 5;
1459 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1460 monster_level = base_level;
1463 else if (value < 40)
1465 /* Monster or object */
1466 if (randint0(100) < 50)
1468 monster_level = base_level + 3;
1469 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1470 monster_level = base_level;
1472 if (randint0(100) < 50)
1474 object_level = base_level + 7;
1475 place_object(y, x, 0L);
1476 object_level = base_level;
1479 else if (value < 50)
1488 /* 20% monster, 40% trap, 20% object, 20% blank space */
1489 if (randint0(100) < 20)
1491 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1493 else if (randint0(100) < 50)
1497 else if (randint0(100) < 50)
1499 place_object(y, x, 0L);
1511 * Overlay a rectangular room given its bounds
1512 * This routine is used by build_room_vault
1513 * The area inside the walls is not touched:
1514 * only granite is removed- normal walls stay
1516 void build_room(POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1518 POSITION x, y, xsize, ysize;
1521 /* Check if rectangle has no width */
1522 if ((x1 == x2) || (y1 == y2)) return;
1526 /* Swap boundaries if in wrong order */
1534 /* Swap boundaries if in wrong order */
1540 /* get total widths */
1545 /* Top and bottom boundaries */
1546 for (i = 0; i <= xsize; i++)
1548 place_outer_noperm_bold(y1, x1 + i);
1549 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1550 place_outer_noperm_bold(y2, x1 + i);
1551 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1554 /* Left and right boundaries */
1555 for (i = 1; i < ysize; i++)
1557 place_outer_noperm_bold(y1 + i, x1);
1558 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1559 place_outer_noperm_bold(y1 + i, x2);
1560 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1564 for (x = 1; x < xsize; x++)
1566 for (y = 1; y < ysize; y++)
1568 if (is_extra_bold(y1+y, x1+x))
1570 /* clear the untouched region */
1571 place_floor_bold(y1 + y, x1 + x);
1572 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1576 /* make it a room- but don't touch */
1577 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1586 * maze vault -- rectangular labyrinthine rooms
1588 * maze vault uses two routines:
1589 * r_visit - a recursive routine that builds the labyrinth
1590 * build_maze_vault - a driver routine that calls r_visit and adds
1591 * monsters, traps and treasure
1593 * The labyrinth is built by creating a spanning tree of a graph.
1594 * The graph vertices are at
1595 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1596 * and the edges are the vertical and horizontal nearest neighbors.
1598 * The spanning tree is created by performing a suitably randomized
1599 * depth-first traversal of the graph. The only adjustable parameter
1600 * is the randint0(3) below; it governs the relative density of
1601 * twists and turns in the labyrinth: smaller number, more twists.
1603 void r_visit(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1605 int i, j, m, n, temp, x, y, adj[4];
1607 /* dimensions of vertex array */
1608 m = (x2 - x1) / 2 + 1;
1609 n = (y2 - y1) / 2 + 1;
1611 /* mark node visited and set it to a floor */
1613 x = 2 * (node % m) + x1;
1614 y = 2 * (node / m) + y1;
1615 place_floor_bold(y, x);
1617 /* setup order of adjacent node visits */
1620 /* pick a random ordering */
1621 for (i = 0; i < 4; i++)
1623 for (i = 0; i < 4; i++)
1634 /* pick a random ordering with dir first */
1636 for (i = 1; i < 4; i++)
1638 for (i = 1; i < 4; i++)
1640 j = 1 + randint0(3);
1647 for (i = 0; i < 4; i++)
1652 /* (0,+) - check for bottom boundary */
1653 if ((node / m < n - 1) && (visited[node + m] == 0))
1655 place_floor_bold(y + 1, x);
1656 r_visit(y1, x1, y2, x2, node + m, dir, visited);
1660 /* (0,-) - check for top boundary */
1661 if ((node / m > 0) && (visited[node - m] == 0))
1663 place_floor_bold(y - 1, x);
1664 r_visit(y1, x1, y2, x2, node - m, dir, visited);
1668 /* (+,0) - check for right boundary */
1669 if ((node % m < m - 1) && (visited[node + 1] == 0))
1671 place_floor_bold(y, x + 1);
1672 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
1676 /* (-,0) - check for left boundary */
1677 if ((node % m > 0) && (visited[node - 1] == 0))
1679 place_floor_bold(y, x - 1);
1680 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
1687 void build_maze_vault(POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1689 POSITION y, x, dy, dx;
1690 POSITION y1, x1, y2, x2;
1691 int m, n, num_vertices, *visited;
1695 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1697 /* Choose lite or dark */
1698 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1700 /* Pick a random room size - randomized by calling routine */
1709 /* generate the room */
1710 for (y = y1 - 1; y <= y2 + 1; y++)
1712 for (x = x1 - 1; x <= x2 + 1; x++)
1714 c_ptr = &cave[y][x];
1715 c_ptr->info |= CAVE_ROOM;
1716 if (is_vault) c_ptr->info |= CAVE_ICKY;
1717 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1719 place_outer_grid(c_ptr);
1723 place_extra_grid(c_ptr);
1727 place_inner_grid(c_ptr);
1729 if (light) c_ptr->info |= (CAVE_GLOW);
1733 /* dimensions of vertex array */
1736 num_vertices = m * n;
1738 /* initialize array of visited vertices */
1739 C_MAKE(visited, num_vertices, int);
1741 /* traverse the graph to create a spaning tree, pick a random root */
1742 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1744 /* Fill with monsters and treasure, low difficulty */
1745 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
1747 C_KILL(visited, num_vertices, int);
1751 /* Build a town/ castle by using a recursive algorithm.
1752 * Basically divide each region in a probalistic way to create
1753 * smaller regions. When the regions get too small stop.
1755 * The power variable is a measure of how well defended a region is.
1756 * This alters the possible choices.
1758 void build_recursive_room(POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1760 POSITION xsize, ysize;
1764 /* Temp variables */
1770 if ((power < 3) && (xsize > 12) && (ysize > 12))
1772 /* Need outside wall +keep */
1779 /* Make rooms + subdivide */
1780 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1786 choice = randint1(2) + 1;
1791 /* Mostly subdivide */
1792 choice = randint1(3) + 1;
1796 /* Based on the choice made above, do something */
1804 /* top and bottom */
1805 for (x = x1; x <= x2; x++)
1807 place_outer_bold(y1, x);
1808 place_outer_bold(y2, x);
1811 /* left and right */
1812 for (y = y1 + 1; y < y2; y++)
1814 place_outer_bold(y, x1);
1815 place_outer_bold(y, x2);
1818 /* Make a couple of entrances */
1821 /* left and right */
1822 y = randint1(ysize) + y1;
1823 place_floor_bold(y, x1);
1824 place_floor_bold(y, x2);
1828 /* top and bottom */
1829 x = randint1(xsize) + x1;
1830 place_floor_bold(y1, x);
1831 place_floor_bold(y2, x);
1834 /* Select size of keep */
1835 t1 = randint1(ysize / 3) + y1;
1836 t2 = y2 - randint1(ysize / 3);
1837 t3 = randint1(xsize / 3) + x1;
1838 t4 = x2 - randint1(xsize / 3);
1840 /* Do outside areas */
1842 /* Above and below keep */
1843 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1844 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
1846 /* Left and right of keep */
1847 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1848 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1850 /* Make the keep itself: */
1863 /* Try to build a room */
1864 if ((xsize < 3) || (ysize < 3))
1866 for (y = y1; y < y2; y++)
1868 for (x = x1; x < x2; x++)
1870 place_inner_bold(y, x);
1878 /* Make outside walls */
1879 /* top and bottom */
1880 for (x = x1 + 1; x <= x2 - 1; x++)
1882 place_inner_bold(y1 + 1, x);
1883 place_inner_bold(y2 - 1, x);
1886 /* left and right */
1887 for (y = y1 + 1; y <= y2 - 1; y++)
1889 place_inner_bold(y, x1 + 1);
1890 place_inner_bold(y, x2 - 1);
1894 y = randint1(ysize - 3) + y1 + 1;
1899 place_floor_bold(y, x1 + 1);
1904 place_floor_bold(y, x2 - 1);
1907 /* Build the room */
1908 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1913 /* Try and divide vertically */
1917 for (y = y1; y < y2; y++)
1919 for (x = x1; x < x2; x++)
1921 place_inner_bold(y, x);
1927 t1 = randint1(xsize - 2) + x1 + 1;
1928 build_recursive_room(x1, y1, t1, y2, power - 2);
1929 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
1934 /* Try and divide horizontally */
1938 for (y = y1; y < y2; y++)
1940 for (x = x1; x < x2; x++)
1942 place_inner_bold(y, x);
1948 t1 = randint1(ysize - 2) + y1 + 1;
1949 build_recursive_room(x1, y1, x2, t1, power - 2);
1950 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
1958 * Add outer wall to a floored region
1959 * Note: no range checking is done so must be inside dungeon
1960 * This routine also stomps on doors
1962 void add_outer_wall(POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1965 feature_type *f_ptr;
1968 if (!in_bounds(y, x)) return;
1970 c_ptr = &cave[y][x];
1972 /* hack- check to see if square has been visited before
1973 * if so, then exit (use room flag to do this) */
1974 if (c_ptr->info & CAVE_ROOM) return;
1977 c_ptr->info |= CAVE_ROOM;
1979 f_ptr = &f_info[c_ptr->feat];
1981 if (is_floor_bold(y, x))
1983 for (i = -1; i <= 1; i++)
1985 for (j = -1; j <= 1; j++)
1987 if ((x + i >= x1) && (x + i <= x2) &&
1988 (y + j >= y1) && (y + j <= y2))
1990 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
1991 if (light) c_ptr->info |= CAVE_GLOW;
1996 else if (is_extra_bold(y, x))
1998 /* Set bounding walls */
1999 place_outer_bold(y, x);
2000 if (light) c_ptr->info |= CAVE_GLOW;
2002 else if (permanent_wall(f_ptr))
2004 /* Set bounding walls */
2005 if (light) c_ptr->info |= CAVE_GLOW;
2011 * Hacked distance formula - gives the 'wrong' answer.
2012 * Used to build crypts
2014 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
2020 /* Basically this works by taking the normal pythagorean formula
2021 * and using an expansion to express this in a way without the
2022 * square root. This approximate formula is then perturbed to give
2023 * the distorted results. (I found this by making a mistake when I was
2024 * trying to fix the circular rooms.)
2027 /* h1-h4 are constants that describe the metric */
2028 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2029 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2030 return (((dx + dy) * 128) / 181 +
2031 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2032 /* 128/181 is approx. 1/sqrt(2) */
2038 /* Create a new floor room with optional light */
2039 void generate_room_floor(POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2045 for (y = y1; y <= y2; y++)
2047 for (x = x1; x <= x2; x++)
2050 c_ptr = &cave[y][x];
2051 place_floor_grid(c_ptr);
2052 c_ptr->info |= (CAVE_ROOM);
2053 if (light) c_ptr->info |= (CAVE_GLOW);
2058 void generate_fill_perm_bold(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2062 for (y = y1; y <= y2; y++)
2064 for (x = x1; x <= x2; x++)
2067 place_inner_perm_bold(y, x);
2074 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2076 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2077 * @return 部屋の精製に成功した場合 TRUE を返す。
2079 static bool room_build(EFFECT_ID typ)
2084 /* Build an appropriate room */
2085 case ROOM_T_NORMAL: return build_type1();
2086 case ROOM_T_OVERLAP: return build_type2();
2087 case ROOM_T_CROSS: return build_type3();
2088 case ROOM_T_INNER_FEAT: return build_type4();
2089 case ROOM_T_NEST: return build_type5();
2090 case ROOM_T_PIT: return build_type6();
2091 case ROOM_T_LESSER_VAULT: return build_type7();
2092 case ROOM_T_GREATER_VAULT: return build_type8();
2093 case ROOM_T_FRACAVE: return build_type9();
2094 case ROOM_T_RANDOM_VAULT: return build_type10();
2095 case ROOM_T_OVAL: return build_type11();
2096 case ROOM_T_CRYPT: return build_type12();
2097 case ROOM_T_TRAP_PIT: return build_type13();
2098 case ROOM_T_TRAP: return build_type14();
2099 case ROOM_T_GLASS: return build_type15();
2100 case ROOM_T_ARCADE: return build_type16();
2101 case ROOM_T_FIXED: return build_type17();
2109 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2110 * @param dst 確率を移す先の部屋種ID
2111 * @param src 確率を与える元の部屋種ID
2113 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2116 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2117 * @return 部屋生成に成功した場合 TRUE を返す。
2119 bool generate_rooms(void)
2125 int prob_list[ROOM_T_MAX];
2126 int rooms_built = 0;
2127 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
2128 int level_index = MIN(10, div_round(dun_level, 10));
2130 /* Number of each type of room on this level */
2131 s16b room_num[ROOM_T_MAX];
2133 /* Limit number of rooms */
2134 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2136 /* Assume normal cave */
2137 room_info_type *room_info_ptr = room_info_normal;
2140 * Initialize probability list.
2142 for (i = 0; i < ROOM_T_MAX; i++)
2144 /* No rooms allowed above their minimum depth. */
2145 if (dun_level < room_info_ptr[i].min_level)
2151 prob_list[i] = room_info_ptr[i].prob[level_index];
2156 * XXX -- Various dungeon types and options.
2159 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2160 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2161 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2162 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2164 for (i = 0; i < ROOM_T_MAX; i++)
2166 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2167 else prob_list[i] = 0;
2171 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2172 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
2174 prob_list[ROOM_T_LESSER_VAULT] = 0;
2175 prob_list[ROOM_T_GREATER_VAULT] = 0;
2176 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2179 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2180 if (d_info[dungeon_type].flags1 & DF1_BEGINNER)
2182 prob_list[ROOM_T_FIXED] = 0;
2185 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2186 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
2188 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2189 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2190 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2193 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
2194 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
2196 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2199 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2200 else if (dun->cavern || dun->empty_level)
2202 prob_list[ROOM_T_FRACAVE] = 0;
2205 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2206 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
2208 prob_list[ROOM_T_GLASS] = 0;
2211 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2212 if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
2214 prob_list[ROOM_T_ARCADE] = 0;
2218 * Initialize number of rooms,
2219 * And calcurate total probability.
2221 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2224 total_prob += prob_list[i];
2228 * Prepare the number of rooms, of all types, we should build
2231 for (i = dun_rooms; i > 0; i--)
2234 int rand = randint0(total_prob);
2236 /* Get room_type randomly */
2237 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2239 if (rand < prob_list[room_type]) break;
2240 else rand -= prob_list[room_type];
2244 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2246 /* Increase the number of rooms of that type we should build. */
2247 room_num[room_type]++;
2253 case ROOM_T_LESSER_VAULT:
2254 case ROOM_T_TRAP_PIT:
2262 case ROOM_T_GREATER_VAULT:
2263 case ROOM_T_RANDOM_VAULT:
2272 * Build each type of room one by one until we cannot build any more.
2273 * [from SAngband (originally from OAngband)]
2277 /* Assume no remaining rooms */
2280 for (i = 0; i < ROOM_T_MAX; i++)
2282 /* What type of room are we building now? */
2283 int room_type = room_build_order[i];
2285 /* Go next if none available */
2286 if (!room_num[room_type]) continue;
2288 /* Use up one unit */
2289 room_num[room_type]--;
2291 /* Build the room. */
2292 if (room_build(room_type))
2294 /* Increase the room built count. */
2297 /* Mark as there was some remaining rooms */
2304 case ROOM_T_TRAP_PIT:
2306 /* Avoid too many monsters */
2309 room_num[ROOM_T_PIT] = 0;
2310 room_num[ROOM_T_NEST] = 0;
2311 room_num[ROOM_T_TRAP_PIT] = 0;
2317 /* Avoid double-town */
2318 room_num[ROOM_T_ARCADE] = 0;
2324 /* End loop if no room remain */
2328 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2329 if (rooms_built < 2)
2331 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2335 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);