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 "floor-generate.h"
49 #include "rooms-city.h"
50 #include "rooms-fractal.h"
51 #include "rooms-normal.h"
52 #include "rooms-pitnest.h"
53 #include "rooms-special.h"
54 #include "rooms-trap.h"
55 #include "rooms-vault.h"
64 *[from SAngband (originally from OAngband)]\n
66 * Table of values that control how many times each type of room will\n
67 * appear. Each type of room has its own row, and each column\n
68 * corresponds to dungeon levels 0, 10, 20, and so on. The final\n
69 * value is the minimum depth the room can appear at. -LM-\n
71 * Level 101 and below use the values for level 100.\n
73 * Rooms with lots of monsters or loot may not be generated if the\n
74 * object or monster lists are already nearly full. Rooms will not\n
75 * appear above their minimum depth. Tiny levels will not have space\n
76 * for all the rooms you ask for.\n
81 static room_info_type room_info_normal[ROOM_T_MAX] =
84 /* 0 10 20 30 40 50 60 70 80 90 100 min limit */
85 {{999,900,800,700,600,500,400,300,200,100, 0}, 0}, /*NORMAL */
86 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 1}, /*OVERLAP */
87 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*CROSS */
88 {{ 1, 10, 20, 30, 40, 50, 60, 70, 80, 90,100}, 3}, /*INNER_F */
89 {{ 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 13}, 10}, /*NEST */
90 {{ 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 16}, 10}, /*PIT */
91 {{ 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 10}, 10}, /*LESSER_V */
92 {{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4}, 20}, /*GREATER_V*/
93 {{ 0,100,200,300,400,500,600,700,800,900,999}, 10}, /*FRACAVE */
94 {{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2}, 10}, /*RANDOM_V */
95 {{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40}, 3}, /*OVAL */
96 {{ 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60}, 10}, /*CRYPT */
97 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP_PIT */
98 {{ 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 8}, 20}, /*TRAP */
99 {{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2}, 40}, /*GLASS */
100 {{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3}, 1}, /*ARCADE */
101 {{ 1, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80}, 1}, /*FIX */
107 static room_info_type room_info_normal[ROOM_T_MAX] =
110 { {999, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0}, 0}, /*NORMAL */
111 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 1 }, /*OVERLAP */
112 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*CROSS */
113 { { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0}, 3 }, /*INNER_F */
114 { { 0, 1, 1, 1, 2, 3, 5, 6, 8, 10, 0}, 10 }, /*NEST */
115 { { 0, 1, 1, 2, 3, 4, 6, 8, 10, 13, 0}, 10 }, /*PIT */
116 { { 0, 1, 1, 1, 2, 2, 3, 5, 6, 8, 0}, 10 }, /*LESSER_V */
117 { { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 0}, 20 }, /*GREATER_V*/
118 { { 0,100,200,300,400,500,600,700,800,900, 0}, 10 }, /*FRACAVE */
119 { { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0}, 10 }, /*RANDOM_V */
120 { { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 0}, 3 }, /*OVAL */
121 { { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 0}, 10 }, /*CRYPT */
122 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP_PIT */
123 { { 0, 0, 1, 1, 1, 2, 3, 4, 5, 6, 0}, 20 }, /*TRAP */
124 { { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 0}, 40 }, /*GLASS */
125 { { 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 0}, 1 }, /*ARCADE */
126 { { 20, 40, 60, 80,100,100,100,100,100,100,100}, 1 }, /*FIX */
133 /*! 部屋の生成処理順 / Build rooms in descending order of difficulty. */
134 static byte room_build_order[ROOM_T_MAX] = {
135 ROOM_T_GREATER_VAULT,
155 * @brief 1マスだけの部屋を作成し、上下左右いずれか一つに隠しドアを配置する。
156 * @param floor_ptr 配置するフロアの参照ポインタ
157 * @param y0 配置したい中心のY座標
158 * @param x0 配置したい中心のX座標
160 * This funtion makes a very small room centred at (x0, y0)
161 * This is used in crypts, and random elemental vaults.
163 * Note - this should be used only on allocated regions
164 * within another room.
166 void build_small_room(floor_type *floor_ptr, POSITION x0, POSITION y0)
170 for (y = y0 - 1; y <= y0 + 1; y++)
172 place_inner_bold(floor_ptr, y, x0 - 1);
173 place_inner_bold(floor_ptr, y, x0 + 1);
176 for (x = x0 - 1; x <= x0 + 1; x++)
178 place_inner_bold(floor_ptr, y0 - 1, x);
179 place_inner_bold(floor_ptr, y0 + 1, x);
182 /* Place a secret door on one side */
185 case 0: place_secret_door(floor_ptr, y0, x0 - 1, DOOR_DEFAULT); break;
186 case 1: place_secret_door(floor_ptr, y0, x0 + 1, DOOR_DEFAULT); break;
187 case 2: place_secret_door(floor_ptr, y0 - 1, x0, DOOR_DEFAULT); break;
188 case 3: place_secret_door(floor_ptr, y0 + 1, x0, DOOR_DEFAULT); break;
191 /* Clear mimic type */
192 floor_ptr->grid_array[y0][x0].mimic = 0;
194 /* Add inner open space */
195 place_floor_bold(floor_ptr, y0, x0);
200 * 指定範囲に通路が通っていることを確認した上で床で埋める
201 * This function tunnels around a room if it will cut off part of a grid system.
208 static void check_room_boundary(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
212 bool old_is_floor, new_is_floor;
215 old_is_floor = get_is_floor(floor_ptr, x1 - 1, y1);
218 * Count the number of floor-wall boundaries around the room
219 * Note: diagonal squares are ignored since the player can move diagonally
220 * to bypass these if needed.
223 /* Above the top boundary */
224 for (x = x1; x <= x2; x++)
226 new_is_floor = get_is_floor(floor_ptr, x, y1 - 1);
228 /* Increment counter if they are different */
229 if (new_is_floor != old_is_floor) count++;
231 old_is_floor = new_is_floor;
235 for (y = y1; y <= y2; y++)
237 new_is_floor = get_is_floor(floor_ptr, x2 + 1, y);
239 /* increment counter if they are different */
240 if (new_is_floor != old_is_floor) count++;
242 old_is_floor = new_is_floor;
245 /* Bottom boundary */
246 for (x = x2; x >= x1; x--)
248 new_is_floor = get_is_floor(floor_ptr, x, y2 + 1);
250 /* increment counter if they are different */
251 if (new_is_floor != old_is_floor) count++;
253 old_is_floor = new_is_floor;
257 for (y = y2; y >= y1; y--)
259 new_is_floor = get_is_floor(floor_ptr, x1 - 1, y);
261 /* increment counter if they are different */
262 if (new_is_floor != old_is_floor) count++;
264 old_is_floor = new_is_floor;
267 /* If all the same, or only one connection exit. */
268 if (count <= 2) return;
271 /* Tunnel around the room so to prevent problems with caves */
272 for (y = y1; y <= y2; y++)
274 for (x = x1; x <= x2; x++)
276 set_floor(floor_ptr, x, y);
284 * find_space()の予備処理として部屋の生成が可能かを判定する /
285 * Helper function for find_space(). Is this a good location?
286 * @param blocks_high 範囲の高さ
287 * @param blocks_wide 範囲の幅
288 * @param block_y 範囲の上端
289 * @param block_x 範囲の左端
292 static bool find_space_aux(POSITION blocks_high, POSITION blocks_wide, POSITION block_y, POSITION block_x)
294 POSITION by1, bx1, by2, bx2, by, bx;
296 /* Itty-bitty rooms must shift about within their rectangle */
299 if ((blocks_wide == 2) && (block_x % 3) == 2)
303 /* Rooms with width divisible by 3 must be fitted to a rectangle. */
304 else if ((blocks_wide % 3) == 0)
306 /* Must be aligned to the left edge of a 11x33 rectangle. */
307 if ((block_x % 3) != 0)
312 * Big rooms that do not have a width divisible by 3 must be
313 * aligned towards the edge of the dungeon closest to them.
317 /* Shift towards left edge of dungeon. */
318 if (block_x + (blocks_wide / 2) <= dun->col_rooms / 2)
320 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
322 if ((block_x % 3) == 1)
326 /* Shift toward right edge of dungeon. */
329 if (((block_x % 3) == 2) && ((blocks_wide % 3) == 2))
331 if ((block_x % 3) == 1)
339 by2 = block_y + blocks_high;
340 bx2 = block_x + blocks_wide;
342 /* Never run off the screen */
343 if ((by1 < 0) || (by2 > dun->row_rooms)) return FALSE;
344 if ((bx1 < 0) || (bx2 > dun->col_rooms)) return FALSE;
346 /* Verify available space */
347 for (by = by1; by < by2; by++)
349 for (bx = bx1; bx < bx2; bx++)
351 if (dun->room_map[by][bx])
358 /* This location is okay */
364 * @brief 部屋生成が可能なスペースを確保する / Find a good spot for the next room. -LM-
365 * @param y 部屋の生成が可能な中心Y座標を返す参照ポインタ
366 * @param x 部屋の生成が可能な中心X座標を返す参照ポインタ
367 * @param height 確保したい領域の高さ
368 * @param width 確保したい領域の幅
369 * @return 所定の範囲が確保できた場合TRUEを返す
371 * Find and allocate a free space in the dungeon large enough to hold\n
372 * the room calling this function.\n
374 * We allocate space in 11x11 blocks, but want to make sure that rooms\n
375 * align neatly on the standard screen. Therefore, we make them use\n
376 * blocks in few 11x33 rectangles as possible.\n
378 * Be careful to include the edges of the room in height and width!\n
380 * Return TRUE and values for the center of the room if all went well.\n
381 * Otherwise, return FALSE.\n
383 bool find_space(floor_type *floor_ptr, POSITION *y, POSITION *x, POSITION height, POSITION width)
385 int candidates, pick;
386 POSITION by, bx, by1, bx1, by2, bx2;
387 POSITION block_y = 0, block_x = 0;
389 /* Find out how many blocks we need. */
390 POSITION blocks_high = 1 + ((height - 1) / BLOCK_HGT);
391 POSITION blocks_wide = 1 + ((width - 1) / BLOCK_WID);
393 /* There are no way to allocate such huge space */
394 if (dun->row_rooms < blocks_high) return FALSE;
395 if (dun->col_rooms < blocks_wide) return FALSE;
400 /* Count the number of valid places */
401 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
403 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
405 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
407 /* Find a valid place */
420 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE))
422 /* Choose a random one */
423 pick = randint1(candidates);
426 /* NO_CAVE dungeon (Castle) */
429 /* Always choose the center one */
430 pick = candidates/2 + 1;
433 /* Pick up the choosen location */
434 for (block_y = dun->row_rooms - blocks_high; block_y >= 0; block_y--)
436 for (block_x = dun->col_rooms - blocks_wide; block_x >= 0; block_x--)
438 if (find_space_aux(blocks_high, blocks_wide, block_y, block_x))
442 /* This one is picked? */
453 by2 = block_y + blocks_high;
454 bx2 = block_x + blocks_wide;
457 * It is *extremely* important that the following calculation
458 * be *exactly* correct to prevent memory errors
461 /* Acquire the location of the room */
462 (*y) = ((by1 + by2) * BLOCK_HGT) / 2;
463 (*x) = ((bx1 + bx2) * BLOCK_WID) / 2;
465 /* Save the room location */
466 if (dun->cent_n < CENT_MAX)
468 dun->cent[dun->cent_n].y = (byte_hack)*y;
469 dun->cent[dun->cent_n].x = (byte_hack)*x;
473 /* Reserve some blocks. */
474 for (by = by1; by < by2; by++)
476 for (bx = bx1; bx < bx2; bx++)
478 dun->room_map[by][bx] = TRUE;
483 * Hack- See if room will cut off a cavern.
485 * If so, fix by tunneling outside the room in such a
486 * way as to connect the caves.
488 check_room_boundary(floor_ptr, *x - width / 2 - 1, *y - height / 2 - 1, *x + (width - 1) / 2 + 1, *y + (height - 1) / 2 + 1);
496 * Structure to hold all "fill" data
499 typedef struct fill_data_type fill_data_type;
501 struct fill_data_type
514 /* features to fill with */
523 /* number of filled squares */
527 static fill_data_type fill_data;
530 /* Store routine for the fractal floor generator */
531 /* this routine probably should be an inline function or a macro. */
532 static void store_height(floor_type *floor_ptr, POSITION x, POSITION y, FEAT_IDX val)
534 /* if on boundary set val > cutoff so walls are not as square */
535 if (((x == fill_data.xmin) || (y == fill_data.ymin) ||
536 (x == fill_data.xmax) || (y == fill_data.ymax)) &&
537 (val <= fill_data.c1)) val = fill_data.c1 + 1;
539 /* store the value in height-map format */
540 floor_ptr->grid_array[y][x].feat = val;
547 * Explanation of the plasma fractal algorithm:
549 * A grid of points is created with the properties of a 'height-map'
550 * This is done by making the corners of the grid have a random value.
551 * The grid is then subdivided into one with twice the resolution.
552 * The new points midway between two 'known' points can be calculated
553 * by taking the average value of the 'known' ones and randomly adding
554 * or subtracting an amount proportional to the distance between those
555 * points. The final 'middle' points of the grid are then calculated
556 * by averaging all four of the originally 'known' corner points. An
557 * random amount is added or subtracted from this to get a value of the
558 * height at that point. The scaling factor here is adjusted to the
559 * slightly larger distance diagonally as compared to orthogonally.
561 * This is then repeated recursively to fill an entire 'height-map'
562 * A rectangular map is done the same way, except there are different
563 * scaling factors along the x and y directions.
565 * A hack to change the amount of correlation between points is done using
566 * the grd variable. If the current step size is greater than grd then
567 * the point will be random, otherwise it will be calculated by the
568 * above algorithm. This makes a maximum distance at which two points on
569 * the height map can affect each other.
571 * How fractal caves are made:
573 * When the map is complete, a cut-off value is used to create a floor.
574 * Heights below this value are "floor", and heights above are "wall".
575 * This also can be used to create lakes, by adding more height levels
576 * representing shallow and deep water/ lava etc.
578 * The grd variable affects the width of passages.
579 * The roug variable affects the roughness of those passages
581 * The tricky part is making sure the created floor is connected. This
582 * is done by 'filling' from the inside and only keeping the 'filled'
583 * floor. Walls bounding the 'filled' floor are also kept. Everything
584 * else is converted to the normal _extra_.
589 * Note that this uses the floor array in a very hackish way
590 * the values are first set to zero, and then each array location
591 * is used as a "heightmap"
592 * The heightmap then needs to be converted back into the "feat" format.
594 * grd=level at which fractal turns on. smaller gives more mazelike caves
595 * roug=roughness level. 16=normal. higher values make things more convoluted
596 * small values are good for smooth walls.
597 * size=length of the side of the square grid system.
599 void generate_hmap(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsiz, POSITION ysiz, int grd, int roug, int cutoff)
601 POSITION xhsize, yhsize, xsize, ysize, maxsize;
604 * fixed point variables- these are stored as 256 x normal value
605 * this gives 8 binary places of fractional part + 8 places of normal part
608 POSITION xstep, xhstep, ystep, yhstep;
609 POSITION xstep2, xhstep2, ystep2, yhstep2;
610 POSITION i, j, ii, jj, diagsize, xxsize, yysize;
612 /* Cache for speed */
613 POSITION xm, xp, ym, yp;
615 /* redefine size so can change the value if out of range */
619 /* Paranoia about size of the system of caves */
620 if (xsize > 254) xsize = 254;
621 if (xsize < 4) xsize = 4;
622 if (ysize > 254) ysize = 254;
623 if (ysize < 4) ysize = 4;
625 /* get offsets to middle of array */
629 /* fix rounding problem */
633 /* get limits of region */
634 fill_data.xmin = x0 - xhsize;
635 fill_data.ymin = y0 - yhsize;
636 fill_data.xmax = x0 + xhsize;
637 fill_data.ymax = y0 + yhsize;
639 /* Store cutoff in global for quick access */
640 fill_data.c1 = cutoff;
643 * Scale factor for middle points:
644 * About sqrt(2) * 256 - correct for a square lattice
645 * approximately correct for everything else.
649 /* maximum of xsize and ysize */
650 maxsize = (xsize > ysize) ? xsize : ysize;
652 /* Clear the section */
653 for (i = 0; i <= xsize; i++)
655 for (j = 0; j <= ysize; j++)
657 /* -1 is a flag for "not done yet" */
658 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].feat = -1;
659 /* Clear icky flag because may be redoing the floor_ptr->grid_array */
660 floor_ptr->grid_array[(int)(fill_data.ymin + j)][(int)(fill_data.xmin + i)].info &= ~(CAVE_ICKY);
664 /* Boundaries are walls */
665 floor_ptr->grid_array[fill_data.ymin][fill_data.xmin].feat = (s16b)maxsize;
666 floor_ptr->grid_array[fill_data.ymax][fill_data.xmin].feat = (s16b)maxsize;
667 floor_ptr->grid_array[fill_data.ymin][fill_data.xmax].feat = (s16b)maxsize;
668 floor_ptr->grid_array[fill_data.ymax][fill_data.xmax].feat = (s16b)maxsize;
670 /* Set the middle square to be an open area. */
671 floor_ptr->grid_array[y0][x0].feat = 0;
673 /* Initialize the step sizes */
674 xstep = xhstep = xsize * 256;
675 ystep = yhstep = ysize * 256;
676 xxsize = xsize * 256;
677 yysize = ysize * 256;
680 * Fill in the rectangle with fractal height data -
681 * like the 'plasma fractal' in fractint.
683 while ((xhstep > 256) || (yhstep > 256))
685 /* Halve the step sizes */
691 /* cache well used values */
692 xstep2 = xstep / 256;
693 ystep2 = ystep / 256;
695 xhstep2 = xhstep / 256;
696 yhstep2 = yhstep / 256;
698 /* middle top to bottom. */
699 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
701 for (j = 0; j <= yysize; j += ystep)
703 /* cache often used values */
704 ii = i / 256 + fill_data.xmin;
705 jj = j / 256 + fill_data.ymin;
708 if (floor_ptr->grid_array[jj][ii].feat == -1)
712 /* If greater than 'grid' level then is random */
713 store_height(floor_ptr, ii, jj, randint1(maxsize));
717 /* Average of left and right points +random bit */
718 store_height(floor_ptr, ii, jj,
719 (floor_ptr->grid_array[jj][fill_data.xmin + (i - xhstep) / 256].feat
720 + floor_ptr->grid_array[jj][fill_data.xmin + (i + xhstep) / 256].feat) / 2
721 + (randint1(xstep2) - xhstep2) * roug / 16);
728 /* middle left to right. */
729 for (j = yhstep; j <= yysize - yhstep; j += ystep)
731 for (i = 0; i <= xxsize; i += xstep)
733 /* cache often used values */
734 ii = i / 256 + fill_data.xmin;
735 jj = j / 256 + fill_data.ymin;
738 if (floor_ptr->grid_array[jj][ii].feat == -1)
742 /* If greater than 'grid' level then is random */
743 store_height(floor_ptr, ii, jj, randint1(maxsize));
747 /* Average of up and down points +random bit */
748 store_height(floor_ptr, ii, jj,
749 (floor_ptr->grid_array[fill_data.ymin + (j - yhstep) / 256][ii].feat
750 + floor_ptr->grid_array[fill_data.ymin + (j + yhstep) / 256][ii].feat) / 2
751 + (randint1(ystep2) - yhstep2) * roug / 16);
758 for (i = xhstep; i <= xxsize - xhstep; i += xstep)
760 for (j = yhstep; j <= yysize - yhstep; j += ystep)
762 /* cache often used values */
763 ii = i / 256 + fill_data.xmin;
764 jj = j / 256 + fill_data.ymin;
767 if (floor_ptr->grid_array[jj][ii].feat == -1)
771 /* If greater than 'grid' level then is random */
772 store_height(floor_ptr, ii, jj, randint1(maxsize));
776 /* Cache reused values. */
777 xm = fill_data.xmin + (i - xhstep) / 256;
778 xp = fill_data.xmin + (i + xhstep) / 256;
779 ym = fill_data.ymin + (j - yhstep) / 256;
780 yp = fill_data.ymin + (j + yhstep) / 256;
783 * Average over all four corners + scale by diagsize to
784 * reduce the effect of the square grid on the shape of the fractal
786 store_height(floor_ptr, ii, jj,
787 (floor_ptr->grid_array[ym][xm].feat + floor_ptr->grid_array[yp][xm].feat
788 + floor_ptr->grid_array[ym][xp].feat + floor_ptr->grid_array[yp][xp].feat) / 4
789 + (randint1(xstep2) - xhstep2) * (diagsize / 16) / 256 * roug);
798 static bool hack_isnt_wall(floor_type *floor_ptr, POSITION y, POSITION x, int c1, int c2, int c3, FEAT_IDX feat1, FEAT_IDX feat2, FEAT_IDX feat3, BIT_FLAGS info1, BIT_FLAGS info2, BIT_FLAGS info3)
801 * function used to convert from height-map back to the
802 * normal angband floor_ptr->grid_array format
804 if (floor_ptr->grid_array[y][x].info & CAVE_ICKY)
811 /* Show that have looked at this square */
812 floor_ptr->grid_array[y][x].info|= (CAVE_ICKY);
814 /* Use cutoffs c1-c3 to allocate regions of floor /water/ lava etc. */
815 if (floor_ptr->grid_array[y][x].feat <= c1)
817 /* 25% of the time use the other tile : it looks better this way */
818 if (randint1(100) < 75)
820 floor_ptr->grid_array[y][x].feat = feat1;
821 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
822 floor_ptr->grid_array[y][x].info |= info1;
827 floor_ptr->grid_array[y][x].feat = feat2;
828 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
829 floor_ptr->grid_array[y][x].info |= info2;
833 else if (floor_ptr->grid_array[y][x].feat <= c2)
835 /* 25% of the time use the other tile : it looks better this way */
836 if (randint1(100) < 75)
838 floor_ptr->grid_array[y][x].feat = feat2;
839 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
840 floor_ptr->grid_array[y][x].info |= info2;
845 floor_ptr->grid_array[y][x].feat = feat1;
846 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
847 floor_ptr->grid_array[y][x].info |= info1;
851 else if (floor_ptr->grid_array[y][x].feat <= c3)
853 floor_ptr->grid_array[y][x].feat = feat3;
854 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
855 floor_ptr->grid_array[y][x].info |= info3;
858 /* if greater than cutoff then is a wall */
861 place_outer_bold(floor_ptr, y, x);
871 * Quick and nasty fill routine used to find the connected region
872 * of floor in the middle of the grids
874 static void cave_fill(floor_type *floor_ptr, POSITION y, POSITION x)
885 /* Enqueue that entry */
889 /* Now process the queue */
890 while (flow_head != flow_tail)
892 /* Extract the next entry */
893 ty = tmp_pos.y[flow_head];
894 tx = tmp_pos.x[flow_head];
896 /* Forget that entry */
897 if (++flow_head == TEMP_MAX) flow_head = 0;
899 /* Add the "children" */
900 for (d = 0; d < 8; d++)
902 int old_head = flow_tail;
908 /* Paranoia Don't leave the floor_ptr->grid_array */
909 if (!in_bounds(floor_ptr, j, i))
911 /* affect boundary */
912 floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
916 /* If within bounds */
917 else if ((i > fill_data.xmin) && (i < fill_data.xmax)
918 && (j > fill_data.ymin) && (j < fill_data.ymax))
920 /* If not a wall or floor done before */
921 if (hack_isnt_wall(floor_ptr, j, i,
922 fill_data.c1, fill_data.c2, fill_data.c3,
923 fill_data.feat1, fill_data.feat2, fill_data.feat3,
924 fill_data.info1, fill_data.info2, fill_data.info3))
926 /* Enqueue that entry */
927 tmp_pos.y[flow_tail] = (byte_hack)j;
928 tmp_pos.x[flow_tail] = (byte_hack)i;
930 /* Advance the queue */
931 if (++flow_tail == TEMP_MAX) flow_tail = 0;
933 /* Hack -- Overflow by forgetting new entry */
934 if (flow_tail == flow_head)
936 flow_tail = old_head;
940 /* keep tally of size of floor_ptr->grid_array system */
941 (fill_data.amount)++;
947 /* affect boundary */
948 floor_ptr->grid_array[j][i].info |= CAVE_ICKY;
955 bool generate_fracave(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int cutoff, bool light, bool room)
957 POSITION x, y, xhsize, yhsize;
960 /* offsets to middle from corner */
966 * select region connected to center of floor_ptr->grid_array system
967 * this gets rid of alot of isolated one-sqaures that
968 * can make teleport traps instadeaths...
972 fill_data.c1 = cutoff;
976 /* features to fill with */
977 fill_data.feat1 = feat_ground_type[randint0(100)];
978 fill_data.feat2 = feat_ground_type[randint0(100)];
979 fill_data.feat3 = feat_ground_type[randint0(100)];
981 fill_data.info1 = CAVE_FLOOR;
982 fill_data.info2 = CAVE_FLOOR;
983 fill_data.info3 = CAVE_FLOOR;
985 /* number of filled squares */
986 fill_data.amount = 0;
988 cave_fill(floor_ptr, (byte)y0, (byte)x0);
990 /* if tally too small, try again */
991 if (fill_data.amount < 10)
993 /* too small - clear area and try again later */
994 for (x = 0; x <= xsize; ++x)
996 for (y = 0; y <= ysize; ++y)
998 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
999 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1006 * Do boundarys-check to see if they are next to a filled region
1007 * If not then they are set to normal granite
1008 * If so then they are marked as room walls.
1010 for (i = 0; i <= xsize; ++i)
1013 if ((floor_ptr->grid_array[0 + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1015 /* Next to a 'filled' region? - set to be room walls */
1016 place_outer_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
1017 if (light) floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_GLOW);
1018 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info |= (CAVE_ROOM);
1019 place_outer_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
1023 /* set to be normal granite */
1024 place_extra_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
1027 /* bottom boundary */
1028 if ((floor_ptr->grid_array[ysize + y0 - yhsize][i + x0 - xhsize].info & CAVE_ICKY) && (room))
1030 /* Next to a 'filled' region? - set to be room walls */
1031 place_outer_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1032 if (light) floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_GLOW);
1033 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info|=(CAVE_ROOM);
1034 place_outer_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1038 /* set to be normal granite */
1039 place_extra_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1042 /* clear the icky flag-don't need it any more */
1043 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1044 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1047 /* Do the left and right boundaries minus the corners (done above) */
1048 for (i = 1; i < ysize; ++i)
1051 if ((floor_ptr->grid_array[i + y0 - yhsize][0 + x0 - xhsize].info & CAVE_ICKY) && room)
1054 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1055 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_GLOW);
1056 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info |= (CAVE_ROOM);
1057 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1062 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1064 /* right boundary */
1065 if ((floor_ptr->grid_array[i + y0 - yhsize][xsize + x0 - xhsize].info & CAVE_ICKY) && room)
1068 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1069 if (light) floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_GLOW);
1070 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info |= (CAVE_ROOM);
1071 place_outer_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1076 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1079 /* clear icky flag -done with it */
1080 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1081 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1085 /* Do the rest: convert back to the normal format */
1086 for (x = 1; x < xsize; ++x)
1088 for (y = 1; y < ysize; ++y)
1090 if (is_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1091 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1093 /* Clear the icky flag in the filled region */
1094 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~CAVE_ICKY;
1096 /* Set appropriate flags */
1097 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1098 if (room) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1100 else if (is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize) &&
1101 (floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY))
1104 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1105 if (light) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_GLOW);
1108 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= (CAVE_ROOM);
1113 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1114 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ROOM);
1119 /* Clear the unconnected regions */
1120 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1121 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1127 * There is a slight problem when tunnels pierce the caves:
1128 * Extra doors appear inside the system. (Its not very noticeable though.)
1129 * This can be removed by "filling" from the outside in. This allows a separation
1130 * from _outer_ with _inner_. (Internal walls are _outer_ instead.)
1131 * The extra effort for what seems to be only a minor thing (even non-existant if you
1132 * think of the caves not as normal rooms, but as holes in the dungeon), doesn't seem
1140 #ifdef ALLOW_CAVERNS_AND_LAKES
1142 * Builds a cave system in the center of the dungeon.
1144 void build_cavern(floor_type *floor_ptr)
1146 int grd, roug, cutoff;
1147 POSITION xsize, ysize, x0, y0;
1150 light = done = FALSE;
1151 if ((floor_ptr->dun_level <= randint1(50)) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) light = TRUE;
1153 /* Make a cave the size of the dungeon */
1154 xsize = floor_ptr->width - 1;
1155 ysize = floor_ptr->height - 1;
1159 /* Paranoia: make size even */
1165 /* testing values for these parameters: feel free to adjust */
1166 grd = randint1(4) + 4;
1168 /* want average of about 16 */
1169 roug = randint1(8) * randint1(4);
1175 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, cutoff);
1177 /* Convert to normal format+ clean up */
1178 done = generate_fracave(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, cutoff, light, FALSE);
1182 bool generate_lake(floor_type *floor_ptr, POSITION y0, POSITION x0, POSITION xsize, POSITION ysize, int c1, int c2, int c3, int type)
1184 POSITION x, y, xhsize, yhsize;
1186 FEAT_IDX feat1, feat2, feat3;
1188 /* offsets to middle from corner */
1192 /* Get features based on type */
1195 case LAKE_T_LAVA: /* Lava */
1196 feat1 = feat_deep_lava;
1197 feat2 = feat_shallow_lava;
1198 feat3 = feat_ground_type[randint0(100)];
1200 case LAKE_T_WATER: /* Water */
1201 feat1 = feat_deep_water;
1202 feat2 = feat_shallow_water;
1203 feat3 = feat_ground_type[randint0(100)];
1205 case LAKE_T_CAVE: /* Collapsed floor_ptr->grid_array */
1206 feat1 = feat_ground_type[randint0(100)];
1207 feat2 = feat_ground_type[randint0(100)];
1208 feat3 = feat_rubble;
1210 case LAKE_T_EARTH_VAULT: /* Earth vault */
1211 feat1 = feat_rubble;
1212 feat2 = feat_ground_type[randint0(100)];
1213 feat3 = feat_rubble;
1215 case LAKE_T_AIR_VAULT: /* Air vault */
1220 case LAKE_T_WATER_VAULT: /* Water vault */
1221 feat1 = feat_shallow_water;
1222 feat2 = feat_deep_water;
1223 feat3 = feat_shallow_water;
1225 case LAKE_T_FIRE_VAULT: /* Fire Vault */
1226 feat1 = feat_shallow_lava;
1227 feat2 = feat_deep_lava;
1228 feat3 = feat_shallow_lava;
1230 default: return FALSE;
1234 * select region connected to center of floor_ptr->grid_array system
1235 * this gets rid of alot of isolated one-sqaures that
1236 * can make teleport traps instadeaths...
1244 /* features to fill with */
1245 fill_data.feat1 = feat1;
1246 fill_data.feat2 = feat2;
1247 fill_data.feat3 = feat3;
1249 fill_data.info1 = 0;
1250 fill_data.info2 = 0;
1251 fill_data.info3 = 0;
1253 /* number of filled squares */
1254 fill_data.amount = 0;
1256 /* select region connected to center of floor_ptr->grid_array system
1257 * this gets rid of alot of isolated one-sqaures that
1258 * can make teleport traps instadeaths... */
1259 cave_fill(floor_ptr, (byte)y0, (byte)x0);
1261 /* if tally too small, try again */
1262 if (fill_data.amount < 10)
1264 /* too small -clear area and try again later */
1265 for (x = 0; x <= xsize; ++x)
1267 for (y = 0; y <= ysize; ++y)
1269 place_floor_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1270 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY);
1276 /* Do boundarys- set to normal granite */
1277 for (i = 0; i <= xsize; ++i)
1279 place_extra_bold(floor_ptr, y0 + 0 - yhsize, x0 + i - xhsize);
1280 place_extra_bold(floor_ptr, y0 + ysize - yhsize, x0 + i - xhsize);
1282 /* clear the icky flag-don't need it any more */
1283 floor_ptr->grid_array[y0 + 0 - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1284 floor_ptr->grid_array[y0 + ysize - yhsize][x0 + i - xhsize].info &= ~(CAVE_ICKY);
1287 /* Do the left and right boundaries minus the corners (done above) */
1289 for (i = 1; i < ysize; ++i)
1291 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + 0 - xhsize);
1292 place_extra_bold(floor_ptr, y0 + i - yhsize, x0 + xsize - xhsize);
1294 /* clear icky flag -done with it */
1295 floor_ptr->grid_array[y0 + i - yhsize][x0 + 0 - xhsize].info &= ~(CAVE_ICKY);
1296 floor_ptr->grid_array[y0 + i - yhsize][x0 + xsize - xhsize].info &= ~(CAVE_ICKY);
1300 /* Do the rest: convert back to the normal format */
1301 for (x = 1; x < xsize; ++x)
1303 for (y = 1; y < ysize; ++y)
1305 /* Fill unconnected regions with granite */
1306 if ((!(floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info & CAVE_ICKY)) ||
1307 is_outer_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize))
1308 place_extra_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize);
1310 /* turn off icky flag (no longer needed.) */
1311 floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info &= ~(CAVE_ICKY | CAVE_ROOM);
1314 if (cave_have_flag_bold(floor_ptr, y0 + y - yhsize, x0 + x - xhsize, FF_LAVA))
1316 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) floor_ptr->grid_array[y0 + y - yhsize][x0 + x - xhsize].info |= CAVE_GLOW;
1326 * makes a lake/collapsed floor in the center of the dungeon
1328 void build_lake(floor_type *floor_ptr, int type)
1330 int grd, roug, xsize, ysize, x0, y0;
1334 /* paranoia - exit if lake type out of range. */
1335 if ((type < LAKE_T_LAVA) || (type > LAKE_T_FIRE_VAULT))
1337 msg_format("Invalid lake type (%d)", type);
1341 /* Make the size of the dungeon */
1342 xsize = floor_ptr->width - 1;
1343 ysize = floor_ptr->height - 1;
1347 /* Paranoia: make size even */
1353 /* testing values for these parameters: feel free to adjust */
1354 grd = randint1(3) + 4;
1356 /* want average of about 16 */
1357 roug = randint1(8) * randint1(4);
1359 /* Make up size of various componants */
1363 /* Deep water/lava */
1364 c1 = randint0(c3 / 2) + randint0(c3 / 2) - 5;
1366 /* Shallow boundary */
1370 generate_hmap(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, grd, roug, c3);
1372 /* Convert to normal format+ clean up */
1373 done = generate_lake(floor_ptr, y0 + 1, x0 + 1, xsize, ysize, c1, c2, c3, type);
1376 #endif /* ALLOW_CAVERNS_AND_LAKES */
1381 * Routine that fills the empty areas of a room with treasure and monsters.
1383 void fill_treasure(player_type *player_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
1385 POSITION x, y, cx, cy, size;
1388 /* center of room:*/
1392 /* Rough measure of size of vault= sum of lengths of sides */
1393 size = abs(x2 - x1) + abs(y2 - y1);
1395 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1396 for (x = x1; x <= x2; x++)
1398 for (y = y1; y <= y2; y++)
1400 /* Thing added based on distance to center of vault
1401 * Difficulty is 1-easy to 10-hard */
1402 value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
1404 /* hack- empty square part of the time */
1405 if ((randint1(100) - difficulty * 3) > 50) value = 20;
1407 /* if floor, shallow water and lava */
1408 if (is_floor_bold(floor_ptr, y, x) ||
1409 (cave_have_flag_bold(floor_ptr, y, x, FF_PLACE) && cave_have_flag_bold(floor_ptr, y, x, FF_DROP)))
1411 /* The smaller 'value' is, the better the stuff */
1414 /* Meanest monster + treasure */
1415 floor_ptr->monster_level = floor_ptr->base_level + 40;
1416 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1417 floor_ptr->monster_level = floor_ptr->base_level;
1418 floor_ptr->object_level = floor_ptr->base_level + 20;
1419 place_object(player_ptr, y, x, AM_GOOD);
1420 floor_ptr->object_level = floor_ptr->base_level;
1424 /* Mean monster +treasure */
1425 floor_ptr->monster_level = floor_ptr->base_level + 20;
1426 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1427 floor_ptr->monster_level = floor_ptr->base_level;
1428 floor_ptr->object_level = floor_ptr->base_level + 10;
1429 place_object(player_ptr, y, x, AM_GOOD);
1430 floor_ptr->object_level = floor_ptr->base_level;
1432 else if (value < 10)
1434 floor_ptr->monster_level = floor_ptr->base_level + 9;
1435 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1436 floor_ptr->monster_level = floor_ptr->base_level;
1438 else if (value < 17)
1440 /* Intentional Blank space */
1443 * (Want some of the vault to be empty
1444 * so have room for group monsters.
1445 * This is used in the hack above to lower
1446 * the density of stuff in the vault.)
1449 else if (value < 23)
1451 /* Object or trap */
1452 if (randint0(100) < 25)
1454 place_object(player_ptr, y, x, 0L);
1458 place_trap(player_ptr, y, x);
1461 else if (value < 30)
1463 /* Monster and trap */
1464 floor_ptr->monster_level = floor_ptr->base_level + 5;
1465 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1466 floor_ptr->monster_level = floor_ptr->base_level;
1467 place_trap(player_ptr, y, x);
1469 else if (value < 40)
1471 /* Monster or object */
1472 if (randint0(100) < 50)
1474 floor_ptr->monster_level = floor_ptr->base_level + 3;
1475 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1476 floor_ptr->monster_level = floor_ptr->base_level;
1478 if (randint0(100) < 50)
1480 floor_ptr->object_level = floor_ptr->base_level + 7;
1481 place_object(player_ptr, y, x, 0L);
1482 floor_ptr->object_level = floor_ptr->base_level;
1485 else if (value < 50)
1488 place_trap(player_ptr, y, x);
1494 /* 20% monster, 40% trap, 20% object, 20% blank space */
1495 if (randint0(100) < 20)
1497 place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1499 else if (randint0(100) < 50)
1501 place_trap(player_ptr, y, x);
1503 else if (randint0(100) < 50)
1505 place_object(player_ptr, y, x, 0L);
1516 * Overlay a rectangular room given its bounds
1517 * This routine is used by build_room_vault
1518 * The area inside the walls is not touched:
1519 * only granite is removed- normal walls stay
1521 void build_room(floor_type *floor_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2)
1523 POSITION x, y, xsize, ysize;
1526 /* Check if rectangle has no width */
1527 if ((x1 == x2) || (y1 == y2)) return;
1531 /* Swap boundaries if in wrong order */
1539 /* Swap boundaries if in wrong order */
1545 /* get total widths */
1550 /* Top and bottom boundaries */
1551 for (i = 0; i <= xsize; i++)
1553 place_outer_noperm_bold(floor_ptr, y1, x1 + i);
1554 floor_ptr->grid_array[y1][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1555 place_outer_noperm_bold(floor_ptr, y2, x1 + i);
1556 floor_ptr->grid_array[y2][x1 + i].info |= (CAVE_ROOM | CAVE_ICKY);
1559 /* Left and right boundaries */
1560 for (i = 1; i < ysize; i++)
1562 place_outer_noperm_bold(floor_ptr, y1 + i, x1);
1563 floor_ptr->grid_array[y1 + i][x1].info|=(CAVE_ROOM | CAVE_ICKY);
1564 place_outer_noperm_bold(floor_ptr, y1 + i, x2);
1565 floor_ptr->grid_array[y1 + i][x2].info|=(CAVE_ROOM | CAVE_ICKY);
1569 for (x = 1; x < xsize; x++)
1571 for (y = 1; y < ysize; y++)
1573 if (is_extra_bold(floor_ptr, y1+y, x1+x))
1575 /* clear the untouched region */
1576 place_floor_bold(floor_ptr, y1 + y, x1 + x);
1577 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1581 /* make it a room- but don't touch */
1582 floor_ptr->grid_array[y1 + y][x1 + x].info |= (CAVE_ROOM | CAVE_ICKY);
1591 * maze vault -- rectangular labyrinthine rooms
1593 * maze vault uses two routines:
1594 * r_visit - a recursive routine that builds the labyrinth
1595 * build_maze_vault - a driver routine that calls r_visit and adds
1596 * monsters, traps and treasure
1598 * The labyrinth is built by creating a spanning tree of a graph.
1599 * The graph vertices are at
1600 * (x, y) = (2j + x1, 2k + y1) j = 0,...,m-1 k = 0,...,n-1
1601 * and the edges are the vertical and horizontal nearest neighbors.
1603 * The spanning tree is created by performing a suitably randomized
1604 * depth-first traversal of the graph. The only adjustable parameter
1605 * is the randint0(3) below; it governs the relative density of
1606 * twists and turns in the labyrinth: smaller number, more twists.
1608 void r_visit(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int node, DIRECTION dir, int *visited)
1610 int i, j, m, n, temp, x, y, adj[4];
1612 /* dimensions of vertex array */
1613 m = (x2 - x1) / 2 + 1;
1614 n = (y2 - y1) / 2 + 1;
1616 /* mark node visited and set it to a floor */
1618 x = 2 * (node % m) + x1;
1619 y = 2 * (node / m) + y1;
1620 place_floor_bold(floor_ptr, y, x);
1622 /* setup order of adjacent node visits */
1625 /* pick a random ordering */
1626 for (i = 0; i < 4; i++)
1628 for (i = 0; i < 4; i++)
1639 /* pick a random ordering with dir first */
1641 for (i = 1; i < 4; i++)
1643 for (i = 1; i < 4; i++)
1645 j = 1 + randint0(3);
1652 for (i = 0; i < 4; i++)
1657 /* (0,+) - check for bottom boundary */
1658 if ((node / m < n - 1) && (visited[node + m] == 0))
1660 place_floor_bold(floor_ptr, y + 1, x);
1661 r_visit(floor_ptr, y1, x1, y2, x2, node + m, dir, visited);
1665 /* (0,-) - check for top boundary */
1666 if ((node / m > 0) && (visited[node - m] == 0))
1668 place_floor_bold(floor_ptr, y - 1, x);
1669 r_visit(floor_ptr, y1, x1, y2, x2, node - m, dir, visited);
1673 /* (+,0) - check for right boundary */
1674 if ((node % m < m - 1) && (visited[node + 1] == 0))
1676 place_floor_bold(floor_ptr, y, x + 1);
1677 r_visit(floor_ptr, y1, x1, y2, x2, node + 1, dir, visited);
1681 /* (-,0) - check for left boundary */
1682 if ((node % m > 0) && (visited[node - 1] == 0))
1684 place_floor_bold(floor_ptr, y, x - 1);
1685 r_visit(floor_ptr, y1, x1, y2, x2, node - 1, dir, visited);
1692 void build_maze_vault(player_type *player_ptr, POSITION x0, POSITION y0, POSITION xsize, POSITION ysize, bool is_vault)
1694 POSITION y, x, dy, dx;
1695 POSITION y1, x1, y2, x2;
1696 int m, n, num_vertices, *visited;
1700 msg_print_wizard(CHEAT_DUNGEON, _("迷路ランダムVaultを生成しました。", "Maze Vault."));
1702 /* Choose lite or dark */
1703 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1704 light = ((floor_ptr->dun_level <= randint1(25)) && is_vault && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS));
1706 /* Pick a random room size - randomized by calling routine */
1715 /* generate the room */
1716 for (y = y1 - 1; y <= y2 + 1; y++)
1718 for (x = x1 - 1; x <= x2 + 1; x++)
1720 g_ptr = &floor_ptr->grid_array[y][x];
1721 g_ptr->info |= CAVE_ROOM;
1722 if (is_vault) g_ptr->info |= CAVE_ICKY;
1723 if ((x == x1 - 1) || (x == x2 + 1) || (y == y1 - 1) || (y == y2 + 1))
1725 place_outer_grid(g_ptr);
1729 place_extra_grid(g_ptr);
1733 place_inner_grid(g_ptr);
1735 if (light) g_ptr->info |= (CAVE_GLOW);
1739 /* dimensions of vertex array */
1742 num_vertices = m * n;
1744 /* initialize array of visited vertices */
1745 C_MAKE(visited, num_vertices, int);
1747 /* traverse the graph to create a spaning tree, pick a random root */
1748 r_visit(floor_ptr, y1, x1, y2, x2, randint0(num_vertices), 0, visited);
1750 /* Fill with monsters and treasure, low difficulty */
1751 if (is_vault) fill_treasure(player_ptr, x1, x2, y1, y2, randint1(5));
1753 C_KILL(visited, num_vertices, int);
1757 /* Build a town/ castle by using a recursive algorithm.
1758 * Basically divide each region in a probalistic way to create
1759 * smaller regions. When the regions get too small stop.
1761 * The power variable is a measure of how well defended a region is.
1762 * This alters the possible choices.
1764 void build_recursive_room(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, int power)
1766 POSITION xsize, ysize;
1770 /* Temp variables */
1776 if ((power < 3) && (xsize > 12) && (ysize > 12))
1778 /* Need outside wall +keep */
1785 /* Make rooms + subdivide */
1786 if ((randint1(10) > 2) && (xsize < 8) && (ysize < 8))
1792 choice = randint1(2) + 1;
1797 /* Mostly subdivide */
1798 choice = randint1(3) + 1;
1802 /* Based on the choice made above, do something */
1810 /* top and bottom */
1811 for (x = x1; x <= x2; x++)
1813 place_outer_bold(floor_ptr, y1, x);
1814 place_outer_bold(floor_ptr, y2, x);
1817 /* left and right */
1818 for (y = y1 + 1; y < y2; y++)
1820 place_outer_bold(floor_ptr, y, x1);
1821 place_outer_bold(floor_ptr, y, x2);
1824 /* Make a couple of entrances */
1827 /* left and right */
1828 y = randint1(ysize) + y1;
1829 place_floor_bold(floor_ptr, y, x1);
1830 place_floor_bold(floor_ptr, y, x2);
1834 /* top and bottom */
1835 x = randint1(xsize) + x1;
1836 place_floor_bold(floor_ptr, y1, x);
1837 place_floor_bold(floor_ptr, y2, x);
1840 /* Select size of keep */
1841 t1 = randint1(ysize / 3) + y1;
1842 t2 = y2 - randint1(ysize / 3);
1843 t3 = randint1(xsize / 3) + x1;
1844 t4 = x2 - randint1(xsize / 3);
1846 /* Do outside areas */
1848 /* Above and below keep */
1849 build_recursive_room(floor_ptr, x1 + 1, y1 + 1, x2 - 1, t1, power + 1);
1850 build_recursive_room(floor_ptr, x1 + 1, t2, x2 - 1, y2, power + 1);
1852 /* Left and right of keep */
1853 build_recursive_room(floor_ptr, x1 + 1, t1 + 1, t3, t2 - 1, power + 3);
1854 build_recursive_room(floor_ptr, t4, t1 + 1, x2 - 1, t2 - 1, power + 3);
1856 /* Make the keep itself: */
1869 /* Try to build a room */
1870 if ((xsize < 3) || (ysize < 3))
1872 for (y = y1; y < y2; y++)
1874 for (x = x1; x < x2; x++)
1876 place_inner_bold(floor_ptr, y, x);
1884 /* Make outside walls */
1885 /* top and bottom */
1886 for (x = x1 + 1; x <= x2 - 1; x++)
1888 place_inner_bold(floor_ptr, y1 + 1, x);
1889 place_inner_bold(floor_ptr, y2 - 1, x);
1892 /* left and right */
1893 for (y = y1 + 1; y <= y2 - 1; y++)
1895 place_inner_bold(floor_ptr, y, x1 + 1);
1896 place_inner_bold(floor_ptr, y, x2 - 1);
1900 y = randint1(ysize - 3) + y1 + 1;
1905 place_floor_bold(floor_ptr, y, x1 + 1);
1910 place_floor_bold(floor_ptr, y, x2 - 1);
1913 /* Build the room */
1914 build_recursive_room(floor_ptr, x1 + 2, y1 + 2, x2 - 2, y2 - 2, power + 3);
1919 /* Try and divide vertically */
1923 for (y = y1; y < y2; y++)
1925 for (x = x1; x < x2; x++)
1927 place_inner_bold(floor_ptr, y, x);
1933 t1 = randint1(xsize - 2) + x1 + 1;
1934 build_recursive_room(floor_ptr, x1, y1, t1, y2, power - 2);
1935 build_recursive_room(floor_ptr, t1 + 1, y1, x2, y2, power - 2);
1940 /* Try and divide horizontally */
1944 for (y = y1; y < y2; y++)
1946 for (x = x1; x < x2; x++)
1948 place_inner_bold(floor_ptr, y, x);
1954 t1 = randint1(ysize - 2) + y1 + 1;
1955 build_recursive_room(floor_ptr, x1, y1, x2, t1, power - 2);
1956 build_recursive_room(floor_ptr, x1, t1 + 1, x2, y2, power - 2);
1964 * Add outer wall to a floored region
1965 * Note: no range checking is done so must be inside dungeon
1966 * This routine also stomps on doors
1968 void add_outer_wall(floor_type *floor_ptr, POSITION x, POSITION y, int light, POSITION x1, POSITION y1, POSITION x2, POSITION y2)
1971 feature_type *f_ptr;
1974 if (!in_bounds(floor_ptr, y, x)) return;
1976 g_ptr = &floor_ptr->grid_array[y][x];
1978 /* hack- check to see if square has been visited before
1979 * if so, then exit (use room flag to do this) */
1980 if (g_ptr->info & CAVE_ROOM) return;
1983 g_ptr->info |= CAVE_ROOM;
1985 f_ptr = &f_info[g_ptr->feat];
1987 if (is_floor_bold(floor_ptr, y, x))
1989 for (i = -1; i <= 1; i++)
1991 for (j = -1; j <= 1; j++)
1993 if ((x + i >= x1) && (x + i <= x2) && (y + j >= y1) && (y + j <= y2))
1995 add_outer_wall(floor_ptr, x + i, y + j, light, x1, y1, x2, y2);
1996 if (light) g_ptr->info |= CAVE_GLOW;
2001 else if (is_extra_bold(floor_ptr, y, x))
2003 /* Set bounding walls */
2004 place_outer_bold(floor_ptr, y, x);
2005 if (light) g_ptr->info |= CAVE_GLOW;
2007 else if (permanent_wall(f_ptr))
2009 /* Set bounding walls */
2010 if (light) g_ptr->info |= CAVE_GLOW;
2016 * Hacked distance formula - gives the 'wrong' answer.
2017 * Used to build crypts
2019 POSITION dist2(POSITION x1, POSITION y1, POSITION x2, POSITION y2, POSITION h1, POSITION h2, POSITION h3, POSITION h4)
2025 /* Basically this works by taking the normal pythagorean formula
2026 * and using an expansion to express this in a way without the
2027 * square root. This approximate formula is then perturbed to give
2028 * the distorted results. (I found this by making a mistake when I was
2029 * trying to fix the circular rooms.)
2032 /* h1-h4 are constants that describe the metric */
2033 if (dx >= 2 * dy) return (dx + (dy * h1) / h2);
2034 if (dy >= 2 * dx) return (dy + (dx * h1) / h2);
2035 return (((dx + dy) * 128) / 181 +
2036 (dx * dx / (dy * h3) + dy * dy / (dx * h3)) * h4);
2037 /* 128/181 is approx. 1/sqrt(2) */
2043 /* Create a new floor room with optional light */
2044 void generate_room_floor(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
2050 for (y = y1; y <= y2; y++)
2052 for (x = x1; x <= x2; x++)
2055 g_ptr = &floor_ptr->grid_array[y][x];
2056 place_floor_grid(g_ptr);
2057 g_ptr->info |= (CAVE_ROOM);
2058 if (light) g_ptr->info |= (CAVE_GLOW);
2063 void generate_fill_perm_bold(floor_type *floor_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
2067 for (y = y1; y <= y2; y++)
2069 for (x = x1; x <= x2; x++)
2072 place_inner_perm_bold(floor_ptr ,y, x);
2079 * @brief 与えられた部屋型IDに応じて部屋の生成処理分岐を行い結果を返す / Attempt to build a room of the given type at the given block
2080 * @param player_ptr プレーヤーへの参照ポインタ
2082 * @note that we restrict the number of "crowded" rooms to reduce the chance of overflowing the monster list during level creation.
2083 * @return 部屋の生成に成功した場合 TRUE を返す。
2085 static bool room_build(player_type *player_ptr, EFFECT_ID typ)
2087 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2090 /* Build an appropriate room */
2091 case ROOM_T_NORMAL: return build_type1(floor_ptr);
2092 case ROOM_T_OVERLAP: return build_type2(floor_ptr);
2093 case ROOM_T_CROSS: return build_type3(player_ptr);
2094 case ROOM_T_INNER_FEAT: return build_type4(player_ptr);
2095 case ROOM_T_NEST: return build_type5(floor_ptr);
2096 case ROOM_T_PIT: return build_type6(floor_ptr);
2097 case ROOM_T_LESSER_VAULT: return build_type7(player_ptr);
2098 case ROOM_T_GREATER_VAULT: return build_type8(player_ptr);
2099 case ROOM_T_FRACAVE: return build_type9(floor_ptr);
2100 case ROOM_T_RANDOM_VAULT: return build_type10(player_ptr);
2101 case ROOM_T_OVAL: return build_type11(floor_ptr);
2102 case ROOM_T_CRYPT: return build_type12(player_ptr);
2103 case ROOM_T_TRAP_PIT: return build_type13(floor_ptr);
2104 case ROOM_T_TRAP: return build_type14(floor_ptr);
2105 case ROOM_T_GLASS: return build_type15(player_ptr);
2106 case ROOM_T_ARCADE: return build_type16(floor_ptr);
2107 case ROOM_T_FIXED: return build_type17(player_ptr);
2113 * @brief 指定した部屋の生成確率を別の部屋に加算し、指定した部屋の生成率を0にする
2114 * @param dst 確率を移す先の部屋種ID
2115 * @param src 確率を与える元の部屋種ID
2117 #define MOVE_PLIST(dst, src) (prob_list[dst] += prob_list[src], prob_list[src] = 0)
2120 * @brief 部屋生成処理のメインルーチン(Sangbandを経由してOangbandからの実装を引用) / Generate rooms in dungeon. Build bigger rooms at first. [from SAngband (originally from OAngband)]
2121 * @param player_ptr プレーヤーへの参照ポインタ
2122 * @return 部屋生成に成功した場合 TRUE を返す。
2124 bool generate_rooms(player_type *player_ptr)
2126 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2131 int prob_list[ROOM_T_MAX];
2132 int rooms_built = 0;
2133 int area_size = 100 * (floor_ptr->height*floor_ptr->width) / (MAX_HGT*MAX_WID);
2134 int level_index = MIN(10, div_round(floor_ptr->dun_level, 10));
2136 /* Number of each type of room on this level */
2137 s16b room_num[ROOM_T_MAX];
2139 /* Limit number of rooms */
2140 int dun_rooms = DUN_ROOMS_MAX * area_size / 100;
2142 /* Assume normal floor_ptr->grid_array */
2143 room_info_type *room_info_ptr = room_info_normal;
2146 * Initialize probability list.
2148 for (i = 0; i < ROOM_T_MAX; i++)
2150 /* No rooms allowed above their minimum depth. */
2151 if (floor_ptr->dun_level < room_info_ptr[i].min_level)
2157 prob_list[i] = room_info_ptr[i].prob[level_index];
2162 * XXX -- Various dungeon types and options.
2165 /*! @details ダンジョンにBEGINNER、CHAMELEON、SMALLESTいずれのフラグもなく、
2166 * かつ「常に通常でない部屋を生成する」フラグがONならば、
2167 * GRATER_VAULTのみを生成対象とする。 / Ironman sees only Greater Vaults */
2168 if (ironman_rooms && !((d_info[floor_ptr->dungeon_idx].flags1 & (DF1_BEGINNER | DF1_CHAMELEON | DF1_SMALLEST))))
2170 for (i = 0; i < ROOM_T_MAX; i++)
2172 if (i == ROOM_T_GREATER_VAULT) prob_list[i] = 1;
2173 else prob_list[i] = 0;
2177 /*! @details ダンジョンにNO_VAULTフラグがあるならば、LESSER_VAULT / GREATER_VAULT/ RANDOM_VAULTを除外 / Forbidden vaults */
2178 else if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_VAULT)
2180 prob_list[ROOM_T_LESSER_VAULT] = 0;
2181 prob_list[ROOM_T_GREATER_VAULT] = 0;
2182 prob_list[ROOM_T_RANDOM_VAULT] = 0;
2185 /*! @details ダンジョンにBEGINNERフラグがあるならば、FIXED_ROOMを除外 / Forbidden vaults */
2186 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_BEGINNER)
2188 prob_list[ROOM_T_FIXED] = 0;
2191 /*! @details ダンジョンにNO_CAVEフラグがある場合、FRACAVEの生成枠がNORMALに与えられる。CRIPT、OVALの生成枠がINNER_Fに与えられる。/ NO_CAVE dungeon (Castle)*/
2192 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE)
2194 MOVE_PLIST(ROOM_T_NORMAL, ROOM_T_FRACAVE);
2195 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_CRYPT);
2196 MOVE_PLIST(ROOM_T_INNER_FEAT, ROOM_T_OVAL);
2199 /*! @details ダンジョンにCAVEフラグがある場合、NORMALの生成枠がFRACAVEに与えられる。/ CAVE dungeon (Orc floor_ptr->grid_array etc.) */
2200 else if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_CAVE)
2202 MOVE_PLIST(ROOM_T_FRACAVE, ROOM_T_NORMAL);
2205 /*! @details ダンジョンの基本地形が最初から渓谷かアリーナ型の場合 FRACAVE は生成から除外。 / No caves when a (random) cavern exists: they look bad */
2206 else if (dun->cavern || dun->empty_level)
2208 prob_list[ROOM_T_FRACAVE] = 0;
2211 /*! @details ダンジョンに最初からGLASS_ROOMフラグがある場合、GLASS を生成から除外。/ Forbidden glass rooms */
2212 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_ROOM))
2214 prob_list[ROOM_T_GLASS] = 0;
2217 /*! @details ARCADEは同フラグがダンジョンにないと生成されない。 / Forbidden glass rooms */
2218 if (!(d_info[floor_ptr->dungeon_idx].flags1 & DF1_ARCADE))
2220 prob_list[ROOM_T_ARCADE] = 0;
2224 * Initialize number of rooms,
2225 * And calcurate total probability.
2227 for (total_prob = 0, i = 0; i < ROOM_T_MAX; i++)
2230 total_prob += prob_list[i];
2234 * Prepare the number of rooms, of all types, we should build
2237 for (i = dun_rooms; i > 0; i--)
2240 int rand = randint0(total_prob);
2242 /* Get room_type randomly */
2243 for (room_type = 0; room_type < ROOM_T_MAX; room_type++)
2245 if (rand < prob_list[room_type]) break;
2246 else rand -= prob_list[room_type];
2248 if (room_type >= ROOM_T_MAX) room_type = ROOM_T_NORMAL;
2250 /* Increase the number of rooms of that type we should build. */
2251 room_num[room_type]++;
2257 case ROOM_T_LESSER_VAULT:
2258 case ROOM_T_TRAP_PIT:
2266 case ROOM_T_GREATER_VAULT:
2267 case ROOM_T_RANDOM_VAULT:
2276 * Build each type of room one by one until we cannot build any more.
2277 * [from SAngband (originally from OAngband)]
2281 /* Assume no remaining rooms */
2284 for (i = 0; i < ROOM_T_MAX; i++)
2286 /* What type of room are we building now? */
2287 int room_type = room_build_order[i];
2289 /* Go next if none available */
2290 if (!room_num[room_type]) continue;
2292 /* Use up one unit */
2293 room_num[room_type]--;
2295 /* Build the room. */
2296 if (room_build(player_ptr, room_type))
2298 /* Increase the room built count. */
2301 /* Mark as there was some remaining rooms */
2308 case ROOM_T_TRAP_PIT:
2310 /* Avoid too many monsters */
2313 room_num[ROOM_T_PIT] = 0;
2314 room_num[ROOM_T_NEST] = 0;
2315 room_num[ROOM_T_TRAP_PIT] = 0;
2321 /* Avoid double-town */
2322 room_num[ROOM_T_ARCADE] = 0;
2328 /* End loop if no room remain */
2332 /*! @details 部屋生成数が2未満の場合生成失敗を返す */
2333 if (rooms_built < 2)
2335 msg_format_wizard(CHEAT_DUNGEON, _("部屋数が2未満でした。生成を再試行します。", "Number of rooms was under 2. Retry."), rooms_built);
2339 msg_format_wizard(CHEAT_DUNGEON, _("このダンジョンの部屋数は %d です。", "Number of Rooms: %d"), rooms_built);