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"
55 *[from SAngband (originally from OAngband)]\n
57 * Table of values that control how many times each type of room will\n
58 * appear. Each type of room has its own row, and each column\n
59 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
60 * value is the minimum depth the room can appear at. -LM-\n
62 * Level 101 and below use the values for level 100.\n
64 * Rooms with lots of monsters or loot may not be generated if the\n
65 * object or monster lists are already nearly full. Rooms will not\n
66 * appear above their minimum depth. Tiny levels will not have space\n
67 * for all the rooms you ask for.\n
69 static room_info_type room_info_normal[ROOM_T_MAX] =
72 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
74 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
75 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
76 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
77 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
78 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
79 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
80 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
81 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
82 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
83 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
84 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
85 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
86 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
87 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
88 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
89 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
93 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
94 static byte room_build_order[ROOM_T_MAX] = {
114 * @brief 鍵のかかったドアを配置する
115 * @param y 配置したいフロアのY座標
116 * @param x 配置したいフロアのX座標
119 void place_locked_door(int y, int x)
121 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
123 place_floor_bold(y, x);
127 set_cave_feat(y, x, feat_locked_door_random((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
128 cave[y][x].info &= ~(CAVE_FLOOR);
129 delete_monster(y, x);
135 * @param y 配置したいフロアのY座標
136 * @param x 配置したいフロアのX座標
137 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
140 void place_secret_door(int y, int x, int type)
142 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
144 place_floor_bold(y, x);
148 cave_type *c_ptr = &cave[y][x];
150 if (type == DOOR_DEFAULT)
152 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
153 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
154 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
157 /* Create secret door */
158 place_closed_door(y, x, type);
160 if (type != DOOR_CURTAIN)
162 /* Hide by inner wall because this is used in rooms only */
163 c_ptr->mimic = feat_wall_inner;
165 /* Floor type terrain cannot hide a door */
166 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
168 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
170 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
176 c_ptr->info &= ~(CAVE_FLOOR);
177 delete_monster(y, x);
182 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
183 * @param y0 配置したい中心のY座標
184 * @param x0 配置したい中心のX座標
186 * This funtion makes a very small room centred at (x0, y0)
187 * This is used in crypts, and random elemental vaults.
189 * Note - this should be used only on allocated regions
190 * within another room.
192 void build_small_room(int x0, int y0)
196 for (y = y0 - 1; y <= y0 + 1; y++)
198 place_inner_bold(y, x0 - 1);
199 place_inner_bold(y, x0 + 1);
202 for (x = x0 - 1; x <= x0 + 1; x++)
204 place_inner_bold(y0 - 1, x);
205 place_inner_bold(y0 + 1, x);
208 /* Place a secret door on one side */
211 case 0: place_secret_door(y0, x0 - 1, DOOR_DEFAULT); break;
212 case 1: place_secret_door(y0, x0 + 1, DOOR_DEFAULT); break;
213 case 2: place_secret_door(y0 - 1, x0, DOOR_DEFAULT); break;
214 case 3: place_secret_door(y0 + 1, x0, DOOR_DEFAULT); break;
217 /* Clear mimic type */
218 cave[y0][x0].mimic = 0;
220 /* Add inner open space */
221 place_floor_bold(y0, x0);
226 * 指定範囲に通路が通っていることを確認した上で床で埋める
227 * This function tunnels around a room if it will cut off part of a cave system.
234 static void check_room_boundary(int x1, int y1, int x2, int y2)
237 bool old_is_floor, new_is_floor;
243 old_is_floor = get_is_floor(x1 - 1, y1);
246 * Count the number of floor-wall boundaries around the room
247 * Note: diagonal squares are ignored since the player can move diagonally
248 * to bypass these if needed.
251 /* Above the top boundary */
252 for (x = x1; x <= x2; x++)
254 new_is_floor = get_is_floor(x, y1 - 1);
256 /* Increment counter if they are different */
257 if (new_is_floor != old_is_floor) count++;
259 old_is_floor = new_is_floor;
263 for (y = y1; y <= y2; y++)
265 new_is_floor = get_is_floor(x2 + 1, y);
267 /* increment counter if they are different */
268 if (new_is_floor != old_is_floor) count++;
270 old_is_floor = new_is_floor;
273 /* Bottom boundary */
274 for (x = x2; x >= x1; x--)
276 new_is_floor = get_is_floor(x, y2 + 1);
278 /* increment counter if they are different */
279 if (new_is_floor != old_is_floor) count++;
281 old_is_floor = new_is_floor;
285 for (y = y2; y >= y1; y--)
287 new_is_floor = get_is_floor(x1 - 1, y);
289 /* increment counter if they are different */
290 if (new_is_floor != old_is_floor) count++;
292 old_is_floor = new_is_floor;
295 /* If all the same, or only one connection exit. */
296 if (count <= 2) return;
299 /* Tunnel around the room so to prevent problems with caves */
300 for (y = y1; y <= y2; y++)
302 for (x = x1; x <= x2; x++)
312 * find_space()の予備処理として部屋の生成が可能かを判定する /
313 * Helper function for find_space(). Is this a good location?
314 * @param blocks_high 範囲の高さ
315 * @param blocks_wide 範囲の幅
316 * @param block_y 範囲の上端
317 * @param block_x 範囲の左端
320 static bool find_space_aux(int blocks_high, int blocks_wide, int block_y, int block_x)
322 int by1, bx1, by2, bx2, by, bx;
324 /* Itty-bitty rooms must shift about within their rectangle */
327 if ((blocks_wide == 2) && (block_x % 3) == 2)
331 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
332 else if ((blocks_wide % 3) == 0)
334 /* Must be aligned to the left edge of a 11x33 rectangle. */
335 if ((block_x % 3) != 0)
340 * Big rooms that do not have a width divisible by 3 must be
341 * aligned towards the edge of the dungeon closest to them.
345 /* Shift towards left edge of dungeon. */
346 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
348 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
350 if ((block_x % 3) == 1)
354 /* Shift toward right edge of dungeon. */
357 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
359 if ((block_x % 3) == 1)
367 by2 = block_y + blocks_high;
368 bx2 = block_x + blocks_wide;
370 /* Never run off the screen */
371 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
372 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
374 /* Verify available space */
375 for (by = by1; by < by2; by++)
377 for (bx = bx1; bx < bx2; bx++)
379 if (dun->room_map[by][bx])
386 /* This location is okay */
392 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
393 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
394 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
395 * @param height 確保したい領域の高さ
396 * @param width 確保したい領域の幅
397 * @return 所定の範囲が確保できた場合TRUEを返す
399 * Find and allocate a free space in the dungeon large enough to hold\n
400 * the room calling this function.\n
402 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
403 * align neatly on the standard screen. Therefore, we make them use\n
404 * blocks in few 11x33 rectangles as possible.\n
406 * Be careful to include the edges of the room in height and width!\n
408 * Return TRUE and values for the center of the room if all went well.\n
409 * Otherwise, return FALSE.\n
411 bool find_space(POSITION *y, POSITION *x, POSITION height, POSITION width)
413 int candidates, pick;
414 int by, bx, by1, bx1, by2, bx2;
415 int block_y = 0, block_x = 0;
418 /* Find out how many blocks we need. */
419 int blocks_high = 1 + ((height - 1) / BLOCK_HGT);
420 int blocks_wide = 1 + ((width - 1) / BLOCK_WID);
422 /* There are no way to allocate such huge space */
423 if (dun->row_rooms < blocks_high) return FALSE;
424 if (dun->col_rooms < blocks_wide) return FALSE;
429 /* Count the number of valid places */
430 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
432 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
434 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
436 /* Find a valid place */
449 if (!(d_info[dungeon_type].flags1 & DF1_NO_CAVE))
451 /* Choose a random one */
452 pick = randint1(candidates);
455 /* NO_CAVE dungeon (Castle) */
458 /* Always choose the center one */
459 pick = candidates/2 + 1;
462 /* Pick up the choosen location */
463 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
465 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
467 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
471 /* This one is picked? */
482 by2 = block_y + blocks_high;
483 bx2 = block_x + blocks_wide;
486 * It is *extremely* important that the following calculation
487 * be *exactly* correct to prevent memory errors
490 /* Acquire the location of the room */
491 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
492 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
494 /* Save the room location */
495 if (dun->cent_n < CENT_MAX)
497 dun->cent[dun->cent_n].y = (byte_hack)*y;
498 dun->cent[dun->cent_n].x = (byte_hack)*x;
502 /* Reserve some blocks. */
503 for (by = by1; by < by2; by++)
505 for (bx = bx1; bx < bx2; bx++)
507 dun->room_map[by][bx] = TRUE;
513 * Hack- See if room will cut off a cavern.
515 * If so, fix by tunneling outside the room in such a
516 * way as to connect the caves.
518 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 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 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
1173 #ifdef ALLOW_CAVERNS_AND_LAKES
1175 * Builds a cave system in the center of the dungeon.
1177 void build_cavern(void)
1179 int grd, roug, cutoff, xsize, ysize, x0, y0;
1182 light = done = FALSE;
1183 if ((dun_level <= randint1(50)) && !(d_info[dungeon_type].flags1 & DF1_DARKNESS)) light = TRUE;
1185 /* Make a cave the size of the dungeon */
1186 xsize = cur_wid - 1;
1187 ysize = cur_hgt - 1;
1191 /* Paranoia: make size even */
1197 /* testing values for these parameters: feel free to adjust */
1198 grd = randint1(4) + 4;
1200 /* want average of about 16 */
1201 roug = randint1(8) * randint1(4);
1207 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1209 /* Convert to normal format+ clean up */
1210 done = generate_fracave(y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1214 bool generate_lake(int y0, int x0, int xsize, int ysize, int c1, int c2, int c3, int type)
1216 int x, y, i, xhsize, yhsize;
1217 int feat1, feat2, feat3;
1219 /* offsets to middle from corner */
1223 /* Get features based on type */
1226 case LAKE_T_LAVA: /* Lava */
1227 feat1 = feat_deep_lava;
1228 feat2 = feat_shallow_lava;
1229 feat3 = floor_type[randint0(100)];
1231 case LAKE_T_WATER: /* Water */
1232 feat1 = feat_deep_water;
1233 feat2 = feat_shallow_water;
1234 feat3 = floor_type[randint0(100)];
1236 case LAKE_T_CAVE: /* Collapsed cave */
1237 feat1 = floor_type[randint0(100)];
1238 feat2 = floor_type[randint0(100)];
1239 feat3 = feat_rubble;
1241 case LAKE_T_EARTH_VAULT: /* Earth vault */
1242 feat1 = feat_rubble;
1243 feat2 = floor_type[randint0(100)];
1244 feat3 = feat_rubble;
1246 case LAKE_T_AIR_VAULT: /* Air vault */
1251 case LAKE_T_WATER_VAULT: /* Water vault */
1252 feat1 = feat_shallow_water;
1253 feat2 = feat_deep_water;
1254 feat3 = feat_shallow_water;
1256 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1257 feat1 = feat_shallow_lava;
1258 feat2 = feat_deep_lava;
1259 feat3 = feat_shallow_lava;
1263 default: return FALSE;
1267 * select region connected to center of cave system
1268 * this gets rid of alot of isolated one-sqaures that
1269 * can make teleport traps instadeaths...
1277 /* features to fill with */
1278 fill_data.feat1 = feat1;
1279 fill_data.feat2 = feat2;
1280 fill_data.feat3 = feat3;
1282 fill_data.info1 = 0;
1283 fill_data.info2 = 0;
1284 fill_data.info3 = 0;
1286 /* number of filled squares */
1287 fill_data.amount = 0;
1289 /* select region connected to center of cave system
1290 * this gets rid of alot of isolated one-sqaures that
1291 * can make teleport traps instadeaths... */
1292 cave_fill((byte)y0, (byte)x0);
1294 /* if tally too small, try again */
1295 if (fill_data.amount < 10)
1297 /* too small -clear area and try again later */
1298 for (x = 0; x <= xsize; ++x)
1300 for (y = 0; y <= ysize; ++y)
1302 place_floor_bold(y0 + y - yhsize, x0 + x - xhsize);
1303 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1309 /* Do boundarys- set to normal granite */
1310 for (i = 0; i <= xsize; ++i)
1312 place_extra_bold(y0 + 0 - yhsize, x0 + i - xhsize);
1313 place_extra_bold(y0 + ysize - yhsize, x0 + i - xhsize);
1315 /* clear the icky flag-don't need it any more */
1316 cave[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1317 cave[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1320 /* Do the left and right boundaries minus the corners (done above) */
1322 for (i = 1; i < ysize; ++i)
1324 place_extra_bold(y0 + i - yhsize, x0 + 0 - xhsize);
1325 place_extra_bold(y0 + i - yhsize, x0 + xsize - xhsize);
1327 /* clear icky flag -done with it */
1328 cave[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1329 cave[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1333 /* Do the rest: convert back to the normal format */
1334 for (x = 1; x < xsize; ++x)
1336 for (y = 1; y < ysize; ++y)
1338 /* Fill unconnected regions with granite */
1339 if ((!(cave[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1340 is_outer_bold(y0 + y - yhsize, x0 + x - xhsize))
1341 place_extra_bold(y0 + y - yhsize, x0 + x - xhsize);
1343 /* turn off icky flag (no longer needed.) */
1344 cave[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1347 if (cave_have_flag_bold(y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1349 if (!(d_info[dungeon_type].flags1 & DF1_DARKNESS)) cave[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1359 * makes a lake/collapsed cave system in the center of the dungeon
1361 void build_lake(int type)
1363 int grd, roug, xsize, ysize, x0, y0;
1367 /* paranoia - exit if lake type out of range. */
1368 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1370 msg_format("Invalid lake type (%d)", type);
1374 /* Make the size of the dungeon */
1375 xsize = cur_wid - 1;
1376 ysize = cur_hgt - 1;
1380 /* Paranoia: make size even */
1386 /* testing values for these parameters: feel free to adjust */
1387 grd = randint1(3) + 4;
1389 /* want average of about 16 */
1390 roug = randint1(8) * randint1(4);
1392 /* Make up size of various componants */
1396 /* Deep water/lava */
1397 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1399 /* Shallow boundary */
1403 generate_hmap(y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1405 /* Convert to normal format+ clean up */
1406 done = generate_lake(y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1409 #endif /* ALLOW_CAVERNS_AND_LAKES */
1413 * Routine used by the random vault creators to add a door to a location
1414 * Note that range checking has to be done in the calling routine.
1416 * The doors must be INSIDE the allocated region.
1418 void add_door(int x, int y)
1420 /* Need to have a wall in the center square */
1421 if (!is_outer_bold(y, x)) return;
1428 * where x=don't care
1432 if (is_floor_bold(y-1,x) && is_floor_bold(y+1,x) &&
1433 (is_outer_bold(y, x - 1) && is_outer_bold(y, x + 1)))
1436 place_secret_door(y, x, DOOR_DEFAULT);
1438 /* set boundarys so don't get wide doors */
1439 place_solid_bold(y, x - 1);
1440 place_solid_bold(y, x + 1);
1449 * where x = don't care
1452 if (is_outer_bold(y - 1, x) && is_outer_bold(y + 1, x) &&
1453 is_floor_bold(y,x-1) && is_floor_bold(y,x+1))
1456 place_secret_door(y, x, DOOR_DEFAULT);
1458 /* set boundarys so don't get wide doors */
1459 place_solid_bold(y - 1, x);
1460 place_solid_bold(y + 1, x);
1466 * Routine that fills the empty areas of a room with treasure and monsters.
1468 void fill_treasure(int x1, int x2, int y1, int y2, int difficulty)
1470 int x, y, cx, cy, size;
1473 /* center of room:*/
1477 /* Rough measure of size of vault= sum of lengths of sides */
1478 size = abs(x2 - x1) + abs(y2 - y1);
1480 for (x = x1; x <= x2; x++)
1482 for (y = y1; y <= y2; y++)
1484 /* Thing added based on distance to center of vault
1485 * Difficulty is 1-easy to 10-hard */
1486 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1488 /* hack- empty square part of the time */
1489 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1491 /* if floor, shallow water and lava */
1492 if (is_floor_bold(y, x) ||
1493 (cave_have_flag_bold(y, x, FF_PLACE) && cave_have_flag_bold(y, x, FF_DROP)))
1495 /* The smaller 'value' is, the better the stuff */
1498 /* Meanest monster + treasure */
1499 monster_level = base_level + 40;
1500 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1501 monster_level = base_level;
1502 object_level = base_level + 20;
1503 place_object(y, x, AM_GOOD);
1504 object_level = base_level;
1508 /* Mean monster +treasure */
1509 monster_level = base_level + 20;
1510 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1511 monster_level = base_level;
1512 object_level = base_level + 10;
1513 place_object(y, x, AM_GOOD);
1514 object_level = base_level;
1516 else if (value < 10)
1519 monster_level = base_level + 9;
1520 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1521 monster_level = base_level;
1523 else if (value < 17)
1525 /* Intentional Blank space */
1528 * (Want some of the vault to be empty
1529 * so have room for group monsters.
1530 * This is used in the hack above to lower
1531 * the density of stuff in the vault.)
1534 else if (value < 23)
1536 /* Object or trap */
1537 if (randint0(100) < 25)
1539 place_object(y, x, 0L);
1546 else if (value < 30)
1548 /* Monster and trap */
1549 monster_level = base_level + 5;
1550 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1551 monster_level = base_level;
1554 else if (value < 40)
1556 /* Monster or object */
1557 if (randint0(100) < 50)
1559 monster_level = base_level + 3;
1560 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1561 monster_level = base_level;
1563 if (randint0(100) < 50)
1565 object_level = base_level + 7;
1566 place_object(y, x, 0L);
1567 object_level = base_level;
1570 else if (value < 50)
1579 /* 20% monster, 40% trap, 20% object, 20% blank space */
1580 if (randint0(100) < 20)
1582 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1584 else if (randint0(100) < 50)
1588 else if (randint0(100) < 50)
1590 place_object(y, x, 0L);
1602 * Overlay a rectangular room given its bounds
1603 * This routine is used by build_room_vault
1604 * The area inside the walls is not touched:
1605 * only granite is removed- normal walls stay
1607 void build_room(int x1, int x2, int y1, int y2)
1609 int x, y, i, xsize, ysize, temp;
1611 /* Check if rectangle has no width */
1612 if ((x1 == x2) || (y1 == y2)) return;
1617 /* Swap boundaries if in wrong order */
1625 /* Swap boundaries if in wrong order */
1631 /* get total widths */
1636 /* Top and bottom boundaries */
1637 for (i = 0; i <= xsize; i++)
1639 place_outer_noperm_bold(y1, x1 + i);
1640 cave[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1641 place_outer_noperm_bold(y2, x1 + i);
1642 cave[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1645 /* Left and right boundaries */
1646 for (i = 1; i < ysize; i++)
1648 place_outer_noperm_bold(y1 + i, x1);
1649 cave[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1650 place_outer_noperm_bold(y1 + i, x2);
1651 cave[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1655 for (x = 1; x < xsize; x++)
1657 for (y = 1; y < ysize; y++)
1659 if (is_extra_bold(y1+y, x1+x))
1661 /* clear the untouched region */
1662 place_floor_bold(y1 + y, x1 + x);
1663 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1667 /* make it a room- but don't touch */
1668 cave[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1677 * maze vault -- rectangular labyrinthine rooms
1679 * maze vault uses two routines:
1680 * r_visit - a recursive routine that builds the labyrinth
1681 * build_maze_vault - a driver routine that calls r_visit and adds
1682 * monsters, traps and treasure
1684 * The labyrinth is built by creating a spanning tree of a graph.
1685 * The graph vertices are at
1686 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1687 * and the edges are the vertical and horizontal nearest neighbors.
1689 * The spanning tree is created by performing a suitably randomized
1690 * depth-first traversal of the graph. The only adjustable parameter
1691 * is the randint0(3) below; it governs the relative density of
1692 * twists and turns in the labyrinth: smaller number, more twists.
1694 void r_visit(int y1, int x1, int y2, int x2, int node, int dir, int *visited)
1696 int i, j, m, n, temp, x, y, adj[4];
1698 /* dimensions of vertex array */
1699 m = (x2 - x1) / 2 + 1;
1700 n = (y2 - y1) / 2 + 1;
1702 /* mark node visited and set it to a floor */
1704 x = 2 * (node % m) + x1;
1705 y = 2 * (node / m) + y1;
1706 place_floor_bold(y, x);
1708 /* setup order of adjacent node visits */
1711 /* pick a random ordering */
1712 for (i = 0; i < 4; i++)
1714 for (i = 0; i < 4; i++)
1725 /* pick a random ordering with dir first */
1727 for (i = 1; i < 4; i++)
1729 for (i = 1; i < 4; i++)
1731 j = 1 + randint0(3);
1738 for (i = 0; i < 4; i++)
1743 /* (0,+) - check for bottom boundary */
1744 if ((node / m < n - 1) && (visited[node + m] == 0))
1746 place_floor_bold(y + 1, x);
1747 r_visit(y1, x1, y2, x2, node + m, dir, visited);
1751 /* (0,-) - check for top boundary */
1752 if ((node / m > 0) && (visited[node - m] == 0))
1754 place_floor_bold(y - 1, x);
1755 r_visit(y1, x1, y2, x2, node - m, dir, visited);
1759 /* (+,0) - check for right boundary */
1760 if ((node % m < m - 1) && (visited[node + 1] == 0))
1762 place_floor_bold(y, x + 1);
1763 r_visit(y1, x1, y2, x2, node + 1, dir, visited);
1767 /* (-,0) - check for left boundary */
1768 if ((node % m > 0) && (visited[node - 1] == 0))
1770 place_floor_bold(y, x - 1);
1771 r_visit(y1, x1, y2, x2, node - 1, dir, visited);
1778 void build_maze_vault(int x0, int y0, int xsize, int ysize, bool is_vault)
1782 int m, n, num_vertices, *visited;
1786 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1788 /* Choose lite or dark */
1789 light = ((dun_level <= randint1(25)) && is_vault && !(d_info[dungeon_type].flags1 & DF1_DARKNESS));
1791 /* Pick a random room size - randomized by calling routine */
1800 /* generate the room */
1801 for (y = y1 - 1; y <= y2 + 1; y++)
1803 for (x = x1 - 1; x <= x2 + 1; x++)
1805 c_ptr = &cave[y][x];
1806 c_ptr->info |= CAVE_ROOM;
1807 if (is_vault) c_ptr->info |= CAVE_ICKY;
1808 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1810 place_outer_grid(c_ptr);
1814 place_extra_grid(c_ptr);
1818 place_inner_grid(c_ptr);
1820 if (light) c_ptr->info |= (CAVE_GLOW);
1824 /* dimensions of vertex array */
1827 num_vertices = m * n;
1829 /* initialize array of visited vertices */
1830 C_MAKE(visited, num_vertices, int);
1832 /* traverse the graph to create a spaning tree, pick a random root */
1833 r_visit(y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1835 /* Fill with monsters and treasure, low difficulty */
1836 if (is_vault) fill_treasure(x1, x2, y1, y2, randint1(5));
1838 C_KILL(visited, num_vertices, int);
1842 /* Build a town/ castle by using a recursive algorithm.
1843 * Basically divide each region in a probalistic way to create
1844 * smaller regions. When the regions get too small stop.
1846 * The power variable is a measure of how well defended a region is.
1847 * This alters the possible choices.
1849 void build_recursive_room(int x1, int y1, int x2, int y2, int power)
1855 /* Temp variables */
1861 if ((power < 3) && (xsize > 12) && (ysize > 12))
1863 /* Need outside wall +keep */
1870 /* Make rooms + subdivide */
1871 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1877 choice = randint1(2) + 1;
1882 /* Mostly subdivide */
1883 choice = randint1(3) + 1;
1887 /* Based on the choice made above, do something */
1895 /* top and bottom */
1896 for (x = x1; x <= x2; x++)
1898 place_outer_bold(y1, x);
1899 place_outer_bold(y2, x);
1902 /* left and right */
1903 for (y = y1 + 1; y < y2; y++)
1905 place_outer_bold(y, x1);
1906 place_outer_bold(y, x2);
1909 /* Make a couple of entrances */
1912 /* left and right */
1913 y = randint1(ysize) + y1;
1914 place_floor_bold(y, x1);
1915 place_floor_bold(y, x2);
1919 /* top and bottom */
1920 x = randint1(xsize) + x1;
1921 place_floor_bold(y1, x);
1922 place_floor_bold(y2, x);
1925 /* Select size of keep */
1926 t1 = randint1(ysize / 3) + y1;
1927 t2 = y2 - randint1(ysize / 3);
1928 t3 = randint1(xsize / 3) + x1;
1929 t4 = x2 - randint1(xsize / 3);
1931 /* Do outside areas */
1933 /* Above and below keep */
1934 build_recursive_room(x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1935 build_recursive_room(x1 + 1, t2, x2 - 1, y2, power + 1);
1937 /* Left and right of keep */
1938 build_recursive_room(x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1939 build_recursive_room(t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1941 /* Make the keep itself: */
1954 /* Try to build a room */
1955 if ((xsize < 3) || (ysize < 3))
1957 for (y = y1; y < y2; y++)
1959 for (x = x1; x < x2; x++)
1961 place_inner_bold(y, x);
1969 /* Make outside walls */
1970 /* top and bottom */
1971 for (x = x1 + 1; x <= x2 - 1; x++)
1973 place_inner_bold(y1 + 1, x);
1974 place_inner_bold(y2 - 1, x);
1977 /* left and right */
1978 for (y = y1 + 1; y <= y2 - 1; y++)
1980 place_inner_bold(y, x1 + 1);
1981 place_inner_bold(y, x2 - 1);
1985 y = randint1(ysize - 3) + y1 + 1;
1990 place_floor_bold(y, x1 + 1);
1995 place_floor_bold(y, x2 - 1);
1998 /* Build the room */
1999 build_recursive_room(x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
2004 /* Try and divide vertically */
2008 for (y = y1; y < y2; y++)
2010 for (x = x1; x < x2; x++)
2012 place_inner_bold(y, x);
2018 t1 = randint1(xsize - 2) + x1 + 1;
2019 build_recursive_room(x1, y1, t1, y2, power - 2);
2020 build_recursive_room(t1 + 1, y1, x2, y2, power - 2);
2025 /* Try and divide horizontally */
2029 for (y = y1; y < y2; y++)
2031 for (x = x1; x < x2; x++)
2033 place_inner_bold(y, x);
2039 t1 = randint1(ysize - 2) + y1 + 1;
2040 build_recursive_room(x1, y1, x2, t1, power - 2);
2041 build_recursive_room(x1, t1 + 1, x2, y2, power - 2);
2049 * Add outer wall to a floored region
2050 * Note: no range checking is done so must be inside dungeon
2051 * This routine also stomps on doors
2053 void add_outer_wall(int x, int y, int light, int x1, int y1, int x2, int y2)
2056 feature_type *f_ptr;
2059 if (!in_bounds(y, x)) return;
2061 c_ptr = &cave[y][x];
2063 /* hack- check to see if square has been visited before
2064 * if so, then exit (use room flag to do this) */
2065 if (c_ptr->info & CAVE_ROOM) return;
2068 c_ptr->info |= CAVE_ROOM;
2070 f_ptr = &f_info[c_ptr->feat];
2072 if (is_floor_bold(y, x))
2074 for (i = -1; i <= 1; i++)
2076 for (j = -1; j <= 1; j++)
2078 if ((x + i >= x1) && (x + i <= x2) &&
2079 (y + j >= y1) && (y + j <= y2))
2081 add_outer_wall(x + i, y + j, light, x1, y1, x2, y2);
2082 if (light) c_ptr->info |= CAVE_GLOW;
2087 else if (is_extra_bold(y, x))
2089 /* Set bounding walls */
2090 place_outer_bold(y, x);
2091 if (light) c_ptr->info |= CAVE_GLOW;
2093 else if (permanent_wall(f_ptr))
2095 /* Set bounding walls */
2096 if (light) c_ptr->info |= CAVE_GLOW;
2102 * Hacked distance formula - gives the 'wrong' answer.
2103 * Used to build crypts
2105 int dist2(int x1, int y1, int x2, int y2, int h1, int h2, int h3, int h4)
2111 /* Basically this works by taking the normal pythagorean formula
2112 * and using an expansion to express this in a way without the
2113 * square root. This approximate formula is then perturbed to give
2114 * the distorted results. (I found this by making a mistake when I was
2115 * trying to fix the circular rooms.)
2118 /* h1-h4 are constants that describe the metric */
2119 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2120 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2121 return (((dx + dy) * 128) / 181 +
2122 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2123 /* 128/181 is approx. 1/sqrt(2) */
2129 /* Create a new floor room with optional light */
2130 void generate_room_floor(int y1, int x1, int y2, int x2, int light)
2136 for (y = y1; y <= y2; y++)
2138 for (x = x1; x <= x2; x++)
2141 c_ptr = &cave[y][x];
2142 place_floor_grid(c_ptr);
2143 c_ptr->info |= (CAVE_ROOM);
2144 if (light) c_ptr->info |= (CAVE_GLOW);
2149 void generate_fill_perm_bold(int y1, int x1, int y2, int x2)
2153 for (y = y1; y <= y2; y++)
2155 for (x = x1; x <= x2; x++)
2158 place_inner_perm_bold(y, x);
2165 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2167 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2168 * @return 部屋の精製に成功した場合 TRUE を返す。
2170 static bool room_build(int typ)
2175 /* Build an appropriate room */
2176 case ROOM_T_NORMAL: return build_type1();
2177 case ROOM_T_OVERLAP: return build_type2();
2178 case ROOM_T_CROSS: return build_type3();
2179 case ROOM_T_INNER_FEAT: return build_type4();
2180 case ROOM_T_NEST: return build_type5();
2181 case ROOM_T_PIT: return build_type6();
2182 case ROOM_T_LESSER_VAULT: return build_type7();
2183 case ROOM_T_GREATER_VAULT: return build_type8();
2184 case ROOM_T_FRACAVE: return build_type9();
2185 case ROOM_T_RANDOM_VAULT: return build_type10();
2186 case ROOM_T_OVAL: return build_type11();
2187 case ROOM_T_CRYPT: return build_type12();
2188 case ROOM_T_TRAP_PIT: return build_type13();
2189 case ROOM_T_TRAP: return build_type14();
2190 case ROOM_T_GLASS: return build_type15();
2191 case ROOM_T_ARCADE: return build_type16();
2199 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2200 * @param dst 確率を移す先の部屋種ID
2201 * @param src 確率を与える元の部屋種ID
2203 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2206 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2207 * @return 部屋生成に成功した場合 TRUE を返す。
2209 bool generate_rooms(void)
2215 int prob_list[ROOM_T_MAX];
2216 int rooms_built = 0;
2217 int area_size = 100 * (cur_hgt*cur_wid) / (MAX_HGT*MAX_WID);
2218 int level_index = MIN(10, div_round(dun_level, 10));
2220 /* Number of each type of room on this level */
2221 s16b room_num[ROOM_T_MAX];
2223 /* Limit number of rooms */
2224 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2226 /* Assume normal cave */
2227 room_info_type *room_info_ptr = room_info_normal;
2230 * Initialize probability list.
2232 for (i = 0; i < ROOM_T_MAX; i++)
2234 /* No rooms allowed above their minimum depth. */
2235 if (dun_level < room_info_ptr[i].min_level)
2241 prob_list[i] = room_info_ptr[i].prob[level_index];
2246 * XXX -- Various dungeon types and options.
2249 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、かつ「常に通常でない部屋を生成する」フラグがONならば、GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2250 if (ironman_rooms && !((d_info[dungeon_type].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2252 for (i = 0; i < ROOM_T_MAX; i++)
2254 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2255 else prob_list[i] = 0;
2259 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2260 else if (d_info[dungeon_type].flags1 & DF1_NO_VAULT)
2262 prob_list[ROOM_T_LESSER_VAULT] = 0;
2263 prob_list[ROOM_T_GREATER_VAULT] = 0;
2264 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2267 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2268 if (d_info[dungeon_type].flags1 & DF1_NO_CAVE)
2270 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2271 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2272 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2275 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc cave etc.) */
2276 else if (d_info[dungeon_type].flags1 & DF1_CAVE)
2278 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2281 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2282 else if (dun->cavern || dun->empty_level)
2284 prob_list[ROOM_T_FRACAVE] = 0;
2287 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2288 if (!(d_info[dungeon_type].flags1 & DF1_GLASS_ROOM))
2290 prob_list[ROOM_T_GLASS] = 0;
2293 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2294 if (!(d_info[dungeon_type].flags1 & DF1_ARCADE))
2296 prob_list[ROOM_T_ARCADE] = 0;
2300 * Initialize number of rooms,
2301 * And calcurate total probability.
2303 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2306 total_prob += prob_list[i];
2310 * Prepare the number of rooms, of all types, we should build
2313 for (i = dun_rooms; i > 0; i--)
2316 int rand = randint0(total_prob);
2318 /* Get room_type randomly */
2319 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2321 if (rand < prob_list[room_type]) break;
2322 else rand -= prob_list[room_type];
2326 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2328 /* Increase the number of rooms of that type we should build. */
2329 room_num[room_type]++;
2335 case ROOM_T_LESSER_VAULT:
2336 case ROOM_T_TRAP_PIT:
2344 case ROOM_T_GREATER_VAULT:
2345 case ROOM_T_RANDOM_VAULT:
2354 * Build each type of room one by one until we cannot build any more.
2355 * [from SAngband (originally from OAngband)]
2359 /* Assume no remaining rooms */
2362 for (i = 0; i < ROOM_T_MAX; i++)
2364 /* What type of room are we building now? */
2365 int room_type = room_build_order[i];
2367 /* Go next if none available */
2368 if (!room_num[room_type]) continue;
2370 /* Use up one unit */
2371 room_num[room_type]--;
2373 /* Build the room. */
2374 if (room_build(room_type))
2376 /* Increase the room built count. */
2379 /* Mark as there was some remaining rooms */
2386 case ROOM_T_TRAP_PIT:
2388 /* Avoid too many monsters */
2391 room_num[ROOM_T_PIT] = 0;
2392 room_num[ROOM_T_NEST] = 0;
2393 room_num[ROOM_T_TRAP_PIT] = 0;
2399 /* Avoid double-town */
2400 room_num[ROOM_T_ARCADE] = 0;
2406 /* End loop if no room remain */
2410 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2411 if (rooms_built < 2)
2413 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2417 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);