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-normal.h"
45 #include "rooms-pitnest.h"
46 #include "rooms-vault.h"
47 #include "rooms-city.h"
52 *[from SAngband (originally from OAngband)]\n
54 * Table of values that control how many times each type of room will\n
55 * appear. Each type of room has its own row, and each column\n
56 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
57 * value is the minimum depth the room can appear at. -LM-\n
59 * Level 101 and below use the values for level 100.\n
61 * Rooms with lots of monsters or loot may not be generated if the\n
62 * object or monster lists are already nearly full. Rooms will not\n
63 * appear above their minimum depth. Tiny levels will not have space\n
64 * for all the rooms you ask for.\n
66 static room_info_type room_info_normal[ROOM_T_MAX] =
69 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
71 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
72 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
73 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
74 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
75 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
76 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
77 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
78 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
79 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
80 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
81 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
82 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
83 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
84 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
85 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
86 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
90 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
91 static byte room_build_order[ROOM_T_MAX] = {
111 * @brief 鍵のかかったドアを配置する
112 * @param y 配置したいフロアのY座標
113 * @param x 配置したいフロアのX座標
116 void place_locked_door(int y, int x)
118 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
120 place_floor_bold(y, x);
124 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
125 cave[y][x].info &= ~(CAVE_FLOOR);
126 delete_monster(y, x);
132 * @param y 配置したいフロアのY座標
133 * @param x 配置したいフロアのX座標
134 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
137 void place_secret_door(int y, int x, int type)
139 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
141 place_floor_bold(y, x);
145 cave_type *c_ptr = &cave[y][x];
147 if (type == DOOR_DEFAULT)
149 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
150 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
151 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
154 /* Create secret door */
155 place_closed_door(y, x, type);
157 if (type != DOOR_CURTAIN)
159 /* Hide by inner wall because this is used in rooms only */
160 c_ptr->mimic = feat_wall_inner;
162 /* Floor type terrain cannot hide a door */
163 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
165 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
167 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
173 c_ptr->info &= ~(CAVE_FLOOR);
174 delete_monster(y, x);
179 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
180 * @param y0 配置したい中心のY座標
181 * @param x0 配置したい中心のX座標
183 * This funtion makes a very small room centred at (x0, y0)
184 * This is used in crypts, and random elemental vaults.
186 * Note - this should be used only on allocated regions
187 * within another room.
189 void build_small_room(int x0, int y0)
193 for (y = y0 - 1; y <= y0 + 1; y++)
195 place_inner_bold(y, x0 - 1);
196 place_inner_bold(y, x0 + 1);
199 for (x = x0 - 1; x <= x0 + 1; x++)
201 place_inner_bold(y0 - 1, x);
202 place_inner_bold(y0 + 1, x);
205 /* Place a secret door on one side */
208 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
209 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
210 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
211 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
214 /* Clear mimic type */
215 cave[y0][x0].mimic = 0;
217 /* Add inner open space */
218 place_floor_bold(y0, x0);
223 * 指定範囲に通路が通っていることを確認した上で床で埋める
224 * This function tunnels around a room if it will cut off part of a cave system.
231 static void check_room_boundary(int x1, int y1, int x2, int y2)
234 bool old_is_floor, new_is_floor;
240 old_is_floor = get_is_floor(x1 - 1, y1);
243 * Count the number of floor-wall boundaries around the room
244 * Note: diagonal squares are ignored since the player can move diagonally
245 * to bypass these if needed.
248 /* Above the top boundary */
249 for (x = x1; x <= x2; x++)
251 new_is_floor = get_is_floor(x, y1 - 1);
253 /* Increment counter if they are different */
254 if (new_is_floor != old_is_floor) count++;
256 old_is_floor = new_is_floor;
260 for (y = y1; y <= y2; y++)
262 new_is_floor = get_is_floor(x2 + 1, y);
264 /* increment counter if they are different */
265 if (new_is_floor != old_is_floor) count++;
267 old_is_floor = new_is_floor;
270 /* Bottom boundary */
271 for (x = x2; x >= x1; x--)
273 new_is_floor = get_is_floor(x, y2 + 1);
275 /* increment counter if they are different */
276 if (new_is_floor != old_is_floor) count++;
278 old_is_floor = new_is_floor;
282 for (y = y2; y >= y1; y--)
284 new_is_floor = get_is_floor(x1 - 1, y);
286 /* increment counter if they are different */
287 if (new_is_floor != old_is_floor) count++;
289 old_is_floor = new_is_floor;
292 /* If all the same, or only one connection exit. */
293 if (count <= 2) return;
296 /* Tunnel around the room so to prevent problems with caves */
297 for (y = y1; y <= y2; y++)
299 for (x = x1; x <= x2; x++)
309 * find_space()の予備処理として部屋の生成が可能かを判定する /
310 * Helper function for find_space(). Is this a good location?
311 * @param blocks_high 範囲の高さ
312 * @param blocks_wide 範囲の幅
313 * @param block_y 範囲の上端
314 * @param block_x 範囲の左端
317 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
319 int by1, bx1, by2, bx2, by, bx;
321 /* Itty-bitty rooms must shift about within their rectangle */
324 if ((blocks_wide == 2) && (block_x % 3) == 2)
328 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
329 else if ((blocks_wide % 3) == 0)
331 /* Must be aligned to the left edge of a 11x33 rectangle. */
332 if ((block_x % 3) != 0)
337 * Big rooms that do not have a width divisible by 3 must be
338 * aligned towards the edge of the dungeon closest to them.
342 /* Shift towards left edge of dungeon. */
343 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
345 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
347 if ((block_x % 3) == 1)
351 /* Shift toward right edge of dungeon. */
354 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
356 if ((block_x % 3) == 1)
364 by2 = block_y + blocks_high;
365 bx2 = block_x + blocks_wide;
367 /* Never run off the screen */
368 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
369 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
371 /* Verify available space */
372 for (by = by1; by < by2; by++)
374 for (bx = bx1; bx < bx2; bx++)
376 if (dun->room_map[by][bx])
383 /* This location is okay */
389 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
390 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
391 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
392 * @param height 確保したい領域の高さ
393 * @param width 確保したい領域の幅
394 * @return 所定の範囲が確保できた場合TRUEを返す
396 * Find and allocate a free space in the dungeon large enough to hold\n
397 * the room calling this function.\n
399 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
400 * align neatly on the standard screen. Therefore, we make them use\n
401 * blocks in few 11x33 rectangles as possible.\n
403 * Be careful to include the edges of the room in height and width!\n
405 * Return TRUE and values for the center of the room if all went well.\n
406 * Otherwise, return FALSE.\n
408 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
410 int candidates, pick;
411 int by, bx, by1, bx1, by2, bx2;
412 int block_y = 0, block_x = 0;
415 /* Find out how many blocks we need. */
416 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
417 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
419 /* There are no way to allocate such huge space */
420 if (dun->row_rooms < blocks_high) return FALSE;
421 if (dun->col_rooms < blocks_wide) return FALSE;
426 /* Count the number of valid places */
427 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
429 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
431 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
433 /* Find a valid place */
446 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
448 /* Choose a random one */
449 pick = randint1(candidates);
452 /* NO_CAVE dungeon (Castle) */
455 /* Always choose the center one */
456 pick = candidates/2 + 1;
459 /* Pick up the choosen location */
460 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
462 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
464 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
468 /* This one is picked? */
479 by2 = block_y + blocks_high;
480 bx2 = block_x + blocks_wide;
483 * It is *extremely* important that the following calculation
484 * be *exactly* correct to prevent memory errors
487 /* Acquire the location of the room */
488 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
489 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
491 /* Save the room location */
492 if (dun->cent_n < CENT_MAX)
494 dun->cent[dun->cent_n].y = (byte_hack)*y;
495 dun->cent[dun->cent_n].x = (byte_hack)*x;
499 /* Reserve some blocks. */
500 for (by = by1; by < by2; by++)
502 for (bx = bx1; bx < bx2; bx++)
504 dun->room_map[by][bx] = TRUE;
510 * Hack- See if room will cut off a cavern.
512 * If so, fix by tunneling outside the room in such a
513 * way as to connect the caves.
515 check_room_boundary(*x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
529 * Structure to hold all "fill" data
532 typedef struct fill_data_type fill_data_type;
534 struct fill_data_type
547 /* features to fill with */
556 /* number of filled squares */
560 static fill_data_type fill_data;
563 /* Store routine for the fractal cave generator */
564 /* this routine probably should be an inline function or a macro. */
565 static void store_height(int x, int y, int val)
567 /* if on boundary set val > cutoff so walls are not as square */
568 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
569 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
570 (val <= fill_data.c1)) val = fill_data.c1 + 1;
572 /* store the value in height-map format */
573 cave[y][x].feat = (s16b)val;
580 * Explanation of the plasma fractal algorithm:
582 * A grid of points is created with the properties of a 'height-map'
583 * This is done by making the corners of the grid have a random value.
584 * The grid is then subdivided into one with twice the resolution.
585 * The new points midway between two 'known' points can be calculated
586 * by taking the average value of the 'known' ones and randomly adding
587 * or subtracting an amount proportional to the distance between those
588 * points. The final 'middle' points of the grid are then calculated
589 * by averaging all four of the originally 'known' corner points. An
590 * random amount is added or subtracted from this to get a value of the
591 * height at that point. The scaling factor here is adjusted to the
592 * slightly larger distance diagonally as compared to orthogonally.
594 * This is then repeated recursively to fill an entire 'height-map'
595 * A rectangular map is done the same way, except there are different
596 * scaling factors along the x and y directions.
598 * A hack to change the amount of correlation between points is done using
599 * the grd variable. If the current step size is greater than grd then
600 * the point will be random, otherwise it will be calculated by the
601 * above algorithm. This makes a maximum distance at which two points on
602 * the height map can affect each other.
604 * How fractal caves are made:
606 * When the map is complete, a cut-off value is used to create a cave.
607 * Heights below this value are "floor", and heights above are "wall".
608 * This also can be used to create lakes, by adding more height levels
609 * representing shallow and deep water/ lava etc.
611 * The grd variable affects the width of passages.
612 * The roug variable affects the roughness of those passages
614 * The tricky part is making sure the created cave is connected. This
615 * is done by 'filling' from the inside and only keeping the 'filled'
616 * floor. Walls bounding the 'filled' floor are also kept. Everything
617 * else is converted to the normal _extra_.
622 * Note that this uses the cave.feat array in a very hackish way
623 * the values are first set to zero, and then each array location
624 * is used as a "heightmap"
625 * The heightmap then needs to be converted back into the "feat" format.
627 * grd=level at which fractal turns on. smaller gives more mazelike caves
628 * roug=roughness level. 16=normal. higher values make things more convoluted
629 * small values are good for smooth walls.
630 * size=length of the side of the square cave system.
632 static void generate_hmap(int y0, int x0, int xsiz, int ysiz, int grd, int roug, int cutoff)
634 int xhsize, yhsize, xsize, ysize, maxsize;
637 * fixed point variables- these are stored as 256 x normal value
638 * this gives 8 binary places of fractional part + 8 places of normal part
641 u16b xstep, xhstep, ystep, yhstep;
642 u16b xstep2, xhstep2, ystep2, yhstep2;
643 u16b i, j, ii, jj, diagsize, xxsize, yysize;
645 /* Cache for speed */
648 /* redefine size so can change the value if out of range */
652 /* Paranoia about size of the system of caves */
653 if (xsize > 254) xsize = 254;
654 if (xsize < 4) xsize = 4;
655 if (ysize > 254) ysize = 254;
656 if (ysize < 4) ysize = 4;
658 /* get offsets to middle of array */
662 /* fix rounding problem */
666 /* get limits of region */
667 fill_data.xmin = x0 - xhsize;
668 fill_data.ymin = y0 - yhsize;
669 fill_data.xmax = x0 + xhsize;
670 fill_data.ymax = y0 + yhsize;
672 /* Store cutoff in global for quick access */
673 fill_data.c1 = cutoff;
676 * Scale factor for middle points:
677 * About sqrt(2) * 256 - correct for a square lattice
678 * approximately correct for everything else.
682 /* maximum of xsize and ysize */
683 maxsize = (xsize > ysize) ? xsize : ysize;
685 /* Clear the section */
686 for (i = 0; i <= xsize; i++)
688 for (j = 0; j <= ysize; j++)
690 /* -1 is a flag for "not done yet" */
691 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
692 /* Clear icky flag because may be redoing the cave */
693 cave[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
697 /* Boundaries are walls */
698 cave[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
699 cave[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
700 cave[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
701 cave[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
703 /* Set the middle square to be an open area. */
704 cave[y0][x0].feat = 0;
706 /* Initialize the step sizes */
707 xstep = xhstep = xsize * 256;
708 ystep = yhstep = ysize * 256;
709 xxsize = xsize * 256;
710 yysize = ysize * 256;
713 * Fill in the rectangle with fractal height data -
714 * like the 'plasma fractal' in fractint.
716 while ((xhstep > 256) || (yhstep > 256))
718 /* Halve the step sizes */
724 /* cache well used values */
725 xstep2 = xstep / 256;
726 ystep2 = ystep / 256;
728 xhstep2 = xhstep / 256;
729 yhstep2 = yhstep / 256;
731 /* middle top to bottom. */
732 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
734 for (j = 0; j <= yysize; j += ystep)
736 /* cache often used values */
737 ii = i / 256 + fill_data.xmin;
738 jj = j / 256 + fill_data.ymin;
741 if (cave[jj][ii].feat == -1)
745 /* If greater than 'grid' level then is random */
746 store_height(ii, jj, randint1(maxsize));
750 /* Average of left and right points +random bit */
752 (cave[jj][fill_data.xmin + (i - xhstep) / 256].feat
753 + cave[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
754 + (randint1(xstep2) - xhstep2) * roug / 16);
761 /* middle left to right. */
762 for (j = yhstep; j <= yysize - yhstep; j += ystep)
764 for (i = 0; i <= xxsize; i += xstep)
766 /* cache often used values */
767 ii = i / 256 + fill_data.xmin;
768 jj = j / 256 + fill_data.ymin;
771 if (cave[jj][ii].feat == -1)
775 /* If greater than 'grid' level then is random */
776 store_height(ii, jj, randint1(maxsize));
780 /* Average of up and down points +random bit */
782 (cave[fill_data.ymin + (j - yhstep) / 256][ii].feat
783 + cave[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
784 + (randint1(ystep2) - yhstep2) * roug / 16);
791 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
793 for (j = yhstep; j <= yysize - yhstep; j += ystep)
795 /* cache often used values */
796 ii = i / 256 + fill_data.xmin;
797 jj = j / 256 + fill_data.ymin;
800 if (cave[jj][ii].feat == -1)
804 /* If greater than 'grid' level then is random */
805 store_height(ii, jj, randint1(maxsize));
809 /* Cache reused values. */
810 xm = fill_data.xmin + (i - xhstep) / 256;
811 xp = fill_data.xmin + (i + xhstep) / 256;
812 ym = fill_data.ymin + (j - yhstep) / 256;
813 yp = fill_data.ymin + (j + yhstep) / 256;
816 * Average over all four corners + scale by diagsize to
817 * reduce the effect of the square grid on the shape of the fractal
820 (cave[ym][xm].feat + cave[yp][xm].feat
821 + cave[ym][xp].feat + cave[yp][xp].feat) / 4
822 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
831 static bool hack_isnt_wall(int y, int x, int c1, int c2, int c3, int feat1, int feat2, int feat3, int info1, int info2, int info3)
834 * function used to convert from height-map back to the
835 * normal angband cave format
837 if (cave[y][x].info & CAVE_ICKY)
844 /* Show that have looked at this square */
845 cave[y][x].info|= (CAVE_ICKY);
847 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
848 if (cave[y][x].feat <= c1)
850 /* 25% of the time use the other tile : it looks better this way */
851 if (randint1(100) < 75)
853 cave[y][x].feat = (s16b)feat1;
854 cave[y][x].info &= ~(CAVE_MASK);
855 cave[y][x].info |= info1;
860 cave[y][x].feat = (s16b)feat2;
861 cave[y][x].info &= ~(CAVE_MASK);
862 cave[y][x].info |= info2;
866 else if (cave[y][x].feat <= c2)
868 /* 25% of the time use the other tile : it looks better this way */
869 if (randint1(100) < 75)
871 cave[y][x].feat = (s16b)feat2;
872 cave[y][x].info &= ~(CAVE_MASK);
873 cave[y][x].info |= info2;
878 cave[y][x].feat = (s16b)feat1;
879 cave[y][x].info &= ~(CAVE_MASK);
880 cave[y][x].info |= info1;
884 else if (cave[y][x].feat <= c3)
886 cave[y][x].feat = (s16b)feat3;
887 cave[y][x].info &= ~(CAVE_MASK);
888 cave[y][x].info |= info3;
891 /* if greater than cutoff then is a wall */
894 place_outer_bold(y, x);
904 * Quick and nasty fill routine used to find the connected region
905 * of floor in the middle of the cave
907 static void cave_fill(POSITION y, POSITION x)
918 /* Enqueue that entry */
923 /* Now process the queue */
924 while (flow_head != flow_tail)
926 /* Extract the next entry */
927 ty = temp_y[flow_head];
928 tx = temp_x[flow_head];
930 /* Forget that entry */
931 if (++flow_head == TEMP_MAX) flow_head = 0;
933 /* Add the "children" */
934 for (d = 0; d < 8; d++)
936 int old_head = flow_tail;
942 /* Paranoia Don't leave the cave */
943 if (!in_bounds(j, i))
945 /* affect boundary */
946 cave[j][i].info |= CAVE_ICKY;
950 /* If within bounds */
951 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
952 && (j > fill_data.ymin) && (j < fill_data.ymax))
954 /* If not a wall or floor done before */
955 if (hack_isnt_wall(j, i,
956 fill_data.c1, fill_data.c2, fill_data.c3,
957 fill_data.feat1, fill_data.feat2, fill_data.feat3,
958 fill_data.info1, fill_data.info2, fill_data.info3))
960 /* Enqueue that entry */
961 temp_y[flow_tail] = (byte_hack)j;
962 temp_x[flow_tail] = (byte_hack)i;
964 /* Advance the queue */
965 if (++flow_tail == TEMP_MAX) flow_tail = 0;
967 /* Hack -- Overflow by forgetting new entry */
968 if (flow_tail == flow_head)
970 flow_tail = old_head;
974 /* keep tally of size of cave system */
975 (fill_data.amount)++;
981 /* affect boundary */
982 cave[j][i].info |= CAVE_ICKY;
989 static bool generate_fracave(int y0, int x0, int xsize, int ysize, int cutoff, bool light, bool room)
991 int x, y, i, xhsize, yhsize;
993 /* offsets to middle from corner */
999 * select region connected to center of cave system
1000 * this gets rid of alot of isolated one-sqaures that
1001 * can make teleport traps instadeaths...
1005 fill_data.c1 = cutoff;
1009 /* features to fill with */
1010 fill_data.feat1 = floor_type[randint0(100)];
1011 fill_data.feat2 = floor_type[randint0(100)];
1012 fill_data.feat3 = floor_type[randint0(100)];
1014 fill_data.info1 = CAVE_FLOOR;
1015 fill_data.info2 = CAVE_FLOOR;
1016 fill_data.info3 = CAVE_FLOOR;
1018 /* number of filled squares */
1019 fill_data.amount = 0;
1021 cave_fill((byte)y0, (byte)x0);
1023 /* if tally too small, try again */
1024 if (fill_data.amount < 10)
1026 /* too small - clear area and try again later */
1027 for (x = 0; x <= xsize; ++x)
1029 for (y = 0; y <= ysize; ++y)
1031 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1032 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1039 * Do boundarys-check to see if they are next to a filled region
1040 * If not then they are set to normal granite
1041 * If so then they are marked as room walls.
1043 for (i = 0; i <= xsize; ++i)
1046 if ((cave[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1048 /* Next to a 'filled' region? - set to be room walls */
1049 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1050 if (light) cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1051 cave[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1052 place_outer_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1056 /* set to be normal granite */
1057 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1060 /* bottom boundary */
1061 if ((cave[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1063 /* Next to a 'filled' region? - set to be room walls */
1064 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1065 if (light) cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1066 cave[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1067 place_outer_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1071 /* set to be normal granite */
1072 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1075 /* clear the icky flag-don't need it any more */
1076 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1077 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1080 /* Do the left and right boundaries minus the corners (done above) */
1081 for (i = 1; i < ysize; ++i)
1084 if ((cave[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1087 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1088 if (light) cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1089 cave[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1090 place_outer_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1095 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1097 /* right boundary */
1098 if ((cave[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1101 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1102 if (light) cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1103 cave[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1104 place_outer_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1109 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1112 /* clear icky flag -done with it */
1113 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1114 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1118 /* Do the rest: convert back to the normal format */
1119 for (x = 1; x < xsize; ++x)
1121 for (y = 1; y < ysize; ++y)
1123 if (is_floor_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1124 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1126 /* Clear the icky flag in the filled region */
1127 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1129 /* Set appropriate flags */
1130 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1131 if (room) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1133 else if (is_outer_bold(y0 + y - yhsize, x0 + x - xhsize) &&
1134 (cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1137 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1138 if (light) cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1141 cave[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1146 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1147 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1152 /* Clear the unconnected regions */
1153 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1154 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1160 * XXX XXX XXX There is a slight problem when tunnels pierce the caves:
1161 * Extra doors appear inside the system. (Its not very noticeable though.)
1162 * This can be removed by "filling" from the outside in. This allows a separation
1163 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1164 * The extra effort for what seems to be only a minor thing (even non-existant if you
1165 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1174 * @brief タイプ9の部屋…フラクタルカーブによる洞窟生成 / Type 9 -- Driver routine to create fractal cave system
1177 static bool build_type9(void)
1179 int grd, roug, cutoff;
1180 POSITION xsize, ysize, y0, x0;
1182 bool done, light, room;
1184 /* get size: note 'Evenness'*/
1185 xsize = randint1(22) * 2 + 6;
1186 ysize = randint1(15) * 2 + 6;
1188 /* Find and reserve some space in the dungeon. Get center of room. */
1189 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
1191 /* Limit to the minimum room size, and retry */
1195 /* Find and reserve some space in the dungeon. Get center of room. */
1196 if (!find_space(&y0, &x0, ysize + 1, xsize + 1))
1202 return build_type1();
1206 light = done = FALSE;
1209 if ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1213 /* Note: size must be even or there are rounding problems
1214 * This causes the tunnels not to connect properly to the room */
1216 /* testing values for these parameters feel free to adjust */
1217 grd = 1 << (randint0(4));
1219 /* want average of about 16 */
1220 roug = randint1(8) * randint1(4);
1223 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
1224 randint1(xsize / 4) + randint1(ysize / 4);
1227 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
1229 /* Convert to normal format + clean up */
1230 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
1236 #ifdef ALLOW_CAVERNS_AND_LAKES
1238 * Builds a cave system in the center of the dungeon.
1240 void build_cavern(void)
1242 int grd, roug, cutoff, xsize, ysize, x0, y0;
1245 light = done = FALSE;
1246 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1248 /* Make a cave the size of the dungeon */
1249 xsize = cur_wid - 1;
1250 ysize = cur_hgt - 1;
1254 /* Paranoia: make size even */
1260 /* testing values for these parameters: feel free to adjust */
1261 grd = randint1(4) + 4;
1263 /* want average of about 16 */
1264 roug = randint1(8) * randint1(4);
1270 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1272 /* Convert to normal format+ clean up */
1273 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1277 static bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
1279 int x, y, i, xhsize, yhsize;
1280 int feat1, feat2, feat3;
1282 /* offsets to middle from corner */
1286 /* Get features based on type */
1289 case LAKE_T_LAVA: /* Lava */
1290 feat1 = feat_deep_lava;
1291 feat2 = feat_shallow_lava;
1292 feat3 = floor_type[randint0(100)];
1294 case LAKE_T_WATER: /* Water */
1295 feat1 = feat_deep_water;
1296 feat2 = feat_shallow_water;
1297 feat3 = floor_type[randint0(100)];
1299 case LAKE_T_CAVE: /* Collapsed cave */
1300 feat1 = floor_type[randint0(100)];
1301 feat2 = floor_type[randint0(100)];
1302 feat3 = feat_rubble;
1304 case LAKE_T_EARTH_VAULT: /* Earth vault */
1305 feat1 = feat_rubble;
1306 feat2 = floor_type[randint0(100)];
1307 feat3 = feat_rubble;
1309 case LAKE_T_AIR_VAULT: /* Air vault */
1314 case LAKE_T_WATER_VAULT: /* Water vault */
1315 feat1 = feat_shallow_water;
1316 feat2 = feat_deep_water;
1317 feat3 = feat_shallow_water;
1319 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1320 feat1 = feat_shallow_lava;
1321 feat2 = feat_deep_lava;
1322 feat3 = feat_shallow_lava;
1326 default: return FALSE;
1330 * select region connected to center of cave system
1331 * this gets rid of alot of isolated one-sqaures that
1332 * can make teleport traps instadeaths...
1340 /* features to fill with */
1341 fill_data.feat1 = feat1;
1342 fill_data.feat2 = feat2;
1343 fill_data.feat3 = feat3;
1345 fill_data.info1 = 0;
1346 fill_data.info2 = 0;
1347 fill_data.info3 = 0;
1349 /* number of filled squares */
1350 fill_data.amount = 0;
1352 /* select region connected to center of cave system
1353 * this gets rid of alot of isolated one-sqaures that
1354 * can make teleport traps instadeaths... */
1355 cave_fill((byte)y0, (byte)x0);
1357 /* if tally too small, try again */
1358 if (fill_data.amount < 10)
1360 /* too small -clear area and try again later */
1361 for (x = 0; x <= xsize; ++x)
1363 for (y = 0; y <= ysize; ++y)
1365 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1366 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1372 /* Do boundarys- set to normal granite */
1373 for (i = 0; i <= xsize; ++i)
1375 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1376 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1378 /* clear the icky flag-don't need it any more */
1379 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1380 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1383 /* Do the left and right boundaries minus the corners (done above) */
1385 for (i = 1; i < ysize; ++i)
1387 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1388 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1390 /* clear icky flag -done with it */
1391 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1392 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1396 /* Do the rest: convert back to the normal format */
1397 for (x = 1; x < xsize; ++x)
1399 for (y = 1; y < ysize; ++y)
1401 /* Fill unconnected regions with granite */
1402 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1403 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
1404 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1406 /* turn off icky flag (no longer needed.) */
1407 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1410 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1412 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1422 * makes a lake/collapsed cave system in the center of the dungeon
1424 void build_lake(int type)
1426 int grd, roug, xsize, ysize, x0, y0;
1430 /* paranoia - exit if lake type out of range. */
1431 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1433 msg_format("Invalid lake type (%d)", type);
1437 /* Make the size of the dungeon */
1438 xsize = cur_wid - 1;
1439 ysize = cur_hgt - 1;
1443 /* Paranoia: make size even */
1449 /* testing values for these parameters: feel free to adjust */
1450 grd = randint1(3) + 4;
1452 /* want average of about 16 */
1453 roug = randint1(8) * randint1(4);
1455 /* Make up size of various componants */
1459 /* Deep water/lava */
1460 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1462 /* Shallow boundary */
1466 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1468 /* Convert to normal format+ clean up */
1469 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1472 #endif /* ALLOW_CAVERNS_AND_LAKES */
1476 * Routine used by the random vault creators to add a door to a location
1477 * Note that range checking has to be done in the calling routine.
1479 * The doors must be INSIDE the allocated region.
1481 static void add_door(int x, int y)
1483 /* Need to have a wall in the center square */
1484 if (!is_outer_bold(y, x)) return;
1491 * where x=don't care
1495 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
1496 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
1499 place_secret_door(y, x, DOOR_DEFAULT);
1501 /* set boundarys so don't get wide doors */
1502 place_solid_bold(y, x - 1);
1503 place_solid_bold(y, x + 1);
1512 * where x = don't care
1515 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
1516 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
1519 place_secret_door(y, x, DOOR_DEFAULT);
1521 /* set boundarys so don't get wide doors */
1522 place_solid_bold(y - 1, x);
1523 place_solid_bold(y + 1, x);
1529 * Routine that fills the empty areas of a room with treasure and monsters.
1531 static void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
1533 int x, y, cx, cy, size;
1536 /* center of room:*/
1540 /* Rough measure of size of vault= sum of lengths of sides */
1541 size = abs(x2 - x1) + abs(y2 - y1);
1543 for (x = x1; x <= x2; x++)
1545 for (y = y1; y <= y2; y++)
1547 /* Thing added based on distance to center of vault
1548 * Difficulty is 1-easy to 10-hard */
1549 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1551 /* hack- empty square part of the time */
1552 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1554 /* if floor, shallow water and lava */
1555 if (is_floor_bold(y, x) ||
1556 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1558 /* The smaller 'value' is, the better the stuff */
1561 /* Meanest monster + treasure */
1562 monster_level = base_level + 40;
1563 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1564 monster_level = base_level;
1565 object_level = base_level + 20;
1566 place_object(y, x, AM_GOOD);
1567 object_level = base_level;
1571 /* Mean monster +treasure */
1572 monster_level = base_level + 20;
1573 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1574 monster_level = base_level;
1575 object_level = base_level + 10;
1576 place_object(y, x, AM_GOOD);
1577 object_level = base_level;
1579 else if (value < 10)
1582 monster_level = base_level + 9;
1583 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1584 monster_level = base_level;
1586 else if (value < 17)
1588 /* Intentional Blank space */
1591 * (Want some of the vault to be empty
1592 * so have room for group monsters.
1593 * This is used in the hack above to lower
1594 * the density of stuff in the vault.)
1597 else if (value < 23)
1599 /* Object or trap */
1600 if (randint0(100) < 25)
1602 place_object(y, x, 0L);
1609 else if (value < 30)
1611 /* Monster and trap */
1612 monster_level = base_level + 5;
1613 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1614 monster_level = base_level;
1617 else if (value < 40)
1619 /* Monster or object */
1620 if (randint0(100) < 50)
1622 monster_level = base_level + 3;
1623 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1624 monster_level = base_level;
1626 if (randint0(100) < 50)
1628 object_level = base_level + 7;
1629 place_object(y, x, 0L);
1630 object_level = base_level;
1633 else if (value < 50)
1642 /* 20% monster, 40% trap, 20% object, 20% blank space */
1643 if (randint0(100) < 20)
1645 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1647 else if (randint0(100) < 50)
1651 else if (randint0(100) < 50)
1653 place_object(y, x, 0L);
1664 * This function creates a random vault that looks like a collection of bubbles.
1665 * It works by getting a set of coordinates that represent the center of each
1666 * bubble. The entire room is made by seeing which bubble center is closest. If
1667 * two centers are equidistant then the square is a wall, otherwise it is a floor.
1668 * The only exception is for squares really near a center, these are always floor.
1669 * (It looks better than without this check.)
1671 * Note: If two centers are on the same point then this algorithm will create a
1672 * blank bubble filled with walls. - This is prevented from happening.
1674 static void build_bubble_vault(int x0, int y0, int xsize, int ysize)
1676 #define BUBBLENUM 10 /* number of bubbles */
1678 /* array of center points of bubbles */
1679 coord center[BUBBLENUM];
1682 u16b min1, min2, temp;
1685 /* Offset from center to top left hand corner */
1686 int xhsize = xsize / 2;
1687 int yhsize = ysize / 2;
1689 msg_print_wizard(CHEAT_DUNGEON, _("泡型ランダムVaultを生成しました。", "Room Vault."));
1691 /* Allocate center of bubbles */
1692 center[0].x = (byte)randint1(xsize - 3) + 1;
1693 center[0].y = (byte)randint1(ysize - 3) + 1;
1695 for (i = 1; i < BUBBLENUM; i++)
1699 /* get center and check to see if it is unique */
1704 x = randint1(xsize - 3) + 1;
1705 y = randint1(ysize - 3) + 1;
1707 for (j = 0; j < i; j++)
1709 /* rough test to see if there is an overlap */
1710 if ((x == center[j].x) && (y == center[j].y)) done = FALSE;
1714 center[i].x = (byte_hack)x;
1715 center[i].y = (byte_hack)y;
1719 /* Top and bottom boundaries */
1720 for (i = 0; i < xsize; i++)
1722 int side_x = x0 - xhsize + i;
1724 place_outer_noperm_bold(y0 - yhsize + 0, side_x);
1725 cave[y0 - yhsize + 0][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
1726 place_outer_noperm_bold(y0 - yhsize + ysize - 1, side_x);
1727 cave[y0 - yhsize + ysize - 1][side_x].info |= (CAVE_ROOM | CAVE_ICKY);
1730 /* Left and right boundaries */
1731 for (i = 1; i < ysize - 1; i++)
1733 int side_y = y0 - yhsize + i;
1735 place_outer_noperm_bold(side_y, x0 - xhsize + 0);
1736 cave[side_y][x0 - xhsize + 0].info |= (CAVE_ROOM | CAVE_ICKY);
1737 place_outer_noperm_bold(side_y, x0 - xhsize + xsize - 1);
1738 cave[side_y][x0 - xhsize + xsize - 1].info |= (CAVE_ROOM | CAVE_ICKY);
1741 /* Fill in middle with bubbles */
1742 for (x = 1; x < xsize - 1; x++)
1744 for (y = 1; y < ysize - 1; y++)
1746 /* Get distances to two closest centers */
1749 min1 = (u16b)distance(x, y, center[0].x, center[0].y);
1750 min2 = (u16b)distance(x, y, center[1].x, center[1].y);
1754 /* swap if in wrong order */
1761 for (i = 2; i < BUBBLENUM; i++)
1763 temp = (u16b)distance(x, y, center[i].x, center[i].y);
1771 else if (temp < min2)
1773 /* second smallest */
1777 if (((min2 - min1) <= 2) && (!(min1 < 3)))
1779 /* Boundary at midpoint+ not at inner region of bubble */
1780 place_outer_noperm_bold(y0 - yhsize + y, x0 - xhsize + x);
1784 /* middle of a bubble */
1785 place_floor_bold(y0 - yhsize + y, x0 - xhsize + x);
1788 /* clean up rest of flags */
1789 cave[y0 - yhsize + y][x0 - xhsize + x].info |= (CAVE_ROOM | CAVE_ICKY);
1793 /* Try to add some random doors */
1794 for (i = 0; i < 500; i++)
1796 x = randint1(xsize - 3) - xhsize + x0 + 1;
1797 y = randint1(ysize - 3) - yhsize + y0 + 1;
1801 /* Fill with monsters and treasure, low difficulty */
1802 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5));
1807 * Overlay a rectangular room given its bounds
1808 * This routine is used by build_room_vault
1809 * The area inside the walls is not touched:
1810 * only granite is removed- normal walls stay
1812 static void build_room(int x1, int x2, int y1, int y2)
1814 int x, y, i, xsize, ysize, temp;
1816 /* Check if rectangle has no width */
1817 if ((x1 == x2) || (y1 == y2)) return;
1822 /* Swap boundaries if in wrong order */
1830 /* Swap boundaries if in wrong order */
1836 /* get total widths */
1841 /* Top and bottom boundaries */
1842 for (i = 0; i <= xsize; i++)
1844 place_outer_noperm_bold(y1, x1 + i);
1845 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1846 place_outer_noperm_bold(y2, x1 + i);
1847 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1850 /* Left and right boundaries */
1851 for (i = 1; i < ysize; i++)
1853 place_outer_noperm_bold(y1 + i, x1);
1854 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1855 place_outer_noperm_bold(y1 + i, x2);
1856 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1860 for (x = 1; x < xsize; x++)
1862 for (y = 1; y < ysize; y++)
1864 if (is_extra_bold(y1+y, x1+x))
1866 /* clear the untouched region */
1867 place_floor_bold(y1 + y, x1 + x);
1868 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1872 /* make it a room- but don't touch */
1873 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1880 /* Create a random vault that looks like a collection of overlapping rooms */
1882 static void build_room_vault(int x0, int y0, int xsize, int ysize)
1884 int i, x1, x2, y1, y2, xhsize, yhsize;
1886 /* get offset from center */
1890 msg_print_wizard(CHEAT_DUNGEON, _("部屋型ランダムVaultを生成しました。", "Room Vault."));
1892 /* fill area so don't get problems with arena levels */
1893 for (x1 = 0; x1 < xsize; x1++)
1895 int x = x0 - xhsize + x1;
1897 for (y1 = 0; y1 < ysize; y1++)
1899 int y = y0 - yhsize + y1;
1901 place_extra_bold(y, x);
1902 cave[y][x].info &= (~CAVE_ICKY);
1906 /* add ten random rooms */
1907 for (i = 0; i < 10; i++)
1909 x1 = randint1(xhsize) * 2 + x0 - xhsize;
1910 x2 = randint1(xhsize) * 2 + x0 - xhsize;
1911 y1 = randint1(yhsize) * 2 + y0 - yhsize;
1912 y2 = randint1(yhsize) * 2 + y0 - yhsize;
1913 build_room(x1, x2, y1, y2);
1916 /* Add some random doors */
1917 for (i = 0; i < 500; i++)
1919 x1 = randint1(xsize - 3) - xhsize + x0 + 1;
1920 y1 = randint1(ysize - 3) - yhsize + y0 + 1;
1924 /* Fill with monsters and treasure, high difficulty */
1925 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 2, y0 - yhsize + 1, y0 - yhsize + ysize - 2, randint1(5) + 5);
1929 /* Create a random vault out of a fractal cave */
1930 static void build_cave_vault(int x0, int y0, int xsiz, int ysiz)
1932 int grd, roug, cutoff, xhsize, yhsize, xsize, ysize, x, y;
1933 bool done, light, room;
1935 /* round to make sizes even */
1941 msg_print_wizard(CHEAT_DUNGEON, _("洞穴ランダムVaultを生成しました。", "Cave Vault."));
1943 light = done = FALSE;
1948 /* testing values for these parameters feel free to adjust */
1949 grd = 1 << randint0(4);
1951 /* want average of about 16 */
1952 roug = randint1(8) * randint1(4);
1955 cutoff = randint1(xsize / 4) + randint1(ysize / 4) +
1956 randint1(xsize / 4) + randint1(ysize / 4);
1959 generate_hmap(y0, x0, xsize, ysize, grd, roug, cutoff);
1961 /* Convert to normal format+ clean up */
1962 done = generate_fracave(y0, x0, xsize, ysize, cutoff, light, room);
1965 /* Set icky flag because is a vault */
1966 for (x = 0; x <= xsize; x++)
1968 for (y = 0; y <= ysize; y++)
1970 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
1974 /* Fill with monsters and treasure, low difficulty */
1975 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1, y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
1979 * maze vault -- rectangular labyrinthine rooms
1981 * maze vault uses two routines:
1982 * r_visit - a recursive routine that builds the labyrinth
1983 * build_maze_vault - a driver routine that calls r_visit and adds
1984 * monsters, traps and treasure
1986 * The labyrinth is built by creating a spanning tree of a graph.
1987 * The graph vertices are at
1988 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1989 * and the edges are the vertical and horizontal nearest neighbors.
1991 * The spanning tree is created by performing a suitably randomized
1992 * depth-first traversal of the graph. The only adjustable parameter
1993 * is the randint0(3) below; it governs the relative density of
1994 * twists and turns in the labyrinth: smaller number, more twists.
1996 static void r_visit(int y1, int x1, int y2, int x2,
1997 int node, int dir, int *visited)
1999 int i, j, m, n, temp, x, y, adj[4];
2001 /* dimensions of vertex array */
2002 m = (x2 - x1) / 2 + 1;
2003 n = (y2 - y1) / 2 + 1;
2005 /* mark node visited and set it to a floor */
2007 x = 2 * (node % m) + x1;
2008 y = 2 * (node / m) + y1;
2009 place_floor_bold(y, x);
2011 /* setup order of adjacent node visits */
2014 /* pick a random ordering */
2015 for (i = 0; i < 4; i++)
2017 for (i = 0; i < 4; i++)
2028 /* pick a random ordering with dir first */
2030 for (i = 1; i < 4; i++)
2032 for (i = 1; i < 4; i++)
2034 j = 1 + randint0(3);
2041 for (i = 0; i < 4; i++)
2046 /* (0,+) - check for bottom boundary */
2047 if ((node / m < n - 1) && (visited[node + m] == 0))
2049 place_floor_bold(y + 1, x);
2050 r_visit(y1, x1, y2, x2, node + m, dir, visited);
2054 /* (0,-) - check for top boundary */
2055 if ((node / m > 0) && (visited[node - m] == 0))
2057 place_floor_bold(y - 1, x);
2058 r_visit(y1, x1, y2, x2, node - m, dir, visited);
2062 /* (+,0) - check for right boundary */
2063 if ((node % m < m - 1) && (visited[node + 1] == 0))
2065 place_floor_bold(y, x + 1);
2066 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
2070 /* (-,0) - check for left boundary */
2071 if ((node % m > 0) && (visited[node - 1] == 0))
2073 place_floor_bold(y, x - 1);
2074 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
2081 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
2085 int m, n, num_vertices, *visited;
2089 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
2091 /* Choose lite or dark */
2092 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
2094 /* Pick a random room size - randomized by calling routine */
2103 /* generate the room */
2104 for (y = y1 - 1; y <= y2 + 1; y++)
2106 for (x = x1 - 1; x <= x2 + 1; x++)
2108 c_ptr = &cave[y][x];
2109 c_ptr->info |= CAVE_ROOM;
2110 if (is_vault) c_ptr->info |= CAVE_ICKY;
2111 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
2113 place_outer_grid(c_ptr);
2117 place_extra_grid(c_ptr);
2121 place_inner_grid(c_ptr);
2123 if (light) c_ptr->info |= (CAVE_GLOW);
2127 /* dimensions of vertex array */
2130 num_vertices = m * n;
2132 /* initialize array of visited vertices */
2133 C_MAKE(visited, num_vertices, int);
2135 /* traverse the graph to create a spaning tree, pick a random root */
2136 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
2138 /* Fill with monsters and treasure, low difficulty */
2139 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
2141 C_KILL(visited, num_vertices, int);
2145 /* Build a "mini" checkerboard vault
2147 * This is done by making a permanent wall maze and setting
2148 * the diagonal sqaures of the checker board to be granite.
2149 * The vault has two entrances on opposite sides to guarantee
2150 * a way to get in even if the vault abuts a side of the dungeon.
2152 static void build_mini_c_vault(int x0, int y0, int xsize, int ysize)
2155 int y1, x1, y2, x2, y, x, total;
2156 int m, n, num_vertices;
2159 msg_print_wizard(CHEAT_DUNGEON, _("小型チェッカーランダムVaultを生成しました。", "Mini Checker Board Vault."));
2161 /* Pick a random room size */
2171 /* generate the room */
2172 for (x = x1 - 2; x <= x2 + 2; x++)
2174 if (!in_bounds(y1-2,x)) break;
2176 cave[y1-2][x].info |= (CAVE_ROOM | CAVE_ICKY);
2178 place_outer_noperm_bold(y1-2, x);
2181 for (x = x1 - 2; x <= x2 + 2; x++)
2183 if (!in_bounds(y2+2,x)) break;
2185 cave[y2+2][x].info |= (CAVE_ROOM | CAVE_ICKY);
2187 place_outer_noperm_bold(y2+2, x);
2190 for (y = y1 - 2; y <= y2 + 2; y++)
2192 if (!in_bounds(y,x1-2)) break;
2194 cave[y][x1-2].info |= (CAVE_ROOM | CAVE_ICKY);
2196 place_outer_noperm_bold(y, x1-2);
2199 for (y = y1 - 2; y <= y2 + 2; y++)
2201 if (!in_bounds(y,x2+2)) break;
2203 cave[y][x2+2].info |= (CAVE_ROOM | CAVE_ICKY);
2205 place_outer_noperm_bold(y, x2+2);
2208 for (y = y1 - 1; y <= y2 + 1; y++)
2210 for (x = x1 - 1; x <= x2 + 1; x++)
2212 cave_type *c_ptr = &cave[y][x];
2214 c_ptr->info |= (CAVE_ROOM | CAVE_ICKY);
2216 /* Permanent walls */
2217 place_inner_perm_grid(c_ptr);
2222 /* dimensions of vertex array */
2225 num_vertices = m * n;
2227 /* initialize array of visited vertices */
2228 C_MAKE(visited, num_vertices, int);
2230 /* traverse the graph to create a spannng tree, pick a random root */
2231 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
2233 /* Make it look like a checker board vault */
2234 for (x = x1; x <= x2; x++)
2236 for (y = y1; y <= y2; y++)
2238 total = x - x1 + y - y1;
2239 /* If total is odd- and is a floor then make a wall */
2240 if ((total % 2 == 1) && is_floor_bold(y, x))
2242 place_inner_bold(y, x);
2247 /* Make a couple of entrances */
2250 /* left and right */
2251 y = randint1(dy) + dy / 2;
2252 place_inner_bold(y1 + y, x1 - 1);
2253 place_inner_bold(y1 + y, x2 + 1);
2257 /* top and bottom */
2258 x = randint1(dx) + dx / 2;
2259 place_inner_bold(y1 - 1, x1 + x);
2260 place_inner_bold(y2 + 1, x1 + x);
2263 /* Fill with monsters and treasure, highest difficulty */
2264 fill_treasure(x1, x2, y1, y2, 10);
2266 C_KILL(visited, num_vertices, int);
2270 /* Build a town/ castle by using a recursive algorithm.
2271 * Basically divide each region in a probalistic way to create
2272 * smaller regions. When the regions get too small stop.
2274 * The power variable is a measure of how well defended a region is.
2275 * This alters the possible choices.
2277 static void build_recursive_room(int x1, int y1, int x2, int y2, int power)
2283 /* Temp variables */
2289 if ((power < 3) && (xsize > 12) && (ysize > 12))
2291 /* Need outside wall +keep */
2298 /* Make rooms + subdivide */
2299 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
2305 choice = randint1(2) + 1;
2310 /* Mostly subdivide */
2311 choice = randint1(3) + 1;
2315 /* Based on the choice made above, do something */
2323 /* top and bottom */
2324 for (x = x1; x <= x2; x++)
2326 place_outer_bold(y1, x);
2327 place_outer_bold(y2, x);
2330 /* left and right */
2331 for (y = y1 + 1; y < y2; y++)
2333 place_outer_bold(y, x1);
2334 place_outer_bold(y, x2);
2337 /* Make a couple of entrances */
2340 /* left and right */
2341 y = randint1(ysize) + y1;
2342 place_floor_bold(y, x1);
2343 place_floor_bold(y, x2);
2347 /* top and bottom */
2348 x = randint1(xsize) + x1;
2349 place_floor_bold(y1, x);
2350 place_floor_bold(y2, x);
2353 /* Select size of keep */
2354 t1 = randint1(ysize / 3) + y1;
2355 t2 = y2 - randint1(ysize / 3);
2356 t3 = randint1(xsize / 3) + x1;
2357 t4 = x2 - randint1(xsize / 3);
2359 /* Do outside areas */
2361 /* Above and below keep */
2362 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
2363 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
2365 /* Left and right of keep */
2366 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
2367 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
2369 /* Make the keep itself: */
2382 /* Try to build a room */
2383 if ((xsize < 3) || (ysize < 3))
2385 for (y = y1; y < y2; y++)
2387 for (x = x1; x < x2; x++)
2389 place_inner_bold(y, x);
2397 /* Make outside walls */
2398 /* top and bottom */
2399 for (x = x1 + 1; x <= x2 - 1; x++)
2401 place_inner_bold(y1 + 1, x);
2402 place_inner_bold(y2 - 1, x);
2405 /* left and right */
2406 for (y = y1 + 1; y <= y2 - 1; y++)
2408 place_inner_bold(y, x1 + 1);
2409 place_inner_bold(y, x2 - 1);
2413 y = randint1(ysize - 3) + y1 + 1;
2418 place_floor_bold(y, x1 + 1);
2423 place_floor_bold(y, x2 - 1);
2426 /* Build the room */
2427 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
2432 /* Try and divide vertically */
2436 for (y = y1; y < y2; y++)
2438 for (x = x1; x < x2; x++)
2440 place_inner_bold(y, x);
2446 t1 = randint1(xsize - 2) + x1 + 1;
2447 build_recursive_room(x1, y1, t1, y2, power - 2);
2448 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
2453 /* Try and divide horizontally */
2457 for (y = y1; y < y2; y++)
2459 for (x = x1; x < x2; x++)
2461 place_inner_bold(y, x);
2467 t1 = randint1(ysize - 2) + y1 + 1;
2468 build_recursive_room(x1, y1, x2, t1, power - 2);
2469 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
2476 /* Build a castle */
2478 /* Driver routine: clear the region and call the recursive
2481 *This makes a vault that looks like a castle/ city in the dungeon.
2483 static void build_castle_vault(int x0, int y0, int xsize, int ysize)
2489 /* Pick a random room size */
2498 msg_print_wizard(CHEAT_DUNGEON, _("城型ランダムVaultを生成しました。", "Castle Vault"));
2500 /* generate the room */
2501 for (y = y1 - 1; y <= y2 + 1; y++)
2503 for (x = x1 - 1; x <= x2 + 1; x++)
2505 cave[y][x].info |= (CAVE_ROOM | CAVE_ICKY);
2506 /* Make everything a floor */
2507 place_floor_bold(y, x);
2511 /* Make the castle */
2512 build_recursive_room(x1, y1, x2, y2, randint1(5));
2514 /* Fill with monsters and treasure, low difficulty */
2515 fill_treasure(x1, x2, y1, y2, randint1(3));
2520 * Add outer wall to a floored region
2521 * Note: no range checking is done so must be inside dungeon
2522 * This routine also stomps on doors
2524 void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
2527 feature_type *f_ptr;
2530 if (!in_bounds(y, x)) return;
2532 c_ptr = &cave[y][x];
2534 /* hack- check to see if square has been visited before
2535 * if so, then exit (use room flag to do this) */
2536 if (c_ptr->info & CAVE_ROOM) return;
2539 c_ptr->info |= CAVE_ROOM;
2541 f_ptr = &f_info[c_ptr->feat];
2543 if (is_floor_bold(y, x))
2545 for (i = -1; i <= 1; i++)
2547 for (j = -1; j <= 1; j++)
2549 if ((x + i >= x1) && (x + i <= x2) &&
2550 (y + j >= y1) && (y + j <= y2))
2552 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
2553 if (light) c_ptr->info |= CAVE_GLOW;
2558 else if (is_extra_bold(y, x))
2560 /* Set bounding walls */
2561 place_outer_bold(y, x);
2562 if (light) c_ptr->info |= CAVE_GLOW;
2564 else if (permanent_wall(f_ptr))
2566 /* Set bounding walls */
2567 if (light) c_ptr->info |= CAVE_GLOW;
2573 * Hacked distance formula - gives the 'wrong' answer.
2574 * Used to build crypts
2576 int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4)
2582 /* Basically this works by taking the normal pythagorean formula
2583 * and using an expansion to express this in a way without the
2584 * square root. This approximate formula is then perturbed to give
2585 * the distorted results. (I found this by making a mistake when I was
2586 * trying to fix the circular rooms.)
2589 /* h1-h4 are constants that describe the metric */
2590 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2591 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2592 return (((dx + dy) * 128) / 181 +
2593 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2594 /* 128/181 is approx. 1/sqrt(2) */
2599 * Build target vault.
2600 * This is made by two concentric "crypts" with perpendicular
2601 * walls creating the cross-hairs.
2603 static void build_target_vault(int x0, int y0, int xsize, int ysize)
2607 /* Make a random metric */
2609 h1 = randint1(32) - 16;
2612 h4 = randint1(32) - 16;
2614 msg_print_wizard(CHEAT_DUNGEON, _("対称形ランダムVaultを生成しました。", "Elemental Vault"));
2616 /* work out outer radius */
2627 for (x = x0 - rad; x <= x0 + rad; x++)
2629 for (y = y0 - rad; y <= y0 + rad; y++)
2631 /* clear room flag */
2632 cave[y][x].info &= ~(CAVE_ROOM);
2634 /* Vault - so is "icky" */
2635 cave[y][x].info |= CAVE_ICKY;
2637 if (dist2(y0, x0, y, x, h1, h2, h3, h4) <= rad - 1)
2639 /* inside- so is floor */
2640 place_floor_bold(y, x);
2644 /* make granite outside so arena works */
2645 place_extra_bold(y, x);
2648 /* proper boundary for arena */
2649 if (((y + rad) == y0) || ((y - rad) == y0) ||
2650 ((x + rad) == x0) || ((x - rad) == x0))
2652 place_extra_bold(y, x);
2657 /* Find visible outer walls and set to be FEAT_OUTER */
2658 add_outer_wall(x0, y0, FALSE, x0 - rad - 1, y0 - rad - 1,
2659 x0 + rad + 1, y0 + rad + 1);
2661 /* Add inner wall */
2662 for (x = x0 - rad / 2; x <= x0 + rad / 2; x++)
2664 for (y = y0 - rad / 2; y <= y0 + rad / 2; y++)
2666 if (dist2(y0, x0, y, x, h1, h2, h3, h4) == rad / 2)
2668 /* Make an internal wall */
2669 place_inner_bold(y, x);
2674 /* Add perpendicular walls */
2675 for (x = x0 - rad; x <= x0 + rad; x++)
2677 place_inner_bold(y0, x);
2680 for (y = y0 - rad; y <= y0 + rad; y++)
2682 place_inner_bold(y, x0);
2685 /* Make inner vault */
2686 for (y = y0 - 1; y <= y0 + 1; y++)
2688 place_inner_bold(y, x0 - 1);
2689 place_inner_bold(y, x0 + 1);
2691 for (x = x0 - 1; x <= x0 + 1; x++)
2693 place_inner_bold(y0 - 1, x);
2694 place_inner_bold(y0 + 1, x);
2697 place_floor_bold(y0, x0);
2700 /* Add doors to vault */
2701 /* get two distances so can place doors relative to centre */
2702 x = (rad - 2) / 4 + 1;
2705 add_door(x0 + x, y0);
2706 add_door(x0 + y, y0);
2707 add_door(x0 - x, y0);
2708 add_door(x0 - y, y0);
2709 add_door(x0, y0 + x);
2710 add_door(x0, y0 + y);
2711 add_door(x0, y0 - x);
2712 add_door(x0, y0 - y);
2714 /* Fill with stuff - medium difficulty */
2715 fill_treasure(x0 - rad, x0 + rad, y0 - rad, y0 + rad, randint1(3) + 3);
2719 #ifdef ALLOW_CAVERNS_AND_LAKES
2721 * This routine uses a modified version of the lake code to make a
2722 * distribution of some terrain type over the vault. This type
2723 * depends on the dungeon depth.
2725 * Miniture rooms are then scattered across the vault.
2727 static void build_elemental_vault(int x0, int y0, int xsiz, int ysiz)
2732 int xsize, ysize, xhsize, yhsize, x, y, i;
2735 msg_print_wizard(CHEAT_DUNGEON, _("精霊界ランダムVaultを生成しました。", "Elemental Vault"));
2737 /* round to make sizes even */
2745 /* Earth vault (Rubble) */
2746 type = LAKE_T_EARTH_VAULT;
2748 else if (dun_level < 50)
2750 /* Air vault (Trees) */
2751 type = LAKE_T_AIR_VAULT;
2753 else if (dun_level < 75)
2755 /* Water vault (shallow water) */
2756 type = LAKE_T_WATER_VAULT;
2760 /* Fire vault (shallow lava) */
2761 type = LAKE_T_FIRE_VAULT;
2766 /* testing values for these parameters: feel free to adjust */
2767 grd = 1 << (randint0(3));
2769 /* want average of about 16 */
2770 roug = randint1(8) * randint1(4);
2772 /* Make up size of various componants */
2776 /* Deep water/lava */
2777 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
2779 /* Shallow boundary */
2783 generate_hmap(y0, x0, xsize, ysize, grd, roug, c3);
2785 /* Convert to normal format+ clean up */
2786 done = generate_lake(y0, x0, xsize, ysize, c1, c2, c3, type);
2789 /* Set icky flag because is a vault */
2790 for (x = 0; x <= xsize; x++)
2792 for (y = 0; y <= ysize; y++)
2794 cave[y0 - yhsize + y][x0 - xhsize + x].info |= CAVE_ICKY;
2798 /* make a few rooms in the vault */
2799 for (i = 1; i <= (xsize * ysize) / 50; i++)
2801 build_small_room(x0 + randint0(xsize - 4) - xsize / 2 + 2,
2802 y0 + randint0(ysize - 4) - ysize / 2 + 2);
2805 /* Fill with monsters and treasure, low difficulty */
2806 fill_treasure(x0 - xhsize + 1, x0 - xhsize + xsize - 1,
2807 y0 - yhsize + 1, y0 - yhsize + ysize - 1, randint1(5));
2809 #endif /* ALLOW_CAVERNS_AND_LAKES */
2813 * @brief タイプ10の部屋…ランダム生成vault / Type 10 -- Random vaults
2816 static bool build_type10(void)
2818 POSITION y0, x0, xsize, ysize, vtype;
2821 /* big enough to look good, small enough to be fairly common. */
2822 xsize = randint1(22) + 22;
2823 ysize = randint1(11) + 11;
2825 /* Find and reserve some space in the dungeon. Get center of room. */
2826 if (!find_space(&y0, &x0, ysize + 1, xsize + 1)) return FALSE;
2828 /* Select type of vault */
2829 #ifdef ALLOW_CAVERNS_AND_LAKES
2832 vtype = randint1(15);
2834 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
2835 ((vtype == 1) || (vtype == 3) || (vtype == 8) || (vtype == 9) || (vtype == 11)));
2836 #else /* ALLOW_CAVERNS_AND_LAKES */
2839 vtype = randint1(7);
2841 while ((d_info[dungeon_type].flags1 & DF1_NO_CAVE) &&
2842 ((vtype == 1) || (vtype == 3)));
2843 #endif /* ALLOW_CAVERNS_AND_LAKES */
2847 /* Build an appropriate room */
2848 case 1: case 9: build_bubble_vault(x0, y0, xsize, ysize); break;
2849 case 2: case 10: build_room_vault(x0, y0, xsize, ysize); break;
2850 case 3: case 11: build_cave_vault(x0, y0, xsize, ysize); break;
2851 case 4: case 12: build_maze_vault(x0, y0, xsize, ysize, TRUE); break;
2852 case 5: case 13: build_mini_c_vault(x0, y0, xsize, ysize); break;
2853 case 6: case 14: build_castle_vault(x0, y0, xsize, ysize); break;
2854 case 7: case 15: build_target_vault(x0, y0, xsize, ysize); break;
2855 #ifdef ALLOW_CAVERNS_AND_LAKES
2856 case 8: build_elemental_vault(x0, y0, xsize, ysize); break;
2857 #endif /* ALLOW_CAVERNS_AND_LAKES */
2858 /* I know how to add a few more... give me some time. */
2861 default: return FALSE;
2870 * @brief タイプ14の部屋…特殊トラップ部屋の生成 / Type 14 -- trapped rooms
2873 * A special trap is placed at center of the room
2875 static bool build_type14(void)
2877 POSITION y, x, y2, x2, yval, xval;
2878 POSITION y1, x1, xsize, ysize;
2885 /* Pick a room size */
2891 xsize = x1 + x2 + 1;
2892 ysize = y1 + y2 + 1;
2894 /* Find and reserve some space in the dungeon. Get center of room. */
2895 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
2897 /* Choose lite or dark */
2898 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
2901 /* Get corner values */
2902 y1 = yval - ysize / 2;
2903 x1 = xval - xsize / 2;
2904 y2 = yval + (ysize - 1) / 2;
2905 x2 = xval + (xsize - 1) / 2;
2908 /* Place a full floor under the room */
2909 for (y = y1 - 1; y <= y2 + 1; y++)
2911 for (x = x1 - 1; x <= x2 + 1; x++)
2913 c_ptr = &cave[y][x];
2914 place_floor_grid(c_ptr);
2915 c_ptr->info |= (CAVE_ROOM);
2916 if (light) c_ptr->info |= (CAVE_GLOW);
2920 /* Walls around the room */
2921 for (y = y1 - 1; y <= y2 + 1; y++)
2923 c_ptr = &cave[y][x1 - 1];
2924 place_outer_grid(c_ptr);
2925 c_ptr = &cave[y][x2 + 1];
2926 place_outer_grid(c_ptr);
2928 for (x = x1 - 1; x <= x2 + 1; x++)
2930 c_ptr = &cave[y1 - 1][x];
2931 place_outer_grid(c_ptr);
2932 c_ptr = &cave[y2 + 1][x];
2933 place_outer_grid(c_ptr);
2936 if (dun_level < 30 + randint1(30))
2937 trap = feat_trap_piranha;
2939 trap = feat_trap_armageddon;
2941 /* Place a special trap */
2942 c_ptr = &cave[rand_spread(yval, ysize/4)][rand_spread(xval, xsize/4)];
2943 c_ptr->mimic = c_ptr->feat;
2946 msg_format_wizard(CHEAT_DUNGEON, _("%sの部屋が生成されました。", "Room of %s was generated."), f_name + f_info[trap].name);
2953 * Helper function for "glass room"
2955 static bool vault_aux_lite(MONRACE_IDX r_idx)
2957 monster_race *r_ptr = &r_info[r_idx];
2959 /* Validate the monster */
2960 if (!vault_monster_okay(r_idx)) return FALSE;
2962 /* Require lite attack */
2963 if (!(r_ptr->flags4 & RF4_BR_LITE) && !(r_ptr->a_ability_flags1 & RF5_BA_LITE)) return FALSE;
2965 /* No wall passing monsters */
2966 if (r_ptr->flags2 & (RF2_PASS_WALL | RF2_KILL_WALL)) return FALSE;
2968 /* No disintegrating monsters */
2969 if (r_ptr->flags4 & RF4_BR_DISI) return FALSE;
2975 * Helper function for "glass room"
2977 static bool vault_aux_shards(MONRACE_IDX r_idx)
2979 monster_race *r_ptr = &r_info[r_idx];
2981 /* Validate the monster */
2982 if (!vault_monster_okay(r_idx)) return FALSE;
2984 /* Require shards breath attack */
2985 if (!(r_ptr->flags4 & RF4_BR_SHAR)) return FALSE;
2991 * Hack -- determine if a template is potion
2993 static bool kind_is_potion(KIND_OBJECT_IDX k_idx)
2995 return k_info[k_idx].tval == TV_POTION;
2999 * @brief タイプ15の部屋…ガラス部屋の生成 / Type 15 -- glass rooms
3002 static bool build_type15(void)
3004 POSITION y, x, y2, x2, yval, xval;
3005 POSITION y1, x1, xsize, ysize;
3010 /* Pick a room size */
3011 xsize = rand_range(9, 13);
3012 ysize = rand_range(9, 13);
3014 /* Find and reserve some space in the dungeon. Get center of room. */
3015 if (!find_space(&yval, &xval, ysize + 2, xsize + 2)) return FALSE;
3017 /* Choose lite or dark */
3018 light = ((dun_level <= randint1(25)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
3020 /* Get corner values */
3021 y1 = yval - ysize / 2;
3022 x1 = xval - xsize / 2;
3023 y2 = yval + (ysize - 1) / 2;
3024 x2 = xval + (xsize - 1) / 2;
3026 /* Place a full floor under the room */
3027 for (y = y1 - 1; y <= y2 + 1; y++)
3029 for (x = x1 - 1; x <= x2 + 1; x++)
3031 c_ptr = &cave[y][x];
3032 place_floor_grid(c_ptr);
3033 c_ptr->feat = feat_glass_floor;
3034 c_ptr->info |= (CAVE_ROOM);
3035 if (light) c_ptr->info |= (CAVE_GLOW);
3039 /* Walls around the room */
3040 for (y = y1 - 1; y <= y2 + 1; y++)
3042 c_ptr = &cave[y][x1 - 1];
3043 place_outer_grid(c_ptr);
3044 c_ptr->feat = feat_glass_wall;
3045 c_ptr = &cave[y][x2 + 1];
3046 place_outer_grid(c_ptr);
3047 c_ptr->feat = feat_glass_wall;
3049 for (x = x1 - 1; x <= x2 + 1; x++)
3051 c_ptr = &cave[y1 - 1][x];
3052 place_outer_grid(c_ptr);
3053 c_ptr->feat = feat_glass_wall;
3054 c_ptr = &cave[y2 + 1][x];
3055 place_outer_grid(c_ptr);
3056 c_ptr->feat = feat_glass_wall;
3059 switch (randint1(3))
3061 case 1: /* 4 lite breathers + potion */
3065 /* Prepare allocation table */
3066 get_mon_num_prep(vault_aux_lite, NULL);
3068 /* Place fixed lite berathers */
3069 for (dir1 = 4; dir1 < 8; dir1++)
3071 MONRACE_IDX r_idx = get_mon_num(dun_level);
3073 y = yval + 2 * ddy_ddd[dir1];
3074 x = xval + 2 * ddx_ddd[dir1];
3075 if (r_idx) place_monster_aux(0, y, x, r_idx, PM_ALLOW_SLEEP);
3077 /* Walls around the breather */
3078 for (dir2 = 0; dir2 < 8; dir2++)
3080 c_ptr = &cave[y + ddy_ddd[dir2]][x + ddx_ddd[dir2]];
3081 place_inner_grid(c_ptr);
3082 c_ptr->feat = feat_glass_wall;
3086 /* Walls around the potion */
3087 for (dir1 = 0; dir1 < 4; dir1++)
3089 y = yval + 2 * ddy_ddd[dir1];
3090 x = xval + 2 * ddx_ddd[dir1];
3091 c_ptr = &cave[y][x];
3092 place_inner_perm_grid(c_ptr);
3093 c_ptr->feat = feat_permanent_glass_wall;
3094 cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]].info |= (CAVE_ICKY);
3099 y = yval + 2 * ddy_ddd[dir1];
3100 x = xval + 2 * ddx_ddd[dir1];
3101 place_secret_door(y, x, DOOR_GLASS_DOOR);
3102 c_ptr = &cave[y][x];
3103 if (is_closed_door(c_ptr->feat)) c_ptr->mimic = feat_glass_wall;
3105 /* Place a potion */
3106 get_obj_num_hook = kind_is_potion;
3107 place_object(yval, xval, AM_NO_FIXED_ART);
3108 cave[yval][xval].info |= (CAVE_ICKY);
3112 case 2: /* 1 lite breather + random object */
3118 c_ptr = &cave[y1 + 1][x1 + 1];
3119 place_inner_grid(c_ptr);
3120 c_ptr->feat = feat_glass_wall;
3122 c_ptr = &cave[y1 + 1][x2 - 1];
3123 place_inner_grid(c_ptr);
3124 c_ptr->feat = feat_glass_wall;
3126 c_ptr = &cave[y2 - 1][x1 + 1];
3127 place_inner_grid(c_ptr);
3128 c_ptr->feat = feat_glass_wall;
3130 c_ptr = &cave[y2 - 1][x2 - 1];
3131 place_inner_grid(c_ptr);
3132 c_ptr->feat = feat_glass_wall;
3134 /* Prepare allocation table */
3135 get_mon_num_prep(vault_aux_lite, NULL);
3137 r_idx = get_mon_num(dun_level);
3138 if (r_idx) place_monster_aux(0, yval, xval, r_idx, 0L);
3140 /* Walls around the breather */
3141 for (dir1 = 0; dir1 < 8; dir1++)
3143 c_ptr = &cave[yval + ddy_ddd[dir1]][xval + ddx_ddd[dir1]];
3144 place_inner_grid(c_ptr);
3145 c_ptr->feat = feat_glass_wall;
3148 /* Curtains around the breather */
3149 for (y = yval - 1; y <= yval + 1; y++)
3151 place_closed_door(y, xval - 2, DOOR_CURTAIN);
3152 place_closed_door(y, xval + 2, DOOR_CURTAIN);
3154 for (x = xval - 1; x <= xval + 1; x++)
3156 place_closed_door(yval - 2, x, DOOR_CURTAIN);
3157 place_closed_door(yval + 2, x, DOOR_CURTAIN);
3160 /* Place an object */
3161 place_object(yval, xval, AM_NO_FIXED_ART);
3162 cave[yval][xval].info |= (CAVE_ICKY);
3166 case 3: /* 4 shards breathers + 2 potions */
3170 /* Walls around the potion */
3171 for (y = yval - 2; y <= yval + 2; y++)
3173 c_ptr = &cave[y][xval - 3];
3174 place_inner_grid(c_ptr);
3175 c_ptr->feat = feat_glass_wall;
3176 c_ptr = &cave[y][xval + 3];
3177 place_inner_grid(c_ptr);
3178 c_ptr->feat = feat_glass_wall;
3180 for (x = xval - 2; x <= xval + 2; x++)
3182 c_ptr = &cave[yval - 3][x];
3183 place_inner_grid(c_ptr);
3184 c_ptr->feat = feat_glass_wall;
3185 c_ptr = &cave[yval + 3][x];
3186 place_inner_grid(c_ptr);
3187 c_ptr->feat = feat_glass_wall;
3189 for (dir1 = 4; dir1 < 8; dir1++)
3191 c_ptr = &cave[yval + 2 * ddy_ddd[dir1]][xval + 2 * ddx_ddd[dir1]];
3192 place_inner_grid(c_ptr);
3193 c_ptr->feat = feat_glass_wall;
3196 /* Prepare allocation table */
3197 get_mon_num_prep(vault_aux_shards, NULL);
3199 /* Place shard berathers */
3200 for (dir1 = 4; dir1 < 8; dir1++)
3202 MONRACE_IDX r_idx = get_mon_num(dun_level);
3204 y = yval + ddy_ddd[dir1];
3205 x = xval + ddx_ddd[dir1];
3206 if (r_idx) place_monster_aux(0, y, x, r_idx, 0L);
3209 /* Place two potions */
3212 get_obj_num_hook = kind_is_potion;
3213 place_object(yval, xval - 1, AM_NO_FIXED_ART);
3214 get_obj_num_hook = kind_is_potion;
3215 place_object(yval, xval + 1, AM_NO_FIXED_ART);
3219 get_obj_num_hook = kind_is_potion;
3220 place_object(yval - 1, xval, AM_NO_FIXED_ART);
3221 get_obj_num_hook = kind_is_potion;
3222 place_object(yval + 1, xval, AM_NO_FIXED_ART);
3225 for (y = yval - 2; y <= yval + 2; y++)
3226 for (x = xval - 2; x <= xval + 2; x++)
3227 cave[y][x].info |= (CAVE_ICKY);
3233 msg_print_wizard(CHEAT_DUNGEON, _("ガラスの部屋が生成されました。", "Glass room was generated."));
3239 /* Create a new floor room with optional light */
3240 void generate_room_floor(int y1, int x1, int y2, int x2, int light)
3246 for (y = y1; y <= y2; y++)
3248 for (x = x1; x <= x2; x++)
3251 c_ptr = &cave[y][x];
3252 place_floor_grid(c_ptr);
3253 c_ptr->info |= (CAVE_ROOM);
3254 if (light) c_ptr->info |= (CAVE_GLOW);
3259 void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
3263 for (y = y1; y <= y2; y++)
3265 for (x = x1; x <= x2; x++)
3268 place_inner_perm_bold(y, x);
3275 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
3277 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
3278 * @return 部屋の精製に成功した場合 TRUE を返す。
3280 static bool room_build(int typ)
3285 /* Build an appropriate room */
3286 case ROOM_T_NORMAL: return build_type1();
3287 case ROOM_T_OVERLAP: return build_type2();
3288 case ROOM_T_CROSS: return build_type3();
3289 case ROOM_T_INNER_FEAT: return build_type4();
3290 case ROOM_T_NEST: return build_type5();
3291 case ROOM_T_PIT: return build_type6();
3292 case ROOM_T_LESSER_VAULT: return build_type7();
3293 case ROOM_T_GREATER_VAULT: return build_type8();
3294 case ROOM_T_FRACAVE: return build_type9();
3295 case ROOM_T_RANDOM_VAULT: return build_type10();
3296 case ROOM_T_OVAL: return build_type11();
3297 case ROOM_T_CRYPT: return build_type12();
3298 case ROOM_T_TRAP_PIT: return build_type13();
3299 case ROOM_T_TRAP: return build_type14();
3300 case ROOM_T_GLASS: return build_type15();
3301 case ROOM_T_ARCADE: return build_type16();
3309 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
3310 * @param dst 確率を移す先の部屋種ID
3311 * @param src 確率を与える元の部屋種ID
3313 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
3316 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
3317 * @return 部屋生成に成功した場合 TRUE を返す。
3319 bool generate_rooms(void)
3325 int prob_list[ROOM_T_MAX];
3326 int rooms_built = 0;
3327 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
3328 int level_index = MIN(10, div_round(dun_level, 10));
3330 /* Number of each type of room on this level */
3331 s16b room_num[ROOM_T_MAX];
3333 /* Limit number of rooms */
3334 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
3336 /* Assume normal cave */
3337 room_info_type *room_info_ptr = room_info_normal;
3340 * Initialize probability list.
3342 for (i = 0; i < ROOM_T_MAX; i++)
3344 /* No rooms allowed above their minimum depth. */
3345 if (dun_level < room_info_ptr[i].min_level)
3351 prob_list[i] = room_info_ptr[i].prob[level_index];
3356 * XXX -- Various dungeon types and options.
3359 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、かつ「常に通常でない部屋を生成する」フラグがONならば、GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
3360 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
3362 for (i = 0; i < ROOM_T_MAX; i++)
3364 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
3365 else prob_list[i] = 0;
3369 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
3370 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
3372 prob_list[ROOM_T_LESSER_VAULT] = 0;
3373 prob_list[ROOM_T_GREATER_VAULT] = 0;
3374 prob_list[ROOM_T_RANDOM_VAULT] = 0;
3377 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
3378 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
3380 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
3381 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
3382 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
3385 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
3386 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
3388 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
3391 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
3392 else if (dun->cavern || dun->empty_level)
3394 prob_list[ROOM_T_FRACAVE] = 0;
3397 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
3398 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
3400 prob_list[ROOM_T_GLASS] = 0;
3403 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
3404 if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
3406 prob_list[ROOM_T_ARCADE] = 0;
3410 * Initialize number of rooms,
3411 * And calcurate total probability.
3413 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
3416 total_prob += prob_list[i];
3420 * Prepare the number of rooms, of all types, we should build
3423 for (i = dun_rooms; i > 0; i--)
3426 int rand = randint0(total_prob);
3428 /* Get room_type randomly */
3429 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
3431 if (rand < prob_list[room_type]) break;
3432 else rand -= prob_list[room_type];
3436 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
3438 /* Increase the number of rooms of that type we should build. */
3439 room_num[room_type]++;
3445 case ROOM_T_LESSER_VAULT:
3446 case ROOM_T_TRAP_PIT:
3454 case ROOM_T_GREATER_VAULT:
3455 case ROOM_T_RANDOM_VAULT:
3464 * Build each type of room one by one until we cannot build any more.
3465 * [from SAngband (originally from OAngband)]
3469 /* Assume no remaining rooms */
3472 for (i = 0; i < ROOM_T_MAX; i++)
3474 /* What type of room are we building now? */
3475 int room_type = room_build_order[i];
3477 /* Go next if none available */
3478 if (!room_num[room_type]) continue;
3480 /* Use up one unit */
3481 room_num[room_type]--;
3483 /* Build the room. */
3484 if (room_build(room_type))
3486 /* Increase the room built count. */
3489 /* Mark as there was some remaining rooms */
3496 case ROOM_T_TRAP_PIT:
3498 /* Avoid too many monsters */
3501 room_num[ROOM_T_PIT] = 0;
3502 room_num[ROOM_T_NEST] = 0;
3503 room_num[ROOM_T_TRAP_PIT] = 0;
3509 /* Avoid double-town */
3510 room_num[ROOM_T_ARCADE] = 0;
3516 /* End loop if no room remain */
3520 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
3521 if (rooms_built < 2)
3523 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
3527 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);